typia 7.0.0-dev.20240919 → 7.0.0-dev.20240921
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/programmers/RandomProgrammer.js +557 -493
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/helpers/RandomJoiner.d.ts +17 -3
- package/lib/programmers/helpers/RandomJoiner.js +53 -63
- package/lib/programmers/helpers/RandomJoiner.js.map +1 -1
- package/lib/programmers/helpers/RandomRanger.d.ts +11 -2
- package/lib/programmers/helpers/RandomRanger.js +134 -113
- package/lib/programmers/helpers/RandomRanger.js.map +1 -1
- package/lib/programmers/helpers/StringifyJoinder.d.ts +2 -1
- package/lib/programmers/helpers/StringifyJoinder.js +27 -31
- package/lib/programmers/helpers/StringifyJoinder.js.map +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js +33 -27
- package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
- package/package.json +1 -1
- package/src/programmers/RandomProgrammer.ts +758 -595
- package/src/programmers/helpers/RandomJoiner.ts +121 -110
- package/src/programmers/helpers/RandomRanger.ts +218 -171
- package/src/programmers/helpers/StringifyJoinder.ts +45 -43
- package/src/programmers/json/JsonStringifyProgrammer.ts +67 -58
|
@@ -9,52 +9,54 @@ import { FunctionImporter } from "./FunctionImporter";
|
|
|
9
9
|
import { IExpressionEntry } from "./IExpressionEntry";
|
|
10
10
|
|
|
11
11
|
export namespace StringifyJoiner {
|
|
12
|
-
export const object =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
export const object = (props: {
|
|
13
|
+
importer: FunctionImporter;
|
|
14
|
+
entries: IExpressionEntry<ts.Expression>[];
|
|
15
|
+
}): ts.Expression => {
|
|
16
|
+
// CHECK AND SORT ENTRIES
|
|
17
|
+
if (props.entries.length === 0) return ts.factory.createStringLiteral("{}");
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
19
|
+
// PROPERTIES
|
|
20
|
+
const regular: IExpressionEntry<ts.Expression>[] = props.entries.filter(
|
|
21
|
+
(entry) => entry.key.isSoleLiteral(),
|
|
22
|
+
);
|
|
23
|
+
const dynamic: IExpressionEntry<ts.Expression>[] = props.entries.filter(
|
|
24
|
+
(entry) => !entry.key.isSoleLiteral(),
|
|
25
|
+
);
|
|
26
|
+
const expressions: ts.Expression[] = [
|
|
27
|
+
...stringify_regular_properties(regular, dynamic),
|
|
28
|
+
...(dynamic.length
|
|
29
|
+
? [
|
|
30
|
+
stringify_dynamic_properties(
|
|
31
|
+
dynamic,
|
|
32
|
+
regular.map((r) => r.key.getSoleLiteral()!),
|
|
33
|
+
),
|
|
34
|
+
]
|
|
35
|
+
: []),
|
|
36
|
+
];
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
// POP LAST COMMA, IF REQUIRED
|
|
39
|
+
const filtered: ts.Expression[] =
|
|
40
|
+
(regular.length &&
|
|
41
|
+
regular[regular.length - 1]!.meta.isRequired() &&
|
|
42
|
+
dynamic.length === 0) ||
|
|
43
|
+
(regular.length === 0 && dynamic.length)
|
|
44
|
+
? expressions
|
|
45
|
+
: [
|
|
46
|
+
ts.factory.createCallExpression(
|
|
47
|
+
props.importer.use("tail"),
|
|
48
|
+
undefined,
|
|
49
|
+
[TemplateFactory.generate(expressions)],
|
|
50
|
+
),
|
|
51
|
+
];
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
// RETURNS WITH OBJECT BRACKET
|
|
54
|
+
return TemplateFactory.generate([
|
|
55
|
+
ts.factory.createStringLiteral(`{`),
|
|
56
|
+
...filtered,
|
|
57
|
+
ts.factory.createStringLiteral(`}`),
|
|
58
|
+
]);
|
|
59
|
+
};
|
|
58
60
|
|
|
59
61
|
export const array = (props: {
|
|
60
62
|
input: ts.Expression;
|
|
@@ -174,17 +174,16 @@ export namespace JsonStringifyProgrammer {
|
|
|
174
174
|
metadata,
|
|
175
175
|
explore,
|
|
176
176
|
)(
|
|
177
|
-
wrap_functional(
|
|
177
|
+
wrap_functional({
|
|
178
178
|
input,
|
|
179
179
|
metadata,
|
|
180
180
|
explore,
|
|
181
|
-
|
|
182
|
-
ts.factory.createCallExpression(
|
|
181
|
+
expression: ts.factory.createCallExpression(
|
|
183
182
|
ts.factory.createIdentifier("JSON.stringify"),
|
|
184
183
|
undefined,
|
|
185
184
|
[input],
|
|
186
185
|
),
|
|
187
|
-
),
|
|
186
|
+
}),
|
|
188
187
|
);
|
|
189
188
|
|
|
190
189
|
// ONLY NULL OR UNDEFINED
|
|
@@ -470,7 +469,12 @@ export namespace JsonStringifyProgrammer {
|
|
|
470
469
|
[],
|
|
471
470
|
undefined,
|
|
472
471
|
undefined,
|
|
473
|
-
iterate(
|
|
472
|
+
iterate({
|
|
473
|
+
importer,
|
|
474
|
+
input,
|
|
475
|
+
unions,
|
|
476
|
+
expected: metadata.getName(),
|
|
477
|
+
}),
|
|
474
478
|
),
|
|
475
479
|
undefined,
|
|
476
480
|
undefined,
|
|
@@ -709,7 +713,7 @@ export namespace JsonStringifyProgrammer {
|
|
|
709
713
|
empty: ts.factory.createStringLiteral("[]"),
|
|
710
714
|
success: ts.factory.createTrue(),
|
|
711
715
|
failure: (input, expected) =>
|
|
712
|
-
create_throw_error(importer
|
|
716
|
+
create_throw_error({ importer, expected, input }),
|
|
713
717
|
}),
|
|
714
718
|
)(input, elements, explore);
|
|
715
719
|
|
|
@@ -808,40 +812,40 @@ export namespace JsonStringifyProgrammer {
|
|
|
808
812
|
);
|
|
809
813
|
};
|
|
810
814
|
|
|
811
|
-
const wrap_functional = (
|
|
812
|
-
input: ts.Expression
|
|
813
|
-
|
|
814
|
-
explore: FeatureProgrammer.IExplore
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
815
|
+
const wrap_functional = (props: {
|
|
816
|
+
input: ts.Expression;
|
|
817
|
+
metadata: Metadata;
|
|
818
|
+
explore: FeatureProgrammer.IExplore;
|
|
819
|
+
expression: ts.Expression;
|
|
820
|
+
}): ts.Expression => {
|
|
821
|
+
if (props.metadata.functions.length === 0) return props.expression;
|
|
822
|
+
return ts.factory.createConditionalExpression(
|
|
823
|
+
ts.factory.createStrictInequality(
|
|
824
|
+
ts.factory.createStringLiteral("function"),
|
|
825
|
+
ValueFactory.TYPEOF(props.input),
|
|
826
|
+
),
|
|
827
|
+
undefined,
|
|
828
|
+
props.expression,
|
|
829
|
+
undefined,
|
|
830
|
+
decode_functional(props.explore),
|
|
831
|
+
);
|
|
828
832
|
};
|
|
829
833
|
|
|
830
|
-
const iterate = (
|
|
831
|
-
importer: FunctionImporter
|
|
832
|
-
input: ts.Expression
|
|
833
|
-
unions: IUnion[]
|
|
834
|
-
expected: string
|
|
835
|
-
) =>
|
|
834
|
+
const iterate = (props: {
|
|
835
|
+
importer: FunctionImporter;
|
|
836
|
+
input: ts.Expression;
|
|
837
|
+
unions: IUnion[];
|
|
838
|
+
expected: string;
|
|
839
|
+
}) =>
|
|
836
840
|
ts.factory.createBlock(
|
|
837
841
|
[
|
|
838
|
-
...unions.map((u) =>
|
|
842
|
+
...props.unions.map((u) =>
|
|
839
843
|
ts.factory.createIfStatement(
|
|
840
844
|
u.is(),
|
|
841
845
|
ts.factory.createReturnStatement(u.value()),
|
|
842
846
|
),
|
|
843
847
|
),
|
|
844
|
-
create_throw_error(
|
|
848
|
+
create_throw_error(props),
|
|
845
849
|
],
|
|
846
850
|
true,
|
|
847
851
|
);
|
|
@@ -854,7 +858,7 @@ export namespace JsonStringifyProgrammer {
|
|
|
854
858
|
const configure =
|
|
855
859
|
(project: ITypiaContext) =>
|
|
856
860
|
(importer: FunctionImporter): FeatureProgrammer.IConfig => {
|
|
857
|
-
const config: FeatureProgrammer.IConfig = {
|
|
861
|
+
const config: FeatureProgrammer.IConfig<ts.Expression> = {
|
|
858
862
|
types: {
|
|
859
863
|
input: (type, name) =>
|
|
860
864
|
ts.factory.createTypeReferenceNode(
|
|
@@ -870,14 +874,18 @@ export namespace JsonStringifyProgrammer {
|
|
|
870
874
|
objector: {
|
|
871
875
|
checker: () => IsProgrammer.decode(project)(importer),
|
|
872
876
|
decoder: () => decode_object(importer),
|
|
873
|
-
joiner:
|
|
877
|
+
joiner: (props) =>
|
|
878
|
+
StringifyJoiner.object({
|
|
879
|
+
...props,
|
|
880
|
+
importer,
|
|
881
|
+
}),
|
|
874
882
|
unionizer: decode_union_object(
|
|
875
883
|
IsProgrammer.decode_object(project)(importer),
|
|
876
|
-
)(decode_object(importer))((exp) => exp)((
|
|
877
|
-
create_throw_error(importer
|
|
884
|
+
)(decode_object(importer))((exp) => exp)((input, expected) =>
|
|
885
|
+
create_throw_error({ importer, expected, input }),
|
|
878
886
|
),
|
|
879
887
|
failure: (input, expected) =>
|
|
880
|
-
create_throw_error(importer
|
|
888
|
+
create_throw_error({ importer, expected, input }),
|
|
881
889
|
},
|
|
882
890
|
generator: {
|
|
883
891
|
arrays: () => write_array_functions(config)(importer),
|
|
@@ -896,28 +904,29 @@ export namespace JsonStringifyProgrammer {
|
|
|
896
904
|
type,
|
|
897
905
|
});
|
|
898
906
|
|
|
899
|
-
const create_throw_error =
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
),
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
)
|
|
907
|
+
const create_throw_error = (props: {
|
|
908
|
+
importer: FunctionImporter;
|
|
909
|
+
expected: string;
|
|
910
|
+
input: ts.Expression;
|
|
911
|
+
}) =>
|
|
912
|
+
ts.factory.createExpressionStatement(
|
|
913
|
+
ts.factory.createCallExpression(
|
|
914
|
+
props.importer.use("throws"),
|
|
915
|
+
[],
|
|
916
|
+
[
|
|
917
|
+
ts.factory.createObjectLiteralExpression(
|
|
918
|
+
[
|
|
919
|
+
ts.factory.createPropertyAssignment(
|
|
920
|
+
"expected",
|
|
921
|
+
ts.factory.createStringLiteral(props.expected),
|
|
922
|
+
),
|
|
923
|
+
ts.factory.createPropertyAssignment("value", props.input),
|
|
924
|
+
],
|
|
925
|
+
true,
|
|
926
|
+
),
|
|
927
|
+
],
|
|
928
|
+
),
|
|
929
|
+
);
|
|
921
930
|
}
|
|
922
931
|
|
|
923
932
|
interface IUnion {
|