taon 19.0.62 → 19.0.63

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 (125) hide show
  1. package/README.md +160 -160
  2. package/bin/start.js +281 -281
  3. package/bin/taon +6 -6
  4. package/bin/taon-debug +5 -5
  5. package/bin/taon-debug-brk +5 -5
  6. package/browser/README.md +24 -24
  7. package/browser/fesm2022/taon.mjs +177 -77
  8. package/browser/fesm2022/taon.mjs.map +1 -1
  9. package/browser/lib/base-classes/base-context.d.ts +6 -0
  10. package/browser/lib/base-classes/base-controller.d.ts +3 -3
  11. package/browser/lib/base-classes/base.d.ts +6 -0
  12. package/browser/lib/create-context.d.ts +12 -4
  13. package/browser/lib/endpoint-context-storage.d.ts +11 -0
  14. package/browser/lib/endpoint-context.d.ts +28 -8
  15. package/browser/lib/index.d.ts +19 -0
  16. package/browser/lib/models.d.ts +7 -8
  17. package/browser/package.json +1 -1
  18. package/icon-menu-taon.svg +15 -15
  19. package/lib/base-classes/base-context.d.ts +6 -0
  20. package/lib/base-classes/base-controller.d.ts +3 -3
  21. package/lib/base-classes/base-controller.js +2 -2
  22. package/lib/base-classes/base-controller.js.map +1 -1
  23. package/lib/base-classes/base.d.ts +6 -0
  24. package/lib/build-info._auto-generated_.d.ts +1 -1
  25. package/lib/build-info._auto-generated_.js +1 -1
  26. package/lib/context-db-migrations.js +5 -5
  27. package/lib/context-db-migrations.js.map +1 -1
  28. package/lib/create-context.d.ts +12 -4
  29. package/lib/create-context.js +35 -5
  30. package/lib/create-context.js.map +1 -1
  31. package/lib/endpoint-context-storage.d.ts +10 -0
  32. package/lib/endpoint-context-storage.js +34 -0
  33. package/lib/endpoint-context-storage.js.map +1 -0
  34. package/lib/endpoint-context.d.ts +28 -8
  35. package/lib/endpoint-context.js +96 -55
  36. package/lib/endpoint-context.js.map +1 -1
  37. package/lib/index.d.ts +19 -0
  38. package/lib/index.js +3 -1
  39. package/lib/index.js.map +1 -1
  40. package/lib/models.d.ts +7 -8
  41. package/lib/models.js.map +1 -1
  42. package/lib/realtime/realtime-client.js +12 -11
  43. package/lib/realtime/realtime-client.js.map +1 -1
  44. package/lib/realtime/realtime-core.js +6 -3
  45. package/lib/realtime/realtime-core.js.map +1 -1
  46. package/lib/realtime/realtime-server.js +6 -5
  47. package/lib/realtime/realtime-server.js.map +1 -1
  48. package/lib/ui/index.js +2 -2
  49. package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
  50. package/package.json +1 -1
  51. package/websql/README.md +24 -24
  52. package/websql/fesm2022/taon.mjs +184 -84
  53. package/websql/fesm2022/taon.mjs.map +1 -1
  54. package/websql/lib/base-classes/base-context.d.ts +6 -0
  55. package/websql/lib/base-classes/base-controller.d.ts +3 -3
  56. package/websql/lib/base-classes/base.d.ts +6 -0
  57. package/websql/lib/create-context.d.ts +12 -4
  58. package/websql/lib/endpoint-context-storage.d.ts +11 -0
  59. package/websql/lib/endpoint-context.d.ts +28 -8
  60. package/websql/lib/index.d.ts +19 -0
  61. package/websql/lib/models.d.ts +7 -8
  62. package/websql/package.json +1 -1
  63. package/lib/decorators/classes/controller-config.d.ts +0 -9
  64. package/lib/decorators/classes/controller-config.js +0 -11
  65. package/lib/decorators/classes/controller-config.js.map +0 -1
  66. package/lib/decorators/classes/controller-options.d.ts +0 -11
  67. package/lib/decorators/classes/controller-options.js +0 -16
  68. package/lib/decorators/classes/controller-options.js.map +0 -1
  69. package/lib/env.d.ts +0 -2
  70. package/lib/env.js +0 -7
  71. package/lib/env.js.map +0 -1
  72. package/lib/storage.d.ts +0 -1
  73. package/lib/storage.js +0 -6
  74. package/lib/storage.js.map +0 -1
  75. package/lib/ui/directives/index.d.ts +0 -3
  76. package/lib/ui/directives/index.js +0 -5
  77. package/lib/ui/directives/index.js.map +0 -1
  78. package/lib/ui/directives/safe.pipe.d.ts +0 -7
  79. package/lib/ui/directives/taon-inject-html.directive.d.ts +0 -6
  80. package/lib/ui/directives/taon-long-press.directive.d.ts +0 -22
  81. package/lib/ui/directives/view-mode.d.ts +0 -5
  82. package/lib/ui/directives/view-mode.js +0 -10
  83. package/lib/ui/directives/view-mode.js.map +0 -1
  84. package/lib/ui/taon-admin-mode-configuration/taon-admin-mode-configuration.component.d.ts +0 -43
  85. package/lib/ui/taon-admin-mode-configuration/taon-admin.models.d.ts +0 -5
  86. package/lib/ui/taon-admin-mode-configuration/taon-admin.models.js +0 -3
  87. package/lib/ui/taon-admin-mode-configuration/taon-admin.models.js.map +0 -1
  88. package/lib/ui/taon-full-material.module.d.ts +0 -5
  89. package/lib/ui/taon-github-fork-me-corner/index.d.ts +0 -2
  90. package/lib/ui/taon-github-fork-me-corner/index.js +0 -5
  91. package/lib/ui/taon-github-fork-me-corner/index.js.map +0 -1
  92. package/lib/ui/taon-github-fork-me-corner/taon-github-fork-me-corner.component.d.ts +0 -3
  93. package/lib/ui/taon-github-fork-me-corner/taon-github-fork-me-corner.module.d.ts +0 -2
  94. package/lib/ui/taon-github-fork-me-ribbon/index.d.ts +0 -2
  95. package/lib/ui/taon-github-fork-me-ribbon/index.js +0 -5
  96. package/lib/ui/taon-github-fork-me-ribbon/index.js.map +0 -1
  97. package/lib/ui/taon-github-fork-me-ribbon/taon-github-fork-me-ribbon.component.d.ts +0 -3
  98. package/lib/ui/taon-github-fork-me-ribbon/taon-github-fork-me-ribbon.module.d.ts +0 -2
  99. package/lib/ui/taon-notifications/index.d.ts +0 -4
  100. package/lib/ui/taon-notifications/index.js +0 -24
  101. package/lib/ui/taon-notifications/index.js.map +0 -1
  102. package/lib/ui/taon-notifications/taon-notifications.component.d.ts +0 -9
  103. package/lib/ui/taon-notifications/taon-notifications.models.d.ts +0 -6
  104. package/lib/ui/taon-notifications/taon-notifications.models.js +0 -5
  105. package/lib/ui/taon-notifications/taon-notifications.models.js.map +0 -1
  106. package/lib/ui/taon-notifications/taon-notifications.module.d.ts +0 -2
  107. package/lib/ui/taon-notifications/taon-notifications.service.d.ts +0 -11
  108. package/lib/ui/taon-progress-bar/index.d.ts +0 -2
  109. package/lib/ui/taon-progress-bar/index.js +0 -5
  110. package/lib/ui/taon-progress-bar/index.js.map +0 -1
  111. package/lib/ui/taon-progress-bar/taon-progress-bar.component.d.ts +0 -13
  112. package/lib/ui/taon-progress-bar/taon-progress-bar.module.d.ts +0 -2
  113. package/lib/ui/taon-session-passcode/index.d.ts +0 -1
  114. package/lib/ui/taon-session-passcode/index.js +0 -5
  115. package/lib/ui/taon-session-passcode/index.js.map +0 -1
  116. package/lib/ui/taon-session-passcode/taon-session-passcode.component.d.ts +0 -35
  117. package/lib/ui/taon-table/index.d.ts +0 -2
  118. package/lib/ui/taon-table/index.js +0 -5
  119. package/lib/ui/taon-table/index.js.map +0 -1
  120. package/lib/ui/taon-table/taon-table.component.d.ts +0 -34
  121. package/lib/ui/taon-table/taon-table.module.d.ts +0 -2
  122. package/lib/ui/taon.models.d.ts +0 -11
  123. package/lib/ui/taon.models.js +0 -3
  124. package/lib/ui/taon.models.js.map +0 -1
  125. package/tmp-environment.json +0 -39
