@agoric/vat-data 0.5.3-u13.0 → 0.5.3-u16.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,35 +3,23 @@
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
-
6
+ ### [0.5.3-u16.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.5.2...@agoric/vat-data@0.5.3-u16.0) (2024-07-02)
26
7
 
27
8
 
9
+ ### Features
28
10
 
11
+ * **liveslots:** virtual exo meta-ops ([#8779](https://github.com/Agoric/agoric-sdk/issues/8779)) ([af3ced9](https://github.com/Agoric/agoric-sdk/commit/af3ced91861731353e10a45e4eae63450f74a0ea))
12
+ * **vow:** make `when` an augmentation of `E.when` ([c2a3179](https://github.com/Agoric/agoric-sdk/commit/c2a31792b7070a44b2ab6c9f95dd845b75b316e8))
29
13
 
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
14
 
15
+ ### Bug Fixes
34
16
 
17
+ * "x" parameter in many tests is optional ([#8750](https://github.com/Agoric/agoric-sdk/issues/8750)) ([00137a3](https://github.com/Agoric/agoric-sdk/commit/00137a3dd689ca6255e11dc171c9b1cc8b8261ba))
18
+ * **types:** board ([c73f4f9](https://github.com/Agoric/agoric-sdk/commit/c73f4f9686215a37e8c5f82ce8dbe4742886a02b))
19
+ * **types:** problems hidden by skipLibCheck ([6a6e595](https://github.com/Agoric/agoric-sdk/commit/6a6e59549e7beeeef94bf90556ed16873c46d285))
20
+ * **vat-data:** methods can be `PropertyKey`s ([b99f499](https://github.com/Agoric/agoric-sdk/commit/b99f4993c0f1caa651b83755f85689f123717f67))
21
+ * **vow:** persistent resolution, settler->resolver ([4d9371c](https://github.com/Agoric/agoric-sdk/commit/4d9371cb7d450e25146787474760b4c00b11e405))
22
+ * **vow:** use `zone.watchPromise` ([b8ddc9d](https://github.com/Agoric/agoric-sdk/commit/b8ddc9d1ddf06fed8b434f36aa86a2a70293fd56))
35
23
 
36
24
 
37
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/vat-data",
3
- "version": "0.5.3-u13.0",
3
+ "version": "0.5.3-u16.0",
4
4
  "description": "Safe access to VatData global",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/Agoric/agoric-sdk",
@@ -19,20 +19,37 @@
19
19
  "author": "Agoric",
20
20
  "license": "Apache-2.0",
21
21
  "dependencies": {
22
- "@agoric/assert": "^0.6.1-u11wf.0",
23
- "@agoric/internal": "^0.4.0-u13.0",
24
- "@agoric/store": "^0.9.3-u13.0"
22
+ "@agoric/assert": "^0.6.1-u16.0",
23
+ "@agoric/base-zone": "^0.1.1-u16.0",
24
+ "@agoric/store": "^0.9.3-u16.0",
25
+ "@agoric/swingset-liveslots": "^0.10.3-u16.0",
26
+ "@agoric/vow": "^0.2.0-u16.0",
27
+ "@endo/exo": "^1.5.0",
28
+ "@endo/patterns": "^1.4.0"
25
29
  },
26
30
  "devDependencies": {
27
- "@agoric/swingset-vat": "^0.32.3-u13.0",
28
- "ava": "^5.2.0",
29
- "tsd": "^0.28.1"
31
+ "@endo/far": "^1.1.2",
32
+ "@endo/init": "^1.1.2",
33
+ "@endo/ses-ava": "^1.2.2",
34
+ "ava": "^5.3.0",
35
+ "tsd": "^0.30.7"
36
+ },
37
+ "ava": {
38
+ "require": [
39
+ "@endo/init/debug.js"
40
+ ],
41
+ "files": [
42
+ "test/**/*.test.*"
43
+ ]
30
44
  },
31
45
  "publishConfig": {
32
46
  "access": "public"
33
47
  },
34
48
  "engines": {
35
- "node": ">=14.15.0"
49
+ "node": "^18.12 || ^20.9"
50
+ },
51
+ "typeCoverage": {
52
+ "atLeast": 99.33
36
53
  },
37
- "gitHead": "5a6cdeb0c18ae9700d706445acf402f8d1e873c3"
54
+ "gitHead": "bbdf652c3f413381cb352a8a360db1063974fafd"
38
55
  }
package/src/exo-utils.js CHANGED
@@ -4,19 +4,26 @@ import { initEmpty } from '@agoric/store';
4
4
 
5
5
  import { provide, VatData as globalVatData } from './vat-data-bindings.js';
6
6
 
7
- /** @template L,R @typedef {import('@endo/eventual-send').RemotableBrand<L, R>} RemotableBrand */
8
- /** @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 */
7
+ /**
8
+ * @import {InterfaceGuard} from '@endo/patterns';
9
+ * @import {RemotableObject} from '@endo/pass-style';
10
+ * @import {Baggage, DefineKindOptions, DurableKindHandle, InterfaceGuardKit} from '@agoric/swingset-liveslots';
11
+ */
12
+
13
+ // Some feedback if the init function is async
14
+ /**
15
+ * @typedef {(...args: any[]) => any} InitState
16
+ */
17
+ /**
18
+ * @template {InitState} I
19
+ * @typedef {ReturnType<I> extends Promise<any> ? never : ReturnType<I>} StateResult
20
+ */
14
21
 
15
22
  /**
16
23
  * Make a version of the argument function that takes a kind context but
17
24
  * ignores it.
18
25
  *
19
- * @type {<T extends Function>(fn: T) => import('./types.js').PlusContext<never, T>}
26
+ * @type {<T extends (...args: any) => any>(fn: T) => import('@agoric/swingset-liveslots').PlusContext<never, T>}
20
27
  */
21
28
  export const ignoreContext =
22
29
  fn =>
@@ -25,6 +32,7 @@ export const ignoreContext =
25
32
  harden(ignoreContext);
26
33
 
27
34
  // TODO: Find a good home for this function used by @agoric/vat-data and testing code
35
+ /** @param {import('@agoric/swingset-liveslots').VatData} VatData */
28
36
  export const makeExoUtils = VatData => {
29
37
  const {
30
38
  defineKind,
@@ -35,6 +43,7 @@ export const makeExoUtils = VatData => {
35
43
  } = VatData;
36
44
 
37
45
  /**
46
+ * @deprecated Use Exos/ExoClasses instead of Kinds
38
47
  * @param {Baggage} baggage
39
48
  * @param {string} kindName
40
49
  * @returns {DurableKindHandle}
@@ -45,7 +54,7 @@ export const makeExoUtils = VatData => {
45
54
 
46
55
  /**
47
56
  * @deprecated Use prepareExoClass instead
48
- * @type {import('./types.js').PrepareKind}
57
+ * @type {import('@agoric/swingset-liveslots').PrepareKind}
49
58
  */
50
59
  const prepareKind = (
51
60
  baggage,
@@ -64,7 +73,7 @@ export const makeExoUtils = VatData => {
64
73
 
65
74
  /**
66
75
  * @deprecated Use prepareExoClassKit instead
67
- * @type {import('./types.js').PrepareKindMulti}
76
+ * @type {import('@agoric/swingset-liveslots').PrepareKindMulti}
68
77
  */
69
78
  const prepareKindMulti = (
70
79
  baggage,
@@ -81,18 +90,24 @@ export const makeExoUtils = VatData => {
81
90
  );
82
91
  harden(prepareKindMulti);
83
92
 
84
- // TODO interfaceGuard type https://github.com/Agoric/agoric-sdk/issues/6206
85
93
  /**
86
- * @template {(...args: any) => any} I init state function
94
+ * @template {InitState} I init state function
87
95
  * @template T behavior
88
96
  * @param {string} tag
89
- * @param {any} interfaceGuard
97
+ * @param {InterfaceGuard | undefined} interfaceGuard
90
98
  * @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>)}
99
+ * @param {T & ThisType<{
100
+ * self: T,
101
+ * state: StateResult<I>
102
+ * }>} methods
103
+ * @param {DefineKindOptions<{
104
+ * self: T,
105
+ * state: StateResult<I>
106
+ * }>} [options]
107
+ * @returns {(...args: Parameters<I>) => import('@endo/exo').Guarded<T>}
94
108
  */
95
109
  const defineVirtualExoClass = (tag, interfaceGuard, init, methods, options) =>
110
+ // @ts-expect-error 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
- * @template {(...args: any) => any} I init state function
106
- * @template {Record<string, Record<string | symbol, CallableFunction>>} T facets
119
+ * @template {InitState} I init state function
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').GuardedKit<T>,
126
+ * state: StateResult<I>
127
+ * }> } facets
128
+ * @param {DefineKindOptions<{
129
+ * facets: T,
130
+ * state: StateResult<I>
131
+ * }>} [options]
132
+ * @returns {(...args: Parameters<I>) => import('@endo/exo').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-expect-error 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
- * @template {(...args: any) => any} I init state function
131
- * @template {Record<string | symbol, CallableFunction>} T methods
150
+ * @template {InitState} I init state function
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: StateResult<I>
158
+ * }>} methods
159
+ * @param {DefineKindOptions<{
160
+ * self: T,
161
+ * state: StateResult<I>
162
+ * }>} [options]
163
+ * @returns {(...args: Parameters<I>) => import('@endo/exo').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-expect-error 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
- * @template {(...args: any) => any} I init state function
156
- * @template {Record<string, Record<string | symbol, CallableFunction>>} T facets
181
+ * @template {InitState} I init state function
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').GuardedKit<T>,
188
+ * state: StateResult<I>
189
+ * }> } facets
190
+ * @param {DefineKindOptions<{
191
+ * facets: T,
192
+ * state: StateResult<I>
193
+ * }>} [options]
194
+ * @returns {(...args: Parameters<I>) => import('@endo/exo').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-expect-error 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
- * @template {(...args: any) => any} I init state function
181
- * @template {Record<string | symbol, CallableFunction>} T methods
212
+ * @template {InitState} I init state function
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: RemotableObject & T,
220
+ * state: StateResult<I>
221
+ * }>} methods
222
+ * @param {DefineKindOptions<{
223
+ * self: T,
224
+ * state: StateResult<I>
225
+ * }>} [options]
226
+ * @returns {(...args: Parameters<I>) => import('@endo/exo').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
- * @template {(...args: any) => any} I init state function
210
- * @template {Record<string, Record<string | symbol, CallableFunction>>} T facets
246
+ * @template {InitState} I init state function
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').GuardedKit<T>,
254
+ * state: StateResult<I>
255
+ * }> } facets
256
+ * @param {DefineKindOptions<{
257
+ * facets: T,
258
+ * state: StateResult<I>
259
+ * }>} [options]
260
+ * @returns {(...args: Parameters<I>) => import('@endo/exo').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').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').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
@@ -1,6 +1,6 @@
1
1
  // @jessie-check
2
2
 
3
- /// <reference types="ses"/>
3
+ /// <reference types="ses" />
4
4
  export {
5
5
  M,
6
6
  makeScalarMapStore,
@@ -42,9 +42,11 @@ 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
+ // TODO re-export these
46
+ /** @template T @typedef {import('@agoric/swingset-liveslots').DefineKindOptions<T>} DefineKindOptions */
47
+ // Copy this type because aliasing it by `import('@agoric/swingset-liveslots').Baggage`
48
+ // causes this error in typedoc: Expected a symbol for node with kind Identifier
49
+ /** @typedef {MapStore<string, any>} Baggage */
48
50
 
49
51
  // //////////////////////////// deprecated /////////////////////////////////////
50
52
 
@@ -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,
9
- } from '.';
10
- import {
11
- KindFacets,
12
- DurableKindHandle,
13
- KindFacet,
14
- FunctionsPlusContext,
15
- } from './types.js';
16
+ watchPromise,
17
+ } from './index.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,29 +3,32 @@
3
3
  import { Fail } from '@agoric/assert';
4
4
  import { provideLazy } from '@agoric/store';
5
5
 
6
- /** @type {import('./types').VatData} */
6
+ /** @import {Baggage, PickFacet, VatData} from '@agoric/swingset-liveslots' */
7
+
8
+ /** @type {VatData} */
7
9
  let VatDataGlobal;
8
10
  if ('VatData' in globalThis) {
9
11
  globalThis.VatData || Fail`VatData defined in global as null or undefined`;
10
- VatDataGlobal = globalThis.VatData;
12
+ // XXX types incompatibility
13
+ VatDataGlobal = /** @type {any} */ (globalThis.VatData);
11
14
  } else {
12
15
  // XXX this module has been known to get imported (transitively) in cases that
13
16
  // never use it so we make a version that will satisfy module resolution but
14
17
  // fail at runtime.
15
- const unvailable = () => Fail`VatData unavailable`;
18
+ const unavailable = () => Fail`VatData unavailable`;
16
19
  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,
20
+ defineKind: unavailable,
21
+ defineKindMulti: unavailable,
22
+ defineDurableKind: unavailable,
23
+ defineDurableKindMulti: unavailable,
24
+ makeKindHandle: unavailable,
25
+ providePromiseWatcher: unavailable,
26
+ watchPromise: unavailable,
27
+ makeScalarBigMapStore: unavailable,
28
+ makeScalarBigWeakMapStore: unavailable,
29
+ makeScalarBigSetStore: unavailable,
30
+ makeScalarBigWeakSetStore: unavailable,
31
+ canBeDurable: unavailable,
29
32
  };
30
33
  }
31
34
 
@@ -62,7 +65,7 @@ export const {
62
65
  *
63
66
  * const makeFoo = pickFacet(makeFooBase, 'self');
64
67
  *
65
- * @type {import('./types').PickFacet}
68
+ * @type {PickFacet}
66
69
  */
67
70
  export const pickFacet =
68
71
  (maker, facetName) =>
@@ -83,33 +86,8 @@ export const partialAssign = (target, source) => {
83
86
  };
84
87
  harden(partialAssign);
85
88
 
86
- // XXX copied from @agoric/store types
87
- // UNTIL https://github.com/Agoric/agoric-sdk/issues/4560
88
- /**
89
- * @typedef {object} StoreOptions
90
- * Of the dimensions on which KeyedStores can differ, we only represent a few
91
- * of them as standard options. A given store maker should document which
92
- * options it supports, as well as its positions on dimensions for which it
93
- * does not support options.
94
- * @property {boolean} [longLived=true] Which way to optimize a weak store. True means
95
- * that we expect this weak store to outlive most of its keys, in which
96
- * case we internally may use a JavaScript `WeakMap`. Otherwise we internally
97
- * may use a JavaScript `Map`.
98
- * Defaults to true, so please mark short lived stores explicitly.
99
- * @property {boolean} [durable=false] The contents of this store survive termination
100
- * of its containing process, allowing for restart or upgrade but at the cost
101
- * of forbidding storage of references to ephemeral data. Defaults to false.
102
- * @property {boolean} [fakeDurable=false] This store pretends to be a durable store
103
- * but does not enforce that the things stored in it actually be themselves
104
- * durable (whereas an actual durable store would forbid storage of such
105
- * items). This is in service of allowing incremental transition to use of
106
- * durable stores, to enable normal operation and testing when some stuff
107
- * intended to eventually be durable has not yet been made durable. A store
108
- * marked as fakeDurable will appear to operate normally but any attempt to
109
- * upgrade its containing vat will fail with an error.
110
- * @property {import('./types').Pattern} [keyShape]
111
- * @property {import('./types').Pattern} [valueShape]
112
- */
89
+ /** @import {StoreOptions} from '@agoric/store' */
90
+
113
91
  /**
114
92
  * Unlike `provideLazy`, `provide` should be called at most once
115
93
  * within any vat incarnation with a given `baggage`,`key` pair.
@@ -138,12 +116,12 @@ harden(partialAssign);
138
116
 
139
117
  export const provide =
140
118
  // 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} */ (
119
+ /** @type {<K, V>(baggage: Baggage, key: K, makeValue: (key: K) => V) => V} */ (
142
120
  provideLazy
143
121
  );
144
122
 
145
123
  // 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 */
124
+ /** @param {VatData} VatData */
147
125
  export const makeStoreUtils = VatData => {
148
126
  const {
149
127
  // eslint-disable-next-line no-shadow -- these literally do shadow the globals
@@ -157,7 +135,7 @@ export const makeStoreUtils = VatData => {
157
135
  } = VatData;
158
136
 
159
137
  /**
160
- * @param {import('./types').Baggage} baggage
138
+ * @param {Baggage} baggage
161
139
  * @param {string} name
162
140
  * @param {Omit<StoreOptions, 'durable'>} options
163
141
  */
@@ -168,7 +146,7 @@ export const makeStoreUtils = VatData => {
168
146
  harden(provideDurableMapStore);
169
147
 
170
148
  /**
171
- * @param {import('./types').Baggage} baggage
149
+ * @param {Baggage} baggage
172
150
  * @param {string} name
173
151
  * @param {Omit<StoreOptions, 'durable'>} options
174
152
  */
@@ -179,7 +157,7 @@ export const makeStoreUtils = VatData => {
179
157
  harden(provideDurableWeakMapStore);
180
158
 
181
159
  /**
182
- * @param {import('./types').Baggage} baggage
160
+ * @param {Baggage} baggage
183
161
  * @param {string} name
184
162
  * @param {Omit<StoreOptions, 'durable'>} options
185
163
  */
@@ -190,7 +168,7 @@ export const makeStoreUtils = VatData => {
190
168
  harden(provideDurableSetStore);
191
169
 
192
170
  /**
193
- * @param {import('./types').Baggage} baggage
171
+ * @param {Baggage} baggage
194
172
  * @param {string} name
195
173
  * @param {Omit<StoreOptions, 'durable'>} options
196
174
  */
@@ -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
  });
@@ -0,0 +1,90 @@
1
+ // modeled on test-amplify-heap-class-kits.js
2
+ import { test } from './prepare-test-env-ava.js';
3
+
4
+ // eslint-disable-next-line import/order
5
+ import { M } from '@endo/patterns';
6
+ import {
7
+ defineVirtualExoClass,
8
+ defineVirtualExoClassKit,
9
+ } from '../src/exo-utils.js';
10
+
11
+ const UpCounterI = M.interface('UpCounter', {
12
+ incr: M.call().optional(M.gte(0)).returns(M.number()),
13
+ });
14
+
15
+ const DownCounterI = M.interface('DownCounter', {
16
+ decr: M.call().optional(M.gte(0)).returns(M.number()),
17
+ });
18
+
19
+ test('test amplify defineVirtualExoClass fails', t => {
20
+ t.throws(
21
+ () =>
22
+ defineVirtualExoClass(
23
+ 'UpCounter',
24
+ UpCounterI,
25
+ /** @param {number} [x] */
26
+ (x = 0) => ({ x }),
27
+ {
28
+ incr(y = 1) {
29
+ const { state } = this;
30
+ state.x += y;
31
+ return state.x;
32
+ },
33
+ },
34
+ {
35
+ receiveAmplifier(_) {},
36
+ },
37
+ ),
38
+ {
39
+ message:
40
+ 'Only facets of an exo class kit can be amplified, not "UpCounter"',
41
+ },
42
+ );
43
+ });
44
+
45
+ test('test amplify defineVirtualExoClassKit', t => {
46
+ /** @type {import('@endo/exo').Amplify} */
47
+ let amp;
48
+ const makeCounterKit = defineVirtualExoClassKit(
49
+ 'Counter',
50
+ { up: UpCounterI, down: DownCounterI },
51
+ /** @param {number} [x] */
52
+ (x = 0) => ({ x }),
53
+ {
54
+ up: {
55
+ incr(y = 1) {
56
+ const { state } = this;
57
+ state.x += y;
58
+ return state.x;
59
+ },
60
+ },
61
+ down: {
62
+ decr(y = 1) {
63
+ const { state } = this;
64
+ state.x -= y;
65
+ return state.x;
66
+ },
67
+ },
68
+ },
69
+ {
70
+ receiveAmplifier(a) {
71
+ amp = a;
72
+ },
73
+ },
74
+ );
75
+ // @ts-expect-error TS thinks it is used before assigned, which is a hazard
76
+ // TS is correct to bring to our attention, since there is not enough static
77
+ // into to infer otherwise.
78
+ assert(amp !== undefined);
79
+
80
+ const counterKit = makeCounterKit(3);
81
+ const { up: upCounter, down: downCounter } = counterKit;
82
+ t.is(upCounter.incr(5), 8);
83
+ t.is(downCounter.decr(), 7);
84
+
85
+ t.throws(() => amp(harden({})), {
86
+ message: 'Must be a facet of "Counter": {}',
87
+ });
88
+ t.deepEqual(amp(upCounter), counterKit);
89
+ t.deepEqual(amp(downCounter), counterKit);
90
+ });
@@ -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
  {
@@ -0,0 +1,110 @@
1
+ // modeled on test-is-instance-heap-class-kits.js
2
+
3
+ import { test } from './prepare-test-env-ava.js';
4
+
5
+ // eslint-disable-next-line import/order
6
+ import { M } from '@endo/patterns';
7
+ import {
8
+ defineVirtualExoClass,
9
+ defineVirtualExoClassKit,
10
+ } from '../src/exo-utils.js';
11
+
12
+ const UpCounterI = M.interface('UpCounter', {
13
+ incr: M.call().optional(M.gte(0)).returns(M.number()),
14
+ });
15
+
16
+ const DownCounterI = M.interface('DownCounter', {
17
+ decr: M.call().optional(M.gte(0)).returns(M.number()),
18
+ });
19
+
20
+ test('test isInstance defineVirtualExoClass', t => {
21
+ /** @type {import('@endo/exo').IsInstance} */
22
+ let isInstance;
23
+ const makeUpCounter = defineVirtualExoClass(
24
+ 'UpCounter',
25
+ UpCounterI,
26
+ /** @param {number} x */
27
+ (x = 0) => ({ x }),
28
+ {
29
+ incr(y = 1) {
30
+ const { state } = this;
31
+ state.x += y;
32
+ return state.x;
33
+ },
34
+ },
35
+ {
36
+ receiveInstanceTester(i) {
37
+ isInstance = i;
38
+ },
39
+ },
40
+ );
41
+ // @ts-expect-error TS thinks it is used before assigned, which is a hazard
42
+ // TS is correct to bring to our attention, since there is not enough static
43
+ // into to infer otherwise.
44
+ assert(isInstance !== undefined);
45
+
46
+ t.is(isInstance(harden({})), false);
47
+ t.throws(() => isInstance(harden({}), 'up'), {
48
+ message:
49
+ 'facetName can only be used with an exo class kit: "UpCounter" has no facet "up"',
50
+ });
51
+
52
+ const upCounter = makeUpCounter(3);
53
+
54
+ t.is(isInstance(upCounter), true);
55
+ t.throws(() => isInstance(upCounter, 'up'), {
56
+ message:
57
+ 'facetName can only be used with an exo class kit: "UpCounter" has no facet "up"',
58
+ });
59
+ });
60
+
61
+ test('test isInstance defineVirtualExoClassKit', t => {
62
+ /** @type {import('@endo/exo').IsInstance} */
63
+ let isInstance;
64
+ const makeCounterKit = defineVirtualExoClassKit(
65
+ 'Counter',
66
+ { up: UpCounterI, down: DownCounterI },
67
+ /** @param {number} x */
68
+ (x = 0) => ({ x }),
69
+ {
70
+ up: {
71
+ incr(y = 1) {
72
+ const { state } = this;
73
+ state.x += y;
74
+ return state.x;
75
+ },
76
+ },
77
+ down: {
78
+ decr(y = 1) {
79
+ const { state } = this;
80
+ state.x -= y;
81
+ return state.x;
82
+ },
83
+ },
84
+ },
85
+ {
86
+ receiveInstanceTester(i) {
87
+ isInstance = i;
88
+ },
89
+ },
90
+ );
91
+ // @ts-expect-error TS thinks it is used before assigned, which is a hazard
92
+ // TS is correct to bring to our attention, since there is not enough static
93
+ // into to infer otherwise.
94
+ assert(isInstance !== undefined);
95
+
96
+ t.is(isInstance(harden({})), false);
97
+ t.is(isInstance(harden({}), 'up'), false);
98
+ t.throws(() => isInstance(harden({}), 'foo'), {
99
+ message: 'exo class kit "Counter" has no facet named "foo"',
100
+ });
101
+
102
+ const { up: upCounter } = makeCounterKit(3);
103
+
104
+ t.is(isInstance(upCounter), true);
105
+ t.is(isInstance(upCounter, 'up'), true);
106
+ t.is(isInstance(upCounter, 'down'), false);
107
+ t.throws(() => isInstance(upCounter, 'foo'), {
108
+ message: 'exo class kit "Counter" has no facet named "foo"',
109
+ });
110
+ });
@@ -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,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: {
@@ -1,7 +1,12 @@
1
- import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';
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 };
2
8
 
3
9
  test('methods available', async t => {
4
10
  const { defineKind } = await import('../src/index.js');
5
- defineKind('test', () => {}, {});
6
- t.pass();
11
+ t.is(defineKind, mockDefineKind);
7
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
  });
@@ -16,7 +16,7 @@ test('scalar maps should reject non-scalar keys', t => {
16
16
 
17
17
  test('scalar big maps should reject non-scalar keys', t => {
18
18
  const bigMap = makeScalarBigMapStore('dummy', { keyShape: M.key() });
19
- t.throws(() => bigMap.init(harden({ label: 'not a scalar' })), {
19
+ t.throws(() => bigMap.init(harden({ label: 'not a scalar' }), null), {
20
20
  message:
21
21
  /A "copyRecord" cannot be a scalar key: \{"label":"not a scalar"\}/,
22
22
  });
@@ -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: {
package/tsconfig.json CHANGED
@@ -1,8 +1,9 @@
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
+ // "strict": true, // disabled for compat with >0 module depth
6
+ // "noImplicitAny": false, // for compat with peer packages using ambient types
6
7
  },
7
8
  "include": [
8
9
  "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/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>;