@nestia/migrate 0.7.0-dev.20240201 → 0.7.1

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 (39) hide show
  1. package/lib/bundles/NEST_TEMPLATE.js +2 -7
  2. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  3. package/lib/bundles/SDK_TEMPLATE.js +1 -6
  4. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  5. package/lib/executable/migrate.js +2 -2
  6. package/lib/executable/migrate.js.map +1 -1
  7. package/lib/internal/MigrateCommander.d.ts +1 -7
  8. package/lib/internal/MigrateCommander.js +39 -50
  9. package/lib/internal/MigrateCommander.js.map +1 -1
  10. package/lib/internal/MigrateInquirer.d.ts +9 -0
  11. package/lib/internal/MigrateInquirer.js +72 -0
  12. package/lib/internal/MigrateInquirer.js.map +1 -0
  13. package/lib/programmers/ApiFunctionProgrammer.js +1 -1
  14. package/lib/programmers/ApiSimulatationProgrammer.js +1 -1
  15. package/package.json +68 -68
  16. package/src/MigrateApplication.ts +35 -35
  17. package/src/archivers/FileArchiver.ts +38 -38
  18. package/src/bundles/NEST_TEMPLATE.ts +2 -7
  19. package/src/bundles/SDK_TEMPLATE.ts +1 -6
  20. package/src/executable/bundle.ts +102 -102
  21. package/src/executable/migrate.ts +7 -7
  22. package/src/module.ts +4 -4
  23. package/src/programmers/ApiFunctionProgrammer.ts +1 -1
  24. package/src/programmers/ApiSimulatationProgrammer.ts +1 -1
  25. package/src/programmers/DtoProgrammer.ts +74 -74
  26. package/src/programmers/ImportProgrammer.ts +114 -114
  27. package/src/programmers/NestControllerProgrammer.ts +48 -48
  28. package/src/programmers/NestProgrammer.ts +74 -74
  29. package/src/structures/IMigrateProgram.ts +9 -9
  30. package/src/structures/IMigrateRoute.ts +44 -44
  31. package/src/utils/JsonTypeChecker.ts +67 -67
  32. package/src/utils/SetupWizard.ts +12 -12
  33. package/src/utils/StringUtil.ts +60 -60
  34. package/lib/bundles/TEMPLATE.d.ts +0 -5
  35. package/lib/bundles/TEMPLATE.js +0 -166
  36. package/lib/bundles/TEMPLATE.js.map +0 -1
  37. package/lib/internal/MigrateCli.d.ts +0 -3
  38. package/lib/internal/MigrateCli.js +0 -59
  39. package/lib/internal/MigrateCli.js.map +0 -1
@@ -1,38 +1,38 @@
1
- import { IMigrateFile } from "../structures/IMigrateFile";
2
-
3
- export namespace FileArchiver {
4
- export interface IOperator {
5
- mkdir(path: string): Promise<void>;
6
- writeFile(path: string, content: string): Promise<void>;
7
- }
8
-
9
- export const archive =
10
- (operator: IOperator) =>
11
- (output: string) =>
12
- async (files: IMigrateFile[]): Promise<void> => {
13
- const visited: Set<string> = new Set();
14
- for (const f of files) {
15
- await mkdir(operator.mkdir)(output)(visited)(f.location);
16
- await operator.writeFile(
17
- [output, f.location, f.file].join("/"),
18
- f.content,
19
- );
20
- }
21
- };
22
-
23
- const mkdir =
24
- (creator: (path: string) => void) =>
25
- (output: string) =>
26
- (visited: Set<string>) =>
27
- async (path: string): Promise<void> => {
28
- const sequence: string[] = path
29
- .split("/")
30
- .map((_str, i, entire) => entire.slice(0, i + 1).join("/"));
31
- for (const s of sequence)
32
- if (visited.has(s) === false)
33
- try {
34
- await creator([output, s].join("/"));
35
- visited.add(s);
36
- } catch {}
37
- };
38
- }
1
+ import { IMigrateFile } from "../structures/IMigrateFile";
2
+
3
+ export namespace FileArchiver {
4
+ export interface IOperator {
5
+ mkdir(path: string): Promise<void>;
6
+ writeFile(path: string, content: string): Promise<void>;
7
+ }
8
+
9
+ export const archive =
10
+ (operator: IOperator) =>
11
+ (output: string) =>
12
+ async (files: IMigrateFile[]): Promise<void> => {
13
+ const visited: Set<string> = new Set();
14
+ for (const f of files) {
15
+ await mkdir(operator.mkdir)(output)(visited)(f.location);
16
+ await operator.writeFile(
17
+ [output, f.location, f.file].join("/"),
18
+ f.content,
19
+ );
20
+ }
21
+ };
22
+
23
+ const mkdir =
24
+ (creator: (path: string) => void) =>
25
+ (output: string) =>
26
+ (visited: Set<string>) =>
27
+ async (path: string): Promise<void> => {
28
+ const sequence: string[] = path
29
+ .split("/")
30
+ .map((_str, i, entire) => entire.slice(0, i + 1).join("/"));
31
+ for (const s of sequence)
32
+ if (visited.has(s) === false)
33
+ try {
34
+ await creator([output, s].join("/"));
35
+ visited.add(s);
36
+ } catch {}
37
+ };
38
+ }
@@ -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.4.5\",\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.1.2\",\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.4.5\",\r\n \"@nestia/fetcher\": \"^2.4.5\",\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.3.12\",\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.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}"
56
56
  },
