@storyblok/schema 1.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/README.md +72 -0
  2. package/dist/generated/mapi-types.d.cts +732 -0
  3. package/dist/generated/mapi-types.d.mts +732 -0
  4. package/dist/generated/types.d.cts +155 -0
  5. package/dist/generated/types.d.mts +155 -0
  6. package/dist/helpers/create-story-helpers.cjs +42 -0
  7. package/dist/helpers/create-story-helpers.cjs.map +1 -0
  8. package/dist/helpers/create-story-helpers.d.cts +48 -0
  9. package/dist/helpers/create-story-helpers.d.mts +48 -0
  10. package/dist/helpers/create-story-helpers.mjs +42 -0
  11. package/dist/helpers/create-story-helpers.mjs.map +1 -0
  12. package/dist/helpers/define-asset-folder.cjs +40 -0
  13. package/dist/helpers/define-asset-folder.cjs.map +1 -0
  14. package/dist/helpers/define-asset-folder.d.cts +33 -0
  15. package/dist/helpers/define-asset-folder.d.mts +33 -0
  16. package/dist/helpers/define-asset-folder.mjs +37 -0
  17. package/dist/helpers/define-asset-folder.mjs.map +1 -0
  18. package/dist/helpers/define-asset.cjs +43 -0
  19. package/dist/helpers/define-asset.cjs.map +1 -0
  20. package/dist/helpers/define-asset.d.cts +32 -0
  21. package/dist/helpers/define-asset.d.mts +32 -0
  22. package/dist/helpers/define-asset.mjs +40 -0
  23. package/dist/helpers/define-asset.mjs.map +1 -0
  24. package/dist/helpers/define-block-folder.cjs +40 -0
  25. package/dist/helpers/define-block-folder.cjs.map +1 -0
  26. package/dist/helpers/define-block-folder.d.cts +34 -0
  27. package/dist/helpers/define-block-folder.d.mts +34 -0
  28. package/dist/helpers/define-block-folder.mjs +37 -0
  29. package/dist/helpers/define-block-folder.mjs.map +1 -0
  30. package/dist/helpers/define-block.cjs +51 -0
  31. package/dist/helpers/define-block.cjs.map +1 -0
  32. package/dist/helpers/define-block.d.cts +90 -0
  33. package/dist/helpers/define-block.d.mts +90 -0
  34. package/dist/helpers/define-block.mjs +48 -0
  35. package/dist/helpers/define-block.mjs.map +1 -0
  36. package/dist/helpers/define-datasource-entry.cjs +41 -0
  37. package/dist/helpers/define-datasource-entry.cjs.map +1 -0
  38. package/dist/helpers/define-datasource-entry.d.cts +48 -0
  39. package/dist/helpers/define-datasource-entry.d.mts +48 -0
  40. package/dist/helpers/define-datasource-entry.mjs +37 -0
  41. package/dist/helpers/define-datasource-entry.mjs.map +1 -0
  42. package/dist/helpers/define-datasource.cjs +33 -0
  43. package/dist/helpers/define-datasource.cjs.map +1 -0
  44. package/dist/helpers/define-datasource.d.cts +41 -0
  45. package/dist/helpers/define-datasource.d.mts +41 -0
  46. package/dist/helpers/define-datasource.mjs +30 -0
  47. package/dist/helpers/define-datasource.mjs.map +1 -0
  48. package/dist/helpers/define-field.cjs +17 -0
  49. package/dist/helpers/define-field.cjs.map +1 -0
  50. package/dist/helpers/define-field.d.cts +100 -0
  51. package/dist/helpers/define-field.d.mts +100 -0
  52. package/dist/helpers/define-field.mjs +16 -0
  53. package/dist/helpers/define-field.mjs.map +1 -0
  54. package/dist/helpers/define-internal-tag.cjs +37 -0
  55. package/dist/helpers/define-internal-tag.cjs.map +1 -0
  56. package/dist/helpers/define-internal-tag.d.cts +34 -0
  57. package/dist/helpers/define-internal-tag.d.mts +34 -0
  58. package/dist/helpers/define-internal-tag.mjs +34 -0
  59. package/dist/helpers/define-internal-tag.mjs.map +1 -0
  60. package/dist/helpers/define-link.cjs +22 -0
  61. package/dist/helpers/define-link.cjs.map +1 -0
  62. package/dist/helpers/define-link.d.cts +31 -0
  63. package/dist/helpers/define-link.d.mts +31 -0
  64. package/dist/helpers/define-link.mjs +21 -0
  65. package/dist/helpers/define-link.mjs.map +1 -0
  66. package/dist/helpers/define-preset.cjs +37 -0
  67. package/dist/helpers/define-preset.cjs.map +1 -0
  68. package/dist/helpers/define-preset.d.cts +35 -0
  69. package/dist/helpers/define-preset.d.mts +35 -0
  70. package/dist/helpers/define-preset.mjs +34 -0
  71. package/dist/helpers/define-preset.mjs.map +1 -0
  72. package/dist/helpers/define-space.cjs +34 -0
  73. package/dist/helpers/define-space.cjs.map +1 -0
  74. package/dist/helpers/define-space.d.cts +31 -0
  75. package/dist/helpers/define-space.d.mts +31 -0
  76. package/dist/helpers/define-space.mjs +31 -0
  77. package/dist/helpers/define-space.mjs.map +1 -0
  78. package/dist/helpers/define-story.cjs +94 -0
  79. package/dist/helpers/define-story.cjs.map +1 -0
  80. package/dist/helpers/define-story.d.cts +127 -0
  81. package/dist/helpers/define-story.d.mts +127 -0
  82. package/dist/helpers/define-story.mjs +90 -0
  83. package/dist/helpers/define-story.mjs.map +1 -0
  84. package/dist/helpers/define-tag.cjs +13 -0
  85. package/dist/helpers/define-tag.cjs.map +1 -0
  86. package/dist/helpers/define-tag.d.cts +23 -0
  87. package/dist/helpers/define-tag.d.mts +23 -0
  88. package/dist/helpers/define-tag.mjs +12 -0
  89. package/dist/helpers/define-tag.mjs.map +1 -0
  90. package/dist/helpers/define-user.cjs +32 -0
  91. package/dist/helpers/define-user.cjs.map +1 -0
  92. package/dist/helpers/define-user.d.cts +26 -0
  93. package/dist/helpers/define-user.d.mts +26 -0
  94. package/dist/helpers/define-user.mjs +30 -0
  95. package/dist/helpers/define-user.mjs.map +1 -0
  96. package/dist/helpers/schema-type.d.cts +40 -0
  97. package/dist/helpers/schema-type.d.mts +40 -0
  98. package/dist/index.cjs +55 -0
  99. package/dist/index.d.cts +19 -0
  100. package/dist/index.d.mts +19 -0
  101. package/dist/index.mjs +17 -0
  102. package/dist/utils/prettify.d.cts +9 -0
  103. package/dist/utils/prettify.d.mts +9 -0
  104. package/package.json +85 -0
