@agoric/vow 0.1.1-dev-43dd3ec.0 → 0.1.1-dev-6909994.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/vow",
3
- "version": "0.1.1-dev-43dd3ec.0+43dd3ec",
3
+ "version": "0.1.1-dev-6909994.0+6909994",
4
4
  "description": "Remote (shortening and disconnection-tolerant) Promise-likes",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -19,8 +19,8 @@
19
19
  "lint:types": "tsc"
20
20
  },
21
21
  "dependencies": {
22
- "@agoric/base-zone": "0.1.1-dev-43dd3ec.0+43dd3ec",
23
- "@agoric/internal": "0.3.3-dev-43dd3ec.0+43dd3ec",
22
+ "@agoric/base-zone": "0.1.1-dev-6909994.0+6909994",
23
+ "@agoric/internal": "0.3.3-dev-6909994.0+6909994",
24
24
  "@endo/env-options": "^1.1.6",
25
25
  "@endo/errors": "^1.2.5",
26
26
  "@endo/eventual-send": "^1.2.5",
@@ -30,8 +30,8 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "@agoric/internal": "^0.3.2",
33
- "@agoric/swingset-vat": "0.32.3-dev-43dd3ec.0+43dd3ec",
34
- "@agoric/zone": "0.2.3-dev-43dd3ec.0+43dd3ec",
33
+ "@agoric/swingset-vat": "0.32.3-dev-6909994.0+6909994",
34
+ "@agoric/zone": "0.2.3-dev-6909994.0+6909994",
35
35
  "@endo/far": "^1.1.5",
36
36
  "@endo/init": "^1.1.4",
37
37
  "ava": "^5.3.0",
@@ -57,5 +57,5 @@
57
57
  "typeCoverage": {
58
58
  "atLeast": 89.96
59
59
  },
60
- "gitHead": "43dd3ec21c2f8a885af8e3c1d038437e8d2dc8e5"
60
+ "gitHead": "6909994fc7df88c73d6a476f4d10f56aea85bea5"
61
61
  }
package/src/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  export * from "../vat.js";
2
- export * from "./types.js";
3
- export * from "@agoric/internal/src/types.js";
2
+ export * from "./types-index.js";
4
3
  export { default as makeE } from "./E.js";
5
- export type VowTools = import("./tools.js").VowTools;
6
4
  export { VowShape, toPassableCap } from "./vow-utils.js";
7
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":";;;;uBASa,OAAO,YAAY,EAAE,QAAQ"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":""}
package/src/index.js CHANGED
@@ -6,12 +6,5 @@ export * from '../vat.js';
6
6
  export { default as makeE } from './E.js';
7
7
  export { VowShape, toPassableCap } from './vow-utils.js';
8
8
 
9
- /**
10
- * @typedef {import('./tools.js').VowTools} VowTools
11
- */
12
-
13
9
  // eslint-disable-next-line import/export
14
- export * from './types.js';
15
-
16
- // XXX re-exporting the Remote type for back-compat
17
- export * from '@agoric/internal/src/types.js';
10
+ export * from './types-index.js';
package/src/tools.d.ts CHANGED
@@ -1,26 +1,7 @@
1
1
  export function prepareBasicVowTools(zone: Zone, powers?: {
2
2
  isRetryableReason?: IsRetryableReason | undefined;
3
- } | undefined): {
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
- watch: <T = any, TResult1 = T, TResult2 = never, C extends any[] = any[]>(specimenP: EVow<T>, watcher?: import("./types.js").Watcher<T, TResult1, TResult2, C> | undefined, ...watcherArgs: C) => Vow<Exclude<TResult1, void> | Exclude<TResult2, void> extends never ? TResult1 : Exclude<TResult1, void> | Exclude<TResult2, void>>;
6
- makeVowKit: <T>() => import("./types.js").VowKit<T>;
7
- all: (maybeVows: unknown[]) => Vow<any[]>;
8
- allVows: (maybeVows: unknown[]) => Vow<any[]>;
9
- allSettled: (maybeVows: unknown[]) => Vow<({
10
- status: "fulfilled";
11
- value: any;
12
- } | {
13
- status: "rejected";
14
- reason: any;
15
- })[]>;
16
- asVow: <T extends unknown>(fn: (...args: any[]) => Vow<Awaited<T>> | Awaited<T> | import("./types.js").PromiseVow<T>) => Vow<Awaited<T>>;
17
- asPromise: AsPromiseFunction;
18
- retriable: <F extends (...args: any[]) => Promise<any>>(fnZone: Zone, name: string, fn: F) => F extends (...args: infer Args) => Promise<infer R> ? (...args: Args) => Vow<R> : never;
19
- };
20
- export type VowTools = ReturnType<typeof prepareBasicVowTools>;
3
+ } | undefined): VowTools;
21
4
  import type { Zone } from '@agoric/base-zone';
