@agoric/internal 0.4.0-upgrade-16-dev-0df76a7.0 → 0.4.0-upgrade-17-dev-a61cdab.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/internal",
3
- "version": "0.4.0-upgrade-16-dev-0df76a7.0+0df76a7",
3
+ "version": "0.4.0-upgrade-17-dev-a61cdab.0+a61cdab",
4
4
  "description": "Externally unsupported utilities internal to agoric-sdk",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -20,23 +20,24 @@
20
20
  "lint:types": "tsc"
21
21
  },
22
22
  "dependencies": {
23
- "@agoric/assert": "0.6.1-upgrade-16-dev-0df76a7.0+0df76a7",
24
- "@agoric/base-zone": "0.1.1-upgrade-16-dev-0df76a7.0+0df76a7",
25
- "@endo/common": "^1.2.2",
26
- "@endo/far": "^1.1.2",
27
- "@endo/init": "^1.1.2",
28
- "@endo/marshal": "^1.5.0",
29
- "@endo/pass-style": "^1.4.0",
30
- "@endo/patterns": "^1.4.0",
31
- "@endo/promise-kit": "^1.1.2",
32
- "@endo/stream": "^1.2.2",
23
+ "@agoric/base-zone": "0.1.1-upgrade-17-dev-a61cdab.0+a61cdab",
24
+ "@endo/common": "^1.2.5",
25
+ "@endo/errors": "^1.2.5",
26
+ "@endo/far": "^1.1.5",
27
+ "@endo/init": "^1.1.4",
28
+ "@endo/marshal": "^1.5.3",
29
+ "@endo/pass-style": "^1.4.3",
30
+ "@endo/patterns": "^1.4.3",
31
+ "@endo/promise-kit": "^1.1.5",
32
+ "@endo/stream": "^1.2.5",
33
33
  "anylogger": "^0.21.0",
34
34
  "jessie.js": "^0.3.4"
35
35
  },
36
36
  "devDependencies": {
37
- "@endo/init": "^1.1.2",
37
+ "@endo/exo": "^1.5.3",
38
+ "@endo/init": "^1.1.4",
38
39
  "ava": "^5.3.0",
39
- "tsd": "^0.30.7"
40
+ "tsd": "^0.31.1"
40
41
  },
41
42
  "ava": {
42
43
  "require": [
@@ -56,7 +57,7 @@
56
57
  "access": "public"
57
58
  },
58
59
  "typeCoverage": {
59
- "atLeast": 93.89
60
+ "atLeast": 93.32
60
61
  },
61
- "gitHead": "0df76a71058eda04cdc75a54fb4312d286f323a3"
62
+ "gitHead": "a61cdabb23bd2c846e003dee7326018a7462a929"
62
63
  }
package/src/callback.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- export function callSync<I extends (...args: unknown[]) => any>(callback: SyncCallback<I>, ...args: Parameters<I>): ReturnType<I>;
2
- export function callE<I extends (...args: unknown[]) => any>(callback: Callback<I>, ...args: Parameters<I>): Promise<Awaited<ReturnType<I>>>;
3
- export function makeSyncFunctionCallback<I extends (...args: unknown[]) => any, T extends (...args: [...B, ...Parameters<I>]) => ReturnType<I> = I, B extends unknown[] = []>(target: T, ...bound: B): SyncCallback<I>;
4
- export function makeFunctionCallback<I extends (...args: unknown[]) => any, T extends ERef<(...args: [...B, ...Parameters<I>]) => ReturnType<I>> = ERef<I>, B extends unknown[] = []>(target: T, ...bound: B): Callback<I>;
5
- export function makeSyncMethodCallback<I extends (...args: unknown[]) => any, P extends PropertyKey, T extends { [x in P]: (...args: [...B, ...Parameters<I>]) => ReturnType<I>; } = { [x in P]: I; }, B extends unknown[] = []>(target: T, methodName: P, ...bound: B): SyncCallback<I>;
6
- export function makeMethodCallback<I extends (...args: unknown[]) => any, P extends PropertyKey, T extends ERef<{ [x in P]: (...args: [...B, ...Parameters<I>]) => ReturnType<I>; }> = ERef<{ [x in P]: I; }>, B extends unknown[] = []>(target: T, methodName: P, ...bound: B): Callback<I>;
1
+ export function callSync<I extends (...args: any[]) => any>(callback: SyncCallback<I>, ...args: Parameters<I>): ReturnType<I>;
2
+ export function callE<I extends (...args: any[]) => any>(callback: Callback<I>, ...args: Parameters<I>): Promise<Awaited<ReturnType<I>>>;
3
+ export function makeSyncFunctionCallback<I extends (...args: any[]) => any, T extends (...args: [...B, ...Parameters<I>]) => ReturnType<I> = I, B extends any[] = []>(target: T, ...bound: B): SyncCallback<I>;
4
+ export function makeFunctionCallback<I extends (...args: any[]) => any, T extends ERef<(...args: [...B, ...Parameters<I>]) => ReturnType<I>> = ERef<I>, B extends any[] = []>(target: T, ...bound: B): Callback<I>;
5
+ export function makeSyncMethodCallback<I extends (...args: any[]) => any, P extends PropertyKey, T extends { [x in P]: (...args: [...B, ...Parameters<I>]) => ReturnType<I>; } = { [x in P]: I; }, B extends any[] = []>(target: T, methodName: P, ...bound: B): SyncCallback<I>;
6
+ export function makeMethodCallback<I extends (...args: any[]) => any, P extends PropertyKey, T extends ERef<{ [x in P]: (...args: [...B, ...Parameters<I>]) => ReturnType<I>; }> = ERef<{ [x in P]: I; }>, B extends any[] = []>(target: T, methodName: P, ...bound: B): Callback<I>;
7
7
  export function isCallback(callback: any): callback is Callback<any>;
8
8
  export function prepareAttenuator<M extends PropertyKey>(zone: import("@agoric/base-zone").Zone, methodNames: M[], { interfaceGuard, tag }?: {
9
9
  interfaceGuard?: import("@endo/patterns").InterfaceGuard<{ [K in M]: import("@endo/patterns").MethodGuard; }> | undefined;
@@ -12,7 +12,7 @@ export function prepareAttenuator<M extends PropertyKey>(zone: import("@agoric/b
12
12
  target?: any;
13
13
  isSync?: boolean | undefined;
14
14
  overrides?: { [K_1 in M]?: Callback<any> | null | undefined; } | undefined;
15
- }) => import("@endo/exo").Guarded<{ [K_2 in M]: (this: any, ...args: unknown[]) => any; }>;
15
+ }) => import("@endo/exo").Guarded<{ [K_2 in M]: (this: any, ...args: any[]) => any; }>;
16
16
  export function prepareGuardedAttenuator<G extends import("@endo/patterns").InterfaceGuard>(zone: import("@agoric/base-zone").Zone, interfaceGuard: G, opts?: {
17
17
  tag?: string | undefined;
18
18
  } | undefined): MakeAttenuator<any>;
