storyblok 4.23.0 → 4.23.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/index.d.mts +47 -47
- package/dist/index.mjs +108 -37
- package/dist/index.mjs.map +1 -1
- package/dist/storyblok-types.d.mts +47 -47
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -2,11 +2,11 @@ import "dotenv/config";
|
|
|
2
2
|
import { Command } from "commander";
|
|
3
3
|
import "@storyblok/management-api-client";
|
|
4
4
|
//#region src/generated/overlay/types.gen.d.ts
|
|
5
|
-
type RichTextDoc =
|
|
5
|
+
type RichTextDoc = RichTextFieldValue2;
|
|
6
6
|
/**
|
|
7
7
|
* Rich text field type - structured rich text document (ProseMirror/Tiptap format)
|
|
8
8
|
*/
|
|
9
|
-
type
|
|
9
|
+
type RichTextFieldValue2 = {
|
|
10
10
|
/**
|
|
11
11
|
* Root node type — always "doc"
|
|
12
12
|
*/
|
|
@@ -19,12 +19,12 @@ type RichTextFieldValueRoot = {
|
|
|
19
19
|
/**
|
|
20
20
|
* A rich text document node
|
|
21
21
|
*/
|
|
22
|
-
type RichTextFieldValueRichTextNode =
|
|
22
|
+
type RichTextFieldValueRichTextNode = ParagraphNode | TextNode | HeadingNode | BlockquoteNode | BulletListNode | OrderedListNode | ListItemNode | CodeBlockNode | HardBreakNode | HorizontalRuleNode | ImageNode | EmojiNode | TableNode | TableRowNode | TableCellNode | TableHeaderNode | BlockNode;
|
|
23
23
|
/**
|
|
24
24
|
* Inline formatting mark applied to a text node
|
|
25
25
|
*/
|
|
26
|
-
type RichTextFieldValueRichTextMark =
|
|
27
|
-
type
|
|
26
|
+
type RichTextFieldValueRichTextMark = LinkMark | BoldMark | ItalicMark | StrikeMark | UnderlineMark | CodeMark | SuperscriptMark | SubscriptMark | HighlightMark | TextStyleMark | AnchorMark | StyledMark;
|
|
27
|
+
type ParagraphNode = {
|
|
28
28
|
type: 'paragraph';
|
|
29
29
|
attrs?: {
|
|
30
30
|
/**
|
|
@@ -39,7 +39,7 @@ type RichTextFieldValueParagraphNode = {
|
|
|
39
39
|
content?: Array<RichTextFieldValueRichTextNode>;
|
|
40
40
|
marks?: Array<RichTextFieldValueRichTextMark>;
|
|
41
41
|
};
|
|
42
|
-
type
|
|
42
|
+
type TextNode = {
|
|
43
43
|
type: 'text';
|
|
44
44
|
/**
|
|
45
45
|
* The text content
|
|
@@ -47,7 +47,7 @@ type RichTextFieldValueTextNode = {
|
|
|
47
47
|
text: string;
|
|
48
48
|
marks?: Array<RichTextFieldValueRichTextMark>;
|
|
49
49
|
};
|
|
50
|
-
type
|
|
50
|
+
type HeadingNode = {
|
|
51
51
|
type: 'heading';
|
|
52
52
|
attrs: {
|
|
53
53
|
/**
|
|
@@ -66,7 +66,7 @@ type RichTextFieldValueHeadingNode = {
|
|
|
66
66
|
content?: Array<RichTextFieldValueRichTextNode>;
|
|
67
67
|
marks?: Array<RichTextFieldValueRichTextMark>;
|
|
68
68
|
};
|
|
69
|
-
type
|
|
69
|
+
type BlockquoteNode = {
|
|
70
70
|
type: 'blockquote';
|
|
71
71
|
attrs?: {
|
|
72
72
|
/**
|
|
@@ -77,12 +77,12 @@ type RichTextFieldValueBlockquoteNode = {
|
|
|
77
77
|
content?: Array<RichTextFieldValueRichTextNode>;
|
|
78
78
|
marks?: Array<RichTextFieldValueRichTextMark>;
|
|
79
79
|
};
|
|
80
|
-
type
|
|
80
|
+
type BulletListNode = {
|
|
81
81
|
type: 'bullet_list';
|
|
82
82
|
content?: Array<RichTextFieldValueRichTextNode>;
|
|
83
83
|
marks?: Array<RichTextFieldValueRichTextMark>;
|
|
84
84
|
};
|
|
85
|
-
type
|
|
85
|
+
type OrderedListNode = {
|
|
86
86
|
type: 'ordered_list';
|
|
87
87
|
attrs: {
|
|
88
88
|
/**
|
|
@@ -93,7 +93,7 @@ type RichTextFieldValueOrderedListNode = {
|
|
|
93
93
|
content?: Array<RichTextFieldValueRichTextNode>;
|
|
94
94
|
marks?: Array<RichTextFieldValueRichTextMark>;
|
|
95
95
|
};
|
|
96
|
-
type
|
|
96
|
+
type ListItemNode = {
|
|
97
97
|
type: 'list_item';
|
|
98
98
|
attrs?: {
|
|
99
99
|
/**
|
|
@@ -104,7 +104,7 @@ type RichTextFieldValueListItemNode = {
|
|
|
104
104
|
content?: Array<RichTextFieldValueRichTextNode>;
|
|
105
105
|
marks?: Array<RichTextFieldValueRichTextMark>;
|
|
106
106
|
};
|
|
107
|
-
type
|
|
107
|
+
type CodeBlockNode = {
|
|
108
108
|
type: 'code_block';
|
|
109
109
|
attrs: {
|
|
110
110
|
/**
|
|
@@ -119,13 +119,13 @@ type RichTextFieldValueCodeBlockNode = {
|
|
|
119
119
|
content?: Array<RichTextFieldValueRichTextNode>;
|
|
120
120
|
marks?: Array<RichTextFieldValueRichTextMark>;
|
|
121
121
|
};
|
|
122
|
-
type
|
|
122
|
+
type HardBreakNode = {
|
|
123
123
|
type: 'hard_break';
|
|
124
124
|
};
|
|
125
|
-
type
|
|
125
|
+
type HorizontalRuleNode = {
|
|
126
126
|
type: 'horizontal_rule';
|
|
127
127
|
};
|
|
128
|
-
type
|
|
128
|
+
type ImageNode = {
|
|
129
129
|
type: 'image';
|
|
130
130
|
attrs: {
|
|
131
131
|
/**
|
|
@@ -151,11 +151,11 @@ type RichTextFieldValueImageNode = {
|
|
|
151
151
|
title?: string | null;
|
|
152
152
|
source?: string | null;
|
|
153
153
|
copyright?: string | null;
|
|
154
|
-
[key: string]: string | null |
|
|
154
|
+
[key: string]: string | null | undefined;
|
|
155
155
|
} | null;
|
|
156
156
|
};
|
|
157
157
|
};
|
|
158
|
-
type
|
|
158
|
+
type EmojiNode = {
|
|
159
159
|
type: 'emoji';
|
|
160
160
|
attrs: {
|
|
161
161
|
/**
|
|
@@ -172,15 +172,15 @@ type RichTextFieldValueEmojiNode = {
|
|
|
172
172
|
fallbackImage: string;
|
|
173
173
|
};
|
|
174
174
|
};
|
|
175
|
-
type
|
|
175
|
+
type TableNode = {
|
|
176
176
|
type: 'table';
|
|
177
177
|
content?: Array<RichTextFieldValueRichTextNode>;
|
|
178
178
|
};
|
|
179
|
-
type
|
|
179
|
+
type TableRowNode = {
|
|
180
180
|
type: 'tableRow';
|
|
181
181
|
content?: Array<RichTextFieldValueRichTextNode>;
|
|
182
182
|
};
|
|
183
|
-
type
|
|
183
|
+
type TableCellNode = {
|
|
184
184
|
type: 'tableCell';
|
|
185
185
|
attrs: {
|
|
186
186
|
colspan?: number;
|
|
@@ -193,7 +193,7 @@ type RichTextFieldValueTableCellNode = {
|
|
|
193
193
|
};
|
|
194
194
|
content?: Array<RichTextFieldValueRichTextNode>;
|
|
195
195
|
};
|
|
196
|
-
type
|
|
196
|
+
type TableHeaderNode = {
|
|
197
197
|
type: 'tableHeader';
|
|
198
198
|
attrs: {
|
|
199
199
|
colspan?: number;
|
|
@@ -205,7 +205,7 @@ type RichTextFieldValueTableHeaderNode = {
|
|
|
205
205
|
};
|
|
206
206
|
content?: Array<RichTextFieldValueRichTextNode>;
|
|
207
207
|
};
|
|
208
|
-
type
|
|
208
|
+
type BlockNode = {
|
|
209
209
|
type: 'blok';
|
|
210
210
|
attrs: {
|
|
211
211
|
/**
|
|
@@ -215,10 +215,10 @@ type RichTextFieldValueBlockNode = {
|
|
|
215
215
|
/**
|
|
216
216
|
* Array of embedded component instances
|
|
217
217
|
*/
|
|
218
|
-
body: Array<
|
|
218
|
+
body: Array<BlockContentInput2> | null;
|
|
219
219
|
};
|
|
220
220
|
};
|
|
221
|
-
type
|
|
221
|
+
type LinkMark = {
|
|
222
222
|
type: 'link';
|
|
223
223
|
/**
|
|
224
224
|
* Link attributes
|
|
@@ -252,28 +252,28 @@ type RichTextFieldValueLinkMark = {
|
|
|
252
252
|
} | null;
|
|
253
253
|
};
|
|
254
254
|
};
|
|
255
|
-
type
|
|
255
|
+
type BoldMark = {
|
|
256
256
|
type: 'bold';
|
|
257
257
|
};
|
|
258
|
-
type
|
|
258
|
+
type ItalicMark = {
|
|
259
259
|
type: 'italic';
|
|
260
260
|
};
|
|
261
|
-
type
|
|
261
|
+
type StrikeMark = {
|
|
262
262
|
type: 'strike';
|
|
263
263
|
};
|
|
264
|
-
type
|
|
264
|
+
type UnderlineMark = {
|
|
265
265
|
type: 'underline';
|
|
266
266
|
};
|
|
267
|
-
type
|
|
267
|
+
type CodeMark = {
|
|
268
268
|
type: 'code';
|
|
269
269
|
};
|
|
270
|
-
type
|
|
270
|
+
type SuperscriptMark = {
|
|
271
271
|
type: 'superscript';
|
|
272
272
|
};
|
|
273
|
-
type
|
|
273
|
+
type SubscriptMark = {
|
|
274
274
|
type: 'subscript';
|
|
275
275
|
};
|
|
276
|
-
type
|
|
276
|
+
type HighlightMark = {
|
|
277
277
|
type: 'highlight';
|
|
278
278
|
attrs: {
|
|
279
279
|
/**
|
|
@@ -282,7 +282,7 @@ type RichTextFieldValueHighlightMark = {
|
|
|
282
282
|
color: string | null;
|
|
283
283
|
};
|
|
284
284
|
};
|
|
285
|
-
type
|
|
285
|
+
type TextStyleMark = {
|
|
286
286
|
type: 'textStyle';
|
|
287
287
|
attrs: {
|
|
288
288
|
color?: string | null;
|
|
@@ -290,7 +290,7 @@ type RichTextFieldValueTextStyleMark = {
|
|
|
290
290
|
class?: string | null;
|
|
291
291
|
};
|
|
292
292
|
};
|
|
293
|
-
type
|
|
293
|
+
type AnchorMark = {
|
|
294
294
|
type: 'anchor';
|
|
295
295
|
attrs: {
|
|
296
296
|
/**
|
|
@@ -299,7 +299,7 @@ type RichTextFieldValueAnchorMark = {
|
|
|
299
299
|
id: string;
|
|
300
300
|
};
|
|
301
301
|
};
|
|
302
|
-
type
|
|
302
|
+
type StyledMark = {
|
|
303
303
|
type: 'styled';
|
|
304
304
|
attrs: {
|
|
305
305
|
/**
|
|
@@ -311,7 +311,7 @@ type RichTextFieldValueStyledMark = {
|
|
|
311
311
|
/**
|
|
312
312
|
* Content object for creating or updating a component instance. Contains a component technical name and dynamic fields whose values depend on the component's schema field types. The _uid is optional — Storyblok will auto-generate one if not provided.
|
|
313
313
|
*/
|
|
314
|
-
type
|
|
314
|
+
type BlockContentInput2 = {
|
|
315
315
|
/**
|
|
316
316
|
* Unique identifier for this component instance (auto-generated when omitted)
|
|
317
317
|
*/
|
|
@@ -324,12 +324,12 @@ type BlockContentInputRoot = {
|
|
|
324
324
|
* Storyblok editor markup string for inline editing (present in draft/preview mode)
|
|
325
325
|
*/
|
|
326
326
|
_editable?: string;
|
|
327
|
-
[key: string]: null | string | number | boolean | Array<string |
|
|
327
|
+
[key: string]: null | string | number | boolean | Array<string | AssetFieldValue2 | BlockContentInput2> | AssetFieldValue2 | MultilinkFieldValue2 | TableFieldValue2 | RichTextFieldValue2 | PluginFieldValue2 | undefined;
|
|
328
328
|
};
|
|
329
329
|
/**
|
|
330
330
|
* Asset field type - single asset (image, video, audio, or document)
|
|
331
331
|
*/
|
|
332
|
-
type
|
|
332
|
+
type AssetFieldValue2 = {
|
|
333
333
|
/**
|
|
334
334
|
* Identifies this as an asset field
|
|
335
335
|
*/
|
|
@@ -380,11 +380,11 @@ type AssetFieldValueRoot = {
|
|
|
380
380
|
/**
|
|
381
381
|
* Multilink field type - link to internal stories, external URLs, emails, or assets.
|
|
382
382
|
*/
|
|
383
|
-
type
|
|
383
|
+
type MultilinkFieldValue2 = StoryLink | UrlLink | EmailLink | AssetLink;
|
|
384
384
|
/**
|
|
385
385
|
* Table field type - structured table data
|
|
386
386
|
*/
|
|
387
|
-
type
|
|
387
|
+
type TableFieldValue2 = {
|
|
388
388
|
/**
|
|
389
389
|
* Table header cells
|
|
390
390
|
*/
|
|
@@ -418,7 +418,7 @@ type TableFieldValueRoot = {
|
|
|
418
418
|
/**
|
|
419
419
|
* Plugin/Custom field type - field plugin with custom structure
|
|
420
420
|
*/
|
|
421
|
-
type
|
|
421
|
+
type PluginFieldValue2 = {
|
|
422
422
|
/**
|
|
423
423
|
* Technical name of the field plugin
|
|
424
424
|
*/
|
|
@@ -427,12 +427,12 @@ type PluginFieldValueRoot = {
|
|
|
427
427
|
* Unique identifier for this plugin field instance
|
|
428
428
|
*/
|
|
429
429
|
_uid?: string;
|
|
430
|
-
[key: string]: unknown
|
|
430
|
+
[key: string]: unknown;
|
|
431
431
|
};
|
|
432
432
|
/**
|
|
433
433
|
* Link to an internal Storyblok story.
|
|
434
434
|
*/
|
|
435
|
-
type
|
|
435
|
+
type StoryLink = SharedLink & {
|
|
436
436
|
linktype: 'story';
|
|
437
437
|
/**
|
|
438
438
|
* Anchor/fragment identifier for the story link
|
|
@@ -452,7 +452,7 @@ type MultilinkFieldValueStoryLink = MultilinkFieldValueSharedLink & {
|
|
|
452
452
|
/**
|
|
453
453
|
* Link to an external URL.
|
|
454
454
|
*/
|
|
455
|
-
type
|
|
455
|
+
type UrlLink = SharedLink & {
|
|
456
456
|
linktype: 'url';
|
|
457
457
|
/**
|
|
458
458
|
* Link relationship attribute
|
|
@@ -468,7 +468,7 @@ type MultilinkFieldValueUrlLink = MultilinkFieldValueSharedLink & {
|
|
|
468
468
|
/**
|
|
469
469
|
* Link to an email address.
|
|
470
470
|
*/
|
|
471
|
-
type
|
|
471
|
+
type EmailLink = SharedLink & {
|
|
472
472
|
linktype: 'email';
|
|
473
473
|
/**
|
|
474
474
|
* Email address
|
|
@@ -478,10 +478,10 @@ type MultilinkFieldValueEmailLink = MultilinkFieldValueSharedLink & {
|
|
|
478
478
|
/**
|
|
479
479
|
* Link to a Storyblok asset.
|
|
480
480
|
*/
|
|
481
|
-
type
|
|
481
|
+
type AssetLink = SharedLink & {
|
|
482
482
|
linktype: 'asset';
|
|
483
483
|
};
|
|
484
|
-
type
|
|
484
|
+
type SharedLink = {
|
|
485
485
|
/**
|
|
486
486
|
* Identifies this as a multilink field
|
|
487
487
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -5002,6 +5002,69 @@ const STORYBLOK_PROPERTY_TYPES = {
|
|
|
5002
5002
|
};
|
|
5003
5003
|
const isStoryblokPropertyType = (type) => typeof type === "string" && Object.hasOwn(STORYBLOK_PROPERTY_TYPES, type);
|
|
5004
5004
|
//#endregion
|
|
5005
|
+
//#region src/utils/user-module.ts
|
|
5006
|
+
/**
|
|
5007
|
+
* A missing file is a bad invocation, so it surfaces as a {@link CommandError}
|
|
5008
|
+
* instead of Node's resolution failure with its `Require stack:` dump. The file
|
|
5009
|
+
* is checked before the import rather than by inspecting the failure: a module
|
|
5010
|
+
* the file itself imports and cannot resolve raises `Cannot find module
|
|
5011
|
+
* '<specifier>'` with a `Require stack:` naming the file, so matching the path
|
|
5012
|
+
* against the message reported a missing dependency as a missing file.
|
|
5013
|
+
*/
|
|
5014
|
+
async function resolveExistingFile(path, fileDescription) {
|
|
5015
|
+
const absolutePath = resolve(path);
|
|
5016
|
+
try {
|
|
5017
|
+
await stat(absolutePath);
|
|
5018
|
+
} catch {
|
|
5019
|
+
throw new CommandError(`${fileDescription} not found at "${path}".`);
|
|
5020
|
+
}
|
|
5021
|
+
return absolutePath;
|
|
5022
|
+
}
|
|
5023
|
+
/**
|
|
5024
|
+
* The path is resolved to an absolute path first, so jiti's base URL does not
|
|
5025
|
+
* affect which file is loaded; `tsconfigPaths` does read a tsconfig relative to
|
|
5026
|
+
* that base URL, but jiti evaluates each module through a child instance rooted
|
|
5027
|
+
* at the module itself, so the aliases applied to the file come from the user's
|
|
5028
|
+
* project and not from the CLI's own tsconfig.
|
|
5029
|
+
*/
|
|
5030
|
+
async function createUserModuleJiti(options) {
|
|
5031
|
+
const { createJiti } = await import("jiti");
|
|
5032
|
+
return createJiti(import.meta.url, {
|
|
5033
|
+
interopDefault: options.interopDefault,
|
|
5034
|
+
tsconfigPaths: process.env.JITI_TSCONFIG_PATHS !== "false"
|
|
5035
|
+
});
|
|
5036
|
+
}
|
|
5037
|
+
/**
|
|
5038
|
+
* Loads a user-provided `.ts`, `.js`, `.mjs`, `.cjs`, or `.json` file and
|
|
5039
|
+
* returns all of its exports.
|
|
5040
|
+
*/
|
|
5041
|
+
async function importUserModule(path, fileDescription) {
|
|
5042
|
+
const absolutePath = await resolveExistingFile(path, fileDescription);
|
|
5043
|
+
return await (await createUserModuleJiti({ interopDefault: true })).import(absolutePath);
|
|
5044
|
+
}
|
|
5045
|
+
/**
|
|
5046
|
+
* Loads a user-provided `.ts`, `.js`, `.mjs`, `.cjs`, or `.json` file and
|
|
5047
|
+
* returns its default export (`module.exports` for CommonJS, the parsed content
|
|
5048
|
+
* for JSON), or `undefined` when it has none. Named exports are never used in
|
|
5049
|
+
* its place, so a file without a default export can be reported as such.
|
|
5050
|
+
*/
|
|
5051
|
+
async function importUserModuleDefault(path, fileDescription) {
|
|
5052
|
+
const absolutePath = await resolveExistingFile(path, fileDescription);
|
|
5053
|
+
if (extname(absolutePath) === ".json") return parseJsonFile(absolutePath, path, fileDescription);
|
|
5054
|
+
const userModule = await (await createUserModuleJiti({ interopDefault: false })).import(absolutePath);
|
|
5055
|
+
return await (isEsModuleNamespace(userModule) ? userModule.default : userModule);
|
|
5056
|
+
}
|
|
5057
|
+
async function parseJsonFile(absolutePath, path, fileDescription) {
|
|
5058
|
+
try {
|
|
5059
|
+
return JSON.parse(await readFile(absolutePath, "utf8"));
|
|
5060
|
+
} catch (error) {
|
|
5061
|
+
throw new CommandError(`${fileDescription} at "${path}" is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
5062
|
+
}
|
|
5063
|
+
}
|
|
5064
|
+
function isEsModuleNamespace(value) {
|
|
5065
|
+
return Object.prototype.toString.call(value) === "[object Module]" || isRecord(value) && value.__esModule === true;
|
|
5066
|
+
}
|
|
5067
|
+
//#endregion
|
|
5005
5068
|
//#region src/commands/types/generate/utils.ts
|
|
5006
5069
|
/**
|
|
5007
5070
|
* Explicit type-name overrides for Storyblok field types where the generated
|
|
@@ -5258,7 +5321,7 @@ const getComponentPropertiesTypeAnnotations = async (component, options, spaceDa
|
|
|
5258
5321
|
if (isLayoutFieldType(propertyType)) return acc;
|
|
5259
5322
|
const propertyTypeAnnotation = { [key]: getPropertyTypeAnnotation(schema, options.typePrefix, options.typeSuffix) };
|
|
5260
5323
|
if (propertyType === "custom" && customFieldsParser) {
|
|
5261
|
-
const customField =
|
|
5324
|
+
const customField = customFieldsParser(key, schema);
|
|
5262
5325
|
return {
|
|
5263
5326
|
...acc,
|
|
5264
5327
|
...customField
|
|
@@ -5299,17 +5362,18 @@ const getComponentPropertiesTypeAnnotations = async (component, options, spaceDa
|
|
|
5299
5362
|
};
|
|
5300
5363
|
}, Promise.resolve({}));
|
|
5301
5364
|
};
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
}
|
|
5365
|
+
function isCustomFieldsParser(value) {
|
|
5366
|
+
return typeof value === "function";
|
|
5367
|
+
}
|
|
5368
|
+
async function loadCustomFieldsParser(path) {
|
|
5369
|
+
const parser = await importUserModuleDefault(path, "Custom fields parser file");
|
|
5370
|
+
if (!isCustomFieldsParser(parser)) throw new CommandError(`The custom fields parser file at "${path}" must default-export a function.`);
|
|
5371
|
+
return parser;
|
|
5372
|
+
}
|
|
5310
5373
|
async function loadCompilerOptions(path) {
|
|
5311
|
-
|
|
5312
|
-
|
|
5374
|
+
const compilerOptions = await importUserModuleDefault(path, "Compiler options file");
|
|
5375
|
+
if (!isRecord(compilerOptions)) throw new CommandError(`The compiler options file at "${path}" must default-export an options object.`);
|
|
5376
|
+
return compilerOptions;
|
|
5313
5377
|
}
|
|
5314
5378
|
const generateTypes = async (spaceData, options = { strict: false }) => {
|
|
5315
5379
|
try {
|
|
@@ -10055,36 +10119,13 @@ function collectSchemaExports(moduleExports) {
|
|
|
10055
10119
|
};
|
|
10056
10120
|
}
|
|
10057
10121
|
/**
|
|
10058
|
-
* Loads a TypeScript schema entry file
|
|
10059
|
-
* exports. The path is resolved to an absolute path first, so jiti's base URL
|
|
10060
|
-
* does not affect which file is loaded; `tsconfigPaths` does read a tsconfig
|
|
10061
|
-
* relative to that base URL, but jiti evaluates each module through a child
|
|
10062
|
-
* instance rooted at the module itself, so the aliases applied to the entry
|
|
10063
|
-
* file come from the user's project and not from the CLI's own tsconfig.
|
|
10122
|
+
* Loads a TypeScript schema entry file and returns its raw module exports.
|
|
10064
10123
|
* Shared by `schema push` (wire mapping) and the validate commands (DSL
|
|
10065
|
-
* shape).
|
|
10124
|
+
* shape). Throws when the file is missing or fails to evaluate — fatal for
|
|
10066
10125
|
* the callers.
|
|
10067
|
-
*
|
|
10068
|
-
* A missing entry file is a bad invocation, so it surfaces as a
|
|
10069
|
-
* {@link CommandError} instead of Node's resolution failure with its `Require
|
|
10070
|
-
* stack:` dump. The file is checked before the import rather than by inspecting
|
|
10071
|
-
* the failure: a module the entry file itself imports and cannot resolve raises
|
|
10072
|
-
* `Cannot find module '<specifier>'` with a `Require stack:` naming the entry
|
|
10073
|
-
* file, so matching the entry path against the message reported a missing
|
|
10074
|
-
* dependency as a missing entry file.
|
|
10075
10126
|
*/
|
|
10076
10127
|
async function loadSchemaModule(entryPath) {
|
|
10077
|
-
|
|
10078
|
-
try {
|
|
10079
|
-
await stat(entryAbs);
|
|
10080
|
-
} catch {
|
|
10081
|
-
throw new CommandError(`Schema entry file not found at "${entryPath}".`);
|
|
10082
|
-
}
|
|
10083
|
-
const { createJiti } = await import("jiti");
|
|
10084
|
-
return await createJiti(import.meta.url, {
|
|
10085
|
-
interopDefault: true,
|
|
10086
|
-
tsconfigPaths: process.env.JITI_TSCONFIG_PATHS !== "false"
|
|
10087
|
-
}).import(entryAbs);
|
|
10128
|
+
return await importUserModule(entryPath, "Schema entry file");
|
|
10088
10129
|
}
|
|
10089
10130
|
//#endregion
|
|
10090
10131
|
//#region src/lib/validation/adapter.ts
|
|
@@ -11672,6 +11713,35 @@ function assertUniqueIdentities(components, datasources) {
|
|
|
11672
11713
|
collect("datasource slug", datasources.map((datasource) => datasource.slug));
|
|
11673
11714
|
if (collisions.length > 0) throw new CommandError(`Duplicate schema definitions: ${collisions.join(", ")}. Each block name, datasource name, and datasource slug must be unique; rename or remove the duplicate before pushing.`);
|
|
11674
11715
|
}
|
|
11716
|
+
/**
|
|
11717
|
+
* Fails the load when a block declares a field the wire form cannot carry.
|
|
11718
|
+
*
|
|
11719
|
+
* A field is keyed on the wire by its `name` and identified by its `type`, so
|
|
11720
|
+
* one missing either is unpushable: the mapping drops a nameless field outright,
|
|
11721
|
+
* and a typeless one reaches the Management API as an empty object, which the
|
|
11722
|
+
* API discards on the way in. Either way the field is gone from the pushed
|
|
11723
|
+
* component and nothing reports it. `defineField` rejects both at compile time;
|
|
11724
|
+
* this catches a schema authored in plain JavaScript or assembled at runtime.
|
|
11725
|
+
* `schema validate` reports the same fields as `invalid_field` /
|
|
11726
|
+
* `missing_field_name` / `missing_field_type`.
|
|
11727
|
+
*/
|
|
11728
|
+
function assertPushableFields(components) {
|
|
11729
|
+
const problems = [];
|
|
11730
|
+
for (const component of components) {
|
|
11731
|
+
const blockLabel = typeof component.name === "string" ? `block "${component.name}"` : "an unnamed block";
|
|
11732
|
+
(Array.isArray(component.fields) ? component.fields : []).forEach((field, index) => {
|
|
11733
|
+
if (!isRecord(field)) {
|
|
11734
|
+
problems.push(`the entry at index ${index} in ${blockLabel} is not an object`);
|
|
11735
|
+
return;
|
|
11736
|
+
}
|
|
11737
|
+
const hasName = typeof field.name === "string" && field.name !== "";
|
|
11738
|
+
const fieldLabel = hasName ? `field "${String(field.name)}" in ${blockLabel}` : `the field at index ${index} in ${blockLabel}`;
|
|
11739
|
+
if (!hasName) problems.push(`${fieldLabel} has no "name"`);
|
|
11740
|
+
if (typeof field.type !== "string" || field.type.trim() === "") problems.push(`${fieldLabel} has no "type"`);
|
|
11741
|
+
});
|
|
11742
|
+
}
|
|
11743
|
+
if (problems.length > 0) throw new CommandError(`Schema fields that cannot be pushed: ${problems.join(", ")}. Run \`storyblok schema validate\` for the full report.`);
|
|
11744
|
+
}
|
|
11675
11745
|
const toArray = (value) => Array.isArray(value) ? value : [];
|
|
11676
11746
|
/**
|
|
11677
11747
|
* Classifies a module's exports into wire components, datasources, and folders,
|
|
@@ -11682,6 +11752,7 @@ const toArray = (value) => Array.isArray(value) ? value : [];
|
|
|
11682
11752
|
function classifyExports(moduleExports) {
|
|
11683
11753
|
const { components, datasources, folders } = collectSchemaExports(moduleExports);
|
|
11684
11754
|
assertUniqueIdentities(components, datasources);
|
|
11755
|
+
assertPushableFields(components);
|
|
11685
11756
|
const registered = folders.map((folder) => folder.path);
|
|
11686
11757
|
const derived = [];
|
|
11687
11758
|
for (const component of components) {
|