taon 21.0.51 → 21.0.53
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/bin/taon +5 -5
- package/bin/taon-debug +5 -5
- package/bin/taon-debug-brk +4 -4
- package/browser/fesm2022/taon-browser.mjs +11 -1
- package/browser/fesm2022/taon-browser.mjs.map +1 -1
- package/browser/package.json +1 -1
- package/browser-prod/fesm2022/taon-browser.mjs +11 -1
- package/browser-prod/fesm2022/taon-browser.mjs.map +1 -1
- package/browser-prod/package.json +1 -1
- package/icon-menu-taon.svg +15 -15
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/endpoint-context.d.ts +1 -1
- package/lib/endpoint-context.js +11 -6
- package/lib/endpoint-context.js.map +1 -1
- package/lib/package.json +1 -1
- package/lib/ui/index.js +2 -2
- package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
- package/lib-prod/base-classes/base-abstract-entity.js +33 -0
- package/lib-prod/base-classes/base-angular-service.js +56 -0
- package/lib-prod/base-classes/base-class.js +37 -0
- package/lib-prod/base-classes/base-context.js +21 -0
- package/lib-prod/base-classes/base-controller.js +162 -0
- package/lib-prod/base-classes/base-crud-controller.js +235 -0
- package/lib-prod/base-classes/base-custom-repository.js +20 -0
- package/lib-prod/base-classes/base-electron-service.js +0 -0
- package/lib-prod/base-classes/base-entity.js +32 -0
- package/lib-prod/base-classes/base-file-upload.middleware.js +78 -0
- package/lib-prod/base-classes/base-injector.js +202 -0
- package/lib-prod/base-classes/base-middleware.js +6 -0
- package/lib-prod/base-classes/base-migration.js +23 -0
- package/lib-prod/base-classes/base-provider.js +6 -0
- package/lib-prod/base-classes/base-repository.js +589 -0
- package/lib-prod/base-classes/base-subscriber-for-entity.js +154 -0
- package/lib-prod/base-classes/base.js +0 -0
- package/lib-prod/build-info._auto-generated_.js +14 -0
- package/lib-prod/config/controller-config.js +28 -0
- package/lib-prod/config/controller-options.js +6 -0
- package/lib-prod/config/method-config.js +9 -0
- package/lib-prod/config/param-config.js +9 -0
- package/lib-prod/constants.js +29 -0
- package/lib-prod/context-db-migrations.js +339 -0
- package/lib-prod/create-context.js +152 -0
- package/lib-prod/decorators/classes/controller-decorator.js +21 -0
- package/lib-prod/decorators/classes/entity-decorator.js +49 -0
- package/lib-prod/decorators/classes/middleware-decorator.js +26 -0
- package/lib-prod/decorators/classes/migration-decorator.js +24 -0
- package/lib-prod/decorators/classes/provider-decorator.js +25 -0
- package/lib-prod/decorators/classes/repository-decorator.js +24 -0
- package/lib-prod/decorators/classes/subscriber-decorator.js +25 -0
- package/lib-prod/decorators/decorator-abstract-opt.js +5 -0
- package/lib-prod/decorators/http/http-decorators.js +5 -0
- package/lib-prod/decorators/http/http-methods-decorators.js +144 -0
- package/lib-prod/decorators/http/http-params-decorators.js +68 -0
- package/lib-prod/dependency-injection/di-container.js +31 -0
- package/lib-prod/endpoint-context-storage.js +36 -0
- package/lib-prod/endpoint-context.js +2033 -0
- package/lib-prod/entity-process.js +214 -0
- package/lib-prod/env/env.angular-node-app.js +130 -0
- package/lib-prod/env/env.docs-webapp.js +130 -0
- package/lib-prod/env/env.electron-app.js +130 -0
- package/lib-prod/env/env.mobile-app.js +130 -0
- package/lib-prod/env/env.npm-lib-and-cli-tool.js +130 -0
- package/lib-prod/env/env.vscode-plugin.js +130 -0
- package/lib-prod/env/index.js +6 -0
- package/lib-prod/express-types.js +0 -0
- package/lib-prod/formly/formly.models.js +0 -0
- package/lib-prod/formly/fromly.js +184 -0
- package/lib-prod/formly/type-from-entity.js +58 -0
- package/lib-prod/get-response-value.js +19 -0
- package/lib-prod/global-state/taon-global-state/index.js +5 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.abstract.context.js +20 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.constants.js +10 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.controller.js +48 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.entity.js +48 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.middleware.js +22 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.models.js +34 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.provider.js +22 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.repository.js +47 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.subscriber.js +29 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.utils.js +11 -0
- package/lib-prod/global-state/taon-transaction-registry/index.js +10 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.abstract.context.js +22 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.constants.js +8 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.controller.js +41 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.entity.js +56 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.middleware.js +22 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.models.js +10 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.provider.js +22 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.repository.js +36 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.subscriber.js +29 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.utils.js +6 -0
- package/lib-prod/helpers/class-helpers.js +195 -0
- package/lib-prod/helpers/clone-obj.js +21 -0
- package/lib-prod/helpers/taon-helpers.js +129 -0
- package/lib-prod/index._auto-generated_.js +0 -0
- package/lib-prod/index.js +231 -0
- package/lib-prod/inject.js +34 -0
- package/lib-prod/migrations/index.js +1 -0
- package/lib-prod/migrations/migrations_index._auto-generated_.js +0 -0
- package/lib-prod/models.js +109 -0
- package/lib-prod/orm/columns.js +124 -0
- package/lib-prod/orm/index.js +1 -0
- package/lib-prod/package.json +1 -1
- package/lib-prod/realtime/realtime-client.js +196 -0
- package/lib-prod/realtime/realtime-core.js +82 -0
- package/lib-prod/realtime/realtime-server.js +252 -0
- package/lib-prod/realtime/realtime-strategy/index.js +4 -0
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-ipc.js +226 -0
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-mock.js +262 -0
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-socket-io.js +21 -0
- package/lib-prod/realtime/realtime-strategy/realtime-strategy.js +14 -0
- package/lib-prod/realtime/realtime-subs-manager.js +96 -0
- package/lib-prod/realtime/realtime.models.js +0 -0
- package/lib-prod/symbols.js +109 -0
- package/lib-prod/ui/index.js +5 -0
- package/lib-prod/ui/taon-admin-mode-configuration/index.js +5 -0
- package/lib-prod/validators.js +74 -0
- package/package.json +1 -1
- package/websql/fesm2022/taon-websql.mjs +11 -1
- package/websql/fesm2022/taon-websql.mjs.map +1 -1
- package/websql/package.json +1 -1
- package/websql-prod/fesm2022/taon-websql.mjs +11 -1
- package/websql-prod/fesm2022/taon-websql.mjs.map +1 -1
- package/websql-prod/package.json +1 -1
- package/lib-prod/base-classes/base-abstract-entity.ts +0 -34
- package/lib-prod/base-classes/base-angular-service.ts +0 -107
- package/lib-prod/base-classes/base-class.ts +0 -46
- package/lib-prod/base-classes/base-context.ts +0 -21
- package/lib-prod/base-classes/base-controller.ts +0 -240
- package/lib-prod/base-classes/base-crud-controller.ts +0 -298
- package/lib-prod/base-classes/base-custom-repository.ts +0 -10
- package/lib-prod/base-classes/base-electron-service.ts +0 -60
- package/lib-prod/base-classes/base-entity.ts +0 -28
- package/lib-prod/base-classes/base-file-upload.middleware.ts +0 -92
- package/lib-prod/base-classes/base-injector.ts +0 -278
- package/lib-prod/base-classes/base-middleware.ts +0 -71
- package/lib-prod/base-classes/base-migration.ts +0 -26
- package/lib-prod/base-classes/base-provider.ts +0 -8
- package/lib-prod/base-classes/base-repository.ts +0 -942
- package/lib-prod/base-classes/base-subscriber-for-entity.ts +0 -196
- package/lib-prod/base-classes/base.ts +0 -31
- package/lib-prod/build-info._auto-generated_.ts +0 -27
- package/lib-prod/config/controller-config.ts +0 -58
- package/lib-prod/config/controller-options.ts +0 -19
- package/lib-prod/config/method-config.ts +0 -55
- package/lib-prod/config/param-config.ts +0 -16
- package/lib-prod/constants.ts +0 -63
- package/lib-prod/context-db-migrations.ts +0 -488
- package/lib-prod/create-context.ts +0 -345
- package/lib-prod/decorators/classes/controller-decorator.ts +0 -25
- package/lib-prod/decorators/classes/entity-decorator.ts +0 -57
- package/lib-prod/decorators/classes/middleware-decorator.ts +0 -29
- package/lib-prod/decorators/classes/migration-decorator.ts +0 -27
- package/lib-prod/decorators/classes/provider-decorator.ts +0 -28
- package/lib-prod/decorators/classes/repository-decorator.ts +0 -26
- package/lib-prod/decorators/classes/subscriber-decorator.ts +0 -28
- package/lib-prod/decorators/decorator-abstract-opt.ts +0 -4
- package/lib-prod/decorators/http/http-decorators.ts +0 -26
- package/lib-prod/decorators/http/http-methods-decorators.ts +0 -275
- package/lib-prod/decorators/http/http-params-decorators.ts +0 -105
- package/lib-prod/dependency-injection/di-container.ts +0 -39
- package/lib-prod/endpoint-context-storage.ts +0 -47
- package/lib-prod/endpoint-context.ts +0 -3105
- package/lib-prod/entity-process.ts +0 -286
- package/lib-prod/env/env.angular-node-app.ts +0 -66
- package/lib-prod/env/env.docs-webapp.ts +0 -66
- package/lib-prod/env/env.electron-app.ts +0 -66
- package/lib-prod/env/env.mobile-app.ts +0 -66
- package/lib-prod/env/env.npm-lib-and-cli-tool.ts +0 -66
- package/lib-prod/env/env.vscode-plugin.ts +0 -66
- package/lib-prod/env/index.ts +0 -6
- package/lib-prod/express-types.ts +0 -4
- package/lib-prod/formly/formly.models.ts +0 -7
- package/lib-prod/formly/fromly.ts +0 -261
- package/lib-prod/formly/type-from-entity.ts +0 -80
- package/lib-prod/get-response-value.ts +0 -30
- package/lib-prod/global-state/taon-global-state/index.ts +0 -6
- package/lib-prod/global-state/taon-global-state/taon-global-state.abstract.context.ts +0 -21
- package/lib-prod/global-state/taon-global-state/taon-global-state.constants.ts +0 -9
- package/lib-prod/global-state/taon-global-state/taon-global-state.controller.ts +0 -44
- package/lib-prod/global-state/taon-global-state/taon-global-state.entity.ts +0 -40
- package/lib-prod/global-state/taon-global-state/taon-global-state.middleware.ts +0 -12
- package/lib-prod/global-state/taon-global-state/taon-global-state.models.ts +0 -48
- package/lib-prod/global-state/taon-global-state/taon-global-state.provider.ts +0 -16
- package/lib-prod/global-state/taon-global-state/taon-global-state.repository.ts +0 -47
- package/lib-prod/global-state/taon-global-state/taon-global-state.subscriber.ts +0 -18
- package/lib-prod/global-state/taon-global-state/taon-global-state.utils.ts +0 -21
- package/lib-prod/global-state/taon-transaction-registry/index.ts +0 -11
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.abstract.context.ts +0 -23
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.constants.ts +0 -7
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.controller.ts +0 -38
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.entity.ts +0 -54
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.middleware.ts +0 -12
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.models.ts +0 -6
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.provider.ts +0 -16
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.repository.ts +0 -29
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.subscriber.ts +0 -20
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.utils.ts +0 -9
- package/lib-prod/helpers/class-helpers.ts +0 -315
- package/lib-prod/helpers/clone-obj.ts +0 -24
- package/lib-prod/helpers/taon-helpers.ts +0 -181
- package/lib-prod/index._auto-generated_.ts +0 -5
- package/lib-prod/index.ts +0 -323
- package/lib-prod/inject.ts +0 -111
- package/lib-prod/lib-info.md +0 -8
- package/lib-prod/migrations/index.ts +0 -2
- package/lib-prod/migrations/migrations-info.md +0 -6
- package/lib-prod/migrations/migrations_index._auto-generated_.ts +0 -5
- package/lib-prod/models.ts +0 -427
- package/lib-prod/orm/columns.ts +0 -121
- package/lib-prod/orm/index.ts +0 -62
- package/lib-prod/realtime/realtime-client.ts +0 -288
- package/lib-prod/realtime/realtime-core.ts +0 -134
- package/lib-prod/realtime/realtime-server.ts +0 -398
- package/lib-prod/realtime/realtime-strategy/index.ts +0 -4
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-ipc.ts +0 -344
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-mock.ts +0 -349
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-socket-io.ts +0 -30
- package/lib-prod/realtime/realtime-strategy/realtime-strategy.ts +0 -21
- package/lib-prod/realtime/realtime-subs-manager.ts +0 -127
- package/lib-prod/realtime/realtime.models.ts +0 -33
- package/lib-prod/symbols.ts +0 -136
- package/lib-prod/ui/index.ts +0 -1
- package/lib-prod/ui/taon-admin-mode-configuration/index.ts +0 -1
- package/lib-prod/validators.ts +0 -103
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { Subject } from "rxjs";
|
|
2
|
+
import { ___NS__isArray, ___NS__isFunction, ___NS__isObject, ___NS__isString, Helpers__NS__error, UtilsOs__NS__isElectron, UtilsOs__NS__isWebSQL } from "tnp-core/lib-prod";
|
|
3
|
+
import { ClassHelpers__NS__getClassFnFromObject, ClassHelpers__NS__getName, ClassHelpers__NS__getUniqueKey } from "../helpers/class-helpers";
|
|
4
|
+
import { Symbols__NS__REALTIME } from "../symbols";
|
|
5
|
+
class RealtimeServer {
|
|
6
|
+
// private jobs = {};
|
|
7
|
+
constructor(core) {
|
|
8
|
+
this.core = core;
|
|
9
|
+
this.core = core;
|
|
10
|
+
if (core.ctx.disabledRealtime || this.core.ctx.isRemoteHost) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
this.init();
|
|
14
|
+
}
|
|
15
|
+
//#region methods & getters / init
|
|
16
|
+
init() {
|
|
17
|
+
const nspPathGlobal = this.core.pathFor();
|
|
18
|
+
const nspPathRealtime = this.core.pathFor(
|
|
19
|
+
Symbols__NS__REALTIME.NAMESPACE(this.core.ctx.contextName)
|
|
20
|
+
);
|
|
21
|
+
const cors = {
|
|
22
|
+
origin: this.core.ctx.frontendHostUri.origin,
|
|
23
|
+
// only origin needs to be set - pathname not needed
|
|
24
|
+
methods: this.core.allHttpMethods
|
|
25
|
+
};
|
|
26
|
+
this.core.connectSocketBE = this.core.strategy.ioServer(
|
|
27
|
+
UtilsOs__NS__isWebSQL ? this.core.ctx.uriOrigin : this.core.ctx.serverTcpUdp,
|
|
28
|
+
{
|
|
29
|
+
path: nspPathGlobal.pathname,
|
|
30
|
+
cors
|
|
31
|
+
},
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
this.core.ctx
|
|
34
|
+
);
|
|
35
|
+
this.core.ctx.logRealtime && console.info(
|
|
36
|
+
`[backend] CREATE GLOBAL NAMESPACE: '${this.core.connectSocketBE.path()}' , path: '${nspPathGlobal.pathname}'`
|
|
37
|
+
);
|
|
38
|
+
this.core.connectSocketBE.on("connection", (clientSocket) => {
|
|
39
|
+
this.core.ctx.logRealtime && console.info(
|
|
40
|
+
`[backend] client connected to namespace "${nspPathGlobal.pathname}", host: ${this.core.ctx.host}`
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
this.core.socketBE = this.core.strategy.ioServer(
|
|
44
|
+
UtilsOs__NS__isWebSQL || UtilsOs__NS__isElectron ? this.core.ctx.uriOrigin : this.core.ctx.serverTcpUdp,
|
|
45
|
+
{
|
|
46
|
+
path: nspPathRealtime.pathname,
|
|
47
|
+
cors
|
|
48
|
+
},
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
this.core.ctx
|
|
51
|
+
);
|
|
52
|
+
this.core.ctx.logRealtime && console.info(
|
|
53
|
+
`[backend] CREATE REALTIME NAMESPACE: '${this.core.socketBE.path()}' , path: '${nspPathRealtime.pathname}' `
|
|
54
|
+
);
|
|
55
|
+
this.core.socketBE.on("connection", (backendSocketForClient) => {
|
|
56
|
+
this.core.ctx.logRealtime && console.info(
|
|
57
|
+
`[backend] client connected to namespace "${nspPathRealtime.pathname}", host: ${this.core.ctx.host}`
|
|
58
|
+
);
|
|
59
|
+
backendSocketForClient.on(
|
|
60
|
+
Symbols__NS__REALTIME.ROOM_SUBSCRIBE_CUSTOM(this.core.ctx.contextName),
|
|
61
|
+
(roomName) => {
|
|
62
|
+
this.core.ctx.logRealtime && console.info(
|
|
63
|
+
`Joining room ${roomName} in namespace REALTIME host: ${this.core.ctx.contextName}/${this.core.ctx.host}`
|
|
64
|
+
);
|
|
65
|
+
backendSocketForClient.join(roomName);
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
backendSocketForClient.on(
|
|
69
|
+
Symbols__NS__REALTIME.ROOM_SUBSCRIBE_ENTITY_UPDATE_EVENTS(
|
|
70
|
+
this.core.ctx.contextName
|
|
71
|
+
),
|
|
72
|
+
(roomName) => {
|
|
73
|
+
this.core.ctx.logRealtime && console.info(
|
|
74
|
+
`[backend] Joining room ${roomName} in namespace REALTIME host: ${this.core.ctx.contextName}/${this.core.ctx.host}`
|
|
75
|
+
);
|
|
76
|
+
backendSocketForClient.join(roomName);
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
backendSocketForClient.on(
|
|
80
|
+
Symbols__NS__REALTIME.ROOM_SUBSCRIBE_ENTITY_PROPERTY_UPDATE_EVENTS(
|
|
81
|
+
this.core.ctx.contextName
|
|
82
|
+
),
|
|
83
|
+
(roomName) => {
|
|
84
|
+
this.core.ctx.logRealtime && console.info(
|
|
85
|
+
`[backend] Joining room ${roomName} in namespace REALTIME host: ${this.core.ctx.contextName}/${this.core.ctx.host}`
|
|
86
|
+
);
|
|
87
|
+
backendSocketForClient.join(roomName);
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
backendSocketForClient.on(
|
|
91
|
+
Symbols__NS__REALTIME.ROOM_UNSUBSCRIBE_CUSTOM(this.core.ctx.contextName),
|
|
92
|
+
(roomName) => {
|
|
93
|
+
this.core.ctx.logRealtime && console.info(
|
|
94
|
+
`[backend] Leaving room ${roomName} in namespace REALTIME host: ${this.core.ctx.contextName}/${this.core.ctx.host}`
|
|
95
|
+
);
|
|
96
|
+
backendSocketForClient.leave(roomName);
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
backendSocketForClient.on(
|
|
100
|
+
Symbols__NS__REALTIME.ROOM_UNSUBSCRIBE_ENTITY_UPDATE_EVENTS(
|
|
101
|
+
this.core.ctx.contextName
|
|
102
|
+
),
|
|
103
|
+
(roomName) => {
|
|
104
|
+
this.core.ctx.logRealtime && console.info(
|
|
105
|
+
`[backend] Leaving room ${roomName} in namespace REALTIME host: ${this.core.ctx.contextName}/${this.core.ctx.host}`
|
|
106
|
+
);
|
|
107
|
+
backendSocketForClient.leave(roomName);
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
backendSocketForClient.on(
|
|
111
|
+
Symbols__NS__REALTIME.ROOM_UNSUBSCRIBE_ENTITY_PROPERTY_UPDATE_EVENTS(
|
|
112
|
+
this.core.ctx.contextName
|
|
113
|
+
),
|
|
114
|
+
(roomName) => {
|
|
115
|
+
this.core.ctx.logRealtime && console.info(
|
|
116
|
+
`[backend] Leaving room ${roomName} in namespace REALTIME host: ${this.core.ctx.contextName}/${this.core.ctx.host}`
|
|
117
|
+
);
|
|
118
|
+
backendSocketForClient.leave(roomName);
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region methods & getters / trigger changes
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
126
|
+
triggerChanges(entityObjOrClass, property, valueOfUniqueProperty, customEvent, customEventData) {
|
|
127
|
+
let roomName;
|
|
128
|
+
if (this.core.ctx.disabledRealtime || this.core.ctx.isRemoteHost) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (customEvent) {
|
|
132
|
+
roomName = Symbols__NS__REALTIME.ROOM_NAME_CUSTOM(
|
|
133
|
+
this.core.ctx.contextName,
|
|
134
|
+
customEvent
|
|
135
|
+
);
|
|
136
|
+
} else {
|
|
137
|
+
let entityFn = entityObjOrClass;
|
|
138
|
+
const entityIsObject = !___NS__isFunction(entityObjOrClass) && ___NS__isObject(entityObjOrClass);
|
|
139
|
+
if (entityIsObject) {
|
|
140
|
+
entityFn = ClassHelpers__NS__getClassFnFromObject(entityObjOrClass);
|
|
141
|
+
}
|
|
142
|
+
const uniqueKey = ClassHelpers__NS__getUniqueKey(entityFn);
|
|
143
|
+
if (entityIsObject) {
|
|
144
|
+
valueOfUniqueProperty = entityObjOrClass[uniqueKey];
|
|
145
|
+
}
|
|
146
|
+
if (!valueOfUniqueProperty) {
|
|
147
|
+
Helpers__NS__error(
|
|
148
|
+
`[Taon][Realtime] Entity without iD ! ${ClassHelpers__NS__getName(
|
|
149
|
+
entityFn
|
|
150
|
+
)} `,
|
|
151
|
+
true,
|
|
152
|
+
true
|
|
153
|
+
);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
roomName = ___NS__isString(property) ? Symbols__NS__REALTIME.ROOM_NAME_UPDATE_ENTITY_PROPERTY(
|
|
157
|
+
this.core.ctx.contextName,
|
|
158
|
+
ClassHelpers__NS__getName(entityFn),
|
|
159
|
+
property,
|
|
160
|
+
valueOfUniqueProperty
|
|
161
|
+
) : Symbols__NS__REALTIME.ROOM_NAME_UPDATE_ENTITY(
|
|
162
|
+
this.core.ctx.contextName,
|
|
163
|
+
ClassHelpers__NS__getName(entityFn),
|
|
164
|
+
valueOfUniqueProperty
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
this.core.socketBE.in(roomName).emit(
|
|
168
|
+
roomName,
|
|
169
|
+
// roomName == eventName in room na
|
|
170
|
+
customEvent ? customEventData : ""
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region entity changes
|
|
175
|
+
//#region methods & getters / trigger entity changes
|
|
176
|
+
triggerEntityChanges(entityObjOrClass, idToTrigger) {
|
|
177
|
+
if (this.core.ctx.disabledRealtime) {
|
|
178
|
+
const className = ClassHelpers__NS__getName(entityObjOrClass);
|
|
179
|
+
console.warn(
|
|
180
|
+
`[Taon][TriggerEntityChanges] Entity "${className}' is not realtime`
|
|
181
|
+
);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
this.triggerChanges(entityObjOrClass, void 0, idToTrigger);
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region methods & getters / trigger entity property changes
|
|
188
|
+
triggerEntityPropertyChanges(entityObjOrClass, property, idToTrigger) {
|
|
189
|
+
if (this.core.ctx.disabledRealtime) {
|
|
190
|
+
const className = ClassHelpers__NS__getName(entityObjOrClass);
|
|
191
|
+
console.warn(
|
|
192
|
+
`[Taon][TriggerEntityPropertyChanges][property=${property}] Entity "${className}' is not realtime`
|
|
193
|
+
);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (___NS__isArray(property)) {
|
|
197
|
+
property.forEach((propertyFromArr) => {
|
|
198
|
+
this.triggerChanges(
|
|
199
|
+
entityObjOrClass,
|
|
200
|
+
propertyFromArr,
|
|
201
|
+
idToTrigger
|
|
202
|
+
);
|
|
203
|
+
});
|
|
204
|
+
} else {
|
|
205
|
+
this.triggerChanges(entityObjOrClass, property, idToTrigger);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region methods & getters / trigger entity table changes
|
|
210
|
+
triggerEntityTableChanges(entityClassOrInstance) {
|
|
211
|
+
const className = ClassHelpers__NS__getName(entityClassOrInstance);
|
|
212
|
+
if (this.core.ctx.disabledRealtime) {
|
|
213
|
+
console.warn(
|
|
214
|
+
`[Taon][TriggerEntityTableChanges] Entity "${className}' is not realtime`
|
|
215
|
+
);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
this.triggerChanges(
|
|
219
|
+
entityClassOrInstance,
|
|
220
|
+
void 0,
|
|
221
|
+
void 0,
|
|
222
|
+
Symbols__NS__REALTIME.TABLE_CHANGE(this.core.ctx.contextName, className)
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
//#endregion
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region custom changes
|
|
228
|
+
//#region methods & getters / trigger custom event
|
|
229
|
+
triggerCustomEvent(customEvent, dataToPush) {
|
|
230
|
+
this.triggerChanges(void 0, void 0, void 0, customEvent, dataToPush);
|
|
231
|
+
}
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region methods & getters / listen custom events from users
|
|
234
|
+
/**
|
|
235
|
+
* Listen to custom events from users
|
|
236
|
+
* @param customEvent global event name
|
|
237
|
+
*/
|
|
238
|
+
listenChangesCustomEvent(customEvent) {
|
|
239
|
+
const sub = new Subject();
|
|
240
|
+
this.core.socketBE.on("connection", (backendSocketForClient) => {
|
|
241
|
+
backendSocketForClient.on(customEvent, (data, ...args) => {
|
|
242
|
+
sub.next(data);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
return sub.asObservable();
|
|
246
|
+
}
|
|
247
|
+
//#endregion
|
|
248
|
+
//#endregion
|
|
249
|
+
}
|
|
250
|
+
export {
|
|
251
|
+
RealtimeServer
|
|
252
|
+
};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { ipcMain } from "electron";
|
|
2
|
+
import { Symbols__NS__REALTIME } from "../../symbols";
|
|
3
|
+
import { RealtimeStrategy } from "./realtime-strategy";
|
|
4
|
+
class MockServerIpc {
|
|
5
|
+
//#region constructor
|
|
6
|
+
constructor(contextName) {
|
|
7
|
+
this.contextName = contextName;
|
|
8
|
+
MockServerIpc.serverByContextName.set(contextName, this);
|
|
9
|
+
}
|
|
10
|
+
static serverByContextName = /* @__PURE__ */ new Map();
|
|
11
|
+
static from(contextName) {
|
|
12
|
+
if (!MockServerIpc.serverByContextName.has(contextName)) {
|
|
13
|
+
MockServerIpc.serverByContextName.set(
|
|
14
|
+
contextName,
|
|
15
|
+
new MockServerIpc(contextName)
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
return MockServerIpc.serverByContextName.get(contextName);
|
|
19
|
+
}
|
|
20
|
+
namespacesByName = /* @__PURE__ */ new Map();
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region of
|
|
23
|
+
of(namespace) {
|
|
24
|
+
if (!this.namespacesByName.has(namespace)) {
|
|
25
|
+
this.namespacesByName.set(
|
|
26
|
+
namespace,
|
|
27
|
+
new MockNamespaceIpc(namespace, this)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return this.namespacesByName.get(namespace);
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
}
|
|
34
|
+
class MockNamespaceIpc {
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region constructor
|
|
37
|
+
constructor(name, server) {
|
|
38
|
+
this.name = name;
|
|
39
|
+
this.server = server;
|
|
40
|
+
}
|
|
41
|
+
//#region fields & getters
|
|
42
|
+
electronClients = /* @__PURE__ */ new Set();
|
|
43
|
+
roomsByRoomName = {};
|
|
44
|
+
namespaceEventHandlers = {};
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region on
|
|
47
|
+
on(eventName, callback) {
|
|
48
|
+
const listenKey = `(${this.name}) "${eventName}"`;
|
|
49
|
+
if (!this.namespaceEventHandlers[eventName]) {
|
|
50
|
+
this.namespaceEventHandlers[eventName] = /* @__PURE__ */ new Set();
|
|
51
|
+
}
|
|
52
|
+
this.namespaceEventHandlers[eventName].add(callback);
|
|
53
|
+
ipcMain.on(listenKey, (eventElectron, ...args) => {
|
|
54
|
+
this.electronClients.add(eventElectron.sender);
|
|
55
|
+
const connectionListener = `(${this.name}) "connection"`;
|
|
56
|
+
if (connectionListener === listenKey) {
|
|
57
|
+
callback(this, ...args);
|
|
58
|
+
} else {
|
|
59
|
+
if (eventName.includes(`:${Symbols__NS__REALTIME.KEYroomSubscribe}`)) {
|
|
60
|
+
const roomName = args[0];
|
|
61
|
+
this.join(eventElectron.sender, roomName);
|
|
62
|
+
} else if (eventName.includes(`:${Symbols__NS__REALTIME.KEYroomUnsubscribe}`)) {
|
|
63
|
+
const roomName = args[0];
|
|
64
|
+
this.leave(eventElectron.sender, roomName);
|
|
65
|
+
} else {
|
|
66
|
+
callback(...args);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region off
|
|
73
|
+
off(event, callback) {
|
|
74
|
+
if (!this.namespaceEventHandlers[event]) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (callback) {
|
|
78
|
+
this.namespaceEventHandlers[event].delete(callback);
|
|
79
|
+
} else {
|
|
80
|
+
delete this.namespaceEventHandlers[event];
|
|
81
|
+
}
|
|
82
|
+
const removeKey = `(${this.name}) "${event}"`;
|
|
83
|
+
ipcMain.removeListener(removeKey, callback);
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region emit
|
|
87
|
+
emit(eventName, ...args) {
|
|
88
|
+
const sendEventKey = `(${this.name}) "${eventName}"`;
|
|
89
|
+
for (const webContents of this.electronClients) {
|
|
90
|
+
webContents.send(sendEventKey, ...args);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region to
|
|
95
|
+
to(roomName) {
|
|
96
|
+
const electronClientsInroom = this.roomsByRoomName[roomName];
|
|
97
|
+
return new RoomEmitterIpc(electronClientsInroom, this.name, true);
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region in
|
|
101
|
+
in(roomName) {
|
|
102
|
+
const electronClientsInroom = this.roomsByRoomName[roomName];
|
|
103
|
+
return new RoomEmitterIpc(electronClientsInroom, this.name, false);
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region join
|
|
107
|
+
join(webContents, roomName) {
|
|
108
|
+
if (!this.roomsByRoomName[roomName]) {
|
|
109
|
+
this.roomsByRoomName[roomName] = /* @__PURE__ */ new Set();
|
|
110
|
+
}
|
|
111
|
+
this.roomsByRoomName[roomName].add(webContents);
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region leave
|
|
115
|
+
leave(webContents, roomName) {
|
|
116
|
+
if (this.roomsByRoomName[roomName]) {
|
|
117
|
+
this.roomsByRoomName[roomName].delete(webContents);
|
|
118
|
+
if (this.roomsByRoomName[roomName].size === 0) {
|
|
119
|
+
delete this.roomsByRoomName[roomName];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region path
|
|
125
|
+
path() {
|
|
126
|
+
return this.name;
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region get nsp
|
|
130
|
+
get nsp() {
|
|
131
|
+
const self = this;
|
|
132
|
+
return {
|
|
133
|
+
get name() {
|
|
134
|
+
return self.name;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
}
|
|
140
|
+
class RoomEmitterIpc {
|
|
141
|
+
//#region constructor
|
|
142
|
+
constructor(electronClients, name, includeSender = false, sender = null) {
|
|
143
|
+
this.electronClients = electronClients;
|
|
144
|
+
this.name = name;
|
|
145
|
+
this.includeSender = includeSender;
|
|
146
|
+
this.sender = sender;
|
|
147
|
+
}
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region emit in room
|
|
150
|
+
emit(eventName, ...args) {
|
|
151
|
+
const emitEvent = `(${this.name}) "${eventName}"`;
|
|
152
|
+
this.electronClients?.forEach((webContents) => {
|
|
153
|
+
webContents.send(emitEvent, ...args);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
//#endregion
|
|
157
|
+
}
|
|
158
|
+
class MockSocketIpc {
|
|
159
|
+
//#endregion
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region constructor
|
|
162
|
+
/**
|
|
163
|
+
* @param namespaceName instead url for ipc
|
|
164
|
+
*/
|
|
165
|
+
constructor(namespaceName) {
|
|
166
|
+
this.namespaceName = namespaceName;
|
|
167
|
+
}
|
|
168
|
+
//#region fields & getters
|
|
169
|
+
//#region fields & getters / ipc renderer
|
|
170
|
+
/* */
|
|
171
|
+
/* */
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region fields & getters / event handlers by name
|
|
174
|
+
socketEventHandlers = {};
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region fields & getters / name
|
|
177
|
+
get name() {
|
|
178
|
+
return this.namespaceName;
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region on
|
|
182
|
+
on(eventName, callback) {
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region off
|
|
186
|
+
off(event, callback) {
|
|
187
|
+
}
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region emit
|
|
190
|
+
emit(event, ...args) {
|
|
191
|
+
}
|
|
192
|
+
//#endregion
|
|
193
|
+
}
|
|
194
|
+
class RealtimeStrategyIpc extends RealtimeStrategy {
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region constructor
|
|
197
|
+
constructor(ctx) {
|
|
198
|
+
super(ctx);
|
|
199
|
+
this.ctx = ctx;
|
|
200
|
+
}
|
|
201
|
+
//#region to string
|
|
202
|
+
toString() {
|
|
203
|
+
return "ipc";
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region server & io
|
|
207
|
+
ioServer(__, opt) {
|
|
208
|
+
const namespace = opt?.path || "/";
|
|
209
|
+
const server = MockServerIpc.from(this.ctx.contextName);
|
|
210
|
+
return server.of(namespace);
|
|
211
|
+
}
|
|
212
|
+
get ioClient() {
|
|
213
|
+
const clientIo = (__, opt) => {
|
|
214
|
+
const namespace = opt?.path || "/";
|
|
215
|
+
return new MockSocketIpc(namespace);
|
|
216
|
+
};
|
|
217
|
+
return clientIo;
|
|
218
|
+
}
|
|
219
|
+
//#endregion
|
|
220
|
+
}
|
|
221
|
+
export {
|
|
222
|
+
MockNamespaceIpc,
|
|
223
|
+
MockServerIpc,
|
|
224
|
+
MockSocketIpc,
|
|
225
|
+
RealtimeStrategyIpc
|
|
226
|
+
};
|