-
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close #1190: adjust optimization logic.
- Loading branch information
Showing
66 changed files
with
2,617 additions
and
1,689 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"]`]; | ||
}, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]"]; | ||
}, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface Spoiler<T> { | ||
(input: T): string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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">; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,6 @@ | |
], | ||
}, | ||
"include": [ | ||
"./features" | ||
"src" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.