import type { Class, RetainPrimitiveFields } from '@travetto/runtime'; import type { ModelType } from '../types/model.ts'; export type SortClauseRaw = { [P in keyof T]?: T[P] extends object ? SortClauseRaw> : 1 | -1; }; type IndexClauseRaw = { [P in keyof T]?: T[P] extends object ? IndexClauseRaw> : 1 | -1 | true; }; export type DataHandler = (inst: T) => (Promise | T | void); export type PrePersistScope = 'full' | 'partial' | 'all'; /** * Model config */ export class ModelConfig { /** * Class for model */ class: Class; /** * Store name */ store: string; /** * Indices */ indices?: IndexConfig[]; /** * Vendor specific extras */ extra?: object; /** * Expiry field */ expiresAt?: string; /** * Allows auto creation of a model storage backing at runtime */ autoCreate?: 'production' | 'development' | 'off'; /** * Pre-persist handlers */ prePersist?: { scope: PrePersistScope, handler: DataHandler }[]; /** * Post-load handlers */ postLoad?: DataHandler[]; } /** * Supported index types */ export type IndexType = 'unique' | 'unsorted' | 'sorted'; /** * Index options */ export type IndexConfig = { /** * Index name */ name: string; /** * Fields and sort order */ fields: IndexClauseRaw>[]; /** * Type */ type: IndexType; }; export type IndexField = IndexClauseRaw>;