From 8d7406cbbb91c20815622445b2f67ce6d7fa4d6d Mon Sep 17 00:00:00 2001 From: Vyacheslav Tumanov Date: Wed, 29 May 2024 20:30:36 +0500 Subject: [PATCH] throw error in case of non-model space for classes in model (#5694) Signed-off-by: Vyacheslav Tumanov --- packages/core/src/operations.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/core/src/operations.ts b/packages/core/src/operations.ts index 684ba74660..ff8e7406f5 100644 --- a/packages/core/src/operations.ts +++ b/packages/core/src/operations.ts @@ -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 { 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