@storyblok/schema 0.1.0-alpha.0 → 0.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/field-plugins/index.cjs +4 -0
- package/dist/field-plugins/index.d.cts +2 -0
- package/dist/field-plugins/index.d.mts +2 -0
- package/dist/field-plugins/index.mjs +3 -0
- package/dist/field-plugins/storyblok-color-field.cjs +32 -0
- package/dist/field-plugins/storyblok-color-field.cjs.map +1 -0
- package/dist/field-plugins/storyblok-color-field.d.cts +16 -0
- package/dist/field-plugins/storyblok-color-field.d.mts +16 -0
- package/dist/field-plugins/storyblok-color-field.mjs +32 -0
- package/dist/field-plugins/storyblok-color-field.mjs.map +1 -0
- package/dist/generated/capi/types.gen.d.cts +1 -126
- package/dist/generated/capi/types.gen.d.mts +1 -126
- package/dist/generated/mapi/_internal.gen.d.cts +1 -171
- package/dist/generated/mapi/_internal.gen.d.mts +1 -171
- package/dist/generated/overlay/zod.gen.cjs +407 -0
- package/dist/generated/overlay/zod.gen.cjs.map +1 -0
- package/dist/generated/overlay/zod.gen.mjs +402 -0
- package/dist/generated/overlay/zod.gen.mjs.map +1 -0
- package/dist/generated/types/block.d.cts +27 -14
- package/dist/generated/types/block.d.mts +27 -14
- package/dist/generated/types/field.d.cts +48 -17
- package/dist/generated/types/field.d.mts +48 -17
- package/dist/generated/types/mapi-story.d.cts +6 -10
- package/dist/generated/types/mapi-story.d.mts +6 -10
- package/dist/generated/types/story.d.cts +3 -3
- package/dist/generated/types/story.d.mts +3 -3
- package/dist/helpers/define-block.cjs +10 -28
- package/dist/helpers/define-block.cjs.map +1 -1
- package/dist/helpers/define-block.d.cts +14 -31
- package/dist/helpers/define-block.d.mts +14 -31
- package/dist/helpers/define-block.mjs +11 -27
- package/dist/helpers/define-block.mjs.map +1 -1
- package/dist/helpers/define-datasource.cjs +0 -16
- package/dist/helpers/define-datasource.cjs.map +1 -1
- package/dist/helpers/define-datasource.d.cts +14 -23
- package/dist/helpers/define-datasource.d.mts +14 -23
- package/dist/helpers/define-datasource.mjs +1 -15
- package/dist/helpers/define-datasource.mjs.map +1 -1
- package/dist/helpers/define-field-plugin.cjs +21 -0
- package/dist/helpers/define-field-plugin.cjs.map +1 -0
- package/dist/helpers/define-field-plugin.d.cts +33 -0
- package/dist/helpers/define-field-plugin.d.mts +33 -0
- package/dist/helpers/define-field-plugin.mjs +20 -0
- package/dist/helpers/define-field-plugin.mjs.map +1 -0
- package/dist/helpers/define-field.cjs +11 -11
- package/dist/helpers/define-field.cjs.map +1 -1
- package/dist/helpers/define-field.d.cts +46 -85
- package/dist/helpers/define-field.d.mts +46 -85
- package/dist/helpers/define-field.mjs +12 -11
- package/dist/helpers/define-field.mjs.map +1 -1
- package/dist/helpers/define-schema.cjs +22 -0
- package/dist/helpers/define-schema.cjs.map +1 -0
- package/dist/helpers/define-schema.d.cts +28 -0
- package/dist/helpers/define-schema.d.mts +28 -0
- package/dist/helpers/define-schema.mjs +21 -0
- package/dist/helpers/define-schema.mjs.map +1 -0
- package/dist/helpers/schema-type.d.cts +21 -17
- package/dist/helpers/schema-type.d.mts +21 -17
- package/dist/index.cjs +10 -47
- package/dist/index.d.cts +13 -20
- package/dist/index.d.mts +13 -20
- package/dist/index.mjs +8 -15
- package/dist/utils/is-record.cjs +10 -0
- package/dist/utils/is-record.cjs.map +1 -0
- package/dist/utils/is-record.mjs +9 -0
- package/dist/utils/is-record.mjs.map +1 -0
- package/dist/validators/create-story-validator.cjs +37 -0
- package/dist/validators/create-story-validator.cjs.map +1 -0
- package/dist/validators/create-story-validator.d.cts +18 -0
- package/dist/validators/create-story-validator.d.mts +18 -0
- package/dist/validators/create-story-validator.mjs +37 -0
- package/dist/validators/create-story-validator.mjs.map +1 -0
- package/dist/validators/internal-schemas.cjs +1 -0
- package/dist/validators/internal-schemas.mjs +3 -0
- package/dist/validators/shapes.cjs +12 -0
- package/dist/validators/shapes.cjs.map +1 -0
- package/dist/validators/shapes.d.cts +71 -0
- package/dist/validators/shapes.d.mts +71 -0
- package/dist/validators/shapes.mjs +12 -0
- package/dist/validators/shapes.mjs.map +1 -0
- package/dist/validators/types.d.cts +25 -0
- package/dist/validators/types.d.mts +25 -0
- package/dist/validators/validate-schema.cjs +145 -0
- package/dist/validators/validate-schema.cjs.map +1 -0
- package/dist/validators/validate-schema.d.cts +19 -0
- package/dist/validators/validate-schema.d.mts +19 -0
- package/dist/validators/validate-schema.mjs +145 -0
- package/dist/validators/validate-schema.mjs.map +1 -0
- package/dist/validators/validate-story.cjs +285 -0
- package/dist/validators/validate-story.cjs.map +1 -0
- package/dist/validators/validate-story.d.cts +17 -0
- package/dist/validators/validate-story.d.mts +17 -0
- package/dist/validators/validate-story.mjs +284 -0
- package/dist/validators/validate-story.mjs.map +1 -0
- package/package.json +17 -2
- package/dist/generated/mapi/types.gen.d.cts +0 -1272
- package/dist/generated/mapi/types.gen.d.mts +0 -1272
- package/dist/helpers/create-story-helpers.cjs +0 -42
- package/dist/helpers/create-story-helpers.cjs.map +0 -1
- package/dist/helpers/create-story-helpers.d.cts +0 -50
- package/dist/helpers/create-story-helpers.d.mts +0 -50
- package/dist/helpers/create-story-helpers.mjs +0 -42
- package/dist/helpers/create-story-helpers.mjs.map +0 -1
- package/dist/helpers/define-asset-folder.cjs +0 -46
- package/dist/helpers/define-asset-folder.cjs.map +0 -1
- package/dist/helpers/define-asset-folder.d.cts +0 -33
- package/dist/helpers/define-asset-folder.d.mts +0 -33
- package/dist/helpers/define-asset-folder.mjs +0 -43
- package/dist/helpers/define-asset-folder.mjs.map +0 -1
- package/dist/helpers/define-asset.cjs +0 -60
- package/dist/helpers/define-asset.cjs.map +0 -1
- package/dist/helpers/define-asset.d.cts +0 -32
- package/dist/helpers/define-asset.d.mts +0 -32
- package/dist/helpers/define-asset.mjs +0 -57
- package/dist/helpers/define-asset.mjs.map +0 -1
- package/dist/helpers/define-block-folder.cjs +0 -44
- package/dist/helpers/define-block-folder.cjs.map +0 -1
- package/dist/helpers/define-block-folder.d.cts +0 -34
- package/dist/helpers/define-block-folder.d.mts +0 -34
- package/dist/helpers/define-block-folder.mjs +0 -41
- package/dist/helpers/define-block-folder.mjs.map +0 -1
- package/dist/helpers/define-datasource-entry.cjs +0 -47
- package/dist/helpers/define-datasource-entry.cjs.map +0 -1
- package/dist/helpers/define-datasource-entry.d.cts +0 -49
- package/dist/helpers/define-datasource-entry.d.mts +0 -49
- package/dist/helpers/define-datasource-entry.mjs +0 -43
- package/dist/helpers/define-datasource-entry.mjs.map +0 -1
- package/dist/helpers/define-internal-tag.cjs +0 -41
- package/dist/helpers/define-internal-tag.cjs.map +0 -1
- package/dist/helpers/define-internal-tag.d.cts +0 -34
- package/dist/helpers/define-internal-tag.d.mts +0 -34
- package/dist/helpers/define-internal-tag.mjs +0 -38
- package/dist/helpers/define-internal-tag.mjs.map +0 -1
- package/dist/helpers/define-link.cjs +0 -23
- package/dist/helpers/define-link.cjs.map +0 -1
- package/dist/helpers/define-link.d.cts +0 -32
- package/dist/helpers/define-link.d.mts +0 -32
- package/dist/helpers/define-link.mjs +0 -22
- package/dist/helpers/define-link.mjs.map +0 -1
- package/dist/helpers/define-preset.cjs +0 -44
- package/dist/helpers/define-preset.cjs.map +0 -1
- package/dist/helpers/define-preset.d.cts +0 -35
- package/dist/helpers/define-preset.d.mts +0 -35
- package/dist/helpers/define-preset.mjs +0 -41
- package/dist/helpers/define-preset.mjs.map +0 -1
- package/dist/helpers/define-space.cjs +0 -47
- package/dist/helpers/define-space.cjs.map +0 -1
- package/dist/helpers/define-space.d.cts +0 -31
- package/dist/helpers/define-space.d.mts +0 -31
- package/dist/helpers/define-space.mjs +0 -44
- package/dist/helpers/define-space.mjs.map +0 -1
- package/dist/helpers/define-story.cjs +0 -122
- package/dist/helpers/define-story.cjs.map +0 -1
- package/dist/helpers/define-story.d.cts +0 -135
- package/dist/helpers/define-story.d.mts +0 -135
- package/dist/helpers/define-story.mjs +0 -118
- package/dist/helpers/define-story.mjs.map +0 -1
- package/dist/helpers/define-tag.cjs +0 -13
- package/dist/helpers/define-tag.cjs.map +0 -1
- package/dist/helpers/define-tag.d.cts +0 -23
- package/dist/helpers/define-tag.d.mts +0 -23
- package/dist/helpers/define-tag.mjs +0 -12
- package/dist/helpers/define-tag.mjs.map +0 -1
- package/dist/helpers/define-user.cjs +0 -50
- package/dist/helpers/define-user.cjs.map +0 -1
- package/dist/helpers/define-user.d.cts +0 -26
- package/dist/helpers/define-user.d.mts +0 -26
- package/dist/helpers/define-user.mjs +0 -48
- package/dist/helpers/define-user.mjs.map +0 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SchemaLike } from "./shapes.mjs";
|
|
2
|
+
import { ValidationResult } from "./types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/validators/validate-schema.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Validates a schema definition without throwing. Checks structural identity
|
|
7
|
+
* (duplicate block names, field names, and datasource slugs) and cross-references
|
|
8
|
+
* (every `allow` entry resolves to a defined block; every field `datasource`
|
|
9
|
+
* resolves to a defined datasource; every `custom` field's `field_type`
|
|
10
|
+
* resolves to a registered field plugin).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const result = validateSchema({ blocks: { hero }, datasources: { colors } });
|
|
14
|
+
* if (!result.ok) console.error(result.issues);
|
|
15
|
+
*/
|
|
16
|
+
declare function validateSchema(schema: SchemaLike): ValidationResult;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { validateSchema };
|
|
19
|
+
//# sourceMappingURL=validate-schema.d.mts.map
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { isRecord } from "../utils/is-record.mjs";
|
|
2
|
+
import { toValues } from "./shapes.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/validators/validate-schema.ts
|
|
5
|
+
/**
|
|
6
|
+
* Validates a schema definition without throwing. Checks structural identity
|
|
7
|
+
* (duplicate block names, field names, and datasource slugs) and cross-references
|
|
8
|
+
* (every `allow` entry resolves to a defined block; every field `datasource`
|
|
9
|
+
* resolves to a defined datasource; every `custom` field's `field_type`
|
|
10
|
+
* resolves to a registered field plugin).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const result = validateSchema({ blocks: { hero }, datasources: { colors } });
|
|
14
|
+
* if (!result.ok) console.error(result.issues);
|
|
15
|
+
*/
|
|
16
|
+
function validateSchema(schema) {
|
|
17
|
+
const issues = [];
|
|
18
|
+
const blocks = toValues(schema.blocks);
|
|
19
|
+
const datasources = toValues(schema.datasources);
|
|
20
|
+
const fieldPlugins = toValues(schema.fieldPlugins);
|
|
21
|
+
const fieldPluginTypes = /* @__PURE__ */ new Set();
|
|
22
|
+
for (const plugin of fieldPlugins) {
|
|
23
|
+
const fieldType = plugin?.fieldType;
|
|
24
|
+
if (typeof fieldType === "string") fieldPluginTypes.add(fieldType);
|
|
25
|
+
}
|
|
26
|
+
const datasourceSlugs = /* @__PURE__ */ new Set();
|
|
27
|
+
for (const datasource of datasources) {
|
|
28
|
+
const slug = datasource?.slug;
|
|
29
|
+
if (typeof slug !== "string") continue;
|
|
30
|
+
if (datasourceSlugs.has(slug)) issues.push({
|
|
31
|
+
severity: "error",
|
|
32
|
+
code: "duplicate_datasource_slug",
|
|
33
|
+
path: ["datasources", slug],
|
|
34
|
+
entity: `datasource:${slug}`,
|
|
35
|
+
message: `Duplicate datasource slug "${slug}".`
|
|
36
|
+
});
|
|
37
|
+
datasourceSlugs.add(slug);
|
|
38
|
+
}
|
|
39
|
+
const blockNames = /* @__PURE__ */ new Set();
|
|
40
|
+
for (const block of blocks) {
|
|
41
|
+
const name = block?.name;
|
|
42
|
+
if (typeof name !== "string") continue;
|
|
43
|
+
if (blockNames.has(name)) issues.push({
|
|
44
|
+
severity: "error",
|
|
45
|
+
code: "duplicate_block_name",
|
|
46
|
+
path: ["blocks", name],
|
|
47
|
+
entity: `block:${name}`,
|
|
48
|
+
message: `Duplicate block name "${name}".`
|
|
49
|
+
});
|
|
50
|
+
blockNames.add(name);
|
|
51
|
+
}
|
|
52
|
+
for (const block of blocks) {
|
|
53
|
+
const blockName = typeof block?.name === "string" ? block.name : "";
|
|
54
|
+
const fieldNames = /* @__PURE__ */ new Set();
|
|
55
|
+
const fields = block?.fields ?? [];
|
|
56
|
+
for (let index = 0; index < fields.length; index++) {
|
|
57
|
+
const field = fields[index];
|
|
58
|
+
if (!isRecord(field)) {
|
|
59
|
+
issues.push({
|
|
60
|
+
severity: "error",
|
|
61
|
+
code: "invalid_field",
|
|
62
|
+
path: [
|
|
63
|
+
"blocks",
|
|
64
|
+
blockName,
|
|
65
|
+
index
|
|
66
|
+
],
|
|
67
|
+
entity: `block:${blockName}`,
|
|
68
|
+
message: `Field at index ${index} in block "${blockName}" is not an object.`
|
|
69
|
+
});
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const fieldName = field.name;
|
|
73
|
+
if (typeof fieldName === "string") {
|
|
74
|
+
if (fieldNames.has(fieldName)) issues.push({
|
|
75
|
+
severity: "error",
|
|
76
|
+
code: "duplicate_field_name",
|
|
77
|
+
path: [
|
|
78
|
+
"blocks",
|
|
79
|
+
blockName,
|
|
80
|
+
fieldName
|
|
81
|
+
],
|
|
82
|
+
entity: `block:${blockName}`,
|
|
83
|
+
message: `Duplicate field name "${fieldName}" in block "${blockName}".`
|
|
84
|
+
});
|
|
85
|
+
fieldNames.add(fieldName);
|
|
86
|
+
} else issues.push({
|
|
87
|
+
severity: "error",
|
|
88
|
+
code: "missing_field_name",
|
|
89
|
+
path: [
|
|
90
|
+
"blocks",
|
|
91
|
+
blockName,
|
|
92
|
+
index
|
|
93
|
+
],
|
|
94
|
+
entity: `block:${blockName}`,
|
|
95
|
+
message: `Field at index ${index} in block "${blockName}" is missing a string "name".`
|
|
96
|
+
});
|
|
97
|
+
for (const allowed of field.allow ?? []) if (typeof allowed === "string" && !blockNames.has(allowed)) issues.push({
|
|
98
|
+
severity: "error",
|
|
99
|
+
code: "unresolved_allow",
|
|
100
|
+
path: [
|
|
101
|
+
"blocks",
|
|
102
|
+
blockName,
|
|
103
|
+
fieldName ?? "",
|
|
104
|
+
"allow"
|
|
105
|
+
],
|
|
106
|
+
entity: `block:${blockName}`,
|
|
107
|
+
message: `Field "${fieldName}" allows unknown block "${allowed}".`
|
|
108
|
+
});
|
|
109
|
+
const datasource = field.datasource;
|
|
110
|
+
if (typeof datasource === "string" && !datasourceSlugs.has(datasource)) issues.push({
|
|
111
|
+
severity: "error",
|
|
112
|
+
code: "unresolved_datasource",
|
|
113
|
+
path: [
|
|
114
|
+
"blocks",
|
|
115
|
+
blockName,
|
|
116
|
+
fieldName ?? "",
|
|
117
|
+
"datasource"
|
|
118
|
+
],
|
|
119
|
+
entity: `block:${blockName}`,
|
|
120
|
+
message: `Field "${fieldName}" references unknown datasource "${datasource}".`
|
|
121
|
+
});
|
|
122
|
+
const fieldType = field.field_type;
|
|
123
|
+
if (field.type === "custom" && typeof fieldType === "string" && !fieldPluginTypes.has(fieldType)) issues.push({
|
|
124
|
+
severity: "error",
|
|
125
|
+
code: "unresolved_field_plugin",
|
|
126
|
+
path: [
|
|
127
|
+
"blocks",
|
|
128
|
+
blockName,
|
|
129
|
+
fieldName ?? "",
|
|
130
|
+
"field_type"
|
|
131
|
+
],
|
|
132
|
+
entity: `block:${blockName}`,
|
|
133
|
+
message: `Field "${fieldName}" references unregistered field plugin "${fieldType}".`
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
ok: issues.every((issue) => issue.severity !== "error"),
|
|
139
|
+
issues
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
//#endregion
|
|
144
|
+
export { validateSchema };
|
|
145
|
+
//# sourceMappingURL=validate-schema.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-schema.mjs","names":[],"sources":["../../src/validators/validate-schema.ts"],"sourcesContent":["import type { SchemaLike } from './shapes';\nimport type { ValidationIssue, ValidationResult } from './types';\nimport { isRecord, toValues } from './shapes';\n\n/**\n * Validates a schema definition without throwing. Checks structural identity\n * (duplicate block names, field names, and datasource slugs) and cross-references\n * (every `allow` entry resolves to a defined block; every field `datasource`\n * resolves to a defined datasource; every `custom` field's `field_type`\n * resolves to a registered field plugin).\n *\n * @example\n * const result = validateSchema({ blocks: { hero }, datasources: { colors } });\n * if (!result.ok) console.error(result.issues);\n */\nexport function validateSchema(schema: SchemaLike): ValidationResult {\n const issues: ValidationIssue[] = [];\n const blocks = toValues(schema.blocks);\n const datasources = toValues(schema.datasources);\n const fieldPlugins = toValues(schema.fieldPlugins);\n\n const fieldPluginTypes = new Set<string>();\n for (const plugin of fieldPlugins) {\n const fieldType = plugin?.fieldType;\n if (typeof fieldType === 'string') {\n fieldPluginTypes.add(fieldType);\n }\n }\n\n const datasourceSlugs = new Set<string>();\n for (const datasource of datasources) {\n const slug = datasource?.slug;\n if (typeof slug !== 'string') {\n continue;\n }\n if (datasourceSlugs.has(slug)) {\n issues.push({\n severity: 'error',\n code: 'duplicate_datasource_slug',\n path: ['datasources', slug],\n entity: `datasource:${slug}`,\n message: `Duplicate datasource slug \"${slug}\".`,\n });\n }\n datasourceSlugs.add(slug);\n }\n\n const blockNames = new Set<string>();\n for (const block of blocks) {\n const name = block?.name;\n if (typeof name !== 'string') {\n continue;\n }\n if (blockNames.has(name)) {\n issues.push({\n severity: 'error',\n code: 'duplicate_block_name',\n path: ['blocks', name],\n entity: `block:${name}`,\n message: `Duplicate block name \"${name}\".`,\n });\n }\n blockNames.add(name);\n }\n\n // Field-level checks run after the name/slug sets are fully populated so that\n // forward and circular references (resolved by name) validate correctly.\n for (const block of blocks) {\n const blockName = typeof block?.name === 'string' ? block.name : '';\n const fieldNames = new Set<string>();\n const fields = block?.fields ?? [];\n for (let index = 0; index < fields.length; index++) {\n const field = fields[index];\n // Flag malformed fields the wire mapper would otherwise silently drop:\n // a non-object entry, or one without a string `name` (its mapping key).\n if (!isRecord(field)) {\n issues.push({\n severity: 'error',\n code: 'invalid_field',\n path: ['blocks', blockName, index],\n entity: `block:${blockName}`,\n message: `Field at index ${index} in block \"${blockName}\" is not an object.`,\n });\n continue;\n }\n const fieldName = field.name;\n if (typeof fieldName === 'string') {\n if (fieldNames.has(fieldName)) {\n issues.push({\n severity: 'error',\n code: 'duplicate_field_name',\n path: ['blocks', blockName, fieldName],\n entity: `block:${blockName}`,\n message: `Duplicate field name \"${fieldName}\" in block \"${blockName}\".`,\n });\n }\n fieldNames.add(fieldName);\n }\n else {\n issues.push({\n severity: 'error',\n code: 'missing_field_name',\n path: ['blocks', blockName, index],\n entity: `block:${blockName}`,\n message: `Field at index ${index} in block \"${blockName}\" is missing a string \"name\".`,\n });\n }\n\n for (const allowed of field.allow ?? []) {\n if (typeof allowed === 'string' && !blockNames.has(allowed)) {\n issues.push({\n severity: 'error',\n code: 'unresolved_allow',\n path: ['blocks', blockName, fieldName ?? '', 'allow'],\n entity: `block:${blockName}`,\n message: `Field \"${fieldName}\" allows unknown block \"${allowed}\".`,\n });\n }\n }\n\n const datasource = field.datasource;\n if (typeof datasource === 'string' && !datasourceSlugs.has(datasource)) {\n issues.push({\n severity: 'error',\n code: 'unresolved_datasource',\n path: ['blocks', blockName, fieldName ?? '', 'datasource'],\n entity: `block:${blockName}`,\n message: `Field \"${fieldName}\" references unknown datasource \"${datasource}\".`,\n });\n }\n\n const fieldType = field.field_type;\n if (field.type === 'custom' && typeof fieldType === 'string' && !fieldPluginTypes.has(fieldType)) {\n issues.push({\n severity: 'error',\n code: 'unresolved_field_plugin',\n path: ['blocks', blockName, fieldName ?? '', 'field_type'],\n entity: `block:${blockName}`,\n message: `Field \"${fieldName}\" references unregistered field plugin \"${fieldType}\".`,\n });\n }\n }\n }\n\n return { ok: issues.every(issue => issue.severity !== 'error'), issues };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,SAAgB,eAAe,QAAsC;CAC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;;;AAKR,QAAO;EAAE,IAAI,OAAO,OAAM,UAAS,MAAM,aAAa,QAAQ;EAAE;EAAQ"}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
const require_is_record = require('../utils/is-record.cjs');
|
|
3
|
+
const require_shapes = require('./shapes.cjs');
|
|
4
|
+
const require_zod_gen = require('../generated/overlay/zod.gen.cjs');
|
|
5
|
+
require('./internal-schemas.cjs');
|
|
6
|
+
let zod = require("zod");
|
|
7
|
+
|
|
8
|
+
//#region src/validators/validate-story.ts
|
|
9
|
+
/** Field-content keys that are not user-defined fields. */
|
|
10
|
+
const RESERVED_KEYS = new Set([
|
|
11
|
+
"_uid",
|
|
12
|
+
"component",
|
|
13
|
+
"_editable"
|
|
14
|
+
]);
|
|
15
|
+
/**
|
|
16
|
+
* Relaxed plugin envelope used by the `custom` case. Mirrors the generated
|
|
17
|
+
* `zPluginFieldValue` but relaxes `_uid` from a UUID to a plain string, matching
|
|
18
|
+
* the CMS, which persists arbitrary `_uid` strings. Kept local so a codegen
|
|
19
|
+
* regenerate cannot revert it.
|
|
20
|
+
*/
|
|
21
|
+
const zPluginEnvelope = zod.z.object({
|
|
22
|
+
plugin: zod.z.string(),
|
|
23
|
+
_uid: zod.z.optional(zod.z.string())
|
|
24
|
+
});
|
|
25
|
+
/** Maps a Standard Schema validator to a {@link ValidationIssue} reporter at `path`. */
|
|
26
|
+
function checkValue(schema, value, path, entity, issues) {
|
|
27
|
+
const result = schema["~standard"].validate(value);
|
|
28
|
+
if (result instanceof Promise) {
|
|
29
|
+
issues.push({
|
|
30
|
+
severity: "error",
|
|
31
|
+
code: "async_validator_unsupported",
|
|
32
|
+
path,
|
|
33
|
+
entity,
|
|
34
|
+
message: "Field plugin validator is asynchronous; validateStory runs synchronously and cannot await it."
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (result.issues) for (const issue of result.issues) {
|
|
39
|
+
const issuePath = (issue.path ?? []).map((segment) => typeof segment === "object" && segment !== null ? String(segment.key) : segment);
|
|
40
|
+
issues.push({
|
|
41
|
+
severity: "error",
|
|
42
|
+
code: "invalid_value",
|
|
43
|
+
path: [...path, ...issuePath],
|
|
44
|
+
entity,
|
|
45
|
+
message: issue.message
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function validateFieldValue(field, value, blocksByName, fieldPluginsByType, path, entity, issues) {
|
|
50
|
+
switch (field.type) {
|
|
51
|
+
case "asset":
|
|
52
|
+
checkValue(require_zod_gen.zAssetFieldValue, value, path, entity, issues);
|
|
53
|
+
break;
|
|
54
|
+
case "multiasset":
|
|
55
|
+
if (!Array.isArray(value)) {
|
|
56
|
+
pushTypeIssue(value, "array", path, entity, issues);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
value.forEach((item, index) => checkValue(require_zod_gen.zAssetFieldValue, item, [...path, index], entity, issues));
|
|
60
|
+
checkCount(value.length, field.minimum_entries, field.maximum_entries, "asset(s)", path, entity, issues);
|
|
61
|
+
break;
|
|
62
|
+
case "multilink":
|
|
63
|
+
checkValue(require_zod_gen.zMultilinkFieldValue, value, path, entity, issues);
|
|
64
|
+
break;
|
|
65
|
+
case "table":
|
|
66
|
+
checkValue(require_zod_gen.zTableFieldValue, value, path, entity, issues);
|
|
67
|
+
break;
|
|
68
|
+
case "richtext":
|
|
69
|
+
checkValue(require_zod_gen.zRichtextFieldValue, value, path, entity, issues);
|
|
70
|
+
validateRichtextBloks(value, blocksByName, fieldPluginsByType, path, issues);
|
|
71
|
+
break;
|
|
72
|
+
case "custom": {
|
|
73
|
+
checkValue(zPluginEnvelope, value, path, entity, issues);
|
|
74
|
+
const validator = field.field_type ? fieldPluginsByType.get(field.field_type) : void 0;
|
|
75
|
+
if (validator && require_is_record.isRecord(value)) {
|
|
76
|
+
const { plugin: _plugin, _uid, ...pluginValue } = value;
|
|
77
|
+
checkValue(validator, pluginValue, path, entity, issues);
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case "bloks":
|
|
82
|
+
if (!Array.isArray(value)) {
|
|
83
|
+
pushTypeIssue(value, "array", path, entity, issues);
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
checkCount(value.length, field.minimum, field.maximum, "block(s)", path, entity, issues);
|
|
87
|
+
value.forEach((item, index) => {
|
|
88
|
+
if (field.allow && field.allow.length > 0 && require_is_record.isRecord(item) && typeof item.component === "string" && !field.allow.includes(item.component)) issues.push({
|
|
89
|
+
severity: "error",
|
|
90
|
+
code: "disallowed_component",
|
|
91
|
+
path: [
|
|
92
|
+
...path,
|
|
93
|
+
index,
|
|
94
|
+
"component"
|
|
95
|
+
],
|
|
96
|
+
entity,
|
|
97
|
+
message: `Component "${item.component}" is not allowed in field "${field.name}"; allowed: ${field.allow.join(", ")}.`
|
|
98
|
+
});
|
|
99
|
+
validateBlokContent(item, blocksByName, fieldPluginsByType, [...path, index], issues);
|
|
100
|
+
});
|
|
101
|
+
break;
|
|
102
|
+
case "text":
|
|
103
|
+
case "textarea":
|
|
104
|
+
case "markdown":
|
|
105
|
+
if (typeof value !== "string") {
|
|
106
|
+
pushTypeIssue(value, "string", path, entity, issues);
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
checkStringLength(field, value, path, entity, issues);
|
|
110
|
+
break;
|
|
111
|
+
case "option":
|
|
112
|
+
case "datetime":
|
|
113
|
+
if (typeof value !== "string") pushTypeIssue(value, "string", path, entity, issues);
|
|
114
|
+
break;
|
|
115
|
+
case "number":
|
|
116
|
+
if (typeof value !== "number") {
|
|
117
|
+
pushTypeIssue(value, "number", path, entity, issues);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
if (field.min_value != null && value < field.min_value) pushConstraint(`Value ${value} is below the minimum of ${field.min_value}.`, path, entity, issues);
|
|
121
|
+
if (field.max_value != null && value > field.max_value) pushConstraint(`Value ${value} exceeds the maximum of ${field.max_value}.`, path, entity, issues);
|
|
122
|
+
if (field.decimals != null && decimalPlaces(value) > field.decimals) pushConstraint(`Value ${value} has more than ${field.decimals} decimal place(s).`, path, entity, issues);
|
|
123
|
+
if (field.steps != null && field.steps > 0 && !isMultipleOf(value, field.steps, field.min_value ?? 0)) {
|
|
124
|
+
const base = field.min_value ?? 0;
|
|
125
|
+
pushConstraint(`Value ${value} is not a multiple of the step ${field.steps}${base ? ` (offset from ${base})` : ""}.`, path, entity, issues);
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
case "boolean":
|
|
129
|
+
if (typeof value !== "boolean") pushTypeIssue(value, "boolean", path, entity, issues);
|
|
130
|
+
break;
|
|
131
|
+
case "options":
|
|
132
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
133
|
+
pushTypeIssue(value, "string[]", path, entity, issues);
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
checkCount(value.length, toCount(field.min_options), toCount(field.max_options), "option(s)", path, entity, issues);
|
|
137
|
+
break;
|
|
138
|
+
case "section":
|
|
139
|
+
case "tab": break;
|
|
140
|
+
default:
|
|
141
|
+
field.type;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** Reports a constraint (bound/length/count) violation as an error issue. */
|
|
146
|
+
function pushConstraint(message, path, entity, issues) {
|
|
147
|
+
issues.push({
|
|
148
|
+
severity: "error",
|
|
149
|
+
code: "constraint_violation",
|
|
150
|
+
path,
|
|
151
|
+
entity,
|
|
152
|
+
message
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/** Checks an array length against optional inclusive `min`/`max` bounds. */
|
|
156
|
+
function checkCount(length, min, max, noun, path, entity, issues) {
|
|
157
|
+
if (min != null && length < min) pushConstraint(`Expected at least ${min} ${noun}, received ${length}.`, path, entity, issues);
|
|
158
|
+
if (max != null && length > max) pushConstraint(`Expected at most ${max} ${noun}, received ${length}.`, path, entity, issues);
|
|
159
|
+
}
|
|
160
|
+
/** Checks a string against optional `max_length`/`maxlength` and `minlength` bounds. */
|
|
161
|
+
function checkStringLength(field, value, path, entity, issues) {
|
|
162
|
+
const max = field.max_length ?? field.maxlength;
|
|
163
|
+
if (max != null && value.length > max) pushConstraint(`Text length ${value.length} exceeds the maximum of ${max}.`, path, entity, issues);
|
|
164
|
+
if (field.minlength != null && value.length < field.minlength) pushConstraint(`Text length ${value.length} is below the minimum of ${field.minlength}.`, path, entity, issues);
|
|
165
|
+
}
|
|
166
|
+
/** Counts a number's fractional digits, handling exponential notation (e.g. `1e-7` → 7). */
|
|
167
|
+
function decimalPlaces(value) {
|
|
168
|
+
if (!Number.isFinite(value)) return 0;
|
|
169
|
+
const [mantissa, exponent] = String(value).toLowerCase().split("e");
|
|
170
|
+
const fractionDigits = mantissa.includes(".") ? mantissa.split(".")[1].length : 0;
|
|
171
|
+
return exponent ? Math.max(0, fractionDigits - Number(exponent)) : fractionDigits;
|
|
172
|
+
}
|
|
173
|
+
/** Whether `value` lands on a `step` increment offset from `base`, with float tolerance. */
|
|
174
|
+
function isMultipleOf(value, step, base) {
|
|
175
|
+
const ratio = (value - base) / step;
|
|
176
|
+
const tolerance = 1e-9 * Math.max(1, Math.abs(ratio));
|
|
177
|
+
return Math.abs(ratio - Math.round(ratio)) <= tolerance;
|
|
178
|
+
}
|
|
179
|
+
/** Parses a numeric constraint stored as a string (e.g. `min_options`). Empty/non-numeric → undefined. */
|
|
180
|
+
function toCount(value) {
|
|
181
|
+
if (value == null || value === "") return;
|
|
182
|
+
const parsed = Number(value);
|
|
183
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
184
|
+
}
|
|
185
|
+
function pushTypeIssue(value, expected, path, entity, issues) {
|
|
186
|
+
issues.push({
|
|
187
|
+
severity: "error",
|
|
188
|
+
code: "invalid_value",
|
|
189
|
+
path,
|
|
190
|
+
entity,
|
|
191
|
+
message: `Expected ${expected}, received ${value === null ? "null" : typeof value}.`
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/** Walks richtext `content` nodes and validates embedded bloks (`type: 'blok'`). */
|
|
195
|
+
function validateRichtextBloks(value, blocksByName, fieldPluginsByType, path, issues) {
|
|
196
|
+
if (!require_is_record.isRecord(value) || !Array.isArray(value.content)) return;
|
|
197
|
+
value.content.forEach((node, index) => {
|
|
198
|
+
if (!require_is_record.isRecord(node)) return;
|
|
199
|
+
if (node.type === "blok" && require_is_record.isRecord(node.attrs) && Array.isArray(node.attrs.body)) node.attrs.body.forEach((blok, blokIndex) => validateBlokContent(blok, blocksByName, fieldPluginsByType, [
|
|
200
|
+
...path,
|
|
201
|
+
"content",
|
|
202
|
+
index,
|
|
203
|
+
"attrs",
|
|
204
|
+
"body",
|
|
205
|
+
blokIndex
|
|
206
|
+
], issues));
|
|
207
|
+
else if (Array.isArray(node.content)) validateRichtextBloks(node, blocksByName, fieldPluginsByType, [
|
|
208
|
+
...path,
|
|
209
|
+
"content",
|
|
210
|
+
index
|
|
211
|
+
], issues);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/** Validates a single blok content object against its component definition. */
|
|
215
|
+
function validateBlokContent(content, blocksByName, fieldPluginsByType, path, issues) {
|
|
216
|
+
if (!require_is_record.isRecord(content)) {
|
|
217
|
+
issues.push({
|
|
218
|
+
severity: "error",
|
|
219
|
+
code: "invalid_content",
|
|
220
|
+
path,
|
|
221
|
+
entity: "story",
|
|
222
|
+
message: "Expected a block content object."
|
|
223
|
+
});
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const component = content.component;
|
|
227
|
+
const block = typeof component === "string" ? blocksByName.get(component) : void 0;
|
|
228
|
+
if (!block) {
|
|
229
|
+
issues.push({
|
|
230
|
+
severity: "error",
|
|
231
|
+
code: "unknown_component",
|
|
232
|
+
path: [...path, "component"],
|
|
233
|
+
entity: "story",
|
|
234
|
+
message: `Unknown component "${String(component)}".`
|
|
235
|
+
});
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const entity = `block:${block.name}`;
|
|
239
|
+
const fields = block.fields ?? [];
|
|
240
|
+
const fieldsByName = new Map(fields.map((field) => [field.name, field]));
|
|
241
|
+
for (const key of Object.keys(content)) if (!RESERVED_KEYS.has(key) && !fieldsByName.has(key)) issues.push({
|
|
242
|
+
severity: "warning",
|
|
243
|
+
code: "unknown_field",
|
|
244
|
+
path: [...path, key],
|
|
245
|
+
entity,
|
|
246
|
+
message: `Unknown field "${key}" on component "${block.name}".`
|
|
247
|
+
});
|
|
248
|
+
for (const field of fields) {
|
|
249
|
+
const value = content[field.name];
|
|
250
|
+
if (value === void 0 || value === null) {
|
|
251
|
+
if (field.required) issues.push({
|
|
252
|
+
severity: "error",
|
|
253
|
+
code: "missing_required_field",
|
|
254
|
+
path: [...path, field.name],
|
|
255
|
+
entity,
|
|
256
|
+
message: `Missing required field "${field.name}" on component "${block.name}".`
|
|
257
|
+
});
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
validateFieldValue(field, value, blocksByName, fieldPluginsByType, [...path, field.name], entity, issues);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Validates a story's content against a schema without throwing. Reports unknown
|
|
265
|
+
* components (error), unknown fields (warning), missing required fields (error),
|
|
266
|
+
* and invalid field-value shapes (error), recursing into nested `bloks` and
|
|
267
|
+
* richtext-embedded bloks.
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* const result = validateStory(story, { blocks: { page, hero } });
|
|
271
|
+
*/
|
|
272
|
+
function validateStory(story, schema) {
|
|
273
|
+
const issues = [];
|
|
274
|
+
const blocksByName = new Map(require_shapes.toValues(schema.blocks).map((block) => [block.name, block]));
|
|
275
|
+
const fieldPluginsByType = new Map(require_shapes.toValues(schema.fieldPlugins).map((plugin) => [plugin.fieldType, plugin.value]));
|
|
276
|
+
validateBlokContent(require_is_record.isRecord(story) ? story.content : void 0, blocksByName, fieldPluginsByType, ["content"], issues);
|
|
277
|
+
return {
|
|
278
|
+
ok: issues.every((issue) => issue.severity !== "error"),
|
|
279
|
+
issues
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
//#endregion
|
|
284
|
+
exports.validateStory = validateStory;
|
|
285
|
+
//# sourceMappingURL=validate-story.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-story.cjs","names":["z","zAssetFieldValue","zMultilinkFieldValue","zTableFieldValue","zRichtextFieldValue","isRecord","toValues"],"sources":["../../src/validators/validate-story.ts"],"sourcesContent":["import { z } from 'zod';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { SchemaBlockLike, SchemaFieldLike, SchemaLike } from './shapes';\nimport type { ValidationIssue, ValidationResult } from './types';\nimport {\n zAssetFieldValue,\n zMultilinkFieldValue,\n zRichtextFieldValue,\n zTableFieldValue,\n} from './internal-schemas';\nimport { isRecord, toValues } from './shapes';\n\n/** Field-content keys that are not user-defined fields. */\nconst RESERVED_KEYS = new Set(['_uid', 'component', '_editable']);\n\n/**\n * Relaxed plugin envelope used by the `custom` case. Mirrors the generated\n * `zPluginFieldValue` but relaxes `_uid` from a UUID to a plain string, matching\n * the CMS, which persists arbitrary `_uid` strings. Kept local so a codegen\n * regenerate cannot revert it.\n */\nconst zPluginEnvelope = z.object({ plugin: z.string(), _uid: z.optional(z.string()) });\n\n/** Maps a Standard Schema validator to a {@link ValidationIssue} reporter at `path`. */\nfunction checkValue(\n schema: StandardSchemaV1,\n value: unknown,\n path: (string | number)[],\n entity: string,\n issues: ValidationIssue[],\n): void {\n const result = schema['~standard'].validate(value);\n // `validateStory` is synchronous. The internal Zod schemas never return a\n // thenable, but a registered field plugin may ship an async validator — which\n // cannot be awaited here. Surface it as an error instead of silently passing,\n // which would report a false `ok: true`.\n if (result instanceof Promise) {\n issues.push({\n severity: 'error',\n code: 'async_validator_unsupported',\n path,\n entity,\n message: 'Field plugin validator is asynchronous; validateStory runs synchronously and cannot await it.',\n });\n return;\n }\n if (result.issues) {\n for (const issue of result.issues) {\n const issuePath = (issue.path ?? []).map(segment =>\n (typeof segment === 'object' && segment !== null ? String(segment.key) : (segment as string | number)),\n );\n issues.push({\n severity: 'error',\n code: 'invalid_value',\n path: [...path, ...issuePath],\n entity,\n message: issue.message,\n });\n }\n }\n}\n\nfunction validateFieldValue(\n field: SchemaFieldLike,\n value: unknown,\n blocksByName: Map<string, SchemaBlockLike>,\n fieldPluginsByType: Map<string, StandardSchemaV1>,\n path: (string | number)[],\n entity: string,\n issues: ValidationIssue[],\n): void {\n switch (field.type) {\n case 'asset':\n checkValue(zAssetFieldValue, value, path, entity, issues);\n break;\n case 'multiasset':\n if (!Array.isArray(value)) {\n pushTypeIssue(value, 'array', path, entity, issues);\n break;\n }\n value.forEach((item, index) => checkValue(zAssetFieldValue, item, [...path, index], entity, issues));\n checkCount(value.length, field.minimum_entries, field.maximum_entries, 'asset(s)', path, entity, issues);\n break;\n case 'multilink':\n checkValue(zMultilinkFieldValue, value, path, entity, issues);\n break;\n case 'table':\n checkValue(zTableFieldValue, value, path, entity, issues);\n break;\n case 'richtext':\n checkValue(zRichtextFieldValue, value, path, entity, issues);\n validateRichtextBloks(value, blocksByName, fieldPluginsByType, path, issues);\n break;\n case 'custom': {\n checkValue(zPluginEnvelope, value, path, entity, issues);\n const validator = field.field_type ? fieldPluginsByType.get(field.field_type) : undefined;\n if (validator && isRecord(value)) {\n // Envelope keys sit alongside the plugin's own keys; strip them so the\n // plugin validator sees only its value. Sibling keys keep issue paths\n // accurate (an issue at ['color'] maps to [...path, 'color']).\n const { plugin: _plugin, _uid, ...pluginValue } = value;\n checkValue(validator, pluginValue, path, entity, issues);\n }\n break;\n }\n case 'bloks':\n if (!Array.isArray(value)) {\n pushTypeIssue(value, 'array', path, entity, issues);\n break;\n }\n checkCount(value.length, field.minimum, field.maximum, 'block(s)', path, entity, issues);\n value.forEach((item, index) => {\n if (\n field.allow && field.allow.length > 0\n && isRecord(item) && typeof item.component === 'string'\n && !field.allow.includes(item.component)\n ) {\n issues.push({\n severity: 'error',\n code: 'disallowed_component',\n path: [...path, index, 'component'],\n entity,\n message: `Component \"${item.component}\" is not allowed in field \"${field.name}\"; allowed: ${field.allow.join(', ')}.`,\n });\n }\n validateBlokContent(item, blocksByName, fieldPluginsByType, [...path, index], issues);\n });\n break;\n case 'text':\n case 'textarea':\n case 'markdown':\n if (typeof value !== 'string') {\n pushTypeIssue(value, 'string', path, entity, issues);\n break;\n }\n checkStringLength(field, value, path, entity, issues);\n break;\n case 'option':\n case 'datetime':\n if (typeof value !== 'string') {\n pushTypeIssue(value, 'string', path, entity, issues);\n }\n break;\n case 'number':\n if (typeof value !== 'number') {\n pushTypeIssue(value, 'number', path, entity, issues);\n break;\n }\n if (field.min_value != null && value < field.min_value) {\n pushConstraint(`Value ${value} is below the minimum of ${field.min_value}.`, path, entity, issues);\n }\n if (field.max_value != null && value > field.max_value) {\n pushConstraint(`Value ${value} exceeds the maximum of ${field.max_value}.`, path, entity, issues);\n }\n if (field.decimals != null && decimalPlaces(value) > field.decimals) {\n pushConstraint(`Value ${value} has more than ${field.decimals} decimal place(s).`, path, entity, issues);\n }\n if (field.steps != null && field.steps > 0 && !isMultipleOf(value, field.steps, field.min_value ?? 0)) {\n const base = field.min_value ?? 0;\n pushConstraint(\n `Value ${value} is not a multiple of the step ${field.steps}${base ? ` (offset from ${base})` : ''}.`,\n path,\n entity,\n issues,\n );\n }\n break;\n case 'boolean':\n if (typeof value !== 'boolean') {\n pushTypeIssue(value, 'boolean', path, entity, issues);\n }\n break;\n case 'options':\n if (!Array.isArray(value) || value.some(item => typeof item !== 'string')) {\n pushTypeIssue(value, 'string[]', path, entity, issues);\n break;\n }\n checkCount(value.length, toCount(field.min_options), toCount(field.max_options), 'option(s)', path, entity, issues);\n break;\n case 'section':\n case 'tab':\n // Layout-only field types carry no content value.\n break;\n default:\n // Exhaustiveness guard: when a new `FieldType` is added, this fails to\n // compile until the field type is handled (or explicitly skipped) above.\n field.type satisfies never;\n break;\n }\n}\n\n/** Reports a constraint (bound/length/count) violation as an error issue. */\nfunction pushConstraint(\n message: string,\n path: (string | number)[],\n entity: string,\n issues: ValidationIssue[],\n): void {\n issues.push({ severity: 'error', code: 'constraint_violation', path, entity, message });\n}\n\n/** Checks an array length against optional inclusive `min`/`max` bounds. */\nfunction checkCount(\n length: number,\n min: number | undefined,\n max: number | undefined,\n noun: string,\n path: (string | number)[],\n entity: string,\n issues: ValidationIssue[],\n): void {\n if (min != null && length < min) {\n pushConstraint(`Expected at least ${min} ${noun}, received ${length}.`, path, entity, issues);\n }\n if (max != null && length > max) {\n pushConstraint(`Expected at most ${max} ${noun}, received ${length}.`, path, entity, issues);\n }\n}\n\n/** Checks a string against optional `max_length`/`maxlength` and `minlength` bounds. */\nfunction checkStringLength(\n field: SchemaFieldLike,\n value: string,\n path: (string | number)[],\n entity: string,\n issues: ValidationIssue[],\n): void {\n const max = field.max_length ?? field.maxlength;\n if (max != null && value.length > max) {\n pushConstraint(`Text length ${value.length} exceeds the maximum of ${max}.`, path, entity, issues);\n }\n if (field.minlength != null && value.length < field.minlength) {\n pushConstraint(`Text length ${value.length} is below the minimum of ${field.minlength}.`, path, entity, issues);\n }\n}\n\n/** Counts a number's fractional digits, handling exponential notation (e.g. `1e-7` → 7). */\nfunction decimalPlaces(value: number): number {\n if (!Number.isFinite(value)) {\n return 0;\n }\n const text = String(value).toLowerCase();\n const [mantissa, exponent] = text.split('e');\n const fractionDigits = mantissa.includes('.') ? mantissa.split('.')[1].length : 0;\n // A negative exponent (e.g. `1e-7`) adds that many fractional digits.\n return exponent ? Math.max(0, fractionDigits - Number(exponent)) : fractionDigits;\n}\n\n/** Whether `value` lands on a `step` increment offset from `base`, with float tolerance. */\nfunction isMultipleOf(value: number, step: number, base: number): boolean {\n const ratio = (value - base) / step;\n const tolerance = 1e-9 * Math.max(1, Math.abs(ratio));\n return Math.abs(ratio - Math.round(ratio)) <= tolerance;\n}\n\n/** Parses a numeric constraint stored as a string (e.g. `min_options`). Empty/non-numeric → undefined. */\nfunction toCount(value: string | undefined): number | undefined {\n if (value == null || value === '') {\n return undefined;\n }\n const parsed = Number(value);\n return Number.isFinite(parsed) ? parsed : undefined;\n}\n\nfunction pushTypeIssue(\n value: unknown,\n expected: string,\n path: (string | number)[],\n entity: string,\n issues: ValidationIssue[],\n): void {\n issues.push({\n severity: 'error',\n code: 'invalid_value',\n path,\n entity,\n message: `Expected ${expected}, received ${value === null ? 'null' : typeof value}.`,\n });\n}\n\n/** Walks richtext `content` nodes and validates embedded bloks (`type: 'blok'`). */\nfunction validateRichtextBloks(\n value: unknown,\n blocksByName: Map<string, SchemaBlockLike>,\n fieldPluginsByType: Map<string, StandardSchemaV1>,\n path: (string | number)[],\n issues: ValidationIssue[],\n): void {\n if (!isRecord(value) || !Array.isArray(value.content)) {\n return;\n }\n value.content.forEach((node, index) => {\n if (!isRecord(node)) {\n return;\n }\n if (node.type === 'blok' && isRecord(node.attrs) && Array.isArray(node.attrs.body)) {\n node.attrs.body.forEach((blok, blokIndex) =>\n validateBlokContent(blok, blocksByName, fieldPluginsByType, [...path, 'content', index, 'attrs', 'body', blokIndex], issues),\n );\n }\n else if (Array.isArray(node.content)) {\n // Recurse into nested marks/nodes that may themselves embed bloks.\n validateRichtextBloks(node, blocksByName, fieldPluginsByType, [...path, 'content', index], issues);\n }\n });\n}\n\n/** Validates a single blok content object against its component definition. */\nfunction validateBlokContent(\n content: unknown,\n blocksByName: Map<string, SchemaBlockLike>,\n fieldPluginsByType: Map<string, StandardSchemaV1>,\n path: (string | number)[],\n issues: ValidationIssue[],\n): void {\n if (!isRecord(content)) {\n issues.push({\n severity: 'error',\n code: 'invalid_content',\n path,\n entity: 'story',\n message: 'Expected a block content object.',\n });\n return;\n }\n\n const component = content.component;\n const block = typeof component === 'string' ? blocksByName.get(component) : undefined;\n if (!block) {\n issues.push({\n severity: 'error',\n code: 'unknown_component',\n path: [...path, 'component'],\n entity: 'story',\n message: `Unknown component \"${String(component)}\".`,\n });\n return;\n }\n\n const entity = `block:${block.name}`;\n const fields = block.fields ?? [];\n const fieldsByName = new Map(fields.map(field => [field.name, field]));\n\n for (const key of Object.keys(content)) {\n if (!RESERVED_KEYS.has(key) && !fieldsByName.has(key)) {\n issues.push({\n severity: 'warning',\n code: 'unknown_field',\n path: [...path, key],\n entity,\n message: `Unknown field \"${key}\" on component \"${block.name}\".`,\n });\n }\n }\n\n for (const field of fields) {\n const value = content[field.name];\n if (value === undefined || value === null) {\n if (field.required) {\n issues.push({\n severity: 'error',\n code: 'missing_required_field',\n path: [...path, field.name],\n entity,\n message: `Missing required field \"${field.name}\" on component \"${block.name}\".`,\n });\n }\n continue;\n }\n validateFieldValue(field, value, blocksByName, fieldPluginsByType, [...path, field.name], entity, issues);\n }\n}\n\n/**\n * Validates a story's content against a schema without throwing. Reports unknown\n * components (error), unknown fields (warning), missing required fields (error),\n * and invalid field-value shapes (error), recursing into nested `bloks` and\n * richtext-embedded bloks.\n *\n * @example\n * const result = validateStory(story, { blocks: { page, hero } });\n */\nexport function validateStory(story: unknown, schema: SchemaLike): ValidationResult {\n const issues: ValidationIssue[] = [];\n const blocksByName = new Map(toValues(schema.blocks).map(block => [block.name, block]));\n const fieldPluginsByType = new Map(\n toValues(schema.fieldPlugins).map(plugin => [plugin.fieldType, plugin.value]),\n );\n const content = isRecord(story) ? story.content : undefined;\n validateBlokContent(content, blocksByName, fieldPluginsByType, ['content'], issues);\n return { ok: issues.every(issue => issue.severity !== 'error'), issues };\n}\n"],"mappings":";;;;;;;;;AAaA,MAAM,gBAAgB,IAAI,IAAI;CAAC;CAAQ;CAAa;CAAY,CAAC;;;;;;;AAQjE,MAAM,kBAAkBA,MAAE,OAAO;CAAE,QAAQA,MAAE,QAAQ;CAAE,MAAMA,MAAE,SAASA,MAAE,QAAQ,CAAC;CAAE,CAAC;;AAGtF,SAAS,WACP,QACA,OACA,MACA,QACA,QACM;CACN,MAAM,SAAS,OAAO,aAAa,SAAS,MAAM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7D,CAAC;AAIN,MAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,QAAQ,QAAQ,MAAM;AAC5B,MAAI,UAAU,UAAa,UAAU,MAAM;AACzC,OAAI,MAAM,SACR,QAAO,KAAK;IACV,UAAU;IACV,MAAM;IACN,MAAM,CAAC,GAAG,MAAM,MAAM,KAAK;IAC3B;IACA,SAAS,2BAA2B,MAAM,KAAK,kBAAkB,MAAM,KAAK;IAC7E,CAAC;AAEJ;;AAEF,qBAAmB,OAAO,OAAO,cAAc,oBAAoB,CAAC,GAAG,MAAM,MAAM,KAAK,EAAE,QAAQ,OAAO;;;;;;;;;;;;AAa7G,SAAgB,cAAc,OAAgB,QAAsC;CAClF,MAAM,SAA4B,EAAE;CACpC,MAAM,eAAe,IAAI,IAAIC,wBAAS,OAAO,OAAO,CAAC,KAAI,UAAS,CAAC,MAAM,MAAM,MAAM,CAAC,CAAC;CACvF,MAAM,qBAAqB,IAAI,IAC7BA,wBAAS,OAAO,aAAa,CAAC,KAAI,WAAU,CAAC,OAAO,WAAW,OAAO,MAAM,CAAC,CAC9E;AAED,qBADgBD,2BAAS,MAAM,GAAG,MAAM,UAAU,QACrB,cAAc,oBAAoB,CAAC,UAAU,EAAE,OAAO;AACnF,QAAO;EAAE,IAAI,OAAO,OAAM,UAAS,MAAM,aAAa,QAAQ;EAAE;EAAQ"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SchemaLike } from "./shapes.cjs";
|
|
2
|
+
import { ValidationResult } from "./types.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/validators/validate-story.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Validates a story's content against a schema without throwing. Reports unknown
|
|
7
|
+
* components (error), unknown fields (warning), missing required fields (error),
|
|
8
|
+
* and invalid field-value shapes (error), recursing into nested `bloks` and
|
|
9
|
+
* richtext-embedded bloks.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const result = validateStory(story, { blocks: { page, hero } });
|
|
13
|
+
*/
|
|
14
|
+
declare function validateStory(story: unknown, schema: SchemaLike): ValidationResult;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { validateStory };
|
|
17
|
+
//# sourceMappingURL=validate-story.d.cts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SchemaLike } from "./shapes.mjs";
|
|
2
|
+
import { ValidationResult } from "./types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/validators/validate-story.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Validates a story's content against a schema without throwing. Reports unknown
|
|
7
|
+
* components (error), unknown fields (warning), missing required fields (error),
|
|
8
|
+
* and invalid field-value shapes (error), recursing into nested `bloks` and
|
|
9
|
+
* richtext-embedded bloks.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const result = validateStory(story, { blocks: { page, hero } });
|
|
13
|
+
*/
|
|
14
|
+
declare function validateStory(story: unknown, schema: SchemaLike): ValidationResult;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { validateStory };
|
|
17
|
+
//# sourceMappingURL=validate-story.d.mts.map
|