@agoric/vow 0.1.1-dev-249a5d4.0 → 0.1.1-dev-5856dc0.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 +4 -4
- package/src/E.d.ts +30 -32
- package/src/E.d.ts.map +1 -1
- package/src/E.js +44 -38
- package/src/tools.d.ts +1 -1
- package/src/tools.d.ts.map +1 -1
- package/src/types.d.ts +5 -7
- package/src/types.d.ts.map +1 -1
- package/src/types.js +4 -8
- package/src/when.d.ts +2 -2
- package/src/when.d.ts.map +1 -1
- package/src/when.js +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/vow",
|
|
3
|
-
"version": "0.1.1-dev-
|
|
3
|
+
"version": "0.1.1-dev-5856dc0.0+5856dc0",
|
|
4
4
|
"description": "Remote (shortening and disconnection-tolerant) Promise-likes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"lint:types": "tsc"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@agoric/base-zone": "0.1.1-dev-
|
|
24
|
-
"@agoric/internal": "0.3.3-dev-
|
|
23
|
+
"@agoric/base-zone": "0.1.1-dev-5856dc0.0+5856dc0",
|
|
24
|
+
"@agoric/internal": "0.3.3-dev-5856dc0.0+5856dc0",
|
|
25
25
|
"@endo/env-options": "^1.1.4",
|
|
26
26
|
"@endo/eventual-send": "^1.2.2",
|
|
27
27
|
"@endo/pass-style": "^1.4.0",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"typeCoverage": {
|
|
54
54
|
"atLeast": 89.6
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "5856dc0a002031bdcc1d22a68a6fcf6fa9be38e0"
|
|
57
57
|
}
|
package/src/E.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export default makeE;
|
|
2
|
-
export type Callable = (...args:
|
|
3
|
-
export type EProxy = ReturnType<(<A = {}
|
|
2
|
+
export type Callable = (...args: unknown[]) => any;
|
|
3
|
+
export type EProxy = ReturnType<(<A = {}>(HandledPromise: {
|
|
4
4
|
new <R>(executor: HandledExecutor<R>, unfulfilledHandler?: Handler<Promise<unknown>>): Promise<R>;
|
|
5
5
|
prototype: Promise<unknown>;
|
|
6
|
-
} & PromiseConstructor & import("@endo/eventual-send").HandledPromiseStaticMethods,
|
|
7
|
-
unwrap?:
|
|
6
|
+
} & PromiseConstructor & import("@endo/eventual-send").HandledPromiseStaticMethods, powers?: {
|
|
7
|
+
unwrap?: (<T>(x: T) => Promise<EUnwrap<T>>) | undefined;
|
|
8
8
|
additional?: A | undefined;
|
|
9
|
-
} | undefined) => (<
|
|
9
|
+
} | undefined) => (<T_1>(x: T_1) => ECallableOrMethods<RemoteFunctions<T_1>>) & {
|
|
10
10
|
/**
|
|
11
11
|
* E.get(x) returns a proxy on which you can get arbitrary properties.
|
|
12
12
|
* Each of these properties returns a promise for the property. The promise
|
|
@@ -18,7 +18,7 @@ export type EProxy = ReturnType<(<A = {}, U extends (x: any) => Promise<any> = (
|
|
|
18
18
|
* @returns {EGetters<LocalRecord<T>>} property get proxy
|
|
19
19
|
* @readonly
|
|
20
20
|
*/
|
|
21
|
-
readonly get: <
|
|
21
|
+
readonly get: <T_2>(x: T_2) => EGetters<LocalRecord<T_2>>;
|
|
22
22
|
/**
|
|
23
23
|
* E.resolve(x) converts x to a handled promise. It is
|
|
24
24
|
* shorthand for HandledPromise.resolve(x)
|
|
@@ -28,7 +28,7 @@ export type EProxy = ReturnType<(<A = {}, U extends (x: any) => Promise<any> = (
|
|
|
28
28
|
* @returns {Promise<Awaited<T>>} handled promise for x
|
|
29
29
|
* @readonly
|
|
30
30
|
*/
|
|
31
|
-
readonly resolve: <
|
|
31
|
+
readonly resolve: <T_3>(x: T_3) => Promise<Awaited<T_3>>;
|
|
32
32
|
/**
|
|
33
33
|
* E.sendOnly returns a proxy similar to E, but for which the results
|
|
34
34
|
* are ignored (undefined is returned).
|
|
@@ -38,21 +38,21 @@ export type EProxy = ReturnType<(<A = {}, U extends (x: any) => Promise<any> = (
|
|
|
38
38
|
* @returns {ESendOnlyCallableOrMethods<RemoteFunctions<T>>} method/function call proxy
|
|
39
39
|
* @readonly
|
|
40
40
|
*/
|
|
41
|
-
readonly sendOnly: <
|
|
41
|
+
readonly sendOnly: <T_4>(x: T_4) => ESendOnlyCallableOrMethods<RemoteFunctions<T_4>>;
|
|
42
42
|
/**
|
|
43
43
|
* E.when(x, res, rej) is equivalent to
|
|
44
|
-
*
|
|
44
|
+
* unwrap(x).then(onfulfilled, onrejected)
|
|
45
45
|
*
|
|
46
46
|
* @template T
|
|
47
|
-
* @template [TResult1=
|
|
47
|
+
* @template [TResult1=EUnwrap<T>]
|
|
48
48
|
* @template [TResult2=never]
|
|
49
49
|
* @param {ERef<T>} x value to convert to a handled promise
|
|
50
|
-
* @param {(value:
|
|
50
|
+
* @param {(value: EUnwrap<T>) => ERef<TResult1>} [onfulfilled]
|
|
51
51
|
* @param {(reason: any) => ERef<TResult2>} [onrejected]
|
|
52
52
|
* @returns {Promise<TResult1 | TResult2>}
|
|
53
53
|
* @readonly
|
|
54
54
|
*/
|
|
55
|
-
readonly when: <
|
|
55
|
+
readonly when: <T_5, TResult1 = EUnwrap<T_5>, TResult2 = never>(x: ERef<T_5>, onfulfilled?: ((value: EUnwrap<T_5>) => ERef<TResult1>) | undefined, onrejected?: ((reason: any) => ERef<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
|
|
56
56
|
} & A)>;
|
|
57
57
|
/**
|
|
58
58
|
* `DataOnly<T>` means to return a record type `T2` consisting only of
|
|
@@ -60,9 +60,9 @@ export type EProxy = ReturnType<(<A = {}, U extends (x: any) => Promise<any> = (
|
|
|
60
60
|
*/
|
|
61
61
|
export type DataOnly<T> = Omit<T, FilteredKeys<T, Callable>>;
|
|
62
62
|
export type ERef<T> = PromiseLike<T> | T;
|
|
63
|
-
export type ECallable<T extends Callable> = (...args: Parameters<T>) => Promise<
|
|
63
|
+
export type ECallable<T extends Callable> = ReturnType<T> extends EUnwrap<ReturnType<T>> ? (...args: Parameters<T>) => Promise<ReturnType<T>> : ReturnType<T> extends Promise<EUnwrap<ReturnType<T>>> ? T : (...args: Parameters<T>) => Promise<EUnwrap<ReturnType<T>>>;
|
|
64
64
|
export type EMethods<T> = { readonly [P in keyof T]: T[P] extends Callable ? ECallable<T[P]> : never; };
|
|
65
|
-
export type EGetters<T> = { readonly [P in keyof T]: T[P] extends PromiseLike<
|
|
65
|
+
export type EGetters<T> = { readonly [P in keyof T]: T[P] extends PromiseLike<any> ? T[P] : Promise<Awaited<T[P]>>; };
|
|
66
66
|
export type ESendOnlyCallable<T extends Callable> = (...args: Parameters<T>) => Promise<void>;
|
|
67
67
|
export type ESendOnlyMethods<T> = { readonly [P in keyof T]: T[P] extends Callable ? ESendOnlyCallable<T[P]> : never; };
|
|
68
68
|
export type ESendOnlyCallableOrMethods<T> = (T extends Callable ? ESendOnlyCallable<T> & ESendOnlyMethods<Required<T>> : ESendOnlyMethods<Required<T>>);
|
|
@@ -82,12 +82,12 @@ export type FilteredKeys<T, U> = { [P in keyof T]: T[P] extends U ? P : never; }
|
|
|
82
82
|
* `PickCallable<T>` means to return a single root callable or a record type
|
|
83
83
|
* consisting only of properties that are functions.
|
|
84
84
|
*/
|
|
85
|
-
export type PickCallable<T> = (T extends Callable ? (...args: Parameters<T>) => ReturnType<T> : Pick<T, FilteredKeys<T, Callable>>);
|
|
85
|
+
export type PickCallable<T> = (T extends Callable ? (...args: Parameters<T>) => ReturnType<T> : FilteredKeys<T, Callable> extends never ? never : Pick<T, FilteredKeys<T, Callable>>);
|
|
86
86
|
/**
|
|
87
87
|
* `RemoteFunctions<T>` means to return the functions and properties that are remotely callable.
|
|
88
88
|
*/
|
|
89
|
-
export type RemoteFunctions<T> = T extends RemotableBrand<
|
|
90
|
-
export type LocalRecord<T> = T extends RemotableBrand<infer L,
|
|
89
|
+
export type RemoteFunctions<T> = EUnwrap<T> extends RemotableBrand<any, infer R> ? PickCallable<R> : PickCallable<EUnwrap<T>>;
|
|
90
|
+
export type LocalRecord<T> = T extends RemotableBrand<infer L, any> ? L : EUnwrap<T>;
|
|
91
91
|
/**
|
|
92
92
|
* Type for an object that must only be invoked with E. It supports a given
|
|
93
93
|
* interface but declares all the functions as asyncable.
|
|
@@ -95,19 +95,18 @@ export type LocalRecord<T> = T extends RemotableBrand<infer L, infer R> ? L : Aw
|
|
|
95
95
|
export type EOnly<T> = (T extends Callable ? (...args: Parameters<T>) => ERef<Awaited<EOnly<ReturnType<T>>>> : T extends Record<PropertyKey, Callable> ? { [K in keyof T]: T[K] extends Callable ? (...args: Parameters<T[K]>) => ERef<Awaited<EOnly<ReturnType<T[K]>>>> : T[K]; } : T);
|
|
96
96
|
/**
|
|
97
97
|
* @template [A={}]
|
|
98
|
-
* @template {(x: any) => Promise<any>} [U=(x: any) => Promise<any>]
|
|
99
98
|
* @param {HandledPromiseConstructor} HandledPromise
|
|
100
99
|
* @param {object} [powers]
|
|
101
|
-
* @param {
|
|
100
|
+
* @param {<T>(x: T) => Promise<EUnwrap<T>>} [powers.unwrap]
|
|
102
101
|
* @param {A} [powers.additional]
|
|
103
102
|
*/
|
|
104
|
-
declare function makeE<A = {}
|
|
103
|
+
declare function makeE<A = {}>(HandledPromise: {
|
|
105
104
|
new <R>(executor: HandledExecutor<R>, unfulfilledHandler?: Handler<Promise<unknown>>): Promise<R>;
|
|
106
105
|
prototype: Promise<unknown>;
|
|
107
|
-
} & PromiseConstructor & import("@endo/eventual-send").HandledPromiseStaticMethods,
|
|
108
|
-
unwrap?:
|
|
106
|
+
} & PromiseConstructor & import("@endo/eventual-send").HandledPromiseStaticMethods, powers?: {
|
|
107
|
+
unwrap?: (<T>(x: T) => Promise<EUnwrap<T>>) | undefined;
|
|
109
108
|
additional?: A | undefined;
|
|
110
|
-
} | undefined): (<
|
|
109
|
+
} | undefined): (<T_1>(x: T_1) => ECallableOrMethods<RemoteFunctions<T_1>>) & {
|
|
111
110
|
/**
|
|
112
111
|
* E.get(x) returns a proxy on which you can get arbitrary properties.
|
|
113
112
|
* Each of these properties returns a promise for the property. The promise
|
|
@@ -119,7 +118,7 @@ declare function makeE<A = {}, U extends (x: any) => Promise<any> = (x: any) =>
|
|
|
119
118
|
* @returns {EGetters<LocalRecord<T>>} property get proxy
|
|
120
119
|
* @readonly
|
|
121
120
|
*/
|
|
122
|
-
readonly get: <
|
|
121
|
+
readonly get: <T_2>(x: T_2) => EGetters<LocalRecord<T_2>>;
|
|
123
122
|
/**
|
|
124
123
|
* E.resolve(x) converts x to a handled promise. It is
|
|
125
124
|
* shorthand for HandledPromise.resolve(x)
|
|
@@ -129,7 +128,7 @@ declare function makeE<A = {}, U extends (x: any) => Promise<any> = (x: any) =>
|
|
|
129
128
|
* @returns {Promise<Awaited<T>>} handled promise for x
|
|
130
129
|
* @readonly
|
|
131
130
|
*/
|
|
132
|
-
readonly resolve: <
|
|
131
|
+
readonly resolve: <T_3>(x: T_3) => Promise<Awaited<T_3>>;
|
|
133
132
|
/**
|
|
134
133
|
* E.sendOnly returns a proxy similar to E, but for which the results
|
|
135
134
|
* are ignored (undefined is returned).
|
|
@@ -139,23 +138,22 @@ declare function makeE<A = {}, U extends (x: any) => Promise<any> = (x: any) =>
|
|
|
139
138
|
* @returns {ESendOnlyCallableOrMethods<RemoteFunctions<T>>} method/function call proxy
|
|
140
139
|
* @readonly
|
|
141
140
|
*/
|
|
142
|
-
readonly sendOnly: <
|
|
141
|
+
readonly sendOnly: <T_4>(x: T_4) => ESendOnlyCallableOrMethods<RemoteFunctions<T_4>>;
|
|
143
142
|
/**
|
|
144
143
|
* E.when(x, res, rej) is equivalent to
|
|
145
|
-
*
|
|
144
|
+
* unwrap(x).then(onfulfilled, onrejected)
|
|
146
145
|
*
|
|
147
146
|
* @template T
|
|
148
|
-
* @template [TResult1=
|
|
147
|
+
* @template [TResult1=EUnwrap<T>]
|
|
149
148
|
* @template [TResult2=never]
|
|
150
149
|
* @param {ERef<T>} x value to convert to a handled promise
|
|
151
|
-
* @param {(value:
|
|
150
|
+
* @param {(value: EUnwrap<T>) => ERef<TResult1>} [onfulfilled]
|
|
152
151
|
* @param {(reason: any) => ERef<TResult2>} [onrejected]
|
|
153
152
|
* @returns {Promise<TResult1 | TResult2>}
|
|
154
153
|
* @readonly
|
|
155
154
|
*/
|
|
156
|
-
readonly when: <
|
|
155
|
+
readonly when: <T_5, TResult1 = EUnwrap<T_5>, TResult2 = never>(x: ERef<T_5>, onfulfilled?: ((value: EUnwrap<T_5>) => ERef<TResult1>) | undefined, onrejected?: ((reason: any) => ERef<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
|
|
157
156
|
} & A;
|
|
158
|
-
import type {
|
|
157
|
+
import type { EUnwrap } from './types.js';
|
|
159
158
|
import type { RemotableBrand } from '@endo/eventual-send';
|
|
160
|
-
import type { Vow } from './types.js';
|
|
161
159
|
//# sourceMappingURL=E.d.ts.map
|
package/src/E.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"E.d.ts","sourceRoot":"","sources":["E.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"E.d.ts","sourceRoot":"","sources":["E.js"],"names":[],"mappings":";uBA6Bc,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,GAAG;qBAuR3B,UAAU;sBAlToB,gBAAkB,CAAA,CAAC,uBAC1D,QAAS,gBAAgB,CAAC;;;eA2Mb,CAAC,KAAD,CAAC;;oBAiBF,GAAC,KAAD,GAAC;IAQV;;;;;;;;;;OAUG;mBAHQ,GAAC,KAAD,GAAC;IAYZ;;;;;;;;OAQG;uBAHQ,GAAC,KAAD,GAAC;IAMZ;;;;;;;;OAQG;wBAHQ,GAAC,KAAD,GAAC;IAYZ;;;;;;;;;;;;OAYG;oB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AC,AAH2B,CACpB,CAAC,AADqB,CAAC,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAGlE,CAAC,AAHmE,CAC5D,CAAC,AAD6D,CAAC,CAAC,CAAC,CAAC,CAAC,GAG3E,CAAC,AAFM,CAAC,CAAC,CAAC,GACT,GACD,CAAC,CACN;AArPJ;;;;;;GAMG;AACH;sBA/M4C,gBAAkB,CAAA,CAAC,uBAC1D,QAAS,gBAAgB,CAAC;;;eA2MS,CAAC,KAAD,CAAC,AAAtB;;kBAkBmC,GAAC,KAAD,GAAC,AADrC,KACC,kBAAkB,CAAC,eAAe,CAAC,GAAC,CAAC,CAAC;IAOjD;;;;;;;;;;OAUG;mBAF+B,GAAC,KAAD,GAAC,AADvB,KACC,QAAQ,CAAC,WAAW,CAAC,GAAC,CAAC,CAAC;IAWrC;;;;;;;;OAQG;uBAF0B,GAAC,KAAD,GAAC,AADlB,KACC,OAAO,CAAC,OAAO,CAAC,GAAC,CAAC,CAAC;IAKhC;;;;;;;;OAQG;wBAFqD,GAAC,KAAD,GAAC,AAD7C,KACC,0BAA0B,CAAC,eAAe,CAAC,GAAC,CAAC,CAAC;IAW3D;;;;;;;;;;;;OAYG;oBAJwB,GAAC,EAEP,QAAQ,iBAAG,QAAQ,aAH7B,IAAI,CACY,GAAC,AADX,CAAC,0CACgB,IAAI,CAEjB,QAAQ,AAFkB,CAAC,sCAC5B,GAAG,KAAK,IAAI,CACA,QAAQ,AADC,CAAC,kBAC7B,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;MAgBhD;6BArR2B,YAAY;oCADsB,qBAAqB"}
|
package/src/E.js
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* @file provides a `makeE` that can be parameterized with an `unwrap` function
|
|
4
|
+
* and corresponding `import('./types').EUnwrap<T>`. These will be used to
|
|
5
|
+
* extract the final settlement from a chain of PromiseLikes and PromiseSteps or
|
|
6
|
+
* similar non-thenable pseudo-promises.
|
|
7
|
+
*
|
|
8
|
+
* `@agoric/vow/vat.js` uses this mechanism to export a `V` function with
|
|
9
|
+
* similar behaviour as the default `E`, augmented with automatic unwrapping of
|
|
10
|
+
* recipient Vows as if they were PromiseLikes.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
* TODO: Once this implementation has been polished and well-tested, it is
|
|
15
|
+
* designed to be a drop-in replacement for the version in
|
|
16
|
+
* `@endo/eventual-send/src/E.js` which contained no concept of "unwrap",
|
|
17
|
+
*/
|
|
2
18
|
import { trackTurns } from './track-turns.js';
|
|
3
19
|
import { makeMessageBreakpointTester } from './message-breakpoints.js';
|
|
4
20
|
|
|
@@ -9,9 +25,9 @@ const onSend = makeMessageBreakpointTester('ENDO_SEND_BREAKPOINTS');
|
|
|
9
25
|
|
|
10
26
|
/**
|
|
11
27
|
* @import { HandledPromiseConstructor, RemotableBrand } from '@endo/eventual-send'
|
|
12
|
-
* @import {
|
|
28
|
+
* @import { EUnwrap } from './types.js'
|
|
13
29
|
*/
|
|
14
|
-
/** @typedef {(...args:
|
|
30
|
+
/** @typedef {(...args: unknown[]) => any} Callable */
|
|
15
31
|
|
|
16
32
|
/** @type {ProxyHandler<any>} */
|
|
17
33
|
const baseFreezableProxyHandler = {
|
|
@@ -43,7 +59,7 @@ const baseFreezableProxyHandler = {
|
|
|
43
59
|
*
|
|
44
60
|
* @param {any} recipient Any value passed to E(x)
|
|
45
61
|
* @param {HandledPromiseConstructor} HandledPromise
|
|
46
|
-
* @param {(x:
|
|
62
|
+
* @param {<T>(x: T) => Promise<EUnwrap<T>>} unwrap
|
|
47
63
|
* @returns {ProxyHandler<any>} the Proxy handler
|
|
48
64
|
*/
|
|
49
65
|
const makeEProxyHandler = (recipient, HandledPromise, unwrap) =>
|
|
@@ -108,7 +124,7 @@ const makeEProxyHandler = (recipient, HandledPromise, unwrap) =>
|
|
|
108
124
|
*
|
|
109
125
|
* @param {any} recipient Any value passed to E.sendOnly(x)
|
|
110
126
|
* @param {HandledPromiseConstructor} HandledPromise
|
|
111
|
-
* @param {(x:
|
|
127
|
+
* @param {<T>(x: T) => Promise<EUnwrap<T>>} unwrap
|
|
112
128
|
* @returns {ProxyHandler<any>} the Proxy handler
|
|
113
129
|
*/
|
|
114
130
|
const makeESendOnlyProxyHandler = (recipient, HandledPromise, unwrap) =>
|
|
@@ -171,7 +187,7 @@ const makeESendOnlyProxyHandler = (recipient, HandledPromise, unwrap) =>
|
|
|
171
187
|
*
|
|
172
188
|
* @param {any} x Any value passed to E.get(x)
|
|
173
189
|
* @param {HandledPromiseConstructor} HandledPromise
|
|
174
|
-
* @param {(x:
|
|
190
|
+
* @param {<T>(x: T) => Promise<EUnwrap<T>>} unwrap
|
|
175
191
|
* @returns {ProxyHandler<any>} the Proxy handler
|
|
176
192
|
*/
|
|
177
193
|
const makeEGetProxyHandler = (x, HandledPromise, unwrap) =>
|
|
@@ -186,19 +202,17 @@ const resolve = x => HandledPromise.resolve(x);
|
|
|
186
202
|
|
|
187
203
|
/**
|
|
188
204
|
* @template [A={}]
|
|
189
|
-
* @template {(x: any) => Promise<any>} [U=(x: any) => Promise<any>]
|
|
190
205
|
* @param {HandledPromiseConstructor} HandledPromise
|
|
191
206
|
* @param {object} [powers]
|
|
192
|
-
* @param {
|
|
207
|
+
* @param {<T>(x: T) => Promise<EUnwrap<T>>} [powers.unwrap]
|
|
193
208
|
* @param {A} [powers.additional]
|
|
194
209
|
*/
|
|
195
|
-
const makeE = (
|
|
196
|
-
|
|
197
|
-
{
|
|
210
|
+
const makeE = (HandledPromise, powers = {}) => {
|
|
211
|
+
const {
|
|
198
212
|
additional = /** @type {A} */ ({}),
|
|
199
|
-
unwrap = /** @type {
|
|
200
|
-
} =
|
|
201
|
-
|
|
213
|
+
unwrap = /** @type {NonNullable<typeof powers.unwrap>} */ (resolve),
|
|
214
|
+
} = powers;
|
|
215
|
+
|
|
202
216
|
return harden(
|
|
203
217
|
assign(
|
|
204
218
|
/**
|
|
@@ -264,13 +278,13 @@ const makeE = (
|
|
|
264
278
|
|
|
265
279
|
/**
|
|
266
280
|
* E.when(x, res, rej) is equivalent to
|
|
267
|
-
*
|
|
281
|
+
* unwrap(x).then(onfulfilled, onrejected)
|
|
268
282
|
*
|
|
269
283
|
* @template T
|
|
270
|
-
* @template [TResult1=
|
|
284
|
+
* @template [TResult1=EUnwrap<T>]
|
|
271
285
|
* @template [TResult2=never]
|
|
272
286
|
* @param {ERef<T>} x value to convert to a handled promise
|
|
273
|
-
* @param {(value:
|
|
287
|
+
* @param {(value: EUnwrap<T>) => ERef<TResult1>} [onfulfilled]
|
|
274
288
|
* @param {(reason: any) => ERef<TResult2>} [onrejected]
|
|
275
289
|
* @returns {Promise<TResult1 | TResult2>}
|
|
276
290
|
* @readonly
|
|
@@ -310,9 +324,11 @@ export default makeE;
|
|
|
310
324
|
|
|
311
325
|
/**
|
|
312
326
|
* @template {Callable} T
|
|
313
|
-
* @typedef {
|
|
314
|
-
*
|
|
315
|
-
*
|
|
327
|
+
* @typedef {ReturnType<T> extends EUnwrap<ReturnType<T>>
|
|
328
|
+
* ? (...args: Parameters<T>) => Promise<ReturnType<T>>
|
|
329
|
+
* : ReturnType<T> extends Promise<EUnwrap<ReturnType<T>>>
|
|
330
|
+
* ? T
|
|
331
|
+
* : (...args: Parameters<T>) => Promise<EUnwrap<ReturnType<T>>>} ECallable
|
|
316
332
|
*/
|
|
317
333
|
|
|
318
334
|
/**
|
|
@@ -327,7 +343,7 @@ export default makeE;
|
|
|
327
343
|
/**
|
|
328
344
|
* @template T
|
|
329
345
|
* @typedef {{
|
|
330
|
-
* readonly [P in keyof T]: T[P] extends PromiseLike<
|
|
346
|
+
* readonly [P in keyof T]: T[P] extends PromiseLike<any>
|
|
331
347
|
* ? T[P]
|
|
332
348
|
* : Promise<Awaited<T[P]>>;
|
|
333
349
|
* }} EGetters
|
|
@@ -387,7 +403,9 @@ export default makeE;
|
|
|
387
403
|
* @template T
|
|
388
404
|
* @typedef {(
|
|
389
405
|
* T extends Callable
|
|
390
|
-
* ? (...args: Parameters<T>) => ReturnType<T>
|
|
406
|
+
* ? (...args: Parameters<T>) => ReturnType<T> // a root callable, no methods
|
|
407
|
+
* : FilteredKeys<T, Callable> extends never
|
|
408
|
+
* ? never
|
|
391
409
|
* : Pick<T, FilteredKeys<T, Callable>> // any callable methods
|
|
392
410
|
* )} PickCallable
|
|
393
411
|
*/
|
|
@@ -397,30 +415,18 @@ export default makeE;
|
|
|
397
415
|
*
|
|
398
416
|
* @template T
|
|
399
417
|
* @typedef {(
|
|
400
|
-
* T extends RemotableBrand<
|
|
401
|
-
* ? PickCallable<R>
|
|
402
|
-
* :
|
|
403
|
-
* ? PickCallable<R> // then return the callable properties of R
|
|
404
|
-
* : Awaited<T> extends Vow<infer U>
|
|
405
|
-
* ? RemoteFunctions<U> // then extract the remotable functions of U
|
|
406
|
-
* : T extends PromiseLike<infer U> // otherwise, if T is a promise
|
|
407
|
-
* ? Awaited<T> // then return resolved value T
|
|
408
|
-
* : T // otherwise, return T
|
|
418
|
+
* EUnwrap<T> extends RemotableBrand<any, infer R> // if a given T will settle to some remote interface R
|
|
419
|
+
* ? PickCallable<R> // then return the callable properties of R
|
|
420
|
+
* : PickCallable<EUnwrap<T>> // otherwise return the callable properties of the settled T
|
|
409
421
|
* )} RemoteFunctions
|
|
410
422
|
*/
|
|
411
423
|
|
|
412
424
|
/**
|
|
413
425
|
* @template T
|
|
414
426
|
* @typedef {(
|
|
415
|
-
* T extends RemotableBrand<infer L,
|
|
427
|
+
* T extends RemotableBrand<infer L, any>
|
|
416
428
|
* ? L
|
|
417
|
-
* :
|
|
418
|
-
* ? L
|
|
419
|
-
* : Awaited<T> extends Vow<infer U>
|
|
420
|
-
* ? LocalRecord<U>
|
|
421
|
-
* : T extends PromiseLike<infer U>
|
|
422
|
-
* ? Awaited<T>
|
|
423
|
-
* : T
|
|
429
|
+
* : EUnwrap<T>
|
|
424
430
|
* )} LocalRecord
|
|
425
431
|
*/
|
|
426
432
|
|
package/src/tools.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function prepareVowTools(zone: Zone, powers?: {
|
|
2
2
|
isRetryableReason?: IsRetryableReason | undefined;
|
|
3
3
|
} | undefined): {
|
|
4
|
-
when: <T, TResult1 = import("./types.js").
|
|
4
|
+
when: <T, TResult1 = import("./types.js").EUnwrap<T>, TResult2 = never>(specimenP: T, onFulfilled?: ((value: import("./types.js").EUnwrap<T>) => TResult1 | PromiseLike<TResult1>) | undefined, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
|
|
5
5
|
watch: <T_1 = any, TResult1_1 = T_1, TResult2_1 = never, C = any>(specimenP: import("./types.js").ERef<T_1 | import("./types.js").Vow<T_1>>, watcher?: import("./types.js").Watcher<T_1, TResult1_1, TResult2_1> | undefined, watcherContext?: C | undefined) => import("./types.js").Vow<Exclude<TResult1_1, void> | Exclude<TResult2_1, void> extends never ? TResult1_1 : Exclude<TResult1_1, void> | Exclude<TResult2_1, void>>;
|
|
6
6
|
makeVowKit: <T_2>() => import("./types.js").VowKit<T_2>;
|
|
7
7
|
allVows: (vows: unknown[]) => import("./types.js").Vow<any[]>;
|
package/src/tools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["tools.js"],"names":[],"mappings":"AAcO;;;
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["tools.js"],"names":[],"mappings":"AAcO;;;uFACL,CAAA;;;oBAWW,OAAO,EAAE;EAKrB;0BAzBuB,mBAAmB;uCACN,YAAY"}
|
package/src/types.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type ERef<T> = T | PromiseLike<T>;
|
|
|
12
12
|
* Follow the chain of vow shortening to the end, returning the final value.
|
|
13
13
|
* This is used within E, so we must narrow the type to its remote form.
|
|
14
14
|
*/
|
|
15
|
-
export type
|
|
15
|
+
export type EUnwrap<T> = (T extends Vow<infer U> ? EUnwrap<U> : T extends PromiseLike<infer U> ? EUnwrap<U> : T);
|
|
16
16
|
/**
|
|
17
17
|
* The first version of the vow implementation
|
|
18
18
|
* object. CAVEAT: These methods must never be changed or added to, to provide
|
|
@@ -39,21 +39,19 @@ export type VowKit<T = any> = {
|
|
|
39
39
|
resolver: VowResolver<T>;
|
|
40
40
|
};
|
|
41
41
|
export type VowResolver<T = any> = {
|
|
42
|
-
resolve(value?: T | PromiseVow<T>
|
|
42
|
+
resolve(value?: T | PromiseVow<T>): void;
|
|
43
43
|
reject(reason?: any): void;
|
|
44
44
|
};
|
|
45
45
|
export type Watcher<T = any, TResult1 = T, TResult2 = never, C = any> = {
|
|
46
|
-
onFulfilled?: ((value: T, context?: C) => TResult1 |
|
|
47
|
-
onRejected?: ((reason: any) => TResult2 |
|
|
46
|
+
onFulfilled?: ((value: T, context?: C) => Vow<TResult1> | PromiseVow<TResult1> | TResult1) | undefined;
|
|
47
|
+
onRejected?: ((reason: any) => Vow<TResult2> | PromiseVow<TResult2> | TResult2) | undefined;
|
|
48
48
|
};
|
|
49
49
|
export type VowTools = {
|
|
50
|
-
when: <T, TResult1 =
|
|
50
|
+
when: <T, TResult1 = EUnwrap<T>, TResult2 = never>(specimenP: T, onFulfilled?: ((value: EUnwrap<T>) => TResult1 | PromiseLike<TResult1>) | undefined, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
|
|
51
51
|
watch: <T_1 = any, TResult1_1 = T_1, TResult2_1 = never, C = any>(specimenP: ERef<T_1 | Vow<T_1>>, watcher?: Watcher<T_1, TResult1_1, TResult2_1> | undefined, watcherContext?: C | undefined) => Vow<Exclude<TResult1_1, void> | Exclude<TResult2_1, void> extends never ? TResult1_1 : Exclude<TResult1_1, void> | Exclude<TResult2_1, void>>;
|
|
52
52
|
makeVowKit: <T_2>() => VowKit<T_2>;
|
|
53
53
|
allVows: (vows: unknown[]) => Vow<any[]>;
|
|
54
54
|
};
|
|
55
|
-
import type { IsPrimitive } from '@agoric/internal';
|
|
56
|
-
import type { RemotableBrand } from '@endo/eventual-send';
|
|
57
55
|
import type { RemotableObject } from '@endo/pass-style';
|
|
58
56
|
import type { Remote } from '@agoric/internal';
|
|
59
57
|
//# sourceMappingURL=types.d.ts.map
|
package/src/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.js"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.js"],"names":[],"mappings":";;;yCAaW,GAAG,mBACH,GAAG,KAED,GAAG;;;;;uBAMa,CAAC,IAAjB,OAAO,CAAS,CAAC,AAAR,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;iBAMH,CAAC,IAAD,CAAC,AAAhB,GAAG,WAAW,CAAC,CAAC,CAAC;;;;;oBAU9B,CAAK,IAHO,CAGZ,CAAK,AAFA,SAAS,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAEvC,CAAK,AADA,SAAS,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAC/C,CAAK,CACF;;;;;;;kBAUwB,CAAC;;;;;;;aAAf,MAAM,OAAO,CAAC,CAAC,CAAC;;uBASe,CAAC;;;gBAKJ,CAAC;;;mBAOhB,CAAC,UAFf;IACZ,GAAO,EAAE,GAAG,CACc,CAAC,AADb,CAAC,CAAC;IAChB,QAAY,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;CAC1B;wBAK0C,CAAC,UAAlC;IAAE,OAAO,CAAC,KAAK,CAAC,EAAiB,CAAC,AAAf,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,IAAI,CAAA;CAAE;oBAS/D,CAAC,QAAyD,QAAQ,MAClB,QAAQ,UAD3C,CAAC;2BAAd,CAAC,YAAY,CAAC,KAAK,GAAG,CAAoC,QAAQ,AAAnC,CAAC,GAAG,UAAU,CAAa,QAAQ,AAAZ,CAAC,GAAG,QAAQ;2BACjE,GAAG,KAAK,GAAG,CAAoC,QAAQ,AAAnC,CAAC,GAAG,UAAU,CAAa,QAAQ,AAAZ,CAAC,GAAG,QAAQ;;;kEAvE1C,CAAC;;;oBAkB1B,SAAQ;;qCA5Be,kBAAkB;4BAC3B,kBAAkB"}
|
package/src/types.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
export {};
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* @import {RemotableBrand} from '@endo/eventual-send'
|
|
6
5
|
* @import {CopyTagged} from '@endo/pass-style'
|
|
7
6
|
* @import {RemotableObject} from '@endo/pass-style';
|
|
8
|
-
* @import {
|
|
9
|
-
* @import {PromiseVow} from '@agoric/vow';
|
|
7
|
+
* @import {Remote} from '@agoric/internal';
|
|
10
8
|
* @import {prepareVowTools} from './tools.js'
|
|
11
9
|
*/
|
|
12
10
|
|
|
@@ -36,12 +34,10 @@ export {};
|
|
|
36
34
|
* This is used within E, so we must narrow the type to its remote form.
|
|
37
35
|
* @template T
|
|
38
36
|
* @typedef {(
|
|
39
|
-
* T extends
|
|
40
|
-
* T extends
|
|
41
|
-
* IsPrimitive<T> extends true ? T :
|
|
42
|
-
* T extends RemotableBrand<infer Local, infer Primary> ? Local & T :
|
|
37
|
+
* T extends Vow<infer U> ? EUnwrap<U> :
|
|
38
|
+
* T extends PromiseLike<infer U> ? EUnwrap<U> :
|
|
43
39
|
* T
|
|
44
|
-
* )}
|
|
40
|
+
* )} EUnwrap
|
|
45
41
|
*/
|
|
46
42
|
|
|
47
43
|
/**
|
package/src/when.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export function makeWhen(isRetryableReason?: IsRetryableReason | undefined): <T, TResult1 =
|
|
1
|
+
export function makeWhen(isRetryableReason?: IsRetryableReason | undefined): <T, TResult1 = EUnwrap<T>, TResult2 = never>(specimenP: T, onFulfilled?: ((value: EUnwrap<T>) => TResult1 | PromiseLike<TResult1>) | undefined, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
|
|
2
2
|
export type When = ReturnType<typeof makeWhen>;
|
|
3
3
|
import type { IsRetryableReason } from './types.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { EUnwrap } from './types.js';
|
|
5
5
|
//# sourceMappingURL=when.d.ts.map
|
package/src/when.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"when.d.ts","sourceRoot":"","sources":["when.js"],"names":[],"mappings":"AAQO,
|
|
1
|
+
{"version":3,"file":"when.d.ts","sourceRoot":"","sources":["when.js"],"names":[],"mappings":"AAQO,8EAUsB,CAAC,EAEP,QAAQ,eAAG,QAAQ,qBAFb,CAAC,AADhB,wCAGS,QAAQ,AAFa,GAAG,WAAW,CAEnC,QAAQ,AAFoC,CAAC,sCAC9C,GAAG,KACS,QAAQ,AADJ,GAAG,WAAW,CAClB,QAAQ,AADmB,CAAC,kBAC/C,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC,CA2C1C;mBAIa,UAAU,CAAC,OAAO,QAAQ,CAAC;uCAhEO,YAAY;6BAAZ,YAAY"}
|
package/src/when.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import { getVowPayload, basicE } from './vow-utils.js';
|
|
3
3
|
|
|
4
|
-
/** @import { IsRetryableReason,
|
|
4
|
+
/** @import { IsRetryableReason, EUnwrap } from './types.js' */
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @param {IsRetryableReason} [isRetryableReason]
|
|
@@ -13,10 +13,10 @@ export const makeWhen = (
|
|
|
13
13
|
* Shorten `specimenP` until we achieve a final result.
|
|
14
14
|
*
|
|
15
15
|
* @template T
|
|
16
|
-
* @template [TResult1=
|
|
16
|
+
* @template [TResult1=EUnwrap<T>]
|
|
17
17
|
* @template [TResult2=never]
|
|
18
18
|
* @param {T} specimenP value to unwrap
|
|
19
|
-
* @param {(value:
|
|
19
|
+
* @param {(value: EUnwrap<T>) => TResult1 | PromiseLike<TResult1>} [onFulfilled]
|
|
20
20
|
* @param {(reason: any) => TResult2 | PromiseLike<TResult2>} [onRejected]
|
|
21
21
|
* @returns {Promise<TResult1 | TResult2>}
|
|
22
22
|
*/
|
|
@@ -50,7 +50,7 @@ export const makeWhen = (
|
|
|
50
50
|
payload = getVowPayload(result);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
const unwrapped = /** @type {
|
|
53
|
+
const unwrapped = /** @type {EUnwrap<T>} */ (result);
|
|
54
54
|
|
|
55
55
|
// We've extracted the final result.
|
|
56
56
|
if (onFulfilled == null && onRejected == null) {
|