typia 7.0.0-dev.20241007 → 7.0.0-dev.20241008
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/factories/ExpressionFactory.d.ts +1 -1
- package/lib/factories/ValueFactory.d.ts +1 -1
- package/lib/programmers/AssertProgrammer.d.ts +5 -2
- package/lib/programmers/AssertProgrammer.js +12 -5
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/ImportProgrammer.d.ts +25 -4
- package/lib/programmers/ImportProgrammer.js +67 -31
- package/lib/programmers/ImportProgrammer.js.map +1 -1
- package/lib/programmers/RandomProgrammer.js +48 -32
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +10 -4
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/functional/FunctionalAssertFunctionProgrammer.js +1 -1
- package/lib/programmers/functional/FunctionalAssertFunctionProgrammer.js.map +1 -1
- package/lib/programmers/functional/FunctionalValidateFunctionProgrammer.d.ts +1 -0
- package/lib/programmers/functional/FunctionalValidateFunctionProgrammer.js +14 -5
- package/lib/programmers/functional/FunctionalValidateFunctionProgrammer.js.map +1 -1
- package/lib/programmers/functional/FunctionalValidateParametersProgrammer.js +5 -1
- package/lib/programmers/functional/FunctionalValidateParametersProgrammer.js.map +1 -1
- package/lib/programmers/functional/FunctionalValidateReturnProgrammer.js +1 -0
- package/lib/programmers/functional/FunctionalValidateReturnProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpAssertFormDataProgrammer.js +4 -1
- package/lib/programmers/http/HttpAssertFormDataProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpAssertHeadersProgrammer.js +4 -1
- package/lib/programmers/http/HttpAssertHeadersProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpAssertQueryProgrammer.js +4 -1
- package/lib/programmers/http/HttpAssertQueryProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpFormDataProgrammer.js +10 -6
- package/lib/programmers/http/HttpFormDataProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpHeadersProgrammer.js +10 -6
- package/lib/programmers/http/HttpHeadersProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpQueryProgrammer.js +10 -6
- package/lib/programmers/http/HttpQueryProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpValidateFormDataProgrammer.js +5 -3
- package/lib/programmers/http/HttpValidateFormDataProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpValidateHeadersProgrammer.js +5 -3
- package/lib/programmers/http/HttpValidateHeadersProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpValidateQueryProgrammer.js +5 -3
- package/lib/programmers/http/HttpValidateQueryProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonAssertParseProgrammer.js +14 -7
- package/lib/programmers/json/JsonAssertParseProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonAssertStringifyProgrammer.js +4 -1
- package/lib/programmers/json/JsonAssertStringifyProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonIsParseProgrammer.js +10 -6
- package/lib/programmers/json/JsonIsParseProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonValidateParseProgrammer.js +16 -4
- package/lib/programmers/json/JsonValidateParseProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonValidateStringifyProgrammer.js +7 -3
- package/lib/programmers/json/JsonValidateStringifyProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscAssertCloneProgrammer.js +4 -1
- package/lib/programmers/misc/MiscAssertCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscAssertPruneProgrammer.js +4 -1
- package/lib/programmers/misc/MiscAssertPruneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js +10 -6
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscValidateCloneProgrammer.js +5 -3
- package/lib/programmers/misc/MiscValidateCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscValidatePruneProgrammer.js +10 -4
- package/lib/programmers/misc/MiscValidatePruneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationAssertGeneralProgrammer.js +4 -1
- package/lib/programmers/notations/NotationAssertGeneralProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.d.ts +2 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +13 -5
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationValidateGeneralProgrammer.js +5 -3
- package/lib/programmers/notations/NotationValidateGeneralProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufAssertDecodeProgrammer.js +4 -1
- package/lib/programmers/protobuf/ProtobufAssertDecodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufAssertEncodeProgrammer.js +4 -1
- package/lib/programmers/protobuf/ProtobufAssertEncodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +10 -6
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufValidateDecodeProgrammer.js +5 -3
- package/lib/programmers/protobuf/ProtobufValidateDecodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufValidateEncodeProgrammer.js +7 -3
- package/lib/programmers/protobuf/ProtobufValidateEncodeProgrammer.js.map +1 -1
- package/package.json +1 -1
- package/src/factories/JsonMetadataFactory.ts +63 -63
- package/src/factories/ProtobufFactory.ts +275 -275
- package/src/programmers/AssertProgrammer.ts +454 -456
- package/src/programmers/CheckerProgrammer.ts +1610 -1610
- package/src/programmers/ImportProgrammer.ts +184 -109
- package/src/programmers/IsProgrammer.ts +273 -273
- package/src/programmers/RandomProgrammer.ts +168 -149
- package/src/programmers/TypiaProgrammer.ts +171 -171
- package/src/programmers/ValidateProgrammer.ts +434 -430
- package/src/programmers/functional/FunctionalAssertFunctionProgrammer.ts +1 -1
- package/src/programmers/functional/FunctionalValidateFunctionProgrammer.ts +12 -16
- package/src/programmers/functional/FunctionalValidateParametersProgrammer.ts +5 -12
- package/src/programmers/functional/FunctionalValidateReturnProgrammer.ts +1 -0
- package/src/programmers/helpers/OptionPredicator.ts +15 -15
- package/src/programmers/http/HttpAssertFormDataProgrammer.ts +99 -96
- package/src/programmers/http/HttpAssertHeadersProgrammer.ts +99 -96
- package/src/programmers/http/HttpAssertQueryProgrammer.ts +105 -102
- package/src/programmers/http/HttpFormDataProgrammer.ts +304 -308
- package/src/programmers/http/HttpHeadersProgrammer.ts +400 -404
- package/src/programmers/http/HttpIsFormDataProgrammer.ts +108 -108
- package/src/programmers/http/HttpIsHeadersProgrammer.ts +108 -108
- package/src/programmers/http/HttpIsQueryProgrammer.ts +114 -114
- package/src/programmers/http/HttpParameterProgrammer.ts +115 -115
- package/src/programmers/http/HttpQueryProgrammer.ts +329 -333
- package/src/programmers/http/HttpValidateFormDataProgrammer.ts +92 -90
- package/src/programmers/http/HttpValidateHeadersProgrammer.ts +92 -90
- package/src/programmers/http/HttpValidateQueryProgrammer.ts +98 -96
- package/src/programmers/json/JsonApplicationProgrammer.ts +92 -92
- package/src/programmers/json/JsonAssertParseProgrammer.ts +103 -104
- package/src/programmers/json/JsonAssertStringifyProgrammer.ts +115 -112
- package/src/programmers/json/JsonIsParseProgrammer.ts +114 -118
- package/src/programmers/json/JsonIsStringifyProgrammer.ts +108 -108
- package/src/programmers/json/JsonStringifyProgrammer.ts +1124 -1124
- package/src/programmers/json/JsonValidateParseProgrammer.ts +105 -95
- package/src/programmers/json/JsonValidateStringifyProgrammer.ts +124 -119
- package/src/programmers/misc/MiscAssertCloneProgrammer.ts +95 -92
- package/src/programmers/misc/MiscAssertPruneProgrammer.ts +116 -113
- package/src/programmers/misc/MiscCloneProgrammer.ts +1025 -1029
- package/src/programmers/misc/MiscIsCloneProgrammer.ts +99 -99
- package/src/programmers/misc/MiscIsPruneProgrammer.ts +97 -97
- package/src/programmers/misc/MiscLiteralsProgrammer.ts +80 -80
- package/src/programmers/misc/MiscPruneProgrammer.ts +725 -725
- package/src/programmers/misc/MiscValidateCloneProgrammer.ts +111 -109
- package/src/programmers/misc/MiscValidatePruneProgrammer.ts +113 -109
- package/src/programmers/notations/NotationAssertGeneralProgrammer.ts +101 -98
- package/src/programmers/notations/NotationGeneralProgrammer.ts +977 -973
- package/src/programmers/notations/NotationIsGeneralProgrammer.ts +105 -105
- package/src/programmers/notations/NotationValidateGeneralProgrammer.ts +119 -117
- package/src/programmers/protobuf/ProtobufAssertDecodeProgrammer.ts +98 -95
- package/src/programmers/protobuf/ProtobufAssertEncodeProgrammer.ts +102 -99
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +708 -711
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +1019 -1019
- package/src/programmers/protobuf/ProtobufIsDecodeProgrammer.ts +109 -109
- package/src/programmers/protobuf/ProtobufIsEncodeProgrammer.ts +98 -98
- package/src/programmers/protobuf/ProtobufValidateDecodeProgrammer.ts +92 -90
- package/src/programmers/protobuf/ProtobufValidateEncodeProgrammer.ts +119 -114
- package/src/transform.ts +35 -35
- package/src/transformers/CallExpressionTransformer.ts +540 -540
- package/src/transformers/FileTransformer.ts +120 -120
- package/src/transformers/IProgrammerProps.ts +11 -11
- package/src/transformers/ITransformOptions.ts +62 -62
- package/src/transformers/ITransformProps.ts +9 -9
- package/src/transformers/ITypiaContext.ts +18 -18
- package/src/transformers/ImportTransformer.ts +66 -66
- package/src/transformers/NodeTransformer.ts +17 -17
- package/src/transformers/TransformerError.ts +59 -59
- package/src/transformers/features/AssertTransformer.ts +24 -24
- package/src/transformers/features/CreateAssertTransformer.ts +24 -24
- package/src/transformers/features/CreateIsTransformer.ts +18 -18
- package/src/transformers/features/CreateRandomTransformer.ts +43 -43
- package/src/transformers/features/CreateValidateTransformer.ts +18 -18
- package/src/transformers/features/IsTransformer.ts +18 -18
- package/src/transformers/features/RandomTransformer.ts +41 -41
- package/src/transformers/features/ValidateTransformer.ts +18 -18
- package/src/transformers/features/functional/FunctionalGenericTransformer.ts +57 -57
- package/src/transformers/features/http/CreateHttpAssertFormDataTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpAssertHeadersTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpAssertQueryTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpFormDataTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpHeadersTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpIsFormDataTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpIsHeadersTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpIsQueryTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpParameterTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpQueryTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpValidateFormDataTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpValidateHeadersTransformer.ts +13 -13
- package/src/transformers/features/http/CreateHttpValidateQueryTransformer.ts +13 -13
- package/src/transformers/features/http/HttpAssertFormDataTransformer.ts +13 -13
- package/src/transformers/features/http/HttpAssertHeadersTransformer.ts +13 -13
- package/src/transformers/features/http/HttpAssertQueryTransformer.ts +13 -13
- package/src/transformers/features/http/HttpFormDataTransformer.ts +13 -13
- package/src/transformers/features/http/HttpHeadersTransformer.ts +13 -13
- package/src/transformers/features/http/HttpIsFormDataTransformer.ts +13 -13
- package/src/transformers/features/http/HttpIsHeadersTransformer.ts +13 -13
- package/src/transformers/features/http/HttpIsQueryTransformer.ts +13 -13
- package/src/transformers/features/http/HttpParameterTransformer.ts +13 -13
- package/src/transformers/features/http/HttpQueryTransformer.ts +13 -13
- package/src/transformers/features/http/HttpValidateFormDataTransformer.ts +13 -13
- package/src/transformers/features/http/HttpValidateHeadersTransformer.ts +13 -13
- package/src/transformers/features/http/HttpValidateQueryTransformer.ts +13 -13
- package/src/transformers/features/json/JsonApplicationTransformer.ts +130 -130
- package/src/transformers/features/json/JsonAssertParseTransformer.ts +13 -13
- package/src/transformers/features/json/JsonAssertStringifyTransformer.ts +13 -13
- package/src/transformers/features/json/JsonCreateAssertParseTransformer.ts +13 -13
- package/src/transformers/features/json/JsonCreateAssertStringifyTransformer.ts +13 -13
- package/src/transformers/features/json/JsonCreateIsParseTransformer.ts +13 -13
- package/src/transformers/features/json/JsonCreateIsStringifyTransformer.ts +13 -13
- package/src/transformers/features/json/JsonCreateStringifyTransformer.ts +13 -13
- package/src/transformers/features/json/JsonCreateValidateParseTransformer.ts +13 -13
- package/src/transformers/features/json/JsonCreateValidateStringifyProgrammer.ts +13 -13
- package/src/transformers/features/json/JsonIsParseTransformer.ts +13 -13
- package/src/transformers/features/json/JsonIsStringifyTransformer.ts +13 -13
- package/src/transformers/features/json/JsonStringifyTransformer.ts +13 -13
- package/src/transformers/features/json/JsonValidateParseTransformer.ts +13 -13
- package/src/transformers/features/json/JsonValidateStringifyTransformer.ts +13 -13
- package/src/transformers/features/llm/LlmApplicationTransformer.ts +86 -86
- package/src/transformers/features/llm/LlmSchemaTransformer.ts +59 -59
- package/src/transformers/features/misc/MiscAssertCloneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscAssertPruneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCloneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCreateAssertCloneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCreateAssertPruneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCreateCloneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCreateIsCloneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCreateIsPruneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCreatePruneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCreateValidateCloneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscCreateValidatePruneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscIsCloneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscIsPruneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscLiteralsTransformer.ts +35 -35
- package/src/transformers/features/misc/MiscPruneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscValidateCloneTransformer.ts +13 -13
- package/src/transformers/features/misc/MiscValidatePruneTransformer.ts +13 -13
- package/src/transformers/features/notations/NotationAssertGeneralTransformer.ts +20 -20
- package/src/transformers/features/notations/NotationCreateAssertGeneralTransformer.ts +20 -20
- package/src/transformers/features/notations/NotationCreateGeneralTransformer.ts +20 -20
- package/src/transformers/features/notations/NotationCreateIsGeneralTransformer.ts +20 -20
- package/src/transformers/features/notations/NotationCreateValidateGeneralTransformer.ts +20 -20
- package/src/transformers/features/notations/NotationGeneralTransformer.ts +18 -18
- package/src/transformers/features/notations/NotationIsGeneralTransformer.ts +20 -20
- package/src/transformers/features/notations/NotationValidateGeneralTransformer.ts +20 -20
- package/src/transformers/features/protobuf/ProtobufAssertDecodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufAssertEncodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufCreateAssertDecodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufCreateAssertEncodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufCreateDecodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufCreateEncodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufCreateIsDecodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufCreateIsEncodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufCreateValidateDecodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufCreateValidateEncodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufDecodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufEncodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufIsDecodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufIsEncodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufMessageTransformer.ts +35 -35
- package/src/transformers/features/protobuf/ProtobufValidateDecodeTransformer.ts +13 -13
- package/src/transformers/features/protobuf/ProtobufValidateEncodeTransformer.ts +13 -13
- package/src/transformers/features/reflect/ReflectMetadataTransformer.ts +69 -69
- package/src/transformers/features/reflect/ReflectNameTransformer.ts +82 -82
- package/src/transformers/internal/GenericTransformer.ts +101 -101
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import { MetadataFactory } from "../factories/MetadataFactory";
|
|
2
|
-
|
|
3
|
-
import { MetadataObject } from "../schemas/metadata/MetadataObject";
|
|
4
|
-
|
|
5
|
-
import { Escaper } from "../utils/Escaper";
|
|
6
|
-
|
|
7
|
-
export class TransformerError extends Error {
|
|
8
|
-
public readonly code: string;
|
|
9
|
-
|
|
10
|
-
public constructor(props: TransformerError.IProps) {
|
|
11
|
-
super(props.message);
|
|
12
|
-
this.code = props.code;
|
|
13
|
-
|
|
14
|
-
// INHERITANCE POLYFILL
|
|
15
|
-
const proto = new.target.prototype;
|
|
16
|
-
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
17
|
-
else (this as any).__proto__ = proto;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export namespace TransformerError {
|
|
21
|
-
export interface IProps {
|
|
22
|
-
code: string;
|
|
23
|
-
message: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const from = (props: {
|
|
27
|
-
code: string;
|
|
28
|
-
errors: MetadataFactory.IError[];
|
|
29
|
-
}): TransformerError => {
|
|
30
|
-
const body: string = props.errors
|
|
31
|
-
.map((e) => {
|
|
32
|
-
const subject: string =
|
|
33
|
-
e.explore.object === null
|
|
34
|
-
? ""
|
|
35
|
-
: join(e.explore.object)(e.explore.property);
|
|
36
|
-
const middle: string = e.explore.parameter
|
|
37
|
-
? `(parameter: ${JSON.stringify(e.explore.parameter)})`
|
|
38
|
-
: e.explore.output
|
|
39
|
-
? "(return type)"
|
|
40
|
-
: "";
|
|
41
|
-
const type: string = `${subject.length ? `${subject}: ` : ""}${e.name}`;
|
|
42
|
-
return `- ${type}${middle}\n${e.messages
|
|
43
|
-
.map((msg) => ` - ${msg}`)
|
|
44
|
-
.join("\n")}`;
|
|
45
|
-
})
|
|
46
|
-
.join("\n\n");
|
|
47
|
-
return new TransformerError({
|
|
48
|
-
code: props.code,
|
|
49
|
-
message: `unsupported type detected\n\n${body}`,
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const join = (object: MetadataObject) => (key: string | object | null) => {
|
|
54
|
-
if (key === null) return object.name;
|
|
55
|
-
else if (typeof key === "object") return `${object.name}[key]`;
|
|
56
|
-
else if (Escaper.variable(key)) return `${object.name}.${key}`;
|
|
57
|
-
return `${object.name}[${JSON.stringify(key)}]`;
|
|
58
|
-
};
|
|
59
|
-
}
|
|
1
|
+
import { MetadataFactory } from "../factories/MetadataFactory";
|
|
2
|
+
|
|
3
|
+
import { MetadataObject } from "../schemas/metadata/MetadataObject";
|
|
4
|
+
|
|
5
|
+
import { Escaper } from "../utils/Escaper";
|
|
6
|
+
|
|
7
|
+
export class TransformerError extends Error {
|
|
8
|
+
public readonly code: string;
|
|
9
|
+
|
|
10
|
+
public constructor(props: TransformerError.IProps) {
|
|
11
|
+
super(props.message);
|
|
12
|
+
this.code = props.code;
|
|
13
|
+
|
|
14
|
+
// INHERITANCE POLYFILL
|
|
15
|
+
const proto = new.target.prototype;
|
|
16
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
17
|
+
else (this as any).__proto__ = proto;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export namespace TransformerError {
|
|
21
|
+
export interface IProps {
|
|
22
|
+
code: string;
|
|
23
|
+
message: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const from = (props: {
|
|
27
|
+
code: string;
|
|
28
|
+
errors: MetadataFactory.IError[];
|
|
29
|
+
}): TransformerError => {
|
|
30
|
+
const body: string = props.errors
|
|
31
|
+
.map((e) => {
|
|
32
|
+
const subject: string =
|
|
33
|
+
e.explore.object === null
|
|
34
|
+
? ""
|
|
35
|
+
: join(e.explore.object)(e.explore.property);
|
|
36
|
+
const middle: string = e.explore.parameter
|
|
37
|
+
? `(parameter: ${JSON.stringify(e.explore.parameter)})`
|
|
38
|
+
: e.explore.output
|
|
39
|
+
? "(return type)"
|
|
40
|
+
: "";
|
|
41
|
+
const type: string = `${subject.length ? `${subject}: ` : ""}${e.name}`;
|
|
42
|
+
return `- ${type}${middle}\n${e.messages
|
|
43
|
+
.map((msg) => ` - ${msg}`)
|
|
44
|
+
.join("\n")}`;
|
|
45
|
+
})
|
|
46
|
+
.join("\n\n");
|
|
47
|
+
return new TransformerError({
|
|
48
|
+
code: props.code,
|
|
49
|
+
message: `unsupported type detected\n\n${body}`,
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const join = (object: MetadataObject) => (key: string | object | null) => {
|
|
54
|
+
if (key === null) return object.name;
|
|
55
|
+
else if (typeof key === "object") return `${object.name}[key]`;
|
|
56
|
+
else if (Escaper.variable(key)) return `${object.name}.${key}`;
|
|
57
|
+
return `${object.name}[${JSON.stringify(key)}]`;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { AssertProgrammer } from "../../programmers/AssertProgrammer";
|
|
2
|
-
|
|
3
|
-
import { ITransformProps } from "../ITransformProps";
|
|
4
|
-
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
-
|
|
6
|
-
export namespace AssertTransformer {
|
|
7
|
-
export const transform =
|
|
8
|
-
(config: AssertProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
-
GenericTransformer.scalar({
|
|
10
|
-
...props,
|
|
11
|
-
method: config.equals
|
|
12
|
-
? config.guard
|
|
13
|
-
? "assertGuardEquals"
|
|
14
|
-
: "assertEquals"
|
|
15
|
-
: config.guard
|
|
16
|
-
? "assertGuard"
|
|
17
|
-
: "assert",
|
|
18
|
-
write: (x) =>
|
|
19
|
-
AssertProgrammer.write({
|
|
20
|
-
...x,
|
|
21
|
-
config,
|
|
22
|
-
}),
|
|
23
|
-
});
|
|
24
|
-
}
|
|
1
|
+
import { AssertProgrammer } from "../../programmers/AssertProgrammer";
|
|
2
|
+
|
|
3
|
+
import { ITransformProps } from "../ITransformProps";
|
|
4
|
+
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
+
|
|
6
|
+
export namespace AssertTransformer {
|
|
7
|
+
export const transform =
|
|
8
|
+
(config: AssertProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
+
GenericTransformer.scalar({
|
|
10
|
+
...props,
|
|
11
|
+
method: config.equals
|
|
12
|
+
? config.guard
|
|
13
|
+
? "assertGuardEquals"
|
|
14
|
+
: "assertEquals"
|
|
15
|
+
: config.guard
|
|
16
|
+
? "assertGuard"
|
|
17
|
+
: "assert",
|
|
18
|
+
write: (x) =>
|
|
19
|
+
AssertProgrammer.write({
|
|
20
|
+
...x,
|
|
21
|
+
config,
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { AssertProgrammer } from "../../programmers/AssertProgrammer";
|
|
2
|
-
|
|
3
|
-
import { ITransformProps } from "../ITransformProps";
|
|
4
|
-
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
-
|
|
6
|
-
export namespace CreateAssertTransformer {
|
|
7
|
-
export const transform =
|
|
8
|
-
(config: AssertProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
-
GenericTransformer.factory({
|
|
10
|
-
...props,
|
|
11
|
-
method: config.equals
|
|
12
|
-
? config.guard
|
|
13
|
-
? "assertGuardEquals"
|
|
14
|
-
: "assertEquals"
|
|
15
|
-
: config.guard
|
|
16
|
-
? "assertGuard"
|
|
17
|
-
: "assert",
|
|
18
|
-
write: (x) =>
|
|
19
|
-
AssertProgrammer.write({
|
|
20
|
-
...x,
|
|
21
|
-
config,
|
|
22
|
-
}),
|
|
23
|
-
});
|
|
24
|
-
}
|
|
1
|
+
import { AssertProgrammer } from "../../programmers/AssertProgrammer";
|
|
2
|
+
|
|
3
|
+
import { ITransformProps } from "../ITransformProps";
|
|
4
|
+
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
+
|
|
6
|
+
export namespace CreateAssertTransformer {
|
|
7
|
+
export const transform =
|
|
8
|
+
(config: AssertProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
+
GenericTransformer.factory({
|
|
10
|
+
...props,
|
|
11
|
+
method: config.equals
|
|
12
|
+
? config.guard
|
|
13
|
+
? "assertGuardEquals"
|
|
14
|
+
: "assertEquals"
|
|
15
|
+
: config.guard
|
|
16
|
+
? "assertGuard"
|
|
17
|
+
: "assert",
|
|
18
|
+
write: (x) =>
|
|
19
|
+
AssertProgrammer.write({
|
|
20
|
+
...x,
|
|
21
|
+
config,
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { IsProgrammer } from "../../programmers/IsProgrammer";
|
|
2
|
-
|
|
3
|
-
import { ITransformProps } from "../ITransformProps";
|
|
4
|
-
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
-
|
|
6
|
-
export namespace CreateIsTransformer {
|
|
7
|
-
export const transform =
|
|
8
|
-
(config: IsProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
-
GenericTransformer.factory({
|
|
10
|
-
...props,
|
|
11
|
-
method: config.equals ? "equals" : "is",
|
|
12
|
-
write: (x) =>
|
|
13
|
-
IsProgrammer.write({
|
|
14
|
-
...x,
|
|
15
|
-
config,
|
|
16
|
-
}),
|
|
17
|
-
});
|
|
18
|
-
}
|
|
1
|
+
import { IsProgrammer } from "../../programmers/IsProgrammer";
|
|
2
|
+
|
|
3
|
+
import { ITransformProps } from "../ITransformProps";
|
|
4
|
+
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
+
|
|
6
|
+
export namespace CreateIsTransformer {
|
|
7
|
+
export const transform =
|
|
8
|
+
(config: IsProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
+
GenericTransformer.factory({
|
|
10
|
+
...props,
|
|
11
|
+
method: config.equals ? "equals" : "is",
|
|
12
|
+
write: (x) =>
|
|
13
|
+
IsProgrammer.write({
|
|
14
|
+
...x,
|
|
15
|
+
config,
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { RandomProgrammer } from "../../programmers/RandomProgrammer";
|
|
4
|
-
|
|
5
|
-
import { ITransformProps } from "../ITransformProps";
|
|
6
|
-
import { TransformerError } from "../TransformerError";
|
|
7
|
-
|
|
8
|
-
export namespace CreateRandomTransformer {
|
|
9
|
-
export const transform = (props: ITransformProps): ts.Expression => {
|
|
10
|
-
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
11
|
-
if (!props.expression.typeArguments?.[0])
|
|
12
|
-
throw new TransformerError({
|
|
13
|
-
code: "typia.createRandom",
|
|
14
|
-
message: "generic argument is not specified.",
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// GET TYPE INFO
|
|
18
|
-
const node: ts.TypeNode = props.expression.typeArguments[0];
|
|
19
|
-
const type: ts.Type = props.context.checker.getTypeFromTypeNode(node);
|
|
20
|
-
|
|
21
|
-
if (type.isTypeParameter())
|
|
22
|
-
throw new TransformerError({
|
|
23
|
-
code: "typia.createRandom",
|
|
24
|
-
message: "non-specified generic argument.",
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// DO TRANSFORM
|
|
28
|
-
return RandomProgrammer.write({
|
|
29
|
-
context: {
|
|
30
|
-
...props.context,
|
|
31
|
-
options: {
|
|
32
|
-
...props.context.options,
|
|
33
|
-
functional: false,
|
|
34
|
-
numeric: false,
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
modulo: props.modulo,
|
|
38
|
-
type,
|
|
39
|
-
name: node.getFullText().trim(),
|
|
40
|
-
init: props.expression.arguments?.[0],
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { RandomProgrammer } from "../../programmers/RandomProgrammer";
|
|
4
|
+
|
|
5
|
+
import { ITransformProps } from "../ITransformProps";
|
|
6
|
+
import { TransformerError } from "../TransformerError";
|
|
7
|
+
|
|
8
|
+
export namespace CreateRandomTransformer {
|
|
9
|
+
export const transform = (props: ITransformProps): ts.Expression => {
|
|
10
|
+
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
11
|
+
if (!props.expression.typeArguments?.[0])
|
|
12
|
+
throw new TransformerError({
|
|
13
|
+
code: "typia.createRandom",
|
|
14
|
+
message: "generic argument is not specified.",
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// GET TYPE INFO
|
|
18
|
+
const node: ts.TypeNode = props.expression.typeArguments[0];
|
|
19
|
+
const type: ts.Type = props.context.checker.getTypeFromTypeNode(node);
|
|
20
|
+
|
|
21
|
+
if (type.isTypeParameter())
|
|
22
|
+
throw new TransformerError({
|
|
23
|
+
code: "typia.createRandom",
|
|
24
|
+
message: "non-specified generic argument.",
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// DO TRANSFORM
|
|
28
|
+
return RandomProgrammer.write({
|
|
29
|
+
context: {
|
|
30
|
+
...props.context,
|
|
31
|
+
options: {
|
|
32
|
+
...props.context.options,
|
|
33
|
+
functional: false,
|
|
34
|
+
numeric: false,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
modulo: props.modulo,
|
|
38
|
+
type,
|
|
39
|
+
name: node.getFullText().trim(),
|
|
40
|
+
init: props.expression.arguments?.[0],
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { ValidateProgrammer } from "../../programmers/ValidateProgrammer";
|
|
2
|
-
|
|
3
|
-
import { ITransformProps } from "../ITransformProps";
|
|
4
|
-
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
-
|
|
6
|
-
export namespace CreateValidateTransformer {
|
|
7
|
-
export const transform =
|
|
8
|
-
(config: ValidateProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
-
GenericTransformer.factory({
|
|
10
|
-
...props,
|
|
11
|
-
method: config.equals ? "validateEquals" : "validate",
|
|
12
|
-
write: (x) =>
|
|
13
|
-
ValidateProgrammer.write({
|
|
14
|
-
...x,
|
|
15
|
-
config,
|
|
16
|
-
}),
|
|
17
|
-
});
|
|
18
|
-
}
|
|
1
|
+
import { ValidateProgrammer } from "../../programmers/ValidateProgrammer";
|
|
2
|
+
|
|
3
|
+
import { ITransformProps } from "../ITransformProps";
|
|
4
|
+
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
+
|
|
6
|
+
export namespace CreateValidateTransformer {
|
|
7
|
+
export const transform =
|
|
8
|
+
(config: ValidateProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
+
GenericTransformer.factory({
|
|
10
|
+
...props,
|
|
11
|
+
method: config.equals ? "validateEquals" : "validate",
|
|
12
|
+
write: (x) =>
|
|
13
|
+
ValidateProgrammer.write({
|
|
14
|
+
...x,
|
|
15
|
+
config,
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { IsProgrammer } from "../../programmers/IsProgrammer";
|
|
2
|
-
|
|
3
|
-
import { ITransformProps } from "../ITransformProps";
|
|
4
|
-
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
-
|
|
6
|
-
export namespace IsTransformer {
|
|
7
|
-
export const transform =
|
|
8
|
-
(config: IsProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
-
GenericTransformer.scalar({
|
|
10
|
-
...props,
|
|
11
|
-
method: config.equals ? "equals" : "is",
|
|
12
|
-
write: (x) =>
|
|
13
|
-
IsProgrammer.write({
|
|
14
|
-
...x,
|
|
15
|
-
config,
|
|
16
|
-
}),
|
|
17
|
-
});
|
|
18
|
-
}
|
|
1
|
+
import { IsProgrammer } from "../../programmers/IsProgrammer";
|
|
2
|
+
|
|
3
|
+
import { ITransformProps } from "../ITransformProps";
|
|
4
|
+
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
+
|
|
6
|
+
export namespace IsTransformer {
|
|
7
|
+
export const transform =
|
|
8
|
+
(config: IsProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
+
GenericTransformer.scalar({
|
|
10
|
+
...props,
|
|
11
|
+
method: config.equals ? "equals" : "is",
|
|
12
|
+
write: (x) =>
|
|
13
|
+
IsProgrammer.write({
|
|
14
|
+
...x,
|
|
15
|
+
config,
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { RandomProgrammer } from "../../programmers/RandomProgrammer";
|
|
4
|
-
|
|
5
|
-
import { ITransformProps } from "../ITransformProps";
|
|
6
|
-
import { TransformerError } from "../TransformerError";
|
|
7
|
-
|
|
8
|
-
export namespace RandomTransformer {
|
|
9
|
-
export const transform = (props: ITransformProps): ts.Expression => {
|
|
10
|
-
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
11
|
-
if (!props.expression.typeArguments?.[0])
|
|
12
|
-
throw new TransformerError({
|
|
13
|
-
code: `typia.${props.modulo.getText()}`,
|
|
14
|
-
message: "generic argument is not specified.",
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// GET TYPE INFO
|
|
18
|
-
const node: ts.TypeNode = props.expression.typeArguments[0];
|
|
19
|
-
const type: ts.Type = props.context.checker.getTypeFromTypeNode(node);
|
|
20
|
-
|
|
21
|
-
if (type.isTypeParameter())
|
|
22
|
-
throw new TransformerError({
|
|
23
|
-
code: `typia.${props.modulo.getText()}`,
|
|
24
|
-
message: "non-specified generic argument.",
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
return ts.factory.createCallExpression(
|
|
28
|
-
RandomProgrammer.write({
|
|
29
|
-
context: props.context,
|
|
30
|
-
modulo: props.modulo,
|
|
31
|
-
type,
|
|
32
|
-
name: node.getFullText().trim(),
|
|
33
|
-
init: undefined,
|
|
34
|
-
}),
|
|
35
|
-
undefined,
|
|
36
|
-
props.expression.arguments.length
|
|
37
|
-
? [props.expression.arguments[0]!]
|
|
38
|
-
: undefined,
|
|
39
|
-
);
|
|
40
|
-
};
|
|
41
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { RandomProgrammer } from "../../programmers/RandomProgrammer";
|
|
4
|
+
|
|
5
|
+
import { ITransformProps } from "../ITransformProps";
|
|
6
|
+
import { TransformerError } from "../TransformerError";
|
|
7
|
+
|
|
8
|
+
export namespace RandomTransformer {
|
|
9
|
+
export const transform = (props: ITransformProps): ts.Expression => {
|
|
10
|
+
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
11
|
+
if (!props.expression.typeArguments?.[0])
|
|
12
|
+
throw new TransformerError({
|
|
13
|
+
code: `typia.${props.modulo.getText()}`,
|
|
14
|
+
message: "generic argument is not specified.",
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// GET TYPE INFO
|
|
18
|
+
const node: ts.TypeNode = props.expression.typeArguments[0];
|
|
19
|
+
const type: ts.Type = props.context.checker.getTypeFromTypeNode(node);
|
|
20
|
+
|
|
21
|
+
if (type.isTypeParameter())
|
|
22
|
+
throw new TransformerError({
|
|
23
|
+
code: `typia.${props.modulo.getText()}`,
|
|
24
|
+
message: "non-specified generic argument.",
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return ts.factory.createCallExpression(
|
|
28
|
+
RandomProgrammer.write({
|
|
29
|
+
context: props.context,
|
|
30
|
+
modulo: props.modulo,
|
|
31
|
+
type,
|
|
32
|
+
name: node.getFullText().trim(),
|
|
33
|
+
init: undefined,
|
|
34
|
+
}),
|
|
35
|
+
undefined,
|
|
36
|
+
props.expression.arguments.length
|
|
37
|
+
? [props.expression.arguments[0]!]
|
|
38
|
+
: undefined,
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { ValidateProgrammer } from "../../programmers/ValidateProgrammer";
|
|
2
|
-
|
|
3
|
-
import { ITransformProps } from "../ITransformProps";
|
|
4
|
-
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
-
|
|
6
|
-
export namespace ValidateTransformer {
|
|
7
|
-
export const transform =
|
|
8
|
-
(config: ValidateProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
-
GenericTransformer.scalar({
|
|
10
|
-
...props,
|
|
11
|
-
method: config.equals ? "validateEquals" : "validate",
|
|
12
|
-
write: (x) =>
|
|
13
|
-
ValidateProgrammer.write({
|
|
14
|
-
...x,
|
|
15
|
-
config,
|
|
16
|
-
}),
|
|
17
|
-
});
|
|
18
|
-
}
|
|
1
|
+
import { ValidateProgrammer } from "../../programmers/ValidateProgrammer";
|
|
2
|
+
|
|
3
|
+
import { ITransformProps } from "../ITransformProps";
|
|
4
|
+
import { GenericTransformer } from "../internal/GenericTransformer";
|
|
5
|
+
|
|
6
|
+
export namespace ValidateTransformer {
|
|
7
|
+
export const transform =
|
|
8
|
+
(config: ValidateProgrammer.IConfig) => (props: ITransformProps) =>
|
|
9
|
+
GenericTransformer.scalar({
|
|
10
|
+
...props,
|
|
11
|
+
method: config.equals ? "validateEquals" : "validate",
|
|
12
|
+
write: (x) =>
|
|
13
|
+
ValidateProgrammer.write({
|
|
14
|
+
...x,
|
|
15
|
+
config,
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { TypeFactory } from "../../../factories/TypeFactory";
|
|
4
|
-
|
|
5
|
-
import { ITransformProps } from "../../ITransformProps";
|
|
6
|
-
import { ITypiaContext } from "../../ITypiaContext";
|
|
7
|
-
import { TransformerError } from "../../TransformerError";
|
|
8
|
-
|
|
9
|
-
export namespace FunctionalGenericTransformer {
|
|
10
|
-
export interface IConfig {
|
|
11
|
-
equals: boolean;
|
|
12
|
-
}
|
|
13
|
-
export interface ISpecification {
|
|
14
|
-
method: string;
|
|
15
|
-
config: IConfig;
|
|
16
|
-
programmer: (p: {
|
|
17
|
-
context: ITypiaContext;
|
|
18
|
-
modulo: ts.LeftHandSideExpression;
|
|
19
|
-
expression: ts.Expression;
|
|
20
|
-
declaration: ts.FunctionDeclaration;
|
|
21
|
-
config: IConfig;
|
|
22
|
-
init?: ts.Expression;
|
|
23
|
-
}) => ts.Expression;
|
|
24
|
-
}
|
|
25
|
-
export const transform =
|
|
26
|
-
(spec: ISpecification) =>
|
|
27
|
-
(props: ITransformProps): ts.Expression => {
|
|
28
|
-
// CHECK PARAMETER
|
|
29
|
-
if (props.expression.arguments.length === 0)
|
|
30
|
-
throw new TransformerError({
|
|
31
|
-
code: `typia.functional.${spec.method}`,
|
|
32
|
-
message: `no input value.`,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// GET TYPE INFO
|
|
36
|
-
const type: ts.Type =
|
|
37
|
-
props.expression.typeArguments && props.expression.typeArguments[0]
|
|
38
|
-
? props.context.checker.getTypeFromTypeNode(
|
|
39
|
-
props.expression.typeArguments[0],
|
|
40
|
-
)
|
|
41
|
-
: props.context.checker.getTypeAtLocation(
|
|
42
|
-
props.expression.arguments[0]!,
|
|
43
|
-
);
|
|
44
|
-
if (TypeFactory.isFunction(type) === false)
|
|
45
|
-
throw new TransformerError({
|
|
46
|
-
code: `typia.functional.${spec.method}`,
|
|
47
|
-
message: `input value is not a function.`,
|
|
48
|
-
});
|
|
49
|
-
return spec.programmer({
|
|
50
|
-
...props,
|
|
51
|
-
config: spec.config,
|
|
52
|
-
expression: props.expression.arguments[0] as ts.Expression,
|
|
53
|
-
declaration: type.symbol!.declarations![0] as ts.FunctionDeclaration,
|
|
54
|
-
init: props.expression.arguments[1],
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { TypeFactory } from "../../../factories/TypeFactory";
|
|
4
|
+
|
|
5
|
+
import { ITransformProps } from "../../ITransformProps";
|
|
6
|
+
import { ITypiaContext } from "../../ITypiaContext";
|
|
7
|
+
import { TransformerError } from "../../TransformerError";
|
|
8
|
+
|
|
9
|
+
export namespace FunctionalGenericTransformer {
|
|
10
|
+
export interface IConfig {
|
|
11
|
+
equals: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface ISpecification {
|
|
14
|
+
method: string;
|
|
15
|
+
config: IConfig;
|
|
16
|
+
programmer: (p: {
|
|
17
|
+
context: ITypiaContext;
|
|
18
|
+
modulo: ts.LeftHandSideExpression;
|
|
19
|
+
expression: ts.Expression;
|
|
20
|
+
declaration: ts.FunctionDeclaration;
|
|
21
|
+
config: IConfig;
|
|
22
|
+
init?: ts.Expression;
|
|
23
|
+
}) => ts.Expression;
|
|
24
|
+
}
|
|
25
|
+
export const transform =
|
|
26
|
+
(spec: ISpecification) =>
|
|
27
|
+
(props: ITransformProps): ts.Expression => {
|
|
28
|
+
// CHECK PARAMETER
|
|
29
|
+
if (props.expression.arguments.length === 0)
|
|
30
|
+
throw new TransformerError({
|
|
31
|
+
code: `typia.functional.${spec.method}`,
|
|
32
|
+
message: `no input value.`,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// GET TYPE INFO
|
|
36
|
+
const type: ts.Type =
|
|
37
|
+
props.expression.typeArguments && props.expression.typeArguments[0]
|
|
38
|
+
? props.context.checker.getTypeFromTypeNode(
|
|
39
|
+
props.expression.typeArguments[0],
|
|
40
|
+
)
|
|
41
|
+
: props.context.checker.getTypeAtLocation(
|
|
42
|
+
props.expression.arguments[0]!,
|
|
43
|
+
);
|
|
44
|
+
if (TypeFactory.isFunction(type) === false)
|
|
45
|
+
throw new TransformerError({
|
|
46
|
+
code: `typia.functional.${spec.method}`,
|
|
47
|
+
message: `input value is not a function.`,
|
|
48
|
+
});
|
|
49
|
+
return spec.programmer({
|
|
50
|
+
...props,
|
|
51
|
+
config: spec.config,
|
|
52
|
+
expression: props.expression.arguments[0] as ts.Expression,
|
|
53
|
+
declaration: type.symbol!.declarations![0] as ts.FunctionDeclaration,
|
|
54
|
+
init: props.expression.arguments[1],
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
}
|