@jcbuisson/express-x 1.0.17 → 1.0.19

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.mjs +8 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcbuisson/express-x",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",
package/src/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
2
  import http from 'http'
3
3
  import { Server } from "socket.io"
4
+ import { PrismaClient } from '@prisma/client'
4
5
 
5
6
  /*
6
7
  * Enhance `app` express application with Feathers-like services
@@ -19,7 +20,11 @@ function expressX(app, options={}) {
19
20
  * create a service `name` based on Prisma table `entity`
20
21
  */
21
22
  function createDatabaseService(name, { entity=name, client='prisma' }) {
22
- const prisma = app.get('prisma')
23
+ let prisma = app.get('prisma')
24
+ if (!prisma) {
25
+ prisma = new PrismaClient()
26
+ app.set('prisma', prisma)
27
+ }
23
28
 
24
29
  const service = createService(name, {
25
30
  create: (data) => {
@@ -143,7 +148,7 @@ function expressX(app, options={}) {
143
148
  /*
144
149
  * add an HTTP REST endpoint at `path`, based on `service`
145
150
  */
146
- function addHttpRestRoutes(path, service) {
151
+ function addHttpRest(path, service) {
147
152
  const context = {
148
153
  app,
149
154
  http: { name: service.name }
@@ -300,7 +305,7 @@ function expressX(app, options={}) {
300
305
  createService,
301
306
  service,
302
307
  configure,
303
- addHttpRestRoutes,
308
+ addHttpRest,
304
309
  server,
305
310
  joinChannel,
306
311
  leaveChannel,