@@ -23,7 +23,7 @@ export type MakeAttenuator<T extends import("@endo/exo").Methods> = (...args: Pa
23
23
  target?: any;
24
24
  isSync?: boolean | undefined;
25
25
  overrides?: { [K_1 in M]?: Callback<any> | null | undefined; } | undefined;
26
- }) => import("@endo/exo").Guarded<{ [K_2 in M]: (this: any, ...args: unknown[]) => any; }>)>>) => import("@endo/exo").Farable<T>;
26
+ }) => import("@endo/exo").Guarded<{ [K_2 in M]: (this: any, ...args: any[]) => any; }>)>>) => import("@endo/exo").Farable<T>;
27
27
  import type { SyncCallback } from './types.js';
28
28
  import type { Callback } from './types.js';
29
29
  import type { ERef } from '@endo/far';
@@ -1 +1 @@
1
- {"version":3,"file":"callback.d.ts","sourceRoot":"","sources":["callback.js"],"names":[],"mappings":"AAiDO,yBALoC,CAAC,SAA/B,CAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,GAAI,YAC/B,aAAa,CAAC,CAAC,WACf,UAAU,CAAC,CAAC,CAAC,GACX,UAAU,CAAC,CAAC,CAAC,CAQzB;AAWM,sBALoC,CAAC,SAA/B,CAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,GAAI,YAC/B,SAAS,CAAC,CAAC,WACX,UAAU,CAAC,CAAC,CAAC,GACX,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAQ3C;AAaM,yCAPoC,CAAC,SAA/B,CAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,GAAI,EAC2B,CAAC,SAAzD,CAAE,GAAG,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAE,MACzC,CAAC,SAAb,OAAO,EAAG,eACb,CAAC,YACD,CAAC,GACC,aAAa,CAAC,CAAC,CAQ3B;AAaM,qCAPoC,CAAC,SAA/B,CAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,GAAI,EACiC,CAAC,SAA/D,KAAM,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC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EAAE,KAAK,GAAG,KAwF5D;AAYM,yCANgD,CAAC,SAA3C,OAAQ,gBAAgB,EAAE,cAAe,QAC3C,OAAO,mBAAmB,EAAE,IAAI,kBAChC,CAAC;;gBAUQ,cAAc,CAAC,GAAG,CAAC,CACtC;2BAvS0C,CAAC,SAA/B,OAAQ,WAAW,EAAE,OAAQ,IAC7B,CACZ,GAAO,IAAI,EAAE,UAAU,CAAC,UAAU,GAqKR,CAAC,SAAd,WAAY,QACf,OAAO,mBAAmB,EAAE,IAAI,eAEhC,CAAC,EAAE,4BAEX;IAEU,cAAc,8CADrB,CAAC;IAGkB,GAAG;CAC3B;aAgEc,GAAG;;;uDArDgB,GAAG,WAAW,GAAG,EAAE,KAAK,GAAG,MA1LP,CAAC,KAC/C,OAAO,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;kCAdI,YAAY;8BAAZ,YAAY;0BAD9B,WAAW"}
package/src/callback.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // @ts-check
2
+ import { Fail, makeError, q } from '@endo/errors';
2
3
  import { E } from '@endo/far';
3
4
  import { isObject, isPassableSymbol } from '@endo/marshal';
4
5
  import { getInterfaceMethodKeys } from '@endo/patterns';
@@ -6,8 +7,6 @@ import { getInterfaceMethodKeys } from '@endo/patterns';
6
7
  /** @import {ERef} from '@endo/far' */
7
8
  /** @import {Callback, SyncCallback} from './types.js' */
8
9
 
9
- const { Fail, quote: q } = assert;
10
-
11
10
  const { fromEntries } = Object;
12
11
 
13
12
  const { ownKeys: rawOwnKeys } = Reflect;
