taon 19.0.62 → 19.0.64

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 (117) hide show
  1. package/browser/fesm2022/taon.mjs +181 -78
  2. package/browser/fesm2022/taon.mjs.map +1 -1
  3. package/browser/lib/base-classes/base-context.d.ts +6 -0
  4. package/browser/lib/base-classes/base-controller.d.ts +3 -3
  5. package/browser/lib/base-classes/base.d.ts +6 -0
  6. package/browser/lib/create-context.d.ts +12 -4
  7. package/browser/lib/endpoint-context-storage.d.ts +12 -0
  8. package/browser/lib/endpoint-context.d.ts +28 -8
  9. package/browser/lib/index.d.ts +19 -0
  10. package/browser/lib/models.d.ts +7 -8
  11. package/browser/package.json +1 -1
  12. package/lib/base-classes/base-context.d.ts +6 -0
  13. package/lib/base-classes/base-controller.d.ts +3 -3
  14. package/lib/base-classes/base-controller.js +2 -2
  15. package/lib/base-classes/base-controller.js.map +1 -1
  16. package/lib/base-classes/base.d.ts +6 -0
  17. package/lib/build-info._auto-generated_.d.ts +1 -1
  18. package/lib/build-info._auto-generated_.js +1 -1
  19. package/lib/context-db-migrations.js +5 -5
  20. package/lib/context-db-migrations.js.map +1 -1
  21. package/lib/create-context.d.ts +12 -4
  22. package/lib/create-context.js +35 -5
  23. package/lib/create-context.js.map +1 -1
  24. package/lib/decorators/classes/controller-config.d.ts +11 -0
  25. package/lib/decorators/classes/controller-config.js +10 -0
  26. package/lib/decorators/classes/controller-config.js.map +1 -1
  27. package/lib/decorators/classes/controller-options.d.ts +5 -0
  28. package/lib/decorators/classes/controller-options.js +4 -0
  29. package/lib/decorators/classes/controller-options.js.map +1 -1
  30. package/lib/endpoint-context-storage.d.ts +11 -0
  31. package/lib/endpoint-context-storage.js +38 -0
  32. package/lib/endpoint-context-storage.js.map +1 -0
  33. package/lib/endpoint-context.d.ts +28 -8
  34. package/lib/endpoint-context.js +96 -55
  35. package/lib/endpoint-context.js.map +1 -1
  36. package/lib/index.d.ts +19 -0
  37. package/lib/index.js +3 -1
  38. package/lib/index.js.map +1 -1
  39. package/lib/models.d.ts +7 -8
  40. package/lib/models.js.map +1 -1
  41. package/lib/realtime/realtime-client.js +12 -11
  42. package/lib/realtime/realtime-client.js.map +1 -1
  43. package/lib/realtime/realtime-core.js +6 -3
  44. package/lib/realtime/realtime-core.js.map +1 -1
  45. package/lib/realtime/realtime-server.js +6 -5
  46. package/lib/realtime/realtime-server.js.map +1 -1
  47. package/lib/ui/index.js +2 -2
  48. package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
  49. package/package.json +1 -1
  50. package/websql/fesm2022/taon.mjs +188 -85
  51. package/websql/fesm2022/taon.mjs.map +1 -1
  52. package/websql/lib/base-classes/base-context.d.ts +6 -0
  53. package/websql/lib/base-classes/base-controller.d.ts +3 -3
  54. package/websql/lib/base-classes/base.d.ts +6 -0
  55. package/websql/lib/create-context.d.ts +12 -4
  56. package/websql/lib/endpoint-context-storage.d.ts +12 -0
  57. package/websql/lib/endpoint-context.d.ts +28 -8
  58. package/websql/lib/index.d.ts +19 -0
  59. package/websql/lib/models.d.ts +7 -8
  60. package/websql/package.json +1 -1
  61. package/lib/env.d.ts +0 -2
  62. package/lib/env.js +0 -7
  63. package/lib/env.js.map +0 -1
  64. package/lib/storage.d.ts +0 -1
  65. package/lib/storage.js +0 -6
  66. package/lib/storage.js.map +0 -1
  67. package/lib/ui/directives/index.d.ts +0 -3
  68. package/lib/ui/directives/index.js +0 -5
  69. package/lib/ui/directives/index.js.map +0 -1
  70. package/lib/ui/directives/safe.pipe.d.ts +0 -7
  71. package/lib/ui/directives/taon-inject-html.directive.d.ts +0 -6
  72. package/lib/ui/directives/taon-long-press.directive.d.ts +0 -22
  73. package/lib/ui/directives/view-mode.d.ts +0 -5
  74. package/lib/ui/directives/view-mode.js +0 -10
  75. package/lib/ui/directives/view-mode.js.map +0 -1
  76. package/lib/ui/taon-admin-mode-configuration/taon-admin-mode-configuration.component.d.ts +0 -43
  77. package/lib/ui/taon-admin-mode-configuration/taon-admin.models.d.ts +0 -5
  78. package/lib/ui/taon-admin-mode-configuration/taon-admin.models.js +0 -3
  79. package/lib/ui/taon-admin-mode-configuration/taon-admin.models.js.map +0 -1
  80. package/lib/ui/taon-full-material.module.d.ts +0 -5
  81. package/lib/ui/taon-github-fork-me-corner/index.d.ts +0 -2
  82. package/lib/ui/taon-github-fork-me-corner/index.js +0 -5
  83. package/lib/ui/taon-github-fork-me-corner/index.js.map +0 -1
  84. package/lib/ui/taon-github-fork-me-corner/taon-github-fork-me-corner.component.d.ts +0 -3
  85. package/lib/ui/taon-github-fork-me-corner/taon-github-fork-me-corner.module.d.ts +0 -2
  86. package/lib/ui/taon-github-fork-me-ribbon/index.d.ts +0 -2
  87. package/lib/ui/taon-github-fork-me-ribbon/index.js +0 -5
  88. package/lib/ui/taon-github-fork-me-ribbon/index.js.map +0 -1
  89. package/lib/ui/taon-github-fork-me-ribbon/taon-github-fork-me-ribbon.component.d.ts +0 -3
  90. package/lib/ui/taon-github-fork-me-ribbon/taon-github-fork-me-ribbon.module.d.ts +0 -2
  91. package/lib/ui/taon-notifications/index.d.ts +0 -4
  92. package/lib/ui/taon-notifications/index.js +0 -24
  93. package/lib/ui/taon-notifications/index.js.map +0 -1
  94. package/lib/ui/taon-notifications/taon-notifications.component.d.ts +0 -9
  95. package/lib/ui/taon-notifications/taon-notifications.models.d.ts +0 -6
  96. package/lib/ui/taon-notifications/taon-notifications.models.js +0 -5
  97. package/lib/ui/taon-notifications/taon-notifications.models.js.map +0 -1
  98. package/lib/ui/taon-notifications/taon-notifications.module.d.ts +0 -2
  99. package/lib/ui/taon-notifications/taon-notifications.service.d.ts +0 -11
  100. package/lib/ui/taon-progress-bar/index.d.ts +0 -2
  101. package/lib/ui/taon-progress-bar/index.js +0 -5
  102. package/lib/ui/taon-progress-bar/index.js.map +0 -1
  103. package/lib/ui/taon-progress-bar/taon-progress-bar.component.d.ts +0 -13
  104. package/lib/ui/taon-progress-bar/taon-progress-bar.module.d.ts +0 -2
  105. package/lib/ui/taon-session-passcode/index.d.ts +0 -1
  106. package/lib/ui/taon-session-passcode/index.js +0 -5
  107. package/lib/ui/taon-session-passcode/index.js.map +0 -1
  108. package/lib/ui/taon-session-passcode/taon-session-passcode.component.d.ts +0 -35
  109. package/lib/ui/taon-table/index.d.ts +0 -2
  110. package/lib/ui/taon-table/index.js +0 -5
  111. package/lib/ui/taon-table/index.js.map +0 -1
  112. package/lib/ui/taon-table/taon-table.component.d.ts +0 -34
  113. package/lib/ui/taon-table/taon-table.module.d.ts +0 -2
  114. package/lib/ui/taon.models.d.ts +0 -11
  115. package/lib/ui/taon.models.js +0 -3
  116. package/lib/ui/taon.models.js.map +0 -1
  117. package/tmp-environment.json +0 -39
@@ -4,8 +4,18 @@ exports.ControllerConfig = void 0;
4
4
  const controller_options_1 = require("./controller-options");
5
5
  class ControllerConfig extends controller_options_1.TaonControllerOptions {
6
6
  methods = {};
7
+ /**
8
+ * Calculated path from parents controllers
9
+ */
7
10
  calculatedPath;
11
+ /**
12
+ * a way to transform entity before sending to browser
13
+ */
8
14
  browserTransformFn;
15
+ /**
16
+ * Calculated middlewares object from parents controllers
17
+ */
18
+ calculatedMiddlewaresControllerObj;
9
19
  }
10
20
  exports.ControllerConfig = ControllerConfig;
11
21
  //# sourceMappingURL=controller-config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"controller-config.js","sourceRoot":"","sources":[""],"names":[],"mappings":";;;AAEA,6DAA6D;AAC7D,MAAa,gBAAiB,SAAQ,0CAAqB;IACzD,OAAO,GAAkD,EAAE,CAAC;IAC5D,cAAc,CAAU;IACxB,kBAAkB,CAAwB;CAC3C;AAJD,4CAIC"}
1
+ {"version":3,"file":"controller-config.js","sourceRoot":"","sources":[""],"names":[],"mappings":";;;AAIA,6DAA6D;AAE7D,MAAa,gBAAiB,SAAQ,0CAAqB;IACzD,OAAO,GAAkD,EAAE,CAAC;IAC5D;;OAEG;IACH,cAAc,CAAU;IACxB;;OAEG;IACH,kBAAkB,CAAwB;IAC1C;;OAEG;IACH,kCAAkC,CAAgC;CACnE;AAdD,4CAcC"}
@@ -1,4 +1,5 @@
1
1
  import { DecoratorAbstractOpt } from '../decorator-abstract-opt';
