import { type RequestContext } from "@antelopejs/interface-api"; import { type Class } from "@antelopejs/interface-core/decorators"; import type * as DatabaseDev from "@antelopejs/interface-database"; import { type InstanceId } from "@antelopejs/interface-database"; import { type Constructible, type DeepPartial } from "./common"; export type DataModel = { readonly schemaName: string; new (database: DatabaseDev.SchemaInstance): { readonly database: DatabaseDev.SchemaInstance; readonly table: DatabaseDev.Table; }; fromDatabase(obj: any): T | undefined; fromPlainData(obj: any): T; }; export type FieldError = { field: string; message: string; }; export type ValidationResult = { ok: true; } | { ok: false; errors: FieldError[]; }; export type ValidateInputOptions = { partial?: boolean; }; /** * Utility Class factory to create a basic Data Model with 1 table. * * @param dataType Database Table class * @param tableName Table name in Database */ export declare function BasicDataModel(dataType: Constructible, tableName?: string): { new (database: DatabaseDev.SchemaInstance): { /** * AQL Table reference. */ readonly table: DatabaseDev.Table; readonly database: DatabaseDev.SchemaInstance; /** * Get a single element from the table using its primary key. * * @param id Primary key value * @returns Table class instance */ get(id: string): PromiseLike; /** * Get multiple elements from the table using a given index. * * @param index Index name * @param keys Index value(s) * @returns Array of Table class instances. */ getBy(index: keyof T, ...keys: any[]): PromiseLike; /** * Get all the elements from the table. * * @returns Array of Table class instances. */ getAll(): PromiseLike; /** * Insert some data into the table. * * @param obj Table class instance or plain data * @param options Insert options * @returns Insert result */ insert(obj: DeepPartial | Array>, options?: ValidateOptions): Promise; /** * Updates a single element in the table. * * @param id Primary key value * @param obj Table class instance or plain data * @param options Update options * @returns Update result */ update(id: string, obj: DeepPartial, options?: ValidateOptions): Promise; update(obj: DeepPartial, options?: ValidateOptions): Promise; /** * Delete an element from the table. * * @param id Primary key value * @returns Delete result */ delete(id: string): Promise; }; readonly schemaName: string; /** * Converts some plain data into an instance of the Table class. * * @param obj Plain data object containing the table fields * @returns Table class instance */ fromPlainData(obj: any): T; /** * Converts an object acquired from the database into a Table class instance. * * @param obj Object resulting from a database get * @returns Table class instance */ fromDatabase(obj: any): T | undefined; /** * Converts a Table class instance into an object fit to be inserted in the database. * * @param obj Table class instance * @returns Database-ready data */ toDatabase(obj: any): Record; /** * Validates a plain object against every io-ts codec attached via `@Field`. * Pass `{ partial: true }` to skip fields not present on `obj` (patch semantics). */ validate(obj: unknown, options?: ValidateInputOptions): ValidationResult; }; export type ValidateOptions = { validate?: boolean; }; export declare function GetModel>(cl: DataModel & Class, instanceId?: InstanceId): M; export declare const Model: (cl: DataModel & Class<{ readonly database: DatabaseDev.SchemaInstance; readonly table: DatabaseDev.Table; }>, instanceIdOrCallback?: DatabaseDev.InstanceId | ((ctx: RequestContext) => InstanceId | undefined) | undefined) => import("@antelopejs/interface-core/decorators").PropertyDecorator & import("@antelopejs/interface-core/decorators").ParameterDecorator;