taon 21.0.52 → 21.0.54
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/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 +19 -0
- package/lib-prod/base-classes/base-angular-service.js +84 -0
- package/lib-prod/base-classes/base-class.js +35 -0
- package/lib-prod/base-classes/{base-context.ts → base-context.js} +13 -15
- package/lib-prod/base-classes/base-controller.js +154 -0
- package/lib-prod/base-classes/base-crud-controller.js +264 -0
- package/lib-prod/base-classes/base-custom-repository.js +9 -0
- package/lib-prod/base-classes/{base-electron-service.ts → base-electron-service.js} +1 -12
- package/lib-prod/base-classes/base-entity.js +22 -0
- package/lib-prod/base-classes/base-file-upload.middleware.js +75 -0
- package/lib-prod/base-classes/base-injector.js +184 -0
- package/lib-prod/base-classes/base-middleware.js +9 -0
- package/lib-prod/base-classes/base-migration.js +20 -0
- package/lib-prod/base-classes/{base-provider.ts → base-provider.js} +2 -2
- package/lib-prod/base-classes/base-repository.js +617 -0
- package/lib-prod/base-classes/base-subscriber-for-entity.js +145 -0
- package/lib-prod/base-classes/{base.ts → base.js} +2 -15
- package/lib-prod/{build-info._auto-generated_.ts → build-info._auto-generated_.js} +1 -2
- package/lib-prod/config/controller-config.js +28 -0
- package/lib-prod/config/controller-options.js +3 -0
- package/lib-prod/config/method-config.js +7 -0
- package/lib-prod/config/param-config.js +3 -0
- package/lib-prod/constants.js +33 -0
- package/lib-prod/context-db-migrations.js +342 -0
- package/lib-prod/create-context.js +217 -0
- package/lib-prod/decorators/classes/controller-decorator.js +17 -0
- package/lib-prod/decorators/classes/entity-decorator.js +28 -0
- package/lib-prod/decorators/classes/middleware-decorator.js +16 -0
- package/lib-prod/decorators/classes/migration-decorator.js +15 -0
- package/lib-prod/decorators/classes/provider-decorator.js +15 -0
- package/lib-prod/decorators/classes/repository-decorator.js +15 -0
- package/lib-prod/decorators/classes/subscriber-decorator.js +15 -0
- package/lib-prod/decorators/decorator-abstract-opt.js +2 -0
- package/lib-prod/decorators/http/http-decorators.js +20 -0
- package/lib-prod/decorators/http/http-methods-decorators.js +102 -0
- package/lib-prod/decorators/http/http-params-decorators.js +42 -0
- package/lib-prod/dependency-injection/di-container.js +30 -0
- package/lib-prod/endpoint-context-storage.js +31 -0
- package/lib-prod/endpoint-context.js +2397 -0
- package/lib-prod/entity-process.js +225 -0
- package/lib-prod/env/{env.angular-node-app.ts → env.angular-node-app.js} +1 -1
- package/lib-prod/env/{env.docs-webapp.ts → env.docs-webapp.js} +1 -1
- package/lib-prod/env/{env.electron-app.ts → env.electron-app.js} +1 -1
- package/lib-prod/env/{env.mobile-app.ts → env.mobile-app.js} +1 -1
- package/lib-prod/env/{env.npm-lib-and-cli-tool.ts → env.npm-lib-and-cli-tool.js} +1 -1
- package/lib-prod/env/{env.vscode-plugin.ts → env.vscode-plugin.js} +1 -1
- package/lib-prod/express-types.js +1 -0
- package/lib-prod/formly/formly.models.js +1 -0
- package/lib-prod/formly/fromly.js +205 -0
- package/lib-prod/formly/type-from-entity.js +51 -0
- package/lib-prod/get-response-value.js +22 -0
- package/lib-prod/global-state/taon-global-state/{index.ts → index.js} +2 -2
- package/lib-prod/global-state/taon-global-state/{taon-global-state.abstract.context.ts → taon-global-state.abstract.context.js} +9 -11
- package/lib-prod/global-state/taon-global-state/taon-global-state.constants.js +7 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.controller.js +42 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.entity.js +35 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.middleware.js +12 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.models.js +44 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.provider.js +12 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.repository.js +46 -0
- package/lib-prod/global-state/taon-global-state/taon-global-state.subscriber.js +22 -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.ts → index.js} +2 -2
- package/lib-prod/global-state/taon-transaction-registry/{taon-transaction-registry.abstract.context.ts → taon-transaction-registry.abstract.context.js} +10 -12
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.constants.js +5 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.controller.js +36 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.entity.js +36 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.middleware.js +12 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.models.js +7 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.provider.js +12 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.repository.js +31 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.subscriber.js +22 -0
- package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.utils.js +5 -0
- package/lib-prod/helpers/class-helpers.js +228 -0
- package/lib-prod/helpers/clone-obj.js +17 -0
- package/lib-prod/helpers/taon-helpers.js +147 -0
- package/lib-prod/{index._auto-generated_.ts → index._auto-generated_.js} +1 -1
- package/lib-prod/index.js +252 -0
- package/lib-prod/{inject.ts → inject.js} +35 -57
- package/lib-prod/migrations/index.js +2 -0
- package/lib-prod/migrations/{migrations_index._auto-generated_.ts → migrations_index._auto-generated_.js} +0 -2
- package/lib-prod/models.js +78 -0
- package/lib-prod/orm/columns.js +64 -0
- package/lib-prod/orm/index.js +56 -0
- package/lib-prod/package.json +1 -1
- package/lib-prod/realtime/realtime-client.js +198 -0
- package/lib-prod/realtime/realtime-core.js +81 -0
- package/lib-prod/realtime/realtime-server.js +237 -0
- package/lib-prod/realtime/realtime-strategy/{index.ts → index.js} +1 -1
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-ipc.js +280 -0
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-mock.js +289 -0
- package/lib-prod/realtime/realtime-strategy/realtime-strategy-socket-io.js +27 -0
- package/lib-prod/realtime/realtime-strategy/realtime-strategy.js +11 -0
- package/lib-prod/realtime/realtime-subs-manager.js +88 -0
- package/lib-prod/realtime/realtime.models.js +2 -0
- package/lib-prod/symbols.js +108 -0
- package/lib-prod/ui/index.js +1 -0
- package/lib-prod/ui/taon-admin-mode-configuration/index.js +1 -0
- package/lib-prod/validators.js +80 -0
- package/lib-prod.split-namespaces.json +31 -91
- package/package.json +1 -1
- package/websql/package.json +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-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-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-repository.ts +0 -942
- package/lib-prod/base-classes/base-subscriber-for-entity.ts +0 -196
- 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 -3110
- package/lib-prod/entity-process.ts +0 -286
- 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/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/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.ts +0 -323
- 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/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/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
- /package/lib-prod/env/{index.ts → index.js} +0 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { ipcMain } from 'electron'; // @backend
|
|
2
|
+
import { Symbols__NS__REALTIME } from '../../symbols';
|
|
3
|
+
import { RealtimeStrategy } from './realtime-strategy';
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region mock server ipc
|
|
6
|
+
export class MockServerIpc {
|
|
7
|
+
static { this.serverByContextName = new Map(); }
|
|
8
|
+
static from(contextName) {
|
|
9
|
+
if (!MockServerIpc.serverByContextName.has(contextName)) {
|
|
10
|
+
MockServerIpc.serverByContextName.set(contextName, new MockServerIpc(contextName));
|
|
11
|
+
}
|
|
12
|
+
return MockServerIpc.serverByContextName.get(contextName);
|
|
13
|
+
}
|
|
14
|
+
//#region constructor
|
|
15
|
+
constructor(contextName) {
|
|
16
|
+
this.contextName = contextName;
|
|
17
|
+
this.namespacesByName = new Map();
|
|
18
|
+
MockServerIpc.serverByContextName.set(contextName, this);
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region of
|
|
22
|
+
of(namespace) {
|
|
23
|
+
if (!this.namespacesByName.has(namespace)) {
|
|
24
|
+
this.namespacesByName.set(namespace, new MockNamespaceIpc(namespace, this));
|
|
25
|
+
}
|
|
26
|
+
return this.namespacesByName.get(namespace);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region mock namespace ipc
|
|
31
|
+
export class MockNamespaceIpc {
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region constructor
|
|
34
|
+
constructor(
|
|
35
|
+
/**
|
|
36
|
+
* Namespace name
|
|
37
|
+
*/
|
|
38
|
+
name, server) {
|
|
39
|
+
this.name = name;
|
|
40
|
+
this.server = server;
|
|
41
|
+
//#region fields & getters
|
|
42
|
+
this.electronClients = new Set();
|
|
43
|
+
this.roomsByRoomName = {};
|
|
44
|
+
this.namespaceEventHandlers = {};
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region on
|
|
48
|
+
on(eventName, callback) {
|
|
49
|
+
//#region @backendFunc
|
|
50
|
+
const listenKey = `(${this.name}) "${eventName}"`;
|
|
51
|
+
if (!this.namespaceEventHandlers[eventName]) {
|
|
52
|
+
this.namespaceEventHandlers[eventName] = new Set();
|
|
53
|
+
}
|
|
54
|
+
this.namespaceEventHandlers[eventName].add(callback);
|
|
55
|
+
ipcMain.on(listenKey, (eventElectron, ...args) => {
|
|
56
|
+
this.electronClients.add(eventElectron.sender);
|
|
57
|
+
const connectionListener = `(${this.name}) "connection"`;
|
|
58
|
+
if (connectionListener === listenKey) {
|
|
59
|
+
callback(this, ...args);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
if (eventName.includes(`:${Symbols__NS__REALTIME.KEYroomSubscribe}`)) {
|
|
63
|
+
const roomName = args[0];
|
|
64
|
+
this.join(eventElectron.sender, roomName);
|
|
65
|
+
}
|
|
66
|
+
else if (eventName.includes(`:${Symbols__NS__REALTIME.KEYroomUnsubscribe}`)) {
|
|
67
|
+
const roomName = args[0];
|
|
68
|
+
this.leave(eventElectron.sender, roomName);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
callback(...args);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
// this.emit(listenKey); // QUICK_FIX
|
|
76
|
+
//#endregion
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region off
|
|
80
|
+
off(event, callback) {
|
|
81
|
+
//#region @backendFunc
|
|
82
|
+
if (!this.namespaceEventHandlers[event]) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (callback) {
|
|
86
|
+
this.namespaceEventHandlers[event].delete(callback);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
delete this.namespaceEventHandlers[event];
|
|
90
|
+
}
|
|
91
|
+
const removeKey = `(${this.name}) "${event}"`;
|
|
92
|
+
ipcMain.removeListener(removeKey, callback);
|
|
93
|
+
//#endregion
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region emit
|
|
97
|
+
emit(eventName, ...args) {
|
|
98
|
+
//#region @backendFunc
|
|
99
|
+
const sendEventKey = `(${this.name}) "${eventName}"`;
|
|
100
|
+
for (const webContents of this.electronClients) {
|
|
101
|
+
webContents.send(sendEventKey, ...args);
|
|
102
|
+
}
|
|
103
|
+
// const allWindows = Electron.BrowserWindow.getAllWindows();
|
|
104
|
+
// allWindows.forEach((win, index) => {
|
|
105
|
+
// win.webContents.send(sendEventKey, ...args);
|
|
106
|
+
// });
|
|
107
|
+
//#endregion
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region to
|
|
111
|
+
to(roomName) {
|
|
112
|
+
const electronClientsInroom = this.roomsByRoomName[roomName];
|
|
113
|
+
return new RoomEmitterIpc(electronClientsInroom, this.name, true);
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region in
|
|
117
|
+
in(roomName) {
|
|
118
|
+
const electronClientsInroom = this.roomsByRoomName[roomName];
|
|
119
|
+
return new RoomEmitterIpc(electronClientsInroom, this.name, false);
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region join
|
|
123
|
+
join(webContents, roomName) {
|
|
124
|
+
if (!this.roomsByRoomName[roomName]) {
|
|
125
|
+
this.roomsByRoomName[roomName] = new Set();
|
|
126
|
+
}
|
|
127
|
+
this.roomsByRoomName[roomName].add(webContents);
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region leave
|
|
131
|
+
leave(webContents, roomName) {
|
|
132
|
+
if (this.roomsByRoomName[roomName]) {
|
|
133
|
+
this.roomsByRoomName[roomName].delete(webContents);
|
|
134
|
+
if (this.roomsByRoomName[roomName].size === 0) {
|
|
135
|
+
delete this.roomsByRoomName[roomName];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region path
|
|
141
|
+
path() {
|
|
142
|
+
return this.name;
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region get nsp
|
|
146
|
+
get nsp() {
|
|
147
|
+
const self = this;
|
|
148
|
+
return {
|
|
149
|
+
get name() {
|
|
150
|
+
return self.name;
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region room emitter ipc
|
|
157
|
+
class RoomEmitterIpc {
|
|
158
|
+
//#region constructor
|
|
159
|
+
constructor(electronClients,
|
|
160
|
+
/**
|
|
161
|
+
* namespace name
|
|
162
|
+
*/
|
|
163
|
+
name, includeSender = false, sender = null) {
|
|
164
|
+
this.electronClients = electronClients;
|
|
165
|
+
this.name = name;
|
|
166
|
+
this.includeSender = includeSender;
|
|
167
|
+
this.sender = sender;
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region emit in room
|
|
171
|
+
emit(eventName, ...args) {
|
|
172
|
+
const emitEvent = `(${this.name}) "${eventName}"`;
|
|
173
|
+
this.electronClients?.forEach(webContents => {
|
|
174
|
+
webContents.send(emitEvent, ...args);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region mock socket ipc
|
|
180
|
+
export class MockSocketIpc {
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region fields & getters / name
|
|
183
|
+
get name() {
|
|
184
|
+
return this.namespaceName;
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region constructor
|
|
189
|
+
/**
|
|
190
|
+
* @param namespaceName instead url for ipc
|
|
191
|
+
*/
|
|
192
|
+
constructor(namespaceName) {
|
|
193
|
+
/* */
|
|
194
|
+
/* */
|
|
195
|
+
this.namespaceName = namespaceName;
|
|
196
|
+
//#region fields & getters
|
|
197
|
+
//#region fields & getters / ipc renderer
|
|
198
|
+
/* */
|
|
199
|
+
/* */
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region fields & getters / event handlers by name
|
|
202
|
+
this.socketEventHandlers = {};
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region on
|
|
206
|
+
on(eventName, callback) {
|
|
207
|
+
/* */
|
|
208
|
+
/* */
|
|
209
|
+
/* */
|
|
210
|
+
/* */
|
|
211
|
+
/* */
|
|
212
|
+
/* */
|
|
213
|
+
/* */
|
|
214
|
+
/* */
|
|
215
|
+
/* */
|
|
216
|
+
/* */
|
|
217
|
+
/* */
|
|
218
|
+
/* */
|
|
219
|
+
/* */
|
|
220
|
+
/* */
|
|
221
|
+
/* */
|
|
222
|
+
}
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region off
|
|
225
|
+
off(event, callback) {
|
|
226
|
+
/* */
|
|
227
|
+
/* */
|
|
228
|
+
/* */
|
|
229
|
+
/* */
|
|
230
|
+
/* */
|
|
231
|
+
/* */
|
|
232
|
+
/* */
|
|
233
|
+
/* */
|
|
234
|
+
/* */
|
|
235
|
+
/* */
|
|
236
|
+
/* */
|
|
237
|
+
/* */
|
|
238
|
+
/* */
|
|
239
|
+
/* */
|
|
240
|
+
/* */
|
|
241
|
+
}
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region emit
|
|
244
|
+
emit(event, ...args) {
|
|
245
|
+
/* */
|
|
246
|
+
/* */
|
|
247
|
+
/* */
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
//#endregion
|
|
251
|
+
/**
|
|
252
|
+
* Purpose:
|
|
253
|
+
* - backend-browser communication between 2 processes in electron mode
|
|
254
|
+
*/
|
|
255
|
+
export class RealtimeStrategyIpc extends RealtimeStrategy {
|
|
256
|
+
//#region to string
|
|
257
|
+
toString() {
|
|
258
|
+
return 'ipc';
|
|
259
|
+
}
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region constructor
|
|
262
|
+
constructor(ctx) {
|
|
263
|
+
super(ctx);
|
|
264
|
+
this.ctx = ctx;
|
|
265
|
+
}
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region server & io
|
|
268
|
+
ioServer(__, opt) {
|
|
269
|
+
const namespace = opt?.path || '/';
|
|
270
|
+
const server = MockServerIpc.from(this.ctx.contextName);
|
|
271
|
+
return server.of(namespace);
|
|
272
|
+
}
|
|
273
|
+
get ioClient() {
|
|
274
|
+
const clientIo = (__, opt) => {
|
|
275
|
+
const namespace = opt?.path || '/';
|
|
276
|
+
return new MockSocketIpc(namespace);
|
|
277
|
+
};
|
|
278
|
+
return clientIo;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { RealtimeStrategy } from './realtime-strategy';
|
|
2
|
+
import { Symbols__NS__REALTIME } from '../../symbols';
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region mock server
|
|
5
|
+
class MockServer {
|
|
6
|
+
static { this.serverByUrl = new Map(); }
|
|
7
|
+
static from(url) {
|
|
8
|
+
if (!MockServer.serverByUrl.has(url)) {
|
|
9
|
+
MockServer.serverByUrl.set(url, new MockServer(url));
|
|
10
|
+
}
|
|
11
|
+
return MockServer.serverByUrl.get(url);
|
|
12
|
+
}
|
|
13
|
+
get allServers() {
|
|
14
|
+
return Array.from(MockServer.serverByUrl.values());
|
|
15
|
+
}
|
|
16
|
+
//#region constructor
|
|
17
|
+
constructor(url) {
|
|
18
|
+
this.url = url;
|
|
19
|
+
this.namespacesByName = new Map();
|
|
20
|
+
MockServer.serverByUrl.set(url, this);
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region of
|
|
24
|
+
of(namespace) {
|
|
25
|
+
if (!this.namespacesByName.has(namespace)) {
|
|
26
|
+
this.namespacesByName.set(namespace, new MockNamespace(namespace, this));
|
|
27
|
+
}
|
|
28
|
+
return this.namespacesByName.get(namespace);
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region path
|
|
32
|
+
path() {
|
|
33
|
+
return this.url;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region mock namespace
|
|
38
|
+
class MockNamespace {
|
|
39
|
+
//#region constructor
|
|
40
|
+
constructor(
|
|
41
|
+
/**
|
|
42
|
+
* unique namespace name
|
|
43
|
+
*/
|
|
44
|
+
name, server) {
|
|
45
|
+
this.name = name;
|
|
46
|
+
this.server = server;
|
|
47
|
+
/**
|
|
48
|
+
* All sockets connected to this namespace
|
|
49
|
+
*/
|
|
50
|
+
this.allSocketsForNamespace = new Set();
|
|
51
|
+
/**
|
|
52
|
+
* Rooms and their sockets
|
|
53
|
+
*/
|
|
54
|
+
this.socketByRoomName = {};
|
|
55
|
+
/**
|
|
56
|
+
* Event handlers for this namespace
|
|
57
|
+
*/
|
|
58
|
+
this.namespaceEventHandlers = {};
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region on
|
|
62
|
+
on(eventName, handler) {
|
|
63
|
+
// console.log(`ON EVNET event "${eventName}"`);
|
|
64
|
+
if (!this.namespaceEventHandlers[eventName]) {
|
|
65
|
+
this.namespaceEventHandlers[eventName] =
|
|
66
|
+
new Set();
|
|
67
|
+
}
|
|
68
|
+
if (!this.namespaceEventHandlers[eventName].has(handler)) {
|
|
69
|
+
this.namespaceEventHandlers[eventName].add(handler);
|
|
70
|
+
}
|
|
71
|
+
// QUICK_FIX Emit connection event for backend
|
|
72
|
+
// TODO make it in emit
|
|
73
|
+
if (eventName === 'connection') {
|
|
74
|
+
setTimeout(() => {
|
|
75
|
+
this.emit('connection', this);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region emit
|
|
81
|
+
emit(event, ...args) {
|
|
82
|
+
this.allSocketsForNamespace?.forEach(socket => {
|
|
83
|
+
socket.emit(event, ...args);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region connect
|
|
88
|
+
connect(socket) {
|
|
89
|
+
this.allSocketsForNamespace.add(socket);
|
|
90
|
+
socket.namespaceInstance = this;
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region to
|
|
94
|
+
to(roomName) {
|
|
95
|
+
const socketsInRoom = this.socketByRoomName[roomName];
|
|
96
|
+
return new RoomEmitter(socketsInRoom, true);
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region to room
|
|
100
|
+
in(roomName) {
|
|
101
|
+
const socketsInRoom = this.socketByRoomName[roomName];
|
|
102
|
+
return new RoomEmitter(socketsInRoom, false);
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region join room
|
|
106
|
+
joinRoom(roomName, socket) {
|
|
107
|
+
if (!this.socketByRoomName[roomName]) {
|
|
108
|
+
this.socketByRoomName[roomName] = new Set();
|
|
109
|
+
}
|
|
110
|
+
this.socketByRoomName[roomName].add(socket);
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region leave room
|
|
114
|
+
leaveRoom(roomName, socket) {
|
|
115
|
+
const roomSockets = this.socketByRoomName[roomName];
|
|
116
|
+
if (roomSockets) {
|
|
117
|
+
this.socketByRoomName[roomName].delete(socket);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region nsp + name
|
|
122
|
+
get nsp() {
|
|
123
|
+
const self = this;
|
|
124
|
+
return {
|
|
125
|
+
get name() {
|
|
126
|
+
return self.name;
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
path() {
|
|
132
|
+
return this.name;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region room emitter
|
|
137
|
+
class RoomEmitter {
|
|
138
|
+
//#region constructor
|
|
139
|
+
constructor(sockets, includeSender = false, sender = null) {
|
|
140
|
+
this.sockets = sockets;
|
|
141
|
+
this.includeSender = includeSender;
|
|
142
|
+
this.sender = sender;
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region emit in room
|
|
146
|
+
emit(event, ...args) {
|
|
147
|
+
// console.log(
|
|
148
|
+
// `emit room emiter ${event} , this.sockets ${this.sockets.length}`,
|
|
149
|
+
// );
|
|
150
|
+
this.sockets?.forEach(socket => {
|
|
151
|
+
// console.log(`emit event ${event} to socket ${socket.id}`);
|
|
152
|
+
if (this.includeSender || socket !== this.sender) {
|
|
153
|
+
socket.emit(event, ...args);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region mock socket
|
|
160
|
+
class MockSocket {
|
|
161
|
+
get id() {
|
|
162
|
+
return this.nsp.name;
|
|
163
|
+
}
|
|
164
|
+
//#region constructor
|
|
165
|
+
constructor(url, opts) {
|
|
166
|
+
this.url = url;
|
|
167
|
+
this.socketEventHandlers = {};
|
|
168
|
+
// @ts-ignore
|
|
169
|
+
const [baseUrl, namespace] = [url, opts.path || '/'];
|
|
170
|
+
// console.log({ url, baseUrl, namespace });
|
|
171
|
+
const namespaceName = namespace || '/';
|
|
172
|
+
// Look up the server instance from the registry
|
|
173
|
+
const server = MockServer.from(url);
|
|
174
|
+
const ns = server.of(namespaceName);
|
|
175
|
+
ns.connect(this);
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region nsp + name
|
|
179
|
+
get nsp() {
|
|
180
|
+
const self = this;
|
|
181
|
+
return {
|
|
182
|
+
get name() {
|
|
183
|
+
return self.namespaceInstance?.name;
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region path
|
|
189
|
+
path() {
|
|
190
|
+
return this.namespaceInstance?.name;
|
|
191
|
+
}
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region on
|
|
194
|
+
on(eventName, handler) {
|
|
195
|
+
if (!this.socketEventHandlers[eventName]) {
|
|
196
|
+
this.socketEventHandlers[eventName] =
|
|
197
|
+
new Set();
|
|
198
|
+
}
|
|
199
|
+
this.socketEventHandlers[eventName].add(handler);
|
|
200
|
+
// QUICK_FIX client initing itself
|
|
201
|
+
if (eventName === 'connect') {
|
|
202
|
+
setTimeout(() => {
|
|
203
|
+
this.emit('connect');
|
|
204
|
+
// this.namespaceInstance.emit('connection', this); @UNCOMMNENT
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region emit
|
|
210
|
+
emit(eventName, ...args) {
|
|
211
|
+
eventName = eventName || '';
|
|
212
|
+
if (eventName.includes(`:${Symbols__NS__REALTIME.KEYroomSubscribe}`)) {
|
|
213
|
+
const room = args[0];
|
|
214
|
+
this.join(room);
|
|
215
|
+
}
|
|
216
|
+
else if (eventName.includes(`:${Symbols__NS__REALTIME.KEYroomUnsubscribe}`)) {
|
|
217
|
+
const room = args[0];
|
|
218
|
+
this.leave(room);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
// console.log('try to emit event (to server)', event);
|
|
222
|
+
if (this.namespaceInstance) {
|
|
223
|
+
const namespaceEventHandlers = this.namespaceInstance.namespaceEventHandlers[eventName] || [];
|
|
224
|
+
// emit to namespace events
|
|
225
|
+
for (const namespaceEventHandler of namespaceEventHandlers) {
|
|
226
|
+
if (namespaceEventHandler) {
|
|
227
|
+
namespaceEventHandler(...args);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const allSocketsForNamespaceExceptCurrent = Array.from(this.namespaceInstance.allSocketsForNamespace.values()).filter(socket => socket !== this);
|
|
231
|
+
// emit to all sockets in namespace
|
|
232
|
+
for (const socket of allSocketsForNamespaceExceptCurrent) {
|
|
233
|
+
const socketEventHandlers = socket.socketEventHandlers[eventName];
|
|
234
|
+
for (const socketEventHandler of socketEventHandlers) {
|
|
235
|
+
if (socketEventHandler) {
|
|
236
|
+
socketEventHandler(...args);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// Emit to current socket
|
|
241
|
+
const socketEventHandlers = this.socketEventHandlers[eventName] || [];
|
|
242
|
+
for (const clientHandler of socketEventHandlers) {
|
|
243
|
+
if (clientHandler) {
|
|
244
|
+
clientHandler(...args);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region join room
|
|
252
|
+
join(roomName) {
|
|
253
|
+
this.namespaceInstance.joinRoom(roomName, this);
|
|
254
|
+
}
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region leave room
|
|
257
|
+
leave(roomName) {
|
|
258
|
+
this.namespaceInstance.leaveRoom(roomName, this);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
//#endregion
|
|
262
|
+
/**
|
|
263
|
+
* Purpose:
|
|
264
|
+
* - browser-browser communication mock (in websql mode)
|
|
265
|
+
*/
|
|
266
|
+
export class RealtimeStrategyMock extends RealtimeStrategy {
|
|
267
|
+
//#region toString
|
|
268
|
+
toString() {
|
|
269
|
+
return 'mock';
|
|
270
|
+
}
|
|
271
|
+
//#endregion
|
|
272
|
+
//#region constructor
|
|
273
|
+
constructor(ctx) {
|
|
274
|
+
super(ctx);
|
|
275
|
+
this.ctx = ctx;
|
|
276
|
+
}
|
|
277
|
+
//#endregion
|
|
278
|
+
//#region server & io
|
|
279
|
+
ioServer(url, opt) {
|
|
280
|
+
const server = MockServer.from(url || this.ctx.uriOrigin);
|
|
281
|
+
return server.of(opt?.path || '/');
|
|
282
|
+
}
|
|
283
|
+
get ioClient() {
|
|
284
|
+
const clientIo = (uri, opts) => {
|
|
285
|
+
return new MockSocket(uri || this.ctx.uriOrigin, opts);
|
|
286
|
+
};
|
|
287
|
+
return clientIo;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { RealtimeStrategy } from './realtime-strategy';
|
|
2
|
+
//#region @backend
|
|
3
|
+
import { Server } from 'socket.io';
|
|
4
|
+
//#endregion
|
|
5
|
+
import { io } from 'socket.io-client';
|
|
6
|
+
/**
|
|
7
|
+
* Purpose:
|
|
8
|
+
* - backend-browser communication
|
|
9
|
+
* - backend-backend communication
|
|
10
|
+
*/
|
|
11
|
+
export class RealtimeStrategySocketIO extends RealtimeStrategy {
|
|
12
|
+
toString() {
|
|
13
|
+
return 'socket-io';
|
|
14
|
+
}
|
|
15
|
+
constructor(ctx) {
|
|
16
|
+
super(ctx);
|
|
17
|
+
this.ctx = ctx;
|
|
18
|
+
}
|
|
19
|
+
ioServer(...args) {
|
|
20
|
+
//#region @backendFunc
|
|
21
|
+
return new Server(...args);
|
|
22
|
+
//#endregion
|
|
23
|
+
}
|
|
24
|
+
get ioClient() {
|
|
25
|
+
return io;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
//#endregion
|
|
2
|
+
import { ___NS__isString } from 'tnp-core/lib-prod';
|
|
3
|
+
import { Symbols__NS__REALTIME } from '../symbols';
|
|
4
|
+
//#endregion
|
|
5
|
+
export class RealtimeSubsManager {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.options = options;
|
|
8
|
+
this.isListening = false;
|
|
9
|
+
this.observers = [];
|
|
10
|
+
}
|
|
11
|
+
//#region methods & getters / start listen if not started
|
|
12
|
+
startListenIfNotStarted(realtime) {
|
|
13
|
+
if (this.options.core.ctx.disabledRealtime) {
|
|
14
|
+
console.warn(`[Taon][startListenIfNotStarted] sockets are disabled`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (!realtime) {
|
|
18
|
+
console.warn(`[Taon][startListenIfNotStarted] invalid socket connection`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (!this.isListening) {
|
|
22
|
+
// console.info(`[BROWSER]][IPC] subscribe to "${this.options?.roomName}" by sending event: "${subscribeEvent}"`, this.options);
|
|
23
|
+
this.isListening = true;
|
|
24
|
+
if (this.options.customEvent) {
|
|
25
|
+
const subscribeEvent = Symbols__NS__REALTIME.ROOM_SUBSCRIBE_CUSTOM(this.options.core.ctx.contextName);
|
|
26
|
+
// this means: send to current client custom event notification
|
|
27
|
+
realtime.emit(subscribeEvent, this.options.roomName);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
if (___NS__isString(this.options.property)) {
|
|
31
|
+
const subscribeEvent = Symbols__NS__REALTIME.ROOM_SUBSCRIBE_ENTITY_PROPERTY_UPDATE_EVENTS(this.options.core.ctx.contextName);
|
|
32
|
+
// this means: send to current client entity property events updates
|
|
33
|
+
realtime.emit(subscribeEvent, this.options.roomName);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const subscribeEvent = Symbols__NS__REALTIME.ROOM_SUBSCRIBE_ENTITY_UPDATE_EVENTS(this.options.core.ctx.contextName);
|
|
37
|
+
// this means: send to current client entity update events
|
|
38
|
+
realtime.emit(subscribeEvent, this.options.roomName);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// subPath -> SYMBOL - (customevnet|entityupdatebyid){..}{..}
|
|
42
|
+
realtime.on(this.options.roomName, data => {
|
|
43
|
+
this.update(data);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region methods & getters / add observer
|
|
49
|
+
add(observer) {
|
|
50
|
+
// log.info('Add observer')
|
|
51
|
+
this.observers.push(observer);
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region methods & getters / remove observer
|
|
55
|
+
remove(observer) {
|
|
56
|
+
// log.info('Remove observer')
|
|
57
|
+
this.observers = this.observers.filter(obs => obs !== observer);
|
|
58
|
+
if (this.observers.length === 0) {
|
|
59
|
+
// log.info('Emit unsubscribe to server SERVER')
|
|
60
|
+
this.isListening = false;
|
|
61
|
+
const { core, customEvent, roomName, property } = this.options;
|
|
62
|
+
const realtime = core.socketFE;
|
|
63
|
+
if (customEvent) {
|
|
64
|
+
realtime.emit(Symbols__NS__REALTIME.ROOM_UNSUBSCRIBE_CUSTOM(this.options.core.ctx.contextName), roomName);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
if (___NS__isString(property)) {
|
|
68
|
+
realtime.emit(Symbols__NS__REALTIME.ROOM_UNSUBSCRIBE_ENTITY_PROPERTY_UPDATE_EVENTS(this.options.core.ctx.contextName), roomName);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
realtime.emit(Symbols__NS__REALTIME.ROOM_UNSUBSCRIBE_ENTITY_UPDATE_EVENTS(this.options.core.ctx.contextName), roomName);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region methods & getters / update
|
|
78
|
+
update(data) {
|
|
79
|
+
// log.data(`realtime update!!!!! observers=${this.observers?.length} `)
|
|
80
|
+
// console.log('updating', data);
|
|
81
|
+
this.observers.forEach(observer => {
|
|
82
|
+
// console.log(`observer closed: ${observer.closed}`,observer);
|
|
83
|
+
if (!observer.closed) {
|
|
84
|
+
observer.next(data);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|