@datocms/cma-client 5.1.10 → 5.1.12

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 (253) hide show
  1. package/README.md +569 -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 +18 -18
  29. package/dist/cjs/fieldTypes/rich_text.js.map +1 -1
  30. package/dist/cjs/fieldTypes/schema.js +3 -0
  31. package/dist/cjs/fieldTypes/schema.js.map +1 -0
  32. package/dist/cjs/fieldTypes/seo.js +2 -3
  33. package/dist/cjs/fieldTypes/seo.js.map +1 -1
  34. package/dist/cjs/fieldTypes/single_block.js +20 -19
  35. package/dist/cjs/fieldTypes/single_block.js.map +1 -1
  36. package/dist/cjs/fieldTypes/slug.js +2 -3
  37. package/dist/cjs/fieldTypes/slug.js.map +1 -1
  38. package/dist/cjs/fieldTypes/string.js +2 -2
  39. package/dist/cjs/fieldTypes/string.js.map +1 -1
  40. package/dist/cjs/fieldTypes/structured_text.js +17 -18
  41. package/dist/cjs/fieldTypes/structured_text.js.map +1 -1
  42. package/dist/cjs/fieldTypes/text.js +2 -3
  43. package/dist/cjs/fieldTypes/text.js.map +1 -1
  44. package/dist/cjs/fieldTypes/video.js +2 -2
  45. package/dist/cjs/fieldTypes/video.js.map +1 -1
  46. package/dist/cjs/generated/Client.js +1 -1
  47. package/dist/cjs/generated/resources/Item.js.map +1 -1
  48. package/dist/cjs/generated/resources/ScheduledPublication.js.map +1 -1
  49. package/dist/cjs/generated/resources/ScheduledUnpublishing.js.map +1 -1
  50. package/dist/cjs/generated/resources/Upload.js.map +1 -1
  51. package/dist/cjs/index.js +5 -4
  52. package/dist/cjs/index.js.map +1 -1
  53. package/dist/cjs/utilities/buildBlockRecord.js +1 -45
  54. package/dist/cjs/utilities/buildBlockRecord.js.map +1 -1
  55. package/dist/cjs/utilities/duplicateBlockRecord.js +49 -0
  56. package/dist/cjs/utilities/duplicateBlockRecord.js.map +1 -0
  57. package/dist/cjs/utilities/inspectItem.js +427 -0
  58. package/dist/cjs/utilities/inspectItem.js.map +1 -0
  59. package/dist/cjs/utilities/{blocks.js → nonRecursiveBlocks.js} +60 -234
  60. package/dist/cjs/utilities/nonRecursiveBlocks.js.map +1 -0
  61. package/dist/cjs/utilities/{fieldValue.js → normalizedFieldValues.js} +53 -41
  62. package/dist/cjs/utilities/normalizedFieldValues.js.map +1 -0
  63. package/dist/cjs/utilities/recursiveBlocks.js +73 -92
  64. package/dist/cjs/utilities/recursiveBlocks.js.map +1 -1
  65. package/dist/cjs/utilities/schemaRepository.js +2 -2
  66. package/dist/esm/fieldTypes/boolean.d.ts +1 -1
  67. package/dist/esm/fieldTypes/boolean.js +2 -2
  68. package/dist/esm/fieldTypes/boolean.js.map +1 -1
  69. package/dist/esm/fieldTypes/color.d.ts +1 -1
  70. package/dist/esm/fieldTypes/color.js +2 -2
  71. package/dist/esm/fieldTypes/color.js.map +1 -1
  72. package/dist/esm/fieldTypes/date.d.ts +1 -1
  73. package/dist/esm/fieldTypes/date.js +2 -3
  74. package/dist/esm/fieldTypes/date.js.map +1 -1
  75. package/dist/esm/fieldTypes/date_time.d.ts +1 -1
  76. package/dist/esm/fieldTypes/date_time.js +2 -2
  77. package/dist/esm/fieldTypes/date_time.js.map +1 -1
  78. package/dist/esm/fieldTypes/file.d.ts +68 -1
  79. package/dist/esm/fieldTypes/file.js +29 -3
  80. package/dist/esm/fieldTypes/file.js.map +1 -1
  81. package/dist/esm/fieldTypes/float.d.ts +1 -1
  82. package/dist/esm/fieldTypes/float.js +2 -2
  83. package/dist/esm/fieldTypes/float.js.map +1 -1
  84. package/dist/esm/fieldTypes/gallery.d.ts +27 -11
  85. package/dist/esm/fieldTypes/gallery.js +17 -4
  86. package/dist/esm/fieldTypes/gallery.js.map +1 -1
  87. package/dist/esm/fieldTypes/index.d.ts +2 -2
  88. package/dist/esm/fieldTypes/index.js +2 -2
  89. package/dist/esm/fieldTypes/index.js.map +1 -1
  90. package/dist/esm/fieldTypes/integer.d.ts +1 -1
  91. package/dist/esm/fieldTypes/integer.js +2 -2
  92. package/dist/esm/fieldTypes/integer.js.map +1 -1
  93. package/dist/esm/fieldTypes/json.d.ts +1 -1
  94. package/dist/esm/fieldTypes/json.js +2 -3
  95. package/dist/esm/fieldTypes/json.js.map +1 -1
  96. package/dist/esm/fieldTypes/lat_lon.d.ts +1 -1
  97. package/dist/esm/fieldTypes/lat_lon.js +2 -2
  98. package/dist/esm/fieldTypes/lat_lon.js.map +1 -1
  99. package/dist/esm/fieldTypes/link.d.ts +1 -1
  100. package/dist/esm/fieldTypes/link.js +4 -4
  101. package/dist/esm/fieldTypes/link.js.map +1 -1
  102. package/dist/esm/fieldTypes/links.d.ts +1 -1
  103. package/dist/esm/fieldTypes/links.js +5 -3
  104. package/dist/esm/fieldTypes/links.js.map +1 -1
  105. package/dist/esm/fieldTypes/rich_text.d.ts +9 -10
  106. package/dist/esm/fieldTypes/rich_text.js +13 -13
  107. package/dist/esm/fieldTypes/rich_text.js.map +1 -1
  108. package/dist/esm/fieldTypes/schema.d.ts +59 -0
  109. package/dist/esm/fieldTypes/schema.js +2 -0
  110. package/dist/esm/fieldTypes/schema.js.map +1 -0
  111. package/dist/esm/fieldTypes/seo.d.ts +1 -1
  112. package/dist/esm/fieldTypes/seo.js +2 -3
  113. package/dist/esm/fieldTypes/seo.js.map +1 -1
  114. package/dist/esm/fieldTypes/single_block.d.ts +31 -16
  115. package/dist/esm/fieldTypes/single_block.js +15 -14
  116. package/dist/esm/fieldTypes/single_block.js.map +1 -1
  117. package/dist/esm/fieldTypes/slug.d.ts +1 -1
  118. package/dist/esm/fieldTypes/slug.js +2 -3
  119. package/dist/esm/fieldTypes/slug.js.map +1 -1
  120. package/dist/esm/fieldTypes/string.d.ts +1 -1
  121. package/dist/esm/fieldTypes/string.js +2 -2
  122. package/dist/esm/fieldTypes/string.js.map +1 -1
  123. package/dist/esm/fieldTypes/structured_text.d.ts +15 -16
  124. package/dist/esm/fieldTypes/structured_text.js +12 -13
  125. package/dist/esm/fieldTypes/structured_text.js.map +1 -1
  126. package/dist/esm/fieldTypes/text.d.ts +1 -1
  127. package/dist/esm/fieldTypes/text.js +2 -3
  128. package/dist/esm/fieldTypes/text.js.map +1 -1
  129. package/dist/esm/fieldTypes/video.d.ts +1 -1
  130. package/dist/esm/fieldTypes/video.js +2 -2
  131. package/dist/esm/fieldTypes/video.js.map +1 -1
  132. package/dist/esm/generated/ApiTypes.d.ts +90 -980
  133. package/dist/esm/generated/Client.js +1 -1
  134. package/dist/esm/generated/RawApiTypes.d.ts +156 -999
  135. package/dist/esm/generated/resources/Field.d.ts +200 -200
  136. package/dist/esm/generated/resources/Item.d.ts +34 -34
  137. package/dist/esm/generated/resources/Item.js.map +1 -1
  138. package/dist/esm/generated/resources/ItemVersion.d.ts +3 -1
  139. package/dist/esm/generated/resources/ScheduledPublication.d.ts +3 -3
  140. package/dist/esm/generated/resources/ScheduledPublication.js.map +1 -1
  141. package/dist/esm/generated/resources/ScheduledUnpublishing.d.ts +3 -3
  142. package/dist/esm/generated/resources/ScheduledUnpublishing.js.map +1 -1
  143. package/dist/esm/generated/resources/Upload.d.ts +6 -6
  144. package/dist/esm/generated/resources/Upload.js.map +1 -1
  145. package/dist/esm/index.d.ts +5 -4
  146. package/dist/esm/index.js +5 -4
  147. package/dist/esm/index.js.map +1 -1
  148. package/dist/esm/utilities/buildBlockRecord.d.ts +3 -5
  149. package/dist/esm/utilities/buildBlockRecord.js +0 -43
  150. package/dist/esm/utilities/buildBlockRecord.js.map +1 -1
  151. package/dist/esm/utilities/duplicateBlockRecord.d.ts +6 -0
  152. package/dist/esm/utilities/duplicateBlockRecord.js +45 -0
  153. package/dist/esm/utilities/duplicateBlockRecord.js.map +1 -0
  154. package/dist/esm/utilities/inspectItem.d.ts +8 -0
  155. package/dist/esm/utilities/inspectItem.js +400 -0
  156. package/dist/esm/utilities/inspectItem.js.map +1 -0
  157. package/dist/esm/utilities/itemDefinition.d.ts +45 -23
  158. package/dist/esm/utilities/nonRecursiveBlocks.d.ts +114 -0
  159. package/dist/esm/utilities/{blocks.js → nonRecursiveBlocks.js} +52 -220
  160. package/dist/esm/utilities/nonRecursiveBlocks.js.map +1 -0
  161. package/dist/{types/utilities/fieldValue.d.ts → esm/utilities/normalizedFieldValues.d.ts} +15 -14
  162. package/dist/esm/utilities/{fieldValue.js → normalizedFieldValues.js} +39 -28
  163. package/dist/esm/utilities/normalizedFieldValues.js.map +1 -0
  164. package/dist/esm/utilities/recursiveBlocks.d.ts +124 -11
  165. package/dist/esm/utilities/recursiveBlocks.js +65 -84
  166. package/dist/esm/utilities/recursiveBlocks.js.map +1 -1
  167. package/dist/esm/utilities/schemaRepository.d.ts +2 -2
  168. package/dist/esm/utilities/schemaRepository.js +2 -2
  169. package/dist/types/fieldTypes/boolean.d.ts +1 -1
  170. package/dist/types/fieldTypes/color.d.ts +1 -1
  171. package/dist/types/fieldTypes/date.d.ts +1 -1
  172. package/dist/types/fieldTypes/date_time.d.ts +1 -1
  173. package/dist/types/fieldTypes/file.d.ts +68 -1
  174. package/dist/types/fieldTypes/float.d.ts +1 -1
  175. package/dist/types/fieldTypes/gallery.d.ts +27 -11
  176. package/dist/types/fieldTypes/index.d.ts +2 -2
  177. package/dist/types/fieldTypes/integer.d.ts +1 -1
  178. package/dist/types/fieldTypes/json.d.ts +1 -1
  179. package/dist/types/fieldTypes/lat_lon.d.ts +1 -1
  180. package/dist/types/fieldTypes/link.d.ts +1 -1
  181. package/dist/types/fieldTypes/links.d.ts +1 -1
  182. package/dist/types/fieldTypes/rich_text.d.ts +9 -10
  183. package/dist/types/fieldTypes/schema.d.ts +59 -0
  184. package/dist/types/fieldTypes/seo.d.ts +1 -1
  185. package/dist/types/fieldTypes/single_block.d.ts +31 -16
  186. package/dist/types/fieldTypes/slug.d.ts +1 -1
  187. package/dist/types/fieldTypes/string.d.ts +1 -1
  188. package/dist/types/fieldTypes/structured_text.d.ts +15 -16
  189. package/dist/types/fieldTypes/text.d.ts +1 -1
  190. package/dist/types/fieldTypes/video.d.ts +1 -1
  191. package/dist/types/generated/ApiTypes.d.ts +90 -980
  192. package/dist/types/generated/RawApiTypes.d.ts +156 -999
  193. package/dist/types/generated/resources/Field.d.ts +200 -200
  194. package/dist/types/generated/resources/Item.d.ts +34 -34
  195. package/dist/types/generated/resources/ItemVersion.d.ts +3 -1
  196. package/dist/types/generated/resources/ScheduledPublication.d.ts +3 -3
  197. package/dist/types/generated/resources/ScheduledUnpublishing.d.ts +3 -3
  198. package/dist/types/generated/resources/Upload.d.ts +6 -6
  199. package/dist/types/index.d.ts +5 -4
  200. package/dist/types/utilities/buildBlockRecord.d.ts +3 -5
  201. package/dist/types/utilities/duplicateBlockRecord.d.ts +6 -0
  202. package/dist/types/utilities/inspectItem.d.ts +8 -0
  203. package/dist/types/utilities/itemDefinition.d.ts +45 -23
  204. package/dist/types/utilities/nonRecursiveBlocks.d.ts +114 -0
  205. package/dist/{esm/utilities/fieldValue.d.ts → types/utilities/normalizedFieldValues.d.ts} +15 -14
  206. package/dist/types/utilities/recursiveBlocks.d.ts +124 -11
  207. package/dist/types/utilities/schemaRepository.d.ts +2 -2
  208. package/package.json +4 -4
  209. package/src/fieldTypes/boolean.ts +5 -3
  210. package/src/fieldTypes/color.ts +5 -3
  211. package/src/fieldTypes/date.ts +5 -4
  212. package/src/fieldTypes/date_time.ts +5 -3
  213. package/src/fieldTypes/file.ts +98 -4
  214. package/src/fieldTypes/float.ts +5 -3
  215. package/src/fieldTypes/gallery.ts +53 -20
  216. package/src/fieldTypes/index.ts +2 -3
  217. package/src/fieldTypes/integer.ts +5 -3
  218. package/src/fieldTypes/json.ts +5 -4
  219. package/src/fieldTypes/lat_lon.ts +5 -3
  220. package/src/fieldTypes/link.ts +7 -5
  221. package/src/fieldTypes/links.ts +8 -4
  222. package/src/fieldTypes/rich_text.ts +33 -31
  223. package/src/fieldTypes/schema.ts +657 -0
  224. package/src/fieldTypes/seo.ts +5 -4
  225. package/src/fieldTypes/single_block.ts +71 -46
  226. package/src/fieldTypes/slug.ts +5 -4
  227. package/src/fieldTypes/string.ts +5 -3
  228. package/src/fieldTypes/structured_text.ts +64 -58
  229. package/src/fieldTypes/text.ts +5 -4
  230. package/src/fieldTypes/video.ts +5 -3
  231. package/src/generated/ApiTypes.ts +217 -1880
  232. package/src/generated/Client.ts +1 -1
  233. package/src/generated/RawApiTypes.ts +272 -2113
  234. package/src/generated/resources/Item.ts +93 -187
  235. package/src/generated/resources/ScheduledPublication.ts +4 -15
  236. package/src/generated/resources/ScheduledUnpublishing.ts +4 -15
  237. package/src/generated/resources/Upload.ts +9 -32
  238. package/src/index.ts +5 -4
  239. package/src/utilities/buildBlockRecord.ts +4 -59
  240. package/src/utilities/duplicateBlockRecord.ts +52 -0
  241. package/src/utilities/inspectItem.ts +602 -0
  242. package/src/utilities/itemDefinition.ts +130 -92
  243. package/src/utilities/nonRecursiveBlocks.ts +406 -0
  244. package/src/utilities/{fieldValue.ts → normalizedFieldValues.ts} +70 -30
  245. package/src/utilities/recursiveBlocks.ts +484 -204
  246. package/src/utilities/schemaRepository.ts +2 -2
  247. package/dist/cjs/utilities/blocks.js.map +0 -1
  248. package/dist/cjs/utilities/fieldValue.js.map +0 -1
  249. package/dist/esm/utilities/blocks.d.ts +0 -180
  250. package/dist/esm/utilities/blocks.js.map +0 -1
  251. package/dist/esm/utilities/fieldValue.js.map +0 -1
  252. package/dist/types/utilities/blocks.d.ts +0 -180
  253. package/src/utilities/blocks.ts +0 -626
