Commit f953e475 authored by nanahira's avatar nanahira

fix type: Schema problem

parent 5997b78b
......@@ -29,7 +29,7 @@
"typescript": "^4.5.2"
},
"peerDependencies": {
"schemastery": "^3.3.3"
"schemastery": "^3.4.3"
}
},
"node_modules/@babel/code-frame": {
......@@ -4551,9 +4551,9 @@
}
},
"node_modules/schemastery": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.3.3.tgz",
"integrity": "sha512-DwRsse6C+Qao90P/Bz+4G3gmAjM3he/VgHk3TykmEWv3KFqvwmqEn61SF3BPaTPP0L77a5Kc6q4+KQvdN1bBqA==",
"version": "3.4.3",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.4.3.tgz",
"integrity": "sha512-Ui9sPoxOVaKa2EzR6GS08qB/nIMJUczUtkaLfWjeE44kjYZ+GLUFNVE3TpbXRdxjnbIIExwG+paMd0+M7YimqQ==",
"peer": true,
"dependencies": {
"cosmokit": "^1.1.2"
......@@ -8726,9 +8726,9 @@
}
},
"schemastery": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.3.3.tgz",
"integrity": "sha512-DwRsse6C+Qao90P/Bz+4G3gmAjM3he/VgHk3TykmEWv3KFqvwmqEn61SF3BPaTPP0L77a5Kc6q4+KQvdN1bBqA==",
"version": "3.4.3",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.4.3.tgz",
"integrity": "sha512-Ui9sPoxOVaKa2EzR6GS08qB/nIMJUczUtkaLfWjeE44kjYZ+GLUFNVE3TpbXRdxjnbIIExwG+paMd0+M7YimqQ==",
"peer": true,
"requires": {
"cosmokit": "^1.1.2"
......
......@@ -59,6 +59,6 @@
"testEnvironment": "node"
},
"peerDependencies": {
"schemastery": "^3.3.3"
"schemastery": "^3.4.3"
}
}
import {
ClassType,
GeneratedSym,
RefSym,
SchemaOptions,
SchemaReference,
......@@ -40,7 +41,7 @@ export function SchemaProperty(options: SchemaOptions = {}): PropertyDecorator {
if (
options.type &&
typeof options.type !== 'string' &&
((options.type as Schema<any>)[kSchema] || options.type[RefSym])
((options.type as Schema<any>)[GeneratedSym] || options.type[RefSym])
) {
const cl = options.type as ClassType<any>;
let dec: PropertyDecorator;
......@@ -55,7 +56,7 @@ export function SchemaProperty(options: SchemaOptions = {}): PropertyDecorator {
}
dec(obj, key);
}
return Metadata.set('SchemaMeta', options, 'SchemaMetaKey')(obj, key);
Metadata.set('SchemaMeta', options, 'SchemaMetaKey')(obj, key);
};
}
......
import Schema from 'schemastery';
import { RegisterSchema, SchemaProperty } from '../src/decorators';
import { Mixin } from '../src/mixin';
@RegisterSchema()
export class Sleeve {
@SchemaProperty()
@SchemaProperty({ type: Schema.number() })
size: number;
getSleeveSize() {
......
......@@ -9,6 +9,9 @@ describe('Schema registration', () => {
@SchemaProperty({ default: 'bar' })
foo: string;
@SchemaProperty({ default: 'qux', type: Schema.string() })
baz: string;
}
@RegisterSchema()
......@@ -27,6 +30,7 @@ describe('Schema registration', () => {
const schema = Config as Schema<Config>;
expect(schema.type).toBe('object');
expect(schema.dict.foo.type).toBe('string');
expect(schema.dict.baz.type).toBe('string');
});
it('should be serializable', () => {
......@@ -40,7 +44,9 @@ describe('Schema registration', () => {
it('should put default value', () => {
expect(new Config({}).foo).toBe('bar');
expect(new Config({}).baz).toBe('qux');
expect(new Config({ foo: 'baz' }).foo).toBe('baz');
expect(new Config({ baz: 'foo' }).baz).toBe('foo');
});
it('should throw if no default value', () => {
......@@ -59,6 +65,6 @@ describe('Schema registration', () => {
it('should work in toString method', () => {
const schema = Config as Schema<Config>;
expect(schema.toString(true)).toBe('{ foo?: string }');
expect(schema.toString(true)).toBe('{ foo?: string, baz?: string }');
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment