@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
|
@@ -18,6 +18,7 @@ export type LocalizedFieldValue<T = unknown, L extends string = string> = Partia
|
|
|
18
18
|
* @returns true if the field is localized, false otherwise
|
|
19
19
|
*/
|
|
20
20
|
export declare function isLocalized(field: RawApiTypes.Field | ApiTypes.Field): boolean;
|
|
21
|
+
export declare function isLocalizedFieldValue<T = unknown, L extends string = string>(value: unknown): value is LocalizedFieldValue<T, L>;
|
|
21
22
|
/**
|
|
22
23
|
* A normalized entry that represents a single value from either a localized or non-localized field.
|
|
23
24
|
*
|
|
@@ -26,7 +27,7 @@ export declare function isLocalized(field: RawApiTypes.Field | ApiTypes.Field):
|
|
|
26
27
|
*
|
|
27
28
|
* This uniform structure allows the same processing logic to work with both field types.
|
|
28
29
|
*/
|
|
29
|
-
export type
|
|
30
|
+
export type NormalizedFieldValueEntry<T = unknown, L extends string = string> = {
|
|
30
31
|
locale: L | undefined;
|
|
31
32
|
value: T;
|
|
32
33
|
};
|
|
@@ -40,11 +41,11 @@ export type FieldValueEntry<T = unknown, L extends string = string> = {
|
|
|
40
41
|
* @param value - The field value to convert (either a localized object or direct value)
|
|
41
42
|
* @returns Array of entries where each entry contains a locale (string for localized, undefined for non-localized) and the corresponding value
|
|
42
43
|
*/
|
|
43
|
-
export declare function
|
|
44
|
+
export declare function toNormalizedFieldValueEntries<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>): NormalizedFieldValueEntry<T, L>[];
|
|
44
45
|
/**
|
|
45
46
|
* Converts an array of possibly localized entries back into the appropriate field value format.
|
|
46
47
|
*
|
|
47
|
-
* This function is the inverse of `
|
|
48
|
+
* This function is the inverse of `toNormalizedFieldValueEntries`. It takes a uniform
|
|
48
49
|
* array of entries and converts them back to either a localized object or a direct value,
|
|
49
50
|
* depending on the field's localization setting.
|
|
50
51
|
*
|
|
@@ -52,7 +53,7 @@ export declare function fieldValueToEntries<T = unknown, L extends string = stri
|
|
|
52
53
|
* @param entries - Array of entries to convert back to field value format
|
|
53
54
|
* @returns Either a localized object (for localized fields) or the direct value (for non-localized fields)
|
|
54
55
|
*/
|
|
55
|
-
export declare function
|
|
56
|
+
export declare function fromNormalizedFieldValueEntries<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, entries: NormalizedFieldValueEntry<T, L>[]): T | LocalizedFieldValue<T, L>;
|
|
56
57
|
/**
|
|
57
58
|
* Maps field values using a provided mapping function.
|
|
58
59
|
* For localized fields, applies the mapping function to each locale value.
|
|
@@ -64,7 +65,7 @@ export declare function entriesToFieldValue<T = unknown, L extends string = stri
|
|
|
64
65
|
* @param mapFn - The function to apply to each locale value or the direct value
|
|
65
66
|
* @returns The mapped value with the same structure as the input
|
|
66
67
|
*/
|
|
67
|
-
export declare function
|
|
68
|
+
export declare function mapNormalizedFieldValues<TInput = unknown, TOutput = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: TInput | LocalizedFieldValue<TInput, L>, mapFn: (locale: L | undefined, localeValue: TInput) => TOutput): TOutput | LocalizedFieldValue<TOutput, L>;
|
|
68
69
|
/**
|
|
69
70
|
* Maps field values using a provided mapping function (async version).
|
|
70
71
|
* For localized fields, applies the mapping function to each locale value.
|
|
@@ -76,7 +77,7 @@ export declare function mapFieldValue<TInput = unknown, TOutput = unknown, L ext
|
|
|
76
77
|
* @param mapFn - The function to apply to each locale value or the direct value
|
|
77
78
|
* @returns The mapped value with the same structure as the input
|
|
78
79
|
*/
|
|
79
|
-
export declare function
|
|
80
|
+
export declare function mapNormalizedFieldValuesAsync<TInput = unknown, TOutput = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: TInput | LocalizedFieldValue<TInput, L>, mapFn: (locale: L | undefined, localeValue: TInput) => Promise<TOutput>): Promise<TOutput | LocalizedFieldValue<TOutput, L>>;
|
|
80
81
|
/**
|
|
81
82
|
* Filters field values using a provided filter function.
|
|
82
83
|
* For localized fields, filters each locale value.
|
|
@@ -87,7 +88,7 @@ export declare function mapFieldValueAsync<TInput = unknown, TOutput = unknown,
|
|
|
87
88
|
* @param filterFn - The function to test each locale value or the direct value
|
|
88
89
|
* @returns The filtered value with the same structure as the input
|
|
89
90
|
*/
|
|
90
|
-
export declare function
|
|
91
|
+
export declare function filterNormalizedFieldValues<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, filterFn: (locale: L | undefined, localeValue: T) => boolean): T | LocalizedFieldValue<T, L> | undefined;
|
|
91
92
|
/**
|
|
92
93
|
* Filters field values using a provided filter function (async version).
|
|
93
94
|
* For localized fields, filters each locale value.
|
|
@@ -98,7 +99,7 @@ export declare function filterFieldValue<T = unknown, L extends string = string>
|
|
|
98
99
|
* @param filterFn - The function to test each locale value or the direct value
|
|
99
100
|
* @returns The filtered value with the same structure as the input
|
|
100
101
|
*/
|
|
101
|
-
export declare function
|
|
102
|
+
export declare function filterNormalizedFieldValuesAsync<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, filterFn: (locale: L | undefined, localeValue: T) => Promise<boolean>): Promise<T | LocalizedFieldValue<T, L> | undefined>;
|
|
102
103
|
/**
|
|
103
104
|
* Tests whether at least one field value passes the test implemented by the provided function.
|
|
104
105
|
* For localized fields, tests each locale value.
|
|
@@ -109,7 +110,7 @@ export declare function filterFieldValueAsync<T = unknown, L extends string = st
|
|
|
109
110
|
* @param testFn - The function to test each locale value or the direct value
|
|
110
111
|
* @returns true if at least one value passes the test, false otherwise
|
|
111
112
|
*/
|
|
112
|
-
export declare function
|
|
113
|
+
export declare function someNormalizedFieldValues<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, testFn: (locale: L | undefined, localeValue: T) => boolean): boolean;
|
|
113
114
|
/**
|
|
114
115
|
* Tests whether at least one field value passes the test implemented by the provided function (async version).
|
|
115
116
|
* For localized fields, tests each locale value.
|
|
@@ -120,7 +121,7 @@ export declare function someFieldValue<T = unknown, L extends string = string>(f
|
|
|
120
121
|
* @param testFn - The function to test each locale value or the direct value
|
|
121
122
|
* @returns true if at least one value passes the test, false otherwise
|
|
122
123
|
*/
|
|
123
|
-
export declare function
|
|
124
|
+
export declare function someNormalizedFieldValuesAsync<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, testFn: (locale: L | undefined, localeValue: T) => Promise<boolean>): Promise<boolean>;
|
|
124
125
|
/**
|
|
125
126
|
* Tests whether all field values pass the test implemented by the provided function.
|
|
126
127
|
* For localized fields, tests each locale value.
|
|
@@ -131,7 +132,7 @@ export declare function someFieldValueAsync<T = unknown, L extends string = stri
|
|
|
131
132
|
* @param testFn - The function to test each locale value or the direct value
|
|
132
133
|
* @returns true if all values pass the test, false otherwise
|
|
133
134
|
*/
|
|
134
|
-
export declare function
|
|
135
|
+
export declare function everyNormalizedFieldValue<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, testFn: (locale: L | undefined, localeValue: T) => boolean): boolean;
|
|
135
136
|
/**
|
|
136
137
|
* Tests whether all field values pass the test implemented by the provided function (async version).
|
|
137
138
|
* For localized fields, tests each locale value.
|
|
@@ -142,7 +143,7 @@ export declare function everyFieldValue<T = unknown, L extends string = string>(
|
|
|
142
143
|
* @param testFn - The function to test each locale value or the direct value
|
|
143
144
|
* @returns true if all values pass the test, false otherwise
|
|
144
145
|
*/
|
|
145
|
-
export declare function
|
|
146
|
+
export declare function everyNormalizedFieldValueAsync<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, testFn: (locale: L | undefined, localeValue: T) => Promise<boolean>): Promise<boolean>;
|
|
146
147
|
/**
|
|
147
148
|
* Visits each field value with the provided function.
|
|
148
149
|
* For localized fields, visits each locale value.
|
|
@@ -152,7 +153,7 @@ export declare function everyFieldValueAsync<T = unknown, L extends string = str
|
|
|
152
153
|
* @param value - The field value (either localized object or direct value)
|
|
153
154
|
* @param visitFn - The function to call for each locale value or the direct value
|
|
154
155
|
*/
|
|
155
|
-
export declare function
|
|
156
|
+
export declare function visitNormalizedFieldValues<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, visitFn: (locale: L | undefined, localeValue: T) => void): void;
|
|
156
157
|
/**
|
|
157
158
|
* Visits each field value with the provided function (async version).
|
|
158
159
|
* For localized fields, visits each locale value.
|
|
@@ -162,4 +163,4 @@ export declare function visitFieldValue<T = unknown, L extends string = string>(
|
|
|
162
163
|
* @param value - The field value (either localized object or direct value)
|
|
163
164
|
* @param visitFn - The function to call for each locale value or the direct value
|
|
164
165
|
*/
|
|
165
|
-
export declare function
|
|
166
|
+
export declare function visitNormalizedFieldValuesAsync<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field, value: T | LocalizedFieldValue<T, L>, visitFn: (locale: L | undefined, localeValue: T) => Promise<void>): Promise<void>;
|
|
@@ -19,6 +19,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
19
|
export function isLocalized(field) {
|
|
20
20
|
return 'attributes' in field ? field.attributes.localized : field.localized;
|
|
21
21
|
}
|
|
22
|
+
export function isLocalizedFieldValue(value) {
|
|
23
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const keys = Object.keys(value);
|
|
27
|
+
if (keys.length === 0) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const localePattern = /^[A-Za-z]{2,4}(-[A-Za-z]{4})?(-([A-Za-z]{2}|[0-9]{3}))?$/;
|
|
31
|
+
return keys.every((key) => localePattern.test(key));
|
|
32
|
+
}
|
|
22
33
|
/**
|
|
23
34
|
* Converts a field value (localized or non-localized) into a uniform array of entries.
|
|
24
35
|
*
|
|
@@ -29,7 +40,7 @@ export function isLocalized(field) {
|
|
|
29
40
|
* @param value - The field value to convert (either a localized object or direct value)
|
|
30
41
|
* @returns Array of entries where each entry contains a locale (string for localized, undefined for non-localized) and the corresponding value
|
|
31
42
|
*/
|
|
32
|
-
export function
|
|
43
|
+
export function toNormalizedFieldValueEntries(field, value) {
|
|
33
44
|
if (isLocalized(field)) {
|
|
34
45
|
const localizedValue = value;
|
|
35
46
|
return Object.entries(localizedValue).map(([locale, value]) => ({
|
|
@@ -42,7 +53,7 @@ export function fieldValueToEntries(field, value) {
|
|
|
42
53
|
/**
|
|
43
54
|
* Converts an array of possibly localized entries back into the appropriate field value format.
|
|
44
55
|
*
|
|
45
|
-
* This function is the inverse of `
|
|
56
|
+
* This function is the inverse of `toNormalizedFieldValueEntries`. It takes a uniform
|
|
46
57
|
* array of entries and converts them back to either a localized object or a direct value,
|
|
47
58
|
* depending on the field's localization setting.
|
|
48
59
|
*
|
|
@@ -50,7 +61,7 @@ export function fieldValueToEntries(field, value) {
|
|
|
50
61
|
* @param entries - Array of entries to convert back to field value format
|
|
51
62
|
* @returns Either a localized object (for localized fields) or the direct value (for non-localized fields)
|
|
52
63
|
*/
|
|
53
|
-
export function
|
|
64
|
+
export function fromNormalizedFieldValueEntries(field, entries) {
|
|
54
65
|
if (isLocalized(field)) {
|
|
55
66
|
return Object.fromEntries(entries.map(({ locale, value }) => [locale, value]));
|
|
56
67
|
}
|
|
@@ -70,13 +81,13 @@ export function entriesToFieldValue(field, entries) {
|
|
|
70
81
|
* @param mapFn - The function to apply to each locale value or the direct value
|
|
71
82
|
* @returns The mapped value with the same structure as the input
|
|
72
83
|
*/
|
|
73
|
-
export function
|
|
74
|
-
const entries =
|
|
84
|
+
export function mapNormalizedFieldValues(field, value, mapFn) {
|
|
85
|
+
const entries = toNormalizedFieldValueEntries(field, value);
|
|
75
86
|
const mappedEntries = entries.map(({ locale, value }) => ({
|
|
76
87
|
locale,
|
|
77
88
|
value: mapFn(locale, value),
|
|
78
89
|
}));
|
|
79
|
-
return
|
|
90
|
+
return fromNormalizedFieldValueEntries(field, mappedEntries);
|
|
80
91
|
}
|
|
81
92
|
/**
|
|
82
93
|
* Maps field values using a provided mapping function (async version).
|
|
@@ -89,16 +100,16 @@ export function mapFieldValue(field, value, mapFn) {
|
|
|
89
100
|
* @param mapFn - The function to apply to each locale value or the direct value
|
|
90
101
|
* @returns The mapped value with the same structure as the input
|
|
91
102
|
*/
|
|
92
|
-
export function
|
|
103
|
+
export function mapNormalizedFieldValuesAsync(field, value, mapFn) {
|
|
93
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
const entries =
|
|
105
|
+
const entries = toNormalizedFieldValueEntries(field, value);
|
|
95
106
|
const mappedEntries = yield Promise.all(entries.map(({ locale, value }) => __awaiter(this, void 0, void 0, function* () {
|
|
96
107
|
return ({
|
|
97
108
|
locale,
|
|
98
109
|
value: yield mapFn(locale, value),
|
|
99
110
|
});
|
|
100
111
|
})));
|
|
101
|
-
return
|
|
112
|
+
return fromNormalizedFieldValueEntries(field, mappedEntries);
|
|
102
113
|
});
|
|
103
114
|
}
|
|
104
115
|
/**
|
|
@@ -111,12 +122,12 @@ export function mapFieldValueAsync(field, value, mapFn) {
|
|
|
111
122
|
* @param filterFn - The function to test each locale value or the direct value
|
|
112
123
|
* @returns The filtered value with the same structure as the input
|
|
113
124
|
*/
|
|
114
|
-
export function
|
|
125
|
+
export function filterNormalizedFieldValues(field, value, filterFn) {
|
|
115
126
|
var _a;
|
|
116
|
-
const entries =
|
|
127
|
+
const entries = toNormalizedFieldValueEntries(field, value);
|
|
117
128
|
const filteredEntries = entries.filter((entry) => filterFn(entry.locale, entry.value));
|
|
118
129
|
if (isLocalized(field)) {
|
|
119
|
-
return
|
|
130
|
+
return fromNormalizedFieldValueEntries(field, filteredEntries);
|
|
120
131
|
}
|
|
121
132
|
return filteredEntries.length > 0 ? (_a = filteredEntries[0]) === null || _a === void 0 ? void 0 : _a.value : undefined;
|
|
122
133
|
}
|
|
@@ -130,10 +141,10 @@ export function filterFieldValue(field, value, filterFn) {
|
|
|
130
141
|
* @param filterFn - The function to test each locale value or the direct value
|
|
131
142
|
* @returns The filtered value with the same structure as the input
|
|
132
143
|
*/
|
|
133
|
-
export function
|
|
144
|
+
export function filterNormalizedFieldValuesAsync(field, value, filterFn) {
|
|
134
145
|
var _a;
|
|
135
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
-
const entries =
|
|
147
|
+
const entries = toNormalizedFieldValueEntries(field, value);
|
|
137
148
|
const results = yield Promise.all(entries.map(({ locale, value }) => __awaiter(this, void 0, void 0, function* () {
|
|
138
149
|
return ({
|
|
139
150
|
locale,
|
|
@@ -145,7 +156,7 @@ export function filterFieldValueAsync(field, value, filterFn) {
|
|
|
145
156
|
.filter(({ passed }) => passed)
|
|
146
157
|
.map(({ locale, value }) => ({ locale, value }));
|
|
147
158
|
if (isLocalized(field)) {
|
|
148
|
-
return
|
|
159
|
+
return fromNormalizedFieldValueEntries(field, filteredEntries);
|
|
149
160
|
}
|
|
150
161
|
return filteredEntries.length > 0 ? (_a = filteredEntries[0]) === null || _a === void 0 ? void 0 : _a.value : undefined;
|
|
151
162
|
});
|
|
@@ -160,8 +171,8 @@ export function filterFieldValueAsync(field, value, filterFn) {
|
|
|
160
171
|
* @param testFn - The function to test each locale value or the direct value
|
|
161
172
|
* @returns true if at least one value passes the test, false otherwise
|
|
162
173
|
*/
|
|
163
|
-
export function
|
|
164
|
-
const entries =
|
|
174
|
+
export function someNormalizedFieldValues(field, value, testFn) {
|
|
175
|
+
const entries = toNormalizedFieldValueEntries(field, value);
|
|
165
176
|
return entries.some(({ locale, value }) => testFn(locale, value));
|
|
166
177
|
}
|
|
167
178
|
/**
|
|
@@ -174,9 +185,9 @@ export function someFieldValue(field, value, testFn) {
|
|
|
174
185
|
* @param testFn - The function to test each locale value or the direct value
|
|
175
186
|
* @returns true if at least one value passes the test, false otherwise
|
|
176
187
|
*/
|
|
177
|
-
export function
|
|
188
|
+
export function someNormalizedFieldValuesAsync(field, value, testFn) {
|
|
178
189
|
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
-
const entries =
|
|
190
|
+
const entries = toNormalizedFieldValueEntries(field, value);
|
|
180
191
|
const results = yield Promise.all(entries.map(({ locale, value }) => testFn(locale, value)));
|
|
181
192
|
return results.some((result) => result);
|
|
182
193
|
});
|
|
@@ -191,8 +202,8 @@ export function someFieldValueAsync(field, value, testFn) {
|
|
|
191
202
|
* @param testFn - The function to test each locale value or the direct value
|
|
192
203
|
* @returns true if all values pass the test, false otherwise
|
|
193
204
|
*/
|
|
194
|
-
export function
|
|
195
|
-
return !
|
|
205
|
+
export function everyNormalizedFieldValue(field, value, testFn) {
|
|
206
|
+
return !someNormalizedFieldValues(field, value, (locale, localeValue) => !testFn(locale, localeValue));
|
|
196
207
|
}
|
|
197
208
|
/**
|
|
198
209
|
* Tests whether all field values pass the test implemented by the provided function (async version).
|
|
@@ -204,9 +215,9 @@ export function everyFieldValue(field, value, testFn) {
|
|
|
204
215
|
* @param testFn - The function to test each locale value or the direct value
|
|
205
216
|
* @returns true if all values pass the test, false otherwise
|
|
206
217
|
*/
|
|
207
|
-
export function
|
|
218
|
+
export function everyNormalizedFieldValueAsync(field, value, testFn) {
|
|
208
219
|
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
-
return !(yield
|
|
220
|
+
return !(yield someNormalizedFieldValuesAsync(field, value, (locale, localeValue) => __awaiter(this, void 0, void 0, function* () { return !(yield testFn(locale, localeValue)); })));
|
|
210
221
|
});
|
|
211
222
|
}
|
|
212
223
|
/**
|
|
@@ -218,8 +229,8 @@ export function everyFieldValueAsync(field, value, testFn) {
|
|
|
218
229
|
* @param value - The field value (either localized object or direct value)
|
|
219
230
|
* @param visitFn - The function to call for each locale value or the direct value
|
|
220
231
|
*/
|
|
221
|
-
export function
|
|
222
|
-
const entries =
|
|
232
|
+
export function visitNormalizedFieldValues(field, value, visitFn) {
|
|
233
|
+
const entries = toNormalizedFieldValueEntries(field, value);
|
|
223
234
|
for (const { locale, value } of entries) {
|
|
224
235
|
visitFn(locale, value);
|
|
225
236
|
}
|
|
@@ -233,10 +244,10 @@ export function visitFieldValue(field, value, visitFn) {
|
|
|
233
244
|
* @param value - The field value (either localized object or direct value)
|
|
234
245
|
* @param visitFn - The function to call for each locale value or the direct value
|
|
235
246
|
*/
|
|
236
|
-
export function
|
|
247
|
+
export function visitNormalizedFieldValuesAsync(field, value, visitFn) {
|
|
237
248
|
return __awaiter(this, void 0, void 0, function* () {
|
|
238
|
-
const entries =
|
|
249
|
+
const entries = toNormalizedFieldValueEntries(field, value);
|
|
239
250
|
yield Promise.all(entries.map(({ locale, value }) => visitFn(locale, value)));
|
|
240
251
|
});
|
|
241
252
|
}
|
|
242
|
-
//# sourceMappingURL=
|
|
253
|
+
//# sourceMappingURL=normalizedFieldValues.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizedFieldValues.js","sourceRoot":"","sources":["../../../src/utilities/normalizedFieldValues.ts"],"names":[],"mappings":";;;;;;;;;AAkCA;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CACzB,KAAyC;IAEzC,OAAO,YAAY,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,KAAc;IAEd,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACvE,OAAO,KAAK,CAAC;KACd;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAEhC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QACrB,OAAO,KAAK,CAAC;KACd;IAED,MAAM,aAAa,GACjB,0DAA0D,CAAC;IAE7D,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC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ACvC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;KACxB;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAgB,+BAA+B,CAInD,KAAyC,EACzC,KAAoC,EACpC,OAAiE;;QAEjE,MAAM,OAAO,GAAG,6BAA6B,CAAO,KAAK,EAAE,KAAK,CAAC,CAAC;QAClE,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAChF,CAAC;CAAA"}
|
|
@@ -1,18 +1,131 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type BlockInRequest, type RichTextFieldValue, type RichTextFieldValueInNestedResponse, type RichTextFieldValueInRequest, type SingleBlockFieldValue, type SingleBlockFieldValueInNestedResponse, type SingleBlockFieldValueInRequest, type StructuredTextFieldValue, type StructuredTextFieldValueInNestedResponse, type StructuredTextFieldValueInRequest } from '../fieldTypes';
|
|
2
2
|
import type * as ApiTypes from '../generated/ApiTypes';
|
|
3
|
-
import type
|
|
3
|
+
import type { ExtractNestedBlocksFromFieldValue } from './itemDefinition';
|
|
4
4
|
import type { SchemaRepository } from './schemaRepository';
|
|
5
|
+
type RecognizableFieldValue = RichTextFieldValueInNestedResponse | SingleBlockFieldValueInNestedResponse | StructuredTextFieldValueInNestedResponse | RichTextFieldValueInRequest | SingleBlockFieldValueInRequest | StructuredTextFieldValueInRequest | RichTextFieldValue | SingleBlockFieldValue | StructuredTextFieldValue;
|
|
5
6
|
/**
|
|
6
|
-
* Path through a field value (ie. ['content', 0, 'attributes', 'title'])
|
|
7
|
+
* Path through a non-localized field value (ie. ['content', 0, 'attributes', 'title'])
|
|
7
8
|
*/
|
|
8
9
|
export type TreePath = readonly (string | number)[];
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Traversal direction for recursive operations
|
|
12
|
+
*/
|
|
13
|
+
export type TraversalDirection = 'top-down' | 'bottom-up';
|
|
14
|
+
/**
|
|
15
|
+
* Recursively visit every block in a non-localized field value and all nested blocks within those blocks.
|
|
16
|
+
* This function traverses not only the direct blocks in the non-localized field value but also recursively
|
|
17
|
+
* visits blocks contained within the attributes of each block, creating a complete traversal
|
|
18
|
+
* of the entire block hierarchy.
|
|
19
|
+
*
|
|
20
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to visit
|
|
21
|
+
* @param fieldType - The type field (determines how the value is processed)
|
|
22
|
+
* @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
|
|
23
|
+
* @param visitor - Asynchronous function called for each block found, including nested blocks
|
|
24
|
+
* @returns Promise that resolves when all blocks and nested blocks have been visited
|
|
25
|
+
*/
|
|
26
|
+
export declare function visitBlocksInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, visitor: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => void | Promise<void>, path?: TreePath): Promise<void>;
|
|
27
|
+
export declare function visitBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, visitor: (item: BlockInRequest, path: TreePath) => void | Promise<void>, path?: TreePath): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Recursively find all blocks that match the predicate function in a non-localized field value.
|
|
30
|
+
* Searches through all direct blocks and recursively through nested blocks within
|
|
31
|
+
* the attributes of each block, returning all matches found throughout the hierarchy.
|
|
32
|
+
*
|
|
33
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to search
|
|
34
|
+
* @param fieldType - The type field (determines how the value is processed)
|
|
35
|
+
* @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
|
|
36
|
+
* @param predicate - Asynchronous function that tests each block, including nested ones
|
|
37
|
+
* @returns Promise that resolves to an array of objects, each containing a matching block and its full path
|
|
38
|
+
*/
|
|
39
|
+
export declare function findAllBlocksInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<Array<{
|
|
40
|
+
item: ExtractNestedBlocksFromFieldValue<T>;
|
|
41
|
+
path: TreePath;
|
|
42
|
+
}>>;
|
|
43
|
+
export declare function findAllBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: BlockInRequest, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<Array<{
|
|
44
|
+
item: BlockInRequest;
|
|
12
45
|
path: TreePath;
|
|
13
46
|
}>>;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Recursively filter blocks in a non-localized field value, removing those that don't match the predicate.
|
|
49
|
+
* Creates a new non-localized field value structure containing only blocks that pass the predicate test,
|
|
50
|
+
* including recursive filtering of nested blocks within block attributes. The filtering
|
|
51
|
+
* preserves the original non-localized field value structure and hierarchy.
|
|
52
|
+
*
|
|
53
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to filter
|
|
54
|
+
* @param fieldType - The type field (determines how the value is processed)
|
|
55
|
+
* @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
|
|
56
|
+
* @param predicate - Asynchronous function that tests each block, including nested ones
|
|
57
|
+
* @param options - Optional configuration object
|
|
58
|
+
* @param options.traversalDirection - Direction of traversal: 'top-down' (default) applies predicate before processing children, 'bottom-up' processes children first
|
|
59
|
+
* @returns Promise that resolves to the new non-localized field value with recursively filtered blocks
|
|
60
|
+
*/
|
|
61
|
+
export declare function filterBlocksInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => boolean | Promise<boolean>, options?: {
|
|
62
|
+
traversalDirection?: TraversalDirection;
|
|
63
|
+
}, path?: TreePath): Promise<T>;
|
|
64
|
+
export declare function filterBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: BlockInRequest, path: TreePath) => boolean | Promise<boolean>, options?: {
|
|
65
|
+
traversalDirection?: TraversalDirection;
|
|
66
|
+
}, path?: TreePath): Promise<unknown>;
|
|
67
|
+
/**
|
|
68
|
+
* Recursively reduce all blocks in a non-localized field value to a single value by applying a reducer function.
|
|
69
|
+
* Processes each direct block and recursively processes nested blocks within block attributes,
|
|
70
|
+
* accumulating results from the entire block hierarchy into a single value.
|
|
71
|
+
*
|
|
72
|
+
* @template R - The type of the accumulated result
|
|
73
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to reduce
|
|
74
|
+
* @param fieldType - The type field (determines how the value is processed)
|
|
75
|
+
* @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
|
|
76
|
+
* @param reducer - Asynchronous function that processes each block and updates the accumulator
|
|
77
|
+
* @param initialNonLocalizedFieldValue - The initial value for the accumulator
|
|
78
|
+
* @returns Promise that resolves to the final accumulated value from all blocks in the hierarchy
|
|
79
|
+
*/
|
|
80
|
+
export declare function reduceBlocksInNonLocalizedFieldValue<T, R>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, reducer: (accumulator: R, item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => R | Promise<R>, initialValue: R, path?: TreePath): Promise<R>;
|
|
81
|
+
export declare function reduceBlocksInNonLocalizedFieldValue<R>(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, reducer: (accumulator: R, item: BlockInRequest, path: TreePath) => R | Promise<R>, initialValue: R, path?: TreePath): Promise<R>;
|
|
82
|
+
/**
|
|
83
|
+
* Recursively check if any block in the non-localized field value matches the predicate function.
|
|
84
|
+
* Tests both direct blocks and recursively tests nested blocks within block attributes.
|
|
85
|
+
* Returns true as soon as the first matching block is found anywhere in the hierarchy
|
|
86
|
+
* (short-circuit evaluation).
|
|
87
|
+
*
|
|
88
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
|
|
89
|
+
* @param fieldType - The type field (determines how the value is processed)
|
|
90
|
+
* @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
|
|
91
|
+
* @param predicate - Asynchronous function that tests each block, including nested ones
|
|
92
|
+
* @returns Promise that resolves to true if any block in the hierarchy matches, false otherwise
|
|
93
|
+
*/
|
|
94
|
+
export declare function someBlocksInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<boolean>;
|
|
95
|
+
export declare function someBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: BlockInRequest, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<boolean>;
|
|
96
|
+
/**
|
|
97
|
+
* Recursively check if every block in the non-localized field value matches the predicate function.
|
|
98
|
+
* Tests both direct blocks and recursively tests nested blocks within block attributes.
|
|
99
|
+
* Returns false as soon as the first non-matching block is found anywhere in the hierarchy
|
|
100
|
+
* (short-circuit evaluation).
|
|
101
|
+
*
|
|
102
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to test
|
|
103
|
+
* @param fieldType - The type field (determines how the value is processed)
|
|
104
|
+
* @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
|
|
105
|
+
* @param predicate - Asynchronous function that tests each block, including nested ones
|
|
106
|
+
* @returns Promise that resolves to true if all blocks in the hierarchy match, false otherwise
|
|
107
|
+
*/
|
|
108
|
+
export declare function everyBlockInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<boolean>;
|
|
109
|
+
export declare function everyBlockInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, predicate: (item: BlockInRequest, path: TreePath) => boolean | Promise<boolean>, path?: TreePath): Promise<boolean>;
|
|
110
|
+
type FieldValueInRequest<T> = T extends RichTextFieldValueInNestedResponse<infer D> ? RichTextFieldValueInRequest<D> : T extends SingleBlockFieldValueInNestedResponse<infer D> ? SingleBlockFieldValueInRequest<D> : T extends StructuredTextFieldValueInNestedResponse<infer DB, infer DI> ? StructuredTextFieldValueInRequest<DB, DI> : T extends StructuredTextFieldValueInNestedResponse<infer DB> ? StructuredTextFieldValueInRequest<DB> : T;
|
|
111
|
+
/**
|
|
112
|
+
* Recursively transform blocks in a non-localized field value by applying a mapping function to each block.
|
|
113
|
+
* Creates a new non-localized field value structure with transformed blocks while preserving the original
|
|
114
|
+
* structure. Applies the mapping function to both direct blocks and recursively to nested
|
|
115
|
+
* blocks within block attributes throughout the entire hierarchy.
|
|
116
|
+
*
|
|
117
|
+
* @param nonLocalizedFieldValue - The non-localized field value containing blocks to transform
|
|
118
|
+
* @param fieldType - The type field (determines how the value is processed)
|
|
119
|
+
* @param schemaRepository - Repository for accessing DatoCMS schema information (to resolve block structures)
|
|
120
|
+
* @param mapper - Asynchronous function that transforms each block, including nested ones
|
|
121
|
+
* @param options - Optional configuration object
|
|
122
|
+
* @param options.traversalDirection - Direction of traversal: 'top-down' (default) applies mapper before processing children, 'bottom-up' processes children first
|
|
123
|
+
* @returns Promise that resolves to the new non-localized field value with recursively transformed blocks
|
|
124
|
+
*/
|
|
125
|
+
export declare function mapBlocksInNonLocalizedFieldValue<T extends RecognizableFieldValue>(nonLocalizedFieldValue: T, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, mapper: (item: ExtractNestedBlocksFromFieldValue<T>, path: TreePath) => BlockInRequest | Promise<BlockInRequest>, options?: {
|
|
126
|
+
traversalDirection?: TraversalDirection;
|
|
127
|
+
}, path?: TreePath): Promise<FieldValueInRequest<T>>;
|
|
128
|
+
export declare function mapBlocksInNonLocalizedFieldValue(nonLocalizedFieldValue: unknown, fieldType: ApiTypes.Field['field_type'], schemaRepository: SchemaRepository, mapper: (item: BlockInRequest, path: TreePath) => BlockInRequest | Promise<BlockInRequest>, options?: {
|
|
129
|
+
traversalDirection?: TraversalDirection;
|
|
130
|
+
}, path?: TreePath): Promise<unknown>;
|
|
131
|
+
export {};
|