@aeriajs/http 0.0.82 → 0.0.84
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 +15 -9
- package/dist/routing.mjs +16 -10
- package/package.json +5 -5
package/dist/routing.js
CHANGED
|
@@ -17,7 +17,7 @@ const checkUnprocessable = ({ error }, context) => {
|
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
return context.error(types_1.HTTPStatus.UnprocessableContent, {
|
|
20
|
-
code:
|
|
20
|
+
code: types_1.ACError.MalformedInput,
|
|
21
21
|
message: 'the provided payload is unprocessable',
|
|
22
22
|
details: error,
|
|
23
23
|
});
|
|
@@ -61,13 +61,16 @@ const registerRoute = async (context, method, exp, cb, contract, options = {}) =
|
|
|
61
61
|
}
|
|
62
62
|
catch (err) {
|
|
63
63
|
return context.error(types_1.HTTPStatus.UnprocessableContent, {
|
|
64
|
-
code:
|
|
64
|
+
code: types_1.ACError.MalformedInput,
|
|
65
65
|
message: 'Invalid JSON',
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
Object.assign(context.request, match);
|
|
70
70
|
if (contract) {
|
|
71
|
+
if (contract.streamed) {
|
|
72
|
+
context.response[types_1.STREAMED_RESPONSE] = true;
|
|
73
|
+
}
|
|
71
74
|
if (contract.roles) {
|
|
72
75
|
const granted = (0, common_1.isGranted)(contract.roles, context.token);
|
|
73
76
|
if (!granted) {
|
|
@@ -104,11 +107,7 @@ exports.registerRoute = registerRoute;
|
|
|
104
107
|
const wrapRouteExecution = async (response, cb) => {
|
|
105
108
|
try {
|
|
106
109
|
const result = await cb();
|
|
107
|
-
if (
|
|
108
|
-
if (!response.headersSent) {
|
|
109
|
-
response.writeHead(204);
|
|
110
|
-
}
|
|
111
|
-
response.end(result);
|
|
110
|
+
if (response[types_1.STREAMED_RESPONSE] && !result) {
|
|
112
111
|
return;
|
|
113
112
|
}
|
|
114
113
|
if (result instanceof stream_1.Stream) {
|
|
@@ -119,6 +118,13 @@ const wrapRouteExecution = async (response, cb) => {
|
|
|
119
118
|
}
|
|
120
119
|
return;
|
|
121
120
|
}
|
|
121
|
+
if (result === null) {
|
|
122
|
+
if (!response.headersSent) {
|
|
123
|
+
response.writeHead(204);
|
|
124
|
+
}
|
|
125
|
+
response.end(result);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
122
128
|
if (!response.writableEnded) {
|
|
123
129
|
response.end(result);
|
|
124
130
|
}
|
|
@@ -132,7 +138,7 @@ const wrapRouteExecution = async (response, cb) => {
|
|
|
132
138
|
if (!response.writableEnded) {
|
|
133
139
|
return (0, common_1.endpointError)({
|
|
134
140
|
httpStatus: 500,
|
|
135
|
-
code:
|
|
141
|
+
code: types_1.ACError.UnknownError,
|
|
136
142
|
message: 'Internal server error',
|
|
137
143
|
});
|
|
138
144
|
}
|
|
@@ -199,7 +205,7 @@ const createRouter = (options = {}) => {
|
|
|
199
205
|
const result = await routerPipe(undefined, context, options);
|
|
200
206
|
if (exhaust && (result === undefined || (0, next_js_1.isNext)(result))) {
|
|
201
207
|
return context.error(types_1.HTTPStatus.NotFound, {
|
|
202
|
-
code:
|
|
208
|
+
code: types_1.ACError.ResourceNotFound,
|
|
203
209
|
message: 'Not found',
|
|
204
210
|
});
|
|
205
211
|
}
|
package/dist/routing.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { Stream } from "stream";
|
|
3
|
-
import { ACError, HTTPStatus, REQUEST_METHODS } from "@aeriajs/types";
|
|
3
|
+
import { ACError, HTTPStatus, REQUEST_METHODS, STREAMED_RESPONSE } from "@aeriajs/types";
|
|
4
4
|
import { pipe, isGranted, deepMerge, endpointError } from "@aeriajs/common";
|
|
5
5
|
import { validate } from "@aeriajs/validation";
|
|
6
6
|
import { getConfig } from "@aeriajs/entrypoint";
|
|
@@ -15,7 +15,7 @@ const checkUnprocessable = ({ error }, context) => {
|
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
return context.error(HTTPStatus.UnprocessableContent, {
|
|
18
|
-
code:
|
|
18
|
+
code: ACError.MalformedInput,
|
|
19
19
|
message: "the provided payload is unprocessable",
|
|
20
20
|
details: error
|
|
21
21
|
});
|
|
@@ -59,13 +59,16 @@ export const registerRoute = async (context, method, exp, cb, contract, options
|
|
|
59
59
|
);
|
|
60
60
|
} catch (err) {
|
|
61
61
|
return context.error(HTTPStatus.UnprocessableContent, {
|
|
62
|
-
code:
|
|
62
|
+
code: ACError.MalformedInput,
|
|
63
63
|
message: "Invalid JSON"
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
Object.assign(context.request, match);
|
|
68
68
|
if (contract) {
|
|
69
|
+
if (contract.streamed) {
|
|
70
|
+
context.response[STREAMED_RESPONSE] = true;
|
|
71
|
+
}
|
|
69
72
|
if (contract.roles) {
|
|
70
73
|
const granted = isGranted(contract.roles, context.token);
|
|
71
74
|
if (!granted) {
|
|
@@ -99,11 +102,7 @@ export const registerRoute = async (context, method, exp, cb, contract, options
|
|
|
99
102
|
export const wrapRouteExecution = async (response, cb) => {
|
|
100
103
|
try {
|
|
101
104
|
const result = await cb();
|
|
102
|
-
if (
|
|
103
|
-
if (!response.headersSent) {
|
|
104
|
-
response.writeHead(204);
|
|
105
|
-
}
|
|
106
|
-
response.end(result);
|
|
105
|
+
if (response[STREAMED_RESPONSE] && !result) {
|
|
107
106
|
return;
|
|
108
107
|
}
|
|
109
108
|
if (result instanceof Stream) {
|
|
@@ -113,6 +112,13 @@ export const wrapRouteExecution = async (response, cb) => {
|
|
|
113
112
|
}
|
|
114
113
|
return;
|
|
115
114
|
}
|
|
115
|
+
if (result === null) {
|
|
116
|
+
if (!response.headersSent) {
|
|
117
|
+
response.writeHead(204);
|
|
118
|
+
}
|
|
119
|
+
response.end(result);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
116
122
|
if (!response.writableEnded) {
|
|
117
123
|
response.end(result);
|
|
118
124
|
}
|
|
@@ -125,7 +131,7 @@ export const wrapRouteExecution = async (response, cb) => {
|
|
|
125
131
|
if (!response.writableEnded) {
|
|
126
132
|
return endpointError({
|
|
127
133
|
httpStatus: 500,
|
|
128
|
-
code:
|
|
134
|
+
code: ACError.UnknownError,
|
|
129
135
|
message: "Internal server error"
|
|
130
136
|
});
|
|
131
137
|
}
|
|
@@ -195,7 +201,7 @@ export const createRouter = (options = {}) => {
|
|
|
195
201
|
const result = await routerPipe(void 0, context, options2);
|
|
196
202
|
if (exhaust && (result === void 0 || isNext(result))) {
|
|
197
203
|
return context.error(HTTPStatus.NotFound, {
|
|
198
|
-
code:
|
|
204
|
+
code: ACError.ResourceNotFound,
|
|
199
205
|
message: "Not found"
|
|
200
206
|
});
|
|
201
207
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/http",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.84",
|
|
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.
|
|
32
|
-
"@aeriajs/entrypoint": "^0.0.
|
|
33
|
-
"@aeriajs/types": "^0.0.
|
|
34
|
-
"@aeriajs/validation": "^0.0.
|
|
31
|
+
"@aeriajs/common": "^0.0.73",
|
|
32
|
+
"@aeriajs/entrypoint": "^0.0.75",
|
|
33
|
+
"@aeriajs/types": "^0.0.64",
|
|
34
|
+
"@aeriajs/validation": "^0.0.76"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"test": "echo skipping",
|