@agoric/base-zone 0.1.1-dev-24f7f32.0 → 0.1.1-dev-459998d.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/base-zone",
3
- "version": "0.1.1-dev-24f7f32.0+24f7f32",
3
+ "version": "0.1.1-dev-459998d.0+459998d",
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-24f7f32.0+24f7f32",
30
+ "@agoric/store": "0.9.3-dev-459998d.0+459998d",
31
31
  "@endo/common": "^1.2.1",
32
32
  "@endo/exo": "^1.4.0",
33
33
  "@endo/far": "^1.1.1",
@@ -58,5 +58,5 @@
58
58
  "typeCoverage": {
59
59
  "atLeast": 88.55
60
60
  },
61
- "gitHead": "24f7f32495a6eda13fd75d18620ab9f7989b5d2e"
61
+ "gitHead": "459998d3944d5ad9d495de146a6322aedcdd06d0"
62
62
  }
package/src/heap.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"heap.d.ts","sourceRoot":"","sources":["heap.js"],"names":[],"mappings":"AAkCO,8DAFM,OAAO,YAAY,EAAE,IAAI,CA2BrC"}
1
+ {"version":3,"file":"heap.d.ts","sourceRoot":"","sources":["heap.js"],"names":[],"mappings":"AAmCO,8DAFM,OAAO,YAAY,EAAE,IAAI,CA4BrC"}
package/src/heap.js CHANGED
@@ -12,6 +12,7 @@ import {
12
12
 
13
13
  import { makeOnceKit } from './make-once.js';
14
14
  import { agoricVatDataKeys as keys } from './keys.js';
15
+ import { watchPromise } from './watch-promise.js';
15
16
 
16
17
  /**
17
18
  * @type {import('./types.js').Stores}
@@ -49,6 +50,7 @@ export const makeHeapZone = (baseLabel = 'heapZone') => {
49
50
  subZone: wrapProvider(makeSubZone),
50
51
 
51
52
  makeOnce,
53
+ watchPromise,
52
54
  detached: detachedHeapStores.detached,
53
55
  isStorable: detachedHeapStores.isStorable,
54
56
 
package/src/index.d.ts CHANGED
@@ -2,4 +2,5 @@ export * from "./exports.js";
2
2
  export * from "./make-once.js";
3
3
  export * from "./keys.js";
4
4
  export * from "./is-passable.js";
5
+ export * from "./watch-promise.js";
5
6
  //# sourceMappingURL=index.d.ts.map
package/src/index.js CHANGED
@@ -10,3 +10,4 @@ export * from './exports.js';
10
10
  export * from './make-once.js';
11
11
  export * from './keys.js';
12
12
  export * from './is-passable.js';
13
+ export * from './watch-promise.js';
package/src/types.d.ts CHANGED
@@ -26,6 +26,10 @@ export type ExoZone = {
26
26
  * create a new Zone that can be passed to untrusted consumers without exposing the storage of the parent zone
27
27
  */
28
28
  subZone: (label: string, options?: StoreOptions) => Zone;
29
+ /**
30
+ * register a promise watcher created by this zone
31
+ */
32
+ watchPromise: typeof watchPromise;
29
33
  };
