@nestia/sdk 3.11.0-dev.20240813-10 → 3.11.0-dev.20240814

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 (135) hide show
  1. package/assets/bundle/api/Resolved.ts +1 -0
  2. package/assets/bundle/api/module.ts +1 -0
  3. package/lib/NestiaSdkApplication.d.ts +1 -0
  4. package/lib/NestiaSdkApplication.js +24 -26
  5. package/lib/NestiaSdkApplication.js.map +1 -1
  6. package/lib/analyses/ReflectControllerAnalyzer.js +2 -0
  7. package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -1
  8. package/lib/analyses/ReflectHttpOperationAnalyzer.js +10 -1
  9. package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
  10. package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.d.ts +15 -0
  11. package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.js +50 -0
  12. package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.js.map +1 -0
  13. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js +14 -9
  14. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js.map +1 -1
  15. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +2 -1
  16. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -1
  17. package/lib/analyses/ReflectWebSocketOperationAnalyzer.js +3 -2
  18. package/lib/analyses/ReflectWebSocketOperationAnalyzer.js.map +1 -1
  19. package/lib/analyses/TypedHttpRouteAnalyzer.js +3 -1
  20. package/lib/analyses/TypedHttpRouteAnalyzer.js.map +1 -1
  21. package/lib/executable/internal/NestiaSdkCommand.d.ts +1 -0
  22. package/lib/executable/internal/NestiaSdkCommand.js +3 -2
  23. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
  24. package/lib/executable/sdk.js +3 -0
  25. package/lib/executable/sdk.js.map +1 -1
  26. package/lib/generates/CloneGenerator.d.ts +4 -0
  27. package/lib/generates/CloneGenerator.js +62 -60
  28. package/lib/generates/CloneGenerator.js.map +1 -1
  29. package/lib/generates/SdkGenerator.js +4 -3
  30. package/lib/generates/SdkGenerator.js.map +1 -1
  31. package/lib/generates/SwaggerGenerator.js +60 -8
  32. package/lib/generates/SwaggerGenerator.js.map +1 -1
  33. package/lib/generates/internal/E2eFileProgrammer.js +11 -3
  34. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  35. package/lib/generates/internal/ImportDictionary.js +1 -1
  36. package/lib/generates/internal/ImportDictionary.js.map +1 -1
  37. package/lib/generates/internal/SdkAliasCollection.d.ts +5 -1
  38. package/lib/generates/internal/SdkAliasCollection.js +24 -8
  39. package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
  40. package/lib/generates/internal/SdkFileProgrammer.js +1 -1
  41. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  42. package/lib/generates/internal/SdkHttpCloneProgrammer.d.ts +11 -0
  43. package/lib/generates/internal/SdkHttpCloneProgrammer.js +75 -142
  44. package/lib/generates/internal/SdkHttpCloneProgrammer.js.map +1 -1
  45. package/lib/generates/internal/SdkHttpCloneReferencer.d.ts +4 -0
  46. package/lib/generates/internal/SdkHttpCloneReferencer.js +62 -0
  47. package/lib/generates/internal/SdkHttpCloneReferencer.js.map +1 -0
  48. package/lib/generates/internal/SdkHttpFunctionProgrammer.js +26 -13
  49. package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
  50. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +17 -8
  51. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
  52. package/lib/generates/internal/SdkHttpRouteProgrammer.js +2 -2
  53. package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
  54. package/lib/generates/internal/SdkHttpSimulationProgrammer.js +8 -5
  55. package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
  56. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +12 -5
  57. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
  58. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +3 -3
  59. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
  60. package/lib/generates/internal/SwaggerOperationComposer.js +19 -1
  61. package/lib/generates/internal/SwaggerOperationComposer.js.map +1 -1
  62. package/lib/generates/internal/SwaggerOperationParameterComposer.js +3 -3
  63. package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
  64. package/lib/structures/IReflectHttpOperation.d.ts +1 -1
  65. package/lib/structures/IReflectHttpOperationException.d.ts +2 -2
  66. package/lib/structures/ITypedApplication.d.ts +2 -0
  67. package/lib/transform.js +2 -2
  68. package/lib/transform.js.map +1 -1
  69. package/lib/transformers/IOperationMetadata.d.ts +6 -1
  70. package/lib/transformers/{ISdkTransformerContext.d.ts → ISdkOperationTransformerContext.d.ts} +1 -1
  71. package/lib/transformers/{ISdkTransformerContext.js → ISdkOperationTransformerContext.js} +1 -1
  72. package/lib/transformers/ISdkOperationTransformerContext.js.map +1 -0
  73. package/lib/transformers/SdkOperationProgrammer.d.ts +13 -0
  74. package/lib/transformers/{SdkMetadataProgrammer.js → SdkOperationProgrammer.js} +36 -55
  75. package/lib/transformers/SdkOperationProgrammer.js.map +1 -0
  76. package/lib/transformers/SdkOperationTransformer.d.ts +4 -0
  77. package/lib/transformers/{SdkTransformer.js → SdkOperationTransformer.js} +56 -16
  78. package/lib/transformers/SdkOperationTransformer.js.map +1 -0
  79. package/lib/utils/MetadataUtil.d.ts +4 -0
  80. package/lib/utils/MetadataUtil.js +34 -0
  81. package/lib/utils/MetadataUtil.js.map +1 -0
  82. package/lib/utils/StringUtil.d.ts +1 -0
  83. package/lib/utils/StringUtil.js +6 -0
  84. package/lib/utils/StringUtil.js.map +1 -1
  85. package/lib/validators/HttpHeadersValidator.d.ts +5 -0
  86. package/lib/validators/HttpHeadersValidator.js +29 -0
  87. package/lib/validators/HttpHeadersValidator.js.map +1 -0
  88. package/lib/validators/HttpQueryValidator.d.ts +5 -0
  89. package/lib/validators/HttpQueryValidator.js +29 -0
  90. package/lib/validators/HttpQueryValidator.js.map +1 -0
  91. package/package.json +8 -8
  92. package/src/NestiaSdkApplication.ts +20 -30
  93. package/src/analyses/ReflectControllerAnalyzer.ts +2 -0
  94. package/src/analyses/ReflectHttpOperationAnalyzer.ts +10 -1
  95. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +71 -0
  96. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +37 -8
  97. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +8 -0
  98. package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +10 -2
  99. package/src/analyses/TypedHttpRouteAnalyzer.ts +4 -1
  100. package/src/executable/internal/NestiaSdkCommand.ts +3 -2
  101. package/src/executable/sdk.ts +2 -0
  102. package/src/generates/CloneGenerator.ts +61 -60
  103. package/src/generates/SdkGenerator.ts +3 -3
  104. package/src/generates/SwaggerGenerator.ts +84 -10
  105. package/src/generates/internal/E2eFileProgrammer.ts +13 -3
  106. package/src/generates/internal/ImportDictionary.ts +1 -1
  107. package/src/generates/internal/SdkAliasCollection.ts +32 -10
  108. package/src/generates/internal/SdkFileProgrammer.ts +1 -1
  109. package/src/generates/internal/SdkHttpCloneProgrammer.ts +118 -144
  110. package/src/generates/internal/SdkHttpCloneReferencer.ts +71 -0
  111. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +31 -16
  112. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +252 -230
  113. package/src/generates/internal/SdkHttpRouteProgrammer.ts +2 -2
  114. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +30 -24
  115. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +14 -6
  116. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +6 -8
  117. package/src/generates/internal/SwaggerOperationComposer.ts +25 -0
  118. package/src/generates/internal/SwaggerOperationParameterComposer.ts +3 -0
  119. package/src/structures/IReflectHttpOperation.ts +1 -4
  120. package/src/structures/IReflectHttpOperationException.ts +2 -2
  121. package/src/structures/ITypedApplication.ts +3 -0
  122. package/src/transform.ts +2 -2
  123. package/src/transformers/IOperationMetadata.ts +7 -1
  124. package/src/transformers/{ISdkTransformerContext.ts → ISdkOperationTransformerContext.ts} +1 -1
  125. package/src/transformers/{SdkMetadataProgrammer.ts → SdkOperationProgrammer.ts} +40 -62
  126. package/src/transformers/{SdkTransformer.ts → SdkOperationTransformer.ts} +88 -16
  127. package/src/utils/MetadataUtil.ts +26 -0
  128. package/src/utils/StringUtil.ts +8 -0
  129. package/src/validators/HttpHeadersValidator.ts +34 -0
  130. package/src/validators/HttpQueryValidator.ts +34 -0
  131. package/lib/transformers/ISdkTransformerContext.js.map +0 -1
  132. package/lib/transformers/SdkMetadataProgrammer.d.ts +0 -11
  133. package/lib/transformers/SdkMetadataProgrammer.js.map +0 -1
  134. package/lib/transformers/SdkTransformer.d.ts +0 -4
  135. package/lib/transformers/SdkTransformer.js.map +0 -1
