@conloca/astro-cms 0.2.1 → 0.2.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.
Files changed (101) hide show
  1. package/README.md +21 -19
  2. package/dist/internal/page-handler.astro +8 -2
  3. package/dist/ts/.build-inputs.json +88 -0
  4. package/dist/ts/node/content.d.ts +1 -2
  5. package/dist/ts/node/content.d.ts.map +1 -1
  6. package/dist/ts/node/content.js +1 -1
  7. package/dist/ts/node/content.js.map +1 -1
  8. package/dist/ts/node/index.d.ts +1 -1
  9. package/dist/ts/node/index.d.ts.map +1 -1
  10. package/dist/ts/node/index.js +3 -3
  11. package/dist/ts/node/index.js.map +1 -1
  12. package/dist/ts/src/collections.d.ts +31 -53
  13. package/dist/ts/src/collections.d.ts.map +1 -1
  14. package/dist/ts/src/collections.js +66 -71
  15. package/dist/ts/src/collections.js.map +1 -1
  16. package/dist/ts/src/editor-descriptors.d.ts +19 -5
  17. package/dist/ts/src/editor-descriptors.d.ts.map +1 -1
  18. package/dist/ts/src/editor-descriptors.js +26 -5
  19. package/dist/ts/src/editor-descriptors.js.map +1 -1
  20. package/dist/ts/src/entries.d.ts +44 -0
  21. package/dist/ts/src/entries.d.ts.map +1 -0
  22. package/dist/ts/src/entries.js +48 -0
  23. package/dist/ts/src/entries.js.map +1 -0
  24. package/dist/ts/src/handlers/collection-content-api.d.ts.map +1 -1
  25. package/dist/ts/src/handlers/collection-content-api.js +7 -2
  26. package/dist/ts/src/handlers/collection-content-api.js.map +1 -1
  27. package/dist/ts/src/handlers/collection-names.d.ts +9 -0
  28. package/dist/ts/src/handlers/collection-names.d.ts.map +1 -0
  29. package/dist/ts/src/handlers/collection-names.js +9 -0
  30. package/dist/ts/src/handlers/collection-names.js.map +1 -0
  31. package/dist/ts/src/handlers/page-render-core.d.ts +31 -12
  32. package/dist/ts/src/handlers/page-render-core.d.ts.map +1 -1
  33. package/dist/ts/src/handlers/page-render-core.js +38 -17
  34. package/dist/ts/src/handlers/page-render-core.js.map +1 -1
  35. package/dist/ts/src/index.d.ts +2 -2
  36. package/dist/ts/src/index.d.ts.map +1 -1
  37. package/dist/ts/src/index.js +1 -3
  38. package/dist/ts/src/index.js.map +1 -1
  39. package/dist/ts/src/internal/collection-parsers.d.ts +26 -0
  40. package/dist/ts/src/internal/collection-parsers.d.ts.map +1 -0
  41. package/dist/ts/src/internal/collection-parsers.js +34 -0
  42. package/dist/ts/src/internal/collection-parsers.js.map +1 -0
  43. package/dist/ts/src/internal/entry-issues.d.ts +8 -0
  44. package/dist/ts/src/internal/entry-issues.d.ts.map +1 -0
  45. package/dist/ts/src/internal/entry-issues.js +19 -0
  46. package/dist/ts/src/internal/entry-issues.js.map +1 -0
  47. package/dist/ts/src/internal/entry-validation.d.ts +93 -0
  48. package/dist/ts/src/internal/entry-validation.d.ts.map +1 -0
  49. package/dist/ts/src/internal/entry-validation.js +228 -0
  50. package/dist/ts/src/internal/entry-validation.js.map +1 -0
  51. package/dist/ts/src/lib/virtual-module-generators.d.ts +13 -0
  52. package/dist/ts/src/lib/virtual-module-generators.d.ts.map +1 -1
  53. package/dist/ts/src/lib/virtual-module-generators.js +18 -0
  54. package/dist/ts/src/lib/virtual-module-generators.js.map +1 -1
  55. package/dist/ts/src/loader.d.ts +9 -12
  56. package/dist/ts/src/loader.d.ts.map +1 -1
  57. package/dist/ts/src/loader.js +19 -16
  58. package/dist/ts/src/loader.js.map +1 -1
  59. package/dist/ts/src/page-schemas.d.ts +1 -1
  60. package/dist/ts/src/page-schemas.d.ts.map +1 -1
  61. package/dist/ts/src/page-schemas.js +1 -1
  62. package/dist/ts/src/page-schemas.js.map +1 -1
  63. package/dist/ts/src/plugin-spa.d.ts +12 -0
  64. package/dist/ts/src/plugin-spa.d.ts.map +1 -1
  65. package/dist/ts/src/plugin-spa.js +39 -14
  66. package/dist/ts/src/plugin-spa.js.map +1 -1
  67. package/dist/ts/src/sandbox-frame-handler.d.ts +4 -1
  68. package/dist/ts/src/sandbox-frame-handler.d.ts.map +1 -1
  69. package/dist/ts/src/sandbox-frame-handler.js +22 -11
  70. package/dist/ts/src/sandbox-frame-handler.js.map +1 -1
  71. package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts +3 -62
  72. package/dist/ts/src/site-styles/content-wrapper-endpoint.d.ts.map +1 -1
  73. package/dist/ts/src/site-styles/content-wrapper-endpoint.js +12 -193
  74. package/dist/ts/src/site-styles/content-wrapper-endpoint.js.map +1 -1
  75. package/dist/virtual-modules.d.ts +14 -0
  76. package/node/content.ts +10 -1
  77. package/node/index.ts +7 -7
  78. package/package.json +12 -9
  79. package/src/collections.ts +107 -76
  80. package/src/editor-descriptors.ts +43 -5
  81. package/src/entries.ts +111 -0
  82. package/src/handlers/collection-content-api.ts +7 -2
  83. package/src/handlers/collection-names.ts +8 -0
  84. package/src/handlers/page-handler.astro +8 -2
  85. package/src/handlers/page-render-core.ts +65 -17
  86. package/src/index.ts +6 -7
  87. package/src/internal/collection-parsers.ts +51 -0
  88. package/src/internal/entry-issues.ts +23 -0
  89. package/src/internal/entry-validation.ts +305 -0
  90. package/src/lib/virtual-module-generators.ts +20 -0
  91. package/src/loader.ts +33 -17
  92. package/src/page-schemas.ts +4 -0
  93. package/src/plugin-spa.ts +58 -13
  94. package/src/sandbox-frame-handler.ts +16 -5
  95. package/src/site-styles/content-wrapper-endpoint.ts +4 -285
  96. package/src/virtual-modules.d.ts +14 -0
  97. package/dist/ts/src/internal/page-collection-schema.d.ts +0 -44
  98. package/dist/ts/src/internal/page-collection-schema.d.ts.map +0 -1
  99. package/dist/ts/src/internal/page-collection-schema.js +0 -152
  100. package/dist/ts/src/internal/page-collection-schema.js.map +0 -1
  101. package/src/internal/page-collection-schema.ts +0 -210
