Implement typed module contracts and conformance bindings
This commit is contained in:
+34
-7
@@ -45,10 +45,25 @@ assert.ok(data.ok && data.resource.kind === "interface", JSON.stringify(data.dia
|
||||
assert.ok(constructors.ok && constructors.resource.kind === "interface", JSON.stringify(constructors.diagnostics));
|
||||
const dataInterface = data.resource.revision,
|
||||
factoriesInterface = constructors.resource.revision;
|
||||
const ui = compileCapabilityResourceSource(
|
||||
'import interface Data; package UI id "package:ui" revision "package:ui@1" { component Card id "component:card" subject Data runtime react; }',
|
||||
const view = compileCapabilityResourceSource(
|
||||
'import interface Data; interface View id "interface:device-view" revision "interface:device-view@1" { module render id "member:device-view:render" contract "org.quixos.react.subject-only/1" subject interface Data; }',
|
||||
{ source, environment: { interfaces: new Map([["Data", dataInterface]]), interfaceClosure: [dataInterface] } },
|
||||
);
|
||||
assert.ok(view.ok && view.resource.kind === "interface", JSON.stringify(view.diagnostics));
|
||||
const viewInterface = view.resource.revision;
|
||||
const ui = compileCapabilityResourceSource(
|
||||
'import interface Data; import interface View; package UI id "package:ui" revision "package:ui@1" { module Card id "component:card" implements View.render; }',
|
||||
{
|
||||
source,
|
||||
environment: {
|
||||
interfaces: new Map([
|
||||
["Data", dataInterface],
|
||||
["View", viewInterface],
|
||||
]),
|
||||
interfaceClosure: [dataInterface, viewInterface],
|
||||
},
|
||||
},
|
||||
);
|
||||
assert.ok(ui.ok && ui.resource.kind === "package", JSON.stringify(ui.diagnostics));
|
||||
for (const variant of ["base", "added", "gateway", "gateway-next", "session"]) {
|
||||
const session = variant === "session",
|
||||
@@ -56,13 +71,13 @@ for (const variant of ["base", "added", "gateway", "gateway-next", "session"]) {
|
||||
commit = { base: "a", added: "b", gateway: "c", "gateway-next": "d", session: "e" }[variant]!.repeat(40);
|
||||
const pkg = compileCapabilityResourceSource(
|
||||
`${gateway ? 'external atom Entry id "atom:entry";' : ""}
|
||||
${session ? 'external atom Independent id "atom:independent"; import interface Data;' : ""}
|
||||
${session ? 'external atom Independent id "atom:independent"; import interface Data; import interface View;' : ""}
|
||||
package Owner id "package:owner" revision "package:owner@1" {
|
||||
function identity id "identity" : int32 -> record { pid: int32; child: int32; } execution remote;
|
||||
${gateway ? 'function create id "create" : unit -> atom-ref<Entry> execution transaction targets [server] requires { creation entry id "entry:birth" : Entry input unit; };' : ""}
|
||||
${
|
||||
session
|
||||
? `component Editor id "component:owner-editor" subject Data runtime react;
|
||||
? `module Editor id "component:owner-editor" implements View.render;
|
||||
function createOne id "create-one" : string -> atom-ref<Entry> execution transaction targets [browser, server] requires { creation entry id "one:birth" : Entry input unit; };
|
||||
function createTwo id "create-two" : unit -> atom-ref<Independent> execution transaction targets [browser, server] requires { creation entry id "two:birth" : Independent input unit; };
|
||||
operation revise id "revise" : record {body:change<string>; notes:change<string>; reject:bool;} -> unit mode call execution transaction targets [browser, server] receiver any requires {
|
||||
@@ -78,7 +93,15 @@ package Owner id "package:owner" revision "package:owner@1" {
|
||||
{
|
||||
source,
|
||||
...(session
|
||||
? { environment: { interfaces: new Map([["Data", dataInterface]]), interfaceClosure: [dataInterface] } }
|
||||
? {
|
||||
environment: {
|
||||
interfaces: new Map([
|
||||
["Data", dataInterface],
|
||||
["View", viewInterface],
|
||||
]),
|
||||
interfaceClosure: [dataInterface, viewInterface],
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
);
|
||||
@@ -107,7 +130,7 @@ package Owner id "package:owner" revision "package:owner@1" {
|
||||
${session ? "import package UI;" : ""}
|
||||
${
|
||||
session
|
||||
? `import interface Data; import interface Factories;
|
||||
? `import interface Data; import interface View; import interface Factories;
|
||||
conform Entry as Factories id "owner:factories" { bind createOne.call to package Owner.createOne with { entry to creation Entry with {}; }; bind createTwo.call to package Owner.createTwo with { entry to creation Independent with {}; }; }
|
||||
${["Entry", "Independent"].map((atom) => `conform ${atom} as Data id "owner:${atom}:data" { private state ${atom}Label id "label:${atom}" on ${atom} : string policy register default "${atom}"; bind label.get to state ${atom}Label.read; bind label.set to state ${atom}Label.write; private state ${atom}Body id "body:${atom}" on ${atom} : string policy crdt(string) default "hello 🌍"; private state ${atom}Notes id "notes:${atom}" on ${atom} : string policy crdt(string) default "notes"; bind body.get to state ${atom}Body.read; bind body.edit to state ${atom}Body.edit; bind notes.get to state ${atom}Notes.read; bind notes.edit to state ${atom}Notes.edit; bind revise.call to package Owner.revise with {body to state ${atom}Body; notes to state ${atom}Notes;}; }`).join("\n")}
|
||||
`
|
||||
@@ -137,11 +160,15 @@ package Owner id "package:owner" revision "package:owner@1" {
|
||||
...(session
|
||||
? ([
|
||||
["Data", dataInterface],
|
||||
["View", viewInterface],
|
||||
["Factories", factoriesInterface],
|
||||
] as const)
|
||||
: []),
|
||||
]),
|
||||
interfaceClosure: [factory.resource.revision, ...(session ? [dataInterface, factoriesInterface] : [])],
|
||||
interfaceClosure: [
|
||||
factory.resource.revision,
|
||||
...(session ? [dataInterface, viewInterface, factoriesInterface] : []),
|
||||
],
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user