@nestia/sdk 6.0.6 → 7.0.0-dev.20250605

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 (137) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +92 -92
  3. package/assets/bundle/api/HttpError.ts +1 -1
  4. package/assets/bundle/api/IConnection.ts +1 -1
  5. package/assets/bundle/api/Primitive.ts +1 -1
  6. package/assets/bundle/api/Resolved.ts +1 -1
  7. package/assets/bundle/api/index.ts +4 -4
  8. package/assets/bundle/api/module.ts +6 -6
  9. package/assets/bundle/distribute/README.md +37 -37
  10. package/assets/bundle/distribute/package.json +28 -28
  11. package/assets/bundle/distribute/tsconfig.json +109 -109
  12. package/assets/bundle/e2e/index.ts +42 -42
  13. package/assets/config/nestia.config.ts +97 -97
  14. package/lib/INestiaConfig.d.ts +66 -69
  15. package/lib/executable/internal/NestiaConfigLoader.js +10 -5
  16. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  17. package/lib/executable/sdk.js +12 -12
  18. package/lib/generates/internal/E2eFileProgrammer.js +30 -14
  19. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  20. package/lib/generates/internal/ImportDictionary.js +13 -4
  21. package/lib/generates/internal/ImportDictionary.js.map +1 -1
  22. package/lib/generates/internal/SdkAliasCollection.d.ts +3 -2
  23. package/lib/generates/internal/SdkAliasCollection.js +8 -3
  24. package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
  25. package/lib/generates/internal/SdkHttpFunctionProgrammer.d.ts +1 -1
  26. package/lib/generates/internal/SdkHttpFunctionProgrammer.js +47 -35
  27. package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
  28. package/lib/generates/internal/SdkHttpNamespaceProgrammer.d.ts +1 -1
  29. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +50 -37
  30. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
  31. package/lib/generates/internal/SdkHttpRouteProgrammer.js +5 -4
  32. package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
  33. package/lib/generates/internal/SdkHttpSimulationProgrammer.d.ts +1 -1
  34. package/lib/generates/internal/SdkHttpSimulationProgrammer.js +28 -16
  35. package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
  36. package/lib/generates/internal/SdkTypeProgrammer.js +3 -3
  37. package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
  38. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +1 -1
  39. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
  40. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +1 -1
  41. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
  42. package/lib/utils/ArrayUtil.d.ts +2 -2
  43. package/lib/utils/ArrayUtil.js.map +1 -1
  44. package/package.json +6 -6
  45. package/src/INestiaConfig.ts +269 -271
  46. package/src/NestiaSdkApplication.ts +307 -307
  47. package/src/NestiaSwaggerComposer.ts +138 -138
  48. package/src/analyses/AccessorAnalyzer.ts +67 -67
  49. package/src/analyses/ConfigAnalyzer.ts +155 -155
  50. package/src/analyses/ExceptionAnalyzer.ts +154 -154
  51. package/src/analyses/GenericAnalyzer.ts +49 -49
  52. package/src/analyses/ImportAnalyzer.ts +171 -171
  53. package/src/analyses/PathAnalyzer.ts +69 -69
  54. package/src/analyses/ReflectControllerAnalyzer.ts +105 -105
  55. package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
  56. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +71 -71
  57. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +348 -348
  58. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +127 -127
  59. package/src/analyses/ReflectMetadataAnalyzer.ts +44 -44
  60. package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +172 -172
  61. package/src/analyses/SecurityAnalyzer.ts +25 -25
  62. package/src/analyses/TypedHttpRouteAnalyzer.ts +186 -186
  63. package/src/analyses/TypedWebSocketRouteAnalyzer.ts +18 -18
  64. package/src/decorators/OperationMetadata.ts +15 -15
  65. package/src/executable/internal/CommandParser.ts +15 -15
  66. package/src/executable/internal/NestiaConfigLoader.ts +78 -78
  67. package/src/executable/internal/NestiaSdkCommand.ts +103 -103
  68. package/src/executable/sdk.ts +75 -75
  69. package/src/generates/CloneGenerator.ts +66 -66
  70. package/src/generates/E2eGenerator.ts +32 -32
  71. package/src/generates/SdkGenerator.ts +159 -159
  72. package/src/generates/SwaggerGenerator.ts +292 -292
  73. package/src/generates/internal/E2eFileProgrammer.ts +214 -183
  74. package/src/generates/internal/FilePrinter.ts +53 -53
  75. package/src/generates/internal/ImportDictionary.ts +159 -147
  76. package/src/generates/internal/SdkAliasCollection.ts +204 -185
  77. package/src/generates/internal/SdkDistributionComposer.ts +103 -103
  78. package/src/generates/internal/SdkFileProgrammer.ts +116 -116
  79. package/src/generates/internal/SdkHttpCloneProgrammer.ts +124 -124
  80. package/src/generates/internal/SdkHttpCloneReferencer.ts +71 -71
  81. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +325 -301
  82. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +563 -529
  83. package/src/generates/internal/SdkHttpRouteProgrammer.ts +119 -117
  84. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +386 -362
  85. package/src/generates/internal/SdkImportWizard.ts +55 -55
  86. package/src/generates/internal/SdkRouteDirectory.ts +18 -18
  87. package/src/generates/internal/SdkTypeProgrammer.ts +377 -377
  88. package/src/generates/internal/SdkTypeTagProgrammer.ts +102 -102
  89. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +362 -362
  90. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +265 -265
  91. package/src/generates/internal/SwaggerDescriptionComposer.ts +64 -64
  92. package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
  93. package/src/generates/internal/SwaggerOperationParameterComposer.ts +177 -177
  94. package/src/generates/internal/SwaggerOperationResponseComposer.ts +110 -110
  95. package/src/index.ts +4 -4
  96. package/src/module.ts +3 -3
  97. package/src/structures/INestiaProject.ts +13 -13
  98. package/src/structures/INestiaSdkInput.ts +20 -20
  99. package/src/structures/IReflectApplication.ts +8 -8
  100. package/src/structures/IReflectController.ts +15 -15
  101. package/src/structures/IReflectHttpOperation.ts +26 -26
  102. package/src/structures/IReflectHttpOperationException.ts +19 -19
  103. package/src/structures/IReflectHttpOperationParameter.ts +81 -81
  104. package/src/structures/IReflectHttpOperationSuccess.ts +22 -22
  105. package/src/structures/IReflectOperationError.ts +26 -26
  106. package/src/structures/IReflectType.ts +4 -4
  107. package/src/structures/IReflectTypeImport.ts +4 -4
  108. package/src/structures/IReflectWebSocketOperation.ts +17 -17
  109. package/src/structures/IReflectWebSocketOperationParameter.ts +38 -38
  110. package/src/structures/ITypedApplication.ts +11 -11
  111. package/src/structures/ITypedHttpRoute.ts +30 -30
  112. package/src/structures/ITypedHttpRouteException.ts +15 -15
  113. package/src/structures/ITypedHttpRouteParameter.ts +41 -41
  114. package/src/structures/ITypedHttpRouteSuccess.ts +22 -22
  115. package/src/structures/ITypedWebSocketRoute.ts +20 -20
  116. package/src/structures/ITypedWebSocketRouteParameter.ts +3 -3
  117. package/src/structures/MethodType.ts +5 -5
  118. package/src/structures/ParamCategory.ts +1 -1
  119. package/src/structures/TypeEntry.ts +22 -22
  120. package/src/transform.ts +9 -9
  121. package/src/transformers/IOperationMetadata.ts +44 -44
  122. package/src/transformers/ISdkOperationTransformerContext.ts +8 -8
  123. package/src/transformers/SdkOperationProgrammer.ts +209 -209
  124. package/src/transformers/SdkOperationTransformer.ts +253 -253
  125. package/src/transformers/TextPlainValidator.ts +17 -17
  126. package/src/typings/get-function-location.d.ts +7 -7
  127. package/src/utils/ArrayUtil.ts +26 -26
  128. package/src/utils/FileRetriever.ts +22 -22
  129. package/src/utils/MapUtil.ts +14 -14
  130. package/src/utils/MetadataUtil.ts +26 -26
  131. package/src/utils/PathUtil.ts +10 -10
  132. package/src/utils/SourceFinder.ts +66 -66
  133. package/src/utils/StringUtil.ts +17 -17
  134. package/src/utils/StripEnums.ts +5 -5
  135. package/src/utils/VersioningStrategy.ts +28 -28
  136. package/src/validators/HttpHeadersValidator.ts +34 -34
  137. package/src/validators/HttpQueryValidator.ts +34 -34
