decorator | Description | Example |
---|---|---|
Field.Prop | Standard visible property stored in DB and exposed in API |
|
Field.Hidden | Internal data stored in DB but not exposed in API |
|
Field.Secret | Sensitive data with restricted access |
|
Field.Resolve | Computed property calculated at runtime |
|
Standard visible property stored in DB and exposed in API
@Field.Prop(() => String)
Internal data stored in DB but not exposed in API
@Field.Hidden(() => String)
Sensitive data with restricted access
@Field.Secret(() => String)
Computed property calculated at runtime
@Field.Resolve(() => Int)
// Standard property definition
@Field.Prop(() => Type, { ...options })
propertyName: TypeScriptType;
// Example with validation
@Field.Prop(() => Int, { min: 0, max: 100 })
score: number;
@Field.Prop(() => String, { minlength: 3, maxlength: 50 })
username: string;
@Field.Prop(() => Boolean, { default: false })
isActive: boolean;
@Field.Resolve(() => String)
get fullName(): string {
return `${this.firstName} ${this.lastName}`;
}
Option | Type | Default | Description | Example |
---|---|---|---|---|
default | any | null | Default value for the field |
|
nullable | boolean | false | Allows null values |
|
enum | Enum | - | Restricts to specific enum values |
|
immutable | boolean | false | Prevents modification after creation |
|
min/max | number | - | Value range constraints |
|
ref | string | - | Reference to another model |
|
text | "search" | "filter" | - | Search indexing behavior |
|
Default value for the field
{ default: "active" }
Allows null values
{ nullable: true }
Restricts to specific enum values
{ enum: StatusEnum }
Prevents modification after creation
{ immutable: true }
Value range constraints
{ min: 0, max: 100 }
Reference to another model
{ ref: "User" }
Search indexing behavior
{ text: "search" }
export const Status = enumOf(["active", "inactive"] as const);
export type Status = enumOf<typeof Status>;
@Field.Prop(() => String, { enum: Status, default: "active" })
status: Status;
// Single reference
@Field.Prop(() => LightUser, { ref: "User" })
owner: LightUser;
// Dynamic reference
@Field.Prop(() => LightModel, { refPath: "modelType" })
model: LightModel;
// Built-in validation
@Field.Prop(() => String, { minlength: 8, maxlength: 100 })
password: string;
// Custom validation
@Field.Prop(() => String, {
validate: (value) => /^[A-Z][a-z]+$/.test(value)
})
properName: string;
Check if using Field.Hidden instead of Field.Prop
Ensure default value type matches field type
Add { text: 'search' } option to searchable fields