@datocms/cma-client 5.1.10 → 5.1.12
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 +569 -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 +18 -18
- 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/seo.js +2 -3
- package/dist/cjs/fieldTypes/seo.js.map +1 -1
- package/dist/cjs/fieldTypes/single_block.js +20 -19
- 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 +17 -18
- 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/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 +5 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utilities/buildBlockRecord.js +1 -45
- package/dist/cjs/utilities/buildBlockRecord.js.map +1 -1
- package/dist/cjs/utilities/duplicateBlockRecord.js +49 -0
- package/dist/cjs/utilities/duplicateBlockRecord.js.map +1 -0
- package/dist/cjs/utilities/inspectItem.js +427 -0
- package/dist/cjs/utilities/inspectItem.js.map +1 -0
- package/dist/cjs/utilities/{blocks.js → nonRecursiveBlocks.js} +60 -234
- 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 +73 -92
- 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 +9 -10
- package/dist/esm/fieldTypes/rich_text.js +13 -13
- 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/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 +31 -16
- package/dist/esm/fieldTypes/single_block.js +15 -14
- 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 +15 -16
- package/dist/esm/fieldTypes/structured_text.js +12 -13
- 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/ApiTypes.d.ts +90 -980
- package/dist/esm/generated/Client.js +1 -1
- package/dist/esm/generated/RawApiTypes.d.ts +156 -999
- package/dist/esm/generated/resources/Field.d.ts +200 -200
- 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 +5 -4
- package/dist/esm/index.js +5 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utilities/buildBlockRecord.d.ts +3 -5
- package/dist/esm/utilities/buildBlockRecord.js +0 -43
- package/dist/esm/utilities/buildBlockRecord.js.map +1 -1
- package/dist/esm/utilities/duplicateBlockRecord.d.ts +6 -0
- package/dist/esm/utilities/duplicateBlockRecord.js +45 -0
- package/dist/esm/utilities/duplicateBlockRecord.js.map +1 -0
- package/dist/esm/utilities/inspectItem.d.ts +8 -0
- package/dist/esm/utilities/inspectItem.js +400 -0
- package/dist/esm/utilities/inspectItem.js.map +1 -0
- package/dist/esm/utilities/itemDefinition.d.ts +45 -23
- package/dist/esm/utilities/nonRecursiveBlocks.d.ts +114 -0
- package/dist/esm/utilities/{blocks.js → nonRecursiveBlocks.js} +52 -220
- 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 +124 -11
- package/dist/esm/utilities/recursiveBlocks.js +65 -84
- 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 +9 -10
- package/dist/types/fieldTypes/schema.d.ts +59 -0
- package/dist/types/fieldTypes/seo.d.ts +1 -1
- package/dist/types/fieldTypes/single_block.d.ts +31 -16
- 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 +15 -16
- package/dist/types/fieldTypes/text.d.ts +1 -1
- package/dist/types/fieldTypes/video.d.ts +1 -1
- package/dist/types/generated/ApiTypes.d.ts +90 -980
- package/dist/types/generated/RawApiTypes.d.ts +156 -999
- package/dist/types/generated/resources/Field.d.ts +200 -200
- 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 +5 -4
- package/dist/types/utilities/buildBlockRecord.d.ts +3 -5
- package/dist/types/utilities/duplicateBlockRecord.d.ts +6 -0
- package/dist/types/utilities/inspectItem.d.ts +8 -0
- package/dist/types/utilities/itemDefinition.d.ts +45 -23
- package/dist/types/utilities/nonRecursiveBlocks.d.ts +114 -0
- package/dist/{esm/utilities/fieldValue.d.ts → types/utilities/normalizedFieldValues.d.ts} +15 -14
- package/dist/types/utilities/recursiveBlocks.d.ts +124 -11
- 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 +33 -31
- package/src/fieldTypes/schema.ts +657 -0
- package/src/fieldTypes/seo.ts +5 -4
- package/src/fieldTypes/single_block.ts +71 -46
- package/src/fieldTypes/slug.ts +5 -4
- package/src/fieldTypes/string.ts +5 -3
- package/src/fieldTypes/structured_text.ts +64 -58
- package/src/fieldTypes/text.ts +5 -4
- package/src/fieldTypes/video.ts +5 -3
- package/src/generated/ApiTypes.ts +217 -1880
- package/src/generated/Client.ts +1 -1
- package/src/generated/RawApiTypes.ts +272 -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 +5 -4
- package/src/utilities/buildBlockRecord.ts +4 -59
- package/src/utilities/duplicateBlockRecord.ts +52 -0
- package/src/utilities/inspectItem.ts +602 -0
- package/src/utilities/itemDefinition.ts +130 -92
- package/src/utilities/nonRecursiveBlocks.ts +406 -0
- package/src/utilities/{fieldValue.ts → normalizedFieldValues.ts} +70 -30
- package/src/utilities/recursiveBlocks.ts +484 -204
- 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
- package/src/utilities/blocks.ts +0 -626
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DatoCMS Block Field Value Processing Utilities
|
|
3
|
+
*
|
|
4
|
+
* This utility provides a unified interface for working with blocks embedded within DatoCMS field values.
|
|
5
|
+
* DatoCMS supports three field types that can contain blocks:
|
|
6
|
+
* - Modular Content fields: arrays of blocks
|
|
7
|
+
* - Single Block fields: a single block
|
|
8
|
+
* - Structured Text fields: complex document structures with embedded blocks
|
|
9
|
+
*
|
|
10
|
+
* The challenge this solves: Each field type stores blocks differently and requires different
|
|
11
|
+
* traversal logic, making it complex to perform operations like transformations, filtering,
|
|
12
|
+
* or searching across blocks regardless of their containing field type.
|
|
13
|
+
*
|
|
14
|
+
* This utility abstracts away these differences, providing a consistent API to:
|
|
15
|
+
* - Visit/iterate through all blocks in any field type
|
|
16
|
+
* - Transform blocks while preserving field structure
|
|
17
|
+
* - Filter blocks based on conditions
|
|
18
|
+
* - Search for specific blocks
|
|
19
|
+
* - Perform functional operations (map, reduce, some, every)
|
|
20
|
+
*
|
|
21
|
+
* All functions come in both sync and async variants to support different use cases,
|
|
22
|
+
* particularly useful when block transformations require async operations like API calls.
|
|
23
|
+
*/
|
|
24
|
+
import { type TreePath } from 'datocms-structured-text-utils';
|
|
25
|
+
import type { BlockInRequest } from '../fieldTypes';
|
|
26
|
+
import type * as ApiTypes from '../generated/ApiTypes';
|
|
27
|
+
/**
|
|
28
|
+
* Visit every block in a field value, calling the visitor function for each block found.
|
|
29
|
+
* Supports rich text, single block, and structured text field types.
|
|
30
|
+
*
|
|
31
|
+
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
32
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to visit
|
|
33
|
+
* @param visitor - Asynchronous function called for each block. Receives the block item and its path
|
|
34
|
+
* @returns Promise that resolves when all blocks have been visited
|
|
35
|
+
*/
|
|
36
|
+
export declare function nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, visitor: (item: BlockInRequest, path: TreePath) => Promise<void>): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Transform blocks in a field value by applying a mapping function to each block.
|
|
39
|
+
* Creates a new field value structure with transformed blocks while preserving the original structure.
|
|
40
|
+
* Supports rich text, single block, and structured text field types.
|
|
41
|
+
*
|
|
42
|
+
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
43
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to transform
|
|
44
|
+
* @param mapper - Synchronous function that transforms each block. Receives block item and path, returns new block
|
|
45
|
+
* @returns The new field value with transformed blocks
|
|
46
|
+
*/
|
|
47
|
+
export declare function nonRecursiveMapBlocksInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, mapper: (item: BlockInRequest, path: TreePath) => BlockInRequest): unknown;
|
|
48
|
+
/**
|
|
49
|
+
* Transform blocks in a field value by applying a mapping function to each block.
|
|
50
|
+
* Creates a new field value structure with transformed blocks while preserving the original structure.
|
|
51
|
+
* Supports rich text, single block, and structured text field types.
|
|
52
|
+
*
|
|
53
|
+
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
54
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to transform
|
|
55
|
+
* @param mapper - Asynchronous function that transforms each block. Receives block item and path, returns new block
|
|
56
|
+
* @returns Promise that resolves to the new field value with transformed blocks
|
|
57
|
+
*/
|
|
58
|
+
export declare function nonRecursiveMapBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, mapper: (item: BlockInRequest, path: TreePath) => Promise<BlockInRequest>): Promise<unknown>;
|
|
59
|
+
/**
|
|
60
|
+
* Find all blocks that match the predicate function.
|
|
61
|
+
* Searches through all blocks in the non-localized field value and returns all matches.
|
|
62
|
+
*
|
|
63
|
+
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
64
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to search
|
|
65
|
+
* @param predicate - Asynchronous function that tests each block. Should return true for matching blocks
|
|
66
|
+
* @returns Promise that resolves to an array of objects, each containing a matching block and its path
|
|
67
|
+
*/
|
|
68
|
+
export declare function nonRecursiveFindAllBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockInRequest, path: TreePath) => Promise<boolean>): Promise<Array<{
|
|
69
|
+
item: BlockInRequest;
|
|
70
|
+
path: TreePath;
|
|
71
|
+
}>>;
|
|
72
|
+
/**
|
|
73
|
+
* Filter blocks in a field value, removing those that don't match the predicate.
|
|
74
|
+
* Creates a new field value containing only blocks that pass the predicate test.
|
|
75
|
+
* Preserves the original field value structure and hierarchy.
|
|
76
|
+
*
|
|
77
|
+
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
78
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to filter
|
|
79
|
+
* @param predicate - Asynchronous function that tests each block. Blocks returning false are removed
|
|
80
|
+
* @returns Promise that resolves to the new field value with filtered blocks
|
|
81
|
+
*/
|
|
82
|
+
export declare function nonRecursiveFilterBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockInRequest, path: TreePath) => Promise<boolean>): Promise<unknown>;
|
|
83
|
+
/**
|
|
84
|
+
* Reduce all blocks in a field value to a single value by applying a reducer function.
|
|
85
|
+
* Processes each block in the non-localized field value and accumulates the results into a single value.
|
|
86
|
+
*
|
|
87
|
+
* @template R - The type of the accumulated result
|
|
88
|
+
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
89
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to reduce
|
|
90
|
+
* @param reducer - Asynchronous function that processes each block and updates the accumulator
|
|
91
|
+
* @param initialValue - The initial value for the accumulator
|
|
92
|
+
* @returns Promise that resolves to the final accumulated value
|
|
93
|
+
*/
|
|
94
|
+
export declare function nonRecursiveReduceBlocksInNonLocalizedFieldValueAsync<R>(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, reducer: (accumulator: R, item: BlockInRequest, path: TreePath) => Promise<R>, initialValue: R): Promise<R>;
|
|
95
|
+
/**
|
|
96
|
+
* Check if any block in the non-localized field value matches the predicate function.
|
|
97
|
+
* Returns true as soon as the first matching block is found (short-circuit evaluation).
|
|
98
|
+
*
|
|
99
|
+
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
100
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
|
|
101
|
+
* @param predicate - Asynchronous function that tests each block. Should return true for matching blocks
|
|
102
|
+
* @returns Promise that resolves to true if any block matches, false otherwise
|
|
103
|
+
*/
|
|
104
|
+
export declare function nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockInRequest, path: TreePath) => Promise<boolean>): Promise<boolean>;
|
|
105
|
+
/**
|
|
106
|
+
* Check if every block in the non-localized field value matches the predicate function.
|
|
107
|
+
* Returns false as soon as the first non-matching block is found (short-circuit evaluation).
|
|
108
|
+
*
|
|
109
|
+
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
110
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
|
|
111
|
+
* @param predicate - Asynchronous function that tests each block. Should return true for valid blocks
|
|
112
|
+
* @returns Promise that resolves to true if all blocks match, false otherwise
|
|
113
|
+
*/
|
|
114
|
+
export declare function nonRecursiveEveryBlockInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockInRequest, path: TreePath) => Promise<boolean>): Promise<boolean>;
|
|
@@ -49,47 +49,11 @@ 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
|
-
function
|
|
54
|
-
return 'attributes' in field ? field.attributes.field_type : field.field_type;
|
|
55
|
-
}
|
|
56
|
-
function* iterateBlocks(field, value) {
|
|
57
|
-
const fieldType = getFieldType(field);
|
|
58
|
-
if (fieldType === 'rich_text') {
|
|
59
|
-
const richTextValue = value;
|
|
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 = value;
|
|
70
|
-
if (singleBlockValue) {
|
|
71
|
-
yield { item: singleBlockValue, path: [] };
|
|
72
|
-
}
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
if (fieldType === 'structured_text') {
|
|
76
|
-
const structuredTextValue = value;
|
|
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
|
-
}
|
|
88
|
-
function iterateBlocksAsync(field, value) {
|
|
52
|
+
import { collectNodesAsync, filterNodesAsync, mapNodes, mapNodesAsync, } from 'datocms-structured-text-utils';
|
|
53
|
+
function iterateBlocksAsync(fieldType, nonLocalizedFieldValue) {
|
|
89
54
|
return __asyncGenerator(this, arguments, function* iterateBlocksAsync_1() {
|
|
90
|
-
const fieldType = getFieldType(field);
|
|
91
55
|
if (fieldType === 'rich_text') {
|
|
92
|
-
const richTextValue =
|
|
56
|
+
const richTextValue = nonLocalizedFieldValue;
|
|
93
57
|
if (richTextValue) {
|
|
94
58
|
for (let index = 0; index < richTextValue.length; index++) {
|
|
95
59
|
const item = richTextValue[index];
|
|
@@ -99,14 +63,14 @@ function iterateBlocksAsync(field, value) {
|
|
|
99
63
|
return yield __await(void 0);
|
|
100
64
|
}
|
|
101
65
|
if (fieldType === 'single_block') {
|
|
102
|
-
const singleBlockValue =
|
|
66
|
+
const singleBlockValue = nonLocalizedFieldValue;
|
|
103
67
|
if (singleBlockValue) {
|
|
104
68
|
yield yield __await({ item: singleBlockValue, path: [] });
|
|
105
69
|
}
|
|
106
70
|
return yield __await(void 0);
|
|
107
71
|
}
|
|
108
72
|
if (fieldType === 'structured_text') {
|
|
109
|
-
const structuredTextValue =
|
|
73
|
+
const structuredTextValue = nonLocalizedFieldValue;
|
|
110
74
|
if (structuredTextValue) {
|
|
111
75
|
const foundNodes = yield __await(collectNodesAsync(structuredTextValue.document, (node) => __awaiter(this, void 0, void 0, function* () { return node.type === 'block' || node.type === 'inlineBlock'; })));
|
|
112
76
|
for (const { node, path } of foundNodes) {
|
|
@@ -123,29 +87,16 @@ function iterateBlocksAsync(field, value) {
|
|
|
123
87
|
* Visit every block in a field value, calling the visitor function for each block found.
|
|
124
88
|
* Supports rich text, single block, and structured text field types.
|
|
125
89
|
*
|
|
126
|
-
* @param
|
|
127
|
-
* @param
|
|
128
|
-
* @param visitor - Synchronous function called for each block. Receives the block item and its path
|
|
129
|
-
*/
|
|
130
|
-
export function nonRecursiveVisitBlocksInFieldValue(field, value, visitor) {
|
|
131
|
-
for (const { item, path } of iterateBlocks(field, value)) {
|
|
132
|
-
visitor(item, path);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Visit every block in a field value, calling the visitor function for each block found.
|
|
137
|
-
* Supports rich text, single block, and structured text field types.
|
|
138
|
-
*
|
|
139
|
-
* @param field - The DatoCMS field definition that determines how blocks are processed
|
|
140
|
-
* @param value - The field value containing blocks to visit
|
|
90
|
+
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
91
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to visit
|
|
141
92
|
* @param visitor - Asynchronous function called for each block. Receives the block item and its path
|
|
142
93
|
* @returns Promise that resolves when all blocks have been visited
|
|
143
94
|
*/
|
|
144
|
-
export function
|
|
95
|
+
export function nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, visitor) {
|
|
145
96
|
var _a, e_1, _b, _c;
|
|
146
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
98
|
try {
|
|
148
|
-
for (var _d = true, _e = __asyncValues(iterateBlocksAsync(
|
|
99
|
+
for (var _d = true, _e = __asyncValues(iterateBlocksAsync(fieldType, nonLocalizedFieldValue)), _f; _f = yield _e.next(), _a = _f.done, !_a;) {
|
|
149
100
|
_c = _f.value;
|
|
150
101
|
_d = false;
|
|
151
102
|
try {
|
|
@@ -171,25 +122,24 @@ export function nonRecursiveVisitBlocksInFieldValueAsync(field, value, visitor)
|
|
|
171
122
|
* Creates a new field value structure with transformed blocks while preserving the original structure.
|
|
172
123
|
* Supports rich text, single block, and structured text field types.
|
|
173
124
|
*
|
|
174
|
-
* @param
|
|
175
|
-
* @param
|
|
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 transform
|
|
176
127
|
* @param mapper - Synchronous function that transforms each block. Receives block item and path, returns new block
|
|
177
128
|
* @returns The new field value with transformed blocks
|
|
178
129
|
*/
|
|
179
|
-
export function
|
|
180
|
-
const fieldType = getFieldType(field);
|
|
130
|
+
export function nonRecursiveMapBlocksInNonLocalizedFieldValue(fieldType, nonLocalizedFieldValue, mapper) {
|
|
181
131
|
if (fieldType === 'rich_text') {
|
|
182
|
-
const richTextValue =
|
|
132
|
+
const richTextValue = nonLocalizedFieldValue;
|
|
183
133
|
return richTextValue
|
|
184
134
|
? richTextValue.map((item, index) => mapper(item, [index]))
|
|
185
135
|
: richTextValue;
|
|
186
136
|
}
|
|
187
137
|
if (fieldType === 'single_block') {
|
|
188
|
-
const singleBlockValue =
|
|
138
|
+
const singleBlockValue = nonLocalizedFieldValue;
|
|
189
139
|
return singleBlockValue ? mapper(singleBlockValue, []) : null;
|
|
190
140
|
}
|
|
191
141
|
if (fieldType === 'structured_text') {
|
|
192
|
-
const structuredTextValue =
|
|
142
|
+
const structuredTextValue = nonLocalizedFieldValue;
|
|
193
143
|
if (!structuredTextValue) {
|
|
194
144
|
return null;
|
|
195
145
|
}
|
|
@@ -203,33 +153,32 @@ export function nonRecursiveMapBlocksInFieldValue(field, value, mapper) {
|
|
|
203
153
|
}),
|
|
204
154
|
};
|
|
205
155
|
}
|
|
206
|
-
return
|
|
156
|
+
return nonLocalizedFieldValue;
|
|
207
157
|
}
|
|
208
158
|
/**
|
|
209
159
|
* Transform blocks in a field value by applying a mapping function to each block.
|
|
210
160
|
* Creates a new field value structure with transformed blocks while preserving the original structure.
|
|
211
161
|
* Supports rich text, single block, and structured text field types.
|
|
212
162
|
*
|
|
213
|
-
* @param
|
|
214
|
-
* @param
|
|
163
|
+
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
164
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to transform
|
|
215
165
|
* @param mapper - Asynchronous function that transforms each block. Receives block item and path, returns new block
|
|
216
166
|
* @returns Promise that resolves to the new field value with transformed blocks
|
|
217
167
|
*/
|
|
218
|
-
export function
|
|
168
|
+
export function nonRecursiveMapBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, mapper) {
|
|
219
169
|
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
-
const fieldType = getFieldType(field);
|
|
221
170
|
if (fieldType === 'rich_text') {
|
|
222
|
-
const richTextValue =
|
|
171
|
+
const richTextValue = nonLocalizedFieldValue;
|
|
223
172
|
return richTextValue
|
|
224
173
|
? yield Promise.all(richTextValue.map((item, index) => mapper(item, [index])))
|
|
225
174
|
: richTextValue;
|
|
226
175
|
}
|
|
227
176
|
if (fieldType === 'single_block') {
|
|
228
|
-
const singleBlockValue =
|
|
177
|
+
const singleBlockValue = nonLocalizedFieldValue;
|
|
229
178
|
return singleBlockValue ? yield mapper(singleBlockValue, []) : null;
|
|
230
179
|
}
|
|
231
180
|
if (fieldType === 'structured_text') {
|
|
232
|
-
const structuredTextValue =
|
|
181
|
+
const structuredTextValue = nonLocalizedFieldValue;
|
|
233
182
|
if (!structuredTextValue) {
|
|
234
183
|
return null;
|
|
235
184
|
}
|
|
@@ -243,42 +192,24 @@ export function nonRecursiveMapBlocksInFieldValueAsync(field, value, mapper) {
|
|
|
243
192
|
})),
|
|
244
193
|
};
|
|
245
194
|
}
|
|
246
|
-
return
|
|
195
|
+
return nonLocalizedFieldValue;
|
|
247
196
|
});
|
|
248
197
|
}
|
|
249
198
|
/**
|
|
250
199
|
* Find all blocks that match the predicate function.
|
|
251
|
-
* Searches through all blocks in the field value and returns all matches.
|
|
252
|
-
*
|
|
253
|
-
* @param field - The DatoCMS field definition that determines how blocks are processed
|
|
254
|
-
* @param value - The field value containing blocks to search
|
|
255
|
-
* @param predicate - Synchronous function that tests each block. Should return true for matching blocks
|
|
256
|
-
* @returns Array of objects, each containing a matching block and its path
|
|
257
|
-
*/
|
|
258
|
-
export function nonRecursiveFindAllBlocksInFieldValue(field, value, predicate) {
|
|
259
|
-
const results = [];
|
|
260
|
-
for (const { item, path } of iterateBlocks(field, value)) {
|
|
261
|
-
if (predicate(item, path)) {
|
|
262
|
-
results.push({ item, path });
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
return results;
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Find all blocks that match the predicate function.
|
|
269
|
-
* Searches through all blocks in the field value and returns all matches.
|
|
200
|
+
* Searches through all blocks in the non-localized field value and returns all matches.
|
|
270
201
|
*
|
|
271
|
-
* @param
|
|
272
|
-
* @param
|
|
202
|
+
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
203
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to search
|
|
273
204
|
* @param predicate - Asynchronous function that tests each block. Should return true for matching blocks
|
|
274
205
|
* @returns Promise that resolves to an array of objects, each containing a matching block and its path
|
|
275
206
|
*/
|
|
276
|
-
export function
|
|
207
|
+
export function nonRecursiveFindAllBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, predicate) {
|
|
277
208
|
var _a, e_2, _b, _c;
|
|
278
209
|
return __awaiter(this, void 0, void 0, function* () {
|
|
279
210
|
const results = [];
|
|
280
211
|
try {
|
|
281
|
-
for (var _d = true, _e = __asyncValues(iterateBlocksAsync(
|
|
212
|
+
for (var _d = true, _e = __asyncValues(iterateBlocksAsync(fieldType, nonLocalizedFieldValue)), _f; _f = yield _e.next(), _a = _f.done, !_a;) {
|
|
282
213
|
_c = _f.value;
|
|
283
214
|
_d = false;
|
|
284
215
|
try {
|
|
@@ -307,68 +238,18 @@ export function nonRecursiveFindAllBlocksInFieldValueAsync(field, value, predica
|
|
|
307
238
|
* Creates a new field value containing only blocks that pass the predicate test.
|
|
308
239
|
* Preserves the original field value structure and hierarchy.
|
|
309
240
|
*
|
|
310
|
-
* @param
|
|
311
|
-
* @param
|
|
312
|
-
* @param predicate - Synchronous function that tests each block. Blocks returning false are removed
|
|
313
|
-
* @returns The new field value with filtered blocks
|
|
314
|
-
*/
|
|
315
|
-
export function nonRecursiveFilterBlocksInFieldValue(field, value, predicate) {
|
|
316
|
-
const fieldType = getFieldType(field);
|
|
317
|
-
if (fieldType === 'rich_text') {
|
|
318
|
-
const filteredItems = [];
|
|
319
|
-
for (const { item, path } of iterateBlocks(field, value)) {
|
|
320
|
-
if (predicate(item, path)) {
|
|
321
|
-
filteredItems.push(item);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
return value ? filteredItems : value;
|
|
325
|
-
}
|
|
326
|
-
if (fieldType === 'single_block') {
|
|
327
|
-
for (const { item, path } of iterateBlocks(field, value)) {
|
|
328
|
-
if (predicate(item, path)) {
|
|
329
|
-
return item;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
return null;
|
|
333
|
-
}
|
|
334
|
-
if (fieldType === 'structured_text') {
|
|
335
|
-
const structuredTextValue = value;
|
|
336
|
-
if (!structuredTextValue) {
|
|
337
|
-
return null;
|
|
338
|
-
}
|
|
339
|
-
const filteredDocument = filterNodes(structuredTextValue.document, (node, _parent, path) => {
|
|
340
|
-
if (node.type === 'block' || node.type === 'inlineBlock') {
|
|
341
|
-
return predicate(node.item, path);
|
|
342
|
-
}
|
|
343
|
-
return true;
|
|
344
|
-
});
|
|
345
|
-
return filteredDocument
|
|
346
|
-
? {
|
|
347
|
-
schema: 'dast',
|
|
348
|
-
document: filteredDocument,
|
|
349
|
-
}
|
|
350
|
-
: null;
|
|
351
|
-
}
|
|
352
|
-
return value;
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Filter blocks in a field value, removing those that don't match the predicate.
|
|
356
|
-
* Creates a new field value containing only blocks that pass the predicate test.
|
|
357
|
-
* Preserves the original field value structure and hierarchy.
|
|
358
|
-
*
|
|
359
|
-
* @param field - The DatoCMS field definition that determines how blocks are processed
|
|
360
|
-
* @param value - The field value containing blocks to filter
|
|
241
|
+
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
242
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to filter
|
|
361
243
|
* @param predicate - Asynchronous function that tests each block. Blocks returning false are removed
|
|
362
244
|
* @returns Promise that resolves to the new field value with filtered blocks
|
|
363
245
|
*/
|
|
364
|
-
export function
|
|
246
|
+
export function nonRecursiveFilterBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, predicate) {
|
|
365
247
|
var _a, e_3, _b, _c, _d, e_4, _e, _f;
|
|
366
248
|
return __awaiter(this, void 0, void 0, function* () {
|
|
367
|
-
const fieldType = getFieldType(field);
|
|
368
249
|
if (fieldType === 'rich_text') {
|
|
369
250
|
const filteredItems = [];
|
|
370
251
|
try {
|
|
371
|
-
for (var _g = true, _h = __asyncValues(iterateBlocksAsync(
|
|
252
|
+
for (var _g = true, _h = __asyncValues(iterateBlocksAsync(fieldType, nonLocalizedFieldValue)), _j; _j = yield _h.next(), _a = _j.done, !_a;) {
|
|
372
253
|
_c = _j.value;
|
|
373
254
|
_g = false;
|
|
374
255
|
try {
|
|
@@ -389,11 +270,11 @@ export function nonRecursiveFilterBlocksInFieldValueAsync(field, value, predicat
|
|
|
389
270
|
}
|
|
390
271
|
finally { if (e_3) throw e_3.error; }
|
|
391
272
|
}
|
|
392
|
-
return
|
|
273
|
+
return filteredItems;
|
|
393
274
|
}
|
|
394
275
|
if (fieldType === 'single_block') {
|
|
395
276
|
try {
|
|
396
|
-
for (var _k = true, _l = __asyncValues(iterateBlocksAsync(
|
|
277
|
+
for (var _k = true, _l = __asyncValues(iterateBlocksAsync(fieldType, nonLocalizedFieldValue)), _m; _m = yield _l.next(), _d = _m.done, !_d;) {
|
|
397
278
|
_f = _m.value;
|
|
398
279
|
_k = false;
|
|
399
280
|
try {
|
|
@@ -417,7 +298,7 @@ export function nonRecursiveFilterBlocksInFieldValueAsync(field, value, predicat
|
|
|
417
298
|
return null;
|
|
418
299
|
}
|
|
419
300
|
if (fieldType === 'structured_text') {
|
|
420
|
-
const structuredTextValue =
|
|
301
|
+
const structuredTextValue = nonLocalizedFieldValue;
|
|
421
302
|
if (!structuredTextValue) {
|
|
422
303
|
return null;
|
|
423
304
|
}
|
|
@@ -434,44 +315,26 @@ export function nonRecursiveFilterBlocksInFieldValueAsync(field, value, predicat
|
|
|
434
315
|
}
|
|
435
316
|
: null;
|
|
436
317
|
}
|
|
437
|
-
return
|
|
318
|
+
return nonLocalizedFieldValue;
|
|
438
319
|
});
|
|
439
320
|
}
|
|
440
321
|
/**
|
|
441
322
|
* Reduce all blocks in a field value to a single value by applying a reducer function.
|
|
442
|
-
* Processes each block in the field value and accumulates the results into a single value.
|
|
443
|
-
*
|
|
444
|
-
* @template R - The type of the accumulated result
|
|
445
|
-
* @param field - The DatoCMS field definition that determines how blocks are processed
|
|
446
|
-
* @param value - The field value containing blocks to reduce
|
|
447
|
-
* @param reducer - Synchronous function that processes each block and updates the accumulator
|
|
448
|
-
* @param initialValue - The initial value for the accumulator
|
|
449
|
-
* @returns The final accumulated value
|
|
450
|
-
*/
|
|
451
|
-
export function nonRecursiveReduceBlocksInFieldValue(field, value, reducer, initialValue) {
|
|
452
|
-
let accumulator = initialValue;
|
|
453
|
-
for (const { item, path } of iterateBlocks(field, value)) {
|
|
454
|
-
accumulator = reducer(accumulator, item, path);
|
|
455
|
-
}
|
|
456
|
-
return accumulator;
|
|
457
|
-
}
|
|
458
|
-
/**
|
|
459
|
-
* Reduce all blocks in a field value to a single value by applying a reducer function.
|
|
460
|
-
* Processes each block in the field value and accumulates the results into a single value.
|
|
323
|
+
* Processes each block in the non-localized field value and accumulates the results into a single value.
|
|
461
324
|
*
|
|
462
325
|
* @template R - The type of the accumulated result
|
|
463
|
-
* @param
|
|
464
|
-
* @param
|
|
326
|
+
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
327
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to reduce
|
|
465
328
|
* @param reducer - Asynchronous function that processes each block and updates the accumulator
|
|
466
329
|
* @param initialValue - The initial value for the accumulator
|
|
467
330
|
* @returns Promise that resolves to the final accumulated value
|
|
468
331
|
*/
|
|
469
|
-
export function
|
|
332
|
+
export function nonRecursiveReduceBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, reducer, initialValue) {
|
|
470
333
|
var _a, e_5, _b, _c;
|
|
471
334
|
return __awaiter(this, void 0, void 0, function* () {
|
|
472
335
|
let accumulator = initialValue;
|
|
473
336
|
try {
|
|
474
|
-
for (var _d = true, _e = __asyncValues(iterateBlocksAsync(
|
|
337
|
+
for (var _d = true, _e = __asyncValues(iterateBlocksAsync(fieldType, nonLocalizedFieldValue)), _f; _f = yield _e.next(), _a = _f.done, !_a;) {
|
|
475
338
|
_c = _f.value;
|
|
476
339
|
_d = false;
|
|
477
340
|
try {
|
|
@@ -494,36 +357,19 @@ export function nonRecursiveReduceBlocksInFieldValueAsync(field, value, reducer,
|
|
|
494
357
|
});
|
|
495
358
|
}
|
|
496
359
|
/**
|
|
497
|
-
* Check if any block in the field value matches the predicate function.
|
|
498
|
-
* Returns true as soon as the first matching block is found (short-circuit evaluation).
|
|
499
|
-
*
|
|
500
|
-
* @param field - The DatoCMS field definition that determines how blocks are processed
|
|
501
|
-
* @param value - The field value containing blocks to test
|
|
502
|
-
* @param predicate - Synchronous function that tests each block. Should return true for matching blocks
|
|
503
|
-
* @returns True if any block matches, false otherwise
|
|
504
|
-
*/
|
|
505
|
-
export function nonRecursiveSomeBlocksInFieldValue(field, value, predicate) {
|
|
506
|
-
for (const { item, path } of iterateBlocks(field, value)) {
|
|
507
|
-
if (predicate(item, path)) {
|
|
508
|
-
return true;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
return false;
|
|
512
|
-
}
|
|
513
|
-
/**
|
|
514
|
-
* Check if any block in the field value matches the predicate function.
|
|
360
|
+
* Check if any block in the non-localized field value matches the predicate function.
|
|
515
361
|
* Returns true as soon as the first matching block is found (short-circuit evaluation).
|
|
516
362
|
*
|
|
517
|
-
* @param
|
|
518
|
-
* @param
|
|
363
|
+
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
364
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
|
|
519
365
|
* @param predicate - Asynchronous function that tests each block. Should return true for matching blocks
|
|
520
366
|
* @returns Promise that resolves to true if any block matches, false otherwise
|
|
521
367
|
*/
|
|
522
|
-
export function
|
|
368
|
+
export function nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, predicate) {
|
|
523
369
|
var _a, e_6, _b, _c;
|
|
524
370
|
return __awaiter(this, void 0, void 0, function* () {
|
|
525
371
|
try {
|
|
526
|
-
for (var _d = true, _e = __asyncValues(iterateBlocksAsync(
|
|
372
|
+
for (var _d = true, _e = __asyncValues(iterateBlocksAsync(fieldType, nonLocalizedFieldValue)), _f; _f = yield _e.next(), _a = _f.done, !_a;) {
|
|
527
373
|
_c = _f.value;
|
|
528
374
|
_d = false;
|
|
529
375
|
try {
|
|
@@ -548,33 +394,19 @@ export function nonRecursiveSomeBlocksInFieldValueAsync(field, value, predicate)
|
|
|
548
394
|
});
|
|
549
395
|
}
|
|
550
396
|
/**
|
|
551
|
-
* Check if every block in the field value matches the predicate function.
|
|
552
|
-
* Returns false as soon as the first non-matching block is found (short-circuit evaluation).
|
|
553
|
-
*
|
|
554
|
-
* @param field - The DatoCMS field definition that determines how blocks are processed
|
|
555
|
-
* @param value - The field value containing blocks to test
|
|
556
|
-
* @param predicate - Synchronous function that tests each block. Should return true for valid blocks
|
|
557
|
-
* @returns True if all blocks match, false otherwise
|
|
558
|
-
*/
|
|
559
|
-
export function nonRecursiveEveryBlockInFieldValue(field, value, predicate) {
|
|
560
|
-
return !nonRecursiveSomeBlocksInFieldValue(field, value, (item, path) => {
|
|
561
|
-
return !predicate(item, path);
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
/**
|
|
565
|
-
* Check if every block in the field value matches the predicate function.
|
|
397
|
+
* Check if every block in the non-localized field value matches the predicate function.
|
|
566
398
|
* Returns false as soon as the first non-matching block is found (short-circuit evaluation).
|
|
567
399
|
*
|
|
568
|
-
* @param
|
|
569
|
-
* @param
|
|
400
|
+
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
401
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
|
|
570
402
|
* @param predicate - Asynchronous function that tests each block. Should return true for valid blocks
|
|
571
403
|
* @returns Promise that resolves to true if all blocks match, false otherwise
|
|
572
404
|
*/
|
|
573
|
-
export function
|
|
405
|
+
export function nonRecursiveEveryBlockInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, predicate) {
|
|
574
406
|
return __awaiter(this, void 0, void 0, function* () {
|
|
575
|
-
return !(yield
|
|
407
|
+
return !(yield nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (item, path) => __awaiter(this, void 0, void 0, function* () {
|
|
576
408
|
return !(yield predicate(item, path));
|
|
577
409
|
})));
|
|
578
410
|
});
|
|
579
411
|
}
|
|
580
|
-
//# sourceMappingURL=
|
|
412
|
+
//# sourceMappingURL=nonRecursiveBlocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nonRecursiveBlocks.js","sourceRoot":"","sources":["../../../src/utilities/nonRecursiveBlocks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,OAAO,EAEL,iBAAiB,EACjB,gBAAgB,EAChB,QAAQ,EACR,aAAa,GACd,MAAM,+BAA+B,CAAC;AA4BvC,SAAgB,kBAAkB,CAChC,SAAuC,EACvC,sBAA+B;;QAE/B,IAAI,SAAS,KAAK,WAAW,EAAE;YAC7B,MAAM,aAAa,GAAG,sBAA+C,CAAC;YACtE,IAAI,aAAa,EAAE;gBACjB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,aAAa,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;oBACzD,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,CAAE,CAAC;oBACnC,oBAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,CAAA,CAAC;iBAC/B;aACF;YACD,6BAAO;SACR;QAED,IAAI,SAAS,KAAK,cAAc,EAAE;YAChC,MAAM,gBAAgB,GAAG,s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