From ae811da9ac04905794b6561018890fe248f63a33 Mon Sep 17 00:00:00 2001 From: thetek Date: Wed, 3 Apr 2024 12:24:11 +0200 Subject: [PATCH] rm: typia-proof-of-concept --- misc/typia-proof-of-concept/.gitignore | 3 - misc/typia-proof-of-concept/README.md | 11 --- misc/typia-proof-of-concept/package.json | 18 ---- misc/typia-proof-of-concept/src/index.ts | 110 ---------------------- misc/typia-proof-of-concept/tsconfig.json | 21 ----- 5 files changed, 163 deletions(-) delete mode 100644 misc/typia-proof-of-concept/.gitignore delete mode 100644 misc/typia-proof-of-concept/README.md delete mode 100644 misc/typia-proof-of-concept/package.json delete mode 100644 misc/typia-proof-of-concept/src/index.ts delete mode 100644 misc/typia-proof-of-concept/tsconfig.json diff --git a/misc/typia-proof-of-concept/.gitignore b/misc/typia-proof-of-concept/.gitignore deleted file mode 100644 index 5cdf045..0000000 --- a/misc/typia-proof-of-concept/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/dist -/node_modules -/yarn.lock diff --git a/misc/typia-proof-of-concept/README.md b/misc/typia-proof-of-concept/README.md deleted file mode 100644 index 5f75ad8..0000000 --- a/misc/typia-proof-of-concept/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Typia Proof of Concept - -## Running - -```sh -yarn run demo -``` - -## Resources - -- Typia: [Repository](https://github.com/samchon/typia), [Documentation](https://typia.io/docs/) diff --git a/misc/typia-proof-of-concept/package.json b/misc/typia-proof-of-concept/package.json deleted file mode 100644 index a49deac..0000000 --- a/misc/typia-proof-of-concept/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "typia-proof-of-concept", - "version": "1.0.0", - "main": "index.js", - "license": "MIT", - "devDependencies": { - "ts-node": "^10.9.2", - "ts-patch": "^3.1.2", - "typescript": "5.4.2" - }, - "dependencies": { - "typia": "^5.5.7" - }, - "scripts": { - "prepare": "ts-patch install && typia patch", - "demo": "tsc && node dist/index.js" - } -} diff --git a/misc/typia-proof-of-concept/src/index.ts b/misc/typia-proof-of-concept/src/index.ts deleted file mode 100644 index 0091343..0000000 --- a/misc/typia-proof-of-concept/src/index.ts +++ /dev/null @@ -1,110 +0,0 @@ -import typia, { tags } from "typia"; - - - -/* type definitions */ - -type User = { - username: string & tags.MinLength<4> & tags.MaxLength<16>, // string with minimum and maximum length - birthdate: DateString, // custom type that also has constrains added to it - pets: Pet[] & tags.MinItems<1>, // bounds for number of items in list - favouriteTvSeries?: string, // optional properties -}; - -// custom type -type DateString = string & tags.Format<"date">; - -type Cat = { - animalType: "cat", // `animalType` can only be "cat", "dog" or "bird" - numberOfLivesLeft: number & tags.Type<"uint32"> & tags.Maximum<9>, // integer and maximum value constrains -}; - -type Dog = { - animalType: "dog", - favouriteDogFoodBrand?: string, -}; - -type Bird = { - animalType: "bird", -}; - -type Pet = (Cat | Dog | Bird) & { - name: string, -}; - -// other possibilities: -// - other built-in formats: email, uuid, url, json pointers, ... -// - check string for regex pattern -// - completely custom constraints for tags - - - -/* json samples */ - -// valid -const SAMPLE_1 = `{ - "username": "meyer.sepp", - "birthdate": "1983-03-28", - "pets": [ - { "animalType": "cat", "name": "Kittykatty", "numberOfLivesLeft": 5 }, - { "animalType": "dog", "name": "Olaf", "favouriteDogFoodBrand": "DogGo!" }, - { "animalType": "bird", "name": "Lori" }, - { "animalType": "bird", "name": "Flori" } - ], - "favouriteTvSeries": "The Office" -}`; - -// missing property `birthdate` -const SAMPLE_2 = `{ - "username": "foofa", - "pets": [ - { "animalType": "dog", "name": "Ludwig" } - ] -}`; - -// additional property `id` -const SAMPLE_3 = `{ - "id": 42, - "username": "IcyToothPaste", - "birthdate": "2001-08-08", - "pets": [ - { "animalType": "cat", "name": "Susi", "numberOfLivesLeft": 9 }, - { "animalType": "cat", "name": "Lolo", "numberOfLivesLeft": 8 } - ] -}`; - -// incorrect values: too short username, malformatted date, invalid -// `animalType`, incorrect value for `numberOfLivesLeft` -const SAMPLE_4 = `{ - "username": "qux", - "birthdate": "04/32/1947", - "pets": [ - { "animalType": "turtle", "name": "Schildi" }, - { "animalType": "cat", "name": "Felix", "numberOfLivesLeft": 11 } - ] -}`; - -const SAMPLES = [SAMPLE_1, SAMPLE_2, SAMPLE_3, SAMPLE_4]; - - - -/* validation */ - -const validator = typia.createValidateEquals(); - -for (const idx in SAMPLES) { - const json = SAMPLES[idx]; - const parsed = JSON.parse(json); - const validationResult = validator(parsed); - - if (validationResult.success) { - console.log(`sample ${idx + 1}: success`); - // here, we can retrieve the actual `User` object with: - // const user = validationResult.data; - } else { - console.log(`sample ${idx + 1}: failure`); - for (const error of validationResult.errors) { - console.log(` - ${error.path}, expected ${error.expected}, found value ${error.value}`); - } - } -} diff --git a/misc/typia-proof-of-concept/tsconfig.json b/misc/typia-proof-of-concept/tsconfig.json deleted file mode 100644 index 8b5f2b6..0000000 --- a/misc/typia-proof-of-concept/tsconfig.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "compilerOptions": { - "target": "es2016", - "module": "commonjs", - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "strict": true, - "skipLibCheck": true, - "rootDir": "src/", - "outDir": "dist/", - "plugins": [ - { - "transform": "typia/lib/transform" - } - ], - "strictNullChecks": true - }, - "include": [ - "src/" - ] -} \ No newline at end of file