diff --git a/packages/core/src/core.test.ts b/packages/core/src/core.test.ts index c708052..442b2f8 100644 --- a/packages/core/src/core.test.ts +++ b/packages/core/src/core.test.ts @@ -89,6 +89,27 @@ describe("core", () => { await g([]); expect(count).toBe(2); }); + test("naked", async () => { + let check = ""; + const test: Choreography = async ({ locally, multicast, naked, enclave }) => { + const msg = await locally("alice", () => "Hello, world!"); + const mlv = await multicast( + "alice", + ["bob"], + msg, + ); + // @ts-expect-error: xx + naked(mlv); + enclave(["alice", "bob"], async ({ naked }) => { + check = naked(mlv); + return []; + },[]) + return []; + }; + const g = runner.compile(test); + await g([]); + expect(check).toBe("Hello, world!"); + }); test("broadcast", async () => { let count = 0; const test: Choreography = async ({ locally, broadcast }) => { diff --git a/packages/core/src/core.ts b/packages/core/src/core.ts index 944709c..537bad2 100644 --- a/packages/core/src/core.ts +++ b/packages/core/src/core.ts @@ -59,6 +59,22 @@ export class MultiplyLocated { protected phantom?: (x: L) => void; } +export class Faceted { + constructor(value: T, key: symbol) { + this.value = value; + this.key = key; + } + public getValue(key: symbol) { + if (this.key !== key) { + throw new Error("Invalid key"); + } + return this.value; + } + protected value: T; + protected key: symbol; + protected phantom?: (x: L) => void; +} + /** * The dependencies of a choreography */ @@ -106,8 +122,8 @@ export type Enclave = < args: Args, ) => Promise; -export type Naked = ( - mlv: MultiplyLocated, +export type Naked = ( + mlv: MultiplyLocated, ) => T; export type Multicast = < @@ -489,9 +505,6 @@ export class Projector { } }; - const naked: Naked = (cv: MultiplyLocated) => - cv.getValue(key); - const call: (t: Tag) => Call = (t: Tag) => async < @@ -503,6 +516,8 @@ export class Projector { a: Args, ) => { const childTag = t.call(); + const naked: Naked = (cv: MultiplyLocated) => + cv.getValue(key); return await c( wrapMethods((m) => ctxManager.checkContext(m), { locally: locally(childTag), @@ -517,6 +532,8 @@ export class Projector { ); }; + const naked: Naked = (cv: MultiplyLocated) => + cv.getValue(key); const ret = await choreography( wrapMethods((m) => ctxManager.checkContext(m), { locally: locally(tag), @@ -613,6 +630,8 @@ export class Runner { choreography: Choreography, args: Args, ) => { + const naked: Naked = (cv: MultiplyLocated) => + cv.getValue(key); const ret = await choreography( wrapMethods((m) => m, { locally: locally, @@ -652,6 +671,8 @@ export class Runner { c: Choreography, a: Args, ) => { + const naked: Naked = (cv: MultiplyLocated) => + cv.getValue(key); const ret = await c( wrapMethods((m) => m, { locally: locally,