@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.
Files changed (89) hide show
  1. package/README.md +7 -2
  2. package/exported.js +2 -0
  3. package/package.json +32 -16
  4. package/src/action-types.d.ts +1 -0
  5. package/src/action-types.d.ts.map +1 -1
  6. package/src/action-types.js +1 -0
  7. package/src/batched-deliver.d.ts +9 -6
  8. package/src/batched-deliver.d.ts.map +1 -1
  9. package/src/batched-deliver.js +9 -3
  10. package/src/callback.d.ts +23 -16
  11. package/src/callback.d.ts.map +1 -1
  12. package/src/callback.js +35 -39
  13. package/src/chain-storage-paths.d.ts +2 -3
  14. package/src/chain-storage-paths.d.ts.map +1 -1
  15. package/src/chain-storage-paths.js +2 -3
  16. package/src/config.d.ts +21 -12
  17. package/src/config.d.ts.map +1 -1
  18. package/src/config.js +20 -10
  19. package/src/debug.d.ts +1 -1
  20. package/src/index.d.ts +3 -0
  21. package/src/index.js +7 -1
  22. package/src/install-ses-debug.d.ts +2 -0
  23. package/src/install-ses-debug.d.ts.map +1 -0
  24. package/src/install-ses-debug.js +6 -0
  25. package/src/lib-chainStorage.d.ts +42 -52
  26. package/src/lib-chainStorage.d.ts.map +1 -1
  27. package/src/lib-chainStorage.js +82 -74
  28. package/src/lib-nodejs/engine-gc.d.ts +3 -0
  29. package/src/lib-nodejs/engine-gc.d.ts.map +1 -0
  30. package/src/lib-nodejs/engine-gc.js +22 -0
  31. package/src/lib-nodejs/gc-and-finalize.d.ts +2 -0
  32. package/src/lib-nodejs/gc-and-finalize.d.ts.map +1 -0
  33. package/src/lib-nodejs/gc-and-finalize.js +91 -0
  34. package/src/lib-nodejs/spawnSubprocessWorker.d.ts +15 -0
  35. package/src/lib-nodejs/spawnSubprocessWorker.d.ts.map +1 -0
  36. package/src/lib-nodejs/spawnSubprocessWorker.js +89 -0
  37. package/src/lib-nodejs/waitUntilQuiescent.d.ts +2 -0
  38. package/src/lib-nodejs/waitUntilQuiescent.d.ts.map +1 -0
  39. package/src/lib-nodejs/waitUntilQuiescent.js +18 -0
  40. package/src/lib-nodejs/worker-protocol.d.ts +4 -0
  41. package/src/lib-nodejs/worker-protocol.d.ts.map +1 -0
  42. package/src/lib-nodejs/worker-protocol.js +54 -0
  43. package/src/magic-cookie-test-only.js +2 -2
  44. package/src/marshal.d.ts +20 -0
  45. package/src/marshal.d.ts.map +1 -0
  46. package/src/marshal.js +138 -0
  47. package/src/method-tools.d.ts +1 -0
  48. package/src/method-tools.d.ts.map +1 -1
  49. package/src/method-tools.js +29 -16
  50. package/src/netstring.d.ts +24 -0
  51. package/src/netstring.d.ts.map +1 -0
  52. package/src/netstring.js +124 -0
  53. package/src/node/buffer-line-transform.d.ts +17 -13
  54. package/src/node/buffer-line-transform.d.ts.map +1 -1
  55. package/src/node/buffer-line-transform.js +11 -8
  56. package/src/node/fs-stream.d.ts.map +1 -1
  57. package/src/node/fs-stream.js +2 -3
  58. package/src/node/utils.d.ts +9 -0
  59. package/src/node/utils.d.ts.map +1 -0
  60. package/src/node/utils.js +46 -0
  61. package/src/priority-senders.d.ts +1 -1
  62. package/src/priority-senders.d.ts.map +1 -1
  63. package/src/priority-senders.js +7 -3
  64. package/src/queue.d.ts +1 -1
  65. package/src/queue.d.ts.map +1 -1
  66. package/src/queue.js +7 -8
  67. package/src/scratch.d.ts +1 -1
  68. package/src/scratch.d.ts.map +1 -1
  69. package/src/storage-test-utils.d.ts +43 -81
  70. package/src/storage-test-utils.d.ts.map +1 -1
  71. package/src/storage-test-utils.js +103 -40
  72. package/src/tagged.d.ts +155 -0
  73. package/src/testing-utils.d.ts.map +1 -1
  74. package/src/testing-utils.js +7 -5
  75. package/src/tokens.d.ts +34 -0
  76. package/src/tokens.d.ts.map +1 -0
  77. package/src/tokens.js +35 -0
  78. package/src/typeGuards.d.ts +2 -0
  79. package/src/typeGuards.d.ts.map +1 -1
  80. package/src/typeGuards.js +8 -0
  81. package/src/types.d.ts +46 -0
  82. package/src/types.js +2 -0
  83. package/src/upgrade-api.d.ts +13 -4
  84. package/src/upgrade-api.d.ts.map +1 -1
  85. package/src/upgrade-api.js +26 -18
  86. package/src/utils.d.ts +26 -31
  87. package/src/utils.d.ts.map +1 -1
  88. package/src/utils.js +53 -227
  89. package/CHANGELOG.md +0 -137
