-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
118 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
bin/ | ||
issues/ | ||
lib/ | ||
measure/ | ||
node_modules/ | ||
/issues/ | ||
|
||
packages/typescript-json/src/ | ||
package-lock.json | ||
|
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,13 @@ | ||
import typia, { tags } from "typia"; | ||
|
||
interface UpdateUserDto { | ||
email: string & tags.Format<"email"> & tags.MaxLength<20>; | ||
dateOfBirth: string & tags.Format<"date">; | ||
} | ||
|
||
console.log( | ||
typia.validateEquals<UpdateUserDto>({ | ||
dateOfBirth: "2023-11-10", | ||
email: "123@gmail.com", | ||
}), | ||
); |
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,4 @@ | ||
import typia, { IJsonApplication } from "typia"; | ||
|
||
const app = typia.json.application<[IJsonApplication]>(); | ||
console.log(Object.keys(app.components.schemas ?? {})); |
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 typia from "typia"; | ||
|
||
import { TypeTagDefault } from "../structures/TypeTagDefault"; | ||
|
||
typia.createIs<TypeTagDefault>(); |
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,28 @@ | ||
import typia, { tags } from "typia"; | ||
|
||
interface CreditCase { | ||
id: number & tags.Type<"uint32">; | ||
company_name: null | string; | ||
email: (string & tags.Format<"email">) | null; | ||
firstname: null | string; | ||
lastname: null | string; | ||
mobile_number: null | string; | ||
phone_number: null | string; | ||
|
||
created_at: Date; | ||
updated_at: Date; | ||
} | ||
|
||
const stringify = typia.json.createAssertStringify<CreditCase>(); | ||
const str: string = stringify({ | ||
id: 1, | ||
company_name: null, | ||
email: null, | ||
firstname: null, | ||
lastname: null, | ||
mobile_number: null, | ||
phone_number: null, | ||
created_at: new Date(), | ||
updated_at: new Date(), | ||
}); | ||
console.log(str); |
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,19 @@ | ||
import typia from "typia"; | ||
|
||
interface Something { | ||
required: string; | ||
optional?: number; | ||
undefindable: boolean | undefined; | ||
both?: string | undefined; | ||
nullable: Something | null; | ||
} | ||
|
||
const app = typia.metadata<[Something]>(); | ||
console.log( | ||
app.collection.objects[0]?.properties.map((p) => ({ | ||
name: p.key.constants[0]?.values[0], | ||
optional: p.value.optional, | ||
required: p.value.required, | ||
nullable: p.value.nullable, | ||
})), | ||
); |
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,16 @@ | ||
import typia from "typia"; | ||
|
||
interface ISomething { | ||
value: number; | ||
} | ||
type P = Partial<ISomething> & { next: string }; | ||
|
||
const app = typia.metadata<[P]>(); | ||
console.log( | ||
app.collection.objects[0]?.properties.map((p) => ({ | ||
name: p.key.constants[0]?.values[0], | ||
optional: p.value.optional, | ||
required: p.value.required, | ||
nullable: p.value.nullable, | ||
})), | ||
); |
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,12 @@ | ||
import typia from "typia"; | ||
|
||
interface ISomething { | ||
value?: number; | ||
} | ||
type P = Required<ISomething>; | ||
|
||
const value = typia.metadata<[P]>().collection.objects[0]?.properties[0]?.value; | ||
console.log({ | ||
optional: value?.optional, | ||
required: value?.required, | ||
}); |
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,20 @@ | ||
import typia, { IJsonApplication, IJsonComponents } from "typia"; | ||
|
||
interface IQuery { | ||
required: string; | ||
nonRequired: string | undefined; | ||
optional?: string; | ||
none?: string | undefined; | ||
} | ||
|
||
const app: IJsonApplication = typia.json.application<[Partial<IQuery>]>(); | ||
const query: IJsonComponents.IObject = app.components.schemas | ||
?.PartialIQuery as IJsonComponents.IObject; | ||
|
||
console.log( | ||
Object.entries(query.properties).map(([key, value]) => [ | ||
key, | ||
value["x-typia-required"], | ||
value["x-typia-optional"], | ||
]), | ||
); |