@agoric/internal 0.3.3-upgrade-16-fi-dev-8879538.0 → 0.3.3-upgrade-16-dev-f908f89.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 (50) hide show
  1. package/package.json +5 -5
  2. package/src/batched-deliver.d.ts +4 -1
  3. package/src/batched-deliver.d.ts.map +1 -1
  4. package/src/batched-deliver.js +4 -1
  5. package/src/callback.d.ts.map +1 -1
  6. package/src/callback.js +24 -22
  7. package/src/chain-storage-paths.d.ts +2 -3
  8. package/src/chain-storage-paths.d.ts.map +1 -1
  9. package/src/chain-storage-paths.js +2 -3
  10. package/src/config.d.ts +7 -5
  11. package/src/config.d.ts.map +1 -1
  12. package/src/config.js +12 -8
  13. package/src/lib-chainStorage.d.ts +26 -11
  14. package/src/lib-chainStorage.d.ts.map +1 -1
  15. package/src/lib-chainStorage.js +69 -35
  16. package/src/lib-nodejs/spawnSubprocessWorker.d.ts.map +1 -1
  17. package/src/lib-nodejs/spawnSubprocessWorker.js +7 -5
  18. package/src/lib-nodejs/worker-protocol.d.ts.map +1 -1
  19. package/src/lib-nodejs/worker-protocol.js +5 -7
  20. package/src/magic-cookie-test-only.js +2 -2
  21. package/src/marshal.d.ts +3 -2
  22. package/src/marshal.d.ts.map +1 -1
  23. package/src/marshal.js +18 -12
  24. package/src/method-tools.d.ts.map +1 -1
  25. package/src/method-tools.js +17 -16
  26. package/src/netstring.d.ts +4 -5
  27. package/src/netstring.d.ts.map +1 -1
  28. package/src/netstring.js +8 -11
  29. package/src/node/buffer-line-transform.d.ts +15 -10
  30. package/src/node/buffer-line-transform.d.ts.map +1 -1
  31. package/src/node/buffer-line-transform.js +11 -8
  32. package/src/node/fs-stream.js +1 -1
  33. package/src/node/utils.d.ts +9 -0
  34. package/src/node/utils.d.ts.map +1 -0
  35. package/src/node/utils.js +46 -0
  36. package/src/priority-senders.d.ts.map +1 -1
  37. package/src/priority-senders.js +7 -3
  38. package/src/queue.js +2 -2
  39. package/src/storage-test-utils.d.ts +17 -8
  40. package/src/storage-test-utils.d.ts.map +1 -1
  41. package/src/storage-test-utils.js +84 -33
  42. package/src/testing-utils.d.ts.map +1 -1
  43. package/src/testing-utils.js +7 -5
  44. package/src/types.d.ts +10 -1
  45. package/src/upgrade-api.d.ts +2 -2
  46. package/src/upgrade-api.d.ts.map +1 -1
  47. package/src/upgrade-api.js +8 -8
  48. package/src/utils.d.ts +23 -21
  49. package/src/utils.d.ts.map +1 -1
  50. package/src/utils.js +49 -68
@@ -5,6 +5,7 @@ import { unmarshalFromVstorage } from './marshal.js';
5
5
  import { makeTracer } from './debug.js';
6
6
  import { isStreamCell, makeChainStorageRoot } from './lib-chainStorage.js';
7
7
  import { bindAllMethods } from './method-tools.js';
8
+ import { eventLoopIteration } from './testing-utils.js';
8
9
 
9
10
  /**
10
11
  * @import {Marshaller, StorageEntry, StorageMessage, StorageNode} from './lib-chainStorage.js';
@@ -15,11 +16,13 @@ const { Fail } = assert;
15
16
  const trace = makeTracer('StorTU', false);
16
17
 
17
18
  /**
18
- * A map corresponding with a total function such that `get(key)`
19
- * is assumed to always succeed.
19
+ * A map corresponding with a total function such that `get(key)` is assumed to
20
+ * always succeed.
20
21
  *
21
22
  * @template K, V
22
- * @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
23
26
  */
24
27
  /**
25
28
  * @template T
@@ -27,8 +30,8 @@ const trace = makeTracer('StorTU', false);
27
30
  */
28
31
 
