@miqro/core 1.3.2 → 1.3.6
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 +79 -193
- package/dist/handler/api-handler.d.ts +1 -1
- package/dist/handler/api-handler.js +2 -1
- package/dist/handler/api-handler.js.map +1 -1
- package/dist/handler/api-router-utils.d.ts +1 -8
- package/dist/handler/api-router-utils.js +16 -14
- package/dist/handler/api-router-utils.js.map +1 -1
- package/dist/handler/app.d.ts +3 -9
- package/dist/handler/app.js +10 -14
- package/dist/handler/app.js.map +1 -1
- package/dist/handler/common/context.d.ts +1 -1
- package/dist/handler/common/router-utils.d.ts +59 -0
- package/dist/handler/common/router-utils.js +134 -0
- package/dist/handler/common/router-utils.js.map +1 -0
- package/dist/handler/common/router.d.ts +23 -21
- package/dist/handler/common/router.js +55 -81
- package/dist/handler/common/router.js.map +1 -1
- package/dist/handler/common/tokenize-match.d.ts +18 -9
- package/dist/handler/common/tokenize-match.js +34 -28
- package/dist/handler/common/tokenize-match.js.map +1 -1
- package/dist/handler/feature-router.d.ts +4 -2
- package/dist/handler/feature-router.js +1 -1
- package/dist/handler/feature-router.js.map +1 -1
- package/dist/handler/middleware/parse.d.ts +1 -0
- package/dist/handler/middleware/parse.js +10 -0
- package/dist/handler/middleware/parse.js.map +1 -1
- package/dist/util/client.d.ts +17 -0
- package/dist/util/client.js +55 -0
- package/dist/util/client.js.map +1 -0
- package/dist/util/cookie/cookie.d.ts +0 -1
- package/dist/util/parser/get.js +3 -6
- package/dist/util/parser/get.js.map +1 -1
- package/dist/util/request/common.d.ts +0 -1
- package/package.json +1 -2
- package/src/handler/api-handler.ts +3 -2
- package/src/handler/api-router-utils.ts +17 -20
- package/src/handler/app.ts +11 -19
- package/src/handler/common/context.ts +1 -1
- package/src/handler/common/router-utils.ts +184 -0
- package/src/handler/common/router.ts +66 -95
- package/src/handler/common/tokenize-match.ts +40 -40
- package/src/handler/feature-router.ts +4 -2
- package/src/handler/middleware/parse.ts +11 -1
- package/src/util/client.ts +64 -0
- package/src/util/parser/get.ts +3 -5
- package/tsconfig.json +2 -2
package/README.md
CHANGED
|
@@ -2,87 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
this module provides helpers functions to develop nodejs applications like **logging**, **config** and **request parsing**
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
#### parse
|
|
8
|
-
|
|
9
|
-
```typescript
|
|
10
|
-
import { Parser } from "@miqro/core";
|
|
11
|
-
|
|
12
|
-
const parser = new Parser();
|
|
13
|
-
const parsedValue = parser.parse("body", req.body, {
|
|
14
|
-
name: "string",
|
|
15
|
-
age: "number"
|
|
16
|
-
}, "no_extra");
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
#### custom type
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
import { Parser } from "@miqro/core";
|
|
23
|
-
|
|
24
|
-
const parser = new Parser();
|
|
25
|
-
|
|
26
|
-
// registerParser
|
|
27
|
-
parser.registerParser("custom-type", ({ value }) => {
|
|
28
|
-
const value = parseInt(value, 10);
|
|
29
|
-
return {
|
|
30
|
-
isType: !isNaN(value),
|
|
31
|
-
value
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
// parse
|
|
35
|
-
const parsedValue = parser.parse("body", req.body, {
|
|
36
|
-
name: "string",
|
|
37
|
-
age: "number",
|
|
38
|
-
custom: {
|
|
39
|
-
type: "custom-type",
|
|
40
|
-
required: false,
|
|
41
|
-
defaultValue: 0,
|
|
42
|
-
allowNull: true
|
|
43
|
-
},
|
|
44
|
-
customArray: {
|
|
45
|
-
type: "array",
|
|
46
|
-
arrayType: "custom-type",
|
|
47
|
-
required: false,
|
|
48
|
-
defaultValue: 0,
|
|
49
|
-
allowNull: true
|
|
50
|
-
}
|
|
51
|
-
}, "no_extra"):
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## get
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
import { get } from "@miqro/core";
|
|
58
|
-
...
|
|
59
|
-
const name = get(obj, "user.info.name", "no_name");
|
|
60
|
-
// with parse
|
|
61
|
-
const age = get(obj, "user.info.age", 0, {
|
|
62
|
-
type:"number",
|
|
63
|
-
numberMin: 0,
|
|
64
|
-
numberMaxDecimals: 0
|
|
65
|
-
});
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
## request
|
|
5
|
+
## async request with http.request
|
|
69
6
|
|
|
70
7
|
```typescript
|
|
71
8
|
import { request } from "@miqro/core";
|
|
72
9
|
|
|
73
10
|
const response = await request({
|
|
74
11
|
url: "https://hostname/path",
|
|
12
|
+
followRedirect: true, // defaults to false
|
|
75
13
|
query: {
|
|
76
14
|
limit: 100,
|
|
77
15
|
offset: 0,
|
|
78
16
|
q: "search"
|
|
79
17
|
},
|
|
80
18
|
method: "GET"
|
|
81
|
-
|
|
82
19
|
});
|
|
83
20
|
```
|
|
84
21
|
|
|
85
|
-
|
|
22
|
+
### options
|
|
86
23
|
|
|
87
24
|
```typescript
|
|
88
25
|
interface RequestOptions {
|
|
@@ -104,16 +41,7 @@ interface RequestOptions {
|
|
|
104
41
|
## Logger
|
|
105
42
|
|
|
106
43
|
```typescript
|
|
107
|
-
import { getLogger,
|
|
108
|
-
|
|
109
|
-
/*
|
|
110
|
-
// custom factory
|
|
111
|
-
setLoggerFactory((args)=>{
|
|
112
|
-
return new Logger(args.identifier, args.level, {
|
|
113
|
-
transports: [...],
|
|
114
|
-
formatter: (args) => `${args.message}`;
|
|
115
|
-
});
|
|
116
|
-
});*/
|
|
44
|
+
import { getLogger, Logger } from "@miqro/core";
|
|
117
45
|
|
|
118
46
|
// const logger = new Logger();
|
|
119
47
|
const logger = getLogger("identifier");
|
|
@@ -125,7 +53,25 @@ logger.error("error");
|
|
|
125
53
|
logger.trace("trace");
|
|
126
54
|
```
|
|
127
55
|
|
|
128
|
-
|
|
56
|
+
### custom logger factory
|
|
57
|
+
|
|
58
|
+
for example if you want to add default transports or a different formatting for all Loggers created with ***getLogger(....)***
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { setLoggerFactory, Logger } from "@miqro/core";
|
|
62
|
+
// custom factory
|
|
63
|
+
const transports = [
|
|
64
|
+
|
|
65
|
+
];
|
|
66
|
+
setLoggerFactory((args)=>{
|
|
67
|
+
return new Logger(args.identifier, args.level, {
|
|
68
|
+
transports,
|
|
69
|
+
formatter: (args) => `${args.message}`;
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## checkEnvVariables and loadConfig
|
|
129
75
|
|
|
130
76
|
```typescript
|
|
131
77
|
import { checkEnvVariables, loadConfig } from "@miqro/core";
|
|
@@ -146,74 +92,22 @@ const [ URL_A, DB_URI ] = checkEnvVariables([
|
|
|
146
92
|
]);
|
|
147
93
|
```
|
|
148
94
|
|
|
149
|
-
## http
|
|
150
|
-
|
|
151
|
-
#### Context
|
|
152
|
-
|
|
153
|
-
```typescript
|
|
154
|
-
class Context {
|
|
155
|
-
req: IncomingMessage;
|
|
156
|
-
res: ServerResponse;
|
|
157
|
-
url: URL;
|
|
158
|
-
logger: Logger;
|
|
159
|
-
startMS: number;
|
|
160
|
-
uuid: string;
|
|
161
|
-
session?: Session;
|
|
162
|
-
results: any[];
|
|
163
|
-
path: string;
|
|
164
|
-
hash: string;
|
|
165
|
-
method: string;
|
|
166
|
-
headers: IncomingHttpHeaders;
|
|
167
|
-
cookies: {
|
|
168
|
-
[name: string]: string;
|
|
169
|
-
};
|
|
170
|
-
query: {
|
|
171
|
-
[name: string]: string | string[];
|
|
172
|
-
};
|
|
173
|
-
params: {
|
|
174
|
-
[name: string]: string | undefined;
|
|
175
|
-
};
|
|
176
|
-
buffer: Buffer;
|
|
177
|
-
remoteAddress?: string;
|
|
178
|
-
body: any;
|
|
179
|
-
constructor(req: IncomingMessage, res: ServerResponse, logger?: Logger);
|
|
180
|
-
close(): Promise<void>;
|
|
181
|
-
addVaryHeader(value: number | string | ReadonlyArray<string>): ServerResponse;
|
|
182
|
-
setHeader(name: string, value: number | string | ReadonlyArray<string>): ServerResponse;
|
|
183
|
-
setCookie(name: string, value: string, options?: {
|
|
184
|
-
encode?: (uriComponent: string | number | boolean) => string;
|
|
185
|
-
maxAge?: number | null;
|
|
186
|
-
domain?: string;
|
|
187
|
-
httpOnly?: boolean;
|
|
188
|
-
secure?: boolean;
|
|
189
|
-
path?: string;
|
|
190
|
-
expires?: Date;
|
|
191
|
-
sameSite?: "lax" | "strict" | "none" | true;
|
|
192
|
-
}): ServerResponse;
|
|
193
|
-
end({ status, headers, body }: Response): Promise<void>;
|
|
194
|
-
json(body: any, headers?: OutgoingHttpHeaders, status?: number): Promise<void>;
|
|
195
|
-
text(text: string, headers?: OutgoingHttpHeaders, status?: number): Promise<void>;
|
|
196
|
-
html(html: string, headers?: OutgoingHttpHeaders, status?: number): Promise<void>;
|
|
197
|
-
redirect(url: string, headers?: OutgoingHttpHeaders, status?: number): Promise<void>;
|
|
198
|
-
}
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
#### Router
|
|
95
|
+
## helpers for http module
|
|
202
96
|
|
|
203
97
|
```typescript
|
|
204
|
-
import
|
|
205
|
-
import {
|
|
206
|
-
|
|
207
|
-
const app = new App();
|
|
98
|
+
import * as http from "http";
|
|
99
|
+
import { App, Router, JSONParser, ReadBuffer } from "@miqro/core";
|
|
208
100
|
|
|
209
101
|
const router = new Router();
|
|
210
|
-
|
|
211
102
|
router.use([
|
|
212
|
-
ReadBuffer(),
|
|
213
|
-
JSONParser(),
|
|
103
|
+
ReadBuffer(), // needed to read the buffer of the request and set ctx.buffer
|
|
104
|
+
JSONParser(), // needed to read the buffer and check if is a valid JSON and set ctx.body
|
|
214
105
|
]);
|
|
215
106
|
|
|
216
107
|
router.post("/echo", async (ctx) => {
|
|
108
|
+
// the incomingMessage is in ctx.req
|
|
109
|
+
// the ServerResponse is in ctx.res
|
|
110
|
+
ctx.logger.info("we got a echo request");
|
|
217
111
|
ctx.json({
|
|
218
112
|
body: ctx.body
|
|
219
113
|
}):
|
|
@@ -223,73 +117,65 @@ router.get("/user/:userId", async (ctx) => {
|
|
|
223
117
|
userId: ctx.params.userId
|
|
224
118
|
}):
|
|
225
119
|
});
|
|
226
|
-
app.use(router, "/api");
|
|
227
120
|
|
|
228
|
-
//
|
|
229
|
-
//
|
|
230
|
-
createServer(
|
|
231
|
-
|
|
121
|
+
// for using just the router and not the default error handling and 404
|
|
122
|
+
// http.createServer(router.listener).listen(8080);
|
|
123
|
+
http.createServer(new App().use(router).listener).listen(8080);
|
|
124
|
+
// or
|
|
125
|
+
// new App().use(router).listen(8080)
|
|
232
126
|
```
|
|
233
127
|
|
|
234
|
-
|
|
128
|
+
## router.use extended options for request parsing
|
|
235
129
|
|
|
236
130
|
```typescript
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
131
|
+
app.get("/add/:a/:b", {
|
|
132
|
+
request: {
|
|
133
|
+
query: false, // do not allow query params
|
|
134
|
+
body: false, // do not allow body
|
|
135
|
+
params: {
|
|
136
|
+
options: {
|
|
137
|
+
a: "number", // parse param :a to a number if posible if not throw 400
|
|
138
|
+
b: "number" // parse param :b to a number if posible if not throw 400
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
handler: async (ctx) => {
|
|
143
|
+
// ctx.params.a and ctx.params.b are numbers and not strings
|
|
144
|
+
const result = ctx.params.a + ctx.params.b;
|
|
145
|
+
ctx.logger.info("adding %s + %s = %s", ctx.params.a, ctx.params.b, result);
|
|
146
|
+
ctx.json({
|
|
147
|
+
result
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
// or
|
|
152
|
+
/*
|
|
153
|
+
app.get("/add/:a/:b", async (ctx) => {
|
|
154
|
+
return {
|
|
155
|
+
result: ctx.params.a + ctx.params.b
|
|
156
|
+
}
|
|
157
|
+
}, {
|
|
158
|
+
request: {
|
|
260
159
|
...
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
return 2;
|
|
266
|
-
},
|
|
267
|
-
async (ctx)=>{
|
|
268
|
-
// ctx.results will have [123, 2]
|
|
160
|
+
},
|
|
161
|
+
response: {
|
|
162
|
+
options: {
|
|
163
|
+
result: "number"
|
|
269
164
|
},
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
165
|
+
mode: "remove_extra"
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
*/
|
|
273
169
|
```
|
|
274
170
|
|
|
275
|
-
|
|
171
|
+
## error handling
|
|
276
172
|
|
|
277
173
|
```typescript
|
|
278
|
-
...
|
|
279
174
|
app.catch(myFallBackerrorHandler1) // this will catch all throws
|
|
280
|
-
app.catch(myFallBackerrorHandler2) //
|
|
281
|
-
|
|
282
|
-
app.use(
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
// for example this is interpreted as a 400 if req.body doesnt match
|
|
286
|
-
parse("body", body, [
|
|
287
|
-
{ name: "name", type: "string", required: true },
|
|
288
|
-
{ name: "age", type: "number", required: true },
|
|
289
|
-
{ name: "likes", type: "array", required: true, arrayType: "string" }
|
|
290
|
-
], "no_extra");
|
|
291
|
-
},
|
|
292
|
-
...
|
|
293
|
-
]);
|
|
175
|
+
app.catch(myFallBackerrorHandler2) // if myFallBackerrorHandler1 didnt ended the request myFallBackerrorHandler2 will be called
|
|
176
|
+
|
|
177
|
+
app.use(async (ctx) => {
|
|
178
|
+
throw new Error("");
|
|
179
|
+
});
|
|
294
180
|
```
|
|
295
181
|
|
|
@@ -5,6 +5,7 @@ import { ParseOptions } from "../util/parser/common";
|
|
|
5
5
|
import { Handler } from "./common";
|
|
6
6
|
export interface APIHandlerOptions {
|
|
7
7
|
parser?: Parser;
|
|
8
|
+
headers?: ParseOptions | ParseOptions[];
|
|
8
9
|
query?: ParseOptions | false | ParseOptions[];
|
|
9
10
|
params?: ParseOptions | false | ParseOptions[];
|
|
10
11
|
body?: ParseOptions | false | ParseOptions[];
|
|
@@ -13,7 +14,6 @@ export interface APIHandlerOptions {
|
|
|
13
14
|
middleware?: Handler[];
|
|
14
15
|
session?: SessionHandlerOptions | Handler;
|
|
15
16
|
policy?: GroupPolicy;
|
|
16
|
-
responseHandler?: Handler;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* APIHandler
|
|
@@ -26,6 +26,7 @@ const APIHandler = (options) =>
|
|
|
26
26
|
.concat(options.policy ? [(0, group_1.GroupPolicyHandler)(options.policy)] : [])
|
|
27
27
|
// setup request parse
|
|
28
28
|
.concat([(0, parse_1.ParseRequest)({
|
|
29
|
+
headers: options.headers,
|
|
29
30
|
query: options.query,
|
|
30
31
|
params: options.params,
|
|
31
32
|
body: options.body,
|
|
@@ -36,6 +37,6 @@ const APIHandler = (options) =>
|
|
|
36
37
|
// setup response parse
|
|
37
38
|
.concat(options.result ? (0, result_1.ResultParser)(options.result, options.parser) : [])
|
|
38
39
|
// setup response handler
|
|
39
|
-
.concat(
|
|
40
|
+
.concat((0, json_1.ResponseHandler)());
|
|
40
41
|
exports.APIHandler = APIHandler;
|
|
41
42
|
//# sourceMappingURL=api-handler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-handler.js","sourceRoot":"","sources":["../../src/handler/api-handler.ts"],"names":[],"mappings":";;;AACA,kDAA6E;AAC7E,8CAAwD;AAIxD,8CAAkD;AAClD,0CAAkD;AAClD,8CAAiD;AAejD;;;;;;;;;;GAUG;AACI,MAAM,UAAU,GAAG,CAAC,OAA0B,EAAkB,EAAE;AACvE,2BAA2B;AA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GAAE,CAAC,CAAC;AApBlB,QAAA,UAAU,cAoBQ"}
|
|
@@ -1,10 +1,3 @@
|
|
|
1
1
|
import { Logger } from "../util/logger";
|
|
2
|
-
import { APIRoute } from "./api-router";
|
|
3
|
-
import { Method } from "./common";
|
|
4
2
|
import { FeatureRouterOptions } from "./feature-router";
|
|
5
|
-
|
|
6
|
-
method: Method | Method[];
|
|
7
|
-
path: string | string[];
|
|
8
|
-
}
|
|
9
|
-
export declare const traverseAPIRouteDir: (featureName: string, dirname: string, basePath?: string, features?: FeatureRouterOptions<TraversedAPIRoute>, logger?: Logger | undefined) => FeatureRouterOptions<TraversedAPIRoute>;
|
|
10
|
-
export {};
|
|
3
|
+
export declare const traverseAPIRouteDir: (featureName: string, dirname: string, basePath?: string, features?: FeatureRouterOptions, logger?: Logger | undefined) => FeatureRouterOptions;
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.traverseAPIRouteDir = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
const api_handler_1 = require("./api-handler");
|
|
7
6
|
const tokenize_match_1 = require("./common/tokenize-match");
|
|
8
7
|
const traverseAPIRouteDir = (featureName, dirname, basePath = "/", features = {}, logger) => {
|
|
9
8
|
if (logger) {
|
|
@@ -64,21 +63,24 @@ const traverseAPIRouteDir = (featureName, dirname, basePath = "/", features = {}
|
|
|
64
63
|
throw new Error(`${___filePath} feature name collides with ${features[newFeatureSubPath].___filePath}`);
|
|
65
64
|
}
|
|
66
65
|
features[newFeatureSubPath] = {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
options: {
|
|
67
|
+
name: route.name,
|
|
68
|
+
description: route.description,
|
|
69
|
+
parser: route.parser,
|
|
70
|
+
middleware: route.middleware,
|
|
71
71
|
session: route.session,
|
|
72
72
|
policy: route.policy,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
request: {
|
|
74
|
+
headers: route.headers,
|
|
75
|
+
query: route.query,
|
|
76
|
+
body: route.body,
|
|
77
|
+
params: route.params,
|
|
78
|
+
},
|
|
79
|
+
response: route.result ? route.result : true
|
|
80
|
+
},
|
|
81
|
+
path,
|
|
82
|
+
method: routeMethods,
|
|
83
|
+
handler: route.handler
|
|
82
84
|
};
|
|
83
85
|
features[newFeatureSubPath].___filePath = ___filePath;
|
|
84
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-router-utils.js","sourceRoot":"","sources":["../../src/handler/api-router-utils.ts"],"names":[],"mappings":";;;AAAA,2BAA4C;AAC5C,+BAA4C;
|
|
1
|
+
{"version":3,"file":"api-router-utils.js","sourceRoot":"","sources":["../../src/handler/api-router-utils.ts"],"names":[],"mappings":";;;AAAA,2BAA4C;AAC5C,+BAA4C;AAI5C,4DAAwD;AAGjD,MAAM,mBAAmB,GAAG,CACjC,WAAmB,EACnB,OAAe,EACf,QAAQ,GAAG,GAAG,EACd,WAAiC,EAAE,EAAE,MAAe,EAAwB,EAAE;IAC9E,IAAI,MAAM,EAAE;QACV,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAAC;KACnD;IACD,MAAM,KAAK,GAAG,IAAA,gBAAW,EAAC,OAAO,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,IAAA,cAAS,EAAC,IAAA,WAAI,EAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IAC1E,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAA,cAAS,EAAC,IAAA,WAAI,EAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EA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ACF;KACF;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAzFW,QAAA,mBAAmB,uBAyF9B"}
|
package/dist/handler/app.d.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Router, Context } from "./common";
|
|
5
|
-
export interface AppOptions {
|
|
6
|
-
newRequestLogger?: (req: IncomingMessage) => Logger;
|
|
7
|
-
newContext?: (req: IncomingMessage, res: ServerResponse) => Context;
|
|
8
|
-
}
|
|
2
|
+
import { RequestListener, Server } from "http";
|
|
3
|
+
import { Router, RouterOptions } from "./common";
|
|
9
4
|
export declare class App extends Router {
|
|
10
|
-
private appOptions?;
|
|
11
5
|
readonly listener: RequestListener;
|
|
12
|
-
constructor(
|
|
6
|
+
constructor(config?: RouterOptions);
|
|
13
7
|
listen(...args: any[]): Server;
|
|
14
8
|
}
|
package/dist/handler/app.js
CHANGED
|
@@ -4,15 +4,14 @@ exports.App = void 0;
|
|
|
4
4
|
const http_1 = require("http");
|
|
5
5
|
const common_1 = require("./common");
|
|
6
6
|
class App extends common_1.Router {
|
|
7
|
-
constructor(
|
|
8
|
-
super();
|
|
9
|
-
this.appOptions = appOptions;
|
|
7
|
+
constructor(config) {
|
|
8
|
+
super(config);
|
|
10
9
|
const errorHandler = DefaultErrorHandler();
|
|
11
10
|
this.listener = async (req, res) => {
|
|
12
|
-
const ctx = this.
|
|
13
|
-
this.
|
|
14
|
-
new common_1.Context(req, res, this.
|
|
15
|
-
this.
|
|
11
|
+
const ctx = this.config && this.config.newContext ?
|
|
12
|
+
this.config.newContext(req, res) :
|
|
13
|
+
new common_1.Context(req, res, this.config && this.config.newRequestLogger ?
|
|
14
|
+
this.config.newRequestLogger(req) :
|
|
16
15
|
undefined);
|
|
17
16
|
ctx.logger.trace(`request received`);
|
|
18
17
|
try {
|
|
@@ -27,10 +26,7 @@ class App extends common_1.Router {
|
|
|
27
26
|
}
|
|
28
27
|
catch (e) {
|
|
29
28
|
try {
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
catch (e2) {
|
|
33
|
-
try {
|
|
29
|
+
if (!ctx.res.headersSent) {
|
|
34
30
|
await errorHandler(e, ctx);
|
|
35
31
|
if (!ctx.res.headersSent) {
|
|
36
32
|
ctx.logger.error(e);
|
|
@@ -41,9 +37,9 @@ class App extends common_1.Router {
|
|
|
41
37
|
});
|
|
42
38
|
}
|
|
43
39
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
}
|
|
41
|
+
catch (e3) {
|
|
42
|
+
ctx.logger.error(e3);
|
|
47
43
|
}
|
|
48
44
|
}
|
|
49
45
|
};
|
package/dist/handler/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/handler/app.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/handler/app.ts"],"names":[],"mappings":";;;AAAA,+BAA6D;AAC7D,qCAAwE;AAExE,MAAa,GAAI,SAAQ,eAAM;IAG7B,YAAY,MAAsB;QAChC,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,MAAM,YAAY,GAAG,mBAAmB,EAAE,CAAC;QAC3C,IAAI,CAAC,QAAQ,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;YACjC,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBACjD,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;gBAClC,IAAI,gBAAO,CACT,GAAG,EACH,GAAG,EACH,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;oBAC3C,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,C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AAO,EAAE,YAAY;wBACrB,MAAM,EAAE,MAAM,CAAC,KAAK;wBACpB,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc;qBAC7C,CAAC,CAAC;oBACH,MAAM;aACT;YACD,OAAO,KAAK,CAAC;SACd;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Router } from "./router";
|
|
2
|
+
import { Context, Handler } from "./context";
|
|
3
|
+
import { Method } from "./context";
|
|
4
|
+
import { PathPartToken } from "./tokenize-match";
|
|
5
|
+
import { Parser, ParseOptions } from "../../util/parser";
|
|
6
|
+
import { SessionHandlerOptions } from "../middleware/session";
|
|
7
|
+
import { GroupPolicy } from "../../util/session";
|
|
8
|
+
export interface HandlerWithOptions extends RouterHandlerOptions {
|
|
9
|
+
handler: Handler | Array<Handler>;
|
|
10
|
+
}
|
|
11
|
+
export interface RouteOptions {
|
|
12
|
+
name?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
policy?: GroupPolicy;
|
|
15
|
+
request?: {
|
|
16
|
+
headers?: ParseOptions | ParseOptions[];
|
|
17
|
+
query?: ParseOptions | false | ParseOptions[];
|
|
18
|
+
params?: ParseOptions | false | ParseOptions[];
|
|
19
|
+
body?: ParseOptions | false | ParseOptions[];
|
|
20
|
+
};
|
|
21
|
+
response?: true | ParseOptions | ParseOptions[];
|
|
22
|
+
}
|
|
23
|
+
export interface RouteJSONDoc extends RouteOptions {
|
|
24
|
+
identifier: string;
|
|
25
|
+
}
|
|
26
|
+
export interface RouterJSONDoc {
|
|
27
|
+
[path: string]: {
|
|
28
|
+
[method: string]: RouteJSONDoc;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export interface RouterHandlerOptions extends RouteOptions {
|
|
32
|
+
parser?: Parser;
|
|
33
|
+
middleware?: Handler | Handler[];
|
|
34
|
+
session?: SessionHandlerOptions | Handler;
|
|
35
|
+
}
|
|
36
|
+
export declare class RouterHandler {
|
|
37
|
+
private readonly path;
|
|
38
|
+
private readonly method;
|
|
39
|
+
private readonly tokens;
|
|
40
|
+
private readonly handler;
|
|
41
|
+
private readonly isRouter;
|
|
42
|
+
private readonly options?;
|
|
43
|
+
constructor(handler: Array<Handler> | HandlerWithOptions | Handler | Router, path: string | undefined, method: Method | undefined, options?: RouterHandlerOptions);
|
|
44
|
+
getJSONDoc(doc?: RouterJSONDoc, prePath?: string): RouterJSONDoc;
|
|
45
|
+
invoke(ctx: Context, pathTokens: {
|
|
46
|
+
value: string;
|
|
47
|
+
lower: string;
|
|
48
|
+
}[], prePathTokens: PathPartToken[]): Promise<boolean>;
|
|
49
|
+
isMatch(method: string, pathTokens: {
|
|
50
|
+
value: string;
|
|
51
|
+
lower: string;
|
|
52
|
+
}[], prePathTokens: PathPartToken[]): {
|
|
53
|
+
match: boolean;
|
|
54
|
+
params?: {
|
|
55
|
+
[name: string]: string | undefined;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
private pushResults;
|
|
59
|
+
}
|