import { Adapter, AdapterFlags, Condition, Context, ContextualArgs, FlagsOf, MaybeContextualArg, Paginator, PreparedModel, PreparedStatement, Repository, Sequence, SequenceOptions, Statement } from "@decaf-ts/core"; import { BaseError, OperationKeys, PrimaryKeyType } from "@decaf-ts/db-decorators"; import { HttpConfig, HttpFlags } from "./types"; import { Model } from "@decaf-ts/decorator-validation"; import { Constructor } from "@decaf-ts/decoration"; export declare function suffixMethod(obj: any, before: (...args: any[]) => any, suffix: (...args: any[]) => any, beforeName?: string): void; /** * @description Abstract HTTP adapter for REST API interactions * @summary Provides a base implementation for HTTP adapters with methods for CRUD operations, * URL construction, and error handling. This class extends the core Adapter class and * implements the necessary methods for HTTP communication. Concrete implementations * must provide specific HTTP client functionality. * @template Y - The native HTTP client type * @template Q - The query type used by the adapter * @template F - The HTTP flags type, extending HttpFlags * @template C - The context type, extending Context * @param {Y} native - The native HTTP client instance * @param {HttpConfig} config - Configuration for the HTTP adapter * @param {string} flavour - The adapter flavor identifier * @param {string} [alias] - Optional alias for the adapter * @class HttpAdapter * @example * ```typescript * // Example implementation with Axios * class AxiosAdapter extends HttpAdapter { * constructor(config: HttpConfig) { * super(axios.create(), config, 'axios'); * } * * async request(details: AxiosRequestConfig): Promise { * const response = await this.native.request(details); * return response.data; * } * * // Implement other abstract methods... * } * ``` */ export declare abstract class HttpAdapter = PreparedStatement, C extends Context = Context> extends Adapter { protected constructor(config: CONF, flavour: string, alias?: string); /** * @description Generates operation flags with HTTP headers * @summary Extends the base flags method to ensure HTTP headers exist on the flags payload. * @template M - The model type * @param {OperationKeys|string} operation - The type of operation being performed * @param {Constructor | Constructor[]} model - The target model constructor(s) * @param {Partial>} overrides - Optional flag overrides * @param {...any[]} args - Additional arguments forwarded to the base implementation * @return {Promise>} The flags object with headers */ protected flags(operation: OperationKeys | string, model: Constructor | Constructor[], overrides: Partial>): Promise>; protected Dispatch(): any; protected getEventHeaders(): Promise<{}>; /** * @description Returns the repository constructor for this adapter * @summary Provides the RestService class as the repository implementation for this HTTP adapter. * This method is used to create repository instances that work with this adapter type. * @template R - Repository subtype working with this adapter * @return {Constructor} The repository constructor */ repository>>(): Constructor; /** * @description Prepares a model for persistence * @summary Converts a model instance into a format suitable for database storage, * handling column mapping and separating transient properties * @template M - The model type * @param {M} model - The model instance to prepare * @param pk - The primary key property name * @param args * @return The prepared data */ prepare(model: M, ...args: ContextualArgs): PreparedModel; /** * @description Converts database data back into a model instance * @summary Reconstructs a model instance from database data, handling column mapping * and reattaching transient properties * @template M - The model type * @param obj - The database record * @param {string|Constructor} clazz - The model class or name * @param pk - The primary key property name * @param {string|number|bigint} id - The primary key value * @return {M} The reconstructed model instance */ revert(obj: Record, clazz: string | Constructor, id: PrimaryKeyType, ...args: ContextualArgs): M; protected toTableName(t: string | Constructor): string; protected toHeaders(ctx: C): { [x: string]: any; }; /** * @description Constructs a URL for API requests * @summary Builds a complete URL for API requests using the configured protocol and host, * the specified table name, and optional query parameters. The method handles URL encoding. * @param {string | Constructor} tableName - The name of the table or endpoint * @return {string} The encoded URL string */ url(tableName: string | Constructor): string; /** * @description Constructs a URL for API requests * @summary Builds a complete URL for API requests using the configured protocol and host, * the specified table name, and optional query parameters. The method handles URL encoding. * @param {string | Constructor} tableName - The name of the table or endpoint * @param {string[]} pathParams - Optional query parameters * @return {string} The encoded URL string */ url(tableName: string | Constructor, pathParams: string[]): string; /** * @description Constructs a URL for API requests * @summary Builds a complete URL for API requests using the configured protocol and host, * the specified table name, and optional query parameters. The method handles URL encoding. * @param {string | Constructor} tableName - The name of the table or endpoint * @param {Record} queryParams - Optional query parameters * @return {string} The encoded URL string */ url(tableName: string | Constructor, queryParams: Record): string; url(tableName: string | Constructor, pathParams: string[], queryParams: Record): string; abstract toRequest(query: Q): REQ; abstract toRequest(ctx: C): REQ; abstract toRequest(query: Q, ctx: C): REQ; abstract toRequest(ctxOrQuery: C | Q, ctx?: C): REQ; /** * @description Sends an HTTP request * @summary Abstract method that must be implemented by subclasses to send HTTP requests * using the native HTTP client. This is the core method for making API calls. * @template V - The response value type * @param {REQ} details - The request details specific to the HTTP client * @return {Promise} A promise that resolves with the response data */ abstract request(details: REQ, ...args: MaybeContextualArg): Promise; protected extractIdArgs(model: Constructor | string, id: PrimaryKeyType): string[]; parseResponse(clazz: Constructor | undefined, method: OperationKeys | string, res: any): any; /** * @description Creates a new resource * @summary Abstract method that must be implemented by subclasses to create a new resource * via HTTP. This typically corresponds to a POST request. * @param {string} tableName - The name of the table or endpoint * @param {string|number} id - The identifier for the resource * @param {Record} model - The data model to create * @param {...any[]} args - Additional arguments * @return {Promise>} A promise that resolves with the created resource */ abstract create(tableName: Constructor, id: PrimaryKeyType, model: Record, ...args: ContextualArgs): Promise>; /** * @description Retrieves a resource by ID * @summary Abstract method that must be implemented by subclasses to retrieve a resource * via HTTP. This typically corresponds to a GET request. * @param {string} tableName - The name of the table or endpoint * @param {string|number|bigint} id - The identifier for the resource * @param {...any[]} args - Additional arguments * @return {Promise>} A promise that resolves with the retrieved resource */ abstract read(tableName: Constructor, id: PrimaryKeyType, ...args: ContextualArgs): Promise>; /** * @description Updates an existing resource * @summary Abstract method that must be implemented by subclasses to update a resource * via HTTP. This typically corresponds to a PUT or PATCH request. * @param {string} tableName - The name of the table or endpoint * @param {string|number} id - The identifier for the resource * @param {Record} model - The updated data model * @param {...any[]} args - Additional arguments * @return {Promise>} A promise that resolves with the updated resource */ abstract update(tableName: Constructor, id: string | number, model: Record, ...args: ContextualArgs): Promise>; /** * @description Deletes a resource by ID * @summary Abstract method that must be implemented by subclasses to delete a resource * via HTTP. This typically corresponds to a DELETE request. * @param {string} tableName - The name of the table or endpoint * @param {string|number|bigint} id - The identifier for the resource to delete * @param {...any[]} args - Additional arguments * @return {Promise>} A promise that resolves with the deletion result */ abstract delete(tableName: Constructor, id: PrimaryKeyType, ...args: ContextualArgs): Promise>; /** * @description Executes a raw query * @summary Method for executing raw queries directly with the HTTP client. * This method is not supported by default in HTTP adapters and throws an UnsupportedError. * Subclasses can override this method to provide implementation. * @template R - The result type * @param {Q} rawInput - The raw query input * @param {boolean} process - Whether to process the result * @param {...any[]} args - Additional arguments * @return {Promise} A promise that resolves with the query result * @throws {UnsupportedError} Always throws as this method is not supported by default */ raw(rawInput: Q, ...args: ContextualArgs): Promise; /** * @description Creates a sequence * @summary Method for creating a sequence for generating unique identifiers. * This method is not supported by default in HTTP adapters and throws an UnsupportedError. * Subclasses can override this method to provide implementation. * @param {SequenceOptions} options - Options for creating the sequence * @return {Promise} A promise that resolves with the created sequence * @throws {UnsupportedError} Always throws as this method is not supported by default */ Sequence(options: SequenceOptions): Promise; /** * @description Creates a statement for querying * @summary Method for creating a statement for building and executing queries. * This method is not supported by default in HTTP adapters and throws an UnsupportedError. * Subclasses can override this method to provide implementation. * @template M - The model type * @template ! - The raw query type * @return {Statement} A statement object for building queries * @throws {UnsupportedError} Always throws as this method is not supported by default */ Statement(overrides?: Partial): Statement, any>; Paginator(query: Q, size: number, clazz: Constructor): Paginator; /** * @description Parses a condition into a query * @summary Method for parsing a condition object into a query format understood by the HTTP client. * This method is not supported by default in HTTP adapters and throws an UnsupportedError. * Subclasses can override this method to provide implementation. * @param {Condition} condition - The condition to parse * @return {Q} The parsed query * @throws {UnsupportedError} Always throws as this method is not supported by default */ parseCondition(condition: Condition): Q; static parseError(err: Error | string, ...args: any[]): E; static decoration(): void; }