| field | Description |
|---|---|
| *.constant.ts | Defines the scalar schema using via() function and enums using enumOf(). This is where you declare fields, types, defaults, and validation rules. |
| *.dictionary.ts | Provides internationalization using scalarDictionary() builder pattern. Defines translations for model name, field labels, descriptions, and enum values. |
| *.document.ts | Optional file that extends functionality using by() function. Add custom methods for data transformations and computed values. |
Defines the scalar schema using via() function and enums using enumOf(). This is where you declare fields, types, defaults, and validation rules.
Provides internationalization using scalarDictionary() builder pattern. Defines translations for model name, field labels, descriptions, and enum values.
Optional file that extends functionality using by() function. Add custom methods for data transformations and computed values.
| field | Description |
|---|---|
| enumOf(name, values) | Creates a typed enum class. The first argument is the enum name (used in dictionary), the second is an array of values with "as const" for type safety. |
| via((field) => ({...})) | Creates a scalar class with typed fields. The field() function accepts a type and optional configuration for defaults, validation, and more. |
| Field Options | Options include: default (static or function), min/max (for numbers), minlength/maxlength (for strings), validate (custom validator function). |
Creates a typed enum class. The first argument is the enum name (used in dictionary), the second is an array of values with "as const" for type safety.
Creates a scalar class with typed fields. The field() function accepts a type and optional configuration for defaults, validation, and more.
Options include: default (static or function), min/max (for numbers), minlength/maxlength (for strings), validate (custom validator function).
| field | Description |
|---|---|
| scalarDictionary([languages]) | Initialize with supported languages array. The order determines which index corresponds to which language in translation arrays. |
| .of((t) => ...) | Define the scalar's own name and description. Use t([en, ko]) for the label and .desc([en, ko]) for the description. |
| .model<Type>((t) => ({...})) | Define translations for each field. The generic type ensures all fields are covered. Each field has a label and description. |
| .enum<Type>(name, (t) => ({...})) | Define translations for enum values. The first argument is the enum name (matching enumOf()), the second defines translations for each value. |
Initialize with supported languages array. The order determines which index corresponds to which language in translation arrays.
Define the scalar's own name and description. Use t([en, ko]) for the label and .desc([en, ko]) for the description.
Define translations for each field. The generic type ensures all fields are covered. Each field has a label and description.
Define translations for enum values. The first argument is the enum name (matching enumOf()), the second defines translations for each value.
| field | Description |
|---|---|
| by(cnst.ClassName) | Wraps the constant class and enables adding methods. Import the constant as cnst to avoid naming conflicts. |
| Custom Methods | Add computed properties, validation helpers, and transformation methods directly in the class body. |
| Access Fields | Use 'this' to access all fields defined in the constant file. TypeScript provides full autocompletion. |
Wraps the constant class and enables adding methods. Import the constant as cnst to avoid naming conflicts.
Add computed properties, validation helpers, and transformation methods directly in the class body.
Use 'this' to access all fields defined in the constant file. TypeScript provides full autocompletion.
| field | Description |
|---|---|
| Scalar Directory | camelCase (e.g., encourageInfo) |
| Constant File | [name].constant.ts (e.g., encourageInfo.constant.ts) |
| Dictionary File | [name].dictionary.ts (e.g., encourageInfo.dictionary.ts) |
| Document File | [name].document.ts (e.g., encourageInfo.document.ts) |
| Scalar Class | PascalCase (e.g., EncourageInfo) |
| Enum Class | PascalCase (e.g., Journey, LinkType) |
| Enum Values | camelCase (e.g., firstJoin, waitPay) |
camelCase (e.g., encourageInfo)
[name].constant.ts (e.g., encourageInfo.constant.ts)
[name].dictionary.ts (e.g., encourageInfo.dictionary.ts)
[name].document.ts (e.g., encourageInfo.document.ts)
PascalCase (e.g., EncourageInfo)
PascalCase (e.g., Journey, LinkType)
camelCase (e.g., firstJoin, waitPay)
| field | Description |
|---|---|
| Design for Reusability | Create scalars that can be used across multiple modules. Think about common data patterns like addresses, contact info, or status tracking. |
| Keep Scalars Focused | Each scalar should represent a single concept. If a scalar grows too large, consider splitting it into smaller, composable pieces. |
| Use Proper Defaults | Provide sensible defaults for optional fields. Use function defaults (e.g., () => dayjs()) for dynamic values that should be computed at creation time. |
| Complete Dictionary Coverage | Always provide translations for all fields and enum values. Use the type system to ensure nothing is missed. |
| Validate at Field Level | Use field options like min/max, minlength/maxlength, and custom validate functions to ensure data integrity at the schema level. |
Create scalars that can be used across multiple modules. Think about common data patterns like addresses, contact info, or status tracking.
Each scalar should represent a single concept. If a scalar grows too large, consider splitting it into smaller, composable pieces.
Provide sensible defaults for optional fields. Use function defaults (e.g., () => dayjs()) for dynamic values that should be computed at creation time.
Always provide translations for all fields and enum values. Use the type system to ensure nothing is missed.
Use field options like min/max, minlength/maxlength, and custom validate functions to ensure data integrity at the schema level.
| field | Description |
|---|---|
| Domain Models | Embed scalars in models using field([ScalarClass]) |
| GraphQL | Auto-generated types and enums for API contracts |
| Validation | Runtime type checking through field options |
| Internationalization | Consistent terminology via scalarDictionary() |
| UI Components | Enum values can be directly used in select fields |
| Dictionary Sharing | Reuse enum translations across dictionaries |
Embed scalars in models using field([ScalarClass])
Auto-generated types and enums for API contracts
Runtime type checking through field options
Consistent terminology via scalarDictionary()
Enum values can be directly used in select fields
Reuse enum translations across dictionaries