@h3ravel/core 0.5.0 → 1.0.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 +13 -0
- package/dist/index.cjs +459 -339
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +40 -12
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/src/Application.ts +64 -14
- package/src/Contracts/ServiceProviderConstructor.ts +5 -0
- package/src/Providers/AppServiceProvider.ts +2 -0
- package/src/Providers/ViewServiceProvider.ts +2 -0
- package/src/ServiceProvider.ts +2 -0
- package/src/index.ts +1 -0
- package/tsconfig.json +4 -2
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,9 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
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
|
+
};
|
|
9
12
|
var __export = (target, all) => {
|
|
10
13
|
for (var name in all)
|
|
11
14
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -28,371 +31,488 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
31
|
));
|
|
29
32
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
33
|
|
|
31
|
-
// src/index.ts
|
|
32
|
-
var src_exports = {};
|
|
33
|
-
__export(src_exports, {
|
|
34
|
-
AppServiceProvider: () => AppServiceProvider,
|
|
35
|
-
Application: () => Application,
|
|
36
|
-
Container: () => Container,
|
|
37
|
-
Controller: () => Controller,
|
|
38
|
-
Kernel: () => Kernel,
|
|
39
|
-
PathLoader: () => PathLoader,
|
|
40
|
-
ServiceProvider: () => ServiceProvider,
|
|
41
|
-
ViewServiceProvider: () => ViewServiceProvider
|
|
42
|
-
});
|
|
43
|
-
module.exports = __toCommonJS(src_exports);
|
|
44
|
-
|
|
45
34
|
// src/Container.ts
|
|
46
|
-
var Container
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
35
|
+
var Container;
|
|
36
|
+
var init_Container = __esm({
|
|
37
|
+
"src/Container.ts"() {
|
|
38
|
+
"use strict";
|
|
39
|
+
Container = class {
|
|
40
|
+
static {
|
|
41
|
+
__name(this, "Container");
|
|
42
|
+
}
|
|
43
|
+
bindings = /* @__PURE__ */ new Map();
|
|
44
|
+
singletons = /* @__PURE__ */ new Map();
|
|
45
|
+
bind(key, factory) {
|
|
46
|
+
this.bindings.set(key, factory);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Bind a singleton service to the container
|
|
50
|
+
*/
|
|
51
|
+
singleton(key, factory) {
|
|
52
|
+
this.bindings.set(key, () => {
|
|
53
|
+
if (!this.singletons.has(key)) {
|
|
54
|
+
this.singletons.set(key, factory());
|
|
55
|
+
}
|
|
56
|
+
return this.singletons.get(key);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Resolve a service from the container
|
|
61
|
+
*/
|
|
62
|
+
make(key) {
|
|
63
|
+
if (this.bindings.has(key)) {
|
|
64
|
+
return this.bindings.get(key)();
|
|
65
|
+
}
|
|
66
|
+
if (typeof key === "function") {
|
|
67
|
+
return this.build(key);
|
|
68
|
+
}
|
|
69
|
+
throw new Error(`No binding found for key: ${typeof key === "string" ? key : key?.name}`);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Automatically build a class with constructor dependency injection
|
|
73
|
+
*/
|
|
74
|
+
build(ClassType) {
|
|
75
|
+
const paramTypes = Reflect.getMetadata("design:paramtypes", ClassType) || [];
|
|
76
|
+
const dependencies = paramTypes.map((dep) => this.make(dep));
|
|
77
|
+
return new ClassType(...dependencies);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Check if a service is registered
|
|
81
|
+
*/
|
|
82
|
+
has(key) {
|
|
83
|
+
return this.bindings.has(key);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
91
86
|
}
|
|
92
|
-
};
|
|
87
|
+
});
|
|
93
88
|
|
|
94
89
|
// src/Utils/PathLoader.ts
|
|
95
|
-
var import_path
|
|
96
|
-
var
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
90
|
+
var import_path, PathLoader;
|
|
91
|
+
var init_PathLoader = __esm({
|
|
92
|
+
"src/Utils/PathLoader.ts"() {
|
|
93
|
+
"use strict";
|
|
94
|
+
import_path = __toESM(require("path"), 1);
|
|
95
|
+
PathLoader = class {
|
|
96
|
+
static {
|
|
97
|
+
__name(this, "PathLoader");
|
|
98
|
+
}
|
|
99
|
+
paths = {
|
|
100
|
+
base: "",
|
|
101
|
+
views: "/src/resources/views",
|
|
102
|
+
assets: "/public/assets",
|
|
103
|
+
routes: "/src/routes",
|
|
104
|
+
config: "/src/config",
|
|
105
|
+
public: "/public",
|
|
106
|
+
storage: "/storage"
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Dynamically retrieves a path property from the class.
|
|
110
|
+
* Any property ending with "Path" is accessible automatically.
|
|
111
|
+
*
|
|
112
|
+
* @param name - The base name of the path property
|
|
113
|
+
* @param base - The base path to include to the path
|
|
114
|
+
* @returns
|
|
115
|
+
*/
|
|
116
|
+
getPath(name, base) {
|
|
117
|
+
if (base && name !== "base") {
|
|
118
|
+
return import_path.default.join(base, this.paths[name]);
|
|
119
|
+
}
|
|
120
|
+
return this.paths[name];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Programatically set the paths.
|
|
124
|
+
*
|
|
125
|
+
* @param name - The base name of the path property
|
|
126
|
+
* @param path - The new path
|
|
127
|
+
* @param base - The base path to include to the path
|
|
128
|
+
*/
|
|
129
|
+
setPath(name, path2, base) {
|
|
130
|
+
if (base && name !== "base") {
|
|
131
|
+
this.paths[name] = import_path.default.join(base, path2);
|
|
132
|
+
}
|
|
133
|
+
this.paths[name] = path2;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
135
136
|
}
|
|
136
|
-
};
|
|
137
|
+
});
|
|
137
138
|
|
|
138
139
|
// src/Application.ts
|
|
139
|
-
var import_node_path
|
|
140
|
-
var
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
140
|
+
var import_dotenv, import_node_path, Application;
|
|
141
|
+
var init_Application = __esm({
|
|
142
|
+
"src/Application.ts"() {
|
|
143
|
+
"use strict";
|
|
144
|
+
init_Container();
|
|
145
|
+
init_PathLoader();
|
|
146
|
+
import_dotenv = __toESM(require("dotenv"), 1);
|
|
147
|
+
import_node_path = __toESM(require("path"), 1);
|
|
148
|
+
Application = class _Application extends Container {
|
|
149
|
+
static {
|
|
150
|
+
__name(this, "Application");
|
|
151
|
+
}
|
|
152
|
+
paths = new PathLoader();
|
|
153
|
+
booted = false;
|
|
154
|
+
versions = {
|
|
155
|
+
app: "0",
|
|
156
|
+
ts: "0"
|
|
157
|
+
};
|
|
158
|
+
basePath;
|
|
159
|
+
providers = [];
|
|
160
|
+
externalProviders = [];
|
|
161
|
+
constructor(basePath) {
|
|
162
|
+
super();
|
|
163
|
+
this.basePath = basePath;
|
|
164
|
+
this.setPath("base", basePath);
|
|
165
|
+
this.loadOptions();
|
|
166
|
+
this.registerBaseBindings();
|
|
167
|
+
import_dotenv.default.config({
|
|
168
|
+
quiet: true
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Register core bindings into the container
|
|
173
|
+
*/
|
|
174
|
+
registerBaseBindings() {
|
|
175
|
+
this.bind(_Application, () => this);
|
|
176
|
+
this.bind("path.base", () => this.basePath);
|
|
177
|
+
this.bind("app.paths", () => this.paths);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Dynamically register all configured providers
|
|
181
|
+
*/
|
|
182
|
+
async registerConfiguredProviders() {
|
|
183
|
+
const providers = await this.getAllProviders();
|
|
184
|
+
for (const ProviderClass of providers) {
|
|
185
|
+
if (!ProviderClass)
|
|
186
|
+
continue;
|
|
187
|
+
const provider = new ProviderClass(this);
|
|
188
|
+
await this.register(provider);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async loadOptions() {
|
|
192
|
+
const app = await this.safeImport(this.getPath("base", "package.json"));
|
|
193
|
+
const core = await this.safeImport("../package.json");
|
|
194
|
+
if (app && app.dependencies) {
|
|
195
|
+
this.versions.app = app.dependencies["@h3ravel/core"];
|
|
196
|
+
}
|
|
197
|
+
if (core && core.devDependencies) {
|
|
198
|
+
this.versions.ts = app.devDependencies.typescript;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Load default and optional providers dynamically
|
|
203
|
+
*
|
|
204
|
+
* Auto-Registration Behavior
|
|
205
|
+
*
|
|
206
|
+
* Minimal App: Loads only core, config, http, router by default.
|
|
207
|
+
* Full-Stack App: Installs database, mail, queue, cache → they self-register via their providers.
|
|
208
|
+
*/
|
|
209
|
+
async getConfiguredProviders() {
|
|
210
|
+
return [
|
|
211
|
+
(await Promise.resolve().then(() => (init_src(), src_exports))).AppServiceProvider,
|
|
212
|
+
(await Promise.resolve().then(() => (init_src(), src_exports))).ViewServiceProvider
|
|
213
|
+
];
|
|
214
|
+
}
|
|
215
|
+
async getAllProviders() {
|
|
216
|
+
const coreProviders = await this.getConfiguredProviders();
|
|
217
|
+
const allProviders = [
|
|
218
|
+
...coreProviders,
|
|
219
|
+
...this.externalProviders
|
|
220
|
+
];
|
|
221
|
+
const uniqueProviders = Array.from(new Set(allProviders));
|
|
222
|
+
return this.sortProviders(uniqueProviders);
|
|
223
|
+
}
|
|
224
|
+
sortProviders(providers) {
|
|
225
|
+
const priorityMap = /* @__PURE__ */ new Map();
|
|
226
|
+
providers.forEach((Provider) => {
|
|
227
|
+
priorityMap.set(Provider.name, Provider.priority ?? 0);
|
|
228
|
+
});
|
|
229
|
+
providers.forEach((Provider) => {
|
|
230
|
+
const order = Provider.order;
|
|
231
|
+
if (!order)
|
|
232
|
+
return;
|
|
233
|
+
const [direction, target] = order.split(":");
|
|
234
|
+
const targetPriority = priorityMap.get(target) ?? 0;
|
|
235
|
+
if (direction === "before") {
|
|
236
|
+
priorityMap.set(Provider.name, targetPriority - 1);
|
|
237
|
+
} else if (direction === "after") {
|
|
238
|
+
priorityMap.set(Provider.name, targetPriority + 1);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
const sorted = providers.sort((A, B) => (priorityMap.get(B.name) ?? 0) - (priorityMap.get(A.name) ?? 0));
|
|
242
|
+
if (process.env.APP_DEBUG === "true") {
|
|
243
|
+
console.table(sorted.map((P) => ({
|
|
244
|
+
Provider: P.name,
|
|
245
|
+
Priority: priorityMap.get(P.name),
|
|
246
|
+
Order: P.order || "N/A"
|
|
247
|
+
})));
|
|
248
|
+
}
|
|
249
|
+
return sorted;
|
|
250
|
+
}
|
|
251
|
+
registerProviders(providers) {
|
|
252
|
+
this.externalProviders.push(...providers);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Register a provider
|
|
256
|
+
*/
|
|
257
|
+
async register(provider) {
|
|
258
|
+
await provider.register();
|
|
259
|
+
this.providers.push(provider);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Boot all providers after registration
|
|
263
|
+
*/
|
|
264
|
+
async boot() {
|
|
265
|
+
if (this.booted)
|
|
266
|
+
return;
|
|
267
|
+
for (const provider of this.providers) {
|
|
268
|
+
if (provider.boot) {
|
|
269
|
+
await provider.boot();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
this.booted = true;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Attempt to dynamically import an optional module
|
|
276
|
+
*/
|
|
277
|
+
async safeImport(moduleName) {
|
|
278
|
+
try {
|
|
279
|
+
const mod = await import(moduleName);
|
|
280
|
+
return mod.default ?? mod ?? {};
|
|
281
|
+
} catch {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Get the base path of the app
|
|
287
|
+
*
|
|
288
|
+
* @returns
|
|
289
|
+
*/
|
|
290
|
+
getBasePath() {
|
|
291
|
+
return this.basePath;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Dynamically retrieves a path property from the class.
|
|
295
|
+
* Any property ending with "Path" is accessible automatically.
|
|
296
|
+
*
|
|
297
|
+
* @param name - The base name of the path property
|
|
298
|
+
* @returns
|
|
299
|
+
*/
|
|
300
|
+
getPath(name, pth) {
|
|
301
|
+
return import_node_path.default.join(this.paths.getPath(name, this.basePath), pth ?? "");
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Programatically set the paths.
|
|
305
|
+
*
|
|
306
|
+
* @param name - The base name of the path property
|
|
307
|
+
* @param path - The new path
|
|
308
|
+
* @returns
|
|
309
|
+
*/
|
|
310
|
+
setPath(name, path2) {
|
|
311
|
+
return this.paths.setPath(name, path2, this.basePath);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Returns the installed version of the system core and typescript.
|
|
315
|
+
*
|
|
316
|
+
* @returns
|
|
317
|
+
*/
|
|
318
|
+
getVersion(key) {
|
|
319
|
+
return this.versions[key]?.replaceAll(/\^|~/g, "");
|
|
320
|
+
}
|
|
321
|
+
};
|
|
289
322
|
}
|
|
290
|
-
};
|
|
323
|
+
});
|
|
291
324
|
|
|
292
325
|
// src/Controller.ts
|
|
293
|
-
var Controller
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
326
|
+
var Controller;
|
|
327
|
+
var init_Controller = __esm({
|
|
328
|
+
"src/Controller.ts"() {
|
|
329
|
+
"use strict";
|
|
330
|
+
Controller = class {
|
|
331
|
+
static {
|
|
332
|
+
__name(this, "Controller");
|
|
333
|
+
}
|
|
334
|
+
app;
|
|
335
|
+
constructor(app) {
|
|
336
|
+
this.app = app;
|
|
337
|
+
}
|
|
338
|
+
show(_ctx) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
index(_ctx) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
store(_ctx) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
update(_ctx) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
destroy(_ctx) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
};
|
|
315
354
|
}
|
|
316
|
-
};
|
|
355
|
+
});
|
|
317
356
|
|
|
318
357
|
// src/ServiceProvider.ts
|
|
319
|
-
var ServiceProvider
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
358
|
+
var ServiceProvider;
|
|
359
|
+
var init_ServiceProvider = __esm({
|
|
360
|
+
"src/ServiceProvider.ts"() {
|
|
361
|
+
"use strict";
|
|
362
|
+
ServiceProvider = class {
|
|
363
|
+
static {
|
|
364
|
+
__name(this, "ServiceProvider");
|
|
365
|
+
}
|
|
366
|
+
static order;
|
|
367
|
+
static priority = 0;
|
|
368
|
+
app;
|
|
369
|
+
constructor(app) {
|
|
370
|
+
this.app = app;
|
|
371
|
+
}
|
|
372
|
+
};
|
|
326
373
|
}
|
|
327
|
-
};
|
|
374
|
+
});
|
|
328
375
|
|
|
329
|
-
// src/
|
|
330
|
-
var
|
|
331
|
-
|
|
332
|
-
|
|
376
|
+
// src/Contracts/BindingsContract.ts
|
|
377
|
+
var init_BindingsContract = __esm({
|
|
378
|
+
"src/Contracts/BindingsContract.ts"() {
|
|
379
|
+
"use strict";
|
|
333
380
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
async handle(event, next) {
|
|
341
|
-
const ctx = this.context(event);
|
|
342
|
-
const result = await this.runMiddleware(ctx, () => next(ctx));
|
|
343
|
-
if (result !== void 0 && this.isPlainObject(result)) {
|
|
344
|
-
event.res.headers.set("Content-Type", "application/json; charset=UTF-8");
|
|
345
|
-
}
|
|
346
|
-
return result;
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// src/Contracts/ServiceProviderConstructor.ts
|
|
384
|
+
var init_ServiceProviderConstructor = __esm({
|
|
385
|
+
"src/Contracts/ServiceProviderConstructor.ts"() {
|
|
386
|
+
"use strict";
|
|
347
387
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
const middleware = this.middleware[i];
|
|
355
|
-
if (middleware) {
|
|
356
|
-
return middleware.handle(context, () => runner(i + 1));
|
|
357
|
-
} else {
|
|
358
|
-
return next(context);
|
|
359
|
-
}
|
|
360
|
-
}, "runner");
|
|
361
|
-
return runner(0);
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
// src/Exceptions/Handler.ts
|
|
391
|
+
var init_Handler = __esm({
|
|
392
|
+
"src/Exceptions/Handler.ts"() {
|
|
393
|
+
"use strict";
|
|
362
394
|
}
|
|
363
|
-
|
|
364
|
-
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
// src/Http/Kernel.ts
|
|
398
|
+
var Kernel;
|
|
399
|
+
var init_Kernel = __esm({
|
|
400
|
+
"src/Http/Kernel.ts"() {
|
|
401
|
+
"use strict";
|
|
402
|
+
Kernel = class {
|
|
403
|
+
static {
|
|
404
|
+
__name(this, "Kernel");
|
|
405
|
+
}
|
|
406
|
+
context;
|
|
407
|
+
middleware;
|
|
408
|
+
constructor(context, middleware = []) {
|
|
409
|
+
this.context = context;
|
|
410
|
+
this.middleware = middleware;
|
|
411
|
+
}
|
|
412
|
+
async handle(event, next) {
|
|
413
|
+
const ctx = this.context(event);
|
|
414
|
+
const result = await this.runMiddleware(ctx, () => next(ctx));
|
|
415
|
+
if (result !== void 0 && this.isPlainObject(result)) {
|
|
416
|
+
event.res.headers.set("Content-Type", "application/json; charset=UTF-8");
|
|
417
|
+
}
|
|
418
|
+
return result;
|
|
419
|
+
}
|
|
420
|
+
async runMiddleware(context, next) {
|
|
421
|
+
let index = -1;
|
|
422
|
+
const runner = /* @__PURE__ */ __name(async (i) => {
|
|
423
|
+
if (i <= index)
|
|
424
|
+
throw new Error("next() called multiple times");
|
|
425
|
+
index = i;
|
|
426
|
+
const middleware = this.middleware[i];
|
|
427
|
+
if (middleware) {
|
|
428
|
+
return middleware.handle(context, () => runner(i + 1));
|
|
429
|
+
} else {
|
|
430
|
+
return next(context);
|
|
431
|
+
}
|
|
432
|
+
}, "runner");
|
|
433
|
+
return runner(0);
|
|
434
|
+
}
|
|
435
|
+
isPlainObject(value) {
|
|
436
|
+
return typeof value === "object" && value !== null && (value.constructor === Object || value.constructor === Array);
|
|
437
|
+
}
|
|
438
|
+
};
|
|
365
439
|
}
|
|
366
|
-
};
|
|
440
|
+
});
|
|
367
441
|
|
|
368
442
|
// src/Providers/AppServiceProvider.ts
|
|
369
|
-
var import_reflect_metadata
|
|
370
|
-
var
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
443
|
+
var import_reflect_metadata, AppServiceProvider;
|
|
444
|
+
var init_AppServiceProvider = __esm({
|
|
445
|
+
"src/Providers/AppServiceProvider.ts"() {
|
|
446
|
+
"use strict";
|
|
447
|
+
import_reflect_metadata = require("reflect-metadata");
|
|
448
|
+
init_ServiceProvider();
|
|
449
|
+
AppServiceProvider = class extends ServiceProvider {
|
|
450
|
+
static {
|
|
451
|
+
__name(this, "AppServiceProvider");
|
|
452
|
+
}
|
|
453
|
+
static priority = 999;
|
|
454
|
+
register() {
|
|
455
|
+
}
|
|
456
|
+
};
|
|
375
457
|
}
|
|
376
|
-
};
|
|
458
|
+
});
|
|
377
459
|
|
|
378
460
|
// src/Providers/ViewServiceProvider.ts
|
|
379
|
-
var import_edge
|
|
380
|
-
var
|
|
381
|
-
|
|
382
|
-
|
|
461
|
+
var import_edge, ViewServiceProvider;
|
|
462
|
+
var init_ViewServiceProvider = __esm({
|
|
463
|
+
"src/Providers/ViewServiceProvider.ts"() {
|
|
464
|
+
"use strict";
|
|
465
|
+
import_edge = require("edge.js");
|
|
466
|
+
init_ServiceProvider();
|
|
467
|
+
ViewServiceProvider = class extends ServiceProvider {
|
|
468
|
+
static {
|
|
469
|
+
__name(this, "ViewServiceProvider");
|
|
470
|
+
}
|
|
471
|
+
static priority = 995;
|
|
472
|
+
register() {
|
|
473
|
+
const config = this.app.make("config");
|
|
474
|
+
const edge = import_edge.Edge.create({
|
|
475
|
+
cache: process.env.NODE_ENV === "production"
|
|
476
|
+
});
|
|
477
|
+
edge.mount(this.app.getPath("views"));
|
|
478
|
+
edge.global("asset", this.app.make("asset"));
|
|
479
|
+
edge.global("config", config.get);
|
|
480
|
+
edge.global("app", this.app);
|
|
481
|
+
this.app.bind("view", () => edge);
|
|
482
|
+
}
|
|
483
|
+
};
|
|
383
484
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
// src/index.ts
|
|
488
|
+
var src_exports = {};
|
|
489
|
+
__export(src_exports, {
|
|
490
|
+
AppServiceProvider: () => AppServiceProvider,
|
|
491
|
+
Application: () => Application,
|
|
492
|
+
Container: () => Container,
|
|
493
|
+
Controller: () => Controller,
|
|
494
|
+
Kernel: () => Kernel,
|
|
495
|
+
PathLoader: () => PathLoader,
|
|
496
|
+
ServiceProvider: () => ServiceProvider,
|
|
497
|
+
ViewServiceProvider: () => ViewServiceProvider
|
|
498
|
+
});
|
|
499
|
+
module.exports = __toCommonJS(src_exports);
|
|
500
|
+
var init_src = __esm({
|
|
501
|
+
"src/index.ts"() {
|
|
502
|
+
init_Application();
|
|
503
|
+
init_Container();
|
|
504
|
+
init_Controller();
|
|
505
|
+
init_ServiceProvider();
|
|
506
|
+
init_BindingsContract();
|
|
507
|
+
init_ServiceProviderConstructor();
|
|
508
|
+
init_Handler();
|
|
509
|
+
init_Kernel();
|
|
510
|
+
init_AppServiceProvider();
|
|
511
|
+
init_ViewServiceProvider();
|
|
512
|
+
init_PathLoader();
|
|
394
513
|
}
|
|
395
|
-
};
|
|
514
|
+
});
|
|
515
|
+
init_src();
|
|
396
516
|
// Annotate the CommonJS export names for ESM import in node:
|
|
397
517
|
0 && (module.exports = {
|
|
398
518
|
AppServiceProvider,
|