vsrepo 1.2.6 → 1.2.7
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 +296 -437
- package/{VSRepository → dist}/VSRepoError.d.ts +1 -1
- package/dist/VSRepoError.js +17 -0
- package/{VSRepository → dist}/VSRepository.d.ts +937 -907
- package/dist/VSRepository.js +204 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/internal/errors/types/vs-repo-error-type.type.js +2 -0
- package/dist/internal/errors/vs-repo.error.js +27 -0
- package/dist/internal/resolvers/base-methods.resolve.js +535 -0
- package/dist/internal/resolvers/create-update-payloads-with-relations.resolve.js +143 -0
- package/dist/internal/resolvers/data-payload-with-relations.resolve.js +60 -0
- package/dist/internal/resolvers/dbAndPrismaArgs.resolve.js +46 -0
- package/dist/internal/resolvers/dinamic-method-customization.resolve.js +45 -0
- package/dist/internal/resolvers/dinamic-method-info.resolve.js +265 -0
- package/dist/internal/resolvers/merge-wheres.resolve.js +22 -0
- package/dist/internal/resolvers/pretty-wheres.resolve.js +87 -0
- package/dist/internal/resolvers/select.resolve.js +7 -0
- package/dist/internal/resolvers/specific-where.resolve.js +77 -0
- package/dist/internal/resolvers/types/base-method-function.type.js +2 -0
- package/dist/internal/resolvers/types/dinamic-method-customization.type.js +2 -0
- package/dist/internal/resolvers/types/dinamic-method-info.type.js +2 -0
- package/dist/internal/resolvers/types/dinamic-method-where-ops.type.js +2 -0
- package/dist/internal/resolvers/types/pretty-where.type.js +2 -0
- package/dist/internal/resolvers/types/prisma-args.type.js +2 -0
- package/dist/internal/resolvers/types/repository-build-instance.type.js +2 -0
- package/dist/internal/resolvers/types/resolve-db-and-prisma-args-data.type.js +2 -0
- package/dist/internal/resolvers/types/ugly-where.type.js +2 -0
- package/dist/internal/resolvers/ugly-where.resolve.js +178 -0
- package/dist/internal/utils/logger.util.js +21 -0
- package/dist/internal/utils/schemas.util.js +10 -0
- package/dist/internal/utils/uncapitalize.util.js +6 -0
- package/dist/internal/validation/build-config.validate.js +84 -0
- package/dist/internal/validation/constructor-config.validate.js +68 -0
- package/dist/internal/validation/extension.validate.js +15 -0
- package/dist/internal/validation/is-object.validate.js +6 -0
- package/dist/internal/validation/method-options.validate.js +26 -0
- package/dist/internal/validation/obj-with-relations.validate.js +37 -0
- package/dist/internal/validation/prisma-client.validate.js +10 -0
- package/dist/internal/validation/types/base-methods.type.js +2 -0
- package/dist/internal/validation/types/build-config.type.js +2 -0
- package/dist/internal/validation/types/constructor-config.type.js +2 -0
- package/dist/internal/validation/types/method-options.type.js +2 -0
- package/dist/internal/validation/types/method.type.js +2 -0
- package/dist/internal/validation/types/pagination.type.js +2 -0
- package/dist/internal/validation/types/relation.type.js +2 -0
- package/dist/internal/validation/types/see-mode.type.js +2 -0
- package/package.json +72 -70
- package/scripts/configure-prisma-import.mjs +3 -3
- package/scripts/copy-types.mjs +24 -0
- package/VSRepository/VSRepoError.js +0 -33
- package/VSRepository/VSRepoUtils.js +0 -155
- package/VSRepository/VSRepository.js +0 -1445
- package/VSRepository/index.d.ts +0 -2
- package/VSRepository/index.js +0 -2
|
@@ -1,907 +1,937 @@
|
|
|
1
|
-
import { Prisma, PrismaClient } from '
|
|
2
|
-
import { Decimal, JsonValue } from '@prisma/client/runtime/client';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
type
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
S extends `${infer Base}
|
|
86
|
-
S extends `${infer Base}
|
|
87
|
-
S extends `${infer Base}
|
|
88
|
-
S extends `${infer Base}
|
|
89
|
-
S extends `${infer Base}
|
|
90
|
-
S extends `${infer Base}
|
|
91
|
-
S extends `${infer Base}
|
|
92
|
-
S extends `${infer Base}
|
|
93
|
-
S extends `${infer Base}
|
|
94
|
-
S extends `${infer Base}
|
|
95
|
-
S extends `${infer Base}
|
|
96
|
-
S extends `${infer Base}
|
|
97
|
-
S
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
type
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
type
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
type
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
]
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
type
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
K extends `
|
|
288
|
-
K extends `
|
|
289
|
-
K extends `
|
|
290
|
-
K extends
|
|
291
|
-
K extends
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
K extends
|
|
296
|
-
K extends `
|
|
297
|
-
K extends `
|
|
298
|
-
K extends `
|
|
299
|
-
K extends `
|
|
300
|
-
K extends `
|
|
301
|
-
K extends `
|
|
302
|
-
K extends `
|
|
303
|
-
K extends `
|
|
304
|
-
K extends `
|
|
305
|
-
K extends `
|
|
306
|
-
K extends `
|
|
307
|
-
K extends `
|
|
308
|
-
K extends `
|
|
309
|
-
K extends `
|
|
310
|
-
K extends `
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
K extends
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
*/
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
|
|
395
|
-
*/
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
|
|
446
|
-
/**
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
/**
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
type
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
type
|
|
581
|
-
|
|
582
|
-
?
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
TSelects
|
|
656
|
-
TDefault
|
|
657
|
-
TPk
|
|
658
|
-
TRelations =
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
options?: { db?:
|
|
690
|
-
)
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
TSelects
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
pk:
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
*/
|
|
783
|
-
|
|
784
|
-
/**
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
/**
|
|
795
|
-
|
|
796
|
-
*/
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
:
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
*
|
|
806
|
-
*/
|
|
807
|
-
export type
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
*/
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
*
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
*
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
>
|
|
906
|
-
|
|
907
|
-
|
|
1
|
+
import { Prisma, PrismaClient } from '../generated/prisma/client';
|
|
2
|
+
import { Decimal, JsonValue } from '@prisma/client/runtime/client';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Achata uma interseção de tipos em um único objeto,
|
|
6
|
+
* evitando o erro "union type too complex to represent" do TypeScript.
|
|
7
|
+
*/
|
|
8
|
+
type Simplify<T> = { [K in keyof T]: T[K] } & {};
|
|
9
|
+
|
|
10
|
+
type WidenField<T> =
|
|
11
|
+
T extends bigint ? bigint | number :
|
|
12
|
+
T extends Date ? Date | string :
|
|
13
|
+
T extends Decimal ? Decimal | string | number :
|
|
14
|
+
T extends readonly [infer U, infer V] ? [WidenField<U>, WidenField<V>] :
|
|
15
|
+
T extends Array<infer U> ? WidenField<U>[] :
|
|
16
|
+
T;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Instância completa do Prisma Client usada para construir repositories.
|
|
20
|
+
*/
|
|
21
|
+
export type DbClient = PrismaClient;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Cliente transacional do Prisma retornado por `prisma.$transaction`.
|
|
25
|
+
*/
|
|
26
|
+
export type DbTransaction = Prisma.TransactionClient;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Aceita tanto o cliente principal do Prisma quanto um cliente de transação.
|
|
30
|
+
*/
|
|
31
|
+
export type ClientOrTransaction = DbClient | DbTransaction;
|
|
32
|
+
|
|
33
|
+
export * from './VSRepoError';
|
|
34
|
+
|
|
35
|
+
type OrderPattern = {
|
|
36
|
+
[key: string]: 'asc' | 'desc' | { _count: 'asc' | 'desc' } | OrderPattern;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Opções de paginação aceitas pelos métodos com sufixo `Paginated`.
|
|
41
|
+
*
|
|
42
|
+
* @template TCursor Tipo do cursor usado pelo modelo Prisma.
|
|
43
|
+
*/
|
|
44
|
+
export type PaginationOptions<TCursor = unknown> = {
|
|
45
|
+
/** Quantidade de registros a ignorar. */
|
|
46
|
+
skip?: number;
|
|
47
|
+
/** Quantidade máxima de registros retornados. */
|
|
48
|
+
take?: number;
|
|
49
|
+
/** Cursor tipado para paginação baseada em posição. */
|
|
50
|
+
cursor?: TCursor;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Ordenação aceita pelos métodos do repository.
|
|
55
|
+
*
|
|
56
|
+
* Pode ser uma única ordenação ou uma lista de ordenações encadeadas.
|
|
57
|
+
*/
|
|
58
|
+
export type OrderOptions = OrderPattern | OrderPattern[];
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Modo de visibilidade para registros com soft-delete.
|
|
62
|
+
*
|
|
63
|
+
* - `"active"` — retorna apenas registros não removidos (padrão).
|
|
64
|
+
* - `"removed"` — retorna apenas registros removidos.
|
|
65
|
+
* - `"all"` — retorna todos os registros, independentemente do status.
|
|
66
|
+
*/
|
|
67
|
+
export type SeeMode = 'active' | 'removed' | 'all';
|
|
68
|
+
|
|
69
|
+
type ValidMethodPatterns =
|
|
70
|
+
| `existsBy${string}` | `findBy${string}`
|
|
71
|
+
| `findUniqueBy${string}` | `findUniqueOrThrowBy${string}`
|
|
72
|
+
| `findFirstBy${string}` | `findFirst${string}`
|
|
73
|
+
| `findFirstOrThrowBy${string}` | `findFirstOrThrow${string}`
|
|
74
|
+
| `findManyBy${string}` | `findMany${string}`
|
|
75
|
+
| `createManyAndReturn${string}` | `createMany${string}`
|
|
76
|
+
| `create${string}` | `updateManyAndReturnBy${string}` | `updateManyBy${string}`
|
|
77
|
+
| `updateBy${string}` | `upsertBy${string}` | `deleteManyBy${string}`
|
|
78
|
+
| `deleteBy${string}` | `countBy${string}` | `count${string}` | `countWhere${string}`
|
|
79
|
+
| `findWhere${string}` | `findListWhere${string}`
|
|
80
|
+
| `existsWhere${string}` | `updateManyWhere${string}` | `deleteManyWhere${string}`
|
|
81
|
+
| `findOneWhere${string}` | `findOneBy${string}` | `updateManyAndReturnWhere${string}`
|
|
82
|
+
| 'aggregate' | 'groupBy';
|
|
83
|
+
|
|
84
|
+
type StripModifier<S extends string> =
|
|
85
|
+
S extends `${infer Base}NotStartsWithInsensitive` ? Base :
|
|
86
|
+
S extends `${infer Base}StartsWithInsensitive` ? Base :
|
|
87
|
+
S extends `${infer Base}NotEndsWithInsensitive` ? Base :
|
|
88
|
+
S extends `${infer Base}EndsWithInsensitive` ? Base :
|
|
89
|
+
S extends `${infer Base}NotContainsInsensitive` ? Base :
|
|
90
|
+
S extends `${infer Base}ContainsInsensitive` ? Base :
|
|
91
|
+
S extends `${infer Base}NotInInsensitive` ? Base :
|
|
92
|
+
S extends `${infer Base}InInsensitive` ? Base :
|
|
93
|
+
S extends `${infer Base}NotInsensitive` ? Base :
|
|
94
|
+
S extends `${infer Base}NotStartsWith` ? Base :
|
|
95
|
+
S extends `${infer Base}StartsWith` ? Base :
|
|
96
|
+
S extends `${infer Base}NotEndsWith` ? Base :
|
|
97
|
+
S extends `${infer Base}EndsWith` ? Base :
|
|
98
|
+
S extends `${infer Base}NotContains` ? Base :
|
|
99
|
+
S extends `${infer Base}Contains` ? Base :
|
|
100
|
+
S extends `${infer Base}NotIn` ? Base :
|
|
101
|
+
S extends `${infer Base}In` ? Base :
|
|
102
|
+
S extends `${infer Base}NotBetween` ? Base :
|
|
103
|
+
S extends `${infer Base}Between` ? Base :
|
|
104
|
+
S extends `${infer Base}Not` ? Base :
|
|
105
|
+
S extends `${infer Base}LessThanEqual` ? Base :
|
|
106
|
+
S extends `${infer Base}LessThan` ? Base :
|
|
107
|
+
S extends `${infer Base}GreaterThanEqual` ? Base :
|
|
108
|
+
S extends `${infer Base}GreaterThan` ? Base :
|
|
109
|
+
S extends `${infer Base}Insensitive` ? Base :
|
|
110
|
+
S;
|
|
111
|
+
|
|
112
|
+
type ExtractFieldName<S extends string> = Uncapitalize<StripModifier<S>>;
|
|
113
|
+
|
|
114
|
+
type IsArrayFilter<S extends string> = S extends `${string}${'NotIn' | 'In'}` ? true : false;
|
|
115
|
+
|
|
116
|
+
type IsBetweenFilter<S extends string> = S extends `${string}${'NotBetween' | 'Between'}` ? true : false;
|
|
117
|
+
|
|
118
|
+
type ParseRelation<S extends string> =
|
|
119
|
+
S extends `${infer Rel}Without${infer Rest}` ? [Uncapitalize<Rel>, 'isNot', Rest] :
|
|
120
|
+
S extends `${infer Rel}With${infer Rest}` ? [Uncapitalize<Rel>, 'is', Rest] :
|
|
121
|
+
S extends `${infer Rel}Some${infer Rest}` ? [Uncapitalize<Rel>, 'some', Rest] :
|
|
122
|
+
S extends `${infer Rel}Every${infer Rest}` ? [Uncapitalize<Rel>, 'every', Rest] :
|
|
123
|
+
S extends `${infer Rel}None${infer Rest}` ? [Uncapitalize<Rel>, 'none', Rest] : null;
|
|
124
|
+
|
|
125
|
+
type GetFieldType<T, S extends string, I> = WidenField<
|
|
126
|
+
ExtractFieldName<S> extends infer FieldName
|
|
127
|
+
? FieldName extends keyof T
|
|
128
|
+
? IsArrayFilter<S> extends true
|
|
129
|
+
? T[FieldName][]
|
|
130
|
+
: IsBetweenFilter<S> extends true
|
|
131
|
+
? [NonNullable<T[FieldName]>, NonNullable<T[FieldName]>]
|
|
132
|
+
: NonNullable<T[FieldName]> extends object | any[]
|
|
133
|
+
? I extends { whereInput: infer W }
|
|
134
|
+
? FieldName extends keyof NonNullable<W> ? Exclude<NonNullable<W>[FieldName], undefined> : T[FieldName]
|
|
135
|
+
: T[FieldName]
|
|
136
|
+
: T[FieldName]
|
|
137
|
+
: ParseRelation<S> extends [infer Rel extends keyof T, any, infer Rest extends string]
|
|
138
|
+
? GetFieldType<NonNullable<T[Rel]> extends any[] ? NonNullable<T[Rel]>[number] : NonNullable<T[Rel]>, Rest, unknown>
|
|
139
|
+
: unknown
|
|
140
|
+
: unknown
|
|
141
|
+
>;
|
|
142
|
+
|
|
143
|
+
type NoArgModifiers = 'IsNull' | 'IsNotNull' | 'IsTrue' | 'IsFalse' | 'None' | 'Some' | 'Every' | 'Without';
|
|
144
|
+
|
|
145
|
+
type IsNoArgModifier<S extends string> =
|
|
146
|
+
S extends `${string}${'StartsWith' | 'EndsWith'}` ? false :
|
|
147
|
+
S extends `${string}${NoArgModifiers | 'With'}` ? true :
|
|
148
|
+
false;
|
|
149
|
+
|
|
150
|
+
type IsOptional<S extends string> = S extends `${string}Optional` ? true : false;
|
|
151
|
+
type StripOptional<S extends string> = S extends `${infer Base}Optional` ? Base : S;
|
|
152
|
+
|
|
153
|
+
type MapToContractTypes<T, Arr extends string[], I> =
|
|
154
|
+
Arr extends [infer First extends string, ...infer Rest extends string[]]
|
|
155
|
+
? First extends ''
|
|
156
|
+
? MapToContractTypes<T, Rest, I>
|
|
157
|
+
: StripOptional<First> extends infer CleanFirst extends string
|
|
158
|
+
? IsNoArgModifier<CleanFirst> extends true
|
|
159
|
+
? MapToContractTypes<T, Rest, I>
|
|
160
|
+
: IsOptional<First> extends true
|
|
161
|
+
? [GetFieldType<T, CleanFirst, I> | undefined, ...MapToContractTypes<T, Rest, I>]
|
|
162
|
+
: [GetFieldType<T, CleanFirst, I>, ...MapToContractTypes<T, Rest, I>]
|
|
163
|
+
: never
|
|
164
|
+
: [];
|
|
165
|
+
|
|
166
|
+
type SplitAllTokens<S extends string> =
|
|
167
|
+
S extends `${infer L}AND${infer R}` ? [...SplitAllTokens<L>, ...SplitAllTokens<R>] :
|
|
168
|
+
S extends `${infer L}And${infer R}` ? [...SplitAllTokens<L>, ...SplitAllTokens<R>] :
|
|
169
|
+
S extends `${infer L}Or${infer R}` ? [...SplitAllTokens<L>, ...SplitAllTokens<R>] :
|
|
170
|
+
S extends '' ? [] :
|
|
171
|
+
[S];
|
|
172
|
+
|
|
173
|
+
type ExtractFields<T, R extends string, I> =
|
|
174
|
+
R extends '' ? []
|
|
175
|
+
: FilterNonEmpty<MapToContractTypes<T, SplitAllTokens<R>, I>>;
|
|
176
|
+
|
|
177
|
+
type FilterNonEmpty<T extends unknown[]> =
|
|
178
|
+
T extends [infer First, ...infer Rest]
|
|
179
|
+
? [First] extends ['']
|
|
180
|
+
? FilterNonEmpty<Rest>
|
|
181
|
+
: [First, ...FilterNonEmpty<Rest>]
|
|
182
|
+
: [];
|
|
183
|
+
|
|
184
|
+
type ResolveReturnType<M extends string, TSelected> =
|
|
185
|
+
M extends 'existsBy' | 'existsWhere' ? boolean :
|
|
186
|
+
M extends 'createMany' | 'updateManyBy' | 'deleteManyBy' | 'updateManyWhere' | 'deleteManyWhere' ? { count: number } :
|
|
187
|
+
M extends 'findMany' | 'createManyAndReturn' | 'updateManyAndReturnBy' | 'updateManyAndReturnWhere' | 'findListWhere' | 'findByList' ? TSelected[] :
|
|
188
|
+
M extends 'findUnique' | 'findFirst' | 'findWhere' | 'findByOne' | 'findOneBy' | 'findOneWhere' ? TSelected | null :
|
|
189
|
+
M extends 'findUniqueOrThrow' | 'findFirstOrThrow' | 'create' | 'updateBy' | 'upsertBy' | 'deleteBy' ? TSelected :
|
|
190
|
+
M extends 'count' | 'countWhere' ? number : never;
|
|
191
|
+
|
|
192
|
+
type GetUpdateInput<I> = I extends { updateInput: infer U } ? U : unknown;
|
|
193
|
+
type GetCreateInput<I> = I extends { createInput: infer C } ? C : unknown;
|
|
194
|
+
type GetCreateManyInput<I> = I extends { createManyInput: infer CM } ? CM : unknown;
|
|
195
|
+
type GetUpdateManyInput<I> = I extends { updateManyInput: infer UM } ? UM : unknown;
|
|
196
|
+
type GetWhereInput<I> = I extends { whereInput: infer W } ? NonNullable<W> : unknown;
|
|
197
|
+
type GetCursorInput<I> = I extends { cursorInput: infer C } ? C : unknown;
|
|
198
|
+
type GetOrderByInput<I> = I extends { orderByInput: infer OB } ? OB : OrderOptions;
|
|
199
|
+
|
|
200
|
+
type ExtraArgs<M extends string, R extends string, I> = [
|
|
201
|
+
...(M extends 'upsertBy' ? [update: GetUpdateInput<I>, create: GetCreateInput<I>]
|
|
202
|
+
: M extends 'create' ? [data: GetCreateInput<I>]
|
|
203
|
+
: M extends 'updateBy' ? [data: GetUpdateInput<I>]
|
|
204
|
+
: M extends 'createMany' | 'createManyAndReturn' ? [data: GetCreateManyInput<I>]
|
|
205
|
+
: M extends 'updateManyBy' | 'updateManyAndReturnBy' ? [data: GetUpdateManyInput<I>]
|
|
206
|
+
: M extends 'findWhere' | 'findListWhere' | 'countWhere' | 'existsWhere' | 'deleteManyWhere' | 'findOneWhere' ? [where: GetWhereInput<I>]
|
|
207
|
+
: M extends 'updateManyWhere' | 'updateManyAndReturnWhere' ? [where: GetWhereInput<I>, data: GetUpdateManyInput<I>]
|
|
208
|
+
: []),
|
|
209
|
+
...(R extends `${string}PaginatedAndOrdered` ? [pagination: PaginationOptions<GetCursorInput<I>>, order: GetOrderByInput<I>]
|
|
210
|
+
: R extends `${string}OrderedAndPaginated` ? [order: GetOrderByInput<I>, pagination: PaginationOptions<GetCursorInput<I>>]
|
|
211
|
+
: R extends `${string}Paginated` ? [pagination: PaginationOptions<GetCursorInput<I>>]
|
|
212
|
+
: R extends `${string}Ordered` ? [order: GetOrderByInput<I>]
|
|
213
|
+
: [])
|
|
214
|
+
];
|
|
215
|
+
|
|
216
|
+
type PrismaDelegate<M extends Prisma.ModelName> = Uncapitalize<M> extends keyof DbClient ? DbClient[Uncapitalize<M>] : never;
|
|
217
|
+
|
|
218
|
+
type FullModelType<M extends Prisma.ModelName> =
|
|
219
|
+
Prisma.Result<PrismaDelegate<M>, {}, 'findMany'> extends Array<infer U> ? U : never;
|
|
220
|
+
|
|
221
|
+
type PrecomputedSelects<M extends Prisma.ModelName, SelectModels> = {
|
|
222
|
+
[S in keyof SelectModels]: Prisma.Result<PrismaDelegate<M>, { select: SelectModels[S] }, 'findMany'> extends Array<infer U> ? U : never
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
type SelectedModel<M extends Prisma.ModelName, S, SelectModels> =
|
|
226
|
+
[S] extends [false]
|
|
227
|
+
? FullModelType<M>
|
|
228
|
+
: [S] extends [never]
|
|
229
|
+
? FullModelType<M>
|
|
230
|
+
: [S] extends [keyof SelectModels]
|
|
231
|
+
? PrecomputedSelects<M, SelectModels>[S]
|
|
232
|
+
: FullModelType<M>;
|
|
233
|
+
|
|
234
|
+
type CleanFields<R extends string> =
|
|
235
|
+
R extends `${infer F}PaginatedAndOrdered` ? F :
|
|
236
|
+
R extends `${infer F}OrderedAndPaginated` ? F :
|
|
237
|
+
R extends `${infer F}Paginated` ? F :
|
|
238
|
+
R extends `${infer F}Ordered` ? F :
|
|
239
|
+
R extends `${infer F}SkipDuplicates` ? F : R;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Opções adicionais aceitas pelos métodos do repository.
|
|
243
|
+
*
|
|
244
|
+
* @template S Chaves disponíveis em `selectModels`.
|
|
245
|
+
*/
|
|
246
|
+
export type MethodOptions<S> = {
|
|
247
|
+
/**
|
|
248
|
+
* Select model a ser aplicado na operação.
|
|
249
|
+
*
|
|
250
|
+
* @note Use `false` para retornar o payload completo do Prisma, sem select.
|
|
251
|
+
*/
|
|
252
|
+
selectModel?: S | false;
|
|
253
|
+
/**
|
|
254
|
+
* Cliente Prisma ou transação que deve executar a operação.
|
|
255
|
+
*/
|
|
256
|
+
db?: ClientOrTransaction;
|
|
257
|
+
/**
|
|
258
|
+
* Modo de visibilidade para registros com soft-delete.
|
|
259
|
+
*
|
|
260
|
+
* Só tem efeito se `softRemovekName` estiver configurado no repository.
|
|
261
|
+
*
|
|
262
|
+
* - `"active"` — retorna apenas registros não removidos (padrão).
|
|
263
|
+
* - `"removed"` — retorna apenas registros removidos.
|
|
264
|
+
* - `"all"` — retorna todos os registros, ignorando o status de remoção.
|
|
265
|
+
*/
|
|
266
|
+
see?: SeeMode;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Versão de `MethodOptions` derivada diretamente de uma instância configurada de `VSRepository`.
|
|
271
|
+
*
|
|
272
|
+
* @template TRepo Instância de `VSRepository` configurada (use `typeof meuVSRepo`).
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* const usuarioVSRepo = setupVSRepo<Usuario, "usuario">()(config);
|
|
276
|
+
* type Opts = MethodOptionsModel<typeof usuarioVSRepo>;
|
|
277
|
+
*/
|
|
278
|
+
export type MethodOptionsModel<TRepo> =
|
|
279
|
+
TRepo extends VSRepository<any, any, infer Config>
|
|
280
|
+
? MethodOptions<keyof ExtractSelectModels<Config> | false>
|
|
281
|
+
: never;
|
|
282
|
+
|
|
283
|
+
type MethodFn<MethodName extends string, T, M extends Prisma.ModelName, R extends string, SelectModels, DefaultSelect extends keyof SelectModels | false, I> =
|
|
284
|
+
<S extends keyof SelectModels | false = DefaultSelect>(...args: [...ExtractFields<T, CleanFields<R>, I>, ...ExtraArgs<MethodName, R, I>, options?: MethodOptions<S>]) => Promise<ResolveReturnType<MethodName, SelectedModel<M, S, SelectModels>>>;
|
|
285
|
+
|
|
286
|
+
type GetMappedMethod<K extends string, MethodConf> =
|
|
287
|
+
K extends `findBy${string}` ? (MethodConf extends { fbMode: 'one' } ? 'findByOne' : 'findByList') :
|
|
288
|
+
K extends `findOneBy${string}` ? 'findOneBy' :
|
|
289
|
+
K extends `existsBy${string}` ? 'existsBy' :
|
|
290
|
+
K extends `existsWhere${string}` ? 'existsWhere' :
|
|
291
|
+
K extends `findUniqueOrThrowBy${string}` ? 'findUniqueOrThrow' :
|
|
292
|
+
K extends `findUniqueBy${string}` ? 'findUnique' :
|
|
293
|
+
K extends `findFirstOrThrowBy${string}` | `findFirstOrThrow${string}` ? 'findFirstOrThrow' :
|
|
294
|
+
K extends `findFirstBy${string}` | `findFirst${string}` ? 'findFirst' :
|
|
295
|
+
K extends `findManyBy${string}` | `findMany${string}` ? 'findMany' :
|
|
296
|
+
K extends `createManyAndReturn${string}` ? 'createManyAndReturn' :
|
|
297
|
+
K extends `createMany${string}` ? 'createMany' :
|
|
298
|
+
K extends `create${string}` ? 'create' :
|
|
299
|
+
K extends `updateManyAndReturnBy${string}` ? 'updateManyAndReturnBy' :
|
|
300
|
+
K extends `updateManyAndReturnWhere${string}` ? 'updateManyAndReturnWhere' :
|
|
301
|
+
K extends `updateManyBy${string}` ? 'updateManyBy' :
|
|
302
|
+
K extends `updateManyWhere${string}` ? 'updateManyWhere' :
|
|
303
|
+
K extends `updateBy${string}` ? 'updateBy' :
|
|
304
|
+
K extends `upsertBy${string}` ? 'upsertBy' :
|
|
305
|
+
K extends `deleteManyBy${string}` ? 'deleteManyBy' :
|
|
306
|
+
K extends `deleteManyWhere${string}` ? 'deleteManyWhere' :
|
|
307
|
+
K extends `deleteBy${string}` ? 'deleteBy' :
|
|
308
|
+
K extends `countWhere${string}` ? 'countWhere' :
|
|
309
|
+
K extends `countBy${string}` | `count${string}` ? 'count' :
|
|
310
|
+
K extends `findListWhere${string}` ? 'findListWhere' :
|
|
311
|
+
K extends `findOneWhere${string}` ? 'findOneWhere' :
|
|
312
|
+
K extends `findWhere${string}` ? 'findWhere' :
|
|
313
|
+
K extends 'aggregate' ? 'aggregate' :
|
|
314
|
+
K extends 'groupBy' ? 'groupBy' :
|
|
315
|
+
never;
|
|
316
|
+
|
|
317
|
+
type ExtractPatternBase<K extends string> =
|
|
318
|
+
K extends `${string}By${infer R}` ? R :
|
|
319
|
+
K extends `findFirstOrThrow${infer R}` ? R :
|
|
320
|
+
K extends `findFirst${infer R}` ? R :
|
|
321
|
+
K extends `findMany${infer R}` ? R :
|
|
322
|
+
K extends `createManyAndReturn${infer R}` ? R :
|
|
323
|
+
K extends `createMany${infer R}` ? R :
|
|
324
|
+
K extends `create${infer R}` ? R :
|
|
325
|
+
K extends `countWhere${infer R}` ? R :
|
|
326
|
+
K extends `count${infer R}` ? R :
|
|
327
|
+
K extends `findListWhere${infer R}` ? R :
|
|
328
|
+
K extends `findOneWhere${infer R}` ? R :
|
|
329
|
+
K extends `findWhere${infer R}` ? R :
|
|
330
|
+
K extends `existsWhere${infer R}` ? R :
|
|
331
|
+
K extends `updateManyWhere${infer R}` ? R :
|
|
332
|
+
K extends `updateManyAndReturnWhere${infer R}` ? R :
|
|
333
|
+
K extends `deleteManyWhere${infer R}` ? R : '';
|
|
334
|
+
|
|
335
|
+
type MethodFactory<T, M extends Prisma.ModelName, K extends string, SelectModels, DefaultSelect extends keyof SelectModels | false, I, MethodConf> =
|
|
336
|
+
K extends `findWhere${string}`
|
|
337
|
+
? {
|
|
338
|
+
/** @deprecated Use findOneWhere em seu lugar. */
|
|
339
|
+
<S extends keyof SelectModels | false = DefaultSelect>(...args: [...ExtractFields<T, CleanFields<ExtractPatternBase<K>>, I>, ...ExtraArgs<GetMappedMethod<K, MethodConf>, ExtractPatternBase<K>, I>, options?: MethodOptions<S>]): Promise<ResolveReturnType<GetMappedMethod<K, MethodConf>, SelectedModel<M, S, SelectModels>>>;
|
|
340
|
+
}
|
|
341
|
+
: MethodFn<GetMappedMethod<K, MethodConf>, T, M, ExtractPatternBase<K>, SelectModels, DefaultSelect, I>;
|
|
342
|
+
|
|
343
|
+
type ResolveSelectModel<MethodConf, GlobalConf, SelectModels> =
|
|
344
|
+
MethodConf extends { selectModel: infer S } ? (S extends false ? false : S extends keyof SelectModels ? S : never) :
|
|
345
|
+
GlobalConf extends { defaultSelectModel: infer D } ? (D extends keyof SelectModels ? D : never) : never;
|
|
346
|
+
|
|
347
|
+
type ExtractPkName<T, Config> = Config extends { pkName: infer PK } ? (PK extends keyof T ? PK : never) : never;
|
|
348
|
+
type ExtractSelectModels<Config> = Config extends { selectModels: infer SM } ? SM : {};
|
|
349
|
+
type ExtractDefaultSelect<Config> = Config extends { defaultSelectModel: infer D } ? D : never;
|
|
350
|
+
type ExtractRelations<Config> = Config extends { relations: infer R } ? (R extends object ? R : {}) : {};
|
|
351
|
+
type ExtractSoftRemovekName<Config> = Config extends { softRemovekName: infer S } ? S : never;
|
|
352
|
+
|
|
353
|
+
type AggregateMethod<M extends Prisma.ModelName> = <A extends Prisma.TypeMap['model'][M]['operations']['aggregate']['args']>(
|
|
354
|
+
prismaArgs: A,
|
|
355
|
+
options?: { db?: ClientOrTransaction }
|
|
356
|
+
) => Promise<Prisma.Result<PrismaDelegate<M>, A, 'aggregate'>>;
|
|
357
|
+
|
|
358
|
+
type GroupByMethod<M extends Prisma.ModelName> = <A extends Prisma.TypeMap['model'][M]['operations']['groupBy']['args']>(
|
|
359
|
+
prismaArgs: A,
|
|
360
|
+
options?: { db?: ClientOrTransaction }
|
|
361
|
+
) => Promise<Prisma.Result<PrismaDelegate<M>, A, 'groupBy'>>;
|
|
362
|
+
|
|
363
|
+
type DynamicMethods<T, M extends Prisma.ModelName, Config, I> = Config extends { methods: infer Methods }
|
|
364
|
+
? {
|
|
365
|
+
[K in keyof Methods as Methods[K] extends { map: true } ? K : never]: K extends string
|
|
366
|
+
? (Methods[K] extends { proxyTo: infer P extends string } ? P : K) extends infer ResolvedKey
|
|
367
|
+
? ResolvedKey extends 'aggregate'
|
|
368
|
+
? AggregateMethod<M>
|
|
369
|
+
: ResolvedKey extends 'groupBy'
|
|
370
|
+
? GroupByMethod<M>
|
|
371
|
+
: ResolvedKey extends string
|
|
372
|
+
? MethodFactory<T, M, ResolvedKey, ExtractSelectModels<Config>, ResolveSelectModel<Methods[K], Config, ExtractSelectModels<Config>>, I, Methods[K]>
|
|
373
|
+
: never
|
|
374
|
+
: never
|
|
375
|
+
: never;
|
|
376
|
+
}
|
|
377
|
+
: {};
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Agrupa os principais tipos de input do Prisma derivados de um modelo.
|
|
381
|
+
*
|
|
382
|
+
* @template M Nome do modelo Prisma.
|
|
383
|
+
*/
|
|
384
|
+
export type PrismaModelInputs<M extends Prisma.ModelName> = {
|
|
385
|
+
/** Tipo do argumento `select` usado em consultas do modelo. */
|
|
386
|
+
select: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['select'];
|
|
387
|
+
/** Tipo do `data` usado em `create`. */
|
|
388
|
+
createInput: Prisma.TypeMap['model'][M]['operations']['create']['args']['data'];
|
|
389
|
+
/** Tipo do `data` usado em `createMany`. */
|
|
390
|
+
createManyInput: Prisma.TypeMap['model'][M]['operations']['createMany']['args']['data'];
|
|
391
|
+
/** Tipo do `data` usado em `update`. */
|
|
392
|
+
updateInput: Prisma.TypeMap['model'][M]['operations']['update']['args']['data'];
|
|
393
|
+
/** Tipo do `data` usado em `updateMany`. */
|
|
394
|
+
updateManyInput: Prisma.TypeMap['model'][M]['operations']['updateMany']['args']['data'];
|
|
395
|
+
/** Tipo do `where` usado nas buscas do modelo. */
|
|
396
|
+
whereInput: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['where'];
|
|
397
|
+
/** Tipo do `orderBy` usado nas buscas do modelo. */
|
|
398
|
+
orderByInput: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['orderBy'];
|
|
399
|
+
/** Tipo do cursor usado nas buscas do modelo. */
|
|
400
|
+
cursorInput: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['cursor'];
|
|
401
|
+
/** Tipo do payload `create` usado em `upsert`. */
|
|
402
|
+
upsertCreateInput: Prisma.TypeMap['model'][M]['operations']['upsert']['args']['create'];
|
|
403
|
+
/** Tipo do payload `update` usado em `upsert`. */
|
|
404
|
+
upsertUpdateInput: Prisma.TypeMap['model'][M]['operations']['upsert']['args']['update'];
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Tipo do objeto `select` de um modelo Prisma.
|
|
409
|
+
*/
|
|
410
|
+
export type SelectModel<M extends Prisma.ModelName> = PrismaModelInputs<M>['select'];
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Mapa de selects nomeados e reutilizáveis para um modelo Prisma.
|
|
414
|
+
*/
|
|
415
|
+
export type SelectModels<M extends Prisma.ModelName> = Record<string, SelectModel<M>>;
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Tipo do objeto `where` de um modelo Prisma.
|
|
419
|
+
*/
|
|
420
|
+
export type WhereModel<M extends Prisma.ModelName> = PrismaModelInputs<M>['whereInput'];
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Tipo do objeto `orderBy` de um modelo Prisma.
|
|
424
|
+
*/
|
|
425
|
+
export type OrdenationModel<M extends Prisma.ModelName> = PrismaModelInputs<M>['orderByInput'];
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Opções de paginação com cursor tipado para um modelo Prisma.
|
|
429
|
+
*/
|
|
430
|
+
export type PaginationModel<M extends Prisma.ModelName> = PaginationOptions<PrismaModelInputs<M>['cursorInput']>;
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Payload base usado para criar um registro no `save`/`upsert` do modelo.
|
|
434
|
+
*/
|
|
435
|
+
export type ModelUpsertInput<M extends Prisma.ModelName> = PrismaModelInputs<M>['upsertCreateInput'];
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Configuração de um método dinâmico definido em `methods`.
|
|
439
|
+
*
|
|
440
|
+
* @template M Nome do modelo Prisma.
|
|
441
|
+
* @template SelectModels Mapa de select models disponíveis no repository.
|
|
442
|
+
*/
|
|
443
|
+
export type MethodConfig<M extends Prisma.ModelName, SelectModels = any> = {
|
|
444
|
+
/** Define se o método será exposto no repository. */
|
|
445
|
+
readonly map: boolean;
|
|
446
|
+
/** Sobrescreve o `defaultSelectModel` apenas para este método. */
|
|
447
|
+
readonly selectModel?: string | false;
|
|
448
|
+
/** Controla se o método combina (`extending`) ou sobrescreve (`overwrite`) o `requiredWhere`. */
|
|
449
|
+
readonly whereType?: 'overwrite' | 'extending';
|
|
450
|
+
/** Redireciona a lógica para outro padrão de método válido. */
|
|
451
|
+
readonly proxyTo?: ValidMethodPatterns;
|
|
452
|
+
/** Adiciona um `where` extra além do `requiredWhere`. */
|
|
453
|
+
readonly pushWhere?: WhereModel<M>;
|
|
454
|
+
/**
|
|
455
|
+
* Define se `findBy` retorna um item (`one`) ou uma lista (`list`).
|
|
456
|
+
* @deprecated Use `findOneBy` se quiser retornar um único resultado.
|
|
457
|
+
*/
|
|
458
|
+
readonly fbMode?: 'one' | 'list';
|
|
459
|
+
/** Injeta uma ordenação fixa automaticamente na query. */
|
|
460
|
+
readonly injectOrdenation?: OrdenationModel<M>;
|
|
461
|
+
/** Injeta uma paginação fixa automaticamente na query. */
|
|
462
|
+
readonly injectPagination?: PaginationModel<M>;
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
type BaseMethodConfig<TSelectKeys extends PropertyKey = string> = {
|
|
466
|
+
/** Ativa ou desativa o método base no `build`. */
|
|
467
|
+
active?: boolean;
|
|
468
|
+
/** Select model padrão usado pelo método base. */
|
|
469
|
+
defaultSelect?: TSelectKeys;
|
|
470
|
+
/** Ignora o `requiredWhere`. */
|
|
471
|
+
ignoreRequiredWhere?: boolean;
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Configuração aplicada durante o `.build(prisma, config?)`.
|
|
476
|
+
*
|
|
477
|
+
* @template TSelectKeys Chaves válidas de `selectModels`.
|
|
478
|
+
*/
|
|
479
|
+
export type BuildConfig<TSelectKeys extends PropertyKey = string> = {
|
|
480
|
+
/**
|
|
481
|
+
* Congela o objeto final do repository com `Object.freeze`.
|
|
482
|
+
* @deprecated Não tem mais efeito prático na nova versão — o freeze é sempre aplicado.
|
|
483
|
+
*/
|
|
484
|
+
freeze?: boolean;
|
|
485
|
+
/** Exibe logs internos de funcionamento no console. */
|
|
486
|
+
showWorking?: boolean;
|
|
487
|
+
/** Personaliza o comportamento dos métodos base automáticos. */
|
|
488
|
+
baseMethods?: {
|
|
489
|
+
/** Configuração do método `get`. */
|
|
490
|
+
get?: BaseMethodConfig<TSelectKeys>;
|
|
491
|
+
/** Configuração do método `getOrThrow`. */
|
|
492
|
+
getOrThrow?: BaseMethodConfig<TSelectKeys>;
|
|
493
|
+
/** Configuração do método `getList` (busca por lista de PKs). */
|
|
494
|
+
getList?: BaseMethodConfig<TSelectKeys>;
|
|
495
|
+
/** Configuração do método `remove`. */
|
|
496
|
+
remove?: BaseMethodConfig<TSelectKeys>;
|
|
497
|
+
/** Configuração do método `save`. */
|
|
498
|
+
save?: BaseMethodConfig<TSelectKeys>;
|
|
499
|
+
/** Configuração do método `patch`. */
|
|
500
|
+
patch?: BaseMethodConfig<TSelectKeys>;
|
|
501
|
+
/** Configuração do método `merge`. */
|
|
502
|
+
merge?: BaseMethodConfig<TSelectKeys>;
|
|
503
|
+
/** Configuração do método `removeList` (exclusão em lote). Não aceita select. */
|
|
504
|
+
removeList?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
|
|
505
|
+
/** Configuração do método `getAll` (listagem total). */
|
|
506
|
+
getAll?: BaseMethodConfig<TSelectKeys>;
|
|
507
|
+
/** Configuração do método `total` (contagem). Não aceita select. */
|
|
508
|
+
total?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
|
|
509
|
+
/** Configuração do método `has` (verificação de existência). Não aceita select. */
|
|
510
|
+
has?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
|
|
511
|
+
/** Configuração do método `saveList` (salvar em lote via transação). */
|
|
512
|
+
saveList?: BaseMethodConfig<TSelectKeys>;
|
|
513
|
+
/** Configuração do método `patchList` (atualizar em lote via transação). */
|
|
514
|
+
patchList?: BaseMethodConfig<TSelectKeys>;
|
|
515
|
+
/** Configuração do método `softRemove`. Só existe se `softRemovekName` estiver configurado. */
|
|
516
|
+
softRemove?: BaseMethodConfig<TSelectKeys>;
|
|
517
|
+
/** Configuração do método `softRemoveList`. Não aceita select. Só existe se `softRemovekName` estiver configurado. */
|
|
518
|
+
softRemoveList?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
|
|
519
|
+
/** Configuração do método `restore`. Só existe se `softRemovekName` estiver configurado. */
|
|
520
|
+
restore?: BaseMethodConfig<TSelectKeys>;
|
|
521
|
+
/** Configuração do método `restoreList`. Não aceita select. Só existe se `softRemovekName` estiver configurado. */
|
|
522
|
+
restoreList?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
|
|
523
|
+
};
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
type ResolveMethodDefaultSelect<Config, C, Method extends keyof NonNullable<BuildConfig['baseMethods']>, TSelects = ExtractSelectModels<Config>> =
|
|
527
|
+
C extends { baseMethods?: { [_ in Method]?: { defaultSelect?: infer D } } }
|
|
528
|
+
? D extends keyof TSelects
|
|
529
|
+
? D
|
|
530
|
+
: ExtractDefaultSelect<Config> extends keyof TSelects
|
|
531
|
+
? ExtractDefaultSelect<Config>
|
|
532
|
+
: false
|
|
533
|
+
: ExtractDefaultSelect<Config> extends keyof TSelects
|
|
534
|
+
? ExtractDefaultSelect<Config>
|
|
535
|
+
: false;
|
|
536
|
+
|
|
537
|
+
type ResolveCurrentReturn<M extends Prisma.ModelName, Models, S, D> =
|
|
538
|
+
[S] extends [false]
|
|
539
|
+
? FullModelType<M>
|
|
540
|
+
: [S] extends [never]
|
|
541
|
+
? ([D] extends [never] ? FullModelType<M> : SelectedModel<M, D, Models>)
|
|
542
|
+
: SelectedModel<M, S, Models>;
|
|
543
|
+
|
|
544
|
+
// ─── helpers reutilizados dentro do tipo mapeado ────────────────────────────
|
|
545
|
+
// ─── tipos de payload para relações ─────────────────────────────────────────
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Versão distributiva de `Omit`, preservando unions ao remover propriedades.
|
|
549
|
+
*/
|
|
550
|
+
type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
|
|
551
|
+
type ExtractUnionProp<T, K extends PropertyKey> = T extends any ? (K extends keyof T ? T[K] : never) : never;
|
|
552
|
+
|
|
553
|
+
type ExtractNestedCreateInput<M extends Prisma.ModelName, K extends PropertyKey> =
|
|
554
|
+
NonNullable<ExtractUnionProp<PrismaModelInputs<M>['createInput'], K>> extends { create?: infer C }
|
|
555
|
+
? Exclude<C, any[]>
|
|
556
|
+
: never;
|
|
557
|
+
|
|
558
|
+
type RelationPayload<TField, TRelationConfig, M extends Prisma.ModelName, K extends PropertyKey> = NonNullable<TField> extends any[]
|
|
559
|
+
? ExtractNestedCreateInput<M, K>[]
|
|
560
|
+
: NonNullable<TField> extends object
|
|
561
|
+
? ExtractNestedCreateInput<M, K> | (TRelationConfig extends { mode: 'oto'; restriction: 'set' } | { mode: 'mto'; nullable: true } | { mode: 'mto'; nullAble: true } ? null : never)
|
|
562
|
+
: never;
|
|
563
|
+
|
|
564
|
+
type TransformCreatePayload<U, T, M extends Prisma.ModelName, TRelations> =
|
|
565
|
+
Omit<U, keyof TRelations> &
|
|
566
|
+
{
|
|
567
|
+
// Campos que são OBRIGATÓRIOS nesta ramificação específica da união do Prisma
|
|
568
|
+
[K in Extract<keyof TRelations, keyof U> as {} extends Pick<U, K> ? never : K]:
|
|
569
|
+
K extends keyof T ? RelationPayload<T[K], TRelations[K], M, K> : never;
|
|
570
|
+
} &
|
|
571
|
+
{
|
|
572
|
+
// Campos que são OPCIONAIS nesta ramificação ou que não pertencem originalmente a ela
|
|
573
|
+
[K in keyof TRelations as K extends keyof U ? ({} extends Pick<U, K> ? K : never) : K]?:
|
|
574
|
+
K extends keyof T ? RelationPayload<T[K], TRelations[K], M, K> : never;
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Payload aceito pelo `save` quando o repository possui relações configuradas.
|
|
579
|
+
*/
|
|
580
|
+
type UpsertWithRelations<T, M extends Prisma.ModelName, TRelations> =
|
|
581
|
+
ModelUpsertInput<M> extends infer U
|
|
582
|
+
? U extends any
|
|
583
|
+
? Simplify<TransformCreatePayload<U, T, M, TRelations>>
|
|
584
|
+
: never
|
|
585
|
+
: never;
|
|
586
|
+
|
|
587
|
+
type CleanNestedInput<T> = T extends any
|
|
588
|
+
? T extends { data: infer D }
|
|
589
|
+
? CleanNestedInput<Exclude<D, any[]>>
|
|
590
|
+
: Omit<T, 'where' | 'data'>
|
|
591
|
+
: never;
|
|
592
|
+
|
|
593
|
+
type ExtractNestedUpdateInput<M extends Prisma.ModelName, K extends PropertyKey> =
|
|
594
|
+
NonNullable<ExtractUnionProp<PrismaModelInputs<M>['updateInput'], K>> extends { update?: infer U }
|
|
595
|
+
? CleanNestedInput<Exclude<U, any[]>>
|
|
596
|
+
: never;
|
|
597
|
+
|
|
598
|
+
type RelationUpdatePayload<TField, TRelationConfig, M extends Prisma.ModelName, K extends PropertyKey> = NonNullable<TField> extends any[]
|
|
599
|
+
? ExtractNestedUpdateInput<M, K>[]
|
|
600
|
+
: NonNullable<TField> extends object
|
|
601
|
+
? ExtractNestedUpdateInput<M, K> | (TRelationConfig extends { mode: 'oto'; restriction: 'set' } | { mode: 'mto'; nullable: true } | { mode: 'mto'; nullAble: true } ? null : never)
|
|
602
|
+
: never;
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* Payload aceito pelo `patch` quando o repository possui relações configuradas.
|
|
606
|
+
*/
|
|
607
|
+
type UpdateWithRelations<T, M extends Prisma.ModelName, TRelations> =
|
|
608
|
+
DistributiveOmit<PrismaModelInputs<M>['updateInput'], keyof TRelations> & {
|
|
609
|
+
[K in Extract<keyof TRelations, keyof T>]?: RelationUpdatePayload<T[K], TRelations[K], M, K>;
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Extrai o tipo de payload do método `save` a partir de uma instância de VSRepository configurada.
|
|
614
|
+
*/
|
|
615
|
+
export type SaveObject<TInput, TRepo> =
|
|
616
|
+
TRepo extends VSRepository<infer T, infer M, infer Config>
|
|
617
|
+
? (Config extends { relations: infer R } ? (R extends object ? R : {}) : {}) extends infer TRelations
|
|
618
|
+
? TInput extends infer U
|
|
619
|
+
? U extends any
|
|
620
|
+
? Simplify<TransformCreatePayload<U, T, M, TRelations>>
|
|
621
|
+
: never
|
|
622
|
+
: never
|
|
623
|
+
: never
|
|
624
|
+
: never;
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Extrai o tipo de payload do método `patch` a partir de uma instância de VSRepository configurada.
|
|
628
|
+
*/
|
|
629
|
+
export type PatchObject<TInput, TRepo> =
|
|
630
|
+
TRepo extends VSRepository<infer T, infer M, infer Config>
|
|
631
|
+
? (Config extends { relations: infer R } ? (R extends object ? R : {}) : {}) extends infer TRelations
|
|
632
|
+
? DistributiveOmit<TInput, keyof TRelations> & {
|
|
633
|
+
[K in Extract<keyof TRelations, keyof T>]?: RelationUpdatePayload<T[K], TRelations[K], M, K>;
|
|
634
|
+
}
|
|
635
|
+
: never
|
|
636
|
+
: never;
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
type _Pk<T, Config> = WidenField<T[ExtractPkName<T, Config> extends keyof T ? ExtractPkName<T, Config> : never]>;
|
|
640
|
+
type _Ret<M extends Prisma.ModelName, TSelects, S, TDefault> = ResolveCurrentReturn<M, TSelects, S, TDefault>;
|
|
641
|
+
type _DS<Config, C, Method extends keyof NonNullable<BuildConfig['baseMethods']>, TSelects = ExtractSelectModels<Config>> =
|
|
642
|
+
ResolveMethodDefaultSelect<Config, C, Method, TSelects>;
|
|
643
|
+
type _Sel<Config> = ExtractSelectModels<Config>;
|
|
644
|
+
type _Def<Config> = ExtractDefaultSelect<Config>;
|
|
645
|
+
type _Rel<Config> = ExtractRelations<Config>;
|
|
646
|
+
type _Soft<Config> = ExtractSoftRemovekName<Config>;
|
|
647
|
+
|
|
648
|
+
// ─── tipo mapeado refatorado — otimizado para o compilador TS ────────────────
|
|
649
|
+
|
|
650
|
+
type AllBaseMethods<
|
|
651
|
+
T,
|
|
652
|
+
M extends Prisma.ModelName,
|
|
653
|
+
Config,
|
|
654
|
+
C extends BuildConfig<any> | undefined,
|
|
655
|
+
TSelects = _Sel<Config>,
|
|
656
|
+
TDefault = _Def<Config>,
|
|
657
|
+
TPk = ExtractPkName<T, Config>,
|
|
658
|
+
TRelations = _Rel<Config>,
|
|
659
|
+
TSoftKey = _Soft<Config>,
|
|
660
|
+
I = PrismaModelInputs<M>
|
|
661
|
+
> = {
|
|
662
|
+
/** Busca um registro pela chave primária (PK). */
|
|
663
|
+
get: <S extends keyof TSelects | false = _DS<Config, C, 'get', TSelects>>(
|
|
664
|
+
pk: _Pk<T, Config>, options?: MethodOptions<S>
|
|
665
|
+
) => Promise<_Ret<M, TSelects, S, TDefault> | null>;
|
|
666
|
+
|
|
667
|
+
/** Busca um registro pela PK e lança `VSRepoRuntimeError` se não encontrado. */
|
|
668
|
+
getOrThrow: <S extends keyof TSelects | false = _DS<Config, C, 'getOrThrow', TSelects>>(
|
|
669
|
+
pk: _Pk<T, Config>, options?: MethodOptions<S>
|
|
670
|
+
) => Promise<_Ret<M, TSelects, S, TDefault>>;
|
|
671
|
+
|
|
672
|
+
/** Busca múltiplos registros por uma lista de chaves primárias (PKs). */
|
|
673
|
+
getList: <S extends keyof TSelects | false = _DS<Config, C, 'getList', TSelects>>(
|
|
674
|
+
pks: _Pk<T, Config>[], options?: MethodOptions<S>
|
|
675
|
+
) => Promise<_Ret<M, TSelects, S, TDefault>[]>;
|
|
676
|
+
|
|
677
|
+
/** Remove um registro identificado pela chave primária (PK). */
|
|
678
|
+
remove: <S extends keyof TSelects | false = _DS<Config, C, 'remove', TSelects>>(
|
|
679
|
+
pk: _Pk<T, Config>, options?: MethodOptions<S>
|
|
680
|
+
) => Promise<_Ret<M, TSelects, S, TDefault>>;
|
|
681
|
+
|
|
682
|
+
/** Insere ou atualiza (upsert) um registro. */
|
|
683
|
+
save: <S extends keyof TSelects | false = _DS<Config, C, 'save', TSelects>>(
|
|
684
|
+
obj: UpsertWithRelations<T, M, TRelations>, options?: MethodOptions<S>
|
|
685
|
+
) => Promise<_Ret<M, TSelects, S, TDefault>>;
|
|
686
|
+
|
|
687
|
+
/** Salva um array de objetos em uma única transação automática. */
|
|
688
|
+
saveList: <S extends keyof TSelects | false = _DS<Config, C, 'saveList', TSelects>>(
|
|
689
|
+
objs: UpsertWithRelations<T, M, TRelations>[], options?: Omit<MethodOptions<S>, 'db'> & { db?: DbTransaction }
|
|
690
|
+
) => Promise<_Ret<M, TSelects, S, TDefault>[]>;
|
|
691
|
+
|
|
692
|
+
/** Atualiza parcialmente (patch) um registro existente pela chave primária (PK). */
|
|
693
|
+
patch: <S extends keyof TSelects | false = _DS<Config, C, 'patch', TSelects>>(
|
|
694
|
+
pk: _Pk<T, Config>, obj: UpdateWithRelations<T, M, TRelations>, options?: MethodOptions<S>
|
|
695
|
+
) => Promise<_Ret<M, TSelects, S, TDefault>>;
|
|
696
|
+
|
|
697
|
+
/** Atualiza parcialmente múltiplos registros via tuplas `[pk, obj]` em transação automática. */
|
|
698
|
+
patchList: <S extends keyof TSelects | false = _DS<Config, C, 'patchList', TSelects>>(
|
|
699
|
+
tuples: [pk: _Pk<T, Config>, obj: UpdateWithRelations<T, M, TRelations>][], options?: Omit<MethodOptions<S>, 'db'> & { db?: DbTransaction }
|
|
700
|
+
) => Promise<_Ret<M, TSelects, S, TDefault>[]>;
|
|
701
|
+
|
|
702
|
+
/** Busca um registro pela PK e faz deep merge com o objeto fornecido **em memória**. */
|
|
703
|
+
merge: <S extends keyof TSelects | false = _DS<Config, C, 'merge', TSelects>>(
|
|
704
|
+
pk: _Pk<T, Config>, obj: UpdateWithRelations<T, M, TRelations>, options?: MethodOptions<S>
|
|
705
|
+
) => Promise<_Ret<M, TSelects, S, TDefault> | null>;
|
|
706
|
+
|
|
707
|
+
/** Remove múltiplos registros pelas suas chaves primárias. */
|
|
708
|
+
removeList: (pks: _Pk<T, Config>[], options?: { db?: ClientOrTransaction }) => Promise<{ count: number }>;
|
|
709
|
+
|
|
710
|
+
/** Busca todos os registros (respeita `requiredWhere` quando aplicado). */
|
|
711
|
+
getAll: <S extends keyof TSelects | false = _DS<Config, C, 'getAll', TSelects>>(
|
|
712
|
+
options?: MethodOptions<S> & {
|
|
713
|
+
pagination?: PaginationOptions<I extends { cursorInput: infer Curs } ? Curs : unknown>;
|
|
714
|
+
order?: I extends { orderByInput: infer OB } ? OB : OrderOptions;
|
|
715
|
+
}
|
|
716
|
+
) => Promise<_Ret<M, TSelects, S, TDefault>[]>;
|
|
717
|
+
|
|
718
|
+
/** Retorna a quantidade total de registros. */
|
|
719
|
+
total: (options?: { db?: ClientOrTransaction; see?: SeeMode }) => Promise<number>;
|
|
720
|
+
|
|
721
|
+
/** Verifica se um registro existe pela chave primária (PK). */
|
|
722
|
+
has: (pk: _Pk<T, Config>, options?: { db?: ClientOrTransaction; see?: SeeMode }) => Promise<boolean>;
|
|
723
|
+
|
|
724
|
+
/** Marca um registro como removido (soft-delete). */
|
|
725
|
+
softRemove: <S extends keyof TSelects | false = _DS<Config, C, 'softRemove', TSelects>>(
|
|
726
|
+
pk: _Pk<T, Config>, options?: Omit<MethodOptions<S>, 'see'>
|
|
727
|
+
) => Promise<_Ret<M, TSelects, S, TDefault>>;
|
|
728
|
+
|
|
729
|
+
/** Marca múltiplos registros como removidos (soft-delete) em lote. */
|
|
730
|
+
softRemoveList: (pks: _Pk<T, Config>[], options?: { db?: ClientOrTransaction }) => Promise<{ count: number }>;
|
|
731
|
+
|
|
732
|
+
/** Restaura um registro marcado como removido (soft-delete). */
|
|
733
|
+
restore: <S extends keyof TSelects | false = _DS<Config, C, 'restore', TSelects>>(
|
|
734
|
+
pk: _Pk<T, Config>, options?: Omit<MethodOptions<S>, 'see'>
|
|
735
|
+
) => Promise<_Ret<M, TSelects, S, TDefault>>;
|
|
736
|
+
|
|
737
|
+
/** Restaura múltiplos registros marcados como removidos (soft-delete) em lote. */
|
|
738
|
+
restoreList: (pks: _Pk<T, Config>[], options?: { db?: ClientOrTransaction }) => Promise<{ count: number }>;
|
|
739
|
+
};
|
|
740
|
+
|
|
741
|
+
type InjectedBaseMethods<
|
|
742
|
+
T,
|
|
743
|
+
M extends Prisma.ModelName,
|
|
744
|
+
Config,
|
|
745
|
+
C extends BuildConfig<any> | undefined,
|
|
746
|
+
TSelects = _Sel<Config>,
|
|
747
|
+
TDefault = _Def<Config>,
|
|
748
|
+
TPk = ExtractPkName<T, Config>,
|
|
749
|
+
TRelations = _Rel<Config>,
|
|
750
|
+
TSoftKey = _Soft<Config>,
|
|
751
|
+
I = PrismaModelInputs<M>
|
|
752
|
+
> = Pick<
|
|
753
|
+
AllBaseMethods<T, M, Config, C, TSelects, TDefault, TPk, TRelations, TSoftKey, I>,
|
|
754
|
+
| (C extends { baseMethods: { get: { active: false } } } ? never : 'get')
|
|
755
|
+
| (C extends { baseMethods: { getOrThrow: { active: false } } } ? never : 'getOrThrow')
|
|
756
|
+
| (C extends { baseMethods: { getList: { active: false } } } ? never : 'getList')
|
|
757
|
+
| (C extends { baseMethods: { remove: { active: false } } } ? never : 'remove')
|
|
758
|
+
| (C extends { baseMethods: { save: { active: false } } } ? never : 'save')
|
|
759
|
+
| (C extends { baseMethods: { saveList: { active: false } } } ? never : 'saveList')
|
|
760
|
+
| (C extends { baseMethods: { patch: { active: false } } } ? never : 'patch')
|
|
761
|
+
| (C extends { baseMethods: { patchList: { active: false } } } ? never : 'patchList')
|
|
762
|
+
| (C extends { baseMethods: { merge: { active: false } } } ? never : 'merge')
|
|
763
|
+
| (C extends { baseMethods: { removeList: { active: false } } } ? never : 'removeList')
|
|
764
|
+
| (C extends { baseMethods: { getAll: { active: false } } } ? never : 'getAll')
|
|
765
|
+
| (C extends { baseMethods: { total: { active: false } } } ? never : 'total')
|
|
766
|
+
| (C extends { baseMethods: { has: { active: false } } } ? never : 'has')
|
|
767
|
+
| ([TSoftKey] extends [never] ? never : C extends { baseMethods: { softRemove: { active: false } } } ? never : 'softRemove')
|
|
768
|
+
| ([TSoftKey] extends [never] ? never : C extends { baseMethods: { softRemoveList: { active: false } } } ? never : 'softRemoveList')
|
|
769
|
+
| ([TSoftKey] extends [never] ? never : C extends { baseMethods: { restore: { active: false } } } ? never : 'restore')
|
|
770
|
+
| ([TSoftKey] extends [never] ? never : C extends { baseMethods: { restoreList: { active: false } } } ? never : 'restoreList')
|
|
771
|
+
>;
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* Configuração de relação para One-to-Many ou Many-to-Many.
|
|
776
|
+
*
|
|
777
|
+
* @template TItem O tipo da entidade relacionada.
|
|
778
|
+
*/
|
|
779
|
+
export type ManyRelationConfig<TItem> = {
|
|
780
|
+
/** A chave primária (Primary Key) da entidade relacionada. */
|
|
781
|
+
pk: keyof TItem;
|
|
782
|
+
/** Tipo de relação: `otm` (One-to-Many) ou `mtm` (Many-to-Many). */
|
|
783
|
+
mode: 'otm' | 'mtm';
|
|
784
|
+
/** Comportamento de mutação: `set` (substitui tudo) ou `add` (adiciona aos existentes). */
|
|
785
|
+
restriction: 'set' | 'add';
|
|
786
|
+
};
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* Configuração de relação One-to-One.
|
|
790
|
+
*
|
|
791
|
+
* @template TItem O tipo da entidade relacionada.
|
|
792
|
+
*/
|
|
793
|
+
export type OneToOneRelationConfig<TItem> = {
|
|
794
|
+
/** A chave primária (Primary Key) da entidade relacionada. */
|
|
795
|
+
pk: keyof TItem;
|
|
796
|
+
/** Tipo de relação: `oto` (One-to-One). */
|
|
797
|
+
mode: 'oto';
|
|
798
|
+
/** Comportamento de mutação permitido para salvar. */
|
|
799
|
+
restriction: 'set' | 'add';
|
|
800
|
+
};
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* Configuração de relação Many-to-One.
|
|
804
|
+
*
|
|
805
|
+
* @template TItem O tipo da entidade relacionada.
|
|
806
|
+
*/
|
|
807
|
+
export type ManyToOneRelationConfig<TItem> = {
|
|
808
|
+
/** A chave primária (Primary Key) da entidade relacionada. */
|
|
809
|
+
pk: keyof TItem;
|
|
810
|
+
/** Tipo de relação: `mto` (Many-to-One). */
|
|
811
|
+
mode: 'mto';
|
|
812
|
+
/** Comportamento de mutação permitido para salvar. */
|
|
813
|
+
restriction: 'set' | 'add';
|
|
814
|
+
/**
|
|
815
|
+
* Habilita a possibilidade de desvincular a relação, tornando a chave estrangeira nula.
|
|
816
|
+
* @deprecated Use `nullable` (com letras minúsculas) em vez de `nullAble`.
|
|
817
|
+
*/
|
|
818
|
+
nullAble?: boolean;
|
|
819
|
+
/** Habilita a possibilidade de desvincular a relação, tornando a chave estrangeira nula. */
|
|
820
|
+
nullable?: boolean;
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* Infere automaticamente a configuração de relação possível a partir de um campo.
|
|
825
|
+
*/
|
|
826
|
+
export type ExtractRelationConfig<TField> = NonNullable<TField> extends infer NonNull
|
|
827
|
+
? NonNull extends Date | Buffer | Uint8Array | Decimal | JsonValue ? never
|
|
828
|
+
: NonNull extends any[] ? (NonNull[number] extends object ? ManyRelationConfig<NonNull[number]> : never)
|
|
829
|
+
: NonNull extends object ? (OneToOneRelationConfig<NonNull> | ManyToOneRelationConfig<NonNull>)
|
|
830
|
+
: never
|
|
831
|
+
: never;
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* Mapa das relações configuráveis de um tipo de entidade.
|
|
835
|
+
*/
|
|
836
|
+
export type RepositoryRelations<T> = {
|
|
837
|
+
[K in keyof T as ExtractRelationConfig<T[K]> extends never ? never : K]?: ExtractRelationConfig<T[K]>;
|
|
838
|
+
};
|
|
839
|
+
|
|
840
|
+
type AnySelect<M extends Prisma.ModelName> = Prisma.TypeMap['model'][M]['operations']['findMany']['args']['select'];
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Configuração principal usada em `setupVSRepo<T, M>()(config)`.
|
|
844
|
+
*
|
|
845
|
+
* @template T Tipo da entidade manipulada pelo repository.
|
|
846
|
+
* @template M Nome do modelo Prisma.
|
|
847
|
+
* @template SM Mapa de select models nomeados.
|
|
848
|
+
*/
|
|
849
|
+
export type RepoConfig<T, M extends Prisma.ModelName, SM extends Record<string, AnySelect<M>> = Record<string, AnySelect<M>>> = {
|
|
850
|
+
tableName: Uncapitalize<M>;
|
|
851
|
+
pkName: keyof T;
|
|
852
|
+
/**
|
|
853
|
+
* Nome do campo `DateTime` usado para soft-delete.
|
|
854
|
+
*
|
|
855
|
+
* Quando configurado, habilita os métodos `softRemove`, `softRemoveList`, `restore` e `restoreList`.
|
|
856
|
+
* O campo **deve** ser do tipo `DateTime` no schema do Prisma — o VSRepository valida isso no `build`.
|
|
857
|
+
*/
|
|
858
|
+
softRemovekName?: keyof T & string;
|
|
859
|
+
selectModels?: SM;
|
|
860
|
+
defaultSelectModel?: Extract<keyof SM, string>;
|
|
861
|
+
requiredWhere?: WhereModel<M>;
|
|
862
|
+
relations?: RepositoryRelations<T>;
|
|
863
|
+
methods?: Record<string, MethodConfig<M, SM>>;
|
|
864
|
+
};
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* Tipo final retornado por `.build(prisma)`.
|
|
868
|
+
*
|
|
869
|
+
* Combina métodos dinâmicos, métodos base e extensões personalizadas.
|
|
870
|
+
*/
|
|
871
|
+
type BuiltRepository<T extends object, M extends Prisma.ModelName, Config extends RepoConfig<T, M, any>, C extends BuildConfig<any> | undefined> = {
|
|
872
|
+
/**
|
|
873
|
+
* Estende o repository com métodos personalizados sem perder a tipagem.
|
|
874
|
+
*/
|
|
875
|
+
extend<E>(extensionFunc: (repo: BuiltRepository<T, M, Config, C>) => E): BuiltRepository<T, M, Config, C> & E;
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* Instância do Prisma Client passada no `build`.
|
|
879
|
+
*/
|
|
880
|
+
readonly prisma: DbClient;
|
|
881
|
+
} & DynamicMethods<T, M, Config, PrismaModelInputs<M>> & InjectedBaseMethods<T, M, Config, C>;
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* Fábrica tipada de repositories baseada na configuração do modelo Prisma.
|
|
885
|
+
*/
|
|
886
|
+
export declare class VSRepository<T extends object, M extends Prisma.ModelName, const Config extends RepoConfig<T, M, any> = RepoConfig<T, M, any>> {
|
|
887
|
+
/** Configuração original informada no `setupVSRepo`. */
|
|
888
|
+
readonly config: Config;
|
|
889
|
+
/**
|
|
890
|
+
* Cria uma instância configurável de `VSRepository`.
|
|
891
|
+
*/
|
|
892
|
+
constructor(config: Config);
|
|
893
|
+
/**
|
|
894
|
+
* Constrói o repository final com os métodos base e dinâmicos.
|
|
895
|
+
*/
|
|
896
|
+
build<C extends BuildConfig<keyof ExtractSelectModels<Config>>>(prisma: DbClient, config?: C): BuiltRepository<T, M, Config, C>;
|
|
897
|
+
vsrepocache: never;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* Infere o tipo de um repository já configurado a partir de uma instância de `VSRepository`.
|
|
902
|
+
*
|
|
903
|
+
* Também permite informar manualmente o `BuildConfig` e o tipo de extensões.
|
|
904
|
+
*/
|
|
905
|
+
export type RepositoryOf<TRepo, C extends BuildConfig<any> | undefined = undefined, E = unknown> =
|
|
906
|
+
TRepo extends VSRepository<infer T, infer M, infer Config>
|
|
907
|
+
? Simplify<BuiltRepository<T, M, Config, C> & E>
|
|
908
|
+
: never;
|
|
909
|
+
|
|
910
|
+
/**
|
|
911
|
+
* Tipo utilitário usado para validar a configuração de um repository em tempo de compilação.
|
|
912
|
+
*/
|
|
913
|
+
export type ValidateRepoConfig<T extends object, M extends Prisma.ModelName, Config> = {
|
|
914
|
+
tableName: Uncapitalize<M>;
|
|
915
|
+
pkName: keyof T;
|
|
916
|
+
softRemovekName?: keyof T & string;
|
|
917
|
+
selectModels?: SelectModels<M>;
|
|
918
|
+
defaultSelectModel?: string;
|
|
919
|
+
requiredWhere?: WhereModel<M>;
|
|
920
|
+
relations?: RepositoryRelations<T>;
|
|
921
|
+
methods?: {
|
|
922
|
+
[K in keyof (Config extends { methods: infer Meth } ? Meth : {})]: K extends string
|
|
923
|
+
? MethodConfig<M, Config extends { selectModels: infer SM } ? SM : any> & (K extends ValidMethodPatterns ? {} : { proxyTo: ValidMethodPatterns })
|
|
924
|
+
: never;
|
|
925
|
+
};
|
|
926
|
+
};
|
|
927
|
+
|
|
928
|
+
/**
|
|
929
|
+
* Função para inicializar e configurar o `repository`.
|
|
930
|
+
* As configurações passadas nele são as que serão lidas ao executar o `.build()`.
|
|
931
|
+
*/
|
|
932
|
+
export declare function setupVSRepo<T extends object, M extends Prisma.ModelName>(): <
|
|
933
|
+
const SM extends Record<string, SelectModel<M>>,
|
|
934
|
+
const Config extends RepoConfig<T, M, SM>
|
|
935
|
+
>(
|
|
936
|
+
config: Config & ValidateRepoConfig<T, M, Config>
|
|
937
|
+
) => VSRepository<T, M, Config>;
|