@marcoappio/marco-config 2.0.492 → 2.0.494

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 (71) hide show
  1. package/dist/types/Zero.d.ts +8 -14
  2. package/dist/types/Zero.d.ts.map +1 -1
  3. package/dist/types/index.d.ts +0 -1
  4. package/dist/types/index.d.ts.map +1 -1
  5. package/dist/types/index.js +0 -1
  6. package/dist/zero/crud.d.ts +1024 -0
  7. package/dist/zero/crud.d.ts.map +1 -0
  8. package/dist/zero/crud.js +3 -0
  9. package/dist/zero/index.d.ts +1621 -1447
  10. package/dist/zero/index.d.ts.map +1 -1
  11. package/dist/zero/index.js +2 -4
  12. package/dist/zero/mutators/accountMutators/accountMutators.d.ts +127 -3
  13. package/dist/zero/mutators/accountMutators/accountMutators.d.ts.map +1 -1
  14. package/dist/zero/mutators/accountMutators/accountMutators.js +88 -53
  15. package/dist/zero/mutators/draftMutators/draftMutators.d.ts +185 -3
  16. package/dist/zero/mutators/draftMutators/draftMutators.d.ts.map +1 -1
  17. package/dist/zero/mutators/draftMutators/draftMutators.js +124 -51
  18. package/dist/zero/mutators/index.d.ts +1 -1
  19. package/dist/zero/mutators/index.d.ts.map +1 -1
  20. package/dist/zero/mutators/index.js +1 -1
  21. package/dist/zero/mutators/mutators.d.ts +497 -17
  22. package/dist/zero/mutators/mutators.d.ts.map +1 -1
  23. package/dist/zero/mutators/mutators.js +10 -38
  24. package/dist/zero/mutators/threadMutators/threadMutators.d.ts +147 -6
  25. package/dist/zero/mutators/threadMutators/threadMutators.d.ts.map +1 -1
  26. package/dist/zero/mutators/threadMutators/threadMutators.js +79 -59
  27. package/dist/zero/mutators/userMutators/userMutators.d.ts +37 -3
  28. package/dist/zero/mutators/userMutators/userMutators.d.ts.map +1 -1
  29. package/dist/zero/mutators/userMutators/userMutators.js +32 -14
  30. package/dist/zero/queries/getAccounts.d.ts +135 -135
  31. package/dist/zero/queries/getContacts.d.ts +135 -135
  32. package/dist/zero/queries/getDrafts.d.ts +135 -135
  33. package/dist/zero/queries/getThread.d.ts +135 -135
  34. package/dist/zero/queries/getThreadList.d.ts +135 -135
  35. package/dist/zero/queries/getThreads.d.ts +135 -135
  36. package/dist/zero/queries/getUser.d.ts +135 -135
  37. package/dist/zero/queries/index.d.ts +133 -133
  38. package/dist/zero/schema.d.ts +133 -133
  39. package/dist/zero/schema.d.ts.map +1 -1
  40. package/dist/zero/schema.js +0 -1
  41. package/package.json +2 -2
  42. package/dist/types/AuthData.d.ts +0 -4
  43. package/dist/types/AuthData.d.ts.map +0 -1
  44. package/dist/types/AuthData.js +0 -1
  45. package/dist/zero/mutatorSchemas/account.d.ts +0 -80
  46. package/dist/zero/mutatorSchemas/account.d.ts.map +0 -1
  47. package/dist/zero/mutatorSchemas/account.js +0 -66
  48. package/dist/zero/mutatorSchemas/draft.d.ts +0 -150
  49. package/dist/zero/mutatorSchemas/draft.d.ts.map +0 -1
  50. package/dist/zero/mutatorSchemas/draft.js +0 -104
  51. package/dist/zero/mutatorSchemas/index.d.ts +0 -323
  52. package/dist/zero/mutatorSchemas/index.d.ts.map +0 -1
  53. package/dist/zero/mutatorSchemas/index.js +0 -10
  54. package/dist/zero/mutatorSchemas/thread.d.ts +0 -71
  55. package/dist/zero/mutatorSchemas/thread.d.ts.map +0 -1
  56. package/dist/zero/mutatorSchemas/thread.js +0 -47
  57. package/dist/zero/mutatorSchemas/user.d.ts +0 -26
  58. package/dist/zero/mutatorSchemas/user.d.ts.map +0 -1
  59. package/dist/zero/mutatorSchemas/user.js +0 -27
  60. package/dist/zero/mutators/accountMutators/accountMutators.test.d.ts +0 -2
  61. package/dist/zero/mutators/accountMutators/accountMutators.test.d.ts.map +0 -1
  62. package/dist/zero/mutators/accountMutators/accountMutators.test.js +0 -372
  63. package/dist/zero/mutators/draftMutators/draftMutators.test.d.ts +0 -2
  64. package/dist/zero/mutators/draftMutators/draftMutators.test.d.ts.map +0 -1
  65. package/dist/zero/mutators/draftMutators/draftMutators.test.js +0 -416
  66. package/dist/zero/mutators/threadMutators/threadMutators.test.d.ts +0 -2
  67. package/dist/zero/mutators/threadMutators/threadMutators.test.d.ts.map +0 -1
  68. package/dist/zero/mutators/threadMutators/threadMutators.test.js +0 -755
  69. package/dist/zero/mutators/userMutators/userMutators.test.d.ts +0 -2
  70. package/dist/zero/mutators/userMutators/userMutators.test.d.ts.map +0 -1
  71. package/dist/zero/mutators/userMutators/userMutators.test.js +0 -84
