oak-backend-base 4.1.5 → 4.1.6

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.
@@ -10,7 +10,7 @@ const filter_1 = require("oak-domain/lib/store/filter");
10
10
  const uuid_1 = require("oak-domain/lib/utils/uuid");
11
11
  const lodash_2 = require("lodash");
12
12
  const OAK_SYNC_HEADER_ENTITY = 'oak-sync-entity';
13
- const OAK_SYNC_HEADER_ENTITYID = 'oak-sync-entity-id';
13
+ const OAK_SYNC_HEADER_ENTITY_ID = 'oak-sync-entity-id';
14
14
  class Synchronizer {
15
15
  config;
16
16
  schema;
@@ -36,7 +36,7 @@ class Synchronizer {
36
36
  headers: {
37
37
  'Content-Type': 'application/json',
38
38
  [OAK_SYNC_HEADER_ENTITY]: entity,
39
- [OAK_SYNC_HEADER_ENTITYID]: entityId,
39
+ [OAK_SYNC_HEADER_ENTITY_ID]: entityId,
40
40
  },
41
41
  body: JSON.stringify(opers),
42
42
  });
@@ -50,17 +50,27 @@ class Synchronizer {
50
50
  }
51
51
  catch (err) {
52
52
  if (onFailed) {
53
- await onFailed({
54
- remoteEntity: entity,
55
- remoteEntityId: entityId,
56
- data: queue.map((ele) => ({
57
- entity: ele.oper.targetEntity,
58
- rowIds: ele.oper.filter.id.$in,
59
- action: ele.oper.action,
60
- data: ele.oper.data,
61
- })),
62
- reason: err,
63
- }, context);
53
+ context.on('rollback', async () => {
54
+ const context2 = this.contextBuilder();
55
+ context2.begin();
56
+ try {
57
+ await onFailed({
58
+ remoteEntity: entity,
59
+ remoteEntityId: entityId,
60
+ data: queue.map((ele) => ({
61
+ entity: ele.oper.targetEntity,
62
+ rowIds: ele.oper.filter.id.$in,
63
+ action: ele.oper.action,
64
+ data: ele.oper.data,
65
+ })),
66
+ reason: err,
67
+ }, context2);
68
+ context2.commit();
69
+ }
70
+ catch (err) {
71
+ context2.rollback();
72
+ }
73
+ });
64
74
  }
65
75
  throw err;
66
76
  }
@@ -79,11 +89,12 @@ class Synchronizer {
79
89
  }
80
90
  }, {});
81
91
  const entityIds = operEntityArr.map(ele => ele.entityId);
82
- return onSynchronized && onSynchronized({
92
+ return onSynchronized({
83
93
  action: oper.action,
84
94
  data: oper.data,
85
- // rowIds: getRelevantIds(oper.filter!),
86
- rowIds: entityIds
95
+ rowIds: entityIds,
96
+ remoteEntity: entity,
97
+ remoteEntityId: entityId,
87
98
  }, context);
88
99
  }
89
100
  }
