@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
|
@@ -12,19 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.mapBlocksInNonLocalizedFieldValue = exports.everyBlockInNonLocalizedFieldValue = exports.someBlocksInNonLocalizedFieldValue = exports.reduceBlocksInNonLocalizedFieldValue = exports.filterBlocksInNonLocalizedFieldValue = exports.findAllBlocksInNonLocalizedFieldValue = exports.visitBlocksInNonLocalizedFieldValue = void 0;
|
|
13
13
|
const fieldTypes_1 = require("../fieldTypes");
|
|
14
14
|
const nonRecursiveBlocks_1 = require("./nonRecursiveBlocks");
|
|
15
|
-
|
|
16
|
-
* Recursively visit every block in a non-localized field value and all nested blocks within those blocks.
|
|
17
|
-
* This function traverses not only the direct blocks in the non-localized field value but also recursively
|
|
18
|
-
* visits blocks contained within the attributes of each block, creating a complete traversal
|
|
19
|
-
* of the entire block hierarchy.
|
|
20
|
-
*
|
|
21
|
-
* @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
|
|
22
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
23
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to visit
|
|
24
|
-
* @param visitor - Asynchronous function called for each block found, including nested blocks
|
|
25
|
-
* @returns Promise that resolves when all blocks and nested blocks have been visited
|
|
26
|
-
*/
|
|
27
|
-
function visitBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, visitor, path = []) {
|
|
15
|
+
function visitBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, visitor, path = []) {
|
|
28
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
17
|
yield (0, nonRecursiveBlocks_1.nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync)(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
30
18
|
yield visitor(block, [...path, ...innerPath]);
|
|
@@ -34,24 +22,13 @@ function visitBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLoc
|
|
|
34
22
|
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
35
23
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
36
24
|
for (const field of fields) {
|
|
37
|
-
yield visitBlocksInNonLocalizedFieldValue(
|
|
25
|
+
yield visitBlocksInNonLocalizedFieldValue(block.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, visitor, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
|
|
38
26
|
}
|
|
39
27
|
}));
|
|
40
28
|
});
|
|
41
29
|
}
|
|
42
30
|
exports.visitBlocksInNonLocalizedFieldValue = visitBlocksInNonLocalizedFieldValue;
|
|
43
|
-
|
|
44
|
-
* Recursively find all blocks that match the predicate function in a non-localized field value.
|
|
45
|
-
* Searches through all direct blocks and recursively through nested blocks within
|
|
46
|
-
* the attributes of each block, returning all matches found throughout the hierarchy.
|
|
47
|
-
*
|
|
48
|
-
* @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
|
|
49
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
50
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to search
|
|
51
|
-
* @param predicate - Asynchronous function that tests each block, including nested ones
|
|
52
|
-
* @returns Promise that resolves to an array of objects, each containing a matching block and its full path
|
|
53
|
-
*/
|
|
54
|
-
function findAllBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, predicate, path = []) {
|
|
31
|
+
function findAllBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, predicate, path = []) {
|
|
55
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
33
|
const results = [];
|
|
57
34
|
const directMatches = yield (0, nonRecursiveBlocks_1.nonRecursiveFindAllBlocksInNonLocalizedFieldValueAsync)(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () { return yield predicate(block, [...path, ...innerPath]); }));
|
|
@@ -66,7 +43,7 @@ function findAllBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonL
|
|
|
66
43
|
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
67
44
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
68
45
|
for (const field of fields) {
|
|
69
|
-
const nestedResults = yield findAllBlocksInNonLocalizedFieldValue(
|
|
46
|
+
const nestedResults = yield findAllBlocksInNonLocalizedFieldValue(block.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, predicate, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
|
|
70
47
|
results.push(...nestedResults);
|
|
71
48
|
}
|
|
72
49
|
}));
|
|
@@ -74,54 +51,40 @@ function findAllBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonL
|
|
|
74
51
|
});
|
|
75
52
|
}
|
|
76
53
|
exports.findAllBlocksInNonLocalizedFieldValue = findAllBlocksInNonLocalizedFieldValue;
|
|
77
|
-
|
|
78
|
-
* Recursively filter blocks in a non-localized field value, removing those that don't match the predicate.
|
|
79
|
-
* Creates a new non-localized field value structure containing only blocks that pass the predicate test,
|
|
80
|
-
* including recursive filtering of nested blocks within block attributes. The filtering
|
|
81
|
-
* preserves the original non-localized field value structure and hierarchy.
|
|
82
|
-
*
|
|
83
|
-
* @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
|
|
84
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
85
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to filter
|
|
86
|
-
* @param predicate - Asynchronous function that tests each block, including nested ones
|
|
87
|
-
* @returns Promise that resolves to the new non-localized field value with recursively filtered blocks
|
|
88
|
-
*/
|
|
89
|
-
function filterBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, predicate, path = []) {
|
|
54
|
+
function filterBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, predicate, options = {}, path = []) {
|
|
90
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
|
|
56
|
+
const { traversalDirection = 'top-down' } = options;
|
|
57
|
+
const mapperFunc = (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
92
58
|
const blockPath = [...path, ...innerPath];
|
|
93
|
-
const passes = yield predicate(block, blockPath);
|
|
94
|
-
if (!passes) {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
59
|
if (!(0, fieldTypes_1.isItemWithOptionalIdAndMeta)(block)) {
|
|
98
|
-
return
|
|
60
|
+
return block;
|
|
99
61
|
}
|
|
100
62
|
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
101
63
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
64
|
+
if (traversalDirection === 'top-down') {
|
|
65
|
+
const blockCopy = Object.assign(Object.assign({}, block), { attributes: Object.assign({}, block.attributes) });
|
|
66
|
+
for (const field of fields) {
|
|
67
|
+
blockCopy.attributes[field.attributes.api_key] =
|
|
68
|
+
yield filterBlocksInNonLocalizedFieldValue(blockCopy.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, predicate, options, [...blockPath, 'attributes', field.attributes.api_key]);
|
|
69
|
+
}
|
|
70
|
+
return blockCopy;
|
|
71
|
+
}
|
|
72
|
+
const blockCopy = Object.assign(Object.assign({}, block), { attributes: Object.assign({}, block.attributes) });
|
|
102
73
|
for (const field of fields) {
|
|
103
|
-
|
|
104
|
-
yield filterBlocksInNonLocalizedFieldValue(
|
|
74
|
+
blockCopy.attributes[field.attributes.api_key] =
|
|
75
|
+
yield filterBlocksInNonLocalizedFieldValue(blockCopy.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, predicate, options, [...blockPath, 'attributes', field.attributes.api_key]);
|
|
105
76
|
}
|
|
106
|
-
return
|
|
77
|
+
return blockCopy;
|
|
78
|
+
});
|
|
79
|
+
const mappedValue = yield (0, nonRecursiveBlocks_1.nonRecursiveMapBlocksInNonLocalizedFieldValueAsync)(fieldType, nonLocalizedFieldValue, mapperFunc);
|
|
80
|
+
return (0, nonRecursiveBlocks_1.nonRecursiveFilterBlocksInNonLocalizedFieldValueAsync)(fieldType, mappedValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const blockPath = [...path, ...innerPath];
|
|
82
|
+
return yield predicate(block, blockPath);
|
|
107
83
|
}));
|
|
108
84
|
});
|
|
109
85
|
}
|
|
110
86
|
exports.filterBlocksInNonLocalizedFieldValue = filterBlocksInNonLocalizedFieldValue;
|
|
111
|
-
|
|
112
|
-
* Recursively reduce all blocks in a non-localized field value to a single value by applying a reducer function.
|
|
113
|
-
* Processes each direct block and recursively processes nested blocks within block attributes,
|
|
114
|
-
* accumulating results from the entire block hierarchy into a single value.
|
|
115
|
-
*
|
|
116
|
-
* @template R - The type of the accumulated result
|
|
117
|
-
* @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
|
|
118
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
119
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to reduce
|
|
120
|
-
* @param reducer - Asynchronous function that processes each block and updates the accumulator
|
|
121
|
-
* @param initialNonLocalizedFieldValue - The initial value for the accumulator
|
|
122
|
-
* @returns Promise that resolves to the final accumulated value from all blocks in the hierarchy
|
|
123
|
-
*/
|
|
124
|
-
function reduceBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, reducer, initialValue, path = []) {
|
|
87
|
+
function reduceBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, reducer, initialValue, path = []) {
|
|
125
88
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126
89
|
let accumulator = yield (0, nonRecursiveBlocks_1.nonRecursiveReduceBlocksInNonLocalizedFieldValueAsync)(fieldType, nonLocalizedFieldValue, (acc, block, innerPath) => __awaiter(this, void 0, void 0, function* () { return yield reducer(acc, block, [...path, ...innerPath]); }), initialValue);
|
|
127
90
|
yield (0, nonRecursiveBlocks_1.nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync)(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -131,26 +94,14 @@ function reduceBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLo
|
|
|
131
94
|
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
132
95
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
133
96
|
for (const field of fields) {
|
|
134
|
-
accumulator = yield reduceBlocksInNonLocalizedFieldValue(
|
|
97
|
+
accumulator = yield reduceBlocksInNonLocalizedFieldValue(block.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, reducer, accumulator, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
|
|
135
98
|
}
|
|
136
99
|
}));
|
|
137
100
|
return accumulator;
|
|
138
101
|
});
|
|
139
102
|
}
|
|
140
103
|
exports.reduceBlocksInNonLocalizedFieldValue = reduceBlocksInNonLocalizedFieldValue;
|
|
141
|
-
|
|
142
|
-
* Recursively check if any block in the non-localized field value matches the predicate function.
|
|
143
|
-
* Tests both direct blocks and recursively tests nested blocks within block attributes.
|
|
144
|
-
* Returns true as soon as the first matching block is found anywhere in the hierarchy
|
|
145
|
-
* (short-circuit evaluation).
|
|
146
|
-
*
|
|
147
|
-
* @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
|
|
148
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
149
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
|
|
150
|
-
* @param predicate - Asynchronous function that tests each block, including nested ones
|
|
151
|
-
* @returns Promise that resolves to true if any block in the hierarchy matches, false otherwise
|
|
152
|
-
*/
|
|
153
|
-
function someBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, predicate, path = []) {
|
|
104
|
+
function someBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, predicate, path = []) {
|
|
154
105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
155
106
|
const directMatch = yield (0, nonRecursiveBlocks_1.nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync)(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () { return yield predicate(block, [...path, ...innerPath]); }));
|
|
156
107
|
if (directMatch) {
|
|
@@ -166,7 +117,7 @@ function someBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLoca
|
|
|
166
117
|
for (const field of fields) {
|
|
167
118
|
if (found)
|
|
168
119
|
break;
|
|
169
|
-
const nestedMatch = yield someBlocksInNonLocalizedFieldValue(
|
|
120
|
+
const nestedMatch = yield someBlocksInNonLocalizedFieldValue(block.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, predicate, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
|
|
170
121
|
if (nestedMatch) {
|
|
171
122
|
found = true;
|
|
172
123
|
}
|
|
@@ -176,50 +127,39 @@ function someBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLoca
|
|
|
176
127
|
});
|
|
177
128
|
}
|
|
178
129
|
exports.someBlocksInNonLocalizedFieldValue = someBlocksInNonLocalizedFieldValue;
|
|
179
|
-
|
|
180
|
-
* Recursively check if every block in the non-localized field value matches the predicate function.
|
|
181
|
-
* Tests both direct blocks and recursively tests nested blocks within block attributes.
|
|
182
|
-
* Returns false as soon as the first non-matching block is found anywhere in the hierarchy
|
|
183
|
-
* (short-circuit evaluation).
|
|
184
|
-
*
|
|
185
|
-
* @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
|
|
186
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
187
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
|
|
188
|
-
* @param predicate - Asynchronous function that tests each block, including nested ones
|
|
189
|
-
* @returns Promise that resolves to true if all blocks in the hierarchy match, false otherwise
|
|
190
|
-
*/
|
|
191
|
-
function everyBlockInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, predicate, path = []) {
|
|
130
|
+
function everyBlockInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, predicate, path = []) {
|
|
192
131
|
return __awaiter(this, void 0, void 0, function* () {
|
|
193
|
-
return !(yield someBlocksInNonLocalizedFieldValue(
|
|
132
|
+
return !(yield someBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, (item, path) => __awaiter(this, void 0, void 0, function* () { return !(yield predicate(item, path)); }), path));
|
|
194
133
|
});
|
|
195
134
|
}
|
|
196
135
|
exports.everyBlockInNonLocalizedFieldValue = everyBlockInNonLocalizedFieldValue;
|
|
197
|
-
|
|
198
|
-
* Recursively transform blocks in a non-localized field value by applying a mapping function to each block.
|
|
199
|
-
* Creates a new non-localized field value structure with transformed blocks while preserving the original
|
|
200
|
-
* structure. Applies the mapping function to both direct blocks and recursively to nested
|
|
201
|
-
* blocks within block attributes throughout the entire hierarchy.
|
|
202
|
-
*
|
|
203
|
-
* @param schemaRepository - Repository for accessing DatoCMS schema information to resolve block structures
|
|
204
|
-
* @param fieldType - The type of DatoCMS field definition that determines how the value is processed
|
|
205
|
-
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to transform
|
|
206
|
-
* @param mapper - Asynchronous function that transforms each block, including nested ones
|
|
207
|
-
* @returns Promise that resolves to the new non-localized field value with recursively transformed blocks
|
|
208
|
-
*/
|
|
209
|
-
function mapBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, mapper, path = []) {
|
|
136
|
+
function mapBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, mapper, options = {}, path = []) {
|
|
210
137
|
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
const { traversalDirection = 'top-down' } = options;
|
|
211
139
|
return (0, nonRecursiveBlocks_1.nonRecursiveMapBlocksInNonLocalizedFieldValueAsync)(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
212
|
-
const
|
|
213
|
-
if (!(0, fieldTypes_1.isItemWithOptionalIdAndMeta)(
|
|
214
|
-
return
|
|
140
|
+
const blockPath = [...path, ...innerPath];
|
|
141
|
+
if (!(0, fieldTypes_1.isItemWithOptionalIdAndMeta)(block)) {
|
|
142
|
+
return yield mapper(block, blockPath);
|
|
215
143
|
}
|
|
216
|
-
const itemType = yield schemaRepository.getRawItemTypeById(
|
|
144
|
+
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
217
145
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
146
|
+
if (traversalDirection === 'top-down') {
|
|
147
|
+
const newBlock = yield mapper(block, blockPath);
|
|
148
|
+
if (!(0, fieldTypes_1.isItemWithOptionalIdAndMeta)(newBlock)) {
|
|
149
|
+
return newBlock;
|
|
150
|
+
}
|
|
151
|
+
for (const field of fields) {
|
|
152
|
+
newBlock.attributes[field.attributes.api_key] =
|
|
153
|
+
yield mapBlocksInNonLocalizedFieldValue(newBlock.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, mapper, options, [...blockPath, 'attributes', field.attributes.api_key]);
|
|
154
|
+
}
|
|
155
|
+
return newBlock;
|
|
156
|
+
}
|
|
157
|
+
const blockCopy = Object.assign({}, block);
|
|
218
158
|
for (const field of fields) {
|
|
219
|
-
|
|
220
|
-
yield mapBlocksInNonLocalizedFieldValue(
|
|
159
|
+
blockCopy.attributes[field.attributes.api_key] =
|
|
160
|
+
yield mapBlocksInNonLocalizedFieldValue(blockCopy.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, mapper, options, [...blockPath, 'attributes', field.attributes.api_key]);
|
|
221
161
|
}
|
|
222
|
-
return
|
|
162
|
+
return yield mapper(blockCopy, blockPath);
|
|
223
163
|
}));
|
|
224
164
|
});
|
|
225
165
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recursiveBlocks.js","sourceRoot":"","sources":["../../../src/utilities/recursiveBlocks.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"recursiveBlocks.js","sourceRoot":"","sources":["../../../src/utilities/recursiveBlocks.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAYuB;AAGvB,6DAO8B;AAuD9B,SAAsB,mCAAmC,CACvD,sBAA+B,EAC/B,SAAuC,EACvC,gBAAkC,EAClC,OAAuE,EACvE,OAAiB,EAAE;;QAEnB,MAAM,IAAA,yEAAoD,EACxD,SAAS,EACT,sBAAsB,EACtB,CAAO,KAAK,EAAE,SAAS,EAAE,EAAE;YACzB,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC;YAE9C,IAAI,CAAC,IAAA,wCAA2B,EAAC,KAAK,CAAC,EAAE;gBACvC,OAAO;aACR;YAED,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,kBAAkB,CACxD,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CACtC,CAAC;YAEF,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;YAErE,KAAK,MAAM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AQ,GAAG,MAAM,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;gBAEhD,IAAI,CAAC,IAAA,wCAA2B,EAAC,QAAQ,CAAC,EAAE;oBAC1C,OAAO,QAAQ,CAAC;iBACjB;gBAED,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;oBAC1B,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC;wBAC3C,MAAM,iCAAiC,CACrC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,EAC7C,KAAK,CAAC,UAAU,CAAC,UAAU,EAC3B,gBAAgB,EAChB,MAAM,EACN,OAAO,EACP,CAAC,GAAG,SAAS,EAAE,YAAY,EAAE,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CACvD,CAAC;iBACL;gBAED,OAAO,QAAQ,CAAC;aACjB;YAED,MAAM,SAAS,qBAAQ,KAAK,CAAE,CAAC;YAE/B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;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;AArED,8EAqEC"}
|
|
@@ -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;
|
|
@@ -22,7 +22,7 @@ export function isFileFieldValue(value) {
|
|
|
22
22
|
* Type guard for File field values in API request format.
|
|
23
23
|
* Allows metadata fields to be optional or omitted.
|
|
24
24
|
*/
|
|
25
|
-
export function
|
|
25
|
+
export function isFileFieldValueInRequest(value) {
|
|
26
26
|
if (value === null)
|
|
27
27
|
return true;
|
|
28
28
|
return typeof value === 'object' && value !== null && 'upload_id' in value;
|
|
@@ -30,8 +30,8 @@ export function isFileFieldValueAsRequest(value) {
|
|
|
30
30
|
export function isLocalizedFileFieldValue(value) {
|
|
31
31
|
return (isLocalizedFieldValue(value) && Object.values(value).every(isFileFieldValue));
|
|
32
32
|
}
|
|
33
|
-
export function
|
|
33
|
+
export function isLocalizedFileFieldValueInRequest(value) {
|
|
34
34
|
return (isLocalizedFieldValue(value) &&
|
|
35
|
-
Object.values(value).every(
|
|
35
|
+
Object.values(value).every(isFileFieldValueInRequest));
|
|
36
36
|
}
|
|
37
37
|
//# sourceMappingURL=file.js.map
|
|
@@ -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,5 +1,5 @@
|
|
|
1
1
|
import { isLocalizedFieldValue, } from '../utilities/normalizedFieldValues';
|
|
2
|
-
import { isFileFieldValue,
|
|
2
|
+
import { isFileFieldValue, isFileFieldValueInRequest, } from './file';
|
|
3
3
|
/**
|
|
4
4
|
* Type guard for Gallery field values - validates each item using File field validation
|
|
5
5
|
*/
|
|
@@ -9,15 +9,15 @@ export function isGalleryFieldValue(value) {
|
|
|
9
9
|
/**
|
|
10
10
|
* Type guard for Gallery field values in API request format
|
|
11
11
|
*/
|
|
12
|
-
export function
|
|
13
|
-
return Array.isArray(value) && value.every(
|
|
12
|
+
export function isGalleryFieldValueInRequest(value) {
|
|
13
|
+
return Array.isArray(value) && value.every(isFileFieldValueInRequest);
|
|
14
14
|
}
|
|
15
15
|
export function isLocalizedGalleryFieldValue(value) {
|
|
16
16
|
return (isLocalizedFieldValue(value) &&
|
|
17
17
|
Object.values(value).every(isGalleryFieldValue));
|
|
18
18
|
}
|
|
19
|
-
export function
|
|
19
|
+
export function isLocalizedGalleryFieldValueInRequest(value) {
|
|
20
20
|
return (isLocalizedFieldValue(value) &&
|
|
21
|
-
Object.values(value).every(
|
|
21
|
+
Object.values(value).every(isGalleryFieldValueInRequest));
|
|
22
22
|
}
|
|
23
23
|
//# sourceMappingURL=gallery.js.map
|
|
@@ -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;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isValidId } from '../utilities/id';
|
|
1
2
|
import { isLocalizedFieldValue, } from '../utilities/normalizedFieldValues';
|
|
2
3
|
import { isItemId, isItemWithOptionalIdAndMeta, isItemWithOptionalMeta, } from './single_block';
|
|
3
4
|
/**
|
|
@@ -10,7 +11,8 @@ import { isItemId, isItemWithOptionalIdAndMeta, isItemWithOptionalMeta, } from '
|
|
|
10
11
|
* Checks for array structure and ensures all blocks are string references.
|
|
11
12
|
*/
|
|
12
13
|
export function isRichTextFieldValue(value) {
|
|
13
|
-
return (Array.isArray(value) &&
|
|
14
|
+
return (Array.isArray(value) &&
|
|
15
|
+
value.every((block) => typeof block === 'string' && isValidId(block)));
|
|
14
16
|
}
|
|
15
17
|
export function isLocalizedRichTextFieldValue(value) {
|
|
16
18
|
return (isLocalizedFieldValue(value) &&
|
|
@@ -20,7 +22,7 @@ export function isLocalizedRichTextFieldValue(value) {
|
|
|
20
22
|
* Type guard for Modular Content field values in API request format.
|
|
21
23
|
* Allows blocks as string IDs, full objects with IDs, or objects without IDs.
|
|
22
24
|
*/
|
|
23
|
-
export function
|
|
25
|
+
export function isRichTextFieldValueInRequest(value) {
|
|
24
26
|
if (value === null)
|
|
25
27
|
return true;
|
|
26
28
|
if (!Array.isArray(value))
|
|
@@ -33,15 +35,15 @@ export function isRichTextFieldValueAsRequest(value) {
|
|
|
33
35
|
return isItemWithOptionalIdAndMeta(block);
|
|
34
36
|
});
|
|
35
37
|
}
|
|
36
|
-
export function
|
|
38
|
+
export function isLocalizedRichTextFieldValueInRequest(value) {
|
|
37
39
|
return (isLocalizedFieldValue(value) &&
|
|
38
|
-
Object.values(value).every(
|
|
40
|
+
Object.values(value).every(isRichTextFieldValueInRequest));
|
|
39
41
|
}
|
|
40
42
|
/**
|
|
41
43
|
* Type guard for Modular Content field values with nested blocks (?nested=true format).
|
|
42
44
|
* Ensures all blocks are full RawApiTypes.Item objects with complete data.
|
|
43
45
|
*/
|
|
44
|
-
export function
|
|
46
|
+
export function isRichTextFieldValueInNestedResponse(value) {
|
|
45
47
|
if (!Array.isArray(value))
|
|
46
48
|
return false;
|
|
47
49
|
return value.every((block) => {
|
|
@@ -49,8 +51,8 @@ export function isRichTextFieldValueWithNestedBlocks(value) {
|
|
|
49
51
|
return isItemWithOptionalMeta(block);
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
|
-
export function
|
|
54
|
+
export function isLocalizedRichTextFieldValueInNestedResponse(value) {
|
|
53
55
|
return (isLocalizedFieldValue(value) &&
|
|
54
|
-
Object.values(value).every(
|
|
56
|
+
Object.values(value).every(isRichTextFieldValueInNestedResponse));
|
|
55
57
|
}
|
|
56
58
|
//# sourceMappingURL=rich_text.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rich_text.js","sourceRoot":"","sources":["../../../src/fieldTypes/rich_text.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rich_text.js","sourceRoot":"","sources":["../../../src/fieldTypes/rich_text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAEL,qBAAqB,GACtB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAGL,QAAQ,EACR,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,gBAAgB,CAAC;AA2ExB;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,UAAU,oBAAoB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AAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,6CAA6C,CAG3D,KAAc;IAEd,OAAO,CACL,qBAAqB,CAAC,KAAK,CAAC;QAC5B,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,oCAAoC,CAAC,CACjE,CAAC;AACJ,CAAC"}
|
|
@@ -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 {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/fieldTypes/schema.ts"],"names":[],"mappings":""}
|