@storyblok/schema 0.1.0-alpha.0 → 0.1.0-alpha.1
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/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 +409 -0
- package/dist/generated/overlay/zod.gen.cjs.map +1 -0
- package/dist/generated/overlay/zod.gen.mjs +403 -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 +28 -13
- package/dist/generated/types/field.d.mts +28 -13
- package/dist/generated/types/mapi-story.d.cts +5 -9
- package/dist/generated/types/mapi-story.d.mts +5 -9
- 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.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/schema-type.d.cts +5 -9
- package/dist/helpers/schema-type.d.mts +5 -9
- package/dist/index.cjs +6 -47
- package/dist/index.d.cts +11 -20
- package/dist/index.d.mts +11 -20
- package/dist/index.mjs +6 -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 +62 -0
- package/dist/validators/shapes.d.mts +62 -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 +125 -0
- package/dist/validators/validate-schema.cjs.map +1 -0
- package/dist/validators/validate-schema.d.cts +18 -0
- package/dist/validators/validate-schema.d.mts +18 -0
- package/dist/validators/validate-schema.mjs +125 -0
- package/dist/validators/validate-schema.mjs.map +1 -0
- package/dist/validators/validate-story.cjs +257 -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 +257 -0
- package/dist/validators/validate-story.mjs.map +1 -0
- package/package.json +5 -1
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AssetFieldValue, BlockContentBase, BlockContentInputBase, Field, MultilinkFieldValue, PluginFieldValue, RichtextFieldValue, TableFieldValue } from "../overlay/_internal.gen.mjs";
|
|
2
2
|
import { Prettify } from "./_utils.mjs";
|
|
3
|
-
import { Block } from "./block.mjs";
|
|
3
|
+
import { Block, BlockFields } from "./block.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/generated/types/field.d.ts
|
|
6
6
|
/**
|
|
@@ -11,27 +11,42 @@ import { Block } from "./block.mjs";
|
|
|
11
11
|
type NoBlocks = false;
|
|
12
12
|
/** True when `T` is the un-narrowed base `Block` (i.e. no specific block was supplied). */
|
|
13
13
|
type IsBaseBlock<T> = [Block] extends [T] ? true : false;
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Maps a block's ordered `fields` array to its read content object, splitting
|
|
16
|
+
* required (`required: true`) from optional fields. Each `F` is a member of the
|
|
17
|
+
* field union, so it provably satisfies `FieldValue`'s `Field` constraint.
|
|
18
|
+
*/
|
|
19
|
+
type ContentFields<TFields extends BlockFields, TBlocks> = Prettify<{ [F in TFields[number] as F extends {
|
|
20
|
+
required: true;
|
|
21
|
+
} ? F['name'] : never]: FieldValue<F, TBlocks> } & { [F in TFields[number] as F extends {
|
|
22
|
+
required: true;
|
|
23
|
+
} ? never : F['name']]?: FieldValue<F, TBlocks> | null }>;
|
|
24
|
+
/** Input (write) variant of {@link ContentFields}, resolving each field via {@link FieldValueInput}. */
|
|
25
|
+
type ContentFieldsInput<TFields extends BlockFields, TBlocks> = Prettify<{ [F in TFields[number] as F extends {
|
|
26
|
+
required: true;
|
|
27
|
+
} ? F['name'] : never]: FieldValueInput<F, TBlocks> } & { [F in TFields[number] as F extends {
|
|
15
28
|
required: true;
|
|
16
|
-
} ?
|
|
17
|
-
type OptionalFieldKeys<T> = Exclude<keyof T, RequiredFieldKeys<T>>;
|
|
29
|
+
} ? never : F['name']]?: FieldValueInput<F, TBlocks> | null }>;
|
|
18
30
|
/**
|
|
19
31
|
* Content object for a single block instance as returned by the Storyblok
|
|
20
32
|
* Content Delivery API. Without a `TBlock` argument, this is the loose
|
|
21
33
|
* runtime shape (any block, `_editable` optional). With a schema-typed
|
|
22
|
-
* `TBlock`, fields are narrowed per the block's
|
|
34
|
+
* `TBlock`, fields are narrowed per the block's `fields`.
|
|
23
35
|
*/
|
|
24
36
|
type BlockContent<TBlock extends Block = Block, TBlocks = NoBlocks> = IsBaseBlock<TBlock> extends true ? BlockContentBase : TBlock extends any ? Prettify<{
|
|
25
37
|
_uid: string;
|
|
26
38
|
component: TBlock['name'];
|
|
27
39
|
_editable?: string;
|
|
28
|
-
} &
|
|
40
|
+
} & ContentFields<TBlock['fields'], TBlocks>> : never;
|
|
29
41
|
/** Input variant of {@link BlockContent} for write operations (creating/updating stories via the MAPI). `_uid` is optional. */
|
|
30
42
|
type BlockContentInput<TBlock extends Block = Block, TBlocks = NoBlocks> = IsBaseBlock<TBlock> extends true ? BlockContentInputBase : TBlock extends any ? Prettify<{
|
|
31
43
|
_uid?: string;
|
|
32
44
|
component: TBlock['name'];
|
|
33
45
|
_editable?: string;
|
|
34
|
-
} &
|
|
46
|
+
} & ContentFieldsInput<TBlock['fields'], TBlocks>> : never;
|
|
47
|
+
type BlocksFieldValue<TBlock extends Block = Block, TBlocks = NoBlocks> = BlockContent<TBlock, TBlocks>[];
|
|
48
|
+
/** Union of all valid Storyblok field type discriminants (e.g., `text`, `bloks`). */
|
|
49
|
+
type FieldType = Field['type'];
|
|
35
50
|
interface FieldTypeValueMap {
|
|
36
51
|
text: string;
|
|
37
52
|
textarea: string;
|
|
@@ -56,19 +71,19 @@ type IsNestable<T> = T extends {
|
|
|
56
71
|
} ? false : T extends {
|
|
57
72
|
is_nestable: true;
|
|
58
73
|
} ? true : true;
|
|
59
|
-
type
|
|
60
|
-
|
|
74
|
+
type ApplyAllow<TField, TBlocks> = TField extends {
|
|
75
|
+
allow: ReadonlyArray<infer TAllowed extends string>;
|
|
61
76
|
} ? Extract<TBlocks, {
|
|
62
|
-
name:
|
|
77
|
+
name: TAllowed;
|
|
63
78
|
}> : TBlocks extends any ? IsNestable<TBlocks> extends true ? TBlocks : never : never;
|
|
64
79
|
/** Resolves a field definition to its runtime content value type (read). */
|
|
65
80
|
type FieldValue<TField extends Field = Field, TBlocks = NoBlocks> = Prettify<TField extends {
|
|
66
81
|
type: 'bloks';
|
|
67
|
-
} ? [TBlocks] extends [never] ? BlockContentBase[] : [TBlocks] extends [Block] ? BlockContent<
|
|
82
|
+
} ? [TBlocks] extends [never] ? BlockContentBase[] : [TBlocks] extends [Block] ? BlockContent<ApplyAllow<TField, TBlocks>, TBlocks>[] : BlockContentBase[] : FieldTypeValueMap[TField['type']]>;
|
|
68
83
|
/** Resolves a field definition to its input value type (write). */
|
|
69
84
|
type FieldValueInput<TField extends Field = Field, TBlocks = NoBlocks> = Prettify<TField extends {
|
|
70
85
|
type: 'bloks';
|
|
71
|
-
} ? [TBlocks] extends [never] ? BlockContentInputBase[] : [TBlocks] extends [Block] ? BlockContentInput<
|
|
86
|
+
} ? [TBlocks] extends [never] ? BlockContentInputBase[] : [TBlocks] extends [Block] ? BlockContentInput<ApplyAllow<TField, TBlocks>, TBlocks>[] : BlockContentInputBase[] : FieldTypeValueMap[TField['type']]>;
|
|
72
87
|
//#endregion
|
|
73
|
-
export { BlockContent, BlockContentInput };
|
|
88
|
+
export { BlockContent, BlockContentInput, BlocksFieldValue, FieldType, FieldValue, FieldValueInput };
|
|
74
89
|
//# sourceMappingURL=field.d.mts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MapiStory as MapiStory$1, StoryCreate
|
|
1
|
+
import { MapiStory as MapiStory$1, StoryCreate, StoryUpdate } from "../mapi/_internal.gen.cjs";
|
|
2
2
|
import { Override, Prettify } from "./_utils.cjs";
|
|
3
3
|
import { Block, RootBlock } from "./block.cjs";
|
|
4
4
|
import { BlockContent, BlockContentInput } from "./field.cjs";
|
|
@@ -14,16 +14,12 @@ type NoBlocks = false;
|
|
|
14
14
|
* Base (un-narrowed) `RootBlock` means no schema was supplied, so the generated
|
|
15
15
|
* story passes through unchanged.
|
|
16
16
|
*/
|
|
17
|
-
type MapiStoryWithSchemaContent<TStory extends MapiStory$1 | StoryCreate
|
|
18
|
-
content: TStory extends StoryCreate
|
|
17
|
+
type MapiStoryWithSchemaContent<TStory extends MapiStory$1 | StoryCreate | StoryUpdate, TBlock extends RootBlock = RootBlock, TBlocks = NoBlocks> = RootBlock extends TBlock ? TStory : Override<TStory, {
|
|
18
|
+
content: TStory extends StoryCreate | StoryUpdate ? BlockContentInput<TBlock, TBlocks> : BlockContent<TBlock, TBlocks>;
|
|
19
19
|
}>;
|
|
20
|
-
type MakeMapiStory<TStory extends MapiStory$1 | StoryCreate
|
|
20
|
+
type MakeMapiStory<TStory extends MapiStory$1 | StoryCreate | StoryUpdate, TBlockOrBlocks extends RootBlock | Block = RootBlock, TBlocks = NoBlocks> = Prettify<[TBlockOrBlocks] extends [RootBlock] ? MapiStoryWithSchemaContent<TStory, TBlockOrBlocks, TBlocks> : TBlocks extends NoBlocks ? MapiStoryWithSchemaContent<TStory, Extract<TBlockOrBlocks, RootBlock>, TBlockOrBlocks> : never>;
|
|
21
21
|
/** A Storyblok MAPI story. */
|
|
22
22
|
type MapiStory<TBlockOrBlocks extends RootBlock | Block = RootBlock, TBlocks = NoBlocks> = MakeMapiStory<MapiStory$1, TBlockOrBlocks, TBlocks>;
|
|
23
|
-
/** Payload for creating a story via the MAPI. */
|
|
24
|
-
type StoryCreate<TBlockOrBlocks extends RootBlock | Block = RootBlock, TBlocks = NoBlocks> = MakeMapiStory<StoryCreate$1, TBlockOrBlocks, TBlocks>;
|
|
25
|
-
/** Payload for updating a story via the MAPI. */
|
|
26
|
-
type StoryUpdate<TBlockOrBlocks extends RootBlock | Block = RootBlock, TBlocks = NoBlocks> = MakeMapiStory<StoryUpdate$1, TBlockOrBlocks, TBlocks>;
|
|
27
23
|
//#endregion
|
|
28
|
-
export { MapiStory
|
|
24
|
+
export { MapiStory };
|
|
29
25
|
//# sourceMappingURL=mapi-story.d.cts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MapiStory as MapiStory$1, StoryCreate
|
|
1
|
+
import { MapiStory as MapiStory$1, StoryCreate, StoryUpdate } from "../mapi/_internal.gen.mjs";
|
|
2
2
|
import { Override, Prettify } from "./_utils.mjs";
|
|
3
3
|
import { Block, RootBlock } from "./block.mjs";
|
|
4
4
|
import { BlockContent, BlockContentInput } from "./field.mjs";
|
|
@@ -14,16 +14,12 @@ type NoBlocks = false;
|
|
|
14
14
|
* Base (un-narrowed) `RootBlock` means no schema was supplied, so the generated
|
|
15
15
|
* story passes through unchanged.
|
|
16
16
|
*/
|
|
17
|
-
type MapiStoryWithSchemaContent<TStory extends MapiStory$1 | StoryCreate
|
|
18
|
-
content: TStory extends StoryCreate
|
|
17
|
+
type MapiStoryWithSchemaContent<TStory extends MapiStory$1 | StoryCreate | StoryUpdate, TBlock extends RootBlock = RootBlock, TBlocks = NoBlocks> = RootBlock extends TBlock ? TStory : Override<TStory, {
|
|
18
|
+
content: TStory extends StoryCreate | StoryUpdate ? BlockContentInput<TBlock, TBlocks> : BlockContent<TBlock, TBlocks>;
|
|
19
19
|
}>;
|
|
20
|
-
type MakeMapiStory<TStory extends MapiStory$1 | StoryCreate
|
|
20
|
+
type MakeMapiStory<TStory extends MapiStory$1 | StoryCreate | StoryUpdate, TBlockOrBlocks extends RootBlock | Block = RootBlock, TBlocks = NoBlocks> = Prettify<[TBlockOrBlocks] extends [RootBlock] ? MapiStoryWithSchemaContent<TStory, TBlockOrBlocks, TBlocks> : TBlocks extends NoBlocks ? MapiStoryWithSchemaContent<TStory, Extract<TBlockOrBlocks, RootBlock>, TBlockOrBlocks> : never>;
|
|
21
21
|
/** A Storyblok MAPI story. */
|
|
22
22
|
type MapiStory<TBlockOrBlocks extends RootBlock | Block = RootBlock, TBlocks = NoBlocks> = MakeMapiStory<MapiStory$1, TBlockOrBlocks, TBlocks>;
|
|
23
|
-
/** Payload for creating a story via the MAPI. */
|
|
24
|
-
type StoryCreate<TBlockOrBlocks extends RootBlock | Block = RootBlock, TBlocks = NoBlocks> = MakeMapiStory<StoryCreate$1, TBlockOrBlocks, TBlocks>;
|
|
25
|
-
/** Payload for updating a story via the MAPI. */
|
|
26
|
-
type StoryUpdate<TBlockOrBlocks extends RootBlock | Block = RootBlock, TBlocks = NoBlocks> = MakeMapiStory<StoryUpdate$1, TBlockOrBlocks, TBlocks>;
|
|
27
23
|
//#endregion
|
|
28
|
-
export { MapiStory
|
|
24
|
+
export { MapiStory };
|
|
29
25
|
//# sourceMappingURL=mapi-story.d.mts.map
|
|
@@ -5,47 +5,29 @@ const BLOCK_DEFAULTS = {
|
|
|
5
5
|
created_at: "",
|
|
6
6
|
updated_at: "",
|
|
7
7
|
is_root: false,
|
|
8
|
-
is_nestable: true
|
|
9
|
-
component_group_uuid: null
|
|
8
|
+
is_nestable: true
|
|
10
9
|
};
|
|
11
10
|
function defineBlock(block) {
|
|
12
|
-
const
|
|
11
|
+
const inputFields = Array.isArray(block?.fields) ? block.fields : [];
|
|
13
12
|
const seen = /* @__PURE__ */ new Set();
|
|
14
|
-
const
|
|
15
|
-
inputSchema.forEach((field, index) => {
|
|
13
|
+
const fields = inputFields.map((field, index) => {
|
|
16
14
|
const name = field?.name;
|
|
17
|
-
if (typeof name
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
...
|
|
15
|
+
if (typeof name === "string") {
|
|
16
|
+
if (seen.has(name)) throw new Error(`defineBlock: duplicate field name "${name}" in block "${block?.name ?? ""}"`);
|
|
17
|
+
seen.add(name);
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
...field,
|
|
23
21
|
pos: index
|
|
24
22
|
};
|
|
25
23
|
});
|
|
26
24
|
return {
|
|
27
25
|
...BLOCK_DEFAULTS,
|
|
28
26
|
...block,
|
|
29
|
-
|
|
27
|
+
fields
|
|
30
28
|
};
|
|
31
29
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Defines a block creation payload for the MAPI.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* const payload = defineBlockCreate({ name: 'page', schema: { ... } });
|
|
37
|
-
*/
|
|
38
|
-
const defineBlockCreate = (block) => block;
|
|
39
|
-
/**
|
|
40
|
-
* Defines a block update payload for the MAPI.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* const payload = defineBlockUpdate({ display_name: 'Page' });
|
|
44
|
-
*/
|
|
45
|
-
const defineBlockUpdate = (block) => block;
|
|
46
30
|
|
|
47
31
|
//#endregion
|
|
48
32
|
exports.defineBlock = defineBlock;
|
|
49
|
-
exports.defineBlockCreate = defineBlockCreate;
|
|
50
|
-
exports.defineBlockUpdate = defineBlockUpdate;
|
|
51
33
|
//# sourceMappingURL=define-block.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-block.cjs","names":[],"sources":["../../src/helpers/define-block.ts"],"sourcesContent":["import type {\n Block,\n
|
|
1
|
+
{"version":3,"file":"define-block.cjs","names":[],"sources":["../../src/helpers/define-block.ts"],"sourcesContent":["import type {\n Block,\n BlockFields,\n NestableBlock,\n RootBlock,\n} from '../generated/types/block';\nimport type { Prettify } from '../utils/prettify';\n\nexport type { Block, BlockFields, NestableBlock, RootBlock };\n\nconst BLOCK_DEFAULTS = {\n id: 1,\n created_at: '',\n updated_at: '',\n is_root: false,\n is_nestable: true,\n};\n\n/** Fields that have safe defaults and may be omitted from block input. */\ntype BlockOptional = keyof typeof BLOCK_DEFAULTS;\n\ntype BlockInput<\n TName extends string = string,\n TFields extends BlockFields = BlockFields,\n TIsRoot extends boolean = false,\n TIsNestable extends boolean = true,\n> = Prettify<\n Omit<Block, 'name' | 'fields' | 'is_root' | 'is_nestable' | BlockOptional> & {\n name: TName;\n fields: TFields;\n is_root?: TIsRoot;\n is_nestable?: TIsNestable;\n } & Partial<Pick<Block, Exclude<BlockOptional, 'is_root' | 'is_nestable'>>>\n>;\n\ntype DefinedBlock<\n TName extends string,\n TFields extends BlockFields,\n TIsRoot extends boolean,\n TIsNestable extends boolean,\n> = Prettify<\n Omit<Block, 'name' | 'fields' | 'is_root' | 'is_nestable'> & {\n name: TName;\n fields: TFields;\n is_root: TIsRoot;\n is_nestable: TIsNestable;\n }\n>;\n\n/**\n * Returns a {@link Block} content-shape definition. The user-facing input is an\n * ordered array of `defineField` calls under `fields`; the array index becomes\n * each field's `pos`. A thin, strongly-typed helper — it does not map to the\n * MAPI wire shape (the CLI owns the DSL→wire mapping). Throws only on duplicate\n * field names (a programming error).\n *\n * @example\n * const pageBlock = defineBlock({\n * name: 'page',\n * is_root: true,\n * fields: [\n * defineField('headline', { type: 'text', required: true }),\n * ],\n * });\n */\nexport function defineBlock<\n TName extends string,\n const TFields extends BlockFields,\n TIsRoot extends boolean = false,\n TIsNestable extends boolean = true,\n>(\n block: BlockInput<TName, TFields, TIsRoot, TIsNestable>,\n): DefinedBlock<TName, TFields, TIsRoot, TIsNestable>;\n\nexport function defineBlock(block: any) {\n const inputFields = Array.isArray(block?.fields) ? block.fields : [];\n const seen = new Set<string>();\n const fields = inputFields.map((field: any, index: number) => {\n const name = field?.name;\n if (typeof name === 'string') {\n if (seen.has(name)) {\n throw new Error(`defineBlock: duplicate field name \"${name}\" in block \"${block?.name ?? ''}\"`);\n }\n seen.add(name);\n }\n return { ...field, pos: index };\n });\n return { ...BLOCK_DEFAULTS, ...block, fields };\n}\n"],"mappings":";;AAUA,MAAM,iBAAiB;CACrB,IAAI;CACJ,YAAY;CACZ,YAAY;CACZ,SAAS;CACT,aAAa;CACd;AA0DD,SAAgB,YAAY,OAAY;CACtC,MAAM,cAAc,MAAM,QAAQ,OAAO,OAAO,GAAG,MAAM,SAAS,EAAE;CACpE,MAAM,uBAAO,IAAI,KAAa;CAC9B,MAAM,SAAS,YAAY,KAAK,OAAY,UAAkB;EAC5D,MAAM,OAAO,OAAO;AACpB,MAAI,OAAO,SAAS,UAAU;AAC5B,OAAI,KAAK,IAAI,KAAK,CAChB,OAAM,IAAI,MAAM,sCAAsC,KAAK,cAAc,OAAO,QAAQ,GAAG,GAAG;AAEhG,QAAK,IAAI,KAAK;;AAEhB,SAAO;GAAE,GAAG;GAAO,KAAK;GAAO;GAC/B;AACF,QAAO;EAAE,GAAG;EAAgB,GAAG;EAAO;EAAQ"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Block, BlockSchema, BlockSchemaInput, NestableBlock, RootBlock, SchemaArrayToRecord } from "../generated/types/block.cjs";
|
|
1
|
+
import { Block, BlockFields, NestableBlock, RootBlock } from "../generated/types/block.cjs";
|
|
3
2
|
import { Prettify } from "../utils/prettify.cjs";
|
|
4
3
|
|
|
5
4
|
//#region src/helpers/define-block.d.ts
|
|
@@ -9,54 +8,38 @@ declare const BLOCK_DEFAULTS: {
|
|
|
9
8
|
updated_at: string;
|
|
10
9
|
is_root: boolean;
|
|
11
10
|
is_nestable: boolean;
|
|
12
|
-
component_group_uuid: null;
|
|
13
11
|
};
|
|
14
12
|
/** Fields that have safe defaults and may be omitted from block input. */
|
|
15
13
|
type BlockOptional = keyof typeof BLOCK_DEFAULTS;
|
|
16
|
-
type BlockInput<TName extends string = string,
|
|
14
|
+
type BlockInput<TName extends string = string, TFields extends BlockFields = BlockFields, TIsRoot extends boolean = false, TIsNestable extends boolean = true> = Prettify<Omit<Block, 'name' | 'fields' | 'is_root' | 'is_nestable' | BlockOptional> & {
|
|
17
15
|
name: TName;
|
|
18
|
-
|
|
16
|
+
fields: TFields;
|
|
19
17
|
is_root?: TIsRoot;
|
|
20
18
|
is_nestable?: TIsNestable;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
type DefinedBlock<TName extends string, TBlockSchema, TIsRoot extends boolean, TIsNestable extends boolean, TComponentGroupUuid extends string | null> = Prettify<Omit<Block, 'name' | 'schema' | 'is_root' | 'is_nestable' | 'component_group_uuid'> & {
|
|
19
|
+
} & Partial<Pick<Block, Exclude<BlockOptional, 'is_root' | 'is_nestable'>>>>;
|
|
20
|
+
type DefinedBlock<TName extends string, TFields extends BlockFields, TIsRoot extends boolean, TIsNestable extends boolean> = Prettify<Omit<Block, 'name' | 'fields' | 'is_root' | 'is_nestable'> & {
|
|
24
21
|
name: TName;
|
|
25
|
-
|
|
22
|
+
fields: TFields;
|
|
26
23
|
is_root: TIsRoot;
|
|
27
24
|
is_nestable: TIsNestable;
|
|
28
|
-
component_group_uuid: TComponentGroupUuid;
|
|
29
25
|
}>;
|
|
30
26
|
/**
|
|
31
|
-
* Returns a {@link Block}
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
27
|
+
* Returns a {@link Block} content-shape definition. The user-facing input is an
|
|
28
|
+
* ordered array of `defineField` calls under `fields`; the array index becomes
|
|
29
|
+
* each field's `pos`. A thin, strongly-typed helper — it does not map to the
|
|
30
|
+
* MAPI wire shape (the CLI owns the DSL→wire mapping). Throws only on duplicate
|
|
31
|
+
* field names (a programming error).
|
|
35
32
|
*
|
|
36
33
|
* @example
|
|
37
34
|
* const pageBlock = defineBlock({
|
|
38
35
|
* name: 'page',
|
|
39
36
|
* is_root: true,
|
|
40
|
-
*
|
|
37
|
+
* fields: [
|
|
41
38
|
* defineField('headline', { type: 'text', required: true }),
|
|
42
39
|
* ],
|
|
43
40
|
* });
|
|
44
41
|
*/
|
|
45
|
-
declare function defineBlock<TName extends string, const
|
|
46
|
-
/**
|
|
47
|
-
* Defines a block creation payload for the MAPI.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* const payload = defineBlockCreate({ name: 'page', schema: { ... } });
|
|
51
|
-
*/
|
|
52
|
-
declare const defineBlockCreate: (block: ComponentCreate) => ComponentCreate;
|
|
53
|
-
/**
|
|
54
|
-
* Defines a block update payload for the MAPI.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* const payload = defineBlockUpdate({ display_name: 'Page' });
|
|
58
|
-
*/
|
|
59
|
-
declare const defineBlockUpdate: (block: ComponentUpdate) => ComponentUpdate;
|
|
42
|
+
declare function defineBlock<TName extends string, const TFields extends BlockFields, TIsRoot extends boolean = false, TIsNestable extends boolean = true>(block: BlockInput<TName, TFields, TIsRoot, TIsNestable>): DefinedBlock<TName, TFields, TIsRoot, TIsNestable>;
|
|
60
43
|
//#endregion
|
|
61
|
-
export { defineBlock
|
|
44
|
+
export { defineBlock };
|
|
62
45
|
//# sourceMappingURL=define-block.d.cts.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Block, BlockSchema, BlockSchemaInput, NestableBlock, RootBlock, SchemaArrayToRecord } from "../generated/types/block.mjs";
|
|
1
|
+
import { Block, BlockFields, NestableBlock, RootBlock } from "../generated/types/block.mjs";
|
|
3
2
|
import { Prettify } from "../utils/prettify.mjs";
|
|
4
3
|
|
|
5
4
|
//#region src/helpers/define-block.d.ts
|
|
@@ -9,54 +8,38 @@ declare const BLOCK_DEFAULTS: {
|
|
|
9
8
|
updated_at: string;
|
|
10
9
|
is_root: boolean;
|
|
11
10
|
is_nestable: boolean;
|
|
12
|
-
component_group_uuid: null;
|
|
13
11
|
};
|
|
14
12
|
/** Fields that have safe defaults and may be omitted from block input. */
|
|
15
13
|
type BlockOptional = keyof typeof BLOCK_DEFAULTS;
|
|
16
|
-
type BlockInput<TName extends string = string,
|
|
14
|
+
type BlockInput<TName extends string = string, TFields extends BlockFields = BlockFields, TIsRoot extends boolean = false, TIsNestable extends boolean = true> = Prettify<Omit<Block, 'name' | 'fields' | 'is_root' | 'is_nestable' | BlockOptional> & {
|
|
17
15
|
name: TName;
|
|
18
|
-
|
|
16
|
+
fields: TFields;
|
|
19
17
|
is_root?: TIsRoot;
|
|
20
18
|
is_nestable?: TIsNestable;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
type DefinedBlock<TName extends string, TBlockSchema, TIsRoot extends boolean, TIsNestable extends boolean, TComponentGroupUuid extends string | null> = Prettify<Omit<Block, 'name' | 'schema' | 'is_root' | 'is_nestable' | 'component_group_uuid'> & {
|
|
19
|
+
} & Partial<Pick<Block, Exclude<BlockOptional, 'is_root' | 'is_nestable'>>>>;
|
|
20
|
+
type DefinedBlock<TName extends string, TFields extends BlockFields, TIsRoot extends boolean, TIsNestable extends boolean> = Prettify<Omit<Block, 'name' | 'fields' | 'is_root' | 'is_nestable'> & {
|
|
24
21
|
name: TName;
|
|
25
|
-
|
|
22
|
+
fields: TFields;
|
|
26
23
|
is_root: TIsRoot;
|
|
27
24
|
is_nestable: TIsNestable;
|
|
28
|
-
component_group_uuid: TComponentGroupUuid;
|
|
29
25
|
}>;
|
|
30
26
|
/**
|
|
31
|
-
* Returns a {@link Block}
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
27
|
+
* Returns a {@link Block} content-shape definition. The user-facing input is an
|
|
28
|
+
* ordered array of `defineField` calls under `fields`; the array index becomes
|
|
29
|
+
* each field's `pos`. A thin, strongly-typed helper — it does not map to the
|
|
30
|
+
* MAPI wire shape (the CLI owns the DSL→wire mapping). Throws only on duplicate
|
|
31
|
+
* field names (a programming error).
|
|
35
32
|
*
|
|
36
33
|
* @example
|
|
37
34
|
* const pageBlock = defineBlock({
|
|
38
35
|
* name: 'page',
|
|
39
36
|
* is_root: true,
|
|
40
|
-
*
|
|
37
|
+
* fields: [
|
|
41
38
|
* defineField('headline', { type: 'text', required: true }),
|
|
42
39
|
* ],
|
|
43
40
|
* });
|
|
44
41
|
*/
|
|
45
|
-
declare function defineBlock<TName extends string, const
|
|
46
|
-
/**
|
|
47
|
-
* Defines a block creation payload for the MAPI.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* const payload = defineBlockCreate({ name: 'page', schema: { ... } });
|
|
51
|
-
*/
|
|
52
|
-
declare const defineBlockCreate: (block: ComponentCreate) => ComponentCreate;
|
|
53
|
-
/**
|
|
54
|
-
* Defines a block update payload for the MAPI.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* const payload = defineBlockUpdate({ display_name: 'Page' });
|
|
58
|
-
*/
|
|
59
|
-
declare const defineBlockUpdate: (block: ComponentUpdate) => ComponentUpdate;
|
|
42
|
+
declare function defineBlock<TName extends string, const TFields extends BlockFields, TIsRoot extends boolean = false, TIsNestable extends boolean = true>(block: BlockInput<TName, TFields, TIsRoot, TIsNestable>): DefinedBlock<TName, TFields, TIsRoot, TIsNestable>;
|
|
60
43
|
//#endregion
|
|
61
|
-
export { defineBlock
|
|
44
|
+
export { defineBlock };
|
|
62
45
|
//# sourceMappingURL=define-block.d.mts.map
|
|
@@ -4,45 +4,29 @@ const BLOCK_DEFAULTS = {
|
|
|
4
4
|
created_at: "",
|
|
5
5
|
updated_at: "",
|
|
6
6
|
is_root: false,
|
|
7
|
-
is_nestable: true
|
|
8
|
-
component_group_uuid: null
|
|
7
|
+
is_nestable: true
|
|
9
8
|
};
|
|
10
9
|
function defineBlock(block) {
|
|
11
|
-
const
|
|
10
|
+
const inputFields = Array.isArray(block?.fields) ? block.fields : [];
|
|
12
11
|
const seen = /* @__PURE__ */ new Set();
|
|
13
|
-
const
|
|
14
|
-
inputSchema.forEach((field, index) => {
|
|
12
|
+
const fields = inputFields.map((field, index) => {
|
|
15
13
|
const name = field?.name;
|
|
16
|
-
if (typeof name
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
...
|
|
14
|
+
if (typeof name === "string") {
|
|
15
|
+
if (seen.has(name)) throw new Error(`defineBlock: duplicate field name "${name}" in block "${block?.name ?? ""}"`);
|
|
16
|
+
seen.add(name);
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
...field,
|
|
22
20
|
pos: index
|
|
23
21
|
};
|
|
24
22
|
});
|
|
25
23
|
return {
|
|
26
24
|
...BLOCK_DEFAULTS,
|
|
27
25
|
...block,
|
|
28
|
-
|
|
26
|
+
fields
|
|
29
27
|
};
|
|
30
28
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Defines a block creation payload for the MAPI.
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* const payload = defineBlockCreate({ name: 'page', schema: { ... } });
|
|
36
|
-
*/
|
|
37
|
-
const defineBlockCreate = (block) => block;
|
|
38
|
-
/**
|
|
39
|
-
* Defines a block update payload for the MAPI.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* const payload = defineBlockUpdate({ display_name: 'Page' });
|
|
43
|
-
*/
|
|
44
|
-
const defineBlockUpdate = (block) => block;
|
|
45
29
|
|
|
46
30
|
//#endregion
|
|
47
|
-
export { defineBlock
|
|
31
|
+
export { defineBlock };
|
|
48
32
|
//# sourceMappingURL=define-block.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-block.mjs","names":[],"sources":["../../src/helpers/define-block.ts"],"sourcesContent":["import type {\n Block,\n
|
|
1
|
+
{"version":3,"file":"define-block.mjs","names":[],"sources":["../../src/helpers/define-block.ts"],"sourcesContent":["import type {\n Block,\n BlockFields,\n NestableBlock,\n RootBlock,\n} from '../generated/types/block';\nimport type { Prettify } from '../utils/prettify';\n\nexport type { Block, BlockFields, NestableBlock, RootBlock };\n\nconst BLOCK_DEFAULTS = {\n id: 1,\n created_at: '',\n updated_at: '',\n is_root: false,\n is_nestable: true,\n};\n\n/** Fields that have safe defaults and may be omitted from block input. */\ntype BlockOptional = keyof typeof BLOCK_DEFAULTS;\n\ntype BlockInput<\n TName extends string = string,\n TFields extends BlockFields = BlockFields,\n TIsRoot extends boolean = false,\n TIsNestable extends boolean = true,\n> = Prettify<\n Omit<Block, 'name' | 'fields' | 'is_root' | 'is_nestable' | BlockOptional> & {\n name: TName;\n fields: TFields;\n is_root?: TIsRoot;\n is_nestable?: TIsNestable;\n } & Partial<Pick<Block, Exclude<BlockOptional, 'is_root' | 'is_nestable'>>>\n>;\n\ntype DefinedBlock<\n TName extends string,\n TFields extends BlockFields,\n TIsRoot extends boolean,\n TIsNestable extends boolean,\n> = Prettify<\n Omit<Block, 'name' | 'fields' | 'is_root' | 'is_nestable'> & {\n name: TName;\n fields: TFields;\n is_root: TIsRoot;\n is_nestable: TIsNestable;\n }\n>;\n\n/**\n * Returns a {@link Block} content-shape definition. The user-facing input is an\n * ordered array of `defineField` calls under `fields`; the array index becomes\n * each field's `pos`. A thin, strongly-typed helper — it does not map to the\n * MAPI wire shape (the CLI owns the DSL→wire mapping). Throws only on duplicate\n * field names (a programming error).\n *\n * @example\n * const pageBlock = defineBlock({\n * name: 'page',\n * is_root: true,\n * fields: [\n * defineField('headline', { type: 'text', required: true }),\n * ],\n * });\n */\nexport function defineBlock<\n TName extends string,\n const TFields extends BlockFields,\n TIsRoot extends boolean = false,\n TIsNestable extends boolean = true,\n>(\n block: BlockInput<TName, TFields, TIsRoot, TIsNestable>,\n): DefinedBlock<TName, TFields, TIsRoot, TIsNestable>;\n\nexport function defineBlock(block: any) {\n const inputFields = Array.isArray(block?.fields) ? block.fields : [];\n const seen = new Set<string>();\n const fields = inputFields.map((field: any, index: number) => {\n const name = field?.name;\n if (typeof name === 'string') {\n if (seen.has(name)) {\n throw new Error(`defineBlock: duplicate field name \"${name}\" in block \"${block?.name ?? ''}\"`);\n }\n seen.add(name);\n }\n return { ...field, pos: index };\n });\n return { ...BLOCK_DEFAULTS, ...block, fields };\n}\n"],"mappings":";AAUA,MAAM,iBAAiB;CACrB,IAAI;CACJ,YAAY;CACZ,YAAY;CACZ,SAAS;CACT,aAAa;CACd;AA0DD,SAAgB,YAAY,OAAY;CACtC,MAAM,cAAc,MAAM,QAAQ,OAAO,OAAO,GAAG,MAAM,SAAS,EAAE;CACpE,MAAM,uBAAO,IAAI,KAAa;CAC9B,MAAM,SAAS,YAAY,KAAK,OAAY,UAAkB;EAC5D,MAAM,OAAO,OAAO;AACpB,MAAI,OAAO,SAAS,UAAU;AAC5B,OAAI,KAAK,IAAI,KAAK,CAChB,OAAM,IAAI,MAAM,sCAAsC,KAAK,cAAc,OAAO,QAAQ,GAAG,GAAG;AAEhG,QAAK,IAAI,KAAK;;AAEhB,SAAO;GAAE,GAAG;GAAO,KAAK;GAAO;GAC/B;AACF,QAAO;EAAE,GAAG;EAAgB,GAAG;EAAO;EAAQ"}
|
|
@@ -12,23 +12,7 @@ function defineDatasource(datasource) {
|
|
|
12
12
|
...datasource
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Defines a datasource creation payload for the MAPI.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* const payload = defineDatasourceCreate({ name: 'Colors', slug: 'colors' });
|
|
20
|
-
*/
|
|
21
|
-
const defineDatasourceCreate = (datasource) => datasource;
|
|
22
|
-
/**
|
|
23
|
-
* Defines a datasource update payload for the MAPI.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* const payload = defineDatasourceUpdate({ name: 'Updated Colors' });
|
|
27
|
-
*/
|
|
28
|
-
const defineDatasourceUpdate = (datasource) => datasource;
|
|
29
15
|
|
|
30
16
|
//#endregion
|
|
31
17
|
exports.defineDatasource = defineDatasource;
|
|
32
|
-
exports.defineDatasourceCreate = defineDatasourceCreate;
|
|
33
|
-
exports.defineDatasourceUpdate = defineDatasourceUpdate;
|
|
34
18
|
//# sourceMappingURL=define-datasource.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-datasource.cjs","names":[],"sources":["../../src/helpers/define-datasource.ts"],"sourcesContent":["import type { Datasource } from '../generated/capi/types.gen';\nimport type {
|
|
1
|
+
{"version":3,"file":"define-datasource.cjs","names":[],"sources":["../../src/helpers/define-datasource.ts"],"sourcesContent":["import type { Datasource as DatasourceGenerated } from '../generated/capi/types.gen';\nimport type { Override } from '../generated/types/_utils';\nimport type { Prettify } from '../utils/prettify';\n\nconst DATASOURCE_DEFAULTS = {\n id: 1,\n created_at: '',\n updated_at: '',\n dimensions: [],\n};\n\n/**\n * A Storyblok datasource content shape. Carries the datasource definition only\n * (`name`, `slug`, dimensions). Entry values are content authored by editors,\n * not part of the schema, so they are neither modelled nor pushed here.\n */\nexport type Datasource = Override<DatasourceGenerated, { slug: string }>;\n\n/** Fields that have safe defaults and may be omitted from datasource input. */\ntype DatasourceOptional = keyof typeof DATASOURCE_DEFAULTS;\n\ntype DatasourceInput = Prettify<Omit<Datasource, DatasourceOptional> & Partial<Pick<Datasource, DatasourceOptional>>>;\n\n/**\n * Returns a {@link Datasource} content-shape definition. A thin, strongly-typed\n * helper — it does not validate or throw.\n *\n * @example\n * const colors = defineDatasource({ name: 'Colors', slug: 'colors' });\n */\nexport function defineDatasource(datasource: DatasourceInput): Datasource;\nexport function defineDatasource(datasource: any) {\n return { ...DATASOURCE_DEFAULTS, ...datasource };\n}\n"],"mappings":";;AAIA,MAAM,sBAAsB;CAC1B,IAAI;CACJ,YAAY;CACZ,YAAY;CACZ,YAAY,EAAE;CACf;AAsBD,SAAgB,iBAAiB,YAAiB;AAChD,QAAO;EAAE,GAAG;EAAqB,GAAG;EAAY"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Override } from "../generated/types/_utils.cjs";
|
|
1
2
|
import { Prettify } from "../utils/prettify.cjs";
|
|
2
|
-
import { Datasource } from "../generated/capi/types.gen.cjs";
|
|
3
|
-
import { DatasourceCreate, DatasourceUpdate } from "../generated/mapi/types.gen.cjs";
|
|
3
|
+
import { Datasource as Datasource$1 } from "../generated/capi/types.gen.cjs";
|
|
4
4
|
|
|
5
5
|
//#region src/helpers/define-datasource.d.ts
|
|
6
6
|
declare const DATASOURCE_DEFAULTS: {
|
|
@@ -9,34 +9,25 @@ declare const DATASOURCE_DEFAULTS: {
|
|
|
9
9
|
updated_at: string;
|
|
10
10
|
dimensions: never[];
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* A Storyblok datasource content shape. Carries the datasource definition only
|
|
14
|
+
* (`name`, `slug`, dimensions). Entry values are content authored by editors,
|
|
15
|
+
* not part of the schema, so they are neither modelled nor pushed here.
|
|
16
|
+
*/
|
|
17
|
+
type Datasource = Override<Datasource$1, {
|
|
18
|
+
slug: string;
|
|
19
|
+
}>;
|
|
12
20
|
/** Fields that have safe defaults and may be omitted from datasource input. */
|
|
13
21
|
type DatasourceOptional = keyof typeof DATASOURCE_DEFAULTS;
|
|
14
22
|
type DatasourceInput = Prettify<Omit<Datasource, DatasourceOptional> & Partial<Pick<Datasource, DatasourceOptional>>>;
|
|
15
23
|
/**
|
|
16
|
-
* Returns a
|
|
17
|
-
*
|
|
24
|
+
* Returns a {@link Datasource} content-shape definition. A thin, strongly-typed
|
|
25
|
+
* helper — it does not validate or throw.
|
|
18
26
|
*
|
|
19
27
|
* @example
|
|
20
|
-
* const
|
|
21
|
-
* name: 'Colors',
|
|
22
|
-
* slug: 'colors',
|
|
23
|
-
* });
|
|
28
|
+
* const colors = defineDatasource({ name: 'Colors', slug: 'colors' });
|
|
24
29
|
*/
|
|
25
30
|
declare function defineDatasource(datasource: DatasourceInput): Datasource;
|
|
26
|
-
/**
|
|
27
|
-
* Defines a datasource creation payload for the MAPI.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* const payload = defineDatasourceCreate({ name: 'Colors', slug: 'colors' });
|
|
31
|
-
*/
|
|
32
|
-
declare const defineDatasourceCreate: (datasource: DatasourceCreate) => DatasourceCreate;
|
|
33
|
-
/**
|
|
34
|
-
* Defines a datasource update payload for the MAPI.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* const payload = defineDatasourceUpdate({ name: 'Updated Colors' });
|
|
38
|
-
*/
|
|
39
|
-
declare const defineDatasourceUpdate: (datasource: DatasourceUpdate) => DatasourceUpdate;
|
|
40
31
|
//#endregion
|
|
41
|
-
export {
|
|
32
|
+
export { Datasource, defineDatasource };
|
|
42
33
|
//# sourceMappingURL=define-datasource.d.cts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Override } from "../generated/types/_utils.mjs";
|
|
1
2
|
import { Prettify } from "../utils/prettify.mjs";
|
|
2
|
-
import { Datasource } from "../generated/capi/types.gen.mjs";
|
|
3
|
-
import { DatasourceCreate, DatasourceUpdate } from "../generated/mapi/types.gen.mjs";
|
|
3
|
+
import { Datasource as Datasource$1 } from "../generated/capi/types.gen.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/helpers/define-datasource.d.ts
|
|
6
6
|
declare const DATASOURCE_DEFAULTS: {
|
|
@@ -9,34 +9,25 @@ declare const DATASOURCE_DEFAULTS: {
|
|
|
9
9
|
updated_at: string;
|
|
10
10
|
dimensions: never[];
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* A Storyblok datasource content shape. Carries the datasource definition only
|
|
14
|
+
* (`name`, `slug`, dimensions). Entry values are content authored by editors,
|
|
15
|
+
* not part of the schema, so they are neither modelled nor pushed here.
|
|
16
|
+
*/
|
|
17
|
+
type Datasource = Override<Datasource$1, {
|
|
18
|
+
slug: string;
|
|
19
|
+
}>;
|
|
12
20
|
/** Fields that have safe defaults and may be omitted from datasource input. */
|
|
13
21
|
type DatasourceOptional = keyof typeof DATASOURCE_DEFAULTS;
|
|
14
22
|
type DatasourceInput = Prettify<Omit<Datasource, DatasourceOptional> & Partial<Pick<Datasource, DatasourceOptional>>>;
|
|
15
23
|
/**
|
|
16
|
-
* Returns a
|
|
17
|
-
*
|
|
24
|
+
* Returns a {@link Datasource} content-shape definition. A thin, strongly-typed
|
|
25
|
+
* helper — it does not validate or throw.
|
|
18
26
|
*
|
|
19
27
|
* @example
|
|
20
|
-
* const
|
|
21
|
-
* name: 'Colors',
|
|
22
|
-
* slug: 'colors',
|
|
23
|
-
* });
|
|
28
|
+
* const colors = defineDatasource({ name: 'Colors', slug: 'colors' });
|
|
24
29
|
*/
|
|
25
30
|
declare function defineDatasource(datasource: DatasourceInput): Datasource;
|
|
26
|
-
/**
|
|
27
|
-
* Defines a datasource creation payload for the MAPI.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* const payload = defineDatasourceCreate({ name: 'Colors', slug: 'colors' });
|
|
31
|
-
*/
|
|
32
|
-
declare const defineDatasourceCreate: (datasource: DatasourceCreate) => DatasourceCreate;
|
|
33
|
-
/**
|
|
34
|
-
* Defines a datasource update payload for the MAPI.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* const payload = defineDatasourceUpdate({ name: 'Updated Colors' });
|
|
38
|
-
*/
|
|
39
|
-
declare const defineDatasourceUpdate: (datasource: DatasourceUpdate) => DatasourceUpdate;
|
|
40
31
|
//#endregion
|
|
41
|
-
export {
|
|
32
|
+
export { Datasource, defineDatasource };
|
|
42
33
|
//# sourceMappingURL=define-datasource.d.mts.map
|