@travetto/schema 4.0.1 → 4.0.2
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/package.json +2 -2
- package/src/bind-util.ts +1 -1
- package/src/service/registry.ts +4 -2
- package/src/validate/validator.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/schema",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Data type registry for runtime validation, reflection and binding.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"schema",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"directory": "module/schema"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/registry": "^4.0.
|
|
30
|
+
"@travetto/registry": "^4.0.2"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@travetto/transformer": "^4.0.1"
|
package/src/bind-util.ts
CHANGED
|
@@ -148,7 +148,7 @@ export class BindUtil {
|
|
|
148
148
|
return data;
|
|
149
149
|
}
|
|
150
150
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
151
|
-
const cls = SchemaRegistry.
|
|
151
|
+
const cls = SchemaRegistry.resolveInstanceType<T>(cons, data as T);
|
|
152
152
|
if (data instanceof cls) {
|
|
153
153
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
154
154
|
return data as T;
|
package/src/service/registry.ts
CHANGED
|
@@ -101,11 +101,13 @@ class $SchemaRegistry extends MetadataRegistry<ClassConfig, FieldConfig> {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
|
-
* Find the
|
|
104
|
+
* Find the resolved type for a given instance
|
|
105
105
|
* @param cls Class for instance
|
|
106
106
|
* @param o Actual instance
|
|
107
107
|
*/
|
|
108
|
-
|
|
108
|
+
resolveInstanceType<T>(cls: Class<T>, o: T): Class {
|
|
109
|
+
cls = SchemaRegistry.get(cls.Ⲑid).class; // Resolve by id to handle any stale references
|
|
110
|
+
|
|
109
111
|
const base = this.getBaseSchema(cls);
|
|
110
112
|
const clsSchema = this.get(cls);
|
|
111
113
|
const baseSchema = this.get(base);
|
|
@@ -13,7 +13,7 @@ import { isValidationError, TypeMismatchError, ValidationResultError } from './e
|
|
|
13
13
|
*/
|
|
14
14
|
function resolveSchema<T>(base: Class<T>, o: T, view?: string): SchemaConfig {
|
|
15
15
|
return SchemaRegistry.getViewSchema(
|
|
16
|
-
SchemaRegistry.
|
|
16
|
+
SchemaRegistry.resolveInstanceType(base, o), view
|
|
17
17
|
).schema;
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -272,7 +272,7 @@ export class SchemaValidator {
|
|
|
272
272
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
273
273
|
throw new TypeMismatchError(cls.name, (o as ClassInstance).constructor.name);
|
|
274
274
|
}
|
|
275
|
-
cls = SchemaRegistry.
|
|
275
|
+
cls = SchemaRegistry.resolveInstanceType(cls, o);
|
|
276
276
|
|
|
277
277
|
const config = SchemaRegistry.getViewSchema(cls, view);
|
|
278
278
|
|