@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
@@ -44,7 +44,7 @@ import type {
44
44
  StructuredTextFieldValueWithNestedBlocks,
45
45
  } from '../fieldTypes';
46
46
  import type * as ApiTypes from '../generated/ApiTypes';
47
- import type * as RawApiTypes from '../generated/RawApiTypes';
47
+ import { isLocalizedFieldValue } from './normalizedFieldValues';
48
48
 
49
49
  type PossibleRichTextValue =
50
50
  | RichTextFieldValue
@@ -59,18 +59,16 @@ type PossibleStructuredTextValue =
59
59
  | StructuredTextFieldValueAsRequest
60
60
  | StructuredTextFieldValueWithNestedBlocks;
61
61
 
62
- function getFieldType(field: RawApiTypes.Field | ApiTypes.Field) {
63
- return 'attributes' in field ? field.attributes.field_type : field.field_type;
64
- }
65
-
66
62
  function* iterateBlocks(
67
- field: RawApiTypes.Field | ApiTypes.Field,
68
- value: unknown,
63
+ fieldType: ApiTypes.Field['field_type'],
64
+ nonLocalizedFieldValue: unknown,
69
65
  ): Generator<{ item: BlockItemInARequest; path: TreePath }> {
70
- const fieldType = getFieldType(field);
66
+ if (isLocalizedFieldValue(nonLocalizedFieldValue)) {
67
+ throw new Error('A non-localized field value is required!');
68
+ }
71
69
 
72
70
  if (fieldType === 'rich_text') {
73
- const richTextValue = value as PossibleRichTextValue;
71
+ const richTextValue = nonLocalizedFieldValue as PossibleRichTextValue;
74
72
  if (richTextValue) {
75
73
  for (let index = 0; index < richTextValue.length; index++) {
76
74
  const item = richTextValue[index]!;
@@ -81,7 +79,7 @@ function* iterateBlocks(
81
79
  }
82
80
 
83
81
  if (fieldType === 'single_block') {
84
- const singleBlockValue = value as PossibleSingleBlockValue;
82
+ const singleBlockValue = nonLocalizedFieldValue as PossibleSingleBlockValue;
85
83
  if (singleBlockValue) {
86
84
  yield { item: singleBlockValue, path: [] };
87
85
  }
@@ -89,7 +87,8 @@ function* iterateBlocks(
89
87
  }
90
88
 
91
89
  if (fieldType === 'structured_text') {
92
- const structuredTextValue = value as PossibleStructuredTextValue;
90
+ const structuredTextValue =
91
+ nonLocalizedFieldValue as PossibleStructuredTextValue;
93
92
  if (structuredTextValue) {
94
93
  const foundNodes = collectNodes(
95
94
  structuredTextValue.document,
@@ -107,13 +106,11 @@ function* iterateBlocks(
107
106
  }
108
107
 
109
108
  async function* iterateBlocksAsync(
110
- field: RawApiTypes.Field | ApiTypes.Field,
111
- value: unknown,
109
+ fieldType: ApiTypes.Field['field_type'],
110
+ nonLocalizedFieldValue: unknown,
112
111
  ): AsyncGenerator<{ item: BlockItemInARequest; path: TreePath }> {
113
- const fieldType = getFieldType(field);
114
-
115
112
  if (fieldType === 'rich_text') {
116
- const richTextValue = value as PossibleRichTextValue;
113
+ const richTextValue = nonLocalizedFieldValue as PossibleRichTextValue;
117
114
  if (richTextValue) {
118
115
  for (let index = 0; index < richTextValue.length; index++) {
119
116
  const item = richTextValue[index]!;
@@ -124,7 +121,7 @@ async function* iterateBlocksAsync(
124
121
  }
125
122
 
126
123
  if (fieldType === 'single_block') {
127
- const singleBlockValue = value as PossibleSingleBlockValue;
124
+ const singleBlockValue = nonLocalizedFieldValue as PossibleSingleBlockValue;
128
125
  if (singleBlockValue) {
129
126
  yield { item: singleBlockValue, path: [] };
130
127
  }
@@ -132,7 +129,8 @@ async function* iterateBlocksAsync(
132
129
  }
133
130
 
134
131
  if (fieldType === 'structured_text') {
135
- const structuredTextValue = value as PossibleStructuredTextValue;
132
+ const structuredTextValue =
133
+ nonLocalizedFieldValue as PossibleStructuredTextValue;
136
134
  if (structuredTextValue) {
137
135
  const foundNodes = await collectNodesAsync(
138
136
  structuredTextValue.document,
@@ -153,16 +151,19 @@ async function* iterateBlocksAsync(
153
151
  * Visit every block in a field value, calling the visitor function for each block found.
154
152
  * Supports rich text, single block, and structured text field types.
155
153
  *
156
- * @param field - The DatoCMS field definition that determines how blocks are processed
157
- * @param value - The field value containing blocks to visit
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 visit
158
156
  * @param visitor - Synchronous function called for each block. Receives the block item and its path
159
157
  */
160
- export function nonRecursiveVisitBlocksInFieldValue(
161
- field: RawApiTypes.Field | ApiTypes.Field,
162
- value: unknown,
158
+ export function nonRecursiveVisitBlocksInNonLocalizedFieldValue(
159
+ fieldType: ApiTypes.Field['field_type'],
160
+ nonLocalizedFieldValue: unknown,
163
161
  visitor: (item: BlockItemInARequest, path: TreePath) => void,
164
162
  ): void {
165
- for (const { item, path } of iterateBlocks(field, value)) {
163
+ for (const { item, path } of iterateBlocks(
164
+ fieldType,
165
+ nonLocalizedFieldValue,
166
+ )) {
166
167
  visitor(item, path);
167
168
  }
168
169
  }
@@ -171,17 +172,20 @@ export function nonRecursiveVisitBlocksInFieldValue(
171
172
  * Visit every block in a field value, calling the visitor function for each block found.
172
173
  * Supports rich text, single block, and structured text field types.
173
174
  *
174
- * @param field - The DatoCMS field definition that determines how blocks are processed
175
- * @param value - The field value containing blocks to visit
175
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
176
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to visit
176
177
  * @param visitor - Asynchronous function called for each block. Receives the block item and its path
177
178
  * @returns Promise that resolves when all blocks have been visited
178
179
  */
179
- export async function nonRecursiveVisitBlocksInFieldValueAsync(
180
- field: RawApiTypes.Field | ApiTypes.Field,
181
- value: unknown,
180
+ export async function nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(
181
+ fieldType: ApiTypes.Field['field_type'],
182
+ nonLocalizedFieldValue: unknown,
182
183
  visitor: (item: BlockItemInARequest, path: TreePath) => Promise<void>,
183
184
  ): Promise<void> {
184
- for await (const { item, path } of iterateBlocksAsync(field, value)) {
185
+ for await (const { item, path } of iterateBlocksAsync(
186
+ fieldType,
187
+ nonLocalizedFieldValue,
188
+ )) {
185
189
  await visitor(item, path);
186
190
  }
187
191
  }
@@ -191,32 +195,31 @@ export async function nonRecursiveVisitBlocksInFieldValueAsync(
191
195
  * Creates a new field value structure with transformed blocks while preserving the original structure.
192
196
  * Supports rich text, single block, and structured text field types.
193
197
  *
194
- * @param field - The DatoCMS field definition that determines how blocks are processed
195
- * @param value - The field value containing blocks to transform
198
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
199
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to transform
196
200
  * @param mapper - Synchronous function that transforms each block. Receives block item and path, returns new block
197
201
  * @returns The new field value with transformed blocks
198
202
  */
199
- export function nonRecursiveMapBlocksInFieldValue(
200
- field: RawApiTypes.Field | ApiTypes.Field,
201
- value: unknown,
203
+ export function nonRecursiveMapBlocksInNonLocalizedFieldValue(
204
+ fieldType: ApiTypes.Field['field_type'],
205
+ nonLocalizedFieldValue: unknown,
202
206
  mapper: (item: BlockItemInARequest, path: TreePath) => BlockItemInARequest,
203
207
  ): unknown {
204
- const fieldType = getFieldType(field);
205
-
206
208
  if (fieldType === 'rich_text') {
207
- const richTextValue = value as PossibleRichTextValue;
209
+ const richTextValue = nonLocalizedFieldValue as PossibleRichTextValue;
208
210
  return richTextValue
209
211
  ? richTextValue.map((item, index) => mapper(item, [index]))
210
212
  : richTextValue;
211
213
  }
212
214
 
213
215
  if (fieldType === 'single_block') {
214
- const singleBlockValue = value as PossibleSingleBlockValue;
216
+ const singleBlockValue = nonLocalizedFieldValue as PossibleSingleBlockValue;
215
217
  return singleBlockValue ? mapper(singleBlockValue, []) : null;
216
218
  }
217
219
 
218
220
  if (fieldType === 'structured_text') {
219
- const structuredTextValue = value as PossibleStructuredTextValue;
221
+ const structuredTextValue =
222
+ nonLocalizedFieldValue as PossibleStructuredTextValue;
220
223
 
221
224
  if (!structuredTextValue) {
222
225
  return null;
@@ -237,7 +240,7 @@ export function nonRecursiveMapBlocksInFieldValue(
237
240
  };
238
241
  }
239
242
 
240
- return value;
243
+ return nonLocalizedFieldValue;
241
244
  }
242
245
 
243
246
  /**
@@ -245,23 +248,21 @@ export function nonRecursiveMapBlocksInFieldValue(
245
248
  * Creates a new field value structure with transformed blocks while preserving the original structure.
246
249
  * Supports rich text, single block, and structured text field types.
247
250
  *
248
- * @param field - The DatoCMS field definition that determines how blocks are processed
249
- * @param value - The field value containing blocks to transform
251
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
252
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to transform
250
253
  * @param mapper - Asynchronous function that transforms each block. Receives block item and path, returns new block
251
254
  * @returns Promise that resolves to the new field value with transformed blocks
252
255
  */
253
- export async function nonRecursiveMapBlocksInFieldValueAsync(
254
- field: RawApiTypes.Field | ApiTypes.Field,
255
- value: unknown,
256
+ export async function nonRecursiveMapBlocksInNonLocalizedFieldValueAsync(
257
+ fieldType: ApiTypes.Field['field_type'],
258
+ nonLocalizedFieldValue: unknown,
256
259
  mapper: (
257
260
  item: BlockItemInARequest,
258
261
  path: TreePath,
259
262
  ) => Promise<BlockItemInARequest>,
260
263
  ): Promise<unknown> {
261
- const fieldType = getFieldType(field);
262
-
263
264
  if (fieldType === 'rich_text') {
264
- const richTextValue = value as PossibleRichTextValue;
265
+ const richTextValue = nonLocalizedFieldValue as PossibleRichTextValue;
265
266
  return richTextValue
266
267
  ? await Promise.all(
267
268
  richTextValue.map((item, index) => mapper(item, [index])),
@@ -270,12 +271,13 @@ export async function nonRecursiveMapBlocksInFieldValueAsync(
270
271
  }
271
272
 
272
273
  if (fieldType === 'single_block') {
273
- const singleBlockValue = value as PossibleSingleBlockValue;
274
+ const singleBlockValue = nonLocalizedFieldValue as PossibleSingleBlockValue;
274
275
  return singleBlockValue ? await mapper(singleBlockValue, []) : null;
275
276
  }
276
277
 
277
278
  if (fieldType === 'structured_text') {
278
- const structuredTextValue = value as PossibleStructuredTextValue;
279
+ const structuredTextValue =
280
+ nonLocalizedFieldValue as PossibleStructuredTextValue;
279
281
 
280
282
  if (!structuredTextValue) {
281
283
  return null;
@@ -296,26 +298,29 @@ export async function nonRecursiveMapBlocksInFieldValueAsync(
296
298
  };
297
299
  }
298
300
 
299
- return value;
301
+ return nonLocalizedFieldValue;
300
302
  }
301
303
 
302
304
  /**
303
305
  * Find all blocks that match the predicate function.
304
- * Searches through all blocks in the field value and returns all matches.
306
+ * Searches through all blocks in the non-localized field value and returns all matches.
305
307
  *
306
- * @param field - The DatoCMS field definition that determines how blocks are processed
307
- * @param value - The field value containing blocks to search
308
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
309
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to search
308
310
  * @param predicate - Synchronous function that tests each block. Should return true for matching blocks
309
311
  * @returns Array of objects, each containing a matching block and its path
310
312
  */
311
- export function nonRecursiveFindAllBlocksInFieldValue(
312
- field: RawApiTypes.Field | ApiTypes.Field,
313
- value: unknown,
313
+ export function nonRecursiveFindAllBlocksInNonLocalizedFieldValue(
314
+ fieldType: ApiTypes.Field['field_type'],
315
+ nonLocalizedFieldValue: unknown,
314
316
  predicate: (item: BlockItemInARequest, path: TreePath) => boolean,
315
317
  ): Array<{ item: BlockItemInARequest; path: TreePath }> {
316
318
  const results: Array<{ item: BlockItemInARequest; path: TreePath }> = [];
317
319
 
318
- for (const { item, path } of iterateBlocks(field, value)) {
320
+ for (const { item, path } of iterateBlocks(
321
+ fieldType,
322
+ nonLocalizedFieldValue,
323
+ )) {
319
324
  if (predicate(item, path)) {
320
325
  results.push({ item, path });
321
326
  }
@@ -326,21 +331,24 @@ export function nonRecursiveFindAllBlocksInFieldValue(
326
331
 
327
332
  /**
328
333
  * Find all blocks that match the predicate function.
329
- * Searches through all blocks in the field value and returns all matches.
334
+ * Searches through all blocks in the non-localized field value and returns all matches.
330
335
  *
331
- * @param field - The DatoCMS field definition that determines how blocks are processed
332
- * @param value - The field value containing blocks to search
336
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
337
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to search
333
338
  * @param predicate - Asynchronous function that tests each block. Should return true for matching blocks
334
339
  * @returns Promise that resolves to an array of objects, each containing a matching block and its path
335
340
  */
336
- export async function nonRecursiveFindAllBlocksInFieldValueAsync(
337
- field: RawApiTypes.Field | ApiTypes.Field,
338
- value: unknown,
341
+ export async function nonRecursiveFindAllBlocksInNonLocalizedFieldValueAsync(
342
+ fieldType: ApiTypes.Field['field_type'],
343
+ nonLocalizedFieldValue: unknown,
339
344
  predicate: (item: BlockItemInARequest, path: TreePath) => Promise<boolean>,
340
345
  ): Promise<Array<{ item: BlockItemInARequest; path: TreePath }>> {
341
346
  const results: Array<{ item: BlockItemInARequest; path: TreePath }> = [];
342
347
 
343
- for await (const { item, path } of iterateBlocksAsync(field, value)) {
348
+ for await (const { item, path } of iterateBlocksAsync(
349
+ fieldType,
350
+ nonLocalizedFieldValue,
351
+ )) {
344
352
  if (await predicate(item, path)) {
345
353
  results.push({ item, path });
346
354
  }
@@ -354,32 +362,36 @@ export async function nonRecursiveFindAllBlocksInFieldValueAsync(
354
362
  * Creates a new field value containing only blocks that pass the predicate test.
355
363
  * Preserves the original field value structure and hierarchy.
356
364
  *
357
- * @param field - The DatoCMS field definition that determines how blocks are processed
358
- * @param value - The field value containing blocks to filter
365
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
366
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to filter
359
367
  * @param predicate - Synchronous function that tests each block. Blocks returning false are removed
360
368
  * @returns The new field value with filtered blocks
361
369
  */
362
- export function nonRecursiveFilterBlocksInFieldValue(
363
- field: RawApiTypes.Field | ApiTypes.Field,
364
- value: unknown,
370
+ export function nonRecursiveFilterBlocksInNonLocalizedFieldValue(
371
+ fieldType: ApiTypes.Field['field_type'],
372
+ nonLocalizedFieldValue: unknown,
365
373
  predicate: (item: BlockItemInARequest, path: TreePath) => boolean,
366
374
  ): unknown {
367
- const fieldType = getFieldType(field);
368
-
369
375
  if (fieldType === 'rich_text') {
370
376
  const filteredItems: BlockItemInARequest[] = [];
371
377
 
372
- for (const { item, path } of iterateBlocks(field, value)) {
378
+ for (const { item, path } of iterateBlocks(
379
+ fieldType,
380
+ nonLocalizedFieldValue,
381
+ )) {
373
382
  if (predicate(item, path)) {
374
383
  filteredItems.push(item);
375
384
  }
376
385
  }
377
386
 
378
- return value ? filteredItems : value;
387
+ return filteredItems;
379
388
  }
380
389
 
381
390
  if (fieldType === 'single_block') {
382
- for (const { item, path } of iterateBlocks(field, value)) {
391
+ for (const { item, path } of iterateBlocks(
392
+ fieldType,
393
+ nonLocalizedFieldValue,
394
+ )) {
383
395
  if (predicate(item, path)) {
384
396
  return item;
385
397
  }
@@ -388,7 +400,8 @@ export function nonRecursiveFilterBlocksInFieldValue(
388
400
  }
389
401
 
390
402
  if (fieldType === 'structured_text') {
391
- const structuredTextValue = value as PossibleStructuredTextValue;
403
+ const structuredTextValue =
404
+ nonLocalizedFieldValue as PossibleStructuredTextValue;
392
405
 
393
406
  if (!structuredTextValue) {
394
407
  return null;
@@ -412,7 +425,7 @@ export function nonRecursiveFilterBlocksInFieldValue(
412
425
  : null;
413
426
  }
414
427
 
415
- return value;
428
+ return nonLocalizedFieldValue;
416
429
  }
417
430
 
418
431
  /**
@@ -420,32 +433,36 @@ export function nonRecursiveFilterBlocksInFieldValue(
420
433
  * Creates a new field value containing only blocks that pass the predicate test.
421
434
  * Preserves the original field value structure and hierarchy.
422
435
  *
423
- * @param field - The DatoCMS field definition that determines how blocks are processed
424
- * @param value - The field value containing blocks to filter
436
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
437
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to filter
425
438
  * @param predicate - Asynchronous function that tests each block. Blocks returning false are removed
426
439
  * @returns Promise that resolves to the new field value with filtered blocks
427
440
  */
428
- export async function nonRecursiveFilterBlocksInFieldValueAsync(
429
- field: RawApiTypes.Field | ApiTypes.Field,
430
- value: unknown,
441
+ export async function nonRecursiveFilterBlocksInNonLocalizedFieldValueAsync(
442
+ fieldType: ApiTypes.Field['field_type'],
443
+ nonLocalizedFieldValue: unknown,
431
444
  predicate: (item: BlockItemInARequest, path: TreePath) => Promise<boolean>,
432
445
  ): Promise<unknown> {
433
- const fieldType = getFieldType(field);
434
-
435
446
  if (fieldType === 'rich_text') {
436
447
  const filteredItems: BlockItemInARequest[] = [];
437
448
 
438
- for await (const { item, path } of iterateBlocksAsync(field, value)) {
449
+ for await (const { item, path } of iterateBlocksAsync(
450
+ fieldType,
451
+ nonLocalizedFieldValue,
452
+ )) {
439
453
  if (await predicate(item, path)) {
440
454
  filteredItems.push(item);
441
455
  }
442
456
  }
443
457
 
444
- return value ? filteredItems : value;
458
+ return filteredItems;
445
459
  }
446
460
 
447
461
  if (fieldType === 'single_block') {
448
- for await (const { item, path } of iterateBlocksAsync(field, value)) {
462
+ for await (const { item, path } of iterateBlocksAsync(
463
+ fieldType,
464
+ nonLocalizedFieldValue,
465
+ )) {
449
466
  if (await predicate(item, path)) {
450
467
  return item;
451
468
  }
@@ -454,7 +471,8 @@ export async function nonRecursiveFilterBlocksInFieldValueAsync(
454
471
  }
455
472
 
456
473
  if (fieldType === 'structured_text') {
457
- const structuredTextValue = value as PossibleStructuredTextValue;
474
+ const structuredTextValue =
475
+ nonLocalizedFieldValue as PossibleStructuredTextValue;
458
476
 
459
477
  if (!structuredTextValue) {
460
478
  return null;
@@ -478,29 +496,32 @@ export async function nonRecursiveFilterBlocksInFieldValueAsync(
478
496
  : null;
479
497
  }
480
498
 
481
- return value;
499
+ return nonLocalizedFieldValue;
482
500
  }
483
501
 
484
502
  /**
485
503
  * Reduce all blocks in a field value to a single value by applying a reducer function.
486
- * Processes each block in the field value and accumulates the results into a single value.
504
+ * Processes each block in the non-localized field value and accumulates the results into a single value.
487
505
  *
488
506
  * @template R - The type of the accumulated result
489
- * @param field - The DatoCMS field definition that determines how blocks are processed
490
- * @param value - The field value containing blocks to reduce
507
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
508
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to reduce
491
509
  * @param reducer - Synchronous function that processes each block and updates the accumulator
492
510
  * @param initialValue - The initial value for the accumulator
493
511
  * @returns The final accumulated value
494
512
  */
495
- export function nonRecursiveReduceBlocksInFieldValue<R>(
496
- field: RawApiTypes.Field | ApiTypes.Field,
497
- value: unknown,
513
+ export function nonRecursiveReduceBlocksInNonLocalizedFieldValue<R>(
514
+ fieldType: ApiTypes.Field['field_type'],
515
+ nonLocalizedFieldValue: unknown,
498
516
  reducer: (accumulator: R, item: BlockItemInARequest, path: TreePath) => R,
499
517
  initialValue: R,
500
518
  ): R {
501
519
  let accumulator = initialValue;
502
520
 
503
- for (const { item, path } of iterateBlocks(field, value)) {
521
+ for (const { item, path } of iterateBlocks(
522
+ fieldType,
523
+ nonLocalizedFieldValue,
524
+ )) {
504
525
  accumulator = reducer(accumulator, item, path);
505
526
  }
506
527
 
@@ -509,18 +530,18 @@ export function nonRecursiveReduceBlocksInFieldValue<R>(
509
530
 
510
531
  /**
511
532
  * Reduce all blocks in a field value to a single value by applying a reducer function.
512
- * Processes each block in the field value and accumulates the results into a single value.
533
+ * Processes each block in the non-localized field value and accumulates the results into a single value.
513
534
  *
514
535
  * @template R - The type of the accumulated result
515
- * @param field - The DatoCMS field definition that determines how blocks are processed
516
- * @param value - The field value containing blocks to reduce
536
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
537
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to reduce
517
538
  * @param reducer - Asynchronous function that processes each block and updates the accumulator
518
539
  * @param initialValue - The initial value for the accumulator
519
540
  * @returns Promise that resolves to the final accumulated value
520
541
  */
521
- export async function nonRecursiveReduceBlocksInFieldValueAsync<R>(
522
- field: RawApiTypes.Field | ApiTypes.Field,
523
- value: unknown,
542
+ export async function nonRecursiveReduceBlocksInNonLocalizedFieldValueAsync<R>(
543
+ fieldType: ApiTypes.Field['field_type'],
544
+ nonLocalizedFieldValue: unknown,
524
545
  reducer: (
525
546
  accumulator: R,
526
547
  item: BlockItemInARequest,
@@ -530,7 +551,10 @@ export async function nonRecursiveReduceBlocksInFieldValueAsync<R>(
530
551
  ): Promise<R> {
531
552
  let accumulator = initialValue;
532
553
 
533
- for await (const { item, path } of iterateBlocksAsync(field, value)) {
554
+ for await (const { item, path } of iterateBlocksAsync(
555
+ fieldType,
556
+ nonLocalizedFieldValue,
557
+ )) {
534
558
  accumulator = await reducer(accumulator, item, path);
535
559
  }
536
560
 
@@ -538,20 +562,23 @@ export async function nonRecursiveReduceBlocksInFieldValueAsync<R>(
538
562
  }
539
563
 
540
564
  /**
541
- * Check if any block in the field value matches the predicate function.
565
+ * Check if any block in the non-localized field value matches the predicate function.
542
566
  * Returns true as soon as the first matching block is found (short-circuit evaluation).
543
567
  *
544
- * @param field - The DatoCMS field definition that determines how blocks are processed
545
- * @param value - The field value containing blocks to test
568
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
569
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
546
570
  * @param predicate - Synchronous function that tests each block. Should return true for matching blocks
547
571
  * @returns True if any block matches, false otherwise
548
572
  */
549
- export function nonRecursiveSomeBlocksInFieldValue(
550
- field: RawApiTypes.Field | ApiTypes.Field,
551
- value: unknown,
573
+ export function nonRecursiveSomeBlocksInNonLocalizedFieldValue(
574
+ fieldType: ApiTypes.Field['field_type'],
575
+ nonLocalizedFieldValue: unknown,
552
576
  predicate: (item: BlockItemInARequest, path: TreePath) => boolean,
553
577
  ): boolean {
554
- for (const { item, path } of iterateBlocks(field, value)) {
578
+ for (const { item, path } of iterateBlocks(
579
+ fieldType,
580
+ nonLocalizedFieldValue,
581
+ )) {
555
582
  if (predicate(item, path)) {
556
583
  return true;
557
584
  }
@@ -561,20 +588,23 @@ export function nonRecursiveSomeBlocksInFieldValue(
561
588
  }
562
589
 
563
590
  /**
564
- * Check if any block in the field value matches the predicate function.
591
+ * Check if any block in the non-localized field value matches the predicate function.
565
592
  * Returns true as soon as the first matching block is found (short-circuit evaluation).
566
593
  *
567
- * @param field - The DatoCMS field definition that determines how blocks are processed
568
- * @param value - The field value containing blocks to test
594
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
595
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
569
596
  * @param predicate - Asynchronous function that tests each block. Should return true for matching blocks
570
597
  * @returns Promise that resolves to true if any block matches, false otherwise
571
598
  */
572
- export async function nonRecursiveSomeBlocksInFieldValueAsync(
573
- field: RawApiTypes.Field | ApiTypes.Field,
574
- value: unknown,
599
+ export async function nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync(
600
+ fieldType: ApiTypes.Field['field_type'],
601
+ nonLocalizedFieldValue: unknown,
575
602
  predicate: (item: BlockItemInARequest, path: TreePath) => Promise<boolean>,
576
603
  ): Promise<boolean> {
577
- for await (const { item, path } of iterateBlocksAsync(field, value)) {
604
+ for await (const { item, path } of iterateBlocksAsync(
605
+ fieldType,
606
+ nonLocalizedFieldValue,
607
+ )) {
578
608
  if (await predicate(item, path)) {
579
609
  return true;
580
610
  }
@@ -584,41 +614,45 @@ export async function nonRecursiveSomeBlocksInFieldValueAsync(
584
614
  }
585
615
 
586
616
  /**
587
- * Check if every block in the field value matches the predicate function.
617
+ * Check if every block in the non-localized field value matches the predicate function.
588
618
  * Returns false as soon as the first non-matching block is found (short-circuit evaluation).
589
619
  *
590
- * @param field - The DatoCMS field definition that determines how blocks are processed
591
- * @param value - The field value containing blocks to test
620
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
621
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
592
622
  * @param predicate - Synchronous function that tests each block. Should return true for valid blocks
593
623
  * @returns True if all blocks match, false otherwise
594
624
  */
595
- export function nonRecursiveEveryBlockInFieldValue(
596
- field: RawApiTypes.Field | ApiTypes.Field,
597
- value: unknown,
625
+ export function nonRecursiveEveryBlockInNonLocalizedFieldValue(
626
+ fieldType: ApiTypes.Field['field_type'],
627
+ nonLocalizedFieldValue: unknown,
598
628
  predicate: (item: BlockItemInARequest, path: TreePath) => boolean,
599
629
  ): boolean {
600
- return !nonRecursiveSomeBlocksInFieldValue(field, value, (item, path) => {
601
- return !predicate(item, path);
602
- });
630
+ return !nonRecursiveSomeBlocksInNonLocalizedFieldValue(
631
+ fieldType,
632
+ nonLocalizedFieldValue,
633
+ (item, path) => {
634
+ return !predicate(item, path);
635
+ },
636
+ );
603
637
  }
604
638
 
605
639
  /**
606
- * Check if every block in the field value matches the predicate function.
640
+ * Check if every block in the non-localized field value matches the predicate function.
607
641
  * Returns false as soon as the first non-matching block is found (short-circuit evaluation).
608
642
  *
609
- * @param field - The DatoCMS field definition that determines how blocks are processed
610
- * @param value - The field value containing blocks to test
643
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
644
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
611
645
  * @param predicate - Asynchronous function that tests each block. Should return true for valid blocks
612
646
  * @returns Promise that resolves to true if all blocks match, false otherwise
613
647
  */
614
- export async function nonRecursiveEveryBlockInFieldValueAsync(
615
- field: RawApiTypes.Field | ApiTypes.Field,
616
- value: unknown,
648
+ export async function nonRecursiveEveryBlockInNonLocalizedFieldValueAsync(
649
+ fieldType: ApiTypes.Field['field_type'],
650
+ nonLocalizedFieldValue: unknown,
617
651
  predicate: (item: BlockItemInARequest, path: TreePath) => Promise<boolean>,
618
652
  ): Promise<boolean> {
619
- return !(await nonRecursiveSomeBlocksInFieldValueAsync(
620
- field,
621
- value,
653
+ return !(await nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync(
654
+ fieldType,
655
+ nonLocalizedFieldValue,
622
656
  async (item, path) => {
623
657
  return !(await predicate(item, path));
624
658
  },