@framers/sql-storage-adapter 0.7.2 → 0.7.3

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.
Files changed (184) hide show
  1. package/README.md +20 -0
  2. package/dist/adapters/electron/preload.cjs +289 -0
  3. package/dist/adapters/electron/renderer.d.ts +9 -0
  4. package/dist/adapters/electron/renderer.d.ts.map +1 -0
  5. package/dist/adapters/electron/renderer.js +8 -0
  6. package/dist/adapters/electron/renderer.js.map +1 -0
  7. package/dist/cjs/adapters/__tests__/indexedDbAdapter.spec.d.ts +2 -0
  8. package/dist/cjs/adapters/__tests__/indexedDbAdapter.spec.js +133 -0
  9. package/dist/cjs/adapters/baseStorageAdapter.d.ts +368 -0
  10. package/dist/cjs/adapters/baseStorageAdapter.js +744 -0
  11. package/dist/cjs/adapters/betterSqliteAdapter.d.ts +124 -0
  12. package/dist/cjs/adapters/betterSqliteAdapter.js +334 -0
  13. package/dist/cjs/adapters/capacitorSqliteAdapter.d.ts +83 -0
  14. package/dist/cjs/adapters/capacitorSqliteAdapter.js +250 -0
  15. package/dist/cjs/adapters/electron/electronMainAdapter.d.ts +251 -0
  16. package/dist/cjs/adapters/electron/electronMainAdapter.js +392 -0
  17. package/dist/cjs/adapters/electron/electronRendererAdapter.d.ts +177 -0
  18. package/dist/cjs/adapters/electron/electronRendererAdapter.js +283 -0
  19. package/dist/cjs/adapters/electron/index.d.ts +74 -0
  20. package/dist/cjs/adapters/electron/index.js +86 -0
  21. package/dist/cjs/adapters/electron/ipc/channels.d.ts +196 -0
  22. package/dist/cjs/adapters/electron/ipc/channels.js +127 -0
  23. package/dist/cjs/adapters/electron/ipc/index.d.ts +11 -0
  24. package/dist/cjs/adapters/electron/ipc/index.js +38 -0
  25. package/dist/cjs/adapters/electron/ipc/protocol.d.ts +78 -0
  26. package/dist/cjs/adapters/electron/ipc/protocol.js +341 -0
  27. package/dist/cjs/adapters/electron/ipc/types.d.ts +248 -0
  28. package/dist/cjs/adapters/electron/ipc/types.js +15 -0
  29. package/dist/cjs/adapters/electron/migration/autoMigrator.d.ts +184 -0
  30. package/dist/cjs/adapters/electron/migration/autoMigrator.js +441 -0
  31. package/dist/cjs/adapters/electron/migration/index.d.ts +9 -0
  32. package/dist/cjs/adapters/electron/migration/index.js +29 -0
  33. package/dist/cjs/adapters/electron/preload.d.ts +126 -0
  34. package/dist/cjs/adapters/electron/preload.js +233 -0
  35. package/dist/cjs/adapters/electron/recovery/corruptionDetector.d.ts +214 -0
  36. package/dist/cjs/adapters/electron/recovery/corruptionDetector.js +359 -0
  37. package/dist/cjs/adapters/electron/recovery/index.d.ts +11 -0
  38. package/dist/cjs/adapters/electron/recovery/index.js +34 -0
  39. package/dist/cjs/adapters/electron/recovery/walCheckpoint.d.ts +186 -0
  40. package/dist/cjs/adapters/electron/recovery/walCheckpoint.js +263 -0
  41. package/dist/cjs/adapters/electron/renderer.d.ts +9 -0
  42. package/dist/cjs/adapters/electron/renderer.js +33 -0
  43. package/dist/cjs/adapters/electron/window/index.d.ts +9 -0
  44. package/dist/cjs/adapters/electron/window/index.js +29 -0
  45. package/dist/cjs/adapters/electron/window/windowManager.d.ts +190 -0
  46. package/dist/cjs/adapters/electron/window/windowManager.js +321 -0
  47. package/dist/cjs/adapters/indexedDbAdapter.d.ts +490 -0
  48. package/dist/cjs/adapters/indexedDbAdapter.js +993 -0
  49. package/dist/cjs/adapters/postgresAdapter.d.ts +424 -0
  50. package/dist/cjs/adapters/postgresAdapter.js +889 -0
  51. package/dist/cjs/adapters/sqlJsAdapter.d.ts +64 -0
  52. package/dist/cjs/adapters/sqlJsAdapter.js +268 -0
  53. package/dist/cjs/adapters/supabase.d.ts +58 -0
  54. package/dist/cjs/adapters/supabase.js +401 -0
  55. package/dist/cjs/codecs/BrowserBlobCodec.d.ts +14 -0
  56. package/dist/cjs/codecs/BrowserBlobCodec.js +57 -0
  57. package/dist/cjs/codecs/NodeBlobCodec.d.ts +14 -0
  58. package/dist/cjs/codecs/NodeBlobCodec.js +59 -0
  59. package/dist/cjs/core/contracts/blobCodec.d.ts +15 -0
  60. package/dist/cjs/core/contracts/blobCodec.js +15 -0
  61. package/dist/cjs/core/contracts/context.d.ts +221 -0
  62. package/dist/cjs/core/contracts/context.js +15 -0
  63. package/dist/cjs/core/contracts/dialect.d.ts +154 -0
  64. package/dist/cjs/core/contracts/dialect.js +15 -0
  65. package/dist/cjs/core/contracts/events.d.ts +225 -0
  66. package/dist/cjs/core/contracts/events.js +15 -0
  67. package/dist/cjs/core/contracts/exporter.d.ts +13 -0
  68. package/dist/cjs/core/contracts/exporter.js +15 -0
  69. package/dist/cjs/core/contracts/extensions.d.ts +73 -0
  70. package/dist/cjs/core/contracts/extensions.js +15 -0
  71. package/dist/cjs/core/contracts/features.d.ts +25 -0
  72. package/dist/cjs/core/contracts/features.js +61 -0
  73. package/dist/cjs/core/contracts/fts.d.ts +66 -0
  74. package/dist/cjs/core/contracts/fts.js +15 -0
  75. package/dist/cjs/core/contracts/hooks.d.ts +481 -0
  76. package/dist/cjs/core/contracts/hooks.js +140 -0
  77. package/dist/cjs/core/contracts/index.d.ts +260 -0
  78. package/dist/cjs/core/contracts/index.js +41 -0
  79. package/dist/cjs/core/contracts/limitations.d.ts +46 -0
  80. package/dist/cjs/core/contracts/limitations.js +218 -0
  81. package/dist/cjs/core/contracts/performance.d.ts +308 -0
  82. package/dist/cjs/core/contracts/performance.js +144 -0
  83. package/dist/cjs/core/database.d.ts +220 -0
  84. package/dist/cjs/core/database.js +136 -0
  85. package/dist/cjs/core/portable.d.ts +23 -0
  86. package/dist/cjs/core/portable.js +66 -0
  87. package/dist/cjs/core/resolver.d.ts +77 -0
  88. package/dist/cjs/core/resolver.js +235 -0
  89. package/dist/cjs/dialects/PostgresDialect.d.ts +35 -0
  90. package/dist/cjs/dialects/PostgresDialect.js +143 -0
  91. package/dist/cjs/dialects/SqliteDialect.d.ts +35 -0
  92. package/dist/cjs/dialects/SqliteDialect.js +142 -0
  93. package/dist/cjs/dialects/shared.d.ts +17 -0
  94. package/dist/cjs/dialects/shared.js +90 -0
  95. package/dist/cjs/exporters/PostgresExporter.d.ts +14 -0
  96. package/dist/cjs/exporters/PostgresExporter.js +61 -0
  97. package/dist/cjs/exporters/SqliteFileExporter.d.ts +16 -0
  98. package/dist/cjs/exporters/SqliteFileExporter.js +43 -0
  99. package/dist/cjs/features/backup/cloudBackup.d.ts +219 -0
  100. package/dist/cjs/features/backup/cloudBackup.js +209 -0
  101. package/dist/cjs/features/kv/idb.d.ts +79 -0
  102. package/dist/cjs/features/kv/idb.js +32 -0
  103. package/dist/cjs/features/kv/index.d.ts +14 -0
  104. package/dist/cjs/features/kv/index.js +40 -0
  105. package/dist/cjs/features/kv/indexedDbKeyValueStore.d.ts +77 -0
  106. package/dist/cjs/features/kv/indexedDbKeyValueStore.js +116 -0
  107. package/dist/cjs/features/kv/keyValueStore.d.ts +48 -0
  108. package/dist/cjs/features/kv/keyValueStore.js +67 -0
  109. package/dist/cjs/features/kv/sqlKeyValueStore.d.ts +34 -0
  110. package/dist/cjs/features/kv/sqlKeyValueStore.js +81 -0
  111. package/dist/cjs/features/kv/valueCodec.d.ts +35 -0
  112. package/dist/cjs/features/kv/valueCodec.js +426 -0
  113. package/dist/cjs/features/migrations/dataExport.d.ts +77 -0
  114. package/dist/cjs/features/migrations/dataExport.js +194 -0
  115. package/dist/cjs/features/migrations/dataImport.d.ts +54 -0
  116. package/dist/cjs/features/migrations/dataImport.js +300 -0
  117. package/dist/cjs/features/migrations/migration.d.ts +89 -0
  118. package/dist/cjs/features/migrations/migration.js +187 -0
  119. package/dist/cjs/features/migrations/schemaMigrations.d.ts +93 -0
  120. package/dist/cjs/features/migrations/schemaMigrations.js +220 -0
  121. package/dist/cjs/features/sync/conflicts/conflictResolver.d.ts +222 -0
  122. package/dist/cjs/features/sync/conflicts/conflictResolver.js +366 -0
  123. package/dist/cjs/features/sync/conflicts/index.d.ts +9 -0
  124. package/dist/cjs/features/sync/conflicts/index.js +21 -0
  125. package/dist/cjs/features/sync/crossPlatformSync.d.ts +281 -0
  126. package/dist/cjs/features/sync/crossPlatformSync.js +551 -0
  127. package/dist/cjs/features/sync/devices/deviceManager.d.ts +243 -0
  128. package/dist/cjs/features/sync/devices/deviceManager.js +450 -0
  129. package/dist/cjs/features/sync/devices/index.d.ts +10 -0
  130. package/dist/cjs/features/sync/devices/index.js +21 -0
  131. package/dist/cjs/features/sync/index.d.ts +37 -0
  132. package/dist/cjs/features/sync/index.js +111 -0
  133. package/dist/cjs/features/sync/protocol/index.d.ts +11 -0
  134. package/dist/cjs/features/sync/protocol/index.js +23 -0
  135. package/dist/cjs/features/sync/protocol/messages.d.ts +348 -0
  136. package/dist/cjs/features/sync/protocol/messages.js +215 -0
  137. package/dist/cjs/features/sync/protocol/vectorClock.d.ts +164 -0
  138. package/dist/cjs/features/sync/protocol/vectorClock.js +256 -0
  139. package/dist/cjs/features/sync/syncManager.d.ts +348 -0
  140. package/dist/cjs/features/sync/syncManager.js +455 -0
  141. package/dist/cjs/features/sync/tables/index.d.ts +10 -0
  142. package/dist/cjs/features/sync/tables/index.js +21 -0
  143. package/dist/cjs/features/sync/tables/syncLogManager.d.ts +216 -0
  144. package/dist/cjs/features/sync/tables/syncLogManager.js +423 -0
  145. package/dist/cjs/features/sync/transport/httpTransport.d.ts +123 -0
  146. package/dist/cjs/features/sync/transport/httpTransport.js +346 -0
  147. package/dist/cjs/features/sync/transport/index.d.ts +12 -0
  148. package/dist/cjs/features/sync/transport/index.js +25 -0
  149. package/dist/cjs/features/sync/transport/transport.d.ts +259 -0
  150. package/dist/cjs/features/sync/transport/transport.js +163 -0
  151. package/dist/cjs/features/sync/transport/websocketTransport.d.ts +126 -0
  152. package/dist/cjs/features/sync/transport/websocketTransport.js +342 -0
  153. package/dist/cjs/fts/PostgresFts.d.ts +29 -0
  154. package/dist/cjs/fts/PostgresFts.js +77 -0
  155. package/dist/cjs/fts/SqliteFts5.d.ts +22 -0
  156. package/dist/cjs/fts/SqliteFts5.js +58 -0
  157. package/dist/cjs/index.d.ts +30 -0
  158. package/dist/cjs/index.js +101 -0
  159. package/dist/cjs/package.json +3 -0
  160. package/dist/cjs/shared/connectionGate.d.ts +94 -0
  161. package/dist/cjs/shared/connectionGate.js +77 -0
  162. package/dist/cjs/shared/errors.d.ts +23 -0
  163. package/dist/cjs/shared/errors.js +45 -0
  164. package/dist/cjs/shared/logger.d.ts +26 -0
  165. package/dist/cjs/shared/logger.js +40 -0
  166. package/dist/cjs/shared/parameterUtils.d.ts +16 -0
  167. package/dist/cjs/shared/parameterUtils.js +59 -0
  168. package/dist/cjs/shared/postgresTarget.d.ts +11 -0
  169. package/dist/cjs/shared/postgresTarget.js +30 -0
  170. package/dist/cjs/shared/segment.d.ts +43 -0
  171. package/dist/cjs/shared/segment.js +63 -0
  172. package/dist/cjs/shared/serializedTransaction.d.ts +14 -0
  173. package/dist/cjs/shared/serializedTransaction.js +74 -0
  174. package/dist/cjs/shared/splitSqlStatements.d.ts +27 -0
  175. package/dist/cjs/shared/splitSqlStatements.js +163 -0
  176. package/dist/cjs/shared/sqlPlaceholders.d.ts +48 -0
  177. package/dist/cjs/shared/sqlPlaceholders.js +263 -0
  178. package/dist/cjs/types/index.d.ts +29 -0
  179. package/dist/cjs/types/index.js +33 -0
  180. package/dist/core/portable.d.ts +23 -0
  181. package/dist/core/portable.d.ts.map +1 -0
  182. package/dist/core/portable.js +23 -0
  183. package/dist/core/portable.js.map +1 -0
  184. package/package.json +139 -24
