@agoric/internal 0.3.3-other-dev-3eb1a1d.0 → 0.3.3-other-dev-d15096d.0.d15096d

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 (111) hide show
  1. package/README.md +1 -4
  2. package/package.json +29 -23
  3. package/src/action-types.d.ts +2 -1
  4. package/src/action-types.d.ts.map +1 -1
  5. package/src/action-types.js +4 -4
  6. package/src/batched-deliver.d.ts +6 -2
  7. package/src/batched-deliver.d.ts.map +1 -1
  8. package/src/batched-deliver.js +7 -2
  9. package/src/callback.d.ts +10 -12
  10. package/src/callback.d.ts.map +1 -1
  11. package/src/callback.js +23 -16
  12. package/src/chain-storage-paths.d.ts.map +1 -1
  13. package/src/chain-utils.d.ts +3 -1
  14. package/src/chain-utils.d.ts.map +1 -1
  15. package/src/chain-utils.js +6 -1
  16. package/src/cli-utils.d.ts +2 -0
  17. package/src/cli-utils.d.ts.map +1 -0
  18. package/src/cli-utils.js +21 -0
  19. package/src/config.d.ts +21 -4
  20. package/src/config.d.ts.map +1 -1
  21. package/src/config.js +25 -2
  22. package/src/debug.d.ts +4 -1
  23. package/src/debug.d.ts.map +1 -1
  24. package/src/debug.js +26 -13
  25. package/src/errors.d.ts +1 -1
  26. package/src/errors.d.ts.map +1 -1
  27. package/src/hex.d.ts +15 -0
  28. package/src/hex.d.ts.map +1 -0
  29. package/src/hex.js +105 -0
  30. package/src/index.d.ts +5 -3
  31. package/src/index.js +13 -4
  32. package/src/js-utils.d.ts +38 -1
  33. package/src/js-utils.d.ts.map +1 -1
  34. package/src/js-utils.js +184 -14
  35. package/src/lib-chainStorage.d.ts +45 -32
  36. package/src/lib-chainStorage.d.ts.map +1 -1
  37. package/src/lib-chainStorage.js +24 -32
  38. package/src/lib-nodejs/ava-unhandled-rejection.d.ts +13 -0
  39. package/src/lib-nodejs/ava-unhandled-rejection.d.ts.map +1 -0
  40. package/src/lib-nodejs/ava-unhandled-rejection.js +66 -0
  41. package/src/lib-nodejs/spawnSubprocessWorker.d.ts +0 -2
  42. package/src/lib-nodejs/spawnSubprocessWorker.d.ts.map +1 -1
  43. package/src/lib-nodejs/spawnSubprocessWorker.js +5 -3
  44. package/src/lib-nodejs/waitUntilQuiescent.d.ts +3 -0
  45. package/src/lib-nodejs/waitUntilQuiescent.d.ts.map +1 -1
  46. package/src/lib-nodejs/waitUntilQuiescent.js +5 -1
  47. package/src/marshal/board-client-utils.d.ts +19 -0
  48. package/src/marshal/board-client-utils.d.ts.map +1 -0
  49. package/src/{marshal.js → marshal/board-client-utils.js} +30 -36
  50. package/src/marshal/cap-data.d.ts +3 -0
  51. package/src/marshal/cap-data.d.ts.map +1 -0
  52. package/src/marshal/cap-data.js +20 -0
  53. package/src/marshal/inaccessible-val.d.ts +2 -0
  54. package/src/marshal/inaccessible-val.d.ts.map +1 -0
  55. package/src/marshal/inaccessible-val.js +15 -0
  56. package/src/marshal/pure-data.d.ts +8 -0
  57. package/src/marshal/pure-data.d.ts.map +1 -0
  58. package/src/marshal/pure-data.js +14 -0
  59. package/src/marshal/wrap-marshaller.d.ts +33 -0
  60. package/src/marshal/wrap-marshaller.d.ts.map +1 -0
  61. package/src/marshal/wrap-marshaller.js +439 -0
  62. package/src/method-tools.d.ts.map +1 -1
  63. package/src/method-tools.js +8 -50
  64. package/src/metrics.d.ts +183 -0
  65. package/src/metrics.d.ts.map +1 -0
  66. package/src/metrics.js +476 -0
  67. package/src/module-utils.d.ts +2 -0
  68. package/src/module-utils.d.ts.map +1 -0
  69. package/src/module-utils.js +27 -0
  70. package/src/natural-sort.d.ts +2 -0
  71. package/src/natural-sort.d.ts.map +1 -0
  72. package/src/natural-sort.js +83 -0
  73. package/src/netstring.d.ts +2 -2
  74. package/src/netstring.d.ts.map +1 -1
  75. package/src/netstring.js +1 -0
  76. package/src/node/buffer-line-transform.d.ts +12 -7
  77. package/src/node/buffer-line-transform.d.ts.map +1 -1
  78. package/src/node/buffer-line-transform.js +8 -4
  79. package/src/node/fs-stream.d.ts +4 -1
  80. package/src/node/fs-stream.d.ts.map +1 -1
  81. package/src/node/fs-stream.js +28 -27
  82. package/src/node/shutdown.d.ts.map +1 -1
  83. package/src/node/shutdown.js +2 -0
  84. package/src/priority-senders.d.ts +3 -1
  85. package/src/priority-senders.d.ts.map +1 -1
  86. package/src/priority-senders.js +7 -2
  87. package/src/queue.d.ts +1 -1
  88. package/src/queue.d.ts.map +1 -1
  89. package/src/ses-utils.d.ts +24 -5
  90. package/src/ses-utils.d.ts.map +1 -1
  91. package/src/ses-utils.js +189 -15
  92. package/src/storage-test-utils.d.ts +25 -7
  93. package/src/storage-test-utils.d.ts.map +1 -1
  94. package/src/storage-test-utils.js +141 -22
  95. package/src/tagged.d.ts +4 -1
  96. package/src/testing-utils.js +1 -1
  97. package/src/tmpDir.d.ts +2 -0
  98. package/src/tmpDir.d.ts.map +1 -0
  99. package/src/tmpDir.js +17 -0
  100. package/src/tokens.d.ts.map +1 -1
  101. package/src/typeGuards.d.ts +19 -0
  102. package/src/typeGuards.d.ts.map +1 -1
  103. package/src/typeGuards.js +16 -0
  104. package/src/types.d.ts +30 -17
  105. package/src/types.d.ts.map +1 -1
  106. package/src/types.ts +43 -18
  107. package/src/work-pool.d.ts +13 -0
  108. package/src/work-pool.d.ts.map +1 -0
  109. package/src/work-pool.js +233 -0
  110. package/src/marshal.d.ts +0 -20
  111. package/src/marshal.d.ts.map +0 -1
