@remit/drizzle-pg-schema 0.0.33 → 0.0.35
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/schema.d.ts +261 -363
- package/dist/schema.js +23 -30
- package/dist/types.d.ts +55 -1
- package/dist/types.js +132 -6
- package/package.json +1 -4
- package/schema.ts +29 -40
- package/types.ts +142 -6
package/dist/schema.d.ts
CHANGED
|
@@ -601,6 +601,168 @@ export declare const quarantines: import("drizzle-orm/pg-core").PgTableWithColum
|
|
|
601
601
|
};
|
|
602
602
|
dialect: "pg";
|
|
603
603
|
}>;
|
|
604
|
+
export declare const syncWarnings: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
605
|
+
name: "sync_warning";
|
|
606
|
+
schema: undefined;
|
|
607
|
+
columns: {
|
|
608
|
+
syncWarningId: import("drizzle-orm/pg-core").PgColumn<{
|
|
609
|
+
name: "sync_warning_id";
|
|
610
|
+
tableName: "sync_warning";
|
|
611
|
+
dataType: "string";
|
|
612
|
+
columnType: "PgText";
|
|
613
|
+
data: string;
|
|
614
|
+
driverParam: string;
|
|
615
|
+
notNull: true;
|
|
616
|
+
hasDefault: true;
|
|
617
|
+
isPrimaryKey: true;
|
|
618
|
+
isAutoincrement: false;
|
|
619
|
+
hasRuntimeDefault: true;
|
|
620
|
+
enumValues: [string, ...string[]];
|
|
621
|
+
baseColumn: never;
|
|
622
|
+
identity: undefined;
|
|
623
|
+
generated: undefined;
|
|
624
|
+
}, {}, {}>;
|
|
625
|
+
accountConfigId: import("drizzle-orm/pg-core").PgColumn<{
|
|
626
|
+
name: "account_config_id";
|
|
627
|
+
tableName: "sync_warning";
|
|
628
|
+
dataType: "string";
|
|
629
|
+
columnType: "PgText";
|
|
630
|
+
data: string;
|
|
631
|
+
driverParam: string;
|
|
632
|
+
notNull: true;
|
|
633
|
+
hasDefault: false;
|
|
634
|
+
isPrimaryKey: false;
|
|
635
|
+
isAutoincrement: false;
|
|
636
|
+
hasRuntimeDefault: false;
|
|
637
|
+
enumValues: [string, ...string[]];
|
|
638
|
+
baseColumn: never;
|
|
639
|
+
identity: undefined;
|
|
640
|
+
generated: undefined;
|
|
641
|
+
}, {}, {}>;
|
|
642
|
+
accountId: import("drizzle-orm/pg-core").PgColumn<{
|
|
643
|
+
name: "account_id";
|
|
644
|
+
tableName: "sync_warning";
|
|
645
|
+
dataType: "string";
|
|
646
|
+
columnType: "PgText";
|
|
647
|
+
data: string;
|
|
648
|
+
driverParam: string;
|
|
649
|
+
notNull: true;
|
|
650
|
+
hasDefault: false;
|
|
651
|
+
isPrimaryKey: false;
|
|
652
|
+
isAutoincrement: false;
|
|
653
|
+
hasRuntimeDefault: false;
|
|
654
|
+
enumValues: [string, ...string[]];
|
|
655
|
+
baseColumn: never;
|
|
656
|
+
identity: undefined;
|
|
657
|
+
generated: undefined;
|
|
658
|
+
}, {}, {}>;
|
|
659
|
+
mailboxId: import("drizzle-orm/pg-core").PgColumn<{
|
|
660
|
+
name: "mailbox_id";
|
|
661
|
+
tableName: "sync_warning";
|
|
662
|
+
dataType: "string";
|
|
663
|
+
columnType: "PgText";
|
|
664
|
+
data: string;
|
|
665
|
+
driverParam: string;
|
|
666
|
+
notNull: true;
|
|
667
|
+
hasDefault: false;
|
|
668
|
+
isPrimaryKey: false;
|
|
669
|
+
isAutoincrement: false;
|
|
670
|
+
hasRuntimeDefault: false;
|
|
671
|
+
enumValues: [string, ...string[]];
|
|
672
|
+
baseColumn: never;
|
|
673
|
+
identity: undefined;
|
|
674
|
+
generated: undefined;
|
|
675
|
+
}, {}, {}>;
|
|
676
|
+
uidValidity: import("drizzle-orm/pg-core").PgColumn<{
|
|
677
|
+
name: "uid_validity";
|
|
678
|
+
tableName: "sync_warning";
|
|
679
|
+
dataType: "number";
|
|
680
|
+
columnType: "PgBigInt53";
|
|
681
|
+
data: number;
|
|
682
|
+
driverParam: string | number;
|
|
683
|
+
notNull: true;
|
|
684
|
+
hasDefault: false;
|
|
685
|
+
isPrimaryKey: false;
|
|
686
|
+
isAutoincrement: false;
|
|
687
|
+
hasRuntimeDefault: false;
|
|
688
|
+
enumValues: undefined;
|
|
689
|
+
baseColumn: never;
|
|
690
|
+
identity: undefined;
|
|
691
|
+
generated: undefined;
|
|
692
|
+
}, {}, {}>;
|
|
693
|
+
uid: import("drizzle-orm/pg-core").PgColumn<{
|
|
694
|
+
name: "uid";
|
|
695
|
+
tableName: "sync_warning";
|
|
696
|
+
dataType: "number";
|
|
697
|
+
columnType: "PgBigInt53";
|
|
698
|
+
data: number;
|
|
699
|
+
driverParam: string | number;
|
|
700
|
+
notNull: true;
|
|
701
|
+
hasDefault: false;
|
|
702
|
+
isPrimaryKey: false;
|
|
703
|
+
isAutoincrement: false;
|
|
704
|
+
hasRuntimeDefault: false;
|
|
705
|
+
enumValues: undefined;
|
|
706
|
+
baseColumn: never;
|
|
707
|
+
identity: undefined;
|
|
708
|
+
generated: undefined;
|
|
709
|
+
}, {}, {}>;
|
|
710
|
+
stage: import("drizzle-orm/pg-core").PgColumn<{
|
|
711
|
+
name: "stage";
|
|
712
|
+
tableName: "sync_warning";
|
|
713
|
+
dataType: "string";
|
|
714
|
+
columnType: "PgText";
|
|
715
|
+
data: "Header" | "Body";
|
|
716
|
+
driverParam: string;
|
|
717
|
+
notNull: true;
|
|
718
|
+
hasDefault: false;
|
|
719
|
+
isPrimaryKey: false;
|
|
720
|
+
isAutoincrement: false;
|
|
721
|
+
hasRuntimeDefault: false;
|
|
722
|
+
enumValues: [string, ...string[]];
|
|
723
|
+
baseColumn: never;
|
|
724
|
+
identity: undefined;
|
|
725
|
+
generated: undefined;
|
|
726
|
+
}, {}, {
|
|
727
|
+
$type: "Header" | "Body";
|
|
728
|
+
}>;
|
|
729
|
+
attempts: import("drizzle-orm/pg-core").PgColumn<{
|
|
730
|
+
name: "attempts";
|
|
731
|
+
tableName: "sync_warning";
|
|
732
|
+
dataType: "number";
|
|
733
|
+
columnType: "PgInteger";
|
|
734
|
+
data: number;
|
|
735
|
+
driverParam: string | number;
|
|
736
|
+
notNull: true;
|
|
737
|
+
hasDefault: false;
|
|
738
|
+
isPrimaryKey: false;
|
|
739
|
+
isAutoincrement: false;
|
|
740
|
+
hasRuntimeDefault: false;
|
|
741
|
+
enumValues: undefined;
|
|
742
|
+
baseColumn: never;
|
|
743
|
+
identity: undefined;
|
|
744
|
+
generated: undefined;
|
|
745
|
+
}, {}, {}>;
|
|
746
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
747
|
+
name: "created_at";
|
|
748
|
+
tableName: "sync_warning";
|
|
749
|
+
dataType: "number";
|
|
750
|
+
columnType: "PgBigInt53";
|
|
751
|
+
data: number;
|
|
752
|
+
driverParam: string | number;
|
|
753
|
+
notNull: true;
|
|
754
|
+
hasDefault: false;
|
|
755
|
+
isPrimaryKey: false;
|
|
756
|
+
isAutoincrement: false;
|
|
757
|
+
hasRuntimeDefault: false;
|
|
758
|
+
enumValues: undefined;
|
|
759
|
+
baseColumn: never;
|
|
760
|
+
identity: undefined;
|
|
761
|
+
generated: undefined;
|
|
762
|
+
}, {}, {}>;
|
|
763
|
+
};
|
|
764
|
+
dialect: "pg";
|
|
765
|
+
}>;
|
|
604
766
|
export declare const accountConfigs: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
605
767
|
name: "account_config";
|
|
606
768
|
schema: undefined;
|
|
@@ -1921,23 +2083,6 @@ export declare const filters: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
|
1921
2083
|
}, {}, {
|
|
1922
2084
|
$type: "None" | "UserDisabled" | "AwaitingFolder" | "FolderCreateFailed" | "FolderMissing";
|
|
1923
2085
|
}>;
|
|
1924
|
-
hasAnchor: import("drizzle-orm/pg-core").PgColumn<{
|
|
1925
|
-
name: "has_anchor";
|
|
1926
|
-
tableName: "filter";
|
|
1927
|
-
dataType: "boolean";
|
|
1928
|
-
columnType: "PgBoolean";
|
|
1929
|
-
data: boolean;
|
|
1930
|
-
driverParam: boolean;
|
|
1931
|
-
notNull: true;
|
|
1932
|
-
hasDefault: true;
|
|
1933
|
-
isPrimaryKey: false;
|
|
1934
|
-
isAutoincrement: false;
|
|
1935
|
-
hasRuntimeDefault: false;
|
|
1936
|
-
enumValues: undefined;
|
|
1937
|
-
baseColumn: never;
|
|
1938
|
-
identity: undefined;
|
|
1939
|
-
generated: undefined;
|
|
1940
|
-
}, {}, {}>;
|
|
1941
2086
|
ruleChangedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
1942
2087
|
name: "rule_changed_at";
|
|
1943
2088
|
tableName: "filter";
|
|
@@ -1999,7 +2144,7 @@ export declare const filters: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
|
1999
2144
|
data: unknown;
|
|
2000
2145
|
driverParam: unknown;
|
|
2001
2146
|
notNull: true;
|
|
2002
|
-
hasDefault:
|
|
2147
|
+
hasDefault: false;
|
|
2003
2148
|
isPrimaryKey: false;
|
|
2004
2149
|
isAutoincrement: false;
|
|
2005
2150
|
hasRuntimeDefault: false;
|
|
@@ -2298,23 +2443,6 @@ export declare const organizeJobRequests: import("drizzle-orm/pg-core").PgTableW
|
|
|
2298
2443
|
identity: undefined;
|
|
2299
2444
|
generated: undefined;
|
|
2300
2445
|
}, {}, {}>;
|
|
2301
|
-
anchorMessageId: import("drizzle-orm/pg-core").PgColumn<{
|
|
2302
|
-
name: "anchor_message_id";
|
|
2303
|
-
tableName: "organize_job_request";
|
|
2304
|
-
dataType: "string";
|
|
2305
|
-
columnType: "PgText";
|
|
2306
|
-
data: string;
|
|
2307
|
-
driverParam: string;
|
|
2308
|
-
notNull: true;
|
|
2309
|
-
hasDefault: true;
|
|
2310
|
-
isPrimaryKey: false;
|
|
2311
|
-
isAutoincrement: false;
|
|
2312
|
-
hasRuntimeDefault: false;
|
|
2313
|
-
enumValues: [string, ...string[]];
|
|
2314
|
-
baseColumn: never;
|
|
2315
|
-
identity: undefined;
|
|
2316
|
-
generated: undefined;
|
|
2317
|
-
}, {}, {}>;
|
|
2318
2446
|
matchOperator: import("drizzle-orm/pg-core").PgColumn<{
|
|
2319
2447
|
name: "match_operator";
|
|
2320
2448
|
tableName: "organize_job_request";
|
|
@@ -2351,23 +2479,6 @@ export declare const organizeJobRequests: import("drizzle-orm/pg-core").PgTableW
|
|
|
2351
2479
|
identity: undefined;
|
|
2352
2480
|
generated: undefined;
|
|
2353
2481
|
}, {}, {}>;
|
|
2354
|
-
similarityThreshold: import("drizzle-orm/pg-core").PgColumn<{
|
|
2355
|
-
name: "similarity_threshold";
|
|
2356
|
-
tableName: "organize_job_request";
|
|
2357
|
-
dataType: "number";
|
|
2358
|
-
columnType: "PgDoublePrecision";
|
|
2359
|
-
data: number;
|
|
2360
|
-
driverParam: string | number;
|
|
2361
|
-
notNull: true;
|
|
2362
|
-
hasDefault: true;
|
|
2363
|
-
isPrimaryKey: false;
|
|
2364
|
-
isAutoincrement: false;
|
|
2365
|
-
hasRuntimeDefault: false;
|
|
2366
|
-
enumValues: undefined;
|
|
2367
|
-
baseColumn: never;
|
|
2368
|
-
identity: undefined;
|
|
2369
|
-
generated: undefined;
|
|
2370
|
-
}, {}, {}>;
|
|
2371
2482
|
actionLabelId: import("drizzle-orm/pg-core").PgColumn<{
|
|
2372
2483
|
name: "action_label_id";
|
|
2373
2484
|
tableName: "organize_job_request";
|
|
@@ -4494,7 +4605,7 @@ export declare const addresses: import("drizzle-orm/pg-core").PgTableWithColumns
|
|
|
4494
4605
|
};
|
|
4495
4606
|
dialect: "pg";
|
|
4496
4607
|
}>;
|
|
4497
|
-
export declare const
|
|
4608
|
+
export declare const messageRecords: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
4498
4609
|
name: "message";
|
|
4499
4610
|
schema: undefined;
|
|
4500
4611
|
columns: {
|
|
@@ -4600,25 +4711,6 @@ export declare const messages: import("drizzle-orm/pg-core").PgTableWithColumns<
|
|
|
4600
4711
|
identity: undefined;
|
|
4601
4712
|
generated: undefined;
|
|
4602
4713
|
}, {}, {}>;
|
|
4603
|
-
messageIdHeader: import("drizzle-orm/pg-core").PgColumn<{
|
|
4604
|
-
name: "message_id_header";
|
|
4605
|
-
tableName: "message";
|
|
4606
|
-
dataType: "custom";
|
|
4607
|
-
columnType: "PgCustomColumn";
|
|
4608
|
-
data: string;
|
|
4609
|
-
driverParam: string;
|
|
4610
|
-
notNull: false;
|
|
4611
|
-
hasDefault: false;
|
|
4612
|
-
isPrimaryKey: false;
|
|
4613
|
-
isAutoincrement: false;
|
|
4614
|
-
hasRuntimeDefault: false;
|
|
4615
|
-
enumValues: undefined;
|
|
4616
|
-
baseColumn: never;
|
|
4617
|
-
identity: undefined;
|
|
4618
|
-
generated: undefined;
|
|
4619
|
-
}, {}, {
|
|
4620
|
-
pgColumnBuilderBrand: "PgCustomColumnBuilderBrand";
|
|
4621
|
-
}>;
|
|
4622
4714
|
envelopeId: import("drizzle-orm/pg-core").PgColumn<{
|
|
4623
4715
|
name: "envelope_id";
|
|
4624
4716
|
tableName: "message";
|
|
@@ -5746,6 +5838,23 @@ export declare const calendarSuggestions: import("drizzle-orm/pg-core").PgTableW
|
|
|
5746
5838
|
identity: undefined;
|
|
5747
5839
|
generated: undefined;
|
|
5748
5840
|
}, {}, {}>;
|
|
5841
|
+
endsAtUtc: import("drizzle-orm/pg-core").PgColumn<{
|
|
5842
|
+
name: "ends_at_utc";
|
|
5843
|
+
tableName: "calendar_suggestion";
|
|
5844
|
+
dataType: "string";
|
|
5845
|
+
columnType: "PgText";
|
|
5846
|
+
data: string;
|
|
5847
|
+
driverParam: string;
|
|
5848
|
+
notNull: true;
|
|
5849
|
+
hasDefault: false;
|
|
5850
|
+
isPrimaryKey: false;
|
|
5851
|
+
isAutoincrement: false;
|
|
5852
|
+
hasRuntimeDefault: false;
|
|
5853
|
+
enumValues: [string, ...string[]];
|
|
5854
|
+
baseColumn: never;
|
|
5855
|
+
identity: undefined;
|
|
5856
|
+
generated: undefined;
|
|
5857
|
+
}, {}, {}>;
|
|
5749
5858
|
allDay: import("drizzle-orm/pg-core").PgColumn<{
|
|
5750
5859
|
name: "all_day";
|
|
5751
5860
|
tableName: "calendar_suggestion";
|
|
@@ -7511,13 +7620,13 @@ export declare const bodyPartParameters: import("drizzle-orm/pg-core").PgTableWi
|
|
|
7511
7620
|
};
|
|
7512
7621
|
dialect: "pg";
|
|
7513
7622
|
}>;
|
|
7514
|
-
export declare const
|
|
7515
|
-
name: "
|
|
7623
|
+
export declare const bodyStructureRefetches: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
7624
|
+
name: "body_structure_refetch";
|
|
7516
7625
|
schema: undefined;
|
|
7517
7626
|
columns: {
|
|
7518
|
-
|
|
7519
|
-
name: "
|
|
7520
|
-
tableName: "
|
|
7627
|
+
messageId: import("drizzle-orm/pg-core").PgColumn<{
|
|
7628
|
+
name: "message_id";
|
|
7629
|
+
tableName: "body_structure_refetch";
|
|
7521
7630
|
dataType: "string";
|
|
7522
7631
|
columnType: "PgText";
|
|
7523
7632
|
data: string;
|
|
@@ -7532,32 +7641,90 @@ export declare const rawMessageStorages: import("drizzle-orm/pg-core").PgTableWi
|
|
|
7532
7641
|
identity: undefined;
|
|
7533
7642
|
generated: undefined;
|
|
7534
7643
|
}, {}, {}>;
|
|
7535
|
-
|
|
7536
|
-
name: "
|
|
7537
|
-
tableName: "
|
|
7538
|
-
dataType: "
|
|
7539
|
-
columnType: "
|
|
7540
|
-
data:
|
|
7541
|
-
driverParam: string;
|
|
7644
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
7645
|
+
name: "created_at";
|
|
7646
|
+
tableName: "body_structure_refetch";
|
|
7647
|
+
dataType: "number";
|
|
7648
|
+
columnType: "PgBigInt53";
|
|
7649
|
+
data: number;
|
|
7650
|
+
driverParam: string | number;
|
|
7542
7651
|
notNull: true;
|
|
7543
7652
|
hasDefault: false;
|
|
7544
7653
|
isPrimaryKey: false;
|
|
7545
7654
|
isAutoincrement: false;
|
|
7546
7655
|
hasRuntimeDefault: false;
|
|
7547
|
-
enumValues:
|
|
7656
|
+
enumValues: undefined;
|
|
7548
7657
|
baseColumn: never;
|
|
7549
7658
|
identity: undefined;
|
|
7550
7659
|
generated: undefined;
|
|
7551
7660
|
}, {}, {}>;
|
|
7552
|
-
|
|
7553
|
-
name: "
|
|
7554
|
-
tableName: "
|
|
7555
|
-
dataType: "
|
|
7556
|
-
columnType: "
|
|
7557
|
-
data:
|
|
7558
|
-
driverParam: string;
|
|
7559
|
-
notNull: true;
|
|
7560
|
-
hasDefault: false;
|
|
7661
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
7662
|
+
name: "updated_at";
|
|
7663
|
+
tableName: "body_structure_refetch";
|
|
7664
|
+
dataType: "number";
|
|
7665
|
+
columnType: "PgBigInt53";
|
|
7666
|
+
data: number;
|
|
7667
|
+
driverParam: string | number;
|
|
7668
|
+
notNull: true;
|
|
7669
|
+
hasDefault: false;
|
|
7670
|
+
isPrimaryKey: false;
|
|
7671
|
+
isAutoincrement: false;
|
|
7672
|
+
hasRuntimeDefault: false;
|
|
7673
|
+
enumValues: undefined;
|
|
7674
|
+
baseColumn: never;
|
|
7675
|
+
identity: undefined;
|
|
7676
|
+
generated: undefined;
|
|
7677
|
+
}, {}, {}>;
|
|
7678
|
+
};
|
|
7679
|
+
dialect: "pg";
|
|
7680
|
+
}>;
|
|
7681
|
+
export declare const rawMessageStorages: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
7682
|
+
name: "raw_message_storage";
|
|
7683
|
+
schema: undefined;
|
|
7684
|
+
columns: {
|
|
7685
|
+
rawStorageId: import("drizzle-orm/pg-core").PgColumn<{
|
|
7686
|
+
name: "raw_storage_id";
|
|
7687
|
+
tableName: "raw_message_storage";
|
|
7688
|
+
dataType: "string";
|
|
7689
|
+
columnType: "PgText";
|
|
7690
|
+
data: string;
|
|
7691
|
+
driverParam: string;
|
|
7692
|
+
notNull: true;
|
|
7693
|
+
hasDefault: true;
|
|
7694
|
+
isPrimaryKey: true;
|
|
7695
|
+
isAutoincrement: false;
|
|
7696
|
+
hasRuntimeDefault: true;
|
|
7697
|
+
enumValues: [string, ...string[]];
|
|
7698
|
+
baseColumn: never;
|
|
7699
|
+
identity: undefined;
|
|
7700
|
+
generated: undefined;
|
|
7701
|
+
}, {}, {}>;
|
|
7702
|
+
messageId: import("drizzle-orm/pg-core").PgColumn<{
|
|
7703
|
+
name: "message_id";
|
|
7704
|
+
tableName: "raw_message_storage";
|
|
7705
|
+
dataType: "string";
|
|
7706
|
+
columnType: "PgText";
|
|
7707
|
+
data: string;
|
|
7708
|
+
driverParam: string;
|
|
7709
|
+
notNull: true;
|
|
7710
|
+
hasDefault: false;
|
|
7711
|
+
isPrimaryKey: false;
|
|
7712
|
+
isAutoincrement: false;
|
|
7713
|
+
hasRuntimeDefault: false;
|
|
7714
|
+
enumValues: [string, ...string[]];
|
|
7715
|
+
baseColumn: never;
|
|
7716
|
+
identity: undefined;
|
|
7717
|
+
generated: undefined;
|
|
7718
|
+
}, {}, {}>;
|
|
7719
|
+
storageType: import("drizzle-orm/pg-core").PgColumn<{
|
|
7720
|
+
name: "storage_type";
|
|
7721
|
+
tableName: "raw_message_storage";
|
|
7722
|
+
dataType: "string";
|
|
7723
|
+
columnType: "PgText";
|
|
7724
|
+
data: "inline" | "s3" | "filesystem" | "database";
|
|
7725
|
+
driverParam: string;
|
|
7726
|
+
notNull: true;
|
|
7727
|
+
hasDefault: false;
|
|
7561
7728
|
isPrimaryKey: false;
|
|
7562
7729
|
isAutoincrement: false;
|
|
7563
7730
|
hasRuntimeDefault: false;
|
|
@@ -7979,132 +8146,6 @@ export declare const bodyPartStorages: import("drizzle-orm/pg-core").PgTableWith
|
|
|
7979
8146
|
};
|
|
7980
8147
|
dialect: "pg";
|
|
7981
8148
|
}>;
|
|
7982
|
-
export declare const bodyPartContents: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
7983
|
-
name: "body_part_content";
|
|
7984
|
-
schema: undefined;
|
|
7985
|
-
columns: {
|
|
7986
|
-
bodyPartContentId: import("drizzle-orm/pg-core").PgColumn<{
|
|
7987
|
-
name: "body_part_content_id";
|
|
7988
|
-
tableName: "body_part_content";
|
|
7989
|
-
dataType: "string";
|
|
7990
|
-
columnType: "PgText";
|
|
7991
|
-
data: string;
|
|
7992
|
-
driverParam: string;
|
|
7993
|
-
notNull: true;
|
|
7994
|
-
hasDefault: true;
|
|
7995
|
-
isPrimaryKey: true;
|
|
7996
|
-
isAutoincrement: false;
|
|
7997
|
-
hasRuntimeDefault: true;
|
|
7998
|
-
enumValues: [string, ...string[]];
|
|
7999
|
-
baseColumn: never;
|
|
8000
|
-
identity: undefined;
|
|
8001
|
-
generated: undefined;
|
|
8002
|
-
}, {}, {}>;
|
|
8003
|
-
messageId: import("drizzle-orm/pg-core").PgColumn<{
|
|
8004
|
-
name: "message_id";
|
|
8005
|
-
tableName: "body_part_content";
|
|
8006
|
-
dataType: "string";
|
|
8007
|
-
columnType: "PgText";
|
|
8008
|
-
data: string;
|
|
8009
|
-
driverParam: string;
|
|
8010
|
-
notNull: true;
|
|
8011
|
-
hasDefault: false;
|
|
8012
|
-
isPrimaryKey: false;
|
|
8013
|
-
isAutoincrement: false;
|
|
8014
|
-
hasRuntimeDefault: false;
|
|
8015
|
-
enumValues: [string, ...string[]];
|
|
8016
|
-
baseColumn: never;
|
|
8017
|
-
identity: undefined;
|
|
8018
|
-
generated: undefined;
|
|
8019
|
-
}, {}, {}>;
|
|
8020
|
-
bodyPartId: import("drizzle-orm/pg-core").PgColumn<{
|
|
8021
|
-
name: "body_part_id";
|
|
8022
|
-
tableName: "body_part_content";
|
|
8023
|
-
dataType: "string";
|
|
8024
|
-
columnType: "PgText";
|
|
8025
|
-
data: string;
|
|
8026
|
-
driverParam: string;
|
|
8027
|
-
notNull: true;
|
|
8028
|
-
hasDefault: false;
|
|
8029
|
-
isPrimaryKey: false;
|
|
8030
|
-
isAutoincrement: false;
|
|
8031
|
-
hasRuntimeDefault: false;
|
|
8032
|
-
enumValues: [string, ...string[]];
|
|
8033
|
-
baseColumn: never;
|
|
8034
|
-
identity: undefined;
|
|
8035
|
-
generated: undefined;
|
|
8036
|
-
}, {}, {}>;
|
|
8037
|
-
content: import("drizzle-orm/pg-core").PgColumn<{
|
|
8038
|
-
name: "content";
|
|
8039
|
-
tableName: "body_part_content";
|
|
8040
|
-
dataType: "string";
|
|
8041
|
-
columnType: "PgText";
|
|
8042
|
-
data: string;
|
|
8043
|
-
driverParam: string;
|
|
8044
|
-
notNull: true;
|
|
8045
|
-
hasDefault: false;
|
|
8046
|
-
isPrimaryKey: false;
|
|
8047
|
-
isAutoincrement: false;
|
|
8048
|
-
hasRuntimeDefault: false;
|
|
8049
|
-
enumValues: [string, ...string[]];
|
|
8050
|
-
baseColumn: never;
|
|
8051
|
-
identity: undefined;
|
|
8052
|
-
generated: undefined;
|
|
8053
|
-
}, {}, {}>;
|
|
8054
|
-
contentLength: import("drizzle-orm/pg-core").PgColumn<{
|
|
8055
|
-
name: "content_length";
|
|
8056
|
-
tableName: "body_part_content";
|
|
8057
|
-
dataType: "number";
|
|
8058
|
-
columnType: "PgBigInt53";
|
|
8059
|
-
data: number;
|
|
8060
|
-
driverParam: string | number;
|
|
8061
|
-
notNull: true;
|
|
8062
|
-
hasDefault: false;
|
|
8063
|
-
isPrimaryKey: false;
|
|
8064
|
-
isAutoincrement: false;
|
|
8065
|
-
hasRuntimeDefault: false;
|
|
8066
|
-
enumValues: undefined;
|
|
8067
|
-
baseColumn: never;
|
|
8068
|
-
identity: undefined;
|
|
8069
|
-
generated: undefined;
|
|
8070
|
-
}, {}, {}>;
|
|
8071
|
-
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
8072
|
-
name: "created_at";
|
|
8073
|
-
tableName: "body_part_content";
|
|
8074
|
-
dataType: "number";
|
|
8075
|
-
columnType: "PgBigInt53";
|
|
8076
|
-
data: number;
|
|
8077
|
-
driverParam: string | number;
|
|
8078
|
-
notNull: true;
|
|
8079
|
-
hasDefault: false;
|
|
8080
|
-
isPrimaryKey: false;
|
|
8081
|
-
isAutoincrement: false;
|
|
8082
|
-
hasRuntimeDefault: false;
|
|
8083
|
-
enumValues: undefined;
|
|
8084
|
-
baseColumn: never;
|
|
8085
|
-
identity: undefined;
|
|
8086
|
-
generated: undefined;
|
|
8087
|
-
}, {}, {}>;
|
|
8088
|
-
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
8089
|
-
name: "updated_at";
|
|
8090
|
-
tableName: "body_part_content";
|
|
8091
|
-
dataType: "number";
|
|
8092
|
-
columnType: "PgBigInt53";
|
|
8093
|
-
data: number;
|
|
8094
|
-
driverParam: string | number;
|
|
8095
|
-
notNull: true;
|
|
8096
|
-
hasDefault: false;
|
|
8097
|
-
isPrimaryKey: false;
|
|
8098
|
-
isAutoincrement: false;
|
|
8099
|
-
hasRuntimeDefault: false;
|
|
8100
|
-
enumValues: undefined;
|
|
8101
|
-
baseColumn: never;
|
|
8102
|
-
identity: undefined;
|
|
8103
|
-
generated: undefined;
|
|
8104
|
-
}, {}, {}>;
|
|
8105
|
-
};
|
|
8106
|
-
dialect: "pg";
|
|
8107
|
-
}>;
|
|
8108
8149
|
export declare const calendarEventIndexes: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
8109
8150
|
name: "calendar_event_index";
|
|
8110
8151
|
schema: undefined;
|
|
@@ -8557,146 +8598,3 @@ export declare const messageLabels: import("drizzle-orm/pg-core").PgTableWithCol
|
|
|
8557
8598
|
};
|
|
8558
8599
|
dialect: "pg";
|
|
8559
8600
|
}>;
|
|
8560
|
-
export declare const filterAnchors: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
8561
|
-
name: "filter_anchor";
|
|
8562
|
-
schema: undefined;
|
|
8563
|
-
columns: {
|
|
8564
|
-
accountConfigId: import("drizzle-orm/pg-core").PgColumn<{
|
|
8565
|
-
name: "account_config_id";
|
|
8566
|
-
tableName: "filter_anchor";
|
|
8567
|
-
dataType: "string";
|
|
8568
|
-
columnType: "PgText";
|
|
8569
|
-
data: string;
|
|
8570
|
-
driverParam: string;
|
|
8571
|
-
notNull: true;
|
|
8572
|
-
hasDefault: false;
|
|
8573
|
-
isPrimaryKey: false;
|
|
8574
|
-
isAutoincrement: false;
|
|
8575
|
-
hasRuntimeDefault: false;
|
|
8576
|
-
enumValues: [string, ...string[]];
|
|
8577
|
-
baseColumn: never;
|
|
8578
|
-
identity: undefined;
|
|
8579
|
-
generated: undefined;
|
|
8580
|
-
}, {}, {}>;
|
|
8581
|
-
filterId: import("drizzle-orm/pg-core").PgColumn<{
|
|
8582
|
-
name: "filter_id";
|
|
8583
|
-
tableName: "filter_anchor";
|
|
8584
|
-
dataType: "string";
|
|
8585
|
-
columnType: "PgText";
|
|
8586
|
-
data: string;
|
|
8587
|
-
driverParam: string;
|
|
8588
|
-
notNull: true;
|
|
8589
|
-
hasDefault: false;
|
|
8590
|
-
isPrimaryKey: false;
|
|
8591
|
-
isAutoincrement: false;
|
|
8592
|
-
hasRuntimeDefault: false;
|
|
8593
|
-
enumValues: [string, ...string[]];
|
|
8594
|
-
baseColumn: never;
|
|
8595
|
-
identity: undefined;
|
|
8596
|
-
generated: undefined;
|
|
8597
|
-
}, {}, {}>;
|
|
8598
|
-
anchorEmbedding: import("drizzle-orm/pg-core").PgColumn<{
|
|
8599
|
-
name: "anchor_embedding";
|
|
8600
|
-
tableName: "filter_anchor";
|
|
8601
|
-
dataType: "json";
|
|
8602
|
-
columnType: "PgJsonb";
|
|
8603
|
-
data: unknown;
|
|
8604
|
-
driverParam: unknown;
|
|
8605
|
-
notNull: true;
|
|
8606
|
-
hasDefault: false;
|
|
8607
|
-
isPrimaryKey: false;
|
|
8608
|
-
isAutoincrement: false;
|
|
8609
|
-
hasRuntimeDefault: false;
|
|
8610
|
-
enumValues: undefined;
|
|
8611
|
-
baseColumn: never;
|
|
8612
|
-
identity: undefined;
|
|
8613
|
-
generated: undefined;
|
|
8614
|
-
}, {}, {}>;
|
|
8615
|
-
anchorEmbeddingId: import("drizzle-orm/pg-core").PgColumn<{
|
|
8616
|
-
name: "anchor_embedding_id";
|
|
8617
|
-
tableName: "filter_anchor";
|
|
8618
|
-
dataType: "string";
|
|
8619
|
-
columnType: "PgText";
|
|
8620
|
-
data: string;
|
|
8621
|
-
driverParam: string;
|
|
8622
|
-
notNull: true;
|
|
8623
|
-
hasDefault: false;
|
|
8624
|
-
isPrimaryKey: false;
|
|
8625
|
-
isAutoincrement: false;
|
|
8626
|
-
hasRuntimeDefault: false;
|
|
8627
|
-
enumValues: [string, ...string[]];
|
|
8628
|
-
baseColumn: never;
|
|
8629
|
-
identity: undefined;
|
|
8630
|
-
generated: undefined;
|
|
8631
|
-
}, {}, {}>;
|
|
8632
|
-
anchorSourceText: import("drizzle-orm/pg-core").PgColumn<{
|
|
8633
|
-
name: "anchor_source_text";
|
|
8634
|
-
tableName: "filter_anchor";
|
|
8635
|
-
dataType: "string";
|
|
8636
|
-
columnType: "PgText";
|
|
8637
|
-
data: string;
|
|
8638
|
-
driverParam: string;
|
|
8639
|
-
notNull: true;
|
|
8640
|
-
hasDefault: false;
|
|
8641
|
-
isPrimaryKey: false;
|
|
8642
|
-
isAutoincrement: false;
|
|
8643
|
-
hasRuntimeDefault: false;
|
|
8644
|
-
enumValues: [string, ...string[]];
|
|
8645
|
-
baseColumn: never;
|
|
8646
|
-
identity: undefined;
|
|
8647
|
-
generated: undefined;
|
|
8648
|
-
}, {}, {}>;
|
|
8649
|
-
anchorMessageId: import("drizzle-orm/pg-core").PgColumn<{
|
|
8650
|
-
name: "anchor_message_id";
|
|
8651
|
-
tableName: "filter_anchor";
|
|
8652
|
-
dataType: "string";
|
|
8653
|
-
columnType: "PgText";
|
|
8654
|
-
data: string;
|
|
8655
|
-
driverParam: string;
|
|
8656
|
-
notNull: true;
|
|
8657
|
-
hasDefault: false;
|
|
8658
|
-
isPrimaryKey: false;
|
|
8659
|
-
isAutoincrement: false;
|
|
8660
|
-
hasRuntimeDefault: false;
|
|
8661
|
-
enumValues: [string, ...string[]];
|
|
8662
|
-
baseColumn: never;
|
|
8663
|
-
identity: undefined;
|
|
8664
|
-
generated: undefined;
|
|
8665
|
-
}, {}, {}>;
|
|
8666
|
-
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
8667
|
-
name: "created_at";
|
|
8668
|
-
tableName: "filter_anchor";
|
|
8669
|
-
dataType: "number";
|
|
8670
|
-
columnType: "PgBigInt53";
|
|
8671
|
-
data: number;
|
|
8672
|
-
driverParam: string | number;
|
|
8673
|
-
notNull: true;
|
|
8674
|
-
hasDefault: false;
|
|
8675
|
-
isPrimaryKey: false;
|
|
8676
|
-
isAutoincrement: false;
|
|
8677
|
-
hasRuntimeDefault: false;
|
|
8678
|
-
enumValues: undefined;
|
|
8679
|
-
baseColumn: never;
|
|
8680
|
-
identity: undefined;
|
|
8681
|
-
generated: undefined;
|
|
8682
|
-
}, {}, {}>;
|
|
8683
|
-
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
8684
|
-
name: "updated_at";
|
|
8685
|
-
tableName: "filter_anchor";
|
|
8686
|
-
dataType: "number";
|
|
8687
|
-
columnType: "PgBigInt53";
|
|
8688
|
-
data: number;
|
|
8689
|
-
driverParam: string | number;
|
|
8690
|
-
notNull: true;
|
|
8691
|
-
hasDefault: false;
|
|
8692
|
-
isPrimaryKey: false;
|
|
8693
|
-
isAutoincrement: false;
|
|
8694
|
-
hasRuntimeDefault: false;
|
|
8695
|
-
enumValues: undefined;
|
|
8696
|
-
baseColumn: never;
|
|
8697
|
-
identity: undefined;
|
|
8698
|
-
generated: undefined;
|
|
8699
|
-
}, {}, {}>;
|
|
8700
|
-
};
|
|
8701
|
-
dialect: "pg";
|
|
8702
|
-
}>;
|
package/dist/schema.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bigint, boolean,
|
|
1
|
+
import { bigint, boolean, index, integer, jsonb, pgTable, primaryKey, text, uniqueIndex } from "drizzle-orm/pg-core";
|
|
2
2
|
import { generateBase36Id, nullableBigint, nullableInteger, nullableText } from "./types.js";
|
|
3
3
|
export const accountExportRequests = pgTable("account_export_request", {
|
|
4
4
|
accountExportRequestId: text("account_export_request_id").primaryKey().$defaultFn(() => generateBase36Id()),
|
|
@@ -41,6 +41,20 @@ export const quarantines = pgTable("quarantine", {
|
|
|
41
41
|
}, (table) => [
|
|
42
42
|
index("quarantine_by_account_config_id").on(table.accountConfigId, table.quarantinedAt),
|
|
43
43
|
]);
|
|
44
|
+
export const syncWarnings = pgTable("sync_warning", {
|
|
45
|
+
syncWarningId: text("sync_warning_id").primaryKey().$defaultFn(() => generateBase36Id()),
|
|
46
|
+
accountConfigId: text("account_config_id").notNull(),
|
|
47
|
+
accountId: text("account_id").notNull(),
|
|
48
|
+
mailboxId: text("mailbox_id").notNull(),
|
|
49
|
+
uidValidity: bigint("uid_validity", { mode: "number" }).notNull(),
|
|
50
|
+
uid: bigint("uid", { mode: "number" }).notNull(),
|
|
51
|
+
stage: text("stage").$type().notNull(),
|
|
52
|
+
attempts: integer("attempts").notNull(),
|
|
53
|
+
createdAt: bigint("created_at", { mode: "number" }).notNull(),
|
|
54
|
+
}, (table) => [
|
|
55
|
+
index("sync_warning_by_mailbox_id").on(table.mailboxId),
|
|
56
|
+
index("sync_warning_by_account_config_id").on(table.accountConfigId, table.createdAt),
|
|
57
|
+
]);
|
|
44
58
|
export const accountConfigs = pgTable("account_config", {
|
|
45
59
|
accountConfigId: text("account_config_id").primaryKey().$defaultFn(() => generateBase36Id()),
|
|
46
60
|
userId: text("user_id").notNull(),
|
|
@@ -128,11 +142,10 @@ export const filters = pgTable("filter", {
|
|
|
128
142
|
ttl: nullableBigint("ttl"),
|
|
129
143
|
state: text("state").$type().notNull().default("Active"),
|
|
130
144
|
disabledReason: text("disabled_reason").$type().notNull().default("None"),
|
|
131
|
-
hasAnchor: boolean("has_anchor").notNull().default(false),
|
|
132
145
|
ruleChangedAt: bigint("rule_changed_at", { mode: "number" }).notNull(),
|
|
133
146
|
actionChangedAt: bigint("action_changed_at", { mode: "number" }).notNull(),
|
|
134
147
|
matchOperator: text("match_operator").$type().notNull().default("And"),
|
|
135
|
-
literalClauses: jsonb("literal_clauses").notNull()
|
|
148
|
+
literalClauses: jsonb("literal_clauses").notNull(),
|
|
136
149
|
actionLabelId: text("action_label_id").notNull().default("None"),
|
|
137
150
|
actionMailboxId: text("action_mailbox_id").notNull().default("None"),
|
|
138
151
|
createdAt: bigint("created_at", { mode: "number" }).notNull(),
|
|
@@ -159,10 +172,8 @@ export const organizeJobRequests = pgTable("organize_job_request", {
|
|
|
159
172
|
userId: text("user_id").notNull(),
|
|
160
173
|
state: text("state").$type().notNull().default("Pending"),
|
|
161
174
|
filterId: text("filter_id").notNull().default("None"),
|
|
162
|
-
anchorMessageId: text("anchor_message_id").notNull().default("None"),
|
|
163
175
|
matchOperator: text("match_operator").$type().notNull().default("And"),
|
|
164
176
|
literalClauses: jsonb("literal_clauses").notNull().default([]),
|
|
165
|
-
similarityThreshold: doublePrecision("similarity_threshold").notNull().default(0.75),
|
|
166
177
|
actionLabelId: text("action_label_id").notNull().default("None"),
|
|
167
178
|
actionMailboxId: text("action_mailbox_id").notNull().default("None"),
|
|
168
179
|
matchedCount: integer("matched_count").notNull().default(0),
|
|
@@ -321,14 +332,13 @@ export const addresses = pgTable("address", {
|
|
|
321
332
|
}, (table) => [
|
|
322
333
|
index("address_by_account_config_id").on(table.accountConfigId, table.normalizedCompound),
|
|
323
334
|
]);
|
|
324
|
-
export const
|
|
335
|
+
export const messageRecords = pgTable("message", {
|
|
325
336
|
messageId: text("message_id").primaryKey().$defaultFn(() => generateBase36Id()),
|
|
326
337
|
mailboxId: text("mailbox_id").notNull(),
|
|
327
338
|
uid: bigint("uid", { mode: "number" }).notNull(),
|
|
328
339
|
sequenceNumber: integer("sequence_number").notNull(),
|
|
329
340
|
rfc822Size: bigint("rfc822_size", { mode: "number" }).notNull(),
|
|
330
341
|
internalDate: bigint("internal_date", { mode: "number" }).notNull(),
|
|
331
|
-
messageIdHeader: nullableText("message_id_header"),
|
|
332
342
|
envelopeId: text("envelope_id").notNull(),
|
|
333
343
|
rootBodyPartId: text("root_body_part_id").notNull(),
|
|
334
344
|
bodyStorageKey: nullableText("body_storage_key"),
|
|
@@ -403,6 +413,7 @@ export const calendarSuggestions = pgTable("calendar_suggestion", {
|
|
|
403
413
|
summary: text("summary").notNull(),
|
|
404
414
|
dtStart: text("dt_start").notNull(),
|
|
405
415
|
dtEnd: text("dt_end").notNull(),
|
|
416
|
+
endsAtUtc: text("ends_at_utc").notNull(),
|
|
406
417
|
allDay: boolean("all_day").notNull().default(false),
|
|
407
418
|
location: text("location").notNull().default(""),
|
|
408
419
|
organizer: text("organizer").notNull().default(""),
|
|
@@ -562,6 +573,11 @@ export const bodyPartParameters = pgTable("body_part_parameter", {
|
|
|
562
573
|
}, (table) => [
|
|
563
574
|
index("body_part_parameter_by_message_id").on(table.messageId, table.bodyPartParameterId),
|
|
564
575
|
]);
|
|
576
|
+
export const bodyStructureRefetches = pgTable("body_structure_refetch", {
|
|
577
|
+
messageId: text("message_id").primaryKey().$defaultFn(() => generateBase36Id()),
|
|
578
|
+
createdAt: bigint("created_at", { mode: "number" }).notNull(),
|
|
579
|
+
updatedAt: bigint("updated_at", { mode: "number" }).notNull(),
|
|
580
|
+
});
|
|
565
581
|
export const rawMessageStorages = pgTable("raw_message_storage", {
|
|
566
582
|
rawStorageId: text("raw_storage_id").primaryKey().$defaultFn(() => generateBase36Id()),
|
|
567
583
|
messageId: text("message_id").notNull(),
|
|
@@ -596,17 +612,6 @@ export const bodyPartStorages = pgTable("body_part_storage", {
|
|
|
596
612
|
}, (table) => [
|
|
597
613
|
index("body_part_storage_by_message_id").on(table.messageId, table.bodyPartStorageId),
|
|
598
614
|
]);
|
|
599
|
-
export const bodyPartContents = pgTable("body_part_content", {
|
|
600
|
-
bodyPartContentId: text("body_part_content_id").primaryKey().$defaultFn(() => generateBase36Id()),
|
|
601
|
-
messageId: text("message_id").notNull(),
|
|
602
|
-
bodyPartId: text("body_part_id").notNull(),
|
|
603
|
-
content: text("content").notNull(),
|
|
604
|
-
contentLength: bigint("content_length", { mode: "number" }).notNull(),
|
|
605
|
-
createdAt: bigint("created_at", { mode: "number" }).notNull(),
|
|
606
|
-
updatedAt: bigint("updated_at", { mode: "number" }).notNull(),
|
|
607
|
-
}, (table) => [
|
|
608
|
-
index("body_part_content_by_message_id").on(table.messageId, table.bodyPartContentId),
|
|
609
|
-
]);
|
|
610
615
|
export const calendarEventIndexes = pgTable("calendar_event_index", {
|
|
611
616
|
calendarId: text("calendar_id").notNull(),
|
|
612
617
|
calendarObjectId: text("calendar_object_id").notNull(),
|
|
@@ -647,15 +652,3 @@ export const messageLabels = pgTable("message_label", {
|
|
|
647
652
|
index("message_label_by_label_id").on(table.accountConfigId, table.labelId, table.createdAt),
|
|
648
653
|
index("message_label_by_message_id").on(table.messageId, table.labelId),
|
|
649
654
|
]);
|
|
650
|
-
export const filterAnchors = pgTable("filter_anchor", {
|
|
651
|
-
accountConfigId: text("account_config_id").notNull(),
|
|
652
|
-
filterId: text("filter_id").notNull(),
|
|
653
|
-
anchorEmbedding: jsonb("anchor_embedding").notNull(),
|
|
654
|
-
anchorEmbeddingId: text("anchor_embedding_id").notNull(),
|
|
655
|
-
anchorSourceText: text("anchor_source_text").notNull(),
|
|
656
|
-
anchorMessageId: text("anchor_message_id").notNull(),
|
|
657
|
-
createdAt: bigint("created_at", { mode: "number" }).notNull(),
|
|
658
|
-
updatedAt: bigint("updated_at", { mode: "number" }).notNull(),
|
|
659
|
-
}, (table) => [
|
|
660
|
-
primaryKey({ name: "filter_anchor_pk", columns: [table.accountConfigId, table.filterId] }),
|
|
661
|
-
]);
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,31 @@
|
|
|
1
|
-
/** UUID column
|
|
1
|
+
/** UUID column stored as native pg uuid, reads/writes as base36 */
|
|
2
|
+
export declare const canonicalUuid: {
|
|
3
|
+
(): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
4
|
+
name: "";
|
|
5
|
+
dataType: "custom";
|
|
6
|
+
columnType: "PgCustomColumn";
|
|
7
|
+
data: string;
|
|
8
|
+
driverParam: string;
|
|
9
|
+
enumValues: undefined;
|
|
10
|
+
}>;
|
|
11
|
+
<TConfig extends Record<string, any>>(fieldConfig?: TConfig): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
12
|
+
name: "";
|
|
13
|
+
dataType: "custom";
|
|
14
|
+
columnType: "PgCustomColumn";
|
|
15
|
+
data: string;
|
|
16
|
+
driverParam: string;
|
|
17
|
+
enumValues: undefined;
|
|
18
|
+
}>;
|
|
19
|
+
<TName extends string>(dbName: TName, fieldConfig?: unknown): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
20
|
+
name: TName;
|
|
21
|
+
dataType: "custom";
|
|
22
|
+
columnType: "PgCustomColumn";
|
|
23
|
+
data: string;
|
|
24
|
+
driverParam: string;
|
|
25
|
+
enumValues: undefined;
|
|
26
|
+
}>;
|
|
27
|
+
};
|
|
28
|
+
/** UUID column stored as the 25-character base36 string, reads/writes as base36 */
|
|
2
29
|
export declare const base36Uuid: {
|
|
3
30
|
(): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
4
31
|
name: "";
|
|
@@ -25,6 +52,33 @@ export declare const base36Uuid: {
|
|
|
25
52
|
enumValues: undefined;
|
|
26
53
|
}>;
|
|
27
54
|
};
|
|
55
|
+
/** UUID column stored as native pg uuid — 16 bytes on disk — reads/writes as base36 */
|
|
56
|
+
export declare const rawUuid: {
|
|
57
|
+
(): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
58
|
+
name: "";
|
|
59
|
+
dataType: "custom";
|
|
60
|
+
columnType: "PgCustomColumn";
|
|
61
|
+
data: string;
|
|
62
|
+
driverParam: string;
|
|
63
|
+
enumValues: undefined;
|
|
64
|
+
}>;
|
|
65
|
+
<TConfig extends Record<string, any>>(fieldConfig?: TConfig): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
66
|
+
name: "";
|
|
67
|
+
dataType: "custom";
|
|
68
|
+
columnType: "PgCustomColumn";
|
|
69
|
+
data: string;
|
|
70
|
+
driverParam: string;
|
|
71
|
+
enumValues: undefined;
|
|
72
|
+
}>;
|
|
73
|
+
<TName extends string>(dbName: TName, fieldConfig?: unknown): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
74
|
+
name: TName;
|
|
75
|
+
dataType: "custom";
|
|
76
|
+
columnType: "PgCustomColumn";
|
|
77
|
+
data: string;
|
|
78
|
+
driverParam: string;
|
|
79
|
+
enumValues: undefined;
|
|
80
|
+
}>;
|
|
81
|
+
};
|
|
28
82
|
export declare function generateBase36Id(): string;
|
|
29
83
|
export declare const nullableText: {
|
|
30
84
|
(): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
package/dist/types.js
CHANGED
|
@@ -1,14 +1,140 @@
|
|
|
1
1
|
import { customType } from "drizzle-orm/pg-core";
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
2
|
+
const base36Digits = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
3
|
+
const hexDigits = "0123456789abcdef";
|
|
4
|
+
const base36Values = (() => {
|
|
5
|
+
const table = new Int8Array(128).fill(-1);
|
|
6
|
+
for (let i = 0; i < base36Digits.length; i += 1)
|
|
7
|
+
table[base36Digits.charCodeAt(i)] = i;
|
|
8
|
+
return table;
|
|
9
|
+
})();
|
|
10
|
+
const hexValues = (() => {
|
|
11
|
+
const table = new Int8Array(128).fill(-1);
|
|
12
|
+
for (let i = 0; i < hexDigits.length; i += 1) {
|
|
13
|
+
table[hexDigits.charCodeAt(i)] = i;
|
|
14
|
+
table[hexDigits.toUpperCase().charCodeAt(i)] = i;
|
|
15
|
+
}
|
|
16
|
+
return table;
|
|
17
|
+
})();
|
|
18
|
+
const hexOctets = (() => {
|
|
19
|
+
const table = [];
|
|
20
|
+
for (let i = 0; i < 256; i += 1)
|
|
21
|
+
table.push(i.toString(16).padStart(2, "0"));
|
|
22
|
+
return table;
|
|
23
|
+
})();
|
|
24
|
+
const base36Scales = [1, 36, 1296, 46656, 1679616, 60466176];
|
|
25
|
+
function readBase36(id, start, count) {
|
|
26
|
+
let value = 0;
|
|
27
|
+
for (let i = start; i < start + count; i += 1) {
|
|
28
|
+
const code = id.charCodeAt(i);
|
|
29
|
+
const digit = code < 128 ? base36Values[code] : -1;
|
|
30
|
+
if (digit < 0)
|
|
31
|
+
throw new Error(`Not a base36 uuid: ${id}`);
|
|
32
|
+
value = value * 36 + digit;
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
function scaleAndAdd(limbs, scale, addend) {
|
|
37
|
+
let carry = addend;
|
|
38
|
+
for (let i = 7; i >= 0; i -= 1) {
|
|
39
|
+
const product = limbs[i] * scale + carry;
|
|
40
|
+
const low = product % 65536;
|
|
41
|
+
limbs[i] = low;
|
|
42
|
+
carry = (product - low) / 65536;
|
|
43
|
+
}
|
|
44
|
+
return carry;
|
|
45
|
+
}
|
|
46
|
+
function base36ToBytes(id) {
|
|
47
|
+
if (id.length === 0 || id.length > 25)
|
|
48
|
+
throw new Error(`Not a base36 uuid: ${id}`);
|
|
49
|
+
const limbs = new Uint32Array(8);
|
|
50
|
+
const head = id.length % 5;
|
|
51
|
+
if (head > 0 && scaleAndAdd(limbs, base36Scales[head], readBase36(id, 0, head)) !== 0) {
|
|
52
|
+
throw new Error(`base36 uuid does not fit in 128 bits: ${id}`);
|
|
53
|
+
}
|
|
54
|
+
for (let cursor = head; cursor < id.length; cursor += 5) {
|
|
55
|
+
if (scaleAndAdd(limbs, 60466176, readBase36(id, cursor, 5)) !== 0) {
|
|
56
|
+
throw new Error(`base36 uuid does not fit in 128 bits: ${id}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const bytes = new Uint8Array(16);
|
|
60
|
+
for (let i = 0; i < 8; i += 1) {
|
|
61
|
+
bytes[i * 2] = limbs[i] >>> 8;
|
|
62
|
+
bytes[i * 2 + 1] = limbs[i] & 0xff;
|
|
63
|
+
}
|
|
64
|
+
return bytes;
|
|
65
|
+
}
|
|
66
|
+
function bytesToBase36(bytes) {
|
|
67
|
+
if (bytes.length !== 16)
|
|
68
|
+
throw new Error(`Not a 16-byte uuid: ${bytes.length} bytes`);
|
|
69
|
+
const limbs = new Uint32Array(8);
|
|
70
|
+
for (let i = 0; i < 8; i += 1)
|
|
71
|
+
limbs[i] = (bytes[i * 2] << 8) | bytes[i * 2 + 1];
|
|
72
|
+
let id = "";
|
|
73
|
+
for (let chunk = 0; chunk < 5; chunk += 1) {
|
|
74
|
+
let remainder = 0;
|
|
75
|
+
for (let i = 0; i < 8; i += 1) {
|
|
76
|
+
const current = remainder * 65536 + limbs[i];
|
|
77
|
+
const quotient = Math.floor(current / 60466176);
|
|
78
|
+
limbs[i] = quotient;
|
|
79
|
+
remainder = current - quotient * 60466176;
|
|
80
|
+
}
|
|
81
|
+
let piece = "";
|
|
82
|
+
for (let i = 0; i < 5; i += 1) {
|
|
83
|
+
const digit = remainder % 36;
|
|
84
|
+
piece = base36Digits[digit] + piece;
|
|
85
|
+
remainder = (remainder - digit) / 36;
|
|
86
|
+
}
|
|
87
|
+
id = piece + id;
|
|
88
|
+
}
|
|
89
|
+
return id;
|
|
90
|
+
}
|
|
91
|
+
function uuidToBytes(uuid) {
|
|
92
|
+
const bytes = new Uint8Array(16);
|
|
93
|
+
let cursor = 0;
|
|
94
|
+
for (let i = 0; i < 16; i += 1) {
|
|
95
|
+
if (uuid.charCodeAt(cursor) === 45)
|
|
96
|
+
cursor += 1;
|
|
97
|
+
const high = readHex(uuid, cursor);
|
|
98
|
+
const low = readHex(uuid, cursor + 1);
|
|
99
|
+
bytes[i] = (high << 4) | low;
|
|
100
|
+
cursor += 2;
|
|
101
|
+
}
|
|
102
|
+
if (cursor !== uuid.length)
|
|
103
|
+
throw new Error(`Not a uuid: ${uuid}`);
|
|
104
|
+
return bytes;
|
|
105
|
+
}
|
|
106
|
+
function readHex(uuid, index) {
|
|
107
|
+
const code = uuid.charCodeAt(index);
|
|
108
|
+
const value = code < 128 ? hexValues[code] : -1;
|
|
109
|
+
if (value < 0)
|
|
110
|
+
throw new Error(`Not a uuid: ${uuid}`);
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
function bytesToUuid(bytes) {
|
|
114
|
+
return `${hexOctets[bytes[0]]}${hexOctets[bytes[1]]}${hexOctets[bytes[2]]}${hexOctets[bytes[3]]}-${hexOctets[bytes[4]]}${hexOctets[bytes[5]]}-${hexOctets[bytes[6]]}${hexOctets[bytes[7]]}-${hexOctets[bytes[8]]}${hexOctets[bytes[9]]}-${hexOctets[bytes[10]]}${hexOctets[bytes[11]]}${hexOctets[bytes[12]]}${hexOctets[bytes[13]]}${hexOctets[bytes[14]]}${hexOctets[bytes[15]]}`;
|
|
115
|
+
}
|
|
116
|
+
/** UUID column stored as native pg uuid, reads/writes as base36 */
|
|
117
|
+
export const canonicalUuid = customType({
|
|
118
|
+
dataType: () => "uuid",
|
|
119
|
+
toDriver: (value) => bytesToUuid(base36ToBytes(value)),
|
|
120
|
+
fromDriver: (value) => bytesToBase36(uuidToBytes(value)),
|
|
121
|
+
});
|
|
122
|
+
/** UUID column stored as the 25-character base36 string, reads/writes as base36 */
|
|
5
123
|
export const base36Uuid = customType({
|
|
124
|
+
dataType: () => "text",
|
|
125
|
+
});
|
|
126
|
+
/** UUID column stored as native pg uuid — 16 bytes on disk — reads/writes as base36 */
|
|
127
|
+
export const rawUuid = customType({
|
|
6
128
|
dataType: () => "uuid",
|
|
7
|
-
toDriver: (value) =>
|
|
8
|
-
fromDriver: (value) =>
|
|
129
|
+
toDriver: (value) => bytesToUuid(base36ToBytes(value)),
|
|
130
|
+
fromDriver: (value) => bytesToBase36(uuidToBytes(value)),
|
|
9
131
|
});
|
|
10
132
|
export function generateBase36Id() {
|
|
11
|
-
|
|
133
|
+
const bytes = new Uint8Array(16);
|
|
134
|
+
crypto.getRandomValues(bytes);
|
|
135
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
136
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
137
|
+
return bytesToBase36(bytes);
|
|
12
138
|
}
|
|
13
139
|
export const nullableText = customType({
|
|
14
140
|
dataType: () => "text",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remit/drizzle-pg-schema",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.35",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,9 +15,6 @@
|
|
|
15
15
|
"build": "tsc",
|
|
16
16
|
"prepare": "tsc"
|
|
17
17
|
},
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"short-uuid": "^5.2.0"
|
|
20
|
-
},
|
|
21
18
|
"peerDependencies": {
|
|
22
19
|
"drizzle-orm": ">=0.30.0",
|
|
23
20
|
"typescript": ">=5.0.0"
|
package/schema.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bigint, boolean,
|
|
1
|
+
import { bigint, boolean, index, integer, jsonb, pgTable, primaryKey, text, uniqueIndex } from "drizzle-orm/pg-core";
|
|
2
2
|
import { generateBase36Id, nullableBigint, nullableInteger, nullableText } from "./types.js";
|
|
3
3
|
|
|
4
4
|
export const accountExportRequests = pgTable(
|
|
@@ -52,6 +52,25 @@ export const quarantines = pgTable(
|
|
|
52
52
|
],
|
|
53
53
|
);
|
|
54
54
|
|
|
55
|
+
export const syncWarnings = pgTable(
|
|
56
|
+
"sync_warning",
|
|
57
|
+
{
|
|
58
|
+
syncWarningId: text("sync_warning_id").primaryKey().$defaultFn(() => generateBase36Id()),
|
|
59
|
+
accountConfigId: text("account_config_id").notNull(),
|
|
60
|
+
accountId: text("account_id").notNull(),
|
|
61
|
+
mailboxId: text("mailbox_id").notNull(),
|
|
62
|
+
uidValidity: bigint("uid_validity", { mode: "number" }).notNull(),
|
|
63
|
+
uid: bigint("uid", { mode: "number" }).notNull(),
|
|
64
|
+
stage: text("stage").$type<"Header" | "Body">().notNull(),
|
|
65
|
+
attempts: integer("attempts").notNull(),
|
|
66
|
+
createdAt: bigint("created_at", { mode: "number" }).notNull(),
|
|
67
|
+
},
|
|
68
|
+
(table) => [
|
|
69
|
+
index("sync_warning_by_mailbox_id").on(table.mailboxId),
|
|
70
|
+
index("sync_warning_by_account_config_id").on(table.accountConfigId, table.createdAt),
|
|
71
|
+
],
|
|
72
|
+
);
|
|
73
|
+
|
|
55
74
|
export const accountConfigs = pgTable(
|
|
56
75
|
"account_config",
|
|
57
76
|
{
|
|
@@ -156,11 +175,10 @@ export const filters = pgTable(
|
|
|
156
175
|
ttl: nullableBigint("ttl"),
|
|
157
176
|
state: text("state").$type<"Active" | "Expired" | "Disabled">().notNull().default("Active"),
|
|
158
177
|
disabledReason: text("disabled_reason").$type<"None" | "UserDisabled" | "AwaitingFolder" | "FolderCreateFailed" | "FolderMissing">().notNull().default("None"),
|
|
159
|
-
hasAnchor: boolean("has_anchor").notNull().default(false),
|
|
160
178
|
ruleChangedAt: bigint("rule_changed_at", { mode: "number" }).notNull(),
|
|
161
179
|
actionChangedAt: bigint("action_changed_at", { mode: "number" }).notNull(),
|
|
162
180
|
matchOperator: text("match_operator").$type<"And" | "Or">().notNull().default("And"),
|
|
163
|
-
literalClauses: jsonb("literal_clauses").notNull()
|
|
181
|
+
literalClauses: jsonb("literal_clauses").notNull(),
|
|
164
182
|
actionLabelId: text("action_label_id").notNull().default("None"),
|
|
165
183
|
actionMailboxId: text("action_mailbox_id").notNull().default("None"),
|
|
166
184
|
createdAt: bigint("created_at", { mode: "number" }).notNull(),
|
|
@@ -197,10 +215,8 @@ export const organizeJobRequests = pgTable(
|
|
|
197
215
|
userId: text("user_id").notNull(),
|
|
198
216
|
state: text("state").$type<"Pending" | "Running" | "Complete" | "Failed">().notNull().default("Pending"),
|
|
199
217
|
filterId: text("filter_id").notNull().default("None"),
|
|
200
|
-
anchorMessageId: text("anchor_message_id").notNull().default("None"),
|
|
201
218
|
matchOperator: text("match_operator").$type<"And" | "Or">().notNull().default("And"),
|
|
202
219
|
literalClauses: jsonb("literal_clauses").notNull().default([]),
|
|
203
|
-
similarityThreshold: doublePrecision("similarity_threshold").notNull().default(0.75),
|
|
204
220
|
actionLabelId: text("action_label_id").notNull().default("None"),
|
|
205
221
|
actionMailboxId: text("action_mailbox_id").notNull().default("None"),
|
|
206
222
|
matchedCount: integer("matched_count").notNull().default(0),
|
|
@@ -392,7 +408,7 @@ export const addresses = pgTable(
|
|
|
392
408
|
],
|
|
393
409
|
);
|
|
394
410
|
|
|
395
|
-
export const
|
|
411
|
+
export const messageRecords = pgTable(
|
|
396
412
|
"message",
|
|
397
413
|
{
|
|
398
414
|
messageId: text("message_id").primaryKey().$defaultFn(() => generateBase36Id()),
|
|
@@ -401,7 +417,6 @@ export const messages = pgTable(
|
|
|
401
417
|
sequenceNumber: integer("sequence_number").notNull(),
|
|
402
418
|
rfc822Size: bigint("rfc822_size", { mode: "number" }).notNull(),
|
|
403
419
|
internalDate: bigint("internal_date", { mode: "number" }).notNull(),
|
|
404
|
-
messageIdHeader: nullableText("message_id_header"),
|
|
405
420
|
envelopeId: text("envelope_id").notNull(),
|
|
406
421
|
rootBodyPartId: text("root_body_part_id").notNull(),
|
|
407
422
|
bodyStorageKey: nullableText("body_storage_key"),
|
|
@@ -491,6 +506,7 @@ export const calendarSuggestions = pgTable(
|
|
|
491
506
|
summary: text("summary").notNull(),
|
|
492
507
|
dtStart: text("dt_start").notNull(),
|
|
493
508
|
dtEnd: text("dt_end").notNull(),
|
|
509
|
+
endsAtUtc: text("ends_at_utc").notNull(),
|
|
494
510
|
allDay: boolean("all_day").notNull().default(false),
|
|
495
511
|
location: text("location").notNull().default(""),
|
|
496
512
|
organizer: text("organizer").notNull().default(""),
|
|
@@ -718,6 +734,12 @@ export const bodyPartParameters = pgTable(
|
|
|
718
734
|
],
|
|
719
735
|
);
|
|
720
736
|
|
|
737
|
+
export const bodyStructureRefetches = pgTable("body_structure_refetch", {
|
|
738
|
+
messageId: text("message_id").primaryKey().$defaultFn(() => generateBase36Id()),
|
|
739
|
+
createdAt: bigint("created_at", { mode: "number" }).notNull(),
|
|
740
|
+
updatedAt: bigint("updated_at", { mode: "number" }).notNull(),
|
|
741
|
+
});
|
|
742
|
+
|
|
721
743
|
export const rawMessageStorages = pgTable(
|
|
722
744
|
"raw_message_storage",
|
|
723
745
|
{
|
|
@@ -762,22 +784,6 @@ export const bodyPartStorages = pgTable(
|
|
|
762
784
|
],
|
|
763
785
|
);
|
|
764
786
|
|
|
765
|
-
export const bodyPartContents = pgTable(
|
|
766
|
-
"body_part_content",
|
|
767
|
-
{
|
|
768
|
-
bodyPartContentId: text("body_part_content_id").primaryKey().$defaultFn(() => generateBase36Id()),
|
|
769
|
-
messageId: text("message_id").notNull(),
|
|
770
|
-
bodyPartId: text("body_part_id").notNull(),
|
|
771
|
-
content: text("content").notNull(),
|
|
772
|
-
contentLength: bigint("content_length", { mode: "number" }).notNull(),
|
|
773
|
-
createdAt: bigint("created_at", { mode: "number" }).notNull(),
|
|
774
|
-
updatedAt: bigint("updated_at", { mode: "number" }).notNull(),
|
|
775
|
-
},
|
|
776
|
-
(table) => [
|
|
777
|
-
index("body_part_content_by_message_id").on(table.messageId, table.bodyPartContentId),
|
|
778
|
-
],
|
|
779
|
-
);
|
|
780
|
-
|
|
781
787
|
export const calendarEventIndexes = pgTable(
|
|
782
788
|
"calendar_event_index",
|
|
783
789
|
{
|
|
@@ -832,20 +838,3 @@ export const messageLabels = pgTable(
|
|
|
832
838
|
index("message_label_by_message_id").on(table.messageId, table.labelId),
|
|
833
839
|
],
|
|
834
840
|
);
|
|
835
|
-
|
|
836
|
-
export const filterAnchors = pgTable(
|
|
837
|
-
"filter_anchor",
|
|
838
|
-
{
|
|
839
|
-
accountConfigId: text("account_config_id").notNull(),
|
|
840
|
-
filterId: text("filter_id").notNull(),
|
|
841
|
-
anchorEmbedding: jsonb("anchor_embedding").notNull(),
|
|
842
|
-
anchorEmbeddingId: text("anchor_embedding_id").notNull(),
|
|
843
|
-
anchorSourceText: text("anchor_source_text").notNull(),
|
|
844
|
-
anchorMessageId: text("anchor_message_id").notNull(),
|
|
845
|
-
createdAt: bigint("created_at", { mode: "number" }).notNull(),
|
|
846
|
-
updatedAt: bigint("updated_at", { mode: "number" }).notNull(),
|
|
847
|
-
},
|
|
848
|
-
(table) => [
|
|
849
|
-
primaryKey({ name: "filter_anchor_pk", columns: [table.accountConfigId, table.filterId] }),
|
|
850
|
-
],
|
|
851
|
-
);
|
package/types.ts
CHANGED
|
@@ -1,20 +1,156 @@
|
|
|
1
1
|
import { customType } from "drizzle-orm/pg-core";
|
|
2
|
-
import short from "short-uuid";
|
|
3
2
|
|
|
4
|
-
const
|
|
3
|
+
const base36Digits = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
4
|
+
const hexDigits = "0123456789abcdef";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const base36Values = ((): Int8Array => {
|
|
7
|
+
const table = new Int8Array(128).fill(-1);
|
|
8
|
+
for (let i = 0; i < base36Digits.length; i += 1) table[base36Digits.charCodeAt(i)] = i;
|
|
9
|
+
return table;
|
|
10
|
+
})();
|
|
11
|
+
|
|
12
|
+
const hexValues = ((): Int8Array => {
|
|
13
|
+
const table = new Int8Array(128).fill(-1);
|
|
14
|
+
for (let i = 0; i < hexDigits.length; i += 1) {
|
|
15
|
+
table[hexDigits.charCodeAt(i)] = i;
|
|
16
|
+
table[hexDigits.toUpperCase().charCodeAt(i)] = i;
|
|
17
|
+
}
|
|
18
|
+
return table;
|
|
19
|
+
})();
|
|
20
|
+
|
|
21
|
+
const hexOctets = ((): string[] => {
|
|
22
|
+
const table: string[] = [];
|
|
23
|
+
for (let i = 0; i < 256; i += 1) table.push(i.toString(16).padStart(2, "0"));
|
|
24
|
+
return table;
|
|
25
|
+
})();
|
|
26
|
+
|
|
27
|
+
const base36Scales = [1, 36, 1296, 46656, 1679616, 60466176];
|
|
28
|
+
|
|
29
|
+
function readBase36(id: string, start: number, count: number): number {
|
|
30
|
+
let value = 0;
|
|
31
|
+
for (let i = start; i < start + count; i += 1) {
|
|
32
|
+
const code = id.charCodeAt(i);
|
|
33
|
+
const digit = code < 128 ? base36Values[code] : -1;
|
|
34
|
+
if (digit < 0) throw new Error(`Not a base36 uuid: ${id}`);
|
|
35
|
+
value = value * 36 + digit;
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function scaleAndAdd(limbs: Uint32Array, scale: number, addend: number): number {
|
|
41
|
+
let carry = addend;
|
|
42
|
+
for (let i = 7; i >= 0; i -= 1) {
|
|
43
|
+
const product = limbs[i] * scale + carry;
|
|
44
|
+
const low = product % 65536;
|
|
45
|
+
limbs[i] = low;
|
|
46
|
+
carry = (product - low) / 65536;
|
|
47
|
+
}
|
|
48
|
+
return carry;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function base36ToBytes(id: string): Uint8Array {
|
|
52
|
+
if (id.length === 0 || id.length > 25) throw new Error(`Not a base36 uuid: ${id}`);
|
|
53
|
+
const limbs = new Uint32Array(8);
|
|
54
|
+
const head = id.length % 5;
|
|
55
|
+
if (head > 0 && scaleAndAdd(limbs, base36Scales[head], readBase36(id, 0, head)) !== 0) {
|
|
56
|
+
throw new Error(`base36 uuid does not fit in 128 bits: ${id}`);
|
|
57
|
+
}
|
|
58
|
+
for (let cursor = head; cursor < id.length; cursor += 5) {
|
|
59
|
+
if (scaleAndAdd(limbs, 60466176, readBase36(id, cursor, 5)) !== 0) {
|
|
60
|
+
throw new Error(`base36 uuid does not fit in 128 bits: ${id}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const bytes = new Uint8Array(16);
|
|
64
|
+
for (let i = 0; i < 8; i += 1) {
|
|
65
|
+
bytes[i * 2] = limbs[i] >>> 8;
|
|
66
|
+
bytes[i * 2 + 1] = limbs[i] & 0xff;
|
|
67
|
+
}
|
|
68
|
+
return bytes;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function bytesToBase36(bytes: Uint8Array): string {
|
|
72
|
+
if (bytes.length !== 16) throw new Error(`Not a 16-byte uuid: ${bytes.length} bytes`);
|
|
73
|
+
const limbs = new Uint32Array(8);
|
|
74
|
+
for (let i = 0; i < 8; i += 1) limbs[i] = (bytes[i * 2] << 8) | bytes[i * 2 + 1];
|
|
75
|
+
let id = "";
|
|
76
|
+
for (let chunk = 0; chunk < 5; chunk += 1) {
|
|
77
|
+
let remainder = 0;
|
|
78
|
+
for (let i = 0; i < 8; i += 1) {
|
|
79
|
+
const current = remainder * 65536 + limbs[i];
|
|
80
|
+
const quotient = Math.floor(current / 60466176);
|
|
81
|
+
limbs[i] = quotient;
|
|
82
|
+
remainder = current - quotient * 60466176;
|
|
83
|
+
}
|
|
84
|
+
let piece = "";
|
|
85
|
+
for (let i = 0; i < 5; i += 1) {
|
|
86
|
+
const digit = remainder % 36;
|
|
87
|
+
piece = base36Digits[digit] + piece;
|
|
88
|
+
remainder = (remainder - digit) / 36;
|
|
89
|
+
}
|
|
90
|
+
id = piece + id;
|
|
91
|
+
}
|
|
92
|
+
return id;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function uuidToBytes(uuid: string): Uint8Array {
|
|
96
|
+
const bytes = new Uint8Array(16);
|
|
97
|
+
let cursor = 0;
|
|
98
|
+
for (let i = 0; i < 16; i += 1) {
|
|
99
|
+
if (uuid.charCodeAt(cursor) === 45) cursor += 1;
|
|
100
|
+
const high = readHex(uuid, cursor);
|
|
101
|
+
const low = readHex(uuid, cursor + 1);
|
|
102
|
+
bytes[i] = (high << 4) | low;
|
|
103
|
+
cursor += 2;
|
|
104
|
+
}
|
|
105
|
+
if (cursor !== uuid.length) throw new Error(`Not a uuid: ${uuid}`);
|
|
106
|
+
return bytes;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function readHex(uuid: string, index: number): number {
|
|
110
|
+
const code = uuid.charCodeAt(index);
|
|
111
|
+
const value = code < 128 ? hexValues[code] : -1;
|
|
112
|
+
if (value < 0) throw new Error(`Not a uuid: ${uuid}`);
|
|
113
|
+
return value;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function bytesToUuid(bytes: Uint8Array): string {
|
|
117
|
+
return `${hexOctets[bytes[0]]}${hexOctets[bytes[1]]}${hexOctets[bytes[2]]}${hexOctets[bytes[3]]}-${hexOctets[bytes[4]]}${hexOctets[bytes[5]]}-${hexOctets[bytes[6]]}${hexOctets[bytes[7]]}-${hexOctets[bytes[8]]}${hexOctets[bytes[9]]}-${hexOctets[bytes[10]]}${hexOctets[bytes[11]]}${hexOctets[bytes[12]]}${hexOctets[bytes[13]]}${hexOctets[bytes[14]]}${hexOctets[bytes[15]]}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** UUID column stored as native pg uuid, reads/writes as base36 */
|
|
121
|
+
export const canonicalUuid = customType<{
|
|
122
|
+
data: string;
|
|
123
|
+
driverData: string;
|
|
124
|
+
}>({
|
|
125
|
+
dataType: () => "uuid",
|
|
126
|
+
toDriver: (value: string): string => bytesToUuid(base36ToBytes(value)),
|
|
127
|
+
fromDriver: (value: string): string => bytesToBase36(uuidToBytes(value)),
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
/** UUID column stored as the 25-character base36 string, reads/writes as base36 */
|
|
7
131
|
export const base36Uuid = customType<{
|
|
8
132
|
data: string;
|
|
9
133
|
driverData: string;
|
|
134
|
+
}>({
|
|
135
|
+
dataType: () => "text",
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
/** UUID column stored as native pg uuid — 16 bytes on disk — reads/writes as base36 */
|
|
139
|
+
export const rawUuid = customType<{
|
|
140
|
+
data: string;
|
|
141
|
+
driverData: string;
|
|
10
142
|
}>({
|
|
11
143
|
dataType: () => "uuid",
|
|
12
|
-
toDriver: (value: string): string =>
|
|
13
|
-
fromDriver: (value: string): string =>
|
|
144
|
+
toDriver: (value: string): string => bytesToUuid(base36ToBytes(value)),
|
|
145
|
+
fromDriver: (value: string): string => bytesToBase36(uuidToBytes(value)),
|
|
14
146
|
});
|
|
15
147
|
|
|
16
148
|
export function generateBase36Id(): string {
|
|
17
|
-
|
|
149
|
+
const bytes = new Uint8Array(16);
|
|
150
|
+
crypto.getRandomValues(bytes);
|
|
151
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
152
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
153
|
+
return bytesToBase36(bytes);
|
|
18
154
|
}
|
|
19
155
|
|
|
20
156
|
export const nullableText = customType<{
|