@jcbuisson/express-x 1.6.0 → 1.6.1

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/server.mjs +13 -12
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.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",
package/src/server.mjs CHANGED
@@ -49,6 +49,14 @@ export function expressX(prisma, options = {}) {
49
49
  }
50
50
  }
51
51
 
52
+ function getSocket(connectionId) {
53
+ return cnx2Socket[connectionId]
54
+ }
55
+
56
+ function setSocket(connectionId, socket) {
57
+ cnx2Socket[connectionId] = socket
58
+ }
59
+
52
60
 
53
61
  // logging function - a winston logger must be configured first
54
62
  app.log = (severity, message) => {
@@ -126,7 +134,7 @@ export function expressX(prisma, options = {}) {
126
134
  for (const connection of connectionList) {
127
135
  const trimmedResult = result ? JSON.stringify(result).slice(0, 300) : ''
128
136
  app.log('verbose', `emit to ${connection.id} ${service.name} ${methodName} ${trimmedResult}`)
129
- const socket = cnx2Socket[connection.id]
137
+ const socket = getSocket(connection.id)
130
138
  // emit service event
131
139
  socket && socket.emit('service-event', {
132
140
  name: service.name,
@@ -136,18 +144,11 @@ export function expressX(prisma, options = {}) {
136
144
  }
137
145
  }
138
146
  }
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
147
 
147
148
  return context.result
148
149
  }
149
150
 
150
- // TODO: NOT CLEAR, CREATE ISSUES
151
+ // TODO: NOT CLEAR AND PROBABLY USELESS
151
152
  // hooked version of method: `create`, etc., to be called from backend with no context
152
153
  service[methodName] = method
153
154
  // un-hooked version of method: `_create`, etc., to be called from backend with no context
@@ -321,7 +322,7 @@ export function expressX(prisma, options = {}) {
321
322
  const connection = await createConnection(clientIP)
322
323
  app.log('verbose', `Client connected ${connection.id} from IP ${clientIP}`)
323
324
 
324
- cnx2Socket[connection.id] = socket
325
+ setSocket(connection.id, socket)
325
326
 
326
327
  // emit 'connection' event for app (expressjs extends EventEmitter)
327
328
  console.log('EMIT CONNECTION')
@@ -352,7 +353,7 @@ export function expressX(prisma, options = {}) {
352
353
  const fromConnection = await getConnection(from)
353
354
  if (!fromConnection) return
354
355
  await cloneConnection(to, fromConnection)
355
- cnx2Socket[to] = socket
356
+ setSocket(to, socket)
356
357
  await deleteConnection(from)
357
358
  // send acknowledge to client
358
359
  io.emit('cnx-transfer-ack', to)
@@ -436,7 +437,7 @@ export function expressX(prisma, options = {}) {
436
437
  return Object.assign(app, {
437
438
  prisma,
438
439
  options,
439
- cnx2Socket,
440
+ getSocket, setSocket,
440
441
  createDatabaseService,
441
442
  createService,
442
443
  service,