throw error in case of non-model space for classes in model (#5694)

Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
Vyacheslav Tumanov 2024-05-29 20:30:36 +05:00 committed by GitHub
parent 9903d9e7a7
commit 8d7406cbbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,5 @@
import { deepEqual } from 'fast-equals'
import { DocumentUpdate, Hierarchy, MixinData, MixinUpdate, ModelDb, toFindResult } from '.'
import { DocumentUpdate, DOMAIN_MODEL, Hierarchy, MixinData, MixinUpdate, ModelDb, toFindResult } from '.'
import type {
Account,
AnyAttribute,
@ -93,6 +93,9 @@ export class TxOperations implements Omit<Client, 'notify'> {
if (hierarchy.isDerived(_class, core.class.AttachedDoc)) {
throw new Error('createDoc cannot be used for objects inherited from AttachedDoc')
}
if (hierarchy.findDomain(_class) === DOMAIN_MODEL && space !== core.space.Model) {
throw new Error('createDoc cannot be called for DOMAIN_MODEL classes with non-model space')
}
const tx = this.txFactory.createTxCreateDoc(_class, space, attributes, id, modifiedOn, modifiedBy)
await this.client.tx(tx)
return tx.objectId