@storyblok/schema 0.1.0-alpha.0 → 0.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/field-plugins/index.cjs +4 -0
  3. package/dist/field-plugins/index.d.cts +2 -0
  4. package/dist/field-plugins/index.d.mts +2 -0
  5. package/dist/field-plugins/index.mjs +3 -0
  6. package/dist/field-plugins/storyblok-color-field.cjs +32 -0
  7. package/dist/field-plugins/storyblok-color-field.cjs.map +1 -0
  8. package/dist/field-plugins/storyblok-color-field.d.cts +16 -0
  9. package/dist/field-plugins/storyblok-color-field.d.mts +16 -0
  10. package/dist/field-plugins/storyblok-color-field.mjs +32 -0
  11. package/dist/field-plugins/storyblok-color-field.mjs.map +1 -0
  12. package/dist/generated/capi/types.gen.d.cts +1 -126
  13. package/dist/generated/capi/types.gen.d.mts +1 -126
  14. package/dist/generated/mapi/_internal.gen.d.cts +1 -171
  15. package/dist/generated/mapi/_internal.gen.d.mts +1 -171
  16. package/dist/generated/overlay/zod.gen.cjs +407 -0
  17. package/dist/generated/overlay/zod.gen.cjs.map +1 -0
  18. package/dist/generated/overlay/zod.gen.mjs +402 -0
  19. package/dist/generated/overlay/zod.gen.mjs.map +1 -0
  20. package/dist/generated/types/block.d.cts +27 -14
  21. package/dist/generated/types/block.d.mts +27 -14
  22. package/dist/generated/types/field.d.cts +48 -17
  23. package/dist/generated/types/field.d.mts +48 -17
  24. package/dist/generated/types/mapi-story.d.cts +6 -10
  25. package/dist/generated/types/mapi-story.d.mts +6 -10
  26. package/dist/generated/types/story.d.cts +3 -3
  27. package/dist/generated/types/story.d.mts +3 -3
  28. package/dist/helpers/define-block.cjs +10 -28
  29. package/dist/helpers/define-block.cjs.map +1 -1
  30. package/dist/helpers/define-block.d.cts +14 -31
  31. package/dist/helpers/define-block.d.mts +14 -31
  32. package/dist/helpers/define-block.mjs +11 -27
  33. package/dist/helpers/define-block.mjs.map +1 -1
  34. package/dist/helpers/define-datasource.cjs +0 -16
  35. package/dist/helpers/define-datasource.cjs.map +1 -1
  36. package/dist/helpers/define-datasource.d.cts +14 -23
  37. package/dist/helpers/define-datasource.d.mts +14 -23
  38. package/dist/helpers/define-datasource.mjs +1 -15
  39. package/dist/helpers/define-datasource.mjs.map +1 -1
  40. package/dist/helpers/define-field-plugin.cjs +21 -0
  41. package/dist/helpers/define-field-plugin.cjs.map +1 -0
  42. package/dist/helpers/define-field-plugin.d.cts +33 -0
  43. package/dist/helpers/define-field-plugin.d.mts +33 -0
  44. package/dist/helpers/define-field-plugin.mjs +20 -0
  45. package/dist/helpers/define-field-plugin.mjs.map +1 -0
  46. package/dist/helpers/define-field.cjs +11 -11
  47. package/dist/helpers/define-field.cjs.map +1 -1
  48. package/dist/helpers/define-field.d.cts +46 -85
  49. package/dist/helpers/define-field.d.mts +46 -85
  50. package/dist/helpers/define-field.mjs +12 -11
  51. package/dist/helpers/define-field.mjs.map +1 -1
  52. package/dist/helpers/define-schema.cjs +22 -0
  53. package/dist/helpers/define-schema.cjs.map +1 -0
  54. package/dist/helpers/define-schema.d.cts +28 -0
  55. package/dist/helpers/define-schema.d.mts +28 -0
  56. package/dist/helpers/define-schema.mjs +21 -0
  57. package/dist/helpers/define-schema.mjs.map +1 -0
  58. package/dist/helpers/schema-type.d.cts +21 -17
  59. package/dist/helpers/schema-type.d.mts +21 -17
  60. package/dist/index.cjs +10 -47
  61. package/dist/index.d.cts +13 -20
  62. package/dist/index.d.mts +13 -20
  63. package/dist/index.mjs +8 -15
  64. package/dist/utils/is-record.cjs +10 -0
  65. package/dist/utils/is-record.cjs.map +1 -0
  66. package/dist/utils/is-record.mjs +9 -0
  67. package/dist/utils/is-record.mjs.map +1 -0
  68. package/dist/validators/create-story-validator.cjs +37 -0
  69. package/dist/validators/create-story-validator.cjs.map +1 -0
  70. package/dist/validators/create-story-validator.d.cts +18 -0
  71. package/dist/validators/create-story-validator.d.mts +18 -0
  72. package/dist/validators/create-story-validator.mjs +37 -0
  73. package/dist/validators/create-story-validator.mjs.map +1 -0
  74. package/dist/validators/internal-schemas.cjs +1 -0
  75. package/dist/validators/internal-schemas.mjs +3 -0
  76. package/dist/validators/shapes.cjs +12 -0
  77. package/dist/validators/shapes.cjs.map +1 -0
  78. package/dist/validators/shapes.d.cts +71 -0
  79. package/dist/validators/shapes.d.mts +71 -0
  80. package/dist/validators/shapes.mjs +12 -0
  81. package/dist/validators/shapes.mjs.map +1 -0
  82. package/dist/validators/types.d.cts +25 -0
  83. package/dist/validators/types.d.mts +25 -0
  84. package/dist/validators/validate-schema.cjs +145 -0
  85. package/dist/validators/validate-schema.cjs.map +1 -0
  86. package/dist/validators/validate-schema.d.cts +19 -0
  87. package/dist/validators/validate-schema.d.mts +19 -0
  88. package/dist/validators/validate-schema.mjs +145 -0
  89. package/dist/validators/validate-schema.mjs.map +1 -0
  90. package/dist/validators/validate-story.cjs +285 -0
  91. package/dist/validators/validate-story.cjs.map +1 -0
  92. package/dist/validators/validate-story.d.cts +17 -0
  93. package/dist/validators/validate-story.d.mts +17 -0
  94. package/dist/validators/validate-story.mjs +284 -0
  95. package/dist/validators/validate-story.mjs.map +1 -0
  96. package/package.json +17 -2
  97. package/dist/generated/mapi/types.gen.d.cts +0 -1272
  98. package/dist/generated/mapi/types.gen.d.mts +0 -1272
  99. package/dist/helpers/create-story-helpers.cjs +0 -42
  100. package/dist/helpers/create-story-helpers.cjs.map +0 -1
  101. package/dist/helpers/create-story-helpers.d.cts +0 -50
  102. package/dist/helpers/create-story-helpers.d.mts +0 -50
  103. package/dist/helpers/create-story-helpers.mjs +0 -42
  104. package/dist/helpers/create-story-helpers.mjs.map +0 -1
  105. package/dist/helpers/define-asset-folder.cjs +0 -46
  106. package/dist/helpers/define-asset-folder.cjs.map +0 -1
  107. package/dist/helpers/define-asset-folder.d.cts +0 -33
  108. package/dist/helpers/define-asset-folder.d.mts +0 -33
  109. package/dist/helpers/define-asset-folder.mjs +0 -43
  110. package/dist/helpers/define-asset-folder.mjs.map +0 -1
  111. package/dist/helpers/define-asset.cjs +0 -60
  112. package/dist/helpers/define-asset.cjs.map +0 -1
  113. package/dist/helpers/define-asset.d.cts +0 -32
  114. package/dist/helpers/define-asset.d.mts +0 -32
  115. package/dist/helpers/define-asset.mjs +0 -57
  116. package/dist/helpers/define-asset.mjs.map +0 -1
  117. package/dist/helpers/define-block-folder.cjs +0 -44
  118. package/dist/helpers/define-block-folder.cjs.map +0 -1
  119. package/dist/helpers/define-block-folder.d.cts +0 -34
  120. package/dist/helpers/define-block-folder.d.mts +0 -34
  121. package/dist/helpers/define-block-folder.mjs +0 -41
  122. package/dist/helpers/define-block-folder.mjs.map +0 -1
  123. package/dist/helpers/define-datasource-entry.cjs +0 -47
  124. package/dist/helpers/define-datasource-entry.cjs.map +0 -1
  125. package/dist/helpers/define-datasource-entry.d.cts +0 -49
  126. package/dist/helpers/define-datasource-entry.d.mts +0 -49
  127. package/dist/helpers/define-datasource-entry.mjs +0 -43
  128. package/dist/helpers/define-datasource-entry.mjs.map +0 -1
  129. package/dist/helpers/define-internal-tag.cjs +0 -41
  130. package/dist/helpers/define-internal-tag.cjs.map +0 -1
  131. package/dist/helpers/define-internal-tag.d.cts +0 -34
  132. package/dist/helpers/define-internal-tag.d.mts +0 -34
  133. package/dist/helpers/define-internal-tag.mjs +0 -38
  134. package/dist/helpers/define-internal-tag.mjs.map +0 -1
  135. package/dist/helpers/define-link.cjs +0 -23
  136. package/dist/helpers/define-link.cjs.map +0 -1
  137. package/dist/helpers/define-link.d.cts +0 -32
  138. package/dist/helpers/define-link.d.mts +0 -32
  139. package/dist/helpers/define-link.mjs +0 -22
  140. package/dist/helpers/define-link.mjs.map +0 -1
  141. package/dist/helpers/define-preset.cjs +0 -44
  142. package/dist/helpers/define-preset.cjs.map +0 -1
  143. package/dist/helpers/define-preset.d.cts +0 -35
  144. package/dist/helpers/define-preset.d.mts +0 -35
  145. package/dist/helpers/define-preset.mjs +0 -41
  146. package/dist/helpers/define-preset.mjs.map +0 -1
  147. package/dist/helpers/define-space.cjs +0 -47
  148. package/dist/helpers/define-space.cjs.map +0 -1
  149. package/dist/helpers/define-space.d.cts +0 -31
  150. package/dist/helpers/define-space.d.mts +0 -31
  151. package/dist/helpers/define-space.mjs +0 -44
  152. package/dist/helpers/define-space.mjs.map +0 -1
  153. package/dist/helpers/define-story.cjs +0 -122
  154. package/dist/helpers/define-story.cjs.map +0 -1
  155. package/dist/helpers/define-story.d.cts +0 -135
  156. package/dist/helpers/define-story.d.mts +0 -135
  157. package/dist/helpers/define-story.mjs +0 -118
  158. package/dist/helpers/define-story.mjs.map +0 -1
  159. package/dist/helpers/define-tag.cjs +0 -13
  160. package/dist/helpers/define-tag.cjs.map +0 -1
  161. package/dist/helpers/define-tag.d.cts +0 -23
  162. package/dist/helpers/define-tag.d.mts +0 -23
  163. package/dist/helpers/define-tag.mjs +0 -12
  164. package/dist/helpers/define-tag.mjs.map +0 -1
  165. package/dist/helpers/define-user.cjs +0 -50
  166. package/dist/helpers/define-user.cjs.map +0 -1
  167. package/dist/helpers/define-user.d.cts +0 -26
  168. package/dist/helpers/define-user.d.mts +0 -26
  169. package/dist/helpers/define-user.mjs +0 -48
  170. package/dist/helpers/define-user.mjs.map +0 -1