@@ -0,0 +1,228 @@
1
+ import { resolveHostJsonSchema, rootObjectOf, toPageSchemaDescriptor, } from '@conloca/cms-spa/page-schema-define';
2
+ import { PAGE_META_KEYS, parseLooseDataMeta, parseLooseFragmentMeta, parseLoosePageMeta, } from '@conloca/content-api/schemas';
3
+ /**
4
+ * Validation of Conloca collection entries, at build time and in a draft preview.
5
+ *
6
+ * Astro's `defineCollection({ schema })` only takes a Zod schema, and a schema
7
+ * is optional: without one, `parseData` hands the entry through unchanged
8
+ * (astro/dist/content/utils.js `getEntryData`). So the factories declare their
9
+ * collections schema-less and the loader validates every entry with the parsers
10
+ * below BEFORE `store.set` — the generated Typia validators from
11
+ * `@conloca/content-api/schemas` for Conloca's own fields, and the host's
12
+ * generated validators for its `pageSchemas` / `dataSchemas`. A draft preview
13
+ * parses its records with the same parsers, in a server runtime, so this
14
+ * module stays free of the loader's filesystem reader.
15
+ */
16
+ /**
17
+ * Entry fields the content loader owns, written into every entry's data in
18
+ * its load().
19
+ *
20
+ * None of them belong to `PageMeta`, so page validation keeps them only as
21
+ * undeclared top-level fields. A host page-meta field of the same name would
22
+ * replace the loader's value — a host `puckData` shape would empty the page
23
+ * tree of every page in the built site. `hostFieldsFromPageSchemas` refuses
24
+ * those names with an error.
25
+ *
26
+ * Adding a field to the record the loader builds also means reserving it here.
27
+ */
28
+ export const LOADER_RESERVED_FIELDS = ['created', 'modified', 'name', 'data', 'mdx', 'puckData'];
29
+ const CORE_FIELD_NAMES = new Set(PAGE_META_KEYS);
30
+ // `Object.hasOwn` is ES2022, past this package's `lib`.
31
+ const hasOwn = (record, key) => Object.getOwnPropertyDescriptor(record, key) !== undefined;
32
+ const RESERVED_FIELD_NAMES = new Set(LOADER_RESERVED_FIELDS);
33
+ /**
34
+ * The generated JSON Schema of one field, `$ref`s inlined, as a comparable
35
+ * string. The `title`/`description` annotations are dropped — help text may
36
+ * differ between descriptors — but never a field that happens to be named
37
+ * `title` or `description` inside a `properties` map.
38
+ */
39
+ function canonicalFieldSchema(metadata, node, depth = 0, isNameMap = false) {
40
+ if (depth > 32 || typeof node !== 'object' || node === null)
41
+ return node;
42
+ if (Array.isArray(node))
43
+ return node.map((item) => canonicalFieldSchema(metadata, item, depth + 1));
44
+ const resolved = !isNameMap && '$ref' in node && typeof node.$ref === 'string'
45
+ ? resolveHostJsonSchema(metadata, { $ref: node.$ref })
46
+ : node;
47
+ if (resolved === null)
48
+ return null;
49
+ return Object.fromEntries(Object.entries(resolved)
50
+ .filter(([key]) => isNameMap || (key !== 'description' && key !== 'title'))
51
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
52
+ .map(([key, value]) => [
53
+ key,
54
+ canonicalFieldSchema(metadata, value, depth + 1,
55
+ // These keywords map field names to schemas; their keys are names, not annotations.
56
+ !isNameMap && (key === 'properties' || key === 'patternProperties')),
57
+ ]));
58
+ }
59
+ function assertHostFieldIsSafe(name) {
60
+ if (CORE_FIELD_NAMES.has(name)) {
61
+ throw new Error(`[conloca] pageSchemas cannot redeclare Conloca field "${name}". ` +
62
+ 'Title, pathname, locale, and the other core fields come from the CMS — put constraints on them in the editor schema, not here.');
63
+ }
64
+ if (RESERVED_FIELD_NAMES.has(name)) {
65
+ throw new Error(`[conloca] pageSchemas cannot declare "${name}". ` +
66
+ 'That field is owned by the content loader; a host schema of the same name would replace page content on every page.');
67
+ }
68
+ }
69
+ /**
70
+ * Fold every page-schema descriptor into the host fields page validation checks.
71
+ *
72
+ * Every page is checked against every descriptor's fields — Astro builds the
73
+ * whole `pages` pile while the editor scopes a descriptor to a prefix — so a
74
+ * field name may only be declared twice with the same generated schema:
75
+ * otherwise one prefix's pages would be validated against the other's type,
76
+ * failing with an error that names neither descriptor.
77
+ */
78
+ export function hostFieldsFromPageSchemas(pageSchemas) {
79
+ const owners = new Map();
80
+ return Object.entries(pageSchemas).map(([key, entry]) => {
81
+ const descriptor = toPageSchemaDescriptor(entry);
82
+ // 'minimal'/'none' descriptors declare title for the form; those names stay Conloca's.
83
+ const mode = descriptor.coreFields?.mode;
84
+ const ownsCore = mode === 'minimal' || mode === 'none';
85
+ const { metadata } = descriptor.schema;
86
+ const root = rootObjectOf(metadata);
87
+ if (root === null) {
88
+ // Without an object root there are no fields to check, and every page
89
+ // would pass unvalidated instead of failing the build.
90
+ throw new Error(`[conloca] pageSchemas "${key}" metadata is not generated for an object type. ` +
91
+ 'Declare it with defineHostSchema<T>({ validate, metadata: typia.json.schema<T>() }) for an object type T.');
92
+ }
93
+ const fields = [];
94
+ const coreOwned = [];
95
+ for (const [name, node] of Object.entries(root.properties ?? {})) {
96
+ if (ownsCore && CORE_FIELD_NAMES.has(name)) {
97
+ coreOwned.push(name);
98
+ continue;
99
+ }
100
+ assertHostFieldIsSafe(name);
101
+ const canonical = JSON.stringify(canonicalFieldSchema(metadata, node));
102
+ const owner = owners.get(name);
103
+ if (owner !== undefined && owner.canonical !== canonical) {
104
+ throw new Error(`[conloca] pageSchemas "${owner.key}" and "${key}" both declare field "${name}" with different schemas. ` +
105
+ 'Every page is validated against every declared field — declare the field with one type in both ' +
106
+ 'schemas, or rename one of the fields.');
107
+ }
108
+ if (owner === undefined)
109
+ owners.set(name, { key, canonical });
110
+ fields.push(name);
111
+ }
112
+ return { key, schema: descriptor.schema, fields, coreOwned };
113
+ });
114
+ }
115
+ /** The top-level key a Typia error path (`$input.name`, `$input["a-b"]`, …) starts with. */
116
+ export function topLevelKeyOf(path) {
117
+ const rest = path.startsWith('$input') ? path.slice('$input'.length) : undefined;
118
+ if (rest === undefined)
119
+ return undefined;
120
+ const dotted = /^\.([A-Za-z_$][\w$]*)/.exec(rest);
121
+ if (dotted)
122
+ return dotted[1];
123
+ const bracketed = /^\[("(?:[^"\\]|\\.)*")\]/.exec(rest);
124
+ return bracketed?.[1] === undefined ? undefined : JSON.parse(bracketed[1]);
125
+ }
126
+ /** Re-roots a generated validator's error under `prefix` (`$input` → `$input.data`). */
127
+ function toIssue(error, prefix = '') {
128
+ return {
129
+ path: prefix ? `$input${prefix}${error.path.slice('$input'.length)}` : error.path,
130
+ expected: error.expected,
131
+ value: error.value,
132
+ };
133
+ }
134
+ /**
135
+ * Validate one descriptor's fields on a page. The fields are copied out first, so
136
+ * a pruning validator never mutates the loader's data, and a field the page
137
+ * does not carry is not an error: host fields are optional collection-wide.
138
+ * Requiredness is shallow, as `.partial()` was — a nested required field still
139
+ * has to be present when its parent is.
140
+ *
141
+ * A generated validator prunes only on success, so the core fields a
142
+ * 'minimal'/'none' descriptor redeclares are passed in with the page's own
143
+ * values: otherwise its required `title` would fail every page and leave the
144
+ * host's nested fields unpruned. Errors on them are Conloca's to report, not the
145
+ * host's, and they never reach the returned values.
146
+ *
147
+ * When the only failures are on ignored fields — those core fields, or a host
148
+ * field the page does not carry that `T` declares required — the validator's
149
+ * prune does not run, so nested undeclared keys are kept, as with a non-pruning
150
+ * `createValidate`, where `.partial()` would still have stripped them. A host
151
+ * schema carries no marker telling a pruning validator from a plain one, so
152
+ * there is nothing to re-run; a host that wants every page pruned declares its
153
+ * page fields optional (`?`), which they are collection-wide anyway.
154
+ */
155
+ function validateHostFields(set, entry) {
156
+ const picked = {};
157
+ for (const name of set.fields) {
158
+ if (hasOwn(entry, name))
159
+ picked[name] = structuredClone(entry[name]);
160
+ }
161
+ const input = { ...picked };
162
+ for (const name of set.coreOwned) {
163
+ if (hasOwn(entry, name))
164
+ input[name] = structuredClone(entry[name]);
165
+ }
166
+ // Pruning rewrites `input`'s nested values in place, which `picked` shares.
167
+ const result = set.schema.validate(input);
168
+ if (result.success)
169
+ return { issues: [], values: picked };
170
+ const issues = result.errors
171
+ .filter((error) => {
172
+ const key = topLevelKeyOf(error.path);
173
+ return key === undefined || hasOwn(picked, key);
174
+ })
175
+ .map((error) => toIssue(error));
176
+ return { issues, values: picked };
177
+ }
178
+ /**
179
+ * The parser a page collection validates entries with: Conloca's page fields
180
+ * (dates coerced, unknown keys kept) plus every host field from `pageSchemas`.
181
+ */
182
+ export function createPageEntryParser(pageSchemas) {
183
+ const hostFieldSets = pageSchemas ? hostFieldsFromPageSchemas(pageSchemas) : [];
184
+ return (data) => {
185
+ const core = parseLoosePageMeta(data);
186
+ const issues = core.success ? [] : [...core.issues];
187
+ let entry = core.success ? core.data : data;
188
+ for (const set of hostFieldSets) {
189
+ const host = validateHostFields(set, entry);
190
+ issues.push(...host.issues);
191
+ if (host.issues.length === 0 && Object.keys(host.values).length > 0)
192
+ entry = { ...entry, ...host.values };
193
+ }
194
+ if (!core.success || issues.length > 0)
195
+ return { success: false, issues };
196
+ // The one declared seam: the runtime value is core fields validated by
197
+ // content-api's generated validator plus host fields validated by the host's,
198
+ // but the host's declared field TYPES reach TypeScript only through the
199
+ // `HostPageMeta` augmentation a site writes next to its pageSchemas. A host
200
+ // declaring `HostPageMeta` promises it matches them, as listings always have.
201
+ return { success: true, data: entry };
202
+ };
203
+ }
204
+ /** The parser a fragment collection validates entries with. */
205
+ export const parseFragmentEntry = parseLooseFragmentMeta;
206
+ /**
207
+ * The parser a `conlocaData` collection validates entries with: Conloca's data
208
+ * fields, then the collection's payload under `data` against its host schema.
209
+ * `data` stays optional — an entry saved before any payload exists is not an
210
+ * error. The payload is validated as given: requiredness preserved.
211
+ */
212
+ export function createDataEntryParser(payload) {
213
+ return (data) => {
214
+ const base = parseLooseDataMeta(data);
215
+ if (!base.success)
216
+ return base;
217
+ if (base.data.data === undefined) {
218
+ const { data: _absent, ...rest } = base.data;
219
+ return { success: true, data: rest };
220
+ }
221
+ const result = payload.validate(structuredClone(base.data.data));
222
+ if (!result.success) {
223
+ return { success: false, issues: result.errors.map((error) => toIssue(error, '.data')) };
224
+ }
225
+ return { success: true, data: { ...base.data, data: result.data } };
226
+ };
227
+ }
228
+ //# sourceMappingURL=entry-validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry-validation.js","sourceRoot":"","sources":["../../../../src/internal/entry-validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,qBAAqB,EACrB,YAAY,EACZ,sBAAsB,GACvB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAIL,cAAc,EAEd,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,GAGnB,MAAM,8BAA8B,CAAC;AAEtC;;;;;;;;;;;;GAYG;AAEH;;;;;;;;;;;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AAC;AAE5F;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAmB,OAAsB;IAC5E,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,MAAM,IAAI,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC;QAC/B,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YACjC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC;YAC7C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACvC,CAAC;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACjE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;QAC3F,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;IACtE,CAAC,CAAC;AACJ,CAAC"}
@@ -30,4 +30,17 @@ export declare function generateLayoutModule(routing: RoutingConfig | undefined)
30
30
  * @returns JavaScript module code as a string
