UNPKG

2.97 kBTypeScriptView Raw
1/// <reference types="node" />
2import { Platform } from '@prisma/get-platform';
3import { GeneratorConfig } from '@prisma/generator-helper';
4import { RustLog, RustError } from './log';
5import { ChildProcessWithoutNullStreams } from 'child_process';
6export interface DatasourceOverwrite {
7 name: string;
8 url: string;
9}
10export interface EngineConfig {
11 cwd?: string;
12 datamodelPath: string;
13 debug?: boolean;
14 prismaPath?: string;
15 fetcher?: (query: string) => Promise<{
16 data?: any;
17 error?: any;
18 }>;
19 generator?: GeneratorConfig;
20 datasources?: DatasourceOverwrite[];
21 showColors?: boolean;
22 logQueries?: boolean;
23 logLevel?: 'info' | 'warn';
24 env?: Record<string, string>;
25 flags?: string[];
26}
27export declare type Deferred = {
28 resolve: () => void;
29 reject: (err: Error) => void;
30};
31export declare class NodeEngine {
32 private logEmitter;
33 private showColors;
34 private logQueries;
35 private logLevel?;
36 private env?;
37 private flags;
38 port?: number;
39 debug: boolean;
40 child?: ChildProcessWithoutNullStreams;
41 /**
42 * exiting is used to tell the .on('exit') hook, if the exit came from our script.
43 * As soon as the Prisma binary returns a correct return code (like 1 or 0), we don't need this anymore
44 */
45 exiting: boolean;
46 managementApiEnabled: boolean;
47 datamodelJson?: string;
48 cwd: string;
49 datamodelPath: string;
50 prismaPath?: string;
51 url: string;
52 ready: boolean;
53 stderrLogs: string;
54 stdoutLogs: string;
55 currentRequestPromise?: any;
56 cwdPromise: Promise<string>;
57 platformPromise: Promise<Platform>;
58 platform?: Platform | string;
59 generator?: GeneratorConfig;
60 incorrectlyPinnedPlatform?: string;
61 datasources?: DatasourceOverwrite[];
62 lastErrorLog?: RustLog;
63 lastError?: RustError;
64 startPromise?: Promise<any>;
65 engineStartDeferred?: Deferred;
66 constructor({ cwd, datamodelPath, prismaPath, generator, datasources, showColors, logLevel, logQueries, env, flags, ...args }: EngineConfig);
67 private resolveCwd;
68 on(event: 'query' | 'info' | 'warn', listener: (log: RustLog) => any): void;
69 getPlatform(): Promise<Platform>;
70 private getQueryEnginePath;
71 private handlePanic;
72 private resolvePrismaPath;
73 private getPrismaPath;
74 printDatasources(): string;
75 /**
76 * Starts the engine, returns the url that it runs on
77 */
78 start(): Promise<void>;
79 private internalStart;
80 fail: (e: any, why: any) => Promise<void>;
81 /**
82 * If Prisma runs, stop it
83 */
84 stop(): Promise<void>;
85 /**
86 * Use the port 0 trick to get a new port
87 */
88 protected getFreePort(): Promise<number>;
89 /**
90 * Make sure that our internal port is not conflicting with the prisma.yml's port
91 * @param str config
92 */
93 protected trimPort(str: string): string;
94 request<T>(queries: string[]): Promise<T>;
95 private graphQLToJSError;
96}