oak-domain 2.6.9 → 2.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/store/actionDef.js +50 -36
- package/lib/types/Port.d.ts +3 -2
- package/lib/utils/money.js +1 -1
- package/package.json +1 -1
package/lib/store/actionDef.js
CHANGED
|
@@ -50,34 +50,48 @@ function makeIntrinsicWatchers(schema) {
|
|
|
50
50
|
return watchers;
|
|
51
51
|
}
|
|
52
52
|
function checkUniqueBetweenRows(rows, uniqAttrs) {
|
|
53
|
+
var e_1, _a, e_2, _b;
|
|
53
54
|
// 先检查这些行本身之间有无unique冲突
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
var
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
var dict = {};
|
|
56
|
+
try {
|
|
57
|
+
for (var rows_1 = tslib_1.__values(rows), rows_1_1 = rows_1.next(); !rows_1_1.done; rows_1_1 = rows_1.next()) {
|
|
58
|
+
var row = rows_1_1.value;
|
|
59
|
+
var s = '';
|
|
60
|
+
try {
|
|
61
|
+
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()) {
|
|
62
|
+
var a = uniqAttrs_1_1.value;
|
|
63
|
+
if (row[a] === null || row[a] === undefined) {
|
|
64
|
+
s + row.id;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
s + "-".concat(row[a]);
|
|
68
|
+
}
|
|
62
69
|
}
|
|
63
|
-
|
|
64
|
-
|
|
70
|
+
}
|
|
71
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
72
|
+
finally {
|
|
73
|
+
try {
|
|
74
|
+
if (uniqAttrs_1_1 && !uniqAttrs_1_1.done && (_b = uniqAttrs_1.return)) _b.call(uniqAttrs_1);
|
|
65
75
|
}
|
|
76
|
+
finally { if (e_2) throw e_2.error; }
|
|
66
77
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
78
|
+
if (dict[s]) {
|
|
79
|
+
throw new types_1.OakUniqueViolationException([{
|
|
80
|
+
id: row.id,
|
|
81
|
+
attrs: uniqAttrs,
|
|
82
|
+
}]);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
dict[s] = 1;
|
|
72
86
|
}
|
|
73
|
-
finally { if (e_1) throw e_1.error; }
|
|
74
87
|
}
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
}
|
|
89
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
90
|
+
finally {
|
|
91
|
+
try {
|
|
92
|
+
if (rows_1_1 && !rows_1_1.done && (_a = rows_1.return)) _a.call(rows_1);
|
|
93
|
+
}
|
|
94
|
+
finally { if (e_1) throw e_1.error; }
|
|
81
95
|
}
|
|
82
96
|
}
|
|
83
97
|
function checkCountLessThan(count, uniqAttrs, than, id) {
|
|
@@ -110,7 +124,7 @@ function checkUnique(entity, row, context, uniqAttrs, extraFilter) {
|
|
|
110
124
|
// 说明有null值,不需要检查约束
|
|
111
125
|
return;
|
|
112
126
|
}
|
|
113
|
-
var filter2 = extraFilter ? (0, filter_1.addFilterSegment)(
|
|
127
|
+
var filter2 = extraFilter ? (0, filter_1.addFilterSegment)(filter, extraFilter) : filter;
|
|
114
128
|
var count = context.count(entity, { filter: filter2 }, { dontCollect: true });
|
|
115
129
|
return checkCountLessThan(count, uniqAttrs, 0, row.id);
|
|
116
130
|
}
|
|
@@ -190,7 +204,7 @@ function analyzeActionDefDict(schema, actionDefDict) {
|
|
|
190
204
|
}
|
|
191
205
|
}
|
|
192
206
|
var _loop_2 = function (entity) {
|
|
193
|
-
var
|
|
207
|
+
var e_3, _e;
|
|
194
208
|
var indexes = schema[entity].indexes;
|
|
195
209
|
if (indexes) {
|
|
196
210
|
var _loop_4 = function (index) {
|
|
@@ -221,7 +235,7 @@ function analyzeActionDefDict(schema, actionDefDict) {
|
|
|
221
235
|
type: 'logical',
|
|
222
236
|
priority: 20,
|
|
223
237
|
checker: function (operation, context) {
|
|
224
|
-
var
|
|
238
|
+
var e_4, _a, e_5, _b, _c;
|
|
225
239
|
var _d = operation, data = _d.data, operationFilter = _d.filter;
|
|
226
240
|
var attrs = Object.keys(data);
|
|
227
241
|
var refAttrs = (0, lodash_1.intersection)(attrs, uniqAttrs_2);
|
|
@@ -230,7 +244,7 @@ function analyzeActionDefDict(schema, actionDefDict) {
|
|
|
230
244
|
return;
|
|
231
245
|
}
|
|
232
246
|
try {
|
|
233
|
-
for (var refAttrs_1 = (
|
|
247
|
+
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()) {
|
|
234
248
|
var attr = refAttrs_1_1.value;
|
|
235
249
|
// 如果有更新为null值,不用再检查约束
|
|
236
250
|
if (data[attr] === null || data[attr] === undefined) {
|
|
@@ -238,12 +252,12 @@ function analyzeActionDefDict(schema, actionDefDict) {
|
|
|
238
252
|
}
|
|
239
253
|
}
|
|
240
254
|
}
|
|
241
|
-
catch (
|
|
255
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
242
256
|
finally {
|
|
243
257
|
try {
|
|
244
258
|
if (refAttrs_1_1 && !refAttrs_1_1.done && (_a = refAttrs_1.return)) _a.call(refAttrs_1);
|
|
245
259
|
}
|
|
246
|
-
finally { if (
|
|
260
|
+
finally { if (e_4) throw e_4.error; }
|
|
247
261
|
}
|
|
248
262
|
if (refAttrs.length === uniqAttrs_2.length) {
|
|
249
263
|
// 如果更新了全部属性,直接检查
|
|
@@ -254,12 +268,12 @@ function analyzeActionDefDict(schema, actionDefDict) {
|
|
|
254
268
|
$not: operationFilter,
|
|
255
269
|
}]),
|
|
256
270
|
}, { dontCollect: true });
|
|
257
|
-
var checkCount = checkCountLessThan(count, uniqAttrs_2);
|
|
271
|
+
var checkCount = checkCountLessThan(count, uniqAttrs_2, 0, operationFilter === null || operationFilter === void 0 ? void 0 : operationFilter.id);
|
|
258
272
|
// 更新的行只能有一行
|
|
259
273
|
var rowCount = context.count(entity, {
|
|
260
274
|
filter: operationFilter,
|
|
261
275
|
}, { dontCollect: true });
|
|
262
|
-
var checkRowCount = checkCountLessThan(rowCount, uniqAttrs_2, 1);
|
|
276
|
+
var checkRowCount = checkCountLessThan(rowCount, uniqAttrs_2, 1, operationFilter === null || operationFilter === void 0 ? void 0 : operationFilter.id);
|
|
263
277
|
// 如果更新的行数为零似乎也可以,但这应该不可能出现吧,by Xc 20230131
|
|
264
278
|
if (checkRowCount instanceof Promise) {
|
|
265
279
|
return Promise.all([checkCount, checkRowCount]).then(function () { return undefined; });
|
|
@@ -268,19 +282,19 @@ function analyzeActionDefDict(schema, actionDefDict) {
|
|
|
268
282
|
// 否则需要结合本行现有的属性来进行检查
|
|
269
283
|
var projection = { id: 1 };
|
|
270
284
|
try {
|
|
271
|
-
for (var uniqAttrs_3 = (
|
|
285
|
+
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()) {
|
|
272
286
|
var attr = uniqAttrs_3_1.value;
|
|
273
287
|
Object.assign(projection, (_c = {},
|
|
274
288
|
_c[attr] = 1,
|
|
275
289
|
_c));
|
|
276
290
|
}
|
|
277
291
|
}
|
|
278
|
-
catch (
|
|
292
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
279
293
|
finally {
|
|
280
294
|
try {
|
|
281
295
|
if (uniqAttrs_3_1 && !uniqAttrs_3_1.done && (_b = uniqAttrs_3.return)) _b.call(uniqAttrs_3);
|
|
282
296
|
}
|
|
283
|
-
finally { if (
|
|
297
|
+
finally { if (e_5) throw e_5.error; }
|
|
284
298
|
}
|
|
285
299
|
var checkWithRows = function (rows2) {
|
|
286
300
|
var rows22 = rows2.map(function (ele) { return Object.assign(ele, data); });
|
|
@@ -306,17 +320,17 @@ function analyzeActionDefDict(schema, actionDefDict) {
|
|
|
306
320
|
}
|
|
307
321
|
};
|
|
308
322
|
try {
|
|
309
|
-
for (var indexes_1 = (
|
|
323
|
+
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()) {
|
|
310
324
|
var index = indexes_1_1.value;
|
|
311
325
|
_loop_4(index);
|
|
312
326
|
}
|
|
313
327
|
}
|
|
314
|
-
catch (
|
|
328
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
315
329
|
finally {
|
|
316
330
|
try {
|
|
317
331
|
if (indexes_1_1 && !indexes_1_1.done && (_e = indexes_1.return)) _e.call(indexes_1);
|
|
318
332
|
}
|
|
319
|
-
finally { if (
|
|
333
|
+
finally { if (e_3) throw e_3.error; }
|
|
320
334
|
}
|
|
321
335
|
}
|
|
322
336
|
};
|
package/lib/types/Port.d.ts
CHANGED
|
@@ -5,8 +5,9 @@ export declare type Exportation<ED extends EntityDict, T extends keyof ED, K ext
|
|
|
5
5
|
id: string;
|
|
6
6
|
entity: T;
|
|
7
7
|
projection: ED[T]['Selection']['data'];
|
|
8
|
-
headers
|
|
9
|
-
|
|
8
|
+
headers?: K[];
|
|
9
|
+
makeHeaders?: (dataList: Partial<ED[T]['Schema']>[]) => string[];
|
|
10
|
+
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>>;
|
|
10
11
|
};
|
|
11
12
|
export declare type Importation<ED extends EntityDict, T extends keyof ED, K extends string> = {
|
|
12
13
|
name: string;
|
package/lib/utils/money.js
CHANGED