@agoric/vat-data 0.5.3-other-dev-8f8782b.0 → 0.5.3-other-dev-3eb1a1d.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 +0 -8
- package/package.json +25 -10
- package/src/exo-utils.js +116 -63
- package/src/index.js +10 -4
- package/src/index.test-d.ts +38 -9
- package/src/vat-data-bindings.js +55 -73
- package/test/absent.test.js +6 -2
- package/test/amplify-virtual-class-kits.test.js +90 -0
- package/test/{test-durable-classes.js → durable-classes.test.js} +6 -4
- package/test/is-instance-virtual-class-kits.test.js +110 -0
- package/test/prepare-test-env-ava.js +7 -0
- package/test/prepare-test-env.js +1 -0
- package/test/{test-prepare.js → prepare.test.js} +5 -3
- package/test/present.test.js +8 -3
- package/test/{test-scalar-only-keys.js → scalar-only-keys.test.js} +4 -4
- package/test/{test-virtual-classes.js → virtual-classes.test.js} +5 -3
- package/tsconfig.json +3 -2
- package/typedoc.json +8 -0
- package/src/types.d.ts +0 -203
package/CHANGELOG.md
CHANGED
|
@@ -3,14 +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-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)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
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)
|
|
15
7
|
|
|
16
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-other-dev-
|
|
3
|
+
"version": "0.5.3-other-dev-3eb1a1d.0+3eb1a1d",
|
|
4
4
|
"description": "Safe access to VatData global",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": "https://github.com/Agoric/agoric-sdk",
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "exit 0",
|
|
10
10
|
"test": "ava",
|
|
11
|
-
"test:c8": "exit 0",
|
|
12
11
|
"test:xs": "exit 0",
|
|
13
12
|
"lint-fix": "yarn lint:eslint --fix",
|
|
14
13
|
"lint": "run-s --continue-on-error lint:*",
|
|
@@ -19,20 +18,36 @@
|
|
|
19
18
|
"author": "Agoric",
|
|
20
19
|
"license": "Apache-2.0",
|
|
21
20
|
"dependencies": {
|
|
22
|
-
"@agoric/
|
|
23
|
-
"@agoric/
|
|
24
|
-
"@agoric/
|
|
21
|
+
"@agoric/base-zone": "0.1.1-other-dev-3eb1a1d.0+3eb1a1d",
|
|
22
|
+
"@agoric/store": "0.9.3-other-dev-3eb1a1d.0+3eb1a1d",
|
|
23
|
+
"@agoric/swingset-liveslots": "0.10.3-other-dev-3eb1a1d.0+3eb1a1d",
|
|
24
|
+
"@endo/errors": "^1.2.8",
|
|
25
|
+
"@endo/exo": "^1.5.7",
|
|
26
|
+
"@endo/patterns": "^1.4.7"
|
|
25
27
|
},
|
|
26
28
|
"devDependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"
|
|
29
|
-
"
|
|
29
|
+
"@endo/far": "^1.1.9",
|
|
30
|
+
"@endo/init": "^1.1.7",
|
|
31
|
+
"@endo/ses-ava": "^1.2.8",
|
|
32
|
+
"ava": "^5.3.0",
|
|
33
|
+
"tsd": "^0.31.1"
|
|
34
|
+
},
|
|
35
|
+
"ava": {
|
|
36
|
+
"require": [
|
|
37
|
+
"@endo/init/debug.js"
|
|
38
|
+
],
|
|
39
|
+
"files": [
|
|
40
|
+
"test/**/*.test.*"
|
|
41
|
+
]
|
|
30
42
|
},
|
|
31
43
|
"publishConfig": {
|
|
32
44
|
"access": "public"
|
|
33
45
|
},
|
|
34
46
|
"engines": {
|
|
35
|
-
"node": "
|
|
47
|
+
"node": "^18.12 || ^20.9"
|
|
48
|
+
},
|
|
49
|
+
"typeCoverage": {
|
|
50
|
+
"atLeast": 99.33
|
|
36
51
|
},
|
|
37
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "3eb1a1d2d75b2b4a94807cd3bf759bc9fc531f05"
|
|
38
53
|
}
|
package/src/exo-utils.js
CHANGED
|
@@ -4,19 +4,28 @@ import { initEmpty } from '@agoric/store';
|
|
|
4
4
|
|
|
5
5
|
import { provide, VatData as globalVatData } from './vat-data-bindings.js';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
* Make a version of the argument function that takes a kind context but
|
|
17
|
-
*
|
|
23
|
+
* Make a version of the argument function that takes a kind context but ignores
|
|
24
|
+
* it.
|
|
18
25
|
*
|
|
19
|
-
* @type {<T extends
|
|
26
|
+
* @type {<T extends (...args: any) => any>(
|
|
27
|
+
* fn: T,
|
|
28
|
+
* ) => import('@agoric/swingset-liveslots').PlusContext<never, T>}
|
|
20
29
|
*/
|
|
21
30
|
export const ignoreContext =
|
|
22
31
|
fn =>
|
|
@@ -25,6 +34,7 @@ export const ignoreContext =
|
|
|
25
34
|
harden(ignoreContext);
|
|
26
35
|
|
|
27
36
|
// TODO: Find a good home for this function used by @agoric/vat-data and testing code
|
|
37
|
+
/** @param {import('@agoric/swingset-liveslots').VatData} VatData */
|
|
28
38
|
export const makeExoUtils = VatData => {
|
|
29
39
|
const {
|
|
30
40
|
defineKind,
|
|
@@ -35,6 +45,7 @@ export const makeExoUtils = VatData => {
|
|
|
35
45
|
} = VatData;
|
|
36
46
|
|
|
37
47
|
/**
|
|
48
|
+
* @deprecated Use Exos/ExoClasses instead of Kinds
|
|
38
49
|
* @param {Baggage} baggage
|
|
39
50
|
* @param {string} kindName
|
|
40
51
|
* @returns {DurableKindHandle}
|
|
@@ -45,7 +56,7 @@ export const makeExoUtils = VatData => {
|
|
|
45
56
|
|
|
46
57
|
/**
|
|
47
58
|
* @deprecated Use prepareExoClass instead
|
|
48
|
-
* @type {import('
|
|
59
|
+
* @type {import('@agoric/swingset-liveslots').PrepareKind}
|
|
49
60
|
*/
|
|
50
61
|
const prepareKind = (
|
|
51
62
|
baggage,
|
|
@@ -64,7 +75,7 @@ export const makeExoUtils = VatData => {
|
|
|
64
75
|
|
|
65
76
|
/**
|
|
66
77
|
* @deprecated Use prepareExoClassKit instead
|
|
67
|
-
* @type {import('
|
|
78
|
+
* @type {import('@agoric/swingset-liveslots').PrepareKindMulti}
|
|
68
79
|
*/
|
|
69
80
|
const prepareKindMulti = (
|
|
70
81
|
baggage,
|
|
@@ -81,18 +92,25 @@ export const makeExoUtils = VatData => {
|
|
|
81
92
|
);
|
|
82
93
|
harden(prepareKindMulti);
|
|
83
94
|
|
|
84
|
-
// TODO interfaceGuard type https://github.com/Agoric/agoric-sdk/issues/6206
|
|
85
95
|
/**
|
|
86
|
-
* @template {
|
|
96
|
+
* @template {InitState} I init state function
|
|
87
97
|
* @template T behavior
|
|
88
98
|
* @param {string} tag
|
|
89
|
-
* @param {
|
|
99
|
+
* @param {InterfaceGuard | undefined} interfaceGuard
|
|
90
100
|
* @param {I} init
|
|
91
|
-
* @param {T &
|
|
92
|
-
*
|
|
93
|
-
*
|
|
101
|
+
* @param {T &
|
|
102
|
+
* ThisType<{
|
|
103
|
+
* self: T;
|
|
104
|
+
* state: StateResult<I>;
|
|
105
|
+
* }>} methods
|
|
106
|
+
* @param {DefineKindOptions<{
|
|
107
|
+
* self: T;
|
|
108
|
+
* state: StateResult<I>;
|
|
109
|
+
* }>} [options]
|
|
110
|
+
* @returns {(...args: Parameters<I>) => import('@endo/exo').Guarded<T>}
|
|
94
111
|
*/
|
|
95
112
|
const defineVirtualExoClass = (tag, interfaceGuard, init, methods, options) =>
|
|
113
|
+
// @ts-expect-error cast
|
|
96
114
|
defineKind(tag, init, methods, {
|
|
97
115
|
...options,
|
|
98
116
|
thisfulMethods: true,
|
|
@@ -100,16 +118,22 @@ export const makeExoUtils = VatData => {
|
|
|
100
118
|
});
|
|
101
119
|
harden(defineVirtualExoClass);
|
|
102
120
|
|
|
103
|
-
// TODO interfaceGuard type https://github.com/Agoric/agoric-sdk/issues/6206
|
|
104
121
|
/**
|
|
105
|
-
* @template {
|
|
106
|
-
* @template {Record<string, Record<
|
|
122
|
+
* @template {InitState} I init state function
|
|
123
|
+
* @template {Record<string, Record<PropertyKey, CallableFunction>>} T facets
|
|
107
124
|
* @param {string} tag
|
|
108
|
-
* @param {
|
|
125
|
+
* @param {InterfaceGuardKit | undefined} interfaceGuardKit
|
|
109
126
|
* @param {I} init
|
|
110
|
-
* @param {T &
|
|
111
|
-
*
|
|
112
|
-
* @
|
|
127
|
+
* @param {T &
|
|
128
|
+
* ThisType<{
|
|
129
|
+
* facets: import('@endo/exo').GuardedKit<T>;
|
|
130
|
+
* state: StateResult<I>;
|
|
131
|
+
* }>} facets
|
|
132
|
+
* @param {DefineKindOptions<{
|
|
133
|
+
* facets: T;
|
|
134
|
+
* state: StateResult<I>;
|
|
135
|
+
* }>} [options]
|
|
136
|
+
* @returns {(...args: Parameters<I>) => import('@endo/exo').GuardedKit<T>}
|
|
113
137
|
*/
|
|
114
138
|
const defineVirtualExoClassKit = (
|
|
115
139
|
tag,
|
|
@@ -118,23 +142,30 @@ export const makeExoUtils = VatData => {
|
|
|
118
142
|
facets,
|
|
119
143
|
options,
|
|
120
144
|
) =>
|
|
145
|
+
// @ts-expect-error cast
|
|
121
146
|
defineKindMulti(tag, init, facets, {
|
|
122
147
|
...options,
|
|
123
148
|
thisfulMethods: true,
|
|
124
|
-
|
|
149
|
+
interfaceGuardKit,
|
|
125
150
|
});
|
|
126
151
|
harden(defineVirtualExoClassKit);
|
|
127
152
|
|
|
128
|
-
// TODO interfaceGuard type https://github.com/Agoric/agoric-sdk/issues/6206
|
|
129
153
|
/**
|
|
130
|
-
* @template {
|
|
131
|
-
* @template {Record<
|
|
154
|
+
* @template {InitState} I init state function
|
|
155
|
+
* @template {Record<PropertyKey, CallableFunction>} T methods
|
|
132
156
|
* @param {DurableKindHandle} kindHandle
|
|
133
|
-
* @param {
|
|
157
|
+
* @param {InterfaceGuard | undefined} interfaceGuard
|
|
134
158
|
* @param {I} init
|
|
135
|
-
* @param {T &
|
|
136
|
-
*
|
|
137
|
-
*
|
|
159
|
+
* @param {T &
|
|
160
|
+
* ThisType<{
|
|
161
|
+
* self: T;
|
|
162
|
+
* state: StateResult<I>;
|
|
163
|
+
* }>} methods
|
|
164
|
+
* @param {DefineKindOptions<{
|
|
165
|
+
* self: T;
|
|
166
|
+
* state: StateResult<I>;
|
|
167
|
+
* }>} [options]
|
|
168
|
+
* @returns {(...args: Parameters<I>) => import('@endo/exo').Guarded<T>}
|
|
138
169
|
*/
|
|
139
170
|
const defineDurableExoClass = (
|
|
140
171
|
kindHandle,
|
|
@@ -143,6 +174,7 @@ export const makeExoUtils = VatData => {
|
|
|
143
174
|
methods,
|
|
144
175
|
options,
|
|
145
176
|
) =>
|
|
177
|
+
// @ts-expect-error cast
|
|
146
178
|
defineDurableKind(kindHandle, init, methods, {
|
|
147
179
|
...options,
|
|
148
180
|
thisfulMethods: true,
|
|
@@ -150,16 +182,22 @@ export const makeExoUtils = VatData => {
|
|
|
150
182
|
});
|
|
151
183
|
harden(defineDurableExoClass);
|
|
152
184
|
|
|
153
|
-
// TODO interfaceGuard type https://github.com/Agoric/agoric-sdk/issues/6206
|
|
154
185
|
/**
|
|
155
|
-
* @template {
|
|
156
|
-
* @template {Record<string, Record<
|
|
186
|
+
* @template {InitState} I init state function
|
|
187
|
+
* @template {Record<string, Record<PropertyKey, CallableFunction>>} T facets
|
|
157
188
|
* @param {DurableKindHandle} kindHandle
|
|
158
|
-
* @param {
|
|
189
|
+
* @param {InterfaceGuardKit | undefined} interfaceGuardKit
|
|
159
190
|
* @param {I} init
|
|
160
|
-
* @param {T &
|
|
161
|
-
*
|
|
162
|
-
* @
|
|
191
|
+
* @param {T &
|
|
192
|
+
* ThisType<{
|
|
193
|
+
* facets: import('@endo/exo').GuardedKit<T>;
|
|
194
|
+
* state: StateResult<I>;
|
|
195
|
+
* }>} facets
|
|
196
|
+
* @param {DefineKindOptions<{
|
|
197
|
+
* facets: T;
|
|
198
|
+
* state: StateResult<I>;
|
|
199
|
+
* }>} [options]
|
|
200
|
+
* @returns {(...args: Parameters<I>) => import('@endo/exo').GuardedKit<T>}
|
|
163
201
|
*/
|
|
164
202
|
const defineDurableExoClassKit = (
|
|
165
203
|
kindHandle,
|
|
@@ -168,24 +206,31 @@ export const makeExoUtils = VatData => {
|
|
|
168
206
|
facets,
|
|
169
207
|
options,
|
|
170
208
|
) =>
|
|
209
|
+
// @ts-expect-error cast
|
|
171
210
|
defineDurableKindMulti(kindHandle, init, facets, {
|
|
172
211
|
...options,
|
|
173
212
|
thisfulMethods: true,
|
|
174
|
-
|
|
213
|
+
interfaceGuardKit,
|
|
175
214
|
});
|
|
176
215
|
harden(defineDurableExoClassKit);
|
|
177
216
|
|
|
178
|
-
// TODO interfaceGuard type https://github.com/Agoric/agoric-sdk/issues/6206
|
|
179
217
|
/**
|
|
180
|
-
* @template {
|
|
181
|
-
* @template {Record<
|
|
218
|
+
* @template {InitState} I init state function
|
|
219
|
+
* @template {Record<PropertyKey, CallableFunction>} T methods
|
|
182
220
|
* @param {Baggage} baggage
|
|
183
221
|
* @param {string} kindName
|
|
184
|
-
* @param {
|
|
222
|
+
* @param {InterfaceGuard | undefined} interfaceGuard
|
|
185
223
|
* @param {I} init
|
|
186
|
-
* @param {T &
|
|
187
|
-
*
|
|
188
|
-
*
|
|
224
|
+
* @param {T &
|
|
225
|
+
* ThisType<{
|
|
226
|
+
* self: RemotableObject & T;
|
|
227
|
+
* state: StateResult<I>;
|
|
228
|
+
* }>} methods
|
|
229
|
+
* @param {DefineKindOptions<{
|
|
230
|
+
* self: T;
|
|
231
|
+
* state: StateResult<I>;
|
|
232
|
+
* }>} [options]
|
|
233
|
+
* @returns {(...args: Parameters<I>) => import('@endo/exo').Guarded<T>}
|
|
189
234
|
*/
|
|
190
235
|
const prepareExoClass = (
|
|
191
236
|
baggage,
|
|
@@ -204,17 +249,23 @@ export const makeExoUtils = VatData => {
|
|
|
204
249
|
);
|
|
205
250
|
harden(prepareExoClass);
|
|
206
251
|
|
|
207
|
-
// TODO interfaceGuard type https://github.com/Agoric/agoric-sdk/issues/6206
|
|
208
252
|
/**
|
|
209
|
-
* @template {
|
|
210
|
-
* @template {Record<string, Record<
|
|
253
|
+
* @template {InitState} I init state function
|
|
254
|
+
* @template {Record<string, Record<PropertyKey, CallableFunction>>} T facets
|
|
211
255
|
* @param {Baggage} baggage
|
|
212
256
|
* @param {string} kindName
|
|
213
|
-
* @param {
|
|
257
|
+
* @param {InterfaceGuardKit | undefined} interfaceGuardKit
|
|
214
258
|
* @param {I} init
|
|
215
|
-
* @param {T &
|
|
216
|
-
*
|
|
217
|
-
* @
|
|
259
|
+
* @param {T &
|
|
260
|
+
* ThisType<{
|
|
261
|
+
* facets: import('@endo/exo').GuardedKit<T>;
|
|
262
|
+
* state: StateResult<I>;
|
|
263
|
+
* }>} facets
|
|
264
|
+
* @param {DefineKindOptions<{
|
|
265
|
+
* facets: T;
|
|
266
|
+
* state: StateResult<I>;
|
|
267
|
+
* }>} [options]
|
|
268
|
+
* @returns {(...args: Parameters<I>) => import('@endo/exo').GuardedKit<T>}
|
|
218
269
|
*/
|
|
219
270
|
const prepareExoClassKit = (
|
|
220
271
|
baggage,
|
|
@@ -233,15 +284,17 @@ export const makeExoUtils = VatData => {
|
|
|
233
284
|
);
|
|
234
285
|
harden(prepareExoClassKit);
|
|
235
286
|
|
|
236
|
-
// TODO interfaceGuard type https://github.com/Agoric/agoric-sdk/issues/6206
|
|
237
287
|
/**
|
|
238
|
-
* @template {Record<
|
|
288
|
+
* @template {Record<PropertyKey, CallableFunction>} M methods
|
|
239
289
|
* @param {Baggage} baggage
|
|
240
290
|
* @param {string} kindName
|
|
241
|
-
* @param {
|
|
242
|
-
* @param {M
|
|
291
|
+
* @param {InterfaceGuard | undefined} interfaceGuard
|
|
292
|
+
* @param {M &
|
|
293
|
+
* ThisType<{
|
|
294
|
+
* self: RemotableObject & M;
|
|
295
|
+
* }>} methods
|
|
243
296
|
* @param {DefineKindOptions<{ self: M }>} [options]
|
|
244
|
-
* @returns {
|
|
297
|
+
* @returns {import('@endo/exo').Guarded<M>}
|
|
245
298
|
*/
|
|
246
299
|
const prepareExo = (
|
|
247
300
|
baggage,
|
|
@@ -264,13 +317,13 @@ export const makeExoUtils = VatData => {
|
|
|
264
317
|
harden(prepareExo);
|
|
265
318
|
|
|
266
319
|
/**
|
|
267
|
-
* @template {Record<string | symbol, CallableFunction>} M methods
|
|
268
320
|
* @deprecated Use prepareExo instead.
|
|
321
|
+
* @template {Record<PropertyKey, CallableFunction>} M methods
|
|
269
322
|
* @param {Baggage} baggage
|
|
270
323
|
* @param {string} kindName
|
|
271
324
|
* @param {M} methods
|
|
272
325
|
* @param {DefineKindOptions<{ self: M }>} [options]
|
|
273
|
-
* @returns {
|
|
326
|
+
* @returns {import('@endo/exo').Guarded<M>}
|
|
274
327
|
*/
|
|
275
328
|
const prepareSingleton = (baggage, kindName, methods, options = undefined) =>
|
|
276
329
|
prepareExo(baggage, kindName, undefined, methods, options);
|
|
@@ -284,8 +337,8 @@ export const makeExoUtils = VatData => {
|
|
|
284
337
|
prepareExoClass,
|
|
285
338
|
prepareExoClassKit,
|
|
286
339
|
prepareExo,
|
|
287
|
-
prepareSingleton,
|
|
288
340
|
|
|
341
|
+
prepareSingleton,
|
|
289
342
|
provideKindHandle,
|
|
290
343
|
prepareKind,
|
|
291
344
|
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,15 @@ export {
|
|
|
42
42
|
prepareSingleton,
|
|
43
43
|
} from './exo-utils.js';
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
|
|
45
|
+
// TODO re-export these
|
|
46
|
+
/**
|
|
47
|
+
* @template T @typedef
|
|
48
|
+
* {import('@agoric/swingset-liveslots').DefineKindOptions<T>}
|
|
49
|
+
* DefineKindOptions
|
|
50
|
+
*/
|
|
51
|
+
// Copy this type because aliasing it by `import('@agoric/swingset-liveslots').Baggage`
|
|
52
|
+
// causes this error in typedoc: Expected a symbol for node with kind Identifier
|
|
53
|
+
/** @typedef {MapStore<string, any>} Baggage */
|
|
48
54
|
|
|
49
55
|
// //////////////////////////// deprecated /////////////////////////////////////
|
|
50
56
|
|
package/src/index.test-d.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
/* eslint-disable no-use-before-define, import/no-extraneous-dependencies */
|
|
2
1
|
import { expectType } from 'tsd';
|
|
2
|
+
import type {
|
|
3
|
+
KindFacets,
|
|
4
|
+
DurableKindHandle,
|
|
5
|
+
KindFacet,
|
|
6
|
+
FunctionsPlusContext,
|
|
7
|
+
} from '@agoric/swingset-liveslots';
|
|
8
|
+
import type { VirtualObjectManager } from '@agoric/swingset-liveslots/src/virtualObjectManager.js';
|
|
3
9
|
import {
|
|
4
10
|
defineKind,
|
|
5
11
|
defineKindMulti,
|
|
6
12
|
makeKindHandle,
|
|
7
13
|
defineDurableKind,
|
|
8
14
|
partialAssign,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
FunctionsPlusContext,
|
|
15
|
-
} from './types.js';
|
|
15
|
+
watchPromise,
|
|
16
|
+
} from './index.js';
|
|
17
|
+
|
|
18
|
+
// for use in assignments below
|
|
19
|
+
const anyVal = null as any;
|
|
16
20
|
|
|
17
21
|
/*
|
|
18
22
|
export const makePaymentMaker = (allegedName: string, brand: unknown) => {
|
|
@@ -154,7 +158,32 @@ const someBehavior: FunctionsPlusContext<SomeContext, SomeFacet> = {
|
|
|
154
158
|
return b > context.state.a;
|
|
155
159
|
},
|
|
156
160
|
};
|
|
157
|
-
const someFacet: KindFacet<typeof someBehavior> =
|
|
161
|
+
const someFacet: KindFacet<typeof someBehavior> = anyVal;
|
|
158
162
|
// @ts-expect-error
|
|
159
163
|
someFacet.gt();
|
|
160
164
|
expectType<boolean>(someFacet.gt(1));
|
|
165
|
+
|
|
166
|
+
const vom: VirtualObjectManager = anyVal;
|
|
167
|
+
// @ts-expect-error
|
|
168
|
+
vom.missingMethod;
|
|
169
|
+
// @ts-expect-error Expected 0-4 arguments but got 5
|
|
170
|
+
vom.defineDurableKind(anyVal, anyVal, anyVal, anyVal, 'extra');
|
|
171
|
+
|
|
172
|
+
const p: Promise<bigint> = anyVal;
|
|
173
|
+
watchPromise(
|
|
174
|
+
p,
|
|
175
|
+
{
|
|
176
|
+
onFulfilled(value, extra1, extra2) {
|
|
177
|
+
expectType<bigint>(value);
|
|
178
|
+
expectType<string>(extra1);
|
|
179
|
+
// @ts-expect-error str
|
|
180
|
+
expectType<number>(extra2);
|
|
181
|
+
},
|
|
182
|
+
onRejected(reason, extra1) {
|
|
183
|
+
expectType<unknown>(reason);
|
|
184
|
+
expectType<string>(extra1);
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
'extraString',
|
|
188
|
+
'alsoString',
|
|
189
|
+
);
|
package/src/vat-data-bindings.js
CHANGED
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
/* global globalThis */
|
|
2
2
|
|
|
3
|
-
import { Fail } from '@
|
|
3
|
+
import { Fail } from '@endo/errors';
|
|
4
4
|
import { provideLazy } from '@agoric/store';
|
|
5
5
|
|
|
6
|
-
/** @
|
|
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
|
-
|
|
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
|
|
18
|
+
const unavailable = () => Fail`VatData unavailable`;
|
|
16
19
|
VatDataGlobal = {
|
|
17
|
-
defineKind:
|
|
18
|
-
defineKindMulti:
|
|
19
|
-
defineDurableKind:
|
|
20
|
-
defineDurableKindMulti:
|
|
21
|
-
makeKindHandle:
|
|
22
|
-
providePromiseWatcher:
|
|
23
|
-
watchPromise:
|
|
24
|
-
makeScalarBigMapStore:
|
|
25
|
-
makeScalarBigWeakMapStore:
|
|
26
|
-
makeScalarBigSetStore:
|
|
27
|
-
makeScalarBigWeakSetStore:
|
|
28
|
-
canBeDurable:
|
|
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
|
|
|
@@ -54,7 +57,8 @@ export const {
|
|
|
54
57
|
} = VatDataGlobal;
|
|
55
58
|
|
|
56
59
|
/**
|
|
57
|
-
* When making a multi-facet kind, it's common to pick one facet to expose.
|
|
60
|
+
* When making a multi-facet kind, it's common to pick one facet to expose.
|
|
61
|
+
* E.g.,
|
|
58
62
|
*
|
|
59
63
|
* const makeFoo = (a, b, c, d) => makeFooBase(a, b, c, d).self;
|
|
60
64
|
*
|
|
@@ -62,7 +66,7 @@ export const {
|
|
|
62
66
|
*
|
|
63
67
|
* const makeFoo = pickFacet(makeFooBase, 'self');
|
|
64
68
|
*
|
|
65
|
-
* @type {
|
|
69
|
+
* @type {PickFacet}
|
|
66
70
|
*/
|
|
67
71
|
export const pickFacet =
|
|
68
72
|
(maker, facetName) =>
|
|
@@ -83,67 +87,45 @@ export const partialAssign = (target, source) => {
|
|
|
83
87
|
};
|
|
84
88
|
harden(partialAssign);
|
|
85
89
|
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
*/
|
|
90
|
+
/** @import {StoreOptions} from '@agoric/store' */
|
|
91
|
+
|
|
113
92
|
/**
|
|
114
|
-
* Unlike `provideLazy`, `provide` should be called at most once
|
|
115
|
-
*
|
|
93
|
+
* Unlike `provideLazy`, `provide` should be called at most once within any vat
|
|
94
|
+
* incarnation with a given `baggage`,`key` pair.
|
|
95
|
+
*
|
|
96
|
+
* `provide` should only be used to populate baggage, where the total number of
|
|
97
|
+
* calls to `provide` must be low cardinality, since we keep the bookkeeping to
|
|
98
|
+
* detect collisions in normal language-heap memory. All the other
|
|
99
|
+
* baggage-oriented `provide*` and `prepare*` functions call `provide`, and so
|
|
100
|
+
* impose the same constraints. This is consistent with our expected durability
|
|
101
|
+
* patterns: What we store in baggage are
|
|
116
102
|
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* `provide*` and `prepare*` functions call `provide`,
|
|
122
|
-
* and so impose the same constraints. This is consistent with
|
|
123
|
-
* our expected durability patterns: What we store in baggage are
|
|
124
|
-
* * kindHandles, which are per kind, which must be low cardinality
|
|
125
|
-
* * data "variables" for reestablishing the lexical scope, especially
|
|
126
|
-
* of singletons
|
|
127
|
-
* * named non-baggage collections at the leaves of the baggage tree.
|
|
103
|
+
* - kindHandles, which are per kind, which must be low cardinality
|
|
104
|
+
* - data "variables" for reestablishing the lexical scope, especially of
|
|
105
|
+
* singletons
|
|
106
|
+
* - named non-baggage collections at the leaves of the baggage tree.
|
|
128
107
|
*
|
|
129
|
-
* What is expected to be high cardinality are the instances of the kinds,
|
|
130
|
-
*
|
|
108
|
+
* What is expected to be high cardinality are the instances of the kinds, and
|
|
109
|
+
* the members of the non-bagggage collections.
|
|
131
110
|
*
|
|
132
|
-
* TODO https://github.com/Agoric/agoric-sdk/pull/5875 :
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* baggage,key pair.
|
|
111
|
+
* TODO https://github.com/Agoric/agoric-sdk/pull/5875 : Implement
|
|
112
|
+
* development-time instrumentation to detect when `provide` violates the above
|
|
113
|
+
* prescription, and is called more than once in the same vat incarnation with
|
|
114
|
+
* the same baggage,key pair.
|
|
137
115
|
*/
|
|
138
116
|
|
|
139
117
|
export const provide =
|
|
140
118
|
// XXX cast because provideLazy is `any` due to broken type import
|
|
141
|
-
/**
|
|
142
|
-
|
|
143
|
-
|
|
119
|
+
/**
|
|
120
|
+
* @type {<K, V>(
|
|
121
|
+
* baggage: Baggage,
|
|
122
|
+
* key: K,
|
|
123
|
+
* makeValue: (key: K) => V,
|
|
124
|
+
* ) => V}
|
|
125
|
+
*/ (provideLazy);
|
|
144
126
|
|
|
145
127
|
// TODO: Find a good home for this function used by @agoric/vat-data and testing code
|
|
146
|
-
/** @param {
|
|
128
|
+
/** @param {VatData} VatData */
|
|
147
129
|
export const makeStoreUtils = VatData => {
|
|
148
130
|
const {
|
|
149
131
|
// eslint-disable-next-line no-shadow -- these literally do shadow the globals
|
|
@@ -157,7 +139,7 @@ export const makeStoreUtils = VatData => {
|
|
|
157
139
|
} = VatData;
|
|
158
140
|
|
|
159
141
|
/**
|
|
160
|
-
* @param {
|
|
142
|
+
* @param {Baggage} baggage
|
|
161
143
|
* @param {string} name
|
|
162
144
|
* @param {Omit<StoreOptions, 'durable'>} options
|
|
163
145
|
*/
|
|
@@ -168,7 +150,7 @@ export const makeStoreUtils = VatData => {
|
|
|
168
150
|
harden(provideDurableMapStore);
|
|
169
151
|
|
|
170
152
|
/**
|
|
171
|
-
* @param {
|
|
153
|
+
* @param {Baggage} baggage
|
|
172
154
|
* @param {string} name
|
|
173
155
|
* @param {Omit<StoreOptions, 'durable'>} options
|
|
174
156
|
*/
|
|
@@ -179,7 +161,7 @@ export const makeStoreUtils = VatData => {
|
|
|
179
161
|
harden(provideDurableWeakMapStore);
|
|
180
162
|
|
|
181
163
|
/**
|
|
182
|
-
* @param {
|
|
164
|
+
* @param {Baggage} baggage
|
|
183
165
|
* @param {string} name
|
|
184
166
|
* @param {Omit<StoreOptions, 'durable'>} options
|
|
185
167
|
*/
|
|
@@ -190,7 +172,7 @@ export const makeStoreUtils = VatData => {
|
|
|
190
172
|
harden(provideDurableSetStore);
|
|
191
173
|
|
|
192
174
|
/**
|
|
193
|
-
* @param {
|
|
175
|
+
* @param {Baggage} baggage
|
|
194
176
|
* @param {string} name
|
|
195
177
|
* @param {Omit<StoreOptions, 'durable'>} options
|
|
196
178
|
*/
|
package/test/absent.test.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import
|
|
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,
|
|
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 '
|
|
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 @@
|
|
|
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 '
|
|
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: {
|
package/test/present.test.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import
|
|
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
|
|
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 '
|
|
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 '
|
|
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
|
-
|
|
5
|
-
"
|
|
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
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>;
|