@agoric/internal 0.3.3-other-dev-3eb1a1d.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.
Files changed (77) hide show
  1. package/package.json +27 -23
  2. package/src/action-types.d.ts +2 -1
  3. package/src/action-types.d.ts.map +1 -1
  4. package/src/action-types.js +4 -4
  5. package/src/batched-deliver.d.ts.map +1 -1
  6. package/src/callback.d.ts +1 -1
  7. package/src/callback.d.ts.map +1 -1
  8. package/src/callback.js +7 -6
  9. package/src/chain-storage-paths.d.ts.map +1 -1
  10. package/src/chain-utils.d.ts +3 -1
  11. package/src/chain-utils.d.ts.map +1 -1
  12. package/src/chain-utils.js +6 -1
  13. package/src/cli-utils.d.ts +2 -0
  14. package/src/cli-utils.d.ts.map +1 -0
  15. package/src/cli-utils.js +21 -0
  16. package/src/config.d.ts +2 -4
  17. package/src/config.js +4 -2
  18. package/src/errors.d.ts +1 -1
  19. package/src/errors.d.ts.map +1 -1
  20. package/src/hex.d.ts +15 -0
  21. package/src/hex.d.ts.map +1 -0
  22. package/src/hex.js +105 -0
  23. package/src/index.d.ts +5 -3
  24. package/src/index.js +5 -4
  25. package/src/js-utils.d.ts +34 -1
  26. package/src/js-utils.d.ts.map +1 -1
  27. package/src/js-utils.js +162 -14
  28. package/src/lib-chainStorage.d.ts +26 -24
  29. package/src/lib-chainStorage.d.ts.map +1 -1
  30. package/src/lib-chainStorage.js +7 -15
  31. package/src/lib-nodejs/ava-unhandled-rejection.d.ts +13 -0
  32. package/src/lib-nodejs/ava-unhandled-rejection.d.ts.map +1 -0
  33. package/src/lib-nodejs/ava-unhandled-rejection.js +66 -0
  34. package/src/marshal.d.ts +15 -2
  35. package/src/marshal.d.ts.map +1 -1
  36. package/src/marshal.js +26 -7
  37. package/src/method-tools.d.ts.map +1 -1
  38. package/src/method-tools.js +8 -50
  39. package/src/metrics.d.ts +183 -0
  40. package/src/metrics.d.ts.map +1 -0
  41. package/src/metrics.js +476 -0
  42. package/src/module-utils.d.ts +2 -0
  43. package/src/module-utils.d.ts.map +1 -0
  44. package/src/module-utils.js +27 -0
  45. package/src/natural-sort.d.ts +2 -0
  46. package/src/natural-sort.d.ts.map +1 -0
  47. package/src/natural-sort.js +48 -0
  48. package/src/netstring.d.ts +2 -2
  49. package/src/netstring.d.ts.map +1 -1
  50. package/src/netstring.js +1 -0
  51. package/src/node/buffer-line-transform.d.ts +3 -3
  52. package/src/node/buffer-line-transform.d.ts.map +1 -1
  53. package/src/node/fs-stream.d.ts.map +1 -1
  54. package/src/node/fs-stream.js +23 -24
  55. package/src/priority-senders.d.ts +1 -0
  56. package/src/priority-senders.d.ts.map +1 -1
  57. package/src/priority-senders.js +3 -0
  58. package/src/queue.d.ts +1 -1
  59. package/src/queue.d.ts.map +1 -1
  60. package/src/ses-utils.d.ts +9 -1
  61. package/src/ses-utils.d.ts.map +1 -1
  62. package/src/ses-utils.js +79 -3
  63. package/src/storage-test-utils.d.ts +12 -4
  64. package/src/storage-test-utils.d.ts.map +1 -1
  65. package/src/storage-test-utils.js +81 -16
  66. package/src/tagged.d.ts +4 -1
  67. package/src/testing-utils.js +1 -1
  68. package/src/tmpDir.d.ts +2 -0
  69. package/src/tmpDir.d.ts.map +1 -0
  70. package/src/tmpDir.js +17 -0
  71. package/src/tokens.d.ts.map +1 -1
  72. package/src/typeGuards.d.ts +15 -0
  73. package/src/typeGuards.d.ts.map +1 -1
  74. package/src/typeGuards.js +12 -0
  75. package/src/types.d.ts +12 -0
  76. package/src/types.d.ts.map +1 -1
  77. package/src/types.ts +21 -0
