@cenk1cenk2/oclif-common 3.0.2 → 3.1.0-beta.1

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/dist/index.d.ts CHANGED
@@ -204,7 +204,7 @@ declare class ConfigService implements GlobalConfig {
204
204
  constructor(oclif: Command['config'], command: Command['ctor'], config: Omit<GlobalConfig, 'isVerbose' | 'isDebug' | 'isSilent'>);
205
205
  read<T extends LockableData = LockableData>(path: string): Promise<T>;
206
206
  extend<T extends LockableData = LockableData>(paths: string[], strategy?: MergeStrategy): Promise<T>;
207
- merge<T extends LockableData = LockableData>(configs: Partial<T>[], strategy?: MergeStrategy): Promise<T>;
207
+ merge<T extends LockableData = LockableData>(configs: Partial<T>[], strategy?: MergeStrategy): T;
208
208
  env<T extends LockableData = LockableData>(definition: string, config: T): Promise<T>;
209
209
  write<T extends LockableData = LockableData>(path: string, data: T): Promise<void>;
210
210
  private recalculate;
package/dist/index.js CHANGED
@@ -626,13 +626,12 @@ var ConfigService = class {
626
626
  return config;
627
627
  } catch (e) {
628
628
  this.logger.trace("Failed to extend config from: %s", e.message);
629
- return {};
630
629
  }
631
630
  })
632
631
  )).filter(Boolean);
633
632
  return this.merge(configs, strategy);
634
633
  }
635
- async merge(configs, strategy = "OVERWRITE" /* OVERWRITE */) {
634
+ merge(configs, strategy = "OVERWRITE" /* OVERWRITE */) {
636
635
  if (configs.length === 0) {
637
636
  throw new Error("Nothing to merge, configuration files are empty.");
638
637
  }
@@ -648,13 +647,18 @@ var ConfigService = class {
648
647
  if (typeof value === "string") {
649
648
  return [{ key: location, env: value }];
650
649
  } else if (typeof value === "object") {
651
- if ("__name" in value && "__format" in value) {
650
+ const extras = [];
651
+ if ("__element" /* ELEMENT */ in value) {
652
+ extras.push(await iter(value, [...location, "__element" /* ELEMENT */]));
653
+ }
654
+ if ("__name" /* NAME */ in value && "__format" /* PARSER */ in value) {
652
655
  return [
653
656
  {
654
657
  key: location,
655
- env: value.__name,
656
- parser: value.__format
657
- }
658
+ env: value["__name" /* NAME */],
659
+ parser: value["__format" /* PARSER */]
660
+ },
661
+ ...extras
658
662
  ];
659
663
  } else {
660
664
  return iter(value, location);
@@ -679,10 +683,31 @@ var ConfigService = class {
679
683
  throw e;
680
684
  }
681
685
  }
682
- config = import_object_path_immutable.default.update(config, variable.key, () => {
683
- this.logger.trace("Overwriting config with environment variable: %s -> %s", variable.key.join("."), variable.env);
684
- return data;
685
- });
686
+ if (variable.key.includes("__element" /* ELEMENT */)) {
687
+ const timeout = 6e4;
688
+ const startedAt = Date.now();
689
+ for (let i = 0; i < Infinity; i++) {
690
+ if (Date.now() - startedAt > timeout) {
691
+ throw new Error(`Timed-out in ${timeout}ms while looking for element environment variables.`);
692
+ }
693
+ data = process.env[variable.env.replace("${i}", i.toString())];
694
+ if (!data) {
695
+ this.logger.trace("No more variable available: %s -> %d", variable.env, i);
696
+ break;
697
+ }
698
+ const clone = JSON.parse(JSON.stringify(variable.key));
699
+ clone[clone.findIndex("__element" /* ELEMENT */)] = i;
700
+ config = import_object_path_immutable.default.update(config, clone, () => {
701
+ this.logger.trace("Overwriting config with element environment variable: %s -> %s", clone.join("."), variable.env);
702
+ return data;
703
+ });
704
+ }
705
+ } else {
706
+ config = import_object_path_immutable.default.update(config, variable.key, () => {
707
+ this.logger.trace("Overwriting config with environment variable: %s -> %s", variable.key.join("."), variable.env);
708
+ return data;
709
+ });
710
+ }
686
711
  })
687
712
  );
688
713
  return config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cenk1cenk2/oclif-common",
3
- "version": "3.0.2",
3
+ "version": "3.1.0-beta.1",
4
4
  "description": "Oclif common package for oclif2 projects.",
5
5
  "repository": "https://gitlab.kilic.dev/libraries/oclif-tools",
6
6
  "author": {