@agoric/internal 0.4.0 → 0.4.1-upgrade-23-dev-bd79330.0.bd79330

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 (131) hide show
  1. package/README.md +1 -4
  2. package/package.json +13 -11
  3. package/src/action-types.d.ts +47 -20
  4. package/src/action-types.d.ts.map +1 -1
  5. package/src/action-types.js +19 -19
  6. package/src/ava-force-exit.d.mts +2 -0
  7. package/src/ava-force-exit.d.mts.map +1 -0
  8. package/src/ava-force-exit.mjs +6 -0
  9. package/src/batched-deliver.d.ts +6 -2
  10. package/src/batched-deliver.d.ts.map +1 -1
  11. package/src/batched-deliver.js +7 -3
  12. package/src/build-cache-types.d.ts +33 -0
  13. package/src/build-cache-types.d.ts.map +1 -0
  14. package/src/build-cache-types.js +42 -0
  15. package/src/build-cache.d.ts +12 -0
  16. package/src/build-cache.d.ts.map +1 -0
  17. package/src/build-cache.js +184 -0
  18. package/src/callback.d.ts +9 -11
  19. package/src/callback.d.ts.map +1 -1
  20. package/src/callback.js +16 -10
  21. package/src/chain-storage-paths.d.ts.map +1 -1
  22. package/src/chain-storage-paths.js +0 -2
  23. package/src/chain-utils.d.ts +3 -1
  24. package/src/chain-utils.d.ts.map +1 -1
  25. package/src/chain-utils.js +6 -1
  26. package/src/config.d.ts +22 -3
  27. package/src/config.d.ts.map +1 -1
  28. package/src/config.js +25 -3
  29. package/src/debug.d.ts +4 -1
  30. package/src/debug.d.ts.map +1 -1
  31. package/src/debug.js +26 -15
  32. package/src/index.d.ts +2 -1
  33. package/src/index.js +10 -3
  34. package/src/js-utils.d.ts +7 -3
  35. package/src/js-utils.d.ts.map +1 -1
  36. package/src/js-utils.js +24 -3
  37. package/src/keyMirror.d.ts +3 -0
  38. package/src/keyMirror.d.ts.map +1 -0
  39. package/src/keyMirror.js +45 -0
  40. package/src/kv-store.d.ts +33 -0
  41. package/src/kv-store.d.ts.map +1 -0
  42. package/src/kv-store.js +257 -0
  43. package/src/lib-chainStorage.d.ts +23 -12
  44. package/src/lib-chainStorage.d.ts.map +1 -1
  45. package/src/lib-chainStorage.js +18 -18
  46. package/src/lib-nodejs/ava-unhandled-rejection.d.ts +18 -3
  47. package/src/lib-nodejs/ava-unhandled-rejection.d.ts.map +1 -1
  48. package/src/lib-nodejs/ava-unhandled-rejection.js +211 -20
  49. package/src/lib-nodejs/engine-gc.js +2 -2
  50. package/src/lib-nodejs/spawnSubprocessWorker.d.ts +0 -2
  51. package/src/lib-nodejs/spawnSubprocessWorker.d.ts.map +1 -1
  52. package/src/lib-nodejs/spawnSubprocessWorker.js +8 -7
  53. package/src/lib-nodejs/waitUntilQuiescent.d.ts +3 -0
  54. package/src/lib-nodejs/waitUntilQuiescent.d.ts.map +1 -1
  55. package/src/lib-nodejs/waitUntilQuiescent.js +5 -1
  56. package/src/lib-nodejs/worker-protocol.d.ts +1 -1
  57. package/src/lib-nodejs/worker-protocol.d.ts.map +1 -1
  58. package/src/lib-nodejs/worker-protocol.js +5 -5
  59. package/src/magic-cookie-test-only.d.ts.map +1 -1
  60. package/src/magic-cookie-test-only.js +0 -2
  61. package/src/marshal/board-client-utils.d.ts +19 -0
  62. package/src/marshal/board-client-utils.d.ts.map +1 -0
  63. package/src/{marshal.js → marshal/board-client-utils.js} +27 -52
  64. package/src/marshal/cap-data.d.ts +11 -0
  65. package/src/marshal/cap-data.d.ts.map +1 -0
  66. package/src/marshal/cap-data.js +19 -0
  67. package/src/marshal/inaccessible-val.d.ts +2 -0
  68. package/src/marshal/inaccessible-val.d.ts.map +1 -0
  69. package/src/marshal/inaccessible-val.js +15 -0
  70. package/src/marshal/pure-data.d.ts +8 -0
  71. package/src/marshal/pure-data.d.ts.map +1 -0
  72. package/src/marshal/pure-data.js +14 -0
  73. package/src/marshal/wrap-marshaller.d.ts +60 -0
  74. package/src/marshal/wrap-marshaller.d.ts.map +1 -0
  75. package/src/marshal/wrap-marshaller.js +432 -0
  76. package/src/module-utils.d.ts +1 -0
  77. package/src/module-utils.d.ts.map +1 -1
  78. package/src/module-utils.js +16 -0
  79. package/src/natural-sort.d.ts.map +1 -1
  80. package/src/natural-sort.js +48 -13
  81. package/src/netstring.d.ts +1 -1
  82. package/src/netstring.d.ts.map +1 -1
  83. package/src/netstring.js +5 -5
  84. package/src/node/buffer-line-transform.d.ts +10 -5
  85. package/src/node/buffer-line-transform.d.ts.map +1 -1
  86. package/src/node/buffer-line-transform.js +8 -4
  87. package/src/node/createBundles.d.ts.map +1 -1
  88. package/src/node/createBundles.js +3 -5
  89. package/src/node/fs-stream.d.ts +4 -1
  90. package/src/node/fs-stream.d.ts.map +1 -1
  91. package/src/node/fs-stream.js +58 -9
  92. package/src/node/read-json.d.ts +2 -0
  93. package/src/node/read-json.d.ts.map +1 -0
  94. package/src/node/read-json.js +18 -0
  95. package/src/node/shutdown.js +1 -1
  96. package/src/priority-senders.d.ts +2 -1
  97. package/src/priority-senders.d.ts.map +1 -1
  98. package/src/priority-senders.js +6 -4
  99. package/src/queue.d.ts.map +1 -1
  100. package/src/queue.js +0 -2
  101. package/src/ses-utils.d.ts +27 -5
  102. package/src/ses-utils.d.ts.map +1 -1
  103. package/src/ses-utils.js +115 -20
  104. package/src/storage-test-utils.d.ts +15 -5
  105. package/src/storage-test-utils.d.ts.map +1 -1
  106. package/src/storage-test-utils.js +62 -8
  107. package/src/tagged.d.ts +18 -1
  108. package/src/testing-utils.d.ts +4 -0
  109. package/src/testing-utils.d.ts.map +1 -1
  110. package/src/testing-utils.js +88 -2
  111. package/src/typeGuards.d.ts +6 -2
  112. package/src/typeGuards.d.ts.map +1 -1
  113. package/src/typeGuards.js +7 -4
  114. package/src/types-index.d.ts +1 -0
  115. package/src/types.d.ts +34 -19
  116. package/src/types.d.ts.map +1 -1
  117. package/src/types.js +173 -0
  118. package/src/upgrade-api.d.ts.map +1 -1
  119. package/src/upgrade-api.js +4 -3
  120. package/src/work-pool.d.ts +13 -0
  121. package/src/work-pool.d.ts.map +1 -0
  122. package/src/work-pool.js +233 -0
  123. package/vendor/anylogger.d.ts +98 -0
  124. package/vendor/anylogger.d.ts.map +1 -0
  125. package/vendor/anylogger.js +60 -0
  126. package/vendor/anylogger.ts +160 -0
  127. package/vendor/tsconfig.anylogger.json +15 -0
  128. package/exported.js +0 -2
  129. package/src/marshal.d.ts +0 -33
  130. package/src/marshal.d.ts.map +0 -1
  131. package/src/types.ts +0 -129