@@ -0,0 +1,127 @@
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 channels_exports = {};
19
+ __export(channels_exports, {
20
+ BACKUP_CHANNELS: () => BACKUP_CHANNELS,
21
+ BROADCAST_CHANNELS: () => BROADCAST_CHANNELS,
22
+ DB_CHANNELS: () => DB_CHANNELS,
23
+ IPC_CHANNELS: () => IPC_CHANNELS,
24
+ MIGRATION_CHANNELS: () => MIGRATION_CHANNELS,
25
+ RECOVERY_CHANNELS: () => RECOVERY_CHANNELS,
26
+ SYNC_CHANNELS: () => SYNC_CHANNELS,
27
+ TRANSACTION_CHANNELS: () => TRANSACTION_CHANNELS
28
+ });
29
+ module.exports = __toCommonJS(channels_exports);
30
+ const DB_CHANNELS = {
31
+ /** Execute a mutation (INSERT/UPDATE/DELETE) */
32
+ RUN: "sql-storage:db:run",
33
+ /** Get a single row */
34
+ GET: "sql-storage:db:get",
35
+ /** Get all matching rows */
36
+ ALL: "sql-storage:db:all",
37
+ /** Execute a SQL script */
38
+ EXEC: "sql-storage:db:exec",
39
+ /** Execute batch operations */
40
+ BATCH: "sql-storage:db:batch",
41
+ /** Open database connection */
42
+ OPEN: "sql-storage:db:open",
43
+ /** Close database connection */
44
+ CLOSE: "sql-storage:db:close",
45
+ /** Check if database is open */
46
+ IS_OPEN: "sql-storage:db:is-open",
47
+ /** Get adapter capabilities */
48
+ CAPABILITIES: "sql-storage:db:capabilities"
49
+ };
50
+ const TRANSACTION_CHANNELS = {
51
+ /** Begin a transaction */
52
+ BEGIN: "sql-storage:transaction:begin",
53
+ /** Commit current transaction */
54
+ COMMIT: "sql-storage:transaction:commit",
55
+ /** Rollback current transaction */
56
+ ROLLBACK: "sql-storage:transaction:rollback",
57
+ /** Execute operation within transaction context */
58
+ EXECUTE: "sql-storage:transaction:execute"
59
+ };
60
+ const SYNC_CHANNELS = {
61
+ /** Get sync status */
62
+ STATUS: "sql-storage:sync:status",
63
+ /** Trigger manual sync */
64
+ TRIGGER: "sql-storage:sync:trigger",
65
+ /** Sync progress updates (main -> renderer) */
66
+ PROGRESS: "sql-storage:sync:progress",
67
+ /** Sync completed (main -> renderer) */
68
+ COMPLETE: "sql-storage:sync:complete",
69
+ /** Sync error (main -> renderer) */
70
+ ERROR: "sql-storage:sync:error"
71
+ };
72
+ const BACKUP_CHANNELS = {
73
+ /** Trigger cloud backup */
74
+ TRIGGER: "sql-storage:backup:trigger",
75
+ /** Backup progress (main -> renderer) */
76
+ PROGRESS: "sql-storage:backup:progress",
77
+ /** Backup completed (main -> renderer) */
78
+ COMPLETE: "sql-storage:backup:complete",
79
+ /** Restore from backup */
80
+ RESTORE: "sql-storage:backup:restore",
81
+ /** List available backups */
82
+ LIST: "sql-storage:backup:list"
83
+ };
84
+ const RECOVERY_CHANNELS = {
85
+ /** Run integrity check */
86
+ CHECK_INTEGRITY: "sql-storage:recovery:check-integrity",
87
+ /** Trigger WAL checkpoint */
88
+ WAL_CHECKPOINT: "sql-storage:recovery:wal-checkpoint",
89
+ /** Repair database */
90
+ REPAIR: "sql-storage:recovery:repair"
91
+ };
92
+ const MIGRATION_CHANNELS = {
93
+ /** Run pending migrations */
94
+ RUN: "sql-storage:migration:run",
95
+ /** Get migration status */
96
+ STATUS: "sql-storage:migration:status",
97
+ /** Rollback last migration */
98
+ ROLLBACK: "sql-storage:migration:rollback"
99
+ };
100
+ const BROADCAST_CHANNELS = {
101
+ /** Database change notification */
102
+ DB_CHANGE: "sql-storage:broadcast:db-change",
103
+ /** Connection state change */
104
+ CONNECTION_STATE: "sql-storage:broadcast:connection-state",
105
+ /** Error notification */
106
+ ERROR: "sql-storage:broadcast:error"
107
+ };
108
+ const IPC_CHANNELS = {
109
+ db: DB_CHANNELS,
110
+ transaction: TRANSACTION_CHANNELS,
111
+ sync: SYNC_CHANNELS,
112
+ backup: BACKUP_CHANNELS,
113
+ recovery: RECOVERY_CHANNELS,
114
+ migration: MIGRATION_CHANNELS,
115
+ broadcast: BROADCAST_CHANNELS
116
+ };
117
+ // Annotate the CommonJS export names for ESM import in node:
118
+ 0 && (module.exports = {
119
+ BACKUP_CHANNELS,
120
+ BROADCAST_CHANNELS,
121
+ DB_CHANNELS,
122
+ IPC_CHANNELS,
123
+ MIGRATION_CHANNELS,
124
+ RECOVERY_CHANNELS,
125
+ SYNC_CHANNELS,
126
+ TRANSACTION_CHANNELS
127
+ });
@@ -0,0 +1,11 @@
1
+ /**
2
+ * IPC Module for Electron SQL Storage Adapter.
3
+ *
4
+ * Provides type-safe IPC communication between main and renderer processes.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ export * from './channels.js';
9
+ export * from './types.js';
10
+ export { IpcProtocolManager, protocolManager, initializeIpcProtocol, disposeIpcProtocol, } from './protocol.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,38 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var ipc_exports = {};
20
+ __export(ipc_exports, {
21
+ IpcProtocolManager: () => import_protocol.IpcProtocolManager,
22
+ disposeIpcProtocol: () => import_protocol.disposeIpcProtocol,
23
+ initializeIpcProtocol: () => import_protocol.initializeIpcProtocol,
24
+ protocolManager: () => import_protocol.protocolManager
25
+ });
26
+ module.exports = __toCommonJS(ipc_exports);
27
+ __reExport(ipc_exports, require("./channels.js"), module.exports);
28
+ __reExport(ipc_exports, require("./types.js"), module.exports);
29
+ var import_protocol = require("./protocol.js");
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ IpcProtocolManager,
33
+ disposeIpcProtocol,
34
+ initializeIpcProtocol,
35
+ protocolManager,
36
+ ...require("./channels.js"),
37
+ ...require("./types.js")
38
+ });
@@ -0,0 +1,78 @@
1
+ /**
2
+ * IPC Protocol Handlers for Electron SQL Storage Adapter.
3
+ *
4
+ * Registers IPC handlers in the main process to handle database
5
+ * operations from renderer processes. Ensures type-safe communication
6
+ * and proper error handling.
7
+ */
8
+ import type { StorageAdapter } from '../../../core/contracts/index.js';
9
+ /**
10
+ * IPC Protocol Manager.
11
+ *
12
+ * Manages IPC communication between main and renderer processes
13
+ * for database operations. Handles request routing, error handling,
14
+ * and change broadcasting.
15
+ */
16
+ export declare class IpcProtocolManager {
17
+ private adapter;
18
+ private activeTransactions;
19
+ private handlersRegistered;
20
+ /**
21
+ * Initialize the protocol manager with a storage adapter.
22
+ */
23
+ initialize(adapter: StorageAdapter): void;
24
+ /**
25
+ * Register all IPC handlers.
26
+ */
27
+ private registerHandlers;
28
+ /**
29
+ * Unregister all IPC handlers.
30
+ */
31
+ dispose(): void;
32
+ private handleOpen;
33
+ private handleClose;
34
+ private handleIsOpen;
35
+ private handleCapabilities;
36
+ private handleRun;
37
+ private handleGet;
38
+ private handleAll;
39
+ private handleExec;
40
+ private handleBatch;
41
+ private handleTransactionBegin;
42
+ private handleTransactionCommit;
43
+ private handleTransactionRollback;
44
+ private handleTransactionExecute;
45
+ /**
46
+ * Wrap handler with error handling and response formatting.
47
+ */
48
+ private wrapHandler;
49
+ /**
50
+ * Format error for IPC response.
51
+ */
52
+ private formatError;
53
+ /**
54
+ * Broadcast database change to all windows except sender.
55
+ */
56
+ private broadcastDbChange;
57
+ /**
58
+ * Detect mutation type from SQL statement.
59
+ */
60
+ private detectMutationType;
61
+ /**
62
+ * Extract table names from SQL statement.
63
+ */
64
+ private extractTables;
65
+ }
66
+ /**
67
+ * Singleton protocol manager instance.
68
+ */
69
+ export declare const protocolManager: IpcProtocolManager;
70
+ /**
71
+ * Initialize IPC protocol with the given adapter.
72
+ */
73
+ export declare function initializeIpcProtocol(adapter: StorageAdapter): void;
74
+ /**
75
+ * Dispose IPC protocol handlers.
76
+ */
77
+ export declare function disposeIpcProtocol(): void;
78
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1,341 @@
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 protocol_exports = {};
19
+ __export(protocol_exports, {
20
+ IpcProtocolManager: () => IpcProtocolManager,
21
+ disposeIpcProtocol: () => disposeIpcProtocol,
22
+ initializeIpcProtocol: () => initializeIpcProtocol,
23
+ protocolManager: () => protocolManager
24
+ });
25
+ module.exports = __toCommonJS(protocol_exports);
26
+ var import_electron = require("electron");
27
+ var import_channels = require("./channels.js");
28
+ class IpcProtocolManager {
29
+ constructor() {
30
+ this.adapter = null;
31
+ this.activeTransactions = /* @__PURE__ */ new Map();
32
+ this.handlersRegistered = false;
33
+ }
34
+ /**
35
+ * Initialize the protocol manager with a storage adapter.
36
+ */
37
+ initialize(adapter) {
38
+ this.adapter = adapter;
39
+ this.registerHandlers();
40
+ }
41
+ /**
42
+ * Register all IPC handlers.
43
+ */
44
+ registerHandlers() {
45
+ if (this.handlersRegistered) {
46
+ console.warn("[IpcProtocol] Handlers already registered");
47
+ return;
48
+ }
49
+ import_electron.ipcMain.handle(import_channels.DB_CHANNELS.OPEN, this.handleOpen.bind(this));
50
+ import_electron.ipcMain.handle(import_channels.DB_CHANNELS.CLOSE, this.handleClose.bind(this));
51
+ import_electron.ipcMain.handle(import_channels.DB_CHANNELS.IS_OPEN, this.handleIsOpen.bind(this));
52
+ import_electron.ipcMain.handle(import_channels.DB_CHANNELS.CAPABILITIES, this.handleCapabilities.bind(this));
53
+ import_electron.ipcMain.handle(import_channels.DB_CHANNELS.RUN, this.handleRun.bind(this));
54
+ import_electron.ipcMain.handle(import_channels.DB_CHANNELS.GET, this.handleGet.bind(this));
55
+ import_electron.ipcMain.handle(import_channels.DB_CHANNELS.ALL, this.handleAll.bind(this));
56
+ import_electron.ipcMain.handle(import_channels.DB_CHANNELS.EXEC, this.handleExec.bind(this));
57
+ import_electron.ipcMain.handle(import_channels.DB_CHANNELS.BATCH, this.handleBatch.bind(this));
58
+ import_electron.ipcMain.handle(import_channels.TRANSACTION_CHANNELS.BEGIN, this.handleTransactionBegin.bind(this));
59
+ import_electron.ipcMain.handle(import_channels.TRANSACTION_CHANNELS.COMMIT, this.handleTransactionCommit.bind(this));
60
+ import_electron.ipcMain.handle(import_channels.TRANSACTION_CHANNELS.ROLLBACK, this.handleTransactionRollback.bind(this));
61
+ import_electron.ipcMain.handle(import_channels.TRANSACTION_CHANNELS.EXECUTE, this.handleTransactionExecute.bind(this));
62
+ this.handlersRegistered = true;
63
+ }
64
+ /**
65
+ * Unregister all IPC handlers.
66
+ */
67
+ dispose() {
68
+ if (!this.handlersRegistered)
69
+ return;
70
+ import_electron.ipcMain.removeHandler(import_channels.DB_CHANNELS.OPEN);
71
+ import_electron.ipcMain.removeHandler(import_channels.DB_CHANNELS.CLOSE);
72
+ import_electron.ipcMain.removeHandler(import_channels.DB_CHANNELS.IS_OPEN);
73
+ import_electron.ipcMain.removeHandler(import_channels.DB_CHANNELS.CAPABILITIES);
74
+ import_electron.ipcMain.removeHandler(import_channels.DB_CHANNELS.RUN);
75
+ import_electron.ipcMain.removeHandler(import_channels.DB_CHANNELS.GET);
76
+ import_electron.ipcMain.removeHandler(import_channels.DB_CHANNELS.ALL);
77
+ import_electron.ipcMain.removeHandler(import_channels.DB_CHANNELS.EXEC);
78
+ import_electron.ipcMain.removeHandler(import_channels.DB_CHANNELS.BATCH);
79
+ import_electron.ipcMain.removeHandler(import_channels.TRANSACTION_CHANNELS.BEGIN);
80
+ import_electron.ipcMain.removeHandler(import_channels.TRANSACTION_CHANNELS.COMMIT);
81
+ import_electron.ipcMain.removeHandler(import_channels.TRANSACTION_CHANNELS.ROLLBACK);
82
+ import_electron.ipcMain.removeHandler(import_channels.TRANSACTION_CHANNELS.EXECUTE);
83
+ this.handlersRegistered = false;
84
+ }
85
+ // ============================================================================
86
+ // Database Operation Handlers
87
+ // ============================================================================
88
+ async handleOpen(_event, request) {
89
+ return this.wrapHandler(request, async () => {
90
+ await this.adapter.open(request.payload.options);
91
+ });
92
+ }
93
+ async handleClose(_event, request) {
94
+ return this.wrapHandler(request, async () => {
95
+ await this.adapter.close();
96
+ });
97
+ }
98
+ async handleIsOpen(_event, request) {
99
+ return this.wrapHandler(request, async () => {
100
+ if ("isOpen" in this.adapter && typeof this.adapter.isOpen === "function") {
101
+ return this.adapter.isOpen();
102
+ }
103
+ try {
104
+ await this.adapter.get("SELECT 1");
105
+ return true;
106
+ } catch {
107
+ return false;
108
+ }
109
+ });
110
+ }
111
+ async handleCapabilities(_event, request) {
112
+ return this.wrapHandler(request, async () => {
113
+ return Array.from(this.adapter.capabilities);
114
+ });
115
+ }
116
+ async handleRun(event, request) {
117
+ return this.wrapHandler(request, async () => {
118
+ const result = await this.adapter.run(request.payload.statement, request.payload.parameters);
119
+ this.broadcastDbChange(event, {
120
+ type: this.detectMutationType(request.payload.statement),
121
+ tables: this.extractTables(request.payload.statement),
122
+ changes: result.changes,
123
+ timestamp: Date.now(),
124
+ sourceWindowId: import_electron.BrowserWindow.fromWebContents(event.sender)?.id
125
+ });
126
+ return result;
127
+ });
128
+ }
129
+ async handleGet(_event, request) {
130
+ return this.wrapHandler(request, async () => {
131
+ return this.adapter.get(request.payload.statement, request.payload.parameters);
132
+ });
133
+ }
134
+ async handleAll(_event, request) {
135
+ return this.wrapHandler(request, async () => {
136
+ return this.adapter.all(request.payload.statement, request.payload.parameters);
137
+ });
138
+ }
139
+ async handleExec(event, request) {
140
+ return this.wrapHandler(request, async () => {
141
+ await this.adapter.exec(request.payload.script);
142
+ this.broadcastDbChange(event, {
143
+ type: "transaction",
144
+ tables: [],
145
+ changes: 0,
146
+ timestamp: Date.now(),
147
+ sourceWindowId: import_electron.BrowserWindow.fromWebContents(event.sender)?.id
148
+ });
149
+ });
150
+ }
151
+ async handleBatch(event, request) {
152
+ return this.wrapHandler(request, async () => {
153
+ if (!this.adapter.batch) {
154
+ throw new Error("Batch operations not supported by this adapter");
155
+ }
156
+ const result = await this.adapter.batch(request.payload.operations);
157
+ this.broadcastDbChange(event, {
158
+ type: "transaction",
159
+ tables: request.payload.operations.flatMap((op) => this.extractTables(op.statement)),
160
+ changes: result.successful,
161
+ timestamp: Date.now(),
162
+ sourceWindowId: import_electron.BrowserWindow.fromWebContents(event.sender)?.id
163
+ });
164
+ return result;
165
+ });
166
+ }
167
+ // ============================================================================
168
+ // Transaction Handlers
169
+ // ============================================================================
170
+ async handleTransactionBegin(event, request) {
171
+ return this.wrapHandler(request, async () => {
172
+ const transactionId = `trx_${Date.now()}_${Math.random().toString(36).slice(2)}`;
173
+ const windowId = import_electron.BrowserWindow.fromWebContents(event.sender)?.id ?? 0;
174
+ await this.adapter.exec("BEGIN IMMEDIATE");
175
+ const context = {
176
+ transactionId,
177
+ active: true,
178
+ startedAt: Date.now()
179
+ };
180
+ this.activeTransactions.set(transactionId, {
181
+ id: transactionId,
182
+ startedAt: context.startedAt,
183
+ windowId
184
+ });
185
+ return context;
186
+ });
187
+ }
188
+ async handleTransactionCommit(event, request) {
189
+ return this.wrapHandler(request, async () => {
190
+ const trx = this.activeTransactions.get(request.payload.transactionId);
191
+ if (!trx) {
192
+ throw new Error(`Transaction ${request.payload.transactionId} not found`);
193
+ }
194
+ await this.adapter.exec("COMMIT");
195
+ this.activeTransactions.delete(request.payload.transactionId);
196
+ this.broadcastDbChange(event, {
197
+ type: "transaction",
198
+ tables: [],
199
+ changes: 0,
200
+ timestamp: Date.now(),
201
+ sourceWindowId: import_electron.BrowserWindow.fromWebContents(event.sender)?.id
202
+ });
203
+ });
204
+ }
205
+ async handleTransactionRollback(_event, request) {
206
+ return this.wrapHandler(request, async () => {
207
+ const trx = this.activeTransactions.get(request.payload.transactionId);
208
+ if (!trx) {
209
+ throw new Error(`Transaction ${request.payload.transactionId} not found`);
210
+ }
211
+ await this.adapter.exec("ROLLBACK");
212
+ this.activeTransactions.delete(request.payload.transactionId);
213
+ });
214
+ }
215
+ async handleTransactionExecute(_event, request) {
216
+ return this.wrapHandler(request, async () => {
217
+ const trx = this.activeTransactions.get(request.payload.transactionId);
218
+ if (!trx) {
219
+ throw new Error(`Transaction ${request.payload.transactionId} not found`);
220
+ }
221
+ const { statement, parameters } = request.payload.operation;
222
+ const upperStatement = statement.trim().toUpperCase();
223
+ if (upperStatement.startsWith("SELECT")) {
224
+ return this.adapter.all(statement, parameters);
225
+ } else {
226
+ return this.adapter.run(statement, parameters);
227
+ }
228
+ });
229
+ }
230
+ // ============================================================================
231
+ // Helper Methods
232
+ // ============================================================================
233
+ /**
234
+ * Wrap handler with error handling and response formatting.
235
+ */
236
+ async wrapHandler(request, handler) {
237
+ const startTime = Date.now();
238
+ if (!this.adapter) {
239
+ return {
240
+ messageId: request.messageId,
241
+ success: false,
242
+ error: this.formatError(new Error("Adapter not initialized")),
243
+ duration: Date.now() - startTime
244
+ };
245
+ }
246
+ try {
247
+ const data = await handler();
248
+ return {
249
+ messageId: request.messageId,
250
+ success: true,
251
+ data,
252
+ duration: Date.now() - startTime
253
+ };
254
+ } catch (error) {
255
+ return {
256
+ messageId: request.messageId,
257
+ success: false,
258
+ error: this.formatError(error),
259
+ duration: Date.now() - startTime
260
+ };
261
+ }
262
+ }
263
+ /**
264
+ * Format error for IPC response.
265
+ */
266
+ formatError(error) {
267
+ if (error instanceof Error) {
268
+ return {
269
+ code: error.name || "ERROR",
270
+ message: error.message,
271
+ stack: process.env.NODE_ENV === "development" ? error.stack : void 0,
272
+ cause: error.cause
273
+ };
274
+ }
275
+ return {
276
+ code: "UNKNOWN_ERROR",
277
+ message: String(error)
278
+ };
279
+ }
280
+ /**
281
+ * Broadcast database change to all windows except sender.
282
+ */
283
+ broadcastDbChange(event, change) {
284
+ const senderWindow = import_electron.BrowserWindow.fromWebContents(event.sender);
285
+ const allWindows = import_electron.BrowserWindow.getAllWindows();
286
+ for (const win of allWindows) {
287
+ if (win.id !== senderWindow?.id && !win.isDestroyed()) {
288
+ win.webContents.send(import_channels.BROADCAST_CHANNELS.DB_CHANGE, change);
289
+ }
290
+ }
291
+ }
292
+ /**
293
+ * Detect mutation type from SQL statement.
294
+ */
295
+ detectMutationType(statement) {
296
+ const upper = statement.trim().toUpperCase();
297
+ if (upper.startsWith("INSERT"))
298
+ return "insert";
299
+ if (upper.startsWith("UPDATE"))
300
+ return "update";
301
+ if (upper.startsWith("DELETE"))
302
+ return "delete";
303
+ return "transaction";
304
+ }
305
+ /**
306
+ * Extract table names from SQL statement.
307
+ */
308
+ extractTables(statement) {
309
+ const tables = [];
310
+ const patterns = [
311
+ /FROM\s+([^\s,;(]+)/gi,
312
+ /INSERT\s+INTO\s+([^\s(]+)/i,
313
+ /UPDATE\s+([^\s]+)/i,
314
+ /DELETE\s+FROM\s+([^\s]+)/i,
315
+ /JOIN\s+([^\s]+)/gi
316
+ ];
317
+ for (const pattern of patterns) {
318
+ const matches = statement.matchAll(pattern);
319
+ for (const match of matches) {
320
+ if (match[1]) {
321
+ tables.push(match[1].toLowerCase().replace(/["`[\]]/g, ""));
322
+ }
323
+ }
324
+ }
325
+ return [...new Set(tables)];
326
+ }
327
+ }
328
+ const protocolManager = new IpcProtocolManager();
329
+ function initializeIpcProtocol(adapter) {
330
+ protocolManager.initialize(adapter);
331
+ }
332
+ function disposeIpcProtocol() {
333
+ protocolManager.dispose();
334
+ }
335
+ // Annotate the CommonJS export names for ESM import in node:
336
+ 0 && (module.exports = {
337
+ IpcProtocolManager,
338
+ disposeIpcProtocol,
339
+ initializeIpcProtocol,
340
+ protocolManager
341
+ });