@phtngyn/cms 0.2.0-beta.4 → 0.2.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -13
- package/package.json +7 -7
- package/src/ApplicationTypes.d.ts +3 -3
- package/src/Authoring.d.ts +11 -3
- package/src/{Configuration-BU-UyGoH.js → Configuration-JQ1qyaU0.js} +347 -189
- package/src/Configuration-JQ1qyaU0.js.map +1 -0
- package/src/Configuration.d.ts +1 -1
- package/src/Content.d.ts +7 -6
- package/src/Content.js +106 -47
- package/src/Content.js.map +1 -1
- package/src/ContentTransfer-BxwswWn3.js +86 -0
- package/src/ContentTransfer-BxwswWn3.js.map +1 -0
- package/src/{ContentTransfer-CRQet3QJ.d.ts → ContentTransfer-Z9FHyLez.d.ts} +33 -9
- package/src/{DocumentEngine-ClhFXW9M.js → DocumentEngine-j6Vi7nQo.js} +279 -178
- package/src/DocumentEngine-j6Vi7nQo.js.map +1 -0
- package/src/DocumentModel.d.ts +9 -2
- package/src/DocumentModel.js +17 -4
- package/src/DocumentModel.js.map +1 -1
- package/src/{Forms-DoB56hfe.js → Forms-CX-hwmJF.js} +18 -11
- package/src/Forms-CX-hwmJF.js.map +1 -0
- package/src/{Forms-BbkE7QfC.js → Forms-CfNPTiCr.js} +2 -2
- package/src/{Forms-BbkE7QfC.js.map → Forms-CfNPTiCr.js.map} +1 -1
- package/src/Media-j1bTritO.js +112 -0
- package/src/Media-j1bTritO.js.map +1 -0
- package/src/Module.js +0 -4
- package/src/Module.js.map +1 -1
- package/src/References-CCPDAPve.js +45 -0
- package/src/References-CCPDAPve.js.map +1 -0
- package/src/{S3MediaObjects-CR3p1WTg.js → S3MediaObjects-BRuPQbxl.js} +454 -516
- package/src/S3MediaObjects-BRuPQbxl.js.map +1 -0
- package/src/cli/content.js +6 -5
- package/src/cli/content.js.map +1 -1
- package/src/cli.js +16 -3
- package/src/cli.js.map +1 -1
- package/src/{connection-D5S9Iph-.js → connection-BP80q4d-.js} +2 -2
- package/src/{connection-D5S9Iph-.js.map → connection-BP80q4d-.js.map} +1 -1
- package/src/{dev-lifecycle-D3f9-upa.js → dev-lifecycle-DdBluSiR.js} +26 -6
- package/src/dev-lifecycle-DdBluSiR.js.map +1 -0
- package/src/{installation-fZtNxtoW.js → installation-BoG8E3nJ.js} +7982 -7155
- package/src/installation-BoG8E3nJ.js.map +1 -0
- package/src/internal/authoring-catalog.js +2 -2
- package/src/internal/authoring-compiler.js +35 -9
- package/src/internal/authoring-compiler.js.map +1 -1
- package/src/internal/authoring-metadata.js +14 -5
- package/src/internal/authoring-metadata.js.map +1 -1
- package/src/internal/configuration.js +27 -3
- package/src/internal/configuration.js.map +1 -1
- package/src/internal/dev-lifecycle.js +2 -2
- package/src/internal/document-model.js +134 -43
- package/src/internal/document-model.js.map +1 -1
- package/src/internal/field-metadata.js +2 -1
- package/src/internal/field-metadata.js.map +1 -1
- package/src/internal/form-capabilities.js +1 -1
- package/src/{location-CPX7oj0o.js → location-CMNGO3lU.js} +2 -2
- package/src/{location-CPX7oj0o.js.map → location-CMNGO3lU.js.map} +1 -1
- package/src/{metadata-BEZPWh-3.js → metadata-UzZmjwxM.js} +2 -2
- package/src/{metadata-BEZPWh-3.js.map → metadata-UzZmjwxM.js.map} +1 -1
- package/src/{models-C9kF9JlQ.js → models-5j67LMqW.js} +4 -4
- package/src/{models-C9kF9JlQ.js.map → models-5j67LMqW.js.map} +1 -1
- package/src/{models-ChRxBChy.js → models-VmGmG19-.js} +42 -130
- package/src/models-VmGmG19-.js.map +1 -0
- package/src/runtime/delivery/DocumentRenderer.js +5 -1
- package/src/runtime/delivery/DocumentRenderer.js.map +1 -1
- package/src/runtime/delivery/context.js +1 -1
- package/src/runtime/delivery/plugin.js +2 -2
- package/src/runtime/delivery/preview.d.ts +1 -1
- package/src/runtime/delivery/types.d.ts +1 -1
- package/src/runtime/delivery/useCmsDocumentSeo.d.ts +1 -1
- package/src/runtime/forms/document.js +2 -2
- package/src/runtime/forms/useCmsForm.js +2 -2
- package/src/runtime/installation.js +1 -1
- package/src/runtime/plugin.js +1 -1
- package/src/runtime/preview/CmsStudioPreviewMarker.js +18 -4
- package/src/runtime/preview/CmsStudioPreviewMarker.js.map +1 -1
- package/src/runtime/preview/connection.js +1 -1
- package/src/runtime/preview/controller.js +65 -74
- package/src/runtime/preview/controller.js.map +1 -1
- package/src/runtime/preview/overlay.js +85 -28
- package/src/runtime/preview/overlay.js.map +1 -1
- package/src/runtime/preview/plugin.client.js +4 -4
- package/src/runtime/preview/preview.css +50 -36
- package/src/runtime/preview/protocol.d.ts +11 -5
- package/src/runtime/preview/protocol.js +17 -5
- package/src/runtime/preview/protocol.js.map +1 -1
- package/src/runtime/preview/regions.js +142 -0
- package/src/runtime/preview/regions.js.map +1 -0
- package/src/runtime/preview/store.js +1 -1
- package/src/runtime/sitemap.js +9 -10
- package/src/runtime/sitemap.js.map +1 -1
- package/src/{scalars-B2lgGUnj.js → scalars-CVZqT3L0.js} +2 -6
- package/src/scalars-CVZqT3L0.js.map +1 -0
- package/src/{store-CCsjHaZm.js → store-PKKB8xa2.js} +49 -66
- package/src/store-PKKB8xa2.js.map +1 -0
- package/src/{types-DutFRtaG.d.ts → types-DZ0IV-Ow.d.ts} +14 -3
- package/studio/CreateDocumentDialog-vQ8hDs2C.js +253 -0
- package/studio/{documentPlanning-CDb31mnl.js → documentPlanning-Bx3W9KkD.js} +12054 -12085
- package/studio/{editor-Bzlh3zXt.js → editor-P2rB7Csp.js} +11228 -11927
- package/studio/host.css +1 -1
- package/studio/host.js +23594 -24903
- package/studio/rolldown-runtime-Dy4uBu1J.js +11 -0
- package/src/Configuration-BU-UyGoH.js.map +0 -1
- package/src/ContentTransfer-BhF9G56s.js +0 -57
- package/src/ContentTransfer-BhF9G56s.js.map +0 -1
- package/src/DocumentEngine-ClhFXW9M.js.map +0 -1
- package/src/Forms-DoB56hfe.js.map +0 -1
- package/src/S3MediaObjects-CR3p1WTg.js.map +0 -1
- package/src/dev-lifecycle-D3f9-upa.js.map +0 -1
- package/src/installation-fZtNxtoW.js.map +0 -1
- package/src/models-ChRxBChy.js.map +0 -1
- package/src/runtime/preview/targets.js +0 -101
- package/src/runtime/preview/targets.js.map +0 -1
- package/src/scalars-B2lgGUnj.js.map +0 -1
- package/src/store-CCsjHaZm.js.map +0 -1
- package/studio/CreateDocumentDialog-DJ8c0WZb.js +0 -256
- package/studio/dom-to-image-more.min-D6jGGdrW.js +0 -877
- package/studio/rolldown-runtime-B0aSnxlc.js +0 -20
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FIELD_INPUT_METADATA } from "./field-metadata.js";
|
|
2
|
-
import { r as DocumentConfiguration } from "../Configuration-
|
|
3
|
-
import { t as createDocumentEngine } from "../DocumentEngine-
|
|
1
|
+
import { FIELD_INPUT_METADATA, FIELD_OPTIONS_METADATA } from "./field-metadata.js";
|
|
2
|
+
import { r as DocumentConfiguration, u as compileStructuredFields } from "../Configuration-JQ1qyaU0.js";
|
|
3
|
+
import { t as createDocumentEngine } from "../DocumentEngine-j6Vi7nQo.js";
|
|
4
4
|
import { Effect, Predicate, Result, Schema } from "effect";
|
|
5
5
|
|
|
6
6
|
//#region src/internal/document-model.ts
|
|
@@ -40,7 +40,7 @@ function compileCollection(collection, options) {
|
|
|
40
40
|
try {
|
|
41
41
|
if (isEffectCollectionSchema(options.schema)) {
|
|
42
42
|
const document = Schema.toJsonSchemaDocument(options.schema, {
|
|
43
|
-
includeAnnotationKey: (key) => key ===
|
|
43
|
+
includeAnnotationKey: (key) => key === "x-cms-input" || key === "x-cms-options",
|
|
44
44
|
referencePolicy: () => void 0
|
|
45
45
|
});
|
|
46
46
|
generated = {
|
|
@@ -59,43 +59,68 @@ function compileCollection(collection, options) {
|
|
|
59
59
|
const input = resolveInputStructure(decoded.success, `${path}.schema`);
|
|
60
60
|
if (input.type !== "object") throw invalid(`${path}.schema`, "A collection schema must describe an object input.");
|
|
61
61
|
const projection = compileProjection(input, `${path}.schema`);
|
|
62
|
+
const authoringFields = compileAuthoringFields(input, `${path}.schema`);
|
|
63
|
+
const structuredFields = compileStructuredFields(authoringFields);
|
|
62
64
|
const validator = isEffectCollectionSchema(options.schema) ? Schema.toStandardSchemaV1(options.schema) : options.schema;
|
|
63
65
|
return {
|
|
64
66
|
authoring: {
|
|
65
|
-
addressPattern: options.route,
|
|
66
67
|
...options.body === void 0 ? void 0 : { body: options.body },
|
|
67
|
-
authoringFields
|
|
68
|
+
authoringFields,
|
|
68
69
|
canCreate: options.canCreate ?? true,
|
|
69
70
|
collection,
|
|
70
71
|
description: options.description ?? "",
|
|
71
|
-
directory: options.source ?? collection,
|
|
72
72
|
hierarchy: options.hierarchy ?? options.route.includes("*"),
|
|
73
|
-
label: options.label
|
|
73
|
+
label: options.label,
|
|
74
|
+
routes: {
|
|
75
|
+
entry: options.route,
|
|
76
|
+
home: collectionHomeRoute(options.route)
|
|
77
|
+
}
|
|
74
78
|
},
|
|
75
79
|
executable: {
|
|
76
80
|
project: projection,
|
|
77
|
-
validate: (value) => Effect.tryPromise(() => Promise.resolve(validator["~standard"].validate(value)))
|
|
81
|
+
validate: (value) => Effect.tryPromise(() => Promise.resolve(validator["~standard"].validate(value)).then((validation) => {
|
|
82
|
+
if ("issues" in validation || !Schema.is(Schema.JsonObject)(validation.value)) return validation;
|
|
83
|
+
const issues = structuredFields.validateIdentities(validation.value);
|
|
84
|
+
return issues.length > 0 ? { issues } : validation;
|
|
85
|
+
}))
|
|
78
86
|
}
|
|
79
87
|
};
|
|
80
88
|
}
|
|
81
|
-
function
|
|
89
|
+
function collectionHomeRoute(entryRoute) {
|
|
90
|
+
const token = entryRoute.indexOf(":");
|
|
91
|
+
const normalized = `/${(token < 0 ? entryRoute : entryRoute.slice(0, token)).split("/").filter(Boolean).join("/")}`;
|
|
92
|
+
return normalized === "/" ? "/" : normalized.replace(/\/$/u, "");
|
|
93
|
+
}
|
|
94
|
+
function compileProjection(schema, path) {
|
|
82
95
|
const properties = objectKeyword(schema, "properties", path, true);
|
|
83
96
|
const declarations = new Map(Object.entries(properties).map(([name, value]) => {
|
|
84
|
-
const fieldPath = parent ? `${parent}.${name}` : name;
|
|
85
97
|
const property = requireObject(value, `${path}.${name}`);
|
|
86
|
-
|
|
98
|
+
const nested = property.type === "object" ? compileProjection(property, `${path}.${name}`) : void 0;
|
|
99
|
+
const items = property.type === "array" ? requireObject(property.items, `${path}.${name}[]`) : void 0;
|
|
100
|
+
return [name, {
|
|
101
|
+
listItem: items?.type === "object" ? compileProjection(items, `${path}.${name}[]`) : void 0,
|
|
102
|
+
nested
|
|
103
|
+
}];
|
|
87
104
|
}));
|
|
88
|
-
return (input) => {
|
|
105
|
+
return (input, parent = "") => {
|
|
89
106
|
const value = {};
|
|
90
107
|
const unknownPaths = [];
|
|
91
108
|
for (const [name, child] of Object.entries(input)) {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
109
|
+
const declaration = declarations.get(name);
|
|
110
|
+
const fieldPath = parent ? `${parent}.${name}` : name;
|
|
111
|
+
if (!declarations.has(name)) unknownPaths.push(fieldPath);
|
|
112
|
+
else if (declaration?.nested && isJsonObject(child)) {
|
|
113
|
+
const projected = declaration.nested(child, fieldPath);
|
|
96
114
|
value[name] = projected.value;
|
|
97
115
|
unknownPaths.push(...projected.unknownPaths);
|
|
98
|
-
} else value[name] = child
|
|
116
|
+
} else if (declaration?.listItem && Array.isArray(child)) value[name] = child.map((item, index) => {
|
|
117
|
+
if (!isJsonObject(item)) return item;
|
|
118
|
+
const projected = declaration.listItem?.(item, `${fieldPath}.${index}`);
|
|
119
|
+
if (!projected) return item;
|
|
120
|
+
unknownPaths.push(...projected.unknownPaths);
|
|
121
|
+
return projected.value;
|
|
122
|
+
});
|
|
123
|
+
else value[name] = child;
|
|
99
124
|
}
|
|
100
125
|
return {
|
|
101
126
|
unknownPaths,
|
|
@@ -103,33 +128,39 @@ function compileProjection(schema, path, parent = "") {
|
|
|
103
128
|
};
|
|
104
129
|
};
|
|
105
130
|
}
|
|
106
|
-
function compileAuthoringFields(schema, path,
|
|
131
|
+
function compileAuthoringFields(schema, path, listItem = false) {
|
|
107
132
|
const properties = objectKeyword(schema, "properties", path, true);
|
|
108
133
|
const required = stringArrayKeyword(schema, "required", path);
|
|
109
134
|
return Object.entries(properties).flatMap(([name, value]) => {
|
|
110
135
|
if (!name || name.includes(".")) throw invalid(`${path}.${name || "<empty>"}`, "Field names must be non-empty and cannot contain dots.");
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const fieldRequired = parentRequired && required.has(name);
|
|
115
|
-
if (property.type === "object") {
|
|
116
|
-
if (property.default !== void 0) throw invalid(`${path}.${name}`, "Defaults on object fields are not supported; default their leaf fields instead.");
|
|
117
|
-
return compileAuthoringFields(property, `${path}.${name}`, fieldPath, fieldRequired);
|
|
136
|
+
if (name === "id") {
|
|
137
|
+
if (listItem) return [];
|
|
138
|
+
throw invalid(`${path}.id`, "Field \"id\" is reserved for CMS identity.");
|
|
118
139
|
}
|
|
119
|
-
|
|
140
|
+
const property = requireObject(value, `${path}.${name}`);
|
|
141
|
+
const fieldRequired = required.has(name);
|
|
142
|
+
if (property.type === "object") return [{
|
|
143
|
+
...fieldPresentation(property, `${path}.${name}`, name, fieldRequired),
|
|
144
|
+
fields: compileAuthoringFields(property, `${path}.${name}`),
|
|
145
|
+
input: "object",
|
|
146
|
+
options: [],
|
|
147
|
+
type: "object"
|
|
148
|
+
}];
|
|
149
|
+
return [compileAuthoringField(property, `${path}.${name}`, name, fieldRequired)];
|
|
120
150
|
});
|
|
121
151
|
}
|
|
122
|
-
function compileAuthoringField(schema, schemaPath,
|
|
123
|
-
const presentation = fieldPresentation(schema, schemaPath,
|
|
152
|
+
function compileAuthoringField(schema, schemaPath, name, required) {
|
|
153
|
+
const presentation = fieldPresentation(schema, schemaPath, name, required);
|
|
124
154
|
switch (schema.type) {
|
|
125
155
|
case "boolean": return {
|
|
126
156
|
...presentation,
|
|
127
157
|
input: input(schema, schemaPath, "toggle", ["toggle"]),
|
|
158
|
+
options: [],
|
|
128
159
|
type: "boolean"
|
|
129
160
|
};
|
|
130
161
|
case "integer":
|
|
131
162
|
case "number": {
|
|
132
|
-
const options = numericOptions(schema
|
|
163
|
+
const options = numericOptions(schema, schemaPath);
|
|
133
164
|
return {
|
|
134
165
|
...presentation,
|
|
135
166
|
input: input(schema, schemaPath, options.length > 0 ? "select" : "number", ["number", "select"]),
|
|
@@ -141,15 +172,32 @@ function compileAuthoringField(schema, schemaPath, path, required) {
|
|
|
141
172
|
if (schema.format === "date") return {
|
|
142
173
|
...presentation,
|
|
143
174
|
input: input(schema, schemaPath, "date", ["date"]),
|
|
175
|
+
options: [],
|
|
144
176
|
type: "date"
|
|
145
177
|
};
|
|
146
|
-
|
|
178
|
+
if (schema.format === "cms-document-reference") return {
|
|
179
|
+
...presentation,
|
|
180
|
+
input: "document",
|
|
181
|
+
options: [],
|
|
182
|
+
type: "string"
|
|
183
|
+
};
|
|
184
|
+
if (schema.format === "cms-managed-media-reference") return {
|
|
185
|
+
...presentation,
|
|
186
|
+
input: "media",
|
|
187
|
+
options: [],
|
|
188
|
+
type: "string"
|
|
189
|
+
};
|
|
190
|
+
const options = stringOptions(schema, schemaPath);
|
|
147
191
|
return {
|
|
148
192
|
...presentation,
|
|
149
193
|
input: input(schema, schemaPath, options.length > 0 ? "select" : "text", [
|
|
150
194
|
"select",
|
|
151
195
|
"text",
|
|
152
|
-
"textarea"
|
|
196
|
+
"textarea",
|
|
197
|
+
"image",
|
|
198
|
+
"link",
|
|
199
|
+
"document",
|
|
200
|
+
"media"
|
|
153
201
|
]),
|
|
154
202
|
options,
|
|
155
203
|
type: "string"
|
|
@@ -157,26 +205,40 @@ function compileAuthoringField(schema, schemaPath, path, required) {
|
|
|
157
205
|
}
|
|
158
206
|
case "array": {
|
|
159
207
|
const items = requireObject(schema.items, `${schemaPath}[]`);
|
|
160
|
-
if (items.type
|
|
208
|
+
if (items.type === "object") {
|
|
209
|
+
const itemProperties = objectKeyword(items, "properties", `${schemaPath}[]`, true);
|
|
210
|
+
const itemRequired = stringArrayKeyword(items, "required", `${schemaPath}[]`);
|
|
211
|
+
const identity = itemProperties.id;
|
|
212
|
+
if (!identity || requireObject(identity, `${schemaPath}[].id`).type !== "string" || !itemRequired.has("id")) throw invalid(schemaPath, "Repeatable object items need a required string id managed by the CMS.");
|
|
213
|
+
return {
|
|
214
|
+
...presentation,
|
|
215
|
+
fields: compileAuthoringFields(items, `${schemaPath}[]`, true),
|
|
216
|
+
input: "list",
|
|
217
|
+
options: [],
|
|
218
|
+
type: "array"
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
if (items.type !== "string") throw invalid(schemaPath, "Studio supports scalar string lists or repeatable objects with stable identity.");
|
|
161
222
|
return {
|
|
162
223
|
...presentation,
|
|
163
224
|
input: input(schema, schemaPath, "multiselect", ["multiselect"]),
|
|
164
|
-
options: stringOptions(items
|
|
225
|
+
options: stringOptions(items, `${schemaPath}[]`, schema[FIELD_OPTIONS_METADATA]),
|
|
165
226
|
type: "string[]"
|
|
166
227
|
};
|
|
167
228
|
}
|
|
168
229
|
default: throw invalid(schemaPath, `Studio cannot generate an input for schema type "${displayJson(schema.type)}".`);
|
|
169
230
|
}
|
|
170
231
|
}
|
|
171
|
-
function fieldPresentation(schema, schemaPath,
|
|
232
|
+
function fieldPresentation(schema, schemaPath, name, required) {
|
|
172
233
|
const defaultValue = schema.default;
|
|
173
234
|
const description = stringKeyword(schema, "description", schemaPath);
|
|
174
235
|
const title = stringKeyword(schema, "title", schemaPath);
|
|
175
236
|
return {
|
|
176
237
|
...defaultValue === void 0 ? void 0 : { defaultValue },
|
|
177
238
|
...description === void 0 ? void 0 : { description },
|
|
178
|
-
label: title?.trim() || humanize(
|
|
179
|
-
|
|
239
|
+
label: title?.trim() || humanize(name),
|
|
240
|
+
name,
|
|
241
|
+
nullable: schema["x-cms-nullable"] === true,
|
|
180
242
|
required
|
|
181
243
|
};
|
|
182
244
|
}
|
|
@@ -187,17 +249,34 @@ function input(schema, path, fallback, supported) {
|
|
|
187
249
|
if (Result.isSuccess(decoded)) return decoded.success;
|
|
188
250
|
throw invalid(path, `Input "${displayJson(configured)}" is not compatible with this field.`);
|
|
189
251
|
}
|
|
190
|
-
function stringOptions(
|
|
252
|
+
function stringOptions(schema, path, configured = schema[FIELD_OPTIONS_METADATA]) {
|
|
253
|
+
const value = schema.enum;
|
|
191
254
|
if (value === void 0) return [];
|
|
192
255
|
const decoded = Schema.decodeUnknownResult(Schema.Array(Schema.String))(value);
|
|
193
256
|
if (Result.isFailure(decoded)) throw invalid(path, "Field options must all be strings.");
|
|
194
|
-
return decoded.success;
|
|
257
|
+
return labeledOptions(configured, decoded.success, path);
|
|
195
258
|
}
|
|
196
|
-
function numericOptions(
|
|
259
|
+
function numericOptions(schema, path) {
|
|
260
|
+
const value = schema.enum;
|
|
197
261
|
if (value === void 0) return [];
|
|
198
262
|
const decoded = Schema.decodeUnknownResult(Schema.Array(Schema.Finite))(value);
|
|
199
263
|
if (Result.isFailure(decoded)) throw invalid(path, "Field options must all be finite numbers.");
|
|
200
|
-
return decoded.success;
|
|
264
|
+
return labeledOptions(schema[FIELD_OPTIONS_METADATA], decoded.success, path);
|
|
265
|
+
}
|
|
266
|
+
function labeledOptions(configured, values, path) {
|
|
267
|
+
if (configured === void 0) return values.map((value) => ({
|
|
268
|
+
label: String(value),
|
|
269
|
+
value
|
|
270
|
+
}));
|
|
271
|
+
const decoded = Schema.decodeUnknownResult(Schema.Array(Schema.Struct({
|
|
272
|
+
label: Schema.String,
|
|
273
|
+
value: Schema.Union([Schema.String, Schema.Finite])
|
|
274
|
+
})))(configured);
|
|
275
|
+
if (Result.isFailure(decoded) || decoded.success.length !== values.length || decoded.success.some((option, index) => option.value !== values[index])) throw invalid(path, "Labeled options must match the schema enum values in order.");
|
|
276
|
+
return values.map((value, index) => ({
|
|
277
|
+
label: decoded.success[index]?.label ?? String(value),
|
|
278
|
+
value
|
|
279
|
+
}));
|
|
201
280
|
}
|
|
202
281
|
function objectKeyword(schema, keyword, path, optional = false) {
|
|
203
282
|
const value = schema[keyword];
|
|
@@ -249,7 +328,18 @@ function resolveInputStructure(root, path) {
|
|
|
249
328
|
const { $ref: _, ...siblings } = node;
|
|
250
329
|
return visit(Object.assign({}, requireObject(target, currentPath), siblings), currentPath, /* @__PURE__ */ new Set([...ancestors, ref]));
|
|
251
330
|
}
|
|
252
|
-
if (node.anyOf !== void 0
|
|
331
|
+
if (node.anyOf !== void 0) {
|
|
332
|
+
if (!Array.isArray(node.anyOf)) throw invalid(currentPath, "Expected an array of schema alternatives.");
|
|
333
|
+
const alternatives = node.anyOf.map((value) => requireObject(value, currentPath));
|
|
334
|
+
const nulls = alternatives.filter((value) => value.type === "null");
|
|
335
|
+
const values = alternatives.filter((value) => value.type !== "null");
|
|
336
|
+
if (nulls.length === 1 && values.length === 1) {
|
|
337
|
+
const { anyOf: _, ...siblings } = node;
|
|
338
|
+
return Object.assign(visit(Object.assign({}, values[0], siblings), currentPath, ancestors), { "x-cms-nullable": true });
|
|
339
|
+
}
|
|
340
|
+
throw invalid(currentPath, "Studio requires a single supported input type per field.");
|
|
341
|
+
}
|
|
342
|
+
if (node.oneOf !== void 0) throw invalid(currentPath, "Studio requires a single supported input type per field.");
|
|
253
343
|
const out = Object.fromEntries(Object.entries(node));
|
|
254
344
|
if (node.allOf !== void 0) {
|
|
255
345
|
if (!Array.isArray(node.allOf)) throw invalid(currentPath, "Expected an array of schema constraints.");
|
|
@@ -262,7 +352,8 @@ function resolveInputStructure(root, path) {
|
|
|
262
352
|
"default",
|
|
263
353
|
"format",
|
|
264
354
|
"enum",
|
|
265
|
-
FIELD_INPUT_METADATA
|
|
355
|
+
FIELD_INPUT_METADATA,
|
|
356
|
+
FIELD_OPTIONS_METADATA
|
|
266
357
|
]) {
|
|
267
358
|
if (part[key] === void 0) continue;
|
|
268
359
|
if (out[key] !== void 0 && JSON.stringify(out[key]) !== JSON.stringify(part[key])) throw invalid(currentPath, `Conflicting field metadata "${key}" in schema intersection.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-model.js","names":[],"sources":["../../../../src/internal/document-model.ts"],"sourcesContent":["import type { CmsI18nOptions } from '../I18n'\nimport type { StandardJSONSchemaV1 } from '@standard-schema/spec'\nimport type {\n DocumentSchemaProjection,\n ExecutableDocumentModel,\n ExecutableDocumentSchema,\n} from '@internal/document/DocumentEngine'\nimport type {\n DocumentConfiguration as DocumentConfigurationType,\n DocumentField,\n} from '@internal/protocol/Configuration'\nimport type {\n CmsCollectionOptions,\n CmsCollectionSchema,\n CmsDocumentModelOptions,\n CmsFieldInput,\n} from '../DocumentModel'\nimport { createDocumentEngine } from '@internal/document/DocumentEngine'\nimport { DocumentConfiguration } from '@internal/protocol/Configuration'\nimport { Effect, Predicate, Result, Schema } from 'effect'\nimport { FIELD_INPUT_METADATA } from './field-metadata'\n\nconst isJsonObject = Schema.is(Schema.JsonObject)\n\ntype EncodedDocumentConfiguration = Schema.Codec.Encoded<typeof DocumentConfiguration>\n\ninterface CmsDocumentModel {\n readonly authoring: DocumentConfigurationType\n readonly executable: ExecutableDocumentModel\n}\n\ninterface CompiledCollection {\n readonly authoring: EncodedDocumentConfiguration['types'][number]\n readonly executable: ExecutableDocumentSchema\n}\n\nexport class CmsDocumentModelInvalid extends Schema.TaggedError<CmsDocumentModelInvalid>()('Cms.DocumentModelInvalid', {\n message: Schema.NonEmptyString,\n path: Schema.NonEmptyString,\n}) {}\n\nconst isCmsDocumentModelInvalid = Schema.is(CmsDocumentModelInvalid)\n\nexport function compileCmsDocumentModel(documents: CmsDocumentModelOptions, i18n?: CmsI18nOptions): CmsDocumentModel {\n try {\n const compiled = Object.entries(documents.collections).map(([collection, options]) =>\n compileCollection(collection, options),\n )\n\n const decoded = Schema.decodeResult(DocumentConfiguration)({\n ...(i18n === undefined\n ? undefined\n : {\n locales: {\n defaultLocale: i18n.defaultLocale,\n fallbackLocale: i18n.fallbackLocale ?? null,\n locales: Object.keys(i18n.locales),\n prefixDefaultLocale: i18n.prefixDefaultLocale ?? false,\n },\n }),\n types: compiled.map((entry) => entry.authoring),\n })\n\n if (Result.isFailure(decoded)) throw invalid('documents', String(decoded.failure))\n\n const model = {\n authoring: decoded.success,\n executable: {\n types: Object.fromEntries(compiled.map((entry) => [entry.authoring.collection, entry.executable])),\n },\n }\n\n const engine = Effect.runSync(\n Effect.result(createDocumentEngine(model.authoring, { documentModel: model.executable })),\n )\n\n if (Result.isFailure(engine)) throw invalid('documents', engine.failure.message)\n\n return model\n } catch (cause) {\n throw isCmsDocumentModelInvalid(cause)\n ? cause\n : invalid('documents.collections', cause instanceof Error ? cause.message : String(cause))\n }\n}\n\nfunction compileCollection(collection: string, options: CmsCollectionOptions): CompiledCollection {\n const path = `documents.collections.${collection}`\n let generated: ReturnType<StandardJSONSchemaV1.Converter['input']>\n\n try {\n if (isEffectCollectionSchema(options.schema)) {\n const document = Schema.toJsonSchemaDocument(options.schema, {\n includeAnnotationKey: (key) => key === FIELD_INPUT_METADATA,\n referencePolicy: () => undefined,\n })\n\n generated = { ...document.schema, $defs: document.definitions }\n } else {\n if (!Predicate.isFunction(options.schema['~standard']?.jsonSchema?.input)) {\n throw new Error('Studio needs Standard JSON Schema V1 input conversion (or an adapter that supplies it).')\n }\n\n generated = options.schema['~standard'].jsonSchema.input({ target: 'draft-2020-12' })\n }\n } catch (cause) {\n throw invalid(`${path}.schema`, cause instanceof Error ? cause.message : String(cause))\n }\n\n const decoded = Schema.decodeUnknownResult(Schema.JsonObject)(generated)\n\n if (Result.isFailure(decoded)) throw invalid(`${path}.schema`, 'The generated input structure is not serializable.')\n const input = resolveInputStructure(decoded.success, `${path}.schema`)\n\n if (input.type !== 'object') throw invalid(`${path}.schema`, 'A collection schema must describe an object input.')\n const projection = compileProjection(input, `${path}.schema`)\n\n const validator = isEffectCollectionSchema(options.schema)\n ? Schema.toStandardSchemaV1(options.schema)\n : options.schema\n\n return {\n authoring: {\n addressPattern: options.route,\n ...(options.body === undefined ? undefined : { body: options.body }),\n authoringFields: compileAuthoringFields(input, `${path}.schema`),\n canCreate: options.canCreate ?? true,\n collection,\n description: options.description ?? '',\n directory: options.source ?? collection,\n hierarchy: options.hierarchy ?? options.route.includes('*'),\n label: options.label,\n },\n executable: {\n project: projection,\n validate: (value) => Effect.tryPromise(() => Promise.resolve(validator['~standard'].validate(value))),\n },\n }\n}\n\ntype ProjectDocumentProjection = (input: Schema.JsonObject) => DocumentSchemaProjection\n\nfunction compileProjection(schema: Schema.JsonObject, path: string, parent = ''): ProjectDocumentProjection {\n const properties = objectKeyword(schema, 'properties', path, true)\n\n const declarations = new Map(\n Object.entries(properties).map(([name, value]) => {\n const fieldPath = parent ? `${parent}.${name}` : name\n const property = requireObject(value, `${path}.${name}`)\n const nested = property.type === 'object' ? compileProjection(property, `${path}.${name}`, fieldPath) : undefined\n\n return [name, nested] as const\n }),\n )\n\n return (input) => {\n const value: Record<string, Schema.Json> = {}\n const unknownPaths: string[] = []\n\n for (const [name, child] of Object.entries(input)) {\n const nested = declarations.get(name)\n\n if (!declarations.has(name)) {\n unknownPaths.push(parent ? `${parent}.${name}` : name)\n } else if (nested && isJsonObject(child)) {\n const projected = nested(child)\n value[name] = projected.value\n unknownPaths.push(...projected.unknownPaths)\n } else {\n value[name] = child\n }\n }\n\n return { unknownPaths, value }\n }\n}\n\nfunction compileAuthoringFields(\n schema: Schema.JsonObject,\n path: string,\n parent = '',\n parentRequired = true,\n): ReadonlyArray<DocumentField> {\n const properties = objectKeyword(schema, 'properties', path, true)\n const required = stringArrayKeyword(schema, 'required', path)\n\n return Object.entries(properties).flatMap(([name, value]) => {\n if (!name || name.includes('.')) {\n throw invalid(`${path}.${name || '<empty>'}`, 'Field names must be non-empty and cannot contain dots.')\n }\n\n const fieldPath = parent ? `${parent}.${name}` : name\n\n if (fieldPath === 'id') throw invalid(`${path}.id`, 'Field \"id\" is reserved for CMS identity.')\n const property = requireObject(value, `${path}.${name}`)\n const fieldRequired = parentRequired && required.has(name)\n\n if (property.type === 'object') {\n if (property.default !== undefined) {\n throw invalid(\n `${path}.${name}`,\n 'Defaults on object fields are not supported; default their leaf fields instead.',\n )\n }\n\n return compileAuthoringFields(property, `${path}.${name}`, fieldPath, fieldRequired)\n }\n\n return [compileAuthoringField(property, `${path}.${name}`, fieldPath, fieldRequired)]\n })\n}\n\nfunction compileAuthoringField(\n schema: Schema.JsonObject,\n schemaPath: string,\n path: string,\n required: boolean,\n): DocumentField {\n const presentation = fieldPresentation(schema, schemaPath, path, required)\n\n switch (schema.type) {\n case 'boolean':\n return { ...presentation, input: input(schema, schemaPath, 'toggle', ['toggle']), type: 'boolean' }\n case 'integer':\n case 'number': {\n const options = numericOptions(schema.enum, schemaPath)\n\n return {\n ...presentation,\n input: input(schema, schemaPath, options.length > 0 ? 'select' : 'number', ['number', 'select']),\n options,\n type: 'number',\n }\n }\n\n case 'string': {\n if (schema.format === 'date') {\n return { ...presentation, input: input(schema, schemaPath, 'date', ['date']), type: 'date' }\n }\n\n const options = stringOptions(schema.enum, schemaPath)\n\n return {\n ...presentation,\n input: input(schema, schemaPath, options.length > 0 ? 'select' : 'text', ['select', 'text', 'textarea']),\n options,\n type: 'string',\n }\n }\n\n case 'array': {\n const items = requireObject(schema.items, `${schemaPath}[]`)\n\n if (items.type !== 'string') throw invalid(schemaPath, 'Studio currently supports authoring arrays of strings.')\n\n return {\n ...presentation,\n input: input(schema, schemaPath, 'multiselect', ['multiselect']),\n options: stringOptions(items.enum, `${schemaPath}[]`),\n type: 'string[]',\n }\n }\n\n default:\n throw invalid(schemaPath, `Studio cannot generate an input for schema type \"${displayJson(schema.type)}\".`)\n }\n}\n\nfunction fieldPresentation(schema: Schema.JsonObject, schemaPath: string, path: string, required: boolean) {\n const defaultValue = schema.default\n const description = stringKeyword(schema, 'description', schemaPath)\n const title = stringKeyword(schema, 'title', schemaPath)\n\n return {\n ...(defaultValue === undefined ? undefined : { defaultValue }),\n ...(description === undefined ? undefined : { description }),\n label: title?.trim() || humanize(path),\n path,\n required,\n }\n}\n\nfunction input<const Supported extends ReadonlyArray<CmsFieldInput>>(\n schema: Schema.JsonObject,\n path: string,\n fallback: Supported[number],\n supported: Supported,\n): Supported[number] {\n const configured = schema[FIELD_INPUT_METADATA]\n\n if (configured === undefined) return fallback\n const decoded = Schema.decodeUnknownResult(Schema.Literals([...supported]))(configured)\n\n if (Result.isSuccess(decoded)) return decoded.success\n throw invalid(path, `Input \"${displayJson(configured)}\" is not compatible with this field.`)\n}\n\nfunction stringOptions(value: Schema.Json | undefined, path: string): ReadonlyArray<string> {\n if (value === undefined) return []\n const decoded = Schema.decodeUnknownResult(Schema.Array(Schema.String))(value)\n\n if (Result.isFailure(decoded)) throw invalid(path, 'Field options must all be strings.')\n\n return decoded.success\n}\n\nfunction numericOptions(value: Schema.Json | undefined, path: string): ReadonlyArray<number> {\n if (value === undefined) return []\n const decoded = Schema.decodeUnknownResult(Schema.Array(Schema.Finite))(value)\n\n if (Result.isFailure(decoded)) throw invalid(path, 'Field options must all be finite numbers.')\n\n return decoded.success\n}\n\nfunction objectKeyword(schema: Schema.JsonObject, keyword: string, path: string, optional = false): Schema.JsonObject {\n const value = schema[keyword]\n\n if (value === undefined && optional) return {}\n\n return requireObject(value, `${path}.${keyword}`)\n}\n\nfunction stringArrayKeyword(schema: Schema.JsonObject, keyword: string, path: string): ReadonlySet<string> {\n const value = schema[keyword]\n\n if (value === undefined) return new Set()\n const decoded = Schema.decodeUnknownResult(Schema.Array(Schema.String))(value)\n\n if (Result.isFailure(decoded)) throw invalid(`${path}.${keyword}`, `Expected \"${keyword}\" to be an array of strings.`)\n\n return new Set(decoded.success)\n}\n\nfunction stringKeyword(schema: Schema.JsonObject, keyword: string, path: string): string | undefined {\n const value = schema[keyword]\n\n if (value === undefined) return undefined\n const decoded = Schema.decodeUnknownResult(Schema.String)(value)\n\n if (Result.isFailure(decoded)) throw invalid(`${path}.${keyword}`, `Expected \"${keyword}\" to be a string.`)\n\n return decoded.success\n}\n\nfunction requireObject(value: Schema.Json | undefined, path: string): Schema.JsonObject {\n if (!isJsonObject(value)) throw invalid(path, 'Studio requires an object input structure at this location.')\n\n return value\n}\n\nfunction humanize(path: string): string {\n const name = path.split('.').at(-1) ?? path\n\n const words = name\n .replace(/([a-z\\d])([A-Z])/gu, '$1 $2')\n .replace(/[-_]+/gu, ' ')\n .trim()\n\n return words ? `${words.charAt(0).toUpperCase()}${words.slice(1)}` : name\n}\n\nfunction displayJson(value: Schema.Json | undefined): string {\n return value === undefined ? 'undefined' : (JSON.stringify(value) ?? 'undefined')\n}\n\nfunction invalid(path: string, message: string): CmsDocumentModelInvalid {\n return new CmsDocumentModelInvalid({ message, path })\n}\n\n/** Resolve local input references while rejecting recursive or ambiguous editor structures. */\nfunction resolveInputStructure(root: Schema.JsonObject, path: string): Schema.JsonObject {\n function visit(node: Schema.JsonObject, currentPath: string, ancestors: ReadonlySet<string>): Schema.JsonObject {\n if (node.$ref !== undefined) {\n const decodedRef = Schema.decodeUnknownResult(Schema.String)(node.$ref)\n\n if (Result.isFailure(decodedRef)) throw invalid(currentPath, 'Expected a string schema reference.')\n const ref = decodedRef.success\n\n if (!ref.startsWith('#/') || ancestors.has(ref)) {\n throw invalid(currentPath, 'Studio requires non-recursive local schema references.')\n }\n\n let target: Schema.Json | undefined = root\n\n for (const segment of ref.slice(2).split('/')) {\n target = isJsonObject(target) ? target[segment.replace(/~1/gu, '/').replace(/~0/gu, '~')] : undefined\n }\n\n const { $ref: _, ...siblings } = node\n\n return visit(\n Object.assign({}, requireObject(target, currentPath), siblings),\n currentPath,\n new Set([...ancestors, ref]),\n )\n }\n\n if (node.anyOf !== undefined || node.oneOf !== undefined) {\n throw invalid(currentPath, 'Studio requires a single supported input type per field.')\n }\n\n const out = Object.fromEntries(Object.entries(node))\n\n if (node.allOf !== undefined) {\n if (!Array.isArray(node.allOf)) throw invalid(currentPath, 'Expected an array of schema constraints.')\n\n for (const constraint of node.allOf) {\n const part = visit(requireObject(constraint, currentPath), currentPath, ancestors)\n\n if (\n part.properties !== undefined ||\n part.items !== undefined ||\n (part.type !== undefined && part.type !== node.type)\n ) {\n throw invalid(currentPath, 'Studio cannot combine structural schema intersections.')\n }\n\n for (const key of ['title', 'description', 'default', 'format', 'enum', FIELD_INPUT_METADATA]) {\n if (part[key] === undefined) continue\n\n if (out[key] !== undefined && JSON.stringify(out[key]) !== JSON.stringify(part[key])) {\n throw invalid(currentPath, `Conflicting field metadata \"${key}\" in schema intersection.`)\n }\n\n out[key] = part[key]\n }\n }\n }\n\n if (node.properties !== undefined) {\n out.properties = Object.fromEntries(\n Object.entries(requireObject(node.properties, currentPath)).map(([name, value]) => [\n name,\n visit(requireObject(value, `${currentPath}.${name}`), `${currentPath}.${name}`, ancestors),\n ]),\n )\n }\n\n if (node.items !== undefined)\n out.items = visit(requireObject(node.items, `${currentPath}[]`), `${currentPath}[]`, ancestors)\n\n return out\n }\n\n return visit(root, path, new Set())\n}\n\nfunction isEffectCollectionSchema(schema: CmsCollectionSchema): schema is Schema.ConstraintDecoder<unknown> {\n return Schema.isSchema(schema)\n}\n"],"mappings":";;;;;;AAsBA,MAAM,eAAe,OAAO,GAAG,OAAO,UAAU;AAchD,IAAa,0BAAb,cAA6C,OAAO,YAAqC,CAAC,CAAC,4BAA4B;CACrH,SAAS,OAAO;CAChB,MAAM,OAAO;AACf,CAAC,CAAC,CAAC,CAAC;AAEJ,MAAM,4BAA4B,OAAO,GAAG,uBAAuB;AAEnE,SAAgB,wBAAwB,WAAoC,MAAyC;CACnH,IAAI;EACF,MAAM,WAAW,OAAO,QAAQ,UAAU,WAAW,CAAC,CAAC,KAAK,CAAC,YAAY,aACvE,kBAAkB,YAAY,OAAO,CACvC;EAEA,MAAM,UAAU,OAAO,aAAa,qBAAqB,CAAC,CAAC;GACzD,GAAI,SAAS,SACT,SACA,EACE,SAAS;IACP,eAAe,KAAK;IACpB,gBAAgB,KAAK,kB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KAAW;KAAU;KAAQ;IAAoB,GAAG;KAC7F,IAAI,KAAK,SAAS,QAAW;KAE7B,IAAI,IAAI,SAAS,UAAa,KAAK,UAAU,IAAI,IAAI,MAAM,KAAK,UAAU,KAAK,IAAI,GACjF,MAAM,QAAQ,aAAa,+BAA+B,IAAI,0BAA0B;KAG1F,IAAI,OAAO,KAAK;IAClB;GACF;EACF;EAEA,IAAI,KAAK,eAAe,QACtB,IAAI,aAAa,OAAO,YACtB,OAAO,QAAQ,cAAc,KAAK,YAAY,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW,CACjF,MACA,MAAM,cAAc,OAAO,GAAG,YAAY,GAAG,MAAM,GAAG,GAAG,YAAY,GAAG,QAAQ,SAAS,CAC3F,CAAC,CACH;EAGF,IAAI,KAAK,UAAU,QACjB,IAAI,QAAQ,MAAM,cAAc,KAAK,OAAO,GAAG,YAAY,GAAG,GAAG,GAAG,YAAY,KAAK,SAAS;EAEhG,OAAO;CACT;CAEA,OAAO,MAAM,MAAM,sBAAM,IAAI,IAAI,CAAC;AACpC;AAEA,SAAS,yBAAyB,QAA0E;CAC1G,OAAO,OAAO,SAAS,MAAM;AAC/B"}
|
|
1
|
+
{"version":3,"file":"document-model.js","names":[],"sources":["../../../../src/internal/document-model.ts"],"sourcesContent":["import type { CmsI18nOptions } from '../I18n'\nimport type { StandardJSONSchemaV1 } from '@standard-schema/spec'\nimport type {\n DocumentSchemaProjection,\n ExecutableDocumentModel,\n ExecutableDocumentSchema,\n} from '@internal/document/DocumentEngine'\nimport type { DocumentConfiguration as DocumentConfigurationType } from '@internal/protocol/Configuration'\nimport type { StructuredField } from '@internal/protocol/StructuredFields'\nimport type {\n CmsCollectionOptions,\n CmsCollectionSchema,\n CmsDocumentModelOptions,\n CmsFieldInput,\n} from '../DocumentModel'\nimport { createDocumentEngine } from '@internal/document/DocumentEngine'\nimport { compileStructuredFields } from '@internal/document/StructuredFields'\nimport { DocumentConfiguration } from '@internal/protocol/Configuration'\nimport { Effect, Predicate, Result, Schema } from 'effect'\nimport { FIELD_INPUT_METADATA, FIELD_OPTIONS_METADATA } from './field-metadata'\n\nconst isJsonObject = Schema.is(Schema.JsonObject)\n\ntype EncodedDocumentConfiguration = Schema.Codec.Encoded<typeof DocumentConfiguration>\n\ninterface CmsDocumentModel {\n readonly authoring: DocumentConfigurationType\n readonly executable: ExecutableDocumentModel\n}\n\ninterface CompiledCollection {\n readonly authoring: EncodedDocumentConfiguration['types'][number]\n readonly executable: ExecutableDocumentSchema\n}\n\nexport class CmsDocumentModelInvalid extends Schema.TaggedError<CmsDocumentModelInvalid>()('Cms.DocumentModelInvalid', {\n message: Schema.NonEmptyString,\n path: Schema.NonEmptyString,\n}) {}\n\nconst isCmsDocumentModelInvalid = Schema.is(CmsDocumentModelInvalid)\n\nexport function compileCmsDocumentModel(documents: CmsDocumentModelOptions, i18n?: CmsI18nOptions): CmsDocumentModel {\n try {\n const compiled = Object.entries(documents.collections).map(([collection, options]) =>\n compileCollection(collection, options),\n )\n\n const decoded = Schema.decodeResult(DocumentConfiguration)({\n ...(i18n === undefined\n ? undefined\n : {\n locales: {\n defaultLocale: i18n.defaultLocale,\n fallbackLocale: i18n.fallbackLocale ?? null,\n locales: Object.keys(i18n.locales),\n prefixDefaultLocale: i18n.prefixDefaultLocale ?? false,\n },\n }),\n types: compiled.map((entry) => entry.authoring),\n })\n\n if (Result.isFailure(decoded)) throw invalid('documents', String(decoded.failure))\n\n const model = {\n authoring: decoded.success,\n executable: {\n types: Object.fromEntries(compiled.map((entry) => [entry.authoring.collection, entry.executable])),\n },\n }\n\n const engine = Effect.runSync(\n Effect.result(createDocumentEngine(model.authoring, { documentModel: model.executable })),\n )\n\n if (Result.isFailure(engine)) throw invalid('documents', engine.failure.message)\n\n return model\n } catch (cause) {\n throw isCmsDocumentModelInvalid(cause)\n ? cause\n : invalid('documents.collections', cause instanceof Error ? cause.message : String(cause))\n }\n}\n\nfunction compileCollection(collection: string, options: CmsCollectionOptions): CompiledCollection {\n const path = `documents.collections.${collection}`\n let generated: ReturnType<StandardJSONSchemaV1.Converter['input']>\n\n try {\n if (isEffectCollectionSchema(options.schema)) {\n const document = Schema.toJsonSchemaDocument(options.schema, {\n includeAnnotationKey: (key) => key === FIELD_INPUT_METADATA || key === FIELD_OPTIONS_METADATA,\n referencePolicy: () => undefined,\n })\n\n generated = { ...document.schema, $defs: document.definitions }\n } else {\n if (!Predicate.isFunction(options.schema['~standard']?.jsonSchema?.input)) {\n throw new Error('Studio needs Standard JSON Schema V1 input conversion (or an adapter that supplies it).')\n }\n\n generated = options.schema['~standard'].jsonSchema.input({ target: 'draft-2020-12' })\n }\n } catch (cause) {\n throw invalid(`${path}.schema`, cause instanceof Error ? cause.message : String(cause))\n }\n\n const decoded = Schema.decodeUnknownResult(Schema.JsonObject)(generated)\n\n if (Result.isFailure(decoded)) throw invalid(`${path}.schema`, 'The generated input structure is not serializable.')\n const input = resolveInputStructure(decoded.success, `${path}.schema`)\n\n if (input.type !== 'object') throw invalid(`${path}.schema`, 'A collection schema must describe an object input.')\n const projection = compileProjection(input, `${path}.schema`)\n const authoringFields = compileAuthoringFields(input, `${path}.schema`)\n const structuredFields = compileStructuredFields(authoringFields)\n\n const validator = isEffectCollectionSchema(options.schema)\n ? Schema.toStandardSchemaV1(options.schema)\n : options.schema\n\n return {\n authoring: {\n ...(options.body === undefined ? undefined : { body: options.body }),\n authoringFields,\n canCreate: options.canCreate ?? true,\n collection,\n description: options.description ?? '',\n hierarchy: options.hierarchy ?? options.route.includes('*'),\n label: options.label,\n routes: { entry: options.route, home: collectionHomeRoute(options.route) },\n },\n executable: {\n project: projection,\n validate: (value) =>\n Effect.tryPromise(() =>\n Promise.resolve(validator['~standard'].validate(value)).then((validation) => {\n if ('issues' in validation || !Schema.is(Schema.JsonObject)(validation.value)) return validation\n const issues = structuredFields.validateIdentities(validation.value)\n\n return issues.length > 0 ? { issues } : validation\n }),\n ),\n },\n }\n}\n\nfunction collectionHomeRoute(entryRoute: string): string {\n const token = entryRoute.indexOf(':')\n const prefix = token < 0 ? entryRoute : entryRoute.slice(0, token)\n const normalized = `/${prefix.split('/').filter(Boolean).join('/')}`\n\n return normalized === '/' ? '/' : normalized.replace(/\\/$/u, '')\n}\n\ntype ProjectDocumentProjection = (input: Schema.JsonObject, parent?: string) => DocumentSchemaProjection\n\nfunction compileProjection(schema: Schema.JsonObject, path: string): ProjectDocumentProjection {\n const properties = objectKeyword(schema, 'properties', path, true)\n\n const declarations = new Map(\n Object.entries(properties).map(([name, value]) => {\n const property = requireObject(value, `${path}.${name}`)\n const nested = property.type === 'object' ? compileProjection(property, `${path}.${name}`) : undefined\n const items = property.type === 'array' ? requireObject(property.items, `${path}.${name}[]`) : undefined\n const listItem = items?.type === 'object' ? compileProjection(items, `${path}.${name}[]`) : undefined\n\n return [name, { listItem, nested }] as const\n }),\n )\n\n return (input, parent = '') => {\n const value: Record<string, Schema.Json> = {}\n const unknownPaths: string[] = []\n\n for (const [name, child] of Object.entries(input)) {\n const declaration = declarations.get(name)\n const fieldPath = parent ? `${parent}.${name}` : name\n\n if (!declarations.has(name)) {\n unknownPaths.push(fieldPath)\n } else if (declaration?.nested && isJsonObject(child)) {\n const projected = declaration.nested(child, fieldPath)\n value[name] = projected.value\n unknownPaths.push(...projected.unknownPaths)\n } else if (declaration?.listItem && Array.isArray(child)) {\n value[name] = child.map((item, index) => {\n if (!isJsonObject(item)) return item\n const projected = declaration.listItem?.(item, `${fieldPath}.${index}`)\n\n if (!projected) return item\n unknownPaths.push(...projected.unknownPaths)\n\n return projected.value\n })\n } else {\n value[name] = child\n }\n }\n\n return { unknownPaths, value }\n }\n}\n\nfunction compileAuthoringFields(\n schema: Schema.JsonObject,\n path: string,\n listItem = false,\n): ReadonlyArray<StructuredField> {\n const properties = objectKeyword(schema, 'properties', path, true)\n const required = stringArrayKeyword(schema, 'required', path)\n\n return Object.entries(properties).flatMap(([name, value]) => {\n if (!name || name.includes('.')) {\n throw invalid(`${path}.${name || '<empty>'}`, 'Field names must be non-empty and cannot contain dots.')\n }\n\n if (name === 'id') {\n if (listItem) return []\n throw invalid(`${path}.id`, 'Field \"id\" is reserved for CMS identity.')\n }\n\n const property = requireObject(value, `${path}.${name}`)\n const fieldRequired = required.has(name)\n\n if (property.type === 'object') {\n return [\n {\n ...fieldPresentation(property, `${path}.${name}`, name, fieldRequired),\n fields: compileAuthoringFields(property, `${path}.${name}`),\n input: 'object',\n options: [],\n type: 'object',\n },\n ]\n }\n\n return [compileAuthoringField(property, `${path}.${name}`, name, fieldRequired)]\n })\n}\n\nfunction compileAuthoringField(\n schema: Schema.JsonObject,\n schemaPath: string,\n name: string,\n required: boolean,\n): StructuredField {\n const presentation = fieldPresentation(schema, schemaPath, name, required)\n\n switch (schema.type) {\n case 'boolean':\n return { ...presentation, input: input(schema, schemaPath, 'toggle', ['toggle']), options: [], type: 'boolean' }\n case 'integer':\n case 'number': {\n const options = numericOptions(schema, schemaPath)\n\n return {\n ...presentation,\n input: input(schema, schemaPath, options.length > 0 ? 'select' : 'number', ['number', 'select']),\n options,\n type: 'number',\n }\n }\n\n case 'string': {\n if (schema.format === 'date') {\n return { ...presentation, input: input(schema, schemaPath, 'date', ['date']), options: [], type: 'date' }\n }\n\n if (schema.format === 'cms-document-reference') {\n return { ...presentation, input: 'document', options: [], type: 'string' }\n }\n\n if (schema.format === 'cms-managed-media-reference') {\n return { ...presentation, input: 'media', options: [], type: 'string' }\n }\n\n const options = stringOptions(schema, schemaPath)\n\n return {\n ...presentation,\n input: input(schema, schemaPath, options.length > 0 ? 'select' : 'text', [\n 'select',\n 'text',\n 'textarea',\n 'image',\n 'link',\n 'document',\n 'media',\n ]),\n options,\n type: 'string',\n }\n }\n\n case 'array': {\n const items = requireObject(schema.items, `${schemaPath}[]`)\n\n if (items.type === 'object') {\n const itemProperties = objectKeyword(items, 'properties', `${schemaPath}[]`, true)\n const itemRequired = stringArrayKeyword(items, 'required', `${schemaPath}[]`)\n const identity = itemProperties.id\n\n if (!identity || requireObject(identity, `${schemaPath}[].id`).type !== 'string' || !itemRequired.has('id')) {\n throw invalid(schemaPath, 'Repeatable object items need a required string id managed by the CMS.')\n }\n\n return {\n ...presentation,\n fields: compileAuthoringFields(items, `${schemaPath}[]`, true),\n input: 'list',\n options: [],\n type: 'array',\n }\n }\n\n if (items.type !== 'string')\n throw invalid(schemaPath, 'Studio supports scalar string lists or repeatable objects with stable identity.')\n\n return {\n ...presentation,\n input: input(schema, schemaPath, 'multiselect', ['multiselect']),\n options: stringOptions(items, `${schemaPath}[]`, schema[FIELD_OPTIONS_METADATA]),\n type: 'string[]',\n }\n }\n\n default:\n throw invalid(schemaPath, `Studio cannot generate an input for schema type \"${displayJson(schema.type)}\".`)\n }\n}\n\nfunction fieldPresentation(schema: Schema.JsonObject, schemaPath: string, name: string, required: boolean) {\n const defaultValue = schema.default\n const description = stringKeyword(schema, 'description', schemaPath)\n const title = stringKeyword(schema, 'title', schemaPath)\n\n return {\n ...(defaultValue === undefined ? undefined : { defaultValue }),\n ...(description === undefined ? undefined : { description }),\n label: title?.trim() || humanize(name),\n name,\n nullable: schema['x-cms-nullable'] === true,\n required,\n }\n}\n\nfunction input<const Supported extends ReadonlyArray<CmsFieldInput>>(\n schema: Schema.JsonObject,\n path: string,\n fallback: Supported[number],\n supported: Supported,\n): Supported[number] {\n const configured = schema[FIELD_INPUT_METADATA]\n\n if (configured === undefined) return fallback\n const decoded = Schema.decodeUnknownResult(Schema.Literals([...supported]))(configured)\n\n if (Result.isSuccess(decoded)) return decoded.success\n throw invalid(path, `Input \"${displayJson(configured)}\" is not compatible with this field.`)\n}\n\nfunction stringOptions(\n schema: Schema.JsonObject,\n path: string,\n configured: Schema.Json | undefined = schema[FIELD_OPTIONS_METADATA],\n): ReadonlyArray<{ label: string; value: string }> {\n const value = schema.enum\n\n if (value === undefined) return []\n const decoded = Schema.decodeUnknownResult(Schema.Array(Schema.String))(value)\n\n if (Result.isFailure(decoded)) throw invalid(path, 'Field options must all be strings.')\n\n return labeledOptions(configured, decoded.success, path)\n}\n\nfunction numericOptions(schema: Schema.JsonObject, path: string): ReadonlyArray<{ label: string; value: number }> {\n const value = schema.enum\n\n if (value === undefined) return []\n const decoded = Schema.decodeUnknownResult(Schema.Array(Schema.Finite))(value)\n\n if (Result.isFailure(decoded)) throw invalid(path, 'Field options must all be finite numbers.')\n\n return labeledOptions(schema[FIELD_OPTIONS_METADATA], decoded.success, path)\n}\n\nfunction labeledOptions<const Value extends string | number>(\n configured: Schema.Json | undefined,\n values: ReadonlyArray<Value>,\n path: string,\n): ReadonlyArray<{ label: string; value: Value }> {\n if (configured === undefined) return values.map((value) => ({ label: String(value), value }))\n\n const decoded = Schema.decodeUnknownResult(\n Schema.Array(Schema.Struct({ label: Schema.String, value: Schema.Union([Schema.String, Schema.Finite]) })),\n )(configured)\n\n if (\n Result.isFailure(decoded) ||\n decoded.success.length !== values.length ||\n decoded.success.some((option, index) => option.value !== values[index])\n )\n throw invalid(path, 'Labeled options must match the schema enum values in order.')\n\n return values.map((value, index) => ({ label: decoded.success[index]?.label ?? String(value), value }))\n}\n\nfunction objectKeyword(schema: Schema.JsonObject, keyword: string, path: string, optional = false): Schema.JsonObject {\n const value = schema[keyword]\n\n if (value === undefined && optional) return {}\n\n return requireObject(value, `${path}.${keyword}`)\n}\n\nfunction stringArrayKeyword(schema: Schema.JsonObject, keyword: string, path: string): ReadonlySet<string> {\n const value = schema[keyword]\n\n if (value === undefined) return new Set()\n const decoded = Schema.decodeUnknownResult(Schema.Array(Schema.String))(value)\n\n if (Result.isFailure(decoded)) throw invalid(`${path}.${keyword}`, `Expected \"${keyword}\" to be an array of strings.`)\n\n return new Set(decoded.success)\n}\n\nfunction stringKeyword(schema: Schema.JsonObject, keyword: string, path: string): string | undefined {\n const value = schema[keyword]\n\n if (value === undefined) return undefined\n const decoded = Schema.decodeUnknownResult(Schema.String)(value)\n\n if (Result.isFailure(decoded)) throw invalid(`${path}.${keyword}`, `Expected \"${keyword}\" to be a string.`)\n\n return decoded.success\n}\n\nfunction requireObject(value: Schema.Json | undefined, path: string): Schema.JsonObject {\n if (!isJsonObject(value)) throw invalid(path, 'Studio requires an object input structure at this location.')\n\n return value\n}\n\nfunction humanize(path: string): string {\n const name = path.split('.').at(-1) ?? path\n\n const words = name\n .replace(/([a-z\\d])([A-Z])/gu, '$1 $2')\n .replace(/[-_]+/gu, ' ')\n .trim()\n\n return words ? `${words.charAt(0).toUpperCase()}${words.slice(1)}` : name\n}\n\nfunction displayJson(value: Schema.Json | undefined): string {\n return value === undefined ? 'undefined' : (JSON.stringify(value) ?? 'undefined')\n}\n\nfunction invalid(path: string, message: string): CmsDocumentModelInvalid {\n return new CmsDocumentModelInvalid({ message, path })\n}\n\n/** Resolve local input references while rejecting recursive or ambiguous editor structures. */\nfunction resolveInputStructure(root: Schema.JsonObject, path: string): Schema.JsonObject {\n function visit(node: Schema.JsonObject, currentPath: string, ancestors: ReadonlySet<string>): Schema.JsonObject {\n if (node.$ref !== undefined) {\n const decodedRef = Schema.decodeUnknownResult(Schema.String)(node.$ref)\n\n if (Result.isFailure(decodedRef)) throw invalid(currentPath, 'Expected a string schema reference.')\n const ref = decodedRef.success\n\n if (!ref.startsWith('#/') || ancestors.has(ref)) {\n throw invalid(currentPath, 'Studio requires non-recursive local schema references.')\n }\n\n let target: Schema.Json | undefined = root\n\n for (const segment of ref.slice(2).split('/')) {\n target = isJsonObject(target) ? target[segment.replace(/~1/gu, '/').replace(/~0/gu, '~')] : undefined\n }\n\n const { $ref: _, ...siblings } = node\n\n return visit(\n Object.assign({}, requireObject(target, currentPath), siblings),\n currentPath,\n new Set([...ancestors, ref]),\n )\n }\n\n if (node.anyOf !== undefined) {\n if (!Array.isArray(node.anyOf)) throw invalid(currentPath, 'Expected an array of schema alternatives.')\n const alternatives = node.anyOf.map((value) => requireObject(value, currentPath))\n const nulls = alternatives.filter((value) => value.type === 'null')\n const values = alternatives.filter((value) => value.type !== 'null')\n\n if (nulls.length === 1 && values.length === 1) {\n const { anyOf: _, ...siblings } = node\n\n return Object.assign(visit(Object.assign({}, values[0], siblings), currentPath, ancestors), {\n 'x-cms-nullable': true,\n })\n }\n\n throw invalid(currentPath, 'Studio requires a single supported input type per field.')\n }\n\n if (node.oneOf !== undefined) {\n throw invalid(currentPath, 'Studio requires a single supported input type per field.')\n }\n\n const out = Object.fromEntries(Object.entries(node))\n\n if (node.allOf !== undefined) {\n if (!Array.isArray(node.allOf)) throw invalid(currentPath, 'Expected an array of schema constraints.')\n\n for (const constraint of node.allOf) {\n const part = visit(requireObject(constraint, currentPath), currentPath, ancestors)\n\n if (\n part.properties !== undefined ||\n part.items !== undefined ||\n (part.type !== undefined && part.type !== node.type)\n ) {\n throw invalid(currentPath, 'Studio cannot combine structural schema intersections.')\n }\n\n for (const key of [\n 'title',\n 'description',\n 'default',\n 'format',\n 'enum',\n FIELD_INPUT_METADATA,\n FIELD_OPTIONS_METADATA,\n ]) {\n if (part[key] === undefined) continue\n\n if (out[key] !== undefined && JSON.stringify(out[key]) !== JSON.stringify(part[key])) {\n throw invalid(currentPath, `Conflicting field metadata \"${key}\" in schema intersection.`)\n }\n\n out[key] = part[key]\n }\n }\n }\n\n if (node.properties !== undefined) {\n out.properties = Object.fromEntries(\n Object.entries(requireObject(node.properties, currentPath)).map(([name, value]) => [\n name,\n visit(requireObject(value, `${currentPath}.${name}`), `${currentPath}.${name}`, ancestors),\n ]),\n )\n }\n\n if (node.items !== undefined)\n out.items = visit(requireObject(node.items, `${currentPath}[]`), `${currentPath}[]`, ancestors)\n\n return out\n }\n\n return visit(root, path, new Set())\n}\n\nfunction isEffectCollectionSchema(schema: CmsCollectionSchema): schema is Schema.ConstraintDecoder<unknown> {\n return Schema.isSchema(schema)\n}\n"],"mappings":";;;;;;AAqBA,MAAM,eAAe,OAAO,GAAG,OAAO,UAAU;AAchD,IAAa,0BAAb,cAA6C,OAAO,YAAqC,CAAC,CAAC,4BAA4B;CACrH,SAAS,OAAO;CAChB,MAAM,OAAO;AACf,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CACjF,MACA,MAAM,cAAc,OAAO,GAAG,YAAY,GAAG,MAAM,GAAG,GAAG,YAAY,GAAG,QAAQ,SAAS,CAC3F,CAAC,CACH;EAGF,IAAI,KAAK,UAAU,QACjB,IAAI,QAAQ,MAAM,cAAc,KAAK,OAAO,GAAG,YAAY,GAAG,GAAG,GAAG,YAAY,KAAK,SAAS;EAEhG,OAAO;CACT;CAEA,OAAO,MAAM,MAAM,sBAAM,IAAI,IAAI,CAAC;AACpC;AAEA,SAAS,yBAAyB,QAA0E;CAC1G,OAAO,OAAO,SAAS,MAAM;AAC/B"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
//#region src/internal/field-metadata.ts
|
|
2
2
|
const FIELD_INPUT_METADATA = "x-cms-input";
|
|
3
|
+
const FIELD_OPTIONS_METADATA = "x-cms-options";
|
|
3
4
|
|
|
4
5
|
//#endregion
|
|
5
|
-
export { FIELD_INPUT_METADATA };
|
|
6
|
+
export { FIELD_INPUT_METADATA, FIELD_OPTIONS_METADATA };
|
|
6
7
|
//# sourceMappingURL=field-metadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-metadata.js","names":[],"sources":["../../../../src/internal/field-metadata.ts"],"sourcesContent":["export const FIELD_INPUT_METADATA = 'x-cms-input'\n"],"mappings":";AAAA,MAAa,uBAAuB"}
|
|
1
|
+
{"version":3,"file":"field-metadata.js","names":[],"sources":["../../../../src/internal/field-metadata.ts"],"sourcesContent":["export const FIELD_INPUT_METADATA = 'x-cms-input'\n\nexport const FIELD_OPTIONS_METADATA = 'x-cms-options'\n"],"mappings":";AAAA,MAAa,uBAAuB;AAEpC,MAAa,yBAAyB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as PreviewSessionId, i as PreviewOrigin } from "./models-
|
|
1
|
+
import { a as PreviewSessionId, i as PreviewOrigin } from "./models-5j67LMqW.js";
|
|
2
2
|
import { Option, Schema } from "effect";
|
|
3
3
|
|
|
4
4
|
//#region ../protocol/src/internal/preview/location.ts
|
|
@@ -32,4 +32,4 @@ function previewRedirect(url, parameters) {
|
|
|
32
32
|
|
|
33
33
|
//#endregion
|
|
34
34
|
export { readPreviewLocation as n, withPreviewLocation as r, previewRedirect as t };
|
|
35
|
-
//# sourceMappingURL=location-
|
|
35
|
+
//# sourceMappingURL=location-CMNGO3lU.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"location-
|
|
1
|
+
{"version":3,"file":"location-CMNGO3lU.js","names":["PreviewOriginSchema","PreviewSessionIdSchema"],"sources":["../../../../protocol/src/internal/preview/location.ts"],"sourcesContent":["import { Option, Schema } from 'effect'\nimport { PreviewOrigin as PreviewOriginSchema, PreviewSessionId as PreviewSessionIdSchema } from './models'\n\nconst ENABLED_PARAMETER = '_cms_preview'\n\nconst EDITOR_ORIGIN_PARAMETER = '_cms_preview_editor_origin'\n\nconst SESSION_PARAMETER = '_cms_preview_session'\n\nconst PreviewLocationParameters = Schema.Struct({\n editorOrigin: PreviewOriginSchema,\n sessionId: PreviewSessionIdSchema,\n})\n\nexport interface PreviewLocationParameters extends Schema.Schema.Type<typeof PreviewLocationParameters> {}\n\nexport function readPreviewLocation(url: URL): PreviewLocationParameters | undefined {\n if (url.searchParams.get(ENABLED_PARAMETER) !== '1' || url.searchParams.get(EDITOR_ORIGIN_PARAMETER) !== url.origin)\n return undefined\n\n return Schema.decodeUnknownOption(PreviewLocationParameters)({\n editorOrigin: url.searchParams.get(EDITOR_ORIGIN_PARAMETER),\n sessionId: url.searchParams.get(SESSION_PARAMETER),\n }).pipe(Option.getOrUndefined)\n}\n\nexport function withPreviewLocation(url: URL, parameters: PreviewLocationParameters): URL {\n const next = new URL(url)\n next.searchParams.set(ENABLED_PARAMETER, '1')\n next.searchParams.set(EDITOR_ORIGIN_PARAMETER, parameters.editorOrigin)\n next.searchParams.set(SESSION_PARAMETER, parameters.sessionId)\n\n return next\n}\n\nexport function withoutPreviewLocation(url: URL): URL {\n const next = new URL(url)\n next.searchParams.delete(ENABLED_PARAMETER)\n next.searchParams.delete(EDITOR_ORIGIN_PARAMETER)\n next.searchParams.delete(SESSION_PARAMETER)\n\n return next\n}\n\nexport function previewRedirect(url: URL, parameters: PreviewLocationParameters): string | undefined {\n const current = readPreviewLocation(url)\n\n if (current?.sessionId === parameters.sessionId && current.editorOrigin === parameters.editorOrigin) return undefined\n const next = withPreviewLocation(url, parameters)\n\n return `${next.pathname}${next.search}${next.hash}`\n}\n"],"mappings":";;;;AAGA,MAAM,oBAAoB;AAE1B,MAAM,0BAA0B;AAEhC,MAAM,oBAAoB;AAE1B,MAAM,4BAA4B,OAAO,OAAO;CAC9C,cAAcA;CACd,WAAWC;AACb,CAAC;AAID,SAAgB,oBAAoB,KAAiD;CACnF,IAAI,IAAI,aAAa,IAAI,iBAAiB,MAAM,OAAO,IAAI,aAAa,IAAI,uBAAuB,MAAM,IAAI,QAC3G,OAAO;CAET,OAAO,OAAO,oBAAoB,yBAAyB,CAAC,CAAC;EAC3D,cAAc,IAAI,aAAa,IAAI,uBAAuB;EAC1D,WAAW,IAAI,aAAa,IAAI,iBAAiB;CACnD,CAAC,CAAC,CAAC,KAAK,OAAO,cAAc;AAC/B;AAEA,SAAgB,oBAAoB,KAAU,YAA4C;CACxF,MAAM,OAAO,IAAI,IAAI,GAAG;CACxB,KAAK,aAAa,IAAI,mBAAmB,GAAG;CAC5C,KAAK,aAAa,IAAI,yBAAyB,WAAW,YAAY;CACtE,KAAK,aAAa,IAAI,mBAAmB,WAAW,SAAS;CAE7D,OAAO;AACT;AAWA,SAAgB,gBAAgB,KAAU,YAA2D;CACnG,MAAM,UAAU,oBAAoB,GAAG;CAEvC,IAAI,SAAS,cAAc,WAAW,aAAa,QAAQ,iBAAiB,WAAW,cAAc,OAAO;CAC5G,MAAM,OAAO,oBAAoB,KAAK,UAAU;CAEhD,OAAO,GAAG,KAAK,WAAW,KAAK,SAAS,KAAK;AAC/C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as EditorNodeId } from "./scalars-
|
|
1
|
+
import { a as EditorNodeId } from "./scalars-CVZqT3L0.js";
|
|
2
2
|
import { Predicate, Schema } from "effect";
|
|
3
3
|
|
|
4
4
|
//#region ../document/src/internal/editor/identity.ts
|
|
@@ -118,4 +118,4 @@ function jsonObject(value) {
|
|
|
118
118
|
|
|
119
119
|
//#endregion
|
|
120
120
|
export { createEditorNodeId as a, withoutEditorMetadata as i, editorMetadata as n, editorNodeId as o, identifiedAttributes as r, assertCanonicalEditorContent as t };
|
|
121
|
-
//# sourceMappingURL=metadata-
|
|
121
|
+
//# sourceMappingURL=metadata-UzZmjwxM.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata-
|
|
1
|
+
{"version":3,"file":"metadata-UzZmjwxM.js","names":["EditorNodeIdSchema"],"sources":["../../../../document/src/internal/editor/identity.ts","../../../../document/src/internal/editor/metadata.ts"],"sourcesContent":["import type { EditorNodeId } from '@internal/protocol/Documents'\nimport { EditorNodeId as EditorNodeIdSchema } from '@internal/protocol/Documents'\nimport { Schema } from 'effect'\n\nconst isEditorNodeId = Schema.is(EditorNodeIdSchema)\n\nexport const IDENTIFIED_EDITOR_TYPES = new Set([\n 'blockquote',\n 'bulletList',\n 'cmsBlock',\n 'cmsOpaque',\n 'cmsSlot',\n 'codeBlock',\n 'heading',\n 'horizontalRule',\n 'image',\n 'listItem',\n 'orderedList',\n 'paragraph',\n])\n\nexport function createEditorNodeId(): EditorNodeId {\n const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16))\n bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x40\n bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80\n const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('')\n\n return EditorNodeIdSchema.make(\n `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`,\n )\n}\n\nexport function editorNodeId(value: Schema.Json | undefined): EditorNodeId | undefined {\n return isEditorNodeId(value) ? value : undefined\n}\n\nexport function isIdentifiedEditorType(type: string | undefined): boolean {\n return type !== undefined && IDENTIFIED_EDITOR_TYPES.has(type)\n}\n","import type { CmsMarkdownDocument, MarkdownNode } from '@internal/protocol/Documents'\nimport type { EditorNodeId } from '@internal/protocol/Documents'\nimport type { JSONContent } from '@tiptap/core'\nimport { Predicate, Schema } from 'effect'\nimport { editorNodeId, isIdentifiedEditorType } from './identity'\n\nconst isJsonObject = Schema.is(Schema.JsonObject)\n\ninterface EditorMetadata {\n readonly implicitSlotId?: EditorNodeId\n readonly nodeId: EditorNodeId\n}\n\nexport function assertCanonicalEditorContent(content: JSONContent): void {\n const seen = new Set<EditorNodeId>()\n\n const visit = (node: JSONContent, path: ReadonlyArray<number>) => {\n if (isIdentifiedEditorNode(node)) {\n const id = editorNodeId(node.attrs?.cmsNodeId)\n\n if (id === undefined) {\n throw new Error(`Authorable ${node.type} at ${diagnosticPath(path)} has no valid node identity.`)\n }\n\n if (seen.has(id)) {\n throw new Error(`Authorable ${node.type} at ${diagnosticPath(path)} duplicates node identity \"${id}\".`)\n }\n\n seen.add(id)\n }\n\n node.content?.forEach((child, index) => visit(child, [...path, index]))\n }\n\n visit(content, [])\n}\n\nexport function identifiedAttributes(\n attributes: Schema.JsonObject,\n nodeIdValue: Schema.Json | undefined,\n implicitSlotIdValue?: Schema.Json,\n): Schema.JsonObject {\n const nodeId = editorNodeId(nodeIdValue)\n const implicitSlotId = implicitSlotIdValue === undefined ? undefined : editorNodeId(implicitSlotIdValue)\n\n if (nodeId === undefined) throw new Error('Cannot project an authorable node without a valid identity.')\n\n if (implicitSlotIdValue !== undefined && implicitSlotId === undefined)\n throw new Error('Cannot project an implicit slot without a valid identity.')\n\n const internal: Record<string, Schema.Json> = structuredClone(jsonObject(attributes.$))\n\n if (implicitSlotId === undefined) internal.editor = { nodeId }\n else internal.editor = { implicitSlotId, nodeId }\n const result: Record<string, Schema.Json> = structuredClone(attributes)\n result.$ = internal\n\n return result\n}\n\nexport function editorMetadata(attributes: Schema.JsonObject): EditorMetadata | undefined {\n const metadata = jsonObject(jsonObject(attributes.$).editor)\n const nodeId = editorNodeId(metadata.nodeId)\n const implicitSlotId = metadata.implicitSlotId === undefined ? undefined : editorNodeId(metadata.implicitSlotId)\n\n if (nodeId === undefined) return undefined\n\n if (metadata.implicitSlotId !== undefined && implicitSlotId === undefined) return undefined\n\n return implicitSlotId === undefined ? { nodeId } : { implicitSlotId, nodeId }\n}\n\nexport function withoutEditorMetadata(body: CmsMarkdownDocument): CmsMarkdownDocument {\n return {\n frontmatter: structuredClone(body.frontmatter),\n meta: structuredClone(body.meta),\n nodes: body.nodes.map(cleanNode),\n }\n}\n\nfunction cleanNode(node: MarkdownNode): MarkdownNode {\n if (Predicate.isString(node)) return node\n\n if (node[0] === null) {\n const cleanAttributes = cleanNodeAttributes(node[1])\n\n return [null, cleanAttributes, node[2]]\n }\n\n const [tag, attributes, ...children] = node\n\n return [tag, cleanNodeAttributes(attributes), ...children.map(cleanNode)]\n}\n\nfunction cleanNodeAttributes(attributes: Schema.JsonObject): Record<string, Schema.Json> {\n const cleanAttributes: Record<string, Schema.Json> = structuredClone(attributes)\n const internal = jsonObject(cleanAttributes.$)\n\n if (internal.editor !== undefined) {\n const { editor: _editor, ...remaining } = internal\n\n if (Object.keys(remaining).length) cleanAttributes.$ = remaining\n else delete cleanAttributes.$\n }\n\n return cleanAttributes\n}\n\nfunction isIdentifiedEditorNode(node: JSONContent): boolean {\n if (!isIdentifiedEditorType(node.type)) return false\n\n if (node.attrs?.cmsSynthetic === true || node.attrs?.cmsTransient === true) return false\n\n return node.type !== 'paragraph' || Boolean(node.content?.length)\n}\n\nfunction diagnosticPath(path: ReadonlyArray<number>): string {\n return path.length ? path.join('.') : 'document root'\n}\n\nfunction jsonObject(value: Schema.Json | undefined): Schema.JsonObject {\n return isJsonObject(value) ? value : {}\n}\n"],"mappings":";;;;AAIA,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AAG,KAAK;CAAE;CAGxC,MAAM,CAAC,KAAK,YAAY,GAAG,YAAY;CAEvC,OAAO;EAAC;EAAK,oBAAoB,UAAU;EAAG,GAAG,SAAS,IAAI,SAAS;CAAC;AAC1E;AAEA,SAAS,oBAAoB,YAA4D;CACvF,MAAM,kBAA+C,gBAAgB,UAAU;CAC/E,MAAM,WAAW,WAAW,gBAAgB,CAAC;CAE7C,IAAI,SAAS,WAAW,QAAW;EACjC,MAAM,EAAE,QAAQ,SAAS,GAAG,cAAc;EAE1C,IAAI,OAAO,KAAK,SAAS,CAAC,CAAC,QAAQ,gBAAgB,IAAI;OAClD,OAAO,gBAAgB;CAC9B;CAEA,OAAO;AACT;AAEA,SAAS,uBAAuB,MAA4B;CAC1D,IAAI,CAAC,uBAAuB,KAAK,IAAI,GAAG,OAAO;CAE/C,IAAI,KAAK,OAAO,iBAAiB,QAAQ,KAAK,OAAO,iBAAiB,MAAM,OAAO;CAEnF,OAAO,KAAK,SAAS,eAAe,QAAQ,KAAK,SAAS,MAAM;AAClE;AAEA,SAAS,eAAe,MAAqC;CAC3D,OAAO,KAAK,SAAS,KAAK,KAAK,GAAG,IAAI;AACxC;AAEA,SAAS,WAAW,OAAmD;CACrE,OAAO,aAAa,KAAK,IAAI,QAAQ,CAAC;AACxC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as EditorNodeId,
|
|
2
|
-
import {
|
|
1
|
+
import { a as EditorNodeId, c as RevisionNumber, o as PublicPath, r as DocumentId } from "./scalars-CVZqT3L0.js";
|
|
2
|
+
import { it as CollectionName, r as CompiledDocument, st as RequestId } from "./models-VmGmG19-.js";
|
|
3
3
|
import { Schema } from "effect";
|
|
4
4
|
|
|
5
5
|
//#region ../protocol/src/internal/preview/models.ts
|
|
@@ -18,6 +18,7 @@ const PreviewOrigin = Schema.NonEmptyString.check(exactOrigin).pipe(Schema.brand
|
|
|
18
18
|
const DocumentPreviewFocusIntent = Schema.Struct({
|
|
19
19
|
id: PreviewIntentId,
|
|
20
20
|
documentId: DocumentId,
|
|
21
|
+
label: Schema.optionalKey(Schema.NonEmptyString),
|
|
21
22
|
nodeId: Schema.optionalKey(EditorNodeId),
|
|
22
23
|
origin: Schema.Literals(["editor", "preview"]),
|
|
23
24
|
reveal: Schema.Boolean,
|
|
@@ -85,7 +86,6 @@ const PreviewActivateMessage = Schema.Struct({
|
|
|
85
86
|
...previewEnvelope,
|
|
86
87
|
type: Schema.tag("preview:activate"),
|
|
87
88
|
documentId: DocumentId,
|
|
88
|
-
field: Schema.optionalKey(Schema.NonEmptyString),
|
|
89
89
|
nodeId: Schema.optionalKey(EditorNodeId),
|
|
90
90
|
requestId: RequestId,
|
|
91
91
|
revision: RevisionNumber
|
|
@@ -128,4 +128,4 @@ const isDocumentPreviewMessage = Schema.is(DocumentPreviewMessage);
|
|
|
128
128
|
|
|
129
129
|
//#endregion
|
|
130
130
|
export { PreviewSessionId as a, PreviewOrigin as i, DocumentPreviewMessage as n, isDocumentPreviewMessage as o, PreviewIntentId as r, DOCUMENT_PREVIEW_CHANNEL as t };
|
|
131
|
-
//# sourceMappingURL=models-
|
|
131
|
+
//# sourceMappingURL=models-5j67LMqW.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models-
|
|
1
|
+
{"version":3,"file":"models-5j67LMqW.js","names":[],"sources":["../../../../protocol/src/internal/preview/models.ts"],"sourcesContent":["import { CompiledDocument } from '../../Documents'\nimport { RequestId } from '../../Identity'\nimport { CollectionName } from '../configuration/scalars'\nimport { DocumentId, EditorNodeId, PublicPath, RevisionNumber } from '../documents/scalars'\nimport { Schema } from 'effect'\n\nexport const DOCUMENT_PREVIEW_CHANNEL = 'cms:document-preview'\n\nexport const PreviewSessionId = Schema.String.check(Schema.isUUID()).pipe(Schema.brand('PreviewSessionId'))\n\nexport type PreviewSessionId = typeof PreviewSessionId.Type\n\nexport const PreviewIntentId = Schema.String.check(Schema.isUUID()).pipe(Schema.brand('PreviewIntentId'))\n\nexport type PreviewIntentId = typeof PreviewIntentId.Type\n\nconst exactOrigin = Schema.makeFilter<string>(\n (value) => {\n try {\n const url = new URL(value)\n\n return (url.protocol === 'http:' || url.protocol === 'https:') && url.origin === value\n } catch {\n return false\n }\n },\n { expected: 'an exact HTTP or HTTPS origin without a path' },\n)\n\nexport const PreviewOrigin = Schema.NonEmptyString.check(exactOrigin).pipe(Schema.brand('PreviewOrigin'))\n\nexport type PreviewOrigin = typeof PreviewOrigin.Type\n\nexport const DocumentPreviewFocusIntent = Schema.Struct({\n id: PreviewIntentId,\n documentId: DocumentId,\n label: Schema.optionalKey(Schema.NonEmptyString),\n nodeId: Schema.optionalKey(EditorNodeId),\n origin: Schema.Literals(['editor', 'preview']),\n reveal: Schema.Boolean,\n revision: RevisionNumber,\n})\n\nexport interface DocumentPreviewFocusIntent extends Schema.Schema.Type<typeof DocumentPreviewFocusIntent> {}\n\nexport const RenderedCompiledDocument = Schema.Struct({\n collection: CollectionName,\n documentId: DocumentId,\n path: PublicPath,\n role: Schema.Literals(['embedded', 'primary', 'related', 'summary']),\n title: Schema.NonEmptyString,\n})\n\nexport interface RenderedCompiledDocument extends Schema.Schema.Type<typeof RenderedCompiledDocument> {}\n\nexport const RenderedDocumentManifest = Schema.Struct({\n documents: Schema.Array(RenderedCompiledDocument),\n route: PublicPath,\n})\n\nexport interface RenderedDocumentManifest extends Schema.Schema.Type<typeof RenderedDocumentManifest> {}\n\nconst previewEnvelope = {\n channel: Schema.Literal(DOCUMENT_PREVIEW_CHANNEL),\n sessionId: PreviewSessionId,\n}\n\nconst StudioConnectMessage = Schema.Struct({\n ...previewEnvelope,\n type: Schema.tag('studio:connect'),\n})\n\nconst StudioModeMessage = Schema.Struct({\n ...previewEnvelope,\n type: Schema.tag('studio:mode'),\n mode: Schema.Literals(['browse', 'edit']),\n})\n\nconst StudioNavigateMessage = Schema.Struct({\n ...previewEnvelope,\n type: Schema.tag('studio:navigate'),\n path: PublicPath,\n})\n\nconst StudioPatchMessage = Schema.Struct({\n ...previewEnvelope,\n type: Schema.tag('studio:patch'),\n document: CompiledDocument,\n fallbacks: Schema.Record(Schema.String, Schema.String),\n focus: Schema.optionalKey(DocumentPreviewFocusIntent),\n revision: RevisionNumber,\n})\n\nconst StudioFocusMessage = Schema.Struct({\n ...previewEnvelope,\n type: Schema.tag('studio:focus'),\n focus: DocumentPreviewFocusIntent,\n})\n\nconst PreviewReadyMessage = Schema.Struct({\n ...previewEnvelope,\n type: Schema.tag('preview:ready'),\n path: PublicPath,\n})\n\nconst PreviewManifestMessage = Schema.Struct({\n ...previewEnvelope,\n type: Schema.tag('preview:manifest'),\n manifest: RenderedDocumentManifest,\n revision: RevisionNumber,\n})\n\nconst PreviewActivateMessage = Schema.Struct({\n ...previewEnvelope,\n type: Schema.tag('preview:activate'),\n documentId: DocumentId,\n nodeId: Schema.optionalKey(EditorNodeId),\n requestId: RequestId,\n revision: RevisionNumber,\n})\n\nconst PreviewAppliedMessage = Schema.Struct({\n ...previewEnvelope,\n type: Schema.tag('preview:applied'),\n intentId: PreviewIntentId,\n nodeId: Schema.optionalKey(EditorNodeId),\n result: Schema.Literals(['exact', 'fallback', 'missing']),\n revision: RevisionNumber,\n})\n\nconst PreviewRenderedMessage = Schema.Struct({\n ...previewEnvelope,\n type: Schema.tag('preview:rendered'),\n revision: RevisionNumber,\n})\n\nexport const DocumentPreviewMessage = Schema.Union([\n StudioConnectMessage,\n StudioModeMessage,\n StudioNavigateMessage,\n StudioPatchMessage,\n StudioFocusMessage,\n PreviewReadyMessage,\n Schema.Struct({ ...previewEnvelope, type: Schema.tag('preview:error'), message: Schema.NullOr(Schema.String) }),\n PreviewManifestMessage,\n PreviewActivateMessage,\n PreviewAppliedMessage,\n PreviewRenderedMessage,\n]).pipe(Schema.toTaggedUnion('type'))\n\nexport type DocumentPreviewMessage = typeof DocumentPreviewMessage.Type\n\nexport const isDocumentPreviewMessage = Schema.is(DocumentPreviewMessage)\n\ntype PreviewPayload<Message extends DocumentPreviewMessage> = Message extends DocumentPreviewMessage\n ? Omit<Message, 'channel' | 'sessionId'>\n : never\n\nexport type StudioPreviewPayload = PreviewPayload<\n Extract<DocumentPreviewMessage, { readonly type: `studio:${string}` }>\n>\n\nexport type PreviewSitePayload = PreviewPayload<Extract<DocumentPreviewMessage, { readonly type: `preview:${string}` }>>\n"],"mappings":";;;;;AAMA,MAAa,2BAA2B;AAExC,MAAa,mBAAmB,OAAO,OAAO,MAAM,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAI1G,MAAa,kBAAkB,OAAO,OAAO,MAAM,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,MAAM,iBAAiB,CAAC;AAIxG,MAAM,cAAc,OAAO,YACxB,UAAU;CACT,IAAI;EACF,MAAM,MAAM,IAAI,IAAI,KAAK;EAEzB,QAAQ,IAAI,aAAa,WAAW,IAAI,aAAa,aAAa,IAAI,WAAW;CACnF,QAAQ;EACN,OAAO;CACT;AACF,GACA,EAAE,UAAU,+CAA+C,CAC7D;AAEA,MAAa,gBAAgB,OAAO,eAAe,MAAM,WAAW,CAAC,CAAC,KAAK,OAAO,MAAM,eAAe,CAAC;AAIxG,MAAa,6BAA6B,OAAO,OAAO;CACtD,IAAI;CACJ,YAAY;CACZ,OAAO,OAAO,YAAY,OAAO,cAAc;CAC/C,QAAQ,OAAO,YAAY,YAAY;CACvC,QAAQ,OAAO,SAAS,CAAC,UAAU,SAAS,CAAC;CAC7C,QAAQ,OAAO;CACf,UAAU;AACZ,CAAC;AAID,MAAa,2BAA2B,OAAO,OAAO;CACpD,YAAY;CACZ,YAAY;CACZ,MAAM;CACN,MAAM,OAAO,SAAS;EAAC;EAAY;EAAW;EAAW;CAAS,CAAC;CACnE,OAAO,OAAO;AAChB,CAAC;AAID,MAAa,2BAA2B,OAAO,OAAO;CACpD,WAAW,OAAO,MAAM,wBAAwB;CAChD,OAAO;AACT,CAAC;AAID,MAAM,kBAAkB;CACtB,SAAS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