package/src/js-utils.js CHANGED
@@ -5,6 +5,52 @@
5
5
  * dependent upon a hardened environment.
6
6
  */
7
7
 
8
+ const { defineProperty } = Object;
9
+
10
+ /** For overriding TypeScript inferring the type of `true` as boolean. */
11
+ export const TRUE = /** @type {const} */ (true);
12
+
13
+ /**
14
+ * @typedef {<O extends Record<string, unknown>>(
15
+ * obj: O,
16
+ * ) => { [K in keyof O]: K extends string ? [K, O[K]] : never }[keyof O][]} TypedEntries
17
+ */
18
+ export const typedEntries = /** @type {TypedEntries} */ (Object.entries);
19
+
20
+ /**
21
+ * @typedef {<
22
+ * const Entries extends ReadonlyArray<readonly [PropertyKey, unknown]>,
23
+ * >(
24
+ * entries: Entries,
25
+ * ) => { [Entry in Entries[number] as Entry[0]]: Entry[1] }} FromTypedEntries
26
+ */
27
+ export const fromTypedEntries = /** @type {FromTypedEntries} */ (
28
+ Object.fromEntries
29
+ );
30
+
31
+ /**
32
+ * @typedef {<A extends unknown[], V>(
33
+ * arr: A,
34
+ * mapper: <K extends number>(el: A[K], idx: K, arr: A) => V,
35
+ * ) => V[]} TypedMap
36
+ */
37
+ export const typedMap = /** @type {TypedMap} */ (
38
+ Function.prototype.call.bind(Array.prototype.map)
39
+ );
40
+
41
+ export const logLevels = /** @type {const} */ ([
42
+ 'debug',
43
+ 'log',
44
+ 'info',
45
+ 'warn',
46
+ 'error',
47
+ ]);
48
+ Object.freeze(logLevels);
49
+
50
+ /** @typedef {(typeof logLevels)[keyof logLevels & number]} LogLevel */
51
+
52
+ /** @typedef {Pick<Console, LogLevel>} LimitedConsole */
53
+
8
54
  /**
9
55
  * Deep-copy a value by round-tripping it through JSON (which drops
10
56
  * function/symbol/undefined values and properties that are non-enumerable
@@ -17,11 +63,14 @@
17
63
  export const deepCopyJsonable = value => JSON.parse(JSON.stringify(value));
18
64
 
19
65
  /**
20
- * @param {any} value
21
- * @param {string | undefined} name
22
- * @param {object | undefined} container
23
- * @param {(value: any, name: string, record: object) => any} mapper
24
- * @returns {any}
66
+ * @template {Record<PropertyKey, unknown>} O
67
+ * @template {string & keyof O} K
68
+ * @template M
69
+ * @param {O[K]} value
70
+ * @param {K | undefined} name
71
+ * @param {O | undefined} container
72
+ * @param {(value: O[K], name: string, record: O) => O[K] | M} mapper
73
+ * @returns {O[K] | M | { [K2 in keyof O[K]]: O[K][K2] | M }}
25
74
  */
