@marcoappio/marco-config 2.0.503 → 2.0.504

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.
@@ -1,4 +1,4 @@
1
- export declare const zeroCRUD: import("node_modules/@rocicorp/zero/out/zql/src/mutate/crud").SchemaCRUDMutators<{
1
+ export declare const zeroCRUD: import("@rocicorp/zero").SchemaCRUDMutators<{
2
2
  tables: {
3
3
  readonly user: {
4
4
  name: "user";
@@ -1 +1 @@
1
- {"version":3,"file":"accountMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/accountMutators/accountMutators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAM5B,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4CjC,CAAA;AAED,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8H3B,CAAA"}
1
+ {"version":3,"file":"accountMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/accountMutators/accountMutators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAO5B,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4CjC,CAAA;AAED,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8H3B,CAAA"}
@@ -2,6 +2,7 @@ import * as v from 'valibot';
2
2
  import { marcoSchemas } from '../../../schemas';
3
3
  import { zeroCRUD } from '../../../zero/crud';
4
4
  import { defineMutator } from '../../../zero/mutators/typedMutator';
5
+ import { z } from '../../../zero/queries/z';
5
6
  export const accountMutatorSchemas = {
6
7
  createAccount: v.object({
7
8
  aliasId: marcoSchemas.string.required(),
@@ -80,10 +81,10 @@ export const accountMutators = {
80
81
  await tx.mutate(zeroCRUD.account.delete({ id }));
81
82
  }),
82
83
  deleteAlias: defineMutator(accountMutatorSchemas.deleteAlias, async ({ tx, args: { accountId, aliasId } }) => {
83
- const alias = await tx.run(tx.query.accountAlias.where('id', aliasId).one());
84
+ const alias = await tx.run(z.accountAlias.where('id', aliasId).one());
84
85
  await tx.mutate(zeroCRUD.accountAlias.delete({ id: aliasId }));
85
86
  if (alias?.isPrimary) {
86
- const remainingAliases = await tx.run(tx.query.accountAlias.where('accountId', accountId));
87
+ const remainingAliases = await tx.run(z.accountAlias.where('accountId', accountId));
87
88
  if (remainingAliases.length > 0) {
88
89
  const newPrimaryAlias = remainingAliases[0];
89
90
  await tx.mutate(zeroCRUD.accountAlias.update({
@@ -110,7 +111,7 @@ export const accountMutators = {
110
111
  }));
111
112
  }),
112
113
  setAliasPrimary: defineMutator(accountMutatorSchemas.setAliasPrimary, async ({ tx, args: { accountId, aliasId } }) => {
113
- const aliases = await tx.run(tx.query.accountAlias.where('accountId', accountId));
114
+ const aliases = await tx.run(z.accountAlias.where('accountId', accountId));
114
115
  for (const alias of aliases) {
115
116
  await tx.mutate(zeroCRUD.accountAlias.update({
116
117
  id: alias.id,
@@ -1 +1 @@
1
- {"version":3,"file":"draftMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/draftMutators/draftMutators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAuD5B,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqC/B,CAAA;AAED,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyKzB,CAAA"}
1
+ {"version":3,"file":"draftMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/draftMutators/draftMutators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAwD5B,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqC/B,CAAA;AAED,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyKzB,CAAA"}
@@ -3,6 +3,7 @@ import { marcoSchemas } from '../../../schemas';
3
3
  import { DRAFT_ATTACHMENT_UPLOAD_STATUSES, DRAFT_STATUSES, DRAFT_TYPES, MutationError } from '../../../types';
4
4
  import { stringPatch } from '../../../utils';
5
5
  import { zeroCRUD } from '../../../zero/crud';
6
+ import { z } from '../../../zero/queries/z';
6
7
  import { defineMutator } from '../typedMutator';
7
8
  const draftBodySchema = v.object({
8
9
  bcc: v.array(marcoSchemas.string.email()),
@@ -86,7 +87,7 @@ export const draftMutatorSchemas = {
86
87
  };
87
88
  export const draftMutators = {
88
89
  cancelSend: defineMutator(draftMutatorSchemas.cancelSend, async ({ tx, args: { id, updatedAt } }) => {
89
- const draft = await tx.run(tx.query.draft.where('id', id).one());
90
+ const draft = await tx.run(z.draft.where('id', id).one());
90
91
  if (!draft) {
91
92
  throw new Error(MutationError.ENTITY_NOT_FOUND);
92
93
  }
@@ -172,7 +173,7 @@ export const draftMutators = {
172
173
  }
173
174
  }),
174
175
  setContent: defineMutator(draftMutatorSchemas.setContent, async ({ tx, args: { id, patch, updatedAt } }) => {
175
- const draft = await tx.run(tx.query.draft.where('id', id).one());
176
+ const draft = await tx.run(z.draft.where('id', id).one());
176
177
  if (!draft) {
177
178
  throw new Error(MutationError.ENTITY_NOT_FOUND);
178
179
  }
@@ -186,7 +187,7 @@ export const draftMutators = {
186
187
  }));
187
188
  }),
188
189
  setEnvelope: defineMutator(draftMutatorSchemas.setEnvelope, async ({ tx, args: { id, envelope, updatedAt } }) => {
189
- const draft = await tx.run(tx.query.draft.where('id', id).one());
190
+ const draft = await tx.run(z.draft.where('id', id).one());
190
191
  if (!draft) {
191
192
  throw new Error(MutationError.ENTITY_NOT_FOUND);
192
193
  }
@@ -1 +1 @@
1
- {"version":3,"file":"threadMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/threadMutators/threadMutators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAG5B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAI1D,OAAO,EAAiB,KAAK,gBAAgB,EAAE,MAAM,0CAA0C,CAAA;AAoB/F,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgBhC,CAAA;AAED,eAAO,MAAM,cAAc,OACrB,gBAAgB,YACV,MAAM,oBACE,eAAe,KAChC,OAAO,CAAC,IAAI,CAqGd,CAAA;AAED,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsQ1B,CAAA"}
1
+ {"version":3,"file":"threadMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/threadMutators/threadMutators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAG5B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAI1D,OAAO,EAAiB,KAAK,gBAAgB,EAAE,MAAM,0CAA0C,CAAA;AAqB/F,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgBhC,CAAA;AAED,eAAO,MAAM,cAAc,OACrB,gBAAgB,YACV,MAAM,oBACE,eAAe,KAChC,OAAO,CAAC,IAAI,CAqGd,CAAA;AAED,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoQ1B,CAAA"}
@@ -4,6 +4,7 @@ import { MutationError } from '../../../types';
4
4
  import { threadsUtils } from '../../../utils/threads';
5
5
  import { zeroCRUD } from '../../../zero/crud';
6
6
  import { defineMutator } from '../../../zero/mutators/typedMutator';
7
+ import { z } from '../../../zero/queries/z';
7
8
  const buildLabelIdList = (x) => (x.length === 0 ? '' : ` ${[...new Set(x)].join(' ')} `);
8
9
  const accountsSchema = v.record(marcoSchemas.string.required(), v.object({
9
10
  threadIds: v.array(marcoSchemas.string.required()),
@@ -33,13 +34,13 @@ export const threadMutatorSchemas = {
33
34
  setTrash: baseThreadSchema,
34
35
  };
35
36
  export const setSystemLabel = async (tx, threadId, targetSpecialUse) => {
36
- const thread = await tx.run(tx.query.thread.where('id', threadId).one());
37
+ const thread = await tx.run(z.thread.where('id', threadId).one());
37
38
  if (!thread) {
38
39
  throw new Error(MutationError.ENTITY_NOT_FOUND);
39
40
  }
40
41
  const [targetLabel, messages] = await Promise.all([
41
- tx.run(tx.query.accountLabel.where('accountId', thread.accountId).where('specialUse', targetSpecialUse).one()),
42
- tx.run(tx.query.threadMessage.where('threadId', threadId)),
42
+ tx.run(z.accountLabel.where('accountId', thread.accountId).where('specialUse', targetSpecialUse).one()),
43
+ tx.run(z.threadMessage.where('threadId', threadId)),
43
44
  ]);
44
45
  if (!targetLabel) {
45
46
  throw new Error(MutationError.ENTITY_NOT_FOUND);
@@ -63,7 +64,7 @@ export const setSystemLabel = async (tx, threadId, targetSpecialUse) => {
63
64
  ...[...labelIdsToRemove].map(labelId => tx.mutate(zeroCRUD.threadByLabel.delete({ labelId, threadId }))),
64
65
  ]);
65
66
  if (thread.seen === false && labelIdsToRemove.size > 0) {
66
- const labelsToUpdate = await tx.run(tx.query.accountLabel.where('id', 'IN', [...labelIdsToRemove]));
67
+ const labelsToUpdate = await tx.run(z.accountLabel.where('id', 'IN', [...labelIdsToRemove]));
67
68
  await Promise.all(labelsToUpdate.map(label => tx.mutate(zeroCRUD.accountLabel.update({
68
69
  id: label.id,
69
70
  unreadCount: Math.max(0, (label.unreadCount ?? 0) - 1),
@@ -104,14 +105,14 @@ export const setSystemLabel = async (tx, threadId, targetSpecialUse) => {
104
105
  export const threadMutators = {
105
106
  addLabel: defineMutator(threadMutatorSchemas.addLabel, async ({ tx, args: { accounts, labelPath } }) => {
106
107
  for (const [accountId, { threadIds }] of Object.entries(accounts)) {
107
- const label = await tx.run(tx.query.accountLabel.where('accountId', accountId).where('path', labelPath).one());
108
+ const label = await tx.run(z.accountLabel.where('accountId', accountId).where('path', labelPath).one());
108
109
  if (!label) {
109
110
  throw new Error(MutationError.ENTITY_NOT_FOUND);
110
111
  }
111
112
  for (const threadId of threadIds) {
112
113
  const [thread, messages] = await Promise.all([
113
- tx.run(tx.query.thread.where('id', threadId).one()),
114
- tx.run(tx.query.threadMessage.where('threadId', threadId)),
114
+ tx.run(z.thread.where('id', threadId).one()),
115
+ tx.run(z.threadMessage.where('threadId', threadId)),
115
116
  ]);
116
117
  if (!thread) {
117
118
  throw new Error(MutationError.ENTITY_NOT_FOUND);
@@ -134,7 +135,7 @@ export const threadMutators = {
134
135
  : []),
135
136
  ]);
136
137
  }
137
- const existingChecks = await Promise.all(messages.map(x => tx.run(tx.query.threadLabel.where('threadMessageId', x.id).where('labelId', label.id).one())));
138
+ const existingChecks = await Promise.all(messages.map(x => tx.run(z.threadLabel.where('threadMessageId', x.id).where('labelId', label.id).one())));
138
139
  const messagesToInsert = messages.filter((_, i) => !existingChecks[i]);
139
140
  const baseTimestamp = Date.now();
140
141
  if (messagesToInsert.length > 0) {
@@ -159,12 +160,12 @@ export const threadMutators = {
159
160
  delete: defineMutator(threadMutatorSchemas.delete, async ({ tx, args: { accounts } }) => {
160
161
  for (const [, { threadIds }] of Object.entries(accounts)) {
161
162
  for (const threadId of threadIds) {
162
- const thread = await tx.run(tx.query.thread.where('id', threadId).one());
163
+ const thread = await tx.run(z.thread.where('id', threadId).one());
163
164
  if (thread) {
164
165
  if (thread.seen === false) {
165
166
  const labelIds = threadsUtils.parseLabelIdList(thread.labelIdList);
166
167
  if (labelIds.length > 0) {
167
- const labels = await tx.run(tx.query.accountLabel.where('id', 'IN', labelIds));
168
+ const labels = await tx.run(z.accountLabel.where('id', 'IN', labelIds));
168
169
  await Promise.all(labels.map(x => tx.mutate(zeroCRUD.accountLabel.update({
169
170
  id: x.id,
170
171
  unreadCount: Math.max(0, (x.unreadCount ?? 0) - 1),
@@ -180,14 +181,14 @@ export const threadMutators = {
180
181
  }),
181
182
  removeLabel: defineMutator(threadMutatorSchemas.removeLabel, async ({ tx, args: { accounts, labelPath } }) => {
182
183
  for (const [accountId, { threadIds }] of Object.entries(accounts)) {
183
- const label = await tx.run(tx.query.accountLabel.where('accountId', accountId).where('path', labelPath).one());
184
+ const label = await tx.run(z.accountLabel.where('accountId', accountId).where('path', labelPath).one());
184
185
  if (!label) {
185
186
  throw new Error(MutationError.ENTITY_NOT_FOUND);
186
187
  }
187
188
  for (const threadId of threadIds) {
188
189
  const [thread, messages] = await Promise.all([
189
- tx.run(tx.query.thread.where('id', threadId).one()),
190
- tx.run(tx.query.threadMessage.where('threadId', threadId)),
190
+ tx.run(z.thread.where('id', threadId).one()),
191
+ tx.run(z.threadMessage.where('threadId', threadId)),
191
192
  ]);
192
193
  if (!thread) {
193
194
  throw new Error(MutationError.ENTITY_NOT_FOUND);
@@ -247,7 +248,7 @@ export const threadMutators = {
247
248
  }),
248
249
  setSeen: defineMutator(threadMutatorSchemas.setSeen, async ({ tx, args: { accounts, seen } }) => {
249
250
  const allThreadIds = Object.values(accounts).flatMap(x => x.threadIds);
250
- const threads = await tx.run(tx.query.thread.where('id', 'IN', allThreadIds));
251
+ const threads = await tx.run(z.thread.where('id', 'IN', allThreadIds));
251
252
  const labelCounts = new Map();
252
253
  for (const thread of threads) {
253
254
  if (thread.seen !== seen) {
@@ -257,7 +258,7 @@ export const threadMutators = {
257
258
  }
258
259
  }
259
260
  if (labelCounts.size > 0) {
260
- const labels = await tx.run(tx.query.accountLabel.where('id', 'IN', [...labelCounts.keys()]));
261
+ const labels = await tx.run(z.accountLabel.where('id', 'IN', [...labelCounts.keys()]));
261
262
  const delta = seen ? -1 : 1;
262
263
  await Promise.all(labels
263
264
  .filter(x => labelCounts.has(x.id))
@@ -1 +1 @@
1
- {"version":3,"file":"userMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/userMutators/userMutators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAM5B,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;CAiB9B,CAAA;AAED,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BxB,CAAA"}
1
+ {"version":3,"file":"userMutators.d.ts","sourceRoot":"","sources":["../../../../src/zero/mutators/userMutators/userMutators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAO5B,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;CAiB9B,CAAA;AAED,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BxB,CAAA"}
@@ -2,6 +2,7 @@ import * as v from 'valibot';
2
2
  import { marcoSchemas } from '../../../schemas';
3
3
  import { zeroCRUD } from '../../../zero/crud';
4
4
  import { defineMutator } from '../../../zero/mutators/typedMutator';
5
+ import { z } from '../../../zero/queries/z';
5
6
  export const userMutatorSchemas = {
6
7
  deleteSettingsPushNotificationToken: v.object({
7
8
  id: marcoSchemas.string.required(),
@@ -28,7 +29,7 @@ export const userMutators = {
28
29
  await tx.mutate(zeroCRUD.user.update({ id, name }));
29
30
  }),
30
31
  setSettingsPushNotificationToken: defineMutator(userMutatorSchemas.setSettingsPushNotificationToken, async ({ tx, args: { id, pushNotificationToken } }) => {
31
- const existing = await tx.run(tx.query.userPushNotificationToken.where('userId', id).where('token', pushNotificationToken.token).one());
32
+ const existing = await tx.run(z.userPushNotificationToken.where('userId', id).where('token', pushNotificationToken.token).one());
32
33
  if (!existing) {
33
34
  await tx.mutate(zeroCRUD.userPushNotificationToken.insert({
34
35
  createdAt: pushNotificationToken.createdAt,
@@ -1 +1 @@
1
- {"version":3,"file":"getAccounts.d.ts","sourceRoot":"","sources":["../../../src/zero/queries/getAccounts.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEvB,CAAA"}
1
+ {"version":3,"file":"getAccounts.d.ts","sourceRoot":"","sources":["../../../src/zero/queries/getAccounts.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAItB,CAAA"}
@@ -1,3 +1,6 @@
1
1
  import { defineQuery } from '@rocicorp/zero';
2
2
  import { z } from '../../zero/queries/z';
3
- export const getAccounts = defineQuery(({ ctx: { userId } }) => z.account.where('userId', userId).related('aliases').related('primaryAlias').related('labels'));
3
+ export const getAccounts = defineQuery(({ ctx: { userId } }) => {
4
+ console.log('CONTEXT_USER_ID', userId);
5
+ return z.account.where('userId', userId).related('aliases').related('primaryAlias').related('labels');
6
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"getUser.d.ts","sourceRoot":"","sources":["../../../src/zero/queries/getUser.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMnB,CAAA"}
1
+ {"version":3,"file":"getUser.d.ts","sourceRoot":"","sources":["../../../src/zero/queries/getUser.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAOlB,CAAA"}
@@ -1,7 +1,10 @@
1
1
  import { defineQuery } from '@rocicorp/zero';
2
2
  import { z } from '../../zero/queries/z';
3
- export const getUser = defineQuery(({ ctx: { userId } }) => z.user
4
- .where('id', userId)
5
- .limit(1)
6
- .related('accounts', x => x.related('aliases').related('primaryAlias').related('labels'))
7
- .related('pushNotificationTokens'));
3
+ export const getUser = defineQuery(({ ctx: { userId } }) => {
4
+ console.log('CONTEXT_USER_ID', userId);
5
+ return z.user
6
+ .where('id', userId)
7
+ .limit(1)
8
+ .related('accounts', x => x.related('aliases').related('primaryAlias').related('labels'))
9
+ .related('pushNotificationTokens');
10
+ });