@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>;
@@ -19,6 +19,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
19
  export function isLocalized(field) {
20
20
  return 'attributes' in field ? field.attributes.localized : field.localized;
21
21
  }
22
+ export function isLocalizedFieldValue(value) {
23
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
24
+ return false;
25
+ }
26
+ const keys = Object.keys(value);
27
+ if (keys.length === 0) {
28
+ return false;
29
+ }
30
+ const localePattern = /^[A-Za-z]{2,4}(-[A-Za-z]{4})?(-([A-Za-z]{2}|[0-9]{3}))?$/;
31
+ return keys.every((key) => localePattern.test(key));
32
+ }
22
33
  /**
23
34
  * Converts a field value (localized or non-localized) into a uniform array of entries.
24
35
  *
@@ -29,7 +40,7 @@ export function isLocalized(field) {
29
40
  * @param value - The field value to convert (either a localized object or direct value)
30
41
  * @returns Array of entries where each entry contains a locale (string for localized, undefined for non-localized) and the corresponding value
31
42
  */
32
- export function fieldValueToEntries(field, value) {
43
+ export function toNormalizedFieldValueEntries(field, value) {
33
44
  if (isLocalized(field)) {
34
45
  const localizedValue = value;
35
46
  return Object.entries(localizedValue).map(([locale, value]) => ({
@@ -42,7 +53,7 @@ export function fieldValueToEntries(field, value) {
42
53
  /**
43
54
  * Converts an array of possibly localized entries back into the appropriate field value format.
44
55
  *
45
- * This function is the inverse of `fieldValueToEntries`. It takes a uniform
56
+ * This function is the inverse of `toNormalizedFieldValueEntries`. It takes a uniform
46
57
  * array of entries and converts them back to either a localized object or a direct value,
47
58
  * depending on the field's localization setting.
48
59
  *
@@ -50,7 +61,7 @@ export function fieldValueToEntries(field, value) {
50
61
  * @param entries - Array of entries to convert back to field value format
51
62
  * @returns Either a localized object (for localized fields) or the direct value (for non-localized fields)
52
63
  */
53
- export function entriesToFieldValue(field, entries) {
64
+ export function fromNormalizedFieldValueEntries(field, entries) {
54
65
  if (isLocalized(field)) {
55
66
  return Object.fromEntries(entries.map(({ locale, value }) => [locale, value]));
56
67
  }
@@ -70,13 +81,13 @@ export function entriesToFieldValue(field, entries) {
70
81
  * @param mapFn - The function to apply to each locale value or the direct value
71
82
  * @returns The mapped value with the same structure as the input
72
83
  */
73
- export function mapFieldValue(field, value, mapFn) {
74
- const entries = fieldValueToEntries(field, value);
84
+ export function mapNormalizedFieldValues(field, value, mapFn) {
85
+ const entries = toNormalizedFieldValueEntries(field, value);
75
86
  const mappedEntries = entries.map(({ locale, value }) => ({
76
87
  locale,
77
88
  value: mapFn(locale, value),
78
89
  }));
79
- return entriesToFieldValue(field, mappedEntries);
90
+ return fromNormalizedFieldValueEntries(field, mappedEntries);
80
91
  }
81
92
  /**
82
93
  * Maps field values using a provided mapping function (async version).
@@ -89,16 +100,16 @@ export function mapFieldValue(field, value, mapFn) {
89
100
  * @param mapFn - The function to apply to each locale value or the direct value
90
101
  * @returns The mapped value with the same structure as the input
91
102
  */
92
- export function mapFieldValueAsync(field, value, mapFn) {
103
+ export function mapNormalizedFieldValuesAsync(field, value, mapFn) {
93
104
  return __awaiter(this, void 0, void 0, function* () {
94
- const entries = fieldValueToEntries(field, value);
105
+ const entries = toNormalizedFieldValueEntries(field, value);
95
106
  const mappedEntries = yield Promise.all(entries.map(({ locale, value }) => __awaiter(this, void 0, void 0, function* () {
96
107
  return ({
97
108
  locale,
98
109
  value: yield mapFn(locale, value),
99
110
  });
100
111
  })));
101
- return entriesToFieldValue(field, mappedEntries);
112
+ return fromNormalizedFieldValueEntries(field, mappedEntries);
102
113
  });
103
114
  }
104
115
  /**
@@ -111,12 +122,12 @@ export function mapFieldValueAsync(field, value, mapFn) {
111
122
  * @param filterFn - The function to test each locale value or the direct value
112
123
  * @returns The filtered value with the same structure as the input
113
124
  */
114
- export function filterFieldValue(field, value, filterFn) {
125
+ export function filterNormalizedFieldValues(field, value, filterFn) {
115
126
  var _a;
116
- const entries = fieldValueToEntries(field, value);
127
+ const entries = toNormalizedFieldValueEntries(field, value);
117
128
  const filteredEntries = entries.filter((entry) => filterFn(entry.locale, entry.value));
118
129
  if (isLocalized(field)) {
119
- return entriesToFieldValue(field, filteredEntries);
130
+ return fromNormalizedFieldValueEntries(field, filteredEntries);
120
131
  }
121
132
  return filteredEntries.length > 0 ? (_a = filteredEntries[0]) === null || _a === void 0 ? void 0 : _a.value : undefined;
122
133
  }
@@ -130,10 +141,10 @@ export function filterFieldValue(field, value, filterFn) {
130
141
  * @param filterFn - The function to test each locale value or the direct value
131
142
  * @returns The filtered value with the same structure as the input
132
143
  */
133
- export function filterFieldValueAsync(field, value, filterFn) {
144
+ export function filterNormalizedFieldValuesAsync(field, value, filterFn) {
134
145
  var _a;
135
146
  return __awaiter(this, void 0, void 0, function* () {
136
- const entries = fieldValueToEntries(field, value);
147
+ const entries = toNormalizedFieldValueEntries(field, value);
137
148
  const results = yield Promise.all(entries.map(({ locale, value }) => __awaiter(this, void 0, void 0, function* () {
138
149
  return ({
139
150
  locale,
@@ -145,7 +156,7 @@ export function filterFieldValueAsync(field, value, filterFn) {
145
156
  .filter(({ passed }) => passed)
146
157
  .map(({ locale, value }) => ({ locale, value }));
147
158
  if (isLocalized(field)) {
148
- return entriesToFieldValue(field, filteredEntries);
159
+ return fromNormalizedFieldValueEntries(field, filteredEntries);
149
160
  }
150
161
  return filteredEntries.length > 0 ? (_a = filteredEntries[0]) === null || _a === void 0 ? void 0 : _a.value : undefined;
151
162
  });
@@ -160,8 +171,8 @@ export function filterFieldValueAsync(field, value, filterFn) {
160
171
  * @param testFn - The function to test each locale value or the direct value
161
172
  * @returns true if at least one value passes the test, false otherwise
162
173
  */
163
- export function someFieldValue(field, value, testFn) {
164
- const entries = fieldValueToEntries(field, value);
174
+ export function someNormalizedFieldValues(field, value, testFn) {
175
+ const entries = toNormalizedFieldValueEntries(field, value);
165
176
  return entries.some(({ locale, value }) => testFn(locale, value));
166
177
  }
167
178
  /**
@@ -174,9 +185,9 @@ export function someFieldValue(field, value, testFn) {
174
185
  * @param testFn - The function to test each locale value or the direct value
175
186
  * @returns true if at least one value passes the test, false otherwise
176
187
  */
177
- export function someFieldValueAsync(field, value, testFn) {
188
+ export function someNormalizedFieldValuesAsync(field, value, testFn) {
178
189
  return __awaiter(this, void 0, void 0, function* () {
179
- const entries = fieldValueToEntries(field, value);
190
+ const entries = toNormalizedFieldValueEntries(field, value);
180
191
  const results = yield Promise.all(entries.map(({ locale, value }) => testFn(locale, value)));
181
192
  return results.some((result) => result);
182
193
  });
@@ -191,8 +202,8 @@ export function someFieldValueAsync(field, value, testFn) {
191
202
  * @param testFn - The function to test each locale value or the direct value
192
203
  * @returns true if all values pass the test, false otherwise
193
204
  */
194
- export function everyFieldValue(field, value, testFn) {
195
- return !someFieldValue(field, value, (locale, localeValue) => !testFn(locale, localeValue));
205
+ export function everyNormalizedFieldValue(field, value, testFn) {
206
+ return !someNormalizedFieldValues(field, value, (locale, localeValue) => !testFn(locale, localeValue));
196
207
  }
197
208
  /**
198
209
  * Tests whether all field values pass the test implemented by the provided function (async version).
@@ -204,9 +215,9 @@ export function everyFieldValue(field, value, testFn) {
204
215
  * @param testFn - The function to test each locale value or the direct value
205
216
  * @returns true if all values pass the test, false otherwise
206
217
  */
207
- export function everyFieldValueAsync(field, value, testFn) {
218
+ export function everyNormalizedFieldValueAsync(field, value, testFn) {
208
219
  return __awaiter(this, void 0, void 0, function* () {
209
- return !(yield someFieldValueAsync(field, value, (locale, localeValue) => __awaiter(this, void 0, void 0, function* () { return !(yield testFn(locale, localeValue)); })));
220
+ return !(yield someNormalizedFieldValuesAsync(field, value, (locale, localeValue) => __awaiter(this, void 0, void 0, function* () { return !(yield testFn(locale, localeValue)); })));
210
221
  });
211
222
  }
212
223
  /**
@@ -218,8 +229,8 @@ export function everyFieldValueAsync(field, value, testFn) {
218
229
  * @param value - The field value (either localized object or direct value)
219
230
  * @param visitFn - The function to call for each locale value or the direct value
220
231
  */
221
- export function visitFieldValue(field, value, visitFn) {
222
- const entries = fieldValueToEntries(field, value);
232
+ export function visitNormalizedFieldValues(field, value, visitFn) {
233
+ const entries = toNormalizedFieldValueEntries(field, value);
223
234
  for (const { locale, value } of entries) {
224
235
  visitFn(locale, value);
225
236
  }
@@ -233,10 +244,10 @@ export function visitFieldValue(field, value, visitFn) {
233
244
  * @param value - The field value (either localized object or direct value)
234
245
  * @param visitFn - The function to call for each locale value or the direct value
235
246
  */
236
- export function visitFieldValueAsync(field, value, visitFn) {
247
+ export function visitNormalizedFieldValuesAsync(field, value, visitFn) {
237
248
  return __awaiter(this, void 0, void 0, function* () {
238
- const entries = fieldValueToEntries(field, value);
249
+ const entries = toNormalizedFieldValueEntries(field, value);
239
250
  yield Promise.all(entries.map(({ locale, value }) => visitFn(locale, value)));
240
251
  });
241
252
  }
242
- //# sourceMappingURL=fieldValue.js.map
253
+ //# sourceMappingURL=normalizedFieldValues.js.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,MAA0D;IAE1D,OAAO,CAAC,yBAAyB,CAC/B,KAAK,EACL,KAAK,EACL,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CACtD,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAgB,8BAA8B,CAIlD,KAAyC,EACzC,KAAoC,EACpC,MAAmE;;QAEnE,OAAO,CAAC,CAAC,MAAM,8BAA8B,CAC3C,KAAK,EACL,KAAK,EACL,CAAO,MAAM,EAAE,WAAW,EAAE,EAAE,gDAAC,OAAA,CAAC,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAA,GAAA,CACpE,CAAC,CAAC;IACL,CAAC;CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,0BAA0B,CAIxC,KAAyC,EACzC,KAAoC,EACpC,OAAwD;IAExD,MAAM,OAAO,GAAG,6BAA6B,CAAO,KAAK,EAAE,KAAK,CAAC,CAAC;IAClE,KAAK,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,OAAO,EAAE;QACvC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;KACxB;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAgB,+BAA+B,CAInD,KAAyC,EACzC,KAAoC,EACpC,OAAiE;;QAEjE,MAAM,OAAO,GAAG,6BAA6B,CAAO,KAAK,EAAE,KAAK,CAAC,CAAC;QAClE,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAChF,CAAC;CAAA"}
@@ -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 {};