@datocms/cma-client 5.1.14 → 5.1.16
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 +31 -28
- package/dist/cjs/generated/Client.js +1 -1
- package/dist/cjs/utilities/normalizedFieldValues.js +39 -39
- package/dist/cjs/utilities/normalizedFieldValues.js.map +1 -1
- package/dist/cjs/utilities/schemaRepository.js +33 -25
- package/dist/cjs/utilities/schemaRepository.js.map +1 -1
- package/dist/esm/generated/Client.js +1 -1
- package/dist/esm/utilities/normalizedFieldValues.d.ts +25 -25
- package/dist/esm/utilities/normalizedFieldValues.js +39 -39
- package/dist/esm/utilities/normalizedFieldValues.js.map +1 -1
- package/dist/esm/utilities/schemaRepository.d.ts +1 -0
- package/dist/esm/utilities/schemaRepository.js +33 -25
- package/dist/esm/utilities/schemaRepository.js.map +1 -1
- package/dist/types/utilities/normalizedFieldValues.d.ts +25 -25
- package/dist/types/utilities/schemaRepository.d.ts +1 -0
- package/package.json +2 -2
- package/src/generated/Client.ts +1 -1
- package/src/utilities/normalizedFieldValues.ts +60 -39
- package/src/utilities/schemaRepository.ts +41 -30
|
@@ -14,8 +14,8 @@ export type LocalizedFieldValue<T = unknown, L extends string = string> = Partia
|
|
|
14
14
|
* This function handles both full Schema field objects and simplified Schema field objects
|
|
15
15
|
* by checking the appropriate property based on the object structure.
|
|
16
16
|
*
|
|
17
|
-
* @param field - The DatoCMS field definition (either full or simple schema)
|
|
18
17
|
* @returns true if the field is localized, false otherwise
|
|
18
|
+
* @param field - The DatoCMS field definition (either full or simple schema)
|
|
19
19
|
*/
|
|
20
20
|
export declare function isLocalized(field: RawApiTypes.Field | ApiTypes.Field): boolean;
|
|
21
21
|
export declare function isLocalizedFieldValue<T = unknown, L extends string = string>(value: unknown): value is LocalizedFieldValue<T, L>;
|
|
@@ -37,11 +37,11 @@ export type NormalizedFieldValueEntry<T = unknown, L extends string = string> =
|
|
|
37
37
|
* This function normalizes the handling of field values by converting them into a consistent
|
|
38
38
|
* array format, regardless of whether the field is localized or not.
|
|
39
39
|
*
|
|
40
|
-
* @param field - The DatoCMS field definition that determines localization behavior
|
|
41
40
|
* @param value - The field value to convert (either a localized object or direct value)
|
|
41
|
+
* @param field - The DatoCMS field definition that determines localization behavior
|
|
42
42
|
* @returns Array of entries where each entry contains a locale (string for localized, undefined for non-localized) and the corresponding value
|
|
43
43
|
*/
|
|
44
|
-
export declare function toNormalizedFieldValueEntries<T = unknown, L extends string = string>(
|
|
44
|
+
export declare function toNormalizedFieldValueEntries<T = unknown, L extends string = string>(value: T | LocalizedFieldValue<T, L>, field: RawApiTypes.Field | ApiTypes.Field): NormalizedFieldValueEntry<T, L>[];
|
|
45
45
|
/**
|
|
46
46
|
* Converts an array of possibly localized entries back into the appropriate field value format.
|
|
47
47
|
*
|
|
@@ -49,118 +49,118 @@ export declare function toNormalizedFieldValueEntries<T = unknown, L extends str
|
|
|
49
49
|
* array of entries and converts them back to either a localized object or a direct value,
|
|
50
50
|
* depending on the field's localization setting.
|
|
51
51
|
*
|
|
52
|
-
* @param field - The DatoCMS field definition that determines the output format
|
|
53
52
|
* @param entries - Array of entries to convert back to field value format
|
|
53
|
+
* @param field - The DatoCMS field definition that determines the output format
|
|
54
54
|
* @returns Either a localized object (for localized fields) or the direct value (for non-localized fields)
|
|
55
55
|
*/
|
|
56
|
-
export declare function fromNormalizedFieldValueEntries<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field
|
|
56
|
+
export declare function fromNormalizedFieldValueEntries<T = unknown, L extends string = string>(entries: NormalizedFieldValueEntry<T, L>[], field: RawApiTypes.Field | ApiTypes.Field): T | LocalizedFieldValue<T, L>;
|
|
57
57
|
/**
|
|
58
58
|
* Maps field values using a provided mapping function.
|
|
59
59
|
* For localized fields, applies the mapping function to each locale value.
|
|
60
60
|
* For non-localized fields, applies the mapping function directly to the value.
|
|
61
61
|
*
|
|
62
62
|
* @template T - The type that the mapping function returns
|
|
63
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
63
64
|
* @param field - The DatoCMS field definition
|
|
64
|
-
* @param value - The field value (either localized object or direct value)
|
|
65
65
|
* @param mapFn - The function to apply to each locale value or the direct value
|
|
66
66
|
* @returns The mapped value with the same structure as the input
|
|
67
67
|
*/
|
|
68
|
-
export declare function mapNormalizedFieldValues<TInput = unknown, TOutput = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field,
|
|
68
|
+
export declare function mapNormalizedFieldValues<TInput = unknown, TOutput = unknown, L extends string = string>(localizedOrNonLocalizedFieldValue: TInput | LocalizedFieldValue<TInput, L>, field: RawApiTypes.Field | ApiTypes.Field, mapFn: (locale: L | undefined, localeValue: TInput) => TOutput): TOutput | LocalizedFieldValue<TOutput, L>;
|
|
69
69
|
/**
|
|
70
70
|
* Maps field values using a provided mapping function (async version).
|
|
71
71
|
* For localized fields, applies the mapping function to each locale value.
|
|
72
72
|
* For non-localized fields, applies the mapping function directly to the value.
|
|
73
73
|
*
|
|
74
74
|
* @template T - The type that the mapping function returns
|
|
75
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
75
76
|
* @param field - The DatoCMS field definition
|
|
76
|
-
* @param value - The field value (either localized object or direct value)
|
|
77
77
|
* @param mapFn - The function to apply to each locale value or the direct value
|
|
78
78
|
* @returns The mapped value with the same structure as the input
|
|
79
79
|
*/
|
|
80
|
-
export declare function mapNormalizedFieldValuesAsync<TInput = unknown, TOutput = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field,
|
|
80
|
+
export declare function mapNormalizedFieldValuesAsync<TInput = unknown, TOutput = unknown, L extends string = string>(localizedOrNonLocalizedFieldValue: TInput | LocalizedFieldValue<TInput, L>, field: RawApiTypes.Field | ApiTypes.Field, mapFn: (locale: L | undefined, localeValue: TInput) => Promise<TOutput>): Promise<TOutput | LocalizedFieldValue<TOutput, L>>;
|
|
81
81
|
/**
|
|
82
82
|
* Filters field values using a provided filter function.
|
|
83
83
|
* For localized fields, filters each locale value.
|
|
84
84
|
* For non-localized fields, returns the value if the filter passes, otherwise undefined.
|
|
85
85
|
*
|
|
86
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
86
87
|
* @param field - The DatoCMS field definition
|
|
87
|
-
* @param value - The field value (either localized object or direct value)
|
|
88
88
|
* @param filterFn - The function to test each locale value or the direct value
|
|
89
89
|
* @returns The filtered value with the same structure as the input
|
|
90
90
|
*/
|
|
91
|
-
export declare function filterNormalizedFieldValues<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field,
|
|
91
|
+
export declare function filterNormalizedFieldValues<T = unknown, L extends string = string>(localizedOrNonLocalizedFieldValue: T | LocalizedFieldValue<T, L>, field: RawApiTypes.Field | ApiTypes.Field, filterFn: (locale: L | undefined, localeValue: T) => boolean): T | LocalizedFieldValue<T, L> | undefined;
|
|
92
92
|
/**
|
|
93
93
|
* Filters field values using a provided filter function (async version).
|
|
94
94
|
* For localized fields, filters each locale value.
|
|
95
95
|
* For non-localized fields, returns the value if the filter passes, otherwise undefined.
|
|
96
96
|
*
|
|
97
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
97
98
|
* @param field - The DatoCMS field definition
|
|
98
|
-
* @param value - The field value (either localized object or direct value)
|
|
99
99
|
* @param filterFn - The function to test each locale value or the direct value
|
|
100
100
|
* @returns The filtered value with the same structure as the input
|
|
101
101
|
*/
|
|
102
|
-
export declare function filterNormalizedFieldValuesAsync<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field,
|
|
102
|
+
export declare function filterNormalizedFieldValuesAsync<T = unknown, L extends string = string>(localizedOrNonLocalizedFieldValue: T | LocalizedFieldValue<T, L>, field: RawApiTypes.Field | ApiTypes.Field, filterFn: (locale: L | undefined, localeValue: T) => Promise<boolean>): Promise<T | LocalizedFieldValue<T, L> | undefined>;
|
|
103
103
|
/**
|
|
104
104
|
* Tests whether at least one field value passes the test implemented by the provided function.
|
|
105
105
|
* For localized fields, tests each locale value.
|
|
106
106
|
* For non-localized fields, tests the direct value.
|
|
107
107
|
*
|
|
108
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
108
109
|
* @param field - The DatoCMS field definition
|
|
109
|
-
* @param value - The field value (either localized object or direct value)
|
|
110
110
|
* @param testFn - The function to test each locale value or the direct value
|
|
111
111
|
* @returns true if at least one value passes the test, false otherwise
|
|
112
112
|
*/
|
|
113
|
-
export declare function someNormalizedFieldValues<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field,
|
|
113
|
+
export declare function someNormalizedFieldValues<T = unknown, L extends string = string>(localizedOrNonLocalizedFieldValue: T | LocalizedFieldValue<T, L>, field: RawApiTypes.Field | ApiTypes.Field, testFn: (locale: L | undefined, localeValue: T) => boolean): boolean;
|
|
114
114
|
/**
|
|
115
115
|
* Tests whether at least one field value passes the test implemented by the provided function (async version).
|
|
116
116
|
* For localized fields, tests each locale value.
|
|
117
117
|
* For non-localized fields, tests the direct value.
|
|
118
118
|
*
|
|
119
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
119
120
|
* @param field - The DatoCMS field definition
|
|
120
|
-
* @param value - The field value (either localized object or direct value)
|
|
121
121
|
* @param testFn - The function to test each locale value or the direct value
|
|
122
122
|
* @returns true if at least one value passes the test, false otherwise
|
|
123
123
|
*/
|
|
124
|
-
export declare function someNormalizedFieldValuesAsync<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field,
|
|
124
|
+
export declare function someNormalizedFieldValuesAsync<T = unknown, L extends string = string>(localizedOrNonLocalizedFieldValue: T | LocalizedFieldValue<T, L>, field: RawApiTypes.Field | ApiTypes.Field, testFn: (locale: L | undefined, localeValue: T) => Promise<boolean>): Promise<boolean>;
|
|
125
125
|
/**
|
|
126
126
|
* Tests whether all field values pass the test implemented by the provided function.
|
|
127
127
|
* For localized fields, tests each locale value.
|
|
128
128
|
* For non-localized fields, tests the direct value.
|
|
129
129
|
*
|
|
130
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
130
131
|
* @param field - The DatoCMS field definition
|
|
131
|
-
* @param value - The field value (either localized object or direct value)
|
|
132
132
|
* @param testFn - The function to test each locale value or the direct value
|
|
133
133
|
* @returns true if all values pass the test, false otherwise
|
|
134
134
|
*/
|
|
135
|
-
export declare function everyNormalizedFieldValue<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field,
|
|
135
|
+
export declare function everyNormalizedFieldValue<T = unknown, L extends string = string>(localizedOrNonLocalizedFieldValue: T | LocalizedFieldValue<T, L>, field: RawApiTypes.Field | ApiTypes.Field, testFn: (locale: L | undefined, localeValue: T) => boolean): boolean;
|
|
136
136
|
/**
|
|
137
137
|
* Tests whether all field values pass the test implemented by the provided function (async version).
|
|
138
138
|
* For localized fields, tests each locale value.
|
|
139
139
|
* For non-localized fields, tests the direct value.
|
|
140
140
|
*
|
|
141
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
141
142
|
* @param field - The DatoCMS field definition
|
|
142
|
-
* @param value - The field value (either localized object or direct value)
|
|
143
143
|
* @param testFn - The function to test each locale value or the direct value
|
|
144
144
|
* @returns true if all values pass the test, false otherwise
|
|
145
145
|
*/
|
|
146
|
-
export declare function everyNormalizedFieldValueAsync<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field,
|
|
146
|
+
export declare function everyNormalizedFieldValueAsync<T = unknown, L extends string = string>(localizedOrNonLocalizedFieldValue: T | LocalizedFieldValue<T, L>, field: RawApiTypes.Field | ApiTypes.Field, testFn: (locale: L | undefined, localeValue: T) => Promise<boolean>): Promise<boolean>;
|
|
147
147
|
/**
|
|
148
148
|
* Visits each field value with the provided function.
|
|
149
149
|
* For localized fields, visits each locale value.
|
|
150
150
|
* For non-localized fields, visits the direct value.
|
|
151
151
|
*
|
|
152
|
-
* @param field - The DatoCMS field definition
|
|
153
152
|
* @param value - The field value (either localized object or direct value)
|
|
153
|
+
* @param field - The DatoCMS field definition
|
|
154
154
|
* @param visitFn - The function to call for each locale value or the direct value
|
|
155
155
|
*/
|
|
156
|
-
export declare function visitNormalizedFieldValues<T = unknown, L extends string = string>(
|
|
156
|
+
export declare function visitNormalizedFieldValues<T = unknown, L extends string = string>(value: T | LocalizedFieldValue<T, L>, field: RawApiTypes.Field | ApiTypes.Field, visitFn: (locale: L | undefined, localeValue: T) => void): void;
|
|
157
157
|
/**
|
|
158
158
|
* Visits each field value with the provided function (async version).
|
|
159
159
|
* For localized fields, visits each locale value.
|
|
160
160
|
* For non-localized fields, visits the direct value.
|
|
161
161
|
*
|
|
162
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
162
163
|
* @param field - The DatoCMS field definition
|
|
163
|
-
* @param value - The field value (either localized object or direct value)
|
|
164
164
|
* @param visitFn - The function to call for each locale value or the direct value
|
|
165
165
|
*/
|
|
166
|
-
export declare function visitNormalizedFieldValuesAsync<T = unknown, L extends string = string>(field: RawApiTypes.Field | ApiTypes.Field,
|
|
166
|
+
export declare function visitNormalizedFieldValuesAsync<T = unknown, L extends string = string>(localizedOrNonLocalizedFieldValue: T | LocalizedFieldValue<T, L>, field: RawApiTypes.Field | ApiTypes.Field, visitFn: (locale: L | undefined, localeValue: T) => Promise<void>): Promise<void>;
|
|
@@ -13,8 +13,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
13
13
|
* This function handles both full Schema field objects and simplified Schema field objects
|
|
14
14
|
* by checking the appropriate property based on the object structure.
|
|
15
15
|
*
|
|
16
|
-
* @param field - The DatoCMS field definition (either full or simple schema)
|
|
17
16
|
* @returns true if the field is localized, false otherwise
|
|
17
|
+
* @param field - The DatoCMS field definition (either full or simple schema)
|
|
18
18
|
*/
|
|
19
19
|
export function isLocalized(field) {
|
|
20
20
|
return 'attributes' in field ? field.attributes.localized : field.localized;
|
|
@@ -36,11 +36,11 @@ export function isLocalizedFieldValue(value) {
|
|
|
36
36
|
* This function normalizes the handling of field values by converting them into a consistent
|
|
37
37
|
* array format, regardless of whether the field is localized or not.
|
|
38
38
|
*
|
|
39
|
-
* @param field - The DatoCMS field definition that determines localization behavior
|
|
40
39
|
* @param value - The field value to convert (either a localized object or direct value)
|
|
40
|
+
* @param field - The DatoCMS field definition that determines localization behavior
|
|
41
41
|
* @returns Array of entries where each entry contains a locale (string for localized, undefined for non-localized) and the corresponding value
|
|
42
42
|
*/
|
|
43
|
-
export function toNormalizedFieldValueEntries(
|
|
43
|
+
export function toNormalizedFieldValueEntries(value, field) {
|
|
44
44
|
if (isLocalized(field)) {
|
|
45
45
|
const localizedValue = value;
|
|
46
46
|
return Object.entries(localizedValue).map(([locale, value]) => ({
|
|
@@ -57,11 +57,11 @@ export function toNormalizedFieldValueEntries(field, value) {
|
|
|
57
57
|
* array of entries and converts them back to either a localized object or a direct value,
|
|
58
58
|
* depending on the field's localization setting.
|
|
59
59
|
*
|
|
60
|
-
* @param field - The DatoCMS field definition that determines the output format
|
|
61
60
|
* @param entries - Array of entries to convert back to field value format
|
|
61
|
+
* @param field - The DatoCMS field definition that determines the output format
|
|
62
62
|
* @returns Either a localized object (for localized fields) or the direct value (for non-localized fields)
|
|
63
63
|
*/
|
|
64
|
-
export function fromNormalizedFieldValueEntries(
|
|
64
|
+
export function fromNormalizedFieldValueEntries(entries, field) {
|
|
65
65
|
if (isLocalized(field)) {
|
|
66
66
|
return Object.fromEntries(entries.map(({ locale, value }) => [locale, value]));
|
|
67
67
|
}
|
|
@@ -76,18 +76,18 @@ export function fromNormalizedFieldValueEntries(field, entries) {
|
|
|
76
76
|
* For non-localized fields, applies the mapping function directly to the value.
|
|
77
77
|
*
|
|
78
78
|
* @template T - The type that the mapping function returns
|
|
79
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
79
80
|
* @param field - The DatoCMS field definition
|
|
80
|
-
* @param value - The field value (either localized object or direct value)
|
|
81
81
|
* @param mapFn - The function to apply to each locale value or the direct value
|
|
82
82
|
* @returns The mapped value with the same structure as the input
|
|
83
83
|
*/
|
|
84
|
-
export function mapNormalizedFieldValues(
|
|
85
|
-
const entries = toNormalizedFieldValueEntries(
|
|
84
|
+
export function mapNormalizedFieldValues(localizedOrNonLocalizedFieldValue, field, mapFn) {
|
|
85
|
+
const entries = toNormalizedFieldValueEntries(localizedOrNonLocalizedFieldValue, field);
|
|
86
86
|
const mappedEntries = entries.map(({ locale, value }) => ({
|
|
87
87
|
locale,
|
|
88
88
|
value: mapFn(locale, value),
|
|
89
89
|
}));
|
|
90
|
-
return fromNormalizedFieldValueEntries(
|
|
90
|
+
return fromNormalizedFieldValueEntries(mappedEntries, field);
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
93
93
|
* Maps field values using a provided mapping function (async version).
|
|
@@ -95,21 +95,21 @@ export function mapNormalizedFieldValues(field, value, mapFn) {
|
|
|
95
95
|
* For non-localized fields, applies the mapping function directly to the value.
|
|
96
96
|
*
|
|
97
97
|
* @template T - The type that the mapping function returns
|
|
98
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
98
99
|
* @param field - The DatoCMS field definition
|
|
99
|
-
* @param value - The field value (either localized object or direct value)
|
|
100
100
|
* @param mapFn - The function to apply to each locale value or the direct value
|
|
101
101
|
* @returns The mapped value with the same structure as the input
|
|
102
102
|
*/
|
|
103
|
-
export function mapNormalizedFieldValuesAsync(
|
|
103
|
+
export function mapNormalizedFieldValuesAsync(localizedOrNonLocalizedFieldValue, field, mapFn) {
|
|
104
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
const entries = toNormalizedFieldValueEntries(
|
|
105
|
+
const entries = toNormalizedFieldValueEntries(localizedOrNonLocalizedFieldValue, field);
|
|
106
106
|
const mappedEntries = yield Promise.all(entries.map(({ locale, value }) => __awaiter(this, void 0, void 0, function* () {
|
|
107
107
|
return ({
|
|
108
108
|
locale,
|
|
109
109
|
value: yield mapFn(locale, value),
|
|
110
110
|
});
|
|
111
111
|
})));
|
|
112
|
-
return fromNormalizedFieldValueEntries(
|
|
112
|
+
return fromNormalizedFieldValueEntries(mappedEntries, field);
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
/**
|
|
@@ -117,17 +117,17 @@ export function mapNormalizedFieldValuesAsync(field, value, mapFn) {
|
|
|
117
117
|
* For localized fields, filters each locale value.
|
|
118
118
|
* For non-localized fields, returns the value if the filter passes, otherwise undefined.
|
|
119
119
|
*
|
|
120
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
120
121
|
* @param field - The DatoCMS field definition
|
|
121
|
-
* @param value - The field value (either localized object or direct value)
|
|
122
122
|
* @param filterFn - The function to test each locale value or the direct value
|
|
123
123
|
* @returns The filtered value with the same structure as the input
|
|
124
124
|
*/
|
|
125
|
-
export function filterNormalizedFieldValues(
|
|
125
|
+
export function filterNormalizedFieldValues(localizedOrNonLocalizedFieldValue, field, filterFn) {
|
|
126
126
|
var _a;
|
|
127
|
-
const entries = toNormalizedFieldValueEntries(
|
|
127
|
+
const entries = toNormalizedFieldValueEntries(localizedOrNonLocalizedFieldValue, field);
|
|
128
128
|
const filteredEntries = entries.filter((entry) => filterFn(entry.locale, entry.value));
|
|
129
129
|
if (isLocalized(field)) {
|
|
130
|
-
return fromNormalizedFieldValueEntries(
|
|
130
|
+
return fromNormalizedFieldValueEntries(filteredEntries, field);
|
|
131
131
|
}
|
|
132
132
|
return filteredEntries.length > 0 ? (_a = filteredEntries[0]) === null || _a === void 0 ? void 0 : _a.value : undefined;
|
|
133
133
|
}
|
|
@@ -136,15 +136,15 @@ export function filterNormalizedFieldValues(field, value, filterFn) {
|
|
|
136
136
|
* For localized fields, filters each locale value.
|
|
137
137
|
* For non-localized fields, returns the value if the filter passes, otherwise undefined.
|
|
138
138
|
*
|
|
139
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
139
140
|
* @param field - The DatoCMS field definition
|
|
140
|
-
* @param value - The field value (either localized object or direct value)
|
|
141
141
|
* @param filterFn - The function to test each locale value or the direct value
|
|
142
142
|
* @returns The filtered value with the same structure as the input
|
|
143
143
|
*/
|
|
144
|
-
export function filterNormalizedFieldValuesAsync(
|
|
144
|
+
export function filterNormalizedFieldValuesAsync(localizedOrNonLocalizedFieldValue, field, filterFn) {
|
|
145
145
|
var _a;
|
|
146
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
const entries = toNormalizedFieldValueEntries(
|
|
147
|
+
const entries = toNormalizedFieldValueEntries(localizedOrNonLocalizedFieldValue, field);
|
|
148
148
|
const results = yield Promise.all(entries.map(({ locale, value }) => __awaiter(this, void 0, void 0, function* () {
|
|
149
149
|
return ({
|
|
150
150
|
locale,
|
|
@@ -156,7 +156,7 @@ export function filterNormalizedFieldValuesAsync(field, value, filterFn) {
|
|
|
156
156
|
.filter(({ passed }) => passed)
|
|
157
157
|
.map(({ locale, value }) => ({ locale, value }));
|
|
158
158
|
if (isLocalized(field)) {
|
|
159
|
-
return fromNormalizedFieldValueEntries(
|
|
159
|
+
return fromNormalizedFieldValueEntries(filteredEntries, field);
|
|
160
160
|
}
|
|
161
161
|
return filteredEntries.length > 0 ? (_a = filteredEntries[0]) === null || _a === void 0 ? void 0 : _a.value : undefined;
|
|
162
162
|
});
|
|
@@ -166,13 +166,13 @@ export function filterNormalizedFieldValuesAsync(field, value, filterFn) {
|
|
|
166
166
|
* For localized fields, tests each locale value.
|
|
167
167
|
* For non-localized fields, tests the direct value.
|
|
168
168
|
*
|
|
169
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
169
170
|
* @param field - The DatoCMS field definition
|
|
170
|
-
* @param value - The field value (either localized object or direct value)
|
|
171
171
|
* @param testFn - The function to test each locale value or the direct value
|
|
172
172
|
* @returns true if at least one value passes the test, false otherwise
|
|
173
173
|
*/
|
|
174
|
-
export function someNormalizedFieldValues(
|
|
175
|
-
const entries = toNormalizedFieldValueEntries(
|
|
174
|
+
export function someNormalizedFieldValues(localizedOrNonLocalizedFieldValue, field, testFn) {
|
|
175
|
+
const entries = toNormalizedFieldValueEntries(localizedOrNonLocalizedFieldValue, field);
|
|
176
176
|
return entries.some(({ locale, value }) => testFn(locale, value));
|
|
177
177
|
}
|
|
178
178
|
/**
|
|
@@ -180,14 +180,14 @@ export function someNormalizedFieldValues(field, value, testFn) {
|
|
|
180
180
|
* For localized fields, tests each locale value.
|
|
181
181
|
* For non-localized fields, tests the direct value.
|
|
182
182
|
*
|
|
183
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
183
184
|
* @param field - The DatoCMS field definition
|
|
184
|
-
* @param value - The field value (either localized object or direct value)
|
|
185
185
|
* @param testFn - The function to test each locale value or the direct value
|
|
186
186
|
* @returns true if at least one value passes the test, false otherwise
|
|
187
187
|
*/
|
|
188
|
-
export function someNormalizedFieldValuesAsync(
|
|
188
|
+
export function someNormalizedFieldValuesAsync(localizedOrNonLocalizedFieldValue, field, testFn) {
|
|
189
189
|
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
-
const entries = toNormalizedFieldValueEntries(
|
|
190
|
+
const entries = toNormalizedFieldValueEntries(localizedOrNonLocalizedFieldValue, field);
|
|
191
191
|
const results = yield Promise.all(entries.map(({ locale, value }) => testFn(locale, value)));
|
|
192
192
|
return results.some((result) => result);
|
|
193
193
|
});
|
|
@@ -197,27 +197,27 @@ export function someNormalizedFieldValuesAsync(field, value, testFn) {
|
|
|
197
197
|
* For localized fields, tests each locale value.
|
|
198
198
|
* For non-localized fields, tests the direct value.
|
|
199
199
|
*
|
|
200
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
200
201
|
* @param field - The DatoCMS field definition
|
|
201
|
-
* @param value - The field value (either localized object or direct value)
|
|
202
202
|
* @param testFn - The function to test each locale value or the direct value
|
|
203
203
|
* @returns true if all values pass the test, false otherwise
|
|
204
204
|
*/
|
|
205
|
-
export function everyNormalizedFieldValue(
|
|
206
|
-
return !someNormalizedFieldValues(
|
|
205
|
+
export function everyNormalizedFieldValue(localizedOrNonLocalizedFieldValue, field, testFn) {
|
|
206
|
+
return !someNormalizedFieldValues(localizedOrNonLocalizedFieldValue, field, (locale, localeValue) => !testFn(locale, localeValue));
|
|
207
207
|
}
|
|
208
208
|
/**
|
|
209
209
|
* Tests whether all field values pass the test implemented by the provided function (async version).
|
|
210
210
|
* For localized fields, tests each locale value.
|
|
211
211
|
* For non-localized fields, tests the direct value.
|
|
212
212
|
*
|
|
213
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
213
214
|
* @param field - The DatoCMS field definition
|
|
214
|
-
* @param value - The field value (either localized object or direct value)
|
|
215
215
|
* @param testFn - The function to test each locale value or the direct value
|
|
216
216
|
* @returns true if all values pass the test, false otherwise
|
|
217
217
|
*/
|
|
218
|
-
export function everyNormalizedFieldValueAsync(
|
|
218
|
+
export function everyNormalizedFieldValueAsync(localizedOrNonLocalizedFieldValue, field, testFn) {
|
|
219
219
|
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
-
return !(yield someNormalizedFieldValuesAsync(
|
|
220
|
+
return !(yield someNormalizedFieldValuesAsync(localizedOrNonLocalizedFieldValue, field, (locale, localeValue) => __awaiter(this, void 0, void 0, function* () { return !(yield testFn(locale, localeValue)); })));
|
|
221
221
|
});
|
|
222
222
|
}
|
|
223
223
|
/**
|
|
@@ -225,12 +225,12 @@ export function everyNormalizedFieldValueAsync(field, value, testFn) {
|
|
|
225
225
|
* For localized fields, visits each locale value.
|
|
226
226
|
* For non-localized fields, visits the direct value.
|
|
227
227
|
*
|
|
228
|
-
* @param field - The DatoCMS field definition
|
|
229
228
|
* @param value - The field value (either localized object or direct value)
|
|
229
|
+
* @param field - The DatoCMS field definition
|
|
230
230
|
* @param visitFn - The function to call for each locale value or the direct value
|
|
231
231
|
*/
|
|
232
|
-
export function visitNormalizedFieldValues(
|
|
233
|
-
const entries = toNormalizedFieldValueEntries(
|
|
232
|
+
export function visitNormalizedFieldValues(value, field, visitFn) {
|
|
233
|
+
const entries = toNormalizedFieldValueEntries(value, field);
|
|
234
234
|
for (const { locale, value } of entries) {
|
|
235
235
|
visitFn(locale, value);
|
|
236
236
|
}
|
|
@@ -240,13 +240,13 @@ export function visitNormalizedFieldValues(field, value, visitFn) {
|
|
|
240
240
|
* For localized fields, visits each locale value.
|
|
241
241
|
* For non-localized fields, visits the direct value.
|
|
242
242
|
*
|
|
243
|
+
* @param localizedOrNonLocalizedFieldValue - The field value (either localized object or direct value)
|
|
243
244
|
* @param field - The DatoCMS field definition
|
|
244
|
-
* @param value - The field value (either localized object or direct value)
|
|
245
245
|
* @param visitFn - The function to call for each locale value or the direct value
|
|
246
246
|
*/
|
|
247
|
-
export function visitNormalizedFieldValuesAsync(
|
|
247
|
+
export function visitNormalizedFieldValuesAsync(localizedOrNonLocalizedFieldValue, field, visitFn) {
|
|
248
248
|
return __awaiter(this, void 0, void 0, function* () {
|
|
249
|
-
const entries = toNormalizedFieldValueEntries(
|
|
249
|
+
const entries = toNormalizedFieldValueEntries(localizedOrNonLocalizedFieldValue, field);
|
|
250
250
|
yield Promise.all(entries.map(({ locale, value }) => visitFn(locale, value)));
|
|
251
251
|
});
|
|
252
252
|
}
|
|
@@ -1 +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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C;KACxB;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAgB,+BAA+B,CAInD,iCAAgE,EAChE,KAAyC,EACzC,OAAiE;;QAEjE,MAAM,OAAO,GAAG,6BAA6B,CAC3C,iCAAiC,EACjC,KAAK,CACN,CAAC;QACF,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"}
|
|
@@ -111,6 +111,7 @@ export declare class SchemaRepository {
|
|
|
111
111
|
private pluginsPromise;
|
|
112
112
|
private pluginsById;
|
|
113
113
|
private pluginsByPackageName;
|
|
114
|
+
private prefetchPromise;
|
|
114
115
|
/**
|
|
115
116
|
* Creates a new SchemaRepository instance.
|
|
116
117
|
* @param client - The DatoCMS client instance
|
|
@@ -91,6 +91,7 @@ export class SchemaRepository {
|
|
|
91
91
|
this.pluginsPromise = null;
|
|
92
92
|
this.pluginsById = new Map();
|
|
93
93
|
this.pluginsByPackageName = new Map();
|
|
94
|
+
this.prefetchPromise = null;
|
|
94
95
|
this.client = client;
|
|
95
96
|
}
|
|
96
97
|
/**
|
|
@@ -424,33 +425,40 @@ export class SchemaRepository {
|
|
|
424
425
|
*/
|
|
425
426
|
prefetchAllModelsAndFields() {
|
|
426
427
|
return __awaiter(this, void 0, void 0, function* () {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
});
|
|
430
|
-
if (!included) {
|
|
431
|
-
throw new Error('This should not happen');
|
|
432
|
-
}
|
|
433
|
-
const allItemTypes = included.filter((item) => item.type === 'item_type');
|
|
434
|
-
const allFields = included.filter((item) => item.type === 'field');
|
|
435
|
-
// Populate item types caches
|
|
436
|
-
this.itemTypesPromise = Promise.resolve(allItemTypes);
|
|
437
|
-
for (const itemType of allItemTypes) {
|
|
438
|
-
this.itemTypesByApiKey.set(itemType.attributes.api_key, itemType);
|
|
439
|
-
this.itemTypesById.set(itemType.id, itemType);
|
|
428
|
+
if (this.prefetchPromise) {
|
|
429
|
+
return this.prefetchPromise;
|
|
440
430
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
if (!
|
|
446
|
-
|
|
431
|
+
const prefetch = () => __awaiter(this, void 0, void 0, function* () {
|
|
432
|
+
const { included } = yield this.client.site.rawFind({
|
|
433
|
+
include: 'item_types,item_types.fields',
|
|
434
|
+
});
|
|
435
|
+
if (!included) {
|
|
436
|
+
throw new Error('This should not happen');
|
|
447
437
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
438
|
+
const allItemTypes = included.filter((item) => item.type === 'item_type');
|
|
439
|
+
const allFields = included.filter((item) => item.type === 'field');
|
|
440
|
+
// Populate item types caches
|
|
441
|
+
this.itemTypesPromise = Promise.resolve(allItemTypes);
|
|
442
|
+
for (const itemType of allItemTypes) {
|
|
443
|
+
this.itemTypesByApiKey.set(itemType.attributes.api_key, itemType);
|
|
444
|
+
this.itemTypesById.set(itemType.id, itemType);
|
|
445
|
+
}
|
|
446
|
+
// Group fields by item type and populate fields cache
|
|
447
|
+
const fieldsByItemTypeId = new Map();
|
|
448
|
+
for (const field of allFields) {
|
|
449
|
+
const itemTypeId = field.relationships.item_type.data.id;
|
|
450
|
+
if (!fieldsByItemTypeId.has(itemTypeId)) {
|
|
451
|
+
fieldsByItemTypeId.set(itemTypeId, []);
|
|
452
|
+
}
|
|
453
|
+
fieldsByItemTypeId.get(itemTypeId).push(field);
|
|
454
|
+
}
|
|
455
|
+
// Populate the fields cache
|
|
456
|
+
for (const [itemTypeId, fields] of fieldsByItemTypeId) {
|
|
457
|
+
this.fieldsByItemType.set(itemTypeId, fields);
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
this.prefetchPromise = prefetch();
|
|
461
|
+
return this.prefetchPromise;
|
|
454
462
|
});
|
|
455
463
|
}
|
|
456
464
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaRepository.js","sourceRoot":"","sources":["../../../src/utilities/schemaRepository.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAGrE,OAAO,EAAE,8BAA8B,EAAE,MAAM,8BAA8B,CAAC;AAwB9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,MAAM,OAAO,gBAAgB;
|
|
1
|
+
{"version":3,"file":"schemaRepository.js","sourceRoot":"","sources":["../../../src/utilities/schemaRepository.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAGrE,OAAO,EAAE,8BAA8B,EAAE,MAAM,8BAA8B,CAAC;AAwB9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,MAAM,OAAO,gBAAgB;IAY3B;;;OAGG;IACH,YAAY,MAAqB;QAdzB,qBAAgB,GAA2C,IAAI,CAAC;QAChE,sBAAiB,GAAsC,IAAI,GAAG,EAAE,CAAC;QACjE,kBAAa,GAAsC,IAAI,GAAG,EAAE,CAAC;QAC7D,qBAAgB,GAAqC,IAAI,GAAG,EAAE,CAAC;QAC/D,wBAAmB,GAAwC,IAAI,GAAG,EAAE,CAAC;QACrE,mBAAc,GAAyC,IAAI,CAAC;QAC5D,gBAAW,GAAoC,IAAI,GAAG,EAAE,CAAC;QACzD,yBAAoB,GAAoC,IAAI,GAAG,EAAE,CAAC;QAClE,oBAAe,GAAyB,IAAI,CAAC;QAOnD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACW,aAAa;;YACzB,IAAI,CAAC,IA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