@marcoappio/marco-config 2.0.490 → 2.0.492

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 (25) hide show
  1. package/dist/zero/index.d.ts +28 -46
  2. package/dist/zero/index.d.ts.map +1 -1
  3. package/dist/zero/mutatorSchemas/index.d.ts +27 -45
  4. package/dist/zero/mutatorSchemas/index.d.ts.map +1 -1
  5. package/dist/zero/mutatorSchemas/thread.d.ts +27 -45
  6. package/dist/zero/mutatorSchemas/thread.d.ts.map +1 -1
  7. package/dist/zero/mutatorSchemas/thread.js +12 -20
  8. package/dist/zero/mutators/accountMutators/accountMutators.d.ts +1 -5
  9. package/dist/zero/mutators/accountMutators/accountMutators.d.ts.map +1 -1
  10. package/dist/zero/mutators/accountMutators/accountMutators.js +1 -10
  11. package/dist/zero/mutators/accountMutators/accountMutators.test.js +4 -22
  12. package/dist/zero/mutators/draftMutators/draftMutators.d.ts +1 -5
  13. package/dist/zero/mutators/draftMutators/draftMutators.d.ts.map +1 -1
  14. package/dist/zero/mutators/draftMutators/draftMutators.js +5 -16
  15. package/dist/zero/mutators/mutators.d.ts +3 -14
  16. package/dist/zero/mutators/mutators.d.ts.map +1 -1
  17. package/dist/zero/mutators/mutators.js +5 -5
  18. package/dist/zero/mutators/threadMutators/threadMutators.d.ts +1 -5
  19. package/dist/zero/mutators/threadMutators/threadMutators.d.ts.map +1 -1
  20. package/dist/zero/mutators/threadMutators/threadMutators.js +130 -122
  21. package/dist/zero/mutators/threadMutators/threadMutators.test.js +14 -14
  22. package/dist/zero/mutators/userMutators/userMutators.d.ts +1 -5
  23. package/dist/zero/mutators/userMutators/userMutators.d.ts.map +1 -1
  24. package/dist/zero/mutators/userMutators/userMutators.js +1 -4
  25. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { MutationError } from '../../../types';
