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.
Files changed (2) hide show
  1. package/README.md +124 -84
  2. 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
- where: { name: { contains: true } },
305
- take: { max: 50, default: 20 },
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
- ### Single shape per operation
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
- A single shape object restricts what the client can do on that operation. No caller routing is needed.
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
- where: { email: { contains: true }, role: { equals: true } },
334
- orderBy: { createdAt: true },
335
- take: { max: 100, default: 25 },
336
- skip: true,
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
- data: { email: true, name: true, role: 'user' },
349
+ default: {
350
+ data: { email: true, name: true, role: 'user' },
351
+ },
342
352
  },
343
353
  },
344
354
  update: {
345
355
  shape: {
346
- data: { name: true },
347
- where: { id: { equals: true } },
356
+ default: {
357
+ data: { name: true },
358
+ where: { id: { equals: true } },
359
+ },
348
360
  },
349
361
  },
350
362
  delete: {
351
363
  shape: {
352
- where: { id: { equals: true } },
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
- data: {
378
- email: true, // client-controlled, @zod chains apply
379
- name: true, // client-controlled
380
- role: 'member', // forced to 'member', client cannot override
381
- isActive: force(true), // forced to boolean true (force() needed to distinguish from client-controlled)
382
- bio: (base) => base.max(500), // client-controlled with inline validation override
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
- where: {
543
- status: { equals: 'published' }, // always filter to published
544
- isDeleted: { equals: false }, // always exclude deleted
545
- isActive: { equals: force(true) }, // force() needed for boolean true
546
- title: { contains: true }, // client-controlled
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
- where: {
574
- OR: {
575
- title: { contains: true },
576
- description: { contains: true },
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
- status: { equals: 'published' }, // forced, always applied
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
- where: {
610
- posts: {
611
- some: {
612
- title: { contains: true },
613
- published: { equals: true }, // forced inside the relation
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
- where: { role: { equals: true } },
634
- select: {
635
- id: true,
636
- email: true,
637
- name: true,
638
- posts: {
639
- select: { id: true, title: true },
640
- },
641
- _count: {
642
- select: { posts: true },
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
- include: {
670
- posts: {
671
- where: { isDeleted: { equals: false } }, // forced: never return deleted posts
672
- orderBy: { createdAt: true },
673
- take: { max: 20, default: 10 },
674
- skip: true,
675
- },
676
- profile: true, // simple include, no constraints
677
- _count: {
678
- select: {
679
- posts: {
680
- where: { isDeleted: { equals: false } }, // count only non-deleted
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
- data: { email: true, name: true },
700
- include: {
701
- profile: true,
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
- data: { name: true },
708
- where: { id: { equals: true } },
709
- select: {
710
- id: true,
711
- name: true,
712
- updatedAt: true,
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
- where: { id: { equals: true } },
734
- create: {
735
- title: true,
736
- status: 'draft',
737
- isActive: force(true),
738
- },
739
- update: {
740
- title: true,
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
- where: { isActive: { equals: true }, role: { equals: true } },
790
+ default: {
791
+ where: { isActive: { equals: true }, role: { equals: true } },
792
+ },
759
793
  },
760
794
  },
761
795
  updateMany: {
762
796
  shape: {
763
- data: { isActive: true },
764
- where: { role: { equals: true } },
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
- where: { title: { contains: true } },
816
- take: { max: 50 },
851
+ default: {
852
+ where: { title: { contains: true } },
853
+ take: { max: 50 },
854
+ },
817
855
  },
818
856
  },
819
857
  create: {
820
858
  shape: {
821
- data: { title: true },
859
+ default: {
860
+ data: { title: true },
861
+ },
822
862
  },
823
863
  },
824
864
  }))
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "prisma-generator-express",
3
3
  "description": "Prisma generator for Express/Fastify CRUD API with OpenAPI documentation",
4
- "version": "1.38.0",
4
+ "version": "1.39.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "MIT",