import { type InsForgeClient } from "@insforge/sdk"; import type { ConfigFacade, FetchResult, IfConfig, IfInsertRows, IfInvokeOptions, IfListOptions, IfRpcCall, IfStorageRef, IfTableQuery, IfUpdatePatch, IfWriteQuery } from "../../types/index.js"; /** * InsForgeService - Singleton para el cliente InsForge (fallback de base de datos). * * Aplica el patrón Singleton: una única instancia mantiene el * {@link InsForgeClient} y centraliza las operaciones de tabla, RPC, * storage y edge functions, devolviendo siempre Safe Results. * * @example * ```ts * const insforge = InsForgeService.getInstance(); * insforge.useInit({ baseUrl: "https://app.insforge.app", anonKey: "…" }); * const result = await insforge.useSelect({ table: "posts" }); * ``` */ export declare class InsForgeService { private static instance; /** InsForge client. InsForge is the database fallback, not the default. */ private client; /** * Constructor privado - enforce singleton. */ private constructor(); /** * Obtiene la instancia única del InsForgeService (Singleton). * * @returns La instancia única de {@link InsForgeService}. */ static getInstance(): InsForgeService; /** * Registers the InsForge client. Call once per app. Prefer `apiKey` * (server-only, admin) or `anonKey` (browser-safe) depending on the runtime. * * @param config - Backend URL + credentials + optional schema. * @throws {Error} If the config fails validation. * * @example * ```ts * InsForgeService.getInstance().useInit({ baseUrl: "https://app.insforge.app", anonKey: "…" }); * ``` */ useInit(config: IfConfig): void; /** * Returns the initialized client (or `null` before `useInit`). * Exposed for advanced use - the wrappers cover the supported surface. * * @returns The InsForge client or `null`. */ useGetClient(): InsForgeClient | null; /** * Reads rows from a table with equality filters, ordering and pagination. * * @param query - Table, columns, filters, order, limit and offset. * @returns Safe Result with the rows. */ useSelect>(query: IfTableQuery): Promise>; /** * Inserts one or more rows and returns the created rows. * * @param table - Table name. * @param rows - Rows to insert (at least one). * @param schema - Optional schema override. * @returns Safe Result with the inserted rows. */ useInsert>(table: string, rows: IfInsertRows, schema?: string): Promise>; /** * Updates rows matching the filters and returns the updated rows. * Filters are REQUIRED - mass updates are refused at validation time. * * @param query - Table + mandatory filters (+ optional schema). * @param patch - Column patch (must not be empty). * @returns Safe Result with the updated rows. */ useUpdate>(query: IfWriteQuery, patch: IfUpdatePatch): Promise>; /** * Deletes rows matching the filters and returns the deleted rows. * Filters are REQUIRED - mass deletes are refused at validation time. * * @param query - Table + mandatory filters (+ optional schema). * @returns Safe Result with the deleted rows. */ useDelete>(query: IfWriteQuery): Promise>; /** * Calls a Postgres function (RPC). * * @param call - Function name, params and optional schema. * @returns Safe Result with the function output. */ useRpc(call: IfRpcCall): Promise>; /** * Uploads a file to a bucket (standard PUT semantics: same key replaces). * * @param ref - Bucket + object key. * @param file - File or Blob to upload. * @returns Safe Result with the stored file metadata. */ useUpload(ref: IfStorageRef, file: File | Blob): Promise>>; /** * Downloads a file from a bucket. * * @param ref - Bucket + object key. * @returns Safe Result with the file as a Blob. */ useDownload(ref: IfStorageRef): Promise>; /** * Removes a file from a bucket. * * @param ref - Bucket + object key. * @returns Safe Result with the deletion response. */ useRemove(ref: IfStorageRef): Promise>>; /** * Lists objects in a bucket. * * @param bucket - Bucket name. * @param options - Prefix, search, limit and offset. * @returns Safe Result with the listing. */ useListObjects(bucket: string, options?: IfListOptions): Promise>>; /** * Builds the public URL for an object in a public bucket (no network call). * * @param ref - Bucket + object key. * @returns Safe Result with `{ publicUrl }`. */ useGetPublicUrl(ref: IfStorageRef): FetchResult<{ publicUrl: string; }>; /** * Invokes an edge function. * * @param options - Function slug + optional JSON body. * @returns Safe Result with the function response. */ useInvokeFunction(options: IfInvokeOptions): Promise>; } /** * Registers the InsForge client and returns your methods alongside it - the * config-file entry point. One call is the whole setup: no separate * `useInitInsforge(...)` step. * * Prefer `apiKey` (server-only, admin) or `anonKey` (browser-safe) depending * on the runtime. Declare methods with `function` (never arrows) so * `this.config` resolves to the config you declared. * * @typeParam T - The literal passed in: InsForge config plus any methods. * @param input - Backend URL + credentials + optional schema, plus your methods. * @returns The declared config plus your methods (see {@link ConfigFacade}). * @throws {Error} If the config fails validation. * * @example * ```ts * import { defineInsforgeConfig } from "katanakit-js/adapters/insforge"; * * export default defineInsforgeConfig({ * baseUrl: "https://app.insforge.app", * anonKey: "…", * listUsers: async function () { * return useIfSelect("users"); * }, * }); * ``` */ export declare function defineInsforgeConfig(input: T & ThisType>): ConfigFacade; /** * Registers the InsForge client. Call once per app. Prefer `apiKey` * (server-only, admin) or `anonKey` (browser-safe) depending on the runtime. * * @deprecated Use {@link defineInsforgeConfig}, which registers the config and * returns it with any methods declared on the same literal. * * @param config - Backend URL + credentials + optional schema. * @throws {Error} If the config fails validation. * * @example * ```ts * import { useInitInsforge } from "katanakit-js/adapters/insforge"; * * useInitInsforge({ baseUrl: "https://app.insforge.app", anonKey: "…" }); * ``` */ export declare function useInitInsforge(config: IfConfig): void; /** * Returns the initialized client (or `null` before `useInitInsforge`). * Exposed for advanced use - the wrappers cover the supported surface. * * @returns The InsForge client or `null`. */ export declare function useGetInsforgeClient(): InsForgeClient | null; /** * Reads rows from a table with equality filters, ordering and pagination. * * @param query - Table, columns, filters, order, limit and offset. * @returns Safe Result with the rows. * * @example * ```ts * const result = await useIfSelect({ table: "posts", filters: { author_id: 7 } }); * ``` */ export declare function useIfSelect>(query: IfTableQuery): Promise>; /** * Inserts one or more rows and returns the created rows. * * @param table - Table name. * @param rows - Rows to insert (at least one). * @param schema - Optional schema override. * @returns Safe Result with the inserted rows. */ export declare function useIfInsert>(table: string, rows: IfInsertRows, schema?: string): Promise>; /** * Updates rows matching the filters and returns the updated rows. * Filters are REQUIRED - mass updates are refused at validation time. * * @param query - Table + mandatory filters (+ optional schema). * @param patch - Column patch (must not be empty). * @returns Safe Result with the updated rows. */ export declare function useIfUpdate>(query: IfWriteQuery, patch: IfUpdatePatch): Promise>; /** * Deletes rows matching the filters and returns the deleted rows. * Filters are REQUIRED - mass deletes are refused at validation time. * * @param query - Table + mandatory filters (+ optional schema). * @returns Safe Result with the deleted rows. */ export declare function useIfDelete>(query: IfWriteQuery): Promise>; /** * Calls a Postgres function (RPC). * * @param call - Function name, params and optional schema. * @returns Safe Result with the function output. */ export declare function useIfRpc(call: IfRpcCall): Promise>; /** * Uploads a file to a bucket (standard PUT semantics: same key replaces). * * @param ref - Bucket + object key. * @param file - File or Blob to upload. * @returns Safe Result with the stored file metadata. */ export declare function useIfUpload(ref: IfStorageRef, file: File | Blob): Promise>>; /** * Downloads a file from a bucket. * * @param ref - Bucket + object key. * @returns Safe Result with the file as a Blob. */ export declare function useIfDownload(ref: IfStorageRef): Promise>; /** * Removes a file from a bucket. * * @param ref - Bucket + object key. * @returns Safe Result with the deletion response. */ export declare function useIfRemove(ref: IfStorageRef): Promise>>; /** * Lists objects in a bucket. * * @param bucket - Bucket name. * @param options - Prefix, search, limit and offset. * @returns Safe Result with the listing. */ export declare function useIfListObjects(bucket: string, options?: IfListOptions): Promise>>; /** * Builds the public URL for an object in a public bucket (no network call). * * @param ref - Bucket + object key. * @returns Safe Result with `{ publicUrl }`. */ export declare function useIfGetPublicUrl(ref: IfStorageRef): FetchResult<{ publicUrl: string; }>; /** * Invokes an edge function. * * @param options - Function slug + optional JSON body. * @returns Safe Result with the function response. */ export declare function useIfInvokeFunction(options: IfInvokeOptions): Promise>; //# sourceMappingURL=insforge.service.d.ts.map