oak-domain 1.1.14 → 2.0.1

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 (73) hide show
  1. package/lib/base-app-domain/Modi/Schema.d.ts +22 -22
  2. package/lib/base-app-domain/ModiEntity/Schema.d.ts +17 -17
  3. package/lib/base-app-domain/Oper/Schema.d.ts +17 -17
  4. package/lib/base-app-domain/OperEntity/Schema.d.ts +18 -18
  5. package/lib/base-app-domain/User/Schema.d.ts +15 -15
  6. package/lib/checkers/index.d.ts +4 -2
  7. package/lib/compiler/schemalBuilder.js +10 -10
  8. package/lib/store/AsyncRowStore.d.ts +45 -0
  9. package/lib/store/{UniversalContext.js → AsyncRowStore.js} +39 -29
  10. package/lib/store/CascadeStore.d.ts +46 -20
  11. package/lib/store/CascadeStore.js +954 -995
  12. package/lib/store/SyncRowStore.d.ts +26 -0
  13. package/lib/store/SyncRowStore.js +45 -0
  14. package/lib/store/TriggerExecutor.d.ts +14 -14
  15. package/lib/store/TriggerExecutor.js +225 -238
  16. package/lib/store/actionDef.d.ts +5 -4
  17. package/lib/store/actionDef.js +44 -134
  18. package/lib/store/checker.d.ts +6 -0
  19. package/lib/store/checker.js +165 -0
  20. package/lib/store/filter.d.ts +5 -0
  21. package/lib/store/filter.js +394 -2
  22. package/lib/store/modi.d.ts +7 -6
  23. package/lib/store/modi.js +35 -46
  24. package/lib/store/relation.d.ts +1 -1
  25. package/lib/triggers/index.d.ts +4 -3
  26. package/lib/triggers/modi.d.ts +2 -2
  27. package/lib/triggers/modi.js +5 -5
  28. package/lib/types/AppLoader.d.ts +3 -3
  29. package/lib/types/Aspect.d.ts +3 -3
  30. package/lib/types/Auth.d.ts +25 -22
  31. package/lib/types/Connector.d.ts +7 -7
  32. package/lib/types/Context.d.ts +4 -14
  33. package/lib/types/Entity.d.ts +20 -15
  34. package/lib/types/Entity.js +9 -2
  35. package/lib/types/Exception.js +11 -11
  36. package/lib/types/RowStore.d.ts +2 -13
  37. package/lib/types/RowStore.js +1 -6
  38. package/lib/types/Trigger.d.ts +32 -48
  39. package/lib/types/Trigger.js +24 -9
  40. package/lib/types/Watcher.d.ts +7 -8
  41. package/lib/utils/SimpleConnector.d.ts +9 -8
  42. package/lib/utils/SimpleConnector.js +4 -5
  43. package/lib/utils/random/random.d.ts +1 -0
  44. package/lib/utils/random/random.js +24 -0
  45. package/lib/utils/random/random.mp.d.ts +1 -0
  46. package/lib/utils/random/random.mp.js +25 -0
  47. package/lib/utils/random/random.web.d.ts +1 -0
  48. package/lib/utils/random/random.web.js +17 -0
  49. package/lib/utils/string.d.ts +20 -0
  50. package/lib/utils/string.js +60 -1
  51. package/lib/utils/uuid.d.ts +10 -0
  52. package/lib/utils/uuid.js +172 -1
  53. package/lib/utils/validator.js +1 -1
  54. package/package.json +5 -3
  55. package/lib/OakError.d.ts +0 -7
  56. package/lib/OakError.js +0 -15
  57. package/lib/compiler/utils.d.ts +0 -2
  58. package/lib/compiler/utils.js +0 -11
  59. package/lib/entities/Action.d.ts +0 -12
  60. package/lib/entities/Action.js +0 -17
  61. package/lib/entities/Ooperation.d.ts +0 -12
  62. package/lib/entities/Ooperation.js +0 -17
  63. package/lib/entities/Update.d.ts +0 -9
  64. package/lib/entities/Update.js +0 -44
  65. package/lib/entities/Uupdate.d.ts +0 -9
  66. package/lib/entities/Uupdate.js +0 -44
  67. package/lib/store/UniversalContext.d.ts +0 -32
  68. package/lib/store/action.d.ts +0 -6
  69. package/lib/store/action.js +0 -14
  70. package/lib/store/projection.d.ts +0 -7
  71. package/lib/store/projection.js +0 -211
  72. package/lib/store/watchers.d.ts +0 -2
  73. package/lib/store/watchers.js +0 -32
