@agoric/zone 0.2.2 → 0.2.3-calypso-dev-84eb287.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +24 -10
- package/src/durable.d.ts +2 -0
- package/src/durable.d.ts.map +1 -0
- package/src/durable.js +50 -16
- 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 +126 -0
- package/test/make-once.test.js +66 -0
- package/test/prepare-test-env-ava.js +21 -0
- package/tsconfig.build.json +11 -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/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,18 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/zone",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3-calypso-dev-84eb287.0+84eb287",
|
|
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": "tsc --build tsconfig.build.json",
|
|
11
|
+
"postpack": "git clean -f '*.d.ts*'",
|
|
12
|
+
"test": "ava",
|
|
13
|
+
"test:c8": "c8 $C8_OPTIONS ava --config=ava-nesm.config.js",
|
|
12
14
|
"test:xs": "exit 0",
|
|
13
15
|
"lint-fix": "yarn lint:eslint --fix",
|
|
14
16
|
"lint": "run-s --continue-on-error lint:*",
|
|
15
|
-
"lint:types": "tsc
|
|
17
|
+
"lint:types": "tsc",
|
|
16
18
|
"lint:eslint": "eslint ."
|
|
17
19
|
},
|
|
18
20
|
"exports": {
|
|
@@ -25,22 +27,34 @@
|
|
|
25
27
|
"author": "Agoric",
|
|
26
28
|
"license": "Apache-2.0",
|
|
27
29
|
"dependencies": {
|
|
28
|
-
"@agoric/
|
|
29
|
-
"@agoric/vat-data": "
|
|
30
|
-
"@endo/far": "^
|
|
30
|
+
"@agoric/base-zone": "0.1.1-calypso-dev-84eb287.0+84eb287",
|
|
31
|
+
"@agoric/vat-data": "0.5.3-calypso-dev-84eb287.0+84eb287",
|
|
32
|
+
"@endo/far": "^1.1.2",
|
|
33
|
+
"@endo/pass-style": "^1.4.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@agoric/swingset-liveslots": "0.10.3-calypso-dev-84eb287.0+84eb287",
|
|
37
|
+
"@endo/patterns": "^1.4.0",
|
|
38
|
+
"ava": "^5.3.0"
|
|
31
39
|
},
|
|
32
40
|
"publishConfig": {
|
|
33
41
|
"access": "public"
|
|
34
42
|
},
|
|
35
43
|
"engines": {
|
|
36
|
-
"node": "
|
|
44
|
+
"node": "^18.12 || ^20.9"
|
|
37
45
|
},
|
|
38
46
|
"ava": {
|
|
39
47
|
"files": [
|
|
40
|
-
"test
|
|
48
|
+
"test/**/*.test.*"
|
|
49
|
+
],
|
|
50
|
+
"require": [
|
|
51
|
+
"@endo/init/debug.js"
|
|
41
52
|
],
|
|
42
53
|
"timeout": "20m",
|
|
43
54
|
"workerThreads": false
|
|
44
55
|
},
|
|
45
|
-
"
|
|
56
|
+
"typeCoverage": {
|
|
57
|
+
"atLeast": 96.68
|
|
58
|
+
},
|
|
59
|
+
"gitHead": "84eb287915c8255d68e845a9b6e10c790f0d54cb"
|
|
46
60
|
}
|
package/src/durable.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durable.d.ts","sourceRoot":"","sources":["durable.js"],"names":[],"mappings":"AA0EO,yCAJI,OAAO,kBAAkB,EAAE,OAAO,mCAEhC,OAAO,GAAG,EAAE,IAAI,CA+C5B"}
|
package/src/durable.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
// @jessie-check
|
|
2
3
|
|
|
4
|
+
import { Far, isPassable } from '@endo/pass-style';
|
|
3
5
|
import {
|
|
4
6
|
canBeDurable,
|
|
5
7
|
makeScalarMapStore,
|
|
@@ -10,20 +12,32 @@ import {
|
|
|
10
12
|
provideDurableSetStore,
|
|
11
13
|
provideDurableWeakMapStore,
|
|
12
14
|
provideDurableWeakSetStore,
|
|
13
|
-
|
|
15
|
+
watchPromise,
|
|
14
16
|
} from '@agoric/vat-data';
|
|
15
17
|
|
|
16
|
-
import {
|
|
18
|
+
import { agoricVatDataKeys as keys, makeOnceKit } from '@agoric/base-zone';
|
|
17
19
|
|
|
18
20
|
const { Fail } = assert;
|
|
19
21
|
|
|
22
|
+
/**
|
|
23
|
+
* A variant of `canBeDurable` that returns `false` instead of ever throwing.
|
|
24
|
+
*
|
|
25
|
+
* @param {unknown} specimen
|
|
26
|
+
* @returns {boolean}
|
|
27
|
+
*/
|
|
28
|
+
const isStorable = specimen => isPassable(specimen) && canBeDurable(specimen);
|
|
29
|
+
harden(isStorable);
|
|
30
|
+
|
|
20
31
|
/**
|
|
21
32
|
* @param {() => import('@agoric/vat-data').Baggage} getBaggage
|
|
22
33
|
*/
|
|
23
34
|
const attachDurableStores = getBaggage => {
|
|
24
35
|
/** @type {import('.').Zone['mapStore']} */
|
|
25
|
-
const mapStore = (label, options) =>
|
|
26
|
-
|
|
36
|
+
const mapStore = (label, options) => {
|
|
37
|
+
const baggage = getBaggage();
|
|
38
|
+
const ret = provideDurableMapStore(baggage, label, options);
|
|
39
|
+
return ret;
|
|
40
|
+
};
|
|
27
41
|
/** @type {import('.').Zone['setStore']} */
|
|
28
42
|
const setStore = (label, options) =>
|
|
29
43
|
provideDurableSetStore(getBaggage(), label, options);
|
|
@@ -38,7 +52,7 @@ const attachDurableStores = getBaggage => {
|
|
|
38
52
|
return Far('durableStores', {
|
|
39
53
|
// eslint-disable-next-line no-use-before-define
|
|
40
54
|
detached: () => detachedDurableStores,
|
|
41
|
-
isStorable
|
|
55
|
+
isStorable,
|
|
42
56
|
mapStore,
|
|
43
57
|
setStore,
|
|
44
58
|
weakMapStore,
|
|
@@ -47,7 +61,7 @@ const attachDurableStores = getBaggage => {
|
|
|
47
61
|
};
|
|
48
62
|
|
|
49
63
|
/** @type {import('.').Stores} */
|
|
50
|
-
|
|
64
|
+
const detachedDurableStores = attachDurableStores(() =>
|
|
51
65
|
makeScalarMapStore('detached'),
|
|
52
66
|
);
|
|
53
67
|
|
|
@@ -55,33 +69,53 @@ export const detachedDurableStores = attachDurableStores(() =>
|
|
|
55
69
|
* Create a zone whose objects persist between Agoric vat upgrades.
|
|
56
70
|
*
|
|
57
71
|
* @param {import('@agoric/vat-data').Baggage} baggage
|
|
72
|
+
* @param {string} [baseLabel]
|
|
58
73
|
* @returns {import('.').Zone}
|
|
59
74
|
*/
|
|
60
|
-
export const makeDurableZone = baggage => {
|
|
75
|
+
export const makeDurableZone = (baggage, baseLabel = 'durableZone') => {
|
|
61
76
|
baggage || Fail`baggage required`;
|
|
77
|
+
|
|
78
|
+
const attachedStores = attachDurableStores(() => baggage);
|
|
79
|
+
|
|
80
|
+
const { makeOnce, wrapProvider } = makeOnceKit(
|
|
81
|
+
baseLabel,
|
|
82
|
+
attachedStores,
|
|
83
|
+
baggage,
|
|
84
|
+
);
|
|
85
|
+
|
|
62
86
|
/** @type {import('.').Zone['exoClass']} */
|
|
63
87
|
const exoClass = (...args) => prepareExoClass(baggage, ...args);
|
|
64
88
|
/** @type {import('.').Zone['exoClassKit']} */
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error -- happens only integrating with Endo master
|
|
90
|
+
// @ts-ignore FIXME in Endo
|
|
65
91
|
const exoClassKit = (...args) => prepareExoClassKit(baggage, ...args);
|
|
66
92
|
/** @type {import('.').Zone['exo']} */
|
|
67
93
|
const exo = (...args) => prepareExo(baggage, ...args);
|
|
68
94
|
|
|
69
|
-
const
|
|
95
|
+
const subZoneStore = wrapProvider(attachedStores.mapStore, keys.zone);
|
|
70
96
|
|
|
71
97
|
/** @type {import('.').Zone['subZone']} */
|
|
72
98
|
const subZone = (label, options = {}) => {
|
|
73
|
-
|
|
74
|
-
|
|
99
|
+
/** @type {import('@agoric/swingset-liveslots').Baggage} */
|
|
100
|
+
const subBaggage = subZoneStore(label, options);
|
|
101
|
+
return makeDurableZone(subBaggage, `${baseLabel}.${label}`);
|
|
75
102
|
};
|
|
76
103
|
|
|
77
104
|
return Far('durableZone', {
|
|
78
|
-
exo,
|
|
79
|
-
exoClass,
|
|
80
|
-
exoClassKit,
|
|
105
|
+
exo: wrapProvider(exo, keys.exo),
|
|
106
|
+
exoClass: wrapProvider(exoClass, keys.exoClass),
|
|
107
|
+
exoClassKit: wrapProvider(exoClassKit, keys.exoClassKit),
|
|
81
108
|
subZone,
|
|
82
|
-
|
|
109
|
+
|
|
110
|
+
makeOnce,
|
|
111
|
+
watchPromise,
|
|
112
|
+
detached: attachedStores.detached,
|
|
113
|
+
isStorable: attachedStores.isStorable,
|
|
114
|
+
|
|
115
|
+
mapStore: wrapProvider(attachedStores.mapStore, keys.store),
|
|
116
|
+
setStore: wrapProvider(attachedStores.setStore, keys.store),
|
|
117
|
+
weakMapStore: wrapProvider(attachedStores.weakMapStore, keys.store),
|
|
118
|
+
weakSetStore: wrapProvider(attachedStores.weakSetStore, keys.store),
|
|
83
119
|
});
|
|
84
120
|
};
|
|
85
121
|
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,iEAFM,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,126 @@
|
|
|
1
|
+
// eslint-disable-next-line import/order
|
|
2
|
+
import {
|
|
3
|
+
annihilate,
|
|
4
|
+
getBaggage,
|
|
5
|
+
nextLife,
|
|
6
|
+
test,
|
|
7
|
+
} from './prepare-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
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
annihilate,
|
|
3
|
+
getBaggage,
|
|
4
|
+
nextLife,
|
|
5
|
+
test,
|
|
6
|
+
} from './prepare-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,21 @@
|
|
|
1
|
+
import '@agoric/swingset-liveslots/tools/prepare-test-env.js';
|
|
2
|
+
import { reincarnate } from '@agoric/swingset-liveslots/tools/setup-vat-data.js';
|
|
3
|
+
|
|
4
|
+
import test from 'ava';
|
|
5
|
+
|
|
6
|
+
export { test };
|
|
7
|
+
|
|
8
|
+
/** @type {ReturnType<typeof reincarnate>} */
|
|
9
|
+
let incarnation;
|
|
10
|
+
|
|
11
|
+
export const annihilate = () => {
|
|
12
|
+
incarnation = reincarnate({ relaxDurabilityRules: false });
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const getBaggage = () => {
|
|
16
|
+
return incarnation.fakeVomKit.cm.provideBaggage();
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const nextLife = () => {
|
|
20
|
+
incarnation = reincarnate(incarnation);
|
|
21
|
+
};
|
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 };
|