@miqro/core 3.0.3 → 3.0.4

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 (82) hide show
  1. package/build/cjs/api-router.js +2 -3
  2. package/build/cjs/api-router.js.map +1 -1
  3. package/build/cjs/common/api-router-types.d.ts +4 -2
  4. package/build/cjs/common/api-router-types.js +8 -1
  5. package/build/cjs/common/api-router-types.js.map +1 -1
  6. package/build/cjs/common/api-router-utils.d.ts +2 -4
  7. package/build/cjs/common/api-router-utils.js +64 -46
  8. package/build/cjs/common/api-router-utils.js.map +1 -1
  9. package/build/cjs/common/index.d.ts +1 -1
  10. package/build/cjs/common/index.js +1 -2
  11. package/build/cjs/common/index.js.map +1 -1
  12. package/build/cjs/common/logger/constants.d.ts +1 -0
  13. package/build/cjs/common/logger/constants.js +1 -0
  14. package/build/cjs/common/logger/constants.js.map +1 -1
  15. package/build/cjs/common/logger/interfaces.d.ts +1 -1
  16. package/build/cjs/common/logger/logger.js +1 -1
  17. package/build/cjs/common/logger/logger.js.map +1 -1
  18. package/build/cjs/common/logger/transport/console.js +3 -1
  19. package/build/cjs/common/logger/transport/console.js.map +1 -1
  20. package/build/cjs/common/router-default-logger-factory.d.ts +1 -0
  21. package/build/cjs/common/router-default-logger-factory.js +7 -1
  22. package/build/cjs/common/router-default-logger-factory.js.map +1 -1
  23. package/build/cjs/common/router-handler.js +28 -16
  24. package/build/cjs/common/router-handler.js.map +1 -1
  25. package/build/cjs/router.d.ts +9 -6
  26. package/build/cjs/router.js +21 -0
  27. package/build/cjs/router.js.map +1 -1
  28. package/build/esm/api-router.js +2 -3
  29. package/build/esm/api-router.js.map +1 -1
  30. package/build/esm/common/api-router-types.d.ts +4 -2
  31. package/build/esm/common/api-router-types.js +7 -0
  32. package/build/esm/common/api-router-types.js.map +1 -1
  33. package/build/esm/common/api-router-utils.d.ts +2 -4
  34. package/build/esm/common/api-router-utils.js +62 -44
  35. package/build/esm/common/api-router-utils.js.map +1 -1
  36. package/build/esm/common/index.d.ts +1 -1
  37. package/build/esm/common/index.js +1 -1
  38. package/build/esm/common/index.js.map +1 -1
  39. package/build/esm/common/logger/constants.d.ts +1 -0
  40. package/build/esm/common/logger/constants.js +1 -0
  41. package/build/esm/common/logger/constants.js.map +1 -1
  42. package/build/esm/common/logger/interfaces.d.ts +1 -1
  43. package/build/esm/common/logger/logger.js +1 -1
  44. package/build/esm/common/logger/logger.js.map +1 -1
  45. package/build/esm/common/logger/transport/console.js +3 -1
  46. package/build/esm/common/logger/transport/console.js.map +1 -1
  47. package/build/esm/common/router-default-logger-factory.d.ts +1 -0
  48. package/build/esm/common/router-default-logger-factory.js +5 -0
  49. package/build/esm/common/router-default-logger-factory.js.map +1 -1
  50. package/build/esm/common/router-handler.js +28 -16
  51. package/build/esm/common/router-handler.js.map +1 -1
  52. package/build/esm/router.d.ts +9 -6
  53. package/build/esm/router.js +21 -0
  54. package/build/esm/router.js.map +1 -1
  55. package/package.json +3 -3
  56. package/src/api-router.ts +2 -3
  57. package/src/common/api-router-types.ts +12 -4
  58. package/src/common/api-router-utils.ts +79 -61
  59. package/src/common/index.ts +1 -1
  60. package/src/common/logger/constants.ts +1 -0
  61. package/src/common/logger/interfaces.ts +1 -1
  62. package/src/common/logger/logger.ts +1 -1
  63. package/src/common/logger/transport/console.ts +6 -4
  64. package/src/common/router-default-logger-factory.ts +6 -0
  65. package/src/common/router-handler.ts +27 -16
  66. package/src/router.ts +33 -6
  67. package/test.out.txt +3535 -0
  68. package/build/cjs/common/feature-router-types.d.ts +0 -12
  69. package/build/cjs/common/feature-router-types.js +0 -5
  70. package/build/cjs/common/feature-router-types.js.map +0 -1
  71. package/build/cjs/feature-router.d.ts +0 -4
  72. package/build/cjs/feature-router.js +0 -90
  73. package/build/cjs/feature-router.js.map +0 -1
  74. package/build/esm/common/feature-router-types.d.ts +0 -12
  75. package/build/esm/common/feature-router-types.js +0 -2
  76. package/build/esm/common/feature-router-types.js.map +0 -1
  77. package/build/esm/feature-router.d.ts +0 -4
  78. package/build/esm/feature-router.js +0 -86
  79. package/build/esm/feature-router.js.map +0 -1
  80. package/src/api-router.unit.test.js +0 -280
  81. package/src/common/feature-router-types.ts +0 -13
  82. package/src/feature-router.ts +0 -82
