oak-backend-base 3.3.3 → 3.3.4

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.
@@ -1,23 +1,23 @@
1
- import { EntityDict, OperateOption, OpRecord } 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 { Namespace } from 'socket.io';
5
- /**
6
- * 集群行为备忘:
7
- * 当socket.io通过adapter在集群间通信时,测试行为如下(测试环境为pm2 + cluster-adapter,其它adpater启用时需要再测一次):
8
- * 1)当client连接到node1并join room1时,只有node1上会有create room事件(room结构本身在结点间并不共享)
9
- * 2)当某一个node执行 .adapter.to('room1').emit()时,连接到任一结点的client均能收到消息(但使用room可以实现跨结点推包)
10
- * 3) serverSideEmit执行时如果有callback,而不是所有的接收者都执行callback的话,会抛出一个异常(意味着不需要本结点来判定是否收到全部的返回值了)
11
- */
12
- export default class DataSubscriber<ED extends EntityDict & BaseEntityDict, Context extends BackendRuntimeContext<ED>> {
13
- private ns;
14
- private nsServer?;
15
- private contextBuilder;
16
- constructor(ns: Namespace, contextBuilder: (scene?: string) => Promise<Context>, nsServer?: Namespace);
17
- /**
18
- * 来自外部的socket连接,监听数据变化
19
- */
20
- private startup;
21
- publishEvent(event: string, records: OpRecord<ED>[], sid?: string): void;
22
- publishVolatileTrigger(entity: keyof ED, name: string, instanceNumber: string, ids: string[], cxtStr: string, option: OperateOption): void;
23
- }
1
+ import { EntityDict, OperateOption, OpRecord } 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 { Namespace } from 'socket.io';
5
+ /**
6
+ * 集群行为备忘:
7
+ * 当socket.io通过adapter在集群间通信时,测试行为如下(测试环境为pm2 + cluster-adapter,其它adpater启用时需要再测一次):
8
+ * 1)当client连接到node1并join room1时,只有node1上会有create room事件(room结构本身在结点间并不共享)
9
+ * 2)当某一个node执行 .adapter.to('room1').emit()时,连接到任一结点的client均能收到消息(但使用room可以实现跨结点推包)
10
+ * 3) serverSideEmit执行时如果有callback,而不是所有的接收者都执行callback的话,会抛出一个异常(意味着不需要本结点来判定是否收到全部的返回值了)
11
+ */
12
+ export default class DataSubscriber<ED extends EntityDict & BaseEntityDict, Context extends BackendRuntimeContext<ED>> {
13
+ private ns;
14
+ private nsServer?;
15
+ private contextBuilder;
16
+ constructor(ns: Namespace, contextBuilder: (scene?: string) => Promise<Context>, nsServer?: Namespace);
17
+ /**
18
+ * 来自外部的socket连接,监听数据变化
19
+ */
20
+ private startup;
21
+ publishEvent(event: string, records: OpRecord<ED>[], sid?: string): void;
22
+ publishVolatileTrigger(entity: keyof ED, name: string, instanceNumber: string, ids: string[], cxtStr: string, option: OperateOption): void;
23
+ }
@@ -1,83 +1,83 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const env_1 = require("./env");
4
- const console_1 = require("console");
5
- /**
6
- * 集群行为备忘:
7
- * 当socket.io通过adapter在集群间通信时,测试行为如下(测试环境为pm2 + cluster-adapter,其它adpater启用时需要再测一次):
8
- * 1)当client连接到node1并join room1时,只有node1上会有create room事件(room结构本身在结点间并不共享)
9
- * 2)当某一个node执行 .adapter.to('room1').emit()时,连接到任一结点的client均能收到消息(但使用room可以实现跨结点推包)
10
- * 3) serverSideEmit执行时如果有callback,而不是所有的接收者都执行callback的话,会抛出一个异常(意味着不需要本结点来判定是否收到全部的返回值了)
11
- */
12
- class DataSubscriber {
13
- ns;
14
- nsServer;
15
- contextBuilder;
16
- constructor(ns, contextBuilder, nsServer) {
17
- this.ns = ns;
18
- this.nsServer = nsServer;
19
- this.contextBuilder = contextBuilder;
20
- this.startup();
21
- }
22
- /**
23
- * 来自外部的socket连接,监听数据变化
24
- */
25
- startup() {
26
- this.ns.on('connection', async (socket) => {
27
- try {
28
- const { instanceId } = (0, env_1.getClusterInfo)();
29
- // console.log('on connection', instanceId);
30
- socket.on('sub', async (events) => {
31
- events.forEach((event) => socket.join(event));
32
- });
33
- socket.on('unsub', (events) => {
34
- // console.log('instance:', process.env.NODE_APP_INSTANCE, 'on unsub', JSON.stringify(ids));
35
- events.forEach((id) => {
36
- socket.leave(id);
37
- });
38
- });
39
- }
40
- catch (err) {
41
- socket.emit('error', err.toString());
42
- }
43
- });
44
- if (this.nsServer) {
45
- this.nsServer.on('connection', async (socket) => {
46
- try {
47
- const { instanceId } = (0, env_1.getClusterInfo)();
48
- console.log('on nsServer connection', instanceId);
49
- socket.on('sub', async (events) => {
50
- console.log('on nsServer sub', instanceId, events);
51
- events.forEach((event) => socket.join(event));
52
- });
53
- socket.on('unsub', (events) => {
54
- // console.log('instance:', process.env.NODE_APP_INSTANCE, 'on unsub', JSON.stringify(ids));
55
- events.forEach((id) => {
56
- socket.leave(id);
57
- });
58
- });
59
- }
60
- catch (err) {
61
- socket.emit('error', err.toString());
62
- }
63
- });
64
- }
65
- }
66
- publishEvent(event, records, sid) {
67
- const { instanceId } = (0, env_1.getClusterInfo)();
68
- // console.log('publishEvent', instanceId);
69
- if (sid) {
70
- this.ns.to(event).except(sid).emit('data', records, event);
71
- }
72
- else {
73
- this.ns.to(event).emit('data', records, event);
74
- }
75
- }
76
- publishVolatileTrigger(entity, name, instanceNumber, ids, cxtStr, option) {
77
- const { instanceId } = (0, env_1.getClusterInfo)();
78
- // console.log('publishVolatileTrigger', instanceId, instanceNumber);
79
- (0, console_1.assert)(this.nsServer);
80
- this.nsServer.to(`${name}-${instanceNumber}`).emit('data', entity, name, ids, cxtStr, option);
81
- }
82
- }
83
- exports.default = DataSubscriber;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const env_1 = require("./env");
4
+ const console_1 = require("console");
5
+ /**
6
+ * 集群行为备忘:
7
+ * 当socket.io通过adapter在集群间通信时,测试行为如下(测试环境为pm2 + cluster-adapter,其它adpater启用时需要再测一次):
8
+ * 1)当client连接到node1并join room1时,只有node1上会有create room事件(room结构本身在结点间并不共享)
9
+ * 2)当某一个node执行 .adapter.to('room1').emit()时,连接到任一结点的client均能收到消息(但使用room可以实现跨结点推包)
10
+ * 3) serverSideEmit执行时如果有callback,而不是所有的接收者都执行callback的话,会抛出一个异常(意味着不需要本结点来判定是否收到全部的返回值了)
11
+ */
12
+ class DataSubscriber {
13
+ ns;
14
+ nsServer;
15
+ contextBuilder;
16
+ constructor(ns, contextBuilder, nsServer) {
17
+ this.ns = ns;
18
+ this.nsServer = nsServer;
19
+ this.contextBuilder = contextBuilder;
20
+ this.startup();
21
+ }
22
+ /**
23
+ * 来自外部的socket连接,监听数据变化
24
+ */
25
+ startup() {
26
+ this.ns.on('connection', async (socket) => {
27
+ try {
28
+ const { instanceId } = (0, env_1.getClusterInfo)();
29
+ // console.log('on connection', instanceId);
30
+ socket.on('sub', async (events) => {
31
+ events.forEach((event) => socket.join(event));
32
+ });
33
+ socket.on('unsub', (events) => {
34
+ // console.log('instance:', process.env.NODE_APP_INSTANCE, 'on unsub', JSON.stringify(ids));
35
+ events.forEach((id) => {
36
+ socket.leave(id);
37
+ });
38
+ });
39
+ }
40
+ catch (err) {
41
+ socket.emit('error', err.toString());
42
+ }
43
+ });
44
+ if (this.nsServer) {
45
+ this.nsServer.on('connection', async (socket) => {
46
+ try {
47
+ const { instanceId } = (0, env_1.getClusterInfo)();
48
+ console.log('on nsServer connection', instanceId);
49
+ socket.on('sub', async (events) => {
50
+ console.log('on nsServer sub', instanceId, events);
51
+ events.forEach((event) => socket.join(event));
52
+ });
53
+ socket.on('unsub', (events) => {
54
+ // console.log('instance:', process.env.NODE_APP_INSTANCE, 'on unsub', JSON.stringify(ids));
55
+ events.forEach((id) => {
56
+ socket.leave(id);
57
+ });
58
+ });
59
+ }
60
+ catch (err) {
61
+ socket.emit('error', err.toString());
62
+ }
63
+ });
64
+ }
65
+ }
66
+ publishEvent(event, records, sid) {
67
+ const { instanceId } = (0, env_1.getClusterInfo)();
68
+ // console.log('publishEvent', instanceId);
69
+ if (sid) {
70
+ this.ns.to(event).except(sid).emit('data', records, event);
71
+ }
72
+ else {
73
+ this.ns.to(event).emit('data', records, event);
74
+ }
75
+ }
76
+ publishVolatileTrigger(entity, name, instanceNumber, ids, cxtStr, option) {
77
+ const { instanceId } = (0, env_1.getClusterInfo)();
78
+ // console.log('publishVolatileTrigger', instanceId, instanceNumber);
79
+ (0, console_1.assert)(this.nsServer);
80
+ this.nsServer.to(`${name}-${instanceNumber}`).emit('data', entity, name, ids, cxtStr, option);
81
+ }
82
+ }
83
+ exports.default = DataSubscriber;
@@ -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,42 +1,42 @@
1
- {
2
- "name": "oak-backend-base",
3
- "version": "3.3.3",
4
- "description": "oak-backend-base",
5
- "main": "lib/index",
6
- "author": {
7
- "name": "XuChang"
8
- },
9
- "files": [
10
- "lib/**/*"
11
- ],
12
- "scripts": {
13
- "copy-files": "copyfiles -u 1 src/**/*.json lib/",
14
- "test": "ts-node test/test.ts",
15
- "test2": "ts-node test/testDbStore.ts",
16
- "build": "tsc && npm run copy-files"
17
- },
18
- "dependencies": {
19
- "lodash": "^4.17.21",
20
- "mysql": "^2.18.1",
21
- "mysql2": "^2.3.3",
22
- "node-schedule": "^2.1.0",
23
- "oak-common-aspect": "^2.2.4",
24
- "oak-db": "^3.1.0",
25
- "oak-domain": "^4.2.4",
26
- "oak-frontend-base": "^4.2.5",
27
- "socket.io": "^4.7.2",
28
- "socket.io-client": "^4.7.2",
29
- "uuid": "^8.3.2"
30
- },
31
- "license": "ISC",
32
- "devDependencies": {
33
- "@types/lodash": "^4.14.198",
34
- "@types/node": "^20.6.0",
35
- "@types/node-schedule": "^2.1.0",
36
- "@types/uuid": "^8.3.4",
37
- "copyfiles": "^2.4.1",
38
- "ts-node": "^10.9.1",
39
- "tslib": "^2.4.0",
40
- "typescript": "^5.2.2"
41
- }
42
- }
1
+ {
2
+ "name": "oak-backend-base",
3
+ "version": "3.3.4",
4
+ "description": "oak-backend-base",
5
+ "main": "lib/index",
6
+ "author": {
7
+ "name": "XuChang"
8
+ },
9
+ "files": [
10
+ "lib/**/*"
11
+ ],
12
+ "scripts": {
13
+ "copy-files": "copyfiles -u 1 src/**/*.json lib/",
14
+ "test": "ts-node test/test.ts",
15
+ "test2": "ts-node test/testDbStore.ts",
16
+ "build": "tsc && npm run copy-files"
17
+ },
18
+ "dependencies": {
19
+ "lodash": "^4.17.21",
20
+ "mysql": "^2.18.1",
21
+ "mysql2": "^2.3.3",
22
+ "node-schedule": "^2.1.0",
23
+ "oak-common-aspect": "^2.2.5",
24
+ "oak-db": "^3.1.0",
25
+ "oak-domain": "^4.2.8",
26
+ "oak-frontend-base": "^4.2.7",
27
+ "socket.io": "^4.7.2",
28
+ "socket.io-client": "^4.7.2",
29
+ "uuid": "^8.3.2"
30
+ },
31
+ "license": "ISC",
32
+ "devDependencies": {
33
+ "@types/lodash": "^4.14.198",
34
+ "@types/node": "^20.6.0",
35
+ "@types/node-schedule": "^2.1.0",
36
+ "@types/uuid": "^8.3.4",
37
+ "copyfiles": "^2.4.1",
38
+ "ts-node": "^10.9.1",
39
+ "tslib": "^2.4.0",
40
+ "typescript": "^5.2.2"
41
+ }
42
+ }