@orthograph/projections 0.0.0-stage → 0.1.0-next.1

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 (111) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +26 -2
  3. package/dist/main.d.ts +9 -0
  4. package/dist/main.js +12 -0
  5. package/dist/modules/actions/internal/actions.d.ts +7 -0
  6. package/dist/modules/actions/internal/actions.js +22 -0
  7. package/dist/modules/actions/service.d.ts +5 -0
  8. package/dist/modules/actions/service.js +14 -0
  9. package/dist/modules/actions/types.d.ts +9 -0
  10. package/dist/modules/actions/types.js +5 -0
  11. package/dist/modules/api/internal/api.d.ts +4 -0
  12. package/dist/modules/api/internal/api.js +99 -0
  13. package/dist/modules/api/service.d.ts +5 -0
  14. package/dist/modules/api/service.js +16 -0
  15. package/dist/modules/api/types.d.ts +1 -0
  16. package/dist/modules/api/types.js +1 -0
  17. package/dist/modules/app/internal/links.d.ts +2 -0
  18. package/dist/modules/app/internal/links.js +22 -0
  19. package/dist/modules/app/internal/palette.d.ts +6 -0
  20. package/dist/modules/app/internal/palette.js +55 -0
  21. package/dist/modules/app/internal/render.d.ts +4 -0
  22. package/dist/modules/app/internal/render.js +30 -0
  23. package/dist/modules/app/internal/view.d.ts +3 -0
  24. package/dist/modules/app/internal/view.js +52 -0
  25. package/dist/modules/app/service.d.ts +5 -0
  26. package/dist/modules/app/service.js +17 -0
  27. package/dist/modules/app/types.d.ts +52 -0
  28. package/dist/modules/app/types.js +1 -0
  29. package/dist/modules/cli/internal/cli.d.ts +3 -0
  30. package/dist/modules/cli/internal/cli.js +35 -0
  31. package/dist/modules/cli/internal/session.d.ts +11 -0
  32. package/dist/modules/cli/internal/session.js +55 -0
  33. package/dist/modules/cli/service.d.ts +2 -0
  34. package/dist/modules/cli/service.js +10 -0
  35. package/dist/modules/cli/types.d.ts +1 -0
  36. package/dist/modules/cli/types.js +1 -0
  37. package/dist/modules/handlers/internal/body.d.ts +5 -0
  38. package/dist/modules/handlers/internal/body.js +79 -0
  39. package/dist/modules/handlers/internal/calls.d.ts +17 -0
  40. package/dist/modules/handlers/internal/calls.js +80 -0
  41. package/dist/modules/handlers/internal/header.d.ts +18 -0
  42. package/dist/modules/handlers/internal/header.js +106 -0
  43. package/dist/modules/handlers/internal/paths.d.ts +18 -0
  44. package/dist/modules/handlers/internal/paths.js +11 -0
  45. package/dist/modules/handlers/internal/scaffold.d.ts +7 -0
  46. package/dist/modules/handlers/internal/scaffold.js +73 -0
  47. package/dist/modules/handlers/internal/stubs.d.ts +3 -0
  48. package/dist/modules/handlers/internal/stubs.js +120 -0
  49. package/dist/modules/handlers/internal/words.d.ts +43 -0
  50. package/dist/modules/handlers/internal/words.js +87 -0
  51. package/dist/modules/handlers/service.d.ts +5 -0
  52. package/dist/modules/handlers/service.js +9 -0
  53. package/dist/modules/handlers/types.d.ts +2 -0
  54. package/dist/modules/handlers/types.js +1 -0
  55. package/dist/modules/infra/internal/stack.d.ts +3 -0
  56. package/dist/modules/infra/internal/stack.js +15 -0
  57. package/dist/modules/infra/service.d.ts +5 -0
  58. package/dist/modules/infra/service.js +13 -0
  59. package/dist/modules/infra/types.d.ts +1 -0
  60. package/dist/modules/infra/types.js +1 -0
  61. package/dist/modules/mcp/internal/mcp.d.ts +3 -0
  62. package/dist/modules/mcp/internal/mcp.js +20 -0
  63. package/dist/modules/mcp/service.d.ts +5 -0
  64. package/dist/modules/mcp/service.js +13 -0
  65. package/dist/modules/mcp/types.d.ts +1 -0
  66. package/dist/modules/mcp/types.js +1 -0
  67. package/dist/modules/model/internal/edges.d.ts +4 -0
  68. package/dist/modules/model/internal/edges.js +12 -0
  69. package/dist/modules/model/service.d.ts +6 -0
  70. package/dist/modules/model/service.js +20 -0
  71. package/dist/modules/model/types.d.ts +1 -0
  72. package/dist/modules/model/types.js +1 -0
  73. package/dist/modules/names/internal/names.d.ts +51 -0
  74. package/dist/modules/names/internal/names.js +47 -0
  75. package/dist/modules/names/internal/when.d.ts +5 -0
  76. package/dist/modules/names/internal/when.js +19 -0
  77. package/dist/modules/names/internal/words.d.ts +34 -0
  78. package/dist/modules/names/internal/words.js +61 -0
  79. package/dist/modules/names/service.d.ts +19 -0
  80. package/dist/modules/names/service.js +19 -0
  81. package/dist/modules/names/types.d.ts +16 -0
  82. package/dist/modules/names/types.js +5 -0
  83. package/dist/modules/sdk/internal/client.d.ts +2 -0
  84. package/dist/modules/sdk/internal/client.js +31 -0
  85. package/dist/modules/sdk/internal/sdk.d.ts +3 -0
  86. package/dist/modules/sdk/internal/sdk.js +68 -0
  87. package/dist/modules/sdk/internal/types.d.ts +8 -0
  88. package/dist/modules/sdk/internal/types.js +38 -0
  89. package/dist/modules/sdk/service.d.ts +5 -0
  90. package/dist/modules/sdk/service.js +13 -0
  91. package/dist/modules/sdk/types.d.ts +1 -0
  92. package/dist/modules/sdk/types.js +1 -0
  93. package/dist/modules/server/internal/actors.d.ts +3 -0
  94. package/dist/modules/server/internal/actors.js +5 -0
  95. package/dist/modules/server/internal/doors.d.ts +10 -0
  96. package/dist/modules/server/internal/doors.js +26 -0
  97. package/dist/modules/server/internal/helpers.d.ts +13 -0
  98. package/dist/modules/server/internal/helpers.js +70 -0
  99. package/dist/modules/server/internal/server.d.ts +3 -0
  100. package/dist/modules/server/internal/server.js +65 -0
  101. package/dist/modules/server/internal/versioned.d.ts +13 -0
  102. package/dist/modules/server/internal/versioned.js +17 -0
  103. package/dist/modules/server/internal/worker-config.d.ts +16 -0
  104. package/dist/modules/server/internal/worker-config.js +90 -0
  105. package/dist/modules/server/service.d.ts +10 -0
  106. package/dist/modules/server/service.js +20 -0
  107. package/dist/modules/server/types.d.ts +1 -0
  108. package/dist/modules/server/types.js +1 -0
  109. package/dist/shared.d.ts +6 -0
  110. package/dist/shared.js +6 -0
  111. package/package.json +32 -3
