@agoric/zone 0.2.3-other-dev-3eb1a1d.0 → 0.2.3-other-dev-d15096d.0.d15096d

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 CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "@agoric/zone",
3
- "version": "0.2.3-other-dev-3eb1a1d.0+3eb1a1d",
3
+ "version": "0.2.3-other-dev-d15096d.0.d15096d",
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
- "prepack": "tsc --build tsconfig.build.json",
11
- "postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'",
10
+ "prepack": "yarn run -T tsc --build tsconfig.build.json",
11
+ "postpack": "git clean -f '*.d.*ts*' '*.tsbuildinfo'",
12
12
  "test": "ava",
13
- "test:c8": "c8 --all $C8_OPTIONS ava",
13
+ "test:c8": "c8 --all ${C8_OPTIONS:-} ava",
14
14
  "test:xs": "exit 0",
15
15
  "lint-fix": "yarn lint:eslint --fix",
16
- "lint": "run-s --continue-on-error lint:*",
17
- "lint:types": "tsc",
18
- "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 ."
19
19
  },
20
20
  "exports": {
21
21
  ".": "./src/index.js",
@@ -27,22 +27,22 @@
27
27
  "author": "Agoric",
28
28
  "license": "Apache-2.0",
29
29
  "dependencies": {
30
- "@agoric/base-zone": "0.1.1-other-dev-3eb1a1d.0+3eb1a1d",
31
- "@agoric/vat-data": "0.5.3-other-dev-3eb1a1d.0+3eb1a1d",
32
- "@endo/errors": "^1.2.8",
33
- "@endo/far": "^1.1.9",
34
- "@endo/pass-style": "^1.4.7"
30
+ "@agoric/base-zone": "0.1.1-other-dev-d15096d.0.d15096d",
31
+ "@agoric/vat-data": "0.5.3-other-dev-d15096d.0.d15096d",
32
+ "@endo/errors": "^1.2.13",
33
+ "@endo/far": "^1.1.14",
34
+ "@endo/pass-style": "^1.6.3"
35
35
  },
36
36
  "devDependencies": {
37
- "@agoric/swingset-vat": "0.32.3-other-dev-3eb1a1d.0+3eb1a1d",
38
- "@endo/patterns": "^1.4.7",
37
+ "@agoric/swingset-vat": "0.32.3-other-dev-d15096d.0.d15096d",
38
+ "@endo/patterns": "^1.7.0",
39
39
  "ava": "^5.3.0"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public"
43
43
  },
44
44
  "engines": {
45
- "node": "^18.12 || ^20.9"
45
+ "node": "^20.9 || ^22.11"
46
46
  },
47
47
  "ava": {
48
48
  "files": [
@@ -55,7 +55,7 @@
55
55
  "workerThreads": false
56
56
  },
57
57
  "typeCoverage": {
58
- "atLeast": 98.56
58
+ "atLeast": 94
59
59
  },
60
- "gitHead": "3eb1a1d2d75b2b4a94807cd3bf759bc9fc531f05"
60
+ "gitHead": "d15096dc4ff8b96e9b6cd11954c20d3a9efbb393"
61
61
  }
package/src/durable.d.ts CHANGED
@@ -1,2 +1,4 @@
1
- export function makeDurableZone(baggage: import("@agoric/vat-data").Baggage, baseLabel?: string | undefined): import(".").Zone;
1
+ export function makeDurableZone(baggage: Baggage, baseLabel?: string): Zone;
2
+ import type { Baggage } from '@agoric/swingset-liveslots';
3
+ import type { Zone } from './index.js';
2
4
  //# sourceMappingURL=durable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"durable.d.ts","sourceRoot":"","sources":["durable.js"],"names":[],"mappings":"AAyEO,yCAJI,OAAO,kBAAkB,EAAE,OAAO,mCAEhC,OAAO,GAAG,EAAE,IAAI,CA+C5B"}
1
+ {"version":3,"file":"durable.d.ts","sourceRoot":"","sources":["durable.js"],"names":[],"mappings":"AA+EO,yCAJI,OAAO,cACP,MAAM,GACJ,IAAI,CA+ChB;6BApGyB,4BAA4B;0BAF/B,YAAY"}
package/src/durable.js CHANGED
@@ -19,6 +19,12 @@ import {
19
19
 
20
20
  import { agoricVatDataKeys as keys, makeOnceKit } from '@agoric/base-zone';
21
21
 
22
+ /**
23
+ * @import {Zone} from './index.js';
24
+ * @import {Stores} from './index.js';
25
+ * @import {Baggage} from '@agoric/swingset-liveslots';
26
+ */
27
+
22
28
  /**
23
29
  * A variant of `canBeDurable` that returns `false` instead of ever throwing.
24
30
  *
@@ -29,26 +35,26 @@ const isStorable = specimen => isPassable(specimen) && canBeDurable(specimen);
29
35
  harden(isStorable);
30
36
 
31
37
  /**
32
- * @param {() => import('@agoric/vat-data').Baggage} getBaggage
38
+ * @param {() => Baggage} getBaggage
33
39
  */
34
40
  const attachDurableStores = getBaggage => {
35
- /** @type {import('.').Zone['mapStore']} */
41
+ /** @type {Zone['mapStore']} */
36
42
  const mapStore = (label, options) => {
37
43
  const baggage = getBaggage();
38
44
  const ret = provideDurableMapStore(baggage, label, options);
39
45
  return ret;
40
46
  };
41
- /** @type {import('.').Zone['setStore']} */
47
+ /** @type {Zone['setStore']} */
42
48
  const setStore = (label, options) =>
43
49
  provideDurableSetStore(getBaggage(), label, options);
44
- /** @type {import('.').Zone['weakSetStore']} */
50
+ /** @type {Zone['weakSetStore']} */
45
51
  const weakSetStore = (label, options) =>
46
52
  provideDurableWeakSetStore(getBaggage(), label, options);
47
- /** @type {import('.').Zone['weakMapStore']} */
53
+ /** @type {Zone['weakMapStore']} */
48
54
  const weakMapStore = (label, options) =>
49
55
  provideDurableWeakMapStore(getBaggage(), label, options);
50
56
 
51
- /** @type {import('.').Stores} */
57
+ /** @type {Stores} */
52
58
  return Far('durableStores', {
53
59
  detached: () => detachedDurableStores,
54
60
  isStorable,
@@ -59,7 +65,7 @@ const attachDurableStores = getBaggage => {
59
65
  });
60
66
  };
61
67
 
62
- /** @type {import('.').Stores} */
68
+ /** @type {Stores} */
63
69
  const detachedDurableStores = attachDurableStores(() =>
64
70
  makeScalarMapStore('detached'),
65
71
  );
@@ -67,9 +73,9 @@ const detachedDurableStores = attachDurableStores(() =>
67
73
  /**
68
74
  * Create a zone whose objects persist between Agoric vat upgrades.
69
75
  *
70
- * @param {import('@agoric/vat-data').Baggage} baggage
76
+ * @param {Baggage} baggage
71
77
  * @param {string} [baseLabel]
72
- * @returns {import('.').Zone}
78
+ * @returns {Zone}
73
79
  */
74
80
  export const makeDurableZone = (baggage, baseLabel = 'durableZone') => {
75
81
  baggage || Fail`baggage required`;
@@ -82,20 +88,20 @@ export const makeDurableZone = (baggage, baseLabel = 'durableZone') => {
82
88
  baggage,
83
89
  );
84
90
 
85
- /** @type {import('.').Zone['exoClass']} */
91
+ /** @type {Zone['exoClass']} */
86
92
  const exoClass = (...args) => prepareExoClass(baggage, ...args);
87
- /** @type {import('.').Zone['exoClassKit']} */
93
+ /** @type {Zone['exoClassKit']} */
88
94
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- happens only integrating with Endo master
89
95
  // @ts-ignore FIXME in Endo
90
96
  const exoClassKit = (...args) => prepareExoClassKit(baggage, ...args);
91
- /** @type {import('.').Zone['exo']} */
97
+ /** @type {Zone['exo']} */
92
98
  const exo = (...args) => prepareExo(baggage, ...args);
93
99
 
94
100
  const subZoneStore = wrapProvider(attachedStores.mapStore, keys.zone);
95
101
 
96
- /** @type {import('.').Zone['subZone']} */
102
+ /** @type {Zone['subZone']} */
97
103
  const subZone = (label, options = {}) => {
98
- /** @type {import('@agoric/swingset-liveslots').Baggage} */
104
+ /** @type {Baggage} */
99
105
  const subBaggage = subZoneStore(label, options);
100
106
  return makeDurableZone(subBaggage, `${baseLabel}.${label}`);
101
107
  };
package/src/virtual.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export function makeVirtualZone(baseLabel?: string | undefined): import(".").Zone;
1
+ export function makeVirtualZone(baseLabel?: string): Zone;
2
+ import type { Zone } from './index.js';
2
3
  //# sourceMappingURL=virtual.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"virtual.d.ts","sourceRoot":"","sources":["virtual.js"],"names":[],"mappings":"AAiEO,iEAFM,OAAO,GAAG,EAAE,IAAI,CA+B5B"}
1
+ {"version":3,"file":"virtual.d.ts","sourceRoot":"","sources":["virtual.js"],"names":[],"mappings":"AAqEO,4CAHI,MAAM,GACJ,IAAI,CA+BhB;0BA9EsB,YAAY"}
package/src/virtual.js CHANGED
@@ -17,6 +17,12 @@ import {
17
17
  watchPromise,
18
18
  } from '@agoric/base-zone';
19
19
 
20
+ /**
21
+ * @import {Zone} from './index.js';
22
+ * @import {DefineKindOptions} from '@agoric/vat-data';
23
+ * @import {Stores} from './index.js';
24
+ */
25
+
20
26
  const emptyRecord = harden({});
21
27
  const initEmpty = harden(() => emptyRecord);
22
28
 
@@ -24,7 +30,7 @@ const initEmpty = harden(() => emptyRecord);
24
30
  * This implementation of `defineVirtualExo` only exists to ensure there are no
25
31
  * gaps in the virtualZone API.
26
32
  *
27
- * @type {import('.').Zone['exo']}
33
+ * @type {Zone['exo']}
28
34
  */
29
35
  const makeVirtualExo = (
30
36
  label,
@@ -33,9 +39,7 @@ const makeVirtualExo = (
33
39
  options = undefined,
34
40
  ) => {
35
41
  const defineKindOptions =
36
- /** @type {import('@agoric/vat-data').DefineKindOptions<{ self: typeof methods }>} */ (
37
- options
38
- );
42
+ /** @type {DefineKindOptions<{ self: typeof methods }>} */ (options);
39
43
  const makeInstance = defineVirtualExoClass(
40
44
  label,
41
45
  interfaceGuard,
@@ -46,7 +50,7 @@ const makeVirtualExo = (
46
50
  return makeInstance();
47
51
  };
48
52
 
49
- /** @type {import('.').Stores} */
53
+ /** @type {Stores} */
50
54
  const detachedVirtualStores = Far('virtualStores', {
51
55
  detached: () => detachedVirtualStores,
52
56
  isStorable: isPassable,
@@ -61,7 +65,7 @@ const detachedVirtualStores = Far('virtualStores', {
61
65
  * current vat.
62
66
  *
63
67
  * @param {string} [baseLabel]
64
- * @returns {import('.').Zone}
68
+ * @returns {Zone}
65
69
  */
66
70
  export const makeVirtualZone = (baseLabel = 'virtualZone') => {
67
71
  const { makeOnce, wrapProvider } = makeOnceKit(
package/test/exos.test.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { M } from '@endo/patterns';
1
2
  import {
2
3
  annihilate,
3
4
  getBaggage,
@@ -21,7 +22,11 @@ import { makeHeapZone } from '../heap.js';
21
22
  import { makeVirtualZone } from '../virtual.js';
22
23
 
23
24
  /**
24
- * @param {import('ava').Assertions} t
25
+ * @import {Assertions} from 'ava';
26
+ */
27
+
28
+ /**
29
+ * @param {Assertions} t
25
30
  * @param {MapStore} baggage
26
31
  */
27
32
  const testFirstVatDataIncarnation = (t, baggage) => {
@@ -123,3 +128,80 @@ test.serial('vatData migrate to durableZone', t => {
123
128
  const baggage2 = getBaggage();
124
129
  testSecondZoneIncarnation(t, makeDurableZone(baggage2));
125
130
  });
131
+
132
+ test.serial('exoClass stateShape expansion', t => {
133
+ annihilate();
134
+
135
+ // See ../../swingset-liveslots/test/virtual-objects/state-shape.test.js
136
+ const stateShapeMismatch = { message: /stateShape mismatch/ };
137
+ const HolderI = M.interface('Holder', {
138
+ get: M.call().rest(M.arrayOf(M.string())).returns(M.record()),
139
+ set: M.call(M.record()).returns(),
140
+ });
141
+ const initHolder = fields => ({ ...fields });
142
+ const holderMethods = {
143
+ get(...fields) {
144
+ const { state } = this;
145
+ // We require fields to be explicit because they are currently defined on
146
+ // the state *prototype*.
147
+ return Object.fromEntries(
148
+ fields.flatMap(key => (key in state ? [[key, state[key]]] : [])),
149
+ );
150
+ },
151
+ set(fields) {
152
+ Object.assign(this.state, fields);
153
+ },
154
+ };
155
+ const prepareHolder = (zone, stateShape) =>
156
+ zone.exoClass('Holder', HolderI, initHolder, holderMethods, { stateShape });
157
+
158
+ const fields = ['foo', 'bar', 'baz']; // but "baz" is not initially present
159
+ const baggage1 = getBaggage();
160
+ const zone1 = makeDurableZone(baggage1);
161
+ const makeHolder1 = prepareHolder(zone1, {
162
+ foo: M.number(),
163
+ bar: M.number(),
164
+ });
165
+ const holder1 = makeHolder1({ foo: 0, bar: 1 });
166
+ t.deepEqual(holder1.get(...fields), { foo: 0, bar: 1 });
167
+ holder1.set({ foo: 2, bar: 2 });
168
+ t.deepEqual(holder1.get(...fields), { foo: 2, bar: 2 });
169
+ t.throws(() => makeHolder1({ foo: 0, bar: 1, baz: 2 }));
170
+ t.throws(() => makeHolder1({ foo: 0, bar: 'string' }));
171
+
172
+ nextLife();
173
+ t.throws(
174
+ () =>
175
+ prepareHolder(makeDurableZone(getBaggage()), {
176
+ foo: M.string(),
177
+ bar: M.number(),
178
+ }),
179
+ stateShapeMismatch,
180
+ 'backwards-incompatible stateShape change',
181
+ );
182
+
183
+ nextLife();
184
+ t.throws(
185
+ () =>
186
+ prepareHolder(makeDurableZone(getBaggage()), {
187
+ foo: M.or(M.number(), M.string()),
188
+ bar: M.number(),
189
+ baz: M.or(undefined, M.number()),
190
+ }),
191
+ stateShapeMismatch,
192
+ 'stateShape field value expansion (needs #7407)',
193
+ );
194
+
195
+ nextLife();
196
+ const baggage2 = getBaggage();
197
+ const zone2 = makeDurableZone(baggage2);
198
+ const makeHolder2 = prepareHolder(zone2, {
199
+ foo: M.number(),
200
+ bar: M.number(),
201
+ baz: M.or(undefined, M.number()),
202
+ });
203
+ const holder2 = makeHolder2({ foo: 0, bar: 1, baz: 2 });
204
+ t.deepEqual(holder2.get(...fields), { foo: 0, bar: 1, baz: 2 });
205
+ holder2.set({ foo: 2, bar: 2, baz: undefined });
206
+ t.deepEqual(holder2.get(...fields), { foo: 2, bar: 2, baz: undefined });
207
+ });
@@ -9,10 +9,13 @@ import { makeDurableZone } from '../durable.js';
9
9
  import { makeHeapZone } from '../heap.js';
10
10
  import { makeVirtualZone } from '../virtual.js';
11
11
 
12
- /** @import {Zone} from '../src/index.js' */
12
+ /**
13
+ * @import {Zone} from '../src/index.js'
14
+ * @import {Assertions} from 'ava';
15
+ */
13
16
 
14
17
  /**
15
- * @param {import('ava').Assertions} t
18
+ * @param {Assertions} t
16
19
  * @param {Zone} rootZone
17
20
  */
18
21
  const testOnce = (t, rootZone) => {
@@ -1 +1 @@
1
- {"root":["./durable.js","./heap.js","./virtual.js","./src/durable.js","./src/index.js","./src/virtual.js"],"version":"5.6.3"}
1
+ {"root":["./durable.js","./heap.js","./virtual.js","./src/durable.js","./src/index.js","./src/virtual.js"],"version":"5.9.3"}