Skip to content

Commit a05bfca

Browse files
Castellanos, Eduard Andres (Colombia)Castellanos, Eduard Andres (Colombia)
authored andcommitted
feat(prisma): The code is formatted according to the style guide used
1 parent 6655ba6 commit a05bfca

4 files changed

Lines changed: 38 additions & 18 deletions

File tree

sdk_contrib/prisma/.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"extends": "../../.eslintrc.json"
2+
"extends": "../../.eslintrc.json"
33
}

sdk_contrib/prisma/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dev.db

sdk_contrib/prisma/src/index.ts

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ function captureFluid(
1717
const attr = obj[key as keyof PrismaPromise<any>];
1818
const actionKey = key.toString();
1919

20-
if (!prismaPromiseAttributes.has(actionKey) && typeof attr === 'function')
20+
if (
21+
!prismaPromiseAttributes.has(actionKey) &&
22+
typeof attr === 'function'
23+
) {
2124
return (...args: any[]) => {
2225
const res = attr.bind(obj)(...args);
2326
const isPromise = isPrismaPromise(res);
@@ -48,6 +51,7 @@ function captureFluid(
4851
}
4952
return res;
5053
};
54+
}
5155
callback?.();
5256

5357
return attr;
@@ -74,16 +78,20 @@ function captureActions(
7478
) {
7579
return (...args: any[]): any => {
7680
let segment = baseSegment;
77-
let lastArg: Subsegment | null = args[args.length - 1];
81+
const lastArg: Subsegment | null = args[args.length - 1];
7882

79-
if (AWSXRay.isAutomaticMode()) segment = AWSXRay.getSegment();
83+
if (AWSXRay.isAutomaticMode()) {
84+
segment = AWSXRay.getSegment();
85+
}
8086
if (lastArg instanceof Segment || lastArg instanceof Subsegment) {
8187
args = args.slice(0, -1);
8288
segment = lastArg;
8389
}
8490

8591
const call = () => attr.bind(obj)(...args);
86-
if (!segment) return call();
92+
if (!segment) {
93+
return call();
94+
}
8795

8896
const model = [modelPrefix, modelKey].filter(Boolean).join(divider);
8997
const actionSegment = segment.addNewSubsegment(
@@ -97,13 +105,9 @@ function captureActions(
97105
res.catch(e => {
98106
actionSegment.addError(e);
99107
});
100-
res.finally(() => {
101-
actionSegment.close();
102-
});
103108
promises.push(res);
104-
} else {
105-
actionSegment.close();
106109
}
110+
107111
const close = async () => {
108112
if (promises.length) {
109113
for (const promise of promises) {
@@ -112,8 +116,9 @@ function captureActions(
112116
});
113117
}
114118
}
115-
segment?.close();
119+
actionSegment?.close();
116120
};
121+
117122
if (isPromise) {
118123
const promiseFluid = captureFluid(res, {
119124
callback: promise => {
@@ -138,14 +143,22 @@ function captureModels(
138143
modelKey: string,
139144
{ segment, ...rest }: CommonOpts
140145
) {
141-
if (AWSXRay.isAutomaticMode()) segment = AWSXRay.resolveSegment(segment);
146+
if (AWSXRay.isAutomaticMode()) {
147+
segment = AWSXRay.resolveSegment(segment);
148+
}
149+
150+
if (!attr || attr instanceof Function) {
151+
return attr;
152+
}
142153

143154
return new Proxy(attr, {
144155
get(obj, prop) {
145156
const key = prop.toString();
146157
const attr = obj[key];
147158
if (isAction(key)) {
148-
if (AWSXRay.isAutomaticMode() && segment) AWSXRay.setSegment(segment);
159+
if (AWSXRay.isAutomaticMode() && segment) {
160+
AWSXRay.setSegment(segment);
161+
}
149162

150163
return captureActions(attr, obj, {
151164
segment,
@@ -171,16 +184,22 @@ export function capturePrisma<T extends PrismaClient>(
171184
} catch {
172185
// ignore
173186
}
174-
} else segment = baseSegment;
187+
} else {
188+
segment = baseSegment;
189+
}
175190
if (AWSXRay.isAutomaticMode()) {
176191
const ns = AWSXRay.getNamespace();
177192
return ns.runAndReturn(() => {
178-
if (segment) AWSXRay.setSegment(segment);
193+
if (segment) {
194+
AWSXRay.setSegment(segment);
195+
}
179196
return new Proxy(prisma, {
180197
get(obj, modelKey): any {
181198
const attr = obj[modelKey as keyof T];
182199
return ns.runAndReturn(() => {
183-
if (segment) AWSXRay.setSegment(segment);
200+
if (segment) {
201+
AWSXRay.setSegment(segment);
202+
}
184203
return captureModels(attr, modelKey.toString(), {
185204
segment,
186205
...rest,

sdk_contrib/prisma/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ const { ModelAction } = DMMF;
55

66
export const isAction = (action: any): action is keyof typeof ModelAction =>
77
!!ModelAction[action as keyof typeof ModelAction];
8-
export const isPrismaPromise = (res: any): res is PrismaPromise<any> =>
9-
res[Symbol.toStringTag] === 'PrismaPromise';
8+
export const isPrismaPromise = (res?: any): res is PrismaPromise<any> =>
9+
res?.[Symbol.toStringTag] === 'PrismaPromise';

0 commit comments

Comments
 (0)