@storyblok/schema 1.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -0
- package/dist/generated/mapi-types.d.cts +732 -0
- package/dist/generated/mapi-types.d.mts +732 -0
- package/dist/generated/types.d.cts +155 -0
- package/dist/generated/types.d.mts +155 -0
- package/dist/helpers/create-story-helpers.cjs +42 -0
- package/dist/helpers/create-story-helpers.cjs.map +1 -0
- package/dist/helpers/create-story-helpers.d.cts +48 -0
- package/dist/helpers/create-story-helpers.d.mts +48 -0
- package/dist/helpers/create-story-helpers.mjs +42 -0
- package/dist/helpers/create-story-helpers.mjs.map +1 -0
- package/dist/helpers/define-asset-folder.cjs +40 -0
- package/dist/helpers/define-asset-folder.cjs.map +1 -0
- package/dist/helpers/define-asset-folder.d.cts +33 -0
- package/dist/helpers/define-asset-folder.d.mts +33 -0
- package/dist/helpers/define-asset-folder.mjs +37 -0
- package/dist/helpers/define-asset-folder.mjs.map +1 -0
- package/dist/helpers/define-asset.cjs +43 -0
- package/dist/helpers/define-asset.cjs.map +1 -0
- package/dist/helpers/define-asset.d.cts +32 -0
- package/dist/helpers/define-asset.d.mts +32 -0
- package/dist/helpers/define-asset.mjs +40 -0
- package/dist/helpers/define-asset.mjs.map +1 -0
- package/dist/helpers/define-block-folder.cjs +40 -0
- package/dist/helpers/define-block-folder.cjs.map +1 -0
- package/dist/helpers/define-block-folder.d.cts +34 -0
- package/dist/helpers/define-block-folder.d.mts +34 -0
- package/dist/helpers/define-block-folder.mjs +37 -0
- package/dist/helpers/define-block-folder.mjs.map +1 -0
- package/dist/helpers/define-block.cjs +51 -0
- package/dist/helpers/define-block.cjs.map +1 -0
- package/dist/helpers/define-block.d.cts +90 -0
- package/dist/helpers/define-block.d.mts +90 -0
- package/dist/helpers/define-block.mjs +48 -0
- package/dist/helpers/define-block.mjs.map +1 -0
- package/dist/helpers/define-datasource-entry.cjs +41 -0
- package/dist/helpers/define-datasource-entry.cjs.map +1 -0
- package/dist/helpers/define-datasource-entry.d.cts +48 -0
- package/dist/helpers/define-datasource-entry.d.mts +48 -0
- package/dist/helpers/define-datasource-entry.mjs +37 -0
- package/dist/helpers/define-datasource-entry.mjs.map +1 -0
- package/dist/helpers/define-datasource.cjs +33 -0
- package/dist/helpers/define-datasource.cjs.map +1 -0
- package/dist/helpers/define-datasource.d.cts +41 -0
- package/dist/helpers/define-datasource.d.mts +41 -0
- package/dist/helpers/define-datasource.mjs +30 -0
- package/dist/helpers/define-datasource.mjs.map +1 -0
- package/dist/helpers/define-field.cjs +17 -0
- package/dist/helpers/define-field.cjs.map +1 -0
- package/dist/helpers/define-field.d.cts +100 -0
- package/dist/helpers/define-field.d.mts +100 -0
- package/dist/helpers/define-field.mjs +16 -0
- package/dist/helpers/define-field.mjs.map +1 -0
- package/dist/helpers/define-internal-tag.cjs +37 -0
- package/dist/helpers/define-internal-tag.cjs.map +1 -0
- package/dist/helpers/define-internal-tag.d.cts +34 -0
- package/dist/helpers/define-internal-tag.d.mts +34 -0
- package/dist/helpers/define-internal-tag.mjs +34 -0
- package/dist/helpers/define-internal-tag.mjs.map +1 -0
- package/dist/helpers/define-link.cjs +22 -0
- package/dist/helpers/define-link.cjs.map +1 -0
- package/dist/helpers/define-link.d.cts +31 -0
- package/dist/helpers/define-link.d.mts +31 -0
- package/dist/helpers/define-link.mjs +21 -0
- package/dist/helpers/define-link.mjs.map +1 -0
- package/dist/helpers/define-preset.cjs +37 -0
- package/dist/helpers/define-preset.cjs.map +1 -0
- package/dist/helpers/define-preset.d.cts +35 -0
- package/dist/helpers/define-preset.d.mts +35 -0
- package/dist/helpers/define-preset.mjs +34 -0
- package/dist/helpers/define-preset.mjs.map +1 -0
- package/dist/helpers/define-space.cjs +34 -0
- package/dist/helpers/define-space.cjs.map +1 -0
- package/dist/helpers/define-space.d.cts +31 -0
- package/dist/helpers/define-space.d.mts +31 -0
- package/dist/helpers/define-space.mjs +31 -0
- package/dist/helpers/define-space.mjs.map +1 -0
- package/dist/helpers/define-story.cjs +94 -0
- package/dist/helpers/define-story.cjs.map +1 -0
- package/dist/helpers/define-story.d.cts +127 -0
- package/dist/helpers/define-story.d.mts +127 -0
- package/dist/helpers/define-story.mjs +90 -0
- package/dist/helpers/define-story.mjs.map +1 -0
- package/dist/helpers/define-tag.cjs +13 -0
- package/dist/helpers/define-tag.cjs.map +1 -0
- package/dist/helpers/define-tag.d.cts +23 -0
- package/dist/helpers/define-tag.d.mts +23 -0
- package/dist/helpers/define-tag.mjs +12 -0
- package/dist/helpers/define-tag.mjs.map +1 -0
- package/dist/helpers/define-user.cjs +32 -0
- package/dist/helpers/define-user.cjs.map +1 -0
- package/dist/helpers/define-user.d.cts +26 -0
- package/dist/helpers/define-user.d.mts +26 -0
- package/dist/helpers/define-user.mjs +30 -0
- package/dist/helpers/define-user.mjs.map +1 -0
- package/dist/helpers/schema-type.d.cts +40 -0
- package/dist/helpers/schema-type.d.mts +40 -0
- package/dist/index.cjs +55 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.mts +19 -0
- package/dist/index.mjs +17 -0
- package/dist/utils/prettify.d.cts +9 -0
- package/dist/utils/prettify.d.mts +9 -0
- package/package.json +85 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/helpers/define-story.ts
|
|
3
|
+
const CAPI_STORY_DEFAULTS = {
|
|
4
|
+
id: 1,
|
|
5
|
+
uuid: "",
|
|
6
|
+
created_at: "",
|
|
7
|
+
updated_at: "",
|
|
8
|
+
published_at: null,
|
|
9
|
+
first_published_at: null,
|
|
10
|
+
full_slug: "",
|
|
11
|
+
group_id: "",
|
|
12
|
+
alternates: [],
|
|
13
|
+
default_full_slug: null,
|
|
14
|
+
release_id: null,
|
|
15
|
+
lang: "default",
|
|
16
|
+
slug: "",
|
|
17
|
+
parent_id: 0,
|
|
18
|
+
path: null,
|
|
19
|
+
is_startpage: false,
|
|
20
|
+
sort_by_date: null,
|
|
21
|
+
tag_list: [],
|
|
22
|
+
meta_data: null,
|
|
23
|
+
translated_slugs: null,
|
|
24
|
+
position: 0
|
|
25
|
+
};
|
|
26
|
+
const MAPI_STORY_DEFAULTS = {
|
|
27
|
+
id: 1,
|
|
28
|
+
uuid: "",
|
|
29
|
+
created_at: "",
|
|
30
|
+
updated_at: "",
|
|
31
|
+
published_at: null,
|
|
32
|
+
first_published_at: null,
|
|
33
|
+
full_slug: "",
|
|
34
|
+
group_id: "",
|
|
35
|
+
alternates: [],
|
|
36
|
+
slug: "",
|
|
37
|
+
parent_id: 0,
|
|
38
|
+
path: null,
|
|
39
|
+
is_startpage: false,
|
|
40
|
+
sort_by_date: null,
|
|
41
|
+
tag_list: [],
|
|
42
|
+
meta_data: null,
|
|
43
|
+
translated_slugs: null,
|
|
44
|
+
position: 0
|
|
45
|
+
};
|
|
46
|
+
function defineStory(component, story) {
|
|
47
|
+
const { content, ...rest } = story;
|
|
48
|
+
return {
|
|
49
|
+
...CAPI_STORY_DEFAULTS,
|
|
50
|
+
...rest,
|
|
51
|
+
content: {
|
|
52
|
+
...content,
|
|
53
|
+
component: component.name
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function defineMapiStory(component, story) {
|
|
58
|
+
const { content, ...rest } = story;
|
|
59
|
+
return {
|
|
60
|
+
...MAPI_STORY_DEFAULTS,
|
|
61
|
+
...rest,
|
|
62
|
+
content: {
|
|
63
|
+
...content,
|
|
64
|
+
component: component.name
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function defineStoryCreate(component, story) {
|
|
69
|
+
const { content, ...rest } = story;
|
|
70
|
+
return {
|
|
71
|
+
...rest,
|
|
72
|
+
content: {
|
|
73
|
+
...content,
|
|
74
|
+
component: component.name
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function defineStoryUpdate(component, story) {
|
|
79
|
+
const { content, ...rest } = story;
|
|
80
|
+
return {
|
|
81
|
+
...rest,
|
|
82
|
+
...content && { content: {
|
|
83
|
+
...content,
|
|
84
|
+
component: component.name
|
|
85
|
+
} }
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
exports.defineMapiStory = defineMapiStory;
|
|
91
|
+
exports.defineStory = defineStory;
|
|
92
|
+
exports.defineStoryCreate = defineStoryCreate;
|
|
93
|
+
exports.defineStoryUpdate = defineStoryUpdate;
|
|
94
|
+
//# sourceMappingURL=define-story.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-story.cjs","names":[],"sources":["../../src/helpers/define-story.ts"],"sourcesContent":["import type {\n Story as CapiStoryGenerated,\n StoryAlternate,\n StoryLocalizedPath,\n StoryTranslatedSlug,\n} from '../generated/types';\nimport type {\n Story as MapiStoryGenerated,\n StoryCreate as StoryCreateGenerated,\n StoryUpdate as StoryUpdateGenerated,\n} from '../generated/mapi-types';\nimport type { Block } from './define-block';\nimport type { BlockContent, BlockContentInput } from './define-field';\nimport type { Prettify } from '../utils/prettify';\n\nconst CAPI_STORY_DEFAULTS = {\n id: 1,\n uuid: '',\n created_at: '',\n updated_at: '',\n published_at: null,\n first_published_at: null,\n full_slug: '',\n group_id: '',\n alternates: [],\n default_full_slug: null,\n release_id: null,\n lang: 'default',\n slug: '',\n parent_id: 0,\n path: null,\n is_startpage: false,\n sort_by_date: null,\n tag_list: [],\n meta_data: null,\n translated_slugs: null,\n position: 0,\n};\n\nconst MAPI_STORY_DEFAULTS = {\n id: 1,\n uuid: '',\n created_at: '',\n updated_at: '',\n published_at: null,\n first_published_at: null,\n full_slug: '',\n group_id: '',\n alternates: [],\n slug: '',\n parent_id: 0,\n path: null,\n is_startpage: false,\n sort_by_date: null,\n tag_list: [],\n meta_data: null,\n translated_slugs: null,\n position: 0,\n};\n\nexport type { StoryAlternate, StoryLocalizedPath, StoryTranslatedSlug };\n\nexport type StoryComponent = Omit<Block, 'is_root'> & { is_root: true };\n\n// ---------------------------------------------------------------------------\n// CDN (CAPI) Story\n// ---------------------------------------------------------------------------\n\ntype CapiStoryWithSchemaContent<\n TBlock extends StoryComponent = StoryComponent,\n TBlocks = false,\n> = Omit<CapiStoryGenerated, 'content'> & { content: BlockContent<TBlock, TBlocks> };\n\n/**\n * A Storyblok CDN (CAPI) story.\n */\nexport type Story<\n TBlockOrBlocks extends StoryComponent | Block = StoryComponent,\n TBlocks = false,\n> = Prettify<\n [TBlockOrBlocks] extends [StoryComponent]\n ? CapiStoryWithSchemaContent<TBlockOrBlocks, TBlocks>\n : TBlocks extends false\n ? CapiStoryWithSchemaContent<Extract<TBlockOrBlocks, StoryComponent>, TBlockOrBlocks>\n : never\n>;\n\ntype CapiStoryOptional = keyof typeof CAPI_STORY_DEFAULTS;\n\ntype CapiStoryInput<\n TBlock extends StoryComponent = StoryComponent,\n TBlocks extends Block = never,\n> = Prettify<\n Omit<Story<TBlock, TBlocks>, CapiStoryOptional | 'content'>\n & Partial<Pick<Story<TBlock, TBlocks>, CapiStoryOptional>>\n & {\n content: Omit<BlockContentInput<TBlock, TBlocks>, 'component'>;\n }\n>;\n\n/**\n * Returns a full CDN {@link Story} with all fields populated.\n *\n * @example\n * const myStory = defineStory(pageComponent, {\n * name: 'Home',\n * content: { headline: 'Hello World!' },\n * });\n */\nexport function defineStory<\n TBlock extends StoryComponent,\n TBlocks extends Block,\n>(component: TBlock, story: CapiStoryInput<TBlock, TBlocks>): Story<TBlock, TBlocks>;\n\nexport function defineStory(component: StoryComponent, story: any) {\n const { content, ...rest } = story;\n return {\n ...CAPI_STORY_DEFAULTS,\n ...rest,\n content: { ...content, component: component.name },\n };\n}\n\n// ---------------------------------------------------------------------------\n// MAPI Story helpers\n// ---------------------------------------------------------------------------\n\ntype MapiStoryWithSchemaContent<\n TStory extends MapiStoryGenerated | StoryCreateGenerated | StoryUpdateGenerated,\n TBlock extends StoryComponent = StoryComponent,\n TBlocks = false,\n> = StoryComponent extends TBlock\n ? TStory\n : Omit<TStory, 'content'> & {\n content: TStory extends StoryCreateGenerated | StoryUpdateGenerated\n ? BlockContentInput<TBlock, TBlocks>\n : BlockContent<TBlock, TBlocks>;\n };\n\ntype MakeMapiStory<\n TStory extends MapiStoryGenerated | StoryCreateGenerated | StoryUpdateGenerated,\n TBlockOrBlocks extends StoryComponent | Block = StoryComponent,\n TBlocks = false,\n> = Prettify<\n [TBlockOrBlocks] extends [StoryComponent]\n ? MapiStoryWithSchemaContent<TStory, TBlockOrBlocks, TBlocks>\n : TBlocks extends false\n ? MapiStoryWithSchemaContent<TStory, Extract<TBlockOrBlocks, StoryComponent>, TBlockOrBlocks>\n : never\n>;\n\n/**\n * A Storyblok MAPI story.\n */\nexport type MapiStory<\n TBlockOrBlocks extends StoryComponent | Block = StoryComponent,\n TBlocks = false,\n> = MakeMapiStory<MapiStoryGenerated, TBlockOrBlocks, TBlocks>;\n\n/** Payload for creating a story via the MAPI. */\nexport type StoryCreate<\n TBlockOrBlocks extends StoryComponent | Block = StoryComponent,\n TBlocks = false,\n> = MakeMapiStory<StoryCreateGenerated, TBlockOrBlocks, TBlocks>;\n\n/** Payload for updating a story via the MAPI. */\nexport type StoryUpdate<\n TBlockOrBlocks extends StoryComponent | Block = StoryComponent,\n TBlocks = false,\n> = MakeMapiStory<StoryUpdateGenerated, TBlockOrBlocks, TBlocks>;\n\ntype MapiStoryOptional = keyof typeof MAPI_STORY_DEFAULTS;\n\ntype MakeMapiStoryInput<\n TStory extends MapiStory | StoryCreate | StoryUpdate,\n TBlock extends StoryComponent = StoryComponent,\n TBlocks extends Block = never,\n> = Prettify<\n Omit<TStory, MapiStoryOptional | 'content'>\n & Partial<Pick<TStory, Extract<MapiStoryOptional, keyof TStory>>>\n & {\n content: Omit<BlockContentInput<TBlock, TBlocks>, 'component'>;\n }\n>;\n\ntype MapiStoryInput<\n TBlock extends StoryComponent = StoryComponent,\n TBlocks extends Block = never,\n> = MakeMapiStoryInput<MapiStory, TBlock, TBlocks>;\n\ntype StoryCreateInput<\n TBlock extends StoryComponent = StoryComponent,\n TBlocks extends Block = never,\n> = MakeMapiStoryInput<StoryCreate, TBlock, TBlocks>;\n\ntype StoryUpdateInput<\n TBlock extends StoryComponent = StoryComponent,\n TBlocks extends Block = never,\n> = Prettify<\n Omit<MakeMapiStoryInput<StoryUpdate, TBlock, TBlocks>, 'content'>\n & {\n content: Partial<Omit<BlockContentInput<TBlock, TBlocks>, 'component'>>;\n }\n>;\n\n/**\n * Returns a full MAPI {@link MapiStory} with all fields populated.\n *\n * @example\n * const myStory = defineMapiStory(pageComponent, {\n * name: 'My Page',\n * content: { headline: 'Hello World!' },\n * });\n */\nexport function defineMapiStory<\n const TBlock extends StoryComponent,\n const TBlocks extends Block = never,\n>(component: TBlock, story: MapiStoryInput<TBlock, TBlocks>): MapiStory<TBlock, TBlocks>;\n\nexport function defineMapiStory(component: StoryComponent, story: any) {\n const { content, ...rest } = story;\n return {\n ...MAPI_STORY_DEFAULTS,\n ...rest,\n content: { ...content, component: component.name },\n };\n}\n\n/**\n * Defines a story creation payload for the MAPI.\n *\n * @example\n * const payload = defineStoryCreate(pageComponent, {\n * name: 'My Page',\n * content: { headline: 'Hello World!' },\n * });\n */\nexport function defineStoryCreate<\n const TBlock extends StoryComponent,\n const TBlocks extends Block = never,\n>(component: TBlock, story: StoryCreateInput<TBlock, TBlocks>): StoryCreate<TBlock, TBlocks>;\n\nexport function defineStoryCreate(component: StoryComponent, story: any) {\n const { content, ...rest } = story;\n return {\n ...rest,\n content: { ...content, component: component.name },\n };\n}\n\n/**\n * Defines a story update payload for the MAPI.\n *\n * @example\n * const payload = defineStoryUpdate(pageComponent, {\n * content: { headline: 'Updated!' },\n * });\n */\nexport function defineStoryUpdate<\n const TBlock extends StoryComponent,\n const TBlocks extends Block = never,\n>(component: TBlock, story: StoryUpdateInput<TBlock, TBlocks>): StoryUpdate<TBlock, TBlocks>;\n\nexport function defineStoryUpdate(component: StoryComponent, story: any) {\n const { content, ...rest } = story;\n return {\n ...rest,\n ...(content && {\n content: { ...content, component: component.name },\n }),\n };\n}\n"],"mappings":";;AAeA,MAAM,sBAAsB;CAC1B,IAAI;CACJ,MAAM;CACN,YAAY;CACZ,YAAY;CACZ,cAAc;CACd,oBAAoB;CACpB,WAAW;CACX,UAAU;CACV,YAAY,EAAE;CACd,mBAAmB;CACnB,YAAY;CACZ,MAAM;CACN,MAAM;CACN,WAAW;CACX,MAAM;CACN,cAAc;CACd,cAAc;CACd,UAAU,EAAE;CACZ,WAAW;CACX,kBAAkB;CAClB,UAAU;CACX;AAED,MAAM,sBAAsB;CAC1B,IAAI;CACJ,MAAM;CACN,YAAY;CACZ,YAAY;CACZ,cAAc;CACd,oBAAoB;CACpB,WAAW;CACX,UAAU;CACV,YAAY,EAAE;CACd,MAAM;CACN,WAAW;CACX,MAAM;CACN,cAAc;CACd,cAAc;CACd,UAAU,EAAE;CACZ,WAAW;CACX,kBAAkB;CAClB,UAAU;CACX;AAwDD,SAAgB,YAAY,WAA2B,OAAY;CACjE,MAAM,EAAE,SAAS,GAAG,SAAS;AAC7B,QAAO;EACL,GAAG;EACH,GAAG;EACH,SAAS;GAAE,GAAG;GAAS,WAAW,UAAU;GAAM;EACnD;;AAmGH,SAAgB,gBAAgB,WAA2B,OAAY;CACrE,MAAM,EAAE,SAAS,GAAG,SAAS;AAC7B,QAAO;EACL,GAAG;EACH,GAAG;EACH,SAAS;GAAE,GAAG;GAAS,WAAW,UAAU;GAAM;EACnD;;AAiBH,SAAgB,kBAAkB,WAA2B,OAAY;CACvE,MAAM,EAAE,SAAS,GAAG,SAAS;AAC7B,QAAO;EACL,GAAG;EACH,SAAS;GAAE,GAAG;GAAS,WAAW,UAAU;GAAM;EACnD;;AAgBH,SAAgB,kBAAkB,WAA2B,OAAY;CACvE,MAAM,EAAE,SAAS,GAAG,SAAS;AAC7B,QAAO;EACL,GAAG;EACH,GAAI,WAAW,EACb,SAAS;GAAE,GAAG;GAAS,WAAW,UAAU;GAAM,EACnD;EACF"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Story as Story$1, StoryAlternate, StoryLocalizedPath, StoryTranslatedSlug } from "../generated/types.cjs";
|
|
2
|
+
import { Story as Story$2, StoryCreate as StoryCreate$1, StoryUpdate as StoryUpdate$1 } from "../generated/mapi-types.cjs";
|
|
3
|
+
import { Prettify } from "../utils/prettify.cjs";
|
|
4
|
+
import { Block } from "./define-block.cjs";
|
|
5
|
+
import { BlockContent, BlockContentInput } from "./define-field.cjs";
|
|
6
|
+
|
|
7
|
+
//#region src/helpers/define-story.d.ts
|
|
8
|
+
declare const CAPI_STORY_DEFAULTS: {
|
|
9
|
+
id: number;
|
|
10
|
+
uuid: string;
|
|
11
|
+
created_at: string;
|
|
12
|
+
updated_at: string;
|
|
13
|
+
published_at: null;
|
|
14
|
+
first_published_at: null;
|
|
15
|
+
full_slug: string;
|
|
16
|
+
group_id: string;
|
|
17
|
+
alternates: never[];
|
|
18
|
+
default_full_slug: null;
|
|
19
|
+
release_id: null;
|
|
20
|
+
lang: string;
|
|
21
|
+
slug: string;
|
|
22
|
+
parent_id: number;
|
|
23
|
+
path: null;
|
|
24
|
+
is_startpage: boolean;
|
|
25
|
+
sort_by_date: null;
|
|
26
|
+
tag_list: never[];
|
|
27
|
+
meta_data: null;
|
|
28
|
+
translated_slugs: null;
|
|
29
|
+
position: number;
|
|
30
|
+
};
|
|
31
|
+
declare const MAPI_STORY_DEFAULTS: {
|
|
32
|
+
id: number;
|
|
33
|
+
uuid: string;
|
|
34
|
+
created_at: string;
|
|
35
|
+
updated_at: string;
|
|
36
|
+
published_at: null;
|
|
37
|
+
first_published_at: null;
|
|
38
|
+
full_slug: string;
|
|
39
|
+
group_id: string;
|
|
40
|
+
alternates: never[];
|
|
41
|
+
slug: string;
|
|
42
|
+
parent_id: number;
|
|
43
|
+
path: null;
|
|
44
|
+
is_startpage: boolean;
|
|
45
|
+
sort_by_date: null;
|
|
46
|
+
tag_list: never[];
|
|
47
|
+
meta_data: null;
|
|
48
|
+
translated_slugs: null;
|
|
49
|
+
position: number;
|
|
50
|
+
};
|
|
51
|
+
type StoryComponent = Omit<Block, 'is_root'> & {
|
|
52
|
+
is_root: true;
|
|
53
|
+
};
|
|
54
|
+
type CapiStoryWithSchemaContent<TBlock extends StoryComponent = StoryComponent, TBlocks = false> = Omit<Story$1, 'content'> & {
|
|
55
|
+
content: BlockContent<TBlock, TBlocks>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* A Storyblok CDN (CAPI) story.
|
|
59
|
+
*/
|
|
60
|
+
type Story<TBlockOrBlocks extends StoryComponent | Block = StoryComponent, TBlocks = false> = Prettify<[TBlockOrBlocks] extends [StoryComponent] ? CapiStoryWithSchemaContent<TBlockOrBlocks, TBlocks> : TBlocks extends false ? CapiStoryWithSchemaContent<Extract<TBlockOrBlocks, StoryComponent>, TBlockOrBlocks> : never>;
|
|
61
|
+
type CapiStoryOptional = keyof typeof CAPI_STORY_DEFAULTS;
|
|
62
|
+
type CapiStoryInput<TBlock extends StoryComponent = StoryComponent, TBlocks extends Block = never> = Prettify<Omit<Story<TBlock, TBlocks>, CapiStoryOptional | 'content'> & Partial<Pick<Story<TBlock, TBlocks>, CapiStoryOptional>> & {
|
|
63
|
+
content: Omit<BlockContentInput<TBlock, TBlocks>, 'component'>;
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Returns a full CDN {@link Story} with all fields populated.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* const myStory = defineStory(pageComponent, {
|
|
70
|
+
* name: 'Home',
|
|
71
|
+
* content: { headline: 'Hello World!' },
|
|
72
|
+
* });
|
|
73
|
+
*/
|
|
74
|
+
declare function defineStory<TBlock extends StoryComponent, TBlocks extends Block>(component: TBlock, story: CapiStoryInput<TBlock, TBlocks>): Story<TBlock, TBlocks>;
|
|
75
|
+
type MapiStoryWithSchemaContent<TStory extends Story$2 | StoryCreate$1 | StoryUpdate$1, TBlock extends StoryComponent = StoryComponent, TBlocks = false> = StoryComponent extends TBlock ? TStory : Omit<TStory, 'content'> & {
|
|
76
|
+
content: TStory extends StoryCreate$1 | StoryUpdate$1 ? BlockContentInput<TBlock, TBlocks> : BlockContent<TBlock, TBlocks>;
|
|
77
|
+
};
|
|
78
|
+
type MakeMapiStory<TStory extends Story$2 | StoryCreate$1 | StoryUpdate$1, TBlockOrBlocks extends StoryComponent | Block = StoryComponent, TBlocks = false> = Prettify<[TBlockOrBlocks] extends [StoryComponent] ? MapiStoryWithSchemaContent<TStory, TBlockOrBlocks, TBlocks> : TBlocks extends false ? MapiStoryWithSchemaContent<TStory, Extract<TBlockOrBlocks, StoryComponent>, TBlockOrBlocks> : never>;
|
|
79
|
+
/**
|
|
80
|
+
* A Storyblok MAPI story.
|
|
81
|
+
*/
|
|
82
|
+
type MapiStory<TBlockOrBlocks extends StoryComponent | Block = StoryComponent, TBlocks = false> = MakeMapiStory<Story$2, TBlockOrBlocks, TBlocks>;
|
|
83
|
+
/** Payload for creating a story via the MAPI. */
|
|
84
|
+
type StoryCreate<TBlockOrBlocks extends StoryComponent | Block = StoryComponent, TBlocks = false> = MakeMapiStory<StoryCreate$1, TBlockOrBlocks, TBlocks>;
|
|
85
|
+
/** Payload for updating a story via the MAPI. */
|
|
86
|
+
type StoryUpdate<TBlockOrBlocks extends StoryComponent | Block = StoryComponent, TBlocks = false> = MakeMapiStory<StoryUpdate$1, TBlockOrBlocks, TBlocks>;
|
|
87
|
+
type MapiStoryOptional = keyof typeof MAPI_STORY_DEFAULTS;
|
|
88
|
+
type MakeMapiStoryInput<TStory extends MapiStory | StoryCreate | StoryUpdate, TBlock extends StoryComponent = StoryComponent, TBlocks extends Block = never> = Prettify<Omit<TStory, MapiStoryOptional | 'content'> & Partial<Pick<TStory, Extract<MapiStoryOptional, keyof TStory>>> & {
|
|
89
|
+
content: Omit<BlockContentInput<TBlock, TBlocks>, 'component'>;
|
|
90
|
+
}>;
|
|
91
|
+
type MapiStoryInput<TBlock extends StoryComponent = StoryComponent, TBlocks extends Block = never> = MakeMapiStoryInput<MapiStory, TBlock, TBlocks>;
|
|
92
|
+
type StoryCreateInput<TBlock extends StoryComponent = StoryComponent, TBlocks extends Block = never> = MakeMapiStoryInput<StoryCreate, TBlock, TBlocks>;
|
|
93
|
+
type StoryUpdateInput<TBlock extends StoryComponent = StoryComponent, TBlocks extends Block = never> = Prettify<Omit<MakeMapiStoryInput<StoryUpdate, TBlock, TBlocks>, 'content'> & {
|
|
94
|
+
content: Partial<Omit<BlockContentInput<TBlock, TBlocks>, 'component'>>;
|
|
95
|
+
}>;
|
|
96
|
+
/**
|
|
97
|
+
* Returns a full MAPI {@link MapiStory} with all fields populated.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* const myStory = defineMapiStory(pageComponent, {
|
|
101
|
+
* name: 'My Page',
|
|
102
|
+
* content: { headline: 'Hello World!' },
|
|
103
|
+
* });
|
|
104
|
+
*/
|
|
105
|
+
declare function defineMapiStory<const TBlock extends StoryComponent, const TBlocks extends Block = never>(component: TBlock, story: MapiStoryInput<TBlock, TBlocks>): MapiStory<TBlock, TBlocks>;
|
|
106
|
+
/**
|
|
107
|
+
* Defines a story creation payload for the MAPI.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* const payload = defineStoryCreate(pageComponent, {
|
|
111
|
+
* name: 'My Page',
|
|
112
|
+
* content: { headline: 'Hello World!' },
|
|
113
|
+
* });
|
|
114
|
+
*/
|
|
115
|
+
declare function defineStoryCreate<const TBlock extends StoryComponent, const TBlocks extends Block = never>(component: TBlock, story: StoryCreateInput<TBlock, TBlocks>): StoryCreate<TBlock, TBlocks>;
|
|
116
|
+
/**
|
|
117
|
+
* Defines a story update payload for the MAPI.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* const payload = defineStoryUpdate(pageComponent, {
|
|
121
|
+
* content: { headline: 'Updated!' },
|
|
122
|
+
* });
|
|
123
|
+
*/
|
|
124
|
+
declare function defineStoryUpdate<const TBlock extends StoryComponent, const TBlocks extends Block = never>(component: TBlock, story: StoryUpdateInput<TBlock, TBlocks>): StoryUpdate<TBlock, TBlocks>;
|
|
125
|
+
//#endregion
|
|
126
|
+
export { MapiStory, Story, StoryComponent, StoryCreate, StoryUpdate, defineMapiStory, defineStory, defineStoryCreate, defineStoryUpdate };
|
|
127
|
+
//# sourceMappingURL=define-story.d.cts.map
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Story as Story$1, StoryAlternate, StoryLocalizedPath, StoryTranslatedSlug } from "../generated/types.mjs";
|
|
2
|
+
import { Story as Story$2, StoryCreate as StoryCreate$1, StoryUpdate as StoryUpdate$1 } from "../generated/mapi-types.mjs";
|
|
3
|
+
import { Prettify } from "../utils/prettify.mjs";
|
|
4
|
+
import { Block } from "./define-block.mjs";
|
|
5
|
+
import { BlockContent, BlockContentInput } from "./define-field.mjs";
|
|
6
|
+
|
|
7
|
+
//#region src/helpers/define-story.d.ts
|
|
8
|
+
declare const CAPI_STORY_DEFAULTS: {
|
|
9
|
+
id: number;
|
|
10
|
+
uuid: string;
|
|
11
|
+
created_at: string;
|
|
12
|
+
updated_at: string;
|
|
13
|
+
published_at: null;
|
|
14
|
+
first_published_at: null;
|
|
15
|
+
full_slug: string;
|
|
16
|
+
group_id: string;
|
|
17
|
+
alternates: never[];
|
|
18
|
+
default_full_slug: null;
|
|
19
|
+
release_id: null;
|
|
20
|
+
lang: string;
|
|
21
|
+
slug: string;
|
|
22
|
+
parent_id: number;
|
|
23
|
+
path: null;
|
|
24
|
+
is_startpage: boolean;
|
|
25
|
+
sort_by_date: null;
|
|
26
|
+
tag_list: never[];
|
|
27
|
+
meta_data: null;
|
|
28
|
+
translated_slugs: null;
|
|
29
|
+
position: number;
|
|
30
|
+
};
|
|
31
|
+
declare const MAPI_STORY_DEFAULTS: {
|
|
32
|
+
id: number;
|
|
33
|
+
uuid: string;
|
|
34
|
+
created_at: string;
|
|
35
|
+
updated_at: string;
|
|
36
|
+
published_at: null;
|
|
37
|
+
first_published_at: null;
|
|
38
|
+
full_slug: string;
|
|
39
|
+
group_id: string;
|
|
40
|
+
alternates: never[];
|
|
41
|
+
slug: string;
|
|
42
|
+
parent_id: number;
|
|
43
|
+
path: null;
|
|
44
|
+
is_startpage: boolean;
|
|
45
|
+
sort_by_date: null;
|
|
46
|
+
tag_list: never[];
|
|
47
|
+
meta_data: null;
|
|
48
|
+
translated_slugs: null;
|
|
49
|
+
position: number;
|
|
50
|
+
};
|
|
51
|
+
type StoryComponent = Omit<Block, 'is_root'> & {
|
|
52
|
+
is_root: true;
|
|
53
|
+
};
|
|
54
|
+
type CapiStoryWithSchemaContent<TBlock extends StoryComponent = StoryComponent, TBlocks = false> = Omit<Story$1, 'content'> & {
|
|
55
|
+
content: BlockContent<TBlock, TBlocks>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* A Storyblok CDN (CAPI) story.
|
|
59
|
+
*/
|
|
60
|
+
type Story<TBlockOrBlocks extends StoryComponent | Block = StoryComponent, TBlocks = false> = Prettify<[TBlockOrBlocks] extends [StoryComponent] ? CapiStoryWithSchemaContent<TBlockOrBlocks, TBlocks> : TBlocks extends false ? CapiStoryWithSchemaContent<Extract<TBlockOrBlocks, StoryComponent>, TBlockOrBlocks> : never>;
|
|
61
|
+
type CapiStoryOptional = keyof typeof CAPI_STORY_DEFAULTS;
|
|
62
|
+
type CapiStoryInput<TBlock extends StoryComponent = StoryComponent, TBlocks extends Block = never> = Prettify<Omit<Story<TBlock, TBlocks>, CapiStoryOptional | 'content'> & Partial<Pick<Story<TBlock, TBlocks>, CapiStoryOptional>> & {
|
|
63
|
+
content: Omit<BlockContentInput<TBlock, TBlocks>, 'component'>;
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Returns a full CDN {@link Story} with all fields populated.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* const myStory = defineStory(pageComponent, {
|
|
70
|
+
* name: 'Home',
|
|
71
|
+
* content: { headline: 'Hello World!' },
|
|
72
|
+
* });
|
|
73
|
+
*/
|
|
74
|
+
declare function defineStory<TBlock extends StoryComponent, TBlocks extends Block>(component: TBlock, story: CapiStoryInput<TBlock, TBlocks>): Story<TBlock, TBlocks>;
|
|
75
|
+
type MapiStoryWithSchemaContent<TStory extends Story$2 | StoryCreate$1 | StoryUpdate$1, TBlock extends StoryComponent = StoryComponent, TBlocks = false> = StoryComponent extends TBlock ? TStory : Omit<TStory, 'content'> & {
|
|
76
|
+
content: TStory extends StoryCreate$1 | StoryUpdate$1 ? BlockContentInput<TBlock, TBlocks> : BlockContent<TBlock, TBlocks>;
|
|
77
|
+
};
|
|
78
|
+
type MakeMapiStory<TStory extends Story$2 | StoryCreate$1 | StoryUpdate$1, TBlockOrBlocks extends StoryComponent | Block = StoryComponent, TBlocks = false> = Prettify<[TBlockOrBlocks] extends [StoryComponent] ? MapiStoryWithSchemaContent<TStory, TBlockOrBlocks, TBlocks> : TBlocks extends false ? MapiStoryWithSchemaContent<TStory, Extract<TBlockOrBlocks, StoryComponent>, TBlockOrBlocks> : never>;
|
|
79
|
+
/**
|
|
80
|
+
* A Storyblok MAPI story.
|
|
81
|
+
*/
|
|
82
|
+
type MapiStory<TBlockOrBlocks extends StoryComponent | Block = StoryComponent, TBlocks = false> = MakeMapiStory<Story$2, TBlockOrBlocks, TBlocks>;
|
|
83
|
+
/** Payload for creating a story via the MAPI. */
|
|
84
|
+
type StoryCreate<TBlockOrBlocks extends StoryComponent | Block = StoryComponent, TBlocks = false> = MakeMapiStory<StoryCreate$1, TBlockOrBlocks, TBlocks>;
|
|
85
|
+
/** Payload for updating a story via the MAPI. */
|
|
86
|
+
type StoryUpdate<TBlockOrBlocks extends StoryComponent | Block = StoryComponent, TBlocks = false> = MakeMapiStory<StoryUpdate$1, TBlockOrBlocks, TBlocks>;
|
|
87
|
+
type MapiStoryOptional = keyof typeof MAPI_STORY_DEFAULTS;
|
|
88
|
+
type MakeMapiStoryInput<TStory extends MapiStory | StoryCreate | StoryUpdate, TBlock extends StoryComponent = StoryComponent, TBlocks extends Block = never> = Prettify<Omit<TStory, MapiStoryOptional | 'content'> & Partial<Pick<TStory, Extract<MapiStoryOptional, keyof TStory>>> & {
|
|
89
|
+
content: Omit<BlockContentInput<TBlock, TBlocks>, 'component'>;
|
|
90
|
+
}>;
|
|
91
|
+
type MapiStoryInput<TBlock extends StoryComponent = StoryComponent, TBlocks extends Block = never> = MakeMapiStoryInput<MapiStory, TBlock, TBlocks>;
|
|
92
|
+
type StoryCreateInput<TBlock extends StoryComponent = StoryComponent, TBlocks extends Block = never> = MakeMapiStoryInput<StoryCreate, TBlock, TBlocks>;
|
|
93
|
+
type StoryUpdateInput<TBlock extends StoryComponent = StoryComponent, TBlocks extends Block = never> = Prettify<Omit<MakeMapiStoryInput<StoryUpdate, TBlock, TBlocks>, 'content'> & {
|
|
94
|
+
content: Partial<Omit<BlockContentInput<TBlock, TBlocks>, 'component'>>;
|
|
95
|
+
}>;
|
|
96
|
+
/**
|
|
97
|
+
* Returns a full MAPI {@link MapiStory} with all fields populated.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* const myStory = defineMapiStory(pageComponent, {
|
|
101
|
+
* name: 'My Page',
|
|
102
|
+
* content: { headline: 'Hello World!' },
|
|
103
|
+
* });
|
|
104
|
+
*/
|
|
105
|
+
declare function defineMapiStory<const TBlock extends StoryComponent, const TBlocks extends Block = never>(component: TBlock, story: MapiStoryInput<TBlock, TBlocks>): MapiStory<TBlock, TBlocks>;
|
|
106
|
+
/**
|
|
107
|
+
* Defines a story creation payload for the MAPI.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* const payload = defineStoryCreate(pageComponent, {
|
|
111
|
+
* name: 'My Page',
|
|
112
|
+
* content: { headline: 'Hello World!' },
|
|
113
|
+
* });
|
|
114
|
+
*/
|
|
115
|
+
declare function defineStoryCreate<const TBlock extends StoryComponent, const TBlocks extends Block = never>(component: TBlock, story: StoryCreateInput<TBlock, TBlocks>): StoryCreate<TBlock, TBlocks>;
|
|
116
|
+
/**
|
|
117
|
+
* Defines a story update payload for the MAPI.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* const payload = defineStoryUpdate(pageComponent, {
|
|
121
|
+
* content: { headline: 'Updated!' },
|
|
122
|
+
* });
|
|
123
|
+
*/
|
|
124
|
+
declare function defineStoryUpdate<const TBlock extends StoryComponent, const TBlocks extends Block = never>(component: TBlock, story: StoryUpdateInput<TBlock, TBlocks>): StoryUpdate<TBlock, TBlocks>;
|
|
125
|
+
//#endregion
|
|
126
|
+
export { MapiStory, Story, StoryComponent, StoryCreate, StoryUpdate, defineMapiStory, defineStory, defineStoryCreate, defineStoryUpdate };
|
|
127
|
+
//# sourceMappingURL=define-story.d.mts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
//#region src/helpers/define-story.ts
|
|
2
|
+
const CAPI_STORY_DEFAULTS = {
|
|
3
|
+
id: 1,
|
|
4
|
+
uuid: "",
|
|
5
|
+
created_at: "",
|
|
6
|
+
updated_at: "",
|
|
7
|
+
published_at: null,
|
|
8
|
+
first_published_at: null,
|
|
9
|
+
full_slug: "",
|
|
10
|
+
group_id: "",
|
|
11
|
+
alternates: [],
|
|
12
|
+
default_full_slug: null,
|
|
13
|
+
release_id: null,
|
|
14
|
+
lang: "default",
|
|
15
|
+
slug: "",
|
|
16
|
+
parent_id: 0,
|
|
17
|
+
path: null,
|
|
18
|
+
is_startpage: false,
|
|
19
|
+
sort_by_date: null,
|
|
20
|
+
tag_list: [],
|
|
21
|
+
meta_data: null,
|
|
22
|
+
translated_slugs: null,
|
|
23
|
+
position: 0
|
|
24
|
+
};
|
|
25
|
+
const MAPI_STORY_DEFAULTS = {
|
|
26
|
+
id: 1,
|
|
27
|
+
uuid: "",
|
|
28
|
+
created_at: "",
|
|
29
|
+
updated_at: "",
|
|
30
|
+
published_at: null,
|
|
31
|
+
first_published_at: null,
|
|
32
|
+
full_slug: "",
|
|
33
|
+
group_id: "",
|
|
34
|
+
alternates: [],
|
|
35
|
+
slug: "",
|
|
36
|
+
parent_id: 0,
|
|
37
|
+
path: null,
|
|
38
|
+
is_startpage: false,
|
|
39
|
+
sort_by_date: null,
|
|
40
|
+
tag_list: [],
|
|
41
|
+
meta_data: null,
|
|
42
|
+
translated_slugs: null,
|
|
43
|
+
position: 0
|
|
44
|
+
};
|
|
45
|
+
function defineStory(component, story) {
|
|
46
|
+
const { content, ...rest } = story;
|
|
47
|
+
return {
|
|
48
|
+
...CAPI_STORY_DEFAULTS,
|
|
49
|
+
...rest,
|
|
50
|
+
content: {
|
|
51
|
+
...content,
|
|
52
|
+
component: component.name
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function defineMapiStory(component, story) {
|
|
57
|
+
const { content, ...rest } = story;
|
|
58
|
+
return {
|
|
59
|
+
...MAPI_STORY_DEFAULTS,
|
|
60
|
+
...rest,
|
|
61
|
+
content: {
|
|
62
|
+
...content,
|
|
63
|
+
component: component.name
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function defineStoryCreate(component, story) {
|
|
68
|
+
const { content, ...rest } = story;
|
|
69
|
+
return {
|
|
70
|
+
...rest,
|
|
71
|
+
content: {
|
|
72
|
+
...content,
|
|
73
|
+
component: component.name
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function defineStoryUpdate(component, story) {
|
|
78
|
+
const { content, ...rest } = story;
|
|
79
|
+
return {
|
|
80
|
+
...rest,
|
|
81
|
+
...content && { content: {
|
|
82
|
+
...content,
|
|
83
|
+
component: component.name
|
|
84
|
+
} }
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
export { defineMapiStory, defineStory, defineStoryCreate, defineStoryUpdate };
|
|
90
|
+
//# sourceMappingURL=define-story.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-story.mjs","names":[],"sources":["../../src/helpers/define-story.ts"],"sourcesContent":["import type {\n Story as CapiStoryGenerated,\n StoryAlternate,\n StoryLocalizedPath,\n StoryTranslatedSlug,\n} from '../generated/types';\nimport type {\n Story as MapiStoryGenerated,\n StoryCreate as StoryCreateGenerated,\n StoryUpdate as StoryUpdateGenerated,\n} from '../generated/mapi-types';\nimport type { Block } from './define-block';\nimport type { BlockContent, BlockContentInput } from './define-field';\nimport type { Prettify } from '../utils/prettify';\n\nconst CAPI_STORY_DEFAULTS = {\n id: 1,\n uuid: '',\n created_at: '',\n updated_at: '',\n published_at: null,\n first_published_at: null,\n full_slug: '',\n group_id: '',\n alternates: [],\n default_full_slug: null,\n release_id: null,\n lang: 'default',\n slug: '',\n parent_id: 0,\n path: null,\n is_startpage: false,\n sort_by_date: null,\n tag_list: [],\n meta_data: null,\n translated_slugs: null,\n position: 0,\n};\n\nconst MAPI_STORY_DEFAULTS = {\n id: 1,\n uuid: '',\n created_at: '',\n updated_at: '',\n published_at: null,\n first_published_at: null,\n full_slug: '',\n group_id: '',\n alternates: [],\n slug: '',\n parent_id: 0,\n path: null,\n is_startpage: false,\n sort_by_date: null,\n tag_list: [],\n meta_data: null,\n translated_slugs: null,\n position: 0,\n};\n\nexport type { StoryAlternate, StoryLocalizedPath, StoryTranslatedSlug };\n\nexport type StoryComponent = Omit<Block, 'is_root'> & { is_root: true };\n\n// ---------------------------------------------------------------------------\n// CDN (CAPI) Story\n// ---------------------------------------------------------------------------\n\ntype CapiStoryWithSchemaContent<\n TBlock extends StoryComponent = StoryComponent,\n TBlocks = false,\n> = Omit<CapiStoryGenerated, 'content'> & { content: BlockContent<TBlock, TBlocks> };\n\n/**\n * A Storyblok CDN (CAPI) story.\n */\nexport type Story<\n TBlockOrBlocks extends StoryComponent | Block = StoryComponent,\n TBlocks = false,\n> = Prettify<\n [TBlockOrBlocks] extends [StoryComponent]\n ? CapiStoryWithSchemaContent<TBlockOrBlocks, TBlocks>\n : TBlocks extends false\n ? CapiStoryWithSchemaContent<Extract<TBlockOrBlocks, StoryComponent>, TBlockOrBlocks>\n : never\n>;\n\ntype CapiStoryOptional = keyof typeof CAPI_STORY_DEFAULTS;\n\ntype CapiStoryInput<\n TBlock extends StoryComponent = StoryComponent,\n TBlocks extends Block = never,\n> = Prettify<\n Omit<Story<TBlock, TBlocks>, CapiStoryOptional | 'content'>\n & Partial<Pick<Story<TBlock, TBlocks>, CapiStoryOptional>>\n & {\n content: Omit<BlockContentInput<TBlock, TBlocks>, 'component'>;\n }\n>;\n\n/**\n * Returns a full CDN {@link Story} with all fields populated.\n *\n * @example\n * const myStory = defineStory(pageComponent, {\n * name: 'Home',\n * content: { headline: 'Hello World!' },\n * });\n */\nexport function defineStory<\n TBlock extends StoryComponent,\n TBlocks extends Block,\n>(component: TBlock, story: CapiStoryInput<TBlock, TBlocks>): Story<TBlock, TBlocks>;\n\nexport function defineStory(component: StoryComponent, story: any) {\n const { content, ...rest } = story;\n return {\n ...CAPI_STORY_DEFAULTS,\n ...rest,\n content: { ...content, component: component.name },\n };\n}\n\n// ---------------------------------------------------------------------------\n// MAPI Story helpers\n// ---------------------------------------------------------------------------\n\ntype MapiStoryWithSchemaContent<\n TStory extends MapiStoryGenerated | StoryCreateGenerated | StoryUpdateGenerated,\n TBlock extends StoryComponent = StoryComponent,\n TBlocks = false,\n> = StoryComponent extends TBlock\n ? TStory\n : Omit<TStory, 'content'> & {\n content: TStory extends StoryCreateGenerated | StoryUpdateGenerated\n ? BlockContentInput<TBlock, TBlocks>\n : BlockContent<TBlock, TBlocks>;\n };\n\ntype MakeMapiStory<\n TStory extends MapiStoryGenerated | StoryCreateGenerated | StoryUpdateGenerated,\n TBlockOrBlocks extends StoryComponent | Block = StoryComponent,\n TBlocks = false,\n> = Prettify<\n [TBlockOrBlocks] extends [StoryComponent]\n ? MapiStoryWithSchemaContent<TStory, TBlockOrBlocks, TBlocks>\n : TBlocks extends false\n ? MapiStoryWithSchemaContent<TStory, Extract<TBlockOrBlocks, StoryComponent>, TBlockOrBlocks>\n : never\n>;\n\n/**\n * A Storyblok MAPI story.\n */\nexport type MapiStory<\n TBlockOrBlocks extends StoryComponent | Block = StoryComponent,\n TBlocks = false,\n> = MakeMapiStory<MapiStoryGenerated, TBlockOrBlocks, TBlocks>;\n\n/** Payload for creating a story via the MAPI. */\nexport type StoryCreate<\n TBlockOrBlocks extends StoryComponent | Block = StoryComponent,\n TBlocks = false,\n> = MakeMapiStory<StoryCreateGenerated, TBlockOrBlocks, TBlocks>;\n\n/** Payload for updating a story via the MAPI. */\nexport type StoryUpdate<\n TBlockOrBlocks extends StoryComponent | Block = StoryComponent,\n TBlocks = false,\n> = MakeMapiStory<StoryUpdateGenerated, TBlockOrBlocks, TBlocks>;\n\ntype MapiStoryOptional = keyof typeof MAPI_STORY_DEFAULTS;\n\ntype MakeMapiStoryInput<\n TStory extends MapiStory | StoryCreate | StoryUpdate,\n TBlock extends StoryComponent = StoryComponent,\n TBlocks extends Block = never,\n> = Prettify<\n Omit<TStory, MapiStoryOptional | 'content'>\n & Partial<Pick<TStory, Extract<MapiStoryOptional, keyof TStory>>>\n & {\n content: Omit<BlockContentInput<TBlock, TBlocks>, 'component'>;\n }\n>;\n\ntype MapiStoryInput<\n TBlock extends StoryComponent = StoryComponent,\n TBlocks extends Block = never,\n> = MakeMapiStoryInput<MapiStory, TBlock, TBlocks>;\n\ntype StoryCreateInput<\n TBlock extends StoryComponent = StoryComponent,\n TBlocks extends Block = never,\n> = MakeMapiStoryInput<StoryCreate, TBlock, TBlocks>;\n\ntype StoryUpdateInput<\n TBlock extends StoryComponent = StoryComponent,\n TBlocks extends Block = never,\n> = Prettify<\n Omit<MakeMapiStoryInput<StoryUpdate, TBlock, TBlocks>, 'content'>\n & {\n content: Partial<Omit<BlockContentInput<TBlock, TBlocks>, 'component'>>;\n }\n>;\n\n/**\n * Returns a full MAPI {@link MapiStory} with all fields populated.\n *\n * @example\n * const myStory = defineMapiStory(pageComponent, {\n * name: 'My Page',\n * content: { headline: 'Hello World!' },\n * });\n */\nexport function defineMapiStory<\n const TBlock extends StoryComponent,\n const TBlocks extends Block = never,\n>(component: TBlock, story: MapiStoryInput<TBlock, TBlocks>): MapiStory<TBlock, TBlocks>;\n\nexport function defineMapiStory(component: StoryComponent, story: any) {\n const { content, ...rest } = story;\n return {\n ...MAPI_STORY_DEFAULTS,\n ...rest,\n content: { ...content, component: component.name },\n };\n}\n\n/**\n * Defines a story creation payload for the MAPI.\n *\n * @example\n * const payload = defineStoryCreate(pageComponent, {\n * name: 'My Page',\n * content: { headline: 'Hello World!' },\n * });\n */\nexport function defineStoryCreate<\n const TBlock extends StoryComponent,\n const TBlocks extends Block = never,\n>(component: TBlock, story: StoryCreateInput<TBlock, TBlocks>): StoryCreate<TBlock, TBlocks>;\n\nexport function defineStoryCreate(component: StoryComponent, story: any) {\n const { content, ...rest } = story;\n return {\n ...rest,\n content: { ...content, component: component.name },\n };\n}\n\n/**\n * Defines a story update payload for the MAPI.\n *\n * @example\n * const payload = defineStoryUpdate(pageComponent, {\n * content: { headline: 'Updated!' },\n * });\n */\nexport function defineStoryUpdate<\n const TBlock extends StoryComponent,\n const TBlocks extends Block = never,\n>(component: TBlock, story: StoryUpdateInput<TBlock, TBlocks>): StoryUpdate<TBlock, TBlocks>;\n\nexport function defineStoryUpdate(component: StoryComponent, story: any) {\n const { content, ...rest } = story;\n return {\n ...rest,\n ...(content && {\n content: { ...content, component: component.name },\n }),\n };\n}\n"],"mappings":";AAeA,MAAM,sBAAsB;CAC1B,IAAI;CACJ,MAAM;CACN,YAAY;CACZ,YAAY;CACZ,cAAc;CACd,oBAAoB;CACpB,WAAW;CACX,UAAU;CACV,YAAY,EAAE;CACd,mBAAmB;CACnB,YAAY;CACZ,MAAM;CACN,MAAM;CACN,WAAW;CACX,MAAM;CACN,cAAc;CACd,cAAc;CACd,UAAU,EAAE;CACZ,WAAW;CACX,kBAAkB;CAClB,UAAU;CACX;AAED,MAAM,sBAAsB;CAC1B,IAAI;CACJ,MAAM;CACN,YAAY;CACZ,YAAY;CACZ,cAAc;CACd,oBAAoB;CACpB,WAAW;CACX,UAAU;CACV,YAAY,EAAE;CACd,MAAM;CACN,WAAW;CACX,MAAM;CACN,cAAc;CACd,cAAc;CACd,UAAU,EAAE;CACZ,WAAW;CACX,kBAAkB;CAClB,UAAU;CACX;AAwDD,SAAgB,YAAY,WAA2B,OAAY;CACjE,MAAM,EAAE,SAAS,GAAG,SAAS;AAC7B,QAAO;EACL,GAAG;EACH,GAAG;EACH,SAAS;GAAE,GAAG;GAAS,WAAW,UAAU;GAAM;EACnD;;AAmGH,SAAgB,gBAAgB,WAA2B,OAAY;CACrE,MAAM,EAAE,SAAS,GAAG,SAAS;AAC7B,QAAO;EACL,GAAG;EACH,GAAG;EACH,SAAS;GAAE,GAAG;GAAS,WAAW,UAAU;GAAM;EACnD;;AAiBH,SAAgB,kBAAkB,WAA2B,OAAY;CACvE,MAAM,EAAE,SAAS,GAAG,SAAS;AAC7B,QAAO;EACL,GAAG;EACH,SAAS;GAAE,GAAG;GAAS,WAAW,UAAU;GAAM;EACnD;;AAgBH,SAAgB,kBAAkB,WAA2B,OAAY;CACvE,MAAM,EAAE,SAAS,GAAG,SAAS;AAC7B,QAAO;EACL,GAAG;EACH,GAAI,WAAW,EACb,SAAS;GAAE,GAAG;GAAS,WAAW,UAAU;GAAM,EACnD;EACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/helpers/define-tag.ts
|
|
3
|
+
const TAG_DEFAULTS = { taggings_count: 0 };
|
|
4
|
+
function defineTag(tag) {
|
|
5
|
+
return {
|
|
6
|
+
...TAG_DEFAULTS,
|
|
7
|
+
...tag
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.defineTag = defineTag;
|
|
13
|
+
//# sourceMappingURL=define-tag.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-tag.cjs","names":[],"sources":["../../src/helpers/define-tag.ts"],"sourcesContent":["import type { Tag } from '../generated/types';\nimport type { Prettify } from '../utils/prettify';\n\nconst TAG_DEFAULTS = {\n taggings_count: 0,\n};\n\nexport type { Tag };\n\n/** Fields that have safe defaults and may be omitted from tag input. */\ntype TagOptional = keyof typeof TAG_DEFAULTS;\n\ntype TagInput = Prettify<Omit<Tag, TagOptional> & Partial<Pick<Tag, TagOptional>>>;\n\n/**\n * Returns a full {@link Tag} with all fields populated. API-assigned\n * fields are optional and default to safe values.\n *\n * @example\n * const tag = defineTag({\n * name: 'featured',\n * });\n */\n// Overload: provides the strict public signature for callers.\nexport function defineTag(tag: TagInput): Tag;\n\n// Implementation signature: uses a loose parameter type because\n// TypeScript requires the implementation signature to be assignable\n// to all overloads. Not visible to callers.\nexport function defineTag(tag: any) {\n return { ...TAG_DEFAULTS, ...tag };\n}\n"],"mappings":";;AAGA,MAAM,eAAe,EACnB,gBAAgB,GACjB;AAwBD,SAAgB,UAAU,KAAU;AAClC,QAAO;EAAE,GAAG;EAAc,GAAG;EAAK"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Tag } from "../generated/types.cjs";
|
|
2
|
+
import { Prettify } from "../utils/prettify.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/helpers/define-tag.d.ts
|
|
5
|
+
declare const TAG_DEFAULTS: {
|
|
6
|
+
taggings_count: number;
|
|
7
|
+
};
|
|
8
|
+
/** Fields that have safe defaults and may be omitted from tag input. */
|
|
9
|
+
type TagOptional = keyof typeof TAG_DEFAULTS;
|
|
10
|
+
type TagInput = Prettify<Omit<Tag, TagOptional> & Partial<Pick<Tag, TagOptional>>>;
|
|
11
|
+
/**
|
|
12
|
+
* Returns a full {@link Tag} with all fields populated. API-assigned
|
|
13
|
+
* fields are optional and default to safe values.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const tag = defineTag({
|
|
17
|
+
* name: 'featured',
|
|
18
|
+
* });
|
|
19
|
+
*/
|
|
20
|
+
declare function defineTag(tag: TagInput): Tag;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { defineTag };
|
|
23
|
+
//# sourceMappingURL=define-tag.d.cts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Tag } from "../generated/types.mjs";
|
|
2
|
+
import { Prettify } from "../utils/prettify.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/helpers/define-tag.d.ts
|
|
5
|
+
declare const TAG_DEFAULTS: {
|
|
6
|
+
taggings_count: number;
|
|
7
|
+
};
|
|
8
|
+
/** Fields that have safe defaults and may be omitted from tag input. */
|
|
9
|
+
type TagOptional = keyof typeof TAG_DEFAULTS;
|
|
10
|
+
type TagInput = Prettify<Omit<Tag, TagOptional> & Partial<Pick<Tag, TagOptional>>>;
|
|
11
|
+
/**
|
|
12
|
+
* Returns a full {@link Tag} with all fields populated. API-assigned
|
|
13
|
+
* fields are optional and default to safe values.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const tag = defineTag({
|
|
17
|
+
* name: 'featured',
|
|
18
|
+
* });
|
|
19
|
+
*/
|
|
20
|
+
declare function defineTag(tag: TagInput): Tag;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { defineTag };
|
|
23
|
+
//# sourceMappingURL=define-tag.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-tag.mjs","names":[],"sources":["../../src/helpers/define-tag.ts"],"sourcesContent":["import type { Tag } from '../generated/types';\nimport type { Prettify } from '../utils/prettify';\n\nconst TAG_DEFAULTS = {\n taggings_count: 0,\n};\n\nexport type { Tag };\n\n/** Fields that have safe defaults and may be omitted from tag input. */\ntype TagOptional = keyof typeof TAG_DEFAULTS;\n\ntype TagInput = Prettify<Omit<Tag, TagOptional> & Partial<Pick<Tag, TagOptional>>>;\n\n/**\n * Returns a full {@link Tag} with all fields populated. API-assigned\n * fields are optional and default to safe values.\n *\n * @example\n * const tag = defineTag({\n * name: 'featured',\n * });\n */\n// Overload: provides the strict public signature for callers.\nexport function defineTag(tag: TagInput): Tag;\n\n// Implementation signature: uses a loose parameter type because\n// TypeScript requires the implementation signature to be assignable\n// to all overloads. Not visible to callers.\nexport function defineTag(tag: any) {\n return { ...TAG_DEFAULTS, ...tag };\n}\n"],"mappings":";AAGA,MAAM,eAAe,EACnB,gBAAgB,GACjB;AAwBD,SAAgB,UAAU,KAAU;AAClC,QAAO;EAAE,GAAG;EAAc,GAAG;EAAK"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/helpers/define-user.ts
|
|
3
|
+
const USER_DEFAULTS = {
|
|
4
|
+
id: 1,
|
|
5
|
+
created_at: "",
|
|
6
|
+
updated_at: ""
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Defines a user object for the MAPI.
|
|
10
|
+
* API-assigned fields (`id`, `created_at`, `updated_at`) are optional and filled with safe defaults.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { defineUser } from '@storyblok/schema';
|
|
14
|
+
* const user = defineUser({ email: 'dev@example.com' });
|
|
15
|
+
*/
|
|
16
|
+
const defineUser = (user) => ({
|
|
17
|
+
...USER_DEFAULTS,
|
|
18
|
+
...user
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Defines a user update payload for the MAPI (updateMe endpoint).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* import { defineUserUpdate } from '@storyblok/schema';
|
|
25
|
+
* const payload = defineUserUpdate({ firstname: 'Jane', lastname: 'Doe' });
|
|
26
|
+
*/
|
|
27
|
+
const defineUserUpdate = (user) => user;
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.defineUser = defineUser;
|
|
31
|
+
exports.defineUserUpdate = defineUserUpdate;
|
|
32
|
+
//# sourceMappingURL=define-user.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-user.cjs","names":[],"sources":["../../src/helpers/define-user.ts"],"sourcesContent":["import type { User, UserUpdate } from '../generated/mapi-types';\n\nexport type { User, UserUpdate };\n\nconst USER_DEFAULTS = {\n id: 1,\n created_at: '',\n updated_at: '',\n};\n\ntype UserInput = { email: string } & Partial<Omit<User, 'email'>>;\n\n/**\n * Defines a user object for the MAPI.\n * API-assigned fields (`id`, `created_at`, `updated_at`) are optional and filled with safe defaults.\n *\n * @example\n * import { defineUser } from '@storyblok/schema';\n * const user = defineUser({ email: 'dev@example.com' });\n */\nexport const defineUser = (user: UserInput): User => ({ ...USER_DEFAULTS, ...user });\n\n/**\n * Defines a user update payload for the MAPI (updateMe endpoint).\n *\n * @example\n * import { defineUserUpdate } from '@storyblok/schema';\n * const payload = defineUserUpdate({ firstname: 'Jane', lastname: 'Doe' });\n */\nexport const defineUserUpdate = (user: UserUpdate): UserUpdate => user;\n"],"mappings":";;AAIA,MAAM,gBAAgB;CACpB,IAAI;CACJ,YAAY;CACZ,YAAY;CACb;;;;;;;;;AAYD,MAAa,cAAc,UAA2B;CAAE,GAAG;CAAe,GAAG;CAAM;;;;;;;;AASnF,MAAa,oBAAoB,SAAiC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { User, UserUpdate } from "../generated/mapi-types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/helpers/define-user.d.ts
|
|
4
|
+
type UserInput = {
|
|
5
|
+
email: string;
|
|
6
|
+
} & Partial<Omit<User, 'email'>>;
|
|
7
|
+
/**
|
|
8
|
+
* Defines a user object for the MAPI.
|
|
9
|
+
* API-assigned fields (`id`, `created_at`, `updated_at`) are optional and filled with safe defaults.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* import { defineUser } from '@storyblok/schema';
|
|
13
|
+
* const user = defineUser({ email: 'dev@example.com' });
|
|
14
|
+
*/
|
|
15
|
+
declare const defineUser: (user: UserInput) => User;
|
|
16
|
+
/**
|
|
17
|
+
* Defines a user update payload for the MAPI (updateMe endpoint).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* import { defineUserUpdate } from '@storyblok/schema';
|
|
21
|
+
* const payload = defineUserUpdate({ firstname: 'Jane', lastname: 'Doe' });
|
|
22
|
+
*/
|
|
23
|
+
declare const defineUserUpdate: (user: UserUpdate) => UserUpdate;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { defineUser, defineUserUpdate };
|
|
26
|
+
//# sourceMappingURL=define-user.d.cts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { User, UserUpdate } from "../generated/mapi-types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/helpers/define-user.d.ts
|
|
4
|
+
type UserInput = {
|
|
5
|
+
email: string;
|
|
6
|
+
} & Partial<Omit<User, 'email'>>;
|
|
7
|
+
/**
|
|
8
|
+
* Defines a user object for the MAPI.
|
|
9
|
+
* API-assigned fields (`id`, `created_at`, `updated_at`) are optional and filled with safe defaults.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* import { defineUser } from '@storyblok/schema';
|
|
13
|
+
* const user = defineUser({ email: 'dev@example.com' });
|
|
14
|
+
*/
|
|
15
|
+
declare const defineUser: (user: UserInput) => User;
|
|
16
|
+
/**
|
|
17
|
+
* Defines a user update payload for the MAPI (updateMe endpoint).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* import { defineUserUpdate } from '@storyblok/schema';
|
|
21
|
+
* const payload = defineUserUpdate({ firstname: 'Jane', lastname: 'Doe' });
|
|
22
|
+
*/
|
|
23
|
+
declare const defineUserUpdate: (user: UserUpdate) => UserUpdate;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { defineUser, defineUserUpdate };
|
|
26
|
+
//# sourceMappingURL=define-user.d.mts.map
|