@datocms/cma-client 5.1.9 → 5.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/README.md +575 -0
  2. package/dist/cjs/fieldTypes/boolean.js +2 -2
  3. package/dist/cjs/fieldTypes/boolean.js.map +1 -1
  4. package/dist/cjs/fieldTypes/color.js +2 -2
  5. package/dist/cjs/fieldTypes/color.js.map +1 -1
  6. package/dist/cjs/fieldTypes/date.js +2 -3
  7. package/dist/cjs/fieldTypes/date.js.map +1 -1
  8. package/dist/cjs/fieldTypes/date_time.js +2 -2
  9. package/dist/cjs/fieldTypes/date_time.js.map +1 -1
  10. package/dist/cjs/fieldTypes/file.js +33 -5
  11. package/dist/cjs/fieldTypes/file.js.map +1 -1
  12. package/dist/cjs/fieldTypes/float.js +2 -2
  13. package/dist/cjs/fieldTypes/float.js.map +1 -1
  14. package/dist/cjs/fieldTypes/gallery.js +20 -5
  15. package/dist/cjs/fieldTypes/gallery.js.map +1 -1
  16. package/dist/cjs/fieldTypes/index.js +2 -2
  17. package/dist/cjs/fieldTypes/index.js.map +1 -1
  18. package/dist/cjs/fieldTypes/integer.js +2 -2
  19. package/dist/cjs/fieldTypes/integer.js.map +1 -1
  20. package/dist/cjs/fieldTypes/json.js +2 -3
  21. package/dist/cjs/fieldTypes/json.js.map +1 -1
  22. package/dist/cjs/fieldTypes/lat_lon.js +2 -2
  23. package/dist/cjs/fieldTypes/lat_lon.js.map +1 -1
  24. package/dist/cjs/fieldTypes/link.js +4 -4
  25. package/dist/cjs/fieldTypes/link.js.map +1 -1
  26. package/dist/cjs/fieldTypes/links.js +5 -3
  27. package/dist/cjs/fieldTypes/links.js.map +1 -1
  28. package/dist/cjs/fieldTypes/rich_text.js +4 -6
  29. package/dist/cjs/fieldTypes/rich_text.js.map +1 -1
  30. package/dist/cjs/fieldTypes/seo.js +2 -3
  31. package/dist/cjs/fieldTypes/seo.js.map +1 -1
  32. package/dist/cjs/fieldTypes/single_block.js +7 -7
  33. package/dist/cjs/fieldTypes/single_block.js.map +1 -1
  34. package/dist/cjs/fieldTypes/slug.js +2 -3
  35. package/dist/cjs/fieldTypes/slug.js.map +1 -1
  36. package/dist/cjs/fieldTypes/string.js +2 -2
  37. package/dist/cjs/fieldTypes/string.js.map +1 -1
  38. package/dist/cjs/fieldTypes/structured_text.js +4 -6
  39. package/dist/cjs/fieldTypes/structured_text.js.map +1 -1
  40. package/dist/cjs/fieldTypes/text.js +2 -3
  41. package/dist/cjs/fieldTypes/text.js.map +1 -1
  42. package/dist/cjs/fieldTypes/video.js +2 -2
  43. package/dist/cjs/fieldTypes/video.js.map +1 -1
  44. package/dist/cjs/generated/Client.js +1 -1
  45. package/dist/cjs/generated/Client.js.map +1 -1
  46. package/dist/cjs/generated/resources/Item.js.map +1 -1
  47. package/dist/cjs/generated/resources/Upload.js.map +1 -1
  48. package/dist/cjs/index.js +4 -4
  49. package/dist/cjs/index.js.map +1 -1
  50. package/dist/cjs/utilities/buildBlockRecord.js +8 -7
  51. package/dist/cjs/utilities/buildBlockRecord.js.map +1 -1
  52. package/dist/cjs/utilities/inspectItem.js +397 -0
  53. package/dist/cjs/utilities/inspectItem.js.map +1 -0
  54. package/dist/cjs/utilities/{blocks.js → nonRecursiveBlocks.js} +106 -111
  55. package/dist/cjs/utilities/nonRecursiveBlocks.js.map +1 -0
  56. package/dist/cjs/utilities/{fieldValue.js → normalizedFieldValues.js} +53 -41
  57. package/dist/cjs/utilities/normalizedFieldValues.js.map +1 -0
  58. package/dist/cjs/utilities/recursiveBlocks.js +121 -80
  59. package/dist/cjs/utilities/recursiveBlocks.js.map +1 -1
  60. package/dist/cjs/utilities/schemaRepository.js +2 -2
  61. package/dist/esm/fieldTypes/boolean.d.ts +1 -1
  62. package/dist/esm/fieldTypes/boolean.js +2 -2
  63. package/dist/esm/fieldTypes/boolean.js.map +1 -1
  64. package/dist/esm/fieldTypes/color.d.ts +1 -1
  65. package/dist/esm/fieldTypes/color.js +2 -2
  66. package/dist/esm/fieldTypes/color.js.map +1 -1
  67. package/dist/esm/fieldTypes/date.d.ts +1 -1
  68. package/dist/esm/fieldTypes/date.js +2 -3
  69. package/dist/esm/fieldTypes/date.js.map +1 -1
  70. package/dist/esm/fieldTypes/date_time.d.ts +1 -1
  71. package/dist/esm/fieldTypes/date_time.js +2 -2
  72. package/dist/esm/fieldTypes/date_time.js.map +1 -1
  73. package/dist/esm/fieldTypes/file.d.ts +68 -1
  74. package/dist/esm/fieldTypes/file.js +29 -3
  75. package/dist/esm/fieldTypes/file.js.map +1 -1
  76. package/dist/esm/fieldTypes/float.d.ts +1 -1
  77. package/dist/esm/fieldTypes/float.js +2 -2
  78. package/dist/esm/fieldTypes/float.js.map +1 -1
  79. package/dist/esm/fieldTypes/gallery.d.ts +27 -11
  80. package/dist/esm/fieldTypes/gallery.js +17 -4
  81. package/dist/esm/fieldTypes/gallery.js.map +1 -1
  82. package/dist/esm/fieldTypes/index.d.ts +2 -2
  83. package/dist/esm/fieldTypes/index.js +2 -2
  84. package/dist/esm/fieldTypes/index.js.map +1 -1
  85. package/dist/esm/fieldTypes/integer.d.ts +1 -1
  86. package/dist/esm/fieldTypes/integer.js +2 -2
  87. package/dist/esm/fieldTypes/integer.js.map +1 -1
  88. package/dist/esm/fieldTypes/json.d.ts +1 -1
  89. package/dist/esm/fieldTypes/json.js +2 -3
  90. package/dist/esm/fieldTypes/json.js.map +1 -1
  91. package/dist/esm/fieldTypes/lat_lon.d.ts +1 -1
  92. package/dist/esm/fieldTypes/lat_lon.js +2 -2
  93. package/dist/esm/fieldTypes/lat_lon.js.map +1 -1
  94. package/dist/esm/fieldTypes/link.d.ts +1 -1
  95. package/dist/esm/fieldTypes/link.js +4 -4
  96. package/dist/esm/fieldTypes/link.js.map +1 -1
  97. package/dist/esm/fieldTypes/links.d.ts +1 -1
  98. package/dist/esm/fieldTypes/links.js +5 -3
  99. package/dist/esm/fieldTypes/links.js.map +1 -1
  100. package/dist/esm/fieldTypes/rich_text.d.ts +1 -1
  101. package/dist/esm/fieldTypes/rich_text.js +4 -6
  102. package/dist/esm/fieldTypes/rich_text.js.map +1 -1
  103. package/dist/esm/fieldTypes/seo.d.ts +1 -1
  104. package/dist/esm/fieldTypes/seo.js +2 -3
  105. package/dist/esm/fieldTypes/seo.js.map +1 -1
  106. package/dist/esm/fieldTypes/single_block.d.ts +3 -3
  107. package/dist/esm/fieldTypes/single_block.js +7 -7
  108. package/dist/esm/fieldTypes/single_block.js.map +1 -1
  109. package/dist/esm/fieldTypes/slug.d.ts +1 -1
  110. package/dist/esm/fieldTypes/slug.js +2 -3
  111. package/dist/esm/fieldTypes/slug.js.map +1 -1
  112. package/dist/esm/fieldTypes/string.d.ts +1 -1
  113. package/dist/esm/fieldTypes/string.js +2 -2
  114. package/dist/esm/fieldTypes/string.js.map +1 -1
  115. package/dist/esm/fieldTypes/structured_text.d.ts +1 -1
  116. package/dist/esm/fieldTypes/structured_text.js +4 -6
  117. package/dist/esm/fieldTypes/structured_text.js.map +1 -1
  118. package/dist/esm/fieldTypes/text.d.ts +1 -1
  119. package/dist/esm/fieldTypes/text.js +2 -3
  120. package/dist/esm/fieldTypes/text.js.map +1 -1
  121. package/dist/esm/fieldTypes/video.d.ts +1 -1
  122. package/dist/esm/fieldTypes/video.js +2 -2
  123. package/dist/esm/fieldTypes/video.js.map +1 -1
  124. package/dist/esm/generated/Client.js +1 -1
  125. package/dist/esm/generated/Client.js.map +1 -1
  126. package/dist/esm/generated/resources/Item.d.ts +46 -28
  127. package/dist/esm/generated/resources/Item.js.map +1 -1
  128. package/dist/esm/generated/resources/ScheduledPublication.d.ts +3 -3
  129. package/dist/esm/generated/resources/ScheduledUnpublishing.d.ts +3 -3
  130. package/dist/esm/generated/resources/Upload.d.ts +10 -4
  131. package/dist/esm/generated/resources/Upload.js.map +1 -1
  132. package/dist/esm/index.d.ts +4 -4
  133. package/dist/esm/index.js +4 -4
  134. package/dist/esm/index.js.map +1 -1
  135. package/dist/esm/utilities/buildBlockRecord.d.ts +3 -3
  136. package/dist/esm/utilities/buildBlockRecord.js +9 -8
  137. package/dist/esm/utilities/buildBlockRecord.js.map +1 -1
  138. package/dist/esm/utilities/inspectItem.d.ts +8 -0
  139. package/dist/esm/utilities/inspectItem.js +393 -0
  140. package/dist/esm/utilities/inspectItem.js.map +1 -0
  141. package/dist/esm/utilities/itemDefinition.d.ts +36 -12
  142. package/dist/esm/utilities/nonRecursiveBlocks.d.ts +179 -0
  143. package/dist/esm/utilities/{blocks.js → nonRecursiveBlocks.js} +91 -96
  144. package/dist/esm/utilities/nonRecursiveBlocks.js.map +1 -0
  145. package/dist/{types/utilities/fieldValue.d.ts → esm/utilities/normalizedFieldValues.d.ts} +15 -14
  146. package/dist/esm/utilities/{fieldValue.js → normalizedFieldValues.js} +39 -28
  147. package/dist/esm/utilities/normalizedFieldValues.js.map +1 -0
  148. package/dist/esm/utilities/recursiveBlocks.d.ts +92 -9
  149. package/dist/esm/utilities/recursiveBlocks.js +113 -72
  150. package/dist/esm/utilities/recursiveBlocks.js.map +1 -1
  151. package/dist/esm/utilities/schemaRepository.d.ts +2 -2
  152. package/dist/esm/utilities/schemaRepository.js +2 -2
  153. package/dist/types/fieldTypes/boolean.d.ts +1 -1
  154. package/dist/types/fieldTypes/color.d.ts +1 -1
  155. package/dist/types/fieldTypes/date.d.ts +1 -1
  156. package/dist/types/fieldTypes/date_time.d.ts +1 -1
  157. package/dist/types/fieldTypes/file.d.ts +68 -1
  158. package/dist/types/fieldTypes/float.d.ts +1 -1
  159. package/dist/types/fieldTypes/gallery.d.ts +27 -11
  160. package/dist/types/fieldTypes/index.d.ts +2 -2
  161. package/dist/types/fieldTypes/integer.d.ts +1 -1
  162. package/dist/types/fieldTypes/json.d.ts +1 -1
  163. package/dist/types/fieldTypes/lat_lon.d.ts +1 -1
  164. package/dist/types/fieldTypes/link.d.ts +1 -1
  165. package/dist/types/fieldTypes/links.d.ts +1 -1
  166. package/dist/types/fieldTypes/rich_text.d.ts +1 -1
  167. package/dist/types/fieldTypes/seo.d.ts +1 -1
  168. package/dist/types/fieldTypes/single_block.d.ts +3 -3
  169. package/dist/types/fieldTypes/slug.d.ts +1 -1
  170. package/dist/types/fieldTypes/string.d.ts +1 -1
  171. package/dist/types/fieldTypes/structured_text.d.ts +1 -1
  172. package/dist/types/fieldTypes/text.d.ts +1 -1
  173. package/dist/types/fieldTypes/video.d.ts +1 -1
  174. package/dist/types/generated/resources/Item.d.ts +46 -28
  175. package/dist/types/generated/resources/ScheduledPublication.d.ts +3 -3
  176. package/dist/types/generated/resources/ScheduledUnpublishing.d.ts +3 -3
  177. package/dist/types/generated/resources/Upload.d.ts +10 -4
  178. package/dist/types/index.d.ts +4 -4
  179. package/dist/types/utilities/buildBlockRecord.d.ts +3 -3
  180. package/dist/types/utilities/inspectItem.d.ts +8 -0
  181. package/dist/types/utilities/itemDefinition.d.ts +36 -12
  182. package/dist/types/utilities/nonRecursiveBlocks.d.ts +179 -0
  183. package/dist/{esm/utilities/fieldValue.d.ts → types/utilities/normalizedFieldValues.d.ts} +15 -14
  184. package/dist/types/utilities/recursiveBlocks.d.ts +92 -9
  185. package/dist/types/utilities/schemaRepository.d.ts +2 -2
  186. package/package.json +4 -4
  187. package/src/fieldTypes/boolean.ts +5 -3
  188. package/src/fieldTypes/color.ts +5 -3
  189. package/src/fieldTypes/date.ts +5 -4
  190. package/src/fieldTypes/date_time.ts +5 -3
  191. package/src/fieldTypes/file.ts +98 -4
  192. package/src/fieldTypes/float.ts +5 -3
  193. package/src/fieldTypes/gallery.ts +53 -20
  194. package/src/fieldTypes/index.ts +2 -3
  195. package/src/fieldTypes/integer.ts +5 -3
  196. package/src/fieldTypes/json.ts +5 -4
  197. package/src/fieldTypes/lat_lon.ts +5 -3
  198. package/src/fieldTypes/link.ts +7 -5
  199. package/src/fieldTypes/links.ts +8 -4
  200. package/src/fieldTypes/rich_text.ts +7 -7
  201. package/src/fieldTypes/seo.ts +5 -4
  202. package/src/fieldTypes/single_block.ts +12 -10
  203. package/src/fieldTypes/slug.ts +5 -4
  204. package/src/fieldTypes/string.ts +5 -3
  205. package/src/fieldTypes/structured_text.ts +7 -7
  206. package/src/fieldTypes/text.ts +5 -4
  207. package/src/fieldTypes/video.ts +5 -3
  208. package/src/generated/Client.ts +1 -1
  209. package/src/generated/resources/Item.ts +129 -92
  210. package/src/generated/resources/ScheduledPublication.ts +6 -6
  211. package/src/generated/resources/ScheduledUnpublishing.ts +6 -6
  212. package/src/generated/resources/Upload.ts +36 -10
  213. package/src/index.ts +4 -4
  214. package/src/utilities/buildBlockRecord.ts +24 -31
  215. package/src/utilities/inspectItem.ts +590 -0
  216. package/src/utilities/itemDefinition.ts +53 -35
  217. package/src/utilities/{blocks.ts → nonRecursiveBlocks.ts} +170 -136
  218. package/src/utilities/{fieldValue.ts → normalizedFieldValues.ts} +70 -30
  219. package/src/utilities/recursiveBlocks.ts +186 -171
  220. package/src/utilities/schemaRepository.ts +2 -2
  221. package/dist/cjs/utilities/blocks.js.map +0 -1
  222. package/dist/cjs/utilities/fieldValue.js.map +0 -1
  223. package/dist/esm/utilities/blocks.d.ts +0 -180
  224. package/dist/esm/utilities/blocks.js.map +0 -1
  225. package/dist/esm/utilities/fieldValue.js.map +0 -1
  226. package/dist/types/utilities/blocks.d.ts +0 -180
