@marcoappio/marco-config 2.0.426 → 2.0.428

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 (97) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/types/AuthData.d.ts +4 -0
  5. package/dist/types/AuthData.d.ts.map +1 -0
  6. package/dist/types/AuthData.js +1 -0
  7. package/dist/types/Zero.d.ts +18 -0
  8. package/dist/types/Zero.d.ts.map +1 -1
  9. package/dist/types/Zero.js +5 -1
  10. package/dist/types/index.d.ts +1 -0
  11. package/dist/types/index.d.ts.map +1 -1
  12. package/dist/types/index.js +1 -0
  13. package/dist/zero/index.d.ts +176 -257
  14. package/dist/zero/index.d.ts.map +1 -1
  15. package/dist/zero/index.js +0 -7
  16. package/dist/zero/{mutators → mutatorSchemas}/account.d.ts +4 -33
  17. package/dist/zero/mutatorSchemas/account.d.ts.map +1 -0
  18. package/dist/zero/{mutators → mutatorSchemas}/account.js +4 -7
  19. package/dist/zero/{mutators → mutatorSchemas}/draft.d.ts +1 -1
  20. package/dist/zero/{mutators → mutatorSchemas}/draft.d.ts.map +1 -1
  21. package/dist/zero/{mutators → mutatorSchemas}/draft.js +1 -1
  22. package/dist/zero/mutatorSchemas/index.d.ts +5 -0
  23. package/dist/zero/mutatorSchemas/index.d.ts.map +1 -0
  24. package/dist/zero/mutatorSchemas/index.js +4 -0
  25. package/dist/zero/{mutators → mutatorSchemas}/thread.d.ts +13 -26
  26. package/dist/zero/mutatorSchemas/thread.d.ts.map +1 -0
  27. package/dist/zero/{mutators → mutatorSchemas}/thread.js +13 -24
  28. package/dist/zero/{mutators → mutatorSchemas}/user.d.ts +1 -7
  29. package/dist/zero/mutatorSchemas/user.d.ts.map +1 -0
  30. package/dist/zero/{mutators → mutatorSchemas}/user.js +1 -7
  31. package/dist/zero/mutators/accountMutators/accountMutators.d.ts +8 -0
  32. package/dist/zero/mutators/accountMutators/accountMutators.d.ts.map +1 -0
  33. package/dist/zero/mutators/accountMutators/accountMutators.js +112 -0
  34. package/dist/zero/mutators/accountMutators/accountMutators.test.d.ts +2 -0
  35. package/dist/zero/mutators/accountMutators/accountMutators.test.d.ts.map +1 -0
  36. package/dist/zero/mutators/accountMutators/accountMutators.test.js +390 -0
  37. package/dist/zero/mutators/accountMutators/index.d.ts +2 -0
  38. package/dist/zero/mutators/accountMutators/index.d.ts.map +1 -0
  39. package/dist/zero/mutators/accountMutators/index.js +1 -0
  40. package/dist/zero/mutators/draftMutators/draftMutators.d.ts +8 -0
  41. package/dist/zero/mutators/draftMutators/draftMutators.d.ts.map +1 -0
  42. package/dist/zero/mutators/draftMutators/draftMutators.js +162 -0
  43. package/dist/zero/mutators/draftMutators/draftMutators.test.d.ts +2 -0
  44. package/dist/zero/mutators/draftMutators/draftMutators.test.d.ts.map +1 -0
  45. package/dist/zero/mutators/draftMutators/draftMutators.test.js +390 -0
  46. package/dist/zero/mutators/draftMutators/index.d.ts +2 -0
  47. package/dist/zero/mutators/draftMutators/index.d.ts.map +1 -0
  48. package/dist/zero/mutators/draftMutators/index.js +1 -0
  49. package/dist/zero/mutators/index.d.ts +6566 -0
  50. package/dist/zero/mutators/index.d.ts.map +1 -0
  51. package/dist/zero/mutators/index.js +17 -0
  52. package/dist/zero/mutators/mutators.d.ts +29 -0
  53. package/dist/zero/mutators/mutators.d.ts.map +1 -0
  54. package/dist/zero/{mutators.js → mutators/mutators.js} +10 -15
  55. package/dist/zero/mutators/threadMutators/index.d.ts +2 -0
  56. package/dist/zero/mutators/threadMutators/index.d.ts.map +1 -0
  57. package/dist/zero/mutators/threadMutators/index.js +1 -0
  58. package/dist/zero/mutators/threadMutators/threadMutators.d.ts +8 -0
  59. package/dist/zero/mutators/threadMutators/threadMutators.d.ts.map +1 -0
  60. package/dist/zero/mutators/threadMutators/threadMutators.js +238 -0
  61. package/dist/zero/mutators/threadMutators/threadMutators.test.d.ts +2 -0
  62. package/dist/zero/mutators/threadMutators/threadMutators.test.d.ts.map +1 -0
  63. package/dist/zero/mutators/threadMutators/threadMutators.test.js +465 -0
  64. package/dist/zero/mutators/userMutators/index.d.ts +2 -0
  65. package/dist/zero/mutators/userMutators/index.d.ts.map +1 -0
  66. package/dist/zero/mutators/userMutators/index.js +1 -0
  67. package/dist/zero/mutators/userMutators/userMutators.d.ts +8 -0
  68. package/dist/zero/mutators/userMutators/userMutators.d.ts.map +1 -0
  69. package/dist/zero/mutators/userMutators/userMutators.js +37 -0
  70. package/dist/zero/mutators/userMutators/userMutators.test.d.ts +2 -0
  71. package/dist/zero/mutators/userMutators/userMutators.test.d.ts.map +1 -0
  72. package/dist/zero/mutators/userMutators/userMutators.test.js +123 -0
  73. package/dist/zero/queries/getAccounts.d.ts +29 -40
  74. package/dist/zero/queries/getAccounts.d.ts.map +1 -1
  75. package/dist/zero/queries/getContacts.d.ts +29 -40
  76. package/dist/zero/queries/getContacts.d.ts.map +1 -1
  77. package/dist/zero/queries/getDrafts.d.ts +29 -40
  78. package/dist/zero/queries/getDrafts.d.ts.map +1 -1
  79. package/dist/zero/queries/getThreads.d.ts +29 -47
  80. package/dist/zero/queries/getThreads.d.ts.map +1 -1
  81. package/dist/zero/queries/getThreads.js +1 -1
  82. package/dist/zero/queries/getUser.d.ts +29 -40
  83. package/dist/zero/queries/getUser.d.ts.map +1 -1
  84. package/dist/zero/queries/index.d.ts +29 -40
  85. package/dist/zero/queries/index.d.ts.map +1 -1
  86. package/dist/zero/schema.d.ts +29 -40
  87. package/dist/zero/schema.d.ts.map +1 -1
  88. package/dist/zero/schema.js +0 -9
  89. package/package.json +1 -1
  90. package/dist/zero/mutators/account.d.ts.map +0 -1
  91. package/dist/zero/mutators/thread.d.ts.map +0 -1
  92. package/dist/zero/mutators/user.d.ts.map +0 -1
  93. package/dist/zero/mutators.d.ts +0 -412
  94. package/dist/zero/mutators.d.ts.map +0 -1
  95. package/dist/zero/mutators.test.d.ts +0 -2
  96. package/dist/zero/mutators.test.d.ts.map +0 -1
  97. package/dist/zero/mutators.test.js +0 -33