@@ -1,5 +1,7 @@
1
1
  import ts from "typescript";
2
2
  import typia from "typia";
3
+ import { TypeFactory } from "typia/lib/factories/TypeFactory";
4
+ import { Metadata } from "typia/lib/schemas/metadata/Metadata";
3
5
 
4
6
  import { INestiaProject } from "../../structures/INestiaProject";
5
7
  import { IReflectHttpOperationParameter } from "../../structures/IReflectHttpOperationParameter";
@@ -7,18 +9,29 @@ import { IReflectType } from "../../structures/IReflectType";
7
9
  import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
8
10
  import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
9
11
  import { ImportDictionary } from "./ImportDictionary";
12
+ import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
10
13
 
11
14
  export namespace SdkAliasCollection {
12
- export const name = (type: IReflectType): ts.TypeNode =>
15
+ export const name = ({ type }: { type: IReflectType }): ts.TypeNode =>
13
16
  ts.factory.createTypeReferenceNode(
14
17
  type.name,
15
- type.typeArguments ? type.typeArguments.map(name) : undefined,
18
+ type.typeArguments
19
+ ? type.typeArguments.map((a) => name({ type: a }))
20
+ : undefined,
16
21
  );
17
22
 
23
+ export const from =
24
+ (project: INestiaProject) =>
25
+ (importer: ImportDictionary) =>
26
+ (metadata: Metadata) =>
27
+ SdkTypeProgrammer.write(project)(importer)(metadata);
28
+
18
29
  export const headers =
19
30
  (project: INestiaProject) =>
20
31
  (importer: ImportDictionary) =>
21
32
  (param: ITypedHttpRouteParameter.IHeaders): ts.TypeNode => {
33
+ if (project.config.clone === true)
34
+ return from(project)(importer)(param.metadata);
22
35
  const type: ts.TypeNode = name(param);
23
36
  if (project.config.primitive === false) return type;
24
37
  return ts.factory.createTypeReferenceNode(
@@ -35,6 +48,8 @@ export namespace SdkAliasCollection {
35
48
  (project: INestiaProject) =>
36
49
  (importer: ImportDictionary) =>
37
50
  (param: ITypedHttpRouteParameter.IQuery): ts.TypeNode => {
51
+ if (project.config.clone === true)
52
+ return from(project)(importer)(param.metadata);
38
53
  const type: ts.TypeNode = name(param);
39
54
  if (project.config.primitive === false) return type;
40
55
  return ts.factory.createTypeReferenceNode(
@@ -51,9 +66,10 @@ export namespace SdkAliasCollection {
51
66
  (project: INestiaProject) =>
52
67
  (importer: ImportDictionary) =>
53
68
  (param: ITypedHttpRouteParameter): ts.TypeNode => {
54
- const type: ts.TypeNode = name(param.type);
55
- if (project.config.clone === true || project.config.primitive === false)
56
- return type;
69
+ if (project.config.clone === true)
70
+ return from(project)(importer)(param.metadata);
71
+ const type: ts.TypeNode = name(param);
72
+ if (project.config.primitive === false) return type;
57
73
  return ts.factory.createTypeReferenceNode(
58
74
  importer.external({
59
75
  type: true,
@@ -73,9 +89,15 @@ export namespace SdkAliasCollection {
73
89
  (project: INestiaProject) =>
74
90
  (importer: ImportDictionary) =>
75
91
  (route: ITypedHttpRoute): ts.TypeNode => {
92
+ const schema = (p: { metadata: Metadata; type: IReflectType }) =>
93
+ project.config.clone === true
94
+ ? from(project)(importer)(p.metadata)
95
+ : name(p);
76
96
  if (project.config.propagate !== true) {
77
- if (project.config.clone === true || project.config.primitive === false)
78
- return name(route.success.type);
97
+ if (route.success.metadata.size() === 0)
98
+ return TypeFactory.keyword("void");
99
+ else if (project.config.primitive === false)
100
+ return schema(route.success);
79
101
  return ts.factory.createTypeReferenceNode(
80
102
  importer.external({
81
103
  type: true,
@@ -86,7 +108,7 @@ export namespace SdkAliasCollection {
86
108
  ? "Primitive"
87
109
  : "Resolved",
88
110
  }),
89
- [name(route.success.type)],
111
+ [schema(route.success)],
90
112
  );
91
113
  }
92
114
 
@@ -95,11 +117,11 @@ export namespace SdkAliasCollection {
95
117
  status: String(
96
118
  route.success.status ?? (route.method === "POST" ? 201 : 200),
97
119
  ),
98
- type: name(route.success.type),
120
+ type: schema(route.success),
99
121
  },
100
122
  ...Object.entries(route.exceptions).map(([status, value]) => ({
101
123
  status,
102
- type: name(value.type),
124
+ type: schema(value),
103
125
  })),
104
126
  ];
105
127
  return ts.factory.createTypeReferenceNode(
@@ -75,7 +75,7 @@ export namespace SdkFileProgrammer {
75
75
  `${outDir}/index.ts`,
76
76
  );
77
77
  directory.routes.forEach((route, i) => {
78
- if (project.config.clone !== true || route.protocol === "websocket")
78
+ if (!(project.config.clone === true && route.protocol === "http"))
79
79
  for (const tuple of route.imports)
80
80
  for (const instance of tuple.instances)
81
81
  importer.internal({
@@ -1,154 +1,128 @@
1
- // import { IPointer } from "tstl";
2
- // import ts from "typescript";
3
- // import { IJsDocTagInfo } from "typia";
4
- // import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
5
- // import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
6
- // import { MetadataAlias } from "typia/lib/schemas/metadata/MetadataAlias";
7
- // import { MetadataAtomic } from "typia/lib/schemas/metadata/MetadataAtomic";
8
- // import { MetadataObject } from "typia/lib/schemas/metadata/MetadataObject";
1
+ import { IPointer } from "tstl";
2
+ import ts from "typescript";
3
+ import { IJsDocTagInfo } from "typia";
4
+ import { MetadataAlias } from "typia/lib/schemas/metadata/MetadataAlias";
5
+ import { MetadataAtomic } from "typia/lib/schemas/metadata/MetadataAtomic";
6
+ import { MetadataObject } from "typia/lib/schemas/metadata/MetadataObject";
9
7
 
10
- // import { INestiaProject } from "../../structures/INestiaProject";
11
- // import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
12
- // import { MapUtil } from "../../utils/MapUtil";
13
- // import { FilePrinter } from "./FilePrinter";
14
- // import { ImportDictionary } from "./ImportDictionary";
15
- // import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
8
+ import { INestiaProject } from "../../structures/INestiaProject";
9
+ import { ITypedApplication } from "../../structures/ITypedApplication";
10
+ import { MapUtil } from "../../utils/MapUtil";
11
+ import { StringUtil } from "../../utils/StringUtil";
12
+ import { FilePrinter } from "./FilePrinter";
13
+ import { ImportDictionary } from "./ImportDictionary";
14
+ import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
16
15
 
17
- // export namespace SdkHttpCloneProgrammer {
18
- // export interface IModule {
19
- // name: string;
20
- // children: Map<string, IModule>;
21
- // programmer:
22
- // | null
23
- // | ((importer: ImportDictionary) => ts.TypeAliasDeclaration);
24
- // }
16
+ export namespace SdkHttpCloneProgrammer {
17
+ export interface IModule {
18
+ name: string;
19
+ children: Map<string, IModule>;
20
+ programmer:
21
+ | null
22
+ | ((importer: ImportDictionary) => ts.TypeAliasDeclaration);
23
+ }
25
24
 
26
- // export const write =
27
- // (project: INestiaProject) =>
28
- // (routes: ITypedHttpRoute[]): Map<string, IModule> => {
29
- // const collection = new MetadataCollection({
30
- // replace: MetadataCollection.replace,
31
- // });
32
- // for (const r of routes) {
33
- // for (const p of r.parameters) {
34
- // const res = MetadataFactory.analyze(project.checker)({
35
- // escape: false,
36
- // constant: true,
37
- // absorb: false,
38
- // })(collection)(p.type);
39
- // if (res.success) p.metadata = res.data;
40
- // }
41
- // for (const e of Object.values(r.exceptions)) {
42
- // const res = MetadataFactory.analyze(project.checker)({
43
- // escape: true,
44
- // constant: true,
45
- // absorb: false,
46
- // })(collection)(e.type);
47
- // if (res.success) e.metadata = res.data;
48
- // }
49
- // const res = MetadataFactory.analyze(project.checker)({
50
- // escape: true,
51
- // constant: true,
52
- // absorb: false,
53
- // })(collection)(r.output.type);
54
- // if (res.success) r.success.metadata = res.data;
55
- // }
25
+ export const write = (app: ITypedApplication): Map<string, IModule> => {
26
+ // console.log({
27
+ // objects: Array.from(app.collection.objects.keys()).sort(),
28
+ // aliases: Array.from(app.collection.aliases.keys()).sort(),
29
+ // });
30
+ // COMPOSE THE DICTIONARY
31
+ const dict: Map<string, IModule> = new Map();
32
+ for (const [k, v] of app.collection.objects.entries())
33
+ if (StringUtil.isImplicit(k) === false)
34
+ prepare({
35
+ dict,
36
+ name: k,
37
+ programmer: (importer) => write_object(app.project)(importer)(v),
38
+ });
39
+ for (const [k, v] of app.collection.aliases.entries())
40
+ if (StringUtil.isImplicit(k) === false)
41
+ prepare({
42
+ dict,
43
+ name: k,
44
+ programmer: (importer) => write_alias(app.project)(importer)(v),
45
+ });
46
+ return dict;
47
+ };
56
48
 
57
- // const dict: Map<string, IModule> = new Map();
58
- // for (const alias of collection.aliases())
59
- // if (isNamedDeclaration(alias.name))
60
- // prepare(dict)(alias.name)((importer) =>
61
- // write_alias(project)(importer)(alias),
62
- // );
63
- // for (const object of collection.objects())
64
- // if (isNamedDeclaration(object.name))
65
- // prepare(dict)(object.name)((importer) =>
66
- // write_object(project)(importer)(object),
67
- // );
68
- // return dict;
69
- // };
49
+ const prepare = (props: {
50
+ dict: Map<string, IModule>;
51
+ name: string;
52
+ programmer: (importer: ImportDictionary) => ts.TypeAliasDeclaration;
53
+ }) => {
54
+ let next: Map<string, IModule> = props.dict;
55
+ const accessors: string[] = props.name.split(".");
56
+ const modulo: IPointer<IModule> = { value: null! };
70
57
 
71
- // const prepare =
72
- // (dict: Map<string, IModule>) =>
73
- // (name: string) =>
74
- // (programmer: (importer: ImportDictionary) => ts.TypeAliasDeclaration) => {
75
- // const accessors: string[] = name.split(".");
76
- // const modulo: IPointer<IModule> = { value: null! };
58
+ accessors.forEach((acc, i) => {
59
+ modulo.value = MapUtil.take(next, acc, () => ({
60
+ name: acc,
61
+ children: new Map(),
62
+ programmer: null,
63
+ }));
64
+ if (i === accessors.length - 1)
65
+ modulo.value.programmer = props.programmer;
66
+ next = modulo.value.children;
67
+ });
68
+ return modulo!;
69
+ };
77
70
 
78
- // accessors.forEach((acc, i) => {
79
- // modulo.value = MapUtil.take(dict, acc, () => ({
80
- // name: acc,
81
- // children: new Map(),
82
- // programmer: null,
83
- // }));
84
- // if (i === accessors.length - 1) modulo.value.programmer = programmer;
85
- // dict = modulo.value.children;
86
- // });
87
- // return modulo!;
88
- // };
71
+ const write_alias =
72
+ (project: INestiaProject) =>
73
+ (importer: ImportDictionary) =>
74
+ (alias: MetadataAlias): ts.TypeAliasDeclaration =>
75
+ FilePrinter.description(
76
+ ts.factory.createTypeAliasDeclaration(
77
+ [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
78
+ alias.name.split(".").at(-1)!,
79
+ [],
80
+ SdkTypeProgrammer.write(project)(importer)(alias.value),
81
+ ),
82
+ writeComment([])(alias.description, alias.jsDocTags),
83
+ );
89
84
 
90
- // const write_alias =
91
- // (project: INestiaProject) =>
92
- // (importer: ImportDictionary) =>
93
- // (alias: MetadataAlias): ts.TypeAliasDeclaration =>
94
- // FilePrinter.description(
95
- // ts.factory.createTypeAliasDeclaration(
96
- // [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
97
- // alias.name.split(".").at(-1)!,
98
- // [],
99
- // SdkTypeProgrammer.write(project)(importer)(alias.value),
100
- // ),
101
- // writeComment([])(alias.description, alias.jsDocTags),
102
- // );
85
+ const write_object =
86
+ (project: INestiaProject) =>
87
+ (importer: ImportDictionary) =>
88
+ (object: MetadataObject): ts.TypeAliasDeclaration => {
89
+ return FilePrinter.description(
90
+ ts.factory.createTypeAliasDeclaration(
91
+ [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
92
+ object.name.split(".").at(-1)!,
93
+ [],
94
+ SdkTypeProgrammer.write_object(project)(importer)(object),
95
+ ),
96
+ writeComment([])(object.description ?? null, object.jsDocTags),
97
+ );
98
+ };
99
+ }
103
100
 
104
- // const write_object =
105
- // (project: INestiaProject) =>
106
- // (importer: ImportDictionary) =>
107
- // (object: MetadataObject): ts.TypeAliasDeclaration => {
108
- // return FilePrinter.description(
109
- // ts.factory.createTypeAliasDeclaration(
110
- // [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
111
- // object.name.split(".").at(-1)!,
112
- // [],
113
- // SdkTypeProgrammer.write_object(project)(importer)(object),
114
- // ),
115
- // writeComment([])(object.description ?? null, object.jsDocTags),
116
- // );
117
- // };
118
- // }
101
+ const writeComment =
102
+ (atomics: MetadataAtomic[]) =>
103
+ (description: string | null, jsDocTags: IJsDocTagInfo[]): string => {
104
+ const lines: string[] = [];
105
+ if (description?.length)
106
+ lines.push(...description.split("\n").map((s) => `${s}`));
119
107
 
120
- // const isNamedDeclaration = (name: string) =>
121
- // name !== "object" &&
122
- // name !== "__type" &&
123
- // !name.startsWith("__type.") &&
124
- // name !== "__object" &&
125
- // !name.startsWith("__object.");
108
+ const filtered: IJsDocTagInfo[] =
109
+ !!atomics.length && !!jsDocTags?.length
110
+ ? jsDocTags.filter(
111
+ (tag) =>
112
+ !atomics.some((a) =>
113
+ a.tags.some((r) => r.some((t) => t.kind === tag.name)),
114
+ ),
115
+ )
116
+ : jsDocTags ?? [];
126
117
 
127
- // const writeComment =
128
- // (atomics: MetadataAtomic[]) =>
129
- // (description: string | null, jsDocTags: IJsDocTagInfo[]): string => {
130
- // const lines: string[] = [];
131
- // if (description?.length)
132
- // lines.push(...description.split("\n").map((s) => `${s}`));
133
-
134
- // const filtered: IJsDocTagInfo[] =
135
- // !!atomics.length && !!jsDocTags?.length
136
- // ? jsDocTags.filter(
137
- // (tag) =>
138
- // !atomics.some((a) =>
139
- // a.tags.some((r) => r.some((t) => t.kind === tag.name)),
140
- // ),
141
- // )
142
- // : jsDocTags ?? [];
143
-
144
- // if (description?.length && filtered.length) lines.push("");
145
- // if (filtered.length)
146
- // lines.push(
147
- // ...filtered.map((t) =>
148
- // t.text?.length
149
- // ? `@${t.name} ${t.text.map((e) => e.text).join("")}`
150
- // : `@${t.name}`,
151
- // ),
152
- // );
153
- // return lines.join("\n");
154
- // };
118
+ if (description?.length && filtered.length) lines.push("");
119
+ if (filtered.length)
120
+ lines.push(
121
+ ...filtered.map((t) =>
122
+ t.text?.length
123
+ ? `@${t.name} ${t.text.map((e) => e.text).join("")}`
124
+ : `@${t.name}`,
125
+ ),
126
+ );
127
+ return lines.join("\n");
128
+ };
@@ -0,0 +1,71 @@
1
+ import { Metadata } from "typia/lib/schemas/metadata/Metadata";
2
+
3
+ import { IReflectType } from "../../structures/IReflectType";
4
+ import { ITypedApplication } from "../../structures/ITypedApplication";
5
+ import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
6
+ import { StringUtil } from "../../utils/StringUtil";
7
+
8
+ export namespace SdkHttpCloneReferencer {
9
+ export const replace = (app: ITypedApplication): void => {
10
+ const directory: string = `${app.project.config.output}/structures`;
11
+ for (const route of app.routes)
12
+ if (route.protocol === "http")
13
+ visitRoute({
14
+ directory,
15
+ route,
16
+ });
17
+ };
18
+
19
+ const visitRoute = (props: {
20
+ directory: string;
21
+ route: ITypedHttpRoute;
22
+ }): void => {
23
+ const unique: Set<string> = new Set();
24
+ for (const p of props.route.parameters)
25
+ visitType({
26
+ unique,
27
+ metadata: p.metadata,
28
+ type: p.type,
29
+ name: (name) => (p.type = { name }),
30
+ });
31
+ for (const v of Object.values(props.route.exceptions))
32
+ visitType({
33
+ unique,
34
+ metadata: v.metadata,
35
+ type: v.type,
36
+ name: (name) => (v.type = { name }),
37
+ });
38
+ visitType({
39
+ unique,
40
+ metadata: props.route.success.metadata,
41
+ type: props.route.success.type,
42
+ name: (name) => (props.route.success.type = { name }),
43
+ });
44
+ props.route.imports = Array.from(unique).map((str) => ({
45
+ file: `${props.directory}/${str}`,
46
+ instances: [str],
47
+ }));
48
+ };
49
+
50
+ const visitType = (p: {
51
+ unique: Set<string>;
52
+ metadata: Metadata;
53
+ type: IReflectType;
54
+ name: (key: string) => void;
55
+ }): void => {
56
+ const enroll = (key: string) => {
57
+ if (key.length && StringUtil.isImplicit(key) === false)
58
+ p.unique.add(key.split(".")[0]);
59
+ };
60
+ for (const alias of p.metadata.aliases) enroll(alias.name);
61
+ for (const array of p.metadata.arrays) enroll(array.type.name);
62
+ for (const tuple of p.metadata.tuples) enroll(tuple.type.name);
63
+ for (const object of p.metadata.objects) enroll(object.name);
64
+ p.name(p.metadata.getName());
65
+ };
66
+ }
67
+
68
+ const getFullText = (type: IReflectType): string =>
69
+ type.typeArguments === undefined
70
+ ? type.name
71
+ : `${type.name}<${type.typeArguments.map(getFullText).join(", ")}>`;
@@ -1,7 +1,7 @@
1
1
  import ts from "typescript";
2
2
  import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
3
+ import { TypeFactory } from "typia/lib/factories/TypeFactory";
3
4
 
4
- import { INestiaConfig } from "../../INestiaConfig";
5
5
  import { INestiaProject } from "../../structures/INestiaProject";
6
6
  import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
7
7
  import { ITypedHttpRouteParameter } from "../../structures/ITypedHttpRouteParameter";
@@ -55,21 +55,26 @@ export namespace SdkHttpFunctionProgrammer {
55
55
  ? ts.factory.createTypeReferenceNode(
56
56
  `${route.name}.${p === props.query ? "Query" : "Input"}`,
57
57
  )
58
- : SdkAliasCollection.name(p.type),
58
+ : project.config.clone === true
59
+ ? SdkAliasCollection.from(project)(importer)(p.metadata)
60
+ : SdkAliasCollection.name(p),
59
61
  ),
60
62
  ),
61
63
  ],
62
64
  ts.factory.createTypeReferenceNode("Promise", [
63
- SdkAliasCollection.name(route.success.type),
65
+ project.config.propagate === true ||
66
+ route.success.metadata.size() !== 0
67
+ ? ts.factory.createTypeReferenceNode(`${route.name}.Output`)
68
+ : ts.factory.createTypeReferenceNode("void"),
64
69
  ]),
65
70
  ts.factory.createBlock(
66
- write_body(project.config)(importer)(route, props),
71
+ write_body(project)(importer)(route, props),
67
72
  true,
68
73
  ),
69
74
  );
70
75
 
71
76
  const write_body =
72
- (config: INestiaConfig) =>
77
+ (project: INestiaProject) =>
73
78
  (importer: ImportDictionary) =>
74
79
  (
75
80
  route: ITypedHttpRoute,
@@ -83,10 +88,17 @@ export namespace SdkHttpFunctionProgrammer {
83
88
  ts.factory.createCallExpression(
84
89
  IdentifierFactory.access(
85
90
  ts.factory.createIdentifier(
86
- SdkImportWizard.Fetcher(!!props.input?.encrypted)(importer),
91
+ SdkImportWizard.Fetcher(
92
+ !!props.input?.encrypted || route.success.encrypted,
93
+ )(importer),
87
94
  ),
88
- )(config.propagate ? "propagate" : "fetch"),
89
- undefined,
95
+ )(project.config.propagate ? "propagate" : "fetch"),
96
+ project.config.propagate
97
+ ? route.method.toLowerCase() === "get" ||
98
+ route.method.toLowerCase() === "head"
99
+ ? [TypeFactory.keyword("any")]
100
+ : [TypeFactory.keyword("any"), TypeFactory.keyword("any")]
101
+ : undefined,
90
102
  [
91
103
  props.input?.contentType !== "multipart/form-data"
92
104
  ? ts.factory.createObjectLiteralExpression(
@@ -152,7 +164,7 @@ export namespace SdkHttpFunctionProgrammer {
152
164
  ...(props.input
153
165
  ? [ts.factory.createIdentifier(props.input.name)]
154
166
  : []),
155
- ...(config.json &&
167
+ ...(project.config.json &&
156
168
  props.input !== undefined &&
157
169
  (props.input.contentType === "application/json" ||
158
170
  props.input.encrypted === true)
@@ -161,7 +173,7 @@ export namespace SdkHttpFunctionProgrammer {
161
173
  ],
162
174
  );
163
175
  const output = (awaiter: boolean) =>
164
- config.simulate
176
+ project.config.simulate
165
177
  ? ts.factory.createConditionalExpression(
166
178
  ts.factory.createIdentifier("!!connection.simulate"),
167
179
  undefined,
@@ -182,7 +194,7 @@ export namespace SdkHttpFunctionProgrammer {
182
194
  ? ts.factory.createAwaitExpression(caller())
183
195
  : caller();
184
196
  return [
185
- ...(config.assert
197
+ ...(project.config.assert
186
198
  ? route.parameters
187
199
  .filter((p) => p.category !== "headers")
188
200
  .map((p) =>
@@ -205,12 +217,13 @@ export namespace SdkHttpFunctionProgrammer {
205
217
  : []),
206
218
  ...(route.success.setHeaders.length === 0
207
219
  ? [ts.factory.createReturnStatement(output(false))]
208
- : write_set_headers(config)(route)(output(true))),
220
+ : write_set_headers(project)(importer)(route)(output(true))),
209
221
  ];
210
222
  };
211
223
 
212
224
  const write_set_headers =
213
- (config: INestiaConfig) =>
225
+ (project: INestiaProject) =>
226
+ (importer: ImportDictionary) =>
214
227
  (route: ITypedHttpRoute) =>
215
228
  (condition: ts.Expression): ts.Statement[] => {
216
229
  const accessor = (x: string) => (y: string) =>
@@ -220,7 +233,9 @@ export namespace SdkHttpFunctionProgrammer {
220
233
  ...route.parameters.map((p) => p.name),
221
234
  ])("output");
222
235
  const headers: string = accessor("connection")("headers");
223
- const data: string = config.propagate ? accessor(output)("data") : output;
236
+ const data: string = project.config.propagate
237
+ ? accessor(output)("data")
238
+ : output;
224
239
 
225
240
  const assigners: ts.ExpressionStatement[] = [
226
241
  ts.factory.createBinaryExpression(
@@ -255,14 +270,14 @@ export namespace SdkHttpFunctionProgrammer {
255
270
  ts.factory.createVariableDeclaration(
256
271
  output,
257
272
  undefined,
258
- SdkAliasCollection.name(route.success.type),
273
+ SdkAliasCollection.output(project)(importer)(route),
259
274
  condition,
260
275
  ),
261
276
  ],
262
277
  ts.NodeFlags.Const,
263
278
  ),
264
279
  ),
265
- ...(config.propagate
280
+ ...(project.config.propagate
266
281
  ? [
267
282
  ts.factory.createIfStatement(
268
283
  ts.factory.createIdentifier(accessor(output)("success")),