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.
Files changed (157) hide show
  1. package/lib/actions/action.d.ts +8 -8
  2. package/lib/actions/action.js +2 -2
  3. package/lib/actions/relation.d.ts +1 -1
  4. package/lib/actions/relation.js +9 -22
  5. package/lib/base-app-domain/ActionAuth/Schema.d.ts +68 -42
  6. package/lib/base-app-domain/ActionAuth/Storage.js +12 -15
  7. package/lib/base-app-domain/ActionDefDict.d.ts +2 -3
  8. package/lib/base-app-domain/ActionDefDict.js +3 -5
  9. package/lib/base-app-domain/EntityDict.d.ts +5 -1
  10. package/lib/base-app-domain/I18n/Schema.d.ts +24 -24
  11. package/lib/base-app-domain/I18n/Storage.js +5 -5
  12. package/lib/base-app-domain/Modi/Action.d.ts +4 -4
  13. package/lib/base-app-domain/Modi/Action.js +3 -3
  14. package/lib/base-app-domain/Modi/Schema.d.ts +24 -24
  15. package/lib/base-app-domain/Modi/Storage.js +3 -3
  16. package/lib/base-app-domain/ModiEntity/Schema.d.ts +128 -55
  17. package/lib/base-app-domain/ModiEntity/Storage.js +2 -2
  18. package/lib/base-app-domain/Oper/Schema.d.ts +30 -29
  19. package/lib/base-app-domain/Oper/Storage.js +1 -1
  20. package/lib/base-app-domain/OperEntity/Schema.d.ts +126 -53
  21. package/lib/base-app-domain/OperEntity/Storage.js +2 -2
  22. package/lib/base-app-domain/Path/Schema.d.ts +149 -0
  23. package/lib/base-app-domain/Path/Schema.js +2 -0
  24. package/lib/base-app-domain/Path/Storage.d.ts +3 -0
  25. package/lib/base-app-domain/Path/Storage.js +54 -0
  26. package/lib/base-app-domain/Relation/Schema.d.ts +34 -34
  27. package/lib/base-app-domain/Relation/Storage.js +6 -6
  28. package/lib/base-app-domain/Relation.d.ts +0 -8
  29. package/lib/base-app-domain/Relation.js +1 -7
  30. package/lib/base-app-domain/RelationAuth/Schema.d.ts +74 -40
  31. package/lib/base-app-domain/RelationAuth/Storage.js +9 -11
  32. package/lib/base-app-domain/Storage.js +20 -16
  33. package/lib/base-app-domain/User/Action.d.ts +4 -4
  34. package/lib/base-app-domain/User/Action.js +3 -3
  35. package/lib/base-app-domain/User/Schema.d.ts +40 -27
  36. package/lib/base-app-domain/User/Storage.js +1 -1
  37. package/lib/base-app-domain/UserEntityClaim/Schema.d.ts +264 -0
  38. package/lib/base-app-domain/UserEntityClaim/Schema.js +2 -0
  39. package/lib/base-app-domain/UserEntityClaim/Storage.d.ts +3 -0
  40. package/lib/base-app-domain/UserEntityClaim/Storage.js +37 -0
  41. package/lib/base-app-domain/UserEntityGrant/Action.d.ts +2 -2
  42. package/lib/base-app-domain/UserEntityGrant/Schema.d.ts +55 -81
  43. package/lib/base-app-domain/UserEntityGrant/Storage.js +7 -11
  44. package/lib/base-app-domain/UserRelation/Schema.d.ts +50 -36
  45. package/lib/base-app-domain/UserRelation/Storage.js +7 -7
  46. package/lib/base-app-domain/_SubQuery.d.ts +45 -15
  47. package/lib/base-app-domain/index.js +1 -1
  48. package/lib/checkers/index.js +6 -7
  49. package/lib/compiler/env.js +16 -18
  50. package/lib/compiler/localeBuilder.js +83 -79
  51. package/lib/compiler/schemalBuilder.d.ts +16 -0
  52. package/lib/compiler/schemalBuilder.js +1160 -1378
  53. package/lib/entities/ActionAuth.d.ts +3 -5
  54. package/lib/entities/ActionAuth.js +9 -7
  55. package/lib/entities/I18n.js +1 -1
  56. package/lib/entities/Modi.js +2 -2
  57. package/lib/entities/ModiEntity.js +1 -1
  58. package/lib/entities/Oper.js +1 -1
  59. package/lib/entities/OperEntity.js +1 -1
  60. package/lib/entities/Path.d.ts +8 -0
  61. package/lib/entities/Path.js +35 -0
  62. package/lib/entities/Relation.js +1 -1
  63. package/lib/entities/RelationAuth.d.ts +2 -2
  64. package/lib/entities/RelationAuth.js +1 -1
  65. package/lib/entities/User.js +2 -2
  66. package/lib/entities/UserEntityClaim.d.ts +13 -0
  67. package/lib/entities/UserEntityClaim.js +17 -0
  68. package/lib/entities/UserEntityGrant.d.ts +5 -4
  69. package/lib/entities/UserEntityGrant.js +4 -7
  70. package/lib/entities/UserRelation.js +1 -1
  71. package/lib/index.d.ts +23 -0
  72. package/lib/index.js +37 -0
  73. package/lib/store/AsyncRowStore.d.ts +2 -1
  74. package/lib/store/AsyncRowStore.js +75 -149
  75. package/lib/store/CascadeStore.js +968 -1341
  76. package/lib/store/RelationAuth.d.ts +9 -16
  77. package/lib/store/RelationAuth.js +752 -910
  78. package/lib/store/SyncRowStore.d.ts +1 -1
  79. package/lib/store/SyncRowStore.js +27 -26
  80. package/lib/store/TriggerExecutor.d.ts +17 -10
  81. package/lib/store/TriggerExecutor.js +350 -423
  82. package/lib/store/actionAuth.js +13 -28
  83. package/lib/store/actionDef.js +142 -215
  84. package/lib/store/checker.js +225 -361
  85. package/lib/store/filter.d.ts +2 -3
  86. package/lib/store/filter.js +451 -589
  87. package/lib/store/modi.js +116 -177
  88. package/lib/store/relation.js +17 -17
  89. package/lib/timers/oper.d.ts +1 -1
  90. package/lib/timers/oper.js +44 -47
  91. package/lib/timers/vaccum.d.ts +2 -2
  92. package/lib/timers/vaccum.js +100 -165
  93. package/lib/triggers/index.js +1 -1
  94. package/lib/types/Action.d.ts +7 -7
  95. package/lib/types/AppLoader.d.ts +8 -2
  96. package/lib/types/AppLoader.js +4 -4
  97. package/lib/types/Auth.d.ts +15 -19
  98. package/lib/types/Connector.d.ts +19 -14
  99. package/lib/types/Connector.js +0 -7
  100. package/lib/types/DataType.d.ts +19 -18
  101. package/lib/types/DataType.js +1 -1
  102. package/lib/types/Demand.d.ts +25 -25
  103. package/lib/types/Endpoint.d.ts +1 -1
  104. package/lib/types/Entity.d.ts +62 -53
  105. package/lib/types/Entity.js +4 -3
  106. package/lib/types/EntityDesc.d.ts +2 -1
  107. package/lib/types/Environment.d.ts +4 -4
  108. package/lib/types/Exception.d.ts +34 -2
  109. package/lib/types/Exception.js +214 -197
  110. package/lib/types/Expression.d.ts +14 -14
  111. package/lib/types/Expression.js +54 -87
  112. package/lib/types/Geo.d.ts +6 -6
  113. package/lib/types/Locale.d.ts +5 -5
  114. package/lib/types/Polyfill.d.ts +9 -9
  115. package/lib/types/Port.d.ts +4 -4
  116. package/lib/types/RowStore.d.ts +3 -3
  117. package/lib/types/RowStore.js +18 -19
  118. package/lib/types/Storage.d.ts +5 -4
  119. package/lib/types/Style.d.ts +2 -2
  120. package/lib/types/Timer.d.ts +3 -3
  121. package/lib/types/Trigger.d.ts +30 -14
  122. package/lib/types/Trigger.js +6 -2
  123. package/lib/types/Watcher.d.ts +2 -2
  124. package/lib/types/index.d.ts +1 -0
  125. package/lib/types/index.js +2 -1
  126. package/lib/types/schema/DataTypes.d.ts +7 -7
  127. package/lib/utils/SimpleConnector.d.ts +26 -10
  128. package/lib/utils/SimpleConnector.js +167 -141
  129. package/lib/utils/assert.js +2 -2
  130. package/lib/utils/concurrent.d.ts +1 -1
  131. package/lib/utils/concurrent.js +31 -57
  132. package/lib/utils/date.js +2 -2
  133. package/lib/utils/geo.js +8 -8
  134. package/lib/utils/lodash.d.ts +3 -1
  135. package/lib/utils/lodash.js +21 -34
  136. package/lib/utils/mask.js +12 -13
  137. package/lib/utils/money.d.ts +1 -1
  138. package/lib/utils/money.js +22 -11
  139. package/lib/utils/projection.d.ts +4 -0
  140. package/lib/utils/projection.js +15 -0
  141. package/lib/utils/random/random.js +11 -16
  142. package/lib/utils/random/random.mp.js +7 -18
  143. package/lib/utils/random/random.web.js +6 -12
  144. package/lib/utils/string.d.ts +4 -4
  145. package/lib/utils/string.js +19 -32
  146. package/lib/utils/url.js +5 -4
  147. package/lib/utils/uuid.d.ts +1 -1
  148. package/lib/utils/uuid.js +46 -85
  149. package/lib/utils/validator.d.ts +4 -3
  150. package/lib/utils/validator.js +35 -32
  151. package/lib/utils/version.js +6 -6
  152. package/package.json +7 -7
  153. package/src/entities/ActionAuth.ts +10 -10
  154. package/src/entities/Path.ts +43 -0
  155. package/src/entities/RelationAuth.ts +2 -1
  156. package/src/entities/UserEntityClaim.ts +30 -0
  157. package/src/entities/UserEntityGrant.ts +9 -12