@@ -1,4 +1,23 @@
1
+ /**
2
+ * @import {TypedPattern} from './types.js';
3
+ */
1
4
  export const StorageNodeShape: import("@endo/patterns").Matcher;
2
5
  /** To be used only for 'helper' facets where the calls are from trusted code. */
3
6
  export const UnguardedHelperI: import("@endo/patterns").InterfaceGuard<any>;
7
+ /**
8
+ * @typedef {number | `${bigint}`} BridgeBigInt Ensure that callees passed a
9
+ * bridge message that was serialised from a Golang int64 or uint64 accept
10
+ * either a JS number or a stringified JS bigint.
11
+ */
12
+ /**
13
+ * @type {TypedPattern<BridgeBigInt>}
14
+ */
15
+ export const BridgeBigIntShape: TypedPattern<BridgeBigInt>;
16
+ /**
17
+ * Ensure that callees passed a
18
+ * bridge message that was serialised from a Golang int64 or uint64 accept
19
+ * either a JS number or a stringified JS bigint.
20
+ */
21
+ export type BridgeBigInt = number | `${bigint}`;
22
+ import type { TypedPattern } from './types.js';
4
23
  //# sourceMappingURL=typeGuards.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"typeGuards.d.ts","sourceRoot":"","sources":["typeGuards.js"],"names":[],"mappings":"AAIA,gEAA2D;AAE3D,iFAAiF;AACjF,4EAKE"}
