import { CompiledQuery } from "kysely"; import { QueryCallbackReturnType, useRelationalQueryOptions } from "@powerhousedao/reactor-browser"; import { IRelationalDb, IRelationalQueryBuilder, RelationalDbProcessorClass } from "@powerhousedao/shared/processors"; //#region ../../node_modules/.pnpm/@electric-sql+pglite@0.3.15/node_modules/@electric-sql/pglite/dist/pglite-CntadC_p.d.ts type MessageName = 'parseComplete' | 'bindComplete' | 'closeComplete' | 'noData' | 'portalSuspended' | 'replicationStart' | 'emptyQuery' | 'copyDone' | 'copyData' | 'rowDescription' | 'parameterDescription' | 'parameterStatus' | 'backendKeyData' | 'notification' | 'readyForQuery' | 'commandComplete' | 'dataRow' | 'copyInResponse' | 'copyOutResponse' | 'authenticationOk' | 'authenticationMD5Password' | 'authenticationCleartextPassword' | 'authenticationSASL' | 'authenticationSASLContinue' | 'authenticationSASLFinal' | 'error' | 'notice'; type BackendMessage = { name: MessageName; length: number; }; interface NoticeOrError { message: string | undefined; severity: string | undefined; code: string | undefined; detail: string | undefined; hint: string | undefined; position: string | undefined; internalPosition: string | undefined; internalQuery: string | undefined; where: string | undefined; schema: string | undefined; table: string | undefined; column: string | undefined; dataType: string | undefined; constraint: string | undefined; file: string | undefined; line: string | undefined; routine: string | undefined; } declare class NoticeMessage implements BackendMessage, NoticeOrError { readonly length: number; readonly message: string | undefined; constructor(length: number, message: string | undefined); readonly name = "notice"; severity: string | undefined; code: string | undefined; detail: string | undefined; hint: string | undefined; position: string | undefined; internalPosition: string | undefined; internalQuery: string | undefined; where: string | undefined; schema: string | undefined; table: string | undefined; column: string | undefined; dataType: string | undefined; constraint: string | undefined; file: string | undefined; line: string | undefined; routine: string | undefined; } type IDBFS = Emscripten.FileSystemType & { quit: () => void; dbs: Record; }; type FS = typeof FS & { filesystems: { MEMFS: Emscripten.FileSystemType; NODEFS: Emscripten.FileSystemType; IDBFS: IDBFS; }; quit: () => void; }; interface PostgresMod extends Omit { preInit: Array<{ (mod: PostgresMod): void; }>; preRun: Array<{ (mod: PostgresMod): void; }>; postRun: Array<{ (mod: PostgresMod): void; }>; FS: FS; FD_BUFFER_MAX: number; WASM_PREFIX: string; INITIAL_MEMORY: number; pg_extensions: Record>; _pgl_initdb: () => number; _pgl_backend: () => void; _pgl_shutdown: () => void; _interactive_write: (msgLength: number) => void; _interactive_one: (length: number, peek: number) => void; _set_read_write_cbs: (read_cb: number, write_cb: number) => void; addFunction: (cb: (ptr: any, length: number) => void, signature: string) => number; removeFunction: (f: number) => void; } type DumpTarCompressionOptions = 'none' | 'gzip' | 'auto'; /** * Filesystem interface. * All virtual filesystems that are compatible with PGlite must implement * this interface. */ interface Filesystem { /** * Initiate the filesystem and return the options to pass to the emscripten module. */ init(pg: PGlite, emscriptenOptions: Partial): Promise<{ emscriptenOpts: Partial; }>; /** * Sync the filesystem to any underlying storage. */ syncToFs(relaxedDurability?: boolean): Promise; /** * Sync the filesystem from any underlying storage. */ initialSyncFs(): Promise; /** * Dump the PGDATA dir from the filesystem to a gzipped tarball. */ dumpTar(dbname: string, compression?: DumpTarCompressionOptions): Promise; /** * Close the filesystem. */ closeFs(): Promise; } /** * Base class for all emscripten built-in filesystems. */ type DebugLevel = 0 | 1 | 2 | 3 | 4 | 5; type RowMode = 'array' | 'object'; interface ParserOptions { [pgType: number]: (value: string) => any; } interface SerializerOptions { [pgType: number]: (value: any) => string; } interface QueryOptions { rowMode?: RowMode; parsers?: ParserOptions; serializers?: SerializerOptions; blob?: Blob | File; onNotice?: (notice: NoticeMessage) => void; paramTypes?: number[]; } interface ExecProtocolOptions { syncToFs?: boolean; throwOnError?: boolean; onNotice?: (notice: NoticeMessage) => void; } interface ExtensionSetupResult { emscriptenOpts?: any; namespaceObj?: TNamespace; bundlePath?: URL; init?: () => Promise; close?: () => Promise; } type ExtensionSetup = (pg: PGliteInterface, emscriptenOpts: any, clientOnly?: boolean) => Promise>; interface Extension { name: string; setup: ExtensionSetup; } type ExtensionNamespace = T extends Extension ? TNamespace : any; type Extensions = { [namespace: string]: Extension | URL; }; type InitializedExtensions = { [K in keyof TExtensions]: ExtensionNamespace }; interface ExecProtocolResult { messages: BackendMessage[]; data: Uint8Array; } interface PGliteOptions { dataDir?: string; username?: string; database?: string; fs?: Filesystem; debug?: DebugLevel; relaxedDurability?: boolean; extensions?: TExtensions; loadDataDir?: Blob | File; initialMemory?: number; wasmModule?: WebAssembly.Module; fsBundle?: Blob | File; parsers?: ParserOptions; serializers?: SerializerOptions; } type PGliteInterface = InitializedExtensions & { readonly waitReady: Promise; readonly debug: DebugLevel; readonly ready: boolean; readonly closed: boolean; close(): Promise; query(query: string, params?: any[], options?: QueryOptions): Promise>; sql(sqlStrings: TemplateStringsArray, ...params: any[]): Promise>; exec(query: string, options?: QueryOptions): Promise>; describeQuery(query: string): Promise; transaction(callback: (tx: Transaction) => Promise): Promise; execProtocolRaw(message: Uint8Array, options?: ExecProtocolOptions): Promise; execProtocol(message: Uint8Array, options?: ExecProtocolOptions): Promise; runExclusive(fn: () => Promise): Promise; listen(channel: string, callback: (payload: string) => void, tx?: Transaction): Promise<(tx?: Transaction) => Promise>; unlisten(channel: string, callback?: (payload: string) => void, tx?: Transaction): Promise; onNotification(callback: (channel: string, payload: string) => void): () => void; offNotification(callback: (channel: string, payload: string) => void): void; dumpDataDir(compression?: DumpTarCompressionOptions): Promise; refreshArrayTypes(): Promise; }; type PGliteInterfaceExtensions = E extends Extensions ? { [K in keyof E]: E[K] extends Extension ? Awaited>['namespaceObj'] extends infer N ? N extends undefined | null | void ? never : N : never : never } : Record; type Row = T; type Results = { rows: Row[]; affectedRows?: number; fields: { name: string; dataTypeID: number; }[]; blob?: Blob; }; interface Transaction { query(query: string, params?: any[], options?: QueryOptions): Promise>; sql(sqlStrings: TemplateStringsArray, ...params: any[]): Promise>; exec(query: string, options?: QueryOptions): Promise>; rollback(): Promise; listen(channel: string, callback: (payload: string) => void): Promise<(tx?: Transaction) => Promise>; get closed(): boolean; } type DescribeQueryResult = { queryParams: { dataTypeID: number; serializer: Serializer; }[]; resultFields: { name: string; dataTypeID: number; parser: Parser; }[]; }; type Parser = (x: string, typeId?: number) => any; type Serializer = (x: any) => string; declare abstract class BasePGlite implements Pick { #private; serializers: Record; parsers: Record; abstract debug: DebugLevel; /** * Execute a postgres wire protocol message * @param message The postgres wire protocol message to execute * @returns The result of the query */ abstract execProtocol(message: Uint8Array, { syncToFs, onNotice }: ExecProtocolOptions): Promise; /** * Execute a postgres wire protocol message * @param message The postgres wire protocol message to execute * @returns The parsed results of the query */ abstract execProtocolStream(message: Uint8Array, { syncToFs, onNotice }: ExecProtocolOptions): Promise; /** * Execute a postgres wire protocol message directly without wrapping the response. * Only use if `execProtocol()` doesn't suite your needs. * * **Warning:** This bypasses PGlite's protocol wrappers that manage error/notice messages, * transactions, and notification listeners. Only use if you need to bypass these wrappers and * don't intend to use the above features. * * @param message The postgres wire protocol message to execute * @returns The direct message data response produced by Postgres */ abstract execProtocolRaw(message: Uint8Array, { syncToFs }: ExecProtocolOptions): Promise; /** * Sync the database to the filesystem * @returns Promise that resolves when the database is synced to the filesystem */ abstract syncToFs(): Promise; /** * Handle a file attached to the current query * @param file The file to handle */ abstract _handleBlob(blob?: File | Blob): Promise; /** * Get the written file */ abstract _getWrittenBlob(): Promise; /** * Cleanup the current file */ abstract _cleanupBlob(): Promise; abstract _checkReady(): Promise; abstract _runExclusiveQuery(fn: () => Promise): Promise; abstract _runExclusiveTransaction(fn: () => Promise): Promise; /** * Listen for notifications on a channel */ abstract listen(channel: string, callback: (payload: string) => void, tx?: Transaction): Promise<(tx?: Transaction) => Promise>; /** * Initialize the array types * The oid if the type of an element and the typarray is the oid of the type of the * array. * We extract these from the database then create the serializers/parsers for * each type. * This should be called at the end of #init() in the implementing class. */ _initArrayTypes({ force }?: { force?: boolean | undefined; }): Promise; /** * Re-syncs the array types from the database * This is useful if you add a new type to the database and want to use it, otherwise pglite won't recognize it. */ refreshArrayTypes(): Promise; /** * Execute a single SQL statement * This uses the "Extended Query" postgres wire protocol message. * @param query The query to execute * @param params Optional parameters for the query * @returns The result of the query */ query(query: string, params?: any[], options?: QueryOptions): Promise>; /** * Execute a single SQL statement like with {@link PGlite.query}, but with a * templated statement where template values will be treated as parameters. * * You can use helpers from `/template` to further format the query with * identifiers, raw SQL, and nested statements. * * This uses the "Extended Query" postgres wire protocol message. * * @param query The query to execute with parameters as template values * @returns The result of the query * * @example * ```ts * const results = await db.sql`SELECT * FROM ${identifier`foo`} WHERE id = ${id}` * ``` */ sql(sqlStrings: TemplateStringsArray, ...params: any[]): Promise>; /** * Execute a SQL query, this can have multiple statements. * This uses the "Simple Query" postgres wire protocol message. * @param query The query to execute * @returns The result of the query */ exec(query: string, options?: QueryOptions): Promise>; /** * Describe a query * @param query The query to describe * @returns A description of the result types for the query */ describeQuery(query: string, options?: QueryOptions): Promise; /** * Execute a transaction * @param callback A callback function that takes a transaction object * @returns The result of the transaction */ transaction(callback: (tx: Transaction) => Promise): Promise; /** * Run a function exclusively, no other transactions or queries will be allowed * while the function is running. * This is useful when working with the execProtocol methods as they are not blocked, * and do not block the locks used by transactions and queries. * @param fn The function to run * @returns The result of the function */ runExclusive(fn: () => Promise): Promise; } declare class PGlite extends BasePGlite implements PGliteInterface, AsyncDisposable { #private; fs?: Filesystem; protected mod?: PostgresMod; readonly dataDir?: string; readonly waitReady: Promise; readonly debug: DebugLevel; static readonly DEFAULT_RECV_BUF_SIZE: number; static readonly MAX_BUFFER_SIZE: number; /** * Create a new PGlite instance * @param dataDir The directory to store the database files * Prefix with idb:// to use indexeddb filesystem in the browser * Use memory:// to use in-memory filesystem * @param options PGlite options */ constructor(dataDir?: string, options?: PGliteOptions); /** * Create a new PGlite instance * @param options PGlite options including the data directory */ constructor(options?: PGliteOptions); /** * Create a new PGlite instance with extensions on the Typescript interface * (The main constructor does enable extensions, however due to the limitations * of Typescript, the extensions are not available on the instance interface) * @param options PGlite options including the data directory * @returns A promise that resolves to the PGlite instance when it's ready. */ static create(options?: O): Promise>; /** * Create a new PGlite instance with extensions on the Typescript interface * (The main constructor does enable extensions, however due to the limitations * of Typescript, the extensions are not available on the instance interface) * @param dataDir The directory to store the database files * Prefix with idb:// to use indexeddb filesystem in the browser * Use memory:// to use in-memory filesystem * @param options PGlite options * @returns A promise that resolves to the PGlite instance when it's ready. */ static create(dataDir?: string, options?: O): Promise>; /** * The Postgres Emscripten Module */ get Module(): PostgresMod; /** * The ready state of the database */ get ready(): boolean; /** * The closed state of the database */ get closed(): boolean; /** * Close the database * @returns A promise that resolves when the database is closed */ close(): Promise; /** * Close the database when the object exits scope * Stage 3 ECMAScript Explicit Resource Management * https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management */ [Symbol.asyncDispose](): Promise; /** * Handle a file attached to the current query * @param file The file to handle */ _handleBlob(blob?: File | Blob): Promise; /** * Cleanup the current file */ _cleanupBlob(): Promise; /** * Get the written blob from the current query * @returns The written blob */ _getWrittenBlob(): Promise; /** * Wait for the database to be ready */ _checkReady(): Promise; /** * Execute a postgres wire protocol synchronously * @param message The postgres wire protocol message to execute * @returns The direct message data response produced by Postgres */ execProtocolRawSync(message: Uint8Array): Uint8Array; /** * Execute a postgres wire protocol message directly without wrapping the response. * Only use if `execProtocol()` doesn't suite your needs. * * **Warning:** This bypasses PGlite's protocol wrappers that manage error/notice messages, * transactions, and notification listeners. Only use if you need to bypass these wrappers and * don't intend to use the above features. * * @param message The postgres wire protocol message to execute * @returns The direct message data response produced by Postgres */ execProtocolRaw(message: Uint8Array, { syncToFs }?: ExecProtocolOptions): Promise; /** * Execute a postgres wire protocol message * @param message The postgres wire protocol message to execute * @returns The result of the query */ execProtocol(message: Uint8Array, { syncToFs, throwOnError, onNotice }?: ExecProtocolOptions): Promise; /** * Execute a postgres wire protocol message * @param message The postgres wire protocol message to execute * @returns The parsed results of the query */ execProtocolStream(message: Uint8Array, { syncToFs, throwOnError, onNotice }?: ExecProtocolOptions): Promise; /** * Check if the database is in a transaction * @returns True if the database is in a transaction, false otherwise */ isInTransaction(): boolean; /** * Perform any sync operations implemented by the filesystem, this is * run after every query to ensure that the filesystem is synced. */ syncToFs(): Promise; /** * Listen for a notification * @param channel The channel to listen on * @param callback The callback to call when a notification is received */ listen(channel: string, callback: (payload: string) => void, tx?: Transaction): Promise<(tx?: Transaction) => Promise>; /** * Stop listening for a notification * @param channel The channel to stop listening on * @param callback The callback to remove */ unlisten(channel: string, callback?: (payload: string) => void, tx?: Transaction): Promise; /** * Listen to notifications * @param callback The callback to call when a notification is received */ onNotification(callback: (channel: string, payload: string) => void): () => void; /** * Stop listening to notifications * @param callback The callback to remove */ offNotification(callback: (channel: string, payload: string) => void): void; /** * Dump the PGDATA dir from the filesystem to a gzipped tarball. * @param compression The compression options to use - 'gzip', 'auto', 'none' * @returns The tarball as a File object where available, and fallback to a Blob */ dumpDataDir(compression?: DumpTarCompressionOptions): Promise; /** * Run a function in a mutex that's exclusive to queries * @param fn The query to run * @returns The result of the query */ _runExclusiveQuery(fn: () => Promise): Promise; /** * Run a function in a mutex that's exclusive to transactions * @param fn The function to run * @returns The result of the function */ _runExclusiveTransaction(fn: () => Promise): Promise; clone(): Promise; _runExclusiveListen(fn: () => Promise): Promise; } //#endregion //#region ../../node_modules/.pnpm/@electric-sql+pglite@0.3.15/node_modules/@electric-sql/pglite/dist/live/index.d.ts interface LiveQueryOptions { query: string; params?: any[] | null; offset?: number; limit?: number; callback?: (results: Results) => void; signal?: AbortSignal; } interface LiveChangesOptions { query: string; params?: any[] | null; key: string; callback?: (changes: Array>) => void; signal?: AbortSignal; } interface LiveIncrementalQueryOptions { query: string; params?: any[] | null; key: string; callback?: (results: Results) => void; signal?: AbortSignal; } interface LiveNamespace { /** * Create a live query * @param query - The query to run * @param params - The parameters to pass to the query * @param callback - A callback to run when the query is updated * @returns A promise that resolves to an object with the initial results, * an unsubscribe function, and a refresh function */ query(query: string, params?: any[] | null, callback?: (results: Results) => void): Promise>; /** * Create a live query * @param options - The options to pass to the query * @returns A promise that resolves to an object with the initial results, * an unsubscribe function, and a refresh function */ query(options: LiveQueryOptions): Promise>; /** * Create a live query that returns the changes to the query results * @param query - The query to run * @param params - The parameters to pass to the query * @param callback - A callback to run when the query is updated * @returns A promise that resolves to an object with the initial changes, * an unsubscribe function, and a refresh function */ changes(query: string, params: any[] | undefined | null, key: string, callback?: (changes: Array>) => void): Promise>; /** * Create a live query that returns the changes to the query results * @param options - The options to pass to the query * @returns A promise that resolves to an object with the initial changes, * an unsubscribe function, and a refresh function */ changes(options: LiveChangesOptions): Promise>; /** * Create a live query with incremental updates * @param query - The query to run * @param params - The parameters to pass to the query * @param callback - A callback to run when the query is updated * @returns A promise that resolves to an object with the initial results, * an unsubscribe function, and a refresh function */ incrementalQuery(query: string, params: any[] | undefined | null, key: string, callback?: (results: Results) => void): Promise>; /** * Create a live query with incremental updates * @param options - The options to pass to the query * @returns A promise that resolves to an object with the initial results, * an unsubscribe function, and a refresh function */ incrementalQuery(options: LiveIncrementalQueryOptions): Promise>; } interface LiveQueryResults extends Results { totalCount?: number; offset?: number; limit?: number; } interface LiveQuery { initialResults: LiveQueryResults; subscribe: (callback: (results: LiveQueryResults) => void) => void; unsubscribe: (callback?: (results: LiveQueryResults) => void) => Promise; refresh: (options?: { offset?: number; limit?: number; }) => Promise; } interface LiveChanges { fields: { name: string; dataTypeID: number; }[]; initialChanges: Array>; subscribe: (callback: (changes: Array>) => void) => void; unsubscribe: (callback?: (changes: Array>) => void) => Promise; refresh: () => Promise; } type ChangeInsert = { __changed_columns__: string[]; __op__: 'INSERT'; __after__: number; } & T; type ChangeDelete = { __changed_columns__: string[]; __op__: 'DELETE'; __after__: undefined; } & T; type ChangeUpdate = { __changed_columns__: string[]; __op__: 'UPDATE'; __after__: number; } & T; type ChangeReset = { __op__: 'RESET'; } & T; type Change = ChangeInsert | ChangeDelete | ChangeUpdate | ChangeReset; type PGliteWithLive = PGliteInterface & { live: LiveNamespace; }; //#endregion //#region src/relational/hooks/useRelationalDb.d.ts type RelationalDbWithLive = IRelationalDb & { live: LiveNamespace; }; interface IRelationalDbState { db: RelationalDbWithLive | null; isLoading: boolean; error: Error | null; } declare const useRelationalDb: () => IRelationalDbState; //#endregion //#region src/relational/hooks/useRelationalQuery.d.ts type QueryCallbackReturnType$1 = { sql: string; parameters?: readonly unknown[]; }; type useRelationalQueryOptions$1 = { hashNamespace?: boolean; }; declare function useRelationalQuery(ProcessorClass: RelationalDbProcessorClass, driveId: string, queryCallback: (db: IRelationalQueryBuilder, parameters?: TParams) => QueryCallbackReturnType$1, parameters?: TParams, _options?: useRelationalQueryOptions$1): { readonly isLoading: boolean; readonly error: Error | null; readonly result: LiveQueryResults | null; }; //#endregion //#region src/relational/utils/createProcessorQuery.d.ts declare function createProcessorQuery(ProcessorClass: RelationalDbProcessorClass): { ) => QueryCallbackReturnType>(driveId: string, queryCallback: TQueryBuilder): { isLoading: boolean; error: Error | null; result: LiveQueryResults extends CompiledQuery ? R : any> | null; }; , parameters: TParams) => QueryCallbackReturnType>(driveId: string, queryCallback: TQueryBuilder, parameters: TParams, options?: useRelationalQueryOptions): { isLoading: boolean; error: Error | null; result: LiveQueryResults extends CompiledQuery ? R : any> | null; }; }; //#endregion export { type RelationalDbWithLive as a, type PGlite as c, type useRelationalQueryOptions$1 as i, type QueryCallbackReturnType$1 as n, type useRelationalDb as o, type useRelationalQuery as r, type PGliteWithLive as s, createProcessorQuery as t }; //# sourceMappingURL=index-ZltD7u5Z.d.ts.map