22
5
  import type { IsRetryableReason } from './types.js';
23
- import type { EVow } from './types.js';
24
- import type { Vow } from './types.js';
25
- import type { AsPromiseFunction } from './types.js';
6
+ import type { VowTools } from './types.js';
26
7
  //# sourceMappingURL=tools.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["tools.js"],"names":[],"mappings":"AAqBO,2CAJI,IAAI;;;;;;qBA4CF,OAAO,EAAE;yBAAT,OAAO,EAAE;4BAgBT,OAAO,EAAE;;;;;;;oCAFc,GACpC;;gBAnCkD,CAAC,SAApC,CAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAE,UACpC,IAAI,QACJ,MAAM,MACN,CAAC,KACC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,IAAI,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC,CAAC,GAAG,KAAK;EAmDrG;uBAGa,UAAU,CAAC,OAAO,oBAAoB,CAAC;0BA3F9B,mBAAmB;uCAE8B,YAAY;0BAAZ,YAAY;yBAAZ,YAAY;uCAAZ,YAAY"}
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["tools.js"],"names":[],"mappings":"AAsBO,2CALI,IAAI;;gBAGF,QAAQ,CA+EpB;0BA3FsB,mBAAmB;uCAE4B,YAAY;8BAAZ,YAAY"}
package/src/tools.js CHANGED
@@ -8,7 +8,7 @@ import { makeWhen } from './when.js';
8
8
  /**
9
9
  * @import {Zone} from '@agoric/base-zone';
10
10
  * @import {Passable} from '@endo/pass-style';
11
- * @import {IsRetryableReason, AsPromiseFunction, EVow, Vow, ERef} from './types.js';
11
+ * @import {IsRetryableReason, AsPromiseFunction, Vow, VowTools} from './types.js';
12
12
  */
13
13
 
14
14
  /**
@@ -18,6 +18,7 @@ import { makeWhen } from './when.js';
18
18
  * @param {Zone} zone
19
19
  * @param {object} [powers]
20
20
  * @param {IsRetryableReason} [powers.isRetryableReason]
21
+ * @returns {VowTools}
21
22
  */
