@agoric/zone 0.2.3-other-dev-8f8782b.0 → 0.2.3-other-dev-fbe72e7.0.fbe72e7
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/README.md +4 -4
- package/durable.d.ts +2 -0
- package/durable.d.ts.map +1 -0
- package/heap.d.ts +2 -0
- package/heap.d.ts.map +1 -0
- package/heap.js +1 -1
- package/package.json +27 -12
- package/src/durable.d.ts +3 -0
- package/src/durable.d.ts.map +1 -0
- package/src/durable.js +66 -29
- package/src/exports.d.ts +6 -0
- package/src/exports.js +2 -0
- package/src/index.d.ts +3 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +3 -36
- package/src/virtual.d.ts +2 -0
- package/src/virtual.d.ts.map +1 -0
- package/src/virtual.js +40 -15
- package/test/exos.test.js +203 -0
- package/test/make-once.test.js +66 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +11 -0
- package/typedoc.json +8 -0
- package/virtual.d.ts +2 -0
- package/virtual.d.ts.map +1 -0
- package/jsconfig.json +0 -19
- package/src/heap.js +0 -42
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.2.3-u11.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/zone@0.2.2...@agoric/zone@0.2.3-u11.0) (2023-08-24)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @agoric/zone
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
6
|
### [0.2.2](https://github.com/Agoric/agoric-sdk/compare/@agoric/zone@0.2.1...@agoric/zone@0.2.2) (2023-06-02)
|
|
15
7
|
|
|
16
8
|
**Note:** Version bump only for package @agoric/zone
|
package/README.md
CHANGED
|
@@ -12,18 +12,18 @@ An example of making a Zone-aware vat might look something like this:
|
|
|
12
12
|
|
|
13
13
|
```js
|
|
14
14
|
import { makeDurableZone } from '@agoric/zone/durable.js';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
15
|
+
import { prepareFrobulator } from 'frob-package';
|
|
16
|
+
import { prepareWidget } from 'widget-package';
|
|
17
17
|
|
|
18
18
|
export const buildRootObject = (vatPowers, _args, baggage) => {
|
|
19
19
|
const zone = makeDurableZone(baggage);
|
|
20
20
|
|
|
21
21
|
// Ensure that Widgets cannot interfere with Frobs.
|
|
22
|
-
const makeWidget =
|
|
22
|
+
const makeWidget = prepareWidget(zone.subZone('Widgets'));
|
|
23
23
|
|
|
24
24
|
// Create a collection of frobulators.
|
|
25
25
|
const frobZone = zone.subZone('Frobs');
|
|
26
|
-
const makeFrobulator =
|
|
26
|
+
const makeFrobulator = prepareFrobulator(frobZone);
|
|
27
27
|
const widgetToFrob = frobZone.mapStore('widgetToFrob');
|
|
28
28
|
|
|
29
29
|
return Far('WidgetFrobulator', {
|
package/durable.d.ts
ADDED
package/durable.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durable.d.ts","sourceRoot":"","sources":["durable.js"],"names":[],"mappings":""}
|
package/heap.d.ts
ADDED
package/heap.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heap.d.ts","sourceRoot":"","sources":["heap.js"],"names":[],"mappings":""}
|
package/heap.js
CHANGED
package/package.json
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/zone",
|
|
3
|
-
"version": "0.2.3-other-dev-
|
|
3
|
+
"version": "0.2.3-other-dev-fbe72e7.0.fbe72e7",
|
|
4
4
|
"description": "Allocation zone abstraction for objects on the heap, persistent stores, etc.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": "https://github.com/Agoric/agoric-sdk",
|
|
7
7
|
"main": "./src/index.js",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "exit 0",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"prepack": "yarn run -T tsc --build tsconfig.build.json",
|
|
11
|
+
"postpack": "git clean -f '*.d.*ts*' '*.tsbuildinfo'",
|
|
12
|
+
"test": "ava",
|
|
13
|
+
"test:c8": "c8 --all ${C8_OPTIONS:-} ava",
|
|
12
14
|
"test:xs": "exit 0",
|
|
13
15
|
"lint-fix": "yarn lint:eslint --fix",
|
|
14
|
-
"lint": "run-s --continue-on-error lint:*",
|
|
15
|
-
"lint:types": "
|
|
16
|
-
"lint:eslint": "eslint ."
|
|
16
|
+
"lint": "yarn run -T run-s --continue-on-error 'lint:*'",
|
|
17
|
+
"lint:types": "yarn run -T tsc",
|
|
18
|
+
"lint:eslint": "yarn run -T eslint ."
|
|
17
19
|
},
|
|
18
20
|
"exports": {
|
|
19
21
|
".": "./src/index.js",
|
|
@@ -25,22 +27,35 @@
|
|
|
25
27
|
"author": "Agoric",
|
|
26
28
|
"license": "Apache-2.0",
|
|
27
29
|
"dependencies": {
|
|
28
|
-
"@agoric/
|
|
29
|
-
"@agoric/vat-data": "0.5.3-other-dev-
|
|
30
|
-
"@endo/
|
|
30
|
+
"@agoric/base-zone": "0.1.1-other-dev-fbe72e7.0.fbe72e7",
|
|
31
|
+
"@agoric/vat-data": "0.5.3-other-dev-fbe72e7.0.fbe72e7",
|
|
32
|
+
"@endo/errors": "^1.2.13",
|
|
33
|
+
"@endo/far": "^1.1.14",
|
|
34
|
+
"@endo/pass-style": "^1.6.3"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@agoric/swingset-vat": "0.32.3-other-dev-fbe72e7.0.fbe72e7",
|
|
38
|
+
"@endo/patterns": "^1.7.0",
|
|
39
|
+
"ava": "^5.3.0"
|
|
31
40
|
},
|
|
32
41
|
"publishConfig": {
|
|
33
42
|
"access": "public"
|
|
34
43
|
},
|
|
35
44
|
"engines": {
|
|
36
|
-
"node": "
|
|
45
|
+
"node": "^20.9 || ^22.11"
|
|
37
46
|
},
|
|
38
47
|
"ava": {
|
|
39
48
|
"files": [
|
|
40
|
-
"test
|
|
49
|
+
"test/**/*.test.*"
|
|
50
|
+
],
|
|
51
|
+
"require": [
|
|
52
|
+
"@endo/init/debug.js"
|
|
41
53
|
],
|
|
42
54
|
"timeout": "20m",
|
|
43
55
|
"workerThreads": false
|
|
44
56
|
},
|
|
45
|
-
"
|
|
57
|
+
"typeCoverage": {
|
|
58
|
+
"atLeast": 94
|
|
59
|
+
},
|
|
60
|
+
"gitHead": "fbe72e72107f9997f788674e668c660d92ec4492"
|
|
46
61
|
}
|
package/src/durable.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durable.d.ts","sourceRoot":"","sources":["durable.js"],"names":[],"mappings":"AA6EO,yCAJI,OAAO,kBAAkB,EAAE,OAAO,cAClC,MAAM,GACJ,IAAI,CA+ChB;0BApGsB,YAAY"}
|
package/src/durable.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
// @jessie-check
|
|
2
3
|
|
|
4
|
+
import { Fail } from '@endo/errors';
|
|
5
|
+
import { Far, isPassable } from '@endo/pass-style';
|
|
6
|
+
|
|
3
7
|
import {
|
|
4
8
|
canBeDurable,
|
|
5
9
|
makeScalarMapStore,
|
|
@@ -10,35 +14,48 @@ import {
|
|
|
10
14
|
provideDurableSetStore,
|
|
11
15
|
provideDurableWeakMapStore,
|
|
12
16
|
provideDurableWeakSetStore,
|
|
13
|
-
|
|
17
|
+
watchPromise,
|
|
14
18
|
} from '@agoric/vat-data';
|
|
15
19
|
|
|
16
|
-
import {
|
|
20
|
+
import { agoricVatDataKeys as keys, makeOnceKit } from '@agoric/base-zone';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @import {Zone} from './index.js';
|
|
24
|
+
*/
|
|
17
25
|
|
|
18
|
-
|
|
26
|
+
/**
|
|
27
|
+
* A variant of `canBeDurable` that returns `false` instead of ever throwing.
|
|
28
|
+
*
|
|
29
|
+
* @param {unknown} specimen
|
|
30
|
+
* @returns {boolean}
|
|
31
|
+
*/
|
|
32
|
+
const isStorable = specimen => isPassable(specimen) && canBeDurable(specimen);
|
|
33
|
+
harden(isStorable);
|
|
19
34
|
|
|
20
35
|
/**
|
|
21
36
|
* @param {() => import('@agoric/vat-data').Baggage} getBaggage
|
|
22
37
|
*/
|
|
23
38
|
const attachDurableStores = getBaggage => {
|
|
24
|
-
/** @type {
|
|
25
|
-
const mapStore = (label, options) =>
|
|
26
|
-
|
|
27
|
-
|
|
39
|
+
/** @type {Zone['mapStore']} */
|
|
40
|
+
const mapStore = (label, options) => {
|
|
41
|
+
const baggage = getBaggage();
|
|
42
|
+
const ret = provideDurableMapStore(baggage, label, options);
|
|
43
|
+
return ret;
|
|
44
|
+
};
|
|
45
|
+
/** @type {Zone['setStore']} */
|
|
28
46
|
const setStore = (label, options) =>
|
|
29
47
|
provideDurableSetStore(getBaggage(), label, options);
|
|
30
|
-
/** @type {
|
|
48
|
+
/** @type {Zone['weakSetStore']} */
|
|
31
49
|
const weakSetStore = (label, options) =>
|
|
32
50
|
provideDurableWeakSetStore(getBaggage(), label, options);
|
|
33
|
-
/** @type {
|
|
51
|
+
/** @type {Zone['weakMapStore']} */
|
|
34
52
|
const weakMapStore = (label, options) =>
|
|
35
53
|
provideDurableWeakMapStore(getBaggage(), label, options);
|
|
36
54
|
|
|
37
|
-
/** @type {import('.').Stores} */
|
|
55
|
+
/** @type {import('./index.js').Stores} */
|
|
38
56
|
return Far('durableStores', {
|
|
39
|
-
// eslint-disable-next-line no-use-before-define
|
|
40
57
|
detached: () => detachedDurableStores,
|
|
41
|
-
isStorable
|
|
58
|
+
isStorable,
|
|
42
59
|
mapStore,
|
|
43
60
|
setStore,
|
|
44
61
|
weakMapStore,
|
|
@@ -46,8 +63,8 @@ const attachDurableStores = getBaggage => {
|
|
|
46
63
|
});
|
|
47
64
|
};
|
|
48
65
|
|
|
49
|
-
/** @type {import('.').Stores} */
|
|
50
|
-
|
|
66
|
+
/** @type {import('./index.js').Stores} */
|
|
67
|
+
const detachedDurableStores = attachDurableStores(() =>
|
|
51
68
|
makeScalarMapStore('detached'),
|
|
52
69
|
);
|
|
53
70
|
|
|
@@ -55,33 +72,53 @@ export const detachedDurableStores = attachDurableStores(() =>
|
|
|
55
72
|
* Create a zone whose objects persist between Agoric vat upgrades.
|
|
56
73
|
*
|
|
57
74
|
* @param {import('@agoric/vat-data').Baggage} baggage
|
|
58
|
-
* @
|
|
75
|
+
* @param {string} [baseLabel]
|
|
76
|
+
* @returns {Zone}
|
|
59
77
|
*/
|
|
60
|
-
export const makeDurableZone = baggage => {
|
|
78
|
+
export const makeDurableZone = (baggage, baseLabel = 'durableZone') => {
|
|
61
79
|
baggage || Fail`baggage required`;
|
|
62
|
-
|
|
80
|
+
|
|
81
|
+
const attachedStores = attachDurableStores(() => baggage);
|
|
82
|
+
|
|
83
|
+
const { makeOnce, wrapProvider } = makeOnceKit(
|
|
84
|
+
baseLabel,
|
|
85
|
+
attachedStores,
|
|
86
|
+
baggage,
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
/** @type {Zone['exoClass']} */
|
|
63
90
|
const exoClass = (...args) => prepareExoClass(baggage, ...args);
|
|
64
|
-
/** @type {
|
|
91
|
+
/** @type {Zone['exoClassKit']} */
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- happens only integrating with Endo master
|
|
93
|
+
// @ts-ignore FIXME in Endo
|
|
65
94
|
const exoClassKit = (...args) => prepareExoClassKit(baggage, ...args);
|
|
66
|
-
/** @type {
|
|
95
|
+
/** @type {Zone['exo']} */
|
|
67
96
|
const exo = (...args) => prepareExo(baggage, ...args);
|
|
68
97
|
|
|
69
|
-
const
|
|
98
|
+
const subZoneStore = wrapProvider(attachedStores.mapStore, keys.zone);
|
|
70
99
|
|
|
71
|
-
/** @type {
|
|
100
|
+
/** @type {Zone['subZone']} */
|
|
72
101
|
const subZone = (label, options = {}) => {
|
|
73
|
-
|
|
74
|
-
|
|
102
|
+
/** @type {import('@agoric/swingset-liveslots').Baggage} */
|
|
103
|
+
const subBaggage = subZoneStore(label, options);
|
|
104
|
+
return makeDurableZone(subBaggage, `${baseLabel}.${label}`);
|
|
75
105
|
};
|
|
76
106
|
|
|
77
107
|
return Far('durableZone', {
|
|
78
|
-
exo,
|
|
79
|
-
exoClass,
|
|
80
|
-
exoClassKit,
|
|
108
|
+
exo: wrapProvider(exo, keys.exo),
|
|
109
|
+
exoClass: wrapProvider(exoClass, keys.exoClass),
|
|
110
|
+
exoClassKit: wrapProvider(exoClassKit, keys.exoClassKit),
|
|
81
111
|
subZone,
|
|
82
|
-
|
|
112
|
+
|
|
113
|
+
makeOnce,
|
|
114
|
+
watchPromise,
|
|
115
|
+
detached: attachedStores.detached,
|
|
116
|
+
isStorable: attachedStores.isStorable,
|
|
117
|
+
|
|
118
|
+
mapStore: wrapProvider(attachedStores.mapStore, keys.store),
|
|
119
|
+
setStore: wrapProvider(attachedStores.setStore, keys.store),
|
|
120
|
+
weakMapStore: wrapProvider(attachedStores.weakMapStore, keys.store),
|
|
121
|
+
weakSetStore: wrapProvider(attachedStores.weakSetStore, keys.store),
|
|
83
122
|
});
|
|
84
123
|
};
|
|
85
124
|
harden(makeDurableZone);
|
|
86
|
-
|
|
87
|
-
export { M };
|
package/src/exports.d.ts
ADDED
package/src/exports.js
ADDED
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":""}
|
package/src/index.js
CHANGED
|
@@ -1,37 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export { makeHeapZone } from '@agoric/base-zone/heap.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export * from './heap.js';
|
|
6
|
-
|
|
7
|
-
// References to allow the below typeofs to succeed.
|
|
8
|
-
makeExo;
|
|
9
|
-
defineExoClass;
|
|
10
|
-
defineExoClassKit;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @typedef {ExoZone & Stores} Zone A bag of methods for creating defensible objects and
|
|
14
|
-
* collections with the same allocation semantics (ephemeral, persistent, etc)
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @typedef {object} ExoZone
|
|
19
|
-
* @property {typeof makeExo} exo create a singleton exo-object instance bound to this zone
|
|
20
|
-
* @property {typeof defineExoClass} exoClass create a maker function that can be used to create exo-objects bound to this zone
|
|
21
|
-
* @property {typeof defineExoClassKit} exoClassKit create a "kit" maker function that can be used to create a record of exo-objects sharing the same state
|
|
22
|
-
* @property {(label: string, options?: StoreOptions) => Zone} subZone create a new Zone that can be passed to untrusted consumers without exposing the storage of the parent zone
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @typedef {object} Stores
|
|
27
|
-
* @property {() => Stores} detached obtain store providers which are detached (the stores are anonymous rather than bound to `label` in the zone)
|
|
28
|
-
* @property {(specimen: unknown) => boolean} isStorable return true if the specimen can be stored in the zone, whether as exo-object state or in a store
|
|
29
|
-
* @property {<K,V>(label: string, options?: StoreOptions) => MapStore<K, V>} mapStore provide a Map-like store named `label` in the zone
|
|
30
|
-
* @property {<K>(label: string, options?: StoreOptions) => SetStore<K>} setStore provide a Set-like store named `label` in the zone
|
|
31
|
-
* @property {<K,V>(
|
|
32
|
-
* label: string, options?: StoreOptions) => WeakMapStore<K, V>
|
|
33
|
-
* } weakMapStore provide a WeakMap-like store named `label` in the zone
|
|
34
|
-
* @property {<K>(
|
|
35
|
-
* label: string, options?: StoreOptions) => WeakSetStore<K>
|
|
36
|
-
* } weakSetStore provide a WeakSet-like store named `label` in the zone
|
|
37
|
-
*/
|
|
3
|
+
// eslint-disable-next-line import/export
|
|
4
|
+
export * from './exports.js';
|
package/src/virtual.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"virtual.d.ts","sourceRoot":"","sources":["virtual.js"],"names":[],"mappings":"AAiEO,4CAHI,MAAM,GACJ,OAAO,GAAG,EAAE,IAAI,CA+B5B"}
|
package/src/virtual.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
// @jessie-check
|
|
2
3
|
|
|
4
|
+
import { Far, isPassable } from '@endo/pass-style';
|
|
3
5
|
import {
|
|
4
|
-
canBeDurable,
|
|
5
6
|
defineVirtualExoClass,
|
|
6
7
|
defineVirtualExoClassKit,
|
|
7
8
|
makeScalarBigMapStore,
|
|
8
9
|
makeScalarBigSetStore,
|
|
9
10
|
makeScalarBigWeakMapStore,
|
|
10
11
|
makeScalarBigWeakSetStore,
|
|
11
|
-
M,
|
|
12
12
|
} from '@agoric/vat-data';
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
agoricVatDataKeys as keys,
|
|
16
|
+
makeOnceKit,
|
|
17
|
+
watchPromise,
|
|
18
|
+
} from '@agoric/base-zone';
|
|
15
19
|
|
|
16
20
|
const emptyRecord = harden({});
|
|
17
21
|
const initEmpty = harden(() => emptyRecord);
|
|
@@ -22,7 +26,7 @@ const initEmpty = harden(() => emptyRecord);
|
|
|
22
26
|
*
|
|
23
27
|
* @type {import('.').Zone['exo']}
|
|
24
28
|
*/
|
|
25
|
-
const
|
|
29
|
+
const makeVirtualExo = (
|
|
26
30
|
label,
|
|
27
31
|
interfaceGuard,
|
|
28
32
|
methods,
|
|
@@ -43,9 +47,9 @@ const defineVirtualExo = (
|
|
|
43
47
|
};
|
|
44
48
|
|
|
45
49
|
/** @type {import('.').Stores} */
|
|
46
|
-
|
|
50
|
+
const detachedVirtualStores = Far('virtualStores', {
|
|
47
51
|
detached: () => detachedVirtualStores,
|
|
48
|
-
isStorable:
|
|
52
|
+
isStorable: isPassable,
|
|
49
53
|
mapStore: makeScalarBigMapStore,
|
|
50
54
|
setStore: makeScalarBigSetStore,
|
|
51
55
|
weakMapStore: makeScalarBigWeakMapStore,
|
|
@@ -56,15 +60,36 @@ export const detachedVirtualStores = Far('virtualStores', {
|
|
|
56
60
|
* A zone that utilizes external storage to reduce the memory footprint of the
|
|
57
61
|
* current vat.
|
|
58
62
|
*
|
|
59
|
-
* @
|
|
63
|
+
* @param {string} [baseLabel]
|
|
64
|
+
* @returns {import('.').Zone}
|
|
60
65
|
*/
|
|
61
|
-
export const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
export const makeVirtualZone = (baseLabel = 'virtualZone') => {
|
|
67
|
+
const { makeOnce, wrapProvider } = makeOnceKit(
|
|
68
|
+
baseLabel,
|
|
69
|
+
detachedVirtualStores,
|
|
70
|
+
);
|
|
66
71
|
|
|
67
|
-
|
|
68
|
-
}
|
|
72
|
+
/**
|
|
73
|
+
* @param {string} label
|
|
74
|
+
* @param {any} _options
|
|
75
|
+
*/
|
|
76
|
+
const makeSubZone = (label, _options) =>
|
|
77
|
+
makeVirtualZone(`${baseLabel}.${label}`);
|
|
69
78
|
|
|
70
|
-
|
|
79
|
+
return Far('virtualZone', {
|
|
80
|
+
exo: wrapProvider(makeVirtualExo, keys.exo),
|
|
81
|
+
exoClass: wrapProvider(defineVirtualExoClass, keys.exoClass),
|
|
82
|
+
exoClassKit: wrapProvider(defineVirtualExoClassKit, keys.exoClassKit),
|
|
83
|
+
subZone: wrapProvider(makeSubZone),
|
|
84
|
+
|
|
85
|
+
makeOnce,
|
|
86
|
+
watchPromise,
|
|
87
|
+
detached: detachedVirtualStores.detached,
|
|
88
|
+
isStorable: detachedVirtualStores.isStorable,
|
|
89
|
+
|
|
90
|
+
mapStore: wrapProvider(detachedVirtualStores.mapStore),
|
|
91
|
+
setStore: wrapProvider(detachedVirtualStores.setStore),
|
|
92
|
+
weakMapStore: wrapProvider(detachedVirtualStores.weakMapStore),
|
|
93
|
+
weakSetStore: wrapProvider(detachedVirtualStores.weakSetStore),
|
|
94
|
+
});
|
|
95
|
+
};
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { M } from '@endo/patterns';
|
|
2
|
+
import {
|
|
3
|
+
annihilate,
|
|
4
|
+
getBaggage,
|
|
5
|
+
nextLife,
|
|
6
|
+
test,
|
|
7
|
+
} from '@agoric/swingset-vat/tools/prepare-strict-test-env-ava.js';
|
|
8
|
+
|
|
9
|
+
import * as vatData from '@agoric/vat-data';
|
|
10
|
+
|
|
11
|
+
import { agoricVatDataKeys as keys } from '@agoric/base-zone';
|
|
12
|
+
import {
|
|
13
|
+
agoricVatDataCompatibleKeys,
|
|
14
|
+
testFirstZoneIncarnation,
|
|
15
|
+
testSecondZoneIncarnation,
|
|
16
|
+
testGreeter,
|
|
17
|
+
} from '@agoric/base-zone/tools/testers.js';
|
|
18
|
+
import * as g from '@agoric/base-zone/tools/greeter.js';
|
|
19
|
+
|
|
20
|
+
import { makeDurableZone } from '../durable.js';
|
|
21
|
+
import { makeHeapZone } from '../heap.js';
|
|
22
|
+
import { makeVirtualZone } from '../virtual.js';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {import('ava').Assertions} t
|
|
26
|
+
* @param {MapStore} baggage
|
|
27
|
+
*/
|
|
28
|
+
const testFirstVatDataIncarnation = (t, baggage) => {
|
|
29
|
+
const subBaggage = vatData.provideDurableMapStore(baggage, 'sub');
|
|
30
|
+
|
|
31
|
+
const myThis = Object.freeze({ state: { nick: 'Singly' } });
|
|
32
|
+
const singly = vatData.prepareExo(subBaggage, 'a', g.GreeterWithAdminI, {
|
|
33
|
+
...g.bindAllMethodsTo(g.greetFacet, myThis),
|
|
34
|
+
...g.bindAllMethodsTo(g.adminFacet, myThis),
|
|
35
|
+
});
|
|
36
|
+
testGreeter(t, 'Singly', singly);
|
|
37
|
+
|
|
38
|
+
const makeGreeter = vatData.prepareExoClass(
|
|
39
|
+
subBaggage,
|
|
40
|
+
'Greeter',
|
|
41
|
+
g.GreeterWithAdminI,
|
|
42
|
+
nick => ({ nick }),
|
|
43
|
+
{
|
|
44
|
+
...g.greetFacet,
|
|
45
|
+
...g.adminFacet,
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
const classy = makeGreeter('Classy');
|
|
49
|
+
testGreeter(t, 'Classy', classy);
|
|
50
|
+
|
|
51
|
+
const makeGreeterKit = vatData.prepareExoClassKit(
|
|
52
|
+
subBaggage,
|
|
53
|
+
'GreeterKit',
|
|
54
|
+
{ greeter: g.GreeterI, admin: g.GreeterAdminI },
|
|
55
|
+
nick => ({ nick }),
|
|
56
|
+
{
|
|
57
|
+
greeter: g.greetFacet,
|
|
58
|
+
admin: g.adminFacet,
|
|
59
|
+
},
|
|
60
|
+
);
|
|
61
|
+
const { greeter: kitty, admin: kittyAdmin } = makeGreeterKit('Kitty');
|
|
62
|
+
testGreeter(t, 'Kitty', kitty, kittyAdmin);
|
|
63
|
+
|
|
64
|
+
const mappish = vatData.provideDurableMapStore(subBaggage, 'mappish');
|
|
65
|
+
mappish.init('singly', singly);
|
|
66
|
+
mappish.init('classy', classy);
|
|
67
|
+
mappish.init('kitty', kitty);
|
|
68
|
+
mappish.init('kittyAdmin', kittyAdmin);
|
|
69
|
+
|
|
70
|
+
vatData.provideDurableMapStore(subBaggage, 'subsub');
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
test('heapZone', t => {
|
|
74
|
+
const zone = makeHeapZone();
|
|
75
|
+
testFirstZoneIncarnation(t, zone);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test.serial('virtualZone', t => {
|
|
79
|
+
annihilate();
|
|
80
|
+
const zone = makeVirtualZone();
|
|
81
|
+
testFirstZoneIncarnation(t, zone);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test.serial('durableZone', t => {
|
|
85
|
+
annihilate();
|
|
86
|
+
|
|
87
|
+
const expectedKeys = [
|
|
88
|
+
...keys.exo('a'),
|
|
89
|
+
...keys.exoClass('Greeter'),
|
|
90
|
+
...keys.exoClassKit('GreeterKit'),
|
|
91
|
+
...keys.store('mappish'),
|
|
92
|
+
...keys.zone('subsub'),
|
|
93
|
+
].sort();
|
|
94
|
+
t.deepEqual(agoricVatDataCompatibleKeys, expectedKeys);
|
|
95
|
+
|
|
96
|
+
nextLife();
|
|
97
|
+
const baggage1 = getBaggage();
|
|
98
|
+
testFirstZoneIncarnation(t, makeDurableZone(baggage1));
|
|
99
|
+
t.deepEqual(
|
|
100
|
+
[...baggage1.get('sub').keys()].sort(),
|
|
101
|
+
agoricVatDataCompatibleKeys,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
nextLife();
|
|
105
|
+
const baggage2 = getBaggage();
|
|
106
|
+
t.deepEqual(
|
|
107
|
+
[...baggage2.get('sub').keys()].sort(),
|
|
108
|
+
agoricVatDataCompatibleKeys,
|
|
109
|
+
);
|
|
110
|
+
testSecondZoneIncarnation(t, makeDurableZone(baggage2));
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test.serial('vatData migrate to durableZone', t => {
|
|
114
|
+
annihilate();
|
|
115
|
+
|
|
116
|
+
const baggage1 = getBaggage();
|
|
117
|
+
testFirstVatDataIncarnation(t, baggage1);
|
|
118
|
+
t.deepEqual(
|
|
119
|
+
[...baggage1.get('sub').keys()].sort(),
|
|
120
|
+
agoricVatDataCompatibleKeys,
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
nextLife();
|
|
124
|
+
const baggage2 = getBaggage();
|
|
125
|
+
testSecondZoneIncarnation(t, makeDurableZone(baggage2));
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test.serial('exoClass stateShape expansion', t => {
|
|
129
|
+
annihilate();
|
|
130
|
+
|
|
131
|
+
// See ../../swingset-liveslots/test/virtual-objects/state-shape.test.js
|
|
132
|
+
const stateShapeMismatch = { message: /stateShape mismatch/ };
|
|
133
|
+
const HolderI = M.interface('Holder', {
|
|
134
|
+
get: M.call().rest(M.arrayOf(M.string())).returns(M.record()),
|
|
135
|
+
set: M.call(M.record()).returns(),
|
|
136
|
+
});
|
|
137
|
+
const initHolder = fields => ({ ...fields });
|
|
138
|
+
const holderMethods = {
|
|
139
|
+
get(...fields) {
|
|
140
|
+
const { state } = this;
|
|
141
|
+
// We require fields to be explicit because they are currently defined on
|
|
142
|
+
// the state *prototype*.
|
|
143
|
+
return Object.fromEntries(
|
|
144
|
+
fields.flatMap(key => (key in state ? [[key, state[key]]] : [])),
|
|
145
|
+
);
|
|
146
|
+
},
|
|
147
|
+
set(fields) {
|
|
148
|
+
Object.assign(this.state, fields);
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
const prepareHolder = (zone, stateShape) =>
|
|
152
|
+
zone.exoClass('Holder', HolderI, initHolder, holderMethods, { stateShape });
|
|
153
|
+
|
|
154
|
+
const fields = ['foo', 'bar', 'baz']; // but "baz" is not initially present
|
|
155
|
+
const baggage1 = getBaggage();
|
|
156
|
+
const zone1 = makeDurableZone(baggage1);
|
|
157
|
+
const makeHolder1 = prepareHolder(zone1, {
|
|
158
|
+
foo: M.number(),
|
|
159
|
+
bar: M.number(),
|
|
160
|
+
});
|
|
161
|
+
const holder1 = makeHolder1({ foo: 0, bar: 1 });
|
|
162
|
+
t.deepEqual(holder1.get(...fields), { foo: 0, bar: 1 });
|
|
163
|
+
holder1.set({ foo: 2, bar: 2 });
|
|
164
|
+
t.deepEqual(holder1.get(...fields), { foo: 2, bar: 2 });
|
|
165
|
+
t.throws(() => makeHolder1({ foo: 0, bar: 1, baz: 2 }));
|
|
166
|
+
t.throws(() => makeHolder1({ foo: 0, bar: 'string' }));
|
|
167
|
+
|
|
168
|
+
nextLife();
|
|
169
|
+
t.throws(
|
|
170
|
+
() =>
|
|
171
|
+
prepareHolder(makeDurableZone(getBaggage()), {
|
|
172
|
+
foo: M.string(),
|
|
173
|
+
bar: M.number(),
|
|
174
|
+
}),
|
|
175
|
+
stateShapeMismatch,
|
|
176
|
+
'backwards-incompatible stateShape change',
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
nextLife();
|
|
180
|
+
t.throws(
|
|
181
|
+
() =>
|
|
182
|
+
prepareHolder(makeDurableZone(getBaggage()), {
|
|
183
|
+
foo: M.or(M.number(), M.string()),
|
|
184
|
+
bar: M.number(),
|
|
185
|
+
baz: M.or(undefined, M.number()),
|
|
186
|
+
}),
|
|
187
|
+
stateShapeMismatch,
|
|
188
|
+
'stateShape field value expansion (needs #7407)',
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
nextLife();
|
|
192
|
+
const baggage2 = getBaggage();
|
|
193
|
+
const zone2 = makeDurableZone(baggage2);
|
|
194
|
+
const makeHolder2 = prepareHolder(zone2, {
|
|
195
|
+
foo: M.number(),
|
|
196
|
+
bar: M.number(),
|
|
197
|
+
baz: M.or(undefined, M.number()),
|
|
198
|
+
});
|
|
199
|
+
const holder2 = makeHolder2({ foo: 0, bar: 1, baz: 2 });
|
|
200
|
+
t.deepEqual(holder2.get(...fields), { foo: 0, bar: 1, baz: 2 });
|
|
201
|
+
holder2.set({ foo: 2, bar: 2, baz: undefined });
|
|
202
|
+
t.deepEqual(holder2.get(...fields), { foo: 2, bar: 2, baz: undefined });
|
|
203
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
annihilate,
|
|
3
|
+
getBaggage,
|
|
4
|
+
nextLife,
|
|
5
|
+
test,
|
|
6
|
+
} from '@agoric/swingset-vat/tools/prepare-strict-test-env-ava.js';
|
|
7
|
+
|
|
8
|
+
import { makeDurableZone } from '../durable.js';
|
|
9
|
+
import { makeHeapZone } from '../heap.js';
|
|
10
|
+
import { makeVirtualZone } from '../virtual.js';
|
|
11
|
+
|
|
12
|
+
/** @import {Zone} from '../src/index.js' */
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {import('ava').Assertions} t
|
|
16
|
+
* @param {Zone} rootZone
|
|
17
|
+
*/
|
|
18
|
+
const testOnce = (t, rootZone) => {
|
|
19
|
+
const subZone = rootZone.subZone('sub');
|
|
20
|
+
const a = subZone.makeOnce('a', () => 'A');
|
|
21
|
+
t.is(a, 'A');
|
|
22
|
+
t.throws(() => subZone.makeOnce('a', () => 'A'), {
|
|
23
|
+
message: /has already been used/,
|
|
24
|
+
});
|
|
25
|
+
const nonPassable = harden({
|
|
26
|
+
hello() {
|
|
27
|
+
return 'world';
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
t.is(rootZone.isStorable(nonPassable), false);
|
|
31
|
+
t.is(subZone.isStorable(123), true);
|
|
32
|
+
t.throws(() => rootZone.makeOnce('nonPassable', () => nonPassable), {
|
|
33
|
+
message: /is not storable/,
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
test('heapZone', t => {
|
|
38
|
+
testOnce(t, makeHeapZone());
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test.serial('virtualZone', t => {
|
|
42
|
+
testOnce(t, makeVirtualZone());
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test.serial('durableZone', t => {
|
|
46
|
+
annihilate();
|
|
47
|
+
const rootBaggage = getBaggage();
|
|
48
|
+
const rootDurableZone = makeDurableZone(rootBaggage);
|
|
49
|
+
testOnce(t, rootDurableZone);
|
|
50
|
+
|
|
51
|
+
// Do we actually want to refuse to use the same baggage twice?
|
|
52
|
+
const secondDurableZone = makeDurableZone(rootBaggage);
|
|
53
|
+
testOnce(t, secondDurableZone);
|
|
54
|
+
const subDurableZone = makeDurableZone(rootBaggage).subZone('sub');
|
|
55
|
+
t.is(
|
|
56
|
+
subDurableZone.makeOnce('a', () => 'B'),
|
|
57
|
+
'A',
|
|
58
|
+
);
|
|
59
|
+
t.throws(() => subDurableZone.makeOnce('a', () => 'B'), {
|
|
60
|
+
message: /has already been used/,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
nextLife();
|
|
64
|
+
const thirdDurableZone = makeDurableZone(getBaggage());
|
|
65
|
+
testOnce(t, thirdDurableZone);
|
|
66
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./durable.js","./heap.js","./virtual.js","./src/durable.js","./src/index.js","./src/virtual.js"],"version":"5.9.2"}
|
package/tsconfig.json
ADDED
package/typedoc.json
ADDED
package/virtual.d.ts
ADDED
package/virtual.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"virtual.d.ts","sourceRoot":"","sources":["virtual.js"],"names":[],"mappings":""}
|
package/jsconfig.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// This file can contain .js-specific Typescript compiler config.
|
|
2
|
-
{
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"target": "esnext",
|
|
5
|
-
"module": "esnext",
|
|
6
|
-
"checkJs": true,
|
|
7
|
-
"noEmit": true,
|
|
8
|
-
"downlevelIteration": true,
|
|
9
|
-
"strictNullChecks": true,
|
|
10
|
-
"noImplicitThis": true,
|
|
11
|
-
"moduleResolution": "node",
|
|
12
|
-
},
|
|
13
|
-
"include": [
|
|
14
|
-
"*.js",
|
|
15
|
-
"scripts",
|
|
16
|
-
"src",
|
|
17
|
-
"test",
|
|
18
|
-
],
|
|
19
|
-
}
|
package/src/heap.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// @jessie-check
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
makeExo,
|
|
5
|
-
defineExoClass,
|
|
6
|
-
defineExoClassKit,
|
|
7
|
-
makeScalarMapStore,
|
|
8
|
-
makeScalarSetStore,
|
|
9
|
-
makeScalarWeakMapStore,
|
|
10
|
-
makeScalarWeakSetStore,
|
|
11
|
-
M,
|
|
12
|
-
} from '@agoric/store';
|
|
13
|
-
|
|
14
|
-
import { Far } from '@endo/far';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @type {import('.').Stores}
|
|
18
|
-
*/
|
|
19
|
-
const heapStores = Far('heapStores', {
|
|
20
|
-
detached: () => heapStores,
|
|
21
|
-
isStorable: _specimen => true,
|
|
22
|
-
|
|
23
|
-
setStore: makeScalarSetStore,
|
|
24
|
-
mapStore: makeScalarMapStore,
|
|
25
|
-
weakMapStore: makeScalarWeakMapStore,
|
|
26
|
-
weakSetStore: makeScalarWeakSetStore,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* A heap (in-memory) zone that uses the default exo and store implementations.
|
|
31
|
-
*
|
|
32
|
-
* @type {import('.').Zone}
|
|
33
|
-
*/
|
|
34
|
-
export const heapZone = Far('heapZone', {
|
|
35
|
-
exoClass: defineExoClass,
|
|
36
|
-
exoClassKit: defineExoClassKit,
|
|
37
|
-
exo: makeExo,
|
|
38
|
-
subZone: (_label, _options) => heapZone,
|
|
39
|
-
...heapStores,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
export { M };
|