3.1.17 • Published 2 years ago
schemastery-gen v3.1.17
schemastery-gen
Schemastery 的装饰器定义形式。
Install
npm install schemastery schemastery-gen
Use
The decorator @RegisterSchema
for class is used to register schema from a class. The registered schema is 100% compatible with schemastery.
// Don't forget this decorator.
@RegisterSchema({
description: 'my desc',
})
export class Config {
// add this constructor to make sure the class has one parameter on constructor
constructor(_: any) {
}
@DefineSchema({ type: 'number', required: true })
foo: number;
// Will automatically infer type from class property.
@DefineSchema()
fooAutomated: number;
@DefineSchema({ type: 'string', default: 'shigma' })
bar: string;
@DefineSchema({ type: 'boolean', default: true, hidden: true })
baz: boolean;
// Will infer this property as value, but it cannot infer string type. So you have to specify it manually.
@DefineSchema({ type: 'string', default: ['foo', 'bar'] })
ant: string[];
// You may also specify schema manually.
@DefineSchema({ type: Schema.string() })
dream: string;
// Nested schema.
@DefineSchema({ type: B })
bi: B;
// Type can also be auto-inferred from class property.
@DefineSchema()
biInferred: B;
// Dictionary. Type cannot be auto-inferred.
@DefineSchema({ type: B, dict: true })
biDict: Record<string, B>;
// Combination of dictionary and array. The type cannot be auto-inferred.
@ObjectSchema(B, { dict: true, array: true })
biDictArr: Record<string, B>[];
}
// will resolve this class, just like how Schemastery works.
const config = new Config(myConfigObject);
3.1.17
2 years ago
3.1.16
3 years ago
3.1.14
3 years ago
3.1.15
3 years ago
3.1.12
3 years ago
3.1.11
3 years ago
3.1.13
3 years ago
3.1.10
3 years ago
3.1.9
3 years ago
3.1.8
3 years ago
3.1.7
3 years ago
3.1.6
3 years ago
3.1.5
3 years ago
3.1.3
3 years ago
3.1.4
3 years ago
3.1.2
3 years ago
3.1.1
3 years ago
3.1.0
3 years ago
3.0.0
3 years ago
2.3.0
4 years ago
2.2.0
4 years ago
2.4.1
3 years ago
2.3.2
3 years ago
2.4.0
3 years ago
2.3.1
4 years ago
2.2.5
4 years ago
2.4.2
3 years ago
2.2.4
4 years ago
2.2.6
4 years ago
2.1.0
4 years ago
2.0.2
4 years ago
2.0.1
4 years ago
2.0.0
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago
1.0.3
4 years ago
1.0.2
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago