82 lines
1.9 KiB
TypeScript
82 lines
1.9 KiB
TypeScript
import { BaseModel } from './base.model';
|
|
|
|
export interface FieldOption {
|
|
label: string;
|
|
value: string | number | boolean;
|
|
}
|
|
|
|
export interface ValidationRule {
|
|
type: 'required' | 'min' | 'max' | 'email' | 'url' | 'pattern' | 'custom';
|
|
value?: any;
|
|
message?: string;
|
|
}
|
|
|
|
export interface UIMetadata {
|
|
// Display properties
|
|
placeholder?: string;
|
|
helpText?: string;
|
|
|
|
// View visibility
|
|
showOnList?: boolean;
|
|
showOnDetail?: boolean;
|
|
showOnEdit?: boolean;
|
|
sortable?: boolean;
|
|
|
|
// Field type specific options
|
|
options?: FieldOption[]; // For select, multi-select
|
|
rows?: number; // For textarea
|
|
min?: number; // For number, date
|
|
max?: number; // For number, date
|
|
step?: number; // For number
|
|
accept?: string; // For file/image
|
|
relationDisplayField?: string; // Which field to display for relations
|
|
|
|
// Formatting
|
|
format?: string; // Date format, number format, etc.
|
|
prefix?: string; // Currency symbol, etc.
|
|
suffix?: string;
|
|
|
|
// Validation
|
|
validationRules?: ValidationRule[];
|
|
|
|
// Advanced
|
|
dependsOn?: string[]; // Field dependencies
|
|
computedValue?: string; // Formula for computed fields
|
|
}
|
|
|
|
export class FieldDefinition extends BaseModel {
|
|
static tableName = 'field_definitions';
|
|
|
|
id!: string;
|
|
objectDefinitionId!: string;
|
|
apiName!: string;
|
|
label!: string;
|
|
type!: string;
|
|
length?: number;
|
|
precision?: number;
|
|
scale?: number;
|
|
referenceObject?: string;
|
|
defaultValue?: string;
|
|
description?: string;
|
|
isRequired!: boolean;
|
|
isUnique!: boolean;
|
|
isSystem!: boolean;
|
|
isCustom!: boolean;
|
|
displayOrder!: number;
|
|
uiMetadata?: UIMetadata;
|
|
// Field-level permissions
|
|
defaultReadable!: boolean;
|
|
defaultWritable!: boolean;
|
|
|
|
static relationMappings = {
|
|
objectDefinition: {
|
|
relation: BaseModel.BelongsToOneRelation,
|
|
modelClass: 'object-definition.model',
|
|
join: {
|
|
from: 'field_definitions.objectDefinitionId',
|
|
to: 'object_definitions.id',
|
|
},
|
|
},
|
|
};
|
|
}
|