容了create时不传data的错
This commit is contained in:
parent
060c208804
commit
8256c35baa
|
|
@ -228,7 +228,7 @@ function makeIntrinsicCTWs(schema, actionDefDict) {
|
|||
return Promise.all(checkResult).then(function () { return undefined; });
|
||||
}
|
||||
}
|
||||
else {
|
||||
else if (data) {
|
||||
return checkUnique(entity, data, context, uniqAttrs_2);
|
||||
}
|
||||
}
|
||||
|
|
@ -240,84 +240,86 @@ function makeIntrinsicCTWs(schema, actionDefDict) {
|
|||
checker: function (operation, context) {
|
||||
var e_4, _a, e_5, _b, _c;
|
||||
var _d = operation, data = _d.data, operationFilter = _d.filter;
|
||||
var attrs = Object.keys(data);
|
||||
var refAttrs = (0, lodash_1.intersection)(attrs, uniqAttrs_2);
|
||||
if (refAttrs.length === 0) {
|
||||
// 如果本次更新和unique约束的属性之间没有交集则直接返回
|
||||
return;
|
||||
}
|
||||
try {
|
||||
for (var refAttrs_1 = (e_4 = void 0, tslib_1.__values(refAttrs)), refAttrs_1_1 = refAttrs_1.next(); !refAttrs_1_1.done; refAttrs_1_1 = refAttrs_1.next()) {
|
||||
var attr = refAttrs_1_1.value;
|
||||
// 如果有更新为null值,不用再检查约束
|
||||
if (data[attr] === null || data[attr] === undefined) {
|
||||
return;
|
||||
if (data) {
|
||||
var attrs = Object.keys(data);
|
||||
var refAttrs = (0, lodash_1.intersection)(attrs, uniqAttrs_2);
|
||||
if (refAttrs.length === 0) {
|
||||
// 如果本次更新和unique约束的属性之间没有交集则直接返回
|
||||
return;
|
||||
}
|
||||
try {
|
||||
for (var refAttrs_1 = (e_4 = void 0, tslib_1.__values(refAttrs)), refAttrs_1_1 = refAttrs_1.next(); !refAttrs_1_1.done; refAttrs_1_1 = refAttrs_1.next()) {
|
||||
var attr = refAttrs_1_1.value;
|
||||
// 如果有更新为null值,不用再检查约束
|
||||
if (data[attr] === null || data[attr] === undefined) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (refAttrs_1_1 && !refAttrs_1_1.done && (_a = refAttrs_1.return)) _a.call(refAttrs_1);
|
||||
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (refAttrs_1_1 && !refAttrs_1_1.done && (_a = refAttrs_1.return)) _a.call(refAttrs_1);
|
||||
}
|
||||
finally { if (e_4) throw e_4.error; }
|
||||
}
|
||||
finally { if (e_4) throw e_4.error; }
|
||||
}
|
||||
if (refAttrs.length === uniqAttrs_2.length) {
|
||||
// 如果更新了全部属性,直接检查
|
||||
var filter = (0, lodash_1.pick)(data, refAttrs);
|
||||
// 在这些行以外的行不和更新后的键值冲突
|
||||
var count = context.count(entity, {
|
||||
filter: (0, filter_1.combineFilters)(entity, context.getSchema(), [filter, {
|
||||
$not: operationFilter,
|
||||
}]),
|
||||
}, { dontCollect: true });
|
||||
var checkCount = checkCountLessThan(count, uniqAttrs_2, 0, operationFilter === null || operationFilter === void 0 ? void 0 : operationFilter.id);
|
||||
// 更新的行只能有一行
|
||||
var rowCount = context.count(entity, {
|
||||
if (refAttrs.length === uniqAttrs_2.length) {
|
||||
// 如果更新了全部属性,直接检查
|
||||
var filter = (0, lodash_1.pick)(data, refAttrs);
|
||||
// 在这些行以外的行不和更新后的键值冲突
|
||||
var count = context.count(entity, {
|
||||
filter: (0, filter_1.combineFilters)(entity, context.getSchema(), [filter, {
|
||||
$not: operationFilter,
|
||||
}]),
|
||||
}, { dontCollect: true });
|
||||
var checkCount = checkCountLessThan(count, uniqAttrs_2, 0, operationFilter === null || operationFilter === void 0 ? void 0 : operationFilter.id);
|
||||
// 更新的行只能有一行
|
||||
var rowCount = context.count(entity, {
|
||||
filter: operationFilter,
|
||||
}, { dontCollect: true });
|
||||
var checkRowCount = checkCountLessThan(rowCount, uniqAttrs_2, 1, operationFilter === null || operationFilter === void 0 ? void 0 : operationFilter.id);
|
||||
// 如果更新的行数为零似乎也可以,但这应该不可能出现吧,by Xc 20230131
|
||||
if (checkRowCount instanceof Promise) {
|
||||
return Promise.all([checkCount, checkRowCount]).then(function () { return undefined; });
|
||||
}
|
||||
}
|
||||
// 否则需要结合本行现有的属性来进行检查
|
||||
var projection = { id: 1 };
|
||||
try {
|
||||
for (var uniqAttrs_3 = (e_5 = void 0, tslib_1.__values(uniqAttrs_2)), uniqAttrs_3_1 = uniqAttrs_3.next(); !uniqAttrs_3_1.done; uniqAttrs_3_1 = uniqAttrs_3.next()) {
|
||||
var attr = uniqAttrs_3_1.value;
|
||||
Object.assign(projection, (_c = {},
|
||||
_c[attr] = 1,
|
||||
_c));
|
||||
}
|
||||
}
|
||||
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (uniqAttrs_3_1 && !uniqAttrs_3_1.done && (_b = uniqAttrs_3.return)) _b.call(uniqAttrs_3);
|
||||
}
|
||||
finally { if (e_5) throw e_5.error; }
|
||||
}
|
||||
var checkWithRows_1 = function (rows2) {
|
||||
var rows22 = rows2.map(function (ele) { return Object.assign(ele, data); });
|
||||
// 先检查这些行本身之间是否冲突
|
||||
checkUniqueBetweenRows(rows22, uniqAttrs_2);
|
||||
var checkResults = rows22.map(function (row) { return checkUnique(entity, row, context, uniqAttrs_2, {
|
||||
$not: operationFilter
|
||||
}); });
|
||||
if (checkResults[0] instanceof Promise) {
|
||||
return Promise.all(checkResults).then(function () { return undefined; });
|
||||
}
|
||||
};
|
||||
var currentRows = context.select(entity, {
|
||||
data: projection,
|
||||
filter: operationFilter,
|
||||
}, { dontCollect: true });
|
||||
var checkRowCount = checkCountLessThan(rowCount, uniqAttrs_2, 1, operationFilter === null || operationFilter === void 0 ? void 0 : operationFilter.id);
|
||||
// 如果更新的行数为零似乎也可以,但这应该不可能出现吧,by Xc 20230131
|
||||
if (checkRowCount instanceof Promise) {
|
||||
return Promise.all([checkCount, checkRowCount]).then(function () { return undefined; });
|
||||
if (currentRows instanceof Promise) {
|
||||
return currentRows.then(function (row2) { return checkWithRows_1(row2); });
|
||||
}
|
||||
return checkWithRows_1(currentRows);
|
||||
}
|
||||
// 否则需要结合本行现有的属性来进行检查
|
||||
var projection = { id: 1 };
|
||||
try {
|
||||
for (var uniqAttrs_3 = (e_5 = void 0, tslib_1.__values(uniqAttrs_2)), uniqAttrs_3_1 = uniqAttrs_3.next(); !uniqAttrs_3_1.done; uniqAttrs_3_1 = uniqAttrs_3.next()) {
|
||||
var attr = uniqAttrs_3_1.value;
|
||||
Object.assign(projection, (_c = {},
|
||||
_c[attr] = 1,
|
||||
_c));
|
||||
}
|
||||
}
|
||||
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (uniqAttrs_3_1 && !uniqAttrs_3_1.done && (_b = uniqAttrs_3.return)) _b.call(uniqAttrs_3);
|
||||
}
|
||||
finally { if (e_5) throw e_5.error; }
|
||||
}
|
||||
var checkWithRows = function (rows2) {
|
||||
var rows22 = rows2.map(function (ele) { return Object.assign(ele, data); });
|
||||
// 先检查这些行本身之间是否冲突
|
||||
checkUniqueBetweenRows(rows22, uniqAttrs_2);
|
||||
var checkResults = rows22.map(function (row) { return checkUnique(entity, row, context, uniqAttrs_2, {
|
||||
$not: operationFilter
|
||||
}); });
|
||||
if (checkResults[0] instanceof Promise) {
|
||||
return Promise.all(checkResults).then(function () { return undefined; });
|
||||
}
|
||||
};
|
||||
var currentRows = context.select(entity, {
|
||||
data: projection,
|
||||
filter: operationFilter,
|
||||
}, { dontCollect: true });
|
||||
if (currentRows instanceof Promise) {
|
||||
return currentRows.then(function (row2) { return checkWithRows(row2); });
|
||||
}
|
||||
return checkWithRows(currentRows);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { EntityDict } from "./Entity";
|
||||
import { EntityDict, SubDataDef } from "./Entity";
|
||||
import { OpRecord } from "./Entity";
|
||||
import { AsyncContext } from "../store/AsyncRowStore";
|
||||
export interface Aspect<ED extends EntityDict, Cxt extends AsyncContext<ED>> {
|
||||
|
|
@ -10,4 +10,6 @@ export interface AspectWrapper<ED extends EntityDict, Cxt extends AsyncContext<E
|
|||
opRecords?: OpRecord<ED>[];
|
||||
message?: string | null;
|
||||
}>;
|
||||
sub: (data: Array<SubDataDef<ED, keyof ED>>, callback: (records: OpRecord<ED>[], ids: string[]) => void) => Promise<void>;
|
||||
unsub: (ids: string[]) => Promise<void>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ export function makeIntrinsicCTWs<ED extends EntityDict & BaseEntityDict, Cxt ex
|
|||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
else if (data) {
|
||||
return checkUnique<ED, Cxt | FrontCxt>(entity, data, context, uniqAttrs);
|
||||
}
|
||||
}
|
||||
|
|
@ -231,80 +231,82 @@ export function makeIntrinsicCTWs<ED extends EntityDict & BaseEntityDict, Cxt ex
|
|||
priority: CHECKER_MAX_PRIORITY, // 优先级要放在最低,所有前置的checker/trigger将数据完整之后再在这里检测
|
||||
checker: (operation, context) => {
|
||||
const { data, filter: operationFilter } = operation as ED[keyof ED]['Update'];
|
||||
const attrs = Object.keys(data);
|
||||
|
||||
const refAttrs = intersection(attrs, uniqAttrs);
|
||||
if (refAttrs.length === 0) {
|
||||
// 如果本次更新和unique约束的属性之间没有交集则直接返回
|
||||
return;
|
||||
}
|
||||
for (const attr of refAttrs) {
|
||||
// 如果有更新为null值,不用再检查约束
|
||||
if (data[attr as string] === null || data[attr as string] === undefined) {
|
||||
if (data) {
|
||||
const attrs = Object.keys(data);
|
||||
|
||||
const refAttrs = intersection(attrs, uniqAttrs);
|
||||
if (refAttrs.length === 0) {
|
||||
// 如果本次更新和unique约束的属性之间没有交集则直接返回
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (refAttrs.length === uniqAttrs.length) {
|
||||
// 如果更新了全部属性,直接检查
|
||||
const filter = pick(data, refAttrs);
|
||||
|
||||
// 在这些行以外的行不和更新后的键值冲突
|
||||
const count = context.count(entity, {
|
||||
filter: combineFilters(entity, context.getSchema(), [filter, {
|
||||
$not: operationFilter,
|
||||
}]),
|
||||
}, { dontCollect: true });
|
||||
const checkCount = checkCountLessThan(count, uniqAttrs, 0, operationFilter?.id);
|
||||
|
||||
// 更新的行只能有一行
|
||||
const rowCount = context.count(entity, {
|
||||
for (const attr of refAttrs) {
|
||||
// 如果有更新为null值,不用再检查约束
|
||||
if (data[attr as string] === null || data[attr as string] === undefined) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (refAttrs.length === uniqAttrs.length) {
|
||||
// 如果更新了全部属性,直接检查
|
||||
const filter = pick(data, refAttrs);
|
||||
|
||||
// 在这些行以外的行不和更新后的键值冲突
|
||||
const count = context.count(entity, {
|
||||
filter: combineFilters(entity, context.getSchema(), [filter, {
|
||||
$not: operationFilter,
|
||||
}]),
|
||||
}, { dontCollect: true });
|
||||
const checkCount = checkCountLessThan(count, uniqAttrs, 0, operationFilter?.id);
|
||||
|
||||
// 更新的行只能有一行
|
||||
const rowCount = context.count(entity, {
|
||||
filter: operationFilter,
|
||||
}, { dontCollect: true });
|
||||
const checkRowCount = checkCountLessThan(rowCount, uniqAttrs, 1, operationFilter?.id);
|
||||
|
||||
// 如果更新的行数为零似乎也可以,但这应该不可能出现吧,by Xc 20230131
|
||||
if (checkRowCount instanceof Promise) {
|
||||
return Promise.all([checkCount, checkRowCount]).then(
|
||||
() => undefined
|
||||
);
|
||||
}
|
||||
}
|
||||
// 否则需要结合本行现有的属性来进行检查
|
||||
const projection = { id: 1 };
|
||||
for (const attr of uniqAttrs) {
|
||||
Object.assign(projection, {
|
||||
[attr]: 1,
|
||||
});
|
||||
}
|
||||
|
||||
const checkWithRows = (rows2: ED[keyof ED]['Schema'][]) => {
|
||||
const rows22 = rows2.map(
|
||||
ele => Object.assign(ele, data)
|
||||
);
|
||||
// 先检查这些行本身之间是否冲突
|
||||
checkUniqueBetweenRows(rows22, uniqAttrs);
|
||||
const checkResults = rows22.map(
|
||||
(row) => checkUnique<ED, Cxt | FrontCxt>(entity, row, context, uniqAttrs, {
|
||||
$not: operationFilter
|
||||
})
|
||||
);
|
||||
if (checkResults[0] instanceof Promise) {
|
||||
return Promise.all(checkResults).then(
|
||||
() => undefined
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const currentRows = context.select(entity, {
|
||||
data: projection,
|
||||
filter: operationFilter,
|
||||
}, { dontCollect: true });
|
||||
const checkRowCount = checkCountLessThan(rowCount, uniqAttrs, 1, operationFilter?.id);
|
||||
|
||||
// 如果更新的行数为零似乎也可以,但这应该不可能出现吧,by Xc 20230131
|
||||
if (checkRowCount instanceof Promise) {
|
||||
return Promise.all([checkCount, checkRowCount]).then(
|
||||
() => undefined
|
||||
if (currentRows instanceof Promise) {
|
||||
return currentRows.then(
|
||||
(row2) => checkWithRows(row2 as ED[keyof ED]['Schema'][])
|
||||
);
|
||||
}
|
||||
return checkWithRows(currentRows as ED[keyof ED]['Schema'][]);
|
||||
}
|
||||
// 否则需要结合本行现有的属性来进行检查
|
||||
const projection = { id: 1 };
|
||||
for (const attr of uniqAttrs) {
|
||||
Object.assign(projection, {
|
||||
[attr]: 1,
|
||||
});
|
||||
}
|
||||
|
||||
const checkWithRows = (rows2: ED[keyof ED]['Schema'][]) => {
|
||||
const rows22 = rows2.map(
|
||||
ele => Object.assign(ele, data)
|
||||
);
|
||||
// 先检查这些行本身之间是否冲突
|
||||
checkUniqueBetweenRows(rows22, uniqAttrs);
|
||||
const checkResults = rows22.map(
|
||||
(row) => checkUnique<ED, Cxt | FrontCxt>(entity, row, context, uniqAttrs, {
|
||||
$not: operationFilter
|
||||
})
|
||||
);
|
||||
if (checkResults[0] instanceof Promise) {
|
||||
return Promise.all(checkResults).then(
|
||||
() => undefined
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const currentRows = context.select(entity, {
|
||||
data: projection,
|
||||
filter: operationFilter,
|
||||
}, { dontCollect: true });
|
||||
if (currentRows instanceof Promise) {
|
||||
return currentRows.then(
|
||||
(row2) => checkWithRows(row2 as ED[keyof ED]['Schema'][])
|
||||
);
|
||||
}
|
||||
return checkWithRows(currentRows as ED[keyof ED]['Schema'][]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@ export interface AspectWrapper<ED extends EntityDict, Cxt extends AsyncContext<E
|
|||
message?: string | null;
|
||||
}>;
|
||||
|
||||
/* sub: (data: Array<SubDataDef<ED, keyof ED>>) => Promise<void>;
|
||||
sub: (data: Array<SubDataDef<ED, keyof ED>>, callback: (records: OpRecord<ED>[], ids: string[]) => void) => Promise<void>;
|
||||
|
||||
unsub: (ids: string[]) => Promise<void>;
|
||||
|
||||
registerSubCallback: (callback: (records: OpRecord<ED>[]) => void) => Promise<void>; */
|
||||
};
|
||||
Loading…
Reference in New Issue