Merge 'fix encryption config in the sync-client' from Nikita Sivukhin

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3379
This commit is contained in:
Preston Thorpe
2025-09-26 19:01:27 -04:00
committed by GitHub
9 changed files with 136 additions and 90 deletions

View File

@@ -1,5 +1,5 @@
import { run, memoryIO, SyncEngineGuards } from "./run.js"
import { DatabaseOpts, ProtocolIo, RunOpts, DatabaseRowMutation, DatabaseRowStatement, DatabaseRowTransformResult, DatabaseStats, DatabaseChangeType } from "./types.js"
import { DatabaseOpts, ProtocolIo, RunOpts, DatabaseRowMutation, DatabaseRowStatement, DatabaseRowTransformResult, DatabaseStats, DatabaseChangeType, EncryptionOpts } from "./types.js"
export { run, memoryIO, SyncEngineGuards }
export type {
@@ -9,6 +9,7 @@ export type {
DatabaseRowMutation,
DatabaseRowStatement,
DatabaseRowTransformResult,
EncryptionOpts,
ProtocolIo,
RunOpts,

View File

@@ -56,6 +56,13 @@ export interface DatabaseRowMutation {
}
export type Transform = (arg: DatabaseRowMutation) => DatabaseRowTransformResult;
export interface EncryptionOpts {
// base64 encoded encryption key (must be either 16 or 32 bytes depending on the cipher)
key: string,
// encryption cipher algorithm
cipher: 'aes256gcm' | 'aes128gcm' | 'chacha20poly1305'
}
export interface DatabaseOpts {
/**
* local path where to store all synced database files (e.g. local.db)
@@ -79,9 +86,9 @@ export interface DatabaseOpts {
*/
clientName?: string;
/**
* optional key if cloud database were encrypted by default
* optional encryption parameters if cloud database were encrypted by default
*/
encryptionKey?: string;
encryption?: EncryptionOpts;
/**
* optional callback which will be called for every mutation before sending it to the remote
* this callback can transform the update in order to support complex conflict resolution strategy