1
+ {"version":3,"file":"typeGuards.d.ts","sourceRoot":"","sources":["typeGuards.js"],"names":[],"mappings":"AAKA;;GAEG;AAEH,gEAA2D;AAE3D,iFAAiF;AACjF,4EAKE;AAEF;;;;GAIG;AAEH;;GAEG;AACH,gCAFU,aAAa,YAAY,CAAC,CAE0B;;;;;;2BARjD,MAAM,GAAG,GAAG,MAAM,EAAE;kCAdF,YAAY"}
package/src/typeGuards.js CHANGED
@@ -1,7 +1,12 @@
1
1
  // @jessie-check
2
+ // @ts-check
2
3
 
3
4
  import { M } from '@endo/patterns';
4
5
 
6
+ /**
7
+ * @import {TypedPattern} from './types.js';
8
+ */
9
+
5
10
  export const StorageNodeShape = M.remotable('StorageNode');
6
11
 
7
12
  /** To be used only for 'helper' facets where the calls are from trusted code. */
@@ -11,3 +16,14 @@ export const UnguardedHelperI = M.interface(
11
16
  // not exposed so sloppy okay
12
17
  { sloppy: true },
13
18
  );
19
+
20
+ /**
21
+ * @typedef {number | `${bigint}`} BridgeBigInt Ensure that callees passed a
22
+ * bridge message that was serialised from a Golang int64 or uint64 accept
23
+ * either a JS number or a stringified JS bigint.
24
+ */
25
+
26
+ /**
27
+ * @type {TypedPattern<BridgeBigInt>}
28
+ */
29
+ export const BridgeBigIntShape = M.or(M.number(), M.string());
package/src/types.d.ts CHANGED
@@ -11,6 +11,18 @@ export type TotalMap<K, V> = Omit<Map<K, V>, 'get'> & {
11
11
  get: (key: K) => V;
12
12
  };
13
13
  export type TotalMapFrom<M extends Map<any, any>> = M extends Map<infer K, infer V> ? TotalMap<K, V> : never;
14
+ /**
15
+ * A permit is either `true` or a string (both meaning no attenuation, with a
16
+ * string serving as a grouping label for convenience and/or diagram
17
+ * generation), or an object whose keys identify child properties and whose
18
+ * corresponding values are theirselves (recursive) Permits.
19
+ */
20
+ export type Permit<T> = true | string | Partial<{
21
+ [K in keyof T]: K extends string ? Permit<T[K]> : never;
22
+ }>;
23
+ export type Attenuated<T, P extends Permit<T>> = P extends object ? {
24
+ [K in keyof P]: K extends keyof T ? P[K] extends Permit<T[K]> ? Attenuated<T[K], P[K]> : never : never;
25
+ } : T;
14
26
  export declare class Callback<I extends (...args: any[]) => any> {
15
27
  private iface;
16
28
  target: any;
@@ -23,19 +35,19 @@ export declare class SyncCallback<I extends (...args: unknown[]) => any> extends
23
35
  isSync: true;
24
36
  }
25
37
  /**
26
- Returns a boolean for whether the given type is primitive value or primitive type.
27
-
28
- @example
29
- ```
30
- IsPrimitive<'string'>
31
- //=> true
32
-
33
- IsPrimitive<string>
34
- //=> true
35
-
36
- IsPrimitive<Object>
37
- //=> false
38
- ```
38
+ * Returns a boolean for whether the given type is a primitive value or
39
+ * primitive type.
40
+ *
41
+ * @example
42
+ * ```
43
+ * IsPrimitive<'string'>
44
+ * //=> true
45
+ *
46
+ * IsPrimitive<string>
47
+ * //=> true
48
+ *
49
+ * IsPrimitive<Object>
50
+ * //=> false
39
51
  */
40
52
  export type IsPrimitive<T> = [T] extends [Primitive] ? true : false;