@@ -0,0 +1,390 @@
1
+ import { describe, expect, it, mock } from 'bun:test';
2
+ import { createMutators, ZeroMutatorValidationError } from '../mutators';
3
+ describe('accountMutators', () => {
4
+ describe('createAccount', () => {
5
+ it('creates an account and invokes the callback', async () => {
6
+ const accountInsert = mock(async () => { });
7
+ const accountAliasInsert = mock(async () => { });
8
+ const createAccountCallback = mock(async () => { });
9
+ const mutators = createMutators({ sub: 'test-user-id' }, {
10
+ account: {
11
+ createAccount: createAccountCallback,
12
+ },
13
+ });
14
+ const payload = {
15
+ aliasId: 'test-alias-id-1',
16
+ color: '#ff0000',
17
+ emailAddress: 'user@example.com',
18
+ id: 'test-account-id-1',
19
+ };
20
+ const transaction = {
21
+ mutate: {
22
+ account: {
23
+ delete: mock(async () => { }),
24
+ insert: accountInsert,
25
+ update: mock(async () => { }),
26
+ },
27
+ accountAlias: {
28
+ delete: mock(async () => { }),
29
+ insert: accountAliasInsert,
30
+ update: mock(async () => { }),
31
+ },
32
+ },
33
+ query: {},
34
+ };
35
+ await mutators.account.createAccount(transaction, payload);
36
+ expect(accountInsert).toHaveBeenCalledWith({
37
+ color: payload.color,
38
+ displayName: null,
39
+ id: payload.id,
40
+ imapConnectionStatus: 'AWAITING_CONNECTION',
41
+ mailProcessedCount: 0,
42
+ mailTotalCount: 0,
43
+ primaryAliasId: payload.aliasId,
44
+ userId: 'test-user-id',
45
+ });
46
+ expect(accountAliasInsert).toHaveBeenCalledWith({
47
+ accountId: payload.id,
48
+ emailAddress: payload.emailAddress,
49
+ id: payload.aliasId,
50
+ isPrimary: true,
51
+ name: null,
52
+ });
53
+ expect(createAccountCallback).toHaveBeenCalledWith(payload);
54
+ expect(accountInsert.mock.invocationCallOrder[0]).toBeLessThan(accountAliasInsert.mock.invocationCallOrder[0]);
55
+ });
56
+ it('throws ZeroMutatorValidationError on invalid payloads', async () => {
57
+ const mutators = createMutators({ sub: 'test-user-id' });
58
+ await expect(mutators.account.createAccount({
59
+ mutate: {},
60
+ query: {},
61
+ }, {
62
+ aliasId: 'test-alias-id-1',
63
+ color: 'blue',
64
+ emailAddress: 'invalid-email',
65
+ id: 'test-account-id-1',
66
+ })).rejects.toBeInstanceOf(ZeroMutatorValidationError);
67
+ });
68
+ });
69
+ describe('createAlias', () => {
70
+ it('creates an alias', async () => {
71
+ const accountAliasInsert = mock(async () => { });
72
+ const createAliasCallback = mock(async () => { });
73
+ const mutators = createMutators({ sub: 'test-user-id' }, {
74
+ account: {
75
+ createAlias: createAliasCallback,
76
+ },
77
+ });
78
+ const transaction = {
79
+ mutate: {
80
+ accountAlias: {
81
+ delete: mock(async () => { }),
82
+ insert: accountAliasInsert,
83
+ update: mock(async () => { }),
84
+ },
85
+ },
86
+ query: {},
87
+ };
88
+ await mutators.account.createAlias(transaction, {
89
+ accountId: 'test-account-id-1',
90
+ alias: {
91
+ emailAddress: 'alias@example.com',
92
+ id: 'test-alias-id-2',
93
+ name: 'Work Email',
94
+ },
95
+ });
96
+ expect(accountAliasInsert).toHaveBeenCalledWith({
97
+ accountId: 'test-account-id-1',
98
+ emailAddress: 'alias@example.com',
99
+ id: 'test-alias-id-2',
100
+ isPrimary: false,
101
+ name: 'Work Email',
102
+ });
103
+ expect(createAliasCallback).toHaveBeenCalled();
104
+ });
105
+ });
106
+ describe('deleteAccount', () => {
107
+ it('deletes an account', async () => {
108
+ const accountDelete = mock(async () => { });
109
+ const deleteAccountCallback = mock(async () => { });
110
+ const mutators = createMutators({ sub: 'test-user-id' }, {
111
+ account: {
112
+ deleteAccount: deleteAccountCallback,
113
+ },
114
+ });
115
+ const transaction = {
116
+ mutate: {
117
+ account: {
118
+ delete: accountDelete,
119
+ insert: mock(async () => { }),
120
+ update: mock(async () => { }),
121
+ },
122
+ },
123
+ query: {},
124
+ };
125
+ await mutators.account.deleteAccount(transaction, {
126
+ id: 'test-account-id-1',
127
+ });
128
+ expect(accountDelete).toHaveBeenCalledWith({
129
+ id: 'test-account-id-1',
130
+ });
131
+ expect(deleteAccountCallback).toHaveBeenCalled();
132
+ });
133
+ });
134
+ describe('deleteAlias', () => {
135
+ it('deletes a non-primary alias', async () => {
136
+ const aliasRecord = {
137
+ id: 'test-alias-id-2',
138
+ isPrimary: false,
139
+ };
140
+ const run = mock(async () => aliasRecord);
141
+ const one = mock(() => ({ run }));
142
+ const where = mock(() => ({ one }));
143
+ const accountAliasDelete = mock(async () => { });
144
+ const transaction = {
145
+ mutate: {
146
+ accountAlias: {
147
+ delete: accountAliasDelete,
148
+ insert: mock(async () => { }),
149
+ update: mock(async () => { }),
150
+ },
151
+ },
152
+ query: {
153
+ accountAlias: {
154
+ where,
155
+ },
156
+ },
157
+ };
158
+ const mutators = createMutators();
159
+ await mutators.account.deleteAlias(transaction, {
160
+ accountId: 'test-account-id-1',
161
+ aliasId: 'test-alias-id-2',
162
+ });
163
+ expect(accountAliasDelete).toHaveBeenCalledWith({
164
+ id: 'test-alias-id-2',
165
+ });
166
+ });
167
+ it('deletes a primary alias and assigns new primary', async () => {
168
+ const aliasRecord = {
169
+ id: 'test-alias-id-1',
170
+ isPrimary: true,
171
+ };
172
+ const remainingAliases = [
173
+ {
174
+ id: 'test-alias-id-2',
175
+ isPrimary: false,
176
+ },
177
+ ];
178
+ const runOne = mock(async () => aliasRecord);
179
+ const one = mock(() => ({ run: runOne }));
180
+ const runList = mock(async () => remainingAliases);
181
+ const where = mock((field) => {
182
+ if (field === 'accountId') {
183
+ return { run: runList };
184
+ }
185
+ return { one };
186
+ });
187
+ const accountAliasDelete = mock(async () => { });
188
+ const accountAliasUpdate = mock(async () => { });
189
+ const accountUpdate = mock(async () => { });
190
+ const transaction = {
191
+ mutate: {
192
+ account: {
193
+ delete: mock(async () => { }),
194
+ insert: mock(async () => { }),
195
+ update: accountUpdate,
196
+ },
197
+ accountAlias: {
198
+ delete: accountAliasDelete,
199
+ insert: mock(async () => { }),
200
+ update: accountAliasUpdate,
201
+ },
202
+ },
203
+ query: {
204
+ accountAlias: {
205
+ where,
206
+ },
207
+ },
208
+ };
209
+ const mutators = createMutators();
210
+ await mutators.account.deleteAlias(transaction, {
211
+ accountId: 'test-account-id-1',
212
+ aliasId: 'test-alias-id-1',
213
+ });
214
+ expect(accountAliasDelete).toHaveBeenCalledWith({
215
+ id: 'test-alias-id-1',
216
+ });
217
+ expect(accountAliasUpdate).toHaveBeenCalledWith({
218
+ id: 'test-alias-id-2',
219
+ isPrimary: true,
220
+ });
221
+ expect(accountUpdate).toHaveBeenCalledWith({
222
+ id: 'test-account-id-1',
223
+ primaryAliasId: 'test-alias-id-2',
224
+ });
225
+ });
226
+ });
227
+ describe('setAliasName', () => {
228
+ it('sets alias name', async () => {
229
+ const accountAliasUpdate = mock(async () => { });
230
+ const transaction = {
231
+ mutate: {
232
+ accountAlias: {
233
+ delete: mock(async () => { }),
234
+ insert: mock(async () => { }),
235
+ update: accountAliasUpdate,
236
+ },
237
+ },
238
+ query: {},
239
+ };
240
+ const mutators = createMutators();
241
+ await mutators.account.setAliasName(transaction, {
242
+ accountId: 'test-account-id-1',
243
+ aliasId: 'test-alias-id-1',
244
+ displayName: 'New Name',
245
+ });
246
+ expect(accountAliasUpdate).toHaveBeenCalledWith({
247
+ id: 'test-alias-id-1',
248
+ name: 'New Name',
249
+ });
250
+ });
251
+ });
252
+ describe('setAliasPrimary', () => {
253
+ it('sets alias as primary', async () => {
254
+ const aliases = [
255
+ { id: 'test-alias-id-1', isPrimary: true },
256
+ { id: 'test-alias-id-2', isPrimary: false },
257
+ ];
258
+ const run = mock(async () => aliases);
259
+ const where = mock(() => ({ run }));
260
+ const accountAliasUpdate = mock(async () => { });
261
+ const accountUpdate = mock(async () => { });
262
+ const transaction = {
263
+ mutate: {
264
+ account: {
265
+ delete: mock(async () => { }),
266
+ insert: mock(async () => { }),
267
+ update: accountUpdate,
268
+ },
269
+ accountAlias: {
270
+ delete: mock(async () => { }),
271
+ insert: mock(async () => { }),
272
+ update: accountAliasUpdate,
273
+ },
274
+ },
275
+ query: {
276
+ accountAlias: {
277
+ where,
278
+ },
279
+ },
280
+ };
281
+ const mutators = createMutators();
282
+ await mutators.account.setAliasPrimary(transaction, {
283
+ accountId: 'test-account-id-1',
284
+ aliasId: 'test-alias-id-2',
285
+ });
286
+ expect(accountAliasUpdate).toHaveBeenCalledTimes(2);
287
+ expect(accountAliasUpdate).toHaveBeenCalledWith({
288
+ id: 'test-alias-id-1',
289
+ isPrimary: false,
290
+ });
291
+ expect(accountAliasUpdate).toHaveBeenCalledWith({
292
+ id: 'test-alias-id-2',
293
+ isPrimary: true,
294
+ });
295
+ expect(accountUpdate).toHaveBeenCalledWith({
296
+ id: 'test-account-id-1',
297
+ primaryAliasId: 'test-alias-id-2',
298
+ });
299
+ });
300
+ });
301
+ describe('setConnectionConfigImapRaw', () => {
302
+ it('sets connection config for IMAP raw', async () => {
303
+ const accountUpdate = mock(async () => { });
304
+ const transaction = {
305
+ mutate: {
306
+ account: {
307
+ delete: mock(async () => { }),
308
+ insert: mock(async () => { }),
309
+ update: accountUpdate,
310
+ },
311
+ },
312
+ query: {},
313
+ };
314
+ const mutators = createMutators();
315
+ await mutators.account.setConnectionConfigImapRaw(transaction, {
316
+ connectionConfig: {
317
+ imapHost: 'imap.example.com',
318
+ imapPassword: 'test-password',
319
+ imapPort: 993,
320
+ imapSocketType: 'SSL',
321
+ imapUser: 'user@example.com',
322
+ smtpHost: 'smtp.example.com',
323
+ smtpPassword: 'test-password',
324
+ smtpPort: 465,
325
+ smtpSocketType: 'SSL',
326
+ smtpUser: 'user@example.com',
327
+ },
328
+ id: 'test-account-id-1',
329
+ });
330
+ expect(accountUpdate).toHaveBeenCalledWith({
331
+ id: 'test-account-id-1',
332
+ imapConnectionStatus: 'AWAITING_CONNECTION',
333
+ });
334
+ });
335
+ });
336
+ describe('setConnectionConfigOauth', () => {
337
+ it('sets connection config for OAuth', async () => {
338
+ const accountUpdate = mock(async () => { });
339
+ const transaction = {
340
+ mutate: {
341
+ account: {
342
+ delete: mock(async () => { }),
343
+ insert: mock(async () => { }),
344
+ update: accountUpdate,
345
+ },
346
+ },
347
+ query: {},
348
+ };
349
+ const mutators = createMutators();
350
+ await mutators.account.setConnectionConfigOauth(transaction, {
351
+ connectionConfig: {
352
+ code: 'test-auth-code',
353
+ provider: 'GOOGLE',
354
+ user: 'user@example.com',
355
+ },
356
+ id: 'test-account-id-1',
357
+ });
358
+ expect(accountUpdate).toHaveBeenCalledWith({
359
+ id: 'test-account-id-1',
360
+ imapConnectionStatus: 'AWAITING_CONNECTION',
361
+ });
362
+ });
363
+ });
364
+ describe('setSettings', () => {
365
+ it('sets account settings', async () => {
366
+ const accountUpdate = mock(async () => { });
367
+ const transaction = {
368
+ mutate: {
369
+ account: {
370
+ delete: mock(async () => { }),
371
+ insert: mock(async () => { }),
372
+ update: accountUpdate,
373
+ },
374
+ },
375
+ query: {},
376
+ };
377
+ const mutators = createMutators();
378
+ await mutators.account.setSettings(transaction, {
379
+ color: '#00ff00',
380
+ displayName: 'Work Account',
381
+ id: 'test-account-id-1',
382
+ });
383
+ expect(accountUpdate).toHaveBeenCalledWith({
384
+ color: '#00ff00',
385
+ displayName: 'Work Account',
386
+ id: 'test-account-id-1',
387
+ });
388
+ });
389
+ });
390
+ });
@@ -0,0 +1,2 @@
1
+ export * from './accountMutators';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/accountMutators/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
@@ -0,0 +1 @@
1
+ export * from './accountMutators';
@@ -0,0 +1,8 @@
1
+ import type * as v from 'valibot';
2
+ import { type AuthData, type HandlerMap } from '../../../types';
3
+ import type { draftMutatorSchemas } from '../../../zero/mutatorSchemas';
4
+ export type DraftMutatorCallbacks = {
5
+ [K in keyof typeof draftMutatorSchemas]?: (args: v.InferOutput<(typeof draftMutatorSchemas)[K]['delta']>) => Promise<void>;
6
+ };
7
+ export declare const createDraftMutators: (authData: AuthData | undefined, callbacks?: DraftMutatorCallbacks) => HandlerMap<typeof draftMutatorSchemas>;
8
+ //# sourceMappingURL=draftMutators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draftMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/draftMutators/draftMutators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,CAAC,MAAM,SAAS,CAAA;AAEjC,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAiB,MAAM,qBAAqB,CAAA;AAEnF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AAE5E,MAAM,MAAM,qBAAqB,GAAG;KACjC,CAAC,IAAI,MAAM,OAAO,mBAAmB,CAAC,CAAC,EAAE,CACxC,IAAI,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,OAAO,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KAC1D,OAAO,CAAC,IAAI,CAAC;CACnB,CAAA;AAED,eAAO,MAAM,mBAAmB,aACpB,QAAQ,GAAG,SAAS,cAClB,qBAAqB,KAChC,UAAU,CAAC,OAAO,mBAAmB,CAwLtC,CAAA"}
@@ -0,0 +1,162 @@
1
+ import { MutationError } from '../../../types';
2
+ import { stringPatch } from '../../../utils';
3
+ export const createDraftMutators = (authData, callbacks) => ({
4
+ cancelSend: async (tx, args) => {
5
+ await tx.mutate.draft.update({
6
+ id: args.id,
7
+ scheduledFor: null,
8
+ status: 'DRAFT',
9
+ updatedAt: args.updatedAt,
10
+ });
11
+ await callbacks?.cancelSend?.(args);
12
+ },
13
+ createAttachment: async (tx, args) => {
14
+ await tx.mutate.draftAttachment.insert({
15
+ draftId: args.id,
16
+ failed: args.attachment.failed,
17
+ fileName: args.attachment.fileName,
18
+ id: args.attachment.id,
19
+ mimeType: args.attachment.mimeType,
20
+ totalChunks: args.attachment.totalChunks,
21
+ totalSize: args.attachment.totalSize,
22
+ uploadedChunks: args.attachment.uploadedChunks,
23
+ });
24
+ await tx.mutate.draft.update({
25
+ id: args.id,
26
+ updatedAt: args.updatedAt,
27
+ });
28
+ await callbacks?.createAttachment?.(args);
29
+ },
30
+ createDraft: async (tx, args) => {
31
+ if (!authData) {
32
+ throw new Error(MutationError.AUTHENTICATION_REQUIRED);
33
+ }
34
+ await tx.mutate.draft.insert({
35
+ accountId: args.emailAccountId,
36
+ body: {
37
+ bcc: args.body.bcc,
38
+ cc: args.body.cc,
39
+ content: args.body.content,
40
+ to: args.body.to,
41
+ },
42
+ error: args.error,
43
+ fromAliasId: null,
44
+ fromEmail: args.from,
45
+ fromName: args.fromName,
46
+ id: args.id,
47
+ referencedMessageId: args.referencedMessageId,
48
+ scheduledFor: args.scheduledFor,
49
+ status: args.status,
50
+ subject: args.body.subject,
51
+ type: args.type,
52
+ updatedAt: args.updatedAt,
53
+ userId: authData.sub,
54
+ });
55
+ for (const attachment of args.attachments) {
56
+ await tx.mutate.draftAttachment.insert({
57
+ draftId: args.id,
58
+ failed: attachment.failed,
59
+ fileName: attachment.fileName,
60
+ id: attachment.id,
61
+ mimeType: attachment.mimeType,
62
+ totalChunks: attachment.totalChunks,
63
+ totalSize: attachment.totalSize,
64
+ uploadedChunks: attachment.uploadedChunks,
65
+ });
66
+ }
67
+ await callbacks?.createDraft?.(args);
68
+ },
69
+ deleteAttachment: async (tx, args) => {
70
+ await tx.mutate.draftAttachment.delete({
71
+ id: args.attachmentId,
72
+ });
73
+ await tx.mutate.draft.update({
74
+ id: args.id,
75
+ updatedAt: args.updatedAt,
76
+ });
77
+ await callbacks?.deleteAttachment?.(args);
78
+ },
79
+ deleteDraft: async (tx, args) => {
80
+ await tx.mutate.draft.delete({
81
+ id: args.id,
82
+ });
83
+ await callbacks?.deleteDraft?.(args);
84
+ },
85
+ scheduleSend: async (tx, args) => {
86
+ if (args.kind === 'IMMEDIATE') {
87
+ await tx.mutate.draft.update({
88
+ id: args.id,
89
+ scheduledFor: args.updatedAt + args.undoMs,
90
+ status: 'SEND_REQUESTED',
91
+ updatedAt: args.updatedAt,
92
+ });
93
+ }
94
+ else {
95
+ await tx.mutate.draft.update({
96
+ id: args.id,
97
+ scheduledFor: args.scheduledFor,
98
+ status: 'SEND_REQUESTED',
99
+ updatedAt: args.updatedAt,
100
+ });
101
+ }
102
+ await callbacks?.scheduleSend?.(args);
103
+ },
104
+ setContent: async (tx, args) => {
105
+ const draft = await tx.query.draft.where('id', args.id).one().run();
106
+ if (!draft) {
107
+ throw new Error(MutationError.ENTITY_NOT_FOUND);
108
+ }
109
+ const currentContent = typeof draft.body?.content === 'string' ? draft.body.content : '';
110
+ const updatedBody = {
111
+ ...draft.body,
112
+ content: stringPatch.apply(currentContent, args.patch),
113
+ };
114
+ await tx.mutate.draft.update({
115
+ body: updatedBody,
116
+ id: args.id,
117
+ updatedAt: args.updatedAt,
118
+ });
119
+ await callbacks?.setContent?.(args);
120
+ },
121
+ setEnvelope: async (tx, args) => {
122
+ const draft = await tx.query.draft.where('id', args.id).one().run();
123
+ if (!draft) {
124
+ throw new Error(MutationError.ENTITY_NOT_FOUND);
125
+ }
126
+ await tx.mutate.draft.update({
127
+ body: {
128
+ bcc: args.envelope.bcc,
129
+ cc: args.envelope.cc,
130
+ content: draft.body.content,
131
+ to: args.envelope.to,
132
+ },
133
+ id: args.id,
134
+ subject: args.envelope.subject,
135
+ updatedAt: args.updatedAt,
136
+ });
137
+ await callbacks?.setEnvelope?.(args);
138
+ },
139
+ setFrom: async (tx, args) => {
140
+ await tx.mutate.draft.update({
141
+ accountId: args.emailAccountId,
142
+ fromAliasId: args.aliasId,
143
+ fromEmail: args.from,
144
+ fromName: args.fromName,
145
+ id: args.id,
146
+ updatedAt: args.updatedAt,
147
+ });
148
+ await callbacks?.setFrom?.(args);
149
+ },
150
+ uploadAttachmentChunk: async (tx, args) => {
151
+ const attachment = await tx.query.draftAttachment.where('id', args.attachmentId).one().run();
152
+ if (!attachment) {
153
+ throw new Error(MutationError.ENTITY_NOT_FOUND);
154
+ }
155
+ const uploadedChunks = Math.max(typeof attachment.uploadedChunks === 'number' ? attachment.uploadedChunks : 0, args.chunkIndex + 1);
156
+ await tx.mutate.draftAttachment.update({
157
+ id: args.attachmentId,
158
+ uploadedChunks,
159
+ });
160
+ await callbacks?.uploadAttachmentChunk?.(args);
161
+ },
162
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=draftMutators.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draftMutators.test.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/draftMutators/draftMutators.test.ts"],"names":[],"mappings":""}