@agoric/async-flow 0.1.1-upgrade-17-dev-ec448b0.0 → 0.1.1-upgrade-18-dev-d7c994b.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +0 -28
  2. package/docs/async-flow-states.key +0 -0
  3. package/docs/async-flow-states.md +2 -1
  4. package/docs/async-flow-states.png +0 -0
  5. package/index.d.ts +1 -2
  6. package/index.js +1 -2
  7. package/package.json +18 -19
  8. package/src/async-flow.d.ts.map +1 -1
  9. package/src/async-flow.js +47 -3
  10. package/src/endowments.d.ts +0 -1
  11. package/src/endowments.d.ts.map +1 -1
  12. package/src/endowments.js +7 -35
  13. package/src/equate.d.ts.map +1 -1
  14. package/src/equate.js +16 -8
  15. package/src/log-store.d.ts +39 -2
  16. package/src/log-store.d.ts.map +1 -1
  17. package/src/log-store.js +121 -22
  18. package/src/replay-membrane.d.ts +23 -4
  19. package/src/replay-membrane.d.ts.map +1 -1
  20. package/src/replay-membrane.js +61 -35
  21. package/src/type-guards.d.ts.map +1 -1
  22. package/src/type-guards.js +1 -0
  23. package/src/types-index.d.ts +2 -0
  24. package/src/types.d.ts +86 -166
  25. package/src/types.d.ts.map +1 -0
  26. package/src/types.ts +213 -0
  27. package/test/_utils.js +22 -0
  28. package/test/async-flow-crank.test.js +4 -6
  29. package/test/async-flow-early-completion.test.js +28 -8
  30. package/test/async-flow-no-this.js +2 -4
  31. package/test/async-flow.test.js +13 -5
  32. package/test/bad-host.test.js +13 -3
  33. package/test/endowments.test.js +22 -2
  34. package/test/equate.test.js +5 -5
  35. package/test/exports.test.js +8 -0
  36. package/test/log-store.test.js +46 -11
  37. package/test/prepare-test-env-ava.js +2 -20
  38. package/test/replay-membrane-eventual.test.js +97 -41
  39. package/test/snapshots/exports.test.js.md +14 -0
  40. package/test/snapshots/exports.test.js.snap +0 -0
  41. package/tsconfig.build.tsbuildinfo +1 -0
  42. package/tsconfig.json +0 -3
  43. /package/src/{types.js → types-index.js} +0 -0
