@bobbykim/manguito-cms-api 0.4.3 → 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.
- package/dist/{chunk-4Y4G564P.mjs → chunk-JVP33FI2.mjs} +99 -58
- package/dist/chunk-JVP33FI2.mjs.map +1 -0
- package/dist/{chunk-HEYT5CH5.mjs → chunk-XNXM4W4K.mjs} +147 -40
- package/dist/chunk-XNXM4W4K.mjs.map +1 -0
- package/dist/graphql/index.d.mts +7 -2
- package/dist/graphql/index.d.ts +7 -2
- package/dist/graphql/index.js +145 -38
- package/dist/graphql/index.js.map +1 -1
- package/dist/graphql/index.mjs +2 -2
- package/dist/handler-XZVDLKZ2.mjs +8 -0
- package/dist/index.d.mts +19 -3
- package/dist/index.d.ts +19 -3
- package/dist/index.js +557 -171
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +303 -76
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
- package/dist/chunk-4Y4G564P.mjs.map +0 -1
- package/dist/chunk-HEYT5CH5.mjs.map +0 -1
- package/dist/handler-45O5OX2C.mjs +0 -8
- /package/dist/{handler-45O5OX2C.mjs.map → handler-XZVDLKZ2.mjs.map} +0 -0
|
@@ -1,3 +1,97 @@
|
|
|
1
|
+
// src/field-keys.ts
|
|
2
|
+
function isColumnBacked(field) {
|
|
3
|
+
const col = field.db_column;
|
|
4
|
+
if (col === null) return false;
|
|
5
|
+
if (col.column_name === "") return false;
|
|
6
|
+
if (col.junction) return false;
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
function buildFieldKeyMap(pairs, allLabels, droppedKeys) {
|
|
10
|
+
const labelToColumn = /* @__PURE__ */ new Map();
|
|
11
|
+
const columnToLabel = /* @__PURE__ */ new Map();
|
|
12
|
+
for (const { label, column } of pairs) {
|
|
13
|
+
labelToColumn.set(label, column);
|
|
14
|
+
columnToLabel.set(column, label);
|
|
15
|
+
}
|
|
16
|
+
for (const { label, ownColumn } of allLabels) {
|
|
17
|
+
if (ownColumn === label) continue;
|
|
18
|
+
const columnOwner = columnToLabel.get(label);
|
|
19
|
+
if (columnOwner !== void 0 && columnOwner !== label) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`Fatal: field key map failed to build \u2014 field label "${label}" collides with the storage column of field "${columnOwner}". A field label may not reuse another field's column name. Rename the field, then run \`manguito validate\` to check your schema.`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
for (const label of labelToColumn.keys()) {
|
|
26
|
+
if (droppedKeys.has(label)) labelToColumn.delete(label);
|
|
27
|
+
}
|
|
28
|
+
for (const column of columnToLabel.keys()) {
|
|
29
|
+
if (droppedKeys.has(column)) columnToLabel.delete(column);
|
|
30
|
+
}
|
|
31
|
+
const diverges = [...labelToColumn].some(([label, column]) => label !== column);
|
|
32
|
+
function remap(input, lookup) {
|
|
33
|
+
const out = {};
|
|
34
|
+
for (const key of Object.keys(input)) {
|
|
35
|
+
if (droppedKeys.has(key)) continue;
|
|
36
|
+
out[lookup.get(key) ?? key] = input[key];
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
toStorage: (input) => remap(input, labelToColumn),
|
|
42
|
+
toLabels: (row) => remap(row, columnToLabel),
|
|
43
|
+
columnFor: (label) => labelToColumn.get(label),
|
|
44
|
+
labelFor: (column) => columnToLabel.get(column),
|
|
45
|
+
labels: [...labelToColumn.keys()],
|
|
46
|
+
diverges
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function createFieldKeyMap(fields) {
|
|
50
|
+
const droppedKeys = /* @__PURE__ */ new Set();
|
|
51
|
+
const pairs = [];
|
|
52
|
+
for (const f of fields) {
|
|
53
|
+
if (!isColumnBacked(f)) continue;
|
|
54
|
+
pairs.push({ label: f.name, column: f.db_column.column_name });
|
|
55
|
+
if (f.removed === true) {
|
|
56
|
+
droppedKeys.add(f.name);
|
|
57
|
+
droppedKeys.add(f.db_column.column_name);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return buildFieldKeyMap(
|
|
61
|
+
pairs,
|
|
62
|
+
fields.map((f) => ({
|
|
63
|
+
label: f.name,
|
|
64
|
+
// Conditional spread, not a plain assignment — exactOptionalPropertyTypes
|
|
65
|
+
// forbids present-and-undefined.
|
|
66
|
+
...isColumnBacked(f) && { ownColumn: f.db_column.column_name }
|
|
67
|
+
})),
|
|
68
|
+
droppedKeys
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
function createFieldKeyMapFromProjection(projectionType, allFields) {
|
|
72
|
+
const pairs = projectionType.fields.map((f) => ({ label: f.exposed_as, column: f.column_name }));
|
|
73
|
+
const projected = new Set(pairs.map((p) => p.label));
|
|
74
|
+
const dropped = /* @__PURE__ */ new Set();
|
|
75
|
+
for (const f of allFields) {
|
|
76
|
+
if (!isColumnBacked(f)) continue;
|
|
77
|
+
dropped.add(f.name);
|
|
78
|
+
dropped.add(f.db_column.column_name);
|
|
79
|
+
}
|
|
80
|
+
for (const p of pairs) dropped.delete(p.column);
|
|
81
|
+
for (const label of projected) dropped.delete(label);
|
|
82
|
+
return buildFieldKeyMap(
|
|
83
|
+
pairs,
|
|
84
|
+
allFields.map((f) => ({
|
|
85
|
+
label: f.name,
|
|
86
|
+
// See buildFieldKeyMap's collision check: this is what lets it tell a
|
|
87
|
+
// version exposing a field's own column under a new label (fine) from a
|
|
88
|
+
// label that reuses another field's column (not fine).
|
|
89
|
+
...isColumnBacked(f) && { ownColumn: f.db_column.column_name }
|
|
90
|
+
})),
|
|
91
|
+
dropped
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
1
95
|
// src/relations.ts
|
|
2
96
|
import crypto from "crypto";
|
|
3
97
|
import { sql } from "drizzle-orm";
|
|
@@ -295,68 +389,15 @@ async function resolveRelationBareIds(db, rows, fieldName, rel) {
|
|
|
295
389
|
}
|
|
296
390
|
}
|
|
297
391
|
|
|
298
|
-
// src/field-keys.ts
|
|
299
|
-
function isColumnBacked(field) {
|
|
300
|
-
const col = field.db_column;
|
|
301
|
-
if (col === null) return false;
|
|
302
|
-
if (col.column_name === "") return false;
|
|
303
|
-
if (col.junction) return false;
|
|
304
|
-
return true;
|
|
305
|
-
}
|
|
306
|
-
function createFieldKeyMap(fields) {
|
|
307
|
-
const labelToColumn = /* @__PURE__ */ new Map();
|
|
308
|
-
const columnToLabel = /* @__PURE__ */ new Map();
|
|
309
|
-
const droppedKeys = /* @__PURE__ */ new Set();
|
|
310
|
-
for (const f of fields) {
|
|
311
|
-
if (!isColumnBacked(f)) continue;
|
|
312
|
-
columnToLabel.set(f.db_column.column_name, f.name);
|
|
313
|
-
if (f.removed === true) {
|
|
314
|
-
droppedKeys.add(f.name);
|
|
315
|
-
droppedKeys.add(f.db_column.column_name);
|
|
316
|
-
continue;
|
|
317
|
-
}
|
|
318
|
-
labelToColumn.set(f.name, f.db_column.column_name);
|
|
319
|
-
}
|
|
320
|
-
for (const f of fields) {
|
|
321
|
-
const columnOwner = columnToLabel.get(f.name);
|
|
322
|
-
if (columnOwner !== void 0 && columnOwner !== f.name) {
|
|
323
|
-
throw new Error(
|
|
324
|
-
`Fatal: field key map failed to build \u2014 field label "${f.name}" collides with the storage column of field "${columnOwner}". A field label may not reuse another field's column name. Rename the field, then run \`manguito validate\` to check your schema.`
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
for (const f of fields) {
|
|
329
|
-
if (isColumnBacked(f) && f.removed === true) {
|
|
330
|
-
columnToLabel.delete(f.db_column.column_name);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
const diverges = [...labelToColumn].some(([label, column]) => label !== column);
|
|
334
|
-
function remap(input, lookup) {
|
|
335
|
-
const out = {};
|
|
336
|
-
for (const key of Object.keys(input)) {
|
|
337
|
-
if (droppedKeys.has(key)) continue;
|
|
338
|
-
out[lookup.get(key) ?? key] = input[key];
|
|
339
|
-
}
|
|
340
|
-
return out;
|
|
341
|
-
}
|
|
342
|
-
return {
|
|
343
|
-
toStorage: (input) => remap(input, labelToColumn),
|
|
344
|
-
toLabels: (row) => remap(row, columnToLabel),
|
|
345
|
-
columnFor: (label) => labelToColumn.get(label),
|
|
346
|
-
labelFor: (column) => columnToLabel.get(column),
|
|
347
|
-
labels: [...labelToColumn.keys()],
|
|
348
|
-
diverges
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
|
|
352
392
|
export {
|
|
393
|
+
isColumnBacked,
|
|
394
|
+
createFieldKeyMap,
|
|
395
|
+
createFieldKeyMapFromProjection,
|
|
353
396
|
persistParagraphField,
|
|
354
397
|
deleteParagraphField,
|
|
355
398
|
persistJunctionField,
|
|
356
399
|
buildRelationsMap,
|
|
357
400
|
resolveRelationField,
|
|
358
|
-
resolveRelationBareIds
|
|
359
|
-
isColumnBacked,
|
|
360
|
-
createFieldKeyMap
|
|
401
|
+
resolveRelationBareIds
|
|
361
402
|
};
|
|
362
|
-
//# sourceMappingURL=chunk-
|
|
403
|
+
//# sourceMappingURL=chunk-JVP33FI2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/field-keys.ts","../src/relations.ts"],"sourcesContent":["import type { DbColumn, ParsedField } from '@bobbykim/manguito-cms-core'\n\n// ─── Label ↔ storage key mapping ──────────────────────────────────────────────\n//\n// A field has two names: its public LABEL (`field.name`, what API consumers and\n// the admin panel see) and its STORAGE key (`db_column.column_name`, the actual\n// Postgres column). They are identical today, but schema versioning makes a\n// rename change only the label — the column keeps its original name for the life\n// of the data. Every place that reads or writes a DB row must therefore use the\n// storage key, and every place that reads a request body or writes a response\n// must use the label.\n//\n// Only column-backed fields participate. Paragraph fields have no column\n// (their association lives on the paragraph table via parent_field) and\n// many-to-many references have no column either (the junction table owns the\n// association), so both keep the field name as their identity and are excluded.\n\n// A type predicate, not a plain boolean: narrowing `db_column` to non-null lets\n// the compiler enforce the invariant at every call site instead of each one\n// re-asserting it with `db_column!`.\nexport function isColumnBacked(field: ParsedField): field is ParsedField & { db_column: DbColumn } {\n const col = field.db_column\n if (col === null) return false\n if (col.column_name === '') return false\n if (col.junction) return false\n return true\n}\n\nexport type FieldKeyMap = {\n /** Request body (label-keyed) → storage-keyed. Unknown keys pass through. */\n toStorage(input: Record<string, unknown>): Record<string, unknown>\n /** DB row (storage-keyed) → label-keyed. Unknown keys pass through. */\n toLabels(row: Record<string, unknown>): Record<string, unknown>\n columnFor(label: string): string | undefined\n labelFor(column: string): string | undefined\n /** Labels of column-backed fields — the valid filter/sort surface. */\n labels: string[]\n /** False when every label equals its column, letting callers skip the copy. */\n diverges: boolean\n}\n\n/**\n * One field's place in the label space: the label it is known by, plus the\n * storage column it owns. `ownColumn` is ABSENT — never present-and-undefined,\n * per exactOptionalPropertyTypes — for a field with no column of its own.\n */\ntype LabelEntry = { label: string; ownColumn?: string }\n\n/**\n * The shared core: given a label↔column mapping and the FULL label space to\n * check against, produce a FieldKeyMap. Both `createFieldKeyMap` and\n * `createFieldKeyMapFromProjection` are thin adapters over this — the\n * collision check, the `diverges` computation and `remap` live here exactly\n * once.\n *\n * `pairs` may include entries that must NOT survive into the final map —\n * `createFieldKeyMap` passes tombstoned columns in alongside live ones,\n * exactly as the original single-function implementation did, so that the\n * collision check below (which runs against the unfiltered map) still\n * catches a live field's label colliding with a TOMBSTONE's column. Any\n * pair whose label or column appears in `droppedKeys` is stripped from\n * `labelToColumn`/`columnToLabel` immediately after the check, before\n * `diverges` and `labels` are computed — so the caller does not need to\n * pre-filter `pairs` itself, only tell this function what to drop.\n *\n * `allLabels` is every field's label, including fields with no column of\n * their own. That is not tidiness: a paragraph, many-to-many or programmatic\n * field's label is written into the same key space as storage columns before\n * `toLabels` runs, so one named after another field's column would overwrite\n * that column's value and then be renamed onto the other field's label.\n * Both constructors must pass the complete set.\n *\n * Each entry carries `ownColumn` — the column that field itself is backed by,\n * absent for a paragraph, many-to-many or programmatic field. The collision\n * check below needs it: a label that equals a column is a collision only when\n * the column belongs to a DIFFERENT field, and strings alone cannot tell the\n * two apart.\n *\n * `droppedKeys` also drives `remap`: it must actively remove a key from a\n * mapped object rather than merely leave it unmapped, because `remap` passes\n * an unmapped key through unchanged — a retained-but-unexposed column would\n * otherwise reach the output under its raw name.\n */\nfunction buildFieldKeyMap(\n pairs: Array<{ label: string; column: string }>,\n allLabels: LabelEntry[],\n droppedKeys: Set<string>\n): FieldKeyMap {\n const labelToColumn = new Map<string, string>()\n const columnToLabel = new Map<string, string>()\n for (const { label, column } of pairs) {\n labelToColumn.set(label, column)\n columnToLabel.set(column, label)\n }\n\n // A label that is also some OTHER field's column name would make toLabels\n // ambiguous: two source keys would map onto one destination key.\n //\n // Checked against EVERY label in `allLabels`, not just the ones with a\n // pair of their own. Paragraph, many-to-many and programmatic fields have\n // no column of their own, but their labels are written into the same key\n // space as storage columns before toLabels runs (routes/admin/content.ts,\n // relations.ts, programmatic/resolve.ts). A paragraph field named after\n // another field's column would overwrite that column's value on the row\n // and then be renamed onto the other field's label — serving the wrong\n // value under the wrong key.\n //\n // Deliberately run BEFORE dropped pairs are stripped from `columnToLabel`\n // below: a live field's label may collide with a TOMBSTONE's column (the\n // column still physically exists on the row), and that must keep\n // throwing. Stripping first would silently pass this configuration, and\n // the exclusion step afterward would then delete the live field's column\n // from every response instead of the tombstone's.\n //\n // Not detected: two fields declaring the SAME column name. A field can now\n // declare its own `column`, so this is no longer structurally impossible —\n // but core rejects it with `DUPLICATE_COLUMN` at parse time, so it is still\n // unreachable here.\n for (const { label, ownColumn } of allLabels) {\n // The label is this field's OWN column, exposed by this version under a\n // different name. That is not an ambiguity — it is one field seen twice,\n // under current's name and under the label this version uses — and there\n // is still exactly one column holding exactly one value. It happens when a\n // field is renamed away and then renamed BACK onto its column's name while\n // the intermediate version is still live. Without this skip the map refuses\n // to build and createCmsApp throws at startup for every version at once.\n //\n // Only the SAME field is exempted: `ownColumn` is absent for a field with\n // no column of its own (a paragraph, many-to-many or programmatic field's\n // label named after some other field's column is precisely the ambiguity\n // this check exists for), and differs from `label` when the name belongs to\n // one field while the column belongs to another.\n if (ownColumn === label) continue\n const columnOwner = columnToLabel.get(label)\n if (columnOwner !== undefined && columnOwner !== label) {\n throw new Error(\n `Fatal: field key map failed to build — field label \"${label}\" collides with the ` +\n `storage column of field \"${columnOwner}\". A field label may not reuse another ` +\n `field's column name. Rename the field, then run \\`manguito validate\\` to check your schema.`\n )\n }\n }\n\n // Only now strip dropped pairs — the collision check above has already run\n // against the full map. A dropped pair is removed from BOTH maps: from\n // `labelToColumn` by its label, from `columnToLabel` by its column.\n for (const label of labelToColumn.keys()) {\n if (droppedKeys.has(label)) labelToColumn.delete(label)\n }\n for (const column of columnToLabel.keys()) {\n if (droppedKeys.has(column)) columnToLabel.delete(column)\n }\n\n const diverges = [...labelToColumn].some(([label, column]) => label !== column)\n\n function remap(\n input: Record<string, unknown>,\n lookup: Map<string, string>\n ): Record<string, unknown> {\n // Always returns a NEW object, even when nothing diverges. Returning `input`\n // unchanged would make aliasing depend on the schema, so a bug where a\n // caller mutates a row after mapping would reproduce only on renamed\n // fields. A shallow copy per row is not worth that class of bug.\n //\n // Unknown keys pass through unchanged — which is exactly why a dropped\n // key must be checked and skipped explicitly here, rather than relying on\n // its absence from `lookup`: absence alone would let it pass through under\n // its raw key instead of being dropped.\n const out: Record<string, unknown> = {}\n for (const key of Object.keys(input)) {\n if (droppedKeys.has(key)) continue\n out[lookup.get(key) ?? key] = input[key]\n }\n return out\n }\n\n return {\n toStorage: (input) => remap(input, labelToColumn),\n toLabels: (row) => remap(row, columnToLabel),\n columnFor: (label) => labelToColumn.get(label),\n labelFor: (column) => columnToLabel.get(column),\n labels: [...labelToColumn.keys()],\n diverges,\n }\n}\n\n/**\n * Built ONCE per content type at startup, not per request. Throws on a key\n * collision, matching how createCmsApp refuses to boot on a broken roles\n * registry: an ambiguous mapping would silently corrupt responses.\n *\n * Tombstones (`field.removed === true`) are column-backed — the parser keeps\n * their column alive for older live versions — but the CURRENT version must\n * never serve or accept them. Their pair is passed into the shared core\n * alongside the live ones (so the collision check below still sees them —\n * see `buildFieldKeyMap`'s doc comment), and then stripped from the returned\n * map via `droppedKeys` — which also drives `remap`: without that, an\n * unmapped retained column would pass through `remap` unchanged and reach\n * the response under its raw column name.\n */\nexport function createFieldKeyMap(fields: ParsedField[]): FieldKeyMap {\n // Both the name and the column of every tombstone, so the shared core can\n // strip a tombstone under either key. They differ when a field was renamed\n // and THEN removed: it carries both `column` (the original, still-live\n // column) and `removed`.\n const droppedKeys = new Set<string>()\n const pairs: Array<{ label: string; column: string }> = []\n\n for (const f of fields) {\n if (!isColumnBacked(f)) continue\n // Keyed by `f.name` for every column-backed field, live or tombstoned, so\n // buildFieldKeyMap's post-check stripping (which deletes from\n // `labelToColumn` by the labels in `droppedKeys`) can find and remove a\n // tombstone's own entry. That leans on field names being unique across\n // live and tombstoned fields within one type — true today (core rejects\n // a duplicate name at parse time) but only load-bearing here because this\n // refactor now writes a tombstone's pair into the shared map at all; the\n // original single-function implementation `continue`d past a tombstone\n // before ever writing one, so the collision was structurally impossible.\n pairs.push({ label: f.name, column: f.db_column.column_name })\n if (f.removed === true) {\n droppedKeys.add(f.name)\n droppedKeys.add(f.db_column.column_name)\n }\n }\n\n // `ownColumn` is a strict no-op on this path and is passed only so the two\n // constructors share one core: here a label IS a field's name, so a field\n // whose own column equals its name already maps that column back to itself\n // (`columnOwner === label`) and never reached the throw. It matters only for\n // a projection, which can expose a column under some other label.\n return buildFieldKeyMap(\n pairs,\n fields.map((f) => ({\n label: f.name,\n // Conditional spread, not a plain assignment — exactOptionalPropertyTypes\n // forbids present-and-undefined.\n ...(isColumnBacked(f) && { ownColumn: f.db_column.column_name }),\n })),\n droppedKeys\n )\n}\n\n/**\n * From a version's projection. The projection is already the label↔column\n * mapping and already excludes tombstones and non-column-backed fields, so\n * there is nothing to filter — but the collision check still needs every\n * field's label, which is why `allFields` is required.\n */\nexport function createFieldKeyMapFromProjection(\n projectionType: { fields: Array<{ column_name: string; exposed_as: string; fallback?: unknown }> },\n allFields: ParsedField[]\n): FieldKeyMap {\n const pairs = projectionType.fields.map((f) => ({ label: f.exposed_as, column: f.column_name }))\n const projected = new Set(pairs.map((p) => p.label))\n // Every column-backed field this projection does NOT expose must be\n // actively dropped — not just tombstones. A tombstone's column is one way\n // a column can be absent from the projection, but it is not the only one:\n // a field added to the CURRENT schema after this version was cut is live\n // (`removed !== true`) and is just as absent from an older version's\n // projection, and `remap` passes an unknown key through unchanged — so\n // without this, a column added later would leak into every older live\n // version's response straight off `SELECT *`. Building the drop-set from\n // \"every column-backed field, then un-drop what this projection exposes\"\n // subsumes the tombstone case instead of special-casing it.\n const dropped = new Set<string>()\n for (const f of allFields) {\n if (!isColumnBacked(f)) continue\n dropped.add(f.name)\n dropped.add(f.db_column.column_name)\n }\n // A column this version DOES expose must not be dropped — protects both a\n // retained tombstone column (the original case) and a column that is live\n // in the current schema but simply predates this version (the general case\n // above). Same for its label.\n for (const p of pairs) dropped.delete(p.column)\n for (const label of projected) dropped.delete(label)\n\n return buildFieldKeyMap(\n pairs,\n allFields.map((f) => ({\n label: f.name,\n // See buildFieldKeyMap's collision check: this is what lets it tell a\n // version exposing a field's own column under a new label (fine) from a\n // label that reuses another field's column (not fine).\n ...(isColumnBacked(f) && { ownColumn: f.db_column.column_name }),\n })),\n dropped\n )\n}\n","import crypto from 'node:crypto'\nimport { sql } from 'drizzle-orm'\nimport type { ParsedField, ParsedParagraphType, SchemaRegistry } from '@bobbykim/manguito-cms-core'\nimport type { DrizzlePostgresInstance } from '@bobbykim/manguito-cms-db'\nimport type { MediaDelta } from './media-references.js'\n\n// ─── Relation persistence ─────────────────────────────────────────────────────\n//\n// Owns paragraph/junction/reference/media relation table SQL — both the write\n// side (persist/delete below) and the read side (descriptors + resolvers further\n// down). Each persist/delete returns the MediaDelta of media ids it gained and\n// lost (see media-references.ts), which the caller merges and reconciles once.\n// The repository's resolveRows() drives the read resolvers.\n\nfunction quoteIdent(name: string): string {\n if (!/^[a-z][a-z0-9_-]*$/.test(name)) throw new Error(`Unsafe identifier: ${name}`)\n return `\"${name}\"`\n}\n\n// Paragraph rows live on a child table with their own image/video/file columns\n// (e.g. a \"photo card\" block embeds an image) — these need the same reference-count\n// bookkeeping as top-level content fields, one level down.\nfunction paragraphMediaFieldNames(pType: ParsedParagraphType): Set<string> {\n return new Set(\n pType.fields\n .filter((f) => f.field_type === 'image' || f.field_type === 'video' || f.field_type === 'file')\n .map((f) => f.name)\n )\n}\n\nasync function fetchParagraphMediaIds(\n db: DrizzlePostgresInstance,\n pType: ParsedParagraphType,\n itemId: string,\n fieldName: string\n): Promise<string[]> {\n const mediaColumns = pType.fields\n .filter((f) => f.field_type === 'image' || f.field_type === 'video' || f.field_type === 'file')\n .map((f) => f.db_column!.column_name)\n if (mediaColumns.length === 0) return []\n\n const tbl = sql.raw(quoteIdent(pType.db.table_name))\n const cols = sql.join(mediaColumns.map((c) => sql.raw(quoteIdent(c))), sql`, `)\n const result = await db.execute(\n sql`SELECT ${cols} FROM ${tbl} WHERE parent_id = ${itemId} AND parent_field = ${fieldName}`\n )\n\n const ids: string[] = []\n for (const row of result.rows as Record<string, unknown>[]) {\n for (const col of mediaColumns) {\n const v = row[col]\n if (typeof v === 'string' && v !== '') ids.push(v)\n }\n }\n return ids\n}\n\n// A paragraph type's own paragraph fields — the one level of nesting ADR\n// core/0005 permits. Empty without a registry, which is how callers that have no\n// nesting to persist opt out.\nfunction nestedParagraphFields(\n pType: ParsedParagraphType,\n registry?: SchemaRegistry\n): Array<{ fieldName: string; nType: ParsedParagraphType }> {\n if (!registry) return []\n const out: Array<{ fieldName: string; nType: ParsedParagraphType }> = []\n for (const f of pType.fields) {\n if (f.db_column !== null) continue\n const comp = f.ui_component as { component: string; ref?: string }\n if (comp.component !== 'paragraph-embed' || !comp.ref) continue\n const nType = registry.paragraph_types[comp.ref]\n if (nType) out.push({ fieldName: f.name, nType })\n }\n return out\n}\n\n// Ids of the paragraph rows currently stored for one field of one parent.\nasync function fetchParagraphRowIds(\n db: DrizzlePostgresInstance,\n pType: ParsedParagraphType,\n itemId: string,\n fieldName: string\n): Promise<string[]> {\n const tbl = sql.raw(quoteIdent(pType.db.table_name))\n const result = await db.execute(\n sql`SELECT id FROM ${tbl} WHERE parent_id = ${itemId} AND parent_field = ${fieldName}`\n )\n return (result.rows as Record<string, unknown>[])\n .map((r) => r['id'])\n .filter((id): id is string => typeof id === 'string')\n}\n\n// Replaces every paragraph row for one field of one parent (delete + reinsert),\n// returning the media ids removed (old rows) and added (new rows).\n//\n// `registry` enables one level of paragraph nesting (ADR core/0005): a nested\n// paragraph field has no column on its parent's table, so without this its items\n// were silently dropped on write. Nested rows hang off the *paragraph* row's id,\n// and are torn down with it so the delete+reinsert cannot orphan them.\nexport async function persistParagraphField(\n db: DrizzlePostgresInstance,\n itemId: string,\n parentType: string,\n fieldName: string,\n pType: ParsedParagraphType,\n items: unknown[],\n registry?: SchemaRegistry\n): Promise<MediaDelta> {\n const removed = await fetchParagraphMediaIds(db, pType, itemId, fieldName)\n const nested = nestedParagraphFields(pType, registry)\n\n // Tear down nested rows before their parents disappear, collecting the media\n // they referenced so reference counts stay correct.\n if (nested.length > 0) {\n const staleIds = await fetchParagraphRowIds(db, pType, itemId, fieldName)\n for (const rowId of staleIds) {\n for (const n of nested) {\n const d = await deleteParagraphField(db, rowId, n.fieldName, n.nType, registry)\n removed.push(...d.removed)\n }\n }\n }\n\n const tbl = sql.raw(quoteIdent(pType.db.table_name))\n await db.execute(sql`DELETE FROM ${tbl} WHERE parent_id = ${itemId} AND parent_field = ${fieldName}`)\n\n const mediaFieldNames = paragraphMediaFieldNames(pType)\n const added: string[] = []\n\n for (let i = 0; i < items.length; i++) {\n const pItem = items[i] as Record<string, unknown>\n const rowId = crypto.randomUUID()\n const data: Record<string, unknown> = {\n id: rowId,\n parent_id: itemId,\n parent_type: parentType,\n parent_field: fieldName,\n order: i,\n created_at: new Date(),\n updated_at: new Date(),\n }\n for (const pf of pType.fields) {\n if (!pf.db_column || pf.db_column.junction) continue\n data[pf.db_column.column_name] = pItem[pf.name] ?? null\n }\n const cols = sql.join(Object.keys(data).map((k) => sql.raw(quoteIdent(k))), sql`, `)\n const vals = sql.join(Object.values(data).map((v) => sql`${v}`), sql`, `)\n await db.execute(sql`INSERT INTO ${tbl} (${cols}) VALUES (${vals})`)\n\n for (const name of mediaFieldNames) {\n const val = pItem[name]\n if (typeof val === 'string' && val !== '') added.push(val)\n }\n\n // Persist this row's nested paragraph items against the row just inserted.\n for (const n of nested) {\n const nestedItems = Array.isArray(pItem[n.fieldName]) ? (pItem[n.fieldName] as unknown[]) : []\n const d = await persistParagraphField(\n db,\n rowId,\n pType.db.table_name,\n n.fieldName,\n n.nType,\n nestedItems,\n registry\n )\n added.push(...d.added)\n removed.push(...d.removed)\n }\n }\n\n return { added, removed }\n}\n\n// Deletes all paragraph rows for one field of one parent (used when the parent is\n// being deleted — paragraph rows have no FK/cascade back to their parent, so they'd\n// leak otherwise). Returns the media those rows referenced, all removed.\nexport async function deleteParagraphField(\n db: DrizzlePostgresInstance,\n itemId: string,\n fieldName: string,\n pType: ParsedParagraphType,\n registry?: SchemaRegistry\n): Promise<MediaDelta> {\n const removed = await fetchParagraphMediaIds(db, pType, itemId, fieldName)\n\n // Cascade to nested paragraph rows, which hang off these rows' ids.\n const nested = nestedParagraphFields(pType, registry)\n if (nested.length > 0) {\n const rowIds = await fetchParagraphRowIds(db, pType, itemId, fieldName)\n for (const rowId of rowIds) {\n for (const n of nested) {\n const d = await deleteParagraphField(db, rowId, n.fieldName, n.nType, registry)\n removed.push(...d.removed)\n }\n }\n }\n\n const tbl = sql.raw(quoteIdent(pType.db.table_name))\n await db.execute(sql`DELETE FROM ${tbl} WHERE parent_id = ${itemId} AND parent_field = ${fieldName}`)\n return { added: [], removed }\n}\n\n// Replaces every junction row for one many-to-many field of one parent.\nexport async function persistJunctionField(\n db: DrizzlePostgresInstance,\n itemId: string,\n junction: { table_name: string; left_column: string; right_column: string },\n relatedIds: string[]\n): Promise<void> {\n const tbl = sql.raw(quoteIdent(junction.table_name))\n const left = sql.raw(quoteIdent(junction.left_column))\n const right = sql.raw(quoteIdent(junction.right_column))\n await db.execute(sql`DELETE FROM ${tbl} WHERE ${left} = ${itemId}`)\n for (const rid of relatedIds) {\n await db.execute(sql`INSERT INTO ${tbl} (${left}, ${right}) VALUES (${itemId}, ${rid})`)\n }\n}\n\n// ─── Relation descriptors and resolution (read side) ──────────────────────────\n//\n// Relation read resolution. These were lifted out of the repository so that all\n// paragraph/junction/reference/media table SQL lives in one module alongside the\n// write persistence above. The repository's resolveRows() calls into here.\n\nexport type ParagraphRelationDef = {\n type: 'paragraph'\n table: string\n}\n\nexport type ReferenceRelationDef = {\n type: 'reference'\n table: string\n fk_column: string\n}\n\nexport type JunctionRelationDef = {\n type: 'junction'\n table: string\n junction_table: string\n left_column: string\n right_column: string\n // Only ordered junctions have an \"order\" column (db codegen emits it only when\n // order_column is true) — the resolver must not ORDER BY it otherwise.\n order_column: boolean\n}\n\nexport type MediaRelationDef = {\n type: 'media'\n fk_column: string\n}\n\nexport type RelationDef =\n | ParagraphRelationDef\n | ReferenceRelationDef\n | JunctionRelationDef\n | MediaRelationDef\n\n// Derives a content type's relations map from its parsed fields, so paragraph/\n// reference/media fields are actually resolved instead of silently dropped.\n// Junction and foreign_key info is already on each field's db_column; paragraph\n// fields store their target table on the paragraph type, hence the registry.\nexport function buildRelationsMap(\n fields: ParsedField[],\n registry: SchemaRegistry\n): Record<string, RelationDef> {\n const relations: Record<string, RelationDef> = {}\n\n for (const field of fields) {\n if (field.field_type === 'image' || field.field_type === 'video' || field.field_type === 'file') {\n if (!field.db_column) continue\n relations[field.name] = { type: 'media', fk_column: field.db_column.column_name }\n } else if (field.field_type === 'paragraph') {\n const ref = (field.ui_component as { ref?: string }).ref\n const pType = ref ? registry.paragraph_types[ref] : undefined\n if (!pType) continue\n relations[field.name] = { type: 'paragraph', table: pType.db.table_name }\n } else if (field.field_type === 'reference') {\n if (!field.db_column) continue\n if (field.db_column.junction) {\n const j = field.db_column.junction\n relations[field.name] = {\n type: 'junction',\n table: j.right_table,\n junction_table: j.table_name,\n left_column: j.left_column,\n right_column: j.right_column,\n order_column: j.order_column,\n }\n } else if (field.db_column.foreign_key) {\n relations[field.name] = {\n type: 'reference',\n table: field.db_column.foreign_key.table,\n fk_column: field.db_column.column_name,\n }\n }\n }\n }\n\n return relations\n}\n\nfunction groupBy<T extends Record<string, unknown>>(\n items: T[],\n key: string\n): Record<string, T[]> {\n const result: Record<string, T[]> = {}\n for (const item of items) {\n const k = String(item[key])\n if (!result[k]) result[k] = []\n result[k]!.push(item)\n }\n return result\n}\n\n// A reference/media pass is DESTRUCTIVE: the resolved object replaces the raw FK\n// value, and when the field's label differs from its FK column (a renamed field)\n// the raw FK key is deleted outright — otherwise the response would carry both\n// the column name and the label.\n//\n// That makes a second pass over the same row object dangerous: the FK the first\n// pass consumed is gone, so the row would be nulled out. And the same object\n// really does recur — reference/junction targets are cached by `table:id`, so two\n// parents receive ONE shared object, and the GraphQL dataloaders deliberately do\n// not memoize by parent identity (\"rows are mutated and may recur across nesting\n// levels\", dataloaders.ts). So a row that already holds a resolved value is\n// skipped, which makes the pass idempotent.\nfunction needsFkResolution(\n row: Record<string, unknown>,\n fkColumn: string,\n fieldName: string\n): boolean {\n // Label diverges from the column: a missing FK key means it was already dropped.\n if (fkColumn !== fieldName && !(fkColumn in row)) return false\n // Label equals the column: the resolved object sits where the raw id was, so an\n // object (never a bare id) means this row is already done.\n const current = row[fieldName]\n return !(typeof current === 'object' && current !== null)\n}\n\n// Fully resolves a relation field on a batch of rows: paragraph → ordered rows,\n// reference → the target row, junction → target rows, media → the media row.\n// The cache (keyed table:id) dedupes target lookups within a request.\n//\n// `publishedOnly` (default false, preserving prior behavior for admin callers)\n// adds `AND published = true` to the reference/junction target-row SELECTs.\n// Reference and junction targets are always content or taxonomy tables, which\n// always carry a `published` boolean system field — see CONTENT_SYSTEM_FIELDS /\n// TAXONOMY_SYSTEM_FIELDS in packages/core/src/parser/parseSchema.ts. Paragraph\n// and media targets are deliberately excluded: paragraph rows are owned by\n// their parent (no independent publish state) and media rows have no\n// `published` column at all.\nexport async function resolveRelationField(\n db: DrizzlePostgresInstance,\n rows: Record<string, unknown>[],\n fieldName: string,\n rel: RelationDef,\n cache: Map<string, unknown>,\n publishedOnly = false\n): Promise<void> {\n if (rows.length === 0) return\n\n // Deduped by object identity: one batch can hold the same row twice (see\n // needsFkResolution above), and the destructive branches would then read an FK\n // the first visit already consumed. The caller's array is left untouched — the\n // GraphQL dataloader maps over it to build its results.\n const batch = [...new Set(rows)]\n\n if (rel.type === 'paragraph') {\n const parentIds = batch.map((r) => r['id'] as string)\n const inList = sql.join(parentIds.map((id) => sql`${id}`), sql`, `)\n // Scoped by parent_field as well as parent_id: two paragraph fields of the\n // same paragraph type share one table, so filtering on the parent alone\n // hands each field the other's rows.\n const result = await db.execute(\n sql`SELECT * FROM ${sql.raw(quoteIdent(rel.table))} WHERE parent_id IN (${inList}) AND parent_field = ${fieldName} ORDER BY \"order\" ASC`\n )\n const byParent = groupBy(result.rows as Record<string, unknown>[], 'parent_id')\n for (const row of batch) {\n row[fieldName] = byParent[row['id'] as string] ?? []\n }\n } else if (rel.type === 'reference') {\n const dropFk = rel.fk_column !== fieldName\n const pending = batch.filter((r) => needsFkResolution(r, rel.fk_column, fieldName))\n if (pending.length === 0) return\n\n const fkValues = pending.map((r) => r[rel.fk_column] as string).filter(Boolean)\n if (fkValues.length === 0) {\n for (const row of pending) {\n row[fieldName] = null\n if (dropFk) delete row[rel.fk_column]\n }\n return\n }\n const unique = [...new Set(fkValues)]\n const uncached = unique.filter((id) => !cache.has(`${rel.table}:${id}`))\n if (uncached.length > 0) {\n const inList = sql.join(uncached.map((id) => sql`${id}`), sql`, `)\n const publishedCond = publishedOnly ? sql` AND published = true` : sql``\n const result = await db.execute(\n sql`SELECT * FROM ${sql.raw(quoteIdent(rel.table))} WHERE id IN (${inList})${publishedCond}`\n )\n for (const item of result.rows as Record<string, unknown>[]) {\n cache.set(`${rel.table}:${item['id']}`, item)\n }\n }\n for (const row of pending) {\n const fkVal = row[rel.fk_column] as string\n row[fieldName] = fkVal ? (cache.get(`${rel.table}:${fkVal}`) ?? null) : null\n if (dropFk) delete row[rel.fk_column]\n }\n } else if (rel.type === 'junction') {\n const parentIds = batch.map((r) => r['id'] as string)\n const inList = sql.join(parentIds.map((id) => sql`${id}`), sql`, `)\n const orderBy = rel.order_column ? sql` ORDER BY \"order\" ASC` : sql``\n const junctionResult = await db.execute(\n sql`SELECT * FROM ${sql.raw(quoteIdent(rel.junction_table))} WHERE ${sql.raw(quoteIdent(rel.left_column))} IN (${inList})${orderBy}`\n )\n const jRows = junctionResult.rows as Record<string, unknown>[]\n const rightIds = [...new Set(jRows.map((r) => r[rel.right_column] as string))]\n const uncached = rightIds.filter((id) => !cache.has(`${rel.table}:${id}`))\n if (uncached.length > 0) {\n const rightInList = sql.join(uncached.map((id) => sql`${id}`), sql`, `)\n const publishedCond = publishedOnly ? sql` AND published = true` : sql``\n const entitiesResult = await db.execute(\n sql`SELECT * FROM ${sql.raw(quoteIdent(rel.table))} WHERE id IN (${rightInList})${publishedCond}`\n )\n for (const item of entitiesResult.rows as Record<string, unknown>[]) {\n cache.set(`${rel.table}:${item['id']}`, item)\n }\n }\n const byLeft = groupBy(jRows, rel.left_column)\n for (const row of batch) {\n const jEntries = byLeft[row['id'] as string] ?? []\n row[fieldName] = jEntries\n .map((jr) => cache.get(`${rel.table}:${jr[rel.right_column] as string}`))\n .filter(Boolean)\n }\n } else if (rel.type === 'media') {\n const dropFk = rel.fk_column !== fieldName\n const pending = batch.filter((r) => needsFkResolution(r, rel.fk_column, fieldName))\n if (pending.length === 0) return\n\n const fkValues = pending.map((r) => r[rel.fk_column] as string).filter(Boolean)\n if (fkValues.length === 0) {\n for (const row of pending) {\n row[fieldName] = null\n if (dropFk) delete row[rel.fk_column]\n }\n return\n }\n const unique = [...new Set(fkValues)]\n const uncached = unique.filter((id) => !cache.has(`media:${id}`))\n if (uncached.length > 0) {\n const inList = sql.join(uncached.map((id) => sql`${id}`), sql`, `)\n const result = await db.execute(sql`SELECT * FROM \"media\" WHERE id IN (${inList})`)\n for (const item of result.rows as Record<string, unknown>[]) {\n cache.set(`media:${item['id']}`, item)\n }\n }\n for (const row of pending) {\n const fkVal = row[rel.fk_column] as string\n row[fieldName] = fkVal ? (cache.get(`media:${fkVal}`) ?? null) : null\n if (dropFk) delete row[rel.fk_column]\n }\n }\n}\n\n// Populates paragraph/junction fields with bare ID arrays when they are not\n// explicitly included — they have no column on the owning table, so without this\n// they'd be silently absent. Reference fields already carry their bare ID as a\n// real column from `SELECT *`, so they need no extra query.\nexport async function resolveRelationBareIds(\n db: DrizzlePostgresInstance,\n rows: Record<string, unknown>[],\n fieldName: string,\n rel: RelationDef\n): Promise<void> {\n if (rows.length === 0) return\n\n if (rel.type === 'paragraph') {\n const parentIds = rows.map((r) => r['id'] as string)\n const inList = sql.join(parentIds.map((id) => sql`${id}`), sql`, `)\n const result = await db.execute(\n sql`SELECT id, parent_id FROM ${sql.raw(quoteIdent(rel.table))} WHERE parent_id IN (${inList}) AND parent_field = ${fieldName} ORDER BY \"order\" ASC`\n )\n const byParent = groupBy(result.rows as Record<string, unknown>[], 'parent_id')\n for (const row of rows) {\n row[fieldName] = (byParent[row['id'] as string] ?? []).map((r) => r['id'])\n }\n } else if (rel.type === 'junction') {\n const parentIds = rows.map((r) => r['id'] as string)\n const inList = sql.join(parentIds.map((id) => sql`${id}`), sql`, `)\n const result = await db.execute(\n sql`SELECT ${sql.raw(quoteIdent(rel.left_column))} AS left_id, ${sql.raw(quoteIdent(rel.right_column))} AS right_id FROM ${sql.raw(quoteIdent(rel.junction_table))} WHERE ${sql.raw(quoteIdent(rel.left_column))} IN (${inList})`\n )\n const byLeft = groupBy(result.rows as Record<string, unknown>[], 'left_id')\n for (const row of rows) {\n row[fieldName] = (byLe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,SAAS,YAAY;AAClC,UAAM,YAAY,KAAK,IAAI,CAAC,MAAM,EAAE,IAAI,CAAW;AACnD,UAAM,SAAS,IAAI,KAAK,UAAU,IAAI,CAAC,OAAO,MAAM,EAAE,EAAE,GAAG,OAAO;AAClE,UAAM,SAAS,MAAM,GAAG;AAAA,MACtB,aAAa,IAAI,IAAI,WAAW,IAAI,WAAW,CAAC,CAAC,gBAAgB,IAAI,IAAI,WAAW,IAAI,YAAY,CAAC,CAAC,qBAAqB,IAAI,IAAI,WAAW,IAAI,cAAc,CAAC,CAAC,UAAU,IAAI,IAAI,WAAW,IAAI,WAAW,CAAC,CAAC,QAAQ,MAAM;AAAA,IAChO;AACA,UAAM,SAAS,QAAQ,OAAO,MAAmC,SAAS;AAC1E,eAAW,OAAO,MAAM;AACtB,UAAI,SAAS,KAAK,OAAO,IAAI,IAAI,CAAW,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC;AAAA,IAC/E;AAAA,EACF;AACF;","names":[]}
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
buildRelationsMap,
|
|
3
3
|
isColumnBacked,
|
|
4
4
|
resolveRelationField
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-JVP33FI2.mjs";
|
|
6
6
|
|
|
7
7
|
// src/graphql/handler.ts
|
|
8
8
|
import { createYoga, maskError } from "graphql-yoga";
|
|
@@ -142,10 +142,13 @@ var SORTABLE = [
|
|
|
142
142
|
{ gql: "createdAt", value: "created_at" },
|
|
143
143
|
{ gql: "updatedAt", value: "updated_at" }
|
|
144
144
|
];
|
|
145
|
-
function buildSortFieldEnum(typeName) {
|
|
145
|
+
function buildSortFieldEnum(typeName, fieldKeys) {
|
|
146
|
+
const resolvable = SORTABLE.filter(
|
|
147
|
+
(s) => s.gql === "createdAt" || s.gql === "updatedAt" || fieldKeys === void 0 || fieldKeys.columnFor(s.value) !== void 0
|
|
148
|
+
);
|
|
146
149
|
return new GraphQLEnumType({
|
|
147
150
|
name: `${typeName}SortField`,
|
|
148
|
-
values: Object.fromEntries(
|
|
151
|
+
values: Object.fromEntries(resolvable.map((s) => [s.gql, { value: s.value }]))
|
|
149
152
|
});
|
|
150
153
|
}
|
|
151
154
|
function comparableFilterInput(name, scalar) {
|
|
@@ -189,18 +192,19 @@ function filterInputForField(fieldType) {
|
|
|
189
192
|
if (scalar === null) return null;
|
|
190
193
|
return StringFilter;
|
|
191
194
|
}
|
|
192
|
-
function buildFilterInputType(type) {
|
|
195
|
+
function buildFilterInputType(type, viewFields) {
|
|
193
196
|
const fields = {};
|
|
194
197
|
fields["id"] = { type: IDFilter };
|
|
195
198
|
fields["published"] = { type: BooleanFilter };
|
|
196
199
|
fields["createdAt"] = { type: DateTimeFilter };
|
|
197
200
|
fields["updatedAt"] = { type: DateTimeFilter };
|
|
198
201
|
if (type.schema_type === "content-type") fields["slug"] = { type: StringFilter };
|
|
199
|
-
|
|
202
|
+
const entries = viewFields !== void 0 ? viewFields.map((v) => ({ field: v.field, exposedAs: v.exposedAs })) : type.fields.filter((f) => f.removed !== true).map((f) => ({ field: f, exposedAs: f.name }));
|
|
203
|
+
for (const { field: f, exposedAs } of entries) {
|
|
200
204
|
if (f.field_type === "programmatic" || f.field_type === "paragraph") continue;
|
|
201
205
|
if (f.field_type === "image" || f.field_type === "video" || f.field_type === "file") continue;
|
|
202
206
|
const input = filterInputForField(f.field_type);
|
|
203
|
-
if (input) fields[buildFieldNameMap([
|
|
207
|
+
if (input) fields[buildFieldNameMap([exposedAs]).toGraphql(exposedAs)] = { type: input };
|
|
204
208
|
}
|
|
205
209
|
if (Object.keys(fields).length === 0) return null;
|
|
206
210
|
return new GraphQLInputObjectType({ name: `${graphqlTypeName(type.name)}Filter`, fields });
|
|
@@ -236,32 +240,41 @@ function codeError(code, message) {
|
|
|
236
240
|
function isPublished(item) {
|
|
237
241
|
return !!item && item["published"] === true;
|
|
238
242
|
}
|
|
239
|
-
function resolveFieldValue(field, row) {
|
|
243
|
+
function resolveFieldValue(field, row, fallback) {
|
|
240
244
|
const key = isColumnBacked(field) ? field.db_column.column_name : field.name;
|
|
241
|
-
|
|
245
|
+
const value = row[key];
|
|
246
|
+
if ((value === null || value === void 0) && fallback !== void 0) return fallback;
|
|
247
|
+
return value ?? null;
|
|
242
248
|
}
|
|
243
|
-
function scalarFieldResolver(field) {
|
|
244
|
-
return (parent) => resolveFieldValue(field, parent);
|
|
249
|
+
function scalarFieldResolver(field, fallback) {
|
|
250
|
+
return (parent) => resolveFieldValue(field, parent, fallback);
|
|
245
251
|
}
|
|
246
252
|
function relationFieldResolver(typeName, schemaFieldName) {
|
|
247
253
|
return (parent, _args, ctx) => ctx.loaders.load(typeName, schemaFieldName, parent);
|
|
248
254
|
}
|
|
249
|
-
function programmaticFieldResolver(typeName, schemaFieldName,
|
|
255
|
+
function programmaticFieldResolver(typeName, schemaFieldName, mediaFields = [], fieldKeys) {
|
|
250
256
|
return async (parent, _args, ctx) => {
|
|
251
257
|
let p = ctx.programmaticMemo.get(parent);
|
|
252
258
|
if (!p) {
|
|
253
|
-
p = resolveProgrammaticRow(typeName, parent, ctx,
|
|
259
|
+
p = resolveProgrammaticRow(typeName, parent, ctx, mediaFields, fieldKeys);
|
|
254
260
|
ctx.programmaticMemo.set(parent, p);
|
|
255
261
|
}
|
|
256
262
|
return (await p)[schemaFieldName];
|
|
257
263
|
};
|
|
258
264
|
}
|
|
259
|
-
async function resolveProgrammaticRow(typeName, parent, ctx,
|
|
265
|
+
async function resolveProgrammaticRow(typeName, parent, ctx, mediaFields, fieldKeys) {
|
|
260
266
|
const toLabels = (row) => fieldKeys ? fieldKeys.toLabels(row) : row;
|
|
261
|
-
if (
|
|
267
|
+
if (mediaFields.length === 0) return ctx.resolver.resolveItem(typeName, toLabels(parent));
|
|
262
268
|
const enriched = { ...parent };
|
|
263
|
-
await Promise.all(
|
|
264
|
-
return ctx.resolver.resolveItem(typeName, toLabels(enriched));
|
|
269
|
+
await Promise.all(mediaFields.map((m) => ctx.loaders.load(typeName, m.name, enriched)));
|
|
270
|
+
return ctx.resolver.resolveItem(typeName, relabelMedia(toLabels(enriched), enriched, mediaFields));
|
|
271
|
+
}
|
|
272
|
+
function relabelMedia(record, enriched, mediaFields) {
|
|
273
|
+
for (const { name, exposedAs } of mediaFields) {
|
|
274
|
+
if (!(name in enriched)) continue;
|
|
275
|
+
record[exposedAs] = enriched[name];
|
|
276
|
+
}
|
|
277
|
+
return record;
|
|
265
278
|
}
|
|
266
279
|
function collectionResolver(typeName, nameMap, fieldKeys) {
|
|
267
280
|
return async (_root, args, ctx) => {
|
|
@@ -335,7 +348,7 @@ var MEDIA = new GraphQLObjectType({
|
|
|
335
348
|
duration: { type: GraphQLInt3, resolve: (m) => m.duration }
|
|
336
349
|
}
|
|
337
350
|
});
|
|
338
|
-
function buildGraphQLSchema(registry, fieldKeyMaps = {}) {
|
|
351
|
+
function buildGraphQLSchema(registry, fieldKeyMaps = {}, view) {
|
|
339
352
|
const objectTypes = /* @__PURE__ */ new Map();
|
|
340
353
|
const enumTypes = /* @__PURE__ */ new Map();
|
|
341
354
|
for (const [name, enumType] of Object.entries(registry.enum_types)) {
|
|
@@ -354,14 +367,14 @@ function buildGraphQLSchema(registry, fieldKeyMaps = {}) {
|
|
|
354
367
|
);
|
|
355
368
|
}
|
|
356
369
|
}
|
|
357
|
-
function outputTypeForField(field) {
|
|
370
|
+
function outputTypeForField(field, required) {
|
|
358
371
|
const scalar = scalarOutputType(field.field_type);
|
|
359
|
-
if (scalar) return
|
|
372
|
+
if (scalar) return required ? new GraphQLNonNull2(scalar) : scalar;
|
|
360
373
|
if (field.field_type === "enum") {
|
|
361
374
|
const ref = field.ui_component.component === "select" ? field.ui_component.enum_ref : void 0;
|
|
362
375
|
const et = ref ? enumTypes.get(ref) : void 0;
|
|
363
376
|
const t = et ?? GraphQLString3;
|
|
364
|
-
return
|
|
377
|
+
return required ? new GraphQLNonNull2(t) : t;
|
|
365
378
|
}
|
|
366
379
|
if (field.field_type === "image" || field.field_type === "video" || field.field_type === "file") {
|
|
367
380
|
return MEDIA;
|
|
@@ -391,8 +404,17 @@ function buildGraphQLSchema(registry, fieldKeyMaps = {}) {
|
|
|
391
404
|
}
|
|
392
405
|
return GraphQLString3;
|
|
393
406
|
}
|
|
407
|
+
function exposedFields(type) {
|
|
408
|
+
return type.fields.filter((f) => f.removed !== true);
|
|
409
|
+
}
|
|
410
|
+
function viewFieldsFor(machineName, type) {
|
|
411
|
+
return view?.[machineName]?.fields ?? exposedFields(type).map((f) => ({ field: f, exposedAs: f.name, required: f.required }));
|
|
412
|
+
}
|
|
394
413
|
function buildObjectType(machineName, type) {
|
|
395
|
-
const
|
|
414
|
+
const visible = viewFieldsFor(machineName, type);
|
|
415
|
+
const mediaFields = visible.filter(
|
|
416
|
+
(v) => v.field.field_type === "image" || v.field.field_type === "video" || v.field.field_type === "file"
|
|
417
|
+
).map((v) => ({ name: v.field.name, exposedAs: v.exposedAs }));
|
|
396
418
|
return new GraphQLObjectType({
|
|
397
419
|
name: graphqlTypeName(machineName),
|
|
398
420
|
fields: () => {
|
|
@@ -406,23 +428,25 @@ function buildGraphQLSchema(registry, fieldKeyMaps = {}) {
|
|
|
406
428
|
}
|
|
407
429
|
fields["createdAt"] = { type: new GraphQLNonNull2(DateTimeScalar), resolve: (p) => p["created_at"] };
|
|
408
430
|
fields["updatedAt"] = { type: new GraphQLNonNull2(DateTimeScalar), resolve: (p) => p["updated_at"] };
|
|
409
|
-
for (const
|
|
410
|
-
const
|
|
411
|
-
const
|
|
431
|
+
for (const vf of visible) {
|
|
432
|
+
const field = vf.field;
|
|
433
|
+
const gqlName = toCamelCase(vf.exposedAs);
|
|
434
|
+
const outType = outputTypeForField(field, vf.required);
|
|
412
435
|
let resolve;
|
|
413
436
|
if (field.field_type === "programmatic") {
|
|
414
|
-
resolve = programmaticFieldResolver(
|
|
415
|
-
machineName,
|
|
416
|
-
field.name,
|
|
417
|
-
mediaFieldNames,
|
|
418
|
-
fieldKeyMaps[machineName]
|
|
419
|
-
);
|
|
437
|
+
resolve = programmaticFieldResolver(machineName, field.name, mediaFields, fieldKeyMaps[machineName]);
|
|
420
438
|
} else if (field.field_type === "reference" || field.field_type === "paragraph" || field.field_type === "image" || field.field_type === "video" || field.field_type === "file") {
|
|
421
439
|
resolve = relationFieldResolver(machineName, field.name);
|
|
422
440
|
} else {
|
|
423
|
-
resolve = scalarFieldResolver(field);
|
|
441
|
+
resolve = scalarFieldResolver(field, vf.fallback);
|
|
424
442
|
}
|
|
425
|
-
fields[gqlName] = {
|
|
443
|
+
fields[gqlName] = {
|
|
444
|
+
type: outType,
|
|
445
|
+
resolve,
|
|
446
|
+
// Conditional spread, not `deprecationReason: vf.deprecationReason`
|
|
447
|
+
// — exactOptionalPropertyTypes forbids present-and-undefined.
|
|
448
|
+
...vf.deprecationReason !== void 0 && { deprecationReason: vf.deprecationReason }
|
|
449
|
+
};
|
|
426
450
|
}
|
|
427
451
|
return fields;
|
|
428
452
|
}
|
|
@@ -454,7 +478,8 @@ function buildGraphQLSchema(registry, fieldKeyMaps = {}) {
|
|
|
454
478
|
const queryFields = {};
|
|
455
479
|
for (const [name, ct] of Object.entries(registry.content_types)) {
|
|
456
480
|
const objType = objectTypes.get(name);
|
|
457
|
-
const
|
|
481
|
+
const visible = viewFieldsFor(name, ct);
|
|
482
|
+
const nameMap = buildFieldNameMap(visible.map((v) => v.exposedAs));
|
|
458
483
|
if (ct.only_one) {
|
|
459
484
|
queryFields[singleQueryName(name)] = { type: objType, resolve: singletonResolver(name) };
|
|
460
485
|
continue;
|
|
@@ -466,13 +491,13 @@ function buildGraphQLSchema(registry, fieldKeyMaps = {}) {
|
|
|
466
491
|
meta: { type: new GraphQLNonNull2(PAGE_META), resolve: (r) => r.meta }
|
|
467
492
|
}
|
|
468
493
|
});
|
|
469
|
-
const filterType = buildFilterInputType(ct);
|
|
494
|
+
const filterType = buildFilterInputType(ct, visible);
|
|
470
495
|
queryFields[collectionQueryName(name)] = {
|
|
471
496
|
type: new GraphQLNonNull2(listType),
|
|
472
497
|
args: {
|
|
473
498
|
page: { type: GraphQLInt3 },
|
|
474
499
|
perPage: { type: GraphQLInt3 },
|
|
475
|
-
sortBy: { type: buildSortFieldEnum(graphqlTypeName(name)) },
|
|
500
|
+
sortBy: { type: buildSortFieldEnum(graphqlTypeName(name), fieldKeyMaps[name]) },
|
|
476
501
|
sortOrder: { type: SortOrderEnum },
|
|
477
502
|
...filterType ? { filter: { type: filterType } } : {}
|
|
478
503
|
},
|
|
@@ -496,7 +521,11 @@ function buildGraphQLSchema(registry, fieldKeyMaps = {}) {
|
|
|
496
521
|
queryFields[collectionQueryName(name)] = {
|
|
497
522
|
type: new GraphQLNonNull2(listType),
|
|
498
523
|
args: { page: { type: GraphQLInt3 }, perPage: { type: GraphQLInt3 } },
|
|
499
|
-
resolve: collectionResolver(
|
|
524
|
+
resolve: collectionResolver(
|
|
525
|
+
name,
|
|
526
|
+
buildFieldNameMap(viewFieldsFor(name, tt).map((v) => v.exposedAs)),
|
|
527
|
+
fieldKeyMaps[name]
|
|
528
|
+
)
|
|
500
529
|
};
|
|
501
530
|
queryFields[singleQueryName(name)] = {
|
|
502
531
|
type: objType,
|
|
@@ -509,6 +538,70 @@ function buildGraphQLSchema(registry, fieldKeyMaps = {}) {
|
|
|
509
538
|
});
|
|
510
539
|
}
|
|
511
540
|
|
|
541
|
+
// src/graphql/version-view.ts
|
|
542
|
+
function byColumn(fields) {
|
|
543
|
+
const out = /* @__PURE__ */ new Map();
|
|
544
|
+
for (const f of fields) {
|
|
545
|
+
if (!isColumnBacked(f)) continue;
|
|
546
|
+
out.set(f.db_column.column_name, f);
|
|
547
|
+
}
|
|
548
|
+
return out;
|
|
549
|
+
}
|
|
550
|
+
function deprecationFor(field, currentLabels, currentVersion) {
|
|
551
|
+
const currentLabel = currentLabels.get(field.column_name);
|
|
552
|
+
if (currentLabel === void 0) {
|
|
553
|
+
return `Removed in ${currentVersion}; column retained while this version is live.`;
|
|
554
|
+
}
|
|
555
|
+
if (currentLabel !== field.exposed_as) {
|
|
556
|
+
return `Renamed to '${currentLabel}' in ${currentVersion}.`;
|
|
557
|
+
}
|
|
558
|
+
return void 0;
|
|
559
|
+
}
|
|
560
|
+
function buildVersionView(input) {
|
|
561
|
+
const { registry, projection, currentProjection, currentVersion } = input;
|
|
562
|
+
const out = {};
|
|
563
|
+
const sources = [
|
|
564
|
+
registry.content_types,
|
|
565
|
+
registry.taxonomy_types,
|
|
566
|
+
registry.paragraph_types
|
|
567
|
+
];
|
|
568
|
+
for (const source of sources) {
|
|
569
|
+
for (const [typeName, type] of Object.entries(source)) {
|
|
570
|
+
const projectionType = projection?.types[typeName];
|
|
571
|
+
if (projectionType === void 0) {
|
|
572
|
+
out[typeName] = {
|
|
573
|
+
fields: type.fields.filter((f) => f.removed !== true).map((f) => ({ field: f, exposedAs: f.name, required: f.required }))
|
|
574
|
+
};
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
const columns = byColumn(type.fields);
|
|
578
|
+
const currentLabels = /* @__PURE__ */ new Map();
|
|
579
|
+
for (const f of currentProjection?.types[typeName]?.fields ?? []) {
|
|
580
|
+
currentLabels.set(f.column_name, f.exposed_as);
|
|
581
|
+
}
|
|
582
|
+
const fields = [];
|
|
583
|
+
for (const pf of projectionType.fields) {
|
|
584
|
+
const field = columns.get(pf.column_name);
|
|
585
|
+
if (field === void 0) continue;
|
|
586
|
+
const reason = deprecationFor(pf, currentLabels, currentVersion);
|
|
587
|
+
fields.push({
|
|
588
|
+
field,
|
|
589
|
+
exposedAs: pf.exposed_as,
|
|
590
|
+
required: pf.required,
|
|
591
|
+
...pf.fallback !== void 0 && { fallback: pf.fallback },
|
|
592
|
+
...reason !== void 0 && { deprecationReason: reason }
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
for (const f of type.fields) {
|
|
596
|
+
if (isColumnBacked(f) || f.removed === true) continue;
|
|
597
|
+
fields.push({ field: f, exposedAs: f.name, required: f.required });
|
|
598
|
+
}
|
|
599
|
+
out[typeName] = { fields };
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return out;
|
|
603
|
+
}
|
|
604
|
+
|
|
512
605
|
// src/graphql/dataloaders.ts
|
|
513
606
|
import DataLoader from "dataloader";
|
|
514
607
|
function createRelationLoaders(db, registry) {
|
|
@@ -584,15 +677,29 @@ function isClientSafeGraphQLError(error) {
|
|
|
584
677
|
}
|
|
585
678
|
return false;
|
|
586
679
|
}
|
|
587
|
-
function createGraphQLHandler(registry, repos, fieldKeyMaps, resolver, db, options) {
|
|
588
|
-
|
|
680
|
+
function createGraphQLHandler(registry, repos, fieldKeyMaps, resolver, db, options, versioning = {}) {
|
|
681
|
+
let view;
|
|
682
|
+
if (versioning.projection !== void 0) {
|
|
683
|
+
if (versioning.currentVersion === void 0) {
|
|
684
|
+
throw new Error(
|
|
685
|
+
'createGraphQLHandler: currentVersion is required when a projection is supplied \u2014 deprecation reasons name it, and an empty one ships "Removed in ." into published SDL.'
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
view = buildVersionView({
|
|
689
|
+
registry,
|
|
690
|
+
projection: versioning.projection,
|
|
691
|
+
currentProjection: versioning.currentProjection,
|
|
692
|
+
currentVersion: versioning.currentVersion
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
const schema = buildGraphQLSchema(registry, fieldKeyMaps, view);
|
|
589
696
|
const { plugins } = buildArmorPlugin({
|
|
590
697
|
maxDepth: options.maxDepth,
|
|
591
698
|
maxComplexity: options.maxComplexity
|
|
592
699
|
});
|
|
593
700
|
const yoga = createYoga({
|
|
594
701
|
schema,
|
|
595
|
-
graphqlEndpoint: "/graphql",
|
|
702
|
+
graphqlEndpoint: versioning.endpoint ?? "/graphql",
|
|
596
703
|
graphiql: options.graphiql,
|
|
597
704
|
landingPage: false,
|
|
598
705
|
maskedErrors: {
|
|
@@ -618,4 +725,4 @@ function createGraphQLHandler(registry, repos, fieldKeyMaps, resolver, db, optio
|
|
|
618
725
|
export {
|
|
619
726
|
createGraphQLHandler
|
|
620
727
|
};
|
|
621
|
-
//# sourceMappingURL=chunk-
|
|
728
|
+
//# sourceMappingURL=chunk-XNXM4W4K.mjs.map
|