@dsmrt/axiom-config 0.0.8 → 0.0.10

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/lib/index.d.ts CHANGED
@@ -8,8 +8,22 @@ export interface BaseConfig {
8
8
  name: string;
9
9
  env: string;
10
10
  aws: AwsConfigs;
11
+ prodEnvName?: string;
11
12
  }
12
13
  export type Config<T = object> = T & BaseConfig;
14
+ interface ConfigMethods {
15
+ isProd(): boolean;
16
+ asParameterPath(name: string): string;
17
+ }
18
+ export declare class ConfigContainer<T = object> implements BaseConfig, ConfigMethods {
19
+ readonly name: string;
20
+ readonly env: string;
21
+ readonly aws: AwsConfigs;
22
+ readonly prodEnvName?: string;
23
+ constructor(config: T & BaseConfig);
24
+ isProd(): boolean;
25
+ asParameterPath(name: string): string;
26
+ }
13
27
  export interface LoadConfigInput {
14
28
  /**
15
29
  * defaults to prod
@@ -25,7 +39,7 @@ export interface LoadConfigInput {
25
39
  cwd?: string;
26
40
  }
27
41
  export declare const importConfigFromPath: (path: string) => Config;
28
- export declare const loadConfig: <T extends object>(input?: LoadConfigInput) => object & BaseConfig & T;
42
+ export declare const loadConfig: <T extends object>(input?: LoadConfigInput) => ConfigContainer<T>;
29
43
  /**
30
44
  * Simple object check.
31
45
  */
@@ -35,3 +49,4 @@ export declare function isObject(item: unknown): unknown;
35
49
  */
36
50
  export declare function mergeDeep(target: any, ...sources: any[]): any;
37
51
  export declare const configPath: (input?: LoadConfigInput) => string;
52
+ export {};
package/lib/index.js CHANGED
@@ -1,8 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.configPath = exports.mergeDeep = exports.isObject = exports.loadConfig = exports.importConfigFromPath = void 0;
3
+ exports.configPath = exports.mergeDeep = exports.isObject = exports.loadConfig = exports.importConfigFromPath = exports.ConfigContainer = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const find_up_1 = require("find-up");
6
+ class ConfigContainer {
7
+ name;
8
+ env;
9
+ aws;
10
+ prodEnvName = "prod";
11
+ constructor(config) {
12
+ this.name = config.name;
13
+ this.env = config.env;
14
+ this.aws = config.aws;
15
+ this.prodEnvName ??= config.prodEnvName;
16
+ for (const prop in config) {
17
+ // @ts-ignore
18
+ this[prop] = config[prop];
19
+ }
20
+ }
21
+ isProd() {
22
+ return this.env == this.prodEnvName;
23
+ }
24
+ asParameterPath(name) {
25
+ return (this.aws.baseParameterPath.replace(new RegExp("/+$"), "") + `/${name}`);
26
+ }
27
+ }
28
+ exports.ConfigContainer = ConfigContainer;
6
29
  // TODO - Add validation here
7
30
  const importConfigFromPath = (path) => {
8
31
  if (/\.json$/.test(path)) {
@@ -25,8 +48,9 @@ const loadConfig = (input) => {
25
48
  const devConfig = (0, exports.importConfigFromPath)((0, exports.configPath)(input));
26
49
  overrides = mergeDeep(devConfig, overrides);
27
50
  }
51
+ const configObject = mergeDeep(baseConfig, overrides);
28
52
  // merge env file
29
- return mergeDeep(baseConfig, overrides);
53
+ return new ConfigContainer(configObject);
30
54
  };
31
55
  exports.loadConfig = loadConfig;
32
56
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsmrt/axiom-config",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "Config library for axiom cli",
5
5
  "main": "lib/index.js",
6
6
  "repository": {