@h3ravel/config 1.1.6 → 1.2.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 +20 -0
- package/dist/chunk-4W6577EG.js +21574 -0
- package/dist/chunk-4W6577EG.js.map +1 -0
- package/dist/dist-MPQ4EAQT.js +23 -0
- package/dist/dist-MPQ4EAQT.js.map +1 -0
- package/dist/index.cjs +21899 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +10 -7
- package/dist/index.js.map +1 -1
- package/package.json +10 -4
- package/src/ConfigRepository.ts +4 -3
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
ServiceProvider,
|
|
3
|
+
__name
|
|
4
|
+
} from "./chunk-4W6577EG.js";
|
|
3
5
|
|
|
4
6
|
// src/ConfigRepository.ts
|
|
5
7
|
import { safeDot, setNested } from "@h3ravel/support";
|
|
6
|
-
import path from "
|
|
7
|
-
import { readdir } from "
|
|
8
|
+
import path from "path";
|
|
9
|
+
import { readdir } from "fs/promises";
|
|
8
10
|
var ConfigRepository = class {
|
|
9
11
|
static {
|
|
10
12
|
__name(this, "ConfigRepository");
|
|
@@ -27,10 +29,12 @@ var ConfigRepository = class {
|
|
|
27
29
|
async load() {
|
|
28
30
|
if (!this.loaded) {
|
|
29
31
|
const configPath = this.app.getPath("config");
|
|
30
|
-
const files = await readdir(configPath)
|
|
32
|
+
const files = (await readdir(configPath)).filter((e) => {
|
|
33
|
+
return !e.includes(".d.ts") && !e.includes(".map");
|
|
34
|
+
});
|
|
31
35
|
for (let i = 0; i < files.length; i++) {
|
|
32
36
|
const configModule = await import(path.join(configPath, files[i]));
|
|
33
|
-
const name = files[i].replaceAll(
|
|
37
|
+
const name = files[i].replaceAll(/\.ts|\.js/g, "");
|
|
34
38
|
if (typeof configModule.default === "function") {
|
|
35
39
|
this.configs[name] = configModule.default(this.app);
|
|
36
40
|
}
|
|
@@ -57,7 +61,6 @@ var EnvLoader = class {
|
|
|
57
61
|
};
|
|
58
62
|
|
|
59
63
|
// src/Providers/ConfigServiceProvider.ts
|
|
60
|
-
import { ServiceProvider } from "@h3ravel/core";
|
|
61
64
|
var ConfigServiceProvider = class extends ServiceProvider {
|
|
62
65
|
static {
|
|
63
66
|
__name(this, "ConfigServiceProvider");
|
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(protected 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(
|
|
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(protected 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)).filter((e) => {\n return !e.includes('.d.ts') && !e.includes('.map')\n })\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 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 { ConfigRepository, EnvLoader } from '..'\n\nimport { Bindings } from '@h3ravel/shared';\nimport { ServiceProvider } from '@h3ravel/core'\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 public static priority = 998;\n // public static order = 'before:AppServiceProvider';\n\n async register () {\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,KAAkB;SAAlBA,MAAAA;EAAoB;EAU1CC,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,SAAS,MAAMC,QAAQH,UAAAA,GAAaI,OAAO,CAACC,MAAAA;AAC9C,eAAO,CAACA,EAAEC,SAAS,OAAA,KAAY,CAACD,EAAEC,SAAS,MAAA;MAC/C,CAAA;AAEA,eAASC,IAAI,GAAGA,IAAIL,MAAMM,QAAQD,KAAK;AACnC,cAAME,eAAe,MAAM,OAAOC,KAAKC,KAAKX,YAAYE,MAAMK,CAAAA,CAAE;AAChE,cAAMK,OAAOV,MAAMK,CAAAA,EAAGM,WAAW,cAAc,EAAA;AAC/C,YAAI,OAAOJ,aAAaK,YAAY,YAAY;AAC5C,eAAKxB,QAAQsB,IAAAA,IAAQH,aAAaK,QAAQ,KAAKvB,GAAG;QACtD;MACJ;AAEA,WAAKF,SAAS;IAClB;AACA,WAAO;EACX;AACJ;;;ACnDA,SAAwC0B,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;;;ACFO,IAAMI,wBAAN,cAAoCC,gBAAAA;EAb3C,OAa2CA;;;EACvC,OAAcC,WAAW;;EAGzB,MAAMC,WAAY;AAId,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","filter","e","includes","i","length","configModule","path","join","name","replaceAll","default","safeDot","EnvLoader","_app","get","key","def","safeDot","process","env","ConfigServiceProvider","ServiceProvider","priority","register","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": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Environment/config loading and management system for H3ravel.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -8,6 +8,12 @@
|
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
10
10
|
},
|
|
11
|
+
"homepage": "https://h3ravel.toneflix.net",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/h3ravel/framework.git",
|
|
15
|
+
"directory": "packages/config"
|
|
16
|
+
},
|
|
11
17
|
"keywords": [
|
|
12
18
|
"h3ravel",
|
|
13
19
|
"modern",
|
|
@@ -25,12 +31,12 @@
|
|
|
25
31
|
}
|
|
26
32
|
},
|
|
27
33
|
"dependencies": {
|
|
28
|
-
"@h3ravel/
|
|
29
|
-
"@h3ravel/
|
|
34
|
+
"@h3ravel/support": "^0.7.5",
|
|
35
|
+
"@h3ravel/shared": "^0.15.4"
|
|
30
36
|
},
|
|
31
37
|
"devDependencies": {
|
|
32
38
|
"typescript": "^5.4.0",
|
|
33
|
-
"@h3ravel/core": "^1.
|
|
39
|
+
"@h3ravel/core": "^1.3.0"
|
|
34
40
|
},
|
|
35
41
|
"scripts": {
|
|
36
42
|
"barrel": "barrelsby --directory src --delete --singleQuotes",
|
package/src/ConfigRepository.ts
CHANGED
|
@@ -33,11 +33,13 @@ 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)).filter((e) => {
|
|
37
|
+
return !e.includes('.d.ts') && !e.includes('.map')
|
|
38
|
+
})
|
|
37
39
|
|
|
38
40
|
for (let i = 0; i < files.length; i++) {
|
|
39
41
|
const configModule = await import(path.join(configPath, files[i]))
|
|
40
|
-
const name = files[i].replaceAll(
|
|
42
|
+
const name = files[i].replaceAll(/\.ts|\.js/g, '')
|
|
41
43
|
if (typeof configModule.default === 'function') {
|
|
42
44
|
this.configs[name] = configModule.default(this.app)
|
|
43
45
|
}
|
|
@@ -45,7 +47,6 @@ export class ConfigRepository {
|
|
|
45
47
|
|
|
46
48
|
this.loaded = true
|
|
47
49
|
}
|
|
48
|
-
|
|
49
50
|
return this
|
|
50
51
|
}
|
|
51
52
|
}
|