26
75
  const deepMapObjectInternal = (value, name, container, mapper) => {
27
76
  if (container && typeof name === 'string') {
@@ -36,18 +85,30 @@ const deepMapObjectInternal = (value, name, container, mapper) => {
36
85
  }
37
86
 
38
87
  let wasMapped = false;
39
- const mappedEntries = Object.entries(value).map(([innerName, innerValue]) => {
88
+ const valueObj = /** @type {Record<string, unknown>} */ (value);
89
+ /**
90
+ * @type {<T extends typeof value, K2 extends string & keyof T>(
91
+ * entry: [K2, T[K2]],
92
+ * ) => [K2, T[K2] | M]}
93
+ */
94
+ const mapEntry = ([innerName, innerValue]) => {
40
95
  const mappedInnerValue = deepMapObjectInternal(
41
96
  innerValue,
42
97
  innerName,
43
- value,
98
+ valueObj,
44
99
  mapper,
45
100
  );
46
101
  wasMapped ||= mappedInnerValue !== innerValue;
47
- return [innerName, mappedInnerValue];
48
- });
102
+ return [innerName, /** @type {any} */ (mappedInnerValue)];
103
+ };
104
+ const mappedEntries = typedEntries(valueObj).map(mapEntry);
49
105
 
50
- return wasMapped ? Object.fromEntries(mappedEntries) : value;
106
+ if (!wasMapped) {
107
+ return value;
108
+ }
109
+
110
+ const mappedObj = fromTypedEntries(mappedEntries);
111
+ return /** @type {any} */ (mappedObj);
51
112
  };
52
113
 
53
114
  /**
@@ -59,12 +120,79 @@ const deepMapObjectInternal = (value, name, container, mapper) => {
59
120
  * When the property value is an object, it is sent to the mapper like any other
60
121
  * value, and then recursively traversed unless replaced with a distinct value.
61
122
  *
62
- * @param {object} obj
63
- * @param {(value: any, name: string, record: object) => any} mapper
64
- * @returns {object}
123
+ * @template {Record<string, unknown>} O
124
+ * @template M
125
+ * @param {O} obj
126
+ * @param {<T extends Record<string, unknown>, K extends string & keyof T>(
127
+ * value: T[K],
128
+ * name: K,
129
+ * record: T,
130
+ * ) => T[K] | M} mapper
131
+ * @returns {O | { [K in keyof O]: K extends string ? O[K] | M : never }}
65
132
  */
66
133
  export const deepMapObject = (obj, mapper) =>
67
- deepMapObjectInternal(obj, undefined, undefined, mapper);
134
+ /** @type {any} */ (deepMapObjectInternal(obj, undefined, undefined, mapper));
135
+
136
+ /**
137
+ * Explicitly set a function's name, supporting use of arrow functions for which
138
+ * source text doesn't include a name and no initial name is set by
139
+ * NamedEvaluation
140
+ * https://tc39.es/ecma262/multipage/syntax-directed-operations.html#sec-runtime-semantics-namedevaluation
141
+ *
142
+ * `name` is the first parameter for better readability at call sites (e.g.,
143
+ * `return defineName('foo', () => { ... })`).
144
+ *
145
+ * @template {Function} F
146
+ * @param {string} name
147
+ * @param {F} fn
148
+ * @returns {F}
149
+ */
150
+ export const defineName = (name, fn) =>
151
+ defineProperty(fn, 'name', { value: name });
152
+
153
+ /**
154
+ * By analogy with how `Array.prototype.map` will map the elements of an array
155
+ * to transformed elements of an array of the same shape, `objectMapMutable`
156
+ * will do likewise for the enumerable string-keyed properties of an object.
157
+ *
158
+ * Unlike endo's `objectMap`, this function returns a non-hardened object.
159
+ *
160
+ * @template {Record<string, unknown>} O
161
+ * @template M
162
+ * @param {O} obj
163
+ * @param {<K extends keyof O>(value: O[K], key: K) => M} mapper
164
+ * @returns {{ [K in keyof O]: K extends string ? M : never }}
165
+ */
166
+ export const objectMapMutable = (obj, mapper) => {
167
+ const oldEntries = typedEntries(obj);
168
+ /** @type {<K extends keyof O>(entry: [K, O[K]]) => [K, M]} */
169
+ const mapEntry = ([k, v]) => [k, mapper(v, k)];
170
+ const newEntries = typedMap(oldEntries, mapEntry);
171
+ const newObj = fromTypedEntries(newEntries);
172
+ return /** @type {any} */ (newObj);
173
+ };
174
+
175
+ /**
176
+ * Return the value from `map` associated with `key`. If there is not yet such a
177
+ * value, get one from `makeValue(key)` and update `map` before returning the
178
+ * new value.
179
+ *
180
+ * @template K
181
+ * @template V
182
+ * @param {K extends WeakKey ? WeakMap<K, V> : Map<K, V>} map
183
+ * @param {K} key
184
+ * @param {(key: K) => V} makeValue
185
+ * @returns {V}
186
+ */
187
+ export const provideLazyMap = (map, key, makeValue) => {
188
+ const found = map.get(key);
189
+ if (found !== undefined || map.has(key)) {
190
+ return /** @type {V} */ (found);
191
+ }
192
+ const value = makeValue(key);
193
+ map.set(key, value);
194
+ return value;
195
+ };
68
196
 
69
197
  /**
70
198
  * Returns a function that uses a millisecond-based current-time capability
@@ -87,3 +215,23 @@ export const makeMeasureSeconds = currentTimeMillisec => {
87
215
  };
88
216
  return measureSeconds;
89
217
  };
218
+
219
+ /**
220
+ * Find all of an object's properties whose name starts with a prefix, and
221
+ * return a new object consisting of those properties without that prefix.
222
+ * Useful for filtering environment variables relevant to a particular purpose.
223
+ *
224
+ * @template {string} P
225
+ * @template {string} K
226
+ * @template V
227
+ * @param {Record<`${P}${K}`, V>} obj
228
+ * @param {P} prefix
229
+ */
230
+ export const unprefixedProperties = (obj, prefix) =>
231
+ /** @type {Record<K, V>} */ (
232
+ fromTypedEntries(
233
+ typedEntries(obj)
234
+ .filter(([key]) => key.startsWith(prefix))
235
+ .map(([key, value]) => [key.slice(prefix.length), value]),
236
+ )
237
+ );
@@ -13,23 +13,12 @@
13
13
  */
14
14
  export function makeChainStorageRoot(handleStorageMessage: (message: StorageMessage) => any, rootPath: string, rootOptions?: {
15
15
  sequence?: boolean | undefined;
16
- } | undefined): import("@endo/exo").Guarded<{
16
+ }): import("@endo/exo").Guarded<{
17
17
  getPath(): string;
18
- /**
19
- * @deprecated use getPath
20
- * @type {() => Promise<VStorageKey>}
21
- */
22
18
  getStoreKey(): Promise<VStorageKey>;
23
- /**
24
- * @type {(
25
- * name: string,
26
- * childNodeOptions?: { sequence?: boolean },
27
- * ) => StorageNode}
28
- */
29
19
  makeChildNode(name: string, childNodeOptions?: {
30
20
  sequence?: boolean;
31
21
  }): StorageNode;
32
- /** @type {(value: string) => Promise<void>} */
33
22
  setValue(value: string): Promise<void>;
34
23
  }>;