30
34
  export type Stores = {
31
35
  /**
@@ -56,4 +60,5 @@ export type Stores = {
56
60
  import { makeExo } from '@endo/exo';
57
61
  import { defineExoClass } from '@endo/exo';
58
62
  import { defineExoClassKit } from '@endo/exo';
63
+ import { watchPromise } from './watch-promise.js';
59
64
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.js"],"names":[],"mappings":"4BAMc,UAAU,GAAG,aAAa,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM;wBACrD,MAAM,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EAAE,CAAC;;;;;mBAGnD,OAAO,GAAG,MAAM;;;;;SAMf,OAAO,OAAO;;;;cACd,OAAO,cAAc;;;;iBACrB,OAAO,iBAAiB;;;;cACxB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAA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KnB,MAAM,MAAM;;;;gBACZ,CAAC,QAAQ,EAAE,OAAO,KAAK,OAAO;;;;cAC9B,CAAC,CAAC,EAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,KAAK,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;;;;cAC9D,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC;;;;kBACzD,CAAC,CAAC,EAAC,CAAC,EACjB,KAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,KAAK,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;;;;kBAEnD,CAAC,CAAC,EACf,KAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,KAAK,YAAY,CAAC,CAAC,CAAC;;wBAnCH,WAAW;+BAAX,WAAW;kCAAX,WAAW;6BAEzC,oBAAoB"}
package/src/types.js CHANGED
@@ -1,5 +1,7 @@
1
1
  // eslint-disable-next-line no-unused-vars
2
2
  import { makeExo, defineExoClass, defineExoClassKit } from '@endo/exo';
3
+ // eslint-disable-next-line no-unused-vars
4
+ import { watchPromise } from './watch-promise.js';
3
5
 
4
6
  // Ensure this is a module.
5
7
  export {};
@@ -19,6 +21,7 @@ export {};
19
21
  * @property {typeof defineExoClassKit} exoClassKit create a "kit" maker function that can be used to create a record of exo-objects sharing the same state
20
22
  * @property {<T>(key: string, maker: (key: string) => T) => T} makeOnce create or retrieve a singleton object bound to this zone
21
23
  * @property {(label: string, options?: StoreOptions) => Zone} subZone create a new Zone that can be passed to untrusted consumers without exposing the storage of the parent zone
24
+ * @property {typeof watchPromise} watchPromise register a promise watcher created by this zone
22
25
  */
23
26
 
24
27
  /**
@@ -0,0 +1,29 @@
1
+ /**
2
+ * A PromiseWatcher method guard callable with or more arguments, returning void.
3
+ */
4
+ export const PromiseWatcherHandler: import("@endo/patterns").MethodGuard;
5
+ /**
6
+ * A PromiseWatcher interface that has both onFulfilled and onRejected handlers.
7
+ */
8
+ export const PromiseWatcherI: import("@endo/patterns").InterfaceGuard<{
9
+ onFulfilled: import("@endo/patterns").MethodGuard;
10
+ onRejected: import("@endo/patterns").MethodGuard;
11
+ }>;
12
+ /**
13
+ * A PromiseWatcher interface that has only an onFulfilled handler.
14
+ */
15
+ export const PromiseWatcherFulfilledI: import("@endo/patterns").InterfaceGuard<{
16
+ onFulfilled: import("@endo/patterns").MethodGuard;
17
+ }>;
18
+ /**
19
+ * A PromiseWatcher interface that has only an onRejected handler.
20
+ */
21
+ export const PromiseWatcherRejectedI: import("@endo/patterns").InterfaceGuard<{
22
+ onRejected: import("@endo/patterns").MethodGuard;
23
+ }>;
24
+ export function watchPromise(p: Promise<any>, watcher: PromiseWatcher, ...watcherArgs: unknown[]): void;
25
+ export type PromiseWatcher = {
26
+ onFulfilled?: ((fulfilment: unknown, ...args: unknown[]) => void) | undefined;
27
+ onRejected?: ((reason: unknown, ...args: unknown[]) => void) | undefined;
28
+ };
29
+ //# sourceMappingURL=watch-promise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watch-promise.d.ts","sourceRoot":"","sources":["watch-promise.js"],"names":[],"mappings":"AAQA;;GAEG;AACH,yEAA6E;AAE7E;;GAEG;AACH;;;GAGG;AAEH;;GAEG;AACH;;GAEG;AAEH;;GAEG;AACH;;GAEG;AAuCI,gCALI,OAAO,CAAC,GAAG,CAAC,WACZ,cAAc,kBACX,OAAO,KACR,IAAI,CAUhB;;gCA3C0B,OAAO,WAAW,OAAO,EAAE,KAAK,IAAI;2BACxC,OAAO,WAAW,OAAO,EAAE,KAAK,IAAI"}
@@ -0,0 +1,82 @@
1
+ // @ts-check
2
+ import { M } from '@endo/patterns';
3
+ import { E } from '@endo/far';
4
+
5
+ const { Fail } = assert;
6
+
7
+ const { apply } = Reflect;
8
+
9
+ /**
10
+ * A PromiseWatcher method guard callable with or more arguments, returning void.
11
+ */
12
+ export const PromiseWatcherHandler = M.call(M.any()).rest(M.any()).returns();
13
+
14
+ /**
15
+ * A PromiseWatcher interface that has both onFulfilled and onRejected handlers.
16
+ */
17
+ export const PromiseWatcherI = M.interface('PromiseWatcher', {
18
+ onFulfilled: PromiseWatcherHandler,
19
+ onRejected: PromiseWatcherHandler,
20
+ });
21
+
22
+ /**
23
+ * A PromiseWatcher interface that has only an onFulfilled handler.
24
+ */
25
+ export const PromiseWatcherFulfilledI = M.interface('PromiseWatcherFulfilled', {
26
+ onFulfilled: PromiseWatcherHandler,
27
+ });
28
+
29
+ /**
30
+ * A PromiseWatcher interface that has only an onRejected handler.
31
+ */
32
+ export const PromiseWatcherRejectedI = M.interface('PromiseWatcherRejected', {
33
+ onRejected: PromiseWatcherHandler,
34
+ });
35
+
36
+ /**
37
+ * @typedef {object} PromiseWatcher
38
+ * @property {(fulfilment: unknown, ...args: unknown[]) => void} [onFulfilled]
39
+ * @property {(reason: unknown, ...args: unknown[]) => void} [onRejected]
40
+ */
41
+
42
+ /**
43
+ * Adapt a promise watcher method to E.when.
44
+ * @param {Record<PropertyKey, (...args: unknown[]) => unknown>} that
45
+ * @param {PropertyKey} prop
46
+ * @param {unknown[]} postArgs
47
+ */
48
+ const callMeMaybe = (that, prop, postArgs) => {
49
+ const fn = that[prop];
50
+ if (!fn) {
51
+ return undefined;
52
+ }
53
+ assert.typeof(fn, 'function');
54
+ /**
55
+ * @param {unknown} arg value or reason
56
+ */
57
+ const wrapped = arg => {
58
+ // Don't return a value, to prevent E.when from subscribing to a resulting
59
+ // promise.
60
+ apply(fn, that, [arg, ...postArgs]);
61
+ };
62
+ return wrapped;
63
+ };
64
+
65
+ /**
66
+ * Shim the promise watcher behaviour when VatData.watchPromise is not available.
67
+ *
68
+ * @param {Promise<any>} p
69
+ * @param {PromiseWatcher} watcher
70
+ * @param {...unknown} watcherArgs
71
+ * @returns {void}
72
+ */
73
+ export const watchPromise = (p, watcher, ...watcherArgs) => {
74
+ Promise.resolve(p) === p || Fail`watchPromise only watches promises`;
75
+ const onFulfilled = callMeMaybe(watcher, 'onFulfilled', watcherArgs);
76
+ const onRejected = callMeMaybe(watcher, 'onRejected', watcherArgs);
77
+ onFulfilled ||
78
+ onRejected ||
79
+ Fail`promise watcher must implement at least one handler method`;
80
+ void E.when(p, onFulfilled, onRejected);
81
+ };
82
+ harden(watchPromise);