taon 19.0.61 → 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 (73) 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 -76
  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/lib/base-classes/base-context.d.ts +6 -0
  19. package/lib/base-classes/base-controller.d.ts +3 -3
  20. package/lib/base-classes/base-controller.js +2 -2
  21. package/lib/base-classes/base-controller.js.map +1 -1
  22. package/lib/base-classes/base.d.ts +6 -0
  23. package/lib/build-info._auto-generated_.d.ts +1 -1
  24. package/lib/build-info._auto-generated_.js +1 -1
  25. package/lib/context-db-migrations.js +5 -5
  26. package/lib/context-db-migrations.js.map +1 -1
  27. package/lib/create-context.d.ts +12 -4
  28. package/lib/create-context.js +35 -5
  29. package/lib/create-context.js.map +1 -1
  30. package/lib/endpoint-context-storage.d.ts +10 -0
  31. package/lib/endpoint-context-storage.js +34 -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 -10
  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/README.md +24 -24
  51. package/websql/fesm2022/taon.mjs +184 -83
  52. package/websql/fesm2022/taon.mjs.map +1 -1
  53. package/websql/lib/base-classes/base-context.d.ts +6 -0
  54. package/websql/lib/base-classes/base-controller.d.ts +3 -3
  55. package/websql/lib/base-classes/base.d.ts +6 -0
  56. package/websql/lib/create-context.d.ts +12 -4
  57. package/websql/lib/endpoint-context-storage.d.ts +11 -0
  58. package/websql/lib/endpoint-context.d.ts +28 -8
  59. package/websql/lib/index.d.ts +19 -0
  60. package/websql/lib/models.d.ts +7 -8
  61. package/websql/package.json +1 -1
  62. package/lib/decorators/classes/controller-config.d.ts +0 -0
  63. package/lib/decorators/classes/controller-config.js +0 -5
  64. package/lib/decorators/classes/controller-config.js.map +0 -1
  65. package/lib/decorators/classes/controller-options.d.ts +0 -0
  66. package/lib/decorators/classes/controller-options.js +0 -5
  67. package/lib/decorators/classes/controller-options.js.map +0 -1
  68. package/lib/env.d.ts +0 -2
  69. package/lib/env.js +0 -7
  70. package/lib/env.js.map +0 -1
  71. package/lib/storage.d.ts +0 -1
  72. package/lib/storage.js +0 -6
  73. package/lib/storage.js.map +0 -1
@@ -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,12 +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 ${this.core.ctx.config.frontendHost}`);
1575
+ this.core.ctx.logRealtime &&
1576
+ Helpers.logInfo(`[${this.core.ctx.contextName}] USING FRONTEND HOST` +
1577
+ ` ${this.core.ctx.config.frontendHost} FOR REALTIME`);
1572
1578
  nspPath.global = new URL(`${this.core.ctx.frontendHostUri.origin}${nspPath.global.pathname}`);
1573
1579
  nspPath.realtime = new URL(`${this.core.ctx.frontendHostUri.origin}${nspPath.realtime.pathname}`);
1574
1580
  }
1575
1581
  else {
1576
- Helpers.logInfo(`[${this.core.ctx.contextName}] NOT USING FRONTEND HOST`);
1582
+ this.core.ctx.logRealtime &&
1583
+ Helpers.logInfo(`[${this.core.ctx.contextName}] Not using frontend host for realtime`);
1577
1584
  }
1578
1585
  this.core.ctx.logRealtime &&
1579
1586
  console.info('[CLIENT] NAMESPACE GLOBAL ', nspPath.global.href + ` host: ${this.core.ctx.host}`);
@@ -1718,14 +1725,9 @@ to use socket realtime connection;
1718
1725
  //#endregion
1719
1726
  //#region methods & getters / get room id from
1720
1727
  getUniqueIdentifierForConnection(options) {
1721
- let url;
1722
- if (UtilsOs.isBrowser) {
1723
- url = new URL(options.core.ctx.host);
1724
- }
1725
- else {
1726
- url = new URL(options.core.ctx.remoteHost); // backend-to-backend use remote host
1727
- }
1728
- 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}`;
1729
1731
  }
