@datocms/cma-client 5.1.11 → 5.1.13
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 +313 -178
- package/dist/cjs/fieldTypes/file.js +6 -6
- package/dist/cjs/fieldTypes/gallery.js +7 -7
- package/dist/cjs/fieldTypes/rich_text.js +14 -12
- package/dist/cjs/fieldTypes/rich_text.js.map +1 -1
- package/dist/cjs/fieldTypes/schema.js +3 -0
- package/dist/cjs/fieldTypes/schema.js.map +1 -0
- package/dist/cjs/fieldTypes/single_block.js +13 -12
- package/dist/cjs/fieldTypes/single_block.js.map +1 -1
- package/dist/cjs/fieldTypes/structured_text.js +13 -12
- package/dist/cjs/fieldTypes/structured_text.js.map +1 -1
- package/dist/cjs/generated/Client.js +1 -1
- package/dist/cjs/generated/resources/Item.js.map +1 -1
- package/dist/cjs/generated/resources/ScheduledPublication.js.map +1 -1
- package/dist/cjs/generated/resources/ScheduledUnpublishing.js.map +1 -1
- package/dist/cjs/generated/resources/Upload.js.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utilities/buildBlockRecord.js +1 -46
- package/dist/cjs/utilities/buildBlockRecord.js.map +1 -1
- package/dist/cjs/utilities/duplicateBlockRecord.js +50 -0
- package/dist/cjs/utilities/duplicateBlockRecord.js.map +1 -0
- package/dist/cjs/utilities/inspectItem.js +50 -20
- package/dist/cjs/utilities/inspectItem.js.map +1 -1
- package/dist/cjs/utilities/nonRecursiveBlocks.js +1 -170
- package/dist/cjs/utilities/nonRecursiveBlocks.js.map +1 -1
- package/dist/cjs/utilities/recursiveBlocks.js +52 -112
- package/dist/cjs/utilities/recursiveBlocks.js.map +1 -1
- package/dist/esm/fieldTypes/file.d.ts +3 -3
- package/dist/esm/fieldTypes/file.js +3 -3
- package/dist/esm/fieldTypes/gallery.d.ts +5 -5
- package/dist/esm/fieldTypes/gallery.js +5 -5
- package/dist/esm/fieldTypes/rich_text.d.ts +8 -9
- package/dist/esm/fieldTypes/rich_text.js +9 -7
- package/dist/esm/fieldTypes/rich_text.js.map +1 -1
- package/dist/esm/fieldTypes/schema.d.ts +59 -0
- package/dist/esm/fieldTypes/schema.js +2 -0
- package/dist/esm/fieldTypes/schema.js.map +1 -0
- package/dist/esm/fieldTypes/single_block.d.ts +30 -15
- package/dist/esm/fieldTypes/single_block.js +8 -7
- package/dist/esm/fieldTypes/single_block.js.map +1 -1
- package/dist/esm/fieldTypes/structured_text.d.ts +14 -15
- package/dist/esm/fieldTypes/structured_text.js +8 -7
- package/dist/esm/fieldTypes/structured_text.js.map +1 -1
- package/dist/esm/generated/ApiTypes.d.ts +94 -980
- package/dist/esm/generated/Client.js +1 -1
- package/dist/esm/generated/RawApiTypes.d.ts +160 -999
- package/dist/esm/generated/resources/Field.d.ts +300 -300
- package/dist/esm/generated/resources/Item.d.ts +34 -34
- package/dist/esm/generated/resources/Item.js.map +1 -1
- package/dist/esm/generated/resources/ItemVersion.d.ts +3 -1
- package/dist/esm/generated/resources/ScheduledPublication.d.ts +3 -3
- package/dist/esm/generated/resources/ScheduledPublication.js.map +1 -1
- package/dist/esm/generated/resources/ScheduledUnpublishing.d.ts +3 -3
- package/dist/esm/generated/resources/ScheduledUnpublishing.js.map +1 -1
- package/dist/esm/generated/resources/Upload.d.ts +6 -6
- package/dist/esm/generated/resources/Upload.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utilities/buildBlockRecord.d.ts +11 -5
- package/dist/esm/utilities/buildBlockRecord.js +0 -44
- package/dist/esm/utilities/buildBlockRecord.js.map +1 -1
- package/dist/esm/utilities/duplicateBlockRecord.d.ts +6 -0
- package/dist/esm/utilities/duplicateBlockRecord.js +46 -0
- package/dist/esm/utilities/duplicateBlockRecord.js.map +1 -0
- package/dist/esm/utilities/inspectItem.d.ts +3 -3
- package/dist/esm/utilities/inspectItem.js +28 -21
- package/dist/esm/utilities/inspectItem.js.map +1 -1
- package/dist/esm/utilities/itemDefinition.d.ts +25 -27
- package/dist/esm/utilities/nonRecursiveBlocks.d.ts +10 -75
- package/dist/esm/utilities/nonRecursiveBlocks.js +1 -164
- package/dist/esm/utilities/nonRecursiveBlocks.js.map +1 -1
- package/dist/esm/utilities/recursiveBlocks.d.ts +53 -23
- package/dist/esm/utilities/recursiveBlocks.js +52 -112
- package/dist/esm/utilities/recursiveBlocks.js.map +1 -1
- package/dist/types/fieldTypes/file.d.ts +3 -3
- package/dist/types/fieldTypes/gallery.d.ts +5 -5
- package/dist/types/fieldTypes/rich_text.d.ts +8 -9
- package/dist/types/fieldTypes/schema.d.ts +59 -0
- package/dist/types/fieldTypes/single_block.d.ts +30 -15
- package/dist/types/fieldTypes/structured_text.d.ts +14 -15
- package/dist/types/generated/ApiTypes.d.ts +94 -980
- package/dist/types/generated/RawApiTypes.d.ts +160 -999
- package/dist/types/generated/resources/Field.d.ts +300 -300
- package/dist/types/generated/resources/Item.d.ts +34 -34
- package/dist/types/generated/resources/ItemVersion.d.ts +3 -1
- 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 +6 -6
- package/dist/types/index.d.ts +1 -0
- package/dist/types/utilities/buildBlockRecord.d.ts +11 -5
- package/dist/types/utilities/duplicateBlockRecord.d.ts +6 -0
- package/dist/types/utilities/inspectItem.d.ts +3 -3
- package/dist/types/utilities/itemDefinition.d.ts +25 -27
- package/dist/types/utilities/nonRecursiveBlocks.d.ts +10 -75
- package/dist/types/utilities/recursiveBlocks.d.ts +53 -23
- package/package.json +4 -4
- package/src/fieldTypes/file.ts +6 -6
- package/src/fieldTypes/gallery.ts +10 -10
- package/src/fieldTypes/rich_text.ts +26 -24
- package/src/fieldTypes/schema.ts +657 -0
- package/src/fieldTypes/single_block.ts +61 -38
- package/src/fieldTypes/structured_text.ts +57 -51
- package/src/generated/ApiTypes.ts +221 -1880
- package/src/generated/Client.ts +1 -1
- package/src/generated/RawApiTypes.ts +276 -2113
- package/src/generated/resources/Item.ts +93 -187
- package/src/generated/resources/ScheduledPublication.ts +4 -15
- package/src/generated/resources/ScheduledUnpublishing.ts +4 -15
- package/src/generated/resources/Upload.ts +9 -32
- package/src/index.ts +1 -0
- package/src/utilities/buildBlockRecord.ts +16 -56
- package/src/utilities/duplicateBlockRecord.ts +53 -0
- package/src/utilities/inspectItem.ts +64 -52
- package/src/utilities/itemDefinition.ts +109 -98
- package/src/utilities/nonRecursiveBlocks.ts +25 -279
- package/src/utilities/recursiveBlocks.ts +337 -72
|
@@ -49,42 +49,7 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
49
49
|
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
50
50
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
51
51
|
};
|
|
52
|
-
import {
|
|
53
|
-
import { isLocalizedFieldValue } from './normalizedFieldValues';
|
|
54
|
-
function* iterateBlocks(fieldType, nonLocalizedFieldValue) {
|
|
55
|
-
if (isLocalizedFieldValue(nonLocalizedFieldValue)) {
|
|
56
|
-
throw new Error('A non-localized field value is required!');
|
|
57
|
-
}
|
|
58
|
-
if (fieldType === 'rich_text') {
|
|
59
|
-
const richTextValue = nonLocalizedFieldValue;
|
|
60
|
-
if (richTextValue) {
|
|
61
|
-
for (let index = 0; index < richTextValue.length; index++) {
|
|
62
|
-
const item = richTextValue[index];
|
|
63
|
-
yield { item, path: [index] };
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if (fieldType === 'single_block') {
|
|
69
|
-
const singleBlockValue = nonLocalizedFieldValue;
|
|
70
|
-
if (singleBlockValue) {
|
|
71
|
-
yield { item: singleBlockValue, path: [] };
|
|
72
|
-
}
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
if (fieldType === 'structured_text') {
|
|
76
|
-
const structuredTextValue = nonLocalizedFieldValue;
|
|
77
|
-
if (structuredTextValue) {
|
|
78
|
-
const foundNodes = collectNodes(structuredTextValue.document, (node) => node.type === 'block' || node.type === 'inlineBlock');
|
|
79
|
-
for (const { node, path } of foundNodes) {
|
|
80
|
-
if (node.type === 'block' || node.type === 'inlineBlock') {
|
|
81
|
-
yield { item: node.item, path };
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
52
|
+
import { collectNodesAsync, filterNodesAsync, mapNodes, mapNodesAsync, } from 'datocms-structured-text-utils';
|
|
88
53
|
function iterateBlocksAsync(fieldType, nonLocalizedFieldValue) {
|
|
89
54
|
return __asyncGenerator(this, arguments, function* iterateBlocksAsync_1() {
|
|
90
55
|
if (fieldType === 'rich_text') {
|
|
@@ -118,19 +83,6 @@ function iterateBlocksAsync(fieldType, nonLocalizedFieldValue) {
|
|
|
118
83
|
}
|
|
119
84
|
});
|
|
120
85
|
}
|
|
121
|
-
/**
|
|
122
|
-
* Visit every block in a field value, calling the visitor function for each block found.
|
|
123
|
-
* Supports rich text, single block, and structured text field types.
|
|
124
|
-
*
|
|
125
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
126
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to visit
|
|
127
|
-
* @param visitor - Synchronous function called for each block. Receives the block item and its path
|
|
128
|
-
*/
|
|
129
|
-
export function nonRecursiveVisitBlocksInNonLocalizedFieldValue(fieldType, nonLocalizedFieldValue, visitor) {
|
|
130
|
-
for (const { item, path } of iterateBlocks(fieldType, nonLocalizedFieldValue)) {
|
|
131
|
-
visitor(item, path);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
86
|
/**
|
|
135
87
|
* Visit every block in a field value, calling the visitor function for each block found.
|
|
136
88
|
* Supports rich text, single block, and structured text field types.
|
|
@@ -243,24 +195,6 @@ export function nonRecursiveMapBlocksInNonLocalizedFieldValueAsync(fieldType, no
|
|
|
243
195
|
return nonLocalizedFieldValue;
|
|
244
196
|
});
|
|
245
197
|
}
|
|
246
|
-
/**
|
|
247
|
-
* Find all blocks that match the predicate function.
|
|
248
|
-
* Searches through all blocks in the non-localized field value and returns all matches.
|
|
249
|
-
*
|
|
250
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
251
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to search
|
|
252
|
-
* @param predicate - Synchronous function that tests each block. Should return true for matching blocks
|
|
253
|
-
* @returns Array of objects, each containing a matching block and its path
|
|
254
|
-
*/
|
|
255
|
-
export function nonRecursiveFindAllBlocksInNonLocalizedFieldValue(fieldType, nonLocalizedFieldValue, predicate) {
|
|
256
|
-
const results = [];
|
|
257
|
-
for (const { item, path } of iterateBlocks(fieldType, nonLocalizedFieldValue)) {
|
|
258
|
-
if (predicate(item, path)) {
|
|
259
|
-
results.push({ item, path });
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return results;
|
|
263
|
-
}
|
|
264
198
|
/**
|
|
265
199
|
* Find all blocks that match the predicate function.
|
|
266
200
|
* Searches through all blocks in the non-localized field value and returns all matches.
|
|
@@ -299,54 +233,6 @@ export function nonRecursiveFindAllBlocksInNonLocalizedFieldValueAsync(fieldType
|
|
|
299
233
|
return results;
|
|
300
234
|
});
|
|
301
235
|
}
|
|
302
|
-
/**
|
|
303
|
-
* Filter blocks in a field value, removing those that don't match the predicate.
|
|
304
|
-
* Creates a new field value containing only blocks that pass the predicate test.
|
|
305
|
-
* Preserves the original field value structure and hierarchy.
|
|
306
|
-
*
|
|
307
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
308
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to filter
|
|
309
|
-
* @param predicate - Synchronous function that tests each block. Blocks returning false are removed
|
|
310
|
-
* @returns The new field value with filtered blocks
|
|
311
|
-
*/
|
|
312
|
-
export function nonRecursiveFilterBlocksInNonLocalizedFieldValue(fieldType, nonLocalizedFieldValue, predicate) {
|
|
313
|
-
if (fieldType === 'rich_text') {
|
|
314
|
-
const filteredItems = [];
|
|
315
|
-
for (const { item, path } of iterateBlocks(fieldType, nonLocalizedFieldValue)) {
|
|
316
|
-
if (predicate(item, path)) {
|
|
317
|
-
filteredItems.push(item);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
return filteredItems;
|
|
321
|
-
}
|
|
322
|
-
if (fieldType === 'single_block') {
|
|
323
|
-
for (const { item, path } of iterateBlocks(fieldType, nonLocalizedFieldValue)) {
|
|
324
|
-
if (predicate(item, path)) {
|
|
325
|
-
return item;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
return null;
|
|
329
|
-
}
|
|
330
|
-
if (fieldType === 'structured_text') {
|
|
331
|
-
const structuredTextValue = nonLocalizedFieldValue;
|
|
332
|
-
if (!structuredTextValue) {
|
|
333
|
-
return null;
|
|
334
|
-
}
|
|
335
|
-
const filteredDocument = filterNodes(structuredTextValue.document, (node, _parent, path) => {
|
|
336
|
-
if (node.type === 'block' || node.type === 'inlineBlock') {
|
|
337
|
-
return predicate(node.item, path);
|
|
338
|
-
}
|
|
339
|
-
return true;
|
|
340
|
-
});
|
|
341
|
-
return filteredDocument
|
|
342
|
-
? {
|
|
343
|
-
schema: 'dast',
|
|
344
|
-
document: filteredDocument,
|
|
345
|
-
}
|
|
346
|
-
: null;
|
|
347
|
-
}
|
|
348
|
-
return nonLocalizedFieldValue;
|
|
349
|
-
}
|
|
350
236
|
/**
|
|
351
237
|
* Filter blocks in a field value, removing those that don't match the predicate.
|
|
352
238
|
* Creates a new field value containing only blocks that pass the predicate test.
|
|
@@ -432,24 +318,6 @@ export function nonRecursiveFilterBlocksInNonLocalizedFieldValueAsync(fieldType,
|
|
|
432
318
|
return nonLocalizedFieldValue;
|
|
433
319
|
});
|
|
434
320
|
}
|
|
435
|
-
/**
|
|
436
|
-
* Reduce all blocks in a field value to a single value by applying a reducer function.
|
|
437
|
-
* Processes each block in the non-localized field value and accumulates the results into a single value.
|
|
438
|
-
*
|
|
439
|
-
* @template R - The type of the accumulated result
|
|
440
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
441
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to reduce
|
|
442
|
-
* @param reducer - Synchronous function that processes each block and updates the accumulator
|
|
443
|
-
* @param initialValue - The initial value for the accumulator
|
|
444
|
-
* @returns The final accumulated value
|
|
445
|
-
*/
|
|
446
|
-
export function nonRecursiveReduceBlocksInNonLocalizedFieldValue(fieldType, nonLocalizedFieldValue, reducer, initialValue) {
|
|
447
|
-
let accumulator = initialValue;
|
|
448
|
-
for (const { item, path } of iterateBlocks(fieldType, nonLocalizedFieldValue)) {
|
|
449
|
-
accumulator = reducer(accumulator, item, path);
|
|
450
|
-
}
|
|
451
|
-
return accumulator;
|
|
452
|
-
}
|
|
453
321
|
/**
|
|
454
322
|
* Reduce all blocks in a field value to a single value by applying a reducer function.
|
|
455
323
|
* Processes each block in the non-localized field value and accumulates the results into a single value.
|
|
@@ -488,23 +356,6 @@ export function nonRecursiveReduceBlocksInNonLocalizedFieldValueAsync(fieldType,
|
|
|
488
356
|
return accumulator;
|
|
489
357
|
});
|
|
490
358
|
}
|
|
491
|
-
/**
|
|
492
|
-
* Check if any block in the non-localized field value matches the predicate function.
|
|
493
|
-
* Returns true as soon as the first matching block is found (short-circuit evaluation).
|
|
494
|
-
*
|
|
495
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
496
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
|
|
497
|
-
* @param predicate - Synchronous function that tests each block. Should return true for matching blocks
|
|
498
|
-
* @returns True if any block matches, false otherwise
|
|
499
|
-
*/
|
|
500
|
-
export function nonRecursiveSomeBlocksInNonLocalizedFieldValue(fieldType, nonLocalizedFieldValue, predicate) {
|
|
501
|
-
for (const { item, path } of iterateBlocks(fieldType, nonLocalizedFieldValue)) {
|
|
502
|
-
if (predicate(item, path)) {
|
|
503
|
-
return true;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
return false;
|
|
507
|
-
}
|
|
508
359
|
/**
|
|
509
360
|
* Check if any block in the non-localized field value matches the predicate function.
|
|
510
361
|
* Returns true as soon as the first matching block is found (short-circuit evaluation).
|
|
@@ -542,20 +393,6 @@ export function nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync(fieldType, n
|
|
|
542
393
|
return false;
|
|
543
394
|
});
|
|
544
395
|
}
|
|
545
|
-
/**
|
|
546
|
-
* Check if every block in the non-localized field value matches the predicate function.
|
|
547
|
-
* Returns false as soon as the first non-matching block is found (short-circuit evaluation).
|
|
548
|
-
*
|
|
549
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
550
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
|
|
551
|
-
* @param predicate - Synchronous function that tests each block. Should return true for valid blocks
|
|
552
|
-
* @returns True if all blocks match, false otherwise
|
|
553
|
-
*/
|
|
554
|
-
export function nonRecursiveEveryBlockInNonLocalizedFieldValue(fieldType, nonLocalizedFieldValue, predicate) {
|
|
555
|
-
return !nonRecursiveSomeBlocksInNonLocalizedFieldValue(fieldType, nonLocalizedFieldValue, (item, path) => {
|
|
556
|
-
return !predicate(item, path);
|
|
557
|
-
});
|
|
558
|
-
}
|
|
559
396
|
/**
|
|
560
397
|
* Check if every block in the non-localized field value matches the predicate function.
|
|
561
398
|
* Returns false as soon as the first non-matching block is found (short-circuit evaluation).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nonRecursiveBlocks.js","sourceRoot":"","sources":["../../../src/utilities/nonRecursiveBlocks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;;;;;;;;;;;;;;;;;;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|
1
|
+
import { type BlockInRequest, type RichTextFieldValue, type RichTextFieldValueInNestedResponse, type RichTextFieldValueInRequest, type SingleBlockFieldValue, type SingleBlockFieldValueInNestedResponse, type SingleBlockFieldValueInRequest, type StructuredTextFieldValue, type StructuredTextFieldValueInNestedResponse, type StructuredTextFieldValueInRequest } from '../fieldTypes';
|
|
2
2
|
import type * as ApiTypes from '../generated/ApiTypes';
|
|
3
|
+
import type { ExtractNestedBlocksFromFieldValue } from './itemDefinition';
|
|
3
4
|
import type { SchemaRepository } from './schemaRepository';
|
|
5
|
+
type RecognizableFieldValue = RichTextFieldValueInNestedResponse | SingleBlockFieldValueInNestedResponse | StructuredTextFieldValueInNestedResponse | RichTextFieldValueInRequest | SingleBlockFieldValueInRequest | StructuredTextFieldValueInRequest | RichTextFieldValue | SingleBlockFieldValue | StructuredTextFieldValue;
|
|
4
6
|
/**
|
|
5
7
|
* Path through a non-localized field value (ie. ['content', 0, 'attributes', 'title'])
|
|
6
8
|
*/
|
|
7
9
|
export type TreePath = readonly (string | number)[];
|
|
10
|
+
/**
|
|
11
|
+
* Traversal direction for recursive operations
|
|
12
|
+
*/
|
|
13
|
+
export type TraversalDirection = 'top-down' | 'bottom-up';
|
|
8
14
|
/**
|
|
9
15
|
* Recursively visit every block in a non-localized field value and all nested blocks within those blocks.
|
|
10
16
|
* This function traverses not only the direct blocks in the non-localized field value but also recursively
|
|
11
17
|
* visits blocks contained within the attributes of each block, creating a complete traversal
|
|
12
18
|
* of the entire block hierarchy.
|
|
13
19
|
*
|
|
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
20
|
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to visit
|
|
21
|
+
* @param fieldType - The type field (determines how the value is processed)
|
|
22
|
+
* @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
|
|
17
23
|
* @param visitor - Asynchronous function called for each block found, including nested blocks
|
|
18
24
|
* @returns Promise that resolves when all blocks and nested blocks have been visited
|
|
19
25
|
*/
|
|
20
|
-
export declare function visitBlocksInNonLocalizedFieldValue(
|
|
26
|
+
export declare function visitBlocksInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, visitor: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => void | Promise<void>, path?: TreePath): Promise<void>;
|
|
27
|
+
export declare function visitBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, visitor: (item: BlockInRequest, path: TreePath) => void | Promise<void>, path?: TreePath): Promise<void>;
|
|
21
28
|
/**
|
|
22
29
|
* Recursively find all blocks that match the predicate function in a non-localized field value.
|
|
23
30
|
* Searches through all direct blocks and recursively through nested blocks within
|
|
24
31
|
* the attributes of each block, returning all matches found throughout the hierarchy.
|
|
25
32
|
*
|
|
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
33
|
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to search
|
|
34
|
+
* @param fieldType - The type field (determines how the value is processed)
|
|
35
|
+
* @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
|
|
29
36
|
* @param predicate - Asynchronous function that tests each block, including nested ones
|
|
30
37
|
* @returns Promise that resolves to an array of objects, each containing a matching block and its full path
|
|
31
38
|
*/
|
|
32
|
-
export declare function findAllBlocksInNonLocalizedFieldValue(
|
|
33
|
-
item:
|
|
39
|
+
export declare function findAllBlocksInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<Array<{
|
|
40
|
+
item: ExtractNestedBlocksFromFieldValue<T>;
|
|
41
|
+
path: TreePath;
|
|
42
|
+
}>>;
|
|
43
|
+
export declare function findAllBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: BlockInRequest, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<Array<{
|
|
44
|
+
item: BlockInRequest;
|
|
34
45
|
path: TreePath;
|
|
35
46
|
}>>;
|
|
36
47
|
/**
|
|
@@ -39,63 +50,82 @@ export declare function findAllBlocksInNonLocalizedFieldValue(schemaRepository:
|
|
|
39
50
|
* including recursive filtering of nested blocks within block attributes. The filtering
|
|
40
51
|
* preserves the original non-localized field value structure and hierarchy.
|
|
41
52
|
*
|
|
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
53
|
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to filter
|
|
54
|
+
* @param fieldType - The type field (determines how the value is processed)
|
|
55
|
+
* @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
|
|
45
56
|
* @param predicate - Asynchronous function that tests each block, including nested ones
|
|
57
|
+
* @param options - Optional configuration object
|
|
58
|
+
* @param options.traversalDirection - Direction of traversal: 'top-down' (default) applies predicate before processing children, 'bottom-up' processes children first
|
|
46
59
|
* @returns Promise that resolves to the new non-localized field value with recursively filtered blocks
|
|
47
60
|
*/
|
|
48
|
-
export declare function filterBlocksInNonLocalizedFieldValue(
|
|
61
|
+
export declare function filterBlocksInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => boolean | Promise<boolean>, options?: {
|
|
62
|
+
traversalDirection?: TraversalDirection;
|
|
63
|
+
}, path?: TreePath): Promise<T>;
|
|
64
|
+
export declare function filterBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: BlockInRequest, path: TreePath) => boolean | Promise<boolean>, options?: {
|
|
65
|
+
traversalDirection?: TraversalDirection;
|
|
66
|
+
}, path?: TreePath): Promise<unknown>;
|
|
49
67
|
/**
|
|
50
68
|
* Recursively reduce all blocks in a non-localized field value to a single value by applying a reducer function.
|
|
51
69
|
* Processes each direct block and recursively processes nested blocks within block attributes,
|
|
52
70
|
* accumulating results from the entire block hierarchy into a single value.
|
|
53
71
|
*
|
|
54
72
|
* @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
73
|
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to reduce
|
|
74
|
+
* @param fieldType - The type field (determines how the value is processed)
|
|
75
|
+
* @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
|
|
58
76
|
* @param reducer - Asynchronous function that processes each block and updates the accumulator
|
|
59
77
|
* @param initialNonLocalizedFieldValue - The initial value for the accumulator
|
|
60
78
|
* @returns Promise that resolves to the final accumulated value from all blocks in the hierarchy
|
|
61
79
|
*/
|
|
62
|
-
export declare function reduceBlocksInNonLocalizedFieldValue<R>(
|
|
80
|
+
export declare function reduceBlocksInNonLocalizedFieldValue<T, R>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, reducer: (accumulator: R, item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => R | Promise<R>, initialValue: R, path?: TreePath): Promise<R>;
|
|
81
|
+
export declare function reduceBlocksInNonLocalizedFieldValue<R>(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, reducer: (accumulator: R, item: BlockInRequest, path: TreePath) => R | Promise<R>, initialValue: R, path?: TreePath): Promise<R>;
|
|
63
82
|
/**
|
|
64
83
|
* Recursively check if any block in the non-localized field value matches the predicate function.
|
|
65
84
|
* Tests both direct blocks and recursively tests nested blocks within block attributes.
|
|
66
85
|
* Returns true as soon as the first matching block is found anywhere in the hierarchy
|
|
67
86
|
* (short-circuit evaluation).
|
|
68
87
|
*
|
|
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
88
|
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
|
|
89
|
+
* @param fieldType - The type field (determines how the value is processed)
|
|
90
|
+
* @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
|
|
72
91
|
* @param predicate - Asynchronous function that tests each block, including nested ones
|
|
73
92
|
* @returns Promise that resolves to true if any block in the hierarchy matches, false otherwise
|
|
74
93
|
*/
|
|
75
|
-
export declare function someBlocksInNonLocalizedFieldValue(
|
|
94
|
+
export declare function someBlocksInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<boolean>;
|
|
95
|
+
export declare function someBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: BlockInRequest, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<boolean>;
|
|
76
96
|
/**
|
|
77
97
|
* Recursively check if every block in the non-localized field value matches the predicate function.
|
|
78
98
|
* Tests both direct blocks and recursively tests nested blocks within block attributes.
|
|
79
99
|
* Returns false as soon as the first non-matching block is found anywhere in the hierarchy
|
|
80
100
|
* (short-circuit evaluation).
|
|
81
101
|
*
|
|
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
102
|
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
|
|
103
|
+
* @param fieldType - The type field (determines how the value is processed)
|
|
104
|
+
* @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
|
|
85
105
|
* @param predicate - Asynchronous function that tests each block, including nested ones
|
|
86
106
|
* @returns Promise that resolves to true if all blocks in the hierarchy match, false otherwise
|
|
87
107
|
*/
|
|
88
|
-
export declare function everyBlockInNonLocalizedFieldValue(
|
|
108
|
+
export declare function everyBlockInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<boolean>;
|
|
109
|
+
export declare function everyBlockInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: BlockInRequest, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<boolean>;
|
|
110
|
+
type FieldValueInRequest<T> = T extends RichTextFieldValueInNestedResponse<infer D> ? RichTextFieldValueInRequest<D> : T extends SingleBlockFieldValueInNestedResponse<infer D> ? SingleBlockFieldValueInRequest<D> : T extends StructuredTextFieldValueInNestedResponse<infer DB, infer DI> ? StructuredTextFieldValueInRequest<DB, DI> : T extends StructuredTextFieldValueInNestedResponse<infer DB> ? StructuredTextFieldValueInRequest<DB> : T;
|
|
89
111
|
/**
|
|
90
112
|
* Recursively transform blocks in a non-localized field value by applying a mapping function to each block.
|
|
91
113
|
* Creates a new non-localized field value structure with transformed blocks while preserving the original
|
|
92
114
|
* structure. Applies the mapping function to both direct blocks and recursively to nested
|
|
93
115
|
* blocks within block attributes throughout the entire hierarchy.
|
|
94
116
|
*
|
|
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
117
|
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to transform
|
|
118
|
+
* @param fieldType - The type field (determines how the value is processed)
|
|
119
|
+
* @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
|
|
98
120
|
* @param mapper - Asynchronous function that transforms each block, including nested ones
|
|
121
|
+
* @param options - Optional configuration object
|
|
122
|
+
* @param options.traversalDirection - Direction of traversal: 'top-down' (default) applies mapper before processing children, 'bottom-up' processes children first
|
|
99
123
|
* @returns Promise that resolves to the new non-localized field value with recursively transformed blocks
|
|
100
124
|
*/
|
|
101
|
-
export declare function mapBlocksInNonLocalizedFieldValue(
|
|
125
|
+
export declare function mapBlocksInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, mapper: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => BlockInRequest | Promise<BlockInRequest>, options?: {
|
|
126
|
+
traversalDirection?: TraversalDirection;
|
|
127
|
+
}, path?: TreePath): Promise<FieldValueInRequest<T>>;
|
|
128
|
+
export declare function mapBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, mapper: (item: BlockInRequest, path: TreePath) => BlockInRequest | Promise<BlockInRequest>, options?: {
|
|
129
|
+
traversalDirection?: TraversalDirection;
|
|
130
|
+
}, path?: TreePath): Promise<unknown>;
|
|
131
|
+
export {};
|