@relaybus/postgres 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -2
- package/dist/chunk-NNZJR5AB.js +12 -0
- package/dist/chunk-NNZJR5AB.js.map +1 -0
- package/dist/drizzle.cjs +13 -5
- package/dist/drizzle.cjs.map +1 -1
- package/dist/drizzle.d.cts +1 -1
- package/dist/drizzle.d.ts +1 -1
- package/dist/drizzle.js +6 -4
- package/dist/drizzle.js.map +1 -1
- package/dist/{executor-VZGmsMX4.d.cts → executor-CfJgktC6.d.cts} +17 -0
- package/dist/{executor-VZGmsMX4.d.ts → executor-CfJgktC6.d.ts} +17 -0
- package/dist/index.cjs +2215 -1690
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +50 -9
- package/dist/index.d.ts +50 -9
- package/dist/index.js +2217 -1693
- package/dist/index.js.map +1 -1
- package/dist/knex.cjs +14 -4
- package/dist/knex.cjs.map +1 -1
- package/dist/knex.d.cts +1 -1
- package/dist/knex.d.ts +1 -1
- package/dist/knex.js +6 -4
- package/dist/knex.js.map +1 -1
- package/dist/kysely.cjs +13 -5
- package/dist/kysely.cjs.map +1 -1
- package/dist/kysely.d.cts +1 -1
- package/dist/kysely.d.ts +1 -1
- package/dist/kysely.js +6 -5
- package/dist/kysely.js.map +1 -1
- package/dist/prisma.cjs +14 -4
- package/dist/prisma.cjs.map +1 -1
- package/dist/prisma.d.cts +1 -1
- package/dist/prisma.d.ts +1 -1
- package/dist/prisma.js +7 -4
- package/dist/prisma.js.map +1 -1
- package/dist/typeorm.cjs +14 -4
- package/dist/typeorm.cjs.map +1 -1
- package/dist/typeorm.d.cts +1 -1
- package/dist/typeorm.d.ts +1 -1
- package/dist/typeorm.js +7 -4
- package/dist/typeorm.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import { P as PostgresExecutor, a as PostgresParameter, b as PostgresQueryOptions, c as PostgresRow } from './executor-
|
|
2
|
-
import { RelayBusLogger, EventStore, AppendEntry, AppendResult, ClaimRequest, ClaimedDelivery, LeaseReference, ErrorInfo, DeliveryQuery, DeliveryRecord, PurgeRequest, PurgeResult, EventStoreStatistics } from '@relaybus/core';
|
|
1
|
+
import { P as PostgresExecutor, a as PostgresParameter, b as PostgresQueryOptions, c as PostgresRow } from './executor-CfJgktC6.cjs';
|
|
2
|
+
import { RelayBusLogger, EventStore, EventStoreTransactionOptions, AppendEntry, AppendResult, ClaimRequest, ClaimedDelivery, LeaseReference, ErrorInfo, DeliveryQuery, DeliveryRecord, PurgeRequest, PurgeResult, EventStoreStatistics, CloseOptions, RelayBusError } from '@relaybus/core';
|
|
3
3
|
import { PoolClient, Pool, PoolConfig } from 'pg';
|
|
4
4
|
|
|
5
5
|
interface PgExecutorOptions {
|
|
6
6
|
/** Receives the warning sent when prepared statements are switched off. Default `console`. */
|
|
7
7
|
readonly logger?: RelayBusLogger;
|
|
8
|
+
/**
|
|
9
|
+
* The pool is this executor's alone (the store sets it for the pool it creates from
|
|
10
|
+
* `connectionString`). A transaction budget then becomes a session setting of the connection, sent
|
|
11
|
+
* with `BEGIN` only when the connection does not have it yet, and a transaction without a budget on
|
|
12
|
+
* such a connection puts the session defaults back in its `BEGIN`. Statements outside a
|
|
13
|
+
* transaction run under the budget the connection last got. Never set it for a pool other code
|
|
14
|
+
* uses, or behind a pooler in transaction mode (session settings would reach other clients); the
|
|
15
|
+
* executor stops it by itself when it notices a pooler (see prepared statements). Default `false`.
|
|
16
|
+
*/
|
|
17
|
+
readonly sessionBudget?: boolean;
|
|
8
18
|
}
|
|
9
19
|
/**
|
|
10
20
|
* Executor for a `pg` {@link Pool}. A transaction is a dedicated pool client
|
|
@@ -24,7 +34,15 @@ interface PgExecutorOptions {
|
|
|
24
34
|
declare class PgExecutor implements PostgresExecutor<PoolClient> {
|
|
25
35
|
#private;
|
|
26
36
|
constructor(pool: Pool, options?: PgExecutorOptions);
|
|
37
|
+
/** The connection listens for `error` during the transaction, so a server-ended session fails the transaction instead of the process. */
|
|
38
|
+
readonly sessionTimeouts = true;
|
|
27
39
|
transaction<T>(work: (transaction: PoolClient) => Promise<T>): Promise<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Sends `BEGIN` and the budget settings as one simple query (the value as a literal: the simple
|
|
42
|
+
* query protocol has no parameters), so the budget costs no round trip. With `sessionBudget` a
|
|
43
|
+
* connection that already keeps this budget only gets `BEGIN`.
|
|
44
|
+
*/
|
|
45
|
+
transactionWithBudget<T>(work: (transaction: PoolClient) => Promise<T>, timeoutMs: number): Promise<T>;
|
|
28
46
|
query(sql: string, parameters: readonly PostgresParameter[], transaction?: PoolClient, options?: PostgresQueryOptions): Promise<readonly PostgresRow[]>;
|
|
29
47
|
}
|
|
30
48
|
|
|
@@ -177,6 +195,7 @@ interface PostgresExecutorOptions<TTransaction> extends PostgresEventStoreSettin
|
|
|
177
195
|
readonly poolConfig?: never;
|
|
178
196
|
}
|
|
179
197
|
type PostgresEventStoreOptions<TTransaction = PoolClient> = PostgresPoolOptions | PostgresConnectionOptions | PostgresExecutorOptions<TTransaction>;
|
|
198
|
+
|
|
180
199
|
/**
|
|
181
200
|
* PostgreSQL {@link EventStore} (PostgreSQL 13 or newer).
|
|
182
201
|
*
|
|
@@ -227,10 +246,18 @@ declare class PostgresEventStore<TTransaction = PoolClient> implements EventStor
|
|
|
227
246
|
* `createPostgresSchemaSql()` instead.
|
|
228
247
|
*/
|
|
229
248
|
setup(): Promise<void>;
|
|
230
|
-
|
|
249
|
+
/**
|
|
250
|
+
* Runs `work` in a transaction of the executor. With `options.timeoutMs` (from `bus.transaction`)
|
|
251
|
+
* the server holds the transaction to the budget: `statement_timeout`, and for executors with
|
|
252
|
+
* `sessionTimeouts` (`pg`) also `idle_in_transaction_session_timeout` and, on PostgreSQL 17+,
|
|
253
|
+
* `transaction_timeout`, all scoped to the transaction. An executor with `transactionWithBudget`
|
|
254
|
+
* (`PgExecutor`) sets them with `BEGIN`, so the budget costs no round trip; on a pool the store
|
|
255
|
+
* created they are kept per connection and sent only when the connection does not have them yet.
|
|
256
|
+
*/
|
|
257
|
+
transaction<T>(work: (transaction: TTransaction) => Promise<T>, options?: EventStoreTransactionOptions): Promise<T>;
|
|
231
258
|
/**
|
|
232
259
|
* Writes the entries in `transaction`, normally with one statement
|
|
233
|
-
* (
|
|
260
|
+
* (`AppendStatements.insertFreshEvents`): keyed events reserve their sequence numbers (locking
|
|
234
261
|
* the key rows in sorted order, so publishers cannot deadlock inside one call), then the new events and
|
|
235
262
|
* their deliveries are inserted, ordered by primary key, and one notification wakes the dispatchers
|
|
236
263
|
* when a delivery is due now. Events that already existed get their missing handlers' deliveries in
|
|
@@ -242,14 +269,14 @@ declare class PostgresEventStore<TTransaction = PoolClient> implements EventStor
|
|
|
242
269
|
append(transaction: TTransaction, entries: readonly AppendEntry[], now: Date): Promise<AppendResult>;
|
|
243
270
|
/**
|
|
244
271
|
* Claims up to `limit` due deliveries, normally with one statement
|
|
245
|
-
* (
|
|
272
|
+
* (`LaneStatements.claimLanes`): from the lanes this owner already holds, then from free lanes
|
|
246
273
|
* it takes in the same statement, recording the batch in the lane rows. A claim that would have to take
|
|
247
274
|
* over a lane whose previous holder still runs deliveries under an expired lease continues in a
|
|
248
275
|
* transaction that charges their lost attempts first, taking free lanes a few at a time (4, 8, 16, ...);
|
|
249
276
|
* so does a claim whose statement kept seeing a lane it holds change under it, and one that came up
|
|
250
277
|
* short with more free lanes left than it looked at. The step that fails after
|
|
251
278
|
* the first one has recorded deliveries returns those instead of failing: a recorded delivery nobody
|
|
252
|
-
* received would be held for a whole lease. See
|
|
279
|
+
* received would be held for a whole lease. See `ClaimStatements.claim` for the rules a delivery
|
|
253
280
|
* must satisfy.
|
|
254
281
|
*/
|
|
255
282
|
claim(request: ClaimRequest): Promise<ClaimedDelivery[]>;
|
|
@@ -285,8 +312,22 @@ declare class PostgresEventStore<TTransaction = PoolClient> implements EventStor
|
|
|
285
312
|
*/
|
|
286
313
|
purge(request: PurgeRequest): Promise<PurgeResult>;
|
|
287
314
|
statistics(now: Date): Promise<EventStoreStatistics>;
|
|
288
|
-
/**
|
|
289
|
-
|
|
315
|
+
/**
|
|
316
|
+
* Ends the pool this store created from `connectionString`. Pools and executors you passed in stay
|
|
317
|
+
* open. Once `options.signal` aborts (the shutdown deadline passed), the connections the store opened
|
|
318
|
+
* itself are destroyed: queries still running on them fail at once instead of holding the shutdown.
|
|
319
|
+
*/
|
|
320
|
+
close(options?: CloseOptions): Promise<void>;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* A claim was refused because giving back the deliveries of an earlier, failed
|
|
325
|
+
* claim still fails. Claiming before that would take the owner's live lanes for
|
|
326
|
+
* foreign ones; the next claim tries the reconciliation again.
|
|
327
|
+
*/
|
|
328
|
+
declare class ReconcileFailedError extends RelayBusError {
|
|
329
|
+
name: string;
|
|
330
|
+
readonly code: string;
|
|
290
331
|
}
|
|
291
332
|
|
|
292
|
-
export { PgExecutor, type PgExecutorOptions, type PostgresConnectionOptions, PostgresEventStore, type PostgresEventStoreOptions, type PostgresEventStoreSettings, PostgresExecutor, type PostgresExecutorOptions, type PostgresNames, PostgresParameter, type PostgresPoolOptions, PostgresQueryOptions, PostgresRow, type PostgresSchemaOptions, type PostgresWakeUp, createPostgresSchemaSql, createPostgresSchemaStatements, resolvePostgresNames };
|
|
333
|
+
export { PgExecutor, type PgExecutorOptions, type PostgresConnectionOptions, PostgresEventStore, type PostgresEventStoreOptions, type PostgresEventStoreSettings, PostgresExecutor, type PostgresExecutorOptions, type PostgresNames, PostgresParameter, type PostgresPoolOptions, PostgresQueryOptions, PostgresRow, type PostgresSchemaOptions, type PostgresWakeUp, ReconcileFailedError, createPostgresSchemaSql, createPostgresSchemaStatements, resolvePostgresNames };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import { P as PostgresExecutor, a as PostgresParameter, b as PostgresQueryOptions, c as PostgresRow } from './executor-
|
|
2
|
-
import { RelayBusLogger, EventStore, AppendEntry, AppendResult, ClaimRequest, ClaimedDelivery, LeaseReference, ErrorInfo, DeliveryQuery, DeliveryRecord, PurgeRequest, PurgeResult, EventStoreStatistics } from '@relaybus/core';
|
|
1
|
+
import { P as PostgresExecutor, a as PostgresParameter, b as PostgresQueryOptions, c as PostgresRow } from './executor-CfJgktC6.js';
|
|
2
|
+
import { RelayBusLogger, EventStore, EventStoreTransactionOptions, AppendEntry, AppendResult, ClaimRequest, ClaimedDelivery, LeaseReference, ErrorInfo, DeliveryQuery, DeliveryRecord, PurgeRequest, PurgeResult, EventStoreStatistics, CloseOptions, RelayBusError } from '@relaybus/core';
|
|
3
3
|
import { PoolClient, Pool, PoolConfig } from 'pg';
|
|
4
4
|
|
|
5
5
|
interface PgExecutorOptions {
|
|
6
6
|
/** Receives the warning sent when prepared statements are switched off. Default `console`. */
|
|
7
7
|
readonly logger?: RelayBusLogger;
|
|
8
|
+
/**
|
|
9
|
+
* The pool is this executor's alone (the store sets it for the pool it creates from
|
|
10
|
+
* `connectionString`). A transaction budget then becomes a session setting of the connection, sent
|
|
11
|
+
* with `BEGIN` only when the connection does not have it yet, and a transaction without a budget on
|
|
12
|
+
* such a connection puts the session defaults back in its `BEGIN`. Statements outside a
|
|
13
|
+
* transaction run under the budget the connection last got. Never set it for a pool other code
|
|
14
|
+
* uses, or behind a pooler in transaction mode (session settings would reach other clients); the
|
|
15
|
+
* executor stops it by itself when it notices a pooler (see prepared statements). Default `false`.
|
|
16
|
+
*/
|
|
17
|
+
readonly sessionBudget?: boolean;
|
|
8
18
|
}
|
|
9
19
|
/**
|
|
10
20
|
* Executor for a `pg` {@link Pool}. A transaction is a dedicated pool client
|
|
@@ -24,7 +34,15 @@ interface PgExecutorOptions {
|
|
|
24
34
|
declare class PgExecutor implements PostgresExecutor<PoolClient> {
|
|
25
35
|
#private;
|
|
26
36
|
constructor(pool: Pool, options?: PgExecutorOptions);
|
|
37
|
+
/** The connection listens for `error` during the transaction, so a server-ended session fails the transaction instead of the process. */
|
|
38
|
+
readonly sessionTimeouts = true;
|
|
27
39
|
transaction<T>(work: (transaction: PoolClient) => Promise<T>): Promise<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Sends `BEGIN` and the budget settings as one simple query (the value as a literal: the simple
|
|
42
|
+
* query protocol has no parameters), so the budget costs no round trip. With `sessionBudget` a
|
|
43
|
+
* connection that already keeps this budget only gets `BEGIN`.
|
|
44
|
+
*/
|
|
45
|
+
transactionWithBudget<T>(work: (transaction: PoolClient) => Promise<T>, timeoutMs: number): Promise<T>;
|
|
28
46
|
query(sql: string, parameters: readonly PostgresParameter[], transaction?: PoolClient, options?: PostgresQueryOptions): Promise<readonly PostgresRow[]>;
|
|
29
47
|
}
|
|
30
48
|
|
|
@@ -177,6 +195,7 @@ interface PostgresExecutorOptions<TTransaction> extends PostgresEventStoreSettin
|
|
|
177
195
|
readonly poolConfig?: never;
|
|
178
196
|
}
|
|
179
197
|
type PostgresEventStoreOptions<TTransaction = PoolClient> = PostgresPoolOptions | PostgresConnectionOptions | PostgresExecutorOptions<TTransaction>;
|
|
198
|
+
|
|
180
199
|
/**
|
|
181
200
|
* PostgreSQL {@link EventStore} (PostgreSQL 13 or newer).
|
|
182
201
|
*
|
|
@@ -227,10 +246,18 @@ declare class PostgresEventStore<TTransaction = PoolClient> implements EventStor
|
|
|
227
246
|
* `createPostgresSchemaSql()` instead.
|
|
228
247
|
*/
|
|
229
248
|
setup(): Promise<void>;
|
|
230
|
-
|
|
249
|
+
/**
|
|
250
|
+
* Runs `work` in a transaction of the executor. With `options.timeoutMs` (from `bus.transaction`)
|
|
251
|
+
* the server holds the transaction to the budget: `statement_timeout`, and for executors with
|
|
252
|
+
* `sessionTimeouts` (`pg`) also `idle_in_transaction_session_timeout` and, on PostgreSQL 17+,
|
|
253
|
+
* `transaction_timeout`, all scoped to the transaction. An executor with `transactionWithBudget`
|
|
254
|
+
* (`PgExecutor`) sets them with `BEGIN`, so the budget costs no round trip; on a pool the store
|
|
255
|
+
* created they are kept per connection and sent only when the connection does not have them yet.
|
|
256
|
+
*/
|
|
257
|
+
transaction<T>(work: (transaction: TTransaction) => Promise<T>, options?: EventStoreTransactionOptions): Promise<T>;
|
|
231
258
|
/**
|
|
232
259
|
* Writes the entries in `transaction`, normally with one statement
|
|
233
|
-
* (
|
|
260
|
+
* (`AppendStatements.insertFreshEvents`): keyed events reserve their sequence numbers (locking
|
|
234
261
|
* the key rows in sorted order, so publishers cannot deadlock inside one call), then the new events and
|
|
235
262
|
* their deliveries are inserted, ordered by primary key, and one notification wakes the dispatchers
|
|
236
263
|
* when a delivery is due now. Events that already existed get their missing handlers' deliveries in
|
|
@@ -242,14 +269,14 @@ declare class PostgresEventStore<TTransaction = PoolClient> implements EventStor
|
|
|
242
269
|
append(transaction: TTransaction, entries: readonly AppendEntry[], now: Date): Promise<AppendResult>;
|
|
243
270
|
/**
|
|
244
271
|
* Claims up to `limit` due deliveries, normally with one statement
|
|
245
|
-
* (
|
|
272
|
+
* (`LaneStatements.claimLanes`): from the lanes this owner already holds, then from free lanes
|
|
246
273
|
* it takes in the same statement, recording the batch in the lane rows. A claim that would have to take
|
|
247
274
|
* over a lane whose previous holder still runs deliveries under an expired lease continues in a
|
|
248
275
|
* transaction that charges their lost attempts first, taking free lanes a few at a time (4, 8, 16, ...);
|
|
249
276
|
* so does a claim whose statement kept seeing a lane it holds change under it, and one that came up
|
|
250
277
|
* short with more free lanes left than it looked at. The step that fails after
|
|
251
278
|
* the first one has recorded deliveries returns those instead of failing: a recorded delivery nobody
|
|
252
|
-
* received would be held for a whole lease. See
|
|
279
|
+
* received would be held for a whole lease. See `ClaimStatements.claim` for the rules a delivery
|
|
253
280
|
* must satisfy.
|
|
254
281
|
*/
|
|
255
282
|
claim(request: ClaimRequest): Promise<ClaimedDelivery[]>;
|
|
@@ -285,8 +312,22 @@ declare class PostgresEventStore<TTransaction = PoolClient> implements EventStor
|
|
|
285
312
|
*/
|
|
286
313
|
purge(request: PurgeRequest): Promise<PurgeResult>;
|
|
287
314
|
statistics(now: Date): Promise<EventStoreStatistics>;
|
|
288
|
-
/**
|
|
289
|
-
|
|
315
|
+
/**
|
|
316
|
+
* Ends the pool this store created from `connectionString`. Pools and executors you passed in stay
|
|
317
|
+
* open. Once `options.signal` aborts (the shutdown deadline passed), the connections the store opened
|
|
318
|
+
* itself are destroyed: queries still running on them fail at once instead of holding the shutdown.
|
|
319
|
+
*/
|
|
320
|
+
close(options?: CloseOptions): Promise<void>;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* A claim was refused because giving back the deliveries of an earlier, failed
|
|
325
|
+
* claim still fails. Claiming before that would take the owner's live lanes for
|
|
326
|
+
* foreign ones; the next claim tries the reconciliation again.
|
|
327
|
+
*/
|
|
328
|
+
declare class ReconcileFailedError extends RelayBusError {
|
|
329
|
+
name: string;
|
|
330
|
+
readonly code: string;
|
|
290
331
|
}
|
|
291
332
|
|
|
292
|
-
export { PgExecutor, type PgExecutorOptions, type PostgresConnectionOptions, PostgresEventStore, type PostgresEventStoreOptions, type PostgresEventStoreSettings, PostgresExecutor, type PostgresExecutorOptions, type PostgresNames, PostgresParameter, type PostgresPoolOptions, PostgresQueryOptions, PostgresRow, type PostgresSchemaOptions, type PostgresWakeUp, createPostgresSchemaSql, createPostgresSchemaStatements, resolvePostgresNames };
|
|
333
|
+
export { PgExecutor, type PgExecutorOptions, type PostgresConnectionOptions, PostgresEventStore, type PostgresEventStoreOptions, type PostgresEventStoreSettings, PostgresExecutor, type PostgresExecutorOptions, type PostgresNames, PostgresParameter, type PostgresPoolOptions, PostgresQueryOptions, PostgresRow, type PostgresSchemaOptions, type PostgresWakeUp, ReconcileFailedError, createPostgresSchemaSql, createPostgresSchemaStatements, resolvePostgresNames };
|