@agoric/vat-data 0.5.3-mainnet1B-dev-b0c1f78.0 → 0.5.3-orchestration-dev-096c4e8.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/CHANGELOG.md CHANGED
@@ -3,38 +3,6 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ### [0.5.3-u13.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.5.3-u12.0...@agoric/vat-data@0.5.3-u13.0) (2023-12-07)
7
-
8
- **Note:** Version bump only for package @agoric/vat-data
9
-
10
-
11
-
12
-
13
-
14
- ### [0.5.3-u12.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.5.3-u11wf.0...@agoric/vat-data@0.5.3-u12.0) (2023-11-10)
15
-
16
- **Note:** Version bump only for package @agoric/vat-data
17
-
18
-
19
-
20
-
21
-
22
- ### [0.5.3-u11wf.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.5.3-u11.0...@agoric/vat-data@0.5.3-u11wf.0) (2023-09-23)
23
-
24
- **Note:** Version bump only for package @agoric/vat-data
25
-
26
-
27
-
28
-
29
-
30
- ### [0.5.3-u11.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.5.2...@agoric/vat-data@0.5.3-u11.0) (2023-08-24)
31
-
32
- **Note:** Version bump only for package @agoric/vat-data
33
-
34
-
35
-
36
-
37
-
38
6
  ### [0.5.2](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.5.1...@agoric/vat-data@0.5.2) (2023-06-02)
39
7
 
40
8
  **Note:** Version bump only for package @agoric/vat-data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/vat-data",
3
- "version": "0.5.3-mainnet1B-dev-b0c1f78.0+b0c1f78",
3
+ "version": "0.5.3-orchestration-dev-096c4e8.0+096c4e8",
4
4
  "description": "Safe access to VatData global",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/Agoric/agoric-sdk",
@@ -19,14 +19,27 @@
19
19
  "author": "Agoric",
20
20
  "license": "Apache-2.0",
21
21
  "dependencies": {
22
- "@agoric/assert": "0.6.1-mainnet1B-dev-b0c1f78.0+b0c1f78",
23
- "@agoric/internal": "0.4.0-mainnet1B-dev-b0c1f78.0+b0c1f78",
24
- "@agoric/store": "0.9.3-mainnet1B-dev-b0c1f78.0+b0c1f78"
22
+ "@agoric/assert": "0.6.1-orchestration-dev-096c4e8.0+096c4e8",
23
+ "@agoric/base-zone": "0.1.1-orchestration-dev-096c4e8.0+096c4e8",
24
+ "@agoric/internal": "0.3.3-orchestration-dev-096c4e8.0+096c4e8",
25
+ "@agoric/store": "0.9.3-orchestration-dev-096c4e8.0+096c4e8",
26
+ "@agoric/swingset-liveslots": "0.10.3-orchestration-dev-096c4e8.0+096c4e8",
27
+ "@agoric/vow": "0.1.1-orchestration-dev-096c4e8.0+096c4e8"
25
28
  },
26
29
  "devDependencies": {
27
- "@agoric/swingset-vat": "0.32.3-mainnet1B-dev-b0c1f78.0+b0c1f78",
28
- "ava": "^5.2.0",
29
- "tsd": "^0.28.1"
30
+ "@endo/far": "^1.0.4",
31
+ "@endo/init": "^1.0.4",
32
+ "@endo/ses-ava": "^1.1.2",
33
+ "ava": "^5.3.0",
34
+ "tsd": "^0.30.4"
35
+ },
36
+ "ava": {
37
+ "require": [
38
+ "@endo/init/debug.js"
39
+ ],
40
+ "files": [
41
+ "test/**/test-*.js"
42
+ ]
30
43
  },
31
44
  "publishConfig": {
32
45
  "access": "public"
@@ -34,5 +47,8 @@
34
47
  "engines": {
35
48
  "node": ">=14.15.0"
36
49
  },
37
- "gitHead": "b0c1f788a06e8593426319de068acd64a390d349"
50
+ "typeCoverage": {
51
+ "atLeast": 98.78
52
+ },
53
+ "gitHead": "096c4e8fce80e9a509b0e1a30fda11736c4570e1"
38
54
  }
package/src/exo-utils.js CHANGED
@@ -1,22 +1,28 @@
1
1
  // @jessie-check
2
-
2
+ /* eslint-disable @typescript-eslint/prefer-ts-expect-error -- for casting from deprecated types that aren't worth fixing */
3
3
  import { initEmpty } from '@agoric/store';
4
4
 
5
5
  import { provide, VatData as globalVatData } from './vat-data-bindings.js';
6
6
 
7
+ /** @typedef {import('@endo/patterns').MethodGuard} MethodGuard */
8
+ /**
9
+ * @template {Record<PropertyKey, MethodGuard>} [T=Record<PropertyKey, MethodGuard>]
10
+ * @typedef {import('@endo/patterns').InterfaceGuard<T>} InterfaceGuard
11
+ */
7
12
  /** @template L,R @typedef {import('@endo/eventual-send').RemotableBrand<L, R>} RemotableBrand */
8
13
  /** @template T @typedef {import('@endo/far').ERef<T>} ERef */
9
- /** @typedef {import('./types.js').Baggage} Baggage */
10
- /** @template T @typedef {import('./types.js').DefineKindOptions<T>} DefineKindOptions */
11
- /** @template T @typedef {import('./types.js').KindFacet<T>} KindFacet */
12
- /** @template T @typedef {import('./types.js').KindFacets<T>} KindFacets */
13
- /** @typedef {import('./types.js').DurableKindHandle} DurableKindHandle */
14
+ /** @typedef {import('@agoric/swingset-liveslots').Baggage} Baggage */
15
+ /** @template T @typedef {import('@agoric/swingset-liveslots').DefineKindOptions<T>} DefineKindOptions */
16
+ /** @template T @typedef {import('@agoric/swingset-liveslots').KindFacet<T>} KindFacet */
17
+ /** @template T @typedef {import('@agoric/swingset-liveslots').KindFacets<T>} KindFacets */
18
+ /** @typedef {import('@agoric/swingset-liveslots').DurableKindHandle} DurableKindHandle */
19
+ /** @typedef {import('@agoric/swingset-liveslots').InterfaceGuardKit} InterfaceGuardKit */
14
20
 
