UNPKG

5.4 kBTypeScriptView Raw
1import { DMMF } from './dmmf-types';
2import { DatasourceOverwrite } from '@prisma/engine-core/dist/NodeEngine';
3import { Document } from './query';
4import { GeneratorConfig } from '@prisma/generator-helper/dist/types';
5import { Dataloader } from './Dataloader';
6export declare type ErrorFormat = 'pretty' | 'colorless' | 'minimal';
7export declare type Datasource = {
8 url?: string;
9};
10export declare type Datasources = Record<string, Datasource>;
11export interface PrismaClientOptions {
12 /**
13 * Overwrites the datasource url from your prisma.schema file
14 */
15 datasources?: Datasources;
16 /**
17 * @default "colorless"
18 */
19 errorFormat?: ErrorFormat;
20 /**
21 * @example
22 * \`\`\`
23 * // Defaults to stdout
24 * log: ['query', 'info', 'warn']
25 *
26 * // Emit as events
27 * log: [
28 * { emit: 'stdout', level: 'query' },
29 * { emit: 'stdout', level: 'info' },
30 * { emit: 'stdout', level: 'warn' }
31 * ]
32 * \`\`\`
33 * Read more in our [docs](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/logging#the-log-option).
34 */
35 log?: Array<LogLevel | LogDefinition>;
36 /**
37 * @internal
38 * You probably don't want to use this. \`__internal\` is used by internal tooling.
39 */
40 __internal?: {
41 debug?: boolean;
42 hooks?: Hooks;
43 useUds?: boolean;
44 engine?: {
45 cwd?: string;
46 binaryPath?: string;
47 endpoint?: string;
48 enableEngineDebugMode?: boolean;
49 };
50 };
51}
52export declare type HookParams = {
53 query: string;
54 path: string[];
55 rootField?: string;
56 typeName?: string;
57 document: any;
58 clientMethod: string;
59 args: any;
60};
61/**
62 * These options are being passed in to the middleware as "params"
63 */
64export declare type MiddlewareParams = {
65 model?: string;
66 action: Action;
67 args: any;
68 dataPath: string[];
69 runInTransaction: boolean;
70};
71/**
72 * The `T` type makes sure, that the `return proceed` is not forgotten in the middleware implementation
73 */
74export declare type Middleware<T = any> = (params: MiddlewareParams, next: (params: MiddlewareParams) => Promise<T>) => Promise<T>;
75export interface InternalRequestParams extends MiddlewareParams {
76 /**
77 * The original client method being called.
78 * Even though the rootField / operation can be changed,
79 * this method stays as it is, as it's what the user's
80 * code looks like
81 */
82 clientMethod: string;
83 callsite?: string;
84 headers?: Record<string, string>;
85}
86export declare type HookPoint = 'all' | 'engine';
87export declare type EngineMiddlewareParams = {
88 document: Document;
89 runInTransaction?: boolean;
90};
91export declare type AllHookArgs = {
92 params: HookParams;
93 fetch: (params: HookParams) => Promise<any>;
94};
95/**
96 * The `T` type makes sure, that the `return proceed` is not forgotten in the middleware implementation
97 */
98export declare type EngineMiddleware<T = any> = (params: EngineMiddlewareParams, next: (params: EngineMiddlewareParams) => Promise<T>) => Promise<T>;
99export declare type Hooks = {
100 beforeRequest?: (options: HookParams) => any;
101};
102export declare type LogLevel = 'info' | 'query' | 'warn' | 'error';
103export declare type LogDefinition = {
104 level: LogLevel;
105 emit: 'stdout' | 'event';
106};
107export declare type GetLogType<T extends LogLevel | LogDefinition> = T extends LogDefinition ? T['emit'] extends 'event' ? T['level'] : never : never;
108export declare type GetEvents<T extends Array<LogLevel | LogDefinition>> = GetLogType<T[0]> | GetLogType<T[1]> | GetLogType<T[2]>;
109export declare type QueryEvent = {
110 timestamp: Date;
111 query: string;
112 params: string;
113 duration: number;
114 target: string;
115};
116export declare type LogEvent = {
117 timestamp: Date;
118 message: string;
119 target: string;
120};
121export interface GetPrismaClientOptions {
122 document: DMMF.Document;
123 generator?: GeneratorConfig;
124 sqliteDatasourceOverrides?: DatasourceOverwrite[];
125 relativePath: string;
126 dirname: string;
127 clientVersion?: string;
128 engineVersion?: string;
129}
130export declare type Action = 'findOne' | 'findMany' | 'create' | 'update' | 'updateMany' | 'upsert' | 'delete' | 'deleteMany' | 'executeRaw' | 'queryRaw' | 'aggregate';
131export declare function getPrismaClient(config: GetPrismaClientOptions): any;
132export declare class PrismaClientFetcher {
133 prisma: any;
134 debug: boolean;
135 hooks: any;
136 dataloader: Dataloader<{
137 document: Document;
138 runInTransaction?: boolean;
139 headers?: Record<string, string>;
140 }>;
141 constructor(prisma: any, enableDebug?: boolean, hooks?: any);
142 request({ document, dataPath, rootField, typeName, isList, callsite, clientMethod, runInTransaction, showColors, engineHook, args, headers, }: {
143 document: Document;
144 dataPath: string[];
145 rootField: string;
146 typeName: string;
147 isList: boolean;
148 clientMethod: string;
149 callsite?: string;
150 runInTransaction?: boolean;
151 showColors?: boolean;
152 engineHook?: EngineMiddleware;
153 args: any;
154 headers?: Record<string, string>;
155 }): Promise<any>;
156 sanitizeMessage(message: any): any;
157 unpack(document: any, data: any, path: any, rootField: any): any;
158}
159export declare function getOperation(action: DMMF.ModelAction): 'query' | 'mutation';