Skip to content

Commit

Permalink
feat: add typia (#1023)
Browse files Browse the repository at this point in the history
* Add typia

* For lint

* Add new line

* typia on npm commands

* Understood what parseSafe is

* More simple parseSafe

* Update README.md - add typia

* Change `ITransformOptions.undefined` value

* Upgrade typia version

* Upgrade typia version

* Update typia again

* block undefined value
  • Loading branch information
samchon authored Feb 6, 2023
1 parent 650ec55 commit bfc9e6e
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 43 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
docs/dist
cases/spectypes/build
cases/ts-runtime-checks/build
case/typia/build
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ cases/spectypes/build

# ts-runtime-checks build artifacts
cases/ts-runtime-checks/build

# typia build artifacts
cases/typia/build
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* [ts-runtime-checks](https://github.com/GoogleFeud/ts-runtime-checks)
* [tson](https://github.com/skarab42/tson)
* [ts-utils](https://github.com/ai-labs-team/ts-utils)
* [typia](https://github.com/samchon/typia)
* [@typeofweb/schema](https://github.com/typeofweb/schema)
* [valita](https://github.com/badrap/valita)
* [Vality](https://github.com/jeengbe/vality)
Expand Down
1 change: 1 addition & 0 deletions cases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const cases = [
'ts-utils',
'tson',
'typeofweb-schema',
'typia',
'valita',
'vality',
'yup',
Expand Down
7 changes: 7 additions & 0 deletions cases/typia/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { parseSafe, parseStrict, assertLoose, assertStrict } from './build';
import { addCase } from '../../benchmarks';

addCase('typia', 'parseSafe', parseSafe);
addCase('typia', 'parseStrict', parseStrict);
addCase('typia', 'assertStrict', assertStrict);
addCase('typia', 'assertLoose', assertLoose);
39 changes: 39 additions & 0 deletions cases/typia/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import typia from 'typia';

interface ToBeChecked {
number: number;
negNumber: number;
maxNumber: number;
string: string;
longString: string;
boolean: boolean;
deeplyNested: {
foo: string;
num: number;
bool: boolean;
};
}

const is = typia.createIs<ToBeChecked>();
const equals = typia.createEquals<ToBeChecked>();
const stringify = typia.createStringify<ToBeChecked>();

export function assertLoose(input: unknown): boolean {
if (!is(input)) throw new Error('wrong type.');
return true;
}

export function assertStrict(input: unknown): boolean {
if (!equals(input)) throw new Error('wrong type.');
return true;
}

export function parseStrict(input: unknown): ToBeChecked {
if (!equals(input)) throw new Error('wrong type.');
return input;
}

export function parseSafe(input: unknown): ToBeChecked {
if (!is(input)) throw new Error('wrong type.');
return JSON.parse(stringify(input));
}
16 changes: 16 additions & 0 deletions cases/typia/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "build",
"strict": true,
"plugins": [
{
"transform": "typia/lib/transform",
"undefined": false,
}
]
},
"include": ["src/index.ts"]
}

1 change: 0 additions & 1 deletion docs/results/node-18.json

This file was deleted.

5 changes: 5 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ async function main() {
stdio: 'inherit',
});
}
if (c === 'typia') {
childProcess.execSync('npm run compile:typia', {
stdio: 'inherit',
});
}

const cmd = [...process.argv.slice(0, 2), 'run-internal', c];

Expand Down
70 changes: 33 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
"lint": "gts check",
"lint:fix": "gts fix",
"start": "ts-node index.ts",
"test:build": "npm run compile:spectypes && npm run compile:ts-runtime-checks && tsc --noEmit",
"test": "npm run compile:spectypes && npm run compile:ts-runtime-checks && jest",
"test:build": "npm run compile:spectypes && npm run compile:ts-runtime-checks && npm run compile:typia && tsc --noEmit",
"test": "npm run compile:spectypes && npm run compile:ts-runtime-checks && npm run compile:typia && jest",
"docs:serve": "serve docs",
"docs:watch": "tsc --project tsconfig.docs.json --watch --preserveWatchOutput & serve docs",
"docs:build": "tsc --project tsconfig.docs.json",
"compile:spectypes": "rimraf cases/spectypes/build && tsc -p cases/spectypes/src && babel cases/spectypes/src --out-dir cases/spectypes/build --extensions \".ts\"",
"compile:ts-runtime-checks": "rimraf cases/ts-runtime-checks/build && ttsc -p cases/ts-runtime-checks/src"
"compile:ts-runtime-checks": "rimraf cases/ts-runtime-checks/build && ttsc -p cases/ts-runtime-checks/src",
"compile:typia": "rimraf cases/typia/build && ttsc -p cases/typia/tsconfig.json"
},
"dependencies": {
"@ailabs/ts-utils": "1.4.0",
Expand Down Expand Up @@ -67,8 +68,9 @@
"ts-json-validator": "0.7.1",
"ts-node": "10.9.1",
"ts-runtime-checks": "0.1.3",
"ttypescript": "1.5.13",
"ttypescript": "1.5.15",
"typescript": "4.6.2",
"typia": "3.4.27",
"vality": "6.2.1",
"vega": "5.22.1",
"vega-lite": "4.11.0",
Expand All @@ -82,7 +84,7 @@
"@babel/preset-typescript": "7.18.6",
"@types/clone": "2.1.1",
"@types/jest": "29.0.2",
"@types/node": "16.11.59",
"@types/node": "^18.11.18",
"@types/svgo": "2.6.0",
"@types/yup": "0.29.14",
"babel-plugin-spectypes": "2.1.7",
Expand Down
1 change: 1 addition & 0 deletions test/benchmarks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import '../cases/ts-runtime-checks';
import '../cases/ts-utils';
import '../cases/tson';
import '../cases/typeofweb-schema';
import '../cases/typia';
import '../cases/valita';
import '../cases/vality';
import '../cases/yup';
Expand Down

0 comments on commit bfc9e6e

Please sign in to comment.