@jaypie/express 1.0.1 → 1.0.3

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.
@@ -404,26 +404,6 @@ const expressHandler = (
404
404
  // Main
405
405
  //
406
406
 
407
- const echoHandler = (context = {}) => {
408
- core.validate.object(context);
409
- // Give a default name if there isn't one
410
- if (!context.name) {
411
- context.name = "_echo";
412
- }
413
-
414
- // Return a function that will be used as an express route
415
- return expressHandler(async (req) => {
416
- return {
417
- req: summarizeRequest(req),
418
- };
419
- }, context);
420
- };
421
-
422
- //
423
- //
424
- // Main
425
- //
426
-
427
407
  const httpHandler = (statusCode = core.HTTP.CODE.OK, context = {}) => {
428
408
  // Give a default name if there isn't one
429
409
  if (!context.name) {
@@ -468,7 +448,65 @@ const httpHandler = (statusCode = core.HTTP.CODE.OK, context = {}) => {
468
448
  }, context);
469
449
  };
470
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
+
471
504
  exports.EXPRESS = EXPRESS;
472
- exports.expressEchoHandler = echoHandler;
505
+ exports.echoRoute = echoRoute;
473
506
  exports.expressHandler = expressHandler;
474
- 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
  //
@@ -402,26 +402,6 @@ const expressHandler = (
402
402
  // Main
403
403
  //
404
404
 
405
- const echoHandler = (context = {}) => {
406
- validate.object(context);
407
- // Give a default name if there isn't one
408
- if (!context.name) {
409
- context.name = "_echo";
410
- }
411
-
412
- // Return a function that will be used as an express route
413
- return expressHandler(async (req) => {
414
- return {
415
- req: summarizeRequest(req),
416
- };
417
- }, context);
418
- };
419
-
420
- //
421
- //
422
- // Main
423
- //
424
-
425
405
  const httpHandler = (statusCode = HTTP.CODE.OK, context = {}) => {
426
406
  // Give a default name if there isn't one
427
407
  if (!context.name) {
@@ -466,4 +446,57 @@ const httpHandler = (statusCode = HTTP.CODE.OK, context = {}) => {
466
446
  }, context);
467
447
  };
468
448
 
469
- 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.1",
3
+ "version": "1.0.3",
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"
package/rollup.config.mjs CHANGED
@@ -6,7 +6,7 @@ export default {
6
6
  input: "src/index.js", // Path to your main JavaScript file
7
7
  output: [
8
8
  {
9
- file: "dist/module.cjs.js", // Output file for CommonJS
9
+ file: "dist/module.cjs", // Output file for CommonJS
10
10
  format: "cjs", // CommonJS format
11
11
  },
12
12
  {
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;