@marcoappio/marco-config 2.0.504 → 2.0.506

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 (120) hide show
  1. package/dist/schemas/auth.d.ts +1 -1
  2. package/dist/schemas/index.d.ts +2 -2
  3. package/dist/schemas/string.d.ts +1 -1
  4. package/dist/schemas/string.d.ts.map +1 -1
  5. package/dist/schemas/string.js +4 -1
  6. package/dist/sdk/endpoints/index.d.ts +4 -4
  7. package/dist/sdk/endpoints/public/auth/index.d.ts +4 -4
  8. package/dist/sdk/endpoints/public/auth/refreshAuth.d.ts +1 -1
  9. package/dist/sdk/endpoints/public/auth/sendAuthCode.d.ts +1 -1
  10. package/dist/sdk/endpoints/public/auth/verifyAuthCode.d.ts +2 -2
  11. package/dist/sdk/endpoints/public/index.d.ts +4 -4
  12. package/dist/sdk/index.d.ts +4 -4
  13. package/dist/types/AuthData.d.ts +4 -0
  14. package/dist/types/AuthData.d.ts.map +1 -0
  15. package/dist/types/AuthData.js +1 -0
  16. package/dist/types/IMAPSourceLocation.d.ts +7 -0
  17. package/dist/types/IMAPSourceLocation.d.ts.map +1 -0
  18. package/dist/types/IMAPSourceLocation.js +1 -0
  19. package/dist/types/Zero.d.ts +14 -8
  20. package/dist/types/Zero.d.ts.map +1 -1
  21. package/dist/types/index.d.ts +2 -0
  22. package/dist/types/index.d.ts.map +1 -1
  23. package/dist/types/index.js +2 -0
  24. package/dist/zero/index.d.ts +7749 -3113
  25. package/dist/zero/index.d.ts.map +1 -1
  26. package/dist/zero/index.js +14 -5
  27. package/dist/zero/mutatorSchemas/account.d.ts +80 -0
  28. package/dist/zero/mutatorSchemas/account.d.ts.map +1 -0
  29. package/dist/zero/mutatorSchemas/account.js +66 -0
  30. package/dist/zero/mutatorSchemas/draft.d.ts +150 -0
  31. package/dist/zero/mutatorSchemas/draft.d.ts.map +1 -0
  32. package/dist/zero/mutatorSchemas/draft.js +104 -0
  33. package/dist/zero/mutatorSchemas/index.d.ts +323 -0
  34. package/dist/zero/mutatorSchemas/index.d.ts.map +1 -0
  35. package/dist/zero/mutatorSchemas/index.js +10 -0
  36. package/dist/zero/mutatorSchemas/thread.d.ts +71 -0
  37. package/dist/zero/mutatorSchemas/thread.d.ts.map +1 -0
  38. package/dist/zero/mutatorSchemas/thread.js +47 -0
  39. package/dist/zero/mutatorSchemas/user.d.ts +26 -0
  40. package/dist/zero/mutatorSchemas/user.d.ts.map +1 -0
  41. package/dist/zero/mutatorSchemas/user.js +27 -0
  42. package/dist/zero/mutators/accountMutators/accountMutators.d.ts +3 -188
  43. package/dist/zero/mutators/accountMutators/accountMutators.d.ts.map +1 -1
  44. package/dist/zero/mutators/accountMutators/accountMutators.js +82 -118
  45. package/dist/zero/mutators/accountMutators/accountMutators.test.d.ts +2 -0
  46. package/dist/zero/mutators/accountMutators/accountMutators.test.d.ts.map +1 -0
  47. package/dist/zero/mutators/accountMutators/accountMutators.test.js +372 -0
  48. package/dist/zero/mutators/accountMutators/index.d.ts +1 -1
  49. package/dist/zero/mutators/accountMutators/index.d.ts.map +1 -1
  50. package/dist/zero/mutators/accountMutators/index.js +1 -1
  51. package/dist/zero/mutators/draftMutators/draftMutators.d.ts +3 -305
  52. package/dist/zero/mutators/draftMutators/draftMutators.d.ts.map +1 -1
  53. package/dist/zero/mutators/draftMutators/draftMutators.js +83 -157
  54. package/dist/zero/mutators/draftMutators/draftMutators.test.d.ts +2 -0
  55. package/dist/zero/mutators/draftMutators/draftMutators.test.d.ts.map +1 -0
  56. package/dist/zero/mutators/draftMutators/draftMutators.test.js +416 -0
  57. package/dist/zero/mutators/draftMutators/index.d.ts +1 -1
  58. package/dist/zero/mutators/draftMutators/index.d.ts.map +1 -1
  59. package/dist/zero/mutators/draftMutators/index.js +1 -1
  60. package/dist/zero/mutators/index.d.ts +1 -251
  61. package/dist/zero/mutators/index.d.ts.map +1 -1
  62. package/dist/zero/mutators/index.js +1 -11
  63. package/dist/zero/mutators/mutators.d.ts +17 -1519
  64. package/dist/zero/mutators/mutators.d.ts.map +1 -1
  65. package/dist/zero/mutators/mutators.js +38 -11
  66. package/dist/zero/mutators/threadMutators/index.d.ts +1 -1
  67. package/dist/zero/mutators/threadMutators/index.d.ts.map +1 -1
  68. package/dist/zero/mutators/threadMutators/index.js +1 -1
  69. package/dist/zero/mutators/threadMutators/threadMutators.d.ts +6 -199
  70. package/dist/zero/mutators/threadMutators/threadMutators.d.ts.map +1 -1
  71. package/dist/zero/mutators/threadMutators/threadMutators.js +87 -119
  72. package/dist/zero/mutators/threadMutators/threadMutators.test.d.ts +2 -0
  73. package/dist/zero/mutators/threadMutators/threadMutators.test.d.ts.map +1 -0
  74. package/dist/zero/mutators/threadMutators/threadMutators.test.js +755 -0
  75. package/dist/zero/mutators/userMutators/index.d.ts +1 -1
  76. package/dist/zero/mutators/userMutators/index.d.ts.map +1 -1
  77. package/dist/zero/mutators/userMutators/index.js +1 -1
  78. package/dist/zero/mutators/userMutators/userMutators.d.ts +3 -56
  79. package/dist/zero/mutators/userMutators/userMutators.d.ts.map +1 -1
  80. package/dist/zero/mutators/userMutators/userMutators.js +26 -40
  81. package/dist/zero/mutators/userMutators/userMutators.test.d.ts +2 -0
  82. package/dist/zero/mutators/userMutators/userMutators.test.d.ts.map +1 -0
  83. package/dist/zero/mutators/userMutators/userMutators.test.js +84 -0
  84. package/dist/zero/queries/getAccounts.d.ts +1025 -4
  85. package/dist/zero/queries/getAccounts.d.ts.map +1 -1
  86. package/dist/zero/queries/getAccounts.js +3 -6
  87. package/dist/zero/queries/getContacts.d.ts +1033 -18
  88. package/dist/zero/queries/getContacts.d.ts.map +1 -1
  89. package/dist/zero/queries/getContacts.js +15 -11
  90. package/dist/zero/queries/getDrafts.d.ts +1031 -11
  91. package/dist/zero/queries/getDrafts.d.ts.map +1 -1
  92. package/dist/zero/queries/getDrafts.js +11 -7
  93. package/dist/zero/queries/getThread.d.ts +1028 -7
  94. package/dist/zero/queries/getThread.d.ts.map +1 -1
  95. package/dist/zero/queries/getThread.js +9 -5
  96. package/dist/zero/queries/getThreadList.d.ts +1035 -23
  97. package/dist/zero/queries/getThreadList.d.ts.map +1 -1
  98. package/dist/zero/queries/getThreadList.js +18 -14
  99. package/dist/zero/queries/getThreads.d.ts +1035 -23
  100. package/dist/zero/queries/getThreads.d.ts.map +1 -1
  101. package/dist/zero/queries/getThreads.js +18 -14
  102. package/dist/zero/queries/getUser.d.ts +1025 -4
  103. package/dist/zero/queries/getUser.d.ts.map +1 -1
  104. package/dist/zero/queries/getUser.js +7 -10
  105. package/dist/zero/queries/index.d.ts +141 -460
  106. package/dist/zero/queries/index.d.ts.map +1 -1
  107. package/dist/zero/queries/index.js +10 -18
  108. package/dist/zero/schema.d.ts +133 -133
  109. package/dist/zero/schema.d.ts.map +1 -1
  110. package/dist/zero/schema.js +1 -0
  111. package/package.json +3 -2
  112. package/dist/zero/crud.d.ts +0 -1024
  113. package/dist/zero/crud.d.ts.map +0 -1
  114. package/dist/zero/crud.js +0 -3
  115. package/dist/zero/mutators/typedMutator.d.ts +0 -2056
  116. package/dist/zero/mutators/typedMutator.d.ts.map +0 -1
  117. package/dist/zero/mutators/typedMutator.js +0 -2
  118. package/dist/zero/queries/z.d.ts +0 -14439
  119. package/dist/zero/queries/z.d.ts.map +0 -1
  120. package/dist/zero/queries/z.js +0 -3
