mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 03:22:19 +03:00
refactor minmodel
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
bc5f551fc5
commit
7ec29dffb8
@ -23,7 +23,7 @@ import type {
|
|||||||
FindOptions
|
FindOptions
|
||||||
} from '@anticrm/core'
|
} from '@anticrm/core'
|
||||||
import { getResource } from '@anticrm/platform'
|
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'
|
import * as txJson from './model.tx.json'
|
||||||
|
|
||||||
@ -40,14 +40,14 @@ export interface ServerStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class DevStorage implements ServerStorage {
|
class DevStorage implements ServerStorage {
|
||||||
private readonly txFactory: DefaultTxFactory
|
private readonly txFactory: TxFactory
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
private readonly hierarchy: Hierarchy,
|
private readonly hierarchy: Hierarchy,
|
||||||
private readonly txdb: TxDb,
|
private readonly txdb: TxDb,
|
||||||
private readonly modeldb: ModelDb
|
private readonly modeldb: ModelDb
|
||||||
) {
|
) {
|
||||||
this.txFactory = new DefaultTxFactory(core.account.System)
|
this.txFactory = new TxFactory(core.account.System)
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll<T extends Doc> (
|
async findAll<T extends Doc> (
|
||||||
|
@ -15,43 +15,19 @@
|
|||||||
|
|
||||||
import type { Account, Class, Data, Doc, Domain, Obj, Ref } from '../classes'
|
import type { Account, Class, Data, Doc, Domain, Obj, Ref } from '../classes'
|
||||||
import { ClassifierKind, DOMAIN_MODEL } 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 core from '../component'
|
||||||
import { DOMAIN_TX } from '../tx'
|
import { DOMAIN_TX } from '../tx'
|
||||||
import { generateId } from '../utils'
|
import { generateId } from '../utils'
|
||||||
|
|
||||||
export function createClass<T extends Class<Obj>> (_id: Ref<T>, cl: Omit<Data<T>, 'kind'>, domain?: Domain): Tx {
|
const txFactory = new TxFactory(core.account.System)
|
||||||
const result: TxCreateDoc<Doc> = {
|
|
||||||
_id: generateId(),
|
function createClass(_class: Ref<Class<Obj>>, attributes: Data<Class<Obj>>) {
|
||||||
_class: core.class.TxCreateDoc,
|
return txFactory.createTxCreateDoc(core.class.Class, core.space.Model, attributes)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createDoc<T extends Doc> (_class: Ref<Class<T>>, attributes: Data<T>): Tx {
|
export function createDoc<T extends Doc> (_class: Ref<Class<T>>, attributes: Data<T>) {
|
||||||
const tx: TxCreateDoc<T> = {
|
return txFactory.createTxCreateDoc(_class, core.space.Model, attributes)
|
||||||
_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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,16 +37,16 @@ export function createDoc<T extends Doc> (_class: Ref<Class<T>>, attributes: Dat
|
|||||||
export function genMinModel (): Tx[] {
|
export function genMinModel (): Tx[] {
|
||||||
const txes = []
|
const txes = []
|
||||||
// Fill Tx'es with basic model classes.
|
// Fill Tx'es with basic model classes.
|
||||||
txes.push(createClass(core.class.Obj, {}))
|
txes.push(createClass(core.class.Obj, { kind: ClassifierKind.CLASS }))
|
||||||
txes.push(createClass(core.class.Doc, { extends: core.class.Obj }))
|
txes.push(createClass(core.class.Doc, { extends: core.class.Obj, kind: ClassifierKind.CLASS }))
|
||||||
txes.push(createClass(core.class.Class, { extends: core.class.Doc }))
|
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 }))
|
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 }))
|
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.Tx, { extends: core.class.Doc, kind: ClassifierKind.CLASS, domain: DOMAIN_TX }))
|
||||||
txes.push(createClass(core.class.TxCreateDoc, { extends: core.class.Tx }, 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 }, DOMAIN_TX))
|
txes.push(createClass(core.class.TxUpdateDoc, { extends: core.class.Tx, kind: ClassifierKind.CLASS }))
|
||||||
txes.push(createClass(core.class.TxRemoveDoc, { extends: core.class.Tx }, DOMAIN_TX))
|
txes.push(createClass(core.class.TxRemoveDoc, { extends: core.class.Tx, kind: ClassifierKind.CLASS }))
|
||||||
|
|
||||||
txes.push(
|
txes.push(
|
||||||
createDoc(core.class.Space, {
|
createDoc(core.class.Space, {
|
||||||
|
Loading…
Reference in New Issue
Block a user