41
53
  /** Recursively extract the non-callable properties of T */
@@ -49,9 +61,10 @@ export type DataOnly<T> = IsPrimitive<T> extends true ? T : T extends Callable ?
49
61
  */
50
62
  export type Remote<Primary, Local = DataOnly<Primary>> = Primary | RemotableBrand<Local, Primary>;
51
63
  /**
52
- * Potentially remote promises or settled references.
64
+ * A type that accepts either resolved or promised references that may be either
65
+ * near or marshalled. @see {ERef} and @see {Remote}.
53
66
  */
54
- export type FarRef<Primary, Local = DataOnly<Primary>> = ERef<Remote<Primary, Local>>;
67
+ export type ERemote<Primary, Local = DataOnly<Primary>> = ERef<Remote<Primary, Local>>;
55
68
  declare const validatedType: unique symbol;
56
69
  /**
57
70
  * Tag a pattern with the static type it represents.
@@ -66,8 +79,8 @@ export declare type PatternType<TM extends TypedPattern<any>> = TM extends Typed
66
79
  *
67
80
  * Note: remotables can only be matched as "remotable", not the specific kind.
68
81
  *
69
- * @see {import('@endo/patterns').mustMatch} for the implementation. This one has a type annotation to narrow if the pattern is a TypedPattern.
82
+ * @see {endoMustMatch} for the implementation. This one has a type annotation to narrow if the pattern is a TypedPattern.
70
83
  */
71
84
  export declare type MustMatch = <P extends Pattern>(specimen: unknown, pattern: P, label?: string | number) => asserts specimen is P extends TypedPattern<any> ? PatternType<P> : unknown;
72
- export {};
85
+ export type { TraceLogger } from './debug.js';
73
86
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG;IACpD,6EAA6E;IAC7E,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;CACpB,CAAC;AACF,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,IAC9C,CAAC,SAA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;GAOG;AACH,MAAM,CAAC,OAAO,MAAM,SAAS,GAAG,CAAC,CAAC,SAAS,OAAO,EAChD,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,CAAC,EACV,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,KACpB,OAAO,CAAC,QAAQ,IAAI,CAAC,SAAS,YAAY,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;AAEhF,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
package/src/types.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /* eslint-disable max-classes-per-file */
2
2
  import type { ERef, RemotableBrand } from '@endo/eventual-send';
3
3
  import type { Primitive } from '@endo/pass-style';
4
- import type { Pattern } from '@endo/patterns';
4
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- used in JSDoc
5
+ import type { mustMatch as endoMustMatch, Pattern } from '@endo/patterns';
5
6
  import type { Callable } from './ses-utils.js';
6
7
 
7
8
  /**
@@ -15,6 +16,27 @@ export type TotalMap<K, V> = Omit<Map<K, V>, 'get'> & {
15
16
  export type TotalMapFrom<M extends Map<any, any>> =
16
17
  M extends Map<infer K, infer V> ? TotalMap<K, V> : never;
17
18
 
19
+ /**
20
+ * A permit is either `true` or a string (both meaning no attenuation, with a
21
+ * string serving as a grouping label for convenience and/or diagram
22
+ * generation), or an object whose keys identify child properties and whose
23
+ * corresponding values are theirselves (recursive) Permits.
24
+ */
25
+ export type Permit<T> =
26
+ | true
27
+ | string
28
+ | Partial<{ [K in keyof T]: K extends string ? Permit<T[K]> : never }>;
29
+
30
+ export type Attenuated<T, P extends Permit<T>> = P extends object
31
+ ? {
32
+ [K in keyof P]: K extends keyof T
33
+ ? P[K] extends Permit<T[K]>
34
+ ? Attenuated<T[K], P[K]>
35
+ : never
36
+ : never;
37
+ }
38
+ : T;
39
+
18
40
  export declare class Callback<I extends (...args: any[]) => any> {
19
41
  private iface: I;
20
42
 
@@ -36,19 +58,19 @@ export declare class SyncCallback<
36
58
  }
37
59
 