@@ -18,6 +18,7 @@ export type LocalizedFieldValue<T = unknown, L extends string = string> = Partia
18
18
  * @returns true if the field is localized, false otherwise
19
19
  */
20
20
  export declare function isLocalized(field: RawApiTypes.Field | ApiTypes.Field): boolean;
21
+ export declare function isLocalizedFieldValue<T = unknown, L extends string = string>(value: unknown): value is LocalizedFieldValue<T, L>;
21
22
  /**
22
23
  * A normalized entry that represents a single value from either a localized or non-localized field.
23
24
  *
@@ -26,7 +27,7 @@ export declare function isLocalized(field: RawApiTypes.Field | ApiTypes.Field):
26
27
  *
27
28
  * This uniform structure allows the same processing logic to work with both field types.
28
29
  */
29
- export type FieldValueEntry<T = unknown, L extends string = string> = {
30
+ export type NormalizedFieldValueEntry<T = unknown, L extends string = string> = {
30
31
  locale: L | undefined;
31
32
  value: T;
32
33
  };
@@ -40,11 +41,11 @@ export type FieldValueEntry<T = unknown, L extends string = string> = {
40
41
  * @param value - The field value to convert (either a localized object or direct value)
41
42
  * @returns Array of entries where each entry contains a locale (string for localized, undefined for non-localized) and the corresponding value
42
43
  */
43
- export declare function fieldValueToEntries<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>): FieldValueEntry<T, L>[];
44
+ export declare function toNormalizedFieldValueEntries<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>): NormalizedFieldValueEntry<T, L>[];
44
45
  /**
45
46
  * Converts an array of possibly localized entries back into the appropriate field value format.
46
47
  *
47
- * This function is the inverse of `fieldValueToEntries`. It takes a uniform
48
+ * This function is the inverse of `toNormalizedFieldValueEntries`. It takes a uniform
48
49
  * array of entries and converts them back to either a localized object or a direct value,
49
50
  * depending on the field's localization setting.
50
51
  *
@@ -52,7 +53,7 @@ export declare function fieldValueToEntries<T = unknown, L extends string = stri
52
53
  * @param entries - Array of entries to convert back to field value format
53
54
  * @returns Either a localized object (for localized fields) or the direct value (for non-localized fields)
54
55
  */
