@miqro/core 1.5.21 → 1.7.0
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 +101 -41
- package/dist/api-router.d.ts +1 -1
- package/dist/common/api-router-utils.d.ts +2 -2
- package/dist/common/api-router-utils.js +6 -21
- package/dist/common/api-router-utils.js.map +1 -1
- package/dist/common/api-router.d.ts +18 -0
- package/dist/common/{api-router-helpers.js → api-router.js} +1 -1
- package/dist/common/api-router.js.map +1 -0
- package/dist/common/config/config.d.ts +1 -1
- package/dist/common/config/loader.d.ts +3 -3
- package/dist/common/context.d.ts +3 -1
- package/dist/common/index.d.ts +1 -1
- package/dist/common/index.js +1 -1
- package/dist/common/index.js.map +1 -1
- package/dist/common/logger/constants.d.ts +13 -0
- package/dist/common/logger/constants.js +26 -0
- package/dist/common/logger/constants.js.map +1 -0
- package/dist/common/logger/factory.d.ts +5 -7
- package/dist/common/logger/factory.js +7 -3
- package/dist/common/logger/factory.js.map +1 -1
- package/dist/common/logger/index.d.ts +5 -5
- package/dist/common/logger/index.js +5 -4
- package/dist/common/logger/index.js.map +1 -1
- package/dist/common/logger/{transport.d.ts → interfaces.d.ts} +6 -3
- package/dist/common/logger/interfaces.js +3 -0
- package/dist/common/logger/interfaces.js.map +1 -0
- package/dist/common/logger/logger.d.ts +15 -7
- package/dist/common/logger/logger.js +35 -27
- package/dist/common/logger/logger.js.map +1 -1
- package/dist/common/logger/transport/console.d.ts +5 -0
- package/dist/common/logger/transport/console.js +39 -0
- package/dist/common/logger/transport/console.js.map +1 -0
- package/dist/common/logger/transport/file.d.ts +2 -0
- package/dist/common/logger/transport/file.js +29 -0
- package/dist/common/logger/transport/file.js.map +1 -0
- package/dist/common/router-helpers.d.ts +1 -1
- package/dist/common/router-helpers.js +3 -3
- package/dist/common/router-helpers.js.map +1 -1
- package/dist/common/tokenize-match.d.ts +1 -1
- package/dist/middleware/buffer.d.ts +3 -3
- package/dist/middleware/cors.d.ts +1 -1
- package/dist/middleware/form.d.ts +4 -4
- package/dist/middleware/json.d.ts +4 -4
- package/dist/middleware/parse.d.ts +1 -1
- package/dist/middleware/result.d.ts +1 -1
- package/dist/middleware/tag.d.ts +2 -2
- package/dist/middleware/text.d.ts +3 -3
- package/dist/proxy.js +1 -0
- package/dist/proxy.js.map +1 -1
- package/dist/router.d.ts +1 -1
- package/package.json +9 -10
- package/src/api-router.ts +1 -1
- package/src/common/api-router-utils.ts +18 -34
- package/src/common/api-router.ts +19 -0
- package/src/common/context.ts +1 -1
- package/src/common/index.ts +1 -1
- package/src/common/logger/constants.ts +27 -0
- package/src/common/logger/factory.ts +11 -9
- package/src/common/logger/index.ts +5 -5
- package/src/common/logger/interfaces.ts +19 -0
- package/src/common/logger/logger.ts +52 -30
- package/src/common/logger/transport/console.ts +34 -0
- package/src/common/logger/transport/file.ts +26 -0
- package/src/common/router-helpers.ts +2 -2
- package/src/proxy.ts +1 -0
- package/src/router.ts +1 -1
- package/dist/common/api-router-helpers.d.ts +0 -31
- package/dist/common/api-router-helpers.js.map +0 -1
- package/dist/common/logger/common.d.ts +0 -4
- package/dist/common/logger/common.js +0 -7
- package/dist/common/logger/common.js.map +0 -1
- package/dist/common/logger/formatter.d.ts +0 -7
- package/dist/common/logger/formatter.js +0 -9
- package/dist/common/logger/formatter.js.map +0 -1
- package/dist/common/logger/transport.js +0 -59
- package/dist/common/logger/transport.js.map +0 -1
- package/src/common/api-router-helpers.ts +0 -32
- package/src/common/logger/common.ts +0 -6
- package/src/common/logger/formatter.ts +0 -9
- package/src/common/logger/transport.ts +0 -71
- package/src/proxy.func.test.js +0 -65
|
@@ -1,44 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Logger = void 0;
|
|
3
|
+
exports.Logger = exports.LoggerErrorEvent = void 0;
|
|
4
4
|
const util_1 = require("util");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"error": 1,
|
|
15
|
-
"warn": 2,
|
|
16
|
-
"info": 3,
|
|
17
|
-
"debug": 4,
|
|
18
|
-
"trace": 5,
|
|
19
|
-
};
|
|
20
|
-
class Logger extends events_1.EventEmitter {
|
|
5
|
+
const constants_js_1 = require("./constants.js");
|
|
6
|
+
class LoggerErrorEvent extends Event {
|
|
7
|
+
constructor(event, init) {
|
|
8
|
+
super(event, init);
|
|
9
|
+
this.error = init.error;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.LoggerErrorEvent = LoggerErrorEvent;
|
|
13
|
+
class Logger extends EventTarget {
|
|
21
14
|
constructor(identifier, level = "info", options) {
|
|
22
15
|
super();
|
|
23
16
|
this.identifier = identifier;
|
|
24
17
|
this.level = level;
|
|
25
|
-
if (!LOG_LEVEL_MAP[level]) {
|
|
18
|
+
if (!constants_js_1.LOG_LEVEL_MAP[level]) {
|
|
26
19
|
throw new Error(`Unknown level [${level}]`);
|
|
27
20
|
}
|
|
28
|
-
this.
|
|
29
|
-
console.error(
|
|
21
|
+
this.addEventListener(constants_js_1.LoggerEvents.error, (ev) => {
|
|
22
|
+
console.error(ev.error);
|
|
30
23
|
});
|
|
31
24
|
this.options = {
|
|
32
|
-
transports: options && options.transports !== undefined ? options.transports :
|
|
33
|
-
formatter: options && options.formatter !== undefined ? options.formatter :
|
|
25
|
+
transports: options && options.transports !== undefined ? options.transports : (0, constants_js_1.DEFAULT_LOGGER_TRANSPORTS)(),
|
|
26
|
+
formatter: options && options.formatter !== undefined ? options.formatter : constants_js_1.DEFAULT_LOGGER_FORMATTER,
|
|
34
27
|
};
|
|
35
28
|
}
|
|
29
|
+
setLevel(level) {
|
|
30
|
+
if (!constants_js_1.LOG_LEVEL_MAP[level]) {
|
|
31
|
+
throw new Error(`Unknown level [${level}]`);
|
|
32
|
+
}
|
|
33
|
+
this.level = level;
|
|
34
|
+
}
|
|
35
|
+
addTransport(transport) {
|
|
36
|
+
this.options.transports.push(transport);
|
|
37
|
+
}
|
|
36
38
|
write(args) {
|
|
37
39
|
try {
|
|
38
40
|
let eventArgs = undefined;
|
|
39
41
|
const tR = [];
|
|
40
42
|
for (const transport of this.options.transports) {
|
|
41
|
-
if (LOG_LEVEL_MAP[transport.level ? transport.level : this.level] >= LOG_LEVEL_MAP[args.level]) {
|
|
43
|
+
if (constants_js_1.LOG_LEVEL_MAP[transport.level ? transport.level : this.level] >= constants_js_1.LOG_LEVEL_MAP[args.level]) {
|
|
42
44
|
try {
|
|
43
45
|
eventArgs = eventArgs ? eventArgs : {
|
|
44
46
|
out: this.options.formatter({
|
|
@@ -51,16 +53,22 @@ class Logger extends events_1.EventEmitter {
|
|
|
51
53
|
tR.push(transport.write(eventArgs));
|
|
52
54
|
}
|
|
53
55
|
catch (e2) {
|
|
54
|
-
this.
|
|
56
|
+
this.dispatchEvent(new LoggerErrorEvent(constants_js_1.LoggerEvents.error, {
|
|
57
|
+
error: e2
|
|
58
|
+
}));
|
|
55
59
|
}
|
|
56
60
|
}
|
|
57
61
|
}
|
|
58
|
-
Promise.
|
|
59
|
-
this.
|
|
62
|
+
Promise.allSettled(tR).catch((e) => {
|
|
63
|
+
this.dispatchEvent(new LoggerErrorEvent(constants_js_1.LoggerEvents.error, {
|
|
64
|
+
error: e
|
|
65
|
+
}));
|
|
60
66
|
});
|
|
61
67
|
}
|
|
62
68
|
catch (e) {
|
|
63
|
-
this.
|
|
69
|
+
this.dispatchEvent(new LoggerErrorEvent(constants_js_1.LoggerEvents.error, {
|
|
70
|
+
error: e
|
|
71
|
+
}));
|
|
64
72
|
}
|
|
65
73
|
}
|
|
66
74
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/common/logger/logger.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;
|
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,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAC,CAAC,CAAC;IAC9D,CAAC;CACF;AA7FD,wBA6FC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Console = void 0;
|
|
4
|
+
function Console(color = true, level) {
|
|
5
|
+
return {
|
|
6
|
+
level,
|
|
7
|
+
write: async ({ level, out }) => {
|
|
8
|
+
if (color) {
|
|
9
|
+
switch (level) {
|
|
10
|
+
case "warn":
|
|
11
|
+
console.warn("\x1b[33m%s\x1b[0m", out);
|
|
12
|
+
break;
|
|
13
|
+
case "error":
|
|
14
|
+
console.error("\x1b[31m%s\x1b[0m", out);
|
|
15
|
+
break;
|
|
16
|
+
case "trace":
|
|
17
|
+
console.log("\x1b[34m%s\x1b[0m", out);
|
|
18
|
+
break;
|
|
19
|
+
case "debug":
|
|
20
|
+
console.log("\x1b[36m%s\x1b[0m", out);
|
|
21
|
+
break;
|
|
22
|
+
default:
|
|
23
|
+
console[level](out);
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
if (level === "trace" || level === "debug") {
|
|
29
|
+
console.log(out);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
console[level](out);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.Console = Console;
|
|
39
|
+
//# sourceMappingURL=console.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.js","sourceRoot":"","sources":["../../../../src/common/logger/transport/console.ts"],"names":[],"mappings":";;;AAEA,SAAgB,OAAO,CAAC,QAAiB,IAAI,EAAE,KAAgB;IAC7D,OAAO;QACL,KAAK;QACL,KAAK,EAAE,KAAK,EAAE,EAAC,KAAK,EAAE,GAAG,EAA2B,EAAiB,EAAE;YACrE,IAAI,KAAK,EAAE;gBACT,QAAQ,KAAK,EAAE;oBACb,KAAK,MAAM;wBACT,OAAO,CAAC,IAAI,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC;wBACvC,MAAM;oBACR,KAAK,OAAO;wBACV,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC;wBACxC,MAAM;oBACR,KAAK,OAAO;wBACV,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC;wBACtC,MAAM;oBACR,KAAK,OAAO;wBACV,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC;wBACtC,MAAM;oBACR;wBACE,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;wBACpB,MAAM;iBACT;aACF;iBAAM;gBACL,IAAG,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,OAAO,EAAE;oBACzC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;iBAClB;qBAAM;oBACL,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;iBACrB;aACF;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AA/BD,0BA+BC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.File = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const FILE_TRANSPORT_ENVVAR = "LOG_FILE";
|
|
7
|
+
const File = (filePath = process.env[FILE_TRANSPORT_ENVVAR] ? process.env[FILE_TRANSPORT_ENVVAR] : null, level) => {
|
|
8
|
+
const fileHandler = filePath ? (0, fs_1.createWriteStream)((0, path_1.resolve)(filePath), { flags: "a" }) : null;
|
|
9
|
+
return {
|
|
10
|
+
level,
|
|
11
|
+
write: async ({ out }) => {
|
|
12
|
+
if (fileHandler) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
fileHandler.write(`${out}\n`, (err) => {
|
|
15
|
+
if (err) {
|
|
16
|
+
reject(err);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
resolve();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
exports.File = File;
|
|
29
|
+
//# sourceMappingURL=file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../../../src/common/logger/transport/file.ts"],"names":[],"mappings":";;;AAAA,2BAAqC;AACrC,+BAA6B;AAG7B,MAAM,qBAAqB,GAAG,UAAU,CAAC;AAElC,MAAM,IAAI,GAAoE,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,KAAgB,EAAE,EAAE;IACnM,MAAM,WAAW,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAA,sBAAiB,EAAC,IAAA,cAAO,EAAC,QAAQ,CAAC,EAAE,EAAC,KAAK,EAAE,GAAG,EAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACzF,OAAO;QACL,KAAK;QACL,KAAK,EAAE,KAAK,EAAE,EAAC,GAAG,EAA2B,EAAiB,EAAE;YAC9D,IAAI,WAAW,EAAE;gBACf,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;oBACrC,WAAW,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE;wBACpC,IAAI,GAAG,EAAE;4BACP,MAAM,CAAC,GAAG,CAAC,CAAC;yBACb;6BAAM;4BACL,OAAO,EAAE,CAAC;yBACX;oBACH,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;aACJ;YACD,OAAO;QACT,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,IAAI,QAmBf"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultLoggerFactory = void 0;
|
|
4
|
-
const logger_1 = require("./logger");
|
|
5
4
|
const helpers_1 = require("./helpers");
|
|
6
5
|
const tokenize_match_1 = require("./tokenize-match");
|
|
6
|
+
const index_js_1 = require("./logger/index.js");
|
|
7
7
|
const defaultLoggerFactory = (uuid, req) => {
|
|
8
8
|
const url = (0, helpers_1.newURL)(req.url ? req.url : "/", `http://${req.headers.host}`);
|
|
9
9
|
const method = req.method ? req.method.toUpperCase() : "GET";
|
|
@@ -11,10 +11,10 @@ const defaultLoggerFactory = (uuid, req) => {
|
|
|
11
11
|
const pathToEnv = path.replace(/\//ig, "_").toUpperCase();
|
|
12
12
|
const identifier = `${pathToEnv === "_" ? "" : pathToEnv.substring(1)}${method.toUpperCase()}`;
|
|
13
13
|
const remoteAddress = req.socket.remoteAddress;
|
|
14
|
-
return (0,
|
|
14
|
+
return (0, index_js_1.getLogger)(identifier, {
|
|
15
15
|
formatter: (args) => {
|
|
16
16
|
args.message = `${method} ${url}${uuid ? ` [${uuid}]` : ""}${remoteAddress ? ` (${remoteAddress})` : ""} ${args.message}`;
|
|
17
|
-
return (0,
|
|
17
|
+
return (0, index_js_1.DEFAULT_LOGGER_FORMATTER)(args);
|
|
18
18
|
}
|
|
19
19
|
}, false);
|
|
20
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-helpers.js","sourceRoot":"","sources":["../../src/common/router-helpers.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"router-helpers.js","sourceRoot":"","sources":["../../src/common/router-helpers.ts"],"names":[],"mappings":";;;AAEA,uCAAiC;AACjC,qDAA+C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AC,CAAA;AAbY,QAAA,oBAAoB,wBAahC"}
|
|
@@ -15,7 +15,7 @@ export interface PathPart {
|
|
|
15
15
|
value: string;
|
|
16
16
|
lower: string;
|
|
17
17
|
}
|
|
18
|
-
export declare const splitPath: (path?: string
|
|
18
|
+
export declare const splitPath: (path?: string) => PathPart[];
|
|
19
19
|
export declare function tokenizePath(path?: string): PathPartToken[];
|
|
20
20
|
export declare function matchTokenizePath(checkAsRouter: boolean, pathTokens: PathPartToken[], requestParts: PathPart[]): {
|
|
21
21
|
match: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Handler } from "../common";
|
|
2
2
|
export declare const DEFAULT_READ_BUFFER_LIMIT: number;
|
|
3
3
|
export declare const ReadBuffer: (options?: {
|
|
4
|
-
limit?: number
|
|
5
|
-
timeout?: number
|
|
6
|
-
}
|
|
4
|
+
limit?: number;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
}) => Handler<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Handler } from "../common";
|
|
2
2
|
export declare const URLEncodedParser: (options?: {
|
|
3
|
-
limit?: number
|
|
4
|
-
maxKeys?: number
|
|
5
|
-
type?: string
|
|
6
|
-
}
|
|
3
|
+
limit?: number;
|
|
4
|
+
maxKeys?: number;
|
|
5
|
+
type?: string;
|
|
6
|
+
}) => Handler<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Handler } from "../common";
|
|
2
2
|
export declare const JSONParser: (options?: {
|
|
3
|
-
limit?: number
|
|
4
|
-
strict?: boolean
|
|
5
|
-
type?: string
|
|
6
|
-
}
|
|
3
|
+
limit?: number;
|
|
4
|
+
strict?: boolean;
|
|
5
|
+
type?: string;
|
|
6
|
+
}) => Handler<void>;
|
|
@@ -6,4 +6,4 @@ export interface ParseRequestOptions {
|
|
|
6
6
|
params?: ParseOptions | boolean | ParseOptions[] | string;
|
|
7
7
|
body?: ParseOptions | boolean | ParseOptions[] | string;
|
|
8
8
|
}
|
|
9
|
-
export declare const ParseRequest: (options: ParseRequestOptions, parser?: ParserInterface
|
|
9
|
+
export declare const ParseRequest: (options: ParseRequestOptions, parser?: ParserInterface) => Handler<void>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ParseOptions, ParserInterface } from "@miqro/parser";
|
|
2
2
|
import { Handler } from "../common/context";
|
|
3
|
-
export declare const ResultParser: (options: ParseOptions | ParseOptions[] | string, parser?: ParserInterface
|
|
3
|
+
export declare const ResultParser: (options: ParseOptions | ParseOptions[] | string, parser?: ParserInterface) => Handler;
|
package/dist/middleware/tag.d.ts
CHANGED
package/dist/proxy.js
CHANGED
package/dist/proxy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":";;;AACA,4CAAuD;AACvD,qCAA+C;AAC/C,4DAAqE;AACrE,6BAAwB;AAOxB,MAAM,WAAY,SAAQ,eAAM;IAI9B,YAAY,OAA2B;QACrC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,MAAM,QAAQ,GAAG,IAAI,SAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACtC,QAAQ,CAAC,QAAQ,GAAG,IAAA,8BAAa,EAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACrD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IACvD,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAY,EAAE,UAA+C,EAAE,gBAAiC,EAAE;QAE1G,MAAM,KAAK,GAAG,aAAa,CAAC,MAAM,CAAC;QACnC,MAAM,cAAc,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;QAEvE,IAAI,cAAc,EAAE;YAClB,MAAM,QAAQ,GAAG,GAAG,CAAC,IAAI,CAAC,KAA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ACtB,GAAG,QAAQ,CAAC,OAAO;aACpB,CAAC;YACF,OAAO,eAAe,CAAC,YAAY,CAAC,CAAC;YACrC,OAAO,eAAe,CAAC,YAAY,CAAC,CAAC;YAErC,MAAM,GAAG,CAAC,GAAG,CAAC;gBACZ,OAAO,EAAE,eAAe;gBACxB,IAAI,EAAE,QAAQ,CAAC,MAAM;gBACrB,MAAM,EAAE,QAAQ,CAAC,MAAM;aACxB,CAAC,CAAC;SACJ;QACD,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC;IAC9B,CAAC;CACF;AAEM,MAAM,KAAK,GAAG,CAAC,OAA2B,EAAE,EAAE;IACnD,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC,CAAA;AAFY,QAAA,KAAK,SAEjB"}
|
package/dist/router.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IncomingMessage, RequestListener } from "http";
|
|
3
|
-
import { Logger } from "./common/logger";
|
|
3
|
+
import { Logger } from "./common/logger/index.js";
|
|
4
4
|
import { Context, ErrorHandler, Handler, Method } from "./common/context";
|
|
5
5
|
import { HandlerWithOptions, RouterHandlerOptions, RouterJSONDoc } from "./common/router-utils";
|
|
6
6
|
import { PathPart, PathPartToken } from "./common/tokenize-match";
|
package/package.json
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miqro/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "commonjs",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"prepare": "npm run build",
|
|
9
10
|
"prebuild": "rm -Rf dist/;",
|
|
10
11
|
"build": "tsc",
|
|
11
12
|
"pretest": "npm run build",
|
|
12
|
-
"test": "LOG_LEVEL=debug NODE_ENV=test npx miqro-test -r src/ test/*.test.js -n "
|
|
13
|
-
"test:unit": "LOG_LEVEL=debug NODE_ENV=test npx miqro-test -r src/ -n ",
|
|
14
|
-
"test:func": "LOG_LEVEL=debug NODE_ENV=test npx miqro-test test/*.test.js -n "
|
|
13
|
+
"test": "LOG_LEVEL=debug NODE_ENV=test npx miqro-test -r src/ test/*.test.js -n "
|
|
15
14
|
},
|
|
16
15
|
"author": "claukers",
|
|
17
16
|
"license": "ISC",
|
|
18
17
|
"devDependencies": {
|
|
19
|
-
"@miqro/test": "0.2.
|
|
20
|
-
"@miqro/test-http": "0.0.
|
|
21
|
-
"@types/node": "
|
|
22
|
-
"typescript": "4.
|
|
18
|
+
"@miqro/test": "0.2.4",
|
|
19
|
+
"@miqro/test-http": "0.0.7",
|
|
20
|
+
"@types/node": "18.6.1",
|
|
21
|
+
"typescript": "4.7.4",
|
|
23
22
|
"@types/cookie": "0.4.1",
|
|
24
23
|
"@types/uuid": "8.3.4"
|
|
25
24
|
},
|
|
@@ -28,8 +27,8 @@
|
|
|
28
27
|
"npm": ">=6.0.0"
|
|
29
28
|
},
|
|
30
29
|
"dependencies": {
|
|
31
|
-
"@miqro/
|
|
32
|
-
"@miqro/
|
|
30
|
+
"@miqro/parser": "^0.1.5",
|
|
31
|
+
"@miqro/request": "^0.1.1",
|
|
33
32
|
"cookie": "0.5.0",
|
|
34
33
|
"uuid": "8.3.2"
|
|
35
34
|
}
|
package/src/api-router.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {existsSync, lstatSync} from "fs";
|
|
2
2
|
import {basename} from "path";
|
|
3
3
|
import {FeatureRouter, traverseAPIRouteDir} from "./common/api-router-utils";
|
|
4
|
-
import {Logger} from "./common/logger";
|
|
4
|
+
import {Logger} from "./common/logger/index.js";
|
|
5
5
|
import {parse, ParseOptionMap} from "@miqro/parser";
|
|
6
6
|
|
|
7
7
|
export interface APIRouterOptions {
|
|
@@ -1,29 +1,18 @@
|
|
|
1
|
-
import {lstatSync, readdirSync} from "fs";
|
|
2
|
-
import {join, parse as pathParse, resolve} from "path";
|
|
3
|
-
import {Logger} from "./logger";
|
|
4
|
-
import {APIRoute} from "./api-router
|
|
5
|
-
import {normalizePath} from "./tokenize-match";
|
|
6
|
-
import {isFeatureEnabled} from "./config";
|
|
7
|
-
import {Router} from "../router";
|
|
8
|
-
import {Handler, Method} from "./context";
|
|
9
|
-
import {RouterHandlerOptions} from "./router-utils";
|
|
10
|
-
import {parse, ParseOptionMap} from "@miqro/parser";
|
|
1
|
+
import { lstatSync, readdirSync } from "fs";
|
|
2
|
+
import { join, parse as pathParse, resolve } from "path";
|
|
3
|
+
import { Logger } from "./logger/index.js";
|
|
4
|
+
import { APIRoute } from "./api-router";
|
|
5
|
+
import { normalizePath } from "./tokenize-match";
|
|
6
|
+
import { isFeatureEnabled } from "./config";
|
|
7
|
+
import { Router } from "../router";
|
|
8
|
+
import { Handler, Method } from "./context";
|
|
9
|
+
import { handlerWithOptionsParseOptions, RouterHandlerOptions } from "./router-utils";
|
|
10
|
+
import { parse, ParseOptionMap } from "@miqro/parser";
|
|
11
11
|
|
|
12
12
|
export const APIRouteValidator: ParseOptionMap = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
path: "string[]!?",
|
|
17
|
-
parser: "ParserInterface?",
|
|
18
|
-
headers: "ParseOptions[]!?",
|
|
19
|
-
query: "boolean?|ParseOptions[]!?|string?",
|
|
20
|
-
params: "boolean?|ParseOptions[]!?|string?",
|
|
21
|
-
body: "boolean?|ParseOptions[]!?|string?",
|
|
22
|
-
response: "ParseOptions[]!?|string?",
|
|
23
|
-
handler: "function[]!",
|
|
24
|
-
middleware: "function[]!?",
|
|
25
|
-
session: "function?|SessionHandlerOptions?",
|
|
26
|
-
policy: "GroupPolicy?"
|
|
13
|
+
...handlerWithOptionsParseOptions,
|
|
14
|
+
method: "string?|string[]?",
|
|
15
|
+
path: "string?|string[]?"
|
|
27
16
|
};
|
|
28
17
|
|
|
29
18
|
export function traverseAPIRouteDir(
|
|
@@ -38,11 +27,11 @@ export function traverseAPIRouteDir(
|
|
|
38
27
|
const dirs = files.filter(f => lstatSync(join(dirname, f)).isDirectory());
|
|
39
28
|
const methods = files.filter(f => !lstatSync(join(dirname, f)).isDirectory());
|
|
40
29
|
for (const f of dirs) {
|
|
41
|
-
const {name} = pathParse(f);
|
|
30
|
+
const { name } = pathParse(f);
|
|
42
31
|
features = traverseAPIRouteDir(`${featureName}_${name}`.toUpperCase(), join(dirname, f), `${basePath}/${name}`, features, logger);
|
|
43
32
|
}
|
|
44
33
|
for (const f of methods) {
|
|
45
|
-
const {name, ext} = pathParse(f);
|
|
34
|
+
const { name, ext } = pathParse(f);
|
|
46
35
|
if (name !== "index" && ((ext === ".ts" || ext === ".js") && name.slice(-2) !== ".d")) {
|
|
47
36
|
const filePath = join(dirname, name);
|
|
48
37
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
@@ -101,14 +90,9 @@ export function traverseAPIRouteDir(
|
|
|
101
90
|
middleware: route.middleware,
|
|
102
91
|
session: route.session,
|
|
103
92
|
policy: route.policy,
|
|
104
|
-
request:
|
|
105
|
-
headers: route.headers,
|
|
106
|
-
query: route.query,
|
|
107
|
-
body: route.body,
|
|
108
|
-
params: route.params,
|
|
109
|
-
},
|
|
93
|
+
request: route.request,
|
|
110
94
|
response: {
|
|
111
|
-
body: route.response ? route.response : true
|
|
95
|
+
body: route.response && route.response.body ? route.response.body : true
|
|
112
96
|
}
|
|
113
97
|
},
|
|
114
98
|
path,
|
|
@@ -144,7 +128,7 @@ export const FeatureRouter = (options: FeatureRouterOptions, logger?: Logger): R
|
|
|
144
128
|
if (!handlerOptions) {
|
|
145
129
|
throw new Error(`no handler options for feature [${featureName}]`);
|
|
146
130
|
} else {
|
|
147
|
-
const {path, handler: implementation, method} = handlerOptions;
|
|
131
|
+
const { path, handler: implementation, method } = handlerOptions;
|
|
148
132
|
if (!method) {
|
|
149
133
|
throw new Error(`no methods for feature [${featureName}]`);
|
|
150
134
|
} else if (!implementation) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Method } from "./context";
|
|
2
|
+
import { HandlerWithOptions } from "./router-utils";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* # APIRoute
|
|
6
|
+
*
|
|
7
|
+
* src/api/comment/get.js
|
|
8
|
+
* ```typescript
|
|
9
|
+
*import { APIRouter } from "@miqro/core";
|
|
10
|
+
*const route: APIRoute = {
|
|
11
|
+
* ...
|
|
12
|
+
*};
|
|
13
|
+
*export default route;
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export interface APIRoute extends HandlerWithOptions{
|
|
17
|
+
method?: Method | Method[];
|
|
18
|
+
path?: string | string[];
|
|
19
|
+
}
|
package/src/common/context.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {Logger} from "./logger";
|
|
1
|
+
import {Logger} from "./logger/index.js";
|
|
2
2
|
import {Session} from "./session";
|
|
3
3
|
import {IncomingHttpHeaders, IncomingMessage, OutgoingHttpHeaders, ServerResponse} from "http";
|
|
4
4
|
import {normalizePath, parseSearchParams} from "./tokenize-match";
|
package/src/common/index.ts
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {LoggerFormatter, LoggerTransport} from "./interfaces.js";
|
|
2
|
+
import {File} from "./transport/file.js";
|
|
3
|
+
import {Console} from "./transport/console.js";
|
|
4
|
+
|
|
5
|
+
export const DEFAULT_LOGGER_TRANSPORTS: () => LoggerTransport[] = () => [
|
|
6
|
+
Console(),
|
|
7
|
+
File()
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
export const DEFAULT_LOGGER_FORMATTER: LoggerFormatter =
|
|
11
|
+
({identifier, level, message}) => `${new Date().toISOString()} ${process.pid} ` +
|
|
12
|
+
`${identifier ? `[${identifier}] ` : ""}` +
|
|
13
|
+
`${level !== "info" ? (level === "error" || level === "warn" ? `[${level.toUpperCase()}] ` : `[${level}] `) : ""}` +
|
|
14
|
+
`${message}`;
|
|
15
|
+
|
|
16
|
+
export const LOG_LEVEL_MAP =
|
|
17
|
+
{
|
|
18
|
+
"error": 1,
|
|
19
|
+
"warn": 2,
|
|
20
|
+
"info": 3,
|
|
21
|
+
"debug": 4,
|
|
22
|
+
"trace": 5,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const LoggerEvents = {
|
|
26
|
+
error: "error"
|
|
27
|
+
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {ConfigStore} from "../config";
|
|
1
|
+
import { LoggerFormatter, LoggerTransport, LogLevel } from "./interfaces";
|
|
2
|
+
import { ConfigStore } from "../config";
|
|
3
|
+
import {Logger} from "./logger.js";
|
|
4
|
+
import {DEFAULT_LOGGER_FORMATTER, DEFAULT_LOGGER_TRANSPORTS} from "./constants.js";
|
|
6
5
|
|
|
7
6
|
const loggerContainer: Map<string, Logger> = new Map<string, Logger>();
|
|
8
7
|
const DEFAULT_ENV_NAME = "LOG_LEVEL";
|
|
@@ -17,7 +16,7 @@ export const getLogger = (identifier: string, options?: { formatter?: LoggerForm
|
|
|
17
16
|
const envVarName = `LOG_LEVEL_${identifier}`;
|
|
18
17
|
const level = ConfigStore.getConfig(envVarName) ? ConfigStore.getConfig(envVarName) as LogLevel : ConfigStore.getConfig(DEFAULT_ENV_NAME, "info") as LogLevel;
|
|
19
18
|
const factory = getLoggerFactory();
|
|
20
|
-
const logger = factory({identifier, level, options});
|
|
19
|
+
const logger = factory({ identifier, level, options });
|
|
21
20
|
if (useCache) {
|
|
22
21
|
loggerContainer.set(identifier, logger);
|
|
23
22
|
}
|
|
@@ -27,15 +26,18 @@ export const getLogger = (identifier: string, options?: { formatter?: LoggerForm
|
|
|
27
26
|
|
|
28
27
|
export type LoggerFactory = (args: { identifier: string, level: LogLevel; options?: { transports?: LoggerTransport[]; formatter?: LoggerFormatter; } }) => Logger;
|
|
29
28
|
|
|
30
|
-
const defaultLoggerFactory: LoggerFactory = ({identifier, options, level}): Logger => {
|
|
31
|
-
return new Logger(identifier, level,
|
|
29
|
+
const defaultLoggerFactory: LoggerFactory = ({ identifier, options, level }): Logger => {
|
|
30
|
+
return new Logger(identifier, level, {
|
|
31
|
+
formatter: options && options.formatter ? options.formatter : DEFAULT_LOGGER_FORMATTER,
|
|
32
|
+
transports: options && options.transports ? options.transports : DEFAULT_LOGGER_TRANSPORTS()
|
|
33
|
+
});
|
|
32
34
|
};
|
|
33
35
|
|
|
34
36
|
let customLoggerFactory: LoggerFactory | undefined = undefined;
|
|
35
37
|
|
|
36
38
|
export const setLoggerFactory = (factory: LoggerFactory): LoggerFactory => {
|
|
37
39
|
if (customLoggerFactory !== undefined) {
|
|
38
|
-
throw new Error("cannot change logger factory
|
|
40
|
+
throw new Error("cannot change logger factory after it has been used.");
|
|
39
41
|
}
|
|
40
42
|
customLoggerFactory = factory;
|
|
41
43
|
return customLoggerFactory;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./transport";
|
|
1
|
+
export * from "./constants.js";
|
|
2
|
+
export * from "./logger.js";
|
|
3
|
+
export * from "./factory.js";
|
|
4
|
+
export * from "./interfaces.js";
|
|
5
|
+
export * from "./transport/console.js";
|
|
6
6
|
|