@aeriajs/http 0.0.58 → 0.0.60
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.d.ts +4 -21
- package/dist/routing.js +1 -1
- package/dist/routing.mjs +8 -8
- package/package.json +5 -5
package/dist/routing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RouteContext, GenericRequest, GenericResponse, RequestMethod, RouteUri, InferProperty, InferResponse, PackReferences, ContractWithRoles, ApiConfig,
|
|
1
|
+
import type { RouteContext, GenericRequest, GenericResponse, RequestMethod, RouteUri, InferProperty, InferResponse, PackReferences, ContractWithRoles, ApiConfig, RoleFromAccessCondition } from '@aeriajs/types';
|
|
2
2
|
export type RouterOptions = {
|
|
3
3
|
exhaust?: boolean;
|
|
4
4
|
base?: RouteUri;
|
|
@@ -8,7 +8,7 @@ export type Middleware = (context: RouteContext) => any;
|
|
|
8
8
|
export type RouteGroupOptions = {
|
|
9
9
|
base?: RouteUri;
|
|
10
10
|
};
|
|
11
|
-
type TypedContext<TContractWithRoles extends ContractWithRoles> = RouteContext<TContractWithRoles['roles']
|
|
11
|
+
type TypedContext<TContractWithRoles extends ContractWithRoles> = RouteContext<RoleFromAccessCondition<TContractWithRoles['roles']>> & {
|
|
12
12
|
request: Omit<RouteContext['request'], 'payload' | 'query'> & {
|
|
13
13
|
payload: TContractWithRoles extends {
|
|
14
14
|
payload: infer Payload;
|
|
@@ -20,11 +20,7 @@ type TypedContext<TContractWithRoles extends ContractWithRoles> = RouteContext<T
|
|
|
20
20
|
};
|
|
21
21
|
export type ProxiedRouter<TRouter> = TRouter & Record<RequestMethod, <const TContractWithRoles extends ContractWithRoles, TCallback extends (TContractWithRoles extends {
|
|
22
22
|
response: infer Response;
|
|
23
|
-
} ? InferResponse<Response> : any) extends infer Response ? TContractWithRoles
|
|
24
|
-
token: {
|
|
25
|
-
authenticated: true;
|
|
26
|
-
};
|
|
27
|
-
}) => Response : (context: TypedContext<TContractWithRoles>) => Response : never : never>(exp: RouteUri, cb: TCallback, contract?: TContractWithRoles) => ReturnType<typeof registerRoute>>;
|
|
23
|
+
} ? InferResponse<Response> : any) extends infer Response ? (context: TypedContext<TContractWithRoles>) => Response : never>(exp: RouteUri, cb: TCallback, contract?: TContractWithRoles) => ReturnType<typeof registerRoute>>;
|
|
28
24
|
export declare const matches: <TRequest extends GenericRequest>(req: TRequest, method: RequestMethod | RequestMethod[] | null, exp: string | RegExp, options: RouterOptions, config?: ApiConfig) => {
|
|
29
25
|
fragments: string[];
|
|
30
26
|
} | undefined;
|
|
@@ -33,20 +29,7 @@ export declare const wrapRouteExecution: (response: GenericResponse, cb: () => a
|
|
|
33
29
|
export declare const createRouter: (options?: Partial<RouterOptions>) => ProxiedRouter<{
|
|
34
30
|
route: <const TContractWithRoles extends ContractWithRoles, TCallback extends (TContractWithRoles extends {
|
|
35
31
|
response: infer Response;
|
|
36
|
-
} ? InferResponse<Response> : any) extends infer Response_1 ?
|
|
37
|
-
request: Omit<GenericRequest, "payload" | "query"> & {
|
|
38
|
-
payload: TContractWithRoles extends {
|
|
39
|
-
payload: infer Payload;
|
|
40
|
-
} ? PackReferences<InferProperty<Payload>> : any;
|
|
41
|
-
query: TContractWithRoles extends {
|
|
42
|
-
query: infer Query;
|
|
43
|
-
} ? InferProperty<Query> : any;
|
|
44
|
-
};
|
|
45
|
-
} & {
|
|
46
|
-
token: {
|
|
47
|
-
authenticated: true;
|
|
48
|
-
};
|
|
49
|
-
}) => Response_1 : (context: TypedContext<TContractWithRoles>) => Response_1 : never : never>(method: RequestMethod | RequestMethod[], exp: RouteUri, cb: TCallback, contract?: TContractWithRoles) => void;
|
|
32
|
+
} ? InferResponse<Response> : any) extends infer Response_1 ? (context: TypedContext<TContractWithRoles>) => Response_1 : never>(method: RequestMethod | RequestMethod[], exp: RouteUri, cb: TCallback, contract?: TContractWithRoles) => void;
|
|
50
33
|
routes: ((_: unknown, context: RouteContext, groupOptions?: RouteGroupOptions) => ReturnType<typeof registerRoute>)[];
|
|
51
34
|
routesMeta: RoutesMeta;
|
|
52
35
|
group: <TRouter extends {
|
package/dist/routing.js
CHANGED
|
@@ -129,7 +129,7 @@ const wrapRouteExecution = async (response, cb) => {
|
|
|
129
129
|
response.writeHead(500);
|
|
130
130
|
}
|
|
131
131
|
if (!response.writableEnded) {
|
|
132
|
-
return (0, common_1.
|
|
132
|
+
return (0, common_1.error)({
|
|
133
133
|
httpCode: 500,
|
|
134
134
|
code: 'UNKNOWN_ERROR',
|
|
135
135
|
message: 'Internal server error',
|
package/dist/routing.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { Stream } from "stream";
|
|
3
3
|
import { ACErrors, REQUEST_METHODS } from "@aeriajs/types";
|
|
4
|
-
import { pipe, isGranted, isLeft, deepMerge,
|
|
4
|
+
import { pipe, isGranted, isLeft, deepMerge, error } from "@aeriajs/common";
|
|
5
5
|
import { validate } from "@aeriajs/validation";
|
|
6
6
|
import { getConfig } from "@aeriajs/entrypoint";
|
|
7
7
|
import { safeJson } from "./payload.mjs";
|
|
@@ -76,18 +76,18 @@ export const registerRoute = async (context, method, exp, cb, contract, options
|
|
|
76
76
|
}
|
|
77
77
|
if ("payload" in contract && contract.payload) {
|
|
78
78
|
const validationEither = validate(context.request.payload, contract.payload);
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
return
|
|
79
|
+
const error2 = checkUnprocessable(validationEither, context);
|
|
80
|
+
if (error2) {
|
|
81
|
+
return error2;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
if ("query" in contract && contract.query) {
|
|
85
85
|
const validationEither = validate(context.request.query, contract.query, {
|
|
86
86
|
coerce: true
|
|
87
87
|
});
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
90
|
-
return
|
|
88
|
+
const error2 = checkUnprocessable(validationEither, context);
|
|
89
|
+
if (error2) {
|
|
90
|
+
return error2;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -122,7 +122,7 @@ export const wrapRouteExecution = async (response, cb) => {
|
|
|
122
122
|
response.writeHead(500);
|
|
123
123
|
}
|
|
124
124
|
if (!response.writableEnded) {
|
|
125
|
-
return
|
|
125
|
+
return error({
|
|
126
126
|
httpCode: 500,
|
|
127
127
|
code: "UNKNOWN_ERROR",
|
|
128
128
|
message: "Internal server error"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/http",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.60",
|
|
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.52",
|
|
32
|
+
"@aeriajs/entrypoint": "^0.0.52",
|
|
33
|
+
"@aeriajs/types": "^0.0.49",
|
|
34
|
+
"@aeriajs/validation": "^0.0.55"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"test": "echo skipping",
|