local-lite 0.0.14 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ import { type EncryptedBackupOptions, type RestoreEncryptedBackupOptions } from './encryption.js';
2
+ import type { CloudBackupFile } from './cloud-storage.js';
3
+ export type BackupAccessTokenProvider = () => Promise<string>;
4
+ export interface BackupDatabase {
5
+ exportDatabase(): Promise<Uint8Array>;
6
+ importDatabase(data: Uint8Array): Promise<void>;
7
+ }
8
+ export interface BackupStorage {
9
+ save(fileName: string, data: Uint8Array): Promise<void>;
10
+ read(fileName: string): Promise<Uint8Array>;
11
+ list?(): Promise<CloudBackupFile[]>;
12
+ delete?(fileName: string): Promise<void>;
13
+ }
14
+ export interface CloudBackupClient extends BackupStorage {
15
+ connect(): Promise<boolean>;
16
+ disconnect(): Promise<void>;
17
+ isConnected(): Promise<boolean>;
18
+ list(): Promise<CloudBackupFile[]>;
19
+ deleteBackup?(fileIdOrName: string): Promise<void>;
20
+ onStatusChange?(listener: (connected: boolean) => void): () => void;
21
+ backup?(database: ResolvableBackupDatabase, options?: CreateDatabaseBackupOptions & Partial<EncryptedBackupOptions>): Promise<string>;
22
+ restore?(database: ResolvableBackupDatabase, fileNameOrId: string, options?: Partial<RestoreEncryptedBackupOptions>): Promise<void>;
23
+ }
24
+ export interface CreateDatabaseBackupOptions {
25
+ fileName?: string;
26
+ }
27
+ export type ResolvableBackupDatabase = BackupDatabase | {
28
+ exportDatabase(): Promise<Uint8Array>;
29
+ importDatabase(data: Uint8Array): Promise<void>;
30
+ } | {
31
+ db: any;
32
+ exportDatabase?(): Promise<Uint8Array>;
33
+ importDatabase?(data: Uint8Array): Promise<void>;
34
+ };
35
+ export declare function resolveBackupDatabase(target: any): BackupDatabase;
36
+ export declare function createDatabaseBackup(database: ResolvableBackupDatabase, storage: BackupStorage, options?: CreateDatabaseBackupOptions): Promise<string>;
37
+ export declare function restoreDatabaseBackup(database: ResolvableBackupDatabase, storage: BackupStorage, fileName: string): Promise<void>;
38
+ export declare function performBackup(database: ResolvableBackupDatabase, storage: BackupStorage, options?: CreateDatabaseBackupOptions & Partial<EncryptedBackupOptions>): Promise<string>;
39
+ export declare function performRestore(database: ResolvableBackupDatabase, storage: BackupStorage, fileNameOrId: string, options?: Partial<RestoreEncryptedBackupOptions>): Promise<void>;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveBackupDatabase = resolveBackupDatabase;
4
+ exports.createDatabaseBackup = createDatabaseBackup;
5
+ exports.restoreDatabaseBackup = restoreDatabaseBackup;
6
+ exports.performBackup = performBackup;
7
+ exports.performRestore = performRestore;
8
+ const encryption_js_1 = require("./encryption.js");
9
+ function resolveBackupDatabase(target) {
10
+ if (!target) {
11
+ throw new Error('A valid database or LocalFirstClient is required for backup.');
12
+ }
13
+ if (typeof target.exportDatabase === 'function' && typeof target.importDatabase === 'function') {
14
+ return target;
15
+ }
16
+ if (target.db &&
17
+ typeof target.db.exportDatabase === 'function' &&
18
+ typeof target.db.importDatabase === 'function') {
19
+ return target.db;
20
+ }
21
+ throw new Error('Provided target does not implement BackupDatabase. It must provide exportDatabase() and importDatabase().');
22
+ }
23
+ function validateFileName(fileName) {
24
+ if (!fileName || /[\\/]/.test(fileName)) {
25
+ throw new Error('Backup file name must be a single file name.');
26
+ }
27
+ }
28
+ async function createDatabaseBackup(database, storage, options = {}) {
29
+ const resolved = resolveBackupDatabase(database);
30
+ const fileName = options.fileName ?? `local-lite-${new Date().toISOString().replace(/[:.]/g, '-')}.db`;
31
+ validateFileName(fileName);
32
+ const databaseBytes = await resolved.exportDatabase();
33
+ if (databaseBytes.length === 0) {
34
+ throw new Error('Cannot create a backup from an empty database.');
35
+ }
36
+ await storage.save(fileName, databaseBytes);
37
+ return fileName;
38
+ }
39
+ async function restoreDatabaseBackup(database, storage, fileName) {
40
+ validateFileName(fileName);
41
+ const resolved = resolveBackupDatabase(database);
42
+ const databaseBytes = await storage.read(fileName);
43
+ if (databaseBytes.length === 0) {
44
+ throw new Error('Cannot restore an empty database backup.');
45
+ }
46
+ await resolved.importDatabase(databaseBytes);
47
+ }
48
+ async function performBackup(database, storage, options = {}) {
49
+ const resolved = resolveBackupDatabase(database);
50
+ if (options.passphrase && options.passphrase.trim()) {
51
+ return (0, encryption_js_1.createEncryptedDatabaseBackup)(resolved, storage, {
52
+ passphrase: options.passphrase,
53
+ fileName: options.fileName,
54
+ iterations: options.iterations,
55
+ });
56
+ }
57
+ return createDatabaseBackup(resolved, storage, options);
58
+ }
59
+ async function performRestore(database, storage, fileNameOrId, options = {}) {
60
+ const resolved = resolveBackupDatabase(database);
61
+ if (options.passphrase && options.passphrase.trim()) {
62
+ return (0, encryption_js_1.restoreEncryptedDatabaseBackup)(resolved, storage, fileNameOrId, {
63
+ passphrase: options.passphrase,
64
+ });
65
+ }
66
+ const rawBytes = await storage.read(fileNameOrId);
67
+ if ((0, encryption_js_1.isEncryptedBackup)(rawBytes)) {
68
+ throw new Error('This backup is encrypted. A passphrase is required to restore it.');
69
+ }
70
+ if (rawBytes.length === 0) {
71
+ throw new Error('Cannot restore an empty database backup.');
72
+ }
73
+ await resolved.importDatabase(rawBytes);
74
+ }
@@ -46,7 +46,6 @@ async function resolveRemoteAdapter(config) {
46
46
  updatedAtColumn: config.supabase?.updatedAtColumn,
47
47
  deletedColumn: config.supabase?.deletedColumn,
48
48
  deletedValue: config.supabase?.deletedValue,
49
- deletedAtColumn: config.supabase?.deletedAtColumn,
50
49
  pushRpcName: config.supabase?.pushRpcName,
51
50
  channelName: config.supabase?.channelName,
52
51
  scopedTables: config.supabase?.scopedTables,
@@ -7,6 +7,8 @@ import { SchemaManager } from './schema-manager.js';
7
7
  import { BatchMutation, ConflictResolver, ConflictStrategy, MutateOptions, NetworkStatusProvider, OutboxRecord, OutboxStatus, QueryOptions, RetryConfig, SyncMetrics, SyncOp, TableChangeEvent, WhereFilter } from './types.js';
8
8
  import { SyncLogger, CustomLogger, LogLevel } from '../utils/logger.js';
9
9
  import { QueryBuilder, AggregateSpec, AggregateResult } from './query-builder.js';
10
+ import { type ExportJsonOptions, type ImportJsonOptions, type ExportCsvOptions, type ImportCsvOptions, type ImportSummary } from '../utils/portability.js';
11
+ import { type BackupStorage, type CreateDatabaseBackupOptions, type EncryptedBackupOptions, type RestoreEncryptedBackupOptions } from '../backups/index.js';
10
12
  export interface LocalFirstClientConfig {
11
13
  local: LocalDBAdapter;
12
14
  remote: RemoteDBAdapter;
@@ -62,6 +64,10 @@ export declare class TransactionalClient {
62
64
  includeDeleted?: boolean;
63
65
  }): Promise<T[]>;
64
66
  findMany<T = any>(tableName: string, options?: QueryOptions): Promise<T[]>;
67
+ /**
68
+ * Alias for findMany().
69
+ */
70
+ find<T = any>(tableName: string, options?: QueryOptions): Promise<T[]>;
65
71
  query<T = any>(sql: string, params?: any[]): Promise<T[]>;
66
72
  from<T = any>(tableName: string): QueryBuilder<T>;
67
73
  get rawTx(): LocalTransaction;
@@ -227,6 +233,32 @@ export declare class LocalFirstClient {
227
233
  */
228
234
  aggregate(tableName: string, spec: AggregateSpec): Promise<AggregateResult>;
229
235
  findMany<T = any>(tableName: string, options?: QueryOptions): Promise<T[]>;
236
+ /**
237
+ * Alias for findMany().
238
+ */
239
+ find<T = any>(tableName: string, options?: QueryOptions): Promise<T[]>;
240
+ /**
241
+ * Returns true if client storage has successfully initialized.
242
+ */
243
+ get isReady(): boolean;
244
+ /**
245
+ * Convenience export of tables to JSON.
246
+ */
247
+ exportToJson(tables?: string[], options?: ExportJsonOptions): Promise<string>;
248
+ /**
249
+ * Convenience import of tables from JSON.
250
+ */
251
+ importFromJson(jsonString: string, options?: ImportJsonOptions): Promise<ImportSummary>;
252
+ /**
253
+ * Convenience export of a table to RFC-4180 CSV.
254
+ */
255
+ exportToCsv(tableName: string, options?: ExportCsvOptions): Promise<string>;
256
+ /**
257
+ * Convenience import of RFC-4180 CSV into a table.
258
+ */
259
+ importFromCsv(tableName: string, csvString: string, options?: ImportCsvOptions): Promise<{
260
+ rowCount: number;
261
+ }>;
230
262
  /**
231
263
  * Finds a single record by primary key.
232
264
  *
@@ -294,4 +326,23 @@ export declare class LocalFirstClient {
294
326
  reset(options?: {
295
327
  dropTables?: boolean;
296
328
  }): Promise<void>;
329
+ private getAllTableNames;
330
+ /**
331
+ * Exports the entire local database state as a portable binary snapshot.
332
+ * If the local adapter has a native export mechanism (e.g. serialize or export),
333
+ * it uses that; otherwise, it exports an atomic JSON snapshot of all tables.
334
+ */
335
+ exportDatabase(): Promise<Uint8Array>;
336
+ /**
337
+ * Imports database state from a backup snapshot.
338
+ */
339
+ importDatabase(data: Uint8Array): Promise<void>;
340
+ /**
341
+ * Creates a backup directly from this client to the given cloud or local storage.
342
+ */
343
+ backup(storage: BackupStorage, options?: CreateDatabaseBackupOptions & Partial<EncryptedBackupOptions>): Promise<string>;
344
+ /**
345
+ * Restores this client's database from a backup in cloud or local storage.
346
+ */
347
+ restore(storage: BackupStorage, fileNameOrId: string, options?: Partial<RestoreEncryptedBackupOptions>): Promise<void>;
297
348
  }
@@ -12,6 +12,8 @@ const uuid_js_1 = require("../utils/uuid.js");
12
12
  const sql_js_1 = require("../utils/sql.js");
13
13
  const query_js_1 = require("./query.js");
14
14
  const query_builder_js_1 = require("./query-builder.js");
15
+ const portability_js_1 = require("../utils/portability.js");
16
+ const index_js_1 = require("../backups/index.js");
15
17
  function hasFunctionFilter(value) {
16
18
  if (typeof value === 'function')
17
19
  return true;
@@ -133,6 +135,12 @@ class TransactionalClient {
133
135
  }
134
136
  return this.from(tableName).applyOptions(options).execute();
135
137
  }
138
+ /**
139
+ * Alias for findMany().
140
+ */
141
+ async find(tableName, options) {
142
+ return this.findMany(tableName, options);
143
+ }
136
144
  async query(sql, params = []) {
137
145
  return (await this.tx.execute(sql, params));
138
146
  }
@@ -715,6 +723,42 @@ class LocalFirstClient {
715
723
  }
716
724
  return this.from(tableName).applyOptions(options).execute();
717
725
  }
