@rsdk/core 3.5.0-next.7 → 3.5.0-next.9

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 (36) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/config/config.module.d.ts +5 -0
  3. package/dist/config/config.module.js.map +1 -1
  4. package/dist/config/context/config.context.js +5 -1
  5. package/dist/config/context/config.context.js.map +1 -1
  6. package/dist/config/exceptions/app-name-strategy-validation.exception.d.ts +4 -0
  7. package/dist/config/exceptions/app-name-strategy-validation.exception.js +30 -0
  8. package/dist/config/exceptions/app-name-strategy-validation.exception.js.map +1 -0
  9. package/dist/config/exceptions/index.d.ts +2 -1
  10. package/dist/config/exceptions/index.js +2 -1
  11. package/dist/config/exceptions/index.js.map +1 -1
  12. package/dist/config/strategy/app-name-strategy/legacy.app-name-strategy.d.ts +6 -0
  13. package/dist/config/strategy/app-name-strategy/legacy.app-name-strategy.js +12 -0
  14. package/dist/config/strategy/app-name-strategy/legacy.app-name-strategy.js.map +1 -0
  15. package/dist/config/strategy/app-name-strategy/platform.app-name-strategy.d.ts +6 -0
  16. package/dist/config/strategy/app-name-strategy/platform.app-name-strategy.js +12 -0
  17. package/dist/config/strategy/app-name-strategy/platform.app-name-strategy.js.map +1 -0
  18. package/dist/config/strategy/app-name-strategy.validator.d.ts +3 -0
  19. package/dist/config/strategy/app-name-strategy.validator.js +14 -0
  20. package/dist/config/strategy/app-name-strategy.validator.js.map +1 -0
  21. package/dist/config/types.d.ts +8 -0
  22. package/dist/config/types.js +6 -0
  23. package/dist/config/types.js.map +1 -1
  24. package/dist/config/vars.class.d.ts +11 -2
  25. package/dist/config/vars.class.js +48 -5
  26. package/dist/config/vars.class.js.map +1 -1
  27. package/package.json +2 -2
  28. package/src/config/config.module.ts +6 -0
  29. package/src/config/context/config.context.ts +6 -1
  30. package/src/config/exceptions/app-name-strategy-validation.exception.ts +16 -0
  31. package/src/config/exceptions/index.ts +2 -1
  32. package/src/config/strategy/app-name-strategy/legacy.app-name-strategy.ts +10 -0
  33. package/src/config/strategy/app-name-strategy/platform.app-name-strategy.ts +10 -0
  34. package/src/config/strategy/app-name-strategy.validator.ts +12 -0
  35. package/src/config/types.ts +10 -0
  36. package/src/config/vars.class.ts +88 -6
package/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.5.0-next.9](https://github.com/R-Vision/rsdk/compare/v3.5.0-next.8...v3.5.0-next.9) (2023-10-03)
7
+
8
+ ### Features
9
+
10
+ * **core.config:** PFM-514 Append property name strategy ([#129](https://github.com/R-Vision/rsdk/issues/129)) ([427bde6](https://github.com/R-Vision/rsdk/commit/427bde6a0f2cc90ae1e47e2ceb2f3dc35432947e))
11
+
6
12
  ## [3.5.0-next.7](https://github.com/R-Vision/rsdk/compare/v3.5.0-next.6...v3.5.0-next.7) (2023-10-02)
7
13
 
8
14
  **Note:** Version bump only for package @rsdk/core
@@ -3,6 +3,7 @@ import type { Constructor } from '@rsdk/common';
3
3
  import type { PlatformOptions } from '../types';
4
4
  import type { Config } from './config.abstract';
5
5
  import type { ConfigSource } from './sources';
6
+ import type { AppNameStrategyType } from './types';
6
7
  export interface ConfigModuleOptions {
7
8
  /**
8
9
  * By convention every configuration key should have unique prefix
@@ -14,6 +15,10 @@ export interface ConfigModuleOptions {
14
15
  * that loads configuration from Consul or other remote system.
15
16
  */
16
17
  sources?: Constructor<ConfigSource>[];
18
+ /**
19
+ * Strategy for detect key name for get config values from environments (default: AppNameStrategyType.PLATFORM)
20
+ */
21
+ appNameStrategy?: AppNameStrategyType;
17
22
  }
18
23
  export declare class PlatformConfigModule {
19
24
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"config.module.js","sourceRoot":"","sources":["../../src/config/config.module.ts"],"names":[],"mappings":";;;AAKA,qGAAgG;AAChG,2FAAsF;AACtF,6DAAyD;A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aAA4B,EAC5B,iCAA+D,EAC/D,EAAE;gBACF;;mBAEG;gBACH,MAAM,iCAAiC,EAAE,UAAU,EAAE,CAAC;gBACtD,OAAO,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACrC,CAAC;SACF,CAAC;QAEF,OAAO;YACL;;;;eAIG;YACH,MAAM,EAAE,oBAAoB;YAC5B,SAAS,EAAE,CAAC,QAAQ,CAAC;YAErB,OAAO,EAAE,CAAC,QAAQ,CAAC;SACpB,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,OAAwB;QACrC,MAAM,SAAS,GAAe,EAAE,CAAC;QACjC,MAAM,OAAO,GAA+C,EAAE,CAAC;QAE/D,IAAI,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE;YAC3B,OAAO,CAAC,IAAI,CAAC,iDAAsB,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;SACvE;QAED,OAAO;YACL,MAAM,EAAE,IAAI;YACZ,OAAO;YACP,MAAM,EAAE,oBAAoB;YAC5B,SAAS;YACT,OAAO,EAAE,SAAS;SACnB,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,mBAAmB,CAChC,KAA6C;QAE7C,OAAO;YACL,MAAM,EAAE;gBACN,8BAAa;gBACb,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,2DAA2B,EAAE;aACvD;YACD,OAAO,EAAE,KAAK;YACd,UAAU,EAAE,KAAK,EACf,aAA4B,EAC5B,iCAA+D,EACvC,EAAE;gBAC1B,MAAM,iCAAiC,EAAE,UAAU,EAAE,CAAC;gBACtD,OAAO,aAAa,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;YAC9C,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AApGD,oDAoGC"}
@@ -10,6 +10,7 @@ const exceptions_1 = require("../exceptions");
10
10
  const metadata_1 = require("../metadata");
11
11
  const config_metadata_provider_1 = require("../metadata/config-metadata.provider");
12
12
  const reload_1 = require("../reload");
13
+ const app_name_strategy_validator_1 = require("../strategy/app-name-strategy.validator");
13
14
  const vars_class_1 = require("../vars.class");
14
15
  class ConfigContext {
15
16
  events = new reload_1.ReloadEvents();
@@ -48,6 +49,9 @@ class ConfigContext {
48
49
  */
49
50
  logger = logging_1.LoggerFactory.create('PlatformConfigModule');
50
51
  constructor(rsdkMetadataProvider, options) {
52
+ if (options?.appNameStrategy) {
53
+ (0, app_name_strategy_validator_1.assertAppNameStrategyType)(options.appNameStrategy);
54
+ }
51
55
  /**
52
56
  * Should be invoked BEFORE bootstrapping nest application.
53
57
  *
@@ -66,7 +70,7 @@ class ConfigContext {
66
70
  prefix: this.prefix,
67
71
  });
68
72
  }
69
- this.vars = new vars_class_1.Vars(this.prefix);
73
+ this.vars = new vars_class_1.Vars(this.prefix, options?.appNameStrategy);
70
74
  this.readEnvironment();
71
75
  const properties = new config_metadata_provider_1.ConfigMetadataProvider(rsdkMetadataProvider).getPropertiesMap();
72
76
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"config.context.js","sourceRoot":"","sources":["../../../src/config/context/config.context.ts"],"names":[],"mappings":";;;;;;AASA,2CAA8C;AAE9C,oDAA4B;AAI5B,8CAA+D;AAE/D,0CAA+C;AAC/C,mFAA8E;AAC9E,sCAAyC;AAEzC,8CAAqC;AAErC,MAAa,aAAa;IACf,MAAM,GAAG,IAAI,qBAAY,EAAE,CAAC;IAC5B,IAAI,CAAO;IACX,MAAM,CAAS;IAExB;;;;;;;;;;;;;;;OAeG;IACM,0BAA0B,GAAG,IAAI,GAAG,EAA4B,CAAC;IAE1E;;;OAGG;IACc,kBAAkB,GAAG,IAAI,GAAG,EAA+B,CAAC;IAE7E;;;OAGG;IACc,UAAU,GAAG,IAAI,GAAG,EAAsB,CAAC;IAE5D;;;OAGG;IACc,MAAM,GAAG,uBAAa,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC;IAEvE,YACE,oBAA0C,EAC1C,OAA6B;QAE7B;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A6C,EAAE;YAC/D,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;YAC3B,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzB,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AArLD,sCAqLC"}
1
+ {"version":3,"file":"config.context.js","sourceRoot":"","sources":["../../../src/config/context/config.context.ts"],"names":[],"mappings":";;;;;;AASA,2CAA8C;AAE9C,oDAA4B;AAI5B,8CAA+D;AAE/D,0CAA+C;AAC/C,mFAA8E;AAC9E,sCAAyC;AACzC,yFAAoF;AAEpF,8CAAqC;AAErC,MAAa,aAAa;IACf,MAAM,GAAG,IAAI,qBAAY,EAAE,CAAC;IAC5B,IAAI,CAAO;IACX,MAAM,CAAS;IAExB;;;;;;;;;;;;;;;OAeG;IACM,0BAA0B,GAAG,IAAI,GAAG,EAA4B,CAAC;IAE1E;;;OAGG;IACc,kBAAkB,GAAG,IAAI,GAAG,EAA+B,CAAC;IAE7E;;;OAGG;IACc,UAAU,GAAG,IAAI,GAAG,EAAsB,CAAC;IAE5D;;;OAGG;IACc,MAAM,GAAG,uBAAa,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC;IAEvE,YACE,oBAA0C,EAC1C,OAA6B;QAE7B,IAAI,OAAO,EAAE,eAAe,EAAE;YAC5B,IAAA,uDAAyB,EAAC,OAAO,CAAC,eAAe,CAAC,CAAC;SACpD;QAED;;;;;;;;;;;WAWG;QACH,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC;QAErC,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mCAAmC,EAAE;gBACpD,MAA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AAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzB,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAzLD,sCAyLC"}
@@ -0,0 +1,4 @@
1
+ import { BootstrapException } from '../../exceptions';
2
+ export declare class InvalidAppNameStrategyException extends BootstrapException {
3
+ constructor();
4
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.InvalidAppNameStrategyException = void 0;
13
+ const common_1 = require("@rsdk/common");
14
+ const exceptions_1 = require("../../exceptions");
15
+ let InvalidAppNameStrategyException = exports.InvalidAppNameStrategyException = class InvalidAppNameStrategyException extends exceptions_1.BootstrapException {
16
+ constructor() {
17
+ super((0, common_1.text) `
18
+ Options "appNameStrategy" has wrong value.
19
+ `);
20
+ }
21
+ };
22
+ exports.InvalidAppNameStrategyException = InvalidAppNameStrategyException = __decorate([
23
+ (0, exceptions_1.Exception)({
24
+ description: (0, common_1.text) `
25
+ Options "appNameStrategy" has wrong value.
26
+ `,
27
+ }),
28
+ __metadata("design:paramtypes", [])
29
+ ], InvalidAppNameStrategyException);
30
+ //# sourceMappingURL=app-name-strategy-validation.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-name-strategy-validation.exception.js","sourceRoot":"","sources":["../../../src/config/exceptions/app-name-strategy-validation.exception.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAoC;AAEpC,iDAAiE;AAO1D,IAAM,+BAA+B,6CAArC,MAAM,+BAAgC,SAAQ,+BAAkB;IACrE;QACE,KAAK,CAAC,IAAA,aAAI,EAAA;;KAET,CAAC,CAAC;IACL,CAAC;CACF,CAAA;0CANY,+BAA+B;IAL3C,IAAA,sBAAS,EAAC;QACT,WAAW,EAAE,IAAA,aAAI,EAAA;;GAEhB;KACF,CAAC;;GACW,+BAA+B,CAM3C"}
@@ -1,3 +1,4 @@
1
1
  export * from './config-not-bootstrapped.exception';
2
- export * from './property.exception';
3
2
  export { ConfigPropertyMetadataNotFound } from './config-property-metadata-not-found';
3
+ export * from './app-name-strategy-validation.exception';
4
+ export * from './property.exception';
@@ -16,7 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.ConfigPropertyMetadataNotFound = void 0;
18
18
  __exportStar(require("./config-not-bootstrapped.exception"), exports);
19
- __exportStar(require("./property.exception"), exports);
20
19
  var config_property_metadata_not_found_1 = require("./config-property-metadata-not-found");
21
20
  Object.defineProperty(exports, "ConfigPropertyMetadataNotFound", { enumerable: true, get: function () { return config_property_metadata_not_found_1.ConfigPropertyMetadataNotFound; } });
21
+ __exportStar(require("./app-name-strategy-validation.exception"), exports);
22
+ __exportStar(require("./property.exception"), exports);
22
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/exceptions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,sEAAoD;AACpD,uDAAqC;AACrC,2FAAsF;AAA7E,oJAAA,8BAA8B,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/exceptions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,sEAAoD;AACpD,2FAAsF;AAA7E,oJAAA,8BAA8B,OAAA;AACvC,2EAAyD;AACzD,uDAAqC"}
@@ -0,0 +1,6 @@
1
+ import type { AppNameStrategy } from '../../types';
2
+ import { AppNameStrategyType } from '../../types';
3
+ export declare class LegacyAppNameStrategy implements AppNameStrategy {
4
+ type: AppNameStrategyType;
5
+ transform(appName: string): string;
6
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LegacyAppNameStrategy = void 0;
4
+ const types_1 = require("../../types");
5
+ class LegacyAppNameStrategy {
6
+ type = types_1.AppNameStrategyType.LEGACY;
7
+ transform(appName) {
8
+ return appName.split('.').slice(1).join('.');
9
+ }
10
+ }
11
+ exports.LegacyAppNameStrategy = LegacyAppNameStrategy;
12
+ //# sourceMappingURL=legacy.app-name-strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy.app-name-strategy.js","sourceRoot":"","sources":["../../../../src/config/strategy/app-name-strategy/legacy.app-name-strategy.ts"],"names":[],"mappings":";;;AACA,uCAAkD;AAElD,MAAa,qBAAqB;IAChC,IAAI,GAAG,2BAAmB,CAAC,MAAM,CAAC;IAElC,SAAS,CAAC,OAAe;QACvB,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/C,CAAC;CACF;AAND,sDAMC"}
@@ -0,0 +1,6 @@
1
+ import type { AppNameStrategy } from '../../types';
2
+ import { AppNameStrategyType } from '../../types';
3
+ export declare class PlatformAppNameStrategy implements AppNameStrategy {
4
+ type: AppNameStrategyType;
5
+ transform(appName: string): string;
6
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlatformAppNameStrategy = void 0;
4
+ const types_1 = require("../../types");
5
+ class PlatformAppNameStrategy {
6
+ type = types_1.AppNameStrategyType.PLATFORM;
7
+ transform(appName) {
8
+ return appName;
9
+ }
10
+ }
11
+ exports.PlatformAppNameStrategy = PlatformAppNameStrategy;
12
+ //# sourceMappingURL=platform.app-name-strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.app-name-strategy.js","sourceRoot":"","sources":["../../../../src/config/strategy/app-name-strategy/platform.app-name-strategy.ts"],"names":[],"mappings":";;;AACA,uCAAkD;AAElD,MAAa,uBAAuB;IAClC,IAAI,GAAG,2BAAmB,CAAC,QAAQ,CAAC;IAEpC,SAAS,CAAC,OAAe;QACvB,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAND,0DAMC"}
@@ -0,0 +1,3 @@
1
+ import { AppNameStrategyType } from '../types';
2
+ export declare const isValidAppNameStrategyType: (value: string | AppNameStrategyType) => boolean;
3
+ export declare const assertAppNameStrategyType: (value: AppNameStrategyType) => void;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertAppNameStrategyType = exports.isValidAppNameStrategyType = void 0;
4
+ const app_name_strategy_validation_exception_1 = require("../exceptions/app-name-strategy-validation.exception");
5
+ const types_1 = require("../types");
6
+ const isValidAppNameStrategyType = (value) => value in types_1.AppNameStrategyType;
7
+ exports.isValidAppNameStrategyType = isValidAppNameStrategyType;
8
+ const assertAppNameStrategyType = (value) => {
9
+ if (!(0, exports.isValidAppNameStrategyType)(value)) {
10
+ throw new app_name_strategy_validation_exception_1.InvalidAppNameStrategyException();
11
+ }
12
+ };
13
+ exports.assertAppNameStrategyType = assertAppNameStrategyType;
14
+ //# sourceMappingURL=app-name-strategy.validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-name-strategy.validator.js","sourceRoot":"","sources":["../../../src/config/strategy/app-name-strategy.validator.ts"],"names":[],"mappings":";;;AAAA,iHAAuG;AACvG,oCAA+C;AAExC,MAAM,0BAA0B,GAAG,CACxC,KAAmC,EAC1B,EAAE,CAAC,KAAK,IAAI,2BAAmB,CAAC;AAF9B,QAAA,0BAA0B,8BAEI;AAEpC,MAAM,yBAAyB,GAAG,CAAC,KAA0B,EAAQ,EAAE;IAC5E,IAAI,CAAC,IAAA,kCAA0B,EAAC,KAAK,CAAC,EAAE;QACtC,MAAM,IAAI,wEAA+B,EAAE,CAAC;KAC7C;AACH,CAAC,CAAC;AAJW,QAAA,yBAAyB,6BAIpC"}
@@ -65,3 +65,11 @@ export interface PropertyParser<T = any> {
65
65
  parse(value: unknown): T;
66
66
  }
67
67
  export type RawValues = Map<string, unknown>;
68
+ export declare enum AppNameStrategyType {
69
+ LEGACY = "LEGACY",
70
+ PLATFORM = "PLATFORM"
71
+ }
72
+ export interface AppNameStrategy {
73
+ type: AppNameStrategyType;
74
+ transform(appName: string): string;
75
+ }
@@ -1,3 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppNameStrategyType = void 0;
4
+ var AppNameStrategyType;
5
+ (function (AppNameStrategyType) {
6
+ AppNameStrategyType["LEGACY"] = "LEGACY";
7
+ AppNameStrategyType["PLATFORM"] = "PLATFORM";
8
+ })(AppNameStrategyType || (exports.AppNameStrategyType = AppNameStrategyType = {}));
3
9
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":";;;AA8EA,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC7B,wCAAiB,CAAA;IACjB,4CAAqB,CAAA;AACvB,CAAC,EAHW,mBAAmB,mCAAnB,mBAAmB,QAG9B"}
@@ -1,4 +1,4 @@
1
- import type { Changes, PropertyMetadata, RawValues } from './types';
1
+ import { AppNameStrategyType, type Changes, type PropertyMetadata, type RawValues } from './types';
2
2
  export declare enum SetResult {
3
3
  CREATED = 0,
4
4
  UPDATED = 1,
@@ -6,13 +6,22 @@ export declare enum SetResult {
6
6
  }
7
7
  export declare class Vars {
8
8
  private readonly prefix;
9
+ private readonly appNameStrategyType?;
9
10
  private readonly values;
11
+ private readonly appNameStrategies;
12
+ /**
13
+ * We don't use class as context here because it is undefined if
14
+ * tsc target is ES2022
15
+ */
16
+ private readonly logger;
10
17
  /**
11
18
  * Expecting prefix is already converted to upper snake case
12
19
  * @param prefix
13
20
  */
14
- constructor(prefix: string);
21
+ constructor(prefix: string, appNameStrategyType?: AppNameStrategyType | undefined);
15
22
  set(key: string, value: unknown): [SetResult, string];
16
23
  merge(values: RawValues): Changes;
17
24
  extract<T>(propertyMetadata: PropertyMetadata<T>): T | undefined;
25
+ private getEnvironmentValueWithAppNameStrategyFromConfig;
26
+ private getEnvironmentValueWithPlatformAppNameStrategy;
18
27
  }
@@ -2,8 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Vars = exports.SetResult = void 0;
4
4
  const common_1 = require("@rsdk/common");
5
+ const logging_1 = require("@rsdk/logging");
5
6
  const lodash_1 = require("lodash");
7
+ const legacy_app_name_strategy_1 = require("./strategy/app-name-strategy/legacy.app-name-strategy");
8
+ const platform_app_name_strategy_1 = require("./strategy/app-name-strategy/platform.app-name-strategy");
6
9
  const exceptions_1 = require("./exceptions");
10
+ const types_1 = require("./types");
7
11
  var SetResult;
8
12
  (function (SetResult) {
9
13
  SetResult[SetResult["CREATED"] = 0] = "CREATED";
@@ -12,13 +16,24 @@ var SetResult;
12
16
  })(SetResult || (exports.SetResult = SetResult = {}));
13
17
  class Vars {
14
18
  prefix;
19
+ appNameStrategyType;
15
20
  values = new Map();
21
+ appNameStrategies = [
22
+ new legacy_app_name_strategy_1.LegacyAppNameStrategy(),
23
+ new platform_app_name_strategy_1.PlatformAppNameStrategy(),
24
+ ];
25
+ /**
26
+ * We don't use class as context here because it is undefined if
27
+ * tsc target is ES2022
28
+ */
29
+ logger = logging_1.LoggerFactory.create('Vars');
16
30
  /**
17
31
  * Expecting prefix is already converted to upper snake case
18
32
  * @param prefix
19
33
  */
20
- constructor(prefix) {
34
+ constructor(prefix, appNameStrategyType) {
21
35
  this.prefix = prefix;
36
+ this.appNameStrategyType = appNameStrategyType;
22
37
  }
23
38
  set(key, value) {
24
39
  const preparedKey = common_1.Case.toUpperSnake(key);
@@ -55,10 +70,19 @@ class Vars {
55
70
  extract(propertyMetadata) {
56
71
  const { key, parser, defaultValue } = propertyMetadata;
57
72
  const preparedKey = common_1.Case.toUpperSnake(key);
58
- const withPrefix = this.prefix
59
- ? `${common_1.Case.toUpperSnake(this.prefix)}_${preparedKey}`
60
- : preparedKey;
61
- const raw = this.values.get(withPrefix) ?? this.values.get(preparedKey);
73
+ const { platformEnvironmentValue, platformEnvironmentKey } = this.getEnvironmentValueWithPlatformAppNameStrategy(preparedKey);
74
+ const { appNameStrategy, appEnvironmentValue, appEnvironmentKey } = this.getEnvironmentValueWithAppNameStrategyFromConfig(preparedKey);
75
+ let raw;
76
+ if (platformEnvironmentValue !== undefined) {
77
+ raw = platformEnvironmentValue;
78
+ }
79
+ if (appEnvironmentValue !== undefined) {
80
+ raw = appEnvironmentValue;
81
+ this.logger.warn(`You are using the "${appNameStrategy.type}" format for naming environment variables, for "${appEnvironmentKey}", you should use the "${platformEnvironmentKey}"`);
82
+ }
83
+ if (raw === undefined) {
84
+ raw = this.values.get(preparedKey);
85
+ }
62
86
  if (raw === undefined) {
63
87
  // Важная проверка на то что поле там вообще было
64
88
  if ('defaultValue' in propertyMetadata) {
@@ -79,6 +103,25 @@ class Vars {
79
103
  });
80
104
  }
81
105
  }
106
+ getEnvironmentValueWithAppNameStrategyFromConfig(preparedKey) {
107
+ const appNameStrategy = this.appNameStrategies.find((s) => s.type === this.appNameStrategyType);
108
+ if (appNameStrategy) {
109
+ const appEnvironmentKey = `${common_1.Case.toUpperSnake(appNameStrategy.transform(this.prefix))}_${preparedKey}`;
110
+ const appEnvironmentValue = this.values.get(appEnvironmentKey);
111
+ return { appNameStrategy, appEnvironmentKey, appEnvironmentValue };
112
+ }
113
+ return {
114
+ appNameStrategy,
115
+ appEnvironmentKey: undefined,
116
+ appEnvironmentValue: undefined,
117
+ };
118
+ }
119
+ getEnvironmentValueWithPlatformAppNameStrategy(preparedKey) {
120
+ const platformAppNameStrategy = this.appNameStrategies.find((s) => s.type === types_1.AppNameStrategyType.PLATFORM);
121
+ const platformEnvironmentKey = `${common_1.Case.toUpperSnake(platformAppNameStrategy.transform(this.prefix))}_${preparedKey}`;
122
+ const platformEnvironmentValue = this.values.get(platformEnvironmentKey);
123
+ return { platformEnvironmentValue, platformEnvironmentKey };
124
+ }
82
125
  }
83
126
  exports.Vars = Vars;
84
127
  //# sourceMappingURL=vars.class.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"vars.class.js","sourceRoot":"","sources":["../../src/config/vars.class.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AACpC,mCAA4C;AAE5C,6CAAiD;AAGjD,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,+CAAO,CAAA;IACP,+CAAO,CAAA;IACP,mDAAS,CAAA;AACX,CAAC,EAJW,SAAS,yBAAT,SAAS,QAIpB;AAED,MAAa,IAAI;IAOc;IANZ,MAAM,GAAG,IAAI,GAAG,EAAmB,CAAC;IAErD;;;OAGG;IACH,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAE/C,GAAG,CAAC,GAAW,EAAE,KAAc;QAC7B,MAAM,WAAW,GAAG,aAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QAC3C,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YACxC,CAAC,CAAC,IAAA,kBAAS,EAAC,KAAK,CAAC,CAAC,IAAI,EAAE;YACzB,CAAC,CAAC,KAAK,CAAC;QAEV,MAAM,QAAQ,GAAG,IAAI,CAA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I,WAAW,EAAE,CAAC;QAEnB,MAAM,wBAAwB,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;QAEzE,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,CAAC;IAC9D,CAAC;CACF;AA9JD,oBA8JC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdk/core",
3
- "version": "3.5.0-next.7",
3
+ "version": "3.5.0-next.9",
4
4
  "description": "Nestjs based microservice chassis",
5
5
  "license": "Apache License 2.0",
6
6
  "publishConfig": {
@@ -43,5 +43,5 @@
43
43
  "reflect-metadata": "^0.1.13",
44
44
  "rxjs": "^7.0.0"
45
45
  },
46
- "gitHead": "d45507843068602defe1eabcd11a918aaa837d39"
46
+ "gitHead": "39d1919e0ae2fbb4f637bd7dcb3a74eede698c19"
47
47
  }
@@ -9,6 +9,7 @@ import { ConfigContext } from './context/config.context';
9
9
  import type { Config } from './config.abstract';
10
10
  import { getPropertyToken } from './metadata';
11
11
  import type { ConfigSource } from './sources';
12
+ import type { AppNameStrategyType } from './types';
12
13
 
13
14
  export interface ConfigModuleOptions {
14
15
  /**
@@ -22,6 +23,11 @@ export interface ConfigModuleOptions {
22
23
  * that loads configuration from Consul or other remote system.
23
24
  */
24
25
  sources?: Constructor<ConfigSource>[];
26
+
27
+ /**
28
+ * Strategy for detect key name for get config values from environments (default: AppNameStrategyType.PLATFORM)
29
+ */
30
+ appNameStrategy?: AppNameStrategyType;
25
31
  }
26
32
 
27
33
  export class PlatformConfigModule {
@@ -18,6 +18,7 @@ import type { PropertyToken } from '../metadata';
18
18
  import { getPropertyToken } from '../metadata';
19
19
  import { ConfigMetadataProvider } from '../metadata/config-metadata.provider';
20
20
  import { ReloadEvents } from '../reload';
21
+ import { assertAppNameStrategyType } from '../strategy/app-name-strategy.validator';
21
22
  import type { PropertyMetadata } from '../types';
22
23
  import { Vars } from '../vars.class';
23
24
 
@@ -66,6 +67,10 @@ export class ConfigContext {
66
67
  rsdkMetadataProvider: RsdkMetadataProvider,
67
68
  options?: ConfigModuleOptions,
68
69
  ) {
70
+ if (options?.appNameStrategy) {
71
+ assertAppNameStrategyType(options.appNameStrategy);
72
+ }
73
+
69
74
  /**
70
75
  * Should be invoked BEFORE bootstrapping nest application.
71
76
  *
@@ -86,7 +91,7 @@ export class ConfigContext {
86
91
  });
87
92
  }
88
93
 
89
- this.vars = new Vars(this.prefix);
94
+ this.vars = new Vars(this.prefix, options?.appNameStrategy);
90
95
 
91
96
  this.readEnvironment();
92
97
 
@@ -0,0 +1,16 @@
1
+ import { text } from '@rsdk/common';
2
+
3
+ import { BootstrapException, Exception } from '../../exceptions';
4
+
5
+ @Exception({
6
+ description: text`
7
+ Options "appNameStrategy" has wrong value.
8
+ `,
9
+ })
10
+ export class InvalidAppNameStrategyException extends BootstrapException {
11
+ constructor() {
12
+ super(text`
13
+ Options "appNameStrategy" has wrong value.
14
+ `);
15
+ }
16
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './config-not-bootstrapped.exception';
2
- export * from './property.exception';
3
2
  export { ConfigPropertyMetadataNotFound } from './config-property-metadata-not-found';
3
+ export * from './app-name-strategy-validation.exception';
4
+ export * from './property.exception';
@@ -0,0 +1,10 @@
1
+ import type { AppNameStrategy } from '../../types';
2
+ import { AppNameStrategyType } from '../../types';
3
+
4
+ export class LegacyAppNameStrategy implements AppNameStrategy {
5
+ type = AppNameStrategyType.LEGACY;
6
+
7
+ transform(appName: string): string {
8
+ return appName.split('.').slice(1).join('.');
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { AppNameStrategy } from '../../types';
2
+ import { AppNameStrategyType } from '../../types';
3
+
4
+ export class PlatformAppNameStrategy implements AppNameStrategy {
5
+ type = AppNameStrategyType.PLATFORM;
6
+
7
+ transform(appName: string): string {
8
+ return appName;
9
+ }
10
+ }
@@ -0,0 +1,12 @@
1
+ import { InvalidAppNameStrategyException } from '../exceptions/app-name-strategy-validation.exception';
2
+ import { AppNameStrategyType } from '../types';
3
+
4
+ export const isValidAppNameStrategyType = (
5
+ value: string | AppNameStrategyType,
6
+ ): boolean => value in AppNameStrategyType;
7
+
8
+ export const assertAppNameStrategyType = (value: AppNameStrategyType): void => {
9
+ if (!isValidAppNameStrategyType(value)) {
10
+ throw new InvalidAppNameStrategyException();
11
+ }
12
+ };
@@ -75,3 +75,13 @@ export interface PropertyParser<T = any> {
75
75
  }
76
76
 
77
77
  export type RawValues = Map<string, unknown>;
78
+
79
+ export enum AppNameStrategyType {
80
+ LEGACY = 'LEGACY',
81
+ PLATFORM = 'PLATFORM',
82
+ }
83
+
84
+ export interface AppNameStrategy {
85
+ type: AppNameStrategyType;
86
+ transform(appName: string): string;
87
+ }
@@ -1,8 +1,17 @@
1
1
  import { Case } from '@rsdk/common';
2
+ import { LoggerFactory } from '@rsdk/logging';
2
3
  import { cloneDeep, isEqual } from 'lodash';
3
4
 
5
+ import { LegacyAppNameStrategy } from './strategy/app-name-strategy/legacy.app-name-strategy';
6
+ import { PlatformAppNameStrategy } from './strategy/app-name-strategy/platform.app-name-strategy';
4
7
  import { PropertyException } from './exceptions';
5
- import type { Changes, PropertyMetadata, RawValues } from './types';
8
+ import {
9
+ type AppNameStrategy,
10
+ AppNameStrategyType,
11
+ type Changes,
12
+ type PropertyMetadata,
13
+ type RawValues,
14
+ } from './types';
6
15
 
7
16
  export enum SetResult {
8
17
  CREATED,
@@ -12,12 +21,25 @@ export enum SetResult {
12
21
 
13
22
  export class Vars {
14
23
  private readonly values = new Map<string, unknown>();
24
+ private readonly appNameStrategies: AppNameStrategy[] = [
25
+ new LegacyAppNameStrategy(),
26
+ new PlatformAppNameStrategy(),
27
+ ];
28
+
29
+ /**
30
+ * We don't use class as context here because it is undefined if
31
+ * tsc target is ES2022
32
+ */
33
+ private readonly logger = LoggerFactory.create('Vars');
15
34
 
16
35
  /**
17
36
  * Expecting prefix is already converted to upper snake case
18
37
  * @param prefix
19
38
  */
20
- constructor(private readonly prefix: string) {}
39
+ constructor(
40
+ private readonly prefix: string,
41
+ private readonly appNameStrategyType?: AppNameStrategyType,
42
+ ) {}
21
43
 
22
44
  set(key: string, value: unknown): [SetResult, string] {
23
45
  const preparedKey = Case.toUpperSnake(key);
@@ -68,11 +90,27 @@ export class Vars {
68
90
  const { key, parser, defaultValue } = propertyMetadata;
69
91
  const preparedKey = Case.toUpperSnake(key);
70
92
 
71
- const withPrefix = this.prefix
72
- ? `${Case.toUpperSnake(this.prefix)}_${preparedKey}`
73
- : preparedKey;
93
+ const { platformEnvironmentValue, platformEnvironmentKey } =
94
+ this.getEnvironmentValueWithPlatformAppNameStrategy(preparedKey);
95
+ const { appNameStrategy, appEnvironmentValue, appEnvironmentKey } =
96
+ this.getEnvironmentValueWithAppNameStrategyFromConfig(preparedKey);
74
97
 
75
- const raw = this.values.get(withPrefix) ?? this.values.get(preparedKey);
98
+ let raw: unknown | undefined;
99
+
100
+ if (platformEnvironmentValue !== undefined) {
101
+ raw = platformEnvironmentValue;
102
+ }
103
+
104
+ if (appEnvironmentValue !== undefined) {
105
+ raw = appEnvironmentValue;
106
+ this.logger.warn(
107
+ `You are using the "${appNameStrategy.type}" format for naming environment variables, for "${appEnvironmentKey}", you should use the "${platformEnvironmentKey}"`,
108
+ );
109
+ }
110
+
111
+ if (raw === undefined) {
112
+ raw = this.values.get(preparedKey);
113
+ }
76
114
 
77
115
  if (raw === undefined) {
78
116
  // Важная проверка на то что поле там вообще было
@@ -95,4 +133,48 @@ export class Vars {
95
133
  });
96
134
  }
97
135
  }
136
+
137
+ private getEnvironmentValueWithAppNameStrategyFromConfig(
138
+ preparedKey: string,
139
+ ): {
140
+ appNameStrategy: AppNameStrategy;
141
+ appEnvironmentKey: string | undefined;
142
+ appEnvironmentValue: unknown | undefined;
143
+ } {
144
+ const appNameStrategy = this.appNameStrategies.find(
145
+ (s) => s.type === this.appNameStrategyType,
146
+ )!;
147
+
148
+ if (appNameStrategy) {
149
+ const appEnvironmentKey = `${Case.toUpperSnake(
150
+ appNameStrategy.transform(this.prefix),
151
+ )}_${preparedKey}`;
152
+
153
+ const appEnvironmentValue = this.values.get(appEnvironmentKey);
154
+
155
+ return { appNameStrategy, appEnvironmentKey, appEnvironmentValue };
156
+ }
157
+ return {
158
+ appNameStrategy,
159
+ appEnvironmentKey: undefined,
160
+ appEnvironmentValue: undefined,
161
+ };
162
+ }
163
+
164
+ private getEnvironmentValueWithPlatformAppNameStrategy(preparedKey: string): {
165
+ platformEnvironmentValue: unknown;
166
+ platformEnvironmentKey: string;
167
+ } {
168
+ const platformAppNameStrategy = this.appNameStrategies.find(
169
+ (s) => s.type === AppNameStrategyType.PLATFORM,
170
+ )!;
171
+
172
+ const platformEnvironmentKey = `${Case.toUpperSnake(
173
+ platformAppNameStrategy.transform(this.prefix),
174
+ )}_${preparedKey}`;
175
+
176
+ const platformEnvironmentValue = this.values.get(platformEnvironmentKey);
177
+
178
+ return { platformEnvironmentValue, platformEnvironmentKey };
179
+ }
98
180
  }