|
1 | 1 | import { Injectable, OnModuleDestroy } from '@nestjs/common';
|
2 | 2 | import { AsyncLocalStorage } from 'async_hooks';
|
3 |
| -import { EdgeDBError, Executor, Session } from 'edgedb'; |
4 |
| -import { getPreviousList, ServerException } from '~/common'; |
5 |
| -import { OptionsContext } from './options.context'; |
| 3 | +import { EdgeDBError, Executor } from 'edgedb'; |
| 4 | +import { getPreviousList } from '~/common'; |
6 | 5 | import { Client } from './reexports';
|
7 | 6 |
|
8 | 7 | @Injectable()
|
9 | 8 | export class TransactionContext
|
10 | 9 | extends AsyncLocalStorage<Executor>
|
11 | 10 | implements OnModuleDestroy
|
12 | 11 | {
|
13 |
| - constructor( |
14 |
| - private readonly client: Client, |
15 |
| - private readonly optionsContext: OptionsContext, |
16 |
| - ) { |
| 12 | + constructor(private readonly client: Client) { |
17 | 13 | super();
|
18 | 14 | }
|
19 | 15 |
|
20 | 16 | async inTx<R>(fn: () => Promise<R>): Promise<R> {
|
21 | 17 | const errorMap = new WeakMap<Error, Error>();
|
22 | 18 |
|
23 |
| - const txSession = this.optionsContext.current.session; |
24 |
| - |
25 | 19 | try {
|
26 | 20 | return await this.client.transaction(async (tx) => {
|
27 |
| - const txx = new Proxy(tx, { |
28 |
| - get: (target: typeof tx, p: string, receiver: any) => { |
29 |
| - const current = this.optionsContext.current.session; |
30 |
| - ensureCompatibleSession(txSession, current); |
31 |
| - return Reflect.get(target, p, receiver); |
32 |
| - }, |
33 |
| - }); |
34 |
| - |
35 | 21 | try {
|
36 |
| - return await this.run(txx, fn); |
| 22 | + return await this.run(tx, fn); |
37 | 23 | } catch (error) {
|
38 | 24 | // If the error "wraps" an EdgeDB error, then
|
39 | 25 | // throw that here and save the original.
|
@@ -63,17 +49,3 @@ export class TransactionContext
|
63 | 49 | this.disable();
|
64 | 50 | }
|
65 | 51 | }
|
66 |
| - |
67 |
| -function ensureCompatibleSession(txSession: Session, current: Session) { |
68 |
| - // This should work, but is bugged right now. |
69 |
| - // https://github.com/edgedb/edgedb/issues/7138 |
70 |
| - // It's hard to reason about, so I'm making sure it errors loud. |
71 |
| - if ( |
72 |
| - txSession.config.apply_access_policies !== |
73 |
| - current.config.apply_access_policies |
74 |
| - ) { |
75 |
| - throw new ServerException( |
76 |
| - 'Access policies cannot be toggled within a transaction', |
77 |
| - ); |
78 |
| - } |
79 |
| -} |
0 commit comments