@agoric/base-zone 0.1.1-dev-860d051.0 → 0.1.1-dev-5cdf6e3.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/base-zone",
|
|
3
|
-
"version": "0.1.1-dev-
|
|
3
|
+
"version": "0.1.1-dev-5cdf6e3.0+5cdf6e3",
|
|
4
4
|
"description": "Allocation zone abstraction library and heap implementation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": "https://github.com/Agoric/agoric-sdk",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"author": "Agoric",
|
|
28
28
|
"license": "Apache-2.0",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@agoric/store": "0.9.3-dev-
|
|
30
|
+
"@agoric/store": "0.9.3-dev-5cdf6e3.0+5cdf6e3",
|
|
31
31
|
"@endo/common": "^1.2.0",
|
|
32
32
|
"@endo/exo": "^1.3.0",
|
|
33
33
|
"@endo/far": "^1.1.0",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"typeCoverage": {
|
|
59
59
|
"atLeast": 89.25
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "5cdf6e3a8b4fbb5cb8e276e6efeec65d9c3d6623"
|
|
62
62
|
}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
export function
|
|
2
|
-
export type
|
|
1
|
+
export function prepareRevocableMakerKit<U = any>(zone: import('@agoric/base-zone').Zone, uKindName: string, uMethodNames: (string | symbol)[], options?: RevocableKitOptions<any> | undefined): RevocableMakerKit<U>;
|
|
2
|
+
export type RevocableMakerKit<U = any> = {
|
|
3
|
+
revoke: (revocable: U) => boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Forwards to the underlying exo object, until revoked
|
|
6
|
+
*/
|
|
7
|
+
makeRevocable: (underlying: U) => U;
|
|
8
|
+
};
|
|
9
|
+
export type RevokerFacet = {
|
|
3
10
|
revoke: () => boolean;
|
|
4
11
|
};
|
|
5
|
-
export type RevocableKit<U
|
|
6
|
-
revoker:
|
|
12
|
+
export type RevocableKit<U = any> = {
|
|
13
|
+
revoker: RevokerFacet;
|
|
7
14
|
/**
|
|
8
15
|
* Forwards to the underlying exo object, until revoked
|
|
9
16
|
*/
|
|
@@ -15,7 +22,7 @@ export type RevocableKitThis<U = any> = {
|
|
|
15
22
|
underlying: U;
|
|
16
23
|
};
|
|
17
24
|
};
|
|
18
|
-
export type RevocableKitOptions<U
|
|
25
|
+
export type RevocableKitOptions<U = any> = {
|
|
19
26
|
/**
|
|
20
27
|
* The `interfaceName` of the underlying interface guard.
|
|
21
28
|
* Defaults to the `uKindName`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepare-revocable.d.ts","sourceRoot":"","sources":["prepare-revocable.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prepare-revocable.d.ts","sourceRoot":"","sources":["prepare-revocable.js"],"names":[],"mappings":"AAoEO,wDATI,OAAO,mBAAmB,EAAE,IAAI,aAChC,MAAM,gBAEN,CAAC,MAAM,GAAC,MAAM,CAAC,EAAE,wEA4G3B;;YAlKa,CAAC,SAAS,EAAE,CAAC,KAAK,OAAO;;;;mBACzB,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC;;;YAMpB,MAAM,OAAO;;;aAMb,YAAY;;;;eACZ,CAAC;;;YAOD,aAAa,CAAC,CAAC;WACf;QAAE,UAAU,EAAE,CAAC,CAAA;KAAE;;;;;;;;;;;;;;;;;;kDAkBnB,iBAAiB,CAAC,CAAC,WAAW,GAAG,EAAE,KAAK,GAAG"}
|
package/src/prepare-revocable.js
CHANGED
|
@@ -4,14 +4,22 @@ import { fromUniqueEntries } from '@endo/common/from-unique-entries.js';
|
|
|
4
4
|
const { Fail, quote: q } = assert;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @
|
|
7
|
+
* @template [U=any]
|
|
8
|
+
* @typedef {object} RevocableMakerKit
|
|
9
|
+
* @property {(revocable: U) => boolean} revoke
|
|
10
|
+
* @property {(underlying: U) => U} makeRevocable
|
|
11
|
+
* Forwards to the underlying exo object, until revoked
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {object} RevokerFacet
|
|
8
16
|
* @property {() => boolean} revoke
|
|
9
17
|
*/
|
|
10
18
|
|
|
11
19
|
/**
|
|
12
|
-
* @template
|
|
20
|
+
* @template [U=any]
|
|
13
21
|
* @typedef {object} RevocableKit
|
|
14
|
-
* @property {
|
|
22
|
+
* @property {RevokerFacet} revoker
|
|
15
23
|
* @property {U} revocable
|
|
16
24
|
* Forwards to the underlying exo object, until revoked
|
|
17
25
|
*/
|
|
@@ -24,7 +32,7 @@ const { Fail, quote: q } = assert;
|
|
|
24
32
|
*/
|
|
25
33
|
|
|
26
34
|
/**
|
|
27
|
-
* @template
|
|
35
|
+
* @template [U=any]
|
|
28
36
|
* @typedef {object} RevocableKitOptions
|
|
29
37
|
* @property {string} [uInterfaceName]
|
|
30
38
|
* The `interfaceName` of the underlying interface guard.
|
|
@@ -48,8 +56,7 @@ const { Fail, quote: q } = assert;
|
|
|
48
56
|
* Make an exo class kit for wrapping an underlying exo class,
|
|
49
57
|
* where the wrapper is a revocable forwarder.
|
|
50
58
|
*
|
|
51
|
-
* @
|
|
52
|
-
* @template {any} [U=any]
|
|
59
|
+
* @template [U=any]
|
|
53
60
|
* @param {import('@agoric/base-zone').Zone} zone
|
|
54
61
|
* @param {string} uKindName
|
|
55
62
|
* The `kindName` of the underlying exo class
|
|
@@ -57,9 +64,9 @@ const { Fail, quote: q } = assert;
|
|
|
57
64
|
* The method names of the underlying exo class that should be represented
|
|
58
65
|
* by transparently-forwarding methods of the revocable caretaker.
|
|
59
66
|
* @param {RevocableKitOptions} [options]
|
|
60
|
-
* @returns {
|
|
67
|
+
* @returns {RevocableMakerKit<U>}
|
|
61
68
|
*/
|
|
62
|
-
export const
|
|
69
|
+
export const prepareRevocableMakerKit = (
|
|
63
70
|
zone,
|
|
64
71
|
uKindName,
|
|
65
72
|
uMethodNames,
|
|
@@ -87,6 +94,8 @@ export const prepareRevocableKit = (
|
|
|
87
94
|
|
|
88
95
|
const revocableKindName = `${uKindName}_caretaker`;
|
|
89
96
|
|
|
97
|
+
let amplifier;
|
|
98
|
+
|
|
90
99
|
const makeRevocableKit = zone.exoClassKit(
|
|
91
100
|
revocableKindName,
|
|
92
101
|
RevocableIKit,
|
|
@@ -128,10 +137,36 @@ export const prepareRevocableKit = (
|
|
|
128
137
|
stateShape: {
|
|
129
138
|
underlying: M.opt(M.remotable('underlying')),
|
|
130
139
|
},
|
|
140
|
+
receiveAmplifier: amp => {
|
|
141
|
+
amplifier = amp;
|
|
142
|
+
},
|
|
131
143
|
},
|
|
132
144
|
);
|
|
133
145
|
|
|
134
|
-
|
|
135
|
-
|
|
146
|
+
/**
|
|
147
|
+
* @param {U} underlying
|
|
148
|
+
* @returns {U}
|
|
149
|
+
*/
|
|
150
|
+
const makeRevocable = underlying =>
|
|
151
|
+
// @ts-expect-error some confusion about UU vs Guarded<U> I think
|
|
152
|
+
makeRevocableKit(underlying).revocable;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @param {U} revocable
|
|
156
|
+
* @returns {boolean}
|
|
157
|
+
*/
|
|
158
|
+
const revoke = revocable => {
|
|
159
|
+
/** @type {RevocableKit<U>} */
|
|
160
|
+
const facets = amplifier(revocable);
|
|
161
|
+
if (facets === undefined) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
return facets.revoker.revoke();
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
return harden({
|
|
168
|
+
revoke,
|
|
169
|
+
makeRevocable,
|
|
170
|
+
});
|
|
136
171
|
};
|
|
137
|
-
harden(
|
|
172
|
+
harden(prepareRevocableMakerKit);
|
|
@@ -5,7 +5,7 @@ import { test } from './prepare-test-env-ava.js';
|
|
|
5
5
|
// eslint-disable-next-line import/order
|
|
6
6
|
import { M } from '@endo/patterns';
|
|
7
7
|
import { makeHeapZone } from '../src/heap.js';
|
|
8
|
-
import {
|
|
8
|
+
import { prepareRevocableMakerKit } from '../src/prepare-revocable.js';
|
|
9
9
|
|
|
10
10
|
const UpCounterI = M.interface('UpCounter', {
|
|
11
11
|
incr: M.call()
|
|
@@ -38,16 +38,17 @@ test('test revoke defineVirtualExoClass', t => {
|
|
|
38
38
|
},
|
|
39
39
|
);
|
|
40
40
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const { revoke, makeRevocable } = prepareRevocableMakerKit(
|
|
42
|
+
zone,
|
|
43
|
+
'UpCounter',
|
|
44
|
+
['incr'],
|
|
45
|
+
);
|
|
44
46
|
|
|
45
|
-
const
|
|
46
|
-
makeRevocableUpCounterKit(makeUnderlyingUpCounter(x));
|
|
47
|
+
const makeUpCounter = x => makeRevocable(makeUnderlyingUpCounter(x));
|
|
47
48
|
|
|
48
|
-
const
|
|
49
|
+
const upCounter = makeUpCounter(3);
|
|
49
50
|
t.is(upCounter.incr(5), 8);
|
|
50
|
-
t.is(
|
|
51
|
+
t.is(revoke(upCounter), true);
|
|
51
52
|
t.throws(() => upCounter.incr(1), {
|
|
52
53
|
message: '"UpCounter_caretaker" revoked',
|
|
53
54
|
});
|
|
@@ -79,7 +80,7 @@ test('test revoke defineVirtualExoClassKit', t => {
|
|
|
79
80
|
},
|
|
80
81
|
);
|
|
81
82
|
|
|
82
|
-
const
|
|
83
|
+
const { revoke, makeRevocable } = prepareRevocableMakerKit(
|
|
83
84
|
zone,
|
|
84
85
|
'UpCounter',
|
|
85
86
|
['incr'],
|
|
@@ -89,8 +90,12 @@ test('test revoke defineVirtualExoClassKit', t => {
|
|
|
89
90
|
},
|
|
90
91
|
extraMethods: {
|
|
91
92
|
selfRevoke() {
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
// Could directly use the revoker facet instead, but this
|
|
94
|
+
// should now be considered more of an internal detail that
|
|
95
|
+
// we should deemphasize. This tests the code pattern we wish
|
|
96
|
+
// to encourage.
|
|
97
|
+
const { revocable } = this.facets;
|
|
98
|
+
return revoke(revocable);
|
|
94
99
|
},
|
|
95
100
|
},
|
|
96
101
|
},
|
|
@@ -98,8 +103,7 @@ test('test revoke defineVirtualExoClassKit', t => {
|
|
|
98
103
|
|
|
99
104
|
const makeCounterKit = x => {
|
|
100
105
|
const { up: upCounter, down: downCounter } = makeUnderlyingCounterKit(x);
|
|
101
|
-
const
|
|
102
|
-
makeRevocableUpCounterKit(upCounter);
|
|
106
|
+
const revocableUpCounter = makeRevocable(upCounter);
|
|
103
107
|
return harden({
|
|
104
108
|
up: revocableUpCounter,
|
|
105
109
|
down: downCounter,
|