@marcoappio/marco-config 2.0.540 → 2.0.542

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 (77) hide show
  1. package/dist/constants/index.d.ts +0 -4
  2. package/dist/constants/index.d.ts.map +1 -1
  3. package/dist/constants/index.js +0 -2
  4. package/dist/index.d.ts +1 -2
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +1 -2
  7. package/dist/marcoPublicConfig.d.ts +0 -3
  8. package/dist/marcoPublicConfig.d.ts.map +1 -1
  9. package/dist/marcoPublicConfig.js +0 -9
  10. package/dist/schemas/index.d.ts +2 -0
  11. package/dist/schemas/index.d.ts.map +1 -1
  12. package/dist/schemas/index.js +2 -0
  13. package/dist/schemas/mutators/index.d.ts +2 -0
  14. package/dist/schemas/mutators/index.d.ts.map +1 -0
  15. package/dist/schemas/mutators/index.js +1 -0
  16. package/dist/{zero → schemas/mutators}/mutatorSchemas.d.ts +4 -4
  17. package/dist/{zero → schemas/mutators}/mutatorSchemas.d.ts.map +1 -1
  18. package/dist/{zero → schemas/mutators}/mutatorSchemas.js +4 -4
  19. package/dist/sdk/endpoints/private/mutations/account/createAccount.js +1 -1
  20. package/dist/sdk/endpoints/private/mutations/account/createAlias.js +1 -1
  21. package/dist/sdk/endpoints/private/mutations/account/deleteAccount.js +1 -1
  22. package/dist/sdk/endpoints/private/mutations/account/deleteAlias.js +1 -1
  23. package/dist/sdk/endpoints/private/mutations/account/setAliasName.js +1 -1
  24. package/dist/sdk/endpoints/private/mutations/account/setAliasPrimary.js +1 -1
  25. package/dist/sdk/endpoints/private/mutations/account/setConnectionConfigImap.js +1 -1
  26. package/dist/sdk/endpoints/private/mutations/account/setConnectionConfigOauth.js +1 -1
  27. package/dist/sdk/endpoints/private/mutations/account/setSettings.js +1 -1
  28. package/dist/sdk/endpoints/private/mutations/draft/cancelSend.js +1 -1
  29. package/dist/sdk/endpoints/private/mutations/draft/createAttachment.js +1 -1
  30. package/dist/sdk/endpoints/private/mutations/draft/createDraft.js +1 -1
  31. package/dist/sdk/endpoints/private/mutations/draft/deleteAttachment.js +1 -1
  32. package/dist/sdk/endpoints/private/mutations/draft/deleteDraft.js +1 -1
  33. package/dist/sdk/endpoints/private/mutations/draft/scheduleSend.js +1 -1
  34. package/dist/sdk/endpoints/private/mutations/draft/setContent.js +1 -1
  35. package/dist/sdk/endpoints/private/mutations/draft/setEnvelope.d.ts +2 -2
  36. package/dist/sdk/endpoints/private/mutations/draft/setEnvelope.js +1 -1
  37. package/dist/sdk/endpoints/private/mutations/draft/setFrom.js +1 -1
  38. package/dist/sdk/endpoints/private/mutations/thread/addLabel.js +1 -1
  39. package/dist/sdk/endpoints/private/mutations/thread/deleteThreads.js +1 -1
  40. package/dist/sdk/endpoints/private/mutations/thread/removeLabel.js +1 -1
  41. package/dist/sdk/endpoints/private/mutations/thread/setArchive.js +1 -1
  42. package/dist/sdk/endpoints/private/mutations/thread/setFlagged.js +1 -1
  43. package/dist/sdk/endpoints/private/mutations/thread/setInbox.js +1 -1
  44. package/dist/sdk/endpoints/private/mutations/thread/setSeen.js +1 -1
  45. package/dist/sdk/endpoints/private/mutations/thread/setSpam.js +1 -1
  46. package/dist/sdk/endpoints/private/mutations/thread/setTrash.js +1 -1
  47. package/dist/sdk/endpoints/private/mutations/user/createView.js +1 -1
  48. package/dist/sdk/endpoints/private/mutations/user/deletePushToken.js +1 -1
  49. package/dist/sdk/endpoints/private/mutations/user/deleteView.js +1 -1
  50. package/dist/sdk/endpoints/private/mutations/user/setPushToken.js +1 -1
  51. package/dist/sdk/endpoints/private/mutations/user/setSettingsName.js +1 -1
  52. package/dist/sdk/endpoints/private/mutations/user/updateView.js +1 -1
  53. package/dist/types/index.d.ts +0 -1
  54. package/dist/types/index.d.ts.map +1 -1
  55. package/dist/types/index.js +0 -1
  56. package/package.json +1 -2
  57. package/dist/constants/zero.d.ts +0 -5
  58. package/dist/constants/zero.d.ts.map +0 -1
  59. package/dist/constants/zero.js +0 -4
  60. package/dist/types/Zero.d.ts +0 -17
  61. package/dist/types/Zero.d.ts.map +0 -1
  62. package/dist/types/Zero.js +0 -5
  63. package/dist/zero/index.d.ts +0 -5072
  64. package/dist/zero/index.d.ts.map +0 -1
  65. package/dist/zero/index.js +0 -12
  66. package/dist/zero/mutators.d.ts +0 -1523
  67. package/dist/zero/mutators.d.ts.map +0 -1
  68. package/dist/zero/mutators.js +0 -560
  69. package/dist/zero/mutators.test.d.ts +0 -2
  70. package/dist/zero/mutators.test.d.ts.map +0 -1
  71. package/dist/zero/mutators.test.js +0 -1158
  72. package/dist/zero/queries.d.ts +0 -1372
  73. package/dist/zero/queries.d.ts.map +0 -1
  74. package/dist/zero/queries.js +0 -173
  75. package/dist/zero/schema.d.ts +0 -1821
  76. package/dist/zero/schema.d.ts.map +0 -1
  77. package/dist/zero/schema.js +0 -434