@@ -1,211 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reinforceSelection = void 0;
4
- var tslib_1 = require("tslib");
5
- var assert_1 = tslib_1.__importDefault(require("assert"));
6
- var types_1 = require("../types");
7
- var Demand_1 = require("../types/Demand");
8
- var relation_1 = require("./relation");
9
- /**
10
- * 对selection进行一些完善,避免编程人员的疏漏
11
- * @param selection
12
- */
13
- function reinforceSelection(schema, entity, selection) {
14
- var filter = selection.filter, data = selection.data, sorter = selection.sorter;
15
- var checkNode = function (projectionNode, attrs) {
16
- attrs.forEach(function (attr) {
17
- var _a;
18
- if (!projectionNode.hasOwnProperty(attr)) {
19
- Object.assign(projectionNode, (_a = {},
20
- _a[attr] = 1,
21
- _a));
22
- }
23
- });
24
- };
25
- if (filter) {
26
- var toBeAssignNode_1 = {}; // 用来记录在表达式中涉及到的结点
27
- // filter当中所关联到的属性必须在projection中
28
- var filterNodeDict_1 = {};
29
- var checkFilterNode_1 = function (entity2, filterNode, projectionNode) {
30
- var _a, e_1, _b, _c, _d, _e, _f;
31
- var necessaryAttrs = ['id'];
32
- for (var attr in filterNode) {
33
- if (attr === '#id') {
34
- (0, assert_1.default)(!filterNodeDict_1[filterNode[attr]], "projection\u4E2D\u7ED3\u70B9\u7684id\u6709\u91CD\u590D, ".concat(filterNode[attr]));
35
- Object.assign(filterNodeDict_1, (_a = {},
36
- _a[filterNode[attr]] = projectionNode,
37
- _a));
38
- if (toBeAssignNode_1[filterNode[attr]]) {
39
- checkNode(projectionNode, toBeAssignNode_1[filterNode[attr]]);
40
- }
41
- }
42
- else if (['$and', '$or'].includes(attr)) {
43
- try {
44
- for (var _g = (e_1 = void 0, tslib_1.__values(filterNode[attr])), _h = _g.next(); !_h.done; _h = _g.next()) {
45
- var node = _h.value;
46
- checkFilterNode_1(entity2, node, projectionNode);
47
- }
48
- }
49
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
50
- finally {
51
- try {
52
- if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
53
- }
54
- finally { if (e_1) throw e_1.error; }
55
- }
56
- }
57
- else if (attr === '$not') {
58
- checkFilterNode_1(entity2, filterNode[attr], projectionNode);
59
- }
60
- else {
61
- if (attr.toLowerCase().startsWith(Demand_1.EXPRESSION_PREFIX)) {
62
- var exprResult = (0, types_1.getAttrRefInExpression)(filterNode[attr]);
63
- for (var nodeName in exprResult) {
64
- if (nodeName === '#current') {
65
- checkNode(projectionNode, exprResult[nodeName]);
66
- }
67
- else if (filterNodeDict_1[nodeName]) {
68
- checkNode(filterNodeDict_1[nodeName], exprResult[nodeName]);
69
- }
70
- else {
71
- if (toBeAssignNode_1[nodeName]) {
72
- (_c = toBeAssignNode_1[nodeName]).push.apply(_c, tslib_1.__spreadArray([], tslib_1.__read(exprResult[nodeName]), false));
73
- }
74
- else {
75
- Object.assign(toBeAssignNode_1, (_d = {},
76
- _d[nodeName] = exprResult[nodeName],
77
- _d));
78
- }
79
- }
80
- }
81
- }
82
- else {
83
- var rel = (0, relation_1.judgeRelation)(schema, entity2, attr);
84
- if (rel === 1) {
85
- necessaryAttrs.push(attr);
86
- }
87
- else if (rel === 2) {
88
- // entity/entityId反指
89
- necessaryAttrs.push('entity', 'entityId');
90
- if (!projectionNode[attr]) {
91
- Object.assign(projectionNode, (_e = {},
92
- _e[attr] = {
93
- id: 1,
94
- },
95
- _e));
96
- }
97
- checkFilterNode_1(attr, filterNode[attr], projectionNode[attr]);
98
- }
99
- else if (typeof rel === 'string') {
100
- necessaryAttrs.push("".concat(attr, "Id"));
101
- if (!projectionNode[attr]) {
102
- Object.assign(projectionNode, (_f = {},
103
- _f[attr] = {
104
- id: 1,
105
- },
106
- _f));
107
- }
108
- checkFilterNode_1(rel, filterNode[attr], projectionNode[attr]);
109
- }
110
- else if (rel instanceof Array) {
111
- // 现在filter中还不支持一对多的语义,先放着吧
112
- }
113
- }
114
- }
115
- checkNode(projectionNode, necessaryAttrs);
116
- }
117
- };
118
- checkFilterNode_1(entity, filter, data);
119
- }
120
- // sorter感觉现在取不取影响不大,前端的list直接获取返回的ids了,先不管之
121
- if (sorter) {
122
- }
123
- var toBeAssignNode2 = {}; // 用来记录在表达式中涉及到的结点
124
- var projectionNodeDict = {};
125
- var checkProjectionNode = function (entity2, projectionNode) {
126
- var _a, _b, _c;
127
- var necessaryAttrs = ['id'];
128
- for (var attr in projectionNode) {
129
- if (attr === '#id') {
130
- (0, assert_1.default)(!projectionNodeDict[projectionNode[attr]], "projection\u4E2D\u7ED3\u70B9\u7684id\u6709\u91CD\u590D, ".concat(projectionNode[attr]));
131
- Object.assign(projectionNodeDict, (_a = {},
132
- _a[projectionNode[attr]] = projectionNode,
133
- _a));
134
- if (toBeAssignNode2[projectionNode[attr]]) {
135
- checkNode(projectionNode, toBeAssignNode2[projectionNode[attr]]);
136
- }
137
- }
138
- else {
139
- if (attr.toLowerCase().startsWith(Demand_1.EXPRESSION_PREFIX)) {
140
- var exprResult = (0, types_1.getAttrRefInExpression)(projectionNode[attr]);
141
- for (var nodeName in exprResult) {
142
- if (nodeName === '#current') {
143
- checkNode(projectionNode, exprResult[nodeName]);
144
- }
145
- else if (projectionNodeDict[nodeName]) {
146
- checkNode(projectionNodeDict[nodeName], exprResult[nodeName]);
147
- }
148
- else {
149
- if (toBeAssignNode2[nodeName]) {
150
- (_b = toBeAssignNode2[nodeName]).push.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(exprResult[nodeName]), false));
151
- }
152
- else {
153
- Object.assign(toBeAssignNode2, (_c = {},
154
- _c[nodeName] = exprResult[nodeName],
155
- _c));
156
- }
157
- }
158
- }
159
- }
160
- else {
161
- var rel = (0, relation_1.judgeRelation)(schema, entity2, attr);
162
- if (rel === 1) {
163
- necessaryAttrs.push(attr);
164
- }
165
- else if (rel === 2) {
166
- // entity/entityId反指
167
- necessaryAttrs.push('entity', 'entityId');
168
- checkProjectionNode(attr, projectionNode[attr]);
169
- }
170
- else if (typeof rel === 'string') {
171
- necessaryAttrs.push("".concat(attr, "Id"));
172
- checkProjectionNode(rel, projectionNode[attr]);
173
- }
174
- else if (rel instanceof Array) {
175
- var data_1 = projectionNode[attr].data;
176
- if (rel[1]) {
177
- checkNode(data_1, [rel[1]]);
178
- }
179
- else {
180
- checkNode(data_1, ['entity', 'entityId']);
181
- }
182
- checkProjectionNode(rel[0], data_1);
183
- }
184
- }
185
- }
186
- checkNode(projectionNode, necessaryAttrs);
187
- }
188
- // 如果对象中指向一对多的Modi,此时加上指向Modi的projection
189
- if (schema[entity2].toModi) {
190
- Object.assign(projectionNode, {
191
- modi$entity: {
192
- $entity: 'modi',
193
- data: {
194
- id: 1,
195
- targetEntity: 1,
196
- entity: 1,
197
- entityId: 1,
198
- action: 1,
199
- data: 1,
200
- filter: 1,
201
- },
202
- filter: {
203
- iState: 'active',
204
- },
205
- }
206
- });
207
- }
208
- };
209
- checkProjectionNode(entity, data);
210
- }
211
- exports.reinforceSelection = reinforceSelection;
@@ -1,2 +0,0 @@
1
- import { Context, EntityDict, StorageSchema, Watcher } from "../types";
2
- export declare function makeIntrinsicWatchers<ED extends EntityDict, Cxt extends Context<ED>>(schema: StorageSchema<ED>): Watcher<ED, keyof ED, Cxt>[];
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeIntrinsicWatchers = void 0;
4
- function makeIntrinsicWatchers(schema) {
5
- const watchers = [];
6
- for (const entity in schema) {
7
- const { attributes } = schema[entity];
8
- const { expiresAt, expired } = attributes;
9
- if (expiresAt && expiresAt.type === 'datetime' && expired && expired.type === 'boolean') {
10
- // 如果有定义expiresAt和expired,则自动生成一个检查的watcher
11
- watchers.push({
12
- entity,
13
- name: `对象${entity}上的过期自动watcher`,
14
- filter: async () => {
15
- const now = Date.now();
16
- return {
17
- expired: false,
18
- expiresAt: {
19
- $lte: now,
20
- },
21
- };
22
- },
23
- action: 'update',
24
- actionData: {
25
- expired: true,
26
- },
27
- });
28
- }
29
- }
30
- return watchers;
31
- }
32
- exports.makeIntrinsicWatchers = makeIntrinsicWatchers;