UNPKG

odata-active-record-core

Version:

Core Active Record implementation for OData - The easiest way to interact with OData APIs

94 lines 2.44 kB
import type { IEntitySchema, IDataTypeHandler, IQueryResult, IQuery, ISchemaWarning, ICreateResult, IUpdateResult, IDeleteResult } from 'odata-active-record-contracts'; /** * ActiveRecord class - The main class for OData Active Record pattern * Provides fluent query interface with seamless data type handling */ export declare class ActiveRecord<T = Record<string, unknown>> { private schema; private dataTypeHandler; private query; private warnings; private errors; constructor(schema: IEntitySchema<T>, dataTypeHandler: IDataTypeHandler); /** * Add a where condition to the query */ where(field: keyof T, operator: string, value: unknown): this; /** * Select specific fields */ select(...fields: (keyof T)[]): this; /** * Order by a field */ orderBy(field: keyof T, direction?: 'asc' | 'desc'): this; /** * Limit the number of results */ limit(count: number): this; /** * Skip a number of results */ offset(count: number): this; /** * Expand a relationship */ expand(relation: string, callback?: (query: ActiveRecord<any>) => void): this; /** * Execute the query and return results */ find(): Promise<IQueryResult<T>>; /** * Execute the query and return a single result */ findOne(): Promise<T | null>; /** * Execute a count query */ count(): Promise<number>; /** * Create a new entity */ create(data: Partial<T>): ICreateResult<T>; /** * Update an entity */ update(id: any, data: Partial<T>): IUpdateResult<T>; /** * Delete an entity */ delete(id: any): IDeleteResult; /** * Validate if a field exists in the schema */ validateField(field: keyof T): boolean; /** * Get the schema */ getSchema(): IEntitySchema<T>; /** * Get warnings */ getWarnings(): ISchemaWarning[]; /** * Get the built query */ buildQuery(): IQuery; /** * Convert data types based on schema */ private convertDataTypes; /** * Validate data against schema */ private validateData; /** * Add an error to the error collection */ private addError; /** * Create a user-friendly error from a raw error */ private createUserFriendlyError; } //# sourceMappingURL=active-record.d.ts.map