@agoric/vow 0.1.1-dev-d756c83.0.d756c83 → 0.1.1-dev-e9efaa1.0.e9efaa1

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.
Files changed (3) hide show
  1. package/package.json +8 -8
  2. package/src/types.js +204 -0
  3. package/src/types.ts +0 -204
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/vow",
3
- "version": "0.1.1-dev-d756c83.0.d756c83",
3
+ "version": "0.1.1-dev-e9efaa1.0.e9efaa1",
4
4
  "description": "Remote (shortening and disconnection-tolerant) Promise-likes",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -9,8 +9,8 @@
9
9
  },
10
10
  "scripts": {
11
11
  "build": "exit 0",
12
- "prepack": "yarn run -T tsc --build tsconfig.build.json",
13
- "postpack": "git clean -f '*.d.*ts*' '*.tsbuildinfo'",
12
+ "prepack": "yarn run -T prepack-package",
13
+ "postpack": "yarn run -T postpack-package",
14
14
  "test": "ava",
15
15
  "test:xs": "exit 0",
16
16
  "test:xs:ci": "npm run test:xs",
@@ -20,8 +20,8 @@
20
20
  "lint:types": "yarn run -T tsc"
21
21
  },
22
22
  "dependencies": {
23
- "@agoric/base-zone": "0.1.1-dev-d756c83.0.d756c83",
24
- "@agoric/internal": "0.3.3-dev-d756c83.0.d756c83",
23
+ "@agoric/base-zone": "0.1.1-dev-e9efaa1.0.e9efaa1",
24
+ "@agoric/internal": "0.3.3-dev-e9efaa1.0.e9efaa1",
25
25
  "@endo/env-options": "^1.1.11",
26
26
  "@endo/errors": "^1.2.13",
27
27
  "@endo/eventual-send": "^1.3.4",
@@ -31,8 +31,8 @@
31
31
  },
32
32
  "devDependencies": {
33
33
  "@agoric/internal": "workspace:*",
34
- "@agoric/swingset-vat": "0.32.3-dev-d756c83.0.d756c83",
35
- "@agoric/zone": "0.2.3-dev-d756c83.0.d756c83",
34
+ "@agoric/swingset-vat": "0.32.3-dev-e9efaa1.0.e9efaa1",
35
+ "@agoric/zone": "0.2.3-dev-e9efaa1.0.e9efaa1",
36
36
  "@endo/far": "^1.1.14",
37
37
  "@endo/init": "^1.1.12",
38
38
  "ava": "^5.3.0",
@@ -58,5 +58,5 @@
58
58
  "typeCoverage": {
59
59
  "atLeast": 92.06
60
60
  },
61
- "gitHead": "d756c838c7eb3e3cec4a8bdf5c24b97f942b754e"
61
+ "gitHead": "e9efaa12254f2c9a6faffc40ade2f1d9a70b87ae"
62
62
  }
