ResourcefulBooleanType
The ResourcefulBooleanType class provides boolean value validation and schema generation for true/false fields. It follows OpenAPI 3.0 specifications for boolean data types with support for common modifiers.
For complete API reference, see ResourcefulBooleanType.
Overview
ResourcefulBooleanType is the simplest data type, supporting:
- Boolean Values: Standard true/false validation
- Type Safety: Full TypeScript support with validated configuration
- Common Modifiers: Support for nullable, readOnly, and writeOnly properties
- OpenAPI Integration: Automatic schema generation for boolean fields
Basic Usage
Simple Boolean Validation
import { ResourcefulBooleanType } from '@nhtio/lucid-resourceful/definitions'
// Basic boolean type
const isActiveType = ResourcefulBooleanType()
// Boolean with nullable option
const optionalBooleanType = ResourcefulBooleanType({
nullable: true
})With Decorators
import { resourcefulColumn } from '@nhtio/lucid-resourceful'
class User extends compose(BaseModel, withResourceful({ name: 'User' })) {
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare isActive: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
nullable: true
})
})
declare isVerified: boolean | null
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
readOnly: true
})
})
declare isArchived: boolean
}Configuration Options
No Specific Options
ResourcefulBooleanType has no type-specific configuration options as boolean validation is straightforward - values must be either true or false.
// Simple boolean - no additional configuration needed
const basicType = ResourcefulBooleanType()
// The empty object is optional
const explicitType = ResourcefulBooleanType({})Common Modifiers
All base interface modifiers are supported:
Nullable Booleans
// Boolean that can be null (three-state boolean)
const nullableBooleanType = ResourcefulBooleanType({
nullable: true
})
@resourcefulColumn.boolean({
type: nullableBooleanType
})
declare optionalFlag: boolean | nullRead-Only Booleans
// Boolean that cannot be modified through API
const readOnlyType = ResourcefulBooleanType({
readOnly: true
})
@resourcefulColumn.boolean({
type: readOnlyType
})
declare isSystemGenerated: booleanWrite-Only Booleans
// Boolean that is not returned in responses (rare use case)
const writeOnlyType = ResourcefulBooleanType({
writeOnly: true
})
@resourcefulColumn.boolean({
type: writeOnlyType
})
declare shouldProcessInBackground: booleanCommon Patterns
Status Flags
class Account extends compose(BaseModel, withResourceful({ name: 'Account' })) {
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare isActive: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare isVerified: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare isSuspended: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare isDeleted: boolean
}User Preferences
class UserPreferences extends compose(BaseModel, withResourceful({ name: 'UserPreferences' })) {
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare emailNotifications: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare smsNotifications: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare pushNotifications: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare marketingEmails: boolean
}Feature Flags
class FeatureFlags extends compose(BaseModel, withResourceful({ name: 'FeatureFlags' })) {
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare darkModeEnabled: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare betaFeaturesEnabled: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare advancedUIEnabled: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
nullable: true
})
})
declare experimentalFeature: boolean | null
}System Flags
class SystemSettings extends compose(BaseModel, withResourceful({ name: 'SystemSettings' })) {
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
readOnly: true
})
})
declare maintenanceMode: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
readOnly: true
})
})
declare isHealthy: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType()
})
declare debugMode: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType()
})
declare loggingEnabled: boolean
}Advanced Examples
Audit and Tracking
class Document extends compose(BaseModel, withResourceful({ name: 'Document' })) {
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare isPublished: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare requiresApproval: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
readOnly: true
})
})
declare hasBeenModified: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
readOnly: true
})
})
declare isArchived: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
nullable: true
})
})
declare isConfidential: boolean | null
}E-commerce Product Flags
class Product extends compose(BaseModel, withResourceful({ name: 'Product' })) {
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare isActive: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare inStock: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare isFeatured: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare isOnSale: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare requiresShipping: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
nullable: true
})
})
declare isDigitalProduct: boolean | null
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
readOnly: true
})
})
declare hasReviews: boolean
}Content Management
class BlogPost extends compose(BaseModel, withResourceful({ name: 'BlogPost' })) {
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare isPublished: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare allowComments: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare isFeatured: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare isSticky: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
nullable: true
})
})
declare requiresSubscription: boolean | null
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
readOnly: true
})
})
declare hasBeenEdited: boolean
}Access Control and Permissions
class UserRole extends compose(BaseModel, withResourceful({ name: 'UserRole' })) {
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare canRead: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare canWrite: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare canDelete: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare canAdmin: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
nullable: true
})
})
declare hasSpecialAccess: boolean | null
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
readOnly: true
})
})
declare isSystemRole: boolean
}Three-State Booleans
Sometimes you need to represent three states: true, false, and unknown/not-set:
class Survey extends compose(BaseModel, withResourceful({ name: 'Survey' })) {
// Required yes/no question
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare agreeToTerms: boolean
// Optional questions that can be unanswered
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
nullable: true
})
})
declare likeOurService: boolean | null
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
nullable: true
})
})
declare wouldRecommend: boolean | null
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
nullable: true
})
})
declare satisfiedWithSupport: boolean | null
}Computed Boolean Properties
Use with computed accessors for derived boolean values:
class User extends compose(BaseModel, withResourceful({ name: 'User' })) {
@resourcefulColumn.boolean({
type: ResourcefulBooleanType()
})
declare isActive: boolean
@resourcefulColumn.boolean({
type: ResourcefulBooleanType()
})
declare isVerified: boolean
@resourcefulComputed.boolean({
type: ResourcefulBooleanType({
readOnly: true
})
})
get canLogin(): boolean {
return this.isActive && this.isVerified
}
@resourcefulComputed.boolean({
type: ResourcefulBooleanType({
readOnly: true
})
})
get needsAttention(): boolean {
return !this.isActive || !this.isVerified
}
}Default Values and Behavior
Boolean fields typically have default values defined at the database level:
class Settings extends compose(BaseModel, withResourceful({ name: 'Settings' })) {
// Database should have DEFAULT FALSE
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare emailNotifications: boolean
// Database should have DEFAULT TRUE
@resourcefulColumn.boolean({
type: ResourcefulBooleanType(),
nullable: false
})
declare isActive: boolean
// Database should allow NULL with no default
@resourcefulColumn.boolean({
type: ResourcefulBooleanType({
nullable: true
})
})
declare marketingConsent: boolean | null
}OpenAPI Schema Generation
ResourcefulBooleanType generates simple OpenAPI 3.0 schemas:
const booleanType = ResourcefulBooleanType()
// Generated OpenAPI schema:
{
"type": "boolean"
}
// With nullable:
const nullableType = ResourcefulBooleanType({ nullable: true })
// Generated schema:
{
"type": "boolean",
"nullable": true
}Best Practices
Use meaningful names: Choose descriptive property names that clearly indicate what true/false means
Consider nullability carefully: Decide if three-state logic (true/false/null) is needed
Set appropriate defaults: Define database defaults for non-nullable boolean fields
Document boolean meaning: Make it clear what true/false represents in your domain
Use positive naming: Prefer
isActiveoverisNotActivefor clarityGroup related flags: Consider using separate models for related boolean flags
Validate business logic: Ensure boolean combinations make sense in your domain
Consider computed properties: Use computed accessors for derived boolean values
Handle nullable cases: Properly handle null values in three-state scenarios
Use read-only for calculated flags: Mark system-calculated booleans as read-only
Common Naming Conventions
Status Flags
isActive,isEnabled,isDisabledisPublished,isDraft,isArchivedisDeleted,isSuspended,isBanned
Verification Flags
isVerified,isConfirmed,isValidatedisApproved,isPending,isRejected
Permission Flags
canRead,canWrite,canDelete,canAdminhasAccess,hasPermission,hasRole
Feature Flags
hasFeature,enablesFeature,supportsFeatureallowsComments,requiresLogin,needsApproval
Preference Flags
emailNotifications,smsAlerts,pushNotificationsdarkMode,compactView,autoSave