oak-domain 3.0.2 → 3.0.4
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/actions/action.d.ts +8 -8
- package/lib/actions/action.js +2 -2
- package/lib/actions/relation.d.ts +1 -1
- package/lib/actions/relation.js +9 -22
- package/lib/base-app-domain/ActionAuth/Schema.d.ts +68 -42
- package/lib/base-app-domain/ActionAuth/Storage.js +12 -15
- package/lib/base-app-domain/ActionDefDict.d.ts +2 -3
- package/lib/base-app-domain/ActionDefDict.js +3 -5
- package/lib/base-app-domain/EntityDict.d.ts +5 -1
- package/lib/base-app-domain/I18n/Schema.d.ts +24 -24
- package/lib/base-app-domain/I18n/Storage.js +5 -5
- package/lib/base-app-domain/Modi/Action.d.ts +4 -4
- package/lib/base-app-domain/Modi/Action.js +3 -3
- package/lib/base-app-domain/Modi/Schema.d.ts +24 -24
- package/lib/base-app-domain/Modi/Storage.js +3 -3
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +128 -55
- package/lib/base-app-domain/ModiEntity/Storage.js +2 -2
- package/lib/base-app-domain/Oper/Schema.d.ts +30 -29
- package/lib/base-app-domain/Oper/Storage.js +1 -1
- package/lib/base-app-domain/OperEntity/Schema.d.ts +126 -53
- package/lib/base-app-domain/OperEntity/Storage.js +2 -2
- package/lib/base-app-domain/Path/Schema.d.ts +149 -0
- package/lib/base-app-domain/Path/Schema.js +2 -0
- package/lib/base-app-domain/Path/Storage.d.ts +3 -0
- package/lib/base-app-domain/Path/Storage.js +54 -0
- package/lib/base-app-domain/Relation/Schema.d.ts +34 -34
- package/lib/base-app-domain/Relation/Storage.js +6 -6
- package/lib/base-app-domain/Relation.d.ts +0 -8
- package/lib/base-app-domain/Relation.js +1 -7
- package/lib/base-app-domain/RelationAuth/Schema.d.ts +74 -40
- package/lib/base-app-domain/RelationAuth/Storage.js +9 -11
- package/lib/base-app-domain/Storage.js +20 -16
- package/lib/base-app-domain/User/Action.d.ts +4 -4
- package/lib/base-app-domain/User/Action.js +3 -3
- package/lib/base-app-domain/User/Schema.d.ts +40 -27
- package/lib/base-app-domain/User/Storage.js +1 -1
- package/lib/base-app-domain/UserEntityClaim/Schema.d.ts +264 -0
- package/lib/base-app-domain/UserEntityClaim/Schema.js +2 -0
- package/lib/base-app-domain/UserEntityClaim/Storage.d.ts +3 -0
- package/lib/base-app-domain/UserEntityClaim/Storage.js +37 -0
- package/lib/base-app-domain/UserEntityGrant/Action.d.ts +2 -2
- package/lib/base-app-domain/UserEntityGrant/Schema.d.ts +55 -81
- package/lib/base-app-domain/UserEntityGrant/Storage.js +7 -11
- package/lib/base-app-domain/UserRelation/Schema.d.ts +50 -36
- package/lib/base-app-domain/UserRelation/Storage.js +7 -7
- package/lib/base-app-domain/_SubQuery.d.ts +45 -15
- package/lib/base-app-domain/index.js +1 -1
- package/lib/checkers/index.js +6 -7
- package/lib/compiler/env.js +16 -18
- package/lib/compiler/localeBuilder.js +83 -79
- package/lib/compiler/schemalBuilder.d.ts +16 -0
- package/lib/compiler/schemalBuilder.js +1160 -1378
- package/lib/entities/ActionAuth.d.ts +3 -5
- package/lib/entities/ActionAuth.js +9 -7
- package/lib/entities/I18n.js +1 -1
- package/lib/entities/Modi.js +2 -2
- package/lib/entities/ModiEntity.js +1 -1
- package/lib/entities/Oper.js +1 -1
- package/lib/entities/OperEntity.js +1 -1
- package/lib/entities/Path.d.ts +8 -0
- package/lib/entities/Path.js +35 -0
- package/lib/entities/Relation.js +1 -1
- package/lib/entities/RelationAuth.d.ts +2 -2
- package/lib/entities/RelationAuth.js +1 -1
- package/lib/entities/User.js +2 -2
- package/lib/entities/UserEntityClaim.d.ts +13 -0
- package/lib/entities/UserEntityClaim.js +17 -0
- package/lib/entities/UserEntityGrant.d.ts +5 -4
- package/lib/entities/UserEntityGrant.js +4 -7
- package/lib/entities/UserRelation.js +1 -1
- package/lib/index.d.ts +23 -0
- package/lib/index.js +37 -0
- package/lib/store/AsyncRowStore.d.ts +2 -1
- package/lib/store/AsyncRowStore.js +75 -149
- package/lib/store/CascadeStore.js +968 -1341
- package/lib/store/RelationAuth.d.ts +9 -16
- package/lib/store/RelationAuth.js +752 -910
- package/lib/store/SyncRowStore.d.ts +1 -1
- package/lib/store/SyncRowStore.js +27 -26
- package/lib/store/TriggerExecutor.d.ts +17 -10
- package/lib/store/TriggerExecutor.js +350 -423
- package/lib/store/actionAuth.js +13 -28
- package/lib/store/actionDef.js +142 -215
- package/lib/store/checker.js +225 -361
- package/lib/store/filter.d.ts +2 -3
- package/lib/store/filter.js +451 -589
- package/lib/store/modi.js +116 -177
- package/lib/store/relation.js +17 -17
- package/lib/timers/oper.d.ts +1 -1
- package/lib/timers/oper.js +44 -47
- package/lib/timers/vaccum.d.ts +2 -2
- package/lib/timers/vaccum.js +100 -165
- package/lib/triggers/index.js +1 -1
- package/lib/types/Action.d.ts +7 -7
- package/lib/types/AppLoader.d.ts +8 -2
- package/lib/types/AppLoader.js +4 -4
- package/lib/types/Auth.d.ts +15 -19
- package/lib/types/Connector.d.ts +19 -14
- package/lib/types/Connector.js +0 -7
- package/lib/types/DataType.d.ts +19 -18
- package/lib/types/DataType.js +1 -1
- package/lib/types/Demand.d.ts +25 -25
- package/lib/types/Endpoint.d.ts +1 -1
- package/lib/types/Entity.d.ts +62 -53
- package/lib/types/Entity.js +4 -3
- package/lib/types/EntityDesc.d.ts +2 -1
- package/lib/types/Environment.d.ts +4 -4
- package/lib/types/Exception.d.ts +34 -2
- package/lib/types/Exception.js +214 -197
- package/lib/types/Expression.d.ts +14 -14
- package/lib/types/Expression.js +54 -87
- package/lib/types/Geo.d.ts +6 -6
- package/lib/types/Locale.d.ts +5 -5
- package/lib/types/Polyfill.d.ts +9 -9
- package/lib/types/Port.d.ts +4 -4
- package/lib/types/RowStore.d.ts +3 -3
- package/lib/types/RowStore.js +18 -19
- package/lib/types/Storage.d.ts +5 -4
- package/lib/types/Style.d.ts +2 -2
- package/lib/types/Timer.d.ts +3 -3
- package/lib/types/Trigger.d.ts +30 -14
- package/lib/types/Trigger.js +6 -2
- package/lib/types/Watcher.d.ts +2 -2
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +2 -1
- package/lib/types/schema/DataTypes.d.ts +7 -7
- package/lib/utils/SimpleConnector.d.ts +26 -10
- package/lib/utils/SimpleConnector.js +167 -141
- package/lib/utils/assert.js +2 -2
- package/lib/utils/concurrent.d.ts +1 -1
- package/lib/utils/concurrent.js +31 -57
- package/lib/utils/date.js +2 -2
- package/lib/utils/geo.js +8 -8
- package/lib/utils/lodash.d.ts +3 -1
- package/lib/utils/lodash.js +21 -34
- package/lib/utils/mask.js +12 -13
- package/lib/utils/money.d.ts +1 -1
- package/lib/utils/money.js +22 -11
- package/lib/utils/projection.d.ts +4 -0
- package/lib/utils/projection.js +15 -0
- package/lib/utils/random/random.js +11 -16
- package/lib/utils/random/random.mp.js +7 -18
- package/lib/utils/random/random.web.js +6 -12
- package/lib/utils/string.d.ts +4 -4
- package/lib/utils/string.js +19 -32
- package/lib/utils/url.js +5 -4
- package/lib/utils/uuid.d.ts +1 -1
- package/lib/utils/uuid.js +46 -85
- package/lib/utils/validator.d.ts +4 -3
- package/lib/utils/validator.js +35 -32
- package/lib/utils/version.js +6 -6
- package/package.json +7 -7
- package/src/entities/ActionAuth.ts +10 -10
- package/src/entities/Path.ts +43 -0
- package/src/entities/RelationAuth.ts +2 -1
- package/src/entities/UserEntityClaim.ts +30 -0
- package/src/entities/UserEntityGrant.ts +9 -12
package/lib/store/actionAuth.js
CHANGED
|
@@ -1,39 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.triggers = void 0;
|
|
4
|
-
|
|
5
|
-
var uuid_1 = require("../utils/uuid");
|
|
4
|
+
const uuid_1 = require("../utils/uuid");
|
|
6
5
|
exports.triggers = [
|
|
7
6
|
{
|
|
8
7
|
name: '当actionAuth的deActions被置空后,删除此条数据',
|
|
9
8
|
entity: 'actionAuth',
|
|
10
9
|
action: 'update',
|
|
11
|
-
fn:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
_e = {};
|
|
24
|
-
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
|
25
|
-
case 1: return [4 /*yield*/, _c.apply(_b, _d.concat([(_e.id = _f.sent(),
|
|
26
|
-
_e.action = 'remove',
|
|
27
|
-
_e.data = {},
|
|
28
|
-
_e.filter = filter,
|
|
29
|
-
_e), option]))];
|
|
30
|
-
case 2:
|
|
31
|
-
_f.sent();
|
|
32
|
-
return [2 /*return*/, 1];
|
|
33
|
-
case 3: return [2 /*return*/, 0];
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
});
|
|
10
|
+
fn: async ({ operation }, context, option) => {
|
|
11
|
+
const { data, filter } = operation;
|
|
12
|
+
if (data.deActions && data.deActions.length === 0) {
|
|
13
|
+
await context.operate('actionAuth', {
|
|
14
|
+
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
15
|
+
action: 'remove',
|
|
16
|
+
data: {},
|
|
17
|
+
filter,
|
|
18
|
+
}, option);
|
|
19
|
+
return 1;
|
|
20
|
+
}
|
|
21
|
+
return 0;
|
|
37
22
|
},
|
|
38
23
|
when: 'after',
|
|
39
24
|
}
|
package/lib/store/actionDef.js
CHANGED
|
@@ -1,41 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeIntrinsicCTWs = exports.getFullProjection = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var actionAuth_1 = require("./actionAuth");
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const lodash_1 = require("../utils/lodash");
|
|
6
|
+
const filter_1 = require("./filter");
|
|
7
|
+
const checkers_1 = require("../checkers");
|
|
8
|
+
const triggers_1 = require("../triggers");
|
|
9
|
+
const actionAuth_1 = require("./actionAuth");
|
|
11
10
|
function getFullProjection(entity, schema) {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const { attributes } = schema[entity];
|
|
12
|
+
const projection = {
|
|
14
13
|
id: 1,
|
|
15
14
|
$$createAt$$: 1,
|
|
16
15
|
$$updateAt$$: 1,
|
|
17
16
|
$$deleteAt$$: 1,
|
|
18
17
|
};
|
|
19
|
-
Object.keys(attributes).forEach(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
_a[k] = 1,
|
|
23
|
-
_a));
|
|
24
|
-
});
|
|
18
|
+
Object.keys(attributes).forEach((k) => Object.assign(projection, {
|
|
19
|
+
[k]: 1,
|
|
20
|
+
}));
|
|
25
21
|
return projection;
|
|
26
22
|
}
|
|
27
23
|
exports.getFullProjection = getFullProjection;
|
|
28
24
|
function makeIntrinsicWatchers(schema) {
|
|
29
|
-
|
|
30
|
-
for (
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
const watchers = [];
|
|
26
|
+
for (const entity in schema) {
|
|
27
|
+
const { attributes } = schema[entity];
|
|
28
|
+
const { expiresAt, expired } = attributes;
|
|
33
29
|
if (expiresAt && expiresAt.type === 'datetime' && expired && expired.type === 'boolean') {
|
|
34
30
|
// 如果有定义expiresAt和expired,则自动生成一个检查的watcher
|
|
35
31
|
watchers.push({
|
|
36
|
-
entity
|
|
37
|
-
name:
|
|
38
|
-
filter:
|
|
32
|
+
entity,
|
|
33
|
+
name: `对象${entity}上的过期自动watcher`,
|
|
34
|
+
filter: () => {
|
|
39
35
|
return {
|
|
40
36
|
expired: false,
|
|
41
37
|
expiresAt: {
|
|
@@ -53,57 +49,35 @@ function makeIntrinsicWatchers(schema) {
|
|
|
53
49
|
return watchers;
|
|
54
50
|
}
|
|
55
51
|
function checkUniqueBetweenRows(rows, uniqAttrs) {
|
|
56
|
-
var e_1, _a, e_2, _b;
|
|
57
52
|
// 先检查这些行本身之间有无unique冲突
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
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()) {
|
|
65
|
-
var a = uniqAttrs_1_1.value;
|
|
66
|
-
if (row[a] === null || row[a] === undefined) {
|
|
67
|
-
s + row.id;
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
s + "-".concat(row[a]);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
75
|
-
finally {
|
|
76
|
-
try {
|
|
77
|
-
if (uniqAttrs_1_1 && !uniqAttrs_1_1.done && (_b = uniqAttrs_1.return)) _b.call(uniqAttrs_1);
|
|
78
|
-
}
|
|
79
|
-
finally { if (e_2) throw e_2.error; }
|
|
80
|
-
}
|
|
81
|
-
if (dict[s]) {
|
|
82
|
-
throw new types_1.OakUniqueViolationException([{
|
|
83
|
-
id: row.id,
|
|
84
|
-
attrs: uniqAttrs,
|
|
85
|
-
}]);
|
|
53
|
+
const dict = {};
|
|
54
|
+
for (const row of rows) {
|
|
55
|
+
let s = '';
|
|
56
|
+
for (const a of uniqAttrs) {
|
|
57
|
+
if (row[a] === null || row[a] === undefined) {
|
|
58
|
+
s + row.id;
|
|
86
59
|
}
|
|
87
60
|
else {
|
|
88
|
-
|
|
61
|
+
s + `-${row[a]}`;
|
|
89
62
|
}
|
|
90
63
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
64
|
+
if (dict[s]) {
|
|
65
|
+
throw new types_1.OakUniqueViolationException([{
|
|
66
|
+
id: row.id,
|
|
67
|
+
attrs: uniqAttrs,
|
|
68
|
+
}]);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
dict[s] = 1;
|
|
96
72
|
}
|
|
97
|
-
finally { if (e_1) throw e_1.error; }
|
|
98
73
|
}
|
|
99
74
|
}
|
|
100
|
-
function checkCountLessThan(count, uniqAttrs, than, id) {
|
|
101
|
-
if (than === void 0) { than = 0; }
|
|
75
|
+
function checkCountLessThan(count, uniqAttrs, than = 0, id) {
|
|
102
76
|
if (count instanceof Promise) {
|
|
103
|
-
return count.then(
|
|
77
|
+
return count.then((count2) => {
|
|
104
78
|
if (count2 > than) {
|
|
105
79
|
throw new types_1.OakUniqueViolationException([{
|
|
106
|
-
id
|
|
80
|
+
id,
|
|
107
81
|
attrs: uniqAttrs,
|
|
108
82
|
}]);
|
|
109
83
|
}
|
|
@@ -111,14 +85,14 @@ function checkCountLessThan(count, uniqAttrs, than, id) {
|
|
|
111
85
|
}
|
|
112
86
|
if (count > than) {
|
|
113
87
|
throw new types_1.OakUniqueViolationException([{
|
|
114
|
-
id
|
|
88
|
+
id,
|
|
115
89
|
attrs: uniqAttrs,
|
|
116
90
|
}]);
|
|
117
91
|
}
|
|
118
92
|
}
|
|
119
93
|
function checkUnique(entity, row, context, uniqAttrs, extraFilter) {
|
|
120
|
-
|
|
121
|
-
for (
|
|
94
|
+
const filter = (0, lodash_1.pick)(row, uniqAttrs);
|
|
95
|
+
for (const a in filter) {
|
|
122
96
|
if (filter[a] === null || filter[a] === undefined) {
|
|
123
97
|
delete filter[a];
|
|
124
98
|
}
|
|
@@ -127,33 +101,31 @@ function checkUnique(entity, row, context, uniqAttrs, extraFilter) {
|
|
|
127
101
|
// 说明有null值,不需要检查约束
|
|
128
102
|
return;
|
|
129
103
|
}
|
|
130
|
-
|
|
131
|
-
|
|
104
|
+
const filter2 = extraFilter ? (0, filter_1.combineFilters)(entity, context.getSchema(), [filter, extraFilter]) : filter;
|
|
105
|
+
const count = context.count(entity, { filter: filter2 }, { dontCollect: true });
|
|
132
106
|
return checkCountLessThan(count, uniqAttrs, 0, row.id);
|
|
133
107
|
}
|
|
134
108
|
function makeIntrinsicCTWs(schema, actionDefDict) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
var triggers = (0, triggers_1.createDynamicTriggers)(schema);
|
|
109
|
+
const checkers = (0, checkers_1.createDynamicCheckers)(schema);
|
|
110
|
+
const triggers = (0, triggers_1.createDynamicTriggers)(schema);
|
|
138
111
|
// action状态转换矩阵相应的checker
|
|
139
|
-
for (
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
_d[attr] = {
|
|
112
|
+
for (const entity in actionDefDict) {
|
|
113
|
+
for (const attr in actionDefDict[entity]) {
|
|
114
|
+
const def = actionDefDict[entity][attr];
|
|
115
|
+
const { stm, is } = def;
|
|
116
|
+
for (const action in stm) {
|
|
117
|
+
const actionStm = stm[action];
|
|
118
|
+
const conditionalFilter = typeof actionStm[0] === 'string' ? {
|
|
119
|
+
[attr]: actionStm[0],
|
|
120
|
+
} : {
|
|
121
|
+
[attr]: {
|
|
150
122
|
$in: actionStm[0],
|
|
151
123
|
},
|
|
152
|
-
|
|
124
|
+
};
|
|
153
125
|
checkers.push({
|
|
154
126
|
action: action,
|
|
155
127
|
type: 'row',
|
|
156
|
-
entity
|
|
128
|
+
entity,
|
|
157
129
|
filter: conditionalFilter,
|
|
158
130
|
errMsg: '',
|
|
159
131
|
});
|
|
@@ -161,190 +133,145 @@ function makeIntrinsicCTWs(schema, actionDefDict) {
|
|
|
161
133
|
checkers.push({
|
|
162
134
|
action: action,
|
|
163
135
|
type: 'data',
|
|
164
|
-
entity
|
|
165
|
-
checker:
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
_a));
|
|
136
|
+
entity,
|
|
137
|
+
checker: (data) => {
|
|
138
|
+
Object.assign(data, {
|
|
139
|
+
[attr]: stm[action][1],
|
|
140
|
+
});
|
|
170
141
|
}
|
|
171
142
|
});
|
|
172
|
-
};
|
|
173
|
-
for (var action in stm) {
|
|
174
|
-
_loop_3(action);
|
|
175
143
|
}
|
|
176
144
|
if (is) {
|
|
177
145
|
checkers.push({
|
|
178
146
|
action: 'create',
|
|
179
147
|
type: 'data',
|
|
180
|
-
entity
|
|
148
|
+
entity,
|
|
181
149
|
priority: 10,
|
|
182
|
-
checker:
|
|
183
|
-
var _a;
|
|
150
|
+
checker: (data) => {
|
|
184
151
|
if (data instanceof Array) {
|
|
185
|
-
data.forEach(
|
|
186
|
-
var _a;
|
|
152
|
+
data.forEach(ele => {
|
|
187
153
|
if (!ele[attr]) {
|
|
188
|
-
Object.assign(ele,
|
|
189
|
-
|
|
190
|
-
|
|
154
|
+
Object.assign(ele, {
|
|
155
|
+
[attr]: is,
|
|
156
|
+
});
|
|
191
157
|
}
|
|
192
158
|
});
|
|
193
159
|
}
|
|
194
160
|
else {
|
|
195
161
|
if (!data[attr]) {
|
|
196
|
-
Object.assign(data,
|
|
197
|
-
|
|
198
|
-
|
|
162
|
+
Object.assign(data, {
|
|
163
|
+
[attr]: is,
|
|
164
|
+
});
|
|
199
165
|
}
|
|
200
166
|
}
|
|
201
167
|
}
|
|
202
168
|
});
|
|
203
169
|
}
|
|
204
|
-
};
|
|
205
|
-
for (var attr in actionDefDict[entity]) {
|
|
206
|
-
_loop_1(attr);
|
|
207
170
|
}
|
|
208
171
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
172
|
+
// unique索引相应的checker
|
|
173
|
+
for (const entity in schema) {
|
|
174
|
+
const { indexes } = schema[entity];
|
|
212
175
|
if (indexes) {
|
|
213
|
-
|
|
214
|
-
if (
|
|
215
|
-
|
|
216
|
-
|
|
176
|
+
for (const index of indexes) {
|
|
177
|
+
if (index.config?.unique) {
|
|
178
|
+
const { attributes } = index;
|
|
179
|
+
const uniqAttrs = attributes.map(ele => ele.name);
|
|
217
180
|
checkers.push({
|
|
218
|
-
entity
|
|
181
|
+
entity,
|
|
219
182
|
action: 'create',
|
|
220
|
-
type: '
|
|
183
|
+
type: 'logicalData',
|
|
221
184
|
priority: types_1.CHECKER_MAX_PRIORITY,
|
|
222
|
-
checker:
|
|
223
|
-
|
|
185
|
+
checker: (operation, context) => {
|
|
186
|
+
const { data } = operation;
|
|
224
187
|
if (data instanceof Array) {
|
|
225
|
-
checkUniqueBetweenRows(data,
|
|
226
|
-
|
|
188
|
+
checkUniqueBetweenRows(data, uniqAttrs);
|
|
189
|
+
const checkResult = data.map(ele => checkUnique(entity, ele, context, uniqAttrs));
|
|
227
190
|
if (checkResult[0] instanceof Promise) {
|
|
228
|
-
return Promise.all(checkResult).then(
|
|
191
|
+
return Promise.all(checkResult).then(() => undefined);
|
|
229
192
|
}
|
|
230
193
|
}
|
|
231
|
-
else {
|
|
232
|
-
return checkUnique(entity, data, context,
|
|
194
|
+
else if (data) {
|
|
195
|
+
return checkUnique(entity, data, context, uniqAttrs);
|
|
233
196
|
}
|
|
234
197
|
}
|
|
235
198
|
}, {
|
|
236
|
-
entity
|
|
199
|
+
entity,
|
|
237
200
|
action: 'update',
|
|
238
|
-
type: '
|
|
201
|
+
type: 'logicalData',
|
|
239
202
|
priority: types_1.CHECKER_MAX_PRIORITY,
|
|
240
|
-
checker:
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
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()) {
|
|
251
|
-
var attr = refAttrs_1_1.value;
|
|
203
|
+
checker: (operation, context) => {
|
|
204
|
+
const { data, filter: operationFilter } = operation;
|
|
205
|
+
if (data) {
|
|
206
|
+
const attrs = Object.keys(data);
|
|
207
|
+
const refAttrs = (0, lodash_1.intersection)(attrs, uniqAttrs);
|
|
208
|
+
if (refAttrs.length === 0) {
|
|
209
|
+
// 如果本次更新和unique约束的属性之间没有交集则直接返回
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
for (const attr of refAttrs) {
|
|
252
213
|
// 如果有更新为null值,不用再检查约束
|
|
253
214
|
if (data[attr] === null || data[attr] === undefined) {
|
|
254
215
|
return;
|
|
255
216
|
}
|
|
256
217
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
218
|
+
if (refAttrs.length === uniqAttrs.length) {
|
|
219
|
+
// 如果更新了全部属性,直接检查
|
|
220
|
+
const filter = (0, lodash_1.pick)(data, refAttrs);
|
|
221
|
+
// 在这些行以外的行不和更新后的键值冲突
|
|
222
|
+
const count = context.count(entity, {
|
|
223
|
+
filter: (0, filter_1.combineFilters)(entity, context.getSchema(), [filter, {
|
|
224
|
+
$not: operationFilter,
|
|
225
|
+
}]),
|
|
226
|
+
}, { dontCollect: true });
|
|
227
|
+
const checkCount = checkCountLessThan(count, uniqAttrs, 0, operationFilter?.id);
|
|
228
|
+
// 更新的行只能有一行
|
|
229
|
+
const rowCount = context.count(entity, {
|
|
230
|
+
filter: operationFilter,
|
|
231
|
+
}, { dontCollect: true });
|
|
232
|
+
const checkRowCount = checkCountLessThan(rowCount, uniqAttrs, 1, operationFilter?.id);
|
|
233
|
+
// 如果更新的行数为零似乎也可以,但这应该不可能出现吧,by Xc 20230131
|
|
234
|
+
if (checkRowCount instanceof Promise) {
|
|
235
|
+
return Promise.all([checkCount, checkRowCount]).then(() => undefined);
|
|
236
|
+
}
|
|
262
237
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
238
|
+
// 否则需要结合本行现有的属性来进行检查
|
|
239
|
+
const projection = { id: 1 };
|
|
240
|
+
for (const attr of uniqAttrs) {
|
|
241
|
+
Object.assign(projection, {
|
|
242
|
+
[attr]: 1,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
const checkWithRows = (rows2) => {
|
|
246
|
+
const rows22 = rows2.map(ele => Object.assign(ele, data));
|
|
247
|
+
// 先检查这些行本身之间是否冲突
|
|
248
|
+
checkUniqueBetweenRows(rows22, uniqAttrs);
|
|
249
|
+
const checkResults = rows22.map((row) => checkUnique(entity, row, context, uniqAttrs, {
|
|
250
|
+
$not: operationFilter
|
|
251
|
+
}));
|
|
252
|
+
if (checkResults[0] instanceof Promise) {
|
|
253
|
+
return Promise.all(checkResults).then(() => undefined);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
const currentRows = context.select(entity, {
|
|
257
|
+
data: projection,
|
|
277
258
|
filter: operationFilter,
|
|
278
259
|
}, { dontCollect: true });
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
if (checkRowCount instanceof Promise) {
|
|
282
|
-
return Promise.all([checkCount, checkRowCount]).then(function () { return undefined; });
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
// 否则需要结合本行现有的属性来进行检查
|
|
286
|
-
var projection = { id: 1 };
|
|
287
|
-
try {
|
|
288
|
-
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()) {
|
|
289
|
-
var attr = uniqAttrs_3_1.value;
|
|
290
|
-
Object.assign(projection, (_c = {},
|
|
291
|
-
_c[attr] = 1,
|
|
292
|
-
_c));
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
296
|
-
finally {
|
|
297
|
-
try {
|
|
298
|
-
if (uniqAttrs_3_1 && !uniqAttrs_3_1.done && (_b = uniqAttrs_3.return)) _b.call(uniqAttrs_3);
|
|
260
|
+
if (currentRows instanceof Promise) {
|
|
261
|
+
return currentRows.then((row2) => checkWithRows(row2));
|
|
299
262
|
}
|
|
300
|
-
|
|
263
|
+
return checkWithRows(currentRows);
|
|
301
264
|
}
|
|
302
|
-
var checkWithRows = function (rows2) {
|
|
303
|
-
var rows22 = rows2.map(function (ele) { return Object.assign(ele, data); });
|
|
304
|
-
// 先检查这些行本身之间是否冲突
|
|
305
|
-
checkUniqueBetweenRows(rows22, uniqAttrs_2);
|
|
306
|
-
var checkResults = rows22.map(function (row) { return checkUnique(entity, row, context, uniqAttrs_2, {
|
|
307
|
-
$not: operationFilter
|
|
308
|
-
}); });
|
|
309
|
-
if (checkResults[0] instanceof Promise) {
|
|
310
|
-
return Promise.all(checkResults).then(function () { return undefined; });
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
var currentRows = context.select(entity, {
|
|
314
|
-
data: projection,
|
|
315
|
-
filter: operationFilter,
|
|
316
|
-
}, { dontCollect: true });
|
|
317
|
-
if (currentRows instanceof Promise) {
|
|
318
|
-
return currentRows.then(function (row2) { return checkWithRows(row2); });
|
|
319
|
-
}
|
|
320
|
-
return checkWithRows(currentRows);
|
|
321
265
|
}
|
|
322
266
|
});
|
|
323
267
|
}
|
|
324
|
-
};
|
|
325
|
-
try {
|
|
326
|
-
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()) {
|
|
327
|
-
var index = indexes_1_1.value;
|
|
328
|
-
_loop_4(index);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
332
|
-
finally {
|
|
333
|
-
try {
|
|
334
|
-
if (indexes_1_1 && !indexes_1_1.done && (_e = indexes_1.return)) _e.call(indexes_1);
|
|
335
|
-
}
|
|
336
|
-
finally { if (e_3) throw e_3.error; }
|
|
337
268
|
}
|
|
338
269
|
}
|
|
339
|
-
};
|
|
340
|
-
// unique索引相应的checker
|
|
341
|
-
for (var entity in schema) {
|
|
342
|
-
_loop_2(entity);
|
|
343
270
|
}
|
|
344
|
-
triggers.push
|
|
271
|
+
triggers.push(...actionAuth_1.triggers);
|
|
345
272
|
return {
|
|
346
|
-
triggers
|
|
347
|
-
checkers
|
|
273
|
+
triggers,
|
|
274
|
+
checkers,
|
|
348
275
|
watchers: makeIntrinsicWatchers(schema),
|
|
349
276
|
};
|
|
350
277
|
}
|