diff --git a/dev/storage/src/storage.ts b/dev/storage/src/storage.ts index 0c3708807f..3421279af1 100644 --- a/dev/storage/src/storage.ts +++ b/dev/storage/src/storage.ts @@ -23,7 +23,7 @@ import type { FindOptions } from '@anticrm/core' import { getResource } from '@anticrm/platform' -import core, { ModelDb, TxDb, Hierarchy, DOMAIN_TX, DefaultTxFactory } from '@anticrm/core' +import core, { ModelDb, TxDb, Hierarchy, DOMAIN_TX, TxFactory } from '@anticrm/core' import * as txJson from './model.tx.json' @@ -40,14 +40,14 @@ export interface ServerStorage { } class DevStorage implements ServerStorage { - private readonly txFactory: DefaultTxFactory + private readonly txFactory: TxFactory constructor ( private readonly hierarchy: Hierarchy, private readonly txdb: TxDb, private readonly modeldb: ModelDb ) { - this.txFactory = new DefaultTxFactory(core.account.System) + this.txFactory = new TxFactory(core.account.System) } async findAll ( diff --git a/packages/core/src/__tests__/minmodel.ts b/packages/core/src/__tests__/minmodel.ts index c991d66bbc..a9fe2256a6 100644 --- a/packages/core/src/__tests__/minmodel.ts +++ b/packages/core/src/__tests__/minmodel.ts @@ -15,43 +15,19 @@ import type { Account, Class, Data, Doc, Domain, Obj, Ref } from '../classes' import { ClassifierKind, DOMAIN_MODEL } from '../classes' -import type { Tx, TxCreateDoc } from '../tx' +import { Tx, TxCreateDoc, TxFactory } from '../tx' import core from '../component' import { DOMAIN_TX } from '../tx' import { generateId } from '../utils' -export function createClass> (_id: Ref, cl: Omit, 'kind'>, domain?: Domain): Tx { - const result: TxCreateDoc = { - _id: generateId(), - _class: core.class.TxCreateDoc, - objectId: _id, - objectClass: core.class.Class, - attributes: { - kind: ClassifierKind.CLASS, - domain: domain ?? DOMAIN_MODEL, - ...cl - }, - modifiedBy: 'model' as Ref, - modifiedOn: Date.now(), - objectSpace: core.space.Model, - space: core.space.Model - } - return result +const txFactory = new TxFactory(core.account.System) + +function createClass(_class: Ref>, attributes: Data>) { + return txFactory.createTxCreateDoc(core.class.Class, core.space.Model, attributes) } -export function createDoc (_class: Ref>, attributes: Data): Tx { - const tx: TxCreateDoc = { - _id: generateId(), - _class: core.class.TxCreateDoc, - space: core.space.Tx, - modifiedBy: core.account.System, - modifiedOn: Date.now(), - objectId: generateId(), - objectClass: _class, - objectSpace: core.space.Model, - attributes - } - return tx +export function createDoc (_class: Ref>, attributes: Data) { + return txFactory.createTxCreateDoc(_class, core.space.Model, attributes) } /** @@ -61,16 +37,16 @@ export function createDoc (_class: Ref>, attributes: Dat export function genMinModel (): Tx[] { const txes = [] // Fill Tx'es with basic model classes. - txes.push(createClass(core.class.Obj, {})) - txes.push(createClass(core.class.Doc, { extends: core.class.Obj })) - txes.push(createClass(core.class.Class, { extends: core.class.Doc })) - txes.push(createClass(core.class.Space, { extends: core.class.Doc })) - txes.push(createClass(core.class.Account, { extends: core.class.Doc })) + txes.push(createClass(core.class.Obj, { kind: ClassifierKind.CLASS })) + txes.push(createClass(core.class.Doc, { extends: core.class.Obj, kind: ClassifierKind.CLASS })) + txes.push(createClass(core.class.Class, { extends: core.class.Doc, kind: ClassifierKind.CLASS, domain: DOMAIN_MODEL })) + txes.push(createClass(core.class.Space, { extends: core.class.Doc, kind: ClassifierKind.CLASS, domain: DOMAIN_MODEL })) + txes.push(createClass(core.class.Account, { extends: core.class.Doc, kind: ClassifierKind.CLASS, domain: DOMAIN_MODEL })) - txes.push(createClass(core.class.Tx, { extends: core.class.Doc }, DOMAIN_TX)) - txes.push(createClass(core.class.TxCreateDoc, { extends: core.class.Tx }, DOMAIN_TX)) - txes.push(createClass(core.class.TxUpdateDoc, { extends: core.class.Tx }, DOMAIN_TX)) - txes.push(createClass(core.class.TxRemoveDoc, { extends: core.class.Tx }, DOMAIN_TX)) + txes.push(createClass(core.class.Tx, { extends: core.class.Doc, kind: ClassifierKind.CLASS, domain: DOMAIN_TX })) + txes.push(createClass(core.class.TxCreateDoc, { extends: core.class.Tx, kind: ClassifierKind.CLASS })) + txes.push(createClass(core.class.TxUpdateDoc, { extends: core.class.Tx, kind: ClassifierKind.CLASS })) + txes.push(createClass(core.class.TxRemoveDoc, { extends: core.class.Tx, kind: ClassifierKind.CLASS })) txes.push( createDoc(core.class.Space, {