Last commit july 5th

This commit is contained in:
2024-07-05 13:46:23 +02:00
parent dad0d86e8c
commit b0e4dfbb76
24982 changed files with 2621219 additions and 413 deletions

5
spa/node_modules/sync-rpc/HISTORY.md generated vendored Normal file
View File

@@ -0,0 +1,5 @@
# Changelog
## v0.0.1: 2017-xx-xx
- Initial release

21
spa/node_modules/sync-rpc/LICENSE.md generated vendored Normal file
View File

@@ -0,0 +1,21 @@
# The MIT License (MIT)
Copyright (c) 2017 [Forbes Lindesay](https://github.com/ForbesLindesay)
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.

43
spa/node_modules/sync-rpc/README.md generated vendored Normal file
View File

@@ -0,0 +1,43 @@
# sync-rpc
Run asynchronous commands synchronously by putting them in a separate process
[![Build Status](https://img.shields.io/travis/ForbesLindesay/sync-rpc/master.svg)](https://travis-ci.org/ForbesLindesay/sync-rpc)
[![Dependency Status](https://img.shields.io/david/ForbesLindesay/sync-rpc/master.svg)](http://david-dm.org/ForbesLindesay/sync-rpc)
[![NPM version](https://img.shields.io/npm/v/sync-rpc.svg)](https://www.npmjs.org/package/sync-rpc)
## Installation
```
npm install sync-rpc --save
```
## Usage
### worker.js
```js
function init(connection) {
// you can setup any connections you need here
return function (message) {
// Note how even though we return a promise, the resulting rpc client will be synchronous
return Promise.resolve('sent ' + message + ' to ' + connection);
}
}
module.exports = init;
```
```js
const assert = require('assert');
const rpc = require('sync-rpc');
const client = rpc(__dirname + '/../test-worker.js', 'My Server');
const result = client('My Message');
assert(result === 'sent My Message to My Server');
```
## License
MIT

75
spa/node_modules/sync-rpc/lib/__tests__/index.test.js generated vendored Normal file
View File

@@ -0,0 +1,75 @@
const rpc = require('../');
const client = rpc(__dirname + '/../test-worker.js', 'My Server');
test('it should work', () => {
for (let i = 0; i < 10; i++) {
expect(client('My Message')).toBe('sent My Message to My Server');
}
});
let nativeNCFails = false;
rpc.FUNCTION_PRIORITY.forEach((fn, i) => {
test('profile ' + fn.name, () => {
try {
rpc.configuration.fastestFunction = fn;
const start = Date.now();
for (let i = 0; i < 100; i++) {
expect(client('My Message')).toBe('sent My Message to My Server');
}
const end = Date.now();
console.log(fn.name + ': ' + (end - start));
} catch (ex) {
if (fn.name === 'nativeNC') {
console.log(fn.name + ' fails');
nativeNCFails = true;
return;
}
throw ex;
}
});
});
rpc.FUNCTION_PRIORITY.forEach((fn, i) => {
test('test 30MB ' + fn.name, () => {
let result;
try {
rpc.configuration.fastestFunction = fn;
result = client('big');
} catch (ex) {
if (fn.name === 'nativeNC' && nativeNCFails) {
console.log(fn.name + ' fails');
return;
}
throw ex;
}
expect(result.length).toBe(30 * 1024 * 1024, 42);
// for (let i = 0; i < 30 * 1024 * 1024, 42; i++) {
// expect(result[i]).toBe(42);
// }
});
});
rpc.FUNCTION_PRIORITY.forEach((fn, i) => {
let longMessage = '';
for (let i = 0; i < 100000; i++) {
longMessage += 'My Long Message Content';
}
test('profile large ' + fn.name, () => {
try {
rpc.configuration.fastestFunction = fn;
const start = Date.now();
for (let i = 0; i < 10; i++) {
expect(client(longMessage)).toBe(`sent ${longMessage} to My Server`);
}
const end = Date.now();
console.log('large ' + fn.name + ': ' + (end - start));
} catch (ex) {
if (fn.name === 'nativeNC' && nativeNCFails) {
console.log('large ' + fn.name + ' fails');
return;
}
throw ex;
}
});
});

11
spa/node_modules/sync-rpc/lib/find-port.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
'use strict';
const getPort = require('get-port');
getPort()
.then(port => process.stdout.write('' + port))
.catch(err =>
setTimeout(() => {
throw err;
}, 0)
);

181
spa/node_modules/sync-rpc/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,181 @@
'use strict';
const path = require('path');
const spawn = require('child_process').spawn;
const spawnSync = require('child_process').spawnSync;
const JSON = require('./json-buffer');
const host = '127.0.0.1';
function nodeNetCatSrc(port, input) {
return (
"var c=require('net').connect(" +
port +
",'127.0.0.1',()=>{c.pipe(process.stdout);c.end(" +
JSON.stringify(input)
.replace(/\u2028/g, '\\u2028')
.replace(/\u2029/g, '\\u2029') +
')})'
);
}
const FUNCTION_PRIORITY = [nativeNC, nodeNC];
let started = false;
const configuration = {port: null, fastestFunction: null};
function start() {
if (!spawnSync) {
throw new Error(
'Sync-request requires node version 0.12 or later. If you need to use it with an older version of node\n' +
'you can `npm install sync-request@2.2.0`, which was the last version to support older versions of node.'
);
}
const port = findPort();
const p = spawn(process.execPath, [require.resolve('./worker'), port], {
stdio: 'inherit',
windowsHide: true,
});
p.unref();
process.on('exit', () => {
p.kill();
});
waitForAlive(port);
const fastestFunction = getFastestFunction(port);
configuration.port = port;
configuration.fastestFunction = fastestFunction;
started = true;
}
function findPort() {
const findPortResult = spawnSync(
process.execPath,
[require.resolve('./find-port')],
{
windowsHide: true,
}
);
if (findPortResult.error) {
if (typeof findPortResult.error === 'string') {
throw new Error(findPortResult.error);
}
throw findPortResult.error;
}
if (findPortResult.status !== 0) {
throw new Error(
findPortResult.stderr.toString() ||
'find port exited with code ' + findPortResult.status
);
}
const portString = findPortResult.stdout.toString('utf8').trim();
if (!/^[0-9]+$/.test(portString)) {
throw new Error('Invalid port number string returned: ' + portString);
}
return +portString;
}
function waitForAlive(port) {
let response = null;
let err = null;
let timeout = Date.now() + 10000;
while (response !== 'pong' && Date.now() < timeout) {
const result = nodeNC(port, 'ping\r\n');
response = result.stdout && result.stdout.toString();
err = result.stderr && result.stderr.toString();
}
if (response !== 'pong') {
throw new Error(
'Timed out waiting for sync-rpc server to start (it should respond with "pong" when sent "ping"):\n\n' +
err +
'\n' +
response
);
}
}
function nativeNC(port, input) {
return spawnSync('nc', [host, port], {
input: input,
windowsHide: true,
maxBuffer: Infinity,
});
}
function nodeNC(port, input) {
const src = nodeNetCatSrc(port, input);
if (src.length < 1000) {
return spawnSync(process.execPath, ['-e', src], {
windowsHide: true,
maxBuffer: Infinity,
});
} else {
return spawnSync(process.execPath, [], {
input: src,
windowsHide: true,
maxBuffer: Infinity,
});
}
}
function test(fn, port) {
const result = fn(port, 'ping\r\n');
const response = result.stdout && result.stdout.toString();
return response === 'pong';
}
function getFastestFunction(port) {
for (let i = 0; i < FUNCTION_PRIORITY.length; i++) {
if (test(FUNCTION_PRIORITY[i], port)) {
return FUNCTION_PRIORITY[i];
}
}
}
function sendMessage(input) {
if (!started) start();
const res = configuration.fastestFunction(
configuration.port,
JSON.stringify(input) + '\r\n'
);
try {
return JSON.parse(res.stdout.toString('utf8'));
} catch (ex) {
if (res.error) {
if (typeof res.error === 'string') res.error = new Error(res.error);
throw res.error;
}
if (res.status !== 0) {
throw new Error(
configuration.fastestFunction.name +
' failed:\n' +
(res.stdout && res.stdout.toString()) +
'\n' +
(res.stderr && res.stderr.toString())
);
}
throw new Error(
configuration.fastestFunction.name +
' failed:\n' +
(res.stdout && res.stdout).toString() +
'\n' +
(res.stderr && res.stderr).toString()
);
}
}
function extractValue(msg) {
if (!msg.s) {
const error = new Error(msg.v.message);
error.code = msg.v.code;
throw error;
}
return msg.v;
}
function createClient(filename, args) {
const id = extractValue(sendMessage({t: 1, f: filename, a: args}));
return function(args) {
return extractValue(sendMessage({t: 0, i: id, a: args}));
};
}
createClient.FUNCTION_PRIORITY = FUNCTION_PRIORITY;
createClient.configuration = configuration;
module.exports = createClient;

22
spa/node_modules/sync-rpc/lib/json-buffer/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,22 @@
Copyright (c) 2013 Dominic Tarr
Permission is hereby granted, free of charge,
to any person obtaining a copy of this software and
associated documentation files (the "Software"), to
deal in the Software without restriction, including
without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom
the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1
spa/node_modules/sync-rpc/lib/json-buffer/README.md generated vendored Normal file
View File

@@ -0,0 +1 @@
Code based on https://github.com/dominictarr/json-buffer but adapted to be simpler to run in a purely node.js environment

52
spa/node_modules/sync-rpc/lib/json-buffer/index.js generated vendored Normal file
View File

@@ -0,0 +1,52 @@
'use strict';
//TODO: handle reviver/dehydrate function like normal
//and handle indentation, like normal.
//if anyone needs this... please send pull request.
exports.stringify = function stringify(o) {
if (o && Buffer.isBuffer(o))
return JSON.stringify(':base64:' + o.toString('base64'));
if (o && o.toJSON) o = o.toJSON();
if (o && 'object' === typeof o) {
var s = '';
var array = Array.isArray(o);
s = array ? '[' : '{';
var first = true;
for (var k in o) {
var ignore =
'function' == typeof o[k] || (!array && 'undefined' === typeof o[k]);
if (Object.hasOwnProperty.call(o, k) && !ignore) {
if (!first) s += ',';
first = false;
if (array) {
s += stringify(o[k]);
} else if (o[k] !== void 0) {
s += stringify(k) + ':' + stringify(o[k]);
}
}
}
s += array ? ']' : '}';
return s;
} else if ('string' === typeof o) {
return JSON.stringify(/^:/.test(o) ? ':' + o : o);
} else if ('undefined' === typeof o) {
return 'null';
} else return JSON.stringify(o);
};
exports.parse = function(s) {
return JSON.parse(s, function(key, value) {
if ('string' === typeof value) {
if (/^:base64:/.test(value))
return new Buffer(value.substring(8), 'base64');
else return /^:/.test(value) ? value.substring(1) : value;
}
return value;
});
};

9
spa/node_modules/sync-rpc/lib/test-worker.js generated vendored Normal file
View File

@@ -0,0 +1,9 @@
function init(connection) {
return function(message) {
if (message === 'big') {
return Promise.resolve(Buffer.alloc(30 * 1024 * 1024, 42));
}
return Promise.resolve('sent ' + message + ' to ' + connection);
};
}
module.exports = init;

68
spa/node_modules/sync-rpc/lib/worker.js generated vendored Normal file
View File

@@ -0,0 +1,68 @@
'use strict';
const net = require('net');
const JSON = require('./json-buffer');
const INIT = 1;
const CALL = 0;
const modules = [];
const NULL_PROMISE = Promise.resolve(null);
const server = net.createServer({allowHalfOpen: true}, c => {
let responded = false;
function respond(data) {
if (responded) return;
responded = true;
c.end(JSON.stringify(data));
}
let buffer = '';
c.on('error', function(err) {
respond({s: false, v: {code: err.code, message: err.message}});
});
c.on('data', function(data) {
buffer += data.toString('utf8');
if (/\r\n/.test(buffer)) {
onMessage(buffer.trim());
}
});
function onMessage(str) {
if (str === 'ping') {
c.end('pong');
return;
}
NULL_PROMISE.then(function() {
const req = JSON.parse(str);
if (req.t === INIT) {
return init(req.f, req.a);
}
return modules[req.i](req.a);
}).then(
function(response) {
respond({s: true, v: response});
},
function(err) {
respond({s: false, v: {code: err.code, message: err.message}});
}
);
}
});
function init(filename, arg) {
let m = require(filename);
if (m && typeof m === 'object' && typeof m.default === 'function') {
m = m.default;
}
if (typeof m !== 'function') {
throw new Error(filename + ' did not export a function.');
}
return NULL_PROMISE.then(function() {
return m(arg);
}).then(function(fn) {
const i = modules.length;
modules[i] = fn;
return i;
});
}
server.listen(+process.argv[2]);

41
spa/node_modules/sync-rpc/package.json generated vendored Normal file
View File

@@ -0,0 +1,41 @@
{
"name": "sync-rpc",
"version": "1.3.6",
"main": "lib/index.js",
"description": "Run asynchronous commands synchronously by putting them in a separate process",
"keywords": [],
"files": [
"lib/"
],
"dependencies": {
"get-port": "^3.1.0"
},
"devDependencies": {
"husky": "*",
"jest": "*",
"lint-staged": "*",
"prettier": "*"
},
"scripts": {
"precommit": "lint-staged",
"prettier": "prettier --write \"lib/**/*.js\"",
"prettier:check": "prettier --list-different \"lib/**/*.js\"",
"test": "jest --coverage",
"watch": "jest --coverage --watch"
},
"lint-staged": {
"*.js": [
"prettier --write",
"git add"
]
},
"repository": {
"type": "git",
"url": "https://github.com/ForbesLindesay/sync-rpc.git"
},
"author": {
"name": "Forbes Lindesay",
"url": "http://github.com/ForbesLindesay"
},
"license": "MIT"
}