38
60
  /**
39
- Returns a boolean for whether the given type is primitive value or primitive type.
40
-
41
- @example
42
- ```
43
- IsPrimitive<'string'>
44
- //=> true
45
-
46
- IsPrimitive<string>
47
- //=> true
48
-
49
- IsPrimitive<Object>
50
- //=> false
51
- ```
61
+ * Returns a boolean for whether the given type is a primitive value or
62
+ * primitive type.
63
+ *
64
+ * @example
65
+ * ```
66
+ * IsPrimitive<'string'>
67
+ * //=> true
68
+ *
69
+ * IsPrimitive<string>
70
+ * //=> true
71
+ *
72
+ * IsPrimitive<Object>
73
+ * //=> false
52
74
  */
53
75
  export type IsPrimitive<T> = [T] extends [Primitive] ? true : false;
54
76
 
@@ -69,11 +91,12 @@ export type Remote<Primary, Local = DataOnly<Primary>> =
69
91
  | Primary
70
92
  | RemotableBrand<Local, Primary>;
71
93
 
72
- // TODO: Add type tests for FarRef and Remote.
94
+ // TODO: Add type tests for Remote and ERemote.
73
95
  /**
74
- * Potentially remote promises or settled references.
96
+ * A type that accepts either resolved or promised references that may be either
97
+ * near or marshalled. @see {ERef} and @see {Remote}.
75
98
  */
76
- export type FarRef<Primary, Local = DataOnly<Primary>> = ERef<
99
+ export type ERemote<Primary, Local = DataOnly<Primary>> = ERef<
77
100
  Remote<Primary, Local>
78
101
  >;
79
102
 
@@ -99,10 +122,12 @@ export declare type PatternType<TM extends TypedPattern<any>> =
99
122
  *
100
123
  * Note: remotables can only be matched as "remotable", not the specific kind.
101
124
  *
102
- * @see {import('@endo/patterns').mustMatch} for the implementation. This one has a type annotation to narrow if the pattern is a TypedPattern.
125
+ * @see {endoMustMatch} for the implementation. This one has a type annotation to narrow if the pattern is a TypedPattern.
103
126
  */
104
127
  export declare type MustMatch = <P extends Pattern>(
105
128
  specimen: unknown,
106
129
  pattern: P,
107
130
  label?: string | number,
108
131
  ) => asserts specimen is P extends TypedPattern<any> ? PatternType<P> : unknown;