@@ -1,8 +1,149 @@
1
- import type { Transaction } from '@rocicorp/zero';
1
+ import { type Transaction } from '@rocicorp/zero';
2
2
  import type { LabelSpecialUse } from '../../../types';
3
- import { type AuthData, type HandlerMap } from '../../../types';
4
- import type { ZeroMutatorSchemas } from '../../../zero/mutatorSchemas';
5
- import type { MarcoZeroSchema } from '../../../zero/schema';
6
- export declare const setSystemLabel: (tx: Transaction<MarcoZeroSchema>, threadId: string, targetSpecialUse: LabelSpecialUse) => Promise<void>;
7
- export declare const createThreadMutators: (_authData: AuthData | undefined) => HandlerMap<ZeroMutatorSchemas["thread"]>;
3
+ export declare const setSystemLabel: (tx: Transaction, threadId: string, targetSpecialUse: LabelSpecialUse) => Promise<void>;
4
+ export declare const threadMutators: {
5
+ addLabel: import("@rocicorp/zero").MutatorDefinition<{
6
+ accounts: {
7
+ [x: string]: {
8
+ threadIds: string[];
9
+ };
10
+ };
11
+ labelPath: string;
12
+ }, {
13
+ accounts: {
14
+ [x: string]: {
15
+ threadIds: string[];
16
+ };
17
+ };
18
+ labelPath: string;
19
+ }, {
20
+ readonly userId: string;
21
+ }, unknown>;
22
+ delete: import("@rocicorp/zero").MutatorDefinition<{
23
+ accounts: {
24
+ [x: string]: {
25
+ threadIds: string[];
26
+ };
27
+ };
28
+ }, {
29
+ accounts: {
30
+ [x: string]: {
31
+ threadIds: string[];
32
+ };
33
+ };
34
+ }, {
35
+ readonly userId: string;
36
+ }, unknown>;
37
+ removeLabel: import("@rocicorp/zero").MutatorDefinition<{
38
+ accounts: {
39
+ [x: string]: {
40
+ threadIds: string[];
41
+ };
42
+ };
43
+ labelPath: string;
44
+ }, {
45
+ accounts: {
46
+ [x: string]: {
47
+ threadIds: string[];
48
+ };
49
+ };
50
+ labelPath: string;
51
+ }, {
52
+ readonly userId: string;
53
+ }, unknown>;
54
+ setArchive: import("@rocicorp/zero").MutatorDefinition<{
55
+ accounts: {
56
+ [x: string]: {
57
+ threadIds: string[];
58
+ };
59
+ };
60
+ }, {
61
+ accounts: {
62
+ [x: string]: {
63
+ threadIds: string[];
64
+ };
65
+ };
66
+ }, {
67
+ readonly userId: string;
68
+ }, unknown>;
69
+ setFlagged: import("@rocicorp/zero").MutatorDefinition<{
70
+ accounts: {
71
+ [x: string]: {
72
+ threadIds: string[];
73
+ };
74
+ };
75
+ flagged: boolean;
76
+ }, {
77
+ accounts: {
78
+ [x: string]: {
79
+ threadIds: string[];
80
+ };
81
+ };
82
+ flagged: boolean;
83
+ }, {
84
+ readonly userId: string;
85
+ }, unknown>;
86
+ setInbox: import("@rocicorp/zero").MutatorDefinition<{
87
+ accounts: {
88
+ [x: string]: {
89
+ threadIds: string[];
90
+ };
91
+ };
92
+ }, {
93
+ accounts: {
94
+ [x: string]: {
95
+ threadIds: string[];
96
+ };
97
+ };
98
+ }, {
99
+ readonly userId: string;
100
+ }, unknown>;
101
+ setSeen: import("@rocicorp/zero").MutatorDefinition<{
102
+ accounts: {
103
+ [x: string]: {
104
+ threadIds: string[];
105
+ };
106
+ };
107
+ seen: boolean;
108
+ }, {
109
+ accounts: {
110
+ [x: string]: {
111
+ threadIds: string[];
112
+ };
113
+ };
114
+ seen: boolean;
115
+ }, {
116
+ readonly userId: string;
117
+ }, unknown>;
118
+ setSpam: import("@rocicorp/zero").MutatorDefinition<{
119
+ accounts: {
120
+ [x: string]: {
121
+ threadIds: string[];
122
+ };
123
+ };
124
+ }, {
125
+ accounts: {
126
+ [x: string]: {
127
+ threadIds: string[];
128
+ };
129
+ };
130
+ }, {
131
+ readonly userId: string;
132
+ }, unknown>;
133
+ setTrash: import("@rocicorp/zero").MutatorDefinition<{
134
+ accounts: {
135
+ [x: string]: {
136
+ threadIds: string[];
137
+ };
138
+ };
139
+ }, {
140
+ accounts: {
141
+ [x: string]: {
142
+ threadIds: string[];
143
+ };
144
+ };
145
+ }, {
146
+ readonly userId: string;
147
+ }, unknown>;
148
+ };
8
149
  //# 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;AAEjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAiB,MAAM,qBAAqB,CAAA;AAEnF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAIhE,eAAO,MAAM,cAAc,OACrB,WAAW,CAAC,eAAe,CAAC,YACtB,MAAM,oBACE,eAAe,KAChC,OAAO,CAAC,IAAI,CAyFd,CAAA;AAED,eAAO,MAAM,oBAAoB,cAAe,QAAQ,GAAG,SAAS,KAAG,UAAU,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CA0O5G,CAAA"}
