typia 7.0.0-dev.20241009-3 → 7.0.0-dev.20241010
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/JsonMetadataFactory.d.ts +5 -1
- package/lib/factories/JsonMetadataFactory.js +4 -1
- package/lib/factories/JsonMetadataFactory.js.map +1 -1
- package/lib/internal/{$httpFormDataReadArray.js → $httpFormdataReadArray.js} +1 -1
- package/lib/internal/$httpFormdataReadArray.js.map +1 -0
- package/lib/programmers/CheckerProgrammer.js +4 -1
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/FeatureProgrammer.d.ts +4 -1
- package/lib/programmers/FeatureProgrammer.js +2 -2
- package/lib/programmers/FeatureProgrammer.js.map +1 -1
- package/lib/programmers/TypiaProgrammer.js +4 -1
- package/lib/programmers/TypiaProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js +4 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js +4 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +4 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/transformers/FileTransformer.js +0 -6
- package/lib/transformers/FileTransformer.js.map +1 -1
- package/lib/transformers/ImportTransformer.d.ts +4 -1
- package/lib/transformers/ImportTransformer.js +34 -30
- package/lib/transformers/ImportTransformer.js.map +1 -1
- package/package.json +1 -1
- package/src/IRandomGenerator.ts +49 -49
- package/src/factories/ExpressionFactory.ts +164 -164
- package/src/factories/JsonMetadataFactory.ts +25 -15
- package/src/factories/LiteralFactory.ts +50 -50
- package/src/factories/MetadataCommentTagFactory.ts +650 -650
- package/src/functional.ts +750 -750
- package/src/http.ts +1042 -1042
- package/src/internal/$IProtobufWriter.ts +18 -18
- package/src/internal/$ProtobufReader.ts +194 -194
- package/src/internal/$ProtobufSizer.ts +151 -151
- package/src/internal/$ProtobufWriter.ts +145 -145
- package/src/internal/$accessExpressionAsString.ts +46 -46
- package/src/internal/$assertGuard.ts +13 -13
- package/src/internal/$functionalTypeGuardErrorFactory.ts +4 -4
- package/src/internal/$httpFormDataReadBigint.ts +18 -18
- package/src/internal/$httpFormDataReadBlob.ts +10 -10
- package/src/internal/$httpFormDataReadBoolean.ts +16 -16
- package/src/internal/$httpFormDataReadFile.ts +10 -10
- package/src/internal/$httpFormDataReadNumber.ts +15 -15
- package/src/internal/$httpFormDataReadString.ts +10 -10
- package/src/internal/{$httpFormDataReadArray.ts → $httpFormdataReadArray.ts} +4 -4
- package/src/internal/$httpHeaderReadBigint.ts +10 -10
- package/src/internal/$httpHeaderReadBoolean.ts +8 -8
- package/src/internal/$httpHeaderReadNumber.ts +7 -7
- package/src/internal/$httpParameterBigint.ts +10 -10
- package/src/internal/$httpParameterBoolean.ts +8 -8
- package/src/internal/$httpParameterNumber.ts +7 -7
- package/src/internal/$httpParameterString.ts +2 -2
- package/src/internal/$httpQueryParseURLSearchParams.ts +10 -10
- package/src/internal/$httpQueryReadArray.ts +4 -4
- package/src/internal/$httpQueryReadBigint.ts +12 -12
- package/src/internal/$httpQueryReadBoolean.ts +14 -14
- package/src/internal/$httpQueryReadNumber.ts +9 -9
- package/src/internal/$httpQueryReadString.ts +4 -4
- package/src/internal/$isBetween.ts +2 -2
- package/src/internal/$isBigintString.ts +8 -8
- package/src/internal/$jsonStringifyNumber.ts +12 -12
- package/src/internal/$jsonStringifyRest.ts +3 -3
- package/src/internal/$jsonStringifyString.ts +42 -42
- package/src/internal/$jsonStringifyTail.ts +2 -2
- package/src/internal/$llmApplicationFinalize.ts +18 -18
- package/src/internal/$miscCloneAny.ts +48 -48
- package/src/internal/$notationAny.ts +37 -37
- package/src/internal/$notationCamel.ts +13 -13
- package/src/internal/$notationPascal.ts +8 -8
- package/src/internal/$notationSnake.ts +43 -43
- package/src/internal/$randomArray.ts +21 -21
- package/src/internal/$randomBigint.ts +6 -6
- package/src/internal/$randomBoolean.ts +1 -1
- package/src/internal/$randomFormatByte.ts +3 -3
- package/src/internal/$randomFormatDate.ts +18 -18
- package/src/internal/$randomFormatDatetime.ts +16 -16
- package/src/internal/$randomFormatDuration.ts +27 -27
- package/src/internal/$randomFormatEmail.ts +11 -11
- package/src/internal/$randomFormatHostname.ts +6 -6
- package/src/internal/$randomFormatIdnEmail.ts +3 -3
- package/src/internal/$randomFormatIdnHostname.ts +3 -3
- package/src/internal/$randomFormatIpv4.ts +11 -11
- package/src/internal/$randomFormatIpv6.ts +11 -11
- package/src/internal/$randomFormatIri.ts +3 -3
- package/src/internal/$randomFormatIriReference.ts +3 -3
- package/src/internal/$randomFormatJsonPointer.ts +7 -7
- package/src/internal/$randomFormatPassword.ts +8 -8
- package/src/internal/$randomFormatRegex.ts +4 -4
- package/src/internal/$randomFormatRelativeJsonPointer.ts +8 -8
- package/src/internal/$randomFormatTime.ts +14 -14
- package/src/internal/$randomFormatUri.ts +3 -3
- package/src/internal/$randomFormatUriReference.ts +3 -3
- package/src/internal/$randomFormatUriTemplate.ts +3 -3
- package/src/internal/$randomFormatUrl.ts +11 -11
- package/src/internal/$randomFormatUuid.ts +6 -6
- package/src/internal/$randomInteger.ts +47 -47
- package/src/internal/$randomNumber.ts +74 -74
- package/src/internal/$randomPattern.ts +10 -10
- package/src/internal/$randomPick.ts +9 -9
- package/src/internal/$randomString.ts +24 -24
- package/src/internal/$throwTypeGuardError.ts +5 -5
- package/src/internal/$validateReport.ts +13 -13
- package/src/internal/private/$__notationCapitalize.ts +2 -2
- package/src/internal/private/$__notationUnsnake.ts +24 -24
- package/src/json.ts +651 -651
- package/src/llm.ts +178 -178
- package/src/misc.ts +658 -658
- package/src/module.ts +933 -933
- package/src/notations.ts +827 -827
- package/src/programmers/CheckerProgrammer.ts +4 -1
- package/src/programmers/FeatureProgrammer.ts +619 -616
- package/src/programmers/TypiaProgrammer.ts +4 -1
- package/src/programmers/functional/FunctionalAssertFunctionProgrammer.ts +153 -153
- package/src/programmers/functional/FunctionalAssertParametersProgrammer.ts +125 -125
- package/src/programmers/functional/FunctionalAssertReturnProgrammer.ts +115 -115
- package/src/programmers/functional/FunctionalValidateFunctionProgrammer.ts +119 -119
- package/src/programmers/functional/FunctionalValidateParametersProgrammer.ts +274 -274
- package/src/programmers/functional/FunctionalValidateReturnProgrammer.ts +135 -135
- package/src/programmers/helpers/FunctionProgrammer.ts +67 -67
- package/src/programmers/helpers/RandomJoiner.ts +168 -168
- package/src/programmers/helpers/StringifyJoinder.ts +115 -115
- package/src/programmers/helpers/disable_function_programmer_declare.ts +32 -32
- package/src/programmers/internal/check_dynamic_key.ts +201 -201
- package/src/programmers/internal/check_dynamic_properties.ts +208 -208
- package/src/programmers/internal/check_object.ts +75 -75
- package/src/programmers/internal/feature_object_entries.ts +61 -61
- package/src/programmers/internal/prune_object_properties.ts +71 -71
- package/src/programmers/llm/LlmApplicationProgrammer.ts +235 -235
- package/src/programmers/llm/LlmSchemaProgrammer.ts +51 -51
- package/src/programmers/misc/MiscCloneProgrammer.ts +4 -1
- package/src/programmers/misc/MiscPruneProgrammer.ts +4 -1
- package/src/programmers/notations/NotationGeneralProgrammer.ts +4 -1
- package/src/protobuf.ts +868 -868
- package/src/reflect.ts +57 -57
- package/src/transformers/FileTransformer.ts +0 -6
- package/src/transformers/ImportTransformer.ts +59 -44
- package/src/utils/NamingConvention.ts +94 -94
- package/src/utils/StringUtil.ts +16 -16
- package/lib/internal/$httpFormDataReadArray.js.map +0 -1
- /package/lib/internal/{$httpFormDataReadArray.d.ts → $httpFormdataReadArray.d.ts} +0 -0
|
@@ -1,164 +1,164 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { $randomFormatUuid } from "../internal/$randomFormatUuid";
|
|
4
|
-
|
|
5
|
-
export namespace ExpressionFactory {
|
|
6
|
-
export const number = (value: number) =>
|
|
7
|
-
value < 0
|
|
8
|
-
? ts.factory.createPrefixUnaryExpression(
|
|
9
|
-
ts.SyntaxKind.MinusToken,
|
|
10
|
-
ts.factory.createNumericLiteral(Math.abs(value)),
|
|
11
|
-
)
|
|
12
|
-
: ts.factory.createNumericLiteral(value);
|
|
13
|
-
|
|
14
|
-
export const bigint = (value: number | bigint) =>
|
|
15
|
-
ts.factory.createCallExpression(
|
|
16
|
-
ts.factory.createIdentifier("BigInt"),
|
|
17
|
-
undefined,
|
|
18
|
-
[ts.factory.createIdentifier(value.toString())],
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
export const isRequired = (input: ts.Expression): ts.Expression =>
|
|
22
|
-
ts.factory.createStrictInequality(
|
|
23
|
-
ts.factory.createIdentifier("undefined"),
|
|
24
|
-
input,
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
export const isArray = (input: ts.Expression): ts.Expression =>
|
|
28
|
-
ts.factory.createCallExpression(
|
|
29
|
-
ts.factory.createIdentifier("Array.isArray"),
|
|
30
|
-
undefined,
|
|
31
|
-
[input],
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
export const isObject = (props: {
|
|
35
|
-
checkNull: boolean;
|
|
36
|
-
checkArray: boolean;
|
|
37
|
-
input: ts.Expression;
|
|
38
|
-
}): ts.Expression => {
|
|
39
|
-
const conditions: ts.Expression[] = [
|
|
40
|
-
ts.factory.createStrictEquality(
|
|
41
|
-
ts.factory.createStringLiteral("object"),
|
|
42
|
-
ts.factory.createTypeOfExpression(props.input),
|
|
43
|
-
),
|
|
44
|
-
];
|
|
45
|
-
if (props.checkNull === true)
|
|
46
|
-
conditions.push(
|
|
47
|
-
ts.factory.createStrictInequality(ts.factory.createNull(), props.input),
|
|
48
|
-
);
|
|
49
|
-
if (props.checkArray === true)
|
|
50
|
-
conditions.push(
|
|
51
|
-
ts.factory.createStrictEquality(
|
|
52
|
-
ts.factory.createFalse(),
|
|
53
|
-
ts.factory.createCallExpression(
|
|
54
|
-
ts.factory.createIdentifier("Array.isArray"),
|
|
55
|
-
undefined,
|
|
56
|
-
[props.input],
|
|
57
|
-
),
|
|
58
|
-
),
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
return conditions.length === 1
|
|
62
|
-
? conditions[0]!
|
|
63
|
-
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export const isInstanceOf = (
|
|
67
|
-
type: string,
|
|
68
|
-
input: ts.Expression,
|
|
69
|
-
): ts.Expression => {
|
|
70
|
-
return ts.factory.createBinaryExpression(
|
|
71
|
-
input,
|
|
72
|
-
ts.factory.createToken(ts.SyntaxKind.InstanceOfKeyword),
|
|
73
|
-
ts.factory.createIdentifier(type),
|
|
74
|
-
);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export const coalesce = (x: ts.Expression, y: ts.Expression): ts.Expression =>
|
|
78
|
-
ts.factory.createBinaryExpression(
|
|
79
|
-
x,
|
|
80
|
-
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
|
|
81
|
-
y,
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
export const currying = (props: {
|
|
85
|
-
function: ts.Expression;
|
|
86
|
-
arguments: ts.Expression[];
|
|
87
|
-
}): ts.CallExpression => {
|
|
88
|
-
if (props.arguments.length === 0)
|
|
89
|
-
return ts.factory.createCallExpression(
|
|
90
|
-
props.function,
|
|
91
|
-
undefined,
|
|
92
|
-
undefined,
|
|
93
|
-
);
|
|
94
|
-
let prev: ts.CallExpression = ts.factory.createCallExpression(
|
|
95
|
-
props.function,
|
|
96
|
-
undefined,
|
|
97
|
-
[props.arguments[0]!],
|
|
98
|
-
);
|
|
99
|
-
for (const param of props.arguments.slice(1))
|
|
100
|
-
prev = ts.factory.createCallExpression(prev, undefined, [param]);
|
|
101
|
-
return prev;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
export const selfCall = (body: ts.ConciseBody) =>
|
|
105
|
-
ts.isCallExpression(body)
|
|
106
|
-
? body
|
|
107
|
-
: ts.factory.createCallExpression(
|
|
108
|
-
ts.factory.createParenthesizedExpression(
|
|
109
|
-
ts.factory.createArrowFunction(
|
|
110
|
-
undefined,
|
|
111
|
-
undefined,
|
|
112
|
-
[],
|
|
113
|
-
undefined,
|
|
114
|
-
undefined,
|
|
115
|
-
body,
|
|
116
|
-
),
|
|
117
|
-
),
|
|
118
|
-
undefined,
|
|
119
|
-
undefined,
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
export const getEscapedText = (props: {
|
|
123
|
-
printer: ts.Printer;
|
|
124
|
-
input: ts.Expression;
|
|
125
|
-
}): string =>
|
|
126
|
-
props.printer.printNode(
|
|
127
|
-
ts.EmitHint.Expression,
|
|
128
|
-
props.input,
|
|
129
|
-
props.input.getSourceFile(),
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
export const transpile = (
|
|
133
|
-
transformer: ts.TransformationContext,
|
|
134
|
-
script: string,
|
|
135
|
-
) => {
|
|
136
|
-
const file: ts.SourceFile = ts.createSourceFile(
|
|
137
|
-
`${$randomFormatUuid()}.ts`,
|
|
138
|
-
script,
|
|
139
|
-
ts.ScriptTarget.ESNext,
|
|
140
|
-
true,
|
|
141
|
-
ts.ScriptKind.TS,
|
|
142
|
-
);
|
|
143
|
-
const statement: ts.Statement | undefined = file.statements[0];
|
|
144
|
-
if (statement === undefined)
|
|
145
|
-
throw new ReferenceError(
|
|
146
|
-
"Error on ExpressionFactory.transpile(): no statement exists.",
|
|
147
|
-
);
|
|
148
|
-
else if (!ts.isExpressionStatement(statement))
|
|
149
|
-
throw new TypeError(
|
|
150
|
-
"Error on ExpressionFactory.transpile(): statement is not an expression statement.",
|
|
151
|
-
);
|
|
152
|
-
return (input: ts.Expression): ts.Expression => {
|
|
153
|
-
const visitor = (node: ts.Node): ts.Node => {
|
|
154
|
-
if (ts.isIdentifier(node) && node.text === "$input") return input;
|
|
155
|
-
return ts.visitEachChild(
|
|
156
|
-
(ts.factory as any).cloneNode(node),
|
|
157
|
-
visitor,
|
|
158
|
-
transformer,
|
|
159
|
-
);
|
|
160
|
-
};
|
|
161
|
-
return visitor(statement.expression) as ts.Expression;
|
|
162
|
-
};
|
|
163
|
-
};
|
|
164
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { $randomFormatUuid } from "../internal/$randomFormatUuid";
|
|
4
|
+
|
|
5
|
+
export namespace ExpressionFactory {
|
|
6
|
+
export const number = (value: number) =>
|
|
7
|
+
value < 0
|
|
8
|
+
? ts.factory.createPrefixUnaryExpression(
|
|
9
|
+
ts.SyntaxKind.MinusToken,
|
|
10
|
+
ts.factory.createNumericLiteral(Math.abs(value)),
|
|
11
|
+
)
|
|
12
|
+
: ts.factory.createNumericLiteral(value);
|
|
13
|
+
|
|
14
|
+
export const bigint = (value: number | bigint) =>
|
|
15
|
+
ts.factory.createCallExpression(
|
|
16
|
+
ts.factory.createIdentifier("BigInt"),
|
|
17
|
+
undefined,
|
|
18
|
+
[ts.factory.createIdentifier(value.toString())],
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const isRequired = (input: ts.Expression): ts.Expression =>
|
|
22
|
+
ts.factory.createStrictInequality(
|
|
23
|
+
ts.factory.createIdentifier("undefined"),
|
|
24
|
+
input,
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export const isArray = (input: ts.Expression): ts.Expression =>
|
|
28
|
+
ts.factory.createCallExpression(
|
|
29
|
+
ts.factory.createIdentifier("Array.isArray"),
|
|
30
|
+
undefined,
|
|
31
|
+
[input],
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
export const isObject = (props: {
|
|
35
|
+
checkNull: boolean;
|
|
36
|
+
checkArray: boolean;
|
|
37
|
+
input: ts.Expression;
|
|
38
|
+
}): ts.Expression => {
|
|
39
|
+
const conditions: ts.Expression[] = [
|
|
40
|
+
ts.factory.createStrictEquality(
|
|
41
|
+
ts.factory.createStringLiteral("object"),
|
|
42
|
+
ts.factory.createTypeOfExpression(props.input),
|
|
43
|
+
),
|
|
44
|
+
];
|
|
45
|
+
if (props.checkNull === true)
|
|
46
|
+
conditions.push(
|
|
47
|
+
ts.factory.createStrictInequality(ts.factory.createNull(), props.input),
|
|
48
|
+
);
|
|
49
|
+
if (props.checkArray === true)
|
|
50
|
+
conditions.push(
|
|
51
|
+
ts.factory.createStrictEquality(
|
|
52
|
+
ts.factory.createFalse(),
|
|
53
|
+
ts.factory.createCallExpression(
|
|
54
|
+
ts.factory.createIdentifier("Array.isArray"),
|
|
55
|
+
undefined,
|
|
56
|
+
[props.input],
|
|
57
|
+
),
|
|
58
|
+
),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
return conditions.length === 1
|
|
62
|
+
? conditions[0]!
|
|
63
|
+
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const isInstanceOf = (
|
|
67
|
+
type: string,
|
|
68
|
+
input: ts.Expression,
|
|
69
|
+
): ts.Expression => {
|
|
70
|
+
return ts.factory.createBinaryExpression(
|
|
71
|
+
input,
|
|
72
|
+
ts.factory.createToken(ts.SyntaxKind.InstanceOfKeyword),
|
|
73
|
+
ts.factory.createIdentifier(type),
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const coalesce = (x: ts.Expression, y: ts.Expression): ts.Expression =>
|
|
78
|
+
ts.factory.createBinaryExpression(
|
|
79
|
+
x,
|
|
80
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
|
|
81
|
+
y,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
export const currying = (props: {
|
|
85
|
+
function: ts.Expression;
|
|
86
|
+
arguments: ts.Expression[];
|
|
87
|
+
}): ts.CallExpression => {
|
|
88
|
+
if (props.arguments.length === 0)
|
|
89
|
+
return ts.factory.createCallExpression(
|
|
90
|
+
props.function,
|
|
91
|
+
undefined,
|
|
92
|
+
undefined,
|
|
93
|
+
);
|
|
94
|
+
let prev: ts.CallExpression = ts.factory.createCallExpression(
|
|
95
|
+
props.function,
|
|
96
|
+
undefined,
|
|
97
|
+
[props.arguments[0]!],
|
|
98
|
+
);
|
|
99
|
+
for (const param of props.arguments.slice(1))
|
|
100
|
+
prev = ts.factory.createCallExpression(prev, undefined, [param]);
|
|
101
|
+
return prev;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const selfCall = (body: ts.ConciseBody) =>
|
|
105
|
+
ts.isCallExpression(body)
|
|
106
|
+
? body
|
|
107
|
+
: ts.factory.createCallExpression(
|
|
108
|
+
ts.factory.createParenthesizedExpression(
|
|
109
|
+
ts.factory.createArrowFunction(
|
|
110
|
+
undefined,
|
|
111
|
+
undefined,
|
|
112
|
+
[],
|
|
113
|
+
undefined,
|
|
114
|
+
undefined,
|
|
115
|
+
body,
|
|
116
|
+
),
|
|
117
|
+
),
|
|
118
|
+
undefined,
|
|
119
|
+
undefined,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
export const getEscapedText = (props: {
|
|
123
|
+
printer: ts.Printer;
|
|
124
|
+
input: ts.Expression;
|
|
125
|
+
}): string =>
|
|
126
|
+
props.printer.printNode(
|
|
127
|
+
ts.EmitHint.Expression,
|
|
128
|
+
props.input,
|
|
129
|
+
props.input.getSourceFile(),
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
export const transpile = (
|
|
133
|
+
transformer: ts.TransformationContext,
|
|
134
|
+
script: string,
|
|
135
|
+
) => {
|
|
136
|
+
const file: ts.SourceFile = ts.createSourceFile(
|
|
137
|
+
`${$randomFormatUuid()}.ts`,
|
|
138
|
+
script,
|
|
139
|
+
ts.ScriptTarget.ESNext,
|
|
140
|
+
true,
|
|
141
|
+
ts.ScriptKind.TS,
|
|
142
|
+
);
|
|
143
|
+
const statement: ts.Statement | undefined = file.statements[0];
|
|
144
|
+
if (statement === undefined)
|
|
145
|
+
throw new ReferenceError(
|
|
146
|
+
"Error on ExpressionFactory.transpile(): no statement exists.",
|
|
147
|
+
);
|
|
148
|
+
else if (!ts.isExpressionStatement(statement))
|
|
149
|
+
throw new TypeError(
|
|
150
|
+
"Error on ExpressionFactory.transpile(): statement is not an expression statement.",
|
|
151
|
+
);
|
|
152
|
+
return (input: ts.Expression): ts.Expression => {
|
|
153
|
+
const visitor = (node: ts.Node): ts.Node => {
|
|
154
|
+
if (ts.isIdentifier(node) && node.text === "$input") return input;
|
|
155
|
+
return ts.visitEachChild(
|
|
156
|
+
(ts.factory as any).cloneNode(node),
|
|
157
|
+
visitor,
|
|
158
|
+
transformer,
|
|
159
|
+
);
|
|
160
|
+
};
|
|
161
|
+
return visitor(statement.expression) as ts.Expression;
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -6,6 +6,8 @@ import { AtomicPredicator } from "../programmers/helpers/AtomicPredicator";
|
|
|
6
6
|
|
|
7
7
|
import { TransformerError } from "../transformers/TransformerError";
|
|
8
8
|
|
|
9
|
+
import { ValidationPipe } from "../typings/ValidationPipe";
|
|
10
|
+
|
|
9
11
|
import { MetadataCollection } from "./MetadataCollection";
|
|
10
12
|
import { MetadataFactory } from "./MetadataFactory";
|
|
11
13
|
|
|
@@ -16,27 +18,35 @@ export namespace JsonMetadataFactory {
|
|
|
16
18
|
transformer?: ts.TransformationContext;
|
|
17
19
|
type: ts.Type;
|
|
18
20
|
}
|
|
21
|
+
export interface IOutput {
|
|
22
|
+
collection: MetadataCollection;
|
|
23
|
+
metadata: Metadata;
|
|
24
|
+
}
|
|
19
25
|
|
|
20
|
-
export const analyze = (props: IProps):
|
|
21
|
-
const collection = new MetadataCollection();
|
|
22
|
-
const result
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
export const analyze = (props: IProps): IOutput => {
|
|
27
|
+
const collection: MetadataCollection = new MetadataCollection();
|
|
28
|
+
const result: ValidationPipe<Metadata, MetadataFactory.IError> =
|
|
29
|
+
MetadataFactory.analyze({
|
|
30
|
+
checker: props.checker,
|
|
31
|
+
transformer: props.transformer,
|
|
32
|
+
options: {
|
|
33
|
+
escape: true,
|
|
34
|
+
constant: true,
|
|
35
|
+
absorb: true,
|
|
36
|
+
validate,
|
|
37
|
+
},
|
|
38
|
+
collection,
|
|
39
|
+
type: props.type,
|
|
40
|
+
});
|
|
34
41
|
if (result.success === false)
|
|
35
42
|
throw TransformerError.from({
|
|
36
43
|
code: props.method,
|
|
37
44
|
errors: result.errors,
|
|
38
45
|
});
|
|
39
|
-
return
|
|
46
|
+
return {
|
|
47
|
+
collection,
|
|
48
|
+
metadata: result.data,
|
|
49
|
+
};
|
|
40
50
|
};
|
|
41
51
|
|
|
42
52
|
export const validate = (meta: Metadata) => {
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { ExpressionFactory } from "./ExpressionFactory";
|
|
4
|
-
import { IdentifierFactory } from "./IdentifierFactory";
|
|
5
|
-
|
|
6
|
-
export namespace LiteralFactory {
|
|
7
|
-
export const write = (input: any): ts.Expression => {
|
|
8
|
-
if (input === null) return ts.factory.createNull();
|
|
9
|
-
else if (ts.isIdentifier(input)) return input;
|
|
10
|
-
else if (input instanceof Array) return writeArray(input);
|
|
11
|
-
else if (typeof input === "object") return writeObject(input);
|
|
12
|
-
else if (typeof input === "boolean") return writeBoolean(input);
|
|
13
|
-
else if (typeof input === "bigint") return writeBigint(input);
|
|
14
|
-
else if (typeof input === "number") return writeNumber(input);
|
|
15
|
-
else if (typeof input === "string") return writeStrinng(input);
|
|
16
|
-
// unreachable code
|
|
17
|
-
else if (typeof input === "function")
|
|
18
|
-
return ts.factory.createIdentifier("undefined");
|
|
19
|
-
else
|
|
20
|
-
throw new TypeError("Error on LiteralFactory.generate(): unknown type.");
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const writeObject = (obj: object): ts.ObjectLiteralExpression =>
|
|
24
|
-
ts.factory.createObjectLiteralExpression(
|
|
25
|
-
Object.entries(obj)
|
|
26
|
-
.filter((tuple) => tuple[1] !== undefined)
|
|
27
|
-
.map(([key, value]) =>
|
|
28
|
-
ts.factory.createPropertyAssignment(
|
|
29
|
-
IdentifierFactory.identifier(key),
|
|
30
|
-
write(value),
|
|
31
|
-
),
|
|
32
|
-
),
|
|
33
|
-
true,
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
const writeArray = (array: any[]): ts.ArrayLiteralExpression =>
|
|
37
|
-
ts.factory.createArrayLiteralExpression(array.map(write), true);
|
|
38
|
-
|
|
39
|
-
const writeBoolean = (value: boolean): ts.Expression =>
|
|
40
|
-
value ? ts.factory.createTrue() : ts.factory.createFalse();
|
|
41
|
-
|
|
42
|
-
const writeNumber = (value: number): ts.Expression =>
|
|
43
|
-
ExpressionFactory.number(value);
|
|
44
|
-
|
|
45
|
-
const writeBigint = (value: bigint): ts.Expression =>
|
|
46
|
-
ExpressionFactory.bigint(value);
|
|
47
|
-
|
|
48
|
-
const writeStrinng = (value: string): ts.StringLiteral =>
|
|
49
|
-
ts.factory.createStringLiteral(value);
|
|
50
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { ExpressionFactory } from "./ExpressionFactory";
|
|
4
|
+
import { IdentifierFactory } from "./IdentifierFactory";
|
|
5
|
+
|
|
6
|
+
export namespace LiteralFactory {
|
|
7
|
+
export const write = (input: any): ts.Expression => {
|
|
8
|
+
if (input === null) return ts.factory.createNull();
|
|
9
|
+
else if (ts.isIdentifier(input)) return input;
|
|
10
|
+
else if (input instanceof Array) return writeArray(input);
|
|
11
|
+
else if (typeof input === "object") return writeObject(input);
|
|
12
|
+
else if (typeof input === "boolean") return writeBoolean(input);
|
|
13
|
+
else if (typeof input === "bigint") return writeBigint(input);
|
|
14
|
+
else if (typeof input === "number") return writeNumber(input);
|
|
15
|
+
else if (typeof input === "string") return writeStrinng(input);
|
|
16
|
+
// unreachable code
|
|
17
|
+
else if (typeof input === "function")
|
|
18
|
+
return ts.factory.createIdentifier("undefined");
|
|
19
|
+
else
|
|
20
|
+
throw new TypeError("Error on LiteralFactory.generate(): unknown type.");
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const writeObject = (obj: object): ts.ObjectLiteralExpression =>
|
|
24
|
+
ts.factory.createObjectLiteralExpression(
|
|
25
|
+
Object.entries(obj)
|
|
26
|
+
.filter((tuple) => tuple[1] !== undefined)
|
|
27
|
+
.map(([key, value]) =>
|
|
28
|
+
ts.factory.createPropertyAssignment(
|
|
29
|
+
IdentifierFactory.identifier(key),
|
|
30
|
+
write(value),
|
|
31
|
+
),
|
|
32
|
+
),
|
|
33
|
+
true,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const writeArray = (array: any[]): ts.ArrayLiteralExpression =>
|
|
37
|
+
ts.factory.createArrayLiteralExpression(array.map(write), true);
|
|
38
|
+
|
|
39
|
+
const writeBoolean = (value: boolean): ts.Expression =>
|
|
40
|
+
value ? ts.factory.createTrue() : ts.factory.createFalse();
|
|
41
|
+
|
|
42
|
+
const writeNumber = (value: number): ts.Expression =>
|
|
43
|
+
ExpressionFactory.number(value);
|
|
44
|
+
|
|
45
|
+
const writeBigint = (value: bigint): ts.Expression =>
|
|
46
|
+
ExpressionFactory.bigint(value);
|
|
47
|
+
|
|
48
|
+
const writeStrinng = (value: string): ts.StringLiteral =>
|
|
49
|
+
ts.factory.createStringLiteral(value);
|
|
50
|
+
}
|