@nestia/migrate 0.7.0 → 0.7.2

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 (44) hide show
  1. package/lib/MigrateApplication.js +43 -25
  2. package/lib/MigrateApplication.js.map +1 -1
  3. package/lib/analyzers/MethodAnalyzer.js +25 -11
  4. package/lib/analyzers/MethodAnalyzer.js.map +1 -1
  5. package/lib/bundles/NEST_TEMPLATE.js +3 -8
  6. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  7. package/lib/bundles/SDK_TEMPLATE.js +1 -6
  8. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  9. package/lib/executable/migrate.js +2 -2
  10. package/lib/executable/migrate.js.map +1 -1
  11. package/lib/internal/MigrateCommander.d.ts +1 -7
  12. package/lib/internal/MigrateCommander.js +39 -50
  13. package/lib/internal/MigrateCommander.js.map +1 -1
  14. package/lib/internal/MigrateInquirer.d.ts +9 -0
  15. package/lib/internal/MigrateInquirer.js +72 -0
  16. package/lib/internal/MigrateInquirer.js.map +1 -0
  17. package/lib/programmers/ApiFunctionProgrammer.js +3 -3
  18. package/lib/programmers/ApiFunctionProgrammer.js.map +1 -1
  19. package/lib/programmers/ApiNamespaceProgrammer.js +1 -1
  20. package/lib/programmers/ApiNamespaceProgrammer.js.map +1 -1
  21. package/lib/programmers/ApiSimulatationProgrammer.js +1 -1
  22. package/lib/programmers/NestMethodProgrammer.js +49 -37
  23. package/lib/programmers/NestMethodProgrammer.js.map +1 -1
  24. package/lib/programmers/SchemaProgrammer.js +2 -0
  25. package/lib/programmers/SchemaProgrammer.js.map +1 -1
  26. package/lib/structures/IMigrateRoute.d.ts +1 -1
  27. package/lib/structures/ISwaggerRoute.d.ts +3 -0
  28. package/package.json +68 -68
  29. package/src/analyzers/MethodAnalyzer.ts +37 -18
  30. package/src/bundles/NEST_TEMPLATE.ts +3 -3
  31. package/src/bundles/SDK_TEMPLATE.ts +1 -1
  32. package/src/programmers/ApiFunctionProgrammer.ts +3 -4
  33. package/src/programmers/ApiNamespaceProgrammer.ts +1 -1
  34. package/src/programmers/ApiSimulatationProgrammer.ts +1 -1
  35. package/src/programmers/NestMethodProgrammer.ts +27 -12
  36. package/src/programmers/SchemaProgrammer.ts +3 -0
  37. package/src/structures/IMigrateRoute.ts +2 -1
  38. package/src/structures/ISwaggerRoute.ts +3 -0
  39. package/lib/bundles/TEMPLATE.d.ts +0 -5
  40. package/lib/bundles/TEMPLATE.js +0 -166
  41. package/lib/bundles/TEMPLATE.js.map +0 -1
  42. package/lib/internal/MigrateCli.d.ts +0 -3
  43. package/lib/internal/MigrateCli.js +0 -59
  44. package/lib/internal/MigrateCli.js.map +0 -1
