3.1.17 • Published 1 year ago

schemastery-gen v3.1.17

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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

1 year ago

3.1.16

2 years ago

3.1.14

2 years ago

3.1.15

2 years ago

3.1.12

2 years ago

3.1.11

2 years ago

3.1.13

2 years ago

3.1.10

2 years ago

3.1.9

2 years ago

3.1.8

2 years ago

3.1.7

2 years ago

3.1.6

2 years ago

3.1.5

2 years ago

3.1.3

2 years ago

3.1.4

2 years ago

3.1.2

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.0

2 years ago

2.3.0

2 years ago

2.2.0

2 years ago

2.4.1

2 years ago

2.3.2

2 years ago

2.4.0

2 years ago

2.3.1

2 years ago

2.2.5

2 years ago

2.4.2

2 years ago

2.2.4

2 years ago

2.2.6

2 years ago

2.1.0

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago