From fc4d9120acc9f51a53feda73deb891bfa8d2c772 Mon Sep 17 00:00:00 2001 From: Kristina Date: Mon, 14 Apr 2025 14:18:28 +0400 Subject: [PATCH] Add github actions and fix format (#42) Signed-off-by: Kristina Fefelova --- .github/workflows/main.yaml | 65 +++++++ package.json | 3 +- packages/client-query/package.json | 2 +- packages/cockroach/package.json | 2 +- packages/cockroach/src/db/base.ts | 2 +- packages/cockroach/src/db/label.ts | 28 ++- packages/cockroach/src/db/mapping.ts | 24 +-- packages/cockroach/src/db/message.ts | 132 ++++++++----- packages/cockroach/src/db/notification.ts | 40 ++-- packages/cockroach/src/db/schema.ts | 2 +- packages/cockroach/src/db/utils.ts | 44 ++--- packages/query/package.json | 2 +- packages/query/src/label/query.ts | 63 +++--- packages/query/src/messages/query.ts | 181 +++++++++--------- .../query/src/notification-contexts/query.ts | 45 ++--- packages/query/src/notifications/query.ts | 66 ++++--- packages/rest-client/package.json | 2 +- packages/sdk-types/package.json | 2 +- .../sdk-types/src/requestEvents/common.ts | 2 +- packages/sdk-types/src/requestEvents/label.ts | 9 +- .../sdk-types/src/requestEvents/message.ts | 4 +- .../src/requestEvents/notification.ts | 10 +- .../sdk-types/src/responseEvents/common.ts | 2 +- .../sdk-types/src/responseEvents/label.ts | 16 +- .../sdk-types/src/responseEvents/message.ts | 2 +- .../src/responseEvents/notification.ts | 2 +- packages/server/package.json | 2 +- .../server/src/notification/notification.ts | 44 ++--- packages/shared/package.json | 2 +- packages/types/package.json | 2 +- packages/yaml/package.json | 2 +- 31 files changed, 454 insertions(+), 350 deletions(-) create mode 100644 .github/workflows/main.yaml diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000000..92246ea31e --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,65 @@ +# +# Copyright © 2025 Hardcore Engineering Inc. +# +# Licensed under the Eclipse Public License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. You may +# obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# +# See the License for the specific language governing permissions and +# limitations under the License. +# + +name: CI + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + pull_request: + push: + branches: + - main +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: read + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: 1.2.9 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + registry-url: 'https://npm.pkg.github.com' + scope: '@hcengineering' + + - name: Prepare deps + run: | + echo "@hcengineering:registry=https://npm.pkg.github.com" > .npmrc + echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> .npmrc + + - name: Install dependencies + run: bun install + + - name: Build + run: bun run build + + - name: Check format + run: bun run format:check + + - name: Lint + run: bun run lint + diff --git a/package.json b/package.json index 9fae2f0585..3e8ecf18c8 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "build": "turbo run build", "lint": "turbo run lint", "format": "turbo run format", - "check": "bun run format && bun run lint" + "check": "bun run format && bun run lint", + "format:check": "prettier --check \"**/*.ts\"" }, "devDependencies": { "@eslint/js": "^9.24.0", diff --git a/packages/client-query/package.json b/packages/client-query/package.json index eeea456e41..7b600e99bc 100644 --- a/packages/client-query/package.json +++ b/packages/client-query/package.json @@ -14,7 +14,7 @@ "build:types": "tsc --project ./tsconfig.json --emitDeclarationOnly --declarationDir ./types", "build:browser": "bun build src/index.ts --outdir dist --target browser", "lint": "eslint src/*.ts", - "format": "prettier --write src/*.ts " + "format": "prettier --write src/**/*.ts " }, "devDependencies": { "@types/bun": "^1.1.14" diff --git a/packages/cockroach/package.json b/packages/cockroach/package.json index d803f6c7a8..6b9a8147b1 100644 --- a/packages/cockroach/package.json +++ b/packages/cockroach/package.json @@ -14,7 +14,7 @@ "build:types": "tsc --project ./tsconfig.json --emitDeclarationOnly --declarationDir ./types", "build:node": "bun build src/index.ts --target node --format cjs --outfile dist/index.js", "lint": "eslint src/*.ts", - "format": "prettier --write src/*.ts " + "format": "prettier --write src/**/*.ts" }, "devDependencies": { "@types/bun": "^1.1.14" diff --git a/packages/cockroach/src/db/base.ts b/packages/cockroach/src/db/base.ts index 5f63b6b0e7..9162829fc3 100644 --- a/packages/cockroach/src/db/base.ts +++ b/packages/cockroach/src/db/base.ts @@ -19,7 +19,7 @@ import type { WorkspaceID } from '@hcengineering/communication-types' import { type Logger, type Options, type SqlClient } from '../types' export class BaseDb { - constructor ( + constructor( readonly client: SqlClient, readonly workspace: WorkspaceID, readonly logger?: Logger, diff --git a/packages/cockroach/src/db/label.ts b/packages/cockroach/src/db/label.ts index 0cfccdbb0a..7706cd86df 100644 --- a/packages/cockroach/src/db/label.ts +++ b/packages/cockroach/src/db/label.ts @@ -13,7 +13,6 @@ // limitations under the License. // - import { SortingOrder, type AccountID, @@ -22,26 +21,36 @@ import { type FindLabelsParams, type LabelID, type Label -} from '@hcengineering/communication-types'; +} from '@hcengineering/communication-types' -import {BaseDb} from './base' -import {type LabelDb, TableName} from "./schema.ts"; -import {toLabel} from './mapping.ts'; +import { BaseDb } from './base' +import { type LabelDb, TableName } from './schema.ts' +import { toLabel } from './mapping.ts' export class LabelsDb extends BaseDb { - async createLabel(label: LabelID, card: CardID, cardType: CardType, account: AccountID, created: Date): Promise { + async createLabel( + label: LabelID, + card: CardID, + cardType: CardType, + account: AccountID, + created: Date + ): Promise { const db: LabelDb = { workspace_id: this.workspace, label_id: label, card_id: card, card_type: cardType, account, - created, + created } const sql = `INSERT INTO ${TableName.Label} (workspace_id, label_id, card_id, card_type, account, created) VALUES ($1::uuid, $2::varchar, $3::varchar, $4::varchar, $5::uuid, $6::timestamptz) ON CONFLICT DO NOTHING` - await this.execute(sql, [db.workspace_id, db.label_id, db.card_id, db.card_type, db.account, db.created], 'insert label') + await this.execute( + sql, + [db.workspace_id, db.label_id, db.card_id, db.card_type, db.account, db.created], + 'insert label' + ) } async removeLabel(label: LabelID, card: CardID, account: AccountID): Promise { @@ -90,7 +99,8 @@ export class LabelsDb extends BaseDb { } const limit = params.limit != null ? `LIMIT ${params.limit}` : '' - const orderBy = params.order != null ? `ORDER BY l.created ${params.order === SortingOrder.Ascending ? 'ASC' : 'DESC'}` : '' + const orderBy = + params.order != null ? `ORDER BY l.created ${params.order === SortingOrder.Ascending ? 'ASC' : 'DESC'}` : '' const whereString = `WHERE ${where.join(' AND ')}` const sql = [select, whereString, orderBy, limit].join(' ') diff --git a/packages/cockroach/src/db/mapping.ts b/packages/cockroach/src/db/mapping.ts index 86f1b5f649..cde06de62d 100644 --- a/packages/cockroach/src/db/mapping.ts +++ b/packages/cockroach/src/db/mapping.ts @@ -82,7 +82,7 @@ type RawContext = ContextDb & { id: ContextID } & { notifications?: RawNotification[] } -export function toMessage (raw: RawMessage): Message { +export function toMessage(raw: RawMessage): Message { const lastPatch = raw.patches?.[0] return { @@ -110,7 +110,7 @@ export function toMessage (raw: RawMessage): Message { } } -export function toReaction (raw: ReactionDb): Reaction { +export function toReaction(raw: ReactionDb): Reaction { return { message: String(raw.message_id) as MessageID, reaction: raw.reaction, @@ -119,7 +119,7 @@ export function toReaction (raw: ReactionDb): Reaction { } } -export function toFile (raw: FileDb): File { +export function toFile(raw: FileDb): File { return { card: raw.card_id, message: String(raw.message_id) as MessageID, @@ -132,7 +132,7 @@ export function toFile (raw: FileDb): File { } } -export function toMessagesGroup (raw: MessagesGroupDb): MessagesGroup { +export function toMessagesGroup(raw: MessagesGroupDb): MessagesGroup { return { card: raw.card_id, blobId: raw.blob_id, @@ -143,7 +143,7 @@ export function toMessagesGroup (raw: MessagesGroupDb): MessagesGroup { } } -export function toPatch (raw: PatchDb): Patch { +export function toPatch(raw: PatchDb): Patch { return { type: raw.type, message: String(raw.message_id) as MessageID, @@ -153,7 +153,7 @@ export function toPatch (raw: PatchDb): Patch { } } -export function toThread (raw: ThreadDb): Thread { +export function toThread(raw: ThreadDb): Thread { return { card: raw.card_id, message: String(raw.message_id) as MessageID, @@ -163,7 +163,7 @@ export function toThread (raw: ThreadDb): Thread { } } -export function toNotificationContext (raw: RawContext): NotificationContext { +export function toNotificationContext(raw: RawContext): NotificationContext { const lastView = new Date(raw.last_view) return { id: String(raw.id) as ContextID, @@ -177,7 +177,7 @@ export function toNotificationContext (raw: RawContext): NotificationContext { } } -function toNotificationRaw ( +function toNotificationRaw( id: ContextID, card: CardID, lastView: Date | undefined, @@ -243,13 +243,13 @@ function toNotificationRaw ( } } -export function toNotification (raw: RawNotification & { card_id: CardID, last_view?: Date }): Notification { +export function toNotification(raw: RawNotification & { card_id: CardID; last_view?: Date }): Notification { const lastView = raw.last_view != null ? new Date(raw.last_view) : undefined return toNotificationRaw(raw.context_id, raw.card_id, lastView, raw) } -export function toCollaborator (raw: CollaboratorDb): Collaborator { +export function toCollaborator(raw: CollaboratorDb): Collaborator { return { account: raw.account, cardType: raw.card_type, @@ -257,7 +257,7 @@ export function toCollaborator (raw: CollaboratorDb): Collaborator { } } -export function toLabel (raw: LabelDb): Label { +export function toLabel(raw: LabelDb): Label { return { label: raw.label_id, card: raw.card_id, @@ -265,4 +265,4 @@ export function toLabel (raw: LabelDb): Label { account: raw.account, created: new Date(raw.created) } -} \ No newline at end of file +} diff --git a/packages/cockroach/src/db/message.ts b/packages/cockroach/src/db/message.ts index fd1b65c328..ed89a04cfe 100644 --- a/packages/cockroach/src/db/message.ts +++ b/packages/cockroach/src/db/message.ts @@ -32,13 +32,21 @@ import { import { generateMessageId, parseMessageId } from '@hcengineering/communication-shared' import { BaseDb } from './base' -import {type FileDb, type MessageDb, type MessagesGroupDb, type PatchDb, type ReactionDb, TableName, type ThreadDb } from './schema' +import { + type FileDb, + type MessageDb, + type MessagesGroupDb, + type PatchDb, + type ReactionDb, + TableName, + type ThreadDb +} from './schema' import { getCondition } from './utils' import { toMessage, toMessagesGroup, toThread } from './mapping' export class MessagesDb extends BaseDb { // Message - async createMessage ( + async createMessage( card: CardID, type: MessageType, content: RichText, @@ -65,14 +73,24 @@ export class MessagesDb extends BaseDb { await this.execute( sql, - [db.workspace_id, db.card_id, db.id, db.content, db.creator, db.created, db.type, db.data ?? {}, externalId ?? null], + [ + db.workspace_id, + db.card_id, + db.id, + db.content, + db.creator, + db.created, + db.type, + db.data ?? {}, + externalId ?? null + ], 'insert message' ) return id } - async removeMessages (card: CardID, messages: MessageID[], socialIds?: SocialID[]): Promise { + async removeMessages(card: CardID, messages: MessageID[], socialIds?: SocialID[]): Promise { if (messages.length === 0) return [] const where: string[] = ['workspace_id = $1::uuid', 'card_id = $2::varchar'] @@ -105,7 +123,7 @@ export class MessagesDb extends BaseDb { return result.map((row: any) => row.id) } - async createPatch ( + async createPatch( card: CardID, message: MessageID, type: PatchType, @@ -135,7 +153,16 @@ export class MessagesDb extends BaseDb { } // File - async createFile (card: CardID, message: MessageID, blobId: BlobID, fileType: string, filename: string, size: number,creator: SocialID, created: Date): Promise { + async createFile( + card: CardID, + message: MessageID, + blobId: BlobID, + fileType: string, + filename: string, + size: number, + creator: SocialID, + created: Date + ): Promise { const db: FileDb = { workspace_id: this.workspace, card_id: card, @@ -151,10 +178,25 @@ export class MessagesDb extends BaseDb { const sql = `INSERT INTO ${TableName.File} (workspace_id, card_id, message_id, blob_id, type, filename, creator, created, message_created_sec, size) VALUES ($1::uuid, $2::varchar, $3::int8, $4::uuid, $5::varchar, $6::varchar, $7::varchar, $8::timestamptz, $9::timestamptz, $10::int8)` - await this.execute(sql, [db.workspace_id, db.card_id, db.message_id, db.blob_id, db.type, db.filename, db.creator, db.created, db.message_created_sec, db.size], 'insert file') + await this.execute( + sql, + [ + db.workspace_id, + db.card_id, + db.message_id, + db.blob_id, + db.type, + db.filename, + db.creator, + db.created, + db.message_created_sec, + db.size + ], + 'insert file' + ) } - async removeFile (card: CardID, message: MessageID, blobId: BlobID): Promise { + async removeFile(card: CardID, message: MessageID, blobId: BlobID): Promise { const sql = `DELETE FROM ${TableName.File} WHERE workspace_id = $1::uuid @@ -165,7 +207,7 @@ export class MessagesDb extends BaseDb { } // Reaction - async createReaction ( + async createReaction( card: CardID, message: MessageID, reaction: string, @@ -200,7 +242,7 @@ export class MessagesDb extends BaseDb { } } - async removeReaction ( + async removeReaction( card: CardID, message: MessageID, reaction: string, @@ -228,7 +270,7 @@ export class MessagesDb extends BaseDb { } // Thread - async createThread (card: CardID, message: MessageID, thread: CardID, created: Date): Promise { + async createThread(card: CardID, message: MessageID, thread: CardID, created: Date): Promise { const db: ThreadDb = { workspace_id: this.workspace, card_id: card, @@ -247,7 +289,7 @@ export class MessagesDb extends BaseDb { ) } - async updateThread (thread: CardID, op: 'increment' | 'decrement', lastReply?: Date): Promise { + async updateThread(thread: CardID, op: 'increment' | 'decrement', lastReply?: Date): Promise { const set: string[] = [] const values: any[] = [] @@ -270,7 +312,7 @@ export class MessagesDb extends BaseDb { } // MessagesGroup - async createMessagesGroup (card: CardID, blobId: BlobID, fromSec: Date, toSec: Date, count: number): Promise { + async createMessagesGroup(card: CardID, blobId: BlobID, fromSec: Date, toSec: Date, count: number): Promise { const db: MessagesGroupDb = { workspace_id: this.workspace, card_id: card, @@ -289,7 +331,7 @@ export class MessagesDb extends BaseDb { ) } - async removeMessagesGroup (card: CardID, blobId: BlobID): Promise { + async removeMessagesGroup(card: CardID, blobId: BlobID): Promise { const sql = `DELETE FROM ${TableName.MessagesGroup} WHERE workspace_id = $1::uuid @@ -299,9 +341,9 @@ export class MessagesDb extends BaseDb { } async find(params: FindMessagesParams): Promise { - const { where, values } = this.buildMessageWhere(params); - const orderBy = this.buildOrderBy(params); - const limit = this.buildLimit(params); + const { where, values } = this.buildMessageWhere(params) + const orderBy = this.buildOrderBy(params) + const limit = this.buildLimit(params) const sql = ` WITH @@ -310,20 +352,18 @@ export class MessagesDb extends BaseDb { ${this.buildCteAggregatedReactions(params)} ${this.buildCteAggregatedPatches()} ${this.buildMainSelect(params)} - `; + ` - const result = await this.execute(sql, values, 'find messages'); - return result.map((it: any) => toMessage(it)); + const result = await this.execute(sql, values, 'find messages') + return result.map((it: any) => toMessage(it)) } private buildOrderBy(params: FindMessagesParams): string { - return params.order != null - ? `ORDER BY m.created ${params.order === SortingOrder.Ascending ? 'ASC' : 'DESC'}` - : ''; + return params.order != null ? `ORDER BY m.created ${params.order === SortingOrder.Ascending ? 'ASC' : 'DESC'}` : '' } private buildLimit(params: FindMessagesParams): string { - return params.limit != null ? `LIMIT ${params.limit}` : ''; + return params.limit != null ? `LIMIT ${params.limit}` : '' } private buildCteLimitedMessages(where: string, orderBy: string, limit: string): string { @@ -335,11 +375,11 @@ export class MessagesDb extends BaseDb { ${orderBy} ${limit} ) - `; + ` } private buildCteAggregatedFiles(params: FindMessagesParams): string { - if (!params.files) return ''; + if (!params.files) return '' return `, agg_files AS ( SELECT @@ -362,11 +402,11 @@ export class MessagesDb extends BaseDb { AND m.id = f.message_id GROUP BY f.workspace_id, f.card_id, f.message_id ) - `; + ` } private buildCteAggregatedReactions(params: FindMessagesParams): string { - if (!params.reactions) return ''; + if (!params.reactions) return '' return `, agg_reactions AS ( SELECT @@ -386,7 +426,7 @@ export class MessagesDb extends BaseDb { AND m.id = r.message_id GROUP BY r.workspace_id, r.card_id, r.message_id ) - `; + ` } private buildCteAggregatedPatches(): string { @@ -411,34 +451,36 @@ export class MessagesDb extends BaseDb { WHERE p.type = 'update' GROUP BY p.workspace_id, p.card_id, p.message_id ) - `; + ` } private buildMainSelect(params: FindMessagesParams): string { - const orderBy = this.buildOrderBy(params); + const orderBy = this.buildOrderBy(params) const selectReplies = params.replies ? `t.thread_id as thread_id, t.replies_count as replies_count, t.last_reply as last_reply,` - : ''; + : '' - const selectFiles = params.files - ? `COALESCE(f.files, '[]'::jsonb) AS files,` - : `'[]'::jsonb AS files,`; + const selectFiles = params.files ? `COALESCE(f.files, '[]'::jsonb) AS files,` : `'[]'::jsonb AS files,` const selectReactions = params.reactions ? `COALESCE(r.reactions, '[]'::jsonb) AS reactions,` - : `'[]'::jsonb AS reactions,`; + : `'[]'::jsonb AS reactions,` - const joinFiles = params.files ? ` + const joinFiles = params.files + ? ` LEFT JOIN agg_files f ON f.workspace_id = m.workspace_id AND f.card_id = m.card_id - AND f.message_id = m.id` : ''; + AND f.message_id = m.id` + : '' - const joinReactions = params.reactions ? ` + const joinReactions = params.reactions + ? ` LEFT JOIN agg_reactions r ON r.workspace_id = m.workspace_id AND r.card_id = m.card_id - AND r.message_id = m.id` : ''; + AND r.message_id = m.id` + : '' return ` SELECT @@ -466,10 +508,10 @@ export class MessagesDb extends BaseDb { AND p.card_id = m.card_id AND p.message_id = m.id ${orderBy} - `; + ` } - buildMessageWhere (params: FindMessagesParams): { where: string, values: any[] } { + buildMessageWhere(params: FindMessagesParams): { where: string; values: any[] } { const where: string[] = ['m.workspace_id = $1::uuid'] const values: any[] = [this.workspace] @@ -502,7 +544,7 @@ export class MessagesDb extends BaseDb { } // Find thread - async findThread (thread: CardID): Promise { + async findThread(thread: CardID): Promise { const sql = `SELECT t.card_id, t.message_id, t.thread_id, @@ -518,7 +560,7 @@ export class MessagesDb extends BaseDb { } // Find messages groups - async findMessagesGroups (params: FindMessagesGroupsParams): Promise { + async findMessagesGroups(params: FindMessagesGroupsParams): Promise { const select = ` SELECT mg.card_id, mg.blob_id, @@ -554,7 +596,7 @@ export class MessagesDb extends BaseDb { return result.map((it: any) => toMessagesGroup(it)) } - buildMessagesGroupWhere (params: FindMessagesGroupsParams): { + buildMessagesGroupWhere(params: FindMessagesGroupsParams): { where: string values: any[] } { diff --git a/packages/cockroach/src/db/notification.ts b/packages/cockroach/src/db/notification.ts index a401b807b9..aa0e56f298 100644 --- a/packages/cockroach/src/db/notification.ts +++ b/packages/cockroach/src/db/notification.ts @@ -25,8 +25,8 @@ import { type Notification, type NotificationContext, SortingOrder, - type NotificationID, - type CardType + type NotificationID, + type CardType } from '@hcengineering/communication-types' import { BaseDb } from './base' @@ -35,7 +35,7 @@ import { getCondition } from './utils' import { toCollaborator, toNotification, toNotificationContext } from './mapping' export class NotificationsDb extends BaseDb { - async addCollaborators (card: CardID, cardType: CardType, collaborators: AccountID[], date?: Date): Promise { + async addCollaborators(card: CardID, cardType: CardType, collaborators: AccountID[], date?: Date): Promise { if (collaborators.length === 0) return const values: any[] = [] @@ -52,7 +52,7 @@ export class NotificationsDb extends BaseDb { await this.execute(sql, values, 'insert collaborators') } - async removeCollaborators (card: CardID, collaborators: AccountID[]): Promise { + async removeCollaborators(card: CardID, collaborators: AccountID[]): Promise { if (collaborators.length === 0) return if (collaborators.length === 1) { @@ -74,7 +74,7 @@ export class NotificationsDb extends BaseDb { } } - getCollaboratorsCursor ( + getCollaboratorsCursor( card: CardID, date: Date, size?: number @@ -90,7 +90,7 @@ export class NotificationsDb extends BaseDb { return this.client.cursor(sql, [this.workspace, card, date], size) } - async createNotification (context: ContextID, message: MessageID, created: Date): Promise { + async createNotification(context: ContextID, message: MessageID, created: Date): Promise { const db: Omit = { message_id: message, context_id: context, @@ -103,7 +103,7 @@ export class NotificationsDb extends BaseDb { return result[0].id as NotificationID } - async removeNotifications (context: ContextID, account: AccountID, untilDate: Date): Promise { + async removeNotifications(context: ContextID, account: AccountID, untilDate: Date): Promise { const sql = ` DELETE FROM ${TableName.Notification} n USING ${TableName.NotificationContext} nc @@ -115,7 +115,7 @@ export class NotificationsDb extends BaseDb { await this.execute(sql, [context, account, untilDate], 'remove notification') } - async createContext (account: AccountID, card: CardID, lastUpdate: Date, lastView: Date): Promise { + async createContext(account: AccountID, card: CardID, lastUpdate: Date, lastView: Date): Promise { const db: ContextDb = { workspace_id: this.workspace, card_id: card, @@ -134,14 +134,14 @@ export class NotificationsDb extends BaseDb { return result[0].id as ContextID } - async removeContext (context: ContextID, account: AccountID): Promise { + async removeContext(context: ContextID, account: AccountID): Promise { const sql = `DELETE FROM ${TableName.Notification} WHERE context = $1::int8 AND account = $2::uuid` await this.execute(sql, [context, account], 'remove notification context') } - async updateContext (context: ContextID, account: AccountID, lastUpdate?: Date, lastView?: Date): Promise { + async updateContext(context: ContextID, account: AccountID, lastUpdate?: Date, lastView?: Date): Promise { const dbData: Partial = {} if (lastView != null) { @@ -165,7 +165,7 @@ export class NotificationsDb extends BaseDb { await this.execute(sql, [context, account, ...values], 'update notification context') } - async findContexts (params: FindNotificationContextParams): Promise { + async findContexts(params: FindNotificationContextParams): Promise { const withNotifications = params.notifications != null const withMessages = params.notifications?.message === true @@ -284,7 +284,7 @@ export class NotificationsDb extends BaseDb { return result.map((it: any) => toNotificationContext(it)) } - async findNotifications (params: FindNotificationsParams): Promise { + async findNotifications(params: FindNotificationsParams): Promise { const withMessage = params.message === true let select = 'SELECT n.id, n.created,n.message_id, n.context_id, nc.last_view ' @@ -343,7 +343,7 @@ export class NotificationsDb extends BaseDb { return result.map((it: any) => toNotification(it)) } - async findCollaborators (params: FindCollaboratorsParams): Promise { + async findCollaborators(params: FindCollaboratorsParams): Promise { const { where, values } = this.buildCollaboratorsWhere(params) const select = ` SELECT * @@ -360,7 +360,7 @@ export class NotificationsDb extends BaseDb { return result.map((it: any) => toCollaborator(it)) } - private buildCollaboratorsWhere (params: FindCollaboratorsParams): { where: string, values: any[] } { + private buildCollaboratorsWhere(params: FindCollaboratorsParams): { where: string; values: any[] } { const where: string[] = ['c.workspace_id = $1::uuid', 'c.card_id = $2::varchar'] const values: any[] = [this.workspace, params.card] let index = values.length + 1 @@ -379,7 +379,7 @@ export class NotificationsDb extends BaseDb { return { where: `WHERE ${where.join(' AND ')}`, values } } - private buildContextWhere (params: FindNotificationContextParams): { + private buildContextWhere(params: FindNotificationContextParams): { where: string values: any[] index: number @@ -414,20 +414,20 @@ export class NotificationsDb extends BaseDb { if (lastUpdateCondition != null) { where.push(lastUpdateCondition.where) values.push(...lastUpdateCondition.values) - index= lastUpdateCondition.index + index = lastUpdateCondition.index } return { where: `WHERE ${where.join(' AND ')}`, values, index } } - private buildNotificationWhere ( + private buildNotificationWhere( params: FindNotificationsParams, initialIndex?: number, skipWorkspace?: boolean ): { - where: string - values: any[] - } { + where: string + values: any[] + } { const where: string[] = skipWorkspace === true ? [] : ['nc.workspace_id = $1::uuid'] const values: any[] = skipWorkspace === true ? [] : [this.workspace] let index = (initialIndex ?? 0) + values.length + 1 diff --git a/packages/cockroach/src/db/schema.ts b/packages/cockroach/src/db/schema.ts index 8776149cf0..1721517fc6 100644 --- a/packages/cockroach/src/db/schema.ts +++ b/packages/cockroach/src/db/schema.ts @@ -136,4 +136,4 @@ export interface LabelDb { card_type: CardType account: AccountID created: Date -} \ No newline at end of file +} diff --git a/packages/cockroach/src/db/utils.ts b/packages/cockroach/src/db/utils.ts index 17a6fb9265..498d7a3096 100644 --- a/packages/cockroach/src/db/utils.ts +++ b/packages/cockroach/src/db/utils.ts @@ -19,41 +19,41 @@ export function getCondition( startIndex: number, param: any, type: string -): { where: string, values: any[], index: number } | undefined { - const conditions: string[] = []; - const values: any[] = []; - let index = startIndex; +): { where: string; values: any[]; index: number } | undefined { + const conditions: string[] = [] + const values: any[] = [] + let index = startIndex if (param !== null && typeof param === 'object') { if (param.less !== undefined) { - conditions.push(`${table}.${dbField} < $${index}::${type}`); - values.push(param.less); - index++; + conditions.push(`${table}.${dbField} < $${index}::${type}`) + values.push(param.less) + index++ } if (param.lessOrEqual !== undefined) { - conditions.push(`${table}.${dbField} <= $${index}::${type}`); - values.push(param.lessOrEqual); - index++; + conditions.push(`${table}.${dbField} <= $${index}::${type}`) + values.push(param.lessOrEqual) + index++ } if (param.greater !== undefined) { - conditions.push(`${table}.${dbField} > $${index}::${type}`); - values.push(param.greater); - index++; + conditions.push(`${table}.${dbField} > $${index}::${type}`) + values.push(param.greater) + index++ } if (param.greaterOrEqual !== undefined) { - conditions.push(`${table}.${dbField} >= $${index}::${type}`); - values.push(param.greaterOrEqual); - index++; + conditions.push(`${table}.${dbField} >= $${index}::${type}`) + values.push(param.greaterOrEqual) + index++ } } if (param != null && conditions.length === 0) { - conditions.push(`${table}.${dbField} = $${index}::${type}`); - values.push(param); - index++; + conditions.push(`${table}.${dbField} = $${index}::${type}`) + values.push(param) + index++ } - if (conditions.length === 0) return undefined; + if (conditions.length === 0) return undefined - return { where: conditions.join(' AND '), values, index }; -} \ No newline at end of file + return { where: conditions.join(' AND '), values, index } +} diff --git a/packages/query/package.json b/packages/query/package.json index 7752fb0d4f..d38f232a40 100644 --- a/packages/query/package.json +++ b/packages/query/package.json @@ -14,7 +14,7 @@ "build:types": "tsc --project ./tsconfig.json --emitDeclarationOnly --declarationDir ./types", "build:browser": "bun build src/index.ts --outdir dist --target browser", "lint": "eslint src/*.ts", - "format": "prettier --write src/*.ts " + "format": "prettier --write src/**/*.ts " }, "devDependencies": { "@types/bun": "^1.1.14", diff --git a/packages/query/src/label/query.ts b/packages/query/src/label/query.ts index 67892641f0..8bc384fa32 100644 --- a/packages/query/src/label/query.ts +++ b/packages/query/src/label/query.ts @@ -13,7 +13,7 @@ // limitations under the License. // -import type {FindLabelsParams, Label, WorkspaceID} from '@hcengineering/communication-types' +import type { FindLabelsParams, Label, WorkspaceID } from '@hcengineering/communication-types' import { type EventResult, type LabelCreatedEvent, @@ -21,22 +21,20 @@ import { LabelResponseEventType, type QueryCallback, type RequestEvent, - type ResponseEvent, + type ResponseEvent } from '@hcengineering/communication-sdk-types' -import {QueryResult} from '../result' -import {type Query, type QueryClient, type QueryId} from '../types' +import { QueryResult } from '../result' +import { type Query, type QueryClient, type QueryId } from '../types' - -function getId (label: Label): string { +function getId(label: Label): string { return `${label.label}:${label.card}:${label.account}` } export class LabelsQuery implements Query { private result: Promise> | QueryResult