@aeriajs/http 0.0.67 → 0.0.69

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/routing.js CHANGED
@@ -8,19 +8,18 @@ const validation_1 = require("@aeriajs/validation");
8
8
  const entrypoint_1 = require("@aeriajs/entrypoint");
9
9
  const payload_js_1 = require("./payload.js");
10
10
  const next_js_1 = require("./next.js");
11
- const checkUnprocessable = (validationEither, context) => {
12
- if ((0, common_1.isLeft)(validationEither)) {
13
- const validationError = (0, common_1.unwrapEither)(validationEither);
14
- if ('code' in validationError) {
11
+ const checkUnprocessable = ({ error }, context) => {
12
+ if (error) {
13
+ if ('code' in error) {
15
14
  return context.error(types_1.HTTPStatus.UnprocessableContent, {
16
- code: validationError.code,
17
- details: validationError.errors,
15
+ code: error.code,
16
+ details: error.errors,
18
17
  });
19
18
  }
20
19
  return context.error(types_1.HTTPStatus.UnprocessableContent, {
21
20
  code: 'UNPROCESSABLE_ENTITY',
22
21
  message: 'the provided payload is unprocessable',
23
- details: validationError,
22
+ details: error,
24
23
  });
25
24
  }
26
25
  };
@@ -131,7 +130,7 @@ const wrapRouteExecution = async (response, cb) => {
131
130
  response.writeHead(500);
132
131
  }
133
132
  if (!response.writableEnded) {
134
- return (0, common_1.error)({
133
+ return (0, common_1.endpointError)({
135
134
  httpStatus: 500,
136
135
  code: 'UNKNOWN_ERROR',
137
136
  message: 'Internal server error',
package/dist/routing.mjs CHANGED
@@ -1,24 +1,23 @@
1
1
  "use strict";
2
2
  import { Stream } from "stream";
3
3
  import { ACError, HTTPStatus, REQUEST_METHODS } from "@aeriajs/types";
4
- import { pipe, isGranted, isLeft, unwrapEither, deepMerge, error } from "@aeriajs/common";
4
+ import { pipe, isGranted, deepMerge, endpointError } from "@aeriajs/common";
5
5
  import { validate } from "@aeriajs/validation";
6
6
  import { getConfig } from "@aeriajs/entrypoint";
7
7
  import { safeJson } from "./payload.mjs";
8
8
  import { isNext } from "./next.mjs";
9
- const checkUnprocessable = (validationEither, context) => {
10
- if (isLeft(validationEither)) {
11
- const validationError = unwrapEither(validationEither);
12
- if ("code" in validationError) {
9
+ const checkUnprocessable = ({ error }, context) => {
10
+ if (error) {
11
+ if ("code" in error) {
13
12
  return context.error(HTTPStatus.UnprocessableContent, {
14
- code: validationError.code,
15
- details: validationError.errors
13
+ code: error.code,
14
+ details: error.errors
16
15
  });
17
16
  }
18
17
  return context.error(HTTPStatus.UnprocessableContent, {
19
18
  code: "UNPROCESSABLE_ENTITY",
20
19
  message: "the provided payload is unprocessable",
21
- details: validationError
20
+ details: error
22
21
  });
23
22
  }
24
23
  };
@@ -78,18 +77,18 @@ export const registerRoute = async (context, method, exp, cb, contract, options
78
77
  }
79
78
  if ("payload" in contract && contract.payload) {
80
79
  const validationEither = validate(context.request.payload, contract.payload);
81
- const error2 = checkUnprocessable(validationEither, context);
82
- if (error2) {
83
- return error2;
80
+ const error = checkUnprocessable(validationEither, context);
81
+ if (error) {
82
+ return error;
84
83
  }
85
84
  }
86
85
  if ("query" in contract && contract.query) {
87
86
  const validationEither = validate(context.request.query, contract.query, {
88
87
  coerce: true
89
88
  });
90
- const error2 = checkUnprocessable(validationEither, context);
91
- if (error2) {
92
- return error2;
89
+ const error = checkUnprocessable(validationEither, context);
90
+ if (error) {
91
+ return error;
93
92
  }
94
93
  }
95
94
  }
@@ -124,7 +123,7 @@ export const wrapRouteExecution = async (response, cb) => {
124
123
  response.writeHead(500);
125
124
  }
126
125
  if (!response.writableEnded) {
127
- return error({
126
+ return endpointError({
128
127
  httpStatus: 500,
129
128
  code: "UNKNOWN_ERROR",
130
129
  message: "Internal server error"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/http",
3
- "version": "0.0.67",
3
+ "version": "0.0.69",
4
4
  "description": "## Installation",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -28,10 +28,10 @@
28
28
  "@aeriajs/validation": "link:../validation"
29
29
  },
30
30
  "peerDependencies": {
31
- "@aeriajs/common": "^0.0.59",
32
- "@aeriajs/entrypoint": "^0.0.59",
33
- "@aeriajs/types": "^0.0.55",
34
- "@aeriajs/validation": "^0.0.62"
31
+ "@aeriajs/common": "^0.0.60",
32
+ "@aeriajs/entrypoint": "^0.0.61",
33
+ "@aeriajs/types": "^0.0.56",
34
+ "@aeriajs/validation": "^0.0.63"
35
35
  },
36
36
  "scripts": {
37
37
  "test": "echo skipping",