31
31
  */
32
32
  export declare function generatePuckConfigModule(puckConfigPath: string): string;
33
+ /**
34
+ * Generate the virtual:conloca-content-schemas module: the site's
35
+ * `contentSchemasPath` module — the `pageSchemas` / `dataSchemas` its content
36
+ * config hands the collection factories — for a draft preview to build the
37
+ * same collection schemas from. Not the content config itself: that imports
38
+ * build-time loaders, which cannot be evaluated in a server runtime.
39
+ *
40
+ * Imported lazily, on the first call, so only a preview render evaluates it.
41
+ *
42
+ * @param contentSchemasPath - Absolute path of the module, or undefined when the site names none
43
+ * @returns JavaScript module code as a string
44
+ */
45
+ export declare function generateContentSchemasModule(contentSchemasPath: string | undefined): string;
33
46
  //# sourceMappingURL=virtual-module-generators.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"virtual-module-generators.d.ts","sourceRoot":"","sources":["../../../../src/lib/virtual-module-generators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAExE;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM,CAEjF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,GAAG,SAAS,GAAG,MAAM,CAe/E;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAMvE"}
1
+ {"version":3,"file":"virtual-module-generators.d.ts","sourceRoot":"","sources":["../../../../src/lib/virtual-module-generators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAExE;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM,CAEjF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,GAAG,SAAS,GAAG,MAAM,CAe/E;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAMvE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,4BAA4B,CAAC,kBAAkB,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAM3F"}
@@ -48,4 +48,22 @@ export function generatePuckConfigModule(puckConfigPath) {
48
48
  const absolutePath = puckConfigPath.startsWith('.') ? `/${puckConfigPath.slice(2)}` : puckConfigPath;
49
49
  return `export { default } from '${absolutePath}';`;
50
50
  }
51
+ /**
52
+ * Generate the virtual:conloca-content-schemas module: the site's
53
+ * `contentSchemasPath` module — the `pageSchemas` / `dataSchemas` its content
54
+ * config hands the collection factories — for a draft preview to build the
55
+ * same collection schemas from. Not the content config itself: that imports
56
+ * build-time loaders, which cannot be evaluated in a server runtime.
57
+ *
58
+ * Imported lazily, on the first call, so only a preview render evaluates it.
59
+ *
60
+ * @param contentSchemasPath - Absolute path of the module, or undefined when the site names none
61
+ * @returns JavaScript module code as a string
62
+ */
63
+ export function generateContentSchemasModule(contentSchemasPath) {
64
+ if (contentSchemasPath === undefined) {
65
+ return 'export function loadContentSchemas() { return Promise.resolve({}); }';
66
+ }
67
+ return `export function loadContentSchemas() { return import(${JSON.stringify(contentSchemasPath)}); }`;
68
+ }
51
69
  //# sourceMappingURL=virtual-module-generators.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"virtual-module-generators.js","sourceRoot":"","sources":["../../../../src/lib/virtual-module-generators.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,UAAU,2BAA2B,CAAC,MAA6B;IACvE,OAAO,kBAAkB,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC;AAC9D,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAkC;IACrE,sEAAsE;IACtE,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,EAAE,CAAC;IACrC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,MAAM,UAAU,GAAG,UAAU,EAAE,MAAM,CAAC;IAEtC,IAAI,UAAU,EAAE,CAAC;QACf,wDAAwD;QACxD,wBAAwB;QACxB,MAAM,YAAY,GAAG,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;QAEzF,OAAO,4BAA4B,YAAY,IAAI,CAAC;IACtD,CAAC;IAED,OAAO,2BAA2B,CAAC;AACrC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CAAC,cAAsB;IAC7D,wDAAwD;IACxD,wBAAwB;IACxB,MAAM,YAAY,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC;IAErG,OAAO,4BAA4B,YAAY,IAAI,CAAC;AACtD,CAAC"}
1
+ {"version":3,"file":"virtual-module-generators.js","sourceRoot":"","sources":["../../../../src/lib/virtual-module-generators.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,UAAU,2BAA2B,CAAC,MAA6B;IACvE,OAAO,kBAAkB,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC;AAC9D,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAkC;IACrE,sEAAsE;IACtE,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,EAAE,CAAC;IACrC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,MAAM,UAAU,GAAG,UAAU,EAAE,MAAM,CAAC;IAEtC,IAAI,UAAU,EAAE,CAAC;QACf,wDAAwD;QACxD,wBAAwB;QACxB,MAAM,YAAY,GAAG,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;QAEzF,OAAO,4BAA4B,YAAY,IAAI,CAAC;IACtD,CAAC;IAED,OAAO,2BAA2B,CAAC;AACrC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CAAC,cAAsB;IAC7D,wDAAwD;IACxD,wBAAwB;IACxB,MAAM,YAAY,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC;IAErG,OAAO,4BAA4B,YAAY,IAAI,CAAC;AACtD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,4BAA4B,CAAC,kBAAsC;IACjF,IAAI,kBAAkB,KAAK,SAAS,EAAE,CAAC;QACrC,OAAO,sEAAsE,CAAC;IAChF,CAAC;IAED,OAAO,wDAAwD,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,MAAM,CAAC;AAC1G,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import type { Loader } from 'astro/loaders';
2
+ import type { EntryParser } from './internal/entry-validation.js';
2
3
  export interface ConlocaLoaderOptions {
3
4
  /** Must equal the content.config key this loader is mounted under — load() asserts it. */
4
5
  collection?: string;
@@ -6,19 +7,15 @@ export interface ConlocaLoaderOptions {
6
7
  site?: string;
7
8
  /** Collection kind. If not provided, defaults to 'fragment' for 'fragments' collection, 'page' otherwise. */
8
9
  kind?: 'page' | 'fragment' | 'data';
10
+ /**
11
+ * Validates every entry before it is stored; a failing entry fails the load
12
+ * with its file and every issue. The collection factories pass the generated
13
+ * Typia parsers for the collection's kind and host schemas. Without it, the
14
+ * entry is stored as loaded (and whatever `schema` the collection was
15
+ * declared with still runs through `parseData`).
16
+ */
17
+ parseEntry?: EntryParser<Record<string, unknown>>;
9
18
  }
10
- /**
11
- * Entry fields this loader owns, written into every entry's data in load().
12
- *
13
- * None of them belong to `pageMetaSchema`, so under a page collection's schema
14
- * they survive only through the loose index signature. A host page-meta field
15
- * of the same name would replace the loader's value — a host `puckData` shape
16
- * would empty the page tree of every page in the built site.
17
- * `buildPageCollectionSchema` refuses those names with an error.
18
- *
19
- * Adding a field to the record built in load() also means reserving it here.
20
- */
21
- export declare const LOADER_RESERVED_FIELDS: readonly ['created', 'modified', 'name', 'data', 'mdx', 'puckData'];
22
19
  /**
23
20
  * Custom Astro content loader for Conloca CMS.
24
21
  * Loads content from the Conloca content directory into Astro collections.
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AAE3D,MAAM,WAAW,oBAAoB;IACnC,0FAA0F;IAC1F,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6GAA6G;IAC7G,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC;CACrC;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,YAAI,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAU,CAAC;AAE1G;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAmHnE"}
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AAE3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAElE,MAAM,WAAW,oBAAoB;IACnC,0FAA0F;IAC1F,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6GAA6G;IAC7G,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC;IACpC;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACnD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CA2HnE"}
@@ -1,16 +1,5 @@
1
1
  import { createContentAPI } from '@conloca/content-api/reader';
2
- /**
3
- * Entry fields this loader owns, written into every entry's data in load().
4
- *
5
- * None of them belong to `pageMetaSchema`, so under a page collection's schema
6
- * they survive only through the loose index signature. A host page-meta field
7
- * of the same name would replace the loader's value — a host `puckData` shape
8
- * would empty the page tree of every page in the built site.
9
- * `buildPageCollectionSchema` refuses those names with an error.
10
- *
11
- * Adding a field to the record built in load() also means reserving it here.
12
- */
13
- export const LOADER_RESERVED_FIELDS = ['created', 'modified', 'name', 'data', 'mdx', 'puckData'];
2
+ import { describeEntryIssues } from './internal/entry-issues.js';
14
3
  /**
15
4
  * Custom Astro content loader for Conloca CMS.
16
5
  * Loads content from the Conloca content directory into Astro collections.
@@ -74,9 +63,9 @@ export function conlocaLoader(options) {
74
63
  puckData = fullContent.localized.content.puckData;
75
64
  }
76
65
  }
77
- // Any key added here that is not part of pageMetaSchema must also be
78
- // listed in LOADER_RESERVED_FIELDS, or a host page-meta field of the
79
- // same name will replace it on every page.
66
+ // Any key added here that is not part of PageMeta must also be
67
+ // listed in LOADER_RESERVED_FIELDS (internal/entry-validation.ts),
68
+ // or a host page-meta field of the same name will replace it on every page.
80
69
  const data = {
81
70
  id: manifest.id,
82
71
  locale,
@@ -97,11 +86,18 @@ export function conlocaLoader(options) {
97
86
  if (puckData !== undefined) {
98
87
  data.puckData = puckData;
99
88
  }
89
+ const validatedData = options.parseEntry
90
+ ? validEntryData(options.parseEntry, data, {
91
+ collection: context.collection,
92
+ id: entryId,
93
+ filePath: localeVersion.sourcePath,
94
+ })
95
+ : data;
100
96
  // filePath feeds Astro's error location: without it a validation
101
97
  // failure names only the opaque content id, not a file to open.
102
98
  const parsedData = await parseData({
103
99
  id: entryId,
104
- data,
100
+ data: validatedData,
105
101
  ...(localeVersion.sourcePath ? { filePath: localeVersion.sourcePath } : {}),
106
102
  });
107
103
  store.set({
@@ -115,4 +111,11 @@ export function conlocaLoader(options) {
115
111
  },
116
112
  };
117
113
  }
114
+ /** The parsed entry data, or the build error naming the entry, its file and every issue. */
115
+ function validEntryData(parseEntry, data, where) {
116
+ const result = parseEntry(data);
117
+ if (!result.success)
118
+ throw new Error(describeEntryIssues(result.issues, where));
119
+ return result.data;
120
+ }
118
121
  //# sourceMappingURL=loader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAY/D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAU,CAAC;AAE1G;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,OAA6B;IACzD,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,KAAK,CAAC,IAAI,CAAC,OAAsB;YAC/B,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;YAE7D,mEAAmE;YACnE,oEAAoE;YACpE,6CAA6C;YAC7C,IAAI,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,UAAU,KAAK,OAAO,CAAC,UAAU,EAAE,CAAC;gBACpE,MAAM,IAAI,KAAK,CACb,gEAAgE,OAAO,CAAC,UAAU,IAAI;oBACpF,cAAc,OAAO,CAAC,UAAU,mEAAmE,CACtG,CAAC;YACJ,CAAC;YAED,8BAA8B;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AAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,aAAa,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;qBAC5E,CAAC,CAAC;oBAEH,KAAK,CAAC,GAAG,CAAC;wBACR,EAAE,EAAE,OAAO;wBACX,IAAI,EAAE,UAAU;wBAChB,MAAM,EAAE,cAAc,CAAC,aAAa,CAAC,IAAI,CAAC;qBAC3C,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YAED,MAAM,CAAC,IAAI,CAAC,UAAU,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,iBAAiB,OAAO,CAAC,UAAU,IAAI,GAAG,IAAI,UAAU,EAAE,CAAC,CAAC;QACvG,CAAC;KACF,CAAC;AACJ,CAAC;AAED,4FAA4F;AAC5F,SAAS,cAAc,CACrB,UAAgD,EAChD,IAA6B,EAC7B,KAA4D;IAE5D,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IAChF,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC"}
@@ -2,5 +2,5 @@
2
2
  * Light page-schema helpers for Astro content configs and host schema modules.
3
3
  * Does not import the CMS SPA / MDX editor.
4
4
  */
5
- export { type CoreFieldsMode, definePageSchema, type FieldHint, type FieldHintCommon, type FieldHints, type FieldHintVariant, type PageSchemaDescriptor, type PageSchemaEntry, type PageSchemaGroup, type PageSchemas, type ResolveSchemaContext, resolvePageSchemaEntry, toPageSchemaDescriptor, } from '@conloca/cms-spa/page-schema-define';
5
+ export { type CoreFieldsMode, type DataSchemas, defineHostSchema, definePageSchema, type FieldHint, type FieldHintCommon, type FieldHints, type FieldHintVariant, type HostSchema, type HostSchemaType, type PageSchemaDescriptor, type PageSchemaEntry, type PageSchemaGroup, type PageSchemas, type ResolveSchemaContext, resolvePageSchemaEntry, toPageSchemaDescriptor, } from '@conloca/cms-spa/page-schema-define';
6
6
  //# sourceMappingURL=page-schemas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"page-schemas.d.ts","sourceRoot":"","sources":["../../../src/page-schemas.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,KAAK,cAAc,EACnB,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,oBAAoB,EACzB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,qCAAqC,CAAC"}
1
+ {"version":3,"file":"page-schemas.d.ts","sourceRoot":"","sources":["../../../src/page-schemas.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,oBAAoB,EACzB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,qCAAqC,CAAC"}
@@ -2,5 +2,5 @@
2
2
  * Light page-schema helpers for Astro content configs and host schema modules.
3
3
  * Does not import the CMS SPA / MDX editor.
4
4
  */
5
- export { definePageSchema, resolvePageSchemaEntry, toPageSchemaDescriptor, } from '@conloca/cms-spa/page-schema-define';
5
+ export { defineHostSchema, definePageSchema, resolvePageSchemaEntry, toPageSchemaDescriptor, } from '@conloca/cms-spa/page-schema-define';
6
6
  //# sourceMappingURL=page-schemas.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"page-schemas.js","sourceRoot":"","sources":["../../../src/page-schemas.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAEL,gBAAgB,EAUhB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,qCAAqC,CAAC"}
1
+ {"version":3,"file":"page-schemas.js","sourceRoot":"","sources":["../../../src/page-schemas.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAGL,gBAAgB,EAChB,gBAAgB,EAYhB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,qCAAqC,CAAC"}
@@ -13,6 +13,18 @@ export interface ConlocaCMSOptions extends Omit<UIConfig, 'basename'> {
13
13
  route?: string;
14
14
  puckConfigPath: string;
15
15
  schemasPath?: string;
16
+ /**
17
+ * Module exporting the `pageSchemas` and/or `dataSchemas` the content config
18
+ * hands conlocaPages() and conlocaData(). A draft preview builds the same
19
+ * entry parsers from them and parses each draft as the build parses an
20
+ * entry, so it gets the stored values and fails where the build would. It
21
+ * loads in the preview server, so it may import schema code only (Typia
22
+ * host schemas, definePageSchema) — the module the content config imports
23
+ * them from, not the editor's `schemasPath` barrel.
24
+ *
25
+ * @example './src/page-schemas.ts'
26
+ */
27
+ contentSchemasPath?: string;
16
28
  /**
17
29
  * Default layout for content pages.
18
30
  * When provided without routing config, enables routing with catch-all pattern.
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-spa.d.ts","sourceRoot":"","sources":["../../../src/plugin-spa.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAGjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAW9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AA4C3D,OAAO,KAAK,EAA6C,kBAAkB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAoChH,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC;IACnE;;;;OAIG;IACH,WAAW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AAoLD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,gBAAgB,CAmiCvE"}
@@ -43,7 +43,7 @@ const CMS_HANDLER_PATH = join(__dirname, 'cms-handler.js');
43
43
  const SANDBOX_FRAME_HANDLER_PATH = join(__dirname, 'sandbox-frame-handler.js');
44
44
  const ACORN_DEFAULT_SHIM_PATH = join(__dirname, '..', '..', 'internal', 'acorn-default.mjs');
45
45
  const TIPTAP_HTML_SHIM_PATH = join(__dirname, 'tiptap-html-static.js');
46
- import { generateLayoutModule, generatePuckConfigModule, generateRoutingConfigModule, } from './lib/virtual-module-generators.js';
46
+ import { generateContentSchemasModule, generateLayoutModule, generatePuckConfigModule, generateRoutingConfigModule, } from './lib/virtual-module-generators.js';
47
47
  // Virtual module for passing config from plugin to route handler
48
48
  const VIRTUAL_CONFIG_MODULE = 'virtual:conloca-config';
49
49
  const RESOLVED_VIRTUAL_CONFIG = `\0${VIRTUAL_CONFIG_MODULE}`;
@@ -51,10 +51,12 @@ const RESOLVED_VIRTUAL_CONFIG = `\0${VIRTUAL_CONFIG_MODULE}`;
51
51
  const VIRTUAL_ROUTING_CONFIG = 'virtual:conloca-routing-config';
52
52
  const VIRTUAL_LAYOUT = 'virtual:conloca-layout';
53
53
  const VIRTUAL_PUCK_CONFIG = 'virtual:conloca-puck-config';
54
+ const VIRTUAL_CONTENT_SCHEMAS = 'virtual:conloca-content-schemas';
54
55
  // Resolved IDs (with \0 prefix to prevent file resolution)
55
56
  const RESOLVED_ROUTING_CONFIG = `\0${VIRTUAL_ROUTING_CONFIG}`;
56
57
  const RESOLVED_LAYOUT = `\0${VIRTUAL_LAYOUT}`;
57
58
  const RESOLVED_PUCK_CONFIG = `\0${VIRTUAL_PUCK_CONFIG}`;
59
+ const RESOLVED_CONTENT_SCHEMAS = `\0${VIRTUAL_CONTENT_SCHEMAS}`;
58
60
  // Virtual modules for hydration system
59
61
  const VIRTUAL_HYDRATION_REGISTRY = 'virtual:conloca-hydration-registry';
60
62
  const VIRTUAL_HYDRATION_ENTRY = 'virtual:conloca-hydration-entry';
@@ -417,12 +419,35 @@ export function conlocaCMS(options) {
417
419
  // descriptors dev loads from `schemasPath`, `/api/registry` and
418
420
  // `virtual:conloca-config` instead of taking these options again.
419
421
  // schemasPath is absolutized because a reader may use it as an import
420
- // specifier.
422
+ // specifier. Readers inherit the puck config, the site and editor
423
+ // stylesheets, the editor CSS and the fragment preview route from here
424
+ // too, so the site writes each of them once. The stylesheets resolve
425
+ // against the Astro root, where the dev editor's Vite imports find
426
+ // them, so a build started from another folder (`astro build --root
427
+ // site`) still hands on the same files.
428
+ const configuredStyles = options.siteStyles;
429
+ const siteStyles = configuredStyles
430
+ ? (Array.isArray(configuredStyles) ? configuredStyles : [configuredStyles]).map((path) => resolve(fileURLToPath(config.root), path))
431
+ : undefined;
432
+ const configuredEditorStyles = options.editorStyles;
433
+ const editorStyles = configuredEditorStyles
434
+ ? (Array.isArray(configuredEditorStyles) ? configuredEditorStyles : [configuredEditorStyles]).map((path) => resolve(fileURLToPath(config.root), path))
435
+ : undefined;
421
436
  const editorDescriptors = {
422
437
  ...(options.schemasPath ? { schemasPath: resolve(options.schemasPath) } : {}),
438
+ puckConfigPath: resolve(options.puckConfigPath),
439
+ ...(siteStyles === undefined ? {} : { siteStyles }),
440
+ ...(editorStyles === undefined ? {} : { editorStyles }),
441
+ ...(options.editorCSS ? { editorCSS: options.editorCSS } : {}),
423
442
  registry: registryScan,
424
443
  ...(options.templates ? { templates: options.templates } : {}),
425
444
  ...(spaConfig.dataBindings ? { dataBindings: spaConfig.dataBindings } : {}),
445
+ // Every folder the content API writes to, resolved as it resolves them (the build's working directory).
446
+ contentPaths: [
447
+ resolve(options.contentRoot),
448
+ ...(resolvedMdxPages ? [resolve(resolvedMdxPages)] : []),
449
+ ...(options.assetsPath ? [resolve(options.assetsPath)] : []),
450
+ ],
426
451
  };
427
452
  process.env[EDITOR_DESCRIPTORS_ENV_VAR] = JSON.stringify(editorDescriptors);
428
453
  // Auto-inject fs.allow for external contentRoot (dev mode only)
@@ -570,6 +595,9 @@ export function conlocaCMS(options) {
570
595
  if (id === VIRTUAL_PUCK_CONFIG) {
571
596
  return RESOLVED_PUCK_CONFIG;
572
597
  }
598
+ if (id === VIRTUAL_CONTENT_SCHEMAS) {
599
+ return RESOLVED_CONTENT_SCHEMAS;
600
+ }
573
601
  // Hydration virtual modules
574
602
  if (id === VIRTUAL_HYDRATION_REGISTRY) {
575
603
  return RESOLVED_HYDRATION_REGISTRY;
@@ -594,6 +622,9 @@ export function conlocaCMS(options) {
594
622
  if (id === RESOLVED_PUCK_CONFIG) {
595
623
  return generatePuckConfigModule(options.puckConfigPath);
596
624
  }
625
+ if (id === RESOLVED_CONTENT_SCHEMAS) {
626
+ return generateContentSchemasModule(options.contentSchemasPath ? resolve(options.contentSchemasPath) : undefined);
627
+ }
597
628
  // Hydration virtual modules
598
629
  if (id === RESOLVED_HYDRATION_REGISTRY) {
599
630
  // Always scan - paths are auto-derived from puckConfigPath
@@ -641,17 +672,12 @@ initHydration(componentRegistry)
641
672
  });
642
673
  }
643
674
  }
644
- // The sandbox frame document ContentSandbox loads for MDX previews.
645
- // Root-absolute by contract (SANDBOX_FRAME_PATH in @conloca/mdx) and
646
- // needed wherever the editor runs — anything that serves the editor
647
- // serves the same path. Injected outside the dev-only block: a
648
- // production editor build needs the frame too.
649
- //
650
- // On-demand by necessity — the response carries the sandbox CSP, which
651
- // a prerendered file cannot — so injecting it into a fully static site
652
- // fails that build with NoAdapterInstalled. Such a site has no runtime
653
- // editor to serve it to; dev serves it whatever the output mode.
654
- if (command === 'dev' || config.output !== 'static') {
675
+ // The sandbox frame document ContentSandbox loads for MDX previews in
676
+ // the dev editor. Root-absolute by contract (SANDBOX_FRAME_PATH in
677
+ // @conloca/mdx). On-demand by necessity — the response carries the
678
+ // sandbox CSP, which a prerendered file cannot. A built site never
679
+ // gets it: its editor page ships the frame as a static file.
680
+ if (command === 'dev') {
655
681
  injectRoute({
656
682
  pattern: '/api/v1/mdx/sandbox-frame',
657
683
  entrypoint: SANDBOX_FRAME_HANDLER_PATH,
@@ -711,7 +737,6 @@ initHydration(componentRegistry)
711
737
  'clsx',
712
738
  'tailwind-merge',
713
739
  // Content processing
714
- 'zod',
715
740
  'yaml',
716
741
  'nanoid',
717
742
  'sort-keys',