diff --git a/lib/store/CascadeStore.js b/lib/store/CascadeStore.js index 23eaea7..a9eb420 100644 --- a/lib/store/CascadeStore.js +++ b/lib/store/CascadeStore.js @@ -1132,36 +1132,37 @@ class CascadeStore extends RowStore_1.RowStore { } // 说明没有已有的modi,必须要创建新的,此时应当在option中有相应的parentEntity/Id const { modiParentEntity, modiParentId } = option; - (0, assert_1.default)(modiParentEntity && modiParentId); - return { - id: 'dummy', - action: 'create', - data: { - id: operId, - targetEntity: entity, - entity: modiParentEntity, - entityId: modiParentId, - action, - data, - iState: 'active', - filter: ids.length > 0 ? { - id: { - $in: ids, + if (modiParentEntity && modiParentId) { + return { + id: 'dummy', + action: 'create', + data: { + id: operId, + targetEntity: entity, + entity: modiParentEntity, + entityId: modiParentId, + action, + data, + iState: 'active', + filter: ids.length > 0 ? { + id: { + $in: ids, + }, + } : { + id: ids[0], }, - } : { - id: ids[0], + modiEntity$modi: { + id: 'dummy', + action: 'create', + data: await Promise.all(ids.map(async (id) => ({ + id: await (0, uuid_1.generateNewIdAsync)(), + entity: entity, + entityId: id, + }))), + } }, - modiEntity$modi: { - id: 'dummy', - action: 'create', - data: await Promise.all(ids.map(async (id) => ({ - id: await (0, uuid_1.generateNewIdAsync)(), - entity: entity, - entityId: id, - }))), - } - }, - }; + }; + } } /** * 和具体的update过程无关的例程放在这里,包括对later动作的处理、对oper的记录以及对record的收集等 @@ -1396,14 +1397,18 @@ class CascadeStore extends RowStore_1.RowStore { } const createModi = async () => { const modiOperation = await this.tryMergeModi(entity, operation, context, ids, option); - const closeRootMode = context.openRootMode(); - await this.cascadeUpdateAsync('modi', modiOperation, context, option); - closeRootMode(); - return { - modi: { - ['create']: 1, - }, - }; + if (modiOperation) { + const closeRootMode = context.openRootMode(); + await this.cascadeUpdateAsync('modi', modiOperation, context, option); + closeRootMode(); + return { + modi: { + ['create']: 1, + }, + }; + } + console.warn(`destination includes modies can not be found here: [${entity}], [${JSON.stringify(operation)}]`); + return {}; }; const saveRecordAndCreateOper = async () => { if (action === 'remove') { diff --git a/lib/utils/row.d.ts b/lib/utils/row.d.ts index 5a23042..f018d62 100644 --- a/lib/utils/row.d.ts +++ b/lib/utils/row.d.ts @@ -1,6 +1,14 @@ import { EntityDict } from '../types/Entity'; import { EntityDict as BaseEntityDict } from '../base-app-domain'; import { StorageSchema } from '../types'; +/** + * 比较两行是否完全相等 + * @param schema + * @param entity + * @param row1 + * @param row2 + * @returns 相等返回true,否则返回false + */ export declare function compareRow(schema: StorageSchema, entity: T, row1: Partial, row2: Partial): boolean; /** * 比较两行数据是否完全相等 diff --git a/lib/utils/row.js b/lib/utils/row.js index 75f12e6..4cab2db 100644 --- a/lib/utils/row.js +++ b/lib/utils/row.js @@ -5,6 +5,14 @@ const tslib_1 = require("tslib"); const lodash_1 = require("./lodash"); const relation_1 = require("../store/relation"); const assert_1 = tslib_1.__importDefault(require("assert")); +/** + * 比较两行是否完全相等 + * @param schema + * @param entity + * @param row1 + * @param row2 + * @returns 相等返回true,否则返回false + */ function compareRow(schema, entity, row1, row2) { const attrs1 = Object.keys(row1 || {}).filter(ele => !ele.startsWith('$$')); const attrs2 = Object.keys(row2 || {}).filter(ele => !ele.startsWith('$$')); diff --git a/src/store/CascadeStore.ts b/src/store/CascadeStore.ts index 02a1df9..bf47a2d 100644 --- a/src/store/CascadeStore.ts +++ b/src/store/CascadeStore.ts @@ -1317,7 +1317,7 @@ export abstract class CascadeStore exten context: Cxt, ids: string[], option: OP - ): Promise { + ): Promise { const { action, data, filter, id: operId } = operation; const [ upsertModi ] = await this.selectAbjointRowAsync('modi', { data: { @@ -1399,40 +1399,41 @@ export abstract class CascadeStore exten // 说明没有已有的modi,必须要创建新的,此时应当在option中有相应的parentEntity/Id const { modiParentEntity, modiParentId } = option; - assert(modiParentEntity && modiParentId); - return { - id: 'dummy', - action: 'create', - data: { - id: operId, - targetEntity: entity as string, - entity: modiParentEntity, - entityId: modiParentId, - action, - data, - iState: 'active', - filter: ids.length > 0 ? { - id: { - $in: ids, + if (modiParentEntity && modiParentId) { + return { + id: 'dummy', + action: 'create', + data: { + id: operId, + targetEntity: entity as string, + entity: modiParentEntity, + entityId: modiParentId, + action, + data, + iState: 'active', + filter: ids.length > 0 ? { + id: { + $in: ids, + }, + } : { + id: ids[0], }, - } : { - id: ids[0], + modiEntity$modi: { + id: 'dummy', + action: 'create', + data: await Promise.all( + ids.map( + async (id) => ({ + id: await generateNewIdAsync(), + entity: entity as string, + entityId: id, + }) + ) + ), + } }, - modiEntity$modi: { - id: 'dummy', - action: 'create', - data: await Promise.all( - ids.map( - async (id) => ({ - id: await generateNewIdAsync(), - entity: entity as string, - entityId: id, - }) - ) - ), - } - }, - }; + }; + } } /** @@ -1689,14 +1690,18 @@ export abstract class CascadeStore exten const createModi = async () => { const modiOperation = await this.tryMergeModi(entity, operation as ED[T]['Update'], context, ids, option); - const closeRootMode = context.openRootMode(); - await this.cascadeUpdateAsync('modi', modiOperation!, context, option); - closeRootMode(); - return { - modi: { - ['create' as ED['modi']['Action']]: 1, - }, - } as OperationResult; + if (modiOperation) { + const closeRootMode = context.openRootMode(); + await this.cascadeUpdateAsync('modi', modiOperation!, context, option); + closeRootMode(); + return { + modi: { + ['create' as ED['modi']['Action']]: 1, + }, + } as OperationResult; + } + console.warn(`destination includes modies can not be found here: [${entity as string}], [${JSON.stringify(operation)}]`); + return {} as OperationResult; }; const saveRecordAndCreateOper = async () => { diff --git a/src/utils/row.ts b/src/utils/row.ts index b8295d4..5530fa8 100644 --- a/src/utils/row.ts +++ b/src/utils/row.ts @@ -5,6 +5,14 @@ import { difference } from './lodash'; import { judgeRelation } from '../store/relation'; import assert from 'assert'; +/** + * 比较两行是否完全相等 + * @param schema + * @param entity + * @param row1 + * @param row2 + * @returns 相等返回true,否则返回false + */ export function compareRow ( schema: StorageSchema, entity: T,