@@ -1 +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"}
1
+ {"version":3,"file":"define-block.mjs","names":[],"sources":["../../src/helpers/define-block.ts"],"sourcesContent":["import type {\n Block,\n BlockFields,\n NestableBlock,\n RootBlock,\n} from '../generated/types/block';\nimport type { Prettify } from '../utils/prettify';\n\nexport type { Block, BlockFields, NestableBlock, RootBlock };\n\nconst BLOCK_DEFAULTS = {\n id: 1,\n created_at: '',\n updated_at: '',\n is_root: false,\n is_nestable: true,\n};\n\n/** Fields that have safe defaults and may be omitted from block input. */\ntype BlockOptional = keyof typeof BLOCK_DEFAULTS;\n\ntype BlockInput<\n TName extends string = string,\n TFields extends BlockFields = BlockFields,\n TIsRoot extends boolean = false,\n TIsNestable extends boolean = true,\n> = Prettify<\n Omit<Block, 'name' | 'fields' | 'is_root' | 'is_nestable' | BlockOptional> & {\n name: TName;\n fields: TFields;\n is_root?: TIsRoot;\n is_nestable?: TIsNestable;\n } & Partial<Pick<Block, Exclude<BlockOptional, 'is_root' | 'is_nestable'>>>\n>;\n\ntype DefinedBlock<\n TName extends string,\n TFields extends BlockFields,\n TIsRoot extends boolean,\n TIsNestable extends boolean,\n> = Prettify<\n Omit<Block, 'name' | 'fields' | 'is_root' | 'is_nestable'> & {\n name: TName;\n fields: TFields;\n is_root: TIsRoot;\n is_nestable: TIsNestable;\n }\n>;\n\n/**\n * Returns a {@link Block} content-shape definition. The user-facing input is an\n * ordered array of `defineField` calls under `fields`; the array index becomes\n * each field's `pos`. A thin, strongly-typed helper — it does not map to the\n * MAPI wire shape (the CLI owns the DSL→wire mapping). Throws only on duplicate\n * field names (a programming error).\n *\n * @example\n * const pageBlock = defineBlock({\n * name: 'page',\n * is_root: true,\n * fields: [\n * defineField('headline', { type: 'text', required: true }),\n * ],\n * });\n */\nexport function defineBlock<\n TName extends string,\n const TFields extends BlockFields,\n TIsRoot extends boolean = false,\n TIsNestable extends boolean = true,\n>(\n block: BlockInput<TName, TFields, TIsRoot, TIsNestable>,\n): DefinedBlock<TName, TFields, TIsRoot, TIsNestable>;\n\nexport function defineBlock(block: any) {\n const inputFields = Array.isArray(block?.fields) ? block.fields : [];\n const seen = new Set<string>();\n const fields = inputFields.map((field: any, index: number) => {\n const name = field?.name;\n if (typeof name === 'string') {\n if (seen.has(name)) {\n throw new Error(`defineBlock: duplicate field name \"${name}\" in block \"${block?.name ?? ''}\"`);\n }\n seen.add(name);\n }\n return { ...field, pos: index };\n });\n return { ...BLOCK_DEFAULTS, ...block, fields };\n}\n"],"mappings":";AAUA,MAAM,iBAAiB;CACrB,IAAI;CACJ,YAAY;CACZ,YAAY;CACZ,SAAS;CACT,aAAa;CACd;AA0DD,SAAgB,YAAY,OAAY;CACtC,MAAM,cAAc,MAAM,QAAQ,OAAO,OAAO,GAAG,MAAM,SAAS,EAAE;CACpE,MAAM,uBAAO,IAAI,KAAa;CAC9B,MAAM,SAAS,YAAY,KAAK,OAAY,UAAkB;EAC5D,MAAM,OAAO,OAAO;AACpB,MAAI,OAAO,SAAS,UAAU;AAC5B,OAAI,KAAK,IAAI,KAAK,CAChB,OAAM,IAAI,MAAM,sCAAsC,KAAK,cAAc,OAAO,QAAQ,GAAG,GAAG;AAEhG,QAAK,IAAI,KAAK;;AAEhB,SAAO;GAAE,GAAG;GAAO,KAAK;GAAO;GAC/B;AACF,QAAO;EAAE,GAAG;EAAgB,GAAG;EAAO;EAAQ"}
@@ -12,23 +12,7 @@ function defineDatasource(datasource) {
12
12
  ...datasource
13
13
  };
