@remit/drizzle-sqlite-schema 0.0.1

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.js ADDED
@@ -0,0 +1,474 @@
1
+ import { index, integer, primaryKey, real, sqliteTable, text } from "drizzle-orm/sqlite-core";
2
+ import { generateBase36Id, nullableInteger, nullableText } from "./types.js";
3
+ export const accountExportRequests = sqliteTable("account_export_request", {
4
+ accountExportRequestId: text("account_export_request_id").primaryKey().$defaultFn(() => generateBase36Id()),
5
+ accountConfigId: text("account_config_id").notNull(),
6
+ userId: text("user_id").notNull(),
7
+ state: text("state").$type().notNull().default("Pending"),
8
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
9
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
10
+ expiresAt: integer("expires_at", { mode: "number" }),
11
+ objectKey: nullableText("object_key"),
12
+ downloadUrl: nullableText("download_url"),
13
+ errorMessage: nullableText("error_message"),
14
+ }, (table) => [
15
+ index("account_export_request_by_account_config_id").on(table.accountConfigId, table.createdAt),
16
+ ]);
17
+ export const accountConfigs = sqliteTable("account_config", {
18
+ accountConfigId: text("account_config_id").primaryKey().$defaultFn(() => generateBase36Id()),
19
+ userId: text("user_id").notNull(),
20
+ name: nullableText("name"),
21
+ state: text("state").$type().notNull().default("active"),
22
+ deletedAt: integer("deleted_at", { mode: "number" }),
23
+ cascadeStartedAt: integer("cascade_started_at", { mode: "number" }),
24
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
25
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
26
+ }, (table) => [
27
+ index("account_config_by_user_id").on(table.userId, table.accountConfigId),
28
+ ]);
29
+ export const accounts = sqliteTable("account", {
30
+ accountId: text("account_id").primaryKey().$defaultFn(() => generateBase36Id()),
31
+ accountConfigId: text("account_config_id").notNull(),
32
+ username: text("username").notNull(),
33
+ email: text("email").notNull(),
34
+ authType: text("auth_type").$type().notNull().default("password"),
35
+ passwordHash: nullableText("password_hash"),
36
+ oauthRefreshTokenHash: nullableText("oauth_refresh_token_hash"),
37
+ oauthTokenUpdatedAt: integer("oauth_token_updated_at", { mode: "number" }),
38
+ imapHost: text("imap_host").notNull(),
39
+ imapPort: integer("imap_port").notNull(),
40
+ imapTls: integer("imap_tls", { mode: "boolean" }).notNull(),
41
+ imapStartTls: integer("imap_start_tls", { mode: "boolean" }).notNull(),
42
+ smtpEnabled: integer("smtp_enabled", { mode: "boolean" }).notNull().default(false),
43
+ smtpHost: text("smtp_host").notNull().default(""),
44
+ smtpPort: integer("smtp_port").notNull(),
45
+ smtpTls: integer("smtp_tls", { mode: "boolean" }).notNull().default(false),
46
+ smtpStartTls: integer("smtp_start_tls", { mode: "boolean" }).notNull().default(true),
47
+ smtpUsername: text("smtp_username").notNull().default(""),
48
+ smtpPasswordHash: nullableText("smtp_password_hash"),
49
+ isActive: integer("is_active", { mode: "boolean" }).notNull(),
50
+ connectionState: text("connection_state").$type().notNull(),
51
+ lastConnectedAt: integer("last_connected_at", { mode: "number" }),
52
+ lastSyncAt: integer("last_sync_at", { mode: "number" }),
53
+ lastError: nullableText("last_error"),
54
+ syncPhase: text("sync_phase").$type(),
55
+ mailboxCountTotal: nullableInteger("mailbox_count_total"),
56
+ mailboxCountSynced: nullableInteger("mailbox_count_synced"),
57
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
58
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
59
+ deletedAt: integer("deleted_at", { mode: "number" }),
60
+ }, (table) => [
61
+ index("account_by_account_config_id").on(table.accountConfigId, table.accountId),
62
+ ]);
63
+ export const mailboxes = sqliteTable("mailbox", {
64
+ mailboxId: text("mailbox_id").primaryKey().$defaultFn(() => generateBase36Id()),
65
+ accountId: text("account_id").notNull(),
66
+ namespaceType: text("namespace_type").$type().notNull().default("personal"),
67
+ namespacePrefix: text("namespace_prefix").notNull(),
68
+ hierarchyDelimiter: text("hierarchy_delimiter").notNull(),
69
+ fullPath: text("full_path").notNull(),
70
+ uidValidity: integer("uid_validity", { mode: "number" }).notNull(),
71
+ uidNext: integer("uid_next", { mode: "number" }).notNull(),
72
+ highestModseq: integer("highest_modseq", { mode: "number" }).notNull(),
73
+ messageCount: integer("message_count").notNull(),
74
+ unseenCount: integer("unseen_count").notNull(),
75
+ deletedCount: integer("deleted_count").notNull(),
76
+ totalSize: integer("total_size", { mode: "number" }).notNull(),
77
+ lastSyncUid: integer("last_sync_uid", { mode: "number" }).notNull(),
78
+ highWaterMarkUid: integer("high_water_mark_uid", { mode: "number" }).notNull(),
79
+ lastMessageSyncAt: integer("last_message_sync_at", { mode: "number" }).notNull(),
80
+ initialSyncCompletedAt: integer("initial_sync_completed_at", { mode: "number" }),
81
+ parentMailboxId: text("parent_mailbox_id").notNull().default("None"),
82
+ syncStatus: text("sync_status").$type(),
83
+ cursorState: text("cursor_state").$type().notNull().default("normal"),
84
+ oldPath: nullableText("old_path"),
85
+ specialUse: text("special_use", { mode: "json" }),
86
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
87
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
88
+ }, (table) => [
89
+ index("mailbox_by_account_id").on(table.accountId),
90
+ ]);
91
+ export const filters = sqliteTable("filter", {
92
+ filterId: text("filter_id").primaryKey().$defaultFn(() => generateBase36Id()),
93
+ accountConfigId: text("account_config_id").notNull(),
94
+ name: text("name").notNull(),
95
+ scope: text("scope").$type().notNull(),
96
+ expiresAt: nullableText("expires_at"),
97
+ ttl: integer("ttl", { mode: "number" }),
98
+ state: text("state").$type().notNull().default("Active"),
99
+ hasAnchor: integer("has_anchor", { mode: "boolean" }).notNull().default(false),
100
+ ruleChangedAt: integer("rule_changed_at", { mode: "number" }).notNull(),
101
+ matchOperator: text("match_operator").$type().notNull().default("And"),
102
+ literalClauses: text("literal_clauses", { mode: "json" }).notNull(),
103
+ actionLabelId: text("action_label_id").notNull().default("None"),
104
+ actionMailboxId: text("action_mailbox_id").notNull().default("None"),
105
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
106
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
107
+ }, (table) => [
108
+ index("filter_by_account_and_state").on(table.accountConfigId, table.state, table.filterId),
109
+ index("filter_primary").on(table.accountConfigId, table.filterId),
110
+ ]);
111
+ export const organizeJobRequests = sqliteTable("organize_job_request", {
112
+ organizeJobId: text("organize_job_id").primaryKey().$defaultFn(() => generateBase36Id()),
113
+ accountConfigId: text("account_config_id").notNull(),
114
+ userId: text("user_id").notNull(),
115
+ state: text("state").$type().notNull().default("Pending"),
116
+ anchorMessageId: text("anchor_message_id").notNull().default("None"),
117
+ matchOperator: text("match_operator").$type().notNull().default("And"),
118
+ literalClauses: text("literal_clauses", { mode: "json" }).notNull(),
119
+ similarityThreshold: real("similarity_threshold").notNull(),
120
+ actionLabelId: text("action_label_id").notNull().default("None"),
121
+ actionMailboxId: text("action_mailbox_id").notNull().default("None"),
122
+ matchedCount: integer("matched_count").notNull(),
123
+ appliedCount: integer("applied_count").notNull(),
124
+ failedCount: integer("failed_count").notNull(),
125
+ errorMessage: text("error_message").notNull().default(""),
126
+ ttl: integer("ttl", { mode: "number" }).notNull(),
127
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
128
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
129
+ }, (table) => [
130
+ index("organize_job_request_by_account_config_id").on(table.accountConfigId, table.createdAt),
131
+ ]);
132
+ export const threadMessages = sqliteTable("thread_message", {
133
+ threadMessageId: text("thread_message_id").primaryKey().$defaultFn(() => generateBase36Id()),
134
+ threadId: text("thread_id").notNull(),
135
+ messageId: text("message_id").notNull(),
136
+ accountConfigId: text("account_config_id").notNull(),
137
+ mailboxId: text("mailbox_id").notNull(),
138
+ uid: integer("uid", { mode: "number" }).notNull(),
139
+ messageIdHeader: nullableText("message_id_header"),
140
+ inReplyTo: nullableText("in_reply_to"),
141
+ referenceOrder: integer("reference_order").notNull(),
142
+ fromEmail: nullableText("from_email"),
143
+ fromName: nullableText("from_name"),
144
+ subject: nullableText("subject"),
145
+ internalDate: integer("internal_date", { mode: "number" }).notNull(),
146
+ sentDate: integer("sent_date", { mode: "number" }).notNull(),
147
+ isRead: integer("is_read", { mode: "boolean" }).notNull(),
148
+ hasAttachment: integer("has_attachment", { mode: "boolean" }).notNull(),
149
+ star: text("star").$type().notNull().default("none"),
150
+ hasStars: integer("has_stars", { mode: "boolean" }).notNull(),
151
+ isDeleted: integer("is_deleted", { mode: "boolean" }).notNull(),
152
+ snippet: nullableText("snippet"),
153
+ category: text("category").$type().notNull().default("uncategorized"),
154
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
155
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
156
+ }, (table) => [
157
+ index("thread_message_by_mailbox_and_read_status").on(table.accountConfigId, table.mailboxId, table.isRead, table.sentDate),
158
+ index("thread_message_by_starred").on(table.accountConfigId, table.hasStars, table.sentDate),
159
+ index("thread_message_by_attachment").on(table.accountConfigId, table.hasAttachment, table.sentDate),
160
+ index("thread_message_by_mailbox_id").on(table.accountConfigId, table.mailboxId, table.sentDate),
161
+ index("thread_message_by_date").on(table.accountConfigId, table.sentDate),
162
+ index("thread_message_by_unread").on(table.accountConfigId, table.isRead, table.sentDate),
163
+ index("thread_message_by_message_id").on(table.messageId),
164
+ index("thread_message_by_thread_id").on(table.threadId, table.sentDate),
165
+ index("thread_message_primary").on(table.accountConfigId, table.threadMessageId),
166
+ ]);
167
+ export const outboxMessages = sqliteTable("outbox_message", {
168
+ outboxMessageId: text("outbox_message_id").primaryKey().$defaultFn(() => generateBase36Id()),
169
+ accountId: text("account_id").notNull(),
170
+ accountConfigId: text("account_config_id").notNull(),
171
+ fromAddress: text("from_address").notNull(),
172
+ fromName: nullableText("from_name"),
173
+ toAddresses: text("to_addresses", { mode: "json" }).notNull(),
174
+ ccAddresses: text("cc_addresses", { mode: "json" }).notNull(),
175
+ bccAddresses: text("bcc_addresses", { mode: "json" }).notNull(),
176
+ replyToAddress: nullableText("reply_to_address"),
177
+ subject: nullableText("subject"),
178
+ messageIdValue: text("message_id_value").notNull(),
179
+ inReplyTo: nullableText("in_reply_to"),
180
+ references: text("references", { mode: "json" }).notNull(),
181
+ textBody: nullableText("text_body"),
182
+ htmlBody: nullableText("html_body"),
183
+ status: text("status").$type().notNull(),
184
+ lastError: nullableText("last_error"),
185
+ lastSmtpCode: nullableInteger("last_smtp_code"),
186
+ sentAt: integer("sent_at", { mode: "number" }),
187
+ smtpMessageId: nullableText("smtp_message_id"),
188
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
189
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
190
+ }, (table) => [
191
+ index("outbox_message_by_account_id").on(table.accountId, table.createdAt),
192
+ ]);
193
+ export const addresses = sqliteTable("address", {
194
+ addressId: text("address_id").primaryKey().$defaultFn(() => generateBase36Id()),
195
+ accountConfigId: text("account_config_id").notNull(),
196
+ displayName: nullableText("display_name"),
197
+ localPart: text("local_part").notNull(),
198
+ domain: text("domain").notNull(),
199
+ normalizedEmail: text("normalized_email").notNull(),
200
+ normalizedCompound: text("normalized_compound").notNull(),
201
+ flags: text("flags", { mode: "json" }).notNull(),
202
+ inboundCount: integer("inbound_count").notNull(),
203
+ outboundCount: integer("outbound_count").notNull(),
204
+ replyCount: integer("reply_count").notNull(),
205
+ lastInboundAt: integer("last_inbound_at", { mode: "number" }).notNull(),
206
+ lastOutboundAt: integer("last_outbound_at", { mode: "number" }),
207
+ lastReplyAt: integer("last_reply_at", { mode: "number" }).notNull(),
208
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
209
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
210
+ }, (table) => [
211
+ index("address_by_account_config_id").on(table.accountConfigId, table.normalizedCompound),
212
+ ]);
213
+ export const messages = sqliteTable("message", {
214
+ messageId: text("message_id").primaryKey().$defaultFn(() => generateBase36Id()),
215
+ mailboxId: text("mailbox_id").notNull(),
216
+ uid: integer("uid", { mode: "number" }).notNull(),
217
+ sequenceNumber: integer("sequence_number").notNull(),
218
+ rfc822Size: integer("rfc822_size", { mode: "number" }).notNull(),
219
+ internalDate: integer("internal_date", { mode: "number" }).notNull(),
220
+ messageIdHeader: nullableText("message_id_header"),
221
+ envelopeId: text("envelope_id").notNull(),
222
+ rootBodyPartId: text("root_body_part_id").notNull(),
223
+ bodyStorageKey: nullableText("body_storage_key"),
224
+ status: text("status").$type().notNull().default("active"),
225
+ syncStatus: text("sync_status").$type().notNull().default("synced"),
226
+ originalMailboxId: nullableText("original_mailbox_id"),
227
+ originalUid: integer("original_uid", { mode: "number" }),
228
+ category: text("category").$type().notNull().default("uncategorized"),
229
+ authenticity: text("authenticity", { mode: "json" }),
230
+ authResult: text("auth_result", { mode: "json" }),
231
+ providerSpam: text("provider_spam", { mode: "json" }),
232
+ hasListUnsubscribe: integer("has_list_unsubscribe", { mode: "boolean" }).notNull().default(false),
233
+ movedByRemit: integer("moved_by_remit", { mode: "boolean" }).notNull().default(false),
234
+ placementVerdict: text("placement_verdict", { mode: "json" }),
235
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
236
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
237
+ }, (table) => [
238
+ index("message_by_mailbox_id").on(table.mailboxId, table.uid),
239
+ ]);
240
+ export const bodyParts = sqliteTable("body_part", {
241
+ bodyPartId: text("body_part_id").primaryKey().$defaultFn(() => generateBase36Id()),
242
+ messageId: text("message_id").notNull(),
243
+ parentBodyPartId: nullableText("parent_body_part_id"),
244
+ partPath: text("part_path").notNull(),
245
+ mediaType: text("media_type").$type().notNull(),
246
+ mediaSubtype: text("media_subtype").notNull(),
247
+ contentId: nullableText("content_id"),
248
+ contentDescription: nullableText("content_description"),
249
+ transferEncoding: text("transfer_encoding").$type().notNull(),
250
+ sizeOctets: integer("size_octets", { mode: "number" }).notNull(),
251
+ lineCount: nullableInteger("line_count"),
252
+ md5Hash: nullableText("md5_hash"),
253
+ disposition: text("disposition").$type(),
254
+ dispositionFilename: nullableText("disposition_filename"),
255
+ language: nullableText("language"),
256
+ location: nullableText("location"),
257
+ isMultipart: integer("is_multipart", { mode: "boolean" }).notNull(),
258
+ multipartSubtype: text("multipart_subtype").$type(),
259
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
260
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
261
+ }, (table) => [
262
+ index("body_part_by_message_id").on(table.messageId, table.bodyPartId),
263
+ ]);
264
+ export const messageReferences = sqliteTable("message_reference", {
265
+ messageReferenceId: text("message_reference_id").primaryKey().$defaultFn(() => generateBase36Id()),
266
+ messageId: text("message_id").notNull(),
267
+ envelopeId: text("envelope_id").notNull(),
268
+ messageIdValue: text("message_id_value").notNull(),
269
+ referenceType: text("reference_type").$type().notNull(),
270
+ referenceOrder: integer("reference_order").notNull(),
271
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
272
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
273
+ }, (table) => [
274
+ index("message_reference_by_message_id").on(table.messageId, table.messageReferenceId),
275
+ ]);
276
+ export const envelopeAddresses = sqliteTable("envelope_address", {
277
+ envelopeAddressId: text("envelope_address_id").primaryKey().$defaultFn(() => generateBase36Id()),
278
+ messageId: text("message_id").notNull(),
279
+ addressId: text("address_id").notNull(),
280
+ displayName: nullableText("display_name"),
281
+ normalizedEmail: text("normalized_email").notNull(),
282
+ addressRole: text("address_role").$type().notNull(),
283
+ addressOrder: integer("address_order").notNull(),
284
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
285
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
286
+ }, (table) => [
287
+ index("envelope_address_by_message_id").on(table.messageId, table.envelopeAddressId),
288
+ ]);
289
+ export const accountSettings = sqliteTable("account_setting", {
290
+ accountSettingId: text("account_setting_id").primaryKey().$defaultFn(() => generateBase36Id()),
291
+ accountConfigId: text("account_config_id").notNull(),
292
+ name: text("name").notNull(),
293
+ value: text("value", { mode: "json" }).notNull(),
294
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
295
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
296
+ }, (table) => [
297
+ index("account_setting_by_account_config_id").on(table.accountConfigId, table.name),
298
+ ]);
299
+ export const mailboxAttributeEntries = sqliteTable("mailbox_attribute_entry", {
300
+ mailboxAttributeId: text("mailbox_attribute_id").primaryKey().$defaultFn(() => generateBase36Id()),
301
+ mailboxId: text("mailbox_id").notNull(),
302
+ attributeName: text("attribute_name").$type().notNull(),
303
+ }, (table) => [
304
+ index("mailbox_attribute_entry_by_mailbox_id").on(table.mailboxId, table.mailboxAttributeId),
305
+ ]);
306
+ export const mailboxSpecialUseEntries = sqliteTable("mailbox_special_use_entry", {
307
+ mailboxSpecialUseId: text("mailbox_special_use_id").primaryKey().$defaultFn(() => generateBase36Id()),
308
+ mailboxId: text("mailbox_id").notNull(),
309
+ specialUse: text("special_use").$type().notNull(),
310
+ }, (table) => [
311
+ index("mailbox_special_use_entry_by_mailbox_id").on(table.mailboxId, table.mailboxSpecialUseId),
312
+ ]);
313
+ export const mailboxFlags = sqliteTable("mailbox_flag", {
314
+ mailboxFlagId: text("mailbox_flag_id").primaryKey().$defaultFn(() => generateBase36Id()),
315
+ mailboxId: text("mailbox_id").notNull(),
316
+ flagName: text("flag_name").notNull(),
317
+ isPermanent: integer("is_permanent", { mode: "boolean" }).notNull(),
318
+ }, (table) => [
319
+ index("mailbox_flag_by_mailbox_id").on(table.mailboxId, table.mailboxFlagId),
320
+ ]);
321
+ export const mailboxLocks = sqliteTable("mailbox_lock", {
322
+ mailboxId: text("mailbox_id").notNull(),
323
+ eventName: text("event_name").notNull(),
324
+ accountId: text("account_id").notNull(),
325
+ lockId: text("lock_id").notNull(),
326
+ acquiredAt: integer("acquired_at", { mode: "number" }).notNull(),
327
+ lockedBy: text("locked_by").notNull(),
328
+ ttl: integer("ttl", { mode: "number" }).notNull(),
329
+ }, (table) => [
330
+ primaryKey({ name: "mailbox_lock_pk", columns: [table.mailboxId, table.eventName] }),
331
+ index("mailbox_lock_all_locks").on(table.acquiredAt),
332
+ index("mailbox_lock_by_account_id").on(table.accountId, table.mailboxId, table.eventName),
333
+ ]);
334
+ export const messageFlags = sqliteTable("message_flag", {
335
+ messageFlagId: text("message_flag_id").primaryKey().$defaultFn(() => generateBase36Id()),
336
+ messageId: text("message_id").notNull(),
337
+ flagName: text("flag_name").notNull(),
338
+ setAt: integer("set_at", { mode: "number" }).notNull(),
339
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
340
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
341
+ }, (table) => [
342
+ index("message_flag_by_message_id").on(table.messageId, table.messageFlagId),
343
+ ]);
344
+ export const messagePlacementMoves = sqliteTable("message_placement_move", {
345
+ messageId: text("message_id").primaryKey().$defaultFn(() => generateBase36Id()),
346
+ accountId: text("account_id").notNull(),
347
+ accountConfigId: text("account_config_id").notNull(),
348
+ sourceMailboxId: text("source_mailbox_id").notNull(),
349
+ destinationMailboxId: text("destination_mailbox_id").notNull(),
350
+ state: text("state").$type().notNull().default("pending"),
351
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
352
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
353
+ }, (table) => [
354
+ index("message_placement_move_by_account_id").on(table.accountId, table.messageId),
355
+ ]);
356
+ export const messageFlagPushes = sqliteTable("message_flag_push", {
357
+ messageId: text("message_id").notNull(),
358
+ flagName: text("flag_name").notNull(),
359
+ accountId: text("account_id").notNull(),
360
+ accountConfigId: text("account_config_id").notNull(),
361
+ mailboxId: text("mailbox_id").notNull(),
362
+ operation: text("operation").$type().notNull(),
363
+ state: text("state").$type().notNull().default("pending"),
364
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
365
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
366
+ }, (table) => [
367
+ primaryKey({ name: "message_flag_push_pk", columns: [table.messageId, table.flagName] }),
368
+ index("message_flag_push_by_mailbox_id").on(table.mailboxId, table.messageId, table.flagName),
369
+ index("message_flag_push_by_account_id").on(table.accountId, table.messageId, table.flagName),
370
+ ]);
371
+ export const envelopes = sqliteTable("envelope", {
372
+ envelopeId: text("envelope_id").primaryKey().$defaultFn(() => generateBase36Id()),
373
+ messageId: text("message_id").notNull(),
374
+ dateValue: integer("date_value", { mode: "number" }).notNull(),
375
+ dateRaw: text("date_raw").notNull(),
376
+ subject: nullableText("subject"),
377
+ messageIdValue: nullableText("message_id_value"),
378
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
379
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
380
+ }, (table) => [
381
+ index("envelope_by_message_id").on(table.messageId, table.envelopeId),
382
+ ]);
383
+ export const bodyPartParameters = sqliteTable("body_part_parameter", {
384
+ bodyPartParameterId: text("body_part_parameter_id").primaryKey().$defaultFn(() => generateBase36Id()),
385
+ messageId: text("message_id").notNull(),
386
+ bodyPartId: text("body_part_id").notNull(),
387
+ parameterName: text("parameter_name").notNull(),
388
+ parameterValue: text("parameter_value").notNull(),
389
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
390
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
391
+ }, (table) => [
392
+ index("body_part_parameter_by_message_id").on(table.messageId, table.bodyPartParameterId),
393
+ ]);
394
+ export const rawMessageStorages = sqliteTable("raw_message_storage", {
395
+ rawStorageId: text("raw_storage_id").primaryKey().$defaultFn(() => generateBase36Id()),
396
+ messageId: text("message_id").notNull(),
397
+ storageType: text("storage_type").$type().notNull(),
398
+ storageLocation: text("storage_location").notNull(),
399
+ storageKey: text("storage_key").notNull(),
400
+ sizeBytes: integer("size_bytes", { mode: "number" }).notNull(),
401
+ checksumSha256: text("checksum_sha256").notNull(),
402
+ contentEncoding: text("content_encoding").$type().notNull(),
403
+ storedAt: integer("stored_at", { mode: "number" }).notNull(),
404
+ expiresAt: integer("expires_at", { mode: "number" }),
405
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
406
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
407
+ }, (table) => [
408
+ index("raw_message_storage_by_message_id").on(table.messageId, table.rawStorageId),
409
+ ]);
410
+ export const bodyPartStorages = sqliteTable("body_part_storage", {
411
+ bodyPartStorageId: text("body_part_storage_id").primaryKey().$defaultFn(() => generateBase36Id()),
412
+ messageId: text("message_id").notNull(),
413
+ bodyPartId: text("body_part_id").notNull(),
414
+ storageType: text("storage_type").$type().notNull(),
415
+ storageLocation: text("storage_location").notNull(),
416
+ storageKey: text("storage_key").notNull(),
417
+ decodedSizeBytes: integer("decoded_size_bytes", { mode: "number" }).notNull(),
418
+ checksumSha256: text("checksum_sha256").notNull(),
419
+ contentEncoding: text("content_encoding").$type().notNull(),
420
+ isDeduped: integer("is_deduped", { mode: "boolean" }).notNull(),
421
+ dedupHash: nullableText("dedup_hash"),
422
+ storedAt: integer("stored_at", { mode: "number" }).notNull(),
423
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
424
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
425
+ }, (table) => [
426
+ index("body_part_storage_by_message_id").on(table.messageId, table.bodyPartStorageId),
427
+ ]);
428
+ export const bodyPartContents = sqliteTable("body_part_content", {
429
+ bodyPartContentId: text("body_part_content_id").primaryKey().$defaultFn(() => generateBase36Id()),
430
+ messageId: text("message_id").notNull(),
431
+ bodyPartId: text("body_part_id").notNull(),
432
+ content: text("content").notNull(),
433
+ contentLength: integer("content_length", { mode: "number" }).notNull(),
434
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
435
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
436
+ }, (table) => [
437
+ index("body_part_content_by_message_id").on(table.messageId, table.bodyPartContentId),
438
+ ]);
439
+ export const labels = sqliteTable("label", {
440
+ labelId: text("label_id").primaryKey().$defaultFn(() => generateBase36Id()),
441
+ accountConfigId: text("account_config_id").notNull(),
442
+ name: text("name").notNull(),
443
+ normalizedName: text("normalized_name").notNull(),
444
+ color: text("color").$type().notNull().default("Default"),
445
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
446
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
447
+ }, (table) => [
448
+ index("label_by_normalized_name").on(table.accountConfigId, table.normalizedName),
449
+ index("label_primary").on(table.accountConfigId, table.labelId),
450
+ ]);
451
+ export const messageLabels = sqliteTable("message_label", {
452
+ messageLabelId: text("message_label_id").primaryKey().$defaultFn(() => generateBase36Id()),
453
+ messageId: text("message_id").notNull(),
454
+ labelId: text("label_id").notNull(),
455
+ accountConfigId: text("account_config_id").notNull(),
456
+ appliedByFilterId: nullableText("applied_by_filter_id"),
457
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
458
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
459
+ }, (table) => [
460
+ index("message_label_by_label_id").on(table.accountConfigId, table.labelId, table.createdAt),
461
+ index("message_label_by_message_id").on(table.messageId, table.labelId),
462
+ ]);
463
+ export const filterAnchors = sqliteTable("filter_anchor", {
464
+ accountConfigId: text("account_config_id").notNull(),
465
+ filterId: text("filter_id").notNull(),
466
+ anchorEmbedding: text("anchor_embedding", { mode: "json" }).notNull(),
467
+ anchorEmbeddingId: text("anchor_embedding_id").notNull(),
468
+ anchorSourceText: text("anchor_source_text").notNull(),
469
+ anchorMessageId: text("anchor_message_id").notNull(),
470
+ createdAt: integer("created_at", { mode: "number" }).notNull(),
471
+ updatedAt: integer("updated_at", { mode: "number" }).notNull(),
472
+ }, (table) => [
473
+ primaryKey({ name: "filter_anchor_pk", columns: [table.accountConfigId, table.filterId] }),
474
+ ]);
@@ -0,0 +1,106 @@
1
+ /** UUID column stored as text, reads/writes as base36 */
2
+ export declare const base36Uuid: {
3
+ (): import("drizzle-orm/sqlite-core").SQLiteCustomColumnBuilder<{
4
+ name: "";
5
+ dataType: "custom";
6
+ columnType: "SQLiteCustomColumn";
7
+ data: string;
8
+ driverParam: string;
9
+ enumValues: undefined;
10
+ }>;
11
+ <TConfig extends Record<string, any>>(fieldConfig?: TConfig): import("drizzle-orm/sqlite-core").SQLiteCustomColumnBuilder<{
12
+ name: "";
13
+ dataType: "custom";
14
+ columnType: "SQLiteCustomColumn";
15
+ data: string;
16
+ driverParam: string;
17
+ enumValues: undefined;
18
+ }>;
19
+ <TName extends string>(dbName: TName, fieldConfig?: unknown): import("drizzle-orm/sqlite-core").SQLiteCustomColumnBuilder<{
20
+ name: TName;
21
+ dataType: "custom";
22
+ columnType: "SQLiteCustomColumn";
23
+ data: string;
24
+ driverParam: string;
25
+ enumValues: undefined;
26
+ }>;
27
+ };
28
+ export declare function generateBase36Id(): string;
29
+ export declare const nullableText: {
30
+ (): import("drizzle-orm/sqlite-core").SQLiteCustomColumnBuilder<{
31
+ name: "";
32
+ dataType: "custom";
33
+ columnType: "SQLiteCustomColumn";
34
+ data: string;
35
+ driverParam: string;
36
+ enumValues: undefined;
37
+ }>;
38
+ <TConfig extends Record<string, any>>(fieldConfig?: TConfig): import("drizzle-orm/sqlite-core").SQLiteCustomColumnBuilder<{
39
+ name: "";
40
+ dataType: "custom";
41
+ columnType: "SQLiteCustomColumn";
42
+ data: string;
43
+ driverParam: string;
44
+ enumValues: undefined;
45
+ }>;
46
+ <TName extends string>(dbName: TName, fieldConfig?: unknown): import("drizzle-orm/sqlite-core").SQLiteCustomColumnBuilder<{
47
+ name: TName;
48
+ dataType: "custom";
49
+ columnType: "SQLiteCustomColumn";
50
+ data: string;
51
+ driverParam: string;
52
+ enumValues: undefined;
53
+ }>;
54
+ };
55
+ export declare const nullableInteger: {
56
+ (): import("drizzle-orm/sqlite-core").SQLiteCustomColumnBuilder<{
57
+ name: "";
58
+ dataType: "custom";
59
+ columnType: "SQLiteCustomColumn";
60
+ data: number;
61
+ driverParam: number;
62
+ enumValues: undefined;
63
+ }>;
64
+ <TConfig extends Record<string, any>>(fieldConfig?: TConfig): import("drizzle-orm/sqlite-core").SQLiteCustomColumnBuilder<{
65
+ name: "";
66
+ dataType: "custom";
67
+ columnType: "SQLiteCustomColumn";
68
+ data: number;
69
+ driverParam: number;
70
+ enumValues: undefined;
71
+ }>;
72
+ <TName extends string>(dbName: TName, fieldConfig?: unknown): import("drizzle-orm/sqlite-core").SQLiteCustomColumnBuilder<{
73
+ name: TName;
74
+ dataType: "custom";
75
+ columnType: "SQLiteCustomColumn";
76
+ data: number;
77
+ driverParam: number;
78
+ enumValues: undefined;
79
+ }>;
80
+ };
81
+ export declare const nullableReal: {
82
+ (): import("drizzle-orm/sqlite-core").SQLiteCustomColumnBuilder<{
83
+ name: "";
84
+ dataType: "custom";
85
+ columnType: "SQLiteCustomColumn";
86
+ data: number;
87
+ driverParam: number;
88
+ enumValues: undefined;
89
+ }>;
90
+ <TConfig extends Record<string, any>>(fieldConfig?: TConfig): import("drizzle-orm/sqlite-core").SQLiteCustomColumnBuilder<{
91
+ name: "";
92
+ dataType: "custom";
93
+ columnType: "SQLiteCustomColumn";
94
+ data: number;
95
+ driverParam: number;
96
+ enumValues: undefined;
97
+ }>;
98
+ <TName extends string>(dbName: TName, fieldConfig?: unknown): import("drizzle-orm/sqlite-core").SQLiteCustomColumnBuilder<{
99
+ name: TName;
100
+ dataType: "custom";
101
+ columnType: "SQLiteCustomColumn";
102
+ data: number;
103
+ driverParam: number;
104
+ enumValues: undefined;
105
+ }>;
106
+ };
package/dist/types.js ADDED
@@ -0,0 +1,24 @@
1
+ import { customType } from "drizzle-orm/sqlite-core";
2
+ import short from "short-uuid";
3
+ const translator = short(short.constants.uuid25Base36);
4
+ /** UUID column stored as text, reads/writes as base36 */
5
+ export const base36Uuid = customType({
6
+ dataType: () => "text",
7
+ toDriver: (value) => translator.toUUID(value),
8
+ fromDriver: (value) => translator.fromUUID(value),
9
+ });
10
+ export function generateBase36Id() {
11
+ return translator.new();
12
+ }
13
+ export const nullableText = customType({
14
+ dataType: () => "text",
15
+ fromDriver: (v) => v ?? undefined,
16
+ });
17
+ export const nullableInteger = customType({
18
+ dataType: () => "integer",
19
+ fromDriver: (v) => v ?? undefined,
20
+ });
21
+ export const nullableReal = customType({
22
+ dataType: () => "real",
23
+ fromDriver: (v) => v ?? undefined,
24
+ });
package/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./types.js";
2
+ export * from "./schema.js";
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@remit/drizzle-sqlite-schema",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "prepare": "tsc"
17
+ },
18
+ "dependencies": {
19
+ "short-uuid": "^5.2.0"
20
+ },
21
+ "peerDependencies": {
22
+ "drizzle-orm": ">=0.30.0",
23
+ "typescript": ">=5.0.0"
24
+ },
25
+ "license": "MIT",
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/remit-mail/reader.git"
32
+ }
33
+ }