@marcoappio/marco-config 2.0.493 → 2.0.495

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