@nestia/sdk 11.0.0-dev.20260316 → 11.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +93 -93
  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/executable/internal/NestiaConfigLoader.js +5 -5
  15. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  16. package/package.json +8 -8
  17. package/src/INestiaConfig.ts +267 -267
  18. package/src/NestiaSdkApplication.ts +307 -307
  19. package/src/NestiaSwaggerComposer.ts +143 -143
  20. package/src/analyses/AccessorAnalyzer.ts +67 -67
  21. package/src/analyses/DtoAnalyzer.ts +260 -260
  22. package/src/analyses/ImportAnalyzer.ts +126 -126
  23. package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
  24. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +72 -72
  25. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +350 -350
  26. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +126 -126
  27. package/src/analyses/TypedHttpRouteAnalyzer.ts +208 -208
  28. package/src/executable/internal/NestiaConfigLoader.ts +85 -85
  29. package/src/executable/internal/NestiaSdkCommand.ts +107 -107
  30. package/src/generates/SwaggerGenerator.ts +291 -291
  31. package/src/generates/internal/E2eFileProgrammer.ts +196 -196
  32. package/src/generates/internal/FilePrinter.ts +64 -64
  33. package/src/generates/internal/ImportDictionary.ts +192 -192
  34. package/src/generates/internal/SdkAliasCollection.ts +260 -260
  35. package/src/generates/internal/SdkFileProgrammer.ts +110 -110
  36. package/src/generates/internal/SdkHttpCloneProgrammer.ts +126 -126
  37. package/src/generates/internal/SdkHttpCloneReferencer.ts +77 -77
  38. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +278 -278
  39. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +502 -502
  40. package/src/generates/internal/SdkHttpRouteProgrammer.ts +109 -109
  41. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +312 -312
  42. package/src/generates/internal/SdkImportWizard.ts +62 -62
  43. package/src/generates/internal/SdkTypeProgrammer.ts +388 -388
  44. package/src/generates/internal/SdkTypeTagProgrammer.ts +114 -114
  45. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +379 -379
  46. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +302 -302
  47. package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
  48. package/src/generates/internal/SwaggerOperationParameterComposer.ts +161 -161
  49. package/src/generates/internal/SwaggerOperationResponseComposer.ts +110 -110
  50. package/src/module.ts +4 -4
  51. package/src/structures/IReflectHttpOperationException.ts +18 -18
  52. package/src/structures/IReflectHttpOperationParameter.ts +79 -79
  53. package/src/structures/IReflectHttpOperationSuccess.ts +21 -21
  54. package/src/structures/ITypedApplication.ts +11 -11
  55. package/src/structures/ITypedHttpRouteException.ts +15 -15
  56. package/src/structures/ITypedHttpRouteParameter.ts +41 -41
  57. package/src/structures/ITypedHttpRouteSuccess.ts +22 -22
  58. package/src/transformers/IOperationMetadata.ts +46 -46
  59. package/src/transformers/ISdkOperationTransformerContext.ts +8 -8
  60. package/src/transformers/SdkOperationProgrammer.ts +240 -240
  61. package/src/transformers/SdkOperationTransformer.ts +248 -248
  62. package/src/transformers/TextPlainValidator.ts +17 -17
  63. package/src/utils/MetadataUtil.ts +26 -26
  64. package/src/validators/HttpHeadersValidator.ts +40 -40
  65. package/src/validators/HttpQueryValidator.ts +40 -40
