@h3ravel/core 0.1.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/dist/index.cjs ADDED
@@ -0,0 +1,1860 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __esm = (fn, res) => function __init() {
10
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
+ };
12
+ var __commonJS = (cb, mod) => function __require() {
13
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
14
+ };
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
28
+ // If the importer is in node compatibility mode or this is not an ESM
29
+ // file that has been converted to a CommonJS file using a Babel-
30
+ // compatible transform (i.e. "__esModule" has not been set), then set
31
+ // "default" to the CommonJS "module.exports" for node compatibility.
32
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
33
+ mod
34
+ ));
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+
37
+ // src/Container.ts
38
+ var Container;
39
+ var init_Container = __esm({
40
+ "src/Container.ts"() {
41
+ "use strict";
42
+ Container = class {
43
+ static {
44
+ __name(this, "Container");
45
+ }
46
+ bindings = /* @__PURE__ */ new Map();
47
+ singletons = /* @__PURE__ */ new Map();
48
+ bind(key, factory) {
49
+ this.bindings.set(key, factory);
50
+ }
51
+ /**
52
+ * Bind a singleton service to the container
53
+ */
54
+ singleton(key, factory) {
55
+ this.bindings.set(key, () => {
56
+ if (!this.singletons.has(key)) {
57
+ this.singletons.set(key, factory());
58
+ }
59
+ return this.singletons.get(key);
60
+ });
61
+ }
62
+ /**
63
+ * Resolve a service from the container
64
+ */
65
+ make(key) {
66
+ if (this.bindings.has(key)) {
67
+ return this.bindings.get(key)();
68
+ }
69
+ if (typeof key === "function") {
70
+ return this.build(key);
71
+ }
72
+ throw new Error(`No binding found for key: ${typeof key === "string" ? key : key?.name}`);
73
+ }
74
+ /**
75
+ * Automatically build a class with constructor dependency injection
76
+ */
77
+ build(ClassType) {
78
+ const paramTypes = Reflect.getMetadata("design:paramtypes", ClassType) || [];
79
+ const dependencies = paramTypes.map((dep) => this.make(dep));
80
+ return new ClassType(...dependencies);
81
+ }
82
+ /**
83
+ * Check if a service is registered
84
+ */
85
+ has(key) {
86
+ return this.bindings.has(key);
87
+ }
88
+ };
89
+ }
90
+ });
91
+
92
+ // src/Utils/PathLoader.ts
93
+ var import_path, PathLoader;
94
+ var init_PathLoader = __esm({
95
+ "src/Utils/PathLoader.ts"() {
96
+ "use strict";
97
+ import_path = __toESM(require("path"), 1);
98
+ PathLoader = class {
99
+ static {
100
+ __name(this, "PathLoader");
101
+ }
102
+ paths = {
103
+ base: "",
104
+ views: "/src/resources/views",
105
+ assets: "/public/assets",
106
+ routes: "/src/routes",
107
+ config: "/src/config",
108
+ public: "/public",
109
+ storage: "/src/storage"
110
+ };
111
+ /**
112
+ * Dynamically retrieves a path property from the class.
113
+ * Any property ending with "Path" is accessible automatically.
114
+ *
115
+ * @param name - The base name of the path property
116
+ * @param base - The base path to include to the path
117
+ * @returns
118
+ */
119
+ getPath(name, base) {
120
+ if (base && name !== "base") {
121
+ return import_path.default.join(base, this.paths[name]);
122
+ }
123
+ return this.paths[name];
124
+ }
125
+ /**
126
+ * Programatically set the paths.
127
+ *
128
+ * @param name - The base name of the path property
129
+ * @param path - The new path
130
+ * @param base - The base path to include to the path
131
+ */
132
+ setPath(name, path4, base) {
133
+ if (base && name !== "base") {
134
+ this.paths[name] = import_path.default.join(base, path4);
135
+ }
136
+ this.paths[name] = path4;
137
+ }
138
+ };
139
+ }
140
+ });
141
+
142
+ // ../http/src/Middleware.ts
143
+ var Middleware;
144
+ var init_Middleware = __esm({
145
+ "../http/src/Middleware.ts"() {
146
+ "use strict";
147
+ Middleware = class {
148
+ static {
149
+ __name(this, "Middleware");
150
+ }
151
+ };
152
+ }
153
+ });
154
+
155
+ // ../support/src/Contracts/ObjContract.ts
156
+ var init_ObjContract = __esm({
157
+ "../support/src/Contracts/ObjContract.ts"() {
158
+ "use strict";
159
+ }
160
+ });
161
+
162
+ // ../support/src/Contracts/StrContract.ts
163
+ var init_StrContract = __esm({
164
+ "../support/src/Contracts/StrContract.ts"() {
165
+ "use strict";
166
+ }
167
+ });
168
+
169
+ // ../support/src/Helpers/Arr.ts
170
+ var init_Arr = __esm({
171
+ "../support/src/Helpers/Arr.ts"() {
172
+ "use strict";
173
+ }
174
+ });
175
+
176
+ // ../support/src/Helpers/Number.ts
177
+ var init_Number = __esm({
178
+ "../support/src/Helpers/Number.ts"() {
179
+ "use strict";
180
+ }
181
+ });
182
+
183
+ // ../support/src/Helpers/Obj.ts
184
+ function safeDot(data, key) {
185
+ if (!key) return data;
186
+ return key.split(".").reduce((acc, k) => acc?.[k], data);
187
+ }
188
+ var setNested;
189
+ var init_Obj = __esm({
190
+ "../support/src/Helpers/Obj.ts"() {
191
+ "use strict";
192
+ __name(safeDot, "safeDot");
193
+ setNested = /* @__PURE__ */ __name((obj, key, value) => {
194
+ if (!key.includes(".")) {
195
+ obj[key] = value;
196
+ return;
197
+ }
198
+ const parts = key.split(".");
199
+ let current = obj;
200
+ for (let i = 0; i < parts.length; i++) {
201
+ const part = parts[i];
202
+ if (i === parts.length - 1) {
203
+ current[part] = value;
204
+ } else {
205
+ if (typeof current[part] !== "object" || current[part] === null) {
206
+ current[part] = {};
207
+ }
208
+ current = current[part];
209
+ }
210
+ }
211
+ }, "setNested");
212
+ }
213
+ });
214
+
215
+ // ../support/src/Helpers/Str.ts
216
+ var afterLast, before;
217
+ var init_Str = __esm({
218
+ "../support/src/Helpers/Str.ts"() {
219
+ "use strict";
220
+ init_Obj();
221
+ afterLast = /* @__PURE__ */ __name((value, search) => {
222
+ if (!search) return value;
223
+ const lastIndex = value.lastIndexOf(search);
224
+ return lastIndex !== -1 ? value.slice(lastIndex + search.length) : value;
225
+ }, "afterLast");
226
+ before = /* @__PURE__ */ __name((value, search) => {
227
+ if (!search) return value;
228
+ const index = value.indexOf(search);
229
+ return index !== -1 ? value.slice(0, index) : value;
230
+ }, "before");
231
+ }
232
+ });
233
+
234
+ // ../support/src/index.ts
235
+ var init_src = __esm({
236
+ "../support/src/index.ts"() {
237
+ "use strict";
238
+ init_ObjContract();
239
+ init_StrContract();
240
+ init_Arr();
241
+ init_Number();
242
+ init_Obj();
243
+ init_Str();
244
+ }
245
+ });
246
+
247
+ // ../http/src/Request.ts
248
+ var import_h3, Request;
249
+ var init_Request = __esm({
250
+ "../http/src/Request.ts"() {
251
+ "use strict";
252
+ import_h3 = require("h3");
253
+ init_src();
254
+ Request = class {
255
+ static {
256
+ __name(this, "Request");
257
+ }
258
+ event;
259
+ constructor(event) {
260
+ this.event = event;
261
+ }
262
+ /**
263
+ * Get all input data (query + body).
264
+ */
265
+ async all() {
266
+ let data = {
267
+ ...(0, import_h3.getRouterParams)(this.event),
268
+ ...(0, import_h3.getQuery)(this.event)
269
+ };
270
+ if (this.event.req.method === "POST") {
271
+ data = Object.assign({}, data, Object.fromEntries((await this.event.req.formData()).entries()));
272
+ } else if (this.event.req.method === "PUT") {
273
+ data = Object.fromEntries(Object.entries(await (0, import_h3.readBody)(this.event)));
274
+ }
275
+ return data;
276
+ }
277
+ /**
278
+ * Get a single input field from query or body.
279
+ */
280
+ async input(key, defaultValue) {
281
+ const data = await this.all();
282
+ return data[key] ?? defaultValue;
283
+ }
284
+ /**
285
+ * Get route parameters.
286
+ */
287
+ params() {
288
+ return (0, import_h3.getRouterParams)(this.event);
289
+ }
290
+ /**
291
+ * Get query parameters.
292
+ */
293
+ query() {
294
+ return (0, import_h3.getQuery)(this.event);
295
+ }
296
+ getEvent(key) {
297
+ return safeDot(this.event, key);
298
+ }
299
+ };
300
+ }
301
+ });
302
+
303
+ // ../http/src/Response.ts
304
+ var import_h32, Response;
305
+ var init_Response = __esm({
306
+ "../http/src/Response.ts"() {
307
+ "use strict";
308
+ init_src();
309
+ import_h32 = require("h3");
310
+ Response = class {
311
+ static {
312
+ __name(this, "Response");
313
+ }
314
+ event;
315
+ statusCode = 200;
316
+ headers = {};
317
+ constructor(event) {
318
+ this.event = event;
319
+ }
320
+ /**
321
+ * Set HTTP status code.
322
+ */
323
+ setStatusCode(code) {
324
+ this.statusCode = code;
325
+ this.event.res.status = code;
326
+ return this;
327
+ }
328
+ /**
329
+ * Set a header.
330
+ */
331
+ setHeader(name, value) {
332
+ this.headers[name] = value;
333
+ return this;
334
+ }
335
+ html(content) {
336
+ this.applyHeaders();
337
+ return (0, import_h32.html)(this.event, content);
338
+ }
339
+ /**
340
+ * Send a JSON response.
341
+ */
342
+ json(data) {
343
+ this.setHeader("content-type", "application/json; charset=utf-8");
344
+ this.applyHeaders();
345
+ return data;
346
+ }
347
+ /**
348
+ * Send plain text.
349
+ */
350
+ text(data) {
351
+ this.setHeader("content-type", "text/plain; charset=utf-8");
352
+ this.applyHeaders();
353
+ return data;
354
+ }
355
+ /**
356
+ * Redirect to another URL.
357
+ */
358
+ redirect(url, status = 302) {
359
+ this.setStatusCode(status);
360
+ return (0, import_h32.redirect)(this.event, url, this.statusCode);
361
+ }
362
+ /**
363
+ * Apply headers before sending response.
364
+ */
365
+ applyHeaders() {
366
+ Object.entries(this.headers).forEach(([key, value]) => {
367
+ this.event.res.headers.set(key, value);
368
+ });
369
+ }
370
+ getEvent(key) {
371
+ return safeDot(this.event, key);
372
+ }
373
+ };
374
+ }
375
+ });
376
+
377
+ // ../http/src/Contracts/ControllerContracts.ts
378
+ var init_ControllerContracts = __esm({
379
+ "../http/src/Contracts/ControllerContracts.ts"() {
380
+ "use strict";
381
+ }
382
+ });
383
+
384
+ // ../http/src/Contracts/HttpContract.ts
385
+ var init_HttpContract = __esm({
386
+ "../http/src/Contracts/HttpContract.ts"() {
387
+ "use strict";
388
+ }
389
+ });
390
+
391
+ // ../http/src/Middleware/LogRequests.ts
392
+ var LogRequests;
393
+ var init_LogRequests = __esm({
394
+ "../http/src/Middleware/LogRequests.ts"() {
395
+ "use strict";
396
+ init_src2();
397
+ LogRequests = class extends Middleware {
398
+ static {
399
+ __name(this, "LogRequests");
400
+ }
401
+ async handle({ request }, next) {
402
+ const url = request.getEvent("url");
403
+ console.log(`[${request.getEvent("method")}] ${url.pathname + url.search}`);
404
+ return next();
405
+ }
406
+ };
407
+ }
408
+ });
409
+
410
+ // ../http/src/Providers/HttpServiceProvider.ts
411
+ var import_h33, HttpServiceProvider;
412
+ var init_HttpServiceProvider = __esm({
413
+ "../http/src/Providers/HttpServiceProvider.ts"() {
414
+ "use strict";
415
+ import_h33 = require("h3");
416
+ init_index();
417
+ HttpServiceProvider = class extends ServiceProvider {
418
+ static {
419
+ __name(this, "HttpServiceProvider");
420
+ }
421
+ register() {
422
+ this.app.singleton("http.app", () => {
423
+ return new import_h33.H3();
424
+ });
425
+ this.app.singleton("http.serve", () => import_h33.serve);
426
+ }
427
+ };
428
+ }
429
+ });
430
+
431
+ // ../http/src/Resources/JsonResource.ts
432
+ var JsonResource;
433
+ var init_JsonResource = __esm({
434
+ "../http/src/Resources/JsonResource.ts"() {
435
+ "use strict";
436
+ JsonResource = class {
437
+ static {
438
+ __name(this, "JsonResource");
439
+ }
440
+ event;
441
+ /**
442
+ * The request instance
443
+ */
444
+ request;
445
+ /**
446
+ * The response instance
447
+ */
448
+ response;
449
+ /**
450
+ * The data to send to the client
451
+ */
452
+ resource;
453
+ /**
454
+ * The final response data object
455
+ */
456
+ body = {
457
+ data: {}
458
+ };
459
+ /**
460
+ * Flag to track if response should be sent automatically
461
+ */
462
+ shouldSend = false;
463
+ /**
464
+ * Flag to track if response has been sent
465
+ */
466
+ responseSent = false;
467
+ /**
468
+ * @param req The request instance
469
+ * @param res The response instance
470
+ * @param rsc The data to send to the client
471
+ */
472
+ constructor(event, rsc) {
473
+ this.event = event;
474
+ this.request = event.req;
475
+ this.response = event.res;
476
+ this.resource = rsc;
477
+ for (const key of Object.keys(rsc)) {
478
+ if (!(key in this)) {
479
+ Object.defineProperty(this, key, {
480
+ enumerable: true,
481
+ configurable: true,
482
+ get: /* @__PURE__ */ __name(() => this.resource[key], "get"),
483
+ set: /* @__PURE__ */ __name((value) => {
484
+ this.resource[key] = value;
485
+ }, "set")
486
+ });
487
+ }
488
+ }
489
+ }
490
+ /**
491
+ * Return the data in the expected format
492
+ *
493
+ * @returns
494
+ */
495
+ data() {
496
+ return this.resource;
497
+ }
498
+ /**
499
+ * Build the response object
500
+ * @returns this
501
+ */
502
+ json() {
503
+ this.shouldSend = true;
504
+ this.response.status = 200;
505
+ const resource = this.data();
506
+ let data = Array.isArray(resource) ? [
507
+ ...resource
508
+ ] : {
509
+ ...resource
510
+ };
511
+ if (typeof data.data !== "undefined") {
512
+ data = data.data;
513
+ }
514
+ if (!Array.isArray(resource)) {
515
+ delete data.pagination;
516
+ }
517
+ this.body = {
518
+ data
519
+ };
520
+ if (!Array.isArray(resource) && resource.pagination) {
521
+ const meta = this.body.meta ?? {};
522
+ meta.pagination = resource.pagination;
523
+ this.body.meta = meta;
524
+ }
525
+ if (this.resource.pagination && !this.body.meta?.pagination) {
526
+ const meta = this.body.meta ?? {};
527
+ meta.pagination = this.resource.pagination;
528
+ this.body.meta = meta;
529
+ }
530
+ return this;
531
+ }
532
+ /**
533
+ * Add context data to the response object
534
+ * @param data Context data
535
+ * @returns this
536
+ */
537
+ additional(data) {
538
+ this.shouldSend = true;
539
+ delete data.data;
540
+ delete data.pagination;
541
+ this.body = {
542
+ ...this.body,
543
+ ...data
544
+ };
545
+ return this;
546
+ }
547
+ /**
548
+ * Send the output to the client
549
+ * @returns this
550
+ */
551
+ send() {
552
+ this.shouldSend = false;
553
+ if (!this.responseSent) {
554
+ this.#send();
555
+ }
556
+ return this;
557
+ }
558
+ /**
559
+ * Set the status code for this response
560
+ * @param code Status code
561
+ * @returns this
562
+ */
563
+ status(code) {
564
+ this.response.status = code;
565
+ return this;
566
+ }
567
+ /**
568
+ * Private method to send the response
569
+ */
570
+ #send() {
571
+ if (!this.responseSent) {
572
+ this.event.context.this.response.json(this.body);
573
+ this.responseSent = true;
574
+ }
575
+ }
576
+ /**
577
+ * Check if send should be triggered automatically
578
+ */
579
+ checkSend() {
580
+ if (this.shouldSend && !this.responseSent) {
581
+ this.#send();
582
+ }
583
+ }
584
+ };
585
+ }
586
+ });
587
+
588
+ // ../http/src/Resources/ApiResource.ts
589
+ function ApiResource(instance) {
590
+ return new Proxy(instance, {
591
+ get(target, prop, receiver) {
592
+ const value = Reflect.get(target, prop, receiver);
593
+ if (typeof value === "function") {
594
+ if (prop === "json" || prop === "additional") {
595
+ return (...args) => {
596
+ const result = value.apply(target, args);
597
+ setImmediate(() => target["checkSend"]());
598
+ return result;
599
+ };
600
+ } else if (prop === "send") {
601
+ return (...args) => {
602
+ target["shouldSend"] = false;
603
+ return value.apply(target, args);
604
+ };
605
+ }
606
+ }
607
+ return value;
608
+ }
609
+ });
610
+ }
611
+ var init_ApiResource = __esm({
612
+ "../http/src/Resources/ApiResource.ts"() {
613
+ "use strict";
614
+ init_JsonResource();
615
+ __name(ApiResource, "ApiResource");
616
+ }
617
+ });
618
+
619
+ // ../http/src/index.ts
620
+ var src_exports = {};
621
+ __export(src_exports, {
622
+ ApiResource: () => ApiResource,
623
+ HttpServiceProvider: () => HttpServiceProvider,
624
+ JsonResource: () => JsonResource,
625
+ LogRequests: () => LogRequests,
626
+ Middleware: () => Middleware,
627
+ Request: () => Request,
628
+ Response: () => Response
629
+ });
630
+ var init_src2 = __esm({
631
+ "../http/src/index.ts"() {
632
+ "use strict";
633
+ init_Middleware();
634
+ init_Request();
635
+ init_Response();
636
+ init_ControllerContracts();
637
+ init_HttpContract();
638
+ init_LogRequests();
639
+ init_HttpServiceProvider();
640
+ init_ApiResource();
641
+ init_JsonResource();
642
+ }
643
+ });
644
+
645
+ // ../config/src/ConfigRepository.ts
646
+ var import_node_path, import_promises, ConfigRepository;
647
+ var init_ConfigRepository = __esm({
648
+ "../config/src/ConfigRepository.ts"() {
649
+ "use strict";
650
+ init_src();
651
+ import_node_path = __toESM(require("path"), 1);
652
+ import_promises = require("fs/promises");
653
+ ConfigRepository = class {
654
+ static {
655
+ __name(this, "ConfigRepository");
656
+ }
657
+ app;
658
+ loaded = false;
659
+ configs = {};
660
+ constructor(app) {
661
+ this.app = app;
662
+ }
663
+ get(key, def) {
664
+ return safeDot(this.configs, key) ?? def;
665
+ }
666
+ /**
667
+ * Modify the defined configurations
668
+ */
669
+ set(key, value) {
670
+ setNested(this.configs, key, value);
671
+ }
672
+ async load() {
673
+ if (!this.loaded) {
674
+ const configPath = this.app.getPath("config");
675
+ const files = await (0, import_promises.readdir)(configPath);
676
+ for (let i = 0; i < files.length; i++) {
677
+ const configModule = await import(import_node_path.default.join(configPath, files[i]));
678
+ const name = files[i].replaceAll(/.ts|js/g, "");
679
+ if (typeof configModule.default === "function") {
680
+ this.configs[name] = configModule.default(this.app);
681
+ }
682
+ }
683
+ this.loaded = true;
684
+ }
685
+ return this;
686
+ }
687
+ };
688
+ }
689
+ });
690
+
691
+ // ../config/src/EnvLoader.ts
692
+ var EnvLoader;
693
+ var init_EnvLoader = __esm({
694
+ "../config/src/EnvLoader.ts"() {
695
+ "use strict";
696
+ init_src();
697
+ EnvLoader = class {
698
+ static {
699
+ __name(this, "EnvLoader");
700
+ }
701
+ _app;
702
+ constructor(_app) {
703
+ this._app = _app;
704
+ }
705
+ get(key, def) {
706
+ return safeDot(process.env, key) ?? def;
707
+ }
708
+ };
709
+ }
710
+ });
711
+
712
+ // ../config/src/Helpers.ts
713
+ var init_Helpers = __esm({
714
+ "../config/src/Helpers.ts"() {
715
+ "use strict";
716
+ }
717
+ });
718
+
719
+ // ../../node_modules/.pnpm/dotenv@17.2.1/node_modules/dotenv/package.json
720
+ var require_package = __commonJS({
721
+ "../../node_modules/.pnpm/dotenv@17.2.1/node_modules/dotenv/package.json"(exports2, module2) {
722
+ module2.exports = {
723
+ name: "dotenv",
724
+ version: "17.2.1",
725
+ description: "Loads environment variables from .env file",
726
+ main: "lib/main.js",
727
+ types: "lib/main.d.ts",
728
+ exports: {
729
+ ".": {
730
+ types: "./lib/main.d.ts",
731
+ require: "./lib/main.js",
732
+ default: "./lib/main.js"
733
+ },
734
+ "./config": "./config.js",
735
+ "./config.js": "./config.js",
736
+ "./lib/env-options": "./lib/env-options.js",
737
+ "./lib/env-options.js": "./lib/env-options.js",
738
+ "./lib/cli-options": "./lib/cli-options.js",
739
+ "./lib/cli-options.js": "./lib/cli-options.js",
740
+ "./package.json": "./package.json"
741
+ },
742
+ scripts: {
743
+ "dts-check": "tsc --project tests/types/tsconfig.json",
744
+ lint: "standard",
745
+ pretest: "npm run lint && npm run dts-check",
746
+ test: "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
747
+ "test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=text --coverage-report=lcov",
748
+ prerelease: "npm test",
749
+ release: "standard-version"
750
+ },
751
+ repository: {
752
+ type: "git",
753
+ url: "git://github.com/motdotla/dotenv.git"
754
+ },
755
+ homepage: "https://github.com/motdotla/dotenv#readme",
756
+ funding: "https://dotenvx.com",
757
+ keywords: [
758
+ "dotenv",
759
+ "env",
760
+ ".env",
761
+ "environment",
762
+ "variables",
763
+ "config",
764
+ "settings"
765
+ ],
766
+ readmeFilename: "README.md",
767
+ license: "BSD-2-Clause",
768
+ devDependencies: {
769
+ "@types/node": "^18.11.3",
770
+ decache: "^4.6.2",
771
+ sinon: "^14.0.1",
772
+ standard: "^17.0.0",
773
+ "standard-version": "^9.5.0",
774
+ tap: "^19.2.0",
775
+ typescript: "^4.8.4"
776
+ },
777
+ engines: {
778
+ node: ">=12"
779
+ },
780
+ browser: {
781
+ fs: false
782
+ }
783
+ };
784
+ }
785
+ });
786
+
787
+ // ../../node_modules/.pnpm/dotenv@17.2.1/node_modules/dotenv/lib/main.js
788
+ var require_main = __commonJS({
789
+ "../../node_modules/.pnpm/dotenv@17.2.1/node_modules/dotenv/lib/main.js"(exports2, module2) {
790
+ "use strict";
791
+ var fs = require("fs");
792
+ var path4 = require("path");
793
+ var os = require("os");
794
+ var crypto = require("crypto");
795
+ var packageJson = require_package();
796
+ var version = packageJson.version;
797
+ var TIPS = [
798
+ "\u{1F510} encrypt with Dotenvx: https://dotenvx.com",
799
+ "\u{1F510} prevent committing .env to code: https://dotenvx.com/precommit",
800
+ "\u{1F510} prevent building .env in docker: https://dotenvx.com/prebuild",
801
+ "\u{1F4E1} observe env with Radar: https://dotenvx.com/radar",
802
+ "\u{1F4E1} auto-backup env with Radar: https://dotenvx.com/radar",
803
+ "\u{1F4E1} version env with Radar: https://dotenvx.com/radar",
804
+ "\u{1F6E0}\uFE0F run anywhere with `dotenvx run -- yourcommand`",
805
+ "\u2699\uFE0F specify custom .env file path with { path: '/custom/path/.env' }",
806
+ "\u2699\uFE0F enable debug logging with { debug: true }",
807
+ "\u2699\uFE0F override existing env vars with { override: true }",
808
+ "\u2699\uFE0F suppress all logs with { quiet: true }",
809
+ "\u2699\uFE0F write to custom object with { processEnv: myObject }",
810
+ "\u2699\uFE0F load multiple .env files with { path: ['.env.local', '.env'] }"
811
+ ];
812
+ function _getRandomTip() {
813
+ return TIPS[Math.floor(Math.random() * TIPS.length)];
814
+ }
815
+ __name(_getRandomTip, "_getRandomTip");
816
+ function parseBoolean(value) {
817
+ if (typeof value === "string") {
818
+ return ![
819
+ "false",
820
+ "0",
821
+ "no",
822
+ "off",
823
+ ""
824
+ ].includes(value.toLowerCase());
825
+ }
826
+ return Boolean(value);
827
+ }
828
+ __name(parseBoolean, "parseBoolean");
829
+ function supportsAnsi() {
830
+ return process.stdout.isTTY;
831
+ }
832
+ __name(supportsAnsi, "supportsAnsi");
833
+ function dim(text) {
834
+ return supportsAnsi() ? `\x1B[2m${text}\x1B[0m` : text;
835
+ }
836
+ __name(dim, "dim");
837
+ var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
838
+ function parse(src) {
839
+ const obj = {};
840
+ let lines = src.toString();
841
+ lines = lines.replace(/\r\n?/mg, "\n");
842
+ let match;
843
+ while ((match = LINE.exec(lines)) != null) {
844
+ const key = match[1];
845
+ let value = match[2] || "";
846
+ value = value.trim();
847
+ const maybeQuote = value[0];
848
+ value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
849
+ if (maybeQuote === '"') {
850
+ value = value.replace(/\\n/g, "\n");
851
+ value = value.replace(/\\r/g, "\r");
852
+ }
853
+ obj[key] = value;
854
+ }
855
+ return obj;
856
+ }
857
+ __name(parse, "parse");
858
+ function _parseVault(options) {
859
+ options = options || {};
860
+ const vaultPath = _vaultPath(options);
861
+ options.path = vaultPath;
862
+ const result = DotenvModule.configDotenv(options);
863
+ if (!result.parsed) {
864
+ const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
865
+ err.code = "MISSING_DATA";
866
+ throw err;
867
+ }
868
+ const keys = _dotenvKey(options).split(",");
869
+ const length = keys.length;
870
+ let decrypted;
871
+ for (let i = 0; i < length; i++) {
872
+ try {
873
+ const key = keys[i].trim();
874
+ const attrs = _instructions(result, key);
875
+ decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
876
+ break;
877
+ } catch (error) {
878
+ if (i + 1 >= length) {
879
+ throw error;
880
+ }
881
+ }
882
+ }
883
+ return DotenvModule.parse(decrypted);
884
+ }
885
+ __name(_parseVault, "_parseVault");
886
+ function _warn(message) {
887
+ console.error(`[dotenv@${version}][WARN] ${message}`);
888
+ }
889
+ __name(_warn, "_warn");
890
+ function _debug(message) {
891
+ console.log(`[dotenv@${version}][DEBUG] ${message}`);
892
+ }
893
+ __name(_debug, "_debug");
894
+ function _log(message) {
895
+ console.log(`[dotenv@${version}] ${message}`);
896
+ }
897
+ __name(_log, "_log");
898
+ function _dotenvKey(options) {
899
+ if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
900
+ return options.DOTENV_KEY;
901
+ }
902
+ if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
903
+ return process.env.DOTENV_KEY;
904
+ }
905
+ return "";
906
+ }
907
+ __name(_dotenvKey, "_dotenvKey");
908
+ function _instructions(result, dotenvKey) {
909
+ let uri;
910
+ try {
911
+ uri = new URL(dotenvKey);
912
+ } catch (error) {
913
+ if (error.code === "ERR_INVALID_URL") {
914
+ const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
915
+ err.code = "INVALID_DOTENV_KEY";
916
+ throw err;
917
+ }
918
+ throw error;
919
+ }
920
+ const key = uri.password;
921
+ if (!key) {
922
+ const err = new Error("INVALID_DOTENV_KEY: Missing key part");
923
+ err.code = "INVALID_DOTENV_KEY";
924
+ throw err;
925
+ }
926
+ const environment = uri.searchParams.get("environment");
927
+ if (!environment) {
928
+ const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
929
+ err.code = "INVALID_DOTENV_KEY";
930
+ throw err;
931
+ }
932
+ const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
933
+ const ciphertext = result.parsed[environmentKey];
934
+ if (!ciphertext) {
935
+ const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
936
+ err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
937
+ throw err;
938
+ }
939
+ return {
940
+ ciphertext,
941
+ key
942
+ };
943
+ }
944
+ __name(_instructions, "_instructions");
945
+ function _vaultPath(options) {
946
+ let possibleVaultPath = null;
947
+ if (options && options.path && options.path.length > 0) {
948
+ if (Array.isArray(options.path)) {
949
+ for (const filepath of options.path) {
950
+ if (fs.existsSync(filepath)) {
951
+ possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
952
+ }
953
+ }
954
+ } else {
955
+ possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
956
+ }
957
+ } else {
958
+ possibleVaultPath = path4.resolve(process.cwd(), ".env.vault");
959
+ }
960
+ if (fs.existsSync(possibleVaultPath)) {
961
+ return possibleVaultPath;
962
+ }
963
+ return null;
964
+ }
965
+ __name(_vaultPath, "_vaultPath");
966
+ function _resolveHome(envPath) {
967
+ return envPath[0] === "~" ? path4.join(os.homedir(), envPath.slice(1)) : envPath;
968
+ }
969
+ __name(_resolveHome, "_resolveHome");
970
+ function _configVault(options) {
971
+ const debug = parseBoolean(process.env.DOTENV_CONFIG_DEBUG || options && options.debug);
972
+ const quiet = parseBoolean(process.env.DOTENV_CONFIG_QUIET || options && options.quiet);
973
+ if (debug || !quiet) {
974
+ _log("Loading env from encrypted .env.vault");
975
+ }
976
+ const parsed = DotenvModule._parseVault(options);
977
+ let processEnv = process.env;
978
+ if (options && options.processEnv != null) {
979
+ processEnv = options.processEnv;
980
+ }
981
+ DotenvModule.populate(processEnv, parsed, options);
982
+ return {
983
+ parsed
984
+ };
985
+ }
986
+ __name(_configVault, "_configVault");
987
+ function configDotenv(options) {
988
+ const dotenvPath = path4.resolve(process.cwd(), ".env");
989
+ let encoding = "utf8";
990
+ let processEnv = process.env;
991
+ if (options && options.processEnv != null) {
992
+ processEnv = options.processEnv;
993
+ }
994
+ let debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || options && options.debug);
995
+ let quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || options && options.quiet);
996
+ if (options && options.encoding) {
997
+ encoding = options.encoding;
998
+ } else {
999
+ if (debug) {
1000
+ _debug("No encoding is specified. UTF-8 is used by default");
1001
+ }
1002
+ }
1003
+ let optionPaths = [
1004
+ dotenvPath
1005
+ ];
1006
+ if (options && options.path) {
1007
+ if (!Array.isArray(options.path)) {
1008
+ optionPaths = [
1009
+ _resolveHome(options.path)
1010
+ ];
1011
+ } else {
1012
+ optionPaths = [];
1013
+ for (const filepath of options.path) {
1014
+ optionPaths.push(_resolveHome(filepath));
1015
+ }
1016
+ }
1017
+ }
1018
+ let lastError;
1019
+ const parsedAll = {};
1020
+ for (const path5 of optionPaths) {
1021
+ try {
1022
+ const parsed = DotenvModule.parse(fs.readFileSync(path5, {
1023
+ encoding
1024
+ }));
1025
+ DotenvModule.populate(parsedAll, parsed, options);
1026
+ } catch (e) {
1027
+ if (debug) {
1028
+ _debug(`Failed to load ${path5} ${e.message}`);
1029
+ }
1030
+ lastError = e;
1031
+ }
1032
+ }
1033
+ const populated = DotenvModule.populate(processEnv, parsedAll, options);
1034
+ debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || debug);
1035
+ quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || quiet);
1036
+ if (debug || !quiet) {
1037
+ const keysCount = Object.keys(populated).length;
1038
+ const shortPaths = [];
1039
+ for (const filePath of optionPaths) {
1040
+ try {
1041
+ const relative = path4.relative(process.cwd(), filePath);
1042
+ shortPaths.push(relative);
1043
+ } catch (e) {
1044
+ if (debug) {
1045
+ _debug(`Failed to load ${filePath} ${e.message}`);
1046
+ }
1047
+ lastError = e;
1048
+ }
1049
+ }
1050
+ _log(`injecting env (${keysCount}) from ${shortPaths.join(",")} ${dim(`-- tip: ${_getRandomTip()}`)}`);
1051
+ }
1052
+ if (lastError) {
1053
+ return {
1054
+ parsed: parsedAll,
1055
+ error: lastError
1056
+ };
1057
+ } else {
1058
+ return {
1059
+ parsed: parsedAll
1060
+ };
1061
+ }
1062
+ }
1063
+ __name(configDotenv, "configDotenv");
1064
+ function config(options) {
1065
+ if (_dotenvKey(options).length === 0) {
1066
+ return DotenvModule.configDotenv(options);
1067
+ }
1068
+ const vaultPath = _vaultPath(options);
1069
+ if (!vaultPath) {
1070
+ _warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
1071
+ return DotenvModule.configDotenv(options);
1072
+ }
1073
+ return DotenvModule._configVault(options);
1074
+ }
1075
+ __name(config, "config");
1076
+ function decrypt(encrypted, keyStr) {
1077
+ const key = Buffer.from(keyStr.slice(-64), "hex");
1078
+ let ciphertext = Buffer.from(encrypted, "base64");
1079
+ const nonce = ciphertext.subarray(0, 12);
1080
+ const authTag = ciphertext.subarray(-16);
1081
+ ciphertext = ciphertext.subarray(12, -16);
1082
+ try {
1083
+ const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
1084
+ aesgcm.setAuthTag(authTag);
1085
+ return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
1086
+ } catch (error) {
1087
+ const isRange = error instanceof RangeError;
1088
+ const invalidKeyLength = error.message === "Invalid key length";
1089
+ const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
1090
+ if (isRange || invalidKeyLength) {
1091
+ const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
1092
+ err.code = "INVALID_DOTENV_KEY";
1093
+ throw err;
1094
+ } else if (decryptionFailed) {
1095
+ const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
1096
+ err.code = "DECRYPTION_FAILED";
1097
+ throw err;
1098
+ } else {
1099
+ throw error;
1100
+ }
1101
+ }
1102
+ }
1103
+ __name(decrypt, "decrypt");
1104
+ function populate(processEnv, parsed, options = {}) {
1105
+ const debug = Boolean(options && options.debug);
1106
+ const override = Boolean(options && options.override);
1107
+ const populated = {};
1108
+ if (typeof parsed !== "object") {
1109
+ const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
1110
+ err.code = "OBJECT_REQUIRED";
1111
+ throw err;
1112
+ }
1113
+ for (const key of Object.keys(parsed)) {
1114
+ if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
1115
+ if (override === true) {
1116
+ processEnv[key] = parsed[key];
1117
+ populated[key] = parsed[key];
1118
+ }
1119
+ if (debug) {
1120
+ if (override === true) {
1121
+ _debug(`"${key}" is already defined and WAS overwritten`);
1122
+ } else {
1123
+ _debug(`"${key}" is already defined and was NOT overwritten`);
1124
+ }
1125
+ }
1126
+ } else {
1127
+ processEnv[key] = parsed[key];
1128
+ populated[key] = parsed[key];
1129
+ }
1130
+ }
1131
+ return populated;
1132
+ }
1133
+ __name(populate, "populate");
1134
+ var DotenvModule = {
1135
+ configDotenv,
1136
+ _configVault,
1137
+ _parseVault,
1138
+ config,
1139
+ decrypt,
1140
+ parse,
1141
+ populate
1142
+ };
1143
+ module2.exports.configDotenv = DotenvModule.configDotenv;
1144
+ module2.exports._configVault = DotenvModule._configVault;
1145
+ module2.exports._parseVault = DotenvModule._parseVault;
1146
+ module2.exports.config = DotenvModule.config;
1147
+ module2.exports.decrypt = DotenvModule.decrypt;
1148
+ module2.exports.parse = DotenvModule.parse;
1149
+ module2.exports.populate = DotenvModule.populate;
1150
+ module2.exports = DotenvModule;
1151
+ }
1152
+ });
1153
+
1154
+ // ../config/src/Providers/ConfigServiceProvider.ts
1155
+ var import_dotenv, ConfigServiceProvider;
1156
+ var init_ConfigServiceProvider = __esm({
1157
+ "../config/src/Providers/ConfigServiceProvider.ts"() {
1158
+ "use strict";
1159
+ init_index();
1160
+ init_src3();
1161
+ import_dotenv = __toESM(require_main(), 1);
1162
+ ConfigServiceProvider = class extends ServiceProvider {
1163
+ static {
1164
+ __name(this, "ConfigServiceProvider");
1165
+ }
1166
+ async register() {
1167
+ (0, import_dotenv.config)();
1168
+ this.app.singleton("env", () => {
1169
+ return new EnvLoader(this.app).get;
1170
+ });
1171
+ const repo = new ConfigRepository(this.app);
1172
+ await repo.load();
1173
+ this.app.singleton("config", () => {
1174
+ return {
1175
+ get: /* @__PURE__ */ __name((key, def) => repo.get(key, def), "get"),
1176
+ set: repo.set
1177
+ };
1178
+ });
1179
+ this.app.make("http.app").use((e) => {
1180
+ repo.set("app.url", e.url.origin);
1181
+ });
1182
+ }
1183
+ };
1184
+ }
1185
+ });
1186
+
1187
+ // ../config/src/index.ts
1188
+ var src_exports2 = {};
1189
+ __export(src_exports2, {
1190
+ ConfigRepository: () => ConfigRepository,
1191
+ ConfigServiceProvider: () => ConfigServiceProvider,
1192
+ EnvLoader: () => EnvLoader
1193
+ });
1194
+ var init_src3 = __esm({
1195
+ "../config/src/index.ts"() {
1196
+ "use strict";
1197
+ init_ConfigRepository();
1198
+ init_EnvLoader();
1199
+ init_Helpers();
1200
+ init_ConfigServiceProvider();
1201
+ }
1202
+ });
1203
+
1204
+ // ../router/src/Controller.ts
1205
+ var init_Controller = __esm({
1206
+ "../router/src/Controller.ts"() {
1207
+ "use strict";
1208
+ }
1209
+ });
1210
+
1211
+ // ../router/src/Route.ts
1212
+ var init_Route = __esm({
1213
+ "../router/src/Route.ts"() {
1214
+ "use strict";
1215
+ }
1216
+ });
1217
+
1218
+ // ../router/src/Router.ts
1219
+ var Router;
1220
+ var init_Router = __esm({
1221
+ "../router/src/Router.ts"() {
1222
+ "use strict";
1223
+ init_index();
1224
+ init_src();
1225
+ Router = class {
1226
+ static {
1227
+ __name(this, "Router");
1228
+ }
1229
+ h3App;
1230
+ app;
1231
+ routes = [];
1232
+ groupPrefix = "";
1233
+ groupMiddleware = [];
1234
+ constructor(h3App, app) {
1235
+ this.h3App = h3App;
1236
+ this.app = app;
1237
+ }
1238
+ /**
1239
+ * Route Resolver
1240
+ *
1241
+ * @param handler
1242
+ * @param middleware
1243
+ * @returns
1244
+ */
1245
+ resolveHandler(handler, middleware = []) {
1246
+ return async (event) => {
1247
+ const kernel = new Kernel(middleware);
1248
+ return kernel.handle(event, (ctx) => Promise.resolve(handler(ctx)));
1249
+ };
1250
+ }
1251
+ /**
1252
+ * Add a route to the stack
1253
+ *
1254
+ * @param method
1255
+ * @param path
1256
+ * @param handler
1257
+ * @param name
1258
+ * @param middleware
1259
+ */
1260
+ addRoute(method, path4, handler, name, middleware = []) {
1261
+ const fullPath = `${this.groupPrefix}${path4}`.replace(/\/+/g, "/");
1262
+ this.routes.push({
1263
+ method,
1264
+ path: fullPath,
1265
+ name,
1266
+ handler
1267
+ });
1268
+ this.h3App[method](fullPath, this.resolveHandler(handler, middleware));
1269
+ }
1270
+ resolveControllerOrHandler(handler, methodName) {
1271
+ if (typeof handler === "function" && handler.prototype instanceof Controller) {
1272
+ return (ctx) => {
1273
+ const controller = new handler(this.app);
1274
+ const action = methodName || "index";
1275
+ if (typeof controller[action] !== "function") {
1276
+ throw new Error(`Method "${action}" not found on controller ${handler.name}`);
1277
+ }
1278
+ return controller[action](ctx);
1279
+ };
1280
+ }
1281
+ return handler;
1282
+ }
1283
+ get(path4, handler, methodName, name, middleware = []) {
1284
+ this.addRoute("get", path4, this.resolveControllerOrHandler(handler, methodName), name, middleware);
1285
+ }
1286
+ post(path4, handler, methodName, name, middleware = []) {
1287
+ this.addRoute("post", path4, this.resolveControllerOrHandler(handler, methodName), name, middleware);
1288
+ }
1289
+ put(path4, handler, methodName, name, middleware = []) {
1290
+ this.addRoute("put", path4, this.resolveControllerOrHandler(handler, methodName), name, middleware);
1291
+ }
1292
+ delete(path4, handler, methodName, name, middleware = []) {
1293
+ this.addRoute("delete", path4, this.resolveControllerOrHandler(handler, methodName), name, middleware);
1294
+ }
1295
+ /**
1296
+ * API Resource support
1297
+ *
1298
+ * @param path
1299
+ * @param controller
1300
+ */
1301
+ apiResource(path4, Controller2, middleware = []) {
1302
+ path4 = path4.replace(/\//g, "/");
1303
+ const name = afterLast(path4, "/");
1304
+ const basePath = `/${path4}`.replace(/\/+/g, "/");
1305
+ const controller = new Controller2(this.app);
1306
+ this.addRoute("get", basePath, controller.index.bind(controller), `${name}.index`, middleware);
1307
+ this.addRoute("post", basePath, controller.store.bind(controller), `${name}.store`, middleware);
1308
+ this.addRoute("get", `${basePath}/:id`, controller.show.bind(controller), `${name}.show`, middleware);
1309
+ this.addRoute("put", `${basePath}/:id`, controller.update.bind(controller), `${name}.update`, middleware);
1310
+ this.addRoute("patch", `${basePath}/:id`, controller.update.bind(controller), `${name}.update`, middleware);
1311
+ this.addRoute("delete", `${basePath}/:id`, controller.destroy.bind(controller), `${name}.destroy`, middleware);
1312
+ }
1313
+ /**
1314
+ * Named route URL generator
1315
+ *
1316
+ * @param name
1317
+ * @param params
1318
+ * @returns
1319
+ */
1320
+ route(name, params = {}) {
1321
+ const found = this.routes.find((r) => r.name === name);
1322
+ if (!found) return void 0;
1323
+ let url = found.path;
1324
+ for (const [key, value] of Object.entries(params)) {
1325
+ url = url.replace(`:${key}`, value);
1326
+ }
1327
+ return url;
1328
+ }
1329
+ /**
1330
+ * Grouping
1331
+ *
1332
+ * @param options
1333
+ * @param callback
1334
+ */
1335
+ group(options, callback) {
1336
+ const prevPrefix = this.groupPrefix;
1337
+ const prevMiddleware = [
1338
+ ...this.groupMiddleware
1339
+ ];
1340
+ this.groupPrefix += options.prefix || "";
1341
+ this.groupMiddleware.push(...options.middleware || []);
1342
+ callback();
1343
+ this.groupPrefix = prevPrefix;
1344
+ this.groupMiddleware = prevMiddleware;
1345
+ }
1346
+ middleware(path4, handler, opts) {
1347
+ this.h3App.use(path4, handler, opts);
1348
+ }
1349
+ };
1350
+ }
1351
+ });
1352
+
1353
+ // ../router/src/Decorators/ApiResource.ts
1354
+ var init_ApiResource2 = __esm({
1355
+ "../router/src/Decorators/ApiResource.ts"() {
1356
+ "use strict";
1357
+ }
1358
+ });
1359
+
1360
+ // ../router/src/Decorators/Controller.ts
1361
+ var init_Controller2 = __esm({
1362
+ "../router/src/Decorators/Controller.ts"() {
1363
+ "use strict";
1364
+ }
1365
+ });
1366
+
1367
+ // ../router/src/Decorators/Get.ts
1368
+ var init_Get = __esm({
1369
+ "../router/src/Decorators/Get.ts"() {
1370
+ "use strict";
1371
+ }
1372
+ });
1373
+
1374
+ // ../router/src/Decorators/Middleware.ts
1375
+ var init_Middleware2 = __esm({
1376
+ "../router/src/Decorators/Middleware.ts"() {
1377
+ "use strict";
1378
+ }
1379
+ });
1380
+
1381
+ // ../router/src/Decorators/Post.ts
1382
+ var init_Post = __esm({
1383
+ "../router/src/Decorators/Post.ts"() {
1384
+ "use strict";
1385
+ }
1386
+ });
1387
+
1388
+ // ../router/src/Providers/AssetsServiceProvider.ts
1389
+ var import_promises2, import_node_path2, import_h34, import_node_fs, AssetsServiceProvider;
1390
+ var init_AssetsServiceProvider = __esm({
1391
+ "../router/src/Providers/AssetsServiceProvider.ts"() {
1392
+ "use strict";
1393
+ import_promises2 = require("fs/promises");
1394
+ init_index();
1395
+ init_src();
1396
+ import_node_path2 = require("path");
1397
+ import_h34 = require("h3");
1398
+ import_node_fs = require("fs");
1399
+ AssetsServiceProvider = class extends ServiceProvider {
1400
+ static {
1401
+ __name(this, "AssetsServiceProvider");
1402
+ }
1403
+ register() {
1404
+ const app = this.app.make("router");
1405
+ const config = this.app.make("config");
1406
+ const fsconfig = config.get("filesystem");
1407
+ const publicPath = this.app.getPath("public");
1408
+ app.middleware(`/${fsconfig.public_mask}/**`, (event) => {
1409
+ return (0, import_h34.serveStatic)(event, {
1410
+ indexNames: [
1411
+ "/index.html"
1412
+ ],
1413
+ getContents: /* @__PURE__ */ __name((id) => {
1414
+ const newId = id.replace(`/${fsconfig.public_mask}/`, "");
1415
+ return (0, import_promises2.readFile)((0, import_node_path2.join)(before(publicPath, newId), newId));
1416
+ }, "getContents"),
1417
+ getMeta: /* @__PURE__ */ __name(async (id) => {
1418
+ const newId = id.replace(`/${fsconfig.public_mask}/`, "");
1419
+ const stats = await (0, import_promises2.stat)((0, import_node_path2.join)(before(publicPath, newId), newId)).catch(() => {
1420
+ });
1421
+ if (stats?.isFile()) {
1422
+ return {
1423
+ size: stats.size,
1424
+ mtime: stats.mtimeMs
1425
+ };
1426
+ }
1427
+ }, "getMeta")
1428
+ });
1429
+ });
1430
+ this.app.singleton("asset", () => {
1431
+ return (key, def = "") => {
1432
+ try {
1433
+ (0, import_node_fs.statSync)((0, import_node_path2.join)(before(publicPath, key), key));
1434
+ } catch {
1435
+ key = def;
1436
+ }
1437
+ return (0, import_node_path2.join)(fsconfig.public_mask, key);
1438
+ };
1439
+ });
1440
+ }
1441
+ };
1442
+ }
1443
+ });
1444
+
1445
+ // ../router/src/Providers/RouteServiceProvider.ts
1446
+ var import_node_path3, import_promises3, RouteServiceProvider;
1447
+ var init_RouteServiceProvider = __esm({
1448
+ "../router/src/Providers/RouteServiceProvider.ts"() {
1449
+ "use strict";
1450
+ init_Router();
1451
+ init_index();
1452
+ import_node_path3 = __toESM(require("path"), 1);
1453
+ import_promises3 = require("fs/promises");
1454
+ RouteServiceProvider = class extends ServiceProvider {
1455
+ static {
1456
+ __name(this, "RouteServiceProvider");
1457
+ }
1458
+ register() {
1459
+ this.app.singleton("router", () => {
1460
+ const h3App = this.app.make("http.app");
1461
+ return new Router(h3App, this.app);
1462
+ });
1463
+ }
1464
+ /**
1465
+ * Load routes from src/routes
1466
+ */
1467
+ async boot() {
1468
+ try {
1469
+ const routePath = this.app.getPath("routes");
1470
+ const files = await (0, import_promises3.readdir)(routePath);
1471
+ for (let i = 0; i < files.length; i++) {
1472
+ const routesModule = await import(import_node_path3.default.join(routePath, files[i]));
1473
+ if (typeof routesModule.default === "function") {
1474
+ const router = this.app.make("router");
1475
+ routesModule.default(router);
1476
+ }
1477
+ }
1478
+ } catch (e) {
1479
+ console.warn("No web routes found or failed to load:", e);
1480
+ }
1481
+ }
1482
+ };
1483
+ }
1484
+ });
1485
+
1486
+ // ../router/src/index.ts
1487
+ var src_exports3 = {};
1488
+ __export(src_exports3, {
1489
+ AssetsServiceProvider: () => AssetsServiceProvider,
1490
+ RouteServiceProvider: () => RouteServiceProvider,
1491
+ Router: () => Router
1492
+ });
1493
+ var init_src4 = __esm({
1494
+ "../router/src/index.ts"() {
1495
+ "use strict";
1496
+ init_Controller();
1497
+ init_Route();
1498
+ init_Router();
1499
+ init_ApiResource2();
1500
+ init_Controller2();
1501
+ init_Get();
1502
+ init_Middleware2();
1503
+ init_Post();
1504
+ init_AssetsServiceProvider();
1505
+ init_RouteServiceProvider();
1506
+ }
1507
+ });
1508
+
1509
+ // src/Application.ts
1510
+ var import_node_path4, Application;
1511
+ var init_Application = __esm({
1512
+ "src/Application.ts"() {
1513
+ "use strict";
1514
+ init_Container();
1515
+ init_PathLoader();
1516
+ import_node_path4 = __toESM(require("path"), 1);
1517
+ Application = class _Application extends Container {
1518
+ static {
1519
+ __name(this, "Application");
1520
+ }
1521
+ paths = new PathLoader();
1522
+ booted = false;
1523
+ versions = {
1524
+ app: "0",
1525
+ ts: "0"
1526
+ };
1527
+ basePath;
1528
+ providers = [];
1529
+ externalProviders = [];
1530
+ constructor(basePath) {
1531
+ super();
1532
+ this.basePath = basePath;
1533
+ this.setPath("base", basePath);
1534
+ this.loadOptions();
1535
+ this.registerBaseBindings();
1536
+ }
1537
+ /**
1538
+ * Register core bindings into the container
1539
+ */
1540
+ registerBaseBindings() {
1541
+ this.bind(_Application, () => this);
1542
+ this.bind("path.base", () => this.basePath);
1543
+ this.bind("app.paths", () => this.paths);
1544
+ }
1545
+ /**
1546
+ * Dynamically register all configured providers
1547
+ */
1548
+ async registerConfiguredProviders() {
1549
+ const providers = await this.getAllProviders();
1550
+ for (const ProviderClass of providers) {
1551
+ if (!ProviderClass) continue;
1552
+ const provider = new ProviderClass(this);
1553
+ await this.register(provider);
1554
+ }
1555
+ }
1556
+ async loadOptions() {
1557
+ const app = await this.safeImport(this.getPath("base", "package.json"));
1558
+ const core = await this.safeImport("../package.json");
1559
+ if (app && app.dependencies) {
1560
+ this.versions.app = app.dependencies["@h3ravel/core"];
1561
+ }
1562
+ if (core && core.devDependencies) {
1563
+ this.versions.ts = app.devDependencies.typescript;
1564
+ }
1565
+ }
1566
+ /**
1567
+ * Load default and optional providers dynamically
1568
+ *
1569
+ * Auto-Registration Behavior
1570
+ *
1571
+ * Minimal App: Loads only core, config, http, router by default.
1572
+ * Full-Stack App: Installs database, mail, queue, cache → they self-register via their providers.
1573
+ */
1574
+ async getConfiguredProviders() {
1575
+ return [
1576
+ (await Promise.resolve().then(() => (init_index(), index_exports))).AppServiceProvider,
1577
+ (await Promise.resolve().then(() => (init_src2(), src_exports))).HttpServiceProvider,
1578
+ (await Promise.resolve().then(() => (init_src3(), src_exports2))).ConfigServiceProvider,
1579
+ (await Promise.resolve().then(() => (init_src4(), src_exports3))).RouteServiceProvider,
1580
+ (await Promise.resolve().then(() => (init_src4(), src_exports3))).AssetsServiceProvider,
1581
+ (await Promise.resolve().then(() => (init_index(), index_exports))).ViewServiceProvider,
1582
+ (await this.safeImport("@h3ravel/database"))?.DatabaseServiceProvider,
1583
+ (await this.safeImport("@h3ravel/cache"))?.CacheServiceProvider,
1584
+ (await this.safeImport("@h3ravel/console"))?.ConsoleServiceProvider,
1585
+ (await this.safeImport("@h3ravel/queue"))?.QueueServiceProvider,
1586
+ (await this.safeImport("@h3ravel/mail"))?.MailServiceProvider
1587
+ ];
1588
+ }
1589
+ async getAllProviders() {
1590
+ const coreProviders = await this.getConfiguredProviders();
1591
+ return [
1592
+ ...coreProviders,
1593
+ ...this.externalProviders
1594
+ ];
1595
+ }
1596
+ registerProviders(providers) {
1597
+ this.externalProviders.push(...providers);
1598
+ }
1599
+ /**
1600
+ * Register a provider
1601
+ */
1602
+ async register(provider) {
1603
+ await provider.register();
1604
+ this.providers.push(provider);
1605
+ }
1606
+ /**
1607
+ * Boot all providers after registration
1608
+ */
1609
+ async boot() {
1610
+ if (this.booted) return;
1611
+ for (const provider of this.providers) {
1612
+ if (provider.boot) {
1613
+ await provider.boot();
1614
+ }
1615
+ }
1616
+ this.booted = true;
1617
+ }
1618
+ /**
1619
+ * Attempt to dynamically import an optional module
1620
+ */
1621
+ async safeImport(moduleName) {
1622
+ try {
1623
+ const mod = await import(moduleName);
1624
+ return mod.default ?? mod;
1625
+ } catch {
1626
+ return null;
1627
+ }
1628
+ }
1629
+ /**
1630
+ * Get the base path of the app
1631
+ *
1632
+ * @returns
1633
+ */
1634
+ getBasePath() {
1635
+ return this.basePath;
1636
+ }
1637
+ /**
1638
+ * Dynamically retrieves a path property from the class.
1639
+ * Any property ending with "Path" is accessible automatically.
1640
+ *
1641
+ * @param name - The base name of the path property
1642
+ * @returns
1643
+ */
1644
+ getPath(name, pth) {
1645
+ return import_node_path4.default.join(this.paths.getPath(name, this.basePath), pth ?? "");
1646
+ }
1647
+ /**
1648
+ * Programatically set the paths.
1649
+ *
1650
+ * @param name - The base name of the path property
1651
+ * @param path - The new path
1652
+ * @returns
1653
+ */
1654
+ setPath(name, path4) {
1655
+ return this.paths.setPath(name, path4, this.basePath);
1656
+ }
1657
+ /**
1658
+ * Returns the installed version of the system core and typescript.
1659
+ *
1660
+ * @returns
1661
+ */
1662
+ getVersion(key) {
1663
+ return this.versions[key]?.replaceAll(/\^|\~/g, "");
1664
+ }
1665
+ };
1666
+ }
1667
+ });
1668
+
1669
+ // src/Controller.ts
1670
+ var Controller;
1671
+ var init_Controller3 = __esm({
1672
+ "src/Controller.ts"() {
1673
+ "use strict";
1674
+ Controller = class {
1675
+ static {
1676
+ __name(this, "Controller");
1677
+ }
1678
+ app;
1679
+ constructor(app) {
1680
+ this.app = app;
1681
+ }
1682
+ show(_ctx) {
1683
+ return;
1684
+ }
1685
+ index(_ctx) {
1686
+ return;
1687
+ }
1688
+ store(_ctx) {
1689
+ return;
1690
+ }
1691
+ update(_ctx) {
1692
+ return;
1693
+ }
1694
+ destroy(_ctx) {
1695
+ return;
1696
+ }
1697
+ };
1698
+ }
1699
+ });
1700
+
1701
+ // src/ServiceProvider.ts
1702
+ var ServiceProvider;
1703
+ var init_ServiceProvider = __esm({
1704
+ "src/ServiceProvider.ts"() {
1705
+ "use strict";
1706
+ ServiceProvider = class {
1707
+ static {
1708
+ __name(this, "ServiceProvider");
1709
+ }
1710
+ app;
1711
+ constructor(app) {
1712
+ this.app = app;
1713
+ }
1714
+ };
1715
+ }
1716
+ });
1717
+
1718
+ // src/Contracts/BindingsContract.ts
1719
+ var init_BindingsContract = __esm({
1720
+ "src/Contracts/BindingsContract.ts"() {
1721
+ "use strict";
1722
+ }
1723
+ });
1724
+
1725
+ // src/Exceptions/Handler.ts
1726
+ var init_Handler = __esm({
1727
+ "src/Exceptions/Handler.ts"() {
1728
+ "use strict";
1729
+ }
1730
+ });
1731
+
1732
+ // src/Http/Kernel.ts
1733
+ var Kernel;
1734
+ var init_Kernel = __esm({
1735
+ "src/Http/Kernel.ts"() {
1736
+ "use strict";
1737
+ init_src2();
1738
+ Kernel = class {
1739
+ static {
1740
+ __name(this, "Kernel");
1741
+ }
1742
+ middleware;
1743
+ constructor(middleware = []) {
1744
+ this.middleware = middleware;
1745
+ }
1746
+ async handle(event, next) {
1747
+ const context = {
1748
+ request: new Request(event),
1749
+ response: new Response(event)
1750
+ };
1751
+ const result = await this.runMiddleware(context, () => next(context));
1752
+ if (result !== void 0 && this.isPlainObject(result)) {
1753
+ event.res.headers.set("Content-Type", "application/json; charset=UTF-8");
1754
+ }
1755
+ return result;
1756
+ }
1757
+ async runMiddleware(context, next) {
1758
+ let index = -1;
1759
+ const runner = /* @__PURE__ */ __name(async (i) => {
1760
+ if (i <= index) throw new Error("next() called multiple times");
1761
+ index = i;
1762
+ const middleware = this.middleware[i];
1763
+ if (middleware) {
1764
+ return middleware.handle(context, () => runner(i + 1));
1765
+ } else {
1766
+ return next(context);
1767
+ }
1768
+ }, "runner");
1769
+ return runner(0);
1770
+ }
1771
+ isPlainObject(value) {
1772
+ return typeof value === "object" && value !== null && (value.constructor === Object || value.constructor === Array);
1773
+ }
1774
+ };
1775
+ }
1776
+ });
1777
+
1778
+ // src/Providers/AppServiceProvider.ts
1779
+ var import_reflect_metadata, AppServiceProvider;
1780
+ var init_AppServiceProvider = __esm({
1781
+ "src/Providers/AppServiceProvider.ts"() {
1782
+ "use strict";
1783
+ import_reflect_metadata = require("reflect-metadata");
1784
+ init_ServiceProvider();
1785
+ AppServiceProvider = class extends ServiceProvider {
1786
+ static {
1787
+ __name(this, "AppServiceProvider");
1788
+ }
1789
+ register() {
1790
+ }
1791
+ };
1792
+ }
1793
+ });
1794
+
1795
+ // src/Providers/ViewServiceProvider.ts
1796
+ var import_edge, ViewServiceProvider;
1797
+ var init_ViewServiceProvider = __esm({
1798
+ "src/Providers/ViewServiceProvider.ts"() {
1799
+ "use strict";
1800
+ import_edge = require("edge.js");
1801
+ init_index();
1802
+ ViewServiceProvider = class extends ServiceProvider {
1803
+ static {
1804
+ __name(this, "ViewServiceProvider");
1805
+ }
1806
+ register() {
1807
+ const config = this.app.make("config");
1808
+ const edge = import_edge.Edge.create({
1809
+ cache: process.env.NODE_ENV === "production"
1810
+ });
1811
+ edge.mount(this.app.getPath("views"));
1812
+ edge.global("asset", this.app.make("asset"));
1813
+ edge.global("config", config.get);
1814
+ edge.global("app", this.app);
1815
+ this.app.bind("view", () => edge);
1816
+ }
1817
+ };
1818
+ }
1819
+ });
1820
+
1821
+ // src/index.ts
1822
+ var index_exports = {};
1823
+ __export(index_exports, {
1824
+ AppServiceProvider: () => AppServiceProvider,
1825
+ Application: () => Application,
1826
+ Container: () => Container,
1827
+ Controller: () => Controller,
1828
+ Kernel: () => Kernel,
1829
+ PathLoader: () => PathLoader,
1830
+ ServiceProvider: () => ServiceProvider,
1831
+ ViewServiceProvider: () => ViewServiceProvider
1832
+ });
1833
+ module.exports = __toCommonJS(index_exports);
1834
+ var init_index = __esm({
1835
+ "src/index.ts"() {
1836
+ init_Application();
1837
+ init_Container();
1838
+ init_Controller3();
1839
+ init_ServiceProvider();
1840
+ init_BindingsContract();
1841
+ init_Handler();
1842
+ init_Kernel();
1843
+ init_AppServiceProvider();
1844
+ init_ViewServiceProvider();
1845
+ init_PathLoader();
1846
+ }
1847
+ });
1848
+ init_index();
1849
+ // Annotate the CommonJS export names for ESM import in node:
1850
+ 0 && (module.exports = {
1851
+ AppServiceProvider,
1852
+ Application,
1853
+ Container,
1854
+ Controller,
1855
+ Kernel,
1856
+ PathLoader,
1857
+ ServiceProvider,
1858
+ ViewServiceProvider
1859
+ });
1860
+ //# sourceMappingURL=index.cjs.map