taon 21.0.53 → 21.0.55

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