createModi容错,当更新了完全不存在的行时报warning

This commit is contained in:
Xu Chang 2024-12-31 11:20:52 +08:00
parent fe95729915
commit 39c7cef89f
5 changed files with 111 additions and 77 deletions

View File

@ -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') {

8
lib/utils/row.d.ts vendored
View File

@ -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 truefalse
*/
export declare function compareRow<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(schema: StorageSchema<ED>, entity: T, row1: Partial<ED[T]['Schema']>, row2: Partial<ED[T]['Schema']>): boolean;
/**
*

View File

@ -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('$$'));

View File

@ -1317,7 +1317,7 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
context: Cxt,
ids: string[],
option: OP
): Promise<ED['modi']['Operation']> {
): Promise<ED['modi']['Operation'] | undefined> {
const { action, data, filter, id: operId } = operation;
const [ upsertModi ] = await this.selectAbjointRowAsync('modi', {
data: {
@ -1399,40 +1399,41 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> 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<ED extends EntityDict & BaseEntityDict> 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<ED>;
if (modiOperation) {
const closeRootMode = context.openRootMode();
await this.cascadeUpdateAsync('modi', modiOperation!, context, option);
closeRootMode();
return {
modi: {
['create' as ED['modi']['Action']]: 1,
},
} as OperationResult<ED>;
}
console.warn(`destination includes modies can not be found here: [${entity as string}], [${JSON.stringify(operation)}]`);
return {} as OperationResult<ED>;
};
const saveRecordAndCreateOper = async () => {

View File

@ -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 truefalse
*/
export function compareRow<ED extends EntityDict & BaseEntityDict, T extends keyof ED> (
schema: StorageSchema<ED>,
entity: T,