@nestia/sdk 3.1.0-dev.20240429 → 3.1.0-dev.20240430
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.
- package/lib/analyses/TypedWebSocketOperationAnalyzer.js +1 -1
- package/lib/analyses/TypedWebSocketOperationAnalyzer.js.map +1 -1
- package/lib/executable/sdk.js +11 -11
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js +18 -20
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +30 -1
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
- package/lib/structures/ITypedWebSocketRoute.d.ts +1 -0
- package/package.json +3 -3
- package/src/NestiaSdkApplication.ts +257 -257
- package/src/analyses/AccessorAnalyzer.ts +67 -67
- package/src/analyses/ConfigAnalyzer.ts +147 -147
- package/src/analyses/GenericAnalyzer.ts +51 -51
- package/src/analyses/PathAnalyzer.ts +69 -69
- package/src/analyses/SecurityAnalyzer.ts +25 -25
- package/src/analyses/TypedWebSocketOperationAnalyzer.ts +1 -0
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/executable/internal/NestiaConfigLoader.ts +67 -67
- package/src/executable/internal/NestiaSdkCommand.ts +60 -60
- package/src/executable/sdk.ts +73 -73
- package/src/generates/CloneGenerator.ts +64 -64
- package/src/generates/E2eGenerator.ts +64 -64
- package/src/generates/SdkGenerator.ts +91 -91
- package/src/generates/internal/E2eFileProgrammer.ts +178 -178
- package/src/generates/internal/FilePrinter.ts +53 -53
- package/src/generates/internal/SdkAliasCollection.ts +157 -157
- package/src/generates/internal/SdkDistributionComposer.ts +100 -100
- package/src/generates/internal/SdkFileProgrammer.ts +119 -119
- package/src/generates/internal/SdkHttpCloneProgrammer.ts +154 -154
- package/src/generates/internal/SdkHttpFunctionProgrammer.ts +298 -299
- package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +505 -505
- package/src/generates/internal/SdkHttpRouteProgrammer.ts +82 -82
- package/src/generates/internal/SdkHttpSimulationProgrammer.ts +363 -363
- package/src/generates/internal/SdkImportWizard.ts +55 -55
- package/src/generates/internal/SdkRouteDirectory.ts +18 -18
- package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +42 -1
- package/src/generates/internal/SwaggerSchemaValidator.ts +198 -198
- package/src/index.ts +4 -4
- package/src/module.ts +2 -2
- package/src/structures/IErrorReport.ts +6 -6
- package/src/structures/INestiaProject.ts +13 -13
- package/src/structures/INormalizedInput.ts +20 -20
- package/src/structures/IReflectController.ts +17 -17
- package/src/structures/ITypeTuple.ts +6 -6
- package/src/structures/ITypedHttpRoute.ts +55 -55
- package/src/structures/ITypedWebSocketRoute.ts +1 -0
- package/src/structures/MethodType.ts +5 -5
- package/src/structures/ParamCategory.ts +1 -1
- package/src/utils/ArrayUtil.ts +26 -26
- package/src/utils/FileRetriever.ts +22 -22
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PathUtil.ts +10 -10
- package/src/utils/SourceFinder.ts +66 -66
- package/src/utils/StringUtil.ts +6 -6
- package/src/utils/StripEnums.ts +5 -5
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
import { INestApplication, VersioningType } from "@nestjs/common";
|
|
2
|
-
import { MODULE_PATH } from "@nestjs/common/constants";
|
|
3
|
-
import { NestContainer } from "@nestjs/core";
|
|
4
|
-
import { Module } from "@nestjs/core/injector/module";
|
|
5
|
-
import fs from "fs";
|
|
6
|
-
import path from "path";
|
|
7
|
-
import { HashMap, Pair, Singleton } from "tstl";
|
|
8
|
-
|
|
9
|
-
import { INestiaConfig } from "../INestiaConfig";
|
|
10
|
-
import { SdkGenerator } from "../generates/SdkGenerator";
|
|
11
|
-
import { INormalizedInput } from "../structures/INormalizedInput";
|
|
12
|
-
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
13
|
-
import { MapUtil } from "../utils/MapUtil";
|
|
14
|
-
import { SourceFinder } from "../utils/SourceFinder";
|
|
15
|
-
|
|
16
|
-
export namespace ConfigAnalyzer {
|
|
17
|
-
export const input = (config: INestiaConfig): Promise<INormalizedInput> =>
|
|
18
|
-
MapUtil.take(memory, config, async () => {
|
|
19
|
-
const input = config.input;
|
|
20
|
-
if (Array.isArray(input)) return transform_input(config)(input);
|
|
21
|
-
else if (typeof input === "function")
|
|
22
|
-
return analyze_application(await input());
|
|
23
|
-
else if (typeof input === "object")
|
|
24
|
-
if (input === null)
|
|
25
|
-
throw new Error("Invalid input config. It can't be null.");
|
|
26
|
-
else return transform_input(config)(input.include, input.exclude);
|
|
27
|
-
else if (typeof input === "string")
|
|
28
|
-
return transform_input(config)([input]);
|
|
29
|
-
else throw new Error("Invalid input config.");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const analyze_application = async (
|
|
33
|
-
app: INestApplication,
|
|
34
|
-
): Promise<INormalizedInput> => {
|
|
35
|
-
const files: HashMap<Pair<Function, string>, Set<string>> = new HashMap();
|
|
36
|
-
const container: NestContainer = (app as any).container as NestContainer;
|
|
37
|
-
const modules: Module[] = [...container.getModules().values()].filter(
|
|
38
|
-
(m) => !!m.controllers.size,
|
|
39
|
-
);
|
|
40
|
-
for (const m of modules) {
|
|
41
|
-
const path: string =
|
|
42
|
-
Reflect.getMetadata(
|
|
43
|
-
MODULE_PATH + container.getModules().applicationId,
|
|
44
|
-
m.metatype,
|
|
45
|
-
) ??
|
|
46
|
-
Reflect.getMetadata(MODULE_PATH, m.metatype) ??
|
|
47
|
-
"";
|
|
48
|
-
for (const controller of [...m.controllers.keys()]) {
|
|
49
|
-
const file: string | null =
|
|
50
|
-
(await require("get-function-location")(controller))?.source ?? null;
|
|
51
|
-
if (file === null) continue;
|
|
52
|
-
|
|
53
|
-
const location: string = normalize_file(file);
|
|
54
|
-
if (location.length === 0) continue;
|
|
55
|
-
|
|
56
|
-
const key: Pair<Function, string> = new Pair(
|
|
57
|
-
controller as Function,
|
|
58
|
-
location,
|
|
59
|
-
);
|
|
60
|
-
files.take(key, () => new Set([])).add(path);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const versioning = (app as any).config?.versioningOptions;
|
|
65
|
-
return {
|
|
66
|
-
include: files.toJSON().map((pair) => ({
|
|
67
|
-
controller: pair.first.first,
|
|
68
|
-
file: decodeURIComponent(pair.first.second),
|
|
69
|
-
paths: [...pair.second.values()],
|
|
70
|
-
})),
|
|
71
|
-
globalPrefix:
|
|
72
|
-
typeof (app as any).config?.globalPrefix === "string"
|
|
73
|
-
? {
|
|
74
|
-
prefix: (app as any).config.globalPrefix,
|
|
75
|
-
exclude: (app as any).config.globalPrefixOptions?.exclude ?? {},
|
|
76
|
-
}
|
|
77
|
-
: undefined,
|
|
78
|
-
versioning:
|
|
79
|
-
versioning === undefined || versioning.type !== VersioningType.URI
|
|
80
|
-
? undefined
|
|
81
|
-
: {
|
|
82
|
-
prefix:
|
|
83
|
-
versioning.prefix === undefined || versioning.prefix === false
|
|
84
|
-
? "v"
|
|
85
|
-
: versioning.prefix,
|
|
86
|
-
defaultVersion: versioning.defaultVersion,
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const normalize_file = (str: string) =>
|
|
92
|
-
str.substring(
|
|
93
|
-
str.startsWith("file:///")
|
|
94
|
-
? process.cwd()[0] === "/"
|
|
95
|
-
? 7
|
|
96
|
-
: 8
|
|
97
|
-
: str.startsWith("file://")
|
|
98
|
-
? 7
|
|
99
|
-
: 0,
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
const transform_input =
|
|
103
|
-
(config: INestiaConfig) =>
|
|
104
|
-
async (include: string[], exclude?: string[]) => ({
|
|
105
|
-
include: (
|
|
106
|
-
await SourceFinder.find({
|
|
107
|
-
include,
|
|
108
|
-
exclude,
|
|
109
|
-
filter: filter(config),
|
|
110
|
-
})
|
|
111
|
-
).map((file) => ({
|
|
112
|
-
paths: [""],
|
|
113
|
-
file,
|
|
114
|
-
})),
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
const filter =
|
|
118
|
-
(config: INestiaConfig) =>
|
|
119
|
-
async (location: string): Promise<boolean> =>
|
|
120
|
-
location.endsWith(".ts") &&
|
|
121
|
-
!location.endsWith(".d.ts") &&
|
|
122
|
-
(config.output === undefined ||
|
|
123
|
-
(location.indexOf(path.join(config.output, "functional")) === -1 &&
|
|
124
|
-
(await (
|
|
125
|
-
await bundler.get(config.output)
|
|
126
|
-
)(location))) === false);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const memory = new Map<INestiaConfig, Promise<INormalizedInput>>();
|
|
130
|
-
const bundler = new Singleton(async (output: string) => {
|
|
131
|
-
const assets: string[] = await fs.promises.readdir(SdkGenerator.BUNDLE_PATH);
|
|
132
|
-
const tuples: Pair<string, boolean>[] = await ArrayUtil.asyncMap(
|
|
133
|
-
assets,
|
|
134
|
-
async (file) => {
|
|
135
|
-
const relative: string = path.join(output, file);
|
|
136
|
-
const location: string = path.join(SdkGenerator.BUNDLE_PATH, file);
|
|
137
|
-
const stats: fs.Stats = await fs.promises.stat(location);
|
|
138
|
-
return new Pair(relative, stats.isDirectory());
|
|
139
|
-
},
|
|
140
|
-
);
|
|
141
|
-
return async (file: string): Promise<boolean> => {
|
|
142
|
-
for (const it of tuples)
|
|
143
|
-
if (it.second === false && file === it.first) return true;
|
|
144
|
-
else if (it.second === true && file.indexOf(it.first) === 0) return true;
|
|
145
|
-
return false;
|
|
146
|
-
};
|
|
147
|
-
});
|
|
1
|
+
import { INestApplication, VersioningType } from "@nestjs/common";
|
|
2
|
+
import { MODULE_PATH } from "@nestjs/common/constants";
|
|
3
|
+
import { NestContainer } from "@nestjs/core";
|
|
4
|
+
import { Module } from "@nestjs/core/injector/module";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { HashMap, Pair, Singleton } from "tstl";
|
|
8
|
+
|
|
9
|
+
import { INestiaConfig } from "../INestiaConfig";
|
|
10
|
+
import { SdkGenerator } from "../generates/SdkGenerator";
|
|
11
|
+
import { INormalizedInput } from "../structures/INormalizedInput";
|
|
12
|
+
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
13
|
+
import { MapUtil } from "../utils/MapUtil";
|
|
14
|
+
import { SourceFinder } from "../utils/SourceFinder";
|
|
15
|
+
|
|
16
|
+
export namespace ConfigAnalyzer {
|
|
17
|
+
export const input = (config: INestiaConfig): Promise<INormalizedInput> =>
|
|
18
|
+
MapUtil.take(memory, config, async () => {
|
|
19
|
+
const input = config.input;
|
|
20
|
+
if (Array.isArray(input)) return transform_input(config)(input);
|
|
21
|
+
else if (typeof input === "function")
|
|
22
|
+
return analyze_application(await input());
|
|
23
|
+
else if (typeof input === "object")
|
|
24
|
+
if (input === null)
|
|
25
|
+
throw new Error("Invalid input config. It can't be null.");
|
|
26
|
+
else return transform_input(config)(input.include, input.exclude);
|
|
27
|
+
else if (typeof input === "string")
|
|
28
|
+
return transform_input(config)([input]);
|
|
29
|
+
else throw new Error("Invalid input config.");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const analyze_application = async (
|
|
33
|
+
app: INestApplication,
|
|
34
|
+
): Promise<INormalizedInput> => {
|
|
35
|
+
const files: HashMap<Pair<Function, string>, Set<string>> = new HashMap();
|
|
36
|
+
const container: NestContainer = (app as any).container as NestContainer;
|
|
37
|
+
const modules: Module[] = [...container.getModules().values()].filter(
|
|
38
|
+
(m) => !!m.controllers.size,
|
|
39
|
+
);
|
|
40
|
+
for (const m of modules) {
|
|
41
|
+
const path: string =
|
|
42
|
+
Reflect.getMetadata(
|
|
43
|
+
MODULE_PATH + container.getModules().applicationId,
|
|
44
|
+
m.metatype,
|
|
45
|
+
) ??
|
|
46
|
+
Reflect.getMetadata(MODULE_PATH, m.metatype) ??
|
|
47
|
+
"";
|
|
48
|
+
for (const controller of [...m.controllers.keys()]) {
|
|
49
|
+
const file: string | null =
|
|
50
|
+
(await require("get-function-location")(controller))?.source ?? null;
|
|
51
|
+
if (file === null) continue;
|
|
52
|
+
|
|
53
|
+
const location: string = normalize_file(file);
|
|
54
|
+
if (location.length === 0) continue;
|
|
55
|
+
|
|
56
|
+
const key: Pair<Function, string> = new Pair(
|
|
57
|
+
controller as Function,
|
|
58
|
+
location,
|
|
59
|
+
);
|
|
60
|
+
files.take(key, () => new Set([])).add(path);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const versioning = (app as any).config?.versioningOptions;
|
|
65
|
+
return {
|
|
66
|
+
include: files.toJSON().map((pair) => ({
|
|
67
|
+
controller: pair.first.first,
|
|
68
|
+
file: decodeURIComponent(pair.first.second),
|
|
69
|
+
paths: [...pair.second.values()],
|
|
70
|
+
})),
|
|
71
|
+
globalPrefix:
|
|
72
|
+
typeof (app as any).config?.globalPrefix === "string"
|
|
73
|
+
? {
|
|
74
|
+
prefix: (app as any).config.globalPrefix,
|
|
75
|
+
exclude: (app as any).config.globalPrefixOptions?.exclude ?? {},
|
|
76
|
+
}
|
|
77
|
+
: undefined,
|
|
78
|
+
versioning:
|
|
79
|
+
versioning === undefined || versioning.type !== VersioningType.URI
|
|
80
|
+
? undefined
|
|
81
|
+
: {
|
|
82
|
+
prefix:
|
|
83
|
+
versioning.prefix === undefined || versioning.prefix === false
|
|
84
|
+
? "v"
|
|
85
|
+
: versioning.prefix,
|
|
86
|
+
defaultVersion: versioning.defaultVersion,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const normalize_file = (str: string) =>
|
|
92
|
+
str.substring(
|
|
93
|
+
str.startsWith("file:///")
|
|
94
|
+
? process.cwd()[0] === "/"
|
|
95
|
+
? 7
|
|
96
|
+
: 8
|
|
97
|
+
: str.startsWith("file://")
|
|
98
|
+
? 7
|
|
99
|
+
: 0,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const transform_input =
|
|
103
|
+
(config: INestiaConfig) =>
|
|
104
|
+
async (include: string[], exclude?: string[]) => ({
|
|
105
|
+
include: (
|
|
106
|
+
await SourceFinder.find({
|
|
107
|
+
include,
|
|
108
|
+
exclude,
|
|
109
|
+
filter: filter(config),
|
|
110
|
+
})
|
|
111
|
+
).map((file) => ({
|
|
112
|
+
paths: [""],
|
|
113
|
+
file,
|
|
114
|
+
})),
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const filter =
|
|
118
|
+
(config: INestiaConfig) =>
|
|
119
|
+
async (location: string): Promise<boolean> =>
|
|
120
|
+
location.endsWith(".ts") &&
|
|
121
|
+
!location.endsWith(".d.ts") &&
|
|
122
|
+
(config.output === undefined ||
|
|
123
|
+
(location.indexOf(path.join(config.output, "functional")) === -1 &&
|
|
124
|
+
(await (
|
|
125
|
+
await bundler.get(config.output)
|
|
126
|
+
)(location))) === false);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const memory = new Map<INestiaConfig, Promise<INormalizedInput>>();
|
|
130
|
+
const bundler = new Singleton(async (output: string) => {
|
|
131
|
+
const assets: string[] = await fs.promises.readdir(SdkGenerator.BUNDLE_PATH);
|
|
132
|
+
const tuples: Pair<string, boolean>[] = await ArrayUtil.asyncMap(
|
|
133
|
+
assets,
|
|
134
|
+
async (file) => {
|
|
135
|
+
const relative: string = path.join(output, file);
|
|
136
|
+
const location: string = path.join(SdkGenerator.BUNDLE_PATH, file);
|
|
137
|
+
const stats: fs.Stats = await fs.promises.stat(location);
|
|
138
|
+
return new Pair(relative, stats.isDirectory());
|
|
139
|
+
},
|
|
140
|
+
);
|
|
141
|
+
return async (file: string): Promise<boolean> => {
|
|
142
|
+
for (const it of tuples)
|
|
143
|
+
if (it.second === false && file === it.first) return true;
|
|
144
|
+
else if (it.second === true && file.indexOf(it.first) === 0) return true;
|
|
145
|
+
return false;
|
|
146
|
+
};
|
|
147
|
+
});
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace GenericAnalyzer {
|
|
4
|
-
export type Dictionary = WeakMap<ts.Type, ts.Type>;
|
|
5
|
-
|
|
6
|
-
export function analyze(
|
|
7
|
-
checker: ts.TypeChecker,
|
|
8
|
-
classNode: ts.ClassDeclaration,
|
|
9
|
-
): Dictionary {
|
|
10
|
-
const dict: Dictionary = new WeakMap();
|
|
11
|
-
explore(checker, dict, classNode);
|
|
12
|
-
return dict;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function explore(
|
|
16
|
-
checker: ts.TypeChecker,
|
|
17
|
-
dict: Dictionary,
|
|
18
|
-
classNode: ts.ClassDeclaration,
|
|
19
|
-
): void {
|
|
20
|
-
if (classNode.heritageClauses === undefined) return;
|
|
21
|
-
|
|
22
|
-
for (const heritage of classNode.heritageClauses)
|
|
23
|
-
for (const hType of heritage.types) {
|
|
24
|
-
// MUST BE CLASS
|
|
25
|
-
const expression: ts.Type = checker.getTypeAtLocation(hType.expression);
|
|
26
|
-
const superNode: ts.Declaration | undefined =
|
|
27
|
-
expression.symbol.getDeclarations()?.[0];
|
|
28
|
-
|
|
29
|
-
if (superNode === undefined || !ts.isClassDeclaration(superNode))
|
|
30
|
-
continue;
|
|
31
|
-
|
|
32
|
-
// SPECIFY GENERICS
|
|
33
|
-
const usages: ReadonlyArray<ts.TypeNode> = hType.typeArguments || [];
|
|
34
|
-
const parameters: ReadonlyArray<ts.TypeParameterDeclaration> =
|
|
35
|
-
superNode.typeParameters || [];
|
|
36
|
-
|
|
37
|
-
parameters.forEach((param, index) => {
|
|
38
|
-
const paramType: ts.Type = checker.getTypeAtLocation(param);
|
|
39
|
-
const usageType: ts.Type =
|
|
40
|
-
usages[index] !== undefined
|
|
41
|
-
? checker.getTypeAtLocation(usages[index])
|
|
42
|
-
: checker.getTypeAtLocation(param.default!);
|
|
43
|
-
|
|
44
|
-
dict.set(paramType, usageType);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// RECUSRIVE EXPLORATION
|
|
48
|
-
explore(checker, dict, superNode);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace GenericAnalyzer {
|
|
4
|
+
export type Dictionary = WeakMap<ts.Type, ts.Type>;
|
|
5
|
+
|
|
6
|
+
export function analyze(
|
|
7
|
+
checker: ts.TypeChecker,
|
|
8
|
+
classNode: ts.ClassDeclaration,
|
|
9
|
+
): Dictionary {
|
|
10
|
+
const dict: Dictionary = new WeakMap();
|
|
11
|
+
explore(checker, dict, classNode);
|
|
12
|
+
return dict;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function explore(
|
|
16
|
+
checker: ts.TypeChecker,
|
|
17
|
+
dict: Dictionary,
|
|
18
|
+
classNode: ts.ClassDeclaration,
|
|
19
|
+
): void {
|
|
20
|
+
if (classNode.heritageClauses === undefined) return;
|
|
21
|
+
|
|
22
|
+
for (const heritage of classNode.heritageClauses)
|
|
23
|
+
for (const hType of heritage.types) {
|
|
24
|
+
// MUST BE CLASS
|
|
25
|
+
const expression: ts.Type = checker.getTypeAtLocation(hType.expression);
|
|
26
|
+
const superNode: ts.Declaration | undefined =
|
|
27
|
+
expression.symbol.getDeclarations()?.[0];
|
|
28
|
+
|
|
29
|
+
if (superNode === undefined || !ts.isClassDeclaration(superNode))
|
|
30
|
+
continue;
|
|
31
|
+
|
|
32
|
+
// SPECIFY GENERICS
|
|
33
|
+
const usages: ReadonlyArray<ts.TypeNode> = hType.typeArguments || [];
|
|
34
|
+
const parameters: ReadonlyArray<ts.TypeParameterDeclaration> =
|
|
35
|
+
superNode.typeParameters || [];
|
|
36
|
+
|
|
37
|
+
parameters.forEach((param, index) => {
|
|
38
|
+
const paramType: ts.Type = checker.getTypeAtLocation(param);
|
|
39
|
+
const usageType: ts.Type =
|
|
40
|
+
usages[index] !== undefined
|
|
41
|
+
? checker.getTypeAtLocation(usages[index])
|
|
42
|
+
: checker.getTypeAtLocation(param.default!);
|
|
43
|
+
|
|
44
|
+
dict.set(paramType, usageType);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// RECUSRIVE EXPLORATION
|
|
48
|
+
explore(checker, dict, superNode);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { Token, parse } from "path-to-regexp";
|
|
3
|
-
|
|
4
|
-
export namespace PathAnalyzer {
|
|
5
|
-
export const join = (...args: string[]) =>
|
|
6
|
-
"/" +
|
|
7
|
-
_Trim(
|
|
8
|
-
path
|
|
9
|
-
.join(...args.filter((s) => !!s.length))
|
|
10
|
-
.split("\\")
|
|
11
|
-
.join("/"),
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
export const escape = (str: string): string | null => {
|
|
15
|
-
const args = _Parse(str);
|
|
16
|
-
if (args === null) return null;
|
|
17
|
-
return (
|
|
18
|
-
"/" +
|
|
19
|
-
args
|
|
20
|
-
.map((arg) => (arg.type === "param" ? `:${arg.value}` : arg.value))
|
|
21
|
-
.join("/")
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const parameters = (str: string): string[] | null => {
|
|
26
|
-
const args = _Parse(str);
|
|
27
|
-
if (args === null) return null;
|
|
28
|
-
return args.filter((arg) => arg.type === "param").map((arg) => arg.value);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
function _Parse(str: string): IArgument[] | null {
|
|
32
|
-
const tokens: Token[] | null = (() => {
|
|
33
|
-
try {
|
|
34
|
-
return parse(path.join(str).split("\\").join("/"));
|
|
35
|
-
} catch {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
})();
|
|
39
|
-
if (tokens === null) return null;
|
|
40
|
-
|
|
41
|
-
const output: IArgument[] = [];
|
|
42
|
-
for (const key of tokens) {
|
|
43
|
-
if (typeof key === "string")
|
|
44
|
-
output.push({
|
|
45
|
-
type: "path",
|
|
46
|
-
value: _Trim(key),
|
|
47
|
-
});
|
|
48
|
-
else if (typeof key.name === "number" || _Trim(key.name) === "")
|
|
49
|
-
return null;
|
|
50
|
-
else
|
|
51
|
-
output.push({
|
|
52
|
-
type: "param",
|
|
53
|
-
value: _Trim(key.name),
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return output;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function _Trim(str: string): string {
|
|
60
|
-
if (str[0] === "/") str = str.substring(1);
|
|
61
|
-
if (str[str.length - 1] === "/") str = str.substring(0, str.length - 1);
|
|
62
|
-
return str;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
interface IArgument {
|
|
66
|
-
type: "param" | "path";
|
|
67
|
-
value: string;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { Token, parse } from "path-to-regexp";
|
|
3
|
+
|
|
4
|
+
export namespace PathAnalyzer {
|
|
5
|
+
export const join = (...args: string[]) =>
|
|
6
|
+
"/" +
|
|
7
|
+
_Trim(
|
|
8
|
+
path
|
|
9
|
+
.join(...args.filter((s) => !!s.length))
|
|
10
|
+
.split("\\")
|
|
11
|
+
.join("/"),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export const escape = (str: string): string | null => {
|
|
15
|
+
const args = _Parse(str);
|
|
16
|
+
if (args === null) return null;
|
|
17
|
+
return (
|
|
18
|
+
"/" +
|
|
19
|
+
args
|
|
20
|
+
.map((arg) => (arg.type === "param" ? `:${arg.value}` : arg.value))
|
|
21
|
+
.join("/")
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const parameters = (str: string): string[] | null => {
|
|
26
|
+
const args = _Parse(str);
|
|
27
|
+
if (args === null) return null;
|
|
28
|
+
return args.filter((arg) => arg.type === "param").map((arg) => arg.value);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function _Parse(str: string): IArgument[] | null {
|
|
32
|
+
const tokens: Token[] | null = (() => {
|
|
33
|
+
try {
|
|
34
|
+
return parse(path.join(str).split("\\").join("/"));
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
})();
|
|
39
|
+
if (tokens === null) return null;
|
|
40
|
+
|
|
41
|
+
const output: IArgument[] = [];
|
|
42
|
+
for (const key of tokens) {
|
|
43
|
+
if (typeof key === "string")
|
|
44
|
+
output.push({
|
|
45
|
+
type: "path",
|
|
46
|
+
value: _Trim(key),
|
|
47
|
+
});
|
|
48
|
+
else if (typeof key.name === "number" || _Trim(key.name) === "")
|
|
49
|
+
return null;
|
|
50
|
+
else
|
|
51
|
+
output.push({
|
|
52
|
+
type: "param",
|
|
53
|
+
value: _Trim(key.name),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return output;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function _Trim(str: string): string {
|
|
60
|
+
if (str[0] === "/") str = str.substring(1);
|
|
61
|
+
if (str[str.length - 1] === "/") str = str.substring(0, str.length - 1);
|
|
62
|
+
return str;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface IArgument {
|
|
66
|
+
type: "param" | "path";
|
|
67
|
+
value: string;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { MapUtil } from "../utils/MapUtil";
|
|
2
|
-
|
|
3
|
-
export namespace SecurityAnalyzer {
|
|
4
|
-
export const merge = (...entire: Record<string, string[]>[]) => {
|
|
5
|
-
const dict: Map<string | typeof none, Set<string>> = new Map();
|
|
6
|
-
for (const obj of entire) {
|
|
7
|
-
const entries = Object.entries(obj);
|
|
8
|
-
for (const [key, value] of entries) {
|
|
9
|
-
const set = MapUtil.take(dict, key, () => new Set());
|
|
10
|
-
for (const val of value) set.add(val);
|
|
11
|
-
}
|
|
12
|
-
if (entries.length === 0) MapUtil.take(dict, none, () => new Set());
|
|
13
|
-
}
|
|
14
|
-
const output: Record<string, string[]>[] = [];
|
|
15
|
-
for (const [key, set] of dict)
|
|
16
|
-
key === none
|
|
17
|
-
? output.push({})
|
|
18
|
-
: output.push({
|
|
19
|
-
[key]: [...set],
|
|
20
|
-
});
|
|
21
|
-
return output;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const none = Symbol("none");
|
|
25
|
-
}
|
|
1
|
+
import { MapUtil } from "../utils/MapUtil";
|
|
2
|
+
|
|
3
|
+
export namespace SecurityAnalyzer {
|
|
4
|
+
export const merge = (...entire: Record<string, string[]>[]) => {
|
|
5
|
+
const dict: Map<string | typeof none, Set<string>> = new Map();
|
|
6
|
+
for (const obj of entire) {
|
|
7
|
+
const entries = Object.entries(obj);
|
|
8
|
+
for (const [key, value] of entries) {
|
|
9
|
+
const set = MapUtil.take(dict, key, () => new Set());
|
|
10
|
+
for (const val of value) set.add(val);
|
|
11
|
+
}
|
|
12
|
+
if (entries.length === 0) MapUtil.take(dict, none, () => new Set());
|
|
13
|
+
}
|
|
14
|
+
const output: Record<string, string[]>[] = [];
|
|
15
|
+
for (const [key, set] of dict)
|
|
16
|
+
key === none
|
|
17
|
+
? output.push({})
|
|
18
|
+
: output.push({
|
|
19
|
+
[key]: [...set],
|
|
20
|
+
});
|
|
21
|
+
return output;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const none = Symbol("none");
|
|
25
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export namespace CommandParser {
|
|
2
|
-
export function parse(argList: string[]): Record<string, string> {
|
|
3
|
-
const output: Record<string, string> = {};
|
|
4
|
-
argList.forEach((arg, i) => {
|
|
5
|
-
if (arg.startsWith("--") === false) return;
|
|
6
|
-
|
|
7
|
-
const key = arg.slice(2);
|
|
8
|
-
const value: string | undefined = argList[i + 1];
|
|
9
|
-
if (value === undefined || value.startsWith("--")) return;
|
|
10
|
-
|
|
11
|
-
output[key] = value;
|
|
12
|
-
});
|
|
13
|
-
return output;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
export namespace CommandParser {
|
|
2
|
+
export function parse(argList: string[]): Record<string, string> {
|
|
3
|
+
const output: Record<string, string> = {};
|
|
4
|
+
argList.forEach((arg, i) => {
|
|
5
|
+
if (arg.startsWith("--") === false) return;
|
|
6
|
+
|
|
7
|
+
const key = arg.slice(2);
|
|
8
|
+
const value: string | undefined = argList[i + 1];
|
|
9
|
+
if (value === undefined || value.startsWith("--")) return;
|
|
10
|
+
|
|
11
|
+
output[key] = value;
|
|
12
|
+
});
|
|
13
|
+
return output;
|
|
14
|
+
}
|
|
15
|
+
}
|