14
14
  }
15
- /**
16
- * Defines a datasource creation payload for the MAPI.
17
- *
18
- * @example
19
- * const payload = defineDatasourceCreate({ name: 'Colors', slug: 'colors' });
20
- */
21
- const defineDatasourceCreate = (datasource) => datasource;
22
- /**
23
- * Defines a datasource update payload for the MAPI.
24
- *
25
- * @example
26
- * const payload = defineDatasourceUpdate({ name: 'Updated Colors' });
27
- */
28
- const defineDatasourceUpdate = (datasource) => datasource;
29
15
 
30
16
  //#endregion
31
17
  exports.defineDatasource = defineDatasource;
32
- exports.defineDatasourceCreate = defineDatasourceCreate;
33
- exports.defineDatasourceUpdate = defineDatasourceUpdate;
34
18
  //# sourceMappingURL=define-datasource.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"define-datasource.cjs","names":[],"sources":["../../src/helpers/define-datasource.ts"],"sourcesContent":["import type { Datasource } from '../generated/capi/types.gen';\nimport type { 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"}
1
+ {"version":3,"file":"define-datasource.cjs","names":[],"sources":["../../src/helpers/define-datasource.ts"],"sourcesContent":["import type { Datasource as DatasourceGenerated } from '../generated/capi/types.gen';\nimport type { Override } from '../generated/types/_utils';\nimport type { Prettify } from '../utils/prettify';\n\nconst DATASOURCE_DEFAULTS = {\n id: 1,\n created_at: '',\n updated_at: '',\n dimensions: [],\n};\n\n/**\n * A Storyblok datasource content shape. Carries the datasource definition only\n * (`name`, `slug`, dimensions). Entry values are content authored by editors,\n * not part of the schema, so they are neither modelled nor pushed here.\n */\nexport type Datasource = Override<DatasourceGenerated, { slug: string }>;\n\n/** Fields that have safe defaults and may be omitted from datasource input. */\ntype DatasourceOptional = keyof typeof DATASOURCE_DEFAULTS;\n\ntype DatasourceInput = Prettify<Omit<Datasource, DatasourceOptional> & Partial<Pick<Datasource, DatasourceOptional>>>;\n\n/**\n * Returns a {@link Datasource} content-shape definition. A thin, strongly-typed\n * helper it does not validate or throw.\n *\n * @example\n * const colors = defineDatasource({ name: 'Colors', slug: 'colors' });\n */\nexport function defineDatasource(datasource: DatasourceInput): Datasource;\nexport function defineDatasource(datasource: any) {\n return { ...DATASOURCE_DEFAULTS, ...datasource };\n}\n"],"mappings":";;AAIA,MAAM,sBAAsB;CAC1B,IAAI;CACJ,YAAY;CACZ,YAAY;CACZ,YAAY,EAAE;CACf;AAsBD,SAAgB,iBAAiB,YAAiB;AAChD,QAAO;EAAE,GAAG;EAAqB,GAAG;EAAY"}
@@ -1,6 +1,6 @@
1
+ import { Override } from "../generated/types/_utils.cjs";
1
2
  import { Prettify } from "../utils/prettify.cjs";
