@nestia/sdk 12.0.0-dev.20260601.1 → 12.0.0-dev.20260612.2
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/LICENSE +21 -21
- package/README.md +93 -93
- package/assets/bundle/api/HttpError.ts +1 -1
- package/assets/bundle/api/IConnection.ts +1 -1
- package/assets/bundle/api/Primitive.ts +1 -1
- package/assets/bundle/api/Resolved.ts +1 -1
- package/assets/bundle/api/index.ts +4 -4
- package/assets/bundle/api/module.ts +6 -6
- package/assets/bundle/distribute/README.md +37 -37
- package/assets/bundle/distribute/package.json +28 -28
- package/assets/bundle/distribute/tsconfig.json +109 -109
- package/assets/bundle/e2e/index.ts +42 -42
- package/assets/config/nestia.config.ts +97 -97
- package/lib/NestiaSdkApplication.js +29 -7
- package/lib/NestiaSdkApplication.js.map +1 -1
- package/lib/NestiaSwaggerComposer.js +21 -13
- package/lib/NestiaSwaggerComposer.js.map +1 -1
- package/lib/analyses/AccessorAnalyzer.d.ts +4 -1
- package/lib/analyses/AccessorAnalyzer.js.map +1 -1
- package/lib/analyses/ConfigAnalyzer.js +1 -1
- package/lib/analyses/PathAnalyzer.d.ts +18 -3
- package/lib/analyses/PathAnalyzer.js +32 -0
- package/lib/analyses/PathAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectControllerAnalyzer.js +3 -2
- package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationAnalyzer.d.ts +1 -1
- package/lib/analyses/ReflectHttpOperationAnalyzer.js +1 -1
- package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.d.ts +1 -1
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +53 -20
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectMcpOperationAnalyzer.d.ts +14 -0
- package/lib/analyses/ReflectMcpOperationAnalyzer.js +79 -0
- package/lib/analyses/ReflectMcpOperationAnalyzer.js.map +1 -0
- package/lib/analyses/TypedMcpRouteAnalyzer.d.ts +9 -0
- package/lib/analyses/TypedMcpRouteAnalyzer.js +31 -0
- package/lib/analyses/TypedMcpRouteAnalyzer.js.map +1 -0
- package/lib/executable/internal/NestiaConfigLoader.js +5 -1
- package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
- package/lib/executable/internal/NestiaSdkCommand.js +30 -14
- package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
- package/lib/executable/internal/NestiaSdkWatcher.d.ts +10 -0
- package/lib/executable/internal/NestiaSdkWatcher.js +322 -0
- package/lib/executable/internal/NestiaSdkWatcher.js.map +1 -0
- package/lib/executable/sdk.js +12 -12
- package/lib/executable/sdk.js.map +1 -1
- package/lib/generates/CloneGenerator.js +4 -2
- package/lib/generates/CloneGenerator.js.map +1 -1
- package/lib/generates/SdkGenerator.js +50 -1
- package/lib/generates/SdkGenerator.js.map +1 -1
- package/lib/generates/SwaggerGenerator.js +18 -2
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.js +3 -1
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/generates/internal/ImportDictionary.d.ts +1 -0
- package/lib/generates/internal/ImportDictionary.js +9 -4
- package/lib/generates/internal/ImportDictionary.js.map +1 -1
- package/lib/generates/internal/SdkAliasCollection.d.ts +2 -0
- package/lib/generates/internal/SdkAliasCollection.js +11 -2
- package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
- package/lib/generates/internal/SdkDistributionComposer.d.ts +1 -0
- package/lib/generates/internal/SdkDistributionComposer.js +3 -0
- package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
- package/lib/generates/internal/SdkFileProgrammer.js +4 -1
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpCloneReferencer.d.ts +1 -1
- package/lib/generates/internal/SdkHttpCloneReferencer.js +42 -9
- package/lib/generates/internal/SdkHttpCloneReferencer.js.map +1 -1
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js +3 -4
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +2 -1
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js +6 -3
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkMcpRouteProgrammer.d.ts +15 -0
- package/lib/generates/internal/SdkMcpRouteProgrammer.js +148 -0
- package/lib/generates/internal/SdkMcpRouteProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkRouteDirectory.d.ts +2 -1
- package/lib/generates/internal/SdkRouteDirectory.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketCloneProgrammer.d.ts +6 -0
- package/lib/generates/internal/SdkWebSocketCloneProgrammer.js +283 -0
- package/lib/generates/internal/SdkWebSocketCloneProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +11 -9
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationParameterComposer.js +10 -2
- package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationResponseComposer.d.ts +1 -1
- package/lib/generates/internal/SwaggerOperationResponseComposer.js +6 -1
- package/lib/generates/internal/SwaggerOperationResponseComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerReadonlyArrayEmender.d.ts +9 -0
- package/lib/generates/internal/SwaggerReadonlyArrayEmender.js +174 -0
- package/lib/generates/internal/SwaggerReadonlyArrayEmender.js.map +1 -0
- package/lib/structures/INestiaSdkInput.d.ts +9 -2
- package/lib/structures/IReflectController.d.ts +2 -1
- package/lib/structures/IReflectHttpOperationSuccess.d.ts +4 -2
- package/lib/structures/IReflectMcpOperation.d.ts +35 -0
- package/lib/structures/IReflectMcpOperation.js +3 -0
- package/lib/structures/IReflectMcpOperation.js.map +1 -0
- package/lib/structures/IReflectMcpOperationParameter.d.ts +19 -0
- package/lib/structures/IReflectMcpOperationParameter.js +3 -0
- package/lib/structures/IReflectMcpOperationParameter.js.map +1 -0
- package/lib/structures/ITypedApplication.d.ts +2 -1
- package/lib/structures/ITypedHttpRouteSuccess.d.ts +3 -1
- package/lib/structures/ITypedMcpRoute.d.ts +31 -0
- package/lib/structures/ITypedMcpRoute.js +3 -0
- package/lib/structures/ITypedMcpRoute.js.map +1 -0
- package/lib/utils/HttpResponseContentTypeUtil.d.ts +5 -0
- package/lib/utils/HttpResponseContentTypeUtil.js +22 -0
- package/lib/utils/HttpResponseContentTypeUtil.js.map +1 -0
- package/native/go.mod +52 -52
- package/native/go.sum +84 -54
- package/native/sdk/register.go +322 -165
- package/native/sdk/sdk.go +17 -17
- package/native/sdk/sdk_metadata_json.go +327 -327
- package/native/sdk/sdk_transform.go +1879 -1549
- package/package.json +11 -9
- package/src/INestiaConfig.ts +267 -267
- package/src/NestiaSdkApplication.ts +39 -8
- package/src/NestiaSwaggerComposer.ts +153 -142
- package/src/analyses/AccessorAnalyzer.ts +64 -67
- package/src/analyses/ConfigAnalyzer.ts +330 -330
- package/src/analyses/ImportAnalyzer.ts +92 -92
- package/src/analyses/PathAnalyzer.ts +130 -69
- package/src/analyses/ReflectControllerAnalyzer.ts +112 -105
- package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
- package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +90 -90
- package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +350 -350
- package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +163 -130
- package/src/analyses/ReflectMcpOperationAnalyzer.ts +124 -0
- package/src/analyses/ReflectMetadataAnalyzer.ts +44 -44
- package/src/analyses/SecurityAnalyzer.ts +25 -25
- package/src/analyses/TypedMcpRouteAnalyzer.ts +34 -0
- package/src/decorators/OperationMetadata.ts +29 -29
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/executable/internal/NestiaConfigLoader.ts +451 -446
- package/src/executable/internal/NestiaSdkCommand.ts +124 -106
- package/src/executable/internal/NestiaSdkWatcher.ts +342 -0
- package/src/executable/sdk.ts +90 -88
- package/src/generates/CloneGenerator.ts +73 -66
- package/src/generates/E2eGenerator.ts +32 -32
- package/src/generates/SdkGenerator.ts +176 -118
- package/src/generates/SwaggerGenerator.ts +342 -310
- package/src/generates/internal/E2eFileProgrammer.ts +240 -233
- package/src/generates/internal/FilePrinter.ts +65 -65
- package/src/generates/internal/ImportDictionary.ts +209 -204
- package/src/generates/internal/SdkAliasCollection.ts +274 -261
- package/src/generates/internal/SdkDistributionComposer.ts +123 -116
- package/src/generates/internal/SdkFileProgrammer.ts +116 -112
- package/src/generates/internal/SdkHttpCloneProgrammer.ts +126 -126
- package/src/generates/internal/SdkHttpCloneReferencer.ts +131 -77
- package/src/generates/internal/SdkHttpFunctionProgrammer.ts +301 -301
- package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +520 -510
- package/src/generates/internal/SdkHttpParameterProgrammer.ts +165 -165
- package/src/generates/internal/SdkHttpRouteProgrammer.ts +109 -109
- package/src/generates/internal/SdkHttpSimulationProgrammer.ts +331 -314
- package/src/generates/internal/SdkImportWizard.ts +62 -62
- package/src/generates/internal/SdkMcpRouteProgrammer.ts +452 -0
- package/src/generates/internal/SdkRouteDirectory.ts +21 -18
- package/src/generates/internal/SdkTypeTagProgrammer.ts +114 -114
- package/src/generates/internal/SdkWebSocketCloneProgrammer.ts +319 -0
- package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +389 -389
- package/src/generates/internal/SdkWebSocketParameterProgrammer.ts +89 -89
- package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +331 -323
- package/src/generates/internal/SwaggerDescriptionComposer.ts +64 -64
- package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
- package/src/generates/internal/SwaggerOperationParameterComposer.ts +175 -162
- package/src/generates/internal/SwaggerOperationResponseComposer.ts +115 -110
- package/src/generates/internal/SwaggerReadonlyArrayEmender.ts +262 -0
- package/src/index.ts +4 -4
- package/src/internal/legacy.ts +492 -492
- package/src/module.ts +4 -4
- package/src/structures/INestiaProject.ts +10 -10
- package/src/structures/INestiaSdkInput.ts +27 -20
- package/src/structures/IOperationMetadata.ts +41 -41
- package/src/structures/IReflectController.ts +18 -15
- package/src/structures/IReflectHttpOperation.ts +26 -26
- package/src/structures/IReflectHttpOperationException.ts +18 -18
- package/src/structures/IReflectHttpOperationParameter.ts +79 -79
- package/src/structures/IReflectHttpOperationSuccess.ts +18 -21
- package/src/structures/IReflectImport.ts +6 -6
- package/src/structures/IReflectMcpOperation.ts +38 -0
- package/src/structures/IReflectMcpOperationParameter.ts +27 -0
- package/src/structures/IReflectOperationError.ts +26 -26
- package/src/structures/IReflectType.ts +4 -4
- package/src/structures/IReflectWebSocketOperation.ts +17 -17
- package/src/structures/ITypedApplication.ts +12 -11
- package/src/structures/ITypedHttpRoute.ts +41 -41
- package/src/structures/ITypedHttpRouteException.ts +15 -15
- package/src/structures/ITypedHttpRouteParameter.ts +41 -41
- package/src/structures/ITypedHttpRouteSuccess.ts +18 -22
- package/src/structures/ITypedMcpRoute.ts +33 -0
- package/src/structures/ITypedWebSocketRoute.ts +24 -24
- package/src/structures/ITypedWebSocketRouteParameter.ts +3 -3
- package/src/transform.ts +59 -59
- package/src/typings/get-function-location.d.ts +7 -7
- package/src/utils/ArrayUtil.ts +26 -26
- package/src/utils/EmittedJavaScriptPatcher.ts +88 -88
- package/src/utils/FileRetriever.ts +22 -22
- package/src/utils/HttpResponseContentTypeUtil.ts +30 -0
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PathUtil.ts +10 -10
- package/src/utils/SourceFinder.ts +63 -63
- package/src/utils/StringUtil.ts +17 -17
- package/src/utils/TsConfigReader.ts +108 -108
- package/src/utils/TtscExecutor.ts +68 -68
- package/src/utils/VersioningStrategy.ts +28 -28
- package/src/validators/HttpHeadersValidator.ts +11 -11
- package/src/validators/HttpQueryValidator.ts +11 -11
- package/src/validators/TextPlainValidator.ts +17 -17
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
import { TypeScriptFactory } from "@nestia/factory";
|
|
2
|
-
import { LiteralFactory } from "@nestia/factory";
|
|
3
|
-
import { IMetadataTypeTag } from "@typia/interface";
|
|
4
|
-
|
|
5
|
-
import { ImportDictionary } from "./ImportDictionary";
|
|
6
|
-
|
|
7
|
-
export namespace SdkTypeTagProgrammer {
|
|
8
|
-
export const write = (
|
|
9
|
-
importer: ImportDictionary,
|
|
10
|
-
from: "object" | "array" | "boolean" | "number" | "bigint" | "string",
|
|
11
|
-
tag: IMetadataTypeTag,
|
|
12
|
-
) => {
|
|
13
|
-
const name: string = tag.name.split("<")[0]!;
|
|
14
|
-
if (PREDEFINED[from]?.has(name) === true)
|
|
15
|
-
return TypeScriptFactory.createTypeReferenceNode(
|
|
16
|
-
TypeScriptFactory.createQualifiedName(
|
|
17
|
-
TypeScriptFactory.createIdentifier(
|
|
18
|
-
importer.external({
|
|
19
|
-
declaration: true,
|
|
20
|
-
file: `typia`,
|
|
21
|
-
type: "element",
|
|
22
|
-
name: "tags",
|
|
23
|
-
}),
|
|
24
|
-
),
|
|
25
|
-
TypeScriptFactory.createIdentifier(name),
|
|
26
|
-
),
|
|
27
|
-
[
|
|
28
|
-
TypeScriptFactory.createLiteralTypeNode(
|
|
29
|
-
LiteralFactory.write(tag.value) as any,
|
|
30
|
-
),
|
|
31
|
-
],
|
|
32
|
-
);
|
|
33
|
-
return TypeScriptFactory.createTypeReferenceNode(
|
|
34
|
-
TypeScriptFactory.createQualifiedName(
|
|
35
|
-
TypeScriptFactory.createIdentifier(
|
|
36
|
-
importer.external({
|
|
37
|
-
declaration: true,
|
|
38
|
-
file: `typia`,
|
|
39
|
-
type: "element",
|
|
40
|
-
name: "tags",
|
|
41
|
-
}),
|
|
42
|
-
),
|
|
43
|
-
TypeScriptFactory.createIdentifier("TagBase"),
|
|
44
|
-
),
|
|
45
|
-
[
|
|
46
|
-
TypeScriptFactory.createLiteralTypeNode(
|
|
47
|
-
LiteralFactory.write({
|
|
48
|
-
target: from,
|
|
49
|
-
kind: tag.kind,
|
|
50
|
-
value: tag.value,
|
|
51
|
-
validate: tag.validate,
|
|
52
|
-
exclusive: tag.exclusive,
|
|
53
|
-
schema: tag.schema,
|
|
54
|
-
}) as any,
|
|
55
|
-
),
|
|
56
|
-
],
|
|
57
|
-
);
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const COMMON_KINDS = ["Default", "Example", "Examples", "Sequence"];
|
|
62
|
-
const PREDEFINED = {
|
|
63
|
-
object: new Set([...COMMON_KINDS]),
|
|
64
|
-
array: new Set([...COMMON_KINDS, "MinItems", "MaxItems", "UniqueItems"]),
|
|
65
|
-
boolean: new Set([...COMMON_KINDS]),
|
|
66
|
-
number: new Set([
|
|
67
|
-
...COMMON_KINDS,
|
|
68
|
-
"Minimum",
|
|
69
|
-
"Maximum",
|
|
70
|
-
"ExclusiveMinimum",
|
|
71
|
-
"ExclusiveMaximum",
|
|
72
|
-
"MultipleOf",
|
|
73
|
-
"Type",
|
|
74
|
-
]),
|
|
75
|
-
bigint: new Set([
|
|
76
|
-
...COMMON_KINDS,
|
|
77
|
-
"Minimum",
|
|
78
|
-
"Maximum",
|
|
79
|
-
"ExclusiveMinimum",
|
|
80
|
-
"ExclusiveMaximum",
|
|
81
|
-
"MultipleOf",
|
|
82
|
-
"Type",
|
|
83
|
-
]),
|
|
84
|
-
string: new Set([
|
|
85
|
-
...COMMON_KINDS,
|
|
86
|
-
"ContentMediaType",
|
|
87
|
-
"Format",
|
|
88
|
-
"MaxLength",
|
|
89
|
-
"MinLength",
|
|
90
|
-
"Pattern",
|
|
91
|
-
]),
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
// export * from "./Constant";
|
|
95
|
-
// export * from "./ContentMediaType";
|
|
96
|
-
// export * from "./Default";
|
|
97
|
-
// export * from "./Example";
|
|
98
|
-
// export * from "./Examples";
|
|
99
|
-
// export * from "./ExclusiveMaximum";
|
|
100
|
-
// export * from "./ExclusiveMinimum";
|
|
101
|
-
// export * from "./Format";
|
|
102
|
-
// export * from "./JsonSchemaPlugin";
|
|
103
|
-
// export * from "./Maximum";
|
|
104
|
-
// export * from "./MaxItems";
|
|
105
|
-
// export * from "./MaxLength";
|
|
106
|
-
// export * from "./Minimum";
|
|
107
|
-
// export * from "./MinItems";
|
|
108
|
-
// export * from "./MinLength";
|
|
109
|
-
// export * from "./MultipleOf";
|
|
110
|
-
// export * from "./Pattern";
|
|
111
|
-
// export * from "./Sequence";
|
|
112
|
-
// export * from "./TagBase";
|
|
113
|
-
// export * from "./Type";
|
|
114
|
-
// export * from "./UniqueItems";
|
|
1
|
+
import { TypeScriptFactory } from "@nestia/factory";
|
|
2
|
+
import { LiteralFactory } from "@nestia/factory";
|
|
3
|
+
import { IMetadataTypeTag } from "@typia/interface";
|
|
4
|
+
|
|
5
|
+
import { ImportDictionary } from "./ImportDictionary";
|
|
6
|
+
|
|
7
|
+
export namespace SdkTypeTagProgrammer {
|
|
8
|
+
export const write = (
|
|
9
|
+
importer: ImportDictionary,
|
|
10
|
+
from: "object" | "array" | "boolean" | "number" | "bigint" | "string",
|
|
11
|
+
tag: IMetadataTypeTag,
|
|
12
|
+
) => {
|
|
13
|
+
const name: string = tag.name.split("<")[0]!;
|
|
14
|
+
if (PREDEFINED[from]?.has(name) === true)
|
|
15
|
+
return TypeScriptFactory.createTypeReferenceNode(
|
|
16
|
+
TypeScriptFactory.createQualifiedName(
|
|
17
|
+
TypeScriptFactory.createIdentifier(
|
|
18
|
+
importer.external({
|
|
19
|
+
declaration: true,
|
|
20
|
+
file: `typia`,
|
|
21
|
+
type: "element",
|
|
22
|
+
name: "tags",
|
|
23
|
+
}),
|
|
24
|
+
),
|
|
25
|
+
TypeScriptFactory.createIdentifier(name),
|
|
26
|
+
),
|
|
27
|
+
[
|
|
28
|
+
TypeScriptFactory.createLiteralTypeNode(
|
|
29
|
+
LiteralFactory.write(tag.value) as any,
|
|
30
|
+
),
|
|
31
|
+
],
|
|
32
|
+
);
|
|
33
|
+
return TypeScriptFactory.createTypeReferenceNode(
|
|
34
|
+
TypeScriptFactory.createQualifiedName(
|
|
35
|
+
TypeScriptFactory.createIdentifier(
|
|
36
|
+
importer.external({
|
|
37
|
+
declaration: true,
|
|
38
|
+
file: `typia`,
|
|
39
|
+
type: "element",
|
|
40
|
+
name: "tags",
|
|
41
|
+
}),
|
|
42
|
+
),
|
|
43
|
+
TypeScriptFactory.createIdentifier("TagBase"),
|
|
44
|
+
),
|
|
45
|
+
[
|
|
46
|
+
TypeScriptFactory.createLiteralTypeNode(
|
|
47
|
+
LiteralFactory.write({
|
|
48
|
+
target: from,
|
|
49
|
+
kind: tag.kind,
|
|
50
|
+
value: tag.value,
|
|
51
|
+
validate: tag.validate,
|
|
52
|
+
exclusive: tag.exclusive,
|
|
53
|
+
schema: tag.schema,
|
|
54
|
+
}) as any,
|
|
55
|
+
),
|
|
56
|
+
],
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const COMMON_KINDS = ["Default", "Example", "Examples", "Sequence"];
|
|
62
|
+
const PREDEFINED = {
|
|
63
|
+
object: new Set([...COMMON_KINDS]),
|
|
64
|
+
array: new Set([...COMMON_KINDS, "MinItems", "MaxItems", "UniqueItems"]),
|
|
65
|
+
boolean: new Set([...COMMON_KINDS]),
|
|
66
|
+
number: new Set([
|
|
67
|
+
...COMMON_KINDS,
|
|
68
|
+
"Minimum",
|
|
69
|
+
"Maximum",
|
|
70
|
+
"ExclusiveMinimum",
|
|
71
|
+
"ExclusiveMaximum",
|
|
72
|
+
"MultipleOf",
|
|
73
|
+
"Type",
|
|
74
|
+
]),
|
|
75
|
+
bigint: new Set([
|
|
76
|
+
...COMMON_KINDS,
|
|
77
|
+
"Minimum",
|
|
78
|
+
"Maximum",
|
|
79
|
+
"ExclusiveMinimum",
|
|
80
|
+
"ExclusiveMaximum",
|
|
81
|
+
"MultipleOf",
|
|
82
|
+
"Type",
|
|
83
|
+
]),
|
|
84
|
+
string: new Set([
|
|
85
|
+
...COMMON_KINDS,
|
|
86
|
+
"ContentMediaType",
|
|
87
|
+
"Format",
|
|
88
|
+
"MaxLength",
|
|
89
|
+
"MinLength",
|
|
90
|
+
"Pattern",
|
|
91
|
+
]),
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// export * from "./Constant";
|
|
95
|
+
// export * from "./ContentMediaType";
|
|
96
|
+
// export * from "./Default";
|
|
97
|
+
// export * from "./Example";
|
|
98
|
+
// export * from "./Examples";
|
|
99
|
+
// export * from "./ExclusiveMaximum";
|
|
100
|
+
// export * from "./ExclusiveMinimum";
|
|
101
|
+
// export * from "./Format";
|
|
102
|
+
// export * from "./JsonSchemaPlugin";
|
|
103
|
+
// export * from "./Maximum";
|
|
104
|
+
// export * from "./MaxItems";
|
|
105
|
+
// export * from "./MaxLength";
|
|
106
|
+
// export * from "./Minimum";
|
|
107
|
+
// export * from "./MinItems";
|
|
108
|
+
// export * from "./MinLength";
|
|
109
|
+
// export * from "./MultipleOf";
|
|
110
|
+
// export * from "./Pattern";
|
|
111
|
+
// export * from "./Sequence";
|
|
112
|
+
// export * from "./TagBase";
|
|
113
|
+
// export * from "./Type";
|
|
114
|
+
// export * from "./UniqueItems";
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
import { ITypedApplication } from "../../structures/ITypedApplication";
|
|
5
|
+
|
|
6
|
+
export namespace SdkWebSocketCloneProgrammer {
|
|
7
|
+
export const write = async (app: ITypedApplication): Promise<Set<string>> => {
|
|
8
|
+
const ctx: IContext = {
|
|
9
|
+
output: `${app.project.config.output}/structures`,
|
|
10
|
+
outputs: new Map(),
|
|
11
|
+
visited: new Map(),
|
|
12
|
+
};
|
|
13
|
+
const cloned: Set<string> = new Set();
|
|
14
|
+
for (const route of app.routes)
|
|
15
|
+
if (route.protocol === "websocket")
|
|
16
|
+
for (const imp of route.imports)
|
|
17
|
+
for (const name of imp.elements) {
|
|
18
|
+
if (await clone(ctx)(imp.file, name))
|
|
19
|
+
cloned.add(importKey(imp.file, name));
|
|
20
|
+
}
|
|
21
|
+
return cloned;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const clone =
|
|
25
|
+
(ctx: IContext) =>
|
|
26
|
+
async (file: string, name: string): Promise<boolean> => {
|
|
27
|
+
const location: string | null = await resolveSourceFile(file);
|
|
28
|
+
if (location === null || isNodeModulesPath(location)) return false;
|
|
29
|
+
|
|
30
|
+
const key: string = `${location}#${name}`;
|
|
31
|
+
const status: CloneStatus | undefined = ctx.visited.get(key);
|
|
32
|
+
if (status === "written" || status === "pending") return true;
|
|
33
|
+
else if (status === "missing") return false;
|
|
34
|
+
ctx.visited.set(key, "pending");
|
|
35
|
+
|
|
36
|
+
const text: string = await fs.promises.readFile(location, "utf8");
|
|
37
|
+
const declarations: string[] = getDeclarations(text, name);
|
|
38
|
+
if (declarations.length === 0) {
|
|
39
|
+
ctx.visited.set(key, "missing");
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const body: string = declarations.join("\n\n");
|
|
44
|
+
const imports: string[] = await collectImports(ctx)({
|
|
45
|
+
body,
|
|
46
|
+
location,
|
|
47
|
+
source: text,
|
|
48
|
+
target: name,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const content: string =
|
|
52
|
+
[...imports, body].filter((line) => line.length).join("\n\n") + "\n";
|
|
53
|
+
const oldbie: string | undefined = ctx.outputs.get(name);
|
|
54
|
+
if (oldbie !== undefined && oldbie !== content) {
|
|
55
|
+
ctx.visited.set(key, "missing");
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
ctx.outputs.set(name, content);
|
|
59
|
+
|
|
60
|
+
await fs.promises.mkdir(ctx.output, { recursive: true });
|
|
61
|
+
await fs.promises.writeFile(`${ctx.output}/${name}.ts`, content, "utf8");
|
|
62
|
+
ctx.visited.set(key, "written");
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const collectImports =
|
|
67
|
+
(ctx: IContext) =>
|
|
68
|
+
async (props: {
|
|
69
|
+
body: string;
|
|
70
|
+
location: string;
|
|
71
|
+
source: string;
|
|
72
|
+
target: string;
|
|
73
|
+
}): Promise<string[]> => {
|
|
74
|
+
const imports: string[] = [];
|
|
75
|
+
const add = (line: string): void => {
|
|
76
|
+
if (imports.includes(line) === false) imports.push(line);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
for (const imp of getImports(props.source)) {
|
|
80
|
+
const relative: boolean = imp.specifier.startsWith(".");
|
|
81
|
+
for (const elem of imp.elements) {
|
|
82
|
+
if (uses(props.body, elem.local) === false) continue;
|
|
83
|
+
|
|
84
|
+
if (relative === false) {
|
|
85
|
+
add(imp.text);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const sourceFile: string = path.resolve(
|
|
90
|
+
path.dirname(props.location),
|
|
91
|
+
imp.specifier,
|
|
92
|
+
);
|
|
93
|
+
if ((await clone(ctx)(sourceFile, elem.imported)) === false) {
|
|
94
|
+
add(imp.text);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
add(
|
|
98
|
+
`import type { ${elem.imported}${elem.imported === elem.local ? "" : ` as ${elem.local}`} } from "./${elem.imported}";`,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
for (const name of [imp.default, imp.namespace])
|
|
102
|
+
if (name !== null && uses(props.body, name)) add(imp.text);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
for (const name of getExportedNames(props.source)) {
|
|
106
|
+
if (name === null || name === props.target) continue;
|
|
107
|
+
if (uses(props.body, name) === false) continue;
|
|
108
|
+
if ((await clone(ctx)(props.location, name)) === true)
|
|
109
|
+
add(`import type { ${name} } from "./${name}";`);
|
|
110
|
+
}
|
|
111
|
+
return imports.sort();
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const resolveSourceFile = async (file: string): Promise<string | null> => {
|
|
115
|
+
const base: string = trimRuntimeExtension(file);
|
|
116
|
+
const candidates: string[] = [
|
|
117
|
+
file,
|
|
118
|
+
base,
|
|
119
|
+
`${base}.ts`,
|
|
120
|
+
`${base}.tsx`,
|
|
121
|
+
`${base}.d.ts`,
|
|
122
|
+
path.join(base, "index.ts"),
|
|
123
|
+
path.join(base, "index.d.ts"),
|
|
124
|
+
];
|
|
125
|
+
for (const candidate of candidates) {
|
|
126
|
+
try {
|
|
127
|
+
const location: string = path.resolve(candidate);
|
|
128
|
+
const stat: fs.Stats = await fs.promises.stat(location);
|
|
129
|
+
if (stat.isFile()) return location;
|
|
130
|
+
} catch {}
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const trimRuntimeExtension = (file: string): string => {
|
|
136
|
+
for (const ext of [".js", ".jsx", ".mjs", ".cjs"])
|
|
137
|
+
if (file.endsWith(ext)) return file.slice(0, -ext.length);
|
|
138
|
+
return file;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const getDeclarations = (source: string, name: string): string[] => {
|
|
142
|
+
const output: string[] = [];
|
|
143
|
+
const searchable: string = maskTrivia(source);
|
|
144
|
+
const regex: RegExp = declarationRegex(name);
|
|
145
|
+
for (const match of searchable.matchAll(regex)) {
|
|
146
|
+
if (isTopLevel(searchable, match.index!) === false) continue;
|
|
147
|
+
const end: number = declarationEnd(searchable, match.index!, match[1]!);
|
|
148
|
+
if (end !== -1) output.push(source.slice(match.index!, end).trim());
|
|
149
|
+
}
|
|
150
|
+
return output;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const getExportedNames = (source: string): string[] => {
|
|
154
|
+
const searchable: string = maskTrivia(source);
|
|
155
|
+
return Array.from(
|
|
156
|
+
searchable.matchAll(declarationRegex("[A-Za-z_$][\\w$]*")),
|
|
157
|
+
)
|
|
158
|
+
.filter((match) => isTopLevel(searchable, match.index!))
|
|
159
|
+
.map((match) => match[2]!);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const declarationRegex = (name: string): RegExp =>
|
|
163
|
+
new RegExp(
|
|
164
|
+
`export\\s+(?:declare\\s+)?(interface|type|enum|namespace|class)\\s+(${name})\\b`,
|
|
165
|
+
"g",
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
const declarationEnd = (
|
|
169
|
+
source: string,
|
|
170
|
+
start: number,
|
|
171
|
+
kind: string,
|
|
172
|
+
): number => {
|
|
173
|
+
let depth: number = 0;
|
|
174
|
+
let block: boolean = false;
|
|
175
|
+
for (let i = start; i < source.length; ++i) {
|
|
176
|
+
const ch: string = source[i]!;
|
|
177
|
+
if (ch === "{") {
|
|
178
|
+
++depth;
|
|
179
|
+
block = true;
|
|
180
|
+
} else if (ch === "}") {
|
|
181
|
+
--depth;
|
|
182
|
+
if (kind !== "type" && block && depth === 0) return i + 1;
|
|
183
|
+
} else if (ch === ";" && block === false && depth === 0) return i + 1;
|
|
184
|
+
else if (ch === ";" && kind === "type" && depth === 0) return i + 1;
|
|
185
|
+
}
|
|
186
|
+
return -1;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const isTopLevel = (source: string, index: number): boolean => {
|
|
190
|
+
let depth: number = 0;
|
|
191
|
+
for (let i = 0; i < index; ++i) {
|
|
192
|
+
const ch: string = source[i]!;
|
|
193
|
+
if (ch === "{") ++depth;
|
|
194
|
+
else if (ch === "}") --depth;
|
|
195
|
+
}
|
|
196
|
+
return depth === 0;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const maskTrivia = (source: string): string => {
|
|
200
|
+
const out: string[] = source.split("");
|
|
201
|
+
const mask = (index: number): void => {
|
|
202
|
+
if (out[index] !== "\n" && out[index] !== "\r") out[index] = " ";
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
let quote: string | null = null;
|
|
206
|
+
let escaped: boolean = false;
|
|
207
|
+
for (let i = 0; i < out.length; ++i) {
|
|
208
|
+
const ch: string = source[i]!;
|
|
209
|
+
const next: string | undefined = source[i + 1];
|
|
210
|
+
if (quote !== null) {
|
|
211
|
+
mask(i);
|
|
212
|
+
if (escaped) escaped = false;
|
|
213
|
+
else if (ch === "\\") escaped = true;
|
|
214
|
+
else if (ch === quote) quote = null;
|
|
215
|
+
} else if (ch === "/" && next === "/") {
|
|
216
|
+
mask(i++);
|
|
217
|
+
for (; i < out.length && source[i] !== "\n"; ++i) mask(i);
|
|
218
|
+
--i;
|
|
219
|
+
} else if (ch === "/" && next === "*") {
|
|
220
|
+
mask(i++);
|
|
221
|
+
mask(i);
|
|
222
|
+
for (++i; i < out.length; ++i) {
|
|
223
|
+
const current: string = source[i]!;
|
|
224
|
+
const following: string | undefined = source[i + 1];
|
|
225
|
+
mask(i);
|
|
226
|
+
if (current === "*" && following === "/") {
|
|
227
|
+
mask(++i);
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
} else if (ch === '"' || ch === "'" || ch === "`") {
|
|
232
|
+
quote = ch;
|
|
233
|
+
mask(i);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return out.join("");
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const getImports = (source: string): IImport[] =>
|
|
240
|
+
Array.from(
|
|
241
|
+
source.matchAll(/import\s+([\s\S]*?)\s+from\s+["']([^"']+)["'];?/g),
|
|
242
|
+
).map((match) => {
|
|
243
|
+
const clause: string = match[1]!.trim();
|
|
244
|
+
const specifier: string = match[2]!;
|
|
245
|
+
return {
|
|
246
|
+
text: match[0]!.trim(),
|
|
247
|
+
specifier,
|
|
248
|
+
default: defaultImportName(clause),
|
|
249
|
+
namespace: namespaceImportName(clause),
|
|
250
|
+
elements: namedImportElements(clause),
|
|
251
|
+
};
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const defaultImportName = (clause: string): string | null => {
|
|
255
|
+
const first: string = clause
|
|
256
|
+
.split(",")[0]!
|
|
257
|
+
.trim()
|
|
258
|
+
.replace(/^type\s+/, "");
|
|
259
|
+
return first.length && first.startsWith("{") === false ? first : null;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const namespaceImportName = (clause: string): string | null => {
|
|
263
|
+
const match: RegExpMatchArray | null = clause.match(/\*\s+as\s+(\w+)/);
|
|
264
|
+
return match?.[1] ?? null;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
const namedImportElements = (clause: string): IImportElement[] => {
|
|
268
|
+
const match: RegExpMatchArray | null = clause.match(/\{([\s\S]*?)\}/);
|
|
269
|
+
if (match === null) return [];
|
|
270
|
+
return match[1]!
|
|
271
|
+
.split(",")
|
|
272
|
+
.map((part) => part.trim().replace(/^type\s+/, ""))
|
|
273
|
+
.filter((part) => part.length)
|
|
274
|
+
.map((part) => {
|
|
275
|
+
const pieces: string[] = part.split(/\s+as\s+/);
|
|
276
|
+
const imported: string = pieces[0]!.trim();
|
|
277
|
+
return {
|
|
278
|
+
imported,
|
|
279
|
+
local: (pieces[1] ?? imported).trim(),
|
|
280
|
+
};
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const uses = (body: string, name: string): boolean =>
|
|
285
|
+
new RegExp(`\\b${escapeRegExp(name)}\\b`).test(body);
|
|
286
|
+
|
|
287
|
+
const escapeRegExp = (str: string): string =>
|
|
288
|
+
str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
289
|
+
|
|
290
|
+
export const importKey = (file: string, name: string): string =>
|
|
291
|
+
`${file}#${name}`;
|
|
292
|
+
|
|
293
|
+
export const isNodeModulesPath = (file: string): boolean =>
|
|
294
|
+
path
|
|
295
|
+
.resolve(file)
|
|
296
|
+
.split(/[\\/]+/)
|
|
297
|
+
.includes("node_modules");
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
interface IContext {
|
|
301
|
+
output: string;
|
|
302
|
+
outputs: Map<string, string>;
|
|
303
|
+
visited: Map<string, CloneStatus>;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
type CloneStatus = "pending" | "written" | "missing";
|
|
307
|
+
|
|
308
|
+
interface IImport {
|
|
309
|
+
text: string;
|
|
310
|
+
specifier: string;
|
|
311
|
+
default: string | null;
|
|
312
|
+
namespace: string | null;
|
|
313
|
+
elements: IImportElement[];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
interface IImportElement {
|
|
317
|
+
imported: string;
|
|
318
|
+
local: string;
|
|
319
|
+
}
|