@anievo-id/rbac-evolution-drizzle 1.1.0 → 1.3.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/dist/{chunk-WE5ZHXEW.js → chunk-3AH2K6KS.js} +77 -27
- package/dist/chunk-3AH2K6KS.js.map +1 -0
- package/dist/{chunk-HDQ5ACTJ.js → chunk-CK2CKZPC.js} +49 -6
- package/dist/chunk-CK2CKZPC.js.map +1 -0
- package/dist/{chunk-D6UKXFGV.js → chunk-CQBJTVGQ.js} +48 -5
- package/dist/chunk-CQBJTVGQ.js.map +1 -0
- package/dist/{chunk-4KGIPA5W.js → chunk-SPNXRYKH.js} +48 -5
- package/dist/chunk-SPNXRYKH.js.map +1 -0
- package/dist/index.cjs +209 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -114
- package/dist/index.d.ts +6 -114
- package/dist/index.js +4 -4
- package/dist/mysql.cjs +119 -26
- package/dist/mysql.cjs.map +1 -1
- package/dist/mysql.d.cts +447 -5
- package/dist/mysql.d.ts +447 -5
- package/dist/mysql.js +2 -2
- package/dist/names-DD-kYSFO.d.cts +146 -0
- package/dist/names-DD-kYSFO.d.ts +146 -0
- package/dist/pg.cjs +119 -26
- package/dist/pg.cjs.map +1 -1
- package/dist/pg.d.cts +447 -5
- package/dist/pg.d.ts +447 -5
- package/dist/pg.js +2 -2
- package/dist/sqlite.cjs +119 -26
- package/dist/sqlite.cjs.map +1 -1
- package/dist/sqlite.d.cts +469 -5
- package/dist/sqlite.d.ts +469 -5
- package/dist/sqlite.js +2 -2
- package/package.json +5 -2
- package/sql/mysql-expiry.sql +9 -0
- package/sql/pg-expiry.sql +8 -0
- package/sql/sqlite-expiry.sql +10 -0
- package/dist/chunk-4KGIPA5W.js.map +0 -1
- package/dist/chunk-D6UKXFGV.js.map +0 -1
- package/dist/chunk-HDQ5ACTJ.js.map +0 -1
- package/dist/chunk-WE5ZHXEW.js.map +0 -1
- package/dist/names-BVofJeMN.d.cts +0 -13
- package/dist/names-BVofJeMN.d.ts +0 -13
package/dist/sqlite.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { RbacAdapter } from '@anievo-id/rbac-evolution';
|
|
2
2
|
import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
|
|
3
3
|
import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core';
|
|
4
|
-
import { R as RbacSchemaOptions } from './names-
|
|
4
|
+
import { R as RbacSchemaOptions, D as DrizzleAdapterOptions } from './names-DD-kYSFO.js';
|
|
5
|
+
import 'drizzle-orm';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Builds the rbac-evolution tables for SQLite — libsql / Turso, better-sqlite3, D1, bun:sqlite... (mirrors spatie/laravel-permission).
|
|
@@ -11,7 +12,12 @@ import { R as RbacSchemaOptions } from './names-BVofJeMN.js';
|
|
|
11
12
|
* export const { permissions, roles, roleHasPermissions, modelHasRoles, modelHasPermissions } = sqliteRbacSchema()
|
|
12
13
|
* ```
|
|
13
14
|
*/
|
|
14
|
-
declare function sqliteRbacSchema(options
|
|
15
|
+
declare function sqliteRbacSchema(options: RbacSchemaOptions & {
|
|
16
|
+
expiry: true;
|
|
17
|
+
}): SqliteRbacExpirySchema;
|
|
18
|
+
declare function sqliteRbacSchema(options?: RbacSchemaOptions): SqliteRbacSchema;
|
|
19
|
+
/** The five tables, as in 1.1. */
|
|
20
|
+
declare function buildSqlite(options: RbacSchemaOptions): {
|
|
15
21
|
permissions: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
16
22
|
name: string;
|
|
17
23
|
schema: undefined;
|
|
@@ -427,7 +433,464 @@ declare function sqliteRbacSchema(options?: RbacSchemaOptions): {
|
|
|
427
433
|
dialect: "sqlite";
|
|
428
434
|
}>;
|
|
429
435
|
};
|
|
430
|
-
|
|
436
|
+
/**
|
|
437
|
+
* The tables of `sqliteRbacSchema({ expiry: true })`: the 1.1 tables, with a nullable `expires_at` column on
|
|
438
|
+
* `model_has_roles` and `model_has_permissions` (1.2).
|
|
439
|
+
*/
|
|
440
|
+
declare function buildSqliteExpiry(options: RbacSchemaOptions): {
|
|
441
|
+
permissions: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
442
|
+
name: string;
|
|
443
|
+
schema: undefined;
|
|
444
|
+
columns: {
|
|
445
|
+
createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
446
|
+
name: "created_at";
|
|
447
|
+
tableName: string;
|
|
448
|
+
dataType: "date";
|
|
449
|
+
columnType: "SQLiteTimestamp";
|
|
450
|
+
data: Date;
|
|
451
|
+
driverParam: number;
|
|
452
|
+
notNull: true;
|
|
453
|
+
hasDefault: true;
|
|
454
|
+
isPrimaryKey: false;
|
|
455
|
+
isAutoincrement: false;
|
|
456
|
+
hasRuntimeDefault: false;
|
|
457
|
+
enumValues: undefined;
|
|
458
|
+
baseColumn: never;
|
|
459
|
+
identity: undefined;
|
|
460
|
+
generated: undefined;
|
|
461
|
+
}, {}, {}>;
|
|
462
|
+
updatedAt: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
463
|
+
name: "updated_at";
|
|
464
|
+
tableName: string;
|
|
465
|
+
dataType: "date";
|
|
466
|
+
columnType: "SQLiteTimestamp";
|
|
467
|
+
data: Date;
|
|
468
|
+
driverParam: number;
|
|
469
|
+
notNull: true;
|
|
470
|
+
hasDefault: true;
|
|
471
|
+
isPrimaryKey: false;
|
|
472
|
+
isAutoincrement: false;
|
|
473
|
+
hasRuntimeDefault: false;
|
|
474
|
+
enumValues: undefined;
|
|
475
|
+
baseColumn: never;
|
|
476
|
+
identity: undefined;
|
|
477
|
+
generated: undefined;
|
|
478
|
+
}, {}, {}>;
|
|
479
|
+
id: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
480
|
+
name: "id";
|
|
481
|
+
tableName: string;
|
|
482
|
+
dataType: "number";
|
|
483
|
+
columnType: "SQLiteInteger";
|
|
484
|
+
data: number;
|
|
485
|
+
driverParam: number;
|
|
486
|
+
notNull: true;
|
|
487
|
+
hasDefault: true;
|
|
488
|
+
isPrimaryKey: true;
|
|
489
|
+
isAutoincrement: false;
|
|
490
|
+
hasRuntimeDefault: false;
|
|
491
|
+
enumValues: undefined;
|
|
492
|
+
baseColumn: never;
|
|
493
|
+
identity: undefined;
|
|
494
|
+
generated: undefined;
|
|
495
|
+
}, {}, {}>;
|
|
496
|
+
name: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
497
|
+
name: "name";
|
|
498
|
+
tableName: string;
|
|
499
|
+
dataType: "string";
|
|
500
|
+
columnType: "SQLiteText";
|
|
501
|
+
data: string;
|
|
502
|
+
driverParam: string;
|
|
503
|
+
notNull: true;
|
|
504
|
+
hasDefault: false;
|
|
505
|
+
isPrimaryKey: false;
|
|
506
|
+
isAutoincrement: false;
|
|
507
|
+
hasRuntimeDefault: false;
|
|
508
|
+
enumValues: [string, ...string[]];
|
|
509
|
+
baseColumn: never;
|
|
510
|
+
identity: undefined;
|
|
511
|
+
generated: undefined;
|
|
512
|
+
}, {}, {
|
|
513
|
+
length: number | undefined;
|
|
514
|
+
}>;
|
|
515
|
+
guardName: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
516
|
+
name: "guard_name";
|
|
517
|
+
tableName: string;
|
|
518
|
+
dataType: "string";
|
|
519
|
+
columnType: "SQLiteText";
|
|
520
|
+
data: string;
|
|
521
|
+
driverParam: string;
|
|
522
|
+
notNull: true;
|
|
523
|
+
hasDefault: false;
|
|
524
|
+
isPrimaryKey: false;
|
|
525
|
+
isAutoincrement: false;
|
|
526
|
+
hasRuntimeDefault: false;
|
|
527
|
+
enumValues: [string, ...string[]];
|
|
528
|
+
baseColumn: never;
|
|
529
|
+
identity: undefined;
|
|
530
|
+
generated: undefined;
|
|
531
|
+
}, {}, {
|
|
532
|
+
length: number | undefined;
|
|
533
|
+
}>;
|
|
534
|
+
};
|
|
535
|
+
dialect: "sqlite";
|
|
536
|
+
}>;
|
|
537
|
+
roles: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
538
|
+
name: string;
|
|
539
|
+
schema: undefined;
|
|
540
|
+
columns: {
|
|
541
|
+
createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
542
|
+
name: "created_at";
|
|
543
|
+
tableName: string;
|
|
544
|
+
dataType: "date";
|
|
545
|
+
columnType: "SQLiteTimestamp";
|
|
546
|
+
data: Date;
|
|
547
|
+
driverParam: number;
|
|
548
|
+
notNull: true;
|
|
549
|
+
hasDefault: true;
|
|
550
|
+
isPrimaryKey: false;
|
|
551
|
+
isAutoincrement: false;
|
|
552
|
+
hasRuntimeDefault: false;
|
|
553
|
+
enumValues: undefined;
|
|
554
|
+
baseColumn: never;
|
|
555
|
+
identity: undefined;
|
|
556
|
+
generated: undefined;
|
|
557
|
+
}, {}, {}>;
|
|
558
|
+
updatedAt: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
559
|
+
name: "updated_at";
|
|
560
|
+
tableName: string;
|
|
561
|
+
dataType: "date";
|
|
562
|
+
columnType: "SQLiteTimestamp";
|
|
563
|
+
data: Date;
|
|
564
|
+
driverParam: number;
|
|
565
|
+
notNull: true;
|
|
566
|
+
hasDefault: true;
|
|
567
|
+
isPrimaryKey: false;
|
|
568
|
+
isAutoincrement: false;
|
|
569
|
+
hasRuntimeDefault: false;
|
|
570
|
+
enumValues: undefined;
|
|
571
|
+
baseColumn: never;
|
|
572
|
+
identity: undefined;
|
|
573
|
+
generated: undefined;
|
|
574
|
+
}, {}, {}>;
|
|
575
|
+
id: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
576
|
+
name: "id";
|
|
577
|
+
tableName: string;
|
|
578
|
+
dataType: "number";
|
|
579
|
+
columnType: "SQLiteInteger";
|
|
580
|
+
data: number;
|
|
581
|
+
driverParam: number;
|
|
582
|
+
notNull: true;
|
|
583
|
+
hasDefault: true;
|
|
584
|
+
isPrimaryKey: true;
|
|
585
|
+
isAutoincrement: false;
|
|
586
|
+
hasRuntimeDefault: false;
|
|
587
|
+
enumValues: undefined;
|
|
588
|
+
baseColumn: never;
|
|
589
|
+
identity: undefined;
|
|
590
|
+
generated: undefined;
|
|
591
|
+
}, {}, {}>;
|
|
592
|
+
name: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
593
|
+
name: "name";
|
|
594
|
+
tableName: string;
|
|
595
|
+
dataType: "string";
|
|
596
|
+
columnType: "SQLiteText";
|
|
597
|
+
data: string;
|
|
598
|
+
driverParam: string;
|
|
599
|
+
notNull: true;
|
|
600
|
+
hasDefault: false;
|
|
601
|
+
isPrimaryKey: false;
|
|
602
|
+
isAutoincrement: false;
|
|
603
|
+
hasRuntimeDefault: false;
|
|
604
|
+
enumValues: [string, ...string[]];
|
|
605
|
+
baseColumn: never;
|
|
606
|
+
identity: undefined;
|
|
607
|
+
generated: undefined;
|
|
608
|
+
}, {}, {
|
|
609
|
+
length: number | undefined;
|
|
610
|
+
}>;
|
|
611
|
+
guardName: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
612
|
+
name: "guard_name";
|
|
613
|
+
tableName: string;
|
|
614
|
+
dataType: "string";
|
|
615
|
+
columnType: "SQLiteText";
|
|
616
|
+
data: string;
|
|
617
|
+
driverParam: string;
|
|
618
|
+
notNull: true;
|
|
619
|
+
hasDefault: false;
|
|
620
|
+
isPrimaryKey: false;
|
|
621
|
+
isAutoincrement: false;
|
|
622
|
+
hasRuntimeDefault: false;
|
|
623
|
+
enumValues: [string, ...string[]];
|
|
624
|
+
baseColumn: never;
|
|
625
|
+
identity: undefined;
|
|
626
|
+
generated: undefined;
|
|
627
|
+
}, {}, {
|
|
628
|
+
length: number | undefined;
|
|
629
|
+
}>;
|
|
630
|
+
teamId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
631
|
+
name: "team_id";
|
|
632
|
+
tableName: string;
|
|
633
|
+
dataType: "string";
|
|
634
|
+
columnType: "SQLiteText";
|
|
635
|
+
data: string;
|
|
636
|
+
driverParam: string;
|
|
637
|
+
notNull: true;
|
|
638
|
+
hasDefault: true;
|
|
639
|
+
isPrimaryKey: false;
|
|
640
|
+
isAutoincrement: false;
|
|
641
|
+
hasRuntimeDefault: false;
|
|
642
|
+
enumValues: [string, ...string[]];
|
|
643
|
+
baseColumn: never;
|
|
644
|
+
identity: undefined;
|
|
645
|
+
generated: undefined;
|
|
646
|
+
}, {}, {
|
|
647
|
+
length: number | undefined;
|
|
648
|
+
}>;
|
|
649
|
+
};
|
|
650
|
+
dialect: "sqlite";
|
|
651
|
+
}>;
|
|
652
|
+
roleHasPermissions: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
653
|
+
name: string;
|
|
654
|
+
schema: undefined;
|
|
655
|
+
columns: {
|
|
656
|
+
roleId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
657
|
+
name: "role_id";
|
|
658
|
+
tableName: string;
|
|
659
|
+
dataType: "number";
|
|
660
|
+
columnType: "SQLiteInteger";
|
|
661
|
+
data: number;
|
|
662
|
+
driverParam: number;
|
|
663
|
+
notNull: true;
|
|
664
|
+
hasDefault: false;
|
|
665
|
+
isPrimaryKey: false;
|
|
666
|
+
isAutoincrement: false;
|
|
667
|
+
hasRuntimeDefault: false;
|
|
668
|
+
enumValues: undefined;
|
|
669
|
+
baseColumn: never;
|
|
670
|
+
identity: undefined;
|
|
671
|
+
generated: undefined;
|
|
672
|
+
}, {}, {}>;
|
|
673
|
+
permissionId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
674
|
+
name: "permission_id";
|
|
675
|
+
tableName: string;
|
|
676
|
+
dataType: "number";
|
|
677
|
+
columnType: "SQLiteInteger";
|
|
678
|
+
data: number;
|
|
679
|
+
driverParam: number;
|
|
680
|
+
notNull: true;
|
|
681
|
+
hasDefault: false;
|
|
682
|
+
isPrimaryKey: false;
|
|
683
|
+
isAutoincrement: false;
|
|
684
|
+
hasRuntimeDefault: false;
|
|
685
|
+
enumValues: undefined;
|
|
686
|
+
baseColumn: never;
|
|
687
|
+
identity: undefined;
|
|
688
|
+
generated: undefined;
|
|
689
|
+
}, {}, {}>;
|
|
690
|
+
};
|
|
691
|
+
dialect: "sqlite";
|
|
692
|
+
}>;
|
|
693
|
+
modelHasRoles: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
694
|
+
name: string;
|
|
695
|
+
schema: undefined;
|
|
696
|
+
columns: {
|
|
697
|
+
roleId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
698
|
+
name: "role_id";
|
|
699
|
+
tableName: string;
|
|
700
|
+
dataType: "number";
|
|
701
|
+
columnType: "SQLiteInteger";
|
|
702
|
+
data: number;
|
|
703
|
+
driverParam: number;
|
|
704
|
+
notNull: true;
|
|
705
|
+
hasDefault: false;
|
|
706
|
+
isPrimaryKey: false;
|
|
707
|
+
isAutoincrement: false;
|
|
708
|
+
hasRuntimeDefault: false;
|
|
709
|
+
enumValues: undefined;
|
|
710
|
+
baseColumn: never;
|
|
711
|
+
identity: undefined;
|
|
712
|
+
generated: undefined;
|
|
713
|
+
}, {}, {}>;
|
|
714
|
+
subjectType: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
715
|
+
name: "subject_type";
|
|
716
|
+
tableName: string;
|
|
717
|
+
dataType: "string";
|
|
718
|
+
columnType: "SQLiteText";
|
|
719
|
+
data: string;
|
|
720
|
+
driverParam: string;
|
|
721
|
+
notNull: true;
|
|
722
|
+
hasDefault: false;
|
|
723
|
+
isPrimaryKey: false;
|
|
724
|
+
isAutoincrement: false;
|
|
725
|
+
hasRuntimeDefault: false;
|
|
726
|
+
enumValues: [string, ...string[]];
|
|
727
|
+
baseColumn: never;
|
|
728
|
+
identity: undefined;
|
|
729
|
+
generated: undefined;
|
|
730
|
+
}, {}, {
|
|
731
|
+
length: number | undefined;
|
|
732
|
+
}>;
|
|
733
|
+
subjectId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
734
|
+
name: "subject_id";
|
|
735
|
+
tableName: string;
|
|
736
|
+
dataType: "string";
|
|
737
|
+
columnType: "SQLiteText";
|
|
738
|
+
data: string;
|
|
739
|
+
driverParam: string;
|
|
740
|
+
notNull: true;
|
|
741
|
+
hasDefault: false;
|
|
742
|
+
isPrimaryKey: false;
|
|
743
|
+
isAutoincrement: false;
|
|
744
|
+
hasRuntimeDefault: false;
|
|
745
|
+
enumValues: [string, ...string[]];
|
|
746
|
+
baseColumn: never;
|
|
747
|
+
identity: undefined;
|
|
748
|
+
generated: undefined;
|
|
749
|
+
}, {}, {
|
|
750
|
+
length: number | undefined;
|
|
751
|
+
}>;
|
|
752
|
+
teamId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
753
|
+
name: "team_id";
|
|
754
|
+
tableName: string;
|
|
755
|
+
dataType: "string";
|
|
756
|
+
columnType: "SQLiteText";
|
|
757
|
+
data: string;
|
|
758
|
+
driverParam: string;
|
|
759
|
+
notNull: true;
|
|
760
|
+
hasDefault: true;
|
|
761
|
+
isPrimaryKey: false;
|
|
762
|
+
isAutoincrement: false;
|
|
763
|
+
hasRuntimeDefault: false;
|
|
764
|
+
enumValues: [string, ...string[]];
|
|
765
|
+
baseColumn: never;
|
|
766
|
+
identity: undefined;
|
|
767
|
+
generated: undefined;
|
|
768
|
+
}, {}, {
|
|
769
|
+
length: number | undefined;
|
|
770
|
+
}>;
|
|
771
|
+
expiresAt: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
772
|
+
name: "expires_at";
|
|
773
|
+
tableName: string;
|
|
774
|
+
dataType: "date";
|
|
775
|
+
columnType: "SQLiteTimestamp";
|
|
776
|
+
data: Date;
|
|
777
|
+
driverParam: number;
|
|
778
|
+
notNull: false;
|
|
779
|
+
hasDefault: false;
|
|
780
|
+
isPrimaryKey: false;
|
|
781
|
+
isAutoincrement: false;
|
|
782
|
+
hasRuntimeDefault: false;
|
|
783
|
+
enumValues: undefined;
|
|
784
|
+
baseColumn: never;
|
|
785
|
+
identity: undefined;
|
|
786
|
+
generated: undefined;
|
|
787
|
+
}, {}, {}>;
|
|
788
|
+
};
|
|
789
|
+
dialect: "sqlite";
|
|
790
|
+
}>;
|
|
791
|
+
modelHasPermissions: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
792
|
+
name: string;
|
|
793
|
+
schema: undefined;
|
|
794
|
+
columns: {
|
|
795
|
+
permissionId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
796
|
+
name: "permission_id";
|
|
797
|
+
tableName: string;
|
|
798
|
+
dataType: "number";
|
|
799
|
+
columnType: "SQLiteInteger";
|
|
800
|
+
data: number;
|
|
801
|
+
driverParam: number;
|
|
802
|
+
notNull: true;
|
|
803
|
+
hasDefault: false;
|
|
804
|
+
isPrimaryKey: false;
|
|
805
|
+
isAutoincrement: false;
|
|
806
|
+
hasRuntimeDefault: false;
|
|
807
|
+
enumValues: undefined;
|
|
808
|
+
baseColumn: never;
|
|
809
|
+
identity: undefined;
|
|
810
|
+
generated: undefined;
|
|
811
|
+
}, {}, {}>;
|
|
812
|
+
subjectType: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
813
|
+
name: "subject_type";
|
|
814
|
+
tableName: string;
|
|
815
|
+
dataType: "string";
|
|
816
|
+
columnType: "SQLiteText";
|
|
817
|
+
data: string;
|
|
818
|
+
driverParam: string;
|
|
819
|
+
notNull: true;
|
|
820
|
+
hasDefault: false;
|
|
821
|
+
isPrimaryKey: false;
|
|
822
|
+
isAutoincrement: false;
|
|
823
|
+
hasRuntimeDefault: false;
|
|
824
|
+
enumValues: [string, ...string[]];
|
|
825
|
+
baseColumn: never;
|
|
826
|
+
identity: undefined;
|
|
827
|
+
generated: undefined;
|
|
828
|
+
}, {}, {
|
|
829
|
+
length: number | undefined;
|
|
830
|
+
}>;
|
|
831
|
+
subjectId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
832
|
+
name: "subject_id";
|
|
833
|
+
tableName: string;
|
|
834
|
+
dataType: "string";
|
|
835
|
+
columnType: "SQLiteText";
|
|
836
|
+
data: string;
|
|
837
|
+
driverParam: string;
|
|
838
|
+
notNull: true;
|
|
839
|
+
hasDefault: false;
|
|
840
|
+
isPrimaryKey: false;
|
|
841
|
+
isAutoincrement: false;
|
|
842
|
+
hasRuntimeDefault: false;
|
|
843
|
+
enumValues: [string, ...string[]];
|
|
844
|
+
baseColumn: never;
|
|
845
|
+
identity: undefined;
|
|
846
|
+
generated: undefined;
|
|
847
|
+
}, {}, {
|
|
848
|
+
length: number | undefined;
|
|
849
|
+
}>;
|
|
850
|
+
teamId: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
851
|
+
name: "team_id";
|
|
852
|
+
tableName: string;
|
|
853
|
+
dataType: "string";
|
|
854
|
+
columnType: "SQLiteText";
|
|
855
|
+
data: string;
|
|
856
|
+
driverParam: string;
|
|
857
|
+
notNull: true;
|
|
858
|
+
hasDefault: true;
|
|
859
|
+
isPrimaryKey: false;
|
|
860
|
+
isAutoincrement: false;
|
|
861
|
+
hasRuntimeDefault: false;
|
|
862
|
+
enumValues: [string, ...string[]];
|
|
863
|
+
baseColumn: never;
|
|
864
|
+
identity: undefined;
|
|
865
|
+
generated: undefined;
|
|
866
|
+
}, {}, {
|
|
867
|
+
length: number | undefined;
|
|
868
|
+
}>;
|
|
869
|
+
expiresAt: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
870
|
+
name: "expires_at";
|
|
871
|
+
tableName: string;
|
|
872
|
+
dataType: "date";
|
|
873
|
+
columnType: "SQLiteTimestamp";
|
|
874
|
+
data: Date;
|
|
875
|
+
driverParam: number;
|
|
876
|
+
notNull: false;
|
|
877
|
+
hasDefault: false;
|
|
878
|
+
isPrimaryKey: false;
|
|
879
|
+
isAutoincrement: false;
|
|
880
|
+
hasRuntimeDefault: false;
|
|
881
|
+
enumValues: undefined;
|
|
882
|
+
baseColumn: never;
|
|
883
|
+
identity: undefined;
|
|
884
|
+
generated: undefined;
|
|
885
|
+
}, {}, {}>;
|
|
886
|
+
};
|
|
887
|
+
dialect: "sqlite";
|
|
888
|
+
}>;
|
|
889
|
+
};
|
|
890
|
+
/** The tables of `sqliteRbacSchema()`. */
|
|
891
|
+
type SqliteRbacSchema = ReturnType<typeof buildSqlite>;
|
|
892
|
+
/** The tables of `sqliteRbacSchema({ expiry: true })`: the subject-link tables have an `expiresAt` column. */
|
|
893
|
+
type SqliteRbacExpirySchema = ReturnType<typeof buildSqliteExpiry>;
|
|
431
894
|
|
|
432
895
|
/**
|
|
433
896
|
* @anievo-id/rbac-evolution-drizzle/sqlite — SQLite schema + adapter.
|
|
@@ -439,7 +902,8 @@ type SqliteRbacSchema = ReturnType<typeof sqliteRbacSchema>;
|
|
|
439
902
|
*
|
|
440
903
|
* @param db any Drizzle SQLite database instance
|
|
441
904
|
* @param schema the tables from `sqliteRbacSchema()` (defaults to the unprefixed tables)
|
|
905
|
+
* @param options `{ expiry: true }` to store an expiry per link (needs `sqliteRbacSchema({ expiry: true })`)
|
|
442
906
|
*/
|
|
443
|
-
declare function drizzleSqliteAdapter(db: BaseSQLiteDatabase<'sync' | 'async', any, any, any>, schema?: SqliteRbacSchema): RbacAdapter;
|
|
907
|
+
declare function drizzleSqliteAdapter(db: BaseSQLiteDatabase<'sync' | 'async', any, any, any>, schema?: SqliteRbacSchema | SqliteRbacExpirySchema, options?: DrizzleAdapterOptions): RbacAdapter;
|
|
444
908
|
|
|
445
|
-
export { RbacSchemaOptions, type SqliteRbacSchema, drizzleSqliteAdapter, sqliteRbacSchema };
|
|
909
|
+
export { DrizzleAdapterOptions, RbacSchemaOptions, type SqliteRbacExpirySchema, type SqliteRbacSchema, drizzleSqliteAdapter, sqliteRbacSchema };
|
package/dist/sqlite.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { drizzleSqliteAdapter, sqliteRbacSchema } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
export { drizzleSqliteAdapter, sqliteRbacSchema } from './chunk-SPNXRYKH.js';
|
|
2
|
+
import './chunk-3AH2K6KS.js';
|
|
3
3
|
//# sourceMappingURL=sqlite.js.map
|
|
4
4
|
//# sourceMappingURL=sqlite.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anievo-id/rbac-evolution-drizzle",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Drizzle ORM storage adapter (PostgreSQL, SQLite & MySQL) for rbac-evolution.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "AniEvo-ID (https://github.com/AniEvo-ID)",
|
|
@@ -74,6 +74,9 @@
|
|
|
74
74
|
"./sql/pg.sql": "./sql/pg.sql",
|
|
75
75
|
"./sql/sqlite.sql": "./sql/sqlite.sql",
|
|
76
76
|
"./sql/mysql.sql": "./sql/mysql.sql",
|
|
77
|
+
"./sql/pg-expiry.sql": "./sql/pg-expiry.sql",
|
|
78
|
+
"./sql/sqlite-expiry.sql": "./sql/sqlite-expiry.sql",
|
|
79
|
+
"./sql/mysql-expiry.sql": "./sql/mysql-expiry.sql",
|
|
77
80
|
"./package.json": "./package.json"
|
|
78
81
|
},
|
|
79
82
|
"files": [
|
|
@@ -84,7 +87,7 @@
|
|
|
84
87
|
"access": "public"
|
|
85
88
|
},
|
|
86
89
|
"dependencies": {
|
|
87
|
-
"@anievo-id/rbac-evolution": "^1.
|
|
90
|
+
"@anievo-id/rbac-evolution": "^1.3.0"
|
|
88
91
|
},
|
|
89
92
|
"peerDependencies": {
|
|
90
93
|
"drizzle-orm": ">=0.38"
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- rbac-evolution 1.2: optional expiry on role assignments and direct permissions, for MySQL 8 / MariaDB
|
|
2
|
+
-- (matches `mysqlRbacSchema({ expiry: true })` from @anievo-id/rbac-evolution-drizzle).
|
|
3
|
+
-- Run it once on a database created with `mysql.sql` (MySQL has no ADD COLUMN IF NOT EXISTS: a second run
|
|
4
|
+
-- fails with "Duplicate column name", which is harmless), then create the adapter with
|
|
5
|
+
-- `drizzleMysqlAdapter(db, mysqlRbacSchema({ expiry: true }), { expiry: true })`.
|
|
6
|
+
-- Existing rows get NULL: they stay permanent. Using a table prefix? Prefix the table names below accordingly.
|
|
7
|
+
|
|
8
|
+
ALTER TABLE `model_has_roles` ADD COLUMN `expires_at` datetime(3) NULL;
|
|
9
|
+
ALTER TABLE `model_has_permissions` ADD COLUMN `expires_at` datetime(3) NULL;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- rbac-evolution 1.2: optional expiry on role assignments and direct permissions, for PostgreSQL
|
|
2
|
+
-- (matches `pgRbacSchema({ expiry: true })` from @anievo-id/rbac-evolution-drizzle).
|
|
3
|
+
-- Run it once on a database created with `pg.sql`, then create the adapter with
|
|
4
|
+
-- `drizzlePgAdapter(db, pgRbacSchema({ expiry: true }), { expiry: true })`.
|
|
5
|
+
-- Existing rows get NULL: they stay permanent. Using a table prefix? Prefix the table names below accordingly.
|
|
6
|
+
|
|
7
|
+
ALTER TABLE "model_has_roles" ADD COLUMN IF NOT EXISTS "expires_at" timestamp with time zone;
|
|
8
|
+
ALTER TABLE "model_has_permissions" ADD COLUMN IF NOT EXISTS "expires_at" timestamp with time zone;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- rbac-evolution 1.2: optional expiry on role assignments and direct permissions, for SQLite
|
|
2
|
+
-- (matches `sqliteRbacSchema({ expiry: true })` from @anievo-id/rbac-evolution-drizzle).
|
|
3
|
+
-- Run it once on a database created with `sqlite.sql` (a second run fails with "duplicate column name",
|
|
4
|
+
-- which is harmless), then create the adapter with
|
|
5
|
+
-- `drizzleSqliteAdapter(db, sqliteRbacSchema({ expiry: true }), { expiry: true })`.
|
|
6
|
+
-- `expires_at` holds unix milliseconds. Existing rows get NULL: they stay permanent.
|
|
7
|
+
-- Using a table prefix? Prefix the table names below accordingly.
|
|
8
|
+
|
|
9
|
+
ALTER TABLE "model_has_roles" ADD COLUMN "expires_at" integer;
|
|
10
|
+
ALTER TABLE "model_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EAAG,CAAA,CAAE,mBAAmB,CAAA,KAAA,CAAA;AAAA,QAC9B,OAAA,EAAS,CAAC,CAAA,CAAE,WAAA,EAAa,EAAE,SAAA,EAAW,CAAA,CAAE,MAAA,EAAQ,CAAA,CAAE,YAAY;AAAA,OAC/D,CAAA;AAAA,MACD,KAAA,CAAM,GAAG,CAAA,CAAE,mBAAmB,sBAAsB,CAAA,CAAE,EAAA,CAAG,EAAE,YAAY;AAAA;AACzE,GACF;AAEA,EAAA,OAAO,EAAE,WAAA,EAAa,KAAA,EAAO,kBAAA,EAAoB,eAAe,mBAAA,EAAoB;AACtF;;;ACvFO,SAAS,oBAAA,CAEd,EAAA,EACA,MAAA,GAA2B,gBAAA,EAAiB,EAC/B;AACb,EAAA,OAAO,IAAI,kBAAA,CAAmB,EAAA,EAAI,MAAA,EAAQ,QAAQ,CAAA;AACpD","file":"chunk-4KGIPA5W.js","sourcesContent":["import { sql } from 'drizzle-orm'\nimport { index, integer, primaryKey, sqliteTable, text, uniqueIndex } from 'drizzle-orm/sqlite-core'\nimport { type RbacSchemaOptions, tableNames } from './names'\n\n/**\n * spatie-style `created_at` / `updated_at` (only on `permissions` and `roles`), stored as unix seconds\n * and exposed as `Date` by Drizzle. `strftime('%s','now')` works on every SQLite version (unlike `unixepoch()`).\n */\nconst timestamps = () => ({\n createdAt: integer('created_at', { mode: 'timestamp' })\n .notNull()\n .default(sql`(cast(strftime('%s', 'now') as integer))`),\n updatedAt: integer('updated_at', { mode: 'timestamp' })\n .notNull()\n .default(sql`(cast(strftime('%s', 'now') as integer))`),\n})\n\n/**\n * Builds the rbac-evolution tables for SQLite — libsql / Turso, better-sqlite3, D1, bun:sqlite... (mirrors spatie/laravel-permission).\n *\n * ```ts\n * // schema.ts — export each table so drizzle-kit picks them up\n * export const { permissions, roles, roleHasPermissions, modelHasRoles, modelHasPermissions } = sqliteRbacSchema()\n * ```\n */\nexport function sqliteRbacSchema(options: RbacSchemaOptions = {}) {\n const n = tableNames(options)\n\n const permissions = sqliteTable(\n n.permissions,\n {\n id: integer('id').primaryKey({ autoIncrement: true }),\n name: text('name').notNull(),\n guardName: text('guard_name').notNull(),\n ...timestamps(),\n },\n (t) => [uniqueIndex(`${n.permissions}_name_guard_name_unique`).on(t.name, t.guardName)],\n )\n\n const roles = sqliteTable(\n n.roles,\n {\n id: integer('id').primaryKey({ autoIncrement: true }),\n name: text('name').notNull(),\n guardName: text('guard_name').notNull(),\n /** `''` = global role (no team). */\n teamId: text('team_id').notNull().default(''),\n ...timestamps(),\n },\n (t) => [uniqueIndex(`${n.roles}_name_guard_name_team_id_unique`).on(t.name, t.guardName, t.teamId)],\n )\n\n const roleHasPermissions = sqliteTable(\n n.roleHasPermissions,\n {\n roleId: integer('role_id')\n .notNull()\n .references(() => roles.id, { onDelete: 'cascade' }),\n permissionId: integer('permission_id')\n .notNull()\n .references(() => permissions.id, { onDelete: 'cascade' }),\n },\n (t) => [\n primaryKey({ name: `${n.roleHasPermissions}_pkey`, columns: [t.roleId, t.permissionId] }),\n index(`${n.roleHasPermissions}_permission_id_index`).on(t.permissionId),\n ],\n )\n\n const modelHasRoles = sqliteTable(\n n.modelHasRoles,\n {\n roleId: integer('role_id')\n .notNull()\n .references(() => roles.id, { onDelete: 'cascade' }),\n subjectType: text('subject_type').notNull(),\n subjectId: text('subject_id').notNull(),\n /** `''` = global (no team). */\n teamId: text('team_id').notNull().default(''),\n },\n (t) => [\n primaryKey({ name: `${n.modelHasRoles}_pkey`, columns: [t.subjectType, t.subjectId, t.teamId, t.roleId] }),\n index(`${n.modelHasRoles}_role_id_index`).on(t.roleId),\n ],\n )\n\n const modelHasPermissions = sqliteTable(\n n.modelHasPermissions,\n {\n permissionId: integer('permission_id')\n .notNull()\n .references(() => permissions.id, { onDelete: 'cascade' }),\n subjectType: text('subject_type').notNull(),\n subjectId: text('subject_id').notNull(),\n /** `''` = global (no team). */\n teamId: text('team_id').notNull().default(''),\n },\n (t) => [\n primaryKey({\n name: `${n.modelHasPermissions}_pkey`,\n columns: [t.subjectType, t.subjectId, t.teamId, t.permissionId],\n }),\n index(`${n.modelHasPermissions}_permission_id_index`).on(t.permissionId),\n ],\n )\n\n return { permissions, roles, roleHasPermissions, modelHasRoles, modelHasPermissions }\n}\n\nexport type SqliteRbacSchema = ReturnType<typeof sqliteRbacSchema>\n","/**\n * @anievo-id/rbac-evolution-drizzle/sqlite — SQLite schema + adapter.\n */\nimport type { RbacAdapter } from '@anievo-id/rbac-evolution'\nimport type { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core'\nimport { DrizzleRbacAdapter } from './adapter'\nimport { type SqliteRbacSchema, sqliteRbacSchema } from './sqlite-schema'\n\nexport { sqliteRbacSchema } from './sqlite-schema'\nexport type { SqliteRbacSchema } from './sqlite-schema'\nexport type { RbacSchemaOptions } from './names'\n\n/**\n * Creates an `RbacAdapter` backed by a Drizzle SQLite database\n * (libsql / Turso, better-sqlite3, Bun SQLite, Cloudflare D1, ...).\n *\n * @param db any Drizzle SQLite database instance\n * @param schema the tables from `sqliteRbacSchema()` (defaults to the unprefixed tables)\n */\nexport function drizzleSqliteAdapter(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n db: BaseSQLiteDatabase<'sync' | 'async', any, any, any>,\n schema: SqliteRbacSchema = sqliteRbacSchema(),\n): RbacAdapter {\n return new DrizzleRbacAdapter(db, schema, 'sqlite')\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/pg-schema.ts","../src/pg.ts"],"names":[],"mappings":";;;AAIA,IAAM,aAAa,OAAO;AAAA,EACxB,SAAA,EAAW,SAAA,CAAU,YAAA,EAAc,EAAE,YAAA,EAAc,MAAM,CAAA,CAAE,OAAA,EAAQ,CAAE,UAAA,EAAW;AAAA,EAChF,SAAA,EAAW,SAAA,CAAU,YAAA,EAAc,EAAE,YAAA,EAAc,MAAM,CAAA,CAAE,OAAA,EAAQ,CAAE,UAAA;AACvE,CAAA,CAAA;AAUO,SAAS,YAAA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ChD","file":"chunk-D6UKXFGV.js","sourcesContent":["import { index, integer, pgTable, primaryKey, serial, text, timestamp, uniqueIndex } from 'drizzle-orm/pg-core'\nimport { type RbacSchemaOptions, tableNames } from './names'\n\n/** spatie-style `created_at` / `updated_at` (only on `permissions` and `roles`). */\nconst timestamps = () => ({\n createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),\n updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),\n})\n\n/**\n * Builds the rbac-evolution tables for PostgreSQL (mirrors spatie/laravel-permission).\n *\n * ```ts\n * // schema.ts — export each table so drizzle-kit picks them up\n * export const { permissions, roles, roleHasPermissions, modelHasRoles, modelHasPermissions } = pgRbacSchema()\n * ```\n */\nexport function pgRbacSchema(options: RbacSchemaOptions = {}) {\n const n = tableNames(options)\n\n const permissions = pgTable(\n n.permissions,\n {\n id: serial('id').primaryKey(),\n name: text('name').notNull(),\n guardName: text('guard_name').notNull(),\n ...timestamps(),\n },\n (t) => [uniqueIndex(`${n.permissions}_name_guard_name_unique`).on(t.name, t.guardName)],\n )\n\n const roles = pgTable(\n n.roles,\n {\n id: serial('id').primaryKey(),\n name: text('name').notNull(),\n guardName: text('guard_name').notNull(),\n /** `''` = global role (no team). */\n teamId: text('team_id').notNull().default(''),\n ...timestamps(),\n },\n (t) => [uniqueIndex(`${n.roles}_name_guard_name_team_id_unique`).on(t.name, t.guardName, t.teamId)],\n )\n\n const roleHasPermissions = pgTable(\n n.roleHasPermissions,\n {\n roleId: integer('role_id')\n .notNull()\n .references(() => roles.id, { onDelete: 'cascade' }),\n permissionId: integer('permission_id')\n .notNull()\n .references(() => permissions.id, { onDelete: 'cascade' }),\n },\n (t) => [\n primaryKey({ name: `${n.roleHasPermissions}_pkey`, columns: [t.roleId, t.permissionId] }),\n index(`${n.roleHasPermissions}_permission_id_index`).on(t.permissionId),\n ],\n )\n\n const modelHasRoles = pgTable(\n n.modelHasRoles,\n {\n roleId: integer('role_id')\n .notNull()\n .references(() => roles.id, { onDelete: 'cascade' }),\n subjectType: text('subject_type').notNull(),\n subjectId: text('subject_id').notNull(),\n /** `''` = global (no team). */\n teamId: text('team_id').notNull().default(''),\n },\n (t) => [\n primaryKey({ name: `${n.modelHasRoles}_pkey`, columns: [t.subjectType, t.subjectId, t.teamId, t.roleId] }),\n index(`${n.modelHasRoles}_role_id_index`).on(t.roleId),\n ],\n )\n\n const modelHasPermissions = pgTable(\n n.modelHasPermissions,\n {\n permissionId: integer('permission_id')\n .notNull()\n .references(() => permissions.id, { onDelete: 'cascade' }),\n subjectType: text('subject_type').notNull(),\n subjectId: text('subject_id').notNull(),\n /** `''` = global (no team). */\n teamId: text('team_id').notNull().default(''),\n },\n (t) => [\n primaryKey({\n name: `${n.modelHasPermissions}_pkey`,\n columns: [t.subjectType, t.subjectId, t.teamId, t.permissionId],\n }),\n index(`${n.modelHasPermissions}_permission_id_index`).on(t.permissionId),\n ],\n )\n\n return { permissions, roles, roleHasPermissions, modelHasRoles, modelHasPermissions }\n}\n\nexport type PgRbacSchema = ReturnType<typeof pgRbacSchema>\n","/**\n * @anievo-id/rbac-evolution-drizzle/pg — PostgreSQL schema + adapter.\n */\nimport type { RbacAdapter } from '@anievo-id/rbac-evolution'\nimport type { PgDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core'\nimport { DrizzleRbacAdapter } from './adapter'\nimport { type PgRbacSchema, pgRbacSchema } from './pg-schema'\n\nexport { pgRbacSchema } from './pg-schema'\nexport type { PgRbacSchema } from './pg-schema'\nexport type { RbacSchemaOptions } from './names'\n\n/**\n * Creates an `RbacAdapter` backed by a Drizzle PostgreSQL database\n * (node-postgres, postgres.js, Neon, Vercel Postgres, PGlite, ...).\n *\n * @param db any Drizzle PostgreSQL database instance\n * @param schema the tables from `pgRbacSchema()` (defaults to the unprefixed tables)\n */\nexport function drizzlePgAdapter(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n db: PgDatabase<PgQueryResultHKT, any, any>,\n schema: PgRbacSchema = pgR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,EAAA,EAAI,MAAA,EAAQ,OAAO,CAAA;AACnD","file":"chunk-HDQ5ACTJ.js","sourcesContent":["import {\n customType,\n index,\n int,\n mysqlTable,\n primaryKey,\n timestamp,\n uniqueIndex,\n} from 'drizzle-orm/mysql-core'\nimport { type RbacSchemaOptions, tableNames } from './names'\n\n/**\n * Column lengths. MySQL cannot fully index `TEXT`, and InnoDB caps an index key at 3072 bytes\n * (768 `utf8mb4` characters), so every indexed string column is a bounded `varchar`:\n * - `roles` unique key: name (255) + guard_name (255) + team_id (191) = 701 chars\n * - `model_has_*` primary key: subject_type (191) + subject_id (191) + team_id (191) + int = 573 chars + 4 bytes\n */\nconst MYSQL_LENGTHS = {\n name: 255,\n guardName: 255,\n teamId: 191,\n subjectType: 191,\n subjectId: 191,\n} as const\n\n/**\n * `varchar(n)` with a binary collation, so names, subject ids and team ids compare exactly\n * (case- and accent-sensitive) like on PostgreSQL / SQLite, whatever the table's default collation is.\n * Without it, MySQL's default `utf8mb4_0900_ai_ci` would make `'abc'` and `'ABC'` the same subject id.\n */\nconst exactVarchar = customType<{ data: string; driverData: string; config: { length: number }; configRequired: true }>({\n dataType: (config) => `varchar(${config.length}) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin`,\n})\n\n/** spatie-style `created_at` / `updated_at` (only on `permissions` and `roles`). */\nconst timestamps = () => ({\n createdAt: timestamp('created_at', { mode: 'date' }).notNull().defaultNow(),\n updatedAt: timestamp('updated_at', { mode: 'date' }).notNull().defaultNow(),\n})\n\n/**\n * Builds the rbac-evolution tables for MySQL 8 / MariaDB (mirrors spatie/laravel-permission).\n *\n * ```ts\n * // schema.ts — export each table so drizzle-kit picks them up\n * export const { permissions, roles, roleHasPermissions, modelHasRoles, modelHasPermissions } = mysqlRbacSchema()\n * ```\n */\nexport function mysqlRbacSchema(options: RbacSchemaOptions = {}) {\n const n = tableNames(options)\n\n const permissions = mysqlTable(\n n.permissions,\n {\n id: int('id').autoincrement().primaryKey(),\n name: exactVarchar('name', { length: MYSQL_LENGTHS.name }).notNull(),\n guardName: exactVarchar('guard_name', { length: MYSQL_LENGTHS.guardName }).notNull(),\n ...timestamps(),\n },\n (t) => [uniqueIndex(`${n.permissions}_name_guard_name_unique`).on(t.name, t.guardName)],\n )\n\n const roles = mysqlTable(\n n.roles,\n {\n id: int('id').autoincrement().primaryKey(),\n name: exactVarchar('name', { length: MYSQL_LENGTHS.name }).notNull(),\n guardName: exactVarchar('guard_name', { length: MYSQL_LENGTHS.guardName }).notNull(),\n /** `''` = global role (no team). */\n teamId: exactVarchar('team_id', { length: MYSQL_LENGTHS.teamId }).notNull().default(''),\n ...timestamps(),\n },\n (t) => [uniqueIndex(`${n.roles}_name_guard_name_team_id_unique`).on(t.name, t.guardName, t.teamId)],\n )\n\n const roleHasPermissions = mysqlTable(\n n.roleHasPermissions,\n {\n roleId: int('role_id')\n .notNull()\n .references(() => roles.id, { onDelete: 'cascade' }),\n permissionId: int('permission_id')\n .notNull()\n .references(() => permissions.id, { onDelete: 'cascade' }),\n },\n (t) => [\n primaryKey({ name: `${n.roleHasPermissions}_pkey`, columns: [t.roleId, t.permissionId] }),\n index(`${n.roleHasPermissions}_permission_id_index`).on(t.permissionId),\n ],\n )\n\n const modelHasRoles = mysqlTable(\n n.modelHasRoles,\n {\n roleId: int('role_id')\n .notNull()\n .references(() => roles.id, { onDelete: 'cascade' }),\n subjectType: exactVarchar('subject_type', { length: MYSQL_LENGTHS.subjectType }).notNull(),\n subjectId: exactVarchar('subject_id', { length: MYSQL_LENGTHS.subjectId }).notNull(),\n /** `''` = global (no team). */\n teamId: exactVarchar('team_id', { length: MYSQL_LENGTHS.teamId }).notNull().default(''),\n },\n (t) => [\n primaryKey({ name: `${n.modelHasRoles}_pkey`, columns: [t.subjectType, t.subjectId, t.teamId, t.roleId] }),\n index(`${n.modelHasRoles}_role_id_index`).on(t.roleId),\n ],\n )\n\n const modelHasPermissions = mysqlTable(\n n.modelHasPermissions,\n {\n permissionId: int('permission_id')\n .notNull()\n .references(() => permissions.id, { onDelete: 'cascade' }),\n subjectType: exactVarchar('subject_type', { length: MYSQL_LENGTHS.subjectType }).notNull(),\n subjectId: exactVarchar('subject_id', { length: MYSQL_LENGTHS.subjectId }).notNull(),\n /** `''` = global (no team). */\n teamId: exactVarchar('team_id', { length: MYSQL_LENGTHS.teamId }).notNull().default(''),\n },\n (t) => [\n primaryKey({\n name: `${n.modelHasPermissions}_pkey`,\n columns: [t.subjectType, t.subjectId, t.teamId, t.permissionId],\n }),\n index(`${n.modelHasPermissions}_permission_id_index`).on(t.permissionId),\n ],\n )\n\n return { permissions, roles, roleHasPermissions, modelHasRoles, modelHasPermissions }\n}\n\nexport type MysqlRbacSchema = ReturnType<typeof mysqlRbacSchema>\n","/**\n * @anievo-id/rbac-evolution-drizzle/mysql — MySQL schema + adapter.\n */\nimport type { RbacAdapter } from '@anievo-id/rbac-evolution'\nimport type { MySqlDatabase } from 'drizzle-orm/mysql-core'\nimport { DrizzleRbacAdapter } from './adapter'\nimport { type MysqlRbacSchema, mysqlRbacSchema } from './mysql-schema'\n\nexport { mysqlRbacSchema } from './mysql-schema'\nexport type { MysqlRbacSchema } from './mysql-schema'\nexport type { RbacSchemaOptions } from './names'\n\n/**\n * Creates an `RbacAdapter` backed by a Drizzle MySQL database\n * (mysql2, PlanetScale, TiDB Serverless, ...).\n *\n * @param db any Drizzle MySQL database instance\n * @param schema the tables from `mysqlRbacSchema()` (defaults to the unprefixed tables)\n */\nexport function drizzleMysqlAdapter(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n db: MySqlDatabase<any, any, any, any>,\n schema: MysqlRbacSchema = mysqlRbacSchema(),\n): RbacAdapter {\n return new DrizzleRbacAdapter(db, schema, 'mysql')\n}\n"]}
|