Commit 749d9658 authored by nanahira's avatar nanahira

bump to schemastery 3

parent d9106d66
......@@ -29,7 +29,7 @@
"typescript": "^4.5.2"
},
"peerDependencies": {
"schemastery": "^2.4.2"
"schemastery": "^3.0.0"
}
},
"node_modules/@babel/code-frame": {
......@@ -4545,9 +4545,9 @@
}
},
"node_modules/schemastery": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-2.4.2.tgz",
"integrity": "sha512-0sCJuGa7LyAtnoXEVwUKSPSTMfizA0zpK0kX7dzGPLpeLuxgJg7VVyR2KFsfHg+WlqYbUOvoGY7JSNPk5I5uHQ==",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.0.0.tgz",
"integrity": "sha512-0aWxVyVoa5XMxfsFqHdyj2QZCiUgImzcsCEdseALm57JlmBktu92EvTXm1AebD21q/fcSi+M7BGclDQyfMjQzg==",
"peer": true
},
"node_modules/semver": {
......@@ -8711,9 +8711,9 @@
}
},
"schemastery": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-2.4.2.tgz",
"integrity": "sha512-0sCJuGa7LyAtnoXEVwUKSPSTMfizA0zpK0kX7dzGPLpeLuxgJg7VVyR2KFsfHg+WlqYbUOvoGY7JSNPk5I5uHQ==",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.0.0.tgz",
"integrity": "sha512-0aWxVyVoa5XMxfsFqHdyj2QZCiUgImzcsCEdseALm57JlmBktu92EvTXm1AebD21q/fcSi+M7BGclDQyfMjQzg==",
"peer": true
},
"semver": {
......
......@@ -59,6 +59,6 @@
"testEnvironment": "node"
},
"peerDependencies": {
"schemastery": "^2.4.2"
"schemastery": "^3.0.0"
}
}
......@@ -14,19 +14,25 @@ function getBasePropertySchemaFromOptions(options: SchemaOptions) {
if (options.schema) {
return options.schema;
}
switch (options.type as string) {
// eslint-disable-next-line @typescript-eslint/ban-types
switch (options.type as string | Function) {
case 'any':
return Schema.any();
case 'never':
return Schema.never();
case 'string':
case String:
return Schema.string();
case 'number':
case Number:
return Schema.number();
case 'boolean':
case Boolean:
return Schema.boolean();
case 'object':
return Schema.object({}).default({});
case Function:
return Schema.function();
default:
return Schema.from(options.type);
}
......@@ -105,9 +111,9 @@ const schemaFields: (keyof Schema)[] = [
const schemaFunctions: (keyof Schema)[] = [
'toJSON',
'toBSON',
'required',
'hidden',
'adaptive',
'role',
'link',
'default',
......
......@@ -20,7 +20,7 @@ describe('Schema arrays', () => {
class MyConfig {
constructor(_: any) {}
@SchemaProperty({ type: Schema.array(Schema.string()) })
@SchemaProperty({ type: Schema.array(Schema.string()), default: ['dress'] })
foo: string[];
@SchemaProperty({ type: Number })
......@@ -32,10 +32,13 @@ describe('Schema arrays', () => {
@SchemaProperty()
notArray: string;
@SchemaProperty({ type: Schema.tuple([Number, String]) })
@SchemaProperty({ type: Schema.tuple([Schema.number(), Schema.string()]) })
myTup: [number, string];
@SchemaProperty({ type: Schema.tuple([Number, String]), array: true })
@SchemaProperty({
type: Schema.tuple([Schema.number(), Schema.string()]),
array: true,
})
myTupArr: [number, string][];
}
......@@ -51,7 +54,12 @@ describe('Schema arrays', () => {
});
it('should be instance of property', () => {
const config = new MyConfig({ myProperties: [{ name: 'foo' }] });
const config = new MyConfig({
myProperties: [{ name: 'foo' }],
bar: [4],
});
expect(config.myProperties[0].getName()).toEqual('foo');
expect(config.bar[0]).toEqual(4);
expect(config.foo[0]).toEqual('dress');
});
});
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