@h3ravel/config 0.2.0 → 0.4.0

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,35 @@
1
1
  # @h3ravel/config
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8ceb2c1: implement the Application class directly since it already implements the IClass contract
8
+
9
+ ### Patch Changes
10
+
11
+ - a27f452: chore: fix all linting issues.
12
+ - c906050: chore: migrate tests suite to jest
13
+ - Updated dependencies [8ceb2c1]
14
+ - Updated dependencies [a27f452]
15
+ - Updated dependencies [c906050]
16
+ - @h3ravel/core@0.4.0
17
+ - @h3ravel/shared@0.4.0
18
+ - @h3ravel/support@0.4.0
19
+
20
+ ## 0.3.0
21
+
22
+ ### Minor Changes
23
+
24
+ - 3ff97bf: refactor: add a shared package to be extended by others to avoid cyclic dependency issues.
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies [3ff97bf]
29
+ - @h3ravel/core@0.3.0
30
+ - @h3ravel/shared@0.3.0
31
+ - @h3ravel/support@0.3.0
32
+
3
33
  ## 0.2.0
4
34
 
5
35
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -29,13 +29,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
30
 
31
31
  // src/index.ts
32
- var index_exports = {};
33
- __export(index_exports, {
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
34
  ConfigRepository: () => ConfigRepository,
35
35
  ConfigServiceProvider: () => ConfigServiceProvider,
36
36
  EnvLoader: () => EnvLoader
37
37
  });
38
- module.exports = __toCommonJS(index_exports);
38
+ module.exports = __toCommonJS(src_exports);
39
39
 
40
40
  // src/ConfigRepository.ts
41
41
  var import_support = require("@h3ravel/support");
