@jcbuisson/express-x 1.6.0 → 1.6.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.
package/README.md CHANGED
@@ -102,8 +102,8 @@ node app.js
102
102
 
103
103
  It prints the following lines in the console:
104
104
  ```bash
105
- created service 'user' over table 'User'
106
- created service 'post' over table 'Post'
105
+ created service 'user' over entity 'User'
106
+ created service 'post' over entity 'Post'
107
107
  added HTTP endpoints for service 'user' at path '/api/user'
108
108
  added HTTP endpoints for service 'post' at path '/api/post'
109
109
  App listening at http://localhost:8000
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcbuisson/express-x",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",
package/src/server.mjs CHANGED
@@ -16,6 +16,7 @@ export function expressX(prisma, options = {}) {
16
16
  let appHooks = []
17
17
 
18
18
  const cnx2Socket = {}
19
+ const cnx2Timer = {}
19
20
 
20
21
  async function createConnection(clientIP) {
21
22
  const connection = await prisma.Connection.create({
@@ -49,6 +50,23 @@ export function expressX(prisma, options = {}) {
49
50
  }
50
51
  }
51
52
 
53
+ function getSocket(connectionId) {
54
+ return cnx2Socket[connectionId]
55
+ }
56
+
57
+ function setSocket(connectionId, socket) {
58
+ cnx2Socket[connectionId] = socket
59
+ }
60
+
61
+
62
+ function getTimer(connectionId) {
63
+ return cnx2Timer[connectionId]
64
+ }
65
+
66
+ function setTimer(connectionId, timer) {
67
+ cnx2Timer[connectionId] = timer
68
+ }
69
+
52
70
 
53
71
  // logging function - a winston logger must be configured first
54
72
  app.log = (severity, message) => {
@@ -126,7 +144,7 @@ export function expressX(prisma, options = {}) {
126
144
  for (const connection of connectionList) {
127
145
  const trimmedResult = result ? JSON.stringify(result).slice(0, 300) : ''
128
146
  app.log('verbose', `emit to ${connection.id} ${service.name} ${methodName} ${trimmedResult}`)
129
- const socket = cnx2Socket[connection.id]
147
+ const socket = getSocket(connection.id)
130
148
  // emit service event
131
149
  socket && socket.emit('service-event', {
132
150
  name: service.name,
@@ -136,18 +154,11 @@ export function expressX(prisma, options = {}) {
136
154
  }
137
155
  }
138
156
  }
139
-
140
- // AD-HOC, FOR SESSION EXPIRATION
141
- // emit application event, if any, only to the calling cllient (no pub/sub)
142
- if (context.appEvent) {
143
- const socket = cnx2Socket[context?.params?.connectionId]
144
- socket && socket.emit('app-event', context.appEvent)
145
- }
146
157
 
147
158
  return context.result
148
159
  }
149
160
 
150
- // TODO: NOT CLEAR, CREATE ISSUES
161
+ // TODO: NOT CLEAR AND PROBABLY USELESS
151
162
  // hooked version of method: `create`, etc., to be called from backend with no context
152
163
  service[methodName] = method
153
164
  // un-hooked version of method: `_create`, etc., to be called from backend with no context
@@ -321,7 +332,7 @@ export function expressX(prisma, options = {}) {
321
332
  const connection = await createConnection(clientIP)
322
333
  app.log('verbose', `Client connected ${connection.id} from IP ${clientIP}`)
323
334
 
324
- cnx2Socket[connection.id] = socket
335
+ setSocket(connection.id, socket)
325
336
 
326
337
  // emit 'connection' event for app (expressjs extends EventEmitter)
327
338
  console.log('EMIT CONNECTION')
@@ -352,7 +363,7 @@ export function expressX(prisma, options = {}) {
352
363
  const fromConnection = await getConnection(from)
353
364
  if (!fromConnection) return
354
365
  await cloneConnection(to, fromConnection)
355
- cnx2Socket[to] = socket
366
+ setSocket(to, socket)
356
367
  await deleteConnection(from)
357
368
  // send acknowledge to client
358
369
  io.emit('cnx-transfer-ack', to)
@@ -436,7 +447,8 @@ export function expressX(prisma, options = {}) {
436
447
  return Object.assign(app, {
437
448
  prisma,
438
449
  options,
439
- cnx2Socket,
450
+ getSocket, setSocket,
451
+ getTimer, setTimer,
440
452
  createDatabaseService,
441
453
  createService,
442
454
  service,