@aztec/foundation 5.2.0-nightly.20260813 → 5.2.0-nightly.20260814
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/dest/iterable/first.d.ts +8 -0
- package/dest/iterable/first.d.ts.map +1 -0
- package/dest/iterable/first.js +11 -0
- package/dest/iterable/index.d.ts +2 -1
- package/dest/iterable/index.d.ts.map +1 -1
- package/dest/iterable/index.js +1 -0
- package/dest/promise/utils.d.ts +14 -1
- package/dest/promise/utils.d.ts.map +1 -1
- package/dest/promise/utils.js +20 -0
- package/package.json +2 -2
- package/src/iterable/first.ts +14 -0
- package/src/iterable/index.ts +1 -0
- package/src/promise/utils.ts +31 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the first entry of an iterable, or undefined if it yields none, closing the underlying
|
|
3
|
+
* iterator either way. Use this instead of calling `.next()` once and abandoning the iterator:
|
|
4
|
+
* an abandoned generator never runs its finally blocks, so any resource it holds is leaked — e.g.
|
|
5
|
+
* a kv-store iterator's LMDB cursor, where enough leaks deadlock the store.
|
|
6
|
+
*/
|
|
7
|
+
export declare function first<T>(iterator: Iterable<T> | AsyncIterableIterator<T> | AsyncIterable<T> | IterableIterator<T>): Promise<T | undefined>;
|
|
8
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmlyc3QuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9pdGVyYWJsZS9maXJzdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7R0FLRztBQUNILHdCQUFzQixLQUFLLENBQUMsQ0FBQyxFQUMzQixRQUFRLEVBQUUsUUFBUSxDQUFDLENBQUMsQ0FBQyxHQUFHLHFCQUFxQixDQUFDLENBQUMsQ0FBQyxHQUFHLGFBQWEsQ0FBQyxDQUFDLENBQUMsR0FBRyxnQkFBZ0IsQ0FBQyxDQUFDLENBQUMsR0FDeEYsT0FBTyxDQUFDLENBQUMsR0FBRyxTQUFTLENBQUMsQ0FLeEIifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"first.d.ts","sourceRoot":"","sources":["../../src/iterable/first.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAsB,KAAK,CAAC,CAAC,EAC3B,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,GACxF,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAKxB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the first entry of an iterable, or undefined if it yields none, closing the underlying
|
|
3
|
+
* iterator either way. Use this instead of calling `.next()` once and abandoning the iterator:
|
|
4
|
+
* an abandoned generator never runs its finally blocks, so any resource it holds is leaked — e.g.
|
|
5
|
+
* a kv-store iterator's LMDB cursor, where enough leaks deadlock the store.
|
|
6
|
+
*/ export async function first(iterator) {
|
|
7
|
+
for await (const i of iterator){
|
|
8
|
+
return i;
|
|
9
|
+
}
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
package/dest/iterable/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from './filter.js';
|
|
|
3
3
|
export * from './sort.js';
|
|
4
4
|
export * from './take.js';
|
|
5
5
|
export * from './all.js';
|
|
6
|
+
export * from './first.js';
|
|
6
7
|
export * from './peek.js';
|
|
7
8
|
export * from './toArray.js';
|
|
8
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9pdGVyYWJsZS9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLFVBQVUsQ0FBQztBQUN6QixjQUFjLGFBQWEsQ0FBQztBQUM1QixjQUFjLFdBQVcsQ0FBQztBQUMxQixjQUFjLFdBQVcsQ0FBQztBQUMxQixjQUFjLFVBQVUsQ0FBQztBQUN6QixjQUFjLFlBQVksQ0FBQztBQUMzQixjQUFjLFdBQVcsQ0FBQztBQUMxQixjQUFjLGNBQWMsQ0FBQyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/iterable/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/iterable/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
|
package/dest/iterable/index.js
CHANGED
package/dest/promise/utils.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Like `Promise.all`, but runs every promise to completion before resolving or rejecting.
|
|
3
|
+
*
|
|
4
|
+
* `Promise.all` rejects as soon as one input rejects, abandoning the still-running siblings. When those siblings have
|
|
5
|
+
* side effects, the caller observes the rejection and reacts to the failure while the abandoned work is still
|
|
6
|
+
* producing effects. This helper instead guarantees that by the time it rejects, no input is still running.
|
|
7
|
+
*
|
|
8
|
+
* The signature mirrors `Promise.all`'s declaration in TypeScript's standard library, so call sites type exactly as
|
|
9
|
+
* they did with `Promise.all` (in particular, heterogeneous tuples keep their per-position types).
|
|
10
|
+
*/
|
|
11
|
+
export declare function allToCompletion<T extends readonly unknown[] | []>(promises: T): Promise<{
|
|
12
|
+
-readonly [P in keyof T]: Awaited<T[P]>;
|
|
13
|
+
}>;
|
|
1
14
|
export type PromiseWithResolvers<T> = {
|
|
2
15
|
promise: Promise<T>;
|
|
3
16
|
resolve: (value: T) => void;
|
|
@@ -9,4 +22,4 @@ export type PromiseWithResolvers<T> = {
|
|
|
9
22
|
* @returns A promise with resolvers.
|
|
10
23
|
*/
|
|
11
24
|
export declare function promiseWithResolvers<T>(): PromiseWithResolvers<T>;
|
|
12
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
25
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wcm9taXNlL3V0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7Ozs7R0FTRztBQUNILHdCQUFzQixlQUFlLENBQUMsQ0FBQyxTQUFTLFNBQVMsT0FBTyxFQUFFLEdBQUcsRUFBRSxFQUNyRSxRQUFRLEVBQUUsQ0FBQyxHQUNWLE9BQU8sQ0FBQztJQUFFLENBQUMsVUFBVSxDQUFDLElBQUksTUFBTSxDQUFDLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQztDQUFFLENBQUMsQ0FpQnREO0FBRUQsTUFBTSxNQUFNLG9CQUFvQixDQUFDLENBQUMsSUFBSTtJQUNwQyxPQUFPLEVBQUUsT0FBTyxDQUFDLENBQUMsQ0FBQyxDQUFDO0lBQ3BCLE9BQU8sRUFBRSxDQUFDLEtBQUssRUFBRSxDQUFDLEtBQUssSUFBSSxDQUFDO0lBQzVCLE1BQU0sRUFBRSxDQUFDLE1BQU0sQ0FBQyxFQUFFLEdBQUcsS0FBSyxJQUFJLENBQUM7Q0FDaEMsQ0FBQztBQUVGOzs7O0dBSUc7QUFDSCx3QkFBZ0Isb0JBQW9CLENBQUMsQ0FBQyxLQUFLLG9CQUFvQixDQUFDLENBQUMsQ0FBQyxDQWlCakUifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/promise/utils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI;IACpC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;CAChC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,KAAK,oBAAoB,CAAC,CAAC,CAAC,CAiBjE"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/promise/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,GAAG,EAAE,EACrE,QAAQ,EAAE,CAAC,GACV,OAAO,CAAC;IAAE,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,CAiBtD;AAED,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI;IACpC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;CAChC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,KAAK,oBAAoB,CAAC,CAAC,CAAC,CAiBjE"}
|
package/dest/promise/utils.js
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Like `Promise.all`, but runs every promise to completion before resolving or rejecting.
|
|
3
|
+
*
|
|
4
|
+
* `Promise.all` rejects as soon as one input rejects, abandoning the still-running siblings. When those siblings have
|
|
5
|
+
* side effects, the caller observes the rejection and reacts to the failure while the abandoned work is still
|
|
6
|
+
* producing effects. This helper instead guarantees that by the time it rejects, no input is still running.
|
|
7
|
+
*
|
|
8
|
+
* The signature mirrors `Promise.all`'s declaration in TypeScript's standard library, so call sites type exactly as
|
|
9
|
+
* they did with `Promise.all` (in particular, heterogeneous tuples keep their per-position types).
|
|
10
|
+
*/ export async function allToCompletion(promises) {
|
|
11
|
+
const results = await Promise.allSettled(promises);
|
|
12
|
+
const failures = results.filter((result)=>result.status === 'rejected');
|
|
13
|
+
if (failures.length === 1) {
|
|
14
|
+
// Rethrow a lone failure as-is so error identity is preserved for callers that inspect error types.
|
|
15
|
+
throw failures[0].reason;
|
|
16
|
+
} else if (failures.length > 1) {
|
|
17
|
+
throw new AggregateError(failures.map((failure)=>failure.reason), `${failures.length} of ${results.length} concurrent operations failed: ${failures.map((failure)=>failure.reason instanceof Error ? failure.reason.message : String(failure.reason)).join(' | ')}`);
|
|
18
|
+
}
|
|
19
|
+
return results.map((result)=>result.value);
|
|
20
|
+
}
|
|
1
21
|
/**
|
|
2
22
|
* A polyfill for the Promise.withResolvers proposed API.
|
|
3
23
|
* @see https://github.com/tc39/proposal-promise-with-resolvers
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/foundation",
|
|
3
|
-
"version": "5.2.0-nightly.
|
|
3
|
+
"version": "5.2.0-nightly.20260814",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dest/index.js",
|
|
6
6
|
"types": "./dest/index.d.ts",
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
"testEnvironment": "../../foundation/src/jest/env.mjs"
|
|
147
147
|
},
|
|
148
148
|
"dependencies": {
|
|
149
|
-
"@aztec/bb.js": "5.2.0-nightly.
|
|
149
|
+
"@aztec/bb.js": "5.2.0-nightly.20260814",
|
|
150
150
|
"@koa/cors": "^5.0.0",
|
|
151
151
|
"@noble/curves": "=1.7.0",
|
|
152
152
|
"@noble/hashes": "^1.6.1",
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the first entry of an iterable, or undefined if it yields none, closing the underlying
|
|
3
|
+
* iterator either way. Use this instead of calling `.next()` once and abandoning the iterator:
|
|
4
|
+
* an abandoned generator never runs its finally blocks, so any resource it holds is leaked — e.g.
|
|
5
|
+
* a kv-store iterator's LMDB cursor, where enough leaks deadlock the store.
|
|
6
|
+
*/
|
|
7
|
+
export async function first<T>(
|
|
8
|
+
iterator: Iterable<T> | AsyncIterableIterator<T> | AsyncIterable<T> | IterableIterator<T>,
|
|
9
|
+
): Promise<T | undefined> {
|
|
10
|
+
for await (const i of iterator) {
|
|
11
|
+
return i;
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
package/src/iterable/index.ts
CHANGED
package/src/promise/utils.ts
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Like `Promise.all`, but runs every promise to completion before resolving or rejecting.
|
|
3
|
+
*
|
|
4
|
+
* `Promise.all` rejects as soon as one input rejects, abandoning the still-running siblings. When those siblings have
|
|
5
|
+
* side effects, the caller observes the rejection and reacts to the failure while the abandoned work is still
|
|
6
|
+
* producing effects. This helper instead guarantees that by the time it rejects, no input is still running.
|
|
7
|
+
*
|
|
8
|
+
* The signature mirrors `Promise.all`'s declaration in TypeScript's standard library, so call sites type exactly as
|
|
9
|
+
* they did with `Promise.all` (in particular, heterogeneous tuples keep their per-position types).
|
|
10
|
+
*/
|
|
11
|
+
export async function allToCompletion<T extends readonly unknown[] | []>(
|
|
12
|
+
promises: T,
|
|
13
|
+
): Promise<{ -readonly [P in keyof T]: Awaited<T[P]> }> {
|
|
14
|
+
const results = await Promise.allSettled<unknown>(promises);
|
|
15
|
+
const failures = results.filter((result): result is PromiseRejectedResult => result.status === 'rejected');
|
|
16
|
+
if (failures.length === 1) {
|
|
17
|
+
// Rethrow a lone failure as-is so error identity is preserved for callers that inspect error types.
|
|
18
|
+
throw failures[0].reason;
|
|
19
|
+
} else if (failures.length > 1) {
|
|
20
|
+
throw new AggregateError(
|
|
21
|
+
failures.map(failure => failure.reason),
|
|
22
|
+
`${failures.length} of ${results.length} concurrent operations failed: ${failures
|
|
23
|
+
.map(failure => (failure.reason instanceof Error ? failure.reason.message : String(failure.reason)))
|
|
24
|
+
.join(' | ')}`,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return results.map(result => (result as PromiseFulfilledResult<unknown>).value) as {
|
|
28
|
+
-readonly [P in keyof T]: Awaited<T[P]>;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
1
32
|
export type PromiseWithResolvers<T> = {
|
|
2
33
|
promise: Promise<T>;
|
|
3
34
|
resolve: (value: T) => void;
|