Commit 749d9658 authored by nanahira's avatar nanahira

bump to schemastery 3

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