@marcoappio/marco-config 2.0.418 → 2.0.420

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getThreads.d.ts","sourceRoot":"","sources":["../../../src/zero/queries/getThreads.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAA;AAGlE,KAAK,cAAc,GAAG;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE;QACN,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;QACnB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;QACrB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;QACvB,IAAI,CAAC,EAAE,OAAO,CAAA;KACf,CAAA;CACF,CAAA;AAmBD,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDtB,CAAA"}
@@ -0,0 +1,57 @@
1
+ import { syncedQueryWithContext } from '@rocicorp/zero';
2
+ import * as v from 'valibot';
3
+ import { z } from '../../zero/queries';
4
+ const parseArgs = (args) => {
5
+ const schema = v.object({
6
+ limit: v.optional(v.number()),
7
+ search: v.optional(v.string()),
8
+ where: v.optional(v.object({
9
+ flagged: v.optional(v.boolean()),
10
+ labelIds: v.optional(v.array(v.string())),
11
+ messageIds: v.optional(v.array(v.string())),
12
+ participants: v.optional(v.array(v.string())),
13
+ seen: v.optional(v.boolean()),
14
+ })),
15
+ });
16
+ return [v.parse(schema, args[0] ?? {})];
17
+ };
18
+ export const getThreads = syncedQueryWithContext('getThreads', parseArgs, ({ userId }, { search, limit, where }) => {
19
+ let query = z.thread
20
+ .where('userId', userId)
21
+ .related('messages', q => q.related('recipients').related('attachments').related('labels'))
22
+ .related('labels')
23
+ .related('account')
24
+ .orderBy('latestMessageDate', 'desc');
25
+ if (typeof where?.flagged === 'boolean') {
26
+ query = query.where('flagged', where.flagged);
27
+ }
28
+ if (typeof where?.seen === 'boolean') {
29
+ query = query.where('seen', where.seen);
30
+ }
31
+ if (where?.labelIds && where.labelIds.length > 0) {
32
+ for (const labelId of where.labelIds) {
33
+ query = query.whereExists('labels', q => q.where('id', labelId));
34
+ }
35
+ }
36
+ if (where?.messageIds && where.messageIds.length > 0) {
37
+ for (const messageId of where.messageIds) {
38
+ query = query.whereExists('messages', q => q.where('id', messageId));
39
+ }
40
+ }
41
+ if (where?.participants && where.participants.length > 0) {
42
+ for (const participant of where.participants) {
43
+ query = query.whereExists('messages', q => q.whereExists('recipients', r => r.where('emailAddress', participant)));
44
+ }
45
+ }
46
+ if (search) {
47
+ const sanitizedTerm = search.trim().toLowerCase();
48
+ const tokens = sanitizedTerm.split(/\s+/).filter(Boolean);
49
+ if (tokens.length > 0) {
50
+ query = query.where(({ and, cmp }) => and(...tokens.map(token => cmp('words', 'ILIKE', `%${token}%`))));
51
+ }
52
+ }
53
+ if (typeof limit === 'number') {
54
+ query = query.limit(limit);
55
+ }
56
+ return query;
57
+ });