@jcbuisson/express-x 1.3.3 → 1.3.4

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 +20 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcbuisson/express-x",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",
package/src/server.mjs CHANGED
@@ -19,9 +19,9 @@ export function expressX(options = {}) {
19
19
  let lastConnectionId = 1
20
20
 
21
21
  // logging function - a winston logger must be configured first
22
- app.log = (severity, ...messages) => {
22
+ app.log = (severity, message) => {
23
23
  const logger = app.get('logger')
24
- if (logger) logger.log(severity, ...messages)
24
+ if (logger) logger.log(severity, message)
25
25
  }
26
26
 
27
27
  /*
@@ -74,7 +74,7 @@ export function expressX(options = {}) {
74
74
 
75
75
  // call method
76
76
  const result = await method(...context.args)
77
- app.log('debug', 'result', result)
77
+ app.log('debug', `result ${result}`)
78
78
 
79
79
  // call 'after' hooks
80
80
  const afterMethodHooks = service?.hooks?.after && service.hooks.after[methodName] || []
@@ -152,20 +152,20 @@ export function expressX(options = {}) {
152
152
 
153
153
 
154
154
  app.post(path, async (req, res) => {
155
- app.log('verbose', "http request POST", req.url)
155
+ app.log('verbose', `http request POST ${req.url}`)
156
156
  context.http.req = req
157
157
  try {
158
158
  const value = await service.__create(context, { data: req.body })
159
159
  publish(service, 'create', value)
160
160
  res.json(value)
161
161
  } catch(err) {
162
- console.log('callErr', err)
162
+ app.log('error', err)
163
163
  res.status(500).send(err.toString())
164
164
  }
165
165
  })
166
166
 
167
167
  app.get(path, async (req, res) => {
168
- app.log('verbose', "http request GET", req.url)
168
+ app.log('verbose', `http request GET ${req.url}`)
169
169
  context.http.req = req
170
170
  const query = { ...req.query }
171
171
  try {
@@ -195,13 +195,13 @@ export function expressX(options = {}) {
195
195
  publish(service, 'findMany', values)
196
196
  res.json(values)
197
197
  } catch(err) {
198
- console.log('callErr', err)
198
+ app.log('error', err)
199
199
  res.status(500).send(err.toString())
200
200
  }
201
201
  })
202
202
 
203
203
  app.get(`${path}/:id`, async (req, res) => {
204
- app.log('verbose', "http request GET", req.url)
204
+ app.log('verbose', `http request GET ${req.url}`)
205
205
  context.http.req = req
206
206
  try {
207
207
  const value = await service.__findUnique(context, {
@@ -212,13 +212,13 @@ export function expressX(options = {}) {
212
212
  publish(service, 'findUnique', value)
213
213
  res.json(value)
214
214
  } catch(err) {
215
- console.log('callErr', err)
215
+ app.log('error', err)
216
216
  res.status(500).send(err.toString())
217
217
  }
218
218
  })
219
219
 
220
220
  app.patch(`${path}/:id`, async (req, res) => {
221
- app.log('verbose', "http request PATCH", req.url)
221
+ app.log('verbose', `http request PATCH ${req.url}`)
222
222
  context.http.req = req
223
223
  try {
224
224
  const value = await service.__update(context, {
@@ -230,13 +230,13 @@ export function expressX(options = {}) {
230
230
  publish(service, 'update', value)
231
231
  res.json(value)
232
232
  } catch(err) {
233
- console.log('callErr', err)
233
+ app.log('error', err)
234
234
  res.status(500).send(err.toString())
235
235
  }
236
236
  })
237
237
 
238
238
  app.delete(`${path}/:id`, async (req, res) => {
239
- app.log('verbose', "http request DELETE", req.url)
239
+ app.log('verbose', `http request DELETE ${req.url}`)
240
240
  context.http.req = req
241
241
  try {
242
242
  const value = await service.__delete(context, {
@@ -247,7 +247,7 @@ export function expressX(options = {}) {
247
247
  publish(service, 'delete', value)
248
248
  res.json(value)
249
249
  } catch(err) {
250
- console.log('callErr', err)
250
+ app.log('error', err)
251
251
  res.status(500).send(err.toString())
252
252
  }
253
253
  })
@@ -275,7 +275,7 @@ export function expressX(options = {}) {
275
275
  }
276
276
  // store connection in cache
277
277
  connections[connection.id] = connection
278
- app.log('verbose', 'active connections', Object.keys(connections))
278
+ app.log('verbose', `active connections ${Object.keys(connections)}`)
279
279
 
280
280
  // emit 'connection' event for app (expressjs extends EventEmitter)
281
281
  app.emit('connection', connection)
@@ -284,7 +284,7 @@ export function expressX(options = {}) {
284
284
  socket.emit('connected', connection.id)
285
285
 
286
286
  socket.on('disconnect', () => {
287
- app.log('verbose', 'Client disconnected', connection.id)
287
+ app.log('verbose', `Client disconnected ${connection.id}`)
288
288
  delete connections[connection.id]
289
289
  })
290
290
 
@@ -294,7 +294,7 @@ export function expressX(options = {}) {
294
294
  * Emit in return a 'client-response' message
295
295
  */
296
296
  socket.on('client-request', async ({ uid, name, action, args }) => {
297
- app.log('verbose', "client-request", uid, name, action, args)
297
+ app.log('verbose', `client-request ${uid} ${name} ${action} ${args}`)
298
298
  if (name in services) {
299
299
  const service = services[name]
300
300
  try {
@@ -314,7 +314,7 @@ export function expressX(options = {}) {
314
314
  // pub/sub: send event on associated channels
315
315
  publish(service, action, result)
316
316
  } catch(err) {
317
- console.log('callErr', err)
317
+ app.log('error', err)
318
318
  io.emit('client-response', {
319
319
  uid,
320
320
  error: err.toString(),
@@ -347,12 +347,12 @@ export function expressX(options = {}) {
347
347
  const publishFunc = service.publishCallback
348
348
  if (publishFunc) {
349
349
  const channelNames = await publishFunc(result, app)
350
- app.log('verbose', 'publish channels', service.name, action, channelNames)
350
+ app.log('verbose', `publish channels ${service.name} ${action} ${channelNames}`)
351
351
  for (const channelName of channelNames) {
352
- app.log('verbose', 'service-event', service.name, action, channelName)
352
+ app.log('verbose', `service-event ${service.name} ${action} ${channelName}`)
353
353
  const connectionList = Object.values(connections).filter(cnx => cnx.channelNames.has(channelName))
354
354
  for (const connection of connectionList) {
355
- app.log('verbose', 'emit to', connection.id, service.name, action, result)
355
+ app.log('verbose', `emit to ${connection.id} ${service.name} ${action} ${result}`)
356
356
  connection.socket.emit('service-event', {
357
357
  name: service.name,
358
358
  action,