@@ -1,39 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.triggers = void 0;
4
- var tslib_1 = require("tslib");
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: function (_a, context, option) {
12
- var operation = _a.operation;
13
- return tslib_1.__awaiter(void 0, void 0, void 0, function () {
14
- var data, filter, _b, _c, _d;
15
- var _e;
16
- return tslib_1.__generator(this, function (_f) {
17
- switch (_f.label) {
18
- case 0:
19
- data = operation.data, filter = operation.filter;
20
- if (!(data.deActions && data.deActions.length === 0)) return [3 /*break*/, 3];
21
- _c = (_b = context).operate;
22
- _d = ['actionAuth'];
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
  }
@@ -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
- var tslib_1 = require("tslib");
5
- var types_1 = require("../types");
6
- var lodash_1 = require("../utils/lodash");
7
- var filter_1 = require("./filter");
8
- var checkers_1 = require("../checkers");
9
- var triggers_1 = require("../triggers");
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
- var attributes = schema[entity].attributes;
13
- var projection = {
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(function (k) {
20
- var _a;
21
- return Object.assign(projection, (_a = {},
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
- var watchers = [];
30
- for (var entity in schema) {
31
- var attributes = schema[entity].attributes;
32
- var expiresAt = attributes.expiresAt, expired = attributes.expired;
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: entity,
37
- name: "\u5BF9\u8C61".concat(entity, "\u4E0A\u7684\u8FC7\u671F\u81EA\u52A8watcher"),
38
- filter: function () {
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
- var dict = {};
59
- try {
60
- for (var rows_1 = tslib_1.__values(rows), rows_1_1 = rows_1.next(); !rows_1_1.done; rows_1_1 = rows_1.next()) {
61
- var row = rows_1_1.value;
62
- var s = '';
63
- try {
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
- dict[s] = 1;
61
+ s + `-${row[a]}`;
89
62
  }
90
63
  }
91
- }
92
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
93
- finally {
94
- try {
95
- if (rows_1_1 && !rows_1_1.done && (_a = rows_1.return)) _a.call(rows_1);
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(function (count2) {
77
+ return count.then((count2) => {
104
78
  if (count2 > than) {
105
79
  throw new types_1.OakUniqueViolationException([{
106
- id: 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: id,
88
+ id,
115
89
  attrs: uniqAttrs,
116
90
  }]);
117
91
  }
118
92
  }
119
93
  function checkUnique(entity, row, context, uniqAttrs, extraFilter) {
120
- var filter = (0, lodash_1.pick)(row, uniqAttrs);
121
- for (var a in filter) {
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
- var filter2 = extraFilter ? (0, filter_1.combineFilters)(entity, context.getSchema(), [filter, extraFilter]) : filter;
131
- var count = context.count(entity, { filter: filter2 }, { dontCollect: true });
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
- var _a;
136
- var checkers = (0, checkers_1.createDynamicCheckers)(schema);
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 (var entity in actionDefDict) {
140
- var _loop_1 = function (attr) {
141
- var def = actionDefDict[entity][attr];
142
- var _b = def, stm = _b.stm, is = _b.is;
143
- var _loop_3 = function (action) {
144
- var _c, _d;
145
- var actionStm = stm[action];
146
- var conditionalFilter = typeof actionStm[0] === 'string' ? (_c = {},
147
- _c[attr] = actionStm[0],
148
- _c) : (_d = {},
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
- _d);
124
+ };
153
125
  checkers.push({
154
126
  action: action,
155
127
  type: 'row',
156
- entity: 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: entity,
165
- checker: function (data) {
166
- var _a;
167
- Object.assign(data, (_a = {},
168
- _a[attr] = stm[action][1],
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: entity,
148
+ entity,
181
149
  priority: 10,
182
- checker: function (data) {
183
- var _a;
150
+ checker: (data) => {
184
151
  if (data instanceof Array) {
185
- data.forEach(function (ele) {
186
- var _a;
152
+ data.forEach(ele => {
187
153
  if (!ele[attr]) {
188
- Object.assign(ele, (_a = {},
189
- _a[attr] = is,
190
- _a));
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, (_a = {},
197
- _a[attr] = is,
198
- _a));
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
- var _loop_2 = function (entity) {
210
- var e_3, _e;
211
- var indexes = schema[entity].indexes;
172
+ // unique索引相应的checker
173
+ for (const entity in schema) {
174
+ const { indexes } = schema[entity];
212
175
  if (indexes) {
213
- var _loop_4 = function (index) {
214
- if ((_a = index.config) === null || _a === void 0 ? void 0 : _a.unique) {
215
- var attributes = index.attributes;
216
- var uniqAttrs_2 = attributes.map(function (ele) { return ele.name; });
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: entity,
181
+ entity,
219
182
  action: 'create',
220
- type: 'logical',
183
+ type: 'logicalData',
221
184
  priority: types_1.CHECKER_MAX_PRIORITY,
222
- checker: function (operation, context) {
223
- var data = operation.data;
185
+ checker: (operation, context) => {
186
+ const { data } = operation;
224
187
  if (data instanceof Array) {
225
- checkUniqueBetweenRows(data, uniqAttrs_2);
226
- var checkResult = data.map(function (ele) { return checkUnique(entity, ele, context, uniqAttrs_2); });
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(function () { return undefined; });
191
+ return Promise.all(checkResult).then(() => undefined);
229
192
  }
230
193
  }
231
- else {
232
- return checkUnique(entity, data, context, uniqAttrs_2);
194
+ else if (data) {
195
+ return checkUnique(entity, data, context, uniqAttrs);
233
196
  }
234
197
  }
235
198
  }, {
236
- entity: entity,
199
+ entity,
237
200
  action: 'update',
238
- type: 'logical',
201
+ type: 'logicalData',
239
202
  priority: types_1.CHECKER_MAX_PRIORITY,
240
- checker: function (operation, context) {
241
- var e_4, _a, e_5, _b, _c;
242
- var _d = operation, data = _d.data, operationFilter = _d.filter;
243
- var attrs = Object.keys(data);
244
- var refAttrs = (0, lodash_1.intersection)(attrs, uniqAttrs_2);
245
- if (refAttrs.length === 0) {
246
- // 如果本次更新和unique约束的属性之间没有交集则直接返回
247
- return;
248
- }
249
- try {
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
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
259
- finally {
260
- try {
261
- if (refAttrs_1_1 && !refAttrs_1_1.done && (_a = refAttrs_1.return)) _a.call(refAttrs_1);
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
- finally { if (e_4) throw e_4.error; }
264
- }
265
- if (refAttrs.length === uniqAttrs_2.length) {
266
- // 如果更新了全部属性,直接检查
267
- var filter = (0, lodash_1.pick)(data, refAttrs);
268
- // 在这些行以外的行不和更新后的键值冲突
269
- var count = context.count(entity, {
270
- filter: (0, filter_1.combineFilters)(entity, context.getSchema(), [filter, {
271
- $not: operationFilter,
272
- }]),
273
- }, { dontCollect: true });
274
- var checkCount = checkCountLessThan(count, uniqAttrs_2, 0, operationFilter === null || operationFilter === void 0 ? void 0 : operationFilter.id);
275
- // 更新的行只能有一行
276
- var rowCount = context.count(entity, {
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
- var checkRowCount = checkCountLessThan(rowCount, uniqAttrs_2, 1, operationFilter === null || operationFilter === void 0 ? void 0 : operationFilter.id);
280
- // 如果更新的行数为零似乎也可以,但这应该不可能出现吧,by Xc 20230131
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
- finally { if (e_5) throw e_5.error; }
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.apply(triggers, tslib_1.__spreadArray([], tslib_1.__read(actionAuth_1.triggers), false));
271
+ triggers.push(...actionAuth_1.triggers);
345
272
  return {
346
- triggers: triggers,
347
- checkers: checkers,
273
+ triggers,
274
+ checkers,
348
275
  watchers: makeIntrinsicWatchers(schema),
349
276
  };
350
277
  }