@nextlyhq/adapter-postgres 0.0.2-alpha.68 → 0.0.2-alpha.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,81 +1,11 @@
1
- import { DrizzleAdapter } from '@nextlyhq/adapter-drizzle';
2
- import { PostgresAdapterConfig, SqlParam, TransactionContext, TransactionOptions, DatabaseCapabilities, PoolStats, InsertOptions, DatabaseError } from '@nextlyhq/adapter-drizzle/types';
3
- export { AdapterLogger, PoolConfig as AdapterPoolConfig, BaseAdapterConfig, DatabaseCapabilities, DatabaseError, DatabaseErrorKind, DeleteOptions, InsertOptions, JoinSpec, OrderBySpec, PoolStats, PostgresAdapterConfig, SelectOptions, SqlParam, SslConfig, TransactionContext, TransactionOptions, UpdateOptions, UpsertOptions, WhereClause, WhereCondition, WhereOperator } from '@nextlyhq/adapter-drizzle/types';
4
- import { AnyRelations } from 'drizzle-orm';
5
- import { NodePgDatabase } from 'drizzle-orm/node-postgres';
6
-
7
- /**
8
- * @nextlyhq/adapter-postgres
9
- *
10
- * PostgreSQL database adapter for Nextly.
11
- * Extends the base DrizzleAdapter from @nextlyhq/adapter-drizzle to provide
12
- * PostgreSQL-specific functionality.
13
- *
14
- * @remarks
15
- * This adapter uses the `pg` (node-postgres) driver for database connections
16
- * and integrates with Drizzle ORM for type-safe queries.
17
- *
18
- * Features:
19
- * - Connection pooling via pg.Pool
20
- * - Full transaction support with savepoints
21
- * - RETURNING clause support for all CRUD operations
22
- * - PostgreSQL-specific error classification
23
- * - JSONB support
24
- * - Full-text search capabilities
25
- * - Automatic retry for serialization failures and deadlocks
26
- *
27
- * @example
28
- * Simple usage with connection string:
29
- * ```typescript
30
- * import { createPostgresAdapter } from '@nextlyhq/adapter-postgres';
31
- *
32
- * const adapter = createPostgresAdapter({
33
- * url: process.env.DATABASE_URL!,
34
- * });
35
- *
36
- * await adapter.connect();
37
- * ```
38
- *
39
- * @example
40
- * Full configuration:
41
- * ```typescript
42
- * import { createPostgresAdapter } from '@nextlyhq/adapter-postgres';
43
- *
44
- * const adapter = createPostgresAdapter({
45
- * url: process.env.DATABASE_URL!,
46
- * pool: {
47
- * min: 2,
48
- * max: 20,
49
- * idleTimeoutMs: 30000,
50
- * },
51
- * ssl: {
52
- * rejectUnauthorized: true,
53
- * },
54
- * applicationName: 'my-nextly-app',
55
- * });
56
- * ```
57
- *
58
- * @example
59
- * Using the adapter class directly:
60
- * ```typescript
61
- * import { PostgresAdapter } from '@nextlyhq/adapter-postgres';
62
- * import type { PostgresAdapterConfig } from '@nextlyhq/adapter-postgres';
63
- *
64
- * const config: PostgresAdapterConfig = {
65
- * url: process.env.DATABASE_URL!,
66
- * };
67
- *
68
- * const adapter = new PostgresAdapter(config);
69
- * await adapter.connect();
70
- * ```
71
- *
72
- * @packageDocumentation
73
- */
74
-
1
+ import { DrizzleAdapter } from "@nextlyhq/adapter-drizzle";
2
+ import { AdapterLogger, BaseAdapterConfig, DatabaseCapabilities, DatabaseCapabilities as DatabaseCapabilities$1, DatabaseError, DatabaseError as DatabaseError$1, DatabaseErrorKind, DeleteOptions, InsertOptions, InsertOptions as InsertOptions$1, JoinSpec, OrderBySpec, PoolConfig as AdapterPoolConfig, PoolStats, PoolStats as PoolStats$1, PostgresAdapterConfig, PostgresAdapterConfig as PostgresAdapterConfig$1, SelectOptions, SqlParam, SqlParam as SqlParam$1, SslConfig, TransactionContext, TransactionContext as TransactionContext$1, TransactionOptions, TransactionOptions as TransactionOptions$1, UpdateOptions, UpsertOptions, WhereClause, WhereCondition, WhereOperator } from "@nextlyhq/adapter-drizzle/types";
3
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
4
+ import { AnyRelations } from "drizzle-orm";
75
5
  /**
76
6
  * Package version.
77
7
  */
