Skip to content

Commit

Permalink
feat(orchestration): map flows anywhere in context
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman authored and turadg committed Sep 5, 2024
1 parent 72905fa commit 84d3ea6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
29 changes: 11 additions & 18 deletions packages/orchestration/src/facade.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @file Orchestration facade */
import { assertAllDefined } from '@agoric/internal';
import { assertAllDefined, deepMapObject } from '@agoric/internal';

/**
* @import {AsyncFlowTools, GuestInterface, HostArgs, HostOf} from '@agoric/async-flow';
Expand Down Expand Up @@ -109,26 +109,19 @@ export const makeOrchestrationFacade = ({
* @returns {{ [N in keyof GFM]: HostForGuest<GFM[N]> }}
*/
const orchestrateAll = (guestFns, hostCtx) => {
const getMappedFlows = () => {
return Object.fromEntries(
Object.keys(guestFns).map(name => [
name,
// eslint-disable-next-line no-use-before-define
(...args) => orcFns[name](...args),
]),
);
};

const mappedContext = Object.fromEntries(
Object.entries(hostCtx).map(([key, value]) => [
key,
// TODO: support matching individual guest functions anywhere in the context
// instead of matching the record as a whole
// https://github.com/Agoric/agoric-sdk/issues/9823
value === guestFns ? getMappedFlows() : value,
const mappedFlows = new Map(
Object.entries(guestFns).map(([name, guestFn]) => [
guestFn,
// eslint-disable-next-line no-use-before-define
(...args) => orcFns[name](...args),
]),
);

const mappedContext = deepMapObject(
hostCtx,
val => mappedFlows.get(val) || val,
);

const orcFns = /** @type {{ [N in keyof GFM]: HostForGuest<GFM[N]> }} */ (
Object.fromEntries(
Object.entries(guestFns).map(([name, guestFn]) => [
Expand Down
10 changes: 3 additions & 7 deletions packages/orchestration/test/facade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ test('calls between flows', async t => {
t.deepEqual(await vt.when(outer('a', 'b', 'c')), 'Hello a b c');
});

// UNTIL https://github.com/Agoric/agoric-sdk/issues/9823
test('context mapping limits', async t => {
test('context mapping individual flows', async t => {
const { vt, orchestrateAll, zcf } = t.context;

const flows = {
Expand All @@ -70,12 +69,9 @@ test('context mapping limits', async t => {
} as Record<string, OrchestrationFlow<any>>;

const { outer } = orchestrateAll(flows, {
peerFlows: { ...flows },
peerFlows: { inner: flows.inner },
zcf,
});

// `peerFlows` did not have the same identity as `guestFns`
await t.throwsAsync(vt.when(outer('a', 'b', 'c')), {
message: 'converting apply result: vow expected "[Promise]"',
});
t.deepEqual(await vt.when(outer('a', 'b', 'c')), 'Hello a b c');
});

0 comments on commit 84d3ea6

Please sign in to comment.