57
57
  {
58
58
  "location": "packages/api",
@@ -67,7 +67,7 @@ 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.4.5\",\r\n \"typia\": \"^5.3.12\"\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.0\",\r\n \"typia\": \"^5.4.1\"\r\n }\r\n}"
71
71
  },
72
72
  {
73
73
  "location": "packages/api",
@@ -129,11 +129,6 @@ export const NEST_TEMPLATE = [
129
129
  "file": "IPage.ts",
130
130
  "content": "import { tags } from \"typia\";\r\n\r\n/**\r\n * A page.\r\n *\r\n * Collection of records with pagination indformation.\r\n *\r\n * @author Samchon\r\n */\r\nexport interface IPage<T extends object> {\r\n /**\r\n * Page information.\r\n */\r\n pagination: IPage.IPagination;\r\n\r\n /**\r\n * List of records.\r\n */\r\n data: T[];\r\n}\r\nexport namespace IPage {\r\n /**\r\n * Page information.\r\n */\r\n export interface IPagination {\r\n /**\r\n * Current page number.\r\n */\r\n current: number & tags.Type<\"uint32\">;\r\n\r\n /**\r\n * Limitation of records per a page.\r\n *\r\n * @default 100\r\n */\r\n limit: number & tags.Type<\"uint32\">;\r\n\r\n /**\r\n * Count of total records in database.\r\n */\r\n records: number & tags.Type<\"uint32\">;\r\n\r\n /**\r\n * Number of total pages.\r\n *\r\n * Equal to {@link records} / {@link limit} with ceiling.\r\n */\r\n pages: number & tags.Type<\"uint32\">;\r\n }\r\n\r\n /**\r\n * Page request data\r\n */\r\n export interface IRequest {\r\n /**\r\n * Page number.\r\n */\r\n page?: number & tags.Type<\"uint32\">;\r\n\r\n /**\r\n * Limitation of records per a page.\r\n */\r\n limit?: number & tags.Type<\"uint32\">;\r\n }\r\n\r\n /**\r\n * Sorting column specialization.\r\n *\r\n * The plus means ascending order and the minus means descending order.\r\n */\r\n export type Sort<Literal extends string> = Array<\r\n `-${Literal}` | `+${Literal}`\r\n >;\r\n}\r\n"
131
131
  },
132
- {
133
- "location": "src/api/utils",
134
- "file": "NestiaSimulator.ts",
135
- "content": "import { HttpError } from \"@nestia/fetcher\";\r\n\r\nimport typia from \"typia\";\r\n\r\nexport namespace NestiaSimulator {\r\n export interface IProps {\r\n host: string;\r\n path: string;\r\n method: \"GET\" | \"POST\" | \"PATCH\" | \"PUT\" | \"DELETE\";\r\n contentType: string;\r\n }\r\n\r\n export const assert = (props: IProps) => {\r\n return {\r\n param: param(props),\r\n query: query(props),\r\n body: body(props),\r\n };\r\n };\r\n const param =\r\n (props: IProps) =>\r\n (name: string) =>\r\n <T>(task: () => T): void => {\r\n validate(\r\n (exp) => `URL parameter \"${name}\" is not ${exp.expected} type.`,\r\n )(props)(task);\r\n };\r\n\r\n const query =\r\n (props: IProps) =>\r\n <T>(task: () => T): void =>\r\n validate(\r\n () =>\r\n \"Request query parameters are not following the promised type.\",\r\n )(props)(task);\r\n\r\n const body =\r\n (props: IProps) =>\r\n <T>(task: () => T): void =>\r\n validate(() => \"Request body is not following the promised type.\")(\r\n props,\r\n )(task);\r\n\r\n const validate =\r\n (message: (exp: typia.TypeGuardError) => string, path?: string) =>\r\n (props: IProps) =>\r\n <T>(task: () => T): void => {\r\n try {\r\n task();\r\n } catch (exp) {\r\n if (typia.is<typia.TypeGuardError>(exp))\r\n throw new HttpError(\r\n props.method,\r\n props.host + props.path,\r\n 400,\r\n {\r\n \"Content-Type\": props.contentType,\r\n },\r\n JSON.stringify({\r\n method: exp.method,\r\n path: path ?? exp.path,\r\n expected: exp.expected,\r\n value: exp.value,\r\n message: message(exp),\r\n }),\r\n );\r\n throw exp;\r\n }\r\n };\r\n}\r\n"
136
- },
137
132
  {
138
133
  "location": "src/executable",
139
134
  "file": "server.ts",
@@ -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.4.5\",\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.0\",\r\n \"typia\": \"^5.4.1\"\r\n }\r\n}"
16
16
  },
17
17
  {
18
18
  "location": "",
@@ -44,11 +44,6 @@ export const SDK_TEMPLATE = [
44
44
  "file": "Primitive.ts",
45
45
  "content": "export type { Primitive } from \"@nestia/fetcher\";\r\n"
46
46
  },
47
- {
48
- "location": "src/utils",
49
- "file": "NestiaSimulator.ts",
50
- "content": "import { HttpError } from \"@nestia/fetcher\";\r\n\r\nimport typia from \"typia\";\r\n\r\nexport namespace NestiaSimulator {\r\n export interface IProps {\r\n host: string;\r\n path: string;\r\n method: \"GET\" | \"POST\" | \"PATCH\" | \"PUT\" | \"DELETE\";\r\n contentType: string;\r\n }\r\n\r\n export const assert = (props: IProps) => {\r\n return {\r\n param: param(props),\r\n query: query(props),\r\n body: body(props),\r\n };\r\n };\r\n const param =\r\n (props: IProps) =>\r\n (name: string) =>\r\n <T>(task: () => T): void => {\r\n validate(\r\n (exp) => `URL parameter \"${name}\" is not ${exp.expected} type.`,\r\n )(props)(task);\r\n };\r\n\r\n const query =\r\n (props: IProps) =>\r\n <T>(task: () => T): void =>\r\n validate(\r\n () =>\r\n \"Request query parameters are not following the promised type.\",\r\n )(props)(task);\r\n\r\n const body =\r\n (props: IProps) =>\r\n <T>(task: () => T): void =>\r\n validate(() => \"Request body is not following the promised type.\")(\r\n props,\r\n )(task);\r\n\r\n const validate =\r\n (message: (exp: typia.TypeGuardError) => string, path?: string) =>\r\n (props: IProps) =>\r\n <T>(task: () => T): void => {\r\n try {\r\n task();\r\n } catch (exp) {\r\n if (typia.is<typia.TypeGuardError>(exp))\r\n throw new HttpError(\r\n props.method,\r\n props.host + props.path,\r\n 400,\r\n {\r\n \"Content-Type\": props.contentType,\r\n },\r\n JSON.stringify({\r\n method: exp.method,\r\n path: path ?? exp.path,\r\n expected: exp.expected,\r\n value: exp.value,\r\n message: message(exp),\r\n }),\r\n );\r\n throw exp;\r\n }\r\n };\r\n}\r\n"
51
- },
52
47
  {
53
48
  "location": "",
54
49
  "file": "tsconfig.json",
@@ -1,102 +1,102 @@
1
- import cp from "child_process";
2
- import fs from "fs";
3
-
4
- import { IMigrateFile } from "../structures/IMigrateFile";
5
-
6
- const ROOT: string = `${__dirname}/../..`;
7
- const ASSETS: string = `${ROOT}/assets`;
8
-
9
- const bundle = async (props: {
10
- mode: "nest" | "sdk";
11
- repository: string;
12
- exceptions?: string[];
13
- }): Promise<void> => {
14
- const root: string = `${__dirname}/../..`;
15
- const assets: string = `${root}/assets`;
16
- const template: string = `${assets}/${props.mode}`;
17
-
18
- const clone = async () => {
19
- // CLONE REPOSITORY
20
- if (fs.existsSync(template))
21
- await fs.promises.rm(template, { recursive: true });
22
- else
23
- try {
24
- await fs.promises.mkdir(ASSETS);
25
- } catch {}
26
-
27
- cp.execSync(
28
- `git clone https://github.com/samchon/${props.repository} ${props.mode}`,
29
- {
30
- cwd: ASSETS,
31
- },
32
- );
33
-
34
- // REMOVE VUNLERABLE FILES
35
- for (const location of props.exceptions ?? [])
36
- await fs.promises.rm(`${template}/${location}`, { recursive: true });
37
- };
38
-
39
- const iterate = (collection: IMigrateFile[]) => async (location: string) => {
40
- const directory: string[] = await fs.promises.readdir(location);
41
- for (const file of directory) {
42
- const absolute: string = location + "/" + file;
43
- const stats: fs.Stats = await fs.promises.stat(absolute);
44
- if (stats.isDirectory()) await iterate(collection)(absolute);
45
- else {
46
- const content: string = await fs.promises.readFile(absolute, "utf-8");
47
- collection.push({
48
- location: (() => {
49
- const str: string = location.replace(template, "");
50
- return str[0] === "/" ? str.substring(1) : str;
51
- })(),
52
- file,
53
- content,
54
- });
55
- }
56
- }
57
- };
58
-
59
- const archive = async (collection: IMigrateFile[]): Promise<void> => {
60
- const name: string = `${props.mode.toUpperCase()}_TEMPLATE`;
61
- const body: string = JSON.stringify(collection, null, 2);
62
- const content: string = `export const ${name} = ${body}`;
63
-
64
- try {
65
- await fs.promises.mkdir(`${ROOT}/src/bundles`);
66
- } catch {}
67
- await fs.promises.writeFile(
68
- `${ROOT}/src/bundles/${name}.ts`,
69
- content,
70
- "utf8",
71
- );
72
- };
73
-
74
- const collection: IMigrateFile[] = [];
75
- await clone();
76
- await iterate(collection)(template);
77
- await archive(collection);
78
- };
79
-
80
- const main = async (): Promise<void> => {
81
- await bundle({
82
- mode: "nest",
83
- repository: "nestia-start",
84
- exceptions: [
85
- ".git",
86
- "src/api/functional",
87
- "src/controllers",
88
- "src/MyModule.ts",
89
- "src/providers",
90
- "test/features",
91
- ],
92
- });
93
- await bundle({
94
- mode: "sdk",
95
- repository: "nestia-sdk-template",
96
- exceptions: [".git", "src/functional", "src/structures"],
97
- });
98
- };
99
- main().catch((exp) => {
100
- console.error(exp);
101
- process.exit(-1);
102
- });
1
+ import cp from "child_process";
2
+ import fs from "fs";
3
+
4
+ import { IMigrateFile } from "../structures/IMigrateFile";
5
+
6
+ const ROOT: string = `${__dirname}/../..`;
7
+ const ASSETS: string = `${ROOT}/assets`;
8
+
9
+ const bundle = async (props: {
10
+ mode: "nest" | "sdk";
11
+ repository: string;
12
+ exceptions?: string[];
13
+ }): Promise<void> => {
14
+ const root: string = `${__dirname}/../..`;
15
+ const assets: string = `${root}/assets`;
16
+ const template: string = `${assets}/${props.mode}`;
17
+
18
+ const clone = async () => {
19
+ // CLONE REPOSITORY
20
+ if (fs.existsSync(template))
21
+ await fs.promises.rm(template, { recursive: true });
22
+ else
23
+ try {
24
+ await fs.promises.mkdir(ASSETS);
25
+ } catch {}
26
+
27
+ cp.execSync(
28
+ `git clone https://github.com/samchon/${props.repository} ${props.mode}`,
29
+ {
30
+ cwd: ASSETS,
31
+ },
32
+ );
33
+
34
+ // REMOVE VUNLERABLE FILES
35
+ for (const location of props.exceptions ?? [])
36
+ await fs.promises.rm(`${template}/${location}`, { recursive: true });
37
+ };
38
+
39
+ const iterate = (collection: IMigrateFile[]) => async (location: string) => {
40
+ const directory: string[] = await fs.promises.readdir(location);
41
+ for (const file of directory) {
42
+ const absolute: string = location + "/" + file;
43
+ const stats: fs.Stats = await fs.promises.stat(absolute);
44
+ if (stats.isDirectory()) await iterate(collection)(absolute);
45
+ else {
46
+ const content: string = await fs.promises.readFile(absolute, "utf-8");
47
+ collection.push({
48
+ location: (() => {
49
+ const str: string = location.replace(template, "");
50
+ return str[0] === "/" ? str.substring(1) : str;
51
+ })(),
52
+ file,
53
+ content,
54
+ });
55
+ }
56
+ }
57
+ };
58
+
59
+ const archive = async (collection: IMigrateFile[]): Promise<void> => {
60
+ const name: string = `${props.mode.toUpperCase()}_TEMPLATE`;
61
+ const body: string = JSON.stringify(collection, null, 2);
62
+ const content: string = `export const ${name} = ${body}`;
63
+
64
+ try {
65
+ await fs.promises.mkdir(`${ROOT}/src/bundles`);
66
+ } catch {}
67
+ await fs.promises.writeFile(
68
+ `${ROOT}/src/bundles/${name}.ts`,
69
+ content,
70
+ "utf8",
71
+ );
72
+ };
73
+
74
+ const collection: IMigrateFile[] = [];
75
+ await clone();
76
+ await iterate(collection)(template);
77
+ await archive(collection);
78
+ };
79
+
80
+ const main = async (): Promise<void> => {
81
+ await bundle({
82
+ mode: "nest",
83
+ repository: "nestia-start",
84
+ exceptions: [
85
+ ".git",
86
+ "src/api/functional",
87
+ "src/controllers",
88
+ "src/MyModule.ts",
89
+ "src/providers",
90
+ "test/features",
91
+ ],
92
+ });
93
+ await bundle({
94
+ mode: "sdk",
95
+ repository: "nestia-sdk-template",
96
+ exceptions: [".git", "src/functional", "src/structures"],
97
+ });
98
+ };
99
+ main().catch((exp) => {
100
+ console.error(exp);
101
+ process.exit(-1);
102
+ });
@@ -1,7 +1,7 @@
1
- #!/usr/bin/env node
2
- import { MigrateCommander } from "../internal/MigrateCommander";
3
-
4
- MigrateCommander.main().catch((exp) => {
5
- console.error(exp);
6
- process.exit(-1);
7
- });
1
+ #!/usr/bin/env node
2
+ import { MigrateCommander } from "../internal/MigrateCommander";
3
+
4
+ MigrateCommander.main().catch((exp) => {
5
+ console.error(exp);
6
+ process.exit(-1);
7
+ });
package/src/module.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from "./MigrateApplication";
2
-
3
- export * from "./structures/ISwagger";
4
- export * from "./structures/IMigrateProgram";
1
+ export * from "./MigrateApplication";
2
+
3
+ export * from "./structures/ISwagger";
4
+ export * from "./structures/IMigrateProgram";
@@ -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
@@ -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
  ),
@@ -1,74 +1,74 @@
1
- import { IPointer } from "tstl";
2
- import ts from "typescript";
3
-
4
- import { ISwaggerSchema } from "../structures/ISwaggeSchema";
5
- import { ISwaggerComponents } from "../structures/ISwaggerComponents";
6
- import { FilePrinter } from "../utils/FilePrinter";
7
- import { MapUtil } from "../utils/MapUtil";
8
- import { ImportProgrammer } from "./ImportProgrammer";
9
- import { SchemaProgrammer } from "./SchemaProgrammer";
10
-
11
- export namespace DtoProgrammer {
12
- export interface IModule {
13
- name: string;
14
- children: Map<string, IModule>;
15
- programmer:
16
- | null
17
- | ((importer: ImportProgrammer) => ts.TypeAliasDeclaration);
18
- }
19
-
20
- export const write = (
21
- components: ISwaggerComponents,
22
- ): Map<string, IModule> => {
23
- const dict: Map<string, IModule> = new Map();
24
- for (const [key, value] of Object.entries(components.schemas ?? {}))
25
- prepare(dict)(key)((importer) =>
26
- writeAlias(components)(importer)(key, value),
27
- );
28
- return dict;
29
- };
30
-
31
- const prepare =
32
- (dict: Map<string, IModule>) =>
33
- (name: string) =>
34
- (programmer: (importer: ImportProgrammer) => ts.TypeAliasDeclaration) => {
35
- const accessors: string[] = name.split(".");
36
- const modulo: IPointer<IModule> = { value: null! };
37
-
38
- accessors.forEach((acc, i) => {
39
- modulo.value = MapUtil.take(dict)(acc)(() => ({
40
- name: acc,
41
- children: new Map(),
42
- programmer: null,
43
- }));
44
- if (i === accessors.length - 1) modulo.value.programmer = programmer;
45
- dict = modulo.value.children;
46
- });
47
- return modulo!;
48
- };
49
-
50
- const writeAlias =
51
- (components: ISwaggerComponents) =>
52
- (importer: ImportProgrammer) =>
53
- (key: string, value: ISwaggerSchema) =>
54
- FilePrinter.description(
55
- ts.factory.createTypeAliasDeclaration(
56
- [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
57
- key.split(".").at(-1)!,
58
- [],
59
- SchemaProgrammer.write(components)(importer)(value),
60
- ),
61
- writeComment(value),
62
- );
63
- }
64
-
65
- const writeComment = (schema: ISwaggerSchema): string =>
66
- [
67
- ...(schema.description?.length ? [schema.description] : []),
68
- ...(schema.description?.length &&
69
- (schema.title !== undefined || schema.deprecated === true)
70
- ? [""]
71
- : []),
72
- ...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
73
- ...(schema.deprecated === true ? [`@deprecated`] : []),
74
- ].join("\n");
1
+ import { IPointer } from "tstl";
2
+ import ts from "typescript";
3
+
4
+ import { ISwaggerSchema } from "../structures/ISwaggeSchema";
5
+ import { ISwaggerComponents } from "../structures/ISwaggerComponents";
6
+ import { FilePrinter } from "../utils/FilePrinter";
7
+ import { MapUtil } from "../utils/MapUtil";
8
+ import { ImportProgrammer } from "./ImportProgrammer";
9
+ import { SchemaProgrammer } from "./SchemaProgrammer";
10
+
11
+ export namespace DtoProgrammer {
12
+ export interface IModule {
13
+ name: string;
14
+ children: Map<string, IModule>;
15
+ programmer:
16
+ | null
17
+ | ((importer: ImportProgrammer) => ts.TypeAliasDeclaration);
18
+ }
19
+
20
+ export const write = (
21
+ components: ISwaggerComponents,
22
+ ): Map<string, IModule> => {
23
+ const dict: Map<string, IModule> = new Map();
24
+ for (const [key, value] of Object.entries(components.schemas ?? {}))
25
+ prepare(dict)(key)((importer) =>
26
+ writeAlias(components)(importer)(key, value),
27
+ );
28
+ return dict;
29
+ };
30
+
31
+ const prepare =
32
+ (dict: Map<string, IModule>) =>
33
+ (name: string) =>
34
+ (programmer: (importer: ImportProgrammer) => ts.TypeAliasDeclaration) => {
35
+ const accessors: string[] = name.split(".");
36
+ const modulo: IPointer<IModule> = { value: null! };
37
+
38
+ accessors.forEach((acc, i) => {
39
+ modulo.value = MapUtil.take(dict)(acc)(() => ({
40
+ name: acc,
41
+ children: new Map(),
42
+ programmer: null,
43
+ }));
44
+ if (i === accessors.length - 1) modulo.value.programmer = programmer;
45
+ dict = modulo.value.children;
46
+ });
47
+ return modulo!;
48
+ };
49
+
50
+ const writeAlias =
51
+ (components: ISwaggerComponents) =>
52
+ (importer: ImportProgrammer) =>
53
+ (key: string, value: ISwaggerSchema) =>
54
+ FilePrinter.description(
55
+ ts.factory.createTypeAliasDeclaration(
56
+ [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
57
+ key.split(".").at(-1)!,
58
+ [],
59
+ SchemaProgrammer.write(components)(importer)(value),
60
+ ),
61
+ writeComment(value),
62
+ );
63
+ }
64
+
65
+ const writeComment = (schema: ISwaggerSchema): string =>
66
+ [
67
+ ...(schema.description?.length ? [schema.description] : []),
68
+ ...(schema.description?.length &&
69
+ (schema.title !== undefined || schema.deprecated === true)
70
+ ? [""]
71
+ : []),
72
+ ...(schema.title !== undefined ? [`@title ${schema.title}`] : []),
73
+ ...(schema.deprecated === true ? [`@deprecated`] : []),
74
+ ].join("\n");