@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.
- package/README.md +575 -0
- package/dist/cjs/fieldTypes/boolean.js +2 -2
- package/dist/cjs/fieldTypes/boolean.js.map +1 -1
- package/dist/cjs/fieldTypes/color.js +2 -2
- package/dist/cjs/fieldTypes/color.js.map +1 -1
- package/dist/cjs/fieldTypes/date.js +2 -3
- package/dist/cjs/fieldTypes/date.js.map +1 -1
- package/dist/cjs/fieldTypes/date_time.js +2 -2
- package/dist/cjs/fieldTypes/date_time.js.map +1 -1
- package/dist/cjs/fieldTypes/file.js +33 -5
- package/dist/cjs/fieldTypes/file.js.map +1 -1
- package/dist/cjs/fieldTypes/float.js +2 -2
- package/dist/cjs/fieldTypes/float.js.map +1 -1
- package/dist/cjs/fieldTypes/gallery.js +20 -5
- package/dist/cjs/fieldTypes/gallery.js.map +1 -1
- package/dist/cjs/fieldTypes/index.js +2 -2
- package/dist/cjs/fieldTypes/index.js.map +1 -1
- package/dist/cjs/fieldTypes/integer.js +2 -2
- package/dist/cjs/fieldTypes/integer.js.map +1 -1
- package/dist/cjs/fieldTypes/json.js +2 -3
- package/dist/cjs/fieldTypes/json.js.map +1 -1
- package/dist/cjs/fieldTypes/lat_lon.js +2 -2
- package/dist/cjs/fieldTypes/lat_lon.js.map +1 -1
- package/dist/cjs/fieldTypes/link.js +4 -4
- package/dist/cjs/fieldTypes/link.js.map +1 -1
- package/dist/cjs/fieldTypes/links.js +5 -3
- package/dist/cjs/fieldTypes/links.js.map +1 -1
- package/dist/cjs/fieldTypes/rich_text.js +4 -6
- package/dist/cjs/fieldTypes/rich_text.js.map +1 -1
- package/dist/cjs/fieldTypes/seo.js +2 -3
- package/dist/cjs/fieldTypes/seo.js.map +1 -1
- package/dist/cjs/fieldTypes/single_block.js +7 -7
- package/dist/cjs/fieldTypes/single_block.js.map +1 -1
- package/dist/cjs/fieldTypes/slug.js +2 -3
- package/dist/cjs/fieldTypes/slug.js.map +1 -1
- package/dist/cjs/fieldTypes/string.js +2 -2
- package/dist/cjs/fieldTypes/string.js.map +1 -1
- package/dist/cjs/fieldTypes/structured_text.js +4 -6
- package/dist/cjs/fieldTypes/structured_text.js.map +1 -1
- package/dist/cjs/fieldTypes/text.js +2 -3
- package/dist/cjs/fieldTypes/text.js.map +1 -1
- package/dist/cjs/fieldTypes/video.js +2 -2
- package/dist/cjs/fieldTypes/video.js.map +1 -1
- package/dist/cjs/generated/Client.js +1 -1
- package/dist/cjs/generated/Client.js.map +1 -1
- package/dist/cjs/generated/resources/Item.js.map +1 -1
- package/dist/cjs/generated/resources/Upload.js.map +1 -1
- package/dist/cjs/index.js +4 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utilities/buildBlockRecord.js +8 -7
- package/dist/cjs/utilities/buildBlockRecord.js.map +1 -1
- package/dist/cjs/utilities/inspectItem.js +397 -0
- package/dist/cjs/utilities/inspectItem.js.map +1 -0
- package/dist/cjs/utilities/{blocks.js → nonRecursiveBlocks.js} +106 -111
- package/dist/cjs/utilities/nonRecursiveBlocks.js.map +1 -0
- package/dist/cjs/utilities/{fieldValue.js → normalizedFieldValues.js} +53 -41
- package/dist/cjs/utilities/normalizedFieldValues.js.map +1 -0
- package/dist/cjs/utilities/recursiveBlocks.js +121 -80
- package/dist/cjs/utilities/recursiveBlocks.js.map +1 -1
- package/dist/cjs/utilities/schemaRepository.js +2 -2
- package/dist/esm/fieldTypes/boolean.d.ts +1 -1
- package/dist/esm/fieldTypes/boolean.js +2 -2
- package/dist/esm/fieldTypes/boolean.js.map +1 -1
- package/dist/esm/fieldTypes/color.d.ts +1 -1
- package/dist/esm/fieldTypes/color.js +2 -2
- package/dist/esm/fieldTypes/color.js.map +1 -1
- package/dist/esm/fieldTypes/date.d.ts +1 -1
- package/dist/esm/fieldTypes/date.js +2 -3
- package/dist/esm/fieldTypes/date.js.map +1 -1
- package/dist/esm/fieldTypes/date_time.d.ts +1 -1
- package/dist/esm/fieldTypes/date_time.js +2 -2
- package/dist/esm/fieldTypes/date_time.js.map +1 -1
- package/dist/esm/fieldTypes/file.d.ts +68 -1
- package/dist/esm/fieldTypes/file.js +29 -3
- package/dist/esm/fieldTypes/file.js.map +1 -1
- package/dist/esm/fieldTypes/float.d.ts +1 -1
- package/dist/esm/fieldTypes/float.js +2 -2
- package/dist/esm/fieldTypes/float.js.map +1 -1
- package/dist/esm/fieldTypes/gallery.d.ts +27 -11
- package/dist/esm/fieldTypes/gallery.js +17 -4
- package/dist/esm/fieldTypes/gallery.js.map +1 -1
- package/dist/esm/fieldTypes/index.d.ts +2 -2
- package/dist/esm/fieldTypes/index.js +2 -2
- package/dist/esm/fieldTypes/index.js.map +1 -1
- package/dist/esm/fieldTypes/integer.d.ts +1 -1
- package/dist/esm/fieldTypes/integer.js +2 -2
- package/dist/esm/fieldTypes/integer.js.map +1 -1
- package/dist/esm/fieldTypes/json.d.ts +1 -1
- package/dist/esm/fieldTypes/json.js +2 -3
- package/dist/esm/fieldTypes/json.js.map +1 -1
- package/dist/esm/fieldTypes/lat_lon.d.ts +1 -1
- package/dist/esm/fieldTypes/lat_lon.js +2 -2
- package/dist/esm/fieldTypes/lat_lon.js.map +1 -1
- package/dist/esm/fieldTypes/link.d.ts +1 -1
- package/dist/esm/fieldTypes/link.js +4 -4
- package/dist/esm/fieldTypes/link.js.map +1 -1
- package/dist/esm/fieldTypes/links.d.ts +1 -1
- package/dist/esm/fieldTypes/links.js +5 -3
- package/dist/esm/fieldTypes/links.js.map +1 -1
- package/dist/esm/fieldTypes/rich_text.d.ts +1 -1
- package/dist/esm/fieldTypes/rich_text.js +4 -6
- package/dist/esm/fieldTypes/rich_text.js.map +1 -1
- package/dist/esm/fieldTypes/seo.d.ts +1 -1
- package/dist/esm/fieldTypes/seo.js +2 -3
- package/dist/esm/fieldTypes/seo.js.map +1 -1
- package/dist/esm/fieldTypes/single_block.d.ts +3 -3
- package/dist/esm/fieldTypes/single_block.js +7 -7
- package/dist/esm/fieldTypes/single_block.js.map +1 -1
- package/dist/esm/fieldTypes/slug.d.ts +1 -1
- package/dist/esm/fieldTypes/slug.js +2 -3
- package/dist/esm/fieldTypes/slug.js.map +1 -1
- package/dist/esm/fieldTypes/string.d.ts +1 -1
- package/dist/esm/fieldTypes/string.js +2 -2
- package/dist/esm/fieldTypes/string.js.map +1 -1
- package/dist/esm/fieldTypes/structured_text.d.ts +1 -1
- package/dist/esm/fieldTypes/structured_text.js +4 -6
- package/dist/esm/fieldTypes/structured_text.js.map +1 -1
- package/dist/esm/fieldTypes/text.d.ts +1 -1
- package/dist/esm/fieldTypes/text.js +2 -3
- package/dist/esm/fieldTypes/text.js.map +1 -1
- package/dist/esm/fieldTypes/video.d.ts +1 -1
- package/dist/esm/fieldTypes/video.js +2 -2
- package/dist/esm/fieldTypes/video.js.map +1 -1
- package/dist/esm/generated/Client.js +1 -1
- package/dist/esm/generated/Client.js.map +1 -1
- package/dist/esm/generated/resources/Item.d.ts +46 -28
- package/dist/esm/generated/resources/Item.js.map +1 -1
- package/dist/esm/generated/resources/ScheduledPublication.d.ts +3 -3
- package/dist/esm/generated/resources/ScheduledUnpublishing.d.ts +3 -3
- package/dist/esm/generated/resources/Upload.d.ts +10 -4
- package/dist/esm/generated/resources/Upload.js.map +1 -1
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utilities/buildBlockRecord.d.ts +3 -3
- package/dist/esm/utilities/buildBlockRecord.js +9 -8
- package/dist/esm/utilities/buildBlockRecord.js.map +1 -1
- package/dist/esm/utilities/inspectItem.d.ts +8 -0
- package/dist/esm/utilities/inspectItem.js +393 -0
- package/dist/esm/utilities/inspectItem.js.map +1 -0
- package/dist/esm/utilities/itemDefinition.d.ts +36 -12
- package/dist/esm/utilities/nonRecursiveBlocks.d.ts +179 -0
- package/dist/esm/utilities/{blocks.js → nonRecursiveBlocks.js} +91 -96
- package/dist/esm/utilities/nonRecursiveBlocks.js.map +1 -0
- package/dist/{types/utilities/fieldValue.d.ts → esm/utilities/normalizedFieldValues.d.ts} +15 -14
- package/dist/esm/utilities/{fieldValue.js → normalizedFieldValues.js} +39 -28
- package/dist/esm/utilities/normalizedFieldValues.js.map +1 -0
- package/dist/esm/utilities/recursiveBlocks.d.ts +92 -9
- package/dist/esm/utilities/recursiveBlocks.js +113 -72
- package/dist/esm/utilities/recursiveBlocks.js.map +1 -1
- package/dist/esm/utilities/schemaRepository.d.ts +2 -2
- package/dist/esm/utilities/schemaRepository.js +2 -2
- package/dist/types/fieldTypes/boolean.d.ts +1 -1
- package/dist/types/fieldTypes/color.d.ts +1 -1
- package/dist/types/fieldTypes/date.d.ts +1 -1
- package/dist/types/fieldTypes/date_time.d.ts +1 -1
- package/dist/types/fieldTypes/file.d.ts +68 -1
- package/dist/types/fieldTypes/float.d.ts +1 -1
- package/dist/types/fieldTypes/gallery.d.ts +27 -11
- package/dist/types/fieldTypes/index.d.ts +2 -2
- package/dist/types/fieldTypes/integer.d.ts +1 -1
- package/dist/types/fieldTypes/json.d.ts +1 -1
- package/dist/types/fieldTypes/lat_lon.d.ts +1 -1
- package/dist/types/fieldTypes/link.d.ts +1 -1
- package/dist/types/fieldTypes/links.d.ts +1 -1
- package/dist/types/fieldTypes/rich_text.d.ts +1 -1
- package/dist/types/fieldTypes/seo.d.ts +1 -1
- package/dist/types/fieldTypes/single_block.d.ts +3 -3
- package/dist/types/fieldTypes/slug.d.ts +1 -1
- package/dist/types/fieldTypes/string.d.ts +1 -1
- package/dist/types/fieldTypes/structured_text.d.ts +1 -1
- package/dist/types/fieldTypes/text.d.ts +1 -1
- package/dist/types/fieldTypes/video.d.ts +1 -1
- package/dist/types/generated/resources/Item.d.ts +46 -28
- package/dist/types/generated/resources/ScheduledPublication.d.ts +3 -3
- package/dist/types/generated/resources/ScheduledUnpublishing.d.ts +3 -3
- package/dist/types/generated/resources/Upload.d.ts +10 -4
- package/dist/types/index.d.ts +4 -4
- package/dist/types/utilities/buildBlockRecord.d.ts +3 -3
- package/dist/types/utilities/inspectItem.d.ts +8 -0
- package/dist/types/utilities/itemDefinition.d.ts +36 -12
- package/dist/types/utilities/nonRecursiveBlocks.d.ts +179 -0
- package/dist/{esm/utilities/fieldValue.d.ts → types/utilities/normalizedFieldValues.d.ts} +15 -14
- package/dist/types/utilities/recursiveBlocks.d.ts +92 -9
- package/dist/types/utilities/schemaRepository.d.ts +2 -2
- package/package.json +4 -4
- package/src/fieldTypes/boolean.ts +5 -3
- package/src/fieldTypes/color.ts +5 -3
- package/src/fieldTypes/date.ts +5 -4
- package/src/fieldTypes/date_time.ts +5 -3
- package/src/fieldTypes/file.ts +98 -4
- package/src/fieldTypes/float.ts +5 -3
- package/src/fieldTypes/gallery.ts +53 -20
- package/src/fieldTypes/index.ts +2 -3
- package/src/fieldTypes/integer.ts +5 -3
- package/src/fieldTypes/json.ts +5 -4
- package/src/fieldTypes/lat_lon.ts +5 -3
- package/src/fieldTypes/link.ts +7 -5
- package/src/fieldTypes/links.ts +8 -4
- package/src/fieldTypes/rich_text.ts +7 -7
- package/src/fieldTypes/seo.ts +5 -4
- package/src/fieldTypes/single_block.ts +12 -10
- package/src/fieldTypes/slug.ts +5 -4
- package/src/fieldTypes/string.ts +5 -3
- package/src/fieldTypes/structured_text.ts +7 -7
- package/src/fieldTypes/text.ts +5 -4
- package/src/fieldTypes/video.ts +5 -3
- package/src/generated/Client.ts +1 -1
- package/src/generated/resources/Item.ts +129 -92
- package/src/generated/resources/ScheduledPublication.ts +6 -6
- package/src/generated/resources/ScheduledUnpublishing.ts +6 -6
- package/src/generated/resources/Upload.ts +36 -10
- package/src/index.ts +4 -4
- package/src/utilities/buildBlockRecord.ts +24 -31
- package/src/utilities/inspectItem.ts +590 -0
- package/src/utilities/itemDefinition.ts +53 -35
- package/src/utilities/{blocks.ts → nonRecursiveBlocks.ts} +170 -136
- package/src/utilities/{fieldValue.ts → normalizedFieldValues.ts} +70 -30
- package/src/utilities/recursiveBlocks.ts +186 -171
- package/src/utilities/schemaRepository.ts +2 -2
- package/dist/cjs/utilities/blocks.js.map +0 -1
- package/dist/cjs/utilities/fieldValue.js.map +0 -1
- package/dist/esm/utilities/blocks.d.ts +0 -180
- package/dist/esm/utilities/blocks.js.map +0 -1
- package/dist/esm/utilities/fieldValue.js.map +0 -1
- 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
|
|
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
|
-
|
|
68
|
-
|
|
63
|
+
fieldType: ApiTypes.Field['field_type'],
|
|
64
|
+
nonLocalizedFieldValue: unknown,
|
|
69
65
|
): Generator<{ item: BlockItemInARequest; path: TreePath }> {
|
|
70
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
111
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
|
157
|
-
* @param
|
|
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
|
|
161
|
-
|
|
162
|
-
|
|
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(
|
|
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
|
|
175
|
-
* @param
|
|
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
|
|
180
|
-
|
|
181
|
-
|
|
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(
|
|
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
|
|
195
|
-
* @param
|
|
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
|
|
200
|
-
|
|
201
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
|
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
|
|
249
|
-
* @param
|
|
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
|
|
254
|
-
|
|
255
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
|
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
|
|
307
|
-
* @param
|
|
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
|
|
312
|
-
|
|
313
|
-
|
|
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(
|
|
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
|
|
332
|
-
* @param
|
|
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
|
|
337
|
-
|
|
338
|
-
|
|
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(
|
|
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
|
|
358
|
-
* @param
|
|
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
|
|
363
|
-
|
|
364
|
-
|
|
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(
|
|
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
|
|
387
|
+
return filteredItems;
|
|
379
388
|
}
|
|
380
389
|
|
|
381
390
|
if (fieldType === 'single_block') {
|
|
382
|
-
for (const { item, path } of iterateBlocks(
|
|
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 =
|
|
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
|
|
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
|
|
424
|
-
* @param
|
|
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
|
|
429
|
-
|
|
430
|
-
|
|
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(
|
|
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
|
|
458
|
+
return filteredItems;
|
|
445
459
|
}
|
|
446
460
|
|
|
447
461
|
if (fieldType === 'single_block') {
|
|
448
|
-
for await (const { item, path } of iterateBlocksAsync(
|
|
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 =
|
|
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
|
|
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
|
|
490
|
-
* @param
|
|
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
|
|
496
|
-
|
|
497
|
-
|
|
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(
|
|
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
|
|
516
|
-
* @param
|
|
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
|
|
522
|
-
|
|
523
|
-
|
|
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(
|
|
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
|
|
545
|
-
* @param
|
|
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
|
|
550
|
-
|
|
551
|
-
|
|
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(
|
|
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
|
|
568
|
-
* @param
|
|
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
|
|
573
|
-
|
|
574
|
-
|
|
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(
|
|
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
|
|
591
|
-
* @param
|
|
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
|
|
596
|
-
|
|
597
|
-
|
|
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 !
|
|
601
|
-
|
|
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
|
|
610
|
-
* @param
|
|
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
|
|
615
|
-
|
|
616
|
-
|
|
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
|
|
620
|
-
|
|
621
|
-
|
|
653
|
+
return !(await nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync(
|
|
654
|
+
fieldType,
|
|
655
|
+
nonLocalizedFieldValue,
|
|
622
656
|
async (item, path) => {
|
|
623
657
|
return !(await predicate(item, path));
|
|
624
658
|
},
|