@@ -42,7 +41,7 @@ const isPropertyKey = key => {
42
41
  /**
43
42
  * Synchronously call a callback.
44
43
  *
45
- * @template {(...args: unknown[]) => any} I
44
+ * @template {(...args: any[]) => any} I
46
45
  * @param {SyncCallback<I>} callback
47
46
  * @param {Parameters<I>} args
48
47
  * @returns {ReturnType<I>}
@@ -59,7 +58,7 @@ harden(callSync);
59
58
  /**
60
59
  * Eventual send to a callback.
61
60
  *
62
- * @template {(...args: unknown[]) => any} I
61
+ * @template {(...args: any[]) => any} I
63
62
  * @param {Callback<I>} callback
64
63
  * @param {Parameters<I>} args
65
64
  * @returns {Promise<Awaited<ReturnType<I>>>}
@@ -76,9 +75,9 @@ harden(callE);
76
75
  /**
77
76
  * Create a callback from a near function.
78
77
  *
79
- * @template {(...args: unknown[]) => any} I
78
+ * @template {(...args: any[]) => any} I
80
79
  * @template {(...args: [...B, ...Parameters<I>]) => ReturnType<I>} [T=I]
81
- * @template {unknown[]} [B=[]]
80
+ * @template {any[]} [B=[]]
82
81
  * @param {T} target
83
82
  * @param {B} bound
84
83
  * @returns {SyncCallback<I>}
@@ -95,9 +94,9 @@ harden(makeSyncFunctionCallback);
95
94
  /**
96
95
  * Create a callback from a potentially far function.
97
96
  *
98
- * @template {(...args: unknown[]) => any} I
97
+ * @template {(...args: any[]) => any} I
99
98
  * @template {ERef<(...args: [...B, ...Parameters<I>]) => ReturnType<I>>} [T=ERef<I>]
100
- * @template {unknown[]} [B=[]]
99
+ * @template {any[]} [B=[]]
101
100
  * @param {T} target
102
101
  * @param {B} bound
103
102
  * @returns {Callback<I>}
@@ -114,12 +113,12 @@ harden(makeFunctionCallback);
114
113
  /**
115
114
  * Create a callback from a near method.
116
115
  *
117
- * @template {(...args: unknown[]) => any} I
116
+ * @template {(...args: any[]) => any} I
118
117
  * @template {PropertyKey} P
119
118
  * @template {{
120
119
  * [x in P]: (...args: [...B, ...Parameters<I>]) => ReturnType<I>;
121
120
  * }} [T={ [x in P]: I }]
122
- * @template {unknown[]} [B=[]]
121
+ * @template {any[]} [B=[]]
123
122
  * @param {T} target
124
123
  * @param {P} methodName
125
124
  * @param {B} bound
@@ -140,12 +139,12 @@ harden(makeSyncMethodCallback);
140
139
  /**
141
140
  * Create a callback from a potentially far method.
142
141
  *
143
- * @template {(...args: unknown[]) => any} I
142
+ * @template {(...args: any[]) => any} I
144
143
  * @template {PropertyKey} P
145
144
  * @template {ERef<{
146
145
  * [x in P]: (...args: [...B, ...Parameters<I>]) => ReturnType<I>;
147
146
  * }>} [T=ERef<{ [x in P]: I }>]
148
- * @template {unknown[]} [B=[]]
147
+ * @template {any[]} [B=[]]
149
148
  * @param {T} target
150
149
  * @param {P} methodName
151
150
  * @param {B} bound
@@ -201,11 +200,11 @@ export const prepareAttenuator = (
201
200
  { interfaceGuard, tag = 'Attenuator' } = {},
202
201
  ) => {
203
202
  /**
204
- * @typedef {(this: any, ...args: unknown[]) => any} Method
203
+ * @typedef {(this: any, ...args: any[]) => any} Method
205
204
  *
206
205
  * @typedef {{ [K in M]?: Callback<any> | null }} Overrides
207
206
  *
208
- * @typedef {{ [K in M]: (this: any, ...args: unknown[]) => any }} Methods
207
+ * @typedef {{ [K in M]: (this: any, ...args: any[]) => any }} Methods
209
208
  */
210
209
  const methods = /** @type {Methods} */ (
211
210
  fromEntries(
@@ -223,9 +222,7 @@ export const prepareAttenuator = (
223
222
  // Support both synchronous and async callbacks.
224
223
  const cb = this.state.cbs[key];
225
224
  if (!cb) {
226
- const err = assert.error(
227
- `unimplemented ${q(tag)} method ${q(key)}`,
228
- );
225
+ const err = makeError(`unimplemented ${q(tag)} method ${q(key)}`);
229
226
  if (this.state.isSync) {
230
227
  throw err;
231
228
  }
@@ -0,0 +1,2 @@
1
+ export function NonNullish<T>(val: T | null | undefined, optDetails?: string | undefined): T;
2
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["errors.js"],"names":[],"mappings":"AAQO,2BALM,CAAC,OACH,CAAC,GAAG,IAAI,GAAG,SAAS,oCAElB,CAAC,CAQb"}
package/src/errors.js ADDED
@@ -0,0 +1,16 @@
1
+ import { q } from '@endo/errors';
2
+
3
+ /**
4
+ * @template T
5
+ * @param {T | null | undefined} val
6
+ * @param {string} [optDetails]
7
+ * @returns {T}
8
+ */
9
+ export const NonNullish = (val, optDetails = `unexpected ${q(val)}`) => {
10
+ if (val != null) {
11
+ // This `!= null` idiom checks that `val` is neither `null` nor `undefined`.
12
+ return val;
13
+ }
14
+ assert.fail(optDetails);
15
+ };
16
+ harden(NonNullish);
package/src/index.d.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  export * from "./config.js";
2
2
  export * from "./debug.js";
3
+ export * from "./errors.js";
3
4
  export * from "./utils.js";
4
5
  export * from "./method-tools.js";
6
+ export * from "./typeCheck.js";
5
7
  export * from "./typeGuards.js";
6
8
  export * from "./types.js";
7
9
  export { objectMap } from "@endo/common/object-map.js";
10
+ export { objectMetaMap } from "@endo/common/object-meta-map.js";
8
11
  export { fromUniqueEntries } from "@endo/common/from-unique-entries.js";
9
12
  //# sourceMappingURL=index.d.ts.map
package/src/index.js CHANGED
@@ -4,12 +4,15 @@
4
4
 
5
5
  export * from './config.js';
6
6
  export * from './debug.js';
7
+ export * from './errors.js';
7
8
  export * from './utils.js';
8
9
  export * from './method-tools.js';
10
+ export * from './typeCheck.js';
9
11
  export * from './typeGuards.js';
10
12
 
11
13
  // eslint-disable-next-line import/export -- just types
12
14
  export * from './types.js';
13
15
 
14
16
  export { objectMap } from '@endo/common/object-map.js';
17
+ export { objectMetaMap } from '@endo/common/object-meta-map.js';
15
18
  export { fromUniqueEntries } from '@endo/common/from-unique-entries.js';
@@ -1 +1 @@
1
- {"version":3,"file":"lib-chainStorage.d.ts","sourceRoot":"","sources":["lib-chainStorage.js"],"names":[],"mappings":"AA0PA;;;;;;;;;;;;GAYG;AACH,2DATW,CAAC,OAAO,EAAE,cAAc,KAAK,GAAG,YAGhC,MAAM;;;;IAhEX;;;OAGG;mBADa,OAAO,CAAC,WAAW,CAAC;IASpC;;;;;OAKG;wBAHQ,MAAM,qBACO;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GACtC,WAAW;IAYnB,+CAA+C;oBAA5B,MAAM,GAAK,OAAO,CAAC,IAAI,CAAC;GAqDhD;AAWD;;;;;;;;GAQG;AACH,qDAJW,KAAK,WAAW,OAAC,CAAC,aAClB,MAAM,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;IAC9C,IAAY,EAAE,2BAA2B,CAAC;CACnC,GACD;IACN,MAAc,EAAE,iCAAiC,CAAC;IAClD,IAAY,EAAE,+BAA+B,CAAC;CACvC;0BA5Ie,WAAW;iCACJ,eAAe"}
@@ -1,5 +1,6 @@
1
1
  // @ts-check
2
2
 
3
+ import { Fail } from '@endo/errors';
3
4
  import { E } from '@endo/far';
4
5
  import { M } from '@endo/patterns';
5
6
  import { makeHeapZone } from '@agoric/base-zone/heap.js';
@@ -10,8 +11,6 @@ import * as cb from './callback.js';
10
11
  * @import {PassableCap} from '@endo/marshal';
11
12
  */
12
13
 
13
- const { Fail } = assert;
14
-
15
14
  /** @typedef {ReturnType<typeof import('@endo/marshal').makeMarshal>} Marshaller */
16
15
  /** @typedef {Pick<Marshaller, 'fromCapData'>} Unserializer */
17
16
 
@@ -1,7 +1,7 @@
1
1
  // this file is loaded by the controller, in the start compartment
2
2
  import { spawn } from 'child_process';
3
3
  import { makePromiseKit } from '@endo/promise-kit';
4
- import { NonNullish } from '@agoric/assert';
4
+ import { NonNullish } from '../errors.js';
5
5
  import { arrayEncoderStream, arrayDecoderStream } from './worker-protocol.js';
6
6
  import {
7
7
  netstringEncoderStream,
@@ -1 +1 @@
1
- {"version":3,"file":"marshal.d.ts","sourceRoot":"","sources":["marshal.js"],"names":[],"mappings":"AAkBO,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"}
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"}
package/src/marshal.js CHANGED
@@ -1,10 +1,9 @@
1
1
  // @ts-check
2
+ import { Fail } from '@endo/errors';
2
3
  import { Far } from '@endo/far';
3
4
  import { makeMarshal } from '@endo/marshal';
4
5
  import { isStreamCell } from './lib-chainStorage.js';
5
6
 
6
- const { Fail } = assert;
7
-
8
7
  /**
9
8
  * Should be a union with Remotable, but that's `any`, making this type
10
9
  * meaningless
package/src/netstring.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* global Buffer */
2
- import { Fail } from '@agoric/assert';
2
+ import { Fail } from '@endo/errors';
3
3
 
4
4
  // adapted from 'netstring-stream', https://github.com/tlivings/netstring-stream/
5
5
  import { Transform } from 'stream';
@@ -1 +1 @@
1
- {"version":3,"file":"createBundles.d.ts","sourceRoot":"","sources":["createBundles.js"],"names":[],"mappings":"AAWO,6EA+BN;AAEM,mFAMN;AAEM,iGAkCN"}
1
+ {"version":3,"file":"createBundles.d.ts","sourceRoot":"","sources":["createBundles.js"],"names":[],"mappings":"AAYO,6EAgCN;AAEM,mFAMN;AAEM,iGAkCN"}
@@ -5,7 +5,8 @@ import path from 'path';
5
5
  import { spawnSync } from 'child_process';
6
6
  import { createRequire } from 'module';
7
7
 
8
- const { Fail, quote: q } = assert;
8
+ import { Fail, q } from '@endo/errors';
9
+
9
10
  const BUNDLE_SOURCE_PROGRAM = 'bundle-source';
10
11
  const req = createRequire(import.meta.url);
11
12
 
@@ -24,6 +25,7 @@ export const createBundlesFromAbsolute = async sourceBundles => {
24
25
  const bundle = match[1];
25
26
 
26
27
  const args = cacheToArgs.get(cache) || ['--cache-js', cache];
28
+ args.push('--elide-comments');
27
29
  args.push(srcPath, bundle);
28
30
  cacheToArgs.set(cache, args);
29
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"priority-senders.d.ts","sourceRoot":"","sources":["priority-senders.js"],"names":[],"mappings":"AAMA,4CAA4C;AAC5C,uCADW,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAMtC;AAQK,wDAFI,IAAI,CAAC,OAAO,uBAAuB,EAAE,WAAW,CAAC;IA0CxD;;;;OAIG;wBAHQ,MAAM,WACN,MAAM,KACJ,OAAO,CAAC,IAAI,CAAC;IAe1B;;;;OAIG;2BAHQ,MAAM,WACN,MAAM,KACJ,OAAO,CAAC,IAAI,CAAC;;IArB1B;;;;OAIG;wBAHQ,MAAM,WACN,MAAM,KACJ,OAAO,CAAC,IAAI,CAAC;IAe1B;;;;OAIG;2BAHQ,MAAM,WACN,MAAM,KACJ,OAAO,CAAC,IAAI,CAAC;GAuB7B;qCAGa,UAAU,CAAC,OAAO,0BAA0B,CAAC"}
1
+ {"version":3,"file":"priority-senders.d.ts","sourceRoot":"","sources":["priority-senders.js"],"names":[],"mappings":"AAKA,4CAA4C;AAC5C,uCADW,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAMtC;AAQK,wDAFI,IAAI,CAAC,OAAO,uBAAuB,EAAE,WAAW,CAAC;IA0CxD;;;;OAIG;wBAHQ,MAAM,WACN,MAAM,KACJ,OAAO,CAAC,IAAI,CAAC;IAe1B;;;;OAIG;2BAHQ,MAAM,WACN,MAAM,KACJ,OAAO,CAAC,IAAI,CAAC;;IArB1B;;;;OAIG;wBAHQ,MAAM,WACN,MAAM,KACJ,OAAO,CAAC,IAAI,CAAC;IAe1B;;;;OAIG;2BAHQ,MAAM,WACN,MAAM,KACJ,OAAO,CAAC,IAAI,CAAC;GAuB7B;qCAGa,UAAU,CAAC,OAAO,0BAA0B,CAAC"}
@@ -1,7 +1,6 @@
1
+ import { Fail, q } from '@endo/errors';
1
2
  import { E, Far } from '@endo/far';
2
3
 
3
- const { Fail, quote: q } = assert;
4
-
5
4
  const PRIORITY_SENDERS_NAMESPACE_RE = /^[a-zA-Z0-9_-]{1,50}$/;
6
5
 
7
6
  /** @type {(namespace: string) => string} */
@@ -36,14 +36,6 @@ export function documentStorageSchema(t: import("ava").ExecutionContext<unknown>
36
36
  pattern: string;
37
37
  replacement: string;
38
38
  } | {})): Promise<void>;
39
- /**
40
- * A map corresponding with a total function such that `get(key)` is assumed to
41
- * always succeed.
42
- */
43
- export type TotalMap<K, V> = { [k in Exclude<keyof Map<K, V>, "get">]: Map<K, V>[k]; } & {
44
- get: (key: K) => V;
45
- };
46
- export type TotalMapFrom<T> = T extends Map<infer K, infer V> ? TotalMap<K, V> : never;
47
39
  export type FakeStorageKit = ReturnType<typeof makeFakeStorageKit>;
48
40
  export type MockChainStorageRootMethods = {
49
41
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"storage-test-utils.d.ts","sourceRoot":"","sources":["storage-test-utils.js"],"names":[],"mappings":"AAsCO,yCAHI,MAAM,UACN,MAAM,0GAGC;AAElB;;;GAGG;AACH;;;;;EAEG;AA4CH,8CAtBuB,GAAG,KAAK,GAAG,CAsB+B;AAU1D,6CAHI,MAAM,gBACN,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC;;;;;oBAkGX,CAAC;;;;UAOtB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;;yBAhF1B,cAAc;;;;EAoF3B;AAoBM,4CADO,oBAAoB,CA6BjC;AAQM,yCALI,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,iBAkCnD;;;;;qBAnRY,CAAC,EAAE,CAAC,IACJ,GAAG,CAAoC,IAA/B,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAE,GAAG;IACvE,GAAO,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;CACpB;yBAGS,CAAC,IACD,CAAC,SAAS,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK;6BAsLvD,UAAU,CAAC,OAAO,kBAAkB,CAAC;;;;;;;;aAIr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check
2
+ import { Fail } from '@endo/errors';
2
3
  import { Far } from '@endo/far';
3
4
  import { makeMarshal, Remotable } from '@endo/marshal';
4
5
  import { unmarshalFromVstorage } from './marshal.js';
@@ -8,27 +9,12 @@ import { bindAllMethods } from './method-tools.js';
8
9
  import { eventLoopIteration } from './testing-utils.js';
9
10
 
10
11
  /**
12
+ * @import {TotalMap} from './types.js';
11
13
  * @import {Marshaller, StorageEntry, StorageMessage, StorageNode} from './lib-chainStorage.js';
12
14
  */
13
15
 
14
- const { Fail } = assert;
15
-
16
16
  const trace = makeTracer('StorTU', false);
17
17
 
18
- /**
19
- * A map corresponding with a total function such that `get(key)` is assumed to
20
- * always succeed.
21
- *
22
- * @template K, V
23
- * @typedef {{ [k in Exclude<keyof Map<K, V>, 'get'>]: Map<K, V>[k] } & {
24
- * get: (key: K) => V;
25
- * }} TotalMap
26
- */
27
- /**
28
- * @template T
29
- * @typedef {T extends Map<infer K, infer V> ? TotalMap<K, V> : never} TotalMapFrom
30
- */
31
-
32
18
  /**
33
19
  * A convertSlotToVal function that produces basic Remotables. Assumes that all
34
20
  * slots are Remotables (i.e. none are Promises).
package/src/tagged.d.ts CHANGED
@@ -21,13 +21,13 @@ A tag's name is usually a string (and must be a string, number, or symbol), but
21
21
 
22
22
  A type `A` returned by `Tagged` is assignable to another type `B` returned by `Tagged` if and only if:
23
23
  - the underlying (untagged) type of `A` is assignable to the underlying type of `B`;
24
- - `A` contains at least all the tags `B` has;
25
- - and the metadata type for each of `A`'s tags is assignable to the metadata type of `B`'s corresponding tag.
24
+ - `A` contains at least all the tags `B` has;
25
+ - and the metadata type for each of `A`'s tags is assignable to the metadata type of `B`'s corresponding tag.
26
26
 
27
27
  There have been several discussions about adding similar features to TypeScript. Unfortunately, nothing has (yet) moved forward:
28
- - [Microsoft/TypeScript#202](https://github.com/microsoft/TypeScript/issues/202)
29
- - [Microsoft/TypeScript#4895](https://github.com/microsoft/TypeScript/issues/4895)
30
- - [Microsoft/TypeScript#33290](https://github.com/microsoft/TypeScript/pull/33290)
28
+ - [Microsoft/TypeScript#202](https://github.com/microsoft/TypeScript/issues/202)
29
+ - [Microsoft/TypeScript#4895](https://github.com/microsoft/TypeScript/issues/4895)
30
+ - [Microsoft/TypeScript#33290](https://github.com/microsoft/TypeScript/pull/33290)
31
31
 
32
32
  @example
33
33
  ```
@@ -37,12 +37,12 @@ type AccountNumber = Tagged<number, 'AccountNumber'>;
37
37
  type AccountBalance = Tagged<number, 'AccountBalance'>;
38
38
 
39
39
  function createAccountNumber(): AccountNumber {
40
- // As you can see, casting from a `number` (the underlying type being tagged) is allowed.
41
- return 2 as AccountNumber;
40
+ // As you can see, casting from a `number` (the underlying type being tagged) is allowed.
41
+ return 2 as AccountNumber;
42
42
  }
43
43
 
44
44
  function getMoneyForAccount(accountNumber: AccountNumber): AccountBalance {
45
- return 4 as AccountBalance;
45
+ return 4 as AccountBalance;
46
46
  }
47
47
 
48
48
  // This will compile successfully.
@@ -69,8 +69,6 @@ type SpecialCacheKey = Tagged<Url, 'SpecialCacheKey'>;
69
69
  // You can also pass a union of tag names, so this is equivalent to the above, although it doesn't give you the ability to assign distinct metadata to each tag.
70
70
  type SpecialCacheKey2 = Tagged<string, 'URL' | 'SpecialCacheKey'>;
71
71
  ```
72
-
73
- @category Type
74
72
  */
75
73
  export type Tagged<
76
74
  Type,
@@ -102,8 +100,6 @@ function parse<T extends JsonOf<unknown>>(it: T) {
102
100
  const x = stringify({ hello: 'world' });
103
101
  const parsed = parse(x); // The type of `parsed` is { hello: string }
104
102
  ```
105
-
106
- @category Type
107
103
  */
108
104
  export type GetTagMetadata<
109
105
  Type extends Tag<TagName, unknown>,
@@ -125,8 +121,8 @@ import type {Tagged, UnwrapTagged} from 'type-fest';
125
121
  type AccountType = Tagged<'SAVINGS' | 'CHECKING', 'AccountType'>;
126
122
 
127
123
  const moneyByAccountType: Record<UnwrapTagged<AccountType>, number> = {
128
- SAVINGS: 99,
129
- CHECKING: 0.1
124
+ SAVINGS: 99,
125
+ CHECKING: 0.1
130
126
  };
131
127
 
132
128
  // Without UnwrapTagged, the following expression would throw a type error.
@@ -135,8 +131,6 @@ const money = moneyByAccountType.SAVINGS; // TS error: Property 'SAVINGS' does n
135
131
  // Attempting to pass an non-Tagged type to UnwrapTagged will raise a type error.
136
132
  type WontWork = UnwrapTagged<string>;
137
133
  ```
138
-
139
- @category Type
140
134
  */
141
135
  export type UnwrapTagged<TaggedType extends Tag<PropertyKey, any>> =
142
136
  RemoveAllTags<TaggedType>;
@@ -1,2 +1,4 @@
1
1
  export function eventLoopIteration(): Promise<any>;
2
+ export function inspectMapStore(store: MapStore): object;
3
+ import type { MapStore } from '@agoric/store';
2
4
  //# sourceMappingURL=testing-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing-utils.d.ts","sourceRoot":"","sources":["testing-utils.js"],"names":[],"mappings":"AAaO,mDACwC"}
1
+ {"version":3,"file":"testing-utils.d.ts","sourceRoot":"","sources":["testing-utils.js"],"names":[],"mappings":"AAeO,mDACwC;AAgBxC,uCAHI,QAAQ,GACN,MAAM,CAqBlB;8BA7C2B,eAAe"}
@@ -1,8 +1,10 @@
1
+ // @ts-check
1
2
  /**
2
3
  * @file note this cannot be called test-utils.js due to
3
4
  * https://github.com/Agoric/agoric-sdk/issues/7503
4
5
  */
5
6
  /* global setImmediate */
7
+ /** @import {MapStore} from '@agoric/store'; */
6
8
 
7
9
  /**
8
10
  * A workaround for some issues with fake time in tests.
@@ -14,3 +16,38 @@
14
16
  export const eventLoopIteration = async () =>
15
17
  new Promise(resolve => setImmediate(resolve));
16
18
  harden(eventLoopIteration);
19
+
20
+ /** @type {(value: any) => string} */
21
+ const stringOrTag = value => {
22
+ if (typeof value === 'string') {
23
+ return value;
24
+ } else if (typeof value === 'object' && Symbol.toStringTag in value) {
25
+ return value[Symbol.toStringTag];
26
+ }
27
+ return String(value);
28
+ };
29
+ /**
30
+ * @param {MapStore} store
31
+ * @returns {object} tree of the contents of the storeÂ
32
+ */
33
+ export const inspectMapStore = store => {
34
+ /** @type {Record<string, unknown>} */
35
+ const obj = {};
36
+ for (const key of store.keys()) {
37
+ const value = store.get(key);
38
+ const hasKeys = typeof value === 'object' && 'keys' in value;
39
+ const index = stringOrTag(key);
40
+ if (hasKeys && 'get' in value) {
41
+ obj[index] = inspectMapStore(value);
42
+ } else if (hasKeys) {
43
+ obj[index] = Array.from(value.keys());
44
+ } else {
45
+ obj[index] =
46
+ value instanceof Object && Symbol.toStringTag in value
47
+ ? value[Symbol.toStringTag]
48
+ : value;
49
+ }
50
+ }
51
+ return obj;
52
+ };
53
+ harden(inspectMapStore);
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @import {MustMatch, PatternType, TypedPattern} from './types.js';
3
+ */
4
+ /** @type {MustMatch} */
5
+ export const mustMatch: MustMatch;
6
+ export function cast<M>(specimen: unknown, patt: TypedPattern<M>): M;
7
+ import type { MustMatch } from './types.js';
8
+ import type { TypedPattern } from './types.js';
9
+ //# sourceMappingURL=typeCheck.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeCheck.d.ts","sourceRoot":"","sources":["typeCheck.js"],"names":[],"mappings":"AAGA;;GAEG;AAEH,wBAAwB;AACxB,wBADW,SAAS,CACuB;AAQpC,qBALM,CAAC,YACH,OAAO,QACP,aAAa,CAAC,CAAC,GACb,CAAC,CAQb;+BAlBsD,YAAY;kCAAZ,YAAY"}
@@ -0,0 +1,23 @@
1
+ // @ts-check
2
+ import { mustMatch as typelessMustMatch } from '@endo/patterns';
3
+
4
+ /**
5
+ * @import {MustMatch, PatternType, TypedPattern} from './types.js';
6
+ */
7
+
8
+ /** @type {MustMatch} */
9
+ export const mustMatch = typelessMustMatch;
10
+
11
+ /**
12
+ * @template M
13
+ * @param {unknown} specimen
14
+ * @param {TypedPattern<M>} patt
15
+ * @returns {M}
16
+ */
17
+ export const cast = (specimen, patt) => {
18
+ // mustMatch throws if they don't, which means that `cast` also narrows the
19
+ // type but a function can't both narrow and return a type. That is by design:
20
+ // https://github.com/microsoft/TypeScript/issues/34636#issuecomment-545025916
21
+ mustMatch(specimen, patt);
22
+ return specimen;
23
+ };
package/src/types.d.ts CHANGED
@@ -3,7 +3,18 @@ import type { ERef, RemotableBrand } from '@endo/eventual-send';
3
3
  import type { Primitive } from '@endo/pass-style';
4
4
  import type { Callable } from './utils.js';
5
5
 
6
- export declare class Callback<I extends (...args: unknown[]) => any> {
6
+ /**
7
+ * A map corresponding with a total function such that `get(key)` is assumed to
8
+ * always succeed.
9
+ */
10
+ export type TotalMap<K, V> = Omit<Map<K, V>, 'get'> & {
11
+ /** Returns the element associated with the specified key in the TotalMap. */
12
+ get: (key: K) => V;
13
+ };
14
+ export type TotalMapFrom<M extends Map> =
15
+ M extends Map<infer K, infer V> ? TotalMap<K, V> : never;
16
+
17
+ export declare class Callback<I extends (...args: any[]) => any> {
7
18
  private iface: I;
8
19
 
9
20
  public target: any;
@@ -64,3 +75,33 @@ export type Remote<Primary, Local = DataOnly<Primary>> =
64
75
  export type FarRef<Primary, Local = DataOnly<Primary>> = ERef<
65
76
  Remote<Primary, Local>
66
77
  >;
78
+
79
+ /*
80
+ * Stop-gap until https://github.com/Agoric/agoric-sdk/issues/6160
81
+ * explictly specify the type that the Pattern will verify through a match.
82
+ *
83
+ * TODO move all this pattern typing stuff to @endo/patterns
84
+ */
85
+ declare const validatedType: unique symbol;
86
+ /**
87
+ * Tag a pattern with the static type it represents.
88
+ */
89
+ export type TypedPattern<T> = Pattern & { [validatedType]?: T };
90
+
91
+ export declare type PatternType<TM extends TypedPattern<any>> =
92
+ TM extends TypedPattern<infer T> ? T : never;
93
+
94
+ // TODO make Endo's mustMatch do this
95
+ /**
96
+ * Returning normally indicates success. Match failure is indicated by
97
+ * throwing.
98
+ *
99
+ * Note: remotables can only be matched as "remotable", not the specific kind.
100
+ *
101
+ * @see {import('@endo/patterns').mustMatch} for the implementation. This one has a type annotation to narrow if the pattern is a TypedPattern.
102
+ */
103
+ export declare type MustMatch = <P extends Pattern>(
104
+ specimen: unknown,
105
+ pattern: P,
106
+ label?: string | number,
107
+ ) => asserts specimen is P extends TypedPattern<any> ? PatternType<P> : unknown;
package/src/utils.d.ts CHANGED
@@ -31,6 +31,10 @@ export const BASIS_POINTS: 10000n;
31
31
  * @type {<T extends {}>(unfulfilledTerms: T) => Promise<DeeplyAwaited<T>>}
32
32
  */
33
33
  export const deeplyFulfilledObject: <T extends {}>(unfulfilledTerms: T) => Promise<DeeplyAwaited<T>>;
34
+ export function deepMapObject(obj: object, mapper: (value: any, name: string, record: object) => any): object;
35
+ export function PromiseAllOrErrors<T>(items: readonly (T | PromiseLike<T>)[]): Promise<T[]>;
36
+ export function aggregateTryFinally<T>(trier: () => Promise<T>, finalizer: (error?: unknown) => Promise<unknown>): ReturnType<() => Promise<T>>;
37
+ export function withDeferredCleanup<T>(fn: (addCleanup: (fn: (err?: unknown) => Promise<void>) => void) => Promise<T>): ReturnType<(addCleanup: (fn: (err?: unknown) => Promise<void>) => void) => Promise<T>>;
34
38
  export function makeMeasureSeconds(currentTimeMillisec: typeof import("perf_hooks").performance.now): <T>(fn: () => Promise<T>) => Promise<{
35
39
  result: T;
36
40
  duration: number;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.js"],"names":[],"mappings":"AAYA,kCAAoC;AAEpC,sCAAsC;AAEtC;;;;;GAKG;AAEH;;GAEG;AAEH;;;;;GAKG;AAEH;;;;;;;GAOG;AAEH;;;;;;GAMG;AACH,oCAFU,CAAC,CAAY,SAAF,EAAE,EAAE,gBAAgB,EAAE,CAAC,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAKxE;AAYK,wDALI,cAAc,YAAY,EAAE,WAAW,CAAC,GAAG,GACzC,CAAC,CAAC,EACd,EAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KACjB,OAAO,CAAC;IAAE,MAAM,EAAE,CAAC,CAAC;IAAC,QAAQ,EAAE,MAAM,CA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,CAAC,CAAC,OAAO,CAAC,GAAE,GAAG,EAAE;uBAMzC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG;gCAIlB,CAAC,SAAN,EAAI,IACJ,GACP,CAAY,IAAP,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACnE;0BAIS,CAAC,IACD,CAAC,SAAS,WAAW,CAAC,GAAG,CAAC,GAC9B,OAAO,CAAC,CAAC,CAAC,GACV,CAAC,SAAS,EAAE,GACV,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,GAChC,OAAO,CAAC,CAAC,CAAC;uBAyKkB,CAAC,SAA1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAE,IACzB,GAAG,CAAY,IAAP,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,GAAE;0BApMjC,WAAW"}
package/src/utils.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // @ts-check
2
2
  // @jessie-check
3
3
 
4
+ import { q, Fail, makeError, annotateError, X } from '@endo/errors';
4
5
  import { deeplyFulfilled, isObject } from '@endo/marshal';
5
6
  import { makePromiseKit } from '@endo/promise-kit';
6
7
  import { makeQueue } from '@endo/stream';
@@ -8,8 +9,6 @@ import { asyncGenerate } from 'jessie.js';
8
9
 
9
10
  const { fromEntries, keys, values } = Object;
10
11
 
11
- const { quote: q, Fail } = assert;
12
-
13
12
  export const BASIS_POINTS = 10_000n;
14
13
 
15
14
  /** @import {ERef} from '@endo/far' */
@@ -53,6 +52,138 @@ export const deeplyFulfilledObject = async obj => {
53
52
  return deeplyFulfilled(obj);
54
53
  };
55
54
 
55
+ /**
56
+ * @param {any} value
57
+ * @param {string | undefined} name
58
+ * @param {object | undefined} container
59
+ * @param {(value: any, name: string, record: object) => any} mapper
60
+ * @returns {any}
61
+ */
62
+ const deepMapObjectInternal = (value, name, container, mapper) => {
63
+ if (container && typeof name === 'string') {
64
+ const mapped = mapper(value, name, container);
65
+ if (mapped !== value) {
66
+ return mapped;
67
+ }
68
+ }
69
+
70
+ if (typeof value !== 'object' || !value) {
71
+ return value;
72
+ }
73
+
74
+ let wasMapped = false;
75
+ const mappedEntries = Object.entries(value).map(([innerName, innerValue]) => {
76
+ const mappedInnerValue = deepMapObjectInternal(
77
+ innerValue,
78
+ innerName,
79
+ value,
80
+ mapper,
81
+ );
82
+ wasMapped ||= mappedInnerValue !== innerValue;
83
+ return [innerName, mappedInnerValue];
84
+ });
85
+
86
+ return wasMapped ? Object.fromEntries(mappedEntries) : value;
87
+ };
88
+
89
+ /**
90
+ * Traverses a record object structure deeply, calling a replacer for each
91
+ * enumerable string property values of an object. If none of the values are
92
+ * changed, the original object is used as-is, maintaining its identity.
93
+ *
94
+ * When an object is found as a property value, the replacer is first called on
95
+ * it. If not replaced, the object is then traversed.
96
+ *
97
+ * @param {object} obj
98
+ * @param {(value: any, name: string, record: object) => any} mapper
99
+ * @returns {object}
100
+ */
101
+ export const deepMapObject = (obj, mapper) =>
102
+ deepMapObjectInternal(obj, undefined, undefined, mapper);
103
+
104
+ /**
105
+ * Tolerate absence of AggregateError in e.g. xsnap.
106
+ *
107
+ * @type {(errors: Error[], message?: string, options?: object) => Error}
108
+ */
109
+ const makeAggregateError =
110
+ typeof AggregateError === 'function'
111
+ ? (errors, message, options) => AggregateError(errors, message, options)
112
+ : (errors, message, options) => {
113
+ return makeError(message ?? 'multiple errors', undefined, {
114
+ ...options,
115
+ errors,
116
+ });
117
+ };
118
+
119
+ /**
120
+ * @template T
121
+ * @param {readonly (T | PromiseLike<T>)[]} items
122
+ * @returns {Promise<T[]>}
123
+ */
124
+ export const PromiseAllOrErrors = async items => {
125
+ return Promise.allSettled(items).then(results => {
126
+ const errors = /** @type {PromiseRejectedResult[]} */ (
127
+ results.filter(({ status }) => status === 'rejected')
128
+ ).map(result => result.reason);
129
+ if (!errors.length) {
130
+ return /** @type {PromiseFulfilledResult<T>[]} */ (results).map(
131
+ result => result.value,
132
+ );
133
+ } else if (errors.length === 1) {
134
+ throw errors[0];
135
+ } else {
136
+ throw makeAggregateError(errors);
137
+ }
138
+ });
139
+ };
140
+
141
+ /**
142
+ * @template T
143
+ * @param {() => Promise<T>} trier
144
+ * @param {(error?: unknown) => Promise<unknown>} finalizer
145
+ * @returns {ReturnType<trier>}
146
+ */
147
+ export const aggregateTryFinally = async (trier, finalizer) =>
148
+ trier().then(
149
+ async result => finalizer().then(() => result),
150
+ async tryError =>
151
+ finalizer(tryError)
152
+ .then(
153
+ () => tryError,
154
+ finalizeError => makeAggregateError([tryError, finalizeError]),
155
+ )
156
+ .then(error => Promise.reject(error)),
157
+ );
158
+
159
+ /**
160
+ * Run a function with the ability to defer last-in-first-out cleanup callbacks.
161
+ *
162
+ * @template T
163
+ * @param {(
164
+ * addCleanup: (fn: (err?: unknown) => Promise<void>) => void,
165
+ * ) => Promise<T>} fn
166
+ * @returns {ReturnType<fn>}
167
+ */
168
+ export const withDeferredCleanup = async fn => {
169
+ /** @type {((err?: unknown) => unknown)[]} */
170
+ const cleanupsLIFO = [];
171
+ /** @type {(cleanup: (err?: unknown) => unknown) => void} */
172
+ const addCleanup = cleanup => {
173
+ cleanupsLIFO.unshift(cleanup);
174
+ };
175
+ /** @type {(err?: unknown) => Promise<void>} */
176
+ const finalizer = async err => {
177
+ // Run each cleanup in its own isolated stack.
178
+ const cleanupResults = cleanupsLIFO.map(async cleanup => {
179
+ await null;
180
+ return cleanup(err);
181
+ });
182
+ await PromiseAllOrErrors(cleanupResults);
183
+ };
184
+ return aggregateTryFinally(() => fn(addCleanup), finalizer);
185
+ };
186
+
56
187
  /**
57
188
  * Returns a function that uses a millisecond-based time-since-epoch capability
58
189
  * (such as `performance.now`) to measure execution time of an async function
@@ -204,8 +335,8 @@ export const synchronizedTee = (sourceStream, readerCount) => {
204
335
  if (doneResult) {
205
336
  result = Promise.resolve(doneResult);
206
337
  } else if (rejections.length) {
207
- const error = assert.error(assert.details`Teed stream threw`);
208
- assert.note(error, assert.details`Teed rejections: ${rejections}`);
338
+ const error = makeError(X`Teed stream threw`);
339
+ annotateError(error, X`Teed rejections: ${rejections}`);
209
340
  result =
210
341
  sourceStream.throw?.(error) ||
211
342
  Promise.resolve(sourceStream.return?.()).then(() =>
@@ -228,7 +359,9 @@ export const synchronizedTee = (sourceStream, readerCount) => {
228
359
  doneResult = { done: true, value: undefined };
229
360
  },
230
361
  );
231
- resolvers.forEach(resolve => resolve(result));
362
+ for (const resolve of resolvers) {
363
+ resolve(result);
364
+ }
232
365
  return pullNext();
233
366
  };
234
367
 
@@ -1,9 +0,0 @@
1
- export function PromiseAllOrErrors<T>(items: readonly (T | PromiseLike<T>)[]): Promise<T[]>;
2
- /**
3
- * @type {<T>(
4
- * trier: () => Promise<T>,
5
- * finalizer: (error?: unknown) => Promise<void>,
6
- * ) => Promise<T>}
7
- */
8
- export const aggregateTryFinally: <T>(trier: () => Promise<T>, finalizer: (error?: unknown) => Promise<void>) => Promise<T>;
9
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.js"],"names":[],"mappings":"AAYO,mCAJM,CAAC,SACH,SAAS,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,GAC7B,OAAO,CAAC,CAAC,EAAE,CAAC,CAiBxB;AAED;;;;;GAKG;AACH,kCALU,CAAC,CAAC,EACX,KAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,SAAa,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,KAC1C,OAAO,CAAC,CAAC,CAAC,CAYd"}
package/src/node/utils.js DELETED
@@ -1,46 +0,0 @@
1
- // @ts-check
2
- // @jessie-check
3
-
4
- // These tools seem cross platform, but they rely on AggregateError in the error
5
- // handling path, which is currently not available in xsnap
6
- import 'node:process';
7
-
8
- /**
9
- * @template T
10
- * @param {readonly (T | PromiseLike<T>)[]} items
11
- * @returns {Promise<T[]>}
12
- */
13
- export const PromiseAllOrErrors = async items => {
14
- return Promise.allSettled(items).then(results => {
15
- const errors = /** @type {PromiseRejectedResult[]} */ (
16
- results.filter(({ status }) => status === 'rejected')
17
- ).map(result => result.reason);
18
- if (!errors.length) {
19
- return /** @type {PromiseFulfilledResult<T>[]} */ (results).map(
20
- result => result.value,
21
- );
22
- } else if (errors.length === 1) {
23
- throw errors[0];
24
- } else {
25
- throw AggregateError(errors);
26
- }
27
- });
28
- };
29
-
30
- /**
31
- * @type {<T>(
32
- * trier: () => Promise<T>,
33
- * finalizer: (error?: unknown) => Promise<void>,
34
- * ) => Promise<T>}
35
- */
36
- export const aggregateTryFinally = async (trier, finalizer) =>
37
- trier().then(
38
- async result => finalizer().then(() => result),
39
- async tryError =>
40
- finalizer(tryError)
41
- .then(
42
- () => tryError,
43
- finalizeError => AggregateError([tryError, finalizeError]),
44
- )
45
- .then(error => Promise.reject(error)),
46
- );