@framers/sql-storage-adapter 0.7.1 → 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 (192) hide show
  1. package/README.md +43 -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/dist/features/migrations/schemaMigrations.d.ts +93 -0
  185. package/dist/features/migrations/schemaMigrations.d.ts.map +1 -0
  186. package/dist/features/migrations/schemaMigrations.js +216 -0
  187. package/dist/features/migrations/schemaMigrations.js.map +1 -0
  188. package/dist/index.d.ts +1 -0
  189. package/dist/index.d.ts.map +1 -1
  190. package/dist/index.js +1 -0
  191. package/dist/index.js.map +1 -1
  192. package/package.json +139 -24
@@ -0,0 +1,221 @@
1
+ /**
2
+ * Runtime context and introspection types for storage adapters.
3
+ *
4
+ * These types enable runtime inspection of adapter capabilities,
5
+ * connection state, and performance characteristics without requiring
6
+ * developers to manually check capability flags.
7
+ */
8
+ import type { StorageAdapter, StorageCapability } from './index.js';
9
+ import type { PerformanceMetrics } from './extensions.js';
10
+ /**
11
+ * Type of database connection.
12
+ */
13
+ export type ConnectionType = 'file' | 'memory' | 'network';
14
+ /**
15
+ * Database engine identifier.
16
+ */
17
+ export type DatabaseEngine = 'sqlite' | 'postgres' | 'mysql' | 'sqljs' | 'capacitor' | 'supabase' | 'electron';
18
+ /**
19
+ * Adapter identifier used by the resolver.
20
+ */
21
+ export type AdapterKind = 'postgres' | 'better-sqlite3' | 'capacitor' | 'sqljs' | 'indexeddb' | 'supabase' | 'electron-main' | 'electron-renderer';
22
+ /**
23
+ * Information about the current database connection.
24
+ */
25
+ export interface ConnectionInfo {
26
+ /** Type of connection (file-based, in-memory, or network) */
27
+ type: ConnectionType;
28
+ /** Database engine being used */
29
+ engine: DatabaseEngine;
30
+ /** Engine version (if available) */
31
+ version?: string;
32
+ /** File path for file-based databases */
33
+ filePath?: string;
34
+ /** Host for network databases */
35
+ host?: string;
36
+ /** Database name for network databases */
37
+ database?: string;
38
+ /** Whether the connection is read-only */
39
+ readOnly: boolean;
40
+ /** When the connection was established */
41
+ connectedAt?: Date;
42
+ }
43
+ /**
44
+ * Concurrency model supported by the adapter.
45
+ */
46
+ export type ConcurrencyModel = 'single' | 'pooled' | 'unlimited';
47
+ /**
48
+ * Persistence model of the adapter.
49
+ */
50
+ export type PersistenceModel = 'memory' | 'file' | 'network';
51
+ /**
52
+ * Performance characteristics of an adapter.
53
+ */
54
+ export interface PerformanceCharacteristics {
55
+ /** Concurrency model */
56
+ concurrency: ConcurrencyModel;
57
+ /** Persistence model */
58
+ persistence: PersistenceModel;
59
+ /** Supported transaction isolation levels */
60
+ transactionIsolation: string[];
61
+ /** Whether the adapter uses connection pooling */
62
+ usesConnectionPool: boolean;
63
+ /** Whether queries are executed asynchronously */
64
+ asyncExecution: boolean;
65
+ }
66
+ /**
67
+ * Adapter-specific limitations and constraints.
68
+ */
69
+ export interface AdapterLimitations {
70
+ /** Maximum number of concurrent connections (if applicable) */
71
+ maxConnections?: number;
72
+ /** Maximum length of a single SQL statement (in bytes/characters) */
73
+ maxStatementLength?: number;
74
+ /** Maximum number of operations in a single batch */
75
+ maxBatchSize?: number;
76
+ /** Maximum size of a single parameter value (in bytes) */
77
+ maxParameterSize?: number;
78
+ /** Data types supported by this adapter */
79
+ supportedDataTypes: string[];
80
+ /** Features that are explicitly not supported */
81
+ unsupportedFeatures: string[];
82
+ /** Performance characteristics */
83
+ performanceCharacteristics: PerformanceCharacteristics;
84
+ /** Additional adapter-specific constraints */
85
+ constraints?: Record<string, unknown>;
86
+ }
87
+ /**
88
+ * Current health and status of the adapter.
89
+ */
90
+ export interface AdapterStatus {
91
+ /** Whether the adapter is functioning correctly */
92
+ healthy: boolean;
93
+ /** Whether the adapter is currently connected */
94
+ connected: boolean;
95
+ /** Last error encountered (if any) */
96
+ lastError?: Error;
97
+ /** Timestamp of last successful query */
98
+ lastQuery?: Date;
99
+ /** Total number of queries executed */
100
+ totalQueries: number;
101
+ /** Total number of errors encountered */
102
+ errors: number;
103
+ /** Time since adapter was opened (in milliseconds) */
104
+ uptime: number;
105
+ /** Performance metrics (if available) */
106
+ metrics?: PerformanceMetrics;
107
+ }
108
+ /**
109
+ * Runtime context providing introspection into the current adapter.
110
+ *
111
+ * This interface provides a high-level API for querying adapter
112
+ * capabilities, connection state, and performance without requiring
113
+ * manual capability flag checking.
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * const context = adapter.context;
118
+ *
119
+ * // Simple boolean checks
120
+ * if (context.supportsBatch) {
121
+ * await adapter.batch(operations);
122
+ * }
123
+ *
124
+ * // Get detailed status
125
+ * const status = context.getStatus();
126
+ * console.log(`Healthy: ${status.healthy}, Queries: ${status.totalQueries}`);
127
+ *
128
+ * // Get limitations
129
+ * const limits = context.getLimitations();
130
+ * console.log(`Max batch size: ${limits.maxBatchSize}`);
131
+ * ```
132
+ */
133
+ export interface AdapterContext {
134
+ /** Reference to the underlying adapter */
135
+ readonly adapter: StorageAdapter;
136
+ /** Adapter kind identifier */
137
+ readonly kind: AdapterKind;
138
+ /** Set of capabilities supported by this adapter */
139
+ readonly capabilities: ReadonlySet<StorageCapability>;
140
+ /** Whether the adapter is currently open/connected */
141
+ readonly isOpen: boolean;
142
+ /** Whether the adapter supports synchronous operations */
143
+ readonly supportsSync: boolean;
144
+ /** Whether the adapter supports ACID transactions */
145
+ readonly supportsTransactions: boolean;
146
+ /** Whether the adapter supports batch operations */
147
+ readonly supportsBatch: boolean;
148
+ /** Whether the adapter supports prepared statements */
149
+ readonly supportsPrepared: boolean;
150
+ /** Whether the adapter supports streaming results */
151
+ readonly supportsStreaming: boolean;
152
+ /** Whether the adapter supports Write-Ahead Logging */
153
+ readonly supportsWAL: boolean;
154
+ /** Whether the adapter supports native JSON operations */
155
+ readonly supportsJSON: boolean;
156
+ /** Whether the adapter supports array data types */
157
+ readonly supportsArrays: boolean;
158
+ /** Whether the adapter supports concurrent connections */
159
+ readonly supportsConcurrent: boolean;
160
+ /** Whether the adapter persists data across restarts */
161
+ readonly supportsPersistence: boolean;
162
+ /** Information about the current connection */
163
+ readonly connectionInfo: ConnectionInfo;
164
+ /**
165
+ * Check if a specific capability is supported.
166
+ *
167
+ * @param capability - The capability to check
168
+ * @returns True if the capability is supported
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * if (context.hasCapability('streaming')) {
173
+ * // Use streaming API
174
+ * }
175
+ * ```
176
+ */
177
+ hasCapability(capability: StorageCapability): boolean;
178
+ /**
179
+ * Require a specific capability, throwing an error if not supported.
180
+ *
181
+ * @param capability - The required capability
182
+ * @throws {Error} If the capability is not supported
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * context.requiresCapability('transactions');
187
+ * // Safe to use transactions now
188
+ * await adapter.transaction(async (trx) => { ... });
189
+ * ```
190
+ */
191
+ requiresCapability(capability: StorageCapability): void;
192
+ /**
193
+ * Get detailed limitations and constraints for this adapter.
194
+ *
195
+ * @returns Adapter-specific limitations
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * const limits = context.getLimitations();
200
+ * if (operations.length > limits.maxBatchSize) {
201
+ * // Split into chunks
202
+ * }
203
+ * ```
204
+ */
205
+ getLimitations(): AdapterLimitations;
206
+ /**
207
+ * Get current health and status information.
208
+ *
209
+ * @returns Current adapter status
210
+ *
211
+ * @example
212
+ * ```typescript
213
+ * const status = context.getStatus();
214
+ * if (!status.healthy) {
215
+ * logger.error('Database unhealthy', status.lastError);
216
+ * }
217
+ * ```
218
+ */
219
+ getStatus(): AdapterStatus;
220
+ }
221
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var context_exports = {};
15
+ module.exports = __toCommonJS(context_exports);
@@ -0,0 +1,154 @@
1
+ /**
2
+ * SQL dialect abstraction for cross-platform SQL generation.
3
+ *
4
+ * Each method returns a SQL string fragment or full statement.
5
+ * Implementations are pure string transformers — no database calls.
6
+ *
7
+ * Expressions and placeholders passed in are inserted as written; numbers,
8
+ * units, types and JSON paths are checked, so nothing a caller passes as a
9
+ * value reaches the SQL text unchecked.
10
+ */
11
+ export interface SqlDialect {
12
+ /** Dialect identifier. */
13
+ readonly name: 'sqlite' | 'postgres';
14
+ /**
15
+ * Generate an INSERT OR IGNORE statement.
16
+ * SQLite: `INSERT OR IGNORE INTO t (a, b) VALUES (?, ?)`
17
+ * Postgres: `INSERT INTO t (a, b) VALUES ($1, $2) ON CONFLICT DO NOTHING`
18
+ */
19
+ insertOrIgnore(table: string, columns: string[], placeholders: string[]): string;
20
+ /**
21
+ * Generate an upsert on the primary key that updates the existing row in
22
+ * place, on both engines:
23
+ * `INSERT INTO t (a, b) VALUES (?, ?) ON CONFLICT (a) DO UPDATE SET b = excluded.b`.
24
+ * The row keeps the columns the statement does not name, and its dependents.
25
+ * When every column is the key, the statement does nothing on a conflict.
26
+ *
27
+ * @param primaryKey - The conflict target. Defaults to the first column.
28
+ */
29
+ insertOrReplace(table: string, columns: string[], placeholders: string[], primaryKey?: string): string;
30
+ /**
31
+ * An upsert with an explicit conflict target that updates the existing row
32
+ * in place on both engines (SQLite 3.24 and later):
33
+ * `INSERT INTO t (a, b, c) VALUES (?, ?, ?) ON CONFLICT (a) DO UPDATE SET b = excluded.b, c = excluded.c`.
34
+ *
35
+ * @param conflictColumns - The unique or primary-key columns of the conflict target.
36
+ * @param updateColumns - The columns to update; by default every column outside the target. None left: DO NOTHING.
37
+ */
38
+ upsert(table: string, columns: string[], placeholders: string[], conflictColumns: string[], updateColumns?: string[]): string;
39
+ /**
40
+ * Generate a JSON field extraction expression.
41
+ * SQLite: `json_extract(col, '$.key')`
42
+ * Postgres: `(col::jsonb)->>'key'`
43
+ */
44
+ jsonExtract(column: string, jsonPath: string): string;
45
+ /**
46
+ * A value at `jsonPath` (`$.a.b`, `$.a[0]`) read as text, an integer or a
47
+ * real, with the same result on both engines; `json` reads the JSON value
48
+ * itself (jsonb on PostgreSQL, JSON text on SQLite), for use inside another
49
+ * expression such as jsonArrayContains. A path outside that form is refused.
50
+ */
51
+ jsonExtractAs(column: string, jsonPath: string, type: JsonValueType): string;
52
+ /**
53
+ * Whether the JSON array `jsonArray` holds the value `valueExpr`, compared
54
+ * as text, so a string or a number matches on both engines.
55
+ */
56
+ jsonArrayContains(jsonArray: string, valueExpr: string): string;
57
+ /**
58
+ * Generate a null-coalesce expression.
59
+ * SQLite: `ifnull(expr, fallback)`
60
+ * Postgres: `COALESCE(expr, fallback)`
61
+ */
62
+ ifnull(expr: string, fallback: string): string;
63
+ /**
64
+ * Column definition for an auto-incrementing integer primary key.
65
+ * SQLite: `INTEGER PRIMARY KEY AUTOINCREMENT`
66
+ * Postgres: `INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY`
67
+ */
68
+ autoIncrementPrimaryKey(): string;
69
+ /**
70
+ * A column type for DDL. PostgreSQL: TEXT, INTEGER, BIGINT, DOUBLE
71
+ * PRECISION, BOOLEAN, TIMESTAMPTZ, JSONB, UUID, BYTEA. SQLite: TEXT,
72
+ * INTEGER, INTEGER, REAL, INTEGER, TEXT, TEXT, TEXT, BLOB. The values a
73
+ * column returns follow each engine (a PostgreSQL boolean is `true`, a
74
+ * SQLite one 1); `typeParsers` and the bound-value conversions narrow that.
75
+ */
76
+ columnType(kind: ColumnKind): string;
77
+ /**
78
+ * Generate a PRAGMA statement or equivalent.
79
+ * SQLite: `PRAGMA key = value`
80
+ * Postgres: returns null (skip — Postgres enforces FKs by default, etc.)
81
+ */
82
+ pragma(key: string, value: string): string | null;
83
+ /**
84
+ * Parameter placeholder for the given 0-based index.
85
+ * SQLite: `?`
86
+ * Postgres: `$1`, `$2`, etc.
87
+ */
88
+ placeholder(index: number): string;
89
+ /**
90
+ * The current time. PostgreSQL: `now()` (timestamptz). SQLite: ISO 8601
91
+ * UTC text with milliseconds, the form a bound Date takes, so text
92
+ * comparisons with stored times order correctly.
93
+ */
94
+ now(): string;
95
+ /**
96
+ * `expr` cast to a type both engines read the same way. `timestamp` is
97
+ * timestamptz on PostgreSQL and ISO 8601 UTC text on SQLite.
98
+ */
99
+ cast(expr: string, type: CastType): string;
100
+ /**
101
+ * The time `expr` moved by `amount` units (negative moves back), as an
102
+ * exact number of seconds on both engines. PostgreSQL: timestamptz.
103
+ * SQLite: ISO 8601 UTC text.
104
+ */
105
+ addInterval(expr: string, amount: number, unit: IntervalUnit): string;
106
+ /**
107
+ * The start of the minute, hour, day, month or year that holds `expr`, in
108
+ * UTC, as ISO 8601 text (`2026-10-15T00:00:00.000Z`) on both engines.
109
+ */
110
+ dateBucket(unit: DateBucketUnit, expr: string): string;
111
+ /**
112
+ * Case-insensitive LIKE. PostgreSQL: ILIKE. SQLite: LIKE, which folds only
113
+ * ASCII letters.
114
+ */
115
+ ilike(expr: string, pattern: string): string;
116
+ /** `expr IN (...)` over the given placeholders or expressions; an empty list matches nothing. */
117
+ inList(expr: string, items: string[]): string;
118
+ /**
119
+ * Membership in an array bound as one parameter. PostgreSQL: `= ANY(param)`
120
+ * (pg binds a JavaScript array as an array). SQLite: `IN (SELECT value
121
+ * FROM json_each(param))` over the JSON text the array binds as.
122
+ */
123
+ inArray(expr: string, arrayParam: string): string;
124
+ /**
125
+ * A row-lock clause to append to a SELECT. PostgreSQL: ` FOR UPDATE` or
126
+ * ` FOR SHARE`, with ` SKIP LOCKED` or ` NOWAIT`. SQLite: `''`, since a
127
+ * write transaction there holds the whole database.
128
+ */
129
+ rowLock(mode: 'update' | 'share', wait?: 'wait' | 'skipLocked' | 'noWait'): string;
130
+ /**
131
+ * A statement that takes a transaction-scoped advisory lock on an integer
132
+ * key, released at COMMIT or ROLLBACK. PostgreSQL:
133
+ * `SELECT pg_advisory_xact_lock(key)`. SQLite: null, to skip, since its
134
+ * write transactions already run one at a time.
135
+ */
136
+ advisoryTransactionLock(keyExpr: string): string | null;
137
+ /** The largest of the expressions, NULLs skipped on both engines; NULL when all are. */
138
+ greatest(...exprs: string[]): string;
139
+ /** The smallest of the expressions, NULLs skipped on both engines; NULL when all are. */
140
+ least(...exprs: string[]): string;
141
+ /** A random version 4 UUID as text. PostgreSQL: `gen_random_uuid()` (13 and later). SQLite: built from randomblob(). */
142
+ uuid(): string;
143
+ }
144
+ /** The types jsonExtractAs reads. */
145
+ export type JsonValueType = 'text' | 'integer' | 'real' | 'json';
146
+ /** The types cast takes. */
147
+ export type CastType = 'text' | 'integer' | 'real' | 'timestamp';
148
+ /** The units addInterval takes. Months and years are left out: the engines clamp a month's end differently. */
149
+ export type IntervalUnit = 'seconds' | 'minutes' | 'hours' | 'days';
150
+ /** The units dateBucket takes. */
151
+ export type DateBucketUnit = 'minute' | 'hour' | 'day' | 'month' | 'year';
152
+ /** The column kinds columnType declares. */
153
+ export type ColumnKind = 'text' | 'integer' | 'bigint' | 'real' | 'boolean' | 'timestamp' | 'json' | 'uuid' | 'blob';
154
+ //# sourceMappingURL=dialect.d.ts.map
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var dialect_exports = {};
15
+ module.exports = __toCommonJS(dialect_exports);
@@ -0,0 +1,225 @@
1
+ /**
2
+ * Event system types for adapter lifecycle and query monitoring.
3
+ *
4
+ * These types enable applications to subscribe to adapter events
5
+ * for logging, monitoring, debugging, and analytics purposes.
6
+ */
7
+ import type { StorageParameters } from './index.js';
8
+ import type { AdapterContext } from './context.js';
9
+ /**
10
+ * Event emitted when a connection is opened.
11
+ */
12
+ export interface ConnectionOpenedEvent {
13
+ type: 'connection:opened';
14
+ context: AdapterContext;
15
+ timestamp: Date;
16
+ }
17
+ /**
18
+ * Event emitted when a connection is closed.
19
+ */
20
+ export interface ConnectionClosedEvent {
21
+ type: 'connection:closed';
22
+ context: AdapterContext;
23
+ timestamp: Date;
24
+ }
25
+ /**
26
+ * Event emitted when a connection error occurs.
27
+ */
28
+ export interface ConnectionErrorEvent {
29
+ type: 'connection:error';
30
+ error: Error;
31
+ context: AdapterContext;
32
+ timestamp: Date;
33
+ }
34
+ /**
35
+ * Event emitted when a query starts execution.
36
+ */
37
+ export interface QueryStartEvent {
38
+ type: 'query:start';
39
+ statement: string;
40
+ parameters?: StorageParameters;
41
+ timestamp: Date;
42
+ queryId?: string;
43
+ }
44
+ /**
45
+ * Event emitted when a query completes successfully.
46
+ */
47
+ export interface QueryCompleteEvent {
48
+ type: 'query:complete';
49
+ statement: string;
50
+ duration: number;
51
+ rows?: number;
52
+ timestamp: Date;
53
+ queryId?: string;
54
+ }
55
+ /**
56
+ * Event emitted when a query fails.
57
+ */
58
+ export interface QueryErrorEvent {
59
+ type: 'query:error';
60
+ statement: string;
61
+ error: Error;
62
+ duration: number;
63
+ timestamp: Date;
64
+ queryId?: string;
65
+ }
66
+ /**
67
+ * Event emitted when a transaction starts.
68
+ */
69
+ export interface TransactionStartEvent {
70
+ type: 'transaction:start';
71
+ id: string;
72
+ timestamp: Date;
73
+ }
74
+ /**
75
+ * Event emitted when a transaction commits successfully.
76
+ */
77
+ export interface TransactionCommitEvent {
78
+ type: 'transaction:commit';
79
+ id: string;
80
+ duration: number;
81
+ timestamp: Date;
82
+ }
83
+ /**
84
+ * Event emitted when a transaction is rolled back.
85
+ */
86
+ export interface TransactionRollbackEvent {
87
+ type: 'transaction:rollback';
88
+ id: string;
89
+ error?: Error;
90
+ timestamp: Date;
91
+ }
92
+ /**
93
+ * Event emitted when a slow query is detected.
94
+ */
95
+ export interface PerformanceSlowQueryEvent {
96
+ type: 'performance:slow-query';
97
+ statement: string;
98
+ duration: number;
99
+ threshold: number;
100
+ timestamp: Date;
101
+ }
102
+ /**
103
+ * Event emitted when a cache hit occurs.
104
+ */
105
+ export interface CacheHitEvent {
106
+ type: 'cache:hit';
107
+ key: string;
108
+ statement: string;
109
+ timestamp: Date;
110
+ }
111
+ /**
112
+ * Event emitted when a cache miss occurs.
113
+ */
114
+ export interface CacheMissEvent {
115
+ type: 'cache:miss';
116
+ key: string;
117
+ statement: string;
118
+ timestamp: Date;
119
+ }
120
+ /**
121
+ * Event emitted when the cache is cleared.
122
+ */
123
+ export interface CacheClearEvent {
124
+ type: 'cache:clear';
125
+ entriesCleared: number;
126
+ timestamp: Date;
127
+ }
128
+ /**
129
+ * Union of all possible adapter events.
130
+ */
131
+ export type AdapterEvent = ConnectionOpenedEvent | ConnectionClosedEvent | ConnectionErrorEvent | QueryStartEvent | QueryCompleteEvent | QueryErrorEvent | TransactionStartEvent | TransactionCommitEvent | TransactionRollbackEvent | PerformanceSlowQueryEvent | CacheHitEvent | CacheMissEvent | CacheClearEvent;
132
+ /**
133
+ * Extract event type from AdapterEvent discriminated union.
134
+ */
135
+ export type AdapterEventType = AdapterEvent['type'];
136
+ /**
137
+ * Listener function for adapter events.
138
+ */
139
+ export type AdapterEventListener<T extends AdapterEvent = AdapterEvent> = (event: T) => void;
140
+ /**
141
+ * Unsubscribe function returned by event listeners.
142
+ */
143
+ export type UnsubscribeFn = () => void;
144
+ /**
145
+ * Event emitter interface for storage adapters.
146
+ *
147
+ * Provides a simple pub/sub mechanism for monitoring adapter
148
+ * lifecycle and query execution.
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * // Subscribe to all query errors
153
+ * const unsubscribe = events.on('query:error', (event) => {
154
+ * console.error('Query failed:', event.statement, event.error);
155
+ * });
156
+ *
157
+ * // Later, unsubscribe
158
+ * unsubscribe();
159
+ *
160
+ * // Subscribe to slow queries
161
+ * events.on('performance:slow-query', (event) => {
162
+ * if (event.duration > 5000) {
163
+ * analytics.track('very_slow_query', {
164
+ * statement: event.statement,
165
+ * duration: event.duration
166
+ * });
167
+ * }
168
+ * });
169
+ * ```
170
+ */
171
+ export interface AdapterEventEmitter {
172
+ /**
173
+ * Subscribe to an event type.
174
+ *
175
+ * @param eventType - The type of event to listen for
176
+ * @param listener - Callback function to invoke when event occurs
177
+ * @returns Unsubscribe function
178
+ */
179
+ on<T extends AdapterEventType>(eventType: T, listener: AdapterEventListener<Extract<AdapterEvent, {
180
+ type: T;
181
+ }>>): UnsubscribeFn;
182
+ /**
183
+ * Subscribe to an event type once (auto-unsubscribes after first call).
184
+ *
185
+ * @param eventType - The type of event to listen for
186
+ * @param listener - Callback function to invoke when event occurs
187
+ * @returns Unsubscribe function
188
+ */
189
+ once<T extends AdapterEventType>(eventType: T, listener: AdapterEventListener<Extract<AdapterEvent, {
190
+ type: T;
191
+ }>>): UnsubscribeFn;
192
+ /**
193
+ * Emit an event to all subscribers.
194
+ *
195
+ * @param event - The event to emit
196
+ */
197
+ emit(event: AdapterEvent): void;
198
+ /**
199
+ * Remove all event listeners.
200
+ */
201
+ removeAllListeners(): void;
202
+ /**
203
+ * Remove all listeners for a specific event type.
204
+ *
205
+ * @param eventType - The event type to clear listeners for
206
+ */
207
+ removeListeners(eventType: AdapterEventType): void;
208
+ /**
209
+ * Get the number of listeners for an event type.
210
+ *
211
+ * @param eventType - The event type to count listeners for
212
+ * @returns Number of active listeners
213
+ */
214
+ listenerCount(eventType: AdapterEventType): number;
215
+ }
216
+ /**
217
+ * Helper type for creating type-safe event emitter implementations.
218
+ */
219
+ export interface EventEmitterOptions {
220
+ /** Maximum number of listeners before warning (default: 10) */
221
+ maxListeners?: number;
222
+ /** Whether to log warnings for too many listeners */
223
+ warnOnMaxListeners?: boolean;
224
+ }
225
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var events_exports = {};
15
+ module.exports = __toCommonJS(events_exports);
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Database export abstraction.
3
+ *
4
+ * SQLite: VACUUM INTO or db.export().
5
+ * Postgres: pg_dump via child_process.
6
+ */
7
+ export interface IDatabaseExporter {
8
+ /** Export the full database to a file at the given path. */
9
+ exportToFile(outputPath: string): Promise<void>;
10
+ /** Export the full database as raw bytes. */
11
+ exportToBytes(): Promise<Uint8Array>;
12
+ }
13
+ //# sourceMappingURL=exporter.d.ts.map
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var exporter_exports = {};
15
+ module.exports = __toCommonJS(exporter_exports);