132
+
133
+ export type { TraceLogger } from './debug.js';
@@ -0,0 +1,13 @@
1
+ export function makeWorkPool<T, U = T, M extends "all" | "allSettled" = "all">(source: AsyncIterable<T> | Iterable<T>, config: undefined | [capacity: number][0] | {
2
+ capacity?: number;
3
+ mode?: M;
4
+ }, processInput?: (input: Awaited<T>, index?: number) => Promise<Awaited<U>> | Awaited<U>): AsyncGenerator<[M extends "allSettled" ? PromiseSettledResult<Awaited<U>> : Awaited<U>, number]> & {
5
+ done: Promise<boolean>;
6
+ then: () => never;
7
+ };
8
+ export type PromiseKit<T> = {
9
+ resolve: (value: T | PromiseLike<T>) => void;
10
+ reject: (reason: any) => void;
11
+ promise: Promise<T>;
12
+ };
13
+ //# sourceMappingURL=work-pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"work-pool.d.ts","sourceRoot":"","sources":["work-pool.js"],"names":[],"mappings":"AAgFO,6BAlBM,CAAC,EACA,CAAC,MACsB,CAAC,SAAxB,KAAK,GAAG,YAAa,kBACxB,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,UAC9B,SAAS,GACb,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,GACrB;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,CAAC,CAAA;CAAE,iBAC3B,CACN,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EACjB,KAAK,CAAC,EAAE,MAAM,KACX,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAC3B,cAAc,CAC1B,CACM,CAAC,SAAS,YAAY,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAC5E,MAAY,CACP,CACF,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,KAAK,CAAA;CAAE,CA0JnD;uBAtNY,CAAC;aAEA,CAAC,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI;YACnC,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI;aACrB,OAAO,CAAC,CAAC,CAAC"}
@@ -0,0 +1,233 @@
1
+ // @ts-check
2
+ /**
3
+ * @file A pure JavaScript async work pool utility that is compatible with but
4
+ * not dependent upon a hardened environment.
5
+ */
6
+
7
+ const { isInteger } = Number;
8
+
9
+ const sink = () => {};
10
+
11
+ /**
12
+ * @param {unknown} val
13
+ * @returns {val is bigint | boolean | null | number | string | symbol | undefined}
14
+ */
15
+ const isPrimitive = val =>
16
+ !val || (typeof val !== 'object' && typeof val !== 'function');
17
+
18
+ /**
19
+ * @template T
20
+ * @typedef {object} PromiseKit
21
+ * @property {(value: T | PromiseLike<T>) => void} resolve
22
+ * @property {(reason: any) => void} reject
23
+ * @property {Promise<T>} promise
24
+ */
25
+
26
+ /**
27
+ * @template T
28
+ * @returns {PromiseKit<T>}
29
+ */
30
+ const makePromiseKit = () => {
31
+ /** @type {PromiseKit<T>['resolve']} */
32
+ let resolve;
33
+ /** @type {PromiseKit<T>['reject']} */
34
+ let reject;
35
+ const promise = new Promise((res, rej) => {
36
+ resolve = res;
37
+ reject = rej;
38
+ });
39
+ // @ts-expect-error TS2454 use before assign
40
+ return { promise, resolve, reject };
41
+ };
42
+
43
+ /**
44
+ * Consume an async iterable with at most `capacity` unsettled results at any
45
+ * given time, passing each input through `processInput` and providing [result,
46
+ * index] pairs in settlement order. Source order can be recovered with consumer
47
+ * code like:
48
+ *
49
+ * const results = [];
50
+ * for (const [result, i] of makeWorkPool(...)) results[i] = result;
51
+ *
52
+ * or something more sophisticated to eagerly detect complete subsequences
53
+ * immediately following a previous high-water mark for contiguous results.
54
+ *
55
+ * To support cases in which `processInput` is used only for side effects rather
56
+ * than its return value, the returned AsyncGenerator has a promise-valued
57
+ * `done` property that fulfills when all input has been processed (to `true` if
58
+ * the source was exhausted or to `false` if iteration was aborted early),
59
+ * regardless of how many final iteration results have been consumed:
60
+ *
61
+ * await makeWorkPool(...).done;
62
+ *
63
+ * @template T
64
+ * @template [U=T]
65
+ * @template {'all' | 'allSettled'} [M='all']
66
+ * @param {AsyncIterable<T> | Iterable<T>} source
67
+ * @param {undefined
68
+ * | [capacity: number][0]
69
+ * | { capacity?: number; mode?: M }} config
70
+ * @param {(
71
+ * input: Awaited<T>,
72
+ * index?: number,
73
+ * ) => Promise<Awaited<U>> | Awaited<U>} [processInput]
74
+ * @returns {AsyncGenerator<
75
+ * [
76
+ * M extends 'allSettled' ? PromiseSettledResult<Awaited<U>> : Awaited<U>,
77
+ * number,
78
+ * ]
79
+ * > & { done: Promise<boolean>; then: () => never }}
80
+ */
81
+ export const makeWorkPool = (
82
+ source,
83
+ config,
84
+ processInput = x => /** @type {any} */ (x),
85
+ ) => {
86
+ // Validate arguments.
87
+ if (isPrimitive(config)) config = { capacity: config, mode: undefined };
88
+ const { capacity = 10, mode = 'all' } = config;
89
+ if (!(capacity === Infinity || (isInteger(capacity) && capacity > 0))) {
90
+ throw RangeError('capacity must be a positive integer');
91
+ }
92
+ if (mode !== 'all' && mode !== 'allSettled') {
93
+ throw RangeError('mode must be "all" or "allSettled"');
94
+ }
95
+
96
+ // Normalize source into an `inputs` iterator.
97
+ const makeInputs = source[Symbol.asyncIterator] || source[Symbol.iterator];
98
+ const inputs =
99
+ /** @type {AsyncIterator<Awaited<T>> | Iterator<Awaited<T>>} */ (
100
+ Reflect.apply(makeInputs, source, [])
101
+ );
102
+ let inputsExhausted = false;
103
+ let terminated = false;
104
+ const doneKit = /** @type {PromiseKit<boolean>} */ (makePromiseKit());
105
+
106
+ // Concurrently consume up to `capacity` inputs, pushing the result of
107
+ // processing each into a linked chain of promises before consuming more.
108
+ let nextIndex = 0;
109
+ /**
110
+ * @typedef {object} ResultNode
111
+ * @property {Promise<ResultNode>} nextP
112
+ * @property {number} index
113
+ * @property {M extends 'allSettled'
114
+ * ? PromiseSettledResult<Awaited<U>>
115
+ * : Awaited<U>} result
116
+ */
117
+ const { promise: headP, ...headResolvers } =
118
+ /** @type {PromiseKit<ResultNode>} */ (makePromiseKit());
119
+ let { resolve: resolveCurrent, reject } = headResolvers;
120
+ let inFlight = 0;
121
+ const takeMoreInput = async () => {
122
+ await null;
123
+ while (inFlight < capacity && !inputsExhausted && !terminated) {
124
+ inFlight += 1;
125
+ const index = nextIndex;
126
+ nextIndex += 1;
127
+ /** @type {Promise<IteratorResult<Awaited<T>>>} */
128
+ let iterResultP;
129
+ try {
130
+ iterResultP = Promise.resolve(inputs.next());
131
+ } catch (err) {
132
+ iterResultP = Promise.reject(err);
133
+ }
134
+ void iterResultP
135
+ .then(async iterResult => {
136
+ if (terminated) return;
137
+
138
+ if (iterResult.done) {
139
+ inFlight -= 1;
140
+ inputsExhausted = true;
141
+ void takeMoreInput();
142
+ return;
143
+ }
144
+
145
+ // Process the input, propagating errors if mode is not "allSettled".
146
+ await null;
147
+ /** @type {PromiseSettledResult<Awaited<U>>} */
148
+ let settlementDesc = { status: 'rejected', reason: undefined };
149
+ try {
150
+ const fulfillment = await processInput(iterResult.value, index);
151
+ if (terminated) return;
152
+ settlementDesc = { status: 'fulfilled', value: fulfillment };
153
+ } catch (err) {
154
+ if (terminated) return;
155
+ if (mode !== 'allSettled') throw err;
156
+ /** @type {PromiseRejectedResult} */ (settlementDesc).reason = err;
157
+ }
158
+
159
+ // Fulfill the current tail promise with a record that includes the
160
+ // source index to which it corresponds and a reference to a new
161
+ // [unsettled] successor (thereby extending the chain), then try to
162
+ // consume more input.
163
+ const { promise: nextP, ...nextResolvers } =
164
+ /** @type {PromiseKit<ResultNode>} */ (makePromiseKit());
165
+ // Analogous to `Promise.allSettled`, mode "allSettled" produces
166
+ // { status, value, reason } PromiseSettledResult records.
167
+ const result =
168
+ mode === 'allSettled'
169
+ ? settlementDesc
170
+ : /** @type {PromiseFulfilledResult<Awaited<U>>} */ (
171
+ settlementDesc
172
+ ).value;
173
+ inFlight -= 1;
174
+ void takeMoreInput();
175
+ const untypedResult = /** @type {any} */ (result);
176
+ resolveCurrent({ nextP, index, result: untypedResult });
177
+ ({ resolve: resolveCurrent, reject } = nextResolvers);
178
+ })
179
+ .catch(err => {
180
+ // End the chain with this rejection.
181
+ terminated = true;
182
+ reject(err);
183
+ doneKit.reject(err);
184
+ void (async () => inputs.throw?.(err))().catch(sink);
185
+ });
186
+ }
187
+ if (inFlight <= 0 && inputsExhausted) {
188
+ // @ts-expect-error This dummy signaling record conveys no result.
189
+ resolveCurrent({ nextP: undefined, index: -1, result: undefined });
190
+ doneKit.resolve(true);
191
+ }
192
+ };
193
+
194
+ const results = (async function* generateResults(nextP) {
195
+ await null;
196
+ let exhausted = false;
197
+ try {
198
+ for (;;) {
199
+ const { nextP: successor, index, result } = await nextP;
200
+ nextP = successor;
201
+ if (!successor) break;
202
+ yield /** @type {[typeof result, number]} */ (
203
+ Object.freeze([result, index])
204
+ );
205
+ }
206
+ exhausted = true;
207
+ } catch (err) {
208
+ terminated = true;
209
+ doneKit.reject(err);
210
+ void (async () => inputs.throw?.(err))().catch(sink);
211
+ throw err;
212
+ } finally {
213
+ const interrupted = !exhausted && !terminated;
214
+ terminated = true;
215
+ doneKit.resolve(false);
216
+ if (interrupted) void (async () => inputs.return?.())().catch(sink);
217
+ }
218
+ })(headP);
219
+ Object.defineProperty(results, 'done', {
220
+ value: doneKit.promise,
221
+ enumerable: true,
222
+ });
223
+ Object.defineProperty(results, 'then', {
224
+ value: () => {
225
+ throw Error('A work pool is not thenable; did you forget `.done`?');
226
+ },
227
+ });
228
+
229
+ void takeMoreInput();
230
+
231
+ // @ts-expect-error
232
+ return Object.freeze(results);
233
+ };
package/src/marshal.d.ts DELETED
@@ -1,20 +0,0 @@
1
- export function makeBoardRemote({ boardId, iface }: {
2
- boardId: string | null;
3
- iface?: string;
4
- }): BoardRemote;
5
- export function slotToBoardRemote(boardId: string, iface: string): BoardRemote;
6
- export function boardSlottingMarshaller(slotToVal?: ((slot: string, iface: string) => any) | undefined): Omit<import("@endo/marshal").Marshal<string | null>, "serialize" | "unserialize">;
7
- export function unmarshalFromVstorage(data: Map<string, string>, key: string, fromCapData: ReturnType<typeof import("@endo/marshal").makeMarshal>["fromCapData"], index: number): any;
8
- export function makeHistoryReviver(entries: [string, string][], slotToVal?: ((slot: string, iface?: string) => any) | undefined): {
9
- getItem: (key: string) => any;
10
- children: (prefix: string) => string[];
11
- has: (k: string) => boolean;
12
- };
13
- /**
14
- * Should be a union with Remotable, but that's `any`, making this type
15
- * meaningless
16
- */
17
- export type BoardRemote = {
18
- getBoardId: () => string | null;
19
- };
20
- //# sourceMappingURL=marshal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"marshal.d.ts","sourceRoot":"","sources":["marshal.js"],"names":[],"mappings":"AAiBO,oDAHI;IAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GACxC,WAAW,CAKvB;AAMM,2CAHI,MAAM,SACN,MAAM,eAGoB;AAqB9B,4DANW,MAAM,SAAS,MAAM,KAAK,GAAG,gBAClC,IAAI,CAChB,OAAW,eAAe,EAAE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,EAClD,WAAe,GAAG,aAAa,CAC5B,CAMH;AA6BM,4CATI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,OACnB,MAAM,eACN,UAAU,CACpB,cAAkB,eAAe,EAAE,WAAW,CAC3C,CAAC,aAAa,CAAC,SACR,MAAM,GAEJ,GAAG,CAwBf;AASM,4CAHI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,sBACX,MAAM,UAAU,MAAM,KAAK,GAAG;mBAQlC,MAAM;uBAEN,MAAM;aAYN,MAAM;EAInB;;;;;0BA9HY;IAAE,UAAU,EAAE,MAAM,MAAM,GAAG,IAAI,CAAA;CAAE"}