@datocms/cma-client 5.1.10 → 5.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +569 -0
- package/dist/cjs/fieldTypes/boolean.js +2 -2
- package/dist/cjs/fieldTypes/boolean.js.map +1 -1
- package/dist/cjs/fieldTypes/color.js +2 -2
- package/dist/cjs/fieldTypes/color.js.map +1 -1
- package/dist/cjs/fieldTypes/date.js +2 -3
- package/dist/cjs/fieldTypes/date.js.map +1 -1
- package/dist/cjs/fieldTypes/date_time.js +2 -2
- package/dist/cjs/fieldTypes/date_time.js.map +1 -1
- package/dist/cjs/fieldTypes/file.js +33 -5
- package/dist/cjs/fieldTypes/file.js.map +1 -1
- package/dist/cjs/fieldTypes/float.js +2 -2
- package/dist/cjs/fieldTypes/float.js.map +1 -1
- package/dist/cjs/fieldTypes/gallery.js +20 -5
- package/dist/cjs/fieldTypes/gallery.js.map +1 -1
- package/dist/cjs/fieldTypes/index.js +2 -2
- package/dist/cjs/fieldTypes/index.js.map +1 -1
- package/dist/cjs/fieldTypes/integer.js +2 -2
- package/dist/cjs/fieldTypes/integer.js.map +1 -1
- package/dist/cjs/fieldTypes/json.js +2 -3
- package/dist/cjs/fieldTypes/json.js.map +1 -1
- package/dist/cjs/fieldTypes/lat_lon.js +2 -2
- package/dist/cjs/fieldTypes/lat_lon.js.map +1 -1
- package/dist/cjs/fieldTypes/link.js +4 -4
- package/dist/cjs/fieldTypes/link.js.map +1 -1
- package/dist/cjs/fieldTypes/links.js +5 -3
- package/dist/cjs/fieldTypes/links.js.map +1 -1
- package/dist/cjs/fieldTypes/rich_text.js +18 -18
- package/dist/cjs/fieldTypes/rich_text.js.map +1 -1
- package/dist/cjs/fieldTypes/schema.js +3 -0
- package/dist/cjs/fieldTypes/schema.js.map +1 -0
- package/dist/cjs/fieldTypes/seo.js +2 -3
- package/dist/cjs/fieldTypes/seo.js.map +1 -1
- package/dist/cjs/fieldTypes/single_block.js +20 -19
- package/dist/cjs/fieldTypes/single_block.js.map +1 -1
- package/dist/cjs/fieldTypes/slug.js +2 -3
- package/dist/cjs/fieldTypes/slug.js.map +1 -1
- package/dist/cjs/fieldTypes/string.js +2 -2
- package/dist/cjs/fieldTypes/string.js.map +1 -1
- package/dist/cjs/fieldTypes/structured_text.js +17 -18
- package/dist/cjs/fieldTypes/structured_text.js.map +1 -1
- package/dist/cjs/fieldTypes/text.js +2 -3
- package/dist/cjs/fieldTypes/text.js.map +1 -1
- package/dist/cjs/fieldTypes/video.js +2 -2
- package/dist/cjs/fieldTypes/video.js.map +1 -1
- package/dist/cjs/generated/Client.js +1 -1
- package/dist/cjs/generated/resources/Item.js.map +1 -1
- package/dist/cjs/generated/resources/ScheduledPublication.js.map +1 -1
- package/dist/cjs/generated/resources/ScheduledUnpublishing.js.map +1 -1
- package/dist/cjs/generated/resources/Upload.js.map +1 -1
- package/dist/cjs/index.js +5 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utilities/buildBlockRecord.js +1 -45
- package/dist/cjs/utilities/buildBlockRecord.js.map +1 -1
- package/dist/cjs/utilities/duplicateBlockRecord.js +49 -0
- package/dist/cjs/utilities/duplicateBlockRecord.js.map +1 -0
- package/dist/cjs/utilities/inspectItem.js +427 -0
- package/dist/cjs/utilities/inspectItem.js.map +1 -0
- package/dist/cjs/utilities/{blocks.js → nonRecursiveBlocks.js} +60 -234
- package/dist/cjs/utilities/nonRecursiveBlocks.js.map +1 -0
- package/dist/cjs/utilities/{fieldValue.js → normalizedFieldValues.js} +53 -41
- package/dist/cjs/utilities/normalizedFieldValues.js.map +1 -0
- package/dist/cjs/utilities/recursiveBlocks.js +73 -92
- package/dist/cjs/utilities/recursiveBlocks.js.map +1 -1
- package/dist/cjs/utilities/schemaRepository.js +2 -2
- package/dist/esm/fieldTypes/boolean.d.ts +1 -1
- package/dist/esm/fieldTypes/boolean.js +2 -2
- package/dist/esm/fieldTypes/boolean.js.map +1 -1
- package/dist/esm/fieldTypes/color.d.ts +1 -1
- package/dist/esm/fieldTypes/color.js +2 -2
- package/dist/esm/fieldTypes/color.js.map +1 -1
- package/dist/esm/fieldTypes/date.d.ts +1 -1
- package/dist/esm/fieldTypes/date.js +2 -3
- package/dist/esm/fieldTypes/date.js.map +1 -1
- package/dist/esm/fieldTypes/date_time.d.ts +1 -1
- package/dist/esm/fieldTypes/date_time.js +2 -2
- package/dist/esm/fieldTypes/date_time.js.map +1 -1
- package/dist/esm/fieldTypes/file.d.ts +68 -1
- package/dist/esm/fieldTypes/file.js +29 -3
- package/dist/esm/fieldTypes/file.js.map +1 -1
- package/dist/esm/fieldTypes/float.d.ts +1 -1
- package/dist/esm/fieldTypes/float.js +2 -2
- package/dist/esm/fieldTypes/float.js.map +1 -1
- package/dist/esm/fieldTypes/gallery.d.ts +27 -11
- package/dist/esm/fieldTypes/gallery.js +17 -4
- package/dist/esm/fieldTypes/gallery.js.map +1 -1
- package/dist/esm/fieldTypes/index.d.ts +2 -2
- package/dist/esm/fieldTypes/index.js +2 -2
- package/dist/esm/fieldTypes/index.js.map +1 -1
- package/dist/esm/fieldTypes/integer.d.ts +1 -1
- package/dist/esm/fieldTypes/integer.js +2 -2
- package/dist/esm/fieldTypes/integer.js.map +1 -1
- package/dist/esm/fieldTypes/json.d.ts +1 -1
- package/dist/esm/fieldTypes/json.js +2 -3
- package/dist/esm/fieldTypes/json.js.map +1 -1
- package/dist/esm/fieldTypes/lat_lon.d.ts +1 -1
- package/dist/esm/fieldTypes/lat_lon.js +2 -2
- package/dist/esm/fieldTypes/lat_lon.js.map +1 -1
- package/dist/esm/fieldTypes/link.d.ts +1 -1
- package/dist/esm/fieldTypes/link.js +4 -4
- package/dist/esm/fieldTypes/link.js.map +1 -1
- package/dist/esm/fieldTypes/links.d.ts +1 -1
- package/dist/esm/fieldTypes/links.js +5 -3
- package/dist/esm/fieldTypes/links.js.map +1 -1
- package/dist/esm/fieldTypes/rich_text.d.ts +9 -10
- package/dist/esm/fieldTypes/rich_text.js +13 -13
- package/dist/esm/fieldTypes/rich_text.js.map +1 -1
- package/dist/esm/fieldTypes/schema.d.ts +59 -0
- package/dist/esm/fieldTypes/schema.js +2 -0
- package/dist/esm/fieldTypes/schema.js.map +1 -0
- package/dist/esm/fieldTypes/seo.d.ts +1 -1
- package/dist/esm/fieldTypes/seo.js +2 -3
- package/dist/esm/fieldTypes/seo.js.map +1 -1
- package/dist/esm/fieldTypes/single_block.d.ts +31 -16
- package/dist/esm/fieldTypes/single_block.js +15 -14
- package/dist/esm/fieldTypes/single_block.js.map +1 -1
- package/dist/esm/fieldTypes/slug.d.ts +1 -1
- package/dist/esm/fieldTypes/slug.js +2 -3
- package/dist/esm/fieldTypes/slug.js.map +1 -1
- package/dist/esm/fieldTypes/string.d.ts +1 -1
- package/dist/esm/fieldTypes/string.js +2 -2
- package/dist/esm/fieldTypes/string.js.map +1 -1
- package/dist/esm/fieldTypes/structured_text.d.ts +15 -16
- package/dist/esm/fieldTypes/structured_text.js +12 -13
- package/dist/esm/fieldTypes/structured_text.js.map +1 -1
- package/dist/esm/fieldTypes/text.d.ts +1 -1
- package/dist/esm/fieldTypes/text.js +2 -3
- package/dist/esm/fieldTypes/text.js.map +1 -1
- package/dist/esm/fieldTypes/video.d.ts +1 -1
- package/dist/esm/fieldTypes/video.js +2 -2
- package/dist/esm/fieldTypes/video.js.map +1 -1
- package/dist/esm/generated/ApiTypes.d.ts +90 -980
- package/dist/esm/generated/Client.js +1 -1
- package/dist/esm/generated/RawApiTypes.d.ts +156 -999
- package/dist/esm/generated/resources/Field.d.ts +200 -200
- package/dist/esm/generated/resources/Item.d.ts +34 -34
- package/dist/esm/generated/resources/Item.js.map +1 -1
- package/dist/esm/generated/resources/ItemVersion.d.ts +3 -1
- package/dist/esm/generated/resources/ScheduledPublication.d.ts +3 -3
- package/dist/esm/generated/resources/ScheduledPublication.js.map +1 -1
- package/dist/esm/generated/resources/ScheduledUnpublishing.d.ts +3 -3
- package/dist/esm/generated/resources/ScheduledUnpublishing.js.map +1 -1
- package/dist/esm/generated/resources/Upload.d.ts +6 -6
- package/dist/esm/generated/resources/Upload.js.map +1 -1
- package/dist/esm/index.d.ts +5 -4
- package/dist/esm/index.js +5 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utilities/buildBlockRecord.d.ts +3 -5
- package/dist/esm/utilities/buildBlockRecord.js +0 -43
- package/dist/esm/utilities/buildBlockRecord.js.map +1 -1
- package/dist/esm/utilities/duplicateBlockRecord.d.ts +6 -0
- package/dist/esm/utilities/duplicateBlockRecord.js +45 -0
- package/dist/esm/utilities/duplicateBlockRecord.js.map +1 -0
- package/dist/esm/utilities/inspectItem.d.ts +8 -0
- package/dist/esm/utilities/inspectItem.js +400 -0
- package/dist/esm/utilities/inspectItem.js.map +1 -0
- package/dist/esm/utilities/itemDefinition.d.ts +45 -23
- package/dist/esm/utilities/nonRecursiveBlocks.d.ts +114 -0
- package/dist/esm/utilities/{blocks.js → nonRecursiveBlocks.js} +52 -220
- package/dist/esm/utilities/nonRecursiveBlocks.js.map +1 -0
- package/dist/{types/utilities/fieldValue.d.ts → esm/utilities/normalizedFieldValues.d.ts} +15 -14
- package/dist/esm/utilities/{fieldValue.js → normalizedFieldValues.js} +39 -28
- package/dist/esm/utilities/normalizedFieldValues.js.map +1 -0
- package/dist/esm/utilities/recursiveBlocks.d.ts +124 -11
- package/dist/esm/utilities/recursiveBlocks.js +65 -84
- package/dist/esm/utilities/recursiveBlocks.js.map +1 -1
- package/dist/esm/utilities/schemaRepository.d.ts +2 -2
- package/dist/esm/utilities/schemaRepository.js +2 -2
- package/dist/types/fieldTypes/boolean.d.ts +1 -1
- package/dist/types/fieldTypes/color.d.ts +1 -1
- package/dist/types/fieldTypes/date.d.ts +1 -1
- package/dist/types/fieldTypes/date_time.d.ts +1 -1
- package/dist/types/fieldTypes/file.d.ts +68 -1
- package/dist/types/fieldTypes/float.d.ts +1 -1
- package/dist/types/fieldTypes/gallery.d.ts +27 -11
- package/dist/types/fieldTypes/index.d.ts +2 -2
- package/dist/types/fieldTypes/integer.d.ts +1 -1
- package/dist/types/fieldTypes/json.d.ts +1 -1
- package/dist/types/fieldTypes/lat_lon.d.ts +1 -1
- package/dist/types/fieldTypes/link.d.ts +1 -1
- package/dist/types/fieldTypes/links.d.ts +1 -1
- package/dist/types/fieldTypes/rich_text.d.ts +9 -10
- package/dist/types/fieldTypes/schema.d.ts +59 -0
- package/dist/types/fieldTypes/seo.d.ts +1 -1
- package/dist/types/fieldTypes/single_block.d.ts +31 -16
- package/dist/types/fieldTypes/slug.d.ts +1 -1
- package/dist/types/fieldTypes/string.d.ts +1 -1
- package/dist/types/fieldTypes/structured_text.d.ts +15 -16
- package/dist/types/fieldTypes/text.d.ts +1 -1
- package/dist/types/fieldTypes/video.d.ts +1 -1
- package/dist/types/generated/ApiTypes.d.ts +90 -980
- package/dist/types/generated/RawApiTypes.d.ts +156 -999
- package/dist/types/generated/resources/Field.d.ts +200 -200
- package/dist/types/generated/resources/Item.d.ts +34 -34
- package/dist/types/generated/resources/ItemVersion.d.ts +3 -1
- package/dist/types/generated/resources/ScheduledPublication.d.ts +3 -3
- package/dist/types/generated/resources/ScheduledUnpublishing.d.ts +3 -3
- package/dist/types/generated/resources/Upload.d.ts +6 -6
- package/dist/types/index.d.ts +5 -4
- package/dist/types/utilities/buildBlockRecord.d.ts +3 -5
- package/dist/types/utilities/duplicateBlockRecord.d.ts +6 -0
- package/dist/types/utilities/inspectItem.d.ts +8 -0
- package/dist/types/utilities/itemDefinition.d.ts +45 -23
- package/dist/types/utilities/nonRecursiveBlocks.d.ts +114 -0
- package/dist/{esm/utilities/fieldValue.d.ts → types/utilities/normalizedFieldValues.d.ts} +15 -14
- package/dist/types/utilities/recursiveBlocks.d.ts +124 -11
- package/dist/types/utilities/schemaRepository.d.ts +2 -2
- package/package.json +4 -4
- package/src/fieldTypes/boolean.ts +5 -3
- package/src/fieldTypes/color.ts +5 -3
- package/src/fieldTypes/date.ts +5 -4
- package/src/fieldTypes/date_time.ts +5 -3
- package/src/fieldTypes/file.ts +98 -4
- package/src/fieldTypes/float.ts +5 -3
- package/src/fieldTypes/gallery.ts +53 -20
- package/src/fieldTypes/index.ts +2 -3
- package/src/fieldTypes/integer.ts +5 -3
- package/src/fieldTypes/json.ts +5 -4
- package/src/fieldTypes/lat_lon.ts +5 -3
- package/src/fieldTypes/link.ts +7 -5
- package/src/fieldTypes/links.ts +8 -4
- package/src/fieldTypes/rich_text.ts +33 -31
- package/src/fieldTypes/schema.ts +657 -0
- package/src/fieldTypes/seo.ts +5 -4
- package/src/fieldTypes/single_block.ts +71 -46
- package/src/fieldTypes/slug.ts +5 -4
- package/src/fieldTypes/string.ts +5 -3
- package/src/fieldTypes/structured_text.ts +64 -58
- package/src/fieldTypes/text.ts +5 -4
- package/src/fieldTypes/video.ts +5 -3
- package/src/generated/ApiTypes.ts +217 -1880
- package/src/generated/Client.ts +1 -1
- package/src/generated/RawApiTypes.ts +272 -2113
- package/src/generated/resources/Item.ts +93 -187
- package/src/generated/resources/ScheduledPublication.ts +4 -15
- package/src/generated/resources/ScheduledUnpublishing.ts +4 -15
- package/src/generated/resources/Upload.ts +9 -32
- package/src/index.ts +5 -4
- package/src/utilities/buildBlockRecord.ts +4 -59
- package/src/utilities/duplicateBlockRecord.ts +52 -0
- package/src/utilities/inspectItem.ts +602 -0
- package/src/utilities/itemDefinition.ts +130 -92
- package/src/utilities/nonRecursiveBlocks.ts +406 -0
- package/src/utilities/{fieldValue.ts → normalizedFieldValues.ts} +70 -30
- package/src/utilities/recursiveBlocks.ts +484 -204
- package/src/utilities/schemaRepository.ts +2 -2
- package/dist/cjs/utilities/blocks.js.map +0 -1
- package/dist/cjs/utilities/fieldValue.js.map +0 -1
- package/dist/esm/utilities/blocks.d.ts +0 -180
- package/dist/esm/utilities/blocks.js.map +0 -1
- package/dist/esm/utilities/fieldValue.js.map +0 -1
- package/dist/types/utilities/blocks.d.ts +0 -180
- package/src/utilities/blocks.ts +0 -626
|
@@ -8,11 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { isItemWithOptionalIdAndMeta, } from '../fieldTypes';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
export function visitBlocksInFieldValues(schemaRepository, field, value, visitor, path = []) {
|
|
11
|
+
import { nonRecursiveFilterBlocksInNonLocalizedFieldValueAsync, nonRecursiveFindAllBlocksInNonLocalizedFieldValueAsync, nonRecursiveMapBlocksInNonLocalizedFieldValueAsync, nonRecursiveReduceBlocksInNonLocalizedFieldValueAsync, nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync, nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync, } from './nonRecursiveBlocks';
|
|
12
|
+
export function visitBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, visitor, path = []) {
|
|
14
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
yield
|
|
14
|
+
yield nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
16
15
|
yield visitor(block, [...path, ...innerPath]);
|
|
17
16
|
if (!isItemWithOptionalIdAndMeta(block)) {
|
|
18
17
|
return;
|
|
@@ -20,104 +19,89 @@ export function visitBlocksInFieldValues(schemaRepository, field, value, visitor
|
|
|
20
19
|
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
21
20
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
22
21
|
for (const field of fields) {
|
|
23
|
-
yield
|
|
24
|
-
...path,
|
|
25
|
-
...innerPath,
|
|
26
|
-
'attributes',
|
|
27
|
-
field.attributes.api_key,
|
|
28
|
-
...(locale ? [locale] : []),
|
|
29
|
-
]));
|
|
22
|
+
yield visitBlocksInNonLocalizedFieldValue(block.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, visitor, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
|
|
30
23
|
}
|
|
31
24
|
}));
|
|
32
25
|
});
|
|
33
26
|
}
|
|
34
|
-
export function
|
|
27
|
+
export function findAllBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, predicate, path = []) {
|
|
35
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
29
|
const results = [];
|
|
37
|
-
const directMatches = yield
|
|
30
|
+
const directMatches = yield nonRecursiveFindAllBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () { return yield predicate(block, [...path, ...innerPath]); }));
|
|
38
31
|
results.push(...directMatches.map(({ item, path: innerPath }) => ({
|
|
39
32
|
item,
|
|
40
33
|
path: [...path, ...innerPath],
|
|
41
34
|
})));
|
|
42
|
-
yield
|
|
35
|
+
yield nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
43
36
|
if (!isItemWithOptionalIdAndMeta(block)) {
|
|
44
37
|
return;
|
|
45
38
|
}
|
|
46
39
|
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
47
40
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
48
41
|
for (const field of fields) {
|
|
49
|
-
yield
|
|
50
|
-
|
|
51
|
-
...path,
|
|
52
|
-
...innerPath,
|
|
53
|
-
'attributes',
|
|
54
|
-
field.attributes.api_key,
|
|
55
|
-
...(locale ? [locale] : []),
|
|
56
|
-
]);
|
|
57
|
-
results.push(...nestedResults);
|
|
58
|
-
}));
|
|
42
|
+
const nestedResults = yield findAllBlocksInNonLocalizedFieldValue(block.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, predicate, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
|
|
43
|
+
results.push(...nestedResults);
|
|
59
44
|
}
|
|
60
45
|
}));
|
|
61
46
|
return results;
|
|
62
47
|
});
|
|
63
48
|
}
|
|
64
|
-
export function
|
|
49
|
+
export function filterBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, predicate, options = {}, path = []) {
|
|
65
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
|
|
51
|
+
const { traversalDirection = 'top-down' } = options;
|
|
52
|
+
const mapperFunc = (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
67
53
|
const blockPath = [...path, ...innerPath];
|
|
68
|
-
const passes = yield predicate(block, blockPath);
|
|
69
|
-
if (!passes) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
54
|
if (!isItemWithOptionalIdAndMeta(block)) {
|
|
73
|
-
return
|
|
55
|
+
return block;
|
|
74
56
|
}
|
|
75
57
|
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
76
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) });
|
|
77
68
|
for (const field of fields) {
|
|
78
|
-
|
|
79
|
-
...blockPath,
|
|
80
|
-
'attributes',
|
|
81
|
-
field.attributes.api_key,
|
|
82
|
-
...(locale ? [locale] : []),
|
|
83
|
-
]));
|
|
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]);
|
|
84
71
|
}
|
|
85
|
-
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);
|
|
86
78
|
}));
|
|
87
79
|
});
|
|
88
80
|
}
|
|
89
|
-
export function
|
|
81
|
+
export function reduceBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, reducer, initialValue, path = []) {
|
|
90
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
let accumulator = yield
|
|
92
|
-
yield
|
|
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);
|
|
84
|
+
yield nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
93
85
|
if (!isItemWithOptionalIdAndMeta(block)) {
|
|
94
86
|
return;
|
|
95
87
|
}
|
|
96
88
|
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
97
89
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
98
90
|
for (const field of fields) {
|
|
99
|
-
yield
|
|
100
|
-
accumulator = yield reduceBlocksInFieldValues(schemaRepository, field, valueForLocale, reducer, accumulator, [
|
|
101
|
-
...path,
|
|
102
|
-
...innerPath,
|
|
103
|
-
'attributes',
|
|
104
|
-
field.attributes.api_key,
|
|
105
|
-
...(locale ? [locale] : []),
|
|
106
|
-
]);
|
|
107
|
-
}));
|
|
91
|
+
accumulator = yield reduceBlocksInNonLocalizedFieldValue(block.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, reducer, accumulator, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
|
|
108
92
|
}
|
|
109
93
|
}));
|
|
110
94
|
return accumulator;
|
|
111
95
|
});
|
|
112
96
|
}
|
|
113
|
-
export function
|
|
97
|
+
export function someBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, predicate, path = []) {
|
|
114
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
const directMatch = yield
|
|
99
|
+
const directMatch = yield nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () { return yield predicate(block, [...path, ...innerPath]); }));
|
|
116
100
|
if (directMatch) {
|
|
117
101
|
return true;
|
|
118
102
|
}
|
|
119
103
|
let found = false;
|
|
120
|
-
yield
|
|
104
|
+
yield nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
121
105
|
if (found || !isItemWithOptionalIdAndMeta(block)) {
|
|
122
106
|
return;
|
|
123
107
|
}
|
|
@@ -126,50 +110,47 @@ export function someBlocksInFieldValues(schemaRepository, field, value, predicat
|
|
|
126
110
|
for (const field of fields) {
|
|
127
111
|
if (found)
|
|
128
112
|
break;
|
|
129
|
-
yield
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
...path,
|
|
134
|
-
...innerPath,
|
|
135
|
-
'attributes',
|
|
136
|
-
field.attributes.api_key,
|
|
137
|
-
...(locale ? [locale] : []),
|
|
138
|
-
]);
|
|
139
|
-
if (nestedMatch) {
|
|
140
|
-
found = true;
|
|
141
|
-
}
|
|
142
|
-
}));
|
|
113
|
+
const nestedMatch = yield someBlocksInNonLocalizedFieldValue(block.attributes[field.attributes.api_key], field.attributes.field_type, schemaRepository, predicate, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
|
|
114
|
+
if (nestedMatch) {
|
|
115
|
+
found = true;
|
|
116
|
+
}
|
|
143
117
|
}
|
|
144
118
|
}));
|
|
145
119
|
return found;
|
|
146
120
|
});
|
|
147
121
|
}
|
|
148
|
-
export function
|
|
122
|
+
export function everyBlockInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, predicate, path = []) {
|
|
149
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
return !(yield
|
|
124
|
+
return !(yield someBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, (item, path) => __awaiter(this, void 0, void 0, function* () { return !(yield predicate(item, path)); }), path));
|
|
151
125
|
});
|
|
152
126
|
}
|
|
153
|
-
export function
|
|
127
|
+
export function mapBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue, fieldType, schemaRepository, mapper, options = {}, path = []) {
|
|
154
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
129
|
+
const { traversalDirection = 'top-down' } = options;
|
|
130
|
+
return nonRecursiveMapBlocksInNonLocalizedFieldValueAsync(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
const blockPath = [...path, ...innerPath];
|
|
132
|
+
if (!isItemWithOptionalIdAndMeta(block)) {
|
|
133
|
+
return yield mapper(block, blockPath);
|
|
159
134
|
}
|
|
160
|
-
const itemType = yield schemaRepository.getRawItemTypeById(
|
|
135
|
+
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
161
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);
|
|
162
149
|
for (const field of fields) {
|
|
163
|
-
|
|
164
|
-
yield
|
|
165
|
-
...path,
|
|
166
|
-
...innerPath,
|
|
167
|
-
'attributes',
|
|
168
|
-
field.attributes.api_key,
|
|
169
|
-
...(locale ? [locale] : []),
|
|
170
|
-
]));
|
|
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]);
|
|
171
152
|
}
|
|
172
|
-
return
|
|
153
|
+
return yield mapper(blockCopy, blockPath);
|
|
173
154
|
}));
|
|
174
155
|
});
|
|
175
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,EAWL,2BAA2B,GAC5B,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,qDAAqD,EACrD,sDAAsD,EACtD,kDAAkD,EAClD,qDAAqD,EACrD,mDAAmD,EACnD,oDAAoD,GACrD,MAAM,sBAAsB,CAAC;AAuD9B,MAA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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"}
|
|
@@ -41,7 +41,7 @@ interface GenericClient {
|
|
|
41
41
|
* - **Caching schema entities**: Automatically caches item types, fields, fieldsets,
|
|
42
42
|
* and plugins after the first API request, returning cached results on subsequent calls
|
|
43
43
|
* - **Complex traversal operations**: Essential when using utilities like
|
|
44
|
-
* `
|
|
44
|
+
* `mapBlocksInNonLocalizedFieldValue()` that need to repeatedly lookup block models and fields
|
|
45
45
|
* while traversing nested content structures
|
|
46
46
|
* - **Bulk operations**: Ideal for scripts that process multiple records of different
|
|
47
47
|
* types and need efficient access to schema information
|
|
@@ -73,7 +73,7 @@ interface GenericClient {
|
|
|
73
73
|
* const sameBlogPost = await schemaRepository.getItemTypeByApiKey('blog_post');
|
|
74
74
|
*
|
|
75
75
|
* // Pass the repository to utilities that need schema information
|
|
76
|
-
* await
|
|
76
|
+
* await mapBlocksInNonLocalizedFieldValue(schemaRepository, record, (block) => {
|
|
77
77
|
* // The utility will use the cached schema data internally
|
|
78
78
|
* });
|
|
79
79
|
* ```
|
|
@@ -24,7 +24,7 @@ import { deserializeResponseBody } from '@datocms/rest-client-utils';
|
|
|
24
24
|
* - **Caching schema entities**: Automatically caches item types, fields, fieldsets,
|
|
25
25
|
* and plugins after the first API request, returning cached results on subsequent calls
|
|
26
26
|
* - **Complex traversal operations**: Essential when using utilities like
|
|
27
|
-
* `
|
|
27
|
+
* `mapBlocksInNonLocalizedFieldValue()` that need to repeatedly lookup block models and fields
|
|
28
28
|
* while traversing nested content structures
|
|
29
29
|
* - **Bulk operations**: Ideal for scripts that process multiple records of different
|
|
30
30
|
* types and need efficient access to schema information
|
|
@@ -56,7 +56,7 @@ import { deserializeResponseBody } from '@datocms/rest-client-utils';
|
|
|
56
56
|
* const sameBlogPost = await schemaRepository.getItemTypeByApiKey('blog_post');
|
|
57
57
|
*
|
|
58
58
|
* // Pass the repository to utilities that need schema information
|
|
59
|
-
* await
|
|
59
|
+
* await mapBlocksInNonLocalizedFieldValue(schemaRepository, record, (block) => {
|
|
60
60
|
* // The utility will use the cached schema data internally
|
|
61
61
|
* });
|
|
62
62
|
* ```
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LocalizedFieldValue } from '../utilities/normalizedFieldValues';
|
|
2
2
|
import type { BooleanEditorConfiguration } from './appearance/boolean';
|
|
3
3
|
import type { BooleanRadioGroupEditorConfiguration } from './appearance/boolean_radio_group';
|
|
4
4
|
export type BooleanFieldValue = boolean | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LocalizedFieldValue } from '../utilities/normalizedFieldValues';
|
|
2
2
|
import type { ColorPickerEditorConfiguration } from './appearance/color_picker';
|
|
3
3
|
import type { RequiredValidator } from './validators/required';
|
|
4
4
|
export type ColorFieldValue = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LocalizedFieldValue } from '../utilities/normalizedFieldValues';
|
|
2
2
|
import type { DatePickerEditorConfiguration } from './appearance/date_picker';
|
|
3
3
|
import type { DateRangeValidator } from './validators/date_range';
|
|
4
4
|
import type { RequiredValidator } from './validators/required';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LocalizedFieldValue } from '../utilities/normalizedFieldValues';
|
|
2
2
|
import type { DateTimePickerEditorConfiguration } from './appearance/date_time_picker';
|
|
3
3
|
import type { DateTimeRangeValidator } from './validators/date_time_range';
|
|
4
4
|
import type { RequiredValidator } from './validators/required';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LocalizedFieldValue } from '../utilities/normalizedFieldValues';
|
|
2
2
|
import type { FileEditorConfiguration } from './appearance/file';
|
|
3
3
|
import type { ExtensionValidator } from './validators/extension';
|
|
4
4
|
import type { FileSizeValidator } from './validators/file_size';
|
|
@@ -6,7 +6,59 @@ import type { ImageAspectRatioValidator } from './validators/image_aspect_ratio'
|
|
|
6
6
|
import type { ImageDimensionsValidator } from './validators/image_dimensions';
|
|
7
7
|
import type { RequiredValidator } from './validators/required';
|
|
8
8
|
import type { RequiredAltTitleValidator } from './validators/required_alt_title';
|
|
9
|
+
/**
|
|
10
|
+
* FILE FIELD TYPE SYSTEM FOR DATOCMS
|
|
11
|
+
*
|
|
12
|
+
* This module defines a comprehensive type system for handling DatoCMS File fields,
|
|
13
|
+
* which contain file uploads with optional metadata like alt text, title, custom data, and focal points.
|
|
14
|
+
*
|
|
15
|
+
* The challenge we're solving:
|
|
16
|
+
* - DatoCMS File fields can have optional metadata fields (alt, title, custom_data, focal_point)
|
|
17
|
+
* - For API requests, all these fields are optional and can be omitted
|
|
18
|
+
* - For API responses, DatoCMS provides default values for missing fields:
|
|
19
|
+
* - alt: null
|
|
20
|
+
* - title: null
|
|
21
|
+
* - custom_data: {}
|
|
22
|
+
* - focal_point: null
|
|
23
|
+
* - This creates a need for different type variants for the same conceptual data structure
|
|
24
|
+
*
|
|
25
|
+
* This module provides separate types for:
|
|
26
|
+
* 1. API request format (optional metadata fields)
|
|
27
|
+
* 2. API response format (all fields present with defaults)
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* =============================================================================
|
|
31
|
+
* BASIC FILE TYPE - Default API response format
|
|
32
|
+
* =============================================================================
|
|
33
|
+
*
|
|
34
|
+
* The standard File field value with all metadata fields present and default values applied.
|
|
35
|
+
* This is what you get from API responses where DatoCMS has applied default values.
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* Basic File field value - all metadata fields present with defaults applied
|
|
39
|
+
*/
|
|
9
40
|
export type FileFieldValue = {
|
|
41
|
+
upload_id: string;
|
|
42
|
+
alt: string | null;
|
|
43
|
+
title: string | null;
|
|
44
|
+
custom_data: Record<string, unknown>;
|
|
45
|
+
focal_point: {
|
|
46
|
+
x: number;
|
|
47
|
+
y: number;
|
|
48
|
+
} | null;
|
|
49
|
+
} | null;
|
|
50
|
+
/**
|
|
51
|
+
* =============================================================================
|
|
52
|
+
* REQUEST VARIANT - Type for sending data TO the DatoCMS API
|
|
53
|
+
* =============================================================================
|
|
54
|
+
*
|
|
55
|
+
* When making API requests, metadata fields are optional and can be omitted.
|
|
56
|
+
* DatoCMS will apply default values for any missing fields in the response.
|
|
57
|
+
*/
|
|
58
|
+
/**
|
|
59
|
+
* File field value for API requests - metadata fields are optional
|
|
60
|
+
*/
|
|
61
|
+
export type FileFieldValueInRequest = {
|
|
10
62
|
upload_id: string;
|
|
11
63
|
alt?: string | null;
|
|
12
64
|
title?: string | null;
|
|
@@ -16,8 +68,23 @@ export type FileFieldValue = {
|
|
|
16
68
|
y: number;
|
|
17
69
|
} | null;
|
|
18
70
|
} | null;
|
|
71
|
+
/**
|
|
72
|
+
* =============================================================================
|
|
73
|
+
* TYPE GUARDS - Runtime validation functions
|
|
74
|
+
* =============================================================================
|
|
75
|
+
*/
|
|
76
|
+
/**
|
|
77
|
+
* Type guard for basic File field values (response format with all fields present).
|
|
78
|
+
* Validates that all required metadata fields are present.
|
|
79
|
+
*/
|
|
19
80
|
export declare function isFileFieldValue(value: unknown): value is FileFieldValue;
|
|
81
|
+
/**
|
|
82
|
+
* Type guard for File field values in API request format.
|
|
83
|
+
* Allows metadata fields to be optional or omitted.
|
|
84
|
+
*/
|
|
85
|
+
export declare function isFileFieldValueInRequest(value: unknown): value is FileFieldValueInRequest;
|
|
20
86
|
export declare function isLocalizedFileFieldValue(value: unknown): value is LocalizedFieldValue<FileFieldValue>;
|
|
87
|
+
export declare function isLocalizedFileFieldValueInRequest(value: unknown): value is LocalizedFieldValue<FileFieldValueInRequest>;
|
|
21
88
|
export type FileFieldValidators = {
|
|
22
89
|
/** Value must be specified or it won't be valid */
|
|
23
90
|
required?: RequiredValidator;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LocalizedFieldValue } from '../utilities/normalizedFieldValues';
|
|
2
2
|
import type { FloatEditorConfiguration } from './appearance/float';
|
|
3
3
|
import type { NumberRangeValidator } from './validators/number_range';
|
|
4
4
|
import type { RequiredValidator } from './validators/required';
|
|
@@ -1,23 +1,39 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LocalizedFieldValue } from '../utilities/normalizedFieldValues';
|
|
2
2
|
import type { GalleryEditorConfiguration } from './appearance/gallery';
|
|
3
|
+
import { type FileFieldValue, type FileFieldValueInRequest } from './file';
|
|
3
4
|
import type { ExtensionValidator } from './validators/extension';
|
|
4
5
|
import type { FileSizeValidator } from './validators/file_size';
|
|
5
6
|
import type { ImageAspectRatioValidator } from './validators/image_aspect_ratio';
|
|
6
7
|
import type { ImageDimensionsValidator } from './validators/image_dimensions';
|
|
7
8
|
import type { RequiredAltTitleValidator } from './validators/required_alt_title';
|
|
8
9
|
import type { SizeValidator } from './validators/size';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Gallery field type system - similar to File field but for arrays.
|
|
12
|
+
* See file.ts for detailed explanation of request/response duality.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Individual gallery item types - extracted from File field types
|
|
16
|
+
*/
|
|
17
|
+
export type GalleryItem = NonNullable<FileFieldValue>;
|
|
18
|
+
export type GalleryItemInRequest = NonNullable<FileFieldValueInRequest>;
|
|
19
|
+
/**
|
|
20
|
+
* Gallery field value - response format with all metadata fields present
|
|
21
|
+
*/
|
|
22
|
+
export type GalleryFieldValue = Array<GalleryItem>;
|
|
23
|
+
/**
|
|
24
|
+
* Gallery field value for API requests - metadata fields are optional
|
|
25
|
+
*/
|
|
26
|
+
export type GalleryFieldValueInRequest = Array<GalleryItemInRequest>;
|
|
27
|
+
/**
|
|
28
|
+
* Type guard for Gallery field values - validates each item using File field validation
|
|
29
|
+
*/
|
|
19
30
|
export declare function isGalleryFieldValue(value: unknown): value is GalleryFieldValue;
|
|
31
|
+
/**
|
|
32
|
+
* Type guard for Gallery field values in API request format
|
|
33
|
+
*/
|
|
34
|
+
export declare function isGalleryFieldValueInRequest(value: unknown): value is GalleryFieldValueInRequest;
|
|
20
35
|
export declare function isLocalizedGalleryFieldValue(value: unknown): value is LocalizedFieldValue<GalleryFieldValue>;
|
|
36
|
+
export declare function isLocalizedGalleryFieldValueInRequest(value: unknown): value is LocalizedFieldValue<GalleryFieldValueInRequest>;
|
|
21
37
|
export type GalleryFieldValidators = {
|
|
22
38
|
/** Only accept a number of items within the specified range */
|
|
23
39
|
size?: SizeValidator;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './appearance';
|
|
1
2
|
export * from './boolean';
|
|
2
3
|
export * from './color';
|
|
3
4
|
export * from './date';
|
|
@@ -17,6 +18,5 @@ export * from './slug';
|
|
|
17
18
|
export * from './string';
|
|
18
19
|
export * from './structured_text';
|
|
19
20
|
export * from './text';
|
|
20
|
-
export * from './video';
|
|
21
|
-
export * from './appearance';
|
|
22
21
|
export * from './validators';
|
|
22
|
+
export * from './video';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LocalizedFieldValue } from '../utilities/normalizedFieldValues';
|
|
2
2
|
import type { IntegerEditorConfiguration } from './appearance/integer';
|
|
3
3
|
import type { NumberRangeValidator } from './validators/number_range';
|
|
4
4
|
import type { RequiredValidator } from './validators/required';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LocalizedFieldValue } from '../utilities/normalizedFieldValues';
|
|
2
2
|
import type { JsonEditorConfiguration } from './appearance/json';
|
|
3
3
|
import type { StringCheckboxGroupEditorConfiguration } from './appearance/string_checkbox_group';
|
|
4
4
|
import type { StringMultiSelectEditorConfiguration } from './appearance/string_multi_select';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LocalizedFieldValue } from '../utilities/normalizedFieldValues';
|
|
2
2
|
import type { MapEditorConfiguration } from './appearance/map';
|
|
3
3
|
import type { RequiredValidator } from './validators/required';
|
|
4
4
|
export type LatLonFieldValue = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LocalizedFieldValue } from '../utilities/normalizedFieldValues';
|
|
2
2
|
import type { LinkEmbedEditorConfiguration } from './appearance/link_embed';
|
|
3
3
|
import type { LinkSelectEditorConfiguration } from './appearance/link_select';
|
|
4
4
|
import type { ItemItemTypeValidator } from './validators/item_item_type';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LocalizedFieldValue } from '../utilities/normalizedFieldValues';
|
|
2
2
|
import type { LinksEmbedEditorConfiguration } from './appearance/links_embed';
|
|
3
3
|
import type { LinksSelectEditorConfiguration } from './appearance/links_select';
|
|
4
4
|
import type { ItemsItemTypeValidator } from './validators/items_item_type';
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
3
|
-
import type { ItemDefinition } from '../utilities/itemDefinition';
|
|
1
|
+
import type { ItemTypeDefinition } from '../utilities/itemDefinition';
|
|
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;
|