nestia 2.0.10 → 2.0.11

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 CHANGED
@@ -109,6 +109,15 @@ export interface IConfiguration
109
109
  */
110
110
  assert?: boolean;
111
111
 
112
+ /**
113
+ * Whether to optimize JSON string conversion or not.
114
+ *
115
+ * If you configure this option to be `true`, the SDK library would utilize the
116
+ * [typescript-json](https://github.com/samchon/typescript-json) and the JSON string
117
+ * conversion speed really be two times faster.
118
+ */
119
+ json?: boolean;
120
+
112
121
  /**
113
122
  * List of files or directories containing the NestJS controller classes.
114
123
  */
@@ -4,6 +4,7 @@ export interface IConfiguration {
4
4
  output: string;
5
5
  compilerOptions?: tsc.CompilerOptions;
6
6
  assert?: boolean;
7
+ json?: boolean;
7
8
  }
8
9
  export declare namespace IConfiguration {
9
10
  interface IInput {
@@ -1 +1 @@
1
- {"version":3,"file":"IConfiguration.d.ts","sourceRoot":"","sources":["../src/IConfiguration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,YAAY,CAAC;AAElC,MAAM,WAAW,cAAc;IAE3B,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,cAAc,CAAC,MAAM,CAAC;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,GAAG,CAAC,eAAe,CAAC;IACtC,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB;AACD,yBAAiB,cAAc,CAC/B;IACI,UAAiB,MAAM;QAEnB,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;KACtB;CACJ"}
1
+ {"version":3,"file":"IConfiguration.d.ts","sourceRoot":"","sources":["../src/IConfiguration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,YAAY,CAAC;AAElC,MAAM,WAAW,cAAc;IAE3B,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,cAAc,CAAC,MAAM,CAAC;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,GAAG,CAAC,eAAe,CAAC;IACtC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;CAClB;AACD,yBAAiB,cAAc,CAC/B;IACI,UAAiB,MAAM;QAEnB,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;KACtB;CACJ"}
@@ -136,6 +136,14 @@ var NestiaConfig;
136
136
  if (error)
137
137
  return error;
138
138
  }
139
+ } {
140
+ if ("json" in object) {
141
+ path.push("json");
142
+ var error = su__undefined__3__4_eu(object["json"]);
143
+ path.pop();
144
+ if (error)
145
+ return error;
146
+ }
139
147
  } return null; } return _0(object); });
140
148
  if ((0, typescript_is_1.is)(config.input, function (object) { function _string(object) { ; if (typeof object !== "string")
141
149
  return {};
File without changes
@@ -1 +1 @@
1
- {"version":3,"file":"FileGenerator.d.ts","sourceRoot":"","sources":["../../src/generates/FileGenerator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAI9C,yBAAiB,aAAa,CAC9B;IAII,SAAsB,QAAQ,CAAC,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAYzF;CA4GJ"}
1
+ {"version":3,"file":"FileGenerator.d.ts","sourceRoot":"","sources":["../../src/generates/FileGenerator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAI9C,yBAAiB,aAAa,CAC9B;IAII,SAAsB,QAAQ,CAAC,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAYzF;CA+GJ"}
@@ -104,7 +104,7 @@ var FileGenerator;
104
104
  // RELOCATE FOR ONLY ONE CONTROLLER METHOD IN AN URL CASE
105
105
  relocate(root);
106
106
  // ITERATE FILES
107
- return [4 /*yield*/, iterate(!!config.assert, config.output + "/functional", root)];
107
+ return [4 /*yield*/, iterate(config, config.output + "/functional", root)];
108
108
  case 1:
109
109
  // ITERATE FILES
110
110
  _b.sent();
@@ -168,9 +168,9 @@ var FileGenerator;
168
168
  /* ---------------------------------------------------------
169
169
  FILE ITERATOR
170
170
  --------------------------------------------------------- */
171
- function iterate(assert, outDir, directory) {
171
+ function iterate(config, outDir, directory) {
172
172
  return __awaiter(this, void 0, void 0, function () {
173
- var _a, content, _b, _c, it, e_4_1, importDict, _d, _e, route, _f, _g, tuple, _h, _j, instance, primitived, asserted, fetcher;
173
+ var _a, content, _b, _c, it, e_4_1, importDict, _d, _e, route, _f, _g, tuple, _h, _j, instance, primitived, asserted, json, fetcher;
174
174
  var e_4, _k, e_5, _l, e_6, _m, e_7, _o;
175
175
  return __generator(this, function (_p) {
176
176
  switch (_p.label) {
@@ -193,7 +193,7 @@ var FileGenerator;
193
193
  case 5:
194
194
  if (!!_c.done) return [3 /*break*/, 8];
195
195
  it = _c.value;
196
- return [4 /*yield*/, iterate(assert, "".concat(outDir, "/").concat(it.first), it.second)];
196
+ return [4 /*yield*/, iterate(config, "".concat(outDir, "/").concat(it.first), it.second)];
197
197
  case 6:
198
198
  _p.sent();
199
199
  content += "export * as ".concat(it.first, " from \"./").concat(it.first, "\";\n");
@@ -243,7 +243,7 @@ var FileGenerator;
243
243
  }
244
244
  finally { if (e_6) throw e_6.error; }
245
245
  }
246
- content += FunctionGenerator_1.FunctionGenerator.generate(assert, route) + "\n\n";
246
+ content += FunctionGenerator_1.FunctionGenerator.generate(config, route) + "\n\n";
247
247
  }
248
248
  }
249
249
  catch (e_5_1) { e_5 = { error: e_5_1 }; }
@@ -257,8 +257,10 @@ var FileGenerator;
257
257
  if (directory.routes.length !== 0) {
258
258
  primitived = directory.routes.some(function (route) { return route.output !== "void"
259
259
  || route.parameters.some(function (param) { return param.category !== "param"; }); });
260
- asserted = assert
260
+ asserted = config.assert === true
261
261
  && directory.routes.some(function (route) { return route.parameters.length !== 0; });
262
+ json = config.json === true
263
+ && directory.routes.some(function (route) { return route.method === "POST" || route.method === "PUT" || route.method === "PATCH"; });
262
264
  fetcher = ["Fetcher"];
263
265
  if (primitived)
264
266
  fetcher.push("Primitive");
@@ -266,6 +268,7 @@ var FileGenerator;
266
268
  + "import { ".concat(fetcher.join(", "), " } from \"nestia-fetcher\";\n")
267
269
  + "import type { IConnection } from \"nestia-fetcher\";\n"
268
270
  + (asserted ? "import { assertType } from \"typescript-is\";\n" : "")
271
+ + (json ? "import { createStringifier } from \"typescript-json\";\n" : "")
269
272
  +
270
273
  (importDict.empty()
271
274
  ? ""
@@ -1,5 +1,6 @@
1
+ import { IConfiguration } from "../IConfiguration";
1
2
  import { IRoute } from "../structures/IRoute";
2
3
  export declare namespace FunctionGenerator {
3
- function generate(assert: boolean, route: IRoute): string;
4
+ function generate(config: IConfiguration, route: IRoute): string;
4
5
  }
5
6
  //# sourceMappingURL=FunctionGenerator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionGenerator.d.ts","sourceRoot":"","sources":["../../src/generates/FunctionGenerator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,yBAAiB,iBAAiB,CAClC;IACI,SAAgB,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAS/D;CAuLJ"}
1
+ {"version":3,"file":"FunctionGenerator.d.ts","sourceRoot":"","sources":["../../src/generates/FunctionGenerator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,yBAAiB,iBAAiB,CAClC;IACI,SAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAStE;CAkMJ"}
@@ -41,11 +41,11 @@ var Pair_1 = require("tstl/utility/Pair");
41
41
  var Vector_1 = require("tstl/container/Vector");
42
42
  var FunctionGenerator;
43
43
  (function (FunctionGenerator) {
44
- function generate(assert, route) {
44
+ function generate(config, route) {
45
45
  var query = route.parameters.find(function (param) { return param.category === "query"; });
46
46
  var input = route.parameters.find(function (param) { return param.category === "body"; });
47
47
  return [head, body, tail]
48
- .map(function (closure) { return closure(route, query, input, assert); })
48
+ .map(function (closure) { return closure(route, query, input, config); })
49
49
  .filter(function (str) { return !!str; })
50
50
  .join("\n");
51
51
  }
@@ -53,7 +53,7 @@ var FunctionGenerator;
53
53
  /* ---------------------------------------------------------
54
54
  BODY
55
55
  --------------------------------------------------------- */
56
- function body(route, query, input, assert) {
56
+ function body(route, query, input, config) {
57
57
  // FETCH ARGUMENTS WITH REQUST BODY
58
58
  var parameters = filter_parameters(route, query);
59
59
  var fetchArguments = [
@@ -62,9 +62,12 @@ var FunctionGenerator;
62
62
  "".concat(route.name, ".METHOD"),
63
63
  "".concat(route.name, ".path(").concat(parameters.map(function (p) { return p.name; }).join(", "), ")")
64
64
  ];
65
- if (input !== undefined)
65
+ if (input !== undefined) {
66
66
  fetchArguments.push(input.name);
67
- var assertions = assert === true && route.parameters.length !== 0
67
+ if (config.json === true)
68
+ fetchArguments.push("".concat(route.name, ".stringify"));
69
+ }
70
+ var assertions = config.assert === true && route.parameters.length !== 0
68
71
  ? route.parameters
69
72
  .map(function (param) { return " assertType<typeof ".concat(param.name, ">(").concat(param.name, ");"); })
70
73
  .join("\n") + "\n\n"
@@ -153,7 +156,7 @@ var FunctionGenerator;
153
156
  + "".concat(parameters.map(function (str) { return " ".concat(str); }).join(",\n"), "\n")
154
157
  + " ): Promise<".concat(output, ">");
155
158
  }
156
- function tail(route, query, input) {
159
+ function tail(route, query, input, config) {
157
160
  var e_1, _a;
158
161
  // LIST UP TYPES
159
162
  var types = [];
@@ -201,6 +204,10 @@ var FunctionGenerator;
201
204
  + " {\n"
202
205
  + " return ".concat(path, ";\n")
203
206
  + " }\n"
207
+ +
208
+ (config.json === true && (route.method === "POST" || route.method === "PUT" || route.method === "PATCH")
209
+ ? " export const stringify = createStringifier<Input>()\n"
210
+ : "")
204
211
  + "}";
205
212
  }
206
213
  })(FunctionGenerator = exports.FunctionGenerator || (exports.FunctionGenerator = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestia",
3
- "version": "2.0.10",
3
+ "version": "2.0.11",
4
4
  "description": "Automatic SDK and Document generator for the NestJS",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -34,6 +34,7 @@
34
34
  "del": "^6.0.0",
35
35
  "glob": "^7.2.0",
36
36
  "jsonc-simple-parser": "^2.2.1",
37
+ "nestia-fetcher": "^2.0.1",
37
38
  "tgrid": "^0.8.6",
38
39
  "ts-node": "^10.4.0",
39
40
  "tsconfig-paths": "^3.14.1",
@@ -41,6 +42,7 @@
41
42
  "ttypescript": "^1.5.13",
42
43
  "typescript": "^4.6.3",
43
44
  "typescript-is": "^0.19.0",
45
+ "typescript-json": "^2.0.1",
44
46
  "typescript-transform-paths": "^3.3.1"
45
47
  },
46
48
  "devDependencies": {