Improve TxOperations API (#809)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2022-01-13 16:06:50 +07:00 committed by GitHub
parent 4f70d992e4
commit a2259c002b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 264 additions and 272 deletions

View File

@ -17,7 +17,7 @@
import { Space } from '../classes'
import { createClient } from '../client'
import core from '../component'
import { TxOperations } from '../tx'
import { TxOperations } from '../operations'
import { connect } from './connection'
describe('client', () => {

View File

@ -13,22 +13,44 @@
// limitations under the License.
//
import type { Class, Obj, Ref, Doc } from '../classes'
import { Client } from '..'
import type { Class, Doc, Obj, Ref } from '../classes'
import core from '../component'
import { Hierarchy } from '../hierarchy'
import { ModelDb, TxDb } from '../memdb'
import { SortingOrder } from '../storage'
import { TxOperations } from '../tx'
import { TxOperations } from '../operations'
import { DocumentQuery, FindOptions, SortingOrder, WithLookup } from '../storage'
import { Tx } from '../tx'
import { genMinModel, test, TestMixin } from './minmodel'
const txes = genMinModel()
async function createModel (): Promise<{ model: ModelDb, hierarchy: Hierarchy, txDb: TxDb }> {
class ClientModel extends ModelDb implements Client {
notify?: ((tx: Tx) => void) | undefined
getHierarchy (): Hierarchy {
return this.hierarchy
}
getModel (): ModelDb {
return this
}
async findOne<T extends Doc>(_class: Ref<Class<T>>, query: DocumentQuery<T>, options?: FindOptions<T>): Promise<WithLookup<T> | undefined> {
return (await this.findAll(_class, query, options)).shift()
}
async close (): Promise<void> {
}
}
async function createModel (): Promise<{ model: ClientModel, hierarchy: Hierarchy, txDb: TxDb }> {
const hierarchy = new Hierarchy()
for (const tx of txes) {
hierarchy.tx(tx)
}
const model = new ModelDb(hierarchy)
const model = new ClientModel(hierarchy)
for (const tx of txes) {
await model.tx(tx)
}
@ -172,7 +194,7 @@ describe('memdb', () => {
it('should push to array', async () => {
const hierarchy = new Hierarchy()
for (const tx of txes) hierarchy.tx(tx)
const model = new TxOperations(new ModelDb(hierarchy), core.account.System)
const model = new TxOperations(new ClientModel(hierarchy), core.account.System)
for (const tx of txes) await model.tx(tx)
const space = await model.createDoc(core.class.Space, core.space.Model, {
name: 'name',
@ -190,7 +212,7 @@ describe('memdb', () => {
it('limit and sorting', async () => {
const hierarchy = new Hierarchy()
for (const tx of txes) hierarchy.tx(tx)
const model = new TxOperations(new ModelDb(hierarchy), core.account.System)
const model = new TxOperations(new ClientModel(hierarchy), core.account.System)
for (const tx of txes) await model.tx(tx)
const without = await model.findAll(core.class.Space, {})

View File

@ -15,6 +15,7 @@
export * from './classes'
export * from './tx'
export * from './storage'
export * from './operations'
export * from './utils'
export * from './hierarchy'
export * from './memdb'

View File

@ -27,13 +27,11 @@ import { TxProcessor } from './tx'
* @public
*/
export abstract class MemDb extends TxProcessor {
protected readonly hierarchy: Hierarchy
private readonly objectsByClass = new Map<Ref<Class<Doc>>, Doc[]>()
private readonly objectById = new Map<Ref<Doc>, Doc>()
constructor (hierarchy: Hierarchy) {
constructor (protected readonly hierarchy: Hierarchy) {
super()
this.hierarchy = hierarchy
}
private getObjectsByClass (_class: Ref<Class<Doc>>): Doc[] {

View File

@ -0,0 +1,196 @@
import { Collection, DocumentUpdate, Hierarchy, MixinData, MixinUpdate, ModelDb } from '.'
import type { Account, AttachedData, AttachedDoc, Class, Data, Doc, Mixin, PropertyType, Ref, Space } from './classes'
import { Client } from './client'
import type { DocumentQuery, FindOptions, FindResult, TxResult, WithLookup } from './storage'
import { Tx, TxFactory } from './tx'
import core from './component'
/**
* @public
*
* High Level operations with client, will create low level transactions.
*
* `notify` is not supported by TxOperations.
*/
export class TxOperations implements Omit<Client, 'notify'> {
readonly txFactory: TxFactory
constructor (protected readonly client: Client, user: Ref<Account>) {
this.txFactory = new TxFactory(user)
}
getHierarchy (): Hierarchy {
return this.client.getHierarchy()
}
getModel (): ModelDb {
return this.client.getModel()
}
async close (): Promise<void> {
return await this.client.close()
}
findAll <T extends Doc>(_class: Ref<Class<T>>, query: DocumentQuery<T>, options?: FindOptions<T> | undefined): Promise<FindResult<T>> {
return this.client.findAll(_class, query, options)
}
async findOne <T extends Doc>(_class: Ref<Class<T>>, query: DocumentQuery<T>, options?: FindOptions<T> | undefined): Promise<WithLookup<T> | undefined> {
return (await this.findAll(_class, query, options))[0]
}
tx (tx: Tx): Promise<TxResult> {
return this.client.tx(tx)
}
async createDoc<T extends Doc> (
_class: Ref<Class<T>>,
space: Ref<Space>,
attributes: Data<T>,
id?: Ref<T>
): Promise<Ref<T>> {
const tx = this.txFactory.createTxCreateDoc(_class, space, attributes, id)
await this.client.tx(tx)
return tx.objectId
}
async addCollection<T extends Doc, P extends AttachedDoc>(
_class: Ref<Class<P>>,
space: Ref<Space>,
attachedTo: Ref<T>,
attachedToClass: Ref<Class<T>>,
collection: string,
attributes: AttachedData<P>,
id?: Ref<P>
): Promise<Ref<T>> {
const tx = this.txFactory.createTxCollectionCUD<T, P>(
attachedToClass,
attachedTo,
space,
collection,
this.txFactory.createTxCreateDoc<P>(_class, space, attributes as unknown as Data<P>, id)
)
await this.client.tx(tx)
return tx.objectId
}
async updateCollection<T extends Doc, P extends AttachedDoc>(
_class: Ref<Class<P>>,
space: Ref<Space>,
objectId: Ref<P>,
attachedTo: Ref<T>,
attachedToClass: Ref<Class<T>>,
collection: string,
operations: DocumentUpdate<P>,
retrieve?: boolean
): Promise<Ref<T>> {
const tx = this.txFactory.createTxCollectionCUD(
attachedToClass,
attachedTo,
space,
collection,
this.txFactory.createTxUpdateDoc(_class, space, objectId, operations, retrieve)
)
await this.client.tx(tx)
return tx.objectId
}
async removeCollection<T extends Doc, P extends AttachedDoc>(
_class: Ref<Class<P>>,
space: Ref<Space>,
objectId: Ref<P>,
attachedTo: Ref<T>,
attachedToClass: Ref<Class<T>>,
collection: string
): Promise<Ref<T>> {
const tx = this.txFactory.createTxCollectionCUD(
attachedToClass,
attachedTo,
space,
collection,
this.txFactory.createTxRemoveDoc(_class, space, objectId)
)
await this.client.tx(tx)
return tx.objectId
}
putBag <P extends PropertyType>(
_class: Ref<Class<Doc>>,
space: Ref<Space>,
objectId: Ref<Doc>,
bag: string,
key: string,
value: P
): Promise<TxResult> {
const tx = this.txFactory.createTxPutBag(_class, space, objectId, bag, key, value)
return this.client.tx(tx)
}
updateDoc <T extends Doc>(
_class: Ref<Class<T>>,
space: Ref<Space>,
objectId: Ref<T>,
operations: DocumentUpdate<T>,
retrieve?: boolean
): Promise<TxResult> {
const tx = this.txFactory.createTxUpdateDoc(_class, space, objectId, operations, retrieve)
return this.client.tx(tx)
}
removeDoc<T extends Doc> (
_class: Ref<Class<T>>,
space: Ref<Space>,
objectId: Ref<T>
): Promise<TxResult> {
const tx = this.txFactory.createTxRemoveDoc(_class, space, objectId)
return this.client.tx(tx)
}
createMixin<D extends Doc, M extends D>(
objectId: Ref<D>,
objectClass: Ref<Class<D>>,
objectSpace: Ref<Space>,
mixin: Ref<Mixin<M>>,
attributes: MixinData<D, M>
): Promise<TxResult> {
const tx = this.txFactory.createTxMixin(objectId, objectClass, objectSpace, mixin, attributes)
return this.client.tx(tx)
}
updateMixin<D extends Doc, M extends D>(
objectId: Ref<D>,
objectClass: Ref<Class<D>>,
objectSpace: Ref<Space>,
mixin: Ref<Mixin<M>>,
attributes: MixinUpdate<D, M>
): Promise<TxResult> {
const tx = this.txFactory.createTxMixin(objectId, objectClass, objectSpace, mixin, attributes)
return this.client.tx(tx)
}
update<T extends Doc>(doc: T, update: DocumentUpdate<T>, retrieve?: boolean): Promise<TxResult> {
if (this.client.getHierarchy().isDerived(doc._class, core.class.AttachedDoc)) {
const adoc = doc as unknown as AttachedDoc
return this.updateCollection(doc._class, doc.space, adoc._id, adoc.attachedTo, adoc.attachedToClass, adoc.collection, update, retrieve)
}
return this.updateDoc(doc._class, doc.space, doc._id, update, retrieve)
}
remove<T extends Doc>(doc: T): Promise<TxResult> {
if (this.client.getHierarchy().isDerived(doc._class, core.class.AttachedDoc)) {
const adoc = doc as unknown as AttachedDoc
return this.removeCollection(doc._class, doc.space, adoc._id, adoc.attachedTo, adoc.attachedToClass, adoc.collection)
}
return this.removeDoc(doc._class, doc.space, doc._id)
}
add<T extends Doc, P extends AttachedDoc>(parent: T, _class: Ref<Class<P>>, obj: AttachedData<P>, objId?: Ref<P>): Promise<TxResult> {
const h = this.client.getHierarchy()
const attrs = Array.from(h.getAllAttributes(parent._class).values())
const collections = attrs.filter(a => h.isDerived(a.type._class, core.class.Collection) && h.isDerived(_class, (a.type as Collection<AttachedDoc>).of))
if (collections.length !== 1) {
throw new Error('Please use addCollection method, collection could not be detected.')
}
return this.addCollection<T, P>(_class, parent.space, parent._id, parent._class, collections[0].name, obj, objId)
}
}

View File

@ -14,11 +14,11 @@
//
import type { KeysByType } from 'simplytyped'
import type { Account, Arr, AttachedData, AttachedDoc, Class, Data, Doc, Domain, Mixin, PropertyType, Ref, Space } from './classes'
import type { Account, Arr, AttachedDoc, Class, Data, Doc, Domain, Mixin, PropertyType, Ref, Space } from './classes'
import core from './component'
import { _getOperator } from './operator'
import { _toDoc } from './proxy'
import type { DocumentQuery, FindOptions, FindResult, Storage, TxResult, WithLookup } from './storage'
import type { TxResult } from './storage'
import { generateId } from './utils'
/**
@ -302,153 +302,6 @@ export abstract class TxProcessor implements WithTx {
}
}
/**
* @public
*/
export class TxOperations implements Storage {
readonly txFactory: TxFactory
constructor (private readonly storage: Storage, user: Ref<Account>) {
this.txFactory = new TxFactory(user)
}
findAll <T extends Doc>(_class: Ref<Class<T>>, query: DocumentQuery<T>, options?: FindOptions<T> | undefined): Promise<FindResult<T>> {
return this.storage.findAll(_class, query, options)
}
async findOne <T extends Doc>(_class: Ref<Class<T>>, query: DocumentQuery<T>, options?: FindOptions<T> | undefined): Promise<WithLookup<T> | undefined> {
return (await this.findAll(_class, query, options))[0]
}
tx (tx: Tx): Promise<TxResult> {
return this.storage.tx(tx)
}
async createDoc<T extends Doc> (
_class: Ref<Class<T>>,
space: Ref<Space>,
attributes: Data<T>,
id?: Ref<T>
): Promise<Ref<T>> {
const tx = this.txFactory.createTxCreateDoc(_class, space, attributes, id)
await this.storage.tx(tx)
return tx.objectId
}
async addCollection<T extends Doc, P extends AttachedDoc>(
_class: Ref<Class<P>>,
space: Ref<Space>,
attachedTo: Ref<T>,
attachedToClass: Ref<Class<T>>,
collection: string,
attributes: AttachedData<P>,
id?: Ref<P>
): Promise<Ref<T>> {
const tx = this.txFactory.createTxCollectionCUD<T, P>(
attachedToClass,
attachedTo,
space,
collection,
this.txFactory.createTxCreateDoc<P>(_class, space, attributes as unknown as Data<P>, id)
)
await this.storage.tx(tx)
return tx.objectId
}
async updateCollection<T extends Doc, P extends AttachedDoc>(
_class: Ref<Class<P>>,
space: Ref<Space>,
objectId: Ref<P>,
attachedTo: Ref<T>,
attachedToClass: Ref<Class<T>>,
collection: string,
operations: DocumentUpdate<P>
): Promise<Ref<T>> {
const tx = this.txFactory.createTxCollectionCUD(
attachedToClass,
attachedTo,
space,
collection,
this.txFactory.createTxUpdateDoc(_class, space, objectId, operations)
)
await this.storage.tx(tx)
return tx.objectId
}
async removeCollection<T extends Doc, P extends AttachedDoc>(
_class: Ref<Class<P>>,
space: Ref<Space>,
objectId: Ref<P>,
attachedTo: Ref<T>,
attachedToClass: Ref<Class<T>>,
collection: string
): Promise<Ref<T>> {
const tx = this.txFactory.createTxCollectionCUD(
attachedToClass,
attachedTo,
space,
collection,
this.txFactory.createTxRemoveDoc(_class, space, objectId)
)
await this.storage.tx(tx)
return tx.objectId
}
putBag <P extends PropertyType>(
_class: Ref<Class<Doc>>,
space: Ref<Space>,
objectId: Ref<Doc>,
bag: string,
key: string,
value: P
): Promise<TxResult> {
const tx = this.txFactory.createTxPutBag(_class, space, objectId, bag, key, value)
return this.storage.tx(tx)
}
updateDoc <T extends Doc>(
_class: Ref<Class<T>>,
space: Ref<Space>,
objectId: Ref<T>,
operations: DocumentUpdate<T>,
retrieve?: boolean
): Promise<TxResult> {
const tx = this.txFactory.createTxUpdateDoc(_class, space, objectId, operations, retrieve)
return this.storage.tx(tx)
}
removeDoc<T extends Doc> (
_class: Ref<Class<T>>,
space: Ref<Space>,
objectId: Ref<T>
): Promise<TxResult> {
const tx = this.txFactory.createTxRemoveDoc(_class, space, objectId)
return this.storage.tx(tx)
}
createMixin<D extends Doc, M extends D>(
objectId: Ref<D>,
objectClass: Ref<Class<D>>,
objectSpace: Ref<Space>,
mixin: Ref<Mixin<M>>,
attributes: MixinData<D, M>
): Promise<TxResult> {
const tx = this.txFactory.createTxMixin(objectId, objectClass, objectSpace, mixin, attributes)
return this.storage.tx(tx)
}
updateMixin<D extends Doc, M extends D>(
objectId: Ref<D>,
objectClass: Ref<Class<D>>,
objectSpace: Ref<Space>,
mixin: Ref<Mixin<M>>,
attributes: MixinUpdate<D, M>
): Promise<TxResult> {
const tx = this.txFactory.createTxMixin(objectId, objectClass, objectSpace, mixin, attributes)
return this.storage.tx(tx)
}
}
/**
* @public
*/

View File

@ -8,17 +8,14 @@ export interface KeyedAttribute {
attr: AnyAttribute
}
export async function updateAttribute (client: Client & TxOperations, object: Doc, _class: Ref<Class<Doc>>, attribute: KeyedAttribute, value: any): Promise<void> {
export async function updateAttribute (client: TxOperations, object: Doc, _class: Ref<Class<Doc>>, attribute: KeyedAttribute, value: any): Promise<void> {
const doc = object
const attributeKey = attribute.key
const attr = attribute.attr
if (client.getHierarchy().isMixin(attr.attributeOf)) {
await client.updateMixin(doc._id, _class, doc.space, attr.attributeOf, { [attributeKey]: value })
} else if (client.getHierarchy().isDerived(object._class, core.class.AttachedDoc)) {
const adoc = object as AttachedDoc
await client.updateCollection(_class, object.space, adoc._id, adoc.attachedTo, adoc.attachedToClass, adoc.collection, { [attributeKey]: value })
} else {
await client.updateDoc(_class, doc.space, doc._id, { [attributeKey]: value })
await client.update(object, { [attributeKey]: value })
}
}

View File

@ -14,59 +14,30 @@
// limitations under the License.
//
import core, {
AnyAttribute, ArrOf, AttachedDoc, Class, Client, Collection, Doc, DocumentQuery,
FindOptions, getCurrentAccount, Ref, RefTo, Tx, TxOperations, TxResult
} from '@anticrm/core'
import login from '@anticrm/login'
import { getMetadata } from '@anticrm/platform'
import { LiveQuery as LQ } from '@anticrm/query'
import { onDestroy } from 'svelte'
import core, {
Doc,
Ref,
Class,
DocumentQuery,
FindOptions,
Client,
Hierarchy,
Tx,
getCurrentAccount,
ModelDb,
TxResult,
TxOperations,
AnyAttribute,
RefTo,
Collection,
AttachedDoc,
ArrOf
} from '@anticrm/core'
import { LiveQuery as LQ } from '@anticrm/query'
import { getMetadata } from '@anticrm/platform'
import login from '@anticrm/login'
let liveQuery: LQ
let client: Client & TxOperations
let client: TxOperations
class UIClient extends TxOperations implements Client {
constructor (private readonly client: Client, private readonly liveQuery: LQ) {
constructor (client: Client, private readonly liveQuery: LQ) {
super(client, getCurrentAccount()._id)
}
getHierarchy (): Hierarchy {
return this.client.getHierarchy()
}
getModel (): ModelDb {
return this.client.getModel()
}
async tx (tx: Tx): Promise<TxResult> {
override async tx (tx: Tx): Promise<TxResult> {
// return Promise.all([super.tx(tx), this.liveQuery.tx(tx)]) as unknown as Promise<void>
return await super.tx(tx)
}
async close (): Promise<void> {
await client.close()
}
}
export function getClient (): Client & TxOperations {
export function getClient (): TxOperations {
return client
}

View File

@ -43,9 +43,7 @@
)
function onMessage (event: CustomEvent) {
client.addCollection(chunter.class.Comment, object.space, object._id, object._class, 'comments', {
message: event.detail
})
client.add(object, chunter.class.Comment, { message: event.detail })
}
let viewlets: Map<ActivityKey, TxViewlet>

View File

@ -14,7 +14,7 @@ export type TxDisplayViewlet =
| undefined
async function createPseudoViewlet (
client: Client & TxOperations,
client: TxOperations,
dtx: DisplayTx,
label: string
): Promise<TxDisplayViewlet> {
@ -36,7 +36,7 @@ async function createPseudoViewlet (
}
export async function updateViewlet (
client: Client & TxOperations,
client: TxOperations,
viewlets: Map<ActivityKey, TxViewlet>,
dtx: DisplayTx
): Promise<{
@ -71,7 +71,7 @@ export async function updateViewlet (
async function checkInlineViewlets (
dtx: DisplayTx,
viewlet: TxDisplayViewlet,
client: Client & TxOperations,
client: TxOperations,
model: AttributeModel[]
): Promise<{ viewlet: TxDisplayViewlet, model: AttributeModel[] }> {
if (dtx.tx._class === core.class.TxCreateDoc) {
@ -89,7 +89,7 @@ async function checkInlineViewlets (
async function createUpdateModel (
dtx: DisplayTx,
client: Client & TxOperations,
client: TxOperations,
model: AttributeModel[]
): Promise<AttributeModel[]> {
if (dtx.updateTx !== undefined) {
@ -116,7 +116,7 @@ async function createUpdateModel (
return model
}
function getHiddenAttrs (client: Client & TxOperations, _class: Ref<Class<Doc>>): Set<string> {
function getHiddenAttrs (client: TxOperations, _class: Ref<Class<Doc>>): Set<string> {
return new Set(
[...client.getHierarchy().getAllAttributes(_class).entries()]
.filter(([, attr]) => attr.hidden === true)
@ -124,7 +124,7 @@ function getHiddenAttrs (client: Client & TxOperations, _class: Ref<Class<Doc>>)
)
}
export async function getValue (client: Client & TxOperations, m: AttributeModel, utx: any): Promise<any> {
export async function getValue (client: TxOperations, m: AttributeModel, utx: any): Promise<any> {
const val = utx[m.key]
if (client.getHierarchy().isDerived(m._class, core.class.Doc) && typeof val === 'string') {

View File

@ -15,15 +15,14 @@
-->
<script lang="ts">
import contact, { Contact } from '@anticrm/contact'
import { AttachedData, Ref, SortingOrder, Space } from '@anticrm/core'
import { generateId } from '@anticrm/core'
import { AttachedData, generateId, Ref, SortingOrder, Space } from '@anticrm/core'
import type { Customer, Lead } from '@anticrm/lead'
import { OK, Status } from '@anticrm/platform'
import { Card, getClient, UserBox } from '@anticrm/presentation'
import type { Customer, Lead } from '@anticrm/lead'
import task, { calcRank } from '@anticrm/task'
import { EditBox, Grid, Status as StatusControl } from '@anticrm/ui'
import { createEventDispatcher } from 'svelte'
import lead from '../plugin'
import task, { calcRank } from '@anticrm/task'
export let space: Ref<Space>
@ -57,15 +56,7 @@
{ state: state._id },
{ sort: { rank: SortingOrder.Descending } }
)
const incResult = await client.updateDoc(
task.class.Sequence,
task.space.Sequence,
sequence._id,
{
$inc: { sequence: 1 }
},
true
)
const incResult = await client.update(sequence, { $inc: { sequence: 1 } }, true)
const value: AttachedData<Lead> = {
state: state._id,
@ -84,7 +75,7 @@
await client.createMixin<Contact, Customer>(customerInstance._id, customerInstance._class, customerInstance.space, lead.mixin.Customer, {})
}
await client.addCollection(lead.class.Lead, _space, customer!, lead.mixin.Customer, 'leads', value, leadId)
await client.add(customerInstance, lead.class.Lead, value, leadId)
dispatch('close')
}
</script>

View File

@ -19,12 +19,11 @@
import { getResource, OK, Resource, Severity, Status } from '@anticrm/platform'
import { Card, getClient, UserBox } from '@anticrm/presentation'
import type { Applicant, Candidate } from '@anticrm/recruit'
import { calcRank, SpaceWithStates, State } from '@anticrm/task'
import task from '@anticrm/task'
import task, { calcRank, SpaceWithStates, State } from '@anticrm/task'
import { Grid, Status as StatusControl } from '@anticrm/ui'
import view from '@anticrm/view'
import { createEventDispatcher } from 'svelte'
import recruit from '../plugin'
import view from '@anticrm/view'
export let space: Ref<SpaceWithStates>
export let candidate: Ref<Candidate>
@ -73,15 +72,7 @@
{ state: state._id },
{ sort: { rank: SortingOrder.Descending } }
)
const incResult = await client.updateDoc(
task.class.Sequence,
task.space.Sequence,
sequence._id,
{
$inc: { sequence: 1 }
},
true
)
const incResult = await client.update(sequence, { $inc: { sequence: 1 } }, true)
const candidateInstance = await client.findOne(contact.class.Person, { _id: doc.attachedTo as Ref<Person> })
if (candidateInstance === undefined) {
@ -91,12 +82,8 @@
await client.createMixin<Contact, Candidate>(candidateInstance._id, candidateInstance._class, candidateInstance.space, recruit.mixin.Candidate, {})
}
await client.addCollection(
await client.add(candidateInstance,
recruit.class.Applicant,
doc.space,
doc.attachedTo,
candidateInstance._class,
'applications',
{
state: state._id,
doneState: null,

View File

@ -56,15 +56,7 @@
return
}
await client.updateCollection(
item._class,
item.space,
item._id,
item.attachedTo,
item.attachedToClass,
item.collection,
ops
)
await client.update(item, ops)
}
</script>

View File

@ -52,17 +52,7 @@ async function editStatuses (object: SpaceWithStates): Promise<void> {
}
async function toggleDone (value: boolean, object: TodoItem): Promise<void> {
await getClient().updateCollection(
object._class,
object.space,
object._id,
object.attachedTo,
object.attachedToClass,
object.collection,
{
done: value
}
)
await getClient().update(object, { done: value })
}
async function ArchiveSpace (object: SpaceWithStates): Promise<void> {
@ -78,9 +68,7 @@ async function ArchiveSpace (object: SpaceWithStates): Promise<void> {
const client = getClient()
// eslint-disable-next-line @typescript-eslint/no-floating-promises
client.updateDoc(object._class, object.space, object._id, {
archived: true
})
client.update(object, { archived: true })
}
}
)
@ -99,9 +87,7 @@ async function UnarchiveSpace (object: SpaceWithStates): Promise<void> {
const client = getClient()
// eslint-disable-next-line @typescript-eslint/no-floating-promises
client.updateDoc(object._class, object.space, object._id, {
archived: false
})
client.update(object, { archived: false })
}
}
)

View File

@ -175,7 +175,7 @@ export async function getActions (client: Client, doc: Doc, derived: Ref<Class<D
return await client.findAll(view.class.Action, { _id: { $in: filterActions(client, doc, targets, derived) } })
}
export async function deleteObject (client: Client & TxOperations, object: Doc): Promise<void> {
export async function deleteObject (client: TxOperations, object: Doc): Promise<void> {
const hierarchy = client.getHierarchy()
const attributes = hierarchy.getAllAttributes(object._class)
for (const [name, attribute] of attributes) {