1
+ {"version":3,"file":"threadMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/threadMutators/threadMutators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAIhE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAuB1D,eAAO,MAAM,cAAc,OACrB,WAAW,YACL,MAAM,oBACE,eAAe,KAChC,OAAO,CAAC,IAAI,CAqGd,CAAA;AAED,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgR1B,CAAA"}
@@ -1,6 +1,20 @@
1
+ import { defineMutator } from '@rocicorp/zero';
2
+ import * as v from 'valibot';
3
+ import { marcoSchemas } from '../../../schemas';
1
4
  import { MutationError } from '../../../types';
2
5
  import { threadsUtils } from '../../../utils/threads';
6
+ import { zeroCRUD } from '../../../zero/crud';
3
7
  const buildLabelIdList = (x) => (x.length === 0 ? '' : ` ${[...new Set(x)].join(' ')} `);
8
+ const accountsSchema = v.record(marcoSchemas.string.required(), v.object({
9
+ threadIds: v.array(marcoSchemas.string.required()),
10
+ }));
11
+ const baseThreadSchema = v.object({
12
+ accounts: accountsSchema,
13
+ });
14
+ const threadChangeLabelSchema = v.object({
15
+ accounts: accountsSchema,
16
+ labelPath: marcoSchemas.string.required(),
17
+ });
4
18
  export const setSystemLabel = async (tx, threadId, targetSpecialUse) => {
5
19
  const thread = await tx.query.thread.where('id', threadId).one().run();
6
20
  if (!thread) {
@@ -20,28 +34,28 @@ export const setSystemLabel = async (tx, threadId, targetSpecialUse) => {
20
34
  const threadLabelDeletes = [];
21
35
  for (const message of messages) {
22
36
  for (const labelId of labelIdsToRemove) {
23
- threadLabelDeletes.push(tx.mutate.threadLabel.delete({
37
+ threadLabelDeletes.push(tx.mutate(zeroCRUD.threadLabel.delete({
24
38
  accountId: thread.accountId,
25
39
  labelId,
26
40
  threadMessageId: message.id,
27
- }));
41
+ })));
28
42
  }
29
43
  }
30
44
  await Promise.all([
31
45
  ...threadLabelDeletes,
32
- ...[...labelIdsToRemove].map(labelId => tx.mutate.threadByLabel.delete({ labelId, threadId })),
46
+ ...[...labelIdsToRemove].map(labelId => tx.mutate(zeroCRUD.threadByLabel.delete({ labelId, threadId }))),
33
47
  ]);
34
48
  if (thread.seen === false && labelIdsToRemove.size > 0) {
35
49
  const labelsToUpdate = await tx.query.accountLabel.where('id', 'IN', [...labelIdsToRemove]).run();
36
- await Promise.all(labelsToUpdate.map(label => tx.mutate.accountLabel.update({
50
+ await Promise.all(labelsToUpdate.map(label => tx.mutate(zeroCRUD.accountLabel.update({
37
51
  id: label.id,
38
52
  unreadCount: Math.max(0, (label.unreadCount ?? 0) - 1),
39
- })));
53
+ }))));
40
54
  }
41
55
  if (!hasTarget) {
42
56
  const baseTimestamp = Date.now();
43
57
  await Promise.all([
44
- ...messages.map((message, i) => tx.mutate.threadLabel.insert({
58
+ ...messages.map((message, i) => tx.mutate(zeroCRUD.threadLabel.insert({
45
59
  accountId: thread.accountId,
46
60
  labelId: targetLabel.id,
47
61
  lastSyncedAt: 0,
@@ -49,29 +63,29 @@ export const setSystemLabel = async (tx, threadId, targetSpecialUse) => {
49
63
  threadMessageId: message.id,
50
64
  uid: -(baseTimestamp + i),
51
65
  uidValidity: targetLabel.uidValidity ?? 0,
52
- })),
53
- tx.mutate.threadByLabel.insert({
66
+ }))),
67
+ tx.mutate(zeroCRUD.threadByLabel.insert({
54
68
  labelId: targetLabel.id,
55
69
  latestMessageDate: thread.latestMessageDate,
56
70
  threadId,
57
- }),
71
+ })),
58
72
  ...(thread.seen === false
59
73
  ? [
60
- tx.mutate.accountLabel.update({
74
+ tx.mutate(zeroCRUD.accountLabel.update({
61
75
  id: targetLabel.id,
62
76
  unreadCount: (targetLabel.unreadCount ?? 0) + 1,
63
- }),
77
+ })),
64
78
  ]
65
79
  : []),
66
80
  ]);
67
81
  }
68
- await tx.mutate.thread.update({
82
+ await tx.mutate(zeroCRUD.thread.update({
69
83
  id: threadId,
70
84
  labelIdList: buildLabelIdList([targetLabel.id]),
71
- });
85
+ }));
72
86
  };
73
- export const createThreadMutators = (_authData) => ({
74
- addLabel: async (tx, args) => {
87
+ export const threadMutators = {
88
+ addLabel: defineMutator(threadChangeLabelSchema, async ({ tx, args }) => {
75
89
  for (const [accountId, { threadIds }] of Object.entries(args.accounts)) {
76
90
  const label = await tx.query.accountLabel.where('accountId', accountId).where('path', args.labelPath).one().run();
77
91
  if (!label) {
@@ -88,17 +102,17 @@ export const createThreadMutators = (_authData) => ({
88
102
  const currentLabelIds = new Set(threadsUtils.parseLabelIdList(thread.labelIdList));
89
103
  if (!currentLabelIds.has(label.id)) {
90
104
  await Promise.all([
91
- tx.mutate.threadByLabel.insert({
105
+ tx.mutate(zeroCRUD.threadByLabel.insert({
92
106
  labelId: label.id,
93
107
  latestMessageDate: thread.latestMessageDate,
94
108
  threadId,
95
- }),
109
+ })),
96
110
  ...(thread.seen === false
97
111
  ? [
98
- tx.mutate.accountLabel.update({
112
+ tx.mutate(zeroCRUD.accountLabel.update({
99
113
  id: label.id,
100
114
  unreadCount: (label.unreadCount ?? 0) + 1,
101
- }),
115
+ })),
102
116
  ]
103
117
  : []),
104
118
  ]);
@@ -107,7 +121,7 @@ export const createThreadMutators = (_authData) => ({
107
121
  const messagesToInsert = messages.filter((_, i) => !existingChecks[i]);
108
122
  const baseTimestamp = Date.now();
109
123
  if (messagesToInsert.length > 0) {
110
- await Promise.all(messagesToInsert.map((x, i) => tx.mutate.threadLabel.insert({
124
+ await Promise.all(messagesToInsert.map((x, i) => tx.mutate(zeroCRUD.threadLabel.insert({
111
125
  accountId,
112
126
  labelId: label.id,
113
127
  lastSyncedAt: 0,
@@ -115,17 +129,17 @@ export const createThreadMutators = (_authData) => ({
115
129
  threadMessageId: x.id,
116
130
  uid: -(baseTimestamp + i),
117
131
  uidValidity: label.uidValidity ?? 0,
118
- })));
132
+ }))));
119
133
  }
120
134
  currentLabelIds.add(label.id);
121
- await tx.mutate.thread.update({
135
+ await tx.mutate(zeroCRUD.thread.update({
122
136
  id: threadId,
123
137
  labelIdList: buildLabelIdList([...currentLabelIds]),
124
- });
138
+ }));
125
139
  }
126
140
  }
127
- },
128
- delete: async (tx, args) => {
141
+ }),
142
+ delete: defineMutator(baseThreadSchema, async ({ tx, args }) => {
129
143
  for (const [, { threadIds }] of Object.entries(args.accounts)) {
130
144
  for (const threadId of threadIds) {
131
145
  const thread = await tx.query.thread.where('id', threadId).one().run();
@@ -134,20 +148,20 @@ export const createThreadMutators = (_authData) => ({
134
148
  const labelIds = threadsUtils.parseLabelIdList(thread.labelIdList);
135
149
  if (labelIds.length > 0) {
136
150
  const labels = await tx.query.accountLabel.where('id', 'IN', labelIds).run();
137
- await Promise.all(labels.map(x => tx.mutate.accountLabel.update({
151
+ await Promise.all(labels.map(x => tx.mutate(zeroCRUD.accountLabel.update({
138
152
  id: x.id,
139
153
  unreadCount: Math.max(0, (x.unreadCount ?? 0) - 1),
140
- })));
154
+ }))));
141
155
  }
142
156
  }
143
- await tx.mutate.thread.delete({
157
+ await tx.mutate(zeroCRUD.thread.delete({
144
158
  id: threadId,
145
- });
159
+ }));
146
160
  }
147
161
  }
148
162
  }
149
- },
150
- removeLabel: async (tx, args) => {
163
+ }),
164
+ removeLabel: defineMutator(threadChangeLabelSchema, async ({ tx, args }) => {
151
165
  for (const [accountId, { threadIds }] of Object.entries(args.accounts)) {
152
166
  const label = await tx.query.accountLabel.where('accountId', accountId).where('path', args.labelPath).one().run();
153
167
  if (!label) {
@@ -167,54 +181,60 @@ export const createThreadMutators = (_authData) => ({
167
181
  }
168
182
  currentLabelIds.delete(label.id);
169
183
  await Promise.all([
170
- ...messages.map(x => tx.mutate.threadLabel.delete({
184
+ ...messages.map(x => tx.mutate(zeroCRUD.threadLabel.delete({
171
185
  accountId,
172
186
  labelId: label.id,
173
187
  threadMessageId: x.id,
174
- })),
175
- tx.mutate.threadByLabel.delete({
188
+ }))),
189
+ tx.mutate(zeroCRUD.threadByLabel.delete({
176
190
  labelId: label.id,
177
191
  threadId,
178
- }),
192
+ })),
179
193
  ...(thread.seen === false
180
194
  ? [
181
- tx.mutate.accountLabel.update({
195
+ tx.mutate(zeroCRUD.accountLabel.update({
182
196
  id: label.id,
183
197
  unreadCount: Math.max(0, (label.unreadCount ?? 0) - 1),
184
- }),
198
+ })),
185
199
  ]
186
200
  : []),
187
- tx.mutate.thread.update({
201
+ tx.mutate(zeroCRUD.thread.update({
188
202
  id: threadId,
189
203
  labelIdList: buildLabelIdList([...currentLabelIds]),
190
- }),
204
+ })),
191
205
  ]);
192
206
  }
193
207
  }
194
- },
195
- setArchive: async (tx, args) => {
208
+ }),
209
+ setArchive: defineMutator(baseThreadSchema, async ({ tx, args }) => {
196
210
  for (const [, { threadIds }] of Object.entries(args.accounts)) {
197
211
  for (const threadId of threadIds) {
198
212
  await setSystemLabel(tx, threadId, 'ARCHIVE');
199
213
  }
200
214
  }
201
- },
202
- setFlagged: async (tx, args) => {
215
+ }),
216
+ setFlagged: defineMutator(v.object({
217
+ accounts: accountsSchema,
218
+ flagged: v.nonOptional(v.boolean()),
219
+ }), async ({ tx, args }) => {
203
220
  for (const [, { threadIds }] of Object.entries(args.accounts)) {
204
- await Promise.all(threadIds.map(threadId => tx.mutate.thread.update({
221
+ await Promise.all(threadIds.map(threadId => tx.mutate(zeroCRUD.thread.update({
205
222
  flagged: args.flagged,
206
223
  id: threadId,
207
- })));
224
+ }))));
208
225
  }
209
- },
210
- setInbox: async (tx, args) => {
226
+ }),
227
+ setInbox: defineMutator(baseThreadSchema, async ({ tx, args }) => {
211
228
  for (const [, { threadIds }] of Object.entries(args.accounts)) {
212
229
  for (const threadId of threadIds) {
213
230
  await setSystemLabel(tx, threadId, 'INBOX');
214
231
  }
215
232
  }
216
- },
217
- setSeen: async (tx, args) => {
233
+ }),
234
+ setSeen: defineMutator(v.object({
235
+ accounts: accountsSchema,
236
+ seen: v.boolean(),
237
+ }), async ({ tx, args }) => {
218
238
  const allThreadIds = Object.values(args.accounts).flatMap(x => x.threadIds);
219
239
  const threads = await tx.query.thread.where('id', 'IN', allThreadIds).run();
220
240
  const labelCounts = new Map();
@@ -230,28 +250,28 @@ export const createThreadMutators = (_authData) => ({
230
250
  const delta = args.seen ? -1 : 1;
231
251
  await Promise.all(labels
232
252
  .filter(x => labelCounts.has(x.id))
233
- .map(x => tx.mutate.accountLabel.update({
253
+ .map(x => tx.mutate(zeroCRUD.accountLabel.update({
234
254
  id: x.id,
235
255
  unreadCount: Math.max(0, (x.unreadCount ?? 0) + delta * (labelCounts.get(x.id) ?? 0)),
236
- })));
256
+ }))));
237
257
  }
238
- await Promise.all(allThreadIds.map(threadId => tx.mutate.thread.update({
258
+ await Promise.all(allThreadIds.map(threadId => tx.mutate(zeroCRUD.thread.update({
239
259
  id: threadId,
240
260
  seen: args.seen,
241
- })));
242
- },
243
- setSpam: async (tx, args) => {
261
+ }))));
262
+ }),
263
+ setSpam: defineMutator(baseThreadSchema, async ({ tx, args }) => {
244
264
  for (const [, { threadIds }] of Object.entries(args.accounts)) {
245
265
  for (const threadId of threadIds) {
246
266
  await setSystemLabel(tx, threadId, 'SPAM');
247
267
  }
248
268
  }
249
- },
250
- setTrash: async (tx, args) => {
269
+ }),
270
+ setTrash: defineMutator(baseThreadSchema, async ({ tx, args }) => {
251
271
  for (const [, { threadIds }] of Object.entries(args.accounts)) {
252
272
  for (const threadId of threadIds) {
253
273
  await setSystemLabel(tx, threadId, 'TRASH');
254
274
  }
255
275
  }
256
- },
257
- });
276
+ }),
277
+ };
@@ -1,4 +1,38 @@
1
- import type { AuthData, HandlerMap } from '../../../types';
2
- import type { ZeroMutatorSchemas } from '../../../zero/mutatorSchemas';
3
- export declare const createUserMutators: (_authData: AuthData | undefined) => HandlerMap<ZeroMutatorSchemas["user"]>;
1
+ export declare const userMutators: {
2
+ deleteSettingsPushNotificationToken: import("@rocicorp/zero").MutatorDefinition<{
3
+ id: string;
4
+ token: string;
5
+ }, {
6
+ id: string;
7
+ token: string;
8
+ }, {
9
+ readonly userId: string;
10
+ }, unknown>;
11
+ setSettingsName: import("@rocicorp/zero").MutatorDefinition<{
12
+ id: string;
13
+ name: string | null;
14
+ }, {
15
+ id: string;
16
+ name: string | null;
17
+ }, {
18
+ readonly userId: string;
19
+ }, unknown>;
20
+ setSettingsPushNotificationToken: import("@rocicorp/zero").MutatorDefinition<{
21
+ id: string;
22
+ pushNotificationToken: {
23
+ createdAt: number;
24
+ id: string;
25
+ token: string;
26
+ };
27
+ }, {
28
+ id: string;
29
+ pushNotificationToken: {
30
+ createdAt: number;
31
+ id: string;
32
+ token: string;
33
+ };
34
+ }, {
35
+ readonly userId: string;
36
+ }, unknown>;
37
+ };
4
38
  //# sourceMappingURL=userMutators.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"userMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/userMutators/userMutators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAE3E,eAAO,MAAM,kBAAkB,cAAe,QAAQ,GAAG,SAAS,KAAG,UAAU,CAAC,kBAAkB,CAAC,MAAM,CAAC,CA4BxG,CAAA"}
1
+ {"version":3,"file":"userMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/userMutators/userMutators.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoDxB,CAAA"}
@@ -1,28 +1,46 @@
1
- export const createUserMutators = (_authData) => ({
2
- deleteSettingsPushNotificationToken: async (tx, args) => {
3
- await tx.mutate.userPushNotificationToken.delete({
1
+ import { defineMutator } from '@rocicorp/zero';
2
+ import * as v from 'valibot';
3
+ import { marcoSchemas } from '../../../schemas';
4
+ import { zeroCRUD } from '../../../zero/crud';
5
+ const userPushNotificationTokenSchema = v.object({
6
+ createdAt: marcoSchemas.number.positiveInteger(),
7
+ id: marcoSchemas.string.required(),
8
+ token: marcoSchemas.string.required(),
9
+ });
10
+ export const userMutators = {
11
+ deleteSettingsPushNotificationToken: defineMutator(v.object({
12
+ id: marcoSchemas.string.required(),
13
+ token: marcoSchemas.string.required(),
14
+ }), async ({ tx, args }) => {
15
+ await tx.mutate(zeroCRUD.userPushNotificationToken.delete({
4
16
  id: args.id,
5
- });
6
- },
7
- setSettingsName: async (tx, args) => {
8
- await tx.mutate.user.update({
17
+ }));
18
+ }),
19
+ setSettingsName: defineMutator(v.object({
20
+ id: marcoSchemas.string.required(),
21
+ name: marcoSchemas.string.nullable(),
22
+ }), async ({ tx, args }) => {
23
+ await tx.mutate(zeroCRUD.user.update({
9
24
  id: args.id,
10
25
  name: args.name,
11
- });
12
- },
13
- setSettingsPushNotificationToken: async (tx, args) => {
26
+ }));
27
+ }),
28
+ setSettingsPushNotificationToken: defineMutator(v.object({
29
+ id: marcoSchemas.string.required(),
30
+ pushNotificationToken: userPushNotificationTokenSchema,
31
+ }), async ({ tx, args }) => {
14
32
  const existing = await tx.query.userPushNotificationToken
15
33
  .where('userId', args.id)
16
34
  .where('token', args.pushNotificationToken.token)
17
35
  .one()
18
36
  .run();
19
37
  if (!existing) {
20
- await tx.mutate.userPushNotificationToken.insert({
38
+ await tx.mutate(zeroCRUD.userPushNotificationToken.insert({
21
39
  createdAt: args.pushNotificationToken.createdAt,
22
40
  id: args.pushNotificationToken.id,
23
41
  token: args.pushNotificationToken.token,
24
42
  userId: args.id,
25
- });
43
+ }));
26
44
  }
27
- },
28
- });
45
+ }),
46
+ };