@@ -144,7 +155,7 @@ class Synchronizer {
144
155
  (0, assert_1.default)(channel.entity === remoteEntity);
145
156
  (0, assert_1.default)(channel.entityId === remoteEntityId);
146
157
  if (channel.queue.find(ele => ele.oper.id === oper.id)) {
147
- console.error('aaaaa');
158
+ console.error('channel.queue找到相同的需推送的oper');
148
159
  }
149
160
  channel.queue.push({
150
161
  oper,
@@ -172,7 +183,6 @@ class Synchronizer {
172
183
  async dispatchOperToChannels(oper, context) {
173
184
  const { operatorId, targetEntity, filter, action, data, operEntity$oper } = oper;
174
185
  const entityIds = operEntity$oper?.map(ele => ele.entityId);
175
- // const entityIds = getRelevantIds(filter!);
176
186
  (0, assert_1.default)(entityIds && entityIds.length > 0);
177
187
  const pushEntityNodes = this.pushAccessMap[targetEntity];
178
188
  let pushed = false;
@@ -282,17 +292,17 @@ class Synchronizer {
282
292
  (0, assert_1.default)(this.channelDict[c].queue.length === 0);
283
293
  }
284
294
  const pushedIds = [];
285
- const unpushedIds = [];
295
+ const unPushedIds = [];
286
296
  await Promise.all(dirtyOpers.map(async (oper) => {
287
297
  const result = await this.dispatchOperToChannels(oper, context);
288
298
  if (result) {
289
299
  pushedIds.push(oper.id);
290
300
  }
291
301
  else {
292
- unpushedIds.push(oper.id);
302
+ unPushedIds.push(oper.id);
293
303
  }
294
304
  }));
295
- if (unpushedIds.length > 0) {
305
+ if (unPushedIds.length > 0) {
296
306
  await context.operate('oper', {
297
307
  id: await (0, uuid_1.generateNewIdAsync)(),
298
308
  action: 'update',
@@ -302,7 +312,7 @@ class Synchronizer {
302
312
  },
303
313
  filter: {
304
314
  id: {
305
- $in: unpushedIds,
315
+ $in: unPushedIds,
306
316
  }
307
317
  }
308
318
  }, {});
@@ -452,7 +462,7 @@ class Synchronizer {
452
462
  fn: async (context, params, headers, req, body) => {
453
463
  // body中是传过来的oper数组信息
454
464
  const { entity, entityId } = params;
455
- const { [OAK_SYNC_HEADER_ENTITY]: meEntity, [OAK_SYNC_HEADER_ENTITYID]: meEntityId } = headers;
465
+ const { [OAK_SYNC_HEADER_ENTITY]: meEntity, [OAK_SYNC_HEADER_ENTITY_ID]: meEntityId } = headers;
456
466
  if (process.env.NODE_ENV === 'development') {
457
467
  console.log('接收到来自远端的sync数据', entity, JSON.stringify(body));
458
468
  }
@@ -1,16 +1,16 @@
1
- import { EntityDict } from 'oak-domain/lib/types';
2
- import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
3
- import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext';
4
- import { RemotePushInfo, RemotePullInfo, SelfEncryptInfo, SyncRemoteConfigBase, SyncSelfConfigBase, SyncConfig } from 'oak-domain/lib/types/Sync';
5
- interface SyncRemoteConfigWrapper<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>> extends SyncRemoteConfigBase<ED, Cxt> {
6
- getRemotePushInfo: (userId: string) => Promise<RemotePushInfo>;
7
- getRemotePullInfo: (id: string) => Promise<RemotePullInfo>;
8
- }
9
- interface SyncSelfConfigWrapper<ED extends EntityDict & BaseEntityDict> extends SyncSelfConfigBase<ED> {
10
- getSelfEncryptInfo: () => Promise<SelfEncryptInfo>;
11
- }
12
- export interface SyncConfigWrapper<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>> {
13
- self: SyncSelfConfigWrapper<ED>;
14
- remotes: Array<SyncRemoteConfigWrapper<ED, Cxt>>;
15
- }
16
- export { RemotePushInfo, RemotePullInfo, SelfEncryptInfo, SyncConfig, };
1
+ import { EntityDict } from 'oak-domain/lib/types';
2
+ import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
3
+ import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext';
4
+ import { RemotePushInfo, RemotePullInfo, SelfEncryptInfo, SyncRemoteConfigBase, SyncSelfConfigBase, SyncConfig } from 'oak-domain/lib/types/Sync';
5
+ interface SyncRemoteConfigWrapper<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>> extends SyncRemoteConfigBase<ED, Cxt> {
6
+ getRemotePushInfo: (userId: string) => Promise<RemotePushInfo>;
7
+ getRemotePullInfo: (id: string) => Promise<RemotePullInfo>;
8
+ }
9
+ interface SyncSelfConfigWrapper<ED extends EntityDict & BaseEntityDict> extends SyncSelfConfigBase<ED> {
10
+ getSelfEncryptInfo: () => Promise<SelfEncryptInfo>;
11
+ }
12
+ export interface SyncConfigWrapper<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>> {
13
+ self: SyncSelfConfigWrapper<ED>;
14
+ remotes: Array<SyncRemoteConfigWrapper<ED, Cxt>>;
15
+ }
16
+ export { RemotePushInfo, RemotePullInfo, SelfEncryptInfo, SyncConfig, };
package/lib/types/Sync.js CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- ;
4
- ;
5
- ;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ ;
4
+ ;
5
+ ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-backend-base",
3
- "version": "4.1.5",
3
+ "version": "4.1.6",
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.2",
24
24
  "oak-db": "^3.3.2",
25
- "oak-domain": "^5.1.2",
26
- "oak-frontend-base": "^5.3.10",
25
+ "oak-domain": "^5.1.4",
26
+ "oak-frontend-base": "^5.3.12",
27
27
  "socket.io": "^4.7.2",
28
28
  "socket.io-client": "^4.7.2",
29
29
  "uuid": "^8.3.2"