35
24
  /**
@@ -42,29 +31,41 @@ export function makeChainStorageRoot(handleStorageMessage: (message: StorageMess
42
31
  * @returns {Promise<StorageNode>}
43
32
  */
44
33
  export function makeStorageNodeChild(storageNodeRef: ERef<StorageNode | null>, childName: string): Promise<StorageNode>;
34
+ /**
35
+ * @import {ERef} from '@endo/far';
36
+ * @import {PassableCap} from '@endo/marshal';
37
+ * @import {TypedPattern} from './types.js';
38
+ */
39
+ /** @typedef {ReturnType<typeof import('@endo/marshal').makeMarshal>} Marshaller */
40
+ /** @typedef {Pick<Marshaller, 'fromCapData'>} Unserializer */
41
+ /**
42
+ * Defined by vstorageStoreKey in vstorage.go
43
+ *
44
+ * @typedef VStorageKey
45
+ * @property {string} storeName
46
+ * @property {string} storeSubkey
47
+ * @property {string} dataPrefixBytes
48
+ * @property {string} [noDataValue]
49
+ */
50
+ /**
51
+ * @template [T=unknown]
52
+ * @typedef StreamCell
53
+ * @property {string} blockHeight decimal representation of a natural number
54
+ * @property {T[]} values
55
+ */
56
+ /** @type {TypedPattern<StreamCell>} */
57
+ export const StreamCellShape: TypedPattern<StreamCell>;
45
58
  export function isStreamCell(cell: any): cell is StreamCell;
46
- export function assertCapData(data: unknown): asserts data is import("@endo/marshal").CapData<string>;
47
59
  /** @type {(name: string) => void} */
48
60
  export const assertPathSegment: (name: string) => void;
49
61
  export function prepareChainStorageNode(zone: import("@agoric/base-zone").Zone): (messenger: import("./types.js").Callback<(message: StorageMessage) => any>, path: string, args_2?: {
50
62
  sequence?: boolean | undefined;
51
63
  } | undefined) => import("@endo/exo").Guarded<{
52
64
  getPath(): string;
53
- /**
54
- * @deprecated use getPath
55
- * @type {() => Promise<VStorageKey>}
56
- */
57
65
  getStoreKey(): Promise<VStorageKey>;
58
- /**
59
- * @type {(
60
- * name: string,
61
- * childNodeOptions?: { sequence?: boolean },
62
- * ) => StorageNode}
63
- */
64
66
  makeChildNode(name: string, childNodeOptions?: {
65
67
  sequence?: boolean;
66
68
  }): StorageNode;
67
- /** @type {(value: string) => Promise<void>} */
68
69
  setValue(value: string): Promise<void>;
69
70
  }>;
70
71
  export function makeSerializeToStorage(storageNode: ERef<StorageNode>, marshaller: ERef<Marshaller>): (value: PassableCap) => Promise<void>;
