@jayfong/x-server 2.1.1 → 2.1.2

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.
@@ -1,5 +1,5 @@
1
1
  import { x, HttpError } from '@jayfong/x-server'
2
- import { PrismaClient } from '@prisma/client'
2
+ import { PrismaClient, Prisma } from '@prisma/client'
3
3
 
4
4
  export const prismaClient = new PrismaClient({
5
5
  rejectOnNotFound: err => new HttpError.NotFound(err.message),
@@ -15,6 +15,13 @@ type ModelName =
15
15
  function makeBaseModel<TModelName extends ModelName>(name: TModelName) {
16
16
  return class BaseModel {
17
17
  public query = prismaClient[name]
18
+
19
+ public transactionify = (tx: Prisma.TransactionClient) => {
20
+ // @ts-ignore
21
+ return new (class extends this.constructor {
22
+ public query = tx[name]
23
+ })() as typeof this
24
+ }
18
25
  }
19
26
  }
20
27
 
@@ -1,5 +1,5 @@
1
1
  import { x, HttpError } from '@jayfong/x-server'
2
- import { PrismaClient } from '@prisma/client'
2
+ import { PrismaClient, Prisma } from '@prisma/client'
3
3
 
4
4
  export const prismaClient = new PrismaClient({
5
5
  rejectOnNotFound: err => new HttpError.NotFound(err.message),
@@ -15,6 +15,13 @@ type ModelName =
15
15
  function makeBaseModel<TModelName extends ModelName>(name: TModelName) {
16
16
  return class BaseModel {
17
17
  public query = prismaClient[name]
18
+
19
+ public transactionify = (tx: Prisma.TransactionClient) => {
20
+ // @ts-ignore
21
+ return new (class extends this.constructor {
22
+ public query = tx[name]
23
+ })() as typeof this
24
+ }
18
25
  }
19
26
  }
20
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",