nestia 0.3.6 → 0.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestia",
3
- "version": "0.3.6",
3
+ "version": "0.4.0",
4
4
  "description": "Automatic SDK and Document generator for the NestJS",
5
5
  "main": "src/index.ts",
6
6
  "bin": {
@@ -104,6 +104,8 @@ export namespace ControllerAnalyzer
104
104
  let path: string = NodePath.join(controller.path, func.path).split("\\").join("/");
105
105
  if (path[0] !== "/")
106
106
  path = "/" + path;
107
+ if (path[path.length - 1] === "/" && path !== "/")
108
+ path = path.substr(0, path.length - 1);
107
109
 
108
110
  // RETURNS
109
111
  return {
@@ -1,4 +1,4 @@
1
- import * as path from "path";
1
+ import Pather from "path";
2
2
 
3
3
  import { ArrayUtil } from "../utils/ArrayUtil";
4
4
  import { StringUtil } from "../utils/StringUtil";
@@ -128,7 +128,7 @@ export namespace ReflectAnalyzer
128
128
  }
129
129
 
130
130
  // VALIDATE PATH ARGUMENTS
131
- const funcPathArguments: string[] = StringUtil.betweens(path.join(controller.path, meta.path).split("\\").join("/"), ":", "/").sort();
131
+ const funcPathArguments: string[] = StringUtil.betweens(Pather.join(controller.path, meta.path).split("\\").join("/"), ":", "/").sort();
132
132
  const paramPathArguments: string[] = meta.parameters.filter(param => param.category === "param").map(param => param.field!).sort();
133
133
 
134
134
  if (equal(funcPathArguments, paramPathArguments) === false)
@@ -23,7 +23,7 @@ export namespace FunctionGenerator
23
23
  function body(route: IRoute, query: IRoute.IParameter | undefined, input: IRoute.IParameter | undefined): string
24
24
  {
25
25
  // FETCH ARGUMENTS WITH REQUST BODY
26
- const [parameters] = get_path(route, query);
26
+ const parameters = filter_parameters(route, query);
27
27
  const fetchArguments: string[] =
28
28
  [
29
29
  "connection",
@@ -43,20 +43,12 @@ export namespace FunctionGenerator
43
43
  + "}";
44
44
  }
45
45
 
46
- function get_path(route: IRoute, query: IRoute.IParameter | undefined): [IRoute.IParameter[], string]
46
+ function filter_parameters(route: IRoute, query: IRoute.IParameter | undefined): IRoute.IParameter[]
47
47
  {
48
48
  const parameters = route.parameters.filter(param => param.category === "param");
49
-
50
- let path: string = route.path;
51
- for (const param of parameters)
52
- path = path.replace(`:${param.field}`, `\${${param.name}}`);
53
- path = (query !== undefined)
54
- ? `\`${path}?\${new URLSearchParams(${query.name} as any).toString()}\``
55
- : `\`${path}\``;
56
-
57
49
  if (query)
58
50
  parameters.push(query);
59
- return [parameters, path];
51
+ return parameters;
60
52
  }
61
53
 
62
54
  /* ---------------------------------------------------------
@@ -142,6 +134,7 @@ export namespace FunctionGenerator
142
134
 
143
135
  function tail(route: IRoute, query: IRoute.IParameter | undefined, input: IRoute.IParameter | undefined): string | null
144
136
  {
137
+ // LIST UP TYPES
145
138
  const types: Pair<string, string>[] = [];
146
139
  if (query !== undefined)
147
140
  types.push(new Pair("Query", query.type));
@@ -150,17 +143,25 @@ export namespace FunctionGenerator
150
143
  if (route.output !== "void")
151
144
  types.push(new Pair("Output", route.output));
152
145
 
153
- const [parameters, path] = get_path(route, query);
146
+ // PATH WITH PARAMETERS
147
+ const parameters = filter_parameters(route, query);
148
+ let path: string = route.path;
149
+ for (const param of parameters)
150
+ if (param.category === "param")
151
+ path = path.replace(`:${param.field}`, `\${${param.name}}`);
152
+ path = (query !== undefined)
153
+ ? `\`${path}?\${new URLSearchParams(${query.name} as any).toString()}\``
154
+ : `\`${path}\``;
155
+
154
156
  return `export namespace ${route.name}\n`
155
157
  + "{\n"
156
158
  +
157
159
  (
158
160
  types.length !== 0
159
- ? types.map(tuple => ` export type ${tuple.first} = Primitive<${tuple.second}>;`)
160
- .join("\n")
161
- + "\n\n"
161
+ ? types.map(tuple => ` export type ${tuple.first} = Primitive<${tuple.second}>;`).join("\n") + "\n\n"
162
162
  : ""
163
163
  )
164
+ + "\n"
164
165
  + ` export const METHOD = "${route.method}";\n`
165
166
  + ` export const PATH = "${route.path}";\n`
166
167
  + ` export const CONFIG = {\n`