@agoric/internal 0.3.3-other-dev-8f8782b.0 → 0.3.3-other-dev-fbe72e7.0.fbe72e7
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 +7 -2
- package/exported.js +2 -0
- package/package.json +41 -19
- package/src/action-types.d.ts +51 -5
- package/src/action-types.d.ts.map +1 -1
- package/src/action-types.js +74 -15
- package/src/batched-deliver.d.ts +9 -6
- package/src/batched-deliver.d.ts.map +1 -1
- package/src/batched-deliver.js +9 -3
- package/src/callback.d.ts +24 -17
- package/src/callback.d.ts.map +1 -1
- package/src/callback.js +55 -61
- package/src/chain-storage-paths.d.ts +2 -3
- package/src/chain-storage-paths.d.ts.map +1 -1
- package/src/chain-storage-paths.js +2 -3
- package/src/chain-utils.d.ts +27 -0
- package/src/chain-utils.d.ts.map +1 -0
- package/src/chain-utils.js +62 -0
- package/src/cli-utils.d.ts +2 -0
- package/src/cli-utils.d.ts.map +1 -0
- package/src/cli-utils.js +21 -0
- package/src/config.d.ts +22 -12
- package/src/config.d.ts.map +1 -1
- package/src/config.js +23 -10
- package/src/debug.d.ts +1 -1
- package/src/errors.d.ts +2 -0
- package/src/errors.d.ts.map +1 -0
- package/src/errors.js +16 -0
- package/src/hex.d.ts +15 -0
- package/src/hex.d.ts.map +1 -0
- package/src/hex.js +105 -0
- package/src/index.d.ts +10 -1
- package/src/index.js +13 -2
- package/src/install-ses-debug.d.ts +2 -0
- package/src/install-ses-debug.d.ts.map +1 -0
- package/src/install-ses-debug.js +6 -0
- package/src/js-utils.d.ts +40 -0
- package/src/js-utils.d.ts.map +1 -0
- package/src/js-utils.js +237 -0
- package/src/lib-chainStorage.d.ts +59 -67
- package/src/lib-chainStorage.d.ts.map +1 -1
- package/src/lib-chainStorage.js +95 -92
- package/src/lib-nodejs/ava-unhandled-rejection.d.ts +13 -0
- package/src/lib-nodejs/ava-unhandled-rejection.d.ts.map +1 -0
- package/src/lib-nodejs/ava-unhandled-rejection.js +66 -0
- package/src/lib-nodejs/engine-gc.d.ts +3 -0
- package/src/lib-nodejs/engine-gc.d.ts.map +1 -0
- package/src/lib-nodejs/engine-gc.js +22 -0
- package/src/lib-nodejs/gc-and-finalize.d.ts +2 -0
- package/src/lib-nodejs/gc-and-finalize.d.ts.map +1 -0
- package/src/lib-nodejs/gc-and-finalize.js +91 -0
- package/src/lib-nodejs/spawnSubprocessWorker.d.ts +15 -0
- package/src/lib-nodejs/spawnSubprocessWorker.d.ts.map +1 -0
- package/src/lib-nodejs/spawnSubprocessWorker.js +89 -0
- package/src/lib-nodejs/waitUntilQuiescent.d.ts +2 -0
- package/src/lib-nodejs/waitUntilQuiescent.d.ts.map +1 -0
- package/src/lib-nodejs/waitUntilQuiescent.js +18 -0
- package/src/lib-nodejs/worker-protocol.d.ts +4 -0
- package/src/lib-nodejs/worker-protocol.d.ts.map +1 -0
- package/src/lib-nodejs/worker-protocol.js +54 -0
- package/src/magic-cookie-test-only.js +2 -2
- package/src/marshal.d.ts +33 -0
- package/src/marshal.d.ts.map +1 -0
- package/src/marshal.js +156 -0
- package/src/method-tools.d.ts +1 -0
- package/src/method-tools.d.ts.map +1 -1
- package/src/method-tools.js +33 -62
- package/src/metrics.d.ts +183 -0
- package/src/metrics.d.ts.map +1 -0
- package/src/metrics.js +476 -0
- package/src/module-utils.d.ts +2 -0
- package/src/module-utils.d.ts.map +1 -0
- package/src/module-utils.js +27 -0
- package/src/natural-sort.d.ts +2 -0
- package/src/natural-sort.d.ts.map +1 -0
- package/src/natural-sort.js +48 -0
- package/src/netstring.d.ts +24 -0
- package/src/netstring.d.ts.map +1 -0
- package/src/netstring.js +125 -0
- package/src/node/buffer-line-transform.d.ts +20 -16
- package/src/node/buffer-line-transform.d.ts.map +1 -1
- package/src/node/buffer-line-transform.js +12 -9
- package/src/node/createBundles.d.ts.map +1 -1
- package/src/node/createBundles.js +12 -3
- package/src/node/fs-stream.d.ts +1 -1
- package/src/node/fs-stream.d.ts.map +1 -1
- package/src/node/fs-stream.js +48 -37
- package/src/node/shutdown.d.ts.map +1 -1
- package/src/node/shutdown.js +0 -1
- package/src/priority-senders.d.ts +2 -1
- package/src/priority-senders.d.ts.map +1 -1
- package/src/priority-senders.js +10 -4
- package/src/queue.d.ts +1 -1
- package/src/queue.d.ts.map +1 -1
- package/src/queue.js +7 -8
- package/src/scratch.d.ts +1 -1
- package/src/scratch.d.ts.map +1 -1
- package/src/ses-utils.d.ts +68 -0
- package/src/ses-utils.d.ts.map +1 -0
- package/src/ses-utils.js +422 -0
- package/src/storage-test-utils.d.ts +49 -84
- package/src/storage-test-utils.d.ts.map +1 -1
- package/src/storage-test-utils.js +234 -116
- package/src/tagged.d.ts +152 -0
- package/src/testing-utils.d.ts +2 -0
- package/src/testing-utils.d.ts.map +1 -1
- package/src/testing-utils.js +44 -5
- package/src/tmpDir.d.ts +2 -0
- package/src/tmpDir.d.ts.map +1 -0
- package/src/tmpDir.js +17 -0
- package/src/tokens.d.ts +34 -0
- package/src/tokens.d.ts.map +1 -0
- package/src/tokens.js +35 -0
- package/src/typeCheck.d.ts +9 -0
- package/src/typeCheck.d.ts.map +1 -0
- package/src/typeCheck.js +23 -0
- package/src/typeGuards.d.ts +17 -0
- package/src/typeGuards.d.ts.map +1 -1
- package/src/typeGuards.js +20 -0
- package/src/types-index.d.ts +1 -0
- package/src/types-index.js +2 -0
- package/src/types.d.ts +83 -18
- package/src/types.d.ts.map +1 -0
- package/src/types.ts +129 -0
- package/src/upgrade-api.d.ts +14 -4
- package/src/upgrade-api.d.ts.map +1 -1
- package/src/upgrade-api.js +50 -18
- package/CHANGELOG.md +0 -106
- package/src/utils.d.ts +0 -67
- package/src/utils.d.ts.map +0 -1
- package/src/utils.js +0 -451
package/src/ses-utils.js
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// @jessie-check
|
|
3
|
+
/**
|
|
4
|
+
* @file Utility functions that are dependent upon a hardened environment,
|
|
5
|
+
* either directly or indirectly (e.g. by @endo imports).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { objectMap } from '@endo/common/object-map.js';
|
|
9
|
+
import { objectMetaMap } from '@endo/common/object-meta-map.js';
|
|
10
|
+
import { fromUniqueEntries } from '@endo/common/from-unique-entries.js';
|
|
11
|
+
import { q, Fail, makeError, annotateError, X } from '@endo/errors';
|
|
12
|
+
import { deeplyFulfilled, isPrimitive } from '@endo/pass-style';
|
|
13
|
+
import { makePromiseKit } from '@endo/promise-kit';
|
|
14
|
+
import { makeQueue } from '@endo/stream';
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
16
|
+
// @ts-ignore TS7016 The 'jessie.js' library may need to update its package.json or typings
|
|
17
|
+
import { asyncGenerate } from 'jessie.js';
|
|
18
|
+
import { logLevels } from './js-utils.js';
|
|
19
|
+
|
|
20
|
+
/** @import {LimitedConsole} from './js-utils.js'; */
|
|
21
|
+
|
|
22
|
+
/** @import {ERef} from '@endo/far'; */
|
|
23
|
+
/** @import {Primitive} from '@endo/pass-style'; */
|
|
24
|
+
/** @import {Permit, Attenuated} from './types.js'; */
|
|
25
|
+
|
|
26
|
+
export { objectMap, objectMetaMap, fromUniqueEntries };
|
|
27
|
+
|
|
28
|
+
const { fromEntries, keys, values } = Object;
|
|
29
|
+
|
|
30
|
+
/** @param {(level: string) => (...args: unknown[]) => void} makeLogger */
|
|
31
|
+
export const makeLimitedConsole = makeLogger => {
|
|
32
|
+
const limitedConsole = /** @type {any} */ (
|
|
33
|
+
fromEntries(logLevels.map(level => [level, makeLogger(level)]))
|
|
34
|
+
);
|
|
35
|
+
return /** @type {LimitedConsole} */ (harden(limitedConsole));
|
|
36
|
+
};
|
|
37
|
+
harden(makeLimitedConsole);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @template T
|
|
41
|
+
* @typedef {{ [KeyType in keyof T]: T[KeyType] } & {}} Simplify flatten the
|
|
42
|
+
* type output to improve type hints shown in editors
|
|
43
|
+
* https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @typedef {(...args: any[]) => any} Callable
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @template {{}} T
|
|
52
|
+
* @typedef {{
|
|
53
|
+
* [K in keyof T]: T[K] extends Callable ? T[K] : DeeplyAwaited<T[K]>;
|
|
54
|
+
* }} DeeplyAwaitedObject
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @template T
|
|
59
|
+
* @typedef {T extends PromiseLike<any>
|
|
60
|
+
* ? Awaited<T>
|
|
61
|
+
* : T extends {}
|
|
62
|
+
* ? Simplify<DeeplyAwaitedObject<T>>
|
|
63
|
+
* : Awaited<T>} DeeplyAwaited
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A more constrained version of {deeplyFulfilled} for type safety until
|
|
68
|
+
* https://github.com/endojs/endo/issues/1257 Useful in starting contracts that
|
|
69
|
+
* need all terms to be fulfilled in order to be durable.
|
|
70
|
+
*
|
|
71
|
+
* @type {<T extends {}>(unfulfilledTerms: T) => Promise<DeeplyAwaited<T>>}
|
|
72
|
+
*/
|
|
73
|
+
export const deeplyFulfilledObject = async obj => {
|
|
74
|
+
!isPrimitive(obj) || Fail`param must be an object`;
|
|
75
|
+
return deeplyFulfilled(obj);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Tolerate absence of AggregateError in e.g. xsnap.
|
|
80
|
+
*
|
|
81
|
+
* @type {(errors: Error[], message?: string, options?: object) => Error}
|
|
82
|
+
*/
|
|
83
|
+
const makeAggregateError =
|
|
84
|
+
typeof AggregateError === 'function'
|
|
85
|
+
? (errors, message, options) => AggregateError(errors, message, options)
|
|
86
|
+
: (errors, message, options) => {
|
|
87
|
+
return makeError(message ?? 'multiple errors', undefined, {
|
|
88
|
+
...options,
|
|
89
|
+
errors,
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @template T
|
|
95
|
+
* @param {readonly (T | PromiseLike<T>)[]} items
|
|
96
|
+
* @returns {Promise<T[]>}
|
|
97
|
+
*/
|
|
98
|
+
export const PromiseAllOrErrors = async items => {
|
|
99
|
+
return Promise.allSettled(items).then(results => {
|
|
100
|
+
const errors = /** @type {PromiseRejectedResult[]} */ (
|
|
101
|
+
results.filter(({ status }) => status === 'rejected')
|
|
102
|
+
).map(result => result.reason);
|
|
103
|
+
if (!errors.length) {
|
|
104
|
+
return /** @type {PromiseFulfilledResult<T>[]} */ (results).map(
|
|
105
|
+
result => result.value,
|
|
106
|
+
);
|
|
107
|
+
} else if (errors.length === 1) {
|
|
108
|
+
throw errors[0];
|
|
109
|
+
} else {
|
|
110
|
+
throw makeAggregateError(errors);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @template T
|
|
117
|
+
* @param {() => Promise<T>} trier
|
|
118
|
+
* @param {(error?: unknown) => Promise<unknown>} finalizer
|
|
119
|
+
* @returns {ReturnType<trier>}
|
|
120
|
+
*/
|
|
121
|
+
export const aggregateTryFinally = async (trier, finalizer) =>
|
|
122
|
+
trier().then(
|
|
123
|
+
async result => finalizer().then(() => result),
|
|
124
|
+
async tryError =>
|
|
125
|
+
finalizer(tryError)
|
|
126
|
+
.then(
|
|
127
|
+
() => tryError,
|
|
128
|
+
finalizeError => makeAggregateError([tryError, finalizeError]),
|
|
129
|
+
)
|
|
130
|
+
.then(error => Promise.reject(error)),
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Run a function with the ability to defer last-in-first-out cleanup callbacks.
|
|
135
|
+
*
|
|
136
|
+
* @template T
|
|
137
|
+
* @param {(
|
|
138
|
+
* addCleanup: (fn: (err?: unknown) => Promise<void>) => void,
|
|
139
|
+
* ) => Promise<T>} fn
|
|
140
|
+
* @returns {ReturnType<fn>}
|
|
141
|
+
*/
|
|
142
|
+
export const withDeferredCleanup = async fn => {
|
|
143
|
+
/** @type {((err?: unknown) => unknown)[]} */
|
|
144
|
+
const cleanupsLIFO = [];
|
|
145
|
+
/** @type {(cleanup: (err?: unknown) => unknown) => void} */
|
|
146
|
+
const addCleanup = cleanup => {
|
|
147
|
+
cleanupsLIFO.unshift(cleanup);
|
|
148
|
+
};
|
|
149
|
+
/** @type {(err?: unknown) => Promise<void>} */
|
|
150
|
+
const finalizer = async err => {
|
|
151
|
+
// Run each cleanup in its own isolated stack.
|
|
152
|
+
const cleanupResults = cleanupsLIFO.map(async cleanup => {
|
|
153
|
+
await null;
|
|
154
|
+
return cleanup(err);
|
|
155
|
+
});
|
|
156
|
+
await PromiseAllOrErrors(cleanupResults);
|
|
157
|
+
};
|
|
158
|
+
return aggregateTryFinally(() => fn(addCleanup), finalizer);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @template {Record<string, unknown>} T
|
|
163
|
+
* @typedef {{ [P in keyof T]: Exclude<T[P], undefined> }} AllDefined
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Concise way to check values are available from object literal shorthand.
|
|
168
|
+
* Throws error message to specify the missing values.
|
|
169
|
+
*
|
|
170
|
+
* @template {Record<string, unknown>} T
|
|
171
|
+
* @param {T} obj
|
|
172
|
+
* @returns {asserts obj is AllDefined<T>}
|
|
173
|
+
* @throws if any value in the object entries is not defined
|
|
174
|
+
*/
|
|
175
|
+
export const assertAllDefined = obj => {
|
|
176
|
+
const missing = [];
|
|
177
|
+
for (const [key, val] of Object.entries(obj)) {
|
|
178
|
+
if (val === undefined) {
|
|
179
|
+
missing.push(key);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (missing.length > 0) {
|
|
183
|
+
Fail`missing ${q(missing)}`;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Attenuate `specimen` to only properties allowed by `permit`.
|
|
189
|
+
*
|
|
190
|
+
* @template T
|
|
191
|
+
* @template {Permit<T>} P
|
|
192
|
+
* @param {T} specimen
|
|
193
|
+
* @param {P} permit
|
|
194
|
+
* @param {<U, SubP extends Permit<U>>(attenuation: U, permit: SubP) => U} [transform]
|
|
195
|
+
* used to replace the results of recursive picks (but not blanket permits)
|
|
196
|
+
* @returns {Attenuated<T, P>}
|
|
197
|
+
*/
|
|
198
|
+
export const attenuate = (specimen, permit, transform = x => x) => {
|
|
199
|
+
// Fast-path for no attenuation.
|
|
200
|
+
if (permit === true || typeof permit === 'string') {
|
|
201
|
+
return /** @type {Attenuated<T, P>} */ (specimen);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** @type {string[]} */
|
|
205
|
+
const path = [];
|
|
206
|
+
/**
|
|
207
|
+
* @template SubT
|
|
208
|
+
* @template {Exclude<Permit<SubT>, Primitive>} SubP
|
|
209
|
+
* @type {(specimen: SubT, permit: SubP) => Attenuated<SubT, SubP>}
|
|
210
|
+
*/
|
|
211
|
+
const extract = (subSpecimen, subPermit) => {
|
|
212
|
+
if (subPermit === null || typeof subPermit !== 'object') {
|
|
213
|
+
throw path.length === 0
|
|
214
|
+
? Fail`invalid permit: ${q(permit)}`
|
|
215
|
+
: Fail`invalid permit at path ${q(path)}: ${q(subPermit)}`;
|
|
216
|
+
} else if (subSpecimen === null || typeof subSpecimen !== 'object') {
|
|
217
|
+
throw path.length === 0
|
|
218
|
+
? Fail`specimen must be an object for permit ${q(permit)}`
|
|
219
|
+
: Fail`specimen at path ${q(path)} must be an object for permit ${q(subPermit)}`;
|
|
220
|
+
}
|
|
221
|
+
const picks = Object.entries(subPermit).map(([subKey, deepPermit]) => {
|
|
222
|
+
if (!Object.hasOwn(subSpecimen, subKey)) {
|
|
223
|
+
throw Fail`specimen is missing path ${q(path.concat(subKey))}`;
|
|
224
|
+
}
|
|
225
|
+
const deepSpecimen = Reflect.get(subSpecimen, subKey);
|
|
226
|
+
if (deepPermit === true || typeof deepPermit === 'string') {
|
|
227
|
+
return [subKey, deepSpecimen];
|
|
228
|
+
}
|
|
229
|
+
path.push(subKey);
|
|
230
|
+
const extracted = extract(/** @type {any} */ (deepSpecimen), deepPermit);
|
|
231
|
+
const entry = [subKey, extracted];
|
|
232
|
+
path.pop();
|
|
233
|
+
return entry;
|
|
234
|
+
});
|
|
235
|
+
return transform(Object.fromEntries(picks), subPermit);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// @ts-expect-error cast
|
|
239
|
+
return extract(specimen, permit);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
/** @type {IteratorResult<undefined, never>} */
|
|
243
|
+
const notDone = harden({ done: false, value: undefined });
|
|
244
|
+
|
|
245
|
+
/** @type {IteratorResult<never, void>} */
|
|
246
|
+
const alwaysDone = harden({ done: true, value: undefined });
|
|
247
|
+
|
|
248
|
+
export const forever = asyncGenerate(() => notDone);
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* @template T
|
|
252
|
+
* @param {() => T} produce The value of `await produce()` is used for its
|
|
253
|
+
* truthiness vs falsiness. IOW, it is coerced to a boolean so the caller need
|
|
254
|
+
* not bother doing this themselves.
|
|
255
|
+
* @returns {AsyncIterable<Awaited<T>>}
|
|
256
|
+
*/
|
|
257
|
+
export const whileTrue = produce =>
|
|
258
|
+
asyncGenerate(async () => {
|
|
259
|
+
const value = await produce();
|
|
260
|
+
if (!value) {
|
|
261
|
+
return alwaysDone;
|
|
262
|
+
}
|
|
263
|
+
return harden({
|
|
264
|
+
done: false,
|
|
265
|
+
value,
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @template T
|
|
271
|
+
* @param {() => T} produce The value of `await produce()` is used for its
|
|
272
|
+
* truthiness vs falsiness. IOW, it is coerced to a boolean so the caller need
|
|
273
|
+
* not bother doing this themselves.
|
|
274
|
+
* @returns {AsyncIterable<Awaited<T>>}
|
|
275
|
+
*/
|
|
276
|
+
export const untilTrue = produce =>
|
|
277
|
+
asyncGenerate(async () => {
|
|
278
|
+
const value = await produce();
|
|
279
|
+
if (value) {
|
|
280
|
+
return harden({
|
|
281
|
+
done: true,
|
|
282
|
+
value,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
return harden({
|
|
286
|
+
done: false,
|
|
287
|
+
value,
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
/** @type {<X, Y>(xs: X[], ys: Y[]) => [X, Y][]} */
|
|
292
|
+
export const zip = (xs, ys) => harden(xs.map((x, i) => [x, ys[+i]]));
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* @type {<T extends Record<string, ERef<any>>>(
|
|
296
|
+
* obj: T,
|
|
297
|
+
* ) => Promise<{ [K in keyof T]: Awaited<T[K]> }>}
|
|
298
|
+
*/
|
|
299
|
+
export const allValues = async obj => {
|
|
300
|
+
const resolved = await Promise.all(values(obj));
|
|
301
|
+
// @ts-expect-error cast
|
|
302
|
+
return harden(fromEntries(zip(keys(obj), resolved)));
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* A tee implementation where all readers are synchronized with each other. They
|
|
307
|
+
* all consume the source stream in lockstep, and any one returning or throwing
|
|
308
|
+
* early will affect the others.
|
|
309
|
+
*
|
|
310
|
+
* @template [T=unknown]
|
|
311
|
+
* @param {AsyncIterator<T, void, void>} sourceStream
|
|
312
|
+
* @param {number} readerCount
|
|
313
|
+
*/
|
|
314
|
+
export const synchronizedTee = (sourceStream, readerCount) => {
|
|
315
|
+
/** @type {IteratorReturnResult<void> | undefined} */
|
|
316
|
+
let doneResult;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* @typedef {IteratorResult<
|
|
320
|
+
* (value: PromiseLike<IteratorResult<T>>) => void
|
|
321
|
+
* >} QueuePayload
|
|
322
|
+
*/
|
|
323
|
+
/** @type {import('@endo/stream').AsyncQueue<QueuePayload>[]} */
|
|
324
|
+
const queues = [];
|
|
325
|
+
|
|
326
|
+
/** @returns {Promise<void>} */
|
|
327
|
+
const pullNext = async () => {
|
|
328
|
+
const requests = await Promise.allSettled(queues.map(queue => queue.get()));
|
|
329
|
+
const rejections = [];
|
|
330
|
+
/** @type {Array<(value: PromiseLike<IteratorResult<T>>) => void>} */
|
|
331
|
+
const resolvers = [];
|
|
332
|
+
let done = false;
|
|
333
|
+
for (const settledResult of requests) {
|
|
334
|
+
if (settledResult.status === 'rejected') {
|
|
335
|
+
rejections.push(settledResult.reason);
|
|
336
|
+
} else {
|
|
337
|
+
done ||= !!settledResult.value.done;
|
|
338
|
+
resolvers.push(settledResult.value.value);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
/** @type {Promise<IteratorResult<T>>} */
|
|
342
|
+
let result;
|
|
343
|
+
if (doneResult) {
|
|
344
|
+
result = Promise.resolve(doneResult);
|
|
345
|
+
} else if (rejections.length) {
|
|
346
|
+
const error = makeError(X`Teed stream threw`);
|
|
347
|
+
annotateError(error, X`Teed rejections: ${rejections}`);
|
|
348
|
+
result =
|
|
349
|
+
sourceStream.throw?.(error) ||
|
|
350
|
+
Promise.resolve(sourceStream.return?.()).then(() =>
|
|
351
|
+
Promise.reject(error),
|
|
352
|
+
);
|
|
353
|
+
} else if (done) {
|
|
354
|
+
result =
|
|
355
|
+
sourceStream.return?.() ||
|
|
356
|
+
Promise.resolve({ done: true, value: undefined });
|
|
357
|
+
} else {
|
|
358
|
+
result = sourceStream.next();
|
|
359
|
+
}
|
|
360
|
+
result.then(
|
|
361
|
+
r => {
|
|
362
|
+
if (r.done) {
|
|
363
|
+
doneResult = r;
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
() => {
|
|
367
|
+
doneResult = { done: true, value: undefined };
|
|
368
|
+
},
|
|
369
|
+
);
|
|
370
|
+
for (const resolve of resolvers) {
|
|
371
|
+
resolve(result);
|
|
372
|
+
}
|
|
373
|
+
return pullNext();
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
const readers = Array.from({ length: readerCount }).map(() => {
|
|
377
|
+
/** @type {import('@endo/stream').AsyncQueue<QueuePayload>} */
|
|
378
|
+
const queue = makeQueue();
|
|
379
|
+
queues.push(queue);
|
|
380
|
+
|
|
381
|
+
/** @type {AsyncGenerator<T, void, void>} */
|
|
382
|
+
const reader = harden({
|
|
383
|
+
async next() {
|
|
384
|
+
/**
|
|
385
|
+
* @type {import('@endo/promise-kit').PromiseKit<
|
|
386
|
+
* IteratorResult<T>
|
|
387
|
+
* >}
|
|
388
|
+
*/
|
|
389
|
+
const { promise, resolve } = makePromiseKit();
|
|
390
|
+
queue.put({ value: resolve, done: false });
|
|
391
|
+
return promise;
|
|
392
|
+
},
|
|
393
|
+
async return() {
|
|
394
|
+
/**
|
|
395
|
+
* @type {import('@endo/promise-kit').PromiseKit<
|
|
396
|
+
* IteratorResult<T>
|
|
397
|
+
* >}
|
|
398
|
+
*/
|
|
399
|
+
const { promise, resolve } = makePromiseKit();
|
|
400
|
+
queue.put({ value: resolve, done: true });
|
|
401
|
+
return promise;
|
|
402
|
+
},
|
|
403
|
+
async throw(reason) {
|
|
404
|
+
const rejection = Promise.reject(reason);
|
|
405
|
+
queue.put(rejection);
|
|
406
|
+
return rejection;
|
|
407
|
+
},
|
|
408
|
+
// eslint-disable-next-line no-restricted-globals
|
|
409
|
+
[Symbol.asyncIterator]() {
|
|
410
|
+
return reader;
|
|
411
|
+
},
|
|
412
|
+
// eslint-disable-next-line no-restricted-globals
|
|
413
|
+
async [Symbol.asyncDispose]() {
|
|
414
|
+
await reader.return();
|
|
415
|
+
},
|
|
416
|
+
});
|
|
417
|
+
return reader;
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
void pullNext();
|
|
421
|
+
return readers;
|
|
422
|
+
};
|
|
@@ -1,101 +1,66 @@
|
|
|
1
|
-
export function slotToRemotable(_slotId: string, iface?: string): import("@endo/eventual-send").RemotableBrand<{}, {}>;
|
|
1
|
+
export function slotToRemotable(_slotId: string, iface?: string): import("@endo/pass-style").RemotableObject<string> & import("@endo/eventual-send").RemotableBrand<{}, {}>;
|
|
2
2
|
/**
|
|
3
|
-
* A basic marshaller whose unserializer produces Remotables. It can
|
|
4
|
-
*
|
|
3
|
+
* A basic marshaller whose unserializer produces Remotables. It can only
|
|
4
|
+
* serialize plain data, not Remotables.
|
|
5
5
|
*/
|
|
6
6
|
export const defaultMarshaller: {
|
|
7
|
-
toCapData: import("@endo/marshal
|
|
8
|
-
fromCapData: import("@endo/marshal
|
|
9
|
-
serialize: import("@endo/marshal
|
|
10
|
-
unserialize: import("@endo/marshal
|
|
7
|
+
toCapData: import("@endo/marshal").ToCapData<string>;
|
|
8
|
+
fromCapData: import("@endo/marshal").FromCapData<string>;
|
|
9
|
+
serialize: import("@endo/marshal").ToCapData<string>;
|
|
10
|
+
unserialize: import("@endo/marshal").FromCapData<string>;
|
|
11
11
|
};
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
12
|
+
export namespace defaultSerializer {
|
|
13
|
+
let parse: (text: string) => unknown;
|
|
14
|
+
let stringify: (obj: any) => string;
|
|
15
|
+
}
|
|
16
|
+
export const slotStringUnserialize: (capData: any) => any;
|
|
17
|
+
export function makeFakeStorageKit(rootPath: string, rootOptions?: Parameters<typeof makeChainStorageRoot>[2]): {
|
|
18
|
+
rootNode: import("@endo/exo").Guarded<{
|
|
17
19
|
getPath(): string;
|
|
18
|
-
getStoreKey(): Promise<
|
|
20
|
+
getStoreKey(): Promise<VStorageKey>;
|
|
19
21
|
makeChildNode(name: string, childNodeOptions?: {
|
|
20
|
-
sequence?: boolean
|
|
21
|
-
}
|
|
22
|
-
setValue(value: string): Promise<void>;
|
|
23
|
-
} & import("@endo/eventual-send").RemotableBrand<{}, {
|
|
24
|
-
getPath(): string;
|
|
25
|
-
getStoreKey(): Promise<import("./lib-chainStorage.js").VStorageKey>;
|
|
26
|
-
makeChildNode(name: string, childNodeOptions?: {
|
|
27
|
-
sequence?: boolean | undefined;
|
|
28
|
-
} | undefined): import("./lib-chainStorage.js").StorageNode;
|
|
22
|
+
sequence?: boolean;
|
|
23
|
+
}): StorageNode;
|
|
29
24
|
setValue(value: string): Promise<void>;
|
|
30
25
|
}>;
|
|
31
26
|
data: Map<string, string>;
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
updateNewCellBlockHeight: (blockHeight?: number) => void;
|
|
28
|
+
getValues: (path: string) => string[];
|
|
29
|
+
messages: StorageMessage[];
|
|
30
|
+
toStorage: ((message: StorageMessage) => string | number | true | any[] | {
|
|
34
31
|
storeName: string;
|
|
35
32
|
storeSubkey: string;
|
|
36
|
-
} | null |
|
|
33
|
+
} | null) & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, (message: StorageMessage) => string | number | true | any[] | {
|
|
34
|
+
storeName: string;
|
|
35
|
+
storeSubkey: string;
|
|
36
|
+
} | null>;
|
|
37
37
|
};
|
|
38
|
-
export function makeMockChainStorageRoot():
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
getPath(): string;
|
|
53
|
-
getStoreKey(): Promise<import("./lib-chainStorage.js").VStorageKey>;
|
|
54
|
-
makeChildNode(name: string, childNodeOptions?: {
|
|
55
|
-
sequence?: boolean | undefined;
|
|
56
|
-
} | undefined): import("./lib-chainStorage.js").StorageNode;
|
|
57
|
-
setValue(value: string): Promise<void>;
|
|
58
|
-
} & import("@endo/eventual-send").RemotableBrand<{}, {
|
|
38
|
+
export function makeMockChainStorageRoot(): MockChainStorageRoot;
|
|
39
|
+
export function documentStorageSchema(t: import("ava").ExecutionContext<unknown>, storage: MockChainStorageRoot | FakeStorageKit, opts: ({
|
|
40
|
+
note: string;
|
|
41
|
+
} | {
|
|
42
|
+
node: string;
|
|
43
|
+
owner: string;
|
|
44
|
+
}) & ({
|
|
45
|
+
pattern: string;
|
|
46
|
+
replacement: string;
|
|
47
|
+
} | {}) & {
|
|
48
|
+
showValue?: (v: string) => unknown;
|
|
49
|
+
}): Promise<void>;
|
|
50
|
+
export type FakeStorageKit = ReturnType<typeof makeFakeStorageKit>;
|
|
51
|
+
export type MockChainStorageRootMethods = {
|
|
59
52
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* @param {string} path
|
|
66
|
-
* @param {import('./lib-chainStorage.js').Marshaller} marshaller
|
|
67
|
-
* @param {number} [index]
|
|
68
|
-
* @returns {unknown}
|
|
53
|
+
* Defaults to deserializing slot references into plain Remotable objects having
|
|
54
|
+
* the specified interface name (as from `Far(iface)`), but can accept a
|
|
55
|
+
* different marshaller for producing Remotables that e.g. embed the slot
|
|
56
|
+
* string in their iface name.
|
|
69
57
|
*/
|
|
70
|
-
getBody: (path: string, marshaller?:
|
|
58
|
+
getBody: (path: string, marshaller?: Marshaller, index?: number) => unknown;
|
|
71
59
|
keys: () => string[];
|
|
72
|
-
getPath(): string;
|
|
73
|
-
getStoreKey(): Promise<import("./lib-chainStorage.js").VStorageKey>;
|
|
74
|
-
makeChildNode(name: string, childNodeOptions?: {
|
|
75
|
-
sequence?: boolean | undefined;
|
|
76
|
-
} | undefined): import("./lib-chainStorage.js").StorageNode;
|
|
77
|
-
setValue(value: string): Promise<void>;
|
|
78
|
-
}>;
|
|
79
|
-
/**
|
|
80
|
-
* A map corresponding with a total function such that `get(key)`
|
|
81
|
-
* is assumed to always succeed.
|
|
82
|
-
*/
|
|
83
|
-
export type TotalMap<K, V> = {
|
|
84
|
-
[Symbol.iterator]: () => IterableIterator<[K, V]>;
|
|
85
|
-
[Symbol.toStringTag]: string;
|
|
86
|
-
entries: () => IterableIterator<[K, V]>;
|
|
87
|
-
keys: () => IterableIterator<K>;
|
|
88
|
-
values: () => IterableIterator<V>;
|
|
89
|
-
has: (key: K) => boolean;
|
|
90
|
-
size: number;
|
|
91
|
-
set: (key: K, value: V) => Map<K, V>;
|
|
92
|
-
clear: () => void;
|
|
93
|
-
delete: (key: K) => boolean;
|
|
94
|
-
forEach: (callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any) => void;
|
|
95
|
-
} & {
|
|
96
|
-
get: (key: K) => V;
|
|
97
60
|
};
|
|
98
|
-
export type
|
|
99
|
-
|
|
100
|
-
|
|
61
|
+
export type MockChainStorageRoot = StorageNode & MockChainStorageRootMethods;
|
|
62
|
+
import { makeChainStorageRoot } from './lib-chainStorage.js';
|
|
63
|
+
import type { StorageNode } from './lib-chainStorage.js';
|
|
64
|
+
import type { StorageMessage } from './lib-chainStorage.js';
|
|
65
|
+
import type { Marshaller } from './lib-chainStorage.js';
|
|
101
66
|
//# sourceMappingURL=storage-test-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-test-utils.d.ts","sourceRoot":"","sources":["storage-test-utils.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"storage-test-utils.d.ts","sourceRoot":"","sources":["storage-test-utils.js"],"names":[],"mappings":"AAyBO,yCAHI,MAAM,UACN,MAAM,6GAGC;AAElB;;;GAGG;AACH;;;;;EAEG;;eAMU,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO;mBAEzB,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM;;AA8CjC,8CAtBuB,GAAG,KAAK,GAAG,CAsB+B;AAU1D,6CAHI,MAAM,gBACN,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC;;;;;oBAuFhB,CAAC;;;;UAwDjB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;;sBAd3B,MAAM,KACJ,MAAM,EAAE;;0BA9FP,cAAc;;;8IAAd,cAAc;;;;EAiH7B;AAoBM,4CADO,oBAAoB,CA6BjC;AAUM,yCAPI,OAAO,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAAC,WACvC,oBAAoB,GAAG,cAAc,QACrC,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,GAC9D,CAAK;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,EAAE,CAAC,GAAG;IAChD,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;CACpC,iBAkDL;6BAxGa,UAAU,CAAC,OAAO,kBAAkB,CAAC;;;;;;;;aAIrC,CACT,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,UAAU,EACvB,KAAK,CAAC,EAAE,MAAM,KACX,OAAO;UAKD,MAAM,MAAM,EAAE;;mCAEd,WAAW,GAAG,2BAA2B;qCAhQJ,uBAAuB;iCAOU,uBAAuB;oCAAvB,uBAAuB;gCAAvB,uBAAuB"}
|