@agoric/vow 0.1.1-dev-9986152.0 → 0.1.1-dev-aedfac6.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/README.md +19 -13
- package/package.json +4 -4
- package/src/index.d.ts +2 -1
- package/src/index.d.ts.map +1 -1
- package/src/index.js +8 -1
- package/src/tools.d.ts +2 -2
- package/src/tools.d.ts.map +1 -1
- package/src/tools.js +3 -3
- package/vat.js +11 -5
package/README.md
CHANGED
|
@@ -26,12 +26,12 @@ Here they are: {
|
|
|
26
26
|
}
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
You can use `heapVowE` exported from `@agoric/vow`, which converts a chain of
|
|
30
|
+
promises and vows to a promise for its final fulfilment, by unwrapping any
|
|
31
|
+
intermediate vows:
|
|
32
32
|
|
|
33
33
|
```js
|
|
34
|
-
import {
|
|
34
|
+
import { heapVowE as E } from '@agoric/vow';
|
|
35
35
|
[...]
|
|
36
36
|
const a = await E.when(w1);
|
|
37
37
|
const b = await E(w2).something(...args);
|
|
@@ -40,12 +40,13 @@ const b = await E(w2).something(...args);
|
|
|
40
40
|
|
|
41
41
|
## Vow Producer
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
Use the following to create and resolve a vow:
|
|
44
44
|
|
|
45
45
|
```js
|
|
46
|
-
// CAVEAT: `
|
|
46
|
+
// CAVEAT: `heapVow*` uses internal ephemeral promises, so while it is convenient,
|
|
47
47
|
// it cannot be used by upgradable vats. See "Durability" below:
|
|
48
|
-
import {
|
|
48
|
+
import { heapVowE, heapVowTools } from '@agoric/vow';
|
|
49
|
+
const { makeVowKit } = heapVowTools;
|
|
49
50
|
[...]
|
|
50
51
|
const { resolver, vow } = makeVowKit();
|
|
51
52
|
// Send vow to a potentially different vat.
|
|
@@ -56,15 +57,15 @@ resolver.resolve('now you know the answer');
|
|
|
56
57
|
|
|
57
58
|
## Durability
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
mechanism. To create vow tools that deal with durable objects:
|
|
60
|
+
By default, the `@agoric/vow` module allows vows to integrate with Agoric's vat
|
|
61
|
+
upgrade mechanism. To create vow tools that deal with durable objects:
|
|
61
62
|
|
|
62
63
|
```js
|
|
63
64
|
// NOTE: Cannot use `V` as it has non-durable internal state when unwrapping
|
|
64
65
|
// vows. Instead, use the default vow-exposing `E` with the `watch`
|
|
65
66
|
// operator.
|
|
66
67
|
import { E } from '@endo/far';
|
|
67
|
-
import { prepareVowTools } from '@agoric/vow
|
|
68
|
+
import { prepareVowTools } from '@agoric/vow';
|
|
68
69
|
import { makeDurableZone } from '@agoric/zone';
|
|
69
70
|
|
|
70
71
|
// Only do the following once at the start of a new vat incarnation:
|
|
@@ -94,20 +95,25 @@ final result:
|
|
|
94
95
|
// that may not be side-effect free.
|
|
95
96
|
let result = await specimenP;
|
|
96
97
|
let vowInternals = getVowInternals(result);
|
|
98
|
+
let disconnectionState = undefined;
|
|
97
99
|
// Loop until the result is no longer a vow.
|
|
98
100
|
while (vowInternals) {
|
|
99
101
|
try {
|
|
100
|
-
|
|
102
|
+
// WARNING: Do not use `shorten()` in your own code. This is an example
|
|
103
|
+
// for didactic purposes only.
|
|
104
|
+
const shortened = await E(vowInternals.vowV0).shorten();
|
|
101
105
|
const nextInternals = getVowInternals(shortened);
|
|
102
106
|
// Atomically update the state.
|
|
103
107
|
result = shortened;
|
|
104
108
|
vowInternals = nextInternals;
|
|
105
109
|
} catch (e) {
|
|
106
|
-
|
|
110
|
+
const nextDisconnectionState = isDisconnectionReason(e, disconnectionState);
|
|
111
|
+
if (!nextDisconnectionState) {
|
|
107
112
|
// Not a disconnect, so abort.
|
|
108
113
|
throw e;
|
|
109
114
|
}
|
|
110
|
-
// It was a disconnect, so try again with the
|
|
115
|
+
// It was a disconnect, so try again with the updated state.
|
|
116
|
+
disconnectionState = nextDisconnectionState;
|
|
111
117
|
}
|
|
112
118
|
}
|
|
113
119
|
return result;
|
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-aedfac6.0+aedfac6",
|
|
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-aedfac6.0+aedfac6",
|
|
24
|
+
"@agoric/internal": "0.3.3-dev-aedfac6.0+aedfac6",
|
|
25
25
|
"@endo/env-options": "^1.1.5",
|
|
26
26
|
"@endo/errors": "^1.2.4",
|
|
27
27
|
"@endo/eventual-send": "^1.2.4",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"typeCoverage": {
|
|
57
57
|
"atLeast": 89.93
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "aedfac6ea5fd276a4f64a327cad18d3633901547"
|
|
60
60
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export * from "
|
|
1
|
+
export * from "../vat.js";
|
|
2
2
|
export * from "./types.js";
|
|
3
3
|
export * from "@agoric/internal/src/types.js";
|
|
4
4
|
export { default as makeE } from "./E.js";
|
|
5
|
+
export type VowTools = import("./tools.js").VowTools;
|
|
5
6
|
export { VowShape, toPassableCap } from "./vow-utils.js";
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":";;;;uBASa,OAAO,YAAY,EAAE,QAAQ"}
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
// We default to the vat-compatible version of this package, which is easy to
|
|
4
|
+
// reconfigure if not running under SwingSet.
|
|
5
|
+
export * from '../vat.js';
|
|
3
6
|
export { default as makeE } from './E.js';
|
|
4
7
|
export { VowShape, toPassableCap } from './vow-utils.js';
|
|
5
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {import('./tools.js').VowTools} VowTools
|
|
11
|
+
*/
|
|
12
|
+
|
|
6
13
|
// eslint-disable-next-line import/export
|
|
7
14
|
export * from './types.js';
|
|
8
15
|
|
package/src/tools.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function prepareBasicVowTools(zone: Zone, powers?: {
|
|
2
2
|
isRetryableReason?: IsRetryableReason | undefined;
|
|
3
3
|
} | undefined): {
|
|
4
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>;
|
|
@@ -9,7 +9,7 @@ export function prepareVowTools(zone: Zone, powers?: {
|
|
|
9
9
|
asPromise: AsPromiseFunction;
|
|
10
10
|
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;
|
|
11
11
|
};
|
|
12
|
-
export type VowTools = ReturnType<typeof
|
|
12
|
+
export type VowTools = ReturnType<typeof prepareBasicVowTools>;
|
|
13
13
|
import type { Zone } from '@agoric/base-zone';
|
|
14
14
|
import type { IsRetryableReason } from './types.js';
|
|
15
15
|
import type { EVow } from './types.js';
|
package/src/tools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["tools.js"],"names":[],"mappings":"AAoBO,
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["tools.js"],"names":[],"mappings":"AAoBO,2CAJI,IAAI;;;;;;yBAwCF,KAAK,OAAO,CAAC,EAAE;oCAqB8U,GAAG;;gBArC3T,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;EA6BrG;uBAGa,UAAU,CAAC,OAAO,oBAAoB,CAAC;0BApE9B,mBAAmB;uCAC8B,YAAY;0BAAZ,YAAY;yBAAZ,YAAY;uCAAZ,YAAY"}
|
package/src/tools.js
CHANGED
|
@@ -18,7 +18,7 @@ import { makeWhen } from './when.js';
|
|
|
18
18
|
* @param {object} [powers]
|
|
19
19
|
* @param {IsRetryableReason} [powers.isRetryableReason]
|
|
20
20
|
*/
|
|
21
|
-
export const
|
|
21
|
+
export const prepareBasicVowTools = (zone, powers = {}) => {
|
|
22
22
|
const { isRetryableReason = /** @type {IsRetryableReason} */ (() => false) } =
|
|
23
23
|
powers;
|
|
24
24
|
const makeVowKit = prepareVowKit(zone);
|
|
@@ -72,6 +72,6 @@ export const prepareVowTools = (zone, powers = {}) => {
|
|
|
72
72
|
retriable,
|
|
73
73
|
});
|
|
74
74
|
};
|
|
75
|
-
harden(
|
|
75
|
+
harden(prepareBasicVowTools);
|
|
76
76
|
|
|
77
|
-
/** @typedef {ReturnType<typeof
|
|
77
|
+
/** @typedef {ReturnType<typeof prepareBasicVowTools>} VowTools */
|
package/vat.js
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
// @ts-check
|
|
8
8
|
import { isUpgradeDisconnection } from '@agoric/internal/src/upgrade-api.js';
|
|
9
9
|
import { makeHeapZone } from '@agoric/base-zone/heap.js';
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
import { prepareBasicVowTools } from './src/tools.js';
|
|
12
|
+
import makeE from './src/E.js';
|
|
11
13
|
|
|
12
14
|
/** @type {import('./src/types.js').IsRetryableReason} */
|
|
13
15
|
const isRetryableReason = (reason, priorRetryValue) => {
|
|
@@ -28,13 +30,17 @@ export const defaultPowers = harden({
|
|
|
28
30
|
/**
|
|
29
31
|
* Produce SwingSet-compatible vowTools, with an arbitrary Zone type
|
|
30
32
|
*
|
|
31
|
-
* @type {typeof
|
|
33
|
+
* @type {typeof prepareBasicVowTools}
|
|
32
34
|
*/
|
|
33
35
|
export const prepareSwingsetVowTools = (zone, powers = {}) =>
|
|
34
|
-
|
|
36
|
+
prepareBasicVowTools(zone, { ...defaultPowers, ...powers });
|
|
37
|
+
harden(prepareSwingsetVowTools);
|
|
35
38
|
|
|
36
|
-
/**
|
|
37
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Reexport as prepareVowTools, since that's the thing that people find easiest
|
|
41
|
+
* to reach.
|
|
42
|
+
*/
|
|
43
|
+
export { prepareSwingsetVowTools as prepareVowTools };
|
|
38
44
|
|
|
39
45
|
/**
|
|
40
46
|
* `vowTools` that are not durable, but are useful in non-durable clients that
|