55
- export declare function entriesToFieldValue<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, entries: FieldValueEntry<T, L>[]): T | LocalizedFieldValue<T, L>;
56
+ export declare function fromNormalizedFieldValueEntries<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, entries: NormalizedFieldValueEntry<T, L>[]): T | LocalizedFieldValue<T, L>;
56
57
  /**
57
58
  * Maps field values using a provided mapping function.
58
59
  * For localized fields, applies the mapping function to each locale value.
@@ -64,7 +65,7 @@ export declare function entriesToFieldValue<T = unknown, L extends string = stri
64
65
  * @param mapFn - The function to apply to each locale value or the direct value
65
66
  * @returns The mapped value with the same structure as the input
66
67
  */
67
- export declare function mapFieldValue<TInput = unknown, TOutput = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: TInput | LocalizedFieldValue<TInput, L>, mapFn: (locale: L | undefined, localeValue: TInput) => TOutput): TOutput | LocalizedFieldValue<TOutput, L>;
68
+ export declare function mapNormalizedFieldValues<TInput = unknown, TOutput = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: TInput | LocalizedFieldValue<TInput, L>, mapFn: (locale: L | undefined, localeValue: TInput) => TOutput): TOutput | LocalizedFieldValue<TOutput, L>;
68
69
  /**
69
70
  * Maps field values using a provided mapping function (async version).
70
71
  * For localized fields, applies the mapping function to each locale value.
@@ -76,7 +77,7 @@ export declare function mapFieldValue<TInput = unknown, TOutput = unknown, L ext
76
77
  * @param mapFn - The function to apply to each locale value or the direct value
77
78
  * @returns The mapped value with the same structure as the input
78
79
  */
79
- export declare function mapFieldValueAsync<TInput = unknown, TOutput = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: TInput | LocalizedFieldValue<TInput, L>, mapFn: (locale: L | undefined, localeValue: TInput) => Promise<TOutput>): Promise<TOutput | LocalizedFieldValue<TOutput, L>>;
80
+ export declare function mapNormalizedFieldValuesAsync<TInput = unknown, TOutput = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: TInput | LocalizedFieldValue<TInput, L>, mapFn: (locale: L | undefined, localeValue: TInput) => Promise<TOutput>): Promise<TOutput | LocalizedFieldValue<TOutput, L>>;
80
81
  /**
81
82
  * Filters field values using a provided filter function.
82
83
  * For localized fields, filters each locale value.
@@ -87,7 +88,7 @@ export declare function mapFieldValueAsync<TInput = unknown, TOutput = unknown,
87
88
  * @param filterFn - The function to test each locale value or the direct value
88
89
  * @returns The filtered value with the same structure as the input
89
90
  */
90
- export declare function filterFieldValue<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, filterFn: (locale: L | undefined, localeValue: T) => boolean): T | LocalizedFieldValue<T, L> | undefined;
91
+ export declare function filterNormalizedFieldValues<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, filterFn: (locale: L | undefined, localeValue: T) => boolean): T | LocalizedFieldValue<T, L> | undefined;
91
92
  /**
92
93
  * Filters field values using a provided filter function (async version).
93
94
  * For localized fields, filters each locale value.
@@ -98,7 +99,7 @@ export declare function filterFieldValue<T = unknown, L extends string = string>
98
99
  * @param filterFn - The function to test each locale value or the direct value
99
100
  * @returns The filtered value with the same structure as the input
100
101
  */
101
- export declare function filterFieldValueAsync<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, filterFn: (locale: L | undefined, localeValue: T) => Promise<boolean>): Promise<T | LocalizedFieldValue<T, L> | undefined>;
102
+ export declare function filterNormalizedFieldValuesAsync<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, filterFn: (locale: L | undefined, localeValue: T) => Promise<boolean>): Promise<T | LocalizedFieldValue<T, L> | undefined>;
102
103
  /**
103
104
  * Tests whether at least one field value passes the test implemented by the provided function.
104
105
  * For localized fields, tests each locale value.
@@ -109,7 +110,7 @@ export declare function filterFieldValueAsync<T = unknown, L extends string = st
109
110
  * @param testFn - The function to test each locale value or the direct value
110
111
  * @returns true if at least one value passes the test, false otherwise
111
112
  */
112
- export declare function someFieldValue<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, testFn: (locale: L | undefined, localeValue: T) => boolean): boolean;
113
+ export declare function someNormalizedFieldValues<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, testFn: (locale: L | undefined, localeValue: T) => boolean): boolean;
113
114
  /**
114
115
  * Tests whether at least one field value passes the test implemented by the provided function (async version).
115
116
  * For localized fields, tests each locale value.
@@ -120,7 +121,7 @@ export declare function someFieldValue<T = unknown, L extends string = string>(f
120
121
  * @param testFn - The function to test each locale value or the direct value
121
122
  * @returns true if at least one value passes the test, false otherwise
122
123
  */
123
- export declare function someFieldValueAsync<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, testFn: (locale: L | undefined, localeValue: T) => Promise<boolean>): Promise<boolean>;
124
+ export declare function someNormalizedFieldValuesAsync<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, testFn: (locale: L | undefined, localeValue: T) => Promise<boolean>): Promise<boolean>;
124
125
  /**
125
126
  * Tests whether all field values pass the test implemented by the provided function.
126
127
  * For localized fields, tests each locale value.
@@ -131,7 +132,7 @@ export declare function someFieldValueAsync<T = unknown, L extends string = stri
131
132
  * @param testFn - The function to test each locale value or the direct value
132
133
  * @returns true if all values pass the test, false otherwise
133
134
  */
