@headless-lms/adapter-db 0.3.0 → 0.4.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 (73) hide show
  1. package/dist/index.d.ts +6 -1
  2. package/dist/index.js +6 -1
  3. package/dist/repositories/admin.js +1 -1
  4. package/dist/repositories/assets.d.ts +1 -2
  5. package/dist/repositories/assets.js +0 -4
  6. package/dist/repositories/assets.js.map +1 -1
  7. package/dist/repositories/automations.d.ts +0 -1
  8. package/dist/repositories/automations.js +1 -17
  9. package/dist/repositories/automations.js.map +1 -1
  10. package/dist/repositories/chats.d.ts +4 -4
  11. package/dist/repositories/chats.js +33 -18
  12. package/dist/repositories/chats.js.map +1 -1
  13. package/dist/repositories/content.d.ts +3 -3
  14. package/dist/repositories/content.js +35 -12
  15. package/dist/repositories/content.js.map +1 -1
  16. package/dist/repositories/devices.d.ts +17 -0
  17. package/dist/repositories/devices.js +75 -0
  18. package/dist/repositories/devices.js.map +1 -0
  19. package/dist/repositories/digest-runs.d.ts +14 -0
  20. package/dist/repositories/digest-runs.js +39 -0
  21. package/dist/repositories/digest-runs.js.map +1 -0
  22. package/dist/repositories/discussion.d.ts +6 -1
  23. package/dist/repositories/discussion.js +9 -4
  24. package/dist/repositories/discussion.js.map +1 -1
  25. package/dist/repositories/entitlements.d.ts +3 -1
  26. package/dist/repositories/entitlements.js +12 -6
  27. package/dist/repositories/entitlements.js.map +1 -1
  28. package/dist/repositories/inserted-row.d.ts +5 -0
  29. package/dist/repositories/inserted-row.js +7 -0
  30. package/dist/repositories/inserted-row.js.map +1 -0
  31. package/dist/repositories/mentions.d.ts +17 -0
  32. package/dist/repositories/mentions.js +55 -0
  33. package/dist/repositories/mentions.js.map +1 -0
  34. package/dist/repositories/notification-settings.d.ts +19 -0
  35. package/dist/repositories/notification-settings.js +67 -0
  36. package/dist/repositories/notification-settings.js.map +1 -0
  37. package/dist/repositories/notifications.d.ts +23 -16
  38. package/dist/repositories/notifications.js +152 -44
  39. package/dist/repositories/notifications.js.map +1 -1
  40. package/dist/repositories/organizations.d.ts +1 -0
  41. package/dist/repositories/organizations.js +4 -1
  42. package/dist/repositories/organizations.js.map +1 -1
  43. package/dist/repositories/posts.d.ts +4 -8
  44. package/dist/repositories/posts.js +25 -28
  45. package/dist/repositories/posts.js.map +1 -1
  46. package/dist/repositories/subscriptions.d.ts +18 -0
  47. package/dist/repositories/subscriptions.js +72 -0
  48. package/dist/repositories/subscriptions.js.map +1 -0
  49. package/dist/schema/automations.d.ts +524 -19
  50. package/dist/schema/automations.js +73 -7
  51. package/dist/schema/automations.js.map +1 -1
  52. package/dist/schema/discussion.d.ts +277 -127
  53. package/dist/schema/discussion.js +59 -24
  54. package/dist/schema/discussion.js.map +1 -1
  55. package/dist/schema/identity.d.ts +109 -109
  56. package/dist/schema/identity.js +28 -70
  57. package/dist/schema/identity.js.map +1 -1
  58. package/dist/schema/index.d.ts +5 -5
  59. package/dist/schema/index.js +10 -6
  60. package/drizzle/0011_digest_runs.sql +8 -0
  61. package/drizzle/0012_subscriptions.sql +16 -0
  62. package/drizzle/0013_mentions.sql +10 -0
  63. package/drizzle/0014_notification_settings_devices.sql +36 -0
  64. package/drizzle/0015_automations_drop_source.sql +2 -0
  65. package/drizzle/0016_notifications_automations.sql +48 -0
  66. package/drizzle/meta/0011_snapshot.json +8868 -0
  67. package/drizzle/meta/0012_snapshot.json +8873 -0
  68. package/drizzle/meta/0013_snapshot.json +8943 -0
  69. package/drizzle/meta/0014_snapshot.json +9305 -0
  70. package/drizzle/meta/0015_snapshot.json +9270 -0
  71. package/drizzle/meta/0016_snapshot.json +9230 -0
  72. package/drizzle/meta/_journal.json +42 -0
  73. package/package.json +2 -2
