@typia/utils 12.0.0-dev.20260309 → 12.0.0-dev.20260310
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/http/internal/HttpLlmApplicationComposer.mjs +5 -1
- package/lib/http/internal/HttpLlmApplicationComposer.mjs.map +1 -1
- package/lib/index.mjs +9 -9
- package/lib/utils/LlmJson.mjs +9 -2
- package/lib/utils/LlmJson.mjs.map +1 -1
- package/lib/utils/internal/stringifyValidationFailure.js +17 -15
- package/lib/utils/internal/stringifyValidationFailure.js.map +1 -1
- package/lib/utils/internal/stringifyValidationFailure.mjs +17 -15
- package/lib/utils/internal/stringifyValidationFailure.mjs.map +1 -1
- package/lib/validators/internal/OpenApiOneOfValidator.mjs +5 -1
- package/lib/validators/internal/OpenApiOneOfValidator.mjs.map +1 -1
- package/package.json +2 -2
- package/src/converters/LlmSchemaConverter.ts +647 -647
- package/src/converters/OpenApiConverter.ts +285 -285
- package/src/converters/index.ts +5 -5
- package/src/converters/internal/LlmDescriptionInverter.ts +178 -178
- package/src/converters/internal/LlmParametersComposer.ts +52 -52
- package/src/converters/internal/OpenApiConstraintShifter.ts +154 -154
- package/src/converters/internal/OpenApiExclusiveEmender.ts +46 -46
- package/src/converters/internal/OpenApiV3Downgrader.ts +355 -355
- package/src/converters/internal/OpenApiV3Upgrader.ts +470 -470
- package/src/converters/internal/OpenApiV3_1Upgrader.ts +685 -685
- package/src/converters/internal/SwaggerV2Downgrader.ts +424 -424
- package/src/converters/internal/SwaggerV2Upgrader.ts +523 -523
- package/src/http/HttpError.ts +107 -107
- package/src/http/HttpLlm.ts +167 -167
- package/src/http/HttpMigration.ts +92 -92
- package/src/http/index.ts +3 -3
- package/src/http/internal/HttpLlmApplicationComposer.ts +361 -361
- package/src/http/internal/HttpLlmFunctionFetcher.ts +37 -37
- package/src/http/internal/HttpMigrateApplicationComposer.ts +56 -56
- package/src/http/internal/HttpMigrateRouteAccessor.ts +135 -135
- package/src/http/internal/HttpMigrateRouteComposer.ts +505 -505
- package/src/http/internal/HttpMigrateRouteFetcher.ts +203 -203
- package/src/index.ts +4 -4
- package/src/utils/ArrayUtil.ts +42 -42
- package/src/utils/LlmJson.ts +141 -141
- package/src/utils/MapUtil.ts +15 -15
- package/src/utils/NamingConvention.ts +205 -205
- package/src/utils/Singleton.ts +17 -17
- package/src/utils/StringUtil.ts +14 -14
- package/src/utils/dedent.ts +57 -57
- package/src/utils/index.ts +8 -8
- package/src/utils/internal/EndpointUtil.ts +44 -44
- package/src/utils/internal/JsonDescriptor.ts +70 -70
- package/src/utils/internal/OpenApiTypeCheckerBase.ts +822 -822
- package/src/utils/internal/coerceLlmArguments.ts +314 -314
- package/src/utils/internal/parseLenientJson.ts +894 -894
- package/src/utils/internal/stringifyValidationFailure.ts +415 -411
- package/src/validators/LlmTypeChecker.ts +402 -402
- package/src/validators/OpenApiTypeChecker.ts +297 -297
- package/src/validators/OpenApiV3TypeChecker.ts +70 -70
- package/src/validators/OpenApiV3_1TypeChecker.ts +86 -86
- package/src/validators/OpenApiValidator.ts +94 -94
- package/src/validators/SwaggerV2TypeChecker.ts +71 -71
- package/src/validators/functional/_isBigintString.ts +8 -8
- package/src/validators/functional/_isFormatByte.ts +7 -7
- package/src/validators/functional/_isFormatDate.ts +3 -3
- package/src/validators/functional/_isFormatDateTime.ts +4 -4
- package/src/validators/functional/_isFormatDuration.ts +4 -4
- package/src/validators/functional/_isFormatEmail.ts +4 -4
- package/src/validators/functional/_isFormatHostname.ts +4 -4
- package/src/validators/functional/_isFormatIdnEmail.ts +4 -4
- package/src/validators/functional/_isFormatIdnHostname.ts +4 -4
- package/src/validators/functional/_isFormatIpv4.ts +4 -4
- package/src/validators/functional/_isFormatIpv6.ts +4 -4
- package/src/validators/functional/_isFormatIri.ts +3 -3
- package/src/validators/functional/_isFormatIriReference.ts +4 -4
- package/src/validators/functional/_isFormatJsonPointer.ts +3 -3
- package/src/validators/functional/_isFormatPassword.ts +1 -1
- package/src/validators/functional/_isFormatRegex.ts +8 -8
- package/src/validators/functional/_isFormatRelativeJsonPointer.ts +4 -4
- package/src/validators/functional/_isFormatTime.ts +4 -4
- package/src/validators/functional/_isFormatUri.ts +6 -6
- package/src/validators/functional/_isFormatUriReference.ts +5 -5
- package/src/validators/functional/_isFormatUriTemplate.ts +4 -4
- package/src/validators/functional/_isFormatUrl.ts +4 -4
- package/src/validators/functional/_isFormatUuid.ts +3 -3
- package/src/validators/functional/_isUniqueItems.ts +159 -159
- package/src/validators/index.ts +14 -14
- package/src/validators/internal/IOpenApiValidatorContext.ts +17 -17
- package/src/validators/internal/OpenApiArrayValidator.ts +49 -49
- package/src/validators/internal/OpenApiBooleanValidator.ts +11 -11
- package/src/validators/internal/OpenApiConstantValidator.ts +11 -11
- package/src/validators/internal/OpenApiIntegerValidator.ts +49 -49
- package/src/validators/internal/OpenApiNumberValidator.ts +48 -48
- package/src/validators/internal/OpenApiObjectValidator.ts +83 -83
- package/src/validators/internal/OpenApiOneOfValidator.ts +309 -309
- package/src/validators/internal/OpenApiSchemaNamingRule.ts +124 -124
- package/src/validators/internal/OpenApiStationValidator.ts +115 -115
- package/src/validators/internal/OpenApiStringValidator.ts +88 -88
- package/src/validators/internal/OpenApiTupleValidator.ts +55 -55
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { IHttpMigrateRoute, IHttpResponse } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
import type { HttpLlm } from "../HttpLlm";
|
|
4
|
-
import type { HttpMigration } from "../HttpMigration";
|
|
5
|
-
import { HttpMigrateRouteFetcher } from "./HttpMigrateRouteFetcher";
|
|
6
|
-
|
|
7
|
-
export namespace HttpLlmFunctionFetcher {
|
|
8
|
-
export const execute = (props: HttpLlm.IFetchProps): Promise<unknown> =>
|
|
9
|
-
HttpMigrateRouteFetcher.execute(getFetchArguments("execute", props));
|
|
10
|
-
|
|
11
|
-
export const propagate = (
|
|
12
|
-
props: HttpLlm.IFetchProps,
|
|
13
|
-
): Promise<IHttpResponse> =>
|
|
14
|
-
HttpMigrateRouteFetcher.propagate(getFetchArguments("propagate", props));
|
|
15
|
-
|
|
16
|
-
const getFetchArguments = (
|
|
17
|
-
from: string,
|
|
18
|
-
props: HttpLlm.IFetchProps,
|
|
19
|
-
): HttpMigration.IFetchProps => {
|
|
20
|
-
const route: IHttpMigrateRoute = props.function.route();
|
|
21
|
-
const input: Record<string, any> = props.input;
|
|
22
|
-
const valid: boolean = typeof input === "object" && input !== null;
|
|
23
|
-
if (valid === false)
|
|
24
|
-
throw new Error(
|
|
25
|
-
`Error on HttpLlmFunctionFetcher.${from}(): keyworded arguments must be an object`,
|
|
26
|
-
);
|
|
27
|
-
return {
|
|
28
|
-
connection: props.connection,
|
|
29
|
-
route,
|
|
30
|
-
parameters: Object.fromEntries(
|
|
31
|
-
route.parameters.map((p) => [p.key, input[p.key]] as const),
|
|
32
|
-
),
|
|
33
|
-
query: input.query,
|
|
34
|
-
body: input.body,
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
}
|
|
1
|
+
import { IHttpMigrateRoute, IHttpResponse } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
import type { HttpLlm } from "../HttpLlm";
|
|
4
|
+
import type { HttpMigration } from "../HttpMigration";
|
|
5
|
+
import { HttpMigrateRouteFetcher } from "./HttpMigrateRouteFetcher";
|
|
6
|
+
|
|
7
|
+
export namespace HttpLlmFunctionFetcher {
|
|
8
|
+
export const execute = (props: HttpLlm.IFetchProps): Promise<unknown> =>
|
|
9
|
+
HttpMigrateRouteFetcher.execute(getFetchArguments("execute", props));
|
|
10
|
+
|
|
11
|
+
export const propagate = (
|
|
12
|
+
props: HttpLlm.IFetchProps,
|
|
13
|
+
): Promise<IHttpResponse> =>
|
|
14
|
+
HttpMigrateRouteFetcher.propagate(getFetchArguments("propagate", props));
|
|
15
|
+
|
|
16
|
+
const getFetchArguments = (
|
|
17
|
+
from: string,
|
|
18
|
+
props: HttpLlm.IFetchProps,
|
|
19
|
+
): HttpMigration.IFetchProps => {
|
|
20
|
+
const route: IHttpMigrateRoute = props.function.route();
|
|
21
|
+
const input: Record<string, any> = props.input;
|
|
22
|
+
const valid: boolean = typeof input === "object" && input !== null;
|
|
23
|
+
if (valid === false)
|
|
24
|
+
throw new Error(
|
|
25
|
+
`Error on HttpLlmFunctionFetcher.${from}(): keyworded arguments must be an object`,
|
|
26
|
+
);
|
|
27
|
+
return {
|
|
28
|
+
connection: props.connection,
|
|
29
|
+
route,
|
|
30
|
+
parameters: Object.fromEntries(
|
|
31
|
+
route.parameters.map((p) => [p.key, input[p.key]] as const),
|
|
32
|
+
),
|
|
33
|
+
query: input.query,
|
|
34
|
+
body: input.body,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IHttpMigrateApplication,
|
|
3
|
-
IHttpMigrateRoute,
|
|
4
|
-
OpenApi,
|
|
5
|
-
} from "@typia/interface";
|
|
6
|
-
|
|
7
|
-
import { EndpointUtil } from "../../utils/internal/EndpointUtil";
|
|
8
|
-
import { HttpMigrateRouteAccessor } from "./HttpMigrateRouteAccessor";
|
|
9
|
-
import { HttpMigrateRouteComposer } from "./HttpMigrateRouteComposer";
|
|
10
|
-
|
|
11
|
-
export namespace HttpMigrateApplicationComposer {
|
|
12
|
-
export const compose = (
|
|
13
|
-
document: OpenApi.IDocument,
|
|
14
|
-
): IHttpMigrateApplication => {
|
|
15
|
-
const errors: IHttpMigrateApplication.IError[] = [];
|
|
16
|
-
const entire: Array<IHttpMigrateRoute | null> = Object.entries({
|
|
17
|
-
...(document.paths ?? {}),
|
|
18
|
-
...(document.webhooks ?? {}),
|
|
19
|
-
})
|
|
20
|
-
.map(([path, collection]) =>
|
|
21
|
-
(["head", "get", "post", "put", "patch", "delete"] as const)
|
|
22
|
-
.filter((method) => collection[method] !== undefined)
|
|
23
|
-
.map((method) => {
|
|
24
|
-
const operation: OpenApi.IOperation = collection[method]!;
|
|
25
|
-
const migrated: IHttpMigrateRoute | string[] =
|
|
26
|
-
HttpMigrateRouteComposer.compose({
|
|
27
|
-
document,
|
|
28
|
-
method,
|
|
29
|
-
path,
|
|
30
|
-
emendedPath: EndpointUtil.reJoinWithDecimalParameters(path),
|
|
31
|
-
operation,
|
|
32
|
-
});
|
|
33
|
-
if (Array.isArray(migrated)) {
|
|
34
|
-
errors.push({
|
|
35
|
-
method,
|
|
36
|
-
path,
|
|
37
|
-
operation: () => operation,
|
|
38
|
-
messages: migrated,
|
|
39
|
-
});
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
return migrated;
|
|
43
|
-
}),
|
|
44
|
-
)
|
|
45
|
-
.flat();
|
|
46
|
-
const operations: IHttpMigrateRoute[] = entire.filter(
|
|
47
|
-
(o): o is IHttpMigrateRoute => !!o,
|
|
48
|
-
);
|
|
49
|
-
HttpMigrateRouteAccessor.overwrite(operations);
|
|
50
|
-
return {
|
|
51
|
-
document: () => document,
|
|
52
|
-
routes: operations,
|
|
53
|
-
errors,
|
|
54
|
-
} satisfies IHttpMigrateApplication as IHttpMigrateApplication;
|
|
55
|
-
};
|
|
56
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
IHttpMigrateApplication,
|
|
3
|
+
IHttpMigrateRoute,
|
|
4
|
+
OpenApi,
|
|
5
|
+
} from "@typia/interface";
|
|
6
|
+
|
|
7
|
+
import { EndpointUtil } from "../../utils/internal/EndpointUtil";
|
|
8
|
+
import { HttpMigrateRouteAccessor } from "./HttpMigrateRouteAccessor";
|
|
9
|
+
import { HttpMigrateRouteComposer } from "./HttpMigrateRouteComposer";
|
|
10
|
+
|
|
11
|
+
export namespace HttpMigrateApplicationComposer {
|
|
12
|
+
export const compose = (
|
|
13
|
+
document: OpenApi.IDocument,
|
|
14
|
+
): IHttpMigrateApplication => {
|
|
15
|
+
const errors: IHttpMigrateApplication.IError[] = [];
|
|
16
|
+
const entire: Array<IHttpMigrateRoute | null> = Object.entries({
|
|
17
|
+
...(document.paths ?? {}),
|
|
18
|
+
...(document.webhooks ?? {}),
|
|
19
|
+
})
|
|
20
|
+
.map(([path, collection]) =>
|
|
21
|
+
(["head", "get", "post", "put", "patch", "delete"] as const)
|
|
22
|
+
.filter((method) => collection[method] !== undefined)
|
|
23
|
+
.map((method) => {
|
|
24
|
+
const operation: OpenApi.IOperation = collection[method]!;
|
|
25
|
+
const migrated: IHttpMigrateRoute | string[] =
|
|
26
|
+
HttpMigrateRouteComposer.compose({
|
|
27
|
+
document,
|
|
28
|
+
method,
|
|
29
|
+
path,
|
|
30
|
+
emendedPath: EndpointUtil.reJoinWithDecimalParameters(path),
|
|
31
|
+
operation,
|
|
32
|
+
});
|
|
33
|
+
if (Array.isArray(migrated)) {
|
|
34
|
+
errors.push({
|
|
35
|
+
method,
|
|
36
|
+
path,
|
|
37
|
+
operation: () => operation,
|
|
38
|
+
messages: migrated,
|
|
39
|
+
});
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return migrated;
|
|
43
|
+
}),
|
|
44
|
+
)
|
|
45
|
+
.flat();
|
|
46
|
+
const operations: IHttpMigrateRoute[] = entire.filter(
|
|
47
|
+
(o): o is IHttpMigrateRoute => !!o,
|
|
48
|
+
);
|
|
49
|
+
HttpMigrateRouteAccessor.overwrite(operations);
|
|
50
|
+
return {
|
|
51
|
+
document: () => document,
|
|
52
|
+
routes: operations,
|
|
53
|
+
errors,
|
|
54
|
+
} satisfies IHttpMigrateApplication as IHttpMigrateApplication;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
import { IHttpMigrateRoute } from "@typia/interface";
|
|
2
|
-
|
|
3
|
-
import { MapUtil } from "../../utils/MapUtil";
|
|
4
|
-
import { NamingConvention } from "../../utils/NamingConvention";
|
|
5
|
-
import { EndpointUtil } from "../../utils/internal/EndpointUtil";
|
|
6
|
-
|
|
7
|
-
export namespace HttpMigrateRouteAccessor {
|
|
8
|
-
export const overwrite = (routes: IHttpMigrateRoute[]): void => {
|
|
9
|
-
const predefined: Map<string, number> = getPredefinedAccessors(routes);
|
|
10
|
-
const dict: Map<string, IElement> = collect((op) =>
|
|
11
|
-
op.emendedPath
|
|
12
|
-
.split("/")
|
|
13
|
-
.filter((str) => !!str.length && str[0] !== ":")
|
|
14
|
-
.map(EndpointUtil.normalize)
|
|
15
|
-
.map((str) => (NamingConvention.variable(str) ? str : `_${str}`)),
|
|
16
|
-
)(routes) as Map<string, IElement>;
|
|
17
|
-
|
|
18
|
-
for (const props of dict.values())
|
|
19
|
-
props.entries.forEach((entry, i) => {
|
|
20
|
-
entry.alias = EndpointUtil.escapeDuplicate(
|
|
21
|
-
[
|
|
22
|
-
...props.children,
|
|
23
|
-
...props.entries.filter((_, j) => i !== j).map((e) => e.alias),
|
|
24
|
-
].map(EndpointUtil.normalize),
|
|
25
|
-
)(EndpointUtil.normalize(entry.alias));
|
|
26
|
-
|
|
27
|
-
const parameters: { name: string; key: string }[] = [
|
|
28
|
-
...entry.route.parameters,
|
|
29
|
-
...(entry.route.body ? [entry.route.body] : []),
|
|
30
|
-
...(entry.route.headers ? [entry.route.headers] : []),
|
|
31
|
-
...(entry.route.query ? [entry.route.query] : []),
|
|
32
|
-
];
|
|
33
|
-
parameters.forEach(
|
|
34
|
-
(p, i) =>
|
|
35
|
-
(p.key = EndpointUtil.escapeDuplicate([
|
|
36
|
-
"connection",
|
|
37
|
-
entry.alias,
|
|
38
|
-
...parameters.filter((_, j) => i !== j).map((y) => y.key),
|
|
39
|
-
])(p.key)),
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const accessor: string[] | undefined =
|
|
43
|
-
entry.route.operation()["x-samchon-accessor"];
|
|
44
|
-
if (accessor !== undefined && predefined.get(accessor.join(".")) === 1)
|
|
45
|
-
entry.route.accessor = accessor;
|
|
46
|
-
else entry.route.accessor = [...props.namespace, entry.alias];
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
for (const x of routes) {
|
|
50
|
-
while (true) {
|
|
51
|
-
const neighbor: IHttpMigrateRoute | undefined = routes.find(
|
|
52
|
-
(y) =>
|
|
53
|
-
y.accessor.length < x.accessor.length &&
|
|
54
|
-
x.accessor
|
|
55
|
-
.slice(0, y.accessor.length)
|
|
56
|
-
.every((v, i) => v === y.accessor[i]),
|
|
57
|
-
);
|
|
58
|
-
if (neighbor === undefined) break;
|
|
59
|
-
x.accessor[neighbor.accessor.length - 1] =
|
|
60
|
-
`_${x.accessor[neighbor.accessor.length - 1]}`;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const collect =
|
|
66
|
-
(getter: (r: IHttpMigrateRoute) => string[]) =>
|
|
67
|
-
(routes: IHttpMigrateRoute[]): Map<string, IElement> => {
|
|
68
|
-
const dict: Map<string, IElement> = new Map();
|
|
69
|
-
for (const r of routes) {
|
|
70
|
-
const namespace: string[] = getter(r);
|
|
71
|
-
let last: IElement = MapUtil.take(dict, namespace.join("."), () => ({
|
|
72
|
-
namespace,
|
|
73
|
-
children: new Set(),
|
|
74
|
-
entries: [],
|
|
75
|
-
}));
|
|
76
|
-
last.entries.push({
|
|
77
|
-
route: r,
|
|
78
|
-
alias: getName(r),
|
|
79
|
-
});
|
|
80
|
-
namespace.slice(0, -1).forEach((_i, i, array) => {
|
|
81
|
-
const partial: string[] = namespace.slice(0, array.length - i);
|
|
82
|
-
const element: IElement = MapUtil.take(
|
|
83
|
-
dict,
|
|
84
|
-
partial.join("."),
|
|
85
|
-
() => ({
|
|
86
|
-
namespace: partial,
|
|
87
|
-
children: new Set(),
|
|
88
|
-
entries: [],
|
|
89
|
-
}),
|
|
90
|
-
);
|
|
91
|
-
element.children.add(last.namespace.at(-1)!);
|
|
92
|
-
});
|
|
93
|
-
const top: IElement = MapUtil.take(dict, "", () => ({
|
|
94
|
-
namespace: [],
|
|
95
|
-
children: new Set(),
|
|
96
|
-
entries: [],
|
|
97
|
-
}));
|
|
98
|
-
if (namespace.length) top.children.add(namespace[0]!);
|
|
99
|
-
}
|
|
100
|
-
return dict;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const getName = (op: IHttpMigrateRoute): string => {
|
|
104
|
-
const method = op.method === "delete" ? "erase" : op.method;
|
|
105
|
-
if (op.parameters.length === 0) return method;
|
|
106
|
-
return (
|
|
107
|
-
method +
|
|
108
|
-
"By" +
|
|
109
|
-
op.parameters.map((p) => EndpointUtil.capitalize(p.key)).join("And")
|
|
110
|
-
);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const getPredefinedAccessors = (
|
|
114
|
-
routes: IHttpMigrateRoute[],
|
|
115
|
-
): Map<string, number> => {
|
|
116
|
-
const dict: Map<string, number> = new Map();
|
|
117
|
-
for (const r of routes) {
|
|
118
|
-
const accessor = r.operation()["x-samchon-accessor"]?.join(".");
|
|
119
|
-
if (accessor === undefined) continue;
|
|
120
|
-
else if (dict.has(accessor)) dict.set(accessor, dict.get(accessor)! + 1);
|
|
121
|
-
else dict.set(accessor, 1);
|
|
122
|
-
}
|
|
123
|
-
return dict;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
interface IElement {
|
|
127
|
-
namespace: string[];
|
|
128
|
-
entries: IEntry[];
|
|
129
|
-
children: Set<string>;
|
|
130
|
-
}
|
|
131
|
-
interface IEntry {
|
|
132
|
-
route: IHttpMigrateRoute;
|
|
133
|
-
alias: string;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
1
|
+
import { IHttpMigrateRoute } from "@typia/interface";
|
|
2
|
+
|
|
3
|
+
import { MapUtil } from "../../utils/MapUtil";
|
|
4
|
+
import { NamingConvention } from "../../utils/NamingConvention";
|
|
5
|
+
import { EndpointUtil } from "../../utils/internal/EndpointUtil";
|
|
6
|
+
|
|
7
|
+
export namespace HttpMigrateRouteAccessor {
|
|
8
|
+
export const overwrite = (routes: IHttpMigrateRoute[]): void => {
|
|
9
|
+
const predefined: Map<string, number> = getPredefinedAccessors(routes);
|
|
10
|
+
const dict: Map<string, IElement> = collect((op) =>
|
|
11
|
+
op.emendedPath
|
|
12
|
+
.split("/")
|
|
13
|
+
.filter((str) => !!str.length && str[0] !== ":")
|
|
14
|
+
.map(EndpointUtil.normalize)
|
|
15
|
+
.map((str) => (NamingConvention.variable(str) ? str : `_${str}`)),
|
|
16
|
+
)(routes) as Map<string, IElement>;
|
|
17
|
+
|
|
18
|
+
for (const props of dict.values())
|
|
19
|
+
props.entries.forEach((entry, i) => {
|
|
20
|
+
entry.alias = EndpointUtil.escapeDuplicate(
|
|
21
|
+
[
|
|
22
|
+
...props.children,
|
|
23
|
+
...props.entries.filter((_, j) => i !== j).map((e) => e.alias),
|
|
24
|
+
].map(EndpointUtil.normalize),
|
|
25
|
+
)(EndpointUtil.normalize(entry.alias));
|
|
26
|
+
|
|
27
|
+
const parameters: { name: string; key: string }[] = [
|
|
28
|
+
...entry.route.parameters,
|
|
29
|
+
...(entry.route.body ? [entry.route.body] : []),
|
|
30
|
+
...(entry.route.headers ? [entry.route.headers] : []),
|
|
31
|
+
...(entry.route.query ? [entry.route.query] : []),
|
|
32
|
+
];
|
|
33
|
+
parameters.forEach(
|
|
34
|
+
(p, i) =>
|
|
35
|
+
(p.key = EndpointUtil.escapeDuplicate([
|
|
36
|
+
"connection",
|
|
37
|
+
entry.alias,
|
|
38
|
+
...parameters.filter((_, j) => i !== j).map((y) => y.key),
|
|
39
|
+
])(p.key)),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const accessor: string[] | undefined =
|
|
43
|
+
entry.route.operation()["x-samchon-accessor"];
|
|
44
|
+
if (accessor !== undefined && predefined.get(accessor.join(".")) === 1)
|
|
45
|
+
entry.route.accessor = accessor;
|
|
46
|
+
else entry.route.accessor = [...props.namespace, entry.alias];
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
for (const x of routes) {
|
|
50
|
+
while (true) {
|
|
51
|
+
const neighbor: IHttpMigrateRoute | undefined = routes.find(
|
|
52
|
+
(y) =>
|
|
53
|
+
y.accessor.length < x.accessor.length &&
|
|
54
|
+
x.accessor
|
|
55
|
+
.slice(0, y.accessor.length)
|
|
56
|
+
.every((v, i) => v === y.accessor[i]),
|
|
57
|
+
);
|
|
58
|
+
if (neighbor === undefined) break;
|
|
59
|
+
x.accessor[neighbor.accessor.length - 1] =
|
|
60
|
+
`_${x.accessor[neighbor.accessor.length - 1]}`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const collect =
|
|
66
|
+
(getter: (r: IHttpMigrateRoute) => string[]) =>
|
|
67
|
+
(routes: IHttpMigrateRoute[]): Map<string, IElement> => {
|
|
68
|
+
const dict: Map<string, IElement> = new Map();
|
|
69
|
+
for (const r of routes) {
|
|
70
|
+
const namespace: string[] = getter(r);
|
|
71
|
+
let last: IElement = MapUtil.take(dict, namespace.join("."), () => ({
|
|
72
|
+
namespace,
|
|
73
|
+
children: new Set(),
|
|
74
|
+
entries: [],
|
|
75
|
+
}));
|
|
76
|
+
last.entries.push({
|
|
77
|
+
route: r,
|
|
78
|
+
alias: getName(r),
|
|
79
|
+
});
|
|
80
|
+
namespace.slice(0, -1).forEach((_i, i, array) => {
|
|
81
|
+
const partial: string[] = namespace.slice(0, array.length - i);
|
|
82
|
+
const element: IElement = MapUtil.take(
|
|
83
|
+
dict,
|
|
84
|
+
partial.join("."),
|
|
85
|
+
() => ({
|
|
86
|
+
namespace: partial,
|
|
87
|
+
children: new Set(),
|
|
88
|
+
entries: [],
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
element.children.add(last.namespace.at(-1)!);
|
|
92
|
+
});
|
|
93
|
+
const top: IElement = MapUtil.take(dict, "", () => ({
|
|
94
|
+
namespace: [],
|
|
95
|
+
children: new Set(),
|
|
96
|
+
entries: [],
|
|
97
|
+
}));
|
|
98
|
+
if (namespace.length) top.children.add(namespace[0]!);
|
|
99
|
+
}
|
|
100
|
+
return dict;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const getName = (op: IHttpMigrateRoute): string => {
|
|
104
|
+
const method = op.method === "delete" ? "erase" : op.method;
|
|
105
|
+
if (op.parameters.length === 0) return method;
|
|
106
|
+
return (
|
|
107
|
+
method +
|
|
108
|
+
"By" +
|
|
109
|
+
op.parameters.map((p) => EndpointUtil.capitalize(p.key)).join("And")
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const getPredefinedAccessors = (
|
|
114
|
+
routes: IHttpMigrateRoute[],
|
|
115
|
+
): Map<string, number> => {
|
|
116
|
+
const dict: Map<string, number> = new Map();
|
|
117
|
+
for (const r of routes) {
|
|
118
|
+
const accessor = r.operation()["x-samchon-accessor"]?.join(".");
|
|
119
|
+
if (accessor === undefined) continue;
|
|
120
|
+
else if (dict.has(accessor)) dict.set(accessor, dict.get(accessor)! + 1);
|
|
121
|
+
else dict.set(accessor, 1);
|
|
122
|
+
}
|
|
123
|
+
return dict;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
interface IElement {
|
|
127
|
+
namespace: string[];
|
|
128
|
+
entries: IEntry[];
|
|
129
|
+
children: Set<string>;
|
|
130
|
+
}
|
|
131
|
+
interface IEntry {
|
|
132
|
+
route: IHttpMigrateRoute;
|
|
133
|
+
alias: string;
|
|
134
|
+
}
|
|
135
|
+
}
|