@dsmrt/axiom-config 0.1.1 → 0.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @dsmrt/axiom-config
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 90d88c8: fix load config return with custom interfaces
8
+
9
+ ## 0.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 7aa81f2: fixing issues with publishing the package with changesets
14
+
3
15
  ## 0.1.1
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -15,12 +15,12 @@ interface ConfigMethods {
15
15
  isProd(): boolean;
16
16
  asParameterPath(name: string): string;
17
17
  }
18
- declare class ConfigContainer<T = object> implements BaseConfig, ConfigMethods {
18
+ declare class ConfigContainer implements BaseConfig, ConfigMethods {
19
19
  readonly name: string;
20
20
  readonly env: string;
21
21
  readonly aws: AwsConfigs;
22
22
  readonly prodEnvName?: string;
23
- constructor(config: T & BaseConfig);
23
+ constructor(config: BaseConfig);
24
24
  isProd(): boolean;
25
25
  asParameterPath(name: string): string;
26
26
  }
@@ -39,7 +39,7 @@ interface LoadConfigInput {
39
39
  cwd?: string;
40
40
  }
41
41
  declare const importConfigFromPath: (path: string) => Config;
42
- declare const loadConfig: <T extends object>(input?: LoadConfigInput) => ConfigContainer<T>;
42
+ declare const loadConfig: <T extends object>(input?: LoadConfigInput) => ConfigContainer & T;
43
43
  /**
44
44
  * Simple object check.
45
45
  */
package/dist/index.d.ts CHANGED
@@ -15,12 +15,12 @@ interface ConfigMethods {
15
15
  isProd(): boolean;
16
16
  asParameterPath(name: string): string;
17
17
  }
18
- declare class ConfigContainer<T = object> implements BaseConfig, ConfigMethods {
18
+ declare class ConfigContainer implements BaseConfig, ConfigMethods {
19
19
  readonly name: string;
20
20
  readonly env: string;
21
21
  readonly aws: AwsConfigs;
22
22
  readonly prodEnvName?: string;
23
- constructor(config: T & BaseConfig);
23
+ constructor(config: BaseConfig);
24
24
  isProd(): boolean;
25
25
  asParameterPath(name: string): string;
26
26
  }
@@ -39,7 +39,7 @@ interface LoadConfigInput {
39
39
  cwd?: string;
40
40
  }
41
41
  declare const importConfigFromPath: (path: string) => Config;
42
- declare const loadConfig: <T extends object>(input?: LoadConfigInput) => ConfigContainer<T>;
42
+ declare const loadConfig: <T extends object>(input?: LoadConfigInput) => ConfigContainer & T;
43
43
  /**
44
44
  * Simple object check.
45
45
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsmrt/axiom-config",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "description": "Config library for axiom cli",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -29,13 +29,13 @@
29
29
  "@types/yargs": "^17.0.31",
30
30
  "@typescript-eslint/eslint-plugin": "^6.12.0",
31
31
  "@typescript-eslint/parser": "^6.12.0",
32
- "@vitest/coverage-v8": "^0.34.6",
33
32
  "eslint": "^8.54.0",
34
33
  "prettier": "^3.1.0",
35
34
  "ts-node": "^10.9.1",
36
35
  "tsup": "^8.0.1",
37
36
  "typescript": "^5.2.2",
38
- "vitest": "^0.34.6"
37
+ "@vitest/coverage-v8": "^1.2.1",
38
+ "vitest": "^1.2.1"
39
39
  },
40
40
  "dependencies": {
41
41
  "find-up": "^5.0.0",
package/lib/index.js DELETED
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.configPath = exports.mergeDeep = exports.isObject = exports.loadConfig = exports.importConfigFromPath = void 0;
4
- const fs_1 = require("fs");
5
- const find_up_1 = require("find-up");
6
- // TODO - Add validation here
7
- const importConfigFromPath = (path) => {
8
- if (/\.json$/.test(path)) {
9
- return JSON.parse((0, fs_1.readFileSync)(path).toString());
10
- }
11
- if (/\.(m)?[j|t]s$/.test(path)) {
12
- /* eslint-disable */
13
- return require(path);
14
- }
15
- throw new Error(`Path not found: {path}`);
16
- };
17
- exports.importConfigFromPath = importConfigFromPath;
18
- const loadConfig = (input) => {
19
- // get the base file
20
- const baseConfigFile = (0, exports.configPath)(input);
21
- const baseConfig = (0, exports.importConfigFromPath)(baseConfigFile);
22
- let overrides = input?.overrides || {};
23
- // get the environment file
24
- if (input?.env) {
25
- const devConfig = (0, exports.importConfigFromPath)((0, exports.configPath)(input));
26
- overrides = mergeDeep(devConfig, overrides);
27
- }
28
- // merge env file
29
- return mergeDeep(baseConfig, overrides);
30
- };
31
- exports.loadConfig = loadConfig;
32
- /**
33
- * Simple object check.
34
- */
35
- function isObject(item) {
36
- return item && typeof item === "object" && !Array.isArray(item);
37
- }
38
- exports.isObject = isObject;
39
- /**
40
- * Deep merge two objects.
41
- */
42
- function mergeDeep(target, ...sources) {
43
- if (!sources.length)
44
- return target;
45
- const source = sources.shift();
46
- if (isObject(target) && isObject(source)) {
47
- for (const key in source) {
48
- if (isObject(source[key])) {
49
- if (!target[key])
50
- Object.assign(target, { [key]: {} });
51
- mergeDeep(target[key], source[key]);
52
- }
53
- else {
54
- Object.assign(target, { [key]: source[key] });
55
- }
56
- }
57
- }
58
- return mergeDeep(target, ...sources);
59
- }
60
- exports.mergeDeep = mergeDeep;
61
- const configPath = (input) => {
62
- const envIndicator = input?.env ? `.${input.env}` : "";
63
- const p = (0, find_up_1.sync)([
64
- `.axiom${envIndicator}.json`,
65
- `.axiom${envIndicator}.js`,
66
- `.axiom${envIndicator}.mjs`,
67
- `.axiom${envIndicator}.ts`,
68
- `.axiom${envIndicator}.mts`,
69
- ], { cwd: input?.cwd });
70
- if (p === undefined)
71
- throw new Error(`Axiom config files not found: .axiom${envIndicator}.json, .axiom${envIndicator}.js .axiom${envIndicator}.ts`);
72
- return p;
73
- };
74
- exports.configPath = configPath;