Test case
1 generated file · +1 −1test/inputs/json/misc/016af.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -2,7 +2,7 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 5 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 6 | 6 | "population": z.number().int(), |
| 7 | 7 | }); |
| 8 | 8 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/033b1.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -3,7 +3,7 @@ import * as z from "zod"; | ||
| 3 | 3 | |
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | 5 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 6 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 7 | 7 | "rates": z.record(z.string(), z.number()), |
| 8 | 8 | }); |
| 9 | 9 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +2 −2test/inputs/json/misc/0a358.json
Mtypescript-zoddefault / TopLevel.ts+2 −2
| @@ -7,10 +7,10 @@ export type Facets = z.infer<typeof FacetsSchema>; | ||
| 7 | 7 | |
| 8 | 8 | export const ResultSchema = z.object({ |
| 9 | 9 | "code": z.string(), |
| 10 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 10 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 11 | 11 | "id": z.number().int(), |
| 12 | 12 | "name": z.string(), |
| 13 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 13 | + "updated_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 14 | 14 | "uri": z.string(), |
| 15 | 15 | }); |
| 16 | 16 | export type Result = z.infer<typeof ResultSchema>; |
Test case
1 generated file · +8 −8test/inputs/json/misc/0a91a.json
Mtypescript-zoddefault / TopLevel.ts+8 −8
| @@ -80,7 +80,7 @@ export const BaseRepoSchema = z.object({ | ||
| 80 | 80 | "compare_url": z.string(), |
| 81 | 81 | "contents_url": z.string(), |
| 82 | 82 | "contributors_url": z.string(), |
| 83 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 83 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 84 | 84 | "default_branch": z.string(), |
| 85 | 85 | "deployments_url": z.string(), |
| 86 | 86 | "description": z.null(), |
| @@ -121,7 +121,7 @@ export const BaseRepoSchema = z.object({ | ||
| 121 | 121 | "owner": MergedBySchema, |
| 122 | 122 | "private": z.boolean(), |
| 123 | 123 | "pulls_url": z.string(), |
| 124 | - "pushed_at": z.string().pipe(z.coerce.date()), | |
| 124 | + "pushed_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 125 | 125 | "releases_url": z.string(), |
| 126 | 126 | "size": z.number().int(), |
| 127 | 127 | "ssh_url": z.string(), |
| @@ -134,7 +134,7 @@ export const BaseRepoSchema = z.object({ | ||
| 134 | 134 | "tags_url": z.string(), |
| 135 | 135 | "teams_url": z.string(), |
| 136 | 136 | "trees_url": z.string(), |
| 137 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 137 | + "updated_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 138 | 138 | "url": z.string(), |
| 139 | 139 | "watchers": z.number().int(), |
| 140 | 140 | "watchers_count": z.number().int(), |
| @@ -169,12 +169,12 @@ export const PullRequestSchema = z.object({ | ||
| 169 | 169 | "base": BaseSchema, |
| 170 | 170 | "body": z.string(), |
| 171 | 171 | "changed_files": z.number().int(), |
| 172 | - "closed_at": z.string().pipe(z.coerce.date()), | |
| 172 | + "closed_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 173 | 173 | "comments": z.number().int(), |
| 174 | 174 | "comments_url": z.string(), |
| 175 | 175 | "commits": z.number().int(), |
| 176 | 176 | "commits_url": z.string(), |
| 177 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 177 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 178 | 178 | "deletions": z.number().int(), |
| 179 | 179 | "diff_url": z.string(), |
| 180 | 180 | "head": BaseSchema, |
| @@ -188,7 +188,7 @@ export const PullRequestSchema = z.object({ | ||
| 188 | 188 | "mergeable": z.null(), |
| 189 | 189 | "mergeable_state": z.string(), |
| 190 | 190 | "merged": z.boolean(), |
| 191 | - "merged_at": z.string().pipe(z.coerce.date()), | |
| 191 | + "merged_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 192 | 192 | "merged_by": MergedBySchema, |
| 193 | 193 | "milestone": z.null(), |
| 194 | 194 | "number": z.number().int(), |
| @@ -201,7 +201,7 @@ export const PullRequestSchema = z.object({ | ||
| 201 | 201 | "state": z.string(), |
| 202 | 202 | "statuses_url": z.string(), |
| 203 | 203 | "title": z.string(), |
| 204 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 204 | + "updated_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 205 | 205 | "url": z.string(), |
| 206 | 206 | "user": MergedBySchema, |
| 207 | 207 | }); |
| @@ -227,7 +227,7 @@ export type Payload = z.infer<typeof PayloadSchema>; | ||
| 227 | 227 | |
| 228 | 228 | export const TopLevelElementSchema = z.object({ |
| 229 | 229 | "actor": ActorSchema, |
| 230 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 230 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 231 | 231 | "id": z.string(), |
| 232 | 232 | "org": ActorSchema.optional(), |
| 233 | 233 | "payload": PayloadSchema, |
Test case
1 generated file · +1 −1test/inputs/json/misc/0e0c2.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -80,7 +80,7 @@ export const ResultSchema = z.object({ | ||
| 80 | 80 | "id": z.number().int(), |
| 81 | 81 | "images": z.array(ImageSchema), |
| 82 | 82 | "language": ResultLanguageSchema, |
| 83 | - "release_date": z.string(), | |
| 83 | + "release_date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 84 | 84 | "stars": z.number().int(), |
| 85 | 85 | "tags": z.union([z.null(), z.array(z.any())]), |
| 86 | 86 | "title": z.string(), |
Test case
1 generated file · +1 −1test/inputs/json/misc/167d6.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -3,7 +3,7 @@ import * as z from "zod"; | ||
| 3 | 3 | |
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | 5 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 6 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 7 | 7 | "rates": z.record(z.string(), z.number()), |
| 8 | 8 | }); |
| 9 | 9 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/16bc5.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -106,7 +106,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 106 | 106 | |
| 107 | 107 | export const QuerySchema = z.object({ |
| 108 | 108 | "count": z.number().int(), |
| 109 | - "created": z.string().pipe(z.coerce.date()), | |
| 109 | + "created": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 110 | 110 | "lang": z.string(), |
| 111 | 111 | "results": ResultsSchema, |
| 112 | 112 | }); |
Test case
1 generated file · +1 −1test/inputs/json/misc/1b28c.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -2,7 +2,7 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 5 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 6 | 6 | "population": z.number().int(), |
| 7 | 7 | }); |
| 8 | 8 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +3 −3test/inputs/json/misc/1b409.json
Mtypescript-zoddefault / TopLevel.ts+3 −3
| @@ -70,7 +70,7 @@ export type Extra = z.infer<typeof ExtraSchema>; | ||
| 70 | 70 | |
| 71 | 71 | export const PersonSchema = z.object({ |
| 72 | 72 | "bioguideid": z.string(), |
| 73 | - "birthday": z.string(), | |
| 73 | + "birthday": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 74 | 74 | "cspanid": z.number().int(), |
| 75 | 75 | "firstname": z.string(), |
| 76 | 76 | "gender": GenderSchema, |
| @@ -96,7 +96,7 @@ export const ObjectElementSchema = z.object({ | ||
| 96 | 96 | "current": z.boolean(), |
| 97 | 97 | "description": z.string(), |
| 98 | 98 | "district": z.number().int(), |
| 99 | - "enddate": z.string(), | |
| 99 | + "enddate": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 100 | 100 | "extra": ExtraSchema, |
| 101 | 101 | "id": z.number().int(), |
| 102 | 102 | "leadership_title": z.union([z.null(), z.string()]), |
| @@ -107,7 +107,7 @@ export const ObjectElementSchema = z.object({ | ||
| 107 | 107 | "role_type_label": RoleTypeLabelSchema, |
| 108 | 108 | "senator_class": z.null(), |
| 109 | 109 | "senator_rank": z.null(), |
| 110 | - "startdate": z.string(), | |
| 110 | + "startdate": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 111 | 111 | "state": z.string(), |
| 112 | 112 | "title": TitleSchema, |
| 113 | 113 | "title_long": RoleTypeLabelSchema, |
Test case
1 generated file · +1 −1test/inputs/json/misc/262f0.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -113,7 +113,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 113 | 113 | |
| 114 | 114 | export const QuerySchema = z.object({ |
| 115 | 115 | "count": z.number().int(), |
| 116 | - "created": z.string().pipe(z.coerce.date()), | |
| 116 | + "created": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 117 | 117 | "lang": z.string(), |
| 118 | 118 | "results": ResultsSchema, |
| 119 | 119 | }); |
Test case
1 generated file · +3 −3test/inputs/json/misc/2d4e2.json
Mtypescript-zoddefault / TopLevel.ts+3 −3
| @@ -96,7 +96,7 @@ export type Extra = z.infer<typeof ExtraSchema>; | ||
| 96 | 96 | |
| 97 | 97 | export const PersonSchema = z.object({ |
| 98 | 98 | "bioguideid": z.string(), |
| 99 | - "birthday": z.string(), | |
| 99 | + "birthday": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 100 | 100 | "cspanid": z.number().int(), |
| 101 | 101 | "firstname": z.string(), |
| 102 | 102 | "gender": GenderSchema, |
| @@ -122,7 +122,7 @@ export const ObjectElementSchema = z.object({ | ||
| 122 | 122 | "current": z.boolean(), |
| 123 | 123 | "description": z.string(), |
| 124 | 124 | "district": z.null(), |
| 125 | - "enddate": z.string(), | |
| 125 | + "enddate": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 126 | 126 | "extra": ExtraSchema, |
| 127 | 127 | "id": z.number().int(), |
| 128 | 128 | "leadership_title": z.union([z.null(), z.string()]), |
| @@ -135,7 +135,7 @@ export const ObjectElementSchema = z.object({ | ||
| 135 | 135 | "senator_class_label": SenatorClassLabelSchema, |
| 136 | 136 | "senator_rank": SenatorRankSchema, |
| 137 | 137 | "senator_rank_label": SenatorRankLabelSchema, |
| 138 | - "startdate": z.string(), | |
| 138 | + "startdate": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 139 | 139 | "state": z.string(), |
| 140 | 140 | "title": TitleSchema, |
| 141 | 141 | "title_long": RoleTypeLabelSchema, |
Test case
1 generated file · +6 −1test/inputs/json/misc/31189.json
Mtypescript-zoddefault / TopLevel.ts+6 −1
| @@ -1,6 +1,11 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | +export const EffectiveFromEnumSchema = z.enum([ | |
| 5 | + "0000-01-01", | |
| 6 | +]); | |
| 7 | +export type EffectiveFromEnum = z.infer<typeof EffectiveFromEnumSchema>; | |
| 8 | + | |
| 4 | 9 | export const RatesSchema = z.object({ |
| 5 | 10 | "parking": z.number().optional(), |
| 6 | 11 | "reduced": z.number().optional(), |
| @@ -12,7 +17,7 @@ export const RatesSchema = z.object({ | ||
| 12 | 17 | export type Rates = z.infer<typeof RatesSchema>; |
| 13 | 18 | |
| 14 | 19 | export const PeriodSchema = z.object({ |
| 15 | - "effective_from": z.string(), | |
| 20 | + "effective_from": z.union([z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), EffectiveFromEnumSchema]), | |
| 16 | 21 | "rates": RatesSchema, |
| 17 | 22 | }); |
| 18 | 23 | export type Period = z.infer<typeof PeriodSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/32d5c.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -2,7 +2,7 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TopLevelElementSchema = z.object({ |
| 5 | - "BirthDate": z.union([z.null(), z.string().pipe(z.coerce.date())]), | |
| 5 | + "BirthDate": z.union([z.null(), z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date())]), | |
| 6 | 6 | "BirthDateIsProtected": z.boolean(), |
| 7 | 7 | "GenderTypeID": z.number().int(), |
| 8 | 8 | "Notes": z.string(), |
Test case
1 generated file · +6 −6test/inputs/json/misc/337ed.json
Mtypescript-zoddefault / TopLevel.ts+6 −6
| @@ -28,12 +28,12 @@ export type Facets = z.infer<typeof FacetsSchema>; | ||
| 28 | 28 | |
| 29 | 29 | export const CustomIncomeSchema = z.object({ |
| 30 | 30 | "amount": z.number().int(), |
| 31 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 31 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 32 | 32 | "id": z.string(), |
| 33 | 33 | "name": z.string(), |
| 34 | 34 | "status": StatusSchema, |
| 35 | 35 | "type": CustomIncomeTypeSchema, |
| 36 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 36 | + "updated_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 37 | 37 | "uri": z.string(), |
| 38 | 38 | }); |
| 39 | 39 | export type CustomIncome = z.infer<typeof CustomIncomeSchema>; |
| @@ -42,11 +42,11 @@ export const ResultSchema = z.object({ | ||
| 42 | 42 | "cost_absolute": z.union([z.null(), z.number().int()]), |
| 43 | 43 | "cost_max": z.union([z.null(), z.number().int()]), |
| 44 | 44 | "cost_min": z.union([z.null(), z.number().int()]), |
| 45 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 45 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 46 | 46 | "customIncomes": z.array(CustomIncomeSchema), |
| 47 | 47 | "direct_rep_costs_max": z.null(), |
| 48 | 48 | "direct_rep_costs_min": z.null(), |
| 49 | - "end_date": z.string().pipe(z.coerce.date()), | |
| 49 | + "end_date": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 50 | 50 | "eur_sources_grants": z.number().int(), |
| 51 | 51 | "eur_sources_grants_src": z.union([z.null(), z.string()]), |
| 52 | 52 | "eur_sources_procurement": z.number().int(), |
| @@ -62,14 +62,14 @@ export const ResultSchema = z.object({ | ||
| 62 | 62 | "public_financing_national": z.union([z.null(), z.number().int()]), |
| 63 | 63 | "public_financing_total": z.union([z.null(), z.number().int()]), |
| 64 | 64 | "representative": z.string(), |
| 65 | - "start_date": z.string().pipe(z.coerce.date()), | |
| 65 | + "start_date": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 66 | 66 | "status": StatusSchema, |
| 67 | 67 | "total_budget": z.union([z.null(), z.number().int()]), |
| 68 | 68 | "turnover_absolute": z.union([z.null(), z.number().int()]), |
| 69 | 69 | "turnover_max": z.union([z.null(), z.number().int()]), |
| 70 | 70 | "turnover_min": z.union([z.null(), z.number().int()]), |
| 71 | 71 | "type": ResultTypeSchema, |
| 72 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 72 | + "updated_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 73 | 73 | "uri": z.string(), |
| 74 | 74 | }); |
| 75 | 75 | export type Result = z.infer<typeof ResultSchema>; |
Test case
1 generated file · +10 −2test/inputs/json/misc/33d2e.json
Mtypescript-zoddefault / TopLevel.ts+10 −2
| @@ -1,6 +1,14 @@ | ||
| 1 | 1 | import * as z from "zod"; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | +export const BornEnumSchema = z.enum([ | |
| 5 | + "0000-00-00", | |
| 6 | + "1898-00-00", | |
| 7 | + "1943-00-00", | |
| 8 | +]); | |
| 9 | +export type BornEnum = z.infer<typeof BornEnumSchema>; | |
| 10 | + | |
| 11 | + | |
| 4 | 12 | export const GenderSchema = z.enum([ |
| 5 | 13 | "male", |
| 6 | 14 | "female", |
| @@ -37,11 +45,11 @@ export const PrizeSchema = z.object({ | ||
| 37 | 45 | export type Prize = z.infer<typeof PrizeSchema>; |
| 38 | 46 | |
| 39 | 47 | export const LaureateSchema = z.object({ |
| 40 | - "born": z.string(), | |
| 48 | + "born": z.union([z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), BornEnumSchema]), | |
| 41 | 49 | "bornCity": z.string().optional(), |
| 42 | 50 | "bornCountry": z.string().optional(), |
| 43 | 51 | "bornCountryCode": z.string().optional(), |
| 44 | - "died": z.string(), | |
| 52 | + "died": z.union([z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), BornEnumSchema]), | |
| 45 | 53 | "diedCity": z.string().optional(), |
| 46 | 54 | "diedCountry": z.string().optional(), |
| 47 | 55 | "diedCountryCode": z.string().optional(), |
Test case
1 generated file · +1 −1test/inputs/json/misc/3659d.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -2,7 +2,7 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 5 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 6 | 6 | "population": z.number().int(), |
| 7 | 7 | }); |
| 8 | 8 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/3f1ce.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -111,7 +111,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 111 | 111 | |
| 112 | 112 | export const QuerySchema = z.object({ |
| 113 | 113 | "count": z.number().int(), |
| 114 | - "created": z.string().pipe(z.coerce.date()), | |
| 114 | + "created": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 115 | 115 | "lang": z.string(), |
| 116 | 116 | "results": ResultsSchema, |
| 117 | 117 | }); |
Test case
1 generated file · +1 −1test/inputs/json/misc/43eaf.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -3,7 +3,7 @@ import * as z from "zod"; | ||
| 3 | 3 | |
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | 5 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 6 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 7 | 7 | "rates": z.record(z.string(), z.number()), |
| 8 | 8 | }); |
| 9 | 9 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/4961a.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -2,7 +2,7 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 5 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 6 | 6 | "population": z.number().int(), |
| 7 | 7 | }); |
| 8 | 8 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/4a0d7.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -2,7 +2,7 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 5 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 6 | 6 | "population": z.number().int(), |
| 7 | 7 | }); |
| 8 | 8 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/4c547.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -106,7 +106,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 106 | 106 | |
| 107 | 107 | export const QuerySchema = z.object({ |
| 108 | 108 | "count": z.number().int(), |
| 109 | - "created": z.string().pipe(z.coerce.date()), | |
| 109 | + "created": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 110 | 110 | "lang": z.string(), |
| 111 | 111 | "results": ResultsSchema, |
| 112 | 112 | }); |
Test case
1 generated file · +1 −1test/inputs/json/misc/4e336.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -2,7 +2,7 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 5 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 6 | 6 | "population": z.number().int(), |
| 7 | 7 | }); |
| 8 | 8 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +2 −2test/inputs/json/misc/54d32.json
Mtypescript-zoddefault / TopLevel.ts+2 −2
| @@ -12,12 +12,12 @@ export const FacetsSchema = z.object({ | ||
| 12 | 12 | export type Facets = z.infer<typeof FacetsSchema>; |
| 13 | 13 | |
| 14 | 14 | export const ResultSchema = z.object({ |
| 15 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 15 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 16 | 16 | "id": z.string(), |
| 17 | 17 | "person_id": z.string(), |
| 18 | 18 | "representative_id": z.string(), |
| 19 | 19 | "status": StatusSchema, |
| 20 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 20 | + "updated_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 21 | 21 | }); |
| 22 | 22 | export type Result = z.infer<typeof ResultSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/5eae5.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -2,7 +2,7 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TopLevelElementSchema = z.object({ |
| 5 | - "Date": z.string().pipe(z.coerce.date()), | |
| 5 | + "Date": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 6 | 6 | "ID": z.number().int(), |
| 7 | 7 | "Sponsor": z.string(), |
| 8 | 8 | "Title": z.string(), |
Test case
1 generated file · +1 −1test/inputs/json/misc/5f3a1.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -3,7 +3,7 @@ import * as z from "zod"; | ||
| 3 | 3 | |
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | 5 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 6 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 7 | 7 | "rates": z.record(z.string(), z.number()), |
| 8 | 8 | }); |
| 9 | 9 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/6260a.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -3,7 +3,7 @@ import * as z from "zod"; | ||
| 3 | 3 | |
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | 5 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 6 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 7 | 7 | "rates": z.record(z.string(), z.number()), |
| 8 | 8 | }); |
| 9 | 9 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +2 −2test/inputs/json/misc/65dec.json
Mtypescript-zoddefault / TopLevel.ts+2 −2
| @@ -61,7 +61,7 @@ export const LegalityElementSchema = z.object({ | ||
| 61 | 61 | export type LegalityElement = z.infer<typeof LegalityElementSchema>; |
| 62 | 62 | |
| 63 | 63 | export const RulingSchema = z.object({ |
| 64 | - "date": z.string(), | |
| 64 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 65 | 65 | "text": z.string(), |
| 66 | 66 | }); |
| 67 | 67 | export type Ruling = z.infer<typeof RulingSchema>; |
| @@ -108,7 +108,7 @@ export const TopLevelSchema = z.object({ | ||
| 108 | 108 | "mkm_id": z.number().int(), |
| 109 | 109 | "mkm_name": z.string(), |
| 110 | 110 | "name": z.string(), |
| 111 | - "releaseDate": z.string(), | |
| 111 | + "releaseDate": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 112 | 112 | "type": z.string(), |
| 113 | 113 | }); |
| 114 | 114 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/6dec6.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -113,7 +113,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 113 | 113 | |
| 114 | 114 | export const QuerySchema = z.object({ |
| 115 | 115 | "count": z.number().int(), |
| 116 | - "created": z.string().pipe(z.coerce.date()), | |
| 116 | + "created": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 117 | 117 | "lang": z.string(), |
| 118 | 118 | "results": ResultsSchema, |
| 119 | 119 | }); |
Test case
1 generated file · +1 −1test/inputs/json/misc/70c77.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -3,7 +3,7 @@ import * as z from "zod"; | ||
| 3 | 3 | |
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | 5 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 6 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 7 | 7 | "rates": z.record(z.string(), z.number()), |
| 8 | 8 | }); |
| 9 | 9 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +4 −4test/inputs/json/misc/734ad.json
Mtypescript-zoddefault / TopLevel.ts+4 −4
| @@ -31,7 +31,7 @@ export const ResultSchema = z.object({ | ||
| 31 | 31 | "be_office_town": z.string().optional(), |
| 32 | 32 | "code_of_conduct": z.string(), |
| 33 | 33 | "contact_country": z.number().int(), |
| 34 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 34 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 35 | 35 | "entity": z.string(), |
| 36 | 36 | "goals": z.string(), |
| 37 | 37 | "head": z.string(), |
| @@ -46,7 +46,7 @@ export const ResultSchema = z.object({ | ||
| 46 | 46 | "id": z.string(), |
| 47 | 47 | "identification_code": z.string(), |
| 48 | 48 | "info_members": z.string(), |
| 49 | - "last_update_date": z.string().pipe(z.coerce.date()), | |
| 49 | + "last_update_date": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 50 | 50 | "legal": z.string(), |
| 51 | 51 | "legal_status": z.string(), |
| 52 | 52 | "main_category": z.number().int(), |
| @@ -62,12 +62,12 @@ export const ResultSchema = z.object({ | ||
| 62 | 62 | "networking": z.union([z.null(), z.string()]), |
| 63 | 63 | "number_of_natural_persons": z.union([z.null(), z.number().int()]), |
| 64 | 64 | "other_code_of_conduct": z.union([z.null(), z.string()]), |
| 65 | - "registration_date": z.string().pipe(z.coerce.date()), | |
| 65 | + "registration_date": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 66 | 66 | "status": StatusSchema, |
| 67 | 67 | "structure_members": z.string(), |
| 68 | 68 | "sub_category": z.number().int(), |
| 69 | 69 | "sub_category_title": z.string(), |
| 70 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 70 | + "updated_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 71 | 71 | "uri": z.string(), |
| 72 | 72 | "web_site_url": z.union([z.null(), z.string()]), |
| 73 | 73 | }); |
Test case
1 generated file · +1 −1test/inputs/json/misc/75912.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -3,7 +3,7 @@ import * as z from "zod"; | ||
| 3 | 3 | |
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | 5 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 6 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 7 | 7 | "rates": z.record(z.string(), z.number()), |
| 8 | 8 | }); |
| 9 | 9 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/77392.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -24,7 +24,7 @@ export type Pha = z.infer<typeof PhaSchema>; | ||
| 24 | 24 | |
| 25 | 25 | export const TopLevelElementSchema = z.object({ |
| 26 | 26 | "designation": z.string(), |
| 27 | - "discovery_date": z.string().pipe(z.coerce.date()), | |
| 27 | + "discovery_date": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 28 | 28 | "h_mag": z.string().optional(), |
| 29 | 29 | "i_deg": z.string(), |
| 30 | 30 | "moid_au": z.string(), |
Test case
1 generated file · +1 −1test/inputs/json/misc/7dfa6.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -2,7 +2,7 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 5 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 6 | 6 | "population": z.number().int(), |
| 7 | 7 | }); |
| 8 | 8 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +2 −2test/inputs/json/misc/7f568.json
Mtypescript-zoddefault / TopLevel.ts+2 −2
| @@ -25,7 +25,7 @@ export const TopLevelElementSchema = z.object({ | ||
| 25 | 25 | "comments": z.number().int(), |
| 26 | 26 | "comments_url": z.string(), |
| 27 | 27 | "commits_url": z.string(), |
| 28 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 28 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 29 | 29 | "description": z.union([z.null(), z.string()]), |
| 30 | 30 | "files": z.record(z.string(), FileSchema), |
| 31 | 31 | "forks_url": z.string(), |
| @@ -35,7 +35,7 @@ export const TopLevelElementSchema = z.object({ | ||
| 35 | 35 | "id": z.string(), |
| 36 | 36 | "public": z.boolean(), |
| 37 | 37 | "truncated": z.boolean(), |
| 38 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 38 | + "updated_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 39 | 39 | "url": z.string(), |
| 40 | 40 | "user": z.null(), |
| 41 | 41 | }); |
Test case
1 generated file · +2 −2test/inputs/json/misc/80aff.json
Mtypescript-zoddefault / TopLevel.ts+2 −2
| @@ -6,12 +6,12 @@ export const FacetsSchema = z.object({ | ||
| 6 | 6 | export type Facets = z.infer<typeof FacetsSchema>; |
| 7 | 7 | |
| 8 | 8 | export const ResultSchema = z.object({ |
| 9 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 9 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 10 | 10 | "id": z.number().int(), |
| 11 | 11 | "items": z.number().int(), |
| 12 | 12 | "name": z.string(), |
| 13 | 13 | "parent": z.union([z.null(), z.number().int()]), |
| 14 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 14 | + "updated_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 15 | 15 | "uri": z.string(), |
| 16 | 16 | }); |
| 17 | 17 | export type Result = z.infer<typeof ResultSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/88130.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -106,7 +106,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 106 | 106 | |
| 107 | 107 | export const QuerySchema = z.object({ |
| 108 | 108 | "count": z.number().int(), |
| 109 | - "created": z.string().pipe(z.coerce.date()), | |
| 109 | + "created": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 110 | 110 | "lang": z.string(), |
| 111 | 111 | "results": ResultsSchema, |
| 112 | 112 | }); |
Test case
1 generated file · +1 −1test/inputs/json/misc/8a62c.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -2,7 +2,7 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 5 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 6 | 6 | "population": z.number().int(), |
| 7 | 7 | }); |
| 8 | 8 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/9617f.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -3,7 +3,7 @@ import * as z from "zod"; | ||
| 3 | 3 | |
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | 5 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 6 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 7 | 7 | "rates": z.record(z.string(), z.number()), |
| 8 | 8 | }); |
| 9 | 9 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/9929c.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -106,7 +106,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 106 | 106 | |
| 107 | 107 | export const QuerySchema = z.object({ |
| 108 | 108 | "count": z.number().int(), |
| 109 | - "created": z.string().pipe(z.coerce.date()), | |
| 109 | + "created": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 110 | 110 | "lang": z.string(), |
| 111 | 111 | "results": ResultsSchema, |
| 112 | 112 | }); |
Test case
1 generated file · +2 −2test/inputs/json/misc/9ac3b.json
Mtypescript-zoddefault / TopLevel.ts+2 −2
| @@ -19,7 +19,7 @@ export const FacetsSchema = z.object({ | ||
| 19 | 19 | export type Facets = z.infer<typeof FacetsSchema>; |
| 20 | 20 | |
| 21 | 21 | export const ResultSchema = z.object({ |
| 22 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 22 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 23 | 23 | "entity": z.string(), |
| 24 | 24 | "first_name": z.string(), |
| 25 | 25 | "id": z.string(), |
| @@ -28,7 +28,7 @@ export const ResultSchema = z.object({ | ||
| 28 | 28 | "position": z.union([z.null(), z.string()]), |
| 29 | 29 | "status": StatusSchema, |
| 30 | 30 | "title": z.union([z.null(), TitleSchema]), |
| 31 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 31 | + "updated_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 32 | 32 | "uri": z.string(), |
| 33 | 33 | }); |
| 34 | 34 | export type Result = z.infer<typeof ResultSchema>; |
Test case
1 generated file · +4 −4test/inputs/json/misc/a0496.json
Mtypescript-zoddefault / TopLevel.ts+4 −4
| @@ -8,20 +8,20 @@ export type Errors = z.infer<typeof ErrorsSchema>; | ||
| 8 | 8 | export const TopLevelSchema = z.object({ |
| 9 | 9 | "code": z.string(), |
| 10 | 10 | "column_names": z.array(z.string()), |
| 11 | - "data": z.array(z.array(z.union([z.null(), z.number(), z.string()]))), | |
| 11 | + "data": z.array(z.array(z.union([z.null(), z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), z.number()]))), | |
| 12 | 12 | "description": z.string(), |
| 13 | 13 | "display_url": z.string(), |
| 14 | 14 | "errors": ErrorsSchema, |
| 15 | 15 | "frequency": z.string(), |
| 16 | - "from_date": z.string(), | |
| 16 | + "from_date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 17 | 17 | "id": z.number().int(), |
| 18 | 18 | "name": z.string(), |
| 19 | 19 | "premium": z.boolean(), |
| 20 | 20 | "source_code": z.string(), |
| 21 | 21 | "source_name": z.string(), |
| 22 | - "to_date": z.string(), | |
| 22 | + "to_date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 23 | 23 | "type": z.string(), |
| 24 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 24 | + "updated_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 25 | 25 | "urlize_name": z.string(), |
| 26 | 26 | }); |
| 27 | 27 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/a1eca.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -106,7 +106,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 106 | 106 | |
| 107 | 107 | export const QuerySchema = z.object({ |
| 108 | 108 | "count": z.number().int(), |
| 109 | - "created": z.string().pipe(z.coerce.date()), | |
| 109 | + "created": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 110 | 110 | "lang": z.string(), |
| 111 | 111 | "results": ResultsSchema, |
| 112 | 112 | }); |
Test case
1 generated file · +1 −1test/inputs/json/misc/a9691.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -3,7 +3,7 @@ import * as z from "zod"; | ||
| 3 | 3 | |
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | 5 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 6 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 7 | 7 | "rates": z.record(z.string(), z.number()), |
| 8 | 8 | }); |
| 9 | 9 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/abb4b.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -2,7 +2,7 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 5 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 6 | 6 | "population": z.number().int(), |
| 7 | 7 | }); |
| 8 | 8 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/ac944.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -3,7 +3,7 @@ import * as z from "zod"; | ||
| 3 | 3 | |
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | 5 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 6 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 7 | 7 | "rates": z.record(z.string(), z.number()), |
| 8 | 8 | }); |
| 9 | 9 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/b4865.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -37,7 +37,7 @@ export const TopLevelElementSchema = z.object({ | ||
| 37 | 37 | "recclass": z.string(), |
| 38 | 38 | "reclat": z.string().optional(), |
| 39 | 39 | "reclong": z.string().optional(), |
| 40 | - "year": z.string().pipe(z.coerce.date()).optional(), | |
| 40 | + "year": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()).optional(), | |
| 41 | 41 | }); |
| 42 | 42 | export type TopLevelElement = z.infer<typeof TopLevelElementSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/b6f2c.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -2,7 +2,7 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 5 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 6 | 6 | "population": z.number().int(), |
| 7 | 7 | }); |
| 8 | 8 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/bb1ec.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -2,7 +2,7 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 5 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 6 | 6 | "population": z.number().int(), |
| 7 | 7 | }); |
| 8 | 8 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/cd463.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -3,7 +3,7 @@ import * as z from "zod"; | ||
| 3 | 3 | |
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | 5 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 6 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 7 | 7 | "rates": z.record(z.string(), z.number()), |
| 8 | 8 | }); |
| 9 | 9 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/cf0d8.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -106,7 +106,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 106 | 106 | |
| 107 | 107 | export const QuerySchema = z.object({ |
| 108 | 108 | "count": z.number().int(), |
| 109 | - "created": z.string().pipe(z.coerce.date()), | |
| 109 | + "created": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 110 | 110 | "lang": z.string(), |
| 111 | 111 | "results": ResultsSchema, |
| 112 | 112 | }); |
Test case
1 generated file · +1 −1test/inputs/json/misc/cfbce.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -3,7 +3,7 @@ import * as z from "zod"; | ||
| 3 | 3 | |
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | 5 | "base": z.string(), |
| 6 | - "date": z.string(), | |
| 6 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 7 | 7 | "rates": z.record(z.string(), z.number()), |
| 8 | 8 | }); |
| 9 | 9 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/d0908.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -2,7 +2,7 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TotalPopulationSchema = z.object({ |
| 5 | - "date": z.string(), | |
| 5 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 6 | 6 | "population": z.number().int(), |
| 7 | 7 | }); |
| 8 | 8 | export type TotalPopulation = z.infer<typeof TotalPopulationSchema>; |
Test case
1 generated file · +2 −2test/inputs/json/misc/d23d5.json
Mtypescript-zoddefault / TopLevel.ts+2 −2
| @@ -7,10 +7,10 @@ export type Facets = z.infer<typeof FacetsSchema>; | ||
| 7 | 7 | |
| 8 | 8 | export const ResultSchema = z.object({ |
| 9 | 9 | "acronym": z.union([z.null(), z.string()]), |
| 10 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 10 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 11 | 11 | "id": z.string(), |
| 12 | 12 | "name": z.string(), |
| 13 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 13 | + "updated_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 14 | 14 | "uri": z.string(), |
| 15 | 15 | }); |
| 16 | 16 | export type Result = z.infer<typeof ResultSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/dbfb3.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -112,7 +112,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 112 | 112 | |
| 113 | 113 | export const QuerySchema = z.object({ |
| 114 | 114 | "count": z.number().int(), |
| 115 | - "created": z.string().pipe(z.coerce.date()), | |
| 115 | + "created": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 116 | 116 | "lang": z.string(), |
| 117 | 117 | "results": ResultsSchema, |
| 118 | 118 | }); |
Test case
1 generated file · +2 −2test/inputs/json/misc/dc44f.json
Mtypescript-zoddefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ export const LegalityElementSchema = z.object({ | ||
| 110 | 110 | export type LegalityElement = z.infer<typeof LegalityElementSchema>; |
| 111 | 111 | |
| 112 | 112 | export const RulingSchema = z.object({ |
| 113 | - "date": z.string(), | |
| 113 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 114 | 114 | "text": z.string(), |
| 115 | 115 | }); |
| 116 | 116 | export type Ruling = z.infer<typeof RulingSchema>; |
| @@ -156,7 +156,7 @@ export const TopLevelSchema = z.object({ | ||
| 156 | 156 | "mkm_id": z.number().int(), |
| 157 | 157 | "mkm_name": z.string(), |
| 158 | 158 | "name": z.string(), |
| 159 | - "releaseDate": z.string(), | |
| 159 | + "releaseDate": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 160 | 160 | "type": z.string(), |
| 161 | 161 | }); |
| 162 | 162 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +2 −2test/inputs/json/misc/dd1ce.json
Mtypescript-zoddefault / TopLevel.ts+2 −2
| @@ -110,7 +110,7 @@ export const LegalityElementSchema = z.object({ | ||
| 110 | 110 | export type LegalityElement = z.infer<typeof LegalityElementSchema>; |
| 111 | 111 | |
| 112 | 112 | export const RulingSchema = z.object({ |
| 113 | - "date": z.string(), | |
| 113 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 114 | 114 | "text": z.string(), |
| 115 | 115 | }); |
| 116 | 116 | export type Ruling = z.infer<typeof RulingSchema>; |
| @@ -156,7 +156,7 @@ export const TopLevelSchema = z.object({ | ||
| 156 | 156 | "mkm_id": z.number().int(), |
| 157 | 157 | "mkm_name": z.string(), |
| 158 | 158 | "name": z.string(), |
| 159 | - "releaseDate": z.string(), | |
| 159 | + "releaseDate": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 160 | 160 | "type": z.string(), |
| 161 | 161 | }); |
| 162 | 162 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/misc/df957.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -106,7 +106,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 106 | 106 | |
| 107 | 107 | export const QuerySchema = z.object({ |
| 108 | 108 | "count": z.number().int(), |
| 109 | - "created": z.string().pipe(z.coerce.date()), | |
| 109 | + "created": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 110 | 110 | "lang": z.string(), |
| 111 | 111 | "results": ResultsSchema, |
| 112 | 112 | }); |
Test case
1 generated file · +1 −1test/inputs/json/misc/e2915.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -111,7 +111,7 @@ export type Results = z.infer<typeof ResultsSchema>; | ||
| 111 | 111 | |
| 112 | 112 | export const QuerySchema = z.object({ |
| 113 | 113 | "count": z.number().int(), |
| 114 | - "created": z.string().pipe(z.coerce.date()), | |
| 114 | + "created": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 115 | 115 | "lang": z.string(), |
| 116 | 116 | "results": ResultsSchema, |
| 117 | 117 | }); |
Test case
1 generated file · +2 −2test/inputs/json/priority/bug2590.json
Mtypescript-zoddefault / TopLevel.ts+2 −2
| @@ -2,8 +2,8 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const InvoiceSchema = z.object({ |
| 5 | - "createdAt": z.union([z.null(), z.string().pipe(z.coerce.date())]), | |
| 6 | - "dueDate": z.union([z.null(), z.string()]), | |
| 5 | + "createdAt": z.union([z.null(), z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date())]), | |
| 6 | + "dueDate": z.union([z.null(), z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value)]), | |
| 7 | 7 | "name": z.string(), |
| 8 | 8 | }); |
| 9 | 9 | export type Invoice = z.infer<typeof InvoiceSchema>; |
Test case
1 generated file · +2 −2test/inputs/json/priority/bug2663.json
Mtypescript-zoddefault / TopLevel.ts+2 −2
| @@ -2,8 +2,8 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | - "birthday": z.string(), | |
| 6 | - "lastSeen": z.string().pipe(z.coerce.date()), | |
| 5 | + "birthday": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 6 | + "lastSeen": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 7 | 7 | "name": z.string(), |
| 8 | 8 | }); |
| 9 | 9 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +1 −1test/inputs/json/priority/keywords.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -348,7 +348,7 @@ export const DateParseHandlingSchema = z.object({ | ||
| 348 | 348 | export type DateParseHandling = z.infer<typeof DateParseHandlingSchema>; |
| 349 | 349 | |
| 350 | 350 | export const DateTimeSchema = z.object({ |
| 351 | - "DateTime": z.string().pipe(z.coerce.date()), | |
| 351 | + "DateTime": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 352 | 352 | }); |
| 353 | 353 | export type DateTime = z.infer<typeof DateTimeSchema>; |
Test case
1 generated file · +16 −16test/inputs/json/samples/github-events.json
Mtypescript-zoddefault / TopLevel.ts+16 −16
| @@ -56,10 +56,10 @@ export type Label = z.infer<typeof LabelSchema>; | ||
| 56 | 56 | export const MilestoneSchema = z.object({ |
| 57 | 57 | "closed_at": z.null(), |
| 58 | 58 | "closed_issues": z.number().int(), |
| 59 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 59 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 60 | 60 | "creator": UserSchema, |
| 61 | 61 | "description": z.string(), |
| 62 | - "due_on": z.union([z.null(), z.string().pipe(z.coerce.date())]), | |
| 62 | + "due_on": z.union([z.null(), z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date())]), | |
| 63 | 63 | "html_url": z.string(), |
| 64 | 64 | "id": z.number().int(), |
| 65 | 65 | "labels_url": z.string(), |
| @@ -67,7 +67,7 @@ export const MilestoneSchema = z.object({ | ||
| 67 | 67 | "open_issues": z.number().int(), |
| 68 | 68 | "state": z.string(), |
| 69 | 69 | "title": z.string(), |
| 70 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 70 | + "updated_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 71 | 71 | "url": z.string(), |
| 72 | 72 | }); |
| 73 | 73 | export type Milestone = z.infer<typeof MilestoneSchema>; |
| @@ -92,7 +92,7 @@ export const BaseRepoSchema = z.object({ | ||
| 92 | 92 | "compare_url": z.string(), |
| 93 | 93 | "contents_url": z.string(), |
| 94 | 94 | "contributors_url": z.string(), |
| 95 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 95 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 96 | 96 | "default_branch": z.string(), |
| 97 | 97 | "deployments_url": z.string(), |
| 98 | 98 | "description": z.string(), |
| @@ -133,7 +133,7 @@ export const BaseRepoSchema = z.object({ | ||
| 133 | 133 | "owner": UserSchema, |
| 134 | 134 | "private": z.boolean(), |
| 135 | 135 | "pulls_url": z.string(), |
| 136 | - "pushed_at": z.string().pipe(z.coerce.date()), | |
| 136 | + "pushed_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 137 | 137 | "releases_url": z.string(), |
| 138 | 138 | "size": z.number().int(), |
| 139 | 139 | "ssh_url": z.string(), |
| @@ -146,7 +146,7 @@ export const BaseRepoSchema = z.object({ | ||
| 146 | 146 | "tags_url": z.string(), |
| 147 | 147 | "teams_url": z.string(), |
| 148 | 148 | "trees_url": z.string(), |
| 149 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 149 | + "updated_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 150 | 150 | "url": z.string(), |
| 151 | 151 | "watchers": z.number().int(), |
| 152 | 152 | "watchers_count": z.number().int(), |
| @@ -167,11 +167,11 @@ export type TopLevelRepo = z.infer<typeof TopLevelRepoSchema>; | ||
| 167 | 167 | |
| 168 | 168 | export const CommentSchema = z.object({ |
| 169 | 169 | "body": z.string(), |
| 170 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 170 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 171 | 171 | "html_url": z.string(), |
| 172 | 172 | "id": z.number().int(), |
| 173 | 173 | "issue_url": z.string(), |
| 174 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 174 | + "updated_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 175 | 175 | "url": z.string(), |
| 176 | 176 | "user": UserSchema, |
| 177 | 177 | }); |
| @@ -190,10 +190,10 @@ export const IssueSchema = z.object({ | ||
| 190 | 190 | "assignee": z.null(), |
| 191 | 191 | "assignees": z.array(z.any()), |
| 192 | 192 | "body": z.string(), |
| 193 | - "closed_at": z.union([z.null(), z.string().pipe(z.coerce.date())]), | |
| 193 | + "closed_at": z.union([z.null(), z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date())]), | |
| 194 | 194 | "comments": z.number().int(), |
| 195 | 195 | "comments_url": z.string(), |
| 196 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 196 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 197 | 197 | "events_url": z.string(), |
| 198 | 198 | "html_url": z.string(), |
| 199 | 199 | "id": z.number().int(), |
| @@ -206,7 +206,7 @@ export const IssueSchema = z.object({ | ||
| 206 | 206 | "repository_url": z.string(), |
| 207 | 207 | "state": z.string(), |
| 208 | 208 | "title": z.string(), |
| 209 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 209 | + "updated_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 210 | 210 | "url": z.string(), |
| 211 | 211 | "user": UserSchema, |
| 212 | 212 | }); |
| @@ -240,12 +240,12 @@ export const PayloadPullRequestSchema = z.object({ | ||
| 240 | 240 | "base": BaseSchema, |
| 241 | 241 | "body": z.string(), |
| 242 | 242 | "changed_files": z.number().int(), |
| 243 | - "closed_at": z.string().pipe(z.coerce.date()), | |
| 243 | + "closed_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 244 | 244 | "comments": z.number().int(), |
| 245 | 245 | "comments_url": z.string(), |
| 246 | 246 | "commits": z.number().int(), |
| 247 | 247 | "commits_url": z.string(), |
| 248 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 248 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 249 | 249 | "deletions": z.number().int(), |
| 250 | 250 | "diff_url": z.string(), |
| 251 | 251 | "head": BaseSchema, |
| @@ -259,7 +259,7 @@ export const PayloadPullRequestSchema = z.object({ | ||
| 259 | 259 | "mergeable": z.null(), |
| 260 | 260 | "mergeable_state": z.string(), |
| 261 | 261 | "merged": z.boolean(), |
| 262 | - "merged_at": z.string().pipe(z.coerce.date()), | |
| 262 | + "merged_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 263 | 263 | "merged_by": UserSchema, |
| 264 | 264 | "milestone": z.null(), |
| 265 | 265 | "number": z.number().int(), |
| @@ -272,7 +272,7 @@ export const PayloadPullRequestSchema = z.object({ | ||
| 272 | 272 | "state": z.string(), |
| 273 | 273 | "statuses_url": z.string(), |
| 274 | 274 | "title": z.string(), |
| 275 | - "updated_at": z.string().pipe(z.coerce.date()), | |
| 275 | + "updated_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 276 | 276 | "url": z.string(), |
| 277 | 277 | "user": UserSchema, |
| 278 | 278 | }); |
| @@ -300,7 +300,7 @@ export type Payload = z.infer<typeof PayloadSchema>; | ||
| 300 | 300 | |
| 301 | 301 | export const TopLevelElementSchema = z.object({ |
| 302 | 302 | "actor": ActorSchema, |
| 303 | - "created_at": z.string().pipe(z.coerce.date()), | |
| 303 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 304 | 304 | "id": z.string(), |
| 305 | 305 | "org": ActorSchema.optional(), |
| 306 | 306 | "payload": PayloadSchema, |
Test case
1 generated file · +1 −1test/inputs/json/samples/null-safe.json
Mtypescript-zoddefault / TopLevel.ts+1 −1
| @@ -10,7 +10,7 @@ export type Address = z.infer<typeof AddressSchema>; | ||
| 10 | 10 | |
| 11 | 11 | export const ItemSchema = z.object({ |
| 12 | 12 | "address": AddressSchema.optional(), |
| 13 | - "created_at": z.string().pipe(z.coerce.date()).optional(), | |
| 13 | + "created_at": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()).optional(), | |
| 14 | 14 | "name": z.string(), |
| 15 | 15 | "sex": z.union([z.null(), z.number().int()]), |
| 16 | 16 | }); |
Test case
1 generated file · +3 −3test/inputs/json/samples/us-senators.json
Mtypescript-zoddefault / TopLevel.ts+3 −3
| @@ -96,7 +96,7 @@ export type Extra = z.infer<typeof ExtraSchema>; | ||
| 96 | 96 | |
| 97 | 97 | export const PersonSchema = z.object({ |
| 98 | 98 | "bioguideid": z.string(), |
| 99 | - "birthday": z.string(), | |
| 99 | + "birthday": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 100 | 100 | "cspanid": z.number().int(), |
| 101 | 101 | "firstname": z.string(), |
| 102 | 102 | "gender": GenderSchema, |
| @@ -121,7 +121,7 @@ export const ObjectElementSchema = z.object({ | ||
| 121 | 121 | "current": z.boolean(), |
| 122 | 122 | "description": z.string(), |
| 123 | 123 | "district": z.null(), |
| 124 | - "enddate": z.string(), | |
| 124 | + "enddate": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 125 | 125 | "extra": ExtraSchema, |
| 126 | 126 | "leadership_title": z.union([z.null(), z.string()]), |
| 127 | 127 | "party": PartySchema, |
| @@ -133,7 +133,7 @@ export const ObjectElementSchema = z.object({ | ||
| 133 | 133 | "senator_class_label": SenatorClassLabelSchema, |
| 134 | 134 | "senator_rank": SenatorRankSchema, |
| 135 | 135 | "senator_rank_label": SenatorRankLabelSchema, |
| 136 | - "startdate": z.string(), | |
| 136 | + "startdate": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 137 | 137 | "state": z.string(), |
| 138 | 138 | "title": TitleSchema, |
| 139 | 139 | "title_long": RoleTypeLabelSchema, |
Test case
1 generated file · +1 −1test/inputs/schema/date-time-or-string.schema
Mschema-typescript-zoddefault / TopLevel.ts+1 −1
| @@ -7,7 +7,7 @@ export const BarEnumSchema = z.enum([ | ||
| 7 | 7 | export type BarEnum = z.infer<typeof BarEnumSchema>; |
| 8 | 8 | |
| 9 | 9 | export const TopLevelSchema = z.object({ |
| 10 | - "bar": z.union([BarEnumSchema, z.string().pipe(z.coerce.date())]), | |
| 10 | + "bar": z.union([BarEnumSchema, z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date())]), | |
| 11 | 11 | "foo": z.string(), |
| 12 | 12 | }); |
| 13 | 13 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +5 −5test/inputs/schema/date-time.schema
Mschema-typescript-zoddefault / TopLevel.ts+5 −5
| @@ -8,10 +8,10 @@ export const ComplexUnionArrayEnumSchema = z.enum([ | ||
| 8 | 8 | export type ComplexUnionArrayEnum = z.infer<typeof ComplexUnionArrayEnumSchema>; |
| 9 | 9 | |
| 10 | 10 | export const TopLevelSchema = z.object({ |
| 11 | - "complex-union-array": z.array(z.union([ComplexUnionArrayEnumSchema, z.number().int(), z.string().pipe(z.coerce.date())])), | |
| 12 | - "date": z.string(), | |
| 13 | - "date-time": z.string().pipe(z.coerce.date()), | |
| 14 | - "time": z.string(), | |
| 15 | - "union-array": z.array(z.string()), | |
| 11 | + "complex-union-array": z.array(z.union([ComplexUnionArrayEnumSchema, z.number().int(), z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date())])), | |
| 12 | + "date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 13 | + "date-time": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 14 | + "time": z.string().regex(/^(?:[01]\d|2[0-3]):[0-5]\d:(?:[0-5]\d|60)(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/i), | |
| 15 | + "union-array": z.array(z.union([z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), z.string().regex(/^(?:[01]\d|2[0-3]):[0-5]\d:(?:[0-5]\d|60)(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/i), z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date())])), | |
| 16 | 16 | }); |
| 17 | 17 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
Test case
1 generated file · +6 −6test/inputs/schema/optional-date-time.schema
Mschema-typescript-zoddefault / TopLevel.ts+6 −6
| @@ -2,11 +2,11 @@ import * as z from "zod"; | ||
| 2 | 2 | |
| 3 | 3 | |
| 4 | 4 | export const TopLevelSchema = z.object({ |
| 5 | - "optional-date": z.string().optional(), | |
| 6 | - "optional-date-time": z.string().pipe(z.coerce.date()).optional(), | |
| 7 | - "optional-time": z.string().optional(), | |
| 8 | - "required-date": z.string(), | |
| 9 | - "required-date-time": z.string().pipe(z.coerce.date()), | |
| 10 | - "required-time": z.string(), | |
| 5 | + "optional-date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value).optional(), | |
| 6 | + "optional-date-time": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()).optional(), | |
| 7 | + "optional-time": z.string().regex(/^(?:[01]\d|2[0-3]):[0-5]\d:(?:[0-5]\d|60)(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/i).optional(), | |
| 8 | + "required-date": z.string().regex(/^\d{4}-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])$/).refine(value => (new Date(value + "T00:00:00Z").toJSON() || "").slice(0, 10) === value), | |
| 9 | + "required-date-time": z.string().refine(value => z.string().datetime({ offset: true }).safeParse(value.toUpperCase()).success).pipe(z.coerce.date()), | |
| 10 | + "required-time": z.string().regex(/^(?:[01]\d|2[0-3]):[0-5]\d:(?:[0-5]\d|60)(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/i), | |
| 11 | 11 | }); |
| 12 | 12 | export type TopLevel = z.infer<typeof TopLevelSchema>; |
No generated files match these filters.