@mikemajesty/zod-mock-schema 1.0.36 → 1.0.37
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/README.md +0 -60
- package/dist/__tests__/overrides-all-types.spec.js +0 -16
- package/dist/__tests__/overrides-all-types.spec.js.map +1 -1
- package/dist/__tests__/unsupported-types.spec.js.map +1 -1
- package/dist/__tests__/zod-custom.spec.js +27 -0
- package/dist/__tests__/zod-custom.spec.js.map +1 -0
- package/dist/__tests__/zod-pipe.spec.d.ts +1 -0
- package/dist/__tests__/zod-pipe.spec.js +81 -0
- package/dist/__tests__/zod-pipe.spec.js.map +1 -0
- package/dist/__tests__/zod-types.spec.d.ts +1 -7
- package/dist/__tests__/zod-types.spec.js +341 -157
- package/dist/__tests__/zod-types.spec.js.map +1 -1
- package/dist/constants.d.ts +1 -12
- package/dist/constants.js +1 -42
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +0 -1
- package/dist/zod-mock-schema.d.ts +4 -5
- package/dist/zod-mock-schema.js +126 -79
- package/dist/zod-mock-schema.js.map +1 -1
- package/package.json +8 -11
- package/dist/__tests__/brazilian-formats.spec.js +0 -205
- package/dist/__tests__/brazilian-formats.spec.js.map +0 -1
- /package/dist/__tests__/{brazilian-formats.spec.d.ts → zod-custom.spec.d.ts} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ZodMockSchema } from
|
|
2
|
-
import z from
|
|
1
|
+
import { ZodMockSchema } from "../zod-mock-schema.js";
|
|
2
|
+
import z from "zod";
|
|
3
3
|
const Identifiable = z.object({
|
|
4
4
|
id: z.uuid(),
|
|
5
5
|
createdAt: z.date(),
|
|
@@ -11,23 +11,38 @@ const Auditable = z.object({
|
|
|
11
11
|
createdBy: z.uuid(),
|
|
12
12
|
updatedBy: z.uuid().optional(),
|
|
13
13
|
deletedBy: z.uuid().optional().nullable(),
|
|
14
|
-
auditLog: z
|
|
14
|
+
auditLog: z
|
|
15
|
+
.array(z.object({
|
|
15
16
|
timestamp: z.date(),
|
|
16
|
-
action: z.enum([
|
|
17
|
+
action: z.enum(["CREATE", "UPDATE", "DELETE", "RESTORE"]),
|
|
17
18
|
userId: z.uuid(),
|
|
18
19
|
changes: z.record(z.string(), z.any()).optional(),
|
|
19
|
-
}))
|
|
20
|
+
}))
|
|
21
|
+
.max(100)
|
|
22
|
+
.optional(),
|
|
20
23
|
});
|
|
21
24
|
const ContactInfo = z.object({
|
|
22
25
|
email: z.email(),
|
|
23
26
|
phone: z.string().regex(/^\d{10,11}$/),
|
|
24
|
-
alternativePhone: z
|
|
25
|
-
|
|
27
|
+
alternativePhone: z
|
|
28
|
+
.string()
|
|
29
|
+
.regex(/^\d{10,11}$/)
|
|
30
|
+
.optional(),
|
|
31
|
+
emergencyContact: z
|
|
32
|
+
.object({
|
|
26
33
|
name: z.string(),
|
|
27
|
-
relationship: z.enum([
|
|
34
|
+
relationship: z.enum([
|
|
35
|
+
"parent",
|
|
36
|
+
"spouse",
|
|
37
|
+
"child",
|
|
38
|
+
"sibling",
|
|
39
|
+
"friend",
|
|
40
|
+
"other",
|
|
41
|
+
]),
|
|
28
42
|
phone: z.string().regex(/^\d{10,11}$/),
|
|
29
43
|
priority: z.number().min(1).max(3),
|
|
30
|
-
})
|
|
44
|
+
})
|
|
45
|
+
.optional(),
|
|
31
46
|
});
|
|
32
47
|
const Address = z.object({
|
|
33
48
|
street: z.string().min(3),
|
|
@@ -35,36 +50,46 @@ const Address = z.object({
|
|
|
35
50
|
complement: z.string().optional(),
|
|
36
51
|
neighborhood: z.string(),
|
|
37
52
|
city: z.string(),
|
|
38
|
-
state: z
|
|
53
|
+
state: z
|
|
54
|
+
.string()
|
|
55
|
+
.length(2)
|
|
56
|
+
.regex(/^[A-Z]{2}$/),
|
|
39
57
|
cep: z.string().regex(/^\d{8}$/),
|
|
40
|
-
country: z.string().default(
|
|
58
|
+
country: z.string().default("BR"),
|
|
41
59
|
isPrimary: z.boolean().default(true),
|
|
42
|
-
type: z.enum([
|
|
43
|
-
coordinates: z
|
|
60
|
+
type: z.enum(["home", "work", "billing", "shipping"]),
|
|
61
|
+
coordinates: z
|
|
62
|
+
.object({
|
|
44
63
|
lat: z.number().min(-90).max(90),
|
|
45
64
|
lng: z.number().min(-180).max(180),
|
|
46
|
-
})
|
|
65
|
+
})
|
|
66
|
+
.optional(),
|
|
47
67
|
});
|
|
48
68
|
const Geolocatable = z.object({
|
|
49
69
|
addresses: z.array(Address).min(1).max(5),
|
|
50
70
|
timezone: z.string().optional(),
|
|
51
|
-
locale: z.string().default(
|
|
71
|
+
locale: z.string().default("pt-BR"),
|
|
52
72
|
});
|
|
53
73
|
const BankAccount = z.object({
|
|
54
74
|
bankCode: z.string().regex(/^\d{3}$/),
|
|
55
75
|
agency: z.string().regex(/^\d{4,5}$/),
|
|
56
76
|
account: z.string().regex(/^\d{6,12}$/),
|
|
57
77
|
digit: z.string().regex(/^[0-9X]$/),
|
|
58
|
-
type: z.enum([
|
|
78
|
+
type: z.enum(["checking", "savings", "salary", "payment"]),
|
|
59
79
|
isPrimary: z.boolean(),
|
|
60
80
|
verifiedAt: z.date().optional(),
|
|
61
81
|
});
|
|
62
82
|
const FinancialInfo = z.object({
|
|
63
83
|
bankAccounts: z.array(BankAccount).max(3),
|
|
64
84
|
creditScore: z.number().min(0).max(1000).optional(),
|
|
65
|
-
incomeRange: z.enum([
|
|
66
|
-
taxId: z
|
|
67
|
-
|
|
85
|
+
incomeRange: z.enum(["A", "B", "C", "D", "E"]).optional(),
|
|
86
|
+
taxId: z
|
|
87
|
+
.string()
|
|
88
|
+
.regex(/^\d{11}$|^\d{14}$/)
|
|
89
|
+
.optional(),
|
|
90
|
+
paymentMethods: z
|
|
91
|
+
.array(z.enum(["credit_card", "debit_card", "pix", "boleto", "bank_transfer"]))
|
|
92
|
+
.min(1),
|
|
68
93
|
});
|
|
69
94
|
const Course = z.object({
|
|
70
95
|
id: z.string().regex(/^CRS\d{8}$/),
|
|
@@ -73,112 +98,167 @@ const Course = z.object({
|
|
|
73
98
|
credits: z.number().int().min(1).max(12),
|
|
74
99
|
professorId: z.uuid().optional(),
|
|
75
100
|
schedule: z.object({
|
|
76
|
-
days: z
|
|
101
|
+
days: z
|
|
102
|
+
.array(z.enum([
|
|
103
|
+
"monday",
|
|
104
|
+
"tuesday",
|
|
105
|
+
"wednesday",
|
|
106
|
+
"thursday",
|
|
107
|
+
"friday",
|
|
108
|
+
"saturday",
|
|
109
|
+
]))
|
|
110
|
+
.min(1)
|
|
111
|
+
.max(6),
|
|
77
112
|
startTime: z.string().regex(/^\d{2}:\d{2}$/),
|
|
78
113
|
endTime: z.string().regex(/^\d{2}:\d{2}$/),
|
|
79
114
|
room: z.string().optional(),
|
|
80
115
|
}),
|
|
81
|
-
status: z.enum([
|
|
116
|
+
status: z.enum(["active", "inactive", "completed", "cancelled"]),
|
|
82
117
|
});
|
|
83
118
|
const AcademicRecord = z.object({
|
|
84
119
|
enrollmentId: z.string().regex(/^ENR\d{10}$/),
|
|
85
120
|
semester: z.string().regex(/^\d{4}\.[12]$/),
|
|
86
121
|
gpa: z.number().min(0).max(10).optional(),
|
|
87
122
|
totalCredits: z.number().int().min(0),
|
|
88
|
-
courses: z
|
|
123
|
+
courses: z
|
|
124
|
+
.array(z.object({
|
|
89
125
|
course: Course,
|
|
90
126
|
grade: z.number().min(0).max(10).optional(),
|
|
91
|
-
status: z.enum([
|
|
127
|
+
status: z.enum(["enrolled", "approved", "failed", "dropped"]),
|
|
92
128
|
attendance: z.number().min(0).max(100).optional(),
|
|
93
|
-
}))
|
|
129
|
+
}))
|
|
130
|
+
.max(10),
|
|
94
131
|
});
|
|
95
132
|
const StudentRole = z.object({
|
|
96
|
-
type: z.literal(
|
|
133
|
+
type: z.literal("student"),
|
|
97
134
|
studentId: z.string().regex(/^STU\d{8}$/),
|
|
98
135
|
enrollmentDate: z.date(),
|
|
99
136
|
graduationDate: z.date().optional(),
|
|
100
137
|
academicRecord: AcademicRecord,
|
|
101
|
-
scholarships: z
|
|
138
|
+
scholarships: z
|
|
139
|
+
.array(z.object({
|
|
102
140
|
id: z.string().regex(/^SCH\d{6}$/),
|
|
103
|
-
type: z.enum([
|
|
141
|
+
type: z.enum(["merit", "need", "athletic", "research"]),
|
|
104
142
|
amount: z.number().positive(),
|
|
105
143
|
startDate: z.date(),
|
|
106
144
|
endDate: z.date(),
|
|
107
145
|
renewable: z.boolean(),
|
|
108
|
-
}))
|
|
109
|
-
|
|
146
|
+
}))
|
|
147
|
+
.max(3)
|
|
148
|
+
.optional(),
|
|
149
|
+
campus: z.enum(["main", "north", "south", "online"]),
|
|
110
150
|
});
|
|
111
151
|
const TeacherRole = z.object({
|
|
112
|
-
type: z.literal(
|
|
152
|
+
type: z.literal("teacher"),
|
|
113
153
|
employeeId: z.string().regex(/^TCH\d{8}$/),
|
|
114
154
|
hireDate: z.date(),
|
|
115
155
|
department: z.enum([
|
|
116
|
-
|
|
117
|
-
|
|
156
|
+
"computer_science",
|
|
157
|
+
"mathematics",
|
|
158
|
+
"physics",
|
|
159
|
+
"chemistry",
|
|
160
|
+
"biology",
|
|
161
|
+
"engineering",
|
|
162
|
+
"business",
|
|
163
|
+
"arts",
|
|
164
|
+
"law",
|
|
165
|
+
"medicine",
|
|
118
166
|
]),
|
|
119
|
-
title: z.enum([
|
|
167
|
+
title: z.enum(["assistant", "associate", "full", "adjunct", "visiting"]),
|
|
120
168
|
salary: z.object({
|
|
121
169
|
base: z.number().positive(),
|
|
122
|
-
currency: z.string().default(
|
|
123
|
-
paymentSchedule: z.enum([
|
|
124
|
-
benefits: z
|
|
170
|
+
currency: z.string().default("BRL"),
|
|
171
|
+
paymentSchedule: z.enum(["monthly", "biweekly", "weekly"]),
|
|
172
|
+
benefits: z
|
|
173
|
+
.array(z.enum(["health", "dental", "vision", "retirement", "tuition"]))
|
|
174
|
+
.optional(),
|
|
125
175
|
}),
|
|
126
|
-
officeHours: z
|
|
127
|
-
|
|
176
|
+
officeHours: z
|
|
177
|
+
.array(z.object({
|
|
178
|
+
day: z.enum(["monday", "tuesday", "wednesday", "thursday", "friday"]),
|
|
128
179
|
start: z.string().regex(/^\d{2}:\d{2}$/),
|
|
129
180
|
end: z.string().regex(/^\d{2}:\d{2}$/),
|
|
130
181
|
location: z.string(),
|
|
131
|
-
mode: z.enum([
|
|
132
|
-
}))
|
|
133
|
-
|
|
182
|
+
mode: z.enum(["in_person", "virtual", "hybrid"]),
|
|
183
|
+
}))
|
|
184
|
+
.max(5)
|
|
185
|
+
.optional(),
|
|
186
|
+
coursesTeaching: z
|
|
187
|
+
.array(z.object({
|
|
134
188
|
course: Course,
|
|
135
189
|
semester: z.string().regex(/^\d{4}\.[12]$/),
|
|
136
190
|
section: z.string().regex(/^[A-Z]$/),
|
|
137
|
-
}))
|
|
191
|
+
}))
|
|
192
|
+
.max(4),
|
|
138
193
|
});
|
|
139
194
|
const AdminRole = z.object({
|
|
140
|
-
type: z.literal(
|
|
195
|
+
type: z.literal("admin"),
|
|
141
196
|
employeeId: z.string().regex(/^ADM\d{8}$/),
|
|
142
197
|
hireDate: z.date(),
|
|
143
198
|
department: z.enum([
|
|
144
|
-
|
|
145
|
-
|
|
199
|
+
"human_resources",
|
|
200
|
+
"information_technology",
|
|
201
|
+
"finance",
|
|
202
|
+
"operations",
|
|
203
|
+
"admissions",
|
|
204
|
+
"student_affairs",
|
|
205
|
+
"facilities",
|
|
146
206
|
]),
|
|
147
207
|
level: z.number().min(1).max(10),
|
|
148
|
-
permissions: z
|
|
208
|
+
permissions: z
|
|
209
|
+
.array(z.object({
|
|
149
210
|
resource: z.enum([
|
|
150
|
-
|
|
151
|
-
|
|
211
|
+
"users",
|
|
212
|
+
"courses",
|
|
213
|
+
"enrollments",
|
|
214
|
+
"grades",
|
|
215
|
+
"payments",
|
|
216
|
+
"reports",
|
|
217
|
+
"settings",
|
|
218
|
+
"audit_logs",
|
|
219
|
+
"notifications",
|
|
152
220
|
]),
|
|
153
|
-
actions: z
|
|
154
|
-
|
|
155
|
-
|
|
221
|
+
actions: z
|
|
222
|
+
.array(z.enum(["read", "create", "update", "delete", "approve", "export"]))
|
|
223
|
+
.min(1),
|
|
224
|
+
scope: z.enum(["global", "department", "personal"]),
|
|
225
|
+
}))
|
|
226
|
+
.min(1),
|
|
156
227
|
reportsTo: z.uuid().optional(),
|
|
157
228
|
managedDepartments: z.array(z.string()).optional(),
|
|
158
229
|
});
|
|
159
230
|
const StaffRole = z.object({
|
|
160
|
-
type: z.literal(
|
|
231
|
+
type: z.literal("staff"),
|
|
161
232
|
employeeId: z.string().regex(/^STF\d{8}$/),
|
|
162
233
|
hireDate: z.date(),
|
|
163
234
|
position: z.enum([
|
|
164
|
-
|
|
165
|
-
|
|
235
|
+
"librarian",
|
|
236
|
+
"technician",
|
|
237
|
+
"counselor",
|
|
238
|
+
"coordinator",
|
|
239
|
+
"assistant",
|
|
240
|
+
"specialist",
|
|
241
|
+
"analyst",
|
|
242
|
+
"supervisor",
|
|
166
243
|
]),
|
|
167
244
|
department: z.string(),
|
|
168
245
|
schedule: z.object({
|
|
169
246
|
workHours: z.number().min(20).max(60),
|
|
170
|
-
shift: z.enum([
|
|
171
|
-
remoteDays: z
|
|
247
|
+
shift: z.enum(["morning", "afternoon", "night", "flexible"]),
|
|
248
|
+
remoteDays: z
|
|
249
|
+
.array(z.enum(["monday", "tuesday", "wednesday", "thursday", "friday"]))
|
|
250
|
+
.max(3)
|
|
251
|
+
.optional(),
|
|
172
252
|
}),
|
|
173
253
|
});
|
|
174
|
-
const PersonRole = z.discriminatedUnion(
|
|
254
|
+
const PersonRole = z.discriminatedUnion("type", [
|
|
175
255
|
StudentRole,
|
|
176
256
|
TeacherRole,
|
|
177
257
|
AdminRole,
|
|
178
258
|
StaffRole,
|
|
179
259
|
]);
|
|
180
260
|
const IdentityDocument = z.object({
|
|
181
|
-
type: z.literal(
|
|
261
|
+
type: z.literal("id_card"),
|
|
182
262
|
number: z.string().regex(/^[A-Z0-9]{5,20}$/),
|
|
183
263
|
issuingAuthority: z.string(),
|
|
184
264
|
issueDate: z.date(),
|
|
@@ -187,140 +267,187 @@ const IdentityDocument = z.object({
|
|
|
187
267
|
verified: z.boolean().default(false),
|
|
188
268
|
});
|
|
189
269
|
const PassportDocument = z.object({
|
|
190
|
-
type: z.literal(
|
|
270
|
+
type: z.literal("passport"),
|
|
191
271
|
number: z.string().regex(/^[A-Z0-9]{8,12}$/),
|
|
192
272
|
country: z.string().length(3),
|
|
193
273
|
nationality: z.string(),
|
|
194
274
|
issueDate: z.date(),
|
|
195
275
|
expiryDate: z.date(),
|
|
196
|
-
visaInfo: z
|
|
276
|
+
visaInfo: z
|
|
277
|
+
.array(z.object({
|
|
197
278
|
country: z.string().length(3),
|
|
198
279
|
type: z.string(),
|
|
199
280
|
issueDate: z.date(),
|
|
200
281
|
expiryDate: z.date(),
|
|
201
|
-
}))
|
|
282
|
+
}))
|
|
283
|
+
.max(5)
|
|
284
|
+
.optional(),
|
|
202
285
|
});
|
|
203
286
|
const ProfessionalDocument = z.object({
|
|
204
|
-
type: z.literal(
|
|
287
|
+
type: z.literal("professional"),
|
|
205
288
|
number: z.string().regex(/^[A-Z0-9]{5,15}$/),
|
|
206
289
|
category: z.string(),
|
|
207
290
|
council: z.string(),
|
|
208
291
|
state: z.string().length(2),
|
|
209
292
|
validity: z.date(),
|
|
210
293
|
});
|
|
211
|
-
const Documents = z
|
|
294
|
+
const Documents = z
|
|
295
|
+
.array(z.union([IdentityDocument, PassportDocument, ProfessionalDocument]))
|
|
296
|
+
.max(5)
|
|
297
|
+
.optional();
|
|
212
298
|
const HealthInfo = z.object({
|
|
213
|
-
bloodType: z
|
|
299
|
+
bloodType: z
|
|
300
|
+
.enum(["A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-"])
|
|
301
|
+
.optional(),
|
|
214
302
|
allergies: z.array(z.string()).max(20).optional(),
|
|
215
|
-
medications: z
|
|
303
|
+
medications: z
|
|
304
|
+
.array(z.object({
|
|
216
305
|
name: z.string(),
|
|
217
306
|
dosage: z.string(),
|
|
218
307
|
frequency: z.string(),
|
|
219
308
|
prescribedBy: z.string().optional(),
|
|
220
|
-
}))
|
|
221
|
-
|
|
309
|
+
}))
|
|
310
|
+
.max(10)
|
|
311
|
+
.optional(),
|
|
312
|
+
disabilities: z
|
|
313
|
+
.array(z.object({
|
|
222
314
|
type: z.string(),
|
|
223
315
|
description: z.string(),
|
|
224
316
|
accommodations: z.array(z.string()).optional(),
|
|
225
|
-
}))
|
|
226
|
-
|
|
317
|
+
}))
|
|
318
|
+
.max(5)
|
|
319
|
+
.optional(),
|
|
320
|
+
emergencyMedicalContacts: z
|
|
321
|
+
.array(z.object({
|
|
227
322
|
name: z.string(),
|
|
228
323
|
relationship: z.string(),
|
|
229
324
|
phone: z.string().regex(/^\d{10,11}$/),
|
|
230
325
|
priority: z.number().min(1).max(3),
|
|
231
|
-
}))
|
|
326
|
+
}))
|
|
327
|
+
.max(3)
|
|
328
|
+
.optional(),
|
|
232
329
|
});
|
|
233
330
|
const Preferences = z.object({
|
|
234
331
|
notification: z.object({
|
|
235
332
|
email: z.boolean().default(true),
|
|
236
333
|
sms: z.boolean().default(false),
|
|
237
334
|
push: z.boolean().default(true),
|
|
238
|
-
digest: z.enum([
|
|
335
|
+
digest: z.enum(["daily", "weekly", "monthly", "never"]).default("weekly"),
|
|
239
336
|
}),
|
|
240
337
|
privacy: z.object({
|
|
241
338
|
profileVisible: z.boolean().default(true),
|
|
242
339
|
searchable: z.boolean().default(true),
|
|
243
340
|
showEmail: z.boolean().default(false),
|
|
244
341
|
showPhone: z.boolean().default(false),
|
|
245
|
-
dataSharing: z.enum([
|
|
342
|
+
dataSharing: z.enum(["none", "essential", "all"]).default("essential"),
|
|
246
343
|
}),
|
|
247
|
-
language: z.string().default(
|
|
248
|
-
timeFormat: z.enum([
|
|
249
|
-
dateFormat: z
|
|
344
|
+
language: z.string().default("pt-BR"),
|
|
345
|
+
timeFormat: z.enum(["12h", "24h"]).default("24h"),
|
|
346
|
+
dateFormat: z
|
|
347
|
+
.enum(["DD/MM/YYYY", "MM/DD/YYYY", "YYYY-MM-DD"])
|
|
348
|
+
.default("DD/MM/YYYY"),
|
|
250
349
|
});
|
|
251
|
-
const StatusHistory = z
|
|
252
|
-
|
|
350
|
+
const StatusHistory = z
|
|
351
|
+
.array(z.object({
|
|
352
|
+
status: z.enum([
|
|
353
|
+
"active",
|
|
354
|
+
"inactive",
|
|
355
|
+
"pending",
|
|
356
|
+
"suspended",
|
|
357
|
+
"graduated",
|
|
358
|
+
"terminated",
|
|
359
|
+
]),
|
|
253
360
|
effectiveDate: z.date(),
|
|
254
361
|
reason: z.string().optional(),
|
|
255
362
|
changedBy: z.uuid().optional(),
|
|
256
|
-
}))
|
|
363
|
+
}))
|
|
364
|
+
.min(1);
|
|
257
365
|
const StudentMetadata = z.object({
|
|
258
366
|
advisorId: z.uuid().optional(),
|
|
259
367
|
thesisTitle: z.string().optional(),
|
|
260
368
|
researchArea: z.string().optional(),
|
|
261
|
-
publications: z
|
|
369
|
+
publications: z
|
|
370
|
+
.array(z.object({
|
|
262
371
|
title: z.string(),
|
|
263
372
|
year: z.number().int().min(2000).max(2030),
|
|
264
373
|
venue: z.string().optional(),
|
|
265
|
-
}))
|
|
374
|
+
}))
|
|
375
|
+
.max(20)
|
|
376
|
+
.optional(),
|
|
266
377
|
});
|
|
267
378
|
const TeacherMetadata = z.object({
|
|
268
379
|
researchInterests: z.array(z.string()).max(10).optional(),
|
|
269
380
|
publicationsCount: z.number().int().min(0),
|
|
270
|
-
grants: z
|
|
381
|
+
grants: z
|
|
382
|
+
.array(z.object({
|
|
271
383
|
id: z.string(),
|
|
272
384
|
title: z.string(),
|
|
273
385
|
fundingAgency: z.string(),
|
|
274
386
|
amount: z.number().positive(),
|
|
275
387
|
period: z.string(),
|
|
276
|
-
}))
|
|
388
|
+
}))
|
|
389
|
+
.max(10)
|
|
390
|
+
.optional(),
|
|
277
391
|
officeLocation: z.string(),
|
|
278
392
|
});
|
|
279
393
|
const AdminMetadata = z.object({
|
|
280
394
|
budgetResponsibility: z.number().positive().optional(),
|
|
281
395
|
teamSize: z.number().int().min(0),
|
|
282
|
-
projects: z
|
|
396
|
+
projects: z
|
|
397
|
+
.array(z.object({
|
|
283
398
|
name: z.string(),
|
|
284
|
-
status: z.enum([
|
|
399
|
+
status: z.enum(["planning", "active", "completed", "cancelled"]),
|
|
285
400
|
deadline: z.date().optional(),
|
|
286
|
-
}))
|
|
401
|
+
}))
|
|
402
|
+
.max(10)
|
|
403
|
+
.optional(),
|
|
287
404
|
});
|
|
288
|
-
const Metadata = z.union([
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
AdminMetadata,
|
|
292
|
-
]);
|
|
293
|
-
export const PersonEntitySchema = z.object({
|
|
405
|
+
const Metadata = z.union([StudentMetadata, TeacherMetadata, AdminMetadata]);
|
|
406
|
+
export const PersonEntitySchema = z
|
|
407
|
+
.object({
|
|
294
408
|
name: z.object({
|
|
295
409
|
firstName: z.string().min(2).max(50),
|
|
296
410
|
lastName: z.string().min(2).max(50),
|
|
297
411
|
middleName: z.string().optional(),
|
|
298
412
|
preferredName: z.string().optional(),
|
|
299
|
-
title: z.enum([
|
|
413
|
+
title: z.enum(["Mr.", "Mrs.", "Ms.", "Dr.", "Prof."]).optional(),
|
|
300
414
|
}),
|
|
301
415
|
demographic: z.object({
|
|
302
416
|
birthDate: z.date(),
|
|
303
417
|
age: z.number().int().min(0).max(120),
|
|
304
|
-
gender: z.enum([
|
|
418
|
+
gender: z.enum(["male", "female", "non_binary", "prefer_not_to_say"]),
|
|
305
419
|
nationality: z.string(),
|
|
306
|
-
maritalStatus: z
|
|
307
|
-
|
|
308
|
-
|
|
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(),
|
|
420
|
+
maritalStatus: z
|
|
421
|
+
.enum(["single", "married", "divorced", "widowed"])
|
|
422
|
+
.optional(),
|
|
313
423
|
}),
|
|
314
424
|
role: PersonRole,
|
|
315
|
-
status: z.enum([
|
|
425
|
+
status: z.enum([
|
|
426
|
+
"active",
|
|
427
|
+
"inactive",
|
|
428
|
+
"pending",
|
|
429
|
+
"suspended",
|
|
430
|
+
"graduated",
|
|
431
|
+
"terminated",
|
|
432
|
+
]),
|
|
316
433
|
statusHistory: StatusHistory,
|
|
317
|
-
emergencyContacts: z
|
|
434
|
+
emergencyContacts: z
|
|
435
|
+
.array(z.object({
|
|
318
436
|
name: z.string(),
|
|
319
437
|
phone: z.string().regex(/^\d{10,11}$/),
|
|
320
|
-
relationship: z.enum([
|
|
438
|
+
relationship: z.enum([
|
|
439
|
+
"parent",
|
|
440
|
+
"spouse",
|
|
441
|
+
"child",
|
|
442
|
+
"sibling",
|
|
443
|
+
"friend",
|
|
444
|
+
"other",
|
|
445
|
+
]),
|
|
321
446
|
priority: z.number().min(1).max(3),
|
|
322
447
|
availableHours: z.string().optional(),
|
|
323
|
-
}))
|
|
448
|
+
}))
|
|
449
|
+
.min(1)
|
|
450
|
+
.max(5),
|
|
324
451
|
documents: Documents,
|
|
325
452
|
contactInfo: ContactInfo,
|
|
326
453
|
addresses: z.array(Address).min(1).max(3),
|
|
@@ -335,12 +462,16 @@ export const PersonEntitySchema = z.object({
|
|
|
335
462
|
lastLogin: z.date().optional(),
|
|
336
463
|
loginCount: z.number().int().min(0).default(0),
|
|
337
464
|
tags: z.array(z.string()).max(20).optional(),
|
|
338
|
-
flags: z
|
|
465
|
+
flags: z
|
|
466
|
+
.array(z.enum(["high_value", "at_risk", "vip", "fraud_risk", "legacy"]))
|
|
467
|
+
.optional(),
|
|
339
468
|
}),
|
|
340
|
-
})
|
|
341
|
-
|
|
469
|
+
})
|
|
470
|
+
.and(Identifiable)
|
|
471
|
+
.and(Auditable);
|
|
472
|
+
describe("PersonEntity with Complex Schema", () => {
|
|
342
473
|
const entityMock = new ZodMockSchema(PersonEntitySchema);
|
|
343
|
-
test(
|
|
474
|
+
test("should generate complex mock data", () => {
|
|
344
475
|
const mock = entityMock.generate();
|
|
345
476
|
expect(mock).toBeDefined();
|
|
346
477
|
expect(mock.role).toBeDefined();
|
|
@@ -348,16 +479,16 @@ describe('PersonEntity with Complex Schema', () => {
|
|
|
348
479
|
expect(mock.addresses.length).toBeGreaterThan(0);
|
|
349
480
|
});
|
|
350
481
|
});
|
|
351
|
-
describe(
|
|
352
|
-
describe(
|
|
353
|
-
test(
|
|
482
|
+
describe("New Zod Types Support", () => {
|
|
483
|
+
describe("ZodSet", () => {
|
|
484
|
+
test("should generate a Set with elements", () => {
|
|
354
485
|
const schema = z.set(z.string());
|
|
355
486
|
const mock = new ZodMockSchema(schema);
|
|
356
487
|
const result = mock.generate();
|
|
357
488
|
expect(result).toBeInstanceOf(Set);
|
|
358
489
|
expect(result.size).toBeGreaterThan(0);
|
|
359
490
|
});
|
|
360
|
-
test(
|
|
491
|
+
test("should respect min/max size constraints", () => {
|
|
361
492
|
const schema = z.set(z.number()).min(2).max(5);
|
|
362
493
|
const mock = new ZodMockSchema(schema);
|
|
363
494
|
const result = mock.generate();
|
|
@@ -366,8 +497,8 @@ describe('New Zod Types Support', () => {
|
|
|
366
497
|
expect(result.size).toBeLessThanOrEqual(5);
|
|
367
498
|
});
|
|
368
499
|
});
|
|
369
|
-
describe(
|
|
370
|
-
test(
|
|
500
|
+
describe("ZodMap", () => {
|
|
501
|
+
test("should generate a Map with entries", () => {
|
|
371
502
|
const schema = z.map(z.string(), z.number());
|
|
372
503
|
const mock = new ZodMockSchema(schema);
|
|
373
504
|
const result = mock.generate();
|
|
@@ -375,89 +506,89 @@ describe('New Zod Types Support', () => {
|
|
|
375
506
|
expect(result.size).toBeGreaterThan(0);
|
|
376
507
|
});
|
|
377
508
|
});
|
|
378
|
-
describe(
|
|
379
|
-
test(
|
|
509
|
+
describe("ZodTuple", () => {
|
|
510
|
+
test("should generate a tuple with correct types", () => {
|
|
380
511
|
const schema = z.tuple([z.string(), z.number(), z.boolean()]);
|
|
381
512
|
const mock = new ZodMockSchema(schema);
|
|
382
513
|
const result = mock.generate();
|
|
383
514
|
expect(Array.isArray(result)).toBe(true);
|
|
384
515
|
expect(result).toHaveLength(3);
|
|
385
|
-
expect(typeof result[0]).toBe(
|
|
386
|
-
expect(typeof result[1]).toBe(
|
|
387
|
-
expect(typeof result[2]).toBe(
|
|
516
|
+
expect(typeof result[0]).toBe("string");
|
|
517
|
+
expect(typeof result[1]).toBe("number");
|
|
518
|
+
expect(typeof result[2]).toBe("boolean");
|
|
388
519
|
});
|
|
389
|
-
test(
|
|
520
|
+
test("should generate tuple with rest elements", () => {
|
|
390
521
|
const schema = z.tuple([z.string()]).rest(z.number());
|
|
391
522
|
const mock = new ZodMockSchema(schema);
|
|
392
523
|
const result = mock.generate();
|
|
393
524
|
expect(Array.isArray(result)).toBe(true);
|
|
394
525
|
expect(result.length).toBeGreaterThanOrEqual(1);
|
|
395
|
-
expect(typeof result[0]).toBe(
|
|
526
|
+
expect(typeof result[0]).toBe("string");
|
|
396
527
|
});
|
|
397
528
|
});
|
|
398
|
-
describe(
|
|
399
|
-
test(
|
|
529
|
+
describe("ZodFunction", () => {
|
|
530
|
+
test("should generate a function that returns mocked value", () => {
|
|
400
531
|
const schema = z.function();
|
|
401
532
|
const mock = new ZodMockSchema(schema);
|
|
402
533
|
const result = mock.generate();
|
|
403
|
-
expect(typeof result).toBe(
|
|
534
|
+
expect(typeof result).toBe("function");
|
|
404
535
|
expect(result).toBeDefined();
|
|
405
536
|
});
|
|
406
537
|
});
|
|
407
|
-
describe(
|
|
408
|
-
test(
|
|
409
|
-
const schema = z.discriminatedUnion(
|
|
410
|
-
z.object({ type: z.literal(
|
|
411
|
-
z.object({ type: z.literal(
|
|
538
|
+
describe("ZodDiscriminatedUnion", () => {
|
|
539
|
+
test("should generate one of the union options", () => {
|
|
540
|
+
const schema = z.discriminatedUnion("type", [
|
|
541
|
+
z.object({ type: z.literal("a"), value: z.string() }),
|
|
542
|
+
z.object({ type: z.literal("b"), value: z.number() }),
|
|
412
543
|
]);
|
|
413
544
|
const mock = new ZodMockSchema(schema);
|
|
414
545
|
const result = mock.generate();
|
|
415
546
|
expect(result).toBeDefined();
|
|
416
|
-
expect([
|
|
547
|
+
expect(["a", "b"]).toContain(result.type);
|
|
417
548
|
});
|
|
418
549
|
});
|
|
419
|
-
describe(
|
|
420
|
-
test(
|
|
550
|
+
describe("ZodBigInt", () => {
|
|
551
|
+
test("should generate a BigInt", () => {
|
|
421
552
|
const schema = z.bigint();
|
|
422
553
|
const mock = new ZodMockSchema(schema);
|
|
423
554
|
const result = mock.generate();
|
|
424
|
-
expect(typeof result).toBe(
|
|
555
|
+
expect(typeof result).toBe("bigint");
|
|
425
556
|
expect(result).toBeGreaterThan(BigInt(0));
|
|
426
557
|
});
|
|
427
558
|
});
|
|
428
|
-
describe(
|
|
429
|
-
test(
|
|
559
|
+
describe("ZodNaN", () => {
|
|
560
|
+
test("should generate NaN", () => {
|
|
430
561
|
const schema = z.nan();
|
|
431
562
|
const mock = new ZodMockSchema(schema);
|
|
432
563
|
const result = mock.generate();
|
|
433
564
|
expect(Number.isNaN(result)).toBe(true);
|
|
434
565
|
});
|
|
435
566
|
});
|
|
436
|
-
describe(
|
|
437
|
-
test(
|
|
567
|
+
describe("ZodReadonly", () => {
|
|
568
|
+
test("should generate readonly object", () => {
|
|
438
569
|
const schema = z.object({ name: z.string() }).readonly();
|
|
439
570
|
const mock = new ZodMockSchema(schema);
|
|
440
571
|
const result = mock.generate();
|
|
441
572
|
expect(result).toBeDefined();
|
|
442
|
-
expect(typeof result.name).toBe(
|
|
573
|
+
expect(typeof result.name).toBe("string");
|
|
443
574
|
});
|
|
444
575
|
});
|
|
445
576
|
});
|
|
446
|
-
describe(
|
|
447
|
-
describe(
|
|
448
|
-
test(
|
|
577
|
+
describe("Improved Constraints", () => {
|
|
578
|
+
describe("String min/max", () => {
|
|
579
|
+
test("should respect min length", () => {
|
|
449
580
|
const schema = z.string().min(10);
|
|
450
581
|
const mock = new ZodMockSchema(schema);
|
|
451
582
|
const result = mock.generate();
|
|
452
583
|
expect(result.length).toBeGreaterThanOrEqual(10);
|
|
453
584
|
});
|
|
454
|
-
test(
|
|
585
|
+
test("should respect max length", () => {
|
|
455
586
|
const schema = z.string().max(5);
|
|
456
587
|
const mock = new ZodMockSchema(schema);
|
|
457
588
|
const result = mock.generate();
|
|
458
589
|
expect(result.length).toBeLessThanOrEqual(5);
|
|
459
590
|
});
|
|
460
|
-
test(
|
|
591
|
+
test("should respect both min and max", () => {
|
|
461
592
|
const schema = z.string().min(5).max(10);
|
|
462
593
|
const mock = new ZodMockSchema(schema);
|
|
463
594
|
const result = mock.generate();
|
|
@@ -465,10 +596,10 @@ describe('Improved Constraints', () => {
|
|
|
465
596
|
expect(result.length).toBeLessThanOrEqual(10);
|
|
466
597
|
});
|
|
467
598
|
});
|
|
468
|
-
describe(
|
|
469
|
-
test(
|
|
470
|
-
const minDate = new Date(
|
|
471
|
-
const maxDate = new Date(
|
|
599
|
+
describe("Date min/max", () => {
|
|
600
|
+
test("should respect date range", () => {
|
|
601
|
+
const minDate = new Date("2025-01-01");
|
|
602
|
+
const maxDate = new Date("2025-12-31");
|
|
472
603
|
const schema = z.date().min(minDate).max(maxDate);
|
|
473
604
|
const mock = new ZodMockSchema(schema);
|
|
474
605
|
const result = mock.generate();
|
|
@@ -477,14 +608,14 @@ describe('Improved Constraints', () => {
|
|
|
477
608
|
expect(result.getTime()).toBeLessThanOrEqual(maxDate.getTime());
|
|
478
609
|
});
|
|
479
610
|
});
|
|
480
|
-
describe(
|
|
481
|
-
test(
|
|
482
|
-
const schema = z.string().default(
|
|
611
|
+
describe("ZodDefault always uses default value", () => {
|
|
612
|
+
test("should always return the default value", () => {
|
|
613
|
+
const schema = z.string().default("DEFAULT_VALUE");
|
|
483
614
|
const mock = new ZodMockSchema(schema);
|
|
484
615
|
const results = Array.from({ length: 10 }, () => mock.generate());
|
|
485
|
-
expect(results.every(r => r ===
|
|
616
|
+
expect(results.every((r) => r === "DEFAULT_VALUE")).toBe(true);
|
|
486
617
|
});
|
|
487
|
-
test(
|
|
618
|
+
test("should work with default numbers", () => {
|
|
488
619
|
const schema = z.number().default(42);
|
|
489
620
|
const mock = new ZodMockSchema(schema);
|
|
490
621
|
const result = mock.generate();
|
|
@@ -492,8 +623,8 @@ describe('Improved Constraints', () => {
|
|
|
492
623
|
});
|
|
493
624
|
});
|
|
494
625
|
});
|
|
495
|
-
describe(
|
|
496
|
-
test(
|
|
626
|
+
describe("Seed Support", () => {
|
|
627
|
+
test("should generate same data with same seed", () => {
|
|
497
628
|
const schema = z.object({
|
|
498
629
|
name: z.string(),
|
|
499
630
|
age: z.number(),
|
|
@@ -505,7 +636,7 @@ describe('Seed Support', () => {
|
|
|
505
636
|
const result2 = mock2.generate();
|
|
506
637
|
expect(result1).toEqual(result2);
|
|
507
638
|
});
|
|
508
|
-
test(
|
|
639
|
+
test("should generate different data with different seeds", () => {
|
|
509
640
|
const schema = z.object({
|
|
510
641
|
name: z.string(),
|
|
511
642
|
age: z.number(),
|
|
@@ -516,11 +647,64 @@ describe('Seed Support', () => {
|
|
|
516
647
|
const result2 = mock2.generate();
|
|
517
648
|
expect(result1).not.toEqual(result2);
|
|
518
649
|
});
|
|
519
|
-
test(
|
|
650
|
+
test("should support array seed", () => {
|
|
520
651
|
const schema = z.string();
|
|
521
652
|
const mock = new ZodMockSchema(schema).seed([1, 2, 3]);
|
|
522
653
|
const result = mock.generate();
|
|
523
|
-
expect(typeof result).toBe(
|
|
654
|
+
expect(typeof result).toBe("string");
|
|
655
|
+
});
|
|
656
|
+
describe("Coerce pipe", () => {
|
|
657
|
+
it("should throw for coerce pipes", () => {
|
|
658
|
+
const schema = z.object({
|
|
659
|
+
value: z.string().pipe(z.coerce.number()),
|
|
660
|
+
});
|
|
661
|
+
const mock = new ZodMockSchema(schema);
|
|
662
|
+
expect(() => mock.generate()).toThrow(/Pipe with coerce/);
|
|
663
|
+
});
|
|
664
|
+
});
|
|
665
|
+
describe("Regex check", () => {
|
|
666
|
+
it("should generate a string that satisfies .regex(/:/)", () => {
|
|
667
|
+
const schema = z.string().regex(/:/);
|
|
668
|
+
const mock = new ZodMockSchema(schema);
|
|
669
|
+
const data = mock.generate();
|
|
670
|
+
expect(data).toContain(":");
|
|
671
|
+
});
|
|
672
|
+
it("should generate a string that satisfies a more expressive regex", () => {
|
|
673
|
+
const schema = z.string().regex(/^[a-z]+:[a-z]+$/);
|
|
674
|
+
const mock = new ZodMockSchema(schema);
|
|
675
|
+
const data = mock.generate();
|
|
676
|
+
expect(data).toMatch(/^[a-z]+:[a-z]+$/);
|
|
677
|
+
});
|
|
678
|
+
});
|
|
679
|
+
describe("Regex + transform", () => {
|
|
680
|
+
it('should generate a string with ":" and apply the transform', () => {
|
|
681
|
+
const Name = z
|
|
682
|
+
.string()
|
|
683
|
+
.regex(/^[a-z]+:[a-z]+$/)
|
|
684
|
+
.transform((value) => value.trim().replace(/ /g, "_").toLowerCase());
|
|
685
|
+
const schema = z.object({ name: Name });
|
|
686
|
+
const mock = new ZodMockSchema(schema);
|
|
687
|
+
const data = mock.generate();
|
|
688
|
+
expect(data.name).toContain(":");
|
|
689
|
+
expect(data.name).toBe(data.name.toLowerCase());
|
|
690
|
+
expect(data.name).not.toContain(" ");
|
|
691
|
+
});
|
|
692
|
+
it("should respect the regex even with overrides", () => {
|
|
693
|
+
const Name = z
|
|
694
|
+
.string()
|
|
695
|
+
.regex(/^[a-z]+:[a-z]+$/)
|
|
696
|
+
.transform((value) => value.trim().replace(/ /g, "_").toLowerCase());
|
|
697
|
+
const schema = z.object({ name: Name });
|
|
698
|
+
const mock = new ZodMockSchema(schema);
|
|
699
|
+
const data = mock.generate({ overrides: { name: "user:read" } });
|
|
700
|
+
expect(data.name).toBe("user:read");
|
|
701
|
+
});
|
|
702
|
+
it("should keep regex-generated strings short when there is no maxLength", () => {
|
|
703
|
+
const schema = z.string().regex(/^[a-z]+:[a-z]+$/);
|
|
704
|
+
const mock = new ZodMockSchema(schema);
|
|
705
|
+
const data = mock.generate();
|
|
706
|
+
expect(data.length).toBeLessThanOrEqual(50);
|
|
707
|
+
});
|
|
524
708
|
});
|
|
525
709
|
});
|
|
526
710
|
//# sourceMappingURL=zod-types.spec.js.map
|