@@ -1,46 +1,14 @@
1
- import * as v from 'valibot';
2
- import { marcoSchemas } from '../../../schemas';
3
1
  import { MutationError } from '../../../types';
4
2
  import { threadsUtils } from '../../../utils/threads';
5
- import { zeroCRUD } from '../../../zero/crud';
6
- import { defineMutator } from '../../../zero/mutators/typedMutator';
7
- import { z } from '../../../zero/queries/z';
8
3
  const buildLabelIdList = (x) => (x.length === 0 ? '' : ` ${[...new Set(x)].join(' ')} `);
9
- const accountsSchema = v.record(marcoSchemas.string.required(), v.object({
10
- threadIds: v.array(marcoSchemas.string.required()),
11
- }));
12
- const baseThreadSchema = v.object({
13
- accounts: accountsSchema,
14
- });
15
- const threadChangeLabelSchema = v.object({
16
- accounts: accountsSchema,
17
- labelPath: marcoSchemas.string.required(),
18
- });
19
- export const threadMutatorSchemas = {
20
- addLabel: threadChangeLabelSchema,
21
- delete: baseThreadSchema,
22
- removeLabel: threadChangeLabelSchema,
23
- setArchive: baseThreadSchema,
24
- setFlagged: v.object({
25
- accounts: accountsSchema,
26
- flagged: v.nonOptional(v.boolean()),
27
- }),
28
- setInbox: baseThreadSchema,
29
- setSeen: v.object({
30
- accounts: accountsSchema,
31
- seen: v.boolean(),
32
- }),
33
- setSpam: baseThreadSchema,
34
- setTrash: baseThreadSchema,
35
- };
36
4
  export const setSystemLabel = async (tx, threadId, targetSpecialUse) => {
37
- const thread = await tx.run(z.thread.where('id', threadId).one());
5
+ const thread = await tx.query.thread.where('id', threadId).one().run();
38
6
  if (!thread) {
39
7
  throw new Error(MutationError.ENTITY_NOT_FOUND);
40
8
  }
41
9
  const [targetLabel, messages] = await Promise.all([
42
- tx.run(z.accountLabel.where('accountId', thread.accountId).where('specialUse', targetSpecialUse).one()),
43
- tx.run(z.threadMessage.where('threadId', threadId)),
10
+ tx.query.accountLabel.where('accountId', thread.accountId).where('specialUse', targetSpecialUse).one().run(),
11
+ tx.query.threadMessage.where('threadId', threadId).run(),
44
12
  ]);
45
13
  if (!targetLabel) {
46
14
  throw new Error(MutationError.ENTITY_NOT_FOUND);
@@ -52,28 +20,28 @@ export const setSystemLabel = async (tx, threadId, targetSpecialUse) => {
52
20
  const threadLabelDeletes = [];
53
21
  for (const message of messages) {
54
22
  for (const labelId of labelIdsToRemove) {
55
- threadLabelDeletes.push(tx.mutate(zeroCRUD.threadLabel.delete({
23
+ threadLabelDeletes.push(tx.mutate.threadLabel.delete({
56
24
  accountId: thread.accountId,
57
25
  labelId,
58
26
  threadMessageId: message.id,
59
- })));
27
+ }));
60
28
  }
61
29
  }
62
30
  await Promise.all([
63
31
  ...threadLabelDeletes,
64
- ...[...labelIdsToRemove].map(labelId => tx.mutate(zeroCRUD.threadByLabel.delete({ labelId, threadId }))),
32
+ ...[...labelIdsToRemove].map(labelId => tx.mutate.threadByLabel.delete({ labelId, threadId })),
65
33
  ]);
66
34
  if (thread.seen === false && labelIdsToRemove.size > 0) {
67
- const labelsToUpdate = await tx.run(z.accountLabel.where('id', 'IN', [...labelIdsToRemove]));
68
- await Promise.all(labelsToUpdate.map(label => tx.mutate(zeroCRUD.accountLabel.update({
35
+ const labelsToUpdate = await tx.query.accountLabel.where('id', 'IN', [...labelIdsToRemove]).run();
36
+ await Promise.all(labelsToUpdate.map(label => tx.mutate.accountLabel.update({
69
37
  id: label.id,
70
38
  unreadCount: Math.max(0, (label.unreadCount ?? 0) - 1),
71
- }))));
39
+ })));
72
40
  }
73
41
  if (!hasTarget) {
74
42
  const baseTimestamp = Date.now();
75
43
  await Promise.all([
76
- ...messages.map((message, i) => tx.mutate(zeroCRUD.threadLabel.insert({
44
+ ...messages.map((message, i) => tx.mutate.threadLabel.insert({
77
45
  accountId: thread.accountId,
78
46
  labelId: targetLabel.id,
79
47
  lastSyncedAt: 0,
@@ -81,38 +49,38 @@ export const setSystemLabel = async (tx, threadId, targetSpecialUse) => {
81
49
  threadMessageId: message.id,
82
50
  uid: -(baseTimestamp + i),
83
51
  uidValidity: targetLabel.uidValidity ?? 0,
84
- }))),
85
- tx.mutate(zeroCRUD.threadByLabel.insert({
52
+ })),
53
+ tx.mutate.threadByLabel.insert({
86
54
  labelId: targetLabel.id,
87
55
  latestMessageDate: thread.latestMessageDate,
88
56
  threadId,
89
- })),
57
+ }),
90
58
  ...(thread.seen === false
91
59
  ? [
92
- tx.mutate(zeroCRUD.accountLabel.update({
60
+ tx.mutate.accountLabel.update({
93
61
  id: targetLabel.id,
94
62
  unreadCount: (targetLabel.unreadCount ?? 0) + 1,
95
- })),
63
+ }),
96
64
  ]
97
65
  : []),
98
66
  ]);
99
67
  }
100
- await tx.mutate(zeroCRUD.thread.update({
68
+ await tx.mutate.thread.update({
101
69
  id: threadId,
102
70
  labelIdList: buildLabelIdList([targetLabel.id]),
103
- }));
71
+ });
104
72
  };
105
- export const threadMutators = {
106
- addLabel: defineMutator(threadMutatorSchemas.addLabel, async ({ tx, args: { accounts, labelPath } }) => {
107
- for (const [accountId, { threadIds }] of Object.entries(accounts)) {
108
- const label = await tx.run(z.accountLabel.where('accountId', accountId).where('path', labelPath).one());
73
+ export const createThreadMutators = (_authData) => ({
74
+ addLabel: async (tx, args) => {
75
+ for (const [accountId, { threadIds }] of Object.entries(args.accounts)) {
76
+ const label = await tx.query.accountLabel.where('accountId', accountId).where('path', args.labelPath).one().run();
109
77
  if (!label) {
110
78
  throw new Error(MutationError.ENTITY_NOT_FOUND);
111
79
  }
112
80
  for (const threadId of threadIds) {
113
81
  const [thread, messages] = await Promise.all([
114
- tx.run(z.thread.where('id', threadId).one()),
115
- tx.run(z.threadMessage.where('threadId', threadId)),
82
+ tx.query.thread.where('id', threadId).one().run(),
83
+ tx.query.threadMessage.where('threadId', threadId).run(),
116
84
  ]);
117
85
  if (!thread) {
118
86
  throw new Error(MutationError.ENTITY_NOT_FOUND);
@@ -120,26 +88,26 @@ export const threadMutators = {
120
88
  const currentLabelIds = new Set(threadsUtils.parseLabelIdList(thread.labelIdList));
121
89
  if (!currentLabelIds.has(label.id)) {
122
90
  await Promise.all([
123
- tx.mutate(zeroCRUD.threadByLabel.insert({
91
+ tx.mutate.threadByLabel.insert({
124
92
  labelId: label.id,
125
93
  latestMessageDate: thread.latestMessageDate,
126
94
  threadId,
127
- })),
95
+ }),
128
96
  ...(thread.seen === false
129
97
  ? [
130
- tx.mutate(zeroCRUD.accountLabel.update({
98
+ tx.mutate.accountLabel.update({
131
99
  id: label.id,
132
100
  unreadCount: (label.unreadCount ?? 0) + 1,
133
- })),
101
+ }),
134
102
  ]
135
103
  : []),
136
104
  ]);
137
105
  }
138
- const existingChecks = await Promise.all(messages.map(x => tx.run(z.threadLabel.where('threadMessageId', x.id).where('labelId', label.id).one())));
106
+ const existingChecks = await Promise.all(messages.map(x => tx.query.threadLabel.where('threadMessageId', x.id).where('labelId', label.id).one().run()));
139
107
  const messagesToInsert = messages.filter((_, i) => !existingChecks[i]);
140
108
  const baseTimestamp = Date.now();
141
109
  if (messagesToInsert.length > 0) {
142
- await Promise.all(messagesToInsert.map((x, i) => tx.mutate(zeroCRUD.threadLabel.insert({
110
+ await Promise.all(messagesToInsert.map((x, i) => tx.mutate.threadLabel.insert({
143
111
  accountId,
144
112
  labelId: label.id,
145
113
  lastSyncedAt: 0,
@@ -147,48 +115,48 @@ export const threadMutators = {
147
115
  threadMessageId: x.id,
148
116
  uid: -(baseTimestamp + i),
149
117
  uidValidity: label.uidValidity ?? 0,
150
- }))));
118
+ })));
151
119
  }
152
120
  currentLabelIds.add(label.id);
153
- await tx.mutate(zeroCRUD.thread.update({
121
+ await tx.mutate.thread.update({
154
122
  id: threadId,
155
123
  labelIdList: buildLabelIdList([...currentLabelIds]),
156
- }));
124
+ });
157
125
  }
158
126
  }
159
- }),
160
- delete: defineMutator(threadMutatorSchemas.delete, async ({ tx, args: { accounts } }) => {
161
- for (const [, { threadIds }] of Object.entries(accounts)) {
127
+ },
128
+ delete: async (tx, args) => {
129
+ for (const [, { threadIds }] of Object.entries(args.accounts)) {
162
130
  for (const threadId of threadIds) {
163
- const thread = await tx.run(z.thread.where('id', threadId).one());
131
+ const thread = await tx.query.thread.where('id', threadId).one().run();
164
132
  if (thread) {
165
133
  if (thread.seen === false) {
166
134
  const labelIds = threadsUtils.parseLabelIdList(thread.labelIdList);
167
135
  if (labelIds.length > 0) {
168
- const labels = await tx.run(z.accountLabel.where('id', 'IN', labelIds));
169
- await Promise.all(labels.map(x => tx.mutate(zeroCRUD.accountLabel.update({
136
+ const labels = await tx.query.accountLabel.where('id', 'IN', labelIds).run();
137
+ await Promise.all(labels.map(x => tx.mutate.accountLabel.update({
170
138
  id: x.id,
171
139
  unreadCount: Math.max(0, (x.unreadCount ?? 0) - 1),
172
- }))));
140
+ })));
173
141
  }
174
142
  }
175
- await tx.mutate(zeroCRUD.thread.delete({
143
+ await tx.mutate.thread.delete({
176
144
  id: threadId,
177
- }));
145
+ });
178
146
  }
179
147
  }
180
148
  }
181
- }),
182
- removeLabel: defineMutator(threadMutatorSchemas.removeLabel, async ({ tx, args: { accounts, labelPath } }) => {
183
- for (const [accountId, { threadIds }] of Object.entries(accounts)) {
184
- const label = await tx.run(z.accountLabel.where('accountId', accountId).where('path', labelPath).one());
149
+ },
150
+ removeLabel: async (tx, args) => {
151
+ for (const [accountId, { threadIds }] of Object.entries(args.accounts)) {
152
+ const label = await tx.query.accountLabel.where('accountId', accountId).where('path', args.labelPath).one().run();
185
153
  if (!label) {
186
154
  throw new Error(MutationError.ENTITY_NOT_FOUND);
187
155
  }
188
156
  for (const threadId of threadIds) {
189
157
  const [thread, messages] = await Promise.all([
190
- tx.run(z.thread.where('id', threadId).one()),
191
- tx.run(z.threadMessage.where('threadId', threadId)),
158
+ tx.query.thread.where('id', threadId).one().run(),
159
+ tx.query.threadMessage.where('threadId', threadId).run(),
192
160
  ]);
193
161
  if (!thread) {
194
162
  throw new Error(MutationError.ENTITY_NOT_FOUND);
@@ -199,91 +167,91 @@ export const threadMutators = {
199
167
  }
200
168
  currentLabelIds.delete(label.id);
201
169
  await Promise.all([
202
- ...messages.map(x => tx.mutate(zeroCRUD.threadLabel.delete({
170
+ ...messages.map(x => tx.mutate.threadLabel.delete({
203
171
  accountId,
204
172
  labelId: label.id,
205
173
  threadMessageId: x.id,
206
- }))),
207
- tx.mutate(zeroCRUD.threadByLabel.delete({
174
+ })),
175
+ tx.mutate.threadByLabel.delete({
208
176
  labelId: label.id,
209
177
  threadId,
210
- })),
178
+ }),
211
179
  ...(thread.seen === false
212
180
  ? [
213
- tx.mutate(zeroCRUD.accountLabel.update({
181
+ tx.mutate.accountLabel.update({
214
182
  id: label.id,
215
183
  unreadCount: Math.max(0, (label.unreadCount ?? 0) - 1),
216
- })),
184
+ }),
217
185
  ]
218
186
  : []),
219
- tx.mutate(zeroCRUD.thread.update({
187
+ tx.mutate.thread.update({
220
188
  id: threadId,
221
189
  labelIdList: buildLabelIdList([...currentLabelIds]),
222
- })),
190
+ }),
223
191
  ]);
224
192
  }
225
193
  }
226
- }),
227
- setArchive: defineMutator(threadMutatorSchemas.setArchive, async ({ tx, args: { accounts } }) => {
228
- for (const [, { threadIds }] of Object.entries(accounts)) {
194
+ },
195
+ setArchive: async (tx, args) => {
196
+ for (const [, { threadIds }] of Object.entries(args.accounts)) {
229
197
  for (const threadId of threadIds) {
230
198
  await setSystemLabel(tx, threadId, 'ARCHIVE');
231
199
  }
232
200
  }
233
- }),
234
- setFlagged: defineMutator(threadMutatorSchemas.setFlagged, async ({ tx, args: { accounts, flagged } }) => {
235
- for (const [, { threadIds }] of Object.entries(accounts)) {
236
- await Promise.all(threadIds.map(threadId => tx.mutate(zeroCRUD.thread.update({
237
- flagged,
201
+ },
202
+ setFlagged: async (tx, args) => {
203
+ for (const [, { threadIds }] of Object.entries(args.accounts)) {
204
+ await Promise.all(threadIds.map(threadId => tx.mutate.thread.update({
205
+ flagged: args.flagged,
238
206
  id: threadId,
239
- }))));
207
+ })));
240
208
  }
241
- }),
242
- setInbox: defineMutator(threadMutatorSchemas.setInbox, async ({ tx, args: { accounts } }) => {
243
- for (const [, { threadIds }] of Object.entries(accounts)) {
209
+ },
210
+ setInbox: async (tx, args) => {
211
+ for (const [, { threadIds }] of Object.entries(args.accounts)) {
244
212
  for (const threadId of threadIds) {
245
213
  await setSystemLabel(tx, threadId, 'INBOX');
246
214
  }
247
215
  }
248
- }),
249
- setSeen: defineMutator(threadMutatorSchemas.setSeen, async ({ tx, args: { accounts, seen } }) => {
250
- const allThreadIds = Object.values(accounts).flatMap(x => x.threadIds);
251
- const threads = await tx.run(z.thread.where('id', 'IN', allThreadIds));
216
+ },
217
+ setSeen: async (tx, args) => {
218
+ const allThreadIds = Object.values(args.accounts).flatMap(x => x.threadIds);
219
+ const threads = await tx.query.thread.where('id', 'IN', allThreadIds).run();
252
220
  const labelCounts = new Map();
253
221
  for (const thread of threads) {
254
- if (thread.seen !== seen) {
222
+ if (thread.seen !== args.seen) {
255
223
  for (const labelId of threadsUtils.parseLabelIdList(thread.labelIdList)) {
256
224
  labelCounts.set(labelId, (labelCounts.get(labelId) ?? 0) + 1);
257
225
  }
258
226
  }
259
227
  }
260
228
  if (labelCounts.size > 0) {
261
- const labels = await tx.run(z.accountLabel.where('id', 'IN', [...labelCounts.keys()]));
262
- const delta = seen ? -1 : 1;
229
+ const labels = await tx.query.accountLabel.where('id', 'IN', [...labelCounts.keys()]).run();
230
+ const delta = args.seen ? -1 : 1;
263
231
  await Promise.all(labels
264
232
  .filter(x => labelCounts.has(x.id))
265
- .map(x => tx.mutate(zeroCRUD.accountLabel.update({
233
+ .map(x => tx.mutate.accountLabel.update({
266
234
  id: x.id,
267
235
  unreadCount: Math.max(0, (x.unreadCount ?? 0) + delta * (labelCounts.get(x.id) ?? 0)),
268
- }))));
236
+ })));
269
237
  }
270
- await Promise.all(allThreadIds.map(threadId => tx.mutate(zeroCRUD.thread.update({
238
+ await Promise.all(allThreadIds.map(threadId => tx.mutate.thread.update({
271
239
  id: threadId,
272
- seen,
273
- }))));
274
- }),
275
- setSpam: defineMutator(threadMutatorSchemas.setSpam, async ({ tx, args: { accounts } }) => {
276
- for (const [, { threadIds }] of Object.entries(accounts)) {
240
+ seen: args.seen,
241
+ })));
242
+ },
243
+ setSpam: async (tx, args) => {
244
+ for (const [, { threadIds }] of Object.entries(args.accounts)) {
277
245
  for (const threadId of threadIds) {
278
246
  await setSystemLabel(tx, threadId, 'SPAM');
279
247
  }
280
248
  }
281
- }),
282
- setTrash: defineMutator(threadMutatorSchemas.setTrash, async ({ tx, args: { accounts } }) => {
283
- for (const [, { threadIds }] of Object.entries(accounts)) {
249
+ },
250
+ setTrash: async (tx, args) => {
251
+ for (const [, { threadIds }] of Object.entries(args.accounts)) {
284
252
  for (const threadId of threadIds) {
285
253
  await setSystemLabel(tx, threadId, 'TRASH');
286
254
  }
287
255
  }
288
- }),
289
- };
256
+ },
257
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=threadMutators.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"threadMutators.test.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/threadMutators/threadMutators.test.ts"],"names":[],"mappings":""}