2
- import { Datasource } from "../generated/capi/types.gen.cjs";
3
- import { DatasourceCreate, DatasourceUpdate } from "../generated/mapi/types.gen.cjs";
3
+ import { Datasource as Datasource$1 } from "../generated/capi/types.gen.cjs";
4
4
 
5
5
  //#region src/helpers/define-datasource.d.ts
6
6
  declare const DATASOURCE_DEFAULTS: {
@@ -9,34 +9,25 @@ declare const DATASOURCE_DEFAULTS: {
9
9
  updated_at: string;
10
10
  dimensions: never[];
11
11
  };
12
+ /**
13
+ * A Storyblok datasource content shape. Carries the datasource definition only
14
+ * (`name`, `slug`, dimensions). Entry values are content authored by editors,
15
+ * not part of the schema, so they are neither modelled nor pushed here.
16
+ */
17
+ type Datasource = Override<Datasource$1, {
18
+ slug: string;
19
+ }>;
12
20
  /** Fields that have safe defaults and may be omitted from datasource input. */
13
21
  type DatasourceOptional = keyof typeof DATASOURCE_DEFAULTS;
14
22
  type DatasourceInput = Prettify<Omit<Datasource, DatasourceOptional> & Partial<Pick<Datasource, DatasourceOptional>>>;
15
23
  /**
16
- * Returns a full {@link Datasource} with all fields populated. API-assigned
17
- * fields are optional and default to safe values.
24
+ * Returns a {@link Datasource} content-shape definition. A thin, strongly-typed
25
+ * helper it does not validate or throw.
18
26
  *
19
27
  * @example
20
- * const myDatasource = defineDatasource({
21
- * name: 'Colors',
22
- * slug: 'colors',
23
- * });
28
+ * const colors = defineDatasource({ name: 'Colors', slug: 'colors' });
24
29
  */
25
30
  declare function defineDatasource(datasource: DatasourceInput): Datasource;
26
- /**
27
- * Defines a datasource creation payload for the MAPI.
28
- *
29
- * @example
30
- * const payload = defineDatasourceCreate({ name: 'Colors', slug: 'colors' });
31
- */
32
- declare const defineDatasourceCreate: (datasource: DatasourceCreate) => DatasourceCreate;
33
- /**
34
- * Defines a datasource update payload for the MAPI.
35
- *
36
- * @example
37
- * const payload = defineDatasourceUpdate({ name: 'Updated Colors' });
38
- */
39
- declare const defineDatasourceUpdate: (datasource: DatasourceUpdate) => DatasourceUpdate;
40
31
  //#endregion
41
- export { defineDatasource, defineDatasourceCreate, defineDatasourceUpdate };
32
+ export { Datasource, defineDatasource };
42
33
  //# sourceMappingURL=define-datasource.d.cts.map
@@ -1,6 +1,6 @@
1
+ import { Override } from "../generated/types/_utils.mjs";
1
2
  import { Prettify } from "../utils/prettify.mjs";
2
- import { Datasource } from "../generated/capi/types.gen.mjs";
3
- import { DatasourceCreate, DatasourceUpdate } from "../generated/mapi/types.gen.mjs";
3
+ import { Datasource as Datasource$1 } from "../generated/capi/types.gen.mjs";
4
4
 
5
5
  //#region src/helpers/define-datasource.d.ts
6
6
  declare const DATASOURCE_DEFAULTS: {
@@ -9,34 +9,25 @@ declare const DATASOURCE_DEFAULTS: {
9
9
  updated_at: string;
10
10
  dimensions: never[];
11
11
  };
12
+ /**
13
+ * A Storyblok datasource content shape. Carries the datasource definition only
14
+ * (`name`, `slug`, dimensions). Entry values are content authored by editors,
15
+ * not part of the schema, so they are neither modelled nor pushed here.
16
+ */
17
+ type Datasource = Override<Datasource$1, {
18
+ slug: string;
19
+ }>;
12
20
  /** Fields that have safe defaults and may be omitted from datasource input. */
13
21
  type DatasourceOptional = keyof typeof DATASOURCE_DEFAULTS;
14
22
  type DatasourceInput = Prettify<Omit<Datasource, DatasourceOptional> & Partial<Pick<Datasource, DatasourceOptional>>>;
15
23
  /**
16
- * Returns a full {@link Datasource} with all fields populated. API-assigned
17
- * fields are optional and default to safe values.
24
+ * Returns a {@link Datasource} content-shape definition. A thin, strongly-typed
25
+ * helper it does not validate or throw.
18
26
  *
19
27
  * @example
20
- * const myDatasource = defineDatasource({
21
- * name: 'Colors',
22
- * slug: 'colors',
23
- * });
28
+ * const colors = defineDatasource({ name: 'Colors', slug: 'colors' });
24
29
  */
25
30
  declare function defineDatasource(datasource: DatasourceInput): Datasource;
26
- /**
27
- * Defines a datasource creation payload for the MAPI.
28
- *
29
- * @example
30
- * const payload = defineDatasourceCreate({ name: 'Colors', slug: 'colors' });
31
- */
32
- declare const defineDatasourceCreate: (datasource: DatasourceCreate) => DatasourceCreate;
33
- /**
34
- * Defines a datasource update payload for the MAPI.
35
- *
36
- * @example
37
- * const payload = defineDatasourceUpdate({ name: 'Updated Colors' });
38
- */
39
- declare const defineDatasourceUpdate: (datasource: DatasourceUpdate) => DatasourceUpdate;
40
31
  //#endregion
41
- export { defineDatasource, defineDatasourceCreate, defineDatasourceUpdate };
32
+ export { Datasource, defineDatasource };
42
33
  //# sourceMappingURL=define-datasource.d.mts.map
@@ -11,21 +11,7 @@ function defineDatasource(datasource) {
11
11
  ...datasource
12
12
  };
13
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
14
 
29
15
  //#endregion
30
- export { defineDatasource, defineDatasourceCreate, defineDatasourceUpdate };
16
+ export { defineDatasource };
31
17
  //# sourceMappingURL=define-datasource.mjs.map
@@ -1 +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"}
1
+ {"version":3,"file":"define-datasource.mjs","names":[],"sources":["../../src/helpers/define-datasource.ts"],"sourcesContent":["import type { Datasource as DatasourceGenerated } from '../generated/capi/types.gen';\nimport type { Override } from '../generated/types/_utils';\nimport type { Prettify } from '../utils/prettify';\n\nconst DATASOURCE_DEFAULTS = {\n id: 1,\n created_at: '',\n updated_at: '',\n dimensions: [],\n};\n\n/**\n * A Storyblok datasource content shape. Carries the datasource definition only\n * (`name`, `slug`, dimensions). Entry values are content authored by editors,\n * not part of the schema, so they are neither modelled nor pushed here.\n */\nexport type Datasource = Override<DatasourceGenerated, { slug: string }>;\n\n/** Fields that have safe defaults and may be omitted from datasource input. */\ntype DatasourceOptional = keyof typeof DATASOURCE_DEFAULTS;\n\ntype DatasourceInput = Prettify<Omit<Datasource, DatasourceOptional> & Partial<Pick<Datasource, DatasourceOptional>>>;\n\n/**\n * Returns a {@link Datasource} content-shape definition. A thin, strongly-typed\n * helper it does not validate or throw.\n *\n * @example\n * const colors = defineDatasource({ name: 'Colors', slug: 'colors' });\n */\nexport function defineDatasource(datasource: DatasourceInput): Datasource;\nexport function defineDatasource(datasource: any) {\n return { ...DATASOURCE_DEFAULTS, ...datasource };\n}\n"],"mappings":";AAIA,MAAM,sBAAsB;CAC1B,IAAI;CACJ,YAAY;CACZ,YAAY;CACZ,YAAY,EAAE;CACf;AAsBD,SAAgB,iBAAiB,YAAiB;AAChD,QAAO;EAAE,GAAG;EAAqB,GAAG;EAAY"}
@@ -0,0 +1,21 @@
1
+
2
+ //#region src/helpers/define-field-plugin.ts
3
+ /**
4
+ * Declares a custom field plugin: both the `fieldType` literal and the value
5
+ * type infer from the single argument. `value` accepts any Standard Schema
6
+ * validator (Zod, Valibot, ArkType, or hand-written) and is retained for
7
+ * runtime use. A thin, strongly-typed identity helper — it does not validate.
8
+ *
9
+ * @example
10
+ * const colorPicker = defineFieldPlugin({
11
+ * fieldType: 'my-custom-color-picker',
12
+ * value: z.object({ color: z.string(), alpha: z.number() }),
13
+ * });
14
+ */
15
+ function defineFieldPlugin(config) {
16
+ return config;
17
+ }
18
+
19
+ //#endregion
20
+ exports.defineFieldPlugin = defineFieldPlugin;
21
+ //# sourceMappingURL=define-field-plugin.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-field-plugin.cjs","names":[],"sources":["../../src/helpers/define-field-plugin.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec';\n\n/**\n * Binds a Storyblok custom field `field_type` to a\n * [Standard Schema](https://standardschema.dev) validator. The validator (`S`,\n * retained on `value`) supplies both the static value type\n * (`StandardSchemaV1.InferOutput<S>`) and a runtime handle, so a single\n * declaration serves types and (future) runtime validation.\n */\nexport interface FieldPlugin<\n F extends string = string,\n S extends StandardSchemaV1 = StandardSchemaV1,\n> {\n fieldType: F;\n value: S;\n}\n\n/**\n * Declares a custom field plugin: both the `fieldType` literal and the value\n * type infer from the single argument. `value` accepts any Standard Schema\n * validator (Zod, Valibot, ArkType, or hand-written) and is retained for\n * runtime use. A thin, strongly-typed identity helper — it does not validate.\n *\n * @example\n * const colorPicker = defineFieldPlugin({\n * fieldType: 'my-custom-color-picker',\n * value: z.object({ color: z.string(), alpha: z.number() }),\n * });\n */\nexport function defineFieldPlugin<\n const F extends string,\n S extends StandardSchemaV1,\n>(config: { fieldType: F; value: S }): FieldPlugin<F, S> {\n return config;\n}\n"],"mappings":";;;;;;;;;;;;;;AA6BA,SAAgB,kBAGd,QAAuD;AACvD,QAAO"}
@@ -0,0 +1,33 @@
1
+ import { StandardSchemaV1 } from "@standard-schema/spec";
2
+
3
+ //#region src/helpers/define-field-plugin.d.ts
4
+ /**
5
+ * Binds a Storyblok custom field `field_type` to a
6
+ * [Standard Schema](https://standardschema.dev) validator. The validator (`S`,
7
+ * retained on `value`) supplies both the static value type
8
+ * (`StandardSchemaV1.InferOutput<S>`) and a runtime handle, so a single
9
+ * declaration serves types and (future) runtime validation.
10
+ */
11
+ interface FieldPlugin<F extends string = string, S extends StandardSchemaV1 = StandardSchemaV1> {
12
+ fieldType: F;
13
+ value: S;
14
+ }
15
+ /**
16
+ * Declares a custom field plugin: both the `fieldType` literal and the value
17
+ * type infer from the single argument. `value` accepts any Standard Schema
18
+ * validator (Zod, Valibot, ArkType, or hand-written) and is retained for
19
+ * runtime use. A thin, strongly-typed identity helper — it does not validate.
20
+ *
21
+ * @example
22
+ * const colorPicker = defineFieldPlugin({
23
+ * fieldType: 'my-custom-color-picker',
24
+ * value: z.object({ color: z.string(), alpha: z.number() }),
25
+ * });
26
+ */
27
+ declare function defineFieldPlugin<const F extends string, S extends StandardSchemaV1>(config: {
28
+ fieldType: F;
29
+ value: S;
30
+ }): FieldPlugin<F, S>;
31
+ //#endregion
32
+ export { FieldPlugin, defineFieldPlugin };
33
+ //# sourceMappingURL=define-field-plugin.d.cts.map
@@ -0,0 +1,33 @@
1
+ import { StandardSchemaV1 } from "@standard-schema/spec";
2
+
3
+ //#region src/helpers/define-field-plugin.d.ts
4
+ /**
5
+ * Binds a Storyblok custom field `field_type` to a
6
+ * [Standard Schema](https://standardschema.dev) validator. The validator (`S`,
7
+ * retained on `value`) supplies both the static value type
8
+ * (`StandardSchemaV1.InferOutput<S>`) and a runtime handle, so a single
9
+ * declaration serves types and (future) runtime validation.
10
+ */
11
+ interface FieldPlugin<F extends string = string, S extends StandardSchemaV1 = StandardSchemaV1> {
12
+ fieldType: F;
13
+ value: S;
14
+ }
15
+ /**
16
+ * Declares a custom field plugin: both the `fieldType` literal and the value
17
+ * type infer from the single argument. `value` accepts any Standard Schema
18
+ * validator (Zod, Valibot, ArkType, or hand-written) and is retained for
19
+ * runtime use. A thin, strongly-typed identity helper — it does not validate.
20
+ *
21
+ * @example
22
+ * const colorPicker = defineFieldPlugin({
23
+ * fieldType: 'my-custom-color-picker',
24
+ * value: z.object({ color: z.string(), alpha: z.number() }),
25
+ * });
26
+ */
27
+ declare function defineFieldPlugin<const F extends string, S extends StandardSchemaV1>(config: {
28
+ fieldType: F;
29
+ value: S;
30
+ }): FieldPlugin<F, S>;
31
+ //#endregion
32
+ export { FieldPlugin, defineFieldPlugin };
33
+ //# sourceMappingURL=define-field-plugin.d.mts.map
@@ -0,0 +1,20 @@
1
+ //#region src/helpers/define-field-plugin.ts
2
+ /**
3
+ * Declares a custom field plugin: both the `fieldType` literal and the value
4
+ * type infer from the single argument. `value` accepts any Standard Schema
5
+ * validator (Zod, Valibot, ArkType, or hand-written) and is retained for
6
+ * runtime use. A thin, strongly-typed identity helper — it does not validate.
7
+ *
8
+ * @example
9
+ * const colorPicker = defineFieldPlugin({
10
+ * fieldType: 'my-custom-color-picker',
11
+ * value: z.object({ color: z.string(), alpha: z.number() }),
12
+ * });
13
+ */
14
+ function defineFieldPlugin(config) {
15
+ return config;
16
+ }
17
+
18
+ //#endregion
19
+ export { defineFieldPlugin };
20
+ //# sourceMappingURL=define-field-plugin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-field-plugin.mjs","names":[],"sources":["../../src/helpers/define-field-plugin.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@standard-schema/spec';\n\n/**\n * Binds a Storyblok custom field `field_type` to a\n * [Standard Schema](https://standardschema.dev) validator. The validator (`S`,\n * retained on `value`) supplies both the static value type\n * (`StandardSchemaV1.InferOutput<S>`) and a runtime handle, so a single\n * declaration serves types and (future) runtime validation.\n */\nexport interface FieldPlugin<\n F extends string = string,\n S extends StandardSchemaV1 = StandardSchemaV1,\n> {\n fieldType: F;\n value: S;\n}\n\n/**\n * Declares a custom field plugin: both the `fieldType` literal and the value\n * type infer from the single argument. `value` accepts any Standard Schema\n * validator (Zod, Valibot, ArkType, or hand-written) and is retained for\n * runtime use. A thin, strongly-typed identity helper — it does not validate.\n *\n * @example\n * const colorPicker = defineFieldPlugin({\n * fieldType: 'my-custom-color-picker',\n * value: z.object({ color: z.string(), alpha: z.number() }),\n * });\n */\nexport function defineFieldPlugin<\n const F extends string,\n S extends StandardSchemaV1,\n>(config: { fieldType: F; value: S }): FieldPlugin<F, S> {\n return config;\n}\n"],"mappings":";;;;;;;;;;;;;AA6BA,SAAgB,kBAGd,QAAuD;AACvD,QAAO"}
@@ -1,16 +1,16 @@
1
+ const require_is_record = require('../utils/is-record.cjs');
1
2
 
2
3
  //#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
- });
4
+ function defineField(name, field) {
5
+ const { allow, datasource, ...rest } = field;
6
+ const normalized = {
7
+ ...rest,
8
+ name
9
+ };
10
+ if (allow !== void 0) normalized.allow = (Array.isArray(allow) ? allow : [allow]).map((ref) => typeof ref === "string" ? ref : require_is_record.isRecord(ref) ? ref.name : void 0);
11
+ if (datasource !== void 0) normalized.datasource = typeof datasource === "string" ? datasource : require_is_record.isRecord(datasource) ? datasource.slug : void 0;
12
+ return normalized;
13
+ }
14
14
 
