-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathtypes.ts
210 lines (180 loc) · 5.54 KB
/
types.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { z } from 'zod';
import { FieldInfo } from './cross';
export type PrismaPromise<T> = Promise<T> & Record<string, (args?: any) => PrismaPromise<any>>;
/**
* Weakly-typed database access methods
*/
export interface DbOperations {
findMany(args?: unknown): Promise<any[]>;
findFirst(args?: unknown): PrismaPromise<any>;
findFirstOrThrow(args?: unknown): PrismaPromise<any>;
findUnique(args: unknown): PrismaPromise<any>;
findUniqueOrThrow(args: unknown): PrismaPromise<any>;
create(args: unknown): Promise<any>;
createMany(args: unknown): Promise<{ count: number }>;
createManyAndReturn(args: unknown): Promise<unknown[]>;
update(args: unknown): Promise<any>;
updateMany(args: unknown): Promise<{ count: number }>;
upsert(args: unknown): Promise<any>;
delete(args: unknown): Promise<any>;
deleteMany(args?: unknown): Promise<{ count: number }>;
aggregate(args: unknown): Promise<any>;
groupBy(args: unknown): Promise<any>;
count(args?: unknown): Promise<any>;
subscribe(args?: unknown): Promise<any>;
stream(args?: unknown): Promise<any>;
check(args: unknown): Promise<boolean>;
fields: Record<string, any>;
}
/**
* Kinds of access policy
*/
export type PolicyKind = 'allow' | 'deny';
export type PolicyCrudKind = 'read' | 'create' | 'update' | 'delete' | 'list';
/**
* Kinds of operations controlled by access policies
*/
export type PolicyOperationKind = PolicyCrudKind | 'postUpdate';
/**
* Current login user info
*/
export type AuthUser = Record<string, unknown>;
/**
* Context for database query
*/
export type QueryContext = {
/**
* Current login user (provided by @see RequestHandlerOptions)
*/
user?: AuthUser;
/**
* Pre-update value of the entity
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
preValue?: any;
};
/**
* Context for checking operation allowability.
*/
export type PermissionCheckerContext = {
/**
* Current user
*/
user?: AuthUser;
/**
* Extra field value filters.
*/
fieldValues?: Record<string, string | number | boolean>;
};
/**
* Prisma contract for CRUD operations.
*/
export type CrudContract = Record<string, DbOperations>;
/**
* Prisma contract for database client.
*/
export type DbClientContract = CrudContract & {
$transaction: <T>(action: (tx: CrudContract) => Promise<T>, options?: unknown) => Promise<T>;
};
/**
* Transaction isolation levels: https://www.prisma.io/docs/orm/prisma-client/queries/transactions#transaction-isolation-level
*/
export type TransactionIsolationLevel =
| 'ReadUncommitted'
| 'ReadCommitted'
| 'RepeatableRead'
| 'Snapshot'
| 'Serializable';
/**
* Options for enhancing a PrismaClient.
*/
export type EnhancementOptions = {
/**
* The kinds of enhancements to apply. By default all enhancements are applied.
*/
kinds?: EnhancementKind[];
/**
* Whether to log Prisma query
*/
logPrismaQuery?: boolean;
/**
* Hook for transforming errors before they are thrown to the caller.
*/
errorTransformer?: ErrorTransformer;
/**
* The `maxWait` option passed to `prisma.$transaction()` call for transactions initiated by ZenStack.
*/
transactionMaxWait?: number;
/**
* The `timeout` option passed to `prisma.$transaction()` call for transactions initiated by ZenStack.
*/
transactionTimeout?: number;
/**
* The `isolationLevel` option passed to `prisma.$transaction()` call for transactions initiated by ZenStack.
*/
transactionIsolationLevel?: TransactionIsolationLevel;
/**
* The encryption options for using the `encrypted` enhancement.
*/
encryption?: SimpleEncryption | CustomEncryption;
};
/**
* Context for creating enhanced `PrismaClient`
*/
export type EnhancementContext<User extends AuthUser = AuthUser> = {
user?: User;
};
/**
* Kinds of enhancements to `PrismaClient`
*/
export type EnhancementKind = 'password' | 'omit' | 'policy' | 'validation' | 'delegate' | 'encryption';
/**
* Function for transforming errors.
*/
export type ErrorTransformer = (error: unknown) => unknown;
/**
* Zod schemas for validation
*/
export type ZodSchemas = {
/**
* Zod schema for each model
*/
models: Record<string, z.ZodSchema>;
/**
* Zod schema for Prisma input types for each model
*/
input?: Record<string, Record<string, z.ZodSchema>>;
};
/**
* Simple encryption settings for processing fields marked with `@encrypted`.
*/
export type SimpleEncryption = {
/**
* The encryption key.
*/
encryptionKey: Uint8Array;
/**
* Optional list of all decryption keys that were previously used to encrypt the data
* , for supporting key rotation. The `encryptionKey` field value is automatically
* included for decryption.
*
* When the encrypted data is persisted, a metadata object containing the digest of the
* encryption key is stored alongside the data. This digest is used to quickly determine
* the correct decryption key to use when reading the data.
*/
decryptionKeys?: Uint8Array[];
};
/**
* Custom encryption settings for processing fields marked with `@encrypted`.
*/
export type CustomEncryption = {
/**
* Encryption function.
*/
encrypt: (model: string, field: FieldInfo, plain: string) => Promise<string>;
/**
* Decryption function
*/
decrypt: (model: string, field: FieldInfo, cipher: string) => Promise<string>;
};