Commit f953e475 authored by nanahira's avatar nanahira

fix type: Schema problem

parent 5997b78b
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
"typescript": "^4.5.2" "typescript": "^4.5.2"
}, },
"peerDependencies": { "peerDependencies": {
"schemastery": "^3.3.3" "schemastery": "^3.4.3"
} }
}, },
"node_modules/@babel/code-frame": { "node_modules/@babel/code-frame": {
...@@ -4551,9 +4551,9 @@ ...@@ -4551,9 +4551,9 @@
} }
}, },
"node_modules/schemastery": { "node_modules/schemastery": {
"version": "3.3.3", "version": "3.4.3",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.3.3.tgz", "resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.4.3.tgz",
"integrity": "sha512-DwRsse6C+Qao90P/Bz+4G3gmAjM3he/VgHk3TykmEWv3KFqvwmqEn61SF3BPaTPP0L77a5Kc6q4+KQvdN1bBqA==", "integrity": "sha512-Ui9sPoxOVaKa2EzR6GS08qB/nIMJUczUtkaLfWjeE44kjYZ+GLUFNVE3TpbXRdxjnbIIExwG+paMd0+M7YimqQ==",
"peer": true, "peer": true,
"dependencies": { "dependencies": {
"cosmokit": "^1.1.2" "cosmokit": "^1.1.2"
...@@ -8726,9 +8726,9 @@ ...@@ -8726,9 +8726,9 @@
} }
}, },
"schemastery": { "schemastery": {
"version": "3.3.3", "version": "3.4.3",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.3.3.tgz", "resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.4.3.tgz",
"integrity": "sha512-DwRsse6C+Qao90P/Bz+4G3gmAjM3he/VgHk3TykmEWv3KFqvwmqEn61SF3BPaTPP0L77a5Kc6q4+KQvdN1bBqA==", "integrity": "sha512-Ui9sPoxOVaKa2EzR6GS08qB/nIMJUczUtkaLfWjeE44kjYZ+GLUFNVE3TpbXRdxjnbIIExwG+paMd0+M7YimqQ==",
"peer": true, "peer": true,
"requires": { "requires": {
"cosmokit": "^1.1.2" "cosmokit": "^1.1.2"
......
...@@ -59,6 +59,6 @@ ...@@ -59,6 +59,6 @@
"testEnvironment": "node" "testEnvironment": "node"
}, },
"peerDependencies": { "peerDependencies": {
"schemastery": "^3.3.3" "schemastery": "^3.4.3"
} }
} }
import { import {
ClassType, ClassType,
GeneratedSym,
RefSym, RefSym,
SchemaOptions, SchemaOptions,
SchemaReference, SchemaReference,
...@@ -40,7 +41,7 @@ export function SchemaProperty(options: SchemaOptions = {}): PropertyDecorator { ...@@ -40,7 +41,7 @@ export function SchemaProperty(options: SchemaOptions = {}): PropertyDecorator {
if ( if (
options.type && options.type &&
typeof options.type !== 'string' && 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>; const cl = options.type as ClassType<any>;
let dec: PropertyDecorator; let dec: PropertyDecorator;
...@@ -55,7 +56,7 @@ export function SchemaProperty(options: SchemaOptions = {}): PropertyDecorator { ...@@ -55,7 +56,7 @@ export function SchemaProperty(options: SchemaOptions = {}): PropertyDecorator {
} }
dec(obj, key); 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 { RegisterSchema, SchemaProperty } from '../src/decorators';
import { Mixin } from '../src/mixin'; import { Mixin } from '../src/mixin';
@RegisterSchema() @RegisterSchema()
export class Sleeve { export class Sleeve {
@SchemaProperty() @SchemaProperty({ type: Schema.number() })
size: number; size: number;
getSleeveSize() { getSleeveSize() {
......
...@@ -9,6 +9,9 @@ describe('Schema registration', () => { ...@@ -9,6 +9,9 @@ describe('Schema registration', () => {
@SchemaProperty({ default: 'bar' }) @SchemaProperty({ default: 'bar' })
foo: string; foo: string;
@SchemaProperty({ default: 'qux', type: Schema.string() })
baz: string;
} }
@RegisterSchema() @RegisterSchema()
...@@ -27,6 +30,7 @@ describe('Schema registration', () => { ...@@ -27,6 +30,7 @@ describe('Schema registration', () => {
const schema = Config as Schema<Config>; const schema = Config as Schema<Config>;
expect(schema.type).toBe('object'); expect(schema.type).toBe('object');
expect(schema.dict.foo.type).toBe('string'); expect(schema.dict.foo.type).toBe('string');
expect(schema.dict.baz.type).toBe('string');
}); });
it('should be serializable', () => { it('should be serializable', () => {
...@@ -40,7 +44,9 @@ describe('Schema registration', () => { ...@@ -40,7 +44,9 @@ describe('Schema registration', () => {
it('should put default value', () => { it('should put default value', () => {
expect(new Config({}).foo).toBe('bar'); expect(new Config({}).foo).toBe('bar');
expect(new Config({}).baz).toBe('qux');
expect(new Config({ foo: 'baz' }).foo).toBe('baz'); expect(new Config({ foo: 'baz' }).foo).toBe('baz');
expect(new Config({ baz: 'foo' }).baz).toBe('foo');
}); });
it('should throw if no default value', () => { it('should throw if no default value', () => {
...@@ -59,6 +65,6 @@ describe('Schema registration', () => { ...@@ -59,6 +65,6 @@ describe('Schema registration', () => {
it('should work in toString method', () => { it('should work in toString method', () => {
const schema = Config as Schema<Config>; 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