134
- export declare function everyFieldValue<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, testFn: (locale: L | undefined, localeValue: T) => boolean): boolean;
135
+ export declare function everyNormalizedFieldValue<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, testFn: (locale: L | undefined, localeValue: T) => boolean): boolean;
135
136
  /**
136
137
  * Tests whether all field values pass the test implemented by the provided function (async version).
137
138
  * For localized fields, tests each locale value.
@@ -142,7 +143,7 @@ export declare function everyFieldValue<T = unknown, L extends string = string>(
142
143
  * @param testFn - The function to test each locale value or the direct value
143
144
  * @returns true if all values pass the test, false otherwise
144
145
  */
145
- export declare function everyFieldValueAsync<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, testFn: (locale: L | undefined, localeValue: T) => Promise<boolean>): Promise<boolean>;
146
+ export declare function everyNormalizedFieldValueAsync<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, testFn: (locale: L | undefined, localeValue: T) => Promise<boolean>): Promise<boolean>;
146
147
  /**
147
148
  * Visits each field value with the provided function.
148
149
  * For localized fields, visits each locale value.
@@ -152,7 +153,7 @@ export declare function everyFieldValueAsync<T = unknown, L extends string = str
152
153
  * @param value - The field value (either localized object or direct value)
153
154
  * @param visitFn - The function to call for each locale value or the direct value
154
155
  */
155
- export declare function visitFieldValue<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, visitFn: (locale: L | undefined, localeValue: T) => void): void;
156
+ export declare function visitNormalizedFieldValues<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, visitFn: (locale: L | undefined, localeValue: T) => void): void;
156
157
  /**
157
158
  * Visits each field value with the provided function (async version).
158
159
  * For localized fields, visits each locale value.
@@ -162,4 +163,4 @@ export declare function visitFieldValue<T = unknown, L extends string = string>(
162
163
  * @param value - The field value (either localized object or direct value)
163
164
  * @param visitFn - The function to call for each locale value or the direct value
164
165
  */
165
- export declare function visitFieldValueAsync<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, visitFn: (locale: L | undefined, localeValue: T) => Promise<void>): Promise<void>;
166
+ export declare function visitNormalizedFieldValuesAsync<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, visitFn: (locale: L | undefined, localeValue: T) => Promise<void>): Promise<void>;
@@ -1,18 +1,131 @@
1
- import { type BlockItemInARequest } from '../fieldTypes';
1
+ import { type BlockInRequest, type RichTextFieldValue, type RichTextFieldValueInNestedResponse, type RichTextFieldValueInRequest, type SingleBlockFieldValue, type SingleBlockFieldValueInNestedResponse, type SingleBlockFieldValueInRequest, type StructuredTextFieldValue, type StructuredTextFieldValueInNestedResponse, type StructuredTextFieldValueInRequest } from '../fieldTypes';
2
2
  import type * as ApiTypes from '../generated/ApiTypes';
3
- import type * as RawApiTypes from '../generated/RawApiTypes';
3
+ import type { ExtractNestedBlocksFromFieldValue } from './itemDefinition';
4
4
  import type { SchemaRepository } from './schemaRepository';
5
+ type RecognizableFieldValue = RichTextFieldValueInNestedResponse | SingleBlockFieldValueInNestedResponse | StructuredTextFieldValueInNestedResponse | RichTextFieldValueInRequest | SingleBlockFieldValueInRequest | StructuredTextFieldValueInRequest | RichTextFieldValue | SingleBlockFieldValue | StructuredTextFieldValue;
5
6
  /**
6
- * Path through a field value (ie. ['content', 0, 'attributes', 'title'])
7
+ * Path through a non-localized field value (ie. ['content', 0, 'attributes', 'title'])
7
8
  */
8
9
  export type TreePath = readonly (string | number)[];
9
- export declare function visitBlocksInFieldValues(schemaRepository: SchemaRepository, field: RawApiTypes.Field | ApiTypes.Field, value: unknown, visitor: (item: BlockItemInARequest, path: TreePath) => void | Promise<void>, path?: TreePath): Promise<void>;
10
- export declare function findAllBlocksInFieldValues(schemaRepository: SchemaRepository, field: RawApiTypes.Field | ApiTypes.Field, value: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<Array<{
11
- item: BlockItemInARequest;
10
+ /**
11
+ * Traversal direction for recursive operations
12
+ */
13
+ export type TraversalDirection = 'top-down' | 'bottom-up';
14
+ /**
15
+ * Recursively visit every block in a non-localized field value and all nested blocks within those blocks.
16
+ * This function traverses not only the direct blocks in the non-localized field value but also recursively
17
+ * visits blocks contained within the attributes of each block, creating a complete traversal
18
+ * of the entire block hierarchy.
19
+ *
20
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to visit
21
+ * @param fieldType - The type field (determines how the value is processed)
22
+ * @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
23
+ * @param visitor - Asynchronous function called for each block found, including nested blocks
24
+ * @returns Promise that resolves when all blocks and nested blocks have been visited
25
+ */
26
+ export declare function visitBlocksInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, visitor: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => void | Promise<void>, path?: TreePath): Promise<void>;
27
+ export declare function visitBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, visitor: (item: BlockInRequest, path: TreePath) => void | Promise<void>, path?: TreePath): Promise<void>;
28
+ /**
29
+ * Recursively find all blocks that match the predicate function in a non-localized field value.
30
+ * Searches through all direct blocks and recursively through nested blocks within
31
+ * the attributes of each block, returning all matches found throughout the hierarchy.
32
+ *
33
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to search
34
+ * @param fieldType - The type field (determines how the value is processed)
35
+ * @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
36
+ * @param predicate - Asynchronous function that tests each block, including nested ones
37
+ * @returns Promise that resolves to an array of objects, each containing a matching block and its full path
38
+ */
39
+ export declare function findAllBlocksInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<Array<{
40
+ item: ExtractNestedBlocksFromFieldValue<T>;
41
+ path: TreePath;
42
+ }>>;
43
+ export declare function findAllBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: BlockInRequest, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<Array<{
44
+ item: BlockInRequest;
12
45
  path: TreePath;
13
46
  }>>;