@@ -5,16 +5,19 @@ import { Transform } from 'node:stream';
5
5
 
6
6
  /**
7
7
  * @typedef {object} BufferLineTransformOptions
8
- * @property {Buffer | string | number} [break] line break matcher for Buffer.indexOf() (default: 10)
9
- * @property {BufferEncoding} [breakEncoding] if break is a string, the encoding to use
8
+ * @property {Buffer | string | number} [break] line break matcher for
9
+ * Buffer.indexOf() (default: 10)
10
+ * @property {BufferEncoding} [breakEncoding] if break is a string, the encoding
11
+ * to use
10
12
  */
11
13
 
12
14
  export default class BufferLineTransform extends Transform {
13
15
  /**
14
- * The BufferLineTransform is reading String or Buffer content from a Readable stream
15
- * and writing each line as a Buffer in object mode
16
+ * The BufferLineTransform is reading String or Buffer content from a Readable
17
+ * stream and writing each line as a Buffer in object mode
16
18
  *
17
- * @param {import('node:stream').TransformOptions & BufferLineTransformOptions} [options]
19
+ * @param {import('node:stream').TransformOptions &
20
+ * BufferLineTransformOptions} [options]
18
21
  */
19
22
  constructor(options) {
20
23
  const {
@@ -37,15 +40,15 @@ export default class BufferLineTransform extends Transform {
37
40
  }
38
41
  this._breakLength = breakLength;
39
42
 
40
- /** @type {Array<Buffer>} */
43
+ /** @type {Buffer[]} */
41
44
  this._chunks = [];
42
45
  }
43
46
 
44
47
  /**
45
- * @override
46
48
  * @param {any} chunk
47
49
  * @param {BufferEncoding | 'buffer'} encoding
48
50
  * @param {import('node:stream').TransformCallback} cb
51
+ * @override
49
52
  */
50
53
  _transform(chunk, encoding, cb) {
51
54
  try {
@@ -96,8 +99,8 @@ export default class BufferLineTransform extends Transform {
96
99
  }
97
100
 
98
101
  /**
99
- * @override
100
102
  * @param {import('node:stream').TransformCallback} cb
103
+ * @override
101
104
  */
102
105
  _flush(cb) {
103
106
  if (this._chunks.length) {
@@ -1 +1 @@
1
- {"version":3,"file":"fs-stream.d.ts","sourceRoot":"","sources":["fs-stream.js"],"names":[],"mappings":"AAQO,sCAHI,OAAO,IAAI,EAAE,UAAU,GAAG,OAAO,IAAI,EAAE,WAAW,GAChD,QAAQ,IAAI,CAAC,CAgCtB;AAQG,6CADK,MAAM,GAAG,SAAS,GAAG,IAAI;;;;eA2DpC;6BA5Da,YAAY,QAAQ,WAAW,yBAAyB,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"fs-stream.d.ts","sourceRoot":"","sources":["fs-stream.js"],"names":[],"mappings":"AAOO,sCAHI,OAAO,IAAI,EAAE,UAAU,GAAG,OAAO,IAAI,EAAE,WAAW,GAChD,OAAO,CAAC,IAAI,CAAC,CAgCtB;AAQG,6CADK,MAAM,GAAG,SAAS,GAAG,IAAI;;;;eA2DpC;6BA5Da,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC"}
@@ -1,9 +1,8 @@
1
1
  import { createWriteStream } from 'node:fs';
2
2
  import { open } from 'node:fs/promises';
3
- import { makeAggregateError } from '../utils.js';
4
3
 
5
4
  /**
6
- * @param {import("fs").ReadStream | import("fs").WriteStream} stream
5
+ * @param {import('fs').ReadStream | import('fs').WriteStream} stream
7
6
  * @returns {Promise<void>}
8
7
  */
9
8
  export const fsStreamReady = stream =>
@@ -78,7 +77,7 @@ export const makeFsStreamWriter = async filePath => {
78
77
  Promise.reject(
79
78
  written.then(
80
79
  () => err,
81
- writtenError => makeAggregateError([err, writtenError]),
80
+ writtenError => AggregateError([err, writtenError]),
82
81
  ),
83
82
  ),
84
83
  );
@@ -0,0 +1,9 @@
1
+ export function PromiseAllOrErrors<T>(items: readonly (T | PromiseLike<T>)[]): Promise<T[]>;
2
+ /**
3
+ * @type {<T>(
4
+ * trier: () => Promise<T>,
5
+ * finalizer: (error?: unknown) => Promise<void>,
6
+ * ) => Promise<T>}
7
+ */
8
+ export const aggregateTryFinally: <T>(trier: () => Promise<T>, finalizer: (error?: unknown) => Promise<void>) => Promise<T>;
9
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.js"],"names":[],"mappings":"AAYO,mCAJM,CAAC,SACH,SAAS,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,GAC7B,OAAO,CAAC,CAAC,EAAE,CAAC,CAiBxB;AAED;;;;;GAKG;AACH,kCALU,CAAC,CAAC,EACX,KAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,SAAa,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,KAC1C,OAAO,CAAC,CAAC,CAAC,CAYd"}
@@ -0,0 +1,46 @@
1
+ // @ts-check
2
+ // @jessie-check
3
+
4
+ // These tools seem cross platform, but they rely on AggregateError in the error
5
+ // handling path, which is currently not available in xsnap
6
+ import 'node:process';
7
+
8
+ /**
9
+ * @template T
10
+ * @param {readonly (T | PromiseLike<T>)[]} items
11
+ * @returns {Promise<T[]>}
12
+ */
13
+ export const PromiseAllOrErrors = async items => {
14
+ return Promise.allSettled(items).then(results => {
15
+ const errors = /** @type {PromiseRejectedResult[]} */ (
16
+ results.filter(({ status }) => status === 'rejected')
17
+ ).map(result => result.reason);
18
+ if (!errors.length) {
19
+ return /** @type {PromiseFulfilledResult<T>[]} */ (results).map(
20
+ result => result.value,
21
+ );
22
+ } else if (errors.length === 1) {
23
+ throw errors[0];
24
+ } else {
25
+ throw AggregateError(errors);
26
+ }
27
+ });
28
+ };
29
+
30
+ /**
31
+ * @type {<T>(
32
+ * trier: () => Promise<T>,
33
+ * finalizer: (error?: unknown) => Promise<void>,
34
+ * ) => Promise<T>}
35
+ */
36
+ export const aggregateTryFinally = async (trier, finalizer) =>
37
+ trier().then(
38
+ async result => finalizer().then(() => result),
39
+ async tryError =>
40
+ finalizer(tryError)
41
+ .then(
42
+ () => tryError,
43
+ finalizeError => AggregateError([tryError, finalizeError]),
44
+ )
45
+ .then(error => Promise.reject(error)),
46
+ );
@@ -13,7 +13,7 @@ export function makePrioritySendersManager(sendersNode: ERef<import("./lib-chain
13
13
  * @returns {Promise<void>}
14
14
  */
15
15
  remove: (rawNamespace: string, address: string) => Promise<void>;
16
- } & import("@endo/eventual-send").RemotableBrand<{}, {
16
+ } & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {
17
17
  /**
18
18
  * @param {string} rawNamespace
19
19
  * @param {string} address
@@ -1 +1 @@
1
- {"version":3,"file":"priority-senders.d.ts","sourceRoot":"","sources":["priority-senders.js"],"names":[],"mappings":"AAMA,4CAA4C;AAC5C,mDADuB,MAAM,KAAK,MAAM,CAMtC;AAQK;IAoCH;;;;OAIG;wBAHQ,MAAM,WACN,MAAM,KACJ,QAAQ,IAAI,CAAC;IAe1B;;;;OAIG;2BAHQ,MAAM,WACN,MAAM,KACJ,QAAQ,IAAI,CAAC;;IArB1B;;;;OAIG;wBAHQ,MAAM,WACN,MAAM,KACJ,QAAQ,IAAI,CAAC;IAe1B;;;;OAIG;2BAHQ,MAAM,WACN,MAAM,KACJ,QAAQ,IAAI,CAAC;GAuB7B;qCAGa,WAAW,iCAAiC,CAAC"}
1
+ {"version":3,"file":"priority-senders.d.ts","sourceRoot":"","sources":["priority-senders.js"],"names":[],"mappings":"AAMA,4CAA4C;AAC5C,uCADW,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAMtC;AAQK,wDAFI,IAAI,CAAC,OAAO,uBAAuB,EAAE,WAAW,CAAC;IA0CxD;;;;OAIG;wBAHQ,MAAM,WACN,MAAM,KACJ,OAAO,CAAC,IAAI,CAAC;IAe1B;;;;OAIG;2BAHQ,MAAM,WACN,MAAM,KACJ,OAAO,CAAC,IAAI,CAAC;;IArB1B;;;;OAIG;wBAHQ,MAAM,WACN,MAAM,KACJ,OAAO,CAAC,IAAI,CAAC;IAe1B;;;;OAIG;2BAHQ,MAAM,WACN,MAAM,KACJ,OAAO,CAAC,IAAI,CAAC;GAuB7B;qCAGa,UAAU,CAAC,OAAO,0BAA0B,CAAC"}
@@ -20,9 +20,13 @@ harden(normalizeSenderNamespace);
20
20
  */
21
21
  export const makePrioritySendersManager = sendersNode => {
22
22
  /**
23
- * address to tuple with storage node and set of namespaces that requested priority
23
+ * address to tuple with storage node and set of namespaces that requested
24
+ * priority
24
25
  *
25
- * @type {Map<string, readonly [node: StorageNode, namespaces: Set<string>]>}
26
+ * @type {Map<
27
+ * string,
28
+ * readonly [node: StorageNode, namespaces: Set<string>]
29
+ * >}
26
30
  */
27
31
  const addressRecords = new Map();
28
32
 
@@ -47,7 +51,7 @@ export const makePrioritySendersManager = sendersNode => {
47
51
  const node = await E(sendersNode).makeChildNode(address, {
48
52
  sequence: false,
49
53
  });
50
- /** @type {readonly [ node: StorageNode, namespaces: Set<string> ]} */
54
+ /** @type {readonly [node: StorageNode, namespaces: Set<string>]} */
51
55
  const r = [node, new Set()];
52
56
  addressRecords.set(address, r);
53
57
  return r;
package/src/queue.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export function makeWithQueue(): <T extends any[], R>(inner: (...args: T) => Promise<R>) => (...args: T) => Promise<R>;
1
+ export function makeWithQueue(): <T extends (...args: any[]) => any>(inner: T) => (...args: Parameters<T>) => Promise<Awaited<ReturnType<T>>>;
2
2
  //# sourceMappingURL=queue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["queue.js"],"names":[],"mappings":"AAQO,uHAiDN"}
1
+ {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["queue.js"],"names":[],"mappings":"AAQO,kCAwBkC,CAAC,SAA3B,CAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAI,SAC3B,CAAC,eAIC,UAAU,CAAC,CAAC,CAAC,KACX,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAkB/C"}
package/src/queue.js CHANGED
@@ -3,8 +3,8 @@
3
3
  import { makePromiseKit } from '@endo/promise-kit';
4
4
 
5
5
  /**
6
- * Return a function that can wrap an async or sync method, but
7
- * ensures only one of them (in order) is running at a time.
6
+ * Return a function that can wrap an async or sync method, but ensures only one
7
+ * of them (in order) is running at a time.
8
8
  */
9
9
  export const makeWithQueue = () => {
10
10
  const queue = [];
@@ -16,7 +16,7 @@ export const makeWithQueue = () => {
16
16
  }
17
17
  const [thunk, resolve, reject] = queue[0];
18
18
  // Run the thunk in a new turn.
19
- Promise.resolve()
19
+ void Promise.resolve()
20
20
  .then(thunk)
21
21
  // Resolve or reject our caller with the thunk's value.
22
22
  .then(resolve, reject)
@@ -30,14 +30,13 @@ export const makeWithQueue = () => {
30
30
  };
31
31
 
32
32
  /**
33
- * @template {any[]} T
34
- * @template R
35
- * @param {(...args: T) => Promise<R>} inner
33
+ * @template {(...args: any[]) => any} T
34
+ * @param {T} inner
36
35
  */
37
36
  return function withQueue(inner) {
38
37
  /**
39
- * @param {T} args
40
- * @returns {Promise<R>}
38
+ * @param {Parameters<T>} args
39
+ * @returns {Promise<Awaited<ReturnType<T>>>}
41
40
  */
42
41
  return function queueCall(...args) {
43
42
  // Curry the arguments into the inner function, and
package/src/scratch.d.ts CHANGED
@@ -6,7 +6,7 @@ export default function makeScratchPad(): {
6
6
  keys: () => Promise<any[]>;
7
7
  list: () => Promise<any[]>;
8
8
  set: (keyP: any, objP: any) => Promise<any>;
9
- } & import("@endo/eventual-send").RemotableBrand<{}, {
9
+ } & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {
10
10
  delete: (keyP: any) => Promise<void>;
11
11
  get: (keyP: any) => Promise<any>;
12
12
  lookup: (...path: any[]) => any;
@@ -1 +1 @@
1
- {"version":3,"file":"scratch.d.ts","sourceRoot":"","sources":["scratch.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgDC;yBACa,WAAW,qBAAqB,CAAC"}
1
+ {"version":3,"file":"scratch.d.ts","sourceRoot":"","sources":["scratch.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgDC;yBACa,UAAU,CAAC,OAAO,cAAc,CAAC"}
@@ -1,101 +1,63 @@
1
- export function slotToRemotable(_slotId: string, iface?: string): import("@endo/eventual-send").RemotableBrand<{}, {}>;
1
+ export function slotToRemotable(_slotId: string, iface?: string): import("@endo/marshal").RemotableObject<string> & import("@endo/eventual-send").RemotableBrand<{}, {}>;
2
2
  /**
3
- * A basic marshaller whose unserializer produces Remotables. It can
4
- * only serialize plain data, not Remotables.
3
+ * A basic marshaller whose unserializer produces Remotables. It can only
4
+ * serialize plain data, not Remotables.
5
5
  */
6
6
  export const defaultMarshaller: {
7
- toCapData: import("@endo/marshal/src/marshal.js").ToCapData<string>;
8
- fromCapData: import("@endo/marshal/src/marshal.js").FromCapData<string>;
9
- serialize: import("@endo/marshal/src/marshal.js").ToCapData<string>;
10
- unserialize: import("@endo/marshal/src/marshal.js").FromCapData<string>;
7
+ toCapData: import("@endo/marshal").ToCapData<string>;
8
+ fromCapData: import("@endo/marshal").FromCapData<string>;
9
+ serialize: import("@endo/marshal").ToCapData<string>;
10
+ unserialize: import("@endo/marshal").FromCapData<string>;
11
11
  };
12
- export function slotStringUnserialize(capData: any): any;
13
- export function makeFakeStorageKit(rootPath: string, rootOptions?: [handleStorageMessage: (message: import("./lib-chainStorage.js").StorageMessage) => any, rootPath: string, rootOptions?: {
14
- sequence?: boolean | undefined;
15
- } | undefined][2]): {
16
- rootNode: {
12
+ export const slotStringUnserialize: (capData: any) => any;
13
+ export function makeFakeStorageKit(rootPath: string, rootOptions?: Parameters<typeof makeChainStorageRoot>[2]): {
14
+ rootNode: import("@endo/exo").Guarded<{
17
15
  getPath(): string;
18
- getStoreKey(): Promise<import("./lib-chainStorage.js").VStorageKey>;
16
+ getStoreKey(): Promise<VStorageKey>;
19
17
  makeChildNode(name: string, childNodeOptions?: {
20
- sequence?: boolean | undefined;
21
- } | undefined): import("./lib-chainStorage.js").StorageNode;
22
- setValue(value: string): Promise<void>;
23
- } & import("@endo/eventual-send").RemotableBrand<{}, {
24
- getPath(): string;
25
- getStoreKey(): Promise<import("./lib-chainStorage.js").VStorageKey>;
26
- makeChildNode(name: string, childNodeOptions?: {
27
- sequence?: boolean | undefined;
28
- } | undefined): import("./lib-chainStorage.js").StorageNode;
18
+ sequence?: boolean;
19
+ }): StorageNode;
29
20
  setValue(value: string): Promise<void>;
30
21
  }>;
31
22
  data: Map<string, string>;
32
- messages: import("./lib-chainStorage.js").StorageMessage[];
33
- toStorage: (message: import('../src/lib-chainStorage.js').StorageMessage) => string | number | any[] | {
23
+ messages: StorageMessage[];
24
+ toStorage: (message: StorageMessage) => string | number | any[] | {
34
25
  storeName: string;
35
26
  storeSubkey: string;
36
27
  } | null | undefined;
37
28
  };
38
- export function makeMockChainStorageRoot(): {
39
- /**
40
- * Defaults to deserializing slot references into plain Remotable
41
- * objects having the specified interface name (as from `Far(iface)`),
42
- * but can accept a different marshaller for producing Remotables
43
- * that e.g. embed the slot string in their iface name.
44
- *
45
- * @param {string} path
46
- * @param {import('./lib-chainStorage.js').Marshaller} marshaller
47
- * @param {number} [index]
48
- * @returns {unknown}
49
- */
50
- getBody: (path: string, marshaller?: import('./lib-chainStorage.js').Marshaller, index?: number | undefined) => unknown;
51
- keys: () => string[];
52
- getPath(): string;
53
- getStoreKey(): Promise<import("./lib-chainStorage.js").VStorageKey>;
54
- makeChildNode(name: string, childNodeOptions?: {
55
- sequence?: boolean | undefined;
56
- } | undefined): import("./lib-chainStorage.js").StorageNode;
57
- setValue(value: string): Promise<void>;
58
- } & import("@endo/eventual-send").RemotableBrand<{}, {
59
- /**
60
- * Defaults to deserializing slot references into plain Remotable
61
- * objects having the specified interface name (as from `Far(iface)`),
62
- * but can accept a different marshaller for producing Remotables
63
- * that e.g. embed the slot string in their iface name.
64
- *
65
- * @param {string} path
66
- * @param {import('./lib-chainStorage.js').Marshaller} marshaller
67
- * @param {number} [index]
68
- * @returns {unknown}
69
- */
70
- getBody: (path: string, marshaller?: import('./lib-chainStorage.js').Marshaller, index?: number | undefined) => unknown;
71
- keys: () => string[];
72
- getPath(): string;
73
- getStoreKey(): Promise<import("./lib-chainStorage.js").VStorageKey>;
74
- makeChildNode(name: string, childNodeOptions?: {
75
- sequence?: boolean | undefined;
76
- } | undefined): import("./lib-chainStorage.js").StorageNode;
77
- setValue(value: string): Promise<void>;
78
- }>;
29
+ export function makeMockChainStorageRoot(): MockChainStorageRoot;
30
+ export function documentStorageSchema(t: import("ava").ExecutionContext<unknown>, storage: MockChainStorageRoot | FakeStorageKit, opts: ({
31
+ note: string;
32
+ } | {
33
+ node: string;
34
+ owner: string;
35
+ }) & ({
36
+ pattern: string;
37
+ replacement: string;
38
+ } | {})): Promise<void>;
79
39
  /**
80
- * A map corresponding with a total function such that `get(key)`
81
- * is assumed to always succeed.
40
+ * A map corresponding with a total function such that `get(key)` is assumed to
41
+ * always succeed.
82
42
  */
83
- export type TotalMap<K, V> = {
84
- [Symbol.iterator]: () => IterableIterator<[K, V]>;
85
- [Symbol.toStringTag]: string;
86
- entries: () => IterableIterator<[K, V]>;
87
- keys: () => IterableIterator<K>;
88
- values: () => IterableIterator<V>;
89
- has: (key: K) => boolean;
90
- size: number;
91
- set: (key: K, value: V) => Map<K, V>;
92
- clear: () => void;
93
- delete: (key: K) => boolean;
94
- forEach: (callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any) => void;
95
- } & {
43
+ export type TotalMap<K, V> = { [k in Exclude<keyof Map<K, V>, "get">]: Map<K, V>[k]; } & {
96
44
  get: (key: K) => V;
97
45
  };
98
46
  export type TotalMapFrom<T> = T extends Map<infer K, infer V> ? TotalMap<K, V> : never;
99
47
  export type FakeStorageKit = ReturnType<typeof makeFakeStorageKit>;
100
- export type MockChainStorageRoot = ReturnType<typeof makeMockChainStorageRoot>;
48
+ export type MockChainStorageRootMethods = {
49
+ /**
50
+ * Defaults to deserializing slot references into plain Remotable objects having
51
+ * the specified interface name (as from `Far(iface)`), but can accept a
52
+ * different marshaller for producing Remotables that e.g. embed the slot
53
+ * string in their iface name.
54
+ */
55
+ getBody: (path: string, marshaller?: Marshaller, index?: number) => unknown;
56
+ keys: () => string[];
57
+ };
58
+ export type MockChainStorageRoot = StorageNode & MockChainStorageRootMethods;
59
+ import { makeChainStorageRoot } from './lib-chainStorage.js';
60
+ import type { StorageNode } from './lib-chainStorage.js';
61
+ import type { StorageMessage } from './lib-chainStorage.js';
62
+ import type { Marshaller } from './lib-chainStorage.js';
101
63
  //# sourceMappingURL=storage-test-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage-test-utils.d.ts","sourceRoot":"","sources":["storage-test-utils.js"],"names":[],"mappings":"AAkCO,yCAHI,MAAM,UACN,MAAM,wDAGC;AAElB;;;GAGG;AACH;;;;;EAEG;AAsBW,+CAAU,GAAG,GAAK,GAAG,CAAA;AAgC5B,6CAHI,MAAM,gBACN;;eAAwC,CAAC,CAAC;;;;;;;;;;;;;;;;;;yBAyBvC,OAAO,4BAA4B,EAAE,cAAc;;;;EAoFhE;AAIM;IAIH;;;;;;;;;;OAUG;oBAJQ,MAAM,eACN,OAAO,uBAAuB,EAAE,UAAU,iCAExC,OAAO;;;;;;;;;IATpB;;;;;;;;;;OAUG;oBAJQ,MAAM,eACN,OAAO,uBAAuB,EAAE,UAAU,iCAExC,OAAO;;;;;;;;GAWvB;;;;;;;;;;;;;;;;;;eApNiF,CAAC,KAAK,CAAC;;;6BA0L3E,WAAY,yBAAyB,CAAC;mCA2BtC,WAAW,+BAA+B,CAAC"}
1
+ {"version":3,"file":"storage-test-utils.d.ts","sourceRoot":"","sources":["storage-test-utils.js"],"names":[],"mappings":"AAsCO,yCAHI,MAAM,UACN,MAAM,0GAGC;AAElB;;;GAGG;AACH;;;;;EAEG;AA4CH,8CAtBuB,GAAG,KAAK,GAAG,CAsB+B;AAU1D,6CAHI,MAAM,gBACN,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC;;;;;oBAkGX,CAAC;;;;UAOtB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;;yBAhF1B,cAAc;;;;EAoF3B;AAoBM,4CADO,oBAAoB,CA6BjC;AAQM,yCALI,OAAO,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAAC,WACvC,oBAAoB,GAAG,cAAc,QACrC,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,GAC9D,CAAK;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,EAAE,CAAC,iBAkCnD;;;;;qBAnRY,CAAC,EAAE,CAAC,IACJ,GAAG,CAAoC,IAA/B,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAE,GAAG;IACvE,GAAO,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;CACpB;yBAGS,CAAC,IACD,CAAC,SAAS,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK;6BAsLvD,UAAU,CAAC,OAAO,kBAAkB,CAAC;;;;;;;;aAIrC,CACb,IAAQ,EAAE,MAAM,EAChB,UAAc,CAAC,EAAE,UAAU,EAC3B,KAAS,CAAC,EAAE,MAAM,KACX,OAAO;UAKD,MAAM,MAAM,EAAE;;mCAEd,WAAW,GAAG,2BAA2B;qCA5NJ,uBAAuB;iCAKF,uBAAuB;oCAAvB,uBAAuB;gCAAvB,uBAAuB"}
@@ -1,24 +1,28 @@
1
1
  // @ts-check
2
2
  import { Far } from '@endo/far';
3
3
  import { makeMarshal, Remotable } from '@endo/marshal';
4
+ import { unmarshalFromVstorage } from './marshal.js';
4
5
  import { makeTracer } from './debug.js';
5
- import {
6
- isStreamCell,
7
- makeChainStorageRoot,
8
- unmarshalFromVstorage,
9
- } from './lib-chainStorage.js';
6
+ import { isStreamCell, makeChainStorageRoot } from './lib-chainStorage.js';
10
7
  import { bindAllMethods } from './method-tools.js';
8
+ import { eventLoopIteration } from './testing-utils.js';
9
+
10
+ /**
11
+ * @import {Marshaller, StorageEntry, StorageMessage, StorageNode} from './lib-chainStorage.js';
12
+ */
11
13
 
12
14
  const { Fail } = assert;
13
15
 
14
16
  const trace = makeTracer('StorTU', false);
15
17
 
16
18
  /**
17
- * A map corresponding with a total function such that `get(key)`
18
- * is assumed to always succeed.
19
+ * A map corresponding with a total function such that `get(key)` is assumed to
20
+ * always succeed.
19
21
  *
20
22
  * @template K, V
21
- * @typedef {{[k in Exclude<keyof Map<K, V>, 'get'>]: Map<K, V>[k]} & {get: (key: K) => V}} TotalMap
23
+ * @typedef {{ [k in Exclude<keyof Map<K, V>, 'get'>]: Map<K, V>[k] } & {
24
+ * get: (key: K) => V;
25
+ * }} TotalMap
22
26
  */
23
27
  /**
24
28
  * @template T
@@ -26,8 +30,8 @@ const trace = makeTracer('StorTU', false);
26
30
  */
27
31
 
28
32
  /**
29
- * A convertSlotToVal function that produces basic Remotables. Assumes
30
- * that all slots are Remotables (i.e. none are Promises).
33
+ * A convertSlotToVal function that produces basic Remotables. Assumes that all
34
+ * slots are Remotables (i.e. none are Promises).
31
35
  *
32
36
  * @param {string} _slotId
33
37
  * @param {string} iface
@@ -36,34 +40,34 @@ export const slotToRemotable = (_slotId, iface = 'Remotable') =>
36
40
  Remotable(iface);
37
41
 
38
42
  /**
39
- * A basic marshaller whose unserializer produces Remotables. It can
40
- * only serialize plain data, not Remotables.
43
+ * A basic marshaller whose unserializer produces Remotables. It can only
44
+ * serialize plain data, not Remotables.
41
45
  */
42
46
  export const defaultMarshaller = makeMarshal(undefined, slotToRemotable, {
43
47
  serializeBodyFormat: 'smallcaps',
44
48
  });
45
49
 
46
50
  /**
47
- * A deserializer which produces slot strings instead of Remotables,
48
- * so if `a = Far('iface')`, and serializing `{ a }` into `capData`
49
- * assigned it slot `board123`, then `slotStringUnserialize(capData)`
50
- * would produce `{ a: 'board123' }`.
51
+ * A deserializer which produces slot strings instead of Remotables, so if `a =
52
+ * Far('iface')`, and serializing `{ a }` into `capData` assigned it slot
53
+ * `board123`, then `slotStringUnserialize(capData)` would produce `{ a:
54
+ * 'board123' }`.
51
55
  *
52
56
  * This may be useful for display purposes.
53
57
  *
54
58
  * Limitations:
55
- * * it cannot handle Symbols (registered or well-known)
56
- * * it can handle BigInts, but serialized data that contains a
57
- * particular unusual string will be unserialized into a BigInt by
58
- * mistake
59
- * * it cannot handle Promises, NaN, +/- Infinity, undefined, or
60
- * other non-JSONable JavaScript values
59
+ *
60
+ * - it cannot handle Symbols (registered or well-known)
61
+ * - it can handle BigInts, but serialized data that contains a particular unusual
62
+ * string will be unserialized into a BigInt by mistake
63
+ * - it cannot handle Promises, NaN, +/- Infinity, undefined, or other
64
+ * non-JSONable JavaScript values
61
65
  */
62
66
  const makeSlotStringUnserialize = () => {
63
- /** @type { (slot: string, iface: string) => any } */
67
+ /** @type {(slot: string, iface: string) => any} */
64
68
  const identitySlotToValFn = (slot, _) => Far('unk', { toJSON: () => slot });
65
69
  const { fromCapData } = makeMarshal(undefined, identitySlotToValFn);
66
- /** @type { (capData: any) => any } */
70
+ /** @type {(capData: any) => any} */
67
71
  const unserialize = capData =>
68
72
  JSON.parse(
69
73
  JSON.stringify(fromCapData(capData), (_, val) => {
@@ -88,9 +92,9 @@ const makeSlotStringUnserialize = () => {
88
92
  export const slotStringUnserialize = makeSlotStringUnserialize();
89
93
 
90
94
  /**
91
- * For testing, creates a chainStorage root node over an in-memory map
92
- * and exposes both the map and the sequence of received messages.
93
- * The `sequence` option defaults to true.
95
+ * For testing, creates a chainStorage root node over an in-memory map and
96
+ * exposes both the map and the sequence of received messages. The `sequence`
97
+ * option defaults to true.
94
98
  *
95
99
  * @param {string} rootPath
96
100
  * @param {Parameters<typeof makeChainStorageRoot>[2]} [rootOptions]
@@ -116,10 +120,10 @@ export const makeFakeStorageKit = (rootPath, rootOptions) => {
116
120
  }
117
121
  return childEntries;
118
122
  };
119
- /** @type {import('../src/lib-chainStorage.js').StorageMessage[]} */
123
+ /** @type {StorageMessage[]} */
120
124
  const messages = [];
121
- /** @param {import('../src/lib-chainStorage.js').StorageMessage} message */
122
- // eslint-disable-next-line consistent-return
125
+ /** @param {StorageMessage} message */
126
+
123
127
  const toStorage = message => {
124
128
  messages.push(message);
125
129
  switch (message.method) {
@@ -146,7 +150,7 @@ export const makeFakeStorageKit = (rootPath, rootOptions) => {
146
150
  case 'set':
147
151
  case 'setWithoutNotify': {
148
152
  trace('toStorage set', message);
149
- /** @type {import('../src/lib-chainStorage.js').StorageEntry[]} */
153
+ /** @type {StorageEntry[]} */
150
154
  const newEntries = message.args;
151
155
  for (const [key, value] of newEntries) {
152
156
  if (value != null) {
@@ -159,7 +163,7 @@ export const makeFakeStorageKit = (rootPath, rootOptions) => {
159
163
  }
160
164
  case 'append': {
161
165
  trace('toStorage append', message);
162
- /** @type {import('../src/lib-chainStorage.js').StorageEntry[]} */
166
+ /** @type {StorageEntry[]} */
163
167
  const newEntries = message.args;
164
168
  for (const [key, value] of newEntries) {
165
169
  value != null || Fail`attempt to append with no value`;
@@ -204,26 +208,46 @@ export const makeFakeStorageKit = (rootPath, rootOptions) => {
204
208
  };
205
209
  };
206
210
  harden(makeFakeStorageKit);
207
- /** @typedef {ReturnType< typeof makeFakeStorageKit>} FakeStorageKit */
211
+ /** @typedef {ReturnType<typeof makeFakeStorageKit>} FakeStorageKit */
212
+
213
+ /**
214
+ * @typedef MockChainStorageRootMethods
215
+ * @property {(
216
+ * path: string,
217
+ * marshaller?: Marshaller,
218
+ * index?: number,
219
+ * ) => unknown} getBody
220
+ * Defaults to deserializing slot references into plain Remotable objects having
221
+ * the specified interface name (as from `Far(iface)`), but can accept a
222
+ * different marshaller for producing Remotables that e.g. embed the slot
223
+ * string in their iface name.
224
+ * @property {() => string[]} keys
225
+ */
226
+ /** @typedef {StorageNode & MockChainStorageRootMethods} MockChainStorageRoot */
208
227
 
228
+ /** @returns {MockChainStorageRoot} */
209
229
  export const makeMockChainStorageRoot = () => {
210
230
  const { rootNode, data } = makeFakeStorageKit('mockChainStorageRoot');
211
231
  return Far('mockChainStorage', {
212
232
  ...bindAllMethods(rootNode),
213
233
  /**
214
- * Defaults to deserializing slot references into plain Remotable
215
- * objects having the specified interface name (as from `Far(iface)`),
216
- * but can accept a different marshaller for producing Remotables
217
- * that e.g. embed the slot string in their iface name.
234
+ * Defaults to deserializing slot references into plain Remotable objects
235
+ * having the specified interface name (as from `Far(iface)`), but can
236
+ * accept a different marshaller for producing Remotables that e.g. embed
237
+ * the slot string in their iface name.
218
238
  *
219
239
  * @param {string} path
220
- * @param {import('./lib-chainStorage.js').Marshaller} marshaller
240
+ * @param {Marshaller} marshaller
221
241
  * @param {number} [index]
222
242
  * @returns {unknown}
223
243
  */
224
244
  getBody: (path, marshaller = defaultMarshaller, index = -1) => {
225
245
  data.size || Fail`no data in storage`;
226
- /** @type {ReturnType<typeof import('@endo/marshal').makeMarshal>['fromCapData']} */
246
+ /**
247
+ * @type {ReturnType<
248
+ * typeof import('@endo/marshal').makeMarshal
249
+ * >['fromCapData']}
250
+ */
227
251
  const fromCapData = (...args) =>
228
252
  Reflect.apply(marshaller.fromCapData, marshaller, args);
229
253
  return unmarshalFromVstorage(data, path, fromCapData, index);
@@ -231,4 +255,43 @@ export const makeMockChainStorageRoot = () => {
231
255
  keys: () => [...data.keys()],
232
256
  });
233
257
  };
234
- /** @typedef {ReturnType<typeof makeMockChainStorageRoot>} MockChainStorageRoot */
258
+
259
+ /**
260
+ * @param {import('ava').ExecutionContext<unknown>} t
261
+ * @param {MockChainStorageRoot | FakeStorageKit} storage
262
+ * @param {({ note: string } | { node: string; owner: string }) &
263
+ * ({ pattern: string; replacement: string } | {})} opts
264
+ */
265
+ export const documentStorageSchema = async (t, storage, opts) => {
266
+ // chainStorage publication is unsynchronized
267
+ await eventLoopIteration();
268
+
269
+ const [keys, getBody] =
270
+ 'keys' in storage
271
+ ? [storage.keys(), (/** @type {string} */ k) => storage.getBody(k)]
272
+ : [storage.data.keys(), (/** @type {string} */ k) => storage.data.get(k)];
273
+
274
+ const { pattern, replacement } =
275
+ 'pattern' in opts
276
+ ? opts
277
+ : { pattern: 'mockChainStorageRoot.', replacement: 'published.' };
278
+ const illustration = [...keys].sort().map(
279
+ /** @type {(k: string) => [string, unknown]} */
280
+ key => [key.replace(pattern, replacement), getBody(key)],
281
+ );
282
+ const pruned = illustration.filter(
283
+ 'node' in opts
284
+ ? ([key, _]) => key.startsWith(`published.${opts.node}`)
285
+ : _entry => true,
286
+ );
287
+
288
+ const note =
289
+ 'note' in opts
290
+ ? opts.note
291
+ : `Under "published", the "${opts.node}" node is delegated to ${opts.owner}.`;
292
+ const boilerplate = `
293
+ The example below illustrates the schema of the data published there.
294
+
295
+ See also board marshalling conventions (_to appear_).`;
296
+ t.snapshot(pruned, note + boilerplate);
297
+ };