@@ -1 +1 @@
1
- {"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/router.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAiC,MAAM,kBAAkB,CAAC;AAE1E,OAAO,EAA2B,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,OAAO,MAAM;IAKjB,YAAsB,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;QAJzB,aAAQ,GAAoB,EAAE,CAAC;QAC/B,kBAAa,GAAmB,EAAE,CAAC;QAIpD,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,oBAAoB,CAAC;QAClH,IAAI,CAAC,QAAQ,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;YACjC,MAAM,IAAI,GAAG,UAAU,EAAE,CAAC;YAC1B,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YACxC,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;YAChD,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;YACrC,MAAM,IAAI,CAAC,GAAG,CAAC,G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}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miqro/core",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
4
4
  "description": "",
5
5
  "main": "build/cjs/index.js",
6
6
  "types": "build/cjs/index.d.ts",
@@ -10,8 +10,8 @@
10
10
  "prebuild": "rm -Rf build/;",
11
11
  "build": "tsc && tsc -p tsconfig-esm.json",
12
12
  "pretest": "npm run build",
13
- "test": "LOG_LEVEL=debug NODE_ENV=test node --enable-source-maps --test src/**/*.test.js src/*.test.js test/*.test.js",
14
- "coverage": "node --enable-source-maps --experimental-test-coverage --test src/**/*.test.js src/*.test.js test/*.test.js"
13
+ "test": "LOG_LEVEL=none NODE_ENV=test node --enable-source-maps --test src/**/*.test.js src/*.test.js test/*.test.js",
14
+ "coverage": "LOG_LEVEL=none node --enable-source-maps --experimental-test-coverage --test src/**/*.test.js src/*.test.js test/*.test.js"
15
15
  },
16
16
  "author": "claukers",
17
17
  "license": "ISC",
package/src/api-router.ts CHANGED
@@ -3,7 +3,6 @@ import { basename } from "path";
3
3
  import { traverseAPIRouteDir } from "./common/api-router-utils";
4
4
  import { Logger } from "./common/logger/index.js";
5
5
  import { parse} from "@miqro/parser";
6
- import { FeatureRouter } from "./feature-router";
7
6
  import { MinimalRouter } from "./common/router-types";
8
7
  import { APIRouterOptions, APIRouterParseOptions } from "./common/api-router-types";
9
8
 
@@ -46,6 +45,6 @@ export async function APIRouter(options: APIRouterOptions, logger?: Logger): Pro
46
45
  throw new Error(`${dirname} not a directory!`);
47
46
  }
48
47
  const apiName = options.apiName !== undefined ? options.apiName : basename(dirname);
49
- const apiPath = options.path !== undefined ? options.path : `/${apiName}`;
50
- return FeatureRouter(await traverseAPIRouteDir(apiName.toUpperCase(), dirname, apiPath, undefined, logger), logger);
48
+ const apiPath = options.path !== undefined ? options.path : "";
49
+ return await traverseAPIRouteDir(apiName.toUpperCase(), dirname, apiPath, undefined, logger);
51
50
  }
