Skip to content

Commit

Permalink
chore(types): use HostForGuest consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jul 18, 2024
1 parent 708ace8 commit 80b31f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
13 changes: 4 additions & 9 deletions packages/orchestration/src/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,13 @@ export const makeOrchestrationFacade = ({
const { prepareEndowment, asyncFlow, adminAsyncFlow } = asyncFlowTools;

/**
* @template GR - return type
* @template HC - host context
* @template {any[]} GA - guest args
* @template {OrchestrationFlow<GuestInterface<HC>>} GF guest fn
* @param {string} durableName - the orchestration flow identity in the zone
* (to resume across upgrades)
* @param {HC} hostCtx - values to pass through the async flow membrane
* @param {(
* guestOrc: Orchestrator,
* guestCtx: GuestInterface<HC>,
* ...args: GA
* ) => Promise<GR>} guestFn
* @returns {(...args: HostArgs<GA>) => Vow<GR>}
* @param {GF} guestFn
* @returns {HostForGuest<GF>}
*/
const orchestrate = (durableName, hostCtx, guestFn) => {
const subZone = zone.subZone(durableName);
Expand All @@ -92,7 +87,7 @@ export const makeOrchestrationFacade = ({
const hostFn = asyncFlow(subZone, 'asyncFlow', guestFn);

// cast because return could be arbitrary subtype
const orcFn = /** @type {(...args: HostArgs<GA>) => Vow<GR>} */ (
const orcFn = /** @type {HostForGuest<GF>} */ (
(...args) => hostFn(wrappedOrc, wrappedCtx, ...args)
);

Expand Down
3 changes: 3 additions & 0 deletions packages/orchestration/test/types.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ expectNotType<CosmosValidatorAddress>(chainAddr);
) => Promise.resolve(num);
{
const h = facade.orchestrate('name', undefined, slowEcho);
// TODO keep the return type as Vow<T>
expectType<(num: number) => Vow<number>>(h);
expectType<Vow<number>>(h(42));
// @ts-expect-error literal not carried, widened to number
expectType<Vow<42>>(h(42));
}

Expand Down

0 comments on commit 80b31f4

Please sign in to comment.