@@ -1,248 +1,248 @@
1
- import { LiteralFactory, MetadataCollection, TypeFactory } from "@typia/core";
2
- import path from "path";
3
- import { HashSet, Singleton, hash } from "tstl";
4
- import ts from "typescript";
5
-
6
- import { ImportAnalyzer } from "../analyses/ImportAnalyzer";
7
- import { IReflectImport } from "../structures/IReflectImport";
8
- import { IOperationMetadata } from "./IOperationMetadata";
9
- import { ISdkOperationTransformerContext } from "./ISdkOperationTransformerContext";
10
- import { SdkOperationProgrammer } from "./SdkOperationProgrammer";
11
-
12
- export namespace SdkOperationTransformer {
13
- export const iterateFile =
14
- (checker: ts.TypeChecker) => (api: ts.TransformationContext) => {
15
- const context: ISdkOperationTransformerContext = {
16
- checker,
17
- transformer: api,
18
- collection: collection.get(),
19
- };
20
- return (file: ts.SourceFile): ts.SourceFile => {
21
- if (file.isDeclarationFile === true) return file;
22
- const visitor: IVisitor = {
23
- done: false,
24
- visited: new HashSet(),
25
- };
26
- file = ts.visitEachChild(
27
- file,
28
- (node) =>
29
- iterateNode({
30
- context,
31
- imports: new Singleton(() => ImportAnalyzer.analyze(file)),
32
- visitor,
33
- node,
34
- }),
35
- api,
36
- );
37
- if (visitor.done === false) return file;
38
- return ts.factory.updateSourceFile(file, [
39
- ts.factory.createImportDeclaration(
40
- undefined,
41
- ts.factory.createImportClause(
42
- false,
43
- undefined,
44
- ts.factory.createNamespaceImport(
45
- ts.factory.createIdentifier("__OperationMetadata"),
46
- ),
47
- ),
48
- ts.factory.createStringLiteral("@nestia/sdk"),
49
- undefined,
50
- ),
51
- ...file.statements,
52
- ]);
53
- };
54
- };
55
-
56
- interface IVisitor {
57
- done: boolean;
58
- visited: HashSet<MethodKey>;
59
- }
60
-
61
- const iterateNode = (props: {
62
- context: ISdkOperationTransformerContext;
63
- imports: Singleton<IReflectImport[]>;
64
- visitor: IVisitor;
65
- node: ts.Node;
66
- }): ts.Node =>
67
- ts.visitEachChild(
68
- transformNode(props),
69
- (child) =>
70
- iterateNode({
71
- ...props,
72
- node: child,
73
- }),
74
- props.context.transformer,
75
- );
76
-
77
- const transformNode = (props: {
78
- context: ISdkOperationTransformerContext;
79
- imports: Singleton<IReflectImport[]>;
80
- visitor: IVisitor;
81
- node: ts.Node;
82
- }): ts.Node => {
83
- return ts.isClassDeclaration(props.node)
84
- ? transformClass({
85
- ...props,
86
- node: props.node,
87
- })
88
- : props.node;
89
- };
90
-
91
- const transformClass = (props: {
92
- context: ISdkOperationTransformerContext;
93
- visitor: IVisitor;
94
- imports: Singleton<IReflectImport[]>;
95
- node: ts.ClassDeclaration;
96
- }): ts.ClassDeclaration => {
97
- // TO AVOID COMMENT COMPILATION BUG
98
- const symbolDict: Map<string, ts.Symbol> = new Map();
99
- const classType: ts.InterfaceType = props.context.checker.getTypeAtLocation(
100
- props.node,
101
- ) as ts.InterfaceType;
102
- for (const symbol of classType.getProperties()) {
103
- const declaration: ts.Declaration | undefined = (symbol.declarations ||
104
- [])[0];
105
- if (!declaration || !ts.isMethodDeclaration(declaration)) continue;
106
- const identifier = declaration.name;
107
- if (!ts.isIdentifier(identifier)) continue;
108
- symbolDict.set(identifier.escapedText.toString(), symbol);
109
- }
110
- return ts.factory.updateClassDeclaration(
111
- props.node,
112
- props.node.modifiers,
113
- props.node.name,
114
- props.node.typeParameters,
115
- props.node.heritageClauses,
116
- props.node.members.map((m) =>
117
- ts.isMethodDeclaration(m)
118
- ? transformMethod({
119
- ...props,
120
- class: props.node,
121
- node: m,
122
- symbol: symbolDict.get(m.name.getText()),
123
- })
124
- : m,
125
- ),
126
- );
127
- };
128
-
129
- const transformMethod = (props: {
130
- context: ISdkOperationTransformerContext;
131
- visitor: IVisitor;
132
- imports: Singleton<IReflectImport[]>;
133
- class: ts.ClassDeclaration;
134
- node: ts.MethodDeclaration;
135
- symbol: ts.Symbol | undefined;
136
- }): ts.MethodDeclaration => {
137
- const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
138
- ? ts.getDecorators(props.node)
139
- : (props.node as any).decorators;
140
- if (!decorators?.length) return props.node;
141
-
142
- const key: MethodKey = new MethodKey(
143
- props.class.name?.getText() ?? "",
144
- props.node.name.getText(),
145
- );
146
- props.visitor.done ||= true;
147
- if (props.visitor.visited.has(key)) return props.node;
148
- else props.visitor.visited.insert(key);
149
-
150
- const metadata: IOperationMetadata = SdkOperationProgrammer.write({
151
- ...props,
152
- exceptions: getExceptionTypes({
153
- checker: props.context.checker,
154
- decorators,
155
- }),
156
- });
157
- return ts.factory.updateMethodDeclaration(
158
- props.node,
159
- [
160
- ...(props.node.modifiers ?? []),
161
- ts.factory.createDecorator(
162
- ts.factory.createCallExpression(
163
- ts.factory.createIdentifier(
164
- "__OperationMetadata.OperationMetadata",
165
- ),
166
- undefined,
167
- [
168
- ts.factory.createAsExpression(
169
- LiteralFactory.write(metadata),
170
- TypeFactory.keyword("any"),
171
- ),
172
- ],
173
- ),
174
- ),
175
- ],
176
- props.node.asteriskToken,
177
- props.node.name,
178
- props.node.questionToken,
179
- props.node.typeParameters,
180
- props.node.parameters,
181
- props.node.type,
182
- props.node.body,
183
- );
184
- };
185
-
186
- const getExceptionTypes = (props: {
187
- checker: ts.TypeChecker;
188
- decorators: readonly ts.Decorator[];
189
- }) =>
190
- props.decorators
191
- .map((deco) => {
192
- if (false === ts.isCallExpression(deco.expression)) return null;
193
-
194
- const signature: ts.Signature | undefined =
195
- props.checker.getResolvedSignature(deco.expression);
196
- if (signature === undefined) return null;
197
- else if (!signature.declaration) return null;
198
-
199
- const location: string = path.resolve(
200
- signature.declaration.getSourceFile()?.fileName ?? "",
201
- );
202
- if (
203
- location.includes(TYPED_EXCEPTION_LIB_PATH) === false &&
204
- location.includes(TYPED_EXCEPTION_MONO_PATH) === false
205
- )
206
- return null;
207
- else if (deco.expression.typeArguments?.length !== 1) return null;
208
- return deco.expression.typeArguments[0]!;
209
- })
210
- .filter((t) => t !== null);
211
- }
212
-
213
- class MethodKey {
214
- public constructor(
215
- public readonly className: string,
216
- public readonly methodName: string,
217
- ) {}
218
-
219
- public equals(o: MethodKey): boolean {
220
- return this.className === o.className && this.methodName === o.methodName;
221
- }
222
-
223
- public hashCode(): number {
224
- return hash(this.className, this.methodName);
225
- }
226
- }
227
-
228
- const TYPED_EXCEPTION_LIB_PATH = path.join(
229
- "@nestia",
230
- "core",
231
- "lib",
232
- "decorators",
233
- `TypedException.d.ts`,
234
- );
235
- const TYPED_EXCEPTION_MONO_PATH = path.join(
236
- "packages",
237
- "core",
238
- "src",
239
- "decorators",
240
- `TypedException.ts`,
241
- );
242
-
243
- const collection = new Singleton(
244
- () =>
245
- new MetadataCollection({
246
- replace: MetadataCollection.replace,
247
- }),
248
- );
1
+ import { LiteralFactory, MetadataCollection, TypeFactory } from "@typia/core";
2
+ import path from "path";
3
+ import { HashSet, Singleton, hash } from "tstl";
4
+ import ts from "typescript";
5
+
6
+ import { ImportAnalyzer } from "../analyses/ImportAnalyzer";
7
+ import { IReflectImport } from "../structures/IReflectImport";
8
+ import { IOperationMetadata } from "./IOperationMetadata";
9
+ import { ISdkOperationTransformerContext } from "./ISdkOperationTransformerContext";
10
+ import { SdkOperationProgrammer } from "./SdkOperationProgrammer";
11
+
12
+ export namespace SdkOperationTransformer {
13
+ export const iterateFile =
14
+ (checker: ts.TypeChecker) => (api: ts.TransformationContext) => {
15
+ const context: ISdkOperationTransformerContext = {
16
+ checker,
17
+ transformer: api,
18
+ collection: collection.get(),
19
+ };
20
+ return (file: ts.SourceFile): ts.SourceFile => {
21
+ if (file.isDeclarationFile === true) return file;
22
+ const visitor: IVisitor = {
23
+ done: false,
24
+ visited: new HashSet(),
25
+ };
26
+ file = ts.visitEachChild(
27
+ file,
28
+ (node) =>
29
+ iterateNode({
30
+ context,
31
+ imports: new Singleton(() => ImportAnalyzer.analyze(file)),
32
+ visitor,
33
+ node,
34
+ }),
35
+ api,
36
+ );
37
+ if (visitor.done === false) return file;
38
+ return ts.factory.updateSourceFile(file, [
39
+ ts.factory.createImportDeclaration(
40
+ undefined,
41
+ ts.factory.createImportClause(
42
+ false,
43
+ undefined,
44
+ ts.factory.createNamespaceImport(
45
+ ts.factory.createIdentifier("__OperationMetadata"),
46
+ ),
47
+ ),
48
+ ts.factory.createStringLiteral("@nestia/sdk"),
49
+ undefined,
50
+ ),
51
+ ...file.statements,
52
+ ]);
53
+ };
54
+ };
55
+
56
+ interface IVisitor {
57
+ done: boolean;
58
+ visited: HashSet<MethodKey>;
59
+ }
60
+
61
+ const iterateNode = (props: {
62
+ context: ISdkOperationTransformerContext;
63
+ imports: Singleton<IReflectImport[]>;
64
+ visitor: IVisitor;
65
+ node: ts.Node;
66
+ }): ts.Node =>
67
+ ts.visitEachChild(
68
+ transformNode(props),
69
+ (child) =>
70
+ iterateNode({
71
+ ...props,
72
+ node: child,
73
+ }),
74
+ props.context.transformer,
75
+ );
76
+
77
+ const transformNode = (props: {
78
+ context: ISdkOperationTransformerContext;
79
+ imports: Singleton<IReflectImport[]>;
80
+ visitor: IVisitor;
81
+ node: ts.Node;
82
+ }): ts.Node => {
83
+ return ts.isClassDeclaration(props.node)
84
+ ? transformClass({
85
+ ...props,
86
+ node: props.node,
87
+ })
88
+ : props.node;
89
+ };
90
+
91
+ const transformClass = (props: {
92
+ context: ISdkOperationTransformerContext;
93
+ visitor: IVisitor;
94
+ imports: Singleton<IReflectImport[]>;
95
+ node: ts.ClassDeclaration;
96
+ }): ts.ClassDeclaration => {
97
+ // TO AVOID COMMENT COMPILATION BUG
98
+ const symbolDict: Map<string, ts.Symbol> = new Map();
99
+ const classType: ts.InterfaceType = props.context.checker.getTypeAtLocation(
100
+ props.node,
101
+ ) as ts.InterfaceType;
102
+ for (const symbol of classType.getProperties()) {
103
+ const declaration: ts.Declaration | undefined = (symbol.declarations ||
104
+ [])[0];
105
+ if (!declaration || !ts.isMethodDeclaration(declaration)) continue;
106
+ const identifier = declaration.name;
107
+ if (!ts.isIdentifier(identifier)) continue;
108
+ symbolDict.set(identifier.escapedText.toString(), symbol);
109
+ }
110
+ return ts.factory.updateClassDeclaration(
111
+ props.node,
112
+ props.node.modifiers,
113
+ props.node.name,
114
+ props.node.typeParameters,
115
+ props.node.heritageClauses,
116
+ props.node.members.map((m) =>
117
+ ts.isMethodDeclaration(m)
118
+ ? transformMethod({
119
+ ...props,
120
+ class: props.node,
121
+ node: m,
122
+ symbol: symbolDict.get(m.name.getText()),
123
+ })
124
+ : m,
125
+ ),
126
+ );
127
+ };
128
+
129
+ const transformMethod = (props: {
130
+ context: ISdkOperationTransformerContext;
131
+ visitor: IVisitor;
132
+ imports: Singleton<IReflectImport[]>;
133
+ class: ts.ClassDeclaration;
134
+ node: ts.MethodDeclaration;
135
+ symbol: ts.Symbol | undefined;
136
+ }): ts.MethodDeclaration => {
137
+ const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
138
+ ? ts.getDecorators(props.node)
139
+ : (props.node as any).decorators;
140
+ if (!decorators?.length) return props.node;
141
+
142
+ const key: MethodKey = new MethodKey(
143
+ props.class.name?.getText() ?? "",
144
+ props.node.name.getText(),
145
+ );
146
+ props.visitor.done ||= true;
147
+ if (props.visitor.visited.has(key)) return props.node;
148
+ else props.visitor.visited.insert(key);
149
+
150
+ const metadata: IOperationMetadata = SdkOperationProgrammer.write({
151
+ ...props,
152
+ exceptions: getExceptionTypes({
153
+ checker: props.context.checker,
154
+ decorators,
155
+ }),
156
+ });
157
+ return ts.factory.updateMethodDeclaration(
158
+ props.node,
159
+ [
160
+ ...(props.node.modifiers ?? []),
161
+ ts.factory.createDecorator(
162
+ ts.factory.createCallExpression(
163
+ ts.factory.createIdentifier(
164
+ "__OperationMetadata.OperationMetadata",
165
+ ),
166
+ undefined,
167
+ [
168
+ ts.factory.createAsExpression(
169
+ LiteralFactory.write(metadata),
170
+ TypeFactory.keyword("any"),
171
+ ),
172
+ ],
173
+ ),
174
+ ),
175
+ ],
176
+ props.node.asteriskToken,
177
+ props.node.name,
178
+ props.node.questionToken,
179
+ props.node.typeParameters,
180
+ props.node.parameters,
181
+ props.node.type,
182
+ props.node.body,
183
+ );
184
+ };
185
+
186
+ const getExceptionTypes = (props: {
187
+ checker: ts.TypeChecker;
188
+ decorators: readonly ts.Decorator[];
189
+ }) =>
190
+ props.decorators
191
+ .map((deco) => {
192
+ if (false === ts.isCallExpression(deco.expression)) return null;
193
+
194
+ const signature: ts.Signature | undefined =
195
+ props.checker.getResolvedSignature(deco.expression);
196
+ if (signature === undefined) return null;
197
+ else if (!signature.declaration) return null;
198
+
199
+ const location: string = path.resolve(
200
+ signature.declaration.getSourceFile()?.fileName ?? "",
201
+ );
202
+ if (
203
+ location.includes(TYPED_EXCEPTION_LIB_PATH) === false &&
204
+ location.includes(TYPED_EXCEPTION_MONO_PATH) === false
205
+ )
206
+ return null;
207
+ else if (deco.expression.typeArguments?.length !== 1) return null;
208
+ return deco.expression.typeArguments[0]!;
209
+ })
210
+ .filter((t) => t !== null);
211
+ }
212
+
213
+ class MethodKey {
214
+ public constructor(
215
+ public readonly className: string,
216
+ public readonly methodName: string,
217
+ ) {}
218
+
219
+ public equals(o: MethodKey): boolean {
220
+ return this.className === o.className && this.methodName === o.methodName;
221
+ }
222
+
223
+ public hashCode(): number {
224
+ return hash(this.className, this.methodName);
225
+ }
226
+ }
227
+
228
+ const TYPED_EXCEPTION_LIB_PATH = path.join(
229
+ "@nestia",
230
+ "core",
231
+ "lib",
232
+ "decorators",
233
+ `TypedException.d.ts`,
234
+ );
235
+ const TYPED_EXCEPTION_MONO_PATH = path.join(
236
+ "packages",
237
+ "core",
238
+ "src",
239
+ "decorators",
240
+ `TypedException.ts`,
241
+ );
242
+
243
+ const collection = new Singleton(
244
+ () =>
245
+ new MetadataCollection({
246
+ replace: MetadataCollection.replace,
247
+ }),
248
+ );
@@ -1,17 +1,17 @@
1
- import { MetadataSchema } from "@typia/core";
2
-
3
- export namespace TextPlainValidator {
4
- export const validate = (props: { metadata: MetadataSchema }): string[] => {
5
- const expected: number =
6
- props.metadata.atomics.filter((a) => a.type === "string").length +
7
- props.metadata.constants
8
- .filter((c) => c.type === "string")
9
- .map((c) => c.values.length)
10
- .reduce((a, b) => a + b, 0) +
11
- props.metadata.templates.length +
12
- props.metadata.natives.filter((n) => n.name === "String").length;
13
- if (props.metadata.size() === 0 || props.metadata.size() !== expected)
14
- return [`Only string type is allowed in the "text/plain" content type.`];
15
- return [];
16
- };
17
- }
1
+ import { MetadataSchema } from "@typia/core";
2
+
3
+ export namespace TextPlainValidator {
4
+ export const validate = (props: { metadata: MetadataSchema }): string[] => {
5
+ const expected: number =
6
+ props.metadata.atomics.filter((a) => a.type === "string").length +
7
+ props.metadata.constants
8
+ .filter((c) => c.type === "string")
9
+ .map((c) => c.values.length)
10
+ .reduce((a, b) => a + b, 0) +
11
+ props.metadata.templates.length +
12
+ props.metadata.natives.filter((n) => n.name === "String").length;
13
+ if (props.metadata.size() === 0 || props.metadata.size() !== expected)
14
+ return [`Only string type is allowed in the "text/plain" content type.`];
15
+ return [];
16
+ };
17
+ }
@@ -1,26 +1,26 @@
1
- import { MetadataSchema } from "@typia/core";
2
-
3
- export namespace MetadataUtil {
4
- export const visit = (closure: (m: MetadataSchema) => unknown) => {
5
- const visited: WeakSet<MetadataSchema> = new WeakSet();
6
- const iterate = (metadata: MetadataSchema): void => {
7
- if (visited.has(metadata)) return;
8
- visited.add(metadata);
9
- closure(metadata);
10
- for (const alias of metadata.aliases) iterate(alias.type.value);
11
- for (const array of metadata.arrays) iterate(array.type.value);
12
- for (const tuple of metadata.tuples) tuple.type.elements.map(iterate);
13
- for (const object of metadata.objects)
14
- object.type.properties.forEach((p) => {
15
- iterate(p.key);
16
- iterate(p.value);
17
- });
18
- if (metadata.escaped) {
19
- iterate(metadata.escaped.original);
20
- iterate(metadata.escaped.returns);
21
- }
22
- if (metadata.rest) iterate(metadata.rest);
23
- };
24
- return iterate;
25
- };
26
- }
1
+ import { MetadataSchema } from "@typia/core";
2
+
3
+ export namespace MetadataUtil {
4
+ export const visit = (closure: (m: MetadataSchema) => unknown) => {
5
+ const visited: WeakSet<MetadataSchema> = new WeakSet();
6
+ const iterate = (metadata: MetadataSchema): void => {
7
+ if (visited.has(metadata)) return;
8
+ visited.add(metadata);
9
+ closure(metadata);
10
+ for (const alias of metadata.aliases) iterate(alias.type.value);
11
+ for (const array of metadata.arrays) iterate(array.type.value);
12
+ for (const tuple of metadata.tuples) tuple.type.elements.map(iterate);
13
+ for (const object of metadata.objects)
14
+ object.type.properties.forEach((p) => {
15
+ iterate(p.key);
16
+ iterate(p.value);
17
+ });
18
+ if (metadata.escaped) {
19
+ iterate(metadata.escaped.original);
20
+ iterate(metadata.escaped.returns);
21
+ }
22
+ if (metadata.rest) iterate(metadata.rest);
23
+ };
24
+ return iterate;
25
+ };
26
+ }
@@ -1,40 +1,40 @@
1
- import {
2
- MetadataArrayType,
3
- MetadataFactory,
4
- MetadataSchema,
5
- } from "@typia/core";
6
-
7
- export namespace HttpHeadersValidator {
8
- export const validate = (props: {
9
- metadata: MetadataSchema;
10
- explore: MetadataFactory.IExplore;
11
- }): string[] => {
12
- const errors: string[] = [];
13
- const insert = (msg: string) => errors.push(msg);
14
-
15
- if (props.explore.top === true) {
16
- const expected: number =
17
- props.metadata.atomics.length +
18
- props.metadata.templates.length +
19
- props.metadata.constants
20
- .map((c) => c.values.length)
21
- .reduce((a, b) => a + b, 0) +
22
- props.metadata.arrays.length;
23
- if (props.metadata.size() !== expected)
24
- insert("Only atomic or array of atomic types are allowed.");
25
- } else if (
26
- props.explore.nested !== null &&
27
- props.explore.nested instanceof MetadataArrayType
28
- ) {
29
- const expected: number =
30
- props.metadata.atomics.length +
31
- props.metadata.templates.length +
32
- props.metadata.constants
33
- .map((c) => c.values.length)
34
- .reduce((a, b) => a + b, 0);
35
- if (props.metadata.size() !== expected)
36
- insert("Only atomic types are allowed in array.");
37
- }
38
- return errors;
39
- };
40
- }
1
+ import {
2
+ MetadataArrayType,
3
+ MetadataFactory,
4
+ MetadataSchema,
5
+ } from "@typia/core";
6
+
7
+ export namespace HttpHeadersValidator {
8
+ export const validate = (props: {
9
+ metadata: MetadataSchema;
10
+ explore: MetadataFactory.IExplore;
11
+ }): string[] => {
12
+ const errors: string[] = [];
13
+ const insert = (msg: string) => errors.push(msg);
14
+
15
+ if (props.explore.top === true) {
16
+ const expected: number =
17
+ props.metadata.atomics.length +
18
+ props.metadata.templates.length +
19
+ props.metadata.constants
20
+ .map((c) => c.values.length)
21
+ .reduce((a, b) => a + b, 0) +
22
+ props.metadata.arrays.length;
23
+ if (props.metadata.size() !== expected)
24
+ insert("Only atomic or array of atomic types are allowed.");
25
+ } else if (
26
+ props.explore.nested !== null &&
27
+ props.explore.nested instanceof MetadataArrayType
28
+ ) {
29
+ const expected: number =
30
+ props.metadata.atomics.length +
31
+ props.metadata.templates.length +
32
+ props.metadata.constants
33
+ .map((c) => c.values.length)
34
+ .reduce((a, b) => a + b, 0);
35
+ if (props.metadata.size() !== expected)
36
+ insert("Only atomic types are allowed in array.");
37
+ }
38
+ return errors;
39
+ };
40
+ }