diff --git a/dev/client-resources/src/connection.ts b/dev/client-resources/src/connection.ts index 8b0ff35a9c..1d0b1160e8 100644 --- a/dev/client-resources/src/connection.ts +++ b/dev/client-resources/src/connection.ts @@ -13,7 +13,7 @@ // limitations under the License. // -import type { Tx, Storage, Ref, Doc, Class, DocumentQuery, FindResult, FindOptions, TxHander, ServerStorage } from '@anticrm/core' +import type { Tx, Storage, Ref, Doc, Class, DocumentQuery, FindResult, FindOptions, TxHander, ServerStorage, TxResult } from '@anticrm/core' import { DOMAIN_TX } from '@anticrm/core' import { createInMemoryAdapter, createInMemoryTxAdapter } from '@anticrm/dev-storage' import { createServerStorage, FullTextAdapter, IndexedDoc } from '@anticrm/server-core' @@ -28,19 +28,22 @@ class ServerStorageWrapper implements Storage { return this.storage.findAll(c, q, o) } - async tx (tx: Tx): Promise { + async tx (tx: Tx): Promise { const _tx = protoDeserialize(protoSerialize(tx)) const derived = await this.storage.tx(_tx) for (const tx of derived) { this.handler(tx) } + return {} } } class NullFullTextAdapter implements FullTextAdapter { - async index (doc: IndexedDoc): Promise { + async index (doc: IndexedDoc): Promise { console.log('noop full text indexer: ', doc) + return {} } - async update (id: Ref, update: Record): Promise { + async update (id: Ref, update: Record): Promise { + return {} } async search (query: any): Promise { diff --git a/dev/server/src/server.ts b/dev/server/src/server.ts index fa058f843a..e5acde82bb 100644 --- a/dev/server/src/server.ts +++ b/dev/server/src/server.ts @@ -15,7 +15,7 @@ // import { DOMAIN_TX } from '@anticrm/core' -import type { Ref, Doc } from '@anticrm/core' +import type { Ref, Doc, TxResult } from '@anticrm/core' import { start as startJsonRpc } from '@anticrm/server-ws' import { createInMemoryAdapter, createInMemoryTxAdapter } from '@anticrm/dev-storage' import { createServerStorage, FullTextAdapter, IndexedDoc } from '@anticrm/server-core' @@ -25,11 +25,13 @@ import { addLocation } from '@anticrm/platform' import { serverChunterId } from '@anticrm/server-chunter' class NullFullTextAdapter implements FullTextAdapter { - async index (doc: IndexedDoc): Promise { + async index (doc: IndexedDoc): Promise { console.log('noop full text indexer: ', doc) + return {} } - async update (id: Ref, update: Record): Promise { + async update (id: Ref, update: Record): Promise { + return {} } async search (query: any): Promise { diff --git a/dev/storage/src/storage.ts b/dev/storage/src/storage.ts index 6f98b9d19f..e9dd3e1533 100644 --- a/dev/storage/src/storage.ts +++ b/dev/storage/src/storage.ts @@ -13,7 +13,7 @@ // limitations under the License. // -import type { Tx, Ref, Doc, Class, DocumentQuery, FindResult, FindOptions } from '@anticrm/core' +import type { Tx, Ref, Doc, Class, DocumentQuery, FindResult, FindOptions, TxResult } from '@anticrm/core' import { ModelDb, TxDb, Hierarchy } from '@anticrm/core' import type { DbAdapter, TxAdapter } from '@anticrm/server-core' @@ -30,7 +30,7 @@ class InMemoryTxAdapter implements TxAdapter { return await this.txdb.findAll(_class, query, options) } - tx (tx: Tx): Promise { + tx (tx: Tx): Promise { return this.txdb.tx(tx) } @@ -56,7 +56,7 @@ class InMemoryAdapter implements DbAdapter { return await this.modeldb.findAll(_class, query, options) } - async tx (tx: Tx): Promise { + async tx (tx: Tx): Promise { return await this.modeldb.tx(tx) } diff --git a/packages/core/src/__tests__/connection.ts b/packages/core/src/__tests__/connection.ts index d5499fadd3..6c5330fc3c 100644 --- a/packages/core/src/__tests__/connection.ts +++ b/packages/core/src/__tests__/connection.ts @@ -13,7 +13,7 @@ // limitations under the License. // -import type { Storage, DocumentQuery, FindResult } from '../storage' +import type { Storage, DocumentQuery, FindResult, TxResult } from '../storage' import type { Class, Doc, Ref } from '../classes' import type { Tx } from '../tx' import core from '../component' @@ -43,11 +43,12 @@ export async function connect (handler: (tx: Tx) => void): Promise { return { findAll, - tx: async (tx: Tx): Promise => { + tx: async (tx: Tx): Promise => { if (tx.objectSpace === core.space.Model) { hierarchy.tx(tx) } - await Promise.all([model.tx(tx), transactions.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? } } diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts index 3cab323963..6873be7a2d 100644 --- a/packages/core/src/client.ts +++ b/packages/core/src/client.ts @@ -15,7 +15,7 @@ import type { Doc, Ref, Class } from './classes' import type { Tx } from './tx' -import type { Storage, DocumentQuery, FindOptions, FindResult, WithLookup } from './storage' +import type { Storage, DocumentQuery, FindOptions, FindResult, WithLookup, TxResult } from './storage' import { SortingOrder } from './storage' import { Hierarchy } from './hierarchy' @@ -73,13 +73,13 @@ class ClientImpl implements Client { return (await this.findAll(_class, query, options))[0] } - async tx (tx: Tx): Promise { + async tx (tx: Tx): Promise { if (tx.objectSpace === core.space.Model) { this.hierarchy.tx(tx) await this.model.tx(tx) } this.notify?.(tx) - await this.conn.tx(tx) + return await this.conn.tx(tx) } async updateFromRemote (tx: Tx): Promise { diff --git a/packages/core/src/memdb.ts b/packages/core/src/memdb.ts index 2c10395676..473eecb7ee 100644 --- a/packages/core/src/memdb.ts +++ b/packages/core/src/memdb.ts @@ -20,7 +20,7 @@ import core from './component' import type { Hierarchy } from './hierarchy' import { _getOperator } from './operator' import { findProperty, resultSort } from './query' -import type { DocumentQuery, FindOptions, FindResult, Storage, WithLookup, LookupData, Refs } from './storage' +import type { DocumentQuery, FindOptions, FindResult, Storage, WithLookup, LookupData, Refs, TxResult } from './storage' import { TxProcessor } from './tx' import clone from 'just-clone' @@ -149,28 +149,29 @@ export abstract class MemDb extends TxProcessor { * @public */ export class TxDb extends MemDb implements Storage { - protected txCreateDoc (tx: TxCreateDoc): Promise { + protected txCreateDoc (tx: TxCreateDoc): Promise { throw new Error('Method not implemented.') } - protected txPutBag (tx: TxPutBag): Promise { + protected txPutBag (tx: TxPutBag): Promise { throw new Error('Method not implemented.') } - protected txUpdateDoc (tx: TxUpdateDoc): Promise { + protected txUpdateDoc (tx: TxUpdateDoc): Promise { throw new Error('Method not implemented.') } - protected txRemoveDoc (tx: TxRemoveDoc): Promise { + protected txRemoveDoc (tx: TxRemoveDoc): Promise { throw new Error('Method not implemented.') } - protected txMixin (tx: TxMixin): Promise { + protected txMixin (tx: TxMixin): Promise { throw new Error('Method not implemented.') } - async tx (tx: Tx): Promise { + async tx (tx: Tx): Promise { this.addDoc(tx) + return {} } } @@ -180,7 +181,7 @@ export class TxDb extends MemDb implements Storage { * @public */ export class ModelDb extends MemDb implements Storage { - protected override async txPutBag (tx: TxPutBag): Promise { + protected override async txPutBag (tx: TxPutBag): Promise { const doc = this.getObject(tx.objectId) as any let bag = doc[tx.bag] if (bag === undefined) { @@ -189,13 +190,15 @@ export class ModelDb extends MemDb implements Storage { bag[tx.key] = tx.value doc.modifiedBy = tx.modifiedBy doc.modifiedOn = tx.modifiedOn + return {} } - protected override async txCreateDoc (tx: TxCreateDoc): Promise { + protected override async txCreateDoc (tx: TxCreateDoc): Promise { this.addDoc(TxProcessor.createDoc2Doc(tx)) + return {} } - protected async txUpdateDoc (tx: TxUpdateDoc): Promise { + protected async txUpdateDoc (tx: TxUpdateDoc): Promise { const doc = this.getObject(tx.objectId) as any const ops = tx.operations as any for (const key in ops) { @@ -208,15 +211,18 @@ export class ModelDb extends MemDb implements Storage { } doc.modifiedBy = tx.modifiedBy doc.modifiedOn = tx.modifiedOn + return {} } - protected async txRemoveDoc (tx: TxRemoveDoc): Promise { + protected async txRemoveDoc (tx: TxRemoveDoc): Promise { this.delDoc(tx.objectId) + return {} } // TODO: process ancessor mixins - protected async txMixin (tx: TxMixin): Promise { + protected async txMixin (tx: TxMixin): Promise { const obj = this.getObject(tx.objectId) as any obj[tx.mixin] = tx.attributes + return {} } } diff --git a/packages/core/src/storage.ts b/packages/core/src/storage.ts index bf82bcfa20..8f54269a4d 100644 --- a/packages/core/src/storage.ts +++ b/packages/core/src/storage.ts @@ -101,6 +101,12 @@ export type WithLookup = T & { */ export type FindResult = WithLookup[] +/** + * @public + */ +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface TxResult {} + /** * @public */ @@ -110,5 +116,5 @@ export interface Storage { query: DocumentQuery, options?: FindOptions ) => Promise> - tx: (tx: Tx) => Promise + tx: (tx: Tx) => Promise } diff --git a/packages/core/src/tx.ts b/packages/core/src/tx.ts index c4d376c3d8..4a86b71cfd 100644 --- a/packages/core/src/tx.ts +++ b/packages/core/src/tx.ts @@ -15,7 +15,7 @@ import type { KeysByType } from 'simplytyped' import type { Class, Data, Doc, Domain, Ref, Account, Space, Arr, Mixin, PropertyType } from './classes' -import { DocumentQuery, FindOptions, FindResult, Storage, WithLookup } from './storage' +import type { DocumentQuery, FindOptions, FindResult, Storage, WithLookup, TxResult } from './storage' import core from './component' import { generateId } from './utils' @@ -172,14 +172,14 @@ export const DOMAIN_TX = 'tx' as Domain * @public */ export interface WithTx { - tx: (tx: Tx) => Promise + tx: (tx: Tx) => Promise } /** * @public */ export abstract class TxProcessor implements WithTx { - async tx (tx: Tx): Promise { + async tx (tx: Tx): Promise { switch (tx._class) { case core.class.TxCreateDoc: return await this.txCreateDoc(tx as TxCreateDoc) @@ -209,17 +209,18 @@ export abstract class TxProcessor implements WithTx { } as T } - protected abstract txCreateDoc (tx: TxCreateDoc): Promise - protected abstract txPutBag (tx: TxPutBag): Promise - protected abstract txUpdateDoc (tx: TxUpdateDoc): Promise - protected abstract txRemoveDoc (tx: TxRemoveDoc): Promise - protected abstract txMixin (tx: TxMixin): Promise + protected abstract txCreateDoc (tx: TxCreateDoc): Promise + protected abstract txPutBag (tx: TxPutBag): Promise + protected abstract txUpdateDoc (tx: TxUpdateDoc): Promise + protected abstract txRemoveDoc (tx: TxRemoveDoc): Promise + protected abstract txMixin (tx: TxMixin): Promise - protected async txBulkWrite (bulkTx: TxBulkWrite): Promise { + protected async txBulkWrite (bulkTx: TxBulkWrite): Promise { for (const tx of bulkTx.txes) { console.log('bulk', tx) await this.tx(tx) } + return {} } } @@ -241,7 +242,7 @@ export class TxOperations implements Storage { return (await this.findAll(_class, query, options))[0] } - tx (tx: Tx): Promise { + tx (tx: Tx): Promise { return this.storage.tx(tx) } @@ -263,7 +264,7 @@ export class TxOperations implements Storage { bag: string, key: string, value: P - ): Promise { + ): Promise { const tx = this.txFactory.createTxPutBag(_class, space, objectId, bag, key, value) return this.storage.tx(tx) } @@ -273,7 +274,7 @@ export class TxOperations implements Storage { space: Ref, objectId: Ref, operations: DocumentUpdate - ): Promise { + ): Promise { const tx = this.txFactory.createTxUpdateDoc(_class, space, objectId, operations) return this.storage.tx(tx) } @@ -282,7 +283,7 @@ export class TxOperations implements Storage { _class: Ref>, space: Ref, objectId: Ref - ): Promise { + ): Promise { const tx = this.txFactory.createTxRemoveDoc(_class, space, objectId) return this.storage.tx(tx) } @@ -292,7 +293,7 @@ export class TxOperations implements Storage { objectClass: Ref>, mixin: Ref>, attributes: ExtendedAttributes - ): Promise { + ): Promise { const tx = this.txFactory.createTxMixin(objectId, objectClass, mixin, attributes) return this.storage.tx(tx) } diff --git a/packages/presentation/src/utils.ts b/packages/presentation/src/utils.ts index bb781c0d0a..b13cd731b8 100644 --- a/packages/presentation/src/utils.ts +++ b/packages/presentation/src/utils.ts @@ -16,7 +16,7 @@ import { onDestroy } from 'svelte' -import { Doc, Ref, Class, DocumentQuery, FindOptions, Client, Hierarchy, Tx, getCurrentAccount, ModelDb } from '@anticrm/core' +import { Doc, Ref, Class, DocumentQuery, FindOptions, Client, Hierarchy, Tx, getCurrentAccount, ModelDb, TxResult } from '@anticrm/core' import { TxOperations } from '@anticrm/core' import { LiveQuery as LQ } from '@anticrm/query' import core from '@anticrm/core' @@ -38,7 +38,7 @@ class UIClient extends TxOperations implements Client { return this.client.getModel() } - tx(tx: Tx): Promise { + tx(tx: Tx): Promise { // return Promise.all([super.tx(tx), this.liveQuery.tx(tx)]) as unknown as Promise return super.tx(tx) } diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts index 9be56ac881..00162ba009 100644 --- a/packages/query/src/index.ts +++ b/packages/query/src/index.ts @@ -16,7 +16,7 @@ import { Ref, Class, Doc, Tx, DocumentQuery, TxCreateDoc, TxRemoveDoc, Client, FindOptions, TxUpdateDoc, _getOperator, TxProcessor, resultSort, SortingQuery, - FindResult, Hierarchy, Refs, WithLookup, LookupData, TxMixin, TxPutBag, ModelDb, TxBulkWrite + FindResult, Hierarchy, Refs, WithLookup, LookupData, TxMixin, TxPutBag, ModelDb, TxBulkWrite, TxResult } from '@anticrm/core' interface Query { @@ -91,7 +91,7 @@ export class LiveQuery extends TxProcessor implements Client { } } - protected override async txPutBag (tx: TxPutBag): Promise { + protected override async txPutBag (tx: TxPutBag): Promise { for (const q of this.queries) { if (q.result instanceof Promise) { q.result = await q.result @@ -107,13 +107,14 @@ export class LiveQuery extends TxProcessor implements Client { await this.callback(updatedDoc, q) } } + return {} } - protected txMixin (tx: TxMixin): Promise { + protected txMixin (tx: TxMixin): Promise { throw new Error('Method not implemented.') } - protected async txUpdateDoc (tx: TxUpdateDoc): Promise { + protected async txUpdateDoc (tx: TxUpdateDoc): Promise { console.log(`updating ${this.queries.length} queries`) for (const q of this.queries) { if (q.result instanceof Promise) { @@ -126,6 +127,7 @@ export class LiveQuery extends TxProcessor implements Client { await this.callback(updatedDoc, q) } } + return {} } private async lookup (doc: Doc, lookup: Refs): Promise { @@ -138,7 +140,7 @@ export class LiveQuery extends TxProcessor implements Client { (doc as WithLookup).$lookup = result } - protected async txCreateDoc (tx: TxCreateDoc): Promise { + protected async txCreateDoc (tx: TxCreateDoc): Promise { console.log('query tx', tx) for (const q of this.queries) { const doc = TxProcessor.createDoc2Doc(tx) @@ -162,9 +164,10 @@ export class LiveQuery extends TxProcessor implements Client { } } } + return {} } - protected async txRemoveDoc (tx: TxRemoveDoc): Promise { + protected async txRemoveDoc (tx: TxRemoveDoc): Promise { for (const q of this.queries) { if (q.result instanceof Promise) { q.result = await q.result @@ -175,16 +178,17 @@ export class LiveQuery extends TxProcessor implements Client { q.callback(q.result) } } + return {} } - protected override async txBulkWrite (tx: TxBulkWrite): Promise { + protected override async txBulkWrite (tx: TxBulkWrite): Promise { console.log('query: bulk') - await super.txBulkWrite(tx) + return await super.txBulkWrite(tx) } - async tx (tx: Tx): Promise { + async tx (tx: Tx): Promise { console.log('query tx', tx) - await super.tx(tx) + return await super.tx(tx) } // why this is separate from txUpdateDoc? diff --git a/plugins/client-resources/src/connection.ts b/plugins/client-resources/src/connection.ts index 54dfc1d1eb..d58873d17a 100644 --- a/plugins/client-resources/src/connection.ts +++ b/plugins/client-resources/src/connection.ts @@ -14,7 +14,7 @@ // limitations under the License. // -import type { Class, Doc, DocumentQuery, FindOptions, FindResult, Ref, Storage, Tx, TxHander } from '@anticrm/core' +import type { Class, Doc, DocumentQuery, FindOptions, FindResult, Ref, Storage, Tx, TxHander, TxResult } from '@anticrm/core' import type { ReqId } from '@anticrm/platform' import { serialize, readResponse } from '@anticrm/platform' @@ -94,7 +94,7 @@ class Connection implements Storage { return this.sendRequest('findAll', _class, query, options) } - tx (tx: Tx): Promise { + tx (tx: Tx): Promise { return this.sendRequest('tx', tx) } } diff --git a/server/contrib/src/connection.ts b/server/contrib/src/connection.ts index 8215263ed8..10da3130e6 100644 --- a/server/contrib/src/connection.ts +++ b/server/contrib/src/connection.ts @@ -14,7 +14,7 @@ // limitations under the License. // -import { Tx, Storage, Class, Doc, DocumentQuery, FindOptions, Ref, FindResult } from '@anticrm/core' +import type { Tx, Storage, Class, Doc, DocumentQuery, FindOptions, Ref, FindResult, TxResult } from '@anticrm/core' import { serialize } from '@anticrm/platform' import WebSocket from 'ws' @@ -29,11 +29,12 @@ export class ContributingClient implements Storage { throw new Error('findAll not implemeneted for contributing client') } - async tx (tx: Tx): Promise { + async tx (tx: Tx): Promise { this.websocket.send(serialize({ method: 'tx', params: [tx] })) + return {} } close (): void { diff --git a/server/core/src/fulltext.ts b/server/core/src/fulltext.ts index de8835db77..2204d80e4f 100644 --- a/server/core/src/fulltext.ts +++ b/server/core/src/fulltext.ts @@ -15,7 +15,7 @@ // import core, { Hierarchy, AnyAttribute, Storage, DocumentQuery, FindOptions, FindResult, TxProcessor, TxMixin, TxPutBag, TxRemoveDoc } from '@anticrm/core' -import type { AttachedDoc, TxUpdateDoc, TxCreateDoc, Doc, Ref, Class, Obj } from '@anticrm/core' +import type { AttachedDoc, TxUpdateDoc, TxCreateDoc, Doc, Ref, Class, Obj, TxResult } from '@anticrm/core' import type { IndexedDoc, FullTextAdapter, WithFind } from './types' @@ -33,15 +33,17 @@ export class FullTextIndex extends TxProcessor implements Storage { super() } - protected override async txPutBag (tx: TxPutBag): Promise { + protected override async txPutBag (tx: TxPutBag): Promise { console.log('FullTextIndex.txPutBag: Method not implemented.') + return {} } - protected override async txRemoveDoc (tx: TxRemoveDoc): Promise { + protected override async txRemoveDoc (tx: TxRemoveDoc): Promise { console.log('FullTextIndex.txRemoveDoc: Method not implemented.') + return {} } - protected txMixin (tx: TxMixin): Promise { + protected txMixin (tx: TxMixin): Promise { throw new Error('Method not implemented.') } @@ -74,9 +76,9 @@ export class FullTextIndex extends TxProcessor implements Storage { } } - protected override async txCreateDoc (tx: TxCreateDoc): Promise { + protected override async txCreateDoc (tx: TxCreateDoc): Promise { const attributes = this.getFullTextAttributes(tx.objectClass) - if (attributes === undefined) return + if (attributes === undefined) return {} const doc = TxProcessor.createDoc2Doc(tx) const content = attributes.map(attr => (doc as any)[attr.name]) // buildContent(doc, attributes) // (doc as any)[attribute.name] const indexedDoc: IndexedDoc = { @@ -100,9 +102,9 @@ export class FullTextIndex extends TxProcessor implements Storage { return await this.adapter.index(indexedDoc) } - protected override async txUpdateDoc (tx: TxUpdateDoc): Promise { + protected override async txUpdateDoc (tx: TxUpdateDoc): Promise { const attributes = this.getFullTextAttributes(tx.objectClass) - if (attributes === undefined) return + if (attributes === undefined) return {} const ops: any = tx.operations const update: any = {} let i = 0 @@ -117,5 +119,6 @@ export class FullTextIndex extends TxProcessor implements Storage { if (shouldUpdate) { return await this.adapter.update(tx.objectId, update) } + return {} } } diff --git a/server/core/src/storage.ts b/server/core/src/storage.ts index ac97586750..fc391dee12 100644 --- a/server/core/src/storage.ts +++ b/server/core/src/storage.ts @@ -14,7 +14,7 @@ // limitations under the License. // -import type { ServerStorage, Domain, Tx, TxCUD, Doc, Ref, Class, DocumentQuery, FindResult, FindOptions, Storage, TxBulkWrite } from '@anticrm/core' +import type { ServerStorage, Domain, Tx, TxCUD, Doc, Ref, Class, DocumentQuery, FindResult, FindOptions, Storage, TxBulkWrite, TxResult } from '@anticrm/core' import core, { Hierarchy, DOMAIN_TX, ModelDb } from '@anticrm/core' import type { FullTextAdapterFactory, FullTextAdapter } from './types' import { FullTextIndex } from './fulltext' @@ -88,7 +88,7 @@ class TServerStorage implements ServerStorage { return adapter } - private async routeTx (tx: Tx): Promise { + private async routeTx (tx: Tx): Promise { if (this.hierarchy.isDerived(tx._class, core.class.TxCUD)) { const txCUD = tx as TxCUD const domain = this.hierarchy.getDomain(txCUD.objectClass) @@ -102,6 +102,7 @@ class TServerStorage implements ServerStorage { } else { throw new Error('not implemented (routeTx)') } + return {} } } diff --git a/server/core/src/types.ts b/server/core/src/types.ts index 5f15993bc6..8cc2cd3c99 100644 --- a/server/core/src/types.ts +++ b/server/core/src/types.ts @@ -14,7 +14,7 @@ // limitations under the License. // -import type { Tx, Ref, Doc, Class, Space, Timestamp, Account, FindResult, DocumentQuery, FindOptions } from '@anticrm/core' +import type { Tx, Ref, Doc, Class, Space, Timestamp, Account, FindResult, DocumentQuery, FindOptions, TxResult } from '@anticrm/core' import { TxFactory, Hierarchy } from '@anticrm/core' import type { Resource } from '@anticrm/platform' @@ -67,8 +67,8 @@ export type SearchQuery = any // TODO: replace with DocumentQuery * @public */ export interface FullTextAdapter { - index: (doc: IndexedDoc) => Promise - update: (id: Ref, update: Record) => Promise + index: (doc: IndexedDoc) => Promise + update: (id: Ref, update: Record) => Promise search: (query: SearchQuery) => Promise } diff --git a/server/elastic/src/adapter.ts b/server/elastic/src/adapter.ts index 69df518086..f5af9042a2 100644 --- a/server/elastic/src/adapter.ts +++ b/server/elastic/src/adapter.ts @@ -14,7 +14,7 @@ // limitations under the License. // -import type { Doc, Ref } from '@anticrm/core' +import type { Doc, Ref, TxResult } from '@anticrm/core' import type { FullTextAdapter, IndexedDoc, SearchQuery } from '@anticrm/server-core' import { Client } from '@elastic/elasticsearch' @@ -58,7 +58,7 @@ class ElasticAdapter implements FullTextAdapter { return hits.map(hit => hit._source) } - async index (doc: IndexedDoc): Promise { + async index (doc: IndexedDoc): Promise { console.log('eastic: index', doc) if (doc.data === undefined) { const resp = await this.client.index({ @@ -81,9 +81,10 @@ class ElasticAdapter implements FullTextAdapter { console.log('resp', resp) console.log('error', (resp.meta as any)?.body?.error) } + return {} } - async update (id: Ref, update: Record): Promise { + async update (id: Ref, update: Record): Promise { const resp = await this.client.update({ index: this.db, id, @@ -92,6 +93,7 @@ class ElasticAdapter implements FullTextAdapter { } }) console.log('update', resp) + return {} } } diff --git a/server/mongo/src/storage.ts b/server/mongo/src/storage.ts index a028f25733..3ea6f92749 100644 --- a/server/mongo/src/storage.ts +++ b/server/mongo/src/storage.ts @@ -13,7 +13,7 @@ // limitations under the License. // -import type { Tx, Ref, Doc, Class, DocumentQuery, FindResult, FindOptions, TxCreateDoc, TxUpdateDoc, TxMixin, TxPutBag, TxRemoveDoc } from '@anticrm/core' +import type { Tx, Ref, Doc, Class, DocumentQuery, FindResult, FindOptions, TxCreateDoc, TxUpdateDoc, TxMixin, TxPutBag, TxRemoveDoc, TxResult } from '@anticrm/core' import core, { DOMAIN_TX, DOMAIN_MODEL, SortingOrder, TxProcessor, Hierarchy, isOperator, ModelDb } from '@anticrm/core' import type { DbAdapter, TxAdapter } from '@anticrm/server-core' @@ -121,27 +121,29 @@ abstract class MongoAdapterBase extends TxProcessor { } class MongoAdapter extends MongoAdapterBase { - protected override async txPutBag (tx: TxPutBag): Promise { + protected override async txPutBag (tx: TxPutBag): Promise { const domain = this.hierarchy.getDomain(tx.objectClass) console.log('mongo', { $set: { [tx.bag + '.' + tx.key]: tx.value } }) await this.db.collection(domain).updateOne({ _id: tx.objectId }, { $set: { [tx.bag + '.' + tx.key]: tx.value } }) + return {} } - protected txRemoveDoc (tx: TxRemoveDoc): Promise { + protected txRemoveDoc (tx: TxRemoveDoc): Promise { throw new Error('Method not implemented.') } - protected txMixin (tx: TxMixin): Promise { + protected txMixin (tx: TxMixin): Promise { throw new Error('Method not implemented.') } - protected override async txCreateDoc (tx: TxCreateDoc): Promise { + protected override async txCreateDoc (tx: TxCreateDoc): Promise { const doc = TxProcessor.createDoc2Doc(tx) const domain = this.hierarchy.getDomain(doc._class) await this.db.collection(domain).insertOne(translateDoc(doc)) + return {} } - protected override async txUpdateDoc (tx: TxUpdateDoc): Promise { + protected override async txUpdateDoc (tx: TxUpdateDoc): Promise { const domain = this.hierarchy.getDomain(tx.objectClass) if (isOperator(tx.operations)) { const operator = Object.keys(tx.operations)[0] @@ -182,38 +184,40 @@ class MongoAdapter extends MongoAdapterBase { } else { await this.db.collection(domain).updateOne({ _id: tx.objectId }, { $set: tx.operations }) } + return {} } - override tx (tx: Tx): Promise { + override tx (tx: Tx): Promise { console.log('mongo', tx) return super.tx(tx) } } class MongoTxAdapter extends MongoAdapterBase implements TxAdapter { - protected txCreateDoc (tx: TxCreateDoc): Promise { + protected txCreateDoc (tx: TxCreateDoc): Promise { throw new Error('Method not implemented.') } - protected txPutBag (tx: TxPutBag): Promise { + protected txPutBag (tx: TxPutBag): Promise { throw new Error('Method not implemented.') } - protected txUpdateDoc (tx: TxUpdateDoc): Promise { + protected txUpdateDoc (tx: TxUpdateDoc): Promise { throw new Error('Method not implemented.') } - protected txRemoveDoc (tx: TxRemoveDoc): Promise { + protected txRemoveDoc (tx: TxRemoveDoc): Promise { throw new Error('Method not implemented.') } - protected txMixin (tx: TxMixin): Promise { + protected txMixin (tx: TxMixin): Promise { throw new Error('Method not implemented.') } - override async tx (tx: Tx): Promise { + override async tx (tx: Tx): Promise { console.log('mongotx', tx) await this.db.collection(DOMAIN_TX).insertOne(translateDoc(tx)) + return {} } async getModel (): Promise { diff --git a/server/server/src/server.ts b/server/server/src/server.ts index aecd79bd48..407d8e9fd9 100644 --- a/server/server/src/server.ts +++ b/server/server/src/server.ts @@ -14,7 +14,7 @@ // limitations under the License. // -import { Class, Doc, DocumentQuery, DOMAIN_MODEL, DOMAIN_TX, FindOptions, FindResult, Hierarchy, ModelDb, Ref, Tx } from '@anticrm/core' +import { Class, Doc, DocumentQuery, DOMAIN_MODEL, DOMAIN_TX, FindOptions, FindResult, Hierarchy, ModelDb, Ref, Tx, TxResult } from '@anticrm/core' import { start as startJsonRpc } from '@anticrm/server-ws' import { createMongoAdapter, createMongoTxAdapter } from '@anticrm/mongo' import { createElasticAdapter } from '@anticrm/elastic' @@ -29,7 +29,7 @@ import { serverViewId } from '@anticrm/server-view' class NullDbAdapter implements DbAdapter { async init (model: Tx[]): Promise {} async findAll (_class: Ref>, query: DocumentQuery, options?: FindOptions | undefined): Promise> { return [] } - async tx (tx: Tx): Promise {} + async tx (tx: Tx): Promise { return {} } } async function createNullAdapter (hierarchy: Hierarchy, url: string, db: string, modelDb: ModelDb): Promise { diff --git a/server/ws/src/server.ts b/server/ws/src/server.ts index 4d0184425e..ec624596bd 100644 --- a/server/ws/src/server.ts +++ b/server/ws/src/server.ts @@ -20,7 +20,7 @@ import { createServer, IncomingMessage } from 'http' import WebSocket, { Server } from 'ws' import { decode } from 'jwt-simple' -import type { Doc, Ref, Class, FindOptions, FindResult, Tx, DocumentQuery, Storage, ServerStorage } from '@anticrm/core' +import type { Doc, Ref, Class, FindOptions, FindResult, Tx, DocumentQuery, Storage, ServerStorage, TxResult } from '@anticrm/core' let LOGGING_ENABLED = true @@ -39,12 +39,13 @@ class Session implements Storage { return await this.storage.findAll(_class, query, options) } - async tx (tx: Tx): Promise { + async tx (tx: Tx): Promise { const derived = await this.storage.tx(tx) this.manager.broadcast(this, this.token, { result: tx }) for (const tx of derived) { this.manager.broadcast(null, this.token, { result: tx }) } + return {} } }