@@ -1,4 +1,5 @@
1
- import { DomainEvent } from "@headless-lms/core/shared/ports";
1
+ import { DomainEvent, JsonValue } from "@headless-lms/core/shared/ports";
2
+ import { Reason } from "@headless-lms/core/types";
2
3
  //#region src/schema/automations.d.ts
3
4
  declare const automations: import("drizzle-orm/pg-core").PgTableWithColumns<{
4
5
  name: "automations";
@@ -193,23 +194,6 @@ declare const automations: import("drizzle-orm/pg-core").PgTableWithColumns<{
193
194
  }, {}, {
194
195
  $type: Record<string, import("@headless-lms/core/types").JsonValue> | null;
195
196
  }>;
196
- source: import("drizzle-orm/pg-core").PgColumn<{
197
- name: "source";
198
- tableName: "automations";
199
- dataType: "string";
200
- columnType: "PgText";
201
- data: "user" | "system";
202
- driverParam: string;
203
- notNull: true;
204
- hasDefault: true;
205
- isPrimaryKey: false;
206
- isAutoincrement: false;
207
- hasRuntimeDefault: false;
208
- enumValues: ["system", "user"];
209
- baseColumn: never;
210
- identity: undefined;
211
- generated: undefined;
212
- }, {}, {}>;
213
197
  createdAt: import("drizzle-orm/pg-core").PgColumn<{
214
198
  name: "created_at";
215
199
  tableName: "automations";
@@ -474,6 +458,527 @@ declare const automationRuns: import("drizzle-orm/pg-core").PgTableWithColumns<{
474
458
  };
475
459
  dialect: "pg";
476
460
  }>;
461
+ declare const notifications: import("drizzle-orm/pg-core").PgTableWithColumns<{
462
+ name: "notifications";
463
+ schema: undefined;
464
+ columns: {
465
+ orgId: import("drizzle-orm/pg-core").PgColumn<{
466
+ name: "org_id";
467
+ tableName: "notifications";
468
+ dataType: "string";
469
+ columnType: "PgText";
470
+ data: string;
471
+ driverParam: string;
472
+ notNull: true;
473
+ hasDefault: false;
474
+ isPrimaryKey: false;
475
+ isAutoincrement: false;
476
+ hasRuntimeDefault: false;
477
+ enumValues: [string, ...string[]];
478
+ baseColumn: never;
479
+ identity: undefined;
480
+ generated: undefined;
481
+ }, {}, {}>;
482
+ id: import("drizzle-orm/pg-core").PgColumn<{
483
+ name: "id";
484
+ tableName: "notifications";
485
+ dataType: "string";
486
+ columnType: "PgText";
487
+ data: string;
488
+ driverParam: string;
489
+ notNull: true;
490
+ hasDefault: true;
491
+ isPrimaryKey: false;
492
+ isAutoincrement: false;
493
+ hasRuntimeDefault: true;
494
+ enumValues: [string, ...string[]];
495
+ baseColumn: never;
496
+ identity: undefined;
497
+ generated: undefined;
498
+ }, {}, {}>;
499
+ userId: import("drizzle-orm/pg-core").PgColumn<{
500
+ name: "user_id";
501
+ tableName: "notifications";
502
+ dataType: "string";
503
+ columnType: "PgText";
504
+ data: string;
505
+ driverParam: string;
506
+ notNull: true;
507
+ hasDefault: false;
508
+ isPrimaryKey: false;
509
+ isAutoincrement: false;
510
+ hasRuntimeDefault: false;
511
+ enumValues: [string, ...string[]];
512
+ baseColumn: never;
513
+ identity: undefined;
514
+ generated: undefined;
515
+ }, {}, {}>;
516
+ sourceEventId: import("drizzle-orm/pg-core").PgColumn<{
517
+ name: "source_event_id";
518
+ tableName: "notifications";
519
+ dataType: "string";
520
+ columnType: "PgText";
521
+ data: string;
522
+ driverParam: string;
523
+ notNull: false;
524
+ hasDefault: false;
525
+ isPrimaryKey: false;
526
+ isAutoincrement: false;
527
+ hasRuntimeDefault: false;
528
+ enumValues: [string, ...string[]];
529
+ baseColumn: never;
530
+ identity: undefined;
531
+ generated: undefined;
532
+ }, {}, {}>;
533
+ type: import("drizzle-orm/pg-core").PgColumn<{
534
+ name: "type";
535
+ tableName: "notifications";
536
+ dataType: "string";
537
+ columnType: "PgText";
538
+ data: string;
539
+ driverParam: string;
540
+ notNull: true;
541
+ hasDefault: false;
542
+ isPrimaryKey: false;
543
+ isAutoincrement: false;
544
+ hasRuntimeDefault: false;
545
+ enumValues: [string, ...string[]];
546
+ baseColumn: never;
547
+ identity: undefined;
548
+ generated: undefined;
549
+ }, {}, {}>;
550
+ scope: import("drizzle-orm/pg-core").PgColumn<{
551
+ name: "scope";
552
+ tableName: "notifications";
553
+ dataType: "string";
554
+ columnType: "PgText";
555
+ data: "community" | "space" | "chat" | "org";
556
+ driverParam: string;
557
+ notNull: true;
558
+ hasDefault: false;
559
+ isPrimaryKey: false;
560
+ isAutoincrement: false;
561
+ hasRuntimeDefault: false;
562
+ enumValues: ["org", "community", "space", "chat"];
563
+ baseColumn: never;
564
+ identity: undefined;
565
+ generated: undefined;
566
+ }, {}, {}>;
567
+ reasons: import("drizzle-orm/pg-core").PgColumn<{
568
+ name: "reasons";
569
+ tableName: "notifications";
570
+ dataType: "array";
571
+ columnType: "PgArray";
572
+ data: Reason[];
573
+ driverParam: string | string[];
574
+ notNull: true;
575
+ hasDefault: false;
576
+ isPrimaryKey: false;
577
+ isAutoincrement: false;
578
+ hasRuntimeDefault: false;
579
+ enumValues: [string, ...string[]];
580
+ baseColumn: import("drizzle-orm").Column<{
581
+ name: "reasons";
582
+ tableName: "notifications";
583
+ dataType: "string";
584
+ columnType: "PgText";
585
+ data: string;
586
+ driverParam: string;
587
+ notNull: false;
588
+ hasDefault: false;
589
+ isPrimaryKey: false;
590
+ isAutoincrement: false;
591
+ hasRuntimeDefault: false;
592
+ enumValues: [string, ...string[]];
593
+ baseColumn: never;
594
+ identity: undefined;
595
+ generated: undefined;
596
+ }, {}, {}>;
597
+ identity: undefined;
598
+ generated: undefined;
599
+ }, {}, {
600
+ $type: Reason[];
601
+ size: undefined;
602
+ baseBuilder: import("drizzle-orm/pg-core").PgColumnBuilder<{
603
+ name: "reasons";
604
+ dataType: "string";
605
+ columnType: "PgText";
606
+ data: string;
607
+ enumValues: [string, ...string[]];
608
+ driverParam: string;
609
+ }, {}, {}, import("drizzle-orm").ColumnBuilderExtraConfig>;
610
+ }>;
611
+ matchedReason: import("drizzle-orm/pg-core").PgColumn<{
612
+ name: "matched_reason";
613
+ tableName: "notifications";
614
+ dataType: "string";
615
+ columnType: "PgText";
616
+ data: Reason;
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
+ $type: Reason;
629
+ }>;
630
+ category: import("drizzle-orm/pg-core").PgColumn<{
631
+ name: "category";
632
+ tableName: "notifications";
633
+ dataType: "string";
634
+ columnType: "PgText";
635
+ data: string;
636
+ driverParam: string;
637
+ notNull: true;
638
+ hasDefault: false;
639
+ isPrimaryKey: false;
640
+ isAutoincrement: false;
641
+ hasRuntimeDefault: false;
642
+ enumValues: [string, ...string[]];
643
+ baseColumn: never;
644
+ identity: undefined;
645
+ generated: undefined;
646
+ }, {}, {}>;
647
+ communityId: import("drizzle-orm/pg-core").PgColumn<{
648
+ name: "community_id";
649
+ tableName: "notifications";
650
+ dataType: "string";
651
+ columnType: "PgText";
652
+ data: string;
653
+ driverParam: string;
654
+ notNull: false;
655
+ hasDefault: false;
656
+ isPrimaryKey: false;
657
+ isAutoincrement: false;
658
+ hasRuntimeDefault: false;
659
+ enumValues: [string, ...string[]];
660
+ baseColumn: never;
661
+ identity: undefined;
662
+ generated: undefined;
663
+ }, {}, {}>;
664
+ spaceId: import("drizzle-orm/pg-core").PgColumn<{
665
+ name: "space_id";
666
+ tableName: "notifications";
667
+ dataType: "string";
668
+ columnType: "PgText";
669
+ data: string;
670
+ driverParam: string;
671
+ notNull: false;
672
+ hasDefault: false;
673
+ isPrimaryKey: false;
674
+ isAutoincrement: false;
675
+ hasRuntimeDefault: false;
676
+ enumValues: [string, ...string[]];
677
+ baseColumn: never;
678
+ identity: undefined;
679
+ generated: undefined;
680
+ }, {}, {}>;
681
+ actorOrgUserId: import("drizzle-orm/pg-core").PgColumn<{
682
+ name: "actor_org_user_id";
683
+ tableName: "notifications";
684
+ dataType: "string";
685
+ columnType: "PgText";
686
+ data: string;
687
+ driverParam: string;
688
+ notNull: false;
689
+ hasDefault: false;
690
+ isPrimaryKey: false;
691
+ isAutoincrement: false;
692
+ hasRuntimeDefault: false;
693
+ enumValues: [string, ...string[]];
694
+ baseColumn: never;
695
+ identity: undefined;
696
+ generated: undefined;
697
+ }, {}, {}>;
698
+ subjectType: import("drizzle-orm/pg-core").PgColumn<{
699
+ name: "subject_type";
700
+ tableName: "notifications";
701
+ dataType: "string";
702
+ columnType: "PgText";
703
+ data: string;
704
+ driverParam: string;
705
+ notNull: false;
706
+ hasDefault: false;
707
+ isPrimaryKey: false;
708
+ isAutoincrement: false;
709
+ hasRuntimeDefault: false;
710
+ enumValues: [string, ...string[]];
711
+ baseColumn: never;
712
+ identity: undefined;
713
+ generated: undefined;
714
+ }, {}, {}>;
715
+ subjectId: import("drizzle-orm/pg-core").PgColumn<{
716
+ name: "subject_id";
717
+ tableName: "notifications";
718
+ dataType: "string";
719
+ columnType: "PgText";
720
+ data: string;
721
+ driverParam: string;
722
+ notNull: false;
723
+ hasDefault: false;
724
+ isPrimaryKey: false;
725
+ isAutoincrement: false;
726
+ hasRuntimeDefault: false;
727
+ enumValues: [string, ...string[]];
728
+ baseColumn: never;
729
+ identity: undefined;
730
+ generated: undefined;
731
+ }, {}, {}>;
732
+ parentType: import("drizzle-orm/pg-core").PgColumn<{
733
+ name: "parent_type";
734
+ tableName: "notifications";
735
+ dataType: "string";
736
+ columnType: "PgText";
737
+ data: string;
738
+ driverParam: string;
739
+ notNull: false;
740
+ hasDefault: false;
741
+ isPrimaryKey: false;
742
+ isAutoincrement: false;
743
+ hasRuntimeDefault: false;
744
+ enumValues: [string, ...string[]];
745
+ baseColumn: never;
746
+ identity: undefined;
747
+ generated: undefined;
748
+ }, {}, {}>;
749
+ parentId: import("drizzle-orm/pg-core").PgColumn<{
750
+ name: "parent_id";
751
+ tableName: "notifications";
752
+ dataType: "string";
753
+ columnType: "PgText";
754
+ data: string;
755
+ driverParam: string;
756
+ notNull: false;
757
+ hasDefault: false;
758
+ isPrimaryKey: false;
759
+ isAutoincrement: false;
760
+ hasRuntimeDefault: false;
761
+ enumValues: [string, ...string[]];
762
+ baseColumn: never;
763
+ identity: undefined;
764
+ generated: undefined;
765
+ }, {}, {}>;
766
+ display: import("drizzle-orm/pg-core").PgColumn<{
767
+ name: "display";
768
+ tableName: "notifications";
769
+ dataType: "json";
770
+ columnType: "PgJsonb";
771
+ data: Record<string, JsonValue>;
772
+ driverParam: unknown;
773
+ notNull: true;
774
+ hasDefault: false;
775
+ isPrimaryKey: false;
776
+ isAutoincrement: false;
777
+ hasRuntimeDefault: false;
778
+ enumValues: undefined;
779
+ baseColumn: never;
780
+ identity: undefined;
781
+ generated: undefined;
782
+ }, {}, {
783
+ $type: Record<string, JsonValue>;
784
+ }>;
785
+ inApp: import("drizzle-orm/pg-core").PgColumn<{
786
+ name: "in_app";
787
+ tableName: "notifications";
788
+ dataType: "boolean";
789
+ columnType: "PgBoolean";
790
+ data: boolean;
791
+ driverParam: boolean;
792
+ notNull: true;
793
+ hasDefault: false;
794
+ isPrimaryKey: false;
795
+ isAutoincrement: false;
796
+ hasRuntimeDefault: false;
797
+ enumValues: undefined;
798
+ baseColumn: never;
799
+ identity: undefined;
800
+ generated: undefined;
801
+ }, {}, {}>;
802
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
803
+ name: "created_at";
804
+ tableName: "notifications";
805
+ dataType: "date";
806
+ columnType: "PgTimestamp";
807
+ data: Date;
808
+ driverParam: string;
809
+ notNull: true;
810
+ hasDefault: true;
811
+ isPrimaryKey: false;
812
+ isAutoincrement: false;
813
+ hasRuntimeDefault: false;
814
+ enumValues: undefined;
815
+ baseColumn: never;
816
+ identity: undefined;
817
+ generated: undefined;
818
+ }, {}, {}>;
819
+ readAt: import("drizzle-orm/pg-core").PgColumn<{
820
+ name: "read_at";
821
+ tableName: "notifications";
822
+ dataType: "date";
823
+ columnType: "PgTimestamp";
824
+ data: Date;
825
+ driverParam: string;
826
+ notNull: false;
827
+ hasDefault: false;
828
+ isPrimaryKey: false;
829
+ isAutoincrement: false;
830
+ hasRuntimeDefault: false;
831
+ enumValues: undefined;
832
+ baseColumn: never;
833
+ identity: undefined;
834
+ generated: undefined;
835
+ }, {}, {}>;
836
+ };
837
+ dialect: "pg";
838
+ }>;
839
+ declare const notificationDeliveries: import("drizzle-orm/pg-core").PgTableWithColumns<{
840
+ name: "notification_deliveries";
841
+ schema: undefined;
842
+ columns: {
843
+ orgId: import("drizzle-orm/pg-core").PgColumn<{
844
+ name: "org_id";
845
+ tableName: "notification_deliveries";
846
+ dataType: "string";
847
+ columnType: "PgText";
848
+ data: string;
849
+ driverParam: string;
850
+ notNull: true;
851
+ hasDefault: false;
852
+ isPrimaryKey: false;
853
+ isAutoincrement: false;
854
+ hasRuntimeDefault: false;
855
+ enumValues: [string, ...string[]];
856
+ baseColumn: never;
857
+ identity: undefined;
858
+ generated: undefined;
859
+ }, {}, {}>;
860
+ id: import("drizzle-orm/pg-core").PgColumn<{
861
+ name: "id";
862
+ tableName: "notification_deliveries";
863
+ dataType: "string";
864
+ columnType: "PgText";
865
+ data: string;
866
+ driverParam: string;
867
+ notNull: true;
868
+ hasDefault: true;
869
+ isPrimaryKey: false;
870
+ isAutoincrement: false;
871
+ hasRuntimeDefault: true;
872
+ enumValues: [string, ...string[]];
873
+ baseColumn: never;
874
+ identity: undefined;
875
+ generated: undefined;
876
+ }, {}, {}>;
877
+ notificationId: import("drizzle-orm/pg-core").PgColumn<{
878
+ name: "notification_id";
879
+ tableName: "notification_deliveries";
880
+ dataType: "string";
881
+ columnType: "PgText";
882
+ data: string;
883
+ driverParam: string;
884
+ notNull: true;
885
+ hasDefault: false;
886
+ isPrimaryKey: false;
887
+ isAutoincrement: false;
888
+ hasRuntimeDefault: false;
889
+ enumValues: [string, ...string[]];
890
+ baseColumn: never;
891
+ identity: undefined;
892
+ generated: undefined;
893
+ }, {}, {}>;
894
+ channel: import("drizzle-orm/pg-core").PgColumn<{
895
+ name: "channel";
896
+ tableName: "notification_deliveries";
897
+ dataType: "string";
898
+ columnType: "PgText";
899
+ data: string;
900
+ driverParam: string;
901
+ notNull: true;
902
+ hasDefault: false;
903
+ isPrimaryKey: false;
904
+ isAutoincrement: false;
905
+ hasRuntimeDefault: false;
906
+ enumValues: [string, ...string[]];
907
+ baseColumn: never;
908
+ identity: undefined;
909
+ generated: undefined;
910
+ }, {}, {}>;
911
+ status: import("drizzle-orm/pg-core").PgColumn<{
912
+ name: "status";
913
+ tableName: "notification_deliveries";
914
+ dataType: "string";
915
+ columnType: "PgText";
916
+ data: "pending" | "failed" | "sent";
917
+ driverParam: string;
918
+ notNull: true;
919
+ hasDefault: true;
920
+ isPrimaryKey: false;
921
+ isAutoincrement: false;
922
+ hasRuntimeDefault: false;
923
+ enumValues: ["pending", "sent", "failed"];
924
+ baseColumn: never;
925
+ identity: undefined;
926
+ generated: undefined;
927
+ }, {}, {}>;
928
+ lastError: import("drizzle-orm/pg-core").PgColumn<{
929
+ name: "last_error";
930
+ tableName: "notification_deliveries";
931
+ dataType: "string";
932
+ columnType: "PgText";
933
+ data: string;
934
+ driverParam: string;
935
+ notNull: false;
936
+ hasDefault: false;
937
+ isPrimaryKey: false;
938
+ isAutoincrement: false;
939
+ hasRuntimeDefault: false;
940
+ enumValues: [string, ...string[]];
941
+ baseColumn: never;
942
+ identity: undefined;
943
+ generated: undefined;
944
+ }, {}, {}>;
945
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
946
+ name: "created_at";
947
+ tableName: "notification_deliveries";
948
+ dataType: "date";
949
+ columnType: "PgTimestamp";
950
+ data: Date;
951
+ driverParam: string;
952
+ notNull: true;
953
+ hasDefault: true;
954
+ isPrimaryKey: false;
955
+ isAutoincrement: false;
956
+ hasRuntimeDefault: false;
957
+ enumValues: undefined;
958
+ baseColumn: never;
959
+ identity: undefined;
960
+ generated: undefined;
961
+ }, {}, {}>;
962
+ sentAt: import("drizzle-orm/pg-core").PgColumn<{
963
+ name: "sent_at";
964
+ tableName: "notification_deliveries";
965
+ dataType: "date";
966
+ columnType: "PgTimestamp";
967
+ data: Date;
968
+ driverParam: string;
969
+ notNull: false;
970
+ hasDefault: false;
971
+ isPrimaryKey: false;
972
+ isAutoincrement: false;
973
+ hasRuntimeDefault: false;
974
+ enumValues: undefined;
975
+ baseColumn: never;
976
+ identity: undefined;
977
+ generated: undefined;
978
+ }, {}, {}>;
979
+ };
980
+ dialect: "pg";
981
+ }>;
477
982
  //#endregion