14
- export declare function filterBlocksInFieldValues(schemaRepository: SchemaRepository, field: RawApiTypes.Field | ApiTypes.Field, value: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<unknown>;
15
- export declare function reduceBlocksInFieldValues<R>(schemaRepository: SchemaRepository, field: RawApiTypes.Field | ApiTypes.Field, value: unknown, reducer: (accumulator: R, item: BlockItemInARequest, path: TreePath) => R | Promise<R>, initialValue: R, path?: TreePath): Promise<R>;
16
- export declare function someBlocksInFieldValues(schemaRepository: SchemaRepository, field: RawApiTypes.Field | ApiTypes.Field, value: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<boolean>;
17
- export declare function everyBlockInFieldValues(schemaRepository: SchemaRepository, field: RawApiTypes.Field | ApiTypes.Field, value: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<boolean>;
18
- export declare function mapBlocksInFieldValues(schemaRepository: SchemaRepository, field: RawApiTypes.Field | ApiTypes.Field, value: unknown, mapper: (item: BlockItemInARequest, path: TreePath) => BlockItemInARequest | Promise<BlockItemInARequest>, path?: TreePath): Promise<unknown>;
47
+ /**
48
+ * Recursively filter blocks in a non-localized field value, removing those that don't match the predicate.
49
+ * Creates a new non-localized field value structure containing only blocks that pass the predicate test,
50
+ * including recursive filtering of nested blocks within block attributes. The filtering
51
+ * preserves the original non-localized field value structure and hierarchy.
52
+ *
53
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to filter
54
+ * @param fieldType - The type field (determines how the value is processed)
55
+ * @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
56
+ * @param predicate - Asynchronous function that tests each block, including nested ones
57
+ * @param options - Optional configuration object
58
+ * @param options.traversalDirection - Direction of traversal: 'top-down' (default) applies predicate before processing children, 'bottom-up' processes children first
59
+ * @returns Promise that resolves to the new non-localized field value with recursively filtered blocks
60
+ */
61
+ export declare function filterBlocksInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => boolean | Promise<boolean>, options?: {
62
+ traversalDirection?: TraversalDirection;
63
+ }, path?: TreePath): Promise<T>;
64
+ export declare function filterBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: BlockInRequest, path: TreePath) => boolean | Promise<boolean>, options?: {
65
+ traversalDirection?: TraversalDirection;
66
+ }, path?: TreePath): Promise<unknown>;
67
+ /**
68
+ * Recursively reduce all blocks in a non-localized field value to a single value by applying a reducer function.
69
+ * Processes each direct block and recursively processes nested blocks within block attributes,
70
+ * accumulating results from the entire block hierarchy into a single value.
71
+ *
72
+ * @template R - The type of the accumulated result
73
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to reduce
74
+ * @param fieldType - The type field (determines how the value is processed)
75
+ * @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
76
+ * @param reducer - Asynchronous function that processes each block and updates the accumulator
77
+ * @param initialNonLocalizedFieldValue - The initial value for the accumulator
78
+ * @returns Promise that resolves to the final accumulated value from all blocks in the hierarchy
79
+ */
80
+ export declare function reduceBlocksInNonLocalizedFieldValue<T, R>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, reducer: (accumulator: R, item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => R | Promise<R>, initialValue: R, path?: TreePath): Promise<R>;
81
+ export declare function reduceBlocksInNonLocalizedFieldValue<R>(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, reducer: (accumulator: R, item: BlockInRequest, path: TreePath) => R | Promise<R>, initialValue: R, path?: TreePath): Promise<R>;
82
+ /**
83
+ * Recursively check if any block in the non-localized field value matches the predicate function.
84
+ * Tests both direct blocks and recursively tests nested blocks within block attributes.
85
+ * Returns true as soon as the first matching block is found anywhere in the hierarchy
86
+ * (short-circuit evaluation).
87
+ *
88
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
89
+ * @param fieldType - The type field (determines how the value is processed)
90
+ * @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
91
+ * @param predicate - Asynchronous function that tests each block, including nested ones
92
+ * @returns Promise that resolves to true if any block in the hierarchy matches, false otherwise
93
+ */
94
+ export declare function someBlocksInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<boolean>;
95
+ export declare function someBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: BlockInRequest, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<boolean>;
96
+ /**
97
+ * Recursively check if every block in the non-localized field value matches the predicate function.
98
+ * Tests both direct blocks and recursively tests nested blocks within block attributes.
99
+ * Returns false as soon as the first non-matching block is found anywhere in the hierarchy
100
+ * (short-circuit evaluation).
101
+ *
102
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
103
+ * @param fieldType - The type field (determines how the value is processed)
104
+ * @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
105
+ * @param predicate - Asynchronous function that tests each block, including nested ones
106
+ * @returns Promise that resolves to true if all blocks in the hierarchy match, false otherwise
107
+ */
108
+ export declare function everyBlockInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<boolean>;
109
+ export declare function everyBlockInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: BlockInRequest, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<boolean>;
110
+ type FieldValueInRequest<T> = T extends RichTextFieldValueInNestedResponse<infer D> ? RichTextFieldValueInRequest<D> : T extends SingleBlockFieldValueInNestedResponse<infer D> ? SingleBlockFieldValueInRequest<D> : T extends StructuredTextFieldValueInNestedResponse<infer DB, infer DI> ? StructuredTextFieldValueInRequest<DB, DI> : T extends StructuredTextFieldValueInNestedResponse<infer DB> ? StructuredTextFieldValueInRequest<DB> : T;
111
+ /**
112
+ * Recursively transform blocks in a non-localized field value by applying a mapping function to each block.
113
+ * Creates a new non-localized field value structure with transformed blocks while preserving the original
114
+ * structure. Applies the mapping function to both direct blocks and recursively to nested
115
+ * blocks within block attributes throughout the entire hierarchy.
116
+ *
117
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to transform
118
+ * @param fieldType - The type field (determines how the value is processed)
119
+ * @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
120
+ * @param mapper - Asynchronous function that transforms each block, including nested ones
121
+ * @param options - Optional configuration object
122
+ * @param options.traversalDirection - Direction of traversal: 'top-down' (default) applies mapper before processing children, 'bottom-up' processes children first
123
+ * @returns Promise that resolves to the new non-localized field value with recursively transformed blocks
124
+ */
125
+ export declare function mapBlocksInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, mapper: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => BlockInRequest | Promise<BlockInRequest>, options?: {
126
+ traversalDirection?: TraversalDirection;
127
+ }, path?: TreePath): Promise<FieldValueInRequest<T>>;
128
+ export declare function mapBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, mapper: (item: BlockInRequest, path: TreePath) => BlockInRequest | Promise<BlockInRequest>, options?: {
129
+ traversalDirection?: TraversalDirection;
130
+ }, path?: TreePath): Promise<unknown>;
131
+ export {};
@@ -41,7 +41,7 @@ interface GenericClient {
41
41
  * - **Caching schema entities**: Automatically caches item types, fields, fieldsets,
42
42
  * and plugins after the first API request, returning cached results on subsequent calls
43
43
  * - **Complex traversal operations**: Essential when using utilities like
44
- * `mapBlocksInFieldValues()` that need to repeatedly lookup block models and fields
44
+ * `mapBlocksInNonLocalizedFieldValue()` that need to repeatedly lookup block models and fields
45
45
  * while traversing nested content structures
46
46
  * - **Bulk operations**: Ideal for scripts that process multiple records of different
47
47
  * types and need efficient access to schema information
@@ -73,7 +73,7 @@ interface GenericClient {
73
73
  * const sameBlogPost = await schemaRepository.getItemTypeByApiKey('blog_post');
74
74
  *
75
75
  * // Pass the repository to utilities that need schema information
76
- * await mapBlocksInFieldValues(schemaRepository, record, (block) => {
76
+ * await mapBlocksInNonLocalizedFieldValue(schemaRepository, record, (block) => {
77
77
  * // The utility will use the cached schema data internally
78
78
  * });
79
79
  * ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datocms/cma-client",
3
- "version": "5.1.10",
3
+ "version": "5.1.12",
4
4
  "description": "JS client for DatoCMS REST Content Management API",
5
5
  "keywords": [
6
6
  "datocms",
@@ -38,12 +38,12 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@datocms/rest-client-utils": "^5.1.6",
41
- "datocms-structured-text-utils": "^5.1.2",
41
+ "datocms-structured-text-utils": "^5.1.4",
42
42
  "uuid": "^9.0.1"
43
43
  },
44
44
  "devDependencies": {
45
- "@datocms/dashboard-client": "^5.1.10",
45
+ "@datocms/dashboard-client": "^5.1.12",
46
46
  "@types/uuid": "^9.0.7"
47
47
  },
48
- "gitHead": "3f5298b6aa1592b9425d92bd2e4ca0ad052a0bf0"
48
+ "gitHead": "20ef29ad11049203a14461a9565e0f7833593867"
49
49
  }
@@ -1,4 +1,7 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import {
2
+ type LocalizedFieldValue,
3
+ isLocalizedFieldValue,
4
+ } from '../utilities/normalizedFieldValues';
2
5
  import type { BooleanEditorConfiguration } from './appearance/boolean';
3
6
  import type { BooleanRadioGroupEditorConfiguration } from './appearance/boolean_radio_group';
4
7
 
@@ -14,8 +17,7 @@ export function isLocalizedBooleanFieldValue(
14
17
  value: unknown,
15
18
  ): value is LocalizedFieldValue<BooleanFieldValue> {
16
19
  return (
17
- typeof value === 'object' &&
18
- value !== null &&
20
+ isLocalizedFieldValue(value) &&
19
21
  Object.values(value).every(isBooleanFieldValue)
20
22
  );
21
23
  }
@@ -1,4 +1,7 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import {
2
+ type LocalizedFieldValue,
3
+ isLocalizedFieldValue,
4
+ } from '../utilities/normalizedFieldValues';
2
5
  import type { ColorPickerEditorConfiguration } from './appearance/color_picker';
3
6
  import type { RequiredValidator } from './validators/required';
4
7
 
@@ -25,8 +28,7 @@ export function isLocalizedColorFieldValue(
25
28
  value: unknown,
26
29
  ): value is LocalizedFieldValue<ColorFieldValue> {
27
30
  return (
28
- typeof value === 'object' &&
29
- value !== null &&
31
+ isLocalizedFieldValue(value) &&
30
32
  Object.values(value).every(isColorFieldValue)
31
33
  );
32
34
  }
@@ -1,4 +1,7 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import {
2
+ type LocalizedFieldValue,
3
+ isLocalizedFieldValue,
4
+ } from '../utilities/normalizedFieldValues';
2
5
  import type { DatePickerEditorConfiguration } from './appearance/date_picker';
3
6
  import type { DateRangeValidator } from './validators/date_range';
4
7
  import type { RequiredValidator } from './validators/required';
@@ -14,9 +17,7 @@ export function isLocalizedDateFieldValue(
14
17
  value: unknown,
15
18
  ): value is LocalizedFieldValue<DateFieldValue> {
16
19
  return (
17
- typeof value === 'object' &&
18
- value !== null &&
19
- Object.values(value).every(isDateFieldValue)
20
+ isLocalizedFieldValue(value) && Object.values(value).every(isDateFieldValue)
20
21
  );
21
22
  }
22
23
 
@@ -1,4 +1,7 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import {
2
+ type LocalizedFieldValue,
3
+ isLocalizedFieldValue,
4
+ } from '../utilities/normalizedFieldValues';
2
5
  import type { DateTimePickerEditorConfiguration } from './appearance/date_time_picker';
3
6
  import type { DateTimeRangeValidator } from './validators/date_time_range';
4
7
  import type { RequiredValidator } from './validators/required';
@@ -19,8 +22,7 @@ export function isLocalizedDateTimeFieldValue(
19
22
  value: unknown,
20
23
  ): value is LocalizedFieldValue<DateTimeFieldValue> {
21
24
  return (
22
- typeof value === 'object' &&
23
- value !== null &&
25
+ isLocalizedFieldValue(value) &&
24
26
  Object.values(value).every(isDateTimeFieldValue)
25
27
  );
26
28
  }
@@ -1,4 +1,7 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import {
2
+ type LocalizedFieldValue,
3
+ isLocalizedFieldValue,
4
+ } from '../utilities/normalizedFieldValues';
2
5
  import type { FileEditorConfiguration } from './appearance/file';
3
6
  import type { ExtensionValidator } from './validators/extension';
4
7
  import type { FileSizeValidator } from './validators/file_size';
@@ -7,7 +10,63 @@ import type { ImageDimensionsValidator } from './validators/image_dimensions';
7
10
  import type { RequiredValidator } from './validators/required';
8
11
  import type { RequiredAltTitleValidator } from './validators/required_alt_title';
9
12
 
13
+ /**
14
+ * FILE FIELD TYPE SYSTEM FOR DATOCMS
15
+ *
16
+ * This module defines a comprehensive type system for handling DatoCMS File fields,
17
+ * which contain file uploads with optional metadata like alt text, title, custom data, and focal points.
18
+ *
19
+ * The challenge we're solving:
20
+ * - DatoCMS File fields can have optional metadata fields (alt, title, custom_data, focal_point)
21
+ * - For API requests, all these fields are optional and can be omitted
22
+ * - For API responses, DatoCMS provides default values for missing fields:
23
+ * - alt: null
24
+ * - title: null
25
+ * - custom_data: {}
26
+ * - focal_point: null
27
+ * - This creates a need for different type variants for the same conceptual data structure
28
+ *
29
+ * This module provides separate types for:
30
+ * 1. API request format (optional metadata fields)
31
+ * 2. API response format (all fields present with defaults)
32
+ */
33
+
34
+ /**
35
+ * =============================================================================
36
+ * BASIC FILE TYPE - Default API response format
37
+ * =============================================================================
38
+ *
39
+ * The standard File field value with all metadata fields present and default values applied.
40
+ * This is what you get from API responses where DatoCMS has applied default values.
41
+ */
42
+
43
+ /**
44
+ * Basic File field value - all metadata fields present with defaults applied
45
+ */
10
46
  export type FileFieldValue = {
47
+ upload_id: string;
48
+ alt: string | null;
49
+ title: string | null;
50
+ custom_data: Record<string, unknown>;
51
+ focal_point: {
52
+ x: number;
53
+ y: number;
54
+ } | null;
55
+ } | null;
56
+
57
+ /**
58
+ * =============================================================================
59
+ * REQUEST VARIANT - Type for sending data TO the DatoCMS API
60
+ * =============================================================================
61
+ *
62
+ * When making API requests, metadata fields are optional and can be omitted.
63
+ * DatoCMS will apply default values for any missing fields in the response.
64
+ */
65
+
66
+ /**
67
+ * File field value for API requests - metadata fields are optional
68
+ */
69
+ export type FileFieldValueInRequest = {
11
70
  upload_id: string;
12
71
  alt?: string | null;
13
72
  title?: string | null;
@@ -18,7 +77,35 @@ export type FileFieldValue = {
18
77
  } | null;
19
78
  } | null;
20
79
 
80
+ /**
81
+ * =============================================================================
82
+ * TYPE GUARDS - Runtime validation functions
83
+ * =============================================================================
84
+ */
85
+
86
+ /**
87
+ * Type guard for basic File field values (response format with all fields present).
88
+ * Validates that all required metadata fields are present.
89
+ */
21
90
  export function isFileFieldValue(value: unknown): value is FileFieldValue {
91
+ if (value === null) return true;
92
+ return (
93
+ isLocalizedFieldValue(value) &&
94
+ 'upload_id' in value &&
95
+ 'alt' in value &&
96
+ 'title' in value &&
97
+ 'custom_data' in value &&
98
+ 'focal_point' in value
99
+ );
100
+ }
101
+
102
+ /**
103
+ * Type guard for File field values in API request format.
104
+ * Allows metadata fields to be optional or omitted.
105
+ */
106
+ export function isFileFieldValueInRequest(
107
+ value: unknown,
108
+ ): value is FileFieldValueInRequest {
22
109
  if (value === null) return true;
23
110
  return typeof value === 'object' && value !== null && 'upload_id' in value;
24
111
  }
@@ -27,9 +114,16 @@ export function isLocalizedFileFieldValue(
27
114
  value: unknown,
28
115
  ): value is LocalizedFieldValue<FileFieldValue> {
29
116
  return (
30
- typeof value === 'object' &&
31
- value !== null &&
32
- Object.values(value).every(isFileFieldValue)
117
+ isLocalizedFieldValue(value) && Object.values(value).every(isFileFieldValue)
118
+ );
119
+ }
120
+
121
+ export function isLocalizedFileFieldValueInRequest(
122
+ value: unknown,
123
+ ): value is LocalizedFieldValue<FileFieldValueInRequest> {
124
+ return (
125
+ isLocalizedFieldValue(value) &&
126
+ Object.values(value).every(isFileFieldValueInRequest)
33
127
  );
34
128
  }
35
129
 
@@ -1,4 +1,7 @@
1
- import type { LocalizedFieldValue } from '../utilities/fieldValue';
1
+ import {
2
+ type LocalizedFieldValue,
3
+ isLocalizedFieldValue,
4
+ } from '../utilities/normalizedFieldValues';
2
5
  import type { FloatEditorConfiguration } from './appearance/float';
3
6
  import type { NumberRangeValidator } from './validators/number_range';
4
7
  import type { RequiredValidator } from './validators/required';
@@ -13,8 +16,7 @@ export function isLocalizedFloatFieldValue(
13
16
  value: unknown,
14
17
  ): value is LocalizedFieldValue<FloatFieldValue> {
15
18
  return (
16
- typeof value === 'object' &&
17
- value !== null &&
19
+ isLocalizedFieldValue(value) &&
18
20
  Object.values(value).every(isFloatFieldValue)
19
21
  );
20
22
  }