oak-backend-base 4.1.11 → 4.1.12
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 +10 -4
- package/lib/Synchronizer.js +13 -10
- package/package.json +3 -3
package/lib/AppLoader.js
CHANGED
|
@@ -154,13 +154,15 @@ class AppLoader extends types_1.AppLoader {
|
|
|
154
154
|
if (this.watcherTimerId) {
|
|
155
155
|
console.log('取消watcher...');
|
|
156
156
|
clearTimeout(this.watcherTimerId);
|
|
157
|
+
this.watcherTimerId = undefined;
|
|
157
158
|
}
|
|
158
159
|
for (const job in this.scheduledJobs) {
|
|
159
160
|
console.log(`取消定时任务【${job}】...`);
|
|
160
|
-
this.scheduledJobs[job]
|
|
161
|
+
await this.scheduledJobs[job]?.cancel();
|
|
162
|
+
delete this.scheduledJobs[job];
|
|
161
163
|
}
|
|
162
|
-
(0, index_1.clearPorts)();
|
|
163
|
-
this.dbStore.disconnect();
|
|
164
|
+
await (0, index_1.clearPorts)();
|
|
165
|
+
await this.dbStore.disconnect();
|
|
164
166
|
}
|
|
165
167
|
async execAspect(name, headers, contextString, params) {
|
|
166
168
|
// 从aspect过来的,不能有空cxtString,以防被误判为root
|
|
@@ -239,7 +241,7 @@ class AppLoader extends types_1.AppLoader {
|
|
|
239
241
|
}
|
|
240
242
|
}
|
|
241
243
|
}
|
|
242
|
-
this.dbStore.disconnect();
|
|
244
|
+
await this.dbStore.disconnect();
|
|
243
245
|
}
|
|
244
246
|
getStore() {
|
|
245
247
|
return this.dbStore;
|
|
@@ -424,6 +426,10 @@ class AppLoader extends types_1.AppLoader {
|
|
|
424
426
|
}
|
|
425
427
|
}
|
|
426
428
|
});
|
|
429
|
+
if (!job) {
|
|
430
|
+
// console.error(`定时器【${name}】创建失败,请检查cron表达式是否正确`);
|
|
431
|
+
throw new Error(`定时器【${name}】创建失败,请检查cron表达式是否正确`);
|
|
432
|
+
}
|
|
427
433
|
if (this.scheduledJobs[name]) {
|
|
428
434
|
// console.error(`定时器【${name}】已经存在,请检查定时器名称是否重复`);
|
|
429
435
|
throw new Error(`定时器【${name}】已经存在,请检查定时器名称是否重复`);
|
package/lib/Synchronizer.js
CHANGED
|
@@ -66,7 +66,7 @@ class Synchronizer {
|
|
|
66
66
|
contextBuilder;
|
|
67
67
|
pushAccessMap = {};
|
|
68
68
|
async startChannel2(context, channel) {
|
|
69
|
-
const { queue, api, selfEncryptInfo, entity, entityId, onFailed, timeout } = channel;
|
|
69
|
+
const { queue, api, selfEncryptInfo, entity, entityId, onFailed, timeout = 5000 } = channel;
|
|
70
70
|
// todo 加密
|
|
71
71
|
const opers = queue.map(ele => ele.oper);
|
|
72
72
|
if (process.env.NODE_ENV === 'development') {
|
|
@@ -91,7 +91,7 @@ class Synchronizer {
|
|
|
91
91
|
[OAK_SYNC_HEADER_SIGN]: signature,
|
|
92
92
|
},
|
|
93
93
|
body,
|
|
94
|
-
}, timeout
|
|
94
|
+
}, timeout);
|
|
95
95
|
if (res.status !== 200) {
|
|
96
96
|
throw new Error(`sync数据时,访问api「${finalApi}」的结果不是200。「${res.status}」`);
|
|
97
97
|
}
|
|
@@ -104,23 +104,23 @@ class Synchronizer {
|
|
|
104
104
|
if (onFailed) {
|
|
105
105
|
context.on('rollback', async () => {
|
|
106
106
|
const context2 = this.contextBuilder();
|
|
107
|
-
context2.begin();
|
|
107
|
+
await context2.begin();
|
|
108
108
|
try {
|
|
109
109
|
await onFailed({
|
|
110
110
|
remoteEntity: entity,
|
|
111
111
|
remoteEntityId: entityId,
|
|
112
112
|
data: queue.map((ele) => ({
|
|
113
113
|
entity: ele.oper.targetEntity,
|
|
114
|
-
rowIds: ele.oper.filter.id.$in,
|
|
114
|
+
rowIds: ele.oper.filter.id.$in,
|
|
115
115
|
action: ele.oper.action,
|
|
116
116
|
data: ele.oper.data,
|
|
117
117
|
})),
|
|
118
118
|
reason: err,
|
|
119
119
|
}, context2);
|
|
120
|
-
context2.commit();
|
|
120
|
+
await context2.commit();
|
|
121
121
|
}
|
|
122
122
|
catch (err) {
|
|
123
|
-
context2.rollback();
|
|
123
|
+
await context2.rollback();
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
126
|
}
|
|
@@ -526,7 +526,7 @@ class Synchronizer {
|
|
|
526
526
|
this.remotePullInfoMap[entity] = {};
|
|
527
527
|
}
|
|
528
528
|
if (!this.remotePullInfoMap[entity][entityId]) {
|
|
529
|
-
const { getPullInfo, pullEntities } = this.config.remotes.find(ele => ele.entity === entity);
|
|
529
|
+
const { getPullInfo, pullEntities, clockDriftDuration } = this.config.remotes.find(ele => ele.entity === entity);
|
|
530
530
|
const pullEntityDict = {};
|
|
531
531
|
if (pullEntities) {
|
|
532
532
|
pullEntities.forEach((def) => pullEntityDict[def.entity] = def);
|
|
@@ -538,10 +538,11 @@ class Synchronizer {
|
|
|
538
538
|
remoteEntityId: entityId,
|
|
539
539
|
}),
|
|
540
540
|
pullEntityDict,
|
|
541
|
+
clockDriftDuration,
|
|
541
542
|
};
|
|
542
543
|
closeFn();
|
|
543
544
|
}
|
|
544
|
-
const { pullInfo, pullEntityDict } = this.remotePullInfoMap[entity][entityId];
|
|
545
|
+
const { pullInfo, pullEntityDict, clockDriftDuration } = this.remotePullInfoMap[entity][entityId];
|
|
545
546
|
const { userId, algorithm, publicKey, cxtInfo } = pullInfo;
|
|
546
547
|
(0, assert_1.default)(userId);
|
|
547
548
|
context.setCurrentUserId(userId);
|
|
@@ -549,8 +550,10 @@ class Synchronizer {
|
|
|
549
550
|
await context.initialize(cxtInfo);
|
|
550
551
|
}
|
|
551
552
|
const syncTimestamp = parseInt(syncTs, 10);
|
|
552
|
-
if (
|
|
553
|
-
|
|
553
|
+
if (clockDriftDuration !== 0) {
|
|
554
|
+
if (!(Date.now() - syncTimestamp < (clockDriftDuration || 10000))) {
|
|
555
|
+
throw new types_1.OakClockDriftException('同步时钟漂移过长');
|
|
556
|
+
}
|
|
554
557
|
}
|
|
555
558
|
if (!verify(publicKey, JSON.stringify(body), syncTs, syncNonce, syncSign)) {
|
|
556
559
|
throw new Error('sync验签失败');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oak-backend-base",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.12",
|
|
4
4
|
"description": "oak-backend-base",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"author": {
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"mysql2": "^2.3.3",
|
|
22
22
|
"node-schedule": "^2.1.0",
|
|
23
23
|
"oak-common-aspect": "^3.0.4",
|
|
24
|
-
"oak-db": "^3.3.
|
|
25
|
-
"oak-domain": "^5.1.
|
|
24
|
+
"oak-db": "^3.3.4",
|
|
25
|
+
"oak-domain": "^5.1.13",
|
|
26
26
|
"oak-frontend-base": "^5.3.20",
|
|
27
27
|
"socket.io": "^4.7.2",
|
|
28
28
|
"socket.io-client": "^4.7.2",
|