@agoric/internal 0.4.0-u17.1 → 0.4.0-u18.1

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 (58) hide show
  1. package/README.md +4 -4
  2. package/package.json +17 -16
  3. package/src/action-types.d.ts +49 -5
  4. package/src/action-types.d.ts.map +1 -1
  5. package/src/action-types.js +72 -14
  6. package/src/batched-deliver.d.ts.map +1 -1
  7. package/src/callback.d.ts +1 -1
  8. package/src/callback.d.ts.map +1 -1
  9. package/src/chain-storage-paths.d.ts.map +1 -1
  10. package/src/chain-utils.d.ts +25 -0
  11. package/src/chain-utils.d.ts.map +1 -0
  12. package/src/chain-utils.js +57 -0
  13. package/src/config.d.ts +4 -1
  14. package/src/config.d.ts.map +1 -1
  15. package/src/config.js +2 -1
  16. package/src/errors.d.ts +1 -1
  17. package/src/errors.d.ts.map +1 -1
  18. package/src/index.d.ts +4 -2
  19. package/src/index.js +4 -2
  20. package/src/js-utils.d.ts +7 -0
  21. package/src/js-utils.d.ts.map +1 -0
  22. package/src/js-utils.js +89 -0
  23. package/src/lib-chainStorage.d.ts +1 -23
  24. package/src/lib-chainStorage.d.ts.map +1 -1
  25. package/src/lib-chainStorage.js +5 -2
  26. package/src/lib-nodejs/engine-gc.d.ts +1 -1
  27. package/src/lib-nodejs/worker-protocol.js +1 -1
  28. package/src/marshal.d.ts +8 -2
  29. package/src/marshal.d.ts.map +1 -1
  30. package/src/marshal.js +7 -0
  31. package/src/netstring.d.ts +2 -2
  32. package/src/netstring.d.ts.map +1 -1
  33. package/src/netstring.js +2 -1
  34. package/src/node/buffer-line-transform.d.ts +3 -3
  35. package/src/node/buffer-line-transform.d.ts.map +1 -1
  36. package/src/node/buffer-line-transform.js +1 -1
  37. package/src/node/createBundles.js +1 -1
  38. package/src/node/fs-stream.d.ts +1 -1
  39. package/src/node/fs-stream.d.ts.map +1 -1
  40. package/src/node/fs-stream.js +42 -29
  41. package/src/node/shutdown.d.ts.map +1 -1
  42. package/src/node/shutdown.js +0 -1
  43. package/src/{utils.d.ts → ses-utils.d.ts} +1 -7
  44. package/src/ses-utils.d.ts.map +1 -0
  45. package/src/{utils.js → ses-utils.js} +8 -72
  46. package/src/storage-test-utils.d.ts +14 -4
  47. package/src/storage-test-utils.d.ts.map +1 -1
  48. package/src/storage-test-utils.js +128 -79
  49. package/src/tokens.d.ts.map +1 -1
  50. package/src/types-index.d.ts +1 -0
  51. package/src/types.d.ts +25 -59
  52. package/src/types.d.ts.map +1 -0
  53. package/src/types.ts +108 -0
  54. package/src/upgrade-api.d.ts +1 -0
  55. package/src/upgrade-api.d.ts.map +1 -1
  56. package/src/upgrade-api.js +25 -1
  57. package/src/utils.d.ts.map +0 -1
  58. /package/src/{types.js → types-index.js} +0 -0
@@ -2,9 +2,10 @@
2
2
  import { Fail } from '@endo/errors';
3
3
  import { Far } from '@endo/far';
4
4
  import { makeMarshal, Remotable } from '@endo/marshal';
5
- import { unmarshalFromVstorage } from './marshal.js';
6
5
  import { makeTracer } from './debug.js';
6
+ import { NonNullish } from './errors.js';
7
7
  import { isStreamCell, makeChainStorageRoot } from './lib-chainStorage.js';
8
+ import { unmarshalFromVstorage } from './marshal.js';
8
9
  import { bindAllMethods } from './method-tools.js';
9
10
  import { eventLoopIteration } from './testing-utils.js';
