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