@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,424 @@
1
+ import type { StorageAdapter, StorageCapability, StorageOpenOptions, StorageParameters, StorageRunResult } from '../core/contracts/index.js';
2
+ /** What the adapter reads from the answer to a query. */
3
+ export interface PostgresQueryResultLike {
4
+ rows: unknown[];
5
+ rowCount?: number | null;
6
+ }
7
+ /** A connection checked out of a pool: the part of pg's `PoolClient` the adapter uses. */
8
+ export interface PostgresPoolClientLike {
9
+ query(text: string, values?: unknown[]): Promise<PostgresQueryResultLike>;
10
+ release(error?: Error | boolean): void;
11
+ /**
12
+ * pg's client is an event emitter: while the adapter holds a client, it
13
+ * listens for the client's connection error. A client without these emits
14
+ * nothing for the adapter to hear.
15
+ */
16
+ on?(event: 'error', listener: (error: Error) => void): unknown;
17
+ removeListener?(event: 'error', listener: (error: Error) => void): unknown;
18
+ }
19
+ /**
20
+ * The part of pg's `Pool` the adapter uses. A `Pool` from `pg` is one; so is
21
+ * any object with these members.
22
+ */
23
+ export interface PostgresPoolLike {
24
+ query(text: string, values?: unknown[]): Promise<PostgresQueryResultLike>;
25
+ connect(): Promise<PostgresPoolClientLike>;
26
+ end(): Promise<void>;
27
+ on?(event: 'error', listener: (error: Error) => void): unknown;
28
+ removeListener?(event: 'error', listener: (error: Error) => void): unknown;
29
+ /** True once `end()` has been called; pg's Pool sets it. */
30
+ readonly ending?: boolean;
31
+ /** True once the pool has ended; pg's Pool sets it. */
32
+ readonly ended?: boolean;
33
+ /** Connections the pool holds, checked out or idle; pg's Pool counts them. */
34
+ readonly totalCount?: number;
35
+ /** Connections idle in the pool. */
36
+ readonly idleCount?: number;
37
+ /** Callers waiting for a connection. */
38
+ readonly waitingCount?: number;
39
+ }
40
+ /**
41
+ * Configuration options for PostgreSQL adapter.
42
+ * Supports both connection strings and granular configuration.
43
+ */
44
+ export interface PostgresAdapterOptions {
45
+ /** PostgreSQL connection string (e.g., 'postgresql://user:pass@host:5432/dbname') */
46
+ connectionString?: string;
47
+ /** Host name or IP address (default: localhost) */
48
+ host?: string;
49
+ /** Port number (default: 5432) */
50
+ port?: number;
51
+ /** Database name */
52
+ database?: string;
53
+ /** Username for authentication */
54
+ user?: string;
55
+ /** Password for authentication */
56
+ password?: string;
57
+ /** Enable SSL/TLS connection (recommended for remote) */
58
+ ssl?: boolean | {
59
+ rejectUnauthorized?: boolean;
60
+ ca?: string;
61
+ cert?: string;
62
+ key?: string;
63
+ };
64
+ /** Connection pool size (default: 10) */
65
+ max?: number;
66
+ /** Minimum pool size (default: 0) */
67
+ min?: number;
68
+ /** Idle timeout in ms (default: 10000) */
69
+ idleTimeoutMillis?: number;
70
+ /** Connection timeout in ms (default: 0 = no timeout) */
71
+ connectionTimeoutMillis?: number;
72
+ /** Application name for connection tracking */
73
+ application_name?: string;
74
+ /** Statement timeout in ms (0 = no timeout) */
75
+ statement_timeout?: number;
76
+ /** Query timeout in ms (0 = no timeout) */
77
+ query_timeout?: number;
78
+ /**
79
+ * Let Node exit while every connection in the pool is idle (pg's
80
+ * `allowExitOnIdle`). Default: false, so idle connections keep the process
81
+ * running until `idleTimeoutMillis` closes them or `close()` ends the pool.
82
+ */
83
+ allowExitOnIdle?: boolean;
84
+ /**
85
+ * How this pool's connections decode the column types whose pg defaults
86
+ * surprise JavaScript code, through pg's per-client type parsers. Each field
87
+ * left out keeps pg's default. A value it does not know fails open(). A pool
88
+ * of the caller's decodes with the `types` it was made with, so this cannot
89
+ * be given with `pool`.
90
+ */
91
+ typeParsers?: PostgresTypeParsers;
92
+ /**
93
+ * A schema of its own for the adapter's tables. Every connection of the
94
+ * adapter's pool starts with `search_path` set to the segment, then
95
+ * `public`, so the tables it creates without a schema land in the segment,
96
+ * and the types, functions and operators of extensions in `public`
97
+ * (pgvector's `vector`, `<->`) still resolve. `open()` creates the schema
98
+ * when it is missing, and a `CREATE EXTENSION` that names no schema installs
99
+ * the extension where it would without a segment, in `public`.
100
+ *
101
+ * A name the segment does not hold falls through to `public`: create a
102
+ * segment's tables before reading them (`CREATE TABLE IF NOT EXISTS` creates
103
+ * one in the segment even when `public` has a table of that name), and name
104
+ * the segment in a DROP or ALTER that `public` could also answer.
105
+ *
106
+ * Lower-case letters, digits and underscores; not `public`,
107
+ * `information_schema` or a name beginning with `pg_`. A segment cannot be
108
+ * combined with `pool`, nor with a connection string that sets its own
109
+ * `options` startup parameter: pg sends those in place of the segment's.
110
+ */
111
+ segment?: string;
112
+ /**
113
+ * A pool the caller made (a `pg` `Pool`) for the adapter to run on, instead
114
+ * of making one. The adapter runs on it from the start: no `open()` is
115
+ * needed, and `open()` after `close()` takes it up again. The connection
116
+ * settings above apply when a pool is made, so none of them, nor `segment`,
117
+ * can be given with it.
118
+ */
119
+ pool?: PostgresPoolLike;
120
+ /**
121
+ * Whether `close()` ends `pool`. False by default: the pool is its caller's,
122
+ * and `close()` leaves it open. Pass true when the adapter is the pool's one
123
+ * holder and closing the adapter is how the pool should end; `close()` then
124
+ * ends it once, however often it is called.
125
+ */
126
+ ownsPool?: boolean;
127
+ /**
128
+ * Called with the error an idle connection of the pool reports (the server
129
+ * ended it, the network dropped). pg's Pool raises such an error as an event
130
+ * that, with no listener, ends the process. On a pool the adapter makes or
131
+ * owns, the adapter listens even without `onError` and logs one warning per
132
+ * error; on a pool of its caller's that it does not own, it listens only
133
+ * when given `onError`, and takes its listener off again on `close()`.
134
+ */
135
+ onError?: (error: Error) => void;
136
+ }
137
+ /** Per-pool decoding of int8, numeric, date and json columns. Each field left out keeps pg's default. */
138
+ export interface PostgresTypeParsers {
139
+ /** int8 / bigint (OID 20). pg's default is 'string'. 'number' refuses a value past `Number.MAX_SAFE_INTEGER`. */
140
+ int8?: 'string' | 'number' | 'bigint';
141
+ /** numeric / decimal (OID 1700). pg's default is 'string'. 'number' is a double, so it can round. */
142
+ numeric?: 'string' | 'number';
143
+ /** date (OID 1082). pg's default is 'date', a Date at local midnight; 'string' keeps `YYYY-MM-DD`. */
144
+ date?: 'date' | 'string';
145
+ /** json (OID 114) and jsonb (OID 3802). pg's default is 'parse'; 'string' keeps the text, as SQLite returns it. */
146
+ json?: 'parse' | 'string';
147
+ }
148
+ /** The isolation levels of PostgreSQL's `BEGIN`. */
149
+ export type PostgresIsolationLevel = 'read uncommitted' | 'read committed' | 'repeatable read' | 'serializable';
150
+ /** How a PostgreSQL transaction begins. Left out, each mode is the server's default. */
151
+ export interface PostgresTransactionOptions {
152
+ /** `BEGIN ISOLATION LEVEL ...`. The server's default is `read committed` unless configured otherwise. */
153
+ isolationLevel?: PostgresIsolationLevel;
154
+ /** `READ ONLY` when true, `READ WRITE` when false. */
155
+ readOnly?: boolean;
156
+ /** `DEFERRABLE` when true, `NOT DEFERRABLE` when false. It changes only serializable read-only transactions. */
157
+ deferrable?: boolean;
158
+ }
159
+ /** The counts of a Postgres adapter's connection pool. */
160
+ export interface PostgresPoolStats {
161
+ /** Connections the pool holds, checked out or idle. */
162
+ total: number;
163
+ /** Connections idle in the pool. */
164
+ idle: number;
165
+ /** Callers waiting for a connection. */
166
+ waiting: number;
167
+ }
168
+ /**
169
+ * One pooled connection, held for a `withConnection()` callback. Its
170
+ * statements run outside a transaction unless the callback opens one, and
171
+ * session state (`SET`, session advisory locks, temporary tables) lasts until
172
+ * the connection closes.
173
+ */
174
+ export interface PostgresConnection extends StorageAdapter {
175
+ /** Runs `fn` in a transaction on this connection. One transaction at a time. */
176
+ transaction<T>(fn: (trx: StorageAdapter) => Promise<T>, options?: PostgresTransactionOptions): Promise<T>;
177
+ }
178
+ /**
179
+ * PostgreSQL adapter for production-grade SQL operations.
180
+ *
181
+ * ## Performance Characteristics
182
+ * - Connection pooling for efficient resource usage
183
+ * - Excellent concurrent access with MVCC
184
+ * - Optimized for complex queries and large datasets
185
+ * - ~10,000 queries/second with connection pooling
186
+ *
187
+ * ## Advantages
188
+ * - Full SQL feature set (CTEs, window functions, etc.)
189
+ * - Native JSON/JSONB support
190
+ * - Robust replication and backup options
191
+ * - Battle-tested in production environments
192
+ * - Secure remote connections with SSL/TLS
193
+ *
194
+ * ## Limitations
195
+ * - Requires separate server process
196
+ * - Network latency for remote connections
197
+ * - Higher resource consumption than SQLite
198
+ * - Configuration complexity for optimal performance
199
+ *
200
+ * ## When to Use
201
+ * - Production web applications
202
+ * - Multi-user systems
203
+ * - When you need advanced SQL features
204
+ * - Cloud deployments (AWS RDS, Heroku, Supabase, etc.)
205
+ * - Remote database access
206
+ *
207
+ * ## Remote Connection Examples
208
+ *
209
+ * ### Connection String (Recommended)
210
+ * ```typescript
211
+ * const db = createPostgresAdapter({
212
+ * connectionString: 'postgresql://user:password@db.example.com:5432/mydb?sslmode=require'
213
+ * });
214
+ * ```
215
+ *
216
+ * ### Granular Configuration
217
+ * ```typescript
218
+ * const db = createPostgresAdapter({
219
+ * host: 'db.example.com',
220
+ * port: 5432,
221
+ * database: 'mydb',
222
+ * user: 'dbuser',
223
+ * password: 'secure_password',
224
+ * ssl: true, // Enable SSL for security
225
+ * max: 20, // Connection pool size
226
+ * statement_timeout: 30000 // 30 second timeout
227
+ * });
228
+ * ```
229
+ *
230
+ * ### Cloud Provider Examples
231
+ *
232
+ * #### AWS RDS
233
+ * ```typescript
234
+ * const db = createPostgresAdapter({
235
+ * host: 'mydb.abc123.us-east-1.rds.amazonaws.com',
236
+ * port: 5432,
237
+ * database: 'postgres',
238
+ * user: 'admin',
239
+ * password: process.env.RDS_PASSWORD,
240
+ * ssl: { rejectUnauthorized: true }
241
+ * });
242
+ * ```
243
+ *
244
+ * #### Heroku Postgres
245
+ * ```typescript
246
+ * const db = createPostgresAdapter({
247
+ * connectionString: process.env.DATABASE_URL,
248
+ * ssl: { rejectUnauthorized: false } // Heroku uses self-signed certs
249
+ * });
250
+ * ```
251
+ *
252
+ * #### Supabase
253
+ * ```typescript
254
+ * const db = createPostgresAdapter({
255
+ * connectionString: process.env.SUPABASE_DB_URL,
256
+ * ssl: true
257
+ * });
258
+ * ```
259
+ *
260
+ * #### DigitalOcean Managed Database
261
+ * ```typescript
262
+ * const db = createPostgresAdapter({
263
+ * host: 'db-postgresql-nyc3-12345.ondigitalocean.com',
264
+ * port: 25060,
265
+ * database: 'defaultdb',
266
+ * user: 'doadmin',
267
+ * password: process.env.DO_DB_PASSWORD,
268
+ * ssl: { rejectUnauthorized: true, ca: process.env.DO_CA_CERT }
269
+ * });
270
+ * ```
271
+ *
272
+ * ### A pool the host already holds
273
+ * ```typescript
274
+ * const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
275
+ * // The adapter runs on the host's pool; close() leaves it open.
276
+ * const db = new PostgresAdapter({ pool, onError: (error) => console.warn('idle connection failed', error) });
277
+ * ```
278
+ *
279
+ * ### A segment: the adapter's tables in a schema of their own
280
+ * ```typescript
281
+ * const agentos = createPostgresAdapter({ connectionString: process.env.DATABASE_URL, segment: 'agentos' });
282
+ * ```
283
+ *
284
+ * ## Connection failures
285
+ * - The pool drops a connection that fails, and the next query opens a new one.
286
+ * - The adapter never falls back to SQLite. `resolveStorageAdapter()` without
287
+ * `strict` tries its next candidate when Postgres fails to open; with
288
+ * `strict`, and in `createDatabase()` given a Postgres URL, it throws.
289
+ *
290
+ * ## Pool control
291
+ * - `withConnection(fn)` holds one connection for `fn`: session settings,
292
+ * session advisory locks, and statements that must run outside a
293
+ * transaction.
294
+ * - `getPoolStats()` counts the pool's connections and waiting callers.
295
+ * - `transaction(fn, { isolationLevel, readOnly, deferrable })` sets how the
296
+ * transaction begins.
297
+ * - `allowExitOnIdle` lets Node exit while the pool is idle.
298
+ */
299
+ /**
300
+ * Production-grade PostgreSQL adapter backed by pg.Pool.
301
+ *
302
+ * Safe to import in browser bundles; will only throw if `open()` is invoked
303
+ * in a browser environment.
304
+ */
305
+ export declare class PostgresAdapter implements StorageAdapter {
306
+ readonly kind = "postgres";
307
+ readonly capabilities: ReadonlySet<StorageCapability>;
308
+ private options;
309
+ /**
310
+ * The pool statements run on, or null while the adapter is closed. Hosts
311
+ * written against 0.6 hand the adapter a Pool by setting this field before
312
+ * `open()`; the adapter then runs on that Pool and ends it on `close()`, as
313
+ * 0.6 did. Keep its name, and keep it a plain field that starts as null.
314
+ */
315
+ private pool;
316
+ private pgModule;
317
+ /** The pool of the caller's the adapter was given, which `open()` takes up again after `close()`. */
318
+ private readonly givenPool;
319
+ /** Whether `close()` ends the pool. */
320
+ private readonly ownsPool;
321
+ private readonly segmentStatements;
322
+ /** The error listener the adapter has on a pool, and that pool. */
323
+ private listening;
324
+ private opening;
325
+ private closing;
326
+ constructor(options: PostgresAdapterOptions | string);
327
+ /**
328
+ * The pool the adapter runs on: the pool it was given, or the pool it made
329
+ * while it is open. Null while the adapter is closed.
330
+ */
331
+ getPool(): PostgresPoolLike | null;
332
+ /**
333
+ * Lazy loader for pg module to keep the dependency optional and prevent bundling in browser builds.
334
+ */
335
+ private loadPgModule;
336
+ /**
337
+ * Opens the adapter: makes its pool and checks that a connection can be
338
+ * made (and with a segment, creates the segment's schema when it is
339
+ * missing), or takes up the pool it was given. A failure ends the pool it
340
+ * made, so a later `open()` starts again. Two calls at once open once.
341
+ */
342
+ open(openOptions?: StorageOpenOptions): Promise<void>;
343
+ private openNow;
344
+ /** The configuration of the pool the adapter makes. */
345
+ private poolConfig;
346
+ /** Puts the adapter's error listener on `pool`: `onError`, or the warning on a pool it owns. */
347
+ private listenOn;
348
+ /** The runner of statements outside a transaction. */
349
+ private readonly query;
350
+ run(statement: string, parameters?: StorageParameters): Promise<StorageRunResult>;
351
+ get<T>(statement: string, parameters?: StorageParameters): Promise<T | null>;
352
+ all<T>(statement: string, parameters?: StorageParameters): Promise<T[]>;
353
+ exec(script: string): Promise<void>;
354
+ /**
355
+ * Runs `fn` in a transaction on one pooled connection: COMMIT when it
356
+ * resolves, ROLLBACK when it or COMMIT throws, and that error is rethrown.
357
+ * `options` sets the isolation level and the read-only and deferrable modes;
358
+ * an unknown isolation level is refused before a connection is checked out.
359
+ *
360
+ * When ROLLBACK fails too (the connection broke), the error thrown is still
361
+ * the transaction's own, with the ROLLBACK error on it as `rollbackError`,
362
+ * and the connection is closed instead of returned to the pool. The handle
363
+ * `fn` receives runs on the pool once the transaction has ended.
364
+ */
365
+ transaction<T>(fn: (trx: StorageAdapter) => Promise<T>, options?: PostgresTransactionOptions): Promise<T>;
366
+ /**
367
+ * Holds one pooled connection for `fn`, for work that needs one session:
368
+ * `SET` and other session settings, session advisory locks
369
+ * (`pg_advisory_lock`), temporary tables, or statements that must not run
370
+ * inside a transaction. Its statements run outside a transaction unless
371
+ * `fn` opens one with `connection.transaction()` or `BEGIN`.
372
+ *
373
+ * When `fn` resolves, the connection goes back to the pool with its session
374
+ * state, so undo what `fn` set (or use `SET LOCAL` inside a transaction).
375
+ * When `fn` throws, the connection is closed instead, which ends its session
376
+ * state and any transaction it left open, and `fn`'s error is rethrown.
377
+ * When `fn` resolves inside a transaction it began and did not end, the
378
+ * connection is closed, which rolls the transaction back, and the call
379
+ * rejects (pg 8.21 and later report the transaction status). The connection
380
+ * refuses statements once `fn` has ended. A connection that broke while `fn`
381
+ * held it (the server ended the session) is closed, not returned. On a
382
+ * segmented adapter the connection starts in the segment, as every
383
+ * connection of its pool does.
384
+ */
385
+ withConnection<T>(fn: (connection: PostgresConnection) => Promise<T>): Promise<T>;
386
+ /**
387
+ * The pool's counts, or null when the adapter is not open. A pool of the
388
+ * caller's that does not count its connections, as pg's Pool does, reads 0.
389
+ */
390
+ getPoolStats(): PostgresPoolStats | null;
391
+ /**
392
+ * Closes the adapter. A pool the adapter made or owns is ended, once; a pool
393
+ * of its caller's that it does not own is left open, with the adapter's
394
+ * listener taken off it. A call made while a close is running waits for it.
395
+ */
396
+ close(): Promise<void>;
397
+ private closeNow;
398
+ private requirePool;
399
+ }
400
+ /**
401
+ * Create a PostgreSQL adapter with connection string.
402
+ * @param connectionString - PostgreSQL connection string
403
+ * @example
404
+ * ```typescript
405
+ * const db = createPostgresAdapter('postgresql://user:pass@localhost:5432/mydb');
406
+ * ```
407
+ */
408
+ export declare function createPostgresAdapter(connectionString: string): StorageAdapter;
409
+ /**
410
+ * Create a PostgreSQL adapter with configuration options.
411
+ * @param options - PostgreSQL adapter configuration
412
+ * @example
413
+ * ```typescript
414
+ * const db = createPostgresAdapter({
415
+ * host: 'db.example.com',
416
+ * database: 'mydb',
417
+ * user: 'dbuser',
418
+ * password: 'secure_password',
419
+ * ssl: true
420
+ * });
421
+ * ```
422
+ */
423
+ export declare function createPostgresAdapter(options: PostgresAdapterOptions): StorageAdapter;
424
+ //# sourceMappingURL=postgresAdapter.d.ts.map