29
32
  /**
30
- * A convertSlotToVal function that produces basic Remotables. Assumes
31
- * 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).
32
35
  *
33
36
  * @param {string} _slotId
34
37
  * @param {string} iface
@@ -37,34 +40,34 @@ export const slotToRemotable = (_slotId, iface = 'Remotable') =>
37
40
  Remotable(iface);
38
41
 
39
42
  /**
40
- * A basic marshaller whose unserializer produces Remotables. It can
41
- * only serialize plain data, not Remotables.
43
+ * A basic marshaller whose unserializer produces Remotables. It can only
44
+ * serialize plain data, not Remotables.
42
45
  */
43
46
  export const defaultMarshaller = makeMarshal(undefined, slotToRemotable, {
44
47
  serializeBodyFormat: 'smallcaps',
45
48
  });
46
49
 
47
50
  /**
48
- * A deserializer which produces slot strings instead of Remotables,
49
- * so if `a = Far('iface')`, and serializing `{ a }` into `capData`
50
- * assigned it slot `board123`, then `slotStringUnserialize(capData)`
51
- * 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' }`.
52
55
  *
53
56
  * This may be useful for display purposes.
54
57
  *
55
58
  * Limitations:
56
- * * it cannot handle Symbols (registered or well-known)
57
- * * it can handle BigInts, but serialized data that contains a
58
- * particular unusual string will be unserialized into a BigInt by
59
- * mistake
60
- * * it cannot handle Promises, NaN, +/- Infinity, undefined, or
61
- * 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
62
65
  */