@@ -0,0 +1,18 @@
1
+ import type { Model, OperationModel } from "@orthograph/compiler";
2
+ export type MachinePath = {
3
+ readonly kind: "allowed";
4
+ readonly operation: string;
5
+ readonly move: string;
6
+ readonly from: string | null;
7
+ readonly to: string;
8
+ readonly emits: string;
9
+ } | {
10
+ readonly kind: "refused";
11
+ readonly operation: string;
12
+ readonly move: string;
13
+ readonly from: string;
14
+ readonly refusal: string;
15
+ };
16
+ /** The thing's operations and reads, by name: what `add journeys` walks after the machine. */
17
+ export declare const callsOf: (model: Model, thing: string) => ReadonlyArray<OperationModel>;
18
+ export declare const machinePaths: (model: Model, thing: string) => ReadonlyArray<MachinePath>;
@@ -0,0 +1,11 @@
1
+ /** The thing's operations and reads, by name: what `add journeys` walks after the machine. */
2
+ export const callsOf = (model, thing) => Object.values(model.operations).filter((o) => o.thing === thing).sort((a, b) => a.name.localeCompare(b.name));
3
+ export const machinePaths = (model, thing) => {
4
+ const machine = model.things[thing]?.machine;
5
+ if (!machine)
6
+ return [];
7
+ return Object.entries(machine.moves).flatMap(([key, move]) => callsOf(model, thing).filter((o) => o.move?.key === key).flatMap((op) => [
8
+ ...(move.from.length ? move.from : [null]).flatMap((from) => move.to.map((to) => ({ kind: "allowed", operation: op.name, move: key, from, to, emits: move.emits }))),
9
+ ...(move.from.length === 0 ? [] : machine.states.filter((s) => !move.from.includes(s)).map((from) => ({ kind: "refused", operation: op.name, move: key, from, refusal: machine.notFrom.error }))),
10
+ ]));
11
+ };
@@ -0,0 +1,7 @@
1
+ import type { Model, OperationModel } from "@orthograph/compiler";
2
+ import type { RenderedFile } from "#modules/names/types.js";
3
+ /**
4
+ * An operation's handler scaffold. The model is how the scaffold reads the thing (its machine, errors, events and roles,
5
+ * which are not on the operation); both callers pass it. Without one, the scaffold says only what the operation holds.
6
+ */
7
+ export declare const renderHandlerScaffold: (op: OperationModel, path?: string, model?: Model) => RenderedFile;
@@ -0,0 +1,73 @@
1
+ // src/<thing>/<verb>.ts: written once per operation, then the project's own. Never overwritten. It explains itself (K16):
2
+ // front matter citing each blueprint file, then a body laid out step by step.
3
+ import { Names } from "orthograph/server";
4
+ import { callSteps, handlerTypeAt } from "./calls.js";
5
+ import { body, branches } from "./body.js";
6
+ import { handedIn, header } from "./header.js";
7
+ import { refusalsOf } from "./words.js";
8
+ import { camel, declarationAt, lines, local, scaffolded, toRoot } from "#modules/names/service.js";
9
+ const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
10
+ /** A model of one operation and no things: what the scaffold reads when it is given no model. */
11
+ const alone = (op) => ({ refusals: {}, things: {}, operations: { [op.name]: op } });
12
+ /**
13
+ * The answer field the runtime's minted id fills, once the model says the runtime mints it (M1.46 sets `mints` on a
14
+ * creating operation: the answer's field holding the thing's id, else the payload's). Before that the handler mints its
15
+ * own, and the scaffold leaves the field a blank.
16
+ */
17
+ const mintedField = (model, op) => {
18
+ const mints = op.mints;
19
+ // Only an answer field takes the id; a payload field named by `mints` is the caller's to give, and nothing to write.
20
+ return mints && mints in op.answer && handedIn(model, op).mints ? mints : undefined;
21
+ };
22
+ /** What a handler of a calling operation is told about its operation, as comments. */
23
+ const said = (op) => [
24
+ `Payload: ${Object.keys(op.payload).join(", ") || "none"}.`,
25
+ `Answer: ${Object.keys(op.answer).join(", ") || "nothing"}.`,
26
+ Object.keys(op.steps).length > 0 ? `Steps, each its own span: ${Object.keys(op.steps).map((k) => `steps.${k}(...)`).join(", ")}.` : "",
27
+ ].filter(Boolean);
28
+ /**
29
+ * An operation that calls an adapter: the call is wired by its payload's field names, and what is left to write is the one
30
+ * thing only the app knows, which declared error each way the call can fail becomes. A call that is the whole operation
31
+ * returns what the callable answered, so the answer is the callable's own.
32
+ */
33
+ const calling = (model, op, path) => {
34
+ const steps = callSteps(op);
35
+ const args = `[${Object.keys(op.payload).map((k) => (IDENTIFIER.test(k) ? `payload.${k}` : `payload[${JSON.stringify(k)}]`)).join(", ")}]`;
36
+ const blank = `Handlers.blank("map how this call fails to the error it declares", "failure")`;
37
+ const whole = steps.length === 1 && Object.keys(op.steps).length === 1;
38
+ // The errors the call can be refused with are imported, so the one blank is filled with a bare `new <Error>(...)`; the header names them too.
39
+ const errors = refusalsOf(model, op).filter((r) => r.giver === "yours");
40
+ const comments = [...said(op), "What the call fails with is mapped to one of the errors the operation declares; anything else is a defect."];
41
+ return {
42
+ path,
43
+ scaffold: true,
44
+ content: lines(scaffolded(op.file), whole ? [] : `import { Effect } from "effect";`, `import { Handlers } from "${Names.pkg("language-effect")}";`, errors.map((r) => `import { ${r.name} } from "${declarationAt(path, r.file)}";`), `import type { Handler } from "${toRoot(path)}${handlerTypeAt(op)}";`, "", header(model, op), whole
45
+ ? [`const ${local(camel(op.verb))}: Handler = (payload, { steps }) =>`, ...comments.map((s) => ` // ${s}`), ` steps.${steps[0].key}(${args}, ${blank});`]
46
+ : [
47
+ `const ${local(camel(op.verb))}: Handler = (payload, { steps }) =>`,
48
+ " Effect.gen(function* () {",
49
+ ...comments.map((s) => ` // ${s}`),
50
+ ...steps.map((s) => ` const ${s.key} = yield* steps.${s.key}(${args}, ${blank});`),
51
+ ` return yield* Handlers.blank("this handler is not written yet");`,
52
+ " });",
53
+ ], "", `export default ${local(camel(op.verb))};`),
54
+ };
55
+ };
56
+ /**
57
+ * An operation's handler scaffold. The model is how the scaffold reads the thing (its machine, errors, events and roles,
58
+ * which are not on the operation); both callers pass it. Without one, the scaffold says only what the operation holds.
59
+ */
60
+ export const renderHandlerScaffold = (op, path = `src/${op.thing}/${op.verb}.ts`, model = alone(op)) => {
61
+ if (callSteps(op).length > 0)
62
+ return calling(model, op, path);
63
+ const api = `${toRoot(path)}generated/api/src`;
64
+ const minted = mintedField(model, op);
65
+ const context = [...(Object.keys(op.steps).length > 0 ? ["steps"] : []), ...(op.move ? ["move"] : []), ...(minted ? ["id"] : [])];
66
+ const declared = refusalsOf(model, op).filter((r) => r.giver === "yours").map((r) => r.name);
67
+ const sections = body(model, op, minted);
68
+ return {
69
+ path,
70
+ scaffold: true,
71
+ content: lines(scaffolded(op.file), `import { Effect${branches(op) ? ", Match" : ""} } from "effect";`, `import { Handlers } from "${Names.pkg("language-effect")}";`, declared.length > 0 ? `import { Errors } from "${api}/index.ts";` : [], `import type { Handler${branches(op) ? ", Outcome" : ""} } from "${api}/${op.thing}/${op.verb}.handler.ts";`, "", declared.length > 0 ? [`const { ${declared.join(", ")} } = Errors.declared;`, ""] : [], header(model, op), `const ${local(camel(op.verb))}: Handler = (_payload, ${context.length === 0 ? "_context" : `{ ${context.join(", ")} }`}) =>`, " Effect.gen(function* () {", sections.flatMap((s, i) => (i === 0 ? s : ["", ...s])), " });", "", `export default ${local(camel(op.verb))};`),
72
+ };
73
+ };
@@ -0,0 +1,3 @@
1
+ import type { Model } from "@orthograph/compiler";
2
+ import type { RenderedFile } from "#modules/names/types.js";
3
+ export declare const renderJourneyStubs: (model: Model, thing: string) => ReadonlyArray<RenderedFile>;
@@ -0,0 +1,120 @@
1
+ import { camel, lines, local, scaffolded } from "#modules/names/service.js";
2
+ import { whoLines } from "./header.js";
3
+ import { callsOf, machinePaths } from "./paths.js";
4
+ import { allowedFile, an, callerOf, columns, refusalsOf, roleName, thingFile } from "./words.js";
5
+ /** A blueprint file as a journey in `blueprint/journeys/` imports it. */
6
+ const rel = (file) => (file.startsWith("blueprint/") ? `../${file.slice("blueprint/".length)}` : file);
7
+ const kebab = (name) => name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
8
+ const todo = (what) => `Blueprint.todo(${JSON.stringify(what)})`;
9
+ const roleOf = (a) => (a.kind === "role" || a.kind === "role-of" ? roleName(a.role) : undefined);
10
+ /** The cast for one `allowed` entry: the role itself (imported), or someone signed in, or anyone. */
11
+ const castOf = (model, op, a) => {
12
+ const role = a ? roleOf(a) : undefined;
13
+ // A move made by time is the keeper's alone: anyone else is refused, so its journeys cast the keeper (M8-checks call 4).
14
+ if (a?.kind === "keeper")
15
+ return { actor: "keeper", cast: "{ keeper: Blueprint.keeper }", imports: [] };
16
+ if (a && role)
17
+ return { actor: role, cast: `{ ${role} }`, imports: [`import { ${role} } from "${rel(allowedFile(model, op, a))}";`] };
18
+ return { actor: "someone", cast: `{ someone: Blueprint.${a?.kind === "signed-in" ? "signedIn" : "anyone"} }`, imports: [] };
19
+ };
20
+ /**
21
+ * The call's payload, one blank saying what goes there. A read's `run` is an overload a bare blank can't be inferred
22
+ * through, so its blank is typed `never`, which fits any payload.
23
+ */
24
+ const payloadArg = (op, what) => (op.kind === "read" ? `Blueprint.todo<never>(${JSON.stringify(what)})` : todo(what));
25
+ const render = (op, s) => ({
26
+ path: `blueprint/journeys/${op.thing}-${op.verb}-${s.name}.ts`,
27
+ scaffold: true,
28
+ content: lines(scaffolded(s.from), s.imports, `import ${local(camel(op.verb))} from "${rel(op.file)}";`, "", "/**", s.doc.map((l) => ` * ${l}`), " */", `export default Blueprint.journey(${JSON.stringify(`${op.name}: ${s.title}`)}, {`, ` cast: ${s.cast.cast},`, ` starts: ${todo(s.starts)},`, " steps: (s) => [", " s.step(", ` ${JSON.stringify(`the ${s.cast.actor} calls ${op.name}`)},`,
29
+ // The keeper fires a move for the instant it was due, which the stub leaves for the author like every other blank.
30
+ ` s.${s.cast.actor}.run(${local(camel(op.verb))}, ${payloadArg(op, s.payload)}${s.cast.actor === "keeper" ? `, { due: ${todo(`the instant ${op.name} was due`)} }` : ""}),`, s.checks.map((c) => ` ${c},`), " ),", " ],", "});"),
31
+ });
32
+ const payloadOf = (op, more = "") => `${op.name}'s payload${more}: ${Object.keys(op.payload).join(", ") || "none"}`;
33
+ const pathStub = (model, op, p) => {
34
+ const machine = model.things[op.thing].machine;
35
+ const cast = castOf(model, op, op.allowed[0]);
36
+ const file = thingFile(model, op.thing, "machine");
37
+ const head = `One path through the ${op.thing}'s machine, from ${file}:`;
38
+ const isIn = (state) => `machine.isIn(${todo(`the ${op.thing}'s id`)}, ${JSON.stringify(state)})`;
39
+ const machineImport = `import { machine } from "${rel(file)}";`;
40
+ if (p.kind === "refused") {
41
+ const from = machine.moves[p.move].from;
42
+ const row = [p.from, p.move, `refused ${p.refusal} (exit ${machine.notFrom.exit}, ${machine.notFrom.code}), because ${p.move} starts only from ${from.join(" or ")}`];
43
+ return render(op, {
44
+ name: `refused-from-${p.from}`, from: file, title: `refused from ${p.from}`, cast,
45
+ imports: [`import { Blueprint, noEvents, refuses } from "orthograph";`, machineImport, ...cast.imports],
46
+ doc: [head, ...columns([row]).map((l) => ` ${l}`), `Refused: ${callerOf(op.allowed[0])} calls ${op.name} on ${an(op.thing)} in ${p.from}, and nothing changes.`],
47
+ starts: `a starting world with ${an(op.thing)} in ${p.from}`, payload: payloadOf(op),
48
+ checks: [`refuses(machine.notFrom, { state: ${JSON.stringify(p.from)} })`, "noEvents()", isIn(p.from)],
49
+ });
50
+ }
51
+ const fields = Object.keys(model.things[op.thing].events[p.emits] ?? {});
52
+ const row = [p.from ?? "(creates)", p.move, p.to, `${p.emits}, by ${op.name}`];
53
+ const outcomes = machine.moves[p.move].to.length;
54
+ return render(op, {
55
+ name: p.from === null ? `created-in-${p.to}` : `${p.from}-to-${p.to}`, from: file, cast,
56
+ title: p.from === null ? `created in ${p.to}` : `${p.from} to ${p.to}`,
57
+ imports: [`import { Blueprint, emits } from "orthograph";`, machineImport, ...cast.imports, `import { ${p.emits} } from "${rel(thingFile(model, op.thing, "events"))}";`],
58
+ doc: [head, ...columns([row]).map((l) => ` ${l}`), p.from === null
59
+ ? `Allowed: ${callerOf(op.allowed[0])} calls ${op.name}, and the ${op.thing} is created in ${p.to}.`
60
+ : `Allowed: ${callerOf(op.allowed[0])} calls ${op.name} on ${an(op.thing)} in ${p.from}, and it ends in ${p.to}.`],
61
+ starts: p.from === null ? `a starting world where ${op.name} can run` : `a starting world with ${an(op.thing)} in ${p.from}`,
62
+ payload: payloadOf(op, outcomes > 1 ? `, one that ends in ${p.to}` : ""),
63
+ checks: [`emits(${p.emits}, ${fields.length ? todo(`${p.emits}'s fields: ${fields.join(", ")}`) : "{}"})`, isIn(p.to)],
64
+ });
65
+ };
66
+ /** Who may call: one stub per allowed entry no machine stub casts, then one caller turned away (none for anyone). */
67
+ const roleStubs = (model, op, machined) => {
68
+ const doc = whoLines(model, op, `Who may call ${op.name}`);
69
+ const entries = op.allowed.slice(machined ? 1 : 0);
70
+ const taken = (a) => entries.filter((b) => (roleOf(b) ?? b.kind) === (roleOf(a) ?? a.kind)).length > 1;
71
+ // Two entries of one role (`owner.of("source")`, `owner.of("destination")`) are told apart by the field they follow.
72
+ const named = (a) => `allowed-${roleOf(a) ?? a.kind}${taken(a) && a.kind === "role-of" ? `-${kebab(a.path)}` : ""}`;
73
+ const allowed = entries.map((a) => {
74
+ const cast = castOf(model, op, a);
75
+ return render(op, {
76
+ name: named(a), from: allowedFile(model, op, a), cast, title: `allowed ${roleOf(a) ? `the ${roleOf(a)}` : callerOf(a)}`,
77
+ imports: [`import { Blueprint } from "orthograph";`, ...cast.imports],
78
+ doc: [...doc, `Allowed: ${callerOf(a)} calls ${op.name}, and it answers.`],
79
+ starts: `a starting world where ${op.name} can run`, payload: payloadOf(op),
80
+ checks: [todo(`what ${op.name} answers: ${Object.keys(op.answer).join(", ") || "nothing"}`)],
81
+ });
82
+ });
83
+ if (op.allowed.some((a) => a.kind === "anyone") || op.allowed.length === 0)
84
+ return allowed;
85
+ const anonymous = op.allowed.some((a) => a.kind === "signed-in");
86
+ const roles = op.allowed.flatMap((a) => roleOf(a) ?? []);
87
+ const refused = op.allowed.some((a) => a.kind === "keeper")
88
+ ? { name: "refused-not-the-keeper", title: "refused a caller who isn't the keeper", cast: { actor: "someone", cast: "{ someone: Blueprint.anyone }", imports: [] }, who: "someone who isn't the keeper" }
89
+ : anonymous
90
+ ? { name: "refused-anonymous", title: "refused a caller who isn't signed in", cast: { actor: "visitor", cast: "{ visitor: Blueprint.anyone }", imports: [] }, who: "someone not signed in" }
91
+ : { name: `refused-not-${roles.join("-or-")}`, title: `refused a caller who isn't the ${roles.join(" or ")}`, cast: { actor: "stranger", cast: "{ stranger: Blueprint.signedIn }", imports: [] }, who: `someone signed in who isn't ${op.allowed.map(callerOf).join(" or ")}` };
92
+ return [...allowed, render(op, {
93
+ ...refused, from: allowedFile(model, op, op.allowed[0]),
94
+ imports: [`import { Blueprint, noEvents, refuses } from "orthograph";`],
95
+ doc: [...doc, `Refused: ${refused.who} calls ${op.name}, and nothing changes.`],
96
+ starts: `a starting world where ${op.name} can run`, payload: payloadOf(op),
97
+ checks: ["refuses(Blueprint.NotAllowed)", "noEvents()"],
98
+ })];
99
+ };
100
+ /** One stub per declared error, cast as the first allowed role, its fields a blank. */
101
+ const errorStubs = (model, op) => refusalsOf(model, op).filter((r) => r.giver === "yours").map((r) => {
102
+ const cast = castOf(model, op, op.allowed[0]);
103
+ const caller = op.allowed[0] ? callerOf(op.allowed[0]) : "anyone";
104
+ return render(op, {
105
+ name: `refused-${kebab(r.name)}`, from: r.file, title: `refused ${r.name}`, cast,
106
+ imports: [`import { Blueprint, noEvents, refuses } from "orthograph";`, ...cast.imports, `import { ${r.name} } from "${rel(r.file)}";`],
107
+ doc: [`One refusal of ${op.name}, from ${r.file}:`, ` ${r.name} (exit ${r.exit}, ${r.code})${r.fields.length ? `, carrying ${r.fields.join(", ")}` : ""}`,
108
+ `Refused: ${caller} calls ${op.name} with a payload that triggers it, and nothing changes.`],
109
+ starts: `a starting world where ${op.name} can be refused ${r.name}`, payload: payloadOf(op, ` that triggers ${r.name}`),
110
+ checks: [`refuses(${r.name}${r.fields.length ? `, ${todo(`${r.name}'s fields: ${r.fields.join(", ")}`)}` : ""})`, "noEvents()"],
111
+ });
112
+ });
113
+ export const renderJourneyStubs = (model, thing) => {
114
+ const paths = machinePaths(model, thing);
115
+ const machined = new Set(paths.map((p) => p.operation));
116
+ return [
117
+ ...paths.map((p) => pathStub(model, model.operations[p.operation], p)),
118
+ ...callsOf(model, thing).filter((op) => op.from.kind === "app").flatMap((op) => [...roleStubs(model, op, machined.has(op.name)), ...errorStubs(model, op)]),
119
+ ];
120
+ };
@@ -0,0 +1,43 @@
1
+ import type { AllowedModel, FieldModel, FieldsModel, Model, OperationModel, ThingModel } from "@orthograph/compiler";
2
+ /** The exit of a generated `<Thing>NotFound` (K16 g, M1.46); a thing that declares one keeps its own. */
3
+ export declare const NOT_FOUND_EXIT = 4;
4
+ /** A thing's own file, as the header cites it: the project's `blueprint/things/<thing>/<file>.ts`, or the plugin's. */
5
+ export declare const thingFile: (model: Model, thing: string, file: "thing" | "machine" | "errors" | "events" | "roles" | "invariants") => string;
6
+ export declare const roleName: (role: string) => string;
7
+ /** One `allowed` entry in words: the docs page's own phrase. */
8
+ export declare const callerOf: (a: AllowedModel) => string;
9
+ /** Who may call an operation: "the grantee of the allowance", "the owner of its organization", "anyone signed in". */
10
+ export declare const who: (op: OperationModel) => string;
11
+ /** The file an `allowed` entry is declared in: its role's thing's roles file, or the verb's own for anyone and signed-in. */
12
+ export declare const allowedFile: (model: Model, op: OperationModel, a: AllowedModel) => string;
13
+ /** The rule a role holds, as the model keeps it, when it has one. */
14
+ export declare const ruleOf: (model: Model, a: AllowedModel) => string | {
15
+ readonly kind: "who";
16
+ readonly who: string;
17
+ } | null;
18
+ /** What a field is: what it references, else the value it is named for, else its type. */
19
+ export declare const label: (f: FieldModel) => string;
20
+ /** Who sees a field that isn't public (M1.35's rule), in the words of `who`. */
21
+ export declare const seenBy: (f: FieldModel) => string;
22
+ /** "an Amount", "a Memo". */
23
+ export declare const an: (word: string) => string;
24
+ /** "a", "a and b", "a, b and c". */
25
+ export declare const listed: (xs: ReadonlyArray<string>) => string;
26
+ /** Rows as columns, each padded to its longest entry plus two spaces; the last column is never padded. */
27
+ export declare const columns: (rows: ReadonlyArray<ReadonlyArray<string>>) => ReadonlyArray<string>;
28
+ /** The thing whose generated (or adopted) `<Thing>NotFound` this refusal is, if it is one. */
29
+ export declare const notFoundOf: (model: Model, refusal: string) => ThingModel | undefined;
30
+ /** A refusal of an operation: its exit, its code, and in words who gives it and when, citing the file it came from. */
31
+ export interface Refusal {
32
+ readonly name: string;
33
+ readonly exit: number | "?";
34
+ readonly code: string;
35
+ /** `yours` when the handler refuses it, `runtime` when the runtime does before the handler runs. */
36
+ readonly giver: "yours" | "runtime";
37
+ readonly said: string;
38
+ readonly file: string;
39
+ readonly fields: ReadonlyArray<string>;
40
+ /** The fields as the model holds them, for a declared error's blanks. */
41
+ readonly fieldModels: FieldsModel;
42
+ }
43
+ export declare const refusalsOf: (model: Model, op: OperationModel) => ReadonlyArray<Refusal>;
@@ -0,0 +1,87 @@
1
+ import { IDEMPOTENCY_CONFLICT, IDEMPOTENCY_CONFLICT_EXIT, NOT_ALLOWED_EXIT, ruleBehind } from "#modules/names/service.js";
2
+ /** The exit of a generated `<Thing>NotFound` (K16 g, M1.46); a thing that declares one keeps its own. */
3
+ export const NOT_FOUND_EXIT = 4;
4
+ /** A thing's own file, as the header cites it: the project's `blueprint/things/<thing>/<file>.ts`, or the plugin's. */
5
+ export const thingFile = (model, thing, file) => {
6
+ const t = model.things[thing];
7
+ return t && t.from.kind !== "app" ? `${t.from.package}/blueprint/things/${t.from.thing}/${file}.js` : `blueprint/things/${thing}/${file}.ts`;
8
+ };
9
+ export const roleName = (role) => role.split(".").pop() ?? role;
10
+ const roleThing = (role) => role.split(".")[0] ?? role;
11
+ /** One `allowed` entry in words: the docs page's own phrase. */
12
+ export const callerOf = (a) => {
13
+ if (a.kind === "anyone")
14
+ return "anyone";
15
+ if (a.kind === "system")
16
+ return "the system";
17
+ if (a.kind === "keeper")
18
+ return "the keeper";
19
+ // A narrowed entry says which ways in it keeps (M2-auth, fork 2): `.via(Via.session)` is "by session".
20
+ const by = "via" in a && a.via !== undefined ? ` by ${a.via.join(" or ")}` : "";
21
+ if (a.kind === "signed-in")
22
+ return `anyone signed in${by}`;
23
+ if (a.service !== undefined)
24
+ return `the ${a.service} service`;
25
+ return `${a.kind === "role" ? `the ${roleName(a.role)} of the ${roleThing(a.role)}` : `the ${roleName(a.role)} of its ${a.path}`}${by}`;
26
+ };
27
+ /** Who may call an operation: "the grantee of the allowance", "the owner of its organization", "anyone signed in". */
28
+ export const who = (op) => op.allowed.map(callerOf).join(", or ");
29
+ /** The file an `allowed` entry is declared in: its role's thing's roles file, or the verb's own for anyone and signed-in. */
30
+ export const allowedFile = (model, op, a) => a.kind === "role" || a.kind === "role-of" ? thingFile(model, roleThing(a.role), "roles") : op.file;
31
+ /** The rule a role holds, as the model keeps it, when it has one. */
32
+ export const ruleOf = (model, a) => (a.kind === "role" || a.kind === "role-of") && a.service === undefined ? model.things[roleThing(a.role)]?.roleRules[roleName(a.role)] ?? null : null;
33
+ /** What a field is: what it references, else the value it is named for, else its type. */
34
+ export const label = (f) => f.ref ?? f.named ?? (f.value.type === "schema" && f.value.format === "ref-any" ? "any thing (declaration and id)" : f.value.type);
35
+ /** Who sees a field that isn't public (M1.35's rule), in the words of `who`. */
36
+ export const seenBy = (f) => !f.visibility ? ""
37
+ : f.visibility === "secret" ? " (secret: no caller sees it)"
38
+ : ` (private: only ${f.visibility.private.map((r) => `the ${roleName(r)} of the ${roleThing(r)}`).join(" or ")} sees it)`;
39
+ /** "an Amount", "a Memo". */
40
+ export const an = (word) => (/^[aeiou]/i.test(word) ? `an ${word}` : `a ${word}`);
41
+ /** "a", "a and b", "a, b and c". */
42
+ export const listed = (xs) => (xs.length <= 1 ? (xs[0] ?? "") : `${xs.slice(0, -1).join(", ")} and ${xs.at(-1)}`);
43
+ /** Rows as columns, each padded to its longest entry plus two spaces; the last column is never padded. */
44
+ export const columns = (rows) => {
45
+ const widths = (rows[0] ?? []).map((_, i) => Math.max(...rows.map((r) => (r[i] ?? "").length)) + 2);
46
+ return rows.map((r) => r.map((cell, i) => (i === r.length - 1 ? cell : cell.padEnd(widths[i]))).join(""));
47
+ };
48
+ /** The thing whose generated (or adopted) `<Thing>NotFound` this refusal is, if it is one. */
49
+ export const notFoundOf = (model, refusal) => Object.values(model.things).find((t) => `${t.identifier}NotFound` === refusal);
50
+ /** The thing that declares an error: the operation's own first, else the one it borrows it from. */
51
+ const ownerOf = (model, op, error) => model.things[op.thing]?.errors[error] ? op.thing : Object.values(model.things).find((t) => t.errors[error])?.name;
52
+ export const refusalsOf = (model, op) => {
53
+ const thing = model.things[op.thing];
54
+ const code = (r) => model.refusals[r] ?? "?";
55
+ return op.refusals.map((r) => {
56
+ const owner = op.errors.includes(r) ? ownerOf(model, op, r) : undefined;
57
+ const declared = owner ? model.things[owner]?.errors[r] : thing?.errors[r];
58
+ if (owner && declared) {
59
+ const fields = Object.keys(declared.fields);
60
+ return { name: r, exit: declared.exit, code: code(r), giver: "yours", fields, fieldModels: declared.fields, file: thingFile(model, owner, "errors"), said: `yours to refuse below${fields.length ? `, carrying ${fields.join(", ")}` : ""}` };
61
+ }
62
+ // A rule's refusal (G5): the runtime's, never the handler's, so the scaffold has no blank for it; the header says which rule and where it is written.
63
+ const rule = ruleBehind(model, op, r);
64
+ const refused = rule ? model.things[rule.thing]?.errors[r] : undefined;
65
+ if (rule && refused) {
66
+ return { name: r, exit: refused.exit, code: code(r), giver: "runtime", fields: Object.keys(refused.fields), fieldModels: refused.fields, file: thingFile(model, rule.thing, "invariants"), said: `the runtime's: ${rule.sentence} (${rule.full})` };
67
+ }
68
+ if (thing?.machine && r === thing.machine.notFrom.error) {
69
+ const from = op.move?.from.length ? op.move.from : thing.machine.states;
70
+ return { name: r, exit: thing.machine.notFrom.exit, code: code(r), giver: "runtime", fields: ["state"], fieldModels: {}, file: thingFile(model, op.thing, "machine"), said: `the runtime's, when the ${op.thing} isn't in ${from.join(" or ")}, carrying state` };
71
+ }
72
+ if (r === IDEMPOTENCY_CONFLICT) {
73
+ // The runtime's, before the handler runs (G3): a handler can neither make nor avoid it, as NotAllowed; the header still says it, from where the operation says `idempotent`.
74
+ return { name: r, exit: IDEMPOTENCY_CONFLICT_EXIT, code: code(r), giver: "runtime", fields: [], fieldModels: {}, file: op.file, said: "the runtime's, when the same request key comes with another payload" };
75
+ }
76
+ if (r === "NotAllowed") {
77
+ const first = op.allowed[0];
78
+ return { name: r, exit: NOT_ALLOWED_EXIT, code: code(r), giver: "runtime", fields: [], fieldModels: {}, file: first ? allowedFile(model, op, first) : op.file, said: op.allowed.every((a) => a.kind === "anyone") ? "the runtime's, when the caller is the keeper, which calls only the moves time makes" : `the runtime's, when the caller isn't ${who(op)}` };
79
+ }
80
+ const missing = notFoundOf(model, r);
81
+ if (missing) {
82
+ const own = missing.errors[r];
83
+ return { name: r, exit: own?.exit ?? NOT_FOUND_EXIT, code: code(r), giver: "runtime", fields: ["id"], fieldModels: {}, file: thingFile(model, missing.name, own ? "errors" : "thing"), said: `the runtime's, when no ${missing.name} has that id, carrying id` };
84
+ }
85
+ return { name: r, exit: declared?.exit ?? "?", code: code(r), giver: "runtime", fields: Object.keys(declared?.fields ?? {}), fieldModels: declared?.fields ?? {}, file: thingFile(model, op.thing, "errors"), said: "the runtime's" };
86
+ });
87
+ };
@@ -0,0 +1,5 @@
1
+ export { callImports, callSteps, handlerTypeAt, renderHandlerTypes, wired } from "./internal/calls.ts";
2
+ export { renderHandlerScaffold } from "./internal/scaffold.ts";
3
+ export { machinePaths } from "./internal/paths.ts";
4
+ export { renderJourneyStubs } from "./internal/stubs.ts";
5
+ export { who } from "./internal/words.ts";
@@ -0,0 +1,9 @@
1
+ // What an operation's handler is given and where it starts: its type in `generated/server/handlers/`, the scaffold in the
2
+ // project's `src/` for an operation the project writes (it explains itself, K16), and the journey stubs a thing's machine,
3
+ // roles and errors yield (`ortho add journeys`).
4
+ export { callImports, callSteps, handlerTypeAt, renderHandlerTypes, wired } from "./internal/calls.js";
5
+ export { renderHandlerScaffold } from "./internal/scaffold.js";
6
+ export { machinePaths } from "./internal/paths.js";
7
+ export { renderJourneyStubs } from "./internal/stubs.js";
8
+ // The sentence the docs page shares with the scaffold's front matter (K16 a): who may call an operation.
9
+ export { who } from "./internal/words.js";
@@ -0,0 +1,2 @@
1
+ export type { RenderedFile } from "#modules/names/types.js";
2
+ export type { MachinePath } from "./internal/paths.ts";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { Model } from "@orthograph/compiler";
2
+ import type { RenderedFile } from "#modules/names/types.js";
3
+ export declare const renderStack: (model: Model, name: string) => RenderedFile;
@@ -0,0 +1,15 @@
1
+ import { GENERATED, bindingOf, databaseStores, lines } from "#modules/names/service.js";
2
+ import { COMPATIBILITY_DATE } from "#modules/server/service.js";
3
+ export const renderStack = (model, name) => {
4
+ const actors = Object.values(model.things).some((t) => t.lives === "actor");
5
+ const migrations = [["DB", "../server/migrations"], ...databaseStores(model).map((s) => [bindingOf(s), `../server/migrations/${s.name}`])];
6
+ const classes = actors ? [["World", "WORLD"], ["Actor", "ACTORS"]] : [["World", "WORLD"]];
7
+ const table = (rows) => rows.map(([k, v]) => ` ${k}: ${JSON.stringify(v)},`);
8
+ return {
9
+ path: "generated/infra/alchemy.run.ts",
10
+ scaffold: false,
11
+ content: lines(GENERATED, "// The staging stack (M7.03). `ortho env up|destroy staging --run <id>` runs it with `alchemy deploy|destroy`. The model decides what is bound; the run decides the names,", "// which the plan (`packages/cli/src/modules/staging/internal/plan.ts`) holds and `ortho env up` writes to the file `ORTHO_STAGING_INPUT` names.", `import * as Alchemy from "alchemy";`, `import * as State from "alchemy/State";`, `import * as Cloudflare from "@alchemy.run/cloudflare";`, `import * as Config from "effect/Config";`, `import * as Effect from "effect/Effect";`, `import * as FileSystem from "effect/FileSystem";`, `import * as Path from "effect/Path";`, "", "interface Resource { readonly kind: string; readonly name?: string; readonly binding?: string; readonly script?: string; readonly class?: string }", "interface Input {", " readonly plan: { readonly prefix: string; readonly resources: ReadonlyArray<Resource> };", " /** The revision's bundle, built once. */", " readonly main: string;", " readonly vars: Readonly<Record<string, string>>;", "}", "", "/** Each database binding's migrations folder, beside the generated server. */", "const MIGRATIONS: Readonly<Record<string, string>> = {", table(migrations), "};", "/** Each Durable Object class the Worker exports, and the binding it is under. */", "const CLASSES: Readonly<Record<string, string>> = {", table(classes), "};", "", "export default Alchemy.Stack(", ` ${JSON.stringify(name)},`,
12
+ // Local state: `Cloudflare.state()` would deploy a state Worker, a Durable Object and a secrets store that carry no run's prefix.
13
+ " { providers: Cloudflare.providers(), state: State.localState() },", " Effect.gen(function* () {", " const fs = yield* FileSystem.FileSystem;", " const path = yield* Path.Path;", ` const input = JSON.parse(yield* Effect.orDie(fs.readFileString(yield* Config.String("ORTHO_STAGING_INPUT")))) as Input;`, ` const env: Cloudflare.WorkerBindingProps = { ...input.vars, AUTH_SECRET: yield* Config.Redacted("ORTHO_AUTH_SECRET") };`, "", " for (const r of input.plan.resources) {", ` if (r.kind === "d1") {`, " const dir = MIGRATIONS[String(r.binding)];", " if (dir === undefined) return yield* Effect.die(`the plan binds ${r.binding}, which the model does not`);", " env[String(r.binding)] = yield* Cloudflare.D1.Database(`Db${r.binding}`, { name: String(r.name), migrations: path.resolve(import.meta.dirname, dir) });", " }", ` if (r.kind === "durable-object-namespace") {`, " const binding = CLASSES[String(r.class)];", " if (binding === undefined) return yield* Effect.die(`the plan has the class ${r.class}, which the model does not`);", " env[binding] = Cloudflare.DurableObject(String(r.class), { className: String(r.class) });", " }", " }", "", ` const worker = input.plan.resources.find((r) => r.kind === "worker");`, ` if (worker === undefined) return yield* Effect.die("the plan has no Worker");`, ` const server = yield* Cloudflare.Worker("Server", {`, " name: String(worker.name),", " main: input.main,", " // The bundle is the revision's own, built once and deployed unchanged.", " bundle: false,", " // The address on, previews off, said out loud.", " workersDev: { enabled: true, previewsEnabled: false },", ` compatibility: { date: ${JSON.stringify(COMPATIBILITY_DATE)}, flags: ["nodejs_compat"] },`, " env,", " });", " return { url: server.url };", " }),", ");"),
14
+ };
15
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The Alchemy stack of an environment's cloud resources (`generated/infra/`): the Worker, its D1 databases and its
3
+ * Durable Object namespaces, from the model. Kept in the repository; `ortho env up|destroy staging` runs it.
4
+ */
5
+ export declare const infra: import("orthograph").Projection<{}>;
@@ -0,0 +1,13 @@
1
+ import { Blueprint, Ships } from "orthograph";
2
+ import { modelOf, within } from "#modules/names/service.js";
3
+ import { renderStack } from "./internal/stack.js";
4
+ /**
5
+ * The Alchemy stack of an environment's cloud resources (`generated/infra/`): the Worker, its D1 databases and its
6
+ * Durable Object namespaces, from the model. Kept in the repository; `ortho env up|destroy staging` runs it.
7
+ */
8
+ export const infra = Blueprint.projection({
9
+ description: "The Alchemy stack: the Worker, its databases and its Durable Object namespaces, named by the environment's plan.",
10
+ host: [],
11
+ ships: [Ships.kept],
12
+ render: (input) => within(input, "infra", [renderStack(modelOf(input), input.name)]),
13
+ });
@@ -0,0 +1 @@
1
+ export type { Projection } from "orthograph";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { Model } from "@orthograph/compiler";
2
+ import type { RenderedFile } from "#modules/names/types.js";
3
+ export declare const renderMcp: (model: Model) => ReadonlyArray<RenderedFile>;
@@ -0,0 +1,20 @@
1
+ // generated/mcp: the remote MCP server's catalog, one entry per operation and read (D3 #122). The tool's name is the
2
+ // operation's, its description the model's, its input schema the declaration's own payload (made at run time by the
3
+ // runtime's `Mcp`, which leaves out whatever is not public). The server wires each entry to its served operation.
4
+ import { Names } from "orthograph/server";
5
+ import { GENERATED, lines, opVar, ruleBehind, timeMoveOf, whenWords } from "#modules/names/service.js";
6
+ /** The operation's description, then each refusal the runtime makes for a rule and why, in the rule's one sentence (G5): an agent reads it before it calls. */
7
+ const toolDescription = (model, o) => [o.description, ...(timeMoveOf(model, o) ? [`Made by time: ${whenWords(o.thing, timeMoveOf(model, o), "")}.`] : []), ...Object.keys(o.invariants ?? {}).flatMap((r) => { const rule = ruleBehind(model, o, r); return rule ? [`Refuses ${r} when ${rule.sentence}.`] : []; })].join(" ");
8
+ export const renderMcp = (model) => {
9
+ // MCP is the agent's way in: an operation a mount narrowed without Via.agent has no tool (M1-plugins section 3). The catalog is what the
10
+ // server can serve; which of it an agent is shown follows `allowed` at run time (`Mcp.tools`, and the model's `agentTool`).
11
+ const ops = Object.values(model.operations).filter((o) => o.via === undefined || o.via.includes("agent"));
12
+ return [{
13
+ path: "generated/mcp/src/index.ts",
14
+ scaffold: false,
15
+ content: lines(GENERATED, `import type { McpEntry } from "${Names.pkg("language-effect")}";`, ops.map((o) => `import { declaration as ${opVar(o)} } from "../../api/src/${o.thing}/${o.verb}.ts";`), "", "/** One tool per operation and read, named as the operation is. */", "export const catalog = {", ops.map((o) => {
16
+ const states = model.things[o.thing]?.machine?.states ?? [];
17
+ return ` "${o.name}": { description: ${JSON.stringify(toolDescription(model, o))}, operation: ${opVar(o)}${states.length > 0 ? `, states: ${JSON.stringify(states)}` : ""}${o.move ? `, move: ${JSON.stringify(o.move)}` : ""} },`;
18
+ }), "} as const satisfies { readonly [name: string]: McpEntry };"),
19
+ }];
20
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The remote MCP server's catalog (`generated/mcp/`): a tool for each operation and read an agent can reach, and none for
3
+ * what runs on the device or what a mount narrowed out of `Via.agent`.
4
+ */
5
+ export declare const mcp: import("orthograph").Projection<{}>;
@@ -0,0 +1,13 @@
1
+ import { Blueprint, Ships } from "orthograph";
2
+ import { modelOf, serverModel, within } from "#modules/names/service.js";
3
+ import { renderMcp } from "./internal/mcp.js";
4
+ /**
5
+ * The remote MCP server's catalog (`generated/mcp/`): a tool for each operation and read an agent can reach, and none for
6
+ * what runs on the device or what a mount narrowed out of `Via.agent`.
7
+ */
8
+ export const mcp = Blueprint.projection({
9
+ description: "The MCP catalog: a tool for each operation an agent can reach, named as the operation is.",
10
+ host: [],
11
+ ships: [Ships.kept],
12
+ render: (input) => within(input, "mcp", renderMcp(serverModel(modelOf(input)))),
13
+ });
@@ -0,0 +1 @@
1
+ export type { Projection } from "orthograph";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { Model } from "@orthograph/compiler";
2
+ import type { RenderedFile } from "#modules/names/types.js";
3
+ /** What depends on what: a field naming another thing, an operation on its thing, a move emitting its event. */
4
+ export declare const renderEdges: (model: Model) => RenderedFile;
@@ -0,0 +1,12 @@
1
+ /** What depends on what: a field naming another thing, an operation on its thing, a move emitting its event. */
2
+ export const renderEdges = (model) => {
3
+ const edges = [
4
+ ...Object.values(model.things).flatMap((t) => Object.entries(t.fields).flatMap(([k, f]) => f.ref && !f.ref.startsWith(`${t.name}.`) ? [{ from: `${t.name}.${k}`, to: f.ref, kind: "refers" }] : [])),
5
+ ...Object.values(model.operations).flatMap((o) => [
6
+ { from: o.name, to: o.thing, kind: o.kind === "read" ? "reads" : "acts-on" },
7
+ ...(o.move ? [{ from: o.name, to: `${o.thing}.${o.move.emits}`, kind: "emits" }] : []),
8
+ ...o.allowed.flatMap((a) => (a.kind === "role" || a.kind === "role-of" ? [{ from: o.name, to: a.role, kind: "allowed-by" }] : [])),
9
+ ]),
10
+ ];
11
+ return { path: "generated/model/edges.json", scaffold: false, content: JSON.stringify(edges, null, 2) + "\n" };
12
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The model as data (`generated/model/`): `model.json` is the compiler's model as it is, with its `mounts` when the project
3
+ * mounts anything, and `edges.json` what depends on what. The model is a projection too (M1-plugins, "Checks 12 and 13").
4
+ * `changes.json` beside them is the CLI's, never this projection's.
5
+ */
6
+ export declare const model: import("orthograph").Projection<{}>;
@@ -0,0 +1,20 @@
1
+ import { Blueprint, Ships } from "orthograph";
2
+ import { modelOf, within } from "#modules/names/service.js";
3
+ import { renderEdges } from "./internal/edges.js";
4
+ /**
5
+ * The model as data (`generated/model/`): `model.json` is the compiler's model as it is, with its `mounts` when the project
6
+ * mounts anything, and `edges.json` what depends on what. The model is a projection too (M1-plugins, "Checks 12 and 13").
7
+ * `changes.json` beside them is the CLI's, never this projection's.
8
+ */
9
+ export const model = Blueprint.projection({
10
+ description: "The model as data: every thing, operation and mount, and what depends on what.",
11
+ host: [],
12
+ ships: [Ships.kept],
13
+ render: (input) => {
14
+ const compiled = modelOf(input);
15
+ return within(input, "model", [
16
+ { path: "generated/model/model.json", content: JSON.stringify(compiled, null, 2) + "\n", scaffold: false },
17
+ renderEdges(compiled),
18
+ ]);
19
+ },
20
+ });
@@ -0,0 +1 @@
1
+ export type { Projection } from "orthograph";
@@ -0,0 +1 @@
1
+ export {};