@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.
@@ -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
+ };
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": [
3
+ "./tsconfig.json",
4
+ "../../tsconfig-build-options.json"
5
+ ],
6
+ "exclude": [
7
+ "test",
8
+ "scripts",
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
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./src/prepare-revocable.js";
2
+ //# sourceMappingURL=zone-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zone-helpers.d.ts","sourceRoot":"","sources":["zone-helpers.js"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export * from './src/prepare-revocable.js';