package/src/types.js ADDED
@@ -0,0 +1,204 @@
1
+
2
+
3
+
4
+
5
+ /**
6
+ * Return truthy if a rejection reason should result in a retry.
7
+ */
8
+
9
+
10
+ /**
11
+ * Types that are conceptually similar to Promise<F> in that they wrap a fulfilled type.
12
+ */
13
+ // s| PromiseStep<F> …etc.
14
+
15
+ /**
16
+ * Extract the final fulfilment type from a chain of VowLikes.
17
+ */
18
+
19
+
20
+ /**
21
+ * Return type of a function that may
22
+ * return a promise or a vow.
23
+ */
24
+
25
+
26
+
27
+ /**
28
+ * Eventually a value T or Vow for it.
29
+ */
30
+
31
+
32
+ /**
33
+ * Follow the chain of vow shortening to the end, returning the final value.
34
+ * This is used within E, so we must narrow the type to its remote form.
35
+ */
36
+
37
+
38
+ /**
39
+ * The first version of the vow implementation
40
+ * object. CAVEAT: These methods must never be changed or added to, to provide
41
+ * forward/backward compatibility. Create a new object and bump its version
42
+ * number instead.
43
+ */
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+ /**
59
+ * Vows are objects that represent promises that can be stored durably.
60
+ */
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+ /**
94
+ * Converts a vow or promise to a promise, ensuring proper handling of ephemeral promises.
95
+ */
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
package/src/types.ts DELETED
@@ -1,204 +0,0 @@
1
- import type { Remote } from '@agoric/internal';
2
- import type { Zone } from '@agoric/zone';
3
- import type { CopyTagged, RemotableObject } from '@endo/pass-style';
4
-
5
- /**
6
- * Return truthy if a rejection reason should result in a retry.
7
- */
8
- export type IsRetryableReason = (reason: any, priorRetryValue: any) => any;
9
-
10
- /**
11
- * Types that are conceptually similar to Promise<F> in that they wrap a fulfilled type.
12
- */
13
- export type VowLike<F> = Promise<F> | PromiseLike<F> | Vow<F>; // s| PromiseStep<F> …etc.
14
-
15
- /**
16
- * Extract the final fulfilment type from a chain of VowLikes.
17
- */
18
- export type Fulfilled<T> = T extends VowLike<infer F> ? Fulfilled<F> : T;
19
-
20
- /**
21
- * Return type of a function that may
22
- * return a promise or a vow.
23
- */
24
- export type PromiseVow<T> = Promise<T | Vow<T>>;
25
-
26
- export type ERef<T> = T | PromiseLike<T>;
27
- /**
28
- * Eventually a value T or Vow for it.
29
- */
30
- export type EVow<T> = ERef<T | Vow<T>>;
31
-
32
- /**
33
- * Follow the chain of vow shortening to the end, returning the final value.
34
- * This is used within E, so we must narrow the type to its remote form.
35
- */
36
- export type EUnwrap<T> = Fulfilled<T>;
37
-
38
- /**
39
- * The first version of the vow implementation
40
- * object. CAVEAT: These methods must never be changed or added to, to provide
41
- * forward/backward compatibility. Create a new object and bump its version
42
- * number instead.
43
- */
44
- export type VowPayloadV0<T = any> = {
45
- /**
46
- * Attempt to unwrap all vows in this
47
- * promise chain, returning a promise for the final value. A rejection may
48
- * indicate a temporary routing failure requiring a retry, otherwise that the
49
- * decider of the terminal promise rejected it.
50
- */
51
- shorten: () => Promise<T>;
52
- };
53
-
54
- export type VowPayload<T = any> = {
55
- vowV0: RemotableObject & Remote<VowPayloadV0<T>>;
56
- };
57
-
58
- /**
59
- * Vows are objects that represent promises that can be stored durably.
60
- */
61
- export type Vow<T = any> = CopyTagged<'Vow', VowPayload<T>>;
62
-
63
- export type VowKit<T = any> = {
64
- vow: Vow<T>;
65
- resolver: VowResolver<T>;
66
- };
67
-
68
- export type VowResolver<T = any> = {
69
- resolve(value?: T | PromiseVow<T>): void;
70
- reject(reason?: any): void;
71
- };
72
-
73
- export type Watcher<
74
- T = any,
75
- TResult1 = T,
76
- TResult2 = never,
77
- C extends any[] = any[],
78
- > = {
79
- onFulfilled?:
80
- | ((
81
- value: T,
82
- ...args: C
83
- ) => Vow<TResult1> | PromiseVow<TResult1> | TResult1)
84
- | undefined;
85
- onRejected?:
86
- | ((
87
- reason: any,
88
- ...args: C
89
- ) => Vow<TResult2> | PromiseVow<TResult2> | TResult2)
90
- | undefined;
91
- };
92
-
93
- /**
94
- * Converts a vow or promise to a promise, ensuring proper handling of ephemeral promises.
95
- */
96
- export type AsPromiseFunction<
97
- T = any,
98
- TResult1 = T,
99
- TResult2 = never,
100
- C extends any[] = any[],
101
- > = (
102
- specimenP: ERef<T | Vow<T>>,
103
- watcher?: Watcher<T, TResult1, TResult2, C> | undefined,
104
- watcherArgs?: C | undefined,
105
- ) => Promise<TResult1 | TResult2>;
106
-
107
- export interface RetryableTool {
108
- /**
109
- * Create a function that retries the given function if the underlying
110
- * async function rejects due to an upgrade disconnection. The return value
111
- * of the created function is a vow that settles to the final retry result.
112
- *
113
- * The retried function should be idempotent.
114
- *
115
- * @param fnZone the zone for the named function
116
- * @param name base name to use in the zone
117
- * @param fn the retried function
118
- */
119
- <F extends (...args: any[]) => Promise<any>>(
120
- fnZone: Zone,
121
- name: string,
122
- fn: F,
123
- ): F extends (...args: infer Args) => Promise<infer R>
124
- ? (...args: Args) => Vow<R>
125
- : never;
126
- }
127
-
128
- export type VowTools = {
129
- /**
130
- * Vow-tolerant implementation of Promise.all that takes an iterable of vows
131
- * and other {@link Passable}s and returns a single {@link Vow}. It resolves
132
- * with an array of values when all of the input's promises or vows are
133
- * fulfilled and rejects when any of the input's promises or vows are rejected
134
- * with the first rejection reason.
135
- */
136
- all: <TS extends readonly unknown[]>(
137
- maybeVows: TS,
138
- ) => Vow<{
139
- [K in keyof TS]: Fulfilled<TS[K]>;
140
- }>;
141
- /**
142
- * Vow-tolerant
143
- * implementation of Promise.allSettled that takes an iterable of vows and other
144
- * {@link Passable}s and returns a single {@link Vow}. It resolves when all of
145
- * the input's promises or vows are settled with an array of settled outcome
146
- * objects.
147
- */
148
- allSettled: <TS extends readonly unknown[]>(
149
- maybeVows: TS,
150
- ) => Vow<{
151
- [K in keyof TS]: PromiseSettledResult<Fulfilled<TS[K]>>;
152
- }>;
153
- /**
154
- * @deprecated use `all`
155
- */
156
- allVows: <TS extends readonly unknown[]>(
157
- maybeVows: TS,
158
- ) => Vow<{
159
- [K in keyof TS]: Fulfilled<TS[K]>;
160
- }>;
161
- /**
162
- * Convert a vow or promise to a promise, ensuring proper handling of ephemeral promises.
163
- */
164
- asPromise: AsPromiseFunction;
165
- /**
166
- * Helper function that
167
- * coerces the result of a function to a Vow. Helpful for scenarios like a
168
- * synchronously thrown error.
169
- */
170
- asVow: <T>(
171
- fn: (...args: any[]) => Vow<Awaited<T>> | Awaited<T> | PromiseVow<T>,
172
- ) => Vow<Awaited<T>>;
173
- makeVowKit: <T>() => VowKit<T>;
174
- retryable: RetryableTool;
175
- /**
176
- * @deprecated use `retryable`
177
- */
178
- retriable: RetryableTool;
179
- watch: <T = any, TResult1 = T, TResult2 = never, C extends any[] = any[]>(
180
- specimenP: EVow<T>,
181
- watcher?: Watcher<T, TResult1, TResult2, C> | undefined,
182
- ...watcherArgs: C
183
- ) => Vow<
184
- Exclude<TResult1, void> | Exclude<TResult2, void> extends never
185
- ? TResult1
186
- : Exclude<TResult1, void> | Exclude<TResult2, void>
187
- >;
188
- /**
189
- * Shorten `specimenP` until we achieve a final result.
190
- *
191
- * Does not survive upgrade (even if specimenP is a durable Vow).
192
- *
193
- * Use only if the Vow will resolve _promptly_ {@see {@link @agoric/swingset-vat/docs/async.md}}.
194
- */
195
- when: <T, TResult1 = EUnwrap<T>, TResult2 = never>(
196
- specimenP: T,
197
- onFulfilled?:
198
- | ((value: EUnwrap<T>) => TResult1 | PromiseLike<TResult1>)
199
- | undefined,
200
- onRejected?:
201
- | ((reason: any) => TResult2 | PromiseLike<TResult2>)
202
- | undefined,
203
- ) => Promise<TResult1 | TResult2>;
204
- };