@peripheries/renderer 0.4.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,275 +0,0 @@
1
- import { h as usesStructureLayout, m as structureIssues } from "./structure-OUTX0zxG.js";
2
- import { STATE_NAMES, isStateName } from "@peripheries/runtime";
3
- //#region packages/renderer/src/core/validate.ts
4
- var RESPONSIVE_BUCKETS = [
5
- "narrow",
6
- "compact",
7
- "wide"
8
- ];
9
- var STORE_SCOPES = ["page", "project"];
10
- var WALK_DIRECTIONS = [
11
- "incoming",
12
- "outgoing",
13
- "both"
14
- ];
15
- var BUCKETS = RESPONSIVE_BUCKETS;
16
- var SCOPES = STORE_SCOPES;
17
- var DIRECTIONS = WALK_DIRECTIONS;
18
- function checkBindings(queries, path, push, cellId, template = false) {
19
- if (queries === void 0) return;
20
- if (!queries || typeof queries !== "object" || Array.isArray(queries)) {
21
- push({
22
- severity: "error",
23
- code: "BINDING_INVALID",
24
- cellId,
25
- path,
26
- message: "data.queries must be an object of label → binding"
27
- });
28
- return;
29
- }
30
- for (const [label, raw] of Object.entries(queries)) {
31
- const at = `${path}.${label}`;
32
- const b = raw;
33
- if (!b || typeof b !== "object") {
34
- push({
35
- severity: "error",
36
- code: "BINDING_INVALID",
37
- cellId,
38
- label,
39
- path: at,
40
- message: `"${label}" isn't a binding`
41
- });
42
- continue;
43
- }
44
- if (typeof b.registry === "string") {
45
- push({
46
- severity: "warning",
47
- code: "UNSUPPORTED_REGISTRY_BINDING",
48
- cellId,
49
- label,
50
- path: at,
51
- message: `"${label}" names the registry query ${b.registry}, which the host no longer runs (R2 maps or retires it)`
52
- });
53
- continue;
54
- }
55
- if (typeof b.graph_node_id !== "string" || !b.graph_node_id) {
56
- if (!template) push({
57
- severity: "error",
58
- code: "BINDING_INVALID",
59
- cellId,
60
- label,
61
- path: at,
62
- message: `"${label}" names no graph_node_id`
63
- });
64
- continue;
65
- }
66
- if (b.as !== void 0 && b.as !== "value" && b.as !== "record") push({
67
- severity: "error",
68
- code: "BINDING_INVALID",
69
- cellId,
70
- label,
71
- path: `${at}.as`,
72
- message: `"${label}".as is "${String(b.as)}"; expected value or record`
73
- });
74
- for (const s of b.state === void 0 ? [] : Array.isArray(b.state) ? b.state : [b.state]) if (!isStateName(s)) push({
75
- severity: "error",
76
- code: "STATE_UNKNOWN_NAME",
77
- cellId,
78
- label,
79
- path: `${at}.state`,
80
- message: `"${label}" names state "${String(s)}"; expected one of ${STATE_NAMES.join(", ")}`
81
- });
82
- }
83
- }
84
- function checkTraversal(t, path, push, cellId) {
85
- if (t === void 0) return;
86
- const w = t;
87
- if (!Array.isArray(w.edgeTypes) || w.edgeTypes.length === 0) push({
88
- severity: "error",
89
- code: "WALK_EDGE_TYPES_REQUIRED",
90
- cellId,
91
- path: `${path}.edgeTypes`,
92
- message: "traversal.edgeTypes is required: without it a walk follows every edge type"
93
- });
94
- if (w.direction !== void 0 && !DIRECTIONS.includes(String(w.direction))) push({
95
- severity: "error",
96
- code: "WALK_BAD_DIRECTION",
97
- cellId,
98
- path: `${path}.direction`,
99
- message: `traversal.direction "${String(w.direction)}" isn't incoming, outgoing or both`
100
- });
101
- if (Array.isArray(w.nodeTypes) && w.nodeTypes.length === 0) push({
102
- severity: "warning",
103
- code: "WALK_NODE_TYPES_EMPTY",
104
- cellId,
105
- path: `${path}.nodeTypes`,
106
- message: "traversal.nodeTypes is empty, which filters nothing: leave it out, or name the types the walk may enter"
107
- });
108
- if (typeof w.maxNodes === "number" && w.maxNodes > 500) push({
109
- severity: "warning",
110
- code: "WALK_MAX_NODES_CLAMPED",
111
- cellId,
112
- path: `${path}.maxNodes`,
113
- message: `traversal.maxNodes ${w.maxNodes} is above 500; clamped`
114
- });
115
- for (const s of Array.isArray(w.include_state) ? w.include_state : []) if (!isStateName(s)) push({
116
- severity: "error",
117
- code: "STATE_UNKNOWN_NAME",
118
- cellId,
119
- path: `${path}.include_state`,
120
- message: `include_state "${String(s)}" isn't a system name`
121
- });
122
- }
123
- function checkStore(cell, path, push) {
124
- for (const [kind, key] of [
125
- ["selections", "channel"],
126
- ["viewState", "key"],
127
- ["live", "channel"]
128
- ]) for (const [name, decl] of Object.entries(cell[kind] ?? {})) {
129
- const at = `${path}.${kind}.${name}`;
130
- if (typeof decl?.[key] !== "string" || !decl[key]) push({
131
- severity: "error",
132
- code: "STORE_INVALID",
133
- cellId: cell.id,
134
- path: at,
135
- message: `${kind}.${name} names no ${key}`
136
- });
137
- if (kind !== "live" && !SCOPES.includes(String(decl?.scope))) push({
138
- severity: "error",
139
- code: "STORE_INVALID",
140
- cellId: cell.id,
141
- path: `${at}.scope`,
142
- message: `${kind}.${name}.scope must be page or project`
143
- });
144
- }
145
- }
146
- function validateCell(cell, catalog, path = "cell", ids, options = {}) {
147
- const out = [];
148
- const push = (d) => out.push(d);
149
- if (typeof cell?.id !== "string" || !cell.id) {
150
- push({
151
- severity: "error",
152
- code: "CELL_NO_ID",
153
- path,
154
- message: "a cell needs an id"
155
- });
156
- return out;
157
- }
158
- const cellId = cell.id;
159
- const ref = cell.ref;
160
- if (ref !== void 0 && (typeof ref?.graph_node_id !== "string" || !ref.graph_node_id)) push({
161
- severity: "error",
162
- code: "REF_INVALID",
163
- cellId,
164
- path: `${path}.ref`,
165
- message: "ref names no graph_node_id"
166
- });
167
- const nodeManaged = Boolean(ref?.graph_node_id) || Boolean(cell.graph_node_id) && !cell.component;
168
- if (!ref && cell.graph_node_id && !cell.component) push({
169
- severity: "legacy",
170
- code: "LEGACY_THIN_REF",
171
- cellId,
172
- path,
173
- message: "a thin ref `{ id, graph_node_id }`: publish it as `{ id, ref: { graph_node_id } }`"
174
- });
175
- else if (!ref && cell.graph_node_id) push({
176
- severity: "legacy",
177
- code: "LEGACY_INLINE_NODE",
178
- cellId,
179
- path,
180
- message: "an inline cell with a graph_node_id: its node only starts its walk. Give it a `ref` if the node should manage the cell"
181
- });
182
- if (!nodeManaged && !cell.component) push({
183
- severity: "error",
184
- code: "CELL_NO_COMPONENT",
185
- cellId,
186
- path,
187
- message: "an inline cell needs a component"
188
- });
189
- if (cell.component && catalog && !cell.component.startsWith("@core/")) {
190
- const entry = catalog.components[cell.component];
191
- if (!entry) push({
192
- severity: nodeManaged ? "warning" : "error",
193
- code: "CELL_UNKNOWN_COMPONENT",
194
- cellId,
195
- path: `${path}.component`,
196
- message: `no bundle in scope exports ${cell.component}`
197
- });
198
- else for (const prop of entry.props_schema?.required ?? []) if ((prop === "children" ? cell.props?.children ?? (cell.children?.length ? cell.children : void 0) : cell.props?.[prop]) === void 0) push({
199
- severity: nodeManaged ? "warning" : "error",
200
- code: "PROP_REQUIRED",
201
- cellId,
202
- path: `${path}.props.${prop}`,
203
- message: `${cell.component} requires ${prop}`
204
- });
205
- }
206
- for (const child of cell.children ?? []) if (child === cellId) push({
207
- severity: "error",
208
- code: "CELL_CHILD_CYCLE",
209
- cellId,
210
- path: `${path}.children`,
211
- message: "a cell lists itself as a child"
212
- });
213
- else if (ids && !ids.has(child)) push({
214
- severity: "error",
215
- code: "CELL_UNKNOWN_CHILD",
216
- cellId,
217
- path: `${path}.children`,
218
- message: `child cell "${child}" is not on the page`
219
- });
220
- checkBindings(cell.data?.queries, `${path}.data.queries`, push, cellId, options.template);
221
- checkTraversal(cell.traversal, `${path}.traversal`, push, cellId);
222
- checkStore(cell, path, push);
223
- for (const key of [
224
- "hideWhen",
225
- "showWhen",
226
- "stackWhen",
227
- "truncateWhen"
228
- ]) {
229
- const v = cell.layout?.[key];
230
- if (v !== void 0 && !BUCKETS.includes(v)) push({
231
- severity: "warning",
232
- code: "LAYOUT_INVALID",
233
- cellId,
234
- path: `${path}.layout.${key}`,
235
- message: `layout.${key} "${v}" isn't narrow, compact or wide`
236
- });
237
- }
238
- return out;
239
- }
240
- function validatePage(page, catalog) {
241
- const options = { template: Boolean(page.is_template) };
242
- const out = [];
243
- const cells = page.content?.cells;
244
- if (cells !== void 0 && !Array.isArray(cells)) return [{
245
- severity: "error",
246
- code: "PAGE_INVALID",
247
- path: "content.cells",
248
- message: "content.cells must be a list"
249
- }];
250
- const list = cells ?? [];
251
- const ids = new Set();
252
- list.forEach((cell, i) => {
253
- if (typeof cell?.id === "string" && ids.has(cell.id)) out.push({
254
- severity: "error",
255
- code: "CELL_DUPLICATE_ID",
256
- cellId: cell.id,
257
- path: `content.cells[${i}].id`,
258
- message: `two cells share the id "${cell.id}"`
259
- });
260
- if (typeof cell?.id === "string") ids.add(cell.id);
261
- });
262
- list.forEach((cell, i) => out.push(...validateCell(cell, catalog, `content.cells[${i}]`, ids, options)));
263
- checkBindings(page.content?.data?.queries, "content.data.queries", (d) => out.push(d), void 0, options.template);
264
- if (usesStructureLayout(page.layout)) for (const issue of structureIssues(page.layout?.structure, list)) out.push({
265
- severity: "error",
266
- code: "STRUCTURE_INVALID",
267
- path: "layout.structure",
268
- message: issue
269
- });
270
- return out;
271
- }
272
- //#endregion
273
- export { validatePage as a, validateCell as i, STORE_SCOPES as n, WALK_DIRECTIONS as r, RESPONSIVE_BUCKETS as t };
274
-
275
- //# sourceMappingURL=validate--WdSPgWe.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validate--WdSPgWe.js","names":[],"sources":["../../src/core/validate.ts"],"mappings":";;;AAgBA,IAAa,qBAAqB;CAAC;CAAU;CAAW;AAAM;AAC9D,IAAa,eAAe,CAAC,QAAQ,SAAS;AAC9C,IAAa,kBAAkB;CAAC;CAAY;CAAY;AAAM;AAC9D,IAAM,UAA6B;AACnC,IAAM,SAA4B;AAClC,IAAM,aAAgC;AAOtC,SAAS,cAAc,SAAkB,MAAc,MAAY,QAAiB,WAAW,OAAO;CACpG,IAAI,YAAY,KAAA,GAAW;CAC3B,IAAI,CAAC,WAAW,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,GAAG;EACrE,KAAK;GAAE,UAAU;GAAS,MAAM;GAAmB;GAAQ;GAAM,SAAS;EAAoD,CAAC;EAC/H;CACF;CACA,KAAK,MAAM,CAAC,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