@@ -108,7 +108,7 @@ var ConfigServiceProvider = class extends import_core.ServiceProvider {
108
108
  await repo.load();
109
109
  this.app.singleton("config", () => {
110
110
  return {
111
- get: /* @__PURE__ */ __name((key, def) => repo.get(key, def), "get"),
111
+ get: (key, def) => repo.get(key, def),
112
112
  set: repo.set
113
113
  };
114
114
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/ConfigRepository.ts","../src/EnvLoader.ts","../src/Providers/ConfigServiceProvider.ts"],"sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from './ConfigRepository';\nexport * from './EnvLoader';\nexport * from './Helpers';\nexport * from './Providers/ConfigServiceProvider';\n","import { DotNestedKeys, DotNestedValue, safeDot, setNested } from '@h3ravel/support'\n\nimport { Application } from \"@h3ravel/core\";\nimport path from 'node:path'\nimport { readdir } from 'node:fs/promises'\n\nexport class ConfigRepository {\n private loaded: boolean = false\n private configs: Record<string, Record<string, any>> = {}\n\n constructor(private app: Application) { }\n\n // get<X extends Record<string, any>> (): X\n // get<X extends Record<string, any>, T extends Extract<keyof X, string>> (key: T): X[T]\n\n /**\n * Get the defined configurations\n */\n get<X extends Record<string, any>> (): X\n get<X extends Record<string, any>, K extends DotNestedKeys<X>> (key: K, def?: any): DotNestedValue<X, K>\n get<X extends Record<string, any>, K extends DotNestedKeys<X>> (key?: K, def?: any): any {\n return safeDot(this.configs, key) ?? def\n }\n\n /**\n * Modify the defined configurations\n */\n set<T extends string> (key: T, value: any): void {\n setNested(this.configs, key, value)\n }\n\n async load () {\n if (!this.loaded) {\n const configPath = this.app.getPath('config')\n\n const files = await readdir(configPath);\n\n for (let i = 0; i < files.length; i++) {\n const configModule = await import(path.join(configPath, files[i]))\n const name = files[i].replaceAll(/.ts|js/g, '')\n if (typeof configModule.default === 'function') {\n this.configs[name] = configModule.default(this.app)\n }\n }\n\n this.loaded = true\n }\n\n return this\n }\n}\n","import { DotNestedKeys, DotNestedValue, safeDot } from '@h3ravel/support'\n\nimport { Application } from \"@h3ravel/core\";\n\nexport class EnvLoader {\n constructor(private _app: Application) { }\n\n /**\n * Get the defined environment vars\n */\n get<X extends NodeJS.ProcessEnv> (): X\n get<X extends NodeJS.ProcessEnv, K extends DotNestedKeys<X>> (key: K, def?: any): DotNestedValue<X, K>\n get<X extends NodeJS.ProcessEnv, K extends DotNestedKeys<X>> (key?: K, def?: any): any {\n return safeDot(process.env, key) ?? def\n }\n}\n","import { Bindings, ServiceProvider } from '@h3ravel/core'\nimport { ConfigRepository, EnvLoader } from '..'\n\nimport { config as loadEnv } from 'dotenv'\n\n/**\n * Loads configuration and environment files.\n * \n * Load .env and merge with config files.\n * Bind ConfigRepository to the container.\n * \n * Auto-Registered\n */\nexport class ConfigServiceProvider extends ServiceProvider {\n async register () {\n\n loadEnv()\n\n /**\n * Create singleton to load env\n */\n this.app.singleton('env', () => {\n return new EnvLoader(this.app).get\n })\n\n /**\n * Initialize the configuration through the repository\n */\n const repo = new ConfigRepository(this.app)\n await repo.load()\n\n /**\n * Create singleton to load configurations\n */\n this.app.singleton('config', () => {\n return {\n get: (key, def) => repo.get(key as any, def),\n set: repo.set\n } as Bindings['config']\n })\n\n this.app.make('http.app').use(e => {\n repo.set('app.url', e.url.origin)\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAA,qBAAkE;AAGlE,uBAAiB;AACjB,sBAAwB;AAEjB,IAAMA,mBAAN,MAAMA;EANb,OAMaA;;;;EACDC,SAAkB;EAClBC,UAA+C,CAAC;EAExD,YAAoBC,KAAkB;SAAlBA,MAAAA;EAAoB;EAUxCC,IAAgEC,KAASC,KAAgB;AACrF,eAAOC,wBAAQ,KAAKL,SAASG,GAAAA,KAAQC;EACzC;;;;EAKAE,IAAuBH,KAAQI,OAAkB;AAC7CC,kCAAU,KAAKR,SAASG,KAAKI,KAAAA;EACjC;EAEA,MAAME,OAAQ;AACV,QAAI,CAAC,KAAKV,QAAQ;AACd,YAAMW,aAAa,KAAKT,IAAIU,QAAQ,QAAA;AAEpC,YAA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eDot","set","value","setNested","load","configPath","getPath","files","readdir","i","length","configModule","path","join","name","replaceAll","default","import_support","EnvLoader","_app","get","key","def","safeDot","process","env","ConfigServiceProvider","ServiceProvider","register","loadEnv","app","singleton","EnvLoader","get","repo","ConfigRepository","load","key","def","set","make","use","e","url","origin"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/ConfigRepository.ts","../src/EnvLoader.ts","../src/Providers/ConfigServiceProvider.ts"],"sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from './ConfigRepository';\nexport * from './EnvLoader';\nexport * from './Helpers';\nexport * from './Providers/ConfigServiceProvider';\n","import { DotNestedKeys, DotNestedValue, safeDot, setNested } from '@h3ravel/support'\n\nimport { IApplication } from '@h3ravel/shared'\nimport path from 'node:path'\nimport { readdir } from 'node:fs/promises'\n\nexport class ConfigRepository {\n private loaded: boolean = false\n private configs: Record<string, Record<string, any>> = {}\n\n constructor(protected app: IApplication) { }\n\n // get<X extends Record<string, any>> (): X\n // get<X extends Record<string, any>, T extends Extract<keyof X, string>> (key: T): X[T]\n\n /**\n * Get the defined configurations\n */\n get<X extends Record<string, any>> (): X\n get<X extends Record<string, any>, K extends DotNestedKeys<X>> (key: K, def?: any): DotNestedValue<X, K>\n get<X extends Record<string, any>, K extends DotNestedKeys<X>> (key?: K, def?: any): any {\n return safeDot(this.configs, key) ?? def\n }\n\n /**\n * Modify the defined configurations\n */\n set<T extends string> (key: T, value: any): void {\n setNested(this.configs, key, value)\n }\n\n async load () {\n if (!this.loaded) {\n const configPath = this.app.getPath('config')\n\n const files = await readdir(configPath);\n\n for (let i = 0; i < files.length; i++) {\n const configModule = await import(path.join(configPath, files[i]))\n const name = files[i].replaceAll(/.ts|js/g, '')\n if (typeof configModule.default === 'function') {\n this.configs[name] = configModule.default(this.app)\n }\n }\n\n this.loaded = true\n }\n\n return this\n }\n}\n","import { DotNestedKeys, DotNestedValue, safeDot } from '@h3ravel/support'\n\nimport { Application } from \"@h3ravel/core\";\n\nexport class EnvLoader {\n constructor(protected _app: Application) { }\n\n /**\n * Get the defined environment vars\n */\n get<X extends NodeJS.ProcessEnv> (): X\n get<X extends NodeJS.ProcessEnv, K extends DotNestedKeys<X>> (key: K, def?: any): DotNestedValue<X, K>\n get<X extends NodeJS.ProcessEnv, K extends DotNestedKeys<X>> (key?: K, def?: any): any {\n return safeDot(process.env, key) ?? def\n }\n}\n","import { Bindings, ServiceProvider } from '@h3ravel/core'\nimport { ConfigRepository, EnvLoader } from '..'\n\nimport { config as loadEnv } from 'dotenv'\n\n/**\n * Loads configuration and environment files.\n * \n * Load .env and merge with config files.\n * Bind ConfigRepository to the container.\n * \n * Auto-Registered\n */\nexport class ConfigServiceProvider extends ServiceProvider {\n async register () {\n\n loadEnv()\n\n /**\n * Create singleton to load env\n */\n this.app.singleton('env', () => {\n return new EnvLoader(this.app).get\n })\n\n /**\n * Initialize the configuration through the repository\n */\n const repo = new ConfigRepository(this.app)\n await repo.load()\n\n /**\n * Create singleton to load configurations\n */\n this.app.singleton('config', () => {\n return {\n get: (key, def) => repo.get(key as any, def),\n set: repo.set\n } as Bindings['config']\n })\n\n this.app.make('http.app').use(e => {\n repo.set('app.url', e.url.origin)\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACAA,qBAAkE;AAGlE,uBAAiB;AACjB,sBAAwB;AAEjB,IAAMA,mBAAN,MAAMA;EANb,OAMaA;;;;EACDC,SAAkB;EAClBC,UAA+C,CAAC;EAExD,YAAsBC,KAAmB;SAAnBA,MAAAA;EAAqB;EAU3CC,IAAgEC,KAASC,KAAgB;AACrF,eAAOC,wBAAQ,KAAKL,SAASG,GAAAA,KAAQC;EACzC;;;;EAKAE,IAAuBH,KAAQI,OAAkB;AAC7CC,kCAAU,KAAKR,SAASG,KAAKI,KAAAA;EACjC;EAEA,MAAME,OAAQ;AACV,QAAI,CAAC,KAAKV,QAAQ;AACd,YAAMW,aAAa,KAAKT,IAAIU,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ded","configs","app","get","key","def","safeDot","set","value","setNested","load","configPath","getPath","files","readdir","i","length","configModule","path","join","name","replaceAll","default","import_support","EnvLoader","_app","get","key","def","safeDot","process","env","ConfigServiceProvider","ServiceProvider","register","loadEnv","app","singleton","EnvLoader","get","repo","ConfigRepository","load","key","def","set","make","use","e","url","origin"]}
package/dist/index.d.cts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { DotNestedKeys, DotNestedValue } from '@h3ravel/support';
2
+ import { IApplication } from '@h3ravel/shared';
2
3
  import { Application, ServiceProvider } from '@h3ravel/core';
3
4
 
4
5
  declare class ConfigRepository {
5
- private app;
6
+ protected app: IApplication;
6
7
  private loaded;
7
8
  private configs;
8
- constructor(app: Application);
9
+ constructor(app: IApplication);
9
10
  /**
10
11
  * Get the defined configurations
11
12
  */
@@ -19,7 +20,7 @@ declare class ConfigRepository {
19
20
  }
20
21
 
21
22
  declare class EnvLoader {
22
- private _app;
23
+ protected _app: Application;
23
24
  constructor(_app: Application);
24
25
  /**
25
26
  * Get the defined environment vars
package/dist/index.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { DotNestedKeys, DotNestedValue } from '@h3ravel/support';
2
+ import { IApplication } from '@h3ravel/shared';
2
3
  import { Application, ServiceProvider } from '@h3ravel/core';
3
4
 
4
5
  declare class ConfigRepository {
5
- private app;
6
+ protected app: IApplication;
6
7
  private loaded;
7
8
  private configs;
8
- constructor(app: Application);
9
+ constructor(app: IApplication);
9
10
  /**
10
11
  * Get the defined configurations
11
12
  */
@@ -19,7 +20,7 @@ declare class ConfigRepository {
19
20
  }
20
21
 
21
22
  declare class EnvLoader {
22
- private _app;
23
+ protected _app: Application;
23
24
  constructor(_app: Application);
24
25
  /**
25
26
  * Get the defined environment vars
package/dist/index.js CHANGED
@@ -72,7 +72,7 @@ var ConfigServiceProvider = class extends ServiceProvider {
72
72
  await repo.load();
73
73
  this.app.singleton("config", () => {
74
74
  return {
75
- get: /* @__PURE__ */ __name((key, def) => repo.get(key, def), "get"),
75
+ get: (key, def) => repo.get(key, def),
76
76
  set: repo.set
77
77
  };
78
78
  });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ConfigRepository.ts","../src/EnvLoader.ts","../src/Providers/ConfigServiceProvider.ts"],"sourcesContent":["import { DotNestedKeys, DotNestedValue, safeDot, setNested } from '@h3ravel/support'\n\nimport { Application } from \"@h3ravel/core\";\nimport path from 'node:path'\nimport { readdir } from 'node:fs/promises'\n\nexport class ConfigRepository {\n private loaded: boolean = false\n private configs: Record<string, Record<string, any>> = {}\n\n constructor(private app: Application) { }\n\n // get<X extends Record<string, any>> (): X\n // get<X extends Record<string, any>, T extends Extract<keyof X, string>> (key: T): X[T]\n\n /**\n * Get the defined configurations\n */\n get<X extends Record<string, any>> (): X\n get<X extends Record<string, any>, K extends DotNestedKeys<X>> (key: K, def?: any): DotNestedValue<X, K>\n get<X extends Record<string, any>, K extends DotNestedKeys<X>> (key?: K, def?: any): any {\n return safeDot(this.configs, key) ?? def\n }\n\n /**\n * Modify the defined configurations\n */\n set<T extends string> (key: T, value: any): void {\n setNested(this.configs, key, value)\n }\n\n async load () {\n if (!this.loaded) {\n const configPath = this.app.getPath('config')\n\n const files = await readdir(configPath);\n\n for (let i = 0; i < files.length; i++) {\n const configModule = await import(path.join(configPath, files[i]))\n const name = files[i].replaceAll(/.ts|js/g, '')\n if (typeof configModule.default === 'function') {\n this.configs[name] = configModule.default(this.app)\n }\n }\n\n this.loaded = true\n }\n\n return this\n }\n}\n","import { DotNestedKeys, DotNestedValue, safeDot } from '@h3ravel/support'\n\nimport { Application } from \"@h3ravel/core\";\n\nexport class EnvLoader {\n constructor(private _app: Application) { }\n\n /**\n * Get the defined environment vars\n */\n get<X extends NodeJS.ProcessEnv> (): X\n get<X extends NodeJS.ProcessEnv, K extends DotNestedKeys<X>> (key: K, def?: any): DotNestedValue<X, K>\n get<X extends NodeJS.ProcessEnv, K extends DotNestedKeys<X>> (key?: K, def?: any): any {\n return safeDot(process.env, key) ?? def\n }\n}\n","import { Bindings, ServiceProvider } from '@h3ravel/core'\nimport { ConfigRepository, EnvLoader } from '..'\n\nimport { config as loadEnv } from 'dotenv'\n\n/**\n * Loads configuration and environment files.\n * \n * Load .env and merge with config files.\n * Bind ConfigRepository to the container.\n * \n * Auto-Registered\n */\nexport class ConfigServiceProvider extends ServiceProvider {\n async register () {\n\n loadEnv()\n\n /**\n * Create singleton to load env\n */\n this.app.singleton('env', () => {\n return new EnvLoader(this.app).get\n })\n\n /**\n * Initialize the configuration through the repository\n */\n const repo = new ConfigRepository(this.app)\n await repo.load()\n\n /**\n * Create singleton to load configurations\n */\n this.app.singleton('config', () => {\n return {\n get: (key, def) => repo.get(key as any, def),\n set: repo.set\n } as Bindings['config']\n })\n\n this.app.make('http.app').use(e => {\n repo.set('app.url', e.url.origin)\n })\n }\n}\n"],"mappings":";;;;AAAA,SAAwCA,SAASC,iBAAiB;AAGlE,OAAOC,UAAU;AACjB,SAASC,eAAe;AAEjB,IAAMC,mBAAN,MAAMA;EANb,OAMaA;;;;EACDC,SAAkB;EAClBC,UAA+C,CAAC;EAExD,YAAoBC,KAAkB;SAAlBA,MAAAA;EAAoB;EAUxCC,IAAgEC,KAASC,KAAgB;AACrF,WAAOC,QAAQ,KAAKL,SAASG,GAAAA,KAAQC;EACzC;;;;EAKAE,IAAuBH,KAAQI,OAAkB;AAC7CC,cAAU,KAAKR,SAASG,KAAKI,KAAAA;EACjC;EAEA,MAAME,OAAQ;AACV,QAAI,CAAC,KAAKV,QAAQ;AACd,YAAMW,aAAa,KAAKT,IAAIU,QAAQ,QAAA;AAEpC,YAAMC,QAAQ,MAAMC,QAAQH,UAAAA;AAE5B,eAASI,IAAI,GAAGA,IAAIF,MAAMG,QAAQD,KAAK;AACnC,cAAME,eAAe,MAAM,OAAOC,KAAKC,KAAKR,YAAYE,MAAME,CAAAA,CAAE;AAChE,cAAMK,OAAOP,MAAME,CAAAA,EAAGM,WAAW,WAAW,EAAA;AAC5C,YAAI,OAAOJ,aAAaK,YAAY,YAAY;AAC5C,eAAKrB,QAAQmB,IAAAA,IAAQH,aAAaK,QAAQ,KAAKpB,GAAG;QACtD;MACJ;AAEA,WAAKF,SAAS;IAClB;AAEA,WAAO;EACX;AACJ;;;AClDA,SAAwCuB,WAAAA,gBAAe;AAIhD,IAAMC,YAAN,MAAMA;EAJb,OAIaA;;;;EACT,YAAoBC,MAAmB;SAAnBA,OAAAA;EAAqB;EAOzCC,IAA8DC,KAASC,KAAgB;AACnF,WAAOC,SAAQC,QAAQC,KAAKJ,GAAAA,KAAQC;EACxC;AACJ;;;ACfA,SAAmBI,uBAAuB;AAG1C,SAASC,UAAUC,eAAe;AAU3B,IAAMC,wBAAN,cAAoCC,gBAAAA;EAb3C,OAa2CA;;;EACvC,MAAMC,WAAY;AAEdC,YAAAA;AAKA,SAAKC,IAAIC,UAAU,OAAO,MAAA;AACtB,aAAO,IAAIC,UAAU,KAAKF,GAAG,EAAEG;IACnC,CAAA;AAKA,UAAMC,OAAO,IAAIC,iBAAiB,KAAKL,GAAG;AAC1C,UAAMI,KAAKE,KAAI;AAKf,SAAKN,IAAIC,UAAU,UAAU,MAAA;AACzB,aAAO;QACHE,KAAK,wBAACI,KAAKC,QAAQJ,KAAKD,IAAII,KAAYC,GAAAA,GAAnC;QACLC,KAAKL,KAAKK;MACd;IACJ,CAAA;AAEA,SAAKT,IAAIU,KAAK,UAAA,EAAYC,IAAIC,CAAAA,MAAAA;AAC1BR,WAAKK,IAAI,WAAWG,EAAEC,IAAIC,MAAM;IACpC,CAAA;EACJ;AACJ;","names":["safeDot","setNested","path","readdir","ConfigRepository","loaded","configs","app","get","key","def","safeDot","set","value","setNested","load","configPath","getPath","files","readdir","i","length","configModule","path","join","name","replaceAll","default","safeDot","EnvLoader","_app","get","key","def","safeDot","process","env","ServiceProvider","config","loadEnv","ConfigServiceProvider","ServiceProvider","register","loadEnv","app","singleton","EnvLoader","get","repo","ConfigRepository","load","key","def","set","make","use","e","url","origin"]}
1
+ {"version":3,"sources":["../src/ConfigRepository.ts","../src/EnvLoader.ts","../src/Providers/ConfigServiceProvider.ts"],"sourcesContent":["import { DotNestedKeys, DotNestedValue, safeDot, setNested } from '@h3ravel/support'\n\nimport { IApplication } from '@h3ravel/shared'\nimport path from 'node:path'\nimport { readdir } from 'node:fs/promises'\n\nexport class ConfigRepository {\n private loaded: boolean = false\n private configs: Record<string, Record<string, any>> = {}\n\n constructor(protected app: IApplication) { }\n\n // get<X extends Record<string, any>> (): X\n // get<X extends Record<string, any>, T extends Extract<keyof X, string>> (key: T): X[T]\n\n /**\n * Get the defined configurations\n */\n get<X extends Record<string, any>> (): X\n get<X extends Record<string, any>, K extends DotNestedKeys<X>> (key: K, def?: any): DotNestedValue<X, K>\n get<X extends Record<string, any>, K extends DotNestedKeys<X>> (key?: K, def?: any): any {\n return safeDot(this.configs, key) ?? def\n }\n\n /**\n * Modify the defined configurations\n */\n set<T extends string> (key: T, value: any): void {\n setNested(this.configs, key, value)\n }\n\n async load () {\n if (!this.loaded) {\n const configPath = this.app.getPath('config')\n\n const files = await readdir(configPath);\n\n for (let i = 0; i < files.length; i++) {\n const configModule = await import(path.join(configPath, files[i]))\n const name = files[i].replaceAll(/.ts|js/g, '')\n if (typeof configModule.default === 'function') {\n this.configs[name] = configModule.default(this.app)\n }\n }\n\n this.loaded = true\n }\n\n return this\n }\n}\n","import { DotNestedKeys, DotNestedValue, safeDot } from '@h3ravel/support'\n\nimport { Application } from \"@h3ravel/core\";\n\nexport class EnvLoader {\n constructor(protected _app: Application) { }\n\n /**\n * Get the defined environment vars\n */\n get<X extends NodeJS.ProcessEnv> (): X\n get<X extends NodeJS.ProcessEnv, K extends DotNestedKeys<X>> (key: K, def?: any): DotNestedValue<X, K>\n get<X extends NodeJS.ProcessEnv, K extends DotNestedKeys<X>> (key?: K, def?: any): any {\n return safeDot(process.env, key) ?? def\n }\n}\n","import { Bindings, ServiceProvider } from '@h3ravel/core'\nimport { ConfigRepository, EnvLoader } from '..'\n\nimport { config as loadEnv } from 'dotenv'\n\n/**\n * Loads configuration and environment files.\n * \n * Load .env and merge with config files.\n * Bind ConfigRepository to the container.\n * \n * Auto-Registered\n */\nexport class ConfigServiceProvider extends ServiceProvider {\n async register () {\n\n loadEnv()\n\n /**\n * Create singleton to load env\n */\n this.app.singleton('env', () => {\n return new EnvLoader(this.app).get\n })\n\n /**\n * Initialize the configuration through the repository\n */\n const repo = new ConfigRepository(this.app)\n await repo.load()\n\n /**\n * Create singleton to load configurations\n */\n this.app.singleton('config', () => {\n return {\n get: (key, def) => repo.get(key as any, def),\n set: repo.set\n } as Bindings['config']\n })\n\n this.app.make('http.app').use(e => {\n repo.set('app.url', e.url.origin)\n })\n }\n}\n"],"mappings":";;;;AAAA,SAAwCA,SAASC,iBAAiB;AAGlE,OAAOC,UAAU;AACjB,SAASC,eAAe;AAEjB,IAAMC,mBAAN,MAAMA;EANb,OAMaA;;;;EACDC,SAAkB;EAClBC,UAA+C,CAAC;EAExD,YAAsBC,KAAmB;SAAnBA,MAAAA;EAAqB;EAU3CC,IAAgEC,KAASC,KAAgB;AACrF,WAAOC,QAAQ,KAAKL,SAASG,GAAAA,KAAQC;EACzC;;;;EAKAE,IAAuBH,KAAQI,OAAkB;AAC7CC,cAAU,KAAKR,SAASG,KAAKI,KAAAA;EACjC;EAEA,MAAME,OAAQ;AACV,QAAI,CAAC,KAAKV,QAAQ;AACd,YAAMW,aAAa,KAAKT,IAAIU,QAAQ,QAAA;AAEpC,YAAMC,QAAQ,MAAMC,QAAQH,UAAAA;AAE5B,eAASI,IAAI,GAAGA,IAAIF,MAAMG,QAAQD,KAAK;AACnC,cAAME,eAAe,MAAM,OAAOC,KAAKC,KAAKR,YAAYE,MAAME,CAAAA,CAAE;AAChE,cAAMK,OAAOP,MAAME,CAAAA,EAAGM,WAAW,WAAW,EAAA;AAC5C,YAAI,OAAOJ,aAAaK,YAAY,YAAY;AAC5C,eAAKrB,QAAQmB,IAAAA,IAAQH,aAAaK,QAAQ,KAAKpB,GAAG;QACtD;MACJ;AAEA,WAAKF,SAAS;IAClB;AAEA,WAAO;EACX;AACJ;;;AClDA,SAAwCuB,WAAAA,gBAAe;AAIhD,IAAMC,YAAN,MAAMA;EAJb,OAIaA;;;;EACT,YAAsBC,MAAmB;SAAnBA,OAAAA;EAAqB;EAO3CC,IAA8DC,KAASC,KAAgB;AACnF,WAAOC,SAAQC,QAAQC,KAAKJ,GAAAA,KAAQC;EACxC;AACJ;;;ACfA,SAAmBI,uBAAuB;AAG1C,SAASC,UAAUC,eAAe;AAU3B,IAAMC,wBAAN,cAAoCC,gBAAAA;EAb3C,OAa2CA;;;EACvC,MAAMC,WAAY;AAEdC,YAAAA;AAKA,SAAKC,IAAIC,UAAU,OAAO,MAAA;AACtB,aAAO,IAAIC,UAAU,KAAKF,GAAG,EAAEG;IACnC,CAAA;AAKA,UAAMC,OAAO,IAAIC,iBAAiB,KAAKL,GAAG;AAC1C,UAAMI,KAAKE,KAAI;AAKf,SAAKN,IAAIC,UAAU,UAAU,MAAA;AACzB,aAAO;QACHE,KAAK,CAACI,KAAKC,QAAQJ,KAAKD,IAAII,KAAYC,GAAAA;QACxCC,KAAKL,KAAKK;MACd;IACJ,CAAA;AAEA,SAAKT,IAAIU,KAAK,UAAA,EAAYC,IAAIC,CAAAA,MAAAA;AAC1BR,WAAKK,IAAI,WAAWG,EAAEC,IAAIC,MAAM;IACpC,CAAA;EACJ;AACJ;","names":["safeDot","setNested","path","readdir","ConfigRepository","loaded","configs","app","get","key","def","safeDot","set","value","setNested","load","configPath","getPath","files","readdir","i","length","configModule","path","join","name","replaceAll","default","safeDot","EnvLoader","_app","get","key","def","safeDot","process","env","ServiceProvider","config","loadEnv","ConfigServiceProvider","ServiceProvider","register","loadEnv","app","singleton","EnvLoader","get","repo","ConfigRepository","load","key","def","set","make","use","e","url","origin"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/config",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Environment/config loading and management system for H3ravel.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -16,11 +16,13 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "dotenv": "^17.2.1",
19
- "@h3ravel/support": "0.2.0",
20
- "@h3ravel/core": "0.2.0"
19
+ "@h3ravel/core": "0.4.0",
20
+ "@h3ravel/shared": "0.4.0",
21
+ "@h3ravel/support": "0.4.0"
21
22
  },
22
23
  "devDependencies": {
23
- "typescript": "^5.4.0"
24
+ "typescript": "^5.4.0",
25
+ "@h3ravel/core": "shared:*"
24
26
  },
25
27
  "scripts": {
26
28
  "barrel": "barrelsby --directory src --delete --singleQuotes",
@@ -28,6 +30,6 @@
28
30
  "dev": "tsx watch src/index.ts",
29
31
  "start": "node dist/index.js",
30
32
  "lint": "eslint . --ext .ts",
31
- "test": "vitest"
33
+ "test": "jest --passWithNoTests"
32
34
  }
33
35
  }
@@ -1,6 +1,6 @@
1
1
  import { DotNestedKeys, DotNestedValue, safeDot, setNested } from '@h3ravel/support'
2
2
 
3
- import { Application } from "@h3ravel/core";
3
+ import { Application } from '@h3ravel/core'
4
4
  import path from 'node:path'
5
5
  import { readdir } from 'node:fs/promises'
6
6
 
@@ -33,7 +33,7 @@ export class ConfigRepository {
33
33
  if (!this.loaded) {
34
34
  const configPath = this.app.getPath('config')
35
35
 
36
- const files = await readdir(configPath);
36
+ const files = await readdir(configPath)
37
37
 
38
38
  for (let i = 0; i < files.length; i++) {
39
39
  const configModule = await import(path.join(configPath, files[i]))
package/src/EnvLoader.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DotNestedKeys, DotNestedValue, safeDot } from '@h3ravel/support'
2
2
 
3
- import { Application } from "@h3ravel/core";
3
+ import { Application } from '@h3ravel/core'
4
4
 
5
5
  export class EnvLoader {
6
6
  constructor(protected _app: Application) { }
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "../tsconfig/tsconfig.json",
2
+ "extends": "../shared/tsconfig.json",
3
3
  "compilerOptions": {
4
4
  "outDir": "dist"
5
5
  },