2
+ import type { TaonMiddlewareFunction } from '../http/http-methods-decorators';
2
3
  export declare class TaonControllerOptions<ControllerClass = any> extends DecoratorAbstractOpt {
3
4
  /**
4
5
  * typeorm realtime subscribtion // TODO disabled for now, does not make sense ?s
@@ -8,4 +9,8 @@ export declare class TaonControllerOptions<ControllerClass = any> extends Decora
8
9
  * override default path for controller api
9
10
  */
10
11
  path?: string;
12
+ /**
13
+ * Middlewares to be applied to all methods in the controller
14
+ */
15
+ middlewares?: TaonMiddlewareFunction;
11
16
  }
@@ -11,6 +11,10 @@ class TaonControllerOptions extends decorator_abstract_opt_1.DecoratorAbstractOp
11
11
  * override default path for controller api
12
12
  */
13
13
  path;
14
+ /**
15
+ * Middlewares to be applied to all methods in the controller
16
+ */
17
+ middlewares;
14
18
  }
15
19
  exports.TaonControllerOptions = TaonControllerOptions;
16
20
  //# sourceMappingURL=controller-options.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"controller-options.js","sourceRoot":"","sources":[""],"names":[],"mappings":";;;AAAA,sEAAiE;AAEjE,MAAa,qBAEX,SAAQ,6CAAoB;IAC5B;;OAEG;IACH,QAAQ,CAAW;IACnB;;OAEG;IACH,IAAI,CAAU;CACf;AAXD,sDAWC"}