478
- export { automationRuns, automations };
983
+ export { automationRuns, automations, notificationDeliveries, notifications };
479
984
  //# sourceMappingURL=automations.d.ts.map
@@ -1,6 +1,7 @@
1
- import { organizations } from "./organizations.js";
2
- import { sql } from "drizzle-orm";
3
- import { boolean, index, jsonb, pgTable, primaryKey, text, timestamp, uniqueIndex } from "drizzle-orm/pg-core";
1
+ import { communities, spaces } from "./content.js";
2
+ import { orgUsers, organizations } from "./organizations.js";
3
+ import { desc, sql } from "drizzle-orm";
4
+ import { boolean, foreignKey, index, jsonb, pgTable, primaryKey, text, timestamp, uniqueIndex } from "drizzle-orm/pg-core";
4
5
  import { genId } from "@headless-lms/core/shared/id";
5
6
  //#region src/schema/automations.ts
6
7
  const automations = pgTable("automations", {
@@ -13,13 +14,11 @@ const automations = pgTable("automations", {
13
14
  actions: jsonb("actions").$type().notNull(),
14
15
  enabled: boolean("enabled").notNull().default(true),
15
16
  filter: jsonb("filter").$type(),
16
- source: text("source", { enum: ["system", "user"] }).notNull().default("user"),
17
17
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
18
18
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
19
19
  }, (t) => ({
20
20
  pk: primaryKey({ columns: [t.orgId, t.id] }),
21
- triggersIdx: index("automations_triggers_idx").using("gin", t.triggers),
22
- systemSeedIdx: uniqueIndex("automations_system_seed_idx").on(t.orgId, t.name, sql`coalesce(${t.filter}->>'communityId', '')`).where(sql`${t.source} = 'system'`)
21
+ triggersIdx: index("automations_triggers_idx").using("gin", t.triggers)
23
22
  }));
24
23
  const automationRuns = pgTable("automation_runs", {
25
24
  orgId: text("org_id").notNull().references(() => organizations.id),
@@ -43,7 +42,74 @@ const automationRuns = pgTable("automation_runs", {
43
42
  automationIdx: index("automation_runs_org_automation_idx").on(t.orgId, t.automationId),
44
43
  eventDedupeIdx: uniqueIndex("automation_runs_org_automation_event_idx").on(t.orgId, t.automationId, t.eventId)
45
44
  }));
45
+ const notifications = pgTable("notifications", {
46
+ orgId: text("org_id").notNull(),
47
+ id: text("id").notNull().$defaultFn(() => genId("notification")),
48
+ userId: text("user_id").notNull(),
49
+ sourceEventId: text("source_event_id"),
50
+ type: text("type").notNull(),
51
+ scope: text("scope", { enum: [
52
+ "org",
53
+ "community",
54
+ "space",
55
+ "chat"
56
+ ] }).notNull(),
57
+ reasons: text("reasons").array().$type().notNull(),
58
+ matchedReason: text("matched_reason").$type().notNull(),
59
+ category: text("category").notNull(),
60
+ communityId: text("community_id"),
61
+ spaceId: text("space_id"),
62
+ actorOrgUserId: text("actor_org_user_id"),
63
+ subjectType: text("subject_type"),
64
+ subjectId: text("subject_id"),
65
+ parentType: text("parent_type"),
66
+ parentId: text("parent_id"),
67
+ display: jsonb("display").$type().notNull(),
68
+ inApp: boolean("in_app").notNull(),
69
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
70
+ readAt: timestamp("read_at", { withTimezone: true })
71
+ }, (t) => ({
72
+ pk: primaryKey({ columns: [t.orgId, t.id] }),
73
+ userFk: foreignKey({
74
+ columns: [t.orgId, t.userId],
75
+ foreignColumns: [orgUsers.orgId, orgUsers.userId]
76
+ }).onDelete("cascade"),
77
+ communityFk: foreignKey({
78
+ columns: [t.orgId, t.communityId],
79
+ foreignColumns: [communities.orgId, communities.id]
80
+ }).onDelete("cascade"),
81
+ spaceFk: foreignKey({
82
+ columns: [t.orgId, t.spaceId],
83
+ foreignColumns: [spaces.orgId, spaces.id]
84
+ }).onDelete("cascade"),
85
+ sourceIdx: uniqueIndex("notifications_source_event_idx").on(t.orgId, t.sourceEventId, t.userId, sql`coalesce(${t.communityId}, '')`).where(sql`${t.sourceEventId} is not null`),
86
+ listIdx: index("notifications_list_idx").on(t.orgId, t.userId, desc(t.createdAt), desc(t.id)).where(sql`${t.inApp}`),
87
+ communityIdx: index("notifications_community_idx").on(t.orgId, t.userId, t.communityId),
88
+ categoryIdx: index("notifications_category_idx").on(t.orgId, t.userId, t.category),
89
+ reasonsIdx: index("notifications_reasons_idx").using("gin", t.reasons)
90
+ }));
91
+ const notificationDeliveries = pgTable("notification_deliveries", {
92
+ orgId: text("org_id").notNull(),
93
+ id: text("id").notNull().$defaultFn(() => genId("notificationDelivery")),
94
+ notificationId: text("notification_id").notNull(),
95
+ channel: text("channel").notNull(),
96
+ status: text("status", { enum: [
97
+ "pending",
98
+ "sent",
99
+ "failed"
100
+ ] }).notNull().default("pending"),
101
+ lastError: text("last_error"),
102
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
103
+ sentAt: timestamp("sent_at", { withTimezone: true })
104
+ }, (t) => ({
105
+ pk: primaryKey({ columns: [t.orgId, t.id] }),
106
+ notificationFk: foreignKey({
107
+ columns: [t.orgId, t.notificationId],
108
+ foreignColumns: [notifications.orgId, notifications.id]
109
+ }).onDelete("cascade"),
110
+ channelIdx: uniqueIndex("notification_deliveries_channel_idx").on(t.orgId, t.notificationId, t.channel)
111
+ }));
46
112
  //#endregion
47
- export { automationRuns, automations };
113
+ export { automationRuns, automations, notificationDeliveries, notifications };
48
114
 
49
115
  //# sourceMappingURL=automations.js.map