@bedrockio/yada 1.10.2 → 1.10.3
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/CHANGELOG.md +6 -0
- package/dist/cjs/object.js +24 -17
- package/package.json +1 -1
- package/src/object.js +28 -20
- package/types/object.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
package/dist/cjs/object.js
CHANGED
|
@@ -63,10 +63,7 @@ class ObjectSchema extends _TypeSchema.default {
|
|
|
63
63
|
let errors = [];
|
|
64
64
|
const result = {};
|
|
65
65
|
for (let key of keys) {
|
|
66
|
-
|
|
67
|
-
if (value === '' && stripEmpty) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
66
|
+
let value = passed[key];
|
|
70
67
|
const schema = getSchema(fields, key, options);
|
|
71
68
|
if (!schema) {
|
|
72
69
|
if (stripUnknown) {
|
|
@@ -81,7 +78,19 @@ class ObjectSchema extends _TypeSchema.default {
|
|
|
81
78
|
continue;
|
|
82
79
|
}
|
|
83
80
|
try {
|
|
84
|
-
|
|
81
|
+
let isBaseObject = false;
|
|
82
|
+
if (allowFlatKeys && value === undefined) {
|
|
83
|
+
// When allowing keys like "profile.name", "profile" must still
|
|
84
|
+
// be validated, but will not exist so expand the passed object
|
|
85
|
+
// and take the base value.
|
|
86
|
+
value = expandFlatSyntax(passed)[key];
|
|
87
|
+
|
|
88
|
+
// If the flat key did not exist but the expanded key did then
|
|
89
|
+
// we have a "base object". If both keys do not exist then the
|
|
90
|
+
// validation result needs to be set as it could be a default.
|
|
91
|
+
isBaseObject = value !== undefined;
|
|
92
|
+
}
|
|
93
|
+
const transformed = await schema.validate(value, {
|
|
85
94
|
...options,
|
|
86
95
|
path: [...path, key],
|
|
87
96
|
required: schema.meta.required,
|
|
@@ -94,18 +103,16 @@ class ObjectSchema extends _TypeSchema.default {
|
|
|
94
103
|
// The original root represents the root object
|
|
95
104
|
// before it was transformed.
|
|
96
105
|
originalRoot: original
|
|
97
|
-
};
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
result[key] = transformed;
|
|
108
|
-
}
|
|
106
|
+
});
|
|
107
|
+
if (transformed === '' && stripEmpty) {
|
|
108
|
+
continue;
|
|
109
|
+
} else if (isBaseObject) {
|
|
110
|
+
// We do not want to return the "profile" object in the
|
|
111
|
+
// result when only flat keys are passed, so continue here.
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (transformed !== undefined) {
|
|
115
|
+
result[key] = transformed;
|
|
109
116
|
}
|
|
110
117
|
} catch (error) {
|
|
111
118
|
const {
|
package/package.json
CHANGED
package/src/object.js
CHANGED
|
@@ -66,11 +66,7 @@ class ObjectSchema extends TypeSchema {
|
|
|
66
66
|
const result = {};
|
|
67
67
|
|
|
68
68
|
for (let key of keys) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (value === '' && stripEmpty) {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
69
|
+
let value = passed[key];
|
|
74
70
|
|
|
75
71
|
const schema = getSchema(fields, key, options);
|
|
76
72
|
|
|
@@ -89,7 +85,21 @@ class ObjectSchema extends TypeSchema {
|
|
|
89
85
|
}
|
|
90
86
|
|
|
91
87
|
try {
|
|
92
|
-
|
|
88
|
+
let isBaseObject = false;
|
|
89
|
+
|
|
90
|
+
if (allowFlatKeys && value === undefined) {
|
|
91
|
+
// When allowing keys like "profile.name", "profile" must still
|
|
92
|
+
// be validated, but will not exist so expand the passed object
|
|
93
|
+
// and take the base value.
|
|
94
|
+
value = expandFlatSyntax(passed)[key];
|
|
95
|
+
|
|
96
|
+
// If the flat key did not exist but the expanded key did then
|
|
97
|
+
// we have a "base object". If both keys do not exist then the
|
|
98
|
+
// validation result needs to be set as it could be a default.
|
|
99
|
+
isBaseObject = value !== undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const transformed = await schema.validate(value, {
|
|
93
103
|
...options,
|
|
94
104
|
|
|
95
105
|
path: [...path, key],
|
|
@@ -105,20 +115,18 @@ class ObjectSchema extends TypeSchema {
|
|
|
105
115
|
// The original root represents the root object
|
|
106
116
|
// before it was transformed.
|
|
107
117
|
originalRoot: original,
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
result[key] = transformed;
|
|
121
|
-
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
if (transformed === '' && stripEmpty) {
|
|
121
|
+
continue;
|
|
122
|
+
} else if (isBaseObject) {
|
|
123
|
+
// We do not want to return the "profile" object in the
|
|
124
|
+
// result when only flat keys are passed, so continue here.
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (transformed !== undefined) {
|
|
129
|
+
result[key] = transformed;
|
|
122
130
|
}
|
|
123
131
|
} catch (error) {
|
|
124
132
|
const { message } = schema.meta;
|
package/types/object.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.js"],"names":[],"mappings":"AAsgBA;;;;;;GAMG;AACH,uCAJW,SAAS,gBAQnB;wBAtgBY;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,EAAE;AAD3C;;GAEG;AAEH;IACE,uBAIC;IAED,sBAOC;IAED,cAiHC;IAED;;;;;;OAMG;IACH,WAFW,MAAM,GAAC,KAAK,CAAC,MAAM,CAAC,OAkB9B;IAED;;;;;;OAMG;IACH,cAFW,MAAM,GAAC,KAAK,CAAC,MAAM,CAAC,OAc9B;IAED;;;;OAIG;IACH,gBAFc,MAAM,EAAA,gBASnB;IAED;;;;OAIG;IACH,gBAFc,MAAM,EAAA,gBASnB;IAED;;;;;;;OAOG;IACH,mBAHc,MAAM,EAAA,gBAuBnB;IAED;;OAEG;IACH,2BAQC;IAED;;;;;;OAMG;IACH,yCAFa,IAAI,CAiBhB;IAED;;;;;;OAMG;IACH,cAEC;IAED;;;;;;;;;OASG;IACH,YAFW,SAAS,GAAC,MAAM,gBA+B1B;IAID;;OAEG;IACH,mBAIC;IAED;;OAEG;IACH,qBAIC;IAED;;OAEG;IACH,sBAIC;IAED;;OAEG;IACH,uBAIC;IAED;;;;;;;;;;;OAWG;IACH,kBALG;QAA0B,UAAU,GAA5B,OAAO;QACW,YAAY,GAA9B,OAAO;QACW,aAAa,GAA/B,OAAO;QACW,cAAc,GAAhC,OAAO;KAA0B,QAI3C;IAID,gCAmBC;CACF;mBA5ZgC,UAAU;uBACpB,cAAc"}
|