Expand finds (#45)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina
2025-04-18 09:21:32 +04:00
committed by GitHub
parent 375bdee457
commit e6543090e5
9 changed files with 86 additions and 18 deletions
+1 -1
View File
@@ -1 +1 @@
0.1.170
0.1.171
+4 -4
View File
@@ -5,8 +5,8 @@
"name": "@hcengineering/communication",
"devDependencies": {
"@eslint/js": "^9.24.0",
"@types/bun": "^1.2.9",
"bun-types": "^1.2.9",
"@types/bun": "^1.2.10",
"bun-types": "^1.2.10",
"eslint": "^9.24.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.6",
@@ -269,7 +269,7 @@
"@types/body-parser": ["@types/body-parser@1.19.5", "", { "dependencies": { "@types/connect": "*", "@types/node": "*" } }, "sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg=="],
"@types/bun": ["@types/bun@1.2.9", "", { "dependencies": { "bun-types": "1.2.9" } }, "sha512-epShhLGQYc4Bv/aceHbmBhOz1XgUnuTZgcxjxk+WXwNyDXavv5QHD1QEFV0FwbTSQtNq6g4ZcV6y0vZakTjswg=="],
"@types/bun": ["@types/bun@1.2.10", "", { "dependencies": { "bun-types": "1.2.10" } }, "sha512-eilv6WFM3M0c9ztJt7/g80BDusK98z/FrFwseZgT4bXCq2vPhXD4z8R3oddmAn+R/Nmz9vBn4kweJKmGTZj+lg=="],
"@types/connect": ["@types/connect@3.4.38", "", { "dependencies": { "@types/node": "*" } }, "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug=="],
@@ -345,7 +345,7 @@
"braces": ["braces@3.0.3", "", { "dependencies": { "fill-range": "^7.1.1" } }, "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA=="],
"bun-types": ["bun-types@1.2.9", "", { "dependencies": { "@types/node": "*", "@types/ws": "*" } }, "sha512-dk/kOEfQbajENN/D6FyiSgOKEuUi9PWfqKQJEgwKrCMWbjS/S6tEXp178mWvWAcUSYm9ArDlWHZKO3T/4cLXiw=="],
"bun-types": ["bun-types@1.2.10", "", { "dependencies": { "@types/node": "*" } }, "sha512-b5ITZMnVdf3m1gMvJHG+gIfeJHiQPJak0f7925Hxu6ZN5VKA8AGy4GZ4lM+Xkn6jtWxg5S3ldWvfmXdvnkp3GQ=="],
"callsites": ["callsites@3.1.0", "", {}, "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ=="],
+2 -2
View File
@@ -13,8 +13,8 @@
},
"devDependencies": {
"@eslint/js": "^9.24.0",
"@types/bun": "^1.2.9",
"bun-types": "^1.2.9",
"@types/bun": "^1.2.10",
"bun-types": "^1.2.10",
"eslint": "^9.24.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.6",
+8 -2
View File
@@ -72,8 +72,14 @@ export class LabelsDb extends BaseDb {
let index = whereValues.length + 1
if (params.label != null) {
where.push(`l.label_id = $${index++}::varchar`)
whereValues.push(params.label)
const labels = Array.isArray(params.label) ? params.label : [params.label]
if (labels.length === 1) {
where.push(`l.label_id = $${index++}::varchar`)
whereValues.push(labels[0])
} else {
where.push(`l.label_id = ANY($${index++}::varchar[])`)
whereValues.push(labels)
}
}
if (params.card != null) {
+8 -2
View File
@@ -400,8 +400,14 @@ export class NotificationsDb extends BaseDb {
}
if (params.card != null) {
where.push(`nc.card_id = $${index++}::varchar`)
values.push(params.card)
const cards = Array.isArray(params.card) ? params.card : [params.card]
if (cards.length === 1) {
where.push(`nc.card_id = $${index++}::varchar`)
values.push(cards[0])
} else {
where.push(`nc.card_id = ANY($${index++}::varchar[])`)
values.push(cards)
}
}
if (params.account != null) {
+6 -2
View File
@@ -147,8 +147,12 @@ export class LabelsQuery implements Query<Label, FindLabelsParams> {
if (this.params.card != null && this.params.card !== label.card) {
return false
}
if (this.params.label != null && this.params.label !== label.label) {
return false
if (this.params.label != null) {
const labels = Array.isArray(this.params.label) ? this.params.label : [this.params.label]
if (!labels.includes(label.label)) {
return false
}
}
if (this.params.cardType != null) {
const types = Array.isArray(this.params.cardType) ? this.params.cardType : [this.params.cardType]
@@ -286,6 +286,10 @@ export class NotificationContextsQuery implements PagedQuery<NotificationContext
return
}
if (!this.match(context)) {
return
}
await this.addContext(context)
void this.notify()
}
@@ -496,6 +500,54 @@ export class NotificationContextsQuery implements PagedQuery<NotificationContext
}
}
private match(context: NotificationContext): boolean {
if (this.params.card !== undefined) {
const cards = Array.isArray(this.params.card) ? this.params.card : [this.params.card]
if (!cards.includes(context.card)) return false
}
if (this.params.id !== undefined && context.id !== this.params.id) {
return false
}
if (this.params.lastUpdate !== undefined) {
if (
'greater' in this.params.lastUpdate &&
this.params.lastUpdate.greater != null &&
context.lastUpdate <= this.params.lastUpdate.greater
) {
return false
}
if (
'less' in this.params.lastUpdate &&
this.params.lastUpdate.less != null &&
context.lastUpdate >= this.params.lastUpdate.less
) {
return false
}
if (
'greaterOrEqual' in this.params.lastUpdate &&
this.params.lastUpdate.greaterOrEqual != null &&
context.lastUpdate < this.params.lastUpdate.greaterOrEqual
) {
return false
}
if (
'lessOrEqual' in this.params.lastUpdate &&
this.params.lastUpdate.lessOrEqual != null &&
context.lastUpdate > this.params.lastUpdate.lessOrEqual
) {
return false
}
if (this.params.lastUpdate instanceof Date && this.params.lastUpdate !== context.lastUpdate) {
return false
}
}
return true
}
private async notify(): Promise<void> {
if (this.callback === undefined) return
if (this.result instanceof Promise) {
+3 -3
View File
@@ -175,7 +175,7 @@ const SortingOrder = z.number()
const Date = z.union([z.date(), z.string()])
// Find params
const dateOrRecordSchema = z.union([z.date(), z.string(), z.record(z.string())])
const dateOrRecordSchema = z.union([Date, z.record(Date)])
const FindParamsSchema = z
.object({
@@ -205,7 +205,7 @@ const FindMessagesGroupsParamsSchema = FindParamsSchema.extend({
const FindNotificationContextParamsSchema = FindParamsSchema.extend({
id: ContextID.optional(),
card: CardID.optional(),
card: z.union([CardID, z.array(CardID)]).optional(),
lastUpdate: dateOrRecordSchema.optional(),
account: z.union([AccountID, z.array(AccountID)]).optional(),
notifications: z
@@ -227,7 +227,7 @@ const FindNotificationsParamsSchema = FindParamsSchema.extend({
}).strict()
const FindLabelsParamsSchema = FindParamsSchema.extend({
label: LabelID.optional(),
label: z.union([LabelID, z.array(LabelID)]).optional(),
card: CardID.optional(),
cardType: z.union([CardType, z.array(CardType)]).optional(),
account: AccountID.optional()
+2 -2
View File
@@ -62,7 +62,7 @@ export interface FindMessagesGroupsParams extends FindParams {
export interface FindNotificationContextParams extends FindParams {
id?: ContextID
card?: CardID
card?: CardID | CardID[]
lastUpdate?: Partial<Record<ComparisonOperator, Date>> | Date
account?: AccountID | AccountID[]
notifications?: {
@@ -87,7 +87,7 @@ export interface FindCollaboratorsParams extends FindParams {
}
export interface FindLabelsParams extends FindParams {
label?: LabelID
label?: LabelID | LabelID[]
card?: CardID
cardType?: CardType | CardType[]
account?: AccountID