10
11
 
@@ -33,6 +34,16 @@ export const defaultMarshaller = makeMarshal(undefined, slotToRemotable, {
33
34
  serializeBodyFormat: 'smallcaps',
34
35
  });
35
36
 
37
+ /**
38
+ * Serialize/deserialize functions using {@link defaultMarshaller}
39
+ */
40
+ export const defaultSerializer = {
41
+ /** @type {(text: string) => unknown} */
42
+ parse: txt => defaultMarshaller.fromCapData(JSON.parse(txt)),
43
+ /** @type {(obj: any) => string} */
44
+ stringify: obj => JSON.stringify(defaultMarshaller.toCapData(obj)),
45
+ };
46
+
36
47
  /**
37
48
  * A deserializer which produces slot strings instead of Remotables, so if `a =
38
49
  * Far('iface')`, and serializing `{ a }` into `capData` assigned it slot
@@ -108,87 +119,107 @@ export const makeFakeStorageKit = (rootPath, rootOptions) => {
108
119
  };
109
120
  /** @type {StorageMessage[]} */
110
121
  const messages = [];
111
- /** @param {StorageMessage} message */
112
122
 
113
- const toStorage = message => {
114
- messages.push(message);
115
- switch (message.method) {
116
- case 'getStoreKey': {
117
- const [key] = message.args;
118
- return { storeName: 'swingset', storeSubkey: `fake:${key}` };
119
- }
120
- case 'get': {
121
- const [key] = message.args;
122
- return data.has(key) ? data.get(key) : null;
123
- }
124
- case 'children': {
125
- const [key] = message.args;
126
- const childEntries = getChildEntries(`${key}.`);
127
- return [...childEntries.keys()];
128
- }
129
- case 'entries': {
130
- const [key] = message.args;
131
- const childEntries = getChildEntries(`${key}.`);
132
- return [...childEntries.entries()].map(entry =>
133
- entry[1] != null ? entry : [entry[0]],
134
- );
135
- }
136
- case 'set':
137
- case 'setWithoutNotify': {
138
- trace('toStorage set', message);
139
- /** @type {StorageEntry[]} */
140
- const newEntries = message.args;
141
- for (const [key, value] of newEntries) {
142
- if (value != null) {
143
- data.set(key, value);
144
- } else {
145
- data.delete(key);
146
- }
123
+ const toStorage = Far(
124
+ 'ToStorage',
125
+ /** @param {StorageMessage} message */
126
+ message => {
127
+ messages.push(message);
128
+ switch (message.method) {
129
+ case 'getStoreKey': {
130
+ const [key] = message.args;
131
+ return { storeName: 'swingset', storeSubkey: `fake:${key}` };
147
132
  }
148
- break;
149
- }
150
- case 'append': {
151
- trace('toStorage append', message);
152
- /** @type {StorageEntry[]} */
153
- const newEntries = message.args;
154
- for (const [key, value] of newEntries) {
155
- value != null || Fail`attempt to append with no value`;
156
- // In the absence of block boundaries, everything goes in a single StreamCell.
157
- const oldVal = data.get(key);
158
- let streamCell;
159
- if (oldVal != null) {
160
- try {
161
- streamCell = JSON.parse(oldVal);
162
- assert(isStreamCell(streamCell));
163
- } catch (_err) {
164
- streamCell = undefined;
133
+ case 'get': {
134
+ const [key] = message.args;
135
+ return data.has(key) ? data.get(key) : null;
136
+ }
137
+ case 'children': {
138
+ const [key] = message.args;
139
+ const childEntries = getChildEntries(`${key}.`);
140
+ return [...childEntries.keys()];
141
+ }
142
+ case 'entries': {
143
+ const [key] = message.args;
144
+ const childEntries = getChildEntries(`${key}.`);
145
+ return [...childEntries.entries()].map(entry =>
146
+ entry[1] != null ? entry : [entry[0]],
147
+ );
148
+ }
149
+ case 'set':
150
+ case 'setWithoutNotify': {
151
+ trace('toStorage set', message);
152
+ /** @type {StorageEntry[]} */
153
+ const newEntries = message.args;
154
+ for (const [key, value] of newEntries) {
155
+ if (value != null) {
156
+ data.set(key, value);
157
+ } else {
158
+ data.delete(key);
165
159
  }
166
160
  }
167
- if (streamCell === undefined) {
168
- streamCell = {
169
- blockHeight: '0',
170
- values: oldVal != null ? [oldVal] : [],
171
- };
161
+ break;
162
+ }
163
+ case 'append': {
164
+ trace('toStorage append', message);
165
+ /** @type {StorageEntry[]} */
166
+ const newEntries = message.args;
167
+ for (const [key, value] of newEntries) {
168
+ value != null || Fail`attempt to append with no value`;
169
+ // In the absence of block boundaries, everything goes in a single StreamCell.
170
+ const oldVal = data.get(key);
171
+ let streamCell;
172
+ if (oldVal != null) {
173
+ try {
174
+ streamCell = JSON.parse(oldVal);
175
+ assert(isStreamCell(streamCell));
176
+ } catch (_err) {
177
+ streamCell = undefined;
178
+ }
179
+ }
180
+ if (streamCell === undefined) {
181
+ streamCell = {
182
+ blockHeight: '0',
183
+ values: oldVal != null ? [oldVal] : [],
184
+ };
185
+ }
186
+ streamCell.values.push(value);
187
+ data.set(key, JSON.stringify(streamCell));
172
188
  }
173
- streamCell.values.push(value);
174
- data.set(key, JSON.stringify(streamCell));
189
+ break;
175
190
  }
176
- break;
191
+ case 'size':
192
+ // Intentionally incorrect because it counts non-child descendants,
193
+ // but nevertheless supports a "has children" test.
194
+ return [...data.keys()].filter(k =>
195
+ k.startsWith(`${message.args[0]}.`),
196
+ ).length;
197
+ default:
198
+ throw Error(`unsupported method: ${message.method}`);
177
199
  }
178
- case 'size':
179
- // Intentionally incorrect because it counts non-child descendants,
180
- // but nevertheless supports a "has children" test.
181
- return [...data.keys()].filter(k => k.startsWith(`${message.args[0]}.`))
182
- .length;
183
- default:
184
- throw Error(`unsupported method: ${message.method}`);
185
- }
186
- };
200
+ },
201
+ );
187
202
  const rootNode = makeChainStorageRoot(toStorage, rootPath, resolvedOptions);
203
+
204
+ /**
205
+ * Get the values at a sequence node
206
+ *
207
+ * @param {string} path
208
+ * @returns {string[]}
209
+ */
210
+ const getValues = path => {
211
+ assert(resolvedOptions.sequence);
212
+ const nodeData = data.get(path);
213
+ assert(nodeData, `no data at path ${path}`);
214
+ const wrapper = JSON.parse(nodeData);
215
+ return wrapper.values;
216
+ };
217
+
188
218
  return {
189
219
  rootNode,
190
220
  // eslint-disable-next-line object-shorthand
191
221
  data: /** @type {Map<string, string>} */ (data),
222
+ getValues,
192
223
  messages,
193
224
  toStorage,
194
225
  };
@@ -246,30 +277,48 @@ export const makeMockChainStorageRoot = () => {
246
277
  * @param {import('ava').ExecutionContext<unknown>} t
247
278
  * @param {MockChainStorageRoot | FakeStorageKit} storage
248
279
  * @param {({ note: string } | { node: string; owner: string }) &
249
- * ({ pattern: string; replacement: string } | {})} opts
280
+ * ({ pattern: string; replacement: string } | {}) & {
281
+ * showValue?: (v: string) => unknown;
282
+ * }} opts
250
283
  */
251
284
  export const documentStorageSchema = async (t, storage, opts) => {
252
285
  // chainStorage publication is unsynchronized
253
286
  await eventLoopIteration();
254
287
 
288
+ const getLast = (/** @type {string} */ cell) =>
289
+ JSON.parse(cell).values.at(-1) || assert.fail();
290
+ const { showValue = s => s } = opts;
291
+ /** @type {(d: Map<string, string>, k: string) => unknown} */
292
+ const getBodyDefault = (d, k) => showValue(getLast(NonNullish(d.get(k))));
293
+
255
294
  const [keys, getBody] =
256
295
  'keys' in storage
257
296
  ? [storage.keys(), (/** @type {string} */ k) => storage.getBody(k)]
258
- : [storage.data.keys(), (/** @type {string} */ k) => storage.data.get(k)];
297
+ : [
298
+ storage.data.keys(),
299
+ (/** @type {string} */ k) => getBodyDefault(storage.data, k),
300
+ ];
259
301
 
260
302
  const { pattern, replacement } =
261
303
  'pattern' in opts
262
304
  ? opts
263
305
  : { pattern: 'mockChainStorageRoot.', replacement: 'published.' };
264
- const illustration = [...keys].sort().map(
306
+
307
+ const pruned = [...keys]
308
+ .sort()
309
+ .filter(
310
+ 'node' in opts
311
+ ? key =>
312
+ key
313
+ .replace(pattern, replacement)
314
+ .startsWith(`published.${opts.node}`)
315
+ : _entry => true,
316
+ );
317
+
318
+ const illustration = pruned.map(
265
319
  /** @type {(k: string) => [string, unknown]} */
266
320
  key => [key.replace(pattern, replacement), getBody(key)],
267
321
  );
268
- const pruned = illustration.filter(
269
- 'node' in opts
270
- ? ([key, _]) => key.startsWith(`published.${opts.node}`)
271
- : _entry => true,
272
- );
273
322
 
274
323
  const note =
275
324
  'note' in opts
@@ -279,5 +328,5 @@ export const documentStorageSchema = async (t, storage, opts) => {
279
328
  The example below illustrates the schema of the data published there.
280
329
 
281
330
  See also board marshalling conventions (_to appear_).`;
282
- t.snapshot(pruned, note + boilerplate);
331
+ t.snapshot(illustration, note + boilerplate);
283
332
  };
@@ -1 +1 @@
1
- {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["tokens.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;2BAEc,KAAK,GAAG,KAAK;AAA3B,4CAA4C;AAE5C;;;GAGG;AACH,yBAAkB"}
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["tokens.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;2BAEc,KAAK,GAAG,KAAK;AAA3B,4CAA4C;AAE5C;;;GAGG;AACH,mBAAY,KAAK,CAAC"}
@@ -0,0 +1 @@
1
+ export type * from './types.js';
package/src/types.d.ts CHANGED
@@ -1,39 +1,27 @@
1
- /* eslint-disable max-classes-per-file */
2
1
  import type { ERef, RemotableBrand } from '@endo/eventual-send';
3
2
  import type { Primitive } from '@endo/pass-style';
4
- import type { Callable } from './utils.js';
5
-
3
+ import type { Pattern } from '@endo/patterns';
4
+ import type { Callable } from './ses-utils.js';
6
5
  /**
7
6
  * A map corresponding with a total function such that `get(key)` is assumed to
8
7
  * always succeed.
9
8
  */
10
9
  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;
10
+ /** Returns the element associated with the specified key in the TotalMap. */
11
+ get: (key: K) => V;
13
12
  };
14
- export type TotalMapFrom<M extends Map> =
15
- M extends Map<infer K, infer V> ? TotalMap<K, V> : never;
16
-
13
+ export type TotalMapFrom<M extends Map<any, any>> = M extends Map<infer K, infer V> ? TotalMap<K, V> : never;
17
14
  export declare class Callback<I extends (...args: any[]) => any> {
18
- private iface: I;
19
-
20
- public target: any;
21
-
22
- public methodName?: PropertyKey;
23
-
24
- public bound: unknown[];
25
-
26
- public isSync: boolean;
15
+ private iface;
16
+ target: any;
17
+ methodName?: PropertyKey;
18
+ bound: unknown[];
19
+ isSync: boolean;
27
20
  }
28
-
29
- export declare class SyncCallback<
30
- I extends (...args: unknown[]) => any,
31
- > extends Callback<I> {
32
- private syncIface: I;
33
-
34
- public isSync: true;
21
+ export declare class SyncCallback<I extends (...args: unknown[]) => any> extends Callback<I> {
22
+ private syncIface;
23
+ isSync: true;
35
24
  }
36
-
37
25
  /**
38
26
  Returns a boolean for whether the given type is primitive value or primitive type.
39
27
 
@@ -50,48 +38,28 @@ IsPrimitive<Object>
50
38
  ```
51
39
  */
52
40
  export type IsPrimitive<T> = [T] extends [Primitive] ? true : false;
53
-
54
41
  /** Recursively extract the non-callable properties of T */
55
- export type DataOnly<T> =
56
- IsPrimitive<T> extends true
57
- ? T
58
- : T extends Callable
59
- ? never
60
- : { [P in keyof T as T[P] extends Callable ? never : P]: DataOnly<T[P]> };
61
-
42
+ export type DataOnly<T> = IsPrimitive<T> extends true ? T : T extends Callable ? never : {
43
+ [P in keyof T as T[P] extends Callable ? never : P]: DataOnly<T[P]>;
44
+ };
62
45
  /**
63
46
  * A type that doesn't assume its parameter is local, but is satisfied with both
64
47
  * local and remote references. It accepts both near and marshalled references
65
48
  * that were returned from `Remotable` or `Far`.
66
49
  */
67
- export type Remote<Primary, Local = DataOnly<Primary>> =
68
- | Primary
69
- | RemotableBrand<Local, Primary>;
70
-
71
- // TODO: Add type tests for FarRef and Remote.
50
+ export type Remote<Primary, Local = DataOnly<Primary>> = Primary | RemotableBrand<Local, Primary>;
72
51
  /**
73
52
  * Potentially remote promises or settled references.
74
53
  */
75
- export type FarRef<Primary, Local = DataOnly<Primary>> = ERef<
76
- Remote<Primary, Local>
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
- */
54
+ export type FarRef<Primary, Local = DataOnly<Primary>> = ERef<Remote<Primary, Local>>;
85
55
  declare const validatedType: unique symbol;
86
56
  /**
87
57
  * Tag a pattern with the static type it represents.
88
58
  */
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
59
+ export type TypedPattern<T> = Pattern & {
60
+ [validatedType]?: T;
61
+ };
62
+ export declare type PatternType<TM extends TypedPattern<any>> = TM extends TypedPattern<infer T> ? T : never;
95
63
  /**
96
64
  * Returning normally indicates success. Match failure is indicated by
97
65
  * throwing.
@@ -100,8 +68,6 @@ export declare type PatternType<TM extends TypedPattern<any>> =
100
68
  *
101
69
  * @see {import('@endo/patterns').mustMatch} for the implementation. This one has a type annotation to narrow if the pattern is a TypedPattern.
102
70
  */
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;
71
+ export declare type MustMatch = <P extends Pattern>(specimen: unknown, pattern: P, label?: string | number) => asserts specimen is P extends TypedPattern<any> ? PatternType<P> : unknown;
72
+ export {};
73
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG;IACpD,6EAA6E;IAC7E,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;CACpB,CAAC;AACF,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,IAC9C,CAAC,SAAS,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC;AAE3D,MAAM,CAAC,OAAO,OAAO,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG;IAC7D,OAAO,CAAC,KAAK,CAAI;IAEV,MAAM,EAAE,GAAG,CAAC;IAEZ,UAAU,CAAC,EAAE,WAAW,CAAC;IAEzB,KAAK,EAAE,OAAO,EAAE,CAAC;IAEjB,MAAM,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,CAAC,OAAO,OAAO,YAAY,CAC/B,CAAC,SA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G,CAAC,GAAG,KAAK,CAAC;AAG/C;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,MAAM,SAAS,GAAG,CAAC,CAAC,SAAS,OAAO,EAChD,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,CAAC,EACV,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,KACpB,OAAO,CAAC,QAAQ,IAAI,CAAC,SAAS,YAAY,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC"}
package/src/types.ts ADDED
@@ -0,0 +1,108 @@
1
+ /* eslint-disable max-classes-per-file */
2
+ import type { ERef, RemotableBrand } from '@endo/eventual-send';
3
+ import type { Primitive } from '@endo/pass-style';
4
+ import type { Pattern } from '@endo/patterns';
5
+ import type { Callable } from './ses-utils.js';
6
+
7
+ /**
8
+ * A map corresponding with a total function such that `get(key)` is assumed to
9
+ * always succeed.
10
+ */
11
+ export type TotalMap<K, V> = Omit<Map<K, V>, 'get'> & {
12
+ /** Returns the element associated with the specified key in the TotalMap. */
13
+ get: (key: K) => V;
14
+ };
15
+ export type TotalMapFrom<M extends Map<any, any>> =
16
+ M extends Map<infer K, infer V> ? TotalMap<K, V> : never;
17
+
18
+ export declare class Callback<I extends (...args: any[]) => any> {
19
+ private iface: I;
20
+
21
+ public target: any;
22
+
23
+ public methodName?: PropertyKey;
24
+
25
+ public bound: unknown[];
26
+
27
+ public isSync: boolean;
28
+ }
29
+
30
+ export declare class SyncCallback<
31
+ I extends (...args: unknown[]) => any,
32
+ > extends Callback<I> {
33
+ private syncIface: I;
34
+
35
+ public isSync: true;
36
+ }
37
+
38
+ /**
39
+ Returns a boolean for whether the given type is primitive value or primitive type.
40
+
41
+ @example
42
+ ```
43
+ IsPrimitive<'string'>
44
+ //=> true
45
+
46
+ IsPrimitive<string>
47
+ //=> true
48
+
49
+ IsPrimitive<Object>
50
+ //=> false
51
+ ```
52
+ */
53
+ export type IsPrimitive<T> = [T] extends [Primitive] ? true : false;
54
+
55
+ /** Recursively extract the non-callable properties of T */
56
+ export type DataOnly<T> =
57
+ IsPrimitive<T> extends true
58
+ ? T
59
+ : T extends Callable
60
+ ? never
61
+ : { [P in keyof T as T[P] extends Callable ? never : P]: DataOnly<T[P]> };
62
+
63
+ /**
64
+ * A type that doesn't assume its parameter is local, but is satisfied with both
65
+ * local and remote references. It accepts both near and marshalled references
66
+ * that were returned from `Remotable` or `Far`.
67
+ */
68
+ export type Remote<Primary, Local = DataOnly<Primary>> =
69
+ | Primary
70
+ | RemotableBrand<Local, Primary>;
71
+
72
+ // TODO: Add type tests for FarRef and Remote.
73
+ /**
74
+ * Potentially remote promises or settled references.
75
+ */
76
+ export type FarRef<Primary, Local = DataOnly<Primary>> = ERef<
77
+ Remote<Primary, Local>
78
+ >;
79
+
80
+ /*
81
+ * Stop-gap until https://github.com/Agoric/agoric-sdk/issues/6160
82
+ * explictly specify the type that the Pattern will verify through a match.
83
+ *
84
+ * TODO move all this pattern typing stuff to @endo/patterns
85
+ */
86
+ declare const validatedType: unique symbol;
87
+ /**
88
+ * Tag a pattern with the static type it represents.
89
+ */
90
+ export type TypedPattern<T> = Pattern & { [validatedType]?: T };
91
+
92
+ export declare type PatternType<TM extends TypedPattern<any>> =
93
+ TM extends TypedPattern<infer T> ? T : never;
94
+
95
+ // TODO make Endo's mustMatch do this
96
+ /**
97
+ * Returning normally indicates success. Match failure is indicated by
98
+ * throwing.
99
+ *
100
+ * Note: remotables can only be matched as "remotable", not the specific kind.
101
+ *
102
+ * @see {import('@endo/patterns').mustMatch} for the implementation. This one has a type annotation to narrow if the pattern is a TypedPattern.
103
+ */
104
+ export declare type MustMatch = <P extends Pattern>(
105
+ specimen: unknown,
106
+ pattern: P,
107
+ label?: string | number,
108
+ ) => asserts specimen is P extends TypedPattern<any> ? PatternType<P> : unknown;
@@ -5,6 +5,7 @@ export namespace UpgradeDisconnectionShape {
5
5
  }
6
6
  export function makeUpgradeDisconnection(upgradeMessage: string, toIncarnationNumber: number): UpgradeDisconnection;
7
7
  export function isUpgradeDisconnection(reason: any): reason is UpgradeDisconnection;
8
+ export function isAbandonedError(reason: any): reason is Error;
8
9
  /**
9
10
  * An Error-like object for use as the rejection reason of promises abandoned by
10
11
  * upgrade.
@@ -1 +1 @@
1
- {"version":3,"file":"upgrade-api.d.ts","sourceRoot":"","sources":["upgrade-api.js"],"names":[],"mappings":";;;;;AAgCO,yDAJI,MAAM,uBACN,MAAM,GACJ,oBAAoB,CAO7B;AASG,+CALI,GAAG,GAGD,MAAM,IAAI,oBAAoB,CAGqB;;;;;mCApCnD;IACZ,IAAQ,EAAE,aAAa,CAAC;IACxB,cAAkB,EAAE,MAAM,CAAC;IAC3B,iBAAqB,EAAE,MAAM,CAAC;CAC3B"}
1
+ {"version":3,"file":"upgrade-api.d.ts","sourceRoot":"","sources":["upgrade-api.js"],"names":[],"mappings":";;;;;AAgCO,yDAJI,MAAM,uBACN,MAAM,GACJ,oBAAoB,CAO7B;AASG,+CALI,GAAG,GAGD,MAAM,IAAI,oBAAoB,CAKC;AAgBrC,yCAHI,GAAG,GACD,MAAM,IAAI,KAAK,CAQS;;;;;mCA5DxB;IACR,IAAI,EAAE,aAAa,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;CAC3B"}
@@ -45,5 +45,29 @@ harden(makeUpgradeDisconnection);
45
45
  * @returns {reason is UpgradeDisconnection}
46
46
  */
47
47
  export const isUpgradeDisconnection = reason =>
48
- isFrozen(reason) && matches(reason, UpgradeDisconnectionShape);
48
+ reason != null && // eslint-disable-line eqeqeq
49
+ isFrozen(reason) &&
50
+ matches(reason, UpgradeDisconnectionShape);
49
51
  harden(isUpgradeDisconnection);
52
+
53
+ /**
54
+ * Returns whether a reason is a 'vat terminated' error generated when an object
55
+ * is abandoned by a vat during an upgrade.
56
+ *
57
+ * Normally we do not want to rely on the `message` of an error object, but this
58
+ * is a pragmatic solution to the current state of vat upgrade errors. In the
59
+ * future we'd prefer having an error with a cause referencing a disconnection
60
+ * object like for promise rejections. See
61
+ * https://github.com/Agoric/agoric-sdk/issues/9582
62
+ *
63
+ * @param {any} reason
64
+ * @returns {reason is Error}
65
+ */
66
+ export const isAbandonedError = reason =>
67
+ reason != null && // eslint-disable-line eqeqeq
68
+ isFrozen(reason) &&
69
+ matches(reason, M.error()) &&
70
+ // We're not using a constant here since this special value is already
71
+ // sprinkled throughout the SDK
72
+ reason.message === 'vat terminated';
73
+ harden(isAbandonedError);
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.js"],"names":[],"mappings":"AAWA,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;AAgDK,mCAJI,MAAM,UACN,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,GAAG,GAC/C,MAAM,CAGuC;AAsBnD,mCAJM,CAAC,SACH,SAAS,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,GAC7B,OAAO,CAAC,CAAC,EAAE,CAAC,CAiBxB;AAQM,oCALM,CAAC,SACH,MAAM,OAAO,CAAC,CAAC,CAAC,aAChB,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,GACnC,UAAU,OAFN,OAAO,CAAC,CAAC,CAAC,CAEG,CAY3B;AAWI,oCANM,CAAC,MACH,CACV,UAAc,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,KACvD,OAAO,CAAC,CAAC,CAAC,GACL,UAAU,cAFN,C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