@@ -1,6 +1,6 @@
1
1
  import { ParseOptionMap } from "@miqro/parser";
2
2
  import { Method } from "./context";
3
- import { HandlerWithOptions } from "./router-types";
3
+ import { handlerWithOptionsParseOptions, HandlerWithOptions } from "./router-types";
4
4
 
5
5
  /**
6
6
  * # APIRoute
@@ -14,9 +14,10 @@ import { HandlerWithOptions } from "./router-types";
14
14
  *export default route;
15
15
  * ```
16
16
  */
17
- export interface APIRoute extends HandlerWithOptions{
18
- method?: Method | Method[];
19
- path?: string | string[];
17
+ export interface APIRoute extends HandlerWithOptions {
18
+ postFolder?: boolean,
19
+ method?: Method | "use" | "USE";
20
+ path?: string;
20
21
  }
21
22
 
22
23
  export interface APIRouterOptions {
@@ -30,3 +31,10 @@ export const APIRouterParseOptions: ParseOptionMap = {
30
31
  apiName: "string?",
31
32
  path: "string?"
32
33
  };
34
+
35
+ export const APIRouteValidator: ParseOptionMap = {
36
+ ...handlerWithOptionsParseOptions,
37
+ postFolder: "boolean?",
38
+ method: "string?",
39
+ path: "string?"
40
+ };
@@ -1,34 +1,28 @@
1
1
  import { lstatSync, readdirSync } from "fs";
2
2
  import { join, parse as pathParse, resolve } from "path";
3
3
  import { Logger } from "./logger";
4
- import { APIRoute } from "./api-router-types.js";
5
- import { handlerWithOptionsParseOptions } from "./router-types";
6
- import { parse, ParseOptionMap } from "@miqro/parser";
7
- import { FeatureRouterOptions } from "./feature-router-types.js";
8
- import { Method } from "./context.js";
4
+ import { getPathIdentifier } from "./router-default-logger-factory.js";
5
+ import { APIRoute, APIRouteValidator } from "./api-router-types.js";
6
+ import { parse } from "@miqro/parser";
7
+ import { Handler, Method } from "./context.js";
9
8
  import { normalizePath } from "./url-utils";
10
-
11
- export const APIRouteValidator: ParseOptionMap = {
12
- ...handlerWithOptionsParseOptions,
13
- method: "string?|string[]?",
14
- path: "string?|string[]?"
15
- };
9
+ import { Router } from "../router";
10
+ import { RouterHandlerOptions } from "./router-types";
16
11
 
17
12
  export async function traverseAPIRouteDir(
18
13
  featureName: string,
19
14
  dirname: string,
20
15
  basePath = "/",
21
- features: FeatureRouterOptions = {}, logger?: Logger): Promise<FeatureRouterOptions> {
16
+ router: Router = new Router(), logger?: Logger): Promise<Router> {
22
17
  if (logger) {
23
18
  logger.trace("loading routes from [%s]", dirname);
24
19
  }
25
20
  const files = readdirSync(dirname);
26
21
  const dirs = files.filter(f => lstatSync(join(dirname, f)).isDirectory());
27
22
  const methods = files.filter(f => !lstatSync(join(dirname, f)).isDirectory());
28
- for (const f of dirs) {
29
- const { name } = pathParse(f);
30
- features = await traverseAPIRouteDir(`${featureName}_${name}`.toUpperCase(), join(dirname, f), `${basePath}/${name}`, features, logger);
31
- }
23
+
24
+ const postFolder: [Handler | Handler[], string | undefined, Method | undefined, RouterHandlerOptions][] = [];
25
+
32
26
  for (const f of methods) {
33
27
  const { name, ext } = pathParse(f);
34
28
  if (name !== "index" && ((ext === ".ts" || ext === ".js") && name.slice(-2) !== ".d")) {
@@ -44,19 +38,22 @@ export async function traverseAPIRouteDir(
44
38
  }
45
39
  //const ___filePath = filePath + ext;
46
40
  const ___filePath = filePath;
47
- let routeMethods: Method[] = [name] as Method[];
41
+ //let routeMethods: Method[] = [name] as Method[];
42
+ let routeMethod: Method | "use" | "USE" = name as Method;
48
43
  if (typeof route === "function") {
49
44
  route = {
50
45
  handler: route
51
46
  } as any;
52
47
  } else {
53
- if (typeof route.method !== "undefined" && (!(route.method instanceof Array) && (typeof route.method !== "string"))) {
54
- throw new Error(`${resolve(dirname, name)} doesnt export method as a string or string array`);
48
+ if (typeof route.method !== "undefined" && (/*!(route.method instanceof Array) &&*/ (typeof route.method !== "string"))) {
49
+ //throw new Error(`${resolve(dirname, name)} doesnt export method as a string or string array`);
50
+ throw new Error(`${resolve(dirname, name)} doesnt export method as a string`);
55
51
  } else if (typeof route.method !== "undefined") {
56
- routeMethods = route.method instanceof Array ? route.method : [route.method];
52
+ routeMethod = route.method;//route.method instanceof Array ? route.method : [route.method];
57
53
  }
58
- if (typeof route.path !== "string" && typeof route.path !== "undefined" && !(route.path instanceof Array)) {
59
- throw new Error(`${resolve(dirname, name)} doesnt export path as a string or a string array`);
54
+ if (typeof route.path !== "string" && typeof route.path !== "undefined"/* && !(route.path instanceof Array)*/) {
55
+ //throw new Error(`${resolve(dirname, name)} doesnt export path as a string or a string array`);
56
+ throw new Error(`${resolve(dirname, name)} doesnt export path as a string`);
60
57
  }
61
58
  if ((!(route.handler instanceof Array) && typeof route.handler !== "function") || typeof route.handler === "undefined") {
62
59
  throw new Error(`${resolve(dirname, name)} doesnt export handler as a function or an array`);
@@ -66,49 +63,70 @@ export async function traverseAPIRouteDir(
66
63
  }
67
64
  }
68
65
  route = parse(route, APIRouteValidator, "no_extra", ___filePath) as APIRoute;
69
- const paths = route.path instanceof Array ? route.path : route.path === undefined ? [route.method && route.method.indexOf(name as Method) === -1 ? `/${name}` : "/"] : [route.path];
70
- for (let i = 0; i < paths.length; i++) {
71
- const p = paths[i];
72
- if (typeof p !== "string" || !p) {
73
- throw new Error(`${resolve(dirname, name)} doesnt export path as a string or a string array`);
74
- }
75
- const path = normalizePath(`${basePath}${p && p !== "/" ? `${p}` : ""}`)
66
+ //const paths = route.path instanceof Array ? route.path : route.path === undefined ? [route.method && route.method.indexOf(name as Method) === -1 ? `/${name}` : "/"] : [route.path];
67
+ const p = route.path === undefined ? route.method && route.method.indexOf(name as Method) === -1 ? `/${name}` : "/" : route.path;
68
+ //for (let i = 0; i < paths.length; i++) {
69
+ //const p = paths[i];
70
+ if (typeof p !== "string" || !p) {
71
+ throw new Error(`${resolve(dirname, name)} doesnt export path as a string or a string array`);
72
+ }
73
+ const path = normalizePath(`${basePath}${p && p !== "/" ? `${p}` : ""}`)
76
74
 
77
- const subName = (p.charAt(0) === "/" ? p.substring(1) : p).replace(/[^a-z0-9+]+/gi, '_');
78
- const routeName = route.name ? route.name : name;
75
+ const subName = (p.charAt(0) === "/" ? p.substring(1) : p).replace(/[^a-z0-9+]+/gi, '_');
76
+ const routeName = route.name ? route.name : name;
79
77
 
80
- let newFeatureSubPath = `${featureName}_${route.name ? route.name : name}${routeName !== subName ? `_${subName}` : ""}`.toUpperCase();
78
+ //const identifier = route.identifier ? route.identifier : getPathIdentifier(path, routeMethod);
81
79
 
82
- newFeatureSubPath = newFeatureSubPath.length > 1 && newFeatureSubPath.charAt(newFeatureSubPath.length - 1) === "_" ? newFeatureSubPath.substring(0, newFeatureSubPath.length - 1) : newFeatureSubPath;
83
- if (features[newFeatureSubPath]) {
84
- throw new Error(`${___filePath} feature name collides with ${(features[newFeatureSubPath] as any).___filePath}`)
85
- }
86
- if (newFeatureSubPath === "__prototype__" || newFeatureSubPath === "__proto__") {
87
- throw new Error(`invalid feature name ${newFeatureSubPath}`);
88
- }
89
- features[newFeatureSubPath] = {
90
- options: {
91
- identifier: newFeatureSubPath,
92
- apiName: route.apiName,
93
- name: route.name,
94
- description: route.description,
95
- parser: route.parser,
96
- middleware: route.middleware,
97
- session: route.session,
98
- policy: route.policy,
99
- request: route.request,
100
- response: {
101
- body: route.response && route.response.body ? route.response.body : true,
102
- middleware: route.response && route.response.middleware ? route.response.middleware : undefined
103
- }
104
- },
105
- path,
106
- method: routeMethods,
107
- handler: route.handler
108
- };
109
- (features[newFeatureSubPath] as any).___filePath = ___filePath;
80
+ /*let newFeatureSubPath = `${featureName}_${route.name ? route.name : name}${routeName !== subName ? `_${subName}` : ""}`.toUpperCase();
81
+
82
+ newFeatureSubPath = newFeatureSubPath.length > 1 && newFeatureSubPath.charAt(newFeatureSubPath.length - 1) === "_" ? newFeatureSubPath.substring(0, newFeatureSubPath.length - 1) : newFeatureSubPath;*/
83
+ /*if (features[identifier]) {
84
+ throw new Error(`${___filePath} feature name collides with ${(features[identifier] as any).___filePath}`)
85
+ }*/
86
+ if (route.identifier && route.identifier === "__prototype__" || route.identifier === "__proto__") {
87
+ throw new Error(`invalid feature name ${route.identifier}`);
88
+ }
89
+ if (route.postFolder) {
90
+ postFolder.push([route.handler, path, routeMethod !== "use" && routeMethod !== "USE" ? routeMethod : undefined, {
91
+ identifier: route.identifier,
92
+ apiName: route.apiName,
93
+ name: route.name,
94
+ description: route.description,
95
+ parser: route.parser,
96
+ middleware: route.middleware,
97
+ session: route.session,
98
+ policy: route.policy,
99
+ request: route.request,
100
+ response: {
101
+ body: route.response && route.response.body ? route.response.body : true,
102
+ middleware: route.response && route.response.middleware ? route.response.middleware : undefined
103
+ }
104
+ }]);
105
+ } else {
106
+ router.use(route.handler, path, routeMethod !== "use" && routeMethod !== "USE" ? routeMethod : undefined, {
107
+ identifier: route.identifier,
108
+ apiName: route.apiName,
109
+ name: route.name,
110
+ description: route.description,
111
+ parser: route.parser,
112
+ middleware: route.middleware,
113
+ session: route.session,
114
+ policy: route.policy,
115
+ request: route.request,
116
+ response: {
117
+ body: route.response && route.response.body ? route.response.body : true,
118
+ middleware: route.response && route.response.middleware ? route.response.middleware : undefined
119
+ }
120
+ });
110
121
  }
111
122
  }
112
123
  }
113
- return features;
124
+ for (const f of dirs) {
125
+ const { name } = pathParse(f);
126
+ router = await traverseAPIRouteDir(`${featureName}_${name}`.toUpperCase(), join(dirname, f), `${basePath}/${name}`, router, logger);
127
+ }
128
+ for (const post of postFolder) {
129
+ router.use(...post);
130
+ }
131
+ return router;
114
132
  };
@@ -7,5 +7,5 @@ export * from "./error";
7
7
  export * from "./config";
8
8
  export * from "./logger";
9
9
  export { normalizePath, newURL } from "./url-utils";
10
- export { traverseAPIRouteDir, APIRouteValidator } from "./api-router-utils";
10
+ export { traverseAPIRouteDir } from "./api-router-utils";
11
11
  export { OldResponseHandler, ResponseHandler } from "./router-utils";
@@ -15,6 +15,7 @@ export const DEFAULT_LOGGER_FORMATTER: LoggerFormatter =
15
15
 
16
16
  export const LOG_LEVEL_MAP =
17
17
  {
18
+ "none": 0,
18
19
  "error": 1,
19
20
  "warn": 2,
20
21
  "info": 3,
@@ -1,4 +1,4 @@
1
- export type LogLevel = "error" | "warn" | "info" | "debug" | "trace";
1
+ export type LogLevel = "error" | "warn" | "info" | "debug" | "trace" | "none";
2
2
 
3
3
  export interface WriteArgs {
4
4
  level: LogLevel;
@@ -43,7 +43,7 @@ export class Logger extends EventTarget implements Logger {
43
43
 
44
44
  constructor(protected readonly identifier: string, protected level: LogLevel = "info", options?: { transports?: LoggerTransport[]; formatter?: LoggerFormatter; }) {
45
45
  super();
46
- if (!LOG_LEVEL_MAP[level]) {
46
+ if (LOG_LEVEL_MAP[level] === undefined) {
47
47
  throw new Error(`Unknown level [${level}]`);
48
48
  }
49
49
  this.addEventListener(LoggerEvents.error, (ev: any) => {
@@ -1,9 +1,9 @@
1
- import {LoggerTransportWriteArgs, LogLevel} from "../interfaces.js";
1
+ import { LoggerTransportWriteArgs, LogLevel } from "../interfaces.js";
2
2
 
3
3
  export function ConsoleTransport(color: boolean = true, level?: LogLevel) {
4
4
  return {
5
5
  level,
6
- write: async ({level, out}: LoggerTransportWriteArgs): Promise<void> => {
6
+ write: async ({ level, out }: LoggerTransportWriteArgs): Promise<void> => {
7
7
  if (color) {
8
8
  switch (level) {
9
9
  case "warn":
@@ -18,14 +18,16 @@ export function ConsoleTransport(color: boolean = true, level?: LogLevel) {
18
18
  case "debug":
19
19
  console.log("\x1b[36m%s\x1b[0m", out);
20
20
  break;
21
+ case "none":
22
+ break;
21
23
  default:
22
24
  console[level](out);
23
25
  break;
24
26
  }
25
27
  } else {
26
- if(level === "trace" || level === "debug") {
28
+ if (level === "trace" || level === "debug") {
27
29
  console.log(out);
28
- } else {
30
+ } else if (level !== "none") {
29
31
  console[level](out);
30
32
  }
31
33
  }
@@ -34,3 +34,9 @@ export const defaultLoggerFactory = (uuid: string, req: IncomingMessage): Logger
34
34
 
35
35
  return logger;
36
36
  }
37
+
38
+ export function getPathIdentifier(path: string, method: string) {
39
+ const pathToEnv = path.replace(/[^a-z0-9+]+/gi, '_').toUpperCase();
40
+ const identifier = `${pathToEnv === "_" ? "" : pathToEnv.substring(1)}${method.toUpperCase()}`;
41
+ return identifier;
42
+ }
@@ -98,28 +98,39 @@ export class RouterHandler {
98
98
  if (this.isRouter) {
99
99
  const router: MinimalRouter = this.handler[0] as MinimalRouter;
100
100
  router.getJSONDoc(doc, `${prePath}${nPath}`);
101
- } else if (this.options) {
101
+ } else {
102
102
  if (!doc[`${prePath}${nPath}`]) {
103
103
  doc[`${prePath}${nPath}`] = Object.create(null);
104
104
  }
105
105
  if (doc[`${prePath}${nPath}`][nMethod]) {
106
106
  throw new Error("cannot create doc routes override each other");
107
107
  }
108
- doc[`${prePath}${nPath}`][nMethod] = {
109
- description: this.options.description,
110
- name: this.options.name,
111
- identifier: this.options.identifier ? this.options.identifier : `${prePath}${nPath}${this.options.name ? this.options.name : ""}${nMethod ? `_${nMethod}` : ""}`.replace(/[^a-z0-9+]+/gi, '_').split("_").map(s => s.trim()).filter(s => s).join("_").toUpperCase(),
112
- policy: this.options.policy,
113
- request: this.options.request ? {
114
- body: this.options.request.body,
115
- headers: this.options.request.headers,
116
- params: this.options.request.params,
117
- query: this.options.request.query,
118
- } : undefined,
119
- response: this.options.response ? {
120
- body: this.options.response.body
121
- } : undefined
122
- };
108
+ if(this.options) {
109
+ doc[`${prePath}${nPath}`][nMethod] = {
110
+ description: this.options.description,
111
+ name: this.options.name,
112
+ identifier: this.options.identifier ? this.options.identifier : `${prePath}${nPath}${this.options.name ? this.options.name : ""}${nMethod ? `_${nMethod}` : ""}`.replace(/[^a-z0-9+]+/gi, '_').split("_").map(s => s.trim()).filter(s => s).join("_").toUpperCase(),
113
+ policy: this.options.policy,
114
+ request: this.options.request ? {
115
+ body: this.options.request.body,
116
+ headers: this.options.request.headers,
117
+ params: this.options.request.params,
118
+ query: this.options.request.query,
119
+ } : undefined,
120
+ response: this.options.response ? {
121
+ body: this.options.response.body
122
+ } : undefined
123
+ };
124
+ } else {
125
+ doc[`${prePath}${nPath}`][nMethod] = {
126
+ description: undefined,
127
+ name: undefined,
128
+ identifier: `${prePath}${nPath}${nMethod ? `_${nMethod}` : ""}`.replace(/[^a-z0-9+]+/gi, '_').split("_").map(s => s.trim()).filter(s => s).join("_").toUpperCase(),
129
+ policy: undefined,
130
+ request: undefined,
131
+ response: undefined
132
+ };
133
+ }
123
134
  }
124
135
  return doc;
125
136
  }
package/src/router.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { RequestListener } from "http";
2
+ import { Logger } from "./common/logger";
2
3
  import { Context, ErrorHandler, Handler, Method } from "./common/context";
3
4
  import { HandlerWithOptions, MinimalRouter, RouterHandlerOptions, RouterJSONDoc, RouterOptions } from "./common/router-types";
4
5
  import { PathPart, PathPartToken, splitPath } from "./common/tokenize-match";
@@ -23,27 +24,27 @@ export class Router implements MinimalRouter {
23
24
  };
24
25
  }
25
26
 
26
- public get(path: string, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router {
27
+ public get(path: string | undefined, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router {
27
28
  return this.use(handler, path, "get", options);
28
29
  }
29
30
 
30
- public post(path: string, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router {
31
+ public post(path: string | undefined, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router {
31
32
  return this.use(handler, path, "post", options);
32
33
  }
33
34
 
34
- public patch(path: string, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router {
35
+ public patch(path: string | undefined, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router {
35
36
  return this.use(handler, path, "patch", options);
36
37
  }
37
38
 
38
- public delete(path: string, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router {
39
+ public delete(path: string | undefined, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router {
39
40
  return this.use(handler, path, "delete", options);
40
41
  }
41
42
 
42
- public put(path: string, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router {
43
+ public put(path: string | undefined, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router {
43
44
  return this.use(handler, path, "put", options);
44
45
  }
45
46
 
46
- public options(path: string, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router {
47
+ public options(path: string | undefined, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router {
47
48
  return this.use(handler, path, "options", options);
48
49
  }
49
50
 
@@ -104,4 +105,30 @@ export class Router implements MinimalRouter {
104
105
  }
105
106
  return doc;
106
107
  }
108
+
109
+ public logPaths(logger: Logger): void {
110
+ this.toString().split("\n").forEach(l=>logger.info(l));
111
+ }
112
+
113
+ public toString(): string {
114
+ let ret = "";
115
+ const doc = this.getJSONDoc();
116
+ const paths = Object.keys(doc);
117
+
118
+ for(const path of paths) {
119
+ if (path) {
120
+ const pathData = doc[path];
121
+
122
+ const methods = Object.keys(pathData);
123
+
124
+ for (const method of methods) {
125
+ if (method) {
126
+ const methodData = pathData[method];
127
+ ret += `${ret === "" ? "" : "\n"}${method}:${path}\n\t${methodData.identifier}${methodData.name ? `\n\t\t${methodData.name}` : ""}${methodData.description ? `\n\t\t${methodData.description}` : ""}`;
128
+ }
129
+ }
130
+ }
131
+ }
132
+ return ret;
133
+ }
107
134
  }