-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.ts
87 lines (75 loc) · 2.36 KB
/
index.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
import 'react-native-url-polyfill/auto';
import { NativeModules } from 'react-native';
import { atob, btoa } from 'react-native-quick-base64';
global.atob = atob;
global.btoa = btoa;
export { reactiveHooksExtension } from './ReactiveHooksExtension';
export { reactiveQueriesExtension } from './ReactiveQueriesExtension';
declare global {
// eslint-disable-next-line no-var
var __PrismaProxy: PrismaProxy | undefined;
}
// @ts-expect-error
const isTurboModuleEnabled = global.__turboModuleProxy != null;
const PrismaModule = isTurboModuleEnabled
? require('./NativePrisma').default
: NativeModules.Prisma;
if (!PrismaModule) {
throw new Error('🟥 @prisma/react-native failed to initialize');
}
PrismaModule.install();
if (!global.__PrismaProxy) {
throw new Error('🟥 prisma/react-native C++ bindings failed to initialize');
}
// Wrap the create function to stringify the env variables if necessary
const ogCreate = __PrismaProxy!.create;
global.__PrismaProxy = {
...global.__PrismaProxy,
create: (options: PrismaCreateOptions): QueryEngineObject => {
if (typeof options.env !== 'string') {
options.env = JSON.stringify(options.env);
}
if (typeof options.datasourceOverrides !== 'string') {
options.datasourceOverrides = JSON.stringify(options.datasourceOverrides);
}
return ogCreate(options);
},
};
type PrismaCreateOptions = {
datamodel: string;
logLevel: string;
logQueries: boolean;
logCallback: (msg: string) => void;
ignoreEnvVarErrors: boolean;
datasourceOverrides: object | string;
env: object | string;
};
type QueryEngineObject = object;
type PrismaProxy = {
create: (options: PrismaCreateOptions) => QueryEngineObject;
connect: (engine: QueryEngineObject, trace: string) => void;
execute: (
engine: QueryEngineObject,
body: string,
headers: string,
txId: string
) => Promise<string>;
startTransaction: (
engine: QueryEngineObject,
body: string,
hdears: string
) => string;
commitTransaction: (
engine: QueryEngineObject,
txId: string,
headers: string
) => string;
rollbackTransaction: (
engine: QueryEngineObject,
txId: string,
headers: string
) => string;
disconnect: (engine: QueryEngineObject, headers: string) => void;
pushSchema: (engine: QueryEngineObject, schema: string) => void;
applyPendingMigrations: (engine: QueryEngineObject) => void;
};