@nestia/migrate 14.0.0 → 14.0.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 (182) hide show
  1. package/README.md +1 -1
  2. package/lib/NestiaMigrateApplication.d.ts +111 -0
  3. package/lib/NestiaMigrateApplication.js +148 -9
  4. package/lib/NestiaMigrateApplication.js.map +1 -1
  5. package/lib/NestiaMigrateApplication.mjs +147 -5
  6. package/lib/analyzers/NestiaMigrateControllerAnalyzer.d.ts +58 -0
  7. package/lib/analyzers/NestiaMigrateControllerAnalyzer.js +88 -2
  8. package/lib/analyzers/NestiaMigrateControllerAnalyzer.js.map +1 -1
  9. package/lib/analyzers/NestiaMigrateControllerAnalyzer.mjs +20 -2
  10. package/lib/archivers/NestiaMigrateFileArchiver.d.ts +34 -0
  11. package/lib/archivers/NestiaMigrateFileArchiver.js +34 -0
  12. package/lib/archivers/NestiaMigrateFileArchiver.js.map +1 -1
  13. package/lib/bundles/NEST_TEMPLATE.js +1 -1
  14. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  15. package/lib/bundles/NEST_TEMPLATE.mjs +1 -1
  16. package/lib/bundles/SDK_TEMPLATE.js +1 -1
  17. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  18. package/lib/bundles/SDK_TEMPLATE.mjs +1 -1
  19. package/lib/executable/NestiaMigrateCommander.d.ts +36 -0
  20. package/lib/executable/NestiaMigrateCommander.js +43 -1
  21. package/lib/executable/NestiaMigrateCommander.js.map +1 -1
  22. package/lib/executable/NestiaMigrateCommander.mjs +4 -2
  23. package/lib/executable/NestiaMigrateInquirer.d.ts +29 -0
  24. package/lib/executable/NestiaMigrateInquirer.js +27 -25
  25. package/lib/executable/NestiaMigrateInquirer.js.map +1 -1
  26. package/lib/executable/NestiaMigrateInquirer.mjs +5 -7
  27. package/lib/factories/ExpressionFactory.d.ts +14 -0
  28. package/lib/factories/ExpressionFactory.js +14 -0
  29. package/lib/factories/ExpressionFactory.js.map +1 -1
  30. package/lib/factories/IdentifierFactory.d.ts +20 -0
  31. package/lib/factories/IdentifierFactory.js +20 -0
  32. package/lib/factories/IdentifierFactory.js.map +1 -1
  33. package/lib/factories/LiteralFactory.d.ts +18 -2
  34. package/lib/factories/LiteralFactory.js +18 -2
  35. package/lib/factories/LiteralFactory.js.map +1 -1
  36. package/lib/factories/StatementFactory.d.ts +26 -1
  37. package/lib/factories/StatementFactory.js +26 -1
  38. package/lib/factories/StatementFactory.js.map +1 -1
  39. package/lib/factories/SupportedStringFormats.d.ts +6 -0
  40. package/lib/factories/SupportedStringFormats.js +33 -0
  41. package/lib/factories/SupportedStringFormats.js.map +1 -0
  42. package/lib/factories/SupportedStringFormats.mjs +34 -0
  43. package/lib/factories/SupportedStringFormats.mjs.map +1 -0
  44. package/lib/factories/TypeFactory.d.ts +21 -0
  45. package/lib/factories/TypeFactory.js +13 -0
  46. package/lib/factories/TypeFactory.js.map +1 -1
  47. package/lib/factories/TypeLiteralFactory.d.ts +18 -0
  48. package/lib/factories/TypeLiteralFactory.js +18 -0
  49. package/lib/factories/TypeLiteralFactory.js.map +1 -1
  50. package/lib/internal/ts.d.ts +153 -0
  51. package/lib/internal/ts.js.map +1 -1
  52. package/lib/programmers/NestiaMigrateApiFileProgrammer.d.ts +31 -0
  53. package/lib/programmers/NestiaMigrateApiFileProgrammer.js +17 -0
  54. package/lib/programmers/NestiaMigrateApiFileProgrammer.js.map +1 -1
  55. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.d.ts +40 -0
  56. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js +34 -5
  57. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js.map +1 -1
  58. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.mjs +4 -2
  59. package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.d.ts +39 -0
  60. package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js +57 -13
  61. package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js.map +1 -1
  62. package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.mjs +17 -8
  63. package/lib/programmers/NestiaMigrateApiProgrammer.d.ts +18 -0
  64. package/lib/programmers/NestiaMigrateApiProgrammer.js +18 -0
  65. package/lib/programmers/NestiaMigrateApiProgrammer.js.map +1 -1
  66. package/lib/programmers/NestiaMigrateApiProgrammer.mjs +1 -1
  67. package/lib/programmers/NestiaMigrateApiSimulationProgrammer.d.ts +40 -0
  68. package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js +51 -22
  69. package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js.map +1 -1
  70. package/lib/programmers/NestiaMigrateApiSimulationProgrammer.mjs +13 -20
  71. package/lib/programmers/NestiaMigrateApiStartProgrammer.d.ts +17 -0
  72. package/lib/programmers/NestiaMigrateApiStartProgrammer.js +19 -8
  73. package/lib/programmers/NestiaMigrateApiStartProgrammer.js.map +1 -1
  74. package/lib/programmers/NestiaMigrateApiStartProgrammer.mjs +1 -6
  75. package/lib/programmers/NestiaMigrateDtoProgrammer.d.ts +30 -0
  76. package/lib/programmers/NestiaMigrateDtoProgrammer.js +17 -0
  77. package/lib/programmers/NestiaMigrateDtoProgrammer.js.map +1 -1
  78. package/lib/programmers/NestiaMigrateE2eFileProgrammer.d.ts +39 -0
  79. package/lib/programmers/NestiaMigrateE2eFileProgrammer.js +46 -5
  80. package/lib/programmers/NestiaMigrateE2eFileProgrammer.js.map +1 -1
  81. package/lib/programmers/NestiaMigrateE2eFileProgrammer.mjs +6 -2
  82. package/lib/programmers/NestiaMigrateE2eProgrammer.d.ts +16 -0
  83. package/lib/programmers/NestiaMigrateE2eProgrammer.js +16 -0
  84. package/lib/programmers/NestiaMigrateE2eProgrammer.js.map +1 -1
  85. package/lib/programmers/NestiaMigrateImportProgrammer.d.ts +75 -0
  86. package/lib/programmers/NestiaMigrateImportProgrammer.js +58 -3
  87. package/lib/programmers/NestiaMigrateImportProgrammer.js.map +1 -1
  88. package/lib/programmers/NestiaMigrateImportProgrammer.mjs +58 -3
  89. package/lib/programmers/NestiaMigrateNestControllerProgrammer.d.ts +28 -0
  90. package/lib/programmers/NestiaMigrateNestControllerProgrammer.js +16 -0
  91. package/lib/programmers/NestiaMigrateNestControllerProgrammer.js.map +1 -1
  92. package/lib/programmers/NestiaMigrateNestMethodProgrammer.d.ts +30 -0
  93. package/lib/programmers/NestiaMigrateNestMethodProgrammer.js +85 -13
  94. package/lib/programmers/NestiaMigrateNestMethodProgrammer.js.map +1 -1
  95. package/lib/programmers/NestiaMigrateNestMethodProgrammer.mjs +46 -9
  96. package/lib/programmers/NestiaMigrateNestModuleProgrammer.d.ts +16 -0
  97. package/lib/programmers/NestiaMigrateNestModuleProgrammer.js +16 -0
  98. package/lib/programmers/NestiaMigrateNestModuleProgrammer.js.map +1 -1
  99. package/lib/programmers/NestiaMigrateNestProgrammer.d.ts +17 -0
  100. package/lib/programmers/NestiaMigrateNestProgrammer.js +17 -0
  101. package/lib/programmers/NestiaMigrateNestProgrammer.js.map +1 -1
  102. package/lib/programmers/NestiaMigrateSchemaProgrammer.d.ts +16 -0
  103. package/lib/programmers/NestiaMigrateSchemaProgrammer.js +45 -9
  104. package/lib/programmers/NestiaMigrateSchemaProgrammer.js.map +1 -1
  105. package/lib/programmers/NestiaMigrateSchemaProgrammer.mjs +19 -8
  106. package/lib/structures/INestiaMigrateConfig.d.ts +21 -0
  107. package/lib/structures/INestiaMigrateContext.d.ts +15 -0
  108. package/lib/structures/INestiaMigrateController.d.ts +13 -0
  109. package/lib/structures/INestiaMigrateFile.d.ts +11 -0
  110. package/lib/utils/FilePrinter.d.ts +33 -0
  111. package/lib/utils/FilePrinter.js +33 -0
  112. package/lib/utils/FilePrinter.js.map +1 -1
  113. package/lib/utils/MapUtil.d.ts +17 -0
  114. package/lib/utils/MapUtil.js +19 -3
  115. package/lib/utils/MapUtil.js.map +1 -1
  116. package/lib/utils/MapUtil.mjs +1 -2
  117. package/lib/utils/PathTemplate.d.ts +41 -0
  118. package/lib/utils/PathTemplate.js +56 -0
  119. package/lib/utils/PathTemplate.js.map +1 -0
  120. package/lib/utils/PathTemplate.mjs +34 -0
  121. package/lib/utils/PathTemplate.mjs.map +1 -0
  122. package/lib/utils/RequestBody.d.ts +22 -0
  123. package/lib/utils/RequestBody.js +29 -0
  124. package/lib/utils/RequestBody.js.map +1 -0
  125. package/lib/utils/RequestBody.mjs +9 -0
  126. package/lib/utils/RequestBody.mjs.map +1 -0
  127. package/lib/utils/StringUtil.d.ts +55 -0
  128. package/lib/utils/StringUtil.js +93 -8
  129. package/lib/utils/StringUtil.js.map +1 -1
  130. package/lib/utils/StringUtil.mjs +30 -8
  131. package/lib/utils/SuccessStatus.d.ts +34 -0
  132. package/lib/utils/SuccessStatus.js +48 -0
  133. package/lib/utils/SuccessStatus.js.map +1 -0
  134. package/lib/utils/SuccessStatus.mjs +14 -0
  135. package/lib/utils/SuccessStatus.mjs.map +1 -0
  136. package/package.json +5 -4
  137. package/src/NestiaMigrateApplication.ts +151 -13
  138. package/src/analyzers/NestiaMigrateControllerAnalyzer.ts +94 -2
  139. package/src/archivers/NestiaMigrateFileArchiver.ts +34 -0
  140. package/src/bundles/NEST_TEMPLATE.ts +1 -1
  141. package/src/bundles/SDK_TEMPLATE.ts +1 -1
  142. package/src/executable/NestiaMigrateCommander.ts +47 -1
  143. package/src/executable/NestiaMigrateInquirer.ts +41 -26
  144. package/src/factories/ExpressionFactory.ts +14 -0
  145. package/src/factories/IdentifierFactory.ts +20 -0
  146. package/src/factories/LiteralFactory.ts +18 -2
  147. package/src/factories/StatementFactory.ts +26 -1
  148. package/src/factories/SupportedStringFormats.ts +29 -0
  149. package/src/factories/TypeFactory.ts +21 -0
  150. package/src/factories/TypeLiteralFactory.ts +18 -0
  151. package/src/internal/ts.ts +153 -0
  152. package/src/programmers/NestiaMigrateApiFileProgrammer.ts +35 -0
  153. package/src/programmers/NestiaMigrateApiFunctionProgrammer.ts +53 -4
  154. package/src/programmers/NestiaMigrateApiNamespaceProgrammer.ts +83 -20
  155. package/src/programmers/NestiaMigrateApiProgrammer.ts +18 -0
  156. package/src/programmers/NestiaMigrateApiSimulationProgrammer.ts +66 -73
  157. package/src/programmers/NestiaMigrateApiStartProgrammer.ts +19 -10
  158. package/src/programmers/NestiaMigrateDtoProgrammer.ts +33 -0
  159. package/src/programmers/NestiaMigrateE2eFileProgrammer.ts +83 -8
  160. package/src/programmers/NestiaMigrateE2eProgrammer.ts +16 -0
  161. package/src/programmers/NestiaMigrateImportProgrammer.ts +86 -5
  162. package/src/programmers/NestiaMigrateNestControllerProgrammer.ts +30 -0
  163. package/src/programmers/NestiaMigrateNestMethodProgrammer.ts +122 -29
  164. package/src/programmers/NestiaMigrateNestModuleProgrammer.ts +16 -0
  165. package/src/programmers/NestiaMigrateNestProgrammer.ts +17 -0
  166. package/src/programmers/NestiaMigrateSchemaProgrammer.ts +53 -18
  167. package/src/structures/INestiaMigrateConfig.ts +26 -0
  168. package/src/structures/INestiaMigrateContext.ts +17 -0
  169. package/src/structures/INestiaMigrateController.ts +16 -0
  170. package/src/structures/INestiaMigrateFile.ts +13 -0
  171. package/src/utils/FilePrinter.ts +33 -0
  172. package/src/utils/MapUtil.ts +18 -2
  173. package/src/utils/PathTemplate.ts +61 -0
  174. package/src/utils/RequestBody.ts +27 -0
  175. package/src/utils/StringUtil.ts +101 -9
  176. package/src/utils/SuccessStatus.ts +49 -0
  177. package/lib/factories/FormatCheatSheet.d.ts +0 -25
  178. package/lib/factories/FormatCheatSheet.js +0 -34
  179. package/lib/factories/FormatCheatSheet.js.map +0 -1
  180. package/lib/factories/FormatCheatSheet.mjs +0 -31
  181. package/lib/factories/FormatCheatSheet.mjs.map +0 -1
  182. package/src/factories/FormatCheatSheet.ts +0 -71
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestia/migrate",
3
- "version": "14.0.0",
3
+ "version": "14.0.2",
4
4
  "description": "Migration program from swagger to NestJS",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -52,7 +52,7 @@
