@framers/sql-storage-adapter 0.7.2 → 0.7.4
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 +41 -0
- package/dist/adapters/electron/preload.cjs +289 -0
- package/dist/adapters/electron/renderer.d.ts +9 -0
- package/dist/adapters/electron/renderer.d.ts.map +1 -0
- package/dist/adapters/electron/renderer.js +8 -0
- package/dist/adapters/electron/renderer.js.map +1 -0
- package/dist/cjs/adapters/__tests__/indexedDbAdapter.spec.d.ts +2 -0
- package/dist/cjs/adapters/__tests__/indexedDbAdapter.spec.js +133 -0
- package/dist/cjs/adapters/baseStorageAdapter.d.ts +368 -0
- package/dist/cjs/adapters/baseStorageAdapter.js +744 -0
- package/dist/cjs/adapters/betterSqliteAdapter.d.ts +124 -0
- package/dist/cjs/adapters/betterSqliteAdapter.js +334 -0
- package/dist/cjs/adapters/capacitorSqliteAdapter.d.ts +83 -0
- package/dist/cjs/adapters/capacitorSqliteAdapter.js +250 -0
- package/dist/cjs/adapters/electron/electronMainAdapter.d.ts +251 -0
- package/dist/cjs/adapters/electron/electronMainAdapter.js +392 -0
- package/dist/cjs/adapters/electron/electronRendererAdapter.d.ts +177 -0
- package/dist/cjs/adapters/electron/electronRendererAdapter.js +283 -0
- package/dist/cjs/adapters/electron/index.d.ts +74 -0
- package/dist/cjs/adapters/electron/index.js +86 -0
- package/dist/cjs/adapters/electron/ipc/channels.d.ts +196 -0
- package/dist/cjs/adapters/electron/ipc/channels.js +127 -0
- package/dist/cjs/adapters/electron/ipc/index.d.ts +11 -0
- package/dist/cjs/adapters/electron/ipc/index.js +38 -0
- package/dist/cjs/adapters/electron/ipc/protocol.d.ts +78 -0
- package/dist/cjs/adapters/electron/ipc/protocol.js +341 -0
- package/dist/cjs/adapters/electron/ipc/types.d.ts +248 -0
- package/dist/cjs/adapters/electron/ipc/types.js +15 -0
- package/dist/cjs/adapters/electron/migration/autoMigrator.d.ts +184 -0
- package/dist/cjs/adapters/electron/migration/autoMigrator.js +441 -0
- package/dist/cjs/adapters/electron/migration/index.d.ts +9 -0
- package/dist/cjs/adapters/electron/migration/index.js +29 -0
- package/dist/cjs/adapters/electron/preload.d.ts +126 -0
- package/dist/cjs/adapters/electron/preload.js +233 -0
- package/dist/cjs/adapters/electron/recovery/corruptionDetector.d.ts +214 -0
- package/dist/cjs/adapters/electron/recovery/corruptionDetector.js +359 -0
- package/dist/cjs/adapters/electron/recovery/index.d.ts +11 -0
- package/dist/cjs/adapters/electron/recovery/index.js +34 -0
- package/dist/cjs/adapters/electron/recovery/walCheckpoint.d.ts +186 -0
- package/dist/cjs/adapters/electron/recovery/walCheckpoint.js +263 -0
- package/dist/cjs/adapters/electron/renderer.d.ts +9 -0
- package/dist/cjs/adapters/electron/renderer.js +33 -0
- package/dist/cjs/adapters/electron/window/index.d.ts +9 -0
- package/dist/cjs/adapters/electron/window/index.js +29 -0
- package/dist/cjs/adapters/electron/window/windowManager.d.ts +190 -0
- package/dist/cjs/adapters/electron/window/windowManager.js +321 -0
- package/dist/cjs/adapters/indexedDbAdapter.d.ts +490 -0
- package/dist/cjs/adapters/indexedDbAdapter.js +993 -0
- package/dist/cjs/adapters/postgresAdapter.d.ts +424 -0
- package/dist/cjs/adapters/postgresAdapter.js +889 -0
- package/dist/cjs/adapters/sqlJsAdapter.d.ts +64 -0
- package/dist/cjs/adapters/sqlJsAdapter.js +268 -0
- package/dist/cjs/adapters/supabase.d.ts +58 -0
- package/dist/cjs/adapters/supabase.js +401 -0
- package/dist/cjs/codecs/BrowserBlobCodec.d.ts +14 -0
- package/dist/cjs/codecs/BrowserBlobCodec.js +57 -0
- package/dist/cjs/codecs/NodeBlobCodec.d.ts +14 -0
- package/dist/cjs/codecs/NodeBlobCodec.js +59 -0
- package/dist/cjs/core/contracts/blobCodec.d.ts +15 -0
- package/dist/cjs/core/contracts/blobCodec.js +15 -0
- package/dist/cjs/core/contracts/context.d.ts +221 -0
- package/dist/cjs/core/contracts/context.js +15 -0
- package/dist/cjs/core/contracts/dialect.d.ts +154 -0
- package/dist/cjs/core/contracts/dialect.js +15 -0
- package/dist/cjs/core/contracts/events.d.ts +225 -0
- package/dist/cjs/core/contracts/events.js +15 -0
- package/dist/cjs/core/contracts/exporter.d.ts +13 -0
- package/dist/cjs/core/contracts/exporter.js +15 -0
- package/dist/cjs/core/contracts/extensions.d.ts +73 -0
- package/dist/cjs/core/contracts/extensions.js +15 -0
- package/dist/cjs/core/contracts/features.d.ts +25 -0
- package/dist/cjs/core/contracts/features.js +61 -0
- package/dist/cjs/core/contracts/fts.d.ts +66 -0
- package/dist/cjs/core/contracts/fts.js +15 -0
- package/dist/cjs/core/contracts/hooks.d.ts +481 -0
- package/dist/cjs/core/contracts/hooks.js +140 -0
- package/dist/cjs/core/contracts/index.d.ts +260 -0
- package/dist/cjs/core/contracts/index.js +41 -0
- package/dist/cjs/core/contracts/limitations.d.ts +46 -0
- package/dist/cjs/core/contracts/limitations.js +218 -0
- package/dist/cjs/core/contracts/performance.d.ts +308 -0
- package/dist/cjs/core/contracts/performance.js +144 -0
- package/dist/cjs/core/database.d.ts +220 -0
- package/dist/cjs/core/database.js +136 -0
- package/dist/cjs/core/portable.d.ts +24 -0
- package/dist/cjs/core/portable.js +68 -0
- package/dist/cjs/core/resolver.d.ts +77 -0
- package/dist/cjs/core/resolver.js +235 -0
- package/dist/cjs/dialects/PostgresDialect.d.ts +35 -0
- package/dist/cjs/dialects/PostgresDialect.js +143 -0
- package/dist/cjs/dialects/SqliteDialect.d.ts +35 -0
- package/dist/cjs/dialects/SqliteDialect.js +142 -0
- package/dist/cjs/dialects/shared.d.ts +17 -0
- package/dist/cjs/dialects/shared.js +90 -0
- package/dist/cjs/exporters/PostgresExporter.d.ts +14 -0
- package/dist/cjs/exporters/PostgresExporter.js +61 -0
- package/dist/cjs/exporters/SqliteFileExporter.d.ts +16 -0
- package/dist/cjs/exporters/SqliteFileExporter.js +43 -0
- package/dist/cjs/features/auth/authJsAdapter.d.ts +110 -0
- package/dist/cjs/features/auth/authJsAdapter.js +251 -0
- package/dist/cjs/features/backup/cloudBackup.d.ts +219 -0
- package/dist/cjs/features/backup/cloudBackup.js +209 -0
- package/dist/cjs/features/kv/idb.d.ts +79 -0
- package/dist/cjs/features/kv/idb.js +32 -0
- package/dist/cjs/features/kv/index.d.ts +14 -0
- package/dist/cjs/features/kv/index.js +40 -0
- package/dist/cjs/features/kv/indexedDbKeyValueStore.d.ts +77 -0
- package/dist/cjs/features/kv/indexedDbKeyValueStore.js +116 -0
- package/dist/cjs/features/kv/keyValueStore.d.ts +48 -0
- package/dist/cjs/features/kv/keyValueStore.js +67 -0
- package/dist/cjs/features/kv/sqlKeyValueStore.d.ts +34 -0
- package/dist/cjs/features/kv/sqlKeyValueStore.js +81 -0
- package/dist/cjs/features/kv/valueCodec.d.ts +35 -0
- package/dist/cjs/features/kv/valueCodec.js +426 -0
- package/dist/cjs/features/migrations/dataExport.d.ts +77 -0
- package/dist/cjs/features/migrations/dataExport.js +194 -0
- package/dist/cjs/features/migrations/dataImport.d.ts +54 -0
- package/dist/cjs/features/migrations/dataImport.js +300 -0
- package/dist/cjs/features/migrations/migration.d.ts +89 -0
- package/dist/cjs/features/migrations/migration.js +187 -0
- package/dist/cjs/features/migrations/schemaMigrations.d.ts +93 -0
- package/dist/cjs/features/migrations/schemaMigrations.js +220 -0
- package/dist/cjs/features/sync/conflicts/conflictResolver.d.ts +222 -0
- package/dist/cjs/features/sync/conflicts/conflictResolver.js +366 -0
- package/dist/cjs/features/sync/conflicts/index.d.ts +9 -0
- package/dist/cjs/features/sync/conflicts/index.js +21 -0
- package/dist/cjs/features/sync/crossPlatformSync.d.ts +281 -0
- package/dist/cjs/features/sync/crossPlatformSync.js +551 -0
- package/dist/cjs/features/sync/devices/deviceManager.d.ts +243 -0
- package/dist/cjs/features/sync/devices/deviceManager.js +450 -0
- package/dist/cjs/features/sync/devices/index.d.ts +10 -0
- package/dist/cjs/features/sync/devices/index.js +21 -0
- package/dist/cjs/features/sync/index.d.ts +37 -0
- package/dist/cjs/features/sync/index.js +111 -0
- package/dist/cjs/features/sync/protocol/index.d.ts +11 -0
- package/dist/cjs/features/sync/protocol/index.js +23 -0
- package/dist/cjs/features/sync/protocol/messages.d.ts +348 -0
- package/dist/cjs/features/sync/protocol/messages.js +215 -0
- package/dist/cjs/features/sync/protocol/vectorClock.d.ts +164 -0
- package/dist/cjs/features/sync/protocol/vectorClock.js +256 -0
- package/dist/cjs/features/sync/syncManager.d.ts +348 -0
- package/dist/cjs/features/sync/syncManager.js +455 -0
- package/dist/cjs/features/sync/tables/index.d.ts +10 -0
- package/dist/cjs/features/sync/tables/index.js +21 -0
- package/dist/cjs/features/sync/tables/syncLogManager.d.ts +216 -0
- package/dist/cjs/features/sync/tables/syncLogManager.js +423 -0
- package/dist/cjs/features/sync/transport/httpTransport.d.ts +123 -0
- package/dist/cjs/features/sync/transport/httpTransport.js +346 -0
- package/dist/cjs/features/sync/transport/index.d.ts +12 -0
- package/dist/cjs/features/sync/transport/index.js +25 -0
- package/dist/cjs/features/sync/transport/transport.d.ts +259 -0
- package/dist/cjs/features/sync/transport/transport.js +163 -0
- package/dist/cjs/features/sync/transport/websocketTransport.d.ts +126 -0
- package/dist/cjs/features/sync/transport/websocketTransport.js +342 -0
- package/dist/cjs/fts/PostgresFts.d.ts +29 -0
- package/dist/cjs/fts/PostgresFts.js +77 -0
- package/dist/cjs/fts/SqliteFts5.d.ts +22 -0
- package/dist/cjs/fts/SqliteFts5.js +58 -0
- package/dist/cjs/index.d.ts +31 -0
- package/dist/cjs/index.js +103 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/shared/connectionGate.d.ts +94 -0
- package/dist/cjs/shared/connectionGate.js +77 -0
- package/dist/cjs/shared/errors.d.ts +23 -0
- package/dist/cjs/shared/errors.js +45 -0
- package/dist/cjs/shared/logger.d.ts +26 -0
- package/dist/cjs/shared/logger.js +40 -0
- package/dist/cjs/shared/parameterUtils.d.ts +16 -0
- package/dist/cjs/shared/parameterUtils.js +59 -0
- package/dist/cjs/shared/postgresTarget.d.ts +11 -0
- package/dist/cjs/shared/postgresTarget.js +30 -0
- package/dist/cjs/shared/segment.d.ts +43 -0
- package/dist/cjs/shared/segment.js +63 -0
- package/dist/cjs/shared/serializedTransaction.d.ts +14 -0
- package/dist/cjs/shared/serializedTransaction.js +74 -0
- package/dist/cjs/shared/splitSqlStatements.d.ts +27 -0
- package/dist/cjs/shared/splitSqlStatements.js +163 -0
- package/dist/cjs/shared/sqlPlaceholders.d.ts +48 -0
- package/dist/cjs/shared/sqlPlaceholders.js +263 -0
- package/dist/cjs/types/index.d.ts +29 -0
- package/dist/cjs/types/index.js +33 -0
- package/dist/core/portable.d.ts +24 -0
- package/dist/core/portable.d.ts.map +1 -0
- package/dist/core/portable.js +24 -0
- package/dist/core/portable.js.map +1 -0
- package/dist/features/auth/authJsAdapter.d.ts +110 -0
- package/dist/features/auth/authJsAdapter.d.ts.map +1 -0
- package/dist/features/auth/authJsAdapter.js +248 -0
- package/dist/features/auth/authJsAdapter.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +149 -24
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var preload_exports = {};
|
|
19
|
+
__export(preload_exports, {
|
|
20
|
+
sqlStorageApi: () => sqlStorageApi
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(preload_exports);
|
|
23
|
+
var import_electron = require("electron");
|
|
24
|
+
var import_channels = require("./ipc/channels.js");
|
|
25
|
+
function generateMessageId() {
|
|
26
|
+
return `msg_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;
|
|
27
|
+
}
|
|
28
|
+
function createRequest(payload) {
|
|
29
|
+
return {
|
|
30
|
+
messageId: generateMessageId(),
|
|
31
|
+
payload,
|
|
32
|
+
timestamp: Date.now()
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async function invokeIpc(channel, payload) {
|
|
36
|
+
const request = createRequest(payload);
|
|
37
|
+
const response = await import_electron.ipcRenderer.invoke(channel, request);
|
|
38
|
+
if (!response.success) {
|
|
39
|
+
const error = new Error(response.error?.message ?? "Unknown IPC error");
|
|
40
|
+
error.name = response.error?.code ?? "IpcError";
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
return response.data;
|
|
44
|
+
}
|
|
45
|
+
const sqlStorageApi = {
|
|
46
|
+
// ============================================================================
|
|
47
|
+
// Database Operations
|
|
48
|
+
// ============================================================================
|
|
49
|
+
/**
|
|
50
|
+
* Open the database connection.
|
|
51
|
+
*/
|
|
52
|
+
async open(options) {
|
|
53
|
+
const payload = { options };
|
|
54
|
+
await invokeIpc(import_channels.DB_CHANNELS.OPEN, payload);
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* Close the database connection.
|
|
58
|
+
*/
|
|
59
|
+
async close() {
|
|
60
|
+
await invokeIpc(import_channels.DB_CHANNELS.CLOSE, void 0);
|
|
61
|
+
},
|
|
62
|
+
/**
|
|
63
|
+
* Check if the database is open.
|
|
64
|
+
*/
|
|
65
|
+
async isOpen() {
|
|
66
|
+
return invokeIpc(import_channels.DB_CHANNELS.IS_OPEN, void 0);
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* Get adapter capabilities.
|
|
70
|
+
*/
|
|
71
|
+
async getCapabilities() {
|
|
72
|
+
return invokeIpc(import_channels.DB_CHANNELS.CAPABILITIES, void 0);
|
|
73
|
+
},
|
|
74
|
+
/**
|
|
75
|
+
* Execute a mutation statement (INSERT, UPDATE, DELETE).
|
|
76
|
+
*/
|
|
77
|
+
async run(statement, parameters) {
|
|
78
|
+
const payload = { statement, parameters };
|
|
79
|
+
return invokeIpc(import_channels.DB_CHANNELS.RUN, payload);
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* Get a single row.
|
|
83
|
+
*/
|
|
84
|
+
async get(statement, parameters) {
|
|
85
|
+
const payload = { statement, parameters };
|
|
86
|
+
return invokeIpc(import_channels.DB_CHANNELS.GET, payload);
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* Get all matching rows.
|
|
90
|
+
*/
|
|
91
|
+
async all(statement, parameters) {
|
|
92
|
+
const payload = { statement, parameters };
|
|
93
|
+
return invokeIpc(import_channels.DB_CHANNELS.ALL, payload);
|
|
94
|
+
},
|
|
95
|
+
/**
|
|
96
|
+
* Execute a SQL script.
|
|
97
|
+
*/
|
|
98
|
+
async exec(script) {
|
|
99
|
+
const payload = { script };
|
|
100
|
+
await invokeIpc(import_channels.DB_CHANNELS.EXEC, payload);
|
|
101
|
+
},
|
|
102
|
+
/**
|
|
103
|
+
* Execute batch operations.
|
|
104
|
+
*/
|
|
105
|
+
async batch(operations) {
|
|
106
|
+
const payload = { operations };
|
|
107
|
+
return invokeIpc(import_channels.DB_CHANNELS.BATCH, payload);
|
|
108
|
+
},
|
|
109
|
+
// ============================================================================
|
|
110
|
+
// Transaction Operations
|
|
111
|
+
// ============================================================================
|
|
112
|
+
/**
|
|
113
|
+
* Begin a transaction.
|
|
114
|
+
*/
|
|
115
|
+
async beginTransaction() {
|
|
116
|
+
return invokeIpc(import_channels.TRANSACTION_CHANNELS.BEGIN, void 0);
|
|
117
|
+
},
|
|
118
|
+
/**
|
|
119
|
+
* Commit a transaction.
|
|
120
|
+
*/
|
|
121
|
+
async commitTransaction(transactionId) {
|
|
122
|
+
await invokeIpc(import_channels.TRANSACTION_CHANNELS.COMMIT, { transactionId });
|
|
123
|
+
},
|
|
124
|
+
/**
|
|
125
|
+
* Rollback a transaction.
|
|
126
|
+
*/
|
|
127
|
+
async rollbackTransaction(transactionId) {
|
|
128
|
+
await invokeIpc(import_channels.TRANSACTION_CHANNELS.ROLLBACK, { transactionId });
|
|
129
|
+
},
|
|
130
|
+
/**
|
|
131
|
+
* Execute an operation within a transaction.
|
|
132
|
+
*/
|
|
133
|
+
async executeInTransaction(transactionId, statement, parameters) {
|
|
134
|
+
const payload = {
|
|
135
|
+
transactionId,
|
|
136
|
+
operation: { statement, parameters }
|
|
137
|
+
};
|
|
138
|
+
return invokeIpc(import_channels.TRANSACTION_CHANNELS.EXECUTE, payload);
|
|
139
|
+
},
|
|
140
|
+
/**
|
|
141
|
+
* Execute a callback within a transaction (convenience method).
|
|
142
|
+
* Automatically handles begin/commit/rollback.
|
|
143
|
+
*/
|
|
144
|
+
async transaction(fn) {
|
|
145
|
+
const ctx = await this.beginTransaction();
|
|
146
|
+
const trx = {
|
|
147
|
+
run: async (statement, parameters) => {
|
|
148
|
+
const result = await this.executeInTransaction(ctx.transactionId, statement, parameters);
|
|
149
|
+
return result;
|
|
150
|
+
},
|
|
151
|
+
get: async (statement, parameters) => {
|
|
152
|
+
const result = await this.executeInTransaction(ctx.transactionId, statement, parameters);
|
|
153
|
+
return Array.isArray(result) ? result[0] ?? null : null;
|
|
154
|
+
},
|
|
155
|
+
all: async (statement, parameters) => {
|
|
156
|
+
const result = await this.executeInTransaction(ctx.transactionId, statement, parameters);
|
|
157
|
+
return Array.isArray(result) ? result : [];
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
try {
|
|
161
|
+
const result = await fn(trx);
|
|
162
|
+
await this.commitTransaction(ctx.transactionId);
|
|
163
|
+
return result;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
await this.rollbackTransaction(ctx.transactionId).catch(() => {
|
|
166
|
+
});
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
// ============================================================================
|
|
171
|
+
// Sync Operations
|
|
172
|
+
// ============================================================================
|
|
173
|
+
/**
|
|
174
|
+
* Get sync status.
|
|
175
|
+
*/
|
|
176
|
+
async getSyncStatus() {
|
|
177
|
+
return invokeIpc(import_channels.SYNC_CHANNELS.STATUS, void 0);
|
|
178
|
+
},
|
|
179
|
+
/**
|
|
180
|
+
* Trigger manual sync.
|
|
181
|
+
*/
|
|
182
|
+
async triggerSync() {
|
|
183
|
+
await invokeIpc(import_channels.SYNC_CHANNELS.TRIGGER, void 0);
|
|
184
|
+
},
|
|
185
|
+
// ============================================================================
|
|
186
|
+
// Event Subscriptions
|
|
187
|
+
// ============================================================================
|
|
188
|
+
/**
|
|
189
|
+
* Subscribe to database change events.
|
|
190
|
+
*/
|
|
191
|
+
onDatabaseChange(callback) {
|
|
192
|
+
const handler = (_, event) => {
|
|
193
|
+
callback(event);
|
|
194
|
+
};
|
|
195
|
+
import_electron.ipcRenderer.on(import_channels.BROADCAST_CHANNELS.DB_CHANGE, handler);
|
|
196
|
+
return () => import_electron.ipcRenderer.removeListener(import_channels.BROADCAST_CHANNELS.DB_CHANGE, handler);
|
|
197
|
+
},
|
|
198
|
+
/**
|
|
199
|
+
* Subscribe to sync progress events.
|
|
200
|
+
*/
|
|
201
|
+
onSyncProgress(callback) {
|
|
202
|
+
const handler = (_, progress) => {
|
|
203
|
+
callback(progress);
|
|
204
|
+
};
|
|
205
|
+
import_electron.ipcRenderer.on(import_channels.SYNC_CHANNELS.PROGRESS, handler);
|
|
206
|
+
return () => import_electron.ipcRenderer.removeListener(import_channels.SYNC_CHANNELS.PROGRESS, handler);
|
|
207
|
+
},
|
|
208
|
+
/**
|
|
209
|
+
* Subscribe to sync complete events.
|
|
210
|
+
*/
|
|
211
|
+
onSyncComplete(callback) {
|
|
212
|
+
const handler = () => callback();
|
|
213
|
+
import_electron.ipcRenderer.on(import_channels.SYNC_CHANNELS.COMPLETE, handler);
|
|
214
|
+
return () => import_electron.ipcRenderer.removeListener(import_channels.SYNC_CHANNELS.COMPLETE, handler);
|
|
215
|
+
},
|
|
216
|
+
/**
|
|
217
|
+
* Subscribe to sync error events.
|
|
218
|
+
*/
|
|
219
|
+
onSyncError(callback) {
|
|
220
|
+
const handler = (_, error) => {
|
|
221
|
+
callback(new Error(error.message));
|
|
222
|
+
};
|
|
223
|
+
import_electron.ipcRenderer.on(import_channels.SYNC_CHANNELS.ERROR, handler);
|
|
224
|
+
return () => import_electron.ipcRenderer.removeListener(import_channels.SYNC_CHANNELS.ERROR, handler);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
if (import_electron.contextBridge) {
|
|
228
|
+
import_electron.contextBridge.exposeInMainWorld("sqlStorage", sqlStorageApi);
|
|
229
|
+
}
|
|
230
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
231
|
+
0 && (module.exports = {
|
|
232
|
+
sqlStorageApi
|
|
233
|
+
});
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database Corruption Detection and Auto-Repair.
|
|
3
|
+
*
|
|
4
|
+
* Provides integrity checking and automatic repair capabilities
|
|
5
|
+
* for SQLite databases. Detects corruption early and attempts
|
|
6
|
+
* recovery before data loss occurs.
|
|
7
|
+
*
|
|
8
|
+
* ## Detection Methods
|
|
9
|
+
* - SQLite integrity_check PRAGMA
|
|
10
|
+
* - Quick check (faster, less thorough)
|
|
11
|
+
* - Foreign key constraint validation
|
|
12
|
+
* - Index integrity verification
|
|
13
|
+
*
|
|
14
|
+
* ## Repair Strategies
|
|
15
|
+
* - VACUUM: Rebuilds entire database
|
|
16
|
+
* - REINDEX: Rebuilds all indexes
|
|
17
|
+
* - Export/Import: Last resort recovery
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const detector = new CorruptionDetector(adapter, {
|
|
22
|
+
* checkOnOpen: true,
|
|
23
|
+
* autoRepair: true,
|
|
24
|
+
* backupBeforeRepair: true,
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* const result = await detector.runFullCheck();
|
|
28
|
+
* if (!result.isHealthy) {
|
|
29
|
+
* await detector.attemptRepair();
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
import type { StorageAdapter } from '../../../core/contracts/index.js';
|
|
34
|
+
/**
|
|
35
|
+
* Integrity check level.
|
|
36
|
+
*/
|
|
37
|
+
export type IntegrityCheckLevel = 'quick' | 'full' | 'thorough';
|
|
38
|
+
/**
|
|
39
|
+
* Corruption detection configuration.
|
|
40
|
+
*/
|
|
41
|
+
export interface CorruptionDetectorConfig {
|
|
42
|
+
/** Run check when database is opened (default: true) */
|
|
43
|
+
checkOnOpen?: boolean;
|
|
44
|
+
/** Attempt automatic repair on corruption (default: true) */
|
|
45
|
+
autoRepair?: boolean;
|
|
46
|
+
/** Create backup before repair (default: true) */
|
|
47
|
+
backupBeforeRepair?: boolean;
|
|
48
|
+
/** Maximum time for integrity check in ms (default: 60000) */
|
|
49
|
+
checkTimeout?: number;
|
|
50
|
+
/** Check level (default: 'quick') */
|
|
51
|
+
defaultCheckLevel?: IntegrityCheckLevel;
|
|
52
|
+
/** Enable verbose logging (default: false) */
|
|
53
|
+
verbose?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Single corruption issue.
|
|
57
|
+
*/
|
|
58
|
+
export interface CorruptionIssue {
|
|
59
|
+
/** Issue type */
|
|
60
|
+
type: 'data' | 'index' | 'foreign_key' | 'structure' | 'unknown';
|
|
61
|
+
/** Affected table (if identifiable) */
|
|
62
|
+
table?: string;
|
|
63
|
+
/** Detailed message */
|
|
64
|
+
message: string;
|
|
65
|
+
/** Severity level */
|
|
66
|
+
severity: 'warning' | 'error' | 'critical';
|
|
67
|
+
/** Whether this issue is repairable */
|
|
68
|
+
repairable: boolean;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Result of an integrity check.
|
|
72
|
+
*/
|
|
73
|
+
export interface IntegrityCheckResult {
|
|
74
|
+
/** Whether the database is healthy */
|
|
75
|
+
isHealthy: boolean;
|
|
76
|
+
/** Check level performed */
|
|
77
|
+
level: IntegrityCheckLevel;
|
|
78
|
+
/** List of issues found */
|
|
79
|
+
issues: CorruptionIssue[];
|
|
80
|
+
/** Time taken in milliseconds */
|
|
81
|
+
durationMs: number;
|
|
82
|
+
/** Timestamp of check */
|
|
83
|
+
timestamp: number;
|
|
84
|
+
/** Pages checked (full check only) */
|
|
85
|
+
pagesChecked?: number;
|
|
86
|
+
/** Total database size in bytes */
|
|
87
|
+
databaseSize?: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Repair strategy.
|
|
91
|
+
*/
|
|
92
|
+
export type RepairStrategy = 'vacuum' | 'reindex' | 'export_import';
|
|
93
|
+
/**
|
|
94
|
+
* Result of a repair attempt.
|
|
95
|
+
*/
|
|
96
|
+
export interface RepairResult {
|
|
97
|
+
/** Whether repair was successful */
|
|
98
|
+
success: boolean;
|
|
99
|
+
/** Strategy used */
|
|
100
|
+
strategy: RepairStrategy;
|
|
101
|
+
/** Issues fixed */
|
|
102
|
+
issuesFixed: number;
|
|
103
|
+
/** Issues remaining */
|
|
104
|
+
issuesRemaining: number;
|
|
105
|
+
/** Time taken in milliseconds */
|
|
106
|
+
durationMs: number;
|
|
107
|
+
/** Backup path (if created) */
|
|
108
|
+
backupPath?: string;
|
|
109
|
+
/** Error message if failed */
|
|
110
|
+
error?: string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Database Corruption Detector.
|
|
114
|
+
*
|
|
115
|
+
* Detects and repairs SQLite database corruption.
|
|
116
|
+
*/
|
|
117
|
+
export declare class CorruptionDetector {
|
|
118
|
+
private readonly adapter;
|
|
119
|
+
private readonly config;
|
|
120
|
+
private lastCheck;
|
|
121
|
+
private repairHistory;
|
|
122
|
+
constructor(adapter: StorageAdapter, config?: CorruptionDetectorConfig);
|
|
123
|
+
/**
|
|
124
|
+
* Run a quick integrity check.
|
|
125
|
+
* Faster but less thorough than full check.
|
|
126
|
+
*/
|
|
127
|
+
runQuickCheck(): Promise<IntegrityCheckResult>;
|
|
128
|
+
/**
|
|
129
|
+
* Run a full integrity check.
|
|
130
|
+
* Checks all pages and structures.
|
|
131
|
+
*/
|
|
132
|
+
runFullCheck(): Promise<IntegrityCheckResult>;
|
|
133
|
+
/**
|
|
134
|
+
* Run a thorough integrity check.
|
|
135
|
+
* Includes foreign key and index validation.
|
|
136
|
+
*/
|
|
137
|
+
runThoroughCheck(): Promise<IntegrityCheckResult>;
|
|
138
|
+
/**
|
|
139
|
+
* Run an integrity check at the specified level.
|
|
140
|
+
*/
|
|
141
|
+
private runCheck;
|
|
142
|
+
/**
|
|
143
|
+
* Parse integrity check results into structured issues.
|
|
144
|
+
*/
|
|
145
|
+
private parseIntegrityResults;
|
|
146
|
+
/**
|
|
147
|
+
* Check foreign key constraints.
|
|
148
|
+
*/
|
|
149
|
+
private checkForeignKeys;
|
|
150
|
+
/**
|
|
151
|
+
* Check index integrity.
|
|
152
|
+
*/
|
|
153
|
+
private checkIndexes;
|
|
154
|
+
/**
|
|
155
|
+
* Attempt to repair the database.
|
|
156
|
+
*/
|
|
157
|
+
attemptRepair(strategy?: RepairStrategy): Promise<RepairResult>;
|
|
158
|
+
/**
|
|
159
|
+
* Select the best repair strategy based on issues found.
|
|
160
|
+
*/
|
|
161
|
+
private selectRepairStrategy;
|
|
162
|
+
/**
|
|
163
|
+
* Repair using VACUUM.
|
|
164
|
+
*/
|
|
165
|
+
private repairWithVacuum;
|
|
166
|
+
/**
|
|
167
|
+
* Repair using REINDEX.
|
|
168
|
+
*/
|
|
169
|
+
private repairWithReindex;
|
|
170
|
+
/**
|
|
171
|
+
* Repair using export/import.
|
|
172
|
+
* This is a last resort that exports all data and recreates the database.
|
|
173
|
+
*/
|
|
174
|
+
private repairWithExportImport;
|
|
175
|
+
/**
|
|
176
|
+
* Create a backup of the database.
|
|
177
|
+
*/
|
|
178
|
+
private createBackup;
|
|
179
|
+
/**
|
|
180
|
+
* Get the last integrity check result.
|
|
181
|
+
*/
|
|
182
|
+
getLastCheck(): IntegrityCheckResult | null;
|
|
183
|
+
/**
|
|
184
|
+
* Get repair history.
|
|
185
|
+
*/
|
|
186
|
+
getRepairHistory(): RepairResult[];
|
|
187
|
+
/**
|
|
188
|
+
* Check if the database appears healthy.
|
|
189
|
+
*/
|
|
190
|
+
isHealthy(): boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Get summary of database health.
|
|
193
|
+
*/
|
|
194
|
+
getHealthSummary(): {
|
|
195
|
+
isHealthy: boolean;
|
|
196
|
+
lastCheckAt: number | null;
|
|
197
|
+
issueCount: number;
|
|
198
|
+
repairAttempts: number;
|
|
199
|
+
successfulRepairs: number;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Log a message if verbose mode is enabled.
|
|
203
|
+
*/
|
|
204
|
+
private log;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Create a Corruption Detector.
|
|
208
|
+
*
|
|
209
|
+
* @param adapter - Storage adapter to monitor
|
|
210
|
+
* @param config - Detector configuration
|
|
211
|
+
* @returns CorruptionDetector instance
|
|
212
|
+
*/
|
|
213
|
+
export declare function createCorruptionDetector(adapter: StorageAdapter, config?: CorruptionDetectorConfig): CorruptionDetector;
|
|
214
|
+
//# sourceMappingURL=corruptionDetector.d.ts.map
|