oak-backend-base 4.1.1 → 4.1.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.
- package/lib/AppLoader.js +6 -8
- package/lib/Synchronizer.js +31 -9
- package/package.json +3 -3
package/lib/AppLoader.js
CHANGED
|
@@ -271,14 +271,12 @@ class AppLoader extends types_1.AppLoader {
|
|
|
271
271
|
return endPointRouters;
|
|
272
272
|
}
|
|
273
273
|
operateInWatcher(entity, operation, context) {
|
|
274
|
-
return this.dbStore.operate(entity, operation, context, {
|
|
275
|
-
dontCollect: true,
|
|
276
|
-
});
|
|
274
|
+
return this.dbStore.operate(entity, operation, context, {});
|
|
277
275
|
}
|
|
278
276
|
selectInWatcher(entity, selection, context) {
|
|
279
277
|
return this.dbStore.select(entity, selection, context, {
|
|
280
|
-
dontCollect: true,
|
|
281
278
|
blockTrigger: true,
|
|
279
|
+
forUpdate: true,
|
|
282
280
|
});
|
|
283
281
|
}
|
|
284
282
|
async execWatcher(watcher) {
|
|
@@ -287,8 +285,8 @@ class AppLoader extends types_1.AppLoader {
|
|
|
287
285
|
try {
|
|
288
286
|
if (watcher.hasOwnProperty('actionData')) {
|
|
289
287
|
const { entity, action, filter, actionData } = watcher;
|
|
290
|
-
const filter2 = typeof filter === 'function' ? await filter() : filter;
|
|
291
|
-
const data = typeof actionData === 'function' ? await (actionData)() : actionData;
|
|
288
|
+
const filter2 = typeof filter === 'function' ? await filter() : (0, lodash_1.cloneDeep)(filter);
|
|
289
|
+
const data = typeof actionData === 'function' ? await (actionData)() : (0, lodash_1.cloneDeep)(actionData);
|
|
292
290
|
result = await this.operateInWatcher(entity, {
|
|
293
291
|
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
294
292
|
action: action,
|
|
@@ -298,8 +296,8 @@ class AppLoader extends types_1.AppLoader {
|
|
|
298
296
|
}
|
|
299
297
|
else {
|
|
300
298
|
const { entity, projection, fn, filter } = watcher;
|
|
301
|
-
const filter2 = typeof filter === 'function' ? await filter() : filter;
|
|
302
|
-
const projection2 = typeof projection === 'function' ? await projection() : projection;
|
|
299
|
+
const filter2 = typeof filter === 'function' ? await filter() : (0, lodash_1.cloneDeep)(filter);
|
|
300
|
+
const projection2 = typeof projection === 'function' ? await projection() : (0, lodash_1.cloneDeep)(projection);
|
|
303
301
|
const rows = await this.selectInWatcher(entity, {
|
|
304
302
|
data: projection2,
|
|
305
303
|
filter: filter2,
|
package/lib/Synchronizer.js
CHANGED
|
@@ -102,12 +102,24 @@ class Synchronizer {
|
|
|
102
102
|
}
|
|
103
103
|
if (successIds.length > 0) {
|
|
104
104
|
try {
|
|
105
|
-
await Promise.all(successIds.map((id) => {
|
|
105
|
+
await Promise.all(successIds.map(async (id) => {
|
|
106
106
|
const { onSynchronized, oper } = queue.find(ele => ele.oper.id === id);
|
|
107
|
+
const operEntityArr = await context.select('operEntity', {
|
|
108
|
+
data: {
|
|
109
|
+
id: 1,
|
|
110
|
+
entity: 1,
|
|
111
|
+
entityId: 1
|
|
112
|
+
},
|
|
113
|
+
filter: {
|
|
114
|
+
operId: oper.id,
|
|
115
|
+
}
|
|
116
|
+
}, {});
|
|
117
|
+
const entityIds = operEntityArr.map(ele => ele.entityId);
|
|
107
118
|
return onSynchronized && onSynchronized({
|
|
108
119
|
action: oper.action,
|
|
109
120
|
data: oper.data,
|
|
110
|
-
rowIds:
|
|
121
|
+
// rowIds: getRelevantIds(oper.filter!),
|
|
122
|
+
rowIds: entityIds
|
|
111
123
|
}, context);
|
|
112
124
|
}));
|
|
113
125
|
}
|
|
@@ -184,9 +196,10 @@ class Synchronizer {
|
|
|
184
196
|
};
|
|
185
197
|
}
|
|
186
198
|
async dispatchOperToChannels(oper, context) {
|
|
187
|
-
const { operatorId, targetEntity, filter, action, data } = oper;
|
|
188
|
-
const entityIds = (
|
|
189
|
-
|
|
199
|
+
const { operatorId, targetEntity, filter, action, data, operEntity$oper } = oper;
|
|
200
|
+
const entityIds = operEntity$oper?.map(ele => ele.entityId);
|
|
201
|
+
// const entityIds = getRelevantIds(filter!);
|
|
202
|
+
(0, assert_1.default)(entityIds && entityIds.length > 0);
|
|
190
203
|
const pushEntityNodes = this.pushAccessMap[targetEntity];
|
|
191
204
|
let pushed = false;
|
|
192
205
|
if (pushEntityNodes && pushEntityNodes.length > 0) {
|
|
@@ -229,7 +242,7 @@ class Synchronizer {
|
|
|
229
242
|
this.pushOperToChannel(oper2, userId, url, endpoint, entity, entityId, selfEncryptInfo, onSynchronized);
|
|
230
243
|
};
|
|
231
244
|
for (const userId in userSendDict) {
|
|
232
|
-
if (userId !== operatorId || oper.bornAt) {
|
|
245
|
+
if (userId !== operatorId || !oper.bornAt) {
|
|
233
246
|
await pushToUserIdFn(userId);
|
|
234
247
|
pushed = true;
|
|
235
248
|
}
|
|
@@ -277,6 +290,15 @@ class Synchronizer {
|
|
|
277
290
|
$$createAt$$: 1,
|
|
278
291
|
$$seq$$: 1,
|
|
279
292
|
filter: 1,
|
|
293
|
+
operEntity$oper: {
|
|
294
|
+
$entity: 'operEntity',
|
|
295
|
+
data: {
|
|
296
|
+
entityId: 1,
|
|
297
|
+
operId: 1,
|
|
298
|
+
entity: 1,
|
|
299
|
+
id: 1,
|
|
300
|
+
}
|
|
301
|
+
}
|
|
280
302
|
},
|
|
281
303
|
filter: {
|
|
282
304
|
id: { $in: ids },
|
|
@@ -504,7 +526,7 @@ class Synchronizer {
|
|
|
504
526
|
// todo 解密
|
|
505
527
|
const opers = body;
|
|
506
528
|
const ids = opers.map(ele => ele.id);
|
|
507
|
-
const
|
|
529
|
+
const existsIds = (await context.select('oper', {
|
|
508
530
|
data: {
|
|
509
531
|
id: 1,
|
|
510
532
|
},
|
|
@@ -514,8 +536,8 @@ class Synchronizer {
|
|
|
514
536
|
},
|
|
515
537
|
}
|
|
516
538
|
}, {})).map(ele => ele.id);
|
|
517
|
-
const staleOpers = opers.filter(ele =>
|
|
518
|
-
const freshOpers = opers.filter(ele => !
|
|
539
|
+
const staleOpers = opers.filter((ele) => existsIds.includes(ele.id));
|
|
540
|
+
const freshOpers = opers.filter((ele) => !existsIds.includes(ele.id));
|
|
519
541
|
if (process.env.NODE_ENV !== 'production') {
|
|
520
542
|
const maxStaleSeq = Math.max(...staleOpers.map(ele => ele.$$seq$$));
|
|
521
543
|
for (const oper of freshOpers) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oak-backend-base",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"description": "oak-backend-base",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"author": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"node-schedule": "^2.1.0",
|
|
23
23
|
"oak-common-aspect": "~3.0.0",
|
|
24
24
|
"oak-db": "~3.3.0",
|
|
25
|
-
"oak-domain": "~5.0.
|
|
26
|
-
"oak-frontend-base": "~5.
|
|
25
|
+
"oak-domain": "~5.0.16",
|
|
26
|
+
"oak-frontend-base": "~5.3.0",
|
|
27
27
|
"socket.io": "^4.7.2",
|
|
28
28
|
"socket.io-client": "^4.7.2",
|
|
29
29
|
"uuid": "^8.3.2"
|