@agoric/vat-data 0.6.0 → 0.6.1-upgrade-23-dev-bd79330.0.bd79330
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/package.json +10 -7
- package/src/exo-utils.js +21 -17
- package/src/index.js +6 -5
- package/CHANGELOG.md +0 -119
- package/src/index.test-d.ts +0 -189
- package/test/absent.test.js +0 -13
- package/test/amplify-virtual-class-kits.test.js +0 -90
- package/test/durable-classes.test.js +0 -147
- package/test/is-instance-virtual-class-kits.test.js +0 -110
- package/test/prepare-test-env-ava.js +0 -7
- package/test/prepare-test-env.js +0 -1
- package/test/prepare.test.js +0 -132
- package/test/present.test.js +0 -12
- package/test/scalar-only-keys.test.js +0 -23
- package/test/virtual-classes.test.js +0 -100
- package/tsconfig.json +0 -13
- package/typedoc.json +0 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/vat-data",
|
|
3
|
-
"version": "0.6.0",
|
|
3
|
+
"version": "0.6.1-upgrade-23-dev-bd79330.0.bd79330",
|
|
4
4
|
"description": "Safe access to VatData global",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": "https://github.com/Agoric/agoric-sdk",
|
|
@@ -11,16 +11,16 @@
|
|
|
11
11
|
"test:xs": "exit 0",
|
|
12
12
|
"lint-fix": "yarn lint:eslint --fix",
|
|
13
13
|
"lint": "yarn run -T run-s --continue-on-error 'lint:*'",
|
|
14
|
-
"lint:eslint": "
|
|
14
|
+
"lint:eslint": "node ../../scripts/eslint-repo.mjs .",
|
|
15
15
|
"lint:types": "yarn run -T tsc"
|
|
16
16
|
},
|
|
17
17
|
"keywords": [],
|
|
18
18
|
"author": "Agoric",
|
|
19
19
|
"license": "Apache-2.0",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@agoric/base-zone": "0.2.0",
|
|
22
|
-
"@agoric/store": "0.10.0",
|
|
23
|
-
"@agoric/swingset-liveslots": "0.11.0",
|
|
21
|
+
"@agoric/base-zone": "0.2.1-upgrade-23-dev-bd79330.0.bd79330",
|
|
22
|
+
"@agoric/store": "0.10.1-upgrade-23-dev-bd79330.0.bd79330",
|
|
23
|
+
"@agoric/swingset-liveslots": "0.11.1-upgrade-23-dev-bd79330.0.bd79330",
|
|
24
24
|
"@endo/errors": "^1.2.13",
|
|
25
25
|
"@endo/exo": "^1.5.12",
|
|
26
26
|
"@endo/patterns": "^1.7.0"
|
|
@@ -29,9 +29,12 @@
|
|
|
29
29
|
"@endo/far": "^1.1.14",
|
|
30
30
|
"@endo/init": "^1.1.12",
|
|
31
31
|
"@endo/ses-ava": "^1.3.2",
|
|
32
|
-
"ava": "^
|
|
32
|
+
"ava": "^6.4.1",
|
|
33
33
|
"tsd": "^0.33.0"
|
|
34
34
|
},
|
|
35
|
+
"files": [
|
|
36
|
+
"src"
|
|
37
|
+
],
|
|
35
38
|
"ava": {
|
|
36
39
|
"require": [
|
|
37
40
|
"@endo/init/debug.js"
|
|
@@ -49,5 +52,5 @@
|
|
|
49
52
|
"typeCoverage": {
|
|
50
53
|
"atLeast": 99.33
|
|
51
54
|
},
|
|
52
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "bd79330f78dae2faf9cc3d8b10063567700da07b"
|
|
53
56
|
}
|
package/src/exo-utils.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @jessie-check
|
|
2
|
-
|
|
3
1
|
import { initEmpty } from '@agoric/store';
|
|
4
2
|
|
|
5
3
|
import { provide, VatData as globalVatData } from './vat-data-bindings.js';
|
|
@@ -8,6 +6,12 @@ import { provide, VatData as globalVatData } from './vat-data-bindings.js';
|
|
|
8
6
|
* @import {InterfaceGuard} from '@endo/patterns';
|
|
9
7
|
* @import {RemotableObject} from '@endo/pass-style';
|
|
10
8
|
* @import {Baggage, DefineKindOptions, DurableKindHandle, InterfaceGuardKit} from '@agoric/swingset-liveslots';
|
|
9
|
+
* @import {PlusContext} from '@agoric/swingset-liveslots';
|
|
10
|
+
* @import {VatData} from '@agoric/swingset-liveslots';
|
|
11
|
+
* @import {PrepareKind} from '@agoric/swingset-liveslots';
|
|
12
|
+
* @import {PrepareKindMulti} from '@agoric/swingset-liveslots';
|
|
13
|
+
* @import {Guarded} from '@endo/exo';
|
|
14
|
+
* @import {GuardedKit} from '@endo/exo';
|
|
11
15
|
*/
|
|
12
16
|
|
|
13
17
|
// Some feedback if the init function is async
|
|
@@ -25,7 +29,7 @@ import { provide, VatData as globalVatData } from './vat-data-bindings.js';
|
|
|
25
29
|
*
|
|
26
30
|
* @type {<T extends (...args: any) => any>(
|
|
27
31
|
* fn: T,
|
|
28
|
-
* ) =>
|
|
32
|
+
* ) => PlusContext<never, T>}
|
|
29
33
|
*/
|
|
30
34
|
export const ignoreContext =
|
|
31
35
|
fn =>
|
|
@@ -34,7 +38,7 @@ export const ignoreContext =
|
|
|
34
38
|
harden(ignoreContext);
|
|
35
39
|
|
|
36
40
|
// TODO: Find a good home for this function used by @agoric/vat-data and testing code
|
|
37
|
-
/** @param {
|
|
41
|
+
/** @param {VatData} VatData */
|
|
38
42
|
export const makeExoUtils = VatData => {
|
|
39
43
|
const {
|
|
40
44
|
defineKind,
|
|
@@ -56,7 +60,7 @@ export const makeExoUtils = VatData => {
|
|
|
56
60
|
|
|
57
61
|
/**
|
|
58
62
|
* @deprecated Use prepareExoClass instead
|
|
59
|
-
* @type {
|
|
63
|
+
* @type {PrepareKind}
|
|
60
64
|
*/
|
|
61
65
|
const prepareKind = (
|
|
62
66
|
baggage,
|
|
@@ -75,7 +79,7 @@ export const makeExoUtils = VatData => {
|
|
|
75
79
|
|
|
76
80
|
/**
|
|
77
81
|
* @deprecated Use prepareExoClassKit instead
|
|
78
|
-
* @type {
|
|
82
|
+
* @type {PrepareKindMulti}
|
|
79
83
|
*/
|
|
80
84
|
const prepareKindMulti = (
|
|
81
85
|
baggage,
|
|
@@ -107,7 +111,7 @@ export const makeExoUtils = VatData => {
|
|
|
107
111
|
* self: T;
|
|
108
112
|
* state: StateResult<I>;
|
|
109
113
|
* }>} [options]
|
|
110
|
-
* @returns {(...args: Parameters<I>) =>
|
|
114
|
+
* @returns {(...args: Parameters<I>) => Guarded<T>}
|
|
111
115
|
*/
|
|
112
116
|
const defineVirtualExoClass = (tag, interfaceGuard, init, methods, options) =>
|
|
113
117
|
// @ts-expect-error cast
|
|
@@ -126,14 +130,14 @@ export const makeExoUtils = VatData => {
|
|
|
126
130
|
* @param {I} init
|
|
127
131
|
* @param {T &
|
|
128
132
|
* ThisType<{
|
|
129
|
-
* facets:
|
|
133
|
+
* facets: GuardedKit<T>;
|
|
130
134
|
* state: StateResult<I>;
|
|
131
135
|
* }>} facets
|
|
132
136
|
* @param {DefineKindOptions<{
|
|
133
137
|
* facets: T;
|
|
134
138
|
* state: StateResult<I>;
|
|
135
139
|
* }>} [options]
|
|
136
|
-
* @returns {(...args: Parameters<I>) =>
|
|
140
|
+
* @returns {(...args: Parameters<I>) => GuardedKit<T>}
|
|
137
141
|
*/
|
|
138
142
|
const defineVirtualExoClassKit = (
|
|
139
143
|
tag,
|
|
@@ -165,7 +169,7 @@ export const makeExoUtils = VatData => {
|
|
|
165
169
|
* self: T;
|
|
166
170
|
* state: StateResult<I>;
|
|
167
171
|
* }>} [options]
|
|
168
|
-
* @returns {(...args: Parameters<I>) =>
|
|
172
|
+
* @returns {(...args: Parameters<I>) => Guarded<T>}
|
|
169
173
|
*/
|
|
170
174
|
const defineDurableExoClass = (
|
|
171
175
|
kindHandle,
|
|
@@ -190,14 +194,14 @@ export const makeExoUtils = VatData => {
|
|
|
190
194
|
* @param {I} init
|
|
191
195
|
* @param {T &
|
|
192
196
|
* ThisType<{
|
|
193
|
-
* facets:
|
|
197
|
+
* facets: GuardedKit<T>;
|
|
194
198
|
* state: StateResult<I>;
|
|
195
199
|
* }>} facets
|
|
196
200
|
* @param {DefineKindOptions<{
|
|
197
201
|
* facets: T;
|
|
198
202
|
* state: StateResult<I>;
|
|
199
203
|
* }>} [options]
|
|
200
|
-
* @returns {(...args: Parameters<I>) =>
|
|
204
|
+
* @returns {(...args: Parameters<I>) => GuardedKit<T>}
|
|
201
205
|
*/
|
|
202
206
|
const defineDurableExoClassKit = (
|
|
203
207
|
kindHandle,
|
|
@@ -230,7 +234,7 @@ export const makeExoUtils = VatData => {
|
|
|
230
234
|
* self: T;
|
|
231
235
|
* state: StateResult<I>;
|
|
232
236
|
* }>} [options]
|
|
233
|
-
* @returns {(...args: Parameters<I>) =>
|
|
237
|
+
* @returns {(...args: Parameters<I>) => Guarded<T>}
|
|
234
238
|
*/
|
|
235
239
|
const prepareExoClass = (
|
|
236
240
|
baggage,
|
|
@@ -258,14 +262,14 @@ export const makeExoUtils = VatData => {
|
|
|
258
262
|
* @param {I} init
|
|
259
263
|
* @param {T &
|
|
260
264
|
* ThisType<{
|
|
261
|
-
* facets:
|
|
265
|
+
* facets: GuardedKit<T>;
|
|
262
266
|
* state: StateResult<I>;
|
|
263
267
|
* }>} facets
|
|
264
268
|
* @param {DefineKindOptions<{
|
|
265
269
|
* facets: T;
|
|
266
270
|
* state: StateResult<I>;
|
|
267
271
|
* }>} [options]
|
|
268
|
-
* @returns {(...args: Parameters<I>) =>
|
|
272
|
+
* @returns {(...args: Parameters<I>) => GuardedKit<T>}
|
|
269
273
|
*/
|
|
270
274
|
const prepareExoClassKit = (
|
|
271
275
|
baggage,
|
|
@@ -294,7 +298,7 @@ export const makeExoUtils = VatData => {
|
|
|
294
298
|
* self: RemotableObject & M;
|
|
295
299
|
* }>} methods
|
|
296
300
|
* @param {DefineKindOptions<{ self: M }>} [options]
|
|
297
|
-
* @returns {
|
|
301
|
+
* @returns {Guarded<M>}
|
|
298
302
|
*/
|
|
299
303
|
const prepareExo = (
|
|
300
304
|
baggage,
|
|
@@ -323,7 +327,7 @@ export const makeExoUtils = VatData => {
|
|
|
323
327
|
* @param {string} kindName
|
|
324
328
|
* @param {M} methods
|
|
325
329
|
* @param {DefineKindOptions<{ self: M }>} [options]
|
|
326
|
-
* @returns {
|
|
330
|
+
* @returns {Guarded<M>}
|
|
327
331
|
*/
|
|
328
332
|
const prepareSingleton = (baggage, kindName, methods, options = undefined) =>
|
|
329
333
|
prepareExo(baggage, kindName, undefined, methods, options);
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @import {DefineKindOptions} from '@agoric/swingset-liveslots';
|
|
3
|
+
* @import {MapStore} from '@agoric/swingset-liveslots';
|
|
4
|
+
*/
|
|
2
5
|
|
|
3
6
|
/// <reference types="ses" />
|
|
4
7
|
export {
|
|
@@ -44,13 +47,11 @@ export {
|
|
|
44
47
|
|
|
45
48
|
// TODO re-export these
|
|
46
49
|
/**
|
|
47
|
-
* @template T @typedef
|
|
48
|
-
* {import('@agoric/swingset-liveslots').DefineKindOptions<T>}
|
|
49
|
-
* DefineKindOptions
|
|
50
|
+
* @template T @typedef {DefineKindOptions<T>} DefineKindOptions
|
|
50
51
|
*/
|
|
51
52
|
// Copy this type because aliasing it by `import('@agoric/swingset-liveslots').Baggage`
|
|
52
53
|
// causes this error in typedoc: Expected a symbol for node with kind Identifier
|
|
53
|
-
/** @typedef {
|
|
54
|
+
/** @typedef {MapStore<string, any>} Baggage */
|
|
54
55
|
|
|
55
56
|
// //////////////////////////// deprecated /////////////////////////////////////
|
|
56
57
|
|
package/CHANGELOG.md
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
## [0.6.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.6.0-u22.2...@agoric/vat-data@0.6.0) (2026-04-02)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
9
|
-
|
|
10
|
-
## [0.6.0-u22.2](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.6.0-u22.1...@agoric/vat-data@0.6.0-u22.2) (2025-09-09)
|
|
11
|
-
|
|
12
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
13
|
-
|
|
14
|
-
## [0.6.0-u22.1](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.6.0-u22.0...@agoric/vat-data@0.6.0-u22.1) (2025-09-09)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
17
|
-
|
|
18
|
-
## [0.6.0-u22.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.5.2...@agoric/vat-data@0.6.0-u22.0) (2025-09-08)
|
|
19
|
-
|
|
20
|
-
### Features
|
|
21
|
-
|
|
22
|
-
* **liveslots:** virtual exo meta-ops ([#8779](https://github.com/Agoric/agoric-sdk/issues/8779)) ([af3ced9](https://github.com/Agoric/agoric-sdk/commit/af3ced91861731353e10a45e4eae63450f74a0ea))
|
|
23
|
-
* **vow:** make `when` an augmentation of `E.when` ([c2a3179](https://github.com/Agoric/agoric-sdk/commit/c2a31792b7070a44b2ab6c9f95dd845b75b316e8))
|
|
24
|
-
|
|
25
|
-
### Bug Fixes
|
|
26
|
-
|
|
27
|
-
* "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))
|
|
28
|
-
* **types:** board ([c73f4f9](https://github.com/Agoric/agoric-sdk/commit/c73f4f9686215a37e8c5f82ce8dbe4742886a02b))
|
|
29
|
-
* **types:** problems hidden by skipLibCheck ([6a6e595](https://github.com/Agoric/agoric-sdk/commit/6a6e59549e7beeeef94bf90556ed16873c46d285))
|
|
30
|
-
* **vat-data:** methods can be `PropertyKey`s ([b99f499](https://github.com/Agoric/agoric-sdk/commit/b99f4993c0f1caa651b83755f85689f123717f67))
|
|
31
|
-
* **vow:** persistent resolution, settler->resolver ([4d9371c](https://github.com/Agoric/agoric-sdk/commit/4d9371cb7d450e25146787474760b4c00b11e405))
|
|
32
|
-
* **vow:** use `zone.watchPromise` ([b8ddc9d](https://github.com/Agoric/agoric-sdk/commit/b8ddc9d1ddf06fed8b434f36aa86a2a70293fd56))
|
|
33
|
-
|
|
34
|
-
### [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)
|
|
35
|
-
|
|
36
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
37
|
-
|
|
38
|
-
### [0.5.1](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.5.0...@agoric/vat-data@0.5.1) (2023-05-24)
|
|
39
|
-
|
|
40
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
41
|
-
|
|
42
|
-
## [0.5.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.4.3...@agoric/vat-data@0.5.0) (2023-05-19)
|
|
43
|
-
|
|
44
|
-
### ⚠ BREAKING CHANGES
|
|
45
|
-
|
|
46
|
-
* **vat-data:** deprecate kinds in favor of Far Classes (#6106)
|
|
47
|
-
|
|
48
|
-
### Features
|
|
49
|
-
|
|
50
|
-
* **store:** M.splitArray and M.splitRecord ([#6597](https://github.com/Agoric/agoric-sdk/issues/6597)) ([e7427e3](https://github.com/Agoric/agoric-sdk/commit/e7427e386bcbfbe99312b41342b1fa2e722c57c7))
|
|
51
|
-
* **types:** infer this.state in far classes ([11b35d3](https://github.com/Agoric/agoric-sdk/commit/11b35d38448c9665a6db5a919b37744d2d929a53))
|
|
52
|
-
* **vat-data:** export overlooked `provideDurableWeakSetStore` ([b804736](https://github.com/Agoric/agoric-sdk/commit/b804736497525da3fd8cb96e892d06cd2a68ea25))
|
|
53
|
-
|
|
54
|
-
### Bug Fixes
|
|
55
|
-
|
|
56
|
-
* **types:** makeStoreUtils return types ([bd07ba0](https://github.com/Agoric/agoric-sdk/commit/bd07ba024734a383ae7554f1f3f85c62b1c86093))
|
|
57
|
-
* **vat-data:** normalize kindName mangling ([5bf0088](https://github.com/Agoric/agoric-sdk/commit/5bf0088cf26cc9e2b8d1d4188e9de427045b7b72))
|
|
58
|
-
* prepare for patterns to schematize storage ([#6819](https://github.com/Agoric/agoric-sdk/issues/6819)) ([f0bd3d6](https://github.com/Agoric/agoric-sdk/commit/f0bd3d62c9e480b102fc077997c65d89c0488fa8))
|
|
59
|
-
* rename from FarClass to ExoClass, etc ([#6323](https://github.com/Agoric/agoric-sdk/issues/6323)) ([da96c7c](https://github.com/Agoric/agoric-sdk/commit/da96c7c3c902a5e266baeedf23df02481f2e9c9d))
|
|
60
|
-
* rename vivify to prepare ([#6825](https://github.com/Agoric/agoric-sdk/issues/6825)) ([9261e42](https://github.com/Agoric/agoric-sdk/commit/9261e42e677a3fc31f52defc8fc7ae800f098838))
|
|
61
|
-
* without assertKeyPattern ([#7035](https://github.com/Agoric/agoric-sdk/issues/7035)) ([c9fcd7f](https://github.com/Agoric/agoric-sdk/commit/c9fcd7f82757732435cd96f3377e4fbfb6586ce7))
|
|
62
|
-
* **types:** far class maker params ([91e8fce](https://github.com/Agoric/agoric-sdk/commit/91e8fcecc9c45d3c8725489656f393704738e32a))
|
|
63
|
-
* **vat-data:** deprecate kinds in favor of Far Classes ([#6106](https://github.com/Agoric/agoric-sdk/issues/6106)) ([b63360b](https://github.com/Agoric/agoric-sdk/commit/b63360b416b06cb654d5fc51428a3252e1f0b34f))
|
|
64
|
-
|
|
65
|
-
### [0.4.5](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.4.4...@agoric/vat-data@0.4.5) (2023-02-17)
|
|
66
|
-
|
|
67
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
68
|
-
|
|
69
|
-
### [0.4.4](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.4.3...@agoric/vat-data@0.4.4) (2022-12-14)
|
|
70
|
-
|
|
71
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
72
|
-
|
|
73
|
-
### [0.4.3](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.4.2...@agoric/vat-data@0.4.3) (2022-10-18)
|
|
74
|
-
|
|
75
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
76
|
-
|
|
77
|
-
### [0.4.2](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.4.1...@agoric/vat-data@0.4.2) (2022-10-08)
|
|
78
|
-
|
|
79
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
80
|
-
|
|
81
|
-
### [0.4.1](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.4.0...@agoric/vat-data@0.4.1) (2022-10-05)
|
|
82
|
-
|
|
83
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
84
|
-
|
|
85
|
-
## [0.4.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.3.1...@agoric/vat-data@0.4.0) (2022-09-20)
|
|
86
|
-
|
|
87
|
-
### ⚠ BREAKING CHANGES
|
|
88
|
-
|
|
89
|
-
* **store:** split `provide` into collision vs no-collision variants (#6080)
|
|
90
|
-
* **store:** move some util where they are more reusable (#5990)
|
|
91
|
-
|
|
92
|
-
### Bug Fixes
|
|
93
|
-
|
|
94
|
-
* far classes with interface guards, used by ERTP ([#5960](https://github.com/Agoric/agoric-sdk/issues/5960)) ([a8882a1](https://github.com/Agoric/agoric-sdk/commit/a8882a1cef97c9177bf76d04d1a1253d02c7921b))
|
|
95
|
-
* heap far classes ([#6107](https://github.com/Agoric/agoric-sdk/issues/6107)) ([c10c36d](https://github.com/Agoric/agoric-sdk/commit/c10c36d7ccf6c85239c1dbcec9534d43b20ad00a))
|
|
96
|
-
* **store:** move some util where they are more reusable ([#5990](https://github.com/Agoric/agoric-sdk/issues/5990)) ([0eb83cd](https://github.com/Agoric/agoric-sdk/commit/0eb83cdf3650f75c70be02e863f341214e0e9a8d))
|
|
97
|
-
* **vat-data:** utility type FunctionsPlusContext ([#5607](https://github.com/Agoric/agoric-sdk/issues/5607)) ([7dbe6c0](https://github.com/Agoric/agoric-sdk/commit/7dbe6c0e948f0686ed77ef3439c69f6af1dc29d2))
|
|
98
|
-
|
|
99
|
-
### Code Refactoring
|
|
100
|
-
|
|
101
|
-
* **store:** split `provide` into collision vs no-collision variants ([#6080](https://github.com/Agoric/agoric-sdk/issues/6080)) ([939e25e](https://github.com/Agoric/agoric-sdk/commit/939e25e615ea1fcefff15a032996613031151c0d)), closes [#5875](https://github.com/Agoric/agoric-sdk/issues/5875)
|
|
102
|
-
|
|
103
|
-
### [0.3.1](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.3.0...@agoric/vat-data@0.3.1) (2022-05-28)
|
|
104
|
-
|
|
105
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
106
|
-
|
|
107
|
-
## [0.3.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.2.0...@agoric/vat-data@0.3.0) (2022-05-09)
|
|
108
|
-
|
|
109
|
-
### Features
|
|
110
|
-
|
|
111
|
-
* implement durable promise watchers ([ce55851](https://github.com/Agoric/agoric-sdk/commit/ce558515467e869e784260f5478802835c5eb9cf)), closes [#5006](https://github.com/Agoric/agoric-sdk/issues/5006)
|
|
112
|
-
* **vat-data:** partialAssign function ([96a6243](https://github.com/Agoric/agoric-sdk/commit/96a6243915c736f00fffc7d059cf963d9d5a2f8f))
|
|
113
|
-
|
|
114
|
-
## 0.2.0 (2022-04-18)
|
|
115
|
-
|
|
116
|
-
### Features
|
|
117
|
-
|
|
118
|
-
* split single- and multi-faceted VO definitions into their own functions ([fcf293a](https://github.com/Agoric/agoric-sdk/commit/fcf293a4fcdf64bf30b377c7b3fb8b728efbb4af)), closes [#5093](https://github.com/Agoric/agoric-sdk/issues/5093)
|
|
119
|
-
* yet another overhaul of the `defineKind` API ([3e02d42](https://github.com/Agoric/agoric-sdk/commit/3e02d42312b2963c165623c8cd559b431e5ecdce)), closes [#4905](https://github.com/Agoric/agoric-sdk/issues/4905)
|
package/src/index.test-d.ts
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
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';
|
|
9
|
-
import {
|
|
10
|
-
defineKind,
|
|
11
|
-
defineKindMulti,
|
|
12
|
-
makeKindHandle,
|
|
13
|
-
defineDurableKind,
|
|
14
|
-
partialAssign,
|
|
15
|
-
watchPromise,
|
|
16
|
-
} from './index.js';
|
|
17
|
-
|
|
18
|
-
// for use in assignments below
|
|
19
|
-
const anyVal = null as any;
|
|
20
|
-
|
|
21
|
-
/*
|
|
22
|
-
export const makePaymentMaker = (allegedName: string, brand: unknown) => {
|
|
23
|
-
const makePayment = defineKind(
|
|
24
|
-
`${allegedName} payment`,
|
|
25
|
-
() => ({}),
|
|
26
|
-
// @ts-expect-error "state" type implied by init() doesn't provide "a"
|
|
27
|
-
({ a: something }) => ({
|
|
28
|
-
getAllegedBrand: () => brand,
|
|
29
|
-
}),
|
|
30
|
-
);
|
|
31
|
-
return makePayment;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
type FlorgState = { str: string };
|
|
35
|
-
const makeFlorg = defineKind(
|
|
36
|
-
'florg',
|
|
37
|
-
(num: number) => ({ str: String(num), extra: 'extra' }),
|
|
38
|
-
({ str }: FlorgState) => str,
|
|
39
|
-
);
|
|
40
|
-
const f = makeFlorg(42);
|
|
41
|
-
f.concat; // string
|
|
42
|
-
// @ts-expect-error
|
|
43
|
-
makeFlorg('notnumber');
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
// Single-faceted example from virtual-objects.md
|
|
47
|
-
type SingleCounterState = { counter: number; name: string };
|
|
48
|
-
type SingleCounterContext = {
|
|
49
|
-
state: SingleCounterState;
|
|
50
|
-
self: KindFacet<typeof counterBehavior>;
|
|
51
|
-
};
|
|
52
|
-
const initCounter = (name: string, str: string): SingleCounterState => ({
|
|
53
|
-
counter: 0,
|
|
54
|
-
name,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const counterBehavior = {
|
|
58
|
-
inc: ({ state }: SingleCounterContext) => {
|
|
59
|
-
state.counter += 1;
|
|
60
|
-
},
|
|
61
|
-
dec: ({ state }: SingleCounterContext) => {
|
|
62
|
-
state.counter -= 1;
|
|
63
|
-
},
|
|
64
|
-
reset: ({ state }: SingleCounterContext) => {
|
|
65
|
-
state.counter = 0;
|
|
66
|
-
},
|
|
67
|
-
rename: ({ state }: SingleCounterContext, newName: string) => {
|
|
68
|
-
state.name = newName;
|
|
69
|
-
},
|
|
70
|
-
getCount: ({ state }: SingleCounterContext) => state.counter,
|
|
71
|
-
getName: ({ state }: SingleCounterContext) => state.name,
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const finishCounter = ({ state, self }: SingleCounterContext) => {
|
|
75
|
-
expectType<string>(state.name);
|
|
76
|
-
expectType<number>(self.getCount());
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const makeCounter = defineKind('counter', initCounter, counterBehavior, {
|
|
80
|
-
finish: finishCounter,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// Multi-faceted example from virtual-objects.md
|
|
84
|
-
type MultiCounterContext = {
|
|
85
|
-
state: ReturnType<typeof initFacetedCounter>;
|
|
86
|
-
facets: KindFacets<typeof facetedCounterBehavior>;
|
|
87
|
-
};
|
|
88
|
-
const initFacetedCounter = () => ({ counter: 0 });
|
|
89
|
-
const getCount = ({ state }: MultiCounterContext) => state.counter;
|
|
90
|
-
const facetedCounterBehavior = {
|
|
91
|
-
incr: {
|
|
92
|
-
step: ({ state }: MultiCounterContext) => {
|
|
93
|
-
state.counter += 1;
|
|
94
|
-
},
|
|
95
|
-
getCount,
|
|
96
|
-
},
|
|
97
|
-
decr: {
|
|
98
|
-
step: (context: MultiCounterContext) => {
|
|
99
|
-
// Destructure within method because doing so in params creates a circular reference
|
|
100
|
-
const { state, facets } = context;
|
|
101
|
-
const { other } = facets;
|
|
102
|
-
other.echo('hi');
|
|
103
|
-
state.counter -= 1;
|
|
104
|
-
},
|
|
105
|
-
getCount,
|
|
106
|
-
},
|
|
107
|
-
other: {
|
|
108
|
-
emptyFn: () => null,
|
|
109
|
-
echo: (context: MultiCounterContext, toEcho: string) => toEcho,
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const makeFacetedCounter = defineKindMulti(
|
|
114
|
-
'counter',
|
|
115
|
-
initFacetedCounter,
|
|
116
|
-
facetedCounterBehavior,
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
const fc = makeFacetedCounter();
|
|
120
|
-
expectType<void>(fc.incr.step());
|
|
121
|
-
expectType<void>(fc.decr.step());
|
|
122
|
-
expectType<number>(fc.decr.getCount());
|
|
123
|
-
// @ts-expect-error missing argument
|
|
124
|
-
fc.decr.echo();
|
|
125
|
-
expectType<string>(fc.other.echo('foo'));
|
|
126
|
-
// @ts-expect-error missing method
|
|
127
|
-
fc.incr.echo('foo');
|
|
128
|
-
expectType<null>(fc.other.emptyFn());
|
|
129
|
-
|
|
130
|
-
// durable kind
|
|
131
|
-
const fooHandle = makeKindHandle('foo');
|
|
132
|
-
expectType<DurableKindHandle>(fooHandle);
|
|
133
|
-
const fooInit = (name: string) => ({ name });
|
|
134
|
-
const fooBehavior = {
|
|
135
|
-
sayHi: ({ state }: { state: { name: string } }) => `Howdy, ${state.name}`,
|
|
136
|
-
};
|
|
137
|
-
const makeFoo = defineDurableKind(fooHandle, fooInit, fooBehavior);
|
|
138
|
-
const foo = makeFoo('Doody');
|
|
139
|
-
expectType<string>(foo.sayHi());
|
|
140
|
-
// @ts-expect-error missing method
|
|
141
|
-
foo.sayBye();
|
|
142
|
-
|
|
143
|
-
// partialAssign
|
|
144
|
-
const state = { name: 'ted', color: 'red' };
|
|
145
|
-
partialAssign(state, { name: 'ed' });
|
|
146
|
-
// @ts-expect-error
|
|
147
|
-
partialAssign(state, { key: 'ted' });
|
|
148
|
-
// @ts-expect-error
|
|
149
|
-
partialAssign(state, { name: 3 });
|
|
150
|
-
|
|
151
|
-
// test FunctionsPlusContext
|
|
152
|
-
type SomeFacet = {
|
|
153
|
-
gt(b: number): boolean;
|
|
154
|
-
};
|
|
155
|
-
type SomeContext = { state: { a: number } };
|
|
156
|
-
const someBehavior: FunctionsPlusContext<SomeContext, SomeFacet> = {
|
|
157
|
-
gt(context: SomeContext, b: number) {
|
|
158
|
-
return b > context.state.a;
|
|
159
|
-
},
|
|
160
|
-
};
|
|
161
|
-
const someFacet: KindFacet<typeof someBehavior> = anyVal;
|
|
162
|
-
// @ts-expect-error
|
|
163
|
-
someFacet.gt();
|
|
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/test/absent.test.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
|
|
3
|
-
/* global globalThis */
|
|
4
|
-
// @ts-expect-error VatData not optional
|
|
5
|
-
delete globalThis.VatData;
|
|
6
|
-
|
|
7
|
-
/** @see present.test.js */
|
|
8
|
-
test('methods available that throw', async t => {
|
|
9
|
-
const { defineKind } = await import('../src/index.js');
|
|
10
|
-
t.throws(() => defineKind('someTag', () => {}, {}), {
|
|
11
|
-
message: /VatData unavailable/,
|
|
12
|
-
});
|
|
13
|
-
});
|
|
@@ -1,90 +0,0 @@
|
|
|
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,147 +0,0 @@
|
|
|
1
|
-
// Modeled on test-heap-classes.js
|
|
2
|
-
|
|
3
|
-
import { test } from './prepare-test-env-ava.js';
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line import/order
|
|
6
|
-
import { M } from '@agoric/store';
|
|
7
|
-
import {
|
|
8
|
-
makeKindHandle,
|
|
9
|
-
makeScalarBigMapStore,
|
|
10
|
-
} from '../src/vat-data-bindings.js';
|
|
11
|
-
import {
|
|
12
|
-
defineDurableExoClass,
|
|
13
|
-
defineDurableExoClassKit,
|
|
14
|
-
} from '../src/exo-utils.js';
|
|
15
|
-
|
|
16
|
-
const UpCounterI = M.interface('UpCounter', {
|
|
17
|
-
incr: M.call()
|
|
18
|
-
// TODO M.number() should not be needed to get a better error message
|
|
19
|
-
.optional(M.and(M.number(), M.gte(0)))
|
|
20
|
-
.returns(M.number()),
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const DownCounterI = M.interface('DownCounter', {
|
|
24
|
-
decr: M.call()
|
|
25
|
-
// TODO M.number() should not be needed to get a better error message
|
|
26
|
-
.optional(M.and(M.number(), M.gte(0)))
|
|
27
|
-
.returns(M.number()),
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('test defineDurableExoClass', t => {
|
|
31
|
-
const upCounterKind = makeKindHandle('UpCounter');
|
|
32
|
-
|
|
33
|
-
const makeUpCounter = defineDurableExoClass(
|
|
34
|
-
upCounterKind,
|
|
35
|
-
UpCounterI,
|
|
36
|
-
/** @param {number} [x] */
|
|
37
|
-
(x = 0) => ({ x }),
|
|
38
|
-
{
|
|
39
|
-
incr(y = 1) {
|
|
40
|
-
// @ts-expect-error does not exist
|
|
41
|
-
this.incr;
|
|
42
|
-
assert(this.self.incr);
|
|
43
|
-
const { state } = this;
|
|
44
|
-
state.x += y;
|
|
45
|
-
return state.x;
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
);
|
|
49
|
-
const upCounter = makeUpCounter(3);
|
|
50
|
-
t.is(upCounter.incr(5), 8);
|
|
51
|
-
t.is(upCounter.incr(1), 9);
|
|
52
|
-
t.throws(() => upCounter.incr(-3), {
|
|
53
|
-
message: 'In "incr" method of (UpCounter): arg 0?: -3 - Must be >= 0',
|
|
54
|
-
});
|
|
55
|
-
// @ts-expect-error the type violation is what we're testing
|
|
56
|
-
t.throws(() => upCounter.incr('foo'), {
|
|
57
|
-
message:
|
|
58
|
-
'In "incr" method of (UpCounter): arg 0?: string "foo" - Must be a number',
|
|
59
|
-
});
|
|
60
|
-
// @ts-expect-error arity check
|
|
61
|
-
makeUpCounter(3, 4);
|
|
62
|
-
// @ts-expect-error type check
|
|
63
|
-
makeUpCounter('str');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test('test defineDurableExoClassKit', t => {
|
|
67
|
-
const counterKindHandle = makeKindHandle('Counter');
|
|
68
|
-
|
|
69
|
-
const makeCounterKit = defineDurableExoClassKit(
|
|
70
|
-
counterKindHandle,
|
|
71
|
-
{ up: UpCounterI, down: DownCounterI },
|
|
72
|
-
/** @param {number} [x] */
|
|
73
|
-
(x = 0) => ({ x }),
|
|
74
|
-
{
|
|
75
|
-
up: {
|
|
76
|
-
incr(y = 1) {
|
|
77
|
-
const { state } = this;
|
|
78
|
-
state.x += y;
|
|
79
|
-
return state.x;
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
down: {
|
|
83
|
-
decr(y = 1) {
|
|
84
|
-
const { state } = this;
|
|
85
|
-
state.x -= y;
|
|
86
|
-
return state.x;
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
);
|
|
91
|
-
const { up: upCounter, down: downCounter } = makeCounterKit(3);
|
|
92
|
-
t.is(upCounter.incr(5), 8);
|
|
93
|
-
t.is(downCounter.decr(), 7);
|
|
94
|
-
t.is(upCounter.incr(3), 10);
|
|
95
|
-
t.throws(() => upCounter.incr(-3), {
|
|
96
|
-
message: 'In "incr" method of (Counter up): arg 0?: -3 - Must be >= 0',
|
|
97
|
-
});
|
|
98
|
-
// @ts-expect-error the type violation is what we're testing
|
|
99
|
-
t.throws(() => downCounter.decr('foo'), {
|
|
100
|
-
message:
|
|
101
|
-
'In "decr" method of (Counter down): arg 0?: string "foo" - Must be a number',
|
|
102
|
-
});
|
|
103
|
-
// @ts-expect-error the type violation is what we're testing
|
|
104
|
-
t.throws(() => upCounter.decr(3), {
|
|
105
|
-
message: 'upCounter.decr is not a function',
|
|
106
|
-
});
|
|
107
|
-
// @ts-expect-error arity check
|
|
108
|
-
makeCounterKit(3, 4);
|
|
109
|
-
// @ts-expect-error type check
|
|
110
|
-
makeCounterKit('str');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test('finish option', t => {
|
|
114
|
-
const counterRegistry = makeScalarBigMapStore('counters');
|
|
115
|
-
const upCounterKind = makeKindHandle('UpCounter');
|
|
116
|
-
|
|
117
|
-
const finishCounter = context => {
|
|
118
|
-
const { state, self } = context;
|
|
119
|
-
counterRegistry.init(state.name, self);
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const makeUpCounter = defineDurableExoClass(
|
|
123
|
-
upCounterKind,
|
|
124
|
-
UpCounterI,
|
|
125
|
-
/**
|
|
126
|
-
* @param {string} name
|
|
127
|
-
* @param {number} [x]
|
|
128
|
-
*/
|
|
129
|
-
(name, x = 0) => ({ name, x }),
|
|
130
|
-
{
|
|
131
|
-
incr(y = 1) {
|
|
132
|
-
// @ts-expect-error does not exist
|
|
133
|
-
this.incr;
|
|
134
|
-
assert(this.self.incr);
|
|
135
|
-
const { state } = this;
|
|
136
|
-
state.x += y;
|
|
137
|
-
return state.x;
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
{ finish: finishCounter },
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
makeUpCounter('myCounter', 3);
|
|
144
|
-
t.truthy(counterRegistry.get('myCounter'));
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
test.todo('Add tests for durability');
|
|
@@ -1,110 +0,0 @@
|
|
|
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
|
-
});
|
package/test/prepare-test-env.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@agoric/swingset-liveslots/tools/prepare-test-env.js';
|
package/test/prepare.test.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
// Modeled on test-heap-classes.js
|
|
2
|
-
|
|
3
|
-
import { test } from './prepare-test-env-ava.js';
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line import/order
|
|
6
|
-
import { M } from '@agoric/store';
|
|
7
|
-
import {
|
|
8
|
-
prepareExoClass,
|
|
9
|
-
prepareExoClassKit,
|
|
10
|
-
prepareExo,
|
|
11
|
-
} from '../src/exo-utils.js';
|
|
12
|
-
import { makeScalarBigMapStore } from '../src/vat-data-bindings.js';
|
|
13
|
-
|
|
14
|
-
const UpCounterI = M.interface('UpCounter', {
|
|
15
|
-
incr: M.call()
|
|
16
|
-
// TODO M.number() should not be needed to get a better error message
|
|
17
|
-
.optional(M.and(M.number(), M.gte(0)))
|
|
18
|
-
.returns(M.number()),
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const DownCounterI = M.interface('DownCounter', {
|
|
22
|
-
decr: M.call()
|
|
23
|
-
// TODO M.number() should not be needed to get a better error message
|
|
24
|
-
.optional(M.and(M.number(), M.gte(0)))
|
|
25
|
-
.returns(M.number()),
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('test prepareExoClass', t => {
|
|
29
|
-
const baggage = makeScalarBigMapStore('baggage', { durable: true });
|
|
30
|
-
|
|
31
|
-
const makeUpCounter = prepareExoClass(
|
|
32
|
-
baggage,
|
|
33
|
-
'UpCounter',
|
|
34
|
-
UpCounterI,
|
|
35
|
-
/** @param {number} [x] */
|
|
36
|
-
(x = 0) => ({ x }),
|
|
37
|
-
{
|
|
38
|
-
incr(y = 1) {
|
|
39
|
-
const { state } = this;
|
|
40
|
-
state.x += y;
|
|
41
|
-
return state.x;
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
);
|
|
45
|
-
const upCounter = makeUpCounter(3);
|
|
46
|
-
t.is(upCounter.incr(5), 8);
|
|
47
|
-
t.is(upCounter.incr(1), 9);
|
|
48
|
-
t.throws(() => upCounter.incr(-3), {
|
|
49
|
-
message: 'In "incr" method of (UpCounter): arg 0?: -3 - Must be >= 0',
|
|
50
|
-
});
|
|
51
|
-
// @ts-expect-error the type violation is what we're testing
|
|
52
|
-
t.throws(() => upCounter.incr('foo'), {
|
|
53
|
-
message:
|
|
54
|
-
'In "incr" method of (UpCounter): arg 0?: string "foo" - Must be a number',
|
|
55
|
-
});
|
|
56
|
-
// @ts-expect-error arity check
|
|
57
|
-
makeUpCounter(3, 4);
|
|
58
|
-
// @ts-expect-error type check
|
|
59
|
-
makeUpCounter('str');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('test prepareExoClassKit', t => {
|
|
63
|
-
const baggage = makeScalarBigMapStore('baggage', { durable: true });
|
|
64
|
-
|
|
65
|
-
const makeCounterKit = prepareExoClassKit(
|
|
66
|
-
baggage,
|
|
67
|
-
'Counter',
|
|
68
|
-
{ up: UpCounterI, down: DownCounterI },
|
|
69
|
-
/** @param {number} [x] */
|
|
70
|
-
(x = 0) => ({ x }),
|
|
71
|
-
{
|
|
72
|
-
up: {
|
|
73
|
-
incr(y = 1) {
|
|
74
|
-
const { state } = this;
|
|
75
|
-
state.x += y;
|
|
76
|
-
return state.x;
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
down: {
|
|
80
|
-
decr(y = 1) {
|
|
81
|
-
const { state } = this;
|
|
82
|
-
state.x -= y;
|
|
83
|
-
return state.x;
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
);
|
|
88
|
-
const { up: upCounter, down: downCounter } = makeCounterKit(3);
|
|
89
|
-
t.is(upCounter.incr(5), 8);
|
|
90
|
-
t.is(downCounter.decr(), 7);
|
|
91
|
-
t.is(upCounter.incr(3), 10);
|
|
92
|
-
t.throws(() => upCounter.incr(-3), {
|
|
93
|
-
message: 'In "incr" method of (Counter up): arg 0?: -3 - Must be >= 0',
|
|
94
|
-
});
|
|
95
|
-
// @ts-expect-error the type violation is what we're testing
|
|
96
|
-
t.throws(() => downCounter.decr('foo'), {
|
|
97
|
-
message:
|
|
98
|
-
'In "decr" method of (Counter down): arg 0?: string "foo" - Must be a number',
|
|
99
|
-
});
|
|
100
|
-
// @ts-expect-error the type violation is what we're testing
|
|
101
|
-
t.throws(() => upCounter.decr(3), {
|
|
102
|
-
message: 'upCounter.decr is not a function',
|
|
103
|
-
});
|
|
104
|
-
// @ts-expect-error arity check
|
|
105
|
-
makeCounterKit(3, 4);
|
|
106
|
-
// @ts-expect-error type check
|
|
107
|
-
makeCounterKit('str');
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test('test prepareExo', t => {
|
|
111
|
-
const baggage = makeScalarBigMapStore('baggage', { durable: true });
|
|
112
|
-
|
|
113
|
-
let x = 3;
|
|
114
|
-
const upCounter = prepareExo(baggage, 'upCounter', UpCounterI, {
|
|
115
|
-
incr(y = 1) {
|
|
116
|
-
x += y;
|
|
117
|
-
return x;
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
t.is(upCounter.incr(5), 8);
|
|
121
|
-
t.is(upCounter.incr(1), 9);
|
|
122
|
-
t.throws(() => upCounter.incr(-3), {
|
|
123
|
-
message: 'In "incr" method of (upCounter): arg 0?: -3 - Must be >= 0',
|
|
124
|
-
});
|
|
125
|
-
// @ts-expect-error intentional
|
|
126
|
-
t.throws(() => upCounter.incr('foo'), {
|
|
127
|
-
message:
|
|
128
|
-
'In "incr" method of (upCounter): arg 0?: string "foo" - Must be a number',
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test.todo('Demonstrate that the baggage can be used to revive objects.');
|
package/test/present.test.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
|
|
3
|
-
const mockDefineKind = /** @type {any} */ (harden({}));
|
|
4
|
-
|
|
5
|
-
/* global globalThis */
|
|
6
|
-
// @ts-expect-error missing fields
|
|
7
|
-
globalThis.VatData ||= { defineKind: mockDefineKind };
|
|
8
|
-
|
|
9
|
-
test('methods available', async t => {
|
|
10
|
-
const { defineKind } = await import('../src/index.js');
|
|
11
|
-
t.is(defineKind, mockDefineKind);
|
|
12
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// From https://github.com/Agoric/agoric-sdk/pull/6903#discussion_r1098067133
|
|
2
|
-
|
|
3
|
-
import { test } from './prepare-test-env-ava.js';
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line import/order
|
|
6
|
-
import { M, makeScalarMapStore } from '@agoric/store';
|
|
7
|
-
import { makeScalarBigMapStore } from '../src/vat-data-bindings.js';
|
|
8
|
-
|
|
9
|
-
test('scalar maps should reject non-scalar keys', t => {
|
|
10
|
-
const bigMap = makeScalarMapStore('dummy', { keyShape: M.key() });
|
|
11
|
-
t.throws(() => bigMap.init(harden({ label: 'not a scalar' }), 'val'), {
|
|
12
|
-
message:
|
|
13
|
-
/A "copyRecord" cannot be a scalar key: \{"label":"not a scalar"\}/,
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('scalar big maps should reject non-scalar keys', t => {
|
|
18
|
-
const bigMap = makeScalarBigMapStore('dummy', { keyShape: M.key() });
|
|
19
|
-
t.throws(() => bigMap.init(harden({ label: 'not a scalar' }), null), {
|
|
20
|
-
message:
|
|
21
|
-
/A "copyRecord" cannot be a scalar key: \{"label":"not a scalar"\}/,
|
|
22
|
-
});
|
|
23
|
-
});
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
// Modeled on test-heap-classes.js
|
|
2
|
-
|
|
3
|
-
import { test } from './prepare-test-env-ava.js';
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line import/order
|
|
6
|
-
import { M } from '@agoric/store';
|
|
7
|
-
import {
|
|
8
|
-
defineVirtualExoClass,
|
|
9
|
-
defineVirtualExoClassKit,
|
|
10
|
-
} from '../src/exo-utils.js';
|
|
11
|
-
|
|
12
|
-
const UpCounterI = M.interface('UpCounter', {
|
|
13
|
-
incr: M.call()
|
|
14
|
-
// TODO M.number() should not be needed to get a better error message
|
|
15
|
-
.optional(M.and(M.number(), M.gte(0)))
|
|
16
|
-
.returns(M.number()),
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const DownCounterI = M.interface('DownCounter', {
|
|
20
|
-
decr: M.call()
|
|
21
|
-
// TODO M.number() should not be needed to get a better error message
|
|
22
|
-
.optional(M.and(M.number(), M.gte(0)))
|
|
23
|
-
.returns(M.number()),
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('test defineVirtualExoClass', t => {
|
|
27
|
-
const makeUpCounter = defineVirtualExoClass(
|
|
28
|
-
'UpCounter',
|
|
29
|
-
UpCounterI,
|
|
30
|
-
/** @param {number} [x] */
|
|
31
|
-
(x = 0) => ({ x }),
|
|
32
|
-
{
|
|
33
|
-
incr(y = 1) {
|
|
34
|
-
const { state } = this;
|
|
35
|
-
state.x += y;
|
|
36
|
-
return state.x;
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
);
|
|
40
|
-
const upCounter = makeUpCounter(3);
|
|
41
|
-
t.is(upCounter.incr(5), 8);
|
|
42
|
-
t.is(upCounter.incr(1), 9);
|
|
43
|
-
t.throws(() => upCounter.incr(-3), {
|
|
44
|
-
message: 'In "incr" method of (UpCounter): arg 0?: -3 - Must be >= 0',
|
|
45
|
-
});
|
|
46
|
-
// @ts-expect-error the type violation is what we're testing
|
|
47
|
-
t.throws(() => upCounter.incr('foo'), {
|
|
48
|
-
message:
|
|
49
|
-
'In "incr" method of (UpCounter): arg 0?: string "foo" - Must be a number',
|
|
50
|
-
});
|
|
51
|
-
// @ts-expect-error arity check
|
|
52
|
-
makeUpCounter(3, 4);
|
|
53
|
-
// @ts-expect-error type check
|
|
54
|
-
makeUpCounter('str');
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('test defineVirtualExoClassKit', t => {
|
|
58
|
-
const makeCounterKit = defineVirtualExoClassKit(
|
|
59
|
-
'Counter',
|
|
60
|
-
{ up: UpCounterI, down: DownCounterI },
|
|
61
|
-
/** @param {number} [x] */
|
|
62
|
-
(x = 0) => ({ x }),
|
|
63
|
-
{
|
|
64
|
-
up: {
|
|
65
|
-
incr(y = 1) {
|
|
66
|
-
const { state } = this;
|
|
67
|
-
state.x += y;
|
|
68
|
-
return state.x;
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
down: {
|
|
72
|
-
decr(y = 1) {
|
|
73
|
-
const { state } = this;
|
|
74
|
-
state.x -= y;
|
|
75
|
-
return state.x;
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
);
|
|
80
|
-
const { up: upCounter, down: downCounter } = makeCounterKit(3);
|
|
81
|
-
t.is(upCounter.incr(5), 8);
|
|
82
|
-
t.is(downCounter.decr(), 7);
|
|
83
|
-
t.is(upCounter.incr(3), 10);
|
|
84
|
-
t.throws(() => upCounter.incr(-3), {
|
|
85
|
-
message: 'In "incr" method of (Counter up): arg 0?: -3 - Must be >= 0',
|
|
86
|
-
});
|
|
87
|
-
// @ts-expect-error the type violation is what we're testing
|
|
88
|
-
t.throws(() => downCounter.decr('foo'), {
|
|
89
|
-
message:
|
|
90
|
-
'In "decr" method of (Counter down): arg 0?: string "foo" - Must be a number',
|
|
91
|
-
});
|
|
92
|
-
// @ts-expect-error the type violation is what we're testing
|
|
93
|
-
t.throws(() => upCounter.decr(3), {
|
|
94
|
-
message: 'upCounter.decr is not a function',
|
|
95
|
-
});
|
|
96
|
-
// @ts-expect-error arity check
|
|
97
|
-
makeCounterKit(3, 4);
|
|
98
|
-
// @ts-expect-error type check
|
|
99
|
-
makeCounterKit('str');
|
|
100
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
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
|
|
7
|
-
},
|
|
8
|
-
"include": [
|
|
9
|
-
"src/**/*.js",
|
|
10
|
-
"src/**/*.ts",
|
|
11
|
-
"test/**/*.js",
|
|
12
|
-
]
|
|
13
|
-
}
|