Merge branch 'release'
This commit is contained in:
commit
318e0ec5b6
|
|
@ -50,35 +50,49 @@ function makeIntrinsicWatchers(schema) {
|
||||||
return watchers;
|
return watchers;
|
||||||
}
|
}
|
||||||
function checkUniqueBetweenRows(rows, uniqAttrs) {
|
function checkUniqueBetweenRows(rows, uniqAttrs) {
|
||||||
|
var e_1, _a, e_2, _b;
|
||||||
// 先检查这些行本身之间有无unique冲突
|
// 先检查这些行本身之间有无unique冲突
|
||||||
var uniqRows = (0, lodash_1.uniqBy)(rows, function (d) {
|
var dict = {};
|
||||||
var e_1, _a;
|
try {
|
||||||
|
for (var rows_1 = tslib_1.__values(rows), rows_1_1 = rows_1.next(); !rows_1_1.done; rows_1_1 = rows_1.next()) {
|
||||||
|
var row = rows_1_1.value;
|
||||||
var s = '';
|
var s = '';
|
||||||
try {
|
try {
|
||||||
for (var uniqAttrs_1 = tslib_1.__values(uniqAttrs), uniqAttrs_1_1 = uniqAttrs_1.next(); !uniqAttrs_1_1.done; uniqAttrs_1_1 = uniqAttrs_1.next()) {
|
for (var uniqAttrs_1 = (e_2 = void 0, tslib_1.__values(uniqAttrs)), uniqAttrs_1_1 = uniqAttrs_1.next(); !uniqAttrs_1_1.done; uniqAttrs_1_1 = uniqAttrs_1.next()) {
|
||||||
var a = uniqAttrs_1_1.value;
|
var a = uniqAttrs_1_1.value;
|
||||||
if (d[a] === null || d[a] === undefined) {
|
if (row[a] === null || row[a] === undefined) {
|
||||||
s + d.id;
|
s + row.id;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
s + "-".concat(d[a]);
|
s + "-".concat(row[a]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (uniqAttrs_1_1 && !uniqAttrs_1_1.done && (_b = uniqAttrs_1.return)) _b.call(uniqAttrs_1);
|
||||||
|
}
|
||||||
|
finally { if (e_2) throw e_2.error; }
|
||||||
|
}
|
||||||
|
if (dict[s]) {
|
||||||
|
throw new types_1.OakUniqueViolationException([{
|
||||||
|
id: row.id,
|
||||||
|
attrs: uniqAttrs,
|
||||||
|
}]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dict[s] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
||||||
finally {
|
finally {
|
||||||
try {
|
try {
|
||||||
if (uniqAttrs_1_1 && !uniqAttrs_1_1.done && (_a = uniqAttrs_1.return)) _a.call(uniqAttrs_1);
|
if (rows_1_1 && !rows_1_1.done && (_a = rows_1.return)) _a.call(rows_1);
|
||||||
}
|
}
|
||||||
finally { if (e_1) throw e_1.error; }
|
finally { if (e_1) throw e_1.error; }
|
||||||
}
|
}
|
||||||
return s;
|
|
||||||
});
|
|
||||||
if (uniqRows.length < rows.length) {
|
|
||||||
throw new types_1.OakUniqueViolationException([{
|
|
||||||
attrs: uniqAttrs,
|
|
||||||
}]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
function checkCountLessThan(count, uniqAttrs, than, id) {
|
function checkCountLessThan(count, uniqAttrs, than, id) {
|
||||||
if (than === void 0) { than = 0; }
|
if (than === void 0) { than = 0; }
|
||||||
|
|
@ -110,7 +124,7 @@ function checkUnique(entity, row, context, uniqAttrs, extraFilter) {
|
||||||
// 说明有null值,不需要检查约束
|
// 说明有null值,不需要检查约束
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var filter2 = extraFilter ? (0, filter_1.addFilterSegment)([filter, extraFilter]) : filter;
|
var filter2 = extraFilter ? (0, filter_1.addFilterSegment)(filter, extraFilter) : filter;
|
||||||
var count = context.count(entity, { filter: filter2 }, { dontCollect: true });
|
var count = context.count(entity, { filter: filter2 }, { dontCollect: true });
|
||||||
return checkCountLessThan(count, uniqAttrs, 0, row.id);
|
return checkCountLessThan(count, uniqAttrs, 0, row.id);
|
||||||
}
|
}
|
||||||
|
|
@ -190,7 +204,7 @@ function analyzeActionDefDict(schema, actionDefDict) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var _loop_2 = function (entity) {
|
var _loop_2 = function (entity) {
|
||||||
var e_2, _e;
|
var e_3, _e;
|
||||||
var indexes = schema[entity].indexes;
|
var indexes = schema[entity].indexes;
|
||||||
if (indexes) {
|
if (indexes) {
|
||||||
var _loop_4 = function (index) {
|
var _loop_4 = function (index) {
|
||||||
|
|
@ -221,7 +235,7 @@ function analyzeActionDefDict(schema, actionDefDict) {
|
||||||
type: 'logical',
|
type: 'logical',
|
||||||
priority: 20,
|
priority: 20,
|
||||||
checker: function (operation, context) {
|
checker: function (operation, context) {
|
||||||
var e_3, _a, e_4, _b, _c;
|
var e_4, _a, e_5, _b, _c;
|
||||||
var _d = operation, data = _d.data, operationFilter = _d.filter;
|
var _d = operation, data = _d.data, operationFilter = _d.filter;
|
||||||
var attrs = Object.keys(data);
|
var attrs = Object.keys(data);
|
||||||
var refAttrs = (0, lodash_1.intersection)(attrs, uniqAttrs_2);
|
var refAttrs = (0, lodash_1.intersection)(attrs, uniqAttrs_2);
|
||||||
|
|
@ -230,7 +244,7 @@ function analyzeActionDefDict(schema, actionDefDict) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
for (var refAttrs_1 = (e_3 = void 0, tslib_1.__values(refAttrs)), refAttrs_1_1 = refAttrs_1.next(); !refAttrs_1_1.done; refAttrs_1_1 = refAttrs_1.next()) {
|
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;
|
var attr = refAttrs_1_1.value;
|
||||||
// 如果有更新为null值,不用再检查约束
|
// 如果有更新为null值,不用再检查约束
|
||||||
if (data[attr] === null || data[attr] === undefined) {
|
if (data[attr] === null || data[attr] === undefined) {
|
||||||
|
|
@ -238,12 +252,12 @@ function analyzeActionDefDict(schema, actionDefDict) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
||||||
finally {
|
finally {
|
||||||
try {
|
try {
|
||||||
if (refAttrs_1_1 && !refAttrs_1_1.done && (_a = refAttrs_1.return)) _a.call(refAttrs_1);
|
if (refAttrs_1_1 && !refAttrs_1_1.done && (_a = refAttrs_1.return)) _a.call(refAttrs_1);
|
||||||
}
|
}
|
||||||
finally { if (e_3) throw e_3.error; }
|
finally { if (e_4) throw e_4.error; }
|
||||||
}
|
}
|
||||||
if (refAttrs.length === uniqAttrs_2.length) {
|
if (refAttrs.length === uniqAttrs_2.length) {
|
||||||
// 如果更新了全部属性,直接检查
|
// 如果更新了全部属性,直接检查
|
||||||
|
|
@ -254,12 +268,12 @@ function analyzeActionDefDict(schema, actionDefDict) {
|
||||||
$not: operationFilter,
|
$not: operationFilter,
|
||||||
}]),
|
}]),
|
||||||
}, { dontCollect: true });
|
}, { dontCollect: true });
|
||||||
var checkCount = checkCountLessThan(count, uniqAttrs_2);
|
var checkCount = checkCountLessThan(count, uniqAttrs_2, 0, operationFilter === null || operationFilter === void 0 ? void 0 : operationFilter.id);
|
||||||
// 更新的行只能有一行
|
// 更新的行只能有一行
|
||||||
var rowCount = context.count(entity, {
|
var rowCount = context.count(entity, {
|
||||||
filter: operationFilter,
|
filter: operationFilter,
|
||||||
}, { dontCollect: true });
|
}, { dontCollect: true });
|
||||||
var checkRowCount = checkCountLessThan(rowCount, uniqAttrs_2, 1);
|
var checkRowCount = checkCountLessThan(rowCount, uniqAttrs_2, 1, operationFilter === null || operationFilter === void 0 ? void 0 : operationFilter.id);
|
||||||
// 如果更新的行数为零似乎也可以,但这应该不可能出现吧,by Xc 20230131
|
// 如果更新的行数为零似乎也可以,但这应该不可能出现吧,by Xc 20230131
|
||||||
if (checkRowCount instanceof Promise) {
|
if (checkRowCount instanceof Promise) {
|
||||||
return Promise.all([checkCount, checkRowCount]).then(function () { return undefined; });
|
return Promise.all([checkCount, checkRowCount]).then(function () { return undefined; });
|
||||||
|
|
@ -268,19 +282,19 @@ function analyzeActionDefDict(schema, actionDefDict) {
|
||||||
// 否则需要结合本行现有的属性来进行检查
|
// 否则需要结合本行现有的属性来进行检查
|
||||||
var projection = { id: 1 };
|
var projection = { id: 1 };
|
||||||
try {
|
try {
|
||||||
for (var uniqAttrs_3 = (e_4 = void 0, tslib_1.__values(uniqAttrs_2)), uniqAttrs_3_1 = uniqAttrs_3.next(); !uniqAttrs_3_1.done; uniqAttrs_3_1 = uniqAttrs_3.next()) {
|
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;
|
var attr = uniqAttrs_3_1.value;
|
||||||
Object.assign(projection, (_c = {},
|
Object.assign(projection, (_c = {},
|
||||||
_c[attr] = 1,
|
_c[attr] = 1,
|
||||||
_c));
|
_c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
||||||
finally {
|
finally {
|
||||||
try {
|
try {
|
||||||
if (uniqAttrs_3_1 && !uniqAttrs_3_1.done && (_b = uniqAttrs_3.return)) _b.call(uniqAttrs_3);
|
if (uniqAttrs_3_1 && !uniqAttrs_3_1.done && (_b = uniqAttrs_3.return)) _b.call(uniqAttrs_3);
|
||||||
}
|
}
|
||||||
finally { if (e_4) throw e_4.error; }
|
finally { if (e_5) throw e_5.error; }
|
||||||
}
|
}
|
||||||
var checkWithRows = function (rows2) {
|
var checkWithRows = function (rows2) {
|
||||||
var rows22 = rows2.map(function (ele) { return Object.assign(ele, data); });
|
var rows22 = rows2.map(function (ele) { return Object.assign(ele, data); });
|
||||||
|
|
@ -306,17 +320,17 @@ function analyzeActionDefDict(schema, actionDefDict) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
for (var indexes_1 = (e_2 = void 0, tslib_1.__values(indexes)), indexes_1_1 = indexes_1.next(); !indexes_1_1.done; indexes_1_1 = indexes_1.next()) {
|
for (var indexes_1 = (e_3 = void 0, tslib_1.__values(indexes)), indexes_1_1 = indexes_1.next(); !indexes_1_1.done; indexes_1_1 = indexes_1.next()) {
|
||||||
var index = indexes_1_1.value;
|
var index = indexes_1_1.value;
|
||||||
_loop_4(index);
|
_loop_4(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
||||||
finally {
|
finally {
|
||||||
try {
|
try {
|
||||||
if (indexes_1_1 && !indexes_1_1.done && (_e = indexes_1.return)) _e.call(indexes_1);
|
if (indexes_1_1 && !indexes_1_1.done && (_e = indexes_1.return)) _e.call(indexes_1);
|
||||||
}
|
}
|
||||||
finally { if (e_2) throw e_2.error; }
|
finally { if (e_3) throw e_3.error; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,9 @@ export declare type Exportation<ED extends EntityDict, T extends keyof ED, K ext
|
||||||
id: string;
|
id: string;
|
||||||
entity: T;
|
entity: T;
|
||||||
projection: ED[T]['Selection']['data'];
|
projection: ED[T]['Selection']['data'];
|
||||||
headers: K[];
|
headers?: K[];
|
||||||
fn: (data: ED[T]['Schema']) => Partial<Record<K, string | number | boolean | null>>;
|
makeHeaders?: (dataList: Partial<ED[T]['Schema']>[]) => string[];
|
||||||
|
fn: (data: ED[T]['Schema'], context?: AsyncContext<ED>, properties?: Record<string, any>) => Promise<Partial<Record<string, string | number | boolean | null>>> | Partial<Record<string, string | number | boolean | null>>;
|
||||||
};
|
};
|
||||||
export declare type Importation<ED extends EntityDict, T extends keyof ED, K extends string> = {
|
export declare type Importation<ED extends EntityDict, T extends keyof ED, K extends string> = {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ var ThousandCont = function (value) {
|
||||||
if (value1) {
|
if (value1) {
|
||||||
result = value1 + result;
|
result = value1 + result;
|
||||||
}
|
}
|
||||||
result = result + '.' + numArr[1];
|
result = numArr[1] ? result + '.' + numArr[1] : result;
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
exports.ThousandCont = ThousandCont;
|
exports.ThousandCont = ThousandCont;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "oak-domain",
|
"name": "oak-domain",
|
||||||
"version": "2.6.9",
|
"version": "2.6.10",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "XuChang"
|
"name": "XuChang"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -53,23 +53,27 @@ function makeIntrinsicWatchers<ED extends EntityDict>(schema: StorageSchema<ED>)
|
||||||
|
|
||||||
function checkUniqueBetweenRows(rows: Record<string, any>[], uniqAttrs: string[]) {
|
function checkUniqueBetweenRows(rows: Record<string, any>[], uniqAttrs: string[]) {
|
||||||
// 先检查这些行本身之间有无unique冲突
|
// 先检查这些行本身之间有无unique冲突
|
||||||
const uniqRows = uniqBy(rows, (d) => {
|
const dict: Record<string, 1> = {};
|
||||||
|
for (const row of rows) {
|
||||||
let s = '';
|
let s = '';
|
||||||
for (const a of uniqAttrs) {
|
for (const a of uniqAttrs) {
|
||||||
if (d[a as string] === null || d[a as string] === undefined) {
|
if (row[a] === null || row[a] === undefined) {
|
||||||
s + d.id;
|
s + row.id;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
s + `-${d[a as string]}`;
|
s + `-${row[a]}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s;
|
if (dict[s]) {
|
||||||
});
|
|
||||||
if (uniqRows.length < rows.length) {
|
|
||||||
throw new OakUniqueViolationException([{
|
throw new OakUniqueViolationException([{
|
||||||
|
id: row.id,
|
||||||
attrs: uniqAttrs,
|
attrs: uniqAttrs,
|
||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
dict[s] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkCountLessThan(count: number | Promise<number>, uniqAttrs: string[], than: number = 0, id?: string) {
|
function checkCountLessThan(count: number | Promise<number>, uniqAttrs: string[], than: number = 0, id?: string) {
|
||||||
|
|
@ -110,7 +114,7 @@ function checkUnique<ED extends EntityDict, Cxt extends SyncContext<ED> | AsyncC
|
||||||
// 说明有null值,不需要检查约束
|
// 说明有null值,不需要检查约束
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const filter2 = extraFilter ? addFilterSegment([filter, extraFilter]) : filter;
|
const filter2 = extraFilter ? addFilterSegment(filter, extraFilter) : filter;
|
||||||
const count = context.count(entity, { filter: filter2 }, { dontCollect: true });
|
const count = context.count(entity, { filter: filter2 }, { dontCollect: true });
|
||||||
return checkCountLessThan(count, uniqAttrs, 0, row.id)
|
return checkCountLessThan(count, uniqAttrs, 0, row.id)
|
||||||
}
|
}
|
||||||
|
|
@ -245,13 +249,13 @@ export function analyzeActionDefDict<ED extends EntityDict, Cxt extends SyncCont
|
||||||
$not: operationFilter,
|
$not: operationFilter,
|
||||||
}]),
|
}]),
|
||||||
}, { dontCollect: true });
|
}, { dontCollect: true });
|
||||||
const checkCount = checkCountLessThan(count, uniqAttrs);
|
const checkCount = checkCountLessThan(count, uniqAttrs, 0, operationFilter?.id);
|
||||||
|
|
||||||
// 更新的行只能有一行
|
// 更新的行只能有一行
|
||||||
const rowCount = context.count(entity, {
|
const rowCount = context.count(entity, {
|
||||||
filter: operationFilter,
|
filter: operationFilter,
|
||||||
}, { dontCollect: true });
|
}, { dontCollect: true });
|
||||||
const checkRowCount = checkCountLessThan(rowCount, uniqAttrs, 1);
|
const checkRowCount = checkCountLessThan(rowCount, uniqAttrs, 1, operationFilter?.id);
|
||||||
|
|
||||||
// 如果更新的行数为零似乎也可以,但这应该不可能出现吧,by Xc 20230131
|
// 如果更新的行数为零似乎也可以,但这应该不可能出现吧,by Xc 20230131
|
||||||
if (checkRowCount instanceof Promise) {
|
if (checkRowCount instanceof Promise) {
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,9 @@ export type Exportation<ED extends EntityDict, T extends keyof ED, K extends str
|
||||||
id: string;
|
id: string;
|
||||||
entity: T;
|
entity: T;
|
||||||
projection: ED[T]['Selection']['data'];
|
projection: ED[T]['Selection']['data'];
|
||||||
headers: K[];
|
headers?: K[];
|
||||||
fn: (data: ED[T]['Schema']) => Partial<Record<K, string | number | boolean | null>>;
|
makeHeaders?: (dataList: Partial<ED[T]['Schema']>[]) => string[];
|
||||||
|
fn: (data: ED[T]['Schema'], context?: AsyncContext<ED>, properties?: Record<string, any>) => Promise<Partial<Record<string, string | number | boolean | null>>> | Partial<Record<string, string | number | boolean | null>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Importation<ED extends EntityDict, T extends keyof ED, K extends string> = {
|
export type Importation<ED extends EntityDict, T extends keyof ED, K extends string> = {
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ const ThousandCont: (value: number) => string | undefined = (value) => {
|
||||||
if (value1) {
|
if (value1) {
|
||||||
result = value1 + result;
|
result = value1 + result;
|
||||||
}
|
}
|
||||||
result = result + '.' + numArr[1];
|
result = numArr[1] ? result + '.' + numArr[1] : result;
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue