@jaypie/express 1.0.12 → 1.0.14

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/dist/module.cjs CHANGED
@@ -11,6 +11,7 @@ var serverlessExpress = require('@codegenie/serverless-express');
11
11
  const EXPRESS = {
12
12
  PATH: {
13
13
  ANY: "*",
14
+ ID: "/:id",
14
15
  ROOT: /^\/?$/,
15
16
  },
16
17
  };
@@ -167,14 +168,28 @@ function summarizeResponse(res, extras) {
167
168
  // Main
168
169
  //
169
170
 
170
- const expressHandler = (
171
- handler,
172
- { locals, name, setup = [], teardown = [], unavailable, validate } = {},
173
- ) => {
171
+ const expressHandler = (handler, options = {}) => {
172
+ // If handler is an object and options is a function, swap them
173
+ if (typeof handler === "object" && typeof options === "function") {
174
+ const temp = handler;
175
+ handler = options;
176
+ options = temp;
177
+ }
178
+
174
179
  //
175
180
  //
176
181
  // Validate
177
182
  //
183
+ /* eslint-disable no-autofix/prefer-const */
184
+ let {
185
+ locals,
186
+ name,
187
+ setup = [],
188
+ teardown = [],
189
+ unavailable,
190
+ validate,
191
+ } = options;
192
+ /* eslint-enable no-autofix/prefer-const */
178
193
  core.validate.function(handler);
179
194
  core.validate.optional.object(locals);
180
195
  setup = core.force.array(setup); // allows a single item
@@ -196,6 +211,11 @@ const expressHandler = (
196
211
  const libLogger = core.log.lib({
197
212
  lib: core.JAYPIE.LIB.EXPRESS,
198
213
  });
214
+ // Top-level, important details that run at the same level as the main logger
215
+ const log = core.log.lib({
216
+ level: core.log.level,
217
+ lib: core.JAYPIE.LIB.EXPRESS,
218
+ });
199
219
 
200
220
  // Update the public logger with the request ID
201
221
  const invokeUuid = getCurrentInvokeUuid();
@@ -205,15 +225,24 @@ const expressHandler = (
205
225
  // TODO: in theory this is redundant
206
226
  libLogger.tag({ invoke: invokeUuid });
207
227
  libLogger.tag({ shortInvoke: invokeUuid.slice(0, 8) });
228
+ log.tag({ invoke: invokeUuid });
229
+ log.tag({ shortInvoke: invokeUuid.slice(0, 8) });
208
230
  }
209
231
 
210
- libLogger.trace("[jaypie] Express init");
232
+ if (!name) {
233
+ // If handler has a name, use it
234
+ if (handler.name) {
235
+ name = handler.name;
236
+ } else {
237
+ name = core.JAYPIE.UNKNOWN;
238
+ }
239
+ }
240
+ core.log.tag({ handler: name });
241
+ // TODO: in theory this is redundant
242
+ libLogger.tag({ handler: name });
243
+ log.tag({ handler: name });
211
244
 
212
- // Top-level, important details that run at the same level as the main logger
213
- const log = core.log.lib({
214
- level: core.log.level,
215
- lib: core.JAYPIE.LIB.EXPRESS,
216
- });
245
+ libLogger.trace("[jaypie] Express init");
217
246
 
218
247
  // Set req.locals if it doesn't exist
219
248
  if (!req.locals) req.locals = {};
@@ -9,6 +9,7 @@ import { getCurrentInvoke } from '@codegenie/serverless-express';
9
9
  const EXPRESS = {
10
10
  PATH: {
11
11
  ANY: "*",
12
+ ID: "/:id",
12
13
  ROOT: /^\/?$/,
13
14
  },
14
15
  };
@@ -165,14 +166,28 @@ function summarizeResponse(res, extras) {
165
166
  // Main
166
167
  //
167
168
 
168
- const expressHandler = (
169
- handler,
170
- { locals, name, setup = [], teardown = [], unavailable, validate: validate$1 } = {},
171
- ) => {
169
+ const expressHandler = (handler, options = {}) => {
170
+ // If handler is an object and options is a function, swap them
171
+ if (typeof handler === "object" && typeof options === "function") {
172
+ const temp = handler;
173
+ handler = options;
174
+ options = temp;
175
+ }
176
+
172
177
  //
173
178
  //
174
179
  // Validate
175
180
  //
181
+ /* eslint-disable no-autofix/prefer-const */
182
+ let {
183
+ locals,
184
+ name,
185
+ setup = [],
186
+ teardown = [],
187
+ unavailable,
188
+ validate: validate$1,
189
+ } = options;
190
+ /* eslint-enable no-autofix/prefer-const */
176
191
  validate.function(handler);
177
192
  validate.optional.object(locals);
178
193
  setup = force.array(setup); // allows a single item
@@ -194,6 +209,11 @@ const expressHandler = (
194
209
  const libLogger = log.lib({
195
210
  lib: JAYPIE.LIB.EXPRESS,
196
211
  });
212
+ // Top-level, important details that run at the same level as the main logger
213
+ const log$1 = log.lib({
214
+ level: log.level,
215
+ lib: JAYPIE.LIB.EXPRESS,
216
+ });
197
217
 
198
218
  // Update the public logger with the request ID
199
219
  const invokeUuid = getCurrentInvokeUuid();
@@ -203,15 +223,24 @@ const expressHandler = (
203
223
  // TODO: in theory this is redundant
204
224
  libLogger.tag({ invoke: invokeUuid });
205
225
  libLogger.tag({ shortInvoke: invokeUuid.slice(0, 8) });
226
+ log$1.tag({ invoke: invokeUuid });
227
+ log$1.tag({ shortInvoke: invokeUuid.slice(0, 8) });
206
228
  }
207
229
 
208
- libLogger.trace("[jaypie] Express init");
230
+ if (!name) {
231
+ // If handler has a name, use it
232
+ if (handler.name) {
233
+ name = handler.name;
234
+ } else {
235
+ name = JAYPIE.UNKNOWN;
236
+ }
237
+ }
238
+ log.tag({ handler: name });
239
+ // TODO: in theory this is redundant
240
+ libLogger.tag({ handler: name });
241
+ log$1.tag({ handler: name });
209
242
 
210
- // Top-level, important details that run at the same level as the main logger
211
- const log$1 = log.lib({
212
- level: log.level,
213
- lib: JAYPIE.LIB.EXPRESS,
214
- });
243
+ libLogger.trace("[jaypie] Express init");
215
244
 
216
245
  // Set req.locals if it doesn't exist
217
246
  if (!req.locals) req.locals = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaypie/express",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "author": "Finlayson Studio",
5
5
  "type": "module",
6
6
  "exports": {
@@ -45,7 +45,7 @@
45
45
  "@jaypie/core": "^1.0.41"
46
46
  },
47
47
  "devDependencies": {
48
- "@jaypie/testkit": "^1.0.19",
48
+ "@jaypie/testkit": "^1.0.20",
49
49
  "@rollup/plugin-commonjs": "^26.0.1",
50
50
  "@rollup/plugin-node-resolve": "^15.2.3",
51
51
  "eslint": "^8.57.0",
package/src/constants.js CHANGED
@@ -6,6 +6,7 @@
6
6
  export const EXPRESS = {
7
7
  PATH: {
8
8
  ANY: "*",
9
+ ID: "/:id",
9
10
  ROOT: /^\/?$/,
10
11
  },
11
12
  };
@@ -18,14 +18,28 @@ import summarizeResponse from "./summarizeResponse.helper.js";
18
18
  // Main
19
19
  //
20
20
 
21
- const expressHandler = (
22
- handler,
23
- { locals, name, setup = [], teardown = [], unavailable, validate } = {},
24
- ) => {
21
+ const expressHandler = (handler, options = {}) => {
22
+ // If handler is an object and options is a function, swap them
23
+ if (typeof handler === "object" && typeof options === "function") {
24
+ const temp = handler;
25
+ handler = options;
26
+ options = temp;
27
+ }
28
+
25
29
  //
26
30
  //
27
31
  // Validate
28
32
  //
33
+ /* eslint-disable no-autofix/prefer-const */
34
+ let {
35
+ locals,
36
+ name,
37
+ setup = [],
38
+ teardown = [],
39
+ unavailable,
40
+ validate,
41
+ } = options;
42
+ /* eslint-enable no-autofix/prefer-const */
29
43
  validateIs.function(handler);
30
44
  validateIs.optional.object(locals);
31
45
  setup = force.array(setup); // allows a single item
@@ -47,6 +61,11 @@ const expressHandler = (
47
61
  const libLogger = publicLogger.lib({
48
62
  lib: JAYPIE.LIB.EXPRESS,
49
63
  });
64
+ // Top-level, important details that run at the same level as the main logger
65
+ const log = publicLogger.lib({
66
+ level: publicLogger.level,
67
+ lib: JAYPIE.LIB.EXPRESS,
68
+ });
50
69
 
51
70
  // Update the public logger with the request ID
52
71
  const invokeUuid = getCurrentInvokeUuid();
@@ -56,15 +75,24 @@ const expressHandler = (
56
75
  // TODO: in theory this is redundant
57
76
  libLogger.tag({ invoke: invokeUuid });
58
77
  libLogger.tag({ shortInvoke: invokeUuid.slice(0, 8) });
78
+ log.tag({ invoke: invokeUuid });
79
+ log.tag({ shortInvoke: invokeUuid.slice(0, 8) });
59
80
  }
60
81
 
61
- libLogger.trace("[jaypie] Express init");
82
+ if (!name) {
83
+ // If handler has a name, use it
84
+ if (handler.name) {
85
+ name = handler.name;
86
+ } else {
87
+ name = JAYPIE.UNKNOWN;
88
+ }
89
+ }
90
+ publicLogger.tag({ handler: name });
91
+ // TODO: in theory this is redundant
92
+ libLogger.tag({ handler: name });
93
+ log.tag({ handler: name });
62
94
 
63
- // Top-level, important details that run at the same level as the main logger
64
- const log = publicLogger.lib({
65
- level: publicLogger.level,
66
- lib: JAYPIE.LIB.EXPRESS,
67
- });
95
+ libLogger.trace("[jaypie] Express init");
68
96
 
69
97
  // Set req.locals if it doesn't exist
70
98
  if (!req.locals) req.locals = {};