Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IValidation.IError.data property. #1421

Merged
merged 6 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
name: build
on:
push:
paths:
- 'src/**'
- 'test/**'
- 'test-error/**'
- 'test-esm/**'
- 'package.json'
- '.github/workflows/build.yml'
pull_request:
paths:
- 'src/**'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "7.1.0",
"version": "7.2.0",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/IValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export namespace IValidation {
export interface IFailure {
success: false;
errors: IError[];
data: unknown;
}

export interface IError {
Expand Down
41 changes: 23 additions & 18 deletions src/programmers/ValidateProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,6 @@ export namespace ValidateProgrammer {
"success",
ts.factory.createTrue(),
),
ts.factory.createPropertyAssignment(
"errors",
ts.factory.createArrayLiteralExpression([]),
),
ts.factory.createPropertyAssignment(
"data",
ts.factory.createIdentifier("input"),
Expand Down Expand Up @@ -390,22 +386,31 @@ const joiner = (props: {
});

const create_output = () =>
ts.factory.createObjectLiteralExpression(
[
ts.factory.createShorthandPropertyAssignment("success"),
ts.factory.createShorthandPropertyAssignment("errors"),
ts.factory.createPropertyAssignment(
"data",
ts.factory.createConditionalExpression(
ts.factory.createIdentifier("success"),
undefined,
ts.factory.createConditionalExpression(
ts.factory.createIdentifier("success"),
undefined,
ts.factory.createObjectLiteralExpression(
[
ts.factory.createShorthandPropertyAssignment("success"),
ts.factory.createPropertyAssignment(
"data",
ts.factory.createIdentifier("input"),
undefined,
ts.factory.createIdentifier("undefined"),
),
),
],
true,
],
true,
),
undefined,
ts.factory.createObjectLiteralExpression(
[
ts.factory.createShorthandPropertyAssignment("success"),
ts.factory.createShorthandPropertyAssignment("errors"),
ts.factory.createPropertyAssignment(
"data",
ts.factory.createIdentifier("input"),
),
],
true,
),
);

const create_report_call = (props: {
Expand Down
2 changes: 1 addition & 1 deletion test/generate/output/generate_http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export const validateQuery = (() => {
return {
success,
errors,
data: success ? input : undefined,
data: input,
} as any;
}
return {
Expand Down
4 changes: 2 additions & 2 deletions test/generate/output/generate_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ export const validate = (() => {
return {
success,
errors,
data: success ? input : undefined,
data: input,
} as any;
}
return {
Expand Down Expand Up @@ -1707,7 +1707,7 @@ export const validateEquals = (() => {
return {
success,
errors,
data: success ? input : undefined,
data: input,
} as any;
}
return {
Expand Down
4 changes: 2 additions & 2 deletions test/generate/output/generate_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const createValidateStringify = (() => {
return {
success,
errors,
data: success ? input : undefined,
data: input,
} as any;
}
return {
Expand Down Expand Up @@ -1101,7 +1101,7 @@ export const createValidateParse = (() => {
return {
success,
errors,
data: success ? input : undefined,
data: input,
} as any;
}
return {
Expand Down
4 changes: 2 additions & 2 deletions test/generate/output/generate_misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ export const createValidateClone = (() => {
return {
success,
errors,
data: success ? input : undefined,
data: input,
} as any;
}
return {
Expand Down Expand Up @@ -1198,7 +1198,7 @@ export const createValidatePrune = (() => {
return {
success,
errors,
data: success ? input : undefined,
data: input,
} as any;
}
return {
Expand Down
6 changes: 3 additions & 3 deletions test/generate/output/generate_notations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ export const createValidateCamel = (() => {
return {
success,
errors,
data: success ? input : undefined,
data: input,
} as any;
}
return {
Expand Down Expand Up @@ -1101,7 +1101,7 @@ export const createValidatePascal = (() => {
return {
success,
errors,
data: success ? input : undefined,
data: input,
} as any;
}
return {
Expand Down Expand Up @@ -1653,7 +1653,7 @@ export const createValidateSnake = (() => {
return {
success,
errors,
data: success ? input : undefined,
data: input,
} as any;
}
return {
Expand Down
4 changes: 2 additions & 2 deletions test/generate/output/generate_plain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ export const createValidate = (() => {
return {
success,
errors,
data: success ? input : undefined,
data: input,
} as any;
}
return {
Expand Down Expand Up @@ -1707,7 +1707,7 @@ export const createValidateEquals = (() => {
return {
success,
errors,
data: success ? input : undefined,
data: input,
} as any;
}
return {
Expand Down
4 changes: 2 additions & 2 deletions test/generate/output/generate_protobuf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ export const createValidateEncode = (() => {
return {
success,
errors,
data: success ? input : undefined,
data: input,
} as any;
}
return {
Expand Down Expand Up @@ -870,7 +870,7 @@ export const createValidateDecode = (() => {
return {
success,
errors,
data: success ? input : undefined,
data: input,
} as any;
}
return {
Expand Down
9 changes: 9 additions & 0 deletions test/src/debug/validate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import typia from "typia";

console.log(
typia.validate<number>("one"),
typia.json.validateStringify<string>(2),
typia.protobuf.validateEncode<{
id: string;
}>({ id: 3 }),
);
2 changes: 1 addition & 1 deletion test/src/internal/_test_functional_validateFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const _test_functional_validateFunction =
throw new Error(
`Bug on typia.functional.validateFunction(): failed to detect error on the ${name} type.`,
);
typia.assert(valid);
typia.assertEquals(valid);
valid.errors.sort((x, y) => (x.path < y.path ? -1 : 1));

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const _test_functional_validateFunctionAsync =
throw new Error(
`Bug on await typia.functional.validateFunction(): failed to detect error on the ${name} type.`,
);
typia.assert(valid);
typia.assertEquals(valid);
valid.errors.sort((x, y) => (x.path < y.path ? -1 : 1));

if (
Expand Down
2 changes: 1 addition & 1 deletion test/src/internal/_test_functional_validateParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const _test_functional_validateParameters =
throw new Error(
`Bug on typia.functional.validateFunction(): failed to detect error on the ${name} type.`,
);
typia.assert(valid);
typia.assertEquals(valid);
valid.errors.sort((x, y) => (x.path < y.path ? -1 : 1));

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const _test_functional_validateParametersAsync =
throw new Error(
`Bug on await typia.functional.validateFunction(): failed to detect error on the ${name} type.`,
);
typia.assert(valid);
typia.assertEquals(valid);
valid.errors.sort((x, y) => (x.path < y.path ? -1 : 1));

if (
Expand Down
2 changes: 1 addition & 1 deletion test/src/internal/_test_functional_validateReturn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const _test_functional_validateReturn =
throw new Error(
`Bug on typia.functional.validateFunction(): failed to detect error on the ${name} type.`,
);
typia.assert(valid);
typia.assertEquals(valid);
valid.errors.sort((x, y) => (x.path < y.path ? -1 : 1));

if (
Expand Down
3 changes: 2 additions & 1 deletion test/src/internal/_test_http_validateFormData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const _test_http_validateFormData =
throw new Error(
`Bug on typia.http.validateFormData(): failed to understand ${name} type.`,
);
typia.assertEquals<typia.IValidation.ISuccess<unknown>>(result);

const equal: boolean =
result !== null && resolved_equal_to(name)(data, result.data);
Expand All @@ -38,7 +39,7 @@ export const _test_http_validateFormData =
`Bug on typia.http.validateFormData(): failed to detect error on the ${name} type.`,
);

typia.assert(valid);
typia.assertEquals(valid);
expected.sort();
valid.errors.sort((x, y) => (x.path < y.path ? -1 : 1));

Expand Down
3 changes: 2 additions & 1 deletion test/src/internal/_test_http_validateHeaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const _test_http_validateHeaders =
throw new Error(
`Bug on typia.http.validateHeaders(): failed to understand ${name} type.`,
);
typia.assertEquals<typia.IValidation.ISuccess<unknown>>(result);

const equal: boolean =
result !== null && resolved_equal_to(name)(data, result.data);
Expand All @@ -43,7 +44,7 @@ export const _test_http_validateHeaders =
`Bug on typia.http.validateHeaders(): failed to detect error on the ${name} type.`,
);

typia.assert(valid);
typia.assertEquals(valid);
expected.sort();
valid.errors.sort((x, y) => (x.path < y.path ? -1 : 1));

Expand Down
3 changes: 2 additions & 1 deletion test/src/internal/_test_http_validateQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const _test_http_validateQuery =
throw new Error(
`Bug on typia.http.validateQuery(): failed to understand ${name} type.`,
);
typia.assertEquals<typia.IValidation.ISuccess<unknown>>(result);

const equal: boolean =
result !== null && resolved_equal_to(name)(data, result.data);
Expand All @@ -38,7 +39,7 @@ export const _test_http_validateQuery =
`Bug on typia.http.validateQuery(): failed to detect error on the ${name} type.`,
);

typia.assert(valid);
typia.assertEquals(valid);
expected.sort();
valid.errors.sort((x, y) => (x.path < y.path ? -1 : 1));

Expand Down
1 change: 1 addition & 0 deletions test/src/internal/_test_json_validateParse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const _test_json_validateParse =
`Bug on typia.json.validateParse(): failed to understand the ${name} type.`,
);
}
typia.assertEquals<IValidation.ISuccess<unknown>>(valid);

const wrong: ISpoiled[] = [];
for (const spoil of factory.SPOILERS ?? []) {
Expand Down
3 changes: 2 additions & 1 deletion test/src/internal/_test_json_validateStringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const _test_json_validateStringify =
`Bug on typia.json.validateStringify(): failed to understand the ${name} type.`,
);

typia.assertEquals(valid);
if (predicate(input, valid.data) === false) {
throw new Error(
`Bug on typia.json.validateStringify(): failed to understand the ${name} type.`,
Expand All @@ -32,7 +33,7 @@ export const _test_json_validateStringify =
`Bug on typia.json.validateStringify(): failed to detect error on the ${name} type.`,
);

typia.assert(valid);
typia.assertEquals(valid);
expected.sort();
valid.errors.sort((x, y) => (x.path < y.path ? -1 : 1));

Expand Down
3 changes: 2 additions & 1 deletion test/src/internal/_test_misc_validateClone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const _test_misc_validateClone =
`Bug on typia.misc.validateClone(): failed to understand the ${name} type.`,
);

typia.assertEquals<typia.IValidation.ISuccess<unknown>>(valid);
if (resolved_equal_to(name)(input, valid.data) === false) {
throw new Error(
`Bug on typia.misc.validateClone(): failed to understand the ${name} type.`,
Expand All @@ -32,7 +33,7 @@ export const _test_misc_validateClone =
`Bug on typia.misc.validateClone(): failed to detect error on the ${name} type.`,
);

typia.assert(valid);
typia.assertEquals(valid);
expected.sort();
valid.errors.sort((x, y) => (x.path < y.path ? -1 : 1));

Expand Down
4 changes: 2 additions & 2 deletions test/src/internal/_test_misc_validatePrune.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IValidation, assert } from "typia";
import { IValidation, assertEquals } from "typia";

import { TestStructure } from "../helpers/TestStructure";

Expand Down Expand Up @@ -45,7 +45,7 @@ export const _test_misc_validatePrune =
`Bug on typia.misc.validatePrune(): failed to detect error on the ${name} type.`,
);

assert(valid);
assertEquals(valid);
expected.sort();
valid.errors.sort((x, y) => (x.path < y.path ? -1 : 1));

Expand Down
4 changes: 3 additions & 1 deletion test/src/internal/_test_notation_validateGeneral.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IValidation } from "typia";
import typia, { IValidation } from "typia";

import { TestStructure } from "../helpers/TestStructure";
import { _test_notation_general } from "./_test_notation_general";
Expand All @@ -19,6 +19,7 @@ export const _test_notation_validateGeneral =
throw new Error(
`Bug on typia.notations.validateX(): failed to understand the ${name} type.`,
);
typia.assertEquals<IValidation.ISuccess<unknown>>(res);
return res.data;
},
})();
Expand All @@ -34,6 +35,7 @@ export const _test_notation_validateGeneral =
`Bug on typia.notations.validateX(): failed to detect error on the ${name} type.`,
);

typia.assertEquals(valid);
expected.sort();
valid.errors.sort((x, y) => (x.path < y.path ? -1 : 1));

Expand Down
Loading
Loading