@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
|
@@ -2,41 +2,198 @@
|
|
|
2
2
|
* @zudojs/database — Database Client Core
|
|
3
3
|
*
|
|
4
4
|
* Prisma-backed database client implementation.
|
|
5
|
+
*
|
|
6
|
+
* The client is a thin lifecycle wrapper over a Prisma client. It never
|
|
7
|
+
* reads runtime values from the generated `Prisma` namespace, so it works
|
|
8
|
+
* whether the consumer's generated client lives in `@prisma/client` or in a
|
|
9
|
+
* custom output directory (the Prisma 7 default).
|
|
10
|
+
*
|
|
11
|
+
* Only PostgreSQL is exercised by the runners, locks and health helpers in
|
|
12
|
+
* this package.
|
|
5
13
|
*/
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
import type { Prisma } from "@prisma/client";
|
|
15
|
+
import { DatabaseError } from "@zudojs/errors";
|
|
16
|
+
import type { DatabaseClient as DatabaseClientContract, DatabaseConnectionOptions, DatabaseHealth, DatabaseLogger, DatabaseOperationOptions, DatabaseStatus, TransactionCallback, TransactionIsolationLevel, TransactionOptions } from "../databaseType/databaseType.type.js";
|
|
17
|
+
/**
|
|
18
|
+
* Transaction client handed to callbacks. This is Prisma's interactive
|
|
19
|
+
* transaction client (model delegates plus raw query helpers).
|
|
20
|
+
*/
|
|
21
|
+
export type DatabaseTransactionContext = Prisma.TransactionClient;
|
|
22
|
+
/**
|
|
23
|
+
* Isolation levels accepted by Prisma's interactive transactions. The
|
|
24
|
+
* values are identical to the string names, so no namespace lookup is
|
|
25
|
+
* required.
|
|
26
|
+
*/
|
|
27
|
+
export declare const SUPPORTED_ISOLATION_LEVELS: readonly TransactionIsolationLevel[];
|
|
28
|
+
/**
|
|
29
|
+
* Options forwarded to Prisma's interactive `$transaction`.
|
|
30
|
+
*/
|
|
31
|
+
export interface PrismaTransactionOptions {
|
|
32
|
+
readonly maxWait?: number;
|
|
33
|
+
readonly timeout?: number;
|
|
34
|
+
readonly isolationLevel?: TransactionIsolationLevel;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Structural view of the Prisma client surface this package relies on.
|
|
38
|
+
*
|
|
39
|
+
* Any generated `PrismaClient` satisfies it; tests can supply a stub.
|
|
40
|
+
*/
|
|
41
|
+
export interface PrismaClientLike {
|
|
42
|
+
$connect(): Promise<void>;
|
|
43
|
+
$disconnect(): Promise<void>;
|
|
44
|
+
$transaction<TResult>(callback: (transaction: DatabaseTransactionContext) => Promise<TResult>, options?: PrismaTransactionOptions): Promise<TResult>;
|
|
45
|
+
$queryRawUnsafe<TResult = unknown>(query: string, ...values: unknown[]): Promise<TResult>;
|
|
46
|
+
$executeRawUnsafe(query: string, ...values: unknown[]): Promise<number>;
|
|
47
|
+
$on?(event: "query", callback: (event: PrismaQueryEvent) => void): void;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Prisma query log event.
|
|
51
|
+
*/
|
|
52
|
+
export interface PrismaQueryEvent {
|
|
53
|
+
readonly query: string;
|
|
54
|
+
readonly params: string;
|
|
55
|
+
readonly duration: number;
|
|
56
|
+
readonly target: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Prisma driver adapter (for example `@prisma/adapter-pg`).
|
|
60
|
+
*
|
|
61
|
+
* Typed structurally so this package does not depend on any adapter.
|
|
62
|
+
*/
|
|
63
|
+
export interface PrismaDriverAdapterLike {
|
|
64
|
+
readonly provider: string;
|
|
65
|
+
readonly adapterName: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Options accepted by {@link DatabaseClient}.
|
|
69
|
+
*
|
|
70
|
+
* Prisma 7 requires either a driver adapter or an already constructed
|
|
71
|
+
* client; connection URLs, pool sizes and SSL flags are configured on the
|
|
72
|
+
* adapter and are therefore not accepted here.
|
|
73
|
+
*/
|
|
74
|
+
export interface DatabaseClientOptions extends Pick<DatabaseConnectionOptions, "connectionTimeoutMs" | "logging"> {
|
|
75
|
+
/**
|
|
76
|
+
* Pre-built Prisma client. Takes precedence over `adapter`.
|
|
77
|
+
*/
|
|
11
78
|
readonly prisma?: PrismaClientLike;
|
|
79
|
+
/**
|
|
80
|
+
* Prisma driver adapter used to construct a client when `prisma` is
|
|
81
|
+
* not supplied.
|
|
82
|
+
*/
|
|
83
|
+
readonly adapter?: PrismaDriverAdapterLike;
|
|
84
|
+
readonly logger?: DatabaseLogger;
|
|
12
85
|
}
|
|
13
|
-
|
|
14
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Raw query options.
|
|
88
|
+
*/
|
|
89
|
+
export type RawQueryOptions = DatabaseOperationOptions;
|
|
90
|
+
/**
|
|
91
|
+
* Prisma-backed database client.
|
|
92
|
+
*
|
|
93
|
+
* `connect()` de-duplicates concurrent calls through a shared in-flight
|
|
94
|
+
* promise, and `disconnect()` waits for an in-flight connect before
|
|
95
|
+
* tearing the client down.
|
|
96
|
+
*/
|
|
15
97
|
export declare class DatabaseClient implements DatabaseClientContract<DatabaseTransactionContext> {
|
|
16
98
|
private readonly prisma;
|
|
17
99
|
private readonly logger;
|
|
18
100
|
private readonly options;
|
|
19
101
|
private status;
|
|
20
102
|
private connectedAt?;
|
|
103
|
+
private connectPromise?;
|
|
104
|
+
private disconnectPromise?;
|
|
21
105
|
constructor(options?: DatabaseClientOptions);
|
|
106
|
+
/**
|
|
107
|
+
* Returns the underlying Prisma client.
|
|
108
|
+
*/
|
|
22
109
|
getPrisma(): PrismaClientLike;
|
|
110
|
+
/**
|
|
111
|
+
* Opens the connection. Concurrent calls share one in-flight attempt.
|
|
112
|
+
*/
|
|
23
113
|
connect(): Promise<void>;
|
|
114
|
+
private performConnect;
|
|
115
|
+
/**
|
|
116
|
+
* Closes the connection. Waits for an in-flight connect first.
|
|
117
|
+
*/
|
|
24
118
|
disconnect(): Promise<void>;
|
|
25
|
-
|
|
119
|
+
private performDisconnect;
|
|
120
|
+
/**
|
|
121
|
+
* Executes a lightweight `SELECT 1`.
|
|
122
|
+
*/
|
|
123
|
+
ping(options?: RawQueryOptions): Promise<void>;
|
|
26
124
|
getStatus(): DatabaseStatus;
|
|
27
125
|
getConnectedAt(): Date | undefined;
|
|
28
|
-
|
|
126
|
+
/**
|
|
127
|
+
* Pings the database and reports the real lifecycle status.
|
|
128
|
+
*/
|
|
129
|
+
healthCheck(options?: RawQueryOptions): Promise<DatabaseHealth>;
|
|
130
|
+
/**
|
|
131
|
+
* Runs a callback inside a Prisma interactive transaction.
|
|
132
|
+
*
|
|
133
|
+
* When `options.signal` aborts, the abort is raised *inside* the
|
|
134
|
+
* transaction callback so Prisma rolls the transaction back; the caller
|
|
135
|
+
* is released at the same moment. Racing only the outer promise let the
|
|
136
|
+
* callback finish and the transaction commit after the caller had
|
|
137
|
+
* already been told it was aborted.
|
|
138
|
+
*/
|
|
29
139
|
transaction<TResult>(callback: TransactionCallback<DatabaseTransactionContext, TResult>, options?: TransactionOptions): Promise<TResult>;
|
|
30
|
-
|
|
31
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Executes a raw statement with positional parameters and returns the
|
|
142
|
+
* affected row count.
|
|
143
|
+
*/
|
|
144
|
+
executeRawUnsafe(sql: string, values?: readonly unknown[], options?: RawQueryOptions): Promise<number>;
|
|
145
|
+
/**
|
|
146
|
+
* Executes a raw query with positional parameters.
|
|
147
|
+
*/
|
|
148
|
+
queryRawUnsafe<TResult = unknown>(sql: string, values?: readonly unknown[], options?: RawQueryOptions): Promise<TResult>;
|
|
149
|
+
/**
|
|
150
|
+
* Executes a `Prisma.sql` tagged statement.
|
|
151
|
+
*
|
|
152
|
+
* Only available when the underlying client supports `$executeRaw`.
|
|
153
|
+
*/
|
|
154
|
+
executeRaw(query: Prisma.Sql, options?: RawQueryOptions): Promise<number>;
|
|
155
|
+
/**
|
|
156
|
+
* Executes a `Prisma.sql` tagged query.
|
|
157
|
+
*/
|
|
158
|
+
queryRaw<TResult = unknown>(query: Prisma.Sql, options?: RawQueryOptions): Promise<TResult>;
|
|
32
159
|
ensureConnected(): Promise<void>;
|
|
33
160
|
destroy(): Promise<void>;
|
|
34
161
|
private registerQueryLogging;
|
|
35
|
-
|
|
36
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Applies `signal` and `timeoutMs` to a raw operation.
|
|
164
|
+
*
|
|
165
|
+
* Timeouts are client-side only: the caller stops waiting, but the
|
|
166
|
+
* statement keeps running on the server until it completes. Use
|
|
167
|
+
* `statement_timeout` for server-side cancellation.
|
|
168
|
+
*/
|
|
169
|
+
private runRaw;
|
|
37
170
|
private withTimeout;
|
|
38
|
-
private normalizeError;
|
|
39
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Maps package transaction options onto Prisma's interactive transaction
|
|
174
|
+
* options. Isolation levels are validated against the supported list and
|
|
175
|
+
* passed through as strings.
|
|
176
|
+
*/
|
|
177
|
+
export declare function buildPrismaTransactionOptions(options?: TransactionOptions): PrismaTransactionOptions;
|
|
178
|
+
/**
|
|
179
|
+
* Throws an abort-typed `DatabaseError` when the signal is already aborted.
|
|
180
|
+
*/
|
|
181
|
+
export declare function throwIfAborted(signal: AbortSignal | undefined): void;
|
|
182
|
+
/**
|
|
183
|
+
* Error raised when an operation is cancelled through an `AbortSignal`.
|
|
184
|
+
*/
|
|
185
|
+
export declare class DatabaseAbortError extends DatabaseError {
|
|
186
|
+
constructor(signal?: AbortSignal);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Creates the error used when an operation is aborted through a signal.
|
|
190
|
+
*/
|
|
191
|
+
export declare function createAbortError(signal?: AbortSignal): DatabaseAbortError;
|
|
192
|
+
/**
|
|
193
|
+
* Rejects as soon as the signal aborts, even if the operation is still
|
|
194
|
+
* running. The abort listener is removed once the operation settles.
|
|
195
|
+
*/
|
|
196
|
+
export declare function raceAbort<T>(promise: Promise<T>, signal: AbortSignal | undefined): Promise<T>;
|
|
40
197
|
/** Creates a database client. */
|
|
41
198
|
export declare function createDatabaseClient(options?: DatabaseClientOptions): DatabaseClient;
|
|
42
199
|
//# sourceMappingURL=databaseClient.core.d.ts.map
|