@jcbuisson/express-x 1.3.5 → 1.3.7
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.
- package/package.json +2 -2
- package/src/common-hooks.mjs +1 -1
- package/src/server.mjs +3 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jcbuisson/express-x",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.mjs",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@jcbuisson/express-x-client": "^1.0.10",
|
|
22
22
|
"@prisma/client": "^4.10.1",
|
|
23
23
|
"axios": "^1.4.0",
|
|
24
|
-
"
|
|
24
|
+
"bcryptjs": "^2.4.3",
|
|
25
25
|
"config": "^3.3.9",
|
|
26
26
|
"express": "^4.18.2",
|
|
27
27
|
"socket.io": "^4.6.0"
|
package/src/common-hooks.mjs
CHANGED
package/src/server.mjs
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
import http from 'http'
|
|
3
3
|
import { Server } from "socket.io"
|
|
4
4
|
import express from 'express'
|
|
5
|
-
import { PrismaClient } from '@prisma/client'
|
|
6
5
|
|
|
7
6
|
/*
|
|
8
7
|
* Enhance `app` express application with services and real-time features
|
|
9
8
|
*/
|
|
10
|
-
export function expressX(options = {}) {
|
|
9
|
+
export function expressX(prisma, options = {}) {
|
|
11
10
|
|
|
12
11
|
const app = express()
|
|
12
|
+
app.set('prisma', prisma)
|
|
13
13
|
|
|
14
14
|
if (options.ws === undefined) options.ws = { ws_prefix: "expressx" }
|
|
15
15
|
|
|
@@ -28,13 +28,6 @@ export function expressX(options = {}) {
|
|
|
28
28
|
* create a service `name` based on Prisma table `entity`
|
|
29
29
|
*/
|
|
30
30
|
function createDatabaseService(name, prismaOptions = { entity: name }) {
|
|
31
|
-
|
|
32
|
-
let prisma = app.get('prisma')
|
|
33
|
-
if (!prisma) {
|
|
34
|
-
prisma = new PrismaClient()
|
|
35
|
-
app.set('prisma', prisma)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
31
|
// take all prisma methods on `entity` table
|
|
39
32
|
const methods = prisma[prismaOptions.entity]
|
|
40
33
|
|
|
@@ -74,7 +67,7 @@ export function expressX(options = {}) {
|
|
|
74
67
|
|
|
75
68
|
// call method
|
|
76
69
|
const result = await method(...context.args)
|
|
77
|
-
app.log('debug',
|
|
70
|
+
app.log('debug', 'result ' + JSON.stringify(result))
|
|
78
71
|
|
|
79
72
|
// call 'after' hooks
|
|
80
73
|
const afterMethodHooks = service?.hooks?.after && service.hooks.after[methodName] || []
|