@serve.zone/coremail 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/.smartconfig.json +50 -0
  2. package/changelog.md +10 -0
  3. package/cli.js +4 -0
  4. package/dist_ts/00_commitinfo_data.d.ts +8 -0
  5. package/dist_ts/00_commitinfo_data.js +9 -0
  6. package/dist_ts/classes.auth.d.ts +45 -0
  7. package/dist_ts/classes.auth.js +204 -0
  8. package/dist_ts/classes.config.d.ts +2 -0
  9. package/dist_ts/classes.config.js +72 -0
  10. package/dist_ts/classes.coremail.d.ts +41 -0
  11. package/dist_ts/classes.coremail.js +155 -0
  12. package/dist_ts/classes.desiredstate.d.ts +40 -0
  13. package/dist_ts/classes.desiredstate.js +382 -0
  14. package/dist_ts/classes.gateway.d.ts +62 -0
  15. package/dist_ts/classes.gateway.js +669 -0
  16. package/dist_ts/classes.inbound.d.ts +49 -0
  17. package/dist_ts/classes.inbound.js +702 -0
  18. package/dist_ts/classes.maintenance.d.ts +16 -0
  19. package/dist_ts/classes.maintenance.js +339 -0
  20. package/dist_ts/classes.models.d.ts +161 -0
  21. package/dist_ts/classes.models.js +595 -0
  22. package/dist_ts/classes.server.d.ts +40 -0
  23. package/dist_ts/classes.server.js +309 -0
  24. package/dist_ts/classes.storage.d.ts +32 -0
  25. package/dist_ts/classes.storage.js +317 -0
  26. package/dist_ts/classes.submissions.d.ts +33 -0
  27. package/dist_ts/classes.submissions.js +385 -0
  28. package/dist_ts/classes.transfer.d.ts +41 -0
  29. package/dist_ts/classes.transfer.js +289 -0
  30. package/dist_ts/coremail.cursor.d.ts +20 -0
  31. package/dist_ts/coremail.cursor.js +191 -0
  32. package/dist_ts/coremail.log.d.ts +3 -0
  33. package/dist_ts/coremail.log.js +11 -0
  34. package/dist_ts/coremail.mime.d.ts +8 -0
  35. package/dist_ts/coremail.mime.js +63 -0
  36. package/dist_ts/coremail.persistence.d.ts +148 -0
  37. package/dist_ts/coremail.persistence.js +695 -0
  38. package/dist_ts/coremail.quota.d.ts +29 -0
  39. package/dist_ts/coremail.quota.js +149 -0
  40. package/dist_ts/coremail.selectors.d.ts +3 -0
  41. package/dist_ts/coremail.selectors.js +21 -0
  42. package/dist_ts/coremail.validation.d.ts +9 -0
  43. package/dist_ts/coremail.validation.js +325 -0
  44. package/dist_ts/index.d.ts +4 -0
  45. package/dist_ts/index.js +39 -0
  46. package/dist_ts/interfaces.d.ts +92 -0
  47. package/dist_ts/interfaces.js +2 -0
  48. package/dist_ts/plugins.d.ts +11 -0
  49. package/dist_ts/plugins.js +12 -0
  50. package/license.md +19 -0
  51. package/package.json +48 -0
  52. package/readme.md +199 -0
  53. package/ts/00_commitinfo_data.ts +8 -0
  54. package/ts/classes.auth.ts +321 -0
  55. package/ts/classes.config.ts +104 -0
  56. package/ts/classes.coremail.ts +249 -0
  57. package/ts/classes.desiredstate.ts +508 -0
  58. package/ts/classes.gateway.ts +811 -0
  59. package/ts/classes.inbound.ts +898 -0
  60. package/ts/classes.maintenance.ts +335 -0
  61. package/ts/classes.models.ts +530 -0
  62. package/ts/classes.server.ts +444 -0
  63. package/ts/classes.storage.ts +448 -0
  64. package/ts/classes.submissions.ts +554 -0
  65. package/ts/classes.transfer.ts +379 -0
  66. package/ts/coremail.cursor.ts +328 -0
  67. package/ts/coremail.log.ts +21 -0
  68. package/ts/coremail.mime.ts +94 -0
  69. package/ts/coremail.persistence.ts +1156 -0
  70. package/ts/coremail.quota.ts +214 -0
  71. package/ts/coremail.selectors.ts +35 -0
  72. package/ts/coremail.validation.ts +446 -0
  73. package/ts/index.ts +38 -0
  74. package/ts/interfaces.ts +109 -0
  75. package/ts/plugins.ts +11 -0
