/
PrismaPromise.ts
59 lines (51 loc) · 2 KB
/
PrismaPromise.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { IsolationLevel } from '@prisma/engine-core'
export type PrismaPromiseBatchTransaction = {
kind: 'batch'
id: number
isolationLevel?: IsolationLevel
}
export type PrismaPromiseInteractiveTransaction = {
kind: 'itx'
id: string
}
export type PrismaPromiseTransaction = PrismaPromiseBatchTransaction | PrismaPromiseInteractiveTransaction
export type BatchTransactionOptions = Omit<PrismaPromiseBatchTransaction, 'kind'>
export type InteractiveTransactionOptions = Omit<PrismaPromiseInteractiveTransaction, 'kind'>
/**
* Prisma's `Promise` that is backwards-compatible. All additions on top of the
* original `Promise` are optional so that it can be backwards-compatible.
* @see [[createPrismaPromise]]
*/
export interface PrismaPromise<A> extends Promise<A> {
/**
* Extension of the original `.then` function
* @param onfulfilled same as regular promises
* @param onrejected same as regular promises
* @param transaction interactive transaction options
*/
then<R1 = A, R2 = never>(
onfulfilled?: (value: A) => R1 | PromiseLike<R1>,
onrejected?: (error: unknown) => R2 | PromiseLike<R2>,
transaction?: InteractiveTransactionOptions,
): Promise<R1 | R2>
/**
* Extension of the original `.catch` function
* @param onrejected same as regular promises
* @param transaction interactive transaction options
*/
catch<R = never>(
onrejected?: ((reason: any) => R | PromiseLike<R>) | undefined | null,
transaction?: InteractiveTransactionOptions,
): Promise<A | R>
/**
* Extension of the original `.finally` function
* @param onfinally same as regular promises
* @param transaction interactive transaction options
*/
finally(onfinally?: (() => void) | undefined | null, transaction?: InteractiveTransactionOptions): Promise<A>
/**
* Called when executing a batch of regular tx
* @param transaction transaction options for regular tx
*/
requestTransaction?(transaction: BatchTransactionOptions, lock?: PromiseLike<void>): PromiseLike<unknown>
}