2
- export const createAccountMutators = (authData, callbacks) => ({
2
+ export const createAccountMutators = (authData) => ({
3
3
  createAccount: async (tx, args) => {
4
4
  if (!authData) {
5
5
  throw new Error(MutationError.AUTHENTICATION_REQUIRED);
@@ -21,7 +21,6 @@ export const createAccountMutators = (authData, callbacks) => ({
21
21
  isPrimary: true,
22
22
  name: null,
23
23
  });
24
- callbacks?.createAccount?.(args);
25
24
  },
26
25
  createAlias: async (tx, args) => {
27
26
  await tx.mutate.accountAlias.insert({
@@ -31,13 +30,11 @@ export const createAccountMutators = (authData, callbacks) => ({
31
30
  isPrimary: false,
32
31
  name: args.alias.name ?? null,
33
32
  });
34
- callbacks?.createAlias?.(args);
35
33
  },
36
34
  deleteAccount: async (tx, args) => {
37
35
  await tx.mutate.account.delete({
38
36
  id: args.id,
39
37
  });
40
- callbacks?.deleteAccount?.(args);
41
38
  },
42
39
  deleteAlias: async (tx, args) => {
43
40
  const alias = await tx.query.accountAlias.where('id', args.aliasId).one().run();
@@ -64,14 +61,12 @@ export const createAccountMutators = (authData, callbacks) => ({
64
61
  });
65
62
  }
66
63
  }
67
- callbacks?.deleteAlias?.(args);
68
64
  },
69
65
  setAliasName: async (tx, args) => {
70
66
  await tx.mutate.accountAlias.update({
71
67
  id: args.aliasId,
72
68
  name: args.displayName,
73
69
  });
74
- callbacks?.setAliasName?.(args);
75
70
  },
76
71
  setAliasPrimary: async (tx, args) => {
77
72
  const aliases = await tx.query.accountAlias.where('accountId', args.accountId).run();
@@ -85,21 +80,18 @@ export const createAccountMutators = (authData, callbacks) => ({
85
80
  id: args.accountId,
86
81
  primaryAliasId: args.aliasId,
87
82
  });
88
- callbacks?.setAliasPrimary?.(args);
89
83
  },
90
84
  setConnectionConfigImapRaw: async (tx, args) => {
91
85
  await tx.mutate.account.update({
92
86
  id: args.id,
93
87
  imapConnectionStatus: 'AWAITING_CONNECTION',
94
88
  });
95
- callbacks?.setConnectionConfigImapRaw?.(args);
96
89
  },
97
90
  setConnectionConfigOauth: async (tx, args) => {
98
91
  await tx.mutate.account.update({
99
92
  id: args.id,
100
93
  imapConnectionStatus: 'AWAITING_CONNECTION',
101
94
  });
102
- callbacks?.setConnectionConfigOauth?.(args);
103
95
  },
104
96
  setSettings: async (tx, args) => {
105
97
  await tx.mutate.account.update({
@@ -107,6 +99,5 @@ export const createAccountMutators = (authData, callbacks) => ({
107
99
  displayName: args.displayName ? args.displayName : undefined,
108
100
  id: args.id,
109
101
  });
110
- callbacks?.setSettings?.(args);
111
102
  },
112
103
  });
@@ -2,15 +2,10 @@ import { describe, expect, it, mock } from 'bun:test';
2
2
  import { createMutators, ZeroMutatorValidationError } from '../mutators';
3
3
  describe('accountMutators', () => {
4
4
  describe('createAccount', () => {
5
- it('creates an account and invokes the callback', async () => {
5
+ it('creates an account', async () => {
6
6
  const accountInsert = mock(async () => { });
7
7
  const accountAliasInsert = mock(async () => { });
8
- const createAccountCallback = mock(() => { });
9
- const mutators = createMutators({ sub: 'test-user-id' }, {
10
- account: {
11
- createAccount: createAccountCallback,
12
- },
13
- });
8
+ const mutators = createMutators({ sub: 'test-user-id' });
14
9
  const payload = {
15
10
  aliasId: 'test-alias-id-1',
16
11
  color: '#ff0000',
@@ -50,7 +45,6 @@ describe('accountMutators', () => {
50
45
  isPrimary: true,
51
46
  name: null,
52
47
  });
53
- expect(createAccountCallback).toHaveBeenCalledWith(payload);
54
48
  expect(accountInsert.mock.invocationCallOrder[0]).toBeLessThan(accountAliasInsert.mock.invocationCallOrder[0]);
55
49
  });
56
50
  it('throws ZeroMutatorValidationError on invalid payloads', async () => {
@@ -69,12 +63,7 @@ describe('accountMutators', () => {
69
63
  describe('createAlias', () => {
70
64
  it('creates an alias', async () => {
71
65
  const accountAliasInsert = mock(async () => { });
72
- const createAliasCallback = mock(() => { });
73
- const mutators = createMutators({ sub: 'test-user-id' }, {
74
- account: {
75
- createAlias: createAliasCallback,
76
- },
77
- });
66
+ const mutators = createMutators({ sub: 'test-user-id' });
78
67
  const transaction = {
79
68
  mutate: {
80
69
  accountAlias: {
@@ -100,18 +89,12 @@ describe('accountMutators', () => {
100
89
  isPrimary: false,
101
90
  name: 'Work Email',
102
91
  });
103
- expect(createAliasCallback).toHaveBeenCalled();
104
92
  });
105
93
  });
106
94
  describe('deleteAccount', () => {
107
95
  it('deletes an account', async () => {
108
96
  const accountDelete = mock(async () => { });
109
- const deleteAccountCallback = mock(() => { });
110
- const mutators = createMutators({ sub: 'test-user-id' }, {
111
- account: {
112
- deleteAccount: deleteAccountCallback,
113
- },
114
- });
97
+ const mutators = createMutators({ sub: 'test-user-id' });
115
98
  const transaction = {
116
99
  mutate: {
117
100
  account: {
@@ -128,7 +111,6 @@ describe('accountMutators', () => {
128
111
  expect(accountDelete).toHaveBeenCalledWith({
129
112
  id: 'test-account-id-1',
130
113
  });
131
- expect(deleteAccountCallback).toHaveBeenCalled();
132
114
  });
133
115
  });
134
116
  describe('deleteAlias', () => {
@@ -1,8 +1,4 @@
1
- import type * as v from 'valibot';
2
1
  import { type AuthData, type HandlerMap } from '../../../types';
3
2
  import type { ZeroMutatorSchemas } from '../../../zero/mutatorSchemas';
4
- export type DraftMutatorCallbacks = {
5
- [K in keyof ZeroMutatorSchemas['draft']]?: (args: v.InferOutput<ZeroMutatorSchemas['draft'][K]['delta']>) => Promise<void>;
6
- };
7
- export declare const createDraftMutators: (authData: AuthData | undefined, callbacks?: DraftMutatorCallbacks) => HandlerMap<ZeroMutatorSchemas["draft"]>;
3
+ export declare const createDraftMutators: (authData: AuthData | undefined) => HandlerMap<ZeroMutatorSchemas["draft"]>;
8
4
  //# sourceMappingURL=draftMutators.d.ts.map
@@ -1 +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,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAE3E,MAAM,MAAM,qBAAqB,GAAG;KACjC,CAAC,IAAI,MAAM,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CACzC,IAAI,EAAE,CAAC,CAAC,WAAW,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KACzD,OAAO,CAAC,IAAI,CAAC;CACnB,CAAA;AAED,eAAO,MAAM,mBAAmB,aACpB,QAAQ,GAAG,SAAS,cAClB,qBAAqB,KAChC,UAAU,CAAC,kBAAkB,CAAC,OAAO,CAAC,CA2KvC,CAAA"}
1
+ {"version":3,"file":"draftMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/draftMutators/draftMutators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAiB,MAAM,qBAAqB,CAAA;AAEnF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAE3E,eAAO,MAAM,mBAAmB,aAAc,QAAQ,GAAG,SAAS,KAAG,UAAU,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAwJzG,CAAA"}
@@ -1,6 +1,6 @@
1
1
  import { MutationError } from '../../../types';
2
2
  import { stringPatch } from '../../../utils';
3
- export const createDraftMutators = (authData, callbacks) => ({
3
+ export const createDraftMutators = (authData) => ({
4
4
  cancelSend: async (tx, args) => {
5
5
  const draft = await tx.query.draft.where('id', args.id).one().run();
6
6
  if (!draft) {
@@ -15,7 +15,6 @@ export const createDraftMutators = (authData, callbacks) => ({
15
15
  status: 'DRAFT',
16
16
  updatedAt: args.updatedAt,
17
17
  });
18
- callbacks?.cancelSend?.(args);
19
18
  },
20
19
  createAttachment: async (tx, args) => {
21
20
  await tx.mutate.draftAttachment.insert({
@@ -30,7 +29,6 @@ export const createDraftMutators = (authData, callbacks) => ({
30
29
  id: args.id,
31
30
  updatedAt: args.updatedAt,
32
31
  });
33
- callbacks?.createAttachment?.(args);
34
32
  },
35
33
  createDraft: async (tx, args) => {
36
34
  if (!authData) {
@@ -67,7 +65,6 @@ export const createDraftMutators = (authData, callbacks) => ({
67
65
  totalSize: attachment.totalSize,
68
66
  });
69
67
  }
70
- callbacks?.createDraft?.(args);
71
68
  },
72
69
  deleteAttachment: async (tx, args) => {
73
70
  await tx.mutate.draftAttachment.delete({
@@ -77,13 +74,11 @@ export const createDraftMutators = (authData, callbacks) => ({
77
74
  id: args.id,
78
75
  updatedAt: args.updatedAt,
79
76
  });
80
- callbacks?.deleteAttachment?.(args);
81
77
  },
82
78
  deleteDraft: async (tx, args) => {
83
79
  await tx.mutate.draft.delete({
84
80
  id: args.id,
85
81
  });
86
- callbacks?.deleteDraft?.(args);
87
82
  },
88
83
  scheduleSend: async (tx, args) => {
89
84
  if (args.kind === 'IMMEDIATE') {
@@ -102,24 +97,20 @@ export const createDraftMutators = (authData, callbacks) => ({
102
97
  updatedAt: args.updatedAt,
103
98
  });
104
99
  }
105
- callbacks?.scheduleSend?.(args);
106
100
  },
107
101
  setContent: async (tx, args) => {
108
102
  const draft = await tx.query.draft.where('id', args.id).one().run();
109
103
  if (!draft) {
110
104
  throw new Error(MutationError.ENTITY_NOT_FOUND);
111
105
  }
112
- const currentContent = typeof draft.body?.content === 'string' ? draft.body.content : '';
113
- const updatedBody = {
114
- ...draft.body,
115
- content: stringPatch.apply(currentContent, args.patch),
116
- };
117
106
  await tx.mutate.draft.update({
118
- body: updatedBody,
107
+ body: {
108
+ ...draft.body,
109
+ content: stringPatch.apply(typeof draft.body?.content === 'string' ? draft.body.content : '', args.patch),
110
+ },
119
111
  id: args.id,
120
112
  updatedAt: args.updatedAt,
121
113
  });
122
- callbacks?.setContent?.(args);
123
114
  },
124
115
  setEnvelope: async (tx, args) => {
125
116
  const draft = await tx.query.draft.where('id', args.id).one().run();
@@ -137,7 +128,6 @@ export const createDraftMutators = (authData, callbacks) => ({
137
128
  subject: args.envelope.subject,
138
129
  updatedAt: args.updatedAt,
139
130
  });
140
- callbacks?.setEnvelope?.(args);
141
131
  },
142
132
  setFrom: async (tx, args) => {
143
133
  await tx.mutate.draft.update({
@@ -148,6 +138,5 @@ export const createDraftMutators = (authData, callbacks) => ({
148
138
  id: args.id,
149
139
  updatedAt: args.updatedAt,
150
140
  });
151
- callbacks?.setFrom?.(args);
152
141
  },
153
142
  });
@@ -1,15 +1,8 @@
1
1
  import * as v from 'valibot';
2
2
  import type { MutatorMap } from '../../types';
3
3
  import { type ZeroMutatorSchemas } from '../../zero/mutatorSchemas';
4
- import { type AccountMutatorCallbacks } from './accountMutators';
5
- import { type DraftMutatorCallbacks } from './draftMutators';
6
- import { type ThreadMutatorCallbacks } from './threadMutators';
7
- import { type UserMutatorCallbacks } from './userMutators';
8
- export type MutatorCallbacks = {
9
- account?: AccountMutatorCallbacks;
10
- draft?: DraftMutatorCallbacks;
11
- thread?: ThreadMutatorCallbacks;
12
- user?: UserMutatorCallbacks;
4
+ export type AuthData = {
5
+ sub: string;
13
6
  };
14
7
  export declare class ZeroMutatorValidationError extends Error {
15
8
  readonly issues: ReturnType<typeof v.flatten>;
@@ -21,9 +14,5 @@ export type MarcoZeroMutators = {
21
14
  thread: MutatorMap<ZeroMutatorSchemas['thread']>;
22
15
  user: MutatorMap<ZeroMutatorSchemas['user']>;
23
16
  };
24
- export declare const createMutators: (authData?: AuthData, callbacks?: MutatorCallbacks) => MarcoZeroMutators;
25
- export type { AccountMutatorCallbacks, DraftMutatorCallbacks, ThreadMutatorCallbacks, UserMutatorCallbacks };
26
- export type AuthData = {
27
- sub: string;
28
- };
17
+ export declare const createMutators: (authData?: AuthData) => MarcoZeroMutators;
29
18
  //# sourceMappingURL=mutators.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mutators.d.ts","sourceRoot":"","sources":["../../../src/zero/mutators/mutators.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,OAAO,KAAK,EAAkD,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAC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}
1
+ {"version":3,"file":"mutators.d.ts","sourceRoot":"","sources":["../../../src/zero/mutators/mutators.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,OAAO,KAAK,EAAkD,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrG,OAAO,EAAE,KAAK,kBAAkB,EAAsB,MAAM,mCAAmC,CAAA;AAQ/F,MAAM,MAAM,QAAQ,GAAG;IACrB,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AA8BD,qBAAa,0BAA2B,SAAQ,KAAK;IACvC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;gBAApC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;CAG1D;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,UAAU,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC,CAAA;IAClD,KAAK,EAAE,UAAU,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAA;IAC9C,MAAM,EAAE,UAAU,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAA;IAChD,IAAI,EAAE,UAAU,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAA;CAC7C,CAAA;AAED,eAAO,MAAM,cAAc,cAAe,QAAQ,KAAG,iBAKnD,CAAA"}
@@ -31,9 +31,9 @@ export class ZeroMutatorValidationError extends Error {
31
31
  this.issues = issues;
32
32
  }
33
33
  }
34
- export const createMutators = (authData, callbacks) => ({
35
- account: buildMutatorMap(zeroMutatorSchemas.account, createAccountMutators(authData, callbacks?.account)),
36
- draft: buildMutatorMap(zeroMutatorSchemas.draft, createDraftMutators(authData, callbacks?.draft)),
37
- thread: buildMutatorMap(zeroMutatorSchemas.thread, createThreadMutators(authData, callbacks?.thread)),
38
- user: buildMutatorMap(zeroMutatorSchemas.user, createUserMutators(authData, callbacks?.user)),
34
+ export const createMutators = (authData) => ({
35
+ account: buildMutatorMap(zeroMutatorSchemas.account, createAccountMutators(authData)),
36
+ draft: buildMutatorMap(zeroMutatorSchemas.draft, createDraftMutators(authData)),
37
+ thread: buildMutatorMap(zeroMutatorSchemas.thread, createThreadMutators(authData)),
38
+ user: buildMutatorMap(zeroMutatorSchemas.user, createUserMutators(authData)),
39
39
  });
@@ -1,12 +1,8 @@
1
1
  import type { Transaction } from '@rocicorp/zero';
2
- import type * as v from 'valibot';
3
2
  import type { LabelSpecialUse } from '../../../types';
4
3
  import { type AuthData, type HandlerMap } from '../../../types';
5
4
  import type { ZeroMutatorSchemas } from '../../../zero/mutatorSchemas';
6
5
  import type { MarcoZeroSchema } from '../../../zero/schema';
7
- export type ThreadMutatorCallbacks = {
8
- [K in keyof ZeroMutatorSchemas['thread']]?: (args: v.InferOutput<ZeroMutatorSchemas['thread'][K]['delta']>) => Promise<void>;
9
- };
10
6
  export declare const setSystemLabel: (tx: Transaction<MarcoZeroSchema>, threadId: string, targetSpecialUse: LabelSpecialUse) => Promise<void>;
11
- export declare const createThreadMutators: (_authData: AuthData | undefined, callbacks?: ThreadMutatorCallbacks) => HandlerMap<ZeroMutatorSchemas["thread"]>;
7
+ export declare const createThreadMutators: (_authData: AuthData | undefined) => HandlerMap<ZeroMutatorSchemas["thread"]>;
12
8
  //# sourceMappingURL=threadMutators.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"threadMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/threadMutators/threadMutators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,KAAK,CAAC,MAAM,SAAS,CAAA;AAEjC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAiB,MAAM,qBAAqB,CAAA;AAEnF,OAAO,KAAK,EAAE,kBAAk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 +1,6 @@
1
1
  import { MutationError } from '../../../types';
2
2
  import { threadsUtils } from '../../../utils/threads';
3
- const buildLabelIdList = (labelIds) => labelIds.length === 0 ? '' : ` ${[...new Set(labelIds)].join(' ')} `;
3
+ const buildLabelIdList = (x) => (x.length === 0 ? '' : ` ${[...new Set(x)].join(' ')} `);
4
4
  export const setSystemLabel = async (tx, threadId, targetSpecialUse) => {
5
5
  const thread = await tx.query.thread.where('id', threadId).one().run();
6
6
  if (!thread) {
@@ -70,146 +70,153 @@ export const setSystemLabel = async (tx, threadId, targetSpecialUse) => {
70
70
  labelIdList: buildLabelIdList([targetLabel.id]),
71
71
  });
72
72
  };
73
- export const createThreadMutators = (_authData, callbacks) => ({
73
+ export const createThreadMutators = (_authData) => ({
74
74
  addLabel: async (tx, args) => {
75
- for (const threadId of args.threadIds) {
76
- const thread = await tx.query.thread.where('id', threadId).one().run();
77
- if (!thread) {
78
- throw new Error(MutationError.ENTITY_NOT_FOUND);
79
- }
80
- const [label, messages] = await Promise.all([
81
- tx.query.accountLabel.where('accountId', thread.accountId).where('path', args.labelPath).one().run(),
82
- tx.query.threadMessage.where('threadId', threadId).run(),
83
- ]);
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();
84
77
  if (!label) {
85
78
  throw new Error(MutationError.ENTITY_NOT_FOUND);
86
79
  }
87
- const currentLabelIds = new Set(threadsUtils.parseLabelIdList(thread.labelIdList));
88
- if (!currentLabelIds.has(label.id)) {
89
- await Promise.all([
90
- tx.mutate.threadByLabel.insert({
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,
91
112
  labelId: label.id,
92
- latestMessageDate: thread.latestMessageDate,
113
+ lastSyncedAt: 0,
93
114
  threadId,
94
- }),
95
- ...(thread.seen === false
96
- ? [
97
- tx.mutate.accountLabel.update({
98
- id: label.id,
99
- unreadCount: (label.unreadCount ?? 0) + 1,
100
- }),
101
- ]
102
- : []),
103
- ]);
104
- }
105
- const existingChecks = await Promise.all(messages.map(message => tx.query.threadLabel.where('threadMessageId', message.id).where('labelId', label.id).one().run()));
106
- const messagesToInsert = messages.filter((_, i) => !existingChecks[i]);
107
- const baseTimestamp = Date.now();
108
- if (messagesToInsert.length > 0) {
109
- await Promise.all(messagesToInsert.map((message, i) => tx.mutate.threadLabel.insert({
110
- accountId: thread.accountId,
111
- labelId: label.id,
112
- lastSyncedAt: 0,
113
- threadId,
114
- threadMessageId: message.id,
115
- uid: -(baseTimestamp + i),
116
- uidValidity: label.uidValidity ?? 0,
117
- })));
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
+ });
118
125
  }
119
- currentLabelIds.add(label.id);
120
- await tx.mutate.thread.update({
121
- id: threadId,
122
- labelIdList: buildLabelIdList([...currentLabelIds]),
123
- });
124
126
  }
125
- callbacks?.addLabel?.(args);
126
127
  },
127
128
  delete: async (tx, args) => {
128
- for (const threadId of args.threadIds) {
129
- const thread = await tx.query.thread.where('id', threadId).one().run();
130
- if (thread) {
131
- if (thread.seen === false) {
132
- const labelIds = threadsUtils.parseLabelIdList(thread.labelIdList);
133
- if (labelIds.length > 0) {
134
- const labels = await tx.query.accountLabel.where('id', 'IN', labelIds).run();
135
- await Promise.all(labels.map(label => tx.mutate.accountLabel.update({
136
- id: label.id,
137
- unreadCount: Math.max(0, (label.unreadCount ?? 0) - 1),
138
- })));
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
+ }
139
142
  }
143
+ await tx.mutate.thread.delete({
144
+ id: threadId,
145
+ });
140
146
  }
141
- await tx.mutate.thread.delete({
142
- id: threadId,
143
- });
144
147
  }
145
148
  }
146
- callbacks?.delete?.(args);
147
149
  },
148
150
  removeLabel: async (tx, args) => {
149
- for (const threadId of args.threadIds) {
150
- const thread = await tx.query.thread.where('id', threadId).one().run();
151
- if (!thread) {
152
- throw new Error(MutationError.ENTITY_NOT_FOUND);
153
- }
154
- const [label, messages] = await Promise.all([
155
- tx.query.accountLabel.where('accountId', thread.accountId).where('path', args.labelPath).one().run(),
156
- tx.query.threadMessage.where('threadId', threadId).run(),
157
- ]);
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();
158
153
  if (!label) {
159
154
  throw new Error(MutationError.ENTITY_NOT_FOUND);
160
155
  }
161
- const currentLabelIds = new Set(threadsUtils.parseLabelIdList(thread.labelIdList));
162
- if (!currentLabelIds.has(label.id)) {
163
- throw new Error(MutationError.ENTITY_NOT_FOUND);
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
+ ]);
164
192
  }
165
- currentLabelIds.delete(label.id);
166
- await Promise.all([
167
- ...messages.map(message => tx.mutate.threadLabel.delete({
168
- accountId: thread.accountId,
169
- labelId: label.id,
170
- threadMessageId: message.id,
171
- })),
172
- tx.mutate.threadByLabel.delete({
173
- labelId: label.id,
174
- threadId,
175
- }),
176
- ...(thread.seen === false
177
- ? [
178
- tx.mutate.accountLabel.update({
179
- id: label.id,
180
- unreadCount: Math.max(0, (label.unreadCount ?? 0) - 1),
181
- }),
182
- ]
183
- : []),
184
- tx.mutate.thread.update({
185
- id: threadId,
186
- labelIdList: buildLabelIdList([...currentLabelIds]),
187
- }),
188
- ]);
189
193
  }
190
- callbacks?.removeLabel?.(args);
191
194
  },
192
195
  setArchive: async (tx, args) => {
193
- for (const threadId of args.threadIds) {
194
- await setSystemLabel(tx, threadId, 'ARCHIVE');
196
+ for (const [, { threadIds }] of Object.entries(args.accounts)) {
197
+ for (const threadId of threadIds) {
198
+ await setSystemLabel(tx, threadId, 'ARCHIVE');
199
+ }
195
200
  }
196
- callbacks?.setArchive?.(args);
197
201
  },
198
202
  setFlagged: async (tx, args) => {
199
- await Promise.all(args.threadIds.map(threadId => tx.mutate.thread.update({
200
- flagged: args.flagged,
201
- id: threadId,
202
- })));
203
- callbacks?.setFlagged?.(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
+ }
204
209
  },
205
210
  setInbox: async (tx, args) => {
206
- for (const threadId of args.threadIds) {
207
- await setSystemLabel(tx, threadId, 'INBOX');
211
+ for (const [, { threadIds }] of Object.entries(args.accounts)) {
212
+ for (const threadId of threadIds) {
213
+ await setSystemLabel(tx, threadId, 'INBOX');
214
+ }
208
215
  }
209
- callbacks?.setInbox?.(args);
210
216
  },
211
217
  setSeen: async (tx, args) => {
212
- const threads = await tx.query.thread.where('id', 'IN', args.threadIds).run();
218
+ const allThreadIds = Object.values(args.accounts).flatMap(x => x.threadIds);
219
+ const threads = await tx.query.thread.where('id', 'IN', allThreadIds).run();
213
220
  const labelCounts = new Map();
214
221
  for (const thread of threads) {
215
222
  if (thread.seen !== args.seen) {
@@ -222,28 +229,29 @@ export const createThreadMutators = (_authData, callbacks) => ({
222
229
  const labels = await tx.query.accountLabel.where('id', 'IN', [...labelCounts.keys()]).run();
223
230
  const delta = args.seen ? -1 : 1;
224
231
  await Promise.all(labels
225
- .filter(label => labelCounts.has(label.id))
226
- .map(label => tx.mutate.accountLabel.update({
227
- id: label.id,
228
- unreadCount: Math.max(0, (label.unreadCount ?? 0) + delta * (labelCounts.get(label.id) ?? 0)),
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)),
229
236
  })));
230
237
  }
231
- await Promise.all(args.threadIds.map(threadId => tx.mutate.thread.update({
238
+ await Promise.all(allThreadIds.map(threadId => tx.mutate.thread.update({
232
239
  id: threadId,
233
240
  seen: args.seen,
234
241
  })));
235
- callbacks?.setSeen?.(args);
236
242
  },
237
243
  setSpam: async (tx, args) => {
238
- for (const threadId of args.threadIds) {
239
- await setSystemLabel(tx, threadId, 'SPAM');
244
+ for (const [, { threadIds }] of Object.entries(args.accounts)) {
245
+ for (const threadId of threadIds) {
246
+ await setSystemLabel(tx, threadId, 'SPAM');
247
+ }
240
248
  }
241
- callbacks?.setSpam?.(args);
242
249
  },
243
250
  setTrash: async (tx, args) => {
244
- for (const threadId of args.threadIds) {
245
- await setSystemLabel(tx, threadId, 'TRASH');
251
+ for (const [, { threadIds }] of Object.entries(args.accounts)) {
252
+ for (const threadId of threadIds) {
253
+ await setSystemLabel(tx, threadId, 'TRASH');
254
+ }
246
255
  }
247
- callbacks?.setTrash?.(args);
248
256
  },
249
257
  });