mirror of
https://github.com/hcengineering/platform.git
synced 2025-01-08 21:27:45 +03:00
Merge branch 'main' of github.com:hcengineering/anticrm into main
This commit is contained in:
commit
46de7cd706
@ -0,0 +1,10 @@
|
||||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@anticrm/client-resources",
|
||||
"comment": "Fix server connection",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "@anticrm/client-resources"
|
||||
}
|
10
common/changes/@anticrm/client/server_2021-08-08-21-02.json
Normal file
10
common/changes/@anticrm/client/server_2021-08-08-21-02.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@anticrm/client",
|
||||
"comment": "Fix server connection",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "@anticrm/client"
|
||||
}
|
10
common/changes/@anticrm/core/server_2021-08-08-21-02.json
Normal file
10
common/changes/@anticrm/core/server_2021-08-08-21-02.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@anticrm/core",
|
||||
"comment": "Fix server connection",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "@anticrm/core"
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@anticrm/dev-server",
|
||||
"comment": "Fix server connection",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "@anticrm/dev-server"
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@anticrm/login-resources",
|
||||
"comment": "Fix server connection",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "@anticrm/login-resources"
|
||||
}
|
10
common/changes/@anticrm/login/server_2021-08-08-21-02.json
Normal file
10
common/changes/@anticrm/login/server_2021-08-08-21-02.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@anticrm/login",
|
||||
"comment": "Fix server connection",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "@anticrm/login"
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@anticrm/model-workbench",
|
||||
"comment": "Fix server connection",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "@anticrm/model-workbench"
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@anticrm/presentation",
|
||||
"comment": "Fix server connection",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "@anticrm/presentation"
|
||||
}
|
10
common/changes/@anticrm/query/server_2021-08-08-21-02.json
Normal file
10
common/changes/@anticrm/query/server_2021-08-08-21-02.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@anticrm/query",
|
||||
"comment": "Fix server connection",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "@anticrm/query"
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@anticrm/server-ws",
|
||||
"comment": "Fix server connection",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "@anticrm/server-ws"
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@anticrm/workbench-resources",
|
||||
"comment": "Fix server connection",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "@anticrm/workbench-resources"
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@anticrm/workbench",
|
||||
"comment": "Fix server connection",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "@anticrm/workbench"
|
||||
}
|
10
common/changes/prod/server_2021-08-08-21-02.json
Normal file
10
common/changes/prod/server_2021-08-08-21-02.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "prod",
|
||||
"comment": "Fix server connection",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "prod"
|
||||
}
|
@ -30,6 +30,7 @@ export class DevSession implements Storage {
|
||||
|
||||
async tx (tx: Tx): Promise<void> {
|
||||
const derived = await this.storage.tx(tx)
|
||||
this.server.broadcast(this, { result: tx })
|
||||
for (const tx of derived) {
|
||||
this.server.broadcast(this, { result: tx })
|
||||
}
|
||||
|
@ -32,10 +32,13 @@ export type TxHander = (tx: Tx) => void
|
||||
* @public
|
||||
*/
|
||||
export interface Client extends Storage {
|
||||
notify?: (tx: Tx) => void
|
||||
getHierarchy: () => Hierarchy
|
||||
}
|
||||
|
||||
class ClientImpl implements Storage {
|
||||
class ClientImpl implements Client {
|
||||
notify?: (tx: Tx) => void
|
||||
|
||||
constructor (private readonly hierarchy: Hierarchy, private readonly model: ModelDb, private readonly conn: Storage) {
|
||||
}
|
||||
|
||||
@ -54,7 +57,11 @@ class ClientImpl implements Storage {
|
||||
}
|
||||
|
||||
async tx (tx: Tx): Promise<void> {
|
||||
if (tx.objectSpace === core.space.Model) {
|
||||
this.hierarchy.tx(tx)
|
||||
}
|
||||
await Promise.all([this.conn.tx(tx), this.model.tx(tx)])
|
||||
this.notify?.(tx)
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,8 +69,7 @@ class ClientImpl implements Storage {
|
||||
* @public
|
||||
*/
|
||||
export async function createClient (
|
||||
connect: (txHandler: TxHander) => Promise<Storage>,
|
||||
notify?: (tx: Tx) => void
|
||||
connect: (txHandler: TxHander) => Promise<Storage>
|
||||
): Promise<Client> {
|
||||
let client: Client | null = null
|
||||
let txBuffer: Tx[] | undefined = []
|
||||
@ -75,13 +81,8 @@ export async function createClient (
|
||||
if (client === null) {
|
||||
txBuffer?.push(tx)
|
||||
} else {
|
||||
if (tx.objectSpace === core.space.Model) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
hierarchy.tx(tx)
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
model.tx(tx)
|
||||
}
|
||||
notify?.(tx)
|
||||
console.log('handler got ', tx)
|
||||
client.notify?.(tx)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
import { onDestroy } from 'svelte'
|
||||
|
||||
import { Doc, Ref, Class, DocumentQuery, FindOptions, Client, Hierarchy } from '@anticrm/core'
|
||||
import { Doc, Ref, Class, DocumentQuery, FindOptions, Client, Hierarchy, Tx } from '@anticrm/core'
|
||||
import { TxOperations } from '@anticrm/core'
|
||||
import { LiveQuery as LQ } from '@anticrm/query'
|
||||
import core from '@anticrm/core'
|
||||
@ -26,13 +26,17 @@ let client: Client & TxOperations
|
||||
|
||||
class UIClient extends TxOperations implements Client {
|
||||
|
||||
constructor (private readonly client: Client) {
|
||||
constructor (private readonly client: Client, private readonly liveQuery: LQ) {
|
||||
super(client, core.account.System)
|
||||
}
|
||||
|
||||
getHierarchy (): Hierarchy {
|
||||
return this.client.getHierarchy()
|
||||
}
|
||||
}
|
||||
|
||||
tx(tx: Tx): Promise<void> {
|
||||
return Promise.all([super.tx(tx), this.liveQuery.tx(tx)]) as unknown as Promise<void>
|
||||
}
|
||||
}
|
||||
|
||||
export function getClient(): Client & TxOperations {
|
||||
@ -41,7 +45,10 @@ export function getClient(): Client & TxOperations {
|
||||
|
||||
export function setClient(_client: Client) {
|
||||
liveQuery = new LQ(_client)
|
||||
client = new UIClient(liveQuery)
|
||||
client = new UIClient(_client, liveQuery)
|
||||
_client.notify = (tx: Tx) => {
|
||||
liveQuery.tx(tx)
|
||||
}
|
||||
}
|
||||
|
||||
class LiveQuery {
|
||||
|
@ -108,6 +108,7 @@ export class LiveQuery extends TxProcessor implements Client {
|
||||
}
|
||||
|
||||
protected async txCreateDoc (tx: TxCreateDoc<Doc>): Promise<void> {
|
||||
console.log('query tx', tx)
|
||||
for (const q of this.queries) {
|
||||
const doc = TxProcessor.createDoc2Doc(tx)
|
||||
if (this.match(q, doc)) {
|
||||
@ -146,7 +147,7 @@ export class LiveQuery extends TxProcessor implements Client {
|
||||
}
|
||||
|
||||
async tx (tx: Tx): Promise<void> {
|
||||
await this.client.tx(tx)
|
||||
// await this.client.tx(tx)
|
||||
await super.tx(tx)
|
||||
}
|
||||
|
||||
|
@ -31,12 +31,10 @@ class DeferredPromise {
|
||||
}
|
||||
|
||||
class Connection implements Storage {
|
||||
private readonly webSocket: WebSocket
|
||||
private readonly requests = new Map<ReqId, DeferredPromise>()
|
||||
private lastId = 0
|
||||
|
||||
constructor (url: string, private readonly handler: TxHander) {
|
||||
this.webSocket = new WebSocket(url)
|
||||
constructor (private readonly webSocket: WebSocket, private readonly handler: TxHander) {
|
||||
this.webSocket.onmessage = (event: MessageEvent) => {
|
||||
const resp = readResponse(event.data)
|
||||
if (resp.id !== undefined) {
|
||||
@ -49,6 +47,7 @@ class Connection implements Storage {
|
||||
promise.resolve(resp.result)
|
||||
}
|
||||
} else {
|
||||
console.log('handle', resp)
|
||||
this.handler(resp.result as Tx)
|
||||
}
|
||||
}
|
||||
@ -76,5 +75,11 @@ class Connection implements Storage {
|
||||
}
|
||||
|
||||
export async function connect (url: string, handler: TxHander): Promise<Storage> {
|
||||
return new Connection(url, handler)
|
||||
return await new Promise((resolve, reject) => {
|
||||
const webSocket = new WebSocket(url)
|
||||
webSocket.onopen = () => {
|
||||
resolve(new Connection(webSocket, handler))
|
||||
}
|
||||
webSocket.onerror = () => reject(new Error('Could not connect'))
|
||||
})
|
||||
}
|
||||
|
@ -29,11 +29,9 @@ export interface _Token {
|
||||
async function handleRequest<S> (service: S, ws: WebSocket, msg: string): Promise<void> {
|
||||
const request = readRequest(msg)
|
||||
const f = (service as any)[request.method]
|
||||
const result = await f.apply(null, request.params)
|
||||
ws.send(serialize({
|
||||
id: request.id,
|
||||
result
|
||||
}))
|
||||
const result = await f.apply(service, request.params)
|
||||
const resp = { id: request.id, result }
|
||||
ws.send(serialize(resp))
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,6 +60,7 @@ export function start (sessionFactory: (server: JsonRpcServer) => Session, port:
|
||||
|
||||
const jsonServer: JsonRpcServer = {
|
||||
broadcast (from: Session, resp: Response<[]>) {
|
||||
console.log('server broadcasting', resp)
|
||||
const msg = serialize(resp)
|
||||
for (const session of sessions) {
|
||||
if (session[0] !== from) { session[1].send(msg) }
|
||||
|
Loading…
Reference in New Issue
Block a user