@h3ravel/support 0.15.6 → 0.16.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,19 @@
1
+
2
+ //#region src/Exceptions/RuntimeException.ts
3
+ /**
4
+ * Exception thrown if an error which can only be found on runtime occurs.
5
+ */
6
+ var RuntimeException = class extends Error {
7
+ constructor(message = "") {
8
+ super(message);
9
+ this.name = "RuntimeException";
10
+ }
11
+ };
12
+
13
+ //#endregion
14
+ Object.defineProperty(exports, 'RuntimeException', {
15
+ enumerable: true,
16
+ get: function () {
17
+ return RuntimeException;
18
+ }
19
+ });
@@ -0,0 +1,13 @@
1
+ //#region src/Exceptions/RuntimeException.ts
2
+ /**
3
+ * Exception thrown if an error which can only be found on runtime occurs.
4
+ */
5
+ var RuntimeException = class extends Error {
6
+ constructor(message = "") {
7
+ super(message);
8
+ this.name = "RuntimeException";
9
+ }
10
+ };
11
+
12
+ //#endregion
13
+ export { RuntimeException as t };
@@ -0,0 +1,20 @@
1
+ import "node:module";
2
+
3
+ //#region rolldown:runtime
4
+ var __defProp = Object.defineProperty;
5
+ var __export = (all, symbols) => {
6
+ let target = {};
7
+ for (var name in all) {
8
+ __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ }
13
+ if (symbols) {
14
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
15
+ }
16
+ return target;
17
+ };
18
+
19
+ //#endregion
20
+ export { __export as t };
@@ -0,0 +1,111 @@
1
+ const require_RuntimeException = require('./RuntimeException-CmsL83ow.cjs');
2
+ const require_index = require('./index.cjs');
3
+ let __h3ravel_foundation = require("@h3ravel/foundation");
4
+
5
+ //#region src/Facades/Facades.ts
6
+ var Facades = class {
7
+ /**
8
+ * The application instance being facaded.
9
+ */
10
+ static app;
11
+ /**
12
+ * The resolved object instances.
13
+ */
14
+ static resolvedInstance = /* @__PURE__ */ new Map();
15
+ /**
16
+ * Indicates if the resolved instance should be cached.
17
+ */
18
+ static cached = true;
19
+ /**
20
+ * Called once during bootstrap
21
+ *
22
+ * @param app
23
+ */
24
+ static setApplication(app) {
25
+ this.app = app;
26
+ }
27
+ /**
28
+ * Get the application instance behind the facade.
29
+ */
30
+ static getApplication() {
31
+ return this.app;
32
+ }
33
+ /**
34
+ * Get the registered name of the component.
35
+ * Each facade must define its container key
36
+ *
37
+ * @return string
38
+ *
39
+ * @throws {RuntimeException}
40
+ */
41
+ static getFacadeAccessor() {
42
+ throw new require_RuntimeException.RuntimeException("Facade accessor not implemented.");
43
+ }
44
+ /**
45
+ * Get the root object behind the facade.
46
+ */
47
+ static getFacadeRoot() {
48
+ return this.resolveInstance(this.getFacadeAccessor());
49
+ }
50
+ /**
51
+ * Resolve the facade root instance from the container.
52
+ *
53
+ * @param name
54
+ */
55
+ static resolveInstance(name) {
56
+ if (this.resolvedInstance.has(name)) return this.resolvedInstance.get(name);
57
+ if (this.app) {
58
+ const instance = this.app.make(name);
59
+ if (this.cached) this.resolvedInstance.set(name, instance);
60
+ return instance;
61
+ }
62
+ }
63
+ /**
64
+ * Clear a resolved facade instance.
65
+ *
66
+ * @param name
67
+ */
68
+ static clearResolvedInstance(name) {
69
+ this.resolvedInstance.delete(name);
70
+ }
71
+ /**
72
+ * Clear all of the resolved instances.
73
+ */
74
+ static clearResolvedInstances() {
75
+ this.resolvedInstance.clear();
76
+ }
77
+ /**
78
+ * Hotswap the underlying instance behind the facade.
79
+ *
80
+ * @param instance
81
+ */
82
+ static swap(instance) {
83
+ this.resolvedInstance.set(this.getFacadeAccessor(), instance);
84
+ if (this.app) this.app.instance(this.getFacadeAccessor(), instance);
85
+ }
86
+ static __callStatic(method, args) {
87
+ const instance = this.getFacadeRoot();
88
+ if (!instance) throw new Error("Facade root not resolved.");
89
+ if (typeof instance[method] === "function" && !(0, __h3ravel_foundation.isInternal)(instance, method)) return Reflect.apply(instance[method], instance, args);
90
+ if (typeof instance.__call === "function") return instance.__call(method, args);
91
+ throw new Error(`Method [${method}] does not exist on [${instance.constructor.name}] facade root.`);
92
+ }
93
+ static createFacade() {
94
+ return new Proxy({}, { get: (_target, prop) => {
95
+ return (...args) => this.__callStatic(prop, args);
96
+ } });
97
+ }
98
+ };
99
+
100
+ //#endregion
101
+ //#region src/Facades/RouteFacade.ts
102
+ var RouteFacade = class extends Facades {
103
+ static getFacadeAccessor() {
104
+ return "router";
105
+ }
106
+ };
107
+ const Route = RouteFacade.createFacade();
108
+
109
+ //#endregion
110
+ exports.Facades = Facades;
111
+ exports.Route = Route;
@@ -0,0 +1,70 @@
1
+ import { ClassConstructor, ConcreteConstructor, IApplication, IBinding, IRouteRegistrar, IRouter } from "@h3ravel/contracts";
2
+
3
+ //#region src/Facades/Facades.d.ts
4
+ declare abstract class Facades {
5
+ /**
6
+ * The application instance being facaded.
7
+ */
8
+ protected static app?: IApplication;
9
+ /**
10
+ * The resolved object instances.
11
+ */
12
+ protected static resolvedInstance: Map<string | (new (...args: any[]) => unknown), any>;
13
+ /**
14
+ * Indicates if the resolved instance should be cached.
15
+ */
16
+ protected static cached: boolean;
17
+ /**
18
+ * Called once during bootstrap
19
+ *
20
+ * @param app
21
+ */
22
+ static setApplication(app: IApplication): void;
23
+ /**
24
+ * Get the application instance behind the facade.
25
+ */
26
+ static getApplication(): IApplication | undefined;
27
+ /**
28
+ * Get the registered name of the component.
29
+ * Each facade must define its container key
30
+ *
31
+ * @return string
32
+ *
33
+ * @throws {RuntimeException}
34
+ */
35
+ protected static getFacadeAccessor(): string;
36
+ /**
37
+ * Get the root object behind the facade.
38
+ */
39
+ static getFacadeRoot<T>(): any;
40
+ /**
41
+ * Resolve the facade root instance from the container.
42
+ *
43
+ * @param name
44
+ */
45
+ static resolveInstance<T>(name: string | IBinding): any;
46
+ /**
47
+ * Clear a resolved facade instance.
48
+ *
49
+ * @param name
50
+ */
51
+ static clearResolvedInstance(name: string | IBinding): void;
52
+ /**
53
+ * Clear all of the resolved instances.
54
+ */
55
+ static clearResolvedInstances(): void;
56
+ /**
57
+ * Hotswap the underlying instance behind the facade.
58
+ *
59
+ * @param instance
60
+ */
61
+ static swap(instance: ConcreteConstructor<ClassConstructor>): void;
62
+ static __callStatic<T>(method: string, args: any[]): any;
63
+ static createFacade<T extends object>(): T;
64
+ }
65
+ //#endregion
66
+ //#region src/Facades/RouteFacade.d.ts
67
+ type FRoute = Omit<IRouter, 'group' | 'apiSingleton' | 'match' | 'resource' | 'apiResource' | 'singleton' | 'middleware'>;
68
+ declare const Route: IRouteRegistrar & FRoute;
69
+ //#endregion
70
+ export { FRoute, Facades, Route };
@@ -0,0 +1,109 @@
1
+ import { t as RuntimeException } from "./RuntimeException-CrNX0B-p.js";
2
+ import { isInternal } from "@h3ravel/foundation";
3
+
4
+ //#region src/Facades/Facades.ts
5
+ var Facades = class {
6
+ /**
7
+ * The application instance being facaded.
8
+ */
9
+ static app;
10
+ /**
11
+ * The resolved object instances.
12
+ */
13
+ static resolvedInstance = /* @__PURE__ */ new Map();
14
+ /**
15
+ * Indicates if the resolved instance should be cached.
16
+ */
17
+ static cached = true;
18
+ /**
19
+ * Called once during bootstrap
20
+ *
21
+ * @param app
22
+ */
23
+ static setApplication(app) {
24
+ this.app = app;
25
+ }
26
+ /**
27
+ * Get the application instance behind the facade.
28
+ */
29
+ static getApplication() {
30
+ return this.app;
31
+ }
32
+ /**
33
+ * Get the registered name of the component.
34
+ * Each facade must define its container key
35
+ *
36
+ * @return string
37
+ *
38
+ * @throws {RuntimeException}
39
+ */
40
+ static getFacadeAccessor() {
41
+ throw new RuntimeException("Facade accessor not implemented.");
42
+ }
43
+ /**
44
+ * Get the root object behind the facade.
45
+ */
46
+ static getFacadeRoot() {
47
+ return this.resolveInstance(this.getFacadeAccessor());
48
+ }
49
+ /**
50
+ * Resolve the facade root instance from the container.
51
+ *
52
+ * @param name
53
+ */
54
+ static resolveInstance(name) {
55
+ if (this.resolvedInstance.has(name)) return this.resolvedInstance.get(name);
56
+ if (this.app) {
57
+ const instance = this.app.make(name);
58
+ if (this.cached) this.resolvedInstance.set(name, instance);
59
+ return instance;
60
+ }
61
+ }
62
+ /**
63
+ * Clear a resolved facade instance.
64
+ *
65
+ * @param name
66
+ */
67
+ static clearResolvedInstance(name) {
68
+ this.resolvedInstance.delete(name);
69
+ }
70
+ /**
71
+ * Clear all of the resolved instances.
72
+ */
73
+ static clearResolvedInstances() {
74
+ this.resolvedInstance.clear();
75
+ }
76
+ /**
77
+ * Hotswap the underlying instance behind the facade.
78
+ *
79
+ * @param instance
80
+ */
81
+ static swap(instance) {
82
+ this.resolvedInstance.set(this.getFacadeAccessor(), instance);
83
+ if (this.app) this.app.instance(this.getFacadeAccessor(), instance);
84
+ }
85
+ static __callStatic(method, args) {
86
+ const instance = this.getFacadeRoot();
87
+ if (!instance) throw new Error("Facade root not resolved.");
88
+ if (typeof instance[method] === "function" && !isInternal(instance, method)) return Reflect.apply(instance[method], instance, args);
89
+ if (typeof instance.__call === "function") return instance.__call(method, args);
90
+ throw new Error(`Method [${method}] does not exist on [${instance.constructor.name}] facade root.`);
91
+ }
92
+ static createFacade() {
93
+ return new Proxy({}, { get: (_target, prop) => {
94
+ return (...args) => this.__callStatic(prop, args);
95
+ } });
96
+ }
97
+ };
98
+
99
+ //#endregion
100
+ //#region src/Facades/RouteFacade.ts
101
+ var RouteFacade = class extends Facades {
102
+ static getFacadeAccessor() {
103
+ return "router";
104
+ }
105
+ };
106
+ const Route = RouteFacade.createFacade();
107
+
108
+ //#endregion
109
+ export { Facades, Route };