1730
1732
  }
1731
1733
 
@@ -1737,11 +1739,12 @@ class RealtimeServer {
1737
1739
  constructor(core) {
1738
1740
  this.core = core;
1739
1741
  this.core = core;
1740
- if (!core.ctx.disabledRealtime) {
1741
- //#region @websql
1742
- this.init();
1743
- //#endregion
1742
+ if (core.ctx.disabledRealtime || this.core.ctx.isRemoteHost) {
1743
+ return;
1744
1744
  }
1745
+ //#region @websql
1746
+ this.init();
1747
+ //#endregion
1745
1748
  }
1746
1749
  //#region methods & getters / init
1747
1750
  init() {
@@ -1847,7 +1850,7 @@ class RealtimeServer {
1847
1850
  // console.info('__triger entity changes');
1848
1851
  //#region @websql
1849
1852
  let roomName;
1850
- if (this.core.ctx.disabledRealtime) {
1853
+ if (this.core.ctx.disabledRealtime || this.core.ctx.isRemoteHost) {
1851
1854
  return;
1852
1855
  }
1853
1856
  if (customEvent) {
@@ -2565,8 +2568,10 @@ class RealtimeCore {
2565
2568
  ];
2566
2569
  this.ctx = ctx;
2567
2570
  this.strategy = this.resolveStrategy();
2568
- this.ctx.logRealtime &&
2569
- 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
+ // `);
2570
2575
  if (Helpers.isWebSQL) {
2571
2576
  this.server = new RealtimeServer(this);
2572
2577
  // console.log('DONE INITING SERVER');
@@ -2603,7 +2608,8 @@ class RealtimeCore {
2603
2608
  pathFor(namespace) {
2604
2609
  let nsp = namespace ? namespace : '';
2605
2610
  nsp = nsp === '/' ? '' : nsp;
2606
- let prefix = `${apiPrefix}/${this.ctx.contextName}/udp`;
2611
+ const contextNameForCommunication = this.ctx.contextNameForCommunication;
2612
+ let prefix = `${apiPrefix}/${contextNameForCommunication}/udp`;
2607
2613
  if (Helpers.isElectron) {
2608
2614
  prefix = ``;
2609
2615
  }
@@ -2669,6 +2675,12 @@ class EndpointContext {
2669
2675
  this.ngZone = ngZone;
2670
2676
  //#endregion
2671
2677
  }
2678
+ //#endregion
2679
+ //#endregion
2680
+ //#region fields / source context
2681
+ get sourceContext() {
2682
+ return this.cloneOptions?.sourceContext;
2683
+ }
2672
2684
  get isRunOrRevertOnlyMigrationAppStart() {
2673
2685
  return !!(this.onlyMigrationRun || this.onlyMigrationRevertToTimestamp);
2674
2686
  }
@@ -2710,9 +2722,17 @@ class EndpointContext {
2710
2722
  }
2711
2723
  return this.config?.logs === true;
2712
2724
  }
2713
- 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) {
2714
2733
  this.originalConfig = originalConfig;
2715
2734
  this.configFn = configFn;
2735
+ this.cloneOptions = cloneOptions;
2716
2736
  //#region static
2717
2737
  /**
2718
2738
  * JUST FOR TESTING PURPOSES
@@ -2758,7 +2778,6 @@ class EndpointContext {
2758
2778
  //#region @websql
2759
2779
  this.repos = new Map();
2760
2780
  //#endregion
2761
- //#endregion
2762
2781
  this.skipWritingServerRoutes = false;
2763
2782
  //#region fields / types from contexts
2764
2783
  this.injectableTypesfromContexts = [
@@ -2887,12 +2906,13 @@ class EndpointContext {
2887
2906
  }
2888
2907
  return classes;
2889
2908
  };
2909
+ this.cloneOptions = this.cloneOptions || {};
2890
2910
  this.isRunningInsideDocker = UtilsOs.isRunningInDocker();
2891
2911
  }
2892
2912
  //#endregion
2893
2913
  //#region methods & getters / init
2894
2914
  async init(options) {
2895
- const { initFromRecrusiveContextResovle, overrideHost, overrideRemoteHost, onlyMigrationRun, onlyMigrationRevertToTimestamp, } = options || {}; // TODO use it ?
2915
+ const { initFromRecrusiveContextResovle, onlyMigrationRun, onlyMigrationRevertToTimestamp, } = options || {}; // TODO use it ?
2896
2916
  this.inited = true;
2897
2917
  // @ts-ignore
2898
2918
  this.onlyMigrationRun = onlyMigrationRun;
@@ -2902,31 +2922,23 @@ class EndpointContext {
2902
2922
  if (_.isObject(this.config.database)) {
2903
2923
  this.config.database = Models.DatabaseConfig.from(this.config.database).databaseConfigTypeORM;
2904
2924
  }
2905
- if (overrideHost && overrideRemoteHost) {
2906
- Helpers.throw(`[taon-config] You can't have overrideHost and overrideRemoteHost at the same time`);
2907
- }
2908
- this.config.host = !_.isUndefined(overrideHost)
2909
- ? overrideHost
2910
- : this.config.host;
2911
- this.config.remoteHost = !_.isUndefined(overrideRemoteHost)
2912
- ? overrideRemoteHost
2913
- : this.config.remoteHost;
2914
2925
  this.config.host = this.host === null ? void 0 : this.host;
2915
- this.config.remoteHost =
2916
- 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
+ }
2917
2934
  if (this.config.host &&
2918
2935
  !this.config.host.startsWith('http://') &&
2919
2936
  !this.config.host.startsWith('https://')) {
2920
- 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://`);
2921
2938
  }
2922
2939
  if (_.isUndefined(this.config.useIpcWhenElectron)) {
2923
2940
  this.config.useIpcWhenElectron = true;
2924
2941
  }
2925
- if (this.config.remoteHost &&
2926
- !this.config.remoteHost.startsWith('http://') &&
2927
- !this.config.remoteHost.startsWith('https://')) {
2928
- Helpers.throw(`[taon-config] Your 'remoteHost' must start with http:// or https://`);
2929
- }
2930
2942
  // console.log(`config for ${this.contextName}`, this.config);
2931
2943
  //#region resolve if skipping writing server routes
2932
2944
  //@ts-expect-error overriding readonly
@@ -2941,10 +2953,7 @@ class EndpointContext {
2941
2953
  this.mode = 'backend-frontend(websql)';
2942
2954
  //#endregion
2943
2955
  }
2944
- if (this.config.remoteHost) {
2945
- if (this.config.host) {
2946
- Helpers.throw(`[taon] You can't have remoteHost and host at the same time`);
2947
- }
2956
+ if (this.isRemoteHost) {
2948
2957
  this.mode = 'remote-backend(tcp+udp)';
2949
2958
  }
2950
2959
  // console.log(`
@@ -2965,9 +2974,9 @@ class EndpointContext {
2965
2974
  // console.log(this.config)
2966
2975
  // }
2967
2976
  if (!this.mode && !this.config.abstract) {
2968
- const errMsg = `You need to provide host or remoteHost or ` +
2969
- `useIpcWhenElectron (or mark it as abstract)`;
2970
- 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);
2971
2980
  /* */
2972
2981
  /* */
2973
2982
  }
@@ -3015,7 +3024,7 @@ class EndpointContext {
3015
3024
  axios.defaults.withCredentials = true;
3016
3025
  }
3017
3026
  //#endregion
3018
- //#region prepare & gather all classes recrusively
3027
+ //#region prepare & gather all classes recursively
3019
3028
  this.config.contexts = this.config.contexts || {};
3020
3029
  this.config.entities = this.config.entities || {};
3021
3030
  this.config.controllers = this.config.controllers || {};
@@ -3152,6 +3161,8 @@ class EndpointContext {
3152
3161
  /* */
3153
3162
  /* */
3154
3163
  /* */
3164
+ this.logRealtime &&
3165
+ Helpers.info(`[ctx=${this.contextName}] Init Realtime for ${this.mode}`);
3155
3166
  this.realtime = new RealtimeCore(this);
3156
3167
  }
3157
3168
  //#endregion
@@ -3163,9 +3174,9 @@ class EndpointContext {
3163
3174
  Helpers.info(`[taon] Create abstract context: ${this.config.contextName}`);
3164
3175
  }
3165
3176
  else {
3166
- if (this.config.remoteHost) {
3177
+ if (this.isRemoteHost) {
3167
3178
  this.logFramework &&
3168
- Helpers.info(`[taon] Create context for remote host: ${this.config.remoteHost}`);
3179
+ Helpers.info(`[taon] Create context for remote host: ${this.config.host}`);
3169
3180
  }
3170
3181
  else {
3171
3182
  this.logFramework &&
@@ -3352,6 +3363,10 @@ class EndpointContext {
3352
3363
  /* */
3353
3364
  /* */
3354
3365
  /* */
3366
+ /* */
3367
+ /* */
3368
+ /* */
3369
+ /* */
3355
3370
  return (void 0);
3356
3371
  }
3357
3372
  //#endregion
@@ -3590,7 +3605,7 @@ class EndpointContext {
3590
3605
  //#endregion
3591
3606
  //#region methods & getters / init classes
3592
3607
  async initClasses() {
3593
- if (this.remoteHost) {
3608
+ if (this.isRemoteHost) {
3594
3609
  return;
3595
3610
  }
3596
3611
  //#region @websql
@@ -3653,11 +3668,7 @@ class EndpointContext {
3653
3668
  return uri;
3654
3669
  }
3655
3670
  get uri() {
3656
- const url = this.host
3657
- ? new URL(this.host)
3658
- : this.remoteHost
3659
- ? new URL(this.remoteHost)
3660
- : void 0;
3671
+ const url = this.host ? new URL(this.host) : void 0;
3661
3672
  return url;
3662
3673
  }
3663
3674
  //#endregion
@@ -3725,11 +3736,50 @@ class EndpointContext {
3725
3736
  }
3726
3737
  //#endregion
3727
3738
  //#region methods & getters / public assets
3739
+ get isRemoteHost() {
3740
+ return !!this.cloneOptions?.useAsRemoteContext;
3741
+ }
3742
+ //#endregion
3743
+ //#region methods & getters / public assets
3728
3744
  /**
3729
3745
  * ipc/udp needs this
3730
3746
  */
3731
3747
  get contextName() {
3732
- 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';
3733
3783
  }
3734
3784
  //#endregion
3735
3785
  //#region methods & getters / current working directory
@@ -3757,11 +3807,6 @@ class EndpointContext {
3757
3807
  return this.config.productionMode;
3758
3808
  }
3759
3809
  //#endregion
3760
- //#region methods & getters / remote host
3761
- get remoteHost() {
3762
- return this.config.remoteHost;
3763
- }
3764
- //#endregion
3765
3810
  //#region methods & getters / host
3766
3811
  get host() {
3767
3812
  return this.config.host;
@@ -3775,7 +3820,7 @@ class EndpointContext {
3775
3820
  //#region methods & getters / init subscribers
3776
3821
  async initSubscribers() {
3777
3822
  //#region @websqlFunc
3778
- if (this.remoteHost) {
3823
+ if (this.isRemoteHost) {
3779
3824
  return;
3780
3825
  }
3781
3826
  const subscriberClasses = this.getClassFunByArr(Models.ClassType.SUBSCRIBER);
@@ -3791,7 +3836,7 @@ class EndpointContext {
3791
3836
  //#region methods & getters / init entities
3792
3837
  async initEntities() {
3793
3838
  //#region @websql
3794
- if (this.remoteHost) {
3839
+ if (this.isRemoteHost) {
3795
3840
  return;
3796
3841
  }
3797
3842
  const entities = this.getClassFunByArr(Models.ClassType.ENTITY);
@@ -3837,7 +3882,7 @@ class EndpointContext {
3837
3882
  //#region methods & getters / init connection
3838
3883
  async initDatabaseConnection() {
3839
3884
  //#region @websqlFunc
3840
- if (this.remoteHost || !this.databaseConfig) {
3885
+ if (this.isRemoteHost || !this.databaseConfig) {
3841
3886
  return;
3842
3887
  }
3843
3888
  const entities = this.getClassFunByArr(Models.ClassType.ENTITY).map(entityFn => {
@@ -3943,12 +3988,13 @@ class EndpointContext {
3943
3988
  return bc.className;
3944
3989
  })
3945
3990
  .join('/');
3991
+ const contextNameForCommunication = this.contextNameForCommunication;
3946
3992
  if (TaonHelpers.isGoodPath(classConfig.path)) {
3947
3993
  classConfig.calculatedPath = classConfig.path;
3948
3994
  }
3949
3995
  else {
3950
3996
  classConfig.calculatedPath = (`${this.uriPathnameOrNothingIfRoot}` +
3951
- `/${apiPrefix}/${this.contextName}/tcp${parentsCalculatedPath}/` +
3997
+ `/${apiPrefix}/${contextNameForCommunication}/tcp${parentsCalculatedPath}/` +
3952
3998
  `${ClassHelpers.getName(controllerClassFn)}`)
3953
3999
  .replace(/\/\//g, '/')
3954
4000
  .split('/')
@@ -3978,7 +4024,7 @@ class EndpointContext {
3978
4024
  });
3979
4025
  }
3980
4026
  //#endregion
3981
- async initControllersHook(allInitedEndpointContexts) {
4027
+ async initControllersHook(ctxStorage) {
3982
4028
  if (this.isRunOrRevertOnlyMigrationAppStart) {
3983
4029
  return;
3984
4030
  }
@@ -3986,7 +4032,7 @@ class EndpointContext {
3986
4032
  for (const controllerClassFn of allControllers) {
3987
4033
  const instance = this.getInstanceBy(controllerClassFn);
3988
4034
  if (_.isFunction(instance.afterAllCtxInited)) {
3989
- await instance.afterAllCtxInited(allInitedEndpointContexts);
4035
+ await instance.afterAllCtxInited({ ctxStorage });
3990
4036
  }
3991
4037
  }
3992
4038
  }
@@ -4084,7 +4130,7 @@ class EndpointContext {
4084
4130
  }
4085
4131
  //#endregion
4086
4132
  //#region init client
4087
- const shouldInitClient = Helpers.isBrowser || this.remoteHost || Helpers.isWebSQL;
4133
+ const shouldInitClient = Helpers.isBrowser || this.isRemoteHost || Helpers.isWebSQL;
4088
4134
  // console.log('shouldInitClient', shouldInitClient);
4089
4135
  if (shouldInitClient) {
4090
4136
  // console.log(
@@ -4111,7 +4157,7 @@ class EndpointContext {
4111
4157
  //#endregion
4112
4158
  //#region methods & getters / write active routes
4113
4159
  writeActiveRoutes() {
4114
- if (this.remoteHost ||
4160
+ if (this.isRemoteHost ||
4115
4161
  this.isRunOrRevertOnlyMigrationAppStart ||
4116
4162
  this.skipWritingServerRoutes) {
4117
4163
  return;
@@ -4392,7 +4438,7 @@ class EndpointContext {
4392
4438
  /* */
4393
4439
  /* */
4394
4440
  }
4395
- if (!this.remoteHost) {
4441
+ if (!this.isRemoteHost) {
4396
4442
  //#region apply dummy websql express routers
4397
4443
  //#region @websql
4398
4444
  if (Helpers.isWebSQL) {
@@ -4996,6 +5042,34 @@ instead
4996
5042
  }
4997
5043
  }
4998
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
+
4999
5073
  //#region imports
5000
5074
  //#endregion
5001
5075
  /**
@@ -5012,14 +5086,15 @@ const createContextTemplate = (configFn) => {
5012
5086
  * REQURIED PROPERTY:
5013
5087
  * - contextName
5014
5088
  */
5015
- const createContext = (configFn) => {
5089
+ const createContextFn = (configFn, cloneOptions) => {
5090
+ cloneOptions = cloneOptions || {};
5016
5091
  let config = configFn({});
5017
5092
  // console.log(
5018
5093
  // `
5019
5094
  // [Taon] Creating context ${config.contextName}...`,
5020
5095
  // {config},
5021
5096
  // );
5022
- const endpointContextRef = new EndpointContext(config, configFn);
5097
+ const endpointContextRef = new EndpointContext(config, configFn, cloneOptions);
5023
5098
  const res = {
5024
5099
  //#region contexts
5025
5100
  get contextName() {
@@ -5029,6 +5104,24 @@ const createContext = (configFn) => {
5029
5104
  get appId() {
5030
5105
  return config.appId;
5031
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
+ },
5032
5125
  //#region context
5033
5126
  /**
5034
5127
  * @deprecated
@@ -5142,19 +5235,23 @@ const createContext = (configFn) => {
5142
5235
  //#endregion
5143
5236
  //#region run migrations tasks
5144
5237
  if (endpointContextRef.onlyMigrationRun) {
5145
- Helpers.log(`[taon] Running only migrations (context=${endpointContextRef.contextName}).`);
5238
+ endpointContextRef.logMigrations &&
5239
+ Helpers.log(`[taon] Running only migrations (context=${endpointContextRef.contextName}).`);
5146
5240
  await endpointContextRef.dbMigrations.runAllNotCompletedMigrations();
5147
5241
  }
5148
5242
  else if (endpointContextRef.onlyMigrationRevertToTimestamp) {
5149
- 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}).`);
5150
5245
  await endpointContextRef.dbMigrations.revertMigrationToTimestamp(endpointContextRef.onlyMigrationRevertToTimestamp);
5151
5246
  }
5152
5247
  else {
5153
- 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}).`);
5154
5250
  await endpointContextRef.dbMigrations.runAllNotCompletedMigrations();
5155
5251
  }
5156
5252
  //#endregion
5157
5253
  }
5254
+ ContextsEndpointStorage.Instance.set(endpointContextRef);
5158
5255
  resolve(endpointContextRef);
5159
5256
  });
5160
5257
  //#endregion
@@ -5177,6 +5274,12 @@ const createContext = (configFn) => {
5177
5274
  };
5178
5275
  return res;
5179
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();
5180
5283
 
5181
5284
  /**
5182
5285
  * Provider decorator
@@ -6201,14 +6304,12 @@ function Body(name) {
6201
6304
  };
6202
6305
  }
6203
6306
 
6204
- /* */
6205
- /* */
6206
6307
  let BaseController = class BaseController extends BaseInjector {
6207
6308
  /**
6208
6309
  * Hook that is called when taon app is inited
6209
6310
  * (all contexts are created and inited)
6210
6311
  */
6211
- async afterAllCtxInited(allContexts) { }
6312
+ async afterAllCtxInited(options) { }
6212
6313
  //#region upload form data to server
6213
6314
  uploadFormDataToServer(formData) {
6214
6315
  /* */
@@ -6882,5 +6983,5 @@ var Taon;
6882
6983
  * Generated bundle index. Do not edit.
6883
6984
  */
6884
6985
 
6885
- 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 };
6886
6987
  //# sourceMappingURL=taon.mjs.map