typia 7.0.0-dev.20241009-2 → 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/RandomProgrammer.js +12 -9
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/TypiaProgrammer.js +4 -1
- package/lib/programmers/TypiaProgrammer.js.map +1 -1
- package/lib/programmers/internal/prune_object_properties.js +3 -2
- package/lib/programmers/internal/prune_object_properties.js.map +1 -1
- package/lib/programmers/json/JsonAssertParseProgrammer.js +2 -2
- package/lib/programmers/json/JsonAssertParseProgrammer.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/programmers/protobuf/ProtobufDecodeProgrammer.js +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.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/RandomProgrammer.ts +24 -16
- 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 -63
- package/src/programmers/json/JsonAssertParseProgrammer.ts +14 -11
- 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/programmers/protobuf/ProtobufDecodeProgrammer.ts +1 -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,168 +1,168 @@
|
|
|
1
|
-
import { OpenApi } from "@samchon/openapi";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
5
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
6
|
-
import { LiteralFactory } from "../../factories/LiteralFactory";
|
|
7
|
-
|
|
8
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
9
|
-
import { MetadataArray } from "../../schemas/metadata/MetadataArray";
|
|
10
|
-
import { MetadataArrayType } from "../../schemas/metadata/MetadataArrayType";
|
|
11
|
-
import { MetadataObject } from "../../schemas/metadata/MetadataObject";
|
|
12
|
-
import { MetadataProperty } from "../../schemas/metadata/MetadataProperty";
|
|
13
|
-
import { MetadataTuple } from "../../schemas/metadata/MetadataTuple";
|
|
14
|
-
import { MetadataTupleType } from "../../schemas/metadata/MetadataTupleType";
|
|
15
|
-
|
|
16
|
-
import { Escaper } from "../../utils/Escaper";
|
|
17
|
-
|
|
18
|
-
export namespace RandomJoiner {
|
|
19
|
-
export type Decoder = (metadata: Metadata) => ts.Expression;
|
|
20
|
-
|
|
21
|
-
export const array = (props: {
|
|
22
|
-
decode: Decoder;
|
|
23
|
-
recursive: boolean;
|
|
24
|
-
expression: ts.Expression;
|
|
25
|
-
array: MetadataArrayType;
|
|
26
|
-
schema: Omit<OpenApi.IJsonSchema.IArray, "items"> | undefined;
|
|
27
|
-
}): ts.Expression => {
|
|
28
|
-
const call: ts.Expression = ts.factory.createCallExpression(
|
|
29
|
-
props.expression,
|
|
30
|
-
undefined,
|
|
31
|
-
[
|
|
32
|
-
ts.factory.createObjectLiteralExpression(
|
|
33
|
-
[
|
|
34
|
-
...(props.schema
|
|
35
|
-
? Object.entries(props.schema)
|
|
36
|
-
.filter(([key]) => key !== "items")
|
|
37
|
-
.map(([key, value]) =>
|
|
38
|
-
ts.factory.createPropertyAssignment(
|
|
39
|
-
key,
|
|
40
|
-
LiteralFactory.write(value),
|
|
41
|
-
),
|
|
42
|
-
)
|
|
43
|
-
: []),
|
|
44
|
-
...(props.schema
|
|
45
|
-
? []
|
|
46
|
-
: [
|
|
47
|
-
ts.factory.createSpreadAssignment(
|
|
48
|
-
ts.factory.createIdentifier("_schema"),
|
|
49
|
-
),
|
|
50
|
-
]),
|
|
51
|
-
ts.factory.createPropertyAssignment(
|
|
52
|
-
"element",
|
|
53
|
-
ts.factory.createArrowFunction(
|
|
54
|
-
undefined,
|
|
55
|
-
undefined,
|
|
56
|
-
[],
|
|
57
|
-
undefined,
|
|
58
|
-
undefined,
|
|
59
|
-
props.decode(props.array.value),
|
|
60
|
-
),
|
|
61
|
-
),
|
|
62
|
-
],
|
|
63
|
-
true,
|
|
64
|
-
),
|
|
65
|
-
],
|
|
66
|
-
);
|
|
67
|
-
if (props.recursive === false) return call;
|
|
68
|
-
return ts.factory.createConditionalExpression(
|
|
69
|
-
ts.factory.createGreaterThanEquals(
|
|
70
|
-
ExpressionFactory.number(5),
|
|
71
|
-
ts.factory.createIdentifier("_depth"),
|
|
72
|
-
),
|
|
73
|
-
undefined,
|
|
74
|
-
call,
|
|
75
|
-
undefined,
|
|
76
|
-
ts.factory.createArrayLiteralExpression([]),
|
|
77
|
-
);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export const tuple = (props: {
|
|
81
|
-
decode: Decoder;
|
|
82
|
-
elements: Metadata[];
|
|
83
|
-
}): ts.ArrayLiteralExpression =>
|
|
84
|
-
ts.factory.createArrayLiteralExpression(
|
|
85
|
-
props.elements.map((elem) => props.decode(elem.rest ?? elem)),
|
|
86
|
-
true,
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
export const object = (props: {
|
|
90
|
-
decode: Decoder;
|
|
91
|
-
object: MetadataObject;
|
|
92
|
-
}): ts.ConciseBody => {
|
|
93
|
-
if (props.object.properties.length === 0) return LiteralFactory.write({});
|
|
94
|
-
|
|
95
|
-
// LIST UP PROPERTIES
|
|
96
|
-
const regular = props.object.properties.filter((p) =>
|
|
97
|
-
p.key.isSoleLiteral(),
|
|
98
|
-
);
|
|
99
|
-
const dynamic = props.object.properties.filter(
|
|
100
|
-
(p) => !p.key.isSoleLiteral(),
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
return ts.factory.createObjectLiteralExpression(
|
|
104
|
-
[
|
|
105
|
-
...regular.map((p) => {
|
|
106
|
-
const str: string = p.key.getSoleLiteral()!;
|
|
107
|
-
return ts.factory.createPropertyAssignment(
|
|
108
|
-
Escaper.variable(str) ? str : ts.factory.createStringLiteral(str),
|
|
109
|
-
props.decode(p.value),
|
|
110
|
-
);
|
|
111
|
-
}),
|
|
112
|
-
...dynamic.map((property) =>
|
|
113
|
-
ts.factory.createSpreadAssignment(
|
|
114
|
-
dynamicProperty({
|
|
115
|
-
decode: props.decode,
|
|
116
|
-
property: property,
|
|
117
|
-
}),
|
|
118
|
-
),
|
|
119
|
-
),
|
|
120
|
-
],
|
|
121
|
-
true,
|
|
122
|
-
);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const dynamicProperty = (props: {
|
|
126
|
-
decode: Decoder;
|
|
127
|
-
property: MetadataProperty;
|
|
128
|
-
}) => {
|
|
129
|
-
const tuple: MetadataTuple = MetadataTuple.create({
|
|
130
|
-
type: MetadataTupleType.create({
|
|
131
|
-
name: `[${props.property.key.getName()}, ${props.property.value.getName()}]`,
|
|
132
|
-
elements: [props.property.key, props.property.value],
|
|
133
|
-
index: null,
|
|
134
|
-
recursive: false,
|
|
135
|
-
nullables: [false],
|
|
136
|
-
}),
|
|
137
|
-
tags: [],
|
|
138
|
-
});
|
|
139
|
-
const array: MetadataArray = MetadataArray.create({
|
|
140
|
-
type: MetadataArrayType.create({
|
|
141
|
-
name: `Array<[${props.property.key.getName()}, ${props.property.value.getName()}]>`,
|
|
142
|
-
value: Metadata.create({
|
|
143
|
-
...Metadata.initialize(),
|
|
144
|
-
tuples: [tuple],
|
|
145
|
-
}),
|
|
146
|
-
nullables: [false],
|
|
147
|
-
recursive: false,
|
|
148
|
-
index: null,
|
|
149
|
-
}),
|
|
150
|
-
tags: [[]],
|
|
151
|
-
});
|
|
152
|
-
return ts.factory.createCallExpression(
|
|
153
|
-
IdentifierFactory.access(
|
|
154
|
-
ts.factory.createIdentifier("Object"),
|
|
155
|
-
"fromEntries",
|
|
156
|
-
),
|
|
157
|
-
undefined,
|
|
158
|
-
[
|
|
159
|
-
props.decode(
|
|
160
|
-
Metadata.create({
|
|
161
|
-
...Metadata.initialize(),
|
|
162
|
-
arrays: [array],
|
|
163
|
-
}),
|
|
164
|
-
),
|
|
165
|
-
],
|
|
166
|
-
);
|
|
167
|
-
};
|
|
168
|
-
}
|
|
1
|
+
import { OpenApi } from "@samchon/openapi";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
5
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
6
|
+
import { LiteralFactory } from "../../factories/LiteralFactory";
|
|
7
|
+
|
|
8
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
9
|
+
import { MetadataArray } from "../../schemas/metadata/MetadataArray";
|
|
10
|
+
import { MetadataArrayType } from "../../schemas/metadata/MetadataArrayType";
|
|
11
|
+
import { MetadataObject } from "../../schemas/metadata/MetadataObject";
|
|
12
|
+
import { MetadataProperty } from "../../schemas/metadata/MetadataProperty";
|
|
13
|
+
import { MetadataTuple } from "../../schemas/metadata/MetadataTuple";
|
|
14
|
+
import { MetadataTupleType } from "../../schemas/metadata/MetadataTupleType";
|
|
15
|
+
|
|
16
|
+
import { Escaper } from "../../utils/Escaper";
|
|
17
|
+
|
|
18
|
+
export namespace RandomJoiner {
|
|
19
|
+
export type Decoder = (metadata: Metadata) => ts.Expression;
|
|
20
|
+
|
|
21
|
+
export const array = (props: {
|
|
22
|
+
decode: Decoder;
|
|
23
|
+
recursive: boolean;
|
|
24
|
+
expression: ts.Expression;
|
|
25
|
+
array: MetadataArrayType;
|
|
26
|
+
schema: Omit<OpenApi.IJsonSchema.IArray, "items"> | undefined;
|
|
27
|
+
}): ts.Expression => {
|
|
28
|
+
const call: ts.Expression = ts.factory.createCallExpression(
|
|
29
|
+
props.expression,
|
|
30
|
+
undefined,
|
|
31
|
+
[
|
|
32
|
+
ts.factory.createObjectLiteralExpression(
|
|
33
|
+
[
|
|
34
|
+
...(props.schema
|
|
35
|
+
? Object.entries(props.schema)
|
|
36
|
+
.filter(([key]) => key !== "items")
|
|
37
|
+
.map(([key, value]) =>
|
|
38
|
+
ts.factory.createPropertyAssignment(
|
|
39
|
+
key,
|
|
40
|
+
LiteralFactory.write(value),
|
|
41
|
+
),
|
|
42
|
+
)
|
|
43
|
+
: []),
|
|
44
|
+
...(props.schema
|
|
45
|
+
? []
|
|
46
|
+
: [
|
|
47
|
+
ts.factory.createSpreadAssignment(
|
|
48
|
+
ts.factory.createIdentifier("_schema"),
|
|
49
|
+
),
|
|
50
|
+
]),
|
|
51
|
+
ts.factory.createPropertyAssignment(
|
|
52
|
+
"element",
|
|
53
|
+
ts.factory.createArrowFunction(
|
|
54
|
+
undefined,
|
|
55
|
+
undefined,
|
|
56
|
+
[],
|
|
57
|
+
undefined,
|
|
58
|
+
undefined,
|
|
59
|
+
props.decode(props.array.value),
|
|
60
|
+
),
|
|
61
|
+
),
|
|
62
|
+
],
|
|
63
|
+
true,
|
|
64
|
+
),
|
|
65
|
+
],
|
|
66
|
+
);
|
|
67
|
+
if (props.recursive === false) return call;
|
|
68
|
+
return ts.factory.createConditionalExpression(
|
|
69
|
+
ts.factory.createGreaterThanEquals(
|
|
70
|
+
ExpressionFactory.number(5),
|
|
71
|
+
ts.factory.createIdentifier("_depth"),
|
|
72
|
+
),
|
|
73
|
+
undefined,
|
|
74
|
+
call,
|
|
75
|
+
undefined,
|
|
76
|
+
ts.factory.createArrayLiteralExpression([]),
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const tuple = (props: {
|
|
81
|
+
decode: Decoder;
|
|
82
|
+
elements: Metadata[];
|
|
83
|
+
}): ts.ArrayLiteralExpression =>
|
|
84
|
+
ts.factory.createArrayLiteralExpression(
|
|
85
|
+
props.elements.map((elem) => props.decode(elem.rest ?? elem)),
|
|
86
|
+
true,
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
export const object = (props: {
|
|
90
|
+
decode: Decoder;
|
|
91
|
+
object: MetadataObject;
|
|
92
|
+
}): ts.ConciseBody => {
|
|
93
|
+
if (props.object.properties.length === 0) return LiteralFactory.write({});
|
|
94
|
+
|
|
95
|
+
// LIST UP PROPERTIES
|
|
96
|
+
const regular = props.object.properties.filter((p) =>
|
|
97
|
+
p.key.isSoleLiteral(),
|
|
98
|
+
);
|
|
99
|
+
const dynamic = props.object.properties.filter(
|
|
100
|
+
(p) => !p.key.isSoleLiteral(),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
return ts.factory.createObjectLiteralExpression(
|
|
104
|
+
[
|
|
105
|
+
...regular.map((p) => {
|
|
106
|
+
const str: string = p.key.getSoleLiteral()!;
|
|
107
|
+
return ts.factory.createPropertyAssignment(
|
|
108
|
+
Escaper.variable(str) ? str : ts.factory.createStringLiteral(str),
|
|
109
|
+
props.decode(p.value),
|
|
110
|
+
);
|
|
111
|
+
}),
|
|
112
|
+
...dynamic.map((property) =>
|
|
113
|
+
ts.factory.createSpreadAssignment(
|
|
114
|
+
dynamicProperty({
|
|
115
|
+
decode: props.decode,
|
|
116
|
+
property: property,
|
|
117
|
+
}),
|
|
118
|
+
),
|
|
119
|
+
),
|
|
120
|
+
],
|
|
121
|
+
true,
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const dynamicProperty = (props: {
|
|
126
|
+
decode: Decoder;
|
|
127
|
+
property: MetadataProperty;
|
|
128
|
+
}) => {
|
|
129
|
+
const tuple: MetadataTuple = MetadataTuple.create({
|
|
130
|
+
type: MetadataTupleType.create({
|
|
131
|
+
name: `[${props.property.key.getName()}, ${props.property.value.getName()}]`,
|
|
132
|
+
elements: [props.property.key, props.property.value],
|
|
133
|
+
index: null,
|
|
134
|
+
recursive: false,
|
|
135
|
+
nullables: [false],
|
|
136
|
+
}),
|
|
137
|
+
tags: [],
|
|
138
|
+
});
|
|
139
|
+
const array: MetadataArray = MetadataArray.create({
|
|
140
|
+
type: MetadataArrayType.create({
|
|
141
|
+
name: `Array<[${props.property.key.getName()}, ${props.property.value.getName()}]>`,
|
|
142
|
+
value: Metadata.create({
|
|
143
|
+
...Metadata.initialize(),
|
|
144
|
+
tuples: [tuple],
|
|
145
|
+
}),
|
|
146
|
+
nullables: [false],
|
|
147
|
+
recursive: false,
|
|
148
|
+
index: null,
|
|
149
|
+
}),
|
|
150
|
+
tags: [[]],
|
|
151
|
+
});
|
|
152
|
+
return ts.factory.createCallExpression(
|
|
153
|
+
IdentifierFactory.access(
|
|
154
|
+
ts.factory.createIdentifier("Object"),
|
|
155
|
+
"fromEntries",
|
|
156
|
+
),
|
|
157
|
+
undefined,
|
|
158
|
+
[
|
|
159
|
+
props.decode(
|
|
160
|
+
Metadata.create({
|
|
161
|
+
...Metadata.initialize(),
|
|
162
|
+
arrays: [array],
|
|
163
|
+
}),
|
|
164
|
+
),
|
|
165
|
+
],
|
|
166
|
+
);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
import { TemplateFactory } from "../../factories/TemplateFactory";
|
|
5
|
-
|
|
6
|
-
import { ITypiaContext } from "../../transformers/ITypiaContext";
|
|
7
|
-
|
|
8
|
-
import { stringify_dynamic_properties } from "../internal/stringify_dynamic_properties";
|
|
9
|
-
import { stringify_regular_properties } from "../internal/stringify_regular_properties";
|
|
10
|
-
import { IExpressionEntry } from "./IExpressionEntry";
|
|
11
|
-
|
|
12
|
-
export namespace StringifyJoiner {
|
|
13
|
-
export const object = (props: {
|
|
14
|
-
context: ITypiaContext;
|
|
15
|
-
entries: IExpressionEntry<ts.Expression>[];
|
|
16
|
-
}): ts.Expression => {
|
|
17
|
-
// CHECK AND SORT ENTRIES
|
|
18
|
-
if (props.entries.length === 0) return ts.factory.createStringLiteral("{}");
|
|
19
|
-
|
|
20
|
-
// PROPERTIES
|
|
21
|
-
const regular: IExpressionEntry<ts.Expression>[] = props.entries.filter(
|
|
22
|
-
(entry) => entry.key.isSoleLiteral(),
|
|
23
|
-
);
|
|
24
|
-
const dynamic: IExpressionEntry<ts.Expression>[] = props.entries.filter(
|
|
25
|
-
(entry) => !entry.key.isSoleLiteral(),
|
|
26
|
-
);
|
|
27
|
-
const expressions: ts.Expression[] = [
|
|
28
|
-
...stringify_regular_properties({
|
|
29
|
-
regular,
|
|
30
|
-
dynamic,
|
|
31
|
-
}),
|
|
32
|
-
...(dynamic.length
|
|
33
|
-
? [
|
|
34
|
-
stringify_dynamic_properties(
|
|
35
|
-
dynamic,
|
|
36
|
-
regular.map((r) => r.key.getSoleLiteral()!),
|
|
37
|
-
),
|
|
38
|
-
]
|
|
39
|
-
: []),
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
// POP LAST COMMA, IF REQUIRED
|
|
43
|
-
const filtered: ts.Expression[] =
|
|
44
|
-
(regular.length &&
|
|
45
|
-
regular[regular.length - 1]!.meta.isRequired() &&
|
|
46
|
-
dynamic.length === 0) ||
|
|
47
|
-
(regular.length === 0 && dynamic.length)
|
|
48
|
-
? expressions
|
|
49
|
-
: [
|
|
50
|
-
ts.factory.createCallExpression(
|
|
51
|
-
props.context.importer.internal("jsonStringifyTail"),
|
|
52
|
-
undefined,
|
|
53
|
-
[TemplateFactory.generate(expressions)],
|
|
54
|
-
),
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
// RETURNS WITH OBJECT BRACKET
|
|
58
|
-
return TemplateFactory.generate([
|
|
59
|
-
ts.factory.createStringLiteral(`{`),
|
|
60
|
-
...filtered,
|
|
61
|
-
ts.factory.createStringLiteral(`}`),
|
|
62
|
-
]);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const array = (props: {
|
|
66
|
-
input: ts.Expression;
|
|
67
|
-
arrow: ts.ArrowFunction;
|
|
68
|
-
}): ts.Expression =>
|
|
69
|
-
TemplateFactory.generate([
|
|
70
|
-
ts.factory.createStringLiteral(`[`),
|
|
71
|
-
ts.factory.createCallExpression(
|
|
72
|
-
ts.factory.createPropertyAccessExpression(
|
|
73
|
-
ts.factory.createCallExpression(
|
|
74
|
-
IdentifierFactory.access(props.input, "map"),
|
|
75
|
-
undefined,
|
|
76
|
-
[props.arrow],
|
|
77
|
-
),
|
|
78
|
-
ts.factory.createIdentifier("join"),
|
|
79
|
-
),
|
|
80
|
-
undefined,
|
|
81
|
-
[ts.factory.createStringLiteral(`,`)],
|
|
82
|
-
),
|
|
83
|
-
ts.factory.createStringLiteral(`]`),
|
|
84
|
-
]);
|
|
85
|
-
|
|
86
|
-
export const tuple = (props: {
|
|
87
|
-
elements: ts.Expression[];
|
|
88
|
-
rest: ts.Expression | null;
|
|
89
|
-
}): ts.Expression => {
|
|
90
|
-
if (props.elements.length === 0)
|
|
91
|
-
return ts.factory.createStringLiteral("[]");
|
|
92
|
-
if (
|
|
93
|
-
props.rest === null &&
|
|
94
|
-
props.elements.every((child) => ts.isStringLiteral(child))
|
|
95
|
-
)
|
|
96
|
-
return ts.factory.createStringLiteral(
|
|
97
|
-
"[" +
|
|
98
|
-
props.elements
|
|
99
|
-
.map((child) => (child as ts.StringLiteral).text)
|
|
100
|
-
.join(",") +
|
|
101
|
-
"]",
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
const expressions: ts.Expression[] = [ts.factory.createStringLiteral(`[`)];
|
|
105
|
-
props.elements.forEach((child, i) => {
|
|
106
|
-
expressions.push(child);
|
|
107
|
-
if (i !== props.elements.length - 1)
|
|
108
|
-
expressions.push(ts.factory.createStringLiteral(`,`));
|
|
109
|
-
});
|
|
110
|
-
if (props.rest !== null) expressions.push(props.rest);
|
|
111
|
-
|
|
112
|
-
expressions.push(ts.factory.createStringLiteral(`]`));
|
|
113
|
-
return TemplateFactory.generate(expressions);
|
|
114
|
-
};
|
|
115
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { TemplateFactory } from "../../factories/TemplateFactory";
|
|
5
|
+
|
|
6
|
+
import { ITypiaContext } from "../../transformers/ITypiaContext";
|
|
7
|
+
|
|
8
|
+
import { stringify_dynamic_properties } from "../internal/stringify_dynamic_properties";
|
|
9
|
+
import { stringify_regular_properties } from "../internal/stringify_regular_properties";
|
|
10
|
+
import { IExpressionEntry } from "./IExpressionEntry";
|
|
11
|
+
|
|
12
|
+
export namespace StringifyJoiner {
|
|
13
|
+
export const object = (props: {
|
|
14
|
+
context: ITypiaContext;
|
|
15
|
+
entries: IExpressionEntry<ts.Expression>[];
|
|
16
|
+
}): ts.Expression => {
|
|
17
|
+
// CHECK AND SORT ENTRIES
|
|
18
|
+
if (props.entries.length === 0) return ts.factory.createStringLiteral("{}");
|
|
19
|
+
|
|
20
|
+
// PROPERTIES
|
|
21
|
+
const regular: IExpressionEntry<ts.Expression>[] = props.entries.filter(
|
|
22
|
+
(entry) => entry.key.isSoleLiteral(),
|
|
23
|
+
);
|
|
24
|
+
const dynamic: IExpressionEntry<ts.Expression>[] = props.entries.filter(
|
|
25
|
+
(entry) => !entry.key.isSoleLiteral(),
|
|
26
|
+
);
|
|
27
|
+
const expressions: ts.Expression[] = [
|
|
28
|
+
...stringify_regular_properties({
|
|
29
|
+
regular,
|
|
30
|
+
dynamic,
|
|
31
|
+
}),
|
|
32
|
+
...(dynamic.length
|
|
33
|
+
? [
|
|
34
|
+
stringify_dynamic_properties(
|
|
35
|
+
dynamic,
|
|
36
|
+
regular.map((r) => r.key.getSoleLiteral()!),
|
|
37
|
+
),
|
|
38
|
+
]
|
|
39
|
+
: []),
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
// POP LAST COMMA, IF REQUIRED
|
|
43
|
+
const filtered: ts.Expression[] =
|
|
44
|
+
(regular.length &&
|
|
45
|
+
regular[regular.length - 1]!.meta.isRequired() &&
|
|
46
|
+
dynamic.length === 0) ||
|
|
47
|
+
(regular.length === 0 && dynamic.length)
|
|
48
|
+
? expressions
|
|
49
|
+
: [
|
|
50
|
+
ts.factory.createCallExpression(
|
|
51
|
+
props.context.importer.internal("jsonStringifyTail"),
|
|
52
|
+
undefined,
|
|
53
|
+
[TemplateFactory.generate(expressions)],
|
|
54
|
+
),
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
// RETURNS WITH OBJECT BRACKET
|
|
58
|
+
return TemplateFactory.generate([
|
|
59
|
+
ts.factory.createStringLiteral(`{`),
|
|
60
|
+
...filtered,
|
|
61
|
+
ts.factory.createStringLiteral(`}`),
|
|
62
|
+
]);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const array = (props: {
|
|
66
|
+
input: ts.Expression;
|
|
67
|
+
arrow: ts.ArrowFunction;
|
|
68
|
+
}): ts.Expression =>
|
|
69
|
+
TemplateFactory.generate([
|
|
70
|
+
ts.factory.createStringLiteral(`[`),
|
|
71
|
+
ts.factory.createCallExpression(
|
|
72
|
+
ts.factory.createPropertyAccessExpression(
|
|
73
|
+
ts.factory.createCallExpression(
|
|
74
|
+
IdentifierFactory.access(props.input, "map"),
|
|
75
|
+
undefined,
|
|
76
|
+
[props.arrow],
|
|
77
|
+
),
|
|
78
|
+
ts.factory.createIdentifier("join"),
|
|
79
|
+
),
|
|
80
|
+
undefined,
|
|
81
|
+
[ts.factory.createStringLiteral(`,`)],
|
|
82
|
+
),
|
|
83
|
+
ts.factory.createStringLiteral(`]`),
|
|
84
|
+
]);
|
|
85
|
+
|
|
86
|
+
export const tuple = (props: {
|
|
87
|
+
elements: ts.Expression[];
|
|
88
|
+
rest: ts.Expression | null;
|
|
89
|
+
}): ts.Expression => {
|
|
90
|
+
if (props.elements.length === 0)
|
|
91
|
+
return ts.factory.createStringLiteral("[]");
|
|
92
|
+
if (
|
|
93
|
+
props.rest === null &&
|
|
94
|
+
props.elements.every((child) => ts.isStringLiteral(child))
|
|
95
|
+
)
|
|
96
|
+
return ts.factory.createStringLiteral(
|
|
97
|
+
"[" +
|
|
98
|
+
props.elements
|
|
99
|
+
.map((child) => (child as ts.StringLiteral).text)
|
|
100
|
+
.join(",") +
|
|
101
|
+
"]",
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const expressions: ts.Expression[] = [ts.factory.createStringLiteral(`[`)];
|
|
105
|
+
props.elements.forEach((child, i) => {
|
|
106
|
+
expressions.push(child);
|
|
107
|
+
if (i !== props.elements.length - 1)
|
|
108
|
+
expressions.push(ts.factory.createStringLiteral(`,`));
|
|
109
|
+
});
|
|
110
|
+
if (props.rest !== null) expressions.push(props.rest);
|
|
111
|
+
|
|
112
|
+
expressions.push(ts.factory.createStringLiteral(`]`));
|
|
113
|
+
return TemplateFactory.generate(expressions);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { FunctionProgrammer } from "./FunctionProgrammer";
|
|
4
|
-
|
|
5
|
-
export const disable_function_programmer_declare = (
|
|
6
|
-
functor: FunctionProgrammer,
|
|
7
|
-
): FunctionProgrammer => disable(functor) as FunctionProgrammer;
|
|
8
|
-
|
|
9
|
-
const disable = (
|
|
10
|
-
functor: FunctionProgrammer,
|
|
11
|
-
): MethodOnly<FunctionProgrammer> => ({
|
|
12
|
-
method: functor.method,
|
|
13
|
-
useLocal: (name: string): string => functor.useLocal(name),
|
|
14
|
-
hasLocal: (name: string): boolean => functor.hasLocal(name),
|
|
15
|
-
declare: (): ts.Statement[] => [],
|
|
16
|
-
declareUnions: (): ts.Statement[] => [],
|
|
17
|
-
increment: (): number => functor.increment(),
|
|
18
|
-
emplaceUnion: (
|
|
19
|
-
prefix: string,
|
|
20
|
-
name: string,
|
|
21
|
-
factory: () => ts.ArrowFunction,
|
|
22
|
-
): string => functor.emplaceUnion(prefix, name, factory),
|
|
23
|
-
emplaceVariable: (key, value) => functor.emplaceVariable(key, value),
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
type MethodOnly<T> = {
|
|
27
|
-
[P in keyof T]: T[P] extends Function
|
|
28
|
-
? T[P]
|
|
29
|
-
: P extends "method"
|
|
30
|
-
? T[P]
|
|
31
|
-
: never;
|
|
32
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { FunctionProgrammer } from "./FunctionProgrammer";
|
|
4
|
+
|
|
5
|
+
export const disable_function_programmer_declare = (
|
|
6
|
+
functor: FunctionProgrammer,
|
|
7
|
+
): FunctionProgrammer => disable(functor) as FunctionProgrammer;
|
|
8
|
+
|
|
9
|
+
const disable = (
|
|
10
|
+
functor: FunctionProgrammer,
|
|
11
|
+
): MethodOnly<FunctionProgrammer> => ({
|
|
12
|
+
method: functor.method,
|
|
13
|
+
useLocal: (name: string): string => functor.useLocal(name),
|
|
14
|
+
hasLocal: (name: string): boolean => functor.hasLocal(name),
|
|
15
|
+
declare: (): ts.Statement[] => [],
|
|
16
|
+
declareUnions: (): ts.Statement[] => [],
|
|
17
|
+
increment: (): number => functor.increment(),
|
|
18
|
+
emplaceUnion: (
|
|
19
|
+
prefix: string,
|
|
20
|
+
name: string,
|
|
21
|
+
factory: () => ts.ArrowFunction,
|
|
22
|
+
): string => functor.emplaceUnion(prefix, name, factory),
|
|
23
|
+
emplaceVariable: (key, value) => functor.emplaceVariable(key, value),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
type MethodOnly<T> = {
|
|
27
|
+
[P in keyof T]: T[P] extends Function
|
|
28
|
+
? T[P]
|
|
29
|
+
: P extends "method"
|
|
30
|
+
? T[P]
|
|
31
|
+
: never;
|
|
32
|
+
};
|