@@ -977,7 +977,7 @@ class ContextDbMigrations {
977
977
  //#region methods & getters / make sure migration table exists
978
978
  async ensureMigrationTableExists() {
979
979
  //#region @websqlFunc
980
- if (this.ctx.remoteHost || !this.ctx.connection) {
980
+ if (this.ctx.isRemoteHost || !this.ctx.connection) {
981
981
  return;
982
982
  }
983
983
  const queryRunner = this.ctx.connection.createQueryRunner();
@@ -1017,7 +1017,7 @@ class ContextDbMigrations {
1017
1017
  }
1018
1018
  async revertMigrationToTimestamp(timestamp) {
1019
1019
  //#region @websqlFunc
1020
- if (this.ctx.remoteHost || !this.ctx.connection) {
1020
+ if (this.ctx.isRemoteHost || !this.ctx.connection) {
1021
1021
  return;
1022
1022
  }
1023
1023
  if (!UtilsMigrations.isValidTimestamp(timestamp)) {
@@ -1085,7 +1085,7 @@ class ContextDbMigrations {
1085
1085
  //#region methods & getters / clear migration table
1086
1086
  async clearMigrationTable() {
1087
1087
  //#region @websqlFunc
1088
- if (this.ctx.remoteHost || !this.ctx.connection) {
1088
+ if (this.ctx.isRemoteHost || !this.ctx.connection) {
1089
1089
  return;
1090
1090
  }
1091
1091
  const queryRunner = this.ctx.connection.createQueryRunner();
@@ -1109,7 +1109,7 @@ class ContextDbMigrations {
1109
1109
  //#region methods & getters / mark all migrations as applied
1110
1110
  async markAllMigrationsAsApplied() {
1111
1111
  //#region @websqlFunc
1112
- if (this.ctx.remoteHost || !this.ctx.connection) {
1112
+ if (this.ctx.isRemoteHost || !this.ctx.connection) {
1113
1113
  return;
1114
1114
  }
1115
1115
  const migrationsClassFns = this.ctx.getClassFunByArr(Models.ClassType.MIGRATION);
@@ -1163,7 +1163,7 @@ class ContextDbMigrations {
1163
1163
  //#region methods & getters / run all migrations
1164
1164
  async runAllNotCompletedMigrations() {
1165
1165
  //#region @websqlFunc
1166
- if (this.ctx.remoteHost || !this.ctx.connection) {
1166
+ if (this.ctx.isRemoteHost || !this.ctx.connection) {
1167
1167
  return;
1168
1168
  }
1169
1169
  const migrationsClassFns = this.ctx.getClassFunByArr(Models.ClassType.MIGRATION);
@@ -1554,6 +1554,10 @@ class RealtimeClient {
1554
1554
  this.subsManagers = {};
1555
1555
  this.core = core;
1556
1556
  if (!core.ctx.disabledRealtime) {
1557
+ // this.core.ctx.logRealtime &&
1558
+ // Helpers.info(`
1559
+ // [ctx=${this.core.ctx.contextName}] init RealtimeClient (type: ${this.core.ctx.contextType})
1560
+ // `);
1557
1561
  this.init();
1558
1562
  }
1559
1563
  }
@@ -1568,13 +1572,15 @@ class RealtimeClient {
1568
1572
  if (this.core.ctx.config.frontendHost &&
1569
1573
  this.core.ctx.config.frontendHost !== '' &&
1570
1574
  this.core.ctx.isRunningInsideDocker) {
1571
- Helpers.logInfo(`[${this.core.ctx.contextName}] USING FRONTEND HOST` +
1572
- ` ${this.core.ctx.config.frontendHost} FOR REALTIME`);
1575
+ this.core.ctx.logRealtime &&
1576
+ Helpers.logInfo(`[${this.core.ctx.contextName}] USING FRONTEND HOST` +
1577
+ ` ${this.core.ctx.config.frontendHost} FOR REALTIME`);
1573
1578
  nspPath.global = new URL(`${this.core.ctx.frontendHostUri.origin}${nspPath.global.pathname}`);
1574
1579
  nspPath.realtime = new URL(`${this.core.ctx.frontendHostUri.origin}${nspPath.realtime.pathname}`);
1575
1580
  }
1576
1581
  else {
1577
- Helpers.logInfo(`[${this.core.ctx.contextName}] Not using frontend host for realtime`);
1582
+ this.core.ctx.logRealtime &&
1583
+ Helpers.logInfo(`[${this.core.ctx.contextName}] Not using frontend host for realtime`);
1578
1584
  }
1579
1585
  this.core.ctx.logRealtime &&
1580
1586
  console.info('[CLIENT] NAMESPACE GLOBAL ', nspPath.global.href + ` host: ${this.core.ctx.host}`);
@@ -1719,14 +1725,9 @@ to use socket realtime connection;
1719
1725
  //#endregion
1720
1726
  //#region methods & getters / get room id from
1721
1727
  getUniqueIdentifierForConnection(options) {
1722
- let url;
1723
- if (UtilsOs.isBrowser) {
1724
- url = new URL(options.core.ctx.host);
1725
- }
1726
- else {
1727
- url = new URL(options.core.ctx.remoteHost); // backend-to-backend use remote host
1728
- }
1729
- return `${this.core.ctx.contextName}:${url.origin}|${options.roomName}|${options.property}|${options.customEvent}`;
1728
+ let url = new URL(options.core.ctx.host);
1729
+ let contextNameForCommunication = options.core.ctx.contextNameForCommunication;
1730
+ return `${contextNameForCommunication}:${url.origin}|${options.roomName}|${options.property}|${options.customEvent}`;
1730
1731
  }
1731
1732
  }
1732
1733
 
@@ -1738,11 +1739,12 @@ class RealtimeServer {
1738
1739
  constructor(core) {
1739
1740
  this.core = core;
1740
1741
  this.core = core;
1741
- if (!core.ctx.disabledRealtime) {
1742
- //#region @websql
1743
- this.init();
1744
- //#endregion
1742
+ if (core.ctx.disabledRealtime || this.core.ctx.isRemoteHost) {
1743
+ return;
1745
1744
  }
1745
+ //#region @websql
1746
+ this.init();
1747
+ //#endregion
1746
1748
  }
1747
1749
  //#region methods & getters / init
1748
1750
  init() {
@@ -1848,7 +1850,7 @@ class RealtimeServer {
1848
1850
  // console.info('__triger entity changes');
1849
1851
  //#region @websql
1850
1852
  let roomName;
1851
- if (this.core.ctx.disabledRealtime) {
1853
+ if (this.core.ctx.disabledRealtime || this.core.ctx.isRemoteHost) {
1852
1854
  return;
1853
1855
  }
1854
1856
  if (customEvent) {
@@ -2566,8 +2568,10 @@ class RealtimeCore {
2566
2568
  ];
2567
2569
  this.ctx = ctx;
2568
2570
  this.strategy = this.resolveStrategy();
2569
- this.ctx.logRealtime &&
2570
- console.log(`[taon] realtime strategy: ${this.strategy}`);
2571
+ // this.ctx.logRealtime &&
2572
+ // console.log(`
2573
+ // [ctx=${this.ctx.contextName}] realtime strategy: ${this.strategy}, context type: ${this.ctx.contextType}
2574
+ // `);
2571
2575
  if (Helpers.isWebSQL) {
2572
2576
  this.server = new RealtimeServer(this);
2573
2577
  // console.log('DONE INITING SERVER');
@@ -2604,7 +2608,8 @@ class RealtimeCore {
2604
2608
  pathFor(namespace) {
2605
2609
  let nsp = namespace ? namespace : '';
2606
2610
  nsp = nsp === '/' ? '' : nsp;
2607
- let prefix = `${apiPrefix}/${this.ctx.contextName}/udp`;
2611
+ const contextNameForCommunication = this.ctx.contextNameForCommunication;
2612
+ let prefix = `${apiPrefix}/${contextNameForCommunication}/udp`;
2608
2613
  if (Helpers.isElectron) {
2609
2614
  prefix = ``;
2610
2615
  }
@@ -2670,6 +2675,12 @@ class EndpointContext {
2670
2675
  this.ngZone = ngZone;
2671
2676
  //#endregion
2672
2677
  }
2678
+ //#endregion
2679
+ //#endregion
2680
+ //#region fields / source context
2681
+ get sourceContext() {
2682
+ return this.cloneOptions?.sourceContext;
2683
+ }
2673
2684
  get isRunOrRevertOnlyMigrationAppStart() {
2674
2685
  return !!(this.onlyMigrationRun || this.onlyMigrationRevertToTimestamp);
2675
2686
  }
@@ -2711,9 +2722,17 @@ class EndpointContext {
2711
2722
  }
2712
2723
  return this.config?.logs === true;
2713
2724
  }
2714
- constructor(originalConfig, configFn) {
2725
+ constructor(originalConfig, configFn,
2726
+ /**
2727
+ * (@default: false)
2728
+ * If TRUE context is NOT going to create db/express server/http endpoints
2729
+ * PURPOSE OF THIS PROPERTY
2730
+ * -> ONLY remote access from backend or frontend to specific backend
2731
+ */
2732
+ cloneOptions) {
2715
2733
  this.originalConfig = originalConfig;
2716
2734
  this.configFn = configFn;
2735
+ this.cloneOptions = cloneOptions;
2717
2736
  //#region static
2718
2737
  /**
2719
2738
  * JUST FOR TESTING PURPOSES
@@ -2759,7 +2778,6 @@ class EndpointContext {
2759
2778
  //#region @websql
2760
2779
  this.repos = new Map();
2761
2780
  //#endregion
2762
- //#endregion
2763
2781
  this.skipWritingServerRoutes = false;
2764
2782
  //#region fields / types from contexts
2765
2783
  this.injectableTypesfromContexts = [
@@ -2888,12 +2906,13 @@ class EndpointContext {
2888
2906
  }
2889
2907
  return classes;
2890
2908
  };
2909
+ this.cloneOptions = this.cloneOptions || {};
2891
2910
  this.isRunningInsideDocker = UtilsOs.isRunningInDocker();
2892
2911
  }
2893
2912
  //#endregion
2894
2913
  //#region methods & getters / init
2895
2914
  async init(options) {
2896
- const { initFromRecrusiveContextResovle, overrideHost, overrideRemoteHost, onlyMigrationRun, onlyMigrationRevertToTimestamp, } = options || {}; // TODO use it ?
2915
+ const { initFromRecrusiveContextResovle, onlyMigrationRun, onlyMigrationRevertToTimestamp, } = options || {}; // TODO use it ?
2897
2916
  this.inited = true;
2898
2917
  // @ts-ignore
2899
2918
  this.onlyMigrationRun = onlyMigrationRun;
@@ -2903,31 +2922,23 @@ class EndpointContext {
2903
2922
  if (_.isObject(this.config.database)) {
2904
2923
  this.config.database = Models.DatabaseConfig.from(this.config.database).databaseConfigTypeORM;
2905
2924
  }
2906
- if (overrideHost && overrideRemoteHost) {
2907
- Helpers.throw(`[taon-config] You can't have overrideHost and overrideRemoteHost at the same time`);
2908
- }
2909
- this.config.host = !_.isUndefined(overrideHost)
2910
- ? overrideHost
2911
- : this.config.host;
2912
- this.config.remoteHost = !_.isUndefined(overrideRemoteHost)
2913
- ? overrideRemoteHost
2914
- : this.config.remoteHost;
2915
2925
  this.config.host = this.host === null ? void 0 : this.host;
2916
- this.config.remoteHost =
2917
- this.remoteHost === null ? void 0 : this.remoteHost;
2926
+ if (this.cloneOptions.overrideHost &&
2927
+ !this.cloneOptions.useAsRemoteContext) {
2928
+ this.config.host = this.cloneOptions.overrideHost;
2929
+ }
2930
+ if (this.cloneOptions.overrideRemoteHost &&
2931
+ this.cloneOptions.useAsRemoteContext) {
2932
+ this.config.host = this.cloneOptions.overrideRemoteHost;
2933
+ }
2918
2934
  if (this.config.host &&
2919
2935
  !this.config.host.startsWith('http://') &&
2920
2936
  !this.config.host.startsWith('https://')) {
2921
- Helpers.throw(`[taon-config] Your 'host' must start with http:// or https://`);
2937
+ Helpers.throw(`[taon-config] Your${this.host ? ' remote' : ''} 'host' must start with http:// or https://`);
2922
2938
  }
2923
2939
  if (_.isUndefined(this.config.useIpcWhenElectron)) {
2924
2940
  this.config.useIpcWhenElectron = true;
2925
2941
  }
2926
- if (this.config.remoteHost &&
2927
- !this.config.remoteHost.startsWith('http://') &&
2928
- !this.config.remoteHost.startsWith('https://')) {
2929
- Helpers.throw(`[taon-config] Your 'remoteHost' must start with http:// or https://`);
2930
- }
2931
2942
  // console.log(`config for ${this.contextName}`, this.config);
2932
2943
  //#region resolve if skipping writing server routes
2933
2944
  //@ts-expect-error overriding readonly
@@ -2942,10 +2953,7 @@ class EndpointContext {
2942
2953
  this.mode = 'backend-frontend(websql)';
2943
2954
  //#endregion
2944
2955
  }
2945
- if (this.config.remoteHost) {
2946
- if (this.config.host) {
2947
- Helpers.throw(`[taon] You can't have remoteHost and host at the same time`);
2948
- }
2956
+ if (this.isRemoteHost) {
2949
2957
  this.mode = 'remote-backend(tcp+udp)';
2950
2958
  }
2951
2959
  // console.log(`
@@ -2966,9 +2974,9 @@ class EndpointContext {
2966
2974
  // console.log(this.config)
2967
2975
  // }
2968
2976
  if (!this.mode && !this.config.abstract) {
2969
- const errMsg = `You need to provide host or remoteHost or ` +
2970
- `useIpcWhenElectron (or mark it as abstract)`;
2971
- Helpers.error(`[taon] Context "${this.contextName}": ${errMsg}`, false, true);
2977
+ const errMsg = `You need to provide host property or ` +
2978
+ `useIpcWhenElectron or mark it as abstract`;
2979
+ Helpers.error(`[taon][Context=${this.contextName}]: ${errMsg}`, false, true);
2972
2980
  /* */
2973
2981
  /* */
2974
2982
  }
@@ -3016,7 +3024,7 @@ class EndpointContext {
3016
3024
  axios.defaults.withCredentials = true;
3017
3025
  }
3018
3026
  //#endregion
3019
- //#region prepare & gather all classes recrusively
3027
+ //#region prepare & gather all classes recursively
3020
3028
  this.config.contexts = this.config.contexts || {};
3021
3029
  this.config.entities = this.config.entities || {};
3022
3030
  this.config.controllers = this.config.controllers || {};
@@ -3153,6 +3161,8 @@ class EndpointContext {
3153
3161
  /* */
3154
3162
  /* */
3155
3163
  /* */
3164
+ this.logRealtime &&
3165
+ Helpers.info(`[ctx=${this.contextName}] Init Realtime for ${this.mode}`);
3156
3166
  this.realtime = new RealtimeCore(this);
3157
3167
  }
3158
3168
  //#endregion
@@ -3164,9 +3174,9 @@ class EndpointContext {
3164
3174
  Helpers.info(`[taon] Create abstract context: ${this.config.contextName}`);
3165
3175
  }
3166
3176
  else {
3167
- if (this.config.remoteHost) {
3177
+ if (this.isRemoteHost) {
3168
3178
  this.logFramework &&
3169
- Helpers.info(`[taon] Create context for remote host: ${this.config.remoteHost}`);
3179
+ Helpers.info(`[taon] Create context for remote host: ${this.config.host}`);
3170
3180
  }
3171
3181
  else {
3172
3182
  this.logFramework &&
@@ -3353,6 +3363,10 @@ class EndpointContext {
3353
3363
  /* */
3354
3364
  /* */
3355
3365
  /* */
3366
+ /* */
3367
+ /* */
3368
+ /* */
3369
+ /* */
3356
3370
  return (void 0);
3357
3371
  }
3358
3372
  //#endregion
@@ -3591,7 +3605,7 @@ class EndpointContext {
3591
3605
  //#endregion
3592
3606
  //#region methods & getters / init classes
3593
3607
  async initClasses() {
3594
- if (this.remoteHost) {
3608
+ if (this.isRemoteHost) {
3595
3609
  return;
3596
3610
  }
3597
3611
  //#region @websql
@@ -3654,11 +3668,7 @@ class EndpointContext {
3654
3668
  return uri;
3655
3669
  }
3656
3670
  get uri() {
3657
- const url = this.host
3658
- ? new URL(this.host)
3659
- : this.remoteHost
3660
- ? new URL(this.remoteHost)
3661
- : void 0;
3671
+ const url = this.host ? new URL(this.host) : void 0;
3662
3672
  return url;
3663
3673
  }
3664
3674
  //#endregion
@@ -3726,11 +3736,50 @@ class EndpointContext {
3726
3736
  }
3727
3737
  //#endregion
3728
3738
  //#region methods & getters / public assets
3739
+ get isRemoteHost() {
3740
+ return !!this.cloneOptions?.useAsRemoteContext;
3741
+ }
3742
+ //#endregion
3743
+ //#region methods & getters / public assets
3729
3744
  /**
3730
3745
  * ipc/udp needs this
3731
3746
  */
3732
3747
  get contextName() {
3733
- return this.config.contextName;
3748
+ // console.log(this.originalConfig);
3749
+ return this.config?.contextName || this.originalConfig?.contextName;
3750
+ }
3751
+ //#endregion
3752
+ //#region methods & getters / public assets
3753
+ /**
3754
+ * ipc/udp needs this
3755
+ */
3756
+ get contextNameForCommunication() {
3757
+ let contextName = this.contextName;
3758
+ if (this.isRemoteHost) {
3759
+ if (this.sourceContext?.contextName) {
3760
+ contextName = this.sourceContext?.contextName;
3761
+ }
3762
+ else {
3763
+ // console.log(
3764
+ // `CANT GET SOURCE CONTEXT NAME FOR REMOTE CONTEXT ${this.contextName}`,
3765
+ // );
3766
+ }
3767
+ }
3768
+ return contextName;
3769
+ }
3770
+ //#endregion
3771
+ //#region methods & getters / public assets
3772
+ /**
3773
+ * Check context type
3774
+ */
3775
+ get contextType() {
3776
+ if (this.config.abstract) {
3777
+ return 'abstract';
3778
+ }
3779
+ if (this.host) {
3780
+ return this.isRemoteHost ? 'remote' : 'normal';
3781
+ }
3782
+ return 'invalid';
3734
3783
  }
3735
3784
  //#endregion
3736
3785
  //#region methods & getters / current working directory
@@ -3758,11 +3807,6 @@ class EndpointContext {
3758
3807
  return this.config.productionMode;
3759
3808
  }
3760
3809
  //#endregion
3761
- //#region methods & getters / remote host
3762
- get remoteHost() {
3763
- return this.config.remoteHost;
3764
- }
3765
- //#endregion
3766
3810
  //#region methods & getters / host
3767
3811
  get host() {
3768
3812
  return this.config.host;
@@ -3776,7 +3820,7 @@ class EndpointContext {
3776
3820
  //#region methods & getters / init subscribers
3777
3821
  async initSubscribers() {
3778
3822
  //#region @websqlFunc
3779
- if (this.remoteHost) {
3823
+ if (this.isRemoteHost) {
3780
3824
  return;
3781
3825
  }
3782
3826
  const subscriberClasses = this.getClassFunByArr(Models.ClassType.SUBSCRIBER);
@@ -3792,7 +3836,7 @@ class EndpointContext {
3792
3836
  //#region methods & getters / init entities
3793
3837
  async initEntities() {
3794
3838
  //#region @websql
3795
- if (this.remoteHost) {
3839
+ if (this.isRemoteHost) {
3796
3840
  return;
3797
3841
  }
3798
3842
  const entities = this.getClassFunByArr(Models.ClassType.ENTITY);
@@ -3838,7 +3882,7 @@ class EndpointContext {
3838
3882
  //#region methods & getters / init connection
3839
3883
  async initDatabaseConnection() {
3840
3884
  //#region @websqlFunc
3841
- if (this.remoteHost || !this.databaseConfig) {
3885
+ if (this.isRemoteHost || !this.databaseConfig) {
3842
3886
  return;
3843
3887
  }
3844
3888
  const entities = this.getClassFunByArr(Models.ClassType.ENTITY).map(entityFn => {
@@ -3944,12 +3988,13 @@ class EndpointContext {
3944
3988
  return bc.className;
3945
3989
  })
3946
3990
  .join('/');
3991
+ const contextNameForCommunication = this.contextNameForCommunication;
3947
3992
  if (TaonHelpers.isGoodPath(classConfig.path)) {
3948
3993
  classConfig.calculatedPath = classConfig.path;
3949
3994
  }
3950
3995
  else {
3951
3996
  classConfig.calculatedPath = (`${this.uriPathnameOrNothingIfRoot}` +
3952
- `/${apiPrefix}/${this.contextName}/tcp${parentsCalculatedPath}/` +
3997
+ `/${apiPrefix}/${contextNameForCommunication}/tcp${parentsCalculatedPath}/` +
3953
3998
  `${ClassHelpers.getName(controllerClassFn)}`)
3954
3999
  .replace(/\/\//g, '/')
3955
4000
  .split('/')
@@ -3979,7 +4024,7 @@ class EndpointContext {
3979
4024
  });
3980
4025
  }
3981
4026
  //#endregion
3982
- async initControllersHook(allInitedEndpointContexts) {
4027
+ async initControllersHook(ctxStorage) {
3983
4028
  if (this.isRunOrRevertOnlyMigrationAppStart) {
3984
4029
  return;
3985
4030
  }
@@ -3987,7 +4032,7 @@ class EndpointContext {
3987
4032
  for (const controllerClassFn of allControllers) {
3988
4033
  const instance = this.getInstanceBy(controllerClassFn);
3989
4034
  if (_.isFunction(instance.afterAllCtxInited)) {
3990
- await instance.afterAllCtxInited(allInitedEndpointContexts);
4035
+ await instance.afterAllCtxInited({ ctxStorage });
3991
4036
  }
3992
4037
  }
3993
4038
  }
@@ -4085,7 +4130,7 @@ class EndpointContext {
4085
4130
  }
4086
4131
  //#endregion
4087
4132
  //#region init client
4088
- const shouldInitClient = Helpers.isBrowser || this.remoteHost || Helpers.isWebSQL;
4133
+ const shouldInitClient = Helpers.isBrowser || this.isRemoteHost || Helpers.isWebSQL;
4089
4134
  // console.log('shouldInitClient', shouldInitClient);
4090
4135
  if (shouldInitClient) {
4091
4136
  // console.log(
@@ -4112,7 +4157,7 @@ class EndpointContext {
4112
4157
  //#endregion
4113
4158
  //#region methods & getters / write active routes
4114
4159
  writeActiveRoutes() {
4115
- if (this.remoteHost ||
4160
+ if (this.isRemoteHost ||
4116
4161
  this.isRunOrRevertOnlyMigrationAppStart ||
4117
4162
  this.skipWritingServerRoutes) {
4118
4163
  return;
@@ -4393,7 +4438,7 @@ class EndpointContext {
4393
4438
  /* */
4394
4439
  /* */
4395
4440
  }
4396
- if (!this.remoteHost) {
4441
+ if (!this.isRemoteHost) {
4397
4442
  //#region apply dummy websql express routers
4398
4443
  //#region @websql
4399
4444
  if (Helpers.isWebSQL) {
@@ -4997,6 +5042,34 @@ instead
4997
5042
  }
4998
5043
  }
4999
5044
 
5045
+ class ContextsEndpointStorage {
5046
+ constructor() {
5047
+ this.taonEndpointContexts = new Map();
5048
+ // Private constructor to prevent direct instantiation
5049
+ }
5050
+ static get Instance() {
5051
+ if (!ContextsEndpointStorage.instance) {
5052
+ ContextsEndpointStorage.instance = new ContextsEndpointStorage();
5053
+ }
5054
+ return ContextsEndpointStorage.instance;
5055
+ }
5056
+ //#endregion
5057
+ set(context) {
5058
+ if (!this.taonEndpointContexts.has(context.contextName)) {
5059
+ this.taonEndpointContexts.set(context.contextName, context);
5060
+ }
5061
+ }
5062
+ get arr() {
5063
+ return Array.from(this.taonEndpointContexts.values()).filter(f => f.contextType === 'normal');
5064
+ }
5065
+ getBy(context) {
5066
+ if (typeof context === 'string') {
5067
+ return this.taonEndpointContexts.get(context);
5068
+ }
5069
+ return this.taonEndpointContexts.get(context.contextName);
5070
+ }
5071
+ }
5072
+
5000
5073
  //#region imports
5001
5074
  //#endregion
5002
5075
  /**
@@ -5013,14 +5086,15 @@ const createContextTemplate = (configFn) => {
5013
5086
  * REQURIED PROPERTY:
5014
5087
  * - contextName
5015
5088
  */
5016
- const createContext = (configFn) => {
5089
+ const createContextFn = (configFn, cloneOptions) => {
5090
+ cloneOptions = cloneOptions || {};
5017
5091
  let config = configFn({});
5018
5092
  // console.log(
5019
5093
  // `
5020
5094
  // [Taon] Creating context ${config.contextName}...`,
5021
5095
  // {config},
5022
5096
  // );
5023
- const endpointContextRef = new EndpointContext(config, configFn);
5097
+ const endpointContextRef = new EndpointContext(config, configFn, cloneOptions);
5024
5098
  const res = {
5025
5099
  //#region contexts
5026
5100
  get contextName() {
@@ -5030,6 +5104,24 @@ const createContext = (configFn) => {
5030
5104
  get appId() {
5031
5105
  return config.appId;
5032
5106
  },
5107
+ cloneAsRemote: (cloneOpt) => {
5108
+ cloneOpt = cloneOpt || {};
5109
+ const opt = {
5110
+ ...cloneOpt,
5111
+ sourceContext: endpointContextRef,
5112
+ useAsRemoteContext: true,
5113
+ };
5114
+ return createContextFn(configFn, opt);
5115
+ },
5116
+ cloneAsNormal: (cloneOpt) => {
5117
+ cloneOpt = cloneOpt || {};
5118
+ const opt = {
5119
+ ...cloneOpt,
5120
+ sourceContext: endpointContextRef,
5121
+ useAsRemoteContext: false,
5122
+ };
5123
+ return createContextFn(configFn, opt);
5124
+ },
5033
5125
  //#region context
5034
5126
  /**
5035
5127
  * @deprecated
@@ -5143,19 +5235,23 @@ const createContext = (configFn) => {
5143
5235
  //#endregion
5144
5236
  //#region run migrations tasks
5145
5237
  if (endpointContextRef.onlyMigrationRun) {
5146
- Helpers.log(`[taon] Running only migrations (context=${endpointContextRef.contextName}).`);
5238
+ endpointContextRef.logMigrations &&
5239
+ Helpers.log(`[taon] Running only migrations (context=${endpointContextRef.contextName}).`);
5147
5240
  await endpointContextRef.dbMigrations.runAllNotCompletedMigrations();
5148
5241
  }
5149
5242
  else if (endpointContextRef.onlyMigrationRevertToTimestamp) {
5150
- Helpers.log(`[taon] Reverting migrations to timestamp ${endpointContextRef.onlyMigrationRevertToTimestamp} (context=${endpointContextRef.contextName}).`);
5243
+ endpointContextRef.logMigrations &&
5244
+ Helpers.log(`[taon] Reverting migrations to timestamp ${endpointContextRef.onlyMigrationRevertToTimestamp} (context=${endpointContextRef.contextName}).`);
5151
5245
  await endpointContextRef.dbMigrations.revertMigrationToTimestamp(endpointContextRef.onlyMigrationRevertToTimestamp);
5152
5246
  }
5153
5247
  else {
5154
- Helpers.log(`[taon] Running all not applied migrations (context=${endpointContextRef.contextName}).`);
5248
+ endpointContextRef.logMigrations &&
5249
+ Helpers.log(`[taon] Running all not applied migrations (context=${endpointContextRef.contextName}).`);
5155
5250
  await endpointContextRef.dbMigrations.runAllNotCompletedMigrations();
5156
5251
  }
5157
5252
  //#endregion
5158
5253
  }
5254
+ ContextsEndpointStorage.Instance.set(endpointContextRef);
5159
5255
  resolve(endpointContextRef);
5160
5256
  });
5161
5257
  //#endregion
@@ -5178,6 +5274,12 @@ const createContext = (configFn) => {
5178
5274
  };
5179
5275
  return res;
5180
5276
  };
5277
+ //#endregion
5278
+ const createContext = (configFn) => {
5279
+ return createContextFn(configFn, { useAsRemoteContext: false });
5280
+ };
5281
+ // const AA = createContext(() => ({ contextName: 'aa' }));
5282
+ // const BB = AA.cloneAsRemoteContext();
5181
5283
 
5182
5284
  /**
5183
5285
  * Provider decorator
@@ -6202,14 +6304,12 @@ function Body(name) {
6202
6304
  };
6203
6305
  }
6204
6306
 
6205
- /* */
6206
- /* */
6207
6307
  let BaseController = class BaseController extends BaseInjector {
6208
6308
  /**
6209
6309
  * Hook that is called when taon app is inited
6210
6310
  * (all contexts are created and inited)
6211
6311
  */
6212
- async afterAllCtxInited(allContexts) { }
6312
+ async afterAllCtxInited(options) { }
6213
6313
  //#region upload form data to server
6214
6314
  uploadFormDataToServer(formData) {
6215
6315
  /* */
@@ -6883,5 +6983,5 @@ var Taon;
6883
6983
  * Generated bundle index. Do not edit.
6884
6984
  */
6885
6985
 
6886
- export { BaseContext, BaseController, BaseCustomRepository, BaseEntity, BaseFileUploadMiddleware, BaseMigration, BaseProvider, BaseRepository, CURRENT_HOST_BACKEND_PORT, CURRENT_HOST_URL, ClassHelpers, EndpointContext, Models, TAON_CONTEXT, Taon, TaonAdminService, TaonEntityKeysToOmitArr, apiPrefix, createContext, inject };
6986
+ export { BaseContext, BaseController, BaseCustomRepository, BaseEntity, BaseFileUploadMiddleware, BaseMigration, BaseProvider, BaseRepository, CURRENT_HOST_BACKEND_PORT, CURRENT_HOST_URL, ClassHelpers, ContextsEndpointStorage, EndpointContext, Models, TAON_CONTEXT, Taon, TaonAdminService, TaonEntityKeysToOmitArr, apiPrefix, createContext, inject };
6887
6987
  //# sourceMappingURL=taon.mjs.map