Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into staging
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <[email protected]>
  • Loading branch information
haiodo committed Jan 9, 2025
2 parents 5bf3fc0 + 65e037c commit 3e159a2
Show file tree
Hide file tree
Showing 61 changed files with 894 additions and 627 deletions.
68 changes: 46 additions & 22 deletions packages/core/src/__tests__/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
// limitations under the License.
//
import { IntlString, Plugin } from '@hcengineering/platform'
import { ClientConnectEvent, DocChunk } from '..'
import type { Account, Class, Data, Doc, Domain, PluginConfiguration, Ref, Timestamp } from '../classes'
import { ClassifierKind, DOMAIN_MODEL, Space } from '../classes'
import { ClientConnection, createClient } from '../client'
import { clone } from '../clone'
import core from '../component'
import { Hierarchy } from '../hierarchy'
import { ModelDb, TxDb } from '../memdb'
Expand Down Expand Up @@ -103,38 +103,62 @@ describe('client', () => {
return await transactions.findAll(_class, query)
}

return {
isConnected: () => true,
findAll,
return new (class implements ClientConnection {
handler?: (event: ClientConnectEvent, lastTx: string | undefined, data: any) => Promise<void>

searchFulltext: async (query: SearchQuery, options: SearchOptions): Promise<SearchResult> => {
set onConnect (
handler: ((event: ClientConnectEvent, lastTx: string | undefined, data: any) => Promise<void>) | undefined
) {
this.handler = handler
void this.handler?.(ClientConnectEvent.Connected, '', {})
}

get onConnect ():
| ((event: ClientConnectEvent, lastTx: string | undefined, data: any) => Promise<void>)
| undefined {
return this.handler
}

isConnected = (): boolean => true
findAll = findAll

searchFulltext = async (query: SearchQuery, options: SearchOptions): Promise<SearchResult> => {
return { docs: [] }
},
}

tx: async (tx: Tx): Promise<TxResult> => {
tx = async (tx: Tx): Promise<TxResult> => {
if (tx.objectSpace === core.space.Model) {
hierarchy.tx(tx)
}
const result = await Promise.all([transactions.tx(tx)])
return result[0]
},
close: async () => {},
}

close = async (): Promise<void> => {}

loadChunk: async (domain: Domain, idx?: number) => ({
loadChunk = async (domain: Domain, idx?: number): Promise<DocChunk> => ({
idx: -1,
index: -1,
docs: [],
finished: true,
digest: ''
}),
closeChunk: async (idx: number) => {},
loadDocs: async (domain: Domain, docs: Ref<Doc>[]) => [],
upload: async (domain: Domain, docs: Doc[]) => {},
clean: async (domain: Domain, docs: Ref<Doc>[]) => {},
loadModel: async (last: Timestamp) => clone(txes),
getAccount: async () => null as unknown as Account,
sendForceClose: async () => {}
}
finished: true
})

async closeChunk (idx: number): Promise<void> {}
async loadDocs (domain: Domain, docs: Ref<Doc>[]): Promise<Doc[]> {
return []
}

async upload (domain: Domain, docs: Doc[]): Promise<void> {}
async clean (domain: Domain, docs: Ref<Doc>[]): Promise<void> {}
async loadModel (last: Timestamp): Promise<Tx[]> {
return txes
}

async getAccount (): Promise<Account> {
return null as unknown as Account
}

async sendForceClose (): Promise<void> {}
})()
}
const spyCreate = jest.spyOn(TxProcessor, 'createDoc2Doc')
const spyUpdate = jest.spyOn(TxProcessor, 'updateDoc2Doc')
Expand Down
76 changes: 51 additions & 25 deletions packages/core/src/__tests__/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
// limitations under the License.
//

import { ClientConnectEvent, DocChunk } from '..'
import type { Account, Class, Doc, Domain, Ref, Timestamp } from '../classes'
import { ClientConnection } from '../client'
import core from '../component'
import { Hierarchy } from '../hierarchy'
import { ModelDb, TxDb } from '../memdb'
import type { DocumentQuery, FindResult, TxResult, SearchQuery, SearchOptions, SearchResult } from '../storage'
import type { DocumentQuery, FindResult, SearchOptions, SearchQuery, SearchResult, TxResult } from '../storage'
import type { Tx } from '../tx'
import { DOMAIN_TX } from '../tx'
import { genMinModel } from './minmodel'
Expand All @@ -42,37 +43,62 @@ export async function connect (handler: (tx: Tx) => void): Promise<ClientConnect
return await model.findAll(_class, query)
}

return {
isConnected: () => true,
findAll,
class ClientConnectionImpl implements ClientConnection {
isConnected = (): boolean => true
findAll = findAll

searchFulltext: async (query: SearchQuery, options: SearchOptions): Promise<SearchResult> => {
handler?: (event: ClientConnectEvent, lastTx: string | undefined, data: any) => Promise<void>

set onConnect (
handler: ((event: ClientConnectEvent, lastTx: string | undefined, data: any) => Promise<void>) | undefined
) {
this.handler = handler
void this.handler?.(ClientConnectEvent.Connected, '', {})
}

get onConnect (): ((event: ClientConnectEvent, lastTx: string | undefined, data: any) => Promise<void>) | undefined {
return this.handler
}

async searchFulltext (query: SearchQuery, options: SearchOptions): Promise<SearchResult> {
return { docs: [] }
},
}

tx: async (tx: Tx): Promise<TxResult> => {
async tx (tx: Tx): Promise<TxResult> {
if (tx.objectSpace === core.space.Model) {
hierarchy.tx(tx)
}
const result = await Promise.all([model.tx(tx), transactions.tx(tx)])
return result[0]
// handler(tx) - we have only one client, should not update?
},
close: async () => {},

loadChunk: async (domain: Domain, idx?: number) => ({
idx: -1,
index: -1,
docs: [],
finished: true,
digest: ''
}),
closeChunk: async (idx: number) => {},
loadDocs: async (domain: Domain, docs: Ref<Doc>[]) => [],
upload: async (domain: Domain, docs: Doc[]) => {},
clean: async (domain: Domain, docs: Ref<Doc>[]) => {},
loadModel: async (last: Timestamp) => txes,
getAccount: async () => null as unknown as Account,
sendForceClose: async () => {}
}

async close (): Promise<void> {}

async loadChunk (domain: Domain, idx?: number): Promise<DocChunk> {
return {
idx: -1,
docs: [],
finished: true
}
}

async closeChunk (idx: number): Promise<void> {}
async loadDocs (domain: Domain, docs: Ref<Doc>[]): Promise<Doc[]> {
return []
}

async upload (domain: Domain, docs: Doc[]): Promise<void> {}
async clean (domain: Domain, docs: Ref<Doc>[]): Promise<void> {}
async loadModel (last: Timestamp): Promise<Tx[]> {
return txes
}

async getAccount (): Promise<Account> {
return null as unknown as Account
}

async sendForceClose (): Promise<void> {}
}

return new ClientConnectionImpl()
}
Loading

0 comments on commit 3e159a2

Please sign in to comment.