@sinclair/typebox 0.34.34 → 0.34.35
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.
|
@@ -109,10 +109,26 @@ function FromImport(schema, references, value) {
|
|
|
109
109
|
const target = schema.$defs[schema.$ref];
|
|
110
110
|
return Visit(target, [...references, ...definitions], value);
|
|
111
111
|
}
|
|
112
|
+
// ------------------------------------------------------------------
|
|
113
|
+
// Intersect
|
|
114
|
+
// ------------------------------------------------------------------
|
|
115
|
+
function IntersectAssign(correct, value) {
|
|
116
|
+
// trust correct on mismatch | value on non-object
|
|
117
|
+
if (((0, index_1.IsObject)(correct) && !(0, index_1.IsObject)(value)) || (!(0, index_1.IsObject)(correct) && (0, index_1.IsObject)(value)))
|
|
118
|
+
return correct;
|
|
119
|
+
if (!(0, index_1.IsObject)(correct) || !(0, index_1.IsObject)(value))
|
|
120
|
+
return value;
|
|
121
|
+
return globalThis.Object.getOwnPropertyNames(correct).reduce((result, key) => {
|
|
122
|
+
const property = key in value ? IntersectAssign(correct[key], value[key]) : correct[key];
|
|
123
|
+
return { ...result, [key]: property };
|
|
124
|
+
}, {});
|
|
125
|
+
}
|
|
112
126
|
function FromIntersect(schema, references, value) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
127
|
+
if ((0, index_5.Check)(schema, references, value))
|
|
128
|
+
return value;
|
|
129
|
+
const correct = (0, index_4.Create)(schema, references);
|
|
130
|
+
const assigned = IntersectAssign(correct, value);
|
|
131
|
+
return (0, index_5.Check)(schema, references, assigned) ? assigned : correct;
|
|
116
132
|
}
|
|
117
133
|
function FromNever(schema, references, value) {
|
|
118
134
|
throw new ValueCastError(schema, 'Never types cannot be cast');
|
|
@@ -103,10 +103,26 @@ function FromImport(schema, references, value) {
|
|
|
103
103
|
const target = schema.$defs[schema.$ref];
|
|
104
104
|
return Visit(target, [...references, ...definitions], value);
|
|
105
105
|
}
|
|
106
|
+
// ------------------------------------------------------------------
|
|
107
|
+
// Intersect
|
|
108
|
+
// ------------------------------------------------------------------
|
|
109
|
+
function IntersectAssign(correct, value) {
|
|
110
|
+
// trust correct on mismatch | value on non-object
|
|
111
|
+
if ((IsObject(correct) && !IsObject(value)) || (!IsObject(correct) && IsObject(value)))
|
|
112
|
+
return correct;
|
|
113
|
+
if (!IsObject(correct) || !IsObject(value))
|
|
114
|
+
return value;
|
|
115
|
+
return globalThis.Object.getOwnPropertyNames(correct).reduce((result, key) => {
|
|
116
|
+
const property = key in value ? IntersectAssign(correct[key], value[key]) : correct[key];
|
|
117
|
+
return { ...result, [key]: property };
|
|
118
|
+
}, {});
|
|
119
|
+
}
|
|
106
120
|
function FromIntersect(schema, references, value) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
121
|
+
if (Check(schema, references, value))
|
|
122
|
+
return value;
|
|
123
|
+
const correct = Create(schema, references);
|
|
124
|
+
const assigned = IntersectAssign(correct, value);
|
|
125
|
+
return Check(schema, references, assigned) ? assigned : correct;
|
|
110
126
|
}
|
|
111
127
|
function FromNever(schema, references, value) {
|
|
112
128
|
throw new ValueCastError(schema, 'Never types cannot be cast');
|