@orthograph/projections 0.1.0-next.1 → 0.1.0-next.2

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.
@@ -1,4 +1,4 @@
1
- import { camel, lines, local, scaffolded } from "#modules/names/service.js";
1
+ import { camel, lines, local, ruleBehind, scaffolded } from "#modules/names/service.js";
2
2
  import { whoLines } from "./header.js";
3
3
  import { callsOf, machinePaths } from "./paths.js";
4
4
  import { allowedFile, an, callerOf, columns, refusalsOf, roleName, thingFile } from "./words.js";
@@ -97,19 +97,40 @@ const roleStubs = (model, op, machined) => {
97
97
  checks: ["refuses(Blueprint.NotAllowed)", "noEvents()"],
98
98
  })];
99
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) => {
100
+ /**
101
+ * One stub per refusal a journey can cause by what it sends or the world it starts in: each declared error (the handler's
102
+ * to give), then each refusal a rule gives (the runtime's, G5), cast as the first allowed role, its fields a blank. A
103
+ * rule's stub cites the rule and says the world must already hold what the call would break.
104
+ */
105
+ const errorStubs = (model, op) => {
102
106
  const cast = castOf(model, op, op.allowed[0]);
103
107
  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}`),
108
+ const stub = (r, s) => render(op, {
109
+ ...s, name: `refused-${kebab(r.name)}`, title: `refused ${r.name}`, cast,
110
+ imports: [`import { Blueprint, noEvents, refuses } from "orthograph";`, ...cast.imports, `import { ${r.name} } from "${rel(s.errors)}";`],
110
111
  checks: [`refuses(${r.name}${r.fields.length ? `, ${todo(`${r.name}'s fields: ${r.fields.join(", ")}`)}` : ""})`, "noEvents()"],
111
112
  });
112
- });
113
+ const said = (r) => ` ${r.name} (exit ${r.exit}, ${r.code})${r.fields.length ? `, carrying ${r.fields.join(", ")}` : ""}`;
114
+ const refusals = refusalsOf(model, op);
115
+ return [
116
+ ...refusals.filter((r) => r.giver === "yours").map((r) => stub(r, {
117
+ from: r.file, errors: r.file,
118
+ doc: [`One refusal of ${op.name}, from ${r.file}:`, said(r), `Refused: ${caller} calls ${op.name} with a payload that triggers it, and nothing changes.`],
119
+ starts: `a starting world where ${op.name} can be refused ${r.name}`, payload: payloadOf(op, ` that triggers ${r.name}`),
120
+ })),
121
+ ...refusals.flatMap((r) => {
122
+ const rule = r.giver === "runtime" ? ruleBehind(model, op, r.name) : undefined;
123
+ if (rule === undefined)
124
+ return [];
125
+ return [stub(r, {
126
+ from: r.file, errors: thingFile(model, rule.thing, "errors"),
127
+ doc: [`One refusal of ${op.name}, the runtime's, for a rule in ${r.file}:`, said(r), ` ${rule.full}: ${rule.sentence}`,
128
+ `Refused: ${caller} calls ${op.name} in a world where it would break the rule, and nothing changes.`],
129
+ starts: `a starting world where ${op.name} would break ${rule.full}`, payload: payloadOf(op, ` that breaks ${rule.full}`),
130
+ })];
131
+ }),
132
+ ];
133
+ };
113
134
  export const renderJourneyStubs = (model, thing) => {
114
135
  const paths = machinePaths(model, thing);
115
136
  const machined = new Set(paths.map((p) => p.operation));
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@orthograph/projections",
3
- "version": "0.1.0-next.1",
3
+ "version": "0.1.0-next.2",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "effect": "4.1.4",
8
- "@orthograph/compiler": "0.1.0-next.1",
9
- "orthograph": "0.1.0-next.1"
8
+ "@orthograph/compiler": "0.1.0-next.2",
9
+ "orthograph": "0.1.0-next.2"
10
10
  },
11
11
  "orthograph": {
12
12
  "kind": "projection"
@@ -31,5 +31,10 @@
31
31
  "publishConfig": {
32
32
  "access": "public",
33
33
  "tag": "next"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/Open-Harness/orthograph.git",
38
+ "directory": "packages/projections"
34
39
  }
35
40
  }