@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 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 { zoneFrobulator } from 'frob-package';
16
- import { zoneWidget } from 'widget-package';
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 = zoneWidget(zone.subZone('Widgets'));
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 = zoneFrobulator(frobZone);
26
+ const makeFrobulator = prepareFrobulator(frobZone);
27
27
  const widgetToFrob = frobZone.mapStore('widgetToFrob');
28
28
 
29
29
  return Far('WidgetFrobulator', {
package/durable.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./src/durable.js";
2
+ //# sourceMappingURL=durable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durable.d.ts","sourceRoot":"","sources":["durable.js"],"names":[],"mappings":""}
package/heap.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "@agoric/base-zone/heap.js";
2
+ //# sourceMappingURL=heap.d.ts.map
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
@@ -1,3 +1,3 @@
1
1
  // @jessie-check
2
2
 
3
- export * from './src/heap.js';
3
+ export * from '@agoric/base-zone/heap.js';
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "@agoric/zone",
3
- "version": "0.2.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
- "test": "true || ava",
11
- "test:c8": "true || c8 $C8_OPTIONS ava --config=ava-nesm.config.js",
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 -p jsconfig.json",
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/store": "^0.9.2",
29
- "@agoric/vat-data": "^0.5.2",
30
- "@endo/far": "^0.2.18"
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": ">=14.15.0"
44
+ "node": "^18.12 || ^20.9"
37
45
  },
38
46
  "ava": {
39
47
  "files": [
40
- "test/**/test-*.js"
48
+ "test/**/*.test.*"
49
+ ],
50
+ "require": [
51
+ "@endo/init/debug.js"
41
52
  ],
42
53
  "timeout": "20m",
43
54
  "workerThreads": false
44
55
  },
45
- "gitHead": "b66bf7c881ae462fcb617cd6e8d41b5c40ec58ef"
56
+ "typeCoverage": {
57
+ "atLeast": 96.68
58
+ },
59
+ "gitHead": "84eb287915c8255d68e845a9b6e10c790f0d54cb"
46
60
  }
@@ -0,0 +1,2 @@
1
+ export function makeDurableZone(baggage: import("@agoric/vat-data").Baggage, baseLabel?: string | undefined): import(".").Zone;
2
+ //# sourceMappingURL=durable.d.ts.map
@@ -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
- M,
15
+ watchPromise,
14
16
  } from '@agoric/vat-data';
15
17
 
16
- import { Far } from '@endo/far';
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
- provideDurableMapStore(getBaggage(), label, options);
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: canBeDurable,
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
- export const detachedDurableStores = attachDurableStores(() =>
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 attachedStores = attachDurableStores(() => baggage);
95
+ const subZoneStore = wrapProvider(attachedStores.mapStore, keys.zone);
70
96
 
71
97
  /** @type {import('.').Zone['subZone']} */
72
98
  const subZone = (label, options = {}) => {
73
- const subBaggage = provideDurableMapStore(baggage, label, options);
74
- return makeDurableZone(subBaggage);
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
- ...attachedStores,
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 };
@@ -0,0 +1,6 @@
1
+ // Module Types //////////////////////////////////////////////////////
2
+ //
3
+ // Types exposed from modules.
4
+ //
5
+
6
+ export type * from '@agoric/base-zone';
package/src/exports.js ADDED
@@ -0,0 +1,2 @@
1
+ // Just a dummy to use exports.d.ts and satisfy runtime imports.
2
+ export {};
package/src/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { makeHeapZone } from "@agoric/base-zone/heap.js";
2
+ export * from "./exports.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -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
- // @jessie-check
1
+ export { makeHeapZone } from '@agoric/base-zone/heap.js';
2
2
 
3
- import { makeExo, defineExoClass, defineExoClassKit } from '@agoric/store';
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';
@@ -0,0 +1,2 @@
1
+ export function makeVirtualZone(baseLabel?: string | undefined): import(".").Zone;
2
+ //# sourceMappingURL=virtual.d.ts.map
@@ -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 { Far } from '@endo/far';
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 defineVirtualExo = (
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
- export const detachedVirtualStores = Far('virtualStores', {
50
+ const detachedVirtualStores = Far('virtualStores', {
47
51
  detached: () => detachedVirtualStores,
48
- isStorable: canBeDurable,
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
- * @type {import('.').Zone}
63
+ * @param {string} [baseLabel]
64
+ * @returns {import('.').Zone}
60
65
  */
61
- export const virtualZone = Far('virtualZone', {
62
- exo: defineVirtualExo,
63
- exoClass: defineVirtualExoClass,
64
- exoClassKit: defineVirtualExoClassKit,
65
- subZone: (_label, _options = {}) => virtualZone,
66
+ export const makeVirtualZone = (baseLabel = 'virtualZone') => {
67
+ const { makeOnce, wrapProvider } = makeOnceKit(
68
+ baseLabel,
69
+ detachedVirtualStores,
70
+ );
66
71
 
67
- ...detachedVirtualStores,
68
- });
72
+ /**
73
+ * @param {string} label
74
+ * @param {any} _options
75
+ */
76
+ const makeSubZone = (label, _options) =>
77
+ makeVirtualZone(`${baseLabel}.${label}`);
69
78
 
70
- export { M };
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
+ };
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": [
3
+ "./tsconfig.json",
4
+ "../../tsconfig-build-options.json"
5
+ ],
6
+ "exclude": [
7
+ "scripts",
8
+ "test",
9
+ "**/exports.js",
10
+ ]
11
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ // This file can contain .js-specific Typescript compiler config.
2
+ {
3
+ "extends": "../../tsconfig.json",
4
+ "compilerOptions": {},
5
+ "include": [
6
+ "*.js",
7
+ "scripts",
8
+ "src/**/*.js",
9
+ "test/**/*.js",
10
+ ],
11
+ }
package/typedoc.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": [
3
+ "../../typedoc.base.json"
4
+ ],
5
+ "entryPoints": [
6
+ "src/index.js",
7
+ ]
8
+ }
package/virtual.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./src/virtual.js";
2
+ //# sourceMappingURL=virtual.d.ts.map
@@ -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 };