@h3ravel/core 0.1.0 → 0.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.
@@ -0,0 +1,90 @@
1
+ import {
2
+ ServiceProvider,
3
+ __name,
4
+ safeDot,
5
+ setNested
6
+ } from "./chunk-22XJG4AW.js";
7
+
8
+ // ../config/src/ConfigRepository.ts
9
+ import path from "path";
10
+ import { readdir } from "fs/promises";
11
+ var ConfigRepository = class {
12
+ static {
13
+ __name(this, "ConfigRepository");
14
+ }
15
+ app;
16
+ loaded = false;
17
+ configs = {};
18
+ constructor(app) {
19
+ this.app = app;
20
+ }
21
+ get(key, def) {
22
+ return safeDot(this.configs, key) ?? def;
23
+ }
24
+ /**
25
+ * Modify the defined configurations
26
+ */
27
+ set(key, value) {
28
+ setNested(this.configs, key, value);
29
+ }
30
+ async load() {
31
+ if (!this.loaded) {
32
+ const configPath = this.app.getPath("config");
33
+ const files = await readdir(configPath);
34
+ for (let i = 0; i < files.length; i++) {
35
+ const configModule = await import(path.join(configPath, files[i]));
36
+ const name = files[i].replaceAll(/.ts|js/g, "");
37
+ if (typeof configModule.default === "function") {
38
+ this.configs[name] = configModule.default(this.app);
39
+ }
40
+ }
41
+ this.loaded = true;
42
+ }
43
+ return this;
44
+ }
45
+ };
46
+
47
+ // ../config/src/EnvLoader.ts
48
+ var EnvLoader = class {
49
+ static {
50
+ __name(this, "EnvLoader");
51
+ }
52
+ _app;
53
+ constructor(_app) {
54
+ this._app = _app;
55
+ }
56
+ get(key, def) {
57
+ return safeDot(process.env, key) ?? def;
58
+ }
59
+ };
60
+
61
+ // ../config/src/Providers/ConfigServiceProvider.ts
62
+ import { config as loadEnv } from "dotenv";
63
+ var ConfigServiceProvider = class extends ServiceProvider {
64
+ static {
65
+ __name(this, "ConfigServiceProvider");
66
+ }
67
+ async register() {
68
+ loadEnv();
69
+ this.app.singleton("env", () => {
70
+ return new EnvLoader(this.app).get;
71
+ });
72
+ const repo = new ConfigRepository(this.app);
73
+ await repo.load();
74
+ this.app.singleton("config", () => {
75
+ return {
76
+ get: /* @__PURE__ */ __name((key, def) => repo.get(key, def), "get"),
77
+ set: repo.set
78
+ };
79
+ });
80
+ this.app.make("http.app").use((e) => {
81
+ repo.set("app.url", e.url.origin);
82
+ });
83
+ }
84
+ };
85
+ export {
86
+ ConfigRepository,
87
+ ConfigServiceProvider,
88
+ EnvLoader
89
+ };
90
+ //# sourceMappingURL=src-UIEMS3XE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../config/src/ConfigRepository.ts","../../config/src/EnvLoader.ts","../../config/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":";;;;;;;;AAGA,OAAOA,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;;;AC9CO,IAAMuB,YAAN,MAAMA;EAJb,OAIaA;;;;EACT,YAAoBC,MAAmB;SAAnBA,OAAAA;EAAqB;EAOzCC,IAA8DC,KAASC,KAAgB;AACnF,WAAOC,QAAQC,QAAQC,KAAKJ,GAAAA,KAAQC;EACxC;AACJ;;;ACZA,SAASI,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":["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","EnvLoader","_app","get","key","def","safeDot","process","env","config","loadEnv","ConfigServiceProvider","ServiceProvider","register","loadEnv","app","singleton","EnvLoader","get","repo","ConfigRepository","load","key","def","set","make","use","e","url","origin"]}
@@ -5,7 +5,7 @@ import {
5
5
  __name,
6
6
  afterLast,
7
7
  before
8
- } from "./chunk-UZGBH6AC.js";
8
+ } from "./chunk-22XJG4AW.js";
9
9
 
10
10
  // ../router/src/Router.ts
11
11
  var Router = class {
@@ -220,4 +220,4 @@ export {
220
220
  RouteServiceProvider,
221
221
  Router
222
222
  };
223
- //# sourceMappingURL=src-E5IZSMT7.js.map
223
+ //# sourceMappingURL=src-ZLODNLLQ.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/core",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Core application container, lifecycle management and service providers for H3ravel.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -13,7 +13,9 @@
13
13
  "h3": "^2.0.0-beta.1",
14
14
  "reflect-metadata": "^0.2.2",
15
15
  "srvx": "^0.8.2",
16
- "tslib": "^2.6.0"
16
+ "tslib": "^2.6.0",
17
+ "@h3ravel/tsconfig": "0.2.0",
18
+ "@h3ravel/router": "0.2.0"
17
19
  },
18
20
  "devDependencies": {
19
21
  "typescript": "^5.4.0"
@@ -1,4 +1,4 @@
1
- import { DotNestedKeys, DotNestedValue } from "@h3ravel/support";
1
+ // import { DotNestedKeys, DotNestedValue } from "@h3ravel/support";
2
2
  import type { H3, serve } from "h3";
3
3
 
4
4
  import type { Edge } from "edge.js";
@@ -3,7 +3,7 @@ import { HttpContext, Middleware, Request, Response } from '@h3ravel/http'
3
3
  import type { H3Event } from 'h3'
4
4
 
5
5
  export class Kernel {
6
- constructor(private middleware: Middleware[] = []) { }
6
+ constructor(protected middleware: Middleware[] = []) { }
7
7
 
8
8
  async handle (event: H3Event, next: (ctx: HttpContext) => Promise<unknown>): Promise<unknown> {
9
9
  const context: HttpContext = {
@@ -10,7 +10,7 @@ export class PathLoader {
10
10
  routes: '/src/routes',
11
11
  config: '/src/config',
12
12
  public: '/public',
13
- storage: '/src/storage',
13
+ storage: '/storage',
14
14
  }
15
15
 
16
16
  /**
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "../../tsconfig.json",
2
+ "extends": "../tsconfig/tsconfig.json",
3
3
  "compilerOptions": {
4
4
  "outDir": "dist"
5
5
  },