726
+ /**
727
+ * Alias for findMany().
728
+ */
729
+ async find(tableName, options) {
730
+ return this.findMany(tableName, options);
731
+ }
732
+ /**
733
+ * Returns true if client storage has successfully initialized.
734
+ */
735
+ get isReady() {
736
+ return Boolean(this.initialization);
737
+ }
738
+ /**
739
+ * Convenience export of tables to JSON.
740
+ */
741
+ async exportToJson(tables, options) {
742
+ return (0, portability_js_1.exportTablesToJson)(this, tables, options);
743
+ }
744
+ /**
745
+ * Convenience import of tables from JSON.
746
+ */
747
+ async importFromJson(jsonString, options) {
748
+ return (0, portability_js_1.importTablesFromJson)(this, jsonString, options);
749
+ }
750
+ /**
751
+ * Convenience export of a table to RFC-4180 CSV.
752
+ */
753
+ async exportToCsv(tableName, options) {
754
+ return (0, portability_js_1.exportTableToCsv)(this, tableName, options);
755
+ }
756
+ /**
757
+ * Convenience import of RFC-4180 CSV into a table.
758
+ */
759
+ async importFromCsv(tableName, csvString, options) {
760
+ return (0, portability_js_1.importTableFromCsv)(this, tableName, csvString, options);
761
+ }
718
762
  /**
719
763
  * Finds a single record by primary key.
720
764
  *
@@ -860,5 +904,150 @@ class LocalFirstClient {
860
904
  await this.resetSyncCursor();
861
905
  this.events.emit('reset', { dropTables: options.dropTables ?? false });
862
906
  }
907
+ async getAllTableNames() {
908
+ const list = new Set(this.tables);
909
+ list.add('sync_outbox');
910
+ list.add('sync_meta');
911
+ try {
912
+ const rows = await this.db.execute(`SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'`);
913
+ if (Array.isArray(rows)) {
914
+ for (const r of rows) {
915
+ if (r.name)
916
+ list.add(r.name);
917
+ }
918
+ }
919
+ }
920
+ catch {
921
+ // Non-SQLite database adapter, fallback to configured tables
922
+ }
923
+ return Array.from(list);
924
+ }
925
+ /**
926
+ * Exports the entire local database state as a portable binary snapshot.
927
+ * If the local adapter has a native export mechanism (e.g. serialize or export),
928
+ * it uses that; otherwise, it exports an atomic JSON snapshot of all tables.
929
+ */
930
+ async exportDatabase() {
931
+ await this.initialize();
932
+ if (typeof this.db.exportDatabase === 'function') {
933
+ return this.db.exportDatabase();
934
+ }
935
+ if (typeof this.db.serialize === 'function') {
936
+ return new Uint8Array(this.db.serialize());
937
+ }
938
+ if (typeof this.db.export === 'function') {
939
+ return new Uint8Array(this.db.export());
940
+ }
941
+ const tables = await this.getAllTableNames();
942
+ const snapshot = {};
943
+ for (const table of tables) {
944
+ const safeTable = (0, sql_js_1.escapeIdentifier)(table);
945
+ try {
946
+ const rows = await this.db.execute(`SELECT * FROM ${safeTable}`);
947
+ snapshot[table] = rows || [];
948
+ }
949
+ catch {
950
+ // Table may not exist yet
951
+ }
952
+ }
953
+ const payload = JSON.stringify({
954
+ format: 'local-lite-backup-v1',
955
+ timestamp: Date.now(),
956
+ tables: snapshot,
957
+ });
958
+ return new TextEncoder().encode(payload);
959
+ }
960
+ /**
961
+ * Imports database state from a backup snapshot.
962
+ */
963
+ async importDatabase(data) {
964
+ if (!data || data.length === 0) {
965
+ throw new Error('Cannot restore an empty database snapshot.');
966
+ }
967
+ await this.initialize();
968
+ if (typeof this.db.importDatabase === 'function') {
969
+ await this.db.importDatabase(data);
970
+ this.schemaManager.clearCache();
971
+ this.events.emit('reset', { dropTables: false });
972
+ return;
973
+ }
974
+ // Check if data is SQLite format (magic header: "SQLite format 3\0")
975
+ const isSqlite = data.length > 16 &&
976
+ data[0] === 0x53 &&
977
+ data[1] === 0x51 &&
978
+ data[2] === 0x4c &&
979
+ data[3] === 0x69 &&
980
+ data[4] === 0x74 &&
981
+ data[5] === 0x65 &&
982
+ data[6] === 0x20 &&
983
+ data[7] === 0x66 &&
984
+ data[8] === 0x6f &&
985
+ data[9] === 0x72 &&
986
+ data[10] === 0x6d &&
987
+ data[11] === 0x61 &&
988
+ data[12] === 0x74 &&
989
+ data[13] === 0x20 &&
990
+ data[14] === 0x33 &&
991
+ data[15] === 0x00;
992
+ if (isSqlite) {
993
+ if (typeof this.db.load === 'function') {
994
+ await this.db.load(data);
995
+ this.schemaManager.clearCache();
996
+ this.events.emit('reset', { dropTables: false });
997
+ return;
998
+ }
999
+ throw new Error('Direct SQLite binary snapshot import requires an adapter with native import/load support (e.g. sql.js).');
1000
+ }
1001
+ // Parse portable JSON backup snapshot
1002
+ try {
1003
+ const text = new TextDecoder().decode(data);
1004
+ const parsed = JSON.parse(text);
1005
+ if (parsed.tables && typeof parsed.tables === 'object') {
1006
+ await this.db.transaction(async (tx) => {
1007
+ for (const [table, rows] of Object.entries(parsed.tables)) {
1008
+ const safeTable = (0, sql_js_1.escapeIdentifier)(table);
1009
+ if (Array.isArray(rows) && rows.length > 0) {
1010
+ await this.schemaManager.ensureTable(tx, table, rows[0]);
1011
+ await tx.execute(`DELETE FROM ${safeTable}`);
1012
+ for (const row of rows) {
1013
+ const cols = Object.keys(row);
1014
+ const safeCols = cols.map(sql_js_1.escapeIdentifier).join(', ');
1015
+ const placeholders = cols.map(() => '?').join(', ');
1016
+ const values = cols.map(c => {
1017
+ const val = row[c];
1018
+ return val !== null && typeof val === 'object' ? JSON.stringify(val) : val;
1019
+ });
1020
+ await tx.execute(`INSERT INTO ${safeTable} (${safeCols}) VALUES (${placeholders})`, values);
1021
+ }
1022
+ }
1023
+ else {
1024
+ try {
1025
+ await tx.execute(`DELETE FROM ${safeTable}`);
1026
+ }
1027
+ catch { }
1028
+ }
1029
+ }
1030
+ });
1031
+ this.schemaManager.clearCache();
1032
+ this.events.emit('reset', { dropTables: false });
1033
+ return;
1034
+ }
1035
+ }
1036
+ catch (err) {
1037
+ throw new Error(`Failed to import backup snapshot: ${err?.message || err}`);
1038
+ }
1039
+ }
1040
+ /**
1041
+ * Creates a backup directly from this client to the given cloud or local storage.
1042
+ */
1043
+ async backup(storage, options) {
1044
+ return (0, index_js_1.performBackup)(this, storage, options);
1045
+ }
1046
+ /**
1047
+ * Restores this client's database from a backup in cloud or local storage.
1048
+ */
1049
+ async restore(storage, fileNameOrId, options) {
1050
+ return (0, index_js_1.performRestore)(this, storage, fileNameOrId, options);
1051
+ }
863
1052
  }
