Skip to content

Commit 436043d

Browse files
committed
add validation checker
1 parent e4ac3c0 commit 436043d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

packages/core/src/programmers/json/JsonStringifyProgrammer.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export namespace JsonStringifyProgrammer {
127127
config: FeatureProgrammer.IConfig;
128128
functor: FunctionProgrammer;
129129
collection: MetadataCollection;
130+
validated: boolean;
130131
}): ts.VariableStatement[] =>
131132
props.collection
132133
.tuples()
@@ -156,6 +157,7 @@ export namespace JsonStringifyProgrammer {
156157
from: "array",
157158
postfix: "",
158159
},
160+
validated: props.validated,
159161
}),
160162
),
161163
}),
@@ -171,6 +173,7 @@ export namespace JsonStringifyProgrammer {
171173
input: ts.Expression;
172174
metadata: MetadataSchema;
173175
explore: FeatureProgrammer.IExplore;
176+
validated: boolean;
174177
}): ts.Expression => {
175178
// ANY TYPE
176179
if (props.metadata.any === true)
@@ -591,6 +594,7 @@ export namespace JsonStringifyProgrammer {
591594
input: ts.Expression;
592595
tuple: MetadataTuple;
593596
explore: FeatureProgrammer.IExplore;
597+
validated: boolean;
594598
}): ts.Expression =>
595599
props.tuple.type.recursive
596600
? ts.factory.createCallExpression(
@@ -621,6 +625,7 @@ export namespace JsonStringifyProgrammer {
621625
input: ts.Expression;
622626
tuple: MetadataTupleType;
623627
explore: FeatureProgrammer.IExplore;
628+
validated: boolean;
624629
}): ts.Expression => {
625630
const elements: ts.Expression[] = props.tuple.elements
626631
.filter((elem) => elem.rest === null)
@@ -673,6 +678,7 @@ export namespace JsonStringifyProgrammer {
673678
input: ts.Expression;
674679
type: string;
675680
explore: FeatureProgrammer.IExplore;
681+
validated: boolean;
676682
}): ts.Expression => {
677683
if (props.type === "string")
678684
return ts.factory.createCallExpression(
@@ -685,8 +691,7 @@ export namespace JsonStringifyProgrammer {
685691
...props,
686692
input: ts.factory.createCallExpression(
687693
props.context.importer.internal(
688-
OptionPredicator.finite(props.context.options) ||
689-
OptionPredicator.numeric(props.context.options)
694+
props.validated && OptionPredicator.finite(props.context.options)
690695
? "jsonStringifyNumber"
691696
: "jsonStringifyNumberNull",
692697
),
@@ -710,6 +715,7 @@ export namespace JsonStringifyProgrammer {
710715
input: ts.Expression;
711716
values: string[];
712717
explore: FeatureProgrammer.IExplore;
718+
validated: boolean;
713719
}): ts.Expression => {
714720
if (props.values.every((v) => !StringifyPredicator.require_escape(v)))
715721
return [
@@ -730,6 +736,7 @@ export namespace JsonStringifyProgrammer {
730736
input: ts.Expression;
731737
metadata: MetadataSchema;
732738
explore: FeatureProgrammer.IExplore;
739+
validated: boolean;
733740
}): ts.Expression => {
734741
return decode({
735742
...props,
@@ -977,6 +984,7 @@ export namespace JsonStringifyProgrammer {
977984
const configure = (props: {
978985
context: ITypiaContext;
979986
functor: FunctionProgrammer;
987+
validated: boolean;
980988
}): FeatureProgrammer.IConfig => {
981989
const config: FeatureProgrammer.IConfig<ts.Expression> = {
982990
types: {
@@ -999,6 +1007,7 @@ export namespace JsonStringifyProgrammer {
9991007
metadata: next.metadata,
10001008
input: next.input,
10011009
explore: next.explore,
1010+
validated: props.validated,
10021011
}),
10031012
objector: {
10041013
checker: (next) =>
@@ -1071,6 +1080,7 @@ export namespace JsonStringifyProgrammer {
10711080
context: props.context,
10721081
functor: props.functor,
10731082
collection,
1083+
validated: props.validated,
10741084
}),
10751085
},
10761086
};

0 commit comments

Comments
 (0)