@nestia/sdk 2.6.3-dev.20240328 → 2.6.4-dev.20240401

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 (45) hide show
  1. package/lib/INestiaConfig.d.ts +14 -2
  2. package/lib/executable/internal/NestiaConfigLoader.js +31 -5
  3. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  4. package/lib/generates/SwaggerGenerator.d.ts +2 -0
  5. package/lib/generates/SwaggerGenerator.js +19 -3
  6. package/lib/generates/SwaggerGenerator.js.map +1 -1
  7. package/lib/structures/ISwagger.d.ts +5 -28
  8. package/lib/structures/ISwaggerServer.d.ts +15 -0
  9. package/lib/structures/ISwaggerServer.js +3 -0
  10. package/lib/structures/ISwaggerServer.js.map +1 -0
  11. package/lib/structures/ISwaggerTag.d.ts +9 -0
  12. package/lib/structures/ISwaggerTag.js +3 -0
  13. package/lib/structures/ISwaggerTag.js.map +1 -0
  14. package/package.json +3 -3
  15. package/src/INestiaConfig.ts +261 -248
  16. package/src/NestiaSdkApplication.ts +255 -255
  17. package/src/analyses/ExceptionAnalyzer.ts +148 -148
  18. package/src/analyses/ImportAnalyzer.ts +137 -137
  19. package/src/analyses/SecurityAnalyzer.ts +24 -24
  20. package/src/generates/CloneGenerator.ts +62 -62
  21. package/src/generates/E2eGenerator.ts +66 -66
  22. package/src/generates/SdkGenerator.ts +84 -84
  23. package/src/generates/SwaggerGenerator.ts +23 -3
  24. package/src/generates/internal/E2eFileProgrammer.ts +182 -182
  25. package/src/generates/internal/FilePrinter.ts +53 -53
  26. package/src/generates/internal/SdkAliasCollection.ts +152 -152
  27. package/src/generates/internal/SdkCloneProgrammer.ts +155 -155
  28. package/src/generates/internal/SdkFileProgrammer.ts +115 -115
  29. package/src/generates/internal/SdkFunctionProgrammer.ts +298 -298
  30. package/src/generates/internal/SdkImportWizard.ts +55 -55
  31. package/src/generates/internal/SdkNamespaceProgrammer.ts +510 -510
  32. package/src/generates/internal/SdkRouteProgrammer.ts +83 -83
  33. package/src/generates/internal/SdkSimulationProgrammer.ts +365 -365
  34. package/src/generates/internal/SdkTypeProgrammer.ts +385 -385
  35. package/src/generates/internal/SwaggerSchemaGenerator.ts +438 -438
  36. package/src/structures/IController.ts +94 -94
  37. package/src/structures/IRoute.ts +53 -53
  38. package/src/structures/ISwagger.ts +66 -91
  39. package/src/structures/ISwaggerRoute.ts +54 -54
  40. package/src/structures/ISwaggerSecurityScheme.ts +65 -65
  41. package/src/structures/ISwaggerServer.ts +16 -0
  42. package/src/structures/ISwaggerTag.ts +9 -0
  43. package/src/structures/ParamCategory.ts +1 -1
  44. package/src/structures/TypeEntry.ts +22 -22
  45. package/src/utils/StringUtil.ts +6 -6
