@sprucelabs/schema 30.1.3 → 31.0.0
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.
|
@@ -94,7 +94,7 @@ class SchemaField extends AbstractField {
|
|
|
94
94
|
: `.${matchedTemplateItem.namePascal}Schema`}`;
|
|
95
95
|
if (renderAs === TemplateRenderAs.Type &&
|
|
96
96
|
idsWithVersion.length > 1) {
|
|
97
|
-
valueType = `{
|
|
97
|
+
valueType = `{ id: '${id}', values: ${valueType} }`;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
unions.push({
|
|
@@ -3,13 +3,21 @@ export default function flattenValues(values, ignoreKeys) {
|
|
|
3
3
|
return flattened;
|
|
4
4
|
}
|
|
5
5
|
function flattenValue(values, prefix = '', ignoreKeys) {
|
|
6
|
+
var _a;
|
|
6
7
|
const keys = Object.keys(values);
|
|
7
8
|
let flattened = {};
|
|
8
9
|
for (const key of keys) {
|
|
9
10
|
const value = values[key];
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const isWildCardIgnored = (_a = ignoreKeys === null || ignoreKeys === void 0 ? void 0 : ignoreKeys.includes(`*.${key}`)) !== null && _a !== void 0 ? _a : false;
|
|
12
|
+
const dotKey = prefix && !isWildCardIgnored ? `${prefix}.${key}` : key;
|
|
13
|
+
if (shouldFlatten(value, ignoreKeys, key)) {
|
|
14
|
+
flattened = {
|
|
15
|
+
...flattened,
|
|
16
|
+
...flattenValue(value, dotKey, ignoreKeys),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
else if (isWildCardIgnored) {
|
|
20
|
+
flattened[prefix] = { ...flattened[prefix], [key]: value };
|
|
13
21
|
}
|
|
14
22
|
else {
|
|
15
23
|
flattened[dotKey] = value;
|
|
@@ -17,3 +25,6 @@ function flattenValue(values, prefix = '', ignoreKeys) {
|
|
|
17
25
|
}
|
|
18
26
|
return flattened;
|
|
19
27
|
}
|
|
28
|
+
function shouldFlatten(value, ignoreKeys, key) {
|
|
29
|
+
return value && typeof value === 'object' && !(ignoreKeys === null || ignoreKeys === void 0 ? void 0 : ignoreKeys.includes(key));
|
|
30
|
+
}
|
|
@@ -99,7 +99,7 @@ class SchemaField extends AbstractField_1.default {
|
|
|
99
99
|
: `.${matchedTemplateItem.namePascal}Schema`}`;
|
|
100
100
|
if (renderAs === template_types_1.TemplateRenderAs.Type &&
|
|
101
101
|
idsWithVersion.length > 1) {
|
|
102
|
-
valueType = `{
|
|
102
|
+
valueType = `{ id: '${id}', values: ${valueType} }`;
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
unions.push({
|
|
@@ -10,9 +10,16 @@ function flattenValue(values, prefix = '', ignoreKeys) {
|
|
|
10
10
|
let flattened = {};
|
|
11
11
|
for (const key of keys) {
|
|
12
12
|
const value = values[key];
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const isWildCardIgnored = ignoreKeys?.includes(`*.${key}`) ?? false;
|
|
14
|
+
const dotKey = prefix && !isWildCardIgnored ? `${prefix}.${key}` : key;
|
|
15
|
+
if (shouldFlatten(value, ignoreKeys, key)) {
|
|
16
|
+
flattened = {
|
|
17
|
+
...flattened,
|
|
18
|
+
...flattenValue(value, dotKey, ignoreKeys),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
else if (isWildCardIgnored) {
|
|
22
|
+
flattened[prefix] = { ...flattened[prefix], [key]: value };
|
|
16
23
|
}
|
|
17
24
|
else {
|
|
18
25
|
flattened[dotKey] = value;
|
|
@@ -20,3 +27,6 @@ function flattenValue(values, prefix = '', ignoreKeys) {
|
|
|
20
27
|
}
|
|
21
28
|
return flattened;
|
|
22
29
|
}
|
|
30
|
+
function shouldFlatten(value, ignoreKeys, key) {
|
|
31
|
+
return value && typeof value === 'object' && !ignoreKeys?.includes(key);
|
|
32
|
+
}
|