@@ -165,5 +166,6 @@ export type StorageMessage = {
165
166
  args: StorageUpdateEntriesMessageArgs;
166
167
  };
167
168
  import type { ERef } from '@endo/far';
169
+ import type { TypedPattern } from './types.js';
168
170
  import type { PassableCap } from '@endo/marshal';
169
171
  //# sourceMappingURL=lib-chainStorage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lib-chainStorage.d.ts","sourceRoot":"","sources":["lib-chainStorage.js"],"names":[],"mappings":"AAyPA;;;;;;;;;;;;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;AAcD;;;;;;;;GAQG;AACH,qDAJW,KAAK,WAAW,OAAC,CAAC,aAClB,MAAM,GACJ,OAAO,CAAC,WAAW,CAAC,CAMhC;AApOM,mCAHI,GAAG,GACD,IAAI,IAAI,UAAU,CAOa;AASrC,oCAHI,OAAO,GACL,QAAQ,IAAI,IAAI,OAAO,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC,CAQnE;AAmBD,qCAAqC;AACrC,gCADW,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAI/B;AAyCK,8CAFI,OAAO,mBAAmB,EAAE,IAAI,uDAwBxB,cAAc,KAAK,GAAG;;;;IAenC;;;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;GA0BhD;AA+DM,oDAJI,KAAK,WAAW,CAAC,cACjB,KAAK,UAAU,C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/B,MAAM,MAAM;;;;iBAEZ,MAAM,OAAO,CAAC,WAAW,CAAC;mBAC1B,CACT,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,KAC7B,WAAW;;;;;;;aA8BL,MAAM,OAAO,CAAC,MAAM,CAAC;;;;iBAErB,WAAW,CAAC,aAAa,CAAC;;;;;qBAC1B,MAAM,YAAY;;;;;4CAqBnB,KAAK,GACX,aAAa,GACb,KAAK,GACL,UAAU,GACV,SAAS,GACT,QAAQ,GACR,MAAM;;;;gDAGA,KAAK,GAAG,kBAAkB,GAAG,QAAQ;;;;mCAGrC,6BAA6B,GACnC,iCAAiC;;;;0CAG3B,CAAC,IAAI,EAAE,MAAM,CAAC;;;;2BAEd,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;;;;8CAErC,YAAY,EAAE;;;;6BAEd;IACJ,MAAM,EAAE,6BAA6B,CAAC;IACtC,IAAI,EAAE,2BAA2B,CAAC;CACnC,GACD;IACE,MAAM,EAAE,iCAAiC,CAAC;IAC1C,IAAI,EAAE,+BAA+B,CAAC;CACvC;0BApIe,WAAW;kCAEH,YAAY;iCADb,eAAe"}
@@ -9,6 +9,7 @@ import * as cb from './callback.js';
9
9
  /**
10
10
  * @import {ERef} from '@endo/far';
11
11
  * @import {PassableCap} from '@endo/marshal';
12
+ * @import {TypedPattern} from './types.js';
12
13
  */
13
14
 
14
15
  /** @typedef {ReturnType<typeof import('@endo/marshal').makeMarshal>} Marshaller */
@@ -31,6 +32,12 @@ import * as cb from './callback.js';
31
32
  * @property {T[]} values
32
33
  */
33
34
 
