@hadss/turbo-trans-json-plugin 1.0.0-rc.0
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 +177 -0
- package/README.md +253 -0
- package/dist/core/Types.d.ts +196 -0
- package/dist/core/Types.js +47 -0
- package/dist/core/analyzers/ClassAnalyzer.d.ts +23 -0
- package/dist/core/analyzers/ClassAnalyzer.js +480 -0
- package/dist/core/analyzers/CustomTypeAnalyzer.d.ts +21 -0
- package/dist/core/analyzers/CustomTypeAnalyzer.js +243 -0
- package/dist/core/analyzers/SendableMergeChecker.d.ts +9 -0
- package/dist/core/analyzers/SendableMergeChecker.js +100 -0
- package/dist/core/analyzers/SendableMergeabilityRegistry.d.ts +7 -0
- package/dist/core/analyzers/SendableMergeabilityRegistry.js +23 -0
- package/dist/core/constants/DecoratorConstants.d.ts +7 -0
- package/dist/core/constants/DecoratorConstants.js +13 -0
- package/dist/core/constants/PathConstants.d.ts +6 -0
- package/dist/core/constants/PathConstants.js +10 -0
- package/dist/core/constants/StringConstants.d.ts +83 -0
- package/dist/core/constants/StringConstants.js +87 -0
- package/dist/core/constants/index.d.ts +3 -0
- package/dist/core/constants/index.js +19 -0
- package/dist/core/handlers/BaseTypeHandler.d.ts +23 -0
- package/dist/core/handlers/BaseTypeHandler.js +57 -0
- package/dist/core/handlers/CustomClassHandler.d.ts +21 -0
- package/dist/core/handlers/CustomClassHandler.js +191 -0
- package/dist/core/handlers/DateHandler.d.ts +2 -0
- package/dist/core/handlers/DateHandler.js +60 -0
- package/dist/core/handlers/DecimalHandler.d.ts +2 -0
- package/dist/core/handlers/DecimalHandler.js +60 -0
- package/dist/core/handlers/EnumHandler.d.ts +2 -0
- package/dist/core/handlers/EnumHandler.js +89 -0
- package/dist/core/handlers/GenericContainerHandler.d.ts +2 -0
- package/dist/core/handlers/GenericContainerHandler.js +440 -0
- package/dist/core/handlers/GenericHandler.d.ts +18 -0
- package/dist/core/handlers/GenericHandler.js +92 -0
- package/dist/core/handlers/HandlerBootstrap.d.ts +2 -0
- package/dist/core/handlers/HandlerBootstrap.js +28 -0
- package/dist/core/handlers/ITypeHandler.d.ts +23 -0
- package/dist/core/handlers/ITypeHandler.js +8 -0
- package/dist/core/handlers/PrimitiveHandler.d.ts +2 -0
- package/dist/core/handlers/PrimitiveHandler.js +127 -0
- package/dist/core/handlers/TupleHandler.d.ts +2 -0
- package/dist/core/handlers/TupleHandler.js +98 -0
- package/dist/core/handlers/TypeHandlerRegistry.d.ts +20 -0
- package/dist/core/handlers/TypeHandlerRegistry.js +113 -0
- package/dist/core/handlers/UnionTypeHandler.d.ts +2 -0
- package/dist/core/handlers/UnionTypeHandler.js +263 -0
- package/dist/core/handlers/index.d.ts +2 -0
- package/dist/core/handlers/index.js +5 -0
- package/dist/core/import-rewrite/services/BuildProfileUpdater.d.ts +8 -0
- package/dist/core/import-rewrite/services/BuildProfileUpdater.js +92 -0
- package/dist/core/import-rewrite/services/ImportRewriteService.d.ts +9 -0
- package/dist/core/import-rewrite/services/ImportRewriteService.js +61 -0
- package/dist/core/import-rewrite/services/ImportTransformService.d.ts +15 -0
- package/dist/core/import-rewrite/services/ImportTransformService.js +109 -0
- package/dist/core/import-rewrite/strategies/ImportScanStrategy.d.ts +17 -0
- package/dist/core/import-rewrite/strategies/ImportScanStrategy.js +137 -0
- package/dist/core/import-rewrite/types/ImportRewriteTypes.d.ts +17 -0
- package/dist/core/import-rewrite/types/ImportRewriteTypes.js +2 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.js +27 -0
- package/dist/core/interfaces/ITask.d.ts +7 -0
- package/dist/core/interfaces/ITask.js +2 -0
- package/dist/core/interfaces/ITaskContext.d.ts +11 -0
- package/dist/core/interfaces/ITaskContext.js +2 -0
- package/dist/core/interfaces/index.d.ts +2 -0
- package/dist/core/interfaces/index.js +2 -0
- package/dist/core/logger/Logger.d.ts +13 -0
- package/dist/core/logger/Logger.js +78 -0
- package/dist/core/services/CodeAnalysisService.d.ts +7 -0
- package/dist/core/services/CodeAnalysisService.js +43 -0
- package/dist/core/services/CodeGenerationEngine.d.ts +12 -0
- package/dist/core/services/CodeGenerationEngine.js +102 -0
- package/dist/core/services/CodeGenerationService/CodeGenerationService.d.ts +13 -0
- package/dist/core/services/CodeGenerationService/CodeGenerationService.js +110 -0
- package/dist/core/services/CodeGenerationService/generators/MergedSendableClassGenerator.d.ts +13 -0
- package/dist/core/services/CodeGenerationService/generators/MergedSendableClassGenerator.js +119 -0
- package/dist/core/services/CodeGenerationService/generators/OriginalClassGenerator.d.ts +21 -0
- package/dist/core/services/CodeGenerationService/generators/OriginalClassGenerator.js +224 -0
- package/dist/core/services/CodeGenerationService/generators/SendableClassGenerator.d.ts +24 -0
- package/dist/core/services/CodeGenerationService/generators/SendableClassGenerator.js +307 -0
- package/dist/core/services/CodeGenerationService/generators/SerializerGenerator.d.ts +28 -0
- package/dist/core/services/CodeGenerationService/generators/SerializerGenerator.js +259 -0
- package/dist/core/services/CodeGenerationService/generators/TempSerializerGenerator.d.ts +19 -0
- package/dist/core/services/CodeGenerationService/generators/TempSerializerGenerator.js +178 -0
- package/dist/core/services/CodeGenerationService/index.d.ts +1 -0
- package/dist/core/services/CodeGenerationService/index.js +5 -0
- package/dist/core/services/CodeGenerationService/shared/ImportManager.d.ts +27 -0
- package/dist/core/services/CodeGenerationService/shared/ImportManager.js +127 -0
- package/dist/core/template/HandlebarsTemplateEngine.d.ts +26 -0
- package/dist/core/template/HandlebarsTemplateEngine.js +226 -0
- package/dist/core/utils/ConfigManager.d.ts +10 -0
- package/dist/core/utils/ConfigManager.js +32 -0
- package/dist/core/utils/CustomError.d.ts +30 -0
- package/dist/core/utils/CustomError.js +37 -0
- package/dist/core/utils/DeepCopyUtil.d.ts +15 -0
- package/dist/core/utils/DeepCopyUtil.js +138 -0
- package/dist/core/utils/GenericTypeSubstitutionUtil.d.ts +9 -0
- package/dist/core/utils/GenericTypeSubstitutionUtil.js +68 -0
- package/dist/core/utils/SerializationPathUtil.d.ts +18 -0
- package/dist/core/utils/SerializationPathUtil.js +107 -0
- package/dist/core/utils/TsMorphUtil.d.ts +8 -0
- package/dist/core/utils/TsMorphUtil.js +34 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +57 -0
- package/dist/json-plugin/JSONExecuteController.d.ts +13 -0
- package/dist/json-plugin/JSONExecuteController.js +103 -0
- package/dist/json-plugin/constants/TaskConstants.d.ts +7 -0
- package/dist/json-plugin/constants/TaskConstants.js +11 -0
- package/dist/json-plugin/interfaces/IModuleContext.d.ts +10 -0
- package/dist/json-plugin/interfaces/IModuleContext.js +2 -0
- package/dist/json-plugin/interfaces/ITargetContext.d.ts +8 -0
- package/dist/json-plugin/interfaces/ITargetContext.js +2 -0
- package/dist/json-plugin/interfaces/impl/ModuleContext.d.ts +12 -0
- package/dist/json-plugin/interfaces/impl/ModuleContext.js +24 -0
- package/dist/json-plugin/interfaces/impl/TargetContext.d.ts +23 -0
- package/dist/json-plugin/interfaces/impl/TargetContext.js +113 -0
- package/dist/json-plugin/tasks/BaseTask.d.ts +14 -0
- package/dist/json-plugin/tasks/BaseTask.js +53 -0
- package/dist/json-plugin/tasks/CleanTask.d.ts +8 -0
- package/dist/json-plugin/tasks/CleanTask.js +25 -0
- package/dist/json-plugin/tasks/CodeProcessingTask.d.ts +8 -0
- package/dist/json-plugin/tasks/CodeProcessingTask.js +26 -0
- package/dist/json-plugin/tasks/SyncTask.d.ts +8 -0
- package/dist/json-plugin/tasks/SyncTask.js +21 -0
- package/dist/json-plugin/tasks/WatchTask.d.ts +11 -0
- package/dist/json-plugin/tasks/WatchTask.js +102 -0
- package/package.json +46 -0
- package/src/core/Types.ts +356 -0
- package/src/core/analyzers/ClassAnalyzer.ts +824 -0
- package/src/core/analyzers/CustomTypeAnalyzer.ts +337 -0
- package/src/core/analyzers/SendableMergeChecker.ts +195 -0
- package/src/core/analyzers/SendableMergeabilityRegistry.ts +72 -0
- package/src/core/constants/DecoratorConstants.ts +27 -0
- package/src/core/constants/PathConstants.ts +31 -0
- package/src/core/constants/StringConstants.ts +152 -0
- package/src/core/constants/index.ts +21 -0
- package/src/core/handlers/BaseTypeHandler.ts +121 -0
- package/src/core/handlers/CustomClassHandler.ts +278 -0
- package/src/core/handlers/DateHandler.ts +75 -0
- package/src/core/handlers/DecimalHandler.ts +75 -0
- package/src/core/handlers/EnumHandler.ts +142 -0
- package/src/core/handlers/GenericContainerHandler.ts +621 -0
- package/src/core/handlers/GenericHandler.ts +130 -0
- package/src/core/handlers/HandlerBootstrap.ts +64 -0
- package/src/core/handlers/ITypeHandler.ts +133 -0
- package/src/core/handlers/PrimitiveHandler.ts +159 -0
- package/src/core/handlers/TupleHandler.ts +145 -0
- package/src/core/handlers/TypeHandlerRegistry.ts +236 -0
- package/src/core/handlers/UnionTypeHandler.ts +400 -0
- package/src/core/handlers/index.ts +18 -0
- package/src/core/import-rewrite/services/BuildProfileUpdater.ts +145 -0
- package/src/core/import-rewrite/services/ImportRewriteService.ts +129 -0
- package/src/core/import-rewrite/services/ImportTransformService.ts +200 -0
- package/src/core/import-rewrite/strategies/ImportScanStrategy.ts +303 -0
- package/src/core/import-rewrite/types/ImportRewriteTypes.ts +100 -0
- package/src/core/index.ts +31 -0
- package/src/core/interfaces/ITask.ts +23 -0
- package/src/core/interfaces/ITaskContext.ts +94 -0
- package/src/core/interfaces/index.ts +17 -0
- package/src/core/logger/Logger.ts +149 -0
- package/src/core/services/CodeAnalysisService.ts +67 -0
- package/src/core/services/CodeGenerationEngine.ts +181 -0
- package/src/core/services/CodeGenerationService/CodeGenerationService.ts +159 -0
- package/src/core/services/CodeGenerationService/generators/MergedSendableClassGenerator.ts +189 -0
- package/src/core/services/CodeGenerationService/generators/OriginalClassGenerator.ts +314 -0
- package/src/core/services/CodeGenerationService/generators/SendableClassGenerator.ts +421 -0
- package/src/core/services/CodeGenerationService/generators/SerializerGenerator.ts +392 -0
- package/src/core/services/CodeGenerationService/generators/TempSerializerGenerator.ts +277 -0
- package/src/core/services/CodeGenerationService/index.ts +16 -0
- package/src/core/services/CodeGenerationService/shared/ImportManager.ts +191 -0
- package/src/core/template/HandlebarsTemplateEngine.ts +282 -0
- package/src/core/utils/ConfigManager.ts +49 -0
- package/src/core/utils/CustomError.ts +51 -0
- package/src/core/utils/DeepCopyUtil.ts +185 -0
- package/src/core/utils/GenericTypeSubstitutionUtil.ts +136 -0
- package/src/core/utils/SerializationPathUtil.ts +142 -0
- package/src/core/utils/TsMorphUtil.ts +50 -0
- package/src/index.ts +81 -0
- package/src/json-plugin/JSONExecuteController.ts +134 -0
- package/src/json-plugin/constants/TaskConstants.ts +22 -0
- package/src/json-plugin/interfaces/IModuleContext.ts +27 -0
- package/src/json-plugin/interfaces/ITargetContext.ts +25 -0
- package/src/json-plugin/interfaces/impl/ModuleContext.ts +45 -0
- package/src/json-plugin/interfaces/impl/TargetContext.ts +196 -0
- package/src/json-plugin/tasks/BaseTask.ts +94 -0
- package/src/json-plugin/tasks/CleanTask.ts +36 -0
- package/src/json-plugin/tasks/CodeProcessingTask.ts +41 -0
- package/src/json-plugin/tasks/SyncTask.ts +33 -0
- package/src/json-plugin/tasks/WatchTask.ts +99 -0
- package/template/SerializerPerformanceTemplate.hbs +35 -0
- package/template/SerializerRegisterTemplate.hbs +10 -0
- package/template/SerializerStrictTemplate.hbs +89 -0
- package/template/SerializerTemplate.hbs +176 -0
- package/tsconfig.json +17 -0
- package/tslint.json +3 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPrimitiveHandlers = createPrimitiveHandlers;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const Types_1 = require("../Types");
|
|
6
|
+
const BaseTypeHandler_1 = require("./BaseTypeHandler");
|
|
7
|
+
class PrimitiveHandler extends BaseTypeHandler_1.BaseTypeHandler {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.priority = 100;
|
|
11
|
+
}
|
|
12
|
+
matches(typeNode) {
|
|
13
|
+
return typeNode.getKind() === this.syntaxKind;
|
|
14
|
+
}
|
|
15
|
+
parse(typeNode) {
|
|
16
|
+
return {
|
|
17
|
+
kind: this.kind,
|
|
18
|
+
depth: 0,
|
|
19
|
+
sourceText: typeNode.getText(),
|
|
20
|
+
args: [],
|
|
21
|
+
dependencies: []
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
getSerializerMetadata(structure, withParam) {
|
|
25
|
+
const serializerName = this.getSerializerName();
|
|
26
|
+
const defaultInstantiation = this.generateInstantiation();
|
|
27
|
+
return {
|
|
28
|
+
name: serializerName,
|
|
29
|
+
typeDeclaration: serializerName,
|
|
30
|
+
instantiationTemplate: this.applyWithParam(withParam, defaultInstantiation, structure),
|
|
31
|
+
encodeMethod: `encode${this.getTypeName()}Element`,
|
|
32
|
+
decodeMethod: `decode${this.getTypeName()}`,
|
|
33
|
+
decoderType: `${structure.sourceText} | undefined`,
|
|
34
|
+
needsTypeAssertion: false
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
generateInstantiation() {
|
|
38
|
+
const serializerName = this.getSerializerName();
|
|
39
|
+
return `${serializerName}.INSTANCE`;
|
|
40
|
+
}
|
|
41
|
+
generateTypeDeclaration() {
|
|
42
|
+
return this.getSerializerName();
|
|
43
|
+
}
|
|
44
|
+
generateTypeKey(structure) {
|
|
45
|
+
return `'${structure.sourceText}'`;
|
|
46
|
+
}
|
|
47
|
+
generateSendableTypeDeclaration(structure) {
|
|
48
|
+
return structure.sourceText;
|
|
49
|
+
}
|
|
50
|
+
generatePropertyConversion(_structure, sourceValue) {
|
|
51
|
+
return sourceValue;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
class StringHandler extends PrimitiveHandler {
|
|
55
|
+
constructor() {
|
|
56
|
+
super(...arguments);
|
|
57
|
+
this.name = 'StringHandler';
|
|
58
|
+
this.kind = Types_1.PropertyKind.STRING;
|
|
59
|
+
this.syntaxKind = ts_morph_1.SyntaxKind.StringKeyword;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
class NumberHandler extends PrimitiveHandler {
|
|
63
|
+
constructor() {
|
|
64
|
+
super(...arguments);
|
|
65
|
+
this.name = 'NumberHandler';
|
|
66
|
+
this.kind = Types_1.PropertyKind.NUMBER;
|
|
67
|
+
this.syntaxKind = ts_morph_1.SyntaxKind.NumberKeyword;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
class BooleanHandler extends PrimitiveHandler {
|
|
71
|
+
constructor() {
|
|
72
|
+
super(...arguments);
|
|
73
|
+
this.name = 'BooleanHandler';
|
|
74
|
+
this.kind = Types_1.PropertyKind.BOOLEAN;
|
|
75
|
+
this.syntaxKind = ts_morph_1.SyntaxKind.BooleanKeyword;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
class BigintHandler extends PrimitiveHandler {
|
|
79
|
+
constructor() {
|
|
80
|
+
super(...arguments);
|
|
81
|
+
this.name = 'BigintHandler';
|
|
82
|
+
this.kind = Types_1.PropertyKind.BIGINT;
|
|
83
|
+
this.syntaxKind = ts_morph_1.SyntaxKind.BigIntKeyword;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
class NullHandler extends PrimitiveHandler {
|
|
87
|
+
constructor() {
|
|
88
|
+
super(...arguments);
|
|
89
|
+
this.name = 'NullHandler';
|
|
90
|
+
this.kind = Types_1.PropertyKind.NULL;
|
|
91
|
+
this.syntaxKind = ts_morph_1.SyntaxKind.NullKeyword;
|
|
92
|
+
}
|
|
93
|
+
matches(typeNode) {
|
|
94
|
+
if (typeNode.getKind() === ts_morph_1.SyntaxKind.LiteralType) {
|
|
95
|
+
const literal = typeNode.asKindOrThrow(ts_morph_1.SyntaxKind.LiteralType);
|
|
96
|
+
const literalValue = literal.getLiteral();
|
|
97
|
+
return literalValue.getKind() === ts_morph_1.SyntaxKind.NullKeyword;
|
|
98
|
+
}
|
|
99
|
+
return typeNode.getKind() === ts_morph_1.SyntaxKind.NullKeyword;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
class UndefinedHandler extends PrimitiveHandler {
|
|
103
|
+
constructor() {
|
|
104
|
+
super(...arguments);
|
|
105
|
+
this.name = 'UndefinedHandler';
|
|
106
|
+
this.kind = Types_1.PropertyKind.UNDEFINED;
|
|
107
|
+
this.syntaxKind = ts_morph_1.SyntaxKind.UndefinedKeyword;
|
|
108
|
+
}
|
|
109
|
+
matches(typeNode) {
|
|
110
|
+
if (typeNode.getKind() === ts_morph_1.SyntaxKind.LiteralType) {
|
|
111
|
+
const literal = typeNode.asKindOrThrow(ts_morph_1.SyntaxKind.LiteralType);
|
|
112
|
+
const literalValue = literal.getLiteral();
|
|
113
|
+
return literalValue.getKind() === ts_morph_1.SyntaxKind.UndefinedKeyword;
|
|
114
|
+
}
|
|
115
|
+
return typeNode.getKind() === ts_morph_1.SyntaxKind.UndefinedKeyword;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function createPrimitiveHandlers() {
|
|
119
|
+
return [
|
|
120
|
+
new StringHandler(),
|
|
121
|
+
new NumberHandler(),
|
|
122
|
+
new BooleanHandler(),
|
|
123
|
+
new BigintHandler(),
|
|
124
|
+
new NullHandler(),
|
|
125
|
+
new UndefinedHandler()
|
|
126
|
+
];
|
|
127
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTupleTypeHandlers = createTupleTypeHandlers;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const Types_1 = require("../Types");
|
|
6
|
+
const BaseTypeHandler_1 = require("./BaseTypeHandler");
|
|
7
|
+
const CustomError_1 = require("../utils/CustomError");
|
|
8
|
+
const Logger_1 = require("../logger/Logger");
|
|
9
|
+
class TupleHandler extends BaseTypeHandler_1.BaseTypeHandler {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.name = 'TupleHandler';
|
|
13
|
+
this.kind = Types_1.PropertyKind.TUPLE;
|
|
14
|
+
this.priority = 95;
|
|
15
|
+
}
|
|
16
|
+
matches(typeNode) {
|
|
17
|
+
return typeNode.getKind() === ts_morph_1.SyntaxKind.TupleType;
|
|
18
|
+
}
|
|
19
|
+
parse(typeNode, context) {
|
|
20
|
+
const tupleType = typeNode;
|
|
21
|
+
const elementTypes = tupleType.getElements();
|
|
22
|
+
const elements = [];
|
|
23
|
+
const allDependencies = [];
|
|
24
|
+
let maxDepth = 0;
|
|
25
|
+
for (const elementType of elementTypes) {
|
|
26
|
+
const { TypeHandlerRegistry } = require('./TypeHandlerRegistry');
|
|
27
|
+
const elementStructure = TypeHandlerRegistry.getInstance().parseType(elementType, {
|
|
28
|
+
...context,
|
|
29
|
+
depth: context.depth + 1
|
|
30
|
+
});
|
|
31
|
+
Logger_1.Logger.info(`tuple element type: ${elementType.getText()}, ${elementStructure.kind}`);
|
|
32
|
+
elements.push(elementStructure);
|
|
33
|
+
allDependencies.push(...elementStructure.dependencies);
|
|
34
|
+
maxDepth = Math.max(maxDepth, elementStructure.depth);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
kind: this.kind,
|
|
38
|
+
depth: maxDepth + 1,
|
|
39
|
+
sourceText: typeNode.getText(),
|
|
40
|
+
args: elements,
|
|
41
|
+
dependencies: allDependencies
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
getSerializerMetadata(structure, withParam) {
|
|
45
|
+
const serializerName = this.getSerializerName();
|
|
46
|
+
const defaultInstantiation = this.generateInstantiation(structure);
|
|
47
|
+
return {
|
|
48
|
+
name: serializerName,
|
|
49
|
+
typeDeclaration: this.generateTypeDeclaration(structure),
|
|
50
|
+
instantiationTemplate: this.applyWithParam(withParam, defaultInstantiation, structure),
|
|
51
|
+
encodeMethod: 'encodeSerializableElement',
|
|
52
|
+
decodeMethod: 'deserialize',
|
|
53
|
+
decoderType: `${structure.sourceText} | undefined`,
|
|
54
|
+
needsTypeAssertion: false
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
generateInstantiation(structure) {
|
|
58
|
+
const serializerName = this.getSerializerName();
|
|
59
|
+
const elementSerializers = structure.args.map(element => {
|
|
60
|
+
const { TypeHandlerRegistry } = require('./TypeHandlerRegistry');
|
|
61
|
+
const handler = TypeHandlerRegistry.getInstance().getHandlerForKind(element.kind);
|
|
62
|
+
return handler.generateInstantiation(element);
|
|
63
|
+
});
|
|
64
|
+
return `new ${serializerName}([${elementSerializers.join(', ')}])`;
|
|
65
|
+
}
|
|
66
|
+
generateTypeDeclaration(structure) {
|
|
67
|
+
const serializerName = this.getSerializerName();
|
|
68
|
+
return `${serializerName}<${structure.sourceText}>`;
|
|
69
|
+
}
|
|
70
|
+
generateTypeKey(structure) {
|
|
71
|
+
const elementKeys = structure.args.map(element => {
|
|
72
|
+
const { TypeHandlerRegistry } = require('./TypeHandlerRegistry');
|
|
73
|
+
const handler = TypeHandlerRegistry.getInstance().getHandlerForKind(element.kind);
|
|
74
|
+
return handler.generateTypeKey(element);
|
|
75
|
+
});
|
|
76
|
+
return `[${elementKeys.join(', ')}]`;
|
|
77
|
+
}
|
|
78
|
+
getSerializerName() {
|
|
79
|
+
return 'TupleSerializer';
|
|
80
|
+
}
|
|
81
|
+
generateSendableTypeDeclaration(structure) {
|
|
82
|
+
const registry = require('./TypeHandlerRegistry').TypeHandlerRegistry.getInstance();
|
|
83
|
+
const sendableElementTypes = structure.args.map(element => {
|
|
84
|
+
const handler = registry.getHandlerForKind(element.kind);
|
|
85
|
+
if (!handler) {
|
|
86
|
+
throw new CustomError_1.CustomError(`TupleHandler: no handler for element type: ${element.kind}`, CustomError_1.ErrorCodes.HANDLER_NOT_FOUND);
|
|
87
|
+
}
|
|
88
|
+
return handler.generateSendableTypeDeclaration(element);
|
|
89
|
+
});
|
|
90
|
+
return `[${sendableElementTypes.join(', ')}]`;
|
|
91
|
+
}
|
|
92
|
+
generatePropertyConversion(structure, sourceValue, direction) {
|
|
93
|
+
return sourceValue;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function createTupleTypeHandlers() {
|
|
97
|
+
return new TupleHandler();
|
|
98
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TypeNode } from 'ts-morph';
|
|
2
|
+
import { ITypeHandler, TypeContext } from './ITypeHandler';
|
|
3
|
+
import { PropertyKind, TypeStructure } from '..';
|
|
4
|
+
export declare class TypeHandlerRegistry {
|
|
5
|
+
private static instance;
|
|
6
|
+
private handlers;
|
|
7
|
+
private kindMap;
|
|
8
|
+
private nameMap;
|
|
9
|
+
private constructor();
|
|
10
|
+
static getInstance(): TypeHandlerRegistry;
|
|
11
|
+
register(handler: ITypeHandler): void;
|
|
12
|
+
registerAll(handlers: ITypeHandler[]): void;
|
|
13
|
+
getHandlerForKind(kind: PropertyKind): ITypeHandler;
|
|
14
|
+
findHandler(typeNode: TypeNode, context: TypeContext): ITypeHandler | undefined;
|
|
15
|
+
parseType(typeNode: TypeNode, context: TypeContext): TypeStructure;
|
|
16
|
+
generateInstantiation(structure: TypeStructure): string;
|
|
17
|
+
generateTypeKey(structure: TypeStructure): string;
|
|
18
|
+
private extractTypeName;
|
|
19
|
+
private normalizeTypeName;
|
|
20
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeHandlerRegistry = void 0;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const __1 = require("..");
|
|
6
|
+
const CustomError_1 = require("../utils/CustomError");
|
|
7
|
+
class TypeHandlerRegistry {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.handlers = [];
|
|
10
|
+
this.kindMap = new Map();
|
|
11
|
+
this.nameMap = new Map();
|
|
12
|
+
}
|
|
13
|
+
static getInstance() {
|
|
14
|
+
if (!TypeHandlerRegistry.instance) {
|
|
15
|
+
TypeHandlerRegistry.instance = new TypeHandlerRegistry();
|
|
16
|
+
}
|
|
17
|
+
return TypeHandlerRegistry.instance;
|
|
18
|
+
}
|
|
19
|
+
register(handler) {
|
|
20
|
+
this.handlers.push(handler);
|
|
21
|
+
this.handlers.sort((a, b) => b.priority - a.priority);
|
|
22
|
+
const existingHandler = this.kindMap.get(handler.kind);
|
|
23
|
+
if (!existingHandler || handler.priority > existingHandler.priority) {
|
|
24
|
+
this.kindMap.set(handler.kind, handler);
|
|
25
|
+
}
|
|
26
|
+
const typeName = this.extractTypeName(handler.kind);
|
|
27
|
+
const candidates = this.nameMap.get(typeName) || [];
|
|
28
|
+
candidates.push(handler);
|
|
29
|
+
candidates.sort((a, b) => b.priority - a.priority);
|
|
30
|
+
this.nameMap.set(typeName, candidates);
|
|
31
|
+
}
|
|
32
|
+
registerAll(handlers) {
|
|
33
|
+
handlers.forEach((handler) => this.register(handler));
|
|
34
|
+
}
|
|
35
|
+
getHandlerForKind(kind) {
|
|
36
|
+
const handler = this.kindMap.get(kind);
|
|
37
|
+
if (!handler) {
|
|
38
|
+
throw new CustomError_1.CustomError(`No handler for kind: ${kind}`, CustomError_1.ErrorCodes.HANDLER_NOT_FOUND);
|
|
39
|
+
}
|
|
40
|
+
return handler;
|
|
41
|
+
}
|
|
42
|
+
findHandler(typeNode, context) {
|
|
43
|
+
const typeName = typeNode.getText();
|
|
44
|
+
const candidates = this.nameMap.get(this.normalizeTypeName(typeName));
|
|
45
|
+
if (candidates && candidates.length > 0) {
|
|
46
|
+
for (const handler of candidates) {
|
|
47
|
+
if (handler.matches(typeNode, context)) {
|
|
48
|
+
return handler;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
for (const handler of this.handlers) {
|
|
53
|
+
if (handler.matches(typeNode, context)) {
|
|
54
|
+
return handler;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
__1.Logger.warn(`No handler found for type: ${typeName}`);
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
parseType(typeNode, context) {
|
|
61
|
+
if (typeNode.getKind() === ts_morph_1.SyntaxKind.LiteralType) {
|
|
62
|
+
const literal = typeNode.asKindOrThrow(ts_morph_1.SyntaxKind.LiteralType);
|
|
63
|
+
const literalValue = literal.getLiteral();
|
|
64
|
+
const literalKind = literalValue.getKind();
|
|
65
|
+
if (literalKind !== ts_morph_1.SyntaxKind.NullKeyword && literalKind !== ts_morph_1.SyntaxKind.UndefinedKeyword) {
|
|
66
|
+
throw new CustomError_1.CustomError(`不支持字面量类型 '${typeNode.getText()}'(无论出现在何处)。\n` +
|
|
67
|
+
`不支持的字面量类型包括:字符串字面量(如 'admin')、数字字面量(如 123)、布尔字面量(如 true)。\n` +
|
|
68
|
+
`即使在联合类型、Type 别名、泛型参数中使用字面量也不支持。\n` +
|
|
69
|
+
`请使用基础类型:string、number、boolean 替代字面量类型。`, CustomError_1.ErrorCodes.LITERAL_NOT_SOPPORT);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (typeNode.getKind() === ts_morph_1.SyntaxKind.ParenthesizedType) {
|
|
73
|
+
const parenthesizedType = typeNode.asKindOrThrow(ts_morph_1.SyntaxKind.ParenthesizedType);
|
|
74
|
+
const innerTypeNode = parenthesizedType.getTypeNode();
|
|
75
|
+
return this.parseType(innerTypeNode, context);
|
|
76
|
+
}
|
|
77
|
+
const handler = this.findHandler(typeNode, context);
|
|
78
|
+
if (!handler) {
|
|
79
|
+
const typeName = typeNode.getText();
|
|
80
|
+
__1.Logger.warn(`No handler found for type: ${typeName}, marking as UNKNOWN`);
|
|
81
|
+
return {
|
|
82
|
+
kind: __1.PropertyKind.UNKNOWN,
|
|
83
|
+
depth: 0,
|
|
84
|
+
sourceText: typeName,
|
|
85
|
+
args: [],
|
|
86
|
+
dependencies: []
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return handler.parse(typeNode, context);
|
|
90
|
+
}
|
|
91
|
+
generateInstantiation(structure) {
|
|
92
|
+
const handler = this.getHandlerForKind(structure.kind);
|
|
93
|
+
return handler.generateInstantiation(structure);
|
|
94
|
+
}
|
|
95
|
+
generateTypeKey(structure) {
|
|
96
|
+
const handler = this.getHandlerForKind(structure.kind);
|
|
97
|
+
return handler.generateTypeKey(structure);
|
|
98
|
+
}
|
|
99
|
+
extractTypeName(kind) {
|
|
100
|
+
if (kind.startsWith('collections.')) {
|
|
101
|
+
return kind.split('.')[1];
|
|
102
|
+
}
|
|
103
|
+
return kind;
|
|
104
|
+
}
|
|
105
|
+
normalizeTypeName(typeName) {
|
|
106
|
+
const withoutGenerics = typeName.split('<')[0].trim();
|
|
107
|
+
if (withoutGenerics.startsWith('collections.')) {
|
|
108
|
+
return withoutGenerics.split('.')[1];
|
|
109
|
+
}
|
|
110
|
+
return withoutGenerics;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.TypeHandlerRegistry = TypeHandlerRegistry;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createUnionTypeHandlers = createUnionTypeHandlers;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const Types_1 = require("../Types");
|
|
6
|
+
const BaseTypeHandler_1 = require("./BaseTypeHandler");
|
|
7
|
+
const CustomError_1 = require("../utils/CustomError");
|
|
8
|
+
class UnionTypeHandler extends BaseTypeHandler_1.BaseTypeHandler {
|
|
9
|
+
matches(typeNode) {
|
|
10
|
+
if (typeNode.getKind() !== ts_morph_1.SyntaxKind.UnionType) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const unionType = typeNode;
|
|
14
|
+
const memberTypes = unionType.getTypeNodes();
|
|
15
|
+
const isNullType = (t) => {
|
|
16
|
+
return t.getKind() === ts_morph_1.SyntaxKind.LiteralType && t.getText() === 'null';
|
|
17
|
+
};
|
|
18
|
+
const isUndefinedType = (t) => {
|
|
19
|
+
return t.getKind() === ts_morph_1.SyntaxKind.UndefinedKeyword;
|
|
20
|
+
};
|
|
21
|
+
switch (this.supportedPattern) {
|
|
22
|
+
case 'optional':
|
|
23
|
+
if (memberTypes.length !== 2) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const hasUndefined = memberTypes.some(isUndefinedType);
|
|
27
|
+
const hasNull = memberTypes.some(isNullType);
|
|
28
|
+
return hasUndefined && !hasNull;
|
|
29
|
+
case 'nullable':
|
|
30
|
+
if (memberTypes.length !== 2) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const hasNullable = memberTypes.some(isNullType);
|
|
34
|
+
const hasUndefinedNullable = memberTypes.some(isUndefinedType);
|
|
35
|
+
return hasNullable && !hasUndefinedNullable;
|
|
36
|
+
case 'optionalNullable':
|
|
37
|
+
return memberTypes.length === 3 &&
|
|
38
|
+
memberTypes.some(isNullType) &&
|
|
39
|
+
memberTypes.some(isUndefinedType);
|
|
40
|
+
case 'union':
|
|
41
|
+
return true;
|
|
42
|
+
default:
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
parse(typeNode, context) {
|
|
47
|
+
const unionType = typeNode;
|
|
48
|
+
const members = this.parseUnionMembers(unionType, context);
|
|
49
|
+
const allDependencies = [];
|
|
50
|
+
let maxDepth = 0;
|
|
51
|
+
members.forEach(member => {
|
|
52
|
+
allDependencies.push(...member.dependencies);
|
|
53
|
+
maxDepth = Math.max(maxDepth, member.depth);
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
kind: this.kind,
|
|
57
|
+
depth: this.supportedPattern === 'union' ? 0 : maxDepth + 1,
|
|
58
|
+
sourceText: typeNode.getText(),
|
|
59
|
+
args: [],
|
|
60
|
+
dependencies: allDependencies,
|
|
61
|
+
unionDetails: members
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
getSerializerMetadata(structure, withParam) {
|
|
65
|
+
const serializerName = this.getSerializerName();
|
|
66
|
+
const defaultInstantiation = this.generateInstantiation(structure);
|
|
67
|
+
return {
|
|
68
|
+
name: serializerName,
|
|
69
|
+
typeDeclaration: this.generateTypeDeclaration(structure),
|
|
70
|
+
instantiationTemplate: this.applyWithParam(withParam, defaultInstantiation, structure),
|
|
71
|
+
encodeMethod: 'encodeSerializableElement',
|
|
72
|
+
decodeMethod: 'deserialize',
|
|
73
|
+
decoderType: `${structure.sourceText} | undefined`,
|
|
74
|
+
needsTypeAssertion: false
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
generateInstantiation(structure) {
|
|
78
|
+
if (!structure.unionDetails || structure.unionDetails.length === 0) {
|
|
79
|
+
throw new CustomError_1.CustomError(`${this.name}: missing unionDetails`, CustomError_1.ErrorCodes.UNION_STRUCTURE_NOT_FOUND);
|
|
80
|
+
}
|
|
81
|
+
const serializerName = this.getSerializerName();
|
|
82
|
+
if (this.isOptionalOrNullablePattern()) {
|
|
83
|
+
return this.generateOptionalNullableInstantiation(structure);
|
|
84
|
+
}
|
|
85
|
+
const primitiveTypes = ['undefined', 'null', 'boolean', 'number', 'string', 'bigint'];
|
|
86
|
+
const unionTypes = structure.unionDetails.map(member => {
|
|
87
|
+
return primitiveTypes.includes(member.sourceText)
|
|
88
|
+
? `'${member.sourceText}'`
|
|
89
|
+
: member.sourceText;
|
|
90
|
+
}).join(', ');
|
|
91
|
+
const typeDeclaration = structure.unionDetails.map(member => member.sourceText).join(' | ');
|
|
92
|
+
return `new ${serializerName}<${typeDeclaration}>([${unionTypes}])`;
|
|
93
|
+
}
|
|
94
|
+
generateTypeDeclaration(structure) {
|
|
95
|
+
if (!structure.unionDetails || structure.unionDetails.length === 0) {
|
|
96
|
+
throw new CustomError_1.CustomError(`${this.name}: missing unionDetails`, CustomError_1.ErrorCodes.UNION_STRUCTURE_NOT_FOUND);
|
|
97
|
+
}
|
|
98
|
+
const serializerName = this.getSerializerName();
|
|
99
|
+
if (this.isOptionalOrNullablePattern()) {
|
|
100
|
+
const innerMember = this.getInnerMember(structure);
|
|
101
|
+
if (!innerMember) {
|
|
102
|
+
throw new CustomError_1.CustomError(`${this.name}: cannot find inner member`, CustomError_1.ErrorCodes.UNION_INNER_NOT_FOUND);
|
|
103
|
+
}
|
|
104
|
+
return `${serializerName}<${innerMember.sourceText}>`;
|
|
105
|
+
}
|
|
106
|
+
const typeDeclaration = structure.unionDetails.map(member => member.sourceText).join(' | ');
|
|
107
|
+
return `${serializerName}<${typeDeclaration}>`;
|
|
108
|
+
}
|
|
109
|
+
generateTypeKey(structure) {
|
|
110
|
+
if (!structure.unionDetails || structure.unionDetails.length === 0) {
|
|
111
|
+
throw new CustomError_1.CustomError(`${this.name}: missing unionDetails`, CustomError_1.ErrorCodes.UNION_STRUCTURE_NOT_FOUND);
|
|
112
|
+
}
|
|
113
|
+
if (this.isOptionalOrNullablePattern()) {
|
|
114
|
+
return this.generateOptionalNullableTypeKey(structure);
|
|
115
|
+
}
|
|
116
|
+
const memberTypeKeys = structure.unionDetails.map(member => {
|
|
117
|
+
const { TypeHandlerRegistry } = require('./TypeHandlerRegistry');
|
|
118
|
+
const handler = TypeHandlerRegistry.getInstance().getHandlerForKind(member.kind);
|
|
119
|
+
return handler.generateTypeKey(member);
|
|
120
|
+
});
|
|
121
|
+
return `[${memberTypeKeys.join(', ')}]`;
|
|
122
|
+
}
|
|
123
|
+
isOptionalOrNullablePattern() {
|
|
124
|
+
return this.supportedPattern === 'optional' ||
|
|
125
|
+
this.supportedPattern === 'nullable' ||
|
|
126
|
+
this.supportedPattern === 'optionalNullable';
|
|
127
|
+
}
|
|
128
|
+
getInnerMember(structure) {
|
|
129
|
+
switch (this.supportedPattern) {
|
|
130
|
+
case 'optional':
|
|
131
|
+
return structure.unionDetails?.find(m => m.kind !== Types_1.PropertyKind.UNDEFINED);
|
|
132
|
+
case 'nullable':
|
|
133
|
+
return structure.unionDetails?.find(m => m.kind !== Types_1.PropertyKind.NULL);
|
|
134
|
+
case 'optionalNullable':
|
|
135
|
+
return structure.unionDetails?.find(m => m.kind !== Types_1.PropertyKind.NULL && m.kind !== Types_1.PropertyKind.UNDEFINED);
|
|
136
|
+
default:
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
generateOptionalNullableInstantiation(structure) {
|
|
141
|
+
if (this.supportedPattern === 'optionalNullable' && structure.unionDetails?.length !== 3) {
|
|
142
|
+
throw new CustomError_1.CustomError(`${this.name}: expected 3 union members`, CustomError_1.ErrorCodes.UNION_EXPEDTED_THREE);
|
|
143
|
+
}
|
|
144
|
+
if (this.supportedPattern !== 'optionalNullable' && structure.unionDetails?.length !== 2) {
|
|
145
|
+
throw new CustomError_1.CustomError(`${this.name}: expected 2 union members`, CustomError_1.ErrorCodes.UNION_EXPEDTED_TWO);
|
|
146
|
+
}
|
|
147
|
+
const innerMember = this.getInnerMember(structure);
|
|
148
|
+
if (!innerMember) {
|
|
149
|
+
throw new CustomError_1.CustomError(`${this.name}: cannot find inner member`, CustomError_1.ErrorCodes.UNION_INNER_NOT_FOUND);
|
|
150
|
+
}
|
|
151
|
+
const innerType = innerMember.sourceText;
|
|
152
|
+
const { TypeHandlerRegistry } = require('./TypeHandlerRegistry');
|
|
153
|
+
const innerHandler = TypeHandlerRegistry.getInstance().getHandlerForKind(innerMember.kind);
|
|
154
|
+
const innerSerializer = innerHandler.generateInstantiation(innerMember);
|
|
155
|
+
const serializerName = this.getSerializerName();
|
|
156
|
+
return `new ${serializerName}<${innerType}>(${innerSerializer})`;
|
|
157
|
+
}
|
|
158
|
+
generateOptionalNullableTypeKey(structure) {
|
|
159
|
+
const innerMember = this.getInnerMember(structure);
|
|
160
|
+
if (!innerMember) {
|
|
161
|
+
throw new CustomError_1.CustomError(`${this.name}: cannot find inner member`, CustomError_1.ErrorCodes.UNION_INNER_NOT_FOUND);
|
|
162
|
+
}
|
|
163
|
+
const { TypeHandlerRegistry } = require('./TypeHandlerRegistry');
|
|
164
|
+
const innerHandler = TypeHandlerRegistry.getInstance().getHandlerForKind(innerMember.kind);
|
|
165
|
+
const innerTypeKey = innerHandler.generateTypeKey(innerMember);
|
|
166
|
+
switch (this.supportedPattern) {
|
|
167
|
+
case 'optional':
|
|
168
|
+
return `[${innerTypeKey}, "'undefined'"]`;
|
|
169
|
+
case 'nullable':
|
|
170
|
+
return `[${innerTypeKey}, "'null'"]`;
|
|
171
|
+
case 'optionalNullable':
|
|
172
|
+
return `[${innerTypeKey}, "'null'", "'undefined'"]`;
|
|
173
|
+
default:
|
|
174
|
+
throw new CustomError_1.CustomError(`${this.name}: unsupported pattern`, CustomError_1.ErrorCodes.UNION_UNSUPPORTED_PATTERN);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
parseUnionMembers(typeNode, context) {
|
|
178
|
+
const memberTypes = typeNode.getTypeNodes();
|
|
179
|
+
const members = [];
|
|
180
|
+
for (const memberType of memberTypes) {
|
|
181
|
+
const { TypeHandlerRegistry } = require('./TypeHandlerRegistry');
|
|
182
|
+
const memberStructure = TypeHandlerRegistry.getInstance().parseType(memberType, {
|
|
183
|
+
...context,
|
|
184
|
+
depth: context.depth + 1
|
|
185
|
+
});
|
|
186
|
+
members.push(memberStructure);
|
|
187
|
+
}
|
|
188
|
+
return members;
|
|
189
|
+
}
|
|
190
|
+
generateSendableTypeDeclaration(structure) {
|
|
191
|
+
if (!structure.unionDetails || structure.unionDetails.length === 0) {
|
|
192
|
+
throw new CustomError_1.CustomError(`${this.name}: missing unionDetails for Sendable type declaration`, CustomError_1.ErrorCodes.UNION_STRUCTURE_NOT_FOUND);
|
|
193
|
+
}
|
|
194
|
+
const registry = require('./TypeHandlerRegistry').TypeHandlerRegistry.getInstance();
|
|
195
|
+
const sendableMemberTypes = structure.unionDetails.map(member => {
|
|
196
|
+
const handler = registry.getHandlerForKind(member.kind);
|
|
197
|
+
if (!handler) {
|
|
198
|
+
throw new CustomError_1.CustomError(`${this.name}: no handler for member type: ${member.kind}`, CustomError_1.ErrorCodes.HANDLER_NOT_FOUND);
|
|
199
|
+
}
|
|
200
|
+
return handler.generateSendableTypeDeclaration(member);
|
|
201
|
+
});
|
|
202
|
+
return sendableMemberTypes.join(' | ');
|
|
203
|
+
}
|
|
204
|
+
generatePropertyConversion(structure, sourceValue, direction) {
|
|
205
|
+
return sourceValue;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
class NullableHandler extends UnionTypeHandler {
|
|
209
|
+
constructor() {
|
|
210
|
+
super(...arguments);
|
|
211
|
+
this.name = 'NullableHandler';
|
|
212
|
+
this.kind = Types_1.PropertyKind.NULLABLE;
|
|
213
|
+
this.priority = 95;
|
|
214
|
+
this.supportedPattern = 'nullable';
|
|
215
|
+
}
|
|
216
|
+
getSerializerName() {
|
|
217
|
+
return 'NullableSerializer';
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
class OptionalHandler extends UnionTypeHandler {
|
|
221
|
+
constructor() {
|
|
222
|
+
super(...arguments);
|
|
223
|
+
this.name = 'OptionalHandler';
|
|
224
|
+
this.kind = Types_1.PropertyKind.OPTIONAL;
|
|
225
|
+
this.priority = 95;
|
|
226
|
+
this.supportedPattern = 'optional';
|
|
227
|
+
}
|
|
228
|
+
getSerializerName() {
|
|
229
|
+
return 'OptionalSerializer';
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
class OptionalNullableHandler extends UnionTypeHandler {
|
|
233
|
+
constructor() {
|
|
234
|
+
super(...arguments);
|
|
235
|
+
this.name = 'OptionalNullableHandler';
|
|
236
|
+
this.kind = Types_1.PropertyKind.OPTIONAL_NULLABLE;
|
|
237
|
+
this.priority = 95;
|
|
238
|
+
this.supportedPattern = 'optionalNullable';
|
|
239
|
+
}
|
|
240
|
+
getSerializerName() {
|
|
241
|
+
return 'OptionalNullableSerializer';
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
class UnionHandler extends UnionTypeHandler {
|
|
245
|
+
constructor() {
|
|
246
|
+
super(...arguments);
|
|
247
|
+
this.name = 'UnionHandler';
|
|
248
|
+
this.kind = Types_1.PropertyKind.UNION;
|
|
249
|
+
this.priority = 85;
|
|
250
|
+
this.supportedPattern = 'union';
|
|
251
|
+
}
|
|
252
|
+
getSerializerName() {
|
|
253
|
+
return 'UnionTypeSerializer';
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function createUnionTypeHandlers() {
|
|
257
|
+
return [
|
|
258
|
+
new OptionalHandler(),
|
|
259
|
+
new NullableHandler(),
|
|
260
|
+
new OptionalNullableHandler(),
|
|
261
|
+
new UnionHandler()
|
|
262
|
+
];
|
|
263
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeHandlerRegistry = void 0;
|
|
4
|
+
var TypeHandlerRegistry_1 = require("./TypeHandlerRegistry");
|
|
5
|
+
Object.defineProperty(exports, "TypeHandlerRegistry", { enumerable: true, get: function () { return TypeHandlerRegistry_1.TypeHandlerRegistry; } });
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ITargetContext } from '../../../json-plugin/interfaces/ITargetContext';
|
|
2
|
+
export declare class BuildProfileUpdaterImpl {
|
|
3
|
+
updateSourceRoots(targetContext: ITargetContext): void;
|
|
4
|
+
private getModuleRootFromContext;
|
|
5
|
+
private readBuildProfile;
|
|
6
|
+
private writeBuildProfile;
|
|
7
|
+
private updateSourceRootsConfig;
|
|
8
|
+
}
|