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.
Files changed (226) hide show
  1. package/bin/taon +5 -5
  2. package/bin/taon-debug +5 -5
  3. package/bin/taon-debug-brk +4 -4
  4. package/browser/fesm2022/taon-browser.mjs +11 -1
  5. package/browser/fesm2022/taon-browser.mjs.map +1 -1
  6. package/browser/package.json +1 -1
  7. package/browser-prod/fesm2022/taon-browser.mjs +11 -1
  8. package/browser-prod/fesm2022/taon-browser.mjs.map +1 -1
  9. package/browser-prod/package.json +1 -1
  10. package/icon-menu-taon.svg +15 -15
  11. package/lib/build-info._auto-generated_.d.ts +1 -1
  12. package/lib/build-info._auto-generated_.js +1 -1
  13. package/lib/endpoint-context.d.ts +1 -1
  14. package/lib/endpoint-context.js +11 -6
  15. package/lib/endpoint-context.js.map +1 -1
  16. package/lib/package.json +1 -1
  17. package/lib/ui/index.js +2 -2
  18. package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
  19. package/lib-prod/base-classes/base-abstract-entity.js +33 -0
  20. package/lib-prod/base-classes/base-angular-service.js +56 -0
  21. package/lib-prod/base-classes/base-class.js +37 -0
  22. package/lib-prod/base-classes/base-context.js +21 -0
  23. package/lib-prod/base-classes/base-controller.js +162 -0
  24. package/lib-prod/base-classes/base-crud-controller.js +235 -0
  25. package/lib-prod/base-classes/base-custom-repository.js +20 -0
  26. package/lib-prod/base-classes/base-electron-service.js +0 -0
  27. package/lib-prod/base-classes/base-entity.js +32 -0
  28. package/lib-prod/base-classes/base-file-upload.middleware.js +78 -0
  29. package/lib-prod/base-classes/base-injector.js +202 -0
  30. package/lib-prod/base-classes/base-middleware.js +6 -0
  31. package/lib-prod/base-classes/base-migration.js +23 -0
  32. package/lib-prod/base-classes/base-provider.js +6 -0
  33. package/lib-prod/base-classes/base-repository.js +589 -0
  34. package/lib-prod/base-classes/base-subscriber-for-entity.js +154 -0
  35. package/lib-prod/base-classes/base.js +0 -0
  36. package/lib-prod/build-info._auto-generated_.js +14 -0
  37. package/lib-prod/config/controller-config.js +28 -0
  38. package/lib-prod/config/controller-options.js +6 -0
  39. package/lib-prod/config/method-config.js +9 -0
  40. package/lib-prod/config/param-config.js +9 -0
  41. package/lib-prod/constants.js +29 -0
  42. package/lib-prod/context-db-migrations.js +339 -0
  43. package/lib-prod/create-context.js +152 -0
  44. package/lib-prod/decorators/classes/controller-decorator.js +21 -0
  45. package/lib-prod/decorators/classes/entity-decorator.js +49 -0
  46. package/lib-prod/decorators/classes/middleware-decorator.js +26 -0
  47. package/lib-prod/decorators/classes/migration-decorator.js +24 -0
  48. package/lib-prod/decorators/classes/provider-decorator.js +25 -0
  49. package/lib-prod/decorators/classes/repository-decorator.js +24 -0
  50. package/lib-prod/decorators/classes/subscriber-decorator.js +25 -0
  51. package/lib-prod/decorators/decorator-abstract-opt.js +5 -0
  52. package/lib-prod/decorators/http/http-decorators.js +5 -0
  53. package/lib-prod/decorators/http/http-methods-decorators.js +144 -0
  54. package/lib-prod/decorators/http/http-params-decorators.js +68 -0
  55. package/lib-prod/dependency-injection/di-container.js +31 -0
  56. package/lib-prod/endpoint-context-storage.js +36 -0
  57. package/lib-prod/endpoint-context.js +2033 -0
  58. package/lib-prod/entity-process.js +214 -0
  59. package/lib-prod/env/env.angular-node-app.js +130 -0
  60. package/lib-prod/env/env.docs-webapp.js +130 -0
  61. package/lib-prod/env/env.electron-app.js +130 -0
  62. package/lib-prod/env/env.mobile-app.js +130 -0
  63. package/lib-prod/env/env.npm-lib-and-cli-tool.js +130 -0
  64. package/lib-prod/env/env.vscode-plugin.js +130 -0
  65. package/lib-prod/env/index.js +6 -0
  66. package/lib-prod/express-types.js +0 -0
  67. package/lib-prod/formly/formly.models.js +0 -0
  68. package/lib-prod/formly/fromly.js +184 -0
  69. package/lib-prod/formly/type-from-entity.js +58 -0
  70. package/lib-prod/get-response-value.js +19 -0
  71. package/lib-prod/global-state/taon-global-state/index.js +5 -0
  72. package/lib-prod/global-state/taon-global-state/taon-global-state.abstract.context.js +20 -0
  73. package/lib-prod/global-state/taon-global-state/taon-global-state.constants.js +10 -0
  74. package/lib-prod/global-state/taon-global-state/taon-global-state.controller.js +48 -0
  75. package/lib-prod/global-state/taon-global-state/taon-global-state.entity.js +48 -0
  76. package/lib-prod/global-state/taon-global-state/taon-global-state.middleware.js +22 -0
  77. package/lib-prod/global-state/taon-global-state/taon-global-state.models.js +34 -0
  78. package/lib-prod/global-state/taon-global-state/taon-global-state.provider.js +22 -0
  79. package/lib-prod/global-state/taon-global-state/taon-global-state.repository.js +47 -0
  80. package/lib-prod/global-state/taon-global-state/taon-global-state.subscriber.js +29 -0
  81. package/lib-prod/global-state/taon-global-state/taon-global-state.utils.js +11 -0
  82. package/lib-prod/global-state/taon-transaction-registry/index.js +10 -0
  83. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.abstract.context.js +22 -0
  84. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.constants.js +8 -0
  85. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.controller.js +41 -0
  86. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.entity.js +56 -0
  87. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.middleware.js +22 -0
  88. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.models.js +10 -0
  89. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.provider.js +22 -0
  90. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.repository.js +36 -0
  91. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.subscriber.js +29 -0
  92. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.utils.js +6 -0
  93. package/lib-prod/helpers/class-helpers.js +195 -0
  94. package/lib-prod/helpers/clone-obj.js +21 -0
  95. package/lib-prod/helpers/taon-helpers.js +129 -0
  96. package/lib-prod/index._auto-generated_.js +0 -0
  97. package/lib-prod/index.js +231 -0
  98. package/lib-prod/inject.js +34 -0
  99. package/lib-prod/migrations/index.js +1 -0
  100. package/lib-prod/migrations/migrations_index._auto-generated_.js +0 -0
  101. package/lib-prod/models.js +109 -0
  102. package/lib-prod/orm/columns.js +124 -0
  103. package/lib-prod/orm/index.js +1 -0
  104. package/lib-prod/package.json +1 -1
  105. package/lib-prod/realtime/realtime-client.js +196 -0
  106. package/lib-prod/realtime/realtime-core.js +82 -0
  107. package/lib-prod/realtime/realtime-server.js +252 -0
  108. package/lib-prod/realtime/realtime-strategy/index.js +4 -0
  109. package/lib-prod/realtime/realtime-strategy/realtime-strategy-ipc.js +226 -0
  110. package/lib-prod/realtime/realtime-strategy/realtime-strategy-mock.js +262 -0
  111. package/lib-prod/realtime/realtime-strategy/realtime-strategy-socket-io.js +21 -0
  112. package/lib-prod/realtime/realtime-strategy/realtime-strategy.js +14 -0
  113. package/lib-prod/realtime/realtime-subs-manager.js +96 -0
  114. package/lib-prod/realtime/realtime.models.js +0 -0
  115. package/lib-prod/symbols.js +109 -0
  116. package/lib-prod/ui/index.js +5 -0
  117. package/lib-prod/ui/taon-admin-mode-configuration/index.js +5 -0
  118. package/lib-prod/validators.js +74 -0
  119. package/package.json +1 -1
  120. package/websql/fesm2022/taon-websql.mjs +11 -1
  121. package/websql/fesm2022/taon-websql.mjs.map +1 -1
  122. package/websql/package.json +1 -1
  123. package/websql-prod/fesm2022/taon-websql.mjs +11 -1
  124. package/websql-prod/fesm2022/taon-websql.mjs.map +1 -1
  125. package/websql-prod/package.json +1 -1
  126. package/lib-prod/base-classes/base-abstract-entity.ts +0 -34
  127. package/lib-prod/base-classes/base-angular-service.ts +0 -107
  128. package/lib-prod/base-classes/base-class.ts +0 -46
  129. package/lib-prod/base-classes/base-context.ts +0 -21
  130. package/lib-prod/base-classes/base-controller.ts +0 -240
  131. package/lib-prod/base-classes/base-crud-controller.ts +0 -298
  132. package/lib-prod/base-classes/base-custom-repository.ts +0 -10
  133. package/lib-prod/base-classes/base-electron-service.ts +0 -60
  134. package/lib-prod/base-classes/base-entity.ts +0 -28
  135. package/lib-prod/base-classes/base-file-upload.middleware.ts +0 -92
  136. package/lib-prod/base-classes/base-injector.ts +0 -278
  137. package/lib-prod/base-classes/base-middleware.ts +0 -71
  138. package/lib-prod/base-classes/base-migration.ts +0 -26
  139. package/lib-prod/base-classes/base-provider.ts +0 -8
  140. package/lib-prod/base-classes/base-repository.ts +0 -942
  141. package/lib-prod/base-classes/base-subscriber-for-entity.ts +0 -196
  142. package/lib-prod/base-classes/base.ts +0 -31
  143. package/lib-prod/build-info._auto-generated_.ts +0 -27
  144. package/lib-prod/config/controller-config.ts +0 -58
  145. package/lib-prod/config/controller-options.ts +0 -19
  146. package/lib-prod/config/method-config.ts +0 -55
  147. package/lib-prod/config/param-config.ts +0 -16
  148. package/lib-prod/constants.ts +0 -63
  149. package/lib-prod/context-db-migrations.ts +0 -488
  150. package/lib-prod/create-context.ts +0 -345
  151. package/lib-prod/decorators/classes/controller-decorator.ts +0 -25
  152. package/lib-prod/decorators/classes/entity-decorator.ts +0 -57
  153. package/lib-prod/decorators/classes/middleware-decorator.ts +0 -29
  154. package/lib-prod/decorators/classes/migration-decorator.ts +0 -27
  155. package/lib-prod/decorators/classes/provider-decorator.ts +0 -28
  156. package/lib-prod/decorators/classes/repository-decorator.ts +0 -26
  157. package/lib-prod/decorators/classes/subscriber-decorator.ts +0 -28
  158. package/lib-prod/decorators/decorator-abstract-opt.ts +0 -4
  159. package/lib-prod/decorators/http/http-decorators.ts +0 -26
  160. package/lib-prod/decorators/http/http-methods-decorators.ts +0 -275
  161. package/lib-prod/decorators/http/http-params-decorators.ts +0 -105
  162. package/lib-prod/dependency-injection/di-container.ts +0 -39
  163. package/lib-prod/endpoint-context-storage.ts +0 -47
  164. package/lib-prod/endpoint-context.ts +0 -3105
  165. package/lib-prod/entity-process.ts +0 -286
  166. package/lib-prod/env/env.angular-node-app.ts +0 -66
  167. package/lib-prod/env/env.docs-webapp.ts +0 -66
  168. package/lib-prod/env/env.electron-app.ts +0 -66
  169. package/lib-prod/env/env.mobile-app.ts +0 -66
  170. package/lib-prod/env/env.npm-lib-and-cli-tool.ts +0 -66
  171. package/lib-prod/env/env.vscode-plugin.ts +0 -66
  172. package/lib-prod/env/index.ts +0 -6
  173. package/lib-prod/express-types.ts +0 -4
  174. package/lib-prod/formly/formly.models.ts +0 -7
  175. package/lib-prod/formly/fromly.ts +0 -261
  176. package/lib-prod/formly/type-from-entity.ts +0 -80
  177. package/lib-prod/get-response-value.ts +0 -30
  178. package/lib-prod/global-state/taon-global-state/index.ts +0 -6
  179. package/lib-prod/global-state/taon-global-state/taon-global-state.abstract.context.ts +0 -21
  180. package/lib-prod/global-state/taon-global-state/taon-global-state.constants.ts +0 -9
  181. package/lib-prod/global-state/taon-global-state/taon-global-state.controller.ts +0 -44
  182. package/lib-prod/global-state/taon-global-state/taon-global-state.entity.ts +0 -40
  183. package/lib-prod/global-state/taon-global-state/taon-global-state.middleware.ts +0 -12
  184. package/lib-prod/global-state/taon-global-state/taon-global-state.models.ts +0 -48
  185. package/lib-prod/global-state/taon-global-state/taon-global-state.provider.ts +0 -16
  186. package/lib-prod/global-state/taon-global-state/taon-global-state.repository.ts +0 -47
  187. package/lib-prod/global-state/taon-global-state/taon-global-state.subscriber.ts +0 -18
  188. package/lib-prod/global-state/taon-global-state/taon-global-state.utils.ts +0 -21
  189. package/lib-prod/global-state/taon-transaction-registry/index.ts +0 -11
  190. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.abstract.context.ts +0 -23
  191. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.constants.ts +0 -7
  192. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.controller.ts +0 -38
  193. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.entity.ts +0 -54
  194. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.middleware.ts +0 -12
  195. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.models.ts +0 -6
  196. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.provider.ts +0 -16
  197. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.repository.ts +0 -29
  198. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.subscriber.ts +0 -20
  199. package/lib-prod/global-state/taon-transaction-registry/taon-transaction-registry.utils.ts +0 -9
  200. package/lib-prod/helpers/class-helpers.ts +0 -315
  201. package/lib-prod/helpers/clone-obj.ts +0 -24
  202. package/lib-prod/helpers/taon-helpers.ts +0 -181
  203. package/lib-prod/index._auto-generated_.ts +0 -5
  204. package/lib-prod/index.ts +0 -323
  205. package/lib-prod/inject.ts +0 -111
  206. package/lib-prod/lib-info.md +0 -8
  207. package/lib-prod/migrations/index.ts +0 -2
  208. package/lib-prod/migrations/migrations-info.md +0 -6
  209. package/lib-prod/migrations/migrations_index._auto-generated_.ts +0 -5
  210. package/lib-prod/models.ts +0 -427
  211. package/lib-prod/orm/columns.ts +0 -121
  212. package/lib-prod/orm/index.ts +0 -62
  213. package/lib-prod/realtime/realtime-client.ts +0 -288
  214. package/lib-prod/realtime/realtime-core.ts +0 -134
  215. package/lib-prod/realtime/realtime-server.ts +0 -398
  216. package/lib-prod/realtime/realtime-strategy/index.ts +0 -4
  217. package/lib-prod/realtime/realtime-strategy/realtime-strategy-ipc.ts +0 -344
  218. package/lib-prod/realtime/realtime-strategy/realtime-strategy-mock.ts +0 -349
  219. package/lib-prod/realtime/realtime-strategy/realtime-strategy-socket-io.ts +0 -30
  220. package/lib-prod/realtime/realtime-strategy/realtime-strategy.ts +0 -21
  221. package/lib-prod/realtime/realtime-subs-manager.ts +0 -127
  222. package/lib-prod/realtime/realtime.models.ts +0 -33
  223. package/lib-prod/symbols.ts +0 -136
  224. package/lib-prod/ui/index.ts +0 -1
  225. package/lib-prod/ui/taon-admin-mode-configuration/index.ts +0 -1
  226. package/lib-prod/validators.ts +0 -103