@@ -0,0 +1,41 @@
1
+
2
+ //#region src/helpers/define-datasource-entry.ts
3
+ const DATASOURCE_ENTRY_DEFAULTS = { id: 1 };
4
+ function defineDatasourceEntry(datasourceEntry) {
5
+ return {
6
+ ...DATASOURCE_ENTRY_DEFAULTS,
7
+ ...datasourceEntry
8
+ };
9
+ }
10
+ /**
11
+ * Returns a full {@link MapiDatasourceEntry} (MAPI shape) with all fields populated.
12
+ * Requires `datasource_id` to identify which datasource the entry belongs to.
13
+ *
14
+ * @example
15
+ * const entry = defineMapiDatasourceEntry({ name: 'red', datasource_id: 42 });
16
+ */
17
+ const defineMapiDatasourceEntry = (entry) => ({
18
+ ...DATASOURCE_ENTRY_DEFAULTS,
19
+ ...entry
20
+ });
21
+ /**
22
+ * Defines a datasource entry creation payload for the MAPI.
23
+ *
24
+ * @example
25
+ * const payload = defineDatasourceEntryCreate({ name: 'red', value: '#ff0000', datasource_id: 42 });
26
+ */
27
+ const defineDatasourceEntryCreate = (entry) => entry;
28
+ /**
29
+ * Defines a datasource entry update payload for the MAPI.
30
+ *
31
+ * @example
32
+ * const payload = defineDatasourceEntryUpdate({ value: '#ff0000' });
33
+ */
34
+ const defineDatasourceEntryUpdate = (entry) => entry;
35
+
36
+ //#endregion
37
+ exports.defineDatasourceEntry = defineDatasourceEntry;
38
+ exports.defineDatasourceEntryCreate = defineDatasourceEntryCreate;
39
+ exports.defineDatasourceEntryUpdate = defineDatasourceEntryUpdate;
40
+ exports.defineMapiDatasourceEntry = defineMapiDatasourceEntry;
41
+ //# 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/types';\nimport type { DatasourceEntryCreate, DatasourceEntryUpdate, DatasourceEntry as MapiDatasourceEntryGenerated } from '../generated/mapi-types';\nimport type { Prettify } from '../utils/prettify';\n\nconst DATASOURCE_ENTRY_DEFAULTS = {\n id: 1,\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; datasource_id: number } & Partial<Omit<MapiDatasourceEntryGenerated, 'name' | 'datasource_id'>>;\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});\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,EAChC,IAAI,GACL;AAuBD,SAAgB,sBAAsB,iBAAsB;AAC1D,QAAO;EAAE,GAAG;EAA2B,GAAG;EAAiB;;;;;;;;;AAU7D,MAAa,6BAA6B,WAA0D;CAClG,GAAG;CACH,GAAG;CACJ;;;;;;;AAQD,MAAa,+BAA+B,UAAwD;;;;;;;AAQpG,MAAa,+BAA+B,UAAwD"}
@@ -0,0 +1,48 @@
1
+ import { DatasourceEntry as DatasourceEntry$1 } from "../generated/types.cjs";
2
+ import { DatasourceEntry as DatasourceEntry$2, DatasourceEntryCreate, DatasourceEntryUpdate } from "../generated/mapi-types.cjs";
3
+ import { Prettify } from "../utils/prettify.cjs";
4
+
5
+ //#region src/helpers/define-datasource-entry.d.ts
6
+ declare const DATASOURCE_ENTRY_DEFAULTS: {
7
+ id: number;
8
+ };
9
+ type DatasourceEntry = DatasourceEntry$1;
10
+ type MapiDatasourceEntry = DatasourceEntry$2;
11
+ type DatasourceEntryOptional = keyof typeof DATASOURCE_ENTRY_DEFAULTS;
12
+ type DatasourceEntryInput = Prettify<Omit<DatasourceEntry$1, DatasourceEntryOptional> & Partial<Pick<DatasourceEntry$1, DatasourceEntryOptional>>>;
13
+ type MapiDatasourceEntryInput = {
14
+ name: string;
15
+ datasource_id: number;
16
+ } & Partial<Omit<DatasourceEntry$2, 'name' | 'datasource_id'>>;
17
+ /**
18
+ * Returns a full {@link DatasourceEntry} (CDN shape) with all fields populated.
19
+ *
20
+ * @example
21
+ * const entry = defineDatasourceEntry({ name: 'red', value: '#ff0000' });
22
+ */
23
+ declare function defineDatasourceEntry(datasourceEntry: DatasourceEntryInput): DatasourceEntry;
24
+ /**
25
+ * Returns a full {@link MapiDatasourceEntry} (MAPI shape) with all fields populated.
26
+ * Requires `datasource_id` to identify which datasource the entry belongs to.
27
+ *
28
+ * @example
29
+ * const entry = defineMapiDatasourceEntry({ name: 'red', datasource_id: 42 });
30
+ */
31
+ declare const defineMapiDatasourceEntry: (entry: MapiDatasourceEntryInput) => MapiDatasourceEntry;
32
+ /**
33
+ * Defines a datasource entry creation payload for the MAPI.
34
+ *
35
+ * @example
36
+ * const payload = defineDatasourceEntryCreate({ name: 'red', value: '#ff0000', datasource_id: 42 });
37
+ */
38
+ declare const defineDatasourceEntryCreate: (entry: DatasourceEntryCreate) => DatasourceEntryCreate;
39
+ /**
40
+ * Defines a datasource entry update payload for the MAPI.
41
+ *
42
+ * @example
43
+ * const payload = defineDatasourceEntryUpdate({ value: '#ff0000' });
44
+ */
45
+ declare const defineDatasourceEntryUpdate: (entry: DatasourceEntryUpdate) => DatasourceEntryUpdate;
46
+ //#endregion
47
+ export { DatasourceEntry, MapiDatasourceEntry, defineDatasourceEntry, defineDatasourceEntryCreate, defineDatasourceEntryUpdate, defineMapiDatasourceEntry };
48
+ //# sourceMappingURL=define-datasource-entry.d.cts.map
@@ -0,0 +1,48 @@
1
+ import { DatasourceEntry as DatasourceEntry$1 } from "../generated/types.mjs";
2
+ import { DatasourceEntry as DatasourceEntry$2, DatasourceEntryCreate, DatasourceEntryUpdate } from "../generated/mapi-types.mjs";
3
+ import { Prettify } from "../utils/prettify.mjs";
4
+
5
+ //#region src/helpers/define-datasource-entry.d.ts
6
+ declare const DATASOURCE_ENTRY_DEFAULTS: {
7
+ id: number;
8
+ };
9
+ type DatasourceEntry = DatasourceEntry$1;
10
+ type MapiDatasourceEntry = DatasourceEntry$2;
11
+ type DatasourceEntryOptional = keyof typeof DATASOURCE_ENTRY_DEFAULTS;
12
+ type DatasourceEntryInput = Prettify<Omit<DatasourceEntry$1, DatasourceEntryOptional> & Partial<Pick<DatasourceEntry$1, DatasourceEntryOptional>>>;
13
+ type MapiDatasourceEntryInput = {
14
+ name: string;
15
+ datasource_id: number;
16
+ } & Partial<Omit<DatasourceEntry$2, 'name' | 'datasource_id'>>;
17
+ /**
18
+ * Returns a full {@link DatasourceEntry} (CDN shape) with all fields populated.
19
+ *
20
+ * @example
21
+ * const entry = defineDatasourceEntry({ name: 'red', value: '#ff0000' });
22
+ */
23
+ declare function defineDatasourceEntry(datasourceEntry: DatasourceEntryInput): DatasourceEntry;
24
+ /**
25
+ * Returns a full {@link MapiDatasourceEntry} (MAPI shape) with all fields populated.
26
+ * Requires `datasource_id` to identify which datasource the entry belongs to.
27
+ *
28
+ * @example
29
+ * const entry = defineMapiDatasourceEntry({ name: 'red', datasource_id: 42 });
30
+ */
31
+ declare const defineMapiDatasourceEntry: (entry: MapiDatasourceEntryInput) => MapiDatasourceEntry;
32
+ /**
33
+ * Defines a datasource entry creation payload for the MAPI.
34
+ *
35
+ * @example
36
+ * const payload = defineDatasourceEntryCreate({ name: 'red', value: '#ff0000', datasource_id: 42 });
37
+ */
38
+ declare const defineDatasourceEntryCreate: (entry: DatasourceEntryCreate) => DatasourceEntryCreate;
39
+ /**
40
+ * Defines a datasource entry update payload for the MAPI.
41
+ *
42
+ * @example
43
+ * const payload = defineDatasourceEntryUpdate({ value: '#ff0000' });
44
+ */
45
+ declare const defineDatasourceEntryUpdate: (entry: DatasourceEntryUpdate) => DatasourceEntryUpdate;
46
+ //#endregion
47
+ export { DatasourceEntry, MapiDatasourceEntry, defineDatasourceEntry, defineDatasourceEntryCreate, defineDatasourceEntryUpdate, defineMapiDatasourceEntry };
48
+ //# sourceMappingURL=define-datasource-entry.d.mts.map
@@ -0,0 +1,37 @@
1
+ //#region src/helpers/define-datasource-entry.ts
2
+ const DATASOURCE_ENTRY_DEFAULTS = { id: 1 };
3
+ function defineDatasourceEntry(datasourceEntry) {
4
+ return {
5
+ ...DATASOURCE_ENTRY_DEFAULTS,
6
+ ...datasourceEntry
7
+ };
8
+ }
9
+ /**
10
+ * Returns a full {@link MapiDatasourceEntry} (MAPI shape) with all fields populated.
11
+ * Requires `datasource_id` to identify which datasource the entry belongs to.
12
+ *
13
+ * @example
14
+ * const entry = defineMapiDatasourceEntry({ name: 'red', datasource_id: 42 });
15
+ */
16
+ const defineMapiDatasourceEntry = (entry) => ({
17
+ ...DATASOURCE_ENTRY_DEFAULTS,
18
+ ...entry
19
+ });
20
+ /**
21
+ * Defines a datasource entry creation payload for the MAPI.
22
+ *
23
+ * @example
24
+ * const payload = defineDatasourceEntryCreate({ name: 'red', value: '#ff0000', datasource_id: 42 });
25
+ */
26
+ const defineDatasourceEntryCreate = (entry) => entry;
27
+ /**
28
+ * Defines a datasource entry update payload for the MAPI.
29
+ *
30
+ * @example
31
+ * const payload = defineDatasourceEntryUpdate({ value: '#ff0000' });
32
+ */
33
+ const defineDatasourceEntryUpdate = (entry) => entry;
34
+
35
+ //#endregion
36
+ export { defineDatasourceEntry, defineDatasourceEntryCreate, defineDatasourceEntryUpdate, defineMapiDatasourceEntry };
37
+ //# 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/types';\nimport type { DatasourceEntryCreate, DatasourceEntryUpdate, DatasourceEntry as MapiDatasourceEntryGenerated } from '../generated/mapi-types';\nimport type { Prettify } from '../utils/prettify';\n\nconst DATASOURCE_ENTRY_DEFAULTS = {\n id: 1,\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; datasource_id: number } & Partial<Omit<MapiDatasourceEntryGenerated, 'name' | 'datasource_id'>>;\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});\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,EAChC,IAAI,GACL;AAuBD,SAAgB,sBAAsB,iBAAsB;AAC1D,QAAO;EAAE,GAAG;EAA2B,GAAG;EAAiB;;;;;;;;;AAU7D,MAAa,6BAA6B,WAA0D;CAClG,GAAG;CACH,GAAG;CACJ;;;;;;;AAQD,MAAa,+BAA+B,UAAwD;;;;;;;AAQpG,MAAa,+BAA+B,UAAwD"}
@@ -0,0 +1,33 @@
1
+
2
+ //#region src/helpers/define-datasource.ts
3
+ const DATASOURCE_DEFAULTS = {
4
+ id: 1,
5
+ created_at: "",
6
+ updated_at: ""
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
+ exports.defineDatasource = defineDatasource;
31
+ exports.defineDatasourceCreate = defineDatasourceCreate;
32
+ exports.defineDatasourceUpdate = defineDatasourceUpdate;
33
+ //# 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/types';\nimport type { DatasourceCreate, DatasourceUpdate } from '../generated/mapi-types';\nimport type { Prettify } from '../utils/prettify';\n\nconst DATASOURCE_DEFAULTS = {\n id: 1,\n created_at: '',\n updated_at: '',\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;CACb;AAyBD,SAAgB,iBAAiB,YAAiB;AAChD,QAAO;EAAE,GAAG;EAAqB,GAAG;EAAY;;;;;;;;AASlD,MAAa,0BAA0B,eAAmD;;;;;;;AAQ1F,MAAa,0BAA0B,eAAmD"}
@@ -0,0 +1,41 @@
1
+ import { Datasource } from "../generated/types.cjs";
2
+ import { DatasourceCreate, DatasourceUpdate } from "../generated/mapi-types.cjs";
3
+ import { Prettify } from "../utils/prettify.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
+ };
11
+ /** Fields that have safe defaults and may be omitted from datasource input. */
12
+ type DatasourceOptional = keyof typeof DATASOURCE_DEFAULTS;
13
+ type DatasourceInput = Prettify<Omit<Datasource, DatasourceOptional> & Partial<Pick<Datasource, DatasourceOptional>>>;
14
+ /**
15
+ * Returns a full {@link Datasource} with all fields populated. API-assigned
16
+ * fields are optional and default to safe values.
17
+ *
18
+ * @example
19
+ * const myDatasource = defineDatasource({
20
+ * name: 'Colors',
21
+ * slug: 'colors',
22
+ * });
23
+ */
24
+ declare function defineDatasource(datasource: DatasourceInput): Datasource;
25
+ /**
26
+ * Defines a datasource creation payload for the MAPI.
27
+ *
28
+ * @example
29
+ * const payload = defineDatasourceCreate({ name: 'Colors', slug: 'colors' });
30
+ */
31
+ declare const defineDatasourceCreate: (datasource: DatasourceCreate) => DatasourceCreate;
32
+ /**
33
+ * Defines a datasource update payload for the MAPI.
34
+ *
35
+ * @example
36
+ * const payload = defineDatasourceUpdate({ name: 'Updated Colors' });
37
+ */
38
+ declare const defineDatasourceUpdate: (datasource: DatasourceUpdate) => DatasourceUpdate;
39
+ //#endregion
40
+ export { defineDatasource, defineDatasourceCreate, defineDatasourceUpdate };
41
+ //# sourceMappingURL=define-datasource.d.cts.map
@@ -0,0 +1,41 @@
1
+ import { Datasource } from "../generated/types.mjs";
2
+ import { DatasourceCreate, DatasourceUpdate } from "../generated/mapi-types.mjs";
3
+ import { Prettify } from "../utils/prettify.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
+ };
11
+ /** Fields that have safe defaults and may be omitted from datasource input. */
12
+ type DatasourceOptional = keyof typeof DATASOURCE_DEFAULTS;
13
+ type DatasourceInput = Prettify<Omit<Datasource, DatasourceOptional> & Partial<Pick<Datasource, DatasourceOptional>>>;
14
+ /**
15
+ * Returns a full {@link Datasource} with all fields populated. API-assigned
16
+ * fields are optional and default to safe values.
17
+ *
18
+ * @example
19
+ * const myDatasource = defineDatasource({
20
+ * name: 'Colors',
21
+ * slug: 'colors',
22
+ * });
23
+ */
24
+ declare function defineDatasource(datasource: DatasourceInput): Datasource;
25
+ /**
26
+ * Defines a datasource creation payload for the MAPI.
27
+ *
28
+ * @example
29
+ * const payload = defineDatasourceCreate({ name: 'Colors', slug: 'colors' });
30
+ */
31
+ declare const defineDatasourceCreate: (datasource: DatasourceCreate) => DatasourceCreate;
32
+ /**
33
+ * Defines a datasource update payload for the MAPI.
34
+ *
35
+ * @example
36
+ * const payload = defineDatasourceUpdate({ name: 'Updated Colors' });
37
+ */
38
+ declare const defineDatasourceUpdate: (datasource: DatasourceUpdate) => DatasourceUpdate;
39
+ //#endregion
40
+ export { defineDatasource, defineDatasourceCreate, defineDatasourceUpdate };
41
+ //# sourceMappingURL=define-datasource.d.mts.map
@@ -0,0 +1,30 @@
1
+ //#region src/helpers/define-datasource.ts
2
+ const DATASOURCE_DEFAULTS = {
3
+ id: 1,
4
+ created_at: "",
5
+ updated_at: ""
6
+ };
7
+ function defineDatasource(datasource) {
8
+ return {
9
+ ...DATASOURCE_DEFAULTS,
10
+ ...datasource
11
+ };
12
+ }
13
+ /**
14
+ * Defines a datasource creation payload for the MAPI.
15
+ *
16
+ * @example
17
+ * const payload = defineDatasourceCreate({ name: 'Colors', slug: 'colors' });
18
+ */
19
+ const defineDatasourceCreate = (datasource) => datasource;
20
+ /**
21
+ * Defines a datasource update payload for the MAPI.
22
+ *
23
+ * @example
24
+ * const payload = defineDatasourceUpdate({ name: 'Updated Colors' });
25
+ */
26
+ const defineDatasourceUpdate = (datasource) => datasource;
27
+
28
+ //#endregion
29
+ export { defineDatasource, defineDatasourceCreate, defineDatasourceUpdate };
30
+ //# 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/types';\nimport type { DatasourceCreate, DatasourceUpdate } from '../generated/mapi-types';\nimport type { Prettify } from '../utils/prettify';\n\nconst DATASOURCE_DEFAULTS = {\n id: 1,\n created_at: '',\n updated_at: '',\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;CACb;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 ComponentSchemaField as Field,\n} from '../generated/mapi-types';\nimport type {\n AssetFieldValue,\n BlokContent as BlokContentGenerated,\n MultilinkFieldValue,\n PluginFieldValue,\n RichtextFieldValue,\n TableFieldValue,\n} from '../generated/types';\nimport type { Block } from './define-block';\nimport type { Prettify } from '../utils/prettify';\n\nexport { 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: BlokContentGenerated[];\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 ? BlokContentGenerated[]\n : [TBlocks] extends [Block]\n ? BlockContent<ApplyWhitelist<TField, TBlocks>, TBlocks>[]\n : BlokContentGenerated[]\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":";;;;;;;;;AAmKA,MAAa,eAIX,MACA,WAC4C;CAAE,GAAG;CAAO;CAAM"}
@@ -0,0 +1,100 @@
1
+ import { AssetFieldValue, BlokContent, MultilinkFieldValue, PluginFieldValue, RichtextFieldValue, TableFieldValue } from "../generated/types.cjs";
2
+ import { ComponentSchemaField } from "../generated/mapi-types.cjs";
3
+ import { Prettify } from "../utils/prettify.cjs";
4
+ import { Block } from "./define-block.cjs";
5
+
6
+ //#region src/helpers/define-field.d.ts
7
+ /** Loose variant of the generated `BlokContent` with `_uid` optional — used as the fallback for write operations when no block union is provided. */
8
+ type BlokContentLoose = {
9
+ _uid?: string;
10
+ component: string;
11
+ _editable?: string | undefined;
12
+ } & {
13
+ [key: string]: string | number | boolean | Array<string | AssetFieldValue | BlokContentLoose> | AssetFieldValue | MultilinkFieldValue | TableFieldValue | RichtextFieldValue | PluginFieldValue | undefined;
14
+ };
15
+ /** Keys in a schema record that have `required: true`. */
16
+ type RequiredFieldKeys<T> = { [K in keyof T]: T[K] extends {
17
+ required: true;
18
+ } ? K : never }[keyof T];
19
+ /** Keys in a schema record that do NOT have `required: true`. */
20
+ type OptionalFieldKeys<T> = Exclude<keyof T, RequiredFieldKeys<T>>;
21
+ /**
22
+ * Builds the content object for a single block instance as returned by the
23
+ * Storyblok Content Delivery API. Includes `_uid` (always present in API
24
+ * responses) and respects required/optional field semantics.
25
+ *
26
+ * For write operations (creating/updating stories), use {@link BlockContentInput}
27
+ * instead, which omits `_uid` since Storyblok generates it automatically.
28
+ */
29
+ type BlockContent<TBlock extends Block = Block, TBlocks = false> = TBlock extends any ? {
30
+ _uid: string;
31
+ component: TBlock['name'];
32
+ } & { [K in RequiredFieldKeys<TBlock['schema']>]: FieldValue<NonNullable<TBlock['schema'][K]>, TBlocks> } & { [K in OptionalFieldKeys<TBlock['schema']>]?: FieldValue<NonNullable<TBlock['schema'][K]>, TBlocks> | null } : never;
33
+ /**
34
+ * Input variant of {@link BlockContent} for write operations (creating/updating
35
+ * stories via the MAPI). `_uid` is optional — Storyblok generates it
36
+ * automatically when omitted. Nested bloks fields also use this input variant
37
+ * so that deeply nested blocks do not require `_uid` either.
38
+ */
39
+ type BlockContentInput<TBlock extends Block = Block, TBlocks = false> = TBlock extends any ? {
40
+ _uid?: string;
41
+ component: TBlock['name'];
42
+ } & { [K in RequiredFieldKeys<TBlock['schema']>]: FieldValueInput<NonNullable<TBlock['schema'][K]>, TBlocks> } & { [K in OptionalFieldKeys<TBlock['schema']>]?: FieldValueInput<NonNullable<TBlock['schema'][K]>, TBlocks> | null } : never;
43
+ type BlocksFieldValue<TBlock extends Block = Block, TBlocks = false> = BlockContent<TBlock, TBlocks>[];
44
+ /** Union of all valid Storyblok field type discriminants (e.g., `text`, `bloks`). */
45
+ type FieldType = ComponentSchemaField['type'];
46
+ /** Maps each field type discriminant to its runtime content value type. */
47
+ interface FieldTypeValueMap {
48
+ text: string;
49
+ textarea: string;
50
+ richtext: RichtextFieldValue;
51
+ markdown: string;
52
+ number: number;
53
+ datetime: string;
54
+ boolean: boolean;
55
+ option: string;
56
+ options: string[];
57
+ asset: AssetFieldValue;
58
+ multiasset: AssetFieldValue[];
59
+ multilink: MultilinkFieldValue;
60
+ bloks: BlokContent[];
61
+ table: TableFieldValue;
62
+ section: never;
63
+ tab: never;
64
+ custom: PluginFieldValue;
65
+ }
66
+ /**
67
+ * Checks whether a block is nestable, defaulting to `true` when
68
+ * `is_nestable` is absent or undefined.
69
+ */
70
+ type IsNestable<T> = T extends {
71
+ is_nestable: false;
72
+ } ? false : T extends {
73
+ is_nestable: true;
74
+ } ? true : true;
75
+ type ApplyWhitelist<TField, TBlocks> = TField extends {
76
+ component_whitelist: ReadonlyArray<infer TWhitelisted extends string>;
77
+ } ? TBlocks extends {
78
+ name: TWhitelisted;
79
+ } ? TBlocks : never : TBlocks extends any ? IsNestable<TBlocks> extends true ? TBlocks : never : never;
80
+ /** Resolves a field definition to its runtime content value type (read). */
81
+ type FieldValue<TField extends ComponentSchemaField = ComponentSchemaField, TBlocks = false> = Prettify<TField extends {
82
+ type: 'bloks';
83
+ } ? [TBlocks] extends [never] ? BlokContent[] : [TBlocks] extends [Block] ? BlockContent<ApplyWhitelist<TField, TBlocks>, TBlocks>[] : BlokContent[] : FieldTypeValueMap[TField['type']]>;
84
+ /** Resolves a field definition to its input value type (write). Nested bloks use {@link BlockContentInput}. */
85
+ type FieldValueInput<TField extends ComponentSchemaField = ComponentSchemaField, TBlocks = false> = Prettify<TField extends {
86
+ type: 'bloks';
87
+ } ? [TBlocks] extends [never] ? BlokContentLoose[] : [TBlocks] extends [Block] ? BlockContentInput<ApplyWhitelist<TField, TBlocks>, TBlocks>[] : BlokContentLoose[] : FieldTypeValueMap[TField['type']]>;
88
+ /**
89
+ * Returns a {@link Field} stamped with the given `name`. Use inside a
90
+ * {@link defineBlock} `schema` array — `pos` is inferred from array index.
91
+ *
92
+ * @example
93
+ * defineField('headline', { type: 'text', max_length: 100, required: true });
94
+ */
95
+ declare const defineField: <const TName extends string, const TField extends ComponentSchemaField>(name: TName, field: TField) => Omit<TField, "name"> & {
96
+ name: TName;
97
+ };
98
+ //#endregion
99
+ export { BlockContent, BlockContentInput, BlocksFieldValue, FieldType, FieldValue, FieldValueInput, defineField };
100
+ //# sourceMappingURL=define-field.d.cts.map
@@ -0,0 +1,100 @@
1
+ import { AssetFieldValue, BlokContent, MultilinkFieldValue, PluginFieldValue, RichtextFieldValue, TableFieldValue } from "../generated/types.mjs";
2
+ import { ComponentSchemaField } from "../generated/mapi-types.mjs";
3
+ import { Prettify } from "../utils/prettify.mjs";
4
+ import { Block } from "./define-block.mjs";
5
+
6
+ //#region src/helpers/define-field.d.ts
7
+ /** Loose variant of the generated `BlokContent` with `_uid` optional — used as the fallback for write operations when no block union is provided. */
8
+ type BlokContentLoose = {
9
+ _uid?: string;
10
+ component: string;
11
+ _editable?: string | undefined;
12
+ } & {
13
+ [key: string]: string | number | boolean | Array<string | AssetFieldValue | BlokContentLoose> | AssetFieldValue | MultilinkFieldValue | TableFieldValue | RichtextFieldValue | PluginFieldValue | undefined;
14
+ };
15
+ /** Keys in a schema record that have `required: true`. */
16
+ type RequiredFieldKeys<T> = { [K in keyof T]: T[K] extends {
17
+ required: true;
18
+ } ? K : never }[keyof T];
19
+ /** Keys in a schema record that do NOT have `required: true`. */
20
+ type OptionalFieldKeys<T> = Exclude<keyof T, RequiredFieldKeys<T>>;
21
+ /**
22
+ * Builds the content object for a single block instance as returned by the
23
+ * Storyblok Content Delivery API. Includes `_uid` (always present in API
24
+ * responses) and respects required/optional field semantics.
25
+ *
26
+ * For write operations (creating/updating stories), use {@link BlockContentInput}
27
+ * instead, which omits `_uid` since Storyblok generates it automatically.
28
+ */
29
+ type BlockContent<TBlock extends Block = Block, TBlocks = false> = TBlock extends any ? {
30
+ _uid: string;
31
+ component: TBlock['name'];
32
+ } & { [K in RequiredFieldKeys<TBlock['schema']>]: FieldValue<NonNullable<TBlock['schema'][K]>, TBlocks> } & { [K in OptionalFieldKeys<TBlock['schema']>]?: FieldValue<NonNullable<TBlock['schema'][K]>, TBlocks> | null } : never;
33
+ /**
34
+ * Input variant of {@link BlockContent} for write operations (creating/updating
35
+ * stories via the MAPI). `_uid` is optional — Storyblok generates it
36
+ * automatically when omitted. Nested bloks fields also use this input variant
37
+ * so that deeply nested blocks do not require `_uid` either.
38
+ */
39
+ type BlockContentInput<TBlock extends Block = Block, TBlocks = false> = TBlock extends any ? {
40
+ _uid?: string;
41
+ component: TBlock['name'];
42
+ } & { [K in RequiredFieldKeys<TBlock['schema']>]: FieldValueInput<NonNullable<TBlock['schema'][K]>, TBlocks> } & { [K in OptionalFieldKeys<TBlock['schema']>]?: FieldValueInput<NonNullable<TBlock['schema'][K]>, TBlocks> | null } : never;
43
+ type BlocksFieldValue<TBlock extends Block = Block, TBlocks = false> = BlockContent<TBlock, TBlocks>[];
44
+ /** Union of all valid Storyblok field type discriminants (e.g., `text`, `bloks`). */
45
+ type FieldType = ComponentSchemaField['type'];
46
+ /** Maps each field type discriminant to its runtime content value type. */
47
+ interface FieldTypeValueMap {
48
+ text: string;
49
+ textarea: string;
50
+ richtext: RichtextFieldValue;
51
+ markdown: string;
52
+ number: number;
53
+ datetime: string;
54
+ boolean: boolean;
55
+ option: string;
56
+ options: string[];
57
+ asset: AssetFieldValue;
58
+ multiasset: AssetFieldValue[];
59
+ multilink: MultilinkFieldValue;
60
+ bloks: BlokContent[];
61
+ table: TableFieldValue;
62
+ section: never;
63
+ tab: never;
64
+ custom: PluginFieldValue;
65
+ }
66
+ /**
67
+ * Checks whether a block is nestable, defaulting to `true` when
68
+ * `is_nestable` is absent or undefined.
69
+ */
70
+ type IsNestable<T> = T extends {
71
+ is_nestable: false;
72
+ } ? false : T extends {
73
+ is_nestable: true;
74
+ } ? true : true;
75
+ type ApplyWhitelist<TField, TBlocks> = TField extends {
76
+ component_whitelist: ReadonlyArray<infer TWhitelisted extends string>;
77
+ } ? TBlocks extends {
78
+ name: TWhitelisted;
79
+ } ? TBlocks : never : TBlocks extends any ? IsNestable<TBlocks> extends true ? TBlocks : never : never;
80
+ /** Resolves a field definition to its runtime content value type (read). */
81
+ type FieldValue<TField extends ComponentSchemaField = ComponentSchemaField, TBlocks = false> = Prettify<TField extends {
82
+ type: 'bloks';
83
+ } ? [TBlocks] extends [never] ? BlokContent[] : [TBlocks] extends [Block] ? BlockContent<ApplyWhitelist<TField, TBlocks>, TBlocks>[] : BlokContent[] : FieldTypeValueMap[TField['type']]>;
84
+ /** Resolves a field definition to its input value type (write). Nested bloks use {@link BlockContentInput}. */
85
+ type FieldValueInput<TField extends ComponentSchemaField = ComponentSchemaField, TBlocks = false> = Prettify<TField extends {
86
+ type: 'bloks';
87
+ } ? [TBlocks] extends [never] ? BlokContentLoose[] : [TBlocks] extends [Block] ? BlockContentInput<ApplyWhitelist<TField, TBlocks>, TBlocks>[] : BlokContentLoose[] : FieldTypeValueMap[TField['type']]>;
88
+ /**
89
+ * Returns a {@link Field} stamped with the given `name`. Use inside a
90
+ * {@link defineBlock} `schema` array — `pos` is inferred from array index.
91
+ *
92
+ * @example
93
+ * defineField('headline', { type: 'text', max_length: 100, required: true });
94
+ */
95
+ declare const defineField: <const TName extends string, const TField extends ComponentSchemaField>(name: TName, field: TField) => Omit<TField, "name"> & {
96
+ name: TName;
97
+ };
98
+ //#endregion
99
+ export { BlockContent, BlockContentInput, BlocksFieldValue, FieldType, FieldValue, FieldValueInput, defineField };
100
+ //# sourceMappingURL=define-field.d.mts.map
@@ -0,0 +1,16 @@
1
+ //#region src/helpers/define-field.ts
2
+ /**
3
+ * Returns a {@link Field} stamped with the given `name`. Use inside a
4
+ * {@link defineBlock} `schema` array — `pos` is inferred from array index.
5
+ *
6
+ * @example
7
+ * defineField('headline', { type: 'text', max_length: 100, required: true });
8
+ */
9
+ const defineField = (name, field) => ({
10
+ ...field,
11
+ name
12
+ });
13
+
14
+ //#endregion
15
+ export { defineField };
16
+ //# sourceMappingURL=define-field.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-field.mjs","names":[],"sources":["../../src/helpers/define-field.ts"],"sourcesContent":["import type {\n ComponentSchemaField as Field,\n} from '../generated/mapi-types';\nimport type {\n AssetFieldValue,\n BlokContent as BlokContentGenerated,\n MultilinkFieldValue,\n PluginFieldValue,\n RichtextFieldValue,\n TableFieldValue,\n} from '../generated/types';\nimport type { Block } from './define-block';\nimport type { Prettify } from '../utils/prettify';\n\nexport { 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: BlokContentGenerated[];\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 ? BlokContentGenerated[]\n : [TBlocks] extends [Block]\n ? BlockContent<ApplyWhitelist<TField, TBlocks>, TBlocks>[]\n : BlokContentGenerated[]\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":";;;;;;;;AAmKA,MAAa,eAIX,MACA,WAC4C;CAAE,GAAG;CAAO;CAAM"}