UNPKG

sqljs-documentstore

Version:

Minimal, encrypted, sql friendly typed document store, with support for indexed columns. Protects against transactional conflicts

32 lines (31 loc) 1.42 kB
import * as sqlite from 'sql.js'; export interface EncryptedDataItem { salt: Uint8Array; iv: Uint8Array; data: Uint8Array; } export declare namespace sqljsPersistence { function save(dbName: string, key: CryptoKey, db: Pick<sqlite.Database, 'export'>): Promise<void>; function load(dbName: string, passPhrase: string, sqlJsStatic: sqlite.SqlJsStatic): Promise<{ database: sqlite.Database; key: CryptoKey; }>; } export declare namespace sqljsHelpers { function query<T>(db: Pick<sqlite.Database, 'exec'>, sql: string, params?: any[]): T[]; function exec(db: Pick<sqlite.Database, 'exec'>, sql: string, params?: any[]): sqlite.QueryExecResult[]; function run(db: Pick<sqlite.Database, 'run'>, sql: string, params?: any[]): void; function isTable(db: Pick<sqlite.Database, 'exec'>, table: string): boolean; function sanitizeParams(params: any[]): sqlite.SqlValue[]; } export declare namespace cryptoHelpers { function getKey(passphrase: string, salt?: Uint8Array): Promise<{ key: CryptoKey; salt: Uint8Array; }>; function encrypt(key: CryptoKey, salt: Uint8Array, data: Uint8Array): Promise<EncryptedDataItem>; function decrypt(key: CryptoKey, iv: BufferSource, encryptedData: BufferSource): Promise<ArrayBuffer>; } export declare namespace flushHelpers { function createAsyncFlushQueue(saveFn: () => Promise<void>): () => void; }