@@ -1 +0,0 @@
1
- {"version":3,"file":"mutators.d.ts","sourceRoot":"","sources":["../../src/zero/mutators.ts"],"names":[],"mappings":"AASA,KAAK,OAAO,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAqGjC,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmjBnB,CAAA"}
@@ -1,560 +0,0 @@
1
- import { createBuilder, defineMutators, defineMutatorWithType } from '@rocicorp/zero';
2
- import { marcoConstants } from '../constants';
3
- import { stringPatch } from '../utils';
4
- import { threadsUtils } from '../utils/threads';
5
- import { mutatorSchemas } from '../zero/mutatorSchemas';
6
- import { schema } from '../zero/schema';
7
- const zql = createBuilder(schema);
8
- const defineMutator = defineMutatorWithType();
9
- const buildLabelIdList = (x) => (x.length === 0 ? '' : ` ${[...new Set(x)].join(' ')} `);
10
- const setSystemLabel = async (tx, builder, threadId, targetSpecialUse) => {
11
- const thread = await tx.run(builder.thread.where('id', threadId).one());
12
- if (thread) {
13
- const [targetLabel, messages] = await Promise.all([
14
- tx.run(builder.accountLabel.where('accountId', thread.accountId).where('specialUse', targetSpecialUse).one()),
15
- tx.run(builder.threadMessage.where('threadId', threadId)),
16
- ]);
17
- if (targetLabel) {
18
- const currentLabelIds = new Set(threadsUtils.parseLabelIdList(thread.labelIdList));
19
- const hasTarget = currentLabelIds.has(targetLabel.id);
20
- const labelIdsToRemove = new Set(currentLabelIds);
21
- labelIdsToRemove.delete(targetLabel.id);
22
- const threadLabelDeletes = [];
23
- for (const message of messages) {
24
- for (const labelId of labelIdsToRemove) {
25
- threadLabelDeletes.push(tx.mutate.threadLabel.delete({
26
- accountId: thread.accountId,
27
- labelId,
28
- threadMessageId: message.id,
29
- }));
30
- }
31
- }
32
- await Promise.all([
33
- ...threadLabelDeletes,
34
- ...[...labelIdsToRemove].map(labelId => tx.mutate.threadByLabel.delete({ labelId, threadId })),
35
- ]);
36
- if (thread.seen === false && labelIdsToRemove.size > 0) {
37
- const labelsToUpdate = await tx.run(builder.accountLabel.where('id', 'IN', [...labelIdsToRemove]));
38
- await Promise.all(labelsToUpdate.map(label => tx.mutate.accountLabel.update({
39
- id: label.id,
40
- unreadCount: Math.max(0, (label.unreadCount ?? 0) - 1),
41
- })));
42
- }
43
- if (!hasTarget) {
44
- const baseTimestamp = Date.now();
45
- await Promise.all([
46
- ...messages.map((message, i) => tx.mutate.threadLabel.insert({
47
- accountId: thread.accountId,
48
- labelId: targetLabel.id,
49
- lastSyncedAt: 0,
50
- threadId,
51
- threadMessageId: message.id,
52
- uid: -(baseTimestamp + i),
53
- uidValidity: targetLabel.uidValidity ?? 0,
54
- })),
55
- tx.mutate.threadByLabel.insert({
56
- labelId: targetLabel.id,
57
- latestMessageDate: thread.latestMessageDate,
58
- threadId,
59
- }),
60
- ...(thread.seen === false
61
- ? [
62
- tx.mutate.accountLabel.update({
63
- id: targetLabel.id,
64
- unreadCount: (targetLabel.unreadCount ?? 0) + 1,
65
- }),
66
- ]
67
- : []),
68
- ]);
69
- }
70
- await tx.mutate.thread.update({
71
- id: threadId,
72
- labelIdList: buildLabelIdList([targetLabel.id]),
73
- });
74
- }
75
- }
76
- };
77
- export const mutators = defineMutators({
78
- account: {
79
- createAccount: defineMutator(mutatorSchemas.account.createAccount, async ({ tx, ctx, args }) => {
80
- await tx.mutate.account.insert({
81
- color: args.color,
82
- displayName: null,
83
- id: args.id,
84
- imapConnectionStatus: 'AWAITING_CONNECTION',
85
- mailProcessedCount: 0,
86
- mailTotalCount: 0,
87
- primaryAliasId: args.aliasId,
88
- userId: ctx.userId,
89
- });
90
- await tx.mutate.accountAlias.insert({
91
- accountId: args.id,
92
- emailAddress: args.emailAddress,
93
- id: args.aliasId,
94
- isPrimary: true,
95
- name: null,
96
- });
97
- }),
98
- createAlias: defineMutator(mutatorSchemas.account.createAlias, async ({ tx, args }) => {
99
- await tx.mutate.accountAlias.insert({
100
- accountId: args.accountId,
101
- emailAddress: args.alias.emailAddress,
102
- id: args.alias.id,
103
- isPrimary: false,
104
- name: args.alias.name ?? null,
105
- });
106
- }),
107
- deleteAccount: defineMutator(mutatorSchemas.account.deleteAccount, async ({ tx, args }) => {
108
- await tx.mutate.account.delete({
109
- id: args.id,
110
- });
111
- }),
112
- deleteAlias: defineMutator(mutatorSchemas.account.deleteAlias, async ({ tx, args }) => {
113
- const alias = await tx.run(zql.accountAlias.where('id', args.aliasId).one());
114
- await tx.mutate.accountAlias.delete({
115
- id: args.aliasId,
116
- });
117
- if (alias?.isPrimary) {
118
- const remainingAliases = await tx.run(zql.accountAlias.where('accountId', args.accountId));
119
- if (remainingAliases.length > 0) {
120
- const newPrimaryAlias = remainingAliases[0];
121
- await tx.mutate.accountAlias.update({
122
- id: newPrimaryAlias.id,
123
- isPrimary: true,
124
- });
125
- await tx.mutate.account.update({
126
- id: args.accountId,
127
- primaryAliasId: newPrimaryAlias.id,
128
- });
129
- }
130
- else {
131
- await tx.mutate.account.update({
132
- id: args.accountId,
133
- primaryAliasId: null,
134
- });
135
- }
136
- }
137
- }),
138
- setAliasName: defineMutator(mutatorSchemas.account.setAliasName, async ({ tx, args }) => {
139
- await tx.mutate.accountAlias.update({
140
- id: args.aliasId,
141
- name: args.displayName,
142
- });
143
- }),
144
- setAliasPrimary: defineMutator(mutatorSchemas.account.setAliasPrimary, async ({ tx, args }) => {
145
- const aliases = await tx.run(zql.accountAlias.where('accountId', args.accountId));
146
- for (const alias of aliases) {
147
- await tx.mutate.accountAlias.update({
148
- id: alias.id,
149
- isPrimary: alias.id === args.aliasId,
150
- });
151
- }
152
- await tx.mutate.account.update({
153
- id: args.accountId,
154
- primaryAliasId: args.aliasId,
155
- });
156
- }),
157
- setConnectionConfigImapRaw: defineMutator(mutatorSchemas.account.setConnectionConfigImapRaw, async ({ tx, args }) => {
158
- await tx.mutate.account.update({
159
- id: args.id,
160
- imapConnectionStatus: 'AWAITING_CONNECTION',
161
- });
162
- }),
163
- setConnectionConfigOauth: defineMutator(mutatorSchemas.account.setConnectionConfigOauth, async ({ tx, args }) => {
164
- await tx.mutate.account.update({
165
- id: args.id,
166
- imapConnectionStatus: 'AWAITING_CONNECTION',
167
- });
168
- }),
169
- setSettings: defineMutator(mutatorSchemas.account.setSettings, async ({ tx, args }) => {
170
- await tx.mutate.account.update({
171
- color: args.color ? args.color : undefined,
172
- displayName: args.displayName ? args.displayName : undefined,
173
- id: args.id,
174
- });
175
- }),
176
- },
177
- draft: {
178
- cancelSend: defineMutator(mutatorSchemas.draft.cancelSend, async ({ tx, args }) => {
179
- const draft = await tx.run(zql.draft.where('id', args.id).one());
180
- if (draft) {
181
- if (draft.status !== 'SEND_CONFIRMED') {
182
- await tx.mutate.draft.update({
183
- id: args.id,
184
- scheduledFor: null,
185
- status: 'DRAFT',
186
- updatedAt: args.updatedAt,
187
- });
188
- }
189
- }
190
- }),
191
- createAttachment: defineMutator(mutatorSchemas.draft.createAttachment, async ({ tx, args }) => {
192
- await tx.mutate.draftAttachment.insert({
193
- draftId: args.id,
194
- fileName: args.attachment.fileName,
195
- id: args.attachment.id,
196
- mimeType: args.attachment.mimeType,
197
- status: args.attachment.status,
198
- totalSize: args.attachment.totalSize,
199
- });
200
- await tx.mutate.draft.update({
201
- id: args.id,
202
- updatedAt: args.updatedAt,
203
- });
204
- }),
205
- createDraft: defineMutator(mutatorSchemas.draft.createDraft, async ({ tx, ctx, args }) => {
206
- await tx.mutate.draft.insert({
207
- accountId: args.accountId,
208
- body: {
209
- bcc: args.body.bcc,
210
- cc: args.body.cc,
211
- content: args.body.content,
212
- to: args.body.to,
213
- },
214
- error: args.error,
215
- fromAliasId: null,
216
- fromEmail: args.from,
217
- fromName: args.fromName,
218
- id: args.id,
219
- referencedMessageId: args.referencedMessageId,
220
- scheduledFor: args.scheduledFor,
221
- status: args.status,
222
- subject: args.body.subject,
223
- type: args.type,
224
- updatedAt: args.updatedAt,
225
- userId: ctx.userId,
226
- });
227
- for (const attachment of args.attachments) {
228
- await tx.mutate.draftAttachment.insert({
229
- draftId: args.id,
230
- fileName: attachment.fileName,
231
- id: attachment.id,
232
- mimeType: attachment.mimeType,
233
- status: attachment.status,
234
- totalSize: attachment.totalSize,
235
- });
236
- }
237
- }),
238
- deleteAttachment: defineMutator(mutatorSchemas.draft.deleteAttachment, async ({ tx, args }) => {
239
- await tx.mutate.draftAttachment.delete({
240
- id: args.attachmentId,
241
- });
242
- await tx.mutate.draft.update({
243
- id: args.id,
244
- updatedAt: args.updatedAt,
245
- });
246
- }),
247
- deleteDraft: defineMutator(mutatorSchemas.draft.deleteDraft, async ({ tx, args }) => {
248
- await tx.mutate.draft.delete({
249
- id: args.id,
250
- });
251
- }),
252
- scheduleSend: defineMutator(mutatorSchemas.draft.scheduleSend, async ({ tx, args }) => {
253
- if (args.kind === 'IMMEDIATE') {
254
- await tx.mutate.draft.update({
255
- id: args.id,
256
- scheduledFor: args.updatedAt + args.undoMs,
257
- status: 'SEND_REQUESTED',
258
- updatedAt: args.updatedAt,
259
- });
260
- }
261
- else {
262
- await tx.mutate.draft.update({
263
- id: args.id,
264
- scheduledFor: args.scheduledFor,
265
- status: 'SEND_REQUESTED',
266
- updatedAt: args.updatedAt,
267
- });
268
- }
269
- }),
270
- setContent: defineMutator(mutatorSchemas.draft.setContent, async ({ tx, args }) => {
271
- const draft = await tx.run(zql.draft.where('id', args.id).one());
272
- if (draft) {
273
- await tx.mutate.draft.update({
274
- body: {
275
- ...draft.body,
276
- content: stringPatch.apply(typeof draft.body?.content === 'string' ? draft.body.content : '', args.patch),
277
- },
278
- id: args.id,
279
- updatedAt: args.updatedAt,
280
- });
281
- }
282
- }),
283
- setEnvelope: defineMutator(mutatorSchemas.draft.setEnvelope, async ({ tx, args }) => {
284
- const draft = await tx.run(zql.draft.where('id', args.id).one());
285
- if (draft) {
286
- await tx.mutate.draft.update({
287
- body: {
288
- bcc: args.envelope.bcc,
289
- cc: args.envelope.cc,
290
- content: draft.body.content,
291
- to: args.envelope.to,
292
- },
293
- id: args.id,
294
- subject: args.envelope.subject,
295
- updatedAt: args.updatedAt,
296
- });
297
- }
298
- }),
299
- setFrom: defineMutator(mutatorSchemas.draft.setFrom, async ({ tx, args }) => {
300
- await tx.mutate.draft.update({
301
- accountId: args.accountId,
302
- fromAliasId: args.aliasId,
303
- fromEmail: args.from,
304
- fromName: args.fromName,
305
- id: args.id,
306
- updatedAt: args.updatedAt,
307
- });
308
- }),
309
- },
310
- thread: {
311
- addLabel: defineMutator(mutatorSchemas.thread.addLabel, async ({ tx, args }) => {
312
- for (const [accountId, { threadIds }] of Object.entries(args.accounts)) {
313
- const label = await tx.run(zql.accountLabel.where('accountId', accountId).where('path', args.labelPath).one());
314
- if (label) {
315
- for (const threadId of threadIds) {
316
- const [thread, messages] = await Promise.all([
317
- tx.run(zql.thread.where('id', threadId).one()),
318
- tx.run(zql.threadMessage.where('threadId', threadId)),
319
- ]);
320
- if (thread) {
321
- const currentLabelIds = new Set(threadsUtils.parseLabelIdList(thread.labelIdList));
322
- if (!currentLabelIds.has(label.id)) {
323
- await Promise.all([
324
- tx.mutate.threadByLabel.insert({
325
- labelId: label.id,
326
- latestMessageDate: thread.latestMessageDate,
327
- threadId,
328
- }),
329
- ...(thread.seen === false
330
- ? [
331
- tx.mutate.accountLabel.update({
332
- id: label.id,
333
- unreadCount: (label.unreadCount ?? 0) + 1,
334
- }),
335
- ]
336
- : []),
337
- ]);
338
- }
339
- const existingChecks = await Promise.all(messages.map(x => tx.run(zql.threadLabel.where('threadMessageId', x.id).where('labelId', label.id).one())));
340
- const messagesToInsert = messages.filter((_, i) => !existingChecks[i]);
341
- const baseTimestamp = Date.now();
342
- if (messagesToInsert.length > 0) {
343
- await Promise.all(messagesToInsert.map((x, i) => tx.mutate.threadLabel.insert({
344
- accountId,
345
- labelId: label.id,
346
- lastSyncedAt: 0,
347
- threadId,
348
- threadMessageId: x.id,
349
- uid: -(baseTimestamp + i),
350
- uidValidity: label.uidValidity ?? 0,
351
- })));
352
- }
353
- currentLabelIds.add(label.id);
354
- await tx.mutate.thread.update({
355
- id: threadId,
356
- labelIdList: buildLabelIdList([...currentLabelIds]),
357
- });
358
- }
359
- }
360
- }
361
- }
362
- }),
363
- delete: defineMutator(mutatorSchemas.thread.delete, async ({ tx, args }) => {
364
- for (const [, { threadIds }] of Object.entries(args.accounts)) {
365
- for (const threadId of threadIds) {
366
- const thread = await tx.run(zql.thread.where('id', threadId).one());
367
- if (thread) {
368
- if (thread.seen === false) {
369
- const labelIds = threadsUtils.parseLabelIdList(thread.labelIdList);
370
- if (labelIds.length > 0) {
371
- const labels = await tx.run(zql.accountLabel.where('id', 'IN', labelIds));
372
- await Promise.all(labels.map(x => tx.mutate.accountLabel.update({
373
- id: x.id,
374
- unreadCount: Math.max(0, (x.unreadCount ?? 0) - 1),
375
- })));
376
- }
377
- }
378
- await tx.mutate.thread.delete({
379
- id: threadId,
380
- });
381
- }
382
- }
383
- }
384
- }),
385
- removeLabel: defineMutator(mutatorSchemas.thread.removeLabel, async ({ tx, args }) => {
386
- for (const [accountId, { threadIds }] of Object.entries(args.accounts)) {
387
- const label = await tx.run(zql.accountLabel.where('accountId', accountId).where('path', args.labelPath).one());
388
- if (label) {
389
- for (const threadId of threadIds) {
390
- const [thread, messages] = await Promise.all([
391
- tx.run(zql.thread.where('id', threadId).one()),
392
- tx.run(zql.threadMessage.where('threadId', threadId)),
393
- ]);
394
- if (thread) {
395
- const currentLabelIds = new Set(threadsUtils.parseLabelIdList(thread.labelIdList));
396
- if (currentLabelIds.has(label.id)) {
397
- currentLabelIds.delete(label.id);
398
- await Promise.all([
399
- ...messages.map(x => tx.mutate.threadLabel.delete({
400
- accountId,
401
- labelId: label.id,
402
- threadMessageId: x.id,
403
- })),
404
- tx.mutate.threadByLabel.delete({
405
- labelId: label.id,
406
- threadId,
407
- }),
408
- ...(thread.seen === false
409
- ? [
410
- tx.mutate.accountLabel.update({
411
- id: label.id,
412
- unreadCount: Math.max(0, (label.unreadCount ?? 0) - 1),
413
- }),
414
- ]
415
- : []),
416
- tx.mutate.thread.update({
417
- id: threadId,
418
- labelIdList: buildLabelIdList([...currentLabelIds]),
419
- }),
420
- ]);
421
- }
422
- }
423
- }
424
- }
425
- }
426
- }),
427
- setArchive: defineMutator(mutatorSchemas.thread.setArchive, async ({ tx, args }) => {
428
- for (const [, { threadIds }] of Object.entries(args.accounts)) {
429
- for (const threadId of threadIds) {
430
- await setSystemLabel(tx, zql, threadId, 'ARCHIVE');
431
- }
432
- }
433
- }),
434
- setFlagged: defineMutator(mutatorSchemas.thread.setFlagged, async ({ tx, args }) => {
435
- for (const [, { threadIds }] of Object.entries(args.accounts)) {
436
- await Promise.all(threadIds.map(threadId => tx.mutate.thread.update({
437
- flagged: args.flagged,
438
- id: threadId,
439
- })));
440
- }
441
- }),
442
- setInbox: defineMutator(mutatorSchemas.thread.setInbox, async ({ tx, args }) => {
443
- for (const [, { threadIds }] of Object.entries(args.accounts)) {
444
- for (const threadId of threadIds) {
445
- await setSystemLabel(tx, zql, threadId, 'INBOX');
446
- }
447
- }
448
- }),
449
- setSeen: defineMutator(mutatorSchemas.thread.setSeen, async ({ tx, args }) => {
450
- const allThreadIds = Object.values(args.accounts).flatMap(x => x.threadIds);
451
- const threads = await tx.run(zql.thread.where('id', 'IN', allThreadIds));
452
- const labelCounts = new Map();
453
- for (const thread of threads) {
454
- if (thread.seen !== args.seen) {
455
- for (const labelId of threadsUtils.parseLabelIdList(thread.labelIdList)) {
456
- labelCounts.set(labelId, (labelCounts.get(labelId) ?? 0) + 1);
457
- }
458
- }
459
- }
460
- if (labelCounts.size > 0) {
461
- const labels = await tx.run(zql.accountLabel.where('id', 'IN', [...labelCounts.keys()]));
462
- const delta = args.seen ? -1 : 1;
463
- await Promise.all(labels
464
- .filter(x => labelCounts.has(x.id))
465
- .map(x => tx.mutate.accountLabel.update({
466
- id: x.id,
467
- unreadCount: Math.max(0, (x.unreadCount ?? 0) + delta * (labelCounts.get(x.id) ?? 0)),
468
- })));
469
- }
470
- await Promise.all(allThreadIds.map(threadId => tx.mutate.thread.update({
471
- id: threadId,
472
- seen: args.seen,
473
- })));
474
- }),
475
- setSpam: defineMutator(mutatorSchemas.thread.setSpam, async ({ tx, args }) => {
476
- for (const [, { threadIds }] of Object.entries(args.accounts)) {
477
- for (const threadId of threadIds) {
478
- await setSystemLabel(tx, zql, threadId, 'SPAM');
479
- }
480
- }
481
- }),
482
- setTrash: defineMutator(mutatorSchemas.thread.setTrash, async ({ tx, args }) => {
483
- for (const [, { threadIds }] of Object.entries(args.accounts)) {
484
- for (const threadId of threadIds) {
485
- await setSystemLabel(tx, zql, threadId, 'TRASH');
486
- }
487
- }
488
- }),
489
- },
490
- user: {
491
- createView: defineMutator(mutatorSchemas.user.createView, async ({ tx, args }) => {
492
- const user = await tx.run(zql.user.where('id', args.id).one());
493
- if (user) {
494
- const currentViews = user.views ?? [];
495
- const existingView = currentViews.find(x => x.id === args.view.id);
496
- if (!existingView && currentViews.length < marcoConstants.user.views.maxViews) {
497
- await tx.mutate.user.update({
498
- id: args.id,
499
- views: [
500
- ...currentViews,
501
- {
502
- ...args.view,
503
- aliasEmails: [...new Set(args.view.aliasEmails)],
504
- },
505
- ],
506
- });
507
- }
508
- }
509
- }),
510
- deleteSettingsPushNotificationToken: defineMutator(mutatorSchemas.user.deleteSettingsPushNotificationToken, async ({ tx, args }) => {
511
- await tx.mutate.userPushNotificationToken.delete({
512
- id: args.id,
513
- });
514
- }),
515
- deleteView: defineMutator(mutatorSchemas.user.deleteView, async ({ tx, args }) => {
516
- const user = await tx.run(zql.user.where('id', args.id).one());
517
- if (user) {
518
- await tx.mutate.user.update({
519
- id: args.id,
520
- views: (user.views ?? []).filter(x => x.id !== args.viewId),
521
- });
522
- }
523
- }),
524
- setSettingsName: defineMutator(mutatorSchemas.user.setSettingsName, async ({ tx, args }) => {
525
- await tx.mutate.user.update({
526
- id: args.id,
527
- name: args.name,
528
- });
529
- }),
530
- setSettingsPushNotificationToken: defineMutator(mutatorSchemas.user.setSettingsPushNotificationToken, async ({ tx, args }) => {
531
- const existing = await tx.run(zql.userPushNotificationToken.where('userId', args.id).where('token', args.pushNotificationToken.token).one());
532
- if (!existing) {
533
- await tx.mutate.userPushNotificationToken.insert({
534
- createdAt: args.pushNotificationToken.createdAt,
535
- id: args.pushNotificationToken.id,
536
- token: args.pushNotificationToken.token,
537
- userId: args.id,
538
- });
539
- }
540
- }),
541
- updateView: defineMutator(mutatorSchemas.user.updateView, async ({ tx, args }) => {
542
- const user = await tx.run(zql.user.where('id', args.id).one());
543
- if (user) {
544
- const viewExists = (user.views ?? []).some(x => x.id === args.view.id);
545
- if (viewExists) {
546
- const deduplicatedEmails = [...new Set(args.view.aliasEmails)];
547
- await tx.mutate.user.update({
548
- id: args.id,
549
- views: (user.views ?? []).map(x => x.id === args.view.id
550
- ? {
551
- ...args.view,
552
- aliasEmails: deduplicatedEmails,
553
- }
554
- : x),
555
- });
556
- }
557
- }
558
- }),
559
- },
560
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=mutators.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mutators.test.d.ts","sourceRoot":"","sources":["../../src/zero/mutators.test.ts"],"names":[],"mappings":""}