Skip to content

Commit

Permalink
Close #1190: adjust optimization logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
samchon committed Aug 2, 2024
1 parent 57df81d commit 60e90c2
Show file tree
Hide file tree
Showing 66 changed files with 2,617 additions and 1,689 deletions.
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@
"suppress-warnings": "^1.0.2",
"tstl": "^3.0.0",
"uuid": "^9.0.1",
"typia": "../typia-6.6.2.tgz"
"typia": "../typia-6.7.0-dev.20240802.tgz"
}
}
34 changes: 0 additions & 34 deletions debug/build.js

This file was deleted.

7 changes: 0 additions & 7 deletions debug/features/tuple.ts

This file was deleted.

8 changes: 4 additions & 4 deletions debug/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ const setup = () => {
};

const execute = () => {
runner.register({
project: __dirname + "/tsconfig.json",
argv: ["--allowPlugins"],
cp.execSync("npx tsc", { cwd: __dirname, stdio: "inherit" });
cp.execSync(`node bin/${process.argv[2]}`, {
cwd: __dirname,
stdio: "inherit",
});
require(`./features/${process.argv[2]}.ts`);
};

supress([() => true]);
Expand Down
8 changes: 5 additions & 3 deletions debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
"main": "index.js",
"scripts": {
"start": "node index",
"prepare": "ts-patch install && typia patch",
"build": "node build"
"prepare": "ts-patch install && typia patch"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/uuid": "^10.0.0",
"ts-node": "^10.9.2",
"ts-patch": "^3.2.0",
"typescript": "^5.4.2"
},
"dependencies": {
"typia": "../typia-6.6.1.tgz"
"tstl": "^3.0.0",
"typia": "../typia-6.7.0-dev.20240802-2.tgz",
"uuid": "^10.0.0"
}
}
15 changes: 15 additions & 0 deletions debug/src/decode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import typia from "typia";

interface IBox3D {
scale: IPoint3D;
position: IPoint3D;
rotate: IPoint3D;
pivot: IPoint3D;
}
interface IPoint3D {
x: number;
y: number;
z: number;
}

() => typia.protobuf.decode<IBox3D>(new Uint8Array());
25 changes: 25 additions & 0 deletions debug/src/form.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import typia from "typia";

import { ObjectHttpFormData } from "./internal/ObjectHttpFormData";
import { create_form_data } from "./internal/create_form_data";

const data: ObjectHttpFormData = ObjectHttpFormData.generate();
const assert = (form: FormData) =>
typia.http.assertFormData<ObjectHttpFormData>(form);
const is = (elem: ObjectHttpFormData): boolean => {
const form: FormData = create_form_data(elem);
try {
assert(form);
return true;
} catch {
return false;
}
};

console.log(is(data));

for (const s of ObjectHttpFormData.SPOILERS) {
const elem: ObjectHttpFormData = ObjectHttpFormData.generate();
const fields = s(elem);
console.log(fields, is(elem));
}
43 changes: 43 additions & 0 deletions debug/src/internal/DynamicTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { tags } from "typia";

import { ArrayUtil } from "typia/lib/utils/ArrayUtil";

import { Spoiler } from "./Spoiler";
import { TestRandomGenerator } from "./TestRandomGenerator";

export interface DynamicTag {
[key: number & tags.Minimum<0> & tags.ExclusiveMaximum<10>]: bigint &
tags.Type<"uint64">;
[key: string & tags.Format<"uuid">]: string & tags.Format<"email">;
}
export namespace DynamicTag {
export const BINARABLE = false;
export const JSONABLE = false;
export const PRIMITIVE = false;
export const ADDABLE = false;

export function generate(): DynamicTag {
const dict: DynamicTag = {};
ArrayUtil.repeat(10, (i) => {
dict[i] = TestRandomGenerator.bigint(0n, 1_000_000n);
dict[TestRandomGenerator.uuid()] = TestRandomGenerator.email();
});
return dict;
}

export const SPOILERS: Spoiler<DynamicTag>[] = [
(input) => {
input[0] = false as any;
return [`$input["0"]`];
},
(input) => {
input[9] = -1n;
return [`$input["9"]`];
},
(input) => {
const uuid: string = TestRandomGenerator.uuid();
input[uuid] = "not-email-address";
return [`$input["${uuid}"]`];
},
];
}
64 changes: 64 additions & 0 deletions debug/src/internal/ObjectHttpFormData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { tags } from "typia";
import { v4 } from "uuid";

import { Spoiler } from "./Spoiler";
import { TestRandomGenerator } from "./TestRandomGenerator";

export interface ObjectHttpFormData {
id: string & tags.Format<"uuid">;
number: number;
integers: Array<number & tags.Type<"int32">>;
blob: Blob;
blobs: Blob[];
file: File;
files: File[];
}
export namespace ObjectHttpFormData {
export const ADDABLE = false;
export const BINARABLE = false;
export const FORMDATA = true;
export const JSONABLE = false;

export function generate(): ObjectHttpFormData {
return {
id: v4(),
number: TestRandomGenerator.number(),
integers: TestRandomGenerator.array(() => TestRandomGenerator.integer()),
blob: new Blob(),
blobs: TestRandomGenerator.array(() => new Blob()),
file: new File([], "file"),
files: TestRandomGenerator.array(() => new File([], "file")),
};
}

export const SPOILERS: Spoiler<ObjectHttpFormData>[] = [
(input) => {
input.id = "something";
return ["$input.id"];
},
(input) => {
input.number = "abcd" as any;
return ["$input.number"];
},
(input) => {
input.integers = [3, 3.14, 3.141592];
return ["$input.integers[1]", "$input.integers[2]"];
},
(input) => {
input.blob = new Uint8Array() as any;
return ["$input.blob"];
},
(input) => {
input.blobs = ["string"] as any;
return ["$input.blobs[0]"];
},
(input) => {
input.file = new Uint8Array() as any;
return ["$input.file"];
},
(input) => {
input.files = [new Uint8Array()] as any;
return ["$input.files[0]"];
},
];
}
3 changes: 3 additions & 0 deletions debug/src/internal/Spoiler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface Spoiler<T> {
(input: T): string[];
}
18 changes: 18 additions & 0 deletions debug/src/internal/TestRandomGenerator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { back_inserter, ranges } from "tstl";
import { RandomGenerator } from "typia/lib/utils/RandomGenerator";

export const TestRandomGenerator = {
...RandomGenerator,
array: <T>(closure: (index: number) => T, count?: number): T[] =>
new Array(count ?? RandomGenerator.integer(3, 10))
.fill(0)
.map((_e, index) => closure(index)),

sample:
<T>(array: T[]) =>
(count: number): T[] => {
const ret: T[] = [];
ranges.sample(array, back_inserter(ret), count);
return ret;
},
};
15 changes: 15 additions & 0 deletions debug/src/internal/create_form_data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const create_form_data = (input: Record<string, any>): FormData => {
const encoded: FormData = new FormData();
for (const [key, value] of Object.entries(input))
if (Array.isArray(value)) value.map(append(encoded)(key));
else append(encoded)(key)(value);
return encoded;
};

const append = (data: FormData) => (key: string) => (value: any) => {
if (value === undefined) return;
else if (value instanceof Blob)
if (value instanceof File) data.append(key, value, value.name);
else data.append(key, value);
else data.append(key, String(value));
};
5 changes: 5 additions & 0 deletions debug/src/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { tags } from "typia";

export interface DynamicTag {
[key: string & tags.Format<"uuid">]: string & tags.Format<"email">;
}
9 changes: 9 additions & 0 deletions debug/src/prune.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import typia from "typia";

import { DynamicTag } from "./internal/DynamicTag";

const data = DynamicTag.generate();
data["__non_regular_type__0"] = "vulnerable";
typia.misc.prune<DynamicTag>(data);

console.log(data);
2 changes: 1 addition & 1 deletion debug/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@
],
},
"include": [
"./features"
"src"
]
}
2 changes: 1 addition & 1 deletion errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"typescript": "^5.3.2"
},
"dependencies": {
"typia": "../typia-6.6.2.tgz"
"typia": "../typia-6.7.0-dev.20240802.tgz"
}
}
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": "6.6.2",
"version": "6.7.0-dev.20240802",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-json/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json",
"version": "6.6.2",
"version": "6.7.0-dev.20240802",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -63,7 +63,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "6.6.2"
"typia": "6.7.0-dev.20240802"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.6.0"
Expand Down
Loading

0 comments on commit 60e90c2

Please sign in to comment.