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
@@ -1545,6 +1545,10 @@ class RealtimeClient {
1545
1545
  this.subsManagers = {};
1546
1546
  this.core = core;
1547
1547
  if (!core.ctx.disabledRealtime) {
1548
+ // this.core.ctx.logRealtime &&
1549
+ // Helpers.info(`
1550
+ // [ctx=${this.core.ctx.contextName}] init RealtimeClient (type: ${this.core.ctx.contextType})
1551
+ // `);
1548
1552
  this.init();
1549
1553
  }
1550
1554
  }
@@ -1559,12 +1563,15 @@ class RealtimeClient {
1559
1563
  if (this.core.ctx.config.frontendHost &&
1560
1564
  this.core.ctx.config.frontendHost !== '' &&
1561
1565
  this.core.ctx.isRunningInsideDocker) {
1562
- Helpers.logInfo(`[${this.core.ctx.contextName}] USING FRONTEND HOST ${this.core.ctx.config.frontendHost}`);
1566
+ this.core.ctx.logRealtime &&
1567
+ Helpers.logInfo(`[${this.core.ctx.contextName}] USING FRONTEND HOST` +
1568
+ ` ${this.core.ctx.config.frontendHost} FOR REALTIME`);
1563
1569
  nspPath.global = new URL(`${this.core.ctx.frontendHostUri.origin}${nspPath.global.pathname}`);
1564
1570
  nspPath.realtime = new URL(`${this.core.ctx.frontendHostUri.origin}${nspPath.realtime.pathname}`);
1565
1571
  }
1566
1572
  else {
1567
- Helpers.logInfo(`[${this.core.ctx.contextName}] NOT USING FRONTEND HOST`);
1573
+ this.core.ctx.logRealtime &&
1574
+ Helpers.logInfo(`[${this.core.ctx.contextName}] Not using frontend host for realtime`);
1568
1575
  }
1569
1576
  this.core.ctx.logRealtime &&
1570
1577
  console.info('[CLIENT] NAMESPACE GLOBAL ', nspPath.global.href + ` host: ${this.core.ctx.host}`);
@@ -1709,14 +1716,9 @@ to use socket realtime connection;
1709
1716
  //#endregion
1710
1717
  //#region methods & getters / get room id from
1711
1718
  getUniqueIdentifierForConnection(options) {
1712
- let url;
1713
- if (UtilsOs.isBrowser) {
1714
- url = new URL(options.core.ctx.host);
1715
- }
1716
- else {
1717
- url = new URL(options.core.ctx.remoteHost); // backend-to-backend use remote host
1718
- }
1719
- return `${this.core.ctx.contextName}:${url.origin}|${options.roomName}|${options.property}|${options.customEvent}`;
1719
+ let url = new URL(options.core.ctx.host);
1720
+ let contextNameForCommunication = options.core.ctx.contextNameForCommunication;
1721
+ return `${contextNameForCommunication}:${url.origin}|${options.roomName}|${options.property}|${options.customEvent}`;
1720
1722
  }
1721
1723
  }
1722
1724
 
@@ -1728,10 +1730,11 @@ class RealtimeServer {
1728
1730
  constructor(core) {
1729
1731
  this.core = core;
1730
1732
  this.core = core;
1731
- if (!core.ctx.disabledRealtime) {
1732
- /* */
1733
- /* */
1733
+ if (core.ctx.disabledRealtime || this.core.ctx.isRemoteHost) {
1734
+ return;
1734
1735
  }
1736
+ /* */
1737
+ /* */
1735
1738
  }
1736
1739
  //#region methods & getters / init
1737
1740
  init() {
@@ -2658,8 +2661,10 @@ class RealtimeCore {
2658
2661
  ];
2659
2662
  this.ctx = ctx;
2660
2663
  this.strategy = this.resolveStrategy();
2661
- this.ctx.logRealtime &&
2662
- console.log(`[taon] realtime strategy: ${this.strategy}`);
2664
+ // this.ctx.logRealtime &&
2665
+ // console.log(`
2666
+ // [ctx=${this.ctx.contextName}] realtime strategy: ${this.strategy}, context type: ${this.ctx.contextType}
2667
+ // `);
2663
2668
  if (Helpers.isWebSQL) {
2664
2669
  this.server = new RealtimeServer(this);
2665
2670
  // console.log('DONE INITING SERVER');
@@ -2696,7 +2701,8 @@ class RealtimeCore {
2696
2701
  pathFor(namespace) {
2697
2702
  let nsp = namespace ? namespace : '';
2698
2703
  nsp = nsp === '/' ? '' : nsp;
2699
- let prefix = `${apiPrefix}/${this.ctx.contextName}/udp`;
2704
+ const contextNameForCommunication = this.ctx.contextNameForCommunication;
2705
+ let prefix = `${apiPrefix}/${contextNameForCommunication}/udp`;
2700
2706
  if (Helpers.isElectron) {
2701
2707
  prefix = ``;
2702
2708
  }
@@ -2716,6 +2722,15 @@ class EndpointContext {
2716
2722
  this.ngZone = ngZone;
2717
2723
  //#endregion
2718
2724
  }
2725
+ //#endregion
2726
+ //#region fields / typeorm repositories
2727
+ /* */
2728
+ /* */
2729
+ //#endregion
2730
+ //#region fields / source context
2731
+ get sourceContext() {
2732
+ return this.cloneOptions?.sourceContext;
2733
+ }
2719
2734
  get isRunOrRevertOnlyMigrationAppStart() {
2720
2735
  return !!(this.onlyMigrationRun || this.onlyMigrationRevertToTimestamp);
2721
2736
  }
@@ -2757,9 +2772,17 @@ class EndpointContext {
2757
2772
  }
2758
2773
  return this.config?.logs === true;
2759
2774
  }
2760
- constructor(originalConfig, configFn) {
2775
+ constructor(originalConfig, configFn,
2776
+ /**
2777
+ * (@default: false)
2778
+ * If TRUE context is NOT going to create db/express server/http endpoints
2779
+ * PURPOSE OF THIS PROPERTY
2780
+ * -> ONLY remote access from backend or frontend to specific backend
2781
+ */
2782
+ cloneOptions) {
2761
2783
  this.originalConfig = originalConfig;
2762
2784
  this.configFn = configFn;
2785
+ this.cloneOptions = cloneOptions;
2763
2786
  //#region static
2764
2787
  /**
2765
2788
  * JUST FOR TESTING PURPOSES
@@ -2801,10 +2824,6 @@ class EndpointContext {
2801
2824
  //#region fields / active routes
2802
2825
  this.activeRoutes = [];
2803
2826
  //#endregion
2804
- //#region fields / typeorm repositories
2805
- /* */
2806
- /* */
2807
- //#endregion
2808
2827
  this.skipWritingServerRoutes = false;
2809
2828
  //#region fields / types from contexts
2810
2829
  this.injectableTypesfromContexts = [
@@ -2933,12 +2952,13 @@ class EndpointContext {
2933
2952
  }
2934
2953
  return classes;
2935
2954
  };
2955
+ this.cloneOptions = this.cloneOptions || {};
2936
2956
  this.isRunningInsideDocker = UtilsOs.isRunningInDocker();
2937
2957
  }
2938
2958
  //#endregion
2939
2959
  //#region methods & getters / init
2940
2960
  async init(options) {
2941
- const { initFromRecrusiveContextResovle, overrideHost, overrideRemoteHost, onlyMigrationRun, onlyMigrationRevertToTimestamp, } = options || {}; // TODO use it ?
2961
+ const { initFromRecrusiveContextResovle, onlyMigrationRun, onlyMigrationRevertToTimestamp, } = options || {}; // TODO use it ?
2942
2962
  this.inited = true;
2943
2963
  // @ts-ignore
2944
2964
  this.onlyMigrationRun = onlyMigrationRun;
@@ -2948,31 +2968,23 @@ class EndpointContext {
2948
2968
  if (_.isObject(this.config.database)) {
2949
2969
  this.config.database = Models.DatabaseConfig.from(this.config.database).databaseConfigTypeORM;
2950
2970
  }
2951
- if (overrideHost && overrideRemoteHost) {
2952
- Helpers.throw(`[taon-config] You can't have overrideHost and overrideRemoteHost at the same time`);
2953
- }
2954
- this.config.host = !_.isUndefined(overrideHost)
2955
- ? overrideHost
2956
- : this.config.host;
2957
- this.config.remoteHost = !_.isUndefined(overrideRemoteHost)
2958
- ? overrideRemoteHost
2959
- : this.config.remoteHost;
2960
2971
  this.config.host = this.host === null ? void 0 : this.host;
2961
- this.config.remoteHost =
2962
- this.remoteHost === null ? void 0 : this.remoteHost;
2972
+ if (this.cloneOptions.overrideHost &&
2973
+ !this.cloneOptions.useAsRemoteContext) {
2974
+ this.config.host = this.cloneOptions.overrideHost;
2975
+ }
2976
+ if (this.cloneOptions.overrideRemoteHost &&
2977
+ this.cloneOptions.useAsRemoteContext) {
2978
+ this.config.host = this.cloneOptions.overrideRemoteHost;
2979
+ }
2963
2980
  if (this.config.host &&
2964
2981
  !this.config.host.startsWith('http://') &&
2965
2982
  !this.config.host.startsWith('https://')) {
2966
- Helpers.throw(`[taon-config] Your 'host' must start with http:// or https://`);
2983
+ Helpers.throw(`[taon-config] Your${this.host ? ' remote' : ''} 'host' must start with http:// or https://`);
2967
2984
  }
2968
2985
  if (_.isUndefined(this.config.useIpcWhenElectron)) {
2969
2986
  this.config.useIpcWhenElectron = true;
2970
2987
  }
2971
- if (this.config.remoteHost &&
2972
- !this.config.remoteHost.startsWith('http://') &&
2973
- !this.config.remoteHost.startsWith('https://')) {
2974
- Helpers.throw(`[taon-config] Your 'remoteHost' must start with http:// or https://`);
2975
- }
2976
2988
  // console.log(`config for ${this.contextName}`, this.config);
2977
2989
  //#region resolve if skipping writing server routes
2978
2990
  //@ts-expect-error overriding readonly
@@ -2986,10 +2998,7 @@ class EndpointContext {
2986
2998
  /* */
2987
2999
  /* */
2988
3000
  }
2989
- if (this.config.remoteHost) {
2990
- if (this.config.host) {
2991
- Helpers.throw(`[taon] You can't have remoteHost and host at the same time`);
2992
- }
3001
+ if (this.isRemoteHost) {
2993
3002
  this.mode = 'remote-backend(tcp+udp)';
2994
3003
  }
2995
3004
  // console.log(`
@@ -3010,9 +3019,9 @@ class EndpointContext {
3010
3019
  // console.log(this.config)
3011
3020
  // }
3012
3021
  if (!this.mode && !this.config.abstract) {
3013
- const errMsg = `You need to provide host or remoteHost or ` +
3014
- `useIpcWhenElectron (or mark it as abstract)`;
3015
- Helpers.error(`[taon] Context "${this.contextName}": ${errMsg}`, false, true);
3022
+ const errMsg = `You need to provide host property or ` +
3023
+ `useIpcWhenElectron or mark it as abstract`;
3024
+ Helpers.error(`[taon][Context=${this.contextName}]: ${errMsg}`, false, true);
3016
3025
  /* */
3017
3026
  /* */
3018
3027
  }
@@ -3060,7 +3069,7 @@ class EndpointContext {
3060
3069
  axios.defaults.withCredentials = true;
3061
3070
  }
3062
3071
  //#endregion
3063
- //#region prepare & gather all classes recrusively
3072
+ //#region prepare & gather all classes recursively
3064
3073
  this.config.contexts = this.config.contexts || {};
3065
3074
  this.config.entities = this.config.entities || {};
3066
3075
  this.config.controllers = this.config.controllers || {};
@@ -3197,6 +3206,8 @@ class EndpointContext {
3197
3206
  /* */
3198
3207
  /* */
3199
3208
  /* */
3209
+ this.logRealtime &&
3210
+ Helpers.info(`[ctx=${this.contextName}] Init Realtime for ${this.mode}`);
3200
3211
  this.realtime = new RealtimeCore(this);
3201
3212
  }
3202
3213
  //#endregion
@@ -3208,9 +3219,9 @@ class EndpointContext {
3208
3219
  Helpers.info(`[taon] Create abstract context: ${this.config.contextName}`);
3209
3220
  }
3210
3221
  else {
3211
- if (this.config.remoteHost) {
3222
+ if (this.isRemoteHost) {
3212
3223
  this.logFramework &&
3213
- Helpers.info(`[taon] Create context for remote host: ${this.config.remoteHost}`);
3224
+ Helpers.info(`[taon] Create context for remote host: ${this.config.host}`);
3214
3225
  }
3215
3226
  else {
3216
3227
  this.logFramework &&
@@ -3407,6 +3418,10 @@ class EndpointContext {
3407
3418
  /* */
3408
3419
  /* */
3409
3420
  /* */
3421
+ /* */
3422
+ /* */
3423
+ /* */
3424
+ /* */
3410
3425
  return (void 0);
3411
3426
  }
3412
3427
  //#endregion
@@ -3645,7 +3660,7 @@ class EndpointContext {
3645
3660
  //#endregion
3646
3661
  //#region methods & getters / init classes
3647
3662
  async initClasses() {
3648
- if (this.remoteHost) {
3663
+ if (this.isRemoteHost) {
3649
3664
  return;
3650
3665
  }
3651
3666
  /* */
@@ -3711,11 +3726,7 @@ class EndpointContext {
3711
3726
  return uri;
3712
3727
  }
3713
3728
  get uri() {
3714
- const url = this.host
3715
- ? new URL(this.host)
3716
- : this.remoteHost
3717
- ? new URL(this.remoteHost)
3718
- : void 0;
3729
+ const url = this.host ? new URL(this.host) : void 0;
3719
3730
  return url;
3720
3731
  }
3721
3732
  //#endregion
@@ -3783,11 +3794,50 @@ class EndpointContext {
3783
3794
  }
3784
3795
  //#endregion
3785
3796
  //#region methods & getters / public assets
3797
+ get isRemoteHost() {
3798
+ return !!this.cloneOptions?.useAsRemoteContext;
3799
+ }
3800
+ //#endregion
3801
+ //#region methods & getters / public assets
3786
3802
  /**
3787
3803
  * ipc/udp needs this
3788
3804
  */
3789
3805
  get contextName() {
3790
- return this.config.contextName;
3806
+ // console.log(this.originalConfig);
3807
+ return this.config?.contextName || this.originalConfig?.contextName;
3808
+ }
3809
+ //#endregion
3810
+ //#region methods & getters / public assets
3811
+ /**
3812
+ * ipc/udp needs this
3813
+ */
3814
+ get contextNameForCommunication() {
3815
+ let contextName = this.contextName;
3816
+ if (this.isRemoteHost) {
3817
+ if (this.sourceContext?.contextName) {
3818
+ contextName = this.sourceContext?.contextName;
3819
+ }
3820
+ else {
3821
+ // console.log(
3822
+ // `CANT GET SOURCE CONTEXT NAME FOR REMOTE CONTEXT ${this.contextName}`,
3823
+ // );
3824
+ }
3825
+ }
3826
+ return contextName;
3827
+ }
3828
+ //#endregion
3829
+ //#region methods & getters / public assets
3830
+ /**
3831
+ * Check context type
3832
+ */
3833
+ get contextType() {
3834
+ if (this.config.abstract) {
3835
+ return 'abstract';
3836
+ }
3837
+ if (this.host) {
3838
+ return this.isRemoteHost ? 'remote' : 'normal';
3839
+ }
3840
+ return 'invalid';
3791
3841
  }
3792
3842
  //#endregion
3793
3843
  //#region methods & getters / current working directory
@@ -3815,11 +3865,6 @@ class EndpointContext {
3815
3865
  return this.config.productionMode;
3816
3866
  }
3817
3867
  //#endregion
3818
- //#region methods & getters / remote host
3819
- get remoteHost() {
3820
- return this.config.remoteHost;
3821
- }
3822
- //#endregion
3823
3868
  //#region methods & getters / host
3824
3869
  get host() {
3825
3870
  return this.config.host;
@@ -4034,12 +4079,13 @@ class EndpointContext {
4034
4079
  return bc.className;
4035
4080
  })
4036
4081
  .join('/');
4082
+ const contextNameForCommunication = this.contextNameForCommunication;
4037
4083
  if (TaonHelpers.isGoodPath(classConfig.path)) {
4038
4084
  classConfig.calculatedPath = classConfig.path;
4039
4085
  }
4040
4086
  else {
4041
4087
  classConfig.calculatedPath = (`${this.uriPathnameOrNothingIfRoot}` +
4042
- `/${apiPrefix}/${this.contextName}/tcp${parentsCalculatedPath}/` +
4088
+ `/${apiPrefix}/${contextNameForCommunication}/tcp${parentsCalculatedPath}/` +
4043
4089
  `${ClassHelpers.getName(controllerClassFn)}`)
4044
4090
  .replace(/\/\//g, '/')
4045
4091
  .split('/')
@@ -4069,7 +4115,7 @@ class EndpointContext {
4069
4115
  });
4070
4116
  }
4071
4117
  //#endregion
4072
- async initControllersHook(allInitedEndpointContexts) {
4118
+ async initControllersHook(ctxStorage) {
4073
4119
  if (this.isRunOrRevertOnlyMigrationAppStart) {
4074
4120
  return;
4075
4121
  }
@@ -4077,7 +4123,7 @@ class EndpointContext {
4077
4123
  for (const controllerClassFn of allControllers) {
4078
4124
  const instance = this.getInstanceBy(controllerClassFn);
4079
4125
  if (_.isFunction(instance.afterAllCtxInited)) {
4080
- await instance.afterAllCtxInited(allInitedEndpointContexts);
4126
+ await instance.afterAllCtxInited({ ctxStorage });
4081
4127
  }
4082
4128
  }
4083
4129
  }
@@ -4182,7 +4228,7 @@ class EndpointContext {
4182
4228
  }
4183
4229
  //#endregion
4184
4230
  //#region init client
4185
- const shouldInitClient = Helpers.isBrowser || this.remoteHost || Helpers.isWebSQL;
4231
+ const shouldInitClient = Helpers.isBrowser || this.isRemoteHost || Helpers.isWebSQL;
4186
4232
  // console.log('shouldInitClient', shouldInitClient);
4187
4233
  if (shouldInitClient) {
4188
4234
  // console.log(
@@ -4209,7 +4255,7 @@ class EndpointContext {
4209
4255
  //#endregion
4210
4256
  //#region methods & getters / write active routes
4211
4257
  writeActiveRoutes() {
4212
- if (this.remoteHost ||
4258
+ if (this.isRemoteHost ||
4213
4259
  this.isRunOrRevertOnlyMigrationAppStart ||
4214
4260
  this.skipWritingServerRoutes) {
4215
4261
  return;
@@ -4498,7 +4544,7 @@ class EndpointContext {
4498
4544
  /* */
4499
4545
  /* */
4500
4546
  }
4501
- if (!this.remoteHost) {
4547
+ if (!this.isRemoteHost) {
4502
4548
  //#region apply dummy websql express routers
4503
4549
  /* */
4504
4550
  /* */
@@ -5171,6 +5217,34 @@ class TaonAdminService {
5171
5217
  logout() { }
5172
5218
  }
5173
5219
 
5220
+ class ContextsEndpointStorage {
5221
+ constructor() {
5222
+ this.taonEndpointContexts = new Map();
5223
+ // Private constructor to prevent direct instantiation
5224
+ }
5225
+ static get Instance() {
5226
+ if (!ContextsEndpointStorage.instance) {
5227
+ ContextsEndpointStorage.instance = new ContextsEndpointStorage();
5228
+ }
5229
+ return ContextsEndpointStorage.instance;
5230
+ }
5231
+ //#endregion
5232
+ set(context) {
5233
+ if (!this.taonEndpointContexts.has(context.contextName)) {
5234
+ this.taonEndpointContexts.set(context.contextName, context);
5235
+ }
5236
+ }
5237
+ get arr() {
5238
+ return Array.from(this.taonEndpointContexts.values()).filter(f => f.contextType === 'normal');
5239
+ }
5240
+ getBy(context) {
5241
+ if (typeof context === 'string') {
5242
+ return this.taonEndpointContexts.get(context);
5243
+ }
5244
+ return this.taonEndpointContexts.get(context.contextName);
5245
+ }
5246
+ }
5247
+
5174
5248
  //#region imports
5175
5249
  //#endregion
5176
5250
  /**
@@ -5187,14 +5261,15 @@ const createContextTemplate = (configFn) => {
5187
5261
  * REQURIED PROPERTY:
5188
5262
  * - contextName
5189
5263
  */
5190
- const createContext = (configFn) => {
5264
+ const createContextFn = (configFn, cloneOptions) => {
5265
+ cloneOptions = cloneOptions || {};
5191
5266
  let config = configFn({});
5192
5267
  // console.log(
5193
5268
  // `
5194
5269
  // [Taon] Creating context ${config.contextName}...`,
5195
5270
  // {config},
5196
5271
  // );
5197
- const endpointContextRef = new EndpointContext(config, configFn);
5272
+ const endpointContextRef = new EndpointContext(config, configFn, cloneOptions);
5198
5273
  const res = {
5199
5274
  //#region contexts
5200
5275
  get contextName() {
@@ -5204,6 +5279,24 @@ const createContext = (configFn) => {
5204
5279
  get appId() {
5205
5280
  return config.appId;
5206
5281
  },
5282
+ cloneAsRemote: (cloneOpt) => {
5283
+ cloneOpt = cloneOpt || {};
5284
+ const opt = {
5285
+ ...cloneOpt,
5286
+ sourceContext: endpointContextRef,
5287
+ useAsRemoteContext: true,
5288
+ };
5289
+ return createContextFn(configFn, opt);
5290
+ },
5291
+ cloneAsNormal: (cloneOpt) => {
5292
+ cloneOpt = cloneOpt || {};
5293
+ const opt = {
5294
+ ...cloneOpt,
5295
+ sourceContext: endpointContextRef,
5296
+ useAsRemoteContext: false,
5297
+ };
5298
+ return createContextFn(configFn, opt);
5299
+ },
5207
5300
  //#region context
5208
5301
  /**
5209
5302
  * @deprecated
@@ -5316,19 +5409,23 @@ const createContext = (configFn) => {
5316
5409
  //#endregion
5317
5410
  //#region run migrations tasks
5318
5411
  if (endpointContextRef.onlyMigrationRun) {
5319
- Helpers.log(`[taon] Running only migrations (context=${endpointContextRef.contextName}).`);
5412
+ endpointContextRef.logMigrations &&
5413
+ Helpers.log(`[taon] Running only migrations (context=${endpointContextRef.contextName}).`);
5320
5414
  await endpointContextRef.dbMigrations.runAllNotCompletedMigrations();
5321
5415
  }
5322
5416
  else if (endpointContextRef.onlyMigrationRevertToTimestamp) {
5323
- Helpers.log(`[taon] Reverting migrations to timestamp ${endpointContextRef.onlyMigrationRevertToTimestamp} (context=${endpointContextRef.contextName}).`);
5417
+ endpointContextRef.logMigrations &&
5418
+ Helpers.log(`[taon] Reverting migrations to timestamp ${endpointContextRef.onlyMigrationRevertToTimestamp} (context=${endpointContextRef.contextName}).`);
5324
5419
  await endpointContextRef.dbMigrations.revertMigrationToTimestamp(endpointContextRef.onlyMigrationRevertToTimestamp);
5325
5420
  }
5326
5421
  else {
5327
- Helpers.log(`[taon] Running all not applied migrations (context=${endpointContextRef.contextName}).`);
5422
+ endpointContextRef.logMigrations &&
5423
+ Helpers.log(`[taon] Running all not applied migrations (context=${endpointContextRef.contextName}).`);
5328
5424
  await endpointContextRef.dbMigrations.runAllNotCompletedMigrations();
5329
5425
  }
5330
5426
  //#endregion
5331
5427
  }
5428
+ ContextsEndpointStorage.Instance.set(endpointContextRef);
5332
5429
  resolve(endpointContextRef);
5333
5430
  });
5334
5431
  //#endregion
@@ -5351,6 +5448,12 @@ const createContext = (configFn) => {
5351
5448
  };
5352
5449
  return res;
5353
5450
  };
5451
+ //#endregion
5452
+ const createContext = (configFn) => {
5453
+ return createContextFn(configFn, { useAsRemoteContext: false });
5454
+ };
5455
+ // const AA = createContext(() => ({ contextName: 'aa' }));
5456
+ // const BB = AA.cloneAsRemoteContext();
5354
5457
 
5355
5458
  /**
5356
5459
  * Provider decorator
@@ -6404,14 +6507,12 @@ function Body(name) {
6404
6507
  };
6405
6508
  }
6406
6509
 
6407
- /* */
6408
- /* */
6409
6510
  let BaseController = class BaseController extends BaseInjector {
6410
6511
  /**
6411
6512
  * Hook that is called when taon app is inited
6412
6513
  * (all contexts are created and inited)
6413
6514
  */
6414
- async afterAllCtxInited(allContexts) { }
6515
+ async afterAllCtxInited(options) { }
6415
6516
  //#region upload form data to server
6416
6517
  uploadFormDataToServer(formData) {
6417
6518
  /* */
@@ -7091,5 +7192,5 @@ var Taon;
7091
7192
  * Generated bundle index. Do not edit.
7092
7193
  */
7093
7194
 
7094
- 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 };
7195
+ 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 };
7095
7196
  //# sourceMappingURL=taon.mjs.map