@framers/sql-storage-adapter 0.5.0 → 0.5.2
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.
- package/README.md +94 -2
- package/dist/adapters/electron/electronMainAdapter.d.ts +241 -0
- package/dist/adapters/electron/electronMainAdapter.d.ts.map +1 -0
- package/dist/adapters/electron/electronMainAdapter.js +442 -0
- package/dist/adapters/electron/electronMainAdapter.js.map +1 -0
- package/dist/adapters/electron/electronRendererAdapter.d.ts +177 -0
- package/dist/adapters/electron/electronRendererAdapter.d.ts.map +1 -0
- package/dist/adapters/electron/electronRendererAdapter.js +339 -0
- package/dist/adapters/electron/electronRendererAdapter.js.map +1 -0
- package/dist/adapters/electron/index.d.ts +74 -0
- package/dist/adapters/electron/index.d.ts.map +1 -0
- package/dist/adapters/electron/index.js +96 -0
- package/dist/adapters/electron/index.js.map +1 -0
- package/dist/adapters/electron/ipc/channels.d.ts +196 -0
- package/dist/adapters/electron/ipc/channels.d.ts.map +1 -0
- package/dist/adapters/electron/ipc/channels.js +121 -0
- package/dist/adapters/electron/ipc/channels.js.map +1 -0
- package/dist/adapters/electron/ipc/index.d.ts +11 -0
- package/dist/adapters/electron/ipc/index.d.ts.map +1 -0
- package/dist/adapters/electron/ipc/index.js +11 -0
- package/dist/adapters/electron/ipc/index.js.map +1 -0
- package/dist/adapters/electron/ipc/protocol.d.ts +78 -0
- package/dist/adapters/electron/ipc/protocol.d.ts.map +1 -0
- package/dist/adapters/electron/ipc/protocol.js +347 -0
- package/dist/adapters/electron/ipc/protocol.js.map +1 -0
- package/dist/adapters/electron/ipc/types.d.ts +248 -0
- package/dist/adapters/electron/ipc/types.d.ts.map +1 -0
- package/dist/adapters/electron/ipc/types.js +8 -0
- package/dist/adapters/electron/ipc/types.js.map +1 -0
- package/dist/adapters/electron/migration/autoMigrator.d.ts +184 -0
- package/dist/adapters/electron/migration/autoMigrator.d.ts.map +1 -0
- package/dist/adapters/electron/migration/autoMigrator.js +478 -0
- package/dist/adapters/electron/migration/autoMigrator.js.map +1 -0
- package/dist/adapters/electron/migration/index.d.ts +9 -0
- package/dist/adapters/electron/migration/index.d.ts.map +1 -0
- package/dist/adapters/electron/migration/index.js +9 -0
- package/dist/adapters/electron/migration/index.js.map +1 -0
- package/dist/adapters/electron/preload.d.ts +126 -0
- package/dist/adapters/electron/preload.d.ts.map +1 -0
- package/dist/adapters/electron/preload.js +254 -0
- package/dist/adapters/electron/preload.js.map +1 -0
- package/dist/adapters/electron/recovery/corruptionDetector.d.ts +214 -0
- package/dist/adapters/electron/recovery/corruptionDetector.d.ts.map +1 -0
- package/dist/adapters/electron/recovery/corruptionDetector.js +410 -0
- package/dist/adapters/electron/recovery/corruptionDetector.js.map +1 -0
- package/dist/adapters/electron/recovery/index.d.ts +11 -0
- package/dist/adapters/electron/recovery/index.d.ts.map +1 -0
- package/dist/adapters/electron/recovery/index.js +11 -0
- package/dist/adapters/electron/recovery/index.js.map +1 -0
- package/dist/adapters/electron/recovery/walCheckpoint.d.ts +186 -0
- package/dist/adapters/electron/recovery/walCheckpoint.d.ts.map +1 -0
- package/dist/adapters/electron/recovery/walCheckpoint.js +302 -0
- package/dist/adapters/electron/recovery/walCheckpoint.js.map +1 -0
- package/dist/adapters/electron/window/index.d.ts +9 -0
- package/dist/adapters/electron/window/index.d.ts.map +1 -0
- package/dist/adapters/electron/window/index.js +9 -0
- package/dist/adapters/electron/window/index.js.map +1 -0
- package/dist/adapters/electron/window/windowManager.d.ts +190 -0
- package/dist/adapters/electron/window/windowManager.d.ts.map +1 -0
- package/dist/adapters/electron/window/windowManager.js +358 -0
- package/dist/adapters/electron/window/windowManager.js.map +1 -0
- package/dist/adapters/indexedDbAdapter.d.ts +22 -0
- package/dist/adapters/indexedDbAdapter.d.ts.map +1 -1
- package/dist/adapters/indexedDbAdapter.js +122 -19
- package/dist/adapters/indexedDbAdapter.js.map +1 -1
- package/dist/adapters/sqlJsAdapter.d.ts.map +1 -1
- package/dist/adapters/sqlJsAdapter.js +24 -2
- package/dist/adapters/sqlJsAdapter.js.map +1 -1
- package/dist/core/contracts/context.d.ts +2 -2
- package/dist/core/contracts/context.d.ts.map +1 -1
- package/dist/core/resolver.d.ts.map +1 -1
- package/dist/core/resolver.js +32 -0
- package/dist/core/resolver.js.map +1 -1
- package/dist/features/sync/conflicts/conflictResolver.d.ts +222 -0
- package/dist/features/sync/conflicts/conflictResolver.d.ts.map +1 -0
- package/dist/features/sync/conflicts/conflictResolver.js +396 -0
- package/dist/features/sync/conflicts/conflictResolver.js.map +1 -0
- package/dist/features/sync/conflicts/index.d.ts +9 -0
- package/dist/features/sync/conflicts/index.d.ts.map +1 -0
- package/dist/features/sync/conflicts/index.js +9 -0
- package/dist/features/sync/conflicts/index.js.map +1 -0
- package/dist/features/sync/crossPlatformSync.d.ts +281 -0
- package/dist/features/sync/crossPlatformSync.d.ts.map +1 -0
- package/dist/features/sync/crossPlatformSync.js +623 -0
- package/dist/features/sync/crossPlatformSync.js.map +1 -0
- package/dist/features/sync/devices/deviceManager.d.ts +243 -0
- package/dist/features/sync/devices/deviceManager.d.ts.map +1 -0
- package/dist/features/sync/devices/deviceManager.js +494 -0
- package/dist/features/sync/devices/deviceManager.js.map +1 -0
- package/dist/features/sync/devices/index.d.ts +10 -0
- package/dist/features/sync/devices/index.d.ts.map +1 -0
- package/dist/features/sync/devices/index.js +10 -0
- package/dist/features/sync/devices/index.js.map +1 -0
- package/dist/features/sync/index.d.ts +37 -0
- package/dist/features/sync/index.d.ts.map +1 -0
- package/dist/features/sync/index.js +47 -0
- package/dist/features/sync/index.js.map +1 -0
- package/dist/features/sync/protocol/index.d.ts +11 -0
- package/dist/features/sync/protocol/index.d.ts.map +1 -0
- package/dist/features/sync/protocol/index.js +11 -0
- package/dist/features/sync/protocol/index.js.map +1 -0
- package/dist/features/sync/protocol/messages.d.ts +348 -0
- package/dist/features/sync/protocol/messages.d.ts.map +1 -0
- package/dist/features/sync/protocol/messages.js +216 -0
- package/dist/features/sync/protocol/messages.js.map +1 -0
- package/dist/features/sync/protocol/vectorClock.d.ts +164 -0
- package/dist/features/sync/protocol/vectorClock.d.ts.map +1 -0
- package/dist/features/sync/protocol/vectorClock.js +286 -0
- package/dist/features/sync/protocol/vectorClock.js.map +1 -0
- package/dist/features/sync/tables/index.d.ts +10 -0
- package/dist/features/sync/tables/index.d.ts.map +1 -0
- package/dist/features/sync/tables/index.js +10 -0
- package/dist/features/sync/tables/index.js.map +1 -0
- package/dist/features/sync/tables/syncLogManager.d.ts +216 -0
- package/dist/features/sync/tables/syncLogManager.d.ts.map +1 -0
- package/dist/features/sync/tables/syncLogManager.js +456 -0
- package/dist/features/sync/tables/syncLogManager.js.map +1 -0
- package/dist/features/sync/transport/httpTransport.d.ts +123 -0
- package/dist/features/sync/transport/httpTransport.d.ts.map +1 -0
- package/dist/features/sync/transport/httpTransport.js +380 -0
- package/dist/features/sync/transport/httpTransport.js.map +1 -0
- package/dist/features/sync/transport/index.d.ts +12 -0
- package/dist/features/sync/transport/index.d.ts.map +1 -0
- package/dist/features/sync/transport/index.js +12 -0
- package/dist/features/sync/transport/index.js.map +1 -0
- package/dist/features/sync/transport/transport.d.ts +259 -0
- package/dist/features/sync/transport/transport.d.ts.map +1 -0
- package/dist/features/sync/transport/transport.js +153 -0
- package/dist/features/sync/transport/transport.js.map +1 -0
- package/dist/features/sync/transport/websocketTransport.d.ts +126 -0
- package/dist/features/sync/transport/websocketTransport.d.ts.map +1 -0
- package/dist/features/sync/transport/websocketTransport.js +374 -0
- package/dist/features/sync/transport/websocketTransport.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/package.json +21 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
The SQL Storage Adapter provides a single, ergonomic interface over SQLite (native and WASM), PostgreSQL, Capacitor, IndexedDB, and in-memory stores. It handles adapter discovery, capability detection, and advanced features like cloud backups so you can focus on your application logic.
|
|
21
21
|
|
|
22
|
-
**🆕 NEW:**
|
|
22
|
+
**🆕 NEW in v0.5.1:** Electron adapter with IPC bridge + Cross-platform real-time sync!
|
|
23
23
|
|
|
24
24
|
---
|
|
25
25
|
|
|
@@ -27,6 +27,8 @@ The SQL Storage Adapter provides a single, ergonomic interface over SQLite (nati
|
|
|
27
27
|
- [Installation](#installation)
|
|
28
28
|
- [Quick Start](#quick-start)
|
|
29
29
|
- [Adapter Matrix](#adapter-matrix)
|
|
30
|
+
- [Electron Adapter](#electron-adapter)
|
|
31
|
+
- [Cross-Platform Sync](#cross-platform-sync)
|
|
30
32
|
- [Configuration & Resolution](#configuration--resolution)
|
|
31
33
|
- [Platform Strategy](#platform-strategy)
|
|
32
34
|
- [CI, Releases, and Badges](#ci-releases-and-badges)
|
|
@@ -38,6 +40,8 @@ The SQL Storage Adapter provides a single, ergonomic interface over SQLite (nati
|
|
|
38
40
|
- **Auto-detected adapters** – `createDatabase()` inspects environment signals and picks the best backend (native SQLite, PostgreSQL, Capacitor, sql.js, **IndexedDB**, memory, etc.).
|
|
39
41
|
- **Capability-aware API** – consistent CRUD, transactions, batching, and event hooks across adapters with runtime capability introspection.
|
|
40
42
|
- **🆕 IndexedDB** – sql.js + IndexedDB persistence wrapper for browser-native, offline-first web apps (uses sql.js for SQL execution, IndexedDB for storage).
|
|
43
|
+
- **🆕 Electron Adapter** – Full IPC bridge with main/renderer process split, WAL management, auto-migrations, multi-window support.
|
|
44
|
+
- **🆕 Cross-Platform Sync** – Real-time delta sync with vector clocks, WebSocket/HTTP transports, conflict resolution UI hooks, and device registry.
|
|
41
45
|
- **🆕 Performance Tiers** – Configurable `fast`, `balanced`, `accurate`, `efficient` presets for cost/accuracy tradeoffs. See [Optimization Guide](./guides/OPTIMIZATION_GUIDE.md).
|
|
42
46
|
- **🆕 Lifecycle Hooks** – Extensible hooks (`onBeforeQuery`, `onAfterQuery`, `onBeforeWrite`, `onAfterWrite`) for logging, analytics, caching, and custom extensions.
|
|
43
47
|
- **Cloud backups & migrations** – built-in backup manager with compression, retention policies, and restore helpers plus migration utilities.
|
|
@@ -120,6 +124,7 @@ See [Platform Strategy Guide](./PLATFORM_STRATEGY.md) for detailed pros/cons and
|
|
|
120
124
|
|
|
121
125
|
| Adapter | Package | Ideal for | Pros | Considerations |
|
|
122
126
|
| --- | --- | --- | --- | --- |
|
|
127
|
+
| **🆕 `electron`** | bundled | **Electron desktop apps** | IPC bridge, multi-window, WAL, auto-migrations, crash recovery | Requires Electron runtime |
|
|
123
128
|
| **🆕 `indexeddb`** | bundled (sql.js) | **Browsers, PWAs** | sql.js + IndexedDB persistence wrapper, browser-native storage, 50MB-1GB+ quota, offline-first | IndexedDB quotas vary, WASM overhead (sql.js), not a separate SQL engine |
|
|
124
129
|
| `better-sqlite3` | `better-sqlite3` | Node/Electron, CLI, CI | Native performance, transactional semantics, WAL support | Needs native toolchain; version must match Node ABI |
|
|
125
130
|
| `postgres` | `pg` | Hosted or on-prem PostgreSQL | Connection pooling, rich SQL features, cloud friendly | Requires `DATABASE_URL`/credentials |
|
|
@@ -132,11 +137,98 @@ See [Platform Strategy Guide](./PLATFORM_STRATEGY.md) for detailed pros/cons and
|
|
|
132
137
|
| Platform | Primary Adapter | Fallback | Use Case |
|
|
133
138
|
|----------|----------------|----------|----------|
|
|
134
139
|
| **Web (Browser)** | IndexedDB | sql.js | PWAs, offline-first web apps |
|
|
135
|
-
| **Electron (Desktop)** | better-sqlite3 |
|
|
140
|
+
| **Electron (Desktop)** | electron | better-sqlite3 | Desktop apps, dev tools |
|
|
136
141
|
| **Capacitor (Mobile)** | capacitor | IndexedDB | iOS/Android native apps |
|
|
137
142
|
| **Node.js** | better-sqlite3 | Postgres, sql.js | CLI tools, local servers |
|
|
138
143
|
| **Cloud (Serverless)** | Postgres | better-sqlite3 | Multi-tenant SaaS, APIs |
|
|
139
144
|
|
|
145
|
+
## Electron Adapter
|
|
146
|
+
|
|
147
|
+
The Electron adapter provides a complete IPC bridge architecture for Electron apps with main/renderer process split.
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
// Main process (main.ts)
|
|
151
|
+
import { createElectronMainAdapter } from '@framers/sql-storage-adapter/electron';
|
|
152
|
+
|
|
153
|
+
const db = await createElectronMainAdapter({
|
|
154
|
+
filePath: path.join(app.getPath('userData'), 'app.db'),
|
|
155
|
+
wal: { enabled: true, checkpointInterval: 30000 },
|
|
156
|
+
autoMigration: { enabled: true, migrationsPath: './migrations' },
|
|
157
|
+
multiWindow: { enabled: true, broadcastChanges: true },
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
await db.open();
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
// Renderer process
|
|
165
|
+
import { createElectronRendererAdapter } from '@framers/sql-storage-adapter/electron';
|
|
166
|
+
|
|
167
|
+
const db = createElectronRendererAdapter();
|
|
168
|
+
await db.open();
|
|
169
|
+
|
|
170
|
+
const users = await db.all('SELECT * FROM users');
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**Features:**
|
|
174
|
+
- ✅ Type-safe IPC protocol with request/response correlation
|
|
175
|
+
- ✅ WAL checkpoint management and corruption detection
|
|
176
|
+
- ✅ Auto-migration on app version change
|
|
177
|
+
- ✅ Multi-window database change broadcasting
|
|
178
|
+
- ✅ Preload script with secure `contextBridge` API
|
|
179
|
+
|
|
180
|
+
## Cross-Platform Sync
|
|
181
|
+
|
|
182
|
+
Real-time delta synchronization across Electron, Capacitor, browser, and server platforms.
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { createCrossPlatformSync } from '@framers/sql-storage-adapter/sync';
|
|
186
|
+
|
|
187
|
+
const sync = await createCrossPlatformSync({
|
|
188
|
+
localAdapter: db,
|
|
189
|
+
endpoint: 'wss://sync.example.com',
|
|
190
|
+
authToken: 'bearer-token',
|
|
191
|
+
device: { name: 'MacBook Pro', type: 'electron' },
|
|
192
|
+
tables: {
|
|
193
|
+
notes: { priority: 'high', conflictStrategy: 'merge' },
|
|
194
|
+
settings: { priority: 'critical', conflictStrategy: 'local-wins' },
|
|
195
|
+
},
|
|
196
|
+
hooks: {
|
|
197
|
+
onConflictNeedsResolution: async (conflict) => {
|
|
198
|
+
// Show UI for manual conflict resolution
|
|
199
|
+
return showConflictDialog(conflict);
|
|
200
|
+
},
|
|
201
|
+
onSyncComplete: (result) => {
|
|
202
|
+
console.log(`Synced: ${result.changesPushed} pushed, ${result.changesPulled} pulled`);
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// Manual sync
|
|
208
|
+
await sync.sync();
|
|
209
|
+
|
|
210
|
+
// Or enable real-time sync
|
|
211
|
+
await sync.connect();
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**Features:**
|
|
215
|
+
- ✅ **Vector Clocks** – Distributed causality tracking for accurate conflict detection
|
|
216
|
+
- ✅ **WebSocket Transport** – Real-time bidirectional sync with auto-reconnection
|
|
217
|
+
- ✅ **HTTP Fallback** – Polling transport for firewalls that block WebSocket
|
|
218
|
+
- ✅ **Conflict Resolution** – Strategies: `last-write-wins`, `local-wins`, `remote-wins`, `merge`, `manual`
|
|
219
|
+
- ✅ **Device Registry** – Track syncing devices with presence status (online/offline/syncing)
|
|
220
|
+
- ✅ **UI Hooks** – Custom conflict resolution dialogs
|
|
221
|
+
|
|
222
|
+
**Conflict Strategies:**
|
|
223
|
+
|
|
224
|
+
| Strategy | Description |
|
|
225
|
+
|----------|-------------|
|
|
226
|
+
| `last-write-wins` | Most recent change wins (by timestamp) |
|
|
227
|
+
| `local-wins` | Local changes always take priority |
|
|
228
|
+
| `remote-wins` | Remote changes always take priority |
|
|
229
|
+
| `merge` | Field-level merge with custom mergers |
|
|
230
|
+
| `manual` | Defer to UI hook for user decision |
|
|
231
|
+
|
|
140
232
|
## Configuration & Resolution
|
|
141
233
|
|
|
142
234
|
- `resolveStorageAdapter` inspects:
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Electron Main Process Storage Adapter.
|
|
3
|
+
*
|
|
4
|
+
* Wraps BetterSqliteAdapter for use in Electron's main process.
|
|
5
|
+
* Handles IPC communication, WAL management, crash recovery,
|
|
6
|
+
* and multi-window coordination.
|
|
7
|
+
*
|
|
8
|
+
* ## Architecture
|
|
9
|
+
* This adapter runs in the main process and owns the actual database connection.
|
|
10
|
+
* Renderer processes communicate with it via IPC using ElectronRendererAdapter.
|
|
11
|
+
*
|
|
12
|
+
* ## Features
|
|
13
|
+
* - WAL mode with configurable checkpointing
|
|
14
|
+
* - Integrity checking and auto-repair
|
|
15
|
+
* - Multi-window change broadcasting
|
|
16
|
+
* - Cloud backup scheduling
|
|
17
|
+
* - Auto-migration on app updates
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { createElectronMainAdapter } from '@framers/sql-storage-adapter/electron';
|
|
22
|
+
* import { app } from 'electron';
|
|
23
|
+
* import path from 'path';
|
|
24
|
+
*
|
|
25
|
+
* const db = await createElectronMainAdapter({
|
|
26
|
+
* filePath: path.join(app.getPath('userData'), 'app.db'),
|
|
27
|
+
* wal: { enabled: true, checkpointInterval: 300000 },
|
|
28
|
+
* recovery: { enabled: true, checkOnOpen: true },
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* await db.open();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
import type { StorageAdapter, StorageCapability, StorageOpenOptions, StorageParameters, StorageRunResult, BatchOperation, BatchResult, PreparedStatement } from '../../core/contracts';
|
|
35
|
+
/**
|
|
36
|
+
* WAL (Write-Ahead Logging) configuration.
|
|
37
|
+
*/
|
|
38
|
+
export interface WalConfig {
|
|
39
|
+
/** Enable WAL mode (default: true) */
|
|
40
|
+
enabled?: boolean;
|
|
41
|
+
/** Checkpoint interval in milliseconds (default: 300000 = 5 minutes) */
|
|
42
|
+
checkpointInterval?: number;
|
|
43
|
+
/** Auto-checkpoint threshold in pages (default: 1000) */
|
|
44
|
+
autoCheckpointPages?: number;
|
|
45
|
+
/** Synchronous mode: OFF, NORMAL, FULL, EXTRA (default: NORMAL) */
|
|
46
|
+
synchronous?: 'OFF' | 'NORMAL' | 'FULL' | 'EXTRA';
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Recovery and integrity check configuration.
|
|
50
|
+
*/
|
|
51
|
+
export interface RecoveryConfig {
|
|
52
|
+
/** Enable recovery features (default: true) */
|
|
53
|
+
enabled?: boolean;
|
|
54
|
+
/** Run integrity check on open (default: true) */
|
|
55
|
+
checkOnOpen?: boolean;
|
|
56
|
+
/** Attempt auto-repair on corruption (default: true) */
|
|
57
|
+
autoRepair?: boolean;
|
|
58
|
+
/** Maximum time for integrity check in ms (default: 30000) */
|
|
59
|
+
integrityCheckTimeout?: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Auto-migration configuration.
|
|
63
|
+
*/
|
|
64
|
+
export interface MigrationConfig {
|
|
65
|
+
/** Enable auto-migration (default: false) */
|
|
66
|
+
enabled?: boolean;
|
|
67
|
+
/** Path to migrations directory */
|
|
68
|
+
migrationsPath?: string;
|
|
69
|
+
/** Run migrations on app version change (default: true) */
|
|
70
|
+
runOnVersionChange?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Cloud backup configuration.
|
|
74
|
+
*/
|
|
75
|
+
export interface BackupConfig {
|
|
76
|
+
/** Enable cloud backups (default: false) */
|
|
77
|
+
enabled?: boolean;
|
|
78
|
+
/** Backup interval in milliseconds (default: 3600000 = 1 hour) */
|
|
79
|
+
interval?: number;
|
|
80
|
+
/** Maximum backups to keep (default: 7) */
|
|
81
|
+
maxBackups?: number;
|
|
82
|
+
/** Backup provider (implement your own) */
|
|
83
|
+
provider?: CloudBackupProvider;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Cloud backup provider interface.
|
|
87
|
+
*/
|
|
88
|
+
export interface CloudBackupProvider {
|
|
89
|
+
upload(localPath: string, remotePath: string): Promise<void>;
|
|
90
|
+
download(remotePath: string, localPath: string): Promise<void>;
|
|
91
|
+
list(): Promise<{
|
|
92
|
+
path: string;
|
|
93
|
+
createdAt: Date;
|
|
94
|
+
size: number;
|
|
95
|
+
}[]>;
|
|
96
|
+
delete(remotePath: string): Promise<void>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Multi-window coordination configuration.
|
|
100
|
+
*/
|
|
101
|
+
export interface MultiWindowConfig {
|
|
102
|
+
/** Enable multi-window support (default: true) */
|
|
103
|
+
enabled?: boolean;
|
|
104
|
+
/** Broadcast changes to other windows (default: true) */
|
|
105
|
+
broadcastChanges?: boolean;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Full configuration for ElectronMainAdapter.
|
|
109
|
+
*/
|
|
110
|
+
export interface ElectronMainAdapterOptions {
|
|
111
|
+
/** Path to SQLite database file */
|
|
112
|
+
filePath: string;
|
|
113
|
+
/** WAL configuration */
|
|
114
|
+
wal?: WalConfig;
|
|
115
|
+
/** Recovery configuration */
|
|
116
|
+
recovery?: RecoveryConfig;
|
|
117
|
+
/** Migration configuration */
|
|
118
|
+
migration?: MigrationConfig;
|
|
119
|
+
/** Backup configuration */
|
|
120
|
+
backup?: BackupConfig;
|
|
121
|
+
/** Multi-window configuration */
|
|
122
|
+
multiWindow?: MultiWindowConfig;
|
|
123
|
+
/** Enable verbose logging (default: false) */
|
|
124
|
+
verbose?: boolean;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Electron Main Process Storage Adapter.
|
|
128
|
+
*
|
|
129
|
+
* This adapter is designed to run exclusively in Electron's main process.
|
|
130
|
+
* It wraps BetterSqliteAdapter and adds Electron-specific features like
|
|
131
|
+
* IPC handling, multi-window coordination, and crash recovery.
|
|
132
|
+
*/
|
|
133
|
+
export declare class ElectronMainAdapter implements StorageAdapter {
|
|
134
|
+
readonly kind = "electron-main";
|
|
135
|
+
readonly capabilities: ReadonlySet<StorageCapability>;
|
|
136
|
+
private innerAdapter;
|
|
137
|
+
private isInitialized;
|
|
138
|
+
private walCheckpointTimer;
|
|
139
|
+
private backupTimer;
|
|
140
|
+
private readonly options;
|
|
141
|
+
private readonly walConfig;
|
|
142
|
+
private readonly recoveryConfig;
|
|
143
|
+
private readonly multiWindowConfig;
|
|
144
|
+
constructor(options: ElectronMainAdapterOptions);
|
|
145
|
+
/**
|
|
146
|
+
* Open the database and initialize all subsystems.
|
|
147
|
+
*/
|
|
148
|
+
open(openOptions?: StorageOpenOptions): Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* Close the database and cleanup all subsystems.
|
|
151
|
+
*/
|
|
152
|
+
close(): Promise<void>;
|
|
153
|
+
run(statement: string, parameters?: StorageParameters): Promise<StorageRunResult>;
|
|
154
|
+
get<T = unknown>(statement: string, parameters?: StorageParameters): Promise<T | null>;
|
|
155
|
+
all<T = unknown>(statement: string, parameters?: StorageParameters): Promise<T[]>;
|
|
156
|
+
exec(script: string): Promise<void>;
|
|
157
|
+
transaction<T>(fn: (trx: StorageAdapter) => Promise<T>): Promise<T>;
|
|
158
|
+
batch(operations: BatchOperation[]): Promise<BatchResult>;
|
|
159
|
+
prepare?<T = unknown>(statement: string): PreparedStatement<T>;
|
|
160
|
+
/**
|
|
161
|
+
* Configure WAL mode on the database.
|
|
162
|
+
*/
|
|
163
|
+
private configureWalMode;
|
|
164
|
+
/**
|
|
165
|
+
* Start the WAL checkpoint timer.
|
|
166
|
+
*/
|
|
167
|
+
private startWalCheckpointTimer;
|
|
168
|
+
/**
|
|
169
|
+
* Run a WAL checkpoint.
|
|
170
|
+
*/
|
|
171
|
+
runWalCheckpoint(): Promise<{
|
|
172
|
+
framesCheckpointed: number;
|
|
173
|
+
totalFrames: number;
|
|
174
|
+
}>;
|
|
175
|
+
/**
|
|
176
|
+
* Run an integrity check on the database.
|
|
177
|
+
*/
|
|
178
|
+
runIntegrityCheck(): Promise<{
|
|
179
|
+
ok: boolean;
|
|
180
|
+
issues: string[];
|
|
181
|
+
}>;
|
|
182
|
+
/**
|
|
183
|
+
* Attempt to repair the database.
|
|
184
|
+
*/
|
|
185
|
+
private attemptRepair;
|
|
186
|
+
/**
|
|
187
|
+
* Start the backup scheduler.
|
|
188
|
+
*/
|
|
189
|
+
private startBackupScheduler;
|
|
190
|
+
/**
|
|
191
|
+
* Run a backup.
|
|
192
|
+
*/
|
|
193
|
+
runBackup(): Promise<void>;
|
|
194
|
+
/**
|
|
195
|
+
* Cleanup old backups beyond the retention limit.
|
|
196
|
+
*/
|
|
197
|
+
private cleanupOldBackups;
|
|
198
|
+
/**
|
|
199
|
+
* Broadcast a database change to all windows.
|
|
200
|
+
*/
|
|
201
|
+
private broadcastChange;
|
|
202
|
+
/**
|
|
203
|
+
* Detect mutation type from SQL statement.
|
|
204
|
+
*/
|
|
205
|
+
private detectMutationType;
|
|
206
|
+
/**
|
|
207
|
+
* Extract table names from SQL statement.
|
|
208
|
+
*/
|
|
209
|
+
private extractTables;
|
|
210
|
+
/**
|
|
211
|
+
* Log a message if verbose mode is enabled.
|
|
212
|
+
*/
|
|
213
|
+
private log;
|
|
214
|
+
/**
|
|
215
|
+
* Check if the adapter is initialized.
|
|
216
|
+
*/
|
|
217
|
+
isOpen(): boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Get the database file path.
|
|
220
|
+
*/
|
|
221
|
+
getFilePath(): string;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Create an Electron Main Process Storage Adapter.
|
|
225
|
+
*
|
|
226
|
+
* @param options - Adapter configuration
|
|
227
|
+
* @returns ElectronMainAdapter instance
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* const db = createElectronMainAdapter({
|
|
232
|
+
* filePath: path.join(app.getPath('userData'), 'app.db'),
|
|
233
|
+
* wal: { enabled: true },
|
|
234
|
+
* recovery: { checkOnOpen: true },
|
|
235
|
+
* });
|
|
236
|
+
*
|
|
237
|
+
* await db.open();
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
export declare function createElectronMainAdapter(options: ElectronMainAdapterOptions): ElectronMainAdapter;
|
|
241
|
+
//# sourceMappingURL=electronMainAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"electronMainAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/electron/electronMainAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAOH,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAM9B;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,sCAAsC;IACtC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,wEAAwE;IACxE,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,yDAAyD;IACzD,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,mEAAmE;IACnE,WAAW,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;CACnD;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,+CAA+C;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kDAAkD;IAClD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,wDAAwD;IACxD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,8DAA8D;IAC9D,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,6CAA6C;IAC7C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,mCAAmC;IACnC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,2DAA2D;IAC3D,kBAAkB,CAAC,EAAE,OAAO,CAAC;C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