Skip to content

Commit fab6d7e

Browse files
authored
Complement standard schema type (#1581)
* Complement standard schema type * Concise check-format
1 parent 3030da1 commit fab6d7e

File tree

5 files changed

+144
-130
lines changed

5 files changed

+144
-130
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ jobs:
4949
version: 8
5050
- run: pnpm install --force
5151
- run: pnpm run eslint
52-
- run: pnpm run prettier
5352

5453
NodeJS:
5554
runs-on: ubuntu-latest

src/internal/_createStandardSchema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IValidation } from "../IValidation";
44

55
export const _createStandardSchema = <T>(
66
fn: (input: unknown) => IValidation<T>,
7-
) =>
7+
): ((input: unknown) => IValidation<T>) & StandardSchemaV1<unknown, T> =>
88
Object.assign(fn, {
99
"~standard": {
1010
version: 1,

test/generate/output/generate_index.ts

Lines changed: 69 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import typia, { tags } from "typia";
22
import * as __typia_transform__accessExpressionAsString from "typia/lib/internal/_accessExpressionAsString.js";
33
import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
4+
import * as __typia_transform__createStandardSchema from "typia/lib/internal/_createStandardSchema.js";
45
import * as __typia_transform__isFormatEmail from "typia/lib/internal/_isFormatEmail.js";
56
import * as __typia_transform__isFormatUuid from "typia/lib/internal/_isFormatUuid.js";
67
import * as __typia_transform__isTypeUint32 from "typia/lib/internal/_isTypeUint32.js";
@@ -738,42 +739,44 @@ export const validate = (() => {
738739
"object" === typeof input && null !== input && _io0(input);
739740
let errors: any;
740741
let _report: any;
741-
return (input: any): import("typia").IValidation<ICitizen> => {
742-
if (false === __is(input)) {
743-
errors = [];
744-
_report = (__typia_transform__validateReport._validateReport as any)(
745-
errors,
746-
);
747-
((input: any, _path: string, _exceptionable: boolean = true) =>
748-
((("object" === typeof input && null !== input) ||
742+
return __typia_transform__createStandardSchema._createStandardSchema(
743+
(input: any): import("typia").IValidation<ICitizen> => {
744+
if (false === __is(input)) {
745+
errors = [];
746+
_report = (__typia_transform__validateReport._validateReport as any)(
747+
errors,
748+
);
749+
((input: any, _path: string, _exceptionable: boolean = true) =>
750+
((("object" === typeof input && null !== input) ||
751+
_report(true, {
752+
path: _path + "",
753+
expected: "ICitizen",
754+
value: input,
755+
})) &&
756+
_vo0(input, _path + "", true)) ||
749757
_report(true, {
750758
path: _path + "",
751759
expected: "ICitizen",
752760
value: input,
753-
})) &&
754-
_vo0(input, _path + "", true)) ||
755-
_report(true, {
756-
path: _path + "",
757-
expected: "ICitizen",
758-
value: input,
759-
}))(input, "$input", true);
760-
const success = 0 === errors.length;
761-
return success
762-
? {
763-
success,
764-
data: input,
765-
}
766-
: ({
767-
success,
768-
errors,
769-
data: input,
770-
} as any);
771-
}
772-
return {
773-
success: true,
774-
data: input,
775-
} as any;
776-
};
761+
}))(input, "$input", true);
762+
const success = 0 === errors.length;
763+
return success
764+
? {
765+
success,
766+
data: input,
767+
}
768+
: ({
769+
success,
770+
errors,
771+
data: input,
772+
} as any);
773+
}
774+
return {
775+
success: true,
776+
data: input,
777+
} as any;
778+
},
779+
);
777780
})();
778781
export const equals = (() => {
779782
const _io0 = (input: any, _exceptionable: boolean = true): boolean =>
@@ -1688,42 +1691,44 @@ export const validateEquals = (() => {
16881691
"object" === typeof input && null !== input && _io0(input, true);
16891692
let errors: any;
16901693
let _report: any;
1691-
return (input: any): import("typia").IValidation<ICitizen> => {
1692-
if (false === __is(input)) {
1693-
errors = [];
1694-
_report = (__typia_transform__validateReport._validateReport as any)(
1695-
errors,
1696-
);
1697-
((input: any, _path: string, _exceptionable: boolean = true) =>
1698-
((("object" === typeof input && null !== input) ||
1694+
return __typia_transform__createStandardSchema._createStandardSchema(
1695+
(input: any): import("typia").IValidation<ICitizen> => {
1696+
if (false === __is(input)) {
1697+
errors = [];
1698+
_report = (__typia_transform__validateReport._validateReport as any)(
1699+
errors,
1700+
);
1701+
((input: any, _path: string, _exceptionable: boolean = true) =>
1702+
((("object" === typeof input && null !== input) ||
1703+
_report(true, {
1704+
path: _path + "",
1705+
expected: "ICitizen",
1706+
value: input,
1707+
})) &&
1708+
_vo0(input, _path + "", true)) ||
16991709
_report(true, {
17001710
path: _path + "",
17011711
expected: "ICitizen",
17021712
value: input,
1703-
})) &&
1704-
_vo0(input, _path + "", true)) ||
1705-
_report(true, {
1706-
path: _path + "",
1707-
expected: "ICitizen",
1708-
value: input,
1709-
}))(input, "$input", true);
1710-
const success = 0 === errors.length;
1711-
return success
1712-
? {
1713-
success,
1714-
data: input,
1715-
}
1716-
: ({
1717-
success,
1718-
errors,
1719-
data: input,
1720-
} as any);
1721-
}
1722-
return {
1723-
success: true,
1724-
data: input,
1725-
} as any;
1726-
};
1713+
}))(input, "$input", true);
1714+
const success = 0 === errors.length;
1715+
return success
1716+
? {
1717+
success,
1718+
data: input,
1719+
}
1720+
: ({
1721+
success,
1722+
errors,
1723+
data: input,
1724+
} as any);
1725+
}
1726+
return {
1727+
success: true,
1728+
data: input,
1729+
} as any;
1730+
},
1731+
);
17271732
})();
17281733
export const random = (() => {
17291734
const _ro0 = (_recursive: boolean = true, _depth: number = 0): any => ({

test/generate/output/generate_plain.ts

Lines changed: 69 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import typia, { tags } from "typia";
22
import * as __typia_transform__accessExpressionAsString from "typia/lib/internal/_accessExpressionAsString.js";
33
import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
4+
import * as __typia_transform__createStandardSchema from "typia/lib/internal/_createStandardSchema.js";
45
import * as __typia_transform__isFormatEmail from "typia/lib/internal/_isFormatEmail.js";
56
import * as __typia_transform__isFormatUuid from "typia/lib/internal/_isFormatUuid.js";
67
import * as __typia_transform__isTypeUint32 from "typia/lib/internal/_isTypeUint32.js";
@@ -1443,42 +1444,44 @@ export const createValidate = (() => {
14431444
"object" === typeof input && null !== input && _io0(input);
14441445
let errors: any;
14451446
let _report: any;
1446-
return (input: any): import("typia").IValidation<ICitizen> => {
1447-
if (false === __is(input)) {
1448-
errors = [];
1449-
_report = (__typia_transform__validateReport._validateReport as any)(
1450-
errors,
1451-
);
1452-
((input: any, _path: string, _exceptionable: boolean = true) =>
1453-
((("object" === typeof input && null !== input) ||
1447+
return __typia_transform__createStandardSchema._createStandardSchema(
1448+
(input: any): import("typia").IValidation<ICitizen> => {
1449+
if (false === __is(input)) {
1450+
errors = [];
1451+
_report = (__typia_transform__validateReport._validateReport as any)(
1452+
errors,
1453+
);
1454+
((input: any, _path: string, _exceptionable: boolean = true) =>
1455+
((("object" === typeof input && null !== input) ||
1456+
_report(true, {
1457+
path: _path + "",
1458+
expected: "ICitizen",
1459+
value: input,
1460+
})) &&
1461+
_vo0(input, _path + "", true)) ||
14541462
_report(true, {
14551463
path: _path + "",
14561464
expected: "ICitizen",
14571465
value: input,
1458-
})) &&
1459-
_vo0(input, _path + "", true)) ||
1460-
_report(true, {
1461-
path: _path + "",
1462-
expected: "ICitizen",
1463-
value: input,
1464-
}))(input, "$input", true);
1465-
const success = 0 === errors.length;
1466-
return success
1467-
? {
1468-
success,
1469-
data: input,
1470-
}
1471-
: ({
1472-
success,
1473-
errors,
1474-
data: input,
1475-
} as any);
1476-
}
1477-
return {
1478-
success: true,
1479-
data: input,
1480-
} as any;
1481-
};
1466+
}))(input, "$input", true);
1467+
const success = 0 === errors.length;
1468+
return success
1469+
? {
1470+
success,
1471+
data: input,
1472+
}
1473+
: ({
1474+
success,
1475+
errors,
1476+
data: input,
1477+
} as any);
1478+
}
1479+
return {
1480+
success: true,
1481+
data: input,
1482+
} as any;
1483+
},
1484+
);
14821485
})();
14831486
export const createValidateEquals = (() => {
14841487
const _io0 = (input: any, _exceptionable: boolean = true): boolean =>
@@ -1688,42 +1691,44 @@ export const createValidateEquals = (() => {
16881691
"object" === typeof input && null !== input && _io0(input, true);
16891692
let errors: any;
16901693
let _report: any;
1691-
return (input: any): import("typia").IValidation<ICitizen> => {
1692-
if (false === __is(input)) {
1693-
errors = [];
1694-
_report = (__typia_transform__validateReport._validateReport as any)(
1695-
errors,
1696-
);
1697-
((input: any, _path: string, _exceptionable: boolean = true) =>
1698-
((("object" === typeof input && null !== input) ||
1694+
return __typia_transform__createStandardSchema._createStandardSchema(
1695+
(input: any): import("typia").IValidation<ICitizen> => {
1696+
if (false === __is(input)) {
1697+
errors = [];
1698+
_report = (__typia_transform__validateReport._validateReport as any)(
1699+
errors,
1700+
);
1701+
((input: any, _path: string, _exceptionable: boolean = true) =>
1702+
((("object" === typeof input && null !== input) ||
1703+
_report(true, {
1704+
path: _path + "",
1705+
expected: "ICitizen",
1706+
value: input,
1707+
})) &&
1708+
_vo0(input, _path + "", true)) ||
16991709
_report(true, {
17001710
path: _path + "",
17011711
expected: "ICitizen",
17021712
value: input,
1703-
})) &&
1704-
_vo0(input, _path + "", true)) ||
1705-
_report(true, {
1706-
path: _path + "",
1707-
expected: "ICitizen",
1708-
value: input,
1709-
}))(input, "$input", true);
1710-
const success = 0 === errors.length;
1711-
return success
1712-
? {
1713-
success,
1714-
data: input,
1715-
}
1716-
: ({
1717-
success,
1718-
errors,
1719-
data: input,
1720-
} as any);
1721-
}
1722-
return {
1723-
success: true,
1724-
data: input,
1725-
} as any;
1726-
};
1713+
}))(input, "$input", true);
1714+
const success = 0 === errors.length;
1715+
return success
1716+
? {
1717+
success,
1718+
data: input,
1719+
}
1720+
: ({
1721+
success,
1722+
errors,
1723+
data: input,
1724+
} as any);
1725+
}
1726+
return {
1727+
success: true,
1728+
data: input,
1729+
} as any;
1730+
},
1731+
);
17271732
})();
17281733
export const createRandom = (() => {
17291734
const _ro0 = (_recursive: boolean = true, _depth: number = 0): any => ({

test/src/debug/standard-schema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import typia from "typia";
2+
3+
const validate = typia.createValidate<number>();
4+
const result = validate(42);
5+
if (result.success === true) console.log(result.data);

0 commit comments

Comments
 (0)