15
15
  //#endregion
16
16
  exports.defineField = defineField;
@@ -1 +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 fieldguard 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"}
1
+ {"version":3,"file":"define-field.cjs","names":["isRecord"],"sources":["../../src/helpers/define-field.ts"],"sourcesContent":["import type {\n AssetFieldValue,\n BlockContent,\n BlockContentInput,\n BlocksFieldValue,\n Field,\n FieldType,\n FieldValue,\n FieldValueInput,\n MultilinkFieldValue,\n PluginFieldValue,\n RichtextFieldValue,\n TableFieldValue,\n} from '../generated/types/field';\nimport type { Prettify } from '../utils/prettify';\nimport { isRecord } from '../utils/is-record';\n\nexport type {\n AssetFieldValue,\n BlockContent,\n BlockContentInput,\n BlocksFieldValue,\n Field,\n FieldType,\n FieldValue,\n FieldValueInput,\n MultilinkFieldValue,\n PluginFieldValue,\n RichtextFieldValue,\n TableFieldValue,\n};\n\n/** A block reference for `allow`: a defined block object or its name. */\ntype AllowRef = string | { name: string };\n/** A datasource reference for `datasource`: a defined datasource object or its slug. */\ntype DatasourceRef = string | { slug: string };\n\ntype NameOf<T> = T extends string ? T : T extends { name: infer N extends string } ? N : never;\ntype SlugOf<T> = T extends string ? T : T extends { slug: infer S extends string } ? S : never;\n\n/** Normalizes an `allow` input (ref, name, or array thereof) to a tuple of block-name strings. */\ntype NormalizeAllow<T> = T extends readonly any[]\n ? { [I in keyof T]: NameOf<T[I]> }\n : readonly [NameOf<T>];\n\n/**\n * Field config accepted by {@link defineField}: the content-shape field plus the\n * DSL reference keys. `allow` replaces the wire `component_whitelist`; `datasource`\n * holds the datasource ref/slug (the wire `source` selector still passes through).\n */\nexport type FieldInput = Field & {\n allow?: AllowRef | readonly AllowRef[];\n datasource?: DatasourceRef;\n required?: boolean;\n};\n\n/** Result of {@link defineField}: the field stamped with `name`, with refs normalized to strings. */\nexport type DefinedField<TName extends string, TField extends FieldInput> = Prettify<\n Omit<TField, 'allow' | 'datasource' | 'name'>\n & { name: TName }\n & (TField extends { allow: infer A } ? { allow: NormalizeAllow<A> } : unknown)\n & (TField extends { datasource: infer D } ? { datasource: SlugOf<D> } : unknown)\n>;\n\n/**\n * Returns a {@link Field} stamped with the given `name`, normalizing reference\n * keys to strings so everything downstream sees plain names/slugs. A thin,\n * strongly-typed identity helper it does not validate or throw.\n *\n * Use inside a {@link defineBlock} `fields` array — `pos` is injected from the\n * array index by `defineBlock`.\n *\n * @example\n * defineField('headline', { type: 'text', max_length: 100, required: true });\n * defineField('body', { type: 'bloks', allow: [heroBlock, 'teaser'] });\n * defineField('theme', { type: 'option', source: 'internal', datasource: colors });\n */\nexport function defineField<\n const TName extends string,\n const TField extends FieldInput,\n>(name: TName, field: TField): DefinedField<TName, TField>;\nexport function defineField(name: string, field: Record<string, unknown>): Record<string, unknown> {\n const { allow, datasource, ...rest } = field;\n const normalized: Record<string, unknown> = { ...rest, name };\n if (allow !== undefined) {\n const refs = Array.isArray(allow) ? allow : [allow];\n normalized.allow = refs.map(ref => (typeof ref === 'string' ? ref : isRecord(ref) ? ref.name : undefined));\n }\n if (datasource !== undefined) {\n normalized.datasource = typeof datasource === 'string' ? datasource : isRecord(datasource) ? datasource.slug : undefined;\n }\n return normalized;\n}\n"],"mappings":";;;AAiFA,SAAgB,YAAY,MAAc,OAAyD;CACjG,MAAM,EAAE,OAAO,YAAY,GAAG,SAAS;CACvC,MAAM,aAAsC;EAAE,GAAG;EAAM;EAAM;AAC7D,KAAI,UAAU,OAEZ,YAAW,SADE,MAAM,QAAQ,MAAM,GAAG,QAAQ,CAAC,MAAM,EAC3B,KAAI,QAAQ,OAAO,QAAQ,WAAW,MAAMA,2BAAS,IAAI,GAAG,IAAI,OAAO,OAAW;AAE5G,KAAI,eAAe,OACjB,YAAW,aAAa,OAAO,eAAe,WAAW,aAAaA,2BAAS,WAAW,GAAG,WAAW,OAAO;AAEjH,QAAO"}
@@ -1,99 +1,60 @@
1
1
  import { AssetFieldValue, Field, MultilinkFieldValue, PluginFieldValue, RichtextFieldValue, TableFieldValue } from "../generated/overlay/_internal.gen.cjs";
