@agoric/internal 0.3.3-other-dev-fbe72e7.0.fbe72e7 → 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.
- package/README.md +1 -4
- package/package.json +7 -5
- package/src/batched-deliver.d.ts +6 -2
- package/src/batched-deliver.d.ts.map +1 -1
- package/src/batched-deliver.js +7 -2
- package/src/callback.d.ts +9 -11
- package/src/callback.d.ts.map +1 -1
- package/src/callback.js +16 -10
- package/src/config.d.ts +19 -0
- package/src/config.d.ts.map +1 -1
- package/src/config.js +21 -0
- package/src/debug.d.ts +4 -1
- package/src/debug.d.ts.map +1 -1
- package/src/debug.js +26 -13
- package/src/index.d.ts +1 -1
- package/src/index.js +9 -1
- package/src/js-utils.d.ts +6 -2
- package/src/js-utils.d.ts.map +1 -1
- package/src/js-utils.js +23 -1
- package/src/lib-chainStorage.d.ts +23 -12
- package/src/lib-chainStorage.d.ts.map +1 -1
- package/src/lib-chainStorage.js +18 -18
- package/src/lib-nodejs/spawnSubprocessWorker.d.ts +0 -2
- package/src/lib-nodejs/spawnSubprocessWorker.d.ts.map +1 -1
- package/src/lib-nodejs/spawnSubprocessWorker.js +5 -3
- package/src/lib-nodejs/waitUntilQuiescent.d.ts +3 -0
- package/src/lib-nodejs/waitUntilQuiescent.d.ts.map +1 -1
- package/src/lib-nodejs/waitUntilQuiescent.js +5 -1
- package/src/marshal/board-client-utils.d.ts +19 -0
- package/src/marshal/board-client-utils.d.ts.map +1 -0
- package/src/{marshal.js → marshal/board-client-utils.js} +27 -52
- package/src/marshal/cap-data.d.ts +3 -0
- package/src/marshal/cap-data.d.ts.map +1 -0
- package/src/marshal/cap-data.js +20 -0
- package/src/marshal/inaccessible-val.d.ts +2 -0
- package/src/marshal/inaccessible-val.d.ts.map +1 -0
- package/src/marshal/inaccessible-val.js +15 -0
- package/src/marshal/pure-data.d.ts +8 -0
- package/src/marshal/pure-data.d.ts.map +1 -0
- package/src/marshal/pure-data.js +14 -0
- package/src/marshal/wrap-marshaller.d.ts +33 -0
- package/src/marshal/wrap-marshaller.d.ts.map +1 -0
- package/src/marshal/wrap-marshaller.js +439 -0
- package/src/natural-sort.d.ts.map +1 -1
- package/src/natural-sort.js +47 -12
- package/src/node/buffer-line-transform.d.ts +10 -5
- package/src/node/buffer-line-transform.d.ts.map +1 -1
- package/src/node/buffer-line-transform.js +8 -4
- package/src/node/fs-stream.d.ts +4 -1
- package/src/node/fs-stream.d.ts.map +1 -1
- package/src/node/fs-stream.js +8 -6
- package/src/node/shutdown.d.ts.map +1 -1
- package/src/node/shutdown.js +2 -0
- package/src/priority-senders.d.ts +2 -1
- package/src/priority-senders.d.ts.map +1 -1
- package/src/priority-senders.js +6 -4
- package/src/ses-utils.d.ts +15 -4
- package/src/ses-utils.d.ts.map +1 -1
- package/src/ses-utils.js +112 -14
- package/src/storage-test-utils.d.ts +13 -3
- package/src/storage-test-utils.d.ts.map +1 -1
- package/src/storage-test-utils.js +61 -7
- package/src/typeGuards.d.ts +6 -2
- package/src/typeGuards.d.ts.map +1 -1
- package/src/typeGuards.js +5 -1
- package/src/types.d.ts +18 -17
- package/src/types.d.ts.map +1 -1
- package/src/types.ts +22 -18
- package/src/work-pool.d.ts +13 -0
- package/src/work-pool.d.ts.map +1 -0
- package/src/work-pool.js +233 -0
- package/src/marshal.d.ts +0 -33
- package/src/marshal.d.ts.map +0 -1
|
@@ -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"}
|
package/src/work-pool.js
ADDED
|
@@ -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,33 +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): Omit<import("@endo/marshal").Marshal<string | null>, "serialize" | "unserialize">;
|
|
7
|
-
/**
|
|
8
|
-
* @type {TypedPattern<CapData<any>>}
|
|
9
|
-
*/
|
|
10
|
-
export const CapDataShape: TypedPattern<CapData<any>>;
|
|
11
|
-
export function assertCapData(data: unknown): asserts data is CapData<unknown>;
|
|
12
|
-
export function unmarshalFromVstorage(data: Map<string, string>, key: string, fromCapData: ReturnType<typeof import("@endo/marshal").makeMarshal>["fromCapData"], index: number): any;
|
|
13
|
-
export function makeHistoryReviver(entries: [string, string][], slotToVal?: (slot: string, iface?: string) => any): {
|
|
14
|
-
getItem: (key: string) => any;
|
|
15
|
-
children: (prefix: string) => string[];
|
|
16
|
-
has: (k: string) => boolean;
|
|
17
|
-
};
|
|
18
|
-
export const pureDataMarshaller: {
|
|
19
|
-
toCapData: import("@endo/marshal").ToCapData<CapData<unknown>>;
|
|
20
|
-
fromCapData: import("@endo/marshal").FromCapData<CapData<unknown>>;
|
|
21
|
-
serialize: import("@endo/marshal").ToCapData<CapData<unknown>>;
|
|
22
|
-
unserialize: import("@endo/marshal").FromCapData<CapData<unknown>>;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Should be a union with Remotable, but that's `any`, making this type
|
|
26
|
-
* meaningless
|
|
27
|
-
*/
|
|
28
|
-
export type BoardRemote = {
|
|
29
|
-
getBoardId: () => string | null;
|
|
30
|
-
};
|
|
31
|
-
import type { CapData } from '@endo/marshal';
|
|
32
|
-
import type { TypedPattern } from './types.js';
|
|
33
|
-
//# sourceMappingURL=marshal.d.ts.map
|
package/src/marshal.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"marshal.d.ts","sourceRoot":"","sources":["marshal.js"],"names":[],"mappings":"AAuBO,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,oDANI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,GAAG,GAClC,IAAI,CAChB,OAAW,eAAe,EAAE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,EAClD,WAAe,GAAG,aAAa,CAC5B,CAMH;AAGD;;GAEG;AACH,2BAFU,aAAa,QAAQ,GAAG,CAAC,CAAC,CAE+B;AAS5D,oCAHI,OAAO,GACL,QAAQ,IAAI,IAAI,QAAQ,OAAO,CAAC,CAO5C;AAeM,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,cAClB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,GAAG;mBAQlC,MAAM;uBAEN,MAAM;aAYN,MAAM;EAInB;AAID;;;;;EAEG;;;;;0BA1IU;IAAE,UAAU,EAAE,MAAM,MAAM,GAAG,IAAI,CAAA;CAAE;6BARtB,eAAe;kCACV,YAAY"}
|