@@ -0,0 +1,530 @@
1
+ import * as plugins from './plugins.js';
2
+ import type { ISubmissionPartRecord, TTransferGrantPurpose } from './interfaces.js';
3
+ import {
4
+ assertCoreMailDesiredSnapshotRecord,
5
+ assertCoreMailInboundDeliveryRecord,
6
+ assertCoreMailInboundHandoffRecord,
7
+ assertCoreMailQuotaCounterRecord,
8
+ assertCoreMailRecipientHandleRecord,
9
+ assertCoreMailStateRecord,
10
+ assertCoreMailSubmissionRecord,
11
+ assertCoreMailTransferGrantRecord,
12
+ type ICoreMailDesiredSnapshotRecord,
13
+ type ICoreMailInboundDeliveryRecord,
14
+ type ICoreMailInboundHandoffRecord,
15
+ type ICoreMailQuotaCounterRecord,
16
+ type ICoreMailRecipientHandleRecord,
17
+ type ICoreMailStateRecord,
18
+ type ICoreMailSubmissionRecord,
19
+ type ICoreMailTransferGrantRecord,
20
+ } from './coremail.persistence.js';
21
+
22
+ type TCoreMailSha256 = plugins.serveZoneInterfaces.data.TCoreMailSha256;
23
+
24
+ @plugins.smartdata.exactPersistence({
25
+ assertDocument: assertCoreMailStateRecord,
26
+ reconcileBy: 'stateId',
27
+ })
28
+ export class CoreMailStateDoc extends plugins.smartdata.SmartDataDbDoc<
29
+ CoreMailStateDoc,
30
+ ICoreMailStateRecord
31
+ > implements ICoreMailStateRecord {
32
+ declare public static exact: plugins.smartdata.TExact<CoreMailStateDoc>;
33
+ public stateId!: string;
34
+ public appliedConfigEpoch!: number;
35
+ public appliedDesiredStateDigest!: TCoreMailSha256;
36
+ public snapshotId!: string;
37
+ public updatedAt!: number;
38
+ }
39
+
40
+ @plugins.smartdata.exactPersistence({
41
+ assertDocument: assertCoreMailDesiredSnapshotRecord,
42
+ reconcileBy: 'snapshotId',
43
+ })
44
+ export class CoreMailDesiredSnapshotDoc extends plugins.smartdata.SmartDataDbDoc<
45
+ CoreMailDesiredSnapshotDoc,
46
+ ICoreMailDesiredSnapshotRecord
47
+ > implements ICoreMailDesiredSnapshotRecord {
48
+ declare public static exact:
49
+ plugins.smartdata.TExact<CoreMailDesiredSnapshotDoc>;
50
+ public snapshotId!: string;
51
+ public reconciliationId!: string;
52
+ public expectedAppliedConfigEpoch!: number;
53
+ public configEpoch!: number;
54
+ public desiredStateDigest!: TCoreMailSha256;
55
+ public lengthBytes!: number;
56
+ public objectKey!: string;
57
+ public state!: 'staged' | 'active' | 'superseded' | 'failed' | 'retiring';
58
+ public createdAt!: number;
59
+ public updatedAt!: number;
60
+ public activatedAt?: number;
61
+ public retiringAt?: number;
62
+ public errorCode?: plugins.serveZoneInterfaces.data.TCoreMailErrorCode;
63
+ }
64
+
65
+ @plugins.smartdata.exactPersistence({
66
+ assertDocument: assertCoreMailQuotaCounterRecord,
67
+ reconcileBy: 'counterId',
68
+ })
69
+ export class CoreMailQuotaCounterDoc extends plugins.smartdata.SmartDataDbDoc<
70
+ CoreMailQuotaCounterDoc,
71
+ ICoreMailQuotaCounterRecord
72
+ > implements ICoreMailQuotaCounterRecord {
73
+ declare public static exact: plugins.smartdata.TExact<CoreMailQuotaCounterDoc>;
74
+ public counterId!: TCoreMailSha256;
75
+ public tenantId!: string;
76
+ public serviceId!: string;
77
+ public bindingId!: string;
78
+ public bindingRevision!: number;
79
+ public kind!: ICoreMailQuotaCounterRecord['kind'];
80
+ public windowStartedAt?: number;
81
+ public count!: number;
82
+ public createdAt!: number;
83
+ public updatedAt!: number;
84
+ }
85
+
86
+ @plugins.smartdata.exactPersistence({
87
+ assertDocument: assertCoreMailTransferGrantRecord,
88
+ reconcileBy: 'grantId',
89
+ })
90
+ export class CoreMailTransferGrantDoc extends plugins.smartdata.SmartDataDbDoc<
91
+ CoreMailTransferGrantDoc,
92
+ ICoreMailTransferGrantRecord
93
+ > implements ICoreMailTransferGrantRecord {
94
+ declare public static exact: plugins.smartdata.TExact<CoreMailTransferGrantDoc>;
95
+ public grantId!: string;
96
+ public authorityKind!: 'control' | 'gateway' | 'workload';
97
+ public tenantId!: string;
98
+ public serviceId!: string;
99
+ public bindingId!: string;
100
+ public purpose!: TTransferGrantPurpose;
101
+ public method!: 'PUT' | 'GET';
102
+ public path!: string;
103
+ public bearerSha256!: TCoreMailSha256;
104
+ public expectedSha256!: TCoreMailSha256;
105
+ public lengthBytes!: number;
106
+ public contentType!: string;
107
+ public objectKey!: string;
108
+ public state!: 'issued' | 'transferring' | 'consumed' | 'failed' | 'expired';
109
+ public expiresAt!: number;
110
+ public createdAt!: number;
111
+ public consumedAt?: number;
112
+ }
113
+
114
+ @plugins.smartdata.exactPersistence({
115
+ assertDocument: assertCoreMailSubmissionRecord,
116
+ reconcileBy: 'submissionId',
117
+ })
118
+ export class CoreMailSubmissionDoc extends plugins.smartdata.SmartDataDbDoc<
119
+ CoreMailSubmissionDoc,
120
+ ICoreMailSubmissionRecord
121
+ > implements ICoreMailSubmissionRecord {
122
+ declare public static exact: plugins.smartdata.TExact<CoreMailSubmissionDoc>;
123
+ public submissionId!: string;
124
+ public tenantId!: string;
125
+ public serviceId!: string;
126
+ public bindingId!: string;
127
+ public bindingRevision!: number;
128
+ public revision!: number;
129
+ public idempotencyKey!: string;
130
+ public submissionDigest!: TCoreMailSha256;
131
+ public state!: plugins.serveZoneInterfaces.data.TCoreMailSubmissionState;
132
+ public message!: plugins.serveZoneInterfaces.data.ICoreMailOutboundMessageDescriptor;
133
+ public parts!: ISubmissionPartRecord[];
134
+ public mimeObjectKey?: string;
135
+ public mimeSha256?: TCoreMailSha256;
136
+ public mimeLengthBytes?: number;
137
+ public mimePublishedAt?: number;
138
+ public transportMessageId?: string;
139
+ public transportGrantId?: string;
140
+ public gatewayStatusUpdatedAt?: number;
141
+ public attempts!: number;
142
+ public nextAttemptAt?: number;
143
+ public workerRetryAt?: number;
144
+ public retiringAt?: number;
145
+ public leaseOwnerTaskId?: string;
146
+ public leaseToken?: string;
147
+ public leaseExpiresAt?: number;
148
+ public acceptedAt?: number;
149
+ public deliveredAt?: number;
150
+ public terminalAt?: number;
151
+ public error?: plugins.serveZoneInterfaces.data.ICoreMailErrorData;
152
+ public createdAt!: number;
153
+ public updatedAt!: number;
154
+ }
155
+
156
+ @plugins.smartdata.exactPersistence({
157
+ assertDocument: assertCoreMailInboundDeliveryRecord,
158
+ reconcileBy: 'deliveryId',
159
+ })
160
+ export class CoreMailInboundDeliveryDoc extends plugins.smartdata.SmartDataDbDoc<
161
+ CoreMailInboundDeliveryDoc,
162
+ ICoreMailInboundDeliveryRecord
163
+ > implements ICoreMailInboundDeliveryRecord {
164
+ declare public static exact:
165
+ plugins.smartdata.TExact<CoreMailInboundDeliveryDoc>;
166
+ public deliveryId!: string;
167
+ public tenantId!: string;
168
+ public serviceId!: string;
169
+ public bindingId!: string;
170
+ public bindingRevision!: number;
171
+ public revision!: number;
172
+ public transportDeliveryId!: string;
173
+ public state!: plugins.serveZoneInterfaces.data.TCoreMailInboundDeliveryState;
174
+ public envelope!: plugins.serveZoneInterfaces.data.ICoreMailEnvelope;
175
+ public rawMimeSha256!: TCoreMailSha256;
176
+ public rawMimeLengthBytes!: number;
177
+ public rawMimeObjectKey!: string;
178
+ public messageId?: string;
179
+ public subject?: string;
180
+ public receivedAt!: number;
181
+ public updatedAt!: number;
182
+ public fetchGrantId?: string;
183
+ public acknowledgedOutcome?: plugins.serveZoneInterfaces.data.TCoreMailInboundAckOutcome;
184
+ }
185
+
186
+ @plugins.smartdata.exactPersistence({
187
+ assertDocument: assertCoreMailRecipientHandleRecord,
188
+ reconcileBy: 'routingHandle',
189
+ })
190
+ export class CoreMailRecipientHandleDoc extends plugins.smartdata.SmartDataDbDoc<
191
+ CoreMailRecipientHandleDoc,
192
+ ICoreMailRecipientHandleRecord
193
+ > implements ICoreMailRecipientHandleRecord {
194
+ declare public static exact:
195
+ plugins.smartdata.TExact<CoreMailRecipientHandleDoc>;
196
+ public routingHandle!: string;
197
+ public tenantId!: string;
198
+ public serviceId!: string;
199
+ public bindingId!: string;
200
+ public bindingRevision!: number;
201
+ public maxPendingInbound!: number;
202
+ public recipient!: string;
203
+ public envelopeDigest!: TCoreMailSha256;
204
+ public state!: 'issued' | 'consumed' | 'expired';
205
+ public handoffId?: string;
206
+ public expiresAt!: number;
207
+ public createdAt!: number;
208
+ }
209
+
210
+ @plugins.smartdata.exactPersistence({
211
+ assertDocument: assertCoreMailInboundHandoffRecord,
212
+ reconcileBy: 'handoffId',
213
+ })
214
+ export class CoreMailInboundHandoffDoc extends plugins.smartdata.SmartDataDbDoc<
215
+ CoreMailInboundHandoffDoc,
216
+ ICoreMailInboundHandoffRecord
217
+ > implements ICoreMailInboundHandoffRecord {
218
+ declare public static exact:
219
+ plugins.smartdata.TExact<CoreMailInboundHandoffDoc>;
220
+ public handoffId!: string;
221
+ public revision!: number;
222
+ public transportDeliveryId!: string;
223
+ public routingHandles!: string[];
224
+ public message!: plugins.serveZoneInterfaces.data.ICoreMailGatewayMessageDescriptor;
225
+ public source!: plugins.serveZoneInterfaces.data.IMailConnectionInfo;
226
+ public state!: 'prepared' | 'uploaded' | 'completed' | 'failed' | 'retiring';
227
+ public objectKey!: string;
228
+ public grantId?: string;
229
+ public deliveryIds!: string[];
230
+ public createdAt!: number;
231
+ public updatedAt!: number;
232
+ public completedAt?: number;
233
+ public retiringAt?: number;
234
+ }
235
+
236
+ export interface ICoreMailModels {
237
+ State: typeof CoreMailStateDoc;
238
+ DesiredSnapshot: typeof CoreMailDesiredSnapshotDoc;
239
+ QuotaCounter: typeof CoreMailQuotaCounterDoc;
240
+ TransferGrant: typeof CoreMailTransferGrantDoc;
241
+ Submission: typeof CoreMailSubmissionDoc;
242
+ InboundDelivery: typeof CoreMailInboundDeliveryDoc;
243
+ RecipientHandle: typeof CoreMailRecipientHandleDoc;
244
+ InboundHandoff: typeof CoreMailInboundHandoffDoc;
245
+ }
246
+
247
+ const uniqueIndex = (nameArg: string, fieldArg: string) => ({
248
+ name: nameArg,
249
+ key: { [fieldArg]: 1 as const },
250
+ options: { unique: true },
251
+ });
252
+
253
+ export const createCoreMailModels = (
254
+ dbArg: plugins.smartdata.SmartdataDb,
255
+ ): ICoreMailModels => {
256
+ const bind = <
257
+ TConstructor extends new () =>
258
+ plugins.smartdata.SmartDataDbDoc<any, any>,
259
+ >(
260
+ modelArg: TConstructor,
261
+ collectionNameArg: string,
262
+ persistedFieldsArg: Array<keyof InstanceType<TConstructor> & string>,
263
+ identityFieldArg: keyof InstanceType<TConstructor> & string,
264
+ indexesArg: plugins.smartdata.ICollectionModelIndex[],
265
+ ) => plugins.smartdata.defineCollectionModel(
266
+ modelArg as unknown as new () => InstanceType<TConstructor>,
267
+ dbArg,
268
+ {
269
+ collectionName: collectionNameArg,
270
+ persistedFields: persistedFieldsArg,
271
+ identityFields: [identityFieldArg] as never,
272
+ indexes: [
273
+ uniqueIndex(`${identityFieldArg}_unique`, identityFieldArg),
274
+ ...indexesArg,
275
+ ],
276
+ },
277
+ ) as unknown as TConstructor;
278
+
279
+ return {
280
+ State: bind(CoreMailStateDoc, 'CoreMailState', [
281
+ 'stateId',
282
+ 'appliedConfigEpoch',
283
+ 'appliedDesiredStateDigest',
284
+ 'snapshotId',
285
+ 'updatedAt',
286
+ ], 'stateId', []) as typeof CoreMailStateDoc,
287
+ DesiredSnapshot: bind(CoreMailDesiredSnapshotDoc, 'CoreMailDesiredSnapshot', [
288
+ 'snapshotId',
289
+ 'reconciliationId',
290
+ 'expectedAppliedConfigEpoch',
291
+ 'configEpoch',
292
+ 'desiredStateDigest',
293
+ 'lengthBytes',
294
+ 'objectKey',
295
+ 'state',
296
+ 'createdAt',
297
+ 'updatedAt',
298
+ 'activatedAt',
299
+ 'retiringAt',
300
+ 'errorCode',
301
+ ], 'snapshotId', [
302
+ uniqueIndex('reconciliationId_unique', 'reconciliationId'),
303
+ {
304
+ name: 'config_epoch_digest',
305
+ key: { configEpoch: 1, desiredStateDigest: 1 },
306
+ options: { unique: true },
307
+ },
308
+ {
309
+ name: 'state_updated',
310
+ key: { state: 1, updatedAt: 1 },
311
+ },
312
+ ]) as typeof CoreMailDesiredSnapshotDoc,
313
+ QuotaCounter: bind(CoreMailQuotaCounterDoc, 'CoreMailQuotaCounter', [
314
+ 'counterId',
315
+ 'tenantId',
316
+ 'serviceId',
317
+ 'bindingId',
318
+ 'bindingRevision',
319
+ 'kind',
320
+ 'windowStartedAt',
321
+ 'count',
322
+ 'createdAt',
323
+ 'updatedAt',
324
+ ], 'counterId', [
325
+ {
326
+ name: 'authority_kind_unique',
327
+ key: {
328
+ tenantId: 1,
329
+ serviceId: 1,
330
+ bindingId: 1,
331
+ bindingRevision: 1,
332
+ kind: 1,
333
+ },
334
+ options: { unique: true },
335
+ },
336
+ ]) as typeof CoreMailQuotaCounterDoc,
337
+ TransferGrant: bind(CoreMailTransferGrantDoc, 'CoreMailTransferGrant', [
338
+ 'grantId',
339
+ 'authorityKind',
340
+ 'tenantId',
341
+ 'serviceId',
342
+ 'bindingId',
343
+ 'purpose',
344
+ 'method',
345
+ 'path',
346
+ 'bearerSha256',
347
+ 'expectedSha256',
348
+ 'lengthBytes',
349
+ 'contentType',
350
+ 'objectKey',
351
+ 'state',
352
+ 'expiresAt',
353
+ 'createdAt',
354
+ 'consumedAt',
355
+ ], 'grantId', [
356
+ {
357
+ name: 'authority_state_expiry',
358
+ key: {
359
+ authorityKind: 1,
360
+ tenantId: 1,
361
+ serviceId: 1,
362
+ bindingId: 1,
363
+ state: 1,
364
+ expiresAt: 1,
365
+ },
366
+ },
367
+ ]) as typeof CoreMailTransferGrantDoc,
368
+ Submission: bind(CoreMailSubmissionDoc, 'CoreMailSubmission', [
369
+ 'submissionId',
370
+ 'tenantId',
371
+ 'serviceId',
372
+ 'bindingId',
373
+ 'bindingRevision',
374
+ 'revision',
375
+ 'idempotencyKey',
376
+ 'submissionDigest',
377
+ 'state',
378
+ 'message',
379
+ 'parts',
380
+ 'mimeObjectKey',
381
+ 'mimeSha256',
382
+ 'mimeLengthBytes',
383
+ 'mimePublishedAt',
384
+ 'transportMessageId',
385
+ 'transportGrantId',
386
+ 'gatewayStatusUpdatedAt',
387
+ 'attempts',
388
+ 'nextAttemptAt',
389
+ 'workerRetryAt',
390
+ 'retiringAt',
391
+ 'leaseOwnerTaskId',
392
+ 'leaseToken',
393
+ 'leaseExpiresAt',
394
+ 'acceptedAt',
395
+ 'deliveredAt',
396
+ 'terminalAt',
397
+ 'error',
398
+ 'createdAt',
399
+ 'updatedAt',
400
+ ], 'submissionId', [
401
+ {
402
+ name: 'authority_idempotency_unique',
403
+ key: {
404
+ tenantId: 1,
405
+ serviceId: 1,
406
+ bindingId: 1,
407
+ bindingRevision: 1,
408
+ idempotencyKey: 1,
409
+ },
410
+ options: { unique: true },
411
+ },
412
+ {
413
+ name: 'queue_claim',
414
+ key: { state: 1, workerRetryAt: 1, nextAttemptAt: 1, leaseExpiresAt: 1 },
415
+ options: { sparse: true },
416
+ },
417
+ {
418
+ name: 'transport_message_unique',
419
+ key: { transportMessageId: 1 },
420
+ options: { unique: true, sparse: true },
421
+ },
422
+ {
423
+ name: 'transport_grant_unique',
424
+ key: { transportGrantId: 1 },
425
+ options: { unique: true, sparse: true },
426
+ },
427
+ {
428
+ name: 'state_terminal',
429
+ key: { state: 1, terminalAt: 1 },
430
+ options: { sparse: true },
431
+ },
432
+ {
433
+ name: 'state_updated',
434
+ key: { state: 1, updatedAt: 1 },
435
+ },
436
+ ]) as typeof CoreMailSubmissionDoc,
437
+ InboundDelivery: bind(CoreMailInboundDeliveryDoc, 'CoreMailInboundDelivery', [
438
+ 'deliveryId',
439
+ 'tenantId',
440
+ 'serviceId',
441
+ 'bindingId',
442
+ 'bindingRevision',
443
+ 'revision',
444
+ 'transportDeliveryId',
445
+ 'state',
446
+ 'envelope',
447
+ 'rawMimeSha256',
448
+ 'rawMimeLengthBytes',
449
+ 'rawMimeObjectKey',
450
+ 'messageId',
451
+ 'subject',
452
+ 'receivedAt',
453
+ 'updatedAt',
454
+ 'fetchGrantId',
455
+ 'acknowledgedOutcome',
456
+ ], 'deliveryId', [
457
+ {
458
+ name: 'authority_delivery',
459
+ key: { tenantId: 1, serviceId: 1, bindingId: 1, receivedAt: 1, deliveryId: 1 },
460
+ },
461
+ {
462
+ name: 'transport_binding_unique',
463
+ key: { transportDeliveryId: 1, bindingId: 1, bindingRevision: 1 },
464
+ options: { unique: true },
465
+ },
466
+ {
467
+ name: 'state_updated',
468
+ key: { state: 1, updatedAt: 1 },
469
+ },
470
+ {
471
+ name: 'raw_mime_retention',
472
+ key: { rawMimeObjectKey: 1, state: 1, updatedAt: 1 },
473
+ },
474
+ ]) as typeof CoreMailInboundDeliveryDoc,
475
+ RecipientHandle: bind(CoreMailRecipientHandleDoc, 'CoreMailRecipientHandle', [
476
+ 'routingHandle',
477
+ 'tenantId',
478
+ 'serviceId',
479
+ 'bindingId',
480
+ 'bindingRevision',
481
+ 'maxPendingInbound',
482
+ 'recipient',
483
+ 'envelopeDigest',
484
+ 'state',
485
+ 'handoffId',
486
+ 'expiresAt',
487
+ 'createdAt',
488
+ ], 'routingHandle', [
489
+ {
490
+ name: 'state_expiry',
491
+ key: { state: 1, expiresAt: 1 },
492
+ },
493
+ ]) as typeof CoreMailRecipientHandleDoc,
494
+ InboundHandoff: bind(CoreMailInboundHandoffDoc, 'CoreMailInboundHandoff', [
495
+ 'handoffId',
496
+ 'revision',
497
+ 'transportDeliveryId',
498
+ 'routingHandles',
499
+ 'message',
500
+ 'source',
501
+ 'state',
502
+ 'objectKey',
503
+ 'grantId',
504
+ 'deliveryIds',
505
+ 'createdAt',
506
+ 'updatedAt',
507
+ 'completedAt',
508
+ 'retiringAt',
509
+ ], 'handoffId', [
510
+ uniqueIndex('transportDeliveryId_unique', 'transportDeliveryId'),
511
+ {
512
+ name: 'state_updated',
513
+ key: { state: 1, updatedAt: 1 },
514
+ },
515
+ {
516
+ name: 'state_completed',
517
+ key: { state: 1, completedAt: 1 },
518
+ options: { sparse: true },
519
+ },
520
+ ]) as typeof CoreMailInboundHandoffDoc,
521
+ };
522
+ };
523
+
524
+ export const prepareCoreMailModelsForTransactions = async (
525
+ modelsArg: ICoreMailModels,
526
+ ): Promise<void> => {
527
+ await Promise.all(
528
+ Object.values(modelsArg).map((modelArg) => modelArg.exact.prepare()),
529
+ );
530
+ };