nestia 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestia",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "Automatic SDK and Document generator for the NestJS",
5
5
  "main": "src/index.ts",
6
6
  "bin": {
@@ -2,7 +2,6 @@ import type * as tsc from "typescript";
2
2
  import { Pair } from "tstl/utility/Pair";
3
3
  import { Vector } from "tstl/container/Vector";
4
4
 
5
- import { Fetcher } from "../bundle/__internal/Fetcher";
6
5
  import { IRoute } from "../structures/IRoute";
7
6
 
8
7
  export namespace FunctionGenerator
@@ -23,22 +22,14 @@ export namespace FunctionGenerator
23
22
  --------------------------------------------------------- */
24
23
  function body(route: IRoute, query: IRoute.IParameter | undefined, input: IRoute.IParameter | undefined): string
25
24
  {
26
- // PATH WITH ENCRYPTION
27
- const path: string = get_path(route, query);
28
- const config: Fetcher.IConfig = {
29
- input_encrypted: input !== undefined && input.encrypted,
30
- output_encrypted: route.encrypted
31
- };
32
-
33
25
  // FETCH ARGUMENTS WITH REQUST BODY
26
+ const [parameters] = get_path(route, query);
34
27
  const fetchArguments: string[] =
35
28
  [
36
29
  "connection",
37
- JSON.stringify(config, null, 4)
38
- .split('"').join("")
39
- .split("\n").join("\n" + " ".repeat(8)),
40
- `"${route.method}"`,
41
- path
30
+ `${route.name}.CONFIG`,
31
+ `${route.name}.METHOD`,
32
+ `${route.name}.path(${parameters.map(p => p.name).join(", ")})`
42
33
  ];
43
34
  if (input !== undefined)
44
35
  fetchArguments.push("input");
@@ -52,18 +43,20 @@ export namespace FunctionGenerator
52
43
  + "}";
53
44
  }
54
45
 
55
- function get_path(route: IRoute, query: IRoute.IParameter | undefined): string
46
+ function get_path(route: IRoute, query: IRoute.IParameter | undefined): [IRoute.IParameter[], string]
56
47
  {
57
48
  const parameters = route.parameters.filter(param => param.category === "param");
58
- let path: string = route.path;
59
49
 
50
+ let path: string = route.path;
60
51
  for (const param of parameters)
61
52
  path = path.replace(`:${param.field}`, `\${${param.name}}`);
62
-
63
- new URLSearchParams()
64
- return (query !== undefined)
53
+ path = (query !== undefined)
65
54
  ? `\`${path}?\${new URLSearchParams(${query.name} as any).toString()}\``
66
- : `\`${path}\``
55
+ : `\`${path}\``;
56
+
57
+ if (query)
58
+ parameters.push(query);
59
+ return [parameters, path];
67
60
  }
68
61
 
69
62
  /* ---------------------------------------------------------
@@ -157,12 +150,28 @@ export namespace FunctionGenerator
157
150
  if (route.output !== "void")
158
151
  types.push(new Pair("Output", route.output));
159
152
 
160
- if (types.length === 0)
161
- return null;
162
-
153
+ const [parameters, path] = get_path(route, query);
163
154
  return `export namespace ${route.name}\n`
164
155
  + "{\n"
165
- + (types.map(tuple => ` export type ${tuple.first} = Primitive<${tuple.second}>;`).join("\n")) + "\n"
156
+ +
157
+ (
158
+ types.length !== 0
159
+ ? types.map(tuple => ` export type ${tuple.first} = Primitive<${tuple.second}>;`)
160
+ .join("\n")
161
+ + "\n\n"
162
+ : ""
163
+ )
164
+ + ` export const METHOD = "${route.method}";\n`
165
+ + ` export const PATH = "${route.path}";\n`
166
+ + ` export const CONFIG = {\n`
167
+ + ` input_encrypted: ${input !== undefined && input.encrypted},\n`
168
+ + ` output_encrypted: ${route.encrypted},\n`
169
+ + ` };\n`
170
+ + "\n"
171
+ + ` export function path(${parameters.map(param => `${param.name}: ${param.type}`).join(", ")}): string\n`
172
+ + ` {\n`
173
+ + ` return ${path};\n`
174
+ + ` }\n`
166
175
  + "}";
167
176
  }
168
177
  }