declare module 'nimbus-types' { interface NimbusPlugins { LdsSqliteStore: SqliteStorePlugin; } } import type { SqliteResult, SqliteType } from '@salesforce/lds-store-sql'; /** * A plugin interface that is backed by a sqlite database and * used by a `SqliteStore`. */ export interface SqliteStorePlugin { /** * @see SqliteStore.query */ query(sql: string, params: SqliteType[], onResult: (result: SqliteResult) => void, onError: (message: string) => void): Promise; /** * Perform a set of operations on the underlying database. */ batchOperations(operations: SqliteOperation[], onCompletion: (error: string | null) => void): Promise; /** * Setup a listener to be notified of changes to the Durable Store * * @param listener callback taking an array of store changes * @returns {Promise} a generated id of the listener to unsubscribe with */ registerOnChangedListener(listener: (changes: SqliteStoreChange[]) => void): Promise; /** * * @param id the identifier given from registerOnChangedListener */ unsubscribeOnChangedListener(id: string): Promise; } /** * An operation to perform on the database. */ interface SqliteOperationBase { table: 'lds_data' | 'lds_internal' | 'lds_env_drafts' | 'lds_env_draft_id_map' | 'lds_one_store_data'; keyColumn: string; context: SqliteOperationContext; } /** * An upsert attempts to insert rows into the database. If * there is a primary key or unique constraint violation it * can attempt to update the existing rows. * * ex: * ```javascript * let operation = { * type: "upsert", * table: "luvio_internal", * columns: ["key", "namespace", "data", "metadata"], * keyColumn: "key", * conflictColumns: ["key", "namespace"], * rows: [ * ["001002003004005001", "ADAPTER_CONTEXT", "{'a': 1, 'b': 2}", "{}"], * ["001002003004005002", "ADAPTER_CONTEXT", "{'a': 3, 'b': 5}", "{}"] * ], * context: { * segment: "ADAPTER_CONTEXT" * } * } * ``` * * ```sql * insert into luvio_internal (key, namespace, data, metadata) * values (?, ?, ?, ?) * on conflict (key, namespace) do * update set value = excluded.value, metada = excluded.metadata * ``` */ interface SqliteUpsert extends SqliteOperationBase { type: 'upsert'; conflictColumns: string[]; columns: string[]; rows: SqliteType[][]; } /** * Delete rows from the database. * * ex: * ```javascript * let operation = { * type: "delete", * table: "luvio_data", * keyColumn: "key", * ids: ["001002003004005001", "001002003004005002"], * context: { * segment: "DEFAULT" * } * } * ``` * * ```sql * delete from luvio_data where key in ("001002003004005001", "001002003004005002") * ``` */ interface SqliteDelete extends SqliteOperationBase { type: 'delete'; ids: string[]; } interface SqliteUpdate extends SqliteOperationBase { type: 'update'; columns: string[]; values: Record; segment?: string; } export type SqliteOperation = SqliteDelete | SqliteUpsert | SqliteUpdate; export declare function isUpsertOperation(operation: SqliteOperation): operation is SqliteUpsert; export declare function isUpdateOperation(operation: SqliteOperation): operation is SqliteUpdate; /** * Operations can pass any context object along with the operation. * This context is opaque to the plugin and will be included in any * change notifications generated from the operation. */ export type SqliteOperationContext = { [s: string]: SqliteType; }; /** * A change from the underlying sqlite database triggered by executing a set of operations. * * Example: * * The following operation: * * ```javascript * let operation = { * type: "delete", * table: "luvio_data", * keyColumn: "key", * ids: ["001", "002"], * context: { * segment: "DEFAULT" * } * } * ``` * * should trigger the following change: * ```javascript * { * type: "delete", * table: "luvio_data", * keys: ["001", "002"], * context: { * segment: "DEFAULT" * } * } * ``` */ export interface SqliteStoreChange { type: SqliteOperation['type']; table: string; keys: SqliteType[]; context: SqliteOperationContext; } export declare const sortedSchemaMigrations: Array<{ version: number; sql: string; }>; export {};