| field | Description | Example |
|---|---|---|
| Directory | camelCase | |
| File | <scalarName>.constant.ts | |
| Scalar Class | PascalCase | |
| Enum Class | PascalCase | |
| Enum Values | camelCase | |
camelCase
<scalarName>.constant.ts
PascalCase
PascalCase
camelCase
| method | Description |
|---|---|
| via((field) => ({...})) | Creates a class with typed fields. The callback receives the field() helper function. |
| field(Type) | Defines a single field. First argument is the type (String, Number, Date, etc.). |
| field(Type, { options }) | Optional second argument is an options object for defaults, validation, etc. |
Creates a class with typed fields. The callback receives the field() helper function.
Defines a single field. First argument is the type (String, Number, Date, etc.).
Optional second argument is an options object for defaults, validation, etc.
| field | Description |
|---|---|
| enumOf(name, values) | First argument is the enum name (used in dictionary/GraphQL). Second is the value array. |
| camelCase Values | Always use camelCase for enum values (e.g., "waitPay", not "WAIT_PAY"). |
| as const | Add 'as const' to the values array for better TypeScript type inference. |
First argument is the enum name (used in dictionary/GraphQL). Second is the value array.
Always use camelCase for enum values (e.g., "waitPay", not "WAIT_PAY").
Add 'as const' to the values array for better TypeScript type inference.
| Option | Type | Default | Description | Example |
|---|---|---|---|---|
| default | Any | Function | undefined | Default field value (static or factory function) | |
| min | Number | - | Minimum numeric value | |
| max | Number | - | Maximum numeric value | |
| minlength | Number | - | Minimum string length | |
| maxlength | Number | - | Maximum string length | |
| validate | Function | - | Custom validation function | |
| example | Any | - | Example value for documentation | |
Default field value (static or factory function)
Minimum numeric value
Maximum numeric value
Minimum string length
Maximum string length
Custom validation function
Example value for documentation
| Issue | Wrong | Correct |
|---|---|---|
| Enum case | enumOf('status', ['ACTIVE']) | enumOf('status', ['active']) |
| Array syntax | field(Array<Int>) | field([Int]) |
| Dynamic default | { default: dayjs() } | { default: () => dayjs() } |
| Missing export | class Status extends enumOf(...) | export class Status extends enumOf(...) |
| Optional field | field(ID, { nullable: true }) | field(ID).optional() |