refactor minmodel

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-08-05 10:07:43 +02:00
parent bc5f551fc5
commit 7ec29dffb8
No known key found for this signature in database
GPG Key ID: C8787EFEB4B64AF0
2 changed files with 19 additions and 43 deletions

View File

@ -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<T extends Doc> (

View File

@ -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<T extends Class<Obj>> (_id: Ref<T>, cl: Omit<Data<T>, 'kind'>, domain?: Domain): Tx {
const result: TxCreateDoc<Doc> = {
_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<Account>,
modifiedOn: Date.now(),
objectSpace: core.space.Model,
space: core.space.Model
}
return result
const txFactory = new TxFactory(core.account.System)
function createClass(_class: Ref<Class<Obj>>, attributes: Data<Class<Obj>>) {
return txFactory.createTxCreateDoc(core.class.Class, core.space.Model, attributes)
}
export function createDoc<T extends Doc> (_class: Ref<Class<T>>, attributes: Data<T>): Tx {
const tx: TxCreateDoc<T> = {
_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<T extends Doc> (_class: Ref<Class<T>>, attributes: Data<T>) {
return txFactory.createTxCreateDoc(_class, core.space.Model, attributes)
}
/**
@ -61,16 +37,16 @@ export function createDoc<T extends Doc> (_class: Ref<Class<T>>, 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, {