oak-domain 2.5.2 → 2.6.2

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 (171) hide show
  1. package/lib/actions/action.d.ts +16 -16
  2. package/lib/actions/action.js +17 -17
  3. package/lib/actions/relation.d.ts +5 -5
  4. package/lib/actions/relation.js +38 -38
  5. package/lib/base-app-domain/ActionDefDict.d.ts +8 -8
  6. package/lib/base-app-domain/ActionDefDict.js +9 -9
  7. package/lib/base-app-domain/EntityDict.d.ts +14 -14
  8. package/lib/base-app-domain/EntityDict.js +2 -2
  9. package/lib/base-app-domain/Modi/Action.d.ts +10 -10
  10. package/lib/base-app-domain/Modi/Action.js +14 -14
  11. package/lib/base-app-domain/Modi/Schema.d.ts +146 -146
  12. package/lib/base-app-domain/Modi/Schema.js +2 -2
  13. package/lib/base-app-domain/Modi/Storage.d.ts +3 -3
  14. package/lib/base-app-domain/Modi/Storage.js +60 -60
  15. package/lib/base-app-domain/ModiEntity/Schema.d.ts +189 -189
  16. package/lib/base-app-domain/ModiEntity/Schema.js +2 -2
  17. package/lib/base-app-domain/ModiEntity/Storage.d.ts +3 -3
  18. package/lib/base-app-domain/ModiEntity/Storage.js +27 -27
  19. package/lib/base-app-domain/Oper/Schema.d.ts +144 -144
  20. package/lib/base-app-domain/Oper/Schema.js +2 -2
  21. package/lib/base-app-domain/Oper/Storage.d.ts +3 -3
  22. package/lib/base-app-domain/Oper/Storage.js +29 -29
  23. package/lib/base-app-domain/OperEntity/Schema.d.ts +205 -205
  24. package/lib/base-app-domain/OperEntity/Schema.js +2 -2
  25. package/lib/base-app-domain/OperEntity/Storage.d.ts +3 -3
  26. package/lib/base-app-domain/OperEntity/Storage.js +27 -27
  27. package/lib/base-app-domain/Storage.d.ts +3 -3
  28. package/lib/base-app-domain/Storage.js +17 -17
  29. package/lib/base-app-domain/User/Action.d.ts +10 -10
  30. package/lib/base-app-domain/User/Action.js +12 -12
  31. package/lib/base-app-domain/User/Schema.d.ts +180 -180
  32. package/lib/base-app-domain/User/Schema.js +2 -2
  33. package/lib/base-app-domain/User/Storage.d.ts +3 -3
  34. package/lib/base-app-domain/User/Storage.js +36 -36
  35. package/lib/base-app-domain/UserEntityGrant/Schema.d.ts +121 -121
  36. package/lib/base-app-domain/UserEntityGrant/Schema.js +2 -2
  37. package/lib/base-app-domain/UserEntityGrant/Storage.d.ts +3 -3
  38. package/lib/base-app-domain/UserEntityGrant/Storage.js +28 -28
  39. package/lib/base-app-domain/_SubQuery.d.ts +44 -44
  40. package/lib/base-app-domain/_SubQuery.js +2 -2
  41. package/lib/base-app-domain/index.d.ts +3 -3
  42. package/lib/base-app-domain/index.js +6 -6
  43. package/lib/checkers/index.d.ts +5 -5
  44. package/lib/checkers/index.js +16 -16
  45. package/lib/compiler/env.d.ts +11 -11
  46. package/lib/compiler/env.js +39 -39
  47. package/lib/compiler/schemalBuilder.d.ts +2 -2
  48. package/lib/compiler/schemalBuilder.js +3355 -3355
  49. package/lib/compiler/uiBuilder.d.ts +1 -1
  50. package/lib/compiler/uiBuilder.js +3 -3
  51. package/lib/entities/Modi.d.ts +11 -11
  52. package/lib/entities/Modi.js +46 -46
  53. package/lib/entities/ModiEntity.d.ts +8 -8
  54. package/lib/entities/ModiEntity.js +15 -15
  55. package/lib/entities/Oper.d.ts +10 -10
  56. package/lib/entities/Oper.js +17 -17
  57. package/lib/entities/OperEntity.d.ts +8 -8
  58. package/lib/entities/OperEntity.js +15 -15
  59. package/lib/entities/User.d.ts +8 -8
  60. package/lib/entities/User.js +28 -28
  61. package/lib/entities/UserEntityGrant.d.ts +7 -7
  62. package/lib/entities/UserEntityGrant.js +12 -12
  63. package/lib/store/AsyncRowStore.d.ts +51 -48
  64. package/lib/store/AsyncRowStore.js +189 -183
  65. package/lib/store/CascadeStore.d.ts +91 -91
  66. package/lib/store/CascadeStore.js +1634 -1603
  67. package/lib/store/SyncRowStore.d.ts +29 -29
  68. package/lib/store/SyncRowStore.js +48 -48
  69. package/lib/store/TriggerExecutor.d.ts +32 -32
  70. package/lib/store/TriggerExecutor.js +532 -532
  71. package/lib/store/actionDef.d.ts +9 -9
  72. package/lib/store/actionDef.js +333 -333
  73. package/lib/store/checker.d.ts +26 -26
  74. package/lib/store/checker.js +829 -867
  75. package/lib/store/filter.d.ts +109 -109
  76. package/lib/store/filter.js +893 -893
  77. package/lib/store/modi.d.ts +13 -13
  78. package/lib/store/modi.js +216 -216
  79. package/lib/store/relation.d.ts +13 -13
  80. package/lib/store/relation.js +66 -66
  81. package/lib/store/selection.d.ts +19 -7
  82. package/lib/store/selection.js +265 -238
  83. package/lib/triggers/index.d.ts +6 -6
  84. package/lib/triggers/index.js +11 -11
  85. package/lib/triggers/modi.d.ts +5 -5
  86. package/lib/triggers/modi.js +72 -72
  87. package/lib/types/Action.d.ts +20 -20
  88. package/lib/types/Action.js +2 -2
  89. package/lib/types/AppLoader.d.ts +11 -11
  90. package/lib/types/AppLoader.js +10 -10
  91. package/lib/types/Aspect.d.ts +13 -12
  92. package/lib/types/Aspect.js +4 -4
  93. package/lib/types/Auth.d.ts +69 -69
  94. package/lib/types/Auth.js +2 -2
  95. package/lib/types/Connector.d.ts +27 -26
  96. package/lib/types/Connector.js +9 -9
  97. package/lib/types/Context.d.ts +7 -7
  98. package/lib/types/Context.js +3 -3
  99. package/lib/types/DataType.d.ts +18 -18
  100. package/lib/types/DataType.js +5 -5
  101. package/lib/types/Demand.d.ts +77 -77
  102. package/lib/types/Demand.js +9 -9
  103. package/lib/types/Endpoint.d.ts +11 -11
  104. package/lib/types/Endpoint.js +3 -3
  105. package/lib/types/Entity.d.ts +183 -183
  106. package/lib/types/Entity.js +14 -14
  107. package/lib/types/Exception.d.ts +100 -98
  108. package/lib/types/Exception.js +327 -283
  109. package/lib/types/Expression.d.ts +163 -163
  110. package/lib/types/Expression.js +427 -427
  111. package/lib/types/Geo.d.ts +18 -18
  112. package/lib/types/Geo.js +2 -2
  113. package/lib/types/Locale.d.ts +24 -24
  114. package/lib/types/Locale.js +2 -2
  115. package/lib/types/Logger.d.ts +5 -5
  116. package/lib/types/Logger.js +3 -3
  117. package/lib/types/Polyfill.d.ts +23 -23
  118. package/lib/types/Polyfill.js +2 -2
  119. package/lib/types/Port.d.ts +17 -17
  120. package/lib/types/Port.js +2 -2
  121. package/lib/types/RowStore.d.ts +12 -12
  122. package/lib/types/RowStore.js +34 -34
  123. package/lib/types/Storage.d.ts +56 -56
  124. package/lib/types/Storage.js +2 -2
  125. package/lib/types/Timer.d.ts +13 -13
  126. package/lib/types/Timer.js +2 -2
  127. package/lib/types/Trigger.d.ts +109 -109
  128. package/lib/types/Trigger.js +49 -49
  129. package/lib/types/Txn.d.ts +2 -2
  130. package/lib/types/Txn.js +3 -3
  131. package/lib/types/Watcher.d.ts +19 -19
  132. package/lib/types/Watcher.js +4 -4
  133. package/lib/types/index.d.ts +21 -21
  134. package/lib/types/index.js +24 -24
  135. package/lib/types/schema/DataTypes.d.ts +32 -32
  136. package/lib/types/schema/DataTypes.js +3 -3
  137. package/lib/utils/SimpleConnector.d.ts +35 -30
  138. package/lib/utils/SimpleConnector.js +134 -117
  139. package/lib/utils/assert.d.ts +5 -5
  140. package/lib/utils/assert.js +9 -9
  141. package/lib/utils/concurrent.d.ts +15 -15
  142. package/lib/utils/concurrent.js +89 -89
  143. package/lib/utils/cron.d.ts +1 -1
  144. package/lib/utils/cron.js +18 -18
  145. package/lib/utils/date.d.ts +1 -1
  146. package/lib/utils/date.js +18 -18
  147. package/lib/utils/geo.d.ts +4 -4
  148. package/lib/utils/geo.js +24 -24
  149. package/lib/utils/lodash.d.ts +20 -20
  150. package/lib/utils/lodash.js +55 -55
  151. package/lib/utils/random/random.d.ts +1 -1
  152. package/lib/utils/random/random.js +24 -24
  153. package/lib/utils/random/random.mp.d.ts +1 -1
  154. package/lib/utils/random/random.mp.js +25 -25
  155. package/lib/utils/random/random.web.d.ts +1 -1
  156. package/lib/utils/random/random.web.js +17 -17
  157. package/lib/utils/string.d.ts +22 -22
  158. package/lib/utils/string.js +70 -70
  159. package/lib/utils/url.d.ts +1 -0
  160. package/lib/utils/url.js +12 -0
  161. package/lib/utils/uuid.d.ts +12 -12
  162. package/lib/utils/uuid.js +194 -194
  163. package/lib/utils/validator.d.ts +23 -23
  164. package/lib/utils/validator.js +123 -123
  165. package/package.json +48 -48
  166. package/src/entities/Modi.ts +68 -68
  167. package/src/entities/ModiEntity.ts +24 -24
  168. package/src/entities/Oper.ts +28 -28
  169. package/src/entities/OperEntity.ts +24 -24
  170. package/src/entities/User.ts +44 -44
  171. package/src/entities/UserEntityGrant.ts +24 -24
