@agoric/base-zone 0.1.1-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/CHANGELOG.md +4 -0
- package/LICENSE +201 -0
- package/README.md +13 -0
- package/heap.d.ts +2 -0
- package/heap.d.ts.map +1 -0
- package/heap.js +3 -0
- package/package.json +62 -0
- package/src/exports.d.ts +8 -0
- package/src/exports.js +2 -0
- package/src/heap.d.ts +2 -0
- package/src/heap.d.ts.map +1 -0
- package/src/heap.js +63 -0
- package/src/index.d.ts +6 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +12 -0
- package/src/is-passable.d.ts +2 -0
- package/src/is-passable.d.ts.map +1 -0
- package/src/is-passable.js +8 -0
- package/src/keys.d.ts +7 -0
- package/src/keys.d.ts.map +1 -0
- package/src/keys.js +21 -0
- package/src/make-once.d.ts +5 -0
- package/src/make-once.d.ts.map +1 -0
- package/src/make-once.js +86 -0
- package/src/prepare-revocable.d.ts +43 -0
- package/src/prepare-revocable.d.ts.map +1 -0
- package/src/prepare-revocable.js +175 -0
- package/src/types.d.ts +64 -0
- package/src/types.d.ts.map +1 -0
- package/src/types.js +44 -0
- package/src/watch-promise.d.ts +29 -0
- package/src/watch-promise.d.ts.map +1 -0
- package/src/watch-promise.js +82 -0
- package/test/exos.test.js +9 -0
- package/test/make-once.test.js +8 -0
- package/test/prepare-revocable.test.js +121 -0
- package/test/prepare-test-env-ava.js +4 -0
- package/tools/greeter.js +74 -0
- package/tools/testers.js +120 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.json +11 -0
- package/zone-helpers.d.ts +2 -0
- package/zone-helpers.d.ts.map +1 -0
- package/zone-helpers.js +1 -0
package/tools/testers.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import * as g from './greeter.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {import('ava').Assertions} t
|
|
5
|
+
* @param {import('../src/index.js').Zone} rootZone
|
|
6
|
+
*/
|
|
7
|
+
export const testMakeOnce = (t, rootZone) => {
|
|
8
|
+
const subZone = rootZone.subZone('sub');
|
|
9
|
+
const a = subZone.makeOnce('a', () => 'A');
|
|
10
|
+
t.is(a, 'A');
|
|
11
|
+
t.throws(() => subZone.makeOnce('a', () => 'A'), {
|
|
12
|
+
message: /has already been used/,
|
|
13
|
+
});
|
|
14
|
+
const nonPassable = harden({
|
|
15
|
+
hello() {
|
|
16
|
+
return 'world';
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
t.is(rootZone.isStorable(nonPassable), false);
|
|
20
|
+
t.is(subZone.isStorable(123), true);
|
|
21
|
+
t.throws(() => rootZone.makeOnce('nonPassable', () => nonPassable), {
|
|
22
|
+
message: /is not storable/,
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// CAUTION: Do not modify this list; it exists to ensure that future versions
|
|
27
|
+
// of @agoric/zone are compatible with the baggage created by older versions,
|
|
28
|
+
// including the legacy implementation of @agoric/vat-data.
|
|
29
|
+
export const agoricVatDataCompatibleKeys = harden(
|
|
30
|
+
[
|
|
31
|
+
'Greeter_kindHandle',
|
|
32
|
+
'GreeterKit_kindHandle',
|
|
33
|
+
'a_kindHandle',
|
|
34
|
+
'a_singleton',
|
|
35
|
+
'mappish',
|
|
36
|
+
'subsub',
|
|
37
|
+
].sort(),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export const testGreeter = (t, nick, obj, adminObj = obj) => {
|
|
41
|
+
t.is(obj.greet('Greetings'), `Greetings, ${nick}`);
|
|
42
|
+
t.is(obj.greet(), `Hello, ${nick}`);
|
|
43
|
+
adminObj.setNick(`${nick}2`);
|
|
44
|
+
t.is(obj.greet('Greetings'), `Greetings, ${nick}2`);
|
|
45
|
+
t.is(obj.greet(), `Hello, ${nick}2`);
|
|
46
|
+
adminObj.setNick(nick);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const alreadyExceptionSpec = {
|
|
50
|
+
message: /has already been used/,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @template T
|
|
55
|
+
* @param {import('ava').Assertions} t
|
|
56
|
+
* @param {() => T} fn
|
|
57
|
+
* @param {*} spec
|
|
58
|
+
* @returns {T}
|
|
59
|
+
*/
|
|
60
|
+
const secondThrows = (t, fn, spec = alreadyExceptionSpec) => {
|
|
61
|
+
const ret = fn();
|
|
62
|
+
t.throws(fn, spec);
|
|
63
|
+
return ret;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @param {import('ava').Assertions} t
|
|
68
|
+
* @param {import('../src/index.js').Zone} rootZone
|
|
69
|
+
*/
|
|
70
|
+
export const testFirstZoneIncarnation = (t, rootZone) => {
|
|
71
|
+
const subZone = secondThrows(t, () => rootZone.subZone('sub'));
|
|
72
|
+
const singly = secondThrows(t, () =>
|
|
73
|
+
g.prepareGreeterSingleton(subZone, 'a', 'Singly'),
|
|
74
|
+
);
|
|
75
|
+
testGreeter(t, 'Singly', singly);
|
|
76
|
+
|
|
77
|
+
const makeGreeter = secondThrows(t, () => g.prepareGreeter(subZone));
|
|
78
|
+
const classy = makeGreeter('Classy');
|
|
79
|
+
testGreeter(t, 'Classy', classy);
|
|
80
|
+
|
|
81
|
+
const makeGreeterKit = secondThrows(t, () => g.prepareGreeterKit(subZone));
|
|
82
|
+
|
|
83
|
+
const { greeter: kitty, admin: kittyAdmin } = makeGreeterKit('Kitty');
|
|
84
|
+
testGreeter(t, 'Kitty', kitty, kittyAdmin);
|
|
85
|
+
|
|
86
|
+
const mappish = secondThrows(t, () => subZone.mapStore('mappish'));
|
|
87
|
+
mappish.init('singly', singly);
|
|
88
|
+
mappish.init('classy', classy);
|
|
89
|
+
mappish.init('kitty', kitty);
|
|
90
|
+
mappish.init('kittyAdmin', kittyAdmin);
|
|
91
|
+
|
|
92
|
+
secondThrows(t, () => subZone.subZone('subsub'));
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @param {import('ava').Assertions} t
|
|
97
|
+
* @param {import('../src/index.js').Zone} rootZone
|
|
98
|
+
*/
|
|
99
|
+
export const testSecondZoneIncarnation = (t, rootZone) => {
|
|
100
|
+
const subZone = secondThrows(t, () => rootZone.subZone('sub'));
|
|
101
|
+
const mappish = secondThrows(t, () => subZone.mapStore('mappish'));
|
|
102
|
+
|
|
103
|
+
const singlyReload = secondThrows(t, () =>
|
|
104
|
+
g.prepareGreeterSingleton(subZone, 'a', 'Singly'),
|
|
105
|
+
);
|
|
106
|
+
const makeGreeter = secondThrows(t, () => g.prepareGreeter(subZone));
|
|
107
|
+
const makeGreeterKit = secondThrows(t, () => g.prepareGreeterKit(subZone));
|
|
108
|
+
|
|
109
|
+
const singly = mappish.get('singly');
|
|
110
|
+
t.is(singlyReload, singly);
|
|
111
|
+
testGreeter(t, 'Singly', singly);
|
|
112
|
+
testGreeter(t, 'Classy', mappish.get('classy'));
|
|
113
|
+
testGreeter(t, 'Kitty', mappish.get('kitty'), mappish.get('kittyAdmin'));
|
|
114
|
+
|
|
115
|
+
const classy2 = makeGreeter('Classy2');
|
|
116
|
+
testGreeter(t, 'Classy2', classy2);
|
|
117
|
+
|
|
118
|
+
const { greeter: kitty2, admin: kittyAdmin2 } = makeGreeterKit('Kitty2');
|
|
119
|
+
testGreeter(t, 'Kitty2', kitty2, kittyAdmin2);
|
|
120
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zone-helpers.d.ts","sourceRoot":"","sources":["zone-helpers.js"],"names":[],"mappings":""}
|
package/zone-helpers.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/prepare-revocable.js';
|