2
- import { Block } from "../generated/types/block.cjs";
2
+ import { BlockContent, BlockContentInput, BlocksFieldValue, FieldType, FieldValue, FieldValueInput } from "../generated/types/field.cjs";
3
3
  import { Prettify } from "../utils/prettify.cjs";
4
4
 
5
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;
6
+ /** A block reference for `allow`: a defined block object or its name. */
7
+ type AllowRef = string | {
8
+ name: string;
13
9
  };
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
- }
10
+ /** A datasource reference for `datasource`: a defined datasource object or its slug. */
11
+ type DatasourceRef = string | {
12
+ slug: string;
13
+ };
14
+ type NameOf<T> = T extends string ? T : T extends {
15
+ name: infer N extends string;
16
+ } ? N : never;
17
+ type SlugOf<T> = T extends string ? T : T extends {
18
+ slug: infer S extends string;
19
+ } ? S : never;
20
+ /** Normalizes an `allow` input (ref, name, or array thereof) to a tuple of block-name strings. */
21
+ type NormalizeAllow<T> = T extends readonly any[] ? { [I in keyof T]: NameOf<T[I]> } : readonly [NameOf<T>];
65
22
  /**
66
- * Checks whether a block is nestable, defaulting to `true` when
67
- * `is_nestable` is absent or undefined.
23
+ * Field config accepted by {@link defineField}: the content-shape field plus the
24
+ * DSL reference keys. `allow` replaces the wire `component_whitelist`; `datasource`
25
+ * holds the datasource ref/slug (the wire `source` selector still passes through).
68
26
  */
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']]>;
27
+ type FieldInput = Field & {
28
+ allow?: AllowRef | readonly AllowRef[];
29
+ datasource?: DatasourceRef;
30
+ required?: boolean;
31
+ };
32
+ /** Result of {@link defineField}: the field stamped with `name`, with refs normalized to strings. */
33
+ type DefinedField<TName extends string, TField extends FieldInput> = Prettify<Omit<TField, 'allow' | 'datasource' | 'name'> & {
34
+ name: TName;
35
+ } & (TField extends {
36
+ allow: infer A;
37
+ } ? {
38
+ allow: NormalizeAllow<A>;
39
+ } : unknown) & (TField extends {
40
+ datasource: infer D;
41
+ } ? {
42
+ datasource: SlugOf<D>;
43
+ } : unknown)>;
87
44
  /**
88
- * Returns a {@link Field} stamped with the given `name`. Use inside a
89
- * {@link defineBlock} `schema` array `pos` is inferred from array index.
45
+ * Returns a {@link Field} stamped with the given `name`, normalizing reference
46
+ * keys to strings so everything downstream sees plain names/slugs. A thin,
47
+ * strongly-typed identity helper — it does not validate or throw.
48
+ *
49
+ * Use inside a {@link defineBlock} `fields` array — `pos` is injected from the
50
+ * array index by `defineBlock`.
90
51
  *
91
52
  * @example
92
53
  * defineField('headline', { type: 'text', max_length: 100, required: true });
54
+ * defineField('body', { type: 'bloks', allow: [heroBlock, 'teaser'] });
55
+ * defineField('theme', { type: 'option', source: 'internal', datasource: colors });
93
56
  */
94
- declare const defineField: <const TName extends string, const TField extends Field>(name: TName, field: TField) => Omit<TField, "name"> & {
95
- name: TName;
96
- };
57
+ declare function defineField<const TName extends string, const TField extends FieldInput>(name: TName, field: TField): DefinedField<TName, TField>;
97
58
  //#endregion
98
- export { BlockContent, BlockContentInput, BlocksFieldValue, FieldType, FieldValue, FieldValueInput, defineField };
59
+ export { DefinedField, FieldInput, defineField };
99
60
  //# sourceMappingURL=define-field.d.cts.map