Skip to content

Commit 981980e

Browse files
committed
proxy $parent + more robust test
1 parent f55a2fd commit 981980e

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

packages/runtime/src/enhancements/node/proxy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export function makeProxy<T extends PrismaProxyHandler>(
289289
return propVal;
290290
}
291291

292-
return createHandlerProxy(makeHandler(target, prop), propVal, prop, target, errorTransformer);
292+
return createHandlerProxy(makeHandler(target, prop), propVal, prop, proxy, errorTransformer);
293293
},
294294
});
295295

@@ -308,7 +308,7 @@ function createHandlerProxy<T extends PrismaProxyHandler>(
308308
): T {
309309
return new Proxy(handler, {
310310
get(target, propKey) {
311-
if (propKey === '$zenstack_parent') {
311+
if (propKey === '$parent') {
312312
return dbOrTx;
313313
}
314314

tests/integration/tests/enhancements/proxy/extension-context.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,19 @@ describe('Proxy Extension Context', () => {
2222

2323
const db = enhance();
2424
const dbExtended = db.$extends({
25+
client: {
26+
$one() {
27+
return 1;
28+
}
29+
},
2530
model: {
2631
$allModels: {
2732
async createWithCounter(this: any, args: any) {
2833
const modelName = this.$name;
29-
const dbOrTx = this.$zenstack_parent;
34+
const dbOrTx = this.$parent;
35+
36+
// prisma exposes some internal properties, makes sure these are still preserved
37+
expect(dbOrTx._engine).toBeDefined();
3038

3139
const fn = async (tx: any) => {
3240
const counter = await tx.counter.findUnique({
@@ -35,8 +43,8 @@ describe('Proxy Extension Context', () => {
3543

3644
await tx.counter.upsert({
3745
where: { model: modelName },
38-
update: { value: (counter?.value ?? 0) + 1 },
39-
create: { model: modelName, value: 1 },
46+
update: { value: (counter?.value ?? 0) + tx.$one() },
47+
create: { model: modelName, value: tx.$one() },
4048
});
4149

4250
return tx[modelName].create(args);
@@ -62,7 +70,6 @@ describe('Proxy Extension Context', () => {
6270
),
6371
]);
6472

65-
// expecting object
6673
await expect(dbExtended.counter.findUniqueOrThrow({ where: { model: 'Address' } })).resolves.toMatchObject({
6774
model: 'Address',
6875
value: cities.length * 2,

0 commit comments

Comments
 (0)