@agoric/internal 0.4.0-upgrade-14-dev-c8f9e7b.0 → 0.4.0-upgrade-16a-dev-fb592e4.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/README.md +7 -2
- package/exported.js +2 -0
- package/package.json +32 -16
- package/src/action-types.d.ts +1 -0
- package/src/action-types.d.ts.map +1 -1
- package/src/action-types.js +1 -0
- package/src/batched-deliver.d.ts +9 -6
- package/src/batched-deliver.d.ts.map +1 -1
- package/src/batched-deliver.js +9 -3
- package/src/callback.d.ts +23 -16
- package/src/callback.d.ts.map +1 -1
- package/src/callback.js +35 -39
- package/src/chain-storage-paths.d.ts +2 -3
- package/src/chain-storage-paths.d.ts.map +1 -1
- package/src/chain-storage-paths.js +2 -3
- package/src/config.d.ts +21 -12
- package/src/config.d.ts.map +1 -1
- package/src/config.js +20 -10
- package/src/debug.d.ts +1 -1
- package/src/index.d.ts +3 -0
- package/src/index.js +7 -1
- package/src/install-ses-debug.d.ts +2 -0
- package/src/install-ses-debug.d.ts.map +1 -0
- package/src/install-ses-debug.js +6 -0
- package/src/lib-chainStorage.d.ts +42 -52
- package/src/lib-chainStorage.d.ts.map +1 -1
- package/src/lib-chainStorage.js +82 -74
- package/src/lib-nodejs/engine-gc.d.ts +3 -0
- package/src/lib-nodejs/engine-gc.d.ts.map +1 -0
- package/src/lib-nodejs/engine-gc.js +22 -0
- package/src/lib-nodejs/gc-and-finalize.d.ts +2 -0
- package/src/lib-nodejs/gc-and-finalize.d.ts.map +1 -0
- package/src/lib-nodejs/gc-and-finalize.js +91 -0
- package/src/lib-nodejs/spawnSubprocessWorker.d.ts +15 -0
- package/src/lib-nodejs/spawnSubprocessWorker.d.ts.map +1 -0
- package/src/lib-nodejs/spawnSubprocessWorker.js +89 -0
- package/src/lib-nodejs/waitUntilQuiescent.d.ts +2 -0
- package/src/lib-nodejs/waitUntilQuiescent.d.ts.map +1 -0
- package/src/lib-nodejs/waitUntilQuiescent.js +18 -0
- package/src/lib-nodejs/worker-protocol.d.ts +4 -0
- package/src/lib-nodejs/worker-protocol.d.ts.map +1 -0
- package/src/lib-nodejs/worker-protocol.js +54 -0
- package/src/magic-cookie-test-only.js +2 -2
- package/src/marshal.d.ts +20 -0
- package/src/marshal.d.ts.map +1 -0
- package/src/marshal.js +138 -0
- package/src/method-tools.d.ts +1 -0
- package/src/method-tools.d.ts.map +1 -1
- package/src/method-tools.js +29 -16
- package/src/netstring.d.ts +24 -0
- package/src/netstring.d.ts.map +1 -0
- package/src/netstring.js +124 -0
- package/src/node/buffer-line-transform.d.ts +17 -13
- package/src/node/buffer-line-transform.d.ts.map +1 -1
- package/src/node/buffer-line-transform.js +11 -8
- package/src/node/fs-stream.d.ts.map +1 -1
- package/src/node/fs-stream.js +2 -3
- package/src/node/utils.d.ts +9 -0
- package/src/node/utils.d.ts.map +1 -0
- package/src/node/utils.js +46 -0
- package/src/priority-senders.d.ts +1 -1
- package/src/priority-senders.d.ts.map +1 -1
- package/src/priority-senders.js +7 -3
- package/src/queue.d.ts +1 -1
- package/src/queue.d.ts.map +1 -1
- package/src/queue.js +7 -8
- package/src/scratch.d.ts +1 -1
- package/src/scratch.d.ts.map +1 -1
- package/src/storage-test-utils.d.ts +43 -81
- package/src/storage-test-utils.d.ts.map +1 -1
- package/src/storage-test-utils.js +103 -40
- package/src/tagged.d.ts +155 -0
- package/src/testing-utils.d.ts.map +1 -1
- package/src/testing-utils.js +7 -5
- package/src/tokens.d.ts +34 -0
- package/src/tokens.d.ts.map +1 -0
- package/src/tokens.js +35 -0
- package/src/typeGuards.d.ts +2 -0
- package/src/typeGuards.d.ts.map +1 -1
- package/src/typeGuards.js +8 -0
- package/src/types.d.ts +46 -0
- package/src/types.js +2 -0
- package/src/upgrade-api.d.ts +13 -4
- package/src/upgrade-api.d.ts.map +1 -1
- package/src/upgrade-api.js +26 -18
- package/src/utils.d.ts +26 -31
- package/src/utils.d.ts.map +1 -1
- package/src/utils.js +53 -227
- package/CHANGELOG.md +0 -137
|
@@ -1,41 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Create a heap-based root storage node for a given backing function and root
|
|
2
|
+
* Create a heap-based root storage node for a given backing function and root
|
|
3
|
+
* path.
|
|
3
4
|
*
|
|
4
5
|
* @param {(message: StorageMessage) => any} handleStorageMessage a function for
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* sending a storageMessage object to the storage implementation (cf.
|
|
7
|
+
* golang/cosmos/x/vstorage/vstorage.go)
|
|
7
8
|
* @param {string} rootPath
|
|
8
9
|
* @param {object} [rootOptions]
|
|
9
10
|
* @param {boolean} [rootOptions.sequence] employ a wrapping structure that
|
|
10
|
-
*
|
|
11
|
-
*
|
|
11
|
+
* preserves each value set within a single block, and default child nodes to
|
|
12
|
+
* do the same
|
|
12
13
|
*/
|
|
13
14
|
export function makeChainStorageRoot(handleStorageMessage: (message: StorageMessage) => any, rootPath: string, rootOptions?: {
|
|
14
15
|
sequence?: boolean | undefined;
|
|
15
|
-
} | undefined): {
|
|
16
|
+
} | undefined): import("@endo/exo").Guarded<{
|
|
16
17
|
getPath(): string;
|
|
17
18
|
/**
|
|
18
19
|
* @deprecated use getPath
|
|
19
20
|
* @type {() => Promise<VStorageKey>}
|
|
20
21
|
*/
|
|
21
22
|
getStoreKey(): Promise<VStorageKey>;
|
|
22
|
-
/** @type {(name: string, childNodeOptions?: {sequence?: boolean}) => StorageNode} */
|
|
23
|
-
makeChildNode(name: string, childNodeOptions?: {
|
|
24
|
-
sequence?: boolean | undefined;
|
|
25
|
-
} | undefined): StorageNode;
|
|
26
|
-
/** @type {(value: string) => Promise<void>} */
|
|
27
|
-
setValue(value: string): Promise<void>;
|
|
28
|
-
} & import("@endo/eventual-send").RemotableBrand<{}, {
|
|
29
|
-
getPath(): string;
|
|
30
23
|
/**
|
|
31
|
-
* @
|
|
32
|
-
*
|
|
24
|
+
* @type {(
|
|
25
|
+
* name: string,
|
|
26
|
+
* childNodeOptions?: { sequence?: boolean },
|
|
27
|
+
* ) => StorageNode}
|
|
33
28
|
*/
|
|
34
|
-
getStoreKey(): Promise<VStorageKey>;
|
|
35
|
-
/** @type {(name: string, childNodeOptions?: {sequence?: boolean}) => StorageNode} */
|
|
36
29
|
makeChildNode(name: string, childNodeOptions?: {
|
|
37
|
-
sequence?: boolean
|
|
38
|
-
}
|
|
30
|
+
sequence?: boolean;
|
|
31
|
+
}): StorageNode;
|
|
39
32
|
/** @type {(value: string) => Promise<void>} */
|
|
40
33
|
setValue(value: string): Promise<void>;
|
|
41
34
|
}>;
|
|
@@ -44,48 +37,39 @@ export function makeChainStorageRoot(handleStorageMessage: (message: StorageMess
|
|
|
44
37
|
* falling back to an inert object with the correct interface (but incomplete
|
|
45
38
|
* behavior) when that is unavailable.
|
|
46
39
|
*
|
|
47
|
-
* @param {
|
|
40
|
+
* @param {ERef<StorageNode?>} storageNodeRef
|
|
48
41
|
* @param {string} childName
|
|
49
42
|
* @returns {Promise<StorageNode>}
|
|
50
43
|
*/
|
|
51
|
-
export function makeStorageNodeChild(storageNodeRef:
|
|
52
|
-
export function isStreamCell(cell: any): cell is StreamCell
|
|
44
|
+
export function makeStorageNodeChild(storageNodeRef: ERef<StorageNode | null>, childName: string): Promise<StorageNode>;
|
|
45
|
+
export function isStreamCell(cell: any): cell is StreamCell;
|
|
53
46
|
export function assertCapData(data: unknown): asserts data is import("@endo/marshal").CapData<string>;
|
|
54
|
-
export function unmarshalFromVstorage(data: Map<string, string>, key: string, fromCapData: ReturnType<typeof import('@endo/marshal').makeMarshal>['fromCapData'], index?: number | undefined): any;
|
|
55
47
|
/** @type {(name: string) => void} */
|
|
56
48
|
export const assertPathSegment: (name: string) => void;
|
|
57
|
-
export function prepareChainStorageNode(zone: import(
|
|
49
|
+
export function prepareChainStorageNode(zone: import("@agoric/base-zone").Zone): (messenger: import("./types.js").Callback<(message: StorageMessage) => any>, path: string, args_2?: {
|
|
58
50
|
sequence?: boolean | undefined;
|
|
59
|
-
} | undefined) => {
|
|
51
|
+
} | undefined) => import("@endo/exo").Guarded<{
|
|
60
52
|
getPath(): string;
|
|
61
53
|
/**
|
|
62
54
|
* @deprecated use getPath
|
|
63
55
|
* @type {() => Promise<VStorageKey>}
|
|
64
56
|
*/
|
|
65
57
|
getStoreKey(): Promise<VStorageKey>;
|
|
66
|
-
/** @type {(name: string, childNodeOptions?: {sequence?: boolean}) => StorageNode} */
|
|
67
|
-
makeChildNode(name: string, childNodeOptions?: {
|
|
68
|
-
sequence?: boolean | undefined;
|
|
69
|
-
} | undefined): StorageNode;
|
|
70
|
-
/** @type {(value: string) => Promise<void>} */
|
|
71
|
-
setValue(value: string): Promise<void>;
|
|
72
|
-
} & import("@endo/eventual-send").RemotableBrand<{}, {
|
|
73
|
-
getPath(): string;
|
|
74
58
|
/**
|
|
75
|
-
* @
|
|
76
|
-
*
|
|
59
|
+
* @type {(
|
|
60
|
+
* name: string,
|
|
61
|
+
* childNodeOptions?: { sequence?: boolean },
|
|
62
|
+
* ) => StorageNode}
|
|
77
63
|
*/
|
|
78
|
-
getStoreKey(): Promise<VStorageKey>;
|
|
79
|
-
/** @type {(name: string, childNodeOptions?: {sequence?: boolean}) => StorageNode} */
|
|
80
64
|
makeChildNode(name: string, childNodeOptions?: {
|
|
81
|
-
sequence?: boolean
|
|
82
|
-
}
|
|
65
|
+
sequence?: boolean;
|
|
66
|
+
}): StorageNode;
|
|
83
67
|
/** @type {(value: string) => Promise<void>} */
|
|
84
68
|
setValue(value: string): Promise<void>;
|
|
85
69
|
}>;
|
|
86
|
-
export function makeSerializeToStorage(storageNode:
|
|
87
|
-
export type Marshaller = ReturnType<typeof import(
|
|
88
|
-
export type Unserializer = Pick<Marshaller,
|
|
70
|
+
export function makeSerializeToStorage(storageNode: ERef<StorageNode>, marshaller: ERef<Marshaller>): (value: PassableCap) => Promise<void>;
|
|
71
|
+
export type Marshaller = ReturnType<typeof import("@endo/marshal").makeMarshal>;
|
|
72
|
+
export type Unserializer = Pick<Marshaller, "fromCapData">;
|
|
89
73
|
/**
|
|
90
74
|
* Defined by vstorageStoreKey in vstorage.go
|
|
91
75
|
*/
|
|
@@ -105,7 +89,8 @@ export type StreamCell<T = unknown> = {
|
|
|
105
89
|
/**
|
|
106
90
|
* This represents a node in an IAVL tree.
|
|
107
91
|
*
|
|
108
|
-
* The active implementation is x/vstorage, an Agoric extension of the Cosmos
|
|
92
|
+
* The active implementation is x/vstorage, an Agoric extension of the Cosmos
|
|
93
|
+
* SDK.
|
|
109
94
|
*
|
|
110
95
|
* Vstorage is a hierarchical externally-reachable storage structure that
|
|
111
96
|
* identifies children by restricted ASCII name and is associated with arbitrary
|
|
@@ -117,7 +102,8 @@ export type StorageNode = {
|
|
|
117
102
|
*/
|
|
118
103
|
setValue: (data: string) => Promise<void>;
|
|
119
104
|
/**
|
|
120
|
-
* the chain storage path at which the node was
|
|
105
|
+
* the chain storage path at which the node was
|
|
106
|
+
* constructed
|
|
121
107
|
*/
|
|
122
108
|
getPath: () => string;
|
|
123
109
|
/**
|
|
@@ -130,26 +116,28 @@ export type StorageNode = {
|
|
|
130
116
|
};
|
|
131
117
|
export type StoredFacet = {
|
|
132
118
|
/**
|
|
133
|
-
* the chain storage path at which the
|
|
119
|
+
* the chain storage path at which the
|
|
120
|
+
* node was constructed
|
|
134
121
|
*/
|
|
135
122
|
getPath: () => Promise<string>;
|
|
136
123
|
/**
|
|
137
124
|
* DEPRECATED use getPath
|
|
138
125
|
*/
|
|
139
|
-
getStoreKey: StorageNode[
|
|
126
|
+
getStoreKey: StorageNode["getStoreKey"];
|
|
140
127
|
/**
|
|
141
|
-
* get the unserializer for the
|
|
128
|
+
* get the unserializer for the
|
|
129
|
+
* stored data
|
|
142
130
|
*/
|
|
143
131
|
getUnserializer: () => Unserializer;
|
|
144
132
|
};
|
|
145
133
|
/**
|
|
146
134
|
* Must match the switch in vstorage.go using `vstorageMessage` type
|
|
147
135
|
*/
|
|
148
|
-
export type StorageGetByPathMessageMethod =
|
|
136
|
+
export type StorageGetByPathMessageMethod = "get" | "getStoreKey" | "has" | "children" | "entries" | "values" | "size";
|
|
149
137
|
/**
|
|
150
138
|
* Must match the switch in vstorage.go using `vstorageMessage` type
|
|
151
139
|
*/
|
|
152
|
-
export type StorageUpdateEntriesMessageMethod =
|
|
140
|
+
export type StorageUpdateEntriesMessageMethod = "set" | "setWithoutNotify" | "append";
|
|
153
141
|
/**
|
|
154
142
|
* Must match the switch in vstorage.go using `vstorageMessage` type
|
|
155
143
|
*/
|
|
@@ -165,15 +153,17 @@ export type StorageEntry = [path: string, value?: string | null];
|
|
|
165
153
|
/**
|
|
166
154
|
* Must match the switch in vstorage.go using `vstorageMessage` type
|
|
167
155
|
*/
|
|
168
|
-
export type StorageUpdateEntriesMessageArgs = [
|
|
156
|
+
export type StorageUpdateEntriesMessageArgs = StorageEntry[];
|
|
169
157
|
/**
|
|
170
158
|
* Must match the switch in vstorage.go using `vstorageMessage` type
|
|
171
159
|
*/
|
|
172
160
|
export type StorageMessage = {
|
|
173
161
|
method: StorageGetByPathMessageMethod;
|
|
174
|
-
args:
|
|
162
|
+
args: StorageGetByPathMessageArgs;
|
|
175
163
|
} | {
|
|
176
164
|
method: StorageUpdateEntriesMessageMethod;
|
|
177
165
|
args: StorageUpdateEntriesMessageArgs;
|
|
178
166
|
};
|
|
167
|
+
import type { ERef } from '@endo/far';
|
|
168
|
+
import type { PassableCap } from '@endo/marshal';
|
|
179
169
|
//# sourceMappingURL=lib-chainStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib-chainStorage.d.ts","sourceRoot":"","sources":["lib-chainStorage.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lib-chainStorage.d.ts","sourceRoot":"","sources":["lib-chainStorage.js"],"names":[],"mappings":"AA0PA;;;;;;;;;;;;GAYG;AACH,2DATW,CAAC,OAAO,EAAE,cAAc,KAAK,GAAG,YAGhC,MAAM;;;;IAhEX;;;OAGG;mBADa,OAAO,CAAC,WAAW,CAAC;IASpC;;;;;OAKG;wBAHQ,MAAM,qBACO;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GACtC,WAAW;IAYnB,+CAA+C;oBAA5B,MAAM,GAAK,OAAO,CAAC,IAAI,CAAC;GAqDhD;AAWD;;;;;;;;GAQG;AACH,qDAJW,KAAK,WAAW,OAAC,CAAC,aAClB,MAAM,GACJ,OAAO,CAAC,WAAW,CAAC,CAMhC;AAjOM,mCAHI,GAAG,GACD,IAAI,IAAI,UAAU,CAOa;AASrC,oCAHI,OAAO,GACL,QAAQ,IAAI,IAAI,OAAO,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC,CAQnE;AAmBD,qCAAqC;AACrC,gCADW,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAI/B;AAyCK,8CAFI,OAAO,mBAAmB,EAAE,IAAI,uDAwBxB,cAAc,KAAK,GAAG;;;;IAenC;;;OAGG;mBADa,OAAO,CAAC,WAAW,CAAC;IASpC;;;;;OAKG;wBAHQ,MAAM,qBACO;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GACtC,WAAW;IAYnB,+CAA+C;oBAA5B,MAAM,GAAK,OAAO,CAAC,IAAI,CAAC;GA0BhD;AA4DM,oDAJI,KAAK,WAAW,CAAC,cACjB,KAAK,UAAU,CAAC,GACd,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAQjD;yBA1Sa,UAAU,CAAC,cAAc,eAAe,EAAE,WAAW,CAAC;2BACtD,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC;;;;;eAM/B,MAAM;iBACN,MAAM;qBACN,MAAM;;;uBAKN,CAAC;;;;iBAED,MAAM;YACN,CAAC,EAAE;;;;;;;;;;;;;;;;cAcH,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC;;;;;aAC/B,MAAM,MAAM;;;;iBAEZ,MAAM,OAAO,CAAC,WAAW,CAAC;mBAC1B,CACb,OAAW,EAAE,MAAM,EACnB,OAAW,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,KAC7B,WAAW;;;;;;;aA6CL,MAAM,OAAO,CAAC,MAAM,CAAC;;;;iBAErB,WAAW,CAAC,aAAa,CAAC;;;;;qBAC1B,MAAM,YAAY;;;;;4CAqBnB,KAAK,GACX,aAAa,GACb,KAAK,GACL,UAAU,GACV,SAAS,GACT,QAAQ,GACR,MAAM;;;;gDAGA,KAAK,GAAG,kBAAkB,GAAG,QAAQ;;;;mCAGrC,6BAA6B,GACnC,iCAAiC;;;;0CAG3B,CAAC,IAAI,EAAE,MAAM,CAAC;;;;2BAEd,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;;;;8CAErC,YAAY,EAAE;;;;6BAEd;IACZ,MAAc,EAAE,6BAA6B,CAAC;IAC9C,IAAY,EAAE,2BAA2B,CAAC;CACnC,GACD;IACN,MAAc,EAAE,iCAAiC,CAAC;IAClD,IAAY,EAAE,+BAA+B,CAAC;CACvC;0BA9Ie,WAAW;iCACJ,eAAe"}
|
package/src/lib-chainStorage.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
3
|
import { E } from '@endo/far';
|
|
4
|
-
import { M
|
|
4
|
+
import { M } from '@endo/patterns';
|
|
5
|
+
import { makeHeapZone } from '@agoric/base-zone/heap.js';
|
|
5
6
|
import * as cb from './callback.js';
|
|
6
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @import {ERef} from '@endo/far';
|
|
10
|
+
* @import {PassableCap} from '@endo/marshal';
|
|
11
|
+
*/
|
|
12
|
+
|
|
7
13
|
const { Fail } = assert;
|
|
8
14
|
|
|
9
15
|
/** @typedef {ReturnType<typeof import('@endo/marshal').makeMarshal>} Marshaller */
|
|
@@ -29,7 +35,8 @@ const { Fail } = assert;
|
|
|
29
35
|
/**
|
|
30
36
|
* This represents a node in an IAVL tree.
|
|
31
37
|
*
|
|
32
|
-
* The active implementation is x/vstorage, an Agoric extension of the Cosmos
|
|
38
|
+
* The active implementation is x/vstorage, an Agoric extension of the Cosmos
|
|
39
|
+
* SDK.
|
|
33
40
|
*
|
|
34
41
|
* Vstorage is a hierarchical externally-reachable storage structure that
|
|
35
42
|
* identifies children by restricted ASCII name and is associated with arbitrary
|
|
@@ -37,9 +44,13 @@ const { Fail } = assert;
|
|
|
37
44
|
*
|
|
38
45
|
* @typedef {object} StorageNode
|
|
39
46
|
* @property {(data: string) => Promise<void>} setValue publishes some data
|
|
40
|
-
* @property {() => string} getPath the chain storage path at which the node was
|
|
47
|
+
* @property {() => string} getPath the chain storage path at which the node was
|
|
48
|
+
* constructed
|
|
41
49
|
* @property {() => Promise<VStorageKey>} getStoreKey DEPRECATED use getPath
|
|
42
|
-
* @property {(
|
|
50
|
+
* @property {(
|
|
51
|
+
* subPath: string,
|
|
52
|
+
* options?: { sequence?: boolean },
|
|
53
|
+
* ) => StorageNode} makeChildNode
|
|
43
54
|
*/
|
|
44
55
|
|
|
45
56
|
const ChainStorageNodeI = M.interface('StorageNode', {
|
|
@@ -53,9 +64,8 @@ const ChainStorageNodeI = M.interface('StorageNode', {
|
|
|
53
64
|
|
|
54
65
|
/**
|
|
55
66
|
* This is an imperfect heuristic to navigate the migration from value cells to
|
|
56
|
-
* stream cells.
|
|
57
|
-
*
|
|
58
|
-
* and we do not intend to create any more legacy value cells.
|
|
67
|
+
* stream cells. At time of writing, no legacy cells have the same shape as a
|
|
68
|
+
* stream cell, and we do not intend to create any more legacy value cells.
|
|
59
69
|
*
|
|
60
70
|
* @param {any} cell
|
|
61
71
|
* @returns {cell is StreamCell}
|
|
@@ -83,43 +93,13 @@ export const assertCapData = data => {
|
|
|
83
93
|
};
|
|
84
94
|
harden(assertCapData);
|
|
85
95
|
|
|
86
|
-
/**
|
|
87
|
-
* Read and unmarshal a value from a map representation of vstorage data
|
|
88
|
-
*
|
|
89
|
-
* @param {Map<string, string>} data
|
|
90
|
-
* @param {string} key
|
|
91
|
-
* @param {ReturnType<typeof import('@endo/marshal').makeMarshal>['fromCapData']} fromCapData
|
|
92
|
-
* @param {number} [index=-1] index of the desired value in a deserialized stream cell
|
|
93
|
-
*/
|
|
94
|
-
export const unmarshalFromVstorage = (data, key, fromCapData, index = -1) => {
|
|
95
|
-
const serialized = data.get(key) || Fail`no data for ${key}`;
|
|
96
|
-
assert.typeof(serialized, 'string');
|
|
97
|
-
|
|
98
|
-
const streamCell = JSON.parse(serialized);
|
|
99
|
-
if (!isStreamCell(streamCell)) {
|
|
100
|
-
throw Fail`not a StreamCell: ${streamCell}`;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const { values } = streamCell;
|
|
104
|
-
values.length > 0 || Fail`no StreamCell values: ${streamCell}`;
|
|
105
|
-
|
|
106
|
-
const marshalled = values.at(index);
|
|
107
|
-
assert.typeof(marshalled, 'string');
|
|
108
|
-
|
|
109
|
-
/** @type {import("@endo/marshal").CapData<string>} */
|
|
110
|
-
const capData = harden(JSON.parse(marshalled));
|
|
111
|
-
assertCapData(capData);
|
|
112
|
-
|
|
113
|
-
const unmarshalled = fromCapData(capData);
|
|
114
|
-
return unmarshalled;
|
|
115
|
-
};
|
|
116
|
-
harden(unmarshalFromVstorage);
|
|
117
|
-
|
|
118
96
|
/**
|
|
119
97
|
* @typedef {object} StoredFacet
|
|
120
|
-
* @property {() => Promise<string>} getPath the chain storage path at which the
|
|
98
|
+
* @property {() => Promise<string>} getPath the chain storage path at which the
|
|
99
|
+
* node was constructed
|
|
121
100
|
* @property {StorageNode['getStoreKey']} getStoreKey DEPRECATED use getPath
|
|
122
|
-
* @property {() => Unserializer} getUnserializer get the unserializer for the
|
|
101
|
+
* @property {() => Unserializer} getUnserializer get the unserializer for the
|
|
102
|
+
* stored data
|
|
123
103
|
*/
|
|
124
104
|
|
|
125
105
|
// TODO: Formalize segment constraints.
|
|
@@ -139,44 +119,65 @@ harden(assertPathSegment);
|
|
|
139
119
|
/**
|
|
140
120
|
* Must match the switch in vstorage.go using `vstorageMessage` type
|
|
141
121
|
*
|
|
142
|
-
* @typedef {
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
122
|
+
* @typedef {'get'
|
|
123
|
+
* | 'getStoreKey'
|
|
124
|
+
* | 'has'
|
|
125
|
+
* | 'children'
|
|
126
|
+
* | 'entries'
|
|
127
|
+
* | 'values'
|
|
128
|
+
* | 'size'} StorageGetByPathMessageMethod
|
|
129
|
+
*
|
|
130
|
+
*
|
|
131
|
+
* @typedef {'set' | 'setWithoutNotify' | 'append'} StorageUpdateEntriesMessageMethod
|
|
132
|
+
*
|
|
133
|
+
*
|
|
134
|
+
* @typedef {StorageGetByPathMessageMethod
|
|
135
|
+
* | StorageUpdateEntriesMessageMethod} StorageMessageMethod
|
|
136
|
+
*
|
|
137
|
+
*
|
|
138
|
+
* @typedef {[path: string]} StorageGetByPathMessageArgs
|
|
139
|
+
*
|
|
140
|
+
* @typedef {[path: string, value?: string | null]} StorageEntry
|
|
141
|
+
*
|
|
142
|
+
* @typedef {StorageEntry[]} StorageUpdateEntriesMessageArgs
|
|
143
|
+
*
|
|
148
144
|
* @typedef {{
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
145
|
+
* method: StorageGetByPathMessageMethod;
|
|
146
|
+
* args: StorageGetByPathMessageArgs;
|
|
147
|
+
* }
|
|
148
|
+
* | {
|
|
149
|
+
* method: StorageUpdateEntriesMessageMethod;
|
|
150
|
+
* args: StorageUpdateEntriesMessageArgs;
|
|
151
|
+
* }} StorageMessage
|
|
155
152
|
*/
|
|
156
153
|
|
|
157
154
|
/**
|
|
158
|
-
* @param {import('@agoric/zone').Zone} zone
|
|
155
|
+
* @param {import('@agoric/base-zone').Zone} zone
|
|
159
156
|
*/
|
|
160
157
|
export const prepareChainStorageNode = zone => {
|
|
161
158
|
/**
|
|
162
159
|
* Create a storage node for a given backing storage interface and path.
|
|
163
160
|
*
|
|
164
|
-
* @param {import('./
|
|
165
|
-
*
|
|
166
|
-
*
|
|
161
|
+
* @param {import('./types.js').Callback<
|
|
162
|
+
* (message: StorageMessage) => any
|
|
163
|
+
* >} messenger
|
|
164
|
+
* a callback for sending a storageMessage object to the storage
|
|
165
|
+
* implementation (cf. golang/cosmos/x/vstorage/vstorage.go)
|
|
167
166
|
* @param {string} path
|
|
168
167
|
* @param {object} [options]
|
|
169
|
-
* @param {boolean} [options.sequence] set values with `append` messages
|
|
170
|
-
* so the backing implementation employs a
|
|
171
|
-
* preserves each value set within a single block.
|
|
172
|
-
*
|
|
168
|
+
* @param {boolean} [options.sequence] set values with `append` messages
|
|
169
|
+
* rather than `set` messages so the backing implementation employs a
|
|
170
|
+
* wrapping structure that preserves each value set within a single block.
|
|
171
|
+
* Child nodes default to inheriting this option from their parent.
|
|
173
172
|
* @returns {StorageNode}
|
|
174
173
|
*/
|
|
175
174
|
const makeChainStorageNode = zone.exoClass(
|
|
176
175
|
'ChainStorageNode',
|
|
177
176
|
ChainStorageNodeI,
|
|
178
177
|
/**
|
|
179
|
-
* @param {import('./
|
|
178
|
+
* @param {import('./types.js').Callback<
|
|
179
|
+
* (message: StorageMessage) => any
|
|
180
|
+
* >} messenger
|
|
180
181
|
* @param {string} path
|
|
181
182
|
* @param {object} [options]
|
|
182
183
|
* @param {boolean} [options.sequence]
|
|
@@ -201,7 +202,12 @@ export const prepareChainStorageNode = zone => {
|
|
|
201
202
|
args: [path],
|
|
202
203
|
});
|
|
203
204
|
},
|
|
204
|
-
/**
|
|
205
|
+
/**
|
|
206
|
+
* @type {(
|
|
207
|
+
* name: string,
|
|
208
|
+
* childNodeOptions?: { sequence?: boolean },
|
|
209
|
+
* ) => StorageNode}
|
|
210
|
+
*/
|
|
205
211
|
makeChildNode(name, childNodeOptions = {}) {
|
|
206
212
|
const { sequence, path, messenger } = this.state;
|
|
207
213
|
assertPathSegment(name);
|
|
@@ -240,19 +246,20 @@ export const prepareChainStorageNode = zone => {
|
|
|
240
246
|
return makeChainStorageNode;
|
|
241
247
|
};
|
|
242
248
|
|
|
243
|
-
const makeHeapChainStorageNode = prepareChainStorageNode(
|
|
249
|
+
const makeHeapChainStorageNode = prepareChainStorageNode(makeHeapZone());
|
|
244
250
|
|
|
245
251
|
/**
|
|
246
|
-
* Create a heap-based root storage node for a given backing function and root
|
|
252
|
+
* Create a heap-based root storage node for a given backing function and root
|
|
253
|
+
* path.
|
|
247
254
|
*
|
|
248
255
|
* @param {(message: StorageMessage) => any} handleStorageMessage a function for
|
|
249
|
-
*
|
|
250
|
-
*
|
|
256
|
+
* sending a storageMessage object to the storage implementation (cf.
|
|
257
|
+
* golang/cosmos/x/vstorage/vstorage.go)
|
|
251
258
|
* @param {string} rootPath
|
|
252
259
|
* @param {object} [rootOptions]
|
|
253
260
|
* @param {boolean} [rootOptions.sequence] employ a wrapping structure that
|
|
254
|
-
*
|
|
255
|
-
*
|
|
261
|
+
* preserves each value set within a single block, and default child nodes to
|
|
262
|
+
* do the same
|
|
256
263
|
*/
|
|
257
264
|
export function makeChainStorageRoot(
|
|
258
265
|
handleStorageMessage,
|
|
@@ -267,7 +274,8 @@ export function makeChainStorageRoot(
|
|
|
267
274
|
}
|
|
268
275
|
|
|
269
276
|
/**
|
|
270
|
-
* @returns {StorageNode} an object that confirms to StorageNode API but does
|
|
277
|
+
* @returns {StorageNode} an object that confirms to StorageNode API but does
|
|
278
|
+
* not store anywhere.
|
|
271
279
|
*/
|
|
272
280
|
const makeNullStorageNode = () => {
|
|
273
281
|
// XXX re-use "ChainStorage" methods above which don't actually depend on chains
|
|
@@ -279,7 +287,7 @@ const makeNullStorageNode = () => {
|
|
|
279
287
|
* falling back to an inert object with the correct interface (but incomplete
|
|
280
288
|
* behavior) when that is unavailable.
|
|
281
289
|
*
|
|
282
|
-
* @param {
|
|
290
|
+
* @param {ERef<StorageNode?>} storageNodeRef
|
|
283
291
|
* @param {string} childName
|
|
284
292
|
* @returns {Promise<StorageNode>}
|
|
285
293
|
*/
|
|
@@ -292,9 +300,9 @@ harden(makeStorageNodeChild);
|
|
|
292
300
|
|
|
293
301
|
// TODO find a better module for this
|
|
294
302
|
/**
|
|
295
|
-
* @param {
|
|
296
|
-
* @param {
|
|
297
|
-
* @returns {(value:
|
|
303
|
+
* @param {ERef<StorageNode>} storageNode
|
|
304
|
+
* @param {ERef<Marshaller>} marshaller
|
|
305
|
+
* @returns {(value: PassableCap) => Promise<void>}
|
|
298
306
|
*/
|
|
299
307
|
export const makeSerializeToStorage = (storageNode, marshaller) => {
|
|
300
308
|
return async value => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-gc.d.ts","sourceRoot":"","sources":["engine-gc.js"],"names":[],"mappings":";AAoBA,mCAAwB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gc-and-finalize.d.ts","sourceRoot":"","sources":["gc-and-finalize.js"],"names":[],"mappings":"AAkEA,qEAwBC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function startSubprocessWorker(execPath: any, procArgs?: any[], { netstringMaxChunkSize }?: {
|
|
2
|
+
netstringMaxChunkSize?: undefined;
|
|
3
|
+
}): {
|
|
4
|
+
fromChild: {
|
|
5
|
+
on: (...args: any[]) => import("stream").Transform;
|
|
6
|
+
};
|
|
7
|
+
toChild: {
|
|
8
|
+
write: (...args: any[]) => boolean;
|
|
9
|
+
};
|
|
10
|
+
terminate: () => void;
|
|
11
|
+
done: Promise<any>;
|
|
12
|
+
};
|
|
13
|
+
export type IOType = import("child_process").IOType;
|
|
14
|
+
export type Writable = import("stream").Writable;
|
|
15
|
+
//# sourceMappingURL=spawnSubprocessWorker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawnSubprocessWorker.d.ts","sourceRoot":"","sources":["spawnSubprocessWorker.js"],"names":[],"mappings":"AA8BA;;;;;;;;;;;EA0DC;qBApEa,OAAO,eAAe,EAAE,MAAM;uBAC9B,OAAO,QAAQ,EAAE,QAAQ"}
|