@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
|
@@ -22,17 +22,8 @@
|
|
|
22
22
|
* particularly useful when block transformations require async operations like API calls.
|
|
23
23
|
*/
|
|
24
24
|
import { type TreePath } from 'datocms-structured-text-utils';
|
|
25
|
-
import type {
|
|
25
|
+
import type { BlockInRequest } from '../fieldTypes';
|
|
26
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 - Synchronous function called for each block. Receives the block item and its path
|
|
34
|
-
*/
|
|
35
|
-
export declare function nonRecursiveVisitBlocksInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, visitor: (item: BlockItemInARequest, path: TreePath) => void): void;
|
|
36
27
|
/**
|
|
37
28
|
* Visit every block in a field value, calling the visitor function for each block found.
|
|
38
29
|
* Supports rich text, single block, and structured text field types.
|
|
@@ -42,7 +33,7 @@ export declare function nonRecursiveVisitBlocksInNonLocalizedFieldValue(fieldTyp
|
|
|
42
33
|
* @param visitor - Asynchronous function called for each block. Receives the block item and its path
|
|
43
34
|
* @returns Promise that resolves when all blocks have been visited
|
|
44
35
|
*/
|
|
45
|
-
export declare function nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, visitor: (item:
|
|
36
|
+
export declare function nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, visitor: (item: BlockInRequest, path: TreePath) => Promise<void>): Promise<void>;
|
|
46
37
|
/**
|
|
47
38
|
* Transform blocks in a field value by applying a mapping function to each block.
|
|
48
39
|
* Creates a new field value structure with transformed blocks while preserving the original structure.
|
|
@@ -53,7 +44,7 @@ export declare function nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(fie
|
|
|
53
44
|
* @param mapper - Synchronous function that transforms each block. Receives block item and path, returns new block
|
|
54
45
|
* @returns The new field value with transformed blocks
|
|
55
46
|
*/
|
|
56
|
-
export declare function nonRecursiveMapBlocksInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, mapper: (item:
|
|
47
|
+
export declare function nonRecursiveMapBlocksInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, mapper: (item: BlockInRequest, path: TreePath) => BlockInRequest): unknown;
|
|
57
48
|
/**
|
|
58
49
|
* Transform blocks in a field value by applying a mapping function to each block.
|
|
59
50
|
* Creates a new field value structure with transformed blocks while preserving the original structure.
|
|
@@ -64,20 +55,7 @@ export declare function nonRecursiveMapBlocksInNonLocalizedFieldValue(fieldType:
|
|
|
64
55
|
* @param mapper - Asynchronous function that transforms each block. Receives block item and path, returns new block
|
|
65
56
|
* @returns Promise that resolves to the new field value with transformed blocks
|
|
66
57
|
*/
|
|
67
|
-
export declare function nonRecursiveMapBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, mapper: (item:
|
|
68
|
-
/**
|
|
69
|
-
* Find all blocks that match the predicate function.
|
|
70
|
-
* Searches through all blocks in the non-localized field value and returns all matches.
|
|
71
|
-
*
|
|
72
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
73
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to search
|
|
74
|
-
* @param predicate - Synchronous function that tests each block. Should return true for matching blocks
|
|
75
|
-
* @returns Array of objects, each containing a matching block and its path
|
|
76
|
-
*/
|
|
77
|
-
export declare function nonRecursiveFindAllBlocksInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean): Array<{
|
|
78
|
-
item: BlockItemInARequest;
|
|
79
|
-
path: TreePath;
|
|
80
|
-
}>;
|
|
58
|
+
export declare function nonRecursiveMapBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, mapper: (item: BlockInRequest, path: TreePath) => Promise<BlockInRequest>): Promise<unknown>;
|
|
81
59
|
/**
|
|
82
60
|
* Find all blocks that match the predicate function.
|
|
83
61
|
* Searches through all blocks in the non-localized field value and returns all matches.
|
|
@@ -87,21 +65,10 @@ export declare function nonRecursiveFindAllBlocksInNonLocalizedFieldValue(fieldT
|
|
|
87
65
|
* @param predicate - Asynchronous function that tests each block. Should return true for matching blocks
|
|
88
66
|
* @returns Promise that resolves to an array of objects, each containing a matching block and its path
|
|
89
67
|
*/
|
|
90
|
-
export declare function nonRecursiveFindAllBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item:
|
|
91
|
-
item:
|
|
68
|
+
export declare function nonRecursiveFindAllBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockInRequest, path: TreePath) => Promise<boolean>): Promise<Array<{
|
|
69
|
+
item: BlockInRequest;
|
|
92
70
|
path: TreePath;
|
|
93
71
|
}>>;
|
|
94
|
-
/**
|
|
95
|
-
* Filter blocks in a field value, removing those that don't match the predicate.
|
|
96
|
-
* Creates a new field value containing only blocks that pass the predicate test.
|
|
97
|
-
* Preserves the original field value structure and hierarchy.
|
|
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 filter
|
|
101
|
-
* @param predicate - Synchronous function that tests each block. Blocks returning false are removed
|
|
102
|
-
* @returns The new field value with filtered blocks
|
|
103
|
-
*/
|
|
104
|
-
export declare function nonRecursiveFilterBlocksInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean): unknown;
|
|
105
72
|
/**
|
|
106
73
|
* Filter blocks in a field value, removing those that don't match the predicate.
|
|
107
74
|
* Creates a new field value containing only blocks that pass the predicate test.
|
|
@@ -112,19 +79,7 @@ export declare function nonRecursiveFilterBlocksInNonLocalizedFieldValue(fieldTy
|
|
|
112
79
|
* @param predicate - Asynchronous function that tests each block. Blocks returning false are removed
|
|
113
80
|
* @returns Promise that resolves to the new field value with filtered blocks
|
|
114
81
|
*/
|
|
115
|
-
export declare function nonRecursiveFilterBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item:
|
|
116
|
-
/**
|
|
117
|
-
* Reduce all blocks in a field value to a single value by applying a reducer function.
|
|
118
|
-
* Processes each block in the non-localized field value and accumulates the results into a single value.
|
|
119
|
-
*
|
|
120
|
-
* @template R - The type of the accumulated result
|
|
121
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
122
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to reduce
|
|
123
|
-
* @param reducer - Synchronous function that processes each block and updates the accumulator
|
|
124
|
-
* @param initialValue - The initial value for the accumulator
|
|
125
|
-
* @returns The final accumulated value
|
|
126
|
-
*/
|
|
127
|
-
export declare function nonRecursiveReduceBlocksInNonLocalizedFieldValue<R>(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, reducer: (accumulator: R, item: BlockItemInARequest, path: TreePath) => R, initialValue: R): R;
|
|
82
|
+
export declare function nonRecursiveFilterBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockInRequest, path: TreePath) => Promise<boolean>): Promise<unknown>;
|
|
128
83
|
/**
|
|
129
84
|
* Reduce all blocks in a field value to a single value by applying a reducer function.
|
|
130
85
|
* Processes each block in the non-localized field value and accumulates the results into a single value.
|
|
@@ -136,17 +91,7 @@ export declare function nonRecursiveReduceBlocksInNonLocalizedFieldValue<R>(fiel
|
|
|
136
91
|
* @param initialValue - The initial value for the accumulator
|
|
137
92
|
* @returns Promise that resolves to the final accumulated value
|
|
138
93
|
*/
|
|
139
|
-
export declare function nonRecursiveReduceBlocksInNonLocalizedFieldValueAsync<R>(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, reducer: (accumulator: R, item:
|
|
140
|
-
/**
|
|
141
|
-
* Check if any block in the non-localized field value matches the predicate function.
|
|
142
|
-
* Returns true as soon as the first matching block is found (short-circuit evaluation).
|
|
143
|
-
*
|
|
144
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
145
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
|
|
146
|
-
* @param predicate - Synchronous function that tests each block. Should return true for matching blocks
|
|
147
|
-
* @returns True if any block matches, false otherwise
|
|
148
|
-
*/
|
|
149
|
-
export declare function nonRecursiveSomeBlocksInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean): boolean;
|
|
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>;
|
|
150
95
|
/**
|
|
151
96
|
* Check if any block in the non-localized field value matches the predicate function.
|
|
152
97
|
* Returns true as soon as the first matching block is found (short-circuit evaluation).
|
|
@@ -156,17 +101,7 @@ export declare function nonRecursiveSomeBlocksInNonLocalizedFieldValue(fieldType
|
|
|
156
101
|
* @param predicate - Asynchronous function that tests each block. Should return true for matching blocks
|
|
157
102
|
* @returns Promise that resolves to true if any block matches, false otherwise
|
|
158
103
|
*/
|
|
159
|
-
export declare function nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item:
|
|
160
|
-
/**
|
|
161
|
-
* Check if every block in the non-localized field value matches the predicate function.
|
|
162
|
-
* Returns false as soon as the first non-matching block is found (short-circuit evaluation).
|
|
163
|
-
*
|
|
164
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
165
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
|
|
166
|
-
* @param predicate - Synchronous function that tests each block. Should return true for valid blocks
|
|
167
|
-
* @returns True if all blocks match, false otherwise
|
|
168
|
-
*/
|
|
169
|
-
export declare function nonRecursiveEveryBlockInNonLocalizedFieldValue(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockItemInARequest, path: TreePath) => boolean): boolean;
|
|
104
|
+
export declare function nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockInRequest, path: TreePath) => Promise<boolean>): Promise<boolean>;
|
|
170
105
|
/**
|
|
171
106
|
* Check if every block in the non-localized field value matches the predicate function.
|
|
172
107
|
* Returns false as soon as the first non-matching block is found (short-circuit evaluation).
|
|
@@ -176,4 +111,4 @@ export declare function nonRecursiveEveryBlockInNonLocalizedFieldValue(fieldType
|
|
|
176
111
|
* @param predicate - Asynchronous function that tests each block. Should return true for valid blocks
|
|
177
112
|
* @returns Promise that resolves to true if all blocks match, false otherwise
|
|
178
113
|
*/
|
|
179
|
-
export declare function nonRecursiveEveryBlockInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item:
|
|
114
|
+
export declare function nonRecursiveEveryBlockInNonLocalizedFieldValueAsync(fieldType: ApiTypes.Field['field_type'], nonLocalizedFieldValue: unknown, predicate: (item: BlockInRequest, path: TreePath) => Promise<boolean>): Promise<boolean>;
|
|
@@ -1,36 +1,47 @@
|
|
|
1
|
-
import { type
|
|
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 {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datocms/cma-client",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.13",
|
|
4
4
|
"description": "JS client for DatoCMS REST Content Management API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datocms",
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"url": "https://github.com/datocms/js-rest-api-clients/issues"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@datocms/rest-client-utils": "^5.1.
|
|
40
|
+
"@datocms/rest-client-utils": "^5.1.13",
|
|
41
41
|
"datocms-structured-text-utils": "^5.1.4",
|
|
42
42
|
"uuid": "^9.0.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@datocms/dashboard-client": "^5.1.
|
|
45
|
+
"@datocms/dashboard-client": "^5.1.13",
|
|
46
46
|
"@types/uuid": "^9.0.7"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "966b5835bf69f9e87b34f2075a8596c9208e07c0"
|
|
49
49
|
}
|
package/src/fieldTypes/file.ts
CHANGED
|
@@ -66,7 +66,7 @@ export type FileFieldValue = {
|
|
|
66
66
|
/**
|
|
67
67
|
* File field value for API requests - metadata fields are optional
|
|
68
68
|
*/
|
|
69
|
-
export type
|
|
69
|
+
export type FileFieldValueInRequest = {
|
|
70
70
|
upload_id: string;
|
|
71
71
|
alt?: string | null;
|
|
72
72
|
title?: string | null;
|
|
@@ -103,9 +103,9 @@ export function isFileFieldValue(value: unknown): value is FileFieldValue {
|
|
|
103
103
|
* Type guard for File field values in API request format.
|
|
104
104
|
* Allows metadata fields to be optional or omitted.
|
|
105
105
|
*/
|
|
106
|
-
export function
|
|
106
|
+
export function isFileFieldValueInRequest(
|
|
107
107
|
value: unknown,
|
|
108
|
-
): value is
|
|
108
|
+
): value is FileFieldValueInRequest {
|
|
109
109
|
if (value === null) return true;
|
|
110
110
|
return typeof value === 'object' && value !== null && 'upload_id' in value;
|
|
111
111
|
}
|
|
@@ -118,12 +118,12 @@ export function isLocalizedFileFieldValue(
|
|
|
118
118
|
);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
export function
|
|
121
|
+
export function isLocalizedFileFieldValueInRequest(
|
|
122
122
|
value: unknown,
|
|
123
|
-
): value is LocalizedFieldValue<
|
|
123
|
+
): value is LocalizedFieldValue<FileFieldValueInRequest> {
|
|
124
124
|
return (
|
|
125
125
|
isLocalizedFieldValue(value) &&
|
|
126
|
-
Object.values(value).every(
|
|
126
|
+
Object.values(value).every(isFileFieldValueInRequest)
|
|
127
127
|
);
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
import type { GalleryEditorConfiguration } from './appearance/gallery';
|
|
6
6
|
import {
|
|
7
7
|
type FileFieldValue,
|
|
8
|
-
type
|
|
8
|
+
type FileFieldValueInRequest,
|
|
9
9
|
isFileFieldValue,
|
|
10
|
-
|
|
10
|
+
isFileFieldValueInRequest,
|
|
11
11
|
} from './file';
|
|
12
12
|
import type { ExtensionValidator } from './validators/extension';
|
|
13
13
|
import type { FileSizeValidator } from './validators/file_size';
|
|
@@ -25,7 +25,7 @@ import type { SizeValidator } from './validators/size';
|
|
|
25
25
|
* Individual gallery item types - extracted from File field types
|
|
26
26
|
*/
|
|
27
27
|
export type GalleryItem = NonNullable<FileFieldValue>;
|
|
28
|
-
export type
|
|
28
|
+
export type GalleryItemInRequest = NonNullable<FileFieldValueInRequest>;
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Gallery field value - response format with all metadata fields present
|
|
@@ -35,7 +35,7 @@ export type GalleryFieldValue = Array<GalleryItem>;
|
|
|
35
35
|
/**
|
|
36
36
|
* Gallery field value for API requests - metadata fields are optional
|
|
37
37
|
*/
|
|
38
|
-
export type
|
|
38
|
+
export type GalleryFieldValueInRequest = Array<GalleryItemInRequest>;
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* Type guard for Gallery field values - validates each item using File field validation
|
|
@@ -49,10 +49,10 @@ export function isGalleryFieldValue(
|
|
|
49
49
|
/**
|
|
50
50
|
* Type guard for Gallery field values in API request format
|
|
51
51
|
*/
|
|
52
|
-
export function
|
|
52
|
+
export function isGalleryFieldValueInRequest(
|
|
53
53
|
value: unknown,
|
|
54
|
-
): value is
|
|
55
|
-
return Array.isArray(value) && value.every(
|
|
54
|
+
): value is GalleryFieldValueInRequest {
|
|
55
|
+
return Array.isArray(value) && value.every(isFileFieldValueInRequest);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
export function isLocalizedGalleryFieldValue(
|
|
@@ -64,12 +64,12 @@ export function isLocalizedGalleryFieldValue(
|
|
|
64
64
|
);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
export function
|
|
67
|
+
export function isLocalizedGalleryFieldValueInRequest(
|
|
68
68
|
value: unknown,
|
|
69
|
-
): value is LocalizedFieldValue<
|
|
69
|
+
): value is LocalizedFieldValue<GalleryFieldValueInRequest> {
|
|
70
70
|
return (
|
|
71
71
|
isLocalizedFieldValue(value) &&
|
|
72
|
-
Object.values(value).every(
|
|
72
|
+
Object.values(value).every(isGalleryFieldValueInRequest)
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
1
|
+
import { isValidId } from '../utilities/id';
|
|
2
|
+
import type { ItemTypeDefinition } from '../utilities/itemDefinition';
|
|
3
3
|
import {
|
|
4
4
|
type LocalizedFieldValue,
|
|
5
5
|
isLocalizedFieldValue,
|
|
6
6
|
} from '../utilities/normalizedFieldValues';
|
|
7
7
|
import type { RichTextEditorConfiguration } from './appearance/rich_text';
|
|
8
8
|
import {
|
|
9
|
-
type
|
|
9
|
+
type BlockInNestedResponse,
|
|
10
|
+
type BlockInRequest,
|
|
10
11
|
isItemId,
|
|
11
12
|
isItemWithOptionalIdAndMeta,
|
|
12
13
|
isItemWithOptionalMeta,
|
|
@@ -64,9 +65,9 @@ export type RichTextFieldValue = string[];
|
|
|
64
65
|
* - RawApiTypes.Item: Full block object with ID (for updates)
|
|
65
66
|
* - Omit<RawApiTypes.Item, 'id'>: Block object without ID (for creation)
|
|
66
67
|
*/
|
|
67
|
-
export type
|
|
68
|
-
D extends
|
|
69
|
-
> =
|
|
68
|
+
export type RichTextFieldValueInRequest<
|
|
69
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
70
|
+
> = BlockInRequest<D>[] | null;
|
|
70
71
|
|
|
71
72
|
/**
|
|
72
73
|
* =============================================================================
|
|
@@ -81,9 +82,9 @@ export type RichTextFieldValueAsRequest<
|
|
|
81
82
|
/**
|
|
82
83
|
* Modular Content field value with nested blocks - array of fully populated block objects
|
|
83
84
|
*/
|
|
84
|
-
export type
|
|
85
|
-
D extends
|
|
86
|
-
> =
|
|
85
|
+
export type RichTextFieldValueInNestedResponse<
|
|
86
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
87
|
+
> = BlockInNestedResponse<D>[];
|
|
87
88
|
|
|
88
89
|
/**
|
|
89
90
|
* =============================================================================
|
|
@@ -99,7 +100,8 @@ export function isRichTextFieldValue(
|
|
|
99
100
|
value: unknown,
|
|
100
101
|
): value is RichTextFieldValue {
|
|
101
102
|
return (
|
|
102
|
-
Array.isArray(value) &&
|
|
103
|
+
Array.isArray(value) &&
|
|
104
|
+
value.every((block) => typeof block === 'string' && isValidId(block))
|
|
103
105
|
);
|
|
104
106
|
}
|
|
105
107
|
|
|
@@ -116,9 +118,9 @@ export function isLocalizedRichTextFieldValue(
|
|
|
116
118
|
* Type guard for Modular Content field values in API request format.
|
|
117
119
|
* Allows blocks as string IDs, full objects with IDs, or objects without IDs.
|
|
118
120
|
*/
|
|
119
|
-
export function
|
|
120
|
-
D extends
|
|
121
|
-
>(value: unknown): value is
|
|
121
|
+
export function isRichTextFieldValueInRequest<
|
|
122
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
123
|
+
>(value: unknown): value is RichTextFieldValueInRequest<D> {
|
|
122
124
|
if (value === null) return true;
|
|
123
125
|
|
|
124
126
|
if (!Array.isArray(value)) return false;
|
|
@@ -132,14 +134,14 @@ export function isRichTextFieldValueAsRequest<
|
|
|
132
134
|
});
|
|
133
135
|
}
|
|
134
136
|
|
|
135
|
-
export function
|
|
136
|
-
D extends
|
|
137
|
+
export function isLocalizedRichTextFieldValueInRequest<
|
|
138
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
137
139
|
>(
|
|
138
140
|
value: unknown,
|
|
139
|
-
): value is LocalizedFieldValue<
|
|
141
|
+
): value is LocalizedFieldValue<RichTextFieldValueInRequest<D>> {
|
|
140
142
|
return (
|
|
141
143
|
isLocalizedFieldValue(value) &&
|
|
142
|
-
Object.values(value).every(
|
|
144
|
+
Object.values(value).every(isRichTextFieldValueInRequest)
|
|
143
145
|
);
|
|
144
146
|
}
|
|
145
147
|
|
|
@@ -147,9 +149,9 @@ export function isLocalizedRichTextFieldValueAsRequest<
|
|
|
147
149
|
* Type guard for Modular Content field values with nested blocks (?nested=true format).
|
|
148
150
|
* Ensures all blocks are full RawApiTypes.Item objects with complete data.
|
|
149
151
|
*/
|
|
150
|
-
export function
|
|
151
|
-
D extends
|
|
152
|
-
>(value: unknown): value is
|
|
152
|
+
export function isRichTextFieldValueInNestedResponse<
|
|
153
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
154
|
+
>(value: unknown): value is RichTextFieldValueInNestedResponse<D> {
|
|
153
155
|
if (!Array.isArray(value)) return false;
|
|
154
156
|
|
|
155
157
|
return value.every((block) => {
|
|
@@ -158,14 +160,14 @@ export function isRichTextFieldValueWithNestedBlocks<
|
|
|
158
160
|
});
|
|
159
161
|
}
|
|
160
162
|
|
|
161
|
-
export function
|
|
162
|
-
D extends
|
|
163
|
+
export function isLocalizedRichTextFieldValueInNestedResponse<
|
|
164
|
+
D extends ItemTypeDefinition = ItemTypeDefinition,
|
|
163
165
|
>(
|
|
164
166
|
value: unknown,
|
|
165
|
-
): value is LocalizedFieldValue<
|
|
167
|
+
): value is LocalizedFieldValue<RichTextFieldValueInNestedResponse<D>> {
|
|
166
168
|
return (
|
|
167
169
|
isLocalizedFieldValue(value) &&
|
|
168
|
-
Object.values(value).every(
|
|
170
|
+
Object.values(value).every(isRichTextFieldValueInNestedResponse)
|
|
169
171
|
);
|
|
170
172
|
}
|
|
171
173
|
|