@datocms/cma-client 5.1.9 → 5.1.11
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 +575 -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 +4 -6
- package/dist/cjs/fieldTypes/rich_text.js.map +1 -1
- package/dist/cjs/fieldTypes/seo.js +2 -3
- package/dist/cjs/fieldTypes/seo.js.map +1 -1
- package/dist/cjs/fieldTypes/single_block.js +7 -7
- 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 +4 -6
- 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/Client.js.map +1 -1
- package/dist/cjs/generated/resources/Item.js.map +1 -1
- package/dist/cjs/generated/resources/Upload.js.map +1 -1
- package/dist/cjs/index.js +4 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utilities/buildBlockRecord.js +8 -7
- package/dist/cjs/utilities/buildBlockRecord.js.map +1 -1
- package/dist/cjs/utilities/inspectItem.js +397 -0
- package/dist/cjs/utilities/inspectItem.js.map +1 -0
- package/dist/cjs/utilities/{blocks.js → nonRecursiveBlocks.js} +106 -111
- 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 +121 -80
- 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 +1 -1
- package/dist/esm/fieldTypes/rich_text.js +4 -6
- package/dist/esm/fieldTypes/rich_text.js.map +1 -1
- 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 +3 -3
- package/dist/esm/fieldTypes/single_block.js +7 -7
- 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 +1 -1
- package/dist/esm/fieldTypes/structured_text.js +4 -6
- 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/Client.js +1 -1
- package/dist/esm/generated/Client.js.map +1 -1
- package/dist/esm/generated/resources/Item.d.ts +46 -28
- package/dist/esm/generated/resources/Item.js.map +1 -1
- package/dist/esm/generated/resources/ScheduledPublication.d.ts +3 -3
- package/dist/esm/generated/resources/ScheduledUnpublishing.d.ts +3 -3
- package/dist/esm/generated/resources/Upload.d.ts +10 -4
- package/dist/esm/generated/resources/Upload.js.map +1 -1
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utilities/buildBlockRecord.d.ts +3 -3
- package/dist/esm/utilities/buildBlockRecord.js +9 -8
- package/dist/esm/utilities/buildBlockRecord.js.map +1 -1
- package/dist/esm/utilities/inspectItem.d.ts +8 -0
- package/dist/esm/utilities/inspectItem.js +393 -0
- package/dist/esm/utilities/inspectItem.js.map +1 -0
- package/dist/esm/utilities/itemDefinition.d.ts +36 -12
- package/dist/esm/utilities/nonRecursiveBlocks.d.ts +179 -0
- package/dist/esm/utilities/{blocks.js → nonRecursiveBlocks.js} +91 -96
- 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 +92 -9
- package/dist/esm/utilities/recursiveBlocks.js +113 -72
- 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 +1 -1
- package/dist/types/fieldTypes/seo.d.ts +1 -1
- package/dist/types/fieldTypes/single_block.d.ts +3 -3
- 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 +1 -1
- package/dist/types/fieldTypes/text.d.ts +1 -1
- package/dist/types/fieldTypes/video.d.ts +1 -1
- package/dist/types/generated/resources/Item.d.ts +46 -28
- 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 +10 -4
- package/dist/types/index.d.ts +4 -4
- package/dist/types/utilities/buildBlockRecord.d.ts +3 -3
- package/dist/types/utilities/inspectItem.d.ts +8 -0
- package/dist/types/utilities/itemDefinition.d.ts +36 -12
- package/dist/types/utilities/nonRecursiveBlocks.d.ts +179 -0
- package/dist/{esm/utilities/fieldValue.d.ts → types/utilities/normalizedFieldValues.d.ts} +15 -14
- package/dist/types/utilities/recursiveBlocks.d.ts +92 -9
- 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 +7 -7
- package/src/fieldTypes/seo.ts +5 -4
- package/src/fieldTypes/single_block.ts +12 -10
- package/src/fieldTypes/slug.ts +5 -4
- package/src/fieldTypes/string.ts +5 -3
- package/src/fieldTypes/structured_text.ts +7 -7
- package/src/fieldTypes/text.ts +5 -4
- package/src/fieldTypes/video.ts +5 -3
- package/src/generated/Client.ts +1 -1
- package/src/generated/resources/Item.ts +129 -92
- package/src/generated/resources/ScheduledPublication.ts +6 -6
- package/src/generated/resources/ScheduledUnpublishing.ts +6 -6
- package/src/generated/resources/Upload.ts +36 -10
- package/src/index.ts +4 -4
- package/src/utilities/buildBlockRecord.ts +24 -31
- package/src/utilities/inspectItem.ts +590 -0
- package/src/utilities/itemDefinition.ts +53 -35
- package/src/utilities/{blocks.ts → nonRecursiveBlocks.ts} +170 -136
- package/src/utilities/{fieldValue.ts → normalizedFieldValues.ts} +70 -30
- package/src/utilities/recursiveBlocks.ts +186 -171
- 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
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.visitNormalizedFieldValuesAsync = exports.visitNormalizedFieldValues = exports.everyNormalizedFieldValueAsync = exports.everyNormalizedFieldValue = exports.someNormalizedFieldValuesAsync = exports.someNormalizedFieldValues = exports.filterNormalizedFieldValuesAsync = exports.filterNormalizedFieldValues = exports.mapNormalizedFieldValuesAsync = exports.mapNormalizedFieldValues = exports.fromNormalizedFieldValueEntries = exports.toNormalizedFieldValueEntries = exports.isLocalizedFieldValue = exports.isLocalized = void 0;
|
|
13
13
|
/**
|
|
14
14
|
* Determines whether a DatoCMS field is localized or not.
|
|
15
15
|
*
|
|
@@ -23,6 +23,18 @@ function isLocalized(field) {
|
|
|
23
23
|
return 'attributes' in field ? field.attributes.localized : field.localized;
|
|
24
24
|
}
|
|
25
25
|
exports.isLocalized = isLocalized;
|
|
26
|
+
function isLocalizedFieldValue(value) {
|
|
27
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const keys = Object.keys(value);
|
|
31
|
+
if (keys.length === 0) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const localePattern = /^[A-Za-z]{2,4}(-[A-Za-z]{4})?(-([A-Za-z]{2}|[0-9]{3}))?$/;
|
|
35
|
+
return keys.every((key) => localePattern.test(key));
|
|
36
|
+
}
|
|
37
|
+
exports.isLocalizedFieldValue = isLocalizedFieldValue;
|
|
26
38
|
/**
|
|
27
39
|
* Converts a field value (localized or non-localized) into a uniform array of entries.
|
|
28
40
|
*
|
|
@@ -33,7 +45,7 @@ exports.isLocalized = isLocalized;
|
|
|
33
45
|
* @param value - The field value to convert (either a localized object or direct value)
|
|
34
46
|
* @returns Array of entries where each entry contains a locale (string for localized, undefined for non-localized) and the corresponding value
|
|
35
47
|
*/
|
|
36
|
-
function
|
|
48
|
+
function toNormalizedFieldValueEntries(field, value) {
|
|
37
49
|
if (isLocalized(field)) {
|
|
38
50
|
const localizedValue = value;
|
|
39
51
|
return Object.entries(localizedValue).map(([locale, value]) => ({
|
|
@@ -43,11 +55,11 @@ function fieldValueToEntries(field, value) {
|
|
|
43
55
|
}
|
|
44
56
|
return [{ locale: undefined, value: value }];
|
|
45
57
|
}
|
|
46
|
-
exports.
|
|
58
|
+
exports.toNormalizedFieldValueEntries = toNormalizedFieldValueEntries;
|
|
47
59
|
/**
|
|
48
60
|
* Converts an array of possibly localized entries back into the appropriate field value format.
|
|
49
61
|
*
|
|
50
|
-
* This function is the inverse of `
|
|
62
|
+
* This function is the inverse of `toNormalizedFieldValueEntries`. It takes a uniform
|
|
51
63
|
* array of entries and converts them back to either a localized object or a direct value,
|
|
52
64
|
* depending on the field's localization setting.
|
|
53
65
|
*
|
|
@@ -55,7 +67,7 @@ exports.fieldValueToEntries = fieldValueToEntries;
|
|
|
55
67
|
* @param entries - Array of entries to convert back to field value format
|
|
56
68
|
* @returns Either a localized object (for localized fields) or the direct value (for non-localized fields)
|
|
57
69
|
*/
|
|
58
|
-
function
|
|
70
|
+
function fromNormalizedFieldValueEntries(field, entries) {
|
|
59
71
|
if (isLocalized(field)) {
|
|
60
72
|
return Object.fromEntries(entries.map(({ locale, value }) => [locale, value]));
|
|
61
73
|
}
|
|
@@ -64,7 +76,7 @@ function entriesToFieldValue(field, entries) {
|
|
|
64
76
|
}
|
|
65
77
|
return entries[0].value;
|
|
66
78
|
}
|
|
67
|
-
exports.
|
|
79
|
+
exports.fromNormalizedFieldValueEntries = fromNormalizedFieldValueEntries;
|
|
68
80
|
/**
|
|
69
81
|
* Maps field values using a provided mapping function.
|
|
70
82
|
* For localized fields, applies the mapping function to each locale value.
|
|
@@ -76,15 +88,15 @@ exports.entriesToFieldValue = entriesToFieldValue;
|
|
|
76
88
|
* @param mapFn - The function to apply to each locale value or the direct value
|
|
77
89
|
* @returns The mapped value with the same structure as the input
|
|
78
90
|
*/
|
|
79
|
-
function
|
|
80
|
-
const entries =
|
|
91
|
+
function mapNormalizedFieldValues(field, value, mapFn) {
|
|
92
|
+
const entries = toNormalizedFieldValueEntries(field, value);
|
|
81
93
|
const mappedEntries = entries.map(({ locale, value }) => ({
|
|
82
94
|
locale,
|
|
83
95
|
value: mapFn(locale, value),
|
|
84
96
|
}));
|
|
85
|
-
return
|
|
97
|
+
return fromNormalizedFieldValueEntries(field, mappedEntries);
|
|
86
98
|
}
|
|
87
|
-
exports.
|
|
99
|
+
exports.mapNormalizedFieldValues = mapNormalizedFieldValues;
|
|
88
100
|
/**
|
|
89
101
|
* Maps field values using a provided mapping function (async version).
|
|
90
102
|
* For localized fields, applies the mapping function to each locale value.
|
|
@@ -96,19 +108,19 @@ exports.mapFieldValue = mapFieldValue;
|
|
|
96
108
|
* @param mapFn - The function to apply to each locale value or the direct value
|
|
97
109
|
* @returns The mapped value with the same structure as the input
|
|
98
110
|
*/
|
|
99
|
-
function
|
|
111
|
+
function mapNormalizedFieldValuesAsync(field, value, mapFn) {
|
|
100
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
const entries =
|
|
113
|
+
const entries = toNormalizedFieldValueEntries(field, value);
|
|
102
114
|
const mappedEntries = yield Promise.all(entries.map(({ locale, value }) => __awaiter(this, void 0, void 0, function* () {
|
|
103
115
|
return ({
|
|
104
116
|
locale,
|
|
105
117
|
value: yield mapFn(locale, value),
|
|
106
118
|
});
|
|
107
119
|
})));
|
|
108
|
-
return
|
|
120
|
+
return fromNormalizedFieldValueEntries(field, mappedEntries);
|
|
109
121
|
});
|
|
110
122
|
}
|
|
111
|
-
exports.
|
|
123
|
+
exports.mapNormalizedFieldValuesAsync = mapNormalizedFieldValuesAsync;
|
|
112
124
|
/**
|
|
113
125
|
* Filters field values using a provided filter function.
|
|
114
126
|
* For localized fields, filters each locale value.
|
|
@@ -119,16 +131,16 @@ exports.mapFieldValueAsync = mapFieldValueAsync;
|
|
|
119
131
|
* @param filterFn - The function to test each locale value or the direct value
|
|
120
132
|
* @returns The filtered value with the same structure as the input
|
|
121
133
|
*/
|
|
122
|
-
function
|
|
134
|
+
function filterNormalizedFieldValues(field, value, filterFn) {
|
|
123
135
|
var _a;
|
|
124
|
-
const entries =
|
|
136
|
+
const entries = toNormalizedFieldValueEntries(field, value);
|
|
125
137
|
const filteredEntries = entries.filter((entry) => filterFn(entry.locale, entry.value));
|
|
126
138
|
if (isLocalized(field)) {
|
|
127
|
-
return
|
|
139
|
+
return fromNormalizedFieldValueEntries(field, filteredEntries);
|
|
128
140
|
}
|
|
129
141
|
return filteredEntries.length > 0 ? (_a = filteredEntries[0]) === null || _a === void 0 ? void 0 : _a.value : undefined;
|
|
130
142
|
}
|
|
131
|
-
exports.
|
|
143
|
+
exports.filterNormalizedFieldValues = filterNormalizedFieldValues;
|
|
132
144
|
/**
|
|
133
145
|
* Filters field values using a provided filter function (async version).
|
|
134
146
|
* For localized fields, filters each locale value.
|
|
@@ -139,10 +151,10 @@ exports.filterFieldValue = filterFieldValue;
|
|
|
139
151
|
* @param filterFn - The function to test each locale value or the direct value
|
|
140
152
|
* @returns The filtered value with the same structure as the input
|
|
141
153
|
*/
|
|
142
|
-
function
|
|
154
|
+
function filterNormalizedFieldValuesAsync(field, value, filterFn) {
|
|
143
155
|
var _a;
|
|
144
156
|
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
-
const entries =
|
|
157
|
+
const entries = toNormalizedFieldValueEntries(field, value);
|
|
146
158
|
const results = yield Promise.all(entries.map(({ locale, value }) => __awaiter(this, void 0, void 0, function* () {
|
|
147
159
|
return ({
|
|
148
160
|
locale,
|
|
@@ -154,12 +166,12 @@ function filterFieldValueAsync(field, value, filterFn) {
|
|
|
154
166
|
.filter(({ passed }) => passed)
|
|
155
167
|
.map(({ locale, value }) => ({ locale, value }));
|
|
156
168
|
if (isLocalized(field)) {
|
|
157
|
-
return
|
|
169
|
+
return fromNormalizedFieldValueEntries(field, filteredEntries);
|
|
158
170
|
}
|
|
159
171
|
return filteredEntries.length > 0 ? (_a = filteredEntries[0]) === null || _a === void 0 ? void 0 : _a.value : undefined;
|
|
160
172
|
});
|
|
161
173
|
}
|
|
162
|
-
exports.
|
|
174
|
+
exports.filterNormalizedFieldValuesAsync = filterNormalizedFieldValuesAsync;
|
|
163
175
|
/**
|
|
164
176
|
* Tests whether at least one field value passes the test implemented by the provided function.
|
|
165
177
|
* For localized fields, tests each locale value.
|
|
@@ -170,11 +182,11 @@ exports.filterFieldValueAsync = filterFieldValueAsync;
|
|
|
170
182
|
* @param testFn - The function to test each locale value or the direct value
|
|
171
183
|
* @returns true if at least one value passes the test, false otherwise
|
|
172
184
|
*/
|
|
173
|
-
function
|
|
174
|
-
const entries =
|
|
185
|
+
function someNormalizedFieldValues(field, value, testFn) {
|
|
186
|
+
const entries = toNormalizedFieldValueEntries(field, value);
|
|
175
187
|
return entries.some(({ locale, value }) => testFn(locale, value));
|
|
176
188
|
}
|
|
177
|
-
exports.
|
|
189
|
+
exports.someNormalizedFieldValues = someNormalizedFieldValues;
|
|
178
190
|
/**
|
|
179
191
|
* Tests whether at least one field value passes the test implemented by the provided function (async version).
|
|
180
192
|
* For localized fields, tests each locale value.
|
|
@@ -185,14 +197,14 @@ exports.someFieldValue = someFieldValue;
|
|
|
185
197
|
* @param testFn - The function to test each locale value or the direct value
|
|
186
198
|
* @returns true if at least one value passes the test, false otherwise
|
|
187
199
|
*/
|
|
188
|
-
function
|
|
200
|
+
function someNormalizedFieldValuesAsync(field, value, testFn) {
|
|
189
201
|
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
-
const entries =
|
|
202
|
+
const entries = toNormalizedFieldValueEntries(field, value);
|
|
191
203
|
const results = yield Promise.all(entries.map(({ locale, value }) => testFn(locale, value)));
|
|
192
204
|
return results.some((result) => result);
|
|
193
205
|
});
|
|
194
206
|
}
|
|
195
|
-
exports.
|
|
207
|
+
exports.someNormalizedFieldValuesAsync = someNormalizedFieldValuesAsync;
|
|
196
208
|
/**
|
|
197
209
|
* Tests whether all field values pass the test implemented by the provided function.
|
|
198
210
|
* For localized fields, tests each locale value.
|
|
@@ -203,10 +215,10 @@ exports.someFieldValueAsync = someFieldValueAsync;
|
|
|
203
215
|
* @param testFn - The function to test each locale value or the direct value
|
|
204
216
|
* @returns true if all values pass the test, false otherwise
|
|
205
217
|
*/
|
|
206
|
-
function
|
|
207
|
-
return !
|
|
218
|
+
function everyNormalizedFieldValue(field, value, testFn) {
|
|
219
|
+
return !someNormalizedFieldValues(field, value, (locale, localeValue) => !testFn(locale, localeValue));
|
|
208
220
|
}
|
|
209
|
-
exports.
|
|
221
|
+
exports.everyNormalizedFieldValue = everyNormalizedFieldValue;
|
|
210
222
|
/**
|
|
211
223
|
* Tests whether all field values pass the test implemented by the provided function (async version).
|
|
212
224
|
* For localized fields, tests each locale value.
|
|
@@ -217,12 +229,12 @@ exports.everyFieldValue = everyFieldValue;
|
|
|
217
229
|
* @param testFn - The function to test each locale value or the direct value
|
|
218
230
|
* @returns true if all values pass the test, false otherwise
|
|
219
231
|
*/
|
|
220
|
-
function
|
|
232
|
+
function everyNormalizedFieldValueAsync(field, value, testFn) {
|
|
221
233
|
return __awaiter(this, void 0, void 0, function* () {
|
|
222
|
-
return !(yield
|
|
234
|
+
return !(yield someNormalizedFieldValuesAsync(field, value, (locale, localeValue) => __awaiter(this, void 0, void 0, function* () { return !(yield testFn(locale, localeValue)); })));
|
|
223
235
|
});
|
|
224
236
|
}
|
|
225
|
-
exports.
|
|
237
|
+
exports.everyNormalizedFieldValueAsync = everyNormalizedFieldValueAsync;
|
|
226
238
|
/**
|
|
227
239
|
* Visits each field value with the provided function.
|
|
228
240
|
* For localized fields, visits each locale value.
|
|
@@ -232,13 +244,13 @@ exports.everyFieldValueAsync = everyFieldValueAsync;
|
|
|
232
244
|
* @param value - The field value (either localized object or direct value)
|
|
233
245
|
* @param visitFn - The function to call for each locale value or the direct value
|
|
234
246
|
*/
|
|
235
|
-
function
|
|
236
|
-
const entries =
|
|
247
|
+
function visitNormalizedFieldValues(field, value, visitFn) {
|
|
248
|
+
const entries = toNormalizedFieldValueEntries(field, value);
|
|
237
249
|
for (const { locale, value } of entries) {
|
|
238
250
|
visitFn(locale, value);
|
|
239
251
|
}
|
|
240
252
|
}
|
|
241
|
-
exports.
|
|
253
|
+
exports.visitNormalizedFieldValues = visitNormalizedFieldValues;
|
|
242
254
|
/**
|
|
243
255
|
* Visits each field value with the provided function (async version).
|
|
244
256
|
* For localized fields, visits each locale value.
|
|
@@ -248,11 +260,11 @@ exports.visitFieldValue = visitFieldValue;
|
|
|
248
260
|
* @param value - The field value (either localized object or direct value)
|
|
249
261
|
* @param visitFn - The function to call for each locale value or the direct value
|
|
250
262
|
*/
|
|
251
|
-
function
|
|
263
|
+
function visitNormalizedFieldValuesAsync(field, value, visitFn) {
|
|
252
264
|
return __awaiter(this, void 0, void 0, function* () {
|
|
253
|
-
const entries =
|
|
265
|
+
const entries = toNormalizedFieldValueEntries(field, value);
|
|
254
266
|
yield Promise.all(entries.map(({ locale, value }) => visitFn(locale, value)));
|
|
255
267
|
});
|
|
256
268
|
}
|
|
257
|
-
exports.
|
|
258
|
-
//# sourceMappingURL=
|
|
269
|
+
exports.visitNormalizedFieldValuesAsync = visitNormalizedFieldValuesAsync;
|
|
270
|
+
//# sourceMappingURL=normalizedFieldValues.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizedFieldValues.js","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this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
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
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
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 = []) {
|
|
17
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
yield (0,
|
|
29
|
+
yield (0, nonRecursiveBlocks_1.nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync)(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
19
30
|
yield visitor(block, [...path, ...innerPath]);
|
|
20
31
|
if (!(0, fieldTypes_1.isItemWithOptionalIdAndMeta)(block)) {
|
|
21
32
|
return;
|
|
@@ -23,52 +34,61 @@ function visitBlocksInFieldValues(schemaRepository, field, value, visitor, path
|
|
|
23
34
|
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
24
35
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
25
36
|
for (const field of fields) {
|
|
26
|
-
yield (
|
|
27
|
-
...path,
|
|
28
|
-
...innerPath,
|
|
29
|
-
'attributes',
|
|
30
|
-
field.attributes.api_key,
|
|
31
|
-
...(locale ? [locale] : []),
|
|
32
|
-
]));
|
|
37
|
+
yield visitBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, block.attributes[field.attributes.api_key], visitor, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
|
|
33
38
|
}
|
|
34
39
|
}));
|
|
35
40
|
});
|
|
36
41
|
}
|
|
37
|
-
exports.
|
|
38
|
-
|
|
42
|
+
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 = []) {
|
|
39
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
56
|
const results = [];
|
|
41
|
-
const directMatches = yield (0,
|
|
57
|
+
const directMatches = yield (0, nonRecursiveBlocks_1.nonRecursiveFindAllBlocksInNonLocalizedFieldValueAsync)(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () { return yield predicate(block, [...path, ...innerPath]); }));
|
|
42
58
|
results.push(...directMatches.map(({ item, path: innerPath }) => ({
|
|
43
59
|
item,
|
|
44
60
|
path: [...path, ...innerPath],
|
|
45
61
|
})));
|
|
46
|
-
yield (0,
|
|
62
|
+
yield (0, nonRecursiveBlocks_1.nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync)(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
47
63
|
if (!(0, fieldTypes_1.isItemWithOptionalIdAndMeta)(block)) {
|
|
48
64
|
return;
|
|
49
65
|
}
|
|
50
66
|
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
51
67
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
52
68
|
for (const field of fields) {
|
|
53
|
-
yield (
|
|
54
|
-
|
|
55
|
-
...path,
|
|
56
|
-
...innerPath,
|
|
57
|
-
'attributes',
|
|
58
|
-
field.attributes.api_key,
|
|
59
|
-
...(locale ? [locale] : []),
|
|
60
|
-
]);
|
|
61
|
-
results.push(...nestedResults);
|
|
62
|
-
}));
|
|
69
|
+
const nestedResults = yield findAllBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, block.attributes[field.attributes.api_key], predicate, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
|
|
70
|
+
results.push(...nestedResults);
|
|
63
71
|
}
|
|
64
72
|
}));
|
|
65
73
|
return results;
|
|
66
74
|
});
|
|
67
75
|
}
|
|
68
|
-
exports.
|
|
69
|
-
|
|
76
|
+
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 = []) {
|
|
70
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
return (0,
|
|
91
|
+
return (0, nonRecursiveBlocks_1.nonRecursiveFilterBlocksInNonLocalizedFieldValueAsync)(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
72
92
|
const blockPath = [...path, ...innerPath];
|
|
73
93
|
const passes = yield predicate(block, blockPath);
|
|
74
94
|
if (!passes) {
|
|
@@ -80,51 +100,64 @@ function filterBlocksInFieldValues(schemaRepository, field, value, predicate, pa
|
|
|
80
100
|
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
81
101
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
82
102
|
for (const field of fields) {
|
|
83
|
-
block.attributes[field.attributes.api_key] =
|
|
84
|
-
...blockPath,
|
|
85
|
-
'attributes',
|
|
86
|
-
field.attributes.api_key,
|
|
87
|
-
...(locale ? [locale] : []),
|
|
88
|
-
]));
|
|
103
|
+
block.attributes[field.attributes.api_key] =
|
|
104
|
+
yield filterBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, block.attributes[field.attributes.api_key], predicate, [...blockPath, 'attributes', field.attributes.api_key]);
|
|
89
105
|
}
|
|
90
106
|
return true;
|
|
91
107
|
}));
|
|
92
108
|
});
|
|
93
109
|
}
|
|
94
|
-
exports.
|
|
95
|
-
|
|
110
|
+
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 = []) {
|
|
96
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
let accumulator = yield (0,
|
|
98
|
-
yield (0,
|
|
126
|
+
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
|
+
yield (0, nonRecursiveBlocks_1.nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync)(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
99
128
|
if (!(0, fieldTypes_1.isItemWithOptionalIdAndMeta)(block)) {
|
|
100
129
|
return;
|
|
101
130
|
}
|
|
102
131
|
const itemType = yield schemaRepository.getRawItemTypeById(block.relationships.item_type.data.id);
|
|
103
132
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
104
133
|
for (const field of fields) {
|
|
105
|
-
yield (
|
|
106
|
-
accumulator = yield reduceBlocksInFieldValues(schemaRepository, field, valueForLocale, reducer, accumulator, [
|
|
107
|
-
...path,
|
|
108
|
-
...innerPath,
|
|
109
|
-
'attributes',
|
|
110
|
-
field.attributes.api_key,
|
|
111
|
-
...(locale ? [locale] : []),
|
|
112
|
-
]);
|
|
113
|
-
}));
|
|
134
|
+
accumulator = yield reduceBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, block.attributes[field.attributes.api_key], reducer, accumulator, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
|
|
114
135
|
}
|
|
115
136
|
}));
|
|
116
137
|
return accumulator;
|
|
117
138
|
});
|
|
118
139
|
}
|
|
119
|
-
exports.
|
|
120
|
-
|
|
140
|
+
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 = []) {
|
|
121
154
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
-
const directMatch = yield (0,
|
|
155
|
+
const directMatch = yield (0, nonRecursiveBlocks_1.nonRecursiveSomeBlocksInNonLocalizedFieldValueAsync)(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () { return yield predicate(block, [...path, ...innerPath]); }));
|
|
123
156
|
if (directMatch) {
|
|
124
157
|
return true;
|
|
125
158
|
}
|
|
126
159
|
let found = false;
|
|
127
|
-
yield (0,
|
|
160
|
+
yield (0, nonRecursiveBlocks_1.nonRecursiveVisitBlocksInNonLocalizedFieldValueAsync)(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
128
161
|
if (found || !(0, fieldTypes_1.isItemWithOptionalIdAndMeta)(block)) {
|
|
129
162
|
return;
|
|
130
163
|
}
|
|
@@ -133,35 +166,49 @@ function someBlocksInFieldValues(schemaRepository, field, value, predicate, path
|
|
|
133
166
|
for (const field of fields) {
|
|
134
167
|
if (found)
|
|
135
168
|
break;
|
|
136
|
-
yield (
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
...path,
|
|
141
|
-
...innerPath,
|
|
142
|
-
'attributes',
|
|
143
|
-
field.attributes.api_key,
|
|
144
|
-
...(locale ? [locale] : []),
|
|
145
|
-
]);
|
|
146
|
-
if (nestedMatch) {
|
|
147
|
-
found = true;
|
|
148
|
-
}
|
|
149
|
-
}));
|
|
169
|
+
const nestedMatch = yield someBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, block.attributes[field.attributes.api_key], predicate, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
|
|
170
|
+
if (nestedMatch) {
|
|
171
|
+
found = true;
|
|
172
|
+
}
|
|
150
173
|
}
|
|
151
174
|
}));
|
|
152
175
|
return found;
|
|
153
176
|
});
|
|
154
177
|
}
|
|
155
|
-
exports.
|
|
156
|
-
|
|
178
|
+
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 = []) {
|
|
157
192
|
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
-
return !(yield
|
|
193
|
+
return !(yield someBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, nonLocalizedFieldValue, (item, path) => __awaiter(this, void 0, void 0, function* () { return !(yield predicate(item, path)); }), path));
|
|
159
194
|
});
|
|
160
195
|
}
|
|
161
|
-
exports.
|
|
162
|
-
|
|
196
|
+
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 = []) {
|
|
163
210
|
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
return (0,
|
|
211
|
+
return (0, nonRecursiveBlocks_1.nonRecursiveMapBlocksInNonLocalizedFieldValueAsync)(fieldType, nonLocalizedFieldValue, (block, innerPath) => __awaiter(this, void 0, void 0, function* () {
|
|
165
212
|
const newBlock = yield mapper(block, [...path, ...innerPath]);
|
|
166
213
|
if (!(0, fieldTypes_1.isItemWithOptionalIdAndMeta)(newBlock)) {
|
|
167
214
|
return newBlock;
|
|
@@ -170,17 +217,11 @@ function mapBlocksInFieldValues(schemaRepository, field, value, mapper, path = [
|
|
|
170
217
|
const fields = yield schemaRepository.getRawItemTypeFields(itemType);
|
|
171
218
|
for (const field of fields) {
|
|
172
219
|
newBlock.attributes[field.attributes.api_key] =
|
|
173
|
-
yield (
|
|
174
|
-
...path,
|
|
175
|
-
...innerPath,
|
|
176
|
-
'attributes',
|
|
177
|
-
field.attributes.api_key,
|
|
178
|
-
...(locale ? [locale] : []),
|
|
179
|
-
]));
|
|
220
|
+
yield mapBlocksInNonLocalizedFieldValue(schemaRepository, fieldType, newBlock.attributes[field.attributes.api_key], mapper, [...path, ...innerPath, 'attributes', field.attributes.api_key]);
|
|
180
221
|
}
|
|
181
222
|
return newBlock;
|
|
182
223
|
}));
|
|
183
224
|
});
|
|
184
225
|
}
|
|
185
|
-
exports.
|
|
226
|
+
exports.mapBlocksInNonLocalizedFieldValue = mapBlocksInNonLocalizedFieldValue;
|
|
186
227
|
//# sourceMappingURL=recursiveBlocks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recursiveBlocks.js","sourceRoot":"","sources":["../../../src/utilities/recursiveBlocks.ts"],"names":[],"mappings":";;;;;;;;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EAAE,GAAG,SAAS,EAAE,YAAY,EAAE,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAChE,CAAC;aACL;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAA,CACF,CAAC;IACJ,CAAC;CAAA;AAxCD,8EAwCC"}
|
|
@@ -27,7 +27,7 @@ const rest_client_utils_1 = require("@datocms/rest-client-utils");
|
|
|
27
27
|
* - **Caching schema entities**: Automatically caches item types, fields, fieldsets,
|
|
28
28
|
* and plugins after the first API request, returning cached results on subsequent calls
|
|
29
29
|
* - **Complex traversal operations**: Essential when using utilities like
|
|
30
|
-
* `
|
|
30
|
+
* `mapBlocksInNonLocalizedFieldValue()` that need to repeatedly lookup block models and fields
|
|
31
31
|
* while traversing nested content structures
|
|
32
32
|
* - **Bulk operations**: Ideal for scripts that process multiple records of different
|
|
33
33
|
* types and need efficient access to schema information
|
|
@@ -59,7 +59,7 @@ const rest_client_utils_1 = require("@datocms/rest-client-utils");
|
|
|
59
59
|
* const sameBlogPost = await schemaRepository.getItemTypeByApiKey('blog_post');
|
|
60
60
|
*
|
|
61
61
|
* // Pass the repository to utilities that need schema information
|
|
62
|
-
* await
|
|
62
|
+
* await mapBlocksInNonLocalizedFieldValue(schemaRepository, record, (block) => {
|
|
63
63
|
* // The utility will use the cached schema data internally
|
|
64
64
|
* });
|
|
65
65
|
* ```
|