@agoric/base-zone 0.1.1-dev-1f93cea.0 → 0.1.1-dev-cd45c09.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 +3 -3
- package/src/prepare-attenuator.d.ts +9 -5
- package/src/prepare-attenuator.d.ts.map +1 -1
- package/src/prepare-attenuator.js +82 -43
- package/src/prepare-revocable.d.ts +6 -5
- package/src/prepare-revocable.d.ts.map +1 -1
- package/src/prepare-revocable.js +23 -48
- package/test/prepare-attenuator.test.js +2 -0
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-cd45c09.0+cd45c09",
|
|
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-cd45c09.0+cd45c09",
|
|
31
31
|
"@endo/common": "^1.2.10",
|
|
32
32
|
"@endo/errors": "^1.2.10",
|
|
33
33
|
"@endo/exo": "^1.5.9",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"typeCoverage": {
|
|
60
60
|
"atLeast": 91.4
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "cd45c09e3b855745d1e641534f7d547bfa95ad74"
|
|
63
63
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
export function
|
|
2
|
-
|
|
1
|
+
export function wrapperMethods(wrapperKindName: string, uMethodNames: PropertyKey[], extraMethods?: Record<PropertyKey, (...args: any[]) => any>): {
|
|
2
|
+
[x: string]: ((...args: any[]) => any) | ((...args: any[]) => any);
|
|
3
|
+
};
|
|
4
|
+
export function prepareAttenuatorMaker<U = any>(zone: import("@agoric/base-zone").Zone, uKindName: string, uMethodNames: (keyof U)[], options?: AttenuatorOptions<U>): MakeAttenuator;
|
|
5
|
+
export function attenuateOne<U extends unknown>(underlying: U, uMethodNames: (keyof U)[], options?: AttenuatorOptions<U>): Partial<U>;
|
|
6
|
+
export type MakeAttenuator<U = any> = (underlying: U) => Partial<U>;
|
|
3
7
|
export type AttenuatorThis<U = any> = {
|
|
4
|
-
self: U
|
|
8
|
+
self: Partial<U>;
|
|
5
9
|
state: {
|
|
6
10
|
underlying: U;
|
|
7
11
|
};
|
|
@@ -17,11 +21,11 @@ export type AttenuatorOptions<U = any> = {
|
|
|
17
21
|
* only on the synthesized interface guard for the attenuator, and
|
|
18
22
|
* do not necessarily correspond to any method of the underlying.
|
|
19
23
|
*/
|
|
20
|
-
extraMethodGuards?: Record<
|
|
24
|
+
extraMethodGuards?: Record<PropertyKey, import("@endo/patterns").MethodGuard> | undefined;
|
|
21
25
|
/**
|
|
22
26
|
* Extra methods adding behavior only to the attenuator, and
|
|
23
27
|
* do not necessarily correspond to any methods of the underlying.
|
|
24
28
|
*/
|
|
25
|
-
extraMethods?: Record<
|
|
29
|
+
extraMethods?: Record<PropertyKey, (this: AttenuatorThis<U>, ...args: any[]) => any> | undefined;
|
|
26
30
|
};
|
|
27
31
|
//# sourceMappingURL=prepare-attenuator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepare-attenuator.d.ts","sourceRoot":"","sources":["prepare-attenuator.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prepare-attenuator.d.ts","sourceRoot":"","sources":["prepare-attenuator.js"],"names":[],"mappings":"AA2BO,gDAJI,MAAM,gBACN,WAAW,EAAE,iBACb,MAAM,CAAC,WAAW,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;4BAAd,GAAG,EAAE,KAAK,GAAG;EA6BlD;AAoDG,uCAVO,CAAC,cACJ,OAAO,mBAAmB,EAAE,IAAI,aAChC,MAAM,gBAEN,CAAC,MAAM,CAAC,CAAC,EAAE,YAGX,iBAAiB,CAAC,CAAC,CAAC,GAClB,cAAc,CA8B1B;AAoBM,6BANY,CAAC,8BACT,CAAC,gBACD,CAAC,MAAM,CAAC,CAAC,EAAE,YACX,iBAAiB,CAAC,CAAC,CAAC,GAClB,OAAO,CAAC,CAAC,CAAC,CAgBtB;2BA9Ga,CAAC,uBAEJ,CAAC,KACC,OAAO,CAAC,CAAC,CAAC;2BAIT,CAAC;UAED,OAAO,CAAC,CAAC,CAAC;WACV;QAAE,UAAU,EAAE,CAAC,CAAA;KAAE;;8BAIjB,CAAC;;;;;;;;;;;;;;;;8CAcH,cAAc,CAAC,CAAC,CAAC,WAAW,GAAG,EAAE,KAAK,GAAG"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Fail, q } from '@endo/errors';
|
|
2
2
|
import { fromUniqueEntries } from '@endo/common/from-unique-entries.js';
|
|
3
3
|
import { M } from '@endo/patterns';
|
|
4
|
+
import { makeHeapZone } from './heap.js';
|
|
4
5
|
|
|
5
6
|
// This attenuator implementation is just a simplification of the
|
|
6
7
|
// revocable kit implementation in prepare-revocable.js. The revocable kit
|
|
@@ -19,17 +20,52 @@ import { M } from '@endo/patterns';
|
|
|
19
20
|
// But it can still support `selfRevoke` as a separate `extraMethod`, as shown
|
|
20
21
|
// in a testcase at `prepare-attenuator.test.js`
|
|
21
22
|
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} wrapperKindName
|
|
25
|
+
* @param {PropertyKey[]} uMethodNames
|
|
26
|
+
* @param {Record<PropertyKey, (...args: any[]) => any>} [extraMethods]
|
|
27
|
+
*/
|
|
28
|
+
export const wrapperMethods = (
|
|
29
|
+
wrapperKindName,
|
|
30
|
+
uMethodNames,
|
|
31
|
+
extraMethods = {},
|
|
32
|
+
) =>
|
|
33
|
+
harden({
|
|
34
|
+
...fromUniqueEntries(
|
|
35
|
+
uMethodNames.map(name => [
|
|
36
|
+
name,
|
|
37
|
+
{
|
|
38
|
+
// Use concise method syntax for exo methods
|
|
39
|
+
[name](...args) {
|
|
40
|
+
// @ts-expect-error normal exo-this typing confusion
|
|
41
|
+
const { underlying } = this.state;
|
|
42
|
+
|
|
43
|
+
// Because attenuators still support someone adding `selfRevoke`
|
|
44
|
+
// as an `extraMethod`, this test is still useful. See the
|
|
45
|
+
// testcase in `prepare-attenuator.test.js`.
|
|
46
|
+
underlying !== undefined || Fail`${q(wrapperKindName)} revoked`;
|
|
47
|
+
|
|
48
|
+
return underlying[name](...args);
|
|
49
|
+
},
|
|
50
|
+
// @ts-expect-error using possible symbol as index type
|
|
51
|
+
}[name],
|
|
52
|
+
]),
|
|
53
|
+
),
|
|
54
|
+
...extraMethods,
|
|
55
|
+
});
|
|
56
|
+
harden(wrapperMethods);
|
|
57
|
+
|
|
22
58
|
/**
|
|
23
59
|
* @template [U=any]
|
|
24
60
|
* @callback MakeAttenuator
|
|
25
61
|
* @param {U} underlying
|
|
26
|
-
* @returns {U}
|
|
62
|
+
* @returns {Partial<U>}
|
|
27
63
|
*/
|
|
28
64
|
|
|
29
65
|
/**
|
|
30
66
|
* @template [U=any]
|
|
31
67
|
* @typedef {object} AttenuatorThis
|
|
32
|
-
* @property {U} self
|
|
68
|
+
* @property {Partial<U>} self
|
|
33
69
|
* @property {{ underlying: U }} state
|
|
34
70
|
*/
|
|
35
71
|
|
|
@@ -40,14 +76,14 @@ import { M } from '@endo/patterns';
|
|
|
40
76
|
* The `interfaceName` of the underlying interface guard.
|
|
41
77
|
* Defaults to the `uKindName`.
|
|
42
78
|
* @property {Record<
|
|
43
|
-
*
|
|
79
|
+
* PropertyKey,
|
|
44
80
|
* import('@endo/patterns').MethodGuard
|
|
45
81
|
* >} [extraMethodGuards]
|
|
46
82
|
* For guarding the `extraMethods`, if you include them below. These appear
|
|
47
83
|
* only on the synthesized interface guard for the attenuator, and
|
|
48
84
|
* do not necessarily correspond to any method of the underlying.
|
|
49
85
|
* @property {Record<
|
|
50
|
-
*
|
|
86
|
+
* PropertyKey,
|
|
51
87
|
* (this: AttenuatorThis<U>, ...args: any[]) => any
|
|
52
88
|
* >} [extraMethods]
|
|
53
89
|
* Extra methods adding behavior only to the attenuator, and
|
|
@@ -62,7 +98,7 @@ import { M } from '@endo/patterns';
|
|
|
62
98
|
* @param {import('@agoric/base-zone').Zone} zone
|
|
63
99
|
* @param {string} uKindName
|
|
64
100
|
* The `kindName` of the underlying exo class
|
|
65
|
-
* @param {(
|
|
101
|
+
* @param {(keyof U)[]} uMethodNames
|
|
66
102
|
* The method names of the underlying exo class that should be represented
|
|
67
103
|
* by transparently-forwarding methods of the attenuator.
|
|
68
104
|
* @param {AttenuatorOptions<U>} [options]
|
|
@@ -76,17 +112,13 @@ export const prepareAttenuatorMaker = (
|
|
|
76
112
|
) => {
|
|
77
113
|
const {
|
|
78
114
|
uInterfaceName = uKindName,
|
|
79
|
-
extraMethodGuards =
|
|
80
|
-
extraMethods =
|
|
115
|
+
extraMethodGuards = {},
|
|
116
|
+
extraMethods = {},
|
|
81
117
|
} = options;
|
|
82
118
|
const AttenuatorI = M.interface(
|
|
83
119
|
`${uInterfaceName}_attenuator`,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
defaultGuards: 'raw',
|
|
89
|
-
},
|
|
120
|
+
extraMethodGuards,
|
|
121
|
+
{ defaultGuards: 'raw' },
|
|
90
122
|
);
|
|
91
123
|
|
|
92
124
|
const attenuatorKindName = `${uKindName}_attenuator`;
|
|
@@ -94,38 +126,45 @@ export const prepareAttenuatorMaker = (
|
|
|
94
126
|
return zone.exoClass(
|
|
95
127
|
attenuatorKindName,
|
|
96
128
|
AttenuatorI,
|
|
97
|
-
underlying => ({
|
|
98
|
-
|
|
99
|
-
}),
|
|
129
|
+
underlying => ({ underlying }),
|
|
130
|
+
wrapperMethods(attenuatorKindName, uMethodNames, extraMethods),
|
|
100
131
|
{
|
|
101
|
-
|
|
102
|
-
uMethodNames.map(name => [
|
|
103
|
-
name,
|
|
104
|
-
{
|
|
105
|
-
// Use concise method syntax for exo methods
|
|
106
|
-
[name](...args) {
|
|
107
|
-
// @ts-expect-error normal exo-this typing confusion
|
|
108
|
-
const { underlying } = this.state;
|
|
109
|
-
|
|
110
|
-
// Because attenuators still support someone adding `selfRevoke`
|
|
111
|
-
// as an `extraMethod`, this test is still useful. See the
|
|
112
|
-
// testcase in `prepare-attenuator.test.js`.
|
|
113
|
-
underlying !== undefined ||
|
|
114
|
-
Fail`${q(attenuatorKindName)} revoked`;
|
|
115
|
-
|
|
116
|
-
return underlying[name](...args);
|
|
117
|
-
},
|
|
118
|
-
// @ts-expect-error using possible symbol as index type
|
|
119
|
-
}[name],
|
|
120
|
-
]),
|
|
121
|
-
),
|
|
122
|
-
...extraMethods,
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
stateShape: {
|
|
126
|
-
underlying: M.opt(M.remotable('underlying')),
|
|
127
|
-
},
|
|
132
|
+
stateShape: { underlying: M.opt(M.remotable('underlying')) },
|
|
128
133
|
},
|
|
129
134
|
);
|
|
130
135
|
};
|
|
131
136
|
harden(prepareAttenuatorMaker);
|
|
137
|
+
|
|
138
|
+
const PrefixedKindNameRE = /(alleged: |DebugName: )(.*)/;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A convenience above `prepareAttenuatorMaker` for doing a singleton
|
|
142
|
+
* ephemeral attenuator, i.e., a new attenuator instance (and hidden class)
|
|
143
|
+
* that is allocated in the heap zone, and therefore ephemeral. The underlying
|
|
144
|
+
* can be durable or not, with no conflict with the attenuator being
|
|
145
|
+
* ephemeral. The price of this convenience is the allocation of the hidden
|
|
146
|
+
* class and wrapper methods per `attenuateOne` call, i.e., per attenuator
|
|
147
|
+
* instance.
|
|
148
|
+
*
|
|
149
|
+
* @template {any} U
|
|
150
|
+
* @param {U} underlying
|
|
151
|
+
* @param {(keyof U)[]} uMethodNames
|
|
152
|
+
* @param {AttenuatorOptions<U>} [options]
|
|
153
|
+
* @returns {Partial<U>}
|
|
154
|
+
*/
|
|
155
|
+
export const attenuateOne = (underlying, uMethodNames, options = undefined) => {
|
|
156
|
+
const heapZone = makeHeapZone();
|
|
157
|
+
let uKindName = underlying[Symbol.toStringTag] || 'Underlying';
|
|
158
|
+
const match = PrefixedKindNameRE.exec(uKindName);
|
|
159
|
+
if (match) {
|
|
160
|
+
uKindName = match[2];
|
|
161
|
+
}
|
|
162
|
+
const makeAttenuator = prepareAttenuatorMaker(
|
|
163
|
+
heapZone,
|
|
164
|
+
uKindName,
|
|
165
|
+
uMethodNames,
|
|
166
|
+
options,
|
|
167
|
+
);
|
|
168
|
+
return makeAttenuator(underlying);
|
|
169
|
+
};
|
|
170
|
+
harden(attenuateOne);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export function prepareRevocableMakerKit<U = any>(zone: import("@agoric/base-zone").Zone, uKindName: string, uMethodNames:
|
|
1
|
+
export function prepareRevocableMakerKit<U = any>(zone: import("@agoric/base-zone").Zone, uKindName: string, uMethodNames: PropertyKey[], options?: RevocableKitOptions<U>): RevocableMakerKit<U>;
|
|
2
|
+
export type MakeRevocable<U = any> = (underlying: U) => Partial<U>;
|
|
2
3
|
export type RevocableMakerKit<U = any> = {
|
|
3
4
|
revoke: (revocable: U) => boolean;
|
|
4
5
|
/**
|
|
5
6
|
* Forwards to the underlying exo object, until revoked
|
|
6
7
|
*/
|
|
7
|
-
makeRevocable:
|
|
8
|
+
makeRevocable: MakeRevocable;
|
|
8
9
|
};
|
|
9
10
|
export type RevokerFacet = {
|
|
10
11
|
revoke: () => boolean;
|
|
@@ -14,7 +15,7 @@ export type RevocableKit<U = any> = {
|
|
|
14
15
|
/**
|
|
15
16
|
* Forwards to the underlying exo object, until revoked
|
|
16
17
|
*/
|
|
17
|
-
revocable: U
|
|
18
|
+
revocable: Partial<U>;
|
|
18
19
|
};
|
|
19
20
|
export type RevocableKitThis<U = any> = {
|
|
20
21
|
facets: RevocableKit<U>;
|
|
@@ -33,11 +34,11 @@ export type RevocableKitOptions<U = any> = {
|
|
|
33
34
|
* only on the synthesized interface guard for the revocable caretaker, and
|
|
34
35
|
* do not necessarily correspond to any method of the underlying.
|
|
35
36
|
*/
|
|
36
|
-
extraMethodGuards?: Record<
|
|
37
|
+
extraMethodGuards?: Record<PropertyKey, import("@endo/patterns").MethodGuard> | undefined;
|
|
37
38
|
/**
|
|
38
39
|
* Extra methods adding behavior only to the revocable caretaker, and
|
|
39
40
|
* do not necessarily correspond to any methods of the underlying.
|
|
40
41
|
*/
|
|
41
|
-
extraMethods?: Record<
|
|
42
|
+
extraMethods?: Record<PropertyKey, (this: RevocableKitThis<U>, ...args: any[]) => any> | undefined;
|
|
42
43
|
};
|
|
43
44
|
//# sourceMappingURL=prepare-revocable.d.ts.map
|
|
@@ -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":"AAiFO,yCAVO,CAAC,cACJ,OAAO,mBAAmB,EAAE,IAAI,aAChC,MAAM,gBAEN,WAAW,EAAE,YAGb,mBAAmB,CAAC,CAAC,CAAC,GACpB,iBAAiB,CAAC,CAAC,CAAC,CA0EhC;0BA7Ia,CAAC,uBAEJ,CAAC,KACC,OAAO,CAAC,CAAC,CAAC;8BAIT,CAAC;YAED,CAAC,SAAS,EAAE,CAAC,KAAK,OAAO;;;;mBACzB,aAAa;;;YAMb,MAAM,OAAO;;yBAIb,CAAC;aAED,YAAY;;;;eACZ,OAAO,CAAC,CAAC,CAAC;;6BAKV,CAAC;YAED,YAAY,CAAC,CAAC,CAAC;WACf;QAAE,UAAU,EAAE,CAAC,CAAA;KAAE;;gCAIjB,CAAC;;;;;;;;;;;;;;;;8CAcH,gBAAgB,CAAC,CAAC,CAAC,WAAW,GAAG,EAAE,KAAK,GAAG"}
|
package/src/prepare-revocable.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Fail, q } from '@endo/errors';
|
|
2
|
-
import { fromUniqueEntries } from '@endo/common/from-unique-entries.js';
|
|
3
1
|
import { M } from '@endo/patterns';
|
|
2
|
+
import { wrapperMethods } from './prepare-attenuator.js';
|
|
4
3
|
|
|
5
4
|
/** @import {Amplify} from '@endo/exo'; */
|
|
6
5
|
|
|
@@ -10,11 +9,18 @@ import { M } from '@endo/patterns';
|
|
|
10
9
|
// use the attenuator implementation in prepare-attenuator.js.
|
|
11
10
|
// Please co-maintain these two modules.
|
|
12
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @template [U=any]
|
|
14
|
+
* @callback MakeRevocable
|
|
15
|
+
* @param {U} underlying
|
|
16
|
+
* @returns {Partial<U>}
|
|
17
|
+
*/
|
|
18
|
+
|
|
13
19
|
/**
|
|
14
20
|
* @template [U=any]
|
|
15
21
|
* @typedef {object} RevocableMakerKit
|
|
16
22
|
* @property {(revocable: U) => boolean} revoke
|
|
17
|
-
* @property {
|
|
23
|
+
* @property {MakeRevocable} makeRevocable
|
|
18
24
|
* Forwards to the underlying exo object, until revoked
|
|
19
25
|
*/
|
|
20
26
|
|
|
@@ -27,7 +33,7 @@ import { M } from '@endo/patterns';
|
|
|
27
33
|
* @template [U=any]
|
|
28
34
|
* @typedef {object} RevocableKit
|
|
29
35
|
* @property {RevokerFacet} revoker
|
|
30
|
-
* @property {U} revocable
|
|
36
|
+
* @property {Partial<U>} revocable
|
|
31
37
|
* Forwards to the underlying exo object, until revoked
|
|
32
38
|
*/
|
|
33
39
|
|
|
@@ -45,14 +51,14 @@ import { M } from '@endo/patterns';
|
|
|
45
51
|
* The `interfaceName` of the underlying interface guard.
|
|
46
52
|
* Defaults to the `uKindName`.
|
|
47
53
|
* @property {Record<
|
|
48
|
-
*
|
|
54
|
+
* PropertyKey,
|
|
49
55
|
* import('@endo/patterns').MethodGuard
|
|
50
56
|
* >} [extraMethodGuards]
|
|
51
57
|
* For guarding the `extraMethods`, if you include them below. These appear
|
|
52
58
|
* only on the synthesized interface guard for the revocable caretaker, and
|
|
53
59
|
* do not necessarily correspond to any method of the underlying.
|
|
54
60
|
* @property {Record<
|
|
55
|
-
*
|
|
61
|
+
* PropertyKey,
|
|
56
62
|
* (this: RevocableKitThis<U>, ...args: any[]) => any
|
|
57
63
|
* >} [extraMethods]
|
|
58
64
|
* Extra methods adding behavior only to the revocable caretaker, and
|
|
@@ -67,7 +73,7 @@ import { M } from '@endo/patterns';
|
|
|
67
73
|
* @param {import('@agoric/base-zone').Zone} zone
|
|
68
74
|
* @param {string} uKindName
|
|
69
75
|
* The `kindName` of the underlying exo class
|
|
70
|
-
* @param {
|
|
76
|
+
* @param {PropertyKey[]} uMethodNames
|
|
71
77
|
* The method names of the underlying exo class that should be represented
|
|
72
78
|
* by transparently-forwarding methods of the revocable caretaker.
|
|
73
79
|
* @param {RevocableKitOptions<U>} [options]
|
|
@@ -81,22 +87,16 @@ export const prepareRevocableMakerKit = (
|
|
|
81
87
|
) => {
|
|
82
88
|
const {
|
|
83
89
|
uInterfaceName = uKindName,
|
|
84
|
-
extraMethodGuards =
|
|
85
|
-
extraMethods =
|
|
90
|
+
extraMethodGuards = {},
|
|
91
|
+
extraMethods = {},
|
|
86
92
|
} = options;
|
|
87
93
|
const RevocableIKit = harden({
|
|
88
94
|
revoker: M.interface(`${uInterfaceName}_revoker`, {
|
|
89
95
|
revoke: M.call().returns(M.boolean()),
|
|
90
96
|
}),
|
|
91
|
-
revocable: M.interface(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
...extraMethodGuards,
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
defaultGuards: 'raw',
|
|
98
|
-
},
|
|
99
|
-
),
|
|
97
|
+
revocable: M.interface(`${uInterfaceName}_revocable`, extraMethodGuards, {
|
|
98
|
+
defaultGuards: 'raw',
|
|
99
|
+
}),
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
const revocableKindName = `${uKindName}_caretaker`;
|
|
@@ -107,9 +107,7 @@ export const prepareRevocableMakerKit = (
|
|
|
107
107
|
const makeRevocableKit = zone.exoClassKit(
|
|
108
108
|
revocableKindName,
|
|
109
109
|
RevocableIKit,
|
|
110
|
-
underlying => ({
|
|
111
|
-
underlying,
|
|
112
|
-
}),
|
|
110
|
+
underlying => ({ underlying }),
|
|
113
111
|
{
|
|
114
112
|
revoker: {
|
|
115
113
|
revoke() {
|
|
@@ -121,30 +119,10 @@ export const prepareRevocableMakerKit = (
|
|
|
121
119
|
return true;
|
|
122
120
|
},
|
|
123
121
|
},
|
|
124
|
-
revocable:
|
|
125
|
-
...fromUniqueEntries(
|
|
126
|
-
uMethodNames.map(name => [
|
|
127
|
-
name,
|
|
128
|
-
{
|
|
129
|
-
// Use concise method syntax for exo methods
|
|
130
|
-
[name](...args) {
|
|
131
|
-
// @ts-expect-error normal exo-this typing confusion
|
|
132
|
-
const { underlying } = this.state;
|
|
133
|
-
underlying !== undefined ||
|
|
134
|
-
Fail`${q(revocableKindName)} revoked`;
|
|
135
|
-
return underlying[name](...args);
|
|
136
|
-
},
|
|
137
|
-
// @ts-expect-error using possible symbol as index type
|
|
138
|
-
}[name],
|
|
139
|
-
]),
|
|
140
|
-
),
|
|
141
|
-
...extraMethods,
|
|
142
|
-
},
|
|
122
|
+
revocable: wrapperMethods(revocableKindName, uMethodNames, extraMethods),
|
|
143
123
|
},
|
|
144
124
|
{
|
|
145
|
-
stateShape: {
|
|
146
|
-
underlying: M.opt(M.remotable('underlying')),
|
|
147
|
-
},
|
|
125
|
+
stateShape: { underlying: M.opt(M.remotable('underlying')) },
|
|
148
126
|
receiveAmplifier: amp => {
|
|
149
127
|
amplifier = amp;
|
|
150
128
|
},
|
|
@@ -152,12 +130,9 @@ export const prepareRevocableMakerKit = (
|
|
|
152
130
|
);
|
|
153
131
|
|
|
154
132
|
/**
|
|
155
|
-
* @
|
|
156
|
-
* @returns {U}
|
|
133
|
+
* @type {MakeRevocable}
|
|
157
134
|
*/
|
|
158
|
-
const makeRevocable = underlying =>
|
|
159
|
-
// @ts-expect-error some confusion about UU vs Guarded<U> I think
|
|
160
|
-
makeRevocableKit(underlying).revocable;
|
|
135
|
+
const makeRevocable = underlying => makeRevocableKit(underlying).revocable;
|
|
161
136
|
|
|
162
137
|
/**
|
|
163
138
|
* @param {U} revocable
|
|
@@ -87,6 +87,8 @@ test('test revoke defineVirtualExoClassKit', t => {
|
|
|
87
87
|
if (state.underlying === undefined) {
|
|
88
88
|
return false;
|
|
89
89
|
}
|
|
90
|
+
// @ts-expect-error Setting this to `undefined` is purposely outside
|
|
91
|
+
// the type system.
|
|
90
92
|
state.underlying = undefined;
|
|
91
93
|
return true;
|
|
92
94
|
},
|