@@ -1,147 +1,159 @@
1
- import path from "path";
2
- import { HashMap, HashSet, Pair } from "tstl";
3
- import ts from "typescript";
4
-
5
- import { FilePrinter } from "./FilePrinter";
6
-
7
- export class ImportDictionary {
8
- private readonly components_: HashMap<Pair<string, boolean>, IComposition> =
9
- new HashMap();
10
-
11
- public constructor(public readonly file: string) {}
12
-
13
- public empty(): boolean {
14
- return this.components_.empty();
15
- }
16
-
17
- public external(props: ImportDictionary.IExternalProps): string {
18
- const composition: IComposition = this.components_.take(
19
- new Pair(`node_modules/${props.library}`, props.type),
20
- () => ({
21
- location: `node_modules/${props.library}`,
22
- elements: new HashSet(),
23
- default: false,
24
- type: props.type,
25
- }),
26
- );
27
- if (props.instance === null) composition.default = true;
28
- else composition.elements.insert(props.instance);
29
- return props.instance ?? props.library;
30
- }
31
-
32
- public internal(props: ImportDictionary.IInternalProps): string {
33
- const file: string = (() => {
34
- if (props.file.substring(props.file.length - 5) === ".d.ts")
35
- return props.file.substring(0, props.file.length - 5);
36
- else if (props.file.substring(props.file.length - 3) === ".ts")
37
- return props.file.substring(0, props.file.length - 3);
38
- return props.file;
39
- })();
40
- const composition: IComposition = this.components_.take(
41
- new Pair(file, props.type),
42
- () => ({
43
- location: file,
44
- elements: new HashSet(),
45
- default: false,
46
- type: props.type,
47
- }),
48
- );
49
- if (props.instance === null) {
50
- composition.default = true;
51
- if (props.name) composition.name = props.name;
52
- } else composition.elements.insert(props.instance);
53
- return props.instance ?? file;
54
- }
55
-
56
- public toStatements(outDir: string): ts.Statement[] {
57
- const external: ts.ImportDeclaration[] = [];
58
- const internal: ts.ImportDeclaration[] = [];
59
-
60
- const locator = (str: string) => {
61
- const location: string = path.relative(outDir, str).split("\\").join("/");
62
- const index: number = location.lastIndexOf(NODE_MODULES);
63
- return index === -1
64
- ? location.startsWith("..")
65
- ? location
66
- : `./${location}`
67
- : location.substring(index + NODE_MODULES.length);
68
- };
69
- const enroll =
70
- (filter: (str: string) => boolean) =>
71
- (container: ts.ImportDeclaration[]) => {
72
- const compositions: IComposition[] = this.components_
73
- .toJSON()
74
- .filter((c) => filter(c.second.location))
75
- .map((e) => ({
76
- ...e.second,
77
- location: locator(e.second.location),
78
- }))
79
- .sort((a, b) => a.location.localeCompare(b.location));
80
- for (const c of compositions) {
81
- const brackets: string[] = [];
82
- if (c.default) brackets.push(c.name ?? c.location);
83
- if (c.elements.empty() === false)
84
- brackets.push(
85
- `{ ${c.elements
86
- .toJSON()
87
- .sort((a, b) => a.localeCompare(b))
88
- .join(", ")} }`,
89
- );
90
- container.push(
91
- ts.factory.createImportDeclaration(
92
- undefined,
93
- ts.factory.createImportClause(
94
- c.type,
95
- c.default
96
- ? ts.factory.createIdentifier(c.name ?? c.location)
97
- : undefined,
98
- c.elements.empty() === false
99
- ? ts.factory.createNamedImports(
100
- [...c.elements].map((elem) =>
101
- ts.factory.createImportSpecifier(
102
- false,
103
- undefined,
104
- ts.factory.createIdentifier(elem),
105
- ),
106
- ),
107
- )
108
- : undefined,
109
- ),
110
- ts.factory.createStringLiteral(c.location),
111
- ),
112
- );
113
- }
114
- };
115
-
116
- enroll((str) => str.indexOf(NODE_MODULES) !== -1)(external);
117
- enroll((str) => str.indexOf(NODE_MODULES) === -1)(internal);
118
- return [
119
- ...external,
120
- ...(external.length && internal.length ? [FilePrinter.enter()] : []),
121
- ...internal,
122
- ];
123
- }
124
- }
125
- export namespace ImportDictionary {
126
- export interface IExternalProps {
127
- type: boolean;
128
- library: string;
129
- instance: string | null;
130
- }
131
- export interface IInternalProps {
132
- type: boolean;
133
- file: string;
134
- instance: string | null;
135
- name?: string | null;
136
- }
137
- }
138
-
139
- interface IComposition {
140
- location: string;
141
- type: boolean;
142
- default: boolean;
143
- name?: string;
144
- elements: HashSet<string>;
145
- }
146
-
147
- const NODE_MODULES = "node_modules/";
1
+ import path from "path";
2
+ import { HashMap, HashSet, Pair } from "tstl";
3
+ import ts from "typescript";
4
+
5
+ import { FilePrinter } from "./FilePrinter";
6
+
7
+ export class ImportDictionary {
8
+ private readonly components_: HashMap<Pair<string, boolean>, IComposition> =
9
+ new HashMap();
10
+
11
+ public constructor(public readonly file: string) {}
12
+
13
+ public empty(): boolean {
14
+ return this.components_.empty();
15
+ }
16
+
17
+ public external(props: ImportDictionary.IExternalProps): string {
18
+ const key: string = `node_modules/${props.library}`;
19
+ const composition: IComposition = this.components_.take(
20
+ new Pair(key, props.type),
21
+ () => ({
22
+ location: key,
23
+ elements: new HashSet(),
24
+ default: false,
25
+ type: props.type,
26
+ }),
27
+ );
28
+ if (props.instance === null) composition.default = true;
29
+ else composition.elements.insert(props.instance);
30
+ return props.instance ?? props.library;
31
+ }
32
+
33
+ public internal(props: ImportDictionary.IInternalProps): string {
34
+ const file: string = normalize(
35
+ (() => {
36
+ if (props.file.substring(props.file.length - 5) === ".d.ts")
37
+ return props.file.substring(0, props.file.length - 5);
38
+ else if (props.file.substring(props.file.length - 3) === ".ts")
39
+ return props.file.substring(0, props.file.length - 3);
40
+ return props.file;
41
+ })(),
42
+ );
43
+ const composition: IComposition = this.components_.take(
44
+ new Pair(file, props.type),
45
+ () => ({
46
+ location: file,
47
+ elements: new HashSet(),
48
+ default: false,
49
+ type: props.type,
50
+ }),
51
+ );
52
+ if (props.instance === null) {
53
+ composition.default = true;
54
+ if (props.name) composition.name = props.name;
55
+ } else composition.elements.insert(props.instance);
56
+ return props.instance ?? file;
57
+ }
58
+
59
+ public toStatements(outDir: string): ts.Statement[] {
60
+ const external: ts.ImportDeclaration[] = [];
61
+ const internal: ts.ImportDeclaration[] = [];
62
+
63
+ const locator = (str: string) => {
64
+ const location: string = path.relative(outDir, str).split("\\").join("/");
65
+ const index: number = location.lastIndexOf(NODE_MODULES);
66
+ return index === -1
67
+ ? location.startsWith("..")
68
+ ? location
69
+ : `./${location}`
70
+ : location.substring(index + NODE_MODULES.length);
71
+ };
72
+ const enroll =
73
+ (filter: (str: string) => boolean) =>
74
+ (container: ts.ImportDeclaration[]) => {
75
+ const compositions: IComposition[] = this.components_
76
+ .toJSON()
77
+ .filter((c) => filter(c.second.location))
78
+ .map((e) => ({
79
+ ...e.second,
80
+ location: locator(e.second.location),
81
+ }))
82
+ .sort((a, b) => a.location.localeCompare(b.location));
83
+ for (const c of compositions) {
84
+ const brackets: string[] = [];
85
+ if (c.default) brackets.push(c.name ?? c.location);
86
+ if (c.elements.empty() === false)
87
+ brackets.push(
88
+ `{ ${c.elements
89
+ .toJSON()
90
+ .sort((a, b) => a.localeCompare(b))
91
+ .join(", ")} }`,
92
+ );
93
+ container.push(
94
+ ts.factory.createImportDeclaration(
95
+ undefined,
96
+ ts.factory.createImportClause(
97
+ c.type,
98
+ c.default
99
+ ? ts.factory.createIdentifier(c.name ?? c.location)
100
+ : undefined,
101
+ c.elements.empty() === false
102
+ ? ts.factory.createNamedImports(
103
+ [...c.elements].map((elem) =>
104
+ ts.factory.createImportSpecifier(
105
+ false,
106
+ undefined,
107
+ ts.factory.createIdentifier(elem),
108
+ ),
109
+ ),
110
+ )
111
+ : undefined,
112
+ ),
113
+ ts.factory.createStringLiteral(c.location),
114
+ ),
115
+ );
116
+ }
117
+ };
118
+
119
+ enroll((str) => str.indexOf(NODE_MODULES) !== -1)(external);
120
+ enroll((str) => str.indexOf(NODE_MODULES) === -1)(internal);
121
+ return [
122
+ ...external,
123
+ ...(external.length && internal.length ? [FilePrinter.enter()] : []),
124
+ ...internal,
125
+ ];
126
+ }
127
+ }
128
+ export namespace ImportDictionary {
129
+ export interface IExternalProps {
130
+ type: boolean;
131
+ library: string;
132
+ instance: string | null;
133
+ }
134
+ export interface IInternalProps {
135
+ type: boolean;
136
+ file: string;
137
+ instance: string | null;
138
+ name?: string | null;
139
+ }
140
+ }
141
+
142
+ interface IComposition {
143
+ location: string;
144
+ type: boolean;
145
+ default: boolean;
146
+ name?: string;
147
+ elements: HashSet<string>;
148
+ }
149
+
150
+ const NODE_MODULES = "node_modules/";
151
+
152
+ const normalize = (file: string): string => {
153
+ file = path.resolve(file);
154
+ if (file.includes(`node_modules${path.sep}`))
155
+ file =
156
+ "node_modules/" +
157
+ file.split(`node_modules${path.sep}`).at(-1)!.split(path.sep).join("/");
158
+ return file;
159
+ };