@prisma/security-rules 0.3.6
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 +222 -0
- package/assets/operation-rules.png +0 -0
- package/assets/rpc.png +0 -0
- package/assets/rule-engine.png +0 -0
- package/dist/index.cjs +1137 -0
- package/dist/index.d.cts +276 -0
- package/dist/index.d.ts +276 -0
- package/dist/index.js +1109 -0
- package/package.json +64 -0
package/dist/index.d.cts
ADDED
@@ -0,0 +1,276 @@
|
|
1
|
+
import * as _prisma_client_extension from '@prisma/client/extension';
|
2
|
+
import { Prisma as Prisma$1 } from '@prisma/client/extension';
|
3
|
+
import { Prisma } from '@prisma/client/scripts/default-index.js';
|
4
|
+
import * as _prisma_client_runtime_library from '@prisma/client/runtime/library';
|
5
|
+
import * as _prisma_extension_pulse_workerd from '@prisma/extension-pulse/workerd';
|
6
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
7
|
+
|
8
|
+
/// <reference lib="dom" />
|
9
|
+
|
10
|
+
interface PrismaCacheStrategy {
|
11
|
+
/**
|
12
|
+
* Specifies the caching parameters for Accelerate.
|
13
|
+
*
|
14
|
+
* `cacheStrategy` only applies when used with an Accelerate connection string.
|
15
|
+
*/
|
16
|
+
readonly cacheStrategy?: {
|
17
|
+
/**
|
18
|
+
* `swr` is short for Stale-While-Revalidate.
|
19
|
+
*
|
20
|
+
* `swr` defines the number of seconds that Accelerate may serve _stale_ cache data.
|
21
|
+
* _Stale_ data is a cache hit, but the cache will be refreshed in the background by Accelerate.
|
22
|
+
* The Prisma operation will not be blocked while data is refreshed.
|
23
|
+
*
|
24
|
+
* Use `swr` to reduce the latency of accessing the data while still maintaining
|
25
|
+
* a more up-to-date value in the Accelerate cache.
|
26
|
+
* `swr` without `ttl` will not reduce database load since Accelerate will
|
27
|
+
* run the query in the background.
|
28
|
+
*
|
29
|
+
* `swr` can be combined with `ttl`.
|
30
|
+
* `swr` applies **after** `ttl` has expired.
|
31
|
+
* The total number of seconds data will be cached is `ttl + swr`.
|
32
|
+
*
|
33
|
+
* `swr` only applies when used with an Accelerate connection string.
|
34
|
+
*/
|
35
|
+
readonly swr?: number;
|
36
|
+
/**
|
37
|
+
* `ttl` is short for Time-to-Live.
|
38
|
+
*
|
39
|
+
* `ttl` defines the number of seconds that Accelerate may serve _fresh_ cache data.
|
40
|
+
* _Fresh_ data is a cache hit and will not execute the query against the database.
|
41
|
+
*
|
42
|
+
* Use `ttl` to reduce database load and latency for data that does not
|
43
|
+
* require frequent updates.
|
44
|
+
* `ttl` without `swr` will incur a blocking database query for the first
|
45
|
+
* request after `ttl` expires.
|
46
|
+
*
|
47
|
+
* It's recommended to combine `ttl` and `swr` to maintain low latency while
|
48
|
+
* Accelerate refreshes cached data in the background.
|
49
|
+
* `swr` applies **after** `ttl` has expired.
|
50
|
+
* The total number of seconds data will be cached is `ttl + swr`.
|
51
|
+
*
|
52
|
+
* `ttl` only applies when used with an Accelerate connection string.
|
53
|
+
*/
|
54
|
+
readonly ttl?: number;
|
55
|
+
/**
|
56
|
+
* `tags` allow you to attach string values to the query's cache entry
|
57
|
+
* that can later be used to invalidate the cache.
|
58
|
+
*
|
59
|
+
* A tag may only contain alphanumeric characters and underscores.
|
60
|
+
* Each tag may contain a maximum of 64 characters.
|
61
|
+
* A maximum of 5 tags are allowed per query.
|
62
|
+
*/
|
63
|
+
readonly tags?: ReadonlyArray<string>;
|
64
|
+
};
|
65
|
+
}
|
66
|
+
interface AccelerateInfo {
|
67
|
+
/**
|
68
|
+
* The cache status of the response.
|
69
|
+
* * `ttl` indicates a cache hit within the `ttl` duration and no database query was executed
|
70
|
+
* * `swr` indicates a cache hit within the `swr` duration and the data is being refreshed by Accelerate in the background
|
71
|
+
* * `miss` indicates that both `ttl` and `swr` have expired and the database query was executed by the request
|
72
|
+
* * `none` indicates that no cache strategy was specified and the database query was executed by the request
|
73
|
+
*/
|
74
|
+
cacheStatus: "ttl" | "swr" | "miss" | "none";
|
75
|
+
/**
|
76
|
+
* The date the response was last refreshed.
|
77
|
+
*/
|
78
|
+
lastModified: Date;
|
79
|
+
/**
|
80
|
+
* The datacenter region that received the request.
|
81
|
+
*/
|
82
|
+
region: string;
|
83
|
+
/**
|
84
|
+
* Unique identifier of the request. Useful for troubleshooting.
|
85
|
+
*/
|
86
|
+
requestId: string;
|
87
|
+
/**
|
88
|
+
* The unique signature of the Prisma operation.
|
89
|
+
*/
|
90
|
+
signature: string;
|
91
|
+
}
|
92
|
+
type AccelerateInvalidateInput = {
|
93
|
+
/** Invalidate cache by tags set in the query `cacheStrategy`. */
|
94
|
+
tags: ReadonlyArray<string>;
|
95
|
+
};
|
96
|
+
interface AcceleratePromise<T> extends Prisma.PrismaPromise<T> {
|
97
|
+
withAccelerateInfo(): Prisma.PrismaPromise<{
|
98
|
+
data: T;
|
99
|
+
info: AccelerateInfo | null;
|
100
|
+
}>;
|
101
|
+
}
|
102
|
+
|
103
|
+
type CoerceAnyToNever<T> = unknown extends T ? never : T;
|
104
|
+
type CoerceNeverToValue<T, V> = [T] extends [never] ? V : T;
|
105
|
+
type ModelKeys<T> = {
|
106
|
+
[K in keyof T]: K extends `$${string}` ? never : K;
|
107
|
+
}[keyof T];
|
108
|
+
type Rules<C, Ctx extends StandardSchemaV1, AllModelKeys extends ModelKeys<C> = ModelKeys<C>> = {
|
109
|
+
[K in AllModelKeys]?: {
|
110
|
+
pulse?: PulseRuleShape<C, K, Ctx>;
|
111
|
+
read?: OpRuleShape<ReadOperation, C, K, Ctx>;
|
112
|
+
create?: OpRuleShape<CreateOperation, C, K, Ctx>;
|
113
|
+
delete?: OpRuleShape<DeleteOperation, C, K, Ctx>;
|
114
|
+
update?: OpRuleShape<UpdateOperation, C, K, Ctx>;
|
115
|
+
$allOperations?: OpRuleShape<Operation, C, K, Ctx>;
|
116
|
+
} | boolean;
|
117
|
+
} & {
|
118
|
+
$transaction?: boolean;
|
119
|
+
$allModels?: {
|
120
|
+
pulse?: AnyPulseRuleShape<Ctx>;
|
121
|
+
read?: AnyOpRuleShape<ReadOperation, Ctx>;
|
122
|
+
create?: AnyOpRuleShape<CreateOperation, Ctx>;
|
123
|
+
delete?: AnyOpRuleShape<DeleteOperation, Ctx>;
|
124
|
+
update?: AnyOpRuleShape<UpdateOperation, Ctx>;
|
125
|
+
$allOperations?: AnyOpRuleShape<Operation, Ctx>;
|
126
|
+
} | boolean;
|
127
|
+
};
|
128
|
+
/** <Pulse> */
|
129
|
+
/** <Pulse:Model> */
|
130
|
+
type PulseRuleShape<C, K extends keyof C, Ctx extends StandardSchemaV1> = boolean | PulseRuleShapeStatic<C, K> | PulseRuleShapeCallback<C, K, Ctx>;
|
131
|
+
type PulseWhere<C, K extends keyof C> = Partial<Pick<Prisma$1.Args<C[K], "findMany">["where"], keyof Prisma$1.Payload<C[K], "findMany">["scalars"]>>;
|
132
|
+
type PulseRuleShapeCallback<C, K extends keyof C, Ctx extends StandardSchemaV1> = {
|
133
|
+
(ctx: {
|
134
|
+
context: StandardSchemaV1.InferOutput<Ctx>;
|
135
|
+
action: "create" | "update" | "delete";
|
136
|
+
model: K;
|
137
|
+
}): MaybePromise<boolean | PulseRuleShapeStatic<C, K>>;
|
138
|
+
};
|
139
|
+
type PulseRuleShapeStatic<C, K extends keyof C, Where = PulseWhere<C, K>> = {
|
140
|
+
$select?: {
|
141
|
+
[K in keyof Where]: boolean;
|
142
|
+
};
|
143
|
+
$where?: Where;
|
144
|
+
};
|
145
|
+
/** </Pulse:Model> */
|
146
|
+
/** <Pulse:Any> */
|
147
|
+
type AnyPulseRuleShape<Ctx extends StandardSchemaV1> = boolean | AnyPulseRuleShapeStatic | AnyPulseRuleShapeCallback<Ctx>;
|
148
|
+
type AnyPulseRuleShapeCallback<Ctx extends StandardSchemaV1> = {
|
149
|
+
(ctx: {
|
150
|
+
context: StandardSchemaV1.InferOutput<Ctx>;
|
151
|
+
action: "create" | "update" | "delete";
|
152
|
+
}): MaybePromise<boolean | AnyPulseRuleShapeStatic>;
|
153
|
+
};
|
154
|
+
type AnyPulseRuleShapeStatic = {
|
155
|
+
$select?: Record<string, boolean>;
|
156
|
+
$where?: object;
|
157
|
+
};
|
158
|
+
/** </Pulse:Any> */
|
159
|
+
/** </Pulse> */
|
160
|
+
/** <Operation> */
|
161
|
+
type DeleteOperation = "delete" | "deleteMany";
|
162
|
+
type UpdateOperation = "update" | "updateMany" | "updateManyAndReturn" | "upsert";
|
163
|
+
type CreateOperation = "create" | "upsert" | "createMany" | "createManyAndReturn";
|
164
|
+
type ReadOperation = "aggregate" | "count" | "findFirst" | "findFirstOrThrow" | "findMany" | "findUnique" | "findUniqueOrThrow" | "groupBy";
|
165
|
+
type Operation = CreateOperation | DeleteOperation | UpdateOperation | ReadOperation;
|
166
|
+
/** <Operation:Model> */
|
167
|
+
type OpRuleShape<O extends Operation, C, K extends keyof C, Ctx extends StandardSchemaV1> = boolean | OpRuleShapeWhere<O, C, K> | OpRuleShapeCallback<O, C, K, Ctx> | OpRuleShapeVerbose<O, C, K, Ctx>;
|
168
|
+
type OpRuleShapeWhere<O extends Operation, C, K extends keyof C> = Prisma$1.Args<C[K], O> extends {
|
169
|
+
where?: infer W;
|
170
|
+
} ? {
|
171
|
+
$where: W;
|
172
|
+
$rule?: never;
|
173
|
+
} : never;
|
174
|
+
type OpCtx<O extends Operation, C, K extends keyof C, Ctx extends StandardSchemaV1> = K extends unknown ? O extends unknown ? {
|
175
|
+
model: K;
|
176
|
+
operation: O;
|
177
|
+
args: CoerceAnyToNever<Prisma$1.Args<C[K], O>>;
|
178
|
+
context: StandardSchemaV1.InferOutput<Ctx>;
|
179
|
+
uuid?: string;
|
180
|
+
} : never : never;
|
181
|
+
type OpRuleShapeCallback<O extends Operation, C, K extends keyof C, Ctx extends StandardSchemaV1> = {
|
182
|
+
(ctx: OpCtx<O, C, K, Ctx>): MaybePromise<boolean | OpRuleShapeWhere<O, C, K>>;
|
183
|
+
};
|
184
|
+
type OpRuleShapeBefore<O extends Operation, C, K extends keyof C, Ctx extends StandardSchemaV1> = {
|
185
|
+
(ctx: OpCtx<O, C, K, Ctx>): MaybePromise<void>;
|
186
|
+
};
|
187
|
+
type OpRuleShapeAfter<O extends Operation, C, K extends keyof C, Ctx extends StandardSchemaV1> = {
|
188
|
+
(ctx: OpCtx<O, C, K, Ctx> & {
|
189
|
+
result: unknown;
|
190
|
+
}): MaybePromise<void>;
|
191
|
+
};
|
192
|
+
type OpRuleShapeVerbose<O extends Operation, C, K extends keyof C, Ctx extends StandardSchemaV1> = {
|
193
|
+
$rule: boolean | OpRuleShapeWhere<O, C, K> | OpRuleShapeCallback<O, C, K, Ctx>;
|
194
|
+
$after?: OpRuleShapeAfter<O, C, K, Ctx>;
|
195
|
+
$before?: OpRuleShapeBefore<O, C, K, Ctx>;
|
196
|
+
$blockedFields?: FieldsOf<O, C, K>[];
|
197
|
+
$where?: never;
|
198
|
+
};
|
199
|
+
/** </Operation:Model> */
|
200
|
+
/** <Operation:Any> */
|
201
|
+
type AnyOpRuleShape<O extends Operation, Ctx extends StandardSchemaV1> = boolean | AnyOpRuleShapeCallback<O, Ctx> | AnyOpRuleShapeVerbose<O, Ctx>;
|
202
|
+
type AnyOpRuleShapeWhere = object;
|
203
|
+
type AnyOpCtx<O extends Operation, Ctx extends StandardSchemaV1> = {
|
204
|
+
model: string;
|
205
|
+
operation: O;
|
206
|
+
args: object;
|
207
|
+
context: StandardSchemaV1.InferOutput<Ctx>;
|
208
|
+
uuid?: string;
|
209
|
+
};
|
210
|
+
type AnyOpRuleShapeCallback<O extends Operation, Ctx extends StandardSchemaV1> = {
|
211
|
+
(ctx: AnyOpCtx<O, Ctx>): MaybePromise<boolean | AnyOpRuleShapeWhere>;
|
212
|
+
};
|
213
|
+
type AnyOpRuleShapeBefore<O extends Operation, Ctx extends StandardSchemaV1> = {
|
214
|
+
(ctx: AnyOpCtx<O, Ctx>): MaybePromise<void>;
|
215
|
+
};
|
216
|
+
type AnyOpRuleShapeAfter<O extends Operation, Ctx extends StandardSchemaV1> = {
|
217
|
+
(ctx: AnyOpCtx<O, Ctx> & {
|
218
|
+
result: unknown;
|
219
|
+
}): MaybePromise<void>;
|
220
|
+
};
|
221
|
+
type AnyOpRuleShapeVerbose<O extends Operation, Ctx extends StandardSchemaV1> = {
|
222
|
+
$rule: boolean | AnyOpRuleShapeCallback<O, Ctx>;
|
223
|
+
$after?: AnyOpRuleShapeAfter<O, Ctx>;
|
224
|
+
$before?: AnyOpRuleShapeBefore<O, Ctx>;
|
225
|
+
$blockedFields?: string[];
|
226
|
+
};
|
227
|
+
/** </Operation:Any> */
|
228
|
+
/** </Operation> */
|
229
|
+
type MaybePromise<T> = T | Promise<T>;
|
230
|
+
type FieldsOf<O extends Operation, C, K extends keyof C, P extends Record<string, unknown> = Prisma$1.Payload<C[K], O>> = CoerceNeverToValue<keyof P["scalars"] | keyof P["objects"] | keyof P["composites"], string>;
|
231
|
+
declare function withPolicy<C, const R extends Rules<C, CtxSchema>, CtxSchema extends StandardSchemaV1 = StandardSchemaV1>(args: {
|
232
|
+
contextSchema?: CtxSchema;
|
233
|
+
rules: R;
|
234
|
+
}): (prisma: C) => _prisma_client_extension.PrismaClientExtends<_prisma_client_runtime_library.InternalArgs<{}, {
|
235
|
+
$allModels: {
|
236
|
+
subscribe<TModel, TArgs>(this: TModel, args?: Prisma$1.Exact<TArgs, _prisma_extension_pulse_workerd.PulseSubscribeArgs<TModel>>): Promise<_prisma_extension_pulse_workerd.PulseSubscription<_prisma_extension_pulse_workerd.PulseResultType<_prisma_extension_pulse_workerd.Omit<TArgs, "name">, Prisma$1.Result<TModel, TArgs, "findFirstOrThrow">>>>;
|
237
|
+
stream<TModel_1, TArgs_1>(this: TModel_1, args?: Prisma$1.Exact<TArgs_1, _prisma_extension_pulse_workerd.PulseStreamArgs<TModel_1>>): Promise<_prisma_extension_pulse_workerd.PulseSubscription<_prisma_extension_pulse_workerd.PulseResultType<_prisma_extension_pulse_workerd.Omit<TArgs_1, "name">, Prisma$1.Result<TModel_1, TArgs_1, "findFirstOrThrow">>>>;
|
238
|
+
};
|
239
|
+
}, {}, {}> & _prisma_client_runtime_library.DefaultArgs & _prisma_client_runtime_library.InternalArgs<{}, {
|
240
|
+
$allModels: {
|
241
|
+
aggregate<T, A>(this: T, args: _prisma_client_runtime_library.Exact<A, _prisma_client_runtime_library.Args_3<T, "aggregate"> & PrismaCacheStrategy>): AcceleratePromise<_prisma_client_runtime_library.Result_2<T, A, "aggregate">>;
|
242
|
+
count<T_1, A_1>(this: T_1, args?: _prisma_client_runtime_library.Exact<A_1, _prisma_client_runtime_library.Args_3<T_1, "count"> & PrismaCacheStrategy> | undefined): AcceleratePromise<_prisma_client_runtime_library.Result_2<T_1, A_1, "count">>;
|
243
|
+
findFirst<T_2, A_2>(this: T_2, args?: _prisma_client_runtime_library.Exact<A_2, _prisma_client_runtime_library.Args_3<T_2, "findFirst"> & PrismaCacheStrategy> | undefined): AcceleratePromise<_prisma_client_runtime_library.Result_2<T_2, A_2, "findFirst"> | null>;
|
244
|
+
findFirstOrThrow<T_3, A_3>(this: T_3, args?: _prisma_client_runtime_library.Exact<A_3, _prisma_client_runtime_library.Args_3<T_3, "findFirstOrThrow"> & PrismaCacheStrategy> | undefined): AcceleratePromise<_prisma_client_runtime_library.Result_2<T_3, A_3, "findFirstOrThrow">>;
|
245
|
+
findMany<T_4, A_4>(this: T_4, args?: _prisma_client_runtime_library.Exact<A_4, _prisma_client_runtime_library.Args_3<T_4, "findMany"> & PrismaCacheStrategy> | undefined): AcceleratePromise<_prisma_client_runtime_library.Result_2<T_4, A_4, "findMany">>;
|
246
|
+
findUnique<T_5, A_5>(this: T_5, args: _prisma_client_runtime_library.Exact<A_5, _prisma_client_runtime_library.Args_3<T_5, "findUnique"> & PrismaCacheStrategy>): AcceleratePromise<_prisma_client_runtime_library.Result_2<T_5, A_5, "findUnique"> | null>;
|
247
|
+
findUniqueOrThrow<T_6, A_6>(this: T_6, args: _prisma_client_runtime_library.Exact<A_6, _prisma_client_runtime_library.Args_3<T_6, "findUniqueOrThrow"> & PrismaCacheStrategy>): AcceleratePromise<_prisma_client_runtime_library.Result_2<T_6, A_6, "findUniqueOrThrow">>;
|
248
|
+
groupBy<T_7, A_7>(this: T_7, args: _prisma_client_runtime_library.Exact<A_7, _prisma_client_runtime_library.Args_3<T_7, "groupBy"> & PrismaCacheStrategy>): AcceleratePromise<_prisma_client_runtime_library.Result_2<T_7, A_7, "groupBy">>;
|
249
|
+
};
|
250
|
+
}, {}, {
|
251
|
+
$accelerate: {
|
252
|
+
invalidate: (input: AccelerateInvalidateInput) => Promise<{
|
253
|
+
requestId: string;
|
254
|
+
}>;
|
255
|
+
};
|
256
|
+
}> & _prisma_client_runtime_library.InternalArgs<{}, {}, {}, {}> & _prisma_client_runtime_library.InternalArgs<{}, {}, {}, {
|
257
|
+
$policy: {
|
258
|
+
setGlobalContext(ctx: StandardSchemaV1.InferInput<CtxSchema>): void;
|
259
|
+
contextSchema: unknown;
|
260
|
+
rules: R;
|
261
|
+
};
|
262
|
+
}>> & {};
|
263
|
+
|
264
|
+
/**
|
265
|
+
* Allow only accessing the models on the client object.
|
266
|
+
*/
|
267
|
+
type KeepObjectsOnly<T> = {
|
268
|
+
[K in keyof T as K extends `$${string}` ? (K extends "$transaction" | "$policy" ? K : never) : K]: T[K];
|
269
|
+
};
|
270
|
+
type PolicyClient<T> = KeepObjectsOnly<T>;
|
271
|
+
declare const PolicyClient: new <T>(args: {
|
272
|
+
url?: string;
|
273
|
+
publicKey: string;
|
274
|
+
}) => PolicyClient<T>;
|
275
|
+
|
276
|
+
export { PolicyClient, withPolicy };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,276 @@
|
|
1
|
+
import * as _prisma_client_extension from '@prisma/client/extension';
|
2
|
+
import { Prisma as Prisma$1 } from '@prisma/client/extension';
|
3
|
+
import { Prisma } from '@prisma/client/scripts/default-index.js';
|
4
|
+
import * as _prisma_client_runtime_library from '@prisma/client/runtime/library';
|
5
|
+
import * as _prisma_extension_pulse_workerd from '@prisma/extension-pulse/workerd';
|
6
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
7
|
+
|
8
|
+
/// <reference lib="dom" />
|
9
|
+
|
10
|
+
interface PrismaCacheStrategy {
|
11
|
+
/**
|
12
|
+
* Specifies the caching parameters for Accelerate.
|
13
|
+
*
|
14
|
+
* `cacheStrategy` only applies when used with an Accelerate connection string.
|
15
|
+
*/
|
16
|
+
readonly cacheStrategy?: {
|
17
|
+
/**
|
18
|
+
* `swr` is short for Stale-While-Revalidate.
|
19
|
+
*
|
20
|
+
* `swr` defines the number of seconds that Accelerate may serve _stale_ cache data.
|
21
|
+
* _Stale_ data is a cache hit, but the cache will be refreshed in the background by Accelerate.
|
22
|
+
* The Prisma operation will not be blocked while data is refreshed.
|
23
|
+
*
|
24
|
+
* Use `swr` to reduce the latency of accessing the data while still maintaining
|
25
|
+
* a more up-to-date value in the Accelerate cache.
|
26
|
+
* `swr` without `ttl` will not reduce database load since Accelerate will
|
27
|
+
* run the query in the background.
|
28
|
+
*
|
29
|
+
* `swr` can be combined with `ttl`.
|
30
|
+
* `swr` applies **after** `ttl` has expired.
|
31
|
+
* The total number of seconds data will be cached is `ttl + swr`.
|
32
|
+
*
|
33
|
+
* `swr` only applies when used with an Accelerate connection string.
|
34
|
+
*/
|
35
|
+
readonly swr?: number;
|
36
|
+
/**
|
37
|
+
* `ttl` is short for Time-to-Live.
|
38
|
+
*
|
39
|
+
* `ttl` defines the number of seconds that Accelerate may serve _fresh_ cache data.
|
40
|
+
* _Fresh_ data is a cache hit and will not execute the query against the database.
|
41
|
+
*
|
42
|
+
* Use `ttl` to reduce database load and latency for data that does not
|
43
|
+
* require frequent updates.
|
44
|
+
* `ttl` without `swr` will incur a blocking database query for the first
|
45
|
+
* request after `ttl` expires.
|
46
|
+
*
|
47
|
+
* It's recommended to combine `ttl` and `swr` to maintain low latency while
|
48
|
+
* Accelerate refreshes cached data in the background.
|
49
|
+
* `swr` applies **after** `ttl` has expired.
|
50
|
+
* The total number of seconds data will be cached is `ttl + swr`.
|
51
|
+
*
|
52
|
+
* `ttl` only applies when used with an Accelerate connection string.
|
53
|
+
*/
|
54
|
+
readonly ttl?: number;
|
55
|
+
/**
|
56
|
+
* `tags` allow you to attach string values to the query's cache entry
|
57
|
+
* that can later be used to invalidate the cache.
|
58
|
+
*
|
59
|
+
* A tag may only contain alphanumeric characters and underscores.
|
60
|
+
* Each tag may contain a maximum of 64 characters.
|
61
|
+
* A maximum of 5 tags are allowed per query.
|
62
|
+
*/
|
63
|
+
readonly tags?: ReadonlyArray<string>;
|
64
|
+
};
|
65
|
+
}
|
66
|
+
interface AccelerateInfo {
|
67
|
+
/**
|
68
|
+
* The cache status of the response.
|
69
|
+
* * `ttl` indicates a cache hit within the `ttl` duration and no database query was executed
|
70
|
+
* * `swr` indicates a cache hit within the `swr` duration and the data is being refreshed by Accelerate in the background
|
71
|
+
* * `miss` indicates that both `ttl` and `swr` have expired and the database query was executed by the request
|
72
|
+
* * `none` indicates that no cache strategy was specified and the database query was executed by the request
|
73
|
+
*/
|
74
|
+
cacheStatus: "ttl" | "swr" | "miss" | "none";
|
75
|
+
/**
|
76
|
+
* The date the response was last refreshed.
|
77
|
+
*/
|
78
|
+
lastModified: Date;
|
79
|
+
/**
|
80
|
+
* The datacenter region that received the request.
|
81
|
+
*/
|
82
|
+
region: string;
|
83
|
+
/**
|
84
|
+
* Unique identifier of the request. Useful for troubleshooting.
|
85
|
+
*/
|
86
|
+
requestId: string;
|
87
|
+
/**
|
88
|
+
* The unique signature of the Prisma operation.
|
89
|
+
*/
|
90
|
+
signature: string;
|
91
|
+
}
|
92
|
+
type AccelerateInvalidateInput = {
|
93
|
+
/** Invalidate cache by tags set in the query `cacheStrategy`. */
|
94
|
+
tags: ReadonlyArray<string>;
|
95
|
+
};
|
96
|
+
interface AcceleratePromise<T> extends Prisma.PrismaPromise<T> {
|
97
|
+
withAccelerateInfo(): Prisma.PrismaPromise<{
|
98
|
+
data: T;
|
99
|
+
info: AccelerateInfo | null;
|
100
|
+
}>;
|
101
|
+
}
|
102
|
+
|
103
|
+
type CoerceAnyToNever<T> = unknown extends T ? never : T;
|
104
|
+
type CoerceNeverToValue<T, V> = [T] extends [never] ? V : T;
|
105
|
+
type ModelKeys<T> = {
|
106
|
+
[K in keyof T]: K extends `$${string}` ? never : K;
|
107
|
+
}[keyof T];
|
108
|
+
type Rules<C, Ctx extends StandardSchemaV1, AllModelKeys extends ModelKeys<C> = ModelKeys<C>> = {
|
109
|
+
[K in AllModelKeys]?: {
|
110
|
+
pulse?: PulseRuleShape<C, K, Ctx>;
|
111
|
+
read?: OpRuleShape<ReadOperation, C, K, Ctx>;
|
112
|
+
create?: OpRuleShape<CreateOperation, C, K, Ctx>;
|
113
|
+
delete?: OpRuleShape<DeleteOperation, C, K, Ctx>;
|
114
|
+
update?: OpRuleShape<UpdateOperation, C, K, Ctx>;
|
115
|
+
$allOperations?: OpRuleShape<Operation, C, K, Ctx>;
|
116
|
+
} | boolean;
|
117
|
+
} & {
|
118
|
+
$transaction?: boolean;
|
119
|
+
$allModels?: {
|
120
|
+
pulse?: AnyPulseRuleShape<Ctx>;
|
121
|
+
read?: AnyOpRuleShape<ReadOperation, Ctx>;
|
122
|
+
create?: AnyOpRuleShape<CreateOperation, Ctx>;
|
123
|
+
delete?: AnyOpRuleShape<DeleteOperation, Ctx>;
|
124
|
+
update?: AnyOpRuleShape<UpdateOperation, Ctx>;
|
125
|
+
$allOperations?: AnyOpRuleShape<Operation, Ctx>;
|
126
|
+
} | boolean;
|
127
|
+
};
|
128
|
+
/** <Pulse> */
|
129
|
+
/** <Pulse:Model> */
|
130
|
+
type PulseRuleShape<C, K extends keyof C, Ctx extends StandardSchemaV1> = boolean | PulseRuleShapeStatic<C, K> | PulseRuleShapeCallback<C, K, Ctx>;
|
131
|
+
type PulseWhere<C, K extends keyof C> = Partial<Pick<Prisma$1.Args<C[K], "findMany">["where"], keyof Prisma$1.Payload<C[K], "findMany">["scalars"]>>;
|
132
|
+
type PulseRuleShapeCallback<C, K extends keyof C, Ctx extends StandardSchemaV1> = {
|
133
|
+
(ctx: {
|
134
|
+
context: StandardSchemaV1.InferOutput<Ctx>;
|
135
|
+
action: "create" | "update" | "delete";
|
136
|
+
model: K;
|
137
|
+
}): MaybePromise<boolean | PulseRuleShapeStatic<C, K>>;
|
138
|
+
};
|
139
|
+
type PulseRuleShapeStatic<C, K extends keyof C, Where = PulseWhere<C, K>> = {
|
140
|
+
$select?: {
|
141
|
+
[K in keyof Where]: boolean;
|
142
|
+
};
|
143
|
+
$where?: Where;
|
144
|
+
};
|
145
|
+
/** </Pulse:Model> */
|
146
|
+
/** <Pulse:Any> */
|
147
|
+
type AnyPulseRuleShape<Ctx extends StandardSchemaV1> = boolean | AnyPulseRuleShapeStatic | AnyPulseRuleShapeCallback<Ctx>;
|
148
|
+
type AnyPulseRuleShapeCallback<Ctx extends StandardSchemaV1> = {
|
149
|
+
(ctx: {
|
150
|
+
context: StandardSchemaV1.InferOutput<Ctx>;
|
151
|
+
action: "create" | "update" | "delete";
|
152
|
+
}): MaybePromise<boolean | AnyPulseRuleShapeStatic>;
|
153
|
+
};
|
154
|
+
type AnyPulseRuleShapeStatic = {
|
155
|
+
$select?: Record<string, boolean>;
|
156
|
+
$where?: object;
|
157
|
+
};
|
158
|
+
/** </Pulse:Any> */
|
159
|
+
/** </Pulse> */
|
160
|
+
/** <Operation> */
|
161
|
+
type DeleteOperation = "delete" | "deleteMany";
|
162
|
+
type UpdateOperation = "update" | "updateMany" | "updateManyAndReturn" | "upsert";
|
163
|
+
type CreateOperation = "create" | "upsert" | "createMany" | "createManyAndReturn";
|
164
|
+
type ReadOperation = "aggregate" | "count" | "findFirst" | "findFirstOrThrow" | "findMany" | "findUnique" | "findUniqueOrThrow" | "groupBy";
|
165
|
+
type Operation = CreateOperation | DeleteOperation | UpdateOperation | ReadOperation;
|
166
|
+
/** <Operation:Model> */
|
167
|
+
type OpRuleShape<O extends Operation, C, K extends keyof C, Ctx extends StandardSchemaV1> = boolean | OpRuleShapeWhere<O, C, K> | OpRuleShapeCallback<O, C, K, Ctx> | OpRuleShapeVerbose<O, C, K, Ctx>;
|
168
|
+
type OpRuleShapeWhere<O extends Operation, C, K extends keyof C> = Prisma$1.Args<C[K], O> extends {
|
169
|
+
where?: infer W;
|
170
|
+
} ? {
|
171
|
+
$where: W;
|
172
|
+
$rule?: never;
|
173
|
+
} : never;
|
174
|
+
type OpCtx<O extends Operation, C, K extends keyof C, Ctx extends StandardSchemaV1> = K extends unknown ? O extends unknown ? {
|
175
|
+
model: K;
|
176
|
+
operation: O;
|
177
|
+
args: CoerceAnyToNever<Prisma$1.Args<C[K], O>>;
|
178
|
+
context: StandardSchemaV1.InferOutput<Ctx>;
|
179
|
+
uuid?: string;
|
180
|
+
} : never : never;
|
181
|
+
type OpRuleShapeCallback<O extends Operation, C, K extends keyof C, Ctx extends StandardSchemaV1> = {
|
182
|
+
(ctx: OpCtx<O, C, K, Ctx>): MaybePromise<boolean | OpRuleShapeWhere<O, C, K>>;
|
183
|
+
};
|
184
|
+
type OpRuleShapeBefore<O extends Operation, C, K extends keyof C, Ctx extends StandardSchemaV1> = {
|
185
|
+
(ctx: OpCtx<O, C, K, Ctx>): MaybePromise<void>;
|
186
|
+
};
|
187
|
+
type OpRuleShapeAfter<O extends Operation, C, K extends keyof C, Ctx extends StandardSchemaV1> = {
|
188
|
+
(ctx: OpCtx<O, C, K, Ctx> & {
|
189
|
+
result: unknown;
|
190
|
+
}): MaybePromise<void>;
|
191
|
+
};
|
192
|
+
type OpRuleShapeVerbose<O extends Operation, C, K extends keyof C, Ctx extends StandardSchemaV1> = {
|
193
|
+
$rule: boolean | OpRuleShapeWhere<O, C, K> | OpRuleShapeCallback<O, C, K, Ctx>;
|
194
|
+
$after?: OpRuleShapeAfter<O, C, K, Ctx>;
|
195
|
+
$before?: OpRuleShapeBefore<O, C, K, Ctx>;
|
196
|
+
$blockedFields?: FieldsOf<O, C, K>[];
|
197
|
+
$where?: never;
|
198
|
+
};
|
199
|
+
/** </Operation:Model> */
|
200
|
+
/** <Operation:Any> */
|
201
|
+
type AnyOpRuleShape<O extends Operation, Ctx extends StandardSchemaV1> = boolean | AnyOpRuleShapeCallback<O, Ctx> | AnyOpRuleShapeVerbose<O, Ctx>;
|
202
|
+
type AnyOpRuleShapeWhere = object;
|
203
|
+
type AnyOpCtx<O extends Operation, Ctx extends StandardSchemaV1> = {
|
204
|
+
model: string;
|
205
|
+
operation: O;
|
206
|
+
args: object;
|
207
|
+
context: StandardSchemaV1.InferOutput<Ctx>;
|
208
|
+
uuid?: string;
|
209
|
+
};
|
210
|
+
type AnyOpRuleShapeCallback<O extends Operation, Ctx extends StandardSchemaV1> = {
|
211
|
+
(ctx: AnyOpCtx<O, Ctx>): MaybePromise<boolean | AnyOpRuleShapeWhere>;
|
212
|
+
};
|
213
|
+
type AnyOpRuleShapeBefore<O extends Operation, Ctx extends StandardSchemaV1> = {
|
214
|
+
(ctx: AnyOpCtx<O, Ctx>): MaybePromise<void>;
|
215
|
+
};
|
216
|
+
type AnyOpRuleShapeAfter<O extends Operation, Ctx extends StandardSchemaV1> = {
|
217
|
+
(ctx: AnyOpCtx<O, Ctx> & {
|
218
|
+
result: unknown;
|
219
|
+
}): MaybePromise<void>;
|
220
|
+
};
|
221
|
+
type AnyOpRuleShapeVerbose<O extends Operation, Ctx extends StandardSchemaV1> = {
|
222
|
+
$rule: boolean | AnyOpRuleShapeCallback<O, Ctx>;
|
223
|
+
$after?: AnyOpRuleShapeAfter<O, Ctx>;
|
224
|
+
$before?: AnyOpRuleShapeBefore<O, Ctx>;
|
225
|
+
$blockedFields?: string[];
|
226
|
+
};
|
227
|
+
/** </Operation:Any> */
|
228
|
+
/** </Operation> */
|
229
|
+
type MaybePromise<T> = T | Promise<T>;
|
230
|
+
type FieldsOf<O extends Operation, C, K extends keyof C, P extends Record<string, unknown> = Prisma$1.Payload<C[K], O>> = CoerceNeverToValue<keyof P["scalars"] | keyof P["objects"] | keyof P["composites"], string>;
|
231
|
+
declare function withPolicy<C, const R extends Rules<C, CtxSchema>, CtxSchema extends StandardSchemaV1 = StandardSchemaV1>(args: {
|
232
|
+
contextSchema?: CtxSchema;
|
233
|
+
rules: R;
|
234
|
+
}): (prisma: C) => _prisma_client_extension.PrismaClientExtends<_prisma_client_runtime_library.InternalArgs<{}, {
|
235
|
+
$allModels: {
|
236
|
+
subscribe<TModel, TArgs>(this: TModel, args?: Prisma$1.Exact<TArgs, _prisma_extension_pulse_workerd.PulseSubscribeArgs<TModel>>): Promise<_prisma_extension_pulse_workerd.PulseSubscription<_prisma_extension_pulse_workerd.PulseResultType<_prisma_extension_pulse_workerd.Omit<TArgs, "name">, Prisma$1.Result<TModel, TArgs, "findFirstOrThrow">>>>;
|
237
|
+
stream<TModel_1, TArgs_1>(this: TModel_1, args?: Prisma$1.Exact<TArgs_1, _prisma_extension_pulse_workerd.PulseStreamArgs<TModel_1>>): Promise<_prisma_extension_pulse_workerd.PulseSubscription<_prisma_extension_pulse_workerd.PulseResultType<_prisma_extension_pulse_workerd.Omit<TArgs_1, "name">, Prisma$1.Result<TModel_1, TArgs_1, "findFirstOrThrow">>>>;
|
238
|
+
};
|
239
|
+
}, {}, {}> & _prisma_client_runtime_library.DefaultArgs & _prisma_client_runtime_library.InternalArgs<{}, {
|
240
|
+
$allModels: {
|
241
|
+
aggregate<T, A>(this: T, args: _prisma_client_runtime_library.Exact<A, _prisma_client_runtime_library.Args_3<T, "aggregate"> & PrismaCacheStrategy>): AcceleratePromise<_prisma_client_runtime_library.Result_2<T, A, "aggregate">>;
|
242
|
+
count<T_1, A_1>(this: T_1, args?: _prisma_client_runtime_library.Exact<A_1, _prisma_client_runtime_library.Args_3<T_1, "count"> & PrismaCacheStrategy> | undefined): AcceleratePromise<_prisma_client_runtime_library.Result_2<T_1, A_1, "count">>;
|
243
|
+
findFirst<T_2, A_2>(this: T_2, args?: _prisma_client_runtime_library.Exact<A_2, _prisma_client_runtime_library.Args_3<T_2, "findFirst"> & PrismaCacheStrategy> | undefined): AcceleratePromise<_prisma_client_runtime_library.Result_2<T_2, A_2, "findFirst"> | null>;
|
244
|
+
findFirstOrThrow<T_3, A_3>(this: T_3, args?: _prisma_client_runtime_library.Exact<A_3, _prisma_client_runtime_library.Args_3<T_3, "findFirstOrThrow"> & PrismaCacheStrategy> | undefined): AcceleratePromise<_prisma_client_runtime_library.Result_2<T_3, A_3, "findFirstOrThrow">>;
|
245
|
+
findMany<T_4, A_4>(this: T_4, args?: _prisma_client_runtime_library.Exact<A_4, _prisma_client_runtime_library.Args_3<T_4, "findMany"> & PrismaCacheStrategy> | undefined): AcceleratePromise<_prisma_client_runtime_library.Result_2<T_4, A_4, "findMany">>;
|
246
|
+
findUnique<T_5, A_5>(this: T_5, args: _prisma_client_runtime_library.Exact<A_5, _prisma_client_runtime_library.Args_3<T_5, "findUnique"> & PrismaCacheStrategy>): AcceleratePromise<_prisma_client_runtime_library.Result_2<T_5, A_5, "findUnique"> | null>;
|
247
|
+
findUniqueOrThrow<T_6, A_6>(this: T_6, args: _prisma_client_runtime_library.Exact<A_6, _prisma_client_runtime_library.Args_3<T_6, "findUniqueOrThrow"> & PrismaCacheStrategy>): AcceleratePromise<_prisma_client_runtime_library.Result_2<T_6, A_6, "findUniqueOrThrow">>;
|
248
|
+
groupBy<T_7, A_7>(this: T_7, args: _prisma_client_runtime_library.Exact<A_7, _prisma_client_runtime_library.Args_3<T_7, "groupBy"> & PrismaCacheStrategy>): AcceleratePromise<_prisma_client_runtime_library.Result_2<T_7, A_7, "groupBy">>;
|
249
|
+
};
|
250
|
+
}, {}, {
|
251
|
+
$accelerate: {
|
252
|
+
invalidate: (input: AccelerateInvalidateInput) => Promise<{
|
253
|
+
requestId: string;
|
254
|
+
}>;
|
255
|
+
};
|
256
|
+
}> & _prisma_client_runtime_library.InternalArgs<{}, {}, {}, {}> & _prisma_client_runtime_library.InternalArgs<{}, {}, {}, {
|
257
|
+
$policy: {
|
258
|
+
setGlobalContext(ctx: StandardSchemaV1.InferInput<CtxSchema>): void;
|
259
|
+
contextSchema: unknown;
|
260
|
+
rules: R;
|
261
|
+
};
|
262
|
+
}>> & {};
|
263
|
+
|
264
|
+
/**
|
265
|
+
* Allow only accessing the models on the client object.
|
266
|
+
*/
|
267
|
+
type KeepObjectsOnly<T> = {
|
268
|
+
[K in keyof T as K extends `$${string}` ? (K extends "$transaction" | "$policy" ? K : never) : K]: T[K];
|
269
|
+
};
|
270
|
+
type PolicyClient<T> = KeepObjectsOnly<T>;
|
271
|
+
declare const PolicyClient: new <T>(args: {
|
272
|
+
url?: string;
|
273
|
+
publicKey: string;
|
274
|
+
}) => PolicyClient<T>;
|
275
|
+
|
276
|
+
export { PolicyClient, withPolicy };
|