@datocms/cma-client 5.1.9 → 5.1.11

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 (226) hide show
  1. package/README.md +575 -0
  2. package/dist/cjs/fieldTypes/boolean.js +2 -2
  3. package/dist/cjs/fieldTypes/boolean.js.map +1 -1
  4. package/dist/cjs/fieldTypes/color.js +2 -2
  5. package/dist/cjs/fieldTypes/color.js.map +1 -1
  6. package/dist/cjs/fieldTypes/date.js +2 -3
  7. package/dist/cjs/fieldTypes/date.js.map +1 -1
  8. package/dist/cjs/fieldTypes/date_time.js +2 -2
  9. package/dist/cjs/fieldTypes/date_time.js.map +1 -1
  10. package/dist/cjs/fieldTypes/file.js +33 -5
  11. package/dist/cjs/fieldTypes/file.js.map +1 -1
  12. package/dist/cjs/fieldTypes/float.js +2 -2
  13. package/dist/cjs/fieldTypes/float.js.map +1 -1
  14. package/dist/cjs/fieldTypes/gallery.js +20 -5
  15. package/dist/cjs/fieldTypes/gallery.js.map +1 -1
  16. package/dist/cjs/fieldTypes/index.js +2 -2
  17. package/dist/cjs/fieldTypes/index.js.map +1 -1
  18. package/dist/cjs/fieldTypes/integer.js +2 -2
  19. package/dist/cjs/fieldTypes/integer.js.map +1 -1
  20. package/dist/cjs/fieldTypes/json.js +2 -3
  21. package/dist/cjs/fieldTypes/json.js.map +1 -1
  22. package/dist/cjs/fieldTypes/lat_lon.js +2 -2
  23. package/dist/cjs/fieldTypes/lat_lon.js.map +1 -1
  24. package/dist/cjs/fieldTypes/link.js +4 -4
  25. package/dist/cjs/fieldTypes/link.js.map +1 -1
  26. package/dist/cjs/fieldTypes/links.js +5 -3
  27. package/dist/cjs/fieldTypes/links.js.map +1 -1
  28. package/dist/cjs/fieldTypes/rich_text.js +4 -6
  29. package/dist/cjs/fieldTypes/rich_text.js.map +1 -1
  30. package/dist/cjs/fieldTypes/seo.js +2 -3
  31. package/dist/cjs/fieldTypes/seo.js.map +1 -1
  32. package/dist/cjs/fieldTypes/single_block.js +7 -7
  33. package/dist/cjs/fieldTypes/single_block.js.map +1 -1
  34. package/dist/cjs/fieldTypes/slug.js +2 -3
  35. package/dist/cjs/fieldTypes/slug.js.map +1 -1
  36. package/dist/cjs/fieldTypes/string.js +2 -2
  37. package/dist/cjs/fieldTypes/string.js.map +1 -1
  38. package/dist/cjs/fieldTypes/structured_text.js +4 -6
  39. package/dist/cjs/fieldTypes/structured_text.js.map +1 -1
  40. package/dist/cjs/fieldTypes/text.js +2 -3
  41. package/dist/cjs/fieldTypes/text.js.map +1 -1
  42. package/dist/cjs/fieldTypes/video.js +2 -2
  43. package/dist/cjs/fieldTypes/video.js.map +1 -1
  44. package/dist/cjs/generated/Client.js +1 -1
  45. package/dist/cjs/generated/Client.js.map +1 -1
  46. package/dist/cjs/generated/resources/Item.js.map +1 -1
  47. package/dist/cjs/generated/resources/Upload.js.map +1 -1
  48. package/dist/cjs/index.js +4 -4
  49. package/dist/cjs/index.js.map +1 -1
  50. package/dist/cjs/utilities/buildBlockRecord.js +8 -7
  51. package/dist/cjs/utilities/buildBlockRecord.js.map +1 -1
  52. package/dist/cjs/utilities/inspectItem.js +397 -0
  53. package/dist/cjs/utilities/inspectItem.js.map +1 -0
  54. package/dist/cjs/utilities/{blocks.js → nonRecursiveBlocks.js} +106 -111
  55. package/dist/cjs/utilities/nonRecursiveBlocks.js.map +1 -0
  56. package/dist/cjs/utilities/{fieldValue.js → normalizedFieldValues.js} +53 -41
  57. package/dist/cjs/utilities/normalizedFieldValues.js.map +1 -0
  58. package/dist/cjs/utilities/recursiveBlocks.js +121 -80
  59. package/dist/cjs/utilities/recursiveBlocks.js.map +1 -1
  60. package/dist/cjs/utilities/schemaRepository.js +2 -2
  61. package/dist/esm/fieldTypes/boolean.d.ts +1 -1
  62. package/dist/esm/fieldTypes/boolean.js +2 -2
  63. package/dist/esm/fieldTypes/boolean.js.map +1 -1
  64. package/dist/esm/fieldTypes/color.d.ts +1 -1
  65. package/dist/esm/fieldTypes/color.js +2 -2
  66. package/dist/esm/fieldTypes/color.js.map +1 -1
  67. package/dist/esm/fieldTypes/date.d.ts +1 -1
  68. package/dist/esm/fieldTypes/date.js +2 -3
  69. package/dist/esm/fieldTypes/date.js.map +1 -1
  70. package/dist/esm/fieldTypes/date_time.d.ts +1 -1
  71. package/dist/esm/fieldTypes/date_time.js +2 -2
  72. package/dist/esm/fieldTypes/date_time.js.map +1 -1
  73. package/dist/esm/fieldTypes/file.d.ts +68 -1
  74. package/dist/esm/fieldTypes/file.js +29 -3
  75. package/dist/esm/fieldTypes/file.js.map +1 -1
  76. package/dist/esm/fieldTypes/float.d.ts +1 -1
  77. package/dist/esm/fieldTypes/float.js +2 -2
  78. package/dist/esm/fieldTypes/float.js.map +1 -1
  79. package/dist/esm/fieldTypes/gallery.d.ts +27 -11
  80. package/dist/esm/fieldTypes/gallery.js +17 -4
  81. package/dist/esm/fieldTypes/gallery.js.map +1 -1
  82. package/dist/esm/fieldTypes/index.d.ts +2 -2
  83. package/dist/esm/fieldTypes/index.js +2 -2
  84. package/dist/esm/fieldTypes/index.js.map +1 -1
  85. package/dist/esm/fieldTypes/integer.d.ts +1 -1
  86. package/dist/esm/fieldTypes/integer.js +2 -2
  87. package/dist/esm/fieldTypes/integer.js.map +1 -1
  88. package/dist/esm/fieldTypes/json.d.ts +1 -1
  89. package/dist/esm/fieldTypes/json.js +2 -3
  90. package/dist/esm/fieldTypes/json.js.map +1 -1
  91. package/dist/esm/fieldTypes/lat_lon.d.ts +1 -1
  92. package/dist/esm/fieldTypes/lat_lon.js +2 -2
  93. package/dist/esm/fieldTypes/lat_lon.js.map +1 -1
  94. package/dist/esm/fieldTypes/link.d.ts +1 -1
  95. package/dist/esm/fieldTypes/link.js +4 -4
  96. package/dist/esm/fieldTypes/link.js.map +1 -1
  97. package/dist/esm/fieldTypes/links.d.ts +1 -1
  98. package/dist/esm/fieldTypes/links.js +5 -3
  99. package/dist/esm/fieldTypes/links.js.map +1 -1
  100. package/dist/esm/fieldTypes/rich_text.d.ts +1 -1
  101. package/dist/esm/fieldTypes/rich_text.js +4 -6
  102. package/dist/esm/fieldTypes/rich_text.js.map +1 -1
  103. package/dist/esm/fieldTypes/seo.d.ts +1 -1
  104. package/dist/esm/fieldTypes/seo.js +2 -3
  105. package/dist/esm/fieldTypes/seo.js.map +1 -1
  106. package/dist/esm/fieldTypes/single_block.d.ts +3 -3
  107. package/dist/esm/fieldTypes/single_block.js +7 -7
  108. package/dist/esm/fieldTypes/single_block.js.map +1 -1
  109. package/dist/esm/fieldTypes/slug.d.ts +1 -1
  110. package/dist/esm/fieldTypes/slug.js +2 -3
  111. package/dist/esm/fieldTypes/slug.js.map +1 -1
  112. package/dist/esm/fieldTypes/string.d.ts +1 -1
  113. package/dist/esm/fieldTypes/string.js +2 -2
  114. package/dist/esm/fieldTypes/string.js.map +1 -1
  115. package/dist/esm/fieldTypes/structured_text.d.ts +1 -1
  116. package/dist/esm/fieldTypes/structured_text.js +4 -6
  117. package/dist/esm/fieldTypes/structured_text.js.map +1 -1
  118. package/dist/esm/fieldTypes/text.d.ts +1 -1
  119. package/dist/esm/fieldTypes/text.js +2 -3
  120. package/dist/esm/fieldTypes/text.js.map +1 -1
  121. package/dist/esm/fieldTypes/video.d.ts +1 -1
  122. package/dist/esm/fieldTypes/video.js +2 -2
  123. package/dist/esm/fieldTypes/video.js.map +1 -1
  124. package/dist/esm/generated/Client.js +1 -1
  125. package/dist/esm/generated/Client.js.map +1 -1
  126. package/dist/esm/generated/resources/Item.d.ts +46 -28
  127. package/dist/esm/generated/resources/Item.js.map +1 -1
  128. package/dist/esm/generated/resources/ScheduledPublication.d.ts +3 -3
  129. package/dist/esm/generated/resources/ScheduledUnpublishing.d.ts +3 -3
  130. package/dist/esm/generated/resources/Upload.d.ts +10 -4
  131. package/dist/esm/generated/resources/Upload.js.map +1 -1
  132. package/dist/esm/index.d.ts +4 -4
  133. package/dist/esm/index.js +4 -4
  134. package/dist/esm/index.js.map +1 -1
  135. package/dist/esm/utilities/buildBlockRecord.d.ts +3 -3
  136. package/dist/esm/utilities/buildBlockRecord.js +9 -8
  137. package/dist/esm/utilities/buildBlockRecord.js.map +1 -1
  138. package/dist/esm/utilities/inspectItem.d.ts +8 -0
  139. package/dist/esm/utilities/inspectItem.js +393 -0
  140. package/dist/esm/utilities/inspectItem.js.map +1 -0
  141. package/dist/esm/utilities/itemDefinition.d.ts +36 -12
  142. package/dist/esm/utilities/nonRecursiveBlocks.d.ts +179 -0
  143. package/dist/esm/utilities/{blocks.js → nonRecursiveBlocks.js} +91 -96
  144. package/dist/esm/utilities/nonRecursiveBlocks.js.map +1 -0
  145. package/dist/{types/utilities/fieldValue.d.ts → esm/utilities/normalizedFieldValues.d.ts} +15 -14
  146. package/dist/esm/utilities/{fieldValue.js → normalizedFieldValues.js} +39 -28
  147. package/dist/esm/utilities/normalizedFieldValues.js.map +1 -0
  148. package/dist/esm/utilities/recursiveBlocks.d.ts +92 -9
  149. package/dist/esm/utilities/recursiveBlocks.js +113 -72
  150. package/dist/esm/utilities/recursiveBlocks.js.map +1 -1
  151. package/dist/esm/utilities/schemaRepository.d.ts +2 -2
  152. package/dist/esm/utilities/schemaRepository.js +2 -2
  153. package/dist/types/fieldTypes/boolean.d.ts +1 -1
  154. package/dist/types/fieldTypes/color.d.ts +1 -1
  155. package/dist/types/fieldTypes/date.d.ts +1 -1
  156. package/dist/types/fieldTypes/date_time.d.ts +1 -1
  157. package/dist/types/fieldTypes/file.d.ts +68 -1
  158. package/dist/types/fieldTypes/float.d.ts +1 -1
  159. package/dist/types/fieldTypes/gallery.d.ts +27 -11
  160. package/dist/types/fieldTypes/index.d.ts +2 -2
  161. package/dist/types/fieldTypes/integer.d.ts +1 -1
  162. package/dist/types/fieldTypes/json.d.ts +1 -1
  163. package/dist/types/fieldTypes/lat_lon.d.ts +1 -1
  164. package/dist/types/fieldTypes/link.d.ts +1 -1
  165. package/dist/types/fieldTypes/links.d.ts +1 -1
  166. package/dist/types/fieldTypes/rich_text.d.ts +1 -1
  167. package/dist/types/fieldTypes/seo.d.ts +1 -1
  168. package/dist/types/fieldTypes/single_block.d.ts +3 -3
  169. package/dist/types/fieldTypes/slug.d.ts +1 -1
  170. package/dist/types/fieldTypes/string.d.ts +1 -1
  171. package/dist/types/fieldTypes/structured_text.d.ts +1 -1
  172. package/dist/types/fieldTypes/text.d.ts +1 -1
  173. package/dist/types/fieldTypes/video.d.ts +1 -1
  174. package/dist/types/generated/resources/Item.d.ts +46 -28
  175. package/dist/types/generated/resources/ScheduledPublication.d.ts +3 -3
  176. package/dist/types/generated/resources/ScheduledUnpublishing.d.ts +3 -3
  177. package/dist/types/generated/resources/Upload.d.ts +10 -4
  178. package/dist/types/index.d.ts +4 -4
  179. package/dist/types/utilities/buildBlockRecord.d.ts +3 -3
  180. package/dist/types/utilities/inspectItem.d.ts +8 -0
  181. package/dist/types/utilities/itemDefinition.d.ts +36 -12
  182. package/dist/types/utilities/nonRecursiveBlocks.d.ts +179 -0
  183. package/dist/{esm/utilities/fieldValue.d.ts → types/utilities/normalizedFieldValues.d.ts} +15 -14
  184. package/dist/types/utilities/recursiveBlocks.d.ts +92 -9
  185. package/dist/types/utilities/schemaRepository.d.ts +2 -2
  186. package/package.json +4 -4
  187. package/src/fieldTypes/boolean.ts +5 -3
  188. package/src/fieldTypes/color.ts +5 -3
  189. package/src/fieldTypes/date.ts +5 -4
  190. package/src/fieldTypes/date_time.ts +5 -3
  191. package/src/fieldTypes/file.ts +98 -4
  192. package/src/fieldTypes/float.ts +5 -3
  193. package/src/fieldTypes/gallery.ts +53 -20
  194. package/src/fieldTypes/index.ts +2 -3
  195. package/src/fieldTypes/integer.ts +5 -3
  196. package/src/fieldTypes/json.ts +5 -4
  197. package/src/fieldTypes/lat_lon.ts +5 -3
  198. package/src/fieldTypes/link.ts +7 -5
  199. package/src/fieldTypes/links.ts +8 -4
  200. package/src/fieldTypes/rich_text.ts +7 -7
  201. package/src/fieldTypes/seo.ts +5 -4
  202. package/src/fieldTypes/single_block.ts +12 -10
  203. package/src/fieldTypes/slug.ts +5 -4
  204. package/src/fieldTypes/string.ts +5 -3
  205. package/src/fieldTypes/structured_text.ts +7 -7
  206. package/src/fieldTypes/text.ts +5 -4
  207. package/src/fieldTypes/video.ts +5 -3
  208. package/src/generated/Client.ts +1 -1
  209. package/src/generated/resources/Item.ts +129 -92
  210. package/src/generated/resources/ScheduledPublication.ts +6 -6
  211. package/src/generated/resources/ScheduledUnpublishing.ts +6 -6
  212. package/src/generated/resources/Upload.ts +36 -10
  213. package/src/index.ts +4 -4
  214. package/src/utilities/buildBlockRecord.ts +24 -31
  215. package/src/utilities/inspectItem.ts +590 -0
  216. package/src/utilities/itemDefinition.ts +53 -35
  217. package/src/utilities/{blocks.ts → nonRecursiveBlocks.ts} +170 -136
  218. package/src/utilities/{fieldValue.ts → normalizedFieldValues.ts} +70 -30
  219. package/src/utilities/recursiveBlocks.ts +186 -171
  220. package/src/utilities/schemaRepository.ts +2 -2
  221. package/dist/cjs/utilities/blocks.js.map +0 -1
  222. package/dist/cjs/utilities/fieldValue.js.map +0 -1
  223. package/dist/esm/utilities/blocks.d.ts +0 -180
  224. package/dist/esm/utilities/blocks.js.map +0 -1
  225. package/dist/esm/utilities/fieldValue.js.map +0 -1
  226. package/dist/types/utilities/blocks.d.ts +0 -180