15
21
  /**
16
22
  * Make a version of the argument function that takes a kind context but
17
23
  * ignores it.
18
24
  *
19
- * @type {<T extends Function>(fn: T) => import('./types.js').PlusContext<never, T>}
25
+ * @type {<T extends Function>(fn: T) => import('@agoric/swingset-liveslots').PlusContext<never, T>}
20
26
  */
21
27
  export const ignoreContext =
22
28
  fn =>
@@ -25,6 +31,7 @@ export const ignoreContext =
25
31
  harden(ignoreContext);
26
32
 
27
33
  // TODO: Find a good home for this function used by @agoric/vat-data and testing code
34
+ /** @param {import('@agoric/swingset-liveslots').VatData} VatData */
28
35
  export const makeExoUtils = VatData => {
29
36
  const {
30
37
  defineKind,
@@ -35,6 +42,7 @@ export const makeExoUtils = VatData => {
35
42
  } = VatData;
36
43
 
37
44
  /**
45
+ * @deprecated Use Exos/ExoClasses instead of Kinds
38
46
  * @param {Baggage} baggage
39
47
  * @param {string} kindName
40
48
  * @returns {DurableKindHandle}
@@ -45,7 +53,7 @@ export const makeExoUtils = VatData => {
45
53
 
46
54
  /**
47
55
  * @deprecated Use prepareExoClass instead
48
- * @type {import('./types.js').PrepareKind}
56
+ * @type {import('@agoric/swingset-liveslots').PrepareKind}
49
57
  */
50
58
  const prepareKind = (
51
59
  baggage,
@@ -64,7 +72,7 @@ export const makeExoUtils = VatData => {
64
72
 
65
73
  /**
66
74
  * @deprecated Use prepareExoClassKit instead
67
- * @type {import('./types.js').PrepareKindMulti}
75
+ * @type {import('@agoric/swingset-liveslots').PrepareKindMulti}
68
76
  */
69
77
  const prepareKindMulti = (
70
78
  baggage,
@@ -81,18 +89,25 @@ export const makeExoUtils = VatData => {
81
89
  );
82
90
  harden(prepareKindMulti);
83
91
 
84
- // TODO interfaceGuard type https://github.com/Agoric/agoric-sdk/issues/6206
85
92
  /**
86
93
  * @template {(...args: any) => any} I init state function
87
94
  * @template T behavior
88
95
  * @param {string} tag
89
- * @param {any} interfaceGuard
96
+ * @param {InterfaceGuard | undefined} interfaceGuard
90
97
  * @param {I} init
91
- * @param {T & ThisType<{ self: T, state: ReturnType<I> }>} methods
92
- * @param {DefineKindOptions<{ self: T, state: ReturnType<I> }>} [options]
93
- * @returns {(...args: Parameters<I>) => (T & RemotableBrand<{}, T>)}
98
+ * @param {T & ThisType<{
99
+ * self: T,
100
+ * state: ReturnType<I>
101
+ * }>} methods
102
+ * @param {DefineKindOptions<{
103
+ * self: T,
104
+ * state: ReturnType<I>
105
+ * }>} [options]
106
+ * @returns {(...args: Parameters<I>) => import('@endo/exo/src/exo-makers.js').Guarded<T>}
94
107
  */
95
108
  const defineVirtualExoClass = (tag, interfaceGuard, init, methods, options) =>
109
+ // eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
110
+ // @ts-ignore cast
96
111
  defineKind(tag, init, methods, {
97
112
  ...options,
98
113
  thisfulMethods: true,
@@ -100,16 +115,21 @@ export const makeExoUtils = VatData => {
100
115
  });
101
116
  harden(defineVirtualExoClass);
102
117
 
103
- // TODO interfaceGuard type https://github.com/Agoric/agoric-sdk/issues/6206
104
118
  /**
105
119
  * @template {(...args: any) => any} I init state function
106
- * @template {Record<string, Record<string | symbol, CallableFunction>>} T facets
120
+ * @template {Record<string, Record<PropertyKey, CallableFunction>>} T facets
107
121
  * @param {string} tag
108
- * @param {any} interfaceGuardKit
122
+ * @param {InterfaceGuardKit | undefined} interfaceGuardKit
109
123
  * @param {I} init
110
- * @param {T & ThisType<{ facets: T, state: ReturnType<I> }> } facets
111
- * @param {DefineKindOptions<{ facets: T, state: ReturnType<I> }>} [options]
112
- * @returns {(...args: Parameters<I>) => (T & RemotableBrand<{}, T>)}
124
+ * @param {T & ThisType<{
125
+ * facets: import('@endo/exo/src/exo-makers.js').GuardedKit<T>,
126
+ * state: ReturnType<I>
127
+ * }> } facets
128
+ * @param {DefineKindOptions<{
129
+ * facets: T,
130
+ * state: ReturnType<I>
131
+ * }>} [options]
132
+ * @returns {(...args: Parameters<I>) => import('@endo/exo/src/exo-makers.js').GuardedKit<T>}
113
133
  */
114
134
  const defineVirtualExoClassKit = (
115
135
  tag,
@@ -118,23 +138,29 @@ export const makeExoUtils = VatData => {
118
138
  facets,
119
139
  options,
120
140
  ) =>
141
+ // @ts-ignore cast
121
142
  defineKindMulti(tag, init, facets, {
122
143
  ...options,
123
144
  thisfulMethods: true,
124
- interfaceGuard: interfaceGuardKit,
145
+ interfaceGuardKit,
125
146
  });
126
147
  harden(defineVirtualExoClassKit);
127
148
 
128
- // TODO interfaceGuard type https://github.com/Agoric/agoric-sdk/issues/6206
129
149
  /**
130
150
  * @template {(...args: any) => any} I init state function
131
- * @template {Record<string | symbol, CallableFunction>} T methods
151
+ * @template {Record<PropertyKey, CallableFunction>} T methods
132
152
  * @param {DurableKindHandle} kindHandle
133
- * @param {any} interfaceGuard
153
+ * @param {InterfaceGuard | undefined} interfaceGuard
134
154
  * @param {I} init
135
- * @param {T & ThisType<{ self: T, state: ReturnType<I> }>} methods
136
- * @param {DefineKindOptions<{ self: T, state: ReturnType<I> }>} [options]
137
- * @returns {(...args: Parameters<I>) => (T & RemotableBrand<{}, T>)}
155
+ * @param {T & ThisType<{
156
+ * self: T,
157
+ * state: ReturnType<I>
158
+ * }>} methods
159
+ * @param {DefineKindOptions<{
160
+ * self: T,
161
+ * state: ReturnType<I>
162
+ * }>} [options]
163
+ * @returns {(...args: Parameters<I>) => import('@endo/exo/src/exo-makers.js').Guarded<T>}
138
164
  */
139
165
  const defineDurableExoClass = (
140
166
  kindHandle,
@@ -143,6 +169,7 @@ export const makeExoUtils = VatData => {
143
169
  methods,
144
170
  options,
145
171
  ) =>
172
+ // @ts-ignore cast
146
173
  defineDurableKind(kindHandle, init, methods, {
147
174
  ...options,
148
175
  thisfulMethods: true,
@@ -150,16 +177,21 @@ export const makeExoUtils = VatData => {
150
177
  });
151
178
  harden(defineDurableExoClass);
152
179
 
153
- // TODO interfaceGuard type https://github.com/Agoric/agoric-sdk/issues/6206
154
180
  /**
155
181
  * @template {(...args: any) => any} I init state function
156
- * @template {Record<string, Record<string | symbol, CallableFunction>>} T facets
182
+ * @template {Record<string, Record<PropertyKey, CallableFunction>>} T facets
157
183
  * @param {DurableKindHandle} kindHandle
158
- * @param {any} interfaceGuardKit
184
+ * @param {InterfaceGuardKit | undefined} interfaceGuardKit
159
185
  * @param {I} init
160
- * @param {T & ThisType<{ facets: T, state: ReturnType<I>}> } facets
161
- * @param {DefineKindOptions<{ facets: T, state: ReturnType<I>}>} [options]
162
- * @returns {(...args: Parameters<I>) => (T & RemotableBrand<{}, T>)}
186
+ * @param {T & ThisType<{
187
+ * facets: import('@endo/exo/src/exo-makers.js').GuardedKit<T>,
188
+ * state: ReturnType<I>
189
+ * }> } facets
190
+ * @param {DefineKindOptions<{
191
+ * facets: T,
192
+ * state: ReturnType<I>
193
+ * }>} [options]
194
+ * @returns {(...args: Parameters<I>) => import('@endo/exo/src/exo-makers.js').GuardedKit<T>}
163
195
  */
164
196
  const defineDurableExoClassKit = (
165
197
  kindHandle,
@@ -168,24 +200,30 @@ export const makeExoUtils = VatData => {
168
200
  facets,
169
201
  options,
170
202
  ) =>
203
+ // @ts-ignore cast
171
204
  defineDurableKindMulti(kindHandle, init, facets, {
172
205
  ...options,
173
206
  thisfulMethods: true,
174
- interfaceGuard: interfaceGuardKit,
207
+ interfaceGuardKit,
175
208
  });
176
209
  harden(defineDurableExoClassKit);
177
210
 
178
- // TODO interfaceGuard type https://github.com/Agoric/agoric-sdk/issues/6206
179
211
  /**
180
212
  * @template {(...args: any) => any} I init state function
181
- * @template {Record<string | symbol, CallableFunction>} T methods
213
+ * @template {Record<PropertyKey, CallableFunction>} T methods
182
214
  * @param {Baggage} baggage
183
215
  * @param {string} kindName
184
- * @param {any} interfaceGuard
216
+ * @param {InterfaceGuard | undefined} interfaceGuard
185
217
  * @param {I} init
186
- * @param {T & ThisType<{ self: T, state: ReturnType<I> }>} methods
187
- * @param {DefineKindOptions<{ self: T, state: ReturnType<I> }>} [options]
188
- * @returns {(...args: Parameters<I>) => (T & RemotableBrand<{}, T>)}
218
+ * @param {T & ThisType<{
219
+ * self: T,
220
+ * state: ReturnType<I>
221
+ * }>} methods
222
+ * @param {DefineKindOptions<{
223
+ * self: T,
224
+ * state: ReturnType<I>
225
+ * }>} [options]
226
+ * @returns {(...args: Parameters<I>) => import('@endo/exo/src/exo-makers.js').Guarded<T>}
189
227
  */
190
228
  const prepareExoClass = (
191
229
  baggage,
@@ -204,17 +242,22 @@ export const makeExoUtils = VatData => {
204
242
  );
205
243
  harden(prepareExoClass);
206
244
 
207
- // TODO interfaceGuard type https://github.com/Agoric/agoric-sdk/issues/6206
208
245
  /**
209
246
  * @template {(...args: any) => any} I init state function
210
- * @template {Record<string, Record<string | symbol, CallableFunction>>} T facets
247
+ * @template {Record<string, Record<PropertyKey, CallableFunction>>} T facets
211
248
  * @param {Baggage} baggage
212
249
  * @param {string} kindName
213
- * @param {any} interfaceGuardKit
250
+ * @param {InterfaceGuardKit | undefined} interfaceGuardKit
214
251
  * @param {I} init
215
- * @param {T & ThisType<{ facets: T, state: ReturnType<I> }> } facets
216
- * @param {DefineKindOptions<{ facets: T, state: ReturnType<I> }>} [options]
217
- * @returns {(...args: Parameters<I>) => (T & RemotableBrand<{}, T>)}
252
+ * @param {T & ThisType<{
253
+ * facets: import('@endo/exo/src/exo-makers.js').GuardedKit<T>,
254
+ * state: ReturnType<I>
255
+ * }> } facets
256
+ * @param {DefineKindOptions<{
257
+ * facets: T,
258
+ * state: ReturnType<I>
259
+ * }>} [options]
260
+ * @returns {(...args: Parameters<I>) => import('@endo/exo/src/exo-makers.js').GuardedKit<T>}
218
261
  */
219
262
  const prepareExoClassKit = (
220
263
  baggage,
@@ -233,15 +276,14 @@ export const makeExoUtils = VatData => {
233
276
  );
234
277
  harden(prepareExoClassKit);
235
278
 
236
- // TODO interfaceGuard type https://github.com/Agoric/agoric-sdk/issues/6206
237
279
  /**
238
- * @template {Record<string | symbol, CallableFunction>} M methods
280
+ * @template {Record<PropertyKey, CallableFunction>} M methods
239
281
  * @param {Baggage} baggage
240
282
  * @param {string} kindName
241
- * @param {any} interfaceGuard
283
+ * @param {InterfaceGuard | undefined} interfaceGuard
242
284
  * @param {M} methods
243
285
  * @param {DefineKindOptions<{ self: M }>} [options]
244
- * @returns {M & RemotableBrand<{}, M>}
286
+ * @returns {import('@endo/exo/src/exo-makers.js').Guarded<M>}
245
287
  */
246
288
  const prepareExo = (
247
289
  baggage,
@@ -264,13 +306,13 @@ export const makeExoUtils = VatData => {
264
306
  harden(prepareExo);
265
307
 
266
308
  /**
267
- * @template {Record<string | symbol, CallableFunction>} M methods
309
+ * @template {Record<PropertyKey, CallableFunction>} M methods
268
310
  * @deprecated Use prepareExo instead.
269
311
  * @param {Baggage} baggage
270
312
  * @param {string} kindName
271
313
  * @param {M} methods
272
314
  * @param {DefineKindOptions<{ self: M }>} [options]
273
- * @returns {M & RemotableBrand<{}, M>}
315
+ * @returns {import('@endo/exo/src/exo-makers.js').Guarded<M>}
274
316
  */
275
317
  const prepareSingleton = (baggage, kindName, methods, options = undefined) =>
276
318
  prepareExo(baggage, kindName, undefined, methods, options);
@@ -284,8 +326,8 @@ export const makeExoUtils = VatData => {
284
326
  prepareExoClass,
285
327
  prepareExoClassKit,
286
328
  prepareExo,
287
- prepareSingleton,
288
329
 
330
+ prepareSingleton,
289
331
  provideKindHandle,
290
332
  prepareKind,
291
333
  prepareKindMulti,
package/src/index.js CHANGED
@@ -42,9 +42,12 @@ export {
42
42
  prepareSingleton,
43
43
  } from './exo-utils.js';
44
44
 
45
- /** @typedef {import('./types.js').Baggage} Baggage */
46
- /** @typedef {import('./types.js').DurableKindHandle} DurableKindHandle */
47
- /** @template T @typedef {import('./types.js').DefineKindOptions<T>} DefineKindOptions */
45
+ /** @typedef {import('@agoric/swingset-liveslots').DurableKindHandle} DurableKindHandle */
46
+ /** @template T @typedef {import('@agoric/swingset-liveslots').DefineKindOptions<T>} DefineKindOptions */
47
+
48
+ // Copy this type because aliasing it by `import('@agoric/swingset-liveslots').Baggage`
49
+ // causes this error in typedoc: Expected a symbol for node with kind Identifier
50
+ /** @typedef {MapStore<string, any>} Baggage */
48
51
 
49
52
  // //////////////////////////// deprecated /////////////////////////////////////
50
53
 
@@ -1,18 +1,23 @@
1
- /* eslint-disable no-use-before-define, import/no-extraneous-dependencies */
1
+ /* eslint-disable no-use-before-define */
2
2
  import { expectType } from 'tsd';
3
+ import type {
4
+ KindFacets,
5
+ DurableKindHandle,
6
+ KindFacet,
7
+ FunctionsPlusContext,
8
+ } from '@agoric/swingset-liveslots';
9
+ import { VirtualObjectManager } from '@agoric/swingset-liveslots/src/virtualObjectManager.js';
3
10
  import {
4
11
  defineKind,
5
12
  defineKindMulti,
6
13
  makeKindHandle,
7
14
  defineDurableKind,
8
15
  partialAssign,
16
+ watchPromise,
9
17
  } from '.';
10
- import {
11
- KindFacets,
12
- DurableKindHandle,
13
- KindFacet,
14
- FunctionsPlusContext,
15
- } from './types.js';
18
+
19
+ // for use in assignments below
20
+ const anyVal = null as any;
16
21
 
17
22
  /*
18
23
  export const makePaymentMaker = (allegedName: string, brand: unknown) => {
@@ -154,7 +159,32 @@ const someBehavior: FunctionsPlusContext<SomeContext, SomeFacet> = {
154
159
  return b > context.state.a;
155
160
  },
156
161
  };
157
- const someFacet: KindFacet<typeof someBehavior> = null as any;
162
+ const someFacet: KindFacet<typeof someBehavior> = anyVal;
158
163
  // @ts-expect-error
159
164
  someFacet.gt();
160
165
  expectType<boolean>(someFacet.gt(1));
166
+
167
+ const vom: VirtualObjectManager = anyVal;
168
+ // @ts-expect-error
169
+ vom.missingMethod;
170
+ // @ts-expect-error Expected 0-4 arguments but got 5
171
+ vom.defineDurableKind(anyVal, anyVal, anyVal, anyVal, 'extra');
172
+
173
+ const p: Promise<bigint> = anyVal;
174
+ watchPromise(
175
+ p,
176
+ {
177
+ onFulfilled(value, extra1, extra2) {
178
+ expectType<bigint>(value);
179
+ expectType<string>(extra1);
180
+ // @ts-expect-error str
181
+ expectType<number>(extra2);
182
+ },
183
+ onRejected(reason, extra1) {
184
+ expectType<unknown>(reason);
185
+ expectType<string>(extra1);
186
+ },
187
+ },
188
+ 'extraString',
189
+ 'alsoString',
190
+ );
@@ -3,7 +3,7 @@
3
3
  import { Fail } from '@agoric/assert';
4
4
  import { provideLazy } from '@agoric/store';
5
5
 
6
- /** @type {import('./types').VatData} */
6
+ /** @type {import('@agoric/swingset-liveslots').VatData} */
7
7
  let VatDataGlobal;
8
8
  if ('VatData' in globalThis) {
9
9
  globalThis.VatData || Fail`VatData defined in global as null or undefined`;
@@ -12,20 +12,20 @@ if ('VatData' in globalThis) {
12
12
  // XXX this module has been known to get imported (transitively) in cases that
13
13
  // never use it so we make a version that will satisfy module resolution but
14
14
  // fail at runtime.
15
- const unvailable = () => Fail`VatData unavailable`;
15
+ const unavailable = () => Fail`VatData unavailable`;
16
16
  VatDataGlobal = {
17
- defineKind: unvailable,
18
- defineKindMulti: unvailable,
19
- defineDurableKind: unvailable,
20
- defineDurableKindMulti: unvailable,
21
- makeKindHandle: unvailable,
22
- providePromiseWatcher: unvailable,
23
- watchPromise: unvailable,
24
- makeScalarBigMapStore: unvailable,
25
- makeScalarBigWeakMapStore: unvailable,
26
- makeScalarBigSetStore: unvailable,
27
- makeScalarBigWeakSetStore: unvailable,
28
- canBeDurable: unvailable,
17
+ defineKind: unavailable,
18
+ defineKindMulti: unavailable,
19
+ defineDurableKind: unavailable,
20
+ defineDurableKindMulti: unavailable,
21
+ makeKindHandle: unavailable,
22
+ providePromiseWatcher: unavailable,
23
+ watchPromise: unavailable,
24
+ makeScalarBigMapStore: unavailable,
25
+ makeScalarBigWeakMapStore: unavailable,
26
+ makeScalarBigSetStore: unavailable,
27
+ makeScalarBigWeakSetStore: unavailable,
28
+ canBeDurable: unavailable,
29
29
  };
30
30
  }
31
31
 
@@ -62,7 +62,7 @@ export const {
62
62
  *
63
63
  * const makeFoo = pickFacet(makeFooBase, 'self');
64
64
  *
65
- * @type {import('./types').PickFacet}
65
+ * @type {import('@agoric/swingset-liveslots').PickFacet}
66
66
  */
67
67
  export const pickFacet =
68
68
  (maker, facetName) =>
@@ -107,8 +107,8 @@ harden(partialAssign);
107
107
  * intended to eventually be durable has not yet been made durable. A store
108
108
  * marked as fakeDurable will appear to operate normally but any attempt to
109
109
  * upgrade its containing vat will fail with an error.
110
- * @property {import('./types').Pattern} [keyShape]
111
- * @property {import('./types').Pattern} [valueShape]
110
+ * @property {import('@agoric/swingset-liveslots').Pattern} [keyShape]
111
+ * @property {import('@agoric/swingset-liveslots').Pattern} [valueShape]
112
112
  */
113
113
  /**
114
114
  * Unlike `provideLazy`, `provide` should be called at most once
@@ -138,12 +138,12 @@ harden(partialAssign);
138
138
 
139
139
  export const provide =
140
140
  // XXX cast because provideLazy is `any` due to broken type import
141
- /** @type {<K, V>(baggage: import('./types.js').Baggage, key: K, makeValue: (key: K) => V) => V} */ (
141
+ /** @type {<K, V>(baggage: import('@agoric/swingset-liveslots').Baggage, key: K, makeValue: (key: K) => V) => V} */ (
142
142
  provideLazy
143
143
  );
144
144
 
145
145
  // TODO: Find a good home for this function used by @agoric/vat-data and testing code
146
- /** @param {import('@agoric/vat-data/src/types').VatData} VatData */
146
+ /** @param {import('@agoric/swingset-liveslots').VatData} VatData */
147
147
  export const makeStoreUtils = VatData => {
148
148
  const {
149
149
  // eslint-disable-next-line no-shadow -- these literally do shadow the globals
@@ -157,7 +157,7 @@ export const makeStoreUtils = VatData => {
157
157
  } = VatData;
158
158
 
159
159
  /**
160
- * @param {import('./types').Baggage} baggage
160
+ * @param {import('@agoric/swingset-liveslots').Baggage} baggage
161
161
  * @param {string} name
162
162
  * @param {Omit<StoreOptions, 'durable'>} options
163
163
  */
@@ -168,7 +168,7 @@ export const makeStoreUtils = VatData => {
168
168
  harden(provideDurableMapStore);
169
169
 
170
170
  /**
171
- * @param {import('./types').Baggage} baggage
171
+ * @param {import('@agoric/swingset-liveslots').Baggage} baggage
172
172
  * @param {string} name
173
173
  * @param {Omit<StoreOptions, 'durable'>} options
174
174
  */
@@ -179,7 +179,7 @@ export const makeStoreUtils = VatData => {
179
179
  harden(provideDurableWeakMapStore);
180
180
 
181
181
  /**
182
- * @param {import('./types').Baggage} baggage
182
+ * @param {import('@agoric/swingset-liveslots').Baggage} baggage
183
183
  * @param {string} name
184
184
  * @param {Omit<StoreOptions, 'durable'>} options
185
185
  */
@@ -190,7 +190,7 @@ export const makeStoreUtils = VatData => {
190
190
  harden(provideDurableSetStore);
191
191
 
192
192
  /**
193
- * @param {import('./types').Baggage} baggage
193
+ * @param {import('@agoric/swingset-liveslots').Baggage} baggage
194
194
  * @param {string} name
195
195
  * @param {Omit<StoreOptions, 'durable'>} options
196
196
  */
@@ -0,0 +1,7 @@
1
+ import './prepare-test-env.js';
2
+
3
+ import { wrapTest } from '@endo/ses-ava';
4
+ import rawTest from 'ava';
5
+
6
+ /** @type {typeof rawTest} */
7
+ export const test = wrapTest(rawTest);
@@ -0,0 +1 @@
1
+ import '@agoric/swingset-liveslots/tools/prepare-test-env.js';
@@ -1,9 +1,13 @@
1
- import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';
1
+ import test from 'ava';
2
+
2
3
  /* global globalThis */
4
+ // @ts-expect-error VatData not optional
3
5
  delete globalThis.VatData;
4
6
 
5
7
  /** @see present.test.js */
6
8
  test('methods available that throw', async t => {
7
9
  const { defineKind } = await import('../src/index.js');
8
- t.throws(defineKind, { message: /VatData unavailable/ });
10
+ t.throws(() => defineKind('someTag', () => {}, {}), {
11
+ message: /VatData unavailable/,
12
+ });
9
13
  });
@@ -1,6 +1,8 @@
1
1
  // Modeled on test-heap-classes.js
2
2
 
3
- import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';
3
+ import { test } from './prepare-test-env-ava.js';
4
+
5
+ // eslint-disable-next-line import/order
4
6
  import { M } from '@agoric/store';
5
7
  import {
6
8
  makeKindHandle,
@@ -31,7 +33,7 @@ test('test defineDurableExoClass', t => {
31
33
  const makeUpCounter = defineDurableExoClass(
32
34
  upCounterKind,
33
35
  UpCounterI,
34
- /** @param {number} x */
36
+ /** @param {number} [x] */
35
37
  (x = 0) => ({ x }),
36
38
  {
37
39
  incr(y = 1) {
@@ -67,7 +69,7 @@ test('test defineDurableExoClassKit', t => {
67
69
  const makeCounterKit = defineDurableExoClassKit(
68
70
  counterKindHandle,
69
71
  { up: UpCounterI, down: DownCounterI },
70
- /** @param {number} x */
72
+ /** @param {number} [x] */
71
73
  (x = 0) => ({ x }),
72
74
  {
73
75
  up: {
@@ -122,7 +124,7 @@ test('finish option', t => {
122
124
  UpCounterI,
123
125
  /**
124
126
  * @param {string} name
125
- * @param {number} x
127
+ * @param {number} [x]
126
128
  */
127
129
  (name, x = 0) => ({ name, x }),
128
130
  {
@@ -1,6 +1,8 @@
1
1
  // Modeled on test-heap-classes.js
2
2
 
3
- import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';
3
+ import { test } from './prepare-test-env-ava.js';
4
+
5
+ // eslint-disable-next-line import/order
4
6
  import { M } from '@agoric/store';
5
7
  import {
6
8
  prepareExoClass,
@@ -30,7 +32,7 @@ test('test prepareExoClass', t => {
30
32
  baggage,
31
33
  'UpCounter',
32
34
  UpCounterI,
33
- /** @param {number} x */
35
+ /** @param {number} [x] */
34
36
  (x = 0) => ({ x }),
35
37
  {
36
38
  incr(y = 1) {
@@ -64,7 +66,7 @@ test('test prepareExoClassKit', t => {
64
66
  baggage,
65
67
  'Counter',
66
68
  { up: UpCounterI, down: DownCounterI },
67
- /** @param {number} x */
69
+ /** @param {number} [x] */
68
70
  (x = 0) => ({ x }),
69
71
  {
70
72
  up: {
@@ -0,0 +1,12 @@
1
+ import test from 'ava';
2
+
3
+ const mockDefineKind = /** @type {any} */ (harden({}));
4
+
5
+ /* global globalThis */
6
+ // @ts-expect-error missing fields
7
+ globalThis.VatData ||= { defineKind: mockDefineKind };
8
+
9
+ test('methods available', async t => {
10
+ const { defineKind } = await import('../src/index.js');
11
+ t.is(defineKind, mockDefineKind);
12
+ });
@@ -1,14 +1,14 @@
1
1
  // From https://github.com/Agoric/agoric-sdk/pull/6903#discussion_r1098067133
2
2
 
3
- import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';
3
+ import { test } from './prepare-test-env-ava.js';
4
4
 
5
+ // eslint-disable-next-line import/order
5
6
  import { M, makeScalarMapStore } from '@agoric/store';
6
-
7
7
  import { makeScalarBigMapStore } from '../src/vat-data-bindings.js';
8
8
 
9
9
  test('scalar maps should reject non-scalar keys', t => {
10
10
  const bigMap = makeScalarMapStore('dummy', { keyShape: M.key() });
11
- t.throws(() => bigMap.init(harden({ label: 'not a scalar' })), {
11
+ t.throws(() => bigMap.init(harden({ label: 'not a scalar' }), 'val'), {
12
12
  message:
13
13
  /A "copyRecord" cannot be a scalar key: \{"label":"not a scalar"\}/,
14
14
  });
@@ -1,6 +1,8 @@
1
1
  // Modeled on test-heap-classes.js
2
2
 
3
- import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';
3
+ import { test } from './prepare-test-env-ava.js';
4
+
5
+ // eslint-disable-next-line import/order
4
6
  import { M } from '@agoric/store';
5
7
  import {
6
8
  defineVirtualExoClass,
@@ -25,7 +27,7 @@ test('test defineVirtualExoClass', t => {
25
27
  const makeUpCounter = defineVirtualExoClass(
26
28
  'UpCounter',
27
29
  UpCounterI,
28
- /** @param {number} x */
30
+ /** @param {number} [x] */
29
31
  (x = 0) => ({ x }),
30
32
  {
31
33
  incr(y = 1) {
@@ -56,7 +58,7 @@ test('test defineVirtualExoClassKit', t => {
56
58
  const makeCounterKit = defineVirtualExoClassKit(
57
59
  'Counter',
58
60
  { up: UpCounterI, down: DownCounterI },
59
- /** @param {number} x */
61
+ /** @param {number} [x] */
60
62
  (x = 0) => ({ x }),
61
63
  {
62
64
  up: {
@@ -0,0 +1,44 @@
1
+ // @ts-check
2
+ import test from 'ava';
3
+ import { E, Far } from '@endo/far';
4
+
5
+ import { V, makeVowKit } from '../vow.js';
6
+
7
+ test('heap messages', async t => {
8
+ const greeter = Far('Greeter', {
9
+ hello: /** @param {string} name */ name => `Hello, ${name}!`,
10
+ });
11
+
12
+ /** @type {ReturnType<typeof makeVowKit<typeof greeter>>} */
13
+ const { vow, resolver } = makeVowKit();
14
+ const retP = V(vow).hello('World');
15
+ resolver.resolve(greeter);
16
+
17
+ // Happy path: WE(vow)[method](...args) calls the method.
18
+ t.is(await retP, 'Hello, World!');
19
+
20
+ // Sad path: E(vow)[method](...args) rejects.
21
+ await t.throwsAsync(
22
+ // @ts-expect-error hello is not accessible via basicE
23
+ () => E(vow).hello('World'),
24
+ {
25
+ message: /target has no method "hello"/,
26
+ },
27
+ );
28
+
29
+ // Happy path: await WE.when unwraps the vow.
30
+ t.is(await V.when(vow), greeter);
31
+
32
+ t.is(
33
+ await V.when(vow, res => {
34
+ t.is(res, greeter);
35
+ return 'done';
36
+ }),
37
+ 'done',
38
+ );
39
+
40
+ // Sad path: await by itself gives the raw vow.
41
+ const w = await vow;
42
+ t.not(w, greeter);
43
+ t.truthy(w.payload);
44
+ });
package/tsconfig.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
- "strict": true,
5
- "noImplicitAny": false, // for compat with peer packages using ambient types
4
+ // XXX to resolve the swingset-liveslots types
5
+ "maxNodeModuleJsDepth": 1,
6
+ // "strict": true, // disabled for compat with >0 module depth
7
+ // "noImplicitAny": false, // for compat with peer packages using ambient types
6
8
  },
7
9
  "include": [
8
10
  "src/**/*.js",
package/typedoc.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": [
3
+ "../../typedoc.base.json"
4
+ ],
5
+ "entryPoints": [
6
+ "src/index.js",
7
+ ]
8
+ }
package/vow.js ADDED
@@ -0,0 +1,50 @@
1
+ /* global globalThis */
2
+ // @ts-check
3
+ import { makeE, prepareVowTools as rawPrepareVowTools } from '@agoric/vow';
4
+ import { makeHeapZone } from '@agoric/base-zone/heap.js';
5
+ import { isUpgradeDisconnection } from '@agoric/internal/src/upgrade-api.js';
6
+
7
+ /** @type {any} */
8
+ const vatData = globalThis.VatData;
9
+
10
+ /**
11
+ * Manually-extracted watchPromise so we don't accidentally get the 'unavailable'
12
+ * version. If it is `undefined`, `@agoric/vow` will shim it.
13
+ * @type {undefined | ((
14
+ * p: Promise<any>,
15
+ * watcher: import('@agoric/vow/src/watch-promise.js').PromiseWatcher,
16
+ * ...args: unknown[]
17
+ * ) => void)}
18
+ */
19
+ const watchPromise = vatData && vatData.watchPromise;
20
+
21
+ /**
22
+ * Return truthy if a rejection reason should result in a retry.
23
+ * @param {any} reason
24
+ * @returns {boolean}
25
+ */
26
+ const isRetryableReason = reason => isUpgradeDisconnection(reason);
27
+
28
+ export const defaultPowers = harden({
29
+ isRetryableReason,
30
+ watchPromise,
31
+ });
32
+
33
+ /**
34
+ * @type {typeof rawPrepareVowTools}
35
+ */
36
+ export const prepareVowTools = (zone, powers = {}) =>
37
+ rawPrepareVowTools(zone, { ...defaultPowers, ...powers });
38
+
39
+ export const { watch, when, makeVowKit } = prepareVowTools(makeHeapZone());
40
+
41
+ /**
42
+ * An vow-shortening E. CAVEAT: This produces long-lived ephemeral
43
+ * promises that encapsulate the shortening behaviour, and so provides no way
44
+ * for `watch` to durably shorten. Use the standard `import('@endo/far').E` if
45
+ * you need to `watch` its resulting promises.
46
+ */
47
+ export const V = makeE(globalThis.HandledPromise, {
48
+ unwrap: when,
49
+ additional: { when },
50
+ });
package/src/types.d.ts DELETED
@@ -1,203 +0,0 @@
1
- /**
2
- * @file Types for vat-data
3
- *
4
- * Facet is a single object with methods.
5
- * Behavior is a description when defining a kind of what facets it will have.
6
- * For the non-multi defineKind, there is just one facet so it doesn't have a key.
7
- */
8
- import type {
9
- InterfaceGuard,
10
- MapStore,
11
- Pattern,
12
- SetStore,
13
- StoreOptions,
14
- WeakMapStore,
15
- WeakSetStore,
16
- } from '@agoric/store';
17
-
18
- export type { Pattern };
19
-
20
- export type Baggage = MapStore<string, unknown>;
21
-
22
- type Tail<T extends any[]> = T extends [head: any, ...rest: infer Rest]
23
- ? Rest
24
- : [];
25
-
26
- type MinusContext<
27
- F extends (context, ...rest: any[]) => any,
28
- P extends any[] = Parameters<F>, // P: are the parameters of F
29
- R = ReturnType<F>, // R: the return type of F
30
- > = (...args: Tail<P>) => R;
31
-
32
- export type KindFacet<O> = { [K in keyof O]: MinusContext<O[K]> };
33
-
34
- export type KindFacets<B> = {
35
- [FacetKey in keyof B]: KindFacet<B[FacetKey]>;
36
- };
37
-
38
- export type KindContext<S, F> = { state: S; self: KindFacet<F> };
39
- export type MultiKindContext<S, B> = { state: S; facets: KindFacets<B> };
40
-
41
- export type PlusContext<C, M> = (c: C, ...args: Parameters<M>) => ReturnType<M>;
42
- export type FunctionsPlusContext<C, O> = {
43
- [K in keyof O]: PlusContext<C, O[K]>;
44
- };
45
-
46
- declare class DurableKindHandleClass {
47
- private descriptionTag: string;
48
- }
49
- export type DurableKindHandle = DurableKindHandleClass;
50
-
51
- /**
52
- * Grab bag of options that can be provided to `defineDurableKind` and its
53
- * siblings. Not all options are meaningful in all contexts. See the
54
- * doc-comments on each option.
55
- */
56
- export type DefineKindOptions<C> = {
57
- /**
58
- * If provided, the `finish` function will be called after the instance is
59
- * made and internally registered, but before it is returned. The finish
60
- * function is to do any post-intantiation initialization that should be
61
- * done before exposing the object to its clients.
62
- */
63
- finish?: (context: C) => void;
64
-
65
- /**
66
- * Meaningful to `makeScalarBigMapStore` and its siblings. These maker
67
- * fuctions will make either virtual or durable stores, depending on
68
- * this flag. Defaults to off, making virtual but not durable collections.
69
- *
70
- * Generally, durable collections are provided with `provideDurableMapStore`
71
- * and its sibling, which use this flag internally. If you do not make
72
- * durable collections by other means, you can consider this as
73
- * intended for internal use only.
74
- */
75
- durable?: boolean;
76
-
77
- /**
78
- * If provided, it describes the shape of all state records of instances
79
- * of this kind.
80
- */
81
- stateShape?: { [name: string]: Pattern };
82
-
83
- /**
84
- * Intended for internal use only.
85
- * Should the raw methods receive their `context` argument as their first
86
- * argument or as their `this` binding? For `defineDurableKind` and its
87
- * siblings (including `prepareSingleton`), this defaults to off, meaning that
88
- * their behavior methods receive `context` as their first argument.
89
- * `prepareExoClass` and its siblings (including `prepareExo`) use
90
- * this flag internally to indicate that their methods receive `context`
91
- * as their `this` binding.
92
- */
93
- thisfulMethods?: boolean;
94
-
95
- /**
96
- * Intended for internal use only.
97
- * If an `interfaceGuard` is provided, then the raw methods passed alongside
98
- * it are wrapped by a function that first checks that this method's guard
99
- * pattern is satisfied before calling the raw method.
100
- *
101
- * In `defineDurableKind` and its siblings, this defaults to off.
102
- * `prepareExoClass` use this internally to protect their raw class methods
103
- * using the provided interface.
104
- */
105
- interfaceGuard?: InterfaceGuard<unknown>;
106
- };
107
-
108
- export type VatData = {
109
- // virtual kinds
110
- /** @deprecated Use defineVirtualExoClass instead */
111
- defineKind: <P, S, F>(
112
- tag: string,
113
- init: (...args: P) => S,
114
- facet: F,
115
- options?: DefineKindOptions<KindContext<S, F>>,
116
- ) => (...args: P) => KindFacet<F>;
117
-
118
- /** @deprecated Use defineVirtualExoClassKit instead */
119
- defineKindMulti: <P, S, B>(
120
- tag: string,
121
- init: (...args: P) => S,
122
- behavior: B,
123
- options?: DefineKindOptions<MultiKindContext<S, B>>,
124
- ) => (...args: P) => KindFacets<B>;
125
-
126
- // durable kinds
127
- makeKindHandle: (descriptionTag: string) => DurableKindHandle;
128
-
129
- /** @deprecated Use defineDurableExoClass instead */
130
- defineDurableKind: <P, S, F>(
131
- kindHandle: DurableKindHandle,
132
- init: (...args: P) => S,
133
- facet: F,
134
- options?: DefineKindOptions<KindContext<S, F>>,
135
- ) => (...args: P) => KindFacet<F>;
136
-
137
- /** @deprecated Use defineDurableExoClassKit instead */
138
- defineDurableKindMulti: <P, S, B>(
139
- kindHandle: DurableKindHandle,
140
- init: (...args: P) => S,
141
- behavior: B,
142
- options?: DefineKindOptions<MultiKindContext<S, B>>,
143
- ) => (...args: P) => KindFacets<B>;
144
-
145
- providePromiseWatcher: unknown;
146
- watchPromise: unknown;
147
-
148
- makeScalarBigMapStore: <K, V>(
149
- label: string,
150
- options?: StoreOptions,
151
- ) => MapStore<K, V>;
152
- makeScalarBigWeakMapStore: <K, V>(
153
- label: string,
154
- options?: StoreOptions,
155
- ) => WeakMapStore<K, V>;
156
-
157
- makeScalarBigSetStore: <K>(
158
- label: string,
159
- options?: StoreOptions,
160
- ) => SetStore<K>;
161
- makeScalarBigWeakSetStore: <K>(
162
- label: string,
163
- options?: StoreOptions,
164
- ) => WeakSetStore<K>;
165
- canBeDurable: (specimen: unknown) => boolean;
166
- };
167
-
168
- // The JSDoc is repeated here and at the function definition so it appears
169
- // in IDEs where it's used, regardless of type resolution.
170
- export interface PickFacet {
171
- /**
172
- * When making a multi-facet kind, it's common to pick one facet to
173
- * expose. E.g.,
174
- *
175
- * const makeFoo = (a, b, c, d) => makeFooBase(a, b, c, d).self;
176
- *
177
- * This helper reduces the duplication:
178
- *
179
- * const makeFoo = pickFacet(makeFooBase, 'self');
180
- */
181
- <M extends (...args: any[]) => any, F extends keyof ReturnType<M>>(
182
- maker: M,
183
- facetName: F,
184
- ): (...args: Parameters<M>) => ReturnType<M>[F];
185
- }
186
-
187
- /** @deprecated Use prepareExoClass instead */
188
- export type PrepareKind = <P, S, F>(
189
- baggage: Baggage,
190
- tag: string,
191
- init: (...args: P) => S,
192
- facet: F,
193
- options?: DefineKindOptions<KindContext<S, F>>,
194
- ) => (...args: P) => KindFacet<F>;
195
-
196
- /** @deprecated Use prepareExoClassKit instead */
197
- export type PrepareKindMulti = <P, S, B>(
198
- baggage: Baggage,
199
- tag: string,
200
- init: (...args: P) => S,
201
- behavior: B,
202
- options?: DefineKindOptions<MultiKindContext<S, B>>,
203
- ) => (...args: P) => KindFacets<B>;
@@ -1,7 +0,0 @@
1
- import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';
2
-
3
- test('methods available', async t => {
4
- const { defineKind } = await import('../src/index.js');
5
- defineKind('test', () => {}, {});
6
- t.pass();
7
- });