@jaypie/express 1.0.0 → 1.0.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
@@ -16,6 +16,7 @@ See [Jaypie documentation](https://github.com/finlaysonstudio/jaypie) for usage.
16
16
 
17
17
  | Date | Version | Summary |
18
18
  | ---------- | ------- | -------------- |
19
+ | 5/21/2024 | 1.0.0 | Initial release |
19
20
  | 5/19/2024 | 0.1.0 | Initial deploy |
20
21
  | 5/12/2024 | 0.0.1 | Initial commit |
21
22
 
@@ -273,24 +273,25 @@ const expressHandler = (
273
273
  }
274
274
  }
275
275
 
276
- if (!jaypieFunction) {
277
- // Initialize after logging is set up
278
- jaypieFunction = core.jaypieHandler(handler, {
279
- name,
280
- setup,
281
- teardown,
282
- unavailable,
283
- validate,
284
- });
285
- }
286
-
287
276
  let response;
288
277
  let status = core.HTTP.CODE.OK;
289
278
 
290
279
  try {
291
- libLogger.trace("[jaypie] Lambda execution");
292
280
  log.info.var({ req: summarizeRequest(req) });
293
281
 
282
+ if (!jaypieFunction) {
283
+ // Initialize after logging is set up
284
+ jaypieFunction = core.jaypieHandler(handler, {
285
+ name,
286
+ setup,
287
+ teardown,
288
+ unavailable,
289
+ validate,
290
+ });
291
+ }
292
+
293
+ libLogger.trace("[jaypie] Express execution");
294
+
294
295
  //
295
296
  //
296
297
  // Process
@@ -403,26 +404,6 @@ const expressHandler = (
403
404
  // Main
404
405
  //
405
406
 
406
- const echoHandler = (context = {}) => {
407
- core.validate.object(context);
408
- // Give a default name if there isn't one
409
- if (!context.name) {
410
- context.name = "_echo";
411
- }
412
-
413
- // Return a function that will be used as an express route
414
- return expressHandler(async (req) => {
415
- return {
416
- req: summarizeRequest(req),
417
- };
418
- }, context);
419
- };
420
-
421
- //
422
- //
423
- // Main
424
- //
425
-
426
407
  const httpHandler = (statusCode = core.HTTP.CODE.OK, context = {}) => {
427
408
  // Give a default name if there isn't one
428
409
  if (!context.name) {
@@ -467,7 +448,65 @@ const httpHandler = (statusCode = core.HTTP.CODE.OK, context = {}) => {
467
448
  }, context);
468
449
  };
469
450
 
451
+ //
452
+ //
453
+ // Main
454
+ //
455
+
456
+ const echoHandler = (context = {}) => {
457
+ core.validate.object(context);
458
+ // Give a default name if there isn't one
459
+ if (!context.name) {
460
+ context.name = "_echo";
461
+ }
462
+
463
+ // Return a function that will be used as an express route
464
+ return expressHandler(async (req) => {
465
+ return {
466
+ req: summarizeRequest(req),
467
+ };
468
+ }, context);
469
+ };
470
+
471
+ //
472
+ //
473
+ // Functions
474
+ //
475
+
476
+ const routes = {
477
+ echoRoute: echoHandler(),
478
+ forbiddenRoute: httpHandler(core.HTTP.CODE.FORBIDDEN, { name: "_forbidden" }),
479
+ goneRoute: httpHandler(core.HTTP.CODE.GONE, { name: "_gone" }),
480
+ noContentRoute: httpHandler(core.HTTP.CODE.NO_CONTENT, { name: "_noContent" }),
481
+ notFoundRoute: httpHandler(core.HTTP.CODE.NOT_FOUND, { name: "_notFound" }),
482
+ notImplementedRoute: expressHandler(
483
+ () => {
484
+ throw new core.NotImplementedError();
485
+ },
486
+ { name: "_notImplemented" },
487
+ ),
488
+ };
489
+
490
+ //
491
+ //
492
+ // Export
493
+ //
494
+
495
+ const {
496
+ echoRoute,
497
+ forbiddenRoute,
498
+ goneRoute,
499
+ noContentRoute,
500
+ notFoundRoute,
501
+ notImplementedRoute,
502
+ } = routes;
503
+
470
504
  exports.EXPRESS = EXPRESS;
471
- exports.expressEchoHandler = echoHandler;
505
+ exports.echoRoute = echoRoute;
472
506
  exports.expressHandler = expressHandler;
473
- exports.expressHttpHandler = httpHandler;
507
+ exports.expressHttpCodeHandler = httpHandler;
508
+ exports.forbiddenRoute = forbiddenRoute;
509
+ exports.goneRoute = goneRoute;
510
+ exports.noContentRoute = noContentRoute;
511
+ exports.notFoundRoute = notFoundRoute;
512
+ exports.notImplementedRoute = notImplementedRoute;
@@ -1,4 +1,4 @@
1
- import { log, JAYPIE, HTTP, validate, force, jaypieHandler, UnhandledError, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, MethodNotAllowedError, GoneError, TeapotError, InternalError, BadGatewayError, UnavailableError, GatewayTimeoutError } from '@jaypie/core';
1
+ import { log, JAYPIE, HTTP, validate, force, jaypieHandler, UnhandledError, BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, MethodNotAllowedError, GoneError, TeapotError, InternalError, BadGatewayError, UnavailableError, GatewayTimeoutError, NotImplementedError } from '@jaypie/core';
2
2
  import { getCurrentInvoke } from '@codegenie/serverless-express';
3
3
 
4
4
  //
@@ -271,24 +271,25 @@ const expressHandler = (
271
271
  }
272
272
  }
273
273
 
274
- if (!jaypieFunction) {
275
- // Initialize after logging is set up
276
- jaypieFunction = jaypieHandler(handler, {
277
- name,
278
- setup,
279
- teardown,
280
- unavailable,
281
- validate: validate$1,
282
- });
283
- }
284
-
285
274
  let response;
286
275
  let status = HTTP.CODE.OK;
287
276
 
288
277
  try {
289
- libLogger.trace("[jaypie] Lambda execution");
290
278
  log$1.info.var({ req: summarizeRequest(req) });
291
279
 
280
+ if (!jaypieFunction) {
281
+ // Initialize after logging is set up
282
+ jaypieFunction = jaypieHandler(handler, {
283
+ name,
284
+ setup,
285
+ teardown,
286
+ unavailable,
287
+ validate: validate$1,
288
+ });
289
+ }
290
+
291
+ libLogger.trace("[jaypie] Express execution");
292
+
292
293
  //
293
294
  //
294
295
  // Process
@@ -401,26 +402,6 @@ const expressHandler = (
401
402
  // Main
402
403
  //
403
404
 
404
- const echoHandler = (context = {}) => {
405
- validate.object(context);
406
- // Give a default name if there isn't one
407
- if (!context.name) {
408
- context.name = "_echo";
409
- }
410
-
411
- // Return a function that will be used as an express route
412
- return expressHandler(async (req) => {
413
- return {
414
- req: summarizeRequest(req),
415
- };
416
- }, context);
417
- };
418
-
419
- //
420
- //
421
- // Main
422
- //
423
-
424
405
  const httpHandler = (statusCode = HTTP.CODE.OK, context = {}) => {
425
406
  // Give a default name if there isn't one
426
407
  if (!context.name) {
@@ -465,4 +446,57 @@ const httpHandler = (statusCode = HTTP.CODE.OK, context = {}) => {
465
446
  }, context);
466
447
  };
467
448
 
468
- export { EXPRESS, echoHandler as expressEchoHandler, expressHandler, httpHandler as expressHttpHandler };
449
+ //
450
+ //
451
+ // Main
452
+ //
453
+
454
+ const echoHandler = (context = {}) => {
455
+ validate.object(context);
456
+ // Give a default name if there isn't one
457
+ if (!context.name) {
458
+ context.name = "_echo";
459
+ }
460
+
461
+ // Return a function that will be used as an express route
462
+ return expressHandler(async (req) => {
463
+ return {
464
+ req: summarizeRequest(req),
465
+ };
466
+ }, context);
467
+ };
468
+
469
+ //
470
+ //
471
+ // Functions
472
+ //
473
+
474
+ const routes = {
475
+ echoRoute: echoHandler(),
476
+ forbiddenRoute: httpHandler(HTTP.CODE.FORBIDDEN, { name: "_forbidden" }),
477
+ goneRoute: httpHandler(HTTP.CODE.GONE, { name: "_gone" }),
478
+ noContentRoute: httpHandler(HTTP.CODE.NO_CONTENT, { name: "_noContent" }),
479
+ notFoundRoute: httpHandler(HTTP.CODE.NOT_FOUND, { name: "_notFound" }),
480
+ notImplementedRoute: expressHandler(
481
+ () => {
482
+ throw new NotImplementedError();
483
+ },
484
+ { name: "_notImplemented" },
485
+ ),
486
+ };
487
+
488
+ //
489
+ //
490
+ // Export
491
+ //
492
+
493
+ const {
494
+ echoRoute,
495
+ forbiddenRoute,
496
+ goneRoute,
497
+ noContentRoute,
498
+ notFoundRoute,
499
+ notImplementedRoute,
500
+ } = routes;
501
+
502
+ export { EXPRESS, echoRoute, expressHandler, httpHandler as expressHttpCodeHandler, forbiddenRoute, goneRoute, noContentRoute, notFoundRoute, notImplementedRoute };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaypie/express",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "author": "Finlayson Studio",
5
5
  "type": "module",
6
6
  "exports": {
@@ -35,6 +35,7 @@
35
35
  "test:spec:getCurrentInvokeUuid.adapter": "vitest run ./src/__tests__/getCurrentInvokeUuid.adapter.spec.js",
36
36
  "test:spec:http.handler": "vitest run ./src/__tests__/http.handler.spec.js",
37
37
  "test:spec:index": "vitest run ./src/__tests__/index.spec.js",
38
+ "test:spec:routes": "vitest run ./src/__tests__/routes.spec.js",
38
39
  "test:spec:summarizeRequest.helper": "vitest run ./src/__tests__/summarizeRequest.helper.spec.js",
39
40
  "test:spec:summarizeResponse.helper": "vitest run ./src/__tests__/summarizeResponse.helper.spec.js",
40
41
  "test:spec:supertest": "vitest run ./src/__tests__/supertest.spec.js"
@@ -124,24 +124,25 @@ const expressHandler = (
124
124
  }
125
125
  }
126
126
 
127
- if (!jaypieFunction) {
128
- // Initialize after logging is set up
129
- jaypieFunction = jaypieHandler(handler, {
130
- name,
131
- setup,
132
- teardown,
133
- unavailable,
134
- validate,
135
- });
136
- }
137
-
138
127
  let response;
139
128
  let status = HTTP.CODE.OK;
140
129
 
141
130
  try {
142
- libLogger.trace("[jaypie] Lambda execution");
143
131
  log.info.var({ req: summarizeRequest(req) });
144
132
 
133
+ if (!jaypieFunction) {
134
+ // Initialize after logging is set up
135
+ jaypieFunction = jaypieHandler(handler, {
136
+ name,
137
+ setup,
138
+ teardown,
139
+ unavailable,
140
+ validate,
141
+ });
142
+ }
143
+
144
+ libLogger.trace("[jaypie] Express execution");
145
+
145
146
  //
146
147
  //
147
148
  // Process
package/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { EXPRESS } from "./constants.js";
2
- export { default as expressEchoHandler } from "./echo.handler.js";
3
2
  export { default as expressHandler } from "./expressHandler.js";
4
- export { default as expressHttpHandler } from "./http.handler.js";
3
+ export { default as expressHttpCodeHandler } from "./http.handler.js";
4
+ export * from "./routes.js";
package/src/routes.js ADDED
@@ -0,0 +1,37 @@
1
+ import { HTTP, NotImplementedError } from "@jaypie/core";
2
+ import expressHandler from "./expressHandler.js";
3
+ import httpHandler from "./http.handler.js";
4
+ import echoHandler from "./echo.handler.js";
5
+
6
+ //
7
+ //
8
+ // Functions
9
+ //
10
+
11
+ const routes = {
12
+ echoRoute: echoHandler(),
13
+ forbiddenRoute: httpHandler(HTTP.CODE.FORBIDDEN, { name: "_forbidden" }),
14
+ goneRoute: httpHandler(HTTP.CODE.GONE, { name: "_gone" }),
15
+ noContentRoute: httpHandler(HTTP.CODE.NO_CONTENT, { name: "_noContent" }),
16
+ notFoundRoute: httpHandler(HTTP.CODE.NOT_FOUND, { name: "_notFound" }),
17
+ notImplementedRoute: expressHandler(
18
+ () => {
19
+ throw new NotImplementedError();
20
+ },
21
+ { name: "_notImplemented" },
22
+ ),
23
+ };
24
+
25
+ //
26
+ //
27
+ // Export
28
+ //
29
+
30
+ export const {
31
+ echoRoute,
32
+ forbiddenRoute,
33
+ goneRoute,
34
+ noContentRoute,
35
+ notFoundRoute,
36
+ notImplementedRoute,
37
+ } = routes;