suppa-mcp-2 1.47.0 → 1.47.3
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/README.md +2 -2
- package/dist/server.js +3 -3
- package/dist/toolTable.js +1 -1
- package/dist/tools/formInheritance.js +238 -0
- package/dist/tools/formLifecycle.js +117 -6
- package/dist/tools/formV2.js +126 -10
- package/package.json +1 -1
- package/skills/suppa-form-v2/SKILL.md +5 -5
- package/skills/suppa-form-v2/SOURCE.json +4 -4
- package/skills/suppa-form-v2/data/base-props.json +9 -0
- package/skills/suppa-form-v2/data/component-index.json +32 -1
- package/skills/suppa-form-v2/data/component-props.json +1199 -19
- package/skills/suppa-form-v2/data/templates/entity-workspace.json +22 -23
- package/skills/suppa-form-v2/data/templates/list-management.json +22 -0
- package/skills/suppa-form-v2/notes/dynamicComponent.md +57 -1
- package/skills/suppa-form-v2/references/choosing-elements.md +2 -2
- package/skills/suppa-form-v2/references/code-form.md +13 -0
- package/skills/suppa-form-v2/references/publishing.md +2 -0
- package/skills/suppa-form-v2/scripts/form-core.mjs +979 -488
- package/skills/suppa-form-v2/scripts/form-rules.mjs +2 -2
- package/skills/suppa-form-v2/scripts/manifest-corrections.mjs +37 -0
- package/skills/suppa-form-v2/scripts/validate-form-schema.mjs +188 -10
package/README.md
CHANGED
|
@@ -573,12 +573,12 @@ Of the seven above, `suppa_get_form` reads both generations: since 1.43.3 a 2.x
|
|
|
573
573
|
the builder reads it (schema, variables, localizations, the Code Form's files). The other six are
|
|
574
574
|
**Suppa 1.0** forms: they read and write `data.formShema` (the platform's misspelling) and the v1
|
|
575
575
|
field types. A **Suppa 2.0** entity-builder form is a different product —
|
|
576
|
-
the `schema` column on the row since 2.1,
|
|
576
|
+
the `schema` column on the row since 2.1, 62 component types — and is served by the eight below plus the bundled
|
|
577
577
|
`skills/suppa-form-v2` skill. The first two touch no tenant: they read files inside the package.
|
|
578
578
|
|
|
579
579
|
| Tool | Description |
|
|
580
580
|
|---|---|
|
|
581
|
-
| `suppa_form_kb` | The 2.0 form knowledge base: the
|
|
581
|
+
| `suppa_form_kb` | The 2.0 form knowledge base: the 62 element types, one type's prop table, a behaviour note, a reference topic, a template |
|
|
582
582
|
| `suppa_validate_form_schema` | Run the 2.0 form gate over a draft before writing it — 37 structural error codes (the authoring lints live in the source agent, not here), each chart's and each custom chart source's readiness, and widget code: every widget template is compiled with the builder's own compiler (`@vue/compiler-dom` 3.5.12, the esm-bundler production build the builder runs) into the `compiledRender` the runtime executes, and checked against the widget sandbox |
|
|
583
583
|
| `suppa_write_form_draft` | Save a checked draft through the builder's own save (`PUT /core/forms/:id/schema`) — gated first against the live form (what the form already has does not block), guarded by the form's revision, recorded in History; saves the widget renders the gate compiled, never a hand-written one; `variables` only when the draft lists some. It never publishes |
|
|
584
584
|
| `suppa_create_form_v2` | Create a 2.0 form (create / update / custom) with its draft in one transaction — the routing flag and default variable the builder adds, optionally filed into a folder (confirm-gated) |
|
package/dist/server.js
CHANGED
|
@@ -2569,7 +2569,7 @@ export function buildToolTable() {
|
|
|
2569
2569
|
" (without entity_name it is refused, rather than creating an empty form).\n" +
|
|
2570
2570
|
" Form names are UNIQUE platform-wide — a duplicate name fails; pick a distinct one.\n" +
|
|
2571
2571
|
"\n SUPPA 1.0 FORM. This writes data.formShema and the v1 field types. A Suppa 2.0\n" +
|
|
2572
|
-
" (entity-builder) form is a different product — the `schema` column,
|
|
2572
|
+
" (entity-builder) form is a different product — the `schema` column, 62 types:\n" +
|
|
2573
2573
|
" use suppa_form_kb and suppa_validate_form_schema.",
|
|
2574
2574
|
inputSchema: {
|
|
2575
2575
|
name: z.string(),
|
|
@@ -2740,7 +2740,7 @@ export function buildToolTable() {
|
|
|
2740
2740
|
}, async () => text(tenants.listTenants()));
|
|
2741
2741
|
reg("suppa_form_kb", {
|
|
2742
2742
|
description: "The Suppa 2.0 (entity-builder) FORM knowledge base. Offline; touches no tenant.\n\n" +
|
|
2743
|
-
" components the
|
|
2743
|
+
" components the 62 element types (start here) api prop table for the types you name\n" +
|
|
2744
2744
|
" base props every element supports note one type's BEHAVIOUR\n" +
|
|
2745
2745
|
" ref layout|binding|tables|charts|custom-chart|conditions|styling|publishing|\n" +
|
|
2746
2746
|
" choosing-elements\n" +
|
|
@@ -2748,7 +2748,7 @@ export function buildToolTable() {
|
|
|
2748
2748
|
" kit the look of every record card, create form, window: the card kit's\n" +
|
|
2749
2749
|
" patterns (topic='p_block,…' = their elements); rules: ref card-kit\n" +
|
|
2750
2750
|
" note dynamicComponent = the widget contract (sandbox, formAPI, styles, translations)\n\n" +
|
|
2751
|
-
" No mode returns all
|
|
2751
|
+
" No mode returns all 62 prop tables: they are ~14,200 tokens stripped, and not carrying\n" +
|
|
2752
2752
|
" them is what this skill is for. Full skill: skills/suppa-form-v2/SKILL.md.",
|
|
2753
2753
|
inputSchema: {
|
|
2754
2754
|
mode: z
|
package/dist/toolTable.js
CHANGED
|
@@ -8,7 +8,7 @@ export const PROFILES = {
|
|
|
8
8
|
// Two form PRODUCTS live in this group, and the split is the thing to know before reading the
|
|
9
9
|
// list. Of the first seven, get_form reads both (a 2.x form as the builder reads it); the other six
|
|
10
10
|
// are Suppa 1.0: they read and write `data.formShema` (the platform's misspelling) and the v1 field types. `form_kb` and `validate_form_schema` serve the 2.0
|
|
11
|
-
// entity-builder canvas — the `schema` COLUMN on the row since 2.1,
|
|
11
|
+
// entity-builder canvas — the `schema` COLUMN on the row since 2.1, 62 component
|
|
12
12
|
// types — and share nothing with them.
|
|
13
13
|
forms: ["create_form", "get_form", "list_forms", "update_form", "add_field_to_form", "generate_form_schema", "list_form_field_types", "form_kb", "validate_form_schema",
|
|
14
14
|
"write_form_draft", "create_form_v2", "form_versions", "form_lifecycle", "form_code", "push_form_code"],
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A CHILD form judged by the tree a reader gets, not by the layer it stores.
|
|
3
|
+
*
|
|
4
|
+
* A 2.1 form with a `parent` stores only its own layer: the `schema.overrides` it applies to the parent and the
|
|
5
|
+
* elements it adds (entity-builder form-schema.service.ts getSchema: "draft mode stays the child's RAW own layer").
|
|
6
|
+
* Its `settings` are its own too, so the parent's grid (`settings.columnsNumber: 12`) is not in them. Gated on that
|
|
7
|
+
* layer alone, an element placed in an inherited container is `dangling_parent`, and one spanning the inherited
|
|
8
|
+
* 12-column root grid is `span_exceeds_parent_columns` against a root grid of 1 — the false refusals of seven
|
|
9
|
+
* create-form children on modern-expo.test (forms 1910–1916, 2026-12-01).
|
|
10
|
+
*
|
|
11
|
+
* What a publish freezes is the MERGED tree: entity-builder form-publish.service.ts `buildSnapshot` reads
|
|
12
|
+
* `buildEffectiveSchema` — the merge `GET /core/forms/:id/effective-schema` answers — and strips the inheritance
|
|
13
|
+
* bookkeeping (`stripInheritanceMeta`, `stripCollectionMeta`, `settingsEntriesToObject`). So the gate judges that
|
|
14
|
+
* tree, read the same way: an entry tagged `_state: 'removed'` (an inherited element the child deleted — the builder
|
|
15
|
+
* view tags it and never filters it) is not on the form, every other tag is dropped, and the settings arrive as an
|
|
16
|
+
* ARRAY of `{ key, value, _state }` entries that become the plain object a draft carries.
|
|
17
|
+
*
|
|
18
|
+
* The code-typing path (formCode.ts formTypes) reads the same endpoint for the same reason.
|
|
19
|
+
*/
|
|
20
|
+
import { makeRequest } from "../httpClient.js";
|
|
21
|
+
const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
22
|
+
const msgOf = (e) => (e instanceof Error ? e.message : String(e));
|
|
23
|
+
const isRefId = (v) => Number.isSafeInteger(v) && v > 0 ? v : isObj(v) ? isRefId(v.id) : null;
|
|
24
|
+
/** Keys a settings object never takes from a wire entry (entity-builder isForbiddenSettingsKey keeps the same out). */
|
|
25
|
+
const FORBIDDEN_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
26
|
+
/**
|
|
27
|
+
* The parent a form names, or null for a root form — `parentForm` (GET /core/forms/:id/schema) or `parent`
|
|
28
|
+
* (a Forms select), a real reference only: a positive id, or an object holding one.
|
|
29
|
+
*/
|
|
30
|
+
export function parentFormId(form) {
|
|
31
|
+
if (!isObj(form))
|
|
32
|
+
return null;
|
|
33
|
+
return isRefId(form.parentForm) ?? isRefId(form.parent);
|
|
34
|
+
}
|
|
35
|
+
/** The FormVersions row a child is pinned to (`parentVersion`, a number or `{ id }`), or null. */
|
|
36
|
+
export function parentVersionId(form) {
|
|
37
|
+
return isObj(form) ? isRefId(form.parentVersion) : null;
|
|
38
|
+
}
|
|
39
|
+
/** A collection entry without its inheritance tag, or null for one the child removed. */
|
|
40
|
+
function live(entry) {
|
|
41
|
+
if (!isObj(entry) || entry._state === "removed")
|
|
42
|
+
return null;
|
|
43
|
+
const { _state: _ignored, ...rest } = entry;
|
|
44
|
+
return rest;
|
|
45
|
+
}
|
|
46
|
+
const liveList = (list) => (Array.isArray(list) ? list : []).map(live).filter((e) => e !== null);
|
|
47
|
+
/** The effective settings: an array of `{ key, value, _state }` entries, or (an older answer) a plain object. */
|
|
48
|
+
function settingsOf(raw) {
|
|
49
|
+
if (isObj(raw))
|
|
50
|
+
return { ...raw };
|
|
51
|
+
const out = {};
|
|
52
|
+
for (const e of liveList(raw)) {
|
|
53
|
+
if (typeof e.key === "string" && e.key && !FORBIDDEN_KEYS.has(e.key))
|
|
54
|
+
out[e.key] = e.value;
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
/** The ids a list carries — of elements, or of wires. */
|
|
59
|
+
export function elementIdSet(list) {
|
|
60
|
+
const ids = new Set();
|
|
61
|
+
for (const e of Array.isArray(list) ? list : [])
|
|
62
|
+
if (isObj(e) && e.id != null)
|
|
63
|
+
ids.add(String(e.id));
|
|
64
|
+
return ids;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Every key a wire endpoint may name: an element's `name` or its `id`, nested `children` included — entity-builder
|
|
68
|
+
* effective-connections.ts `endpointKeys` over conflict-detection.ts `flatten`.
|
|
69
|
+
*/
|
|
70
|
+
function endpointKeys(components) {
|
|
71
|
+
const keys = new Set();
|
|
72
|
+
const stack = [...components];
|
|
73
|
+
while (stack.length) {
|
|
74
|
+
const c = stack.pop();
|
|
75
|
+
if (!isObj(c))
|
|
76
|
+
continue;
|
|
77
|
+
if (typeof c.name === "string" && c.name)
|
|
78
|
+
keys.add(c.name);
|
|
79
|
+
if (c.id != null)
|
|
80
|
+
keys.add(String(c.id));
|
|
81
|
+
if (Array.isArray(c.children))
|
|
82
|
+
stack.push(...c.children);
|
|
83
|
+
}
|
|
84
|
+
return keys;
|
|
85
|
+
}
|
|
86
|
+
/** Whether a wire has an endpoint no element answers to. */
|
|
87
|
+
function dangles(wire, keys) {
|
|
88
|
+
return ["from", "to"].some((end) => {
|
|
89
|
+
const e = wire[end];
|
|
90
|
+
const element = isObj(e) ? e.element : undefined;
|
|
91
|
+
return typeof element === "string" && element !== "" && !keys.has(element);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The wires a publish freezes. buildSnapshot drops every wire with an endpoint that no merged component answers to
|
|
96
|
+
* (`pruneDanglingConnections`, DSE-7253): a child that removed an inherited element leaves exactly these behind,
|
|
97
|
+
* and gated as they are they read as `dangling_element_ref`, so no such child could be published. The child's OWN
|
|
98
|
+
* wires are kept whatever they point at, so a dangling wire the child authored itself is still reported.
|
|
99
|
+
* `entries` still carry `_state`; the answer does not.
|
|
100
|
+
*/
|
|
101
|
+
function frozenWires(entries, components, isOwn) {
|
|
102
|
+
const keys = endpointKeys(components);
|
|
103
|
+
const wires = [];
|
|
104
|
+
let dropped = 0;
|
|
105
|
+
for (const raw of entries) {
|
|
106
|
+
if (!isObj(raw) || raw._state === "removed")
|
|
107
|
+
continue;
|
|
108
|
+
if (!isOwn(raw) && dangles(raw, keys)) {
|
|
109
|
+
dropped++;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const { _state: _ignored, ...wire } = raw;
|
|
113
|
+
wires.push(wire);
|
|
114
|
+
}
|
|
115
|
+
return { wires, dropped };
|
|
116
|
+
}
|
|
117
|
+
/** A wire is the child's own when the effective view tags it `local`, or its id is in the child's own layer. */
|
|
118
|
+
const ownWire = (ownConnectionIds) => (wire) => wire._state === "local" || (wire.id != null && ownConnectionIds.has(String(wire.id)));
|
|
119
|
+
/**
|
|
120
|
+
* The effective-schema answer as the envelope the gate reads — the tree `buildSnapshot` would freeze. A child
|
|
121
|
+
* stays a child on the tenant; this envelope names no parent, because the tree it carries is already whole.
|
|
122
|
+
* `ownConnectionIds` are the ids of the child's own `schema.connections`. An own wire that shadows an inherited id
|
|
123
|
+
* is tagged `overridden`, not `local` (mergeEffectiveConnections), and it is the child's own all the same.
|
|
124
|
+
*/
|
|
125
|
+
export function envelopeFromEffective(eff, ownConnectionIds = new Set()) {
|
|
126
|
+
if (!isObj(eff) || !Array.isArray(eff.components))
|
|
127
|
+
return { error: "the answer carries no `components` list" };
|
|
128
|
+
const components = liveList(eff.components);
|
|
129
|
+
const mobile = liveList(eff.mobileComponents);
|
|
130
|
+
const { wires, dropped } = frozenWires(Array.isArray(eff.connections) ? eff.connections : [], components, ownWire(ownConnectionIds));
|
|
131
|
+
const envelope = {
|
|
132
|
+
schema: components,
|
|
133
|
+
settings: settingsOf(eff.settings),
|
|
134
|
+
variables: liveList(eff.variables),
|
|
135
|
+
...(wires.length ? { connections: wires } : {}),
|
|
136
|
+
...(mobile.length ? { mobileSchema: mobile } : {}),
|
|
137
|
+
};
|
|
138
|
+
return { envelope, removed: eff.components.length - components.length, droppedWires: dropped };
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The merged tree as it WILL be once a draft write replaces the child's own layer. It starts from the inherited part
|
|
142
|
+
* of the current effective tree: what the parent passes down, with the child's overrides applied (a draft write keeps
|
|
143
|
+
* `schema.overrides`, formV2.ts). The draft's own elements are then added. An own element whose id an inherited one
|
|
144
|
+
* carries SHADOWS it in place, as entity-builder `mergeEffective` does; the rest are appended.
|
|
145
|
+
*
|
|
146
|
+
* `own` holds the ids of the child's CURRENT own layer, whose entries the draft replaces. A `local` element that is
|
|
147
|
+
* not one of them came from an `add` override and stays. Wires work the same way: when the draft sends its wires,
|
|
148
|
+
* every effective wire whose id is in the child's own layer or in the draft's own list is replaced, whatever its tag.
|
|
149
|
+
* An own wire shadowing an inherited id is tagged `overridden`, so going by the tag alone would hold it twice:
|
|
150
|
+
* `invalid_layout`. The inherited wires left are pruned as a publish prunes them (frozenWires).
|
|
151
|
+
*
|
|
152
|
+
* Settings: the draft's keys over the effective ones (the write merges them into the child's own `settings`).
|
|
153
|
+
* Variables: the draft's list replaces the child's own when the file sends one. The mobile list is the effective
|
|
154
|
+
* one, because a draft write never sends `mobileSchema`.
|
|
155
|
+
*/
|
|
156
|
+
export function envelopeWithOwnLayer(eff, own, draft, sentVariables) {
|
|
157
|
+
if (!isObj(eff) || !Array.isArray(eff.components))
|
|
158
|
+
return { error: "the answer carries no `components` list" };
|
|
159
|
+
const keepInherited = (e) => isObj(e) && !(e._state === "local" && e.id != null && own.components.has(String(e.id)));
|
|
160
|
+
const components = liveList(eff.components.filter(keepInherited));
|
|
161
|
+
for (const el of Array.isArray(draft.schema) ? draft.schema : []) {
|
|
162
|
+
const at = isObj(el) && el.id != null ? components.findIndex((c) => String(c.id) === String(el.id)) : -1;
|
|
163
|
+
if (at === -1)
|
|
164
|
+
components.push(el);
|
|
165
|
+
else
|
|
166
|
+
components[at] = el;
|
|
167
|
+
}
|
|
168
|
+
let variables = liveList(eff.variables);
|
|
169
|
+
if (Array.isArray(sentVariables)) {
|
|
170
|
+
const sent = sentVariables.filter(isObj);
|
|
171
|
+
const names = new Set(sent.map((v) => String(v.name ?? "")));
|
|
172
|
+
const inherited = liveList((Array.isArray(eff.variables) ? eff.variables : []).filter((v) => isObj(v) && v._state !== "local"));
|
|
173
|
+
variables = [...inherited.filter((v) => !names.has(String(v.name ?? ""))), ...sent];
|
|
174
|
+
}
|
|
175
|
+
const effWires = Array.isArray(eff.connections) ? eff.connections : [];
|
|
176
|
+
let connections;
|
|
177
|
+
let droppedWires;
|
|
178
|
+
if (Array.isArray(draft.connections)) {
|
|
179
|
+
const sent = draft.connections.filter(isObj);
|
|
180
|
+
const replaced = new Set([...own.connections, ...elementIdSet(sent)]);
|
|
181
|
+
const inherited = effWires.filter((w) => isObj(w) && !(w.id != null && replaced.has(String(w.id))) && w._state !== "local");
|
|
182
|
+
const pruned = frozenWires(inherited, components, () => false);
|
|
183
|
+
connections = [...pruned.wires, ...sent];
|
|
184
|
+
droppedWires = pruned.dropped;
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
const kept = frozenWires(effWires, components, ownWire(own.connections));
|
|
188
|
+
connections = kept.wires;
|
|
189
|
+
droppedWires = kept.dropped;
|
|
190
|
+
}
|
|
191
|
+
const mobile = liveList(eff.mobileComponents);
|
|
192
|
+
return {
|
|
193
|
+
envelope: {
|
|
194
|
+
schema: components,
|
|
195
|
+
settings: { ...settingsOf(eff.settings), ...(isObj(draft.settings) ? draft.settings : {}) },
|
|
196
|
+
variables,
|
|
197
|
+
...(connections.length ? { connections } : {}),
|
|
198
|
+
...(mobile.length ? { mobileSchema: mobile } : {}),
|
|
199
|
+
},
|
|
200
|
+
droppedWires,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/** Why a child could not be judged — the gate then REFUSES; it never falls back to the own layer. */
|
|
204
|
+
export function mergedTreeUnavailable(formId, parent, why) {
|
|
205
|
+
return (`form ${formId} is a child of form ${parent}, and its merged tree (GET /core/forms/${formId}/effective-schema) ` +
|
|
206
|
+
`could not be read: ${why}. A child's own layer is not the form a reader gets — its inherited containers and the ` +
|
|
207
|
+
"parent's settings are not in it — so it is not judged on that layer alone, and nothing is passed unchecked. " +
|
|
208
|
+
"Retry; if the read keeps failing, check the form in the builder.");
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* The raw effective-schema answer of a child form, or why it could not be read. Null for a root form, whose own
|
|
212
|
+
* layer IS the form.
|
|
213
|
+
*/
|
|
214
|
+
export async function readChildTree(formId, form) {
|
|
215
|
+
const parent = parentFormId(form);
|
|
216
|
+
if (parent === null)
|
|
217
|
+
return null;
|
|
218
|
+
try {
|
|
219
|
+
const eff = await makeRequest("GET", `/api/core/forms/${formId}/effective-schema`);
|
|
220
|
+
if (!isObj(eff) || !Array.isArray(eff.components)) {
|
|
221
|
+
return { parent, error: mergedTreeUnavailable(formId, parent, "the answer carries no `components` list") };
|
|
222
|
+
}
|
|
223
|
+
return { parent, eff };
|
|
224
|
+
}
|
|
225
|
+
catch (e) {
|
|
226
|
+
return { parent, error: mergedTreeUnavailable(formId, parent, msgOf(e)) };
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* The note a merged judgment carries, so the answer says which tree was checked. Kept under 200 characters: a
|
|
231
|
+
* preview's `proposed_changes` replaces a longer string with its length (confirmRequired).
|
|
232
|
+
*/
|
|
233
|
+
export function mergedTreeNote(parent, envelope, ownCount, droppedWires = 0) {
|
|
234
|
+
const n = Array.isArray(envelope.schema) ? envelope.schema.length : 0;
|
|
235
|
+
return (`a child of form ${parent}: judged on its MERGED tree (effective-schema, ${n} element${n === 1 ? "" : "s"}` +
|
|
236
|
+
`${ownCount !== null ? `, ${ownCount} own` : ""}, the parent's settings included) — the form a reader gets` +
|
|
237
|
+
(droppedWires ? `; ${droppedWires} dead inherited wire${droppedWires === 1 ? "" : "s"} dropped, as on publish` : ""));
|
|
238
|
+
}
|
|
@@ -20,6 +20,11 @@
|
|
|
20
20
|
* the form gate on what gets frozen + version ownership. The gate's baseline is the version that
|
|
21
21
|
* is live now, so a finding the published form already carries does not block — only breakage the
|
|
22
22
|
* new version would introduce.
|
|
23
|
+
*
|
|
24
|
+
* A CHILD form (one with a `parent`) is gated on its MERGED tree — what buildSnapshot freezes, read off
|
|
25
|
+
* `GET /core/forms/:id/effective-schema` (formInheritance.ts) — never on the own layer its draft read returns. A
|
|
26
|
+
* child never published yet has no live version: its baseline is the parent's published version it is pinned to.
|
|
27
|
+
* A merged tree that cannot be read refuses the publish.
|
|
23
28
|
*/
|
|
24
29
|
import { randomUUID } from "node:crypto";
|
|
25
30
|
import { isAbsolute } from "node:path";
|
|
@@ -27,6 +32,7 @@ import { pathToFileURL } from "node:url";
|
|
|
27
32
|
import { makeRequest, searchEntity, selectEntity } from "../httpClient.js";
|
|
28
33
|
import { confirmRequired, jsonResponse } from "../utils.js";
|
|
29
34
|
import { checkerFailed, gateErrorLines, readJson, sentVariables, skillFile, subtractLiveFindings } from "./formV2.js";
|
|
35
|
+
import { elementIdSet, envelopeFromEffective, mergedTreeNote, mergedTreeUnavailable, parentVersionId, readChildTree } from "./formInheritance.js";
|
|
30
36
|
/** The FB2 kinds this can create. `workspace` inherits the base workspace form (setParent). */
|
|
31
37
|
export const CREATABLE_FORM_TYPES = ["create", "update", "custom"];
|
|
32
38
|
export const LIFECYCLE_ACTIONS = ["publish", "rollback", "discard", "promote"];
|
|
@@ -482,6 +488,70 @@ async function gateAgainstLive(envelope, live, what = { kind: "draft" }) {
|
|
|
482
488
|
const { added } = subtractLiveFindings(g.errors, base.checked ? base.errors : []);
|
|
483
489
|
return { ...g, ok: added.length === 0, errors: added, already_live: g.errors.length - added.length };
|
|
484
490
|
}
|
|
491
|
+
/**
|
|
492
|
+
* What a publish freezes, as the envelope the gate reads. A root form: its draft. A CHILD form: its MERGED tree
|
|
493
|
+
* (formInheritance.ts) — buildSnapshot freezes that, and the own layer the draft read returns is not a form on its
|
|
494
|
+
* own. A merged tree that cannot be read is an error, never the own layer: nothing unchecked is published.
|
|
495
|
+
*/
|
|
496
|
+
async function frozenEnvelope(id, draft) {
|
|
497
|
+
const tree = await readChildTree(id, draft);
|
|
498
|
+
if (!tree)
|
|
499
|
+
return { envelope: envelopeOf(draft), child: null };
|
|
500
|
+
if (tree.error !== undefined)
|
|
501
|
+
return { error: tree.error };
|
|
502
|
+
// The child's own wires (its draft's schema.connections) are kept even when they dangle; an inherited wire into an
|
|
503
|
+
// element the child removed is dropped, as buildSnapshot drops it.
|
|
504
|
+
const ownWires = elementIdSet(isObj(draft.schema) ? draft.schema.connections : null);
|
|
505
|
+
const merged = envelopeFromEffective(tree.eff, ownWires);
|
|
506
|
+
if ("error" in merged)
|
|
507
|
+
return { error: mergedTreeUnavailable(id, tree.parent, merged.error) };
|
|
508
|
+
const meta = isObj(tree.eff.inheritanceMeta) ? tree.eff.inheritanceMeta : {};
|
|
509
|
+
const pinned = parentVersionId(draft) ?? parentVersionId({ parentVersion: meta.parentVersionId });
|
|
510
|
+
return {
|
|
511
|
+
envelope: merged.envelope,
|
|
512
|
+
child: {
|
|
513
|
+
parent: tree.parent,
|
|
514
|
+
parentVersion: pinned,
|
|
515
|
+
note: mergedTreeNote(tree.parent, merged.envelope, componentIds(draft.schema).length, merged.droppedWires),
|
|
516
|
+
},
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* The «already live» baseline of a child that has never been published: the parent's published merge it inherits.
|
|
521
|
+
* First the snapshot of the parent version the child is pinned to — a FormVersions snapshot IS a merged tree
|
|
522
|
+
* (buildSnapshot) — checked to belong to the parent; else the parent's published read. Neither readable: no
|
|
523
|
+
* baseline, which only ever ADDS findings (every inherited one counts), so it is said and never weakens the gate.
|
|
524
|
+
*/
|
|
525
|
+
async function parentBaseline(child) {
|
|
526
|
+
if (child.parentVersion !== null) {
|
|
527
|
+
try {
|
|
528
|
+
const row = await readSnapshot(child.parentVersion);
|
|
529
|
+
const owner = isObj(row?.form) ? Number(row.form.id) : null;
|
|
530
|
+
if (row && isObj(row.snapshot) && owner === child.parent) {
|
|
531
|
+
return {
|
|
532
|
+
baseline: row.snapshot,
|
|
533
|
+
judgedAgainst: `form ${child.parent}'s published version ${row.versionNumber ?? `(FormVersions ${child.parentVersion})`} — the one this child is pinned to; the child itself was never published`,
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
catch {
|
|
538
|
+
/* the published read below */
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
try {
|
|
542
|
+
const pub = await makeRequest("GET", `/api/core/forms/${child.parent}/schema`, null, { query: { mode: "published" } });
|
|
543
|
+
if (isObj(pub) && pub.schema != null) {
|
|
544
|
+
return { baseline: pub, judgedAgainst: `form ${child.parent}'s published version (its published read); the child itself was never published` };
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
catch {
|
|
548
|
+
/* no baseline */
|
|
549
|
+
}
|
|
550
|
+
return {
|
|
551
|
+
baseline: null,
|
|
552
|
+
judgedAgainst: `nothing — the child was never published and form ${child.parent}'s published version could not be read, so every finding counts, inherited ones too`,
|
|
553
|
+
};
|
|
554
|
+
}
|
|
485
555
|
export async function formLifecycle(formId, action, versionId = null, confirm = false, description = null) {
|
|
486
556
|
const id = Number(formId);
|
|
487
557
|
const act = String(action ?? "");
|
|
@@ -541,10 +611,35 @@ export async function formLifecycle(formId, action, versionId = null, confirm =
|
|
|
541
611
|
if (act === "publish" || act === "discard") {
|
|
542
612
|
const draft = (await makeRequest("GET", `/api/core/forms/${id}/schema`));
|
|
543
613
|
if (act === "publish") {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
614
|
+
const frozen = await frozenEnvelope(id, draft);
|
|
615
|
+
if ("error" in frozen) {
|
|
616
|
+
plan.freezes = { ...compare(liveSnap?.schema, draft.schema), status_now: draft.status };
|
|
617
|
+
plan.gate = frozen.error;
|
|
618
|
+
warnings.push(`the confirmed call will REFUSE this publish: ${frozen.error}`);
|
|
619
|
+
}
|
|
620
|
+
else {
|
|
621
|
+
plan.freezes = { ...compare(liveSnap?.schema, frozen.envelope.schema), status_now: draft.status };
|
|
622
|
+
let baseline = liveSnap;
|
|
623
|
+
if (frozen.child) {
|
|
624
|
+
plan.merged_tree = frozen.child.note;
|
|
625
|
+
if (liveSnap)
|
|
626
|
+
plan.judged_against = "the live version of this child — a merged tree, as every version is";
|
|
627
|
+
else if (live) {
|
|
628
|
+
// Published, but its snapshot did not come back: the parent's version is not this child's baseline.
|
|
629
|
+
plan.judged_against =
|
|
630
|
+
`nothing — the snapshot of this child's live version ${live.id} could not be read, so every finding counts; ` +
|
|
631
|
+
"the confirmed call reads it again and aborts if that fails";
|
|
632
|
+
}
|
|
633
|
+
else {
|
|
634
|
+
const pb = await parentBaseline(frozen.child);
|
|
635
|
+
baseline = pb.baseline;
|
|
636
|
+
plan.judged_against = pb.judgedAgainst;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
const g = await gateAgainstLive(frozen.envelope, baseline);
|
|
640
|
+
plan.gate = g.checked ? { passes: g.ok, errors: g.errors.length, already_live: g.already_live, warnings: g.warnings.length } : g.error;
|
|
641
|
+
warnings.push(...gateErrorLines(g.errors), ...warningLines(g.warnings));
|
|
642
|
+
}
|
|
548
643
|
plan.effect = "publish: a new default version";
|
|
549
644
|
warnings.push("publishing makes this draft the version every user of this tenant sees; the draft itself is unchanged.");
|
|
550
645
|
}
|
|
@@ -584,10 +679,23 @@ export async function formLifecycle(formId, action, versionId = null, confirm =
|
|
|
584
679
|
if (act === "publish" || act === "rollback") {
|
|
585
680
|
let envelope;
|
|
586
681
|
let baseline;
|
|
682
|
+
let judgedAgainst = null;
|
|
587
683
|
try {
|
|
588
684
|
baseline = await readLiveSnapshot();
|
|
589
685
|
if (act === "publish") {
|
|
590
|
-
|
|
686
|
+
const frozen = await frozenEnvelope(id, (await makeRequest("GET", `/api/core/forms/${id}/schema`)));
|
|
687
|
+
if ("error" in frozen)
|
|
688
|
+
return jsonResponse({ done: false, published: false, error: `${frozen.error} Nothing was published.` });
|
|
689
|
+
envelope = frozen.envelope;
|
|
690
|
+
if (frozen.child && !baseline && live) {
|
|
691
|
+
// Published, yet its live version carries no snapshot: no baseline (stricter), never the parent's version.
|
|
692
|
+
judgedAgainst = `nothing — the snapshot of this child's live version ${live.id} could not be read, so every finding counts`;
|
|
693
|
+
}
|
|
694
|
+
else if (frozen.child && !baseline) {
|
|
695
|
+
const pb = await parentBaseline(frozen.child);
|
|
696
|
+
baseline = pb.baseline;
|
|
697
|
+
judgedAgainst = pb.judgedAgainst;
|
|
698
|
+
}
|
|
591
699
|
}
|
|
592
700
|
else {
|
|
593
701
|
const target = await readSnapshot(vid);
|
|
@@ -608,7 +716,10 @@ export async function formLifecycle(formId, action, versionId = null, confirm =
|
|
|
608
716
|
errors: g.errors,
|
|
609
717
|
warnings: g.warnings,
|
|
610
718
|
already_live: g.already_live,
|
|
611
|
-
|
|
719
|
+
...(judgedAgainst ? { judged_against: judgedAgainst } : {}),
|
|
720
|
+
note: (judgedAgainst
|
|
721
|
+
? `Nothing was published. Judged against ${judgedAgainst}; the findings that baseline already carries were set aside `
|
|
722
|
+
: "Nothing was published. The live version was gated too and its own findings were set aside ") +
|
|
612
723
|
`(${g.already_live} of them), so these are errors the new version would ADD. Fix the draft ` +
|
|
613
724
|
"(suppa_write_form_draft) and publish again.",
|
|
614
725
|
});
|