@agoric/internal 0.3.3-dev-eb7e9eb.0 → 0.3.3-u11.0
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/CHANGELOG.md +106 -0
- package/README.md +2 -7
- package/package.json +12 -14
- package/src/action-types.d.ts +0 -1
- package/src/action-types.d.ts.map +1 -1
- package/src/action-types.js +0 -1
- package/src/batched-deliver.d.ts +1 -1
- package/src/batched-deliver.d.ts.map +1 -1
- package/src/callback.d.ts +4 -12
- package/src/callback.d.ts.map +1 -1
- package/src/callback.js +5 -5
- package/src/config.d.ts +12 -12
- package/src/lib-chainStorage.d.ts +3 -2
- package/src/lib-chainStorage.d.ts.map +1 -1
- package/src/lib-chainStorage.js +35 -4
- package/src/method-tools.d.ts +0 -1
- package/src/method-tools.d.ts.map +1 -1
- package/src/method-tools.js +0 -12
- package/src/node/buffer-line-transform.d.ts +1 -1
- package/src/node/buffer-line-transform.d.ts.map +1 -1
- package/src/queue.d.ts.map +1 -1
- package/src/queue.js +0 -1
- package/src/storage-test-utils.d.ts +3 -5
- package/src/storage-test-utils.d.ts.map +1 -1
- package/src/storage-test-utils.js +7 -5
- package/src/typeGuards.d.ts +0 -2
- package/src/typeGuards.d.ts.map +1 -1
- package/src/typeGuards.js +0 -8
- package/src/install-ses-debug.d.ts +0 -2
- package/src/install-ses-debug.d.ts.map +0 -1
- package/src/install-ses-debug.js +0 -6
- package/src/lib-nodejs/engine-gc.d.ts +0 -3
- package/src/lib-nodejs/engine-gc.d.ts.map +0 -1
- package/src/lib-nodejs/engine-gc.js +0 -22
- package/src/lib-nodejs/gc-and-finalize.d.ts +0 -2
- package/src/lib-nodejs/gc-and-finalize.d.ts.map +0 -1
- package/src/lib-nodejs/gc-and-finalize.js +0 -91
- package/src/lib-nodejs/spawnSubprocessWorker.d.ts +0 -16
- package/src/lib-nodejs/spawnSubprocessWorker.d.ts.map +0 -1
- package/src/lib-nodejs/spawnSubprocessWorker.js +0 -87
- package/src/lib-nodejs/waitUntilQuiescent.d.ts +0 -2
- package/src/lib-nodejs/waitUntilQuiescent.d.ts.map +0 -1
- package/src/lib-nodejs/waitUntilQuiescent.js +0 -18
- package/src/lib-nodejs/worker-protocol.d.ts +0 -4
- package/src/lib-nodejs/worker-protocol.d.ts.map +0 -1
- package/src/lib-nodejs/worker-protocol.js +0 -56
- package/src/marshal.d.ts +0 -17
- package/src/marshal.d.ts.map +0 -1
- package/src/marshal.js +0 -119
- package/src/netstring.d.ts +0 -13
- package/src/netstring.d.ts.map +0 -1
- package/src/netstring.js +0 -119
- package/src/tokens.d.ts +0 -34
- package/src/tokens.d.ts.map +0 -1
- package/src/tokens.js +0 -35
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import v8 from 'v8';
|
|
2
|
-
import vm from 'vm';
|
|
3
|
-
|
|
4
|
-
/* global globalThis */
|
|
5
|
-
let bestGC = globalThis.gc;
|
|
6
|
-
if (typeof bestGC !== 'function') {
|
|
7
|
-
// Node.js v8 wizardry.
|
|
8
|
-
v8.setFlagsFromString('--expose_gc');
|
|
9
|
-
bestGC = vm.runInNewContext('gc');
|
|
10
|
-
assert(bestGC);
|
|
11
|
-
// We leave --expose_gc turned on, otherwise AVA's shared workers
|
|
12
|
-
// may race and disable it before we manage to extract the
|
|
13
|
-
// binding. This won't cause 'gc' to be visible to new Compartments
|
|
14
|
-
// because SES strips out everything it doesn't recognize.
|
|
15
|
-
|
|
16
|
-
// // Hide the gc global from new contexts/workers.
|
|
17
|
-
// v8.setFlagsFromString('--no-expose_gc');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Export a const.
|
|
21
|
-
const engineGC = bestGC;
|
|
22
|
-
export default engineGC;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gc-and-finalize.d.ts","sourceRoot":"","sources":["gc-and-finalize.js"],"names":[],"mappings":"AAkEA,qEAwBC"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/* global setImmediate */
|
|
2
|
-
|
|
3
|
-
/* A note on our GC terminology:
|
|
4
|
-
*
|
|
5
|
-
* We define four states for any JS object to be in:
|
|
6
|
-
*
|
|
7
|
-
* REACHABLE: There exists a path from some root (live export or top-level
|
|
8
|
-
* global) to this object, making it ineligible for collection. Userspace vat
|
|
9
|
-
* code has a strong reference to it (and userspace is not given access to
|
|
10
|
-
* WeakRef, so it has no weak reference that might be used to get access).
|
|
11
|
-
*
|
|
12
|
-
* UNREACHABLE: There is no strong reference from a root to the object.
|
|
13
|
-
* Userspace vat code has no means to access the object, although liveslots
|
|
14
|
-
* might (via a WeakRef). The object is eligible for collection, but that
|
|
15
|
-
* collection has not yet happened. The liveslots WeakRef is still alive: if
|
|
16
|
-
* it were to call `.deref()`, it would get the object.
|
|
17
|
-
*
|
|
18
|
-
* COLLECTED: The JS engine has performed enough GC to notice the
|
|
19
|
-
* unreachability of the object, and has collected it. The liveslots WeakRef
|
|
20
|
-
* is dead: `wr.deref() === undefined`. Neither liveslots nor userspace has
|
|
21
|
-
* any way to reach the object, and never will again. A finalizer callback
|
|
22
|
-
* has been queued, but not yet executed.
|
|
23
|
-
*
|
|
24
|
-
* FINALIZED: The JS engine has run the finalizer callback. Once the
|
|
25
|
-
* callback completes, the object is thoroughly dead and unremembered,
|
|
26
|
-
* and no longer exists in one of these four states.
|
|
27
|
-
*
|
|
28
|
-
* The transition from REACHABLE to UNREACHABLE always happens as a result of
|
|
29
|
-
* a message delivery or resolution notification (e.g when userspace
|
|
30
|
-
* overwrites a variable, deletes a Map entry, or a callback on the promise
|
|
31
|
-
* queue which closed over some objects is retired and deleted).
|
|
32
|
-
*
|
|
33
|
-
* The transition from UNREACHABLE to COLLECTED can happen spontaneously, as
|
|
34
|
-
* the JS engine decides it wants to perform GC. It will also happen
|
|
35
|
-
* deliberately if we provoke a GC call with a magic function like `gc()`
|
|
36
|
-
* (when Node.js imports `engine-gc`, which is morally-equivalent to
|
|
37
|
-
* running with `--expose-gc`, or when XS is configured to provide it as a
|
|
38
|
-
* C-level callback). We can force GC, but we cannot prevent it from happening
|
|
39
|
-
* at other times.
|
|
40
|
-
*
|
|
41
|
-
* FinalizationRegistry callbacks are defined to run on their own turn, so
|
|
42
|
-
* the transition from COLLECTED to FINALIZED occurs at a turn boundary.
|
|
43
|
-
* Node.js appears to schedule these finalizers on the timer/IO queue, not
|
|
44
|
-
* the promise/microtask queue. So under Node.js, you need a `setImmediate()`
|
|
45
|
-
* or two to ensure that finalizers have had a chance to run. XS is different
|
|
46
|
-
* but responds well to similar techniques.
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
/*
|
|
50
|
-
* `gcAndFinalize` must be defined in the start compartment. It uses
|
|
51
|
-
* platform-specific features to provide a function which provokes a full GC
|
|
52
|
-
* operation: all "UNREACHABLE" objects should transition to "COLLECTED"
|
|
53
|
-
* before it returns. In addition, `gcAndFinalize()` returns a Promise. This
|
|
54
|
-
* Promise will resolve (with `undefined`) after all FinalizationRegistry
|
|
55
|
-
* callbacks have executed, causing all COLLECTED objects to transition to
|
|
56
|
-
* FINALIZED. If the caller can manage call gcAndFinalize with an empty
|
|
57
|
-
* promise queue, then their .then callback will also start with an empty
|
|
58
|
-
* promise queue, and there will be minimal uncollected unreachable objects
|
|
59
|
-
* in the heap when it begins.
|
|
60
|
-
*
|
|
61
|
-
* `gcAndFinalize` depends upon platform-specific tools to provoke a GC sweep
|
|
62
|
-
* and wait for finalizers to run: a `gc()` function, and `setImmediate`. If
|
|
63
|
-
* these tools do not exist, this function will do nothing, and return a
|
|
64
|
-
* dummy pre-resolved Promise.
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
export function makeGcAndFinalize(gcPower) {
|
|
68
|
-
if (typeof gcPower !== 'function') {
|
|
69
|
-
if (gcPower !== false) {
|
|
70
|
-
// We weren't explicitly disabled, so warn.
|
|
71
|
-
console.warn(
|
|
72
|
-
Error(`no gcPower() function; skipping finalizer provocation`),
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return async function gcAndFinalize() {
|
|
77
|
-
if (typeof gcPower !== 'function') {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// on Node.js, GC seems to work better if the promise queue is empty first
|
|
82
|
-
await new Promise(setImmediate);
|
|
83
|
-
// on xsnap, we must do it twice for some reason
|
|
84
|
-
await new Promise(setImmediate);
|
|
85
|
-
gcPower();
|
|
86
|
-
// this gives finalizers a chance to run
|
|
87
|
-
await new Promise(setImmediate);
|
|
88
|
-
// Node.js seems to need another for promises to get cleared out
|
|
89
|
-
await new Promise(setImmediate);
|
|
90
|
-
};
|
|
91
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
export function startSubprocessWorker(execPath: any, procArgs?: any[], { netstringMaxChunkSize }?: {
|
|
3
|
-
netstringMaxChunkSize?: undefined;
|
|
4
|
-
}): {
|
|
5
|
-
fromChild: {
|
|
6
|
-
on: (...args: any[]) => import("stream").Transform;
|
|
7
|
-
};
|
|
8
|
-
toChild: {
|
|
9
|
-
write: (...args: any[]) => boolean;
|
|
10
|
-
};
|
|
11
|
-
terminate: () => void;
|
|
12
|
-
done: Promise<any>;
|
|
13
|
-
};
|
|
14
|
-
export type IOType = import('child_process').IOType;
|
|
15
|
-
export type Writable = import('stream').Writable;
|
|
16
|
-
//# sourceMappingURL=spawnSubprocessWorker.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spawnSubprocessWorker.d.ts","sourceRoot":"","sources":["spawnSubprocessWorker.js"],"names":[],"mappings":";AA8BA;;;;;;;;;;;EAwDC;qBAlEc,OAAO,eAAe,EAAE,MAAM;uBAC9B,OAAO,QAAQ,EAAE,QAAQ"}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
// this file is loaded by the controller, in the start compartment
|
|
2
|
-
import { spawn } from 'child_process';
|
|
3
|
-
import { makePromiseKit } from '@endo/promise-kit';
|
|
4
|
-
import { NonNullish } from '@agoric/assert';
|
|
5
|
-
import { arrayEncoderStream, arrayDecoderStream } from './worker-protocol.js';
|
|
6
|
-
import {
|
|
7
|
-
netstringEncoderStream,
|
|
8
|
-
netstringDecoderStream,
|
|
9
|
-
} from '../netstring.js';
|
|
10
|
-
|
|
11
|
-
// Start a subprocess from a given executable, and arrange a bidirectional
|
|
12
|
-
// message channel with a "supervisor" within that process. Return a {
|
|
13
|
-
// toChild, fromChild } pair of Streams which accept/emit hardened Arrays of
|
|
14
|
-
// JSON-serializable data.
|
|
15
|
-
|
|
16
|
-
// eslint-disable-next-line no-unused-vars
|
|
17
|
-
function parentLog(first, ...args) {
|
|
18
|
-
// console.error(`--parent: ${first}`, ...args);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** @typedef { import('child_process').IOType } IOType */
|
|
22
|
-
/** @typedef { import('stream').Writable } Writable */
|
|
23
|
-
|
|
24
|
-
// we send on fd3, and receive on fd4. We pass fd1/2 (stdout/err) through, so
|
|
25
|
-
// console log/err from the child shows up normally. We don't use Node's
|
|
26
|
-
// built-in serialization feature ('ipc') because the child process won't
|
|
27
|
-
// always be Node.
|
|
28
|
-
/** @type { IOType[] } */
|
|
29
|
-
const stdio = harden(['inherit', 'inherit', 'inherit', 'pipe', 'pipe']);
|
|
30
|
-
|
|
31
|
-
export function startSubprocessWorker(
|
|
32
|
-
execPath,
|
|
33
|
-
procArgs = [],
|
|
34
|
-
{ netstringMaxChunkSize = undefined } = {},
|
|
35
|
-
) {
|
|
36
|
-
const proc = spawn(execPath, procArgs, { stdio });
|
|
37
|
-
|
|
38
|
-
const toChild = arrayEncoderStream();
|
|
39
|
-
toChild
|
|
40
|
-
.pipe(netstringEncoderStream())
|
|
41
|
-
.pipe(/** @type {Writable} */ (proc.stdio[3]));
|
|
42
|
-
// proc.stdio[4].setEncoding('utf-8');
|
|
43
|
-
const fromChild = NonNullish(proc.stdio[4])
|
|
44
|
-
.pipe(netstringDecoderStream(netstringMaxChunkSize))
|
|
45
|
-
.pipe(arrayDecoderStream());
|
|
46
|
-
|
|
47
|
-
// fromChild.addListener('data', data => parentLog(`fd4 data`, data));
|
|
48
|
-
// toChild.write('hello child');
|
|
49
|
-
|
|
50
|
-
const pk = makePromiseKit();
|
|
51
|
-
|
|
52
|
-
proc.once('exit', code => {
|
|
53
|
-
parentLog('child exit', code);
|
|
54
|
-
pk.resolve(code);
|
|
55
|
-
});
|
|
56
|
-
proc.once('error', e => {
|
|
57
|
-
parentLog('child error', e);
|
|
58
|
-
pk.reject(e);
|
|
59
|
-
});
|
|
60
|
-
parentLog(`waiting on child`);
|
|
61
|
-
|
|
62
|
-
function terminate() {
|
|
63
|
-
proc.kill();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// the Transform objects don't like being hardened, so we wrap the methods
|
|
67
|
-
// that get used
|
|
68
|
-
/* @type {typeof fromChild} */
|
|
69
|
-
const wrappedFromChild = {
|
|
70
|
-
on: (...args) =>
|
|
71
|
-
fromChild.on(.../** @type {Parameters<typeof fromChild['on']>} */ (args)),
|
|
72
|
-
};
|
|
73
|
-
/* @type {typeof toChild} */
|
|
74
|
-
const wrappedToChild = {
|
|
75
|
-
write: (...args) =>
|
|
76
|
-
toChild.write(
|
|
77
|
-
.../** @type {Parameters<typeof toChild['write']>} */ (args),
|
|
78
|
-
),
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
return harden({
|
|
82
|
-
fromChild: wrappedFromChild,
|
|
83
|
-
toChild: wrappedToChild,
|
|
84
|
-
terminate,
|
|
85
|
-
done: pk.promise,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"waitUntilQuiescent.d.ts","sourceRoot":"","sources":["waitUntilQuiescent.js"],"names":[],"mappings":"AAMA,oDAWC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/* global setImmediate */
|
|
2
|
-
import { makePromiseKit } from '@endo/promise-kit';
|
|
3
|
-
|
|
4
|
-
// This can only be imported from the Start Compartment, where 'setImmediate'
|
|
5
|
-
// is available.
|
|
6
|
-
|
|
7
|
-
export function waitUntilQuiescent() {
|
|
8
|
-
// the delivery might cause some number of (native) Promises to be
|
|
9
|
-
// created and resolved, so we use the IO queue to detect when the
|
|
10
|
-
// Promise queue is empty. The IO queue (setImmediate and setTimeout) is
|
|
11
|
-
// lower-priority than the Promise queue on browsers and Node 11, but on
|
|
12
|
-
// Node 10 it is higher. So this trick requires Node 11.
|
|
13
|
-
// https://jsblog.insiderattack.net/new-changes-to-timers-and-microtasks-from-node-v11-0-0-and-above-68d112743eb3
|
|
14
|
-
/** @type {import('@endo/promise-kit').PromiseKit<void>} */
|
|
15
|
-
const { promise: queueEmptyP, resolve } = makePromiseKit();
|
|
16
|
-
setImmediate(() => resolve());
|
|
17
|
-
return queueEmptyP;
|
|
18
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker-protocol.d.ts","sourceRoot":"","sources":["worker-protocol.js"],"names":[],"mappings":"AAMA,gDAsBC;AAED,gDAyBC;0BAtDyB,QAAQ"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/* global Buffer */
|
|
2
|
-
import { Transform } from 'stream';
|
|
3
|
-
|
|
4
|
-
// Transform objects which convert from hardened Arrays of JSON-serializable
|
|
5
|
-
// data into Buffers suitable for netstring conversion.
|
|
6
|
-
|
|
7
|
-
export function arrayEncoderStream() {
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @this {{ push: (b: Buffer) => void }}
|
|
11
|
-
* @param {*} object
|
|
12
|
-
* @param {BufferEncoding} encoding
|
|
13
|
-
* @param {*} callback
|
|
14
|
-
*/
|
|
15
|
-
function transform(object, encoding, callback) {
|
|
16
|
-
if (!Array.isArray(object)) {
|
|
17
|
-
throw Error('stream requires Arrays');
|
|
18
|
-
}
|
|
19
|
-
let err;
|
|
20
|
-
try {
|
|
21
|
-
this.push(Buffer.from(JSON.stringify(object)));
|
|
22
|
-
} catch (e) {
|
|
23
|
-
err = e;
|
|
24
|
-
}
|
|
25
|
-
callback(err);
|
|
26
|
-
}
|
|
27
|
-
// Array in, Buffer out, hence writableObjectMode
|
|
28
|
-
return new Transform({ transform, writableObjectMode: true });
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function arrayDecoderStream() {
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
* @this {{ push: (b: Buffer) => void }}
|
|
35
|
-
* @param {Buffer} buf
|
|
36
|
-
* @param {BufferEncoding} encoding
|
|
37
|
-
* @param {*} callback
|
|
38
|
-
*/
|
|
39
|
-
function transform(buf, encoding, callback) {
|
|
40
|
-
let err;
|
|
41
|
-
try {
|
|
42
|
-
if (!Buffer.isBuffer(buf)) {
|
|
43
|
-
throw Error('stream expects Buffers');
|
|
44
|
-
}
|
|
45
|
-
this.push(JSON.parse(buf.toString()));
|
|
46
|
-
} catch (e) {
|
|
47
|
-
err = e;
|
|
48
|
-
}
|
|
49
|
-
// this Transform is a one-to-one conversion of Buffer into Array, so we
|
|
50
|
-
// always consume the input each time we're called
|
|
51
|
-
callback(err);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Buffer in, Array out, hence readableObjectMode
|
|
55
|
-
return new Transform({ transform, readableObjectMode: true });
|
|
56
|
-
}
|
package/src/marshal.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export function makeBoardRemote({ boardId, iface }: any): BoardRemote;
|
|
2
|
-
export function slotToBoardRemote(boardId: any, iface: any): BoardRemote;
|
|
3
|
-
export function boardValToSlot(val: any): any;
|
|
4
|
-
export function boardSlottingMarshaller(slotToVal?: ((slot: string, iface: string) => any) | undefined): Omit<import('@endo/marshal').Marshal<string>, 'serialize' | 'unserialize'>;
|
|
5
|
-
export function unmarshalFromVstorage(data: Map<string, string>, key: string, fromCapData: ReturnType<typeof import('@endo/marshal').makeMarshal>['fromCapData'], index: number): any;
|
|
6
|
-
export function makeHistoryReviver(entries: Array<[string, string]>, slotToVal?: ((slot: string, iface?: string) => any) | undefined): {
|
|
7
|
-
getItem: (key: any) => any;
|
|
8
|
-
children: (prefix: any) => string[];
|
|
9
|
-
has: (k: any) => boolean;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Should be a union with Remotable, but that's `any`, making this type meaningless
|
|
13
|
-
*/
|
|
14
|
-
export type BoardRemote = {
|
|
15
|
-
getBoardId: () => string;
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=marshal.d.ts.map
|
package/src/marshal.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"marshal.d.ts","sourceRoot":"","sources":["marshal.js"],"names":[],"mappings":"AAgBO,0DAFM,WAAW,CAKvB;AAEM,yEAC8B;AAE9B,8CAKN;AAWM,4DAHW,MAAM,SAAS,MAAM,KAAK,GAAG,gBAClC,KAAK,OAAO,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC,CAMtF;AAyBM,4CALI,IAAI,MAAM,EAAE,MAAM,CAAC,OACnB,MAAM,eACN,WAAW,cAAc,eAAe,EAAE,WAAW,CAAC,CAAC,aAAa,CAAC,SACrE,MAAM,OAwBhB;AASM,4CAHI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,sBAChB,MAAM,UAAU,MAAM,KAAK,GAAG;;;;EAoB/C;;;;0BA7GY;IAAE,UAAU,EAAE,MAAM,MAAM,CAAA;CAAE"}
|
package/src/marshal.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { Far } from '@endo/far';
|
|
2
|
-
import { makeMarshal } from '@endo/marshal';
|
|
3
|
-
import { isStreamCell } from './lib-chainStorage.js';
|
|
4
|
-
|
|
5
|
-
const { Fail } = assert;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Should be a union with Remotable, but that's `any`, making this type meaningless
|
|
9
|
-
*
|
|
10
|
-
* @typedef {{ getBoardId: () => string }} BoardRemote
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @param {*} slotInfo
|
|
15
|
-
* @returns {BoardRemote}
|
|
16
|
-
*/
|
|
17
|
-
export const makeBoardRemote = ({ boardId, iface }) => {
|
|
18
|
-
const nonalleged = iface ? iface.replace(/^Alleged: /, '') : '';
|
|
19
|
-
return Far(`BoardRemote${nonalleged}`, { getBoardId: () => boardId });
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const slotToBoardRemote = (boardId, iface) =>
|
|
23
|
-
makeBoardRemote({ boardId, iface });
|
|
24
|
-
|
|
25
|
-
export const boardValToSlot = val => {
|
|
26
|
-
if ('getBoardId' in val) {
|
|
27
|
-
return val.getBoardId();
|
|
28
|
-
}
|
|
29
|
-
Fail`unknown obj in boardSlottingMarshaller.valToSlot ${val}`;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* A marshaller which can serialize getBoardId() -bearing
|
|
34
|
-
* Remotables. This allows the caller to pick their slots. The
|
|
35
|
-
* deserializer is configurable: the default cannot handle
|
|
36
|
-
* Remotable-bearing data.
|
|
37
|
-
*
|
|
38
|
-
* @param {(slot: string, iface: string) => any} [slotToVal]
|
|
39
|
-
* @returns {Omit<import('@endo/marshal').Marshal<string>, 'serialize' | 'unserialize'>}
|
|
40
|
-
*/
|
|
41
|
-
export const boardSlottingMarshaller = (slotToVal = undefined) => {
|
|
42
|
-
return makeMarshal(boardValToSlot, slotToVal, {
|
|
43
|
-
serializeBodyFormat: 'smallcaps',
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// TODO: Consolidate with `insistCapData` functions from swingset-liveslots,
|
|
48
|
-
// swingset-xsnap-supervisor, etc.
|
|
49
|
-
/**
|
|
50
|
-
* @param {unknown} data
|
|
51
|
-
* @returns {asserts data is import('@endo/marshal').CapData<string>}
|
|
52
|
-
*/
|
|
53
|
-
const assertCapData = data => {
|
|
54
|
-
assert.typeof(data, 'object');
|
|
55
|
-
assert(data);
|
|
56
|
-
assert.typeof(data.body, 'string');
|
|
57
|
-
assert(Array.isArray(data.slots));
|
|
58
|
-
// XXX check that the .slots array elements are actually strings
|
|
59
|
-
};
|
|
60
|
-
harden(assertCapData);
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Read and unmarshal a value from a map representation of vstorage data
|
|
64
|
-
*
|
|
65
|
-
* @param {Map<string, string>} data
|
|
66
|
-
* @param {string} key
|
|
67
|
-
* @param {ReturnType<typeof import('@endo/marshal').makeMarshal>['fromCapData']} fromCapData
|
|
68
|
-
* @param {number} index index of the desired value in a deserialized stream cell
|
|
69
|
-
*/
|
|
70
|
-
export const unmarshalFromVstorage = (data, key, fromCapData, index) => {
|
|
71
|
-
const serialized = data.get(key) || Fail`no data for ${key}`;
|
|
72
|
-
assert.typeof(serialized, 'string');
|
|
73
|
-
assert.typeof(index, 'number');
|
|
74
|
-
|
|
75
|
-
const streamCell = JSON.parse(serialized);
|
|
76
|
-
if (!isStreamCell(streamCell)) {
|
|
77
|
-
throw Fail`not a StreamCell: ${streamCell}`;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const { values } = streamCell;
|
|
81
|
-
values.length > 0 || Fail`no StreamCell values: ${streamCell}`;
|
|
82
|
-
|
|
83
|
-
const marshalled = values.at(index);
|
|
84
|
-
assert.typeof(marshalled, 'string');
|
|
85
|
-
|
|
86
|
-
/** @type {import("@endo/marshal").CapData<string>} */
|
|
87
|
-
const capData = harden(JSON.parse(marshalled));
|
|
88
|
-
assertCapData(capData);
|
|
89
|
-
|
|
90
|
-
const unmarshalled = fromCapData(capData);
|
|
91
|
-
return unmarshalled;
|
|
92
|
-
};
|
|
93
|
-
harden(unmarshalFromVstorage);
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Provide access to object graphs serialized in vstorage.
|
|
97
|
-
*
|
|
98
|
-
* @param {Array<[string, string]>} entries
|
|
99
|
-
* @param {(slot: string, iface?: string) => any} [slotToVal]
|
|
100
|
-
*/
|
|
101
|
-
export const makeHistoryReviver = (entries, slotToVal = undefined) => {
|
|
102
|
-
const board = boardSlottingMarshaller(slotToVal);
|
|
103
|
-
const vsMap = new Map(entries);
|
|
104
|
-
const fromCapData = (...args) =>
|
|
105
|
-
Reflect.apply(board.fromCapData, board, args);
|
|
106
|
-
const getItem = key => unmarshalFromVstorage(vsMap, key, fromCapData, -1);
|
|
107
|
-
const children = prefix => {
|
|
108
|
-
prefix.endsWith('.') || Fail`prefix must end with '.'`;
|
|
109
|
-
return harden([
|
|
110
|
-
...new Set(
|
|
111
|
-
entries
|
|
112
|
-
.map(([k, _]) => k)
|
|
113
|
-
.filter(k => k.startsWith(prefix))
|
|
114
|
-
.map(k => k.slice(prefix.length).split('.')[0]),
|
|
115
|
-
),
|
|
116
|
-
]);
|
|
117
|
-
};
|
|
118
|
-
return harden({ getItem, children, has: k => vsMap.get(k) !== undefined });
|
|
119
|
-
};
|
package/src/netstring.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {Buffer} data
|
|
3
|
-
* @returns {Buffer} netstring-wrapped
|
|
4
|
-
*/
|
|
5
|
-
export function encode(data: Buffer): Buffer;
|
|
6
|
-
export function netstringEncoderStream(): Transform;
|
|
7
|
-
export function decode(data: any, optMaxChunkSize: any): {
|
|
8
|
-
leftover: any;
|
|
9
|
-
payloads: any[];
|
|
10
|
-
};
|
|
11
|
-
export function netstringDecoderStream(optMaxChunkSize: any): Transform;
|
|
12
|
-
import { Transform } from 'stream';
|
|
13
|
-
//# sourceMappingURL=netstring.d.ts.map
|
package/src/netstring.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"netstring.d.ts","sourceRoot":"","sources":["netstring.js"],"names":[],"mappings":"AASA;;;GAGG;AACH,6BAHW,MAAM,GACJ,MAAM,CAMlB;AAGD,oDAuBC;AAMD;;;EAgCC;AAGD,wEAkCC;0BAlHyB,QAAQ"}
|
package/src/netstring.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/* global Buffer */
|
|
2
|
-
import { Fail } from '@agoric/assert';
|
|
3
|
-
|
|
4
|
-
// adapted from 'netstring-stream', https://github.com/tlivings/netstring-stream/
|
|
5
|
-
import { Transform } from 'stream';
|
|
6
|
-
|
|
7
|
-
const COLON = 58;
|
|
8
|
-
const COMMA = 44;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @param {Buffer} data
|
|
12
|
-
* @returns {Buffer} netstring-wrapped
|
|
13
|
-
*/
|
|
14
|
-
export function encode(data) {
|
|
15
|
-
const prefix = Buffer.from(`${data.length}:`);
|
|
16
|
-
const suffix = Buffer.from(',');
|
|
17
|
-
return Buffer.concat([prefix, data, suffix]);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// input is a sequence of strings, output is a byte pipe
|
|
21
|
-
export function netstringEncoderStream() {
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @this {{ push: (b: Buffer) => void }}
|
|
25
|
-
* @param {Buffer} chunk
|
|
26
|
-
* @param {BufferEncoding} encoding
|
|
27
|
-
* @param {*} callback
|
|
28
|
-
*/
|
|
29
|
-
function transform(chunk, encoding, callback) {
|
|
30
|
-
if (!Buffer.isBuffer(chunk)) {
|
|
31
|
-
throw Error('stream requires Buffers');
|
|
32
|
-
}
|
|
33
|
-
let err;
|
|
34
|
-
try {
|
|
35
|
-
this.push(encode(chunk));
|
|
36
|
-
} catch (e) {
|
|
37
|
-
err = e;
|
|
38
|
-
}
|
|
39
|
-
callback(err);
|
|
40
|
-
}
|
|
41
|
-
// (maybe empty) Buffer in, Buffer out. We use writableObjectMode to
|
|
42
|
-
// indicate that empty input buffers are important
|
|
43
|
-
return new Transform({ transform, writableObjectMode: true });
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Input is a Buffer containing zero or more netstrings and maybe some
|
|
47
|
-
// leftover bytes. Output is zero or more decoded Buffers, one per netstring,
|
|
48
|
-
// plus a Buffer of leftover bytes.
|
|
49
|
-
//
|
|
50
|
-
export function decode(data, optMaxChunkSize) {
|
|
51
|
-
// TODO: it would be more efficient to accumulate pending data in an array,
|
|
52
|
-
// rather than doing a concat each time
|
|
53
|
-
let start = 0;
|
|
54
|
-
const payloads = [];
|
|
55
|
-
|
|
56
|
-
for (;;) {
|
|
57
|
-
const colon = data.indexOf(COLON, start);
|
|
58
|
-
if (colon === -1) {
|
|
59
|
-
break; // still waiting for `${LENGTH}:`
|
|
60
|
-
}
|
|
61
|
-
const sizeString = data.toString('utf-8', start, colon);
|
|
62
|
-
const size = parseInt(sizeString, 10);
|
|
63
|
-
if (!(size > -1)) {
|
|
64
|
-
// reject NaN, all negative numbers
|
|
65
|
-
Fail`unparsable size ${sizeString}, should be integer`;
|
|
66
|
-
}
|
|
67
|
-
if (optMaxChunkSize) {
|
|
68
|
-
size <= optMaxChunkSize ||
|
|
69
|
-
Fail`size ${size} exceeds limit of ${optMaxChunkSize}`;
|
|
70
|
-
}
|
|
71
|
-
if (data.length < colon + 1 + size + 1) {
|
|
72
|
-
break; // still waiting for `${DATA}.`
|
|
73
|
-
}
|
|
74
|
-
data[colon + 1 + size] === COMMA ||
|
|
75
|
-
Fail`malformed netstring: not terminated by comma`;
|
|
76
|
-
payloads.push(data.subarray(colon + 1, colon + 1 + size));
|
|
77
|
-
start = colon + 1 + size + 1;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const leftover = data.subarray(start);
|
|
81
|
-
return { leftover, payloads };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// input is a byte pipe, output is a sequence of Buffers
|
|
85
|
-
export function netstringDecoderStream(optMaxChunkSize) {
|
|
86
|
-
let buffered = Buffer.from('');
|
|
87
|
-
/**
|
|
88
|
-
*
|
|
89
|
-
* @this {{ push: (b: Buffer) => void }}
|
|
90
|
-
* @param {Buffer} chunk
|
|
91
|
-
* @param {BufferEncoding} encoding
|
|
92
|
-
* @param {*} callback
|
|
93
|
-
*/
|
|
94
|
-
function transform(chunk, encoding, callback) {
|
|
95
|
-
if (!Buffer.isBuffer(chunk)) {
|
|
96
|
-
throw Error('stream requires Buffers');
|
|
97
|
-
}
|
|
98
|
-
buffered = Buffer.concat([buffered, chunk]);
|
|
99
|
-
let err;
|
|
100
|
-
try {
|
|
101
|
-
const { leftover, payloads } = decode(buffered, optMaxChunkSize);
|
|
102
|
-
buffered = leftover;
|
|
103
|
-
for (let i = 0; i < payloads.length; i += 1) {
|
|
104
|
-
this.push(payloads[i]);
|
|
105
|
-
}
|
|
106
|
-
} catch (e) {
|
|
107
|
-
err = e;
|
|
108
|
-
}
|
|
109
|
-
// we buffer all data internally, to accommodate netstrings larger than
|
|
110
|
-
// Transform's default buffer size, and callback() indicates that we've
|
|
111
|
-
// consumed the input
|
|
112
|
-
callback(err);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Buffer in, Buffer out, except that each output Buffer is precious, even
|
|
116
|
-
// empty ones, and without readableObjectMode the Stream will discard empty
|
|
117
|
-
// buffers
|
|
118
|
-
return new Transform({ transform, readableObjectMode: true });
|
|
119
|
-
}
|
package/src/tokens.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export namespace Stable {
|
|
2
|
-
export let symbol: "IST";
|
|
3
|
-
export let denom: "uist";
|
|
4
|
-
export let proposedName: "Agoric stable token";
|
|
5
|
-
export { NAT as assetKind };
|
|
6
|
-
export namespace displayInfo {
|
|
7
|
-
export let decimalPlaces: 6;
|
|
8
|
-
export { NAT as assetKind };
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export namespace Stake {
|
|
12
|
-
let symbol_1: "BLD";
|
|
13
|
-
export { symbol_1 as symbol };
|
|
14
|
-
let denom_1: "ubld";
|
|
15
|
-
export { denom_1 as denom };
|
|
16
|
-
let proposedName_1: "Agoric staking token";
|
|
17
|
-
export { proposedName_1 as proposedName };
|
|
18
|
-
export { NAT as assetKind };
|
|
19
|
-
export namespace displayInfo_1 {
|
|
20
|
-
let decimalPlaces_1: 6;
|
|
21
|
-
export { decimalPlaces_1 as decimalPlaces };
|
|
22
|
-
export { NAT as assetKind };
|
|
23
|
-
}
|
|
24
|
-
export { displayInfo_1 as displayInfo };
|
|
25
|
-
}
|
|
26
|
-
export type TokenKeyword = 'IST' | 'BLD';
|
|
27
|
-
/** @typedef {'IST' | 'BLD'} TokenKeyword */
|
|
28
|
-
/**
|
|
29
|
-
* This is defined by ERTP. For dependency pragmatism it's repeated here. We
|
|
30
|
-
* rely on the static type check and unit tests to detect any incompatibility.
|
|
31
|
-
*/
|
|
32
|
-
declare const NAT: "nat";
|
|
33
|
-
export {};
|
|
34
|
-
//# sourceMappingURL=tokens.d.ts.map
|
package/src/tokens.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["tokens.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;2BAEc,KAAK,GAAG,KAAK;AAA3B,4CAA4C;AAE5C;;;GAGG;AACH,yBAAkB"}
|
package/src/tokens.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
/** @typedef {'IST' | 'BLD'} TokenKeyword */
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* This is defined by ERTP. For dependency pragmatism it's repeated here. We
|
|
7
|
-
* rely on the static type check and unit tests to detect any incompatibility.
|
|
8
|
-
*/
|
|
9
|
-
const NAT = 'nat';
|
|
10
|
-
|
|
11
|
-
export const Stable = harden(
|
|
12
|
-
/** @type {const} */ ({
|
|
13
|
-
symbol: 'IST',
|
|
14
|
-
denom: 'uist',
|
|
15
|
-
proposedName: 'Agoric stable token',
|
|
16
|
-
assetKind: NAT,
|
|
17
|
-
displayInfo: {
|
|
18
|
-
decimalPlaces: 6,
|
|
19
|
-
assetKind: NAT,
|
|
20
|
-
},
|
|
21
|
-
}),
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
export const Stake = harden(
|
|
25
|
-
/** @type {const} */ ({
|
|
26
|
-
symbol: 'BLD',
|
|
27
|
-
denom: 'ubld',
|
|
28
|
-
proposedName: 'Agoric staking token',
|
|
29
|
-
assetKind: NAT,
|
|
30
|
-
displayInfo: {
|
|
31
|
-
decimalPlaces: 6,
|
|
32
|
-
assetKind: NAT,
|
|
33
|
-
},
|
|
34
|
-
}),
|
|
35
|
-
);
|