52
52
  "prettier": "^3.8.1",
53
53
  "prettier-plugin-jsdoc": "^1.8.0",
54
54
  "tstl": "^3.0.0",
55
- "typia": "^15.0.0"
55
+ "typia": "15.0.0"
56
56
  },
57
57
  "files": [
58
58
  "lib",
@@ -67,10 +67,11 @@
67
67
  "access": "public"
68
68
  },
69
69
  "scripts": {
70
- "build": "pnpm run bundle && rimraf lib && ttsc && tsc --emitDeclarationOnly && rolldown -c && node ../../deploy/verify-package-exports.cjs --esm",
70
+ "build": "pnpm run bundle && rimraf lib && ttsc && tsc --emitDeclarationOnly && rolldown -c",
71
71
  "bundle": "node src/executable/bundle.js",
72
72
  "dev": "rimraf lib && ttsc --watch",
73
- "test": "node lib/test"
73
+ "test": "node lib/test",
74
+ "evidence": "evidence"
74
75
  },
75
76
  "types": "lib/index.d.ts",
76
77
  "module": "lib/index.mjs"
@@ -9,6 +9,7 @@ import {
9
9
  } from "@typia/interface";
10
10
  import type { IValidation } from "@typia/interface";
11
11
  import { HttpMigration, OpenApiConverter } from "@typia/utils";