78
- declare const VERSION = "0.1.0";
8
+ export declare const VERSION = "0.1.0";
79
9
  /**
80
10
  * PostgreSQL database adapter for Nextly.
81
11
  *
@@ -113,192 +43,192 @@ declare const VERSION = "0.1.0";
113
43
  *
114
44
  * @public
115
45
  */
116
- declare class PostgresAdapter extends DrizzleAdapter {
117
- private drizzleByRelations;
118
- private drizzleBare;
119
- /**
120
- * The database dialect - always 'postgresql' for this adapter.
121
- */
122
- readonly dialect: "postgresql";
123
- /**
124
- * Adapter configuration.
125
- */
126
- protected readonly config: PostgresAdapterConfig;
127
- /**
128
- * Connection pool instance.
129
- */
130
- private pool;
131
- /**
132
- * Connection state flag.
133
- */
134
- private connected;
135
- /**
136
- * Auto-detected provider (Neon, Supabase, or standard).
137
- * Set during connect() from DATABASE_URL pattern or DB_PROVIDER env var.
138
- */
139
- private detectedProvider;
140
- /**
141
- * Provider-specific connection defaults. Applied as fallbacks when
142
- * user config doesn't specify a value.
143
- */
144
- private providerDefaults;
145
- /**
146
- * Creates a new PostgreSQL adapter instance.
147
- *
148
- * @param config - Adapter configuration
149
- */
150
- constructor(config: PostgresAdapterConfig);
151
- /**
152
- * Establishes a connection to the PostgreSQL database.
153
- *
154
- * @remarks
155
- * This method initializes the connection pool and verifies connectivity
156
- * by executing a simple query. It is idempotent - calling it multiple
157
- * times will not create multiple pools.
158
- *
159
- * @throws {DatabaseError} If connection fails
160
- */
161
- connect(): Promise<void>;
162
- /**
163
- * Closes the database connection and releases all pool resources.
164
- *
165
- * @remarks
166
- * This method is idempotent - calling it multiple times is safe.
167
- * It waits for all checked-out clients to be returned before shutting down.
168
- */
169
- disconnect(): Promise<void>;
170
- /**
171
- * Checks if the adapter is currently connected.
172
- *
173
- * @returns True if connected and pool is available
174
- */
175
- isConnected(): boolean;
176
- /**
177
- * Executes a raw SQL query.
178
- *
179
- * @param sql - SQL statement with $1, $2, ... placeholders
180
- * @param params - Query parameters
181
- * @returns Array of result rows
182
- *
183
- * @throws {DatabaseError} If query execution fails
184
- */
185
- executeQuery<T = unknown>(sql: string, params?: SqlParam[]): Promise<T[]>;
186
- /**
187
- * Executes a callback within a database transaction.
188
- *
189
- * @remarks
190
- * PostgreSQL supports full ACID transactions with savepoints.
191
- * If the callback throws, the transaction is rolled back.
192
- *
193
- * Supports automatic retry for serialization failures (40001) and
194
- * deadlocks (40P01) when `retryCount` is specified in options.
195
- *
196
- * An error carrying the Nextly application brand is neither retried nor
197
- * classified: it is the application refusing the write, so it arrives at the
198
- * caller as it was thrown. Retrying it would repeat work whose verdict has
199
- * already been given. Every other error, including an unbranded one raised by
200
- * the callback, is retried when it is a serialization failure or deadlock and
201
- * classified on the way out.
202
- *
203
- * @param callback - Function to execute within the transaction
204
- * @param options - Transaction options (isolation level, timeout, retry)
205
- * @returns The result of the callback
206
- *
207
- * @throws {DatabaseError} If the transaction itself fails after all retries,
208
- * or if the callback threw an error that does not carry the application brand
209
- * @throws The callback's own error, unchanged, when it carries that brand
210
- */
211
- transaction<T>(callback: (ctx: TransactionContext) => Promise<T>, options?: TransactionOptions): Promise<T>;
212
- /** The attempts `transaction` makes, each on a connection of its own. */
213
- private runTransactionAttempts;
214
- /**
215
- * Returns the database capabilities for PostgreSQL.
216
- *
217
- * @remarks
218
- * PostgreSQL has the most comprehensive feature set of all supported
219
- * databases, including JSONB, arrays, full-text search, and more.
220
- */
221
- getCapabilities(): DatabaseCapabilities;
222
- /**
223
- * The schema set as `search_path` on every pooled connection.
224
- *
225
- * @remarks
226
- * Answers with the same test `buildPoolConfig` applies, so an empty string
227
- * reports `undefined` exactly as it sets no `search_path`: the value
228
- * reported is the one the connections actually use.
229
- *
230
- * @returns The configured schema, or `undefined` when the server's default
231
- * `search_path` applies
232
- */
233
- getConfiguredSchema(): string | undefined;
234
- /**
235
- * Returns connection pool statistics.
236
- *
237
- * @returns Pool stats or null if not connected
238
- */
239
- getPoolStats(): PoolStats | null;
240
- /**
241
- * Override insertMany for bulk insert optimization.
242
- *
243
- * @remarks
244
- * Uses a single multi-row INSERT statement for better performance
245
- * when inserting multiple records.
246
- */
247
- insertMany<T = unknown>(table: string, data: Record<string, unknown>[], options?: InsertOptions): Promise<T[]>;
248
- /**
249
- * Ensures pool is connected and returns it.
250
- *
251
- * @throws {DatabaseError} If not connected
252
- */
253
- private ensurePool;
254
- /**
255
- * Return the typed Drizzle instance for PostgreSQL.
256
- * Guarded for server-only usage and requires an active connection.
257
- *
258
- * @param schema - Optional schema for relational queries (db.query.*)
259
- * @returns Drizzle ORM instance wrapping the pg pool connection
260
- * @throws {Error} If called in browser or not connected
261
- */
262
- getDrizzle<T = NodePgDatabase<AnyRelations>>(relations?: AnyRelations): T;
263
- /**
264
- * A Drizzle handle on the pool, for `getDrizzle`.
265
- *
266
- * Its `transaction` runs on a client this adapter checks out and returns
267
- * itself (`pinDrizzleTransactions`): node-postgres destroys a client
268
- * released with `true`, which is what happens when no ROLLBACK could be
269
- * confirmed on it. And it counts for `transactionOpenInFlow`, as the
270
- * adapter's does.
271
- */
272
- private poolDrizzle;
273
- /**
274
- * Builds pg Pool configuration from adapter config.
275
- */
276
- private buildPoolConfig;
277
- /**
278
- * Begins a transaction with the specified options.
279
- */
280
- private beginTransaction;
281
- /**
282
- * Creates a TransactionContext for the given client.
283
- */
284
- /**
285
- * The RETURNING entries that spell each date column's wall clock out as
286
- * text, one per alias `dateWallClockAliases` chose. `to_char` renders the
287
- * stored value without a zone, which is the only form node-postgres cannot
288
- * shift on the way back.
289
- */
290
- private wallClockSpelling;
291
- /** A table-level `primaryKey({ columns })`, read through the PostgreSQL table config. */
292
- protected compositePrimaryKey(tableObj: Record<string, unknown>): object[];
293
- private createTransactionContext;
294
- /**
295
- * Classifies a PostgreSQL error into a DatabaseError.
296
- *
297
- * @param error - Original error from pg
298
- * @param sql - SQL statement that caused the error (optional)
299
- * @returns DatabaseError with proper classification
300
- */
301
- protected classifyError(error: unknown, sql?: string): DatabaseError;
46
+ export declare class PostgresAdapter extends DrizzleAdapter {
47
+ private drizzleByRelations;
48
+ private drizzleBare;
49
+ /**
50
+ * The database dialect - always 'postgresql' for this adapter.
51
+ */
52
+ readonly dialect: "postgresql";
53
+ /**
54
+ * Adapter configuration.
55
+ */
56
+ protected readonly config: PostgresAdapterConfig$1;
57
+ /**
58
+ * Connection pool instance.
59
+ */
60
+ private pool;
61
+ /**
62
+ * Connection state flag.
63
+ */
64
+ private connected;
65
+ /**
66
+ * Auto-detected provider (Neon, Supabase, or standard).
67
+ * Set during connect() from DATABASE_URL pattern or DB_PROVIDER env var.
68
+ */
69
+ private detectedProvider;
70
+ /**
71
+ * Provider-specific connection defaults. Applied as fallbacks when
72
+ * user config doesn't specify a value.
73
+ */
74
+ private providerDefaults;
75
+ /**
76
+ * Creates a new PostgreSQL adapter instance.
77
+ *
78
+ * @param config - Adapter configuration
79
+ */
80
+ constructor(config: PostgresAdapterConfig$1);
81
+ /**
82
+ * Establishes a connection to the PostgreSQL database.
83
+ *
84
+ * @remarks
85
+ * This method initializes the connection pool and verifies connectivity
86
+ * by executing a simple query. It is idempotent - calling it multiple
87
+ * times will not create multiple pools.
88
+ *
89
+ * @throws {DatabaseError} If connection fails
90
+ */
91
+ connect(): Promise<void>;
92
+ /**
93
+ * Closes the database connection and releases all pool resources.
94
+ *
95
+ * @remarks
96
+ * This method is idempotent - calling it multiple times is safe.
97
+ * It waits for all checked-out clients to be returned before shutting down.
98
+ */
99
+ disconnect(): Promise<void>;
100
+ /**
101
+ * Checks if the adapter is currently connected.
102
+ *
103
+ * @returns True if connected and pool is available
104
+ */
105
+ override isConnected(): boolean;
106
+ /**
107
+ * Executes a raw SQL query.
108
+ *
109
+ * @param sql - SQL statement with $1, $2, ... placeholders
110
+ * @param params - Query parameters
111
+ * @returns Array of result rows
112
+ *
113
+ * @throws {DatabaseError} If query execution fails
114
+ */
115
+ executeQuery<T = unknown>(sql: string, params?: SqlParam$1[]): Promise<T[]>;
116
+ /**
117
+ * Executes a callback within a database transaction.
118
+ *
119
+ * @remarks
120
+ * PostgreSQL supports full ACID transactions with savepoints.
121
+ * If the callback throws, the transaction is rolled back.
122
+ *
123
+ * Supports automatic retry for serialization failures (40001) and
124
+ * deadlocks (40P01) when `retryCount` is specified in options.
125
+ *
126
+ * An error carrying the Nextly application brand is neither retried nor
127
+ * classified: it is the application refusing the write, so it arrives at the
128
+ * caller as it was thrown. Retrying it would repeat work whose verdict has
129
+ * already been given. Every other error, including an unbranded one raised by
130
+ * the callback, is retried when it is a serialization failure or deadlock and
131
+ * classified on the way out.
132
+ *
133
+ * @param callback - Function to execute within the transaction
134
+ * @param options - Transaction options (isolation level, timeout, retry)
135
+ * @returns The result of the callback
136
+ *
137
+ * @throws {DatabaseError} If the transaction itself fails after all retries,
138
+ * or if the callback threw an error that does not carry the application brand
139
+ * @throws The callback's own error, unchanged, when it carries that brand
140
+ */
141
+ transaction<T>(callback: (ctx: TransactionContext$1) => Promise<T>, options?: TransactionOptions$1): Promise<T>;
142
+ /** The attempts `transaction` makes, each on a connection of its own. */
143
+ private runTransactionAttempts;
144
+ /**
145
+ * Returns the database capabilities for PostgreSQL.
146
+ *
147
+ * @remarks
148
+ * PostgreSQL has the most comprehensive feature set of all supported
149
+ * databases, including JSONB, arrays, full-text search, and more.
150
+ */
151
+ getCapabilities(): DatabaseCapabilities$1;
152
+ /**
153
+ * The schema set as `search_path` on every pooled connection.
154
+ *
155
+ * @remarks
156
+ * Answers with the same test `buildPoolConfig` applies, so an empty string
157
+ * reports `undefined` exactly as it sets no `search_path`: the value
158
+ * reported is the one the connections actually use.
159
+ *
160
+ * @returns The configured schema, or `undefined` when the server's default
161
+ * `search_path` applies
162
+ */
163
+ getConfiguredSchema(): string | undefined;
164
+ /**
165
+ * Returns connection pool statistics.
166
+ *
167
+ * @returns Pool stats or null if not connected
168
+ */
169
+ override getPoolStats(): PoolStats$1 | null;
170
+ /**
171
+ * Override insertMany for bulk insert optimization.
172
+ *
173
+ * @remarks
174
+ * Uses a single multi-row INSERT statement for better performance
175
+ * when inserting multiple records.
176
+ */
177
+ override insertMany<T = unknown>(table: string, data: Record<string, unknown>[], options?: InsertOptions$1): Promise<T[]>;
178
+ /**
179
+ * Ensures pool is connected and returns it.
180
+ *
181
+ * @throws {DatabaseError} If not connected
182
+ */
183
+ private ensurePool;
184
+ /**
185
+ * Return the typed Drizzle instance for PostgreSQL.
186
+ * Guarded for server-only usage and requires an active connection.
187
+ *
188
+ * @param schema - Optional schema for relational queries (db.query.*)
189
+ * @returns Drizzle ORM instance wrapping the pg pool connection
190
+ * @throws {Error} If called in browser or not connected
191
+ */
192
+ getDrizzle<T = NodePgDatabase<AnyRelations>>(relations?: AnyRelations): T;
193
+ /**
194
+ * A Drizzle handle on the pool, for `getDrizzle`.
195
+ *
196
+ * Its `transaction` runs on a client this adapter checks out and returns
197
+ * itself (`pinDrizzleTransactions`): node-postgres destroys a client
198
+ * released with `true`, which is what happens when no ROLLBACK could be
199
+ * confirmed on it. And it counts for `transactionOpenInFlow`, as the
200
+ * adapter's does.
201
+ */
202
+ private poolDrizzle;
203
+ /**
204
+ * Builds pg Pool configuration from adapter config.
205
+ */
206
+ private buildPoolConfig;
207
+ /**
208
+ * Begins a transaction with the specified options.
209
+ */
210
+ private beginTransaction;
211
+ /**
212
+ * Creates a TransactionContext for the given client.
213
+ */
214
+ /**
215
+ * The RETURNING entries that spell each date column's wall clock out as
216
+ * text, one per alias `dateWallClockAliases` chose. `to_char` renders the
217
+ * stored value without a zone, which is the only form node-postgres cannot
218
+ * shift on the way back.
219
+ */
220
+ private wallClockSpelling;
221
+ /** A table-level `primaryKey({ columns })`, read through the PostgreSQL table config. */
222
+ protected override compositePrimaryKey(tableObj: Record<string, unknown>): object[];
223
+ private createTransactionContext;
224
+ /**
225
+ * Classifies a PostgreSQL error into a DatabaseError.
226
+ *
227
+ * @param error - Original error from pg
228
+ * @param sql - SQL statement that caused the error (optional)
229
+ * @returns DatabaseError with proper classification
230
+ */
231
+ protected override classifyError(error: unknown, sql?: string): DatabaseError$1;
302
232
  }
303
233
  /**
304
234
  * Creates a PostgreSQL database adapter instance.
@@ -345,7 +275,7 @@ declare class PostgresAdapter extends DrizzleAdapter {
345
275
  *
346
276
  * @public
347
277
  */
348
- declare function createPostgresAdapter(config: PostgresAdapterConfig): PostgresAdapter;
278
+ export declare function createPostgresAdapter(config: PostgresAdapterConfig$1): PostgresAdapter;
349
279
  /**
350
280
  * Type guard to check if a value is a PostgresAdapter instance.
351
281
  *
@@ -364,6 +294,6 @@ declare function createPostgresAdapter(config: PostgresAdapterConfig): PostgresA
364
294
  *
365
295
  * @public
366
296
  */
367
- declare function isPostgresAdapter(value: unknown): value is PostgresAdapter;
368
-
369
- export { PostgresAdapter, VERSION, createPostgresAdapter, isPostgresAdapter };
297
+ export declare function isPostgresAdapter(value: unknown): value is PostgresAdapter;
298
+ export type { AdapterLogger, AdapterPoolConfig, BaseAdapterConfig, DatabaseCapabilities, DatabaseError, DatabaseErrorKind, DeleteOptions, InsertOptions, JoinSpec, OrderBySpec, PoolStats, PostgresAdapterConfig, SelectOptions, SqlParam, SslConfig, TransactionContext, TransactionOptions, UpdateOptions, UpsertOptions, WhereClause, WhereCondition, WhereOperator };
299
+ //# sourceMappingURL=index.d.ts.map