@miqro/core 1.3.8 → 1.4.1

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.
Files changed (117) hide show
  1. package/README.md +0 -18
  2. package/dist/handler/app.d.ts +1 -2
  3. package/dist/handler/app.js +2 -3
  4. package/dist/handler/app.js.map +1 -1
  5. package/dist/handler/common/context.d.ts +2 -10
  6. package/dist/handler/common/context.js +4 -4
  7. package/dist/handler/common/context.js.map +1 -1
  8. package/dist/handler/common/index.js.map +1 -1
  9. package/dist/handler/common/router-utils.js.map +1 -1
  10. package/dist/handler/middleware/cookie.js +2 -2
  11. package/dist/handler/middleware/cookie.js.map +1 -1
  12. package/dist/handler/middleware/form.js.map +1 -1
  13. package/dist/handler/middleware/index.js.map +1 -1
  14. package/dist/handler/middleware/json.js.map +1 -1
  15. package/dist/handler/middleware/session.js.map +1 -1
  16. package/dist/handler/middleware/text.js.map +1 -1
  17. package/dist/index.d.ts +0 -1
  18. package/dist/index.js +0 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/util/cli/index.d.ts +6 -1
  21. package/dist/util/cli/index.js +26 -0
  22. package/dist/util/cli/index.js.map +1 -1
  23. package/dist/util/error/configfilenotfound.js.map +1 -1
  24. package/dist/util/error/forbiddenerror.js.map +1 -1
  25. package/dist/util/error/notfound.js.map +1 -1
  26. package/dist/util/error/notimplemented.js.map +1 -1
  27. package/dist/util/error/parsererror.js.map +1 -1
  28. package/dist/util/error/unauthorizederror.js.map +1 -1
  29. package/dist/util/index.js +0 -2
  30. package/dist/util/index.js.map +1 -1
  31. package/dist/util/logger/formatter.js +1 -1
  32. package/dist/util/logger/formatter.js.map +1 -1
  33. package/dist/util/session/service.js +2 -2
  34. package/dist/util/session/service.js.map +1 -1
  35. package/package.json +12 -4
  36. package/src/handler/app.ts +2 -2
  37. package/src/handler/common/context.ts +5 -14
  38. package/src/handler/common/index.ts +1 -2
  39. package/src/handler/common/router-utils.ts +44 -51
  40. package/src/handler/middleware/cookie.ts +12 -12
  41. package/src/handler/middleware/form.ts +1 -1
  42. package/src/handler/middleware/index.ts +24 -24
  43. package/src/handler/middleware/json.ts +1 -1
  44. package/src/handler/middleware/session.ts +128 -128
  45. package/src/handler/middleware/text.ts +1 -1
  46. package/src/index.ts +0 -1
  47. package/src/util/cli/index.ts +25 -1
  48. package/src/util/error/configfilenotfound.ts +1 -1
  49. package/src/util/error/forbiddenerror.ts +1 -1
  50. package/src/util/error/notfound.ts +1 -1
  51. package/src/util/error/notimplemented.ts +1 -1
  52. package/src/util/error/parsererror.ts +1 -1
  53. package/src/util/error/unauthorizederror.ts +1 -1
  54. package/src/util/index.ts +0 -2
  55. package/src/util/logger/formatter.ts +1 -1
  56. package/src/util/parser/common.ts +1 -1
  57. package/src/util/parser/index.ts +0 -3
  58. package/src/util/request/index.ts +1 -1
  59. package/src/util/session/index.ts +1 -1
  60. package/src/util/session/service.ts +126 -126
  61. package/dist/test/common/app.d.ts +0 -3
  62. package/dist/test/common/app.js +0 -51
  63. package/dist/test/common/app.js.map +0 -1
  64. package/dist/test/common/common.d.ts +0 -6
  65. package/dist/test/common/common.js +0 -15
  66. package/dist/test/common/common.js.map +0 -1
  67. package/dist/test/common/index.d.ts +0 -3
  68. package/dist/test/common/index.js +0 -16
  69. package/dist/test/common/index.js.map +0 -1
  70. package/dist/test/common/runner.d.ts +0 -13
  71. package/dist/test/common/runner.js +0 -92
  72. package/dist/test/common/runner.js.map +0 -1
  73. package/dist/test/index.d.ts +0 -1
  74. package/dist/test/index.js +0 -14
  75. package/dist/test/index.js.map +0 -1
  76. package/dist/test/main.d.ts +0 -1
  77. package/dist/test/main.js +0 -19
  78. package/dist/test/main.js.map +0 -1
  79. package/dist/util/cookie/cookie.d.ts +0 -50
  80. package/dist/util/cookie/cookie.js +0 -168
  81. package/dist/util/cookie/cookie.js.map +0 -1
  82. package/dist/util/cookie/index.d.ts +0 -16
  83. package/dist/util/cookie/index.js +0 -9
  84. package/dist/util/cookie/index.js.map +0 -1
  85. package/dist/util/uuid/index.d.ts +0 -7
  86. package/dist/util/uuid/index.js +0 -8
  87. package/dist/util/uuid/index.js.map +0 -1
  88. package/dist/util/uuid/regex.d.ts +0 -2
  89. package/dist/util/uuid/regex.js +0 -5
  90. package/dist/util/uuid/regex.js.map +0 -1
  91. package/dist/util/uuid/rng.d.ts +0 -1
  92. package/dist/util/uuid/rng.js +0 -18
  93. package/dist/util/uuid/rng.js.map +0 -1
  94. package/dist/util/uuid/stringify.d.ts +0 -2
  95. package/dist/util/uuid/stringify.js +0 -50
  96. package/dist/util/uuid/stringify.js.map +0 -1
  97. package/dist/util/uuid/v4.d.ts +0 -5
  98. package/dist/util/uuid/v4.js +0 -27
  99. package/dist/util/uuid/v4.js.map +0 -1
  100. package/dist/util/uuid/validate.d.ts +0 -2
  101. package/dist/util/uuid/validate.js +0 -12
  102. package/dist/util/uuid/validate.js.map +0 -1
  103. package/src/test/common/app.ts +0 -45
  104. package/src/test/common/common.ts +0 -17
  105. package/src/test/common/index.ts +0 -3
  106. package/src/test/common/runner.ts +0 -97
  107. package/src/test/index.ts +0 -1
  108. package/src/test/main.ts +0 -17
  109. package/src/util/cookie/cookie.ts +0 -207
  110. package/src/util/cookie/index.ts +0 -6
  111. package/src/util/uuid/index.ts +0 -5
  112. package/src/util/uuid/regex.ts +0 -2
  113. package/src/util/uuid/rng.ts +0 -14
  114. package/src/util/uuid/stringify.ts +0 -53
  115. package/src/util/uuid/v4.ts +0 -30
  116. package/src/util/uuid/validate.ts +0 -8
  117. package/tsconfig-test.json +0 -13