864
1053
  exports.LocalFirstClient = LocalFirstClient;
@@ -8,6 +8,7 @@ export * from './meta-store.js';
8
8
  export * from './table-manager.js';
9
9
  export * from './schema-manager.js';
10
10
  export * from './query-builder.js';
11
+ export * from './maintenance.js';
11
12
  export * from '../reactive/event-emitter.js';
12
13
  export * from '../adapters/network/index.js';
13
14
  export type { LocalDBAdapter, LocalTransaction } from '../adapters/local/index.js';
@@ -25,6 +25,7 @@ __exportStar(require("./meta-store.js"), exports);
25
25
  __exportStar(require("./table-manager.js"), exports);
26
26
  __exportStar(require("./schema-manager.js"), exports);
27
27
  __exportStar(require("./query-builder.js"), exports);
28
+ __exportStar(require("./maintenance.js"), exports);
28
29
  __exportStar(require("../reactive/event-emitter.js"), exports);
29
30
  __exportStar(require("../adapters/network/index.js"), exports);
30
31
  __exportStar(require("../utils/logger.js"), exports);
@@ -7,6 +7,7 @@ const outbox_store_js_1 = require("./outbox-store.js");
7
7
  const meta_store_js_1 = require("./meta-store.js");
8
8
  const table_manager_js_1 = require("./table-manager.js");
