@agoric/vat-data 0.5.3-dev-803e785.0.803e785 → 0.5.3-dev-6727d47.0.6727d47
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 +8 -5
- package/CHANGELOG.md +0 -135
- package/test/absent.test.js +0 -13
- package/test/amplify-virtual-class-kits.test.js +0 -94
- package/test/durable-classes.test.js +0 -147
- package/test/is-instance-virtual-class-kits.test.js +0 -114
- 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.5.3-dev-
|
|
3
|
+
"version": "0.5.3-dev-6727d47.0.6727d47",
|
|
4
4
|
"description": "Safe access to VatData global",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": "https://github.com/Agoric/agoric-sdk",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"author": "Agoric",
|
|
19
19
|
"license": "Apache-2.0",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@agoric/base-zone": "0.1.1-dev-
|
|
22
|
-
"@agoric/store": "0.9.3-dev-
|
|
23
|
-
"@agoric/swingset-liveslots": "0.10.3-dev-
|
|
21
|
+
"@agoric/base-zone": "0.1.1-dev-6727d47.0.6727d47",
|
|
22
|
+
"@agoric/store": "0.9.3-dev-6727d47.0.6727d47",
|
|
23
|
+
"@agoric/swingset-liveslots": "0.10.3-dev-6727d47.0.6727d47",
|
|
24
24
|
"@endo/errors": "^1.2.13",
|
|
25
25
|
"@endo/exo": "^1.5.12",
|
|
26
26
|
"@endo/patterns": "^1.7.0"
|
|
@@ -32,6 +32,9 @@
|
|
|
32
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": "6727d47e6970be1f992aa904cd964abdfef00a83"
|
|
53
56
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,135 +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.5.2](https://github.com/Agoric/agoric-sdk/compare/@agoric/vat-data@0.5.1...@agoric/vat-data@0.5.2) (2023-06-02)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
### [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)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
## [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)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
### ⚠ BREAKING CHANGES
|
|
26
|
-
|
|
27
|
-
* **vat-data:** deprecate kinds in favor of Far Classes (#6106)
|
|
28
|
-
|
|
29
|
-
### Features
|
|
30
|
-
|
|
31
|
-
* **store:** M.splitArray and M.splitRecord ([#6597](https://github.com/Agoric/agoric-sdk/issues/6597)) ([e7427e3](https://github.com/Agoric/agoric-sdk/commit/e7427e386bcbfbe99312b41342b1fa2e722c57c7))
|
|
32
|
-
* **types:** infer this.state in far classes ([11b35d3](https://github.com/Agoric/agoric-sdk/commit/11b35d38448c9665a6db5a919b37744d2d929a53))
|
|
33
|
-
* **vat-data:** export overlooked `provideDurableWeakSetStore` ([b804736](https://github.com/Agoric/agoric-sdk/commit/b804736497525da3fd8cb96e892d06cd2a68ea25))
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
### Bug Fixes
|
|
37
|
-
|
|
38
|
-
* **types:** makeStoreUtils return types ([bd07ba0](https://github.com/Agoric/agoric-sdk/commit/bd07ba024734a383ae7554f1f3f85c62b1c86093))
|
|
39
|
-
* **vat-data:** normalize kindName mangling ([5bf0088](https://github.com/Agoric/agoric-sdk/commit/5bf0088cf26cc9e2b8d1d4188e9de427045b7b72))
|
|
40
|
-
* prepare for patterns to schematize storage ([#6819](https://github.com/Agoric/agoric-sdk/issues/6819)) ([f0bd3d6](https://github.com/Agoric/agoric-sdk/commit/f0bd3d62c9e480b102fc077997c65d89c0488fa8))
|
|
41
|
-
* rename from FarClass to ExoClass, etc ([#6323](https://github.com/Agoric/agoric-sdk/issues/6323)) ([da96c7c](https://github.com/Agoric/agoric-sdk/commit/da96c7c3c902a5e266baeedf23df02481f2e9c9d))
|
|
42
|
-
* rename vivify to prepare ([#6825](https://github.com/Agoric/agoric-sdk/issues/6825)) ([9261e42](https://github.com/Agoric/agoric-sdk/commit/9261e42e677a3fc31f52defc8fc7ae800f098838))
|
|
43
|
-
* without assertKeyPattern ([#7035](https://github.com/Agoric/agoric-sdk/issues/7035)) ([c9fcd7f](https://github.com/Agoric/agoric-sdk/commit/c9fcd7f82757732435cd96f3377e4fbfb6586ce7))
|
|
44
|
-
* **types:** far class maker params ([91e8fce](https://github.com/Agoric/agoric-sdk/commit/91e8fcecc9c45d3c8725489656f393704738e32a))
|
|
45
|
-
* **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))
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
### [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)
|
|
50
|
-
|
|
51
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
### [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)
|
|
58
|
-
|
|
59
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
### [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)
|
|
66
|
-
|
|
67
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
### [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)
|
|
74
|
-
|
|
75
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
## [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)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
### ⚠ BREAKING CHANGES
|
|
93
|
-
|
|
94
|
-
* **store:** split `provide` into collision vs no-collision variants (#6080)
|
|
95
|
-
* **store:** move some util where they are more reusable (#5990)
|
|
96
|
-
|
|
97
|
-
### Bug Fixes
|
|
98
|
-
|
|
99
|
-
* 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))
|
|
100
|
-
* heap far classes ([#6107](https://github.com/Agoric/agoric-sdk/issues/6107)) ([c10c36d](https://github.com/Agoric/agoric-sdk/commit/c10c36d7ccf6c85239c1dbcec9534d43b20ad00a))
|
|
101
|
-
* **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))
|
|
102
|
-
* **vat-data:** utility type FunctionsPlusContext ([#5607](https://github.com/Agoric/agoric-sdk/issues/5607)) ([7dbe6c0](https://github.com/Agoric/agoric-sdk/commit/7dbe6c0e948f0686ed77ef3439c69f6af1dc29d2))
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
### Code Refactoring
|
|
106
|
-
|
|
107
|
-
* **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)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
### [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)
|
|
112
|
-
|
|
113
|
-
**Note:** Version bump only for package @agoric/vat-data
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
## [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)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
### Features
|
|
123
|
-
|
|
124
|
-
* implement durable promise watchers ([ce55851](https://github.com/Agoric/agoric-sdk/commit/ce558515467e869e784260f5478802835c5eb9cf)), closes [#5006](https://github.com/Agoric/agoric-sdk/issues/5006)
|
|
125
|
-
* **vat-data:** partialAssign function ([96a6243](https://github.com/Agoric/agoric-sdk/commit/96a6243915c736f00fffc7d059cf963d9d5a2f8f))
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
## 0.2.0 (2022-04-18)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
### Features
|
|
133
|
-
|
|
134
|
-
* 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)
|
|
135
|
-
* 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/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,94 +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
|
-
/**
|
|
12
|
-
* @import {Amplify} from '@endo/exo';
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
const UpCounterI = M.interface('UpCounter', {
|
|
16
|
-
incr: M.call().optional(M.gte(0)).returns(M.number()),
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const DownCounterI = M.interface('DownCounter', {
|
|
20
|
-
decr: M.call().optional(M.gte(0)).returns(M.number()),
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('test amplify defineVirtualExoClass fails', t => {
|
|
24
|
-
t.throws(
|
|
25
|
-
() =>
|
|
26
|
-
defineVirtualExoClass(
|
|
27
|
-
'UpCounter',
|
|
28
|
-
UpCounterI,
|
|
29
|
-
/** @param {number} [x] */
|
|
30
|
-
(x = 0) => ({ x }),
|
|
31
|
-
{
|
|
32
|
-
incr(y = 1) {
|
|
33
|
-
const { state } = this;
|
|
34
|
-
state.x += y;
|
|
35
|
-
return state.x;
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
receiveAmplifier(_) {},
|
|
40
|
-
},
|
|
41
|
-
),
|
|
42
|
-
{
|
|
43
|
-
message:
|
|
44
|
-
'Only facets of an exo class kit can be amplified, not "UpCounter"',
|
|
45
|
-
},
|
|
46
|
-
);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('test amplify defineVirtualExoClassKit', t => {
|
|
50
|
-
/** @type {Amplify} */
|
|
51
|
-
let amp;
|
|
52
|
-
const makeCounterKit = defineVirtualExoClassKit(
|
|
53
|
-
'Counter',
|
|
54
|
-
{ up: UpCounterI, down: DownCounterI },
|
|
55
|
-
/** @param {number} [x] */
|
|
56
|
-
(x = 0) => ({ x }),
|
|
57
|
-
{
|
|
58
|
-
up: {
|
|
59
|
-
incr(y = 1) {
|
|
60
|
-
const { state } = this;
|
|
61
|
-
state.x += y;
|
|
62
|
-
return state.x;
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
down: {
|
|
66
|
-
decr(y = 1) {
|
|
67
|
-
const { state } = this;
|
|
68
|
-
state.x -= y;
|
|
69
|
-
return state.x;
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
receiveAmplifier(a) {
|
|
75
|
-
amp = a;
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
);
|
|
79
|
-
// @ts-expect-error TS thinks it is used before assigned, which is a hazard
|
|
80
|
-
// TS is correct to bring to our attention, since there is not enough static
|
|
81
|
-
// into to infer otherwise.
|
|
82
|
-
assert(amp !== undefined);
|
|
83
|
-
|
|
84
|
-
const counterKit = makeCounterKit(3);
|
|
85
|
-
const { up: upCounter, down: downCounter } = counterKit;
|
|
86
|
-
t.is(upCounter.incr(5), 8);
|
|
87
|
-
t.is(downCounter.decr(), 7);
|
|
88
|
-
|
|
89
|
-
t.throws(() => amp(harden({})), {
|
|
90
|
-
message: 'Must be a facet of "Counter": {}',
|
|
91
|
-
});
|
|
92
|
-
t.deepEqual(amp(upCounter), counterKit);
|
|
93
|
-
t.deepEqual(amp(downCounter), counterKit);
|
|
94
|
-
});
|
|
@@ -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,114 +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
|
-
/**
|
|
13
|
-
* @import {IsInstance} from '@endo/exo';
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
const UpCounterI = M.interface('UpCounter', {
|
|
17
|
-
incr: M.call().optional(M.gte(0)).returns(M.number()),
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const DownCounterI = M.interface('DownCounter', {
|
|
21
|
-
decr: M.call().optional(M.gte(0)).returns(M.number()),
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('test isInstance defineVirtualExoClass', t => {
|
|
25
|
-
/** @type {IsInstance} */
|
|
26
|
-
let isInstance;
|
|
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
|
-
receiveInstanceTester(i) {
|
|
41
|
-
isInstance = i;
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
);
|
|
45
|
-
// @ts-expect-error TS thinks it is used before assigned, which is a hazard
|
|
46
|
-
// TS is correct to bring to our attention, since there is not enough static
|
|
47
|
-
// into to infer otherwise.
|
|
48
|
-
assert(isInstance !== undefined);
|
|
49
|
-
|
|
50
|
-
t.is(isInstance(harden({})), false);
|
|
51
|
-
t.throws(() => isInstance(harden({}), 'up'), {
|
|
52
|
-
message:
|
|
53
|
-
'facetName can only be used with an exo class kit: "UpCounter" has no facet "up"',
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
const upCounter = makeUpCounter(3);
|
|
57
|
-
|
|
58
|
-
t.is(isInstance(upCounter), true);
|
|
59
|
-
t.throws(() => isInstance(upCounter, 'up'), {
|
|
60
|
-
message:
|
|
61
|
-
'facetName can only be used with an exo class kit: "UpCounter" has no facet "up"',
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test('test isInstance defineVirtualExoClassKit', t => {
|
|
66
|
-
/** @type {IsInstance} */
|
|
67
|
-
let isInstance;
|
|
68
|
-
const makeCounterKit = defineVirtualExoClassKit(
|
|
69
|
-
'Counter',
|
|
70
|
-
{ up: UpCounterI, down: DownCounterI },
|
|
71
|
-
/** @param {number} x */
|
|
72
|
-
(x = 0) => ({ x }),
|
|
73
|
-
{
|
|
74
|
-
up: {
|
|
75
|
-
incr(y = 1) {
|
|
76
|
-
const { state } = this;
|
|
77
|
-
state.x += y;
|
|
78
|
-
return state.x;
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
down: {
|
|
82
|
-
decr(y = 1) {
|
|
83
|
-
const { state } = this;
|
|
84
|
-
state.x -= y;
|
|
85
|
-
return state.x;
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
receiveInstanceTester(i) {
|
|
91
|
-
isInstance = i;
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
);
|
|
95
|
-
// @ts-expect-error TS thinks it is used before assigned, which is a hazard
|
|
96
|
-
// TS is correct to bring to our attention, since there is not enough static
|
|
97
|
-
// into to infer otherwise.
|
|
98
|
-
assert(isInstance !== undefined);
|
|
99
|
-
|
|
100
|
-
t.is(isInstance(harden({})), false);
|
|
101
|
-
t.is(isInstance(harden({}), 'up'), false);
|
|
102
|
-
t.throws(() => isInstance(harden({}), 'foo'), {
|
|
103
|
-
message: 'exo class kit "Counter" has no facet named "foo"',
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
const { up: upCounter } = makeCounterKit(3);
|
|
107
|
-
|
|
108
|
-
t.is(isInstance(upCounter), true);
|
|
109
|
-
t.is(isInstance(upCounter, 'up'), true);
|
|
110
|
-
t.is(isInstance(upCounter, 'down'), false);
|
|
111
|
-
t.throws(() => isInstance(upCounter, 'foo'), {
|
|
112
|
-
message: 'exo class kit "Counter" has no facet named "foo"',
|
|
113
|
-
});
|
|
114
|
-
});
|
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
|
-
}
|