1
+ {"version":3,"file":"controller-options.js","sourceRoot":"","sources":[""],"names":[],"mappings":";;;AAAA,sEAAiE;AAGjE,MAAa,qBAEX,SAAQ,6CAAoB;IAC5B;;OAEG;IACH,QAAQ,CAAW;IACnB;;OAEG;IACH,IAAI,CAAU;IACd;;OAEG;IACH,WAAW,CAA0B;CACtC;AAfD,sDAeC"}
@@ -0,0 +1,11 @@
1
+ import type { EndpointContext } from './endpoint-context';
2
+ export declare class ContextsEndpointStorage {
3
+ SPECIAL_APP_READY_MESSAGE: string;
4
+ private taonEndpointContexts;
5
+ private static instance;
6
+ private constructor();
7
+ static get Instance(): ContextsEndpointStorage;
8
+ set(context: EndpointContext): void;
9
+ get arr(): EndpointContext[];
10
+ getBy(context: Partial<EndpointContext> | string): EndpointContext | undefined;
11
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContextsEndpointStorage = void 0;
4
+ const lib_1 = require("tnp-core/lib");
5
+ class ContextsEndpointStorage {
6
+ SPECIAL_APP_READY_MESSAGE = lib_1.CoreModels.SPECIAL_APP_READY_MESSAGE;
7
+ taonEndpointContexts = new Map();
8
+ //#region singleton
9
+ static instance;
10
+ constructor() {
11
+ // Private constructor to prevent direct instantiation
12
+ }
13
+ static get Instance() {
14
+ if (!ContextsEndpointStorage.instance) {
15
+ ContextsEndpointStorage.instance = new ContextsEndpointStorage();
16
+ }
17
+ return ContextsEndpointStorage.instance;
18
+ }
19
+ //#endregion
20
+ set(context) {
21
+ if (!this.taonEndpointContexts.has(context.contextName)) {
22
+ this.taonEndpointContexts.set(context.contextName, context);
23
+ }
24
+ }
25
+ get arr() {
26
+ return Array.from(this.taonEndpointContexts.values()).filter(f => f.contextType === 'normal');
27
+ }
28
+ getBy(context) {
29
+ if (typeof context === 'string') {
30
+ return this.taonEndpointContexts.get(context);
31
+ }
32
+ return this.taonEndpointContexts.get(context.contextName);
33
+ }
34
+ }
35
+ exports.ContextsEndpointStorage = ContextsEndpointStorage;
36
+ // TODO QUICK_FIX @LAST encapsulate this => move to separate package
37
+ globalThis['$$$ContextsEndpointStorage$$$'] = ContextsEndpointStorage.Instance;
38
+ //# sourceMappingURL=endpoint-context-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint-context-storage.js","sourceRoot":"","sources":[""],"names":[],"mappings":";;;AAAA,sCAA0C;AAI1C,MAAa,uBAAuB;IAClC,yBAAyB,GAAG,gBAAU,CAAC,yBAAyB,CAAC;IACzD,oBAAoB,GAAG,IAAI,GAAG,EAA2B,CAAC;IAElE,mBAAmB;IACX,MAAM,CAAC,QAAQ,CAA0B;IAEjD;QACE,sDAAsD;IACxD,CAAC;IAEM,MAAM,KAAK,QAAQ;QACxB,IAAI,CAAC,uBAAuB,CAAC,QAAQ,EAAE,CAAC;YACtC,uBAAuB,CAAC,QAAQ,GAAG,IAAI,uBAAuB,EAAE,CAAC;QACnE,CAAC;QACD,OAAO,uBAAuB,CAAC,QAAQ,CAAC;IAC1C,CAAC;IACD,YAAY;IAEZ,GAAG,CAAC,OAAwB;QAC1B,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;YACxD,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IAED,IAAI,GAAG;QACL,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAC1D,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,KAAK,QAAQ,CAChC,CAAC;IACJ,CAAC;IAED,KAAK,CACH,OAA0C;QAE1C,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,OAAO,CAAQ,CAAC;QACvD,CAAC;QACD,OAAO,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAQ,CAAC;IACnE,CAAC;CACF;AAvCD,0DAuCC;AAED,oEAAoE;AACpE,UAAU,CAAC,+BAA+B,CAAC,GAAG,uBAAuB,CAAC,QAAQ,CAAC"}
@@ -6,10 +6,18 @@ import type { Repository } from 'taon-typeorm';
6
6
  import { DataSource } from 'taon-typeorm';
7
7
  import type { BaseInjector } from './base-classes/base-injector';
8
8
  import { ContextDbMigrations } from './context-db-migrations';
9
+ import type { ContextsEndpointStorage } from './endpoint-context-storage';
9
10
  import { Models } from './models';
10
11
  export declare class EndpointContext {
11
12
  private originalConfig;
12
13
  private configFn;
14
+ /**
15
+ * (@default: false)
16
+ * If TRUE context is NOT going to create db/express server/http endpoints
17
+ * PURPOSE OF THIS PROPERTY
18
+ * -> ONLY remote access from backend or frontend to specific backend
19
+ */
20
+ private readonly cloneOptions;
13
21
  /**
14
22
  * JUST FOR TESTING PURPOSES
15
23
  */
@@ -36,6 +44,7 @@ export declare class EndpointContext {
36
44
  method: Models.Http.Rest.HttpMethod;
37
45
  }[];
38
46
  repos: Map<string, Repository<any>>;
47
+ get sourceContext(): EndpointContext | undefined;
39
48
  readonly skipWritingServerRoutes: boolean;
40
49
  private injectableTypesfromContexts;
41
50
  private allTypesfromContexts;
@@ -65,11 +74,16 @@ export declare class EndpointContext {
65
74
  * Inside docker there is not need for https secure server
66
75
  */
67
76
  readonly isRunningInsideDocker: boolean;
68
- constructor(originalConfig: Models.ContextOptions<any, any, any, any, any, any, any, any>, configFn: (env: any) => Models.ContextOptions<any, any, any, any, any, any, any, any>);
77
+ constructor(originalConfig: Models.ContextOptions<any, any, any, any, any, any, any, any>, configFn: (env: any) => Models.ContextOptions<any, any, any, any, any, any, any, any>,
78
+ /**
79
+ * (@default: false)
80
+ * If TRUE context is NOT going to create db/express server/http endpoints
81
+ * PURPOSE OF THIS PROPERTY
82
+ * -> ONLY remote access from backend or frontend to specific backend
83
+ */
84
+ cloneOptions: Models.TaonCtxCloneParams);
69
85
  init(options?: {
70
86
  initFromRecrusiveContextResovle?: boolean;
71
- overrideHost?: string | null;
72
- overrideRemoteHost?: string | null;
73
87
  onlyMigrationRun?: boolean;
74
88
  onlyMigrationRevertToTimestamp?: number;
75
89
  }): Promise<void>;
@@ -108,7 +122,7 @@ export declare class EndpointContext {
108
122
  initClasses(): Promise<void>;
109
123
  isActiveOn(classInstance: object): boolean;
110
124
  get frontendHostUri(): URL;
111
- get uri(): URL;
125
+ get uri(): URL | undefined;
112
126
  get uriProtocol(): string | undefined;
113
127
  /**
114
128
  * Examples
@@ -136,10 +150,19 @@ export declare class EndpointContext {
136
150
  */
137
151
  get port(): Number | undefined;
138
152
  get isHttpServer(): boolean;
153
+ get isRemoteHost(): boolean;
139
154
  /**
140
155
  * ipc/udp needs this
141
156
  */
142
157
  get contextName(): string;
158
+ /**
159
+ * ipc/udp needs this
160
+ */
161
+ get contextNameForCommunication(): string;
162
+ /**
163
+ * Check context type
164
+ */
165
+ get contextType(): 'normal' | 'remote' | 'abstract' | 'invalid';
143
166
  get cwd(): string;
144
167
  get activeContext(): string | null;
145
168
  get appId(): string;
@@ -148,7 +171,6 @@ export declare class EndpointContext {
148
171
  locationOnDisk: string;
149
172
  }[];
150
173
  get isProductionMode(): boolean;
151
- get remoteHost(): string;
152
174
  get host(): string;
153
175
  get orgin(): string;
154
176
  initSubscribers(): Promise<void>;
@@ -157,9 +179,7 @@ export declare class EndpointContext {
157
179
  initDatabaseConnection(): Promise<void>;
158
180
  private updateCalculatedPathsForControllers;
159
181
  private mergeControllerMethodsConfigs;
160
- initControllersHook(allInitedEndpointContexts: {
161
- [contextName: string]: EndpointContext;
162
- }): Promise<void>;
182
+ initControllersHook(ctxStorage: ContextsEndpointStorage): Promise<void>;
163
183
  initControllers(): Promise<void>;
164
184
  writeActiveRoutes(): void;
165
185
  get middlewares(): Models.MiddlewareType[];
@@ -41,6 +41,7 @@ const symbols_1 = require("./symbols");
41
41
  class EndpointContext {
42
42
  originalConfig;
43
43
  configFn;
44
+ cloneOptions;
44
45
  //#region static
45
46
  /**
46
47
  * JUST FOR TESTING PURPOSES
@@ -94,6 +95,11 @@ class EndpointContext {
94
95
  repos = new Map();
95
96
  //#endregion
96
97
  //#endregion
98
+ //#region fields / source context
99
+ get sourceContext() {
100
+ return this.cloneOptions?.sourceContext;
101
+ }
102
+ //#endregion
97
103
  skipWritingServerRoutes = false;
98
104
  //#region fields / types from contexts
99
105
  injectableTypesfromContexts = [
@@ -191,15 +197,24 @@ class EndpointContext {
191
197
  * Inside docker there is not need for https secure server
192
198
  */
193
199
  isRunningInsideDocker = false;
194
- constructor(originalConfig, configFn) {
200
+ constructor(originalConfig, configFn,
201
+ /**
202
+ * (@default: false)
203
+ * If TRUE context is NOT going to create db/express server/http endpoints
204
+ * PURPOSE OF THIS PROPERTY
205
+ * -> ONLY remote access from backend or frontend to specific backend
206
+ */
207
+ cloneOptions) {
195
208
  this.originalConfig = originalConfig;
196
209
  this.configFn = configFn;
210
+ this.cloneOptions = cloneOptions;
211
+ this.cloneOptions = this.cloneOptions || {};
197
212
  this.isRunningInsideDocker = lib_9.UtilsOs.isRunningInDocker();
198
213
  }
199
214
  //#endregion
200
215
  //#region methods & getters / init
201
216
  async init(options) {
202
- const { initFromRecrusiveContextResovle, overrideHost, overrideRemoteHost, onlyMigrationRun, onlyMigrationRevertToTimestamp, } = options || {}; // TODO use it ?
217
+ const { initFromRecrusiveContextResovle, onlyMigrationRun, onlyMigrationRevertToTimestamp, } = options || {}; // TODO use it ?
203
218
  this.inited = true;
204
219
  // @ts-ignore
205
220
  this.onlyMigrationRun = onlyMigrationRun;
@@ -209,31 +224,23 @@ class EndpointContext {
209
224
  if (lib_11._.isObject(this.config.database)) {
210
225
  this.config.database = models_1.Models.DatabaseConfig.from(this.config.database).databaseConfigTypeORM;
211
226
  }
212
- if (overrideHost && overrideRemoteHost) {
213
- lib_11.Helpers.throw(`[taon-config] You can't have overrideHost and overrideRemoteHost at the same time`);
214
- }
215
- this.config.host = !lib_11._.isUndefined(overrideHost)
216
- ? overrideHost
217
- : this.config.host;
218
- this.config.remoteHost = !lib_11._.isUndefined(overrideRemoteHost)
219
- ? overrideRemoteHost
220
- : this.config.remoteHost;
221
227
  this.config.host = this.host === null ? void 0 : this.host;
222
- this.config.remoteHost =
223
- this.remoteHost === null ? void 0 : this.remoteHost;
228
+ if (this.cloneOptions.overrideHost &&
229
+ !this.cloneOptions.useAsRemoteContext) {
230
+ this.config.host = this.cloneOptions.overrideHost;
231
+ }
232
+ if (this.cloneOptions.overrideRemoteHost &&
233
+ this.cloneOptions.useAsRemoteContext) {
234
+ this.config.host = this.cloneOptions.overrideRemoteHost;
235
+ }
224
236
  if (this.config.host &&
225
237
  !this.config.host.startsWith('http://') &&
226
238
  !this.config.host.startsWith('https://')) {
227
- lib_11.Helpers.throw(`[taon-config] Your 'host' must start with http:// or https://`);
239
+ lib_11.Helpers.throw(`[taon-config] Your${this.host ? ' remote' : ''} 'host' must start with http:// or https://`);
228
240
  }
229
241
  if (lib_11._.isUndefined(this.config.useIpcWhenElectron)) {
230
242
  this.config.useIpcWhenElectron = true;
231
243
  }
232
- if (this.config.remoteHost &&
233
- !this.config.remoteHost.startsWith('http://') &&
234
- !this.config.remoteHost.startsWith('https://')) {
235
- lib_11.Helpers.throw(`[taon-config] Your 'remoteHost' must start with http:// or https://`);
236
- }
237
244
  // console.log(`config for ${this.contextName}`, this.config);
238
245
  //#region resolve if skipping writing server routes
239
246
  //@ts-expect-error overriding readonly
@@ -247,10 +254,7 @@ class EndpointContext {
247
254
  /* */
248
255
  /* */
249
256
  }
250
- if (this.config.remoteHost) {
251
- if (this.config.host) {
252
- lib_11.Helpers.throw(`[taon] You can't have remoteHost and host at the same time`);
253
- }
257
+ if (this.isRemoteHost) {
254
258
  this.mode = 'remote-backend(tcp+udp)';
255
259
  }
256
260
  // console.log(`
@@ -271,9 +275,9 @@ class EndpointContext {
271
275
  // console.log(this.config)
272
276
  // }
273
277
  if (!this.mode && !this.config.abstract) {
274
- const errMsg = `You need to provide host or remoteHost or ` +
275
- `useIpcWhenElectron (or mark it as abstract)`;
276
- lib_11.Helpers.error(`[taon] Context "${this.contextName}": ${errMsg}`, false, true);
278
+ const errMsg = `You need to provide host property or ` +
279
+ `useIpcWhenElectron or mark it as abstract`;
280
+ lib_11.Helpers.error(`[taon][Context=${this.contextName}]: ${errMsg}`, false, true);
277
281
  //#region @backend
278
282
  process.exit(1);
279
283
  //#endregion
@@ -322,7 +326,7 @@ class EndpointContext {
322
326
  axios_1.default.defaults.withCredentials = true;
323
327
  }
324
328
  //#endregion
325
- //#region prepare & gather all classes recrusively
329
+ //#region prepare & gather all classes recursively
326
330
  this.config.contexts = this.config.contexts || {};
327
331
  this.config.entities = this.config.entities || {};
328
332
  this.config.controllers = this.config.controllers || {};
@@ -450,6 +454,8 @@ class EndpointContext {
450
454
  // Helpers.logInfo(`Realtime enabled on backend`);
451
455
  // }
452
456
  //#endregion
457
+ this.logRealtime &&
458
+ lib_11.Helpers.info(`[ctx=${this.contextName}] Init Realtime for ${this.mode}`);
453
459
  this.realtime = new realtime_core_1.RealtimeCore(this);
454
460
  }
455
461
  //#endregion
@@ -461,9 +467,9 @@ class EndpointContext {
461
467
  lib_11.Helpers.info(`[taon] Create abstract context: ${this.config.contextName}`);
462
468
  }
463
469
  else {
464
- if (this.config.remoteHost) {
470
+ if (this.isRemoteHost) {
465
471
  this.logFramework &&
466
- lib_11.Helpers.info(`[taon] Create context for remote host: ${this.config.remoteHost}`);
472
+ lib_11.Helpers.info(`[taon] Create context for remote host: ${this.config.host}`);
467
473
  }
468
474
  else {
469
475
  this.logFramework &&
@@ -614,7 +620,7 @@ class EndpointContext {
614
620
  //#region methods & getters / start server
615
621
  async startServer() {
616
622
  //#region @backendFunc
617
- if (this.remoteHost || this.isRunOrRevertOnlyMigrationAppStart) {
623
+ if (this.isRemoteHost || this.isRunOrRevertOnlyMigrationAppStart) {
618
624
  return;
619
625
  }
620
626
  if (this.mode === 'backend-frontend(tcp+udp)') {
@@ -622,8 +628,10 @@ class EndpointContext {
622
628
  if (this.isRunningInsideDocker) {
623
629
  // this.displayRoutes(this.expressApp);
624
630
  this.serverTcpUdp.listen(Number(this.uriPort), '0.0.0.0', () => {
625
- lib_11.Helpers.log(`Express server (inside docker) started 0.0.0.0:${this.uriPort}`);
626
- lib_11.Helpers.log(`[taon][express-server]listening on port: ${this.uriPort}, hostname: ${this.uriPathname},
631
+ this.logFramework &&
632
+ lib_11.Helpers.log(`[ctx=${this.contextName}] Express server (inside docker) started 0.0.0.0:${this.uriPort}`);
633
+ this.logFramework &&
634
+ lib_11.Helpers.log(`[taon][express-server]listening on port: ${this.uriPort}, hostname: ${this.uriPathname},
627
635
  address: ${this.uriProtocol}//localhost:${this.uriPort}${this.uriPathname}
628
636
  ExpressJS mode: ${this.expressApp.settings.env}
629
637
  `);
@@ -633,8 +641,10 @@ class EndpointContext {
633
641
  else {
634
642
  // this.displayRoutes(this.expressApp);
635
643
  this.serverTcpUdp.listen(Number(this.uriPort), () => {
636
- lib_11.Helpers.log(`Express server (inside nodejs app) started on localhost:${this.uriPort}`);
637
- lib_11.Helpers.log(`[taon][express-server]listening on port: ${this.uriPort}, hostname: ${this.uriPathname},
644
+ this.logFramework &&
645
+ lib_11.Helpers.log(`[ctx=${this.contextName}] Express server (inside nodejs app) started on localhost:${this.uriPort}`);
646
+ this.logFramework &&
647
+ lib_11.Helpers.log(`[taon][express-server]listening on port: ${this.uriPort}, hostname: ${this.uriPathname},
638
648
  address: ${this.uriProtocol}//localhost:${this.uriPort}${this.uriPathname}
639
649
  expressJS mode: ${this.expressApp.settings.env}
640
650
  `);
@@ -974,7 +984,7 @@ class EndpointContext {
974
984
  //#endregion
975
985
  //#region methods & getters / init classes
976
986
  async initClasses() {
977
- if (this.remoteHost) {
987
+ if (this.isRemoteHost) {
978
988
  return;
979
989
  }
980
990
  //#region @websql
@@ -1037,11 +1047,7 @@ class EndpointContext {
1037
1047
  return uri;
1038
1048
  }
1039
1049
  get uri() {
1040
- const url = this.host
1041
- ? new url_1.URL(this.host)
1042
- : this.remoteHost
1043
- ? new url_1.URL(this.remoteHost)
1044
- : void 0;
1050
+ const url = this.host ? new url_1.URL(this.host) : void 0;
1045
1051
  return url;
1046
1052
  }
1047
1053
  //#endregion
@@ -1109,11 +1115,50 @@ class EndpointContext {
1109
1115
  }
1110
1116
  //#endregion
1111
1117
  //#region methods & getters / public assets
1118
+ get isRemoteHost() {
1119
+ return !!this.cloneOptions?.useAsRemoteContext;
1120
+ }
1121
+ //#endregion
1122
+ //#region methods & getters / public assets
1112
1123
  /**
1113
1124
  * ipc/udp needs this
1114
1125
  */
1115
1126
  get contextName() {
1116
- return this.config.contextName;
1127
+ // console.log(this.originalConfig);
1128
+ return this.config?.contextName || this.originalConfig?.contextName;
1129
+ }
1130
+ //#endregion
1131
+ //#region methods & getters / public assets
1132
+ /**
1133
+ * ipc/udp needs this
1134
+ */
1135
+ get contextNameForCommunication() {
1136
+ let contextName = this.contextName;
1137
+ if (this.isRemoteHost) {
1138
+ if (this.sourceContext?.contextName) {
1139
+ contextName = this.sourceContext?.contextName;
1140
+ }
1141
+ else {
1142
+ // console.log(
1143
+ // `CANT GET SOURCE CONTEXT NAME FOR REMOTE CONTEXT ${this.contextName}`,
1144
+ // );
1145
+ }
1146
+ }
1147
+ return contextName;
1148
+ }
1149
+ //#endregion
1150
+ //#region methods & getters / public assets
1151
+ /**
1152
+ * Check context type
1153
+ */
1154
+ get contextType() {
1155
+ if (this.config.abstract) {
1156
+ return 'abstract';
1157
+ }
1158
+ if (this.host) {
1159
+ return this.isRemoteHost ? 'remote' : 'normal';
1160
+ }
1161
+ return 'invalid';
1117
1162
  }
1118
1163
  //#endregion
1119
1164
  //#region methods & getters / current working directory
@@ -1141,11 +1186,6 @@ class EndpointContext {
1141
1186
  return this.config.productionMode;
1142
1187
  }
1143
1188
  //#endregion
1144
- //#region methods & getters / remote host
1145
- get remoteHost() {
1146
- return this.config.remoteHost;
1147
- }
1148
- //#endregion
1149
1189
  //#region methods & getters / host
1150
1190
  get host() {
1151
1191
  return this.config.host;
@@ -1159,7 +1199,7 @@ class EndpointContext {
1159
1199
  //#region methods & getters / init subscribers
1160
1200
  async initSubscribers() {
1161
1201
  //#region @websqlFunc
1162
- if (this.remoteHost) {
1202
+ if (this.isRemoteHost) {
1163
1203
  return;
1164
1204
  }
1165
1205
  const subscriberClasses = this.getClassFunByArr(models_1.Models.ClassType.SUBSCRIBER);
@@ -1175,7 +1215,7 @@ class EndpointContext {
1175
1215
  //#region methods & getters / init entities
1176
1216
  async initEntities() {
1177
1217
  //#region @websql
1178
- if (this.remoteHost) {
1218
+ if (this.isRemoteHost) {
1179
1219
  return;
1180
1220
  }
1181
1221
  const entities = this.getClassFunByArr(models_1.Models.ClassType.ENTITY);
@@ -1221,7 +1261,7 @@ class EndpointContext {
1221
1261
  //#region methods & getters / init connection
1222
1262
  async initDatabaseConnection() {
1223
1263
  //#region @websqlFunc
1224
- if (this.remoteHost || !this.databaseConfig) {
1264
+ if (this.isRemoteHost || !this.databaseConfig) {
1225
1265
  return;
1226
1266
  }
1227
1267
  const entities = this.getClassFunByArr(models_1.Models.ClassType.ENTITY).map(entityFn => {
@@ -1328,12 +1368,13 @@ class EndpointContext {
1328
1368
  return bc.className;
1329
1369
  })
1330
1370
  .join('/');
1371
+ const contextNameForCommunication = this.contextNameForCommunication;
1331
1372
  if (taon_helpers_1.TaonHelpers.isGoodPath(classConfig.path)) {
1332
1373
  classConfig.calculatedPath = classConfig.path;
1333
1374
  }
1334
1375
  else {
1335
1376
  classConfig.calculatedPath = (`${this.uriPathnameOrNothingIfRoot}` +
1336
- `/${constants_1.apiPrefix}/${this.contextName}/tcp${parentsCalculatedPath}/` +
1377
+ `/${constants_1.apiPrefix}/${contextNameForCommunication}/tcp${parentsCalculatedPath}/` +
1337
1378
  `${class_helpers_1.ClassHelpers.getName(controllerClassFn)}`)
1338
1379
  .replace(/\/\//g, '/')
1339
1380
  .split('/')
@@ -1363,7 +1404,7 @@ class EndpointContext {
1363
1404
  });
1364
1405
  }
1365
1406
  //#endregion
1366
- async initControllersHook(allInitedEndpointContexts) {
1407
+ async initControllersHook(ctxStorage) {
1367
1408
  if (this.isRunOrRevertOnlyMigrationAppStart) {
1368
1409
  return;
1369
1410
  }
@@ -1371,7 +1412,7 @@ class EndpointContext {
1371
1412
  for (const controllerClassFn of allControllers) {
1372
1413
  const instance = this.getInstanceBy(controllerClassFn);
1373
1414
  if (lib_11._.isFunction(instance.afterAllCtxInited)) {
1374
- await instance.afterAllCtxInited(allInitedEndpointContexts);
1415
+ await instance.afterAllCtxInited({ ctxStorage });
1375
1416
  }
1376
1417
  }
1377
1418
  }
@@ -1471,7 +1512,7 @@ class EndpointContext {
1471
1512
  }
1472
1513
  //#endregion
1473
1514
  //#region init client
1474
- const shouldInitClient = lib_11.Helpers.isBrowser || this.remoteHost || lib_11.Helpers.isWebSQL;
1515
+ const shouldInitClient = lib_11.Helpers.isBrowser || this.isRemoteHost || lib_11.Helpers.isWebSQL;
1475
1516
  // console.log('shouldInitClient', shouldInitClient);
1476
1517
  if (shouldInitClient) {
1477
1518
  // console.log(
@@ -1500,7 +1541,7 @@ class EndpointContext {
1500
1541
  //#endregion
1501
1542
  //#region methods & getters / write active routes
1502
1543
  writeActiveRoutes() {
1503
- if (this.remoteHost ||
1544
+ if (this.isRemoteHost ||
1504
1545
  this.isRunOrRevertOnlyMigrationAppStart ||
1505
1546
  this.skipWritingServerRoutes) {
1506
1547
  return;
@@ -1742,7 +1783,7 @@ class EndpointContext {
1742
1783
  };
1743
1784
  //#endregion
1744
1785
  }
1745
- if (!this.remoteHost) {
1786
+ if (!this.isRemoteHost) {
1746
1787
  //#region apply dummy websql express routers
1747
1788
  //#region @websql
1748
1789
  if (lib_11.Helpers.isWebSQL) {