@@ -0,0 +1,179 @@
1
+ /**
2
+ * DatoCMS Block Field Value Processing Utilities
3
+ *
4
+ * This utility provides a unified interface for working with blocks embedded within DatoCMS field values.
5
+ * DatoCMS supports three field types that can contain blocks:
6
+ * - Modular Content fields: arrays of blocks
7
+ * - Single Block fields: a single block
8
+ * - Structured Text fields: complex document structures with embedded blocks
9
+ *
10
+ * The challenge this solves: Each field type stores blocks differently and requires different
11
+ * traversal logic, making it complex to perform operations like transformations, filtering,
12
+ * or searching across blocks regardless of their containing field type.
13
+ *
14
+ * This utility abstracts away these differences, providing a consistent API to:
15
+ * - Visit/iterate through all blocks in any field type
16
+ * - Transform blocks while preserving field structure
17
+ * - Filter blocks based on conditions
18
+ * - Search for specific blocks
19
+ * - Perform functional operations (map, reduce, some, every)
20
+ *
21
+ * All functions come in both sync and async variants to support different use cases,
22
+ * particularly useful when block transformations require async operations like API calls.
23
+ */
24
+ import { type TreePath } from 'datocms-structured-text-utils';
25
+ import type { BlockItemInARequest } from '../fieldTypes';
26
+ import type * as ApiTypes from '../generated/ApiTypes';
27
+ /**
28
+ * Visit every block in a field value, calling the visitor function for each block found.
29
+ * Supports rich text, single block, and structured text field types.
30
+ *
31
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
32
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to visit
33
+ * @param visitor - Synchronous function called for each block. Receives the block item and its path
34
+ */
35
+ export declare function nonRecursiveVisitBlocksInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, visitor: (item: BlockItemInARequest, path: TreePath) => void): void;
36
+ /**
37
+ * Visit every block in a field value, calling the visitor function for each block found.
38
+ * Supports rich text, single block, and structured text field types.
39
+ *
40
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
41
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to visit
42
+ * @param visitor - Asynchronous function called for each block. Receives the block item and its path
43
+ * @returns Promise that resolves when all blocks have been visited
44
+ */
45
+ export declare function nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, visitor: (item: BlockItemInARequest, path: TreePath) => Promise<void>): Promise<void>;
46
+ /**
47
+ * Transform blocks in a field value by applying a mapping function to each block.
48
+ * Creates a new field value structure with transformed blocks while preserving the original structure.
49
+ * Supports rich text, single block, and structured text field types.
50
+ *
51
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
52
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to transform
53
+ * @param mapper - Synchronous function that transforms each block. Receives block item and path, returns new block
54
+ * @returns The new field value with transformed blocks
55
+ */
56
+ export declare function nonRecursiveMapBlocksInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, mapper: (item: BlockItemInARequest, path: TreePath) => BlockItemInARequest): unknown;
57
+ /**
58
+ * Transform blocks in a field value by applying a mapping function to each block.
59
+ * Creates a new field value structure with transformed blocks while preserving the original structure.
60
+ * Supports rich text, single block, and structured text field types.
61
+ *
62
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
63
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to transform
64
+ * @param mapper - Asynchronous function that transforms each block. Receives block item and path, returns new block
65
+ * @returns Promise that resolves to the new field value with transformed blocks
66
+ */
67
+ export declare function nonRecursiveMapBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, mapper: (item: BlockItemInARequest, path: TreePath) => Promise<BlockItemInARequest>): Promise<unknown>;
68
+ /**
69
+ * Find all blocks that match the predicate function.
70
+ * Searches through all blocks in the non-localized field value and returns all matches.
71
+ *
72
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
73
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to search
74
+ * @param predicate - Synchronous function that tests each block. Should return true for matching blocks
75
+ * @returns Array of objects, each containing a matching block and its path
76
+ */
77
+ export declare function nonRecursiveFindAllBlocksInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean): Array<{
78
+ item: BlockItemInARequest;
79
+ path: TreePath;
80
+ }>;
81
+ /**
82
+ * Find all blocks that match the predicate function.
83
+ * Searches through all blocks in the non-localized field value and returns all matches.
84
+ *
85
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
86
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to search
87
+ * @param predicate - Asynchronous function that tests each block. Should return true for matching blocks
88
+ * @returns Promise that resolves to an array of objects, each containing a matching block and its path
89
+ */
90
+ export declare function nonRecursiveFindAllBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => Promise<boolean>): Promise<Array<{
91
+ item: BlockItemInARequest;
92
+ path: TreePath;
93
+ }>>;
94
+ /**
95
+ * Filter blocks in a field value, removing those that don't match the predicate.
96
+ * Creates a new field value containing only blocks that pass the predicate test.
97
+ * Preserves the original field value structure and hierarchy.
98
+ *
99
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
100
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to filter
101
+ * @param predicate - Synchronous function that tests each block. Blocks returning false are removed
102
+ * @returns The new field value with filtered blocks
103
+ */
104
+ export declare function nonRecursiveFilterBlocksInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean): unknown;
105
+ /**
106
+ * Filter blocks in a field value, removing those that don't match the predicate.
107
+ * Creates a new field value containing only blocks that pass the predicate test.
108
+ * Preserves the original field value structure and hierarchy.
109
+ *
110
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
111
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to filter
112
+ * @param predicate - Asynchronous function that tests each block. Blocks returning false are removed
113
+ * @returns Promise that resolves to the new field value with filtered blocks
114
+ */
115
+ export declare function nonRecursiveFilterBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => Promise<boolean>): Promise<unknown>;
116
+ /**
117
+ * Reduce all blocks in a field value to a single value by applying a reducer function.
118
+ * Processes each block in the non-localized field value and accumulates the results into a single value.
119
+ *
120
+ * @template R - The type of the accumulated result
121
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
122
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to reduce
123
+ * @param reducer - Synchronous function that processes each block and updates the accumulator
124
+ * @param initialValue - The initial value for the accumulator
125
+ * @returns The final accumulated value
126
+ */
127
+ export declare function nonRecursiveReduceBlocksInNonLocalizedFieldValue<R>(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, reducer: (accumulator: R, item: BlockItemInARequest, path: TreePath) => R, initialValue: R): R;
128
+ /**
129
+ * Reduce all blocks in a field value to a single value by applying a reducer function.
130
+ * Processes each block in the non-localized field value and accumulates the results into a single value.
131
+ *
132
+ * @template R - The type of the accumulated result
133
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
134
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to reduce
135
+ * @param reducer - Asynchronous function that processes each block and updates the accumulator
136
+ * @param initialValue - The initial value for the accumulator
137
+ * @returns Promise that resolves to the final accumulated value
138
+ */
139
+ export declare function nonRecursiveReduceBlocksInNonLocalizedFieldValueAsync<R>(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, reducer: (accumulator: R, item: BlockItemInARequest, path: TreePath) => Promise<R>, initialValue: R): Promise<R>;
140
+ /**
141
+ * Check if any block in the non-localized field value matches the predicate function.
142
+ * Returns true as soon as the first matching block is found (short-circuit evaluation).
143
+ *
144
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
145
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
146
+ * @param predicate - Synchronous function that tests each block. Should return true for matching blocks
147
+ * @returns True if any block matches, false otherwise
148
+ */
149
+ export declare function nonRecursiveSomeBlocksInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean): boolean;
150
+ /**
151
+ * Check if any block in the non-localized field value matches the predicate function.
152
+ * Returns true as soon as the first matching block is found (short-circuit evaluation).
153
+ *
154
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
155
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
156
+ * @param predicate - Asynchronous function that tests each block. Should return true for matching blocks
157
+ * @returns Promise that resolves to true if any block matches, false otherwise
158
+ */
159
+ export declare function nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => Promise<boolean>): Promise<boolean>;
160
+ /**
161
+ * Check if every block in the non-localized field value matches the predicate function.
162
+ * Returns false as soon as the first non-matching block is found (short-circuit evaluation).
163
+ *
164
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
165
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
166
+ * @param predicate - Synchronous function that tests each block. Should return true for valid blocks
167
+ * @returns True if all blocks match, false otherwise
168
+ */
169
+ export declare function nonRecursiveEveryBlockInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean): boolean;
170
+ /**
171
+ * Check if every block in the non-localized field value matches the predicate function.
172
+ * Returns false as soon as the first non-matching block is found (short-circuit evaluation).
173
+ *
174
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
175
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
176
+ * @param predicate - Asynchronous function that tests each block. Should return true for valid blocks
177
+ * @returns Promise that resolves to true if all blocks match, false otherwise
178
+ */
179
+ export declare function nonRecursiveEveryBlockInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => Promise<boolean>): Promise<boolean>;
@@ -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,101 @@
1
1
  import { type BlockItemInARequest } from '../fieldTypes';
