Skip to content

Commit e654309

Browse files
Expand finds (#45)
Signed-off-by: Kristina Fefelova <[email protected]>
1 parent 375bdee commit e654309

File tree

9 files changed

+86
-18
lines changed

9 files changed

+86
-18
lines changed

.version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.170
1+
0.1.171

bun.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"name": "@hcengineering/communication",
66
"devDependencies": {
77
"@eslint/js": "^9.24.0",
8-
"@types/bun": "^1.2.9",
9-
"bun-types": "^1.2.9",
8+
"@types/bun": "^1.2.10",
9+
"bun-types": "^1.2.10",
1010
"eslint": "^9.24.0",
1111
"eslint-config-prettier": "^9.1.0",
1212
"eslint-plugin-prettier": "^5.2.6",
@@ -269,7 +269,7 @@
269269

270270
"@types/body-parser": ["@types/[email protected]", "", { "dependencies": { "@types/connect": "*", "@types/node": "*" } }, "sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg=="],
271271

272-
"@types/bun": ["@types/[email protected].9", "", { "dependencies": { "bun-types": "1.2.9" } }, "sha512-epShhLGQYc4Bv/aceHbmBhOz1XgUnuTZgcxjxk+WXwNyDXavv5QHD1QEFV0FwbTSQtNq6g4ZcV6y0vZakTjswg=="],
272+
"@types/bun": ["@types/[email protected].10", "", { "dependencies": { "bun-types": "1.2.10" } }, "sha512-eilv6WFM3M0c9ztJt7/g80BDusK98z/FrFwseZgT4bXCq2vPhXD4z8R3oddmAn+R/Nmz9vBn4kweJKmGTZj+lg=="],
273273

274274
"@types/connect": ["@types/[email protected]", "", { "dependencies": { "@types/node": "*" } }, "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug=="],
275275

@@ -345,7 +345,7 @@
345345

346346
"braces": ["[email protected]", "", { "dependencies": { "fill-range": "^7.1.1" } }, "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA=="],
347347

348-
"bun-types": ["[email protected].9", "", { "dependencies": { "@types/node": "*", "@types/ws": "*" } }, "sha512-dk/kOEfQbajENN/D6FyiSgOKEuUi9PWfqKQJEgwKrCMWbjS/S6tEXp178mWvWAcUSYm9ArDlWHZKO3T/4cLXiw=="],
348+
"bun-types": ["[email protected].10", "", { "dependencies": { "@types/node": "*" } }, "sha512-b5ITZMnVdf3m1gMvJHG+gIfeJHiQPJak0f7925Hxu6ZN5VKA8AGy4GZ4lM+Xkn6jtWxg5S3ldWvfmXdvnkp3GQ=="],
349349

350350
"callsites": ["[email protected]", "", {}, "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ=="],
351351

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
},
1414
"devDependencies": {
1515
"@eslint/js": "^9.24.0",
16-
"@types/bun": "^1.2.9",
17-
"bun-types": "^1.2.9",
16+
"@types/bun": "^1.2.10",
17+
"bun-types": "^1.2.10",
1818
"eslint": "^9.24.0",
1919
"eslint-config-prettier": "^9.1.0",
2020
"eslint-plugin-prettier": "^5.2.6",

packages/cockroach/src/db/label.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,14 @@ export class LabelsDb extends BaseDb {
7272
let index = whereValues.length + 1
7373

7474
if (params.label != null) {
75-
where.push(`l.label_id = $${index++}::varchar`)
76-
whereValues.push(params.label)
75+
const labels = Array.isArray(params.label) ? params.label : [params.label]
76+
if (labels.length === 1) {
77+
where.push(`l.label_id = $${index++}::varchar`)
78+
whereValues.push(labels[0])
79+
} else {
80+
where.push(`l.label_id = ANY($${index++}::varchar[])`)
81+
whereValues.push(labels)
82+
}
7783
}
7884

7985
if (params.card != null) {

packages/cockroach/src/db/notification.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,14 @@ export class NotificationsDb extends BaseDb {
400400
}
401401

402402
if (params.card != null) {
403-
where.push(`nc.card_id = $${index++}::varchar`)
404-
values.push(params.card)
403+
const cards = Array.isArray(params.card) ? params.card : [params.card]
404+
if (cards.length === 1) {
405+
where.push(`nc.card_id = $${index++}::varchar`)
406+
values.push(cards[0])
407+
} else {
408+
where.push(`nc.card_id = ANY($${index++}::varchar[])`)
409+
values.push(cards)
410+
}
405411
}
406412

407413
if (params.account != null) {

packages/query/src/label/query.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,12 @@ export class LabelsQuery implements Query<Label, FindLabelsParams> {
147147
if (this.params.card != null && this.params.card !== label.card) {
148148
return false
149149
}
150-
if (this.params.label != null && this.params.label !== label.label) {
151-
return false
150+
151+
if (this.params.label != null) {
152+
const labels = Array.isArray(this.params.label) ? this.params.label : [this.params.label]
153+
if (!labels.includes(label.label)) {
154+
return false
155+
}
152156
}
153157
if (this.params.cardType != null) {
154158
const types = Array.isArray(this.params.cardType) ? this.params.cardType : [this.params.cardType]

packages/query/src/notification-contexts/query.ts

+52
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ export class NotificationContextsQuery implements PagedQuery<NotificationContext
286286
return
287287
}
288288

289+
if (!this.match(context)) {
290+
return
291+
}
292+
289293
await this.addContext(context)
290294
void this.notify()
291295
}
@@ -496,6 +500,54 @@ export class NotificationContextsQuery implements PagedQuery<NotificationContext
496500
}
497501
}
498502

503+
private match(context: NotificationContext): boolean {
504+
if (this.params.card !== undefined) {
505+
const cards = Array.isArray(this.params.card) ? this.params.card : [this.params.card]
506+
if (!cards.includes(context.card)) return false
507+
}
508+
509+
if (this.params.id !== undefined && context.id !== this.params.id) {
510+
return false
511+
}
512+
513+
if (this.params.lastUpdate !== undefined) {
514+
if (
515+
'greater' in this.params.lastUpdate &&
516+
this.params.lastUpdate.greater != null &&
517+
context.lastUpdate <= this.params.lastUpdate.greater
518+
) {
519+
return false
520+
}
521+
if (
522+
'less' in this.params.lastUpdate &&
523+
this.params.lastUpdate.less != null &&
524+
context.lastUpdate >= this.params.lastUpdate.less
525+
) {
526+
return false
527+
}
528+
if (
529+
'greaterOrEqual' in this.params.lastUpdate &&
530+
this.params.lastUpdate.greaterOrEqual != null &&
531+
context.lastUpdate < this.params.lastUpdate.greaterOrEqual
532+
) {
533+
return false
534+
}
535+
if (
536+
'lessOrEqual' in this.params.lastUpdate &&
537+
this.params.lastUpdate.lessOrEqual != null &&
538+
context.lastUpdate > this.params.lastUpdate.lessOrEqual
539+
) {
540+
return false
541+
}
542+
543+
if (this.params.lastUpdate instanceof Date && this.params.lastUpdate !== context.lastUpdate) {
544+
return false
545+
}
546+
}
547+
548+
return true
549+
}
550+
499551
private async notify(): Promise<void> {
500552
if (this.callback === undefined) return
501553
if (this.result instanceof Promise) {

packages/server/src/middleware/validate.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ const SortingOrder = z.number()
175175
const Date = z.union([z.date(), z.string()])
176176

177177
// Find params
178-
const dateOrRecordSchema = z.union([z.date(), z.string(), z.record(z.string())])
178+
const dateOrRecordSchema = z.union([Date, z.record(Date)])
179179

180180
const FindParamsSchema = z
181181
.object({
@@ -205,7 +205,7 @@ const FindMessagesGroupsParamsSchema = FindParamsSchema.extend({
205205

206206
const FindNotificationContextParamsSchema = FindParamsSchema.extend({
207207
id: ContextID.optional(),
208-
card: CardID.optional(),
208+
card: z.union([CardID, z.array(CardID)]).optional(),
209209
lastUpdate: dateOrRecordSchema.optional(),
210210
account: z.union([AccountID, z.array(AccountID)]).optional(),
211211
notifications: z
@@ -227,7 +227,7 @@ const FindNotificationsParamsSchema = FindParamsSchema.extend({
227227
}).strict()
228228

229229
const FindLabelsParamsSchema = FindParamsSchema.extend({
230-
label: LabelID.optional(),
230+
label: z.union([LabelID, z.array(LabelID)]).optional(),
231231
card: CardID.optional(),
232232
cardType: z.union([CardType, z.array(CardType)]).optional(),
233233
account: AccountID.optional()

packages/types/src/query.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export interface FindMessagesGroupsParams extends FindParams {
6262

6363
export interface FindNotificationContextParams extends FindParams {
6464
id?: ContextID
65-
card?: CardID
65+
card?: CardID | CardID[]
6666
lastUpdate?: Partial<Record<ComparisonOperator, Date>> | Date
6767
account?: AccountID | AccountID[]
6868
notifications?: {
@@ -87,7 +87,7 @@ export interface FindCollaboratorsParams extends FindParams {
8787
}
8888

8989
export interface FindLabelsParams extends FindParams {
90-
label?: LabelID
90+
label?: LabelID | LabelID[]
9191
card?: CardID
9292
cardType?: CardType | CardType[]
9393
account?: AccountID

0 commit comments

Comments
 (0)