package/src/types.js ADDED
@@ -0,0 +1,173 @@
1
+ /* eslint-disable max-classes-per-file */
2
+
3
+
4
+
5
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- used in JSDoc
6
+
7
+
8
+
9
+ /**
10
+ * A mapping of a tuple type (as from `Parameters<...>`) into a corresponding
11
+ * object type with named fields.
12
+ *
13
+ * @example
14
+ * ```
15
+ * RecordFromTuple<[string, bigint], ['denom', 'amount']>
16
+ * //=> { denom: string, amount: bigint }
17
+ * ```
18
+ */
19
+
20
+
21
+
22
+
23
+
24
+ /**
25
+ * A map corresponding with a total function such that `get(key)` is assumed to
26
+ * always succeed.
27
+ */
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+ /**
36
+ * A permit is either `true` or a string (both meaning no attenuation, with a
37
+ * string serving as a grouping label for convenience and/or diagram
38
+ * generation), or an object whose keys identify child properties and whose
39
+ * corresponding values are theirselves (recursive) Permits.
40
+ */
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+ /**
77
+ * Returns a boolean for whether the given type is a primitive value or
78
+ * primitive type.
79
+ *
80
+ * @example
81
+ * ```
82
+ * IsPrimitive<'string'>
83
+ * //=> true
84
+ *
85
+ * IsPrimitive<string>
86
+ * //=> true
87
+ *
88
+ * IsPrimitive<Object>
89
+ * //=> false
90
+ */
91
+
92
+
93
+ // XXX https://github.com/endojs/endo/issues/2979
94
+
95
+
96
+
97
+
98
+
99
+
100
+ /** Recursively extract the non-callable properties of T */
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+ /**
109
+ * A type that doesn't assume its parameter is local, but is satisfied with both
110
+ * local and remote references. It accepts both near and marshalled references
111
+ * that were returned from `Remotable` or `Far`.
112
+ */
113
+
114
+
115
+
116
+
117
+ // TODO: Add type tests for Remote and ERemote.
118
+ /**
119
+ * A type that accepts either resolved or promised references that may be either
120
+ * near or marshalled. @see {ERef} and @see {Remote}.
121
+ */
122
+
123
+
124
+
125
+
126
+ /*
127
+ * Stop-gap until https://github.com/Agoric/agoric-sdk/issues/6160
128
+ * explictly specify the type that the Pattern will verify through a match.
129
+ *
130
+ * TODO move all this pattern typing stuff to @endo/patterns
131
+ *
132
+ * CAVEAT: We use a constant string here to avoid exposing a `unique symbol`
133
+ * type publicly, such as with:
134
+ *
135
+ * @example
136
+ * declare const mySymbol: unique symbol;
137
+ *
138
+ * Without this workaround, we've observed errors when using at least
139
+ * `typescript@5.9.3`'s `tsc` to generate declaration files (.d.ts) for
140
+ * consumers of modules that in turn import the declaration:
141
+ *
142
+ * @example
143
+ * error TS9006: Declaration emit for this file requires using private name
144
+ * 'tag' from module '.../internal/src/tagged"'. An explicit
145
+ * type annotation may unblock declaration emit.
146
+ */
147
+ // declare const validatedType: unique symbol;
148
+
149
+
150
+ /**
151
+ * Tag a pattern with the static type it represents.
152
+ */
153
+
154
+
155
+
156
+
157
+
158
+ // TODO make Endo's mustMatch do this
159
+ /**
160
+ * Returning normally indicates success. Match failure is indicated by
161
+ * throwing.
162
+ *
163
+ * Note: remotables can only be matched as "remotable", not the specific kind.
164
+ *
165
+ * @see {endoMustMatch} for the implementation. This one has a type annotation to narrow if the pattern is a TypedPattern.
166
+ */
167
+
168
+
169
+
170
+
171
+
172
+
173
+
@@ -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,CAKC;AAgBrC,yCAHI,GAAG,GACD,MAAM,IAAI,KAAK,CAQS;;;;;mCA5DxB;IACR,IAAI,EAAE,aAAa,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;CAC3B"}
1
+ {"version":3,"file":"upgrade-api.d.ts","sourceRoot":"","sources":["upgrade-api.js"],"names":[],"mappings":";;;;;AA+BO,yDAJI,MAAM,uBACN,MAAM,GACJ,oBAAoB,CAO7B;AASG,+CALI,GAAG,GAGD,MAAM,IAAI,oBAAoB,CAMC;AAgBrC,yCAHI,GAAG,GACD,MAAM,IAAI,KAAK,CASS;;;;;mCA9DxB;IACR,IAAI,EAAE,aAAa,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;CAC3B"}
@@ -1,5 +1,4 @@
1
1
  // @ts-check
