mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-23 05:53:09 +03:00
initial BulkWrite
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
877c2f47a4
commit
4a45a0b5fe
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -17,7 +17,7 @@ import { Builder } from '@anticrm/model'
|
||||
import core from './component'
|
||||
import { TAttribute, TClass, TDoc, TMixin, TObj, TType, TTypeString, TTypeBoolean, TTypeTimestamp } from './core'
|
||||
import { TSpace, TAccount, TState, TSpaceWithStates } from './security'
|
||||
import { TTx, TTxCreateDoc, TTxMixin, TTxUpdateDoc, TTxCUD, TTxPutBag, TTxRemoveDoc } from './tx'
|
||||
import { TTx, TTxCreateDoc, TTxMixin, TTxUpdateDoc, TTxCUD, TTxPutBag, TTxRemoveDoc, TTxBulkWrite } from './tx'
|
||||
|
||||
export * from './core'
|
||||
export * from './security'
|
||||
@ -37,6 +37,7 @@ export function createModel (builder: Builder): void {
|
||||
TTxMixin,
|
||||
TTxUpdateDoc,
|
||||
TTxRemoveDoc,
|
||||
TTxBulkWrite,
|
||||
TSpace,
|
||||
TSpaceWithStates,
|
||||
TAccount,
|
||||
|
@ -29,7 +29,8 @@ import type {
|
||||
Mixin,
|
||||
ExtendedAttributes,
|
||||
PropertyType,
|
||||
TxPutBag
|
||||
TxPutBag,
|
||||
TxBulkWrite
|
||||
} from '@anticrm/core'
|
||||
import { DOMAIN_TX } from '@anticrm/core'
|
||||
import { Model } from '@anticrm/model'
|
||||
@ -75,3 +76,8 @@ export class TTxUpdateDoc<T extends Doc> extends TTxCUD<T> implements TxUpdateDo
|
||||
@Model(core.class.TxRemoveDoc, core.class.TxCUD)
|
||||
export class TTxRemoveDoc<T extends Doc> extends TTxCUD<T> implements TxRemoveDoc<T> {
|
||||
}
|
||||
|
||||
@Model(core.class.TxBulkWrite, core.class.Tx)
|
||||
export class TTxBulkWrite extends TTx implements TxBulkWrite {
|
||||
txes!: TxCUD<Doc>[]
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
import type { Plugin, StatusCode } from '@anticrm/platform'
|
||||
import { plugin } from '@anticrm/platform'
|
||||
import type { Account, Class, Doc, Obj, Ref, Space, AnyAttribute, State, Type, PropertyType, SpaceWithStates, Timestamp } from './classes'
|
||||
import type { Tx, TxCreateDoc, TxCUD, TxMixin, TxPutBag, TxRemoveDoc, TxUpdateDoc } from './tx'
|
||||
import type { Tx, TxBulkWrite, TxCreateDoc, TxCUD, TxMixin, TxPutBag, TxRemoveDoc, TxUpdateDoc } from './tx'
|
||||
|
||||
/**
|
||||
* @public
|
||||
@ -29,6 +29,7 @@ export default plugin(coreId, {
|
||||
Class: '' as Ref<Class<Class<Obj>>>,
|
||||
Attribute: '' as Ref<Class<AnyAttribute>>,
|
||||
Tx: '' as Ref<Class<Tx>>,
|
||||
TxBulkWrite: '' as Ref<Class<TxBulkWrite>>,
|
||||
TxCUD: '' as Ref<Class<TxCUD<Doc>>>,
|
||||
TxCreateDoc: '' as Ref<Class<TxCreateDoc<Doc>>>,
|
||||
TxMixin: '' as Ref<Class<TxMixin<Doc, Doc>>>,
|
||||
|
@ -50,6 +50,13 @@ export interface TxPutBag<T extends PropertyType> extends TxCUD<Doc> {
|
||||
value: T
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface TxBulkWrite extends Tx {
|
||||
txes: TxCUD<Doc>[]
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
@ -168,6 +175,8 @@ export abstract class TxProcessor implements WithTx {
|
||||
return await this.txMixin(tx as TxMixin<Doc, Doc>)
|
||||
case core.class.TxPutBag:
|
||||
return await this.txPutBag(tx as TxPutBag<PropertyType>)
|
||||
case core.class.TxBulkWrite:
|
||||
return await this.txBulkWrite(tx as TxBulkWrite)
|
||||
}
|
||||
throw new Error('TxProcessor: unhandled transaction class: ' + tx._class)
|
||||
}
|
||||
@ -189,13 +198,20 @@ export abstract class TxProcessor implements WithTx {
|
||||
protected abstract txUpdateDoc (tx: TxUpdateDoc<Doc>): Promise<void>
|
||||
protected abstract txRemoveDoc (tx: TxRemoveDoc<Doc>): Promise<void>
|
||||
protected abstract txMixin (tx: TxMixin<Doc, Doc>): Promise<void>
|
||||
|
||||
protected async txBulkWrite (bulkTx: TxBulkWrite): Promise<void> {
|
||||
for (const tx of bulkTx.txes) {
|
||||
console.log('bulk', tx)
|
||||
await this.tx(tx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export class TxOperations implements Storage {
|
||||
private readonly txFactory: TxFactory
|
||||
readonly txFactory: TxFactory
|
||||
|
||||
constructor (private readonly storage: Storage, user: Ref<Account>) {
|
||||
this.txFactory = new TxFactory(user)
|
||||
@ -359,4 +375,16 @@ export class TxFactory {
|
||||
attributes
|
||||
}
|
||||
}
|
||||
|
||||
createTxBulkWrite (space: Ref<Space>, txes: TxCUD<Doc>[]): TxBulkWrite {
|
||||
return {
|
||||
_id: generateId(),
|
||||
_class: core.class.TxBulkWrite,
|
||||
space: core.space.Tx,
|
||||
modifiedBy: this.account,
|
||||
modifiedOn: Date.now(),
|
||||
objectSpace: space,
|
||||
txes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
FindResult, Hierarchy, Refs, WithLookup, LookupData, TxMixin, TxPutBag, ModelDb, TxBulkWrite
|
||||
} from '@anticrm/core'
|
||||
|
||||
interface Query {
|
||||
@ -177,8 +177,13 @@ export class LiveQuery extends TxProcessor implements Client {
|
||||
}
|
||||
}
|
||||
|
||||
protected override async txBulkWrite (tx: TxBulkWrite): Promise<void> {
|
||||
console.log('query: bulk')
|
||||
await super.txBulkWrite(tx)
|
||||
}
|
||||
|
||||
async tx (tx: Tx): Promise<void> {
|
||||
// await this.client.tx(tx)
|
||||
console.log('query tx', tx)
|
||||
await super.tx(tx)
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import type { Ref, Class, Doc, Space, SpaceWithStates, FindOptions, State } from '@anticrm/core'
|
||||
import type { Ref, Class, Doc, Space, SpaceWithStates, FindOptions, State, TxBulkWrite } from '@anticrm/core'
|
||||
import { getResource } from '@anticrm/platform'
|
||||
import { buildModel } from '../utils'
|
||||
import { getClient } from '@anticrm/presentation'
|
||||
@ -83,6 +83,26 @@
|
||||
client.updateDoc(_class, space, id, { state })
|
||||
|
||||
if (dragCardInitialPosition !== to) {
|
||||
|
||||
// const remove = client.txFactory.createTxUpdateDoc(core.class.SpaceWithStates, core.space.Model, space, {
|
||||
// $pull: {
|
||||
// order: id
|
||||
// }
|
||||
// })
|
||||
|
||||
// const add = client.txFactory.createTxUpdateDoc(core.class.SpaceWithStates, core.space.Model, space, {
|
||||
// $push: {
|
||||
// order: {
|
||||
// $each: [id],
|
||||
// $position: to
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
|
||||
// const updateTx = client.txFactory.createTxBulkWrite(core.space.Model, [remove, add])
|
||||
|
||||
// await client.tx(updateTx)
|
||||
|
||||
await client.updateDoc(core.class.SpaceWithStates, core.space.Model, space, {
|
||||
$pull: {
|
||||
order: id
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user