35
+ /** @type {TypedPattern<StreamCell>} */
36
+ export const StreamCellShape = harden({
37
+ blockHeight: M.string(),
38
+ values: M.array(),
39
+ });
40
+
34
41
  /**
35
42
  * This represents a node in an IAVL tree.
36
43
  *
@@ -77,21 +84,6 @@ export const isStreamCell = cell =>
77
84
  /^0$|^[1-9][0-9]*$/.test(cell.blockHeight);
78
85
  harden(isStreamCell);
79
86
 
80
- // TODO: Consolidate with `insistCapData` functions from swingset-liveslots,
81
- // swingset-xsnap-supervisor, etc.
82
- /**
83
- * @param {unknown} data
84
- * @returns {asserts data is import('@endo/marshal').CapData<string>}
85
- */
86
- export const assertCapData = data => {
87
- assert.typeof(data, 'object');
88
- assert(data);
89
- assert.typeof(data.body, 'string');
90
- assert(Array.isArray(data.slots));
91
- // XXX check that the .slots array elements are actually strings
92
- };
93
- harden(assertCapData);
94
-
95
87
  /**
96
88
  * @typedef {object} StoredFacet
97
89
  * @property {() => Promise<string>} getPath the chain storage path at which the
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @import {ExecutionContext, Macro, TestFn} from 'ava';
3
+ */
4
+ export const AVA_EXPECT_UNHANDLED_REJECTIONS: "AGORIC_AVA_EXPECT_UNHANDLED_REJECTIONS";
5
+ export const SUBTEST_PREFIX: "(unhandled rejection subprocess): ";
6
+ export function makeExpectUnhandledRejection<C>({ test, importMetaUrl }: {
7
+ test: TestFn<C>;
8
+ importMetaUrl: string;
9
+ }): (expectedUnhandled: number) => Macro<[name: string, impl: (t: ExecutionContext<C>) => any], C>;
10
+ import type { TestFn } from 'ava';
11
+ import type { ExecutionContext } from 'ava';
12
+ import type { Macro } from 'ava';
13
+ //# sourceMappingURL=ava-unhandled-rejection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ava-unhandled-rejection.d.ts","sourceRoot":"","sources":["ava-unhandled-rejection.js"],"names":[],"mappings":"AAOA;;GAEG;AAEH,8CACE,wCAAwC,CAAC;AAE3C,6BAA8B,oCAAoC,CAAC;AAW5D,6CARM,CAAC,2BAEX;IAA0B,IAAI,EAAtB,OAAO,CAAC,CAAC;IACM,aAAa,EAA5B,MAAM;CACd,GAAU,CACR,iBAAiB,EAAE,MAAM,KACtB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CA0CtE;4BAzDiD,KAAK;sCAAL,KAAK;2BAAL,KAAK"}
@@ -0,0 +1,66 @@
1
+ // @ts-check
2
+ import { spawn } from 'child_process';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ import engineGC from './engine-gc.js';
6
+ import { makeGcAndFinalize } from './gc-and-finalize.js';
7
+
8
+ /**
9
+ * @import {ExecutionContext, Macro, TestFn} from 'ava';
10
+ */
11
+
12
+ export const AVA_EXPECT_UNHANDLED_REJECTIONS =
13
+ 'AGORIC_AVA_EXPECT_UNHANDLED_REJECTIONS';
14
+
15
+ export const SUBTEST_PREFIX = '(unhandled rejection subprocess): ';
16
+
17
+ /**
18
+ * @template C
19
+ * @param {object} powers
20
+ * @param {TestFn<C>} powers.test
21
+ * @param {string} powers.importMetaUrl
22
+ * @returns {(
23
+ * expectedUnhandled: number,
24
+ * ) => Macro<[name: string, impl: (t: ExecutionContext<C>) => any], C>}
25
+ */
26
+ export const makeExpectUnhandledRejection = ({ test, importMetaUrl }) => {
27
+ const self = fileURLToPath(importMetaUrl);
28
+ const gcAndFinalize = makeGcAndFinalize(engineGC);
29
+
30
+ if (process.env[AVA_EXPECT_UNHANDLED_REJECTIONS]) {
31
+ return _expectedUnhandled =>
32
+ test.macro({
33
+ title: (_, name, _impl) => SUBTEST_PREFIX + name,
34
+ exec: async (t, _name, impl) => {
35
+ await null;
36
+ try {
37
+ const result = await impl(t);
38
+ return result;
39
+ } finally {
40
+ await gcAndFinalize();
41
+ }
42
+ },
43
+ });
44
+ }
45
+
46
+ return expectedUnhandled =>
47
+ test.macro({
48
+ title: (_, name, _impl) => name,
49
+ exec: async (t, name, _impl) =>
50
+ new Promise((resolve, reject) => {
51
+ const ps = spawn('ava', [self, '-m', SUBTEST_PREFIX + name], {
52
+ env: {
53
+ ...process.env,
54
+ [AVA_EXPECT_UNHANDLED_REJECTIONS]: `${expectedUnhandled}`,
55
+ },
56
+ stdio: ['ignore', 'inherit', 'inherit', 'ignore'],
57
+ });
58
+
59
+ ps.on('close', code => {
60
+ t.is(code, 0, `got exit code ${code}, expected 0 for ${name}`);
61
+ resolve();
62
+ });
63
+ ps.on('error', reject);
64
+ }),
65
+ });
66
+ };
package/src/marshal.d.ts CHANGED
@@ -3,13 +3,24 @@ export function makeBoardRemote({ boardId, iface }: {
3
3
  iface?: string;
4
4
  }): BoardRemote;