@@ -4,6 +4,6 @@ export type LoggerFormatter = (args: { identifier: string, level: LogLevel, mess
4
4
 
5
5
  export const defaultLoggerFormatter: LoggerFormatter =
6
6
  ({ identifier, level, message }) => `${new Date().toISOString()} ${process.pid} ` +
7
- `[${identifier}] ` +
7
+ `${identifier ? `[${identifier}] ` : ""}` +
8
8
  `${level !== "info" ? (level === "error" || level === "warn" ? `[${level.toUpperCase()}] ` : `[${level}] `) : ""}` +
9
9
  `${message}`;
@@ -78,4 +78,4 @@ export interface ParserInterface {
78
78
  options: ParseOption[] | ParseOptionMap,
79
79
  mode?: ParseOptionsMode,
80
80
  ignoreUndefined?: boolean): any
81
- }
81
+ }
@@ -1,6 +1,3 @@
1
1
  export * from "./parser";
2
2
  export * from "./common";
3
3
  export * from "./get";
4
-
5
-
6
-
@@ -227,4 +227,4 @@ export const request = (options: RequestOptions, logger?: Logger): Promise<Reque
227
227
  }
228
228
  });
229
229
  }
230
- }
230
+ }
@@ -1,2 +1,2 @@
1
1
  export * from "./common";
2
- export * from "./service";
2
+ export * from "./service";
@@ -4,7 +4,7 @@ import { checkEnvVariables } from "../config";
4
4
  import { UnAuthorizedError } from "../error";
