dcp-client 4.4.22 → 4.4.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/dcp-config-value +163 -0
- package/build/bundle +1 -10
- package/build/etc/config.cache +2 -2
- package/build/generate-sandbox-definitions-json +2 -0
- package/dist/dcp-client-bundle.js +1 -1
- package/dist/dcp-client-bundle.js.LICENSE.txt +27 -0
- package/dist/dcp-client-bundle.js.map +1 -1
- package/generated/sandbox-definitions.json +1 -1
- package/index.js +5 -4
- package/lib/standaloneWorker.js +56 -46
- package/libexec/sandbox/access-lists.js +2 -514
- package/libexec/sandbox/bravojs-env.js +1 -1
- package/libexec/sandbox/polyfills.js +519 -0
- package/libexec/sandbox/url.js +432 -0
- package/npm-hooks/prepack +10 -3
- package/ns-map.js +0 -1
- package/package.json +6 -6
- package/dist/dcp-modal-style.css +0 -8232
|
@@ -1 +1 @@
|
|
|
1
|
-
{"browser":["deny-node","kvin/kvin.js","script-load-wrapper","timer-classes","wrap-event-listeners","event-loop-virtualization","lift-webgl","lift-wasm","lift-webgpu","worktimes","access-lists","bravojs-init","bravojs/bravo.js","bravojs-env","pyodide-core","calculate-capabilities","bootstrap"],"node":["kvin/kvin.js","sa-ww-simulation","script-load-wrapper","timer-classes","wrap-event-listeners","event-loop-virtualization","lift-webgl","lift-wasm","lift-webgpu","worktimes","access-lists","bravojs-init","bravojs/bravo.js","bravojs-env","pyodide-core","calculate-capabilities","bootstrap"],"native":["deny-node","kvin/kvin.js","sa-ww-simulation","script-load-wrapper","native-event-loop","timer-classes","wrap-event-listeners","event-loop-virtualization","lift-webgl","lift-wasm","lift-webgpu","worktimes","access-lists","bravojs-init","bravojs/bravo.js","bravojs-env","pyodide-core","calculate-capabilities","bootstrap"],"nodeTesting":["kvin/kvin.js","sa-ww-simulation","script-load-wrapper","timer-classes","wrap-event-listeners","event-loop-virtualization","lift-webgl","lift-wasm","lift-webgpu","worktimes","access-lists","bravojs-init","bravojs/bravo.js","bravojs-env","pyodide-core","calculate-capabilities","bootstrap","testing.js"],"testing":["deny-node","kvin/kvin.js","sa-ww-simulation","script-load-wrapper","native-event-loop","timer-classes","wrap-event-listeners","event-loop-virtualization","lift-webgl","lift-wasm","lift-webgpu","worktimes","access-lists","bravojs-init","bravojs/bravo.js","bravojs-env","pyodide-core","calculate-capabilities","bootstrap","testing.js"]}
|
|
1
|
+
{"browser":["deny-node","kvin/kvin.js","script-load-wrapper","timer-classes","wrap-event-listeners","event-loop-virtualization","lift-webgl","lift-wasm","lift-webgpu","worktimes","url","polyfills","access-lists","bravojs-init","bravojs/bravo.js","bravojs-env","pyodide-core","calculate-capabilities","bootstrap"],"node":["kvin/kvin.js","sa-ww-simulation","script-load-wrapper","timer-classes","wrap-event-listeners","event-loop-virtualization","lift-webgl","lift-wasm","lift-webgpu","worktimes","url","polyfills","access-lists","bravojs-init","bravojs/bravo.js","bravojs-env","pyodide-core","calculate-capabilities","bootstrap"],"native":["deny-node","kvin/kvin.js","sa-ww-simulation","script-load-wrapper","native-event-loop","timer-classes","wrap-event-listeners","event-loop-virtualization","lift-webgl","lift-wasm","lift-webgpu","worktimes","url","polyfills","access-lists","bravojs-init","bravojs/bravo.js","bravojs-env","pyodide-core","calculate-capabilities","bootstrap"],"nodeTesting":["kvin/kvin.js","sa-ww-simulation","script-load-wrapper","timer-classes","wrap-event-listeners","event-loop-virtualization","lift-webgl","lift-wasm","lift-webgpu","worktimes","url","polyfills","access-lists","bravojs-init","bravojs/bravo.js","bravojs-env","pyodide-core","calculate-capabilities","bootstrap","testing.js"],"testing":["deny-node","kvin/kvin.js","sa-ww-simulation","script-load-wrapper","native-event-loop","timer-classes","wrap-event-listeners","event-loop-virtualization","lift-webgl","lift-wasm","lift-webgpu","worktimes","url","polyfills","access-lists","bravojs-init","bravojs/bravo.js","bravojs-env","pyodide-core","calculate-capabilities","bootstrap","testing.js"]}
|
package/index.js
CHANGED
|
@@ -37,7 +37,7 @@ const debug = require('debug');
|
|
|
37
37
|
const moduleSystem = require('module');
|
|
38
38
|
const { spawnSync } = require('child_process');
|
|
39
39
|
const vm = require('vm');
|
|
40
|
-
const protectedDcpConfigKeys = [ 'system', 'bundle', 'worker', '
|
|
40
|
+
const protectedDcpConfigKeys = [ 'system', 'bundle', 'worker', 'evaluator' ];
|
|
41
41
|
|
|
42
42
|
let initInvoked = false; /* flag to help us detect use of Compute API before init */
|
|
43
43
|
let originalDcpConfig = globalThis.dcpConfig || false; /* not false if user set their own dcpConfig global variable before init */
|
|
@@ -440,7 +440,7 @@ function checkConfigFileSafePerms(fullPath, statBuf)
|
|
|
440
440
|
* failure is desired behaviour.
|
|
441
441
|
*/
|
|
442
442
|
function addConfigFile(existing /*, file path components ... */) {
|
|
443
|
-
let fullPath = '';
|
|
443
|
+
let fullPath = process.env.DCP_CLIENT_FILESYSTEM_ROOT || '';
|
|
444
444
|
|
|
445
445
|
for (let i=1; i < arguments.length; i++) {
|
|
446
446
|
if (!arguments[i])
|
|
@@ -708,7 +708,7 @@ function initTail(configFrags, options, finalBundleCode, finalBundleURL)
|
|
|
708
708
|
var finalBundleLabel; /* symbolic label used for logs describing the source of the final bundle */
|
|
709
709
|
var ret; /* the return value of the current function - usually the `dcp` object but
|
|
710
710
|
possibly edited by the postInitTailHook function. */
|
|
711
|
-
var schedConfLocFun = require('dcp/protocol
|
|
711
|
+
var schedConfLocFun = require('dcp/protocol').getSchedulerConfigLocation;
|
|
712
712
|
|
|
713
713
|
/* 1 */
|
|
714
714
|
bundleSandbox.dcpConfig = configFrags.internalConfig;
|
|
@@ -737,7 +737,7 @@ function initTail(configFrags, options, finalBundleCode, finalBundleURL)
|
|
|
737
737
|
* closes over the wrong variable and returns `undefined` even though fetch has been used.
|
|
738
738
|
*/
|
|
739
739
|
if (schedConfLocFun)
|
|
740
|
-
require('dcp/protocol
|
|
740
|
+
require('dcp/protocol').getSchedulerConfigLocation = schedConfLocFun;
|
|
741
741
|
|
|
742
742
|
/* Class patch-up is necessary because the KVIN deserialzation and default initializations earlier
|
|
743
743
|
* would have made instances of classes inside the first bundle instead of the final bundle.
|
|
@@ -768,6 +768,7 @@ function initTail(configFrags, options, finalBundleCode, finalBundleURL)
|
|
|
768
768
|
delete remoteConfig[protectedKey];
|
|
769
769
|
|
|
770
770
|
addConfig(workingDcpConfig, configFrags.internalConfig);
|
|
771
|
+
addConfig(workingDcpConfig, configFrags.defaultConfig);
|
|
771
772
|
addConfig(workingDcpConfig, remoteConfig);
|
|
772
773
|
addConfig(workingDcpConfig, configFrags.localConfig);
|
|
773
774
|
addConfig(workingDcpConfig, originalDcpConfig);
|
package/lib/standaloneWorker.js
CHANGED
|
@@ -6,32 +6,26 @@
|
|
|
6
6
|
* @author Wes Garland, wes@sparc.network
|
|
7
7
|
* @date March 2018
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
11
|
const { setBackoffInterval, clearBackoffInterval } = require('dcp/dcp-timers');
|
|
12
|
-
const { leafMerge } = require('dcp/utils');
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
dcpConfig.standaloneWorker = Object.assign(dcpConfig.standaloneWorker || {},
|
|
25
|
-
leafMerge(defaultConfig, dcpConfig.standaloneWorker));
|
|
26
|
-
var debugging = dcpConfig.standaloneWorker.debug ? () => true : require('dcp/internal/debugging').scope('saw');
|
|
27
|
-
|
|
28
|
-
/** StandaloneWorker constructor
|
|
29
|
-
* @param code The code to run in the worker to bootstrap it (setup comms with Supervisor)
|
|
12
|
+
const { leafMerge, deepClone } = require('dcp/utils');
|
|
13
|
+
|
|
14
|
+
var debugging = require('dcp/internal/debugging').scope('saw');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* StandaloneWorker constructor
|
|
18
|
+
* The running configuration is derived by merging:
|
|
19
|
+
* - baked-in defaults
|
|
20
|
+
* - dcpConfig.evaluator
|
|
21
|
+
* - option.hostname/port/location
|
|
22
|
+
*
|
|
30
23
|
* @param options Options for the Worker constructor. These can be options per the specification
|
|
31
24
|
* for Web Workers (note: not current propagated) or any of these options:
|
|
32
25
|
*
|
|
33
|
-
* hostname: The hostname of the Evaluator server; default to dcpConfig.
|
|
26
|
+
* hostname: The hostname of the Evaluator server; default to dcpConfig.eveluator.hostname or localhost.
|
|
34
27
|
* port: The port number of the Evaluator server; default to dcpConfig.evaluator.port or 9000;
|
|
28
|
+
* location: URL which contains hostname and port
|
|
35
29
|
* readStream: An instance of Stream.readable connected to an Evaluator
|
|
36
30
|
* writeStream: An instance of Stream.writeable connected to the same Evaluator, default=readStream
|
|
37
31
|
*
|
|
@@ -48,12 +42,14 @@ var debugging = dcpConfig.standaloneWorker.debug ? () => true : require('dcp/int
|
|
|
48
42
|
* . serial sequence number
|
|
49
43
|
* . serialize current serialization function
|
|
50
44
|
* . deserialize current deserialization function
|
|
45
|
+
* . config derived configuration
|
|
51
46
|
* - events:
|
|
52
47
|
* . error
|
|
53
48
|
* . message
|
|
54
49
|
*/
|
|
55
|
-
function StandaloneWorker(options = {})
|
|
56
|
-
|
|
50
|
+
function StandaloneWorker(options = {})
|
|
51
|
+
{
|
|
52
|
+
const that = this;
|
|
57
53
|
var readStream, writeStream;
|
|
58
54
|
var ee = new (require('events').EventEmitter)('StandaloneWorker');
|
|
59
55
|
var readBuf = ''
|
|
@@ -62,9 +58,28 @@ function StandaloneWorker(options = {}) {
|
|
|
62
58
|
var shutdown;
|
|
63
59
|
var connectTimer = false;
|
|
64
60
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
const defaultConfig = {
|
|
62
|
+
tuning: {
|
|
63
|
+
noDelay: true,
|
|
64
|
+
connectBackoff:
|
|
65
|
+
{
|
|
66
|
+
maxInterval: 5 * 60 * 1000, // max: 5 minutes
|
|
67
|
+
baseInterval: 10 * 1000, // start: 10s
|
|
68
|
+
backoffFactor: 1.1 // each fail, back off by 10%
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
this.config = leafMerge(
|
|
73
|
+
defaultConfig,
|
|
74
|
+
deepClone(dcpConfig.evaluator),
|
|
75
|
+
);
|
|
76
|
+
delete this.config.listen;
|
|
77
|
+
if (options.location)
|
|
78
|
+
this.config.location = options.location;
|
|
79
|
+
if (options.hostname)
|
|
80
|
+
this.config.location.hostname = options.hostname;
|
|
81
|
+
if (options.port)
|
|
82
|
+
this.config.location.port = options.port;
|
|
68
83
|
|
|
69
84
|
if (typeof options === 'object' && options.readStream) {
|
|
70
85
|
debugging('lifecycle') && console.debug('Connecting via supplied streams');
|
|
@@ -77,27 +92,20 @@ function StandaloneWorker(options = {}) {
|
|
|
77
92
|
if (!readStream) {
|
|
78
93
|
/* No supplied streams - reach out and connect over TCP/IP */
|
|
79
94
|
let socket = readStream = writeStream = new (require('net')).Socket().unref();
|
|
80
|
-
let hostname = 'hostname' in options ? options.hostname : dcpConfig.evaluator.location.hostname;
|
|
81
|
-
let port = 'port' in options ? options.port : dcpConfig.evaluator.location.port;
|
|
82
95
|
let connecting = true;
|
|
83
96
|
|
|
84
|
-
|
|
85
|
-
throw new Error(`Invalid evaluator hostname '${hostname}'`);
|
|
86
|
-
if (!Number(port) || port < 1 || port > 65535)
|
|
87
|
-
throw new Error(`Invalid evaluator port '${port}'`);
|
|
88
|
-
|
|
89
|
-
debugging('lifecycle') && console.debug('Connecting to', hostname + ':' + port);
|
|
97
|
+
debugging() && console.debug('Connecting to evaluator on', this.config.location.hostname + ':' + this.config.location.port);
|
|
90
98
|
connectTimer = setBackoffInterval(function saWorker$$connect$backoff() {
|
|
91
99
|
if (!connecting)
|
|
92
100
|
{
|
|
93
101
|
connecting = true;
|
|
94
|
-
socket.connect(port, hostname,
|
|
102
|
+
socket.connect(that.config.location.port, that.config.location.hostname, () => { connecting = false; });
|
|
95
103
|
}
|
|
96
|
-
},
|
|
104
|
+
}, this.config.tuning.connectBackoff);
|
|
97
105
|
connectTimer.unref();
|
|
98
106
|
|
|
99
|
-
socket.setNoDelay(
|
|
100
|
-
socket.connect(port, hostname);
|
|
107
|
+
socket.setNoDelay(this.config.tuning.noDelay ?? true);
|
|
108
|
+
socket.connect(this.config.location.port, this.config.location.hostname);
|
|
101
109
|
socket.on('connect', beginSession.bind(this));
|
|
102
110
|
|
|
103
111
|
let alreadySignaled = false;
|
|
@@ -281,14 +289,13 @@ function StandaloneWorker(options = {}) {
|
|
|
281
289
|
ee.emit('error', new Error('Unrecognized message type from worker #' + this.serial + ', \'' + lineObj.type + '\''))
|
|
282
290
|
}
|
|
283
291
|
} catch (e) {
|
|
284
|
-
|
|
285
|
-
throw e
|
|
292
|
+
ee.emit('error', 'Error processing remote response: \'' + line + '\' (' + e.name + ': ' + e.message + e.stack.split('\n')[1].replace(/^ */, ' ') + ')')
|
|
286
293
|
}
|
|
287
294
|
}
|
|
288
295
|
}.bind(this))
|
|
289
296
|
|
|
290
297
|
ee.on('error', function standaloneWorker$$Worker$recvData$error (e) {
|
|
291
|
-
console.error("Evaluator threw an error:", e);
|
|
298
|
+
debugging() && console.error("Evaluator threw an error:", e);
|
|
292
299
|
})
|
|
293
300
|
|
|
294
301
|
ee.on('message', function standaloneWorker$$Worker$recvData$message (ev) {
|
|
@@ -307,13 +314,13 @@ function StandaloneWorker(options = {}) {
|
|
|
307
314
|
readStream.destroy();
|
|
308
315
|
if (readStream !== writeStream)
|
|
309
316
|
writeStream.destroy();
|
|
310
|
-
} catch(
|
|
311
|
-
console.error(`Warning: could not shutdown evaluator connection ${e.code}`,
|
|
317
|
+
} catch(error) {
|
|
318
|
+
console.error(`Warning: could not shutdown evaluator connection ${e.code}`, error);
|
|
312
319
|
};
|
|
313
320
|
connected = false;
|
|
314
321
|
}
|
|
315
322
|
|
|
316
|
-
debugging('lifecycle') && console.debug('Connecting to', hostname + ':' + port);
|
|
323
|
+
debugging('lifecycle') && console.debug('Connecting to', this.config.location.hostname + ':' + this.config.location.port);
|
|
317
324
|
|
|
318
325
|
/** Send a message over the network to a standalone worker */
|
|
319
326
|
this.postMessage = function standaloneWorker$$Worker$postMessage (message) {
|
|
@@ -345,8 +352,9 @@ function StandaloneWorker(options = {}) {
|
|
|
345
352
|
}
|
|
346
353
|
|
|
347
354
|
/**
|
|
348
|
-
* Function to create constructors which behave very much like the WindowOrWorkerGlobalScope
|
|
349
|
-
*
|
|
355
|
+
* Function to create constructors which behave very much like the WindowOrWorkerGlobalScope Worker
|
|
356
|
+
* constructor, except they instanciate StandaloneWorker in place of a Web Worker. This factory
|
|
357
|
+
* captures the options parameter, so that invocation of the returned constructor does not need to
|
|
350
358
|
*
|
|
351
359
|
* @param options options with which to invoke the StandaloneWorker constructor
|
|
352
360
|
* when constructing workers.
|
|
@@ -355,6 +363,8 @@ exports.workerFactory = function standaloneWorker$$WorkerFactory(options)
|
|
|
355
363
|
{
|
|
356
364
|
function Worker()
|
|
357
365
|
{
|
|
366
|
+
if (!new.target)
|
|
367
|
+
throw new TypeError('Worker constructor: \'new\' is required');
|
|
358
368
|
return new StandaloneWorker(options);
|
|
359
369
|
}
|
|
360
370
|
|