@mikemajesty/zod-mock-schema 1.0.33 → 1.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/advanced-schemas.spec.js +44 -46
- package/dist/__tests__/advanced-schemas.spec.js.map +1 -1
- package/dist/__tests__/brazilian-formats.spec.js +67 -69
- package/dist/__tests__/brazilian-formats.spec.js.map +1 -1
- package/dist/__tests__/complex-intersections.spec.js +26 -28
- package/dist/__tests__/complex-intersections.spec.js.map +1 -1
- package/dist/__tests__/edge-cases.spec.js +64 -66
- package/dist/__tests__/edge-cases.spec.js.map +1 -1
- package/dist/__tests__/faker-injection.spec.js +38 -40
- package/dist/__tests__/faker-injection.spec.js.map +1 -1
- package/dist/__tests__/overrides-all-types.spec.js +83 -85
- package/dist/__tests__/overrides-all-types.spec.js.map +1 -1
- package/dist/__tests__/overrides.spec.js +93 -95
- package/dist/__tests__/overrides.spec.js.map +1 -1
- package/dist/__tests__/unsupported-types.spec.js +3 -5
- package/dist/__tests__/unsupported-types.spec.js.map +1 -1
- package/dist/__tests__/zod-types.spec.d.ts +53 -53
- package/dist/__tests__/zod-types.spec.js +308 -314
- package/dist/__tests__/zod-types.spec.js.map +1 -1
- package/dist/constants.js +81 -85
- package/dist/constants.js.map +1 -1
- package/dist/index.js +1 -5
- package/dist/index.js.map +1 -1
- package/dist/types.js +1 -2
- package/dist/zod-mock-schema.js +75 -80
- package/dist/zod-mock-schema.js.map +1 -1
- package/package.json +6 -11
- package/dist/cjs/__tests__/advanced-schemas.spec.js +0 -151
- package/dist/cjs/__tests__/advanced-schemas.spec.js.map +0 -1
- package/dist/cjs/__tests__/brazilian-formats.spec.js +0 -207
- package/dist/cjs/__tests__/brazilian-formats.spec.js.map +0 -1
- package/dist/cjs/__tests__/complex-intersections.spec.js +0 -178
- package/dist/cjs/__tests__/complex-intersections.spec.js.map +0 -1
- package/dist/cjs/__tests__/edge-cases.spec.js +0 -208
- package/dist/cjs/__tests__/edge-cases.spec.js.map +0 -1
- package/dist/cjs/__tests__/faker-injection.spec.js +0 -112
- package/dist/cjs/__tests__/faker-injection.spec.js.map +0 -1
- package/dist/cjs/__tests__/overrides-all-types.spec.js +0 -285
- package/dist/cjs/__tests__/overrides-all-types.spec.js.map +0 -1
- package/dist/cjs/__tests__/overrides.spec.js +0 -347
- package/dist/cjs/__tests__/overrides.spec.js.map +0 -1
- package/dist/cjs/__tests__/unsupported-types.spec.js +0 -29
- package/dist/cjs/__tests__/unsupported-types.spec.js.map +0 -1
- package/dist/cjs/__tests__/zod-types.spec.js +0 -532
- package/dist/cjs/__tests__/zod-types.spec.js.map +0 -1
- package/dist/cjs/constants.js +0 -87
- package/dist/cjs/constants.js.map +0 -1
- package/dist/cjs/index.js +0 -6
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/types.js +0 -3
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/zod-mock-schema.js +0 -373
- package/dist/cjs/zod-mock-schema.js.map +0 -1
|
@@ -1,351 +1,345 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const Identifiable = zod_1.default.object({
|
|
10
|
-
id: zod_1.default.uuid(),
|
|
11
|
-
createdAt: zod_1.default.date(),
|
|
12
|
-
updatedAt: zod_1.default.date().optional(),
|
|
13
|
-
deletedAt: zod_1.default.date().optional().nullable(),
|
|
14
|
-
version: zod_1.default.number().int().positive().default(1),
|
|
1
|
+
import { ZodMockSchema } from '../zod-mock-schema.js';
|
|
2
|
+
import z from 'zod';
|
|
3
|
+
const Identifiable = z.object({
|
|
4
|
+
id: z.uuid(),
|
|
5
|
+
createdAt: z.date(),
|
|
6
|
+
updatedAt: z.date().optional(),
|
|
7
|
+
deletedAt: z.date().optional().nullable(),
|
|
8
|
+
version: z.number().int().positive().default(1),
|
|
15
9
|
});
|
|
16
|
-
const Auditable =
|
|
17
|
-
createdBy:
|
|
18
|
-
updatedBy:
|
|
19
|
-
deletedBy:
|
|
20
|
-
auditLog:
|
|
21
|
-
timestamp:
|
|
22
|
-
action:
|
|
23
|
-
userId:
|
|
24
|
-
changes:
|
|
10
|
+
const Auditable = z.object({
|
|
11
|
+
createdBy: z.uuid(),
|
|
12
|
+
updatedBy: z.uuid().optional(),
|
|
13
|
+
deletedBy: z.uuid().optional().nullable(),
|
|
14
|
+
auditLog: z.array(z.object({
|
|
15
|
+
timestamp: z.date(),
|
|
16
|
+
action: z.enum(['CREATE', 'UPDATE', 'DELETE', 'RESTORE']),
|
|
17
|
+
userId: z.uuid(),
|
|
18
|
+
changes: z.record(z.string(), z.any()).optional(),
|
|
25
19
|
})).max(100).optional(),
|
|
26
20
|
});
|
|
27
|
-
const ContactInfo =
|
|
28
|
-
email:
|
|
29
|
-
phone:
|
|
30
|
-
alternativePhone:
|
|
31
|
-
emergencyContact:
|
|
32
|
-
name:
|
|
33
|
-
relationship:
|
|
34
|
-
phone:
|
|
35
|
-
priority:
|
|
21
|
+
const ContactInfo = z.object({
|
|
22
|
+
email: z.email(),
|
|
23
|
+
phone: z.string().regex(/^\d{10,11}$/),
|
|
24
|
+
alternativePhone: z.string().regex(/^\d{10,11}$/).optional(),
|
|
25
|
+
emergencyContact: z.object({
|
|
26
|
+
name: z.string(),
|
|
27
|
+
relationship: z.enum(['parent', 'spouse', 'child', 'sibling', 'friend', 'other']),
|
|
28
|
+
phone: z.string().regex(/^\d{10,11}$/),
|
|
29
|
+
priority: z.number().min(1).max(3),
|
|
36
30
|
}).optional(),
|
|
37
31
|
});
|
|
38
|
-
const Address =
|
|
39
|
-
street:
|
|
40
|
-
number:
|
|
41
|
-
complement:
|
|
42
|
-
neighborhood:
|
|
43
|
-
city:
|
|
44
|
-
state:
|
|
45
|
-
cep:
|
|
46
|
-
country:
|
|
47
|
-
isPrimary:
|
|
48
|
-
type:
|
|
49
|
-
coordinates:
|
|
50
|
-
lat:
|
|
51
|
-
lng:
|
|
32
|
+
const Address = z.object({
|
|
33
|
+
street: z.string().min(3),
|
|
34
|
+
number: z.string(),
|
|
35
|
+
complement: z.string().optional(),
|
|
36
|
+
neighborhood: z.string(),
|
|
37
|
+
city: z.string(),
|
|
38
|
+
state: z.string().length(2).regex(/^[A-Z]{2}$/),
|
|
39
|
+
cep: z.string().regex(/^\d{8}$/),
|
|
40
|
+
country: z.string().default('BR'),
|
|
41
|
+
isPrimary: z.boolean().default(true),
|
|
42
|
+
type: z.enum(['home', 'work', 'billing', 'shipping']),
|
|
43
|
+
coordinates: z.object({
|
|
44
|
+
lat: z.number().min(-90).max(90),
|
|
45
|
+
lng: z.number().min(-180).max(180),
|
|
52
46
|
}).optional(),
|
|
53
47
|
});
|
|
54
|
-
const Geolocatable =
|
|
55
|
-
addresses:
|
|
56
|
-
timezone:
|
|
57
|
-
locale:
|
|
48
|
+
const Geolocatable = z.object({
|
|
49
|
+
addresses: z.array(Address).min(1).max(5),
|
|
50
|
+
timezone: z.string().optional(),
|
|
51
|
+
locale: z.string().default('pt-BR'),
|
|
58
52
|
});
|
|
59
|
-
const BankAccount =
|
|
60
|
-
bankCode:
|
|
61
|
-
agency:
|
|
62
|
-
account:
|
|
63
|
-
digit:
|
|
64
|
-
type:
|
|
65
|
-
isPrimary:
|
|
66
|
-
verifiedAt:
|
|
53
|
+
const BankAccount = z.object({
|
|
54
|
+
bankCode: z.string().regex(/^\d{3}$/),
|
|
55
|
+
agency: z.string().regex(/^\d{4,5}$/),
|
|
56
|
+
account: z.string().regex(/^\d{6,12}$/),
|
|
57
|
+
digit: z.string().regex(/^[0-9X]$/),
|
|
58
|
+
type: z.enum(['checking', 'savings', 'salary', 'payment']),
|
|
59
|
+
isPrimary: z.boolean(),
|
|
60
|
+
verifiedAt: z.date().optional(),
|
|
67
61
|
});
|
|
68
|
-
const FinancialInfo =
|
|
69
|
-
bankAccounts:
|
|
70
|
-
creditScore:
|
|
71
|
-
incomeRange:
|
|
72
|
-
taxId:
|
|
73
|
-
paymentMethods:
|
|
62
|
+
const FinancialInfo = z.object({
|
|
63
|
+
bankAccounts: z.array(BankAccount).max(3),
|
|
64
|
+
creditScore: z.number().min(0).max(1000).optional(),
|
|
65
|
+
incomeRange: z.enum(['A', 'B', 'C', 'D', 'E']).optional(),
|
|
66
|
+
taxId: z.string().regex(/^\d{11}$|^\d{14}$/).optional(),
|
|
67
|
+
paymentMethods: z.array(z.enum(['credit_card', 'debit_card', 'pix', 'boleto', 'bank_transfer'])).min(1),
|
|
74
68
|
});
|
|
75
|
-
const Course =
|
|
76
|
-
id:
|
|
77
|
-
name:
|
|
78
|
-
code:
|
|
79
|
-
credits:
|
|
80
|
-
professorId:
|
|
81
|
-
schedule:
|
|
82
|
-
days:
|
|
83
|
-
startTime:
|
|
84
|
-
endTime:
|
|
85
|
-
room:
|
|
69
|
+
const Course = z.object({
|
|
70
|
+
id: z.string().regex(/^CRS\d{8}$/),
|
|
71
|
+
name: z.string(),
|
|
72
|
+
code: z.string().regex(/^[A-Z]{3}\d{3}$/),
|
|
73
|
+
credits: z.number().int().min(1).max(12),
|
|
74
|
+
professorId: z.uuid().optional(),
|
|
75
|
+
schedule: z.object({
|
|
76
|
+
days: z.array(z.enum(['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'])).min(1).max(6),
|
|
77
|
+
startTime: z.string().regex(/^\d{2}:\d{2}$/),
|
|
78
|
+
endTime: z.string().regex(/^\d{2}:\d{2}$/),
|
|
79
|
+
room: z.string().optional(),
|
|
86
80
|
}),
|
|
87
|
-
status:
|
|
81
|
+
status: z.enum(['active', 'inactive', 'completed', 'cancelled']),
|
|
88
82
|
});
|
|
89
|
-
const AcademicRecord =
|
|
90
|
-
enrollmentId:
|
|
91
|
-
semester:
|
|
92
|
-
gpa:
|
|
93
|
-
totalCredits:
|
|
94
|
-
courses:
|
|
83
|
+
const AcademicRecord = z.object({
|
|
84
|
+
enrollmentId: z.string().regex(/^ENR\d{10}$/),
|
|
85
|
+
semester: z.string().regex(/^\d{4}\.[12]$/),
|
|
86
|
+
gpa: z.number().min(0).max(10).optional(),
|
|
87
|
+
totalCredits: z.number().int().min(0),
|
|
88
|
+
courses: z.array(z.object({
|
|
95
89
|
course: Course,
|
|
96
|
-
grade:
|
|
97
|
-
status:
|
|
98
|
-
attendance:
|
|
90
|
+
grade: z.number().min(0).max(10).optional(),
|
|
91
|
+
status: z.enum(['enrolled', 'approved', 'failed', 'dropped']),
|
|
92
|
+
attendance: z.number().min(0).max(100).optional(),
|
|
99
93
|
})).max(10),
|
|
100
94
|
});
|
|
101
|
-
const StudentRole =
|
|
102
|
-
type:
|
|
103
|
-
studentId:
|
|
104
|
-
enrollmentDate:
|
|
105
|
-
graduationDate:
|
|
95
|
+
const StudentRole = z.object({
|
|
96
|
+
type: z.literal('student'),
|
|
97
|
+
studentId: z.string().regex(/^STU\d{8}$/),
|
|
98
|
+
enrollmentDate: z.date(),
|
|
99
|
+
graduationDate: z.date().optional(),
|
|
106
100
|
academicRecord: AcademicRecord,
|
|
107
|
-
scholarships:
|
|
108
|
-
id:
|
|
109
|
-
type:
|
|
110
|
-
amount:
|
|
111
|
-
startDate:
|
|
112
|
-
endDate:
|
|
113
|
-
renewable:
|
|
101
|
+
scholarships: z.array(z.object({
|
|
102
|
+
id: z.string().regex(/^SCH\d{6}$/),
|
|
103
|
+
type: z.enum(['merit', 'need', 'athletic', 'research']),
|
|
104
|
+
amount: z.number().positive(),
|
|
105
|
+
startDate: z.date(),
|
|
106
|
+
endDate: z.date(),
|
|
107
|
+
renewable: z.boolean(),
|
|
114
108
|
})).max(3).optional(),
|
|
115
|
-
campus:
|
|
109
|
+
campus: z.enum(['main', 'north', 'south', 'online']),
|
|
116
110
|
});
|
|
117
|
-
const TeacherRole =
|
|
118
|
-
type:
|
|
119
|
-
employeeId:
|
|
120
|
-
hireDate:
|
|
121
|
-
department:
|
|
111
|
+
const TeacherRole = z.object({
|
|
112
|
+
type: z.literal('teacher'),
|
|
113
|
+
employeeId: z.string().regex(/^TCH\d{8}$/),
|
|
114
|
+
hireDate: z.date(),
|
|
115
|
+
department: z.enum([
|
|
122
116
|
'computer_science', 'mathematics', 'physics', 'chemistry',
|
|
123
117
|
'biology', 'engineering', 'business', 'arts', 'law', 'medicine'
|
|
124
118
|
]),
|
|
125
|
-
title:
|
|
126
|
-
salary:
|
|
127
|
-
base:
|
|
128
|
-
currency:
|
|
129
|
-
paymentSchedule:
|
|
130
|
-
benefits:
|
|
119
|
+
title: z.enum(['assistant', 'associate', 'full', 'adjunct', 'visiting']),
|
|
120
|
+
salary: z.object({
|
|
121
|
+
base: z.number().positive(),
|
|
122
|
+
currency: z.string().default('BRL'),
|
|
123
|
+
paymentSchedule: z.enum(['monthly', 'biweekly', 'weekly']),
|
|
124
|
+
benefits: z.array(z.enum(['health', 'dental', 'vision', 'retirement', 'tuition'])).optional(),
|
|
131
125
|
}),
|
|
132
|
-
officeHours:
|
|
133
|
-
day:
|
|
134
|
-
start:
|
|
135
|
-
end:
|
|
136
|
-
location:
|
|
137
|
-
mode:
|
|
126
|
+
officeHours: z.array(z.object({
|
|
127
|
+
day: z.enum(['monday', 'tuesday', 'wednesday', 'thursday', 'friday']),
|
|
128
|
+
start: z.string().regex(/^\d{2}:\d{2}$/),
|
|
129
|
+
end: z.string().regex(/^\d{2}:\d{2}$/),
|
|
130
|
+
location: z.string(),
|
|
131
|
+
mode: z.enum(['in_person', 'virtual', 'hybrid']),
|
|
138
132
|
})).max(5).optional(),
|
|
139
|
-
coursesTeaching:
|
|
133
|
+
coursesTeaching: z.array(z.object({
|
|
140
134
|
course: Course,
|
|
141
|
-
semester:
|
|
142
|
-
section:
|
|
135
|
+
semester: z.string().regex(/^\d{4}\.[12]$/),
|
|
136
|
+
section: z.string().regex(/^[A-Z]$/),
|
|
143
137
|
})).max(4),
|
|
144
138
|
});
|
|
145
|
-
const AdminRole =
|
|
146
|
-
type:
|
|
147
|
-
employeeId:
|
|
148
|
-
hireDate:
|
|
149
|
-
department:
|
|
139
|
+
const AdminRole = z.object({
|
|
140
|
+
type: z.literal('admin'),
|
|
141
|
+
employeeId: z.string().regex(/^ADM\d{8}$/),
|
|
142
|
+
hireDate: z.date(),
|
|
143
|
+
department: z.enum([
|
|
150
144
|
'human_resources', 'information_technology', 'finance',
|
|
151
145
|
'operations', 'admissions', 'student_affairs', 'facilities'
|
|
152
146
|
]),
|
|
153
|
-
level:
|
|
154
|
-
permissions:
|
|
155
|
-
resource:
|
|
147
|
+
level: z.number().min(1).max(10),
|
|
148
|
+
permissions: z.array(z.object({
|
|
149
|
+
resource: z.enum([
|
|
156
150
|
'users', 'courses', 'enrollments', 'grades', 'payments',
|
|
157
151
|
'reports', 'settings', 'audit_logs', 'notifications'
|
|
158
152
|
]),
|
|
159
|
-
actions:
|
|
160
|
-
scope:
|
|
153
|
+
actions: z.array(z.enum(['read', 'create', 'update', 'delete', 'approve', 'export'])).min(1),
|
|
154
|
+
scope: z.enum(['global', 'department', 'personal']),
|
|
161
155
|
})).min(1),
|
|
162
|
-
reportsTo:
|
|
163
|
-
managedDepartments:
|
|
156
|
+
reportsTo: z.uuid().optional(),
|
|
157
|
+
managedDepartments: z.array(z.string()).optional(),
|
|
164
158
|
});
|
|
165
|
-
const StaffRole =
|
|
166
|
-
type:
|
|
167
|
-
employeeId:
|
|
168
|
-
hireDate:
|
|
169
|
-
position:
|
|
159
|
+
const StaffRole = z.object({
|
|
160
|
+
type: z.literal('staff'),
|
|
161
|
+
employeeId: z.string().regex(/^STF\d{8}$/),
|
|
162
|
+
hireDate: z.date(),
|
|
163
|
+
position: z.enum([
|
|
170
164
|
'librarian', 'technician', 'counselor', 'coordinator',
|
|
171
165
|
'assistant', 'specialist', 'analyst', 'supervisor'
|
|
172
166
|
]),
|
|
173
|
-
department:
|
|
174
|
-
schedule:
|
|
175
|
-
workHours:
|
|
176
|
-
shift:
|
|
177
|
-
remoteDays:
|
|
167
|
+
department: z.string(),
|
|
168
|
+
schedule: z.object({
|
|
169
|
+
workHours: z.number().min(20).max(60),
|
|
170
|
+
shift: z.enum(['morning', 'afternoon', 'night', 'flexible']),
|
|
171
|
+
remoteDays: z.array(z.enum(['monday', 'tuesday', 'wednesday', 'thursday', 'friday'])).max(3).optional(),
|
|
178
172
|
}),
|
|
179
173
|
});
|
|
180
|
-
const PersonRole =
|
|
174
|
+
const PersonRole = z.discriminatedUnion('type', [
|
|
181
175
|
StudentRole,
|
|
182
176
|
TeacherRole,
|
|
183
177
|
AdminRole,
|
|
184
178
|
StaffRole,
|
|
185
179
|
]);
|
|
186
|
-
const IdentityDocument =
|
|
187
|
-
type:
|
|
188
|
-
number:
|
|
189
|
-
issuingAuthority:
|
|
190
|
-
issueDate:
|
|
191
|
-
expiryDate:
|
|
192
|
-
photoUrl:
|
|
193
|
-
verified:
|
|
180
|
+
const IdentityDocument = z.object({
|
|
181
|
+
type: z.literal('id_card'),
|
|
182
|
+
number: z.string().regex(/^[A-Z0-9]{5,20}$/),
|
|
183
|
+
issuingAuthority: z.string(),
|
|
184
|
+
issueDate: z.date(),
|
|
185
|
+
expiryDate: z.date().optional(),
|
|
186
|
+
photoUrl: z.url().optional(),
|
|
187
|
+
verified: z.boolean().default(false),
|
|
194
188
|
});
|
|
195
|
-
const PassportDocument =
|
|
196
|
-
type:
|
|
197
|
-
number:
|
|
198
|
-
country:
|
|
199
|
-
nationality:
|
|
200
|
-
issueDate:
|
|
201
|
-
expiryDate:
|
|
202
|
-
visaInfo:
|
|
203
|
-
country:
|
|
204
|
-
type:
|
|
205
|
-
issueDate:
|
|
206
|
-
expiryDate:
|
|
189
|
+
const PassportDocument = z.object({
|
|
190
|
+
type: z.literal('passport'),
|
|
191
|
+
number: z.string().regex(/^[A-Z0-9]{8,12}$/),
|
|
192
|
+
country: z.string().length(3),
|
|
193
|
+
nationality: z.string(),
|
|
194
|
+
issueDate: z.date(),
|
|
195
|
+
expiryDate: z.date(),
|
|
196
|
+
visaInfo: z.array(z.object({
|
|
197
|
+
country: z.string().length(3),
|
|
198
|
+
type: z.string(),
|
|
199
|
+
issueDate: z.date(),
|
|
200
|
+
expiryDate: z.date(),
|
|
207
201
|
})).max(5).optional(),
|
|
208
202
|
});
|
|
209
|
-
const ProfessionalDocument =
|
|
210
|
-
type:
|
|
211
|
-
number:
|
|
212
|
-
category:
|
|
213
|
-
council:
|
|
214
|
-
state:
|
|
215
|
-
validity:
|
|
203
|
+
const ProfessionalDocument = z.object({
|
|
204
|
+
type: z.literal('professional'),
|
|
205
|
+
number: z.string().regex(/^[A-Z0-9]{5,15}$/),
|
|
206
|
+
category: z.string(),
|
|
207
|
+
council: z.string(),
|
|
208
|
+
state: z.string().length(2),
|
|
209
|
+
validity: z.date(),
|
|
216
210
|
});
|
|
217
|
-
const Documents =
|
|
218
|
-
const HealthInfo =
|
|
219
|
-
bloodType:
|
|
220
|
-
allergies:
|
|
221
|
-
medications:
|
|
222
|
-
name:
|
|
223
|
-
dosage:
|
|
224
|
-
frequency:
|
|
225
|
-
prescribedBy:
|
|
211
|
+
const Documents = z.array(z.union([IdentityDocument, PassportDocument, ProfessionalDocument])).max(5).optional();
|
|
212
|
+
const HealthInfo = z.object({
|
|
213
|
+
bloodType: z.enum(['A+', 'A-', 'B+', 'B-', 'AB+', 'AB-', 'O+', 'O-']).optional(),
|
|
214
|
+
allergies: z.array(z.string()).max(20).optional(),
|
|
215
|
+
medications: z.array(z.object({
|
|
216
|
+
name: z.string(),
|
|
217
|
+
dosage: z.string(),
|
|
218
|
+
frequency: z.string(),
|
|
219
|
+
prescribedBy: z.string().optional(),
|
|
226
220
|
})).max(10).optional(),
|
|
227
|
-
disabilities:
|
|
228
|
-
type:
|
|
229
|
-
description:
|
|
230
|
-
accommodations:
|
|
221
|
+
disabilities: z.array(z.object({
|
|
222
|
+
type: z.string(),
|
|
223
|
+
description: z.string(),
|
|
224
|
+
accommodations: z.array(z.string()).optional(),
|
|
231
225
|
})).max(5).optional(),
|
|
232
|
-
emergencyMedicalContacts:
|
|
233
|
-
name:
|
|
234
|
-
relationship:
|
|
235
|
-
phone:
|
|
236
|
-
priority:
|
|
226
|
+
emergencyMedicalContacts: z.array(z.object({
|
|
227
|
+
name: z.string(),
|
|
228
|
+
relationship: z.string(),
|
|
229
|
+
phone: z.string().regex(/^\d{10,11}$/),
|
|
230
|
+
priority: z.number().min(1).max(3),
|
|
237
231
|
})).max(3).optional(),
|
|
238
232
|
});
|
|
239
|
-
const Preferences =
|
|
240
|
-
notification:
|
|
241
|
-
email:
|
|
242
|
-
sms:
|
|
243
|
-
push:
|
|
244
|
-
digest:
|
|
233
|
+
const Preferences = z.object({
|
|
234
|
+
notification: z.object({
|
|
235
|
+
email: z.boolean().default(true),
|
|
236
|
+
sms: z.boolean().default(false),
|
|
237
|
+
push: z.boolean().default(true),
|
|
238
|
+
digest: z.enum(['daily', 'weekly', 'monthly', 'never']).default('weekly'),
|
|
245
239
|
}),
|
|
246
|
-
privacy:
|
|
247
|
-
profileVisible:
|
|
248
|
-
searchable:
|
|
249
|
-
showEmail:
|
|
250
|
-
showPhone:
|
|
251
|
-
dataSharing:
|
|
240
|
+
privacy: z.object({
|
|
241
|
+
profileVisible: z.boolean().default(true),
|
|
242
|
+
searchable: z.boolean().default(true),
|
|
243
|
+
showEmail: z.boolean().default(false),
|
|
244
|
+
showPhone: z.boolean().default(false),
|
|
245
|
+
dataSharing: z.enum(['none', 'essential', 'all']).default('essential'),
|
|
252
246
|
}),
|
|
253
|
-
language:
|
|
254
|
-
timeFormat:
|
|
255
|
-
dateFormat:
|
|
247
|
+
language: z.string().default('pt-BR'),
|
|
248
|
+
timeFormat: z.enum(['12h', '24h']).default('24h'),
|
|
249
|
+
dateFormat: z.enum(['DD/MM/YYYY', 'MM/DD/YYYY', 'YYYY-MM-DD']).default('DD/MM/YYYY'),
|
|
256
250
|
});
|
|
257
|
-
const StatusHistory =
|
|
258
|
-
status:
|
|
259
|
-
effectiveDate:
|
|
260
|
-
reason:
|
|
261
|
-
changedBy:
|
|
251
|
+
const StatusHistory = z.array(z.object({
|
|
252
|
+
status: z.enum(['active', 'inactive', 'pending', 'suspended', 'graduated', 'terminated']),
|
|
253
|
+
effectiveDate: z.date(),
|
|
254
|
+
reason: z.string().optional(),
|
|
255
|
+
changedBy: z.uuid().optional(),
|
|
262
256
|
})).min(1);
|
|
263
|
-
const StudentMetadata =
|
|
264
|
-
advisorId:
|
|
265
|
-
thesisTitle:
|
|
266
|
-
researchArea:
|
|
267
|
-
publications:
|
|
268
|
-
title:
|
|
269
|
-
year:
|
|
270
|
-
venue:
|
|
257
|
+
const StudentMetadata = z.object({
|
|
258
|
+
advisorId: z.uuid().optional(),
|
|
259
|
+
thesisTitle: z.string().optional(),
|
|
260
|
+
researchArea: z.string().optional(),
|
|
261
|
+
publications: z.array(z.object({
|
|
262
|
+
title: z.string(),
|
|
263
|
+
year: z.number().int().min(2000).max(2030),
|
|
264
|
+
venue: z.string().optional(),
|
|
271
265
|
})).max(20).optional(),
|
|
272
266
|
});
|
|
273
|
-
const TeacherMetadata =
|
|
274
|
-
researchInterests:
|
|
275
|
-
publicationsCount:
|
|
276
|
-
grants:
|
|
277
|
-
id:
|
|
278
|
-
title:
|
|
279
|
-
fundingAgency:
|
|
280
|
-
amount:
|
|
281
|
-
period:
|
|
267
|
+
const TeacherMetadata = z.object({
|
|
268
|
+
researchInterests: z.array(z.string()).max(10).optional(),
|
|
269
|
+
publicationsCount: z.number().int().min(0),
|
|
270
|
+
grants: z.array(z.object({
|
|
271
|
+
id: z.string(),
|
|
272
|
+
title: z.string(),
|
|
273
|
+
fundingAgency: z.string(),
|
|
274
|
+
amount: z.number().positive(),
|
|
275
|
+
period: z.string(),
|
|
282
276
|
})).max(10).optional(),
|
|
283
|
-
officeLocation:
|
|
277
|
+
officeLocation: z.string(),
|
|
284
278
|
});
|
|
285
|
-
const AdminMetadata =
|
|
286
|
-
budgetResponsibility:
|
|
287
|
-
teamSize:
|
|
288
|
-
projects:
|
|
289
|
-
name:
|
|
290
|
-
status:
|
|
291
|
-
deadline:
|
|
279
|
+
const AdminMetadata = z.object({
|
|
280
|
+
budgetResponsibility: z.number().positive().optional(),
|
|
281
|
+
teamSize: z.number().int().min(0),
|
|
282
|
+
projects: z.array(z.object({
|
|
283
|
+
name: z.string(),
|
|
284
|
+
status: z.enum(['planning', 'active', 'completed', 'cancelled']),
|
|
285
|
+
deadline: z.date().optional(),
|
|
292
286
|
})).max(10).optional(),
|
|
293
287
|
});
|
|
294
|
-
const Metadata =
|
|
288
|
+
const Metadata = z.union([
|
|
295
289
|
StudentMetadata,
|
|
296
290
|
TeacherMetadata,
|
|
297
291
|
AdminMetadata,
|
|
298
292
|
]);
|
|
299
|
-
|
|
300
|
-
name:
|
|
301
|
-
firstName:
|
|
302
|
-
lastName:
|
|
303
|
-
middleName:
|
|
304
|
-
preferredName:
|
|
305
|
-
title:
|
|
293
|
+
export const PersonEntitySchema = z.object({
|
|
294
|
+
name: z.object({
|
|
295
|
+
firstName: z.string().min(2).max(50),
|
|
296
|
+
lastName: z.string().min(2).max(50),
|
|
297
|
+
middleName: z.string().optional(),
|
|
298
|
+
preferredName: z.string().optional(),
|
|
299
|
+
title: z.enum(['Mr.', 'Mrs.', 'Ms.', 'Dr.', 'Prof.']).optional(),
|
|
306
300
|
}),
|
|
307
|
-
demographic:
|
|
308
|
-
birthDate:
|
|
309
|
-
age:
|
|
310
|
-
gender:
|
|
311
|
-
nationality:
|
|
312
|
-
maritalStatus:
|
|
301
|
+
demographic: z.object({
|
|
302
|
+
birthDate: z.date(),
|
|
303
|
+
age: z.number().int().min(0).max(120),
|
|
304
|
+
gender: z.enum(['male', 'female', 'non_binary', 'prefer_not_to_say']),
|
|
305
|
+
nationality: z.string(),
|
|
306
|
+
maritalStatus: z.enum(['single', 'married', 'divorced', 'widowed']).optional(),
|
|
313
307
|
}),
|
|
314
|
-
officialDocuments:
|
|
315
|
-
cpf:
|
|
316
|
-
rg:
|
|
317
|
-
pis:
|
|
318
|
-
voterId:
|
|
308
|
+
officialDocuments: z.object({
|
|
309
|
+
cpf: z.string().regex(/^\d{11}$/),
|
|
310
|
+
rg: z.string().regex(/^\d{7,9}$/),
|
|
311
|
+
pis: z.string().regex(/^\d{11}$/).optional(),
|
|
312
|
+
voterId: z.string().regex(/^\d{12}$/).optional(),
|
|
319
313
|
}),
|
|
320
314
|
role: PersonRole,
|
|
321
|
-
status:
|
|
315
|
+
status: z.enum(['active', 'inactive', 'pending', 'suspended', 'graduated', 'terminated']),
|
|
322
316
|
statusHistory: StatusHistory,
|
|
323
|
-
emergencyContacts:
|
|
324
|
-
name:
|
|
325
|
-
phone:
|
|
326
|
-
relationship:
|
|
327
|
-
priority:
|
|
328
|
-
availableHours:
|
|
317
|
+
emergencyContacts: z.array(z.object({
|
|
318
|
+
name: z.string(),
|
|
319
|
+
phone: z.string().regex(/^\d{10,11}$/),
|
|
320
|
+
relationship: z.enum(['parent', 'spouse', 'child', 'sibling', 'friend', 'other']),
|
|
321
|
+
priority: z.number().min(1).max(3),
|
|
322
|
+
availableHours: z.string().optional(),
|
|
329
323
|
})).min(1).max(5),
|
|
330
324
|
documents: Documents,
|
|
331
325
|
contactInfo: ContactInfo,
|
|
332
|
-
addresses:
|
|
326
|
+
addresses: z.array(Address).min(1).max(3),
|
|
333
327
|
financialInfo: FinancialInfo.optional(),
|
|
334
328
|
healthInfo: HealthInfo.optional(),
|
|
335
329
|
preferences: Preferences,
|
|
336
330
|
roleSpecificMetadata: Metadata.optional(),
|
|
337
|
-
academicHistory:
|
|
338
|
-
system:
|
|
339
|
-
isVerified:
|
|
340
|
-
verificationLevel:
|
|
341
|
-
lastLogin:
|
|
342
|
-
loginCount:
|
|
343
|
-
tags:
|
|
344
|
-
flags:
|
|
331
|
+
academicHistory: z.array(AcademicRecord).max(10).optional(),
|
|
332
|
+
system: z.object({
|
|
333
|
+
isVerified: z.boolean().default(false),
|
|
334
|
+
verificationLevel: z.number().min(0).max(3).default(0),
|
|
335
|
+
lastLogin: z.date().optional(),
|
|
336
|
+
loginCount: z.number().int().min(0).default(0),
|
|
337
|
+
tags: z.array(z.string()).max(20).optional(),
|
|
338
|
+
flags: z.array(z.enum(['high_value', 'at_risk', 'vip', 'fraud_risk', 'legacy'])).optional(),
|
|
345
339
|
}),
|
|
346
340
|
}).and(Identifiable).and(Auditable);
|
|
347
341
|
describe('PersonEntity with Complex Schema', () => {
|
|
348
|
-
const entityMock = new
|
|
342
|
+
const entityMock = new ZodMockSchema(PersonEntitySchema);
|
|
349
343
|
test('should generate complex mock data', () => {
|
|
350
344
|
const mock = entityMock.generate();
|
|
351
345
|
expect(mock).toBeDefined();
|
|
@@ -357,15 +351,15 @@ describe('PersonEntity with Complex Schema', () => {
|
|
|
357
351
|
describe('New Zod Types Support', () => {
|
|
358
352
|
describe('ZodSet', () => {
|
|
359
353
|
test('should generate a Set with elements', () => {
|
|
360
|
-
const schema =
|
|
361
|
-
const mock = new
|
|
354
|
+
const schema = z.set(z.string());
|
|
355
|
+
const mock = new ZodMockSchema(schema);
|
|
362
356
|
const result = mock.generate();
|
|
363
357
|
expect(result).toBeInstanceOf(Set);
|
|
364
358
|
expect(result.size).toBeGreaterThan(0);
|
|
365
359
|
});
|
|
366
360
|
test('should respect min/max size constraints', () => {
|
|
367
|
-
const schema =
|
|
368
|
-
const mock = new
|
|
361
|
+
const schema = z.set(z.number()).min(2).max(5);
|
|
362
|
+
const mock = new ZodMockSchema(schema);
|
|
369
363
|
const result = mock.generate();
|
|
370
364
|
expect(result).toBeInstanceOf(Set);
|
|
371
365
|
expect(result.size).toBeGreaterThanOrEqual(2);
|
|
@@ -374,8 +368,8 @@ describe('New Zod Types Support', () => {
|
|
|
374
368
|
});
|
|
375
369
|
describe('ZodMap', () => {
|
|
376
370
|
test('should generate a Map with entries', () => {
|
|
377
|
-
const schema =
|
|
378
|
-
const mock = new
|
|
371
|
+
const schema = z.map(z.string(), z.number());
|
|
372
|
+
const mock = new ZodMockSchema(schema);
|
|
379
373
|
const result = mock.generate();
|
|
380
374
|
expect(result).toBeInstanceOf(Map);
|
|
381
375
|
expect(result.size).toBeGreaterThan(0);
|
|
@@ -383,8 +377,8 @@ describe('New Zod Types Support', () => {
|
|
|
383
377
|
});
|
|
384
378
|
describe('ZodTuple', () => {
|
|
385
379
|
test('should generate a tuple with correct types', () => {
|
|
386
|
-
const schema =
|
|
387
|
-
const mock = new
|
|
380
|
+
const schema = z.tuple([z.string(), z.number(), z.boolean()]);
|
|
381
|
+
const mock = new ZodMockSchema(schema);
|
|
388
382
|
const result = mock.generate();
|
|
389
383
|
expect(Array.isArray(result)).toBe(true);
|
|
390
384
|
expect(result).toHaveLength(3);
|
|
@@ -393,8 +387,8 @@ describe('New Zod Types Support', () => {
|
|
|
393
387
|
expect(typeof result[2]).toBe('boolean');
|
|
394
388
|
});
|
|
395
389
|
test('should generate tuple with rest elements', () => {
|
|
396
|
-
const schema =
|
|
397
|
-
const mock = new
|
|
390
|
+
const schema = z.tuple([z.string()]).rest(z.number());
|
|
391
|
+
const mock = new ZodMockSchema(schema);
|
|
398
392
|
const result = mock.generate();
|
|
399
393
|
expect(Array.isArray(result)).toBe(true);
|
|
400
394
|
expect(result.length).toBeGreaterThanOrEqual(1);
|
|
@@ -403,8 +397,8 @@ describe('New Zod Types Support', () => {
|
|
|
403
397
|
});
|
|
404
398
|
describe('ZodFunction', () => {
|
|
405
399
|
test('should generate a function that returns mocked value', () => {
|
|
406
|
-
const schema =
|
|
407
|
-
const mock = new
|
|
400
|
+
const schema = z.function();
|
|
401
|
+
const mock = new ZodMockSchema(schema);
|
|
408
402
|
const result = mock.generate();
|
|
409
403
|
expect(typeof result).toBe('function');
|
|
410
404
|
expect(result).toBeDefined();
|
|
@@ -412,11 +406,11 @@ describe('New Zod Types Support', () => {
|
|
|
412
406
|
});
|
|
413
407
|
describe('ZodDiscriminatedUnion', () => {
|
|
414
408
|
test('should generate one of the union options', () => {
|
|
415
|
-
const schema =
|
|
416
|
-
|
|
417
|
-
|
|
409
|
+
const schema = z.discriminatedUnion('type', [
|
|
410
|
+
z.object({ type: z.literal('a'), value: z.string() }),
|
|
411
|
+
z.object({ type: z.literal('b'), value: z.number() }),
|
|
418
412
|
]);
|
|
419
|
-
const mock = new
|
|
413
|
+
const mock = new ZodMockSchema(schema);
|
|
420
414
|
const result = mock.generate();
|
|
421
415
|
expect(result).toBeDefined();
|
|
422
416
|
expect(['a', 'b']).toContain(result.type);
|
|
@@ -424,8 +418,8 @@ describe('New Zod Types Support', () => {
|
|
|
424
418
|
});
|
|
425
419
|
describe('ZodBigInt', () => {
|
|
426
420
|
test('should generate a BigInt', () => {
|
|
427
|
-
const schema =
|
|
428
|
-
const mock = new
|
|
421
|
+
const schema = z.bigint();
|
|
422
|
+
const mock = new ZodMockSchema(schema);
|
|
429
423
|
const result = mock.generate();
|
|
430
424
|
expect(typeof result).toBe('bigint');
|
|
431
425
|
expect(result).toBeGreaterThan(BigInt(0));
|
|
@@ -433,16 +427,16 @@ describe('New Zod Types Support', () => {
|
|
|
433
427
|
});
|
|
434
428
|
describe('ZodNaN', () => {
|
|
435
429
|
test('should generate NaN', () => {
|
|
436
|
-
const schema =
|
|
437
|
-
const mock = new
|
|
430
|
+
const schema = z.nan();
|
|
431
|
+
const mock = new ZodMockSchema(schema);
|
|
438
432
|
const result = mock.generate();
|
|
439
433
|
expect(Number.isNaN(result)).toBe(true);
|
|
440
434
|
});
|
|
441
435
|
});
|
|
442
436
|
describe('ZodReadonly', () => {
|
|
443
437
|
test('should generate readonly object', () => {
|
|
444
|
-
const schema =
|
|
445
|
-
const mock = new
|
|
438
|
+
const schema = z.object({ name: z.string() }).readonly();
|
|
439
|
+
const mock = new ZodMockSchema(schema);
|
|
446
440
|
const result = mock.generate();
|
|
447
441
|
expect(result).toBeDefined();
|
|
448
442
|
expect(typeof result.name).toBe('string');
|
|
@@ -452,20 +446,20 @@ describe('New Zod Types Support', () => {
|
|
|
452
446
|
describe('Improved Constraints', () => {
|
|
453
447
|
describe('String min/max', () => {
|
|
454
448
|
test('should respect min length', () => {
|
|
455
|
-
const schema =
|
|
456
|
-
const mock = new
|
|
449
|
+
const schema = z.string().min(10);
|
|
450
|
+
const mock = new ZodMockSchema(schema);
|
|
457
451
|
const result = mock.generate();
|
|
458
452
|
expect(result.length).toBeGreaterThanOrEqual(10);
|
|
459
453
|
});
|
|
460
454
|
test('should respect max length', () => {
|
|
461
|
-
const schema =
|
|
462
|
-
const mock = new
|
|
455
|
+
const schema = z.string().max(5);
|
|
456
|
+
const mock = new ZodMockSchema(schema);
|
|
463
457
|
const result = mock.generate();
|
|
464
458
|
expect(result.length).toBeLessThanOrEqual(5);
|
|
465
459
|
});
|
|
466
460
|
test('should respect both min and max', () => {
|
|
467
|
-
const schema =
|
|
468
|
-
const mock = new
|
|
461
|
+
const schema = z.string().min(5).max(10);
|
|
462
|
+
const mock = new ZodMockSchema(schema);
|
|
469
463
|
const result = mock.generate();
|
|
470
464
|
expect(result.length).toBeGreaterThanOrEqual(5);
|
|
471
465
|
expect(result.length).toBeLessThanOrEqual(10);
|
|
@@ -475,8 +469,8 @@ describe('Improved Constraints', () => {
|
|
|
475
469
|
test('should respect date range', () => {
|
|
476
470
|
const minDate = new Date('2025-01-01');
|
|
477
471
|
const maxDate = new Date('2025-12-31');
|
|
478
|
-
const schema =
|
|
479
|
-
const mock = new
|
|
472
|
+
const schema = z.date().min(minDate).max(maxDate);
|
|
473
|
+
const mock = new ZodMockSchema(schema);
|
|
480
474
|
const result = mock.generate();
|
|
481
475
|
expect(result).toBeInstanceOf(Date);
|
|
482
476
|
expect(result.getTime()).toBeGreaterThanOrEqual(minDate.getTime());
|
|
@@ -485,14 +479,14 @@ describe('Improved Constraints', () => {
|
|
|
485
479
|
});
|
|
486
480
|
describe('ZodDefault always uses default value', () => {
|
|
487
481
|
test('should always return the default value', () => {
|
|
488
|
-
const schema =
|
|
489
|
-
const mock = new
|
|
482
|
+
const schema = z.string().default('DEFAULT_VALUE');
|
|
483
|
+
const mock = new ZodMockSchema(schema);
|
|
490
484
|
const results = Array.from({ length: 10 }, () => mock.generate());
|
|
491
485
|
expect(results.every(r => r === 'DEFAULT_VALUE')).toBe(true);
|
|
492
486
|
});
|
|
493
487
|
test('should work with default numbers', () => {
|
|
494
|
-
const schema =
|
|
495
|
-
const mock = new
|
|
488
|
+
const schema = z.number().default(42);
|
|
489
|
+
const mock = new ZodMockSchema(schema);
|
|
496
490
|
const result = mock.generate();
|
|
497
491
|
expect(result).toBe(42);
|
|
498
492
|
});
|
|
@@ -500,31 +494,31 @@ describe('Improved Constraints', () => {
|
|
|
500
494
|
});
|
|
501
495
|
describe('Seed Support', () => {
|
|
502
496
|
test('should generate same data with same seed', () => {
|
|
503
|
-
const schema =
|
|
504
|
-
name:
|
|
505
|
-
age:
|
|
506
|
-
email:
|
|
497
|
+
const schema = z.object({
|
|
498
|
+
name: z.string(),
|
|
499
|
+
age: z.number(),
|
|
500
|
+
email: z.email(),
|
|
507
501
|
});
|
|
508
|
-
const mock1 = new
|
|
502
|
+
const mock1 = new ZodMockSchema(schema).seed(12345);
|
|
509
503
|
const result1 = mock1.generate();
|
|
510
|
-
const mock2 = new
|
|
504
|
+
const mock2 = new ZodMockSchema(schema).seed(12345);
|
|
511
505
|
const result2 = mock2.generate();
|
|
512
506
|
expect(result1).toEqual(result2);
|
|
513
507
|
});
|
|
514
508
|
test('should generate different data with different seeds', () => {
|
|
515
|
-
const schema =
|
|
516
|
-
name:
|
|
517
|
-
age:
|
|
509
|
+
const schema = z.object({
|
|
510
|
+
name: z.string(),
|
|
511
|
+
age: z.number(),
|
|
518
512
|
});
|
|
519
|
-
const mock1 = new
|
|
513
|
+
const mock1 = new ZodMockSchema(schema).seed(111);
|
|
520
514
|
const result1 = mock1.generate();
|
|
521
|
-
const mock2 = new
|
|
515
|
+
const mock2 = new ZodMockSchema(schema).seed(222);
|
|
522
516
|
const result2 = mock2.generate();
|
|
523
517
|
expect(result1).not.toEqual(result2);
|
|
524
518
|
});
|
|
525
519
|
test('should support array seed', () => {
|
|
526
|
-
const schema =
|
|
527
|
-
const mock = new
|
|
520
|
+
const schema = z.string();
|
|
521
|
+
const mock = new ZodMockSchema(schema).seed([1, 2, 3]);
|
|
528
522
|
const result = mock.generate();
|
|
529
523
|
expect(typeof result).toBe('string');
|
|
530
524
|
});
|