@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,99 @@
|
|
|
1
|
+
import { Blanks } from "orthograph/server";
|
|
2
|
+
import { Times } from "#modules/time/service.js";
|
|
3
|
+
import { RefusalLock } from "#modules/lock/service.js";
|
|
4
|
+
import { MACHINE_NUMBER, inDeclarationOrder } from "./codes.js";
|
|
5
|
+
import { NOT_FOUND_NUMBER, notFoundOf } from "./found.js";
|
|
6
|
+
import { roleRuleOf } from "./bits.js";
|
|
7
|
+
import { hashOf } from "./hash.js";
|
|
8
|
+
import { invariantsOf } from "./invariants.js";
|
|
9
|
+
import { pascal } from "./layout.js";
|
|
10
|
+
import { lockFields } from "./lock-fields.js";
|
|
11
|
+
/** A module's exports in name order: a namespace's own order differs between loaders, and the model must not. */
|
|
12
|
+
const byName = (m) => [...m].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
13
|
+
const problem = (problems, p) => {
|
|
14
|
+
problems.push(p);
|
|
15
|
+
return "?";
|
|
16
|
+
};
|
|
17
|
+
export const thingsOf = (env) => {
|
|
18
|
+
const { layout, before, problems, prefix, missable, verbs, chain, thingNames, eventNames, errorNames, fieldsModel, fieldModel, blankIn } = env;
|
|
19
|
+
/** The declared store a thing lives in, by name: absent for the default store. */
|
|
20
|
+
const storeOf = (store, where) => store ? { store: chain.storeNames.get(store) ?? problem(problems, `${where}/thing.ts: lives in a store that isn't a default export of a stores/<name>.ts`) } : {};
|
|
21
|
+
// G4's `unique:` key is retired (S-30): a thing still carrying it is refused, by thing name only (never a field name).
|
|
22
|
+
for (const [n, t] of layout.things)
|
|
23
|
+
if (t.thing && "unique" in t.thing)
|
|
24
|
+
problems.push(`thing ${n} declares unique, which is retired: declare it with Blueprint.invariant.unique in blueprint/things/${n}/invariants.ts`);
|
|
25
|
+
// The id prefixes some thing owns: its own `id` field's. A field that names another prefix names nothing.
|
|
26
|
+
// `per` is the identity's own: the people who sign in are a thing of Better Auth's, which a blueprint refers to without declaring.
|
|
27
|
+
const owned = new Set(["per", ...[...layout.things.values()].flatMap((t) => { const m = t.thing?.fields["id"]?.value.meta; return m?.type === "id" ? [m.prefix] : []; })]);
|
|
28
|
+
const wanted = [];
|
|
29
|
+
const drafts = [...layout.things].sort(([a], [b]) => a.localeCompare(b)).flatMap(([name, t]) => {
|
|
30
|
+
if (!t.thing)
|
|
31
|
+
return [];
|
|
32
|
+
const where = t.base;
|
|
33
|
+
const onChain = chain.is(t.thing);
|
|
34
|
+
const ctx = { owner: { name, thing: t.thing }, chain: onChain };
|
|
35
|
+
const code = prefix.get(name) ?? "??";
|
|
36
|
+
const fields = Object.fromEntries(Object.entries(t.thing.fields).map(([k, f]) => [k, fieldModel(f.issued === true ? f : f.from ?? f.value, `${where}/thing.ts field ${k}`, { place: "a thing's field", ...ctx })]));
|
|
37
|
+
const m = t.machine;
|
|
38
|
+
blankIn(name, {
|
|
39
|
+
description: t.thing.description, states: m?.declared,
|
|
40
|
+
...Object.fromEntries([...t.roles].map(([r, role]) => [`role ${r}`, role.rule])),
|
|
41
|
+
});
|
|
42
|
+
const states = m && !Blanks.isBlank(m.declared) ? m.declared : [];
|
|
43
|
+
const machine = m
|
|
44
|
+
? {
|
|
45
|
+
states,
|
|
46
|
+
moves: Object.fromEntries(Object.entries(m.moves).map(([k, mv]) => [k, {
|
|
47
|
+
from: mv.from, to: mv.to, emits: eventNames.get(mv.emits) ?? problem(problems, `${where}/machine.ts move ${k}: emits an event not exported from events.ts`),
|
|
48
|
+
...Times.timed({ name, thing: t.thing, key: k, move: mv, file: `${where}/machine.ts`, problems }),
|
|
49
|
+
}])),
|
|
50
|
+
notFrom: { error: `${pascal(name)}Not${pascal(states[0] ?? "")}`, exit: m.notFrom.exit },
|
|
51
|
+
}
|
|
52
|
+
: null;
|
|
53
|
+
if (m && m.thing !== t.thing)
|
|
54
|
+
problems.push(`${where}/machine.ts: is a machine of another thing`);
|
|
55
|
+
const invariants = invariantsOf(t, { thingNames, errorNames, verbs }, problems);
|
|
56
|
+
if (t.thing.versions !== undefined && !(t.thing.versions.key in t.thing.fields))
|
|
57
|
+
problems.push(`${where}/thing.ts: versions key ${t.thing.versions.key} is not a field of ${name}`);
|
|
58
|
+
for (const [k, f] of Object.entries(t.thing.fields)) {
|
|
59
|
+
const meta = f.value.meta;
|
|
60
|
+
if (k !== "id" && meta.type === "id" && !owned.has(meta.prefix))
|
|
61
|
+
problems.push(`${where}/thing.ts field ${k}: the id prefix "${meta.prefix}" is no thing's own id: name a prefix some thing owns`);
|
|
62
|
+
}
|
|
63
|
+
if (onChain && t.invariants.size > 0)
|
|
64
|
+
problems.push(`${where}/invariants.ts: ${name} lives in a chain store, which enforces no invariants yet: a chain-stored thing declares none`);
|
|
65
|
+
const errors = inDeclarationOrder(t.errors).map(([n, e]) => ({ name: n, fields: fieldsModel(e.fields, `${where}/errors.ts ${n}`, { place: "an error", ...ctx }), exit: e.exit }));
|
|
66
|
+
const events = Object.fromEntries(byName(t.events).map(([n, e]) => [n, fieldsModel(e.fields, `${where}/events.ts ${n}`, { place: "an event", ...ctx })]));
|
|
67
|
+
for (const role of t.roles.values()) {
|
|
68
|
+
if (role.who !== undefined && role.who.of !== t.thing)
|
|
69
|
+
problems.push(`${where}/roles.ts: a who role names a field of another thing; a role's who is a field of ${name}`);
|
|
70
|
+
}
|
|
71
|
+
const roleRules = Object.fromEntries(byName(t.roles).map(([role, r]) => [role, r.who !== undefined ? { kind: "who", who: r.who.key } : Blanks.isBlank(r.rule) ? null : roleRuleOf(r)]));
|
|
72
|
+
// Every refusal this thing has, for the lock: its declared errors in order, the machine's 900 and the generated not-found, 901.
|
|
73
|
+
const owner = name;
|
|
74
|
+
const idValue = t.thing.fields["id"]?.value.meta;
|
|
75
|
+
wanted.push(...errors.map((e) => ({ name: e.name, owner, from: t.from.kind !== "app" ? `${t.from.package}/blueprint/things/${t.from.thing}/errors.js` : `${where}/errors.ts`, fields: lockFields(e.fields), prefix: code })), ...(machine ? [{ name: machine.notFrom.error, owner, fields: { state: { value: "text", max: 64 } }, code: `${code}-${MACHINE_NUMBER}`, prefix: code }] : []), ...(missable.has(t.thing) && !t.errors.has(`${pascal(name)}NotFound`)
|
|
76
|
+
? [{ name: `${pascal(name)}NotFound`, owner, fields: { id: idValue?.type === "id" ? { value: "id", prefix: idValue.prefix } : { value: "text", max: 200 } }, code: `${code}-${NOT_FOUND_NUMBER}`, prefix: code }] : []));
|
|
77
|
+
const stateNumbers = onChain && m ? Object.fromEntries(["absent", ...states].map((s, i) => [s, i])) : undefined;
|
|
78
|
+
return [{ name, t, where, code, fields, machine, invariants, errors, events, roleRules, roles: [...t.roles.keys()].sort(), stateNumbers, onChain }];
|
|
79
|
+
});
|
|
80
|
+
const runtime = RefusalLock.runtime(chain.has);
|
|
81
|
+
const { lock, codes } = RefusalLock.assign(before, [...runtime, ...wanted]);
|
|
82
|
+
const given = new Map(wanted.map((w, i) => [`${w.owner}/${w.name}`, codes[runtime.length + i] ?? "??"]));
|
|
83
|
+
const codeFor = (thing, error) => given.get(`${thing}/${error}`) ?? "??";
|
|
84
|
+
const things = {};
|
|
85
|
+
for (const d of drafts) {
|
|
86
|
+
const errors = Object.fromEntries(d.errors.map((e) => [e.name, { fields: e.fields, exit: e.exit, code: codeFor(d.name, e.name) }]));
|
|
87
|
+
const machine = d.machine ? { ...d.machine, notFrom: { ...d.machine.notFrom, code: `${d.code}-${MACHINE_NUMBER}` } } : null;
|
|
88
|
+
const entry = {
|
|
89
|
+
name: d.name, identifier: pascal(d.name), code: d.code, description: Blanks.isBlank(d.t.thing.description) ? "" : d.t.thing.description, fields: d.fields, ...(d.t.thing.versions ? { versions: { key: d.t.thing.versions.key } } : {}),
|
|
90
|
+
lives: (d.t.thing.lives ?? "database"), ...storeOf(d.t.thing.store, d.where), ...(d.invariants ? { invariants: d.invariants } : {}), machine,
|
|
91
|
+
events: d.events,
|
|
92
|
+
errors, ...(missable.has(d.t.thing) ? { notFound: notFoundOf(pascal(d.name), `${d.code}-${NOT_FOUND_NUMBER}`, errors) } : {}),
|
|
93
|
+
roles: d.roles, roleRules: d.roleRules, ...(d.stateNumbers ? { stateNumbers: d.stateNumbers } : {}),
|
|
94
|
+
from: d.t.from,
|
|
95
|
+
};
|
|
96
|
+
things[d.name] = { ...entry, hash: hashOf(entry) };
|
|
97
|
+
}
|
|
98
|
+
return { things, lock };
|
|
99
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { ErrorNames, EventNames } from "orthograph/server";
|
|
3
|
+
import { BlueprintSource } from "#modules/source/types.js";
|
|
4
|
+
import { RefusalLock } from "#modules/lock/service.js";
|
|
5
|
+
import { BlueprintInvalid } from "./types.js";
|
|
6
|
+
import { hashOf } from "./internal/hash.js";
|
|
7
|
+
import { describe } from "./internal/describe.js";
|
|
8
|
+
import { readLayout } from "./internal/layout.js";
|
|
9
|
+
import { Mounts } from "#modules/mounts/service.js";
|
|
10
|
+
import { App } from "#modules/app/service.js";
|
|
11
|
+
const locked = Effect.gen(function* () {
|
|
12
|
+
const source = yield* BlueprintSource;
|
|
13
|
+
const paths = yield* source.list;
|
|
14
|
+
const files = yield* Effect.forEach(paths, source.load);
|
|
15
|
+
const { app: appFiles, rest } = App.setAside(files);
|
|
16
|
+
const layout = readLayout(rest);
|
|
17
|
+
// Each mount's plugin, folded in: its things beside the project's own, under the names the mount gives them.
|
|
18
|
+
const folded = yield* Mounts.fold(layout);
|
|
19
|
+
// An app folder of verbs with no thing.ts adds operations to a plugin's thing: they join it, and are the app's.
|
|
20
|
+
// It finds the thing by the thing its operations are declared on, so a plugin mounted under an alias is found as well.
|
|
21
|
+
for (const [folder, own] of [...layout.things]) {
|
|
22
|
+
if (own.thing)
|
|
23
|
+
continue;
|
|
24
|
+
const declaredOn = [...own.verbs.values()][0]?.declaration.thing;
|
|
25
|
+
const found = declaredOn === undefined ? undefined : [...folded.things].find(([, x]) => x.thing === declaredOn);
|
|
26
|
+
if (!found)
|
|
27
|
+
continue;
|
|
28
|
+
const [name, t] = found;
|
|
29
|
+
for (const [verb, v] of own.verbs) {
|
|
30
|
+
const taken = t.verbs.get(verb);
|
|
31
|
+
// One operation has one declaration: the app may not add a verb the thing already has, from its plugin or another folder.
|
|
32
|
+
if (taken)
|
|
33
|
+
layout.problems.push(`${v.file}: adds ${name}.${verb}, which ${name} already has (${taken.file}): name the operation another verb`);
|
|
34
|
+
else
|
|
35
|
+
t.verbs.set(verb, { ...v, from: { kind: "app" } });
|
|
36
|
+
}
|
|
37
|
+
const at = layout.problems.indexOf(`${own.base}: has no thing.ts`);
|
|
38
|
+
if (at >= 0)
|
|
39
|
+
layout.problems.splice(at, 1);
|
|
40
|
+
layout.things.delete(folder);
|
|
41
|
+
}
|
|
42
|
+
for (const [name, t] of folded.things)
|
|
43
|
+
layout.things.set(name, t);
|
|
44
|
+
for (const [n, a] of folded.agents) {
|
|
45
|
+
const mine = layout.agents.get(n);
|
|
46
|
+
if (mine)
|
|
47
|
+
layout.problems.push(`${mine.file}: the app's agent ${n} has the name of the one ${a.mount} brings (${a.file}): an agent is named by its file`);
|
|
48
|
+
else
|
|
49
|
+
layout.agents.set(n, a);
|
|
50
|
+
}
|
|
51
|
+
for (const [n, s] of folded.sources) {
|
|
52
|
+
const mine = layout.sources.get(n);
|
|
53
|
+
if (mine)
|
|
54
|
+
layout.problems.push(`${mine.file}: the app's source ${n} has the name of the one ${s.mount} brings (${s.file}): a source is named by its file`);
|
|
55
|
+
else
|
|
56
|
+
layout.sources.set(n, s);
|
|
57
|
+
}
|
|
58
|
+
for (const [call, reach] of folded.calls)
|
|
59
|
+
layout.calls.set(call, reach);
|
|
60
|
+
for (const [file, journey] of folded.journeys)
|
|
61
|
+
layout.journeys.set(file, journey);
|
|
62
|
+
for (const [name, s] of folded.stores)
|
|
63
|
+
layout.stores.set(name, s);
|
|
64
|
+
layout.mountSecrets.push(...folded.secrets);
|
|
65
|
+
layout.problems.push(...folded.problems);
|
|
66
|
+
// Errors take their names from their exports; stamping them here lets the loaded classes be used by name.
|
|
67
|
+
for (const t of layout.things.values())
|
|
68
|
+
for (const [name, cls] of t.errors)
|
|
69
|
+
ErrorNames.name(cls, name);
|
|
70
|
+
for (const t of layout.things.values())
|
|
71
|
+
for (const [name, event] of t.events)
|
|
72
|
+
EventNames.name(event, name);
|
|
73
|
+
// The codes come from the lock the project keeps (M6-chain item 4): a name keeps its code, a new name takes the next number.
|
|
74
|
+
const text = source.lock === undefined ? undefined : yield* source.lock;
|
|
75
|
+
const before = yield* RefusalLock.parse(text).pipe(Effect.mapError((e) => new BlueprintInvalid({ problems: [`blueprint/refusals.lock: ${e.message}`] })));
|
|
76
|
+
const described = describe(layout, before, folded.mounts);
|
|
77
|
+
const { app, problems: appProblems } = App.describe(appFiles, layout, described.model);
|
|
78
|
+
const problems = [...described.problems, ...appProblems];
|
|
79
|
+
if (problems.length > 0)
|
|
80
|
+
return yield* new BlueprintInvalid({ problems: Mounts.attributed(problems, folded.mounts) });
|
|
81
|
+
const { lock } = described;
|
|
82
|
+
const model = app ? { ...described.model, app } : described.model;
|
|
83
|
+
return { model: Object.keys(folded.mounts).length > 0 ? { ...narrowed(model, folded.mounts), mounts: folded.mounts } : model, lock: RefusalLock.text(lock) };
|
|
84
|
+
});
|
|
85
|
+
export const Compiler = {
|
|
86
|
+
model: Effect.map(locked, (c) => c.model),
|
|
87
|
+
locked,
|
|
88
|
+
};
|
|
89
|
+
/** An operation a mount narrowed keeps only the ways in named: `via` on it, in its hash; it is an agent's tool only while `agent` is kept. */
|
|
90
|
+
const narrowed = (model, mounts) => {
|
|
91
|
+
const operations = { ...model.operations };
|
|
92
|
+
for (const m of Object.values(mounts)) {
|
|
93
|
+
for (const [name, via] of Object.entries(m.narrowed ?? {})) {
|
|
94
|
+
const op = operations[name];
|
|
95
|
+
if (!op)
|
|
96
|
+
continue;
|
|
97
|
+
const { hash: _, ...entry } = op;
|
|
98
|
+
const agentTool = entry.agentTool && via.includes("agent");
|
|
99
|
+
operations[name] = { ...entry, agentTool, via, hash: hashOf({ ...entry, agentTool, via }) };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return { ...model, operations };
|
|
103
|
+
};
|
|
104
|
+
export { canonical } from "./internal/hash.js";
|
|
105
|
+
export { DEVICE_HOSTS, handlerFiles, isVersioned } from "./internal/handler-files.js";
|