mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-13 21:27:46 +02:00
Update version and server-core (#24)
Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
},
|
||||
"packages/client-query": {
|
||||
"name": "@hcengineering/communication-client-query",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"dependencies": {
|
||||
"@hcengineering/communication-query": "workspace:*",
|
||||
"@hcengineering/communication-sdk-types": "workspace:*",
|
||||
@@ -32,7 +32,7 @@
|
||||
},
|
||||
"packages/client-sqlite": {
|
||||
"name": "@hcengineering/communication-client-sqlite",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"dependencies": {
|
||||
"@hcengineering/communication-sdk-types": "workspace:*",
|
||||
"@hcengineering/communication-sqlite-wasm": "workspace:*",
|
||||
@@ -48,7 +48,7 @@
|
||||
},
|
||||
"packages/client-ws": {
|
||||
"name": "@hcengineering/communication-client-ws",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"dependencies": {
|
||||
"@hcengineering/communication-sdk-types": "workspace:*",
|
||||
"@hcengineering/communication-types": "workspace:*",
|
||||
@@ -63,7 +63,7 @@
|
||||
},
|
||||
"packages/cockroach": {
|
||||
"name": "@hcengineering/communication-cockroach",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"dependencies": {
|
||||
"@hcengineering/communication-sdk-types": "workspace:*",
|
||||
"@hcengineering/communication-types": "workspace:*",
|
||||
@@ -80,7 +80,7 @@
|
||||
},
|
||||
"packages/examples": {
|
||||
"name": "@hcengineering/communication-examples",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"dependencies": {
|
||||
"@hcengineering/communication-client-query": "workspace:*",
|
||||
"@hcengineering/communication-client-sqlite": "workspace:*",
|
||||
@@ -96,7 +96,7 @@
|
||||
},
|
||||
"packages/query": {
|
||||
"name": "@hcengineering/communication-query",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"dependencies": {
|
||||
"@hcengineering/communication-sdk-types": "workspace:*",
|
||||
"@hcengineering/communication-types": "workspace:*",
|
||||
@@ -112,7 +112,7 @@
|
||||
},
|
||||
"packages/sdk-types": {
|
||||
"name": "@hcengineering/communication-sdk-types",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"dependencies": {
|
||||
"@hcengineering/communication-types": "^0.1.0",
|
||||
},
|
||||
@@ -125,7 +125,7 @@
|
||||
},
|
||||
"packages/server-core": {
|
||||
"name": "@hcengineering/communication-server-core",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"dependencies": {
|
||||
"@hcengineering/communication-cockroach": "workspace:*",
|
||||
"@hcengineering/communication-sdk-types": "workspace:*",
|
||||
@@ -144,7 +144,7 @@
|
||||
},
|
||||
"packages/server-ws": {
|
||||
"name": "@hcengineering/communication-server-ws",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"dependencies": {
|
||||
"@hcengineering/communication-cockroach": "workspace:*",
|
||||
"@hcengineering/communication-sdk-types": "workspace:*",
|
||||
@@ -168,7 +168,7 @@
|
||||
},
|
||||
"packages/sqlite-wasm": {
|
||||
"name": "@hcengineering/communication-sqlite-wasm",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"dependencies": {
|
||||
"@hcengineering/communication-sdk-types": "workspace:*",
|
||||
"@hcengineering/communication-types": "workspace:*",
|
||||
@@ -185,7 +185,7 @@
|
||||
},
|
||||
"packages/types": {
|
||||
"name": "@hcengineering/communication-types",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"dependencies": {
|
||||
"@hcengineering/core": "0.6.411",
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hcengineering/communication-client-query",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.js",
|
||||
"types": "./types/index.d.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hcengineering/communication-client-sqlite",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.js",
|
||||
"types": "./types/index.d.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hcengineering/communication-client-ws",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.js",
|
||||
"types": "./types/index.d.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hcengineering/communication-cockroach",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.js",
|
||||
"types": "./types/index.d.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hcengineering/communication-examples",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.js",
|
||||
"types": "./types/index.d.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hcengineering/communication-query",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.js",
|
||||
"types": "./types/index.d.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hcengineering/communication-sdk-types",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.js",
|
||||
"types": "./types/index.d.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { FindMessagesParams, Message, SocialID } from '@hcengineering/communication-types'
|
||||
|
||||
import type { BroadcastEvent, EventResult, Event } from './event'
|
||||
import type { EventResult, Event } from './event'
|
||||
|
||||
export interface ConnectionInfo {
|
||||
sessionId: string
|
||||
@@ -8,17 +8,13 @@ export interface ConnectionInfo {
|
||||
socialId: SocialID
|
||||
}
|
||||
|
||||
export type Result = {
|
||||
broadcastEvent?: BroadcastEvent
|
||||
result: EventResult
|
||||
}
|
||||
|
||||
export interface ServerApi {
|
||||
findMessages(info: ConnectionInfo, params: FindMessagesParams, queryId?: number): Promise<Message[]>
|
||||
|
||||
unsubscribeQuery(info: ConnectionInfo, id: number): Promise<void>
|
||||
event(info: ConnectionInfo, event: Event): Promise<EventResult>
|
||||
|
||||
event(info: ConnectionInfo, event: Event): Promise<Result>
|
||||
closeSession(sessionId: string): Promise<void>
|
||||
unsubscribeQuery(info: ConnectionInfo, id: number): Promise<void>
|
||||
|
||||
close(): Promise<void>
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hcengineering/communication-server-core",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.js",
|
||||
"types": "./types/index.d.ts",
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import type { MeasureContext } from '@hcengineering/core'
|
||||
import type { FindMessagesParams, Message } from '@hcengineering/communication-types'
|
||||
import { createDbAdapter } from '@hcengineering/communication-cockroach'
|
||||
import type { ConnectionInfo, DbAdapter, Event, ServerApi } from '@hcengineering/communication-sdk-types'
|
||||
import type { ConnectionInfo, DbAdapter, Event, EventResult, ServerApi } from '@hcengineering/communication-sdk-types'
|
||||
|
||||
import { type Result } from './eventProcessor.ts'
|
||||
import { Manager } from './manager.ts'
|
||||
import { Manager, type BroadcastSessionsFunc } from './manager.ts'
|
||||
|
||||
export class Api implements ServerApi {
|
||||
private readonly manager: Manager
|
||||
@@ -12,14 +11,20 @@ export class Api implements ServerApi {
|
||||
private constructor(
|
||||
private readonly ctx: MeasureContext,
|
||||
private readonly workspace: string,
|
||||
db: DbAdapter
|
||||
db: DbAdapter,
|
||||
broadcast: BroadcastSessionsFunc
|
||||
) {
|
||||
this.manager = new Manager(this.ctx, db, this.workspace)
|
||||
this.manager = new Manager(this.ctx, db, this.workspace, broadcast)
|
||||
}
|
||||
|
||||
static async create(ctx: MeasureContext, workspace: string, dbUrl: string): Promise<Api> {
|
||||
static async create(
|
||||
ctx: MeasureContext,
|
||||
workspace: string,
|
||||
dbUrl: string,
|
||||
broadcast: BroadcastSessionsFunc
|
||||
): Promise<Api> {
|
||||
const db = await createDbAdapter(dbUrl)
|
||||
return new Api(ctx, workspace, db)
|
||||
return new Api(ctx, workspace, db, broadcast)
|
||||
}
|
||||
|
||||
async findMessages(info: ConnectionInfo, params: FindMessagesParams, queryId?: number): Promise<Message[]> {
|
||||
@@ -30,10 +35,14 @@ export class Api implements ServerApi {
|
||||
this.manager.unsubscribeQuery(info, id)
|
||||
}
|
||||
|
||||
async event(info: ConnectionInfo, event: Event): Promise<Result> {
|
||||
async event(info: ConnectionInfo, event: Event): Promise<EventResult> {
|
||||
return await this.manager.event(info, event)
|
||||
}
|
||||
|
||||
async closeSession(sessionId: string): Promise<void> {
|
||||
this.manager.closeSession(sessionId)
|
||||
}
|
||||
|
||||
async close(): Promise<void> {
|
||||
this.manager.close()
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ import {
|
||||
EventType,
|
||||
type NotificationContextCreatedEvent,
|
||||
type NotificationCreatedEvent,
|
||||
type Event
|
||||
type Event,
|
||||
type EventResult
|
||||
} from '@hcengineering/communication-sdk-types'
|
||||
import type {
|
||||
FindMessagesParams,
|
||||
@@ -16,12 +17,14 @@ import type {
|
||||
} from '@hcengineering/communication-types'
|
||||
|
||||
import { Triggers } from './triggers.ts'
|
||||
import { EventProcessor, type Result } from './eventProcessor.ts'
|
||||
import { EventProcessor } from './eventProcessor.ts'
|
||||
import type { MeasureContext } from '@hcengineering/core'
|
||||
|
||||
type QueryId = number | string
|
||||
type QueryType = 'message' | 'notification' | 'context'
|
||||
|
||||
export type BroadcastSessionsFunc = (ctx: MeasureContext, sessionIds: string[], result: any) => void
|
||||
|
||||
type SessionInfo = {
|
||||
personalWorkspace: string
|
||||
messageQueries: Map<QueryId, FindMessagesParams>
|
||||
@@ -37,10 +40,11 @@ export class Manager {
|
||||
constructor(
|
||||
private readonly ctx: MeasureContext,
|
||||
private readonly db: DbAdapter,
|
||||
private readonly workspace: string
|
||||
private readonly workspace: string,
|
||||
private readonly broadcast: BroadcastSessionsFunc
|
||||
) {
|
||||
this.eventProcessor = new EventProcessor(db, this.workspace)
|
||||
this.triggers = new Triggers(db)
|
||||
this.triggers = new Triggers(db, this.workspace)
|
||||
}
|
||||
|
||||
async findMessages(info: ConnectionInfo, params: FindMessagesParams, queryId?: number): Promise<Message[]> {
|
||||
@@ -51,18 +55,13 @@ export class Manager {
|
||||
return result
|
||||
}
|
||||
|
||||
async event(info: ConnectionInfo, event: Event): Promise<Result> {
|
||||
return await this.eventProcessor.process(info.personalWorkspace, event)
|
||||
// const { result, broadcastEvent } = await this.eventProcessor.process(personalWorkspace, event)
|
||||
// if (broadcastEvent !== undefined) {
|
||||
// void this.manager.next(broadcastEvent)
|
||||
// }
|
||||
// return result
|
||||
async event(info: ConnectionInfo, event: Event): Promise<EventResult> {
|
||||
const { result, broadcastEvent } = await this.eventProcessor.process(info.personalWorkspace, event)
|
||||
if (broadcastEvent !== undefined) {
|
||||
void this.next(broadcastEvent)
|
||||
}
|
||||
return result
|
||||
}
|
||||
//
|
||||
// async broadcastEvent (ctx: MeasureContext, personalWorkspace: string, event: BroadcastEvent): Promise<void> {
|
||||
// void this.manager.next(event, personalWorkspace)
|
||||
// }
|
||||
|
||||
subscribeQuery(info: ConnectionInfo, type: QueryType, queryId: number, params: Record<string, any>): void {
|
||||
const { sessionId, personalWorkspace } = info
|
||||
@@ -94,30 +93,28 @@ export class Manager {
|
||||
data.contextQueries.delete(queryId)
|
||||
}
|
||||
|
||||
// closeSession(sessionId: string): void {
|
||||
// this.dataBySessionId.delete(sessionId)
|
||||
// }
|
||||
closeSession(sessionId: string): void {
|
||||
this.dataBySessionId.delete(sessionId)
|
||||
}
|
||||
|
||||
// async next(event: BroadcastEvent, workspace: string): Promise<void> {
|
||||
// // await this.broadcast(event, workspace)
|
||||
// // const derived = await this.triggers.process(event, workspace)
|
||||
// // const derivedPromises: Promise<void>[] = []
|
||||
// // for (const d of derived) {
|
||||
// // derivedPromises.push(this.next(d, workspace))
|
||||
// // }
|
||||
// // await Promise.all(derivedPromises)
|
||||
// }
|
||||
async next(event: BroadcastEvent): Promise<void> {
|
||||
await this.broadcastEvent(event)
|
||||
const derived = await this.triggers.process(event)
|
||||
await Promise.all(derived.map((it) => this.next(it)))
|
||||
}
|
||||
|
||||
// private async broadcast(event: BroadcastEvent, workspace: string): Promise<void> {
|
||||
// // const sessions = this.sessionsByWorkspace.get(workspace) ?? []
|
||||
// // const response: Response = { result: event }
|
||||
// // for (const session of sessions) {
|
||||
// // const msg = serializeResponse(response, session.session.binary)
|
||||
// // if (this.match(event, session)) {
|
||||
// // session.ws.send(msg)
|
||||
// // }
|
||||
// // }
|
||||
// }
|
||||
private async broadcastEvent(event: BroadcastEvent): Promise<void> {
|
||||
const sessionIds: string[] = []
|
||||
for (const [sessionId, session] of this.dataBySessionId.entries()) {
|
||||
if (this.match(event, session)) {
|
||||
sessionIds.push(sessionId)
|
||||
}
|
||||
}
|
||||
|
||||
if (sessionIds.length > 0) {
|
||||
this.broadcast(this.ctx, sessionIds, event)
|
||||
}
|
||||
}
|
||||
|
||||
private match(event: BroadcastEvent, info: SessionInfo): boolean {
|
||||
switch (event.type) {
|
||||
|
||||
@@ -9,18 +9,21 @@ import {
|
||||
import type { NotificationContext, ContextID, CardID } from '@hcengineering/communication-types'
|
||||
|
||||
export class Triggers {
|
||||
constructor(private readonly db: DbAdapter) {}
|
||||
constructor(
|
||||
private readonly db: DbAdapter,
|
||||
private readonly workspace: string
|
||||
) {}
|
||||
|
||||
async process(event: BroadcastEvent, workspace: string): Promise<BroadcastEvent[]> {
|
||||
async process(event: BroadcastEvent): Promise<BroadcastEvent[]> {
|
||||
switch (event.type) {
|
||||
case EventType.MessageCreated:
|
||||
return this.createNotifications(event, workspace)
|
||||
return this.createNotifications(event)
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
private async createNotifications(event: MessageCreatedEvent, workspace: string): Promise<BroadcastEvent[]> {
|
||||
private async createNotifications(event: MessageCreatedEvent): Promise<BroadcastEvent[]> {
|
||||
const card = event.message.card as any as CardID
|
||||
const subscribedPersonalWorkspaces = [
|
||||
'cd0aba36-1c4f-4170-95f2-27a12a5415f7',
|
||||
@@ -28,16 +31,16 @@ export class Triggers {
|
||||
]
|
||||
|
||||
const res: BroadcastEvent[] = []
|
||||
const contexts = await this.db.findContexts({ card }, [], workspace)
|
||||
const contexts = await this.db.findContexts({ card }, [], this.workspace)
|
||||
|
||||
res.push(...(await this.updateNotificationContexts(event.message.created, contexts)))
|
||||
|
||||
for (const personalWorkspace of subscribedPersonalWorkspaces) {
|
||||
const existsContext = contexts.find(
|
||||
(it) => it.card === card && it.personalWorkspace === personalWorkspace && workspace === it.workspace
|
||||
(it) => it.card === card && it.personalWorkspace === personalWorkspace && this.workspace === it.workspace
|
||||
)
|
||||
const contextId = await this.getOrCreateContextId(
|
||||
workspace,
|
||||
this.workspace,
|
||||
card,
|
||||
personalWorkspace,
|
||||
res,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hcengineering/communication-server-ws",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.js",
|
||||
"types": "./types/index.d.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hcengineering/communication-sqlite-wasm",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.js",
|
||||
"types": "./types/index.d.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hcengineering/communication-types",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.js",
|
||||
"types": "./types/index.d.ts",
|
||||
|
||||
Reference in New Issue
Block a user