@@ -1,5 +1,5 @@
1
- import type { BooleanFieldValue, ColorFieldValue, DateFieldValue, DateTimeFieldValue, FileFieldValue, FloatFieldValue, GalleryFieldValue, IntegerFieldValue, JsonFieldValue, LatLonFieldValue, LinkFieldValue, LinksFieldValue, RichTextFieldValue, RichTextFieldValueAsRequest, RichTextFieldValueWithNestedBlocks, SeoFieldValue, SingleBlockFieldValue, SingleBlockFieldValueAsRequest, SingleBlockFieldValueWithNestedBlocks, SlugFieldValue, StringFieldValue, StructuredTextFieldValue, StructuredTextFieldValueAsRequest, StructuredTextFieldValueWithNestedBlocks, TextFieldValue, VideoFieldValue } from '../fieldTypes';
2
- import type { LocalizedFieldValue } from './fieldValue';
1
+ import type { BooleanFieldValue, ColorFieldValue, DateFieldValue, DateTimeFieldValue, FileFieldValue, FileFieldValueAsRequest, FloatFieldValue, GalleryFieldValue, GalleryFieldValueAsRequest, IntegerFieldValue, JsonFieldValue, LatLonFieldValue, LinkFieldValue, LinksFieldValue, RichTextFieldValue, RichTextFieldValueAsRequest, RichTextFieldValueWithNestedBlocks, SeoFieldValue, SingleBlockFieldValue, SingleBlockFieldValueAsRequest, SingleBlockFieldValueWithNestedBlocks, SlugFieldValue, StringFieldValue, StructuredTextFieldValue, StructuredTextFieldValueAsRequest, StructuredTextFieldValueWithNestedBlocks, TextFieldValue, VideoFieldValue } from '../fieldTypes';
2
+ import type { LocalizedFieldValue } from './normalizedFieldValues';
3
3
  /** Base field definition */
