@contember/database 2.2.0-alpha.1 → 2.2.0-alpha.10
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/CLAUDE.md +19 -0
- package/dist/development/index.cjs +5 -0
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +6 -1
- package/dist/development/index.js.map +1 -1
- package/dist/development/src/builders/LimitByGroupWrapper.cjs +1 -1
- package/dist/development/src/builders/LimitByGroupWrapper.cjs.map +1 -1
- package/dist/development/src/builders/LimitByGroupWrapper.js +1 -1
- package/dist/development/src/builders/LimitByGroupWrapper.js.map +1 -1
- package/dist/development/src/builders/WindowFunction.cjs +1 -1
- package/dist/development/src/builders/WindowFunction.cjs.map +1 -1
- package/dist/development/src/builders/WindowFunction.js +1 -1
- package/dist/development/src/builders/WindowFunction.js.map +1 -1
- package/dist/development/src/client/AcquiredConnection.cjs +105 -32
- package/dist/development/src/client/AcquiredConnection.cjs.map +1 -1
- package/dist/development/src/client/AcquiredConnection.js +107 -34
- package/dist/development/src/client/AcquiredConnection.js.map +1 -1
- package/dist/development/src/client/Client.cjs +9 -1
- package/dist/development/src/client/Client.cjs.map +1 -1
- package/dist/development/src/client/Client.js +9 -1
- package/dist/development/src/client/Client.js.map +1 -1
- package/dist/development/src/client/Connection.cjs +8 -1
- package/dist/development/src/client/Connection.cjs.map +1 -1
- package/dist/development/src/client/Connection.js +8 -1
- package/dist/development/src/client/Connection.js.map +1 -1
- package/dist/development/src/client/EventManager.cjs +6 -2
- package/dist/development/src/client/EventManager.cjs.map +1 -1
- package/dist/development/src/client/EventManager.js +6 -2
- package/dist/development/src/client/EventManager.js.map +1 -1
- package/dist/development/src/client/RequestMemoryBudget.cjs +237 -0
- package/dist/development/src/client/RequestMemoryBudget.cjs.map +1 -0
- package/dist/development/src/client/RequestMemoryBudget.js +237 -0
- package/dist/development/src/client/RequestMemoryBudget.js.map +1 -0
- package/dist/development/src/client/Transaction.cjs +20 -8
- package/dist/development/src/client/Transaction.cjs.map +1 -1
- package/dist/development/src/client/Transaction.js +21 -9
- package/dist/development/src/client/Transaction.js.map +1 -1
- package/dist/development/src/client/cancelRunningStatement.cjs +32 -0
- package/dist/development/src/client/cancelRunningStatement.cjs.map +1 -0
- package/dist/development/src/client/cancelRunningStatement.js +32 -0
- package/dist/development/src/client/cancelRunningStatement.js.map +1 -0
- package/dist/development/src/client/errors.cjs +6 -0
- package/dist/development/src/client/errors.cjs.map +1 -1
- package/dist/development/src/client/errors.js +6 -0
- package/dist/development/src/client/errors.js.map +1 -1
- package/dist/development/src/utils/pgClientFactory.cjs +4 -1
- package/dist/development/src/utils/pgClientFactory.cjs.map +1 -1
- package/dist/development/src/utils/pgClientFactory.js +4 -1
- package/dist/development/src/utils/pgClientFactory.js.map +1 -1
- package/dist/production/index.cjs +5 -0
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +6 -1
- package/dist/production/index.js.map +1 -1
- package/dist/production/src/builders/LimitByGroupWrapper.cjs +1 -1
- package/dist/production/src/builders/LimitByGroupWrapper.cjs.map +1 -1
- package/dist/production/src/builders/LimitByGroupWrapper.js +1 -1
- package/dist/production/src/builders/LimitByGroupWrapper.js.map +1 -1
- package/dist/production/src/builders/WindowFunction.cjs +1 -1
- package/dist/production/src/builders/WindowFunction.cjs.map +1 -1
- package/dist/production/src/builders/WindowFunction.js +1 -1
- package/dist/production/src/builders/WindowFunction.js.map +1 -1
- package/dist/production/src/client/AcquiredConnection.cjs +105 -32
- package/dist/production/src/client/AcquiredConnection.cjs.map +1 -1
- package/dist/production/src/client/AcquiredConnection.js +107 -34
- package/dist/production/src/client/AcquiredConnection.js.map +1 -1
- package/dist/production/src/client/Client.cjs +9 -1
- package/dist/production/src/client/Client.cjs.map +1 -1
- package/dist/production/src/client/Client.js +9 -1
- package/dist/production/src/client/Client.js.map +1 -1
- package/dist/production/src/client/Connection.cjs +8 -1
- package/dist/production/src/client/Connection.cjs.map +1 -1
- package/dist/production/src/client/Connection.js +8 -1
- package/dist/production/src/client/Connection.js.map +1 -1
- package/dist/production/src/client/EventManager.cjs +6 -2
- package/dist/production/src/client/EventManager.cjs.map +1 -1
- package/dist/production/src/client/EventManager.js +6 -2
- package/dist/production/src/client/EventManager.js.map +1 -1
- package/dist/production/src/client/RequestMemoryBudget.cjs +237 -0
- package/dist/production/src/client/RequestMemoryBudget.cjs.map +1 -0
- package/dist/production/src/client/RequestMemoryBudget.js +237 -0
- package/dist/production/src/client/RequestMemoryBudget.js.map +1 -0
- package/dist/production/src/client/Transaction.cjs +20 -8
- package/dist/production/src/client/Transaction.cjs.map +1 -1
- package/dist/production/src/client/Transaction.js +21 -9
- package/dist/production/src/client/Transaction.js.map +1 -1
- package/dist/production/src/client/cancelRunningStatement.cjs +32 -0
- package/dist/production/src/client/cancelRunningStatement.cjs.map +1 -0
- package/dist/production/src/client/cancelRunningStatement.js +32 -0
- package/dist/production/src/client/cancelRunningStatement.js.map +1 -0
- package/dist/production/src/client/errors.cjs +6 -0
- package/dist/production/src/client/errors.cjs.map +1 -1
- package/dist/production/src/client/errors.js +6 -0
- package/dist/production/src/client/errors.js.map +1 -1
- package/dist/production/src/utils/pgClientFactory.cjs +4 -1
- package/dist/production/src/utils/pgClientFactory.cjs.map +1 -1
- package/dist/production/src/utils/pgClientFactory.js +4 -1
- package/dist/production/src/utils/pgClientFactory.js.map +1 -1
- package/dist/tests/cases/integration/requestMemoryBudget.test.d.ts +2 -0
- package/dist/tests/cases/integration/requestMemoryBudget.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/acquiredConnection.test.d.ts +2 -0
- package/dist/tests/cases/unit/acquiredConnection.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/createConnectionMockAlt.d.ts +6 -3
- package/dist/tests/cases/unit/createConnectionMockAlt.d.ts.map +1 -1
- package/dist/tests/cases/unit/requestMemoryBudget.test.d.ts +2 -0
- package/dist/tests/cases/unit/requestMemoryBudget.test.d.ts.map +1 -0
- package/dist/tests/src/tags.d.ts.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/Literal.d.ts.map +1 -1
- package/dist/types/builders/CaseStatement.d.ts.map +1 -1
- package/dist/types/builders/ColumnExpressionFactory.d.ts.map +1 -1
- package/dist/types/builders/Compiler.d.ts.map +1 -1
- package/dist/types/builders/ConditionBuilder.d.ts.map +1 -1
- package/dist/types/builders/DeleteBuilder.d.ts.map +1 -1
- package/dist/types/builders/InsertBuilder.d.ts.map +1 -1
- package/dist/types/builders/LimitByGroupWrapper.d.ts.map +1 -1
- package/dist/types/builders/SelectBuilder.d.ts.map +1 -1
- package/dist/types/builders/UpdateBuilder.d.ts.map +1 -1
- package/dist/types/builders/WindowFunction.d.ts +2 -1
- package/dist/types/builders/WindowFunction.d.ts.map +1 -1
- package/dist/types/builders/internal/Returning.d.ts.map +1 -1
- package/dist/types/builders/internal/Where.d.ts.map +1 -1
- package/dist/types/builders/internal/With.d.ts.map +1 -1
- package/dist/types/client/AcquiredConnection.d.ts +6 -1
- package/dist/types/client/AcquiredConnection.d.ts.map +1 -1
- package/dist/types/client/Client.d.ts +8 -0
- package/dist/types/client/Client.d.ts.map +1 -1
- package/dist/types/client/Connection.d.ts.map +1 -1
- package/dist/types/client/EventManager.d.ts +5 -1
- package/dist/types/client/EventManager.d.ts.map +1 -1
- package/dist/types/client/PgClient.d.ts +12 -1
- package/dist/types/client/PgClient.d.ts.map +1 -1
- package/dist/types/client/Pool.d.ts.map +1 -1
- package/dist/types/client/RequestMemoryBudget.d.ts +41 -0
- package/dist/types/client/RequestMemoryBudget.d.ts.map +1 -0
- package/dist/types/client/ScopeLimitedConnection.d.ts.map +1 -1
- package/dist/types/client/Transaction.d.ts +3 -3
- package/dist/types/client/Transaction.d.ts.map +1 -1
- package/dist/types/client/cancelRunningStatement.d.ts +7 -0
- package/dist/types/client/cancelRunningStatement.d.ts.map +1 -0
- package/dist/types/client/errors.d.ts +3 -0
- package/dist/types/client/errors.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/metadata/DatabaseMetadata.d.ts.map +1 -1
- package/dist/types/metadata/DatabaseMetadataResolver.d.ts.map +1 -1
- package/dist/types/metadata/ForeignKeyConstraintMetadata.d.ts.map +1 -1
- package/dist/types/metadata/IndexMetadata.d.ts.map +1 -1
- package/dist/types/metadata/UniqueConstraintMetadata.d.ts.map +1 -1
- package/dist/types/metadata/stringArrayEquals.d.ts.map +1 -1
- package/dist/types/queryable/DatabaseQuery.d.ts.map +1 -1
- package/dist/types/queryable/DatabaseQueryable.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types.d.ts +15 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/ConstraintHelper.d.ts.map +1 -1
- package/dist/types/utils/Mutex.d.ts.map +1 -1
- package/dist/types/utils/Semaphore.d.ts.map +1 -1
- package/dist/types/utils/createDatabaseIfNotExists.d.ts.map +1 -1
- package/dist/types/utils/listen.d.ts.map +1 -1
- package/dist/types/utils/pgClientFactory.d.ts.map +1 -1
- package/dist/types/utils/retryTransaction.d.ts.map +1 -1
- package/dist/types/utils/sql.d.ts.map +1 -1
- package/dist/types/utils/withDatabaseAdvisoryLock.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/builders/LimitByGroupWrapper.ts +1 -1
- package/src/builders/WindowFunction.ts +3 -2
- package/src/client/AcquiredConnection.ts +125 -33
- package/src/client/Client.ts +11 -1
- package/src/client/Connection.ts +9 -1
- package/src/client/EventManager.ts +11 -1
- package/src/client/PgClient.ts +16 -1
- package/src/client/RequestMemoryBudget.ts +260 -0
- package/src/client/Transaction.ts +21 -8
- package/src/client/cancelRunningStatement.ts +36 -0
- package/src/client/errors.ts +6 -0
- package/src/index.ts +1 -0
- package/src/types.ts +15 -0
- package/src/utils/pgClientFactory.ts +4 -1
- package/tests/cases/integration/requestMemoryBudget.test.ts +296 -0
- package/tests/cases/unit/acquiredConnection.test.ts +154 -0
- package/tests/cases/unit/connection.test.ts +32 -0
- package/tests/cases/unit/createConnectionMockAlt.ts +17 -3
- package/tests/cases/unit/queryBuilder.test.ts +22 -1
- package/tests/cases/unit/requestMemoryBudget.test.ts +287 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { EventManager } from "./EventManager.js";
|
|
1
2
|
import { wrapIdentifier } from "../utils/sql.js";
|
|
2
3
|
import "../builders/Compiler.js";
|
|
3
4
|
import "../Literal.js";
|
|
4
5
|
import "../builders/SelectBuilder.js";
|
|
5
6
|
import "../builders/internal/With.js";
|
|
6
7
|
import "../builders/internal/Where.js";
|
|
7
|
-
import "./EventManager.js";
|
|
8
8
|
import "@contember/queryable";
|
|
9
|
-
import { CannotCommitError } from "./errors.js";
|
|
9
|
+
import { CannotCommitError, TerminatedConnectionError } from "./errors.js";
|
|
10
10
|
import "./Connection.js";
|
|
11
11
|
import "node:timers";
|
|
12
12
|
import "../utils/Mutex.js";
|
|
@@ -47,7 +47,7 @@ class Transaction {
|
|
|
47
47
|
}, { eventManager: this.eventManager });
|
|
48
48
|
}
|
|
49
49
|
async rollback() {
|
|
50
|
-
await this.close("ROLLBACK");
|
|
50
|
+
await this.close("ROLLBACK", new EventManager(this.eventManager, null));
|
|
51
51
|
}
|
|
52
52
|
async commit() {
|
|
53
53
|
const commitResult = await this.close("COMMIT");
|
|
@@ -55,8 +55,11 @@ class Transaction {
|
|
|
55
55
|
throw new CannotCommitError("Unexpected commit result: " + commitResult.command);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
async close(command) {
|
|
59
|
-
|
|
58
|
+
async close(command, eventManager = this.eventManager) {
|
|
59
|
+
if (this.isClosed) {
|
|
60
|
+
throw new Error("Transaction is already closed");
|
|
61
|
+
}
|
|
62
|
+
const result = await this.scope((connection) => connection.query(command), { eventManager });
|
|
60
63
|
this.state.close();
|
|
61
64
|
return result;
|
|
62
65
|
}
|
|
@@ -95,13 +98,16 @@ class SavePoint {
|
|
|
95
98
|
}, { eventManager: this.eventManager });
|
|
96
99
|
}
|
|
97
100
|
async rollback() {
|
|
98
|
-
await this.close(`ROLLBACK TO SAVEPOINT ${wrapIdentifier(this.savepointName)}
|
|
101
|
+
await this.close(`ROLLBACK TO SAVEPOINT ${wrapIdentifier(this.savepointName)}`, new EventManager(this.eventManager, null));
|
|
99
102
|
}
|
|
100
103
|
async commit() {
|
|
101
104
|
await this.close(`RELEASE SAVEPOINT ${wrapIdentifier(this.savepointName)}`);
|
|
102
105
|
}
|
|
103
|
-
async close(sql) {
|
|
104
|
-
|
|
106
|
+
async close(sql, eventManager = this.eventManager) {
|
|
107
|
+
if (this.isClosed) {
|
|
108
|
+
throw new Error(`Savepoint ${this.savepointName} is already closed.`);
|
|
109
|
+
}
|
|
110
|
+
await this.scope((connection) => connection.query(sql), { eventManager });
|
|
105
111
|
this.state.close();
|
|
106
112
|
}
|
|
107
113
|
}
|
|
@@ -136,7 +142,13 @@ const executeTransaction = async (transaction, callback) => {
|
|
|
136
142
|
return result;
|
|
137
143
|
} catch (e) {
|
|
138
144
|
if (!transaction.isClosed) {
|
|
139
|
-
|
|
145
|
+
try {
|
|
146
|
+
await transaction.rollback();
|
|
147
|
+
} catch (rollbackError) {
|
|
148
|
+
if (!(rollbackError instanceof TerminatedConnectionError)) {
|
|
149
|
+
throw rollbackError;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
140
152
|
}
|
|
141
153
|
throw e;
|
|
142
154
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transaction.js","sources":["../../../../../packages/database/src/client/Transaction.ts"],"sourcesContent":["import { Connection } from './Connection.js'\nimport { EventManager } from './EventManager.js'\nimport { wrapIdentifier } from '../utils/index.js'\nimport { Notification } from 'pg'\nimport { CannotCommitError, DatabaseError } from './errors.js'\n\nexport class Transaction implements Connection.TransactionLike {\n\tpublic get isClosed(): boolean {\n\t\treturn this.state.isClosed\n\t}\n\n\tpublic on\n\n\tconstructor(\n\t\tprivate readonly connection: Connection.AcquiredConnectionLike,\n\t\tprivate readonly savepointManager = new SavepointState(),\n\t\tprivate readonly state = new TransactionLikeState(),\n\t) {\n\t\tthis.on = this.connection.on.bind(this.connection)\n\t}\n\n\tget eventManager() {\n\t\treturn this.connection.eventManager\n\t}\n\n\tasync scope<Result>(\n\t\tcallback: (connection: Connection.TransactionLike) => Promise<Result> | Result,\n\t\t{ eventManager = this.eventManager }: { eventManager?: EventManager } = {},\n\t): Promise<Result> {\n\t\treturn await this.connection.scope(async connection => {\n\t\t\treturn await callback(new Transaction(connection, this.savepointManager, this.state))\n\t\t}, { eventManager })\n\t}\n\n\tasync transaction<Result>(\n\t\tcallback: (connection: Connection.TransactionLike) => Promise<Result> | Result,\n\t\toptions?: { eventManager?: EventManager },\n\t): Promise<Result> {\n\t\treturn await this.scope(async connection => {\n\t\t\treturn await this.savepointManager.execute(connection, callback)\n\t\t}, options)\n\t}\n\n\tasync query<Row extends Record<string, any>>(\n\t\tsql: string,\n\t\tparameters: any[] = [],\n\t\tmeta: Record<string, any> = {},\n\t): Promise<Connection.Result<Row>> {\n\t\tif (this.isClosed) {\n\t\t\tthrow new Error('Transaction is already closed')\n\t\t}\n\t\treturn await this.connection.scope(async connection => {\n\t\t\treturn connection.query(sql, parameters, meta)\n\t\t}, { eventManager: this.eventManager })\n\t}\n\n\tasync rollback(): Promise<void> {\n\t\tawait this.close('ROLLBACK')\n\t}\n\n\tasync commit(): Promise<void> {\n\t\tconst commitResult = await this.close('COMMIT')\n\t\tif (commitResult.command !== 'COMMIT') {\n\t\t\tthrow new CannotCommitError('Unexpected commit result: ' + commitResult.command)\n\t\t}\n\t}\n\n\tprivate async close(command: string) {\n\t\tconst result = await this.query(command)\n\t\tthis.state.close()\n\t\treturn result\n\t}\n}\n\nclass SavePoint implements Connection.TransactionLike {\n\tpublic on\n\n\tconstructor(\n\t\tpublic readonly savepointName: string,\n\t\tpublic readonly savepointManager: SavepointState,\n\t\tprivate readonly connection: Connection.AcquiredConnectionLike,\n\t\tprivate readonly state = new TransactionLikeState(),\n\t) {\n\t\tthis.on = this.connection.on.bind(this.connection)\n\t}\n\n\tget isClosed() {\n\t\treturn this.state.isClosed\n\t}\n\n\tget eventManager() {\n\t\treturn this.connection.eventManager\n\t}\n\n\tasync scope<Result>(\n\t\tcallback: (connection: Connection.TransactionLike) => Promise<Result> | Result,\n\t\t{ eventManager = this.eventManager }: { eventManager?: EventManager } = {},\n\t): Promise<Result> {\n\t\treturn this.connection.scope(async connection => {\n\t\t\treturn await callback(new SavePoint(this.savepointName, this.savepointManager, connection, this.state))\n\t\t}, { eventManager })\n\t}\n\n\tasync transaction<Result>(\n\t\tcallback: (connection: Connection.TransactionLike) => Promise<Result> | Result,\n\t\toptions: { eventManager?: EventManager } = {},\n\t): Promise<Result> {\n\t\treturn await this.scope(async connection => {\n\t\t\treturn await this.savepointManager.execute(connection, callback)\n\t\t}, options)\n\t}\n\n\tasync query<Row extends Record<string, any>>(\n\t\tsql: string,\n\t\tparameters: any[] = [],\n\t\tmeta: Record<string, any> = {},\n\t): Promise<Connection.Result<Row>> {\n\t\tif (this.isClosed) {\n\t\t\tthrow new Error(`Savepoint ${this.savepointName} is already closed.`)\n\t\t}\n\t\treturn await this.connection.scope(connection => {\n\t\t\treturn connection.query(sql, parameters, meta)\n\t\t}, { eventManager: this.eventManager })\n\t}\n\n\tasync rollback(): Promise<void> {\n\t\tawait this.close(`ROLLBACK TO SAVEPOINT ${wrapIdentifier(this.savepointName)}
|
|
1
|
+
{"version":3,"file":"Transaction.js","sources":["../../../../../packages/database/src/client/Transaction.ts"],"sourcesContent":["import { Connection } from './Connection.js'\nimport { EventManager } from './EventManager.js'\nimport { wrapIdentifier } from '../utils/index.js'\nimport { Notification } from 'pg'\nimport { CannotCommitError, DatabaseError, TerminatedConnectionError } from './errors.js'\n\nexport class Transaction implements Connection.TransactionLike {\n\tpublic get isClosed(): boolean {\n\t\treturn this.state.isClosed\n\t}\n\n\tpublic on\n\n\tconstructor(\n\t\tprivate readonly connection: Connection.AcquiredConnectionLike,\n\t\tprivate readonly savepointManager = new SavepointState(),\n\t\tprivate readonly state = new TransactionLikeState(),\n\t) {\n\t\tthis.on = this.connection.on.bind(this.connection)\n\t}\n\n\tget eventManager() {\n\t\treturn this.connection.eventManager\n\t}\n\n\tasync scope<Result>(\n\t\tcallback: (connection: Connection.TransactionLike) => Promise<Result> | Result,\n\t\t{ eventManager = this.eventManager }: { eventManager?: EventManager } = {},\n\t): Promise<Result> {\n\t\treturn await this.connection.scope(async connection => {\n\t\t\treturn await callback(new Transaction(connection, this.savepointManager, this.state))\n\t\t}, { eventManager })\n\t}\n\n\tasync transaction<Result>(\n\t\tcallback: (connection: Connection.TransactionLike) => Promise<Result> | Result,\n\t\toptions?: { eventManager?: EventManager },\n\t): Promise<Result> {\n\t\treturn await this.scope(async connection => {\n\t\t\treturn await this.savepointManager.execute(connection, callback)\n\t\t}, options)\n\t}\n\n\tasync query<Row extends Record<string, any>>(\n\t\tsql: string,\n\t\tparameters: any[] = [],\n\t\tmeta: Record<string, any> = {},\n\t): Promise<Connection.Result<Row>> {\n\t\tif (this.isClosed) {\n\t\t\tthrow new Error('Transaction is already closed')\n\t\t}\n\t\treturn await this.connection.scope(async connection => {\n\t\t\treturn connection.query(sql, parameters, meta)\n\t\t}, { eventManager: this.eventManager })\n\t}\n\n\tasync rollback(): Promise<void> {\n\t\tawait this.close('ROLLBACK', new EventManager(this.eventManager, null))\n\t}\n\n\tasync commit(): Promise<void> {\n\t\tconst commitResult = await this.close('COMMIT')\n\t\tif (commitResult.command !== 'COMMIT') {\n\t\t\tthrow new CannotCommitError('Unexpected commit result: ' + commitResult.command)\n\t\t}\n\t}\n\n\tprivate async close(command: string, eventManager = this.eventManager) {\n\t\tif (this.isClosed) {\n\t\t\tthrow new Error('Transaction is already closed')\n\t\t}\n\t\tconst result = await this.scope(connection => connection.query(command), { eventManager })\n\t\tthis.state.close()\n\t\treturn result\n\t}\n}\n\nclass SavePoint implements Connection.TransactionLike {\n\tpublic on\n\n\tconstructor(\n\t\tpublic readonly savepointName: string,\n\t\tpublic readonly savepointManager: SavepointState,\n\t\tprivate readonly connection: Connection.AcquiredConnectionLike,\n\t\tprivate readonly state = new TransactionLikeState(),\n\t) {\n\t\tthis.on = this.connection.on.bind(this.connection)\n\t}\n\n\tget isClosed() {\n\t\treturn this.state.isClosed\n\t}\n\n\tget eventManager() {\n\t\treturn this.connection.eventManager\n\t}\n\n\tasync scope<Result>(\n\t\tcallback: (connection: Connection.TransactionLike) => Promise<Result> | Result,\n\t\t{ eventManager = this.eventManager }: { eventManager?: EventManager } = {},\n\t): Promise<Result> {\n\t\treturn this.connection.scope(async connection => {\n\t\t\treturn await callback(new SavePoint(this.savepointName, this.savepointManager, connection, this.state))\n\t\t}, { eventManager })\n\t}\n\n\tasync transaction<Result>(\n\t\tcallback: (connection: Connection.TransactionLike) => Promise<Result> | Result,\n\t\toptions: { eventManager?: EventManager } = {},\n\t): Promise<Result> {\n\t\treturn await this.scope(async connection => {\n\t\t\treturn await this.savepointManager.execute(connection, callback)\n\t\t}, options)\n\t}\n\n\tasync query<Row extends Record<string, any>>(\n\t\tsql: string,\n\t\tparameters: any[] = [],\n\t\tmeta: Record<string, any> = {},\n\t): Promise<Connection.Result<Row>> {\n\t\tif (this.isClosed) {\n\t\t\tthrow new Error(`Savepoint ${this.savepointName} is already closed.`)\n\t\t}\n\t\treturn await this.connection.scope(connection => {\n\t\t\treturn connection.query(sql, parameters, meta)\n\t\t}, { eventManager: this.eventManager })\n\t}\n\n\tasync rollback(): Promise<void> {\n\t\tawait this.close(`ROLLBACK TO SAVEPOINT ${wrapIdentifier(this.savepointName)}`, new EventManager(this.eventManager, null))\n\t}\n\n\tasync commit(): Promise<void> {\n\t\tawait this.close(`RELEASE SAVEPOINT ${wrapIdentifier(this.savepointName)}`)\n\t}\n\n\tprivate async close(sql: string, eventManager = this.eventManager) {\n\t\tif (this.isClosed) {\n\t\t\tthrow new Error(`Savepoint ${this.savepointName} is already closed.`)\n\t\t}\n\t\tawait this.scope(connection => connection.query(sql), { eventManager })\n\t\tthis.state.close()\n\t}\n}\n\nclass TransactionLikeState {\n\tprivate _isClosed = false\n\n\tpublic get isClosed(): boolean {\n\t\treturn this._isClosed\n\t}\n\n\tpublic close(): void {\n\t\tthis._isClosed = true\n\t}\n}\n\nclass SavepointState {\n\tpublic counter = 1\n\n\tpublic async execute<Result>(\n\t\tconnection: Connection.AcquiredConnectionLike,\n\t\tcallback: (connection: Connection.TransactionLike) => Promise<Result> | Result,\n\t) {\n\t\tconst savepointName = `savepoint_${this.counter++}`\n\n\t\tawait connection.query(`SAVEPOINT ${wrapIdentifier(savepointName)}`)\n\t\tconst savepoint = new SavePoint(savepointName, this, connection)\n\t\treturn await executeTransaction(savepoint, callback)\n\t}\n}\n\nexport const executeTransaction = async <Result>(\n\ttransaction: Connection.TransactionLike,\n\tcallback: (connection: Connection.TransactionLike) => Promise<Result> | Result,\n) => {\n\ttry {\n\t\tconst result = await callback(transaction)\n\t\tif (!transaction.isClosed) {\n\t\t\tawait transaction.commit()\n\t\t}\n\t\treturn result\n\t} catch (e) {\n\t\tif (!transaction.isClosed) {\n\t\t\ttry {\n\t\t\t\tawait transaction.rollback()\n\t\t\t} catch (rollbackError) {\n\t\t\t\t// PostgreSQL already rolled back the transaction of a terminated connection, whatever terminated it.\n\t\t\t\tif (!(rollbackError instanceof TerminatedConnectionError)) {\n\t\t\t\t\tthrow rollbackError\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthrow e\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAMO,MAAM,YAAkD;AAAA,EAO9D,YACkB,YACA,mBAAmB,IAAI,kBACvB,QAAQ,IAAI,wBAC5B;AAHgB,SAAA,aAAA;AACA,SAAA,mBAAA;AACA,SAAA,QAAA;AALlB,kBAAA,MAAO,IAAA;AAON,SAAK,KAAK,KAAK,WAAW,GAAG,KAAK,KAAK,UAAU;AAAA,EAClD;AAAA,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M;AAAA,QACP;AAAA,MACD;AAAA,IACD;AACA,UAAM;AAAA,EACP;AACD;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const node_net = require("node:net");
|
|
4
|
+
const CANCEL_REQUEST_CODE = 80877102;
|
|
5
|
+
const CANCEL_REQUEST_TIMEOUT_MS = 5e3;
|
|
6
|
+
const cancelRunningStatement = async ({ host, port, processID, secretKey }) => {
|
|
7
|
+
if (processID === null || secretKey === null) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const message = Buffer.alloc(16);
|
|
11
|
+
message.writeInt32BE(16, 0);
|
|
12
|
+
message.writeInt32BE(CANCEL_REQUEST_CODE, 4);
|
|
13
|
+
message.writeInt32BE(processID, 8);
|
|
14
|
+
message.writeInt32BE(secretKey, 12);
|
|
15
|
+
const socket = host.startsWith("/") ? node_net.connect(`${host}/.s.PGSQL.${port}`) : node_net.connect(port, host);
|
|
16
|
+
await new Promise((resolve, reject) => {
|
|
17
|
+
socket.setTimeout(CANCEL_REQUEST_TIMEOUT_MS, () => {
|
|
18
|
+
socket.destroy(new Error(`PostgreSQL cancel request timed out after ${CANCEL_REQUEST_TIMEOUT_MS} ms`));
|
|
19
|
+
});
|
|
20
|
+
socket.once("error", reject);
|
|
21
|
+
socket.once("close", (hadError) => {
|
|
22
|
+
if (!hadError) {
|
|
23
|
+
resolve();
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
socket.once("connect", () => {
|
|
27
|
+
socket.end(message);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
exports.cancelRunningStatement = cancelRunningStatement;
|
|
32
|
+
//# sourceMappingURL=cancelRunningStatement.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancelRunningStatement.cjs","sources":["../../../../../packages/database/src/client/cancelRunningStatement.ts"],"sourcesContent":["import { connect } from 'node:net'\nimport { PgClient } from './PgClient.js'\n\nconst CANCEL_REQUEST_CODE = 80877102\nconst CANCEL_REQUEST_TIMEOUT_MS = 5000\n\n/**\n * Asks the server to cancel the statement the client is running, with a protocol CancelRequest on a separate socket.\n * Closing the client's own socket does not stop a statement that has not sent a row yet.\n */\nexport const cancelRunningStatement = async ({ host, port, processID, secretKey }: PgClient): Promise<void> => {\n\tif (processID === null || secretKey === null) {\n\t\treturn\n\t}\n\tconst message = Buffer.alloc(16)\n\tmessage.writeInt32BE(16, 0)\n\tmessage.writeInt32BE(CANCEL_REQUEST_CODE, 4)\n\tmessage.writeInt32BE(processID, 8)\n\tmessage.writeInt32BE(secretKey, 12)\n\n\tconst socket = host.startsWith('/') ? connect(`${host}/.s.PGSQL.${port}`) : connect(port, host)\n\tawait new Promise<void>((resolve, reject) => {\n\t\tsocket.setTimeout(CANCEL_REQUEST_TIMEOUT_MS, () => {\n\t\t\tsocket.destroy(new Error(`PostgreSQL cancel request timed out after ${CANCEL_REQUEST_TIMEOUT_MS} ms`))\n\t\t})\n\t\tsocket.once('error', reject)\n\t\tsocket.once('close', hadError => {\n\t\t\tif (!hadError) {\n\t\t\t\tresolve()\n\t\t\t}\n\t\t})\n\t\tsocket.once('connect', () => {\n\t\t\tsocket.end(message)\n\t\t})\n\t})\n}\n"],"names":["connect"],"mappings":";;;AAGA,MAAM,sBAAsB;AAC5B,MAAM,4BAA4B;AAM3B,MAAM,yBAAyB,OAAO,EAAE,MAAM,MAAM,WAAW,gBAAyC;AAC9G,MAAI,cAAc,QAAQ,cAAc,MAAM;AAC7C;AAAA,EACD;AACA,QAAM,UAAU,OAAO,MAAM,EAAE;AAC/B,UAAQ,aAAa,IAAI,CAAC;AAC1B,UAAQ,aAAa,qBAAqB,CAAC;AAC3C,UAAQ,aAAa,WAAW,CAAC;AACjC,UAAQ,aAAa,WAAW,EAAE;AAElC,QAAM,SAAS,KAAK,WAAW,GAAG,IAAIA,SAAAA,QAAQ,GAAG,IAAI,aAAa,IAAI,EAAE,IAAIA,SAAAA,QAAQ,MAAM,IAAI;AAC9F,QAAM,IAAI,QAAc,CAAC,SAAS,WAAW;AAC5C,WAAO,WAAW,2BAA2B,MAAM;AAClD,aAAO,QAAQ,IAAI,MAAM,6CAA6C,yBAAyB,KAAK,CAAC;AAAA,IACtG,CAAC;AACD,WAAO,KAAK,SAAS,MAAM;AAC3B,WAAO,KAAK,SAAS,CAAA,aAAY;AAChC,UAAI,CAAC,UAAU;AACd,gBAAA;AAAA,MACD;AAAA,IACD,CAAC;AACD,WAAO,KAAK,WAAW,MAAM;AAC5B,aAAO,IAAI,OAAO;AAAA,IACnB,CAAC;AAAA,EACF,CAAC;AACF;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { connect } from "node:net";
|
|
2
|
+
const CANCEL_REQUEST_CODE = 80877102;
|
|
3
|
+
const CANCEL_REQUEST_TIMEOUT_MS = 5e3;
|
|
4
|
+
const cancelRunningStatement = async ({ host, port, processID, secretKey }) => {
|
|
5
|
+
if (processID === null || secretKey === null) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const message = Buffer.alloc(16);
|
|
9
|
+
message.writeInt32BE(16, 0);
|
|
10
|
+
message.writeInt32BE(CANCEL_REQUEST_CODE, 4);
|
|
11
|
+
message.writeInt32BE(processID, 8);
|
|
12
|
+
message.writeInt32BE(secretKey, 12);
|
|
13
|
+
const socket = host.startsWith("/") ? connect(`${host}/.s.PGSQL.${port}`) : connect(port, host);
|
|
14
|
+
await new Promise((resolve, reject) => {
|
|
15
|
+
socket.setTimeout(CANCEL_REQUEST_TIMEOUT_MS, () => {
|
|
16
|
+
socket.destroy(new Error(`PostgreSQL cancel request timed out after ${CANCEL_REQUEST_TIMEOUT_MS} ms`));
|
|
17
|
+
});
|
|
18
|
+
socket.once("error", reject);
|
|
19
|
+
socket.once("close", (hadError) => {
|
|
20
|
+
if (!hadError) {
|
|
21
|
+
resolve();
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
socket.once("connect", () => {
|
|
25
|
+
socket.end(message);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
cancelRunningStatement
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=cancelRunningStatement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancelRunningStatement.js","sources":["../../../../../packages/database/src/client/cancelRunningStatement.ts"],"sourcesContent":["import { connect } from 'node:net'\nimport { PgClient } from './PgClient.js'\n\nconst CANCEL_REQUEST_CODE = 80877102\nconst CANCEL_REQUEST_TIMEOUT_MS = 5000\n\n/**\n * Asks the server to cancel the statement the client is running, with a protocol CancelRequest on a separate socket.\n * Closing the client's own socket does not stop a statement that has not sent a row yet.\n */\nexport const cancelRunningStatement = async ({ host, port, processID, secretKey }: PgClient): Promise<void> => {\n\tif (processID === null || secretKey === null) {\n\t\treturn\n\t}\n\tconst message = Buffer.alloc(16)\n\tmessage.writeInt32BE(16, 0)\n\tmessage.writeInt32BE(CANCEL_REQUEST_CODE, 4)\n\tmessage.writeInt32BE(processID, 8)\n\tmessage.writeInt32BE(secretKey, 12)\n\n\tconst socket = host.startsWith('/') ? connect(`${host}/.s.PGSQL.${port}`) : connect(port, host)\n\tawait new Promise<void>((resolve, reject) => {\n\t\tsocket.setTimeout(CANCEL_REQUEST_TIMEOUT_MS, () => {\n\t\t\tsocket.destroy(new Error(`PostgreSQL cancel request timed out after ${CANCEL_REQUEST_TIMEOUT_MS} ms`))\n\t\t})\n\t\tsocket.once('error', reject)\n\t\tsocket.once('close', hadError => {\n\t\t\tif (!hadError) {\n\t\t\t\tresolve()\n\t\t\t}\n\t\t})\n\t\tsocket.once('connect', () => {\n\t\t\tsocket.end(message)\n\t\t})\n\t})\n}\n"],"names":[],"mappings":";AAGA,MAAM,sBAAsB;AAC5B,MAAM,4BAA4B;AAM3B,MAAM,yBAAyB,OAAO,EAAE,MAAM,MAAM,WAAW,gBAAyC;AAC9G,MAAI,cAAc,QAAQ,cAAc,MAAM;AAC7C;AAAA,EACD;AACA,QAAM,UAAU,OAAO,MAAM,EAAE;AAC/B,UAAQ,aAAa,IAAI,CAAC;AAC1B,UAAQ,aAAa,qBAAqB,CAAC;AAC3C,UAAQ,aAAa,WAAW,CAAC;AACjC,UAAQ,aAAa,WAAW,EAAE;AAElC,QAAM,SAAS,KAAK,WAAW,GAAG,IAAI,QAAQ,GAAG,IAAI,aAAa,IAAI,EAAE,IAAI,QAAQ,MAAM,IAAI;AAC9F,QAAM,IAAI,QAAc,CAAC,SAAS,WAAW;AAC5C,WAAO,WAAW,2BAA2B,MAAM;AAClD,aAAO,QAAQ,IAAI,MAAM,6CAA6C,yBAAyB,KAAK,CAAC;AAAA,IACtG,CAAC;AACD,WAAO,KAAK,SAAS,MAAM;AAC3B,WAAO,KAAK,SAAS,CAAA,aAAY;AAChC,UAAI,CAAC,UAAU;AACd,gBAAA;AAAA,MACD;AAAA,IACD,CAAC;AACD,WAAO,KAAK,WAAW,MAAM;AAC5B,aAAO,IAAI,OAAO;AAAA,IACnB,CAAC;AAAA,EACF,CAAC;AACF;"}
|
|
@@ -55,6 +55,11 @@ class TransactionAbortedError extends QueryError {
|
|
|
55
55
|
}
|
|
56
56
|
class CannotCommitError extends DatabaseError {
|
|
57
57
|
}
|
|
58
|
+
class TerminatedConnectionError extends DatabaseError {
|
|
59
|
+
constructor() {
|
|
60
|
+
super("Database connection was terminated");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
58
63
|
exports.CannotCommitError = CannotCommitError;
|
|
59
64
|
exports.ClientError = ClientError;
|
|
60
65
|
exports.DatabaseError = DatabaseError;
|
|
@@ -63,6 +68,7 @@ exports.InvalidDataError = InvalidDataError;
|
|
|
63
68
|
exports.NotNullViolationError = NotNullViolationError;
|
|
64
69
|
exports.QueryError = QueryError;
|
|
65
70
|
exports.SerializationFailureError = SerializationFailureError;
|
|
71
|
+
exports.TerminatedConnectionError = TerminatedConnectionError;
|
|
66
72
|
exports.TransactionAbortedError = TransactionAbortedError;
|
|
67
73
|
exports.UniqueViolationError = UniqueViolationError;
|
|
68
74
|
//# sourceMappingURL=errors.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","sources":["../../../../../packages/database/src/client/errors.ts"],"sourcesContent":["export class DatabaseError extends Error {\n\tpublic readonly code?: string\n\tpublic readonly originalMessage?: string\n\tpublic readonly previous: any\n\n\tconstructor(errMessage: string, previous?: Error | any) {\n\t\tsuper(errMessage)\n\t\tif (previous) {\n\t\t\tconst { message, stack, ...other } = previous\n\t\t\tconst otherDefined = Object.fromEntries(Object.entries(other).filter(it => it[1] !== undefined))\n\t\t\tthis.previous = { message, ...otherDefined }\n\t\t\tthis.code = previous.code\n\t\t\tthis.originalMessage = previous.message\n\t\t}\n\t}\n}\n\nexport type ClientErrorType =\n\t| 'recoverable connection error'\n\t| 'connection error'\n\t| 'runtime error'\n\t| 'disposal error'\n\nexport class ClientError extends DatabaseError {\n\tconstructor(previous: Error | any, public readonly type: ClientErrorType) {\n\t\tsuper(`Database client ${type}: ${'message' in previous && previous.message ? previous.message : JSON.stringify(previous)}`, previous)\n\t}\n}\n\nexport class QueryError extends DatabaseError {\n\tpublic readonly constraint?: string\n\tpublic readonly table?: string\n\n\tconstructor(public readonly sql: string, public readonly parameters: any, public override readonly previous: Error | any) {\n\t\tsuper(\n\t\t\t`Database query error: ${'message' in previous && previous.message ? previous.message : JSON.stringify(previous)}\nSQL: ${sql}\nparameters: ${parameters}`,\n\t\t\tprevious,\n\t\t)\n\t\tthis.constraint = previous.constraint\n\t\tthis.table = previous.table\n\t}\n}\n\nexport class NotNullViolationError extends QueryError {}\n\nexport class ForeignKeyViolationError extends QueryError {}\n\nexport class UniqueViolationError extends QueryError {}\n\nexport class SerializationFailureError extends QueryError {}\n\nexport class InvalidDataError extends QueryError {}\n\nexport class TransactionAbortedError extends QueryError {}\n\nexport class C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AAyB,WAAW;AAAC;AAE3C,MAAM,gCAAgC,WAAW;AAAC;AAElD,MAAM,0BAA0B,cAAc;AAAC
|
|
1
|
+
{"version":3,"file":"errors.cjs","sources":["../../../../../packages/database/src/client/errors.ts"],"sourcesContent":["export class DatabaseError extends Error {\n\tpublic readonly code?: string\n\tpublic readonly originalMessage?: string\n\tpublic readonly previous: any\n\n\tconstructor(errMessage: string, previous?: Error | any) {\n\t\tsuper(errMessage)\n\t\tif (previous) {\n\t\t\tconst { message, stack, ...other } = previous\n\t\t\tconst otherDefined = Object.fromEntries(Object.entries(other).filter(it => it[1] !== undefined))\n\t\t\tthis.previous = { message, ...otherDefined }\n\t\t\tthis.code = previous.code\n\t\t\tthis.originalMessage = previous.message\n\t\t}\n\t}\n}\n\nexport type ClientErrorType =\n\t| 'recoverable connection error'\n\t| 'connection error'\n\t| 'runtime error'\n\t| 'disposal error'\n\nexport class ClientError extends DatabaseError {\n\tconstructor(previous: Error | any, public readonly type: ClientErrorType) {\n\t\tsuper(`Database client ${type}: ${'message' in previous && previous.message ? previous.message : JSON.stringify(previous)}`, previous)\n\t}\n}\n\nexport class QueryError extends DatabaseError {\n\tpublic readonly constraint?: string\n\tpublic readonly table?: string\n\n\tconstructor(public readonly sql: string, public readonly parameters: any, public override readonly previous: Error | any) {\n\t\tsuper(\n\t\t\t`Database query error: ${'message' in previous && previous.message ? previous.message : JSON.stringify(previous)}\nSQL: ${sql}\nparameters: ${parameters}`,\n\t\t\tprevious,\n\t\t)\n\t\tthis.constraint = previous.constraint\n\t\tthis.table = previous.table\n\t}\n}\n\nexport class NotNullViolationError extends QueryError {}\n\nexport class ForeignKeyViolationError extends QueryError {}\n\nexport class UniqueViolationError extends QueryError {}\n\nexport class SerializationFailureError extends QueryError {}\n\nexport class InvalidDataError extends QueryError {}\n\nexport class TransactionAbortedError extends QueryError {}\n\nexport class CannotCommitError extends DatabaseError {}\n\nexport class TerminatedConnectionError extends DatabaseError {\n\tconstructor() {\n\t\tsuper('Database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AyB,WAAW;AAAC;AAE3C,MAAM,gCAAgC,WAAW;AAAC;AAElD,MAAM,0BAA0B,cAAc;AAAC;AAE/C,MAAM,kCAAkC,cAAc;AAAA,EAC5D,cAAc;AACb,UAAM,oCAAoC;AAAA,EAC3C;AACD;;;;;;;;;;;;"}
|
|
@@ -53,6 +53,11 @@ class TransactionAbortedError extends QueryError {
|
|
|
53
53
|
}
|
|
54
54
|
class CannotCommitError extends DatabaseError {
|
|
55
55
|
}
|
|
56
|
+
class TerminatedConnectionError extends DatabaseError {
|
|
57
|
+
constructor() {
|
|
58
|
+
super("Database connection was terminated");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
56
61
|
export {
|
|
57
62
|
CannotCommitError,
|
|
58
63
|
ClientError,
|
|
@@ -62,6 +67,7 @@ export {
|
|
|
62
67
|
NotNullViolationError,
|
|
63
68
|
QueryError,
|
|
64
69
|
SerializationFailureError,
|
|
70
|
+
TerminatedConnectionError,
|
|
65
71
|
TransactionAbortedError,
|
|
66
72
|
UniqueViolationError
|
|
67
73
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sources":["../../../../../packages/database/src/client/errors.ts"],"sourcesContent":["export class DatabaseError extends Error {\n\tpublic readonly code?: string\n\tpublic readonly originalMessage?: string\n\tpublic readonly previous: any\n\n\tconstructor(errMessage: string, previous?: Error | any) {\n\t\tsuper(errMessage)\n\t\tif (previous) {\n\t\t\tconst { message, stack, ...other } = previous\n\t\t\tconst otherDefined = Object.fromEntries(Object.entries(other).filter(it => it[1] !== undefined))\n\t\t\tthis.previous = { message, ...otherDefined }\n\t\t\tthis.code = previous.code\n\t\t\tthis.originalMessage = previous.message\n\t\t}\n\t}\n}\n\nexport type ClientErrorType =\n\t| 'recoverable connection error'\n\t| 'connection error'\n\t| 'runtime error'\n\t| 'disposal error'\n\nexport class ClientError extends DatabaseError {\n\tconstructor(previous: Error | any, public readonly type: ClientErrorType) {\n\t\tsuper(`Database client ${type}: ${'message' in previous && previous.message ? previous.message : JSON.stringify(previous)}`, previous)\n\t}\n}\n\nexport class QueryError extends DatabaseError {\n\tpublic readonly constraint?: string\n\tpublic readonly table?: string\n\n\tconstructor(public readonly sql: string, public readonly parameters: any, public override readonly previous: Error | any) {\n\t\tsuper(\n\t\t\t`Database query error: ${'message' in previous && previous.message ? previous.message : JSON.stringify(previous)}\nSQL: ${sql}\nparameters: ${parameters}`,\n\t\t\tprevious,\n\t\t)\n\t\tthis.constraint = previous.constraint\n\t\tthis.table = previous.table\n\t}\n}\n\nexport class NotNullViolationError extends QueryError {}\n\nexport class ForeignKeyViolationError extends QueryError {}\n\nexport class UniqueViolationError extends QueryError {}\n\nexport class SerializationFailureError extends QueryError {}\n\nexport class InvalidDataError extends QueryError {}\n\nexport class TransactionAbortedError extends QueryError {}\n\nexport class CannotCommitError extends DatabaseError {}\n"],"names":[],"mappings":";;;AAAO,MAAM,sBAAsB,MAAM;AAAA,EAKxC,YAAY,YAAoB,UAAwB;AACvD,UAAM,UAAU;AALjB,kBAAA,MAAgB,MAAA;AAChB,kBAAA,MAAgB,iBAAA;AAChB,kBAAA,MAAgB,UAAA;AAIf,QAAI,UAAU;AACb,YAAM,EAAE,SAAS,OAAO,GAAG,UAAU;AACrC,YAAM,eAAe,OAAO,YAAY,OAAO,QAAQ,KAAK,EAAE,OAAO,CAAA,OAAM,GAAG,CAAC,MAAM,MAAS,CAAC;AAC/F,WAAK,WAAW,EAAE,SAAS,GAAG,aAAA;AAC9B,WAAK,OAAO,SAAS;AACrB,WAAK,kBAAkB,SAAS;AAAA,IACjC;AAAA,EACD;AACD;AAQO,MAAM,oBAAoB,cAAc;AAAA,EAC9C,YAAY,UAAuC,MAAuB;AACzE,UAAM,mBAAmB,IAAI,KAAK,aAAa,YAAY,SAAS,UAAU,SAAS,UAAU,KAAK,UAAU,QAAQ,CAAC,IAAI,QAAQ;AADnF,SAAA,OAAA;AAAA,EAEnD;AACD;AAEO,MAAM,mBAAmB,cAAc;AAAA,EAI7C,YAA4B,KAA6B,YAA0C,UAAuB;AACzH;AAAA,MACC,yBAAyB,aAAa,YAAY,SAAS,UAAU,SAAS,UAAU,KAAK,UAAU,QAAQ,CAAC;AAAA,OAC5G,GAAG;AAAA,cACI,UAAU;AAAA,MACrB;AAAA,IAAA;AAL0B,SAAA,MAAA;AAA6B,SAAA,aAAA;AAA0C,SAAA,WAAA;AAHnG,kBAAA,MAAgB,YAAA;AAChB,kBAAA,MAAgB,OAAA;AASf,SAAK,aAAa,SAAS;AAC3B,SAAK,QAAQ,SAAS;AAAA,EACvB;AACD;AAEO,MAAM,8BAA8B,WAAW;AAAC;AAEhD,MAAM,iCAAiC,WAAW;AAAC;AAEnD,MAAM,6BAA6B,WAAW;AAAC;AAE/C,MAAM,kCAAkC,WAAW;AAAC;AAEpD,MAAM,yBAAyB,WAAW;AAAC;AAE3C,MAAM,gCAAgC,WAAW;AAAC;AAElD,MAAM,0BAA0B,cAAc;AAAC;"}
|
|
1
|
+
{"version":3,"file":"errors.js","sources":["../../../../../packages/database/src/client/errors.ts"],"sourcesContent":["export class DatabaseError extends Error {\n\tpublic readonly code?: string\n\tpublic readonly originalMessage?: string\n\tpublic readonly previous: any\n\n\tconstructor(errMessage: string, previous?: Error | any) {\n\t\tsuper(errMessage)\n\t\tif (previous) {\n\t\t\tconst { message, stack, ...other } = previous\n\t\t\tconst otherDefined = Object.fromEntries(Object.entries(other).filter(it => it[1] !== undefined))\n\t\t\tthis.previous = { message, ...otherDefined }\n\t\t\tthis.code = previous.code\n\t\t\tthis.originalMessage = previous.message\n\t\t}\n\t}\n}\n\nexport type ClientErrorType =\n\t| 'recoverable connection error'\n\t| 'connection error'\n\t| 'runtime error'\n\t| 'disposal error'\n\nexport class ClientError extends DatabaseError {\n\tconstructor(previous: Error | any, public readonly type: ClientErrorType) {\n\t\tsuper(`Database client ${type}: ${'message' in previous && previous.message ? previous.message : JSON.stringify(previous)}`, previous)\n\t}\n}\n\nexport class QueryError extends DatabaseError {\n\tpublic readonly constraint?: string\n\tpublic readonly table?: string\n\n\tconstructor(public readonly sql: string, public readonly parameters: any, public override readonly previous: Error | any) {\n\t\tsuper(\n\t\t\t`Database query error: ${'message' in previous && previous.message ? previous.message : JSON.stringify(previous)}\nSQL: ${sql}\nparameters: ${parameters}`,\n\t\t\tprevious,\n\t\t)\n\t\tthis.constraint = previous.constraint\n\t\tthis.table = previous.table\n\t}\n}\n\nexport class NotNullViolationError extends QueryError {}\n\nexport class ForeignKeyViolationError extends QueryError {}\n\nexport class UniqueViolationError extends QueryError {}\n\nexport class SerializationFailureError extends QueryError {}\n\nexport class InvalidDataError extends QueryError {}\n\nexport class TransactionAbortedError extends QueryError {}\n\nexport class CannotCommitError extends DatabaseError {}\n\nexport class TerminatedConnectionError extends DatabaseError {\n\tconstructor() {\n\t\tsuper('Database connection was terminated')\n\t}\n}\n"],"names":[],"mappings":";;;AAAO,MAAM,sBAAsB,MAAM;AAAA,EAKxC,YAAY,YAAoB,UAAwB;AACvD,UAAM,UAAU;AALjB,kBAAA,MAAgB,MAAA;AAChB,kBAAA,MAAgB,iBAAA;AAChB,kBAAA,MAAgB,UAAA;AAIf,QAAI,UAAU;AACb,YAAM,EAAE,SAAS,OAAO,GAAG,UAAU;AACrC,YAAM,eAAe,OAAO,YAAY,OAAO,QAAQ,KAAK,EAAE,OAAO,CAAA,OAAM,GAAG,CAAC,MAAM,MAAS,CAAC;AAC/F,WAAK,WAAW,EAAE,SAAS,GAAG,aAAA;AAC9B,WAAK,OAAO,SAAS;AACrB,WAAK,kBAAkB,SAAS;AAAA,IACjC;AAAA,EACD;AACD;AAQO,MAAM,oBAAoB,cAAc;AAAA,EAC9C,YAAY,UAAuC,MAAuB;AACzE,UAAM,mBAAmB,IAAI,KAAK,aAAa,YAAY,SAAS,UAAU,SAAS,UAAU,KAAK,UAAU,QAAQ,CAAC,IAAI,QAAQ;AADnF,SAAA,OAAA;AAAA,EAEnD;AACD;AAEO,MAAM,mBAAmB,cAAc;AAAA,EAI7C,YAA4B,KAA6B,YAA0C,UAAuB;AACzH;AAAA,MACC,yBAAyB,aAAa,YAAY,SAAS,UAAU,SAAS,UAAU,KAAK,UAAU,QAAQ,CAAC;AAAA,OAC5G,GAAG;AAAA,cACI,UAAU;AAAA,MACrB;AAAA,IAAA;AAL0B,SAAA,MAAA;AAA6B,SAAA,aAAA;AAA0C,SAAA,WAAA;AAHnG,kBAAA,MAAgB,YAAA;AAChB,kBAAA,MAAgB,OAAA;AASf,SAAK,aAAa,SAAS;AAC3B,SAAK,QAAQ,SAAS;AAAA,EACvB;AACD;AAEO,MAAM,8BAA8B,WAAW;AAAC;AAEhD,MAAM,iCAAiC,WAAW;AAAC;AAEnD,MAAM,6BAA6B,WAAW;AAAC;AAE/C,MAAM,kCAAkC,WAAW;AAAC;AAEpD,MAAM,yBAAyB,WAAW;AAAC;AAE3C,MAAM,gCAAgC,WAAW;AAAC;AAElD,MAAM,0BAA0B,cAAc;AAAC;AAE/C,MAAM,kCAAkC,cAAc;AAAA,EAC5D,cAAc;AACb,UAAM,oCAAoC;AAAA,EAC3C;AACD;"}
|
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const pg = require("pg");
|
|
4
4
|
const createPgClientFactory = ({ queryTimeoutMs, statementTimeoutMs, lockTimeoutMs, connectionTimeoutMs, ...config }) => () => {
|
|
5
|
+
const { keepAlive, keepAliveInitialDelayMs, ...connectionConfig } = config;
|
|
5
6
|
const clientConfig = {
|
|
6
7
|
query_timeout: queryTimeoutMs,
|
|
7
8
|
statement_timeout: statementTimeoutMs,
|
|
8
9
|
lock_timeout: lockTimeoutMs,
|
|
9
10
|
connectionTimeoutMillis: connectionTimeoutMs,
|
|
10
|
-
|
|
11
|
+
keepAlive: keepAlive ?? false,
|
|
12
|
+
keepAliveInitialDelayMillis: keepAliveInitialDelayMs,
|
|
13
|
+
...connectionConfig
|
|
11
14
|
};
|
|
12
15
|
return new pg.Client(clientConfig);
|
|
13
16
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgClientFactory.cjs","sources":["../../../../../packages/database/src/utils/pgClientFactory.ts"],"sourcesContent":["import pg from 'pg'\nimport { DatabaseConfig } from '../types.js'\nimport { PgClient } from '../client/PgClient.js'\n\nexport type PgClientFactory = () => PgClient\nexport const createPgClientFactory =\n\t({ queryTimeoutMs, statementTimeoutMs, lockTimeoutMs, connectionTimeoutMs, ...config }: DatabaseConfig) => () => {\n\t\t// `lock_timeout` is supported by pg at runtime but missing from the installed @types/pg version,\n\t\t// so it is typed explicitly here.\n\t\tconst clientConfig: pg.ClientConfig & { lock_timeout?: number } = {\n\t\t\tquery_timeout: queryTimeoutMs,\n\t\t\tstatement_timeout: statementTimeoutMs,\n\t\t\tlock_timeout: lockTimeoutMs,\n\t\t\tconnectionTimeoutMillis: connectionTimeoutMs,\n\t\t\t...
|
|
1
|
+
{"version":3,"file":"pgClientFactory.cjs","sources":["../../../../../packages/database/src/utils/pgClientFactory.ts"],"sourcesContent":["import pg from 'pg'\nimport { DatabaseConfig } from '../types.js'\nimport { PgClient } from '../client/PgClient.js'\n\nexport type PgClientFactory = () => PgClient\nexport const createPgClientFactory =\n\t({ queryTimeoutMs, statementTimeoutMs, lockTimeoutMs, connectionTimeoutMs, ...config }: DatabaseConfig) => () => {\n\t\t// `lock_timeout` is supported by pg at runtime but missing from the installed @types/pg version,\n\t\t// so it is typed explicitly here.\n\t\tconst { keepAlive, keepAliveInitialDelayMs, ...connectionConfig } = config\n\t\tconst clientConfig: pg.ClientConfig & { lock_timeout?: number } = {\n\t\t\tquery_timeout: queryTimeoutMs,\n\t\t\tstatement_timeout: statementTimeoutMs,\n\t\t\tlock_timeout: lockTimeoutMs,\n\t\t\tconnectionTimeoutMillis: connectionTimeoutMs,\n\t\t\tkeepAlive: keepAlive ?? false,\n\t\t\tkeepAliveInitialDelayMillis: keepAliveInitialDelayMs,\n\t\t\t...connectionConfig,\n\t\t}\n\t\treturn new pg.Client(clientConfig)\n\t}\n"],"names":[],"mappings":";;;AAKO,MAAM,wBACZ,CAAC,EAAE,gBAAgB,oBAAoB,eAAe,qBAAqB,GAAG,OAAA,MAA6B,MAAM;AAGhH,QAAM,EAAE,WAAW,yBAAyB,GAAG,qBAAqB;AACpE,QAAM,eAA4D;AAAA,IACjE,eAAe;AAAA,IACf,mBAAmB;AAAA,IACnB,cAAc;AAAA,IACd,yBAAyB;AAAA,IACzB,WAAW,aAAa;AAAA,IACxB,6BAA6B;AAAA,IAC7B,GAAG;AAAA,EAAA;AAEJ,SAAO,IAAI,GAAG,OAAO,YAAY;AAClC;;"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import pg from "pg";
|
|
2
2
|
const createPgClientFactory = ({ queryTimeoutMs, statementTimeoutMs, lockTimeoutMs, connectionTimeoutMs, ...config }) => () => {
|
|
3
|
+
const { keepAlive, keepAliveInitialDelayMs, ...connectionConfig } = config;
|
|
3
4
|
const clientConfig = {
|
|
4
5
|
query_timeout: queryTimeoutMs,
|
|
5
6
|
statement_timeout: statementTimeoutMs,
|
|
6
7
|
lock_timeout: lockTimeoutMs,
|
|
7
8
|
connectionTimeoutMillis: connectionTimeoutMs,
|
|
8
|
-
|
|
9
|
+
keepAlive: keepAlive ?? false,
|
|
10
|
+
keepAliveInitialDelayMillis: keepAliveInitialDelayMs,
|
|
11
|
+
...connectionConfig
|
|
9
12
|
};
|
|
10
13
|
return new pg.Client(clientConfig);
|
|
11
14
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pgClientFactory.js","sources":["../../../../../packages/database/src/utils/pgClientFactory.ts"],"sourcesContent":["import pg from 'pg'\nimport { DatabaseConfig } from '../types.js'\nimport { PgClient } from '../client/PgClient.js'\n\nexport type PgClientFactory = () => PgClient\nexport const createPgClientFactory =\n\t({ queryTimeoutMs, statementTimeoutMs, lockTimeoutMs, connectionTimeoutMs, ...config }: DatabaseConfig) => () => {\n\t\t// `lock_timeout` is supported by pg at runtime but missing from the installed @types/pg version,\n\t\t// so it is typed explicitly here.\n\t\tconst clientConfig: pg.ClientConfig & { lock_timeout?: number } = {\n\t\t\tquery_timeout: queryTimeoutMs,\n\t\t\tstatement_timeout: statementTimeoutMs,\n\t\t\tlock_timeout: lockTimeoutMs,\n\t\t\tconnectionTimeoutMillis: connectionTimeoutMs,\n\t\t\t...
|
|
1
|
+
{"version":3,"file":"pgClientFactory.js","sources":["../../../../../packages/database/src/utils/pgClientFactory.ts"],"sourcesContent":["import pg from 'pg'\nimport { DatabaseConfig } from '../types.js'\nimport { PgClient } from '../client/PgClient.js'\n\nexport type PgClientFactory = () => PgClient\nexport const createPgClientFactory =\n\t({ queryTimeoutMs, statementTimeoutMs, lockTimeoutMs, connectionTimeoutMs, ...config }: DatabaseConfig) => () => {\n\t\t// `lock_timeout` is supported by pg at runtime but missing from the installed @types/pg version,\n\t\t// so it is typed explicitly here.\n\t\tconst { keepAlive, keepAliveInitialDelayMs, ...connectionConfig } = config\n\t\tconst clientConfig: pg.ClientConfig & { lock_timeout?: number } = {\n\t\t\tquery_timeout: queryTimeoutMs,\n\t\t\tstatement_timeout: statementTimeoutMs,\n\t\t\tlock_timeout: lockTimeoutMs,\n\t\t\tconnectionTimeoutMillis: connectionTimeoutMs,\n\t\t\tkeepAlive: keepAlive ?? false,\n\t\t\tkeepAliveInitialDelayMillis: keepAliveInitialDelayMs,\n\t\t\t...connectionConfig,\n\t\t}\n\t\treturn new pg.Client(clientConfig)\n\t}\n"],"names":[],"mappings":";AAKO,MAAM,wBACZ,CAAC,EAAE,gBAAgB,oBAAoB,eAAe,qBAAqB,GAAG,OAAA,MAA6B,MAAM;AAGhH,QAAM,EAAE,WAAW,yBAAyB,GAAG,qBAAqB;AACpE,QAAM,eAA4D;AAAA,IACjE,eAAe;AAAA,IACf,mBAAmB;AAAA,IACnB,cAAc;AAAA,IACd,yBAAyB;AAAA,IACzB,WAAW,aAAa;AAAA,IACxB,6BAA6B;AAAA,IAC7B,GAAG;AAAA,EAAA;AAEJ,SAAO,IAAI,GAAG,OAAO,YAAY;AAClC;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestMemoryBudget.test.d.ts","sourceRoot":"","sources":["../../../../tests/cases/integration/requestMemoryBudget.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acquiredConnection.test.d.ts","sourceRoot":"","sources":["../../../../tests/cases/unit/acquiredConnection.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { Connection } from '../../../src/index.js';
|
|
2
|
-
|
|
1
|
+
import { Connection, PoolConfig } from '../../../src/index.js';
|
|
2
|
+
type MockQuery = {
|
|
3
3
|
sql: string;
|
|
4
4
|
timeout?: number;
|
|
5
5
|
result?: any;
|
|
6
|
-
}
|
|
6
|
+
};
|
|
7
|
+
export declare const createConnectionMockAlt: (...queries: MockQuery[][]) => [Connection, () => void];
|
|
8
|
+
export declare const createConnectionMockAltWithPool: (poolConfig: Partial<Omit<PoolConfig, 'logError'>>, ...queries: MockQuery[][]) => [Connection, () => void];
|
|
9
|
+
export {};
|
|
7
10
|
//# sourceMappingURL=createConnectionMockAlt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createConnectionMockAlt.d.ts","sourceRoot":"","sources":["../../../../tests/cases/unit/createConnectionMockAlt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAQ,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"createConnectionMockAlt.d.ts","sourceRoot":"","sources":["../../../../tests/cases/unit/createConnectionMockAlt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAQ,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAKpE,KAAK,SAAS,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,GAAG,CAAA;CAAE,CAAA;AAEhE,eAAO,MAAM,uBAAuB,eAAgB,SAAS,EAAE,EAAE,KAAG,CAAC,UAAU,EAAE,MAAM,IAAI,CAE1F,CAAA;AAED,eAAO,MAAM,+BAA+B,eAC/B,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,cACrC,SAAS,EAAE,EAAE,KACvB,CAAC,UAAU,EAAE,MAAM,IAAI,CA6CzB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestMemoryBudget.test.d.ts","sourceRoot":"","sources":["../../../../tests/cases/unit/requestMemoryBudget.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../../../tests/src/tags.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../../../tests/src/tags.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,GAAG,YAAa,oBAAoB,aAAa,MAAM,EAAE,WAG7D,CAAA"}
|