forked from EvolutionAPI/evolution-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextendsWithProxy.ts
More file actions
27 lines (23 loc) · 851 Bytes
/
extendsWithProxy.ts
File metadata and controls
27 lines (23 loc) · 851 Bytes
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
import { PrismaClient } from '@prisma/client';
type ExtensionArgs = Parameters<PrismaClient['$extends']>[0];
export function extendsWithProxy<T extends PrismaClient>(
instanciaBase: T,
extensao: ExtensionArgs
): T {
const instanciaEstendida = instanciaBase.$extends(extensao);
const proxy = new Proxy(instanciaBase as unknown as object, {
get(target, prop, receiver) {
if (prop === 'toString') {
return () => '[Proxy toString]';
}
if (prop === Symbol.toStringTag) {
return undefined;
}
return prop in instanciaEstendida ? Reflect.get(instanciaEstendida as any, prop, receiver) : Reflect.get(target, prop, receiver);
},
has(target, prop) {
return prop in target || prop in (instanciaEstendida as any);
},
});
return proxy as unknown as T;
}