4
4
  type BaseFieldDefinition<Type extends string> = {
5
5
  type: Type;
@@ -32,7 +32,7 @@ export type ItemDefinition<ItemTypeId extends string = string, FieldValues exten
32
32
  itemTypeId: ItemTypeId;
33
33
  fields: FieldValues;
34
34
  };
35
- /** Standard field values */
35
+ /** Standard field values (response format) */
36
36
  type FieldTypeToValue = {
37
37
  boolean: BooleanFieldValue;
38
38
  color: ColorFieldValue;
@@ -56,6 +56,30 @@ type FieldTypeToValue = {
56
56
  video: VideoFieldValue;
57
57
  unknown: unknown;
58
58
  };
59
+ /** Request field values (request format with optional metadata) */
60
+ type FieldTypeToValueAsRequest = {
61
+ boolean: BooleanFieldValue;
62
+ color: ColorFieldValue;
63
+ date: DateFieldValue;
64
+ date_time: DateTimeFieldValue;
65
+ file: FileFieldValueAsRequest;
66
+ float: FloatFieldValue;
67
+ gallery: GalleryFieldValueAsRequest;
68
+ integer: IntegerFieldValue;
69
+ json: JsonFieldValue;
70
+ lat_lon: LatLonFieldValue;
71
+ link: LinkFieldValue;
72
+ links: LinksFieldValue;
73
+ rich_text: RichTextFieldValueAsRequest;
74
+ seo: SeoFieldValue;
75
+ single_block: SingleBlockFieldValueAsRequest;
76
+ slug: SlugFieldValue;
77
+ string: StringFieldValue;
78
+ structured_text: StructuredTextFieldValueAsRequest;
79
+ text: TextFieldValue;
80
+ video: VideoFieldValue;
81
+ unknown: unknown;
82
+ };
59
83
  /** Localized wrapper */
60
84
  type LocalizeIfNeeded<T extends FieldDefinition, Value, Locales extends string> = T extends {
61
85
  localized: true;
@@ -63,24 +87,24 @@ type LocalizeIfNeeded<T extends FieldDefinition, Value, Locales extends string>
63
87
  /** Standard mapping */
64
88
  type FieldDefinitionToFieldValue<T extends FieldDefinition, Locales extends string> = LocalizeIfNeeded<T, FieldTypeToValue[T['type']], Locales>;
65
89
  /** AsRequest mapping (block fields become generic over allowed blocks) */
66
- type FieldDefinitionToFieldValueAsRequest<T extends FieldDefinition, Locales extends string> = T extends RichTextFieldDefinition<infer B> ? LocalizeIfNeeded<T, RichTextFieldValueAsRequest<ItemTypeDefinitionToItemDefinitionAsRequest<B>>, Locales> : T extends SingleBlockFieldDefinition<infer B> ? LocalizeIfNeeded<T, SingleBlockFieldValueAsRequest<ItemTypeDefinitionToItemDefinitionAsRequest<B>>, Locales> : T extends StructuredTextFieldDefinition<infer B, infer I> ? LocalizeIfNeeded<T, StructuredTextFieldValueAsRequest<T extends {
90
+ type FieldDefinitionToFieldValueAsRequest<T extends FieldDefinition, Locales extends string> = T extends RichTextFieldDefinition<infer B> ? LocalizeIfNeeded<T, RichTextFieldValueAsRequest<ToItemDefinitionAsRequest<B>>, Locales> : T extends SingleBlockFieldDefinition<infer B> ? LocalizeIfNeeded<T, SingleBlockFieldValueAsRequest<ToItemDefinitionAsRequest<B>>, Locales> : T extends StructuredTextFieldDefinition<infer B, infer I> ? LocalizeIfNeeded<T, StructuredTextFieldValueAsRequest<T extends {
67
91
  blocks: any;
68
- } ? ItemTypeDefinitionToItemDefinitionAsRequest<B> : never, T extends {
92
+ } ? ToItemDefinitionAsRequest<B> : never, T extends {
69
93
  inline_blocks: any;
70
- } ? ItemTypeDefinitionToItemDefinitionAsRequest<I> : never>, Locales> : LocalizeIfNeeded<T, FieldTypeToValue[T['type']], Locales>;
71
- type FieldDefinitionToFieldValueWithNestedBlocks<T extends FieldDefinition, Locales extends string> = T extends RichTextFieldDefinition<infer B> ? LocalizeIfNeeded<T, RichTextFieldValueWithNestedBlocks<ItemTypeDefinitionToItemDefinitionWithNestedBlocks<B>>, Locales> : T extends SingleBlockFieldDefinition<infer B> ? LocalizeIfNeeded<T, SingleBlockFieldValueWithNestedBlocks<ItemTypeDefinitionToItemDefinitionWithNestedBlocks<B>>, Locales> : T extends StructuredTextFieldDefinition<infer B, infer I> ? LocalizeIfNeeded<T, StructuredTextFieldValueWithNestedBlocks<T extends {
94
+ } ? ToItemDefinitionAsRequest<I> : never>, Locales> : LocalizeIfNeeded<T, FieldTypeToValueAsRequest[T['type']], Locales>;
95
+ type FieldDefinitionToFieldValueWithNestedBlocks<T extends FieldDefinition, Locales extends string> = T extends RichTextFieldDefinition<infer B> ? LocalizeIfNeeded<T, RichTextFieldValueWithNestedBlocks<ToItemDefinitionWithNestedBlocks<B>>, Locales> : T extends SingleBlockFieldDefinition<infer B> ? LocalizeIfNeeded<T, SingleBlockFieldValueWithNestedBlocks<ToItemDefinitionWithNestedBlocks<B>>, Locales> : T extends StructuredTextFieldDefinition<infer B, infer I> ? LocalizeIfNeeded<T, StructuredTextFieldValueWithNestedBlocks<T extends {
72
96
  blocks: any;
73
- } ? ItemTypeDefinitionToItemDefinitionWithNestedBlocks<B> : never, T extends {
97
+ } ? ToItemDefinitionWithNestedBlocks<B> : never, T extends {
74
98
  inline_blocks: any;
75
- } ? ItemTypeDefinitionToItemDefinitionWithNestedBlocks<I> : never>, Locales> : LocalizeIfNeeded<T, FieldTypeToValue[T['type']], Locales>;
99
+ } ? ToItemDefinitionWithNestedBlocks<I> : never>, Locales> : LocalizeIfNeeded<T, FieldTypeToValue[T['type']], Locales>;
76
100
  /** Transformers */
77
- export type ItemTypeDefinitionToItemDefinition<T extends ItemTypeDefinition<any, any, any>> = T extends ItemTypeDefinition<infer Settings, infer ItemTypeId, infer Fields> ? keyof Fields extends never ? ItemDefinition<ItemTypeId> : ItemDefinition<ItemTypeId, {
101
+ export type ToItemDefinition<T extends ItemTypeDefinition<any, any, any>> = T extends ItemTypeDefinition<infer Settings, infer ItemTypeId, infer Fields> ? keyof Fields extends never ? ItemDefinition<ItemTypeId> : ItemDefinition<ItemTypeId, {
78
102
  [K in keyof Fields]: Fields[K] extends FieldDefinition ? FieldDefinitionToFieldValue<Fields[K], Settings['locales']> : never;
79
103
  }> : never;
80
- export type ItemTypeDefinitionToItemDefinitionAsRequest<T extends ItemTypeDefinition<any, any, any>> = T extends ItemTypeDefinition<infer Settings, infer ItemTypeId, infer Fields> ? keyof Fields extends never ? ItemDefinition<ItemTypeId> : ItemDefinition<ItemTypeId, Partial<{
104
+ export type ToItemDefinitionAsRequest<T extends ItemTypeDefinition<any, any, any>> = T extends ItemTypeDefinition<infer Settings, infer ItemTypeId, infer Fields> ? keyof Fields extends never ? ItemDefinition<ItemTypeId> : ItemDefinition<ItemTypeId, Partial<{
81
105
  [K in keyof Fields]: Fields[K] extends FieldDefinition ? FieldDefinitionToFieldValueAsRequest<Fields[K], Settings['locales']> : never;
82
106
  }>> : never;
83
- export type ItemTypeDefinitionToItemDefinitionWithNestedBlocks<T extends ItemTypeDefinition<any, any, any>> = T extends ItemTypeDefinition<infer Settings, infer ItemTypeId, infer Fields> ? keyof Fields extends never ? ItemDefinition<ItemTypeId> : ItemDefinition<ItemTypeId, {
107
+ export type ToItemDefinitionWithNestedBlocks<T extends ItemTypeDefinition<any, any, any>> = T extends ItemTypeDefinition<infer Settings, infer ItemTypeId, infer Fields> ? keyof Fields extends never ? ItemDefinition<ItemTypeId> : ItemDefinition<ItemTypeId, {
84
108
  [K in keyof Fields]: Fields[K] extends FieldDefinition ? FieldDefinitionToFieldValueWithNestedBlocks<Fields[K], Settings['locales']> : never;
85
109
  }> : never;
86
110
  export type UnknownField = Record<string, unknown>;
@@ -0,0 +1,179 @@
1
+ /**
2
+ * DatoCMS Block Field Value Processing Utilities
3
+ *
4
+ * This utility provides a unified interface for working with blocks embedded within DatoCMS field values.
5
+ * DatoCMS supports three field types that can contain blocks:
6
+ * - Modular Content fields: arrays of blocks
7
+ * - Single Block fields: a single block
8
+ * - Structured Text fields: complex document structures with embedded blocks
9
+ *
10
+ * The challenge this solves: Each field type stores blocks differently and requires different
11
+ * traversal logic, making it complex to perform operations like transformations, filtering,
12
+ * or searching across blocks regardless of their containing field type.
13
+ *
14
+ * This utility abstracts away these differences, providing a consistent API to:
15
+ * - Visit/iterate through all blocks in any field type
16
+ * - Transform blocks while preserving field structure
17
+ * - Filter blocks based on conditions
18
+ * - Search for specific blocks
19
+ * - Perform functional operations (map, reduce, some, every)
20
+ *
21
+ * All functions come in both sync and async variants to support different use cases,
22
+ * particularly useful when block transformations require async operations like API calls.
23
+ */
24
+ import { type TreePath } from 'datocms-structured-text-utils';
25
+ import type { BlockItemInARequest } from '../fieldTypes';
26
+ import type * as ApiTypes from '../generated/ApiTypes';
27
+ /**
28
+ * Visit every block in a field value, calling the visitor function for each block found.
29
+ * Supports rich text, single block, and structured text field types.
30
+ *
31
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
32
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to visit
33
+ * @param visitor - Synchronous function called for each block. Receives the block item and its path
34
+ */
35
+ export declare function nonRecursiveVisitBlocksInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, visitor: (item: BlockItemInARequest, path: TreePath) => void): void;
36
+ /**
37
+ * Visit every block in a field value, calling the visitor function for each block found.
38
+ * Supports rich text, single block, and structured text field types.
39
+ *
40
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
41
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to visit
42
+ * @param visitor - Asynchronous function called for each block. Receives the block item and its path
43
+ * @returns Promise that resolves when all blocks have been visited
44
+ */
45
+ export declare function nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, visitor: (item: BlockItemInARequest, path: TreePath) => Promise<void>): Promise<void>;
46
+ /**
47
+ * Transform blocks in a field value by applying a mapping function to each block.
48
+ * Creates a new field value structure with transformed blocks while preserving the original structure.
49
+ * Supports rich text, single block, and structured text field types.
50
+ *
51
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
52
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to transform
53
+ * @param mapper - Synchronous function that transforms each block. Receives block item and path, returns new block
54
+ * @returns The new field value with transformed blocks
55
+ */
56
+ export declare function nonRecursiveMapBlocksInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, mapper: (item: BlockItemInARequest, path: TreePath) => BlockItemInARequest): unknown;
57
+ /**
58
+ * Transform blocks in a field value by applying a mapping function to each block.
59
+ * Creates a new field value structure with transformed blocks while preserving the original structure.
60
+ * Supports rich text, single block, and structured text field types.
61
+ *
62
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
63
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to transform
64
+ * @param mapper - Asynchronous function that transforms each block. Receives block item and path, returns new block
65
+ * @returns Promise that resolves to the new field value with transformed blocks
66
+ */
67
+ export declare function nonRecursiveMapBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, mapper: (item: BlockItemInARequest, path: TreePath) => Promise<BlockItemInARequest>): Promise<unknown>;
68
+ /**
69
+ * Find all blocks that match the predicate function.
70
+ * Searches through all blocks in the non-localized field value and returns all matches.
71
+ *
72
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
73
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to search
74
+ * @param predicate - Synchronous function that tests each block. Should return true for matching blocks
75
+ * @returns Array of objects, each containing a matching block and its path
76
+ */
77
+ export declare function nonRecursiveFindAllBlocksInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean): Array<{
78
+ item: BlockItemInARequest;
79
+ path: TreePath;
80
+ }>;
81
+ /**
82
+ * Find all blocks that match the predicate function.
83
+ * Searches through all blocks in the non-localized field value and returns all matches.
84
+ *
85
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
86
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to search
87
+ * @param predicate - Asynchronous function that tests each block. Should return true for matching blocks
88
+ * @returns Promise that resolves to an array of objects, each containing a matching block and its path
89
+ */
90
+ export declare function nonRecursiveFindAllBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => Promise<boolean>): Promise<Array<{
91
+ item: BlockItemInARequest;
92
+ path: TreePath;
93
+ }>>;
94
+ /**
95
+ * Filter blocks in a field value, removing those that don't match the predicate.
96
+ * Creates a new field value containing only blocks that pass the predicate test.
97
+ * Preserves the original field value structure and hierarchy.
98
+ *
99
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
100
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to filter
101
+ * @param predicate - Synchronous function that tests each block. Blocks returning false are removed
102
+ * @returns The new field value with filtered blocks
103
+ */
104
+ export declare function nonRecursiveFilterBlocksInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean): unknown;
105
+ /**
106
+ * Filter blocks in a field value, removing those that don't match the predicate.
107
+ * Creates a new field value containing only blocks that pass the predicate test.
108
+ * Preserves the original field value structure and hierarchy.
109
+ *
110
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
111
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to filter
112
+ * @param predicate - Asynchronous function that tests each block. Blocks returning false are removed
113
+ * @returns Promise that resolves to the new field value with filtered blocks
114
+ */
115
+ export declare function nonRecursiveFilterBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => Promise<boolean>): Promise<unknown>;
116
+ /**
117
+ * Reduce all blocks in a field value to a single value by applying a reducer function.
118
+ * Processes each block in the non-localized field value and accumulates the results into a single value.
119
+ *
120
+ * @template R - The type of the accumulated result
121
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
122
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to reduce
123
+ * @param reducer - Synchronous function that processes each block and updates the accumulator
124
+ * @param initialValue - The initial value for the accumulator
125
+ * @returns The final accumulated value
126
+ */
127
+ export declare function nonRecursiveReduceBlocksInNonLocalizedFieldValue<R>(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, reducer: (accumulator: R, item: BlockItemInARequest, path: TreePath) => R, initialValue: R): R;
128
+ /**
129
+ * Reduce all blocks in a field value to a single value by applying a reducer function.
130
+ * Processes each block in the non-localized field value and accumulates the results into a single value.
131
+ *
132
+ * @template R - The type of the accumulated result
133
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
134
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to reduce
135
+ * @param reducer - Asynchronous function that processes each block and updates the accumulator
136
+ * @param initialValue - The initial value for the accumulator
137
+ * @returns Promise that resolves to the final accumulated value
138
+ */
139
+ export declare function nonRecursiveReduceBlocksInNonLocalizedFieldValueAsync<R>(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, reducer: (accumulator: R, item: BlockItemInARequest, path: TreePath) => Promise<R>, initialValue: R): Promise<R>;
140
+ /**
141
+ * Check if any block in the non-localized field value matches the predicate function.
142
+ * Returns true as soon as the first matching block is found (short-circuit evaluation).
143
+ *
144
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
145
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
146
+ * @param predicate - Synchronous function that tests each block. Should return true for matching blocks
147
+ * @returns True if any block matches, false otherwise
148
+ */
149
+ export declare function nonRecursiveSomeBlocksInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean): boolean;
150
+ /**
151
+ * Check if any block in the non-localized field value matches the predicate function.
152
+ * Returns true as soon as the first matching block is found (short-circuit evaluation).
153
+ *
154
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
155
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
156
+ * @param predicate - Asynchronous function that tests each block. Should return true for matching blocks
157
+ * @returns Promise that resolves to true if any block matches, false otherwise
158
+ */
159
+ export declare function nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => Promise<boolean>): Promise<boolean>;
160
+ /**
161
+ * Check if every block in the non-localized field value matches the predicate function.
162
+ * Returns false as soon as the first non-matching block is found (short-circuit evaluation).
163
+ *
164
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
165
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
166
+ * @param predicate - Synchronous function that tests each block. Should return true for valid blocks
167
+ * @returns True if all blocks match, false otherwise
168
+ */
169
+ export declare function nonRecursiveEveryBlockInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean): boolean;
170
+ /**
171
+ * Check if every block in the non-localized field value matches the predicate function.
172
+ * Returns false as soon as the first non-matching block is found (short-circuit evaluation).
173
+ *
174
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
175
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
176
+ * @param predicate - Asynchronous function that tests each block. Should return true for valid blocks
177
+ * @returns Promise that resolves to true if all blocks match, false otherwise
178
+ */
179
+ export declare function nonRecursiveEveryBlockInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => Promise<boolean>): Promise<boolean>;