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