5
5
  export function slotToBoardRemote(boardId: string, iface: string): BoardRemote;
6
- export function boardSlottingMarshaller(slotToVal?: ((slot: string, iface: string) => any) | undefined): Omit<import("@endo/marshal").Marshal<string | null>, "serialize" | "unserialize">;
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>;
7
12
  export function unmarshalFromVstorage(data: Map<string, string>, key: string, fromCapData: ReturnType<typeof import("@endo/marshal").makeMarshal>["fromCapData"], index: number): any;
8
- export function makeHistoryReviver(entries: [string, string][], slotToVal?: ((slot: string, iface?: string) => any) | undefined): {
13
+ export function makeHistoryReviver(entries: [string, string][], slotToVal?: (slot: string, iface?: string) => any): {
9
14
  getItem: (key: string) => any;
10
15
  children: (prefix: string) => string[];
11
16
  has: (k: string) => boolean;
12
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
+ };
13
24
  /**
14
25
  * Should be a union with Remotable, but that's `any`, making this type
15
26
  * meaningless
@@ -17,4 +28,6 @@ export function makeHistoryReviver(entries: [string, string][], slotToVal?: ((sl
17
28
  export type BoardRemote = {
18
29
  getBoardId: () => string | null;
19
30
  };
31
+ import type { CapData } from '@endo/marshal';
32
+ import type { TypedPattern } from './types.js';
20
33
  //# sourceMappingURL=marshal.d.ts.map
@@ -1 +1 @@
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"}
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"}
package/src/marshal.js CHANGED
@@ -2,8 +2,14 @@
2
2
  import { Fail } from '@endo/errors';
3
3
  import { Far } from '@endo/far';
4
4
  import { makeMarshal } from '@endo/marshal';
5
+ import { M } from '@endo/patterns';
5
6
  import { isStreamCell } from './lib-chainStorage.js';
6
7
 
8
+ /**
9
+ * @import {CapData} from '@endo/marshal';
10
+ * @import {TypedPattern} from './types.js';
11
+ */
12
+
7
13
  /**
8
14
  * Should be a union with Remotable, but that's `any`, making this type
9
15
  * meaningless
@@ -52,18 +58,24 @@ export const boardSlottingMarshaller = (slotToVal = undefined) => {
52
58
  });
53
59
  };
54
60
 
55
- // TODO: Consolidate with `insistCapData` functions from swingset-liveslots,
56
- // swingset-xsnap-supervisor, etc.
61
+ // TODO move CapDataShape to Endo
62
+ /**
63
+ * @type {TypedPattern<CapData<any>>}
64
+ */
65
+ export const CapDataShape = { body: M.string(), slots: M.array() };
66
+ harden(CapDataShape);
67
+
57
68
  /**
69
+ * Assert that this is CapData
70
+ *
58
71
  * @param {unknown} data
59
- * @returns {asserts data is import('@endo/marshal').CapData<string>}
72
+ * @returns {asserts data is CapData<unknown>}
60
73
  */
61
- const assertCapData = data => {
74
+ export const assertCapData = data => {
62
75
  assert.typeof(data, 'object');
63
76
  assert(data);
64
- assert.typeof(data.body, 'string');
65
- assert(Array.isArray(data.slots));
66
- // XXX check that the .slots array elements are actually strings
77
+ typeof data.body === 'string' || Fail`data has non-string .body ${data.body}`;
78
+ Array.isArray(data.slots) || Fail`data has non-Array slots ${data.slots}`;
67
79
  };
68
80
  harden(assertCapData);
69
81
 
@@ -135,3 +147,10 @@ export const makeHistoryReviver = (entries, slotToVal = undefined) => {
135
147
 
136
148
  return harden({ getItem, children, has });
137
149
  };
150
+
151
+ /** @param {import('@endo/marshal').CapData<unknown>} cap */
152
+ const rejectOCap = cap => Fail`${cap} is not pure data`;
153
+ export const pureDataMarshaller = makeMarshal(rejectOCap, rejectOCap, {
154
+ serializeBodyFormat: 'smallcaps',
155
+ });
156
+ harden(pureDataMarshaller);
@@ -1 +1 @@
1
- {"version":3,"file":"method-tools.d.ts","sourceRoot":"","sources":["method-tools.js"],"names":[],"mappings":"AA0CO,+BAJoB,CAAC,SAAd,WAAY,OACf,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,GACZ,CAAC,EAAE,CAsBf;AAUM,qCAJoB,CAAC,SAAd,WAAY,OACf,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,GACZ,MAAM,EAAE,CAKlB;AA+BI,+BAJiC,CAAC,SAA3B,MAAM,CAAC,WAAW,EAAE,GAAG,CAAE,OAC5B,CAAC,GACC,CAAC,CAiBX"}
1
+ {"version":3,"file":"method-tools.d.ts","sourceRoot":"","sources":["method-tools.js"],"names":[],"mappings":"AAmBO,+BAJoB,CAAC,SAAd,WAAY,OACf,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,GACZ,CAAC,EAAE,CAG8B;AAUvC,qCAJoB,CAAC,SAAd,WAAY,OACf,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,GACZ,MAAM,EAAE,CAKlB;AA+BI,+BAJiC,CAAC,SAA3B,MAAM,CAAC,WAAW,EAAE,GAAG,CAAE,OAC5B,CAAC,GACC,CAAC,CAiBX"}
@@ -1,66 +1,24 @@
1
1
  // @ts-check
2
- import { isObject } from '@endo/marshal';
2
+ import { getMethodNames as realGetMethodNames } from '@endo/eventual-send/utils.js';
3
3
 
4
4
  /**
5
5
  * @file method-tools use dynamic property lookup, which is not
6
6
  * Jessie-compatible
7
7
  */
8
8
 
9
- const { getPrototypeOf, create, fromEntries, getOwnPropertyDescriptors } =
10
- Object;
11
- const { ownKeys, apply } = Reflect;
12
-
13
- /**
14
- * Prioritize symbols as earlier than strings.
15
- *
16
- * @param {string | symbol} a
17
- * @param {string | symbol} b
18
- * @returns {-1 | 0 | 1}
19
- */
20
- const compareStringified = (a, b) => {
21
- if (typeof a === typeof b) {
22
- const left = String(a);
23
- const right = String(b);
24
- // eslint-disable-next-line no-nested-ternary
25
- return left < right ? -1 : left > right ? 1 : 0;
26
- }
27
- if (typeof a === 'symbol') {
28
- assert(typeof b === 'string');
29
- return -1;
30
- }
31
- assert(typeof a === 'string');
32
- assert(typeof b === 'symbol');
33
- return 1;
34
- };
9
+ const { create, fromEntries } = Object;
10
+ const { apply } = Reflect;
35
11
 
36
12
  /**
37
13
  * TODO Consolidate with the `getMethodNames` in `@endo/eventual-send`
38
14
  *
15
+ * @deprecated Use `getMethodNames` from `@endo/eventual-send/utils.js` instead.
39
16
  * @template {PropertyKey} K
40
17
  * @param {Record<K, any>} val
41
18
  * @returns {K[]}
42
19
  */
43
- export const getMethodNames = val => {
44
- let layer = val;
45
- const names = new Set(); // Set to deduplicate
46
- while (layer !== null && layer !== Object.prototype) {
47
- // be tolerant of non-objects
48
- const descs = getOwnPropertyDescriptors(layer);
49
- const ownNames = /** @type {K[]} */ (ownKeys(descs));
50
- for (const name of ownNames) {
51
- // In case a method is overridden by a non-method,
52
- // test `val[name]` rather than `layer[name]`
53
- if (typeof val[name] === 'function') {
54
- names.add(name);
55
- }
56
- }
57
- if (!isObject(val)) {
58
- break;
59
- }
60
- layer = getPrototypeOf(layer);
61
- }
62
- return harden([...names].sort(compareStringified));
63
- };
20
+ export const getMethodNames = val =>
21
+ /** @type {K[]} */ (realGetMethodNames(val));
64
22
  harden(getMethodNames);
65
23
 
66
24
  /**
@@ -72,7 +30,7 @@ harden(getMethodNames);
72
30
  */
73
31
  export const getStringMethodNames = val =>
74
32
  /** @type {string[]} */ (
75
- getMethodNames(val).filter(name => typeof name === 'string')
33
+ realGetMethodNames(val).filter(name => typeof name === 'string')
76
34
  );
77
35
 
78
36
  /**
@@ -109,7 +67,7 @@ export const bindAllMethods = obj =>
109
67
  create(
110
68
  obj,
111
69
  fromEntries(
112
- getMethodNames(obj).map(name => [
70
+ realGetMethodNames(obj).map(name => [
113
71
  name,
114
72
  {
115
73
  value: (/** @type {unknown[]} */ ...args) =>