22
23
  export const prepareBasicVowTools = (zone, powers = {}) => {
23
24
  const { isRetryableReason = /** @type {IsRetryableReason} */ (() => false) } =
@@ -34,8 +35,10 @@ export const prepareBasicVowTools = (zone, powers = {}) => {
34
35
  const watchUtils = makeWatchUtils();
35
36
  const asVow = makeAsVow(makeVowKit);
36
37
 
38
+ // FIXME in https://github.com/Agoric/agoric-sdk/pull/9785
37
39
  /**
38
- * TODO FIXME make this real
40
+ * @alpha Not yet implemented
41
+ *
39
42
  * Create a function that retries the given function if the underlying
40
43
  * functions rejects due to upgrade disconnection.
41
44
  *
@@ -96,5 +99,3 @@ export const prepareBasicVowTools = (zone, powers = {}) => {
96
99
  });
97
100
  };
98
101
  harden(prepareBasicVowTools);
99
-
100
- /** @typedef {ReturnType<typeof prepareBasicVowTools>} VowTools */
@@ -0,0 +1,5 @@
1
+ // Export all the types this package provides
2
+ export * from './types.js';
3
+
4
+ // XXX re-exporting the Remote type for back-compat
5
+ export { Remote } from '@agoric/internal/src/types.js';
@@ -0,0 +1,2 @@
1
+ // Empty JS file to correspond with its .d.ts twin
2
+ export {};
package/src/types.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import type { Remote } from '@agoric/internal';
2
+ import type { Zone } from '@agoric/zone';
3
+ import type { CopyTagged, RemotableObject } from '@endo/pass-style';
1
4
  /**
2
5
  * Return truthy if a rejection reason should result in a retry.
3
6
  */
@@ -16,7 +19,7 @@ export type EVow<T> = ERef<T | Vow<T>>;
16
19
  * Follow the chain of vow shortening to the end, returning the final value.
17
20
  * This is used within E, so we must narrow the type to its remote form.
18
21
  */
19
- export type EUnwrap<T> = (T extends Vow<infer U> ? EUnwrap<U> : T extends PromiseLike<infer U> ? EUnwrap<U> : T);
22
+ export type EUnwrap<T> = T extends Vow<infer U> ? EUnwrap<U> : T extends PromiseLike<infer U> ? EUnwrap<U> : T;
20
23
  /**
21
24
  * The first version of the vow implementation
22
25
  * object. CAVEAT: These methods must never be changed or added to, to provide
@@ -38,7 +41,7 @@ export type VowPayload<T = any> = {
38
41
  /**
39
42
  * Vows are objects that represent promises that can be stored durably.
40
43
  */
41
- export type Vow<T = any> = CopyTagged<"Vow", VowPayload<T>>;
44
+ export type Vow<T = any> = CopyTagged<'Vow', VowPayload<T>>;
42
45
  export type VowKit<T = any> = {
43
46
  vow: Vow<T>;
44
47
  resolver: VowResolver<T>;
@@ -55,7 +58,50 @@ export type Watcher<T = any, TResult1 = T, TResult2 = never, C extends any[] = a
55
58
  * Converts a vow or promise to a promise, ensuring proper handling of ephemeral promises.
56
59
  */
57
60
  export type AsPromiseFunction<T = any, TResult1 = T, TResult2 = never, C extends any[] = any[]> = (specimenP: ERef<T | Vow<T>>, watcher?: Watcher<T, TResult1, TResult2, C> | undefined, watcherArgs?: C | undefined) => Promise<TResult1 | TResult2>;
58
- import type { RemotableObject } from '@endo/pass-style';
59
- import type { Remote } from '@agoric/internal';
60
- import type { CopyTagged } from '@endo/pass-style';
61
+ export type VowTools = {
62
+ /**
63
+ * Vow-tolerant implementation of Promise.all that takes an iterable of vows
64
+ * and other {@link Passable}s and returns a single {@link Vow}. It resolves
65
+ * with an array of values when all of the input's promises or vows are
66
+ * fulfilled and rejects when any of the input's promises or vows are rejected
67
+ * with the first rejection reason.
68
+ */
69
+ all: (maybeVows: unknown[]) => Vow<any[]>;
70
+ /**
71
+ * Vow-tolerant
72
+ * implementation of Promise.allSettled that takes an iterable of vows and other
73
+ * {@link Passable}s and returns a single {@link Vow}. It resolves when all of
74
+ * the input's promises or vows are settled with an array of settled outcome
75
+ * objects.
76
+ */
77
+ allSettled: (maybeVows: unknown[]) => Vow<({
78
+ status: 'fulfilled';
79
+ value: any;
80
+ } | {
81
+ status: 'rejected';
82
+ reason: any;
83
+ })[]>;
84
+ allVows: (maybeVows: unknown[]) => Vow<any[]>;
85
+ /**
86
+ * Convert a vow or promise to a promise, ensuring proper handling of ephemeral promises.
87
+ */
88
+ asPromise: AsPromiseFunction;
89
+ /**
90
+ * Helper function that
91
+ * coerces the result of a function to a Vow. Helpful for scenarios like a
92
+ * synchronously thrown error.
93
+ */
94
+ asVow: <T extends unknown>(fn: (...args: any[]) => Vow<Awaited<T>> | Awaited<T> | PromiseVow<T>) => Vow<Awaited<T>>;
95
+ makeVowKit: <T>() => VowKit<T>;
96
+ retriable: <F extends (...args: any[]) => Promise<any>>(fnZone: Zone, name: string, fn: F) => F extends (...args: infer Args) => Promise<infer R> ? (...args: Args) => Vow<R> : never;
97
+ watch: <T = any, TResult1 = T, TResult2 = never, C extends any[] = any[]>(specimenP: EVow<T>, watcher?: Watcher<T, TResult1, TResult2, C> | undefined, ...watcherArgs: C) => Vow<Exclude<TResult1, void> | Exclude<TResult2, void> extends never ? TResult1 : Exclude<TResult1, void> | Exclude<TResult2, void>>;
98
+ /**
99
+ * Shorten `specimenP` until we achieve a final result.
100
+ *
101
+ * Does not survive upgrade (even if specimenP is a durable Vow).
102
+ *
103
+ * Use only if the Vow will resolve _promptly_ {@see {@link @agoric/swingset-vat/docs/async.md}}.
104
+ */
105
+ 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>;
106
+ };
61
107
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.js"],"names":[],"mappings":";;;yCAaW,GAAG,mBACH,GAAG,KAED,GAAG;;;;;uBAKH,CAAC,IACD,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;iBAKnB,CAAC,IACD,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC;;;;iBAKlB,CAAC,IACD,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;;;;;oBAMhB,CAAC,IACD,CACR,CAAC,SAAS,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACnC,CAAC,SAAS,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAC3C,CAAC,CACF;;;;;;;kBAIU,CAAC;;;;;;;aAMD,MAAM,OAAO,CAAC,CAAC,CAAC;;uBAOhB,CAAC;WAED,eAAe,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;;;;;gBAKlC,CAAC,UACF,WAAW,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;mBAI/B,CAAC,UACF;IACR,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IACZ,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;CAC1B;wBAIU,CAAC,UACF;IAAE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAAC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,IAAI,CAAA;CAAE;oBAIvE,CAAC,QACD,QAAQ,MACR,QAAQ,UACA,CAAC,SAAT,GAAG,EAAG;2BAEE,CAAC,WAAW,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AAS,EAAE,CAAC,EACZ,WAAW,CAAC,EACR,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GACzD,SAAS,EACb,UAAU,CAAC,EACP,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GACnD,SAAS,KACV,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC;CACnC,CAAC"}
package/src/types.ts ADDED
@@ -0,0 +1,177 @@
1
+ /* eslint-disable no-use-before-define */
2
+ import type { Remote } from '@agoric/internal';
3
+ import type { Zone } from '@agoric/zone';
4
+ import type { CopyTagged, RemotableObject } from '@endo/pass-style';
5
+
6
+ /**
7
+ * Return truthy if a rejection reason should result in a retry.
8
+ */
9
+ export type IsRetryableReason = (reason: any, priorRetryValue: any) => any;
10
+
11
+ /**
12
+ * Return type of a function that may
13
+ * return a promise or a vow.
14
+ */
15
+ export type PromiseVow<T> = Promise<T | Vow<T>>;
16
+
17
+ export type ERef<T> = T | PromiseLike<T>;
18
+ /**
19
+ * Eventually a value T or Vow for it.
20
+ */
21
+ export type EVow<T> = ERef<T | Vow<T>>;
22
+
23
+ /**
24
+ * Follow the chain of vow shortening to the end, returning the final value.
25
+ * This is used within E, so we must narrow the type to its remote form.
26
+ */
27
+ export type EUnwrap<T> =
28
+ T extends Vow<infer U>
29
+ ? EUnwrap<U>
30
+ : T extends PromiseLike<infer U>
31
+ ? EUnwrap<U>
32
+ : T;
33
+
34
+ /**
35
+ * The first version of the vow implementation
36
+ * object. CAVEAT: These methods must never be changed or added to, to provide
37
+ * forward/backward compatibility. Create a new object and bump its version
38
+ * number instead.
39
+ */
40
+ export type VowV0<T = any> = {
41
+ /**
42
+ * Attempt to unwrap all vows in this
43
+ * promise chain, returning a promise for the final value. A rejection may
44
+ * indicate a temporary routing failure requiring a retry, otherwise that the
45
+ * decider of the terminal promise rejected it.
46
+ */
47
+ shorten: () => Promise<T>;
48
+ };
49
+
50
+ export type VowPayload<T = any> = {
51
+ vowV0: RemotableObject & Remote<VowV0<T>>;
52
+ };
53
+
54
+ /**
55
+ * Vows are objects that represent promises that can be stored durably.
56
+ */
57
+ export type Vow<T = any> = CopyTagged<'Vow', VowPayload<T>>;
58
+
59
+ export type VowKit<T = any> = {
60
+ vow: Vow<T>;
61
+ resolver: VowResolver<T>;
62
+ };
63
+
64
+ export type VowResolver<T = any> = {
65
+ resolve(value?: T | PromiseVow<T>): void;
66
+ reject(reason?: any): void;
67
+ };
68
+
69
+ export type Watcher<
70
+ T = any,
71
+ TResult1 = T,
72
+ TResult2 = never,
73
+ C extends any[] = any[],
74
+ > = {
75
+ onFulfilled?:
76
+ | ((
77
+ value: T,
78
+ ...args: C
79
+ ) => Vow<TResult1> | PromiseVow<TResult1> | TResult1)
80
+ | undefined;
81
+ onRejected?:
82
+ | ((
83
+ reason: any,
84
+ ...args: C
85
+ ) => Vow<TResult2> | PromiseVow<TResult2> | TResult2)
86
+ | undefined;
87
+ };
88
+
89
+ /**
90
+ * Converts a vow or promise to a promise, ensuring proper handling of ephemeral promises.
91
+ */
92
+ export type AsPromiseFunction<
93
+ T = any,
94
+ TResult1 = T,
95
+ TResult2 = never,
96
+ C extends any[] = any[],
97
+ > = (
98
+ specimenP: ERef<T | Vow<T>>,
99
+ watcher?: Watcher<T, TResult1, TResult2, C> | undefined,
100
+ watcherArgs?: C | undefined,
101
+ ) => Promise<TResult1 | TResult2>;
102
+
103
+ export type VowTools = {
104
+ /**
105
+ * Vow-tolerant implementation of Promise.all that takes an iterable of vows
106
+ * and other {@link Passable}s and returns a single {@link Vow}. It resolves
107
+ * with an array of values when all of the input's promises or vows are
108
+ * fulfilled and rejects when any of the input's promises or vows are rejected
109
+ * with the first rejection reason.
110
+ */
111
+ all: (maybeVows: unknown[]) => Vow<any[]>;
112
+ /**
113
+ * Vow-tolerant
114
+ * implementation of Promise.allSettled that takes an iterable of vows and other
115
+ * {@link Passable}s and returns a single {@link Vow}. It resolves when all of
116
+ * the input's promises or vows are settled with an array of settled outcome
117
+ * objects.
118
+ */
119
+ allSettled: (maybeVows: unknown[]) => Vow<
120
+ (
121
+ | {
122
+ status: 'fulfilled';
123
+ value: any;
124
+ }
125
+ | {
126
+ status: 'rejected';
127
+ reason: any;
128
+ }
129
+ )[]
130
+ >;
131
+ allVows: (maybeVows: unknown[]) => Vow<any[]>;
132
+ /**
133
+ * Convert a vow or promise to a promise, ensuring proper handling of ephemeral promises.
134
+ */
135
+ asPromise: AsPromiseFunction;
136
+ /**
137
+ * Helper function that
138
+ * coerces the result of a function to a Vow. Helpful for scenarios like a
139
+ * synchronously thrown error.
140
+ */
141
+ asVow: <T extends unknown>(
142
+ fn: (...args: any[]) => Vow<Awaited<T>> | Awaited<T> | PromiseVow<T>,
143
+ ) => Vow<Awaited<T>>;
144
+ makeVowKit: <T>() => VowKit<T>;
145
+ retriable: <F extends (...args: any[]) => Promise<any>>(
146
+ fnZone: Zone,
147
+ name: string,
148
+ fn: F,
149
+ ) => F extends (...args: infer Args) => Promise<infer R>
150
+ ? (...args: Args) => Vow<R>
151
+ : never;
152
+ watch: <T = any, TResult1 = T, TResult2 = never, C extends any[] = any[]>(
153
+ specimenP: EVow<T>,
154
+ watcher?: Watcher<T, TResult1, TResult2, C> | undefined,
155
+ ...watcherArgs: C
156
+ ) => Vow<
157
+ Exclude<TResult1, void> | Exclude<TResult2, void> extends never
158
+ ? TResult1
159
+ : Exclude<TResult1, void> | Exclude<TResult2, void>
160
+ >;
161
+ /**
162
+ * Shorten `specimenP` until we achieve a final result.
163
+ *
164
+ * Does not survive upgrade (even if specimenP is a durable Vow).
165
+ *
166
+ * Use only if the Vow will resolve _promptly_ {@see {@link @agoric/swingset-vat/docs/async.md}}.
167
+ */
168
+ when: <T, TResult1 = EUnwrap<T>, TResult2 = never>(
169
+ specimenP: T,
170
+ onFulfilled?:
171
+ | ((value: EUnwrap<T>) => TResult1 | PromiseLike<TResult1>)
172
+ | undefined,
173
+ onRejected?:
174
+ | ((reason: any) => TResult2 | PromiseLike<TResult2>)
175
+ | undefined,
176
+ ) => Promise<TResult1 | TResult2>;
177
+ };
@@ -15,7 +15,7 @@ export function prepareWatchUtils(zone: Zone, { watch, when, makeVowKit, isRetry
15
15
  reason: any;
16
16
  })[]>;
17
17
  /** @type {AsPromiseFunction} */
18
- asPromise(specimenP: any, watcher: import("./types.js").Watcher<any, any, never, any[]> | undefined, watcherArgs: any[] | undefined): Promise<any>;
18
+ asPromise(specimenP: any, watcher?: import("./types.js").Watcher<any, any, never, any[]> | undefined, watcherArgs?: any[] | undefined): Promise<any>;
19
19
  }>;
20
20
  import type { Zone } from '@agoric/base-zone';
21
21
  import type { Watch } from './watch.js';
package/src/types.js DELETED
@@ -1,109 +0,0 @@
1
- // @ts-check
2
- export {};
3
-
4
- /**
5
- * @import {CopyTagged} from '@endo/pass-style'
6
- * @import {RemotableObject} from '@endo/pass-style';
7
- * @import {Remote} from '@agoric/internal';
8
- * @import {prepareVowTools} from './tools.js'
9
- */
10
-
11
- /**
12
- * @callback IsRetryableReason
13
- * Return truthy if a rejection reason should result in a retry.
14
- * @param {any} reason
15
- * @param {any} priorRetryValue the previous value returned by this function
16
- * when deciding whether to retry the same logical operation
17
- * @returns {any} If falsy, the reason is not retryable. If truthy, the
18
- * priorRetryValue for the next call.
19
- */
20
-
21
- /**
22
- * @template T
23
- * @typedef {Promise<T | Vow<T>>} PromiseVow Return type of a function that may
24
- * return a promise or a vow.
25
- */
26
-
27
- /**
28
- * @template T
29
- * @typedef {T | PromiseLike<T>} ERef
30
- */
31
-
32
- /**
33
- * Eventually a value T or Vow for it.
34
- * @template T
35
- * @typedef {ERef<T | Vow<T>>} EVow
36
- */
37
-
38
- /**
39
- * Follow the chain of vow shortening to the end, returning the final value.
40
- * This is used within E, so we must narrow the type to its remote form.
41
- * @template T
42
- * @typedef {(
43
- * T extends Vow<infer U> ? EUnwrap<U> :
44
- * T extends PromiseLike<infer U> ? EUnwrap<U> :
45
- * T
46
- * )} EUnwrap
47
- */
48
-
49
- /**
50
- * @template [T=any]
51
- * @typedef {object} VowV0 The first version of the vow implementation
52
- * object. CAVEAT: These methods must never be changed or added to, to provide
53
- * forward/backward compatibility. Create a new object and bump its version
54
- * number instead.
55
- *
56
- * @property {() => Promise<T>} shorten Attempt to unwrap all vows in this
57
- * promise chain, returning a promise for the final value. A rejection may
58
- * indicate a temporary routing failure requiring a retry, otherwise that the
59
- * decider of the terminal promise rejected it.
60
- */
61
-
62
- /**
63
- * @template [T=any]
64
- * @typedef {object} VowPayload
65
- * @property {RemotableObject & Remote<VowV0<T>>} vowV0
66
- */
67
-
68
- /**
69
- * Vows are objects that represent promises that can be stored durably.
70
- * @template [T=any]
71
- * @typedef {CopyTagged<'Vow', VowPayload<T>>} Vow
72
- */
73
-
74
- /**
75
- * @template [T=any]
76
- * @typedef {{
77
- * vow: Vow<T>,
78
- * resolver: VowResolver<T>,
79
- * }} VowKit
80
- */
81
-
82
- /**
83
- * @template [T=any]
84
- * @typedef {{ resolve(value?: T | PromiseVow<T>): void, reject(reason?: any): void }} VowResolver
85
- */
86
-
87
- /**
88
- * @template [T=any]
89
- * @template [TResult1=T]
90
- * @template [TResult2=never]
91
- * @template {any[]} [C=any[]] watcher args
92
- * @typedef {object} Watcher
93
- * @property {(value: T, ...args: C) => Vow<TResult1> | PromiseVow<TResult1> | TResult1} [onFulfilled]
94
- * @property {(reason: any, ...args: C) => Vow<TResult2> | PromiseVow<TResult2> | TResult2} [onRejected]
95
- */
96
-
97
- /**
98
- * Converts a vow or promise to a promise, ensuring proper handling of ephemeral promises.
99
- *
100
- * @template [T=any]
101
- * @template [TResult1=T]
102
- * @template [TResult2=never]
103
- * @template {any[]} [C=any[]]
104
- * @callback AsPromiseFunction
105
- * @param {ERef<T | Vow<T>>} specimenP
106
- * @param {Watcher<T, TResult1, TResult2, C>} [watcher]
107
- * @param {C} [watcherArgs]
108
- * @returns {Promise<TResult1 | TResult2>}
109
- */