turbine-orm 0.95.0 → 0.96.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/README.md +2 -2
- package/dist/cjs/cli/prisma-resolve.js +14 -9
- package/dist/cjs/client.js +49 -0
- package/dist/cjs/connection-url.d.ts +44 -1
- package/dist/cjs/connection-url.js +57 -2
- package/dist/cjs/nested-write.js +79 -17
- package/dist/cjs/prisma-compat.d.ts +107 -15
- package/dist/cjs/prisma-compat.js +654 -113
- package/dist/cjs/query/aggregates.js +13 -1
- package/dist/cjs/query/types.d.ts +15 -1
- package/dist/cjs/schema.d.ts +8 -7
- package/dist/cjs/transaction-state.d.ts +14 -1
- package/dist/cjs/transaction-state.js +61 -6
- package/dist/cli/prisma-resolve.js +14 -9
- package/dist/client.js +50 -1
- package/dist/connection-url.d.ts +44 -1
- package/dist/connection-url.js +55 -2
- package/dist/nested-write.js +79 -17
- package/dist/prisma-compat.d.ts +107 -15
- package/dist/prisma-compat.js +652 -113
- package/dist/query/aggregates.js +14 -2
- package/dist/query/types.d.ts +15 -1
- package/dist/schema.d.ts +8 -7
- package/dist/transaction-state.d.ts +14 -1
- package/dist/transaction-state.js +61 -6
- package/package.json +1 -1
|
@@ -63,21 +63,26 @@
|
|
|
63
63
|
* - `instanceof PrismaClientKnownRequestError`, `.meta`/message byte parity
|
|
64
64
|
* (opt into `prismaErrorCodes` for a `.code` like `P2002`, without pretending
|
|
65
65
|
* `instanceof` identity).
|
|
66
|
-
* -
|
|
66
|
+
* - Splicing another library's `Prisma.sql` fragments unless asked to: they are
|
|
67
|
+
* bound as values until the client is given that library's namespace
|
|
68
|
+
* ({@link PrismaCompatOptions.prismaNamespace}).
|
|
67
69
|
* - Fluent relation chaining (`prisma.user.findUnique().posts()`).
|
|
68
70
|
* - Accelerate / Pulse / driver-adapter preview features, the Mongo API, and the
|
|
69
71
|
* `prisma migrate`/`db` CLI family (Turbine ships its own migrations).
|
|
70
72
|
* - **Negative `take`** (take-from-end) throws: Turbine has no reverse-take.
|
|
71
73
|
* A **`cursor` on a nested relation include** throws: `with` has no cursor
|
|
72
74
|
* (`take` / `skip` there page each parent's rows, as in Prisma).
|
|
73
|
-
* -
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
75
|
+
* - **`distinct` on a nested include** throws `UnsupportedFeatureError`: core
|
|
76
|
+
* includes a relation whole, so honoring it would mean returning duplicate
|
|
77
|
+
* rows. The message names the alternative (a `findMany` on the related model).
|
|
78
|
+
* A filtered relation count (`_count: { select: { posts: { where } } }`) and a
|
|
79
|
+
* `_count` below the top level ARE supported: this layer runs one grouped
|
|
80
|
+
* count per counted relation after the read, in the same transaction (see
|
|
81
|
+
* {@link ReadPlan}). Those two forms count one-to-many relations only; a
|
|
82
|
+
* many-to-many one is refused by name.
|
|
78
83
|
* - **Nothing is accepted and dropped.** Every option on an included relation
|
|
79
|
-
* and every key under `_count` is translated, refused by name (
|
|
80
|
-
*
|
|
84
|
+
* and every key under `_count` is translated, refused by name (`distinct`,
|
|
85
|
+
* `cursor`), or refused as unknown (`ValidationError`, with a
|
|
81
86
|
* suggestion): a misspelled `wher`, a Turbine spelling like `limit`, a
|
|
82
87
|
* relation `_count` does not know. The same holds for `$transaction` options
|
|
83
88
|
* (`maxWait` is accepted, warned about once, and not applied: the pool's
|
|
@@ -89,10 +94,11 @@
|
|
|
89
94
|
* - **Write projections**: `select` / `omit` on create/update/delete/upsert
|
|
90
95
|
* narrow the RETURNED OBJECT (see {@link resolveWriteProjection}); they do
|
|
91
96
|
* NOT narrow the statement's `RETURNING` list, so the column still crosses
|
|
92
|
-
* the wire, and `pii: true` remains the SQL-level control. A
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
97
|
+
* the wire, and `pii: true` remains the SQL-level control. A write whose
|
|
98
|
+
* `include` / `select` names a relation or `_count` runs as the write followed
|
|
99
|
+
* by a read of the written row by primary key, in one transaction (a delete
|
|
100
|
+
* reads first), so it returns what Prisma returns. `omit` on READS is
|
|
101
|
+
* translated to core's own `omit`, see {@link translateOmit}.
|
|
96
102
|
* - **`take` / `skip` / `cursor` on `count` and `aggregate`** throw: Prisma
|
|
97
103
|
* computes those over one page of rows and Turbine has no paged count. An
|
|
98
104
|
* `orderBy` alone changes nothing there and is accepted. `count({ select })`
|
|
@@ -126,7 +132,7 @@
|
|
|
126
132
|
* });
|
|
127
133
|
* ```
|
|
128
134
|
*/
|
|
129
|
-
import type { TurbineClient } from './client.js';
|
|
135
|
+
import type { TransactionClient, TurbineClient } from './client.js';
|
|
130
136
|
import { type DeferredQuery } from './query/index.js';
|
|
131
137
|
import type { PrismaCompatMap, SchemaMetadata } from './schema.js';
|
|
132
138
|
/** A build-only query object with the `build*` methods the adapter drives. */
|
|
@@ -191,6 +197,10 @@ export interface CompatTransactionClient {
|
|
|
191
197
|
/** The minimal `TurbineClient` surface the adapter consumes. */
|
|
192
198
|
export interface CompatTurbineClient extends CompatTransactionClient {
|
|
193
199
|
readonly schema: SchemaMetadata;
|
|
200
|
+
/** Core `connect()`; absent on a test stub. */
|
|
201
|
+
connect?(): Promise<void>;
|
|
202
|
+
/** Core `disconnect()`; absent on a test stub. */
|
|
203
|
+
disconnect?(): Promise<unknown>;
|
|
194
204
|
$transaction<R>(fn: (tx: CompatTransactionClient) => Promise<R>, options?: unknown): Promise<R>;
|
|
195
205
|
$transaction(queries: readonly DeferredQuery<unknown>[], options?: unknown): Promise<unknown[]>;
|
|
196
206
|
}
|
|
@@ -218,6 +228,16 @@ export interface Sql {
|
|
|
218
228
|
readonly values: readonly unknown[];
|
|
219
229
|
readonly [SQL_FRAGMENT]: true;
|
|
220
230
|
}
|
|
231
|
+
/** The structural shape of a fragment: this module's {@link Sql}, or another library's. */
|
|
232
|
+
export interface SqlFragmentLike {
|
|
233
|
+
readonly strings: readonly string[];
|
|
234
|
+
readonly values: readonly unknown[];
|
|
235
|
+
}
|
|
236
|
+
/** The part of a client library's `Prisma` namespace {@link PrismaCompatOptions.prismaNamespace} reads. */
|
|
237
|
+
export interface PrismaNamespaceLike {
|
|
238
|
+
/** `Prisma.empty`: an instance of the library's fragment class. */
|
|
239
|
+
readonly empty: object;
|
|
240
|
+
}
|
|
221
241
|
/**
|
|
222
242
|
* `Prisma`-compatible raw-SQL helpers, a minimal local implementation so
|
|
223
243
|
* migrated `Prisma.sql\`…\`` / `Prisma.join(...)` / `Prisma.raw(...)` calls keep
|
|
@@ -272,6 +292,27 @@ export interface PrismaCompatOptions {
|
|
|
272
292
|
* `false` (Turbine's own `TURBINE_E0NN` codes are preserved untouched).
|
|
273
293
|
*/
|
|
274
294
|
prismaErrorCodes?: boolean;
|
|
295
|
+
/**
|
|
296
|
+
* The `Prisma` namespace of the client library the call sites were written
|
|
297
|
+
* against (`import { Prisma } from '@prisma/client'`). With it, fragments that
|
|
298
|
+
* library builds (`Prisma.sql`, `Prisma.join`, `Prisma.raw`, `Prisma.empty`)
|
|
299
|
+
* compose in `$queryRaw` / `$executeRaw` exactly like this module's own: nested
|
|
300
|
+
* in a template, as the lone argument, and inside each other. Without it they
|
|
301
|
+
* are bound as `$N` values, which is the safe reading of an object nobody vouched
|
|
302
|
+
* for.
|
|
303
|
+
*
|
|
304
|
+
* Only instances of the namespace's own fragment class are spliced (recognized
|
|
305
|
+
* by prototype, never by shape), so an object parsed from a request body is a
|
|
306
|
+
* value whatever keys it carries.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```ts
|
|
310
|
+
* import { Prisma } from '@prisma/client';
|
|
311
|
+
* const prisma = createPrismaCompatClient(db, PRISMA_MAP, { prismaNamespace: Prisma });
|
|
312
|
+
* await prisma.$queryRaw`SELECT * FROM "User" WHERE id IN (${Prisma.join(ids)})`;
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
prismaNamespace?: PrismaNamespaceLike;
|
|
275
316
|
}
|
|
276
317
|
/** The delegate operations this adapter exposes. */
|
|
277
318
|
export type CompatOperation = 'findMany' | 'findFirst' | 'findFirstOrThrow' | 'findUnique' | 'findUniqueOrThrow' | 'create' | 'createMany' | 'update' | 'updateMany' | 'delete' | 'deleteMany' | 'upsert' | 'count' | 'aggregate' | 'groupBy';
|
|
@@ -335,9 +376,11 @@ export interface PrismaModelDelegate<M extends PrismaModelTypes> {
|
|
|
335
376
|
* the transaction's own connection.
|
|
336
377
|
*/
|
|
337
378
|
export interface PrismaCompatRawSurface {
|
|
338
|
-
|
|
379
|
+
/** A tagged template, or one fragment (`$queryRaw(Prisma.sql\`...\`)`), as in Prisma. */
|
|
380
|
+
$queryRaw<T = unknown>(strings: TemplateStringsArray | SqlFragmentLike, ...values: unknown[]): Promise<T[]>;
|
|
339
381
|
$queryRawUnsafe<T = unknown>(sql: string, ...params: unknown[]): Promise<T[]>;
|
|
340
|
-
|
|
382
|
+
/** A tagged template, or one fragment (`$executeRaw(Prisma.sql\`...\`)`), as in Prisma. */
|
|
383
|
+
$executeRaw(strings: TemplateStringsArray | SqlFragmentLike, ...values: unknown[]): Promise<number>;
|
|
341
384
|
$executeRawUnsafe(sql: string, ...params: unknown[]): Promise<number>;
|
|
342
385
|
}
|
|
343
386
|
/**
|
|
@@ -403,7 +446,13 @@ export interface PrismaCompatClientBase<S extends Record<string, PrismaModelType
|
|
|
403
446
|
* extensions throw, see {@link PrismaCompatExtension}.
|
|
404
447
|
*/
|
|
405
448
|
$extends<E extends PrismaCompatExtension>(extension: E): PrismaCompatExtendedClient<S, E>;
|
|
449
|
+
/** Open a connection now (core `connect()`: one `SELECT 1`), so a bad URL fails here rather than at the first query. */
|
|
406
450
|
$connect(): Promise<void>;
|
|
451
|
+
/**
|
|
452
|
+
* Close the wrapped client's pool (core `disconnect()`), so a script can
|
|
453
|
+
* exit. Idempotent, and shared by every `$extends` of this client. Unlike
|
|
454
|
+
* Prisma the pool is not reopened by a later query: build a new client.
|
|
455
|
+
*/
|
|
407
456
|
$disconnect(): Promise<void>;
|
|
408
457
|
}
|
|
409
458
|
/** Options accepted by `$transaction`, in its callback and array forms. */
|
|
@@ -435,6 +484,49 @@ export type PrismaCompatClient<S extends Record<string, PrismaModelTypes> = Reco
|
|
|
435
484
|
} & {
|
|
436
485
|
[K in keyof S as Uncapitalize<K & string>]: PrismaModelDelegate<S[K]>;
|
|
437
486
|
} & PrismaCompatClientBase<S>;
|
|
487
|
+
/**
|
|
488
|
+
* The Turbine client under a compat client: the `TurbineClient` it wraps for the
|
|
489
|
+
* client (or any `$extends` of it), and the core `TransactionClient` for the `tx`
|
|
490
|
+
* a `$transaction(async (tx) => ...)` callback receives (or one
|
|
491
|
+
* {@link bindTransaction} made). This is how code is moved off the compat surface
|
|
492
|
+
* one module at a time: a ported function takes the compat client, calls
|
|
493
|
+
* `turbineOf`, and uses Turbine's own API on the SAME connection, so inside a
|
|
494
|
+
* transaction it sees that transaction's uncommitted writes and is rolled back
|
|
495
|
+
* with it.
|
|
496
|
+
*
|
|
497
|
+
* Throws for anything this module did not build.
|
|
498
|
+
*
|
|
499
|
+
* @example
|
|
500
|
+
* ```ts
|
|
501
|
+
* await prisma.$transaction(async (tx) => {
|
|
502
|
+
* await tx.user.update({ where: { id }, data: { name } });
|
|
503
|
+
* const user = await turbineOf(tx).table('users').findUnique({ where: { id } }); // same transaction
|
|
504
|
+
* });
|
|
505
|
+
* ```
|
|
506
|
+
*/
|
|
507
|
+
export declare function turbineOf<S extends Record<string, PrismaModelTypes>>(compat: PrismaCompatClient<S>): TurbineClient;
|
|
508
|
+
export declare function turbineOf<S extends Record<string, PrismaModelTypes>>(tx: PrismaCompatTransactionClient<S>): TransactionClient;
|
|
509
|
+
export declare function turbineOf(compat: object): TurbineClient | TransactionClient;
|
|
510
|
+
/**
|
|
511
|
+
* A compat transaction client running inside a core transaction this layer did
|
|
512
|
+
* not open: the other direction of {@link turbineOf}. Code already on Turbine's API
|
|
513
|
+
* opens `db.$transaction(async (core) => ...)` and calls into a module still
|
|
514
|
+
* written against the Prisma surface with `bindTransaction(prisma, core)`; every
|
|
515
|
+
* delegate call and raw statement on the result runs on `core`'s connection and
|
|
516
|
+
* commits or rolls back with it. The result has the same members as the `tx` of
|
|
517
|
+
* a compat `$transaction` callback (delegates, extension `model` members, the
|
|
518
|
+
* raw surface), and no `$transaction` of its own, as in Prisma.
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* ```ts
|
|
522
|
+
* await db.$transaction(async (core) => {
|
|
523
|
+
* await core.table('users').update({ where: { id }, data: { name } });
|
|
524
|
+
* await legacyAudit(bindTransaction(prisma, core)); // still prisma.auditLog.create(...)
|
|
525
|
+
* });
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
export declare function bindTransaction<S extends Record<string, PrismaModelTypes>>(compat: PrismaCompatClient<S>, tx: TransactionClient): PrismaCompatTransactionClient<S>;
|
|
529
|
+
export declare function bindTransaction(compat: object, tx: TransactionClient): PrismaCompatTransactionClient;
|
|
438
530
|
/** @internal Names on a compat client that are NOT model delegates. */
|
|
439
531
|
export declare const CLIENT_RESERVED_KEYS: ReadonlySet<string>;
|
|
440
532
|
/**
|