@@ -1,4 +1,4 @@
1
- export function makeReplayMembrane({ log, bijection, vowTools, watchWake, panic, }: {
1
+ export function makeReplayMembrane(arg: {
2
2
  log: LogStore;
3
3
  bijection: Bijection;
4
4
  vowTools: VowTools;
@@ -9,13 +9,31 @@ export function makeReplayMembrane({ log, bijection, vowTools, watchWake, panic,
9
9
  guestToHost: (specimen: Passable, label?: string | undefined) => any;
10
10
  wake: () => void;
11
11
  stop: () => void;
12
- } & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {
12
+ } & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & RemotableBrand<{}, {
13
13
  hostToGuest: (specimen: Passable, label?: string | undefined) => any;
14
14
  guestToHost: (specimen: Passable, label?: string | undefined) => any;
15
15
  wake: () => void;
16
16
  stop: () => void;
17
17
  }>;
18
- export type ReplayMembrane = ReturnType<({ log, bijection, vowTools, watchWake, panic, }: {
18
+ export function makeReplayMembraneForTesting({ log, bijection, vowTools, watchWake, panic, __eventualSendForTesting, }: {
19
+ log: LogStore;
20
+ bijection: Bijection;
21
+ vowTools: VowTools;
22
+ watchWake: (vowish: Promise<any> | Vow) => void;
23
+ panic: (problem: Error) => never;
24
+ __eventualSendForTesting?: boolean | undefined;
25
+ }): {
26
+ hostToGuest: (specimen: Passable, label?: string | undefined) => any;
27
+ guestToHost: (specimen: Passable, label?: string | undefined) => any;
28
+ wake: () => void;
29
+ stop: () => void;
30
+ } & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & RemotableBrand<{}, {
31
+ hostToGuest: (specimen: Passable, label?: string | undefined) => any;
32
+ guestToHost: (specimen: Passable, label?: string | undefined) => any;
33
+ wake: () => void;
34
+ stop: () => void;
35
+ }>;
36
+ export type ReplayMembrane = ReturnType<(arg: {
19
37
  log: LogStore;
20
38
  bijection: Bijection;
21
39
  vowTools: VowTools;
@@ -26,7 +44,7 @@ export type ReplayMembrane = ReturnType<({ log, bijection, vowTools, watchWake,
26
44
  guestToHost: (specimen: Passable, label?: string | undefined) => any;
27
45
  wake: () => void;
28
46
  stop: () => void;
29
- } & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, {
47
+ } & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & RemotableBrand<{}, {
30
48
  hostToGuest: (specimen: Passable, label?: string | undefined) => any;
31
49
  guestToHost: (specimen: Passable, label?: string | undefined) => any;
32
50
  wake: () => void;
@@ -37,4 +55,5 @@ import type { Bijection } from '../src/bijection.js';
37
55
  import type { VowTools } from '@agoric/vow';
38
56
  import type { Vow } from '@agoric/vow';
39
57
  import type { Passable } from '@endo/pass-style';
58
+ import type { RemotableBrand } from '@endo/eventual-send';
40
59
  //# sourceMappingURL=replay-membrane.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"replay-membrane.d.ts","sourceRoot":"","sources":["replay-membrane.js"],"names":[],"mappings":"AA8BO,oFANJ;IAAsB,GAAG,EAAjB,QAAQ;IACO,SAAS,EAAxB,SAAS;IACK,QAAQ,EAAtB,QAAQ;IAC6B,SAAS,EAA9C,CAAC,MAAM,EAAE,eAAU,GAAG,KAAK,IAAI;IACA,KAAK,EAApC,CAAC,OAAO,EAAE,KAAK,KAAK,KAAK;CACnC;;;;;;;;;;GAmpBA;6BAGa,UAAU,mDA3pBrB;IAAsB,GAAG,EAAjB,QAAQ;IACO,SAAS,EAAxB,SAAS;IACK,QAAQ,EAAtB,QAAQ;IAC6B,SAAS,EAA9C,CAAC,MAAM,EAAE,eAAU,GAAG,KAAK,IAAI;IACA,KAAK,EAApC,CAAC,OAAO,EAAE,KAAK,KAAK,KAAK;CACnC;;;;;;;;;;GAspB2C;8BApqBjB,qBAAqB;+BACpB,qBAAqB;8BAFT,aAAa;yBAAb,aAAa;8BADD,kBAAkB"}
1
+ {"version":3,"file":"replay-membrane.d.ts","sourceRoot":"","sources":["replay-membrane.js"],"names":[],"mappings":"AA+BO,wCANJ;IAAsB,GAAG,EAAjB,QAAQ;IACO,SAAS,EAAxB,SAAS;IACK,QAAQ,EAAtB,QAAQ;IAC6B,SAAS,EAA9C,CAAC,MAAM,EAAE,eAAU,GAAG,KAAK,IAAI;IACA,KAAK,EAApC,CAAC,OAAO,EAAE,KAAK,KAAK,KAAK;CACnC;;;;;;;;;;GAMA;AAWM,wHAPJ;IAAsB,GAAG,EAAjB,QAAQ;IACO,SAAS,EAAxB,SAAS;IACK,QAAQ,EAAtB,QAAQ;IAC6B,SAAS,EAA9C,CAAC,MAAM,EAAE,eAAU,GAAG,KAAK,IAAI;IACA,KAAK,EAApC,CAAC,OAAO,EAAE,KAAK,KAAK,KAAK;IACX,wBAAwB;CAChD;;;;;;;;;;GA4pBA;6BAGa,UAAU,OAprBrB;IAAsB,GAAG,EAAjB,QAAQ;IACO,SAAS,EAAxB,SAAS;IACK,QAAQ,EAAtB,QAAQ;IAC6B,SAAS,EAA9C,CAAC,MAAM,EAAE,eAAU,GAAG,KAAK,IAAI;IACA,KAAK,EAApC,CAAC,OAAO,EAAE,KAAK,KAAK,KAAK;CACnC;;;;;;;;;;GA+qB2C;8BA7rBjB,qBAAqB;+BACpB,qBAAqB;8BAFT,aAAa;yBAAb,aAAa;8BADH,kBAAkB;oCADnC,qBAAqB"}
@@ -10,9 +10,10 @@ import { makeConvertKit } from './convert.js';
10
10
  import { makeEquate } from './equate.js';
11
11
 
12
12
  /**
13
- * @import {PromiseKit} from '@endo/promise-kit'
14
- * @import {Passable, PassableCap, CopyTagged} from '@endo/pass-style'
15
- * @import {Vow, VowTools, VowKit} from '@agoric/vow'
13
+ * @import {PromiseKit} from '@endo/promise-kit';
14
+ * @import {RemotableBrand} from '@endo/eventual-send';
15
+ * @import {Callable, Passable, PassableCap} from '@endo/pass-style';
16
+ * @import {Vow, VowTools, VowKit} from '@agoric/vow';
16
17
  * @import {LogStore} from '../src/log-store.js';
17
18
  * @import {Bijection} from '../src/bijection.js';
18
19
  * @import {Host, HostVow, LogEntry, Outcome} from '../src/types.js';
@@ -28,12 +29,29 @@ const { fromEntries, defineProperties, assign } = Object;
28
29
  * @param {(vowish: Promise | Vow) => void} arg.watchWake
29
30
  * @param {(problem: Error) => never} arg.panic
30
31
  */
31
- export const makeReplayMembrane = ({
32
+ export const makeReplayMembrane = arg => {
33
+ const noDunderArg = /** @type {typeof arg} */ (
34
+ Object.fromEntries(Object.entries(arg).filter(([k]) => !k.startsWith('__')))
35
+ );
36
+ return makeReplayMembraneForTesting(noDunderArg);
37
+ };
38
+
39
+ /**
40
+ * @param {object} arg
41
+ * @param {LogStore} arg.log
42
+ * @param {Bijection} arg.bijection
43
+ * @param {VowTools} arg.vowTools
44
+ * @param {(vowish: Promise | Vow) => void} arg.watchWake
45
+ * @param {(problem: Error) => never} arg.panic
46
+ * @param {boolean} [arg.__eventualSendForTesting] CAVEAT: Only for async-flow tests
47
+ */
48
+ export const makeReplayMembraneForTesting = ({
32
49
  log,
33
50
  bijection,
34
51
  vowTools,
35
52
  watchWake,
36
53
  panic,
54
+ __eventualSendForTesting,
37
55
  }) => {
38
56
  const { when, makeVowKit } = vowTools;
39
57
 
@@ -45,6 +63,13 @@ export const makeReplayMembrane = ({
45
63
 
46
64
  const Panic = (template, ...args) => panic(makeError(X(template, ...args)));
47
65
 
66
+ const startGeneration = generation => {
67
+ Number.isSafeInteger(generation) ||
68
+ Fail`generation expected integer; got ${generation}`;
69
+ generation >= 0 ||
70
+ Fail`generation expected non-negative; got ${generation}`;
71
+ };
72
+
48
73
  // ////////////// Host or Interpreter to Guest ///////////////////////////////
49
74
 
50
75
  /**
@@ -218,30 +243,22 @@ export const makeReplayMembrane = ({
218
243
  // //////////////// Eventual Send ////////////////////////////////////////////
219
244
 
220
245
  /**
221
- * @param {PassableCap} hostTarget
246
+ * @param {RemotableBrand<PassableCap, Callable>} hostTarget
222
247
  * @param {string | undefined} optVerb
223
248
  * @param {Passable[]} hostArgs
224
249
  */
225
250
  const performSendOnly = (hostTarget, optVerb, hostArgs) => {
226
251
  try {
227
- optVerb
228
- ? heapVowE.sendOnly(hostTarget)[optVerb](...hostArgs)
229
- : // eslint-disable-next-line @typescript-eslint/ban-ts-comment
230
- // @ts-ignore once we changed this from E to heapVowE,
231
- // typescript started complaining that heapVowE(hostTarget)
232
- // is not callable. I'm not sure if this is a just a typing bug
233
- // in heapVowE or also reflects a runtime deficiency. But this
234
- // case it not used yet anyway. We disable it
235
- // with at-ts-ignore rather than at-ts-expect-error because
236
- // the dependency-graph tests complains that the latter is unused.
237
- heapVowE.sendOnly(hostTarget)(...hostArgs);
252
+ optVerb === undefined
253
+ ? heapVowE.sendOnly(hostTarget)(...hostArgs)
254
+ : heapVowE.sendOnly(hostTarget)[optVerb](...hostArgs);
238
255
  } catch (hostProblem) {
239
- throw Panic`internal: eventual sendOnly synchrously failed ${hostProblem}`;
256
+ throw Panic`internal: eventual sendOnly synchronously failed ${hostProblem}`;
240
257
  }
241
258
  };
242
259
 
243
260
  /**
244
- * @param {PassableCap} hostTarget
261
+ * @param {RemotableBrand<PassableCap, Callable>} hostTarget
245
262
  * @param {string | undefined} optVerb
246
263
  * @param {Passable[]} hostArgs
247
264
  * @param {number} callIndex
@@ -259,22 +276,16 @@ export const makeReplayMembrane = ({
259
276
  ) => {
260
277
  const { vow, resolver } = hostResultKit;
261
278
  try {
262
- const hostPromise = optVerb
263
- ? heapVowE(hostTarget)[optVerb](...hostArgs)
264
- : // eslint-disable-next-line @typescript-eslint/ban-ts-comment
265
- // @ts-ignore once we changed this from E to heapVowE,
266
- // typescript started complaining that heapVowE(hostTarget)
267
- // is not callable. I'm not sure if this is a just a typing bug
268
- // in heapVowE or also reflects a runtime deficiency. But this
269
- // case it not used yet anyway. We disable it
270
- // with at-ts-ignore rather than at-ts-expect-error because
271
- // the dependency-graph tests complains that the latter is unused.
272
- heapVowE(hostTarget)(...hostArgs);
279
+ const hostPromise =
280
+ optVerb === undefined
281
+ ? heapVowE(hostTarget)(...hostArgs)
282
+ : heapVowE(hostTarget)[optVerb](...hostArgs);
273
283
  resolver.resolve(hostPromise); // TODO does this always work?
274
284
  } catch (hostProblem) {
275
- throw Panic`internal: eventual send synchrously failed ${hostProblem}`;
285
+ throw Panic`internal: eventual send synchronously failed ${hostProblem}`;
276
286
  }
277
287
  try {
288
+ /** @type {LogEntry} */
278
289
  const entry = harden(['doReturn', callIndex, vow]);
279
290
  log.pushEntry(entry);
280
291
  const guestPromise = makeGuestForHostVow(vow, guestReturnedP);
@@ -293,6 +304,10 @@ export const makeReplayMembrane = ({
293
304
 
294
305
  const guestHandler = harden({
295
306
  applyMethodSendOnly(guestTarget, optVerb, guestArgs) {
307
+ __eventualSendForTesting ||
308
+ Panic`guest eventual applyMethodSendOnly not yet supported: ${guestTarget}.${b(optVerb)}`;
309
+ // The following code is only intended to be used by tests.
310
+ // TODO: properly support applyMethodSendOnly
296
311
  const callIndex = log.getIndex();
297
312
  if (stopped || !bijection.hasGuest(guestTarget)) {
298
313
  Fail`Sent from a previous run: ${guestTarget}`;
@@ -331,6 +346,10 @@ export const makeReplayMembrane = ({
331
346
  }
332
347
  },
333
348
  applyMethod(guestTarget, optVerb, guestArgs, guestReturnedP) {
349
+ __eventualSendForTesting ||
350
+ Panic`guest eventual applyMethod not yet supported: ${guestTarget}.${b(optVerb)} -> ${b(guestReturnedP)}`;
351
+ // The following code is only intended to be used by tests.
352
+ // TODO: properly support applyMethod
334
353
  const callIndex = log.getIndex();
335
354
  if (stopped || !bijection.hasGuest(guestTarget)) {
336
355
  Fail`Sent from a previous run: ${guestTarget}`;
@@ -398,6 +417,8 @@ export const makeReplayMembrane = ({
398
417
  }
399
418
  },
400
419
  applyFunctionSendOnly(guestTarget, guestArgs) {
420
+ __eventualSendForTesting ||
421
+ Panic`guest eventual applyFunctionSendOnly not yet supported: ${guestTarget}`;
401
422
  return guestHandler.applyMethodSendOnly(
402
423
  guestTarget,
403
424
  undefined,
@@ -405,6 +426,8 @@ export const makeReplayMembrane = ({
405
426
  );
406
427
  },
407
428
  applyFunction(guestTarget, guestArgs, guestReturnedP) {
429
+ __eventualSendForTesting ||
430
+ Panic`guest eventual applyFunction not yet supported: ${guestTarget} -> ${b(guestReturnedP)}`;
408
431
  return guestHandler.applyMethod(
409
432
  guestTarget,
410
433
  undefined,
@@ -413,9 +436,11 @@ export const makeReplayMembrane = ({
413
436
  );
414
437
  },
415
438
  getSendOnly(guestTarget, prop) {
439
+ // TODO: support getSendOnly
416
440
  throw Panic`guest eventual getSendOnly not yet supported: ${guestTarget}.${b(prop)}`;
417
441
  },
418
442
  get(guestTarget, prop, guestReturnedP) {
443
+ // TODO: support get
419
444
  throw Panic`guest eventual get not yet supported: ${guestTarget}.${b(prop)} -> ${b(guestReturnedP)}`;
420
445
  },
421
446
  });
@@ -585,21 +610,22 @@ export const makeReplayMembrane = ({
585
610
  // /////////////////////////////// Interpreter ///////////////////////////////
586
611
 
587
612
  /**
588
- * These are the only ones that are driven from the interpreter loop
613
+ * These are the only ones that are driven from the top level interpreter loop
589
614
  */
590
615
  const topDispatch = harden({
616
+ startGeneration,
591
617
  doFulfill,
592
618
  doReject,
593
619
  // doCall, // unimplemented in the current plan
594
620
  });
595
621
 
596
622
  /**
597
- * These are the only ones that are driven from the interpreter loop
623
+ * These are the only ones that are driven from the nested interpreter loop
598
624
  */
599
625
  const nestDispatch = harden({
600
- // doCall, // unimplemented in the current plan
601
626
  doReturn,
602
627
  doThrow,
628
+ // doCall, // unimplemented in the current plan
603
629
  });
604
630
 
605
631
  const interpretOne = (dispatch, [op, ...args]) => {
@@ -629,7 +655,7 @@ export const makeReplayMembrane = ({
629
655
  const nestInterpreter = callIndex => {
630
656
  callStack.push(callIndex);
631
657
  while (log.isReplaying() && !stopped) {
632
- const entry = log.nextEntry();
658
+ const entry = log.nextUnfilteredEntry();
633
659
  const optOutcome = interpretOne(nestDispatch, entry);
634
660
  if (unnestFlag) {
635
661
  optOutcome ||
@@ -670,7 +696,7 @@ export const makeReplayMembrane = ({
670
696
  if (!(op in topDispatch)) {
671
697
  return;
672
698
  }
673
- void log.nextEntry();
699
+ void log.nextUnfilteredEntry();
674
700
  interpretOne(topDispatch, entry);
675
701
  }
676
702
  };
@@ -1 +1 @@
1
- {"version":3,"file":"type-guards.d.ts","sourceRoot":"","sources":["type-guards.js"],"names":[],"mappings":"AAGA,8DAME;AAEF,gEAA6D;AAE7D,6DAsDE"}
1
+ {"version":3,"file":"type-guards.d.ts","sourceRoot":"","sources":["type-guards.js"],"names":[],"mappings":"AAGA,8DAME;AAEF,gEAA6D;AAE7D,6DAuDE"}
@@ -12,6 +12,7 @@ export const FlowStateShape = M.or(
12
12
  export const PropertyKeyShape = M.or(M.string(), M.symbol());
13
13
 
14
14
  export const LogEntryShape = M.or(
15
+ ['startGeneration', M.number()],
15
16
  // ////////////////////////////// From Host to Guest /////////////////////////
16
17
  ['doFulfill', VowShape, M.any()],
17
18
  ['doReject', VowShape, M.any()],
@@ -0,0 +1,2 @@
1
+ // Export all the types this package provides
2
+ export type * from './types.js';
package/src/types.d.ts CHANGED
@@ -3,14 +3,7 @@ import type { Vow, VowTools } from '@agoric/vow';
3
3
  import type { LogStore } from './log-store.js';
4
4
  import type { Bijection } from './bijection.js';
5
5
  import type { EndowmentTools } from './endowments.js';
6
-
7
- export type FlowState =
8
- | 'Running'
9
- | 'Sleeping'
10
- | 'Replaying'
11
- | 'Failed'
12
- | 'Done';
13
-
6
+ export type FlowState = 'Running' | 'Sleeping' | 'Replaying' | 'Failed' | 'Done';
14
7
  /**
15
8
  * `T` defaults to `any`, not `Passable`, because unwrapped guests include
16
9
  * non-passables, like unwrapped functions and unwrapped state records.
@@ -20,202 +13,129 @@ export type FlowState =
20
13
  */
21
14
  export type Guest<T extends unknown = any> = T;
22
15
  export type Host<T extends Passable = Passable> = T;
23
-
24
16
  /**
25
17
  * A HostVow must be durably storable. It corresponds to an
26
18
  * ephemeral guest promise.
27
19
  */
28
20
  export type HostVow<T extends Passable = Passable> = Host<Vow<T>>;
29
-
30
- export type GuestAsyncFunc = (
31
- ...activationArgs: Guest[]
32
- ) => Guest<Promise<any>>;
33
-
34
- export type HostAsyncFuncWrapper = (
35
- ...activationArgs: Host<any>[]
36
- ) => HostVow<any>;
37
-
21
+ export type GuestAsyncFunc = (...activationArgs: Guest[]) => Guest<Promise<any>>;
22
+ export type HostAsyncFuncWrapper = (...activationArgs: Host<any>[]) => HostVow<any>;
38
23
  /**
39
24
  * The function from the host as it will be available in the guest.
40
25
  *
41
26
  * Specifically, Vow return values are converted to Promises.
42
27
  */
43
- export type GuestOf<F extends HostAsyncFuncWrapper> = F extends (
44
- ...args: infer A
45
- ) => Vow<infer R>
46
- ? (...args: A) => Promise<R>
47
- : F;
48
-
49
- // from https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts
50
- type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
51
-
28
+ export type GuestOf<F extends HostAsyncFuncWrapper> = F extends (...args: infer A) => Vow<infer R> ? (...args: A) => Promise<R> : F;
29
+ type Simplify<T> = {
30
+ [KeyType in keyof T]: T[KeyType];
31
+ } & {};
52
32
  /**
53
33
  * Convert an entire Guest interface into what the host will implement.
54
34
  */
55
- type HostInterface<T> = {
56
- [K in keyof T]: T[K] extends CallableFunction
57
- ? HostOf<T[K]>
58
- : T[K] extends Record<string, any>
59
- ? Simplify<HostInterface<T[K]>>
60
- : T[K];
35
+ export type HostInterface<T> = {
36
+ [K in keyof T]: T[K] extends CallableFunction ? HostOf<T[K]> : T[K] extends Record<string, any> ? Simplify<HostInterface<T[K]>> : T[K];
61
37
  };
62
-
63
38
  /**
64
39
  * Convert an entire Host interface into what the Guest will receive.
65
40
  */
66
41
  export type GuestInterface<T> = {
67
- [K in keyof T]: T[K] extends (...args: any[]) => Vow<infer R>
68
- ? (...args: Parameters<T[K]>) => Promise<R>
69
- : T[K] extends HostAsyncFuncWrapper
70
- ? GuestOf<T[K]>
71
- : T[K] extends (...args: any[]) => infer R
72
- ? T[K]
73
- : T[K] extends object
74
- ? GuestInterface<T[K]>
75
- : T[K];
42
+ [K in keyof T]: T[K] extends (...args: any[]) => Vow<infer R> ? (...args: Parameters<T[K]>) => Promise<R> : T[K] extends HostAsyncFuncWrapper ? GuestOf<T[K]> : T[K] extends (...args: any[]) => infer R ? T[K] : T[K] extends object ? GuestInterface<T[K]> : T[K];
76
43
  };
77
-
78
44
  /**
79
45
  * The function the host must provide to match an interface the guest expects.
80
46
  *
81
47
  * Specifically, Promise return values are converted to Vows.
82
48
  */
83
- export type HostOf<F extends CallableFunction> = F extends (
84
- ...args: infer A
85
- ) => infer R
86
- ? R extends Promise<infer T>
87
- ? (...args: A) => Vow<T extends Passable ? T : HostInterface<T>>
88
- : (...args: A) => HostInterface<R>
89
- : F;
90
-
91
- export type HostArgs<GA extends any[]> = { [K in keyof GA]: HostOf<GA[K]> };
92
-
49
+ export type HostOf<F extends CallableFunction> = F extends (...args: infer A) => infer R ? R extends Promise<infer T> ? (...args: A) => Vow<T extends Passable ? T : HostInterface<T>> : (...args: A) => HostInterface<R> : F;
50
+ export type HostArgs<GA extends any[]> = {
51
+ [K in keyof GA]: HostOf<GA[K]>;
52
+ };
93
53
  export type PreparationOptions = {
94
- vowTools?: VowTools;
95
- makeLogStore?: (() => LogStore) | undefined;
96
- makeBijection?: (() => Bijection) | undefined;
97
- endowmentTools?: EndowmentTools;
54
+ vowTools?: VowTools;
55
+ makeLogStore?: (() => LogStore) | undefined;
56
+ makeBijection?: (() => Bijection) | undefined;
57
+ endowmentTools?: EndowmentTools;
58
+ panicHandler?: (e: any) => void;
98
59
  };
99
60
  export type OutcomeKind = 'return' | 'throw';
100
-
101
- export type Outcome =
102
- | {
103
- kind: 'return';
104
- result: any;
105
- }
106
- | {
107
- kind: 'throw';
108
- problem: any;
109
- };
110
-
61
+ export type Outcome = {
62
+ kind: 'return';
63
+ result: any;
64
+ } | {
65
+ kind: 'throw';
66
+ problem: any;
67
+ };
111
68
  export type Ephemera<S extends WeakKey = WeakKey, V extends unknown = any> = {
112
- for: (self: S) => V;
113
- resetFor: (self: S) => void;
69
+ for: (self: S) => V;
70
+ resetFor: (self: S) => void;
114
71
  };
115
-
116
72
  /**
117
73
  * This is the type alias for the membrane log entries we currently implement.
118
74
  *
119
75
  * @see {FutureLogEntry} below for the full membrane log entry, which we do not
120
76
  * yet support.
121
77
  */
122
- export type LogEntry =
123
- | [
124
- // ///////////////// From Host to Guest /////////////////////////
125
- op: 'doFulfill',
126
- vow: HostVow,
127
- fulfillment: Host,
128
- ]
129
- | [op: 'doReject', vow: HostVow, reason: Host]
130
- | [op: 'doReturn', callIndex: number, result: Host]
131
- | [op: 'doThrow', callIndex: number, problem: Host]
132
- | [
133
- // ///////////////////// From Guest to Host /////////////////////////
134
- op: 'checkCall',
135
- target: Host,
136
- optVerb: PropertyKey | undefined,
137
- args: Host[],
138
- callIndex: number,
139
- ]
140
- | [
141
- op: 'checkSendOnly',
142
- target: Host,
143
- optVerb: PropertyKey | undefined,
144
- args: Host[],
145
- callIndex: number,
146
- ]
147
- | [
148
- op: 'checkSend',
149
- target: Host,
150
- optVerb: PropertyKey | undefined,
151
- args: Host[],
152
- callIndex: number,
153
- ];
154
-
78
+ export type LogEntry = [op: 'startGeneration', generation: number] | [op: 'doFulfill', vow: HostVow, fulfillment: Host] | [op: 'doReject', vow: HostVow, reason: Host] | [op: 'doReturn', callIndex: number, result: Host] | [op: 'doThrow', callIndex: number, problem: Host] | [
79
+ op: 'checkCall',
80
+ target: Host,
81
+ optVerb: PropertyKey | undefined,
82
+ args: Host[],
83
+ callIndex: number
84
+ ] | [
85
+ op: 'checkSendOnly',
86
+ target: Host,
87
+ optVerb: PropertyKey | undefined,
88
+ args: Host[],
89
+ callIndex: number
90
+ ] | [
91
+ op: 'checkSend',
92
+ target: Host,
93
+ optVerb: PropertyKey | undefined,
94
+ args: Host[],
95
+ callIndex: number
96
+ ];
155
97
  /**
156
98
  * This would be the type alias for the full membrane log, if we supported:
157
99
  * - the guest sending guest-promises and guest-remotables to the host
158
100
  * - the guest using `E` to eventual-send to guest wrappers of the host
159
101
  * vows and remotables.
160
102
  */
161
- export type FutureLogEntry =
162
- | [
163
- // ///////////////// From Host to Guest ///////////////////////
164
- op: 'doFulfill',
165
- vow: HostVow,
166
- fulfillment: Host,
167
- ]
168
- | [op: 'doReject', vow: HostVow, reason: Host]
169
- | [
170
- op: 'doCall',
171
- target: Host,
172
- optVerb: PropertyKey | undefined,
173
- args: Host[],
174
- callIndex: number,
175
- ]
176
- | [
177
- op: 'doSendOnly',
178
- target: Host,
179
- optVerb: PropertyKey | undefined,
180
- args: Host[],
181
- callIndex: number,
182
- ]
183
- | [
184
- op: 'doSend',
185
- target: Host,
186
- optVerb: PropertyKey | undefined,
187
- args: Host[],
188
- callIndex: number,
189
- ]
190
- | [op: 'doReturn', callIndex: number, result: Host]
191
- | [op: 'doThrow', callIndex: number, problem: Host]
192
- | [
193
- // ///////////////////// From Guest to Host /////////////////////////
194
- op: 'checkFulfill',
195
- vow: HostVow,
196
- fulfillment: Host,
197
- ]
198
- | [op: 'checkReject', vow: HostVow, reason: Host]
199
- | [
200
- op: 'checkCall',
201
- target: Host,
202
- optVerb: PropertyKey | undefined,
203
- args: Host[],
204
- callIndex: number,
205
- ]
206
- | [
207
- op: 'checkSendOnly',
208
- target: Host,
209
- optVerb: PropertyKey | undefined,
210
- args: Host[],
211
- callIndex: number,
212
- ]
213
- | [
214
- op: 'checkSend',
215
- target: Host,
216
- optVerb: PropertyKey | undefined,
217
- args: Host[],
218
- callIndex: number,
219
- ]
220
- | [op: 'checkReturn', callIndex: number, result: Host]
221
- | [op: 'checkThrow', callIndex: number, problem: Host];
103
+ export type FutureLogEntry = [op: 'startGeneration', generation: number] | [op: 'doFulfill', vow: HostVow, fulfillment: Host] | [op: 'doReject', vow: HostVow, reason: Host] | [
104
+ op: 'doCall',
105
+ target: Host,
106
+ optVerb: PropertyKey | undefined,
107
+ args: Host[],
108
+ callIndex: number
109
+ ] | [
110
+ op: 'doSendOnly',
111
+ target: Host,
112
+ optVerb: PropertyKey | undefined,
113
+ args: Host[],
114
+ callIndex: number
115
+ ] | [
116
+ op: 'doSend',
117
+ target: Host,
118
+ optVerb: PropertyKey | undefined,
119
+ args: Host[],
120
+ callIndex: number
121
+ ] | [op: 'doReturn', callIndex: number, result: Host] | [op: 'doThrow', callIndex: number, problem: Host] | [op: 'checkFulfill', vow: HostVow, fulfillment: Host] | [op: 'checkReject', vow: HostVow, reason: Host] | [
122
+ op: 'checkCall',
123
+ target: Host,
124
+ optVerb: PropertyKey | undefined,
125
+ args: Host[],
126
+ callIndex: number
127
+ ] | [
128
+ op: 'checkSendOnly',
129
+ target: Host,
130
+ optVerb: PropertyKey | undefined,
131
+ args: Host[],
132
+ callIndex: number
133
+ ] | [
134
+ op: 'checkSend',
135
+ target: Host,
136
+ optVerb: PropertyKey | undefined,
137
+ args: Host[],
138
+ callIndex: number
139
+ ] | [op: 'checkReturn', callIndex: number, result: Host] | [op: 'checkThrow', callIndex: number, problem: Host];
140
+ export {};
141
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,MAAM,MAAM,SAAS,GACjB,SAAS,GACT,UAAU,GACV,WAAW,GACX,QAAQ,GACR,MAAM,CAAC;AAEX;;;;;;GAMG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,OAAO,GAAG,GAAG,IAAI,CAAC,CAAC;AAC/C,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