@@ -1,13 +1,13 @@
1
- import { EntityDict as BaseEntityDict } from '../base-app-domain';
2
- import { OpSchema as Modi } from '../base-app-domain/Modi/Schema';
3
- import { Operation, StorageSchema, RowChecker, EntityDict, OperateOption, Trigger } from '../types';
4
- import { AsyncContext } from './AsyncRowStore';
5
- import { SyncContext } from './SyncRowStore';
6
- export declare function createOperationsFromModies(modies: Modi[]): Array<{
7
- operation: Operation<string, Object, Object>;
8
- entity: string;
9
- }>;
10
- export declare function applyModis<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>, Op extends OperateOption>(filter: ED['modi']['Selection']['filter'], context: Cxt, option: Op): Promise<import("../types").OperationResult<ED>>;
11
- export declare function abandonModis<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>, Op extends OperateOption>(filter: ED['modi']['Selection']['filter'], context: Cxt, option: Op): Promise<import("../types").OperationResult<ED>>;
12
- export declare function createModiRelatedCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>): RowChecker<ED, keyof ED, Cxt>[];
13
- export declare function createModiRelatedTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>>(schema: StorageSchema<ED>): Trigger<ED, keyof ED, Cxt>[];
1
+ import { EntityDict as BaseEntityDict } from '../base-app-domain';
2
+ import { OpSchema as Modi } from '../base-app-domain/Modi/Schema';
3
+ import { Operation, StorageSchema, RowChecker, EntityDict, OperateOption, Trigger } from '../types';
4
+ import { AsyncContext } from './AsyncRowStore';
5
+ import { SyncContext } from './SyncRowStore';
6
+ export declare function createOperationsFromModies(modies: Modi[]): Array<{
7
+ operation: Operation<string, Object, Object>;
8
+ entity: string;
9
+ }>;
10
+ export declare function applyModis<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>, Op extends OperateOption>(filter: ED['modi']['Selection']['filter'], context: Cxt, option: Op): Promise<import("../types").OperationResult<ED>>;
11
+ export declare function abandonModis<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>, Op extends OperateOption>(filter: ED['modi']['Selection']['filter'], context: Cxt, option: Op): Promise<import("../types").OperationResult<ED>>;
12
+ export declare function createModiRelatedCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>): RowChecker<ED, keyof ED, Cxt>[];
13
+ export declare function createModiRelatedTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>>(schema: StorageSchema<ED>): Trigger<ED, keyof ED, Cxt>[];
package/lib/store/modi.js CHANGED
@@ -1,216 +1,216 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createModiRelatedTriggers = exports.createModiRelatedCheckers = exports.abandonModis = exports.applyModis = exports.createOperationsFromModies = void 0;
4
- var tslib_1 = require("tslib");
5
- var types_1 = require("../types");
6
- var action_1 = require("../actions/action");
7
- var lodash_1 = require("../utils/lodash");
8
- var uuid_1 = require("../utils/uuid");
9
- var assert_1 = tslib_1.__importDefault(require("assert"));
10
- function createOperationsFromModies(modies) {
11
- return modies.map(function (modi) {
12
- return {
13
- entity: modi.targetEntity,
14
- operation: {
15
- id: modi.id,
16
- action: modi.action,
17
- data: modi.data,
18
- filter: modi.filter,
19
- }
20
- };
21
- });
22
- }
23
- exports.createOperationsFromModies = createOperationsFromModies;
24
- function applyModis(filter, context, option) {
25
- return tslib_1.__awaiter(this, void 0, void 0, function () {
26
- var _a, _b, _c;
27
- var _d;
28
- return tslib_1.__generator(this, function (_e) {
29
- switch (_e.label) {
30
- case 0:
31
- _b = (_a = context).operate;
32
- _c = ['modi'];
33
- _d = {};
34
- return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
35
- case 1: return [2 /*return*/, _b.apply(_a, _c.concat([(_d.id = _e.sent(),
36
- _d.action = 'apply',
37
- _d.data = {},
38
- _d.filter = filter,
39
- _d), Object.assign({}, option, {
40
- blockTrigger: false,
41
- })]))];
42
- }
43
- });
44
- });
45
- }
46
- exports.applyModis = applyModis;
47
- function abandonModis(filter, context, option) {
48
- return tslib_1.__awaiter(this, void 0, void 0, function () {
49
- var _a, _b, _c;
50
- var _d;
51
- return tslib_1.__generator(this, function (_e) {
52
- switch (_e.label) {
53
- case 0:
54
- _b = (_a = context).operate;
55
- _c = ['modi'];
56
- _d = {};
57
- return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
58
- case 1: return [2 /*return*/, _b.apply(_a, _c.concat([(_d.id = _e.sent(),
59
- _d.action = 'abandon',
60
- _d.data = {},
61
- _d.filter = filter,
62
- _d), Object.assign({}, option, {
63
- blockTrigger: false,
64
- })]))];
65
- }
66
- });
67
- });
68
- }
69
- exports.abandonModis = abandonModis;
70
- function createModiRelatedCheckers(schema) {
71
- var checkers = [];
72
- var _loop_1 = function (entity) {
73
- var _a = schema[entity], actionType = _a.actionType, actions = _a.actions, inModi = _a.inModi;
74
- if (!inModi || ['readOnly', 'appendOnly'].includes(actionType)) {
75
- return "continue";
76
- }
77
- var restActions = (0, lodash_1.difference)(actions, action_1.appendOnlyActions);
78
- checkers.push({
79
- entity: entity,
80
- action: restActions,
81
- type: 'row',
82
- filter: function (operation, context, option) {
83
- /**
84
- * 只有一种情况可以通过,即当前是在更新和active的modi所指向同一个父更新对象。
85
- * 比如:先申请了一个公司(company),再申请修改公司(companyApplyment),这时所有的active modi都指向此条companyApplyment
86
- * 这时:
87
- * 1)再申请一条新的修改公司(create companyApplyment),应被拒绝
88
- * 2)申请修改原来的companyApplyment(update companyApplyment),可以通过
89
- * 3)在其它路径上对此company对象进行直接的更新,应被拒绝
90
- */
91
- if (option.modiParentEntity) {
92
- var _a = option, modiParentEntity = _a.modiParentEntity, modiParentId = _a.modiParentId;
93
- (0, assert_1.default)(modiParentEntity);
94
- (0, assert_1.default)(modiParentId);
95
- return {
96
- id: {
97
- $nin: {
98
- entity: 'modiEntity',
99
- data: {
100
- entityId: 1,
101
- },
102
- filter: {
103
- entity: entity,
104
- modi: {
105
- iState: 'active',
106
- $or: [
107
- {
108
- entity: {
109
- $ne: modiParentEntity,
110
- },
111
- },
112
- {
113
- entityId: {
114
- $ne: modiParentId,
115
- },
116
- }
117
- ],
118
- },
119
- },
120
- },
121
- }
122
- };
123
- }
124
- return {
125
- id: {
126
- $nin: {
127
- entity: 'modiEntity',
128
- data: {
129
- entityId: 1,
130
- },
131
- filter: {
132
- entity: entity,
133
- modi: {
134
- iState: 'active',
135
- }
136
- },
137
- },
138
- }
139
- };
140
- },
141
- errMsg: '您请求的更新对象上还有正在申请的更新,请等该更新结束后再试',
142
- });
143
- };
144
- for (var entity in schema) {
145
- _loop_1(entity);
146
- }
147
- return checkers;
148
- }
149
- exports.createModiRelatedCheckers = createModiRelatedCheckers;
150
- function createModiRelatedTriggers(schema) {
151
- var _this = this;
152
- var triggers = [];
153
- var _loop_2 = function (entity) {
154
- var inModi = schema[entity].inModi;
155
- if (inModi) {
156
- // 当关联modi的对象被删除时,对应的modi也删除
157
- triggers.push({
158
- name: "\u5F53\u5220\u9664".concat(entity, "\u5BF9\u8C61\u65F6\uFF0C\u5220\u9664\u76F8\u5173\u8054\u7684modi\u7684modiEntity"),
159
- action: 'remove',
160
- entity: entity,
161
- when: 'after',
162
- priority: types_1.REMOVE_CASCADE_PRIORITY,
163
- fn: function (_a, context, option) {
164
- var operation = _a.operation;
165
- return tslib_1.__awaiter(_this, void 0, void 0, function () {
166
- var data, id, _b, _c, _d, _e, _f, _g;
167
- var _h, _j;
168
- return tslib_1.__generator(this, function (_k) {
169
- switch (_k.label) {
170
- case 0:
171
- data = operation.data;
172
- id = data.id;
173
- _c = (_b = context).operate;
174
- _d = ['modiEntity'];
175
- _h = {};
176
- return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
177
- case 1: return [4 /*yield*/, _c.apply(_b, _d.concat([(_h.id = _k.sent(),
178
- _h.action = 'remove',
179
- _h.data = {},
180
- _h.filter = {
181
- modi: {
182
- entity: entity,
183
- entityId: id,
184
- },
185
- },
186
- _h), { dontCollect: true }]))];
187
- case 2:
188
- _k.sent();
189
- _f = (_e = context).operate;
190
- _g = ['modi'];
191
- _j = {};
192
- return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
193
- case 3: return [4 /*yield*/, _f.apply(_e, _g.concat([(_j.id = _k.sent(),
194
- _j.action = 'remove',
195
- _j.data = {},
196
- _j.filter = {
197
- entity: entity,
198
- entityId: id,
199
- },
200
- _j), { dontCollect: true }]))];
201
- case 4:
202
- _k.sent();
203
- return [2 /*return*/, 0];
204
- }
205
- });
206
- });
207
- },
208
- });
209
- }
210
- };
211
- for (var entity in schema) {
212
- _loop_2(entity);
213
- }
214
- return triggers;
215
- }
216
- exports.createModiRelatedTriggers = createModiRelatedTriggers;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createModiRelatedTriggers = exports.createModiRelatedCheckers = exports.abandonModis = exports.applyModis = exports.createOperationsFromModies = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var types_1 = require("../types");
6
+ var action_1 = require("../actions/action");
7
+ var lodash_1 = require("../utils/lodash");
8
+ var uuid_1 = require("../utils/uuid");
9
+ var assert_1 = tslib_1.__importDefault(require("assert"));
10
+ function createOperationsFromModies(modies) {
11
+ return modies.map(function (modi) {
12
+ return {
13
+ entity: modi.targetEntity,
14
+ operation: {
15
+ id: modi.id,
16
+ action: modi.action,
17
+ data: modi.data,
18
+ filter: modi.filter,
19
+ }
20
+ };
21
+ });
22
+ }
23
+ exports.createOperationsFromModies = createOperationsFromModies;
24
+ function applyModis(filter, context, option) {
25
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
26
+ var _a, _b, _c;
27
+ var _d;
28
+ return tslib_1.__generator(this, function (_e) {
29
+ switch (_e.label) {
30
+ case 0:
31
+ _b = (_a = context).operate;
32
+ _c = ['modi'];
33
+ _d = {};
34
+ return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
35
+ case 1: return [2 /*return*/, _b.apply(_a, _c.concat([(_d.id = _e.sent(),
36
+ _d.action = 'apply',
37
+ _d.data = {},
38
+ _d.filter = filter,
39
+ _d), Object.assign({}, option, {
40
+ blockTrigger: false,
41
+ })]))];
42
+ }
43
+ });
44
+ });
45
+ }
46
+ exports.applyModis = applyModis;
47
+ function abandonModis(filter, context, option) {
48
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
49
+ var _a, _b, _c;
50
+ var _d;
51
+ return tslib_1.__generator(this, function (_e) {
52
+ switch (_e.label) {
53
+ case 0:
54
+ _b = (_a = context).operate;
55
+ _c = ['modi'];
56
+ _d = {};
57
+ return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
58
+ case 1: return [2 /*return*/, _b.apply(_a, _c.concat([(_d.id = _e.sent(),
59
+ _d.action = 'abandon',
60
+ _d.data = {},
61
+ _d.filter = filter,
62
+ _d), Object.assign({}, option, {
63
+ blockTrigger: false,
64
+ })]))];
65
+ }
66
+ });
67
+ });
68
+ }
69
+ exports.abandonModis = abandonModis;
70
+ function createModiRelatedCheckers(schema) {
71
+ var checkers = [];
72
+ var _loop_1 = function (entity) {
73
+ var _a = schema[entity], actionType = _a.actionType, actions = _a.actions, inModi = _a.inModi;
74
+ if (!inModi || ['readOnly', 'appendOnly'].includes(actionType)) {
75
+ return "continue";
76
+ }
77
+ var restActions = (0, lodash_1.difference)(actions, action_1.appendOnlyActions);
78
+ checkers.push({
79
+ entity: entity,
80
+ action: restActions,
81
+ type: 'row',
82
+ filter: function (operation, context, option) {
83
+ /**
84
+ * 只有一种情况可以通过,即当前是在更新和active的modi所指向同一个父更新对象。
85
+ * 比如:先申请了一个公司(company),再申请修改公司(companyApplyment),这时所有的active modi都指向此条companyApplyment
86
+ * 这时:
87
+ * 1)再申请一条新的修改公司(create companyApplyment),应被拒绝
88
+ * 2)申请修改原来的companyApplyment(update companyApplyment),可以通过
89
+ * 3)在其它路径上对此company对象进行直接的更新,应被拒绝
90
+ */
91
+ if (option.modiParentEntity) {
92
+ var _a = option, modiParentEntity = _a.modiParentEntity, modiParentId = _a.modiParentId;
93
+ (0, assert_1.default)(modiParentEntity);
94
+ (0, assert_1.default)(modiParentId);
95
+ return {
96
+ id: {
97
+ $nin: {
98
+ entity: 'modiEntity',
99
+ data: {
100
+ entityId: 1,
101
+ },
102
+ filter: {
103
+ entity: entity,
104
+ modi: {
105
+ iState: 'active',
106
+ $or: [
107
+ {
108
+ entity: {
109
+ $ne: modiParentEntity,
110
+ },
111
+ },
112
+ {
113
+ entityId: {
114
+ $ne: modiParentId,
115
+ },
116
+ }
117
+ ],
118
+ },
119
+ },
120
+ },
121
+ }
122
+ };
123
+ }
124
+ return {
125
+ id: {
126
+ $nin: {
127
+ entity: 'modiEntity',
128
+ data: {
129
+ entityId: 1,
130
+ },
131
+ filter: {
132
+ entity: entity,
133
+ modi: {
134
+ iState: 'active',
135
+ }
136
+ },
137
+ },
138
+ }
139
+ };
140
+ },
141
+ errMsg: '您请求的更新对象上还有正在申请的更新,请等该更新结束后再试',
142
+ });
143
+ };
144
+ for (var entity in schema) {
145
+ _loop_1(entity);
146
+ }
147
+ return checkers;
148
+ }
149
+ exports.createModiRelatedCheckers = createModiRelatedCheckers;
150
+ function createModiRelatedTriggers(schema) {
151
+ var _this = this;
152
+ var triggers = [];
153
+ var _loop_2 = function (entity) {
154
+ var inModi = schema[entity].inModi;
155
+ if (inModi) {
156
+ // 当关联modi的对象被删除时,对应的modi也删除。这里似乎只需要删除掉活跃对象?因为oper不能删除,所以oper和modi是必须要支持对deleted对象的容错?
157
+ // 这里没有想清楚,by Xc 20230209
158
+ triggers.push({
159
+ name: "\u5F53\u5220\u9664".concat(entity, "\u5BF9\u8C61\u65F6\uFF0C\u5220\u9664\u76F8\u5173\u8054\u7684modi\u7684modiEntity"),
160
+ action: 'remove',
161
+ entity: entity,
162
+ when: 'after',
163
+ priority: types_1.REMOVE_CASCADE_PRIORITY,
164
+ fn: function (_a, context, option) {
165
+ var operation = _a.operation;
166
+ return tslib_1.__awaiter(_this, void 0, void 0, function () {
167
+ var filter, _b, _c, _d, _e, _f, _g;
168
+ var _h, _j, _k, _l;
169
+ return tslib_1.__generator(this, function (_m) {
170
+ switch (_m.label) {
171
+ case 0:
172
+ filter = operation.filter;
173
+ _c = (_b = context).operate;
174
+ _d = ['modiEntity'];
175
+ _h = {};
176
+ return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
177
+ case 1: return [4 /*yield*/, _c.apply(_b, _d.concat([(_h.id = _m.sent(),
178
+ _h.action = 'remove',
179
+ _h.data = {},
180
+ _h.filter = {
181
+ modi: (_j = {},
182
+ _j[entity] = filter,
183
+ _j.iState = 'active',
184
+ _j),
185
+ },
186
+ _h), { dontCollect: true }]))];
187
+ case 2:
188
+ _m.sent();
189
+ _f = (_e = context).operate;
190
+ _g = ['modi'];
191
+ _k = {};
192
+ return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
193
+ case 3: return [4 /*yield*/, _f.apply(_e, _g.concat([(_k.id = _m.sent(),
194
+ _k.action = 'remove',
195
+ _k.data = {},
196
+ _k.filter = (_l = {},
197
+ _l[entity] = filter,
198
+ _l.iState = 'active',
199
+ _l),
200
+ _k), { dontCollect: true }]))];
201
+ case 4:
202
+ _m.sent();
203
+ return [2 /*return*/, 0];
204
+ }
205
+ });
206
+ });
207
+ },
208
+ });
209
+ }
210
+ };
211
+ for (var entity in schema) {
212
+ _loop_2(entity);
213
+ }
214
+ return triggers;
215
+ }
216
+ exports.createModiRelatedTriggers = createModiRelatedTriggers;
@@ -1,13 +1,13 @@
1
- import { EntityDef } from "../types/Entity";
2
- import { StorageSchema } from "../types/Storage";
3
- /**
4
- * 判断对象和属性之间的关系
5
- * @param schema
6
- * @param entity
7
- * @param attr
8
- * @param row
9
- * @returns
10
- */
11
- export declare function judgeRelation<ED extends {
12
- [E: string]: EntityDef;
13
- }>(schema: StorageSchema<ED>, entity: keyof ED, attr: string): string | 1 | 2 | string[] | 0;
1
+ import { EntityDef } from "../types/Entity";
2
+ import { StorageSchema } from "../types/Storage";
3
+ /**
4
+ * 判断对象和属性之间的关系
5
+ * @param schema
6
+ * @param entity
7
+ * @param attr
8
+ * @param row
9
+ * @returns
10
+ */
11
+ export declare function judgeRelation<ED extends {
12
+ [E: string]: EntityDef;
13
+ }>(schema: StorageSchema<ED>, entity: keyof ED, attr: string): string | 1 | 2 | string[] | 0;
@@ -1,66 +1,66 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.judgeRelation = void 0;
4
- var tslib_1 = require("tslib");
5
- var assert_1 = tslib_1.__importDefault(require("assert"));
6
- var Demand_1 = require("../types/Demand");
7
- var Entity_1 = require("../types/Entity");
8
- /**
9
- * 判断对象和属性之间的关系
10
- * @param schema
11
- * @param entity
12
- * @param attr
13
- * @param row
14
- * @returns
15
- */
16
- function judgeRelation(schema, entity, attr) {
17
- var _a = schema, _b = entity, attributes = _a[_b].attributes;
18
- if (attr.startsWith(Demand_1.EXPRESSION_PREFIX) || attr.startsWith('#')) {
19
- // 表达式属性或者metadata
20
- return 0;
21
- }
22
- if (attributes.hasOwnProperty(attr) || Entity_1.initinctiveAttributes.includes(attr)) {
23
- // 原生属性
24
- return 1;
25
- }
26
- if (attr.includes('$')) {
27
- var firstDelimiter = attr.indexOf('$');
28
- var entity2 = attr.slice(0, firstDelimiter);
29
- (0, assert_1.default)(schema.hasOwnProperty(entity2));
30
- var secondDelemiter = attr.indexOf('$', firstDelimiter + 1);
31
- var foreignKey = attr.slice(firstDelimiter + 1, secondDelemiter > 0 ? secondDelemiter : attr.length);
32
- var _c = schema, _d = entity2, attributes2 = _c[_d].attributes;
33
- if (foreignKey === 'entity') {
34
- // 基于反指对象的反向关联
35
- return [entity2];
36
- }
37
- else if (attributes2.hasOwnProperty("".concat(foreignKey, "Id"))
38
- && attributes2["".concat(foreignKey, "Id")].type === 'ref'
39
- && attributes2["".concat(foreignKey, "Id")].ref === entity) {
40
- // 基于外键的反向关联
41
- return [entity2, "".concat(foreignKey, "Id")];
42
- }
43
- else {
44
- // 这种情况应该不会跑到
45
- (0, assert_1.default)(false);
46
- }
47
- }
48
- else if ((attributes.hasOwnProperty("".concat(attr, "Id")))) {
49
- var _e = attributes["".concat(attr, "Id")], type = _e.type, ref = _e.ref;
50
- if (type === 'ref') {
51
- return ref;
52
- }
53
- return 1;
54
- }
55
- else if (attributes.hasOwnProperty('entity')
56
- && attributes.hasOwnProperty('entityId')
57
- && schema.hasOwnProperty(attr)) {
58
- // 反向指针的外键
59
- return 2;
60
- }
61
- else {
62
- (0, assert_1.default)(Entity_1.initinctiveAttributes.includes(attr), "".concat(entity, "\u5BF9\u8C61\u4E2D\u7684").concat(attr, "\u5C5E\u6027\u627E\u4E0D\u5230"));
63
- return 1;
64
- }
65
- }
66
- exports.judgeRelation = judgeRelation;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.judgeRelation = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var assert_1 = tslib_1.__importDefault(require("assert"));
6
+ var Demand_1 = require("../types/Demand");
7
+ var Entity_1 = require("../types/Entity");
8
+ /**
9
+ * 判断对象和属性之间的关系
10
+ * @param schema
11
+ * @param entity
12
+ * @param attr
13
+ * @param row
14
+ * @returns
15
+ */
16
+ function judgeRelation(schema, entity, attr) {
17
+ var _a = schema, _b = entity, attributes = _a[_b].attributes;
18
+ if (attr.startsWith(Demand_1.EXPRESSION_PREFIX) || attr.startsWith('#')) {
19
+ // 表达式属性或者metadata
20
+ return 0;
21
+ }
22
+ if (attributes.hasOwnProperty(attr) || Entity_1.initinctiveAttributes.includes(attr)) {
23
+ // 原生属性
24
+ return 1;
25
+ }
26
+ if (attr.includes('$')) {
27
+ var firstDelimiter = attr.indexOf('$');
28
+ var entity2 = attr.slice(0, firstDelimiter);
29
+ (0, assert_1.default)(schema.hasOwnProperty(entity2));
30
+ var secondDelemiter = attr.indexOf('$', firstDelimiter + 1);
31
+ var foreignKey = attr.slice(firstDelimiter + 1, secondDelemiter > 0 ? secondDelemiter : attr.length);
32
+ var _c = schema, _d = entity2, attributes2 = _c[_d].attributes;
33
+ if (foreignKey === 'entity') {
34
+ // 基于反指对象的反向关联
35
+ return [entity2];
36
+ }
37
+ else if (attributes2.hasOwnProperty("".concat(foreignKey, "Id"))
38
+ && attributes2["".concat(foreignKey, "Id")].type === 'ref'
39
+ && attributes2["".concat(foreignKey, "Id")].ref === entity) {
40
+ // 基于外键的反向关联
41
+ return [entity2, "".concat(foreignKey, "Id")];
42
+ }
43
+ else {
44
+ // 这种情况应该不会跑到
45
+ (0, assert_1.default)(false);
46
+ }
47
+ }
48
+ else if ((attributes.hasOwnProperty("".concat(attr, "Id")))) {
49
+ var _e = attributes["".concat(attr, "Id")], type = _e.type, ref = _e.ref;
50
+ if (type === 'ref') {
51
+ return ref;
52
+ }
53
+ return 1;
54
+ }
55
+ else if (attributes.hasOwnProperty('entity')
56
+ && attributes.hasOwnProperty('entityId')
57
+ && schema.hasOwnProperty(attr)) {
58
+ // 反向指针的外键
59
+ return 2;
60
+ }
61
+ else {
62
+ (0, assert_1.default)(Entity_1.initinctiveAttributes.includes(attr), "".concat(entity, "\u5BF9\u8C61\u4E2D\u7684").concat(attr, "\u5C5E\u6027\u627E\u4E0D\u5230"));
63
+ return 1;
64
+ }
65
+ }
66
+ exports.judgeRelation = judgeRelation;