Fields Reference
Complete reference for field types and methods.
Field Types
string
Short text field.
name: string
name: string.min(2).max(100)text
Long text field (unlimited length).
content: text
bio: text.optional()int
Integer number.
age: int
quantity: int.gte(0).default(0)float
Decimal number.
price: float
rating: float.gte(0).lte(5)boolean / bool
True/false value.
isActive: boolean
published: bool.default(false)datetime
Date and time.
createdAt: datetime
publishedAt: datetime.optional()json
Untyped JSON data.
metadata: json
settings: json.optional()jsonTyped<T>()
Typed JSON data.
interface Address {
street: string
city: string
zip: string
}
address: jsonTyped<Address>()email
String with email validation.
email: email.unique()
// Equivalent to: string.email()Modifiers
.optional()
Make field optional.
bio: text.optional().unique()
Add unique constraint.
email: string.unique()
slug: string.lower().unique().default(value)
Set default value.
role: string.default("user")
count: int.default(0)
createdAt: datetime.default(() => new Date())Validation Methods
.min(value, message?)
Minimum length/value.
name: string.min(2)
age: int.min(18, "Must be 18+").max(value, message?)
Maximum length/value.
title: string.max(200)
quantity: int.max(100).length(min, max, message?)
Length range.
code: string.length(6, 6)
password: string.length(8, 128).email(message?)
Email validation.
email: string.email().url(message?)
URL validation.
website: string.url().optional().regex(pattern, message?)
Regex validation.
phone: string.regex(/^\+?[\d\s-]+$/, "Invalid phone")
sku: string.regex(/^[A-Z]{3}-\d{4}$/).startsWith(value, message?)
String starts with.
url: string.startsWith("https://").endsWith(value, message?)
String ends with.
email: string.endsWith("@company.com").contains(value, message?)
String contains.
name: string.contains("test").gt(value, message?)
Greater than.
price: float.gt(0, "Must be positive").gte(value, message?)
Greater than or equal.
quantity: int.gte(0).lt(value, message?)
Less than.
discount: float.lt(100).lte(value, message?)
Less than or equal.
rating: float.lte(5).validate(fn, message?)
Custom validation.
code: string.validate(
(v) => luhnCheck(v),
"Invalid code"
)Transform Methods
.trim()
Trim whitespace.
name: string.trim().lower()
Convert to lowercase.
email: string.lower()
slug: string.trim().lower().upper()
Convert to uppercase.
code: string.upper()
sku: string.trim().upper()Security Methods
.password(options?)
Hash password with scrypt (Node.js native, zero dependencies).
password: string.password() // default cost 2
password: string.password({ cost: 1 }) // fast (development)
password: string.password({ cost: 3 }) // high securityCost Levels:
| Cost | N Value | Time | Use Case |
|---|---|---|---|
| 1 | 16384 | ~200ms | Development/testing |
| 2 | 32768 | ~400ms | Production (default) |
| 3 | 65536 | ~800ms | High security |
| 4 | 131072 | ~1.6s | Maximum security |
.omit()
Omit from API responses.
password: string.password().omit()
internalNote: text.omit().encrypted()
Encrypt with AES-256-GCM.
ssn: string.encrypted()
apiKey: string.encrypted()Access Policy Methods
.readable(policy)
Set read access policy.
email: string.readable("authenticated")
salary: float.readable("admin").writable(policy)
Set write access policy.
role: string.writable("admin")
status: string.writable("owner").readOnly()
Make field read-only.
createdBy: string.readOnly().adminOnly()
Admin-only access.
internalNotes: text.adminOnly().ownerWritable()
Owner can write.
bio: text.ownerWritable()Rich Metadata Methods
These methods enhance OpenAPI docs, Admin UI, and AI integrations.
.label(value)
Set human-readable label for forms and API docs.
email: string.label("Email Address")
dob: datetime.label("Date of Birth").description(value)
Set detailed description for tooltips and documentation.
email: string.description("Primary email used for notifications")
status: string.description("Current order fulfillment status").placeholder(value)
Set placeholder text for form inputs.
email: string.placeholder("Enter your email...")
search: string.placeholder("Search products...").example(value)
Set example value for OpenAPI documentation.
email: string.example("user@example.com")
price: float.example(29.99).icon(value)
Set icon for Admin UI display.
email: string.icon("📧")
phone: string.icon("📱").options(values)
Define allowed values (creates enum in OpenAPI and TypeScript).
status: string.options(["pending", "active", "closed"])
priority: string.options(["low", "medium", "high", "urgent"]).ui(config)
Set UI rendering hints for Admin UI generation.
content: text.ui({ component: "RichTextEditor" })
password: string.ui({ hidden: ["list", "detail"] })
order: int.ui({ order: 1, width: "100px" })Config options:
component- Custom component namehidden- Hide in specific views:trueor["list" | "detail" | "form" | "create" | "edit"]readonly- Read-only in formsorder- Display orderwidth- Column widthgroup- Group fields together
.searchable()
Mark field for full-text search indexing.
title: string.searchable()
content: text.searchable().embedding(config?)
Enable vector embedding for semantic search (RAG).
content: text.embedding()
content: text.embedding({ provider: "openai", model: "text-embedding-3-small" })Config options:
provider-"openai"|"cohere"|"huggingface"| custommodel- Model namedimensions- Vector dimensions
.sensitive()
Mark as PII/sensitive data for GDPR compliance.
ssn: string.sensitive()
email: string.sensitive()Relations
belongsTo(entity)
Many-to-one relation.
author: belongsTo(() => user)
category: belongsTo(() => category).optional()hasMany(entity)
One-to-many relation.
posts: hasMany(() => post)
comments: hasMany(() => comment)hasOne(entity)
One-to-one relation.
profile: hasOne(() => profile)selfRef(type?)
Self-referential relation.
parent: selfRef("parent").optional()
children: selfRef("children")Relation Methods
.foreignKey(key)
Custom foreign key.
author: belongsTo(() => user).foreignKey("creatorId").onDelete(action)
Delete behavior.
author: belongsTo(() => user).onDelete("cascade")
// "cascade" | "setNull" | "restrict".remote(serviceId)
Remote relation.
subscription: belongsTo(() => Sub).remote("stripeService")