@@ -1,148 +1,148 @@
1
- import path from "path";
2
- import ts from "typescript";
3
- import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
4
- import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
5
- import { Metadata } from "typia/lib/schemas/metadata/Metadata";
6
-
7
- import { IController } from "../structures/IController";
8
- import { INestiaProject } from "../structures/INestiaProject";
9
- import { IRoute } from "../structures/IRoute";
10
- import { ITypeTuple } from "../structures/ITypeTuple";
11
- import { GenericAnalyzer } from "./GenericAnalyzer";
12
- import { ImportAnalyzer } from "./ImportAnalyzer";
13
-
14
- export namespace ExceptionAnalyzer {
15
- export const analyze =
16
- (project: INestiaProject) =>
17
- (
18
- genericDict: GenericAnalyzer.Dictionary,
19
- importDict: ImportAnalyzer.Dictionary,
20
- ) =>
21
- (controller: IController, func: IController.IFunction) =>
22
- (
23
- declaration: ts.MethodDeclaration,
24
- ): Record<number | "2XX" | "3XX" | "4XX" | "5XX", IRoute.IOutput> => {
25
- const output: Record<
26
- number | "2XX" | "3XX" | "4XX" | "5XX",
27
- IRoute.IOutput
28
- > = {} as any;
29
- for (const decorator of declaration.modifiers ?? [])
30
- if (ts.isDecorator(decorator))
31
- analyzeTyped(project)(genericDict, importDict)(controller, func)(
32
- output,
33
- )(decorator);
34
- return output;
35
- };
36
-
37
- const analyzeTyped =
38
- (project: INestiaProject) =>
39
- (
40
- genericDict: GenericAnalyzer.Dictionary,
41
- importDict: ImportAnalyzer.Dictionary,
42
- ) =>
43
- (controller: IController, func: IController.IFunction) =>
44
- (output: Record<number | "2XX" | "3XX" | "4XX" | "5XX", IRoute.IOutput>) =>
45
- (decorator: ts.Decorator): boolean => {
46
- // CHECK DECORATOR
47
- if (!ts.isCallExpression(decorator.expression)) return false;
48
- else if ((decorator.expression.typeArguments ?? []).length !== 1)
49
- return false;
50
-
51
- // CHECK SIGNATURE
52
- const signature: ts.Signature | undefined =
53
- project.checker.getResolvedSignature(decorator.expression);
54
- if (!signature || !signature.declaration) return false;
55
- else if (
56
- path
57
- .resolve(signature.declaration.getSourceFile().fileName)
58
- .indexOf(TYPED_EXCEPTION_PATH) === -1
59
- )
60
- return false;
61
-
62
- // GET TYPE INFO
63
- const status: string | null = getStatus(project.checker)(
64
- decorator.expression.arguments[0] ?? null,
65
- );
66
- if (status === null) return false;
67
-
68
- const node: ts.TypeNode = decorator.expression.typeArguments![0];
69
- const type: ts.Type = project.checker.getTypeFromTypeNode(node);
70
- if (type.isTypeParameter()) {
71
- project.errors.push({
72
- file: controller.file,
73
- controller: controller.name,
74
- function: func.name,
75
- message: "TypedException() without generic argument specification.",
76
- });
77
- return false;
78
- }
79
-
80
- const tuple: ITypeTuple | null = ImportAnalyzer.analyze(
81
- project.checker,
82
- genericDict,
83
- importDict,
84
- type,
85
- );
86
- if (
87
- tuple === null ||
88
- (project.config.clone !== true &&
89
- (tuple.typeName === "__type" || tuple.typeName === "__object"))
90
- ) {
91
- project.errors.push({
92
- file: controller.file,
93
- controller: controller.name,
94
- function: func.name,
95
- message: "TypeException() with implicit (unnamed) type.",
96
- });
97
- return false;
98
- }
99
-
100
- // DO ASSIGN
101
- const matched: IController.IException[] = Object.entries(func.exceptions)
102
- .filter(([key]) => status === key)
103
- .map(([_key, value]) => value);
104
- for (const m of matched)
105
- output[m.status] = {
106
- type: tuple.type,
107
- typeName: tuple.typeName,
108
- contentType: "application/json",
109
- description: m.description,
110
- };
111
- return true;
112
- };
113
-
114
- const getStatus =
115
- (checker: ts.TypeChecker) =>
116
- (expression: ts.Expression | null): string | null => {
117
- if (expression === null) return null;
118
-
119
- const type: ts.Type = checker.getTypeAtLocation(expression);
120
- const result = MetadataFactory.analyze(checker)({
121
- escape: true,
122
- constant: true,
123
- absorb: true,
124
- })(new MetadataCollection())(type);
125
- if (false === result.success) return null;
126
-
127
- const meta: Metadata = result.data;
128
- if (meta.constants.length === 1)
129
- return meta.constants[0].values[0].toString();
130
- else if (meta.escaped && meta.escaped.returns.constants.length === 1)
131
- return meta.escaped.returns.constants[0].values[0].toString();
132
- else if (ts.isStringLiteral(expression)) return expression.text;
133
- else if (ts.isNumericLiteral(expression)) {
134
- const value: number = Number(expression.text.split("_").join(""));
135
- if (false === isNaN(value)) return value.toString();
136
- }
137
- return null;
138
- };
139
- }
140
-
141
- const TYPED_EXCEPTION_PATH = path.join(
142
- "node_modules",
143
- "@nestia",
144
- "core",
145
- "lib",
146
- "decorators",
147
- "TypedException.d.ts",
148
- );
1
+ import path from "path";
2
+ import ts from "typescript";
3
+ import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
4
+ import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
5
+ import { Metadata } from "typia/lib/schemas/metadata/Metadata";
6
+
7
+ import { IController } from "../structures/IController";
8
+ import { INestiaProject } from "../structures/INestiaProject";
9
+ import { IRoute } from "../structures/IRoute";
10
+ import { ITypeTuple } from "../structures/ITypeTuple";
11
+ import { GenericAnalyzer } from "./GenericAnalyzer";
12
+ import { ImportAnalyzer } from "./ImportAnalyzer";
13
+
14
+ export namespace ExceptionAnalyzer {
15
+ export const analyze =
16
+ (project: INestiaProject) =>
17
+ (
18
+ genericDict: GenericAnalyzer.Dictionary,
19
+ importDict: ImportAnalyzer.Dictionary,
20
+ ) =>
21
+ (controller: IController, func: IController.IFunction) =>
22
+ (
23
+ declaration: ts.MethodDeclaration,
24
+ ): Record<number | "2XX" | "3XX" | "4XX" | "5XX", IRoute.IOutput> => {
25
+ const output: Record<
26
+ number | "2XX" | "3XX" | "4XX" | "5XX",
27
+ IRoute.IOutput
28
+ > = {} as any;
29
+ for (const decorator of declaration.modifiers ?? [])
30
+ if (ts.isDecorator(decorator))
31
+ analyzeTyped(project)(genericDict, importDict)(controller, func)(
32
+ output,
33
+ )(decorator);
34
+ return output;
35
+ };
36
+
37
+ const analyzeTyped =
38
+ (project: INestiaProject) =>
39
+ (
40
+ genericDict: GenericAnalyzer.Dictionary,
41
+ importDict: ImportAnalyzer.Dictionary,
42
+ ) =>
43
+ (controller: IController, func: IController.IFunction) =>
44
+ (output: Record<number | "2XX" | "3XX" | "4XX" | "5XX", IRoute.IOutput>) =>
45
+ (decorator: ts.Decorator): boolean => {
46
+ // CHECK DECORATOR
47
+ if (!ts.isCallExpression(decorator.expression)) return false;
48
+ else if ((decorator.expression.typeArguments ?? []).length !== 1)
49
+ return false;
50
+
51
+ // CHECK SIGNATURE
52
+ const signature: ts.Signature | undefined =
53
+ project.checker.getResolvedSignature(decorator.expression);
54
+ if (!signature || !signature.declaration) return false;
55
+ else if (
56
+ path
57
+ .resolve(signature.declaration.getSourceFile().fileName)
58
+ .indexOf(TYPED_EXCEPTION_PATH) === -1
59
+ )
60
+ return false;
61
+
62
+ // GET TYPE INFO
63
+ const status: string | null = getStatus(project.checker)(
64
+ decorator.expression.arguments[0] ?? null,
65
+ );
66
+ if (status === null) return false;
67
+
68
+ const node: ts.TypeNode = decorator.expression.typeArguments![0];
69
+ const type: ts.Type = project.checker.getTypeFromTypeNode(node);
70
+ if (type.isTypeParameter()) {
71
+ project.errors.push({
72
+ file: controller.file,
73
+ controller: controller.name,
74
+ function: func.name,
75
+ message: "TypedException() without generic argument specification.",
76
+ });
77
+ return false;
78
+ }
79
+
80
+ const tuple: ITypeTuple | null = ImportAnalyzer.analyze(
81
+ project.checker,
82
+ genericDict,
83
+ importDict,
84
+ type,
85
+ );
86
+ if (
87
+ tuple === null ||
88
+ (project.config.clone !== true &&
89
+ (tuple.typeName === "__type" || tuple.typeName === "__object"))
90
+ ) {
91
+ project.errors.push({
92
+ file: controller.file,
93
+ controller: controller.name,
94
+ function: func.name,
95
+ message: "TypeException() with implicit (unnamed) type.",
96
+ });
97
+ return false;
98
+ }
99
+
100
+ // DO ASSIGN
101
+ const matched: IController.IException[] = Object.entries(func.exceptions)
102
+ .filter(([key]) => status === key)
103
+ .map(([_key, value]) => value);
104
+ for (const m of matched)
105
+ output[m.status] = {
106
+ type: tuple.type,
107
+ typeName: tuple.typeName,
108
+ contentType: "application/json",
109
+ description: m.description,
110
+ };
111
+ return true;
112
+ };
113
+
114
+ const getStatus =
115
+ (checker: ts.TypeChecker) =>
116
+ (expression: ts.Expression | null): string | null => {
117
+ if (expression === null) return null;
118
+
119
+ const type: ts.Type = checker.getTypeAtLocation(expression);
120
+ const result = MetadataFactory.analyze(checker)({
121
+ escape: true,
122
+ constant: true,
123
+ absorb: true,
124
+ })(new MetadataCollection())(type);
125
+ if (false === result.success) return null;
126
+
127
+ const meta: Metadata = result.data;
128
+ if (meta.constants.length === 1)
129
+ return meta.constants[0].values[0].toString();
130
+ else if (meta.escaped && meta.escaped.returns.constants.length === 1)
131
+ return meta.escaped.returns.constants[0].values[0].toString();
132
+ else if (ts.isStringLiteral(expression)) return expression.text;
133
+ else if (ts.isNumericLiteral(expression)) {
134
+ const value: number = Number(expression.text.split("_").join(""));
135
+ if (false === isNaN(value)) return value.toString();
136
+ }
137
+ return null;
138
+ };
139
+ }
140
+
141
+ const TYPED_EXCEPTION_PATH = path.join(
142
+ "node_modules",
143
+ "@nestia",
144
+ "core",
145
+ "lib",
146
+ "decorators",
147
+ "TypedException.d.ts",
148
+ );
@@ -1,137 +1,137 @@
1
- import { HashMap, HashSet } from "tstl";
2
- import ts from "typescript";
3
-
4
- import { ITypeTuple } from "../structures/ITypeTuple";
5
- import { GenericAnalyzer } from "./GenericAnalyzer";
6
-
7
- export namespace ImportAnalyzer {
8
- export interface IOutput {
9
- features: [string, string[]][];
10
- alias: string;
11
- }
12
-
13
- export type Dictionary = HashMap<string, HashSet<string>>;
14
-
15
- export function analyze(
16
- checker: ts.TypeChecker,
17
- genericDict: GenericAnalyzer.Dictionary,
18
- importDict: Dictionary,
19
- type: ts.Type,
20
- ): ITypeTuple | null {
21
- type = get_type(checker, type);
22
- explore_escaped_name(checker, genericDict, importDict, type);
23
-
24
- try {
25
- return {
26
- type,
27
- typeName: explore_escaped_name(checker, genericDict, importDict, type),
28
- };
29
- } catch {
30
- return null;
31
- }
32
- }
33
-
34
- /* ---------------------------------------------------------
35
- TYPE
36
- --------------------------------------------------------- */
37
- function get_type(checker: ts.TypeChecker, type: ts.Type): ts.Type {
38
- const symbol: ts.Symbol | undefined = type.getSymbol();
39
- return symbol && get_name(symbol) === "Promise"
40
- ? escape_promise(checker, type)
41
- : type;
42
- }
43
-
44
- function escape_promise(checker: ts.TypeChecker, type: ts.Type): ts.Type {
45
- const generic: readonly ts.Type[] = checker.getTypeArguments(
46
- type as ts.TypeReference,
47
- );
48
- if (generic.length !== 1)
49
- throw new Error(
50
- "Error on ImportAnalyzer.analyze(): invalid promise type.",
51
- );
52
- return generic[0];
53
- }
54
-
55
- function get_name(symbol: ts.Symbol): string {
56
- return explore_name(
57
- symbol.escapedName.toString(),
58
- symbol.getDeclarations()?.[0]?.parent,
59
- );
60
- }
61
-
62
- /* ---------------------------------------------------------
63
- ESCAPED TEXT WITH IMPORT STATEMENTS
64
- --------------------------------------------------------- */
65
- function explore_escaped_name(
66
- checker: ts.TypeChecker,
67
- genericDict: GenericAnalyzer.Dictionary,
68
- importDict: Dictionary,
69
- type: ts.Type,
70
- ): string {
71
- //----
72
- // CONDITIONAL BRANCHES
73
- //----
74
- // DECOMPOSE GENERIC ARGUMENT
75
- while (genericDict.has(type) === true) type = genericDict.get(type)!;
76
-
77
- // PRIMITIVE
78
- const symbol: ts.Symbol | undefined = type.aliasSymbol ?? type.getSymbol();
79
-
80
- // UNION OR INTERSECT
81
- if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
82
- const joiner: string = type.isIntersection() ? " & " : " | ";
83
- return type.types
84
- .map((child) =>
85
- explore_escaped_name(checker, genericDict, importDict, child),
86
- )
87
- .join(joiner);
88
- }
89
-
90
- // NO SYMBOL
91
- else if (symbol === undefined)
92
- return checker.typeToString(
93
- type,
94
- undefined,
95
- ts.TypeFormatFlags.NoTruncation,
96
- );
97
-
98
- //----
99
- // SPECIALIZATION
100
- //----
101
- const name: string = get_name(symbol);
102
- const sourceFile: ts.SourceFile | undefined =
103
- symbol.declarations?.[0]?.getSourceFile();
104
- if (sourceFile === undefined) return name;
105
-
106
- if (sourceFile.fileName.indexOf("typescript/lib") === -1) {
107
- const set: HashSet<string> = importDict.take(
108
- sourceFile.fileName,
109
- () => new HashSet(),
110
- );
111
- set.insert(name.split(".")[0]);
112
- }
113
-
114
- // CHECK GENERIC
115
- const generic: readonly ts.Type[] = type.aliasSymbol
116
- ? type.aliasTypeArguments || []
117
- : checker.getTypeArguments(type as ts.TypeReference);
118
- return generic.length
119
- ? name === "Promise"
120
- ? explore_escaped_name(checker, genericDict, importDict, generic[0])
121
- : `${name}<${generic
122
- .map((child) =>
123
- explore_escaped_name(checker, genericDict, importDict, child),
124
- )
125
- .join(", ")}>`
126
- : name;
127
- }
128
-
129
- function explore_name(name: string, decl?: ts.Node): string {
130
- return decl && ts.isModuleBlock(decl)
131
- ? explore_name(
132
- `${decl.parent.name.getFullText().trim()}.${name}`,
133
- decl.parent.parent,
134
- )
135
- : name;
136
- }
137
- }
1
+ import { HashMap, HashSet } from "tstl";
2
+ import ts from "typescript";
3
+
4
+ import { ITypeTuple } from "../structures/ITypeTuple";
5
+ import { GenericAnalyzer } from "./GenericAnalyzer";
6
+
7
+ export namespace ImportAnalyzer {
8
+ export interface IOutput {
9
+ features: [string, string[]][];
10
+ alias: string;
11
+ }
12
+
13
+ export type Dictionary = HashMap<string, HashSet<string>>;
14
+
15
+ export function analyze(
16
+ checker: ts.TypeChecker,
17
+ genericDict: GenericAnalyzer.Dictionary,
18
+ importDict: Dictionary,
19
+ type: ts.Type,
20
+ ): ITypeTuple | null {
21
+ type = get_type(checker, type);
22
+ explore_escaped_name(checker, genericDict, importDict, type);
23
+
24
+ try {
25
+ return {
26
+ type,
27
+ typeName: explore_escaped_name(checker, genericDict, importDict, type),
28
+ };
29
+ } catch {
30
+ return null;
31
+ }
32
+ }
33
+
34
+ /* ---------------------------------------------------------
35
+ TYPE
36
+ --------------------------------------------------------- */
37
+ function get_type(checker: ts.TypeChecker, type: ts.Type): ts.Type {
38
+ const symbol: ts.Symbol | undefined = type.getSymbol();
39
+ return symbol && get_name(symbol) === "Promise"
40
+ ? escape_promise(checker, type)
41
+ : type;
42
+ }
43
+
44
+ function escape_promise(checker: ts.TypeChecker, type: ts.Type): ts.Type {
45
+ const generic: readonly ts.Type[] = checker.getTypeArguments(
46
+ type as ts.TypeReference,
47
+ );
48
+ if (generic.length !== 1)
49
+ throw new Error(
50
+ "Error on ImportAnalyzer.analyze(): invalid promise type.",
51
+ );
52
+ return generic[0];
53
+ }
54
+
55
+ function get_name(symbol: ts.Symbol): string {
56
+ return explore_name(
57
+ symbol.escapedName.toString(),
58
+ symbol.getDeclarations()?.[0]?.parent,
59
+ );
60
+ }
61
+
62
+ /* ---------------------------------------------------------
63
+ ESCAPED TEXT WITH IMPORT STATEMENTS
64
+ --------------------------------------------------------- */
65
+ function explore_escaped_name(
66
+ checker: ts.TypeChecker,
67
+ genericDict: GenericAnalyzer.Dictionary,
68
+ importDict: Dictionary,
69
+ type: ts.Type,
70
+ ): string {
71
+ //----
72
+ // CONDITIONAL BRANCHES
73
+ //----
74
+ // DECOMPOSE GENERIC ARGUMENT
75
+ while (genericDict.has(type) === true) type = genericDict.get(type)!;
76
+
77
+ // PRIMITIVE
78
+ const symbol: ts.Symbol | undefined = type.aliasSymbol ?? type.getSymbol();
79
+
80
+ // UNION OR INTERSECT
81
+ if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
82
+ const joiner: string = type.isIntersection() ? " & " : " | ";
83
+ return type.types
84
+ .map((child) =>
85
+ explore_escaped_name(checker, genericDict, importDict, child),
86
+ )
87
+ .join(joiner);
88
+ }
89
+
90
+ // NO SYMBOL
91
+ else if (symbol === undefined)
92
+ return checker.typeToString(
93
+ type,
94
+ undefined,
95
+ ts.TypeFormatFlags.NoTruncation,
96
+ );
97
+
98
+ //----
99
+ // SPECIALIZATION
100
+ //----
101
+ const name: string = get_name(symbol);
102
+ const sourceFile: ts.SourceFile | undefined =
103
+ symbol.declarations?.[0]?.getSourceFile();
104
+ if (sourceFile === undefined) return name;
105
+
106
+ if (sourceFile.fileName.indexOf("typescript/lib") === -1) {
107
+ const set: HashSet<string> = importDict.take(
108
+ sourceFile.fileName,
109
+ () => new HashSet(),
110
+ );
111
+ set.insert(name.split(".")[0]);
112
+ }
113
+
114
+ // CHECK GENERIC
115
+ const generic: readonly ts.Type[] = type.aliasSymbol
116
+ ? type.aliasTypeArguments || []
117
+ : checker.getTypeArguments(type as ts.TypeReference);
118
+ return generic.length
119
+ ? name === "Promise"
120
+ ? explore_escaped_name(checker, genericDict, importDict, generic[0])
121
+ : `${name}<${generic
122
+ .map((child) =>
123
+ explore_escaped_name(checker, genericDict, importDict, child),
124
+ )
125
+ .join(", ")}>`
126
+ : name;
127
+ }
128
+
129
+ function explore_name(name: string, decl?: ts.Node): string {
130
+ return decl && ts.isModuleBlock(decl)
131
+ ? explore_name(
132
+ `${decl.parent.name.getFullText().trim()}.${name}`,
133
+ decl.parent.parent,
134
+ )
135
+ : name;
136
+ }
137
+ }
@@ -1,24 +1,24 @@
1
- import { MapUtil } from "../utils/MapUtil";
2
-
3
- export namespace SecurityAnalyzer {
4
- const none = Symbol("none");
5
- export const merge = (...entire: Record<string, string[]>[]) => {
6
- const dict: Map<string | typeof none, Set<string>> = new Map();
7
- for (const obj of entire) {
8
- const entries = Object.entries(obj);
9
- for (const [key, value] of entries) {
10
- const set = MapUtil.take(dict, key, () => new Set());
11
- for (const val of value) set.add(val);
12
- }
13
- if (entries.length === 0) MapUtil.take(dict, none, () => new Set());
14
- }
15
- const output: Record<string, string[]>[] = [];
16
- for (const [key, set] of dict)
17
- key === none
18
- ? output.push({})
19
- : output.push({
20
- [key]: [...set],
21
- });
22
- return output;
23
- };
24
- }
1
+ import { MapUtil } from "../utils/MapUtil";
2
+
3
+ export namespace SecurityAnalyzer {
4
+ const none = Symbol("none");
5
+ export const merge = (...entire: Record<string, string[]>[]) => {
6
+ const dict: Map<string | typeof none, Set<string>> = new Map();
7
+ for (const obj of entire) {
8
+ const entries = Object.entries(obj);
9
+ for (const [key, value] of entries) {
10
+ const set = MapUtil.take(dict, key, () => new Set());
11
+ for (const val of value) set.add(val);
12
+ }
13
+ if (entries.length === 0) MapUtil.take(dict, none, () => new Set());
14
+ }
15
+ const output: Record<string, string[]>[] = [];
16
+ for (const [key, set] of dict)
17
+ key === none
18
+ ? output.push({})
19
+ : output.push({
20
+ [key]: [...set],
21
+ });
22
+ return output;
23
+ };
24
+ }