@jayfong/x-server 2.1.2 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,12 +16,26 @@ function makeBaseModel<TModelName extends ModelName>(name: TModelName) {
16
16
  return class BaseModel {
17
17
  public query = prismaClient[name]
18
18
 
19
+ public transactionClient: Prisma.TransactionClient | null = null
20
+
19
21
  public transactionify = (tx: Prisma.TransactionClient) => {
20
22
  // @ts-ignore
21
23
  return new (class extends this.constructor {
22
24
  public query = tx[name]
25
+
26
+ public transactionClient = tx
23
27
  })() as typeof this
24
28
  }
29
+
30
+ public getModel = <T extends ModelName>(
31
+ name: T,
32
+ ): typeof import('../../src/models')[`${T}Model`] => {
33
+ return this.transactionClient
34
+ ? require('../../src/models')[`${name}Model`].transactionify(
35
+ this.transactionClient,
36
+ )
37
+ : require('../../src/models')[`${name}Model`]
38
+ }
25
39
  }
26
40
  }
27
41
 
@@ -16,12 +16,26 @@ function makeBaseModel<TModelName extends ModelName>(name: TModelName) {
16
16
  return class BaseModel {
17
17
  public query = prismaClient[name]
18
18
 
19
+ public transactionClient: Prisma.TransactionClient | null = null
20
+
19
21
  public transactionify = (tx: Prisma.TransactionClient) => {
20
22
  // @ts-ignore
21
23
  return new (class extends this.constructor {
22
24
  public query = tx[name]
25
+
26
+ public transactionClient = tx
23
27
  })() as typeof this
24
28
  }
29
+
30
+ public getModel = <T extends ModelName>(
31
+ name: T,
32
+ ): typeof import('../../src/models')[`${T}Model`] => {
33
+ return this.transactionClient
34
+ ? require('../../src/models')[`${name}Model`].transactionify(
35
+ this.transactionClient,
36
+ )
37
+ : require('../../src/models')[`${name}Model`]
38
+ }
25
39
  }
26
40
  }
27
41
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",