@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
|
@@ -9,19 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { isItemWithOptionalIdAndMeta, } from '../fieldTypes';
|
|
11
11
|
import { nonRecursiveFilterBlocksInNonLocalizedFieldValueAsync, nonRecursiveFindAllBlocksInNonLocalizedFieldValueAsync, nonRecursiveMapBlocksInNonLocalizedFieldValueAsync, nonRecursiveReduceBlocksInNonLocalizedFieldValueAsync, nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync, nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync, } from './nonRecursiveBlocks';
|
|
12
|
-
|
|
13
|
-
* Recursively visit every block in a non-localized field value and all nested blocks within those blocks.
|
|
14
|
-
* This function traverses not only the direct blocks in the non-localized field value but also recursively
|
|
15
|
-
* visits blocks contained within the attributes of each block, creating a complete traversal
|
|
16
|
-
* of the entire block hierarchy.
|
|
17
|
-
*
|
|
18
|
-
* @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
|
|
19
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
20
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to visit
|
|
21
|
-
* @param visitor - Asynchronous function called for each block found, including nested blocks
|
|
22
|
-
* @returns Promise that resolves when all blocks and nested blocks have been visited
|
|
23
|
-
*/
|
|
24
|
-
export function visitBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, visitor, path = []) {
|
|
12
|
+
export function visitBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, visitor, path = []) {
|
|
25
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
14
|
yield nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
27
15
|
yield visitor(block, [...path, ...innerPath]);
|
|
@@ -31,23 +19,12 @@ export function visitBlocksInNonLocalizedFieldValue(schemaRepository, fieldType,
|
|
|
31
19
|
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
32
20
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
33
21
|
for (const field of fields) {
|
|
34
|
-
yield visitBlocksInNonLocalizedFieldValue(
|
|
22
|
+
yield visitBlocksInNonLocalizedFieldValue(block.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, visitor, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
|
|
35
23
|
}
|
|
36
24
|
}));
|
|
37
25
|
});
|
|
38
26
|
}
|
|
39
|
-
|
|
40
|
-
* Recursively find all blocks that match the predicate function in a non-localized field value.
|
|
41
|
-
* Searches through all direct blocks and recursively through nested blocks within
|
|
42
|
-
* the attributes of each block, returning all matches found throughout the hierarchy.
|
|
43
|
-
*
|
|
44
|
-
* @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
|
|
45
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
46
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to search
|
|
47
|
-
* @param predicate - Asynchronous function that tests each block, including nested ones
|
|
48
|
-
* @returns Promise that resolves to an array of objects, each containing a matching block and its full path
|
|
49
|
-
*/
|
|
50
|
-
export function findAllBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, predicate, path = []) {
|
|
27
|
+
export function findAllBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, predicate, path = []) {
|
|
51
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
29
|
const results = [];
|
|
53
30
|
const directMatches = yield nonRecursiveFindAllBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () { return yield predicate(block, [...path, ...innerPath]); }));
|
|
@@ -62,60 +39,46 @@ export function findAllBlocksInNonLocalizedFieldValue(schemaRepository, fieldTyp
|
|
|
62
39
|
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
63
40
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
64
41
|
for (const field of fields) {
|
|
65
|
-
const nestedResults = yield findAllBlocksInNonLocalizedFieldValue(
|
|
42
|
+
const nestedResults = yield findAllBlocksInNonLocalizedFieldValue(block.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, predicate, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
|
|
66
43
|
results.push(...nestedResults);
|
|
67
44
|
}
|
|
68
45
|
}));
|
|
69
46
|
return results;
|
|
70
47
|
});
|
|
71
48
|
}
|
|
72
|
-
|
|
73
|
-
* Recursively filter blocks in a non-localized field value, removing those that don't match the predicate.
|
|
74
|
-
* Creates a new non-localized field value structure containing only blocks that pass the predicate test,
|
|
75
|
-
* including recursive filtering of nested blocks within block attributes. The filtering
|
|
76
|
-
* preserves the original non-localized field value structure and hierarchy.
|
|
77
|
-
*
|
|
78
|
-
* @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
|
|
79
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
80
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to filter
|
|
81
|
-
* @param predicate - Asynchronous function that tests each block, including nested ones
|
|
82
|
-
* @returns Promise that resolves to the new non-localized field value with recursively filtered blocks
|
|
83
|
-
*/
|
|
84
|
-
export function filterBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, predicate, path = []) {
|
|
49
|
+
export function filterBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, predicate, options = {}, path = []) {
|
|
85
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
|
|
51
|
+
const { traversalDirection = 'top-down' } = options;
|
|
52
|
+
const mapperFunc = (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
87
53
|
const blockPath = [...path, ...innerPath];
|
|
88
|
-
const passes = yield predicate(block, blockPath);
|
|
89
|
-
if (!passes) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
54
|
if (!isItemWithOptionalIdAndMeta(block)) {
|
|
93
|
-
return
|
|
55
|
+
return block;
|
|
94
56
|
}
|
|
95
57
|
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
96
58
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
59
|
+
if (traversalDirection === 'top-down') {
|
|
60
|
+
const blockCopy = Object.assign(Object.assign({}, block), { attributes: Object.assign({}, block.attributes) });
|
|
61
|
+
for (const field of fields) {
|
|
62
|
+
blockCopy.attributes[field.attributes.api_key] =
|
|
63
|
+
yield filterBlocksInNonLocalizedFieldValue(blockCopy.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, predicate, options, [...blockPath, 'attributes', field.attributes.api_key]);
|
|
64
|
+
}
|
|
65
|
+
return blockCopy;
|
|
66
|
+
}
|
|
67
|
+
const blockCopy = Object.assign(Object.assign({}, block), { attributes: Object.assign({}, block.attributes) });
|
|
97
68
|
for (const field of fields) {
|
|
98
|
-
|
|
99
|
-
yield filterBlocksInNonLocalizedFieldValue(
|
|
69
|
+
blockCopy.attributes[field.attributes.api_key] =
|
|
70
|
+
yield filterBlocksInNonLocalizedFieldValue(blockCopy.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, predicate, options, [...blockPath, 'attributes', field.attributes.api_key]);
|
|
100
71
|
}
|
|
101
|
-
return
|
|
72
|
+
return blockCopy;
|
|
73
|
+
});
|
|
74
|
+
const mappedValue = yield nonRecursiveMapBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, mapperFunc);
|
|
75
|
+
return nonRecursiveFilterBlocksInNonLocalizedFieldValueAsync(fieldType, mappedValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const blockPath = [...path, ...innerPath];
|
|
77
|
+
return yield predicate(block, blockPath);
|
|
102
78
|
}));
|
|
103
79
|
});
|
|
104
80
|
}
|
|
105
|
-
|
|
106
|
-
* Recursively reduce all blocks in a non-localized field value to a single value by applying a reducer function.
|
|
107
|
-
* Processes each direct block and recursively processes nested blocks within block attributes,
|
|
108
|
-
* accumulating results from the entire block hierarchy into a single value.
|
|
109
|
-
*
|
|
110
|
-
* @template R - The type of the accumulated result
|
|
111
|
-
* @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
|
|
112
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
113
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to reduce
|
|
114
|
-
* @param reducer - Asynchronous function that processes each block and updates the accumulator
|
|
115
|
-
* @param initialNonLocalizedFieldValue - The initial value for the accumulator
|
|
116
|
-
* @returns Promise that resolves to the final accumulated value from all blocks in the hierarchy
|
|
117
|
-
*/
|
|
118
|
-
export function reduceBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, reducer, initialValue, path = []) {
|
|
81
|
+
export function reduceBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, reducer, initialValue, path = []) {
|
|
119
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
120
83
|
let accumulator = yield nonRecursiveReduceBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (acc, block, innerPath) => __awaiter(this, void 0, void 0, function* () { return yield reducer(acc, block, [...path, ...innerPath]); }), initialValue);
|
|
121
84
|
yield nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -125,25 +88,13 @@ export function reduceBlocksInNonLocalizedFieldValue(schemaRepository, fieldType
|
|
|
125
88
|
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
126
89
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
127
90
|
for (const field of fields) {
|
|
128
|
-
accumulator = yield reduceBlocksInNonLocalizedFieldValue(
|
|
91
|
+
accumulator = yield reduceBlocksInNonLocalizedFieldValue(block.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, reducer, accumulator, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
|
|
129
92
|
}
|
|
130
93
|
}));
|
|
131
94
|
return accumulator;
|
|
132
95
|
});
|
|
133
96
|
}
|
|
134
|
-
|
|
135
|
-
* Recursively check if any block in the non-localized field value matches the predicate function.
|
|
136
|
-
* Tests both direct blocks and recursively tests nested blocks within block attributes.
|
|
137
|
-
* Returns true as soon as the first matching block is found anywhere in the hierarchy
|
|
138
|
-
* (short-circuit evaluation).
|
|
139
|
-
*
|
|
140
|
-
* @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
|
|
141
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
142
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
|
|
143
|
-
* @param predicate - Asynchronous function that tests each block, including nested ones
|
|
144
|
-
* @returns Promise that resolves to true if any block in the hierarchy matches, false otherwise
|
|
145
|
-
*/
|
|
146
|
-
export function someBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, predicate, path = []) {
|
|
97
|
+
export function someBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, predicate, path = []) {
|
|
147
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
148
99
|
const directMatch = yield nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () { return yield predicate(block, [...path, ...innerPath]); }));
|
|
149
100
|
if (directMatch) {
|
|
@@ -159,7 +110,7 @@ export function someBlocksInNonLocalizedFieldValue(schemaRepository, fieldType,
|
|
|
159
110
|
for (const field of fields) {
|
|
160
111
|
if (found)
|
|
161
112
|
break;
|
|
162
|
-
const nestedMatch = yield someBlocksInNonLocalizedFieldValue(
|
|
113
|
+
const nestedMatch = yield someBlocksInNonLocalizedFieldValue(block.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, predicate, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
|
|
163
114
|
if (nestedMatch) {
|
|
164
115
|
found = true;
|
|
165
116
|
}
|
|
@@ -168,49 +119,38 @@ export function someBlocksInNonLocalizedFieldValue(schemaRepository, fieldType,
|
|
|
168
119
|
return found;
|
|
169
120
|
});
|
|
170
121
|
}
|
|
171
|
-
|
|
172
|
-
* Recursively check if every block in the non-localized field value matches the predicate function.
|
|
173
|
-
* Tests both direct blocks and recursively tests nested blocks within block attributes.
|
|
174
|
-
* Returns false as soon as the first non-matching block is found anywhere in the hierarchy
|
|
175
|
-
* (short-circuit evaluation).
|
|
176
|
-
*
|
|
177
|
-
* @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
|
|
178
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
179
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
|
|
180
|
-
* @param predicate - Asynchronous function that tests each block, including nested ones
|
|
181
|
-
* @returns Promise that resolves to true if all blocks in the hierarchy match, false otherwise
|
|
182
|
-
*/
|
|
183
|
-
export function everyBlockInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, predicate, path = []) {
|
|
122
|
+
export function everyBlockInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, predicate, path = []) {
|
|
184
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
-
return !(yield someBlocksInNonLocalizedFieldValue(
|
|
124
|
+
return !(yield someBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, (item, path) => __awaiter(this, void 0, void 0, function* () { return !(yield predicate(item, path)); }), path));
|
|
186
125
|
});
|
|
187
126
|
}
|
|
188
|
-
|
|
189
|
-
* Recursively transform blocks in a non-localized field value by applying a mapping function to each block.
|
|
190
|
-
* Creates a new non-localized field value structure with transformed blocks while preserving the original
|
|
191
|
-
* structure. Applies the mapping function to both direct blocks and recursively to nested
|
|
192
|
-
* blocks within block attributes throughout the entire hierarchy.
|
|
193
|
-
*
|
|
194
|
-
* @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
|
|
195
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
196
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to transform
|
|
197
|
-
* @param mapper - Asynchronous function that transforms each block, including nested ones
|
|
198
|
-
* @returns Promise that resolves to the new non-localized field value with recursively transformed blocks
|
|
199
|
-
*/
|
|
200
|
-
export function mapBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, mapper, path = []) {
|
|
127
|
+
export function mapBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, mapper, options = {}, path = []) {
|
|
201
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
const { traversalDirection = 'top-down' } = options;
|
|
202
130
|
return nonRecursiveMapBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
203
|
-
const
|
|
204
|
-
if (!isItemWithOptionalIdAndMeta(
|
|
205
|
-
return
|
|
131
|
+
const blockPath = [...path, ...innerPath];
|
|
132
|
+
if (!isItemWithOptionalIdAndMeta(block)) {
|
|
133
|
+
return yield mapper(block, blockPath);
|
|
206
134
|
}
|
|
207
|
-
const itemType = yield schemaRepository.getRawItemTypeById(
|
|
135
|
+
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
208
136
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
137
|
+
if (traversalDirection === 'top-down') {
|
|
138
|
+
const newBlock = yield mapper(block, blockPath);
|
|
139
|
+
if (!isItemWithOptionalIdAndMeta(newBlock)) {
|
|
140
|
+
return newBlock;
|
|
141
|
+
}
|
|
142
|
+
for (const field of fields) {
|
|
143
|
+
newBlock.attributes[field.attributes.api_key] =
|
|
144
|
+
yield mapBlocksInNonLocalizedFieldValue(newBlock.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, mapper, options, [...blockPath, 'attributes', field.attributes.api_key]);
|
|
145
|
+
}
|
|
146
|
+
return newBlock;
|
|
147
|
+
}
|
|
148
|
+
const blockCopy = Object.assign({}, block);
|
|
209
149
|
for (const field of fields) {
|
|
210
|
-
|
|
211
|
-
yield mapBlocksInNonLocalizedFieldValue(
|
|
150
|
+
blockCopy.attributes[field.attributes.api_key] =
|
|
151
|
+
yield mapBlocksInNonLocalizedFieldValue(blockCopy.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, mapper, options, [...blockPath, 'attributes', field.attributes.api_key]);
|
|
212
152
|
}
|
|
213
|
-
return
|
|
153
|
+
return yield mapper(blockCopy, blockPath);
|
|
214
154
|
}));
|
|
215
155
|
});
|
|
216
156
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recursiveBlocks.js","sourceRoot":"","sources":["../../../src/utilities/recursiveBlocks.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"recursiveBlocks.js","sourceRoot":"","sources":["../../../src/utilities/recursiveBlocks.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EA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AE;gBAC1B,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC;oBAC5C,MAAM,iCAAiC,CACrC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,EAC9C,KAAK,CAAC,UAAU,CAAC,UAAU,EAC3B,gBAAgB,EAEhB,MAAM,EACN,OAAO,EACP,CAAC,GAAG,SAAS,EAAE,YAAY,EAAE,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CACvD,CAAC;aACL;YAED,OAAO,MAAM,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAC5C,CAAC,CAAA,CACF,CAAC;IACJ,CAAC;CAAA"}
|
|
@@ -58,7 +58,7 @@ export type FileFieldValue = {
|
|
|
58
58
|
/**
|
|
59
59
|
* File field value for API requests - metadata fields are optional
|
|
60
60
|
*/
|
|
61
|
-
export type
|
|
61
|
+
export type FileFieldValueInRequest = {
|
|
62
62
|
upload_id: string;
|
|
63
63
|
alt?: string | null;
|
|
64
64
|
title?: string | null;
|
|
@@ -82,9 +82,9 @@ export declare function isFileFieldValue(value: unknown): value is FileFieldValu
|
|
|
82
82
|
* Type guard for File field values in API request format.
|
|
83
83
|
* Allows metadata fields to be optional or omitted.
|
|
84
84
|
*/
|
|
85
|
-
export declare function
|
|
85
|
+
export declare function isFileFieldValueInRequest(value: unknown): value is FileFieldValueInRequest;
|
|
86
86
|
export declare function isLocalizedFileFieldValue(value: unknown): value is LocalizedFieldValue<FileFieldValue>;
|
|
87
|
-
export declare function
|
|
87
|
+
export declare function isLocalizedFileFieldValueInRequest(value: unknown): value is LocalizedFieldValue<FileFieldValueInRequest>;
|
|
88
88
|
export type FileFieldValidators = {
|
|
89
89
|
/** Value must be specified or it won't be valid */
|
|
90
90
|
required?: RequiredValidator;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type LocalizedFieldValue } from '../utilities/normalizedFieldValues';
|
|
2
2
|
import type { GalleryEditorConfiguration } from './appearance/gallery';
|
|
3
|
-
import { type FileFieldValue, type
|
|
3
|
+
import { type FileFieldValue, type FileFieldValueInRequest } from './file';
|
|
4
4
|
import type { ExtensionValidator } from './validators/extension';
|
|
5
5
|
import type { FileSizeValidator } from './validators/file_size';
|
|
6
6
|
import type { ImageAspectRatioValidator } from './validators/image_aspect_ratio';
|
|
@@ -15,7 +15,7 @@ import type { SizeValidator } from './validators/size';
|
|
|
15
15
|
* Individual gallery item types - extracted from File field types
|
|
16
16
|
*/
|
|
17
17
|
export type GalleryItem = NonNullable<FileFieldValue>;
|
|
18
|
-
export type
|
|
18
|
+
export type GalleryItemInRequest = NonNullable<FileFieldValueInRequest>;
|
|
19
19
|
/**
|
|
20
20
|
* Gallery field value - response format with all metadata fields present
|
|
21
21
|
*/
|
|
@@ -23,7 +23,7 @@ export type GalleryFieldValue = Array<GalleryItem>;
|
|
|
23
23
|
/**
|
|
24
24
|
* Gallery field value for API requests - metadata fields are optional
|
|
25
25
|
*/
|
|
26
|
-
export type
|
|
26
|
+
export type GalleryFieldValueInRequest = Array<GalleryItemInRequest>;
|
|
27
27
|
/**
|
|
28
28
|
* Type guard for Gallery field values - validates each item using File field validation
|
|
29
29
|
*/
|
|
@@ -31,9 +31,9 @@ export declare function isGalleryFieldValue(value: unknown): value is GalleryFie
|
|
|
31
31
|
/**
|
|
32
32
|
* Type guard for Gallery field values in API request format
|
|
33
33
|
*/
|
|
34
|
-
export declare function
|
|
34
|
+
export declare function isGalleryFieldValueInRequest(value: unknown): value is GalleryFieldValueInRequest;
|
|
35
35
|
export declare function isLocalizedGalleryFieldValue(value: unknown): value is LocalizedFieldValue<GalleryFieldValue>;
|
|
36
|
-
export declare function
|
|
36
|
+
export declare function isLocalizedGalleryFieldValueInRequest(value: unknown): value is LocalizedFieldValue<GalleryFieldValueInRequest>;
|
|
37
37
|
export type GalleryFieldValidators = {
|
|
38
38
|
/** Only accept a number of items within the specified range */
|
|
39
39
|
size?: SizeValidator;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { ItemDefinition } from '../utilities/itemDefinition';
|
|
1
|
+
import type { ItemTypeDefinition } from '../utilities/itemDefinition';
|
|
3
2
|
import { type LocalizedFieldValue } from '../utilities/normalizedFieldValues';
|
|
4
3
|
import type { RichTextEditorConfiguration } from './appearance/rich_text';
|
|
5
|
-
import { type
|
|
4
|
+
import { type BlockInNestedResponse, type BlockInRequest } from './single_block';
|
|
6
5
|
import type { RichTextBlocksValidator } from './validators/rich_text_blocks';
|
|
7
6
|
import type { SizeValidator } from './validators/size';
|
|
8
7
|
/**
|
|
@@ -51,7 +50,7 @@ export type RichTextFieldValue = string[];
|
|
|
51
50
|
* - RawApiTypes.Item: Full block object with ID (for updates)
|
|
52
51
|
* - Omit<RawApiTypes.Item, 'id'>: Block object without ID (for creation)
|
|
53
52
|
*/
|
|
54
|
-
export type
|
|
53
|
+
export type RichTextFieldValueInRequest<D extends ItemTypeDefinition = ItemTypeDefinition> = BlockInRequest<D>[] | null;
|
|
55
54
|
/**
|
|
56
55
|
* =============================================================================
|
|
57
56
|
* NESTED VARIANT - Type for API responses with ?nested=true parameter
|
|
@@ -64,7 +63,7 @@ export type RichTextFieldValueAsRequest<D extends ItemDefinition = ItemDefinitio
|
|
|
64
63
|
/**
|
|
65
64
|
* Modular Content field value with nested blocks - array of fully populated block objects
|
|
66
65
|
*/
|
|
67
|
-
export type
|
|
66
|
+
export type RichTextFieldValueInNestedResponse<D extends ItemTypeDefinition = ItemTypeDefinition> = BlockInNestedResponse<D>[];
|
|
68
67
|
/**
|
|
69
68
|
* =============================================================================
|
|
70
69
|
* TYPE GUARDS - Runtime validation functions
|
|
@@ -80,14 +79,14 @@ export declare function isLocalizedRichTextFieldValue(value: unknown): value is
|
|
|
80
79
|
* Type guard for Modular Content field values in API request format.
|
|
81
80
|
* Allows blocks as string IDs, full objects with IDs, or objects without IDs.
|
|
82
81
|
*/
|
|
83
|
-
export declare function
|
|
84
|
-
export declare function
|
|
82
|
+
export declare function isRichTextFieldValueInRequest<D extends ItemTypeDefinition = ItemTypeDefinition>(value: unknown): value is RichTextFieldValueInRequest<D>;
|
|
83
|
+
export declare function isLocalizedRichTextFieldValueInRequest<D extends ItemTypeDefinition = ItemTypeDefinition>(value: unknown): value is LocalizedFieldValue<RichTextFieldValueInRequest<D>>;
|
|
85
84
|
/**
|
|
86
85
|
* Type guard for Modular Content field values with nested blocks (?nested=true format).
|
|
87
86
|
* Ensures all blocks are full RawApiTypes.Item objects with complete data.
|
|
88
87
|
*/
|
|
89
|
-
export declare function
|
|
90
|
-
export declare function
|
|
88
|
+
export declare function isRichTextFieldValueInNestedResponse<D extends ItemTypeDefinition = ItemTypeDefinition>(value: unknown): value is RichTextFieldValueInNestedResponse<D>;
|
|
89
|
+
export declare function isLocalizedRichTextFieldValueInNestedResponse<D extends ItemTypeDefinition = ItemTypeDefinition>(value: unknown): value is LocalizedFieldValue<RichTextFieldValueInNestedResponse<D>>;
|
|
91
90
|
export type RichTextFieldValidators = {
|
|
92
91
|
/** Only accept references to block records of the specified block models */
|
|
93
92
|
rich_text_blocks: RichTextBlocksValidator;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { BooleanFieldAppearance, BooleanFieldValidators, BooleanFieldValue, ColorFieldAppearance, ColorFieldValidators, ColorFieldValue, DateFieldAppearance, DateFieldValidators, DateFieldValue, DateTimeFieldAppearance, DateTimeFieldValidators, DateTimeFieldValue, FileFieldAppearance, FileFieldValidators, FloatFieldAppearance, FloatFieldValidators, FloatFieldValue, GalleryFieldAppearance, GalleryFieldValidators, IntegerFieldAppearance, IntegerFieldValidators, IntegerFieldValue, JsonFieldAppearance, JsonFieldValidators, JsonFieldValue, LatLonFieldAppearance, LatLonFieldValidators, LatLonFieldValue, LinkFieldAppearance, LinkFieldValidators, LinksFieldAppearance, LinksFieldValidators, RichTextFieldAppearance, RichTextFieldValidators, SeoFieldAppearance, SeoFieldValidators, SingleBlockFieldAppearance, SingleBlockFieldValidators, SlugFieldAppearance, SlugFieldValidators, StringFieldAppearance, StringFieldValidators, StringFieldValue, StructuredTextFieldAppearance, StructuredTextFieldValidators, TextFieldAppearance, TextFieldValidators, TextFieldValue, VideoFieldAppearance, VideoFieldValidators } from '..';
|
|
2
|
+
import type { FieldAttributesStableShell } from '../generated/RawApiTypes';
|
|
3
|
+
/**
|
|
4
|
+
* Enhanced appearance configuration with field-specific types and addon support
|
|
5
|
+
*/
|
|
6
|
+
type FieldAppearanceConfig<TAppearance> = TAppearance & Omit<FieldAttributesStableShell['appearance'], keyof TAppearance>;
|
|
7
|
+
/**
|
|
8
|
+
* Base field configuration for attributes (non-localized), extending the original RawApiTypes
|
|
9
|
+
*/
|
|
10
|
+
type NonLocalizedFieldAttributesForFieldType<SourceType, FieldType extends FieldAttributesStableShell['field_type'], FieldValue, FieldValidators, FieldAppearance> = Omit<SourceType, 'field_type' | 'default_value' | 'validators' | 'appearance' | 'localized'> & {
|
|
11
|
+
field_type: FieldType;
|
|
12
|
+
localized: false;
|
|
13
|
+
default_value: FieldValue;
|
|
14
|
+
validators: FieldValidators;
|
|
15
|
+
appearance: FieldAppearanceConfig<FieldAppearance>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Base field configuration for attributes (localized), extending the original RawApiTypes
|
|
19
|
+
*/
|
|
20
|
+
type LocalizedFieldAttributesForFieldType<SourceType, FieldType extends FieldAttributesStableShell['field_type'], FieldValue, FieldValidators, FieldAppearance> = Omit<SourceType, 'field_type' | 'default_value' | 'validators' | 'appearance' | 'localized'> & {
|
|
21
|
+
field_type: FieldType;
|
|
22
|
+
localized: true;
|
|
23
|
+
default_value: Record<string, FieldValue>;
|
|
24
|
+
validators: FieldValidators;
|
|
25
|
+
appearance: FieldAppearanceConfig<FieldAppearance>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Union of localized and non-localized field configurations for attributes
|
|
29
|
+
*/
|
|
30
|
+
type FieldAttributesForFieldType<SourceType, FieldType extends FieldAttributesStableShell['field_type'], FieldValue, FieldValidators, FieldAppearance> = NonLocalizedFieldAttributesForFieldType<SourceType, FieldType, FieldValue, FieldValidators, FieldAppearance> | LocalizedFieldAttributesForFieldType<SourceType, FieldType, FieldValue, FieldValidators, FieldAppearance>;
|
|
31
|
+
export type GenericFieldAttributes<SourceType> = FieldAttributesForFieldType<SourceType, 'boolean', BooleanFieldValue, BooleanFieldValidators, BooleanFieldAppearance> | FieldAttributesForFieldType<SourceType, 'color', ColorFieldValue, ColorFieldValidators, ColorFieldAppearance> | FieldAttributesForFieldType<SourceType, 'date', DateFieldValue, DateFieldValidators, DateFieldAppearance> | FieldAttributesForFieldType<SourceType, 'date_time', DateTimeFieldValue, DateTimeFieldValidators, DateTimeFieldAppearance> | FieldAttributesForFieldType<SourceType, 'file', null, FileFieldValidators, FileFieldAppearance> | FieldAttributesForFieldType<SourceType, 'float', FloatFieldValue, FloatFieldValidators, FloatFieldAppearance> | FieldAttributesForFieldType<SourceType, 'gallery', null, GalleryFieldValidators, GalleryFieldAppearance> | FieldAttributesForFieldType<SourceType, 'integer', IntegerFieldValue, IntegerFieldValidators, IntegerFieldAppearance> | FieldAttributesForFieldType<SourceType, 'json', JsonFieldValue, JsonFieldValidators, JsonFieldAppearance> | FieldAttributesForFieldType<SourceType, 'lat_lon', LatLonFieldValue, LatLonFieldValidators, LatLonFieldAppearance> | FieldAttributesForFieldType<SourceType, 'link', null, LinkFieldValidators, LinkFieldAppearance> | FieldAttributesForFieldType<SourceType, 'links', null, LinksFieldValidators, LinksFieldAppearance> | FieldAttributesForFieldType<SourceType, 'rich_text', null, RichTextFieldValidators, RichTextFieldAppearance> | FieldAttributesForFieldType<SourceType, 'seo', null, SeoFieldValidators, SeoFieldAppearance> | FieldAttributesForFieldType<SourceType, 'single_block', null, SingleBlockFieldValidators, SingleBlockFieldAppearance> | FieldAttributesForFieldType<SourceType, 'slug', null, SlugFieldValidators, SlugFieldAppearance> | FieldAttributesForFieldType<SourceType, 'string', StringFieldValue, StringFieldValidators, StringFieldAppearance> | FieldAttributesForFieldType<SourceType, 'structured_text', null, StructuredTextFieldValidators, StructuredTextFieldAppearance> | FieldAttributesForFieldType<SourceType, 'text', TextFieldValue, TextFieldValidators, TextFieldAppearance> | FieldAttributesForFieldType<SourceType, 'video', null, VideoFieldValidators, VideoFieldAppearance>;
|
|
32
|
+
type LocalizedFieldCreateConfigForFieldType<SourceType, FieldType extends FieldAttributesStableShell['field_type'], FieldValue, FieldValidators, FieldAppearance> = Omit<SourceType, 'field_type' | 'default_value' | 'validators' | 'appearance' | 'localized'> & {
|
|
33
|
+
field_type: FieldType;
|
|
34
|
+
localized: true;
|
|
35
|
+
default_value?: Record<string, FieldValue>;
|
|
36
|
+
validators?: FieldValidators;
|
|
37
|
+
appearance?: FieldAppearanceConfig<FieldAppearance>;
|
|
38
|
+
};
|
|
39
|
+
type NonLocalizedFieldCreateConfigForFieldType<SourceType, FieldType extends FieldAttributesStableShell['field_type'], FieldValue, FieldValidators, FieldAppearance> = Omit<SourceType, 'field_type' | 'default_value' | 'validators' | 'appearance' | 'localized'> & {
|
|
40
|
+
field_type: FieldType;
|
|
41
|
+
localized?: false;
|
|
42
|
+
default_value?: FieldValue;
|
|
43
|
+
validators?: FieldValidators;
|
|
44
|
+
appearance?: FieldAppearanceConfig<FieldAppearance>;
|
|
45
|
+
};
|
|
46
|
+
type FieldCreateConfigForFieldType<SourceType, FieldType extends FieldAttributesStableShell['field_type'], FieldValue, FieldValidators, FieldAppearance> = LocalizedFieldCreateConfigForFieldType<SourceType, FieldType, FieldValue, FieldValidators, FieldAppearance> | NonLocalizedFieldCreateConfigForFieldType<SourceType, FieldType, FieldValue, FieldValidators, FieldAppearance>;
|
|
47
|
+
export type FieldCreateConfig<SourceType> = FieldCreateConfigForFieldType<SourceType, 'boolean', BooleanFieldValue, BooleanFieldValidators, BooleanFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'color', ColorFieldValue, ColorFieldValidators, ColorFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'date', DateFieldValue, DateFieldValidators, DateFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'date_time', DateTimeFieldValue, DateTimeFieldValidators, DateTimeFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'file', null, FileFieldValidators, FileFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'float', FloatFieldValue, FloatFieldValidators, FloatFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'gallery', null, GalleryFieldValidators, GalleryFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'integer', IntegerFieldValue, IntegerFieldValidators, IntegerFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'json', JsonFieldValue, JsonFieldValidators, JsonFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'lat_lon', LatLonFieldValue, LatLonFieldValidators, LatLonFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'link', null, LinkFieldValidators, LinkFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'links', null, LinksFieldValidators, LinksFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'rich_text', null, RichTextFieldValidators, RichTextFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'seo', null, SeoFieldValidators, SeoFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'single_block', null, SingleBlockFieldValidators, SingleBlockFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'slug', null, SlugFieldValidators, SlugFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'string', StringFieldValue, StringFieldValidators, StringFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'structured_text', null, StructuredTextFieldValidators, StructuredTextFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'text', TextFieldValue, TextFieldValidators, TextFieldAppearance> | FieldCreateConfigForFieldType<SourceType, 'video', null, VideoFieldValidators, VideoFieldAppearance>;
|
|
48
|
+
/**
|
|
49
|
+
* Helper type to conditionally handle default values based on localization for field updates
|
|
50
|
+
*/
|
|
51
|
+
type FieldUpdateDefaultValue<T> = T | Record<string, T> | undefined;
|
|
52
|
+
type FieldUpdateConfigForFieldType<SourceType, FieldType extends FieldAttributesStableShell['field_type'], FieldValue, FieldValidators, FieldAppearance> = Omit<SourceType, 'field_type' | 'default_value' | 'validators' | 'appearance'> & {
|
|
53
|
+
field_type?: FieldType;
|
|
54
|
+
default_value?: FieldUpdateDefaultValue<FieldValue>;
|
|
55
|
+
validators?: FieldValidators;
|
|
56
|
+
appearance?: FieldAppearanceConfig<FieldAppearance>;
|
|
57
|
+
};
|
|
58
|
+
export type FieldUpdateConfig<SourceType> = FieldUpdateConfigForFieldType<SourceType, 'boolean', BooleanFieldValue, BooleanFieldValidators, BooleanFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'color', ColorFieldValue, ColorFieldValidators, ColorFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'date', DateFieldValue, DateFieldValidators, DateFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'date_time', DateTimeFieldValue, DateTimeFieldValidators, DateTimeFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'file', null, FileFieldValidators, FileFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'float', FloatFieldValue, FloatFieldValidators, FloatFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'gallery', null, GalleryFieldValidators, GalleryFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'integer', IntegerFieldValue, IntegerFieldValidators, IntegerFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'json', JsonFieldValue, JsonFieldValidators, JsonFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'lat_lon', LatLonFieldValue, LatLonFieldValidators, LatLonFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'link', null, LinkFieldValidators, LinkFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'links', null, LinksFieldValidators, LinksFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'rich_text', null, RichTextFieldValidators, RichTextFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'seo', null, SeoFieldValidators, SeoFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'single_block', null, SingleBlockFieldValidators, SingleBlockFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'slug', null, SlugFieldValidators, SlugFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'string', StringFieldValue, StringFieldValidators, StringFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'structured_text', null, StructuredTextFieldValidators, StructuredTextFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'text', TextFieldValue, TextFieldValidators, TextFieldAppearance> | FieldUpdateConfigForFieldType<SourceType, 'video', null, VideoFieldValidators, VideoFieldAppearance>;
|
|
59
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as RawApiTypes from '../generated/RawApiTypes';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ItemTypeDefinition, ToItemAttributesInRequest } from '../utilities/itemDefinition';
|
|
3
3
|
import { type LocalizedFieldValue } from '../utilities/normalizedFieldValues';
|
|
4
4
|
import type { FramedSingleBlockEditorConfiguration } from './appearance/framed_single_block';
|
|
5
5
|
import type { FramelessSingleBlockEditorConfiguration } from './appearance/frameless_single_block';
|
|
@@ -46,11 +46,25 @@ export type SingleBlockFieldValue = string | null;
|
|
|
46
46
|
* - Omit ID for new blocks being created
|
|
47
47
|
*/
|
|
48
48
|
/** Represents an existing block in a CMA request */
|
|
49
|
-
export type
|
|
49
|
+
export type UnchangedBlockInRequest = RawApiTypes.ItemIdentity;
|
|
50
50
|
/** Represents a block we want to update in a CMA request */
|
|
51
|
-
export type
|
|
51
|
+
export type UpdatedBlockInRequest<D extends ItemTypeDefinition = ItemTypeDefinition> = {
|
|
52
|
+
__itemTypeId?: D['itemTypeId'];
|
|
53
|
+
type: RawApiTypes.ItemType1;
|
|
54
|
+
id: RawApiTypes.ItemIdentity;
|
|
55
|
+
relationships: RawApiTypes.ItemRelationships<D>;
|
|
56
|
+
meta?: RawApiTypes.ItemMeta;
|
|
57
|
+
attributes: ToItemAttributesInRequest<D>;
|
|
58
|
+
};
|
|
52
59
|
/** Represents a new block to create in a CMA request */
|
|
53
|
-
export type
|
|
60
|
+
export type NewBlockInRequest<D extends ItemTypeDefinition = ItemTypeDefinition> = {
|
|
61
|
+
__itemTypeId?: D['itemTypeId'];
|
|
62
|
+
type: RawApiTypes.ItemType1;
|
|
63
|
+
id?: RawApiTypes.ItemIdentity;
|
|
64
|
+
relationships: RawApiTypes.ItemRelationships<D>;
|
|
65
|
+
meta?: RawApiTypes.ItemMeta;
|
|
66
|
+
attributes: ToItemAttributesInRequest<D>;
|
|
67
|
+
};
|
|
54
68
|
/**
|
|
55
69
|
* Union type representing the different ways a block can be specified in API requests:
|
|
56
70
|
* - string: Just the block ID (to keep existing blocks unchanged)
|
|
@@ -59,14 +73,15 @@ export type NewBlockInARequest<D extends ItemDefinition = ItemDefinition> = D ex
|
|
|
59
73
|
*
|
|
60
74
|
* Also, 'meta' can always be omitted
|
|
61
75
|
*/
|
|
62
|
-
export type
|
|
76
|
+
export type BlockInRequest<D extends ItemTypeDefinition = ItemTypeDefinition> = UnchangedBlockInRequest | UpdatedBlockInRequest<D> | NewBlockInRequest<D>;
|
|
77
|
+
export type BlockInNestedResponse<D extends ItemTypeDefinition = ItemTypeDefinition> = D extends unknown ? RawApiTypes.ItemInNestedResponse<D> : never;
|
|
63
78
|
/**
|
|
64
79
|
* Single Block field value for API requests - allows flexible block representations:
|
|
65
80
|
* - string: Just the block ID (to keep existing blocks unchanged)
|
|
66
81
|
* - Full block object with ID (to update an existing block)
|
|
67
82
|
* - Block object without ID (to create a new block)
|
|
68
83
|
*/
|
|
69
|
-
export type
|
|
84
|
+
export type SingleBlockFieldValueInRequest<D extends ItemTypeDefinition = ItemTypeDefinition> = BlockInRequest<D> | null;
|
|
70
85
|
/**
|
|
71
86
|
* =============================================================================
|
|
72
87
|
* NESTED VARIANT - Type for API responses with ?nested=true parameter
|
|
@@ -79,7 +94,7 @@ export type SingleBlockFieldValueAsRequest<D extends ItemDefinition = ItemDefini
|
|
|
79
94
|
/**
|
|
80
95
|
* Single Block field value with nested block - fully populated block object
|
|
81
96
|
*/
|
|
82
|
-
export type
|
|
97
|
+
export type SingleBlockFieldValueInNestedResponse<D extends ItemTypeDefinition = ItemTypeDefinition> = BlockInNestedResponse<D> | null;
|
|
83
98
|
/**
|
|
84
99
|
* =============================================================================
|
|
85
100
|
* SHARED UTILITY FUNCTIONS
|
|
@@ -90,16 +105,16 @@ export type SingleBlockFieldValueWithNestedBlocks<D extends ItemDefinition = Ite
|
|
|
90
105
|
* Validates if the input is a valid item (either block or record) ID
|
|
91
106
|
*/
|
|
92
107
|
export declare function isItemId(input: unknown): input is string;
|
|
93
|
-
export type ItemWithOptionalIdAndMeta<D extends
|
|
108
|
+
export type ItemWithOptionalIdAndMeta<D extends ItemTypeDefinition = ItemTypeDefinition> = D extends any ? OptionalFields<RawApiTypes.Item<D>, 'id' | 'meta'> : never;
|
|
94
109
|
/**
|
|
95
110
|
* Validates if the input is a RawApiTypes.Item object (with optional `id` and `meta`)
|
|
96
111
|
*/
|
|
97
|
-
export declare function isItemWithOptionalIdAndMeta<D extends
|
|
98
|
-
export type ItemWithOptionalMeta<D extends
|
|
112
|
+
export declare function isItemWithOptionalIdAndMeta<D extends ItemTypeDefinition = ItemTypeDefinition>(block: unknown): block is ItemWithOptionalIdAndMeta<D>;
|
|
113
|
+
export type ItemWithOptionalMeta<D extends ItemTypeDefinition = ItemTypeDefinition> = D extends any ? OptionalFields<RawApiTypes.Item<D>, 'meta'> : never;
|
|
99
114
|
/**
|
|
100
115
|
* Validates if the input is a a complete RawApiTypes.Item object with optional `meta`
|
|
101
116
|
*/
|
|
102
|
-
export declare function isItemWithOptionalMeta<D extends
|
|
117
|
+
export declare function isItemWithOptionalMeta<D extends ItemTypeDefinition = ItemTypeDefinition>(block: unknown): block is ItemWithOptionalMeta<D>;
|
|
103
118
|
/**
|
|
104
119
|
* =============================================================================
|
|
105
120
|
* TYPE GUARDS - Runtime validation functions
|
|
@@ -115,14 +130,14 @@ export declare function isLocalizedSingleBlockFieldValue(value: unknown): value
|
|
|
115
130
|
* Type guard for Single Block field values in API request format.
|
|
116
131
|
* Allows block as string ID, full object with ID, or object without ID.
|
|
117
132
|
*/
|
|
118
|
-
export declare function
|
|
119
|
-
export declare function
|
|
133
|
+
export declare function isSingleBlockFieldValueInRequest<D extends ItemTypeDefinition = ItemTypeDefinition>(value: unknown): value is SingleBlockFieldValueInRequest<D>;
|
|
134
|
+
export declare function isLocalizedSingleBlockFieldValueInRequest<D extends ItemTypeDefinition = ItemTypeDefinition>(value: unknown): value is LocalizedFieldValue<SingleBlockFieldValueInRequest<D>>;
|
|
120
135
|
/**
|
|
121
136
|
* Type guard for Single Block field values with nested blocks (?nested=true format).
|
|
122
137
|
* Ensures block is a full RawApiTypes.Item object with complete data.
|
|
123
138
|
*/
|
|
124
|
-
export declare function
|
|
125
|
-
export declare function
|
|
139
|
+
export declare function isSingleBlockFieldValueInNestedResponse<D extends ItemTypeDefinition = ItemTypeDefinition>(value: unknown): value is SingleBlockFieldValueInNestedResponse<D>;
|
|
140
|
+
export declare function isLocalizedSingleBlockFieldValueInNestedResponse<D extends ItemTypeDefinition = ItemTypeDefinition>(value: unknown): value is LocalizedFieldValue<SingleBlockFieldValueInNestedResponse<D>>;
|
|
126
141
|
export type SingleBlockFieldValidators = {
|
|
127
142
|
/** Only accept references to block records of the specified block models */
|
|
128
143
|
single_block_blocks: SingleBlockBlocksValidator;
|