9
9
  const logger_js_1 = require("../utils/logger.js");
10
+ const dynamic_js_1 = require("../utils/dynamic.js");
10
11
  const REACT_NATIVE_PKG = ['react', 'native'].join('-');
11
12
  /** Maximum outbox records sent per push cycle. */
12
13
  const PUSH_BATCH_SIZE = 50;
@@ -236,7 +237,8 @@ class SyncWorker {
236
237
  return false;
237
238
  // React Native AppState
238
239
  try {
239
- const { AppState } = require('react-native');
240
+ const rn = (0, dynamic_js_1.safeDynamicRequire)(REACT_NATIVE_PKG);
241
+ const AppState = rn?.AppState;
240
242
  if (AppState?.currentState && typeof AppState.currentState === 'string') {
241
243
  return Boolean(AppState.currentState.match(/inactive|background/));
242
244
  }
@@ -255,7 +257,8 @@ class SyncWorker {
255
257
  return;
256
258
  // 1. Try React Native AppState
257
259
  try {
258
- const { AppState } = require('react-native');
260
+ const rn = (0, dynamic_js_1.safeDynamicRequire)(REACT_NATIVE_PKG);
261
+ const AppState = rn?.AppState;
259
262
  if (AppState && typeof AppState.addEventListener === 'function') {
260
263
  const sub = AppState.addEventListener('change', (state) => {
261
264
  if (state.match(/inactive|background/)) {
@@ -27,5 +27,3 @@ export interface SyncInspectorProps {
27
27
  * Displays real-time outbox telemetry, connection status, metrics, and triggers manual push, pull, reset, and benchmarks.
28
28
  */
29
29
  export declare function SyncInspector({ client, position, variant, initialOpen, enableBenchmark, onOpenBenchmark, style, theme, alwaysVisible, renderTrigger, }: SyncInspectorProps): React.JSX.Element | null;
30
- export declare const SyncIndicator: typeof SyncInspector;
31
- export type SyncIndicatorProps = SyncInspectorProps;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SyncIndicator = void 0;
4
3
  exports.SyncInspector = SyncInspector;
5
4
  const jsx_runtime_1 = require("react/jsx-runtime");
6
5
  const react_1 = require("react");
@@ -582,4 +581,3 @@ const rnStyles = RN && RN.StyleSheet
582
581
  },
583
582
  })
584
583
  : {};
585
- exports.SyncIndicator = SyncInspector;
@@ -21,9 +21,7 @@ export interface UseMicrosoftAuthResult {
21
21
  signOut: () => Promise<void>;
22
22
  refetchUser: () => Promise<MicrosoftUser | null>;
23
23
  }
24
- export type UseOneDriveAuthResult = UseMicrosoftAuthResult;
25
24
  export declare function useMicrosoftAuth(client: MicrosoftAuthClient | null | undefined): UseMicrosoftAuthResult;
26
- export declare const useOneDriveAuth: typeof useMicrosoftAuth;
27
25
  export interface UseGitHubAuthResult {
28
26
  user: GitHubUser | null;
29
27
  isSignedIn: boolean;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useOneDriveAuth = void 0;
4
3
  exports.useGoogleAuth = useGoogleAuth;
5
4
  exports.useMicrosoftAuth = useMicrosoftAuth;
6
5
  exports.useGitHubAuth = useGitHubAuth;
@@ -184,7 +183,6 @@ function useMicrosoftAuth(client) {
184
183
  refetchUser,
185
184
  };
186
185
  }
187
- exports.useOneDriveAuth = useMicrosoftAuth;
188
186
  function useGitHubAuth(client) {
189
187
  const [user, setUser] = (0, react_1.useState)(null);
190
188
  const [loading, setLoading] = (0, react_1.useState)(true);
@@ -0,0 +1,28 @@
1
+ import type { CloudBackupClient, CloudBackupFile, ResolvableBackupDatabase, GoogleDriveBackupClient, OneDriveBackupClient } from '../backups/index.js';
2
+ export interface UseCloudBackupOptions {
3
+ passphrase?: string;
4
+ autoRefresh?: boolean;
5
+ }
6
+ export interface UseCloudBackupResult {
7
+ isConnected: boolean;
8
+ isLoading: boolean;
9
+ isBackingUp: boolean;
10
+ isRestoring: boolean;
11
+ backups: CloudBackupFile[];
12
+ lastBackupAt: string | null;
13
+ error: Error | null;
14
+ connect: () => Promise<boolean>;
15
+ disconnect: () => Promise<void>;
16
+ refreshBackups: () => Promise<CloudBackupFile[]>;
17
+ backup: (options?: {
18
+ fileName?: string;
19
+ passphrase?: string;
20
+ }) => Promise<string>;
21
+ restore: (fileNameOrId: string, options?: {
22
+ passphrase?: string;
23
+ }) => Promise<void>;
24
+ deleteBackup: (fileNameOrId: string) => Promise<void>;
25
+ }
26
+ export declare function useCloudBackup(client: CloudBackupClient | null | undefined, database?: ResolvableBackupDatabase, options?: UseCloudBackupOptions): UseCloudBackupResult;
27
+ export declare function useGoogleDriveBackup(client: GoogleDriveBackupClient | null | undefined, database?: ResolvableBackupDatabase, options?: UseCloudBackupOptions): UseCloudBackupResult;
28
+ export declare function useOneDriveBackup(client: OneDriveBackupClient | null | undefined, database?: ResolvableBackupDatabase, options?: UseCloudBackupOptions): UseCloudBackupResult;