5
5
  import { request, RequestOptions, RequestResponse } from "../request";
6
6
  import { parse } from "../parser";
7
- import { COOKIE } from "../cookie";
7
+ import { parse as cookieParse } from "cookie";
8
8
 
9
9
  const DEFAULT_TOKEN_LOCATION = "header";
10
10
  const DEFAULT_TOKEN_HEADER = "Authorization";
@@ -12,143 +12,143 @@ const DEFAULT_TOKEN_QUERY = "token";
12
12
  const DEFAULT_TOKEN_COOKIE = "Authorization";
13
13
 
14
14
  export interface VerifyTokenService {
15
- verify(args: { token: string; ctx: Context }): Promise<Session | null>;
15
+ verify(args: { token: string; ctx: Context }): Promise<Session | null>;
16
16
  }
17
17
 
18
18
  export interface VerifyEndpointServiceOptions {
19
- url: string;
20
- method: string;
21
- tokenLocation: "header" | "query" | "cookie";
22
- tokenLocationName: string | ((ctx: Context) => Promise<string>);
19
+ url: string;
20
+ method: string;
21
+ tokenLocation: "header" | "query" | "cookie";
22
+ tokenLocationName: string | ((ctx: Context) => Promise<string>);
23
23
  }
24
24
 
25
25
  export class VerifyEndpointService implements VerifyTokenService {
26
26
 
27
- protected options: VerifyEndpointServiceOptions;
27
+ protected options: VerifyEndpointServiceOptions;
28
28
 
29
- constructor(options?: VerifyEndpointServiceOptions) {
30
- if (!options) {
31
- const [url, method] = checkEnvVariables(["TOKEN_VERIFY_ENDPOINT", "TOKEN_VERIFY_ENDPOINT_METHOD"]);
32
- const [tokenVerifyLocation] = checkEnvVariables(["TOKEN_VERIFY_LOCATION"], [DEFAULT_TOKEN_LOCATION]);
33
- let tokenLocationName;
34
- switch (tokenVerifyLocation) {
35
- case "header":
36
- tokenLocationName = checkEnvVariables(["TOKEN_HEADER"], [DEFAULT_TOKEN_HEADER])[0];
37
- break;
38
- case "query":
39
- tokenLocationName = checkEnvVariables(["TOKEN_QUERY"], [DEFAULT_TOKEN_QUERY])[0];
40
- break;
41
- case "cookie":
42
- tokenLocationName = checkEnvVariables(["TOKEN_COOKIE"], [DEFAULT_TOKEN_COOKIE])[0];
43
- break;
44
- default:
45
- throw new Error(`TOKEN_VERIFY_LOCATION=${tokenVerifyLocation} not supported use (header or query)`);
46
- }
47
- this.options = {
48
- url, method,
49
- tokenLocation: tokenVerifyLocation,
50
- tokenLocationName
51
- }
52
- } else {
53
- this.options = parse("options", options as any, [
54
- { name: "url", required: true, type: "string", stringMinLength: 1 },
55
- { name: "method", required: true, type: "string", stringMinLength: 1 },
56
- { name: "tokenLocation", required: true, type: "enum", enumValues: ["header", "query", "cookie"] },
57
- { name: "tokenLocationName", required: true, type: "any" }
58
- ], "no_extra") as any;
59
- }
29
+ constructor(options?: VerifyEndpointServiceOptions) {
30
+ if (!options) {
31
+ const [url, method] = checkEnvVariables(["TOKEN_VERIFY_ENDPOINT", "TOKEN_VERIFY_ENDPOINT_METHOD"]);
32
+ const [tokenVerifyLocation] = checkEnvVariables(["TOKEN_VERIFY_LOCATION"], [DEFAULT_TOKEN_LOCATION]);
33
+ let tokenLocationName;
34
+ switch (tokenVerifyLocation) {
35
+ case "header":
36
+ tokenLocationName = checkEnvVariables(["TOKEN_HEADER"], [DEFAULT_TOKEN_HEADER])[0];
37
+ break;
38
+ case "query":
39
+ tokenLocationName = checkEnvVariables(["TOKEN_QUERY"], [DEFAULT_TOKEN_QUERY])[0];
40
+ break;
41
+ case "cookie":
42
+ tokenLocationName = checkEnvVariables(["TOKEN_COOKIE"], [DEFAULT_TOKEN_COOKIE])[0];
43
+ break;
44
+ default:
45
+ throw new Error(`TOKEN_VERIFY_LOCATION=${tokenVerifyLocation} not supported use (header or query)`);
46
+ }
47
+ this.options = {
48
+ url, method,
49
+ tokenLocation: tokenVerifyLocation,
50
+ tokenLocationName
51
+ }
52
+ } else {
53
+ this.options = parse("options", options as any, [
54
+ { name: "url", required: true, type: "string", stringMinLength: 1 },
55
+ { name: "method", required: true, type: "string", stringMinLength: 1 },
56
+ { name: "tokenLocation", required: true, type: "enum", enumValues: ["header", "query", "cookie"] },
57
+ { name: "tokenLocationName", required: true, type: "any" }
58
+ ], "no_extra") as any;
60
59
  }
60
+ }
61
61
 
62
- public async verify({ token, ctx }: { token: string; ctx: Context }): Promise<Session | null> {
63
- try {
64
- let response = null;
65
- const tokenVerifyLocation = this.options.tokenLocation;
66
- const url = this.options.url;
67
- const method = this.options.method;
68
- switch (tokenVerifyLocation) {
69
- case "header":
70
- const tokenHeaderLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
71
- ctx.logger.trace(`verifying [${token}] on TOKEN_VERIFY_ENDPOINT=[${process.env.TOKEN_VERIFY_ENDPOINT}] TOKEN_HEADER=[${tokenHeaderLocation}]`);
72
- response = await this.getResponse({
73
- url,
74
- headers: {
75
- [tokenHeaderLocation]: token
76
- },
77
- method
78
- }, ctx);
79
- break;
80
- case "query":
81
- const tokenQueryLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
82
- ctx.logger.trace(`verifying [${token}] on TOKEN_VERIFY_ENDPOINT=[${process.env.TOKEN_VERIFY_ENDPOINT}] TOKEN_QUERY=[${tokenQueryLocation}]`);
83
- response = await this.getResponse({
84
- url,
85
- query: {
86
- [tokenQueryLocation]: token
87
- },
88
- method
89
- }, ctx);
90
- break;
91
- case "cookie":
92
- const tokenCookieLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
93
- ctx.logger.trace(`verifying [${token}] on TOKEN_VERIFY_ENDPOINT=[${process.env.TOKEN_VERIFY_ENDPOINT}] TOKEN_COOKIE=[${tokenCookieLocation}]`);
94
- response = await this.getResponse({
95
- url,
96
- method,
97
- headers: {
98
- Cookie: `${tokenCookieLocation}=${token}; Path=/; HttpOnly;`
99
- }
100
- }, ctx);
101
- break;
102
- default:
103
- throw new Error(`TOKEN_VERIFY_LOCATION=${tokenVerifyLocation} not supported use (header, query or cookie)`);
62
+ public async verify({ token, ctx }: { token: string; ctx: Context }): Promise<Session | null> {
63
+ try {
64
+ let response = null;
65
+ const tokenVerifyLocation = this.options.tokenLocation;
66
+ const url = this.options.url;
67
+ const method = this.options.method;
68
+ switch (tokenVerifyLocation) {
69
+ case "header":
70
+ const tokenHeaderLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
71
+ ctx.logger.trace(`verifying [${token}] on TOKEN_VERIFY_ENDPOINT=[${process.env.TOKEN_VERIFY_ENDPOINT}] TOKEN_HEADER=[${tokenHeaderLocation}]`);
72
+ response = await this.getResponse({
73
+ url,
74
+ headers: {
75
+ [tokenHeaderLocation]: token
76
+ },
77
+ method
78
+ }, ctx);
79
+ break;
80
+ case "query":
81
+ const tokenQueryLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
82
+ ctx.logger.trace(`verifying [${token}] on TOKEN_VERIFY_ENDPOINT=[${process.env.TOKEN_VERIFY_ENDPOINT}] TOKEN_QUERY=[${tokenQueryLocation}]`);
83
+ response = await this.getResponse({
84
+ url,
85
+ query: {
86
+ [tokenQueryLocation]: token
87
+ },
88
+ method
89
+ }, ctx);
90
+ break;
91
+ case "cookie":
92
+ const tokenCookieLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
93
+ ctx.logger.trace(`verifying [${token}] on TOKEN_VERIFY_ENDPOINT=[${process.env.TOKEN_VERIFY_ENDPOINT}] TOKEN_COOKIE=[${tokenCookieLocation}]`);
94
+ response = await this.getResponse({
95
+ url,
96
+ method,
97
+ headers: {
98
+ Cookie: `${tokenCookieLocation}=${token}; Path=/; HttpOnly;`
104
99
  }
105
- if (response) {
106
- const session = await this.decodeSession(response, token, ctx);
107
- if (!this.checkSession(session, ctx)) {
108
- ctx.logger.warn(`unauthorized token not valid [${token}]`);
109
- return null;
110
- } else {
111
- ctx.logger.trace("token [%s]authorized!", token);
100
+ }, ctx);
101
+ break;
102
+ default:
103
+ throw new Error(`TOKEN_VERIFY_LOCATION=${tokenVerifyLocation} not supported use (header, query or cookie)`);
104
+ }
105
+ if (response) {
106
+ const session = await this.decodeSession(response, token, ctx);
107
+ if (!this.checkSession(session, ctx)) {
108
+ ctx.logger.warn(`unauthorized token not valid [${token}]`);
109
+ return null;
110
+ } else {
111
+ ctx.logger.trace("token [%s]authorized!", token);
112
112
 
113
- if (tokenVerifyLocation === "cookie" && response.headers["set-cookie"]) {
114
- const tokenCookieLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
115
- const cookies = response.headers["set-cookie"].map(c => COOKIE.parse(c)).filter(c => c[tokenCookieLocation] !== undefined);
116
- if (cookies.length === 1) {
117
- const value = cookies[0][tokenCookieLocation];
118
- if (value) {
119
- session.token = value; // replace token because token update via set-cookie
120
- }
121
- }
122
- }
123
- return {
124
- token,
125
- ...session
126
- } as Session;
127
- }
128
- } else {
129
- ctx.logger.warn(`unauthorized token not valid [${token}]`);
130
- return null;
113
+ if (tokenVerifyLocation === "cookie" && response.headers["set-cookie"]) {
114
+ const tokenCookieLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
115
+ const cookies = response.headers["set-cookie"].map(c => cookieParse(c)).filter(c => c[tokenCookieLocation] !== undefined);
116
+ if (cookies.length === 1) {
117
+ const value = cookies[0][tokenCookieLocation];
118
+ if (value) {
119
+ session.token = value; // replace token because token update via set-cookie
120
+ }
131
121
  }
132
- } catch (e: any) {
133
- throw new UnAuthorizedError(`Fail to authenticate token! error verifying [${token}] [${e.status}][${e.config ? e.config.url : ""}]`);
122
+ }
123
+ return {
124
+ token,
125
+ ...session
126
+ } as Session;
134
127
  }
128
+ } else {
129
+ ctx.logger.warn(`unauthorized token not valid [${token}]`);
130
+ return null;
131
+ }
132
+ } catch (e: any) {
133
+ throw new UnAuthorizedError(`Fail to authenticate token! error verifying [${token}] [${e.status}][${e.config ? e.config.url : ""}]`);
135
134
  }
136
- /* eslint-disable @typescript-eslint/no-unused-vars */
137
- protected async getResponse(config: RequestOptions, ctx?: Context): Promise<RequestResponse> {
138
- return request(config);
139
- }
140
- /* eslint-disable @typescript-eslint/no-unused-vars */
141
- protected checkSession(session: NoTokenSession, ctx?: Context): boolean {
142
- parse("session", session, [
143
- { name: "username", required: true, type: "string" },
144
- { name: "account", required: true, type: "string" },
145
- { name: "groups", required: true, type: "array", arrayType: "string" }
146
- ], "add_extra");
147
- return true;
148
- }
149
- /* eslint-disable @typescript-eslint/no-unused-vars */
150
- protected async decodeSession(response: RequestResponse, token: string, ctx?: Context): Promise<NoTokenSession> {
151
- const session = response.data;
152
- return session as NoTokenSession;
153
- }
154
- }
135
+ }
136
+ /* eslint-disable @typescript-eslint/no-unused-vars */
137
+ protected async getResponse(config: RequestOptions, ctx?: Context): Promise<RequestResponse> {
138
+ return request(config);
139
+ }
140
+ /* eslint-disable @typescript-eslint/no-unused-vars */
141
+ protected checkSession(session: NoTokenSession, ctx?: Context): boolean {
142
+ parse("session", session, [
143
+ { name: "username", required: true, type: "string" },
144
+ { name: "account", required: true, type: "string" },
145
+ { name: "groups", required: true, type: "array", arrayType: "string" }
146
+ ], "add_extra");
147
+ return true;
148
+ }
149
+ /* eslint-disable @typescript-eslint/no-unused-vars */
150
+ protected async decodeSession(response: RequestResponse, token: string, ctx?: Context): Promise<NoTokenSession> {
151
+ const session = response.data;
152
+ return session as NoTokenSession;
153
+ }
154
+ }
@@ -1,3 +0,0 @@
1
- import { RequestOptions, RequestResponse } from "../../util/request";
2
- import { App } from "../../handler/app";
3
- export declare const TestHelper: (app: App, options: RequestOptions, cb?: ((response: RequestResponse) => void) | undefined) => Promise<RequestResponse>;
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TestHelper = void 0;
4
- const request_1 = require("../../util/request");
5
- const fs_1 = require("fs");
6
- const http_1 = require("http");
7
- const TestHelper = async (app, options, cb) => {
8
- const unixSocket = `/tmp/socket.test.helper${Date.now()}`;
9
- if ((0, fs_1.existsSync)(unixSocket)) {
10
- (0, fs_1.unlinkSync)(unixSocket);
11
- }
12
- const server = (0, http_1.createServer)(app.listener);
13
- return new Promise((resolve, reject) => {
14
- server.listen(unixSocket, () => {
15
- (0, request_1.request)({
16
- disableThrow: true,
17
- ...options,
18
- socketPath: unixSocket
19
- }).then((response) => {
20
- server.close(() => {
21
- if (cb) {
22
- try {
23
- cb(response);
24
- }
25
- catch (ee) {
26
- reject(ee);
27
- }
28
- }
29
- resolve(response);
30
- });
31
- }).catch((e) => {
32
- server.close(() => {
33
- if (cb) {
34
- try {
35
- cb(e);
36
- }
37
- catch (ee) {
38
- reject(ee);
39
- }
40
- resolve(undefined);
41
- }
42
- else {
43
- reject(e);
44
- }
45
- });
46
- });
47
- });
48
- });
49
- };
50
- exports.TestHelper = TestHelper;
51
- //# sourceMappingURL=app.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"app.js","sourceRoot":"","sources":["../../../src/test/common/app.ts"],"names":[],"mappings":";;;AAAA,gDAA8E;AAE9E,2BAA4C;AAC5C,+BAAoC;AAE7B,MAAM,UAAU,GAAG,KAAK,EAAE,GAAQ,EAAE,OAAuB,EAAE,EAAwC,EAA4B,EAAE;IACxI,MAAM,UAAU,GAAG,0BAA0B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-1,6 +0,0 @@
1
- export declare type Callback<T = any> = (...args: any[]) => T;
2
- export interface FakeCallback<T = any> extends Callback<T> {
3
- callCount: number;
4
- callArgs: T[];
5
- }
6
- export declare const fake: (cb: Callback) => FakeCallback;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fake = void 0;
4
- const fake = (cb) => {
5
- const ret = (...args) => {
6
- ret.callCount++;
7
- ret.callArgs.push(args);
8
- return cb(...args);
9
- };
10
- ret.callCount = 0;
11
- ret.callArgs = [];
12
- return ret;
13
- };
14
- exports.fake = fake;
15
- //# sourceMappingURL=common.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/test/common/common.ts"],"names":[],"mappings":";;;AAOO,MAAM,IAAI,GAAG,CAAC,EAAY,EAAgB,EAAE;IACjD,MAAM,GAAG,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE;QAC7B,GAAG,CAAC,SAAS,EAAE,CAAC;QAChB,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxB,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;IACrB,CAAC,CAAC;IACF,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC;IAClB,GAAG,CAAC,QAAQ,GAAG,EAAS,CAAC;IACzB,OAAO,GAAG,CAAC;AACb,CAAC,CAAA;AATY,QAAA,IAAI,QAShB"}
@@ -1,3 +0,0 @@
1
- export * from "./common";
2
- export * from "./app";
3
- export * from "./runner";
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./common"), exports);
14
- __exportStar(require("./app"), exports);
15
- __exportStar(require("./runner"), exports);
16
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/test/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyB;AACzB,wCAAsB;AACtB,2CAAyB"}
@@ -1,13 +0,0 @@
1
- import { Console } from "console";
2
- import { Logger } from "../../util";
3
- export declare type TestFunction = () => void | Promise<void>;
4
- export declare const getTestCount: () => number;
5
- export declare const it: (title: string, impl: TestFunction, options?: {
6
- category?: string | undefined;
7
- timeout?: number | undefined;
8
- before?: TestFunction | undefined;
9
- after?: TestFunction | undefined;
10
- } | undefined, logger?: Logger | Console) => void;
11
- export declare const runTests: (title?: string | string[] | undefined, logger?: Logger | Console) => Promise<void>;
12
- export declare const runTestModules: (modules: string[], title?: string | string[] | undefined) => Promise<void>;
13
- export declare const runTestDir: (dirs: string[], title?: string | string[] | undefined, exts?: string[]) => Promise<void>;
@@ -1,92 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runTestDir = exports.runTestModules = exports.runTests = exports.it = exports.getTestCount = void 0;
4
- const console_1 = require("console");
5
- const fs_1 = require("fs");
6
- const path_1 = require("path");
7
- const util_1 = require("util");
8
- const DEFAULT_TIMEOUT = 2000;
9
- const tests = [];
10
- const getTestCount = () => tests.length;
11
- exports.getTestCount = getTestCount;
12
- const it = (title, impl, options, logger = new console_1.Console(process.stdout)) => {
13
- const category = options && options.category ? options.category : undefined;
14
- const fullName = `${category ? `${category} [` : ""}${title}${category ? "]" : ""}`;
15
- tests.push({
16
- run: () => new Promise((resolve, reject) => {
17
- const timeoutMS = options && options.timeout ? options.timeout : DEFAULT_TIMEOUT;
18
- const timeout = setTimeout(() => {
19
- reject(new Error((0, util_1.format)("\n\n%s failed\x1b[31m\n%s timeout %o\x1b", fullName, fullName, timeoutMS)));
20
- }, timeoutMS);
21
- try {
22
- (async () => {
23
- if (options && options.before) {
24
- await options.before();
25
- }
26
- const startMS = Date.now();
27
- await impl();
28
- const took = Date.now() - startMS;
29
- if (options && options.after) {
30
- await options.after();
31
- }
32
- return took;
33
- })().then((took) => {
34
- clearTimeout(timeout);
35
- logger.log("\x1b[32mpassed %s (took %sms)\x1b[0m\n", fullName, took);
36
- resolve();
37
- }).catch(e => {
38
- clearTimeout(timeout);
39
- reject(new Error((0, util_1.format)("\n\n%s failed\x1b[31m\n%s finished with errors %o\x1b", fullName, fullName, e)));
40
- });
41
- }
42
- catch (e) {
43
- clearTimeout(timeout);
44
- reject(new Error((0, util_1.format)("\n\n%s failed\x1b[31m\n%s finished with errors %o\x1b", fullName, fullName, e)));
45
- }
46
- }), title,
47
- category,
48
- fullName
49
- });
50
- };
51
- exports.it = it;
52
- const runTests = async (title, logger = new console_1.Console(process.stdout)) => {
53
- const titles = title ? title instanceof Array ? title : [title] : undefined;
54
- for (const test of tests) {
55
- if (!titles || titles.indexOf(test.title) !== -1) {
56
- try {
57
- await test.run();
58
- }
59
- catch (e) {
60
- logger.error(e);
61
- process.exit(1);
62
- }
63
- }
64
- }
65
- };
66
- exports.runTests = runTests;
67
- const runTestModules = async (modules, title) => {
68
- for (const path of modules) {
69
- require(path);
70
- }
71
- await (0, exports.runTests)(title);
72
- };
73
- exports.runTestModules = runTestModules;
74
- const runTestDir = async (dirs, title, exts = ["test.js"]) => {
75
- for (const dir of dirs) {
76
- const files = (0, fs_1.readdirSync)((0, path_1.resolve)(process.cwd(), dir));
77
- for (const f of files) {
78
- const path = (0, path_1.resolve)(dir, f);
79
- if (!(0, fs_1.lstatSync)(path).isDirectory()) {
80
- for (const ext of exts) {
81
- const name = (0, path_1.basename)(f);
82
- if (name.indexOf(ext) === name.length - ext.length) {
83
- require(path);
84
- }
85
- }
86
- }
87
- }
88
- }
89
- await (0, exports.runTests)(title);
90
- };
91
- exports.runTestDir = runTestDir;
92
- //# sourceMappingURL=runner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../src/test/common/runner.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAClC,2BAA4C;AAC5C,+BAAyC;AACzC,+BAA8B;AAI9B,MAAM,eAAe,GAAG,IAAI,CAAC;AAI7B,MAAM,KAAK,GAAW,EAAE,CAAC;AAElB,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC;AAAlC,QAAA,YAAY,gBAAsB;AAExC,MAAM,EAAE,GAAG,CAAC,KAAa,EAAE,IAAkB,EAAE,OAKrD,EAAE,SAA2B,IAAI,iBAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAQ,EAAE;IACjE,MAAM,QAAQ,GAAG,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5E,MAAM,QAAQ,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACpF,KAAK,CAAC,IAAI,CAAC;QACT,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACzC,MAAM,SAAS,GAAG,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;YACjF,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;gBAC9B,MAAM,CAAC,IAAI,KAAK,CAAC,IAAA,aAAM,EAAC,0CAA0C,EAAE,QAAQ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,EAAE;YACrB,MAAM,IAAI,GAAG,IAAA,cAAO,EAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAC7B,IAAI,CAAC,IAAA,cAAS,EAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE;gBAClC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;oBACtB,MAAM,IAAI,GAAG,IAAA,eAAQ,EAAC,CAAC,CAAC,CAAC;oBACzB,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE;wBAClD,OAAO,CAAC,IAAI,CAAC,CAAC;qBACf;iBACF;aACF;SACF;KACF;IACD,MAAM,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;AACxB,CAAC,CAAA;AAhBY,QAAA,UAAU,cAgBtB"}
@@ -1 +0,0 @@
1
- export * from "./common";
@@ -1,14 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./common"), exports);
14
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyB"}
@@ -1 +0,0 @@
1
- export {};
package/dist/test/main.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const path_1 = require("path");
4
- const common_1 = require("./common");
5
- const startMS = Date.now();
6
- const name = process.argv[2];
7
- if (!name) {
8
- throw new Error("bad arguments");
9
- }
10
- const modules = process.argv.slice(3);
11
- (0, common_1.runTestModules)(modules.map(m => (0, path_1.resolve)(process.cwd(), m)), name.toLowerCase() !== "all" ? name : undefined).then(() => {
12
- const took = Date.now() - startMS;
13
- const count = (0, common_1.getTestCount)();
14
- console.log("\n\n" + count + " tests pased took " + took + "ms\n\n");
15
- }).catch(e => {
16
- console.error(e);
17
- process.exit(1);
18
- });
19
- //# sourceMappingURL=main.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/test/main.ts"],"names":[],"mappings":";;AAAA,+BAA+B;AAC/B,qCAAwD;AAExD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;AAC3B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC7B,IAAI,CAAC,IAAI,EAAE;IACT,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;CAClC;AACD,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACtC,IAAA,uBAAc,EAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAA,cAAO,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;IACrH,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC;IAClC,MAAM,KAAK,GAAG,IAAA,qBAAY,GAAE,CAAC;IAC7B,OAAO,CAAC,GAAG,CAAC,MAAM,GAAG,KAAK,GAAG,oBAAoB,GAAG,IAAI,GAAG,QAAQ,CAAC,CAAC;AACvE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;IACX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}