@orthograph/compiler 0.0.0-stage → 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.
- package/LICENSE +202 -0
- package/README.md +4 -2
- package/dist/index.d.ts +12 -0
- package/dist/index.js +9 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +18 -0
- package/dist/modules/app/internal/checks.d.ts +30 -0
- package/dist/modules/app/internal/checks.js +99 -0
- package/dist/modules/app/internal/describe.d.ts +6 -0
- package/dist/modules/app/internal/describe.js +59 -0
- package/dist/modules/app/internal/hash.d.ts +1 -0
- package/dist/modules/app/internal/hash.js +7 -0
- package/dist/modules/app/internal/known.d.ts +19 -0
- package/dist/modules/app/internal/known.js +45 -0
- package/dist/modules/app/internal/read.d.ts +6 -0
- package/dist/modules/app/internal/read.js +45 -0
- package/dist/modules/app/service.d.ts +2 -0
- package/dist/modules/app/service.js +3 -0
- package/dist/modules/app/types.d.ts +87 -0
- package/dist/modules/app/types.js +1 -0
- package/dist/modules/compare/internal/assets.d.ts +4 -0
- package/dist/modules/compare/internal/assets.js +40 -0
- package/dist/modules/compare/internal/chain.d.ts +4 -0
- package/dist/modules/compare/internal/chain.js +37 -0
- package/dist/modules/compare/internal/diff.d.ts +3 -0
- package/dist/modules/compare/internal/diff.js +27 -0
- package/dist/modules/compare/internal/versions.d.ts +9 -0
- package/dist/modules/compare/internal/versions.js +75 -0
- package/dist/modules/compare/service.d.ts +2 -0
- package/dist/modules/compare/service.js +43 -0
- package/dist/modules/compare/types.d.ts +47 -0
- package/dist/modules/compare/types.js +1 -0
- package/dist/modules/lock/internal/evolve.d.ts +7 -0
- package/dist/modules/lock/internal/evolve.js +52 -0
- package/dist/modules/lock/internal/runtime.d.ts +3 -0
- package/dist/modules/lock/internal/runtime.js +12 -0
- package/dist/modules/lock/service.d.ts +4 -0
- package/dist/modules/lock/service.js +20 -0
- package/dist/modules/lock/types.d.ts +101 -0
- package/dist/modules/lock/types.js +6 -0
- package/dist/modules/model/internal/allowed.d.ts +26 -0
- package/dist/modules/model/internal/allowed.js +78 -0
- package/dist/modules/model/internal/approval.d.ts +4 -0
- package/dist/modules/model/internal/approval.js +10 -0
- package/dist/modules/model/internal/assets.d.ts +5 -0
- package/dist/modules/model/internal/assets.js +31 -0
- package/dist/modules/model/internal/bits.d.ts +6 -0
- package/dist/modules/model/internal/bits.js +9 -0
- package/dist/modules/model/internal/chain.d.ts +9 -0
- package/dist/modules/model/internal/chain.js +47 -0
- package/dist/modules/model/internal/codes.d.ts +59 -0
- package/dist/modules/model/internal/codes.js +80 -0
- package/dist/modules/model/internal/derive.d.ts +11 -0
- package/dist/modules/model/internal/derive.js +31 -0
- package/dist/modules/model/internal/describe.d.ts +8 -0
- package/dist/modules/model/internal/describe.js +248 -0
- package/dist/modules/model/internal/device.d.ts +5 -0
- package/dist/modules/model/internal/device.js +12 -0
- package/dist/modules/model/internal/environments.d.ts +7 -0
- package/dist/modules/model/internal/environments.js +90 -0
- package/dist/modules/model/internal/exits.d.ts +49 -0
- package/dist/modules/model/internal/exits.js +85 -0
- package/dist/modules/model/internal/fields.d.ts +23 -0
- package/dist/modules/model/internal/fields.js +50 -0
- package/dist/modules/model/internal/fillable.d.ts +3 -0
- package/dist/modules/model/internal/fillable.js +9 -0
- package/dist/modules/model/internal/forms.d.ts +47 -0
- package/dist/modules/model/internal/forms.js +75 -0
- package/dist/modules/model/internal/found.d.ts +40 -0
- package/dist/modules/model/internal/found.js +60 -0
- package/dist/modules/model/internal/handler-files.d.ts +18 -0
- package/dist/modules/model/internal/handler-files.js +23 -0
- package/dist/modules/model/internal/hash.d.ts +4 -0
- package/dist/modules/model/internal/hash.js +7 -0
- package/dist/modules/model/internal/holds.d.ts +19 -0
- package/dist/modules/model/internal/holds.js +65 -0
- package/dist/modules/model/internal/invariants.d.ts +38 -0
- package/dist/modules/model/internal/invariants.js +134 -0
- package/dist/modules/model/internal/journeys.d.ts +15 -0
- package/dist/modules/model/internal/journeys.js +135 -0
- package/dist/modules/model/internal/layout.d.ts +143 -0
- package/dist/modules/model/internal/layout.js +203 -0
- package/dist/modules/model/internal/lock-fields.d.ts +3 -0
- package/dist/modules/model/internal/lock-fields.js +17 -0
- package/dist/modules/model/internal/money.d.ts +17 -0
- package/dist/modules/model/internal/money.js +49 -0
- package/dist/modules/model/internal/nullable.d.ts +7 -0
- package/dist/modules/model/internal/nullable.js +21 -0
- package/dist/modules/model/internal/operations.d.ts +27 -0
- package/dist/modules/model/internal/operations.js +81 -0
- package/dist/modules/model/internal/reads.d.ts +16 -0
- package/dist/modules/model/internal/reads.js +58 -0
- package/dist/modules/model/internal/rules.d.ts +2 -0
- package/dist/modules/model/internal/rules.js +33 -0
- package/dist/modules/model/internal/same-value.d.ts +10 -0
- package/dist/modules/model/internal/same-value.js +50 -0
- package/dist/modules/model/internal/secrets.d.ts +4 -0
- package/dist/modules/model/internal/secrets.js +35 -0
- package/dist/modules/model/internal/source-refusals.d.ts +7 -0
- package/dist/modules/model/internal/source-refusals.js +52 -0
- package/dist/modules/model/internal/sources.d.ts +12 -0
- package/dist/modules/model/internal/sources.js +65 -0
- package/dist/modules/model/internal/stores.d.ts +20 -0
- package/dist/modules/model/internal/stores.js +44 -0
- package/dist/modules/model/internal/things.d.ts +33 -0
- package/dist/modules/model/internal/things.js +99 -0
- package/dist/modules/model/service.d.ts +4 -0
- package/dist/modules/model/service.js +105 -0
- package/dist/modules/model/types.d.ts +485 -0
- package/dist/modules/model/types.js +5 -0
- package/dist/modules/mounts/fixtures/both/things/echo/thing.d.ts +1 -0
- package/dist/modules/mounts/fixtures/both/things/echo/thing.js +1 -0
- package/dist/modules/mounts/fixtures/both/things/echo/verbs/only.d.ts +1 -0
- package/dist/modules/mounts/fixtures/both/things/echo/verbs/only.js +1 -0
- package/dist/modules/mounts/internal/attribute.d.ts +2 -0
- package/dist/modules/mounts/internal/attribute.js +4 -0
- package/dist/modules/mounts/internal/calls.d.ts +12 -0
- package/dist/modules/mounts/internal/calls.js +42 -0
- package/dist/modules/mounts/internal/choices.d.ts +11 -0
- package/dist/modules/mounts/internal/choices.js +34 -0
- package/dist/modules/mounts/internal/fold.d.ts +6 -0
- package/dist/modules/mounts/internal/fold.js +8 -0
- package/dist/modules/mounts/internal/needs.d.ts +14 -0
- package/dist/modules/mounts/internal/needs.js +26 -0
- package/dist/modules/mounts/internal/verbs.d.ts +11 -0
- package/dist/modules/mounts/internal/verbs.js +44 -0
- package/dist/modules/mounts/service.d.ts +2 -0
- package/dist/modules/mounts/service.js +165 -0
- package/dist/modules/mounts/types.d.ts +78 -0
- package/dist/modules/mounts/types.js +1 -0
- package/dist/modules/source/internal/plugins.d.ts +25 -0
- package/dist/modules/source/internal/plugins.js +49 -0
- package/dist/modules/source/service.d.ts +6 -0
- package/dist/modules/source/service.js +86 -0
- package/dist/modules/source/types.d.ts +55 -0
- package/dist/modules/source/types.js +6 -0
- package/dist/modules/time/internal/anchor.d.ts +2 -0
- package/dist/modules/time/internal/anchor.js +48 -0
- package/dist/modules/time/internal/keeper.d.ts +13 -0
- package/dist/modules/time/internal/keeper.js +19 -0
- package/dist/modules/time/internal/zones.d.ts +1 -0
- package/dist/modules/time/internal/zones.js +3 -0
- package/dist/modules/time/service.d.ts +2 -0
- package/dist/modules/time/service.js +56 -0
- package/dist/modules/time/types.d.ts +89 -0
- package/dist/modules/time/types.js +1 -0
- package/package.json +35 -3
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// A plugin's needs, met by the app's mount of each needed descriptor (identity), whatever the mount is named.
|
|
2
|
+
import { Mounts as Picks } from "orthograph/server";
|
|
3
|
+
const kindOf = (x) => (typeof x === "object" && x !== null ? x.kind : undefined);
|
|
4
|
+
/** The mounts meeting this mount's needs (`feature:echo`), and the needs nothing meets, each naming the command to mount it. */
|
|
5
|
+
export const needsOf = (me, matched, installed) => {
|
|
6
|
+
const met = [];
|
|
7
|
+
const problems = [];
|
|
8
|
+
const needs = (me.mount.plugin.needs ?? []);
|
|
9
|
+
for (const need of needs) {
|
|
10
|
+
const conditional = kindOf(need) === "need" ? need : undefined;
|
|
11
|
+
const wanted = conditional ? conditional.plugin : need;
|
|
12
|
+
if (conditional?.when && !Picks.picked(me.mount, conditional.when))
|
|
13
|
+
continue;
|
|
14
|
+
const by = matched.find((m) => m.mount.plugin === wanted);
|
|
15
|
+
if (by) {
|
|
16
|
+
met.push(`${by.kind}:${by.name}`);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const pkg = installed.find((p) => p.descriptor === wanted);
|
|
20
|
+
const kind = String(kindOf(wanted) ?? "feature");
|
|
21
|
+
problems.push(pkg
|
|
22
|
+
? `${me.file}: ${me.plugin.name} needs ${pkg.name}, which isn't mounted: ortho add ${kind} ${pkg.name}`
|
|
23
|
+
: `${me.file}: ${me.plugin.name} needs a ${kind} that isn't installed: install the package it names and mount it with ortho add ${kind} <package>`);
|
|
24
|
+
}
|
|
25
|
+
return { needs: [...new Set(met)].sort(), problems };
|
|
26
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Mount } from "orthograph";
|
|
2
|
+
import type { Layout, ThingFiles } from "#modules/model/internal/layout.js";
|
|
3
|
+
/**
|
|
4
|
+
* Apply a feature mount's `omit` and `narrow` to its renamed things: an omitted operation leaves them; a narrowed one
|
|
5
|
+
* keeps the ways in named. `app` names an operation that isn't the plugin's, for the message.
|
|
6
|
+
*/
|
|
7
|
+
export declare const applyVerbs: (file: string, pkg: string, mount: Mount, things: ReadonlyArray<ThingFiles>, app: Layout) => {
|
|
8
|
+
problems: string[];
|
|
9
|
+
omitted: string[];
|
|
10
|
+
narrowed: Record<string, readonly string[]>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** The name an operation goes by in `layout`, when it is there. */
|
|
2
|
+
const nameIn = (layout, op) => {
|
|
3
|
+
for (const t of layout.things.values())
|
|
4
|
+
for (const [verb, v] of t.verbs)
|
|
5
|
+
if (v.declaration === op)
|
|
6
|
+
return `${t.name}.${verb}`;
|
|
7
|
+
return undefined;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Apply a feature mount's `omit` and `narrow` to its renamed things: an omitted operation leaves them; a narrowed one
|
|
11
|
+
* keeps the ways in named. `app` names an operation that isn't the plugin's, for the message.
|
|
12
|
+
*/
|
|
13
|
+
export const applyVerbs = (file, pkg, mount, things, app) => {
|
|
14
|
+
const problems = [];
|
|
15
|
+
const omitted = [];
|
|
16
|
+
const narrowed = {};
|
|
17
|
+
const owner = (op) => {
|
|
18
|
+
for (const t of things)
|
|
19
|
+
for (const [verb, v] of t.verbs)
|
|
20
|
+
if (v.declaration === op)
|
|
21
|
+
return { t, verb, name: `${t.name}.${verb}` };
|
|
22
|
+
return undefined;
|
|
23
|
+
};
|
|
24
|
+
for (const v of mount.verbs) {
|
|
25
|
+
if (v.verb !== "omit" && v.verb !== "narrow")
|
|
26
|
+
continue;
|
|
27
|
+
const found = owner(v.operation);
|
|
28
|
+
if (!found) {
|
|
29
|
+
problems.push(`${file}: ${v.verb}s ${nameIn(app, v.operation) ?? "an operation"}, which isn't one of ${pkg}'s operations: a mount only ${v.verb}s its own plugin's`);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (v.verb === "omit") {
|
|
33
|
+
found.t.verbs.delete(found.verb);
|
|
34
|
+
omitted.push(found.name);
|
|
35
|
+
}
|
|
36
|
+
else if (v.via.length === 0) {
|
|
37
|
+
problems.push(`${file}: narrows ${found.name} to no ways in (an empty via): omit is how an operation goes, p.omit(...)`);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
narrowed[found.name] = [...new Set(v.via)].sort();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return { problems, omitted: omitted.sort(), narrowed };
|
|
44
|
+
};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { BlueprintSource } from "#modules/source/types.js";
|
|
3
|
+
import { readLayout } from "#modules/model/internal/layout.js";
|
|
4
|
+
import { hashOf } from "#modules/model/internal/hash.js";
|
|
5
|
+
import { chosenOf, choicesIn } from "./internal/choices.js";
|
|
6
|
+
import { callsOf } from "./internal/calls.js";
|
|
7
|
+
import { renamed, renamedStores } from "./internal/fold.js";
|
|
8
|
+
import { applyVerbs } from "./internal/verbs.js";
|
|
9
|
+
import { needsOf } from "./internal/needs.js";
|
|
10
|
+
import { attributed } from "./internal/attribute.js";
|
|
11
|
+
const byName = (m) => [...m].sort(([a], [b]) => a.localeCompare(b));
|
|
12
|
+
/** Each mount matched to the installed plugin whose descriptor it imports, once, in its kind's folder. */
|
|
13
|
+
const match = (layout, plugins, problems) => {
|
|
14
|
+
const matched = [];
|
|
15
|
+
for (const [name, m] of byName(layout.mounts)) {
|
|
16
|
+
const plugin = plugins.find((p) => m.mount.plugin !== undefined && (p.descriptor === m.mount.plugin || Object.values(p.descriptors ?? {}).includes(m.mount.plugin)));
|
|
17
|
+
if (!plugin) {
|
|
18
|
+
problems.push(`${m.file}: mounts a ${m.mount.plugin?.kind ?? "plugin"} that no installed dependency in package.json provides: install its package with pnpm add --save-exact <package>`);
|
|
19
|
+
for (const p of plugins)
|
|
20
|
+
if (p.problem)
|
|
21
|
+
problems.push(`${m.file}: ${p.problem}`);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const twice = matched.find((x) => x.mount.plugin === m.mount.plugin);
|
|
25
|
+
if (twice) {
|
|
26
|
+
problems.push(`${twice.file} and ${m.file} both mount ${plugin.name}: a plugin is mounted once`);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (plugin.kind !== m.kind || m.mount.plugin.kind !== m.kind) {
|
|
30
|
+
problems.push(`${m.file}: ${plugin.name} is a ${plugin.kind}, so its mount goes in blueprint/${plugin.kind}s/, not with the ${m.kind}s`);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
matched.push({ name, kind: m.kind, file: m.file, mount: m.mount, plugin });
|
|
34
|
+
}
|
|
35
|
+
return matched;
|
|
36
|
+
};
|
|
37
|
+
/** What an adapter declared to stand in for its outside system, as the model records it. */
|
|
38
|
+
const standInOf = (descriptor) => {
|
|
39
|
+
const stand = descriptor.standIn;
|
|
40
|
+
return stand?.how === "process" || stand?.how === "vendor" ? { how: stand.how, ...(stand.what === undefined ? {} : { what: stand.what }) } : stand?.how === "none" ? { how: "none" } : undefined;
|
|
41
|
+
};
|
|
42
|
+
/** The door a mount's adapter opens: only when it has one and the mount includes an event for it to receive. */
|
|
43
|
+
const doorOf = (mount, descriptor, events) => descriptor.door !== undefined && events.length > 0 ? { secret: `${mount.toUpperCase().replaceAll("-", "_")}_WEBHOOK_SIGNING` } : undefined;
|
|
44
|
+
export const Mounts = {
|
|
45
|
+
fold: (layout) => Effect.gen(function* () {
|
|
46
|
+
if (layout.mounts.size === 0)
|
|
47
|
+
return { things: new Map(), stores: new Map(), journeys: new Map(), mounts: {}, calls: new Map(), agents: new Map(), sources: new Map(), secrets: [], problems: [] };
|
|
48
|
+
const source = yield* BlueprintSource;
|
|
49
|
+
const problems = [];
|
|
50
|
+
const plugins = yield* source.plugins.pipe(Effect.catch((e) => Effect.sync(() => { problems.push(e.message); return []; })));
|
|
51
|
+
const matched = match(layout, plugins, problems);
|
|
52
|
+
const things = new Map();
|
|
53
|
+
const calls = new Map();
|
|
54
|
+
const journeys = new Map();
|
|
55
|
+
const stores = new Map();
|
|
56
|
+
const agents = new Map();
|
|
57
|
+
const sources = new Map();
|
|
58
|
+
const extensions = [];
|
|
59
|
+
const brought = new Map();
|
|
60
|
+
const mounts = {};
|
|
61
|
+
const secrets = [];
|
|
62
|
+
for (const me of matched) {
|
|
63
|
+
const { name, file, mount, plugin } = me;
|
|
64
|
+
const { chosen, problems: picks } = chosenOf(file, plugin.name, mount, choicesIn(mount.plugin.choices), plugins);
|
|
65
|
+
problems.push(...picks);
|
|
66
|
+
const files = yield* source.pluginFiles(plugin.name).pipe(Effect.result);
|
|
67
|
+
if (files._tag === "Failure") {
|
|
68
|
+
problems.push(`${file}: ${files.failure.message}`);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
// A plugin's `blueprint/secrets.ts`, whatever its kind: its name in an environment comes from this mount and the export.
|
|
72
|
+
// A built plugin has `secrets.js`; a workspace one (every generated adapter in an app's `plugins/`) has `secrets.ts`.
|
|
73
|
+
const declared = readLayout(files.success.files.filter((f) => f.path === "secrets.js" || f.path === "secrets.ts"), (path) => `${plugin.name}/blueprint/${path}`);
|
|
74
|
+
problems.push(...declared.problems);
|
|
75
|
+
for (const s of declared.secrets.values())
|
|
76
|
+
secrets.push({ ...s, mount: name, kind: me.kind, mountFile: file, package: plugin.name, version: plugin.version });
|
|
77
|
+
let verbs = {};
|
|
78
|
+
if (me.kind === "feature" || me.kind === "adapter") {
|
|
79
|
+
// An adapter adds no operations, but its errors are declared in its things, which the model names like a feature's.
|
|
80
|
+
const own = readLayout(files.success.files.filter((f) => f.path.startsWith("things/") || (me.kind === "feature" && (f.path.startsWith("journeys/") || f.path.startsWith("stores/") || f.path.startsWith("agents/") || f.path.startsWith("sources/")))), (path) => `${plugin.name}/blueprint/${path}`);
|
|
81
|
+
// A folder of verbs and no thing.ts adds operations to a thing another plugin (or the app) brings: not a thing of its own.
|
|
82
|
+
const added = [...own.things.values()].filter((t) => !t.thing).map((t) => t.name);
|
|
83
|
+
problems.push(...own.problems.filter((p) => !added.some((n) => p === `${plugin.name}/blueprint/things/${n}: has no thing.ts`)));
|
|
84
|
+
for (const [path, journey] of own.journeys)
|
|
85
|
+
journeys.set(path, journey);
|
|
86
|
+
for (const [n, a] of own.agents) {
|
|
87
|
+
if (agents.has(n))
|
|
88
|
+
problems.push(`${file}: ${plugin.name} brings agent ${n} (${a.file}), and ${agents.get(n).mount} brings one by that name`);
|
|
89
|
+
else
|
|
90
|
+
agents.set(n, { ...a, file: `blueprint/agents/${n}.ts`, mount: name });
|
|
91
|
+
}
|
|
92
|
+
for (const [n, s] of own.sources) {
|
|
93
|
+
if (sources.has(n))
|
|
94
|
+
problems.push(`${file}: ${plugin.name} brings source ${n} (${s.file}), and ${sources.get(n).file} brings one by that name: a source is named by its file`);
|
|
95
|
+
else
|
|
96
|
+
sources.set(n, { ...s, mount: name, package: plugin.name });
|
|
97
|
+
}
|
|
98
|
+
// Each thing gets its own verbs map, so an omit changes only this mount's copy.
|
|
99
|
+
const written = me.kind === "adapter" && files.success.written ? { written: `${plugin.name}/src/written.ts` } : {};
|
|
100
|
+
const mine = renamed(own, name, plugin.name, plugin.version).map((t) => ({ ...t, ...written, verbs: new Map(t.verbs) }));
|
|
101
|
+
const applied = applyVerbs(file, plugin.name, mount, mine, layout);
|
|
102
|
+
problems.push(...applied.problems);
|
|
103
|
+
for (const s of renamedStores(own, name, plugin.name, plugin.version)) {
|
|
104
|
+
const app = layout.stores.get(s.name);
|
|
105
|
+
const other = stores.get(s.name);
|
|
106
|
+
if (app)
|
|
107
|
+
problems.push(`${file}: ${plugin.name} brings store ${s.name}, and the blueprint has one by that name, ${app.file}: mount it under another name`);
|
|
108
|
+
else if (other)
|
|
109
|
+
problems.push(`${file}: ${plugin.name} brings store ${s.name}, and ${other.file} brings one by that name: mount one under another name`);
|
|
110
|
+
else
|
|
111
|
+
stores.set(s.name, s);
|
|
112
|
+
}
|
|
113
|
+
verbs = { ...(applied.omitted.length > 0 ? { omitted: applied.omitted } : {}), ...(Object.keys(applied.narrowed).length > 0 ? { narrowed: applied.narrowed } : {}) };
|
|
114
|
+
for (const t of mine.filter((x) => !x.thing))
|
|
115
|
+
extensions.push({ file, plugin: plugin.name, t });
|
|
116
|
+
for (const t of mine.filter((x) => x.thing)) {
|
|
117
|
+
const app = layout.things.get(t.name);
|
|
118
|
+
const other = brought.get(t.name);
|
|
119
|
+
// An app folder with verbs and no thing.ts adds operations to the plugin's thing; it is not a second thing.
|
|
120
|
+
if (app?.thing)
|
|
121
|
+
problems.push(`${file}: ${plugin.name} brings thing ${t.name} (${t.base}), and the blueprint has one by that name, ${app.base}: mount it under another name`);
|
|
122
|
+
else if (other)
|
|
123
|
+
problems.push(`${file}: ${plugin.name} brings thing ${t.name} (${t.base}), and ${other.file} brings one by that name from ${other.plugin.name}: mount one under another name`);
|
|
124
|
+
else {
|
|
125
|
+
things.set(t.name, t);
|
|
126
|
+
brought.set(t.name, me);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (me.kind === "adapter") {
|
|
131
|
+
const reached = callsOf(file, plugin.name, name, mount);
|
|
132
|
+
problems.push(...reached.problems);
|
|
133
|
+
for (const [call, reach] of reached.reach)
|
|
134
|
+
calls.set(call, reach);
|
|
135
|
+
const stand = standInOf(mount.plugin);
|
|
136
|
+
const door = doorOf(name, mount.plugin, reached.events);
|
|
137
|
+
verbs = { ...verbs, ...(reached.included.length > 0 ? { calls: reached.included } : {}), ...(reached.events.length > 0 ? { events: reached.events } : {}), ...(files.success.layer ? { layer: true } : {}), ...(stand ? { standIn: stand } : {}), ...(door ? { door } : {}) };
|
|
138
|
+
}
|
|
139
|
+
const needs = needsOf(me, matched, plugins);
|
|
140
|
+
problems.push(...needs.problems);
|
|
141
|
+
const entry = { kind: me.kind, file, package: plugin.name, version: plugin.version, integrity: files.success.integrity, chosen, ...verbs, ...(needs.needs.length > 0 ? { needs: needs.needs } : {}) };
|
|
142
|
+
mounts[name] = { ...entry, hash: hashOf({ ...entry, file: undefined }) };
|
|
143
|
+
}
|
|
144
|
+
// Each such folder joins its thing; its operations are the plugin's that wrote them.
|
|
145
|
+
for (const { file, plugin, t } of extensions) {
|
|
146
|
+
// The thing it adds to is found by the thing its operations are declared on, never by the folder's name: either mount may be aliased.
|
|
147
|
+
const declaredOn = [...t.verbs.values()][0]?.declaration.thing;
|
|
148
|
+
const target = declaredOn === undefined ? undefined : [...things.values(), ...layout.things.values()].find((x) => x.thing === declaredOn);
|
|
149
|
+
if (!target?.thing) {
|
|
150
|
+
problems.push(`${file}: ${plugin} adds operations to thing ${t.from.kind === "app" ? t.name : t.from.thing}, which no mounted plugin or the app brings`);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
for (const [verb, v] of t.verbs) {
|
|
154
|
+
const taken = target.verbs.get(verb);
|
|
155
|
+
// One operation has one declaration: an added verb may not be one the thing already has, nor one another folder adds.
|
|
156
|
+
if (taken)
|
|
157
|
+
problems.push(`${file}: ${plugin} adds ${target.name}.${verb} (${v.file}), which ${target.name} already has (${taken.file}): name the operation another verb`);
|
|
158
|
+
else
|
|
159
|
+
target.verbs.set(verb, { ...v, from: t.from });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return { things, stores, journeys, mounts, calls, agents, sources, secrets, problems };
|
|
163
|
+
}),
|
|
164
|
+
attributed,
|
|
165
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Effect } from "effect";
|
|
2
|
+
import type { Agent, SourceKind } from "orthograph";
|
|
3
|
+
import type { BlueprintSource } from "#modules/source/types.js";
|
|
4
|
+
import type { Layout, MountSecret, StoreFile, ThingFiles } from "#modules/model/internal/layout.js";
|
|
5
|
+
/** What a mount adds to the model, by the mount's name. */
|
|
6
|
+
export interface MountModel {
|
|
7
|
+
readonly kind: "feature" | "adapter" | "projection";
|
|
8
|
+
readonly file: string;
|
|
9
|
+
readonly package: string;
|
|
10
|
+
readonly version: string;
|
|
11
|
+
/** `sha256-…` over the installed package's files: changed bytes at the same version change it. */
|
|
12
|
+
readonly integrity: string;
|
|
13
|
+
/** Each choice by its path in the plugin's choices, and the option picked: chosen, or the first. */
|
|
14
|
+
readonly chosen: Readonly<Record<string, string>>;
|
|
15
|
+
readonly omitted?: ReadonlyArray<string>;
|
|
16
|
+
readonly narrowed?: Readonly<Record<string, ReadonlyArray<string>>>;
|
|
17
|
+
readonly needs?: ReadonlyArray<string>;
|
|
18
|
+
/** An adapter's calls this mount includes, by the adapter's name for each: the only ones an operation may call. */
|
|
19
|
+
readonly calls?: ReadonlyArray<string>;
|
|
20
|
+
/** An adapter's events this mount includes, by the adapter's name for each: the only ones its door accepts. */
|
|
21
|
+
readonly events?: ReadonlyArray<string>;
|
|
22
|
+
/** An adapter whose door receives events this mount includes: the name of its signing secret in an environment, `<MOUNT>_WEBHOOK_SIGNING`. The Worker serves `/_in/<mount>` for it. */
|
|
23
|
+
readonly door?: {
|
|
24
|
+
readonly secret: string;
|
|
25
|
+
};
|
|
26
|
+
/** An adapter that ships a `layer.js`: the services its calls need, provided to its calls and to nothing else. */
|
|
27
|
+
readonly layer?: true;
|
|
28
|
+
/** What stands in for an adapter's outside system in a world, as the adapter declared it. */
|
|
29
|
+
readonly standIn?: {
|
|
30
|
+
readonly how: "process" | "vendor" | "none";
|
|
31
|
+
readonly what?: string;
|
|
32
|
+
};
|
|
33
|
+
readonly hash: string;
|
|
34
|
+
}
|
|
35
|
+
/** Where an adapter's call is: its mount and its name there, and whether the mount includes it. */
|
|
36
|
+
export interface CallReach {
|
|
37
|
+
readonly mount: string;
|
|
38
|
+
readonly file: string;
|
|
39
|
+
readonly package: string;
|
|
40
|
+
readonly call: string;
|
|
41
|
+
readonly included: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface BroughtAgent {
|
|
44
|
+
/** Relative to the plugin: `blueprint/agents/<name>.ts`. */
|
|
45
|
+
readonly file: string;
|
|
46
|
+
readonly declaration: Agent;
|
|
47
|
+
readonly mount: string;
|
|
48
|
+
}
|
|
49
|
+
export interface BroughtSource {
|
|
50
|
+
readonly file: string;
|
|
51
|
+
readonly declaration: SourceKind<any>;
|
|
52
|
+
readonly exportName: string;
|
|
53
|
+
readonly mount: string;
|
|
54
|
+
readonly package: string;
|
|
55
|
+
}
|
|
56
|
+
export interface Folded {
|
|
57
|
+
/** The plugins' things, under their final names, each with `from`. */
|
|
58
|
+
readonly things: ReadonlyMap<string, ThingFiles>;
|
|
59
|
+
readonly journeys: Layout["journeys"];
|
|
60
|
+
/** The plugins' stores, named by the mount and the store's path, each with `from`. */
|
|
61
|
+
readonly stores: ReadonlyMap<string, StoreFile>;
|
|
62
|
+
readonly mounts: Readonly<Record<string, MountModel>>;
|
|
63
|
+
/** Every call of every mounted adapter, by the call object an operation's step holds. */
|
|
64
|
+
readonly calls: ReadonlyMap<unknown, CallReach>;
|
|
65
|
+
/** The agent kinds the features bring, by the file's name, each with the mount that brought it. */
|
|
66
|
+
readonly agents: ReadonlyMap<string, BroughtAgent>;
|
|
67
|
+
/** The source kinds the features bring, by the file's name. */
|
|
68
|
+
readonly sources: ReadonlyMap<string, BroughtSource>;
|
|
69
|
+
/** Every mounted plugin's secrets, from its `secrets.ts`, each with the mount that brought it. */
|
|
70
|
+
readonly secrets: ReadonlyArray<MountSecret>;
|
|
71
|
+
readonly problems: ReadonlyArray<string>;
|
|
72
|
+
}
|
|
73
|
+
export interface MountsApi {
|
|
74
|
+
/** Match each mount in the layout to its installed plugin and fold the plugin in. Problems name the mount's file. */
|
|
75
|
+
readonly fold: (layout: Layout) => Effect.Effect<Folded, never, BlueprintSource>;
|
|
76
|
+
/** Each problem that names a plugin's path, prefixed with the mount file that brought the plugin in. */
|
|
77
|
+
readonly attributed: (problems: ReadonlyArray<string>, mounts: Readonly<Record<string, MountModel>>) => ReadonlyArray<string>;
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface Manifest {
|
|
2
|
+
readonly name?: string;
|
|
3
|
+
readonly version?: string;
|
|
4
|
+
readonly dependencies?: Readonly<Record<string, string>>;
|
|
5
|
+
readonly devDependencies?: Readonly<Record<string, string>>;
|
|
6
|
+
readonly peerDependencies?: Readonly<Record<string, string>>;
|
|
7
|
+
readonly orthograph?: {
|
|
8
|
+
readonly kind?: string;
|
|
9
|
+
readonly blueprint?: string;
|
|
10
|
+
readonly src?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare const readManifest: (file: string) => Manifest;
|
|
14
|
+
/** The project's dependencies, every kind, by name. */
|
|
15
|
+
export declare const dependenciesOf: (manifest: Manifest) => ReadonlyArray<string>;
|
|
16
|
+
/** Where an installed package is: the first `node_modules/<name>` from the project up. */
|
|
17
|
+
export declare const packageDir: (root: string, name: string) => string | undefined;
|
|
18
|
+
/** A file the project's own imports would load for `specifier`, as a URL. */
|
|
19
|
+
export declare const resolveFrom: (root: string, specifier: string) => string;
|
|
20
|
+
/** `sha256-<base64>` over each file's path inside the package and its bytes, in path order; over `only` those files, when given. */
|
|
21
|
+
export declare const integrityOf: (dir: string, only?: ReadonlyArray<string>) => string;
|
|
22
|
+
/** The `.js` files under a plugin's blueprint folder, or its `.ts` files when it ships as source (no build), relative to it, sorted. */
|
|
23
|
+
export declare const blueprintFilesOf: (folder: string) => ReadonlyArray<string>;
|
|
24
|
+
/** A plugin's declared blueprint folder, as installed for the project, when it has one. */
|
|
25
|
+
export declare const pluginFolder: (root: string, name: string) => string | undefined;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// The plugins a project depends on, found through its package.json and loaded from its node_modules, the way the
|
|
2
|
+
// project's own imports resolve them: so a mount's `import plugin from "@x/y"` and the compiler hold the same object.
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
import { dirname, join, relative, sep } from "node:path";
|
|
7
|
+
import { pathToFileURL } from "node:url";
|
|
8
|
+
export const readManifest = (file) => JSON.parse(readFileSync(file, "utf8"));
|
|
9
|
+
/** The project's dependencies, every kind, by name. */
|
|
10
|
+
export const dependenciesOf = (manifest) => [...new Set([...Object.keys(manifest.dependencies ?? {}), ...Object.keys(manifest.devDependencies ?? {}), ...Object.keys(manifest.peerDependencies ?? {})])].sort();
|
|
11
|
+
/** Where an installed package is: the first `node_modules/<name>` from the project up. */
|
|
12
|
+
export const packageDir = (root, name) => {
|
|
13
|
+
for (let dir = root;; dir = dirname(dir)) {
|
|
14
|
+
const candidate = join(dir, "node_modules", name);
|
|
15
|
+
if (existsSync(join(candidate, "package.json")))
|
|
16
|
+
return candidate;
|
|
17
|
+
if (dirname(dir) === dir)
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
/** A file the project's own imports would load for `specifier`, as a URL. */
|
|
22
|
+
export const resolveFrom = (root, specifier) => pathToFileURL(createRequire(join(root, "package.json")).resolve(specifier)).href;
|
|
23
|
+
const walk = (dir, keep) => readdirSync(dir).flatMap((entry) => {
|
|
24
|
+
const full = join(dir, entry);
|
|
25
|
+
return statSync(full).isDirectory() ? (entry === "node_modules" ? [] : walk(full, keep)) : keep(full) ? [full] : [];
|
|
26
|
+
});
|
|
27
|
+
const slashed = (path) => path.split(sep).join("/");
|
|
28
|
+
/** `sha256-<base64>` over each file's path inside the package and its bytes, in path order; over `only` those files, when given. */
|
|
29
|
+
export const integrityOf = (dir, only) => {
|
|
30
|
+
const hash = createHash("sha256");
|
|
31
|
+
// `only` is read as named, never by walking the package, whose scratch folders may come and go while it is read.
|
|
32
|
+
const files = only === undefined ? walk(dir, () => true).map((f) => slashed(relative(dir, f))) : only.filter((f) => existsSync(join(dir, f)));
|
|
33
|
+
for (const file of [...files].sort()) {
|
|
34
|
+
hash.update(file).update("\0").update(readFileSync(join(dir, file))).update("\0");
|
|
35
|
+
}
|
|
36
|
+
return `sha256-${hash.digest("base64")}`;
|
|
37
|
+
};
|
|
38
|
+
/** The `.js` files under a plugin's blueprint folder, or its `.ts` files when it ships as source (no build), relative to it, sorted. */
|
|
39
|
+
export const blueprintFilesOf = (folder) => {
|
|
40
|
+
const found = walk(folder, (f) => f.endsWith(".js") || (f.endsWith(".ts") && !f.endsWith(".d.ts"))).map((f) => slashed(relative(folder, f))).sort();
|
|
41
|
+
// A plugin that ships both for one file is built: the `.js` is the one loaded, never the `.ts` beside it.
|
|
42
|
+
return found.filter((f) => !(f.endsWith(".ts") && found.includes(`${f.slice(0, -3)}.js`)));
|
|
43
|
+
};
|
|
44
|
+
/** A plugin's declared blueprint folder, as installed for the project, when it has one. */
|
|
45
|
+
export const pluginFolder = (root, name) => {
|
|
46
|
+
const dir = packageDir(root, name);
|
|
47
|
+
const declared = dir ? readManifest(join(dir, "package.json")).orthograph?.blueprint : undefined;
|
|
48
|
+
return dir && declared && existsSync(join(dir, declared)) ? join(dir, declared) : undefined;
|
|
49
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Layer } from "effect";
|
|
2
|
+
import { BlueprintSource } from "./types.ts";
|
|
3
|
+
/** The blueprint as it is on disk, loaded with Node's own module loader; plugins as the project resolves them. */
|
|
4
|
+
export declare const nodeSource: (given: string) => Layer.Layer<BlueprintSource, never, never>;
|
|
5
|
+
/** Where the project has a package installed, and a plugin's blueprint folder: for the loaders that run journeys. */
|
|
6
|
+
export { packageDir, pluginFolder, resolveFrom } from "./internal/plugins.ts";
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { createHash } from "node:crypto";
|
|
10
|
+
import { readFileSync, existsSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
11
|
+
import { join, relative, sep } from "node:path";
|
|
12
|
+
import { pathToFileURL } from "node:url";
|
|
13
|
+
import { Effect, Layer } from "effect";
|
|
14
|
+
import { BlueprintSource, SourceError } from "./types.js";
|
|
15
|
+
import { blueprintFilesOf, dependenciesOf, integrityOf, packageDir, readManifest, resolveFrom } from "./internal/plugins.js";
|
|
16
|
+
const walk = (dir) => readdirSync(dir).flatMap((entry) => {
|
|
17
|
+
const full = join(dir, entry);
|
|
18
|
+
return statSync(full).isDirectory() ? walk(full) : full.endsWith(".ts") && !full.endsWith(".d.ts") ? [full] : [];
|
|
19
|
+
});
|
|
20
|
+
const importing = (url, what) => Effect.tryPromise({
|
|
21
|
+
try: () => import(__rewriteRelativeImportExtension(url)),
|
|
22
|
+
catch: (e) => new SourceError({ message: `can't load ${what}: ${String(e)}` }),
|
|
23
|
+
});
|
|
24
|
+
/** The blueprint as it is on disk, loaded with Node's own module loader; plugins as the project resolves them. */
|
|
25
|
+
export const nodeSource = (given) => {
|
|
26
|
+
// By its real path: a module loader that resolves imports to real paths (Vite's does) would otherwise load a file
|
|
27
|
+
// twice, once under a symlinked path such as macOS's /var and once under /private/var, and identity would break.
|
|
28
|
+
const projectRoot = existsSync(given) ? realpathSync(given) : given;
|
|
29
|
+
const root = join(projectRoot, "blueprint");
|
|
30
|
+
const sync = (what, f) => Effect.try({ try: f, catch: (e) => new SourceError({ message: `${what}: ${String(e)}` }) });
|
|
31
|
+
const loadFile = (path, file, label) => importing(pathToFileURL(file).href, label).pipe(Effect.flatMap((exports) => /(?:^|\/)(?:journeys|starting-worlds)\//.test(path)
|
|
32
|
+
? sync(`can't hash ${label}`, () => ({ path, exports, sourceHash: createHash("sha256").update(readFileSync(file)).digest("hex") }))
|
|
33
|
+
: Effect.succeed({ path, exports })));
|
|
34
|
+
const plugin = (name) => Effect.gen(function* () {
|
|
35
|
+
const dir = packageDir(projectRoot, name);
|
|
36
|
+
// Installed but with no package.json: it may be the plugin a mount imports, so it is named, never passed over.
|
|
37
|
+
if (!dir)
|
|
38
|
+
return existsSync(join(projectRoot, "node_modules", name))
|
|
39
|
+
? { name, version: "", kind: "", descriptor: undefined, problem: `${name}: is installed with no package.json, so it can't be read as a plugin: reinstall it` }
|
|
40
|
+
: undefined;
|
|
41
|
+
const manifest = yield* sync(`can't read ${name}'s package.json`, () => readManifest(join(dir, "package.json")));
|
|
42
|
+
if (!manifest.orthograph)
|
|
43
|
+
return undefined;
|
|
44
|
+
const known = { name, version: manifest.version ?? "0.0.0", kind: manifest.orthograph.kind ?? "" };
|
|
45
|
+
const loaded = yield* Effect.result(Effect.flatMap(sync(`can't resolve ${name}`, () => resolveFrom(projectRoot, name)), (url) => importing(url, name)));
|
|
46
|
+
return loaded._tag === "Success"
|
|
47
|
+
? { ...known, descriptor: loaded.success["default"], descriptors: Object.fromEntries(Object.entries(loaded.success).filter(([, v]) => ["feature", "adapter", "projection"].includes(String(v?.kind)))) }
|
|
48
|
+
: { ...known, descriptor: undefined, problem: `${name}: its root export can't be loaded (${loaded.failure.message})` };
|
|
49
|
+
});
|
|
50
|
+
const journeys = join(projectRoot, "journeys");
|
|
51
|
+
return Layer.succeed(BlueprintSource, {
|
|
52
|
+
list: sync(`can't list ${root}`, () => [
|
|
53
|
+
...walk(root).map((f) => relative(root, f).split(sep).join("/")),
|
|
54
|
+
...(existsSync(journeys) ? readdirSync(journeys, { withFileTypes: true })
|
|
55
|
+
.filter((f) => f.isFile() && f.name.endsWith(".ts") && !f.name.endsWith(".d.ts"))
|
|
56
|
+
.map((f) => `../journeys/${f.name}`) : []),
|
|
57
|
+
].sort()),
|
|
58
|
+
load: (path) => loadFile(path, join(root, path), path.startsWith("../") ? path.slice(3) : `blueprint/${path}`),
|
|
59
|
+
lock: sync("can't read blueprint/refusals.lock", () => (existsSync(join(root, "refusals.lock")) ? readFileSync(join(root, "refusals.lock"), "utf8") : undefined)),
|
|
60
|
+
plugins: Effect.gen(function* () {
|
|
61
|
+
const manifest = yield* sync("can't read the project's package.json", () => readManifest(join(projectRoot, "package.json")));
|
|
62
|
+
const found = yield* Effect.forEach(dependenciesOf(manifest), plugin);
|
|
63
|
+
return found.filter((p) => p !== undefined);
|
|
64
|
+
}),
|
|
65
|
+
pluginFiles: (name) => Effect.gen(function* () {
|
|
66
|
+
const dir = packageDir(projectRoot, name);
|
|
67
|
+
if (!dir)
|
|
68
|
+
return yield* new SourceError({ message: `${name}: isn't installed` });
|
|
69
|
+
const manifest = readManifest(join(dir, "package.json")).orthograph;
|
|
70
|
+
const declared = manifest?.blueprint;
|
|
71
|
+
// A projection brings no declarations and owns no operations to stale: its mount's hash holds its identity (its
|
|
72
|
+
// package.json), not its sources. What it writes is guarded by drift (`ortho check`), not by the mount's hash (M1.11).
|
|
73
|
+
if (manifest?.kind === "projection" && declared === undefined)
|
|
74
|
+
return { integrity: yield* sync(`can't read ${name}`, () => integrityOf(dir, ["package.json"])), files: [] };
|
|
75
|
+
const folder = declared ? join(dir, declared) : undefined;
|
|
76
|
+
if (!folder || !existsSync(folder)) {
|
|
77
|
+
return yield* new SourceError({ message: `${name}: its package.json declares no blueprint folder that exists (orthograph.blueprint is ${JSON.stringify(declared ?? null)})` });
|
|
78
|
+
}
|
|
79
|
+
const integrity = yield* sync(`can't read ${name}`, () => integrityOf(dir));
|
|
80
|
+
const files = yield* Effect.forEach(blueprintFilesOf(folder), (path) => loadFile(path, join(folder, path), `${name}/blueprint/${path}`).pipe(Effect.map((loaded) => ({ ...loaded, specifier: `${name}/blueprint/${path}` }))));
|
|
81
|
+
return { integrity, layer: manifest?.src !== undefined && existsSync(join(dir, manifest.src, "layer.js")), ...(existsSync(join(dir, "src/written.ts")) ? { written: true } : {}), files };
|
|
82
|
+
}),
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
/** Where the project has a package installed, and a plugin's blueprint folder: for the loaders that run journeys. */
|
|
86
|
+
export { packageDir, pluginFolder, resolveFrom } from "./internal/plugins.js";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Context, type Effect } from "effect";
|
|
2
|
+
declare const SourceError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
3
|
+
readonly _tag: "SourceError";
|
|
4
|
+
} & Readonly<A>;
|
|
5
|
+
export declare class SourceError extends SourceError_base<{
|
|
6
|
+
readonly message: string;
|
|
7
|
+
}> {
|
|
8
|
+
}
|
|
9
|
+
/** One blueprint file: its path under `blueprint/`, with forward slashes, and what it exports. */
|
|
10
|
+
export interface LoadedFile {
|
|
11
|
+
readonly path: string;
|
|
12
|
+
readonly exports: Readonly<Record<string, unknown>>;
|
|
13
|
+
readonly sourceHash?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* An installed package the project depends on whose `package.json` has an `orthograph` key (M1-plugins section 1): a
|
|
17
|
+
* plugin. `descriptor` is its root export, the same object a mount imports. `problem` says why it can't be used.
|
|
18
|
+
*/
|
|
19
|
+
export interface PluginPackage {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly version: string;
|
|
22
|
+
readonly kind: string;
|
|
23
|
+
readonly descriptor: unknown;
|
|
24
|
+
/** Every plugin descriptor its root export holds, by export name: a package that ships several (`@orthograph/projections`) has no default. */
|
|
25
|
+
readonly descriptors?: Readonly<Record<string, unknown>>;
|
|
26
|
+
readonly problem?: string;
|
|
27
|
+
}
|
|
28
|
+
/** A plugin's declarations: each `.js` under its declared `blueprint` folder, and a digest of the installed package. */
|
|
29
|
+
export interface PluginFiles {
|
|
30
|
+
/** `sha256-…` over every file of the installed package: its path inside the package, and its bytes. */
|
|
31
|
+
readonly integrity: string;
|
|
32
|
+
/** Whether its declared `src` folder has a `layer.js`: the services its handlers and calls need. */
|
|
33
|
+
readonly layer?: boolean;
|
|
34
|
+
/** Whether it has a `src/written.ts`: a generated adapter's, where its refusal code prefix and exit base are set by hand. */
|
|
35
|
+
readonly written?: boolean;
|
|
36
|
+
/** `path` is relative to the blueprint folder (`things/echo/thing.js`); `specifier` is how code imports it. */
|
|
37
|
+
readonly files: ReadonlyArray<LoadedFile & {
|
|
38
|
+
readonly specifier: string;
|
|
39
|
+
}>;
|
|
40
|
+
}
|
|
41
|
+
declare const BlueprintSource_base: Context.ServiceClass<BlueprintSource, "@orthograph/compiler/BlueprintSource", {
|
|
42
|
+
/** Blueprint files and root journeys, sorted, with paths relative to `blueprint/`. */
|
|
43
|
+
readonly list: Effect.Effect<ReadonlyArray<string>, SourceError>;
|
|
44
|
+
/** Import one file by its relative path. Blueprint files must have no side effects on import. */
|
|
45
|
+
readonly load: (path: string) => Effect.Effect<LoadedFile, SourceError>;
|
|
46
|
+
/** The text of `blueprint/refusals.lock` (M6-chain item 4), or undefined when the project has none yet. A source with no lock to give leaves this out. */
|
|
47
|
+
readonly lock?: Effect.Effect<string | undefined, SourceError>;
|
|
48
|
+
/** The plugins among the project's dependencies, by package name. */
|
|
49
|
+
readonly plugins: Effect.Effect<ReadonlyArray<PluginPackage>, SourceError>;
|
|
50
|
+
/** One plugin's declarations, loaded from where the project resolves them. Fails naming the package when it can't. */
|
|
51
|
+
readonly pluginFiles: (name: string) => Effect.Effect<PluginFiles, SourceError>;
|
|
52
|
+
}>;
|
|
53
|
+
export declare class BlueprintSource extends BlueprintSource_base {
|
|
54
|
+
}
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Where blueprint files come from: listed under a root, and loaded as modules. The compiler sees only this.
|
|
2
|
+
import { Context, Data } from "effect";
|
|
3
|
+
export class SourceError extends Data.TaggedError("SourceError") {
|
|
4
|
+
}
|
|
5
|
+
export class BlueprintSource extends Context.Service()("@orthograph/compiler/BlueprintSource") {
|
|
6
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { isZone } from "./zones.js";
|
|
2
|
+
const WEEKDAYS = new Set(["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]);
|
|
3
|
+
/** The type of a field of the thing, or nothing when it has no such field. */
|
|
4
|
+
const typeOf = (thing, field) => {
|
|
5
|
+
const f = Object.hasOwn(thing.fields, field) ? thing.fields[field] : undefined;
|
|
6
|
+
return f === undefined ? undefined : f.value.meta.type;
|
|
7
|
+
};
|
|
8
|
+
/** A field the anchor names: the thing must have it and it must be an instant. */
|
|
9
|
+
const instantField = (where, thing, field, what) => {
|
|
10
|
+
const type = typeOf(thing, field);
|
|
11
|
+
if (type === undefined)
|
|
12
|
+
return [`${where} is made by time, but its ${what} ${field} isn't a field of the thing`];
|
|
13
|
+
return type === "instant" ? [] : [`${where} is made by time, but its ${what} ${field} isn't a time (an instant), it is ${type}`];
|
|
14
|
+
};
|
|
15
|
+
const zoneProblems = (where, thing, zone) => {
|
|
16
|
+
if (isZone(zone))
|
|
17
|
+
return [];
|
|
18
|
+
const type = typeOf(thing, zone);
|
|
19
|
+
if (type === "text")
|
|
20
|
+
return [];
|
|
21
|
+
return [`${where} is made by time, but its zone "${zone}" is neither in the tz database nor a text field of the thing`];
|
|
22
|
+
};
|
|
23
|
+
export const anchorProblems = (where, thing, by) => {
|
|
24
|
+
if (by.kind === "after")
|
|
25
|
+
return instantField(where, thing, by.field, "after field");
|
|
26
|
+
const { from, on, zone } = by;
|
|
27
|
+
if (from === undefined && on === undefined)
|
|
28
|
+
return [`${where} is made by time, but every needs a \`from\` field of the thing, or a calendar anchor (\`on\`) with a zone`];
|
|
29
|
+
if (from !== undefined && on !== undefined)
|
|
30
|
+
return [`${where} is made by time, but it names both \`from\` and \`on\`: an anchor is one or the other`];
|
|
31
|
+
const found = [];
|
|
32
|
+
if (from !== undefined)
|
|
33
|
+
found.push(...instantField(where, thing, from, "anchor field"));
|
|
34
|
+
if (on !== undefined) {
|
|
35
|
+
if ("weekday" in on) {
|
|
36
|
+
if (!WEEKDAYS.has(on.weekday))
|
|
37
|
+
found.push(`${where} is made by time, but its weekday "${on.weekday}" isn't a day of the week`);
|
|
38
|
+
}
|
|
39
|
+
else if (on.day !== "last" && !(Number.isInteger(on.day) && on.day >= 1 && on.day <= 31)) {
|
|
40
|
+
found.push(`${where} is made by time, but its day ${String(on.day)} isn't from 1 to 31, or "last"`);
|
|
41
|
+
}
|
|
42
|
+
if (zone === undefined)
|
|
43
|
+
found.push(`${where} is made by time on a calendar day, but names no zone: give a tz database zone ("Europe/London") or a text field of the thing, so nothing silently runs in UTC`);
|
|
44
|
+
}
|
|
45
|
+
if (zone !== undefined)
|
|
46
|
+
found.push(...zoneProblems(where, thing, zone));
|
|
47
|
+
return found;
|
|
48
|
+
};
|