2
- // @jessie-check
3
2
 
4
3
  import { M, matches } from '@endo/patterns';
5
4
 
@@ -45,7 +44,8 @@ harden(makeUpgradeDisconnection);
45
44
  * @returns {reason is UpgradeDisconnection}
46
45
  */
47
46
  export const isUpgradeDisconnection = reason =>
48
- reason != null && // eslint-disable-line eqeqeq
47
+ reason !== null &&
48
+ reason !== undefined &&
49
49
  isFrozen(reason) &&
50
50
  matches(reason, UpgradeDisconnectionShape);
51
51
  harden(isUpgradeDisconnection);
@@ -64,7 +64,8 @@ harden(isUpgradeDisconnection);
64
64
  * @returns {reason is Error}
65
65
  */
66
66
  export const isAbandonedError = reason =>
67
- reason != null && // eslint-disable-line eqeqeq
67
+ reason !== null &&
68
+ reason !== undefined &&
68
69
  isFrozen(reason) &&
69
70
  matches(reason, M.error()) &&
70
71
  // We're not using a constant here since this special value is already
@@ -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
+ };
@@ -0,0 +1,98 @@
1
+ /**
2
+ * VENDORED SOURCE - DO NOT EDIT DIRECTLY
3
+ *
4
+ * Source of truth for the anylogger vendored module.
5
+ *
6
+ * This vendoring flow intentionally keeps three files:
7
+ * - `vendor/anylogger.ts`: upstream TypeScript source (kept close to upstream).
8
+ * - `vendor/anylogger.js`: generated runtime for consumers that import JS directly.
9
+ * - `vendor/anylogger.d.ts`: generated declarations for type imports from that same JS path.
10
+ *
11
+ * To regenerate generated artifacts after editing the TypeScript source file (vendor/anylogger.ts):
12
+ * `cd packages/internal && yarn run -T tsc --project vendor/tsconfig.anylogger.json`
13
+ */
14
+ /**
15
+ * A log function is a function that takes a variable amount of
16
+ * arguments and returns void.
17
+ */
18
+ export type LogFunction = (...args: any) => void;
19
+ /**
20
+ * The default base log levels for anylogger.
21
+ */
22
+ export type LogLevels = {
23
+ error: 1;
24
+ warn: 2;
25
+ info: 3;
26
+ log: 4;
27
+ debug: 5;
28
+ trace: 6;
29
+ };
30
+ /**
31
+ * A log level is a string that is a key of `LogLevels`.
32
+ */
33
+ export type LogLevel = keyof LogLevels;
34
+ /**
35
+ * All loggers, keyed by name.
36
+ */
37
+ export type AllLoggers = {
38
+ [name: string]: Logger;
39
+ };
40
+ /**
41
+ * An alias for the much used concept of a LoggerName.
42
+ */
43
+ export type LoggerName = string;
44
+ /**
45
+ * An adapter accepts a LogFunction and returns a Logger.
46
+ */
47
+ export type Adapter = (logfn: LogFunction) => Logger;
48
+ /**
49
+ * A logger is a log function that has a `name` that corresponds to the logger
50
+ * name, a method `enabledFor(level: LogLevel)` to check whether the logger is
51
+ * enabled for a certain log level, and log methods for each of the log levels
52
+ * supported by AnyLogger: `error`, `warn`, `info`, `log`, `debug` and `trace`.
53
+ */
54
+ export type Logger = LogFunction & {
55
+ readonly name: LoggerName;
56
+ enabledFor: (level?: LogLevel) => boolean | void;
57
+ } & {
58
+ [P in keyof LogLevels as `${P}`]: LogFunction;
59
+ };
60
+ /**
61
+ * Gets or creates a logger by name.
62
+ */
63
+ export type AnyLogger = ((name: LoggerName) => Logger) & {
64
+ /**
65
+ * Stores all loggers created so far.
66
+ */
67
+ all: AllLoggers;
68
+ /**
69
+ * An object containing a mapping of level names to level values.
70
+ */
71
+ levels: {
72
+ [level: string]: number;
73
+ };
74
+ /**
75
+ * Called when a new logger needs to be created.
76
+ */
77
+ new: (name: LoggerName) => LogFunction;
78
+ /**
79
+ * Called by the log function that the default implementation of
80
+ * `anylogger.new` creates.
81
+ */
82
+ log: (name: LoggerName, ...args: any) => void;
83
+ /**
84
+ * Called when a log function needs to be extended.
85
+ */
86
+ ext: Adapter;
87
+ };
88
+ /**
89
+ * Back-compat alias used by callers in this repository.
90
+ */
91
+ export type BaseLevels = LogLevels;
92
+ /**
93
+ * A N Y L O G G E R
94
+ * Get a logger. Any logger.
95
+ */
96
+ declare const anylogger: AnyLogger;
97
+ export default anylogger;
98
+ //# sourceMappingURL=anylogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anylogger.d.ts","sourceRoot":"","sources":["anylogger.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AAGH;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,CAAC,CAAC;IACT,IAAI,EAAE,CAAC,CAAC;IACR,IAAI,EAAE,CAAC,CAAC;IACR,GAAG,EAAE,CAAC,CAAC;IACP,KAAK,EAAE,CAAC,CAAC;IACT,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC;AAEvC;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,CAAC;AAErD;;;;;GAKG;AACH,MAAM,MAAM,MAAM,GAAG,WAAW,GAAG;IACjC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,UAAU,EAAE,CAAC,KAAK,CAAC,EAAE,QAAQ,KAAK,OAAO,GAAG,IAAI,CAAC;CAClD,GAAG;KACD,CAAC,IAAI,MAAM,SAAS,IAAI,GAAG,CAAC,EAAE,GAAG,WAAW;CAC9C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,IAAI,EAAE,UAAU,KAAK,MAAM,CAAC,GAAG;IACvD;;OAEG;IACH,GAAG,EAAE,UAAU,CAAC;IAEhB;;OAEG;IACH,MAAM,EAAE;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAEpC;;OAEG;IACH,GAAG,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,WAAW,CAAC;IAEvC;;;OAGG;IACH,GAAG,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IAE9C;;OAEG;IACH,GAAG,EAAE,OAAO,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,CAAC;AAEnC;;;GAGG;AAGH,QAAA,MAAM,SAAS,EAIkD,SAAS,CAAC;AAyC3E,eAAe,SAAS,CAAC"}
@@ -0,0 +1,60 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * VENDORED SOURCE - DO NOT EDIT DIRECTLY
4
+ *
5
+ * Source of truth for the anylogger vendored module.
6
+ *
7
+ * This vendoring flow intentionally keeps three files:
8
+ * - `vendor/anylogger.ts`: upstream TypeScript source (kept close to upstream).
9
+ * - `vendor/anylogger.js`: generated runtime for consumers that import JS directly.
10
+ * - `vendor/anylogger.d.ts`: generated declarations for type imports from that same JS path.
11
+ *
12
+ * To regenerate generated artifacts after editing the TypeScript source file (vendor/anylogger.ts):
13
+ * `cd packages/internal && yarn run -T tsc --project vendor/tsconfig.anylogger.json`
14
+ */
15
+ // prettier-ignore-start
16
+ /**
17
+ * A N Y L O G G E R
18
+ * Get a logger. Any logger.
19
+ */
20
+ // the main `anylogger` function
21
+ const anylogger = ((name) =>
22
+ // return the existing logger, or
23
+ anylogger.all[name] ||
24
+ // create and store a new logger with that name
25
+ (anylogger.all[name] = anylogger.ext(anylogger.new(name))));
26
+ // all loggers created so far
27
+ anylogger.all = Object.create(null);
28
+ // the supported levels
29
+ anylogger.levels = { error: 1, warn: 2, info: 3, log: 4, debug: 5, trace: 6 };
30
+ // creates a new named log function
31
+ anylogger.new = name => ({
32
+ // to assign the function `name`, set it to a named key in an object.
33
+ // the default implementation calls `anylogger.log`, which should be a
34
+ // good choice in many cases.
35
+ [name]: (...args) => anylogger.log(name, ...args),
36
+ })[name]; // return only the function, not the encapsulating object
37
+ // logs with the logger with the given `name`
38
+ anylogger.log = (name, ...args) => {
39
+ // select the logger to use
40
+ anylogger.all[name][
41
+ // select the level to use
42
+ // if multiple args and first matches a level name
43
+ args.length > 1 && anylogger.levels[args[0]]
44
+ ? args.shift() // use the level from the args
45
+ : 'log' // else use default level `'log'`
46
+ ](...args); // call method matching level with remaining args
47
+ };
48
+ // extends the given `logger` function
49
+ // the implementation here only adds no-ops
50
+ // adapters should change this behavior
51
+ anylogger.ext = (logger) => {
52
+ logger.enabledFor = () => { };
53
+ for (const method in anylogger.levels) {
54
+ logger[method] = () => { };
55
+ }
56
+ return logger;
57
+ };
58
+ // this is a real ESM module
59
+ export default anylogger;
60
+ // prettier-ignore-end