@zudojs/database 0.1.0 → 1.1.0
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/LICENSE +21 -0
- package/README.md +225 -17
- package/dist/cache/cache.memory.d.ts +167 -0
- package/dist/cache/cache.memory.js +186 -40
- package/dist/cache/index.d.ts +2 -2
- package/dist/cache/index.js +2 -2
- package/dist/database/database.core.d.ts +91 -0
- package/dist/database/database.core.js +21 -4
- package/dist/databaseClient/databaseClient.core.d.ts +171 -14
- package/dist/databaseClient/databaseClient.core.js +350 -70
- package/dist/databaseClient/databaseClient.errors.d.ts +112 -0
- package/dist/databaseClient/databaseClient.errors.js +425 -0
- package/dist/databaseClient/index.d.ts +2 -1
- package/dist/databaseClient/index.js +2 -1
- package/dist/databaseConnection/databaseConnection.manager.d.ts +163 -0
- package/dist/databaseConnection/databaseConnection.manager.js +138 -76
- package/dist/databaseConnection/index.d.ts +1 -1
- package/dist/databaseType/databaseType.type.d.ts +224 -0
- package/dist/databaseType/databaseType.type.js +0 -35
- package/dist/health/health.check.d.ts +74 -0
- package/dist/health/health.check.js +78 -47
- package/dist/health/index.d.ts +1 -1
- package/dist/health/index.js +1 -1
- package/dist/index.d.ts +14 -14
- package/dist/index.js +11 -11
- package/dist/locks/index.d.ts +2 -2
- package/dist/locks/index.js +2 -2
- package/dist/locks/locks.core.d.ts +132 -0
- package/dist/locks/locks.core.js +150 -85
- package/dist/migration/index.d.ts +3 -1
- package/dist/migration/index.js +2 -0
- package/dist/migration/migration.dialect.d.ts +65 -0
- package/dist/migration/migration.dialect.js +63 -0
- package/dist/migration/migration.helpers.d.ts +65 -0
- package/dist/migration/migration.helpers.js +60 -18
- package/dist/migration/migration.runner.d.ts +75 -0
- package/dist/migration/migration.runner.js +195 -107
- package/dist/migration/migration.types.d.ts +85 -0
- package/dist/pagination/index.d.ts +2 -1
- package/dist/pagination/index.js +2 -1
- package/dist/pagination/pagination.core.d.ts +163 -0
- package/dist/pagination/pagination.core.js +78 -9
- package/dist/pagination/pagination.keyset.d.ts +55 -0
- package/dist/pagination/pagination.keyset.js +108 -0
- package/dist/queryBuilder/index.d.ts +4 -3
- package/dist/queryBuilder/index.js +3 -2
- package/dist/queryBuilder/queryBuilder.core.d.ts +178 -0
- package/dist/queryBuilder/queryBuilder.core.js +92 -14
- package/dist/queryBuilder/queryBuilder.factory.d.ts +6 -0
- package/dist/queryBuilder/queryBuilder.factory.js +0 -25
- package/dist/queryBuilder/queryBuilder.filter.d.ts +170 -0
- package/dist/queryBuilder/queryBuilder.filter.js +191 -30
- package/dist/queryBuilder/queryBuilder.prisma.d.ts +60 -0
- package/dist/queryBuilder/queryBuilder.prisma.js +233 -0
- package/dist/queryBuilder/queryBuilder.type.d.ts +48 -0
- package/dist/relations/index.d.ts +1 -1
- package/dist/relations/index.js +1 -1
- package/dist/relations/relations.definition.d.ts +184 -0
- package/dist/relations/relations.definition.js +186 -19
- package/dist/repository/index.d.ts +2 -1
- package/dist/repository/index.js +1 -0
- package/dist/repository/repository.base.d.ts +283 -0
- package/dist/repository/repository.base.js +370 -89
- package/dist/repository/repository.errors.d.ts +60 -0
- package/dist/repository/repository.errors.js +235 -0
- package/dist/seed/index.d.ts +2 -2
- package/dist/seed/index.js +1 -1
- package/dist/seed/seed.runner.d.ts +160 -0
- package/dist/seed/seed.runner.js +194 -225
- package/dist/transaction/index.d.ts +1 -1
- package/dist/transaction/index.js +1 -1
- package/dist/transaction/transaction.core.d.ts +117 -0
- package/dist/transaction/transaction.core.js +83 -56
- package/dist/unitOfWork/unitOfWork.core.d.ts +44 -0
- package/dist/unitOfWork/unitOfWork.core.js +9 -20
- package/package.json +44 -24
- package/dist/cache/cache.memory.d.ts.map +0 -1
- package/dist/cache/cache.memory.js.map +0 -1
- package/dist/cache/index.d.ts.map +0 -1
- package/dist/cache/index.js.map +0 -1
- package/dist/database/database.core.d.ts.map +0 -1
- package/dist/database/database.core.js.map +0 -1
- package/dist/database/index.d.ts.map +0 -1
- package/dist/database/index.js.map +0 -1
- package/dist/databaseClient/databaseClient.core.d.ts.map +0 -1
- package/dist/databaseClient/databaseClient.core.js.map +0 -1
- package/dist/databaseClient/databaseClient.logger.d.ts.map +0 -1
- package/dist/databaseClient/databaseClient.logger.js.map +0 -1
- package/dist/databaseClient/index.d.ts.map +0 -1
- package/dist/databaseClient/index.js.map +0 -1
- package/dist/databaseConnection/databaseConnection.manager.d.ts.map +0 -1
- package/dist/databaseConnection/databaseConnection.manager.js.map +0 -1
- package/dist/databaseConnection/index.d.ts.map +0 -1
- package/dist/databaseConnection/index.js.map +0 -1
- package/dist/databaseType/databaseType.type.d.ts.map +0 -1
- package/dist/databaseType/databaseType.type.js.map +0 -1
- package/dist/databaseType/index.d.ts.map +0 -1
- package/dist/databaseType/index.js.map +0 -1
- package/dist/health/health.check.d.ts.map +0 -1
- package/dist/health/health.check.js.map +0 -1
- package/dist/health/index.d.ts.map +0 -1
- package/dist/health/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/locks/index.d.ts.map +0 -1
- package/dist/locks/index.js.map +0 -1
- package/dist/locks/locks.core.d.ts.map +0 -1
- package/dist/locks/locks.core.js.map +0 -1
- package/dist/migration/index.d.ts.map +0 -1
- package/dist/migration/index.js.map +0 -1
- package/dist/migration/migration.helpers.d.ts.map +0 -1
- package/dist/migration/migration.helpers.js.map +0 -1
- package/dist/migration/migration.runner.d.ts.map +0 -1
- package/dist/migration/migration.runner.js.map +0 -1
- package/dist/migration/migration.types.d.ts.map +0 -1
- package/dist/migration/migration.types.js.map +0 -1
- package/dist/pagination/index.d.ts.map +0 -1
- package/dist/pagination/index.js.map +0 -1
- package/dist/pagination/pagination.core.d.ts.map +0 -1
- package/dist/pagination/pagination.core.js.map +0 -1
- package/dist/queryBuilder/index.d.ts.map +0 -1
- package/dist/queryBuilder/index.js.map +0 -1
- package/dist/queryBuilder/queryBuilder.core.d.ts.map +0 -1
- package/dist/queryBuilder/queryBuilder.core.js.map +0 -1
- package/dist/queryBuilder/queryBuilder.factory.d.ts.map +0 -1
- package/dist/queryBuilder/queryBuilder.factory.js.map +0 -1
- package/dist/queryBuilder/queryBuilder.filter.d.ts.map +0 -1
- package/dist/queryBuilder/queryBuilder.filter.js.map +0 -1
- package/dist/queryBuilder/queryBuilder.type.d.ts.map +0 -1
- package/dist/queryBuilder/queryBuilder.type.js.map +0 -1
- package/dist/relations/index.d.ts.map +0 -1
- package/dist/relations/index.js.map +0 -1
- package/dist/relations/relations.definition.d.ts.map +0 -1
- package/dist/relations/relations.definition.js.map +0 -1
- package/dist/repository/index.d.ts.map +0 -1
- package/dist/repository/index.js.map +0 -1
- package/dist/repository/repository.base.d.ts.map +0 -1
- package/dist/repository/repository.base.js.map +0 -1
- package/dist/seed/index.d.ts.map +0 -1
- package/dist/seed/index.js.map +0 -1
- package/dist/seed/seed.runner.d.ts.map +0 -1
- package/dist/seed/seed.runner.js.map +0 -1
- package/dist/transaction/index.d.ts.map +0 -1
- package/dist/transaction/index.js.map +0 -1
- package/dist/transaction/transaction.core.d.ts.map +0 -1
- package/dist/transaction/transaction.core.js.map +0 -1
- package/dist/unitOfWork/index.d.ts.map +0 -1
- package/dist/unitOfWork/index.js.map +0 -1
- package/dist/unitOfWork/unitOfWork.core.d.ts.map +0 -1
- package/dist/unitOfWork/unitOfWork.core.js.map +0 -1
|
@@ -1,9 +1,35 @@
|
|
|
1
|
-
import { DatabaseError } from "@zudojs/errors";
|
|
2
|
-
import {
|
|
1
|
+
import { DatabaseError, DatabaseOperation, ErrorCode } from "@zudojs/errors";
|
|
2
|
+
import { isDatabaseErrorLike, normalizeDatabaseError, } from "../databaseClient/databaseClient.errors.js";
|
|
3
3
|
/**
|
|
4
4
|
* Default database health-check timeout.
|
|
5
5
|
*/
|
|
6
6
|
export const DEFAULT_HEALTH_TIMEOUT_MS = 5_000;
|
|
7
|
+
/**
|
|
8
|
+
* Error raised by {@link assertDatabaseHealth}. The underlying failure is
|
|
9
|
+
* preserved as `cause`.
|
|
10
|
+
*/
|
|
11
|
+
export class DatabaseUnhealthyError extends DatabaseError {
|
|
12
|
+
health;
|
|
13
|
+
constructor(health, cause) {
|
|
14
|
+
super("Database health check failed.", {
|
|
15
|
+
code: ErrorCode.DATABASE_CONNECTION,
|
|
16
|
+
statusCode: 503,
|
|
17
|
+
operation: DatabaseOperation.CONNECT,
|
|
18
|
+
metadata: {
|
|
19
|
+
status: health.status,
|
|
20
|
+
latencyMs: health.latencyMs,
|
|
21
|
+
checkedAt: health.checkedAt.toISOString(),
|
|
22
|
+
...(health.error?.code ? { errorCode: health.error.code } : {}),
|
|
23
|
+
...(health.error?.databaseCode
|
|
24
|
+
? { databaseCode: health.error.databaseCode }
|
|
25
|
+
: {}),
|
|
26
|
+
},
|
|
27
|
+
cause,
|
|
28
|
+
});
|
|
29
|
+
this.name = "DatabaseUnhealthyError";
|
|
30
|
+
this.health = health;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
7
33
|
/**
|
|
8
34
|
* Performs a lightweight database health check.
|
|
9
35
|
*/
|
|
@@ -16,7 +42,7 @@ export async function checkDatabaseHealth(client, options = {}) {
|
|
|
16
42
|
const startedAt = performance.now();
|
|
17
43
|
try {
|
|
18
44
|
await withTimeout(executeHealthCheck(client), timeoutMs);
|
|
19
|
-
const latencyMs =
|
|
45
|
+
const latencyMs = elapsed(startedAt);
|
|
20
46
|
return {
|
|
21
47
|
status: latencyMs > timeoutMs * 0.75 ? "degraded" : "healthy",
|
|
22
48
|
healthy: true,
|
|
@@ -26,9 +52,9 @@ export async function checkDatabaseHealth(client, options = {}) {
|
|
|
26
52
|
};
|
|
27
53
|
}
|
|
28
54
|
catch (error) {
|
|
29
|
-
const latencyMs =
|
|
55
|
+
const latencyMs = elapsed(startedAt);
|
|
30
56
|
const normalizedError = normalizeHealthError(error);
|
|
31
|
-
|
|
57
|
+
const health = {
|
|
32
58
|
status: "unhealthy",
|
|
33
59
|
healthy: false,
|
|
34
60
|
latencyMs,
|
|
@@ -36,8 +62,22 @@ export async function checkDatabaseHealth(client, options = {}) {
|
|
|
36
62
|
message: normalizedError.message,
|
|
37
63
|
error: normalizedError,
|
|
38
64
|
};
|
|
65
|
+
Object.defineProperty(health, HEALTH_CAUSE, { value: error, enumerable: false });
|
|
66
|
+
return health;
|
|
39
67
|
}
|
|
40
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Symbol under which the original failure is kept on an unhealthy result.
|
|
71
|
+
* It is a non-enumerable symbol key, so serialised health output never
|
|
72
|
+
* includes it.
|
|
73
|
+
*/
|
|
74
|
+
const HEALTH_CAUSE = Symbol("zudojs.database.healthCause");
|
|
75
|
+
/**
|
|
76
|
+
* Returns the original error that made a health check fail, if any.
|
|
77
|
+
*/
|
|
78
|
+
export function getHealthCheckCause(health) {
|
|
79
|
+
return health[HEALTH_CAUSE];
|
|
80
|
+
}
|
|
41
81
|
/**
|
|
42
82
|
* Performs a database readiness check.
|
|
43
83
|
*
|
|
@@ -53,38 +93,30 @@ export async function checkDatabaseReadiness(client, options = {}) {
|
|
|
53
93
|
const startedAt = performance.now();
|
|
54
94
|
try {
|
|
55
95
|
await withTimeout(executeHealthCheck(client), timeoutMs);
|
|
56
|
-
const latencyMs = Math.max(0, Math.round(performance.now() - startedAt));
|
|
57
96
|
return {
|
|
58
97
|
ready: true,
|
|
59
98
|
checkedAt,
|
|
60
|
-
latencyMs,
|
|
99
|
+
latencyMs: elapsed(startedAt),
|
|
61
100
|
message: "Database is ready.",
|
|
62
101
|
};
|
|
63
102
|
}
|
|
64
103
|
catch (error) {
|
|
65
|
-
const latencyMs = Math.max(0, Math.round(performance.now() - startedAt));
|
|
66
104
|
return {
|
|
67
105
|
ready: false,
|
|
68
106
|
checkedAt,
|
|
69
|
-
latencyMs,
|
|
107
|
+
latencyMs: elapsed(startedAt),
|
|
70
108
|
message: normalizeHealthError(error).message,
|
|
71
109
|
};
|
|
72
110
|
}
|
|
73
111
|
}
|
|
74
112
|
/**
|
|
75
|
-
* Throws
|
|
113
|
+
* Throws a {@link DatabaseUnhealthyError} (with the real failure as
|
|
114
|
+
* `cause`) when the database is not healthy.
|
|
76
115
|
*/
|
|
77
116
|
export async function assertDatabaseHealth(client, options = {}) {
|
|
78
117
|
const health = await checkDatabaseHealth(client, options);
|
|
79
118
|
if (!health.healthy) {
|
|
80
|
-
throw new
|
|
81
|
-
metadata: {
|
|
82
|
-
status: health.status,
|
|
83
|
-
latencyMs: health.latencyMs,
|
|
84
|
-
checkedAt: health.checkedAt.toISOString(),
|
|
85
|
-
},
|
|
86
|
-
cause: health.error ? new Error(health.error.message) : undefined,
|
|
87
|
-
});
|
|
119
|
+
throw new DatabaseUnhealthyError(health, getHealthCheckCause(health));
|
|
88
120
|
}
|
|
89
121
|
return health;
|
|
90
122
|
}
|
|
@@ -96,21 +128,12 @@ export async function isDatabaseHealthy(client, options = {}) {
|
|
|
96
128
|
return health.healthy;
|
|
97
129
|
}
|
|
98
130
|
/**
|
|
99
|
-
* Executes the lightweight health query.
|
|
131
|
+
* Executes the lightweight health query. Errors are already normalised by
|
|
132
|
+
* the client, so they are passed through unchanged.
|
|
100
133
|
*/
|
|
101
134
|
async function executeHealthCheck(client) {
|
|
102
|
-
|
|
103
|
-
await client.queryRaw(Prisma.sql `SELECT 1 AS result`);
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
throw new DatabaseError("Database health query failed.", {
|
|
107
|
-
cause: error,
|
|
108
|
-
});
|
|
109
|
-
}
|
|
135
|
+
await client.queryRawUnsafe("SELECT 1 AS result");
|
|
110
136
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Runs a promise with a timeout.
|
|
113
|
-
*/
|
|
114
137
|
async function withTimeout(promise, timeoutMs) {
|
|
115
138
|
let timeout;
|
|
116
139
|
try {
|
|
@@ -118,42 +141,50 @@ async function withTimeout(promise, timeoutMs) {
|
|
|
118
141
|
promise,
|
|
119
142
|
new Promise((_resolve, reject) => {
|
|
120
143
|
timeout = setTimeout(() => {
|
|
121
|
-
reject(new DatabaseError(`Database health check timed out after ${timeoutMs}ms
|
|
144
|
+
reject(new DatabaseError(`Database health check timed out after ${timeoutMs}ms.`, {
|
|
145
|
+
code: ErrorCode.DATABASE_TIMEOUT,
|
|
146
|
+
statusCode: 503,
|
|
147
|
+
operation: DatabaseOperation.QUERY,
|
|
148
|
+
metadata: { timeoutMs },
|
|
149
|
+
}));
|
|
122
150
|
}, timeoutMs);
|
|
123
151
|
}),
|
|
124
152
|
]);
|
|
125
153
|
}
|
|
126
154
|
finally {
|
|
127
|
-
if (timeout)
|
|
155
|
+
if (timeout)
|
|
128
156
|
clearTimeout(timeout);
|
|
129
|
-
}
|
|
130
157
|
}
|
|
131
158
|
}
|
|
132
|
-
/**
|
|
133
|
-
* Normalizes timeout values.
|
|
134
|
-
*/
|
|
135
159
|
function normalizeTimeout(timeoutMs) {
|
|
136
|
-
if (timeoutMs === undefined)
|
|
160
|
+
if (timeoutMs === undefined)
|
|
137
161
|
return DEFAULT_HEALTH_TIMEOUT_MS;
|
|
138
|
-
}
|
|
139
162
|
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
140
163
|
throw new TypeError("Database health timeout must be a positive finite number.");
|
|
141
164
|
}
|
|
142
165
|
return Math.floor(timeoutMs);
|
|
143
166
|
}
|
|
167
|
+
function elapsed(startedAt) {
|
|
168
|
+
return Math.max(0, Math.round(performance.now() - startedAt));
|
|
169
|
+
}
|
|
144
170
|
/**
|
|
145
|
-
* Converts an unknown error into a safe health error.
|
|
171
|
+
* Converts an unknown error into a safe health error. Prisma errors are
|
|
172
|
+
* mapped so connection failures never leak host names.
|
|
146
173
|
*/
|
|
147
174
|
function normalizeHealthError(error) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
175
|
+
const normalized = isDatabaseErrorLike(error)
|
|
176
|
+
? error
|
|
177
|
+
: normalizeDatabaseError(error, {
|
|
178
|
+
operation: DatabaseOperation.QUERY,
|
|
179
|
+
fallbackMessage: "Database health check failed.",
|
|
180
|
+
});
|
|
154
181
|
return {
|
|
155
|
-
name:
|
|
156
|
-
message:
|
|
182
|
+
name: normalized.name,
|
|
183
|
+
message: normalized.message,
|
|
184
|
+
code: String(normalized.code),
|
|
185
|
+
...(normalized.databaseCode !== undefined
|
|
186
|
+
? { databaseCode: String(normalized.databaseCode) }
|
|
187
|
+
: {}),
|
|
157
188
|
};
|
|
158
189
|
}
|
|
159
190
|
//# sourceMappingURL=health.check.js.map
|
package/dist/health/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Database health and readiness monitoring.
|
|
5
5
|
*/
|
|
6
|
-
export { checkDatabaseHealth, checkDatabaseReadiness, assertDatabaseHealth, isDatabaseHealthy, DEFAULT_HEALTH_TIMEOUT_MS, type DatabaseHealthStatus, type DatabaseHealth, type DatabaseHealthOptions, type DatabaseReadiness, } from "./health.check.js";
|
|
6
|
+
export { checkDatabaseHealth, checkDatabaseReadiness, assertDatabaseHealth, isDatabaseHealthy, getHealthCheckCause, DatabaseUnhealthyError, DEFAULT_HEALTH_TIMEOUT_MS, type DatabaseHealthStatus, type DatabaseHealth, type DatabaseHealthOptions, type DatabaseReadiness, } from "./health.check.js";
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/health/index.js
CHANGED
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Database health and readiness monitoring.
|
|
5
5
|
*/
|
|
6
|
-
export { checkDatabaseHealth, checkDatabaseReadiness, assertDatabaseHealth, isDatabaseHealthy, DEFAULT_HEALTH_TIMEOUT_MS, } from "./health.check.js";
|
|
6
|
+
export { checkDatabaseHealth, checkDatabaseReadiness, assertDatabaseHealth, isDatabaseHealthy, getHealthCheckCause, DatabaseUnhealthyError, DEFAULT_HEALTH_TIMEOUT_MS, } from "./health.check.js";
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -16,21 +16,21 @@
|
|
|
16
16
|
* • Seed management
|
|
17
17
|
* • Health and readiness checks
|
|
18
18
|
*/
|
|
19
|
-
export type { DatabaseOperationOptions, DatabaseStatus, TransactionIsolationLevel, DatabaseOperation, DatabaseConnectionOptions, DatabaseHealth as DatabaseHealthInfo,
|
|
19
|
+
export type { DatabaseOperationOptions, DatabaseStatus, TransactionIsolationLevel, DatabaseOperation, DatabaseConnectionOptions, DatabaseClientHealth, DatabaseHealth as DatabaseHealthInfo, TransactionOptions, TransactionCallback, Repository, SoftDeletableRepository, PaginationInput, PaginationMeta, PaginatedResult, SortDirection, SortInput, QueryOptions, DatabaseEntity, SoftDeletableEntity, AuditableEntity, DatabaseErrorInfo, DatabaseLogger, } from "./databaseType/index.js";
|
|
20
20
|
export { noopDatabaseLogger } from "./databaseType/index.js";
|
|
21
|
-
export { DatabaseClient, createDatabaseClient, type DatabaseClientOptions, type DatabaseTransactionContext, } from "./databaseClient/index.js";
|
|
22
|
-
export { DatabaseConnectionManager, createConnectionManager, type DatabaseConnectionEvent, type DatabaseConnectionListener, type DatabaseConnectionEventDetails, type DatabaseConnectionManagerOptions, } from "./databaseConnection/index.js";
|
|
21
|
+
export { DatabaseClient, DatabaseAbortError, createDatabaseClient, buildPrismaTransactionOptions, createAbortError, raceAbort, throwIfAborted, SUPPORTED_ISOLATION_LEVELS, normalizeDatabaseError, withDatabaseErrorMetadata, isPrismaError, isRetryableTransactionError, isConflictError, isNotFoundError, getDatabaseErrorCode, getDatabaseErrorKind, isDatabaseErrorLike, toDatabaseErrorInfo, RETRYABLE_DATABASE_CODES, type DatabaseClientOptions, type DatabaseTransactionContext, type PrismaClientLike, type PrismaDriverAdapterLike, type PrismaQueryEvent, type PrismaTransactionOptions, type RawQueryOptions, type DatabaseErrorKind, type NormalizeDatabaseErrorOptions, type PrismaErrorLike, } from "./databaseClient/index.js";
|
|
22
|
+
export { DatabaseConnectionManager, createConnectionManager, type DatabaseConnectionEvent, type DatabaseConnectionListener, type DatabaseConnectionEventDetails, type DatabaseConnectionManagerOptions, type DatabaseReconnectOptions, } from "./databaseConnection/index.js";
|
|
23
23
|
export { Database, createDatabase, getDatabase, connectDatabase, disconnectDatabase, resetDatabase, } from "./database/index.js";
|
|
24
|
-
export { BaseRepository, type RepositoryDelegate, type BaseRepositoryOptions, } from "./repository/index.js";
|
|
25
|
-
export { TransactionManager, createTransactionManager, withTransaction, withTransactionRetry, createTransactionContext, createTransactionId, isTransactionActive, isTransactionCommitted, isTransactionFailed, type TransactionStatus, type TransactionContext, type ManagedTransactionOptions, } from "./transaction/index.js";
|
|
24
|
+
export { BaseRepository, mapRepositoryError, isPrismaErrorLike, toDatabaseOperation, type RepositoryDelegate, type BaseRepositoryOptions, type SoftDeleteOptions, type CursorQueryOptions, type TransactionClientLike, type RepositoryOperation, type RepositoryErrorContext, } from "./repository/index.js";
|
|
25
|
+
export { TransactionManager, createTransactionManager, withTransaction, withTransactionRetry, createTransactionContext, createTransactionId, getTransactionContextFromError, isTransactionActive, isTransactionCommitted, isTransactionFailed, type TransactionStatus, type TransactionContext, type TransactionOutcome, type TransactionRetryOptions, type ManagedTransactionOptions, } from "./transaction/index.js";
|
|
26
26
|
export { DatabaseUnitOfWork, createUnitOfWork, executeUnitOfWork, type UnitOfWork, type UnitOfWorkOptions, } from "./unitOfWork/index.js";
|
|
27
|
-
export { QueryBuilder, createQueryBuilder, type QueryCondition, type QueryFilter, type QueryOperator, type QueryBuilderState, } from "./queryBuilder/index.js";
|
|
28
|
-
export { equals, notEquals, inList, notInList, lessThan, lessThanOrEqual, greaterThan, greaterThanOrEqual, contains, startsWith, endsWith, isNull, isNotNull, and, or, not, condition, allOf, anyOf, fromObject, dateRange, oneOf, noneOf, optionalEquals, optionalContains, hasConditions, flattenAnd, cloneFilter, } from "./queryBuilder/index.js";
|
|
29
|
-
export { normalizePagination, normalizePage, normalizeLimit, calculateOffset, calculateTotalPages, createPaginationMeta, createPaginatedResult, getNextPage, getPreviousPage, isValidPage, getItemRange, paginateCollection, encodeCursor, decodeCursor, normalizeCursorPagination, createCursorPaginationMeta, createCursorPaginatedResult, DEFAULT_PAGE, DEFAULT_LIMIT, MAX_LIMIT, type NormalizedPagination, type CursorPaginationInput, type CursorPaginationMeta, type CursorPaginatedResult, } from "./pagination/index.js";
|
|
30
|
-
export { oneToOne, oneToMany, manyToOne, manyToMany, includeRelation, includeRelations, RelationRegistry, createRelationRegistry, validateRelation, isRelationType, isCollectionRelation, isSingleRelation, type RelationDefinition, type RelationType, type RelationLoadOptions, type RelationInclude, } from "./relations/index.js";
|
|
31
|
-
export { DatabaseLockManager, createLockManager, acquireAdvisoryLock, lockRow, buildLockClause, normalizeAdvisoryKey, type DatabaseLockMode, type DatabaseLockOptions, type DatabaseLockResult, } from "./locks/index.js";
|
|
32
|
-
export { MemoryDatabaseCache, createDatabaseCache, createCacheKey, serializeCachePart, getOrSet, invalidateByPrefix, type CacheEntry, type CacheOptions, type CacheStats, type DatabaseCache, } from "./cache/index.js";
|
|
33
|
-
export { MigrationRunner, createMigrationRunner, normalizeMigrations, validateMigration, getLatestVersion, getCurrentVersion, DEFAULT_MIGRATION_TABLE, DEFAULT_MIGRATION_LOCK, type Migration, type MigrationRecord, type MigrationResult, type MigrationStatus, type MigrationRunnerOptions, } from "./migration/index.js";
|
|
34
|
-
export { SeedRunner, createSeedRunner, normalizeSeeds, validateSeed, DEFAULT_SEED_TABLE, DEFAULT_SEED_LOCK, type Seed, type SeedRecord, type SeedResult, type SeedRunnerOptions, } from "./seed/index.js";
|
|
35
|
-
export { checkDatabaseHealth, checkDatabaseReadiness, assertDatabaseHealth, isDatabaseHealthy, DEFAULT_HEALTH_TIMEOUT_MS, type DatabaseHealthStatus, type DatabaseHealth, type DatabaseHealthOptions, type DatabaseReadiness, } from "./health/index.js";
|
|
27
|
+
export { QueryBuilder, createQueryBuilder, toPrismaWhere, toPrismaArgs, toPrismaOrderBy, toPrismaSelect, toPrismaSkipTake, type QueryCondition, type QueryFilter, type QueryOperator, type RelationOperator, type QueryBuilderState, type PrismaWhere, type PrismaQueryArgs, type ToPrismaArgsOptions, } from "./queryBuilder/index.js";
|
|
28
|
+
export { equals, notEquals, inList, notInList, lessThan, lessThanOrEqual, greaterThan, greaterThanOrEqual, contains, startsWith, endsWith, isNull, isNotNull, and, or, not, condition, allOf, anyOf, fromObject, dateRange, oneOf, noneOf, optionalEquals, optionalContains, hasConditions, flattenAnd, cloneFilter, between, matchesPattern, isEmpty, isNotEmpty, dateOnly, isBefore, isAfter, isBetween, notCondition, relational, } from "./queryBuilder/index.js";
|
|
29
|
+
export { normalizePagination, normalizePage, normalizeLimit, calculateOffset, calculateTotalPages, createPaginationMeta, createPaginatedResult, getNextPage, getPreviousPage, isValidPage, getItemRange, paginateCollection, encodeCursor, decodeCursor, validateCursorPayload, decodeKeysetCursor, buildKeysetWhere, createKeysetCursor, createKeysetPage, normalizeCursorPagination, createCursorPaginationMeta, createCursorPaginatedResult, DEFAULT_PAGE, DEFAULT_LIMIT, MAX_LIMIT, type NormalizedPagination, type CursorPaginationInput, type CursorPaginationMeta, type CursorPaginatedResult, type CursorPayload, type EncodeCursorOptions, type DecodeCursorOptions, type KeysetPageOptions, type KeysetWhere, } from "./pagination/index.js";
|
|
30
|
+
export { oneToOne, oneToMany, manyToOne, manyToMany, includeRelation, includeRelations, RelationRegistry, createRelationRegistry, validateRelation, validateInclude, toPrismaInclude, DEFAULT_INCLUDE_DEPTH, isRelationType, isCollectionRelation, isSingleRelation, type RelationDefinition, type RelationType, type RelationLoadOptions, type RelationInclude, type ToPrismaIncludeOptions, } from "./relations/index.js";
|
|
31
|
+
export { DatabaseLockManager, createLockManager, acquireAdvisoryLock, lockRow, buildLockClause, normalizeAdvisoryKey, normalizeAdvisoryKeyPair, resolveLockTransactionOptions, type DatabaseLockMode, type DatabaseLockOptions, type DatabaseLockResult, } from "./locks/index.js";
|
|
32
|
+
export { MemoryDatabaseCache, createDatabaseCache, createCacheKey, escapeCachePart, serializeCachePart, getOrSet, invalidateByPrefix, CACHE_KEY_SEPARATOR, type CacheEntry, type CacheOptions, type MemoryCacheOptions, type CacheStats, type DatabaseCache, } from "./cache/index.js";
|
|
33
|
+
export { MigrationRunner, createMigrationRunner, normalizeMigrations, validateMigration, getLatestVersion, getCurrentVersion, DEFAULT_MIGRATION_TABLE, DEFAULT_MIGRATION_LOCK, SQL_IDENTIFIER_PATTERN, validateIdentifier, validateLockKey, quoteIdentifier, hashLockKey, fnv1a64, getSqlDialect, isSqlDialectName, UnsupportedDialectError, DEFAULT_SQL_DIALECT, type Migration, type MigrationRecord, type MigrationResult, type MigrationStatus, type MigrationRunnerOptions, type RunnerTransactionOptions, type SqlDialect, type SqlDialectName, } from "./migration/index.js";
|
|
34
|
+
export { SeedRunner, createSeedRunner, normalizeSeeds, validateSeed, DEFAULT_SEED_TABLE, DEFAULT_SEED_LOCK, type Seed, type SeedRecord, type SeedResult, type SeedStatus, type SeedRunnerOptions, } from "./seed/index.js";
|
|
35
|
+
export { checkDatabaseHealth, checkDatabaseReadiness, assertDatabaseHealth, isDatabaseHealthy, getHealthCheckCause, DatabaseUnhealthyError, DEFAULT_HEALTH_TIMEOUT_MS, type DatabaseHealthStatus, type DatabaseHealth, type DatabaseHealthOptions, type DatabaseReadiness, } from "./health/index.js";
|
|
36
36
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -18,32 +18,32 @@
|
|
|
18
18
|
*/
|
|
19
19
|
export { noopDatabaseLogger } from "./databaseType/index.js";
|
|
20
20
|
// Client
|
|
21
|
-
export { DatabaseClient, createDatabaseClient, } from "./databaseClient/index.js";
|
|
21
|
+
export { DatabaseClient, DatabaseAbortError, createDatabaseClient, buildPrismaTransactionOptions, createAbortError, raceAbort, throwIfAborted, SUPPORTED_ISOLATION_LEVELS, normalizeDatabaseError, withDatabaseErrorMetadata, isPrismaError, isRetryableTransactionError, isConflictError, isNotFoundError, getDatabaseErrorCode, getDatabaseErrorKind, isDatabaseErrorLike, toDatabaseErrorInfo, RETRYABLE_DATABASE_CODES, } from "./databaseClient/index.js";
|
|
22
22
|
// Connection
|
|
23
23
|
export { DatabaseConnectionManager, createConnectionManager, } from "./databaseConnection/index.js";
|
|
24
24
|
// Database facade
|
|
25
25
|
export { Database, createDatabase, getDatabase, connectDatabase, disconnectDatabase, resetDatabase, } from "./database/index.js";
|
|
26
26
|
// Repository
|
|
27
|
-
export { BaseRepository, } from "./repository/index.js";
|
|
27
|
+
export { BaseRepository, mapRepositoryError, isPrismaErrorLike, toDatabaseOperation, } from "./repository/index.js";
|
|
28
28
|
// Transactions
|
|
29
|
-
export { TransactionManager, createTransactionManager, withTransaction, withTransactionRetry, createTransactionContext, createTransactionId, isTransactionActive, isTransactionCommitted, isTransactionFailed, } from "./transaction/index.js";
|
|
29
|
+
export { TransactionManager, createTransactionManager, withTransaction, withTransactionRetry, createTransactionContext, createTransactionId, getTransactionContextFromError, isTransactionActive, isTransactionCommitted, isTransactionFailed, } from "./transaction/index.js";
|
|
30
30
|
// Unit of Work
|
|
31
31
|
export { DatabaseUnitOfWork, createUnitOfWork, executeUnitOfWork, } from "./unitOfWork/index.js";
|
|
32
32
|
// Query Builder
|
|
33
|
-
export { QueryBuilder, createQueryBuilder, } from "./queryBuilder/index.js";
|
|
34
|
-
export { equals, notEquals, inList, notInList, lessThan, lessThanOrEqual, greaterThan, greaterThanOrEqual, contains, startsWith, endsWith, isNull, isNotNull, and, or, not, condition, allOf, anyOf, fromObject, dateRange, oneOf, noneOf, optionalEquals, optionalContains, hasConditions, flattenAnd, cloneFilter, } from "./queryBuilder/index.js";
|
|
33
|
+
export { QueryBuilder, createQueryBuilder, toPrismaWhere, toPrismaArgs, toPrismaOrderBy, toPrismaSelect, toPrismaSkipTake, } from "./queryBuilder/index.js";
|
|
34
|
+
export { equals, notEquals, inList, notInList, lessThan, lessThanOrEqual, greaterThan, greaterThanOrEqual, contains, startsWith, endsWith, isNull, isNotNull, and, or, not, condition, allOf, anyOf, fromObject, dateRange, oneOf, noneOf, optionalEquals, optionalContains, hasConditions, flattenAnd, cloneFilter, between, matchesPattern, isEmpty, isNotEmpty, dateOnly, isBefore, isAfter, isBetween, notCondition, relational, } from "./queryBuilder/index.js";
|
|
35
35
|
// Pagination
|
|
36
|
-
export { normalizePagination, normalizePage, normalizeLimit, calculateOffset, calculateTotalPages, createPaginationMeta, createPaginatedResult, getNextPage, getPreviousPage, isValidPage, getItemRange, paginateCollection, encodeCursor, decodeCursor, normalizeCursorPagination, createCursorPaginationMeta, createCursorPaginatedResult, DEFAULT_PAGE, DEFAULT_LIMIT, MAX_LIMIT, } from "./pagination/index.js";
|
|
36
|
+
export { normalizePagination, normalizePage, normalizeLimit, calculateOffset, calculateTotalPages, createPaginationMeta, createPaginatedResult, getNextPage, getPreviousPage, isValidPage, getItemRange, paginateCollection, encodeCursor, decodeCursor, validateCursorPayload, decodeKeysetCursor, buildKeysetWhere, createKeysetCursor, createKeysetPage, normalizeCursorPagination, createCursorPaginationMeta, createCursorPaginatedResult, DEFAULT_PAGE, DEFAULT_LIMIT, MAX_LIMIT, } from "./pagination/index.js";
|
|
37
37
|
// Relations
|
|
38
|
-
export { oneToOne, oneToMany, manyToOne, manyToMany, includeRelation, includeRelations, RelationRegistry, createRelationRegistry, validateRelation, isRelationType, isCollectionRelation, isSingleRelation, } from "./relations/index.js";
|
|
38
|
+
export { oneToOne, oneToMany, manyToOne, manyToMany, includeRelation, includeRelations, RelationRegistry, createRelationRegistry, validateRelation, validateInclude, toPrismaInclude, DEFAULT_INCLUDE_DEPTH, isRelationType, isCollectionRelation, isSingleRelation, } from "./relations/index.js";
|
|
39
39
|
// Locks
|
|
40
|
-
export { DatabaseLockManager, createLockManager, acquireAdvisoryLock, lockRow, buildLockClause, normalizeAdvisoryKey, } from "./locks/index.js";
|
|
40
|
+
export { DatabaseLockManager, createLockManager, acquireAdvisoryLock, lockRow, buildLockClause, normalizeAdvisoryKey, normalizeAdvisoryKeyPair, resolveLockTransactionOptions, } from "./locks/index.js";
|
|
41
41
|
// Cache
|
|
42
|
-
export { MemoryDatabaseCache, createDatabaseCache, createCacheKey, serializeCachePart, getOrSet, invalidateByPrefix, } from "./cache/index.js";
|
|
42
|
+
export { MemoryDatabaseCache, createDatabaseCache, createCacheKey, escapeCachePart, serializeCachePart, getOrSet, invalidateByPrefix, CACHE_KEY_SEPARATOR, } from "./cache/index.js";
|
|
43
43
|
// Migrations
|
|
44
|
-
export { MigrationRunner, createMigrationRunner, normalizeMigrations, validateMigration, getLatestVersion, getCurrentVersion, DEFAULT_MIGRATION_TABLE, DEFAULT_MIGRATION_LOCK, } from "./migration/index.js";
|
|
44
|
+
export { MigrationRunner, createMigrationRunner, normalizeMigrations, validateMigration, getLatestVersion, getCurrentVersion, DEFAULT_MIGRATION_TABLE, DEFAULT_MIGRATION_LOCK, SQL_IDENTIFIER_PATTERN, validateIdentifier, validateLockKey, quoteIdentifier, hashLockKey, fnv1a64, getSqlDialect, isSqlDialectName, UnsupportedDialectError, DEFAULT_SQL_DIALECT, } from "./migration/index.js";
|
|
45
45
|
// Seeds
|
|
46
46
|
export { SeedRunner, createSeedRunner, normalizeSeeds, validateSeed, DEFAULT_SEED_TABLE, DEFAULT_SEED_LOCK, } from "./seed/index.js";
|
|
47
47
|
// Health
|
|
48
|
-
export { checkDatabaseHealth, checkDatabaseReadiness, assertDatabaseHealth, isDatabaseHealthy, DEFAULT_HEALTH_TIMEOUT_MS, } from "./health/index.js";
|
|
48
|
+
export { checkDatabaseHealth, checkDatabaseReadiness, assertDatabaseHealth, isDatabaseHealthy, getHealthCheckCause, DatabaseUnhealthyError, DEFAULT_HEALTH_TIMEOUT_MS, } from "./health/index.js";
|
|
49
49
|
//# sourceMappingURL=index.js.map
|
package/dist/locks/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @zudojs/database — Locks
|
|
3
3
|
*
|
|
4
|
-
* Advisory and row-level database locking.
|
|
4
|
+
* Advisory and row-level database locking (PostgreSQL).
|
|
5
5
|
*/
|
|
6
|
-
export { DatabaseLockManager, createLockManager, acquireAdvisoryLock, lockRow, buildLockClause, normalizeAdvisoryKey, type DatabaseLockMode, type DatabaseLockOptions, type DatabaseLockResult, } from "./locks.core.js";
|
|
6
|
+
export { DatabaseLockManager, createLockManager, acquireAdvisoryLock, lockRow, buildLockClause, normalizeAdvisoryKey, normalizeAdvisoryKeyPair, resolveLockTransactionOptions, type DatabaseLockMode, type DatabaseLockOptions, type DatabaseLockResult, } from "./locks.core.js";
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/locks/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @zudojs/database — Locks
|
|
3
3
|
*
|
|
4
|
-
* Advisory and row-level database locking.
|
|
4
|
+
* Advisory and row-level database locking (PostgreSQL).
|
|
5
5
|
*/
|
|
6
|
-
export { DatabaseLockManager, createLockManager, acquireAdvisoryLock, lockRow, buildLockClause, normalizeAdvisoryKey, } from "./locks.core.js";
|
|
6
|
+
export { DatabaseLockManager, createLockManager, acquireAdvisoryLock, lockRow, buildLockClause, normalizeAdvisoryKey, normalizeAdvisoryKeyPair, resolveLockTransactionOptions, } from "./locks.core.js";
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { DatabaseClient, DatabaseTransactionContext } from "../databaseClient/databaseClient.core.js";
|
|
2
|
+
import type { TransactionOptions } from "../databaseType/databaseType.type.js";
|
|
3
|
+
/**
|
|
4
|
+
* Supported row lock modes (PostgreSQL).
|
|
5
|
+
*/
|
|
6
|
+
export type DatabaseLockMode = "for-update" | "for-no-key-update" | "for-share" | "for-key-share";
|
|
7
|
+
/**
|
|
8
|
+
* Options for acquiring a database lock.
|
|
9
|
+
*
|
|
10
|
+
* All locking in this module is PostgreSQL-specific (`pg_advisory_xact_lock`,
|
|
11
|
+
* `FOR UPDATE ... SKIP LOCKED`, `lock_timeout`).
|
|
12
|
+
*/
|
|
13
|
+
export interface DatabaseLockOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Row lock mode. Ignored for advisory locks.
|
|
16
|
+
*/
|
|
17
|
+
readonly mode?: DatabaseLockMode;
|
|
18
|
+
/**
|
|
19
|
+
* Maximum time to wait for the lock. Applied with
|
|
20
|
+
* `SET LOCAL lock_timeout` inside the transaction, so a contended lock
|
|
21
|
+
* fails with a lock-timeout error instead of Prisma's generic
|
|
22
|
+
* transaction timeout. When it exceeds Prisma's 5 s default and
|
|
23
|
+
* `transaction.timeoutMs` is not set, the transaction timeout is raised
|
|
24
|
+
* automatically (see `resolveLockTransactionOptions`).
|
|
25
|
+
*
|
|
26
|
+
* Must be a positive number: PostgreSQL treats `lock_timeout = 0` as
|
|
27
|
+
* "disabled" (wait forever), so `0` is rejected. Use `noWait` to fail
|
|
28
|
+
* immediately instead.
|
|
29
|
+
*/
|
|
30
|
+
readonly timeoutMs?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Row locks only: skip rows locked by other transactions instead of
|
|
33
|
+
* waiting. When the row is skipped the lock is *not* held and
|
|
34
|
+
* `acquired` is `false`.
|
|
35
|
+
*/
|
|
36
|
+
readonly skipLocked?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Fail immediately when the lock is held by another transaction.
|
|
39
|
+
*/
|
|
40
|
+
readonly noWait?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Advisory locks only: optional namespace. When supplied the two-int
|
|
43
|
+
* form `pg_advisory_xact_lock(int, int)` is used with the namespace
|
|
44
|
+
* hashed into the first argument, so unrelated services sharing one
|
|
45
|
+
* database cannot collide on the same 64-bit key space.
|
|
46
|
+
*/
|
|
47
|
+
readonly namespace?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Options forwarded to the transaction opened by the lock manager.
|
|
50
|
+
*/
|
|
51
|
+
readonly transaction?: TransactionOptions;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Result of a lock acquisition.
|
|
55
|
+
*/
|
|
56
|
+
export interface DatabaseLockResult {
|
|
57
|
+
readonly acquired: boolean;
|
|
58
|
+
readonly lockKey: string;
|
|
59
|
+
readonly mode?: DatabaseLockMode;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Application-level lock abstraction for PostgreSQL.
|
|
63
|
+
*
|
|
64
|
+
* Locks are acquired inside a transaction and released when it ends.
|
|
65
|
+
*/
|
|
66
|
+
export declare class DatabaseLockManager {
|
|
67
|
+
private readonly client;
|
|
68
|
+
constructor(client: DatabaseClient);
|
|
69
|
+
/**
|
|
70
|
+
* Executes work inside a transaction after acquiring a PostgreSQL
|
|
71
|
+
* advisory transaction lock.
|
|
72
|
+
*/
|
|
73
|
+
withAdvisoryLock<TResult>(lockKey: string, callback: (transaction: DatabaseTransactionContext) => Promise<TResult>, options?: DatabaseLockOptions): Promise<TResult>;
|
|
74
|
+
/**
|
|
75
|
+
* Acquires a row-level lock and executes work while holding it.
|
|
76
|
+
*
|
|
77
|
+
* @throws {DatabaseError} when the row does not exist or was skipped
|
|
78
|
+
* because another transaction holds it (`skipLocked`).
|
|
79
|
+
*/
|
|
80
|
+
withRowLock<TResult>(tableName: string, id: string | number, callback: (transaction: DatabaseTransactionContext) => Promise<TResult>, options?: DatabaseLockOptions): Promise<TResult>;
|
|
81
|
+
/**
|
|
82
|
+
* Returns the underlying database client.
|
|
83
|
+
*/
|
|
84
|
+
getClient(): DatabaseClient;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Creates a lock manager.
|
|
88
|
+
*/
|
|
89
|
+
export declare function createLockManager(client: DatabaseClient): DatabaseLockManager;
|
|
90
|
+
/**
|
|
91
|
+
* Acquires a PostgreSQL advisory transaction lock.
|
|
92
|
+
*
|
|
93
|
+
* The lock key is hashed with FNV-1a to a signed 64-bit key (or, with a
|
|
94
|
+
* `namespace`, to a pair of signed 32-bit keys).
|
|
95
|
+
*/
|
|
96
|
+
export declare function acquireAdvisoryLock(transaction: DatabaseTransactionContext, lockKey: string, options?: DatabaseLockOptions): Promise<DatabaseLockResult>;
|
|
97
|
+
/**
|
|
98
|
+
* Acquires a row-level PostgreSQL lock.
|
|
99
|
+
*
|
|
100
|
+
* @throws {DatabaseError} when the row does not exist.
|
|
101
|
+
* @returns `acquired: false` only when `skipLocked` skipped a row held by
|
|
102
|
+
* another transaction.
|
|
103
|
+
*/
|
|
104
|
+
export declare function lockRow(transaction: DatabaseTransactionContext, tableName: string, id: string | number, options?: DatabaseLockOptions): Promise<DatabaseLockResult>;
|
|
105
|
+
/**
|
|
106
|
+
* Builds a safe PostgreSQL lock clause.
|
|
107
|
+
*/
|
|
108
|
+
export declare function buildLockClause(mode: DatabaseLockMode, options?: DatabaseLockOptions): string;
|
|
109
|
+
/**
|
|
110
|
+
* Converts an application lock key into a deterministic signed 64-bit
|
|
111
|
+
* advisory key (FNV-1a 64).
|
|
112
|
+
*/
|
|
113
|
+
export declare function normalizeAdvisoryKey(lockKey: string): bigint;
|
|
114
|
+
/**
|
|
115
|
+
* Converts a namespace and key into the two signed 32-bit integers used by
|
|
116
|
+
* the two-argument advisory lock functions.
|
|
117
|
+
*/
|
|
118
|
+
export declare function normalizeAdvisoryKeyPair(namespace: string, lockKey: string): readonly [number, number];
|
|
119
|
+
/**
|
|
120
|
+
* Derives the transaction options for a lock so that `lock_timeout` is
|
|
121
|
+
* always shorter than the surrounding Prisma transaction timeout.
|
|
122
|
+
*
|
|
123
|
+
* Without this, a lock wait longer than Prisma's 5 s default would surface
|
|
124
|
+
* as a generic "transaction already closed" error instead of a lock
|
|
125
|
+
* timeout. When `transaction.timeoutMs` is not supplied it is raised to
|
|
126
|
+
* cover the lock wait plus the default budget for the callback.
|
|
127
|
+
*
|
|
128
|
+
* @throws {TypeError} when `transaction.timeoutMs` is explicitly shorter
|
|
129
|
+
* than `timeoutMs`.
|
|
130
|
+
*/
|
|
131
|
+
export declare function resolveLockTransactionOptions(options?: DatabaseLockOptions): TransactionOptions | undefined;
|
|
132
|
+
//# sourceMappingURL=locks.core.d.ts.map
|