@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
@@ -19,6 +19,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
19
  export function isLocalized(field) {
20
20
  return 'attributes' in field ? field.attributes.localized : field.localized;
21
21
  }
22
+ export function isLocalizedFieldValue(value) {
23
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
24
+ return false;
25
+ }
26
+ const keys = Object.keys(value);
27
+ if (keys.length === 0) {
28
+ return false;
29
+ }
30
+ const localePattern = /^[A-Za-z]{2,4}(-[A-Za-z]{4})?(-([A-Za-z]{2}|[0-9]{3}))?$/;
31
+ return keys.every((key) => localePattern.test(key));
32
+ }
22
33
  /**
23
34
  * Converts a field value (localized or non-localized) into a uniform array of entries.
24
35
  *
@@ -29,7 +40,7 @@ export function isLocalized(field) {
29
40
  * @param value - The field value to convert (either a localized object or direct value)
30
41
  * @returns Array of entries where each entry contains a locale (string for localized, undefined for non-localized) and the corresponding value
31
42
  */
32
- export function fieldValueToEntries(field, value) {
43
+ export function toNormalizedFieldValueEntries(field, value) {
33
44
  if (isLocalized(field)) {
34
45
  const localizedValue = value;
35
46
  return Object.entries(localizedValue).map(([locale, value]) => ({
@@ -42,7 +53,7 @@ export function fieldValueToEntries(field, value) {
42
53
  /**
43
54
  * Converts an array of possibly localized entries back into the appropriate field value format.
44
55
  *
45
- * This function is the inverse of `fieldValueToEntries`. It takes a uniform
56
+ * This function is the inverse of `toNormalizedFieldValueEntries`. It takes a uniform
46
57
  * array of entries and converts them back to either a localized object or a direct value,
47
58
  * depending on the field's localization setting.
48
59
  *
@@ -50,7 +61,7 @@ export function fieldValueToEntries(field, value) {
50
61
  * @param entries - Array of entries to convert back to field value format
51
62
  * @returns Either a localized object (for localized fields) or the direct value (for non-localized fields)
52
63
  */
53
- export function entriesToFieldValue(field, entries) {
64
+ export function fromNormalizedFieldValueEntries(field, entries) {
54
65
  if (isLocalized(field)) {
55
66
  return Object.fromEntries(entries.map(({ locale, value }) => [locale, value]));
56
67
  }
@@ -70,13 +81,13 @@ export function entriesToFieldValue(field, entries) {
70
81
  * @param mapFn - The function to apply to each locale value or the direct value
71
82
  * @returns The mapped value with the same structure as the input
72
83
  */
73
- export function mapFieldValue(field, value, mapFn) {
74
- const entries = fieldValueToEntries(field, value);
84
+ export function mapNormalizedFieldValues(field, value, mapFn) {
85
+ const entries = toNormalizedFieldValueEntries(field, value);
75
86
  const mappedEntries = entries.map(({ locale, value }) => ({
76
87
  locale,
77
88
  value: mapFn(locale, value),
78
89
  }));
79
- return entriesToFieldValue(field, mappedEntries);
90
+ return fromNormalizedFieldValueEntries(field, mappedEntries);
80
91
  }
81
92
  /**
82
93
  * Maps field values using a provided mapping function (async version).
@@ -89,16 +100,16 @@ export function mapFieldValue(field, value, mapFn) {
89
100
  * @param mapFn - The function to apply to each locale value or the direct value
90
101
  * @returns The mapped value with the same structure as the input
91
102
  */
92
- export function mapFieldValueAsync(field, value, mapFn) {
103
+ export function mapNormalizedFieldValuesAsync(field, value, mapFn) {
93
104
  return __awaiter(this, void 0, void 0, function* () {
94
- const entries = fieldValueToEntries(field, value);
105
+ const entries = toNormalizedFieldValueEntries(field, value);
95
106
  const mappedEntries = yield Promise.all(entries.map(({ locale, value }) => __awaiter(this, void 0, void 0, function* () {
96
107
  return ({
97
108
  locale,
98
109
  value: yield mapFn(locale, value),
99
110
  });
100
111
  })));
101
- return entriesToFieldValue(field, mappedEntries);
112
+ return fromNormalizedFieldValueEntries(field, mappedEntries);
102
113
  });
103
114
  }
104
115
  /**
@@ -111,12 +122,12 @@ export function mapFieldValueAsync(field, value, mapFn) {
111
122
  * @param filterFn - The function to test each locale value or the direct value
112
123
  * @returns The filtered value with the same structure as the input
113
124
  */
114
- export function filterFieldValue(field, value, filterFn) {
125
+ export function filterNormalizedFieldValues(field, value, filterFn) {
115
126
  var _a;
116
- const entries = fieldValueToEntries(field, value);
127
+ const entries = toNormalizedFieldValueEntries(field, value);
117
128
  const filteredEntries = entries.filter((entry) => filterFn(entry.locale, entry.value));
118
129
  if (isLocalized(field)) {
119
- return entriesToFieldValue(field, filteredEntries);
130
+ return fromNormalizedFieldValueEntries(field, filteredEntries);
120
131
  }
121
132
  return filteredEntries.length > 0 ? (_a = filteredEntries[0]) === null || _a === void 0 ? void 0 : _a.value : undefined;
122
133
  }
@@ -130,10 +141,10 @@ export function filterFieldValue(field, value, filterFn) {
130
141
  * @param filterFn - The function to test each locale value or the direct value
131
142
  * @returns The filtered value with the same structure as the input
132
143
  */
133
- export function filterFieldValueAsync(field, value, filterFn) {
144
+ export function filterNormalizedFieldValuesAsync(field, value, filterFn) {
134
145
  var _a;
135
146
  return __awaiter(this, void 0, void 0, function* () {
136
- const entries = fieldValueToEntries(field, value);
147
+ const entries = toNormalizedFieldValueEntries(field, value);
137
148
  const results = yield Promise.all(entries.map(({ locale, value }) => __awaiter(this, void 0, void 0, function* () {
138
149
  return ({
139
150
  locale,
@@ -145,7 +156,7 @@ export function filterFieldValueAsync(field, value, filterFn) {
145
156
  .filter(({ passed }) => passed)
146
157
  .map(({ locale, value }) => ({ locale, value }));
147
158
  if (isLocalized(field)) {
148
- return entriesToFieldValue(field, filteredEntries);
159
+ return fromNormalizedFieldValueEntries(field, filteredEntries);
149
160
  }
150
161
  return filteredEntries.length > 0 ? (_a = filteredEntries[0]) === null || _a === void 0 ? void 0 : _a.value : undefined;
151
162
  });
@@ -160,8 +171,8 @@ export function filterFieldValueAsync(field, value, filterFn) {
160
171
  * @param testFn - The function to test each locale value or the direct value
161
172
  * @returns true if at least one value passes the test, false otherwise
162
173
  */
163
- export function someFieldValue(field, value, testFn) {
164
- const entries = fieldValueToEntries(field, value);
174
+ export function someNormalizedFieldValues(field, value, testFn) {
175
+ const entries = toNormalizedFieldValueEntries(field, value);
165
176
  return entries.some(({ locale, value }) => testFn(locale, value));
166
177
  }
167
178
  /**
@@ -174,9 +185,9 @@ export function someFieldValue(field, value, testFn) {
174
185
  * @param testFn - The function to test each locale value or the direct value
175
186
  * @returns true if at least one value passes the test, false otherwise
176
187
  */
177
- export function someFieldValueAsync(field, value, testFn) {
188
+ export function someNormalizedFieldValuesAsync(field, value, testFn) {
178
189
  return __awaiter(this, void 0, void 0, function* () {
179
- const entries = fieldValueToEntries(field, value);
190
+ const entries = toNormalizedFieldValueEntries(field, value);
180
191
  const results = yield Promise.all(entries.map(({ locale, value }) => testFn(locale, value)));
181
192
  return results.some((result) => result);
182
193
  });
@@ -191,8 +202,8 @@ export function someFieldValueAsync(field, value, testFn) {
191
202
  * @param testFn - The function to test each locale value or the direct value
192
203
  * @returns true if all values pass the test, false otherwise
193
204
  */
194
- export function everyFieldValue(field, value, testFn) {
195
- return !someFieldValue(field, value, (locale, localeValue) => !testFn(locale, localeValue));
205
+ export function everyNormalizedFieldValue(field, value, testFn) {
206
+ return !someNormalizedFieldValues(field, value, (locale, localeValue) => !testFn(locale, localeValue));
196
207
  }
197
208
  /**
198
209
  * Tests whether all field values pass the test implemented by the provided function (async version).
@@ -204,9 +215,9 @@ export function everyFieldValue(field, value, testFn) {
204
215
  * @param testFn - The function to test each locale value or the direct value
205
216
  * @returns true if all values pass the test, false otherwise
206
217
  */
207
- export function everyFieldValueAsync(field, value, testFn) {
218
+ export function everyNormalizedFieldValueAsync(field, value, testFn) {
208
219
  return __awaiter(this, void 0, void 0, function* () {
209
- return !(yield someFieldValueAsync(field, value, (locale, localeValue) => __awaiter(this, void 0, void 0, function* () { return !(yield testFn(locale, localeValue)); })));
220
+ return !(yield someNormalizedFieldValuesAsync(field, value, (locale, localeValue) => __awaiter(this, void 0, void 0, function* () { return !(yield testFn(locale, localeValue)); })));
210
221
  });
211
222
  }
212
223
  /**
@@ -218,8 +229,8 @@ export function everyFieldValueAsync(field, value, testFn) {
218
229
  * @param value - The field value (either localized object or direct value)
219
230
  * @param visitFn - The function to call for each locale value or the direct value
220
231
  */
221
- export function visitFieldValue(field, value, visitFn) {
222
- const entries = fieldValueToEntries(field, value);
232
+ export function visitNormalizedFieldValues(field, value, visitFn) {
233
+ const entries = toNormalizedFieldValueEntries(field, value);
223
234
  for (const { locale, value } of entries) {
224
235
  visitFn(locale, value);
225
236
  }
@@ -233,10 +244,10 @@ export function visitFieldValue(field, value, visitFn) {
233
244
  * @param value - The field value (either localized object or direct value)
234
245
  * @param visitFn - The function to call for each locale value or the direct value
235
246
  */
236
- export function visitFieldValueAsync(field, value, visitFn) {
247
+ export function visitNormalizedFieldValuesAsync(field, value, visitFn) {
237
248
  return __awaiter(this, void 0, void 0, function* () {
238
- const entries = fieldValueToEntries(field, value);
249
+ const entries = toNormalizedFieldValueEntries(field, value);
239
250
  yield Promise.all(entries.map(({ locale, value }) => visitFn(locale, value)));
240
251
  });
241
252
  }
242
- //# sourceMappingURL=fieldValue.js.map
253
+ //# sourceMappingURL=normalizedFieldValues.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizedFieldValues.js","sourceRoot":"","sources":["../../../src/utilities/normalizedFieldValues.ts"],"names":[],"mappings":";;;;;;;;;AAkCA;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CACzB,KAAyC;IAEzC,OAAO,YAAY,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,KAAc;IAEd,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACvE,OAAO,KAAK,CAAC;KACd;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAEhC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QACrB,OAAO,KAAK,CAAC;KACd;IAED,MAAM,aAAa,GACjB,0DAA0D,CAAC;IAE7D,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACtD,CAAC;AAkBD;;;;;;;;;GASG;AACH,MAAM,UAAU,6BAA6B,CAI3C,KAAyC,EACzC,KAAoC;IAEpC,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE;QACtB,MAAM,cAAc,GAAG,KAAkC,CAAC;QAE1D,OAAO,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YAC9D,MAAM,EAAE,MAAW;YACnB,KAAK,EAAE,KAAU;SAClB,CAAC,CAAC,CAAC;KACL;IAED,OAAO,CAAC,EAAE,MAAM,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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>;
@@ -8,11 +8,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { isItemWithOptionalIdAndMeta, } from '../fieldTypes';
11
- import { nonRecursiveFilterBlocksInFieldValueAsync, nonRecursiveFindAllBlocksInFieldValueAsync, nonRecursiveMapBlocksInFieldValueAsync, nonRecursiveReduceBlocksInFieldValueAsync, nonRecursiveSomeBlocksInFieldValueAsync, nonRecursiveVisitBlocksInFieldValueAsync, } from './blocks';
12
- import { mapFieldValueAsync, visitFieldValueAsync } from './fieldValue';
13
- export function visitBlocksInFieldValues(schemaRepository, field, value, visitor, path = []) {
11
+ import { nonRecursiveFilterBlocksInNonLocalizedFieldValueAsync, nonRecursiveFindAllBlocksInNonLocalizedFieldValueAsync, nonRecursiveMapBlocksInNonLocalizedFieldValueAsync, nonRecursiveReduceBlocksInNonLocalizedFieldValueAsync, nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync, nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync, } from './nonRecursiveBlocks';
12
+ /**
13
+ * Recursively visit every block in a non-localized field value and all nested blocks within those blocks.
14
+ * This function traverses not only the direct blocks in the non-localized field value but also recursively
15
+ * visits blocks contained within the attributes of each block, creating a complete traversal
16
+ * of the entire block hierarchy.
17
+ *
18
+ * @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
19
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
20
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to visit
21
+ * @param visitor - Asynchronous function called for each block found, including nested blocks
22
+ * @returns Promise that resolves when all blocks and nested blocks have been visited
23
+ */
24
+ export function visitBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, visitor, path = []) {
14
25
  return __awaiter(this, void 0, void 0, function* () {
15
- yield nonRecursiveVisitBlocksInFieldValueAsync(field, value, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
26
+ yield nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
16
27
  yield visitor(block, [...path, ...innerPath]);
17
28
  if (!isItemWithOptionalIdAndMeta(block)) {
18
29
  return;
@@ -20,50 +31,59 @@ export function visitBlocksInFieldValues(schemaRepository, field, value, visitor
20
31
  const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
21
32
  const fields = yield schemaRepository.getRawItemTypeFields(itemType);
22
33
  for (const field of fields) {
23
- yield visitFieldValueAsync(field, block.attributes[field.attributes.api_key], (locale, valueForLocale) => visitBlocksInFieldValues(schemaRepository, field, valueForLocale, visitor, [
24
- ...path,
25
- ...innerPath,
26
- 'attributes',
27
- field.attributes.api_key,
28
- ...(locale ? [locale] : []),
29
- ]));
34
+ yield visitBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, block.attributes[field.attributes.api_key], visitor, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
30
35
  }
31
36
  }));
32
37
  });
33
38
  }
34
- export function findAllBlocksInFieldValues(schemaRepository, field, value, predicate, path = []) {
39
+ /**
40
+ * Recursively find all blocks that match the predicate function in a non-localized field value.
41
+ * Searches through all direct blocks and recursively through nested blocks within
42
+ * the attributes of each block, returning all matches found throughout the hierarchy.
43
+ *
44
+ * @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
45
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
46
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to search
47
+ * @param predicate - Asynchronous function that tests each block, including nested ones
48
+ * @returns Promise that resolves to an array of objects, each containing a matching block and its full path
49
+ */
50
+ export function findAllBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, predicate, path = []) {
35
51
  return __awaiter(this, void 0, void 0, function* () {
36
52
  const results = [];
37
- const directMatches = yield nonRecursiveFindAllBlocksInFieldValueAsync(field, value, (block, innerPath) => __awaiter(this, void 0, void 0, function* () { return yield predicate(block, [...path, ...innerPath]); }));
53
+ const directMatches = yield nonRecursiveFindAllBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () { return yield predicate(block, [...path, ...innerPath]); }));
38
54
  results.push(...directMatches.map(({ item, path: innerPath }) => ({
39
55
  item,
40
56
  path: [...path, ...innerPath],
41
57
  })));
42
- yield nonRecursiveVisitBlocksInFieldValueAsync(field, value, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
58
+ yield nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
43
59
  if (!isItemWithOptionalIdAndMeta(block)) {
44
60
  return;
45
61
  }
46
62
  const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
47
63
  const fields = yield schemaRepository.getRawItemTypeFields(itemType);
48
64
  for (const field of fields) {
49
- yield visitFieldValueAsync(field, block.attributes[field.attributes.api_key], (locale, valueForLocale) => __awaiter(this, void 0, void 0, function* () {
50
- const nestedResults = yield findAllBlocksInFieldValues(schemaRepository, field, valueForLocale, predicate, [
51
- ...path,
52
- ...innerPath,
53
- 'attributes',
54
- field.attributes.api_key,
55
- ...(locale ? [locale] : []),
56
- ]);
57
- results.push(...nestedResults);
58
- }));
65
+ const nestedResults = yield findAllBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, block.attributes[field.attributes.api_key], predicate, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
66
+ results.push(...nestedResults);
59
67
  }
60
68
  }));
61
69
  return results;
62
70
  });
63
71
  }
64
- export function filterBlocksInFieldValues(schemaRepository, field, value, predicate, path = []) {
72
+ /**
73
+ * Recursively filter blocks in a non-localized field value, removing those that don't match the predicate.
74
+ * Creates a new non-localized field value structure containing only blocks that pass the predicate test,
75
+ * including recursive filtering of nested blocks within block attributes. The filtering
76
+ * preserves the original non-localized field value structure and hierarchy.
77
+ *
78
+ * @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
79
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
80
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to filter
81
+ * @param predicate - Asynchronous function that tests each block, including nested ones
82
+ * @returns Promise that resolves to the new non-localized field value with recursively filtered blocks
83
+ */
84
+ export function filterBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, predicate, path = []) {
65
85
  return __awaiter(this, void 0, void 0, function* () {
66
- return nonRecursiveFilterBlocksInFieldValueAsync(field, value, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
86
+ return nonRecursiveFilterBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
67
87
  const blockPath = [...path, ...innerPath];
68
88
  const passes = yield predicate(block, blockPath);
69
89
  if (!passes) {
@@ -75,49 +95,62 @@ export function filterBlocksInFieldValues(schemaRepository, field, value, predic
75
95
  const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
76
96
  const fields = yield schemaRepository.getRawItemTypeFields(itemType);
77
97
  for (const field of fields) {
78
- block.attributes[field.attributes.api_key] = yield mapFieldValueAsync(field, block.attributes[field.attributes.api_key], (locale, valueForLocale) => filterBlocksInFieldValues(schemaRepository, field, valueForLocale, predicate, [
79
- ...blockPath,
80
- 'attributes',
81
- field.attributes.api_key,
82
- ...(locale ? [locale] : []),
83
- ]));
98
+ block.attributes[field.attributes.api_key] =
99
+ yield filterBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, block.attributes[field.attributes.api_key], predicate, [...blockPath, 'attributes', field.attributes.api_key]);
84
100
  }
85
101
  return true;
86
102
  }));
87
103
  });
88
104
  }
89
- export function reduceBlocksInFieldValues(schemaRepository, field, value, reducer, initialValue, path = []) {
105
+ /**
106
+ * Recursively reduce all blocks in a non-localized field value to a single value by applying a reducer function.
107
+ * Processes each direct block and recursively processes nested blocks within block attributes,
108
+ * accumulating results from the entire block hierarchy into a single value.
109
+ *
110
+ * @template R - The type of the accumulated result
111
+ * @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
112
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
113
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to reduce
114
+ * @param reducer - Asynchronous function that processes each block and updates the accumulator
115
+ * @param initialNonLocalizedFieldValue - The initial value for the accumulator
116
+ * @returns Promise that resolves to the final accumulated value from all blocks in the hierarchy
117
+ */
118
+ export function reduceBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, reducer, initialValue, path = []) {
90
119
  return __awaiter(this, void 0, void 0, function* () {
91
- let accumulator = yield nonRecursiveReduceBlocksInFieldValueAsync(field, value, (acc, block, innerPath) => __awaiter(this, void 0, void 0, function* () { return yield reducer(acc, block, [...path, ...innerPath]); }), initialValue);
92
- yield nonRecursiveVisitBlocksInFieldValueAsync(field, value, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
120
+ let accumulator = yield nonRecursiveReduceBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (acc, block, innerPath) => __awaiter(this, void 0, void 0, function* () { return yield reducer(acc, block, [...path, ...innerPath]); }), initialValue);
121
+ yield nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
93
122
  if (!isItemWithOptionalIdAndMeta(block)) {
94
123
  return;
95
124
  }
96
125
  const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
97
126
  const fields = yield schemaRepository.getRawItemTypeFields(itemType);
98
127
  for (const field of fields) {
99
- yield visitFieldValueAsync(field, block.attributes[field.attributes.api_key], (locale, valueForLocale) => __awaiter(this, void 0, void 0, function* () {
100
- accumulator = yield reduceBlocksInFieldValues(schemaRepository, field, valueForLocale, reducer, accumulator, [
101
- ...path,
102
- ...innerPath,
103
- 'attributes',
104
- field.attributes.api_key,
105
- ...(locale ? [locale] : []),
106
- ]);
107
- }));
128
+ accumulator = yield reduceBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, block.attributes[field.attributes.api_key], reducer, accumulator, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
108
129
  }
109
130
  }));
110
131
  return accumulator;
111
132
  });
112
133
  }
113
- export function someBlocksInFieldValues(schemaRepository, field, value, predicate, path = []) {
134
+ /**
135
+ * Recursively check if any block in the non-localized field value matches the predicate function.
136
+ * Tests both direct blocks and recursively tests nested blocks within block attributes.
137
+ * Returns true as soon as the first matching block is found anywhere in the hierarchy
138
+ * (short-circuit evaluation).
139
+ *
140
+ * @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
141
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
142
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
143
+ * @param predicate - Asynchronous function that tests each block, including nested ones
144
+ * @returns Promise that resolves to true if any block in the hierarchy matches, false otherwise
145
+ */
146
+ export function someBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, predicate, path = []) {
114
147
  return __awaiter(this, void 0, void 0, function* () {
115
- const directMatch = yield nonRecursiveSomeBlocksInFieldValueAsync(field, value, (block, innerPath) => __awaiter(this, void 0, void 0, function* () { return yield predicate(block, [...path, ...innerPath]); }));
148
+ const directMatch = yield nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () { return yield predicate(block, [...path, ...innerPath]); }));
116
149
  if (directMatch) {
117
150
  return true;
118
151
  }
119
152
  let found = false;
120
- yield nonRecursiveVisitBlocksInFieldValueAsync(field, value, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
153
+ yield nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
121
154
  if (found || !isItemWithOptionalIdAndMeta(block)) {
122
155
  return;
123
156
  }
@@ -126,33 +159,47 @@ export function someBlocksInFieldValues(schemaRepository, field, value, predicat
126
159
  for (const field of fields) {
127
160
  if (found)
128
161
  break;
129
- yield visitFieldValueAsync(field, block.attributes[field.attributes.api_key], (locale, valueForLocale) => __awaiter(this, void 0, void 0, function* () {
130
- if (found)
131
- return;
132
- const nestedMatch = yield someBlocksInFieldValues(schemaRepository, field, valueForLocale, predicate, [
133
- ...path,
134
- ...innerPath,
135
- 'attributes',
136
- field.attributes.api_key,
137
- ...(locale ? [locale] : []),
138
- ]);
139
- if (nestedMatch) {
140
- found = true;
141
- }
142
- }));
162
+ const nestedMatch = yield someBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, block.attributes[field.attributes.api_key], predicate, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
163
+ if (nestedMatch) {
164
+ found = true;
165
+ }
143
166
  }
144
167
  }));
145
168
  return found;
146
169
  });
147
170
  }
148
- export function everyBlockInFieldValues(schemaRepository, field, value, predicate, path = []) {
171
+ /**
172
+ * Recursively check if every block in the non-localized field value matches the predicate function.
173
+ * Tests both direct blocks and recursively tests nested blocks within block attributes.
174
+ * Returns false as soon as the first non-matching block is found anywhere in the hierarchy
175
+ * (short-circuit evaluation).
176
+ *
177
+ * @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
178
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
179
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
180
+ * @param predicate - Asynchronous function that tests each block, including nested ones
181
+ * @returns Promise that resolves to true if all blocks in the hierarchy match, false otherwise
182
+ */
183
+ export function everyBlockInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, predicate, path = []) {
149
184
  return __awaiter(this, void 0, void 0, function* () {
150
- return !(yield someBlocksInFieldValues(schemaRepository, field, value, (item, path) => __awaiter(this, void 0, void 0, function* () { return !(yield predicate(item, path)); }), path));
185
+ return !(yield someBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, (item, path) => __awaiter(this, void 0, void 0, function* () { return !(yield predicate(item, path)); }), path));
151
186
  });
152
187
  }
153
- export function mapBlocksInFieldValues(schemaRepository, field, value, mapper, path = []) {
188
+ /**
189
+ * Recursively transform blocks in a non-localized field value by applying a mapping function to each block.
190
+ * Creates a new non-localized field value structure with transformed blocks while preserving the original
191
+ * structure. Applies the mapping function to both direct blocks and recursively to nested
192
+ * blocks within block attributes throughout the entire hierarchy.
193
+ *
194
+ * @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
195
+ * @param fieldType - The type of DatoCMS field definition that determines how the value is processed
196
+ * @param nonLocalizedFieldValue - The non-localized field value containing blocks to transform
197
+ * @param mapper - Asynchronous function that transforms each block, including nested ones
198
+ * @returns Promise that resolves to the new non-localized field value with recursively transformed blocks
199
+ */
200
+ export function mapBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, mapper, path = []) {
154
201
  return __awaiter(this, void 0, void 0, function* () {
155
- return nonRecursiveMapBlocksInFieldValueAsync(field, value, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
202
+ return nonRecursiveMapBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
156
203
  const newBlock = yield mapper(block, [...path, ...innerPath]);
157
204
  if (!isItemWithOptionalIdAndMeta(newBlock)) {
158
205
  return newBlock;
@@ -161,13 +208,7 @@ export function mapBlocksInFieldValues(schemaRepository, field, value, mapper, p
161
208
  const fields = yield schemaRepository.getRawItemTypeFields(itemType);
162
209
  for (const field of fields) {
163
210
  newBlock.attributes[field.attributes.api_key] =
164
- yield mapFieldValueAsync(field, newBlock.attributes[field.attributes.api_key], (locale, valueForLocale) => mapBlocksInFieldValues(schemaRepository, field, valueForLocale, mapper, [
165
- ...path,
166
- ...innerPath,
167
- 'attributes',
168
- field.attributes.api_key,
169
- ...(locale ? [locale] : []),
170
- ]));
211
+ yield mapBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, newBlock.attributes[field.attributes.api_key], mapper, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
171
212
  }
172
213
  return newBlock;
173
214
  }));