@storyblok/schema 0.1.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/LICENSE +8 -0
- package/README.md +74 -0
- package/dist/generated/capi/_internal.gen.d.cts +120 -0
- package/dist/generated/capi/_internal.gen.d.mts +120 -0
- package/dist/generated/capi/types.gen.d.cts +181 -0
- package/dist/generated/capi/types.gen.d.mts +181 -0
- package/dist/generated/mapi/_internal.gen.d.cts +683 -0
- package/dist/generated/mapi/_internal.gen.d.mts +683 -0
- package/dist/generated/mapi/types.gen.d.cts +1272 -0
- package/dist/generated/mapi/types.gen.d.mts +1272 -0
- package/dist/generated/overlay/_internal.gen.d.cts +850 -0
- package/dist/generated/overlay/_internal.gen.d.mts +850 -0
- package/dist/generated/types/_utils.d.cts +7 -0
- package/dist/generated/types/_utils.d.mts +7 -0
- package/dist/generated/types/block.d.cts +46 -0
- package/dist/generated/types/block.d.mts +46 -0
- package/dist/generated/types/field.d.cts +74 -0
- package/dist/generated/types/field.d.mts +74 -0
- package/dist/generated/types/mapi-story.d.cts +29 -0
- package/dist/generated/types/mapi-story.d.mts +29 -0
- package/dist/generated/types/story.d.cts +19 -0
- package/dist/generated/types/story.d.mts +19 -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 +50 -0
- package/dist/helpers/create-story-helpers.d.mts +50 -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 +46 -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 +43 -0
- package/dist/helpers/define-asset-folder.mjs.map +1 -0
- package/dist/helpers/define-asset.cjs +60 -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 +57 -0
- package/dist/helpers/define-asset.mjs.map +1 -0
- package/dist/helpers/define-block-folder.cjs +44 -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 +41 -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 +62 -0
- package/dist/helpers/define-block.d.mts +62 -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 +47 -0
- package/dist/helpers/define-datasource-entry.cjs.map +1 -0
- package/dist/helpers/define-datasource-entry.d.cts +49 -0
- package/dist/helpers/define-datasource-entry.d.mts +49 -0
- package/dist/helpers/define-datasource-entry.mjs +43 -0
- package/dist/helpers/define-datasource-entry.mjs.map +1 -0
- package/dist/helpers/define-datasource.cjs +34 -0
- package/dist/helpers/define-datasource.cjs.map +1 -0
- package/dist/helpers/define-datasource.d.cts +42 -0
- package/dist/helpers/define-datasource.d.mts +42 -0
- package/dist/helpers/define-datasource.mjs +31 -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 +99 -0
- package/dist/helpers/define-field.d.mts +99 -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 +41 -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 +38 -0
- package/dist/helpers/define-internal-tag.mjs.map +1 -0
- package/dist/helpers/define-link.cjs +23 -0
- package/dist/helpers/define-link.cjs.map +1 -0
- package/dist/helpers/define-link.d.cts +32 -0
- package/dist/helpers/define-link.d.mts +32 -0
- package/dist/helpers/define-link.mjs +22 -0
- package/dist/helpers/define-link.mjs.map +1 -0
- package/dist/helpers/define-preset.cjs +44 -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 +41 -0
- package/dist/helpers/define-preset.mjs.map +1 -0
- package/dist/helpers/define-space.cjs +47 -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 +44 -0
- package/dist/helpers/define-space.mjs.map +1 -0
- package/dist/helpers/define-story.cjs +122 -0
- package/dist/helpers/define-story.cjs.map +1 -0
- package/dist/helpers/define-story.d.cts +135 -0
- package/dist/helpers/define-story.d.mts +135 -0
- package/dist/helpers/define-story.mjs +118 -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 +50 -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 +48 -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 +23 -0
- package/dist/index.d.mts +23 -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 +78 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ComponentCreate, ComponentUpdate } from "../generated/mapi/_internal.gen.mjs";
|
|
2
|
+
import { Block, BlockSchema, BlockSchemaInput, NestableBlock, RootBlock, SchemaArrayToRecord } from "../generated/types/block.mjs";
|
|
3
|
+
import { Prettify } from "../utils/prettify.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/helpers/define-block.d.ts
|
|
6
|
+
declare const BLOCK_DEFAULTS: {
|
|
7
|
+
id: number;
|
|
8
|
+
created_at: string;
|
|
9
|
+
updated_at: string;
|
|
10
|
+
is_root: boolean;
|
|
11
|
+
is_nestable: boolean;
|
|
12
|
+
component_group_uuid: null;
|
|
13
|
+
};
|
|
14
|
+
/** Fields that have safe defaults and may be omitted from block input. */
|
|
15
|
+
type BlockOptional = keyof typeof BLOCK_DEFAULTS;
|
|
16
|
+
type BlockInput<TName extends string = string, TInputSchema extends BlockSchemaInput = BlockSchemaInput, TIsRoot extends boolean = false, TIsNestable extends boolean = true, TComponentGroupUuid extends string | null = null> = Prettify<Omit<Block, 'name' | 'schema' | 'is_root' | 'is_nestable' | 'component_group_uuid' | BlockOptional> & {
|
|
17
|
+
name: TName;
|
|
18
|
+
schema: TInputSchema;
|
|
19
|
+
is_root?: TIsRoot;
|
|
20
|
+
is_nestable?: TIsNestable;
|
|
21
|
+
component_group_uuid?: TComponentGroupUuid;
|
|
22
|
+
} & Partial<Pick<Block, Exclude<BlockOptional, 'is_root' | 'is_nestable' | 'component_group_uuid'>>>>;
|
|
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'> & {
|
|
24
|
+
name: TName;
|
|
25
|
+
schema: TBlockSchema;
|
|
26
|
+
is_root: TIsRoot;
|
|
27
|
+
is_nestable: TIsNestable;
|
|
28
|
+
component_group_uuid: TComponentGroupUuid;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Returns a {@link Block} with object-shape `schema` (matches the MAPI wire
|
|
32
|
+
* shape). The user-facing input is an ordered array of `defineField` calls;
|
|
33
|
+
* the array index becomes the field's `pos` in the returned map. Throws if
|
|
34
|
+
* two fields share the same `name`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const pageBlock = defineBlock({
|
|
38
|
+
* name: 'page',
|
|
39
|
+
* is_root: true,
|
|
40
|
+
* schema: [
|
|
41
|
+
* defineField('headline', { type: 'text', required: true }),
|
|
42
|
+
* ],
|
|
43
|
+
* });
|
|
44
|
+
*/
|
|
45
|
+
declare function defineBlock<TName extends string, const TInputSchema extends BlockSchemaInput, TIsRoot extends boolean = false, TIsNestable extends boolean = true, TComponentGroupUuid extends string | null = null>(block: BlockInput<TName, TInputSchema, TIsRoot, TIsNestable, TComponentGroupUuid>): DefinedBlock<TName, SchemaArrayToRecord<TInputSchema>, TIsRoot, TIsNestable, TComponentGroupUuid>;
|
|
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;
|
|
60
|
+
//#endregion
|
|
61
|
+
export { defineBlock, defineBlockCreate, defineBlockUpdate };
|
|
62
|
+
//# sourceMappingURL=define-block.d.mts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//#region src/helpers/define-block.ts
|
|
2
|
+
const BLOCK_DEFAULTS = {
|
|
3
|
+
id: 1,
|
|
4
|
+
created_at: "",
|
|
5
|
+
updated_at: "",
|
|
6
|
+
is_root: false,
|
|
7
|
+
is_nestable: true,
|
|
8
|
+
component_group_uuid: null
|
|
9
|
+
};
|
|
10
|
+
function defineBlock(block) {
|
|
11
|
+
const inputSchema = Array.isArray(block?.schema) ? block.schema : [];
|
|
12
|
+
const seen = /* @__PURE__ */ new Set();
|
|
13
|
+
const schemaRecord = {};
|
|
14
|
+
inputSchema.forEach((field, index) => {
|
|
15
|
+
const name = field?.name;
|
|
16
|
+
if (typeof name !== "string") return;
|
|
17
|
+
if (seen.has(name)) throw new Error(`defineBlock: duplicate field name "${name}" in block "${block?.name ?? ""}"`);
|
|
18
|
+
seen.add(name);
|
|
19
|
+
const { name: _name, ...rest } = field;
|
|
20
|
+
schemaRecord[name] = {
|
|
21
|
+
...rest,
|
|
22
|
+
pos: index
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
...BLOCK_DEFAULTS,
|
|
27
|
+
...block,
|
|
28
|
+
schema: schemaRecord
|
|
29
|
+
};
|
|
30
|
+
}
|
|
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
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { defineBlock, defineBlockCreate, defineBlockUpdate };
|
|
48
|
+
//# sourceMappingURL=define-block.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-block.mjs","names":[],"sources":["../../src/helpers/define-block.ts"],"sourcesContent":["import type {\n Block,\n BlockSchema,\n BlockSchemaInput,\n ComponentCreate,\n ComponentUpdate,\n NestableBlock,\n RootBlock,\n SchemaArrayToRecord,\n} from '../generated/types/block';\nimport type { Prettify } from '../utils/prettify';\n\nexport type { Block, BlockSchema, BlockSchemaInput, NestableBlock, RootBlock, SchemaArrayToRecord };\n\nconst BLOCK_DEFAULTS = {\n id: 1,\n created_at: '',\n updated_at: '',\n is_root: false,\n is_nestable: true,\n component_group_uuid: null,\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 TInputSchema extends BlockSchemaInput = BlockSchemaInput,\n TIsRoot extends boolean = false,\n TIsNestable extends boolean = true,\n TComponentGroupUuid extends string | null = null,\n> = Prettify<\n Omit<Block, 'name' | 'schema' | 'is_root' | 'is_nestable' | 'component_group_uuid' | BlockOptional> & {\n name: TName;\n schema: TInputSchema;\n is_root?: TIsRoot;\n is_nestable?: TIsNestable;\n component_group_uuid?: TComponentGroupUuid;\n } & Partial<Pick<Block, Exclude<BlockOptional, 'is_root' | 'is_nestable' | 'component_group_uuid'>>>\n>;\n\ntype DefinedBlock<\n TName extends string,\n TBlockSchema,\n TIsRoot extends boolean,\n TIsNestable extends boolean,\n TComponentGroupUuid extends string | null,\n> = Prettify<\n Omit<Block, 'name' | 'schema' | 'is_root' | 'is_nestable' | 'component_group_uuid'> & {\n name: TName;\n schema: TBlockSchema;\n is_root: TIsRoot;\n is_nestable: TIsNestable;\n component_group_uuid: TComponentGroupUuid;\n }\n>;\n\n/**\n * Returns a {@link Block} with object-shape `schema` (matches the MAPI wire\n * shape). The user-facing input is an ordered array of `defineField` calls;\n * the array index becomes the field's `pos` in the returned map. Throws if\n * two fields share the same `name`.\n *\n * @example\n * const pageBlock = defineBlock({\n * name: 'page',\n * is_root: true,\n * schema: [\n * defineField('headline', { type: 'text', required: true }),\n * ],\n * });\n */\nexport function defineBlock<\n TName extends string,\n const TInputSchema extends BlockSchemaInput,\n TIsRoot extends boolean = false,\n TIsNestable extends boolean = true,\n TComponentGroupUuid extends string | null = null,\n>(\n block: BlockInput<TName, TInputSchema, TIsRoot, TIsNestable, TComponentGroupUuid>,\n): DefinedBlock<TName, SchemaArrayToRecord<TInputSchema>, TIsRoot, TIsNestable, TComponentGroupUuid>;\n\nexport function defineBlock(block: any) {\n const inputSchema = Array.isArray(block?.schema) ? block.schema : [];\n const seen = new Set<string>();\n const schemaRecord: Record<string, unknown> = {};\n inputSchema.forEach((field: any, index: number) => {\n const name = field?.name;\n if (typeof name !== 'string') {\n return;\n }\n if (seen.has(name)) {\n throw new Error(`defineBlock: duplicate field name \"${name}\" in block \"${block?.name ?? ''}\"`);\n }\n seen.add(name);\n const { name: _name, ...rest } = field;\n schemaRecord[name] = { ...rest, pos: index };\n });\n return { ...BLOCK_DEFAULTS, ...block, schema: schemaRecord };\n}\n\n/**\n * Defines a block creation payload for the MAPI.\n *\n * @example\n * const payload = defineBlockCreate({ name: 'page', schema: { ... } });\n */\nexport const defineBlockCreate = (block: ComponentCreate): ComponentCreate => block;\n\n/**\n * Defines a block update payload for the MAPI.\n *\n * @example\n * const payload = defineBlockUpdate({ display_name: 'Page' });\n */\nexport const defineBlockUpdate = (block: ComponentUpdate): ComponentUpdate => block;\n"],"mappings":";AAcA,MAAM,iBAAiB;CACrB,IAAI;CACJ,YAAY;CACZ,YAAY;CACZ,SAAS;CACT,aAAa;CACb,sBAAsB;CACvB;AA8DD,SAAgB,YAAY,OAAY;CACtC,MAAM,cAAc,MAAM,QAAQ,OAAO,OAAO,GAAG,MAAM,SAAS,EAAE;CACpE,MAAM,uBAAO,IAAI,KAAa;CAC9B,MAAM,eAAwC,EAAE;AAChD,aAAY,SAAS,OAAY,UAAkB;EACjD,MAAM,OAAO,OAAO;AACpB,MAAI,OAAO,SAAS,SAClB;AAEF,MAAI,KAAK,IAAI,KAAK,CAChB,OAAM,IAAI,MAAM,sCAAsC,KAAK,cAAc,OAAO,QAAQ,GAAG,GAAG;AAEhG,OAAK,IAAI,KAAK;EACd,MAAM,EAAE,MAAM,OAAO,GAAG,SAAS;AACjC,eAAa,QAAQ;GAAE,GAAG;GAAM,KAAK;GAAO;GAC5C;AACF,QAAO;EAAE,GAAG;EAAgB,GAAG;EAAO,QAAQ;EAAc;;;;;;;;AAS9D,MAAa,qBAAqB,UAA4C;;;;;;;AAQ9E,MAAa,qBAAqB,UAA4C"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/helpers/define-datasource-entry.ts
|
|
3
|
+
const DATASOURCE_ENTRY_DEFAULTS = {
|
|
4
|
+
id: 1,
|
|
5
|
+
value: "",
|
|
6
|
+
dimension_value: null
|
|
7
|
+
};
|
|
8
|
+
function defineDatasourceEntry(datasourceEntry) {
|
|
9
|
+
return {
|
|
10
|
+
...DATASOURCE_ENTRY_DEFAULTS,
|
|
11
|
+
...datasourceEntry
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Returns a full {@link MapiDatasourceEntry} (MAPI shape) with all fields populated.
|
|
16
|
+
* Requires `datasource_id` to identify which datasource the entry belongs to.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const entry = defineMapiDatasourceEntry({ name: 'red', datasource_id: 42 });
|
|
20
|
+
*/
|
|
21
|
+
const defineMapiDatasourceEntry = (entry) => ({
|
|
22
|
+
...DATASOURCE_ENTRY_DEFAULTS,
|
|
23
|
+
...entry,
|
|
24
|
+
value: entry.value ?? DATASOURCE_ENTRY_DEFAULTS.value,
|
|
25
|
+
dimension_value: entry.dimension_value ?? DATASOURCE_ENTRY_DEFAULTS.dimension_value
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Defines a datasource entry creation payload for the MAPI.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const payload = defineDatasourceEntryCreate({ name: 'red', value: '#ff0000', datasource_id: 42 });
|
|
32
|
+
*/
|
|
33
|
+
const defineDatasourceEntryCreate = (entry) => entry;
|
|
34
|
+
/**
|
|
35
|
+
* Defines a datasource entry update payload for the MAPI.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const payload = defineDatasourceEntryUpdate({ value: '#ff0000' });
|
|
39
|
+
*/
|
|
40
|
+
const defineDatasourceEntryUpdate = (entry) => entry;
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
exports.defineDatasourceEntry = defineDatasourceEntry;
|
|
44
|
+
exports.defineDatasourceEntryCreate = defineDatasourceEntryCreate;
|
|
45
|
+
exports.defineDatasourceEntryUpdate = defineDatasourceEntryUpdate;
|
|
46
|
+
exports.defineMapiDatasourceEntry = defineMapiDatasourceEntry;
|
|
47
|
+
//# sourceMappingURL=define-datasource-entry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-datasource-entry.cjs","names":[],"sources":["../../src/helpers/define-datasource-entry.ts"],"sourcesContent":["import type { DatasourceEntry as CapiDatasourceEntry } from '../generated/capi/types.gen';\nimport type { DatasourceEntryCreate, DatasourceEntryUpdate, MapiDatasourceEntry as MapiDatasourceEntryGenerated } from '../generated/mapi/types.gen';\nimport type { Prettify } from '../utils/prettify';\n\nconst DATASOURCE_ENTRY_DEFAULTS = {\n id: 1,\n value: '',\n dimension_value: null,\n};\n\nexport type DatasourceEntry = CapiDatasourceEntry;\nexport type MapiDatasourceEntry = MapiDatasourceEntryGenerated;\nexport type { DatasourceEntryCreate, DatasourceEntryUpdate };\n\ntype DatasourceEntryOptional = keyof typeof DATASOURCE_ENTRY_DEFAULTS;\n\ntype DatasourceEntryInput = Prettify<\n Omit<CapiDatasourceEntry, DatasourceEntryOptional>\n & Partial<Pick<CapiDatasourceEntry, DatasourceEntryOptional>>\n>;\n\ntype MapiDatasourceEntryInput = { name: string } & Partial<Omit<MapiDatasourceEntryGenerated, 'name'>>;\n\n/**\n * Returns a full {@link DatasourceEntry} (CDN shape) with all fields populated.\n *\n * @example\n * const entry = defineDatasourceEntry({ name: 'red', value: '#ff0000' });\n */\nexport function defineDatasourceEntry(datasourceEntry: DatasourceEntryInput): DatasourceEntry;\n\nexport function defineDatasourceEntry(datasourceEntry: any) {\n return { ...DATASOURCE_ENTRY_DEFAULTS, ...datasourceEntry };\n}\n\n/**\n * Returns a full {@link MapiDatasourceEntry} (MAPI shape) with all fields populated.\n * Requires `datasource_id` to identify which datasource the entry belongs to.\n *\n * @example\n * const entry = defineMapiDatasourceEntry({ name: 'red', datasource_id: 42 });\n */\nexport const defineMapiDatasourceEntry = (entry: MapiDatasourceEntryInput): MapiDatasourceEntry => ({\n ...DATASOURCE_ENTRY_DEFAULTS,\n ...entry,\n value: entry.value ?? DATASOURCE_ENTRY_DEFAULTS.value,\n dimension_value: entry.dimension_value ?? DATASOURCE_ENTRY_DEFAULTS.dimension_value,\n});\n\n/**\n * Defines a datasource entry creation payload for the MAPI.\n *\n * @example\n * const payload = defineDatasourceEntryCreate({ name: 'red', value: '#ff0000', datasource_id: 42 });\n */\nexport const defineDatasourceEntryCreate = (entry: DatasourceEntryCreate): DatasourceEntryCreate => entry;\n\n/**\n * Defines a datasource entry update payload for the MAPI.\n *\n * @example\n * const payload = defineDatasourceEntryUpdate({ value: '#ff0000' });\n */\nexport const defineDatasourceEntryUpdate = (entry: DatasourceEntryUpdate): DatasourceEntryUpdate => entry;\n"],"mappings":";;AAIA,MAAM,4BAA4B;CAChC,IAAI;CACJ,OAAO;CACP,iBAAiB;CAClB;AAuBD,SAAgB,sBAAsB,iBAAsB;AAC1D,QAAO;EAAE,GAAG;EAA2B,GAAG;EAAiB;;;;;;;;;AAU7D,MAAa,6BAA6B,WAA0D;CAClG,GAAG;CACH,GAAG;CACH,OAAO,MAAM,SAAS,0BAA0B;CAChD,iBAAiB,MAAM,mBAAmB,0BAA0B;CACrE;;;;;;;AAQD,MAAa,+BAA+B,UAAwD;;;;;;;AAQpG,MAAa,+BAA+B,UAAwD"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Prettify } from "../utils/prettify.cjs";
|
|
2
|
+
import { DatasourceEntry as DatasourceEntry$1 } from "../generated/capi/types.gen.cjs";
|
|
3
|
+
import { DatasourceEntryCreate, DatasourceEntryUpdate, MapiDatasourceEntry as MapiDatasourceEntry$1 } from "../generated/mapi/types.gen.cjs";
|
|
4
|
+
|
|
5
|
+
//#region src/helpers/define-datasource-entry.d.ts
|
|
6
|
+
declare const DATASOURCE_ENTRY_DEFAULTS: {
|
|
7
|
+
id: number;
|
|
8
|
+
value: string;
|
|
9
|
+
dimension_value: null;
|
|
10
|
+
};
|
|
11
|
+
type DatasourceEntry = DatasourceEntry$1;
|
|
12
|
+
type MapiDatasourceEntry = MapiDatasourceEntry$1;
|
|
13
|
+
type DatasourceEntryOptional = keyof typeof DATASOURCE_ENTRY_DEFAULTS;
|
|
14
|
+
type DatasourceEntryInput = Prettify<Omit<DatasourceEntry$1, DatasourceEntryOptional> & Partial<Pick<DatasourceEntry$1, DatasourceEntryOptional>>>;
|
|
15
|
+
type MapiDatasourceEntryInput = {
|
|
16
|
+
name: string;
|
|
17
|
+
} & Partial<Omit<MapiDatasourceEntry$1, 'name'>>;
|
|
18
|
+
/**
|
|
19
|
+
* Returns a full {@link DatasourceEntry} (CDN shape) with all fields populated.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const entry = defineDatasourceEntry({ name: 'red', value: '#ff0000' });
|
|
23
|
+
*/
|
|
24
|
+
declare function defineDatasourceEntry(datasourceEntry: DatasourceEntryInput): DatasourceEntry;
|
|
25
|
+
/**
|
|
26
|
+
* Returns a full {@link MapiDatasourceEntry} (MAPI shape) with all fields populated.
|
|
27
|
+
* Requires `datasource_id` to identify which datasource the entry belongs to.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const entry = defineMapiDatasourceEntry({ name: 'red', datasource_id: 42 });
|
|
31
|
+
*/
|
|
32
|
+
declare const defineMapiDatasourceEntry: (entry: MapiDatasourceEntryInput) => MapiDatasourceEntry;
|
|
33
|
+
/**
|
|
34
|
+
* Defines a datasource entry creation payload for the MAPI.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const payload = defineDatasourceEntryCreate({ name: 'red', value: '#ff0000', datasource_id: 42 });
|
|
38
|
+
*/
|
|
39
|
+
declare const defineDatasourceEntryCreate: (entry: DatasourceEntryCreate) => DatasourceEntryCreate;
|
|
40
|
+
/**
|
|
41
|
+
* Defines a datasource entry update payload for the MAPI.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* const payload = defineDatasourceEntryUpdate({ value: '#ff0000' });
|
|
45
|
+
*/
|
|
46
|
+
declare const defineDatasourceEntryUpdate: (entry: DatasourceEntryUpdate) => DatasourceEntryUpdate;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { DatasourceEntry, MapiDatasourceEntry, defineDatasourceEntry, defineDatasourceEntryCreate, defineDatasourceEntryUpdate, defineMapiDatasourceEntry };
|
|
49
|
+
//# sourceMappingURL=define-datasource-entry.d.cts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Prettify } from "../utils/prettify.mjs";
|
|
2
|
+
import { DatasourceEntry as DatasourceEntry$1 } from "../generated/capi/types.gen.mjs";
|
|
3
|
+
import { DatasourceEntryCreate, DatasourceEntryUpdate, MapiDatasourceEntry as MapiDatasourceEntry$1 } from "../generated/mapi/types.gen.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/helpers/define-datasource-entry.d.ts
|
|
6
|
+
declare const DATASOURCE_ENTRY_DEFAULTS: {
|
|
7
|
+
id: number;
|
|
8
|
+
value: string;
|
|
9
|
+
dimension_value: null;
|
|
10
|
+
};
|
|
11
|
+
type DatasourceEntry = DatasourceEntry$1;
|
|
12
|
+
type MapiDatasourceEntry = MapiDatasourceEntry$1;
|
|
13
|
+
type DatasourceEntryOptional = keyof typeof DATASOURCE_ENTRY_DEFAULTS;
|
|
14
|
+
type DatasourceEntryInput = Prettify<Omit<DatasourceEntry$1, DatasourceEntryOptional> & Partial<Pick<DatasourceEntry$1, DatasourceEntryOptional>>>;
|
|
15
|
+
type MapiDatasourceEntryInput = {
|
|
16
|
+
name: string;
|
|
17
|
+
} & Partial<Omit<MapiDatasourceEntry$1, 'name'>>;
|
|
18
|
+
/**
|
|
19
|
+
* Returns a full {@link DatasourceEntry} (CDN shape) with all fields populated.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const entry = defineDatasourceEntry({ name: 'red', value: '#ff0000' });
|
|
23
|
+
*/
|
|
24
|
+
declare function defineDatasourceEntry(datasourceEntry: DatasourceEntryInput): DatasourceEntry;
|
|
25
|
+
/**
|
|
26
|
+
* Returns a full {@link MapiDatasourceEntry} (MAPI shape) with all fields populated.
|
|
27
|
+
* Requires `datasource_id` to identify which datasource the entry belongs to.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const entry = defineMapiDatasourceEntry({ name: 'red', datasource_id: 42 });
|
|
31
|
+
*/
|
|
32
|
+
declare const defineMapiDatasourceEntry: (entry: MapiDatasourceEntryInput) => MapiDatasourceEntry;
|
|
33
|
+
/**
|
|
34
|
+
* Defines a datasource entry creation payload for the MAPI.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const payload = defineDatasourceEntryCreate({ name: 'red', value: '#ff0000', datasource_id: 42 });
|
|
38
|
+
*/
|
|
39
|
+
declare const defineDatasourceEntryCreate: (entry: DatasourceEntryCreate) => DatasourceEntryCreate;
|
|
40
|
+
/**
|
|
41
|
+
* Defines a datasource entry update payload for the MAPI.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* const payload = defineDatasourceEntryUpdate({ value: '#ff0000' });
|
|
45
|
+
*/
|
|
46
|
+
declare const defineDatasourceEntryUpdate: (entry: DatasourceEntryUpdate) => DatasourceEntryUpdate;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { DatasourceEntry, MapiDatasourceEntry, defineDatasourceEntry, defineDatasourceEntryCreate, defineDatasourceEntryUpdate, defineMapiDatasourceEntry };
|
|
49
|
+
//# sourceMappingURL=define-datasource-entry.d.mts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//#region src/helpers/define-datasource-entry.ts
|
|
2
|
+
const DATASOURCE_ENTRY_DEFAULTS = {
|
|
3
|
+
id: 1,
|
|
4
|
+
value: "",
|
|
5
|
+
dimension_value: null
|
|
6
|
+
};
|
|
7
|
+
function defineDatasourceEntry(datasourceEntry) {
|
|
8
|
+
return {
|
|
9
|
+
...DATASOURCE_ENTRY_DEFAULTS,
|
|
10
|
+
...datasourceEntry
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Returns a full {@link MapiDatasourceEntry} (MAPI shape) with all fields populated.
|
|
15
|
+
* Requires `datasource_id` to identify which datasource the entry belongs to.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const entry = defineMapiDatasourceEntry({ name: 'red', datasource_id: 42 });
|
|
19
|
+
*/
|
|
20
|
+
const defineMapiDatasourceEntry = (entry) => ({
|
|
21
|
+
...DATASOURCE_ENTRY_DEFAULTS,
|
|
22
|
+
...entry,
|
|
23
|
+
value: entry.value ?? DATASOURCE_ENTRY_DEFAULTS.value,
|
|
24
|
+
dimension_value: entry.dimension_value ?? DATASOURCE_ENTRY_DEFAULTS.dimension_value
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Defines a datasource entry creation payload for the MAPI.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const payload = defineDatasourceEntryCreate({ name: 'red', value: '#ff0000', datasource_id: 42 });
|
|
31
|
+
*/
|
|
32
|
+
const defineDatasourceEntryCreate = (entry) => entry;
|
|
33
|
+
/**
|
|
34
|
+
* Defines a datasource entry update payload for the MAPI.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const payload = defineDatasourceEntryUpdate({ value: '#ff0000' });
|
|
38
|
+
*/
|
|
39
|
+
const defineDatasourceEntryUpdate = (entry) => entry;
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { defineDatasourceEntry, defineDatasourceEntryCreate, defineDatasourceEntryUpdate, defineMapiDatasourceEntry };
|
|
43
|
+
//# sourceMappingURL=define-datasource-entry.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-datasource-entry.mjs","names":[],"sources":["../../src/helpers/define-datasource-entry.ts"],"sourcesContent":["import type { DatasourceEntry as CapiDatasourceEntry } from '../generated/capi/types.gen';\nimport type { DatasourceEntryCreate, DatasourceEntryUpdate, MapiDatasourceEntry as MapiDatasourceEntryGenerated } from '../generated/mapi/types.gen';\nimport type { Prettify } from '../utils/prettify';\n\nconst DATASOURCE_ENTRY_DEFAULTS = {\n id: 1,\n value: '',\n dimension_value: null,\n};\n\nexport type DatasourceEntry = CapiDatasourceEntry;\nexport type MapiDatasourceEntry = MapiDatasourceEntryGenerated;\nexport type { DatasourceEntryCreate, DatasourceEntryUpdate };\n\ntype DatasourceEntryOptional = keyof typeof DATASOURCE_ENTRY_DEFAULTS;\n\ntype DatasourceEntryInput = Prettify<\n Omit<CapiDatasourceEntry, DatasourceEntryOptional>\n & Partial<Pick<CapiDatasourceEntry, DatasourceEntryOptional>>\n>;\n\ntype MapiDatasourceEntryInput = { name: string } & Partial<Omit<MapiDatasourceEntryGenerated, 'name'>>;\n\n/**\n * Returns a full {@link DatasourceEntry} (CDN shape) with all fields populated.\n *\n * @example\n * const entry = defineDatasourceEntry({ name: 'red', value: '#ff0000' });\n */\nexport function defineDatasourceEntry(datasourceEntry: DatasourceEntryInput): DatasourceEntry;\n\nexport function defineDatasourceEntry(datasourceEntry: any) {\n return { ...DATASOURCE_ENTRY_DEFAULTS, ...datasourceEntry };\n}\n\n/**\n * Returns a full {@link MapiDatasourceEntry} (MAPI shape) with all fields populated.\n * Requires `datasource_id` to identify which datasource the entry belongs to.\n *\n * @example\n * const entry = defineMapiDatasourceEntry({ name: 'red', datasource_id: 42 });\n */\nexport const defineMapiDatasourceEntry = (entry: MapiDatasourceEntryInput): MapiDatasourceEntry => ({\n ...DATASOURCE_ENTRY_DEFAULTS,\n ...entry,\n value: entry.value ?? DATASOURCE_ENTRY_DEFAULTS.value,\n dimension_value: entry.dimension_value ?? DATASOURCE_ENTRY_DEFAULTS.dimension_value,\n});\n\n/**\n * Defines a datasource entry creation payload for the MAPI.\n *\n * @example\n * const payload = defineDatasourceEntryCreate({ name: 'red', value: '#ff0000', datasource_id: 42 });\n */\nexport const defineDatasourceEntryCreate = (entry: DatasourceEntryCreate): DatasourceEntryCreate => entry;\n\n/**\n * Defines a datasource entry update payload for the MAPI.\n *\n * @example\n * const payload = defineDatasourceEntryUpdate({ value: '#ff0000' });\n */\nexport const defineDatasourceEntryUpdate = (entry: DatasourceEntryUpdate): DatasourceEntryUpdate => entry;\n"],"mappings":";AAIA,MAAM,4BAA4B;CAChC,IAAI;CACJ,OAAO;CACP,iBAAiB;CAClB;AAuBD,SAAgB,sBAAsB,iBAAsB;AAC1D,QAAO;EAAE,GAAG;EAA2B,GAAG;EAAiB;;;;;;;;;AAU7D,MAAa,6BAA6B,WAA0D;CAClG,GAAG;CACH,GAAG;CACH,OAAO,MAAM,SAAS,0BAA0B;CAChD,iBAAiB,MAAM,mBAAmB,0BAA0B;CACrE;;;;;;;AAQD,MAAa,+BAA+B,UAAwD;;;;;;;AAQpG,MAAa,+BAA+B,UAAwD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/helpers/define-datasource.ts
|
|
3
|
+
const DATASOURCE_DEFAULTS = {
|
|
4
|
+
id: 1,
|
|
5
|
+
created_at: "",
|
|
6
|
+
updated_at: "",
|
|
7
|
+
dimensions: []
|
|
8
|
+
};
|
|
9
|
+
function defineDatasource(datasource) {
|
|
10
|
+
return {
|
|
11
|
+
...DATASOURCE_DEFAULTS,
|
|
12
|
+
...datasource
|
|
13
|
+
};
|
|
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
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
exports.defineDatasource = defineDatasource;
|
|
32
|
+
exports.defineDatasourceCreate = defineDatasourceCreate;
|
|
33
|
+
exports.defineDatasourceUpdate = defineDatasourceUpdate;
|
|
34
|
+
//# sourceMappingURL=define-datasource.cjs.map
|
|
@@ -0,0 +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 { DatasourceCreate, DatasourceUpdate } from '../generated/mapi/types.gen';\nimport type { Prettify } from '../utils/prettify';\n\nconst DATASOURCE_DEFAULTS = {\n id: 1,\n created_at: '',\n updated_at: '',\n dimensions: [],\n};\n\nexport type { Datasource, DatasourceCreate, DatasourceUpdate };\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 full {@link Datasource} with all fields populated. API-assigned\n * fields are optional and default to safe values.\n *\n * @example\n * const myDatasource = defineDatasource({\n * name: 'Colors',\n * slug: 'colors',\n * });\n */\n// Overload: provides the strict public signature for callers.\nexport function defineDatasource(datasource: DatasourceInput): Datasource;\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 defineDatasource(datasource: any) {\n return { ...DATASOURCE_DEFAULTS, ...datasource };\n}\n\n/**\n * Defines a datasource creation payload for the MAPI.\n *\n * @example\n * const payload = defineDatasourceCreate({ name: 'Colors', slug: 'colors' });\n */\nexport const defineDatasourceCreate = (datasource: DatasourceCreate): DatasourceCreate => datasource;\n\n/**\n * Defines a datasource update payload for the MAPI.\n *\n * @example\n * const payload = defineDatasourceUpdate({ name: 'Updated Colors' });\n */\nexport const defineDatasourceUpdate = (datasource: DatasourceUpdate): DatasourceUpdate => datasource;\n"],"mappings":";;AAIA,MAAM,sBAAsB;CAC1B,IAAI;CACJ,YAAY;CACZ,YAAY;CACZ,YAAY,EAAE;CACf;AAyBD,SAAgB,iBAAiB,YAAiB;AAChD,QAAO;EAAE,GAAG;EAAqB,GAAG;EAAY;;;;;;;;AASlD,MAAa,0BAA0B,eAAmD;;;;;;;AAQ1F,MAAa,0BAA0B,eAAmD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
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";
|
|
4
|
+
|
|
5
|
+
//#region src/helpers/define-datasource.d.ts
|
|
6
|
+
declare const DATASOURCE_DEFAULTS: {
|
|
7
|
+
id: number;
|
|
8
|
+
created_at: string;
|
|
9
|
+
updated_at: string;
|
|
10
|
+
dimensions: never[];
|
|
11
|
+
};
|
|
12
|
+
/** Fields that have safe defaults and may be omitted from datasource input. */
|
|
13
|
+
type DatasourceOptional = keyof typeof DATASOURCE_DEFAULTS;
|
|
14
|
+
type DatasourceInput = Prettify<Omit<Datasource, DatasourceOptional> & Partial<Pick<Datasource, DatasourceOptional>>>;
|
|
15
|
+
/**
|
|
16
|
+
* Returns a full {@link Datasource} with all fields populated. API-assigned
|
|
17
|
+
* fields are optional and default to safe values.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const myDatasource = defineDatasource({
|
|
21
|
+
* name: 'Colors',
|
|
22
|
+
* slug: 'colors',
|
|
23
|
+
* });
|
|
24
|
+
*/
|
|
25
|
+
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
|
+
//#endregion
|
|
41
|
+
export { defineDatasource, defineDatasourceCreate, defineDatasourceUpdate };
|
|
42
|
+
//# sourceMappingURL=define-datasource.d.cts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
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";
|
|
4
|
+
|
|
5
|
+
//#region src/helpers/define-datasource.d.ts
|
|
6
|
+
declare const DATASOURCE_DEFAULTS: {
|
|
7
|
+
id: number;
|
|
8
|
+
created_at: string;
|
|
9
|
+
updated_at: string;
|
|
10
|
+
dimensions: never[];
|
|
11
|
+
};
|
|
12
|
+
/** Fields that have safe defaults and may be omitted from datasource input. */
|
|
13
|
+
type DatasourceOptional = keyof typeof DATASOURCE_DEFAULTS;
|
|
14
|
+
type DatasourceInput = Prettify<Omit<Datasource, DatasourceOptional> & Partial<Pick<Datasource, DatasourceOptional>>>;
|
|
15
|
+
/**
|
|
16
|
+
* Returns a full {@link Datasource} with all fields populated. API-assigned
|
|
17
|
+
* fields are optional and default to safe values.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const myDatasource = defineDatasource({
|
|
21
|
+
* name: 'Colors',
|
|
22
|
+
* slug: 'colors',
|
|
23
|
+
* });
|
|
24
|
+
*/
|
|
25
|
+
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
|
+
//#endregion
|
|
41
|
+
export { defineDatasource, defineDatasourceCreate, defineDatasourceUpdate };
|
|
42
|
+
//# sourceMappingURL=define-datasource.d.mts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/helpers/define-datasource.ts
|
|
2
|
+
const DATASOURCE_DEFAULTS = {
|
|
3
|
+
id: 1,
|
|
4
|
+
created_at: "",
|
|
5
|
+
updated_at: "",
|
|
6
|
+
dimensions: []
|
|
7
|
+
};
|
|
8
|
+
function defineDatasource(datasource) {
|
|
9
|
+
return {
|
|
10
|
+
...DATASOURCE_DEFAULTS,
|
|
11
|
+
...datasource
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Defines a datasource creation payload for the MAPI.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const payload = defineDatasourceCreate({ name: 'Colors', slug: 'colors' });
|
|
19
|
+
*/
|
|
20
|
+
const defineDatasourceCreate = (datasource) => datasource;
|
|
21
|
+
/**
|
|
22
|
+
* Defines a datasource update payload for the MAPI.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const payload = defineDatasourceUpdate({ name: 'Updated Colors' });
|
|
26
|
+
*/
|
|
27
|
+
const defineDatasourceUpdate = (datasource) => datasource;
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { defineDatasource, defineDatasourceCreate, defineDatasourceUpdate };
|
|
31
|
+
//# sourceMappingURL=define-datasource.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-datasource.mjs","names":[],"sources":["../../src/helpers/define-datasource.ts"],"sourcesContent":["import type { Datasource } from '../generated/capi/types.gen';\nimport type { DatasourceCreate, DatasourceUpdate } from '../generated/mapi/types.gen';\nimport type { Prettify } from '../utils/prettify';\n\nconst DATASOURCE_DEFAULTS = {\n id: 1,\n created_at: '',\n updated_at: '',\n dimensions: [],\n};\n\nexport type { Datasource, DatasourceCreate, DatasourceUpdate };\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 full {@link Datasource} with all fields populated. API-assigned\n * fields are optional and default to safe values.\n *\n * @example\n * const myDatasource = defineDatasource({\n * name: 'Colors',\n * slug: 'colors',\n * });\n */\n// Overload: provides the strict public signature for callers.\nexport function defineDatasource(datasource: DatasourceInput): Datasource;\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 defineDatasource(datasource: any) {\n return { ...DATASOURCE_DEFAULTS, ...datasource };\n}\n\n/**\n * Defines a datasource creation payload for the MAPI.\n *\n * @example\n * const payload = defineDatasourceCreate({ name: 'Colors', slug: 'colors' });\n */\nexport const defineDatasourceCreate = (datasource: DatasourceCreate): DatasourceCreate => datasource;\n\n/**\n * Defines a datasource update payload for the MAPI.\n *\n * @example\n * const payload = defineDatasourceUpdate({ name: 'Updated Colors' });\n */\nexport const defineDatasourceUpdate = (datasource: DatasourceUpdate): DatasourceUpdate => datasource;\n"],"mappings":";AAIA,MAAM,sBAAsB;CAC1B,IAAI;CACJ,YAAY;CACZ,YAAY;CACZ,YAAY,EAAE;CACf;AAyBD,SAAgB,iBAAiB,YAAiB;AAChD,QAAO;EAAE,GAAG;EAAqB,GAAG;EAAY;;;;;;;;AASlD,MAAa,0BAA0B,eAAmD;;;;;;;AAQ1F,MAAa,0BAA0B,eAAmD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/helpers/define-field.ts
|
|
3
|
+
/**
|
|
4
|
+
* Returns a {@link Field} stamped with the given `name`. Use inside a
|
|
5
|
+
* {@link defineBlock} `schema` array — `pos` is inferred from array index.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* defineField('headline', { type: 'text', max_length: 100, required: true });
|
|
9
|
+
*/
|
|
10
|
+
const defineField = (name, field) => ({
|
|
11
|
+
...field,
|
|
12
|
+
name
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.defineField = defineField;
|
|
17
|
+
//# sourceMappingURL=define-field.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-field.cjs","names":[],"sources":["../../src/helpers/define-field.ts"],"sourcesContent":["import type {\n AssetFieldValue,\n Field,\n MultilinkFieldValue,\n PluginFieldValue,\n RichtextFieldValue,\n TableFieldValue,\n} from '../generated/types/field';\nimport type { Block } from './define-block';\nimport type { Prettify } from '../utils/prettify';\n\nexport type { Field };\n\n/** Loose variant of the generated `BlokContent` with `_uid` optional — used as the fallback for write operations when no block union is provided. */\ntype BlokContentLoose = {\n _uid?: string;\n component: string;\n _editable?: string | undefined;\n} & {\n [key: string]:\n | string\n | number\n | boolean\n | Array<string | AssetFieldValue | BlokContentLoose>\n | AssetFieldValue\n | MultilinkFieldValue\n | TableFieldValue\n | RichtextFieldValue\n | PluginFieldValue\n | undefined;\n};\n\n/** Keys in a schema record that have `required: true`. */\ntype RequiredFieldKeys<T> = {\n [K in keyof T]: T[K] extends { required: true } ? K : never\n}[keyof T];\n\n/** Keys in a schema record that do NOT have `required: true`. */\ntype OptionalFieldKeys<T> = Exclude<keyof T, RequiredFieldKeys<T>>;\n\n/**\n * Builds the content object for a single block instance as returned by the\n * Storyblok Content Delivery API. Includes `_uid` (always present in API\n * responses) and respects required/optional field semantics.\n *\n * For write operations (creating/updating stories), use {@link BlockContentInput}\n * instead, which omits `_uid` since Storyblok generates it automatically.\n */\nexport type BlockContent<TBlock extends Block = Block, TBlocks = false> = TBlock extends any\n ? { _uid: string; component: TBlock['name'] }\n & {\n [K in RequiredFieldKeys<TBlock['schema']>]: FieldValue<NonNullable<TBlock['schema'][K]>, TBlocks>\n }\n & {\n [K in OptionalFieldKeys<TBlock['schema']>]?: FieldValue<NonNullable<TBlock['schema'][K]>, TBlocks> | null\n }\n : never;\n\n/**\n * Input variant of {@link BlockContent} for write operations (creating/updating\n * stories via the MAPI). `_uid` is optional — Storyblok generates it\n * automatically when omitted. Nested bloks fields also use this input variant\n * so that deeply nested blocks do not require `_uid` either.\n */\nexport type BlockContentInput<TBlock extends Block = Block, TBlocks = false> = TBlock extends any\n ? { _uid?: string; component: TBlock['name'] }\n & {\n [K in RequiredFieldKeys<TBlock['schema']>]: FieldValueInput<NonNullable<TBlock['schema'][K]>, TBlocks>\n }\n & {\n [K in OptionalFieldKeys<TBlock['schema']>]?: FieldValueInput<NonNullable<TBlock['schema'][K]>, TBlocks> | null\n }\n : never;\n\nexport type BlocksFieldValue<\n TBlock extends Block = Block,\n TBlocks = false,\n> = BlockContent<TBlock, TBlocks>[];\n\nexport type { AssetFieldValue, MultilinkFieldValue, PluginFieldValue, RichtextFieldValue, TableFieldValue };\n\n/** Union of all valid Storyblok field type discriminants (e.g., `text`, `bloks`). */\nexport type FieldType = Field['type'];\n\n/** Maps each field type discriminant to its runtime content value type. */\ninterface FieldTypeValueMap {\n text: string;\n textarea: string;\n richtext: RichtextFieldValue;\n markdown: string;\n number: number;\n datetime: string;\n boolean: boolean;\n option: string;\n options: string[];\n asset: AssetFieldValue;\n multiasset: AssetFieldValue[];\n multilink: MultilinkFieldValue;\n bloks: BlockContent[];\n table: TableFieldValue;\n section: never;\n tab: never;\n custom: PluginFieldValue;\n}\n\n/**\n * Checks whether a block is nestable, defaulting to `true` when\n * `is_nestable` is absent or undefined.\n */\ntype IsNestable<T> =\n T extends { is_nestable: false } ? false\n : T extends { is_nestable: true } ? true\n : true; // default: nestable when is_nestable is not specified\n\ntype ApplyWhitelist<TField, TBlocks> = TField extends { component_whitelist: ReadonlyArray<infer TWhitelisted extends string> }\n // With whitelist: filter by block name (distributive over TBlocks)\n ? TBlocks extends { name: TWhitelisted } ? TBlocks : never\n // No whitelist: filter by nestability (distributive over TBlocks)\n : TBlocks extends any\n ? IsNestable<TBlocks> extends true ? TBlocks : never\n : never;\n\n/** Resolves a field definition to its runtime content value type (read). */\nexport type FieldValue<\n TField extends Field = Field,\n TBlocks = false,\n> = Prettify<\n TField extends { type: 'bloks' }\n // Bloks field — guard against `never` first (it satisfies `[never] extends [X]`\n // for all X, which would incorrectly enter the typed path with empty results).\n ? [TBlocks] extends [never]\n ? BlockContent[]\n : [TBlocks] extends [Block]\n ? BlockContent<ApplyWhitelist<TField, TBlocks>, TBlocks>[]\n : BlockContent[]\n // No bloks field\n : FieldTypeValueMap[TField['type']]\n>;\n\n/** Resolves a field definition to its input value type (write). Nested bloks use {@link BlockContentInput}. */\nexport type FieldValueInput<\n TField extends Field = Field,\n TBlocks = false,\n> = Prettify<\n TField extends { type: 'bloks' }\n ? [TBlocks] extends [never]\n ? BlokContentLoose[]\n : [TBlocks] extends [Block]\n ? BlockContentInput<ApplyWhitelist<TField, TBlocks>, TBlocks>[]\n : BlokContentLoose[]\n : FieldTypeValueMap[TField['type']]\n>;\n\n/**\n * Returns a {@link Field} stamped with the given `name`. Use inside a\n * {@link defineBlock} `schema` array — `pos` is inferred from array index.\n *\n * @example\n * defineField('headline', { type: 'text', max_length: 100, required: true });\n */\nexport const defineField = <\n const TName extends string,\n const TField extends Field,\n>(\n name: TName,\n field: TField,\n): Omit<TField, 'name'> & { name: TName } => ({ ...field, name });\n"],"mappings":";;;;;;;;;AAgKA,MAAa,eAIX,MACA,WAC4C;CAAE,GAAG;CAAO;CAAM"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { AssetFieldValue, Field, MultilinkFieldValue, PluginFieldValue, RichtextFieldValue, TableFieldValue } from "../generated/overlay/_internal.gen.cjs";
|
|
2
|
+
import { Block } from "../generated/types/block.cjs";
|
|
3
|
+
import { Prettify } from "../utils/prettify.cjs";
|
|
4
|
+
|
|
5
|
+
//#region src/helpers/define-field.d.ts
|
|
6
|
+
/** Loose variant of the generated `BlokContent` with `_uid` optional — used as the fallback for write operations when no block union is provided. */
|
|
7
|
+
type BlokContentLoose = {
|
|
8
|
+
_uid?: string;
|
|
9
|
+
component: string;
|
|
10
|
+
_editable?: string | undefined;
|
|
11
|
+
} & {
|
|
12
|
+
[key: string]: string | number | boolean | Array<string | AssetFieldValue | BlokContentLoose> | AssetFieldValue | MultilinkFieldValue | TableFieldValue | RichtextFieldValue | PluginFieldValue | undefined;
|
|
13
|
+
};
|
|
14
|
+
/** Keys in a schema record that have `required: true`. */
|
|
15
|
+
type RequiredFieldKeys<T> = { [K in keyof T]: T[K] extends {
|
|
16
|
+
required: true;
|
|
17
|
+
} ? K : never }[keyof T];
|
|
18
|
+
/** Keys in a schema record that do NOT have `required: true`. */
|
|
19
|
+
type OptionalFieldKeys<T> = Exclude<keyof T, RequiredFieldKeys<T>>;
|
|
20
|
+
/**
|
|
21
|
+
* Builds the content object for a single block instance as returned by the
|
|
22
|
+
* Storyblok Content Delivery API. Includes `_uid` (always present in API
|
|
23
|
+
* responses) and respects required/optional field semantics.
|
|
24
|
+
*
|
|
25
|
+
* For write operations (creating/updating stories), use {@link BlockContentInput}
|
|
26
|
+
* instead, which omits `_uid` since Storyblok generates it automatically.
|
|
27
|
+
*/
|
|
28
|
+
type BlockContent<TBlock extends Block = Block, TBlocks = false> = TBlock extends any ? {
|
|
29
|
+
_uid: string;
|
|
30
|
+
component: TBlock['name'];
|
|
31
|
+
} & { [K in RequiredFieldKeys<TBlock['schema']>]: FieldValue<NonNullable<TBlock['schema'][K]>, TBlocks> } & { [K in OptionalFieldKeys<TBlock['schema']>]?: FieldValue<NonNullable<TBlock['schema'][K]>, TBlocks> | null } : never;
|
|
32
|
+
/**
|
|
33
|
+
* Input variant of {@link BlockContent} for write operations (creating/updating
|
|
34
|
+
* stories via the MAPI). `_uid` is optional — Storyblok generates it
|
|
35
|
+
* automatically when omitted. Nested bloks fields also use this input variant
|
|
36
|
+
* so that deeply nested blocks do not require `_uid` either.
|
|
37
|
+
*/
|
|
38
|
+
type BlockContentInput<TBlock extends Block = Block, TBlocks = false> = TBlock extends any ? {
|
|
39
|
+
_uid?: string;
|
|
40
|
+
component: TBlock['name'];
|
|
41
|
+
} & { [K in RequiredFieldKeys<TBlock['schema']>]: FieldValueInput<NonNullable<TBlock['schema'][K]>, TBlocks> } & { [K in OptionalFieldKeys<TBlock['schema']>]?: FieldValueInput<NonNullable<TBlock['schema'][K]>, TBlocks> | null } : never;
|
|
42
|
+
type BlocksFieldValue<TBlock extends Block = Block, TBlocks = false> = BlockContent<TBlock, TBlocks>[];
|
|
43
|
+
/** Union of all valid Storyblok field type discriminants (e.g., `text`, `bloks`). */
|
|
44
|
+
type FieldType = Field['type'];
|
|
45
|
+
/** Maps each field type discriminant to its runtime content value type. */
|
|
46
|
+
interface FieldTypeValueMap {
|
|
47
|
+
text: string;
|
|
48
|
+
textarea: string;
|
|
49
|
+
richtext: RichtextFieldValue;
|
|
50
|
+
markdown: string;
|
|
51
|
+
number: number;
|
|
52
|
+
datetime: string;
|
|
53
|
+
boolean: boolean;
|
|
54
|
+
option: string;
|
|
55
|
+
options: string[];
|
|
56
|
+
asset: AssetFieldValue;
|
|
57
|
+
multiasset: AssetFieldValue[];
|
|
58
|
+
multilink: MultilinkFieldValue;
|
|
59
|
+
bloks: BlockContent[];
|
|
60
|
+
table: TableFieldValue;
|
|
61
|
+
section: never;
|
|
62
|
+
tab: never;
|
|
63
|
+
custom: PluginFieldValue;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Checks whether a block is nestable, defaulting to `true` when
|
|
67
|
+
* `is_nestable` is absent or undefined.
|
|
68
|
+
*/
|
|
69
|
+
type IsNestable<T> = T extends {
|
|
70
|
+
is_nestable: false;
|
|
71
|
+
} ? false : T extends {
|
|
72
|
+
is_nestable: true;
|
|
73
|
+
} ? true : true;
|
|
74
|
+
type ApplyWhitelist<TField, TBlocks> = TField extends {
|
|
75
|
+
component_whitelist: ReadonlyArray<infer TWhitelisted extends string>;
|
|
76
|
+
} ? TBlocks extends {
|
|
77
|
+
name: TWhitelisted;
|
|
78
|
+
} ? TBlocks : never : TBlocks extends any ? IsNestable<TBlocks> extends true ? TBlocks : never : never;
|
|
79
|
+
/** Resolves a field definition to its runtime content value type (read). */
|
|
80
|
+
type FieldValue<TField extends Field = Field, TBlocks = false> = Prettify<TField extends {
|
|
81
|
+
type: 'bloks';
|
|
82
|
+
} ? [TBlocks] extends [never] ? BlockContent[] : [TBlocks] extends [Block] ? BlockContent<ApplyWhitelist<TField, TBlocks>, TBlocks>[] : BlockContent[] : FieldTypeValueMap[TField['type']]>;
|
|
83
|
+
/** Resolves a field definition to its input value type (write). Nested bloks use {@link BlockContentInput}. */
|
|
84
|
+
type FieldValueInput<TField extends Field = Field, TBlocks = false> = Prettify<TField extends {
|
|
85
|
+
type: 'bloks';
|
|
86
|
+
} ? [TBlocks] extends [never] ? BlokContentLoose[] : [TBlocks] extends [Block] ? BlockContentInput<ApplyWhitelist<TField, TBlocks>, TBlocks>[] : BlokContentLoose[] : FieldTypeValueMap[TField['type']]>;
|
|
87
|
+
/**
|
|
88
|
+
* Returns a {@link Field} stamped with the given `name`. Use inside a
|
|
89
|
+
* {@link defineBlock} `schema` array — `pos` is inferred from array index.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* defineField('headline', { type: 'text', max_length: 100, required: true });
|
|
93
|
+
*/
|
|
94
|
+
declare const defineField: <const TName extends string, const TField extends Field>(name: TName, field: TField) => Omit<TField, "name"> & {
|
|
95
|
+
name: TName;
|
|
96
|
+
};
|
|
97
|
+
//#endregion
|
|
98
|
+
export { BlockContent, BlockContentInput, BlocksFieldValue, FieldType, FieldValue, FieldValueInput, defineField };
|
|
99
|
+
//# sourceMappingURL=define-field.d.cts.map
|