2
2
  import type * as ApiTypes from '../generated/ApiTypes';
3
- import type * as RawApiTypes from '../generated/RawApiTypes';
4
3
  import type { SchemaRepository } from './schemaRepository';
5
4
  /**
6
- * Path through a field value (ie. ['content', 0, 'attributes', 'title'])
5
+ * Path through a non-localized field value (ie. ['content', 0, 'attributes', 'title'])
7
6
  */
8
7
  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<{
8
+ /**
9
+ * Recursively visit every block in a non-localized field value and all nested blocks within those blocks.
10
+ * This function traverses not only the direct blocks in the non-localized field value but also recursively
11
+ * visits blocks contained within the attributes of each block, creating a complete traversal
12
+ * of the entire block hierarchy.
13
+ *
14
+ * @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
15
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
16
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to visit
17
+ * @param visitor - Asynchronous function called for each block found, including nested blocks
18
+ * @returns Promise that resolves when all blocks and nested blocks have been visited
19
+ */
20
+ export declare function visitBlocksInNonLocalizedFieldValue(schemaRepository: SchemaRepository, fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, visitor: (item: BlockItemInARequest, path: TreePath) => void | Promise<void>, path?: TreePath): Promise<void>;
21
+ /**
22
+ * Recursively find all blocks that match the predicate function in a non-localized field value.
23
+ * Searches through all direct blocks and recursively through nested blocks within
24
+ * the attributes of each block, returning all matches found throughout the hierarchy.
25
+ *
26
+ * @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
27
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
28
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to search
29
+ * @param predicate - Asynchronous function that tests each block, including nested ones
30
+ * @returns Promise that resolves to an array of objects, each containing a matching block and its full path
31
+ */
32
+ export declare function findAllBlocksInNonLocalizedFieldValue(schemaRepository: SchemaRepository, fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<Array<{
11
33
  item: BlockItemInARequest;
12
34
  path: TreePath;
13
35
  }>>;
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>;
36
+ /**
37
+ * Recursively filter blocks in a non-localized field value, removing those that don't match the predicate.
38
+ * Creates a new non-localized field value structure containing only blocks that pass the predicate test,
39
+ * including recursive filtering of nested blocks within block attributes. The filtering
40
+ * preserves the original non-localized field value structure and hierarchy.
41
+ *
42
+ * @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
43
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
44
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to filter
45
+ * @param predicate - Asynchronous function that tests each block, including nested ones
46
+ * @returns Promise that resolves to the new non-localized field value with recursively filtered blocks
47
+ */
48
+ export declare function filterBlocksInNonLocalizedFieldValue(schemaRepository: SchemaRepository, fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<unknown>;
49
+ /**
50
+ * Recursively reduce all blocks in a non-localized field value to a single value by applying a reducer function.
51
+ * Processes each direct block and recursively processes nested blocks within block attributes,
52
+ * accumulating results from the entire block hierarchy into a single value.
53
+ *
54
+ * @template R - The type of the accumulated result
55
+ * @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
56
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
57
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to reduce
58
+ * @param reducer - Asynchronous function that processes each block and updates the accumulator
59
+ * @param initialNonLocalizedFieldValue - The initial value for the accumulator
60
+ * @returns Promise that resolves to the final accumulated value from all blocks in the hierarchy
61
+ */
62
+ export declare function reduceBlocksInNonLocalizedFieldValue<R>(schemaRepository: SchemaRepository, fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, reducer: (accumulator: R, item: BlockItemInARequest, path: TreePath) => R | Promise<R>, initialValue: R, path?: TreePath): Promise<R>;
63
+ /**
64
+ * Recursively check if any block in the non-localized field value matches the predicate function.
65
+ * Tests both direct blocks and recursively tests nested blocks within block attributes.
66
+ * Returns true as soon as the first matching block is found anywhere in the hierarchy
67
+ * (short-circuit evaluation).
68
+ *
69
+ * @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
70
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
71
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
72
+ * @param predicate - Asynchronous function that tests each block, including nested ones
73
+ * @returns Promise that resolves to true if any block in the hierarchy matches, false otherwise
74
+ */
75
+ export declare function someBlocksInNonLocalizedFieldValue(schemaRepository: SchemaRepository, fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<boolean>;
76
+ /**
77
+ * Recursively check if every block in the non-localized field value matches the predicate function.
78
+ * Tests both direct blocks and recursively tests nested blocks within block attributes.
79
+ * Returns false as soon as the first non-matching block is found anywhere in the hierarchy
80
+ * (short-circuit evaluation).
81
+ *
82
+ * @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
83
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
84
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
85
+ * @param predicate - Asynchronous function that tests each block, including nested ones
86
+ * @returns Promise that resolves to true if all blocks in the hierarchy match, false otherwise
87
+ */
88
+ export declare function everyBlockInNonLocalizedFieldValue(schemaRepository: SchemaRepository, fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<boolean>;
89
+ /**
90
+ * Recursively transform blocks in a non-localized field value by applying a mapping function to each block.
91
+ * Creates a new non-localized field value structure with transformed blocks while preserving the original
92
+ * structure. Applies the mapping function to both direct blocks and recursively to nested
93
+ * blocks within block attributes throughout the entire hierarchy.
94
+ *
95
+ * @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
96
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
97
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to transform
98
+ * @param mapper - Asynchronous function that transforms each block, including nested ones
99
+ * @returns Promise that resolves to the new non-localized field value with recursively transformed blocks
100
+ */
101
+ export declare function mapBlocksInNonLocalizedFieldValue(schemaRepository: SchemaRepository, fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, mapper: (item: BlockItemInARequest, path: TreePath) => BlockItemInARequest | Promise<BlockItemInARequest>, path?: TreePath): Promise<unknown>;
@@ -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.9",
3
+ "version": "5.1.11",
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.7",
45
+ "@datocms/dashboard-client": "^5.1.10",
46
46
  "@types/uuid": "^9.0.7"
47
47
  },
48
- "gitHead": "d0c86d5cbb6df9b9260ebe379bcbcc44f6f43706"
48
+ "gitHead": "e809594f4faa92ee8cb1943de52278f9030b09d7"
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
  }