package/package.json CHANGED
@@ -1,68 +1,68 @@
1
- {
2
- "name": "@nestia/migrate",
3
- "version": "0.7.0",
4
- "description": "Migration program from swagger to NestJS",
5
- "main": "lib/index.js",
6
- "typings": "lib/index.d.ts",
7
- "bin": {
8
- "@nestia/migrate": "lib/executable/migrate.js"
9
- },
10
- "scripts": {
11
- "build": "rimraf lib && tsc",
12
- "bundle": "ts-node src/executable/bundle.ts",
13
- "dev": "npm run build -- --watch",
14
- "prepare": "ts-patch install && typia patch && npm run bundle",
15
- "test": "node lib/test"
16
- },
17
- "repository": {
18
- "type": "git",
19
- "url": "https://github.com/samchon/nestia"
20
- },
21
- "keywords": [
22
- "migration",
23
- "swagger",
24
- "NestJS",
25
- "nestia"
26
- ],
27
- "author": "Jeongho Nam",
28
- "license": "MIT",
29
- "bugs": {
30
- "url": "https://github.com/samchon/nestia/issues"
31
- },
32
- "homepage": "https://github.com/samchon/nestia#readme",
33
- "devDependencies": {
34
- "@nestia/core": "2.5.0",
35
- "@nestia/fetcher": "2.5.0",
36
- "@nestjs/common": "^10.3.1",
37
- "@nestjs/core": "^10.3.1",
38
- "@nestjs/platform-express": "^10.3.1",
39
- "@nestjs/platform-fastify": "^10.3.1",
40
- "@types/express": "^4.17.21",
41
- "@types/inquirer": "^9.0.7",
42
- "@types/node": "^20.3.3",
43
- "dotenv": "^16.3.1",
44
- "dotenv-expand": "^10.0.0",
45
- "rimraf": "^5.0.1",
46
- "serialize-error": "^4.1.0",
47
- "source-map-support": "^0.5.21",
48
- "ts-node": "^10.9.1",
49
- "ts-patch": "^3.1.0",
50
- "tstl": "^2.5.13",
51
- "typescript-transform-paths": "^3.4.6"
52
- },
53
- "dependencies": {
54
- "commander": "10.0.0",
55
- "inquirer": "8.2.5",
56
- "typescript": "^5.3.3",
57
- "typia": "^5.4.1"
58
- },
59
- "files": [
60
- "lib",
61
- "src",
62
- "!lib/test",
63
- "!src/test",
64
- "package.json",
65
- "README.md",
66
- "LICENSE"
67
- ]
68
- }
1
+ {
2
+ "name": "@nestia/migrate",
3
+ "version": "0.7.2",
4
+ "description": "Migration program from swagger to NestJS",
5
+ "main": "lib/index.js",
6
+ "typings": "lib/index.d.ts",
7
+ "bin": {
8
+ "@nestia/migrate": "lib/executable/migrate.js"
9
+ },
10
+ "scripts": {
11
+ "build": "rimraf lib && tsc",
12
+ "bundle": "ts-node src/executable/bundle.ts",
13
+ "dev": "npm run build -- --watch",
14
+ "prepare": "ts-patch install && typia patch && npm run bundle",
15
+ "test": "node lib/test"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/samchon/nestia"
20
+ },
21
+ "keywords": [
22
+ "migration",
23
+ "swagger",
24
+ "NestJS",
25
+ "nestia"
26
+ ],
27
+ "author": "Jeongho Nam",
28
+ "license": "MIT",
29
+ "bugs": {
30
+ "url": "https://github.com/samchon/nestia/issues"
31
+ },
32
+ "homepage": "https://github.com/samchon/nestia#readme",
33
+ "devDependencies": {
34
+ "@nestia/core": "2.5.2",
35
+ "@nestia/fetcher": "2.5.2",
36
+ "@nestjs/common": "^10.3.1",
37
+ "@nestjs/core": "^10.3.1",
38
+ "@nestjs/platform-express": "^10.3.1",
39
+ "@nestjs/platform-fastify": "^10.3.1",
40
+ "@types/express": "^4.17.21",
41
+ "@types/inquirer": "^9.0.7",
42
+ "@types/node": "^20.3.3",
43
+ "dotenv": "^16.3.1",
44
+ "dotenv-expand": "^10.0.0",
45
+ "rimraf": "^5.0.1",
46
+ "serialize-error": "^4.1.0",
47
+ "source-map-support": "^0.5.21",
48
+ "ts-node": "^10.9.1",
49
+ "ts-patch": "^3.1.0",
50
+ "tstl": "^2.5.13",
51
+ "typescript-transform-paths": "^3.4.6"
52
+ },
53
+ "dependencies": {
54
+ "commander": "10.0.0",
55
+ "inquirer": "8.2.5",
56
+ "typescript": "^5.3.3",
57
+ "typia": "^5.4.4"
58
+ },
59
+ "files": [
60
+ "lib",
61
+ "src",
62
+ "!lib/test",
63
+ "!src/test",
64
+ "package.json",
65
+ "README.md",
66
+ "LICENSE"
67
+ ]
68
+ }
@@ -12,24 +12,28 @@ export namespace MethodAnalzyer {
12
12
  (swagger: ISwagger) =>
13
13
  (props: { path: string; method: string }) =>
14
14
  (route: ISwaggerRoute): IMigrateRoute | null => {
15
- const body = emplaceBodySchema(emplaceReference(swagger)("body"))(
16
- route.requestBody,
17
- );
18
- const success = emplaceBodySchema(emplaceReference(swagger)("response"))(
19
- route.responses?.["201"] ?? route.responses?.["200"],
20
- );
21
- if (body === false || success === false) {
22
- console.log(
23
- `Failed to migrate ${props.method.toUpperCase()} ${
24
- props.path
25
- }: @nestia/migrate supports only application/json, application/x-www-form-urlencoded or text/plain format yet.`,
15
+ const body = emplaceBodySchema("request")(
16
+ emplaceReference(swagger)("body"),
17
+ )(route.requestBody);
18
+ const success = emplaceBodySchema("response")(
19
+ emplaceReference(swagger)("response"),
20
+ )(route.responses?.["201"] ?? route.responses?.["200"]);
21
+
22
+ const failures: string[] = [];
23
+ if (body === false)
24
+ failures.push(
25
+ `supports only "application/json", "application/x-www-form-urlencoded", "multipart/form-data" and "text/plain" content type in the request body.`,
26
26
  );
27
- return null;
28
- } else if (SUPPORTED_METHODS.has(props.method.toUpperCase()) === false) {
27
+ if (success === false)
28
+ failures.push(
29
+ `supports only "application/json", "application/x-www-form-urlencoded" and "text/plain" content type in the response body.`,
30
+ );
31
+ if (SUPPORTED_METHODS.has(props.method.toUpperCase()) === false)
32
+ failures.push(`does not support ${props.method.toUpperCase()} method.`);
33
+ if (failures.length) {
29
34
  console.log(
30
- `Failed to migrate ${props.method.toUpperCase()} ${
31
- props.path
32
- }: @nestia/migrate does not support ${props.method.toUpperCase()} method.`,
35
+ `Failed to migrate ${props.method.toUpperCase()} ${props.path}`,
36
+ ...failures.map((f) => ` - ${f}`),
33
37
  );
34
38
  return null;
35
39
  }
@@ -189,8 +193,8 @@ export namespace MethodAnalzyer {
189
193
  schema: query,
190
194
  }
191
195
  : null,
192
- body,
193
- success,
196
+ body: body as IMigrateRoute.IBody,
197
+ success: success as IMigrateRoute.IBody,
194
198
  exceptions: Object.fromEntries(
195
199
  Object.entries(route.responses ?? {})
196
200
  .filter(
@@ -264,6 +268,7 @@ export namespace MethodAnalzyer {
264
268
  (SwaggerTypeChecker.isArray(schema) && isNotObjectLiteral(schema.items));
265
269
 
266
270
  const emplaceBodySchema =
271
+ (from: "request" | "response") =>
267
272
  (emplacer: (schema: ISwaggerSchema) => ISwaggerSchema.IReference) =>
268
273
  (meta?: {
269
274
  description?: string;
@@ -305,6 +310,20 @@ export namespace MethodAnalzyer {
305
310
  const text = entries.find((e) => e[0].includes("text/plain"));
306
311
  if (text)
307
312
  return { type: "text/plain", key: "body", schema: { type: "string" } };
313
+
314
+ if (from === "request") {
315
+ const multipart = entries.find((e) =>
316
+ e[0].includes("multipart/form-data"),
317
+ );
318
+ if (multipart) {
319
+ const { schema } = multipart[1];
320
+ return {
321
+ type: "multipart/form-data",
322
+ key: "body",
323
+ schema: isNotObjectLiteral(schema) ? schema : emplacer(schema),
324
+ };
325
+ }
326
+ }
308
327
  return false;
309
328
  };
310
329
 
@@ -52,7 +52,7 @@ export const NEST_TEMPLATE = [
52
52
  {
53
53
  "location": "",
54
54
  "file": "package.json",
55
- "content": "{\r\n \"private\": true,\r\n \"name\": \"@ORGANIZATION/PROJECT\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"Starter kit of Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"scripts\": {\r\n \"test\": \"node bin/test\",\r\n \"test:webpack\": \"npm run webpack && node bin/test/webpack.js\",\r\n \"------------------------BUILDS------------------------\": \"\",\r\n \"build\": \"npm run build:sdk && npm run build:main && npm run build:test\",\r\n \"build:api\": \"rimraf packages/api/lib && npm run build:sdk && tsc -p packages/api/tsconfig.json\",\r\n \"build:main\": \"rimraf lib && tsc\",\r\n \"build:sdk\": \"rimraf src/api/functional && nestia sdk\",\r\n \"build:swagger\": \"npx nestia swagger\",\r\n \"build:test\": \"rimraf bin && tsc -p test/tsconfig.json\",\r\n \"dev\": \"npm run build:test -- --watch\",\r\n \"eslint\": \"eslint src && eslint test\",\r\n \"eslint:fix\": \"eslint --fix src && eslint --fix test\",\r\n \"prepare\": \"ts-patch install && typia patch\",\r\n \"prettier\": \"prettier src --write && prettier test --write\",\r\n \"------------------------WEBPACK------------------------\": \"\",\r\n \"webpack\": \"rimraf dist && webpack\",\r\n \"webpack:start\": \"cd dist && node dist/server\",\r\n \"------------------------DEPLOYS------------------------\": \"\",\r\n \"package:api\": \"npm run build:swagger && npm run build:api && cd packages/api && npm publish\",\r\n \"start\": \"node lib/executable/server\",\r\n \"start:swagger\": \"ts-node src/executable/swagger.ts\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia-start\"\r\n },\r\n \"keywords\": [\r\n \"nestia\",\r\n \"template\",\r\n \"boilerplate\"\r\n ],\r\n \"author\": \"AUTHOR\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia-start/issues\"\r\n },\r\n \"homepage\": \"https://github.com/samchon/nestia-start#readme\",\r\n \"devDependencies\": {\r\n \"@nestia/e2e\": \"^0.4.1\",\r\n \"@nestia/sdk\": \"^2.5.0\",\r\n \"@trivago/prettier-plugin-sort-imports\": \"^4.3.0\",\r\n \"@types/cli\": \"^0.11.21\",\r\n \"@types/express\": \"^4.17.21\",\r\n \"@types/inquirer\": \"^8.2.5\",\r\n \"@types/node\": \"^18.11.0\",\r\n \"@types/uuid\": \"^8.3.4\",\r\n \"@typescript-eslint/eslint-plugin\": \"^6.19.1\",\r\n \"@typescript-eslint/parser\": \"^6.19.1\",\r\n \"chalk\": \"^4.1.0\",\r\n \"cli\": \"^1.0.1\",\r\n \"copy-webpack-plugin\": \"^11.0.0\",\r\n \"eslint-plugin-deprecation\": \"^2.0.0\",\r\n \"express\": \"^4.18.2\",\r\n \"nestia\": \"^5.2.1\",\r\n \"prettier\": \"^3.2.4\",\r\n \"prettier-plugin-prisma\": \"^5.0.0\",\r\n \"rimraf\": \"^3.0.2\",\r\n \"source-map-support\": \"^0.5.21\",\r\n \"swagger-ui-express\": \"^5.0.0\",\r\n \"ts-loader\": \"^9.5.1\",\r\n \"ts-node\": \"^10.9.1\",\r\n \"ts-patch\": \"^3.0.2\",\r\n \"typescript\": \"^5.3.2\",\r\n \"typescript-transform-paths\": \"^3.4.6\",\r\n \"webpack\": \"^5.89.0\",\r\n \"webpack-cli\": \"^5.1.4\",\r\n \"write-file-webpack-plugin\": \"^4.5.1\"\r\n },\r\n \"dependencies\": {\r\n \"@nestia/core\": \"^2.5.0\",\r\n \"@nestia/fetcher\": \"^2.5.0\",\r\n \"@nestjs/common\": \"^10.3.0\",\r\n \"@nestjs/core\": \"^10.3.0\",\r\n \"@nestjs/platform-fastify\": \"^10.3.0\",\r\n \"commander\": \"10.0.0\",\r\n \"dotenv\": \"^16.3.1\",\r\n \"dotenv-expand\": \"^10.0.0\",\r\n \"inquirer\": \"8.2.5\",\r\n \"serialize-error\": \"^4.1.0\",\r\n \"tstl\": \"^2.5.13\",\r\n \"typia\": \"^5.4.1\",\r\n \"uuid\": \"^9.0.0\"\r\n },\r\n \"stackblitz\": {\r\n \"startCommand\": \"npm run prepare && npm run build:test && npm run test\"\r\n }\r\n}"
55
+ "content": "{\r\n \"private\": true,\r\n \"name\": \"@ORGANIZATION/PROJECT\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"Starter kit of Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"scripts\": {\r\n \"test\": \"node bin/test\",\r\n \"test:webpack\": \"npm run webpack && node bin/test/webpack.js\",\r\n \"------------------------BUILDS------------------------\": \"\",\r\n \"build\": \"npm run build:sdk && npm run build:main && npm run build:test\",\r\n \"build:api\": \"rimraf packages/api/lib && npm run build:sdk && tsc -p packages/api/tsconfig.json\",\r\n \"build:main\": \"rimraf lib && tsc\",\r\n \"build:sdk\": \"rimraf src/api/functional && nestia sdk\",\r\n \"build:swagger\": \"npx nestia swagger\",\r\n \"build:test\": \"rimraf bin && tsc -p test/tsconfig.json\",\r\n \"dev\": \"npm run build:test -- --watch\",\r\n \"eslint\": \"eslint src && eslint test\",\r\n \"eslint:fix\": \"eslint --fix src && eslint --fix test\",\r\n \"prepare\": \"ts-patch install && typia patch\",\r\n \"prettier\": \"prettier src --write && prettier test --write\",\r\n \"------------------------WEBPACK------------------------\": \"\",\r\n \"webpack\": \"rimraf dist && webpack\",\r\n \"webpack:start\": \"cd dist && node dist/server\",\r\n \"------------------------DEPLOYS------------------------\": \"\",\r\n \"package:api\": \"npm run build:swagger && npm run build:api && cd packages/api && npm publish\",\r\n \"start\": \"node lib/executable/server\",\r\n \"start:swagger\": \"ts-node src/executable/swagger.ts\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia-start\"\r\n },\r\n \"keywords\": [\r\n \"nestia\",\r\n \"template\",\r\n \"boilerplate\"\r\n ],\r\n \"author\": \"AUTHOR\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia-start/issues\"\r\n },\r\n \"homepage\": \"https://github.com/samchon/nestia-start#readme\",\r\n \"devDependencies\": {\r\n \"@nestia/e2e\": \"^0.4.1\",\r\n \"@nestia/sdk\": \"^2.5.2\",\r\n \"@trivago/prettier-plugin-sort-imports\": \"^4.3.0\",\r\n \"@types/cli\": \"^0.11.21\",\r\n \"@types/express\": \"^4.17.21\",\r\n \"@types/inquirer\": \"^8.2.5\",\r\n \"@types/node\": \"^18.11.0\",\r\n \"@types/uuid\": \"^8.3.4\",\r\n \"@typescript-eslint/eslint-plugin\": \"^6.19.1\",\r\n \"@typescript-eslint/parser\": \"^6.19.1\",\r\n \"chalk\": \"^4.1.0\",\r\n \"cli\": \"^1.0.1\",\r\n \"copy-webpack-plugin\": \"^11.0.0\",\r\n \"eslint-plugin-deprecation\": \"^2.0.0\",\r\n \"express\": \"^4.18.2\",\r\n \"nestia\": \"^5.2.1\",\r\n \"prettier\": \"^3.2.4\",\r\n \"prettier-plugin-prisma\": \"^5.0.0\",\r\n \"rimraf\": \"^3.0.2\",\r\n \"source-map-support\": \"^0.5.21\",\r\n \"swagger-ui-express\": \"^5.0.0\",\r\n \"ts-loader\": \"^9.5.1\",\r\n \"ts-node\": \"^10.9.1\",\r\n \"ts-patch\": \"^3.0.2\",\r\n \"typescript\": \"^5.3.2\",\r\n \"typescript-transform-paths\": \"^3.4.6\",\r\n \"webpack\": \"^5.89.0\",\r\n \"webpack-cli\": \"^5.1.4\",\r\n \"write-file-webpack-plugin\": \"^4.5.1\"\r\n },\r\n \"dependencies\": {\r\n \"@nestia/core\": \"^2.5.2\",\r\n \"@nestia/fetcher\": \"^2.5.2\",\r\n \"@nestjs/common\": \"^10.3.0\",\r\n \"@nestjs/core\": \"^10.3.0\",\r\n \"@nestjs/platform-fastify\": \"^10.3.0\",\r\n \"commander\": \"10.0.0\",\r\n \"dotenv\": \"^16.3.1\",\r\n \"dotenv-expand\": \"^10.0.0\",\r\n \"inquirer\": \"8.2.5\",\r\n \"serialize-error\": \"^4.1.0\",\r\n \"tstl\": \"^2.5.13\",\r\n \"typia\": \"^5.4.4\",\r\n \"uuid\": \"^9.0.0\"\r\n },\r\n \"stackblitz\": {\r\n \"startCommand\": \"npm run prepare && npm run build:test && npm run test\"\r\n }\r\n}"
56
56
  },
57
57
  {
58
58
  "location": "packages/api",
@@ -67,12 +67,12 @@ export const NEST_TEMPLATE = [
67
67
  {
68
68
  "location": "packages/api",
69
69
  "file": "package.json",
70
- "content": "{\r\n \"name\": \"@ORGANIZATION/PROJECT-api\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"SDK library generated by Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"typings\": \"lib/index.d.ts\",\r\n \"scripts\": {\r\n \"build\": \"npm run build:sdk && npm run compile\",\r\n \"build:sdk\": \"rimraf ../../src/api/functional && cd ../.. && npx nestia sdk && cd packages/api\",\r\n \"compile\": \"rimraf lib && tsc\",\r\n \"deploy\": \"npm run build && npm publish\",\r\n \"prepare\": \"ts-patch install && typia patch\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia\"\r\n },\r\n \"author\": \"Jeongho Nam\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia/issues\"\r\n },\r\n \"homepage\": \"https://nestia.io\",\r\n \"files\": [\r\n \"lib\",\r\n \"swagger.json\",\r\n \"package.json\",\r\n \"README.md\"\r\n ],\r\n \"devDependencies\": {\r\n \"rimraf\": \"^5.0.5\",\r\n \"ts-node\": \"^10.9.2\",\r\n \"ts-patch\": \"^3.1.2\",\r\n \"typescript\": \"^5.3.3\"\r\n },\r\n \"dependencies\": {\r\n \"@nestia/fetcher\": \"^2.5.0\",\r\n \"typia\": \"^5.4.1\"\r\n }\r\n}"
70
+ "content": "{\r\n \"name\": \"@ORGANIZATION/PROJECT-api\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"SDK library generated by Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"typings\": \"lib/index.d.ts\",\r\n \"scripts\": {\r\n \"build\": \"npm run build:sdk && npm run compile\",\r\n \"build:sdk\": \"rimraf ../../src/api/functional && cd ../.. && npx nestia sdk && cd packages/api\",\r\n \"compile\": \"rimraf lib && tsc\",\r\n \"deploy\": \"npm run build && npm publish\",\r\n \"prepare\": \"ts-patch install && typia patch\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia\"\r\n },\r\n \"author\": \"Jeongho Nam\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia/issues\"\r\n },\r\n \"homepage\": \"https://nestia.io\",\r\n \"files\": [\r\n \"lib\",\r\n \"swagger.json\",\r\n \"package.json\",\r\n \"README.md\"\r\n ],\r\n \"devDependencies\": {\r\n \"rimraf\": \"^5.0.5\",\r\n \"ts-node\": \"^10.9.2\",\r\n \"ts-patch\": \"^3.1.2\",\r\n \"typescript\": \"^5.3.3\"\r\n },\r\n \"dependencies\": {\r\n \"@nestia/fetcher\": \"^2.5.2\",\r\n \"typia\": \"^5.4.4\"\r\n }\r\n}"
71
71
  },
72
72
  {
73
73
  "location": "packages/api",
74
74
  "file": "README.md",
75
- "content": "# SDK Library\r\nThis is a SDK library generated by [`nestia`](https://nestia.io).\r\n\r\nWith this SDK library, you can easily and safely interact with backend server.\r\n\r\nJust import and call some API functions like gif image below:\r\n\r\n![nestia-sdk-demo](https://user-images.githubusercontent.com/13158709/215004990-368c589d-7101-404e-b81b-fbc936382f05.gif)\r\n\r\n> Left is server code, and right is client code utilizing the SDK\r\n\r\n\r\n\r\n\r\n# What [`Nestia`](https://nestia.io) is:\r\n![Nestia Logo](https://nestia.io/logo.png)\r\n\r\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/samchon/nestia/blob/master/LICENSE)\r\n[![npm version](https://img.shields.io/npm/v/@nestia/core.svg)](https://www.npmjs.com/package/@nestia/core)\r\n[![Downloads](https://img.shields.io/npm/dm/nestia.svg)](https://www.npmjs.com/package/nestia)\r\n[![Build Status](https://github.com/samchon/nestia/workflows/build/badge.svg)](https://github.com/samchon/nestia/actions?query=workflow%3Abuild)\r\n[![Guide Documents](https://img.shields.io/badge/guide-documents-forestgreen)](https://nestia.io/docs/)\r\n\r\n[Nestia](https://nestia.io) is a set of helper libraries for NestJS, supporting below features:\r\n\r\n - `@nestia/core`: super-fast decorators\r\n - `@nestia/sdk`\r\n - SDK generator for clients\r\n - Swagger generator evolved than ever\r\n - Automatic E2E test functions generator\r\n - `nestia`: just CLI (command line interface) tool\r\n\r\n> **Note**\r\n> \r\n> - **Only one line** required, with pure TypeScript type\r\n> - Runtime validator is **20,000x faster** than `class-validator`\r\n> - JSON serialization is **200x faster** than `class-transformer`\r\n> - SDK is similar with [tRPC](https://trpc.io), but much advanced"
75
+ "content": "# SDK Library\r\nThis is a SDK library generated by [`nestia`](https://nestia.io).\r\n\r\nWith this SDK library, you can easily and safely interact with backend server.\r\n\r\nJust import and call some API functions like gif image below:\r\n\r\n![nestia-sdk-demo](https://user-images.githubusercontent.com/13158709/215004990-368c589d-7101-404e-b81b-fbc936382f05.gif)\r\n\r\n> Left is server code, and right is client code utilizing the SDK\r\n\r\n\r\n\r\n\r\n# What [`Nestia`](https://nestia.io) is:\r\n![Nestia Logo](https://nestia.io/logo.png)\r\n\r\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/samchon/nestia/blob/master/LICENSE)\r\n[![npm version](https://img.shields.io/npm/v/@nestia/core.svg)](https://www.npmjs.com/package/@nestia/core)\r\n[![Downloads](https://img.shields.io/npm/dm/@nestia/core.svg)](https://www.npmjs.com/package/@nestia/core)\r\n[![Build Status](https://github.com/samchon/nestia/workflows/build/badge.svg)](https://github.com/samchon/nestia/actions?query=workflow%3Abuild)\r\n[![Guide Documents](https://img.shields.io/badge/guide-documents-forestgreen)](https://nestia.io/docs/)\r\n\r\nNestia is a set of helper libraries for NestJS, supporting below features:\r\n\r\n - `@nestia/core`: super-fast decorators\r\n - `@nestia/sdk`:\r\n - Swagger generator evolved than ever\r\n - SDK library generator for clients\r\n - Mockup Simulator for client applications\r\n - Automatic E2E test functions generator\r\n - `@nestia/migrate`: migration from Swagger to NestJS\r\n - `nestia`: just CLI (command line interface) tool\r\n\r\n> **Note**\r\n> \r\n> - **Only one line** required, with pure TypeScript type\r\n> - Enhance performance **30x** up\r\n> - Runtime validator is **20,000x faster** than `class-validator`\r\n> - JSON serialization is **200x faster** than `class-transformer`\r\n> - Software Development Kit\r\n> - SDK is a collection of `fetch` functions with type definitions like [tRPC](https://trpc.io/)\r\n> - Mockup simulator means embedded backend simulator in SDK\r\n> - similar with [msw](https://mswjs.io/), but fully automated"
76
76
  },
77
77
  {
78
78
  "location": "packages/api",
@@ -12,7 +12,7 @@ export const SDK_TEMPLATE = [
12
12
  {
13
13
  "location": "",
14
14
  "file": "package.json",
15
- "content": "{\r\n \"name\": \"@ORGANIZATION/PROJECT-api\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"SDK library generated by Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"typings\": \"lib/index.d.ts\",\r\n \"scripts\": {\r\n \"build\": \"rimraf lib && tsc\",\r\n \"prepare\": \"ts-patch install && typia patch\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia\"\r\n },\r\n \"author\": \"Jeongho Nam\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia/issues\"\r\n },\r\n \"homepage\": \"https://nestia.io\",\r\n \"files\": [\r\n \"lib\",\r\n \"swagger.json\",\r\n \"package.json\",\r\n \"README.md\"\r\n ],\r\n \"devDependencies\": {\r\n \"rimraf\": \"^5.0.5\",\r\n \"ts-node\": \"^10.9.2\",\r\n \"ts-patch\": \"^3.1.2\",\r\n \"typescript\": \"^5.3.3\"\r\n },\r\n \"dependencies\": {\r\n \"@nestia/fetcher\": \"^2.5.0\",\r\n \"typia\": \"^5.4.1\"\r\n }\r\n}"
15
+ "content": "{\r\n \"name\": \"@ORGANIZATION/PROJECT-api\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"SDK library generated by Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"typings\": \"lib/index.d.ts\",\r\n \"scripts\": {\r\n \"build\": \"rimraf lib && tsc\",\r\n \"prepare\": \"ts-patch install && typia patch\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia\"\r\n },\r\n \"author\": \"Jeongho Nam\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia/issues\"\r\n },\r\n \"homepage\": \"https://nestia.io\",\r\n \"files\": [\r\n \"lib\",\r\n \"swagger.json\",\r\n \"package.json\",\r\n \"README.md\"\r\n ],\r\n \"devDependencies\": {\r\n \"rimraf\": \"^5.0.5\",\r\n \"ts-node\": \"^10.9.2\",\r\n \"ts-patch\": \"^3.1.2\",\r\n \"typescript\": \"^5.3.3\"\r\n },\r\n \"dependencies\": {\r\n \"@nestia/fetcher\": \"^2.5.2\",\r\n \"typia\": \"^5.4.4\"\r\n }\r\n}"
16
16
  },
17
17
  {
18
18
  "location": "",
@@ -50,7 +50,7 @@ export namespace ApiFunctionProgrammer {
50
50
  ts.factory.createTypeReferenceNode(
51
51
  importer.external({
52
52
  type: "instance",
53
- library: "@nestia/Fetcher",
53
+ library: "@nestia/fetcher",
54
54
  name: "IConnection",
55
55
  }),
56
56
  props.route.headers
@@ -99,8 +99,7 @@ export namespace ApiFunctionProgrammer {
99
99
  (importer: ImportProgrammer) =>
100
100
  (props: IProps): ts.Statement[] => {
101
101
  const encrypted: boolean = !!props.route.success?.["x-nestia-encrypted"];
102
- const contentType: string =
103
- props.route.success?.type ?? "application/json";
102
+ const contentType: string = props.route.body?.type ?? "application/json";
104
103
 
105
104
  const caller = () =>
106
105
  ts.factory.createCallExpression(
@@ -115,7 +114,7 @@ export namespace ApiFunctionProgrammer {
115
114
  )("fetch"),
116
115
  undefined,
117
116
  [
118
- contentType
117
+ contentType && contentType !== "multipart/form-data"
119
118
  ? ts.factory.createObjectLiteralExpression(
120
119
  [
121
120
  ts.factory.createSpreadAssignment(
@@ -119,7 +119,7 @@ export namespace ApiNamespaceProgrammer {
119
119
  "request",
120
120
  props.route.body
121
121
  ? LiteralFactory.generate({
122
- type: "application/json",
122
+ type: props.route.body.type,
123
123
  encrypted: !!props.route.body["x-nestia-encrypted"],
124
124
  })
125
125
  : ts.factory.createNull(),
@@ -265,7 +265,7 @@ export namespace ApiSimulatationProgrammer {
265
265
  ts.factory.createTypeReferenceNode(
266
266
  importer.external({
267
267
  type: "instance",
268
- library: "@nestia/Fetcher",
268
+ library: "@nestia/fetcher",
269
269
  name: "HttpError",
270
270
  }),
271
271
  ),
@@ -190,9 +190,17 @@ export namespace NestMethodProgrammer {
190
190
  ...(route.body
191
191
  ? [
192
192
  writeDtoParameter({
193
- method: route.body?.["x-nestia-encrypted"]
193
+ method: route.body["x-nestia-encrypted"]
194
194
  ? "EncryptedBody"
195
- : "TypedBody",
195
+ : route.body.type === "application/json"
196
+ ? "TypedBody"
197
+ : route.body.type === "application/x-www-form-urlencoded"
198
+ ? ["TypedQuery", "Body"]
199
+ : route.body.type === "text/plain"
200
+ ? "PlainBody"
201
+ : route.body.type === "multipart/form-data"
202
+ ? ["TypedMultipart", "Body"]
203
+ : "TypedBody",
196
204
  variable: "body",
197
205
  })(components)(importer)(route.body.schema),
198
206
  ]
@@ -200,21 +208,27 @@ export namespace NestMethodProgrammer {
200
208
  ];
201
209
 
202
210
  const writeDtoParameter =
203
- (accessor: { method: string; variable: string }) =>
211
+ (accessor: { method: string | [string, string]; variable: string }) =>
204
212
  (components: ISwaggerComponents) =>
205
213
  (importer: ImportProgrammer) =>
206
- (schema: ISwaggerSchema): ts.ParameterDeclaration =>
207
- ts.factory.createParameterDeclaration(
214
+ (schema: ISwaggerSchema): ts.ParameterDeclaration => {
215
+ const instance = ts.factory.createIdentifier(
216
+ importer.external({
217
+ type: "instance",
218
+ library: "@nestia/core",
219
+ name:
220
+ typeof accessor.method === "string"
221
+ ? accessor.method
222
+ : accessor.method[0],
223
+ }),
224
+ );
225
+ return ts.factory.createParameterDeclaration(
208
226
  [
209
227
  ts.factory.createDecorator(
210
228
  ts.factory.createCallExpression(
211
- ts.factory.createIdentifier(
212
- importer.external({
213
- type: "instance",
214
- library: "@nestia/core",
215
- name: accessor.method,
216
- }),
217
- ),
229
+ typeof accessor.method === "string"
230
+ ? instance
231
+ : IdentifierFactory.access(instance)(accessor.method[1]),
218
232
  undefined,
219
233
  undefined,
220
234
  ),
@@ -225,4 +239,5 @@ export namespace NestMethodProgrammer {
225
239
  undefined,
226
240
  SchemaProgrammer.write(components)(importer)(schema),
227
241
  );
242
+ };
228
243
  }
@@ -117,6 +117,9 @@ export namespace SchemaProgrammer {
117
117
  const writeString =
118
118
  (importer: ImportProgrammer) =>
119
119
  (schema: ISwaggerSchema.IString): ts.TypeNode => {
120
+ if (schema.format === "binary")
121
+ return ts.factory.createTypeReferenceNode("File");
122
+
120
123
  const intersection: ts.TypeNode[] = [TypeFactory.keyword("string")];
121
124
  if (schema.default !== undefined)
122
125
  intersection.push(importer.tag("Default", schema.default));
@@ -33,7 +33,8 @@ export namespace IMigrateRoute {
33
33
  type:
34
34
  | "text/plain"
35
35
  | "application/json"
36
- | "application/x-www-form-urlencoded";
36
+ | "application/x-www-form-urlencoded"
37
+ | "multipart/form-data";
37
38
  schema: ISwaggerSchema;
38
39
  "x-nestia-encrypted"?: boolean;
39
40
  }
@@ -45,6 +45,9 @@ export namespace ISwaggerRoute {
45
45
  "application/x-www-form-urlencoded"?: {
46
46
  schema: ISwaggerSchema;
47
47
  };
48
+ "multipart/form-data"?: {
49
+ schema: ISwaggerSchema;
50
+ };
48
51
  "*/*"?: {
49
52
  schema: ISwaggerSchema;
50
53
  };
@@ -1,5 +0,0 @@
1
- export declare const NESTJS_TEMPLATE: {
2
- location: string;
3
- file: string;
4
- content: string;
5
- }[];