@marcoappio/marco-config 2.0.508 → 2.0.509
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/types/Zero.d.ts +0 -17
- package/dist/types/Zero.d.ts.map +1 -1
- package/dist/zero/index.d.ts +2903 -8808
- package/dist/zero/index.d.ts.map +1 -1
- package/dist/zero/index.js +6 -17
- package/dist/zero/{queries/getThreadList.d.ts → mutators.d.ts} +572 -169
- package/dist/zero/{queries/getThreads.d.ts.map → mutators.d.ts.map} +1 -1
- package/dist/zero/mutators.js +659 -0
- package/dist/zero/mutators.test.d.ts +2 -0
- package/dist/zero/mutators.test.d.ts.map +1 -0
- package/dist/zero/mutators.test.js +603 -0
- package/dist/zero/{queries/getThreads.d.ts → queries.d.ts} +481 -196
- package/dist/zero/{queries/getThread.d.ts.map → queries.d.ts.map} +1 -1
- package/dist/zero/queries.js +168 -0
- package/dist/zero/schema.d.ts +138 -133
- package/dist/zero/schema.d.ts.map +1 -1
- package/dist/zero/schema.js +1 -1
- package/package.json +3 -3
- package/dist/zero/mutatorSchemas/account.d.ts +0 -80
- package/dist/zero/mutatorSchemas/account.d.ts.map +0 -1
- package/dist/zero/mutatorSchemas/account.js +0 -66
- package/dist/zero/mutatorSchemas/draft.d.ts +0 -150
- package/dist/zero/mutatorSchemas/draft.d.ts.map +0 -1
- package/dist/zero/mutatorSchemas/draft.js +0 -104
- package/dist/zero/mutatorSchemas/index.d.ts +0 -323
- package/dist/zero/mutatorSchemas/index.d.ts.map +0 -1
- package/dist/zero/mutatorSchemas/index.js +0 -10
- package/dist/zero/mutatorSchemas/thread.d.ts +0 -71
- package/dist/zero/mutatorSchemas/thread.d.ts.map +0 -1
- package/dist/zero/mutatorSchemas/thread.js +0 -47
- package/dist/zero/mutatorSchemas/user.d.ts +0 -26
- package/dist/zero/mutatorSchemas/user.d.ts.map +0 -1
- package/dist/zero/mutatorSchemas/user.js +0 -27
- package/dist/zero/mutators/accountMutators/accountMutators.d.ts +0 -4
- package/dist/zero/mutators/accountMutators/accountMutators.d.ts.map +0 -1
- package/dist/zero/mutators/accountMutators/accountMutators.js +0 -103
- package/dist/zero/mutators/accountMutators/accountMutators.test.d.ts +0 -2
- package/dist/zero/mutators/accountMutators/accountMutators.test.d.ts.map +0 -1
- package/dist/zero/mutators/accountMutators/accountMutators.test.js +0 -372
- package/dist/zero/mutators/accountMutators/index.d.ts +0 -2
- package/dist/zero/mutators/accountMutators/index.d.ts.map +0 -1
- package/dist/zero/mutators/accountMutators/index.js +0 -1
- package/dist/zero/mutators/draftMutators/draftMutators.d.ts +0 -4
- package/dist/zero/mutators/draftMutators/draftMutators.d.ts.map +0 -1
- package/dist/zero/mutators/draftMutators/draftMutators.js +0 -142
- package/dist/zero/mutators/draftMutators/draftMutators.test.d.ts +0 -2
- package/dist/zero/mutators/draftMutators/draftMutators.test.d.ts.map +0 -1
- package/dist/zero/mutators/draftMutators/draftMutators.test.js +0 -416
- package/dist/zero/mutators/draftMutators/index.d.ts +0 -2
- package/dist/zero/mutators/draftMutators/index.d.ts.map +0 -1
- package/dist/zero/mutators/draftMutators/index.js +0 -1
- package/dist/zero/mutators/index.d.ts +0 -3
- package/dist/zero/mutators/index.d.ts.map +0 -1
- package/dist/zero/mutators/index.js +0 -1
- package/dist/zero/mutators/mutators.d.ts +0 -18
- package/dist/zero/mutators/mutators.d.ts.map +0 -1
- package/dist/zero/mutators/mutators.js +0 -39
- package/dist/zero/mutators/threadMutators/index.d.ts +0 -2
- package/dist/zero/mutators/threadMutators/index.d.ts.map +0 -1
- package/dist/zero/mutators/threadMutators/index.js +0 -1
- package/dist/zero/mutators/threadMutators/threadMutators.d.ts +0 -8
- package/dist/zero/mutators/threadMutators/threadMutators.d.ts.map +0 -1
- package/dist/zero/mutators/threadMutators/threadMutators.js +0 -257
- package/dist/zero/mutators/threadMutators/threadMutators.test.d.ts +0 -2
- package/dist/zero/mutators/threadMutators/threadMutators.test.d.ts.map +0 -1
- package/dist/zero/mutators/threadMutators/threadMutators.test.js +0 -755
- package/dist/zero/mutators/userMutators/index.d.ts +0 -2
- package/dist/zero/mutators/userMutators/index.d.ts.map +0 -1
- package/dist/zero/mutators/userMutators/index.js +0 -1
- package/dist/zero/mutators/userMutators/userMutators.d.ts +0 -4
- package/dist/zero/mutators/userMutators/userMutators.d.ts.map +0 -1
- package/dist/zero/mutators/userMutators/userMutators.js +0 -28
- package/dist/zero/mutators/userMutators/userMutators.test.d.ts +0 -2
- package/dist/zero/mutators/userMutators/userMutators.test.d.ts.map +0 -1
- package/dist/zero/mutators/userMutators/userMutators.test.js +0 -84
- package/dist/zero/queries/getAccounts.d.ts +0 -1060
- package/dist/zero/queries/getAccounts.d.ts.map +0 -1
- package/dist/zero/queries/getAccounts.js +0 -3
- package/dist/zero/queries/getContacts.d.ts +0 -1040
- package/dist/zero/queries/getContacts.d.ts.map +0 -1
- package/dist/zero/queries/getContacts.js +0 -37
- package/dist/zero/queries/getDrafts.d.ts +0 -1061
- package/dist/zero/queries/getDrafts.d.ts.map +0 -1
- package/dist/zero/queries/getDrafts.js +0 -24
- package/dist/zero/queries/getThread.d.ts +0 -1072
- package/dist/zero/queries/getThread.js +0 -14
- package/dist/zero/queries/getThreadByMessageId.d.ts +0 -1056
- package/dist/zero/queries/getThreadByMessageId.d.ts.map +0 -1
- package/dist/zero/queries/getThreadByMessageId.js +0 -13
- package/dist/zero/queries/getThreadList.d.ts.map +0 -1
- package/dist/zero/queries/getThreadList.js +0 -57
- package/dist/zero/queries/getThreads.js +0 -59
- package/dist/zero/queries/getUser.d.ts +0 -1074
- package/dist/zero/queries/getUser.d.ts.map +0 -1
- package/dist/zero/queries/getUser.js +0 -7
- package/dist/zero/queries/index.d.ts +0 -1032
- package/dist/zero/queries/index.d.ts.map +0 -1
- package/dist/zero/queries/index.js +0 -11
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import { MutationError } from '../../../types';
|
|
2
|
-
import { threadsUtils } from '../../../utils/threads';
|
|
3
|
-
const buildLabelIdList = (x) => (x.length === 0 ? '' : ` ${[...new Set(x)].join(' ')} `);
|
|
4
|
-
export const setSystemLabel = async (tx, threadId, targetSpecialUse) => {
|
|
5
|
-
const thread = await tx.query.thread.where('id', threadId).one().run();
|
|
6
|
-
if (!thread) {
|
|
7
|
-
throw new Error(MutationError.ENTITY_NOT_FOUND);
|
|
8
|
-
}
|
|
9
|
-
const [targetLabel, messages] = await Promise.all([
|
|
10
|
-
tx.query.accountLabel.where('accountId', thread.accountId).where('specialUse', targetSpecialUse).one().run(),
|
|
11
|
-
tx.query.threadMessage.where('threadId', threadId).run(),
|
|
12
|
-
]);
|
|
13
|
-
if (!targetLabel) {
|
|
14
|
-
throw new Error(MutationError.ENTITY_NOT_FOUND);
|
|
15
|
-
}
|
|
16
|
-
const currentLabelIds = new Set(threadsUtils.parseLabelIdList(thread.labelIdList));
|
|
17
|
-
const hasTarget = currentLabelIds.has(targetLabel.id);
|
|
18
|
-
const labelIdsToRemove = new Set(currentLabelIds);
|
|
19
|
-
labelIdsToRemove.delete(targetLabel.id);
|
|
20
|
-
const threadLabelDeletes = [];
|
|
21
|
-
for (const message of messages) {
|
|
22
|
-
for (const labelId of labelIdsToRemove) {
|
|
23
|
-
threadLabelDeletes.push(tx.mutate.threadLabel.delete({
|
|
24
|
-
accountId: thread.accountId,
|
|
25
|
-
labelId,
|
|
26
|
-
threadMessageId: message.id,
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
await Promise.all([
|
|
31
|
-
...threadLabelDeletes,
|
|
32
|
-
...[...labelIdsToRemove].map(labelId => tx.mutate.threadByLabel.delete({ labelId, threadId })),
|
|
33
|
-
]);
|
|
34
|
-
if (thread.seen === false && labelIdsToRemove.size > 0) {
|
|
35
|
-
const labelsToUpdate = await tx.query.accountLabel.where('id', 'IN', [...labelIdsToRemove]).run();
|
|
36
|
-
await Promise.all(labelsToUpdate.map(label => tx.mutate.accountLabel.update({
|
|
37
|
-
id: label.id,
|
|
38
|
-
unreadCount: Math.max(0, (label.unreadCount ?? 0) - 1),
|
|
39
|
-
})));
|
|
40
|
-
}
|
|
41
|
-
if (!hasTarget) {
|
|
42
|
-
const baseTimestamp = Date.now();
|
|
43
|
-
await Promise.all([
|
|
44
|
-
...messages.map((message, i) => tx.mutate.threadLabel.insert({
|
|
45
|
-
accountId: thread.accountId,
|
|
46
|
-
labelId: targetLabel.id,
|
|
47
|
-
lastSyncedAt: 0,
|
|
48
|
-
threadId,
|
|
49
|
-
threadMessageId: message.id,
|
|
50
|
-
uid: -(baseTimestamp + i),
|
|
51
|
-
uidValidity: targetLabel.uidValidity ?? 0,
|
|
52
|
-
})),
|
|
53
|
-
tx.mutate.threadByLabel.insert({
|
|
54
|
-
labelId: targetLabel.id,
|
|
55
|
-
latestMessageDate: thread.latestMessageDate,
|
|
56
|
-
threadId,
|
|
57
|
-
}),
|
|
58
|
-
...(thread.seen === false
|
|
59
|
-
? [
|
|
60
|
-
tx.mutate.accountLabel.update({
|
|
61
|
-
id: targetLabel.id,
|
|
62
|
-
unreadCount: (targetLabel.unreadCount ?? 0) + 1,
|
|
63
|
-
}),
|
|
64
|
-
]
|
|
65
|
-
: []),
|
|
66
|
-
]);
|
|
67
|
-
}
|
|
68
|
-
await tx.mutate.thread.update({
|
|
69
|
-
id: threadId,
|
|
70
|
-
labelIdList: buildLabelIdList([targetLabel.id]),
|
|
71
|
-
});
|
|
72
|
-
};
|
|
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();
|
|
77
|
-
if (!label) {
|
|
78
|
-
throw new Error(MutationError.ENTITY_NOT_FOUND);
|
|
79
|
-
}
|
|
80
|
-
for (const threadId of threadIds) {
|
|
81
|
-
const [thread, messages] = await Promise.all([
|
|
82
|
-
tx.query.thread.where('id', threadId).one().run(),
|
|
83
|
-
tx.query.threadMessage.where('threadId', threadId).run(),
|
|
84
|
-
]);
|
|
85
|
-
if (!thread) {
|
|
86
|
-
throw new Error(MutationError.ENTITY_NOT_FOUND);
|
|
87
|
-
}
|
|
88
|
-
const currentLabelIds = new Set(threadsUtils.parseLabelIdList(thread.labelIdList));
|
|
89
|
-
if (!currentLabelIds.has(label.id)) {
|
|
90
|
-
await Promise.all([
|
|
91
|
-
tx.mutate.threadByLabel.insert({
|
|
92
|
-
labelId: label.id,
|
|
93
|
-
latestMessageDate: thread.latestMessageDate,
|
|
94
|
-
threadId,
|
|
95
|
-
}),
|
|
96
|
-
...(thread.seen === false
|
|
97
|
-
? [
|
|
98
|
-
tx.mutate.accountLabel.update({
|
|
99
|
-
id: label.id,
|
|
100
|
-
unreadCount: (label.unreadCount ?? 0) + 1,
|
|
101
|
-
}),
|
|
102
|
-
]
|
|
103
|
-
: []),
|
|
104
|
-
]);
|
|
105
|
-
}
|
|
106
|
-
const existingChecks = await Promise.all(messages.map(x => tx.query.threadLabel.where('threadMessageId', x.id).where('labelId', label.id).one().run()));
|
|
107
|
-
const messagesToInsert = messages.filter((_, i) => !existingChecks[i]);
|
|
108
|
-
const baseTimestamp = Date.now();
|
|
109
|
-
if (messagesToInsert.length > 0) {
|
|
110
|
-
await Promise.all(messagesToInsert.map((x, i) => tx.mutate.threadLabel.insert({
|
|
111
|
-
accountId,
|
|
112
|
-
labelId: label.id,
|
|
113
|
-
lastSyncedAt: 0,
|
|
114
|
-
threadId,
|
|
115
|
-
threadMessageId: x.id,
|
|
116
|
-
uid: -(baseTimestamp + i),
|
|
117
|
-
uidValidity: label.uidValidity ?? 0,
|
|
118
|
-
})));
|
|
119
|
-
}
|
|
120
|
-
currentLabelIds.add(label.id);
|
|
121
|
-
await tx.mutate.thread.update({
|
|
122
|
-
id: threadId,
|
|
123
|
-
labelIdList: buildLabelIdList([...currentLabelIds]),
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
delete: async (tx, args) => {
|
|
129
|
-
for (const [, { threadIds }] of Object.entries(args.accounts)) {
|
|
130
|
-
for (const threadId of threadIds) {
|
|
131
|
-
const thread = await tx.query.thread.where('id', threadId).one().run();
|
|
132
|
-
if (thread) {
|
|
133
|
-
if (thread.seen === false) {
|
|
134
|
-
const labelIds = threadsUtils.parseLabelIdList(thread.labelIdList);
|
|
135
|
-
if (labelIds.length > 0) {
|
|
136
|
-
const labels = await tx.query.accountLabel.where('id', 'IN', labelIds).run();
|
|
137
|
-
await Promise.all(labels.map(x => tx.mutate.accountLabel.update({
|
|
138
|
-
id: x.id,
|
|
139
|
-
unreadCount: Math.max(0, (x.unreadCount ?? 0) - 1),
|
|
140
|
-
})));
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
await tx.mutate.thread.delete({
|
|
144
|
-
id: threadId,
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
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();
|
|
153
|
-
if (!label) {
|
|
154
|
-
throw new Error(MutationError.ENTITY_NOT_FOUND);
|
|
155
|
-
}
|
|
156
|
-
for (const threadId of threadIds) {
|
|
157
|
-
const [thread, messages] = await Promise.all([
|
|
158
|
-
tx.query.thread.where('id', threadId).one().run(),
|
|
159
|
-
tx.query.threadMessage.where('threadId', threadId).run(),
|
|
160
|
-
]);
|
|
161
|
-
if (!thread) {
|
|
162
|
-
throw new Error(MutationError.ENTITY_NOT_FOUND);
|
|
163
|
-
}
|
|
164
|
-
const currentLabelIds = new Set(threadsUtils.parseLabelIdList(thread.labelIdList));
|
|
165
|
-
if (!currentLabelIds.has(label.id)) {
|
|
166
|
-
throw new Error(MutationError.ENTITY_NOT_FOUND);
|
|
167
|
-
}
|
|
168
|
-
currentLabelIds.delete(label.id);
|
|
169
|
-
await Promise.all([
|
|
170
|
-
...messages.map(x => tx.mutate.threadLabel.delete({
|
|
171
|
-
accountId,
|
|
172
|
-
labelId: label.id,
|
|
173
|
-
threadMessageId: x.id,
|
|
174
|
-
})),
|
|
175
|
-
tx.mutate.threadByLabel.delete({
|
|
176
|
-
labelId: label.id,
|
|
177
|
-
threadId,
|
|
178
|
-
}),
|
|
179
|
-
...(thread.seen === false
|
|
180
|
-
? [
|
|
181
|
-
tx.mutate.accountLabel.update({
|
|
182
|
-
id: label.id,
|
|
183
|
-
unreadCount: Math.max(0, (label.unreadCount ?? 0) - 1),
|
|
184
|
-
}),
|
|
185
|
-
]
|
|
186
|
-
: []),
|
|
187
|
-
tx.mutate.thread.update({
|
|
188
|
-
id: threadId,
|
|
189
|
-
labelIdList: buildLabelIdList([...currentLabelIds]),
|
|
190
|
-
}),
|
|
191
|
-
]);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
setArchive: async (tx, args) => {
|
|
196
|
-
for (const [, { threadIds }] of Object.entries(args.accounts)) {
|
|
197
|
-
for (const threadId of threadIds) {
|
|
198
|
-
await setSystemLabel(tx, threadId, 'ARCHIVE');
|
|
199
|
-
}
|
|
200
|
-
}
|
|
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,
|
|
206
|
-
id: threadId,
|
|
207
|
-
})));
|
|
208
|
-
}
|
|
209
|
-
},
|
|
210
|
-
setInbox: async (tx, args) => {
|
|
211
|
-
for (const [, { threadIds }] of Object.entries(args.accounts)) {
|
|
212
|
-
for (const threadId of threadIds) {
|
|
213
|
-
await setSystemLabel(tx, threadId, 'INBOX');
|
|
214
|
-
}
|
|
215
|
-
}
|
|
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();
|
|
220
|
-
const labelCounts = new Map();
|
|
221
|
-
for (const thread of threads) {
|
|
222
|
-
if (thread.seen !== args.seen) {
|
|
223
|
-
for (const labelId of threadsUtils.parseLabelIdList(thread.labelIdList)) {
|
|
224
|
-
labelCounts.set(labelId, (labelCounts.get(labelId) ?? 0) + 1);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
if (labelCounts.size > 0) {
|
|
229
|
-
const labels = await tx.query.accountLabel.where('id', 'IN', [...labelCounts.keys()]).run();
|
|
230
|
-
const delta = args.seen ? -1 : 1;
|
|
231
|
-
await Promise.all(labels
|
|
232
|
-
.filter(x => labelCounts.has(x.id))
|
|
233
|
-
.map(x => tx.mutate.accountLabel.update({
|
|
234
|
-
id: x.id,
|
|
235
|
-
unreadCount: Math.max(0, (x.unreadCount ?? 0) + delta * (labelCounts.get(x.id) ?? 0)),
|
|
236
|
-
})));
|
|
237
|
-
}
|
|
238
|
-
await Promise.all(allThreadIds.map(threadId => tx.mutate.thread.update({
|
|
239
|
-
id: threadId,
|
|
240
|
-
seen: args.seen,
|
|
241
|
-
})));
|
|
242
|
-
},
|
|
243
|
-
setSpam: async (tx, args) => {
|
|
244
|
-
for (const [, { threadIds }] of Object.entries(args.accounts)) {
|
|
245
|
-
for (const threadId of threadIds) {
|
|
246
|
-
await setSystemLabel(tx, threadId, 'SPAM');
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
setTrash: async (tx, args) => {
|
|
251
|
-
for (const [, { threadIds }] of Object.entries(args.accounts)) {
|
|
252
|
-
for (const threadId of threadIds) {
|
|
253
|
-
await setSystemLabel(tx, threadId, 'TRASH');
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
},
|
|
257
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"threadMutators.test.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/threadMutators/threadMutators.test.ts"],"names":[],"mappings":""}
|