prisma-generator-express 1.38.0 → 1.39.0
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 +124 -84
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -301,8 +301,10 @@ app.use((req, res, next) => {
|
|
|
301
301
|
app.use('/', UserRouter({
|
|
302
302
|
findMany: {
|
|
303
303
|
shape: {
|
|
304
|
-
|
|
305
|
-
|
|
304
|
+
default: {
|
|
305
|
+
where: { name: { contains: true } },
|
|
306
|
+
take: { max: 50, default: 20 },
|
|
307
|
+
},
|
|
306
308
|
},
|
|
307
309
|
},
|
|
308
310
|
}))
|
|
@@ -322,34 +324,46 @@ Each operation config accepts an optional `shape` property. When present, the ge
|
|
|
322
324
|
|
|
323
325
|
When `shape` is absent, the handler calls Prisma directly with no guard enforcement.
|
|
324
326
|
|
|
325
|
-
|
|
327
|
+
Generated route config types treat `shape` as a named shape map. Use `default` for the normal single-shape case, and add other keys only when you need caller-based variants. The runtime still passes the map to `prisma-guard`; the `default` variant is selected when no caller is provided or no variant matches.
|
|
328
|
+
|
|
329
|
+
### Default shape per operation
|
|
330
|
+
|
|
331
|
+
In generated route configs, `shape` is always a named shape map. Use the `default` key when an operation has one normal shape and no caller-specific variants.
|
|
326
332
|
|
|
327
|
-
|
|
333
|
+
`default` is used when no caller is provided or when the caller does not match a named variant. If you do not want fallback behavior, omit `default` and define only explicit variants.
|
|
328
334
|
|
|
329
335
|
```ts
|
|
330
336
|
const userConfig = {
|
|
331
337
|
findMany: {
|
|
332
338
|
shape: {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
339
|
+
default: {
|
|
340
|
+
where: { email: { contains: true }, role: { equals: true } },
|
|
341
|
+
orderBy: { createdAt: true },
|
|
342
|
+
take: { max: 100, default: 25 },
|
|
343
|
+
skip: true,
|
|
344
|
+
},
|
|
337
345
|
},
|
|
338
346
|
},
|
|
339
347
|
create: {
|
|
340
348
|
shape: {
|
|
341
|
-
|
|
349
|
+
default: {
|
|
350
|
+
data: { email: true, name: true, role: 'user' },
|
|
351
|
+
},
|
|
342
352
|
},
|
|
343
353
|
},
|
|
344
354
|
update: {
|
|
345
355
|
shape: {
|
|
346
|
-
|
|
347
|
-
|
|
356
|
+
default: {
|
|
357
|
+
data: { name: true },
|
|
358
|
+
where: { id: { equals: true } },
|
|
359
|
+
},
|
|
348
360
|
},
|
|
349
361
|
},
|
|
350
362
|
delete: {
|
|
351
363
|
shape: {
|
|
352
|
-
|
|
364
|
+
default: {
|
|
365
|
+
where: { id: { equals: true } },
|
|
366
|
+
},
|
|
353
367
|
},
|
|
354
368
|
},
|
|
355
369
|
}
|
|
@@ -374,12 +388,14 @@ import { force } from 'prisma-guard'
|
|
|
374
388
|
const config = {
|
|
375
389
|
create: {
|
|
376
390
|
shape: {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
391
|
+
default: {
|
|
392
|
+
data: {
|
|
393
|
+
email: true, // client-controlled, @zod chains apply
|
|
394
|
+
name: true, // client-controlled
|
|
395
|
+
role: 'member', // forced to 'member', client cannot override
|
|
396
|
+
isActive: force(true), // forced to boolean true (force() needed to distinguish from client-controlled)
|
|
397
|
+
bio: (base) => base.max(500), // client-controlled with inline validation override
|
|
398
|
+
},
|
|
383
399
|
},
|
|
384
400
|
},
|
|
385
401
|
},
|
|
@@ -539,13 +555,15 @@ import { force } from 'prisma-guard'
|
|
|
539
555
|
const projectConfig = {
|
|
540
556
|
findMany: {
|
|
541
557
|
shape: {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
558
|
+
default: {
|
|
559
|
+
where: {
|
|
560
|
+
status: { equals: 'published' }, // always filter to published
|
|
561
|
+
isDeleted: { equals: false }, // always exclude deleted
|
|
562
|
+
isActive: { equals: force(true) }, // force() needed for boolean true
|
|
563
|
+
title: { contains: true }, // client-controlled
|
|
564
|
+
},
|
|
565
|
+
take: { max: 50 },
|
|
547
566
|
},
|
|
548
|
-
take: { max: 50 },
|
|
549
567
|
},
|
|
550
568
|
},
|
|
551
569
|
}
|
|
@@ -570,14 +588,16 @@ Where shapes support `AND`, `OR`, and `NOT`. The combinator value defines which
|
|
|
570
588
|
const config = {
|
|
571
589
|
findMany: {
|
|
572
590
|
shape: {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
591
|
+
default: {
|
|
592
|
+
where: {
|
|
593
|
+
OR: {
|
|
594
|
+
title: { contains: true },
|
|
595
|
+
description: { contains: true },
|
|
596
|
+
},
|
|
597
|
+
status: { equals: 'published' }, // forced, always applied
|
|
577
598
|
},
|
|
578
|
-
|
|
599
|
+
take: { max: 50 },
|
|
579
600
|
},
|
|
580
|
-
take: { max: 50 },
|
|
581
601
|
},
|
|
582
602
|
},
|
|
583
603
|
}
|
|
@@ -606,15 +626,17 @@ Where shapes support relation-level filters. To-many relations use `some`, `ever
|
|
|
606
626
|
const userConfig = {
|
|
607
627
|
findMany: {
|
|
608
628
|
shape: {
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
629
|
+
default: {
|
|
630
|
+
where: {
|
|
631
|
+
posts: {
|
|
632
|
+
some: {
|
|
633
|
+
title: { contains: true },
|
|
634
|
+
published: { equals: true }, // forced inside the relation
|
|
635
|
+
},
|
|
614
636
|
},
|
|
615
637
|
},
|
|
638
|
+
take: { max: 50 },
|
|
616
639
|
},
|
|
617
|
-
take: { max: 50 },
|
|
618
640
|
},
|
|
619
641
|
},
|
|
620
642
|
}
|
|
@@ -630,19 +652,21 @@ Shapes can restrict which response fields and relations the client may request:
|
|
|
630
652
|
const userConfig = {
|
|
631
653
|
findMany: {
|
|
632
654
|
shape: {
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
655
|
+
default: {
|
|
656
|
+
where: { role: { equals: true } },
|
|
657
|
+
select: {
|
|
658
|
+
id: true,
|
|
659
|
+
email: true,
|
|
660
|
+
name: true,
|
|
661
|
+
posts: {
|
|
662
|
+
select: { id: true, title: true },
|
|
663
|
+
},
|
|
664
|
+
_count: {
|
|
665
|
+
select: { posts: true },
|
|
666
|
+
},
|
|
643
667
|
},
|
|
668
|
+
take: { max: 50 },
|
|
644
669
|
},
|
|
645
|
-
take: { max: 50 },
|
|
646
670
|
},
|
|
647
671
|
},
|
|
648
672
|
}
|
|
@@ -666,23 +690,25 @@ import { force } from 'prisma-guard'
|
|
|
666
690
|
const userConfig = {
|
|
667
691
|
findMany: {
|
|
668
692
|
shape: {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
693
|
+
default: {
|
|
694
|
+
include: {
|
|
695
|
+
posts: {
|
|
696
|
+
where: { isDeleted: { equals: false } }, // forced: never return deleted posts
|
|
697
|
+
orderBy: { createdAt: true },
|
|
698
|
+
take: { max: 20, default: 10 },
|
|
699
|
+
skip: true,
|
|
700
|
+
},
|
|
701
|
+
profile: true, // simple include, no constraints
|
|
702
|
+
_count: {
|
|
703
|
+
select: {
|
|
704
|
+
posts: {
|
|
705
|
+
where: { isDeleted: { equals: false } }, // count only non-deleted
|
|
706
|
+
},
|
|
681
707
|
},
|
|
682
708
|
},
|
|
683
709
|
},
|
|
710
|
+
take: { max: 50 },
|
|
684
711
|
},
|
|
685
|
-
take: { max: 50 },
|
|
686
712
|
},
|
|
687
713
|
},
|
|
688
714
|
}
|
|
@@ -696,20 +722,24 @@ Write operations that return records (`create`, `update`, `upsert`, `delete`, `c
|
|
|
696
722
|
const userConfig = {
|
|
697
723
|
create: {
|
|
698
724
|
shape: {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
725
|
+
default: {
|
|
726
|
+
data: { email: true, name: true },
|
|
727
|
+
include: {
|
|
728
|
+
profile: true,
|
|
729
|
+
},
|
|
702
730
|
},
|
|
703
731
|
},
|
|
704
732
|
},
|
|
705
733
|
update: {
|
|
706
734
|
shape: {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
735
|
+
default: {
|
|
736
|
+
data: { name: true },
|
|
737
|
+
where: { id: { equals: true } },
|
|
738
|
+
select: {
|
|
739
|
+
id: true,
|
|
740
|
+
name: true,
|
|
741
|
+
updatedAt: true,
|
|
742
|
+
},
|
|
713
743
|
},
|
|
714
744
|
},
|
|
715
745
|
},
|
|
@@ -730,16 +760,18 @@ import { force } from 'prisma-guard'
|
|
|
730
760
|
const projectConfig = {
|
|
731
761
|
upsert: {
|
|
732
762
|
shape: {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
763
|
+
default: {
|
|
764
|
+
where: { id: { equals: true } },
|
|
765
|
+
create: {
|
|
766
|
+
title: true,
|
|
767
|
+
status: 'draft',
|
|
768
|
+
isActive: force(true),
|
|
769
|
+
},
|
|
770
|
+
update: {
|
|
771
|
+
title: true,
|
|
772
|
+
},
|
|
773
|
+
select: { id: true, title: true, status: true },
|
|
741
774
|
},
|
|
742
|
-
select: { id: true, title: true, status: true },
|
|
743
775
|
},
|
|
744
776
|
},
|
|
745
777
|
}
|
|
@@ -755,13 +787,17 @@ All three (`where`, `create`, `update`) are required. Using `data` instead of `c
|
|
|
755
787
|
const userConfig = {
|
|
756
788
|
deleteMany: {
|
|
757
789
|
shape: {
|
|
758
|
-
|
|
790
|
+
default: {
|
|
791
|
+
where: { isActive: { equals: true }, role: { equals: true } },
|
|
792
|
+
},
|
|
759
793
|
},
|
|
760
794
|
},
|
|
761
795
|
updateMany: {
|
|
762
796
|
shape: {
|
|
763
|
-
|
|
764
|
-
|
|
797
|
+
default: {
|
|
798
|
+
data: { isActive: true },
|
|
799
|
+
where: { role: { equals: true } },
|
|
800
|
+
},
|
|
765
801
|
},
|
|
766
802
|
},
|
|
767
803
|
}
|
|
@@ -812,13 +848,17 @@ app.use((req, res, next) => {
|
|
|
812
848
|
app.use('/', ProjectRouter({
|
|
813
849
|
findMany: {
|
|
814
850
|
shape: {
|
|
815
|
-
|
|
816
|
-
|
|
851
|
+
default: {
|
|
852
|
+
where: { title: { contains: true } },
|
|
853
|
+
take: { max: 50 },
|
|
854
|
+
},
|
|
817
855
|
},
|
|
818
856
|
},
|
|
819
857
|
create: {
|
|
820
858
|
shape: {
|
|
821
|
-
|
|
859
|
+
default: {
|
|
860
|
+
data: { title: true },
|
|
861
|
+
},
|
|
822
862
|
},
|
|
823
863
|
},
|
|
824
864
|
}))
|
package/package.json
CHANGED