11import { z } from 'zod' ;
22
3- export const User = z . object ( {
3+ // Helper types for schemas
4+
5+ export type UserModel = {
6+ 'id' : string ;
7+ 'username' : string ;
8+ 'email' : string ;
9+ 'profile' ?: {
10+ 'fullName' ?: string | undefined ;
11+ 'joinDate' ?: string | undefined ;
12+ } | undefined ;
13+ 'legacyId' ?: number | undefined ;
14+ } ;
15+
16+ export type ProductInputModel = {
17+ 'name' : string ;
18+ 'description' ?: string | undefined ;
19+ 'price' : number ;
20+ } ;
21+
22+ export type ProductModel = ProductInputModel & {
23+ 'id' ?: string | undefined ;
24+ 'imageUrl' ?: string | undefined ;
25+ 'stock' ?: number | undefined ;
26+ } ;
27+
28+ export type PaginatedResponseModel = {
29+ 'page' ?: number | undefined ;
30+ 'pageSize' ?: number | undefined ;
31+ 'total' ?: number | undefined ;
32+ 'items' ?: any [ ] | undefined ;
33+ } ;
34+
35+ export type PaginatedProductResponseModel = PaginatedResponseModel ;
36+
37+ export type CreditCardModel = {
38+ 'methodType' : 'card' ;
39+ 'cardNumber' : string ;
40+ 'expiry' ?: string | undefined ;
41+ 'cvv' ?: string | undefined ;
42+ } ;
43+
44+ export type PayPalModel = {
45+ 'methodType' : 'paypal_account' ;
46+ 'email' : string ;
47+ } ;
48+
49+ export type PaymentMethodModel = CreditCardModel | PayPalModel ;
50+
51+ export type CallbackPayloadModel = {
52+ 'orderId' ?: string | undefined ;
53+ 'status' ?: 'PROCESSED' | 'FAILED' | undefined ;
54+ 'detail' ?: string | undefined ;
55+ } ;
56+
57+ export type InventoryUpdatePayloadModel = {
58+ 'productId' ?: string | undefined ;
59+ 'newStockLevel' ?: number | undefined ;
60+ 'timestamp' ?: string | undefined ;
61+ } ;
62+
63+ export type ApiErrorModel = {
64+ 'errorCode' ?: string | undefined ;
65+ 'message' ?: string | undefined ;
66+ } ;
67+
68+
69+
70+ export const User : z . ZodType < UserModel > = z . object ( {
471'id' : z . uuid ( ) ,
572'username' : z . string ( ) . regex ( / ^ [ a - z A - Z 0 - 9 _ - ] { 3 , 16 } $ / ) ,
673'email' : z . email ( ) ,
@@ -11,76 +78,54 @@ export const User = z.object({
1178'legacyId' : z . number ( ) . int ( ) . optional ( )
1279} ) ;
1380
14- export type UserModel = z . infer < typeof User > ;
15-
16- export const ProductInput = z . object ( {
81+ export const ProductInput : z . ZodType < ProductInputModel > = z . object ( {
1782'name' : z . string ( ) ,
1883'description' : z . string ( ) . optional ( ) ,
1984'price' : z . number ( ) . min ( 0 )
2085} ) ;
2186
22- export type ProductInputModel = z . infer < typeof ProductInput > ;
23-
24- export const Product = ProductInput . and ( z . object ( {
87+ export const Product : z . ZodType < ProductModel > = ProductInput . and ( z . object ( {
2588'id' : z . uuid ( ) . optional ( ) ,
2689'imageUrl' : z . url ( ) . optional ( ) ,
2790'stock' : z . number ( ) . int ( ) . optional ( )
2891} ) ) ;
2992
30- export type ProductModel = z . infer < typeof Product > ;
31-
32- export const PaginatedResponse = z . object ( {
93+ export const PaginatedResponse : z . ZodType < PaginatedResponseModel > = z . object ( {
3394'page' : z . number ( ) . int ( ) . optional ( ) ,
3495'pageSize' : z . number ( ) . int ( ) . optional ( ) ,
3596'total' : z . number ( ) . int ( ) . optional ( ) ,
3697'items' : z . array ( z . any ( ) ) . optional ( )
3798} ) ;
3899
39- export type PaginatedResponseModel = z . infer < typeof PaginatedResponse > ;
100+ export const PaginatedProductResponse : z . ZodType < PaginatedProductResponseModel > = PaginatedResponse ;
40101
41- export const PaginatedProductResponse = PaginatedResponse ;
42-
43- export type PaginatedProductResponseModel = z . infer < typeof PaginatedProductResponse > ;
44-
45- export const CreditCard = z . object ( {
102+ export const CreditCard : z . ZodType < CreditCardModel > = z . object ( {
46103'methodType' : z . enum ( [ 'card' ] ) ,
47104'cardNumber' : z . string ( ) ,
48105'expiry' : z . string ( ) . optional ( ) ,
49106'cvv' : z . string ( ) . optional ( )
50107} ) ;
51108
52- export type CreditCardModel = z . infer < typeof CreditCard > ;
53-
54- export const PayPal = z . object ( {
109+ export const PayPal : z . ZodType < PayPalModel > = z . object ( {
55110'methodType' : z . enum ( [ 'paypal_account' ] ) ,
56111'email' : z . email ( )
57112} ) ;
58113
59- export type PayPalModel = z . infer < typeof PayPal > ;
114+ export const PaymentMethod : z . ZodType < PaymentMethodModel > = z . discriminatedUnion ( 'methodType' , [ CreditCard , PayPal ] ) ;
60115
61- export const PaymentMethod = z . discriminatedUnion ( 'methodType' , [ CreditCard , PayPal ] ) ;
62-
63- export type PaymentMethodModel = z . infer < typeof PaymentMethod > ;
64-
65- export const CallbackPayload = z . object ( {
116+ export const CallbackPayload : z . ZodType < CallbackPayloadModel > = z . object ( {
66117'orderId' : z . uuid ( ) . optional ( ) ,
67118'status' : z . enum ( [ 'PROCESSED' , 'FAILED' ] ) . optional ( ) ,
68119'detail' : z . string ( ) . optional ( )
69120} ) ;
70121
71- export type CallbackPayloadModel = z . infer < typeof CallbackPayload > ;
72-
73- export const InventoryUpdatePayload = z . object ( {
122+ export const InventoryUpdatePayload : z . ZodType < InventoryUpdatePayloadModel > = z . object ( {
74123'productId' : z . uuid ( ) . optional ( ) ,
75124'newStockLevel' : z . number ( ) . int ( ) . optional ( ) ,
76125'timestamp' : z . iso . datetime ( ) . optional ( )
77126} ) ;
78127
79- export type InventoryUpdatePayloadModel = z . infer < typeof InventoryUpdatePayload > ;
80-
81- export const ApiError = z . object ( {
128+ export const ApiError : z . ZodType < ApiErrorModel > = z . object ( {
82129'errorCode' : z . string ( ) . optional ( ) ,
83130'message' : z . string ( ) . optional ( )
84- } ) ;
85-
86- export type ApiErrorModel = z . infer < typeof ApiError > ;
131+ } ) ;
0 commit comments