mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-10 19:57:43 +02:00
introduce TxResult
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
@@ -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<any>): Promise<void> {
|
||||
protected override async txPutBag (tx: TxPutBag<any>): Promise<TxResult> {
|
||||
console.log('FullTextIndex.txPutBag: Method not implemented.')
|
||||
return {}
|
||||
}
|
||||
|
||||
protected override async txRemoveDoc (tx: TxRemoveDoc<Doc>): Promise<void> {
|
||||
protected override async txRemoveDoc (tx: TxRemoveDoc<Doc>): Promise<TxResult> {
|
||||
console.log('FullTextIndex.txRemoveDoc: Method not implemented.')
|
||||
return {}
|
||||
}
|
||||
|
||||
protected txMixin (tx: TxMixin<Doc, Doc>): Promise<void> {
|
||||
protected txMixin (tx: TxMixin<Doc, Doc>): Promise<TxResult> {
|
||||
throw new Error('Method not implemented.')
|
||||
}
|
||||
|
||||
@@ -74,9 +76,9 @@ export class FullTextIndex extends TxProcessor implements Storage {
|
||||
}
|
||||
}
|
||||
|
||||
protected override async txCreateDoc (tx: TxCreateDoc<Doc>): Promise<void> {
|
||||
protected override async txCreateDoc (tx: TxCreateDoc<Doc>): Promise<TxResult> {
|
||||
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<Doc>): Promise<void> {
|
||||
protected override async txUpdateDoc (tx: TxUpdateDoc<Doc>): Promise<TxResult> {
|
||||
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 {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<void> {
|
||||
private async routeTx (tx: Tx): Promise<TxResult> {
|
||||
if (this.hierarchy.isDerived(tx._class, core.class.TxCUD)) {
|
||||
const txCUD = tx as TxCUD<Doc>
|
||||
const domain = this.hierarchy.getDomain(txCUD.objectClass)
|
||||
@@ -102,6 +102,7 @@ class TServerStorage implements ServerStorage {
|
||||
} else {
|
||||
throw new Error('not implemented (routeTx)')
|
||||
}
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<void>
|
||||
update: (id: Ref<Doc>, update: Record<string, any>) => Promise<void>
|
||||
index: (doc: IndexedDoc) => Promise<TxResult>
|
||||
update: (id: Ref<Doc>, update: Record<string, any>) => Promise<TxResult>
|
||||
search: (query: SearchQuery) => Promise<IndexedDoc[]>
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user