@@ -1,344 +0,0 @@
1
- //#region imports
2
- /* */
3
- import type * as Electron from 'electron';
4
- import { ipcMain } from 'electron'; // @backend
5
- import { Server, ServerOptions } from 'socket.io';
6
- import type { io, ManagerOptions, SocketOptions } from 'socket.io-client';
7
-
8
- import { EndpointContext } from '../../endpoint-context';
9
- import { Symbols__NS__classMethodsNames, Symbols__NS__classNameStaticProperty, Symbols__NS__ctxInClassOrClassObj, Symbols__NS__fullClassNameStaticProperty, Symbols__NS__metadata, Symbols__NS__old, Symbols__NS__orignalClass, Symbols__NS__orignalClassClonesObj, Symbols__NS__REALTIME } from '../../symbols';
10
- import { RealtimeModels__NS__ChangeOption, RealtimeModels__NS__EventHandler, RealtimeModels__NS__SubsManagerOpt } from '../realtime.models';
11
-
12
- import { RealtimeStrategy } from './realtime-strategy';
13
- //#endregion
14
-
15
- //#region mock server ipc
16
- export class MockServerIpc {
17
- static serverByContextName = new Map<string, MockServerIpc>();
18
-
19
- static from(contextName: string): MockServerIpc {
20
- if (!MockServerIpc.serverByContextName.has(contextName)) {
21
- MockServerIpc.serverByContextName.set(
22
- contextName,
23
- new MockServerIpc(contextName),
24
- );
25
- }
26
- return MockServerIpc.serverByContextName.get(contextName);
27
- }
28
-
29
- namespacesByName = new Map<string, MockNamespaceIpc>();
30
-
31
- //#region constructor
32
- constructor(public contextName: string) {
33
- MockServerIpc.serverByContextName.set(contextName, this);
34
- }
35
- //#endregion
36
-
37
- //#region of
38
- of(namespace: string): MockNamespaceIpc {
39
- if (!this.namespacesByName.has(namespace)) {
40
- this.namespacesByName.set(
41
- namespace,
42
- new MockNamespaceIpc(namespace, this),
43
- );
44
- }
45
- return this.namespacesByName.get(namespace);
46
- }
47
- //#endregion
48
- }
49
- //#endregion
50
-
51
- //#region mock namespace ipc
52
- export class MockNamespaceIpc {
53
- //#region fields & getters
54
- electronClients = new Set<Electron.WebContents>();
55
- roomsByRoomName: {
56
- [roomName: string]: Set<Electron.WebContents>;
57
- } = {};
58
-
59
- private namespaceEventHandlers: {
60
- [eventName: string]: Set<RealtimeModels__NS__EventHandler>;
61
- } = {};
62
- //#endregion
63
-
64
- //#region constructor
65
- constructor(
66
- /**
67
- * Namespace name
68
- */
69
- public name: string,
70
- public server: MockServerIpc,
71
- ) {}
72
- //#endregion
73
-
74
- //#region on
75
- on(eventName: string, callback: RealtimeModels__NS__EventHandler) {
76
- //#region @backendFunc
77
- const listenKey = `(${this.name}) "${eventName}"`;
78
-
79
- if (!this.namespaceEventHandlers[eventName]) {
80
- this.namespaceEventHandlers[eventName] = new Set();
81
- }
82
- this.namespaceEventHandlers[eventName].add(callback);
83
-
84
- ipcMain.on(listenKey, (eventElectron, ...args) => {
85
- this.electronClients.add(eventElectron.sender);
86
-
87
- const connectionListener = `(${this.name}) "connection"`;
88
- if (connectionListener === listenKey) {
89
- callback(this, ...args);
90
- } else {
91
- if (eventName.includes(`:${Symbols__NS__REALTIME.KEYroomSubscribe}`)) {
92
- const roomName = args[0];
93
- this.join(eventElectron.sender, roomName);
94
- } else if (
95
- eventName.includes(`:${Symbols__NS__REALTIME.KEYroomUnsubscribe}`)
96
- ) {
97
- const roomName = args[0];
98
- this.leave(eventElectron.sender, roomName);
99
- } else {
100
- callback(...args);
101
- }
102
- }
103
- });
104
- // this.emit(listenKey); // QUICK_FIX
105
- //#endregion
106
- }
107
- //#endregion
108
-
109
- //#region off
110
- off(event: string, callback?: RealtimeModels__NS__EventHandler) {
111
- //#region @backendFunc
112
- if (!this.namespaceEventHandlers[event]) {
113
- return;
114
- }
115
-
116
- if (callback) {
117
- this.namespaceEventHandlers[event].delete(callback);
118
- } else {
119
- delete this.namespaceEventHandlers[event];
120
- }
121
- const removeKey = `(${this.name}) "${event}"`;
122
- ipcMain.removeListener(removeKey, callback);
123
- //#endregion
124
- }
125
- //#endregion
126
-
127
- //#region emit
128
- emit(eventName: string, ...args: any[]) {
129
- //#region @backendFunc
130
- const sendEventKey = `(${this.name}) "${eventName}"`;
131
- for (const webContents of this.electronClients) {
132
- webContents.send(sendEventKey, ...args);
133
- }
134
- // const allWindows = Electron.BrowserWindow.getAllWindows();
135
- // allWindows.forEach((win, index) => {
136
- // win.webContents.send(sendEventKey, ...args);
137
- // });
138
- //#endregion
139
- }
140
- //#endregion
141
-
142
- //#region to
143
- to(roomName: string) {
144
- const electronClientsInroom = this.roomsByRoomName[roomName];
145
- return new RoomEmitterIpc(electronClientsInroom, this.name, true);
146
- }
147
- //#endregion
148
-
149
- //#region in
150
- in(roomName: string) {
151
- const electronClientsInroom = this.roomsByRoomName[roomName];
152
- return new RoomEmitterIpc(electronClientsInroom, this.name, false);
153
- }
154
- //#endregion
155
-
156
- //#region join
157
- join(webContents: Electron.WebContents, roomName: string) {
158
- if (!this.roomsByRoomName[roomName]) {
159
- this.roomsByRoomName[roomName] = new Set();
160
- }
161
- this.roomsByRoomName[roomName].add(webContents);
162
- }
163
- //#endregion
164
-
165
- //#region leave
166
- leave(webContents: Electron.WebContents, roomName: string) {
167
- if (this.roomsByRoomName[roomName]) {
168
- this.roomsByRoomName[roomName].delete(webContents);
169
- if (this.roomsByRoomName[roomName].size === 0) {
170
- delete this.roomsByRoomName[roomName];
171
- }
172
- }
173
- }
174
- //#endregion
175
-
176
- //#region path
177
- path() {
178
- return this.name;
179
- }
180
- //#endregion
181
-
182
- //#region get nsp
183
- get nsp() {
184
- const self = this;
185
- return {
186
- get name() {
187
- return self.name;
188
- },
189
- };
190
- }
191
- //#endregion
192
- }
193
-
194
- //#endregion
195
-
196
- //#region room emitter ipc
197
- class RoomEmitterIpc {
198
- //#region constructor
199
- constructor(
200
- private electronClients: Set<Electron.WebContents>,
201
- /**
202
- * namespace name
203
- */
204
- private name: string,
205
- private includeSender: boolean = false,
206
- private sender: MockSocketIpc = null, // TODO QUICK FIX how to include sender
207
- ) {}
208
- //#endregion
209
-
210
- //#region emit in room
211
- emit(eventName: string, ...args: any[]): void {
212
- const emitEvent = `(${this.name}) "${eventName}"`;
213
- this.electronClients?.forEach(webContents => {
214
- webContents.send(emitEvent, ...args);
215
- });
216
- }
217
- //#endregion
218
- }
219
- //#endregion
220
-
221
- //#region mock socket ipc
222
- export class MockSocketIpc {
223
- //#region fields & getters
224
-
225
- //#region fields & getters / ipc renderer
226
- /* */
227
- /* */
228
-
229
- //#endregion
230
-
231
- //#region fields & getters / event handlers by name
232
- private socketEventHandlers = {} as {
233
- [eventName: string]: Set<RealtimeModels__NS__EventHandler>;
234
- };
235
- //#endregion
236
-
237
- //#region fields & getters / name
238
- get name() {
239
- return this.namespaceName;
240
- }
241
- //#endregion
242
-
243
- //#endregion
244
-
245
- //#region constructor
246
- /**
247
- * @param namespaceName instead url for ipc
248
- */
249
- constructor(public namespaceName: string) {
250
- /* */
251
- /* */
252
-
253
- }
254
- //#endregion
255
-
256
- //#region on
257
- on(eventName: string, callback: (event: any, ...args: any[]) => void) {
258
- /* */
259
- /* */
260
- /* */
261
- /* */
262
- /* */
263
- /* */
264
- /* */
265
- /* */
266
- /* */
267
- /* */
268
- /* */
269
- /* */
270
- /* */
271
- /* */
272
- /* */
273
-
274
- }
275
- //#endregion
276
-
277
- //#region off
278
- off(event: string, callback?: (event: any, ...args: any[]) => void) {
279
- /* */
280
- /* */
281
- /* */
282
- /* */
283
- /* */
284
- /* */
285
- /* */
286
- /* */
287
- /* */
288
- /* */
289
- /* */
290
- /* */
291
- /* */
292
- /* */
293
- /* */
294
-
295
- }
296
- //#endregion
297
-
298
- //#region emit
299
- emit(event: string, ...args: any[]) {
300
- /* */
301
- /* */
302
- /* */
303
-
304
- }
305
- //#endregion
306
- }
307
- //#endregion
308
-
309
- /**
310
- * Purpose:
311
- * - backend-browser communication between 2 processes in electron mode
312
- */
313
- export class RealtimeStrategyIpc extends RealtimeStrategy {
314
- //#region to string
315
- toString(): string {
316
- return 'ipc';
317
- }
318
- //#endregion
319
-
320
- //#region constructor
321
- constructor(protected ctx: EndpointContext) {
322
- super(ctx);
323
- }
324
- //#endregion
325
-
326
- //#region server & io
327
- ioServer(__: string, opt: ServerOptions) {
328
- const namespace = opt?.path || '/';
329
- const server = MockServerIpc.from(this.ctx.contextName);
330
- return server.of(namespace) as any;
331
- }
332
-
333
- get ioClient() {
334
- const clientIo = (
335
- __: string,
336
- opt?: Partial<ManagerOptions & SocketOptions>,
337
- ): MockSocketIpc => {
338
- const namespace = opt?.path || '/';
339
- return new MockSocketIpc(namespace);
340
- };
341
- return clientIo as any;
342
- }
343
- //#endregion
344
- }
@@ -1,349 +0,0 @@
1
- //#region imports
2
- import type { EndpointContext } from '../../endpoint-context';
3
- import { RealtimeStrategy } from './realtime-strategy';
4
- import { Symbols__NS__classMethodsNames, Symbols__NS__classNameStaticProperty, Symbols__NS__ctxInClassOrClassObj, Symbols__NS__fullClassNameStaticProperty, Symbols__NS__metadata, Symbols__NS__old, Symbols__NS__orignalClass, Symbols__NS__orignalClassClonesObj, Symbols__NS__REALTIME } from '../../symbols';
5
- import { ManagerOptions, SocketOptions } from 'socket.io-client';
6
- import { RealtimeModels__NS__ChangeOption, RealtimeModels__NS__EventHandler, RealtimeModels__NS__SubsManagerOpt } from '../realtime.models';
7
- import { ServerOptions } from 'socket.io';
8
- //#endregion
9
-
10
- //#region mock server
11
- class MockServer {
12
- static serverByUrl = new Map<string, MockServer>();
13
- static from(url: string): MockServer {
14
- if (!MockServer.serverByUrl.has(url)) {
15
- MockServer.serverByUrl.set(url, new MockServer(url));
16
- }
17
- return MockServer.serverByUrl.get(url);
18
- }
19
-
20
- get allServers() {
21
- return Array.from(MockServer.serverByUrl.values());
22
- }
23
-
24
- namespacesByName = new Map<string, MockNamespace>();
25
-
26
- //#region constructor
27
- constructor(public url: string) {
28
- MockServer.serverByUrl.set(url, this);
29
- }
30
- //#endregion
31
-
32
- //#region of
33
- of(namespace: string): MockNamespace {
34
- if (!this.namespacesByName.has(namespace)) {
35
- this.namespacesByName.set(namespace, new MockNamespace(namespace, this));
36
- }
37
- return this.namespacesByName.get(namespace);
38
- }
39
- //#endregion
40
-
41
- //#region path
42
- path() {
43
- return this.url;
44
- }
45
- //#endregion
46
- }
47
- //#endregion
48
-
49
- //#region mock namespace
50
- class MockNamespace {
51
- /**
52
- * All sockets connected to this namespace
53
- */
54
- public readonly allSocketsForNamespace = new Set<MockSocket>();
55
- /**
56
- * Rooms and their sockets
57
- */
58
- private socketByRoomName: {
59
- [roomName: string]: Set<MockSocket>;
60
- } = {};
61
- /**
62
- * Event handlers for this namespace
63
- */
64
- public namespaceEventHandlers: {
65
- [eventName: string]: Set<RealtimeModels__NS__EventHandler>;
66
- } = {};
67
-
68
- //#region constructor
69
- constructor(
70
- /**
71
- * unique namespace name
72
- */
73
- public name: string,
74
- public server: MockServer,
75
- ) {}
76
- //#endregion
77
-
78
- //#region on
79
- on(eventName: string, handler: RealtimeModels__NS__EventHandler): void {
80
- // console.log(`ON EVNET event "${eventName}"`);
81
- if (!this.namespaceEventHandlers[eventName]) {
82
- this.namespaceEventHandlers[eventName] =
83
- new Set<RealtimeModels__NS__EventHandler>();
84
- }
85
-
86
- if (!this.namespaceEventHandlers[eventName].has(handler)) {
87
- this.namespaceEventHandlers[eventName].add(handler);
88
- }
89
-
90
- // QUICK_FIX Emit connection event for backend
91
- // TODO make it in emit
92
- if (eventName === 'connection') {
93
- setTimeout(() => {
94
- this.emit('connection', this);
95
- });
96
- }
97
- }
98
- //#endregion
99
-
100
- //#region emit
101
- emit(event: string, ...args: any[]): void {
102
- this.allSocketsForNamespace?.forEach(socket => {
103
- socket.emit(event, ...args);
104
- });
105
- }
106
- //#endregion
107
-
108
- //#region connect
109
- connect(socket: MockSocket): void {
110
- this.allSocketsForNamespace.add(socket);
111
- socket.namespaceInstance = this;
112
- }
113
- //#endregion
114
-
115
- //#region to
116
- to(roomName: string): RoomEmitter {
117
- const socketsInRoom = this.socketByRoomName[roomName];
118
- return new RoomEmitter(socketsInRoom, true);
119
- }
120
- //#endregion
121
-
122
- //#region to room
123
- in(roomName: string): RoomEmitter {
124
- const socketsInRoom = this.socketByRoomName[roomName];
125
- return new RoomEmitter(socketsInRoom, false);
126
- }
127
- //#endregion
128
-
129
- //#region join room
130
- joinRoom(roomName: string, socket: MockSocket): void {
131
- if (!this.socketByRoomName[roomName]) {
132
- this.socketByRoomName[roomName] = new Set<MockSocket>();
133
- }
134
- this.socketByRoomName[roomName].add(socket);
135
- }
136
- //#endregion
137
-
138
- //#region leave room
139
- leaveRoom(roomName: string, socket: MockSocket): void {
140
- const roomSockets = this.socketByRoomName[roomName];
141
- if (roomSockets) {
142
- this.socketByRoomName[roomName].delete(socket);
143
- }
144
- }
145
- //#endregion
146
-
147
- //#region nsp + name
148
- get nsp() {
149
- const self = this;
150
- return {
151
- get name() {
152
- return self.name;
153
- },
154
- };
155
- }
156
- //#endregion
157
-
158
- path() {
159
- return this.name;
160
- }
161
- }
162
- //#endregion
163
-
164
- //#region room emitter
165
- class RoomEmitter {
166
- //#region constructor
167
- constructor(
168
- private sockets: Set<MockSocket>,
169
- private includeSender: boolean = false,
170
- private sender: MockSocket = null, // TODO QUICK FIX how to include sender
171
- ) {}
172
- //#endregion
173
-
174
- //#region emit in room
175
- emit(event: string, ...args: any[]): void {
176
- // console.log(
177
- // `emit room emiter ${event} , this.sockets ${this.sockets.length}`,
178
- // );
179
- this.sockets?.forEach(socket => {
180
- // console.log(`emit event ${event} to socket ${socket.id}`);
181
- if (this.includeSender || socket !== this.sender) {
182
- socket.emit(event, ...args);
183
- }
184
- });
185
- }
186
- //#endregion
187
- }
188
- //#endregion
189
-
190
- //#region mock socket
191
- class MockSocket {
192
- public namespaceInstance: MockNamespace;
193
- private socketEventHandlers = {} as {
194
- [eventName: string]: Set<RealtimeModels__NS__EventHandler>;
195
- };
196
- get id() {
197
- return this.nsp.name;
198
- }
199
-
200
- //#region constructor
201
- constructor(
202
- public url: string,
203
- opts?: Partial<ManagerOptions & SocketOptions>,
204
- ) {
205
- // @ts-ignore
206
- const [baseUrl, namespace] = [url, opts.path || '/'];
207
- // console.log({ url, baseUrl, namespace });
208
- const namespaceName = namespace || '/';
209
-
210
- // Look up the server instance from the registry
211
- const server = MockServer.from(url);
212
-
213
- const ns = server.of(namespaceName);
214
- ns.connect(this);
215
- }
216
- //#endregion
217
-
218
- //#region nsp + name
219
- get nsp() {
220
- const self = this;
221
- return {
222
- get name() {
223
- return self.namespaceInstance?.name;
224
- },
225
- };
226
- }
227
- //#endregion
228
-
229
- //#region path
230
- path() {
231
- return this.namespaceInstance?.name;
232
- }
233
- //#endregion
234
-
235
- //#region on
236
- on(eventName: string, handler: RealtimeModels__NS__EventHandler): void {
237
- if (!this.socketEventHandlers[eventName]) {
238
- this.socketEventHandlers[eventName] =
239
- new Set<RealtimeModels__NS__EventHandler>();
240
- }
241
- this.socketEventHandlers[eventName].add(handler);
242
-
243
- // QUICK_FIX client initing itself
244
- if (eventName === 'connect') {
245
- setTimeout(() => {
246
- this.emit('connect');
247
- // this.namespaceInstance.emit('connection', this); @UNCOMMNENT
248
- });
249
- }
250
- }
251
- //#endregion
252
-
253
- //#region emit
254
- emit(eventName: string, ...args: any[]): void {
255
- eventName = eventName || '';
256
-
257
- if (eventName.includes(`:${Symbols__NS__REALTIME.KEYroomSubscribe}`)) {
258
- const room = args[0];
259
- this.join(room);
260
- } else if (eventName.includes(`:${Symbols__NS__REALTIME.KEYroomUnsubscribe}`)) {
261
- const room = args[0];
262
- this.leave(room);
263
- } else {
264
- // console.log('try to emit event (to server)', event);
265
- if (this.namespaceInstance) {
266
- const namespaceEventHandlers =
267
- this.namespaceInstance.namespaceEventHandlers[eventName] || [];
268
-
269
- // emit to namespace events
270
- for (const namespaceEventHandler of namespaceEventHandlers) {
271
- if (namespaceEventHandler) {
272
- namespaceEventHandler(...args);
273
- }
274
- }
275
-
276
- const allSocketsForNamespaceExceptCurrent = Array.from(
277
- this.namespaceInstance.allSocketsForNamespace.values(),
278
- ).filter(socket => socket !== this);
279
-
280
- // emit to all sockets in namespace
281
- for (const socket of allSocketsForNamespaceExceptCurrent) {
282
- const socketEventHandlers = socket.socketEventHandlers[eventName];
283
- for (const socketEventHandler of socketEventHandlers) {
284
- if (socketEventHandler) {
285
- socketEventHandler(...args);
286
- }
287
- }
288
- }
289
-
290
- // Emit to current socket
291
- const socketEventHandlers = this.socketEventHandlers[eventName] || [];
292
- for (const clientHandler of socketEventHandlers) {
293
- if (clientHandler) {
294
- clientHandler(...args);
295
- }
296
- }
297
- }
298
- }
299
- }
300
- //#endregion
301
-
302
- //#region join room
303
- join(roomName: string): void {
304
- this.namespaceInstance.joinRoom(roomName, this);
305
- }
306
- //#endregion
307
-
308
- //#region leave room
309
- leave(roomName: string): void {
310
- this.namespaceInstance.leaveRoom(roomName, this);
311
- }
312
- //#endregion
313
- }
314
- //#endregion
315
-
316
- /**
317
- * Purpose:
318
- * - browser-browser communication mock (in websql mode)
319
- */
320
- export class RealtimeStrategyMock extends RealtimeStrategy {
321
- //#region toString
322
- toString(): string {
323
- return 'mock';
324
- }
325
- //#endregion
326
-
327
- //#region constructor
328
- constructor(protected ctx: EndpointContext) {
329
- super(ctx);
330
- }
331
- //#endregion
332
-
333
- //#region server & io
334
- ioServer(url: string, opt: ServerOptions) {
335
- const server = MockServer.from(url || this.ctx.uriOrigin);
336
- return server.of(opt?.path || '/') as any;
337
- }
338
-
339
- get ioClient() {
340
- const clientIo = (
341
- uri: string,
342
- opts?: Partial<ManagerOptions & SocketOptions>,
343
- ): MockSocket => {
344
- return new MockSocket(uri || this.ctx.uriOrigin, opts as any);
345
- };
346
- return clientIo as any;
347
- }
348
- //#endregion
349
- }
@@ -1,30 +0,0 @@
1
- import { EndpointContext } from '../../endpoint-context';
2
- import { RealtimeStrategy } from './realtime-strategy';
3
- //#region @backend
4
- import { Server, ServerOptions } from 'socket.io';
5
- //#endregion
6
- import { io, ManagerOptions, Socket, SocketOptions } from 'socket.io-client';
7
-
8
- /**
9
- * Purpose:
10
- * - backend-browser communication
11
- * - backend-backend communication
12
- */
13
- export class RealtimeStrategySocketIO extends RealtimeStrategy {
14
- toString(): string {
15
- return 'socket-io';
16
- }
17
- constructor(protected ctx: EndpointContext) {
18
- super(ctx);
19
- }
20
-
21
- ioServer(...args) {
22
- //#region @backendFunc
23
- return new Server(...args);
24
- //#endregion
25
- }
26
-
27
- get ioClient() {
28
- return io;
29
- }
30
- }