12
+ import { TreeSet } from "tstl";
12
13
 
13
14
  import { NEST_TEMPLATE } from "./bundles/NEST_TEMPLATE";
14
15
  import { SDK_TEMPLATE } from "./bundles/SDK_TEMPLATE";
@@ -19,6 +20,32 @@ import { NestiaMigrateNestProgrammer } from "./programmers/NestiaMigrateNestProg
19
20
  import { INestiaMigrateConfig } from "./structures/INestiaMigrateConfig";
20
21
  import { INestiaMigrateContext } from "./structures/INestiaMigrateContext";
21
22
 
23
+ /**
24
+ * Converts an OpenAPI document into a NestJS project or an SDK project, as a
25
+ * map from file path to file content.
26
+ *
27
+ * The constructor analyzes an emended OpenAPI document once; `assert` and
28
+ * `validate` upgrade a document of any supported version to that form first.
29
+ * `nest` and `sdk` then compose the files of the bundled template with the
30
+ * generated ones.
31
+ *
32
+ * The constructor analyzes the document once; generation walks templates and
33
+ * delegates per-route/schema emission, with the context builder’s accessor trie
34
+ * indexing strict prefixes.
35
+ *
36
+ * The instance shares its analyzed application between nest and sdk calls.
37
+ * Generation creates fresh context/accessor copies because its mode and config
38
+ * can differ.
39
+ *
40
+ * One instance retains its original document and analysis until callers release
41
+ * it; generated file maps are returned to callers rather than accumulated on
42
+ * the instance.
43
+ *
44
+ * @evidence contracts/common.md#principled-implementation The constructor analyzes the emended document into routes with `HttpMigration`, and the two generators start from the bundled template files, drop the paths the generators own (structures, functional API, controllers, feature tests), and add the generated files, so the result is the template with those trees replaced.
45
+ * @evidence contracts/common.md#clear-and-simple-design One class with two generators sharing one context builder; the accessor conflict escape and the package renaming are module-private functions.
46
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts Route analysis and the OpenAPI upgrade come from `@typia/utils`, and no document, path, or type name is special-cased; QUERY-method routes are left out because the SDK has no representation for them.
47
+ * @evidence contracts/common.md#meaningful-documentation The comment states what the class produces, when the document is analyzed, and how the two generators use the template.
48
+ */
22
49
  export class NestiaMigrateApplication {
23
50
  private readonly data_: IHttpMigrateApplication;
24
51
 
@@ -29,6 +56,18 @@ export class NestiaMigrateApplication {
29
56
  this.data_ = HttpMigration.application(document);
30
57
  }
31
58
 
59
+ /**
60
+ * Creates the application from a document of any supported OpenAPI or Swagger
61
+ * version, and throws when the document cannot be upgraded.
62
+ *
63
+ * Version conversion and route analysis scale with the document’s routes and
64
+ * schemas; this wrapper delegates each once.
65
+ *
66
+ * @evidence contracts/common.md#principled-implementation The document is upgraded by `OpenApiConverter.upgradeDocument`, which owns the version differences, so this function only wraps a successful result.
67
+ * @evidence contracts/common.md#clear-and-simple-design One expression.
68
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It does not repair or guess invalid documents.
69
+ * @evidence contracts/common.md#meaningful-documentation The comment states the accepted versions and the throwing behavior.
70
+ */
32
71
  public static assert(
33
72
  document:
34
73
  | SwaggerV2.IDocument
@@ -42,6 +81,18 @@ export class NestiaMigrateApplication {
42
81
  );
43
82
  }
44
83
 
84
+ /**
85
+ * Creates the application, or returns the failure as an `IValidation` instead
86
+ * of throwing.
87
+ *
88
+ * Version conversion and route analysis scale with the document’s routes and
89
+ * schemas; validation delegates once and formats one caught failure.
90
+ *
91
+ * @evidence contracts/common.md#principled-implementation The upgrade runs inside a `try`, and an error becomes one validation error whose path is the input and whose value is the message, so a caller can report it.
92
+ * @evidence contracts/common.md#clear-and-simple-design The non-throwing twin of `assert`, sharing its constructor call.
93
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The failure is reported, not hidden, and the message is the original one.
94
+ * @evidence contracts/common.md#meaningful-documentation The comment states the result shape.
95
+ */
45
96
  public static validate(
46
97
  document:
47
98
  | SwaggerV2.IDocument
@@ -77,10 +128,47 @@ export class NestiaMigrateApplication {
77
128
  /* -----------------------------------------------------------
78
129
  ACCESSORS
79
130
  ----------------------------------------------------------- */
131
+ /**
132
+ * Returns the analyzed application: the routes and the operations that could
133
+ * not be migrated.
134
+ *
135
+ * Returning the existing analysis reference uses constant work.
136
+ *
137
+ * The constructor’s analysis is returned directly to every caller; callers
138
+ * receive mutable shared state rather than an independently refreshed view.
139
+ *
140
+ * @evidence contracts/common.md#principled-implementation The analysis is done once in the constructor and returned by reference.
141
+ * @evidence contracts/common.md#clear-and-simple-design One accessor.
142
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It exposes what the analysis produced.
143
+ * @evidence contracts/common.md#meaningful-documentation The comment states what is returned.
144
+ */
80
145
  public getData(): IHttpMigrateApplication {
81
146
  return this.data_;
82
147
  }
83
148
 
149
+ /**
150
+ * Generates a NestJS monorepo project from the document.
151
+ *
152
+ * The files are the template, the controllers, the module, the DTO
153
+ * structures, the functional API, and, when requested, the e2e tests. A
154
+ * package name replaces the placeholder in every file.
155
+ *
156
+ * Template filtering and renaming scale with template/output bytes;
157
+ * programmers traverse routes and schemas. Accessor conflict escape indexes R
158
+ * routes with at most D segments in a trie. Ordered terminal sets preserve
159
+ * first-route precedence with logarithmic updates, and each escape probes
160
+ * only the current D-segment path rather than scanning R routes. Trie state
161
+ * holds original/final prefixes only and is local to generation.
162
+ *
163
+ * The instance’s route analysis is reused. Each call recomputes
164
+ * mode/config-dependent output and copies accessors because conflict escaping
165
+ * mutates them; returned maps remain caller-owned.
166
+ *
167
+ * @evidence contracts/common.md#principled-implementation The context copies the routes and escapes accessors that would collide with a shorter accessor, the template entries of the generated trees are removed, the programmers write the replacements, and `keyword: false` rewrites the one template setting that selects keyword parameters.
168
+ * @evidence contracts/common.md#clear-and-simple-design One method that composes the generators; each generator owns its own files.
169
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The template is the published starter, and the only textual edit of it is the documented keyword setting.
170
+ * @evidence contracts/common.md#meaningful-documentation The comment states what is generated and the package renaming.
171
+ */
84
172
  public nest(config: INestiaMigrateConfig): Record<string, string> {
85
173
  const context: INestiaMigrateContext = createContext(
86
174
  "nest",
@@ -111,6 +199,30 @@ export class NestiaMigrateApplication {
111
199
  return config.package ? renameSlug(config.package, files) : files;
112
200
  }
113
201
 
202
+ /**
203
+ * Generates an SDK project from the document.
204
+ *
205
+ * The files are the template, the DTO structures, the functional API, the
206
+ * start script, the swagger document in its emended form, and, when
207
+ * requested, the e2e tests. A package name replaces the placeholder in every
208
+ * file.
209
+ *
210
+ * Template filtering and renaming scale with template/output bytes;
211
+ * programmers traverse routes and schemas. Accessor conflict escape indexes R
212
+ * routes with at most D segments in a trie. Ordered terminal sets preserve
213
+ * first-route precedence with logarithmic updates, and each escape probes
214
+ * only the current D-segment path rather than scanning R routes. Trie state
215
+ * holds original/final prefixes only and is local to generation.
216
+ *
217
+ * The instance’s route analysis is reused; mode/config-dependent output is
218
+ * recomputed with fresh accessor copies, and returned maps remain
219
+ * caller-owned.
220
+ *
221
+ * @evidence contracts/common.md#principled-implementation The context is built as for `nest`, the template entries of the generated trees are removed, the programmers write the replacements, and the emended document the application was built from, which is the input after any upgrade, is written beside them as `swagger.json`.
222
+ * @evidence contracts/common.md#clear-and-simple-design One method that composes the generators, sharing the context builder with `nest`.
223
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The template is the published starter, and no document is special-cased.
224
+ * @evidence contracts/common.md#meaningful-documentation The comment states what is generated and the package renaming.
225
+ */
114
226
  public sdk(config: INestiaMigrateConfig): Record<string, string> {
115
227
  const context: INestiaMigrateContext = createContext(
116
228
  "sdk",
@@ -161,21 +273,47 @@ const createContext = (
161
273
  const escapeConflictingAccessors = (
162
274
  routes: IHttpMigrateRoute[],
163
275
  ): IHttpMigrateRoute[] => {
164
- for (const route of routes)
276
+ type Prefix = {
277
+ children: Map<string, Prefix>;
278
+ terminal: TreeSet<number>;
279
+ };
280
+ const create = (): Prefix => ({
281
+ children: new Map(),
282
+ terminal: new TreeSet(),
283
+ });
284
+ const root: Prefix = create();
285
+ const insert = (accessor: string[], index: number): Prefix => {
286
+ let node = root;
287
+ for (const segment of accessor) {
288
+ let child = node.children.get(segment);
289
+ if (child === undefined) {
290
+ child = create();
291
+ node.children.set(segment, child);
292
+ }
293
+ node = child;
294
+ }
295
+ node.terminal.insert(index);
296
+ return node;
297
+ };
298
+ const terminals = routes.map((route, index) => insert(route.accessor, index));
299
+ for (const [routeIndex, route] of routes.entries()) {
165
300
  while (true) {
166
- const neighbor: IHttpMigrateRoute | undefined = routes.find(
167
- (candidate) =>
168
- candidate !== route &&
169
- candidate.accessor.length < route.accessor.length &&
170
- route.accessor
171
- .slice(0, candidate.accessor.length)
172
- .every((value, index) => value === candidate.accessor[index]),
173
- );
174
- if (neighbor === undefined) break;
175
-
176
- const index: number = neighbor.accessor.length - 1;
177
- route.accessor[index] = `_${route.accessor[index]}`;
301
+ let node = root;
302
+ let neighborIndex = Infinity;
303
+ for (let depth = 0; depth < route.accessor.length - 1; ++depth) {
304
+ const child = node.children.get(route.accessor[depth]!);
305
+ if (child === undefined) break;
306
+ node = child;
307
+ if (!node.terminal.empty())
308
+ neighborIndex = Math.min(neighborIndex, node.terminal.begin().value);
309
+ }
310
+ if (neighborIndex === Infinity) break;
311
+ const conflict = routes[neighborIndex]!.accessor.length - 1;
312
+ route.accessor[conflict] = `_${route.accessor[conflict]}`;
178
313
  }
314
+ terminals[routeIndex]!.terminal.erase(routeIndex);
315
+ insert(route.accessor, routeIndex);
316
+ }
179
317
  return routes;
180
318
  };
181
319
 
@@ -2,9 +2,47 @@ import { IHttpMigrateRoute } from "@typia/interface";
2
2
 
3
3
  import { INestiaMigrateController } from "../structures/INestiaMigrateController";
4
4
  import { MapUtil } from "../utils/MapUtil";
5
+ import { PathTemplate } from "../utils/PathTemplate";
5
6
  import { StringUtil } from "../utils/StringUtil";
6
7
 
8
+ /**
9
+ * Groups the routes of an application into NestJS controllers.
10
+ *
11
+ * Generated controller locations use portable slash spelling and directoryName
12
+ * applies Windows filename constraints on every host: invalid/control
13
+ * characters and trailing dots/spaces become underscores, and device names,
14
+ * including extension and superscript-digit forms, receive a prefix. Router
15
+ * paths retain their original URL meaning. Directory normalization is
16
+ * intentionally many-to-one; distinct controllers retain their own filenames.
17
+ * Host filesystem case policy is not inferred.
18
+ *
19
+ * @evidence contracts/common.md#principled-implementation Routes are grouped by the controller name from the operation, or by the capitalized accessor prefix, and each controller path is the longest path prefix shared by all of its routes, so one controller covers one resource path.
20
+ * @evidence contracts/common.md#clear-and-simple-design One namespace with the grouping and the path formatting, and small private helpers for the shared-prefix computation.
21
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts Names and paths derive from the document, with no route or controller name special-cased.
22
+ * @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
23
+ */
7
24
  export namespace NestiaMigrateControllerAnalyzer {
25
+ /**
26
+ * Returns the controllers of the routes, each with its name, its path, its
27
+ * source location, and its routes.
28
+ *
29
+ * The name is the `x-samchon-controller` extension of the operation when
30
+ * present, and otherwise the capitalized accessor prefix followed by
31
+ * `Controller`.
32
+ *
33
+ * Generated controller locations use portable slash spelling and
34
+ * directoryName applies Windows filename constraints on every host:
35
+ * invalid/control characters and trailing dots/spaces become underscores, and
36
+ * device names, including extension and superscript-digit forms, receive a
37
+ * prefix. Router paths retain their original URL meaning. Directory
38
+ * normalization is intentionally many-to-one; distinct controllers retain
39
+ * their own filenames. Host filesystem case policy is not inferred.
40
+ *
41
+ * @evidence contracts/common.md#principled-implementation Grouping uses a map keyed by controller name, and the common path prefix and the directory prefix are found by removing every segment after the first difference across the routes, so a controller path is a prefix of every route it owns.
42
+ * @evidence contracts/common.md#clear-and-simple-design One function with two phases: grouping, then prefix computation.
43
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The extension name is part of the generated document contract; no other name is assumed.
44
+ * @evidence contracts/common.md#meaningful-documentation The comment states how the name and the path are chosen.
45
+ */
8
46
  export const analyze = (
9
47
  routes: IHttpMigrateRoute[],
10
48
  ): INestiaMigrateController[] => {
@@ -27,9 +65,11 @@ export namespace NestiaMigrateControllerAnalyzer {
27
65
  const controllers: INestiaMigrateController[] = [...collection.values()];
28
66
  for (const col of controllers) {
29
67
  const splitPath = (r: IHttpMigrateRoute): string[] =>
30
- r.emendedPath.split("/");
68
+ routePath(r).split("/");
31
69
  const splitLocation = (r: IHttpMigrateRoute): string[] =>
32
- splitPath(r).filter((s) => s.length !== 0 && s[0] !== ":");
70
+ splitPath(r)
71
+ .filter((s) => s.length !== 0 && s[0] !== ":")
72
+ .map(directoryName);
33
73
 
34
74
  const minPath: string[] = splitPath(col.routes[0]!);
35
75
  const minLocation: string[] = splitLocation(col.routes[0]!);
@@ -42,8 +82,60 @@ export namespace NestiaMigrateControllerAnalyzer {
42
82
  }
43
83
  return controllers;
44
84
  };
85
+
86
+ /**
87
+ * The route's path as NestJS reads it: each path parameter under the key its
88
+ * handler reads with `@TypedParam()`. The document's name, such as `item-id`,
89
+ * is no path-to-regexp parameter name; it would read as `item` followed by
90
+ * the literal `-id`, and the handler's lookup would miss. Each parameter is
91
+ * found where the document's template writes it, beside literal text in its
92
+ * segment too (`/files/{id}.json`).
93
+ *
94
+ * A literal character the router reserves is escaped, so an AIP custom
95
+ * method's `/items:batchGet` stays a literal rather than a parameter
96
+ * `batchGet`, and `(` or `*` no syntax error.
97
+ *
98
+ * This operation emits router protocol spelling and does not select native
99
+ * filenames or filesystem identities.
100
+ *
101
+ * @evidence contracts/common.md#principled-implementation The path template is split into literal and parameter segments, and every character that path-to-regexp treats specially in a literal is escaped with a backslash, so a literal never changes the route's meaning.
102
+ * @evidence contracts/common.md#clear-and-simple-design One expression over the shared path segmenter.
103
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The reserved set is the router's syntax and is applied to every literal.
104
+ * @evidence contracts/common.md#meaningful-documentation The comment states the escaping and the parameter form.
105
+ */
106
+ export const routePath = (route: IHttpMigrateRoute): string =>
107
+ PathTemplate.segments(route)
108
+ .map((segment) =>
109
+ segment.type === "literal"
110
+ ? segment.value.replace(ROUTER_RESERVED, "\\$&")
111
+ : `:${segment.parameter.key}`,
112
+ )
113
+ .join("");
45
114
  }
46
115
 
116
+ /**
117
+ * The characters path-to-regexp 8, Express 5's router, gives a meaning in a
118
+ * route: parameters, wildcards, optional groups, and its own escape.
119
+ */
120
+ const ROUTER_RESERVED = /[\\:*?+!(){}[\]]/g;
121
+
122
+ /**
123
+ * Maps a route segment to a portable directory component. Router escapes are
124
+ * removed, Windows-invalid characters and trailing dots/spaces become
125
+ * underscores, and reserved device names receive an underscore prefix. Distinct
126
+ * route segments may share a directory; controller files retain their
127
+ * independently assigned controller names.
128
+ */
129
+ const directoryName = (segment: string): string => {
130
+ const name: string = segment
131
+ .replace(/\\(.)/g, "$1")
132
+ .replace(/[<>:"|?*\\\u0000-\u001f]/g, "_")
133
+ .replace(/[. ]+$/, (suffix) => "_".repeat(suffix.length));
134
+ return /^(?:CON|PRN|AUX|NUL|COM[1-9¹²³]|LPT[1-9¹²³])(?:\.|$)/i.test(name)
135
+ ? `_${name}`
136
+ : name || "_";
137
+ };
138
+
47
139
  const getSplitIndex = (x: string[], y: string[]) => {
48
140
  const n: number = Math.min(x.length, y.length);
49
141
  for (let i: number = 0; i < n; ++i) if (x[i] !== y[i]) return i;
@@ -1,6 +1,40 @@
1
1
  import { VariadicSingleton } from "tstl";
2
2
 
3
+ /**
4
+ * Writes a file map into a directory through injected file-system functions.
5
+ *
6
+ * Each path is the root, a `/` and the key's `/`-separated segments, a spelling
7
+ * the filesystem calls of every supported platform accept, and creation and
8
+ * writing are delegated to injected functions, so the caller's filesystem
9
+ * decides existence, case policy and permissions. Directories are created one
10
+ * segment at a time because the injected creator is not recursive. Remaining
11
+ * assumptions: keys are trusted generated names, since a `..` or absolute
12
+ * segment would leave the root, and on a case-insensitive volume two keys that
13
+ * differ only in case write to the same file.
14
+ *
15
+ * @evidence contracts/common.md#principled-implementation Directories are created one path prefix at a time, each once, through a memoized creator, and the files are then written in the order of the map; injecting the functions keeps the archiver independent of Node and of the browser.
16
+ * @evidence contracts/common.md#clear-and-simple-design One function with one memoized directory creator.
17
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It writes exactly the given files, and injection is the supported boundary for the platform.
18
+ * @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
19
+ */
3
20
  export namespace NestiaMigrateFileArchiver {
21
+ /**
22
+ * Writes every file of `files` below `root`, creating the directories on the
23
+ * way.
24
+ *
25
+ * A directory that cannot be created is not reported, because the creator is
26
+ * also called for a directory that already exists; the failure surfaces when
27
+ * the file is written.
28
+ *
29
+ * The memo of created directories is keyed by the spelled path, so on a
30
+ * case-insensitive volume a second spelling attempts the creation again and
31
+ * receives the already-exists error, which is the swallowed outcome.
32
+ *
33
+ * @evidence contracts/common.md#principled-implementation The root and each prefix of each file's directory are created once, in order, before the file is written, and a creation failure is deferred to the write that needs the directory, since the injected creator is not recursive and reports an existing directory as an error.
34
+ * @evidence contracts/common.md#clear-and-simple-design One function; the memoized creator makes a repeated directory a no-op.
35
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The dropped creation error is a stated consequence of the non-recursive creator, and the write still fails loudly when the directory is missing.
36
+ * @evidence contracts/common.md#meaningful-documentation The comment states the order of creation and the deferred error.
37
+ */
4
38
  export const archive = async (props: {
5
39
  mkdir: (path: string) => Promise<void>;
6
40
  writeFile: (path: string, content: string) => Promise<void>;
@@ -49,6 +49,6 @@ export const NEST_TEMPLATE: Record<string, string> = {
49
49
  "packages/backend/test/webpack.ts": "import { DynamicExecutor } from \"@nestia/e2e\";\nimport cp from \"node:child_process\";\nimport { sleep_for } from \"tstl\";\n\nimport { MyConfiguration } from \"../src/MyConfiguration\";\nimport { MyGlobal } from \"../src/MyGlobal\";\nimport { TestAutomation } from \"./helpers/TestAutomation\";\nimport { TestAutomationStdio } from \"./helpers/TestAutomationStdio\";\n\nconst wait = async (): Promise<void> => {\n while (true)\n try {\n await fetch(`http://localhost:${MyConfiguration.API_PORT()}/dsafdsafsd`);\n return;\n } catch (exp) {\n await sleep_for(100);\n }\n};\n\nconst main = async (): Promise<void> => {\n MyGlobal.testing = true;\n\n const report: DynamicExecutor.IReport = await TestAutomation.execute({\n open: async () => {\n const backend: cp.ChildProcess = cp.fork(\n `${MyConfiguration.ROOT}/dist/server.js`,\n {\n cwd: `${MyConfiguration.ROOT}/dist`,\n },\n );\n await wait();\n return backend;\n },\n close: async (backend) => {\n backend.kill();\n },\n options: await TestAutomationStdio.getOptions(),\n onComplete: TestAutomationStdio.onComplete,\n });\n TestAutomationStdio.report(report);\n};\nmain().catch((exp: unknown) => {\n console.log(exp);\n process.exit(-1);\n});\n",
50
50
  "packages/backend/tsconfig.json": "{\n \"extends\": \"../../config/tsconfig.json\",\n \"compilerOptions\": {\n \"outDir\": \"lib\",\n \"rootDir\": \"src\",\n \"experimentalDecorators\": true,\n \"emitDecoratorMetadata\": true\n },\n \"include\": [\"src\"]\n}\n",
51
51
  "packages/backend/webpack.config.js": "const path = require(\"path\");\n\nconst CopyWebpackPlugin = require(\"copy-webpack-plugin\");\nconst WriteFilePlugin = require(\"write-file-webpack-plugin\");\nconst { IgnorePlugin } = require(\"webpack\");\n\nconst lazyImports = [\n \"@modelcontextprotocol/sdk\",\n \"@fastify/static\",\n \"@fastify/view\",\n \"@nestjs/microservices\",\n \"@nestjs/websockets\",\n \"class-transformer\",\n \"class-validator\",\n];\n\n// @reference https://tech-blog.s-yoshiki.com/entry/297\nmodule.exports = {\n // CUSTOMIZE HERE\n entry: {\n server: \"./lib/executable/server.js\",\n },\n output: {\n path: path.join(__dirname, \"dist\"),\n filename: \"[name].js\",\n },\n optimization: {\n minimize: true,\n },\n\n // JUST KEEP THEM\n mode: \"production\",\n target: \"node\",\n plugins: [\n new CopyWebpackPlugin({\n patterns: [\n {\n from: \".env\",\n to: \"[name][ext]\",\n },\n ],\n }),\n new WriteFilePlugin(),\n new IgnorePlugin({\n checkResource: (resource) => {\n if (lazyImports.some((modulo) => resource.startsWith(modulo))) {\n try {\n require.resolve(resource);\n } catch (err) {\n return true;\n }\n }\n return false;\n },\n }),\n ],\n};\n",
52
- "pnpm-workspace.yaml": "packages:\n - \"config\"\n - \"packages/*\"\ncatalogs:\n samchon:\n \"@nestia/benchmark\": ^14.0.0\n \"@nestia/core\": ^14.0.0\n \"@nestia/e2e\": ^14.0.0\n \"@nestia/fetcher\": ^14.0.0\n \"@nestia/sdk\": ^14.0.0\n nestia: ^14.0.0\n tgrid: ^1.2.1\n tstl: ^3.0.0\n typia: ^15.0.0\n rolldown:\n rolldown: ^1.1.5\n utils:\n rimraf: ^6.1.3\n uuid: ^13.0.0\n typescript:\n \"@ttsc/lint\": ^0.18.2\n \"@ttsc/paths\": ^0.18.2\n \"@ttsc/unplugin\": ^0.28.1\n ttsc: ^0.28.1\n typescript: ^7.0.2\n",
52
+ "pnpm-workspace.yaml": "packages:\n - \"config\"\n - \"packages/*\"\ncatalogs:\n samchon:\n \"@nestia/benchmark\": ^14.0.2\n \"@nestia/core\": ^14.0.2\n \"@nestia/e2e\": ^14.0.2\n \"@nestia/fetcher\": ^14.0.2\n \"@nestia/sdk\": ^14.0.2\n nestia: ^14.0.2\n tgrid: ^1.2.1\n tstl: ^3.0.0\n typia: 15.0.0\n rolldown:\n rolldown: ^1.1.5\n utils:\n rimraf: ^6.1.3\n uuid: ^13.0.0\n typescript:\n \"@ttsc/lint\": ^0.18.2\n \"@ttsc/paths\": ^0.18.2\n \"@ttsc/unplugin\": ^0.28.1\n ttsc: ^0.28.1\n typescript: ^7.0.2\n",
53
53
  "typos.toml": "[default]\nlocale = 'en-us'\nextend-ignore-re = [\n \"(?Rm)^.*(<!--|#|//)\\\\s*spellchecker:disable-line(-->|\\n)?$\",\n \"(?s)(<!--|#|//)\\\\s*spellchecker:off\\\\s*(-->|\\n).*?(<!--|#|//)\\\\s*spellchecker:on\",\n]\n\n[default.extend-words]\nJeongho = \"Jeongho\"\nNam = \"Nam\"\ntypia = \"typia\"\n\n[files]\nextend-exclude = [\"*.json\"]"
54
54
  }
@@ -5,7 +5,7 @@ export const SDK_TEMPLATE: Record<string, string> = {
5
5
  "LICENSE": "MIT License\n\nCopyright (c) 2024 Jeongho Nam\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
6
6
  "README.md": "# Software Development Kit\nThis is a SDK library generated by [`@nestia/migrate`](https://nestia.io/docs/migrate) or [`@nestia/editor`](https://nestia.io/docs/editor).\n\nWith this SDK library, you can easily and safely interact with backend server.\n\nJust import and call some API functions like gif image below:\n\n![nestia-sdk-demo](https://user-images.githubusercontent.com/13158709/215004990-368c589d-7101-404e-b81b-fbc936382f05.gif)\n\n> Left is server code, and right is client code utilizing the SDK\n\n\n\n\n## How to Test\n```bash\npnpm install\npnpm run start # run only \"test/start.ts\" file\npnpm run test # everything under the \"test/features\" directory\npnpm run test:simulate # \"test/features\" with mockup simulation mode\n```\n\nIf you run `pnpm run start` command, only [test/start.ts](test/start.ts) file would be executed.\n\nOtherwise you run `pnpm run test` command instead, run everything in the [test/features](test/features) directory.\n\nFor reference, the [test/features](test/features) directory and E2E test functions (for each API endpoints) would be automatically composed only when you've configured the \"E2E test function generation mode\" of the `@nestia/migrate` (or `@nestia/editor`).\n\n```bash\npnpm dlx @nestia/migrate\n? Migration mode (Use arrow keys):\n NestJS\n > SDK\n? Swagger file location: assets/input/clickhouse.json\n? Output directory path: assets/output/clickhouse-sdk-manual\n? Mokup Simulator: true\n? E2E Test Functions: true\n```\n\n\n\n\n## Deploy\n```bash\npnpm install\npnpm run deploy\n```\n\nJust run `pnpm run deploy` command, then your SDK library would be published.\n\nBy the way, the initial package name of this template repository is `@ORGANIZATION/PROJECT-api`. I think it would better to change the word to your own organization and project name. If you're utilizing `VsCode`, you can do it through `Edit > Replace in Files` (*Ctrl + Shift + H*) feature.\n\n-----------\n\n> ## What [`Nestia`](https://nestia.io) is:\n> ![Nestia Logo](https://nestia.io/logo.png)\n> \n> [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/samchon/nestia/blob/master/LICENSE)\n> [![npm version](https://img.shields.io/npm/v/@nestia/core.svg)](https://www.npmjs.com/package/@nestia/core)\n> [![Downloads](https://img.shields.io/npm/dm/@nestia/core.svg)](https://www.npmjs.com/package/@nestia/core)\n> [![Build Status](https://github.com/samchon/nestia/workflows/build/badge.svg)](https://github.com/samchon/nestia/actions?query=workflow%3Abuild)\n> [![Guide Documents](https://img.shields.io/badge/guide-documents-forestgreen)](https://nestia.io/docs/)\n> \n> Nestia is a set of helper libraries for NestJS, supporting below features:\n> \n> - `@nestia/core`: Super-fast decorators\n> - `@nestia/sdk`:\n> - Swagger generator evolved than ever\n> - SDK library generator for clients\n> - Mockup Simulator for client applications\n> - Automatic E2E test functions generator\n> - `@nestia/migrate`: Migration from Swagger to NestJS\n> - `@nestia/editor`: Online TypeScript Swagger Editor\n> - `nestia`: Just CLI (command line interface) tool\n> \n>> **Note**\n>> \n>> - **Only one line** required, with pure TypeScript type\n>> - Enhance performance **30x** up\n>> - Runtime validator is **20,000x faster** than `class-validator`\n>> - JSON serialization is **200x faster** than `class-transformer`\n>> - Software Development Kit\n>> - SDK is a collection of `fetch` functions with type definitions like [tRPC](https://> trpc.io/)\n>> - Mockup simulator means embedded backend simulator in SDK\n>> - similar with [msw](https://mswjs.io/), but fully automated\n",
7
7
  "hello.js": "function print(command, description) {\n return console.log(`\\x1b[1m${command}\\x1b[2m: ${description}\\x1b[0m`);\n}\n\nconsole.log(\"-----------------------------------------\");\nconsole.log(\"\\x1b[7mGenerated by \\x1b[2m@nestia/editor\\x1b[0m\");\nconsole.log(\"\");\nconsole.log(\" - \\x1b[36mhttps://nestia.io/docs/editor\\x1b[0m\");\nconsole.log(\" - \\x1b[36mhttps://github.com/samchon/nestia\\x1b[0m\");\nconsole.log(\"-----------------------------------------\");\n\nprint(\"pnpm run start\", \"Run only test/start.ts\");\nprint(\"pnpm run test\", \"Run every test/features/**/*.ts files\");\nprint(\"pnpm run test:simulate\", \"Test with mockup simulator\");\n",
8
- "package.json": "{\n \"name\": \"@ORGANIZATION/PROJECT-api\",\n \"version\": \"0.1.0\",\n \"description\": \"SDK library generated by Nestia\",\n \"main\": \"src/index.ts\",\n \"exports\": {\n \".\": \"./src/index.ts\",\n \"./lib/*\": \"./src/*.ts\",\n \"./package.json\": \"./package.json\"\n },\n \"publishConfig\": {\n \"main\": \"lib/index.mjs\",\n \"module\": \"lib/index.mjs\",\n \"types\": \"lib/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./lib/index.d.ts\",\n \"import\": \"./lib/index.mjs\",\n \"default\": \"./lib/index.js\"\n },\n \"./lib/*\": {\n \"types\": \"./lib/*.d.ts\",\n \"import\": \"./lib/*.mjs\",\n \"default\": \"./lib/*.js\"\n },\n \"./package.json\": \"./package.json\"\n }\n },\n \"scripts\": {\n \"build\": \"rimraf lib && ttsc && rolldown -c\",\n \"build:test\": \"rimraf bin && ttsc --project test/tsconfig.json\",\n \"deploy\": \"pnpm run build && pnpm publish\",\n \"dev\": \"pnpm run build:test --watch\",\n \"hello\": \"node hello\",\n \"start\": \"ttsx test/start.ts\",\n \"swagger\": \"ttsx test/swagger.ts\",\n \"test\": \"ttsx test/index.ts\",\n \"test:simulate\": \"ttsx test/index.ts --simulate true\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/samchon/nestia\"\n },\n \"author\": \"Jeongho Nam\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/samchon/nestia/issues\"\n },\n \"homepage\": \"https://nestia.io\",\n \"files\": [\n \"lib\",\n \"swagger.json\",\n \"package.json\",\n \"README.md\"\n ],\n \"dependencies\": {\n \"@nestia/fetcher\": \"^14.0.0\",\n \"tgrid\": \"^1.2.1\",\n \"typia\": \"^15.0.0\"\n },\n \"devDependencies\": {\n \"@nestia/e2e\": \"^14.0.0\",\n \"@ttsc/unplugin\": \"^0.28.1\",\n \"@types/express\": \"^4.17.21\",\n \"@types/swagger-ui-express\": \"^4.1.6\",\n \"chalk\": \"4.1.2\",\n \"express\": \"^4.19.2\",\n \"rimraf\": \"^5.0.5\",\n \"rolldown\": \"^1.1.5\",\n \"swagger-ui-express\": \"^5.0.0\",\n \"tinyglobby\": \"^0.2.17\",\n \"ttsc\": \"^0.28.1\",\n \"typescript\": \"^7.0.2\",\n \"@nestia/core\": \"^14.0.0\"\n },\n \"packageManager\": \"pnpm@10.19.0\"\n}",
8
+ "package.json": "{\n \"name\": \"@ORGANIZATION/PROJECT-api\",\n \"version\": \"0.1.0\",\n \"description\": \"SDK library generated by Nestia\",\n \"main\": \"src/index.ts\",\n \"exports\": {\n \".\": \"./src/index.ts\",\n \"./lib/*\": \"./src/*.ts\",\n \"./package.json\": \"./package.json\"\n },\n \"publishConfig\": {\n \"main\": \"lib/index.mjs\",\n \"module\": \"lib/index.mjs\",\n \"types\": \"lib/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./lib/index.d.ts\",\n \"import\": \"./lib/index.mjs\",\n \"default\": \"./lib/index.js\"\n },\n \"./lib/*\": {\n \"types\": \"./lib/*.d.ts\",\n \"import\": \"./lib/*.mjs\",\n \"default\": \"./lib/*.js\"\n },\n \"./package.json\": \"./package.json\"\n }\n },\n \"scripts\": {\n \"build\": \"rimraf lib && ttsc && rolldown -c\",\n \"build:test\": \"rimraf bin && ttsc --project test/tsconfig.json\",\n \"deploy\": \"pnpm run build && pnpm publish\",\n \"dev\": \"pnpm run build:test --watch\",\n \"hello\": \"node hello\",\n \"start\": \"ttsx test/start.ts\",\n \"swagger\": \"ttsx test/swagger.ts\",\n \"test\": \"ttsx test/index.ts\",\n \"test:simulate\": \"ttsx test/index.ts --simulate true\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/samchon/nestia\"\n },\n \"author\": \"Jeongho Nam\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/samchon/nestia/issues\"\n },\n \"homepage\": \"https://nestia.io\",\n \"files\": [\n \"lib\",\n \"swagger.json\",\n \"package.json\",\n \"README.md\"\n ],\n \"dependencies\": {\n \"@nestia/fetcher\": \"^14.0.2\",\n \"tgrid\": \"^1.2.1\",\n \"typia\": \"15.0.0\"\n },\n \"devDependencies\": {\n \"@nestia/e2e\": \"^14.0.2\",\n \"@ttsc/unplugin\": \"^0.28.1\",\n \"@types/express\": \"^4.17.21\",\n \"@types/swagger-ui-express\": \"^4.1.6\",\n \"chalk\": \"4.1.2\",\n \"express\": \"^4.19.2\",\n \"rimraf\": \"^5.0.5\",\n \"rolldown\": \"^1.1.5\",\n \"swagger-ui-express\": \"^5.0.0\",\n \"tinyglobby\": \"^0.2.17\",\n \"ttsc\": \"^0.28.1\",\n \"typescript\": \"^7.0.2\",\n \"@nestia/core\": \"^14.0.2\"\n },\n \"packageManager\": \"pnpm@10.19.0\"\n}",
9
9
  "rolldown.config.mjs": "import ttsc from \"@ttsc/unplugin/rolldown\";\nimport path from \"node:path\";\nimport { globSync } from \"tinyglobby\";\n\nexport default {\n input: globSync(\"./src/**/*.ts\"),\n external: (id) => !id.startsWith(\".\") && !path.isAbsolute(id),\n output: {\n dir: \"./lib\",\n format: \"esm\",\n sourcemap: true,\n entryFileNames: \"[name].mjs\",\n preserveModules: true,\n preserveModulesRoot: \"src\",\n },\n plugins: [ttsc()],\n};\n",
10
10
  "src/HttpError.ts": "export { HttpError } from \"@nestia/fetcher\";\n",
11
11
  "src/IConnection.ts": "export type { IConnection } from \"@nestia/fetcher\";\n",
@@ -15,7 +15,43 @@ import { NestiaMigrateApplication } from "../NestiaMigrateApplication";
15
15
  import { NestiaMigrateFileArchiver } from "../archivers/NestiaMigrateFileArchiver";
16
16
  import { NestiaMigrateInquirer } from "./NestiaMigrateInquirer";
17
17
 
18
+ /**
19
+ * The command-line entry of `@nestia/migrate`.
20
+ *
21
+ * The output path is resolved with `path.resolve` and its parent tested with
22
+ * `existsSync` and `statSync`, with backslashes converted to `/`, which Windows
23
+ * accepts. The input is fetched when it parses as an http or https URL, so a
24
+ * Windows path whose drive letter parses as a scheme is read from disk, and it
25
+ * is read as UTF-8 otherwise. Only files with a `.ts`, `.cts`, `.mts` or `.tsx`
26
+ * extension, tested case-sensitively, are formatted, and text is written
27
+ * without a byte order mark and with the line endings the generator and
28
+ * Prettier produce, which are not the platform's. A failure ends the process
29
+ * through `process.exit(-1)`, whose status the platform truncates to a non-zero
30
+ * value.
31
+ *
32
+ * @evidence contracts/common.md#principled-implementation The command reads the options, validates the output directory, reads the document from a file or an http(s) URL, converts it, reports the operations that could not be migrated, and writes the files, formatting only TypeScript files.
33
+ * @evidence contracts/common.md#clear-and-simple-design One entry function, with formatting, halting, and URL detection as private helpers.
34
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts Every failure ends with a message and a non-zero exit, and unformattable content is written unformatted.
35
+ * @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
36
+ */
18
37
  export namespace NestiaMigrateCommander {
38
+ /**
39
+ * Runs the command: reads the options and the document, generates the
40
+ * project, and writes it to the output directory.
41
+ *
42
+ * It stops with an error when the output directory exists, when its parent
43
+ * does not exist or is not a directory, when the input cannot be read or
44
+ * fetched, or when the document is invalid.
45
+ *
46
+ * Creation and writing use `fs.promises` through the injected archiver, so
47
+ * the volume decides case policy and permissions, and the checks that precede
48
+ * any write are the filesystem's own answers.
49
+ *
50
+ * @evidence contracts/common.md#principled-implementation The checks run before any file is written, the document is fetched only for an http or https URL, a failed HTTP status stops the command, and only files with a TypeScript extension are formatted, because Prettier's TypeScript parser would rewrite a dotfile line into code.
51
+ * @evidence contracts/common.md#clear-and-simple-design One asynchronous function whose phases are marked in comments, with the option parsing in `NestiaMigrateInquirer`.
52
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The checks apply to every input, and a formatting failure keeps the original text.
53
+ * @evidence contracts/common.md#meaningful-documentation The comment states the conditions under which it stops.
54
+ */
19
55
  export const main = async (): Promise<void> => {
20
56
  const resolve = (str: string | undefined) =>
21
57
  str ? path.resolve(str).split("\\").join("/") : undefined;
@@ -39,6 +75,10 @@ export namespace NestiaMigrateCommander {
39
75
  | OpenApiV3_2.IDocument = await (async () => {
40
76
  if (isUri(options.input)) {
41
77
  const response: Response = await fetch(options.input);
78
+ if (response.ok === false)
79
+ halt(
80
+ `Unable to fetch the input swagger.json: ${response.status} ${response.statusText}`,
81
+ );
42
82
  const content: string = await response.text();
43
83
  return JSON.parse(content);
44
84
  }
@@ -76,8 +116,14 @@ export namespace NestiaMigrateCommander {
76
116
  );
77
117
  await NestiaMigrateFileArchiver.archive({
78
118
  mkdir: fs.promises.mkdir,
119
+ // only TypeScript is formatted: prettier's TypeScript parser also
120
+ // accepts a `.gitignore` or `.env` line, and rewrites it into code
79
121
  writeFile: async (file, content) =>
80
- fs.promises.writeFile(file, await beautify(content), "utf-8"),
122
+ fs.promises.writeFile(
123
+ file,
124
+ /\.[cm]?tsx?$/.test(file) ? await beautify(content) : content,
125
+ "utf-8",
126
+ ),
81
127
  root: options.output,
82
128
  files,
83
129
  });
@@ -1,7 +1,25 @@
1
1
  import { program } from "commander";
2
2
  import { createPromptModule } from "inquirer";
3
3
 
4
+ /**
5
+ * Reads the options of the command from flags, asking interactively for what is
6
+ * missing.
7
+ *
8
+ * @evidence contracts/common.md#principled-implementation Each option is taken from its flag when given, and asked with a prompt otherwise, so the same command runs non-interactively when every flag is present.
9
+ * @evidence contracts/common.md#clear-and-simple-design One function and the output type; the prompt helpers are local.
10
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The prompts are the standard `inquirer` ones, and a flag always wins over a prompt.
11
+ * @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
12
+ */
4
13
  export namespace NestiaMigrateInquirer {
14
+ /**
15
+ * The options of the command: the mode, the input and output locations, the
16
+ * flags, and the package name.
17
+ *
18
+ * @evidence contracts/common.md#principled-implementation The record holds the answers needed to run the migration, each as a value and not as an optional.
19
+ * @evidence contracts/common.md#clear-and-simple-design A flat record.
20
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
21
+ * @evidence contracts/common.md#meaningful-documentation The comment lists the options.
22
+ */
5
23
  export interface IOutput {
6
24
  mode: "nest" | "sdk";
7
25
  input: string;
@@ -12,6 +30,17 @@ export namespace NestiaMigrateInquirer {
12
30
  package: string;
13
31
  }
14
32
 
33
+ /**
34
+ * Parses the flags and asks for the missing options.
35
+ *
36
+ * A boolean flag given without a value is `true`, and one given a value is
37
+ * true only for the text `true`.
38
+ *
39
+ * @evidence contracts/common.md#principled-implementation Commander parses the flags, the action asks a prompt for each undefined option, and boolean flags are normalized by one rule, so the result has every field set.
40
+ * @evidence contracts/common.md#clear-and-simple-design One function that wires the parser and the prompts around one action.
41
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It asks only for what is missing.
42
+ * @evidence contracts/common.md#meaningful-documentation The comment states the boolean flag rule.
43
+ */
15
44
  export const parse = async (): Promise<IOutput> => {
16
45
  // PREPARE ASSETS
17
46
  program.option("--mode [nest/sdk]", "migration mode");
@@ -74,32 +103,18 @@ export namespace NestiaMigrateInquirer {
74
103
  partial.input ??= await input("input")("Swagger file location");
75
104
  partial.output ??= await input("output")("Response directory path");
76
105
  partial.package ??= await input("package")("Package name");
77
- partial.keyword ??=
78
- (await select("keyword")("Keyword parameter mode")([
79
- "true",
80
- "false",
81
- ])) === "true";
82
-
83
- if (partial.keyword)
84
- partial.keyword = (partial.keyword as any) === "true";
85
- else
86
- partial.keyword =
87
- (await select("keyword")("Keyword parameter mode")([
88
- "true",
89
- "false",
90
- ])) === "true";
91
- if (partial.simulate)
92
- partial.simulate = (partial.simulate as any) === "true";
93
- else
94
- partial.simulate =
95
- (await select("simulate")("Mokup Simulator")(["true", "false"])) ===
96
- "true";
97
-
98
- if (partial.e2e) partial.e2e = (partial.e2e as any) === "true";
99
- else
100
- partial.e2e =
101
- (await select("e2e")("Generate E2E tests")(["true", "false"])) ===
102
- "true";
106
+ // a flag given alone is `true`, and one given a value is its text
107
+ const flag = (value: unknown): boolean | undefined =>
108
+ value === undefined ? undefined : value === true || value === "true";
109
+ const ask = async (name: string, message: string): Promise<boolean> =>
110
+ (await select(name)(message)(["true", "false"])) === "true";
111
+ partial.keyword =
112
+ flag(partial.keyword) ??
113
+ (await ask("keyword", "Keyword parameter mode"));
114
+ partial.simulate =
115
+ flag(partial.simulate) ?? (await ask("simulate", "Mokup Simulator"));
116
+ partial.e2e =
117
+ flag(partial.e2e) ?? (await ask("e2e", "Generate E2E tests"));
103
118
  return partial as IOutput;
104
119
  });
105
120
  };