63
66
  const makeSlotStringUnserialize = () => {
64
- /** @type { (slot: string, iface: string) => any } */
67
+ /** @type {(slot: string, iface: string) => any} */
65
68
  const identitySlotToValFn = (slot, _) => Far('unk', { toJSON: () => slot });
66
69
  const { fromCapData } = makeMarshal(undefined, identitySlotToValFn);
67
- /** @type { (capData: any) => any } */
70
+ /** @type {(capData: any) => any} */
68
71
  const unserialize = capData =>
69
72
  JSON.parse(
70
73
  JSON.stringify(fromCapData(capData), (_, val) => {
@@ -89,9 +92,9 @@ const makeSlotStringUnserialize = () => {
89
92
  export const slotStringUnserialize = makeSlotStringUnserialize();
90
93
 
91
94
  /**
92
- * For testing, creates a chainStorage root node over an in-memory map
93
- * and exposes both the map and the sequence of received messages.
94
- * 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.
95
98
  *
96
99
  * @param {string} rootPath
97
100
  * @param {Parameters<typeof makeChainStorageRoot>[2]} [rootOptions]
@@ -205,15 +208,19 @@ export const makeFakeStorageKit = (rootPath, rootOptions) => {
205
208
  };
206
209
  };
207
210
  harden(makeFakeStorageKit);
208
- /** @typedef {ReturnType< typeof makeFakeStorageKit>} FakeStorageKit */
211
+ /** @typedef {ReturnType<typeof makeFakeStorageKit>} FakeStorageKit */
209
212
 
210
213
  /**
211
214
  * @typedef MockChainStorageRootMethods
212
- * @property {(path: string, marshaller?: Marshaller, index?: number) => unknown} getBody
213
- * Defaults to deserializing slot references into plain Remotable
214
- * objects having the specified interface name (as from `Far(iface)`),
215
- * but can accept a different marshaller for producing Remotables
216
- * that e.g. embed the slot string in their iface name.
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.
217
224
  * @property {() => string[]} keys
218
225
  */
219
226
  /** @typedef {StorageNode & MockChainStorageRootMethods} MockChainStorageRoot */
@@ -224,10 +231,10 @@ export const makeMockChainStorageRoot = () => {
224
231
  return Far('mockChainStorage', {
225
232
  ...bindAllMethods(rootNode),
226
233
  /**
227
- * Defaults to deserializing slot references into plain Remotable
228
- * objects having the specified interface name (as from `Far(iface)`),
229
- * but can accept a different marshaller for producing Remotables
230
- * 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.
231
238
  *
232
239
  * @param {string} path
233
240
  * @param {Marshaller} marshaller
@@ -236,7 +243,11 @@ export const makeMockChainStorageRoot = () => {
236
243
  */
237
244
  getBody: (path, marshaller = defaultMarshaller, index = -1) => {
238
245
  data.size || Fail`no data in storage`;
239
- /** @type {ReturnType<typeof import('@endo/marshal').makeMarshal>['fromCapData']} */
246
+ /**
247
+ * @type {ReturnType<
248
+ * typeof import('@endo/marshal').makeMarshal
249
+ * >['fromCapData']}
250
+ */
240
251
  const fromCapData = (...args) =>
241
252
  Reflect.apply(marshaller.fromCapData, marshaller, args);
242
253
  return unmarshalFromVstorage(data, path, fromCapData, index);
@@ -244,3 +255,43 @@ export const makeMockChainStorageRoot = () => {
244
255
  keys: () => [...data.keys()],
245
256
  });
246
257
  };
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
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"testing-utils.d.ts","sourceRoot":"","sources":["testing-utils.js"],"names":[],"mappings":"AAWO,mDACwC"}
1
+ {"version":3,"file":"testing-utils.d.ts","sourceRoot":"","sources":["testing-utils.js"],"names":[],"mappings":"AAaO,mDACwC"}
@@ -1,13 +1,15 @@
1
- /** @file note this cannot be called test-utils.js due to https://github.com/Agoric/agoric-sdk/issues/7503 */
1
+ /**
2
+ * @file note this cannot be called test-utils.js due to
3
+ * https://github.com/Agoric/agoric-sdk/issues/7503
4
+ */
2
5
  /* global setImmediate */
3
6
 
4
7
  /**
5
8
  * A workaround for some issues with fake time in tests.
6
9
  *
7
- * Lines of test code can depend on async promises outside the test
8
- * resolving before they run. Awaiting this function result ensures
9
- * that all promises that can do resolve.
10
- * Note that this doesn't mean all outstanding promises.
10
+ * Lines of test code can depend on async promises outside the test resolving
11
+ * before they run. Awaiting this function result ensures that all promises that
12
+ * can do resolve. Note that this doesn't mean all outstanding promises.
11
13
  */
12
14
  export const eventLoopIteration = async () =>
13
15
  new Promise(resolve => setImmediate(resolve));
package/src/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable max-classes-per-file */
2
- import type { Callable, RemotableBrand } from '@endo/eventual-send';
2
+ import type { ERef, RemotableBrand } from '@endo/eventual-send';
3
3
  import type { Primitive } from '@endo/pass-style';
4
+ import type { Callable } from './utils.js';
4
5
 
5
6
  export declare class Callback<I extends (...args: unknown[]) => any> {
6
7
  private iface: I;
@@ -55,3 +56,11 @@ export type DataOnly<T> =
55
56
  export type Remote<Primary, Local = DataOnly<Primary>> =
56
57
  | Primary
57
58
  | RemotableBrand<Local, Primary>;
59
+
60
+ // TODO: Add type tests for FarRef and Remote.
61
+ /**
62
+ * Potentially remote promises or settled references.
63
+ */
64
+ export type FarRef<Primary, Local = DataOnly<Primary>> = ERef<
65
+ Remote<Primary, Local>
66
+ >;
@@ -6,8 +6,8 @@ export namespace UpgradeDisconnectionShape {
6
6
  export function makeUpgradeDisconnection(upgradeMessage: string, toIncarnationNumber: number): UpgradeDisconnection;
7
7
  export function isUpgradeDisconnection(reason: any): reason is UpgradeDisconnection;
8
8
  /**
9
- * An Error-like object for use as the rejection reason of promises
10
- * abandoned by upgrade.
9
+ * An Error-like object for use as the rejection reason of promises abandoned by
10
+ * upgrade.
11
11
  */
12
12
  export type UpgradeDisconnection = {
13
13
  name: "vatUpgraded";
@@ -1 +1 @@
1
- {"version":3,"file":"upgrade-api.d.ts","sourceRoot":"","sources":["upgrade-api.js"],"names":[],"mappings":";;;;;AAgCO,yDAJI,MAAM,uBACN,MAAM,GACJ,oBAAoB,CAO7B;AASG,+CALI,GAAG,GAGD,MAAM,IAAI,oBAAoB,CAGqB;;;;;mCApCnD;IACZ,IAAQ,EAAE,aAAa,CAAC;IACxB,cAAkB,EAAE,MAAM,CAAC;IAC3B,iBAAqB,EAAE,MAAM,CAAA;CAC1B"}
1
+ {"version":3,"file":"upgrade-api.d.ts","sourceRoot":"","sources":["upgrade-api.js"],"names":[],"mappings":";;;;;AAgCO,yDAJI,MAAM,uBACN,MAAM,GACJ,oBAAoB,CAO7B;AASG,+CALI,GAAG,GAGD,MAAM,IAAI,oBAAoB,CAGqB;;;;;mCApCnD;IACZ,IAAQ,EAAE,aAAa,CAAC;IACxB,cAAkB,EAAE,MAAM,CAAC;IAC3B,iBAAqB,EAAE,MAAM,CAAC;CAC3B"}
@@ -6,13 +6,13 @@ import { M, matches } from '@endo/patterns';
6
6
  const { isFrozen } = Object;
7
7
 
8
8
  /**
9
- * An Error-like object for use as the rejection reason of promises
10
- * abandoned by upgrade.
9
+ * An Error-like object for use as the rejection reason of promises abandoned by
10
+ * upgrade.
11
11
  *
12
12
  * @typedef {{
13
- * name: 'vatUpgraded',
14
- * upgradeMessage: string,
15
- * incarnationNumber: number
13
+ * name: 'vatUpgraded';
14
+ * upgradeMessage: string;
15
+ * incarnationNumber: number;
16
16
  * }} UpgradeDisconnection
17
17
  */
18
18
 
@@ -39,9 +39,9 @@ export const makeUpgradeDisconnection = (upgradeMessage, toIncarnationNumber) =>
39
39
  harden(makeUpgradeDisconnection);
40
40
 
41
41
  /**
42
- * @param {any} reason
43
- * If `reason` is not frozen, it cannot be an UpgradeDisconnection,
44
- * so returns false without even checking against the shape.
42
+ * @param {any} reason If `reason` is not frozen, it cannot be an
43
+ * UpgradeDisconnection, so returns false without even checking against the
44
+ * shape.
45
45
  * @returns {reason is UpgradeDisconnection}
46
46
  */
47
47
  export const isUpgradeDisconnection = reason =>
package/src/utils.d.ts CHANGED
@@ -1,27 +1,32 @@
1
1
  export const BASIS_POINTS: 10000n;
2
- /** @import { ERef } from '@endo/far' */
2
+ /** @import {ERef} from '@endo/far' */
3
3
  /**
4
4
  * @template T
5
- * @typedef {{[KeyType in keyof T]: T[KeyType]} & {}} Simplify
6
- * flatten the type output to improve type hints shown in editors
7
- * https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts
5
+ * @typedef {{ [KeyType in keyof T]: T[KeyType] } & {}} Simplify flatten the
6
+ * type output to improve type hints shown in editors
7
+ * https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts
8
8
  */
9
9
  /**
10
10
  * @typedef {(...args: any[]) => any} Callable
11
11
  */
12
12
  /**
13
13
  * @template {{}} T
14
- * @typedef {{ [K in keyof T]: T[K] extends Callable ? T[K] : DeeplyAwaited<T[K]> }} DeeplyAwaitedObject
14
+ * @typedef {{
15
+ * [K in keyof T]: T[K] extends Callable ? T[K] : DeeplyAwaited<T[K]>;
16
+ * }} DeeplyAwaitedObject
15
17
  */
16
18
  /**
17
19
  * @template T
18
- * @typedef {T extends PromiseLike<any> ? Awaited<T> : T extends {} ? Simplify<DeeplyAwaitedObject<T>> : Awaited<T>} DeeplyAwaited
20
+ * @typedef {T extends PromiseLike<any>
21
+ * ? Awaited<T>
22
+ * : T extends {}
23
+ * ? Simplify<DeeplyAwaitedObject<T>>
24
+ * : Awaited<T>} DeeplyAwaited
19
25
  */
20
26
  /**
21
27
  * A more constrained version of {deeplyFulfilled} for type safety until
22
- * https://github.com/endojs/endo/issues/1257
23
- * Useful in starting contracts that need all terms to be fulfilled
24
- * in order to be durable.
28
+ * https://github.com/endojs/endo/issues/1257 Useful in starting contracts that
29
+ * need all terms to be fulfilled in order to be durable.
25
30
  *
26
31
  * @type {<T extends {}>(unfulfilledTerms: T) => Promise<DeeplyAwaited<T>>}
27
32
  */
@@ -30,26 +35,23 @@ export function makeMeasureSeconds(currentTimeMillisec: typeof import("perf_hook
30
35
  result: T;
31
36
  duration: number;
32
37
  }>;
33
- export function PromiseAllOrErrors<T>(items: readonly (T | PromiseLike<T>)[]): Promise<T[]>;
34
- /**
35
- * @type {<T>(
36
- * trier: () => Promise<T>,
37
- * finalizer: (error?: unknown) => Promise<void>,
38
- * ) => Promise<T>}
39
- */
40
- export const aggregateTryFinally: <T>(trier: () => Promise<T>, finalizer: (error?: unknown) => Promise<void>) => Promise<T>;
41
38
  export function assertAllDefined<T extends Record<string, unknown>>(obj: T): asserts obj is AllDefined<T>;
42
39
  export const forever: AsyncIterable<undefined>;
43
40
  export function whileTrue<T>(produce: () => T): AsyncIterable<Awaited<T>>;
44
41
  export function untilTrue<T>(produce: () => T): AsyncIterable<Awaited<T>>;
45
- /** @type { <X, Y>(xs: X[], ys: Y[]) => [X, Y][]} */
42
+ /** @type {<X, Y>(xs: X[], ys: Y[]) => [X, Y][]} */
46
43
  export const zip: <X, Y>(xs: X[], ys: Y[]) => [X, Y][];
47
- /** @type { <T extends Record<string, ERef<any>>>(obj: T) => Promise<{ [K in keyof T]: Awaited<T[K]>}> } */
44
+ /**
45
+ * @type {<T extends Record<string, ERef<any>>>(
46
+ * obj: T,
47
+ * ) => Promise<{ [K in keyof T]: Awaited<T[K]> }>}
48
+ */
48
49
  export const allValues: <T extends Record<string, any>>(obj: T) => Promise<{ [K in keyof T]: Awaited<T[K]>; }>;
49
50
  export function synchronizedTee<T = unknown>(sourceStream: AsyncIterator<T, void, void>, readerCount: number): AsyncGenerator<T, void, void>[];
50
51
  /**
51
- * flatten the type output to improve type hints shown in editors
52
- * https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts
52
+ * flatten the
53
+ * type output to improve type hints shown in editors
54
+ * https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts
53
55
  */
54
56
  export type Simplify<T> = { [KeyType in keyof T]: T[KeyType]; } & {};
55
57
  export type Callable = (...args: any[]) => any;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.js"],"names":[],"mappings":"AAYA,kCAAoC;AAEpC,wCAAwC;AAExC;;;;;GAKG;AAEH;;GAEG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;;;;;GAOG;AACH,oCAFU,CAAC,CAAC,SAAS,EAAE,EAAE,gBAAgB,EAA8B,CAAC,AAA5B,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAKxE;AAUK,wDAHI,cAAc,YAAY,EAAE,WAAW,CAAC,GAAG,GACzC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC;IAAE,MAAM,EAAE,CAAC,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAWjF;AAOM,mCAFc,CAAC,SADX,SAAS,CACC,CAAC,AADA,GAAG,WAAW,CACf,CAAC,AADgB,CAAC,CAAC,EAAE,GAC7B,OAAO,CAAC,CAAC,EAAE,CAAC,CAiBxB;AAED;;;;;GAKG;AACH,kCALU,CAAC,CAAC,EACX,KAAS,EAAE,MAAM,O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
@@ -12,13 +12,13 @@ const { quote: q, Fail } = assert;
12
12
 
13
13
  export const BASIS_POINTS = 10_000n;
14
14
 
15
- /** @import { ERef } from '@endo/far' */
15
+ /** @import {ERef} from '@endo/far' */
16
16
 
17
17
  /**
18
18
  * @template T
19
- * @typedef {{[KeyType in keyof T]: T[KeyType]} & {}} Simplify
20
- * flatten the type output to improve type hints shown in editors
21
- * https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts
19
+ * @typedef {{ [KeyType in keyof T]: T[KeyType] } & {}} Simplify flatten the
20
+ * type output to improve type hints shown in editors
21
+ * https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts
22
22
  */
23
23
 
24
24
  /**
@@ -27,19 +27,24 @@ export const BASIS_POINTS = 10_000n;
27
27
 
28
28
  /**
29
29
  * @template {{}} T
30
- * @typedef {{ [K in keyof T]: T[K] extends Callable ? T[K] : DeeplyAwaited<T[K]> }} DeeplyAwaitedObject
30
+ * @typedef {{
31
+ * [K in keyof T]: T[K] extends Callable ? T[K] : DeeplyAwaited<T[K]>;
32
+ * }} DeeplyAwaitedObject
31
33
  */
32
34
 
33
35
  /**
34
36
  * @template T
35
- * @typedef {T extends PromiseLike<any> ? Awaited<T> : T extends {} ? Simplify<DeeplyAwaitedObject<T>> : Awaited<T>} DeeplyAwaited
37
+ * @typedef {T extends PromiseLike<any>
38
+ * ? Awaited<T>
39
+ * : T extends {}
40
+ * ? Simplify<DeeplyAwaitedObject<T>>
41
+ * : Awaited<T>} DeeplyAwaited
36
42
  */
37
43
 
38
44
  /**
39
45
  * A more constrained version of {deeplyFulfilled} for type safety until
40
- * https://github.com/endojs/endo/issues/1257
41
- * Useful in starting contracts that need all terms to be fulfilled
42
- * in order to be durable.
46
+ * https://github.com/endojs/endo/issues/1257 Useful in starting contracts that
47
+ * need all terms to be fulfilled in order to be durable.
43
48
  *
44
49
  * @type {<T extends {}>(unfulfilledTerms: T) => Promise<DeeplyAwaited<T>>}
45
50
  */
@@ -54,7 +59,9 @@ export const deeplyFulfilledObject = async obj => {
54
59
  * and report the result in seconds to match our telemetry standard.
55
60
  *
56
61
  * @param {typeof import('perf_hooks').performance.now} currentTimeMillisec
57
- * @returns {<T>(fn: () => Promise<T>) => Promise<{ result: T, duration: number }>}
62
+ * @returns {<T>(
63
+ * fn: () => Promise<T>,
64
+ * ) => Promise<{ result: T; duration: number }>}
58
65
  */
59
66
  export const makeMeasureSeconds = currentTimeMillisec => {
60
67
  /** @param {() => any} fn */
@@ -67,49 +74,9 @@ export const makeMeasureSeconds = currentTimeMillisec => {
67
74
  return measureSeconds;
68
75
  };
69
76
 
70
- /**
71
- * @template T
72
- * @param {readonly (T | PromiseLike<T>)[]} items
73
- * @returns {Promise<T[]>}
74
- */
75
- export const PromiseAllOrErrors = async items => {
76
- return Promise.allSettled(items).then(results => {
77
- const errors = /** @type {PromiseRejectedResult[]} */ (
78
- results.filter(({ status }) => status === 'rejected')
79
- ).map(result => result.reason);
80
- if (!errors.length) {
81
- return /** @type {PromiseFulfilledResult<T>[]} */ (results).map(
82
- result => result.value,
83
- );
84
- } else if (errors.length === 1) {
85
- throw errors[0];
86
- } else {
87
- throw AggregateError(errors);
88
- }
89
- });
90
- };
91
-
92
- /**
93
- * @type {<T>(
94
- * trier: () => Promise<T>,
95
- * finalizer: (error?: unknown) => Promise<void>,
96
- * ) => Promise<T>}
97
- */
98
- export const aggregateTryFinally = async (trier, finalizer) =>
99
- trier().then(
100
- async result => finalizer().then(() => result),
101
- async tryError =>
102
- finalizer(tryError)
103
- .then(
104
- () => tryError,
105
- finalizeError => AggregateError([tryError, finalizeError]),
106
- )
107
- .then(error => Promise.reject(error)),
108
- );
109
-
110
77
  /**
111
78
  * @template {Record<string, unknown>} T
112
- * @typedef {{[P in keyof T]: Exclude<T[P], undefined>;}} AllDefined
79
+ * @typedef {{ [P in keyof T]: Exclude<T[P], undefined> }} AllDefined
113
80
  */
114
81
 
115
82
  /**
@@ -118,8 +85,8 @@ export const aggregateTryFinally = async (trier, finalizer) =>
118
85
  *
119
86
  * @template {Record<string, unknown>} T
120
87
  * @param {T} obj
121
- * @throws if any value in the object entries is not defined
122
88
  * @returns {asserts obj is AllDefined<T>}
89
+ * @throws if any value in the object entries is not defined
123
90
  */
124
91
  export const assertAllDefined = obj => {
125
92
  const missing = [];
@@ -143,10 +110,9 @@ export const forever = asyncGenerate(() => notDone);
143
110
 
144
111
  /**
145
112
  * @template T
146
- * @param {() => T} produce
147
- * The value of `await produce()` is used for its truthiness vs falsiness.
148
- * IOW, it is coerced to a boolean so the caller need not bother doing this
149
- * themselves.
113
+ * @param {() => T} produce The value of `await produce()` is used for its
114
+ * truthiness vs falsiness. IOW, it is coerced to a boolean so the caller need
115
+ * not bother doing this themselves.
150
116
  * @returns {AsyncIterable<Awaited<T>>}
151
117
  */
152
118
  export const whileTrue = produce =>
@@ -163,10 +129,9 @@ export const whileTrue = produce =>
163
129
 
164
130
  /**
165
131
  * @template T
166
- * @param {() => T} produce
167
- * The value of `await produce()` is used for its truthiness vs falsiness.
168
- * IOW, it is coerced to a boolean so the caller need not bother doing this
169
- * themselves.
132
+ * @param {() => T} produce The value of `await produce()` is used for its
133
+ * truthiness vs falsiness. IOW, it is coerced to a boolean so the caller need
134
+ * not bother doing this themselves.
170
135
  * @returns {AsyncIterable<Awaited<T>>}
171
136
  */
172
137
  export const untilTrue = produce =>
@@ -184,10 +149,14 @@ export const untilTrue = produce =>
184
149
  });
185
150
  });
186
151
 
187
- /** @type { <X, Y>(xs: X[], ys: Y[]) => [X, Y][]} */
152
+ /** @type {<X, Y>(xs: X[], ys: Y[]) => [X, Y][]} */
188
153
  export const zip = (xs, ys) => harden(xs.map((x, i) => [x, ys[+i]]));
189
154
 
190
- /** @type { <T extends Record<string, ERef<any>>>(obj: T) => Promise<{ [K in keyof T]: Awaited<T[K]>}> } */
155
+ /**
156
+ * @type {<T extends Record<string, ERef<any>>>(
157
+ * obj: T,
158
+ * ) => Promise<{ [K in keyof T]: Awaited<T[K]> }>}
159
+ */
191
160
  export const allValues = async obj => {
192
161
  const resolved = await Promise.all(values(obj));
193
162
  // @ts-expect-error cast
@@ -195,9 +164,9 @@ export const allValues = async obj => {
195
164
  };
196
165
 
197
166
  /**
198
- * A tee implementation where all readers are synchronized with each other.
199
- * They all consume the source stream in lockstep, and any one returning or
200
- * throwing early will affect the others.
167
+ * A tee implementation where all readers are synchronized with each other. They
168
+ * all consume the source stream in lockstep, and any one returning or throwing
169
+ * early will affect the others.
201
170
  *
202
171
  * @template [T=unknown]
203
172
  * @param {AsyncIterator<T, void, void>} sourceStream
@@ -207,7 +176,11 @@ export const synchronizedTee = (sourceStream, readerCount) => {
207
176
  /** @type {IteratorReturnResult<void> | undefined} */
208
177
  let doneResult;
209
178
 
210
- /** @typedef {IteratorResult<(value: PromiseLike<IteratorResult<T>>) => void>} QueuePayload */
179
+ /**
180
+ * @typedef {IteratorResult<
181
+ * (value: PromiseLike<IteratorResult<T>>) => void
182
+ * >} QueuePayload
183
+ */
211
184
  /** @type {import('@endo/stream').AsyncQueue<QueuePayload>[]} */
212
185
  const queues = [];
213
186
 
@@ -267,13 +240,21 @@ export const synchronizedTee = (sourceStream, readerCount) => {
267
240
  /** @type {AsyncGenerator<T, void, void>} */
268
241
  const reader = harden({
269
242
  async next() {
270
- /** @type {import('@endo/promise-kit').PromiseKit<IteratorResult<T>>} */
243
+ /**
244
+ * @type {import('@endo/promise-kit').PromiseKit<
245
+ * IteratorResult<T>
246
+ * >}
247
+ */
271
248
  const { promise, resolve } = makePromiseKit();
272
249
  queue.put({ value: resolve, done: false });
273
250
  return promise;
274
251
  },
275
252
  async return() {
276
- /** @type {import('@endo/promise-kit').PromiseKit<IteratorResult<T>>} */
253
+ /**
254
+ * @type {import('@endo/promise-kit').PromiseKit<
255
+ * IteratorResult<T>
256
+ * >}
257
+ */
277
258
  const { promise, resolve } = makePromiseKit();
278
259
  queue.put({ value: resolve, done: true });
279
260
  return promise;