nestia 2.0.8 → 2.0.11-dev.20220419
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 +20 -7
- package/bin/IConfiguration.d.ts +1 -0
- package/bin/IConfiguration.d.ts.map +1 -1
- package/bin/analyses/ReflectAnalyzer.d.ts.map +1 -1
- package/bin/analyses/ReflectAnalyzer.js +4 -3
- package/bin/executable/internal/NestiaConfig.js +8 -0
- package/bin/generates/FileGenerator.d.ts.map +1 -1
- package/bin/generates/FileGenerator.js +9 -6
- package/bin/generates/FunctionGenerator.d.ts +2 -1
- package/bin/generates/FunctionGenerator.d.ts.map +1 -1
- package/bin/generates/FunctionGenerator.js +13 -6
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -150,7 +150,8 @@ Write below content as the `nestia.config.ts` file and place it onto the root di
|
|
|
150
150
|
```typescript
|
|
151
151
|
export = {
|
|
152
152
|
input: "src/controllers",
|
|
153
|
-
output: "src/api"
|
|
153
|
+
output: "src/api",
|
|
154
|
+
assert: false
|
|
154
155
|
};
|
|
155
156
|
```
|
|
156
157
|
|
|
@@ -160,10 +161,11 @@ export = {
|
|
|
160
161
|
> export = {
|
|
161
162
|
> input: "src/**/*.controller.ts",
|
|
162
163
|
> /* input: {
|
|
163
|
-
> include: ["src/controllers
|
|
164
|
-
> exclude: ["src/controllers
|
|
164
|
+
> include: ["src/controllers/**\/*.controller.ts"],
|
|
165
|
+
> exclude: ["src/controllers/**\/fake_*.controller.ts"]
|
|
165
166
|
> },*/
|
|
166
|
-
> output: "src/api"
|
|
167
|
+
> output: "src/api",
|
|
168
|
+
> assert: true
|
|
167
169
|
> }
|
|
168
170
|
> ```
|
|
169
171
|
|
|
@@ -196,9 +198,20 @@ For your deep understanding about this directory structure with this **Nestia**,
|
|
|
196
198
|
## Demonstration
|
|
197
199
|
To demonstrate which SDK codes would be generated by this **Nestia**:
|
|
198
200
|
|
|
199
|
-
-
|
|
200
|
-
|
|
201
|
-
|
|
201
|
+
- Representative files
|
|
202
|
+
- [Controllers of the NestJS](https://github.com/samchon/nestia/tree/master/src/test/demonstrations/default/src/controllers/base/SaleCommentsController.ts)
|
|
203
|
+
- [Structures used in the RestAPI](https://github.com/samchon/nestia/tree/master/src/test/demonstrations/default/src/api/structures/sales/articles/ISaleArticle.ts)
|
|
204
|
+
- [SDK generated by this **Nestia**](https://github.com/samchon/nestia/tree/master/src/test/demonstrations/default/src/api/functional/consumers/sales/reviews/index.ts)
|
|
205
|
+
- Demonstration Projects
|
|
206
|
+
- [absolute](https://github.com/samchon/nestia/tree/master/src/test/demonstrations/absolute): Absolute path with the `baseUrl` option
|
|
207
|
+
- [alias@api](https://github.com/samchon/nestia/tree/master/src/test/demonstrations/alias@api): The `src/api` directory has been aliased by `paths` option
|
|
208
|
+
- [alias@src](https://github.com/samchon/nestia/tree/master/src/test/demonstrations/alias@src): Entire `src` directory has been aliased by `paths` option
|
|
209
|
+
- [default](https://github.com/samchon/nestia/tree/master/src/test/demonstrations/default): No `tsconfig.json` and `nestia.config.ts`
|
|
210
|
+
- [esnext](https://github.com/samchon/nestia/tree/master/src/test/demonstrations/esnext): ECMAScript target version is `ESNEXT`
|
|
211
|
+
- [exclude](https://github.com/samchon/nestia/tree/master/src/test/demonstrations/exclude): Exclude option using the `--exclude` commad
|
|
212
|
+
- [nestia.config.ts](https://github.com/samchon/nestia/tree/master/src/test/demonstrations/nestia.config.ts): Configured `nestia.config.ts` with `assert` mode
|
|
213
|
+
- [reference](https://github.com/samchon/nestia/tree/master/src/test/demonstrations/reference): Configured input files as `src/**/*.controller.ts`
|
|
214
|
+
- [tsconfig.json](https://github.com/samchon/nestia/tree/master/src/test/demonstrations/tsconfig.json): Special configuration through the `tsconfig.json`
|
|
202
215
|
|
|
203
216
|
### Controller
|
|
204
217
|
If you've decided to adapt this **Nestia** and you want to generate the SDK directly, you don't need any extra work. Just keep you controller class down and do noting. The only one exceptional case that you need an extra dedication is, when you want to explain about the API function to the client developers through the comments.
|
package/bin/IConfiguration.d.ts
CHANGED
|
@@ -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;
|
|
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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReflectAnalyzer.d.ts","sourceRoot":"","sources":["../../src/analyses/ReflectAnalyzer.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAQxD,yBAAiB,eAAe,CAChC;IACI,SAAsB,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAiBxF;
|
|
1
|
+
{"version":3,"file":"ReflectAnalyzer.d.ts","sourceRoot":"","sources":["../../src/analyses/ReflectAnalyzer.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAQxD,yBAAiB,eAAe,CAChC;IACI,SAAsB,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAiBxF;CA4LJ"}
|
|
@@ -181,11 +181,12 @@ var ReflectAnalyzer;
|
|
|
181
181
|
return meta;
|
|
182
182
|
}
|
|
183
183
|
function _Get_prototype_entries(creator) {
|
|
184
|
-
var
|
|
184
|
+
var keyList = Object.getOwnPropertyNames(creator.prototype);
|
|
185
|
+
var entries = keyList.map(function (key) { return [key, creator.prototype[key]]; });
|
|
185
186
|
var parent = Object.getPrototypeOf(creator);
|
|
186
187
|
if (parent.prototype !== undefined)
|
|
187
|
-
|
|
188
|
-
return
|
|
188
|
+
entries.push.apply(entries, __spreadArray([], __read(_Get_prototype_entries(parent)), false));
|
|
189
|
+
return entries;
|
|
189
190
|
}
|
|
190
191
|
/* ---------------------------------------------------------
|
|
191
192
|
FUNCTION
|
|
@@ -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 {};
|
|
@@ -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;
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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,
|
|
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(
|
|
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,
|
|
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,
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "2.0.11-dev.20220419",
|
|
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.0",
|
|
44
46
|
"typescript-transform-paths": "^3.3.1"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|