@rsdk/core 3.1.0-next.0 → 3.1.0-next.2

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
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.1.0-next.2](https://github.com/R-Vision/rsdk/compare/v3.1.0-next.1...v3.1.0-next.2) (2023-08-08)
7
+
8
+ ### Features
9
+
10
+ * config section without requirements `.forFeature(ctor)` ([#95](https://github.com/R-Vision/rsdk/issues/95)) ([0dfa194](https://github.com/R-Vision/rsdk/commit/0dfa1949cd48d98d784b61c21fa9d05048252734))
11
+
12
+ ## [3.1.0-next.1](https://github.com/R-Vision/rsdk/compare/v3.1.0-next.0...v3.1.0-next.1) (2023-08-08)
13
+
14
+ ### Features
15
+
16
+ * **core:** add prefix to config section decorator ([#94](https://github.com/R-Vision/rsdk/issues/94)) ([d4bd4d5](https://github.com/R-Vision/rsdk/commit/d4bd4d5e17d1431a477e6f864b3ad5408535d5c9))
17
+
6
18
  ## [3.1.0-next.0](https://github.com/R-Vision/rsdk/compare/v3.0.2...v3.1.0-next.0) (2023-08-08)
7
19
 
8
20
  **Note:** Version bump only for package @rsdk/core
@@ -5,6 +5,18 @@ export interface ConfigSectionOptions {
5
5
  * Используются только в документации
6
6
  */
7
7
  tags?: string[];
8
+ /**
9
+ * Всем полям указанным в теле будет добавлена строка
10
+ * `<PREFIX>_<PROPERTY_NAME>`
11
+ * @example
12
+ * // @ConfigSection({ prefix: 'APP_CONFIG' })
13
+ * class AppConfig extends Config {
14
+ * // @Property('FIELD', ...)
15
+ * field: string
16
+ * }
17
+ * // env -> APP_CONFIG_FIELD
18
+ */
19
+ prefix?: string;
8
20
  }
9
21
  /**
10
22
  * Sets metadata for Config class
@@ -1,19 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConfigSection = void 0;
4
+ const common_1 = require("@rsdk/common");
4
5
  const config_metadata_registry_1 = require("../config-metadata.registry");
5
6
  const property_decorator_1 = require("./property.decorator");
7
+ function getComputedMetadata(sectionMetadata, options) {
8
+ if (options?.prefix) {
9
+ const properties = Object.fromEntries(Object.entries(sectionMetadata.properties).map(([propName, propMeta]) => {
10
+ return [
11
+ propName,
12
+ {
13
+ ...propMeta,
14
+ key: common_1.Case.toUpperSnake(`${options.prefix}_${propMeta.key}`),
15
+ },
16
+ ];
17
+ }));
18
+ return {
19
+ ...sectionMetadata,
20
+ properties,
21
+ };
22
+ }
23
+ return sectionMetadata;
24
+ }
6
25
  /**
7
26
  * Sets metadata for Config class
8
27
  * @param options ConfigSectionOptions
9
28
  * @returns ClassDecorator
10
29
  */
11
30
  const ConfigSection = (options) => function (target) {
12
- const metadata = Reflect.getMetadata(property_decorator_1.CONFIG_METADATA_KEY, target);
13
- config_metadata_registry_1.ConfigMetadataRegistry.registerSection(target, {
31
+ const metadata = (Reflect.getMetadata(property_decorator_1.CONFIG_METADATA_KEY, target) ??
32
+ {});
33
+ config_metadata_registry_1.ConfigMetadataRegistry.registerSection(target, getComputedMetadata({
14
34
  ...metadata,
15
35
  ...options,
16
- });
36
+ }, options));
17
37
  };
18
38
  exports.ConfigSection = ConfigSection;
19
39
  //# sourceMappingURL=config-section.decorator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config-section.decorator.js","sourceRoot":"","sources":["../../../../src/config/metadata/decorators/config-section.decorator.ts"],"names":[],"mappings":";;;AAIA,0EAAqE;AAErE,6DAA2D;AAW3D;;;;GAIG;AACI,MAAM,aAAa,GAAG,CAAC,OAA8B,EAAkB,EAAE,CAC9E,UAAU,MAAgB;IACxB,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAClC,wCAAmB,EACnB,MAAM,CACY,CAAC;IAErB,iDAAsB,CAAC,eAAe,CAAC,MAAqB,EAAE;QAC5D,GAAG,QAAQ;QACX,GAAG,OAAO;KACX,CAAC,CAAC;AACL,CAAC,CAAC;AAXS,QAAA,aAAa,iBAWtB"}
1
+ {"version":3,"file":"config-section.decorator.js","sourceRoot":"","sources":["../../../../src/config/metadata/decorators/config-section.decorator.ts"],"names":[],"mappings":";;;AAEA,yCAAoC;AAGpC,0EAAqE;AAErE,6DAA2D;AAwB3D,SAAS,mBAAmB,CAC1B,eAAgC,EAChC,OAA8B;IAE9B,IAAI,OAAO,EAAE,MAAM,EAAE;QACnB,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CACnC,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,EAAE;YACtE,OAAO;gBACL,QAAQ;gBACR;oBACE,GAAG,QAAQ;oBACX,GAAG,EAAE,aAAI,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,QAAQ,CAAC,GAAG,EAAE,CAAC;iBAC5D;aACF,CAAC;QACJ,CAAC,CAAC,CACH,CAAC;QAEF,OAAO;YACL,GAAG,eAAe;YAClB,UAAU;SACX,CAAC;KACH;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACI,MAAM,aAAa,GAAG,CAAC,OAA8B,EAAkB,EAAE,CAC9E,UAAU,MAAgB;IACxB,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,wCAAmB,EAAE,MAAM,CAAC;QAChE,EAAE,CAAoB,CAAC;IAEzB,iDAAsB,CAAC,eAAe,CACpC,MAAqB,EACrB,mBAAmB,CACjB;QACE,GAAG,QAAQ;QACX,GAAG,OAAO;KACX,EACD,OAAO,CACR,CACF,CAAC;AACJ,CAAC,CAAC;AAfS,QAAA,aAAa,iBAetB"}
@@ -9,4 +9,4 @@ export declare const CONFIG_METADATA_KEY = "CONFIG_METADATA";
9
9
  * @param options Additional options (default value, description etc.)
10
10
  * @returns PropertyDecorator
11
11
  */
12
- export declare const Property: <T>(key: string, parser: PropertyParser<T>, options: PropertyOptions<T>) => PropertyDecorator;
12
+ export declare const Property: <T>(key: string, parser: PropertyParser<T>, options: PropertyOptions<T>) => (target: object, propertyKey: string) => void;
@@ -13,7 +13,7 @@ exports.CONFIG_METADATA_KEY = 'CONFIG_METADATA';
13
13
  */
14
14
  const Property = (key, parser, options) => function (target, propertyKey) {
15
15
  const ctor = target.constructor;
16
- const metadata = Reflect.getMetadata(exports.CONFIG_METADATA_KEY, ctor) || { properties: {} };
16
+ const metadata = Reflect.getMetadata(exports.CONFIG_METADATA_KEY, ctor) ?? { properties: {} };
17
17
  metadata.properties[propertyKey] = {
18
18
  expectedInEnv: false,
19
19
  key,
@@ -1 +1 @@
1
- {"version":3,"file":"property.decorator.js","sourceRoot":"","sources":["../../../../src/config/metadata/decorators/property.decorator.ts"],"names":[],"mappings":";;;AAMa,QAAA,mBAAmB,GAAG,iBAAiB,CAAC;AAErD;;;;;;;;GAQG;AACI,MAAM,QAAQ,GAAG,CACtB,GAAW,EACX,MAAyB,EACzB,OAA2B,EACR,EAAE,CACrB,UAAU,MAAc,EAAE,WAA4B;IACpD,MAAM,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC;IAEhC,MAAM,QAAQ,GAAI,OAAO,CAAC,WAAW,CACnC,2BAAmB,EACnB,IAAI,CACe,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;IAE5C,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG;QACjC,aAAa,EAAE,KAAK;QACpB,GAAG;QACH,MAAM;QACN,GAAG,OAAO;KACX,CAAC;IAEF,OAAO,CAAC,cAAc,CAAC,2BAAmB,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC9D,CAAC,CAAC;AArBS,QAAA,QAAQ,YAqBjB;AAEJ,6GAA6G"}
1
+ {"version":3,"file":"property.decorator.js","sourceRoot":"","sources":["../../../../src/config/metadata/decorators/property.decorator.ts"],"names":[],"mappings":";;;AAMa,QAAA,mBAAmB,GAAG,iBAAiB,CAAC;AAErD;;;;;;;;GAQG;AACI,MAAM,QAAQ,GAAG,CACtB,GAAW,EACX,MAAyB,EACzB,OAA2B,EACsB,EAAE,CACnD,UAAU,MAAc,EAAE,WAAmB;IAC3C,MAAM,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC;IAEhC,MAAM,QAAQ,GAAI,OAAO,CAAC,WAAW,CACnC,2BAAmB,EACnB,IAAI,CACe,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;IAE5C,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG;QACjC,aAAa,EAAE,KAAK;QACpB,GAAG;QACH,MAAM;QACN,GAAG,OAAO;KACX,CAAC;IAEF,OAAO,CAAC,cAAc,CAAC,2BAAmB,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC9D,CAAC,CAAC;AArBS,QAAA,QAAQ,YAqBjB;AAEJ,6GAA6G"}
@@ -27,9 +27,13 @@ export interface PropertyMetadata<T = any> {
27
27
  export interface SectionMetadata {
28
28
  name?: string;
29
29
  constructorName: string;
30
- properties: Record<string | symbol, PropertyMetadata>;
30
+ /**
31
+ * Record because must be natively serialized to rsdk.json
32
+ */
33
+ properties: Record<string, PropertyMetadata>;
31
34
  description?: string;
32
35
  tags?: string[];
36
+ prefix?: string;
33
37
  }
34
38
  export interface SourceMetadata {
35
39
  type: SourceType;
@@ -26,7 +26,10 @@ class ContextAggregator {
26
26
  }
27
27
  const platformRoot = platform_module_1.PlatformModule.forRoot(this.platformContext.extendedOptions);
28
28
  const rsdkMetadataGlobalModule = await rsdk_metadata_global_module_1.RsdkMetadataGlobalModule.raw(platformRoot);
29
- const rsdkMetadataProvider = await metadata_1.RsdkMetadataProvider.create(rsdkMetadataGlobalModule, platformRoot);
29
+ const rsdkMetadataProvider = await metadata_1.RsdkMetadataProvider.create([
30
+ rsdkMetadataGlobalModule,
31
+ platformRoot,
32
+ ]);
30
33
  const configContext = new config_1.ConfigContext(rsdkMetadataProvider, {
31
34
  ...this.platformContext.options.config,
32
35
  appName: this.platformContext.extendedOptions.name,
@@ -1 +1 @@
1
- {"version":3,"file":"context.aggregator.js","sourceRoot":"","sources":["../src/context.aggregator.ts"],"names":[],"mappings":";;;AACA,6CAAsD;AAEtD,oDAA8D;AAC9D,6FAAuF;AAEvF,qCAAyC;AAEzC,uDAAmD;AAEnD,MAAa,iBAAiB;IAGR;IAFZ,WAAW,CAAqB;IAExC,YAAoB,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;IAAG,CAAC;IAExD;;;;;;;OAOG;IACH,KAAK,CAAC,aAAa;QACjB,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAO,IAAI,CAAC,WAAW,CAAC;SACzB;QACD,MAAM,YAAY,GAAG,gCAAc,CAAC,OAAO,CACzC,IAAI,CAAC,eAAe,CAAC,eAAe,CACrC,CAAC;QACF,MAAM,wBAAwB,GAAG,MAAM,sDAAwB,CAAC,GAAG,CACjE,YAAY,CACb,CAAC;QACF,MAAM,oBAAoB,GAAG,MAAM,+BAAoB,CAAC,MAAM,CAC5D,wBAAwB,EACxB,YAAY,CACb,CAAC;QAEF,MAAM,aAAa,GAAG,IAAI,sBAAa,CAAC,oBAAoB,EAAE;YAC5D,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM;YACtC,OAAO,EAAE,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,IAAI;SACnD,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG;YACX,OAAO,EAAE;gBACP,YAAY;gBACZ,wBAAwB;gBACxB,4BAAmB,CAAC,OAAO,CAAC,aAAa,CAAC;aAC3C;YACD,MAAM,EAAE,iBAAiB;SAC1B,CAAC;QAEF,IAAI,CAAC,WAAW,GAAG,EAAE,IAAI,EAAE,oBAAoB,EAAE,aAAa,EAAE,CAAC;QACjE,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,gBAAgB;QACpB,8DAA8D;QAC9D,OAAO,CAAC,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,aAAa,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,uBAAuB;QAC3B,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAE9C,OAAO,UAAU,CAAC,oBAAoB,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAE5C,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAjED,8CAiEC"}
1
+ {"version":3,"file":"context.aggregator.js","sourceRoot":"","sources":["../src/context.aggregator.ts"],"names":[],"mappings":";;;AACA,6CAAsD;AAEtD,oDAA8D;AAC9D,6FAAuF;AAEvF,qCAAyC;AAEzC,uDAAmD;AAEnD,MAAa,iBAAiB;IAGR;IAFZ,WAAW,CAAqB;IAExC,YAAoB,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;IAAG,CAAC;IAExD;;;;;;;OAOG;IACH,KAAK,CAAC,aAAa;QACjB,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAO,IAAI,CAAC,WAAW,CAAC;SACzB;QACD,MAAM,YAAY,GAAG,gCAAc,CAAC,OAAO,CACzC,IAAI,CAAC,eAAe,CAAC,eAAe,CACrC,CAAC;QACF,MAAM,wBAAwB,GAAG,MAAM,sDAAwB,CAAC,GAAG,CACjE,YAAY,CACb,CAAC;QACF,MAAM,oBAAoB,GAAG,MAAM,+BAAoB,CAAC,MAAM,CAAC;YAC7D,wBAAwB;YACxB,YAAY;SACb,CAAC,CAAC;QAEH,MAAM,aAAa,GAAG,IAAI,sBAAa,CAAC,oBAAoB,EAAE;YAC5D,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM;YACtC,OAAO,EAAE,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,IAAI;SACnD,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG;YACX,OAAO,EAAE;gBACP,YAAY;gBACZ,wBAAwB;gBACxB,4BAAmB,CAAC,OAAO,CAAC,aAAa,CAAC;aAC3C;YACD,MAAM,EAAE,iBAAiB;SAC1B,CAAC;QAEF,IAAI,CAAC,WAAW,GAAG,EAAE,IAAI,EAAE,oBAAoB,EAAE,aAAa,EAAE,CAAC;QACjE,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,gBAAgB;QACpB,8DAA8D;QAC9D,OAAO,CAAC,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,aAAa,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,uBAAuB;QAC3B,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAE9C,OAAO,UAAU,CAAC,oBAAoB,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAE5C,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAjED,8CAiEC"}
@@ -0,0 +1,8 @@
1
+ import type { ClassProvider, DynamicModule, ExistingProvider, FactoryProvider, InjectionToken, ValueProvider } from '@nestjs/common';
2
+ import type { Resource, ResourceExtractor } from '@rsdk/metadata';
3
+ /**
4
+ * @private
5
+ */
6
+ export declare class ConfigMetadataExtractor implements ResourceExtractor {
7
+ extract(value: DynamicModule | ClassProvider<any> | ValueProvider<any> | FactoryProvider<any> | ExistingProvider<any> | InjectionToken): Resource<unknown>[];
8
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigMetadataExtractor = void 0;
4
+ const config_1 = require("../config");
5
+ const constants_1 = require("./constants");
6
+ /**
7
+ * @private
8
+ */
9
+ class ConfigMetadataExtractor {
10
+ extract(value) {
11
+ /**
12
+ * Получаем аргументы конструктора
13
+ */
14
+ const args = Reflect.getMetadata('design:paramtypes', value);
15
+ /**
16
+ * Если их нет, просто возвращаем пустой массив
17
+ */
18
+ if (!Array.isArray(args)) {
19
+ return [];
20
+ }
21
+ const resources = [];
22
+ for (const arg of args) {
23
+ const isConfigSection = Reflect.getMetadata(config_1.CONFIG_METADATA_KEY, arg) &&
24
+ arg.prototype instanceof config_1.Config;
25
+ if (!isConfigSection) {
26
+ continue;
27
+ }
28
+ resources.push({
29
+ value: config_1.PlatformConfigModule.forFeature(arg),
30
+ key: arg,
31
+ scope: constants_1.PLATFORM_RAW_GLOBAL_METADATA_SCOPE,
32
+ });
33
+ }
34
+ return resources;
35
+ }
36
+ }
37
+ exports.ConfigMetadataExtractor = ConfigMetadataExtractor;
38
+ //# sourceMappingURL=config-metadata.extractor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-metadata.extractor.js","sourceRoot":"","sources":["../../src/rsdk-metadata/config-metadata.extractor.ts"],"names":[],"mappings":";;;AAUA,sCAA8E;AAE9E,2CAAiE;AAEjE;;GAEG;AACH,MAAa,uBAAuB;IAClC,OAAO,CACL,KAMkB;QAElB;;WAEG;QACH,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;QAC7D;;WAEG;QACH,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACxB,OAAO,EAAE,CAAC;SACX;QACD,MAAM,SAAS,GAA8B,EAAE,CAAC;QAEhD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;YACtB,MAAM,eAAe,GACnB,OAAO,CAAC,WAAW,CAAC,4BAAmB,EAAE,GAAG,CAAC;gBAC7C,GAAG,CAAC,SAAS,YAAY,eAAM,CAAC;YAElC,IAAI,CAAC,eAAe,EAAE;gBACpB,SAAS;aACV;YACD,SAAS,CAAC,IAAI,CAAC;gBACb,KAAK,EAAE,6BAAoB,CAAC,UAAU,CAAC,GAAG,CAAC;gBAC3C,GAAG,EAAE,GAAG;gBACR,KAAK,EAAE,8CAAkC;aAC1C,CAAC,CAAC;SACJ;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAtCD,0DAsCC"}
@@ -3,14 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RsdkMetadataGlobalModule = void 0;
4
4
  const logging_1 = require("@rsdk/logging");
5
5
  const metadata_1 = require("@rsdk/metadata");
6
+ const config_metadata_extractor_1 = require("./config-metadata.extractor");
6
7
  const constants_1 = require("./constants");
7
8
  class RsdkMetadataGlobalModule {
8
9
  static logger = logging_1.LoggerFactory.create(RsdkMetadataGlobalModule);
9
10
  static async raw(rootModule) {
10
- const rsdkMetadataProvider = await metadata_1.RsdkMetadataProvider.create(rootModule);
11
+ const rsdkMetadataProvider = await metadata_1.RsdkMetadataProvider.create([rootModule], [new config_metadata_extractor_1.ConfigMetadataExtractor()]);
11
12
  const resources = rsdkMetadataProvider.get(constants_1.PLATFORM_RAW_GLOBAL_METADATA_SCOPE);
12
13
  const imports = resources.map(({ value }) => value);
13
- RsdkMetadataGlobalModule.logger.debug('extracted imports: ', {
14
+ RsdkMetadataGlobalModule.logger.trace('extracted imports: ', {
14
15
  imports,
15
16
  });
16
17
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"rsdk-metadata.global-module.js","sourceRoot":"","sources":["../../src/rsdk-metadata/rsdk-metadata.global-module.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAC9C,6CAAsD;AAItD,2CAAiE;AAEjE,MAAa,wBAAwB;IACnC,MAAM,CAAC,MAAM,GAAG,uBAAa,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC;IAC/D,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,UAAgC;QAC/C,MAAM,oBAAoB,GAAG,MAAM,+BAAoB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC3E,MAAM,SAAS,GAAG,oBAAoB,CAAC,GAAG,CACxC,8CAAkC,CACnC,CAAC;QACF,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;QAEpD,wBAAwB,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE;YAC3D,OAAO;SACR,CAAC,CAAC;QACH,OAAO;YACL,MAAM,EAAE,IAAI;YACZ,OAAO;YACP,MAAM,EAAE,wBAAwB;YAChC,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,+BAAoB;oBAC7B,QAAQ,EAAE,oBAAoB;iBAC/B;aACF;YACD,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,+BAAoB,CAAC;SAC5C,CAAC;IACJ,CAAC;;AAxBH,4DAyBC"}
1
+ {"version":3,"file":"rsdk-metadata.global-module.js","sourceRoot":"","sources":["../../src/rsdk-metadata/rsdk-metadata.global-module.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAC9C,6CAAsD;AAGtD,2EAAsE;AAEtE,2CAAiE;AAEjE,MAAa,wBAAwB;IACnC,MAAM,CAAC,MAAM,GAAG,uBAAa,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC;IAE/D,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,UAAgC;QAC/C,MAAM,oBAAoB,GAAG,MAAM,+BAAoB,CAAC,MAAM,CAC5D,CAAC,UAAU,CAAC,EACZ,CAAC,IAAI,mDAAuB,EAAE,CAAC,CAChC,CAAC;QAEF,MAAM,SAAS,GAAG,oBAAoB,CAAC,GAAG,CACxC,8CAAkC,CACnC,CAAC;QACF,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;QAEpD,wBAAwB,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE;YAC3D,OAAO;SACR,CAAC,CAAC;QACH,OAAO;YACL,MAAM,EAAE,IAAI;YACZ,OAAO;YACP,MAAM,EAAE,wBAAwB;YAChC,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,+BAAoB;oBAC7B,QAAQ,EAAE,oBAAoB;iBAC/B;aACF;YACD,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,+BAAoB,CAAC;SAC5C,CAAC;IACJ,CAAC;;AA7BH,4DA8BC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdk/core",
3
- "version": "3.1.0-next.0",
3
+ "version": "3.1.0-next.2",
4
4
  "description": "Nestjs based microservice chassis",
5
5
  "license": "Apache License 2.0",
6
6
  "publishConfig": {
@@ -31,17 +31,17 @@
31
31
  "@nestjs/common": "^10.1.3",
32
32
  "@nestjs/core": "^10.1.3",
33
33
  "@nestjs/microservices": "^10.1.3",
34
- "@rsdk/autodoc.protocol": "^3.1.0-next.0",
34
+ "@rsdk/autodoc.protocol": "^3.1.0-next.2",
35
35
  "@rsdk/common": "^3.1.0-next.0",
36
36
  "@rsdk/common.nestjs": "^3.1.0-next.0",
37
37
  "@rsdk/common.node": "^3.1.0-next.0",
38
38
  "@rsdk/decorators": "^3.1.0-next.0",
39
39
  "@rsdk/logging": "^3.1.0-next.0",
40
- "@rsdk/metadata": "^3.1.0-next.0",
40
+ "@rsdk/metadata": "^3.1.0-next.2",
41
41
  "@rsdk/nest-tools": "^3.1.0-next.0",
42
42
  "axios": "^1.1.3",
43
43
  "reflect-metadata": "^0.1.13",
44
44
  "rxjs": "^7.0.0"
45
45
  },
46
- "gitHead": "55598931db264fb6d5b5c4787c48298ed86bbc0d"
46
+ "gitHead": "28db120cf1b53317241e1b14d936eae785723601"
47
47
  }
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/ban-types */
2
2
  import type { Constructor } from '@rsdk/common';
3
+ import { Case } from '@rsdk/common';
3
4
 
4
5
  import type { SectionMetadata } from '../../types';
5
6
  import { ConfigMetadataRegistry } from '../config-metadata.registry';
@@ -13,6 +14,44 @@ export interface ConfigSectionOptions {
13
14
  * Используются только в документации
14
15
  */
15
16
  tags?: string[];
17
+
18
+ /**
19
+ * Всем полям указанным в теле будет добавлена строка
20
+ * `<PREFIX>_<PROPERTY_NAME>`
21
+ * @example
22
+ * // @ConfigSection({ prefix: 'APP_CONFIG' })
23
+ * class AppConfig extends Config {
24
+ * // @Property('FIELD', ...)
25
+ * field: string
26
+ * }
27
+ * // env -> APP_CONFIG_FIELD
28
+ */
29
+ prefix?: string;
30
+ }
31
+
32
+ function getComputedMetadata(
33
+ sectionMetadata: SectionMetadata,
34
+ options?: ConfigSectionOptions,
35
+ ): SectionMetadata {
36
+ if (options?.prefix) {
37
+ const properties = Object.fromEntries(
38
+ Object.entries(sectionMetadata.properties).map(([propName, propMeta]) => {
39
+ return [
40
+ propName,
41
+ {
42
+ ...propMeta,
43
+ key: Case.toUpperSnake(`${options.prefix}_${propMeta.key}`),
44
+ },
45
+ ];
46
+ }),
47
+ );
48
+
49
+ return {
50
+ ...sectionMetadata,
51
+ properties,
52
+ };
53
+ }
54
+ return sectionMetadata;
16
55
  }
17
56
 
18
57
  /**
@@ -22,13 +61,17 @@ export interface ConfigSectionOptions {
22
61
  */
23
62
  export const ConfigSection = (options?: ConfigSectionOptions): ClassDecorator =>
24
63
  function (target: Function): void {
25
- const metadata = Reflect.getMetadata(
26
- CONFIG_METADATA_KEY,
27
- target,
28
- ) as SectionMetadata;
29
-
30
- ConfigMetadataRegistry.registerSection(target as Constructor, {
31
- ...metadata,
32
- ...options,
33
- });
64
+ const metadata = (Reflect.getMetadata(CONFIG_METADATA_KEY, target) ??
65
+ {}) as SectionMetadata;
66
+
67
+ ConfigMetadataRegistry.registerSection(
68
+ target as Constructor,
69
+ getComputedMetadata(
70
+ {
71
+ ...metadata,
72
+ ...options,
73
+ },
74
+ options,
75
+ ),
76
+ );
34
77
  };
@@ -19,14 +19,14 @@ export const Property = <T>(
19
19
  key: string,
20
20
  parser: PropertyParser<T>,
21
21
  options: PropertyOptions<T>,
22
- ): PropertyDecorator =>
23
- function (target: object, propertyKey: string | symbol): void {
22
+ ): ((target: object, propertyKey: string) => void) =>
23
+ function (target: object, propertyKey: string): void {
24
24
  const ctor = target.constructor;
25
25
 
26
26
  const metadata = (Reflect.getMetadata(
27
27
  CONFIG_METADATA_KEY,
28
28
  ctor,
29
- ) as SectionMetadata) || { properties: {} };
29
+ ) as SectionMetadata) ?? { properties: {} };
30
30
 
31
31
  metadata.properties[propertyKey] = {
32
32
  expectedInEnv: false,
@@ -33,11 +33,13 @@ export interface PropertyMetadata<T = any> {
33
33
  export interface SectionMetadata {
34
34
  name?: string;
35
35
  constructorName: string;
36
- // TODO: Why use Record instead of map here
37
- // TODO: Why symbol here
38
- properties: Record<string | symbol, PropertyMetadata>;
36
+ /**
37
+ * Record because must be natively serialized to rsdk.json
38
+ */
39
+ properties: Record<string, PropertyMetadata>;
39
40
  description?: string;
40
41
  tags?: string[];
42
+ prefix?: string;
41
43
  }
42
44
 
43
45
  export interface SourceMetadata {
@@ -31,10 +31,10 @@ export class ContextAggregator {
31
31
  const rsdkMetadataGlobalModule = await RsdkMetadataGlobalModule.raw(
32
32
  platformRoot,
33
33
  );
34
- const rsdkMetadataProvider = await RsdkMetadataProvider.create(
34
+ const rsdkMetadataProvider = await RsdkMetadataProvider.create([
35
35
  rsdkMetadataGlobalModule,
36
36
  platformRoot,
37
- );
37
+ ]);
38
38
 
39
39
  const configContext = new ConfigContext(rsdkMetadataProvider, {
40
40
  ...this.platformContext.options.config,
@@ -0,0 +1,56 @@
1
+ import type {
2
+ ClassProvider,
3
+ DynamicModule,
4
+ ExistingProvider,
5
+ FactoryProvider,
6
+ InjectionToken,
7
+ ValueProvider,
8
+ } from '@nestjs/common';
9
+ import type { Resource, ResourceExtractor } from '@rsdk/metadata';
10
+
11
+ import { Config, CONFIG_METADATA_KEY, PlatformConfigModule } from '../config';
12
+
13
+ import { PLATFORM_RAW_GLOBAL_METADATA_SCOPE } from './constants';
14
+
15
+ /**
16
+ * @private
17
+ */
18
+ export class ConfigMetadataExtractor implements ResourceExtractor {
19
+ extract(
20
+ value:
21
+ | DynamicModule
22
+ | ClassProvider<any>
23
+ | ValueProvider<any>
24
+ | FactoryProvider<any>
25
+ | ExistingProvider<any>
26
+ | InjectionToken,
27
+ ): Resource<unknown>[] {
28
+ /**
29
+ * Получаем аргументы конструктора
30
+ */
31
+ const args = Reflect.getMetadata('design:paramtypes', value);
32
+ /**
33
+ * Если их нет, просто возвращаем пустой массив
34
+ */
35
+ if (!Array.isArray(args)) {
36
+ return [];
37
+ }
38
+ const resources: Resource<DynamicModule>[] = [];
39
+
40
+ for (const arg of args) {
41
+ const isConfigSection =
42
+ Reflect.getMetadata(CONFIG_METADATA_KEY, arg) &&
43
+ arg.prototype instanceof Config;
44
+
45
+ if (!isConfigSection) {
46
+ continue;
47
+ }
48
+ resources.push({
49
+ value: PlatformConfigModule.forFeature(arg),
50
+ key: arg,
51
+ scope: PLATFORM_RAW_GLOBAL_METADATA_SCOPE,
52
+ });
53
+ }
54
+ return resources;
55
+ }
56
+ }
@@ -3,19 +3,25 @@ import { LoggerFactory } from '@rsdk/logging';
3
3
  import { RsdkMetadataProvider } from '@rsdk/metadata';
4
4
  import type { NestModuleDefinition } from '@rsdk/nest-tools/dist/nest-definition';
5
5
 
6
+ import { ConfigMetadataExtractor } from './config-metadata.extractor';
6
7
  import type { PlatformRawGlobalMetadata } from './constants';
7
8
  import { PLATFORM_RAW_GLOBAL_METADATA_SCOPE } from './constants';
8
9
 
9
10
  export class RsdkMetadataGlobalModule {
10
11
  static logger = LoggerFactory.create(RsdkMetadataGlobalModule);
12
+
11
13
  static async raw(rootModule: NestModuleDefinition): Promise<DynamicModule> {
12
- const rsdkMetadataProvider = await RsdkMetadataProvider.create(rootModule);
14
+ const rsdkMetadataProvider = await RsdkMetadataProvider.create(
15
+ [rootModule],
16
+ [new ConfigMetadataExtractor()],
17
+ );
18
+
13
19
  const resources = rsdkMetadataProvider.get<PlatformRawGlobalMetadata>(
14
20
  PLATFORM_RAW_GLOBAL_METADATA_SCOPE,
15
21
  );
16
22
  const imports = resources.map(({ value }) => value);
17
23
 
18
- RsdkMetadataGlobalModule.logger.debug('extracted imports: ', {
24
+ RsdkMetadataGlobalModule.logger.trace('extracted imports: ', {
19
25
  imports,
20
26
  });
21
27
  return {