taon 21.0.53 → 21.0.55
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/package.json +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/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 +17 -31
- package/lib-prod/base-classes/base-angular-service.js +83 -55
- package/lib-prod/base-classes/base-class.js +33 -35
- package/lib-prod/base-classes/base-context.js +17 -19
- package/lib-prod/base-classes/base-controller.js +146 -154
- package/lib-prod/base-classes/base-crud-controller.js +250 -221
- package/lib-prod/base-classes/base-custom-repository.js +7 -18
- package/lib-prod/base-classes/base-electron-service.js +49 -0
- package/lib-prod/base-classes/base-entity.js +20 -30
- package/lib-prod/base-classes/base-file-upload.middleware.js +72 -75
- package/lib-prod/base-classes/base-injector.js +176 -194
- package/lib-prod/base-classes/base-middleware.js +8 -5
- package/lib-prod/base-classes/base-migration.js +19 -22
- package/lib-prod/base-classes/base-provider.js +7 -5
- package/lib-prod/base-classes/base-repository.js +601 -573
- package/lib-prod/base-classes/base-subscriber-for-entity.js +143 -152
- package/lib-prod/base-classes/base.js +18 -0
- package/lib-prod/build-info._auto-generated_.js +26 -14
- package/lib-prod/config/controller-config.js +24 -24
- package/lib-prod/config/controller-options.js +2 -5
- package/lib-prod/config/method-config.js +6 -8
- package/lib-prod/config/param-config.js +2 -8
- package/lib-prod/constants.js +29 -25
- package/lib-prod/context-db-migrations.js +328 -324
- package/lib-prod/create-context.js +211 -146
- package/lib-prod/decorators/classes/controller-decorator.js +16 -20
- package/lib-prod/decorators/classes/entity-decorator.js +26 -47
- package/lib-prod/decorators/classes/middleware-decorator.js +14 -24
- package/lib-prod/decorators/classes/migration-decorator.js +13 -22
- package/lib-prod/decorators/classes/provider-decorator.js +13 -23
- package/lib-prod/decorators/classes/repository-decorator.js +13 -22
- package/lib-prod/decorators/classes/subscriber-decorator.js +13 -23
- package/lib-prod/decorators/decorator-abstract-opt.js +1 -4
- package/lib-prod/decorators/http/http-decorators.js +20 -5
- package/lib-prod/decorators/http/http-methods-decorators.js +91 -133
- package/lib-prod/decorators/http/http-params-decorators.js +36 -62
- package/lib-prod/dependency-injection/di-container.js +28 -29
- package/lib-prod/endpoint-context-storage.js +27 -32
- package/lib-prod/endpoint-context.js +2294 -1930
- package/lib-prod/entity-process.js +209 -198
- package/lib-prod/env/env.angular-node-app.js +66 -130
- package/lib-prod/env/env.docs-webapp.js +66 -130
- package/lib-prod/env/env.electron-app.js +66 -130
- package/lib-prod/env/env.mobile-app.js +66 -130
- package/lib-prod/env/env.npm-lib-and-cli-tool.js +66 -130
- package/lib-prod/env/env.vscode-plugin.js +66 -130
- package/lib-prod/env/index.js +6 -6
- package/lib-prod/express-types.js +1 -0
- package/lib-prod/formly/formly.models.js +1 -0
- package/lib-prod/formly/fromly.js +196 -175
- package/lib-prod/formly/type-from-entity.js +45 -52
- package/lib-prod/get-response-value.js +21 -18
- package/lib-prod/global-state/taon-global-state/index.js +6 -5
- package/lib-prod/global-state/taon-global-state/taon-global-state.abstract.context.js +18 -19
- package/lib-prod/global-state/taon-global-state/taon-global-state.constants.js +6 -9
- package/lib-prod/global-state/taon-global-state/taon-global-state.controller.js +40 -46
- package/lib-prod/global-state/taon-global-state/taon-global-state.entity.js +33 -46
- package/lib-prod/global-state/taon-global-state/taon-global-state.middleware.js +10 -20
- package/lib-prod/global-state/taon-global-state/taon-global-state.models.js +43 -33
- package/lib-prod/global-state/taon-global-state/taon-global-state.provider.js +10 -20
- package/lib-prod/global-state/taon-global-state/taon-global-state.repository.js +43 -44
- package/lib-prod/global-state/taon-global-state/taon-global-state.subscriber.js +20 -27
- package/lib-prod/global-state/taon-global-state/taon-global-state.utils.js +10 -10
- package/lib-prod/global-state/taon-transaction-registry/index.js +11 -10
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.abstract.context.js +20 -21
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.constants.js +4 -7
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.controller.js +34 -39
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.entity.js +34 -54
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.middleware.js +10 -20
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.models.js +7 -10
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.provider.js +10 -20
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.repository.js +29 -34
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.subscriber.js +20 -27
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.utils.js +4 -5
- package/lib-prod/helpers/class-helpers.js +210 -177
- package/lib-prod/helpers/clone-obj.js +16 -20
- package/lib-prod/helpers/taon-helpers.js +132 -114
- package/lib-prod/index._auto-generated_.js +5 -0
- package/lib-prod/index.js +248 -227
- package/lib-prod/inject.js +88 -33
- package/lib-prod/migrations/index.js +2 -1
- package/lib-prod/migrations/migrations_index._auto-generated_.js +3 -0
- package/lib-prod/models.js +72 -103
- package/lib-prod/orm/columns.js +58 -118
- package/lib-prod/orm/index.js +56 -1
- package/lib-prod/package.json +1 -1
- package/lib-prod/realtime/realtime-client.js +188 -186
- package/lib-prod/realtime/realtime-core.js +77 -78
- package/lib-prod/realtime/realtime-server.js +225 -240
- package/lib-prod/realtime/realtime-strategy/index.js +4 -4
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-ipc.js +273 -219
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-mock.js +267 -240
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-socket-io.js +26 -20
- package/lib-prod/realtime/realtime-strategy/realtime-strategy.js +10 -13
- package/lib-prod/realtime/realtime-subs-manager.js +82 -90
- package/lib-prod/realtime/realtime.models.js +2 -0
- package/lib-prod/symbols.js +104 -105
- package/lib-prod/ui/index.js +1 -5
- package/lib-prod/ui/taon-admin-mode-configuration/index.js +1 -5
- package/lib-prod/validators.js +43 -37
- package/lib-prod.split-namespaces.json +32 -86
- package/package.json +1 -1
- package/websql/package.json +1 -1
- package/websql-prod/package.json +1 -1
|
@@ -1,107 +1,125 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
//#region imports
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { ___NS__isObject, ___NS__isString } from 'tnp-core/lib-prod';
|
|
4
|
+
import { Helpers__NS__logInfo } from 'tnp-core/lib-prod';
|
|
5
|
+
import { ClassHelpers__NS__getClassFnFromObject, ClassHelpers__NS__getName, ClassHelpers__NS__getUniqueKey } from '../helpers/class-helpers';
|
|
6
|
+
import { Symbols__NS__REALTIME } from '../symbols';
|
|
7
|
+
import { RealtimeSubsManager } from './realtime-subs-manager';
|
|
8
|
+
//#endregion
|
|
9
|
+
/**
|
|
10
|
+
* Client for realtime communication
|
|
11
|
+
* you can listen to:
|
|
12
|
+
* - entity changes (any property in table changed)
|
|
13
|
+
* - entity custom property changes (specific property changed)
|
|
14
|
+
* - entity table changes (new instance added, instance removed)
|
|
15
|
+
* - custom events
|
|
16
|
+
*/
|
|
17
|
+
export class RealtimeClient {
|
|
18
|
+
constructor(core) {
|
|
19
|
+
this.core = core;
|
|
20
|
+
this.subsManagers = {};
|
|
21
|
+
this.core = core;
|
|
22
|
+
if (!core.ctx.disabledRealtime) {
|
|
23
|
+
// this.core.ctx.logRealtime &&
|
|
24
|
+
// Helpers__NS__info(`
|
|
25
|
+
// [ctx=${this.core.ctx.contextName}] init RealtimeClient (type: ${this.core.ctx.contextType})
|
|
26
|
+
// `);
|
|
27
|
+
this.init();
|
|
28
|
+
}
|
|
13
29
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
//#endregion
|
|
72
|
-
//#region methods & getters / listen changes entity
|
|
73
|
-
/**
|
|
74
|
-
* Usage:
|
|
75
|
-
* myContext.realtimeClient.listenChangesEntity(myEntityInstance);
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* Changes trigger on backend needs to be done manually.. example code:
|
|
79
|
-
*
|
|
80
|
-
* myContext.realtimeServer.triggerEntityChanges(myEntityInstance);
|
|
81
|
-
* ...
|
|
82
|
-
*/
|
|
83
|
-
listenChangesEntity(entityClassFnOrObj, options) {
|
|
84
|
-
options = options || {};
|
|
85
|
-
if (___NS__isObject(entityClassFnOrObj)) {
|
|
86
|
-
const orgObj = entityClassFnOrObj;
|
|
87
|
-
entityClassFnOrObj = ClassHelpers__NS__getClassFnFromObject(entityClassFnOrObj);
|
|
88
|
-
const uniqueKey = ClassHelpers__NS__getUniqueKey(entityClassFnOrObj);
|
|
89
|
-
if (uniqueKey) {
|
|
90
|
-
options.idOrUniqValue = orgObj[uniqueKey];
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
const { property, customEvent } = options;
|
|
94
|
-
const className = !customEvent && ClassHelpers__NS__getName(entityClassFnOrObj);
|
|
95
|
-
if (___NS__isString(property)) {
|
|
96
|
-
if (property.trim() === "") {
|
|
97
|
-
throw new Error(
|
|
98
|
-
`[Taon][listenChangesEntity.. incorrect property '' for ${className}`
|
|
99
|
-
);
|
|
100
|
-
}
|
|
30
|
+
//#region methods & getters / init
|
|
31
|
+
init() {
|
|
32
|
+
//#region prepare naspaces pathes
|
|
33
|
+
const nspPath = {
|
|
34
|
+
global: this.core.pathFor(),
|
|
35
|
+
realtime: this.core.pathFor(Symbols__NS__REALTIME.NAMESPACE(this.core.ctx.contextName)),
|
|
36
|
+
};
|
|
37
|
+
// console.log('[browser] nspPath', nspPath);
|
|
38
|
+
if (this.core.ctx.config.frontendHost &&
|
|
39
|
+
this.core.ctx.config.frontendHost !== '' &&
|
|
40
|
+
this.core.ctx.isRunningInsideDocker) {
|
|
41
|
+
this.core.ctx.logRealtime &&
|
|
42
|
+
Helpers__NS__logInfo(`[${this.core.ctx.contextName}] USING FRONTEND HOST` +
|
|
43
|
+
` ${this.core.ctx.config.frontendHost} FOR REALTIME`);
|
|
44
|
+
nspPath.global = new URL(`${this.core.ctx.frontendHostUri.origin}${nspPath.global.pathname}`);
|
|
45
|
+
nspPath.realtime = new URL(`${this.core.ctx.frontendHostUri.origin}${nspPath.realtime.pathname}`);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this.core.ctx.logRealtime &&
|
|
49
|
+
Helpers__NS__logInfo(`[${this.core.ctx.contextName}] Not using frontend host for realtime`);
|
|
50
|
+
}
|
|
51
|
+
this.core.ctx.logRealtime &&
|
|
52
|
+
console.info('[CLIENT] NAMESPACE GLOBAL ', nspPath.global.href + ` host: ${this.core.ctx.host}`);
|
|
53
|
+
this.core.ctx.logRealtime &&
|
|
54
|
+
console.info('[CLIENT] NAMESPACE REALTIME', nspPath.realtime.href + ` host: ${this.core.ctx.host}`);
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region prepare globa FE socket
|
|
57
|
+
this.core.conectSocketFE = this.core.strategy.ioClient(nspPath.global.origin, {
|
|
58
|
+
path: nspPath.global.pathname,
|
|
59
|
+
});
|
|
60
|
+
if (this.core.conectSocketFE.on) {
|
|
61
|
+
this.core.conectSocketFE.on('connect', () => {
|
|
62
|
+
// console.info(
|
|
63
|
+
// `[CLIENT] connected to GLOBAL namespace ${global.nsp} of host: ${context.host}`,
|
|
64
|
+
// );
|
|
65
|
+
this.core.ctx.logRealtime &&
|
|
66
|
+
console.info(`[CLIENT] connected to GLOBAL namespace ${nspPath.global.pathname}` +
|
|
67
|
+
` of host: ${this.core.ctx.host}`);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region prepare realtime FE socket
|
|
72
|
+
this.core.socketFE = this.core.strategy.ioClient(nspPath.realtime.origin, {
|
|
73
|
+
path: nspPath.realtime.pathname,
|
|
74
|
+
});
|
|
75
|
+
if (this.core.socketFE.on) {
|
|
76
|
+
this.core.socketFE.on('connect', () => {
|
|
77
|
+
// console.info(
|
|
78
|
+
// `[CLIENT] connected to REALTIME namespace ${realtime.nsp} host: ${context.host}`,
|
|
79
|
+
// );
|
|
80
|
+
this.core.ctx.logRealtime &&
|
|
81
|
+
console.info(`[CLIENT] connected to REALTIME namespace ${nspPath.realtime.pathname}` +
|
|
82
|
+
` host: ${this.core.ctx.host}`);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
101
86
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region methods & getters / listen changes entity
|
|
89
|
+
/**
|
|
90
|
+
* Usage:
|
|
91
|
+
* myContext.realtimeClient.listenChangesEntity(myEntityInstance);
|
|
92
|
+
*
|
|
93
|
+
*
|
|
94
|
+
* Changes trigger on backend needs to be done manually.. example code:
|
|
95
|
+
*
|
|
96
|
+
* myContext.realtimeServer.triggerEntityChanges(myEntityInstance);
|
|
97
|
+
* ...
|
|
98
|
+
*/
|
|
99
|
+
listenChangesEntity(entityClassFnOrObj, options) {
|
|
100
|
+
options = options || {};
|
|
101
|
+
if (___NS__isObject(entityClassFnOrObj)) {
|
|
102
|
+
const orgObj = entityClassFnOrObj;
|
|
103
|
+
entityClassFnOrObj =
|
|
104
|
+
ClassHelpers__NS__getClassFnFromObject(entityClassFnOrObj);
|
|
105
|
+
const uniqueKey = ClassHelpers__NS__getUniqueKey(entityClassFnOrObj);
|
|
106
|
+
if (uniqueKey) {
|
|
107
|
+
options.idOrUniqValue = orgObj[uniqueKey];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//#region parameters validation
|
|
111
|
+
const { property, customEvent } = options;
|
|
112
|
+
const className = !customEvent && ClassHelpers__NS__getName(entityClassFnOrObj);
|
|
113
|
+
if (___NS__isString(property)) {
|
|
114
|
+
if (property.trim() === '') {
|
|
115
|
+
throw new Error(`[Taon][listenChangesEntity.. incorrect property '' for ${className}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
return new Observable(observer => {
|
|
120
|
+
//#region prepare parameters for manager
|
|
121
|
+
if (this.core.ctx.disabledRealtime) {
|
|
122
|
+
console.error(`[Taon][realtime rxjs] remove taon config flag:
|
|
105
123
|
|
|
106
124
|
...
|
|
107
125
|
disabledRealtime: true
|
|
@@ -109,88 +127,72 @@ class RealtimeClient {
|
|
|
109
127
|
|
|
110
128
|
to use socket realtime connection;
|
|
111
129
|
`);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
* @param dataToPush
|
|
181
|
-
*/
|
|
182
|
-
triggerCustomEvent(customEvent, dataToPush) {
|
|
183
|
-
this.core.socketFE.emit(customEvent, dataToPush);
|
|
184
|
-
}
|
|
185
|
-
//#endregion
|
|
186
|
-
//#region methods & getters / get room id from
|
|
187
|
-
getUniqueIdentifierForConnection(options) {
|
|
188
|
-
let url = new URL(options.core.ctx.host);
|
|
189
|
-
let contextNameForCommunication = options.core.ctx.contextNameForCommunication;
|
|
190
|
-
return `${contextNameForCommunication}:${url.origin}|${options.roomName}|${options.property}|${options.customEvent}`;
|
|
191
|
-
}
|
|
192
|
-
//#endregion
|
|
130
|
+
return () => {
|
|
131
|
+
// empty nothing to do
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
let roomName;
|
|
135
|
+
if (customEvent) {
|
|
136
|
+
roomName = Symbols__NS__REALTIME.ROOM_NAME_CUSTOM(this.core.ctx.contextName, customEvent);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
roomName = ___NS__isString(property)
|
|
140
|
+
? Symbols__NS__REALTIME.ROOM_NAME_UPDATE_ENTITY_PROPERTY(this.core.ctx.contextName, className, property, options.idOrUniqValue)
|
|
141
|
+
: Symbols__NS__REALTIME.ROOM_NAME_UPDATE_ENTITY(this.core.ctx.contextName, className, options.idOrUniqValue);
|
|
142
|
+
}
|
|
143
|
+
const roomSubOptions = {
|
|
144
|
+
core: this.core,
|
|
145
|
+
property,
|
|
146
|
+
roomName,
|
|
147
|
+
customEvent,
|
|
148
|
+
};
|
|
149
|
+
//#endregion
|
|
150
|
+
const subManagerId = this.getUniqueIdentifierForConnection(roomSubOptions);
|
|
151
|
+
if (!this.subsManagers[subManagerId]) {
|
|
152
|
+
this.subsManagers[subManagerId] = new RealtimeSubsManager(roomSubOptions);
|
|
153
|
+
}
|
|
154
|
+
const inst = this.subsManagers[subManagerId];
|
|
155
|
+
inst.add(observer);
|
|
156
|
+
inst.startListenIfNotStarted(this.core.socketFE);
|
|
157
|
+
return () => {
|
|
158
|
+
inst.remove(observer);
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region listen changes entity table
|
|
164
|
+
/**
|
|
165
|
+
* Listen changes entity table
|
|
166
|
+
* Example: for pagination, lists update ...
|
|
167
|
+
*/
|
|
168
|
+
listenChangesEntityTable(entityClassFn) {
|
|
169
|
+
const className = ClassHelpers__NS__getName(entityClassFn);
|
|
170
|
+
return this.listenChangesEntity(entityClassFn, {
|
|
171
|
+
customEvent: Symbols__NS__REALTIME.TABLE_CHANGE(this.core.ctx.contextName, className),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region listen changes custom event
|
|
176
|
+
listenChangesCustomEvent(customEvent) {
|
|
177
|
+
return this.listenChangesEntity(void 0, {
|
|
178
|
+
customEvent,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region methods & getters / trigger custom event\
|
|
183
|
+
/**
|
|
184
|
+
* Trigger custom event on backend
|
|
185
|
+
* @param customEvent global event name
|
|
186
|
+
* @param dataToPush
|
|
187
|
+
*/
|
|
188
|
+
triggerCustomEvent(customEvent, dataToPush) {
|
|
189
|
+
this.core.socketFE.emit(customEvent, dataToPush);
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region methods & getters / get room id from
|
|
193
|
+
getUniqueIdentifierForConnection(options) {
|
|
194
|
+
let url = new URL(options.core.ctx.host);
|
|
195
|
+
let contextNameForCommunication = options.core.ctx.contextNameForCommunication;
|
|
196
|
+
return `${contextNameForCommunication}:${url.origin}|${options.roomName}|${options.property}|${options.customEvent}`;
|
|
197
|
+
}
|
|
193
198
|
}
|
|
194
|
-
export {
|
|
195
|
-
RealtimeClient
|
|
196
|
-
};
|
|
@@ -1,82 +1,81 @@
|
|
|
1
|
-
import { UtilsOs__NS__isElectron, UtilsOs__NS__isWebSQL } from
|
|
2
|
-
import { apiPrefix } from
|
|
3
|
-
import { RealtimeClient } from
|
|
4
|
-
import { RealtimeServer } from
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import { UtilsOs__NS__isElectron, UtilsOs__NS__isWebSQL } from 'tnp-core/lib-prod';
|
|
2
|
+
import { apiPrefix } from '../constants';
|
|
3
|
+
import { RealtimeClient } from './realtime-client';
|
|
4
|
+
import { RealtimeServer } from './realtime-server';
|
|
5
|
+
import { RealtimeStrategyIpc, RealtimeStrategyMock, RealtimeStrategySocketIO, } from './realtime-strategy';
|
|
6
|
+
//#endregion
|
|
7
|
+
/**
|
|
8
|
+
* Realtime class
|
|
9
|
+
* - mock (when browser-browser)
|
|
10
|
+
* - sockets (from socket io when backend-browser)
|
|
11
|
+
* - ipc (when electron is used or between processes)
|
|
12
|
+
* - webworker (when webworker is used in browser or nodejs)
|
|
13
|
+
*/
|
|
14
|
+
export class RealtimeCore {
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region constructor
|
|
17
|
+
constructor(ctx) {
|
|
18
|
+
this.ctx = ctx;
|
|
19
|
+
//#region fields
|
|
20
|
+
this.allHttpMethods = [
|
|
21
|
+
'GET',
|
|
22
|
+
'POST',
|
|
23
|
+
'PUT',
|
|
24
|
+
'DELETE',
|
|
25
|
+
'PATCH',
|
|
26
|
+
'OPTIONS',
|
|
27
|
+
'HEAD',
|
|
28
|
+
];
|
|
29
|
+
this.ctx = ctx;
|
|
30
|
+
this.strategy = this.resolveStrategy();
|
|
31
|
+
// this.ctx.logRealtime &&
|
|
32
|
+
// console.log(`
|
|
33
|
+
// [ctx=${this.ctx.contextName}] realtime strategy: ${this.strategy}, context type: ${this.ctx.contextType}
|
|
34
|
+
// `);
|
|
35
|
+
if (UtilsOs__NS__isWebSQL) {
|
|
36
|
+
this.server = new RealtimeServer(this);
|
|
37
|
+
// console.log('DONE INITING SERVER');
|
|
38
|
+
this.client = new RealtimeClient(this);
|
|
39
|
+
// console.log('DONE INITING CLIENT');
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.client = new RealtimeClient(this);
|
|
43
|
+
this.server = new RealtimeServer(this);
|
|
44
|
+
}
|
|
23
45
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
* socket for namespaces and rooms
|
|
44
|
-
*/
|
|
45
|
-
socketFE;
|
|
46
|
-
/**
|
|
47
|
-
* global BE socket - only for established connection
|
|
48
|
-
*/
|
|
49
|
-
connectSocketBE;
|
|
50
|
-
/**
|
|
51
|
-
* socket for namespaces and rooms
|
|
52
|
-
*/
|
|
53
|
-
socketBE;
|
|
54
|
-
//#endregion
|
|
55
|
-
//#region methods & getters / resovle staraegy
|
|
56
|
-
resolveStrategy() {
|
|
57
|
-
if (this.ctx.mode === "backend-frontend(websql)" || this.ctx.mode === "backend-frontend(websql-electron)") {
|
|
58
|
-
return new RealtimeStrategyMock(this.ctx);
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region methods & getters / resovle staraegy
|
|
48
|
+
resolveStrategy() {
|
|
49
|
+
// console.log(`[taon] resolveStrategy for this.ctx.mode ${this.ctx.mode}`);
|
|
50
|
+
if (this.ctx.mode === 'backend-frontend(websql)' ||
|
|
51
|
+
this.ctx.mode === 'backend-frontend(websql-electron)') {
|
|
52
|
+
// debugger
|
|
53
|
+
return new RealtimeStrategyMock(this.ctx);
|
|
54
|
+
}
|
|
55
|
+
if (this.ctx.mode === 'backend-frontend(ipc-electron)') {
|
|
56
|
+
return new RealtimeStrategyIpc(this.ctx);
|
|
57
|
+
}
|
|
58
|
+
// if (this.ctx.mode === 'backend-frontend(tcp+udp)') {
|
|
59
|
+
// return new RealtimeStrategySocketIO(this.ctx);
|
|
60
|
+
// }
|
|
61
|
+
// if (this.ctx.mode === 'remote-backend(tcp+udp)') {
|
|
62
|
+
// return new RealtimeStrategySocketIO(this.ctx);
|
|
63
|
+
// }
|
|
64
|
+
return new RealtimeStrategySocketIO(this.ctx);
|
|
59
65
|
}
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region path for
|
|
68
|
+
pathFor(namespace) {
|
|
69
|
+
let nsp = namespace ? namespace : '';
|
|
70
|
+
nsp = nsp === '/' ? '' : nsp;
|
|
71
|
+
const contextNameForCommunication = this.ctx.contextNameForCommunication;
|
|
72
|
+
let prefix = `${apiPrefix}/${contextNameForCommunication}/udp`;
|
|
73
|
+
if (UtilsOs__NS__isElectron) {
|
|
74
|
+
prefix = ``;
|
|
75
|
+
}
|
|
76
|
+
const href = `${this.ctx.uriOrigin}${this.ctx.uriPathnameOrNothingIfRoot}` +
|
|
77
|
+
`/${prefix}${prefix && nsp ? '-' + nsp : nsp}`;
|
|
78
|
+
// console.log(`HREF: ${href}, nsp: ${nsp}`)
|
|
79
|
+
return new URL(href);
|
|
62
80
|
}
|
|
63
|
-
return new RealtimeStrategySocketIO(this.ctx);
|
|
64
|
-
}
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region path for
|
|
67
|
-
pathFor(namespace) {
|
|
68
|
-
let nsp = namespace ? namespace : "";
|
|
69
|
-
nsp = nsp === "/" ? "" : nsp;
|
|
70
|
-
const contextNameForCommunication = this.ctx.contextNameForCommunication;
|
|
71
|
-
let prefix = `${apiPrefix}/${contextNameForCommunication}/udp`;
|
|
72
|
-
if (UtilsOs__NS__isElectron) {
|
|
73
|
-
prefix = ``;
|
|
74
|
-
}
|
|
75
|
-
const href = `${this.ctx.uriOrigin}${this.ctx.uriPathnameOrNothingIfRoot}/${prefix}${prefix && nsp ? "-" + nsp : nsp}`;
|
|
76
|
-
return new URL(href);
|
|
77
|
-
}
|
|
78
|
-
//#endregion
|
|
79
81
|
}
|
|
80
|
-
export {
|
|
81
|
-
RealtimeCore
|
|
82
|
-
};
|