Skip to content

Commit c8e63c9

Browse files
Johnny Dunnclaude
authored andcommitted
docs: update package exports and documentation for v0.5.0
- Add /sync export path to package.json - Update CHANGELOG.md with v0.5.0 features (Electron, sync) - Update README.md with: - Electron adapter section with usage examples - Cross-platform sync section with API examples - Updated adapter matrix with electron adapter - Updated features list 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f8ca9be commit c8e63c9

3 files changed

Lines changed: 147 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
## [0.5.0] - 2025-12-26
2+
3+
### Added
4+
- **Electron Adapter** - Full-featured Electron support with IPC bridge architecture
5+
- `ElectronMainAdapter`: Main process adapter wrapping better-sqlite3 with WAL, recovery, and multi-window support
6+
- `ElectronRendererAdapter`: Renderer process proxy with transparent IPC communication
7+
- Preload script with `contextBridge` for secure renderer access
8+
- Type-safe IPC protocol with request/response correlation
9+
- WAL checkpoint management and corruption detection
10+
- Auto-migration system with app version tracking
11+
- Multi-window database change broadcasting
12+
- Export: `@framers/sql-storage-adapter/electron`
13+
14+
- **Cross-Platform Sync Module** - Real-time delta synchronization across platforms
15+
- `CrossPlatformSync`: Main sync orchestrator with configurable table priorities
16+
- **Vector Clocks**: Distributed causality tracking for conflict detection
17+
- **WebSocket Transport**: Real-time bidirectional sync with auto-reconnection and heartbeats
18+
- **HTTP Transport**: Polling fallback for firewalls/proxies that block WebSocket
19+
- **Conflict Resolution**: Strategies include `last-write-wins`, `local-wins`, `remote-wins`, `merge`, `manual`
20+
- **Device Registry**: Track and manage syncing devices with presence status
21+
- **SyncLogManager**: Change log and conflict tables for delta tracking
22+
- UI hooks for custom conflict resolution dialogs
23+
- Export: `@framers/sql-storage-adapter/sync`
24+
25+
### Changed
26+
- Updated package exports to include `/electron`, `/electron/preload`, and `/sync` entry points
27+
- Enhanced `StorageContext` with Electron-specific properties
28+
29+
### Technical Details
30+
- Vector clocks use `Record<string, number>` for causality comparison
31+
- Sync protocol messages use underscore naming (`delta_push`, `handshake_response`)
32+
- Transport layer abstracts WebSocket/HTTP with unified event system
33+
- Field mergers support custom merge logic for complex data types
34+
135
## [0.4.2] - 2025-12-11
236

337
### Fixed

README.md

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919
2020
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.
2121

22-
**🆕 NEW:** Full IndexedDB support for browser-native, offline-first web apps!
22+
**🆕 NEW in v0.5.0:** Electron adapter with IPC bridge + Cross-platform real-time sync!
2323

2424
---
2525

2626
- [Features](#features)
2727
- [Installation](#installation)
2828
- [Quick Start](#quick-start)
2929
- [Adapter Matrix](#adapter-matrix)
30+
- [Electron Adapter](#electron-adapter)
31+
- [Cross-Platform Sync](#cross-platform-sync)
3032
- [Configuration & Resolution](#configuration--resolution)
3133
- [Platform Strategy](#platform-strategy)
3234
- [CI, Releases, and Badges](#ci-releases-and-badges)
@@ -38,6 +40,8 @@ The SQL Storage Adapter provides a single, ergonomic interface over SQLite (nati
3840
- **Auto-detected adapters**`createDatabase()` inspects environment signals and picks the best backend (native SQLite, PostgreSQL, Capacitor, sql.js, **IndexedDB**, memory, etc.).
3941
- **Capability-aware API** – consistent CRUD, transactions, batching, and event hooks across adapters with runtime capability introspection.
4042
- **🆕 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.
4145
- **🆕 Performance Tiers** – Configurable `fast`, `balanced`, `accurate`, `efficient` presets for cost/accuracy tradeoffs. See [Optimization Guide](./guides/OPTIMIZATION_GUIDE.md).
4246
- **🆕 Lifecycle Hooks** – Extensible hooks (`onBeforeQuery`, `onAfterQuery`, `onBeforeWrite`, `onAfterWrite`) for logging, analytics, caching, and custom extensions.
4347
- **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
120124

121125
| Adapter | Package | Ideal for | Pros | Considerations |
122126
| --- | --- | --- | --- | --- |
127+
| **🆕 `electron`** | bundled | **Electron desktop apps** | IPC bridge, multi-window, WAL, auto-migrations, crash recovery | Requires Electron runtime |
123128
| **🆕 `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 |
124129
| `better-sqlite3` | `better-sqlite3` | Node/Electron, CLI, CI | Native performance, transactional semantics, WAL support | Needs native toolchain; version must match Node ABI |
125130
| `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
132137
| Platform | Primary Adapter | Fallback | Use Case |
133138
|----------|----------------|----------|----------|
134139
| **Web (Browser)** | IndexedDB | sql.js | PWAs, offline-first web apps |
135-
| **Electron (Desktop)** | better-sqlite3 | sql.js | Desktop apps, dev tools |
140+
| **Electron (Desktop)** | electron | better-sqlite3 | Desktop apps, dev tools |
136141
| **Capacitor (Mobile)** | capacitor | IndexedDB | iOS/Android native apps |
137142
| **Node.js** | better-sqlite3 | Postgres, sql.js | CLI tools, local servers |
138143
| **Cloud (Serverless)** | Postgres | better-sqlite3 | Multi-tenant SaaS, APIs |
139144

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+
140232
## Configuration & Resolution
141233

142234
- `resolveStorageAdapter` inspects:

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@
1717
"import": "./dist/types/index.js",
1818
"default": "./dist/types/index.js"
1919
},
20+
"./electron": {
21+
"types": "./dist/adapters/electron/index.d.ts",
22+
"import": "./dist/adapters/electron/index.js",
23+
"default": "./dist/adapters/electron/index.js"
24+
},
25+
"./electron/preload": {
26+
"types": "./dist/adapters/electron/preload.d.ts",
27+
"import": "./dist/adapters/electron/preload.js",
28+
"default": "./dist/adapters/electron/preload.js"
29+
},
30+
"./sync": {
31+
"types": "./dist/features/sync/index.d.ts",
32+
"import": "./dist/features/sync/index.js",
33+
"default": "./dist/features/sync/index.js"
34+
},
2035
"./package.json": "./package.json"
2136
},
2237
"files": [
@@ -106,6 +121,7 @@
106121
"@aws-sdk/client-s3": "^3.0.0",
107122
"@capacitor-community/sqlite": "^6.0.0",
108123
"better-sqlite3": "^12.0.0",
124+
"electron": ">=20.0.0",
109125
"pg": "^8.13.1"
110126
},
111127
"peerDependenciesMeta": {
@@ -118,6 +134,9 @@
118134
"better-sqlite3": {
119135
"optional": true
120136
},
137+
"electron": {
138+
"optional": true
139+
},
121140
"pg": {
122141
"optional": true
123142
}

0 commit comments

Comments
 (0)