vsrepo 1.2.6 → 1.2.8
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 +12 -12
- package/dist/VSRepoError.js +17 -0
- package/{VSRepository → dist}/VSRepository.d.ts +973 -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,973 @@
|
|
|
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
|
+
* Flattens a type intersection into a single object,
|
|
6
|
+
* avoiding the TypeScript "union type too complex to represent" error.
|
|
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
|
+
* Full Prisma Client instance used to build repositories.
|
|
20
|
+
*/
|
|
21
|
+
export type DbClient = PrismaClient;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Prisma transactional client returned by `prisma.$transaction`.
|
|
25
|
+
*/
|
|
26
|
+
export type DbTransaction = Prisma.TransactionClient;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Accepts either the main Prisma client or a transaction client.
|
|
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
|
+
* Pagination options accepted by methods with the `Paginated` suffix.
|
|
41
|
+
*
|
|
42
|
+
* @template TCursor Type of the cursor used by the Prisma model.
|
|
43
|
+
*/
|
|
44
|
+
export type PaginationOptions<TCursor = unknown> = {
|
|
45
|
+
/** Number of records to skip. */
|
|
46
|
+
skip?: number;
|
|
47
|
+
/** Maximum number of records to return. */
|
|
48
|
+
take?: number;
|
|
49
|
+
/** Typed cursor for position-based pagination. */
|
|
50
|
+
cursor?: TCursor;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Ordering accepted by repository methods.
|
|
55
|
+
*
|
|
56
|
+
* Can be a single ordering or a list of chained orderings.
|
|
57
|
+
*/
|
|
58
|
+
export type OrderOptions = OrderPattern | OrderPattern[];
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Visibility mode for records with soft-delete.
|
|
62
|
+
*
|
|
63
|
+
* - `"active"` — returns only non-deleted records (default).
|
|
64
|
+
* - `"removed"` — returns only deleted records.
|
|
65
|
+
* - `"all"` — returns all records regardless of their 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
|
+
* Additional options accepted by repository methods.
|
|
243
|
+
*
|
|
244
|
+
* @template S Available keys in `selectModels`.
|
|
245
|
+
*/
|
|
246
|
+
export type MethodOptions<S> = {
|
|
247
|
+
/**
|
|
248
|
+
* Select model to apply to the operation.
|
|
249
|
+
*
|
|
250
|
+
* @note Use `false` to return the full Prisma payload without a select.
|
|
251
|
+
*/
|
|
252
|
+
selectModel?: S | false;
|
|
253
|
+
/**
|
|
254
|
+
* Prisma client or transaction to use for the operation.
|
|
255
|
+
*/
|
|
256
|
+
db?: ClientOrTransaction;
|
|
257
|
+
/**
|
|
258
|
+
* Visibility mode for records with soft-delete.
|
|
259
|
+
*
|
|
260
|
+
* Only takes effect if `softRemovekName` is configured on the repository.
|
|
261
|
+
*
|
|
262
|
+
* - `"active"` — returns only non-deleted records (default).
|
|
263
|
+
* - `"removed"` — returns only deleted records.
|
|
264
|
+
* - `"all"` — returns all records, ignoring deletion status.
|
|
265
|
+
*/
|
|
266
|
+
see?: SeeMode;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Version of `MethodOptions` derived directly from a configured `VSRepository` instance.
|
|
271
|
+
*
|
|
272
|
+
* @template TRepo Configured `VSRepository` instance (use `typeof myVSRepo`).
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* const userVSRepo = setupVSRepo<User, "user">()(config);
|
|
276
|
+
* type Opts = MethodOptionsModel<typeof userVSRepo>;
|
|
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 instead. */
|
|
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
|
+
* Groups the main Prisma input types derived from a model.
|
|
381
|
+
*
|
|
382
|
+
* @template M Prisma model name.
|
|
383
|
+
*/
|
|
384
|
+
export type PrismaModelInputs<M extends Prisma.ModelName> = {
|
|
385
|
+
/** Type of the `select` argument used in model queries. */
|
|
386
|
+
select: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['select'];
|
|
387
|
+
/** Type of the `data` used in `create`. */
|
|
388
|
+
createInput: Prisma.TypeMap['model'][M]['operations']['create']['args']['data'];
|
|
389
|
+
/** Type of the `data` used in `createMany`. */
|
|
390
|
+
createManyInput: Prisma.TypeMap['model'][M]['operations']['createMany']['args']['data'];
|
|
391
|
+
/** Type of the `data` used in `update`. */
|
|
392
|
+
updateInput: Prisma.TypeMap['model'][M]['operations']['update']['args']['data'];
|
|
393
|
+
/** Type of the `data` used in `updateMany`. */
|
|
394
|
+
updateManyInput: Prisma.TypeMap['model'][M]['operations']['updateMany']['args']['data'];
|
|
395
|
+
/** Type of the `where` used in model queries. */
|
|
396
|
+
whereInput: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['where'];
|
|
397
|
+
/** Type of the `orderBy` used in model queries. */
|
|
398
|
+
orderByInput: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['orderBy'];
|
|
399
|
+
/** Type of the cursor used in model queries. */
|
|
400
|
+
cursorInput: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['cursor'];
|
|
401
|
+
/** Type of the `create` payload used in `upsert`. */
|
|
402
|
+
upsertCreateInput: Prisma.TypeMap['model'][M]['operations']['upsert']['args']['create'];
|
|
403
|
+
/** Type of the `update` payload used in `upsert`. */
|
|
404
|
+
upsertUpdateInput: Prisma.TypeMap['model'][M]['operations']['upsert']['args']['update'];
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Type of the `select` object of a Prisma model.
|
|
409
|
+
*/
|
|
410
|
+
export type SelectModel<M extends Prisma.ModelName> = PrismaModelInputs<M>['select'];
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Map of named, reusable selects for a Prisma model.
|
|
414
|
+
*/
|
|
415
|
+
export type SelectModels<M extends Prisma.ModelName> = Record<string, SelectModel<M>>;
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Type of the `where` object of a Prisma model.
|
|
419
|
+
*/
|
|
420
|
+
export type WhereModel<M extends Prisma.ModelName> = PrismaModelInputs<M>['whereInput'];
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Type of the `orderBy` object of a Prisma model.
|
|
424
|
+
*/
|
|
425
|
+
export type OrdenationModel<M extends Prisma.ModelName> = PrismaModelInputs<M>['orderByInput'];
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Pagination options with typed cursor for a Prisma model.
|
|
429
|
+
*/
|
|
430
|
+
export type PaginationModel<M extends Prisma.ModelName> = PaginationOptions<PrismaModelInputs<M>['cursorInput']>;
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Base payload used to create a record in the model's `save`/`upsert`.
|
|
434
|
+
*/
|
|
435
|
+
export type ModelUpsertInput<M extends Prisma.ModelName> = PrismaModelInputs<M>['upsertCreateInput'];
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Configuration for a dynamic method defined in `methods`.
|
|
439
|
+
*
|
|
440
|
+
* @template M Prisma model name.
|
|
441
|
+
* @template SelectModels Map of select models available in the repository.
|
|
442
|
+
*/
|
|
443
|
+
export type MethodConfig<M extends Prisma.ModelName, SelectModels = any> = {
|
|
444
|
+
/** Defines whether the method will be exposed on the repository. */
|
|
445
|
+
readonly map: boolean;
|
|
446
|
+
/** Overrides `defaultSelectModel` for this method only. */
|
|
447
|
+
readonly selectModel?: string | false;
|
|
448
|
+
/** Controls whether the method combines (`extending`) or overwrites (`overwrite`) the `requiredWhere`. */
|
|
449
|
+
readonly whereType?: 'overwrite' | 'extending';
|
|
450
|
+
/** Redirects the logic to another valid method pattern. */
|
|
451
|
+
readonly proxyTo?: ValidMethodPatterns;
|
|
452
|
+
/** Adds an extra `where` on top of `requiredWhere`. */
|
|
453
|
+
readonly pushWhere?: WhereModel<M>;
|
|
454
|
+
/**
|
|
455
|
+
* Defines whether `findBy` returns a single item (`one`) or a list (`list`).
|
|
456
|
+
* @deprecated Use `findOneBy` if you want to return a single result.
|
|
457
|
+
*/
|
|
458
|
+
readonly fbMode?: 'one' | 'list';
|
|
459
|
+
/** Injects a fixed ordering automatically into the query. */
|
|
460
|
+
readonly injectOrdenation?: OrdenationModel<M>;
|
|
461
|
+
/** Injects a fixed pagination automatically into the query. */
|
|
462
|
+
readonly injectPagination?: PaginationModel<M>;
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
type BaseMethodConfig<TSelectKeys extends PropertyKey = string> = {
|
|
466
|
+
/** Enables or disables the base method in the `build`. */
|
|
467
|
+
active?: boolean;
|
|
468
|
+
/** Default select model used by the base method. */
|
|
469
|
+
defaultSelect?: TSelectKeys;
|
|
470
|
+
/** Ignores the `requiredWhere`. */
|
|
471
|
+
ignoreRequiredWhere?: boolean;
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Configuration applied during `.build(prisma, config?)`.
|
|
476
|
+
*
|
|
477
|
+
* @template TSelectKeys Valid keys of `selectModels`.
|
|
478
|
+
*/
|
|
479
|
+
export type BuildConfig<TSelectKeys extends PropertyKey = string> = {
|
|
480
|
+
/**
|
|
481
|
+
* Freezes the final repository object with `Object.freeze`.
|
|
482
|
+
* @deprecated No longer has any practical effect in the next version — freeze will be always applied.
|
|
483
|
+
*/
|
|
484
|
+
freeze?: boolean;
|
|
485
|
+
/** Prints internal working logs to the console. */
|
|
486
|
+
showWorking?: boolean;
|
|
487
|
+
/** Customizes the behavior of the automatic base methods. */
|
|
488
|
+
baseMethods?: {
|
|
489
|
+
/** Configuration for the `get` method. */
|
|
490
|
+
get?: BaseMethodConfig<TSelectKeys>;
|
|
491
|
+
/** Configuration for the `getOrThrow` method. */
|
|
492
|
+
getOrThrow?: BaseMethodConfig<TSelectKeys>;
|
|
493
|
+
/** Configuration for the `getList` method (fetch by list of PKs). */
|
|
494
|
+
getList?: BaseMethodConfig<TSelectKeys>;
|
|
495
|
+
/** Configuration for the `remove` method. */
|
|
496
|
+
remove?: BaseMethodConfig<TSelectKeys>;
|
|
497
|
+
/** Configuration for the `save` method. */
|
|
498
|
+
save?: BaseMethodConfig<TSelectKeys>;
|
|
499
|
+
/** Configuration for the `patch` method. */
|
|
500
|
+
patch?: BaseMethodConfig<TSelectKeys>;
|
|
501
|
+
/** Configuration for the `merge` method. */
|
|
502
|
+
merge?: BaseMethodConfig<TSelectKeys>;
|
|
503
|
+
/** Configuration for the `removeList` method (batch deletion). Does not accept select. */
|
|
504
|
+
removeList?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
|
|
505
|
+
/** Configuration for the `getAll` method (full listing). */
|
|
506
|
+
getAll?: BaseMethodConfig<TSelectKeys>;
|
|
507
|
+
/** Configuration for the `total` method (count). Does not accept select. */
|
|
508
|
+
total?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
|
|
509
|
+
/** Configuration for the `has` method (existence check). Does not accept select. */
|
|
510
|
+
has?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
|
|
511
|
+
/** Configuration for the `saveList` method (batch save via transaction). */
|
|
512
|
+
saveList?: BaseMethodConfig<TSelectKeys>;
|
|
513
|
+
/** Configuration for the `patchList` method (batch update via transaction). */
|
|
514
|
+
patchList?: BaseMethodConfig<TSelectKeys>;
|
|
515
|
+
/** Configuration for the `softRemove` method. Only available if `softRemovekName` is configured. */
|
|
516
|
+
softRemove?: BaseMethodConfig<TSelectKeys>;
|
|
517
|
+
/** Configuration for the `softRemoveList` method. Does not accept select. Only available if `softRemovekName` is configured. */
|
|
518
|
+
softRemoveList?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
|
|
519
|
+
/** Configuration for the `restore` method. Only available if `softRemovekName` is configured. */
|
|
520
|
+
restore?: BaseMethodConfig<TSelectKeys>;
|
|
521
|
+
/** Configuration for the `restoreList` method. Does not accept select. Only available if `softRemovekName` is configured. */
|
|
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 reused within the mapped type ───────────────────────────────────
|
|
545
|
+
// ─── relation payload types ──────────────────────────────────────────────────
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Distributive version of `Omit`, preserving unions when removing properties.
|
|
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
|
+
// Fields that are REQUIRED in this specific branch of the Prisma union
|
|
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
|
+
// Fields that are OPTIONAL in this branch or do not originally belong to it
|
|
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 accepted by `save` when the repository has configured relations.
|
|
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 accepted by `patch` when the repository has configured relations.
|
|
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
|
+
* Extracts the payload type of the `save` method from a configured VSRepository instance.
|
|
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
|
+
* Extracts the payload type of the `patch` method from a configured VSRepository instance.
|
|
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
|
+
// ─── refactored mapped type — optimized for the TS compiler ──────────────────
|
|
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
|
+
/** Fetches a record by its primary key (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
|
+
/** Fetches a record by PK and throws `VSRepoRuntimeError` if not found. */
|
|
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
|
+
/** Fetches multiple records by a list of primary keys (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
|
+
/** Deletes a record identified by its primary key (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
|
+
/** Inserts or updates (upsert) a record. */
|
|
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
|
+
/** Saves an array of objects in a single automatic transaction. */
|
|
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
|
+
/** Partially updates (patch) an existing record by its primary key (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
|
+
/** Partially updates multiple records via `[pk, obj]` tuples in an automatic transaction. */
|
|
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
|
+
/** Fetches a record by PK and deep-merges it with the provided object **in memory**. */
|
|
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
|
+
/** Deletes multiple records by their primary keys. */
|
|
708
|
+
removeList: (pks: _Pk<T, Config>[], options?: { db?: ClientOrTransaction }) => Promise<{ count: number }>;
|
|
709
|
+
|
|
710
|
+
/** Fetches all records (respects `requiredWhere` when set). */
|
|
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
|
+
/** Returns the total number of records. */
|
|
719
|
+
total: (options?: { db?: ClientOrTransaction; see?: SeeMode }) => Promise<number>;
|
|
720
|
+
|
|
721
|
+
/** Checks whether a record exists by its primary key (PK). */
|
|
722
|
+
has: (pk: _Pk<T, Config>, options?: { db?: ClientOrTransaction; see?: SeeMode }) => Promise<boolean>;
|
|
723
|
+
|
|
724
|
+
/** Marks a record as deleted (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
|
+
/** Marks multiple records as deleted (soft-delete) in batch. */
|
|
730
|
+
softRemoveList: (pks: _Pk<T, Config>[], options?: { db?: ClientOrTransaction }) => Promise<{ count: number }>;
|
|
731
|
+
|
|
732
|
+
/** Restores a record previously marked as deleted (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
|
+
/** Restores multiple records previously marked as deleted (soft-delete) in batch. */
|
|
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
|
+
* Relation configuration for One-to-Many or Many-to-Many.
|
|
776
|
+
*
|
|
777
|
+
* @template TItem Type of the related entity.
|
|
778
|
+
*/
|
|
779
|
+
export type ManyRelationConfig<TItem> = {
|
|
780
|
+
/** Primary key of the related entity. */
|
|
781
|
+
pk: keyof TItem;
|
|
782
|
+
/** Relation type: `otm` (One-to-Many) or `mtm` (Many-to-Many). */
|
|
783
|
+
mode: 'otm' | 'mtm';
|
|
784
|
+
/** Mutation behavior: `set` (replaces all) or `add` (appends to existing). */
|
|
785
|
+
restriction: 'set' | 'add';
|
|
786
|
+
};
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* One-to-One relation configuration.
|
|
790
|
+
*
|
|
791
|
+
* @template TItem Type of the related entity.
|
|
792
|
+
*/
|
|
793
|
+
export type OneToOneRelationConfig<TItem> = {
|
|
794
|
+
/** Primary key of the related entity. */
|
|
795
|
+
pk: keyof TItem;
|
|
796
|
+
/** Relation type: `oto` (One-to-One). */
|
|
797
|
+
mode: 'oto';
|
|
798
|
+
/** Allowed mutation behavior for saving. */
|
|
799
|
+
restriction: 'set' | 'add';
|
|
800
|
+
};
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* Many-to-One relation configuration.
|
|
804
|
+
*
|
|
805
|
+
* @template TItem Type of the related entity.
|
|
806
|
+
*/
|
|
807
|
+
export type ManyToOneRelationConfig<TItem> = {
|
|
808
|
+
/** Primary key of the related entity. */
|
|
809
|
+
pk: keyof TItem;
|
|
810
|
+
/** Relation type: `mto` (Many-to-One). */
|
|
811
|
+
mode: 'mto';
|
|
812
|
+
/** Allowed mutation behavior for saving. */
|
|
813
|
+
restriction: 'set' | 'add';
|
|
814
|
+
/**
|
|
815
|
+
* Enables the ability to unlink the relation, setting the foreign key to null.
|
|
816
|
+
* @deprecated Use `nullable` (lowercase) instead of `nullAble`.
|
|
817
|
+
*/
|
|
818
|
+
nullAble?: boolean;
|
|
819
|
+
/** Enables the ability to unlink the relation, setting the foreign key to null. */
|
|
820
|
+
nullable?: boolean;
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* Automatically infers the possible relation configuration from a field.
|
|
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
|
+
* Map of configurable relations for an entity type.
|
|
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
|
+
* Main configuration used in `setupVSRepo<T, M>()(config)`.
|
|
844
|
+
*
|
|
845
|
+
* @template T Type of the entity managed by the repository.
|
|
846
|
+
* @template M Prisma model name.
|
|
847
|
+
* @template SM Map of named select models.
|
|
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
|
+
softRemovekName?: keyof T & string;
|
|
853
|
+
selectModels?: SM;
|
|
854
|
+
defaultSelectModel?: Extract<keyof SM, string>;
|
|
855
|
+
requiredWhere?: WhereModel<M>;
|
|
856
|
+
relations?: RepositoryRelations<T>;
|
|
857
|
+
methods?: Record<string, MethodConfig<M, SM>>;
|
|
858
|
+
};
|
|
859
|
+
|
|
860
|
+
/**
|
|
861
|
+
* Final type returned by `.build(prisma)`.
|
|
862
|
+
*
|
|
863
|
+
* Combines dynamic methods, base methods, and custom extensions.
|
|
864
|
+
*/
|
|
865
|
+
type BuiltRepository<T extends object, M extends Prisma.ModelName, Config extends RepoConfig<T, M, any>, C extends BuildConfig<any> | undefined> = {
|
|
866
|
+
/**
|
|
867
|
+
* Extends the repository with custom methods without losing type inference.
|
|
868
|
+
*/
|
|
869
|
+
extend<E>(extensionFunc: (repo: BuiltRepository<T, M, Config, C>) => E): BuiltRepository<T, M, Config, C> & E;
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* The Prisma Client instance passed to `build`.
|
|
873
|
+
*/
|
|
874
|
+
readonly prisma: DbClient;
|
|
875
|
+
} & DynamicMethods<T, M, Config, PrismaModelInputs<M>> & InjectedBaseMethods<T, M, Config, C>;
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* Typed repository factory based on the Prisma model configuration.
|
|
879
|
+
*/
|
|
880
|
+
export declare class VSRepository<T extends object, M extends Prisma.ModelName, const Config extends RepoConfig<T, M, any> = RepoConfig<T, M, any>> {
|
|
881
|
+
/** Original configuration provided to `setupVSRepo`. */
|
|
882
|
+
readonly config: Config;
|
|
883
|
+
/**
|
|
884
|
+
* Creates a configurable instance of `VSRepository`.
|
|
885
|
+
*/
|
|
886
|
+
constructor(config: Config);
|
|
887
|
+
/**
|
|
888
|
+
* Builds the final repository with base and dynamic methods.
|
|
889
|
+
*/
|
|
890
|
+
build<C extends BuildConfig<keyof ExtractSelectModels<Config>>>(prisma: DbClient, config?: C): BuiltRepository<T, M, Config, C>;
|
|
891
|
+
vsrepocache: never;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* Infers the type of an already-configured repository from a `VSRepository` instance.
|
|
896
|
+
*
|
|
897
|
+
* Also allows manually providing the `BuildConfig` and extensions type.
|
|
898
|
+
*/
|
|
899
|
+
export type RepositoryOf<TRepo, C extends BuildConfig<any> | undefined = undefined, E = unknown> =
|
|
900
|
+
TRepo extends VSRepository<infer T, infer M, infer Config>
|
|
901
|
+
? Simplify<BuiltRepository<T, M, Config, C> & E>
|
|
902
|
+
: never;
|
|
903
|
+
|
|
904
|
+
/**
|
|
905
|
+
* Utility type used to validate a repository configuration at compile time.
|
|
906
|
+
*/
|
|
907
|
+
export type ValidateRepoConfig<T extends object, M extends Prisma.ModelName, Config> = {
|
|
908
|
+
/**
|
|
909
|
+
* Name of the table mapped by Prisma (usually uncapitalized).
|
|
910
|
+
*/
|
|
911
|
+
tableName: Uncapitalize<M>;
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* Name of the field that represents the entity's primary key (Primary Key).
|
|
915
|
+
*/
|
|
916
|
+
pkName: keyof T;
|
|
917
|
+
|
|
918
|
+
/**
|
|
919
|
+
* Name of the `DateTime` field used for soft-delete.
|
|
920
|
+
*
|
|
921
|
+
* When configured, enables the `softRemove`, `softRemoveList`, `restore`, and `restoreList` methods.
|
|
922
|
+
* The field **must** be of type `DateTime` in the Prisma schema — VSRepository validates this during `build`.
|
|
923
|
+
*/
|
|
924
|
+
softRemovekName?: keyof T & string;
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* Defines named and reusable data projections (selects).
|
|
928
|
+
* Allows creating different views of the same entity (e.g., `public`, `minimal`, `internal`).
|
|
929
|
+
*/
|
|
930
|
+
selectModels?: SelectModels<M>;
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* Defines which select (a key from `selectModels`) will be used automatically
|
|
934
|
+
* when none is specified in the method call.
|
|
935
|
+
* It is highly recommended to define it whenever `selectModels` are used.
|
|
936
|
+
*/
|
|
937
|
+
defaultSelectModel?: string;
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* Defines global filters that will be automatically applied to all repository queries.
|
|
941
|
+
* Useful for tenant isolation (multi-tenancy) or base restrictions (e.g., `isActive: true`).
|
|
942
|
+
*/
|
|
943
|
+
requiredWhere?: WhereModel<M>;
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* Configures automatic relation management.
|
|
947
|
+
* When configured, allows the `save`, `saveList`, `patch`, and `patchList` methods
|
|
948
|
+
* to automatically handle linking, creation, or cascading deletion of related records.
|
|
949
|
+
*/
|
|
950
|
+
relations?: RepositoryRelations<T>;
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* Definition of dynamic repository methods.
|
|
954
|
+
* Behaviors and return types are automatically inferred from the method's name
|
|
955
|
+
* (e.g., `findOneByEmail`, `findManyPaginated`) or proxied via the `proxyTo` property.
|
|
956
|
+
*/
|
|
957
|
+
methods?: {
|
|
958
|
+
[K in keyof (Config extends { methods: infer Meth } ? Meth : {})]: K extends string
|
|
959
|
+
? MethodConfig<M, Config extends { selectModels: infer SM } ? SM : any> & (K extends ValidMethodPatterns ? {} : { proxyTo: ValidMethodPatterns })
|
|
960
|
+
: never;
|
|
961
|
+
};
|
|
962
|
+
};
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* Function to initialize and configure the `repository`.
|
|
966
|
+
* The configuration passed here is what will be read when `.build()` is called.
|
|
967
|
+
*/
|
|
968
|
+
export declare function setupVSRepo<T extends object, M extends Prisma.ModelName>(): <
|
|
969
|
+
const SM extends Record<string, SelectModel<M>>,
|
|
970
|
+
const Config extends RepoConfig<T, M, SM>
|
|
971
|
+
>(
|
|
972
|
+
config: Config & ValidateRepoConfig<T, M, Config>
|
|
973
|
+
) => VSRepository<T, M, Config>;
|