@marcoappio/marco-config 2.0.521 → 2.0.523
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/types/Zero.d.ts +1 -2
- package/dist/types/Zero.d.ts.map +1 -1
- package/dist/types/Zero.js +0 -1
- package/dist/zero/mutators.d.ts.map +1 -1
- package/dist/zero/mutators.js +171 -183
- package/dist/zero/mutators.test.js +17 -11
- package/package.json +2 -2
package/dist/types/Zero.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { schema, tables } from '../zero/schema';
|
|
2
2
|
export declare enum MutationError {
|
|
3
3
|
AUTHENTICATION_REQUIRED = "MutationError/AUTHENTICATION_REQUIRED",
|
|
4
|
-
ALREADY_APPLIED = "MutationError/ALREADY_APPLIED"
|
|
5
|
-
ENTITY_NOT_FOUND = "MutationError/ENTITY_NOT_FOUND"
|
|
4
|
+
ALREADY_APPLIED = "MutationError/ALREADY_APPLIED"
|
|
6
5
|
}
|
|
7
6
|
export type MarcoZeroSchema = typeof schema;
|
|
8
7
|
export type MarcoZeroTables = typeof tables;
|
package/dist/types/Zero.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Zero.d.ts","sourceRoot":"","sources":["../../src/types/Zero.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAE/D,oBAAY,aAAa;IACvB,uBAAuB,0CAA0C;IACjE,eAAe,kCAAkC;
|
|
1
|
+
{"version":3,"file":"Zero.d.ts","sourceRoot":"","sources":["../../src/types/Zero.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAE/D,oBAAY,aAAa;IACvB,uBAAuB,0CAA0C;IACjE,eAAe,kCAAkC;CAClD;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,MAAM,CAAA;AAC3C,MAAM,MAAM,eAAe,GAAG,OAAO,MAAM,CAAA;AAC3C,MAAM,MAAM,gBAAgB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAEjD,OAAO,QAAQ,gBAAgB,CAAC;IAC9B,UAAU,YAAY;QACpB,MAAM,EAAE,OAAO,MAAM,CAAA;QACrB,OAAO,EAAE,gBAAgB,CAAA;KAC1B;CACF"}
|
package/dist/types/Zero.js
CHANGED
|
@@ -2,5 +2,4 @@ export var MutationError;
|
|
|
2
2
|
(function (MutationError) {
|
|
3
3
|
MutationError["AUTHENTICATION_REQUIRED"] = "MutationError/AUTHENTICATION_REQUIRED";
|
|
4
4
|
MutationError["ALREADY_APPLIED"] = "MutationError/ALREADY_APPLIED";
|
|
5
|
-
MutationError["ENTITY_NOT_FOUND"] = "MutationError/ENTITY_NOT_FOUND";
|
|
6
5
|
})(MutationError || (MutationError = {}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutators.d.ts","sourceRoot":"","sources":["../../src/zero/mutators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mutators.d.ts","sourceRoot":"","sources":["../../src/zero/mutators.ts"],"names":[],"mappings":"AAQA,KAAK,OAAO,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAqGjC,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6fnB,CAAA"}
|
package/dist/zero/mutators.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createBuilder, defineMutators, defineMutatorWithType } from '@rocicorp/zero';
|
|
2
|
-
import { MutationError } from '../types';
|
|
3
2
|
import { stringPatch } from '../utils';
|
|
4
3
|
import { threadsUtils } from '../utils/threads';
|
|
5
4
|
import { mutatorSchemas } from '../zero/mutatorSchemas';
|
|
@@ -9,72 +8,70 @@ const defineMutator = defineMutatorWithType();
|
|
|
9
8
|
const buildLabelIdList = (x) => (x.length === 0 ? '' : ` ${[...new Set(x)].join(' ')} `);
|
|
10
9
|
const setSystemLabel = async (tx, builder, threadId, targetSpecialUse) => {
|
|
11
10
|
const thread = await tx.run(builder.thread.where('id', threadId).one());
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
tx.run(builder.accountLabel.where('accountId', thread.accountId).where('specialUse', targetSpecialUse).one()),
|
|
17
|
-
tx.run(builder.threadMessage.where('threadId', threadId)),
|
|
18
|
-
]);
|
|
19
|
-
if (!targetLabel) {
|
|
20
|
-
throw new Error(MutationError.ENTITY_NOT_FOUND);
|
|
21
|
-
}
|
|
22
|
-
const currentLabelIds = new Set(threadsUtils.parseLabelIdList(thread.labelIdList));
|
|
23
|
-
const hasTarget = currentLabelIds.has(targetLabel.id);
|
|
24
|
-
const labelIdsToRemove = new Set(currentLabelIds);
|
|
25
|
-
labelIdsToRemove.delete(targetLabel.id);
|
|
26
|
-
const threadLabelDeletes = [];
|
|
27
|
-
for (const message of messages) {
|
|
28
|
-
for (const labelId of labelIdsToRemove) {
|
|
29
|
-
threadLabelDeletes.push(tx.mutate.threadLabel.delete({
|
|
30
|
-
accountId: thread.accountId,
|
|
31
|
-
labelId,
|
|
32
|
-
threadMessageId: message.id,
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
await Promise.all([
|
|
37
|
-
...threadLabelDeletes,
|
|
38
|
-
...[...labelIdsToRemove].map(labelId => tx.mutate.threadByLabel.delete({ labelId, threadId })),
|
|
39
|
-
]);
|
|
40
|
-
if (thread.seen === false && labelIdsToRemove.size > 0) {
|
|
41
|
-
const labelsToUpdate = await tx.run(builder.accountLabel.where('id', 'IN', [...labelIdsToRemove]));
|
|
42
|
-
await Promise.all(labelsToUpdate.map(label => tx.mutate.accountLabel.update({
|
|
43
|
-
id: label.id,
|
|
44
|
-
unreadCount: Math.max(0, (label.unreadCount ?? 0) - 1),
|
|
45
|
-
})));
|
|
46
|
-
}
|
|
47
|
-
if (!hasTarget) {
|
|
48
|
-
const baseTimestamp = Date.now();
|
|
49
|
-
await Promise.all([
|
|
50
|
-
...messages.map((message, i) => tx.mutate.threadLabel.insert({
|
|
51
|
-
accountId: thread.accountId,
|
|
52
|
-
labelId: targetLabel.id,
|
|
53
|
-
lastSyncedAt: 0,
|
|
54
|
-
threadId,
|
|
55
|
-
threadMessageId: message.id,
|
|
56
|
-
uid: -(baseTimestamp + i),
|
|
57
|
-
uidValidity: targetLabel.uidValidity ?? 0,
|
|
58
|
-
})),
|
|
59
|
-
tx.mutate.threadByLabel.insert({
|
|
60
|
-
labelId: targetLabel.id,
|
|
61
|
-
latestMessageDate: thread.latestMessageDate,
|
|
62
|
-
threadId,
|
|
63
|
-
}),
|
|
64
|
-
...(thread.seen === false
|
|
65
|
-
? [
|
|
66
|
-
tx.mutate.accountLabel.update({
|
|
67
|
-
id: targetLabel.id,
|
|
68
|
-
unreadCount: (targetLabel.unreadCount ?? 0) + 1,
|
|
69
|
-
}),
|
|
70
|
-
]
|
|
71
|
-
: []),
|
|
11
|
+
if (thread) {
|
|
12
|
+
const [targetLabel, messages] = await Promise.all([
|
|
13
|
+
tx.run(builder.accountLabel.where('accountId', thread.accountId).where('specialUse', targetSpecialUse).one()),
|
|
14
|
+
tx.run(builder.threadMessage.where('threadId', threadId)),
|
|
72
15
|
]);
|
|
16
|
+
if (targetLabel) {
|
|
17
|
+
const currentLabelIds = new Set(threadsUtils.parseLabelIdList(thread.labelIdList));
|
|
18
|
+
const hasTarget = currentLabelIds.has(targetLabel.id);
|
|
19
|
+
const labelIdsToRemove = new Set(currentLabelIds);
|
|
20
|
+
labelIdsToRemove.delete(targetLabel.id);
|
|
21
|
+
const threadLabelDeletes = [];
|
|
22
|
+
for (const message of messages) {
|
|
23
|
+
for (const labelId of labelIdsToRemove) {
|
|
24
|
+
threadLabelDeletes.push(tx.mutate.threadLabel.delete({
|
|
25
|
+
accountId: thread.accountId,
|
|
26
|
+
labelId,
|
|
27
|
+
threadMessageId: message.id,
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
await Promise.all([
|
|
32
|
+
...threadLabelDeletes,
|
|
33
|
+
...[...labelIdsToRemove].map(labelId => tx.mutate.threadByLabel.delete({ labelId, threadId })),
|
|
34
|
+
]);
|
|
35
|
+
if (thread.seen === false && labelIdsToRemove.size > 0) {
|
|
36
|
+
const labelsToUpdate = await tx.run(builder.accountLabel.where('id', 'IN', [...labelIdsToRemove]));
|
|
37
|
+
await Promise.all(labelsToUpdate.map(label => tx.mutate.accountLabel.update({
|
|
38
|
+
id: label.id,
|
|
39
|
+
unreadCount: Math.max(0, (label.unreadCount ?? 0) - 1),
|
|
40
|
+
})));
|
|
41
|
+
}
|
|
42
|
+
if (!hasTarget) {
|
|
43
|
+
const baseTimestamp = Date.now();
|
|
44
|
+
await Promise.all([
|
|
45
|
+
...messages.map((message, i) => tx.mutate.threadLabel.insert({
|
|
46
|
+
accountId: thread.accountId,
|
|
47
|
+
labelId: targetLabel.id,
|
|
48
|
+
lastSyncedAt: 0,
|
|
49
|
+
threadId,
|
|
50
|
+
threadMessageId: message.id,
|
|
51
|
+
uid: -(baseTimestamp + i),
|
|
52
|
+
uidValidity: targetLabel.uidValidity ?? 0,
|
|
53
|
+
})),
|
|
54
|
+
tx.mutate.threadByLabel.insert({
|
|
55
|
+
labelId: targetLabel.id,
|
|
56
|
+
latestMessageDate: thread.latestMessageDate,
|
|
57
|
+
threadId,
|
|
58
|
+
}),
|
|
59
|
+
...(thread.seen === false
|
|
60
|
+
? [
|
|
61
|
+
tx.mutate.accountLabel.update({
|
|
62
|
+
id: targetLabel.id,
|
|
63
|
+
unreadCount: (targetLabel.unreadCount ?? 0) + 1,
|
|
64
|
+
}),
|
|
65
|
+
]
|
|
66
|
+
: []),
|
|
67
|
+
]);
|
|
68
|
+
}
|
|
69
|
+
await tx.mutate.thread.update({
|
|
70
|
+
id: threadId,
|
|
71
|
+
labelIdList: buildLabelIdList([targetLabel.id]),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
73
74
|
}
|
|
74
|
-
await tx.mutate.thread.update({
|
|
75
|
-
id: threadId,
|
|
76
|
-
labelIdList: buildLabelIdList([targetLabel.id]),
|
|
77
|
-
});
|
|
78
75
|
};
|
|
79
76
|
export const mutators = defineMutators({
|
|
80
77
|
account: {
|
|
@@ -179,18 +176,16 @@ export const mutators = defineMutators({
|
|
|
179
176
|
draft: {
|
|
180
177
|
cancelSend: defineMutator(mutatorSchemas.draft.cancelSend, async ({ tx, args }) => {
|
|
181
178
|
const draft = await tx.run(zql.draft.where('id', args.id).one());
|
|
182
|
-
if (
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
179
|
+
if (draft) {
|
|
180
|
+
if (draft.status !== 'SEND_CONFIRMED') {
|
|
181
|
+
await tx.mutate.draft.update({
|
|
182
|
+
id: args.id,
|
|
183
|
+
scheduledFor: null,
|
|
184
|
+
status: 'DRAFT',
|
|
185
|
+
updatedAt: args.updatedAt,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
187
188
|
}
|
|
188
|
-
await tx.mutate.draft.update({
|
|
189
|
-
id: args.id,
|
|
190
|
-
scheduledFor: null,
|
|
191
|
-
status: 'DRAFT',
|
|
192
|
-
updatedAt: args.updatedAt,
|
|
193
|
-
});
|
|
194
189
|
}),
|
|
195
190
|
createAttachment: defineMutator(mutatorSchemas.draft.createAttachment, async ({ tx, args }) => {
|
|
196
191
|
await tx.mutate.draftAttachment.insert({
|
|
@@ -273,34 +268,32 @@ export const mutators = defineMutators({
|
|
|
273
268
|
}),
|
|
274
269
|
setContent: defineMutator(mutatorSchemas.draft.setContent, async ({ tx, args }) => {
|
|
275
270
|
const draft = await tx.run(zql.draft.where('id', args.id).one());
|
|
276
|
-
if (
|
|
277
|
-
|
|
271
|
+
if (draft) {
|
|
272
|
+
await tx.mutate.draft.update({
|
|
273
|
+
body: {
|
|
274
|
+
...draft.body,
|
|
275
|
+
content: stringPatch.apply(typeof draft.body?.content === 'string' ? draft.body.content : '', args.patch),
|
|
276
|
+
},
|
|
277
|
+
id: args.id,
|
|
278
|
+
updatedAt: args.updatedAt,
|
|
279
|
+
});
|
|
278
280
|
}
|
|
279
|
-
await tx.mutate.draft.update({
|
|
280
|
-
body: {
|
|
281
|
-
...draft.body,
|
|
282
|
-
content: stringPatch.apply(typeof draft.body?.content === 'string' ? draft.body.content : '', args.patch),
|
|
283
|
-
},
|
|
284
|
-
id: args.id,
|
|
285
|
-
updatedAt: args.updatedAt,
|
|
286
|
-
});
|
|
287
281
|
}),
|
|
288
282
|
setEnvelope: defineMutator(mutatorSchemas.draft.setEnvelope, async ({ tx, args }) => {
|
|
289
283
|
const draft = await tx.run(zql.draft.where('id', args.id).one());
|
|
290
|
-
if (
|
|
291
|
-
|
|
284
|
+
if (draft) {
|
|
285
|
+
await tx.mutate.draft.update({
|
|
286
|
+
body: {
|
|
287
|
+
bcc: args.envelope.bcc,
|
|
288
|
+
cc: args.envelope.cc,
|
|
289
|
+
content: draft.body.content,
|
|
290
|
+
to: args.envelope.to,
|
|
291
|
+
},
|
|
292
|
+
id: args.id,
|
|
293
|
+
subject: args.envelope.subject,
|
|
294
|
+
updatedAt: args.updatedAt,
|
|
295
|
+
});
|
|
292
296
|
}
|
|
293
|
-
await tx.mutate.draft.update({
|
|
294
|
-
body: {
|
|
295
|
-
bcc: args.envelope.bcc,
|
|
296
|
-
cc: args.envelope.cc,
|
|
297
|
-
content: draft.body.content,
|
|
298
|
-
to: args.envelope.to,
|
|
299
|
-
},
|
|
300
|
-
id: args.id,
|
|
301
|
-
subject: args.envelope.subject,
|
|
302
|
-
updatedAt: args.updatedAt,
|
|
303
|
-
});
|
|
304
297
|
}),
|
|
305
298
|
setFrom: defineMutator(mutatorSchemas.draft.setFrom, async ({ tx, args }) => {
|
|
306
299
|
await tx.mutate.draft.update({
|
|
@@ -317,54 +310,52 @@ export const mutators = defineMutators({
|
|
|
317
310
|
addLabel: defineMutator(mutatorSchemas.thread.addLabel, async ({ tx, args }) => {
|
|
318
311
|
for (const [accountId, { threadIds }] of Object.entries(args.accounts)) {
|
|
319
312
|
const label = await tx.run(zql.accountLabel.where('accountId', accountId).where('path', args.labelPath).one());
|
|
320
|
-
if (
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
tx.run(zql.thread.where('id', threadId).one()),
|
|
326
|
-
tx.run(zql.threadMessage.where('threadId', threadId)),
|
|
327
|
-
]);
|
|
328
|
-
if (!thread) {
|
|
329
|
-
throw new Error(MutationError.ENTITY_NOT_FOUND);
|
|
330
|
-
}
|
|
331
|
-
const currentLabelIds = new Set(threadsUtils.parseLabelIdList(thread.labelIdList));
|
|
332
|
-
if (!currentLabelIds.has(label.id)) {
|
|
333
|
-
await Promise.all([
|
|
334
|
-
tx.mutate.threadByLabel.insert({
|
|
335
|
-
labelId: label.id,
|
|
336
|
-
latestMessageDate: thread.latestMessageDate,
|
|
337
|
-
threadId,
|
|
338
|
-
}),
|
|
339
|
-
...(thread.seen === false
|
|
340
|
-
? [
|
|
341
|
-
tx.mutate.accountLabel.update({
|
|
342
|
-
id: label.id,
|
|
343
|
-
unreadCount: (label.unreadCount ?? 0) + 1,
|
|
344
|
-
}),
|
|
345
|
-
]
|
|
346
|
-
: []),
|
|
313
|
+
if (label) {
|
|
314
|
+
for (const threadId of threadIds) {
|
|
315
|
+
const [thread, messages] = await Promise.all([
|
|
316
|
+
tx.run(zql.thread.where('id', threadId).one()),
|
|
317
|
+
tx.run(zql.threadMessage.where('threadId', threadId)),
|
|
347
318
|
]);
|
|
319
|
+
if (thread) {
|
|
320
|
+
const currentLabelIds = new Set(threadsUtils.parseLabelIdList(thread.labelIdList));
|
|
321
|
+
if (!currentLabelIds.has(label.id)) {
|
|
322
|
+
await Promise.all([
|
|
323
|
+
tx.mutate.threadByLabel.insert({
|
|
324
|
+
labelId: label.id,
|
|
325
|
+
latestMessageDate: thread.latestMessageDate,
|
|
326
|
+
threadId,
|
|
327
|
+
}),
|
|
328
|
+
...(thread.seen === false
|
|
329
|
+
? [
|
|
330
|
+
tx.mutate.accountLabel.update({
|
|
331
|
+
id: label.id,
|
|
332
|
+
unreadCount: (label.unreadCount ?? 0) + 1,
|
|
333
|
+
}),
|
|
334
|
+
]
|
|
335
|
+
: []),
|
|
336
|
+
]);
|
|
337
|
+
}
|
|
338
|
+
const existingChecks = await Promise.all(messages.map(x => tx.run(zql.threadLabel.where('threadMessageId', x.id).where('labelId', label.id).one())));
|
|
339
|
+
const messagesToInsert = messages.filter((_, i) => !existingChecks[i]);
|
|
340
|
+
const baseTimestamp = Date.now();
|
|
341
|
+
if (messagesToInsert.length > 0) {
|
|
342
|
+
await Promise.all(messagesToInsert.map((x, i) => tx.mutate.threadLabel.insert({
|
|
343
|
+
accountId,
|
|
344
|
+
labelId: label.id,
|
|
345
|
+
lastSyncedAt: 0,
|
|
346
|
+
threadId,
|
|
347
|
+
threadMessageId: x.id,
|
|
348
|
+
uid: -(baseTimestamp + i),
|
|
349
|
+
uidValidity: label.uidValidity ?? 0,
|
|
350
|
+
})));
|
|
351
|
+
}
|
|
352
|
+
currentLabelIds.add(label.id);
|
|
353
|
+
await tx.mutate.thread.update({
|
|
354
|
+
id: threadId,
|
|
355
|
+
labelIdList: buildLabelIdList([...currentLabelIds]),
|
|
356
|
+
});
|
|
357
|
+
}
|
|
348
358
|
}
|
|
349
|
-
const existingChecks = await Promise.all(messages.map(x => tx.run(zql.threadLabel.where('threadMessageId', x.id).where('labelId', label.id).one())));
|
|
350
|
-
const messagesToInsert = messages.filter((_, i) => !existingChecks[i]);
|
|
351
|
-
const baseTimestamp = Date.now();
|
|
352
|
-
if (messagesToInsert.length > 0) {
|
|
353
|
-
await Promise.all(messagesToInsert.map((x, i) => tx.mutate.threadLabel.insert({
|
|
354
|
-
accountId,
|
|
355
|
-
labelId: label.id,
|
|
356
|
-
lastSyncedAt: 0,
|
|
357
|
-
threadId,
|
|
358
|
-
threadMessageId: x.id,
|
|
359
|
-
uid: -(baseTimestamp + i),
|
|
360
|
-
uidValidity: label.uidValidity ?? 0,
|
|
361
|
-
})));
|
|
362
|
-
}
|
|
363
|
-
currentLabelIds.add(label.id);
|
|
364
|
-
await tx.mutate.thread.update({
|
|
365
|
-
id: threadId,
|
|
366
|
-
labelIdList: buildLabelIdList([...currentLabelIds]),
|
|
367
|
-
});
|
|
368
359
|
}
|
|
369
360
|
}
|
|
370
361
|
}),
|
|
@@ -393,45 +384,42 @@ export const mutators = defineMutators({
|
|
|
393
384
|
removeLabel: defineMutator(mutatorSchemas.thread.removeLabel, async ({ tx, args }) => {
|
|
394
385
|
for (const [accountId, { threadIds }] of Object.entries(args.accounts)) {
|
|
395
386
|
const label = await tx.run(zql.accountLabel.where('accountId', accountId).where('path', args.labelPath).one());
|
|
396
|
-
if (
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
387
|
+
if (label) {
|
|
388
|
+
for (const threadId of threadIds) {
|
|
389
|
+
const [thread, messages] = await Promise.all([
|
|
390
|
+
tx.run(zql.thread.where('id', threadId).one()),
|
|
391
|
+
tx.run(zql.threadMessage.where('threadId', threadId)),
|
|
392
|
+
]);
|
|
393
|
+
if (thread) {
|
|
394
|
+
const currentLabelIds = new Set(threadsUtils.parseLabelIdList(thread.labelIdList));
|
|
395
|
+
if (currentLabelIds.has(label.id)) {
|
|
396
|
+
currentLabelIds.delete(label.id);
|
|
397
|
+
await Promise.all([
|
|
398
|
+
...messages.map(x => tx.mutate.threadLabel.delete({
|
|
399
|
+
accountId,
|
|
400
|
+
labelId: label.id,
|
|
401
|
+
threadMessageId: x.id,
|
|
402
|
+
})),
|
|
403
|
+
tx.mutate.threadByLabel.delete({
|
|
404
|
+
labelId: label.id,
|
|
405
|
+
threadId,
|
|
406
|
+
}),
|
|
407
|
+
...(thread.seen === false
|
|
408
|
+
? [
|
|
409
|
+
tx.mutate.accountLabel.update({
|
|
410
|
+
id: label.id,
|
|
411
|
+
unreadCount: Math.max(0, (label.unreadCount ?? 0) - 1),
|
|
412
|
+
}),
|
|
413
|
+
]
|
|
414
|
+
: []),
|
|
415
|
+
tx.mutate.thread.update({
|
|
416
|
+
id: threadId,
|
|
417
|
+
labelIdList: buildLabelIdList([...currentLabelIds]),
|
|
418
|
+
}),
|
|
419
|
+
]);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
410
422
|
}
|
|
411
|
-
currentLabelIds.delete(label.id);
|
|
412
|
-
await Promise.all([
|
|
413
|
-
...messages.map(x => tx.mutate.threadLabel.delete({
|
|
414
|
-
accountId,
|
|
415
|
-
labelId: label.id,
|
|
416
|
-
threadMessageId: x.id,
|
|
417
|
-
})),
|
|
418
|
-
tx.mutate.threadByLabel.delete({
|
|
419
|
-
labelId: label.id,
|
|
420
|
-
threadId,
|
|
421
|
-
}),
|
|
422
|
-
...(thread.seen === false
|
|
423
|
-
? [
|
|
424
|
-
tx.mutate.accountLabel.update({
|
|
425
|
-
id: label.id,
|
|
426
|
-
unreadCount: Math.max(0, (label.unreadCount ?? 0) - 1),
|
|
427
|
-
}),
|
|
428
|
-
]
|
|
429
|
-
: []),
|
|
430
|
-
tx.mutate.thread.update({
|
|
431
|
-
id: threadId,
|
|
432
|
-
labelIdList: buildLabelIdList([...currentLabelIds]),
|
|
433
|
-
}),
|
|
434
|
-
]);
|
|
435
423
|
}
|
|
436
424
|
}
|
|
437
425
|
}),
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it, mock } from 'bun:test';
|
|
2
|
-
import { MutationError } from '../types';
|
|
3
2
|
import { mutators } from './mutators';
|
|
4
3
|
const createMockTx = () => ({
|
|
5
4
|
mutate: {
|
|
@@ -212,15 +211,17 @@ describe('mutators', () => {
|
|
|
212
211
|
updatedAt: 1234567890,
|
|
213
212
|
});
|
|
214
213
|
});
|
|
215
|
-
it('
|
|
214
|
+
it('does nothing if draft not found', async () => {
|
|
216
215
|
tx.run = mock(() => Promise.resolve(null));
|
|
217
216
|
const args = { id: 'draft-1', updatedAt: 1234567890 };
|
|
218
|
-
await
|
|
217
|
+
await mutators.draft.cancelSend.fn({ args, ctx, tx: tx });
|
|
218
|
+
expect(tx.mutate.draft.update).not.toHaveBeenCalled();
|
|
219
219
|
});
|
|
220
|
-
it('
|
|
220
|
+
it('does nothing if already confirmed', async () => {
|
|
221
221
|
tx.run = mock(() => Promise.resolve({ status: 'SEND_CONFIRMED' }));
|
|
222
222
|
const args = { id: 'draft-1', updatedAt: 1234567890 };
|
|
223
|
-
await
|
|
223
|
+
await mutators.draft.cancelSend.fn({ args, ctx, tx: tx });
|
|
224
|
+
expect(tx.mutate.draft.update).not.toHaveBeenCalled();
|
|
224
225
|
});
|
|
225
226
|
});
|
|
226
227
|
describe('createAttachment', () => {
|
|
@@ -354,10 +355,11 @@ describe('mutators', () => {
|
|
|
354
355
|
updatedAt: 1234567890,
|
|
355
356
|
});
|
|
356
357
|
});
|
|
357
|
-
it('
|
|
358
|
+
it('does nothing if draft not found', async () => {
|
|
358
359
|
tx.run = mock(() => Promise.resolve(null));
|
|
359
360
|
const args = { id: 'draft-1', patch: [], updatedAt: 1234567890 };
|
|
360
|
-
await
|
|
361
|
+
await mutators.draft.setContent.fn({ args, ctx, tx: tx });
|
|
362
|
+
expect(tx.mutate.draft.update).not.toHaveBeenCalled();
|
|
361
363
|
});
|
|
362
364
|
});
|
|
363
365
|
describe('setEnvelope', () => {
|
|
@@ -428,13 +430,15 @@ describe('mutators', () => {
|
|
|
428
430
|
labelIdList: expect.stringContaining('label-1'),
|
|
429
431
|
});
|
|
430
432
|
});
|
|
431
|
-
it('
|
|
433
|
+
it('does nothing if label not found', async () => {
|
|
432
434
|
tx.run = mock(() => Promise.resolve(null));
|
|
433
435
|
const args = {
|
|
434
436
|
accounts: { 'account-1': { threadIds: ['thread-1'] } },
|
|
435
437
|
labelPath: 'NONEXISTENT',
|
|
436
438
|
};
|
|
437
|
-
await
|
|
439
|
+
await mutators.thread.addLabel.fn({ args, ctx, tx: tx });
|
|
440
|
+
expect(tx.mutate.thread.update).not.toHaveBeenCalled();
|
|
441
|
+
expect(tx.mutate.threadByLabel.insert).not.toHaveBeenCalled();
|
|
438
442
|
});
|
|
439
443
|
});
|
|
440
444
|
describe('delete', () => {
|
|
@@ -477,7 +481,7 @@ describe('mutators', () => {
|
|
|
477
481
|
});
|
|
478
482
|
expect(tx.mutate.accountLabel.update).toHaveBeenCalledWith({ id: 'label-1', unreadCount: 4 });
|
|
479
483
|
});
|
|
480
|
-
it('
|
|
484
|
+
it('does nothing if thread does not have label', async () => {
|
|
481
485
|
tx.run = mock()
|
|
482
486
|
.mockResolvedValueOnce({ id: 'label-1' })
|
|
483
487
|
.mockResolvedValueOnce({ id: 'thread-1', labelIdList: ' label-2 ' })
|
|
@@ -486,7 +490,9 @@ describe('mutators', () => {
|
|
|
486
490
|
accounts: { 'account-1': { threadIds: ['thread-1'] } },
|
|
487
491
|
labelPath: 'INBOX',
|
|
488
492
|
};
|
|
489
|
-
await
|
|
493
|
+
await mutators.thread.removeLabel.fn({ args, ctx, tx: tx });
|
|
494
|
+
expect(tx.mutate.threadLabel.delete).not.toHaveBeenCalled();
|
|
495
|
+
expect(tx.mutate.threadByLabel.delete).not.toHaveBeenCalled();
|
|
490
496
|
});
|
|
491
497
|
});
|
|
492
498
|
describe('setFlagged', () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marcoappio/marco-config",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.523",
|
|
4
4
|
"author": "team@marcoapp.io",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": "git@github.com:marcoappio/marco-config.git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@orama/stemmers": "3.1.16",
|
|
29
29
|
"@orama/stopwords": "3.1.16",
|
|
30
|
-
"@rocicorp/zero": "0.25.
|
|
30
|
+
"@rocicorp/zero": "0.25.7",
|
|
31
31
|
"diff": "8.0.2",
|
|
32
32
|
"valibot": "1.1.0"
|
|
33
33
|
},
|