@orieljs/framework 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +17 -0
- package/dist/chunk-P64C7IEP.js +87 -0
- package/dist/chunk-P64C7IEP.js.map +1 -0
- package/dist/contracts.d.ts +1117 -0
- package/dist/contracts.js +85 -0
- package/dist/contracts.js.map +1 -0
- package/dist/index.d.ts +799 -0
- package/dist/index.js +1036 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1036 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Application,
|
|
3
|
+
ClassRegistry,
|
|
4
|
+
ConfigRepository,
|
|
5
|
+
Container,
|
|
6
|
+
ExceptionCallbacks,
|
|
7
|
+
HttpKernel,
|
|
8
|
+
MiddlewareCallbacks,
|
|
9
|
+
RoutingPaths
|
|
10
|
+
} from "./chunk-P64C7IEP.js";
|
|
11
|
+
|
|
12
|
+
// ../Container/dist/index.js
|
|
13
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
14
|
+
function describe(abstract) {
|
|
15
|
+
return typeof abstract === "function" ? abstract.name || "<anonymous class>" : abstract.description;
|
|
16
|
+
}
|
|
17
|
+
var BindingResolutionError = class extends Error {
|
|
18
|
+
kind = "BindingResolution";
|
|
19
|
+
name = "BindingResolutionError";
|
|
20
|
+
};
|
|
21
|
+
var CircularDependencyError = class extends Error {
|
|
22
|
+
constructor(chain) {
|
|
23
|
+
super(`Circular dependency detected: ${chain.join(" -> ")}`);
|
|
24
|
+
this.chain = chain;
|
|
25
|
+
}
|
|
26
|
+
chain;
|
|
27
|
+
kind = "CircularDependency";
|
|
28
|
+
name = "CircularDependencyError";
|
|
29
|
+
};
|
|
30
|
+
var ContainerNotAvailableError = class extends Error {
|
|
31
|
+
kind = "ContainerNotAvailable";
|
|
32
|
+
name = "ContainerNotAvailableError";
|
|
33
|
+
constructor(what) {
|
|
34
|
+
super(
|
|
35
|
+
`Cannot resolve [${what}]: no container is available. inject(), helpers and facades only work while the application is running (inside a request, job, command, provider or app.run()). Don't call them at module top level.`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var ALS_KEY = /* @__PURE__ */ Symbol.for("oriel:container.als");
|
|
40
|
+
var GLOBAL_KEY = /* @__PURE__ */ Symbol.for("oriel:container.instance");
|
|
41
|
+
var BUILDING_KEY = /* @__PURE__ */ Symbol.for("oriel:container.building");
|
|
42
|
+
var g = globalThis;
|
|
43
|
+
var storage = g[ALS_KEY] ??= new AsyncLocalStorage();
|
|
44
|
+
var building = g[BUILDING_KEY] ??= {
|
|
45
|
+
keys: [],
|
|
46
|
+
names: [],
|
|
47
|
+
containers: []
|
|
48
|
+
};
|
|
49
|
+
function currentContainer() {
|
|
50
|
+
return building.containers.at(-1) ?? storage.getStore() ?? g[GLOBAL_KEY];
|
|
51
|
+
}
|
|
52
|
+
function inject(abstract) {
|
|
53
|
+
const container = currentContainer();
|
|
54
|
+
if (!container) throw new ContainerNotAvailableError(describe(abstract));
|
|
55
|
+
return container.make(abstract);
|
|
56
|
+
}
|
|
57
|
+
var globals = globalThis;
|
|
58
|
+
var keyOf = (abstract) => typeof abstract === "function" ? abstract : abstract.id;
|
|
59
|
+
var isClass = (fn) => typeof fn === "function" && /^class[\s{]/.test(Function.prototype.toString.call(fn));
|
|
60
|
+
var Container2 = class _Container {
|
|
61
|
+
static getInstance() {
|
|
62
|
+
return globals[GLOBAL_KEY];
|
|
63
|
+
}
|
|
64
|
+
static setInstance(container) {
|
|
65
|
+
globals[GLOBAL_KEY] = container;
|
|
66
|
+
}
|
|
67
|
+
shared;
|
|
68
|
+
root;
|
|
69
|
+
parent;
|
|
70
|
+
local = /* @__PURE__ */ new Map();
|
|
71
|
+
constructor(parent) {
|
|
72
|
+
this.parent = parent;
|
|
73
|
+
this.root = parent?.root ?? this;
|
|
74
|
+
this.shared = parent?.shared ?? { bindings: /* @__PURE__ */ new Map(), extenders: /* @__PURE__ */ new Map(), resolving: /* @__PURE__ */ new Map(), resolved: /* @__PURE__ */ new Set() };
|
|
75
|
+
this.local.set(keyOf(Container), this);
|
|
76
|
+
this.local.set(_Container, this);
|
|
77
|
+
}
|
|
78
|
+
bind(abstract, concrete) {
|
|
79
|
+
this.#assertRoot("bind");
|
|
80
|
+
this.#addBinding(abstract, concrete, "transient");
|
|
81
|
+
}
|
|
82
|
+
singleton(abstract, concrete) {
|
|
83
|
+
this.#assertRoot("singleton");
|
|
84
|
+
this.#addBinding(abstract, concrete, "singleton");
|
|
85
|
+
}
|
|
86
|
+
scoped(abstract, concrete) {
|
|
87
|
+
this.#assertRoot("scoped");
|
|
88
|
+
this.#addBinding(abstract, concrete, "scoped");
|
|
89
|
+
}
|
|
90
|
+
instance(abstract, instance) {
|
|
91
|
+
const key = keyOf(abstract);
|
|
92
|
+
this.local.set(key, instance);
|
|
93
|
+
if (this === this.root) this.shared.resolved.add(key);
|
|
94
|
+
return instance;
|
|
95
|
+
}
|
|
96
|
+
make(abstract) {
|
|
97
|
+
const key = keyOf(abstract);
|
|
98
|
+
const owner = this.#owning(key);
|
|
99
|
+
if (owner) return owner.local.get(key);
|
|
100
|
+
const binding = this.shared.bindings.get(key) ?? this.#implicitBinding(abstract);
|
|
101
|
+
if (binding.lifetime === "scoped" && this === this.root) {
|
|
102
|
+
throw new BindingResolutionError(
|
|
103
|
+
`Scoped binding [${describe(abstract)}] was resolved outside a scope. Resolve it inside app.createScope().run(...), and don't inject scoped services into singletons.`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
const builder = binding.lifetime === "singleton" ? this.root : this;
|
|
107
|
+
const instance = builder.build(abstract, key, binding);
|
|
108
|
+
if (binding.lifetime === "singleton") this.root.local.set(key, instance);
|
|
109
|
+
if (binding.lifetime === "scoped") this.local.set(key, instance);
|
|
110
|
+
return instance;
|
|
111
|
+
}
|
|
112
|
+
bound(abstract) {
|
|
113
|
+
const key = keyOf(abstract);
|
|
114
|
+
return this.shared.bindings.has(key) || this.#owning(key) !== void 0;
|
|
115
|
+
}
|
|
116
|
+
resolved(abstract) {
|
|
117
|
+
const key = keyOf(abstract);
|
|
118
|
+
return this.shared.resolved.has(key) || this.#owning(key) !== void 0;
|
|
119
|
+
}
|
|
120
|
+
extend(abstract, extender) {
|
|
121
|
+
this.#assertRoot("extend");
|
|
122
|
+
const key = keyOf(abstract);
|
|
123
|
+
const list = this.shared.extenders.get(key) ?? [];
|
|
124
|
+
list.push(extender);
|
|
125
|
+
this.shared.extenders.set(key, list);
|
|
126
|
+
if (this.local.has(key)) this.local.set(key, extender(this.local.get(key), this));
|
|
127
|
+
}
|
|
128
|
+
resolving(abstract, callback) {
|
|
129
|
+
this.#assertRoot("resolving");
|
|
130
|
+
const key = keyOf(abstract);
|
|
131
|
+
const list = this.shared.resolving.get(key) ?? [];
|
|
132
|
+
list.push(callback);
|
|
133
|
+
this.shared.resolving.set(key, list);
|
|
134
|
+
}
|
|
135
|
+
forgetInstance(abstract) {
|
|
136
|
+
this.local.delete(keyOf(abstract));
|
|
137
|
+
}
|
|
138
|
+
/** Scopes are always plain Containers (never subclasses such as Application). */
|
|
139
|
+
createScope() {
|
|
140
|
+
return new _Container(this);
|
|
141
|
+
}
|
|
142
|
+
run(fn) {
|
|
143
|
+
return storage.run(this, fn);
|
|
144
|
+
}
|
|
145
|
+
/** The nearest container in this -> parent scopes -> root that holds an instance for the key. */
|
|
146
|
+
#owning(key) {
|
|
147
|
+
if (this.local.has(key)) return this;
|
|
148
|
+
return this.parent === void 0 ? void 0 : this.parent.#owning(key);
|
|
149
|
+
}
|
|
150
|
+
/** Bindings, extenders and callbacks are app-wide state: a request scope must never write them. */
|
|
151
|
+
#assertRoot(method) {
|
|
152
|
+
if (this !== this.root) {
|
|
153
|
+
throw new Error(
|
|
154
|
+
`Cannot register bindings on a request scope (${method}). Register them on the application in a service provider; use instance() for per-request values.`
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
#addBinding(abstract, concrete, lifetime) {
|
|
159
|
+
const key = keyOf(abstract);
|
|
160
|
+
let factory;
|
|
161
|
+
if (concrete === void 0) {
|
|
162
|
+
if (typeof abstract !== "function") throw new TypeError(`bind(${describe(abstract)}) needs a concrete: tokens can't be constructed`);
|
|
163
|
+
factory = () => new abstract();
|
|
164
|
+
} else if (isClass(concrete)) {
|
|
165
|
+
factory = () => new concrete();
|
|
166
|
+
} else {
|
|
167
|
+
factory = concrete;
|
|
168
|
+
}
|
|
169
|
+
this.shared.bindings.set(key, { lifetime, factory });
|
|
170
|
+
this.local.delete(key);
|
|
171
|
+
}
|
|
172
|
+
#implicitBinding(abstract) {
|
|
173
|
+
if (typeof abstract === "function") {
|
|
174
|
+
return { lifetime: "transient", factory: () => new abstract() };
|
|
175
|
+
}
|
|
176
|
+
throw new BindingResolutionError(
|
|
177
|
+
`Target [${abstract.description}] is not bound. Is its service provider registered in bootstrap/providers.ts?`
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
build(abstract, key, binding) {
|
|
181
|
+
const stackIndex = building.keys.indexOf(key);
|
|
182
|
+
if (stackIndex !== -1) {
|
|
183
|
+
const chain = [...building.names.slice(stackIndex), describe(abstract)];
|
|
184
|
+
throw new CircularDependencyError(chain);
|
|
185
|
+
}
|
|
186
|
+
building.keys.push(key);
|
|
187
|
+
building.names.push(describe(abstract));
|
|
188
|
+
building.containers.push(this);
|
|
189
|
+
try {
|
|
190
|
+
let instance = binding.factory(this);
|
|
191
|
+
for (const extender of this.shared.extenders.get(key) ?? []) instance = extender(instance, this);
|
|
192
|
+
for (const callback of this.shared.resolving.get(key) ?? []) callback(instance, this);
|
|
193
|
+
this.shared.resolved.add(key);
|
|
194
|
+
return instance;
|
|
195
|
+
} finally {
|
|
196
|
+
building.keys.pop();
|
|
197
|
+
building.names.pop();
|
|
198
|
+
building.containers.pop();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// ../Collections/dist/index.js
|
|
204
|
+
function compare(left, operator, right) {
|
|
205
|
+
switch (operator) {
|
|
206
|
+
case "=":
|
|
207
|
+
case "==":
|
|
208
|
+
return left == right;
|
|
209
|
+
case "===":
|
|
210
|
+
return left === right;
|
|
211
|
+
case "!=":
|
|
212
|
+
case "<>":
|
|
213
|
+
return left != right;
|
|
214
|
+
case "!==":
|
|
215
|
+
return left !== right;
|
|
216
|
+
case "<":
|
|
217
|
+
return left < right;
|
|
218
|
+
case "<=":
|
|
219
|
+
return left <= right;
|
|
220
|
+
case ">":
|
|
221
|
+
return left > right;
|
|
222
|
+
case ">=":
|
|
223
|
+
return left >= right;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function ascending(a, b) {
|
|
227
|
+
const aNil = a === null || a === void 0;
|
|
228
|
+
const bNil = b === null || b === void 0;
|
|
229
|
+
if (aNil || bNil) return aNil === bNil ? 0 : aNil ? 1 : -1;
|
|
230
|
+
if (typeof a === "number" && typeof b === "number") return a - b;
|
|
231
|
+
if (a instanceof Date && b instanceof Date) return a.getTime() - b.getTime();
|
|
232
|
+
return String(a).localeCompare(String(b));
|
|
233
|
+
}
|
|
234
|
+
var read = (item, getter) => typeof getter === "function" ? getter(item) : item?.[getter];
|
|
235
|
+
var isArrayable = (v) => typeof v === "object" && v !== null && typeof v.toArray === "function";
|
|
236
|
+
var numbers = (items, getter) => items.map((item) => getter === void 0 ? item : read(item, getter)).filter((v) => typeof v === "number" && !Number.isNaN(v));
|
|
237
|
+
var Collection = class _Collection {
|
|
238
|
+
items;
|
|
239
|
+
constructor(items = []) {
|
|
240
|
+
this.items = [...items];
|
|
241
|
+
}
|
|
242
|
+
static make(items = []) {
|
|
243
|
+
return new _Collection(items);
|
|
244
|
+
}
|
|
245
|
+
/** Laravel semantics: callback receives 1..n. */
|
|
246
|
+
static times(count, callback) {
|
|
247
|
+
return new _Collection(Array.from({ length: Math.max(0, count) }, (_, i) => callback(i + 1)));
|
|
248
|
+
}
|
|
249
|
+
[Symbol.iterator]() {
|
|
250
|
+
return this.items[Symbol.iterator]();
|
|
251
|
+
}
|
|
252
|
+
all() {
|
|
253
|
+
return [...this.items];
|
|
254
|
+
}
|
|
255
|
+
count() {
|
|
256
|
+
return this.items.length;
|
|
257
|
+
}
|
|
258
|
+
isEmpty() {
|
|
259
|
+
return this.items.length === 0;
|
|
260
|
+
}
|
|
261
|
+
isNotEmpty() {
|
|
262
|
+
return this.items.length > 0;
|
|
263
|
+
}
|
|
264
|
+
toArray() {
|
|
265
|
+
return this.items.map((i) => isArrayable(i) ? i.toArray() : i);
|
|
266
|
+
}
|
|
267
|
+
toJSON() {
|
|
268
|
+
return this.all();
|
|
269
|
+
}
|
|
270
|
+
toJson() {
|
|
271
|
+
return JSON.stringify(this);
|
|
272
|
+
}
|
|
273
|
+
map(callback) {
|
|
274
|
+
return new _Collection(this.items.map(callback));
|
|
275
|
+
}
|
|
276
|
+
flatMap(callback) {
|
|
277
|
+
return new _Collection(
|
|
278
|
+
this.items.flatMap((item, i) => {
|
|
279
|
+
const out = callback(item, i);
|
|
280
|
+
return out instanceof _Collection ? out.all() : out;
|
|
281
|
+
})
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
filter(callback) {
|
|
285
|
+
return new _Collection(this.items.filter(callback ?? ((item) => Boolean(item))));
|
|
286
|
+
}
|
|
287
|
+
reject(callback) {
|
|
288
|
+
return new _Collection(this.items.filter((item, i) => !callback(item, i)));
|
|
289
|
+
}
|
|
290
|
+
/** Return false from the callback to stop. */
|
|
291
|
+
each(callback) {
|
|
292
|
+
for (let i = 0; i < this.items.length; i++) if (callback(this.items[i], i) === false) break;
|
|
293
|
+
return this;
|
|
294
|
+
}
|
|
295
|
+
reduce(callback, initial) {
|
|
296
|
+
return this.items.reduce(callback, initial);
|
|
297
|
+
}
|
|
298
|
+
first(callback, defaultValue) {
|
|
299
|
+
if (!callback) return this.items[0];
|
|
300
|
+
const index = this.items.findIndex(callback);
|
|
301
|
+
return index === -1 ? defaultValue : this.items[index];
|
|
302
|
+
}
|
|
303
|
+
last(callback, defaultValue) {
|
|
304
|
+
if (!callback) return this.items.at(-1);
|
|
305
|
+
const index = this.items.findLastIndex(callback);
|
|
306
|
+
return index === -1 ? defaultValue : this.items[index];
|
|
307
|
+
}
|
|
308
|
+
where(key, operatorOrValue, value2) {
|
|
309
|
+
const [op, expected] = arguments.length === 2 ? ["=", operatorOrValue] : [operatorOrValue, value2];
|
|
310
|
+
return this.filter((item) => compare(read(item, key), op, expected));
|
|
311
|
+
}
|
|
312
|
+
firstWhere(key, operatorOrValue, value2) {
|
|
313
|
+
const [op, expected] = arguments.length === 2 ? ["=", operatorOrValue] : [operatorOrValue, value2];
|
|
314
|
+
return this.items.find((item) => compare(read(item, key), op, expected));
|
|
315
|
+
}
|
|
316
|
+
whereIn(key, values) {
|
|
317
|
+
const set = new Set(values);
|
|
318
|
+
return this.filter((item) => set.has(read(item, key)));
|
|
319
|
+
}
|
|
320
|
+
whereNotIn(key, values) {
|
|
321
|
+
const set = new Set(values);
|
|
322
|
+
return this.filter((item) => !set.has(read(item, key)));
|
|
323
|
+
}
|
|
324
|
+
pluck(key) {
|
|
325
|
+
return this.map((item) => read(item, key));
|
|
326
|
+
}
|
|
327
|
+
keyBy(key) {
|
|
328
|
+
return Object.fromEntries(this.items.map((item) => [String(read(item, key)), item]));
|
|
329
|
+
}
|
|
330
|
+
groupBy(key) {
|
|
331
|
+
const groups = {};
|
|
332
|
+
for (const item of this.items) (groups[String(read(item, key))] ??= new _Collection()).push(item);
|
|
333
|
+
return groups;
|
|
334
|
+
}
|
|
335
|
+
mapWithKeys(callback) {
|
|
336
|
+
return Object.fromEntries(this.items.map(callback));
|
|
337
|
+
}
|
|
338
|
+
sortBy(key, direction = "asc") {
|
|
339
|
+
const sign = direction === "asc" ? 1 : -1;
|
|
340
|
+
return new _Collection(
|
|
341
|
+
this.items.map((item, index) => ({ item, index, value: read(item, key) })).sort((a, b) => {
|
|
342
|
+
const aNil = a.value === null || a.value === void 0;
|
|
343
|
+
const bNil = b.value === null || b.value === void 0;
|
|
344
|
+
if (aNil || bNil) return aNil === bNil ? a.index - b.index : aNil ? 1 : -1;
|
|
345
|
+
return sign * ascending(a.value, b.value) || a.index - b.index;
|
|
346
|
+
}).map((x) => x.item)
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
sortByDesc(key) {
|
|
350
|
+
return this.sortBy(key, "desc");
|
|
351
|
+
}
|
|
352
|
+
sum(key) {
|
|
353
|
+
return numbers(this.items, key).reduce((a, b) => a + b, 0);
|
|
354
|
+
}
|
|
355
|
+
avg(key) {
|
|
356
|
+
const values = numbers(this.items, key);
|
|
357
|
+
return values.length ? values.reduce((a, b) => a + b, 0) / values.length : void 0;
|
|
358
|
+
}
|
|
359
|
+
min(key) {
|
|
360
|
+
const values = numbers(this.items, key);
|
|
361
|
+
return values.length ? Math.min(...values) : void 0;
|
|
362
|
+
}
|
|
363
|
+
max(key) {
|
|
364
|
+
const values = numbers(this.items, key);
|
|
365
|
+
return values.length ? Math.max(...values) : void 0;
|
|
366
|
+
}
|
|
367
|
+
unique(key) {
|
|
368
|
+
const seen = /* @__PURE__ */ new Set();
|
|
369
|
+
return this.filter((item) => {
|
|
370
|
+
const v = key === void 0 ? item : read(item, key);
|
|
371
|
+
if (seen.has(v)) return false;
|
|
372
|
+
seen.add(v);
|
|
373
|
+
return true;
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
chunk(size) {
|
|
377
|
+
if (size <= 0) return new _Collection();
|
|
378
|
+
const chunks = [];
|
|
379
|
+
for (let i = 0; i < this.items.length; i += size) chunks.push(new _Collection(this.items.slice(i, i + size)));
|
|
380
|
+
return new _Collection(chunks);
|
|
381
|
+
}
|
|
382
|
+
/** Negative count takes from the end. */
|
|
383
|
+
take(count) {
|
|
384
|
+
return new _Collection(count < 0 ? this.items.slice(count) : this.items.slice(0, count));
|
|
385
|
+
}
|
|
386
|
+
skip(count) {
|
|
387
|
+
return new _Collection(this.items.slice(count));
|
|
388
|
+
}
|
|
389
|
+
slice(offset, length) {
|
|
390
|
+
return new _Collection(this.items.slice(offset, length === void 0 ? void 0 : offset + length));
|
|
391
|
+
}
|
|
392
|
+
values() {
|
|
393
|
+
return new _Collection(this.items);
|
|
394
|
+
}
|
|
395
|
+
contains(keyOrValue, value2) {
|
|
396
|
+
if (arguments.length === 2) return this.items.some((item) => read(item, keyOrValue) === value2);
|
|
397
|
+
if (typeof keyOrValue === "function") return this.items.some(keyOrValue);
|
|
398
|
+
return this.items.includes(keyOrValue);
|
|
399
|
+
}
|
|
400
|
+
/** Mutates, like Laravel. */
|
|
401
|
+
push(...values) {
|
|
402
|
+
this.items.push(...values);
|
|
403
|
+
return this;
|
|
404
|
+
}
|
|
405
|
+
concat(values) {
|
|
406
|
+
return new _Collection([...this.items, ...values]);
|
|
407
|
+
}
|
|
408
|
+
partition(callback) {
|
|
409
|
+
return [this.filter(callback), this.reject(callback)];
|
|
410
|
+
}
|
|
411
|
+
implode(keyOrGlue, glue) {
|
|
412
|
+
if (glue === void 0) return this.items.join(keyOrGlue);
|
|
413
|
+
return this.items.map((item) => read(item, keyOrGlue)).join(glue);
|
|
414
|
+
}
|
|
415
|
+
when(condition, callback) {
|
|
416
|
+
return condition ? callback(this) : this;
|
|
417
|
+
}
|
|
418
|
+
pipe(callback) {
|
|
419
|
+
return callback(this);
|
|
420
|
+
}
|
|
421
|
+
tap(callback) {
|
|
422
|
+
callback(this);
|
|
423
|
+
return this;
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
function collect(items = []) {
|
|
427
|
+
return new Collection(items);
|
|
428
|
+
}
|
|
429
|
+
var LazyCollection = class _LazyCollection {
|
|
430
|
+
constructor(source) {
|
|
431
|
+
this.source = source;
|
|
432
|
+
}
|
|
433
|
+
source;
|
|
434
|
+
static make(source) {
|
|
435
|
+
return new _LazyCollection(source);
|
|
436
|
+
}
|
|
437
|
+
async *[Symbol.asyncIterator]() {
|
|
438
|
+
yield* this.source();
|
|
439
|
+
}
|
|
440
|
+
map(callback) {
|
|
441
|
+
const self = this;
|
|
442
|
+
return new _LazyCollection(async function* () {
|
|
443
|
+
let i = 0;
|
|
444
|
+
for await (const item of self) yield await callback(item, i++);
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
filter(callback) {
|
|
448
|
+
const self = this;
|
|
449
|
+
return new _LazyCollection(async function* () {
|
|
450
|
+
let i = 0;
|
|
451
|
+
for await (const item of self) if (await callback(item, i++)) yield item;
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
take(count) {
|
|
455
|
+
const self = this;
|
|
456
|
+
return new _LazyCollection(async function* () {
|
|
457
|
+
if (count <= 0) return;
|
|
458
|
+
let taken = 0;
|
|
459
|
+
for await (const item of self) {
|
|
460
|
+
yield item;
|
|
461
|
+
if (++taken >= count) return;
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
chunk(size) {
|
|
466
|
+
const self = this;
|
|
467
|
+
return new _LazyCollection(async function* () {
|
|
468
|
+
if (size <= 0) return;
|
|
469
|
+
let buffer = [];
|
|
470
|
+
for await (const item of self) {
|
|
471
|
+
buffer.push(item);
|
|
472
|
+
if (buffer.length === size) {
|
|
473
|
+
yield new Collection(buffer);
|
|
474
|
+
buffer = [];
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
if (buffer.length) yield new Collection(buffer);
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
/** Return false from the callback to stop. */
|
|
481
|
+
async each(callback) {
|
|
482
|
+
let i = 0;
|
|
483
|
+
for await (const item of this) if (await callback(item, i++) === false) return;
|
|
484
|
+
}
|
|
485
|
+
async first(callback) {
|
|
486
|
+
for await (const item of this) if (!callback || await callback(item)) return item;
|
|
487
|
+
return void 0;
|
|
488
|
+
}
|
|
489
|
+
async count() {
|
|
490
|
+
let n = 0;
|
|
491
|
+
for await (const item of this) {
|
|
492
|
+
void item;
|
|
493
|
+
n++;
|
|
494
|
+
}
|
|
495
|
+
return n;
|
|
496
|
+
}
|
|
497
|
+
async collect() {
|
|
498
|
+
const items = [];
|
|
499
|
+
for await (const item of this) items.push(item);
|
|
500
|
+
return new Collection(items);
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
// ../Support/dist/index.js
|
|
505
|
+
import { randomBytes, randomUUID } from "crypto";
|
|
506
|
+
import pluralize from "pluralize";
|
|
507
|
+
import { setTimeout as sleep } from "timers/promises";
|
|
508
|
+
var words = (value2) => value2.replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").split(/[^A-Za-z\d]+/).filter(Boolean);
|
|
509
|
+
var ALPHANUM = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
510
|
+
var escapeRegex = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
511
|
+
var anyOf = (needles) => (Array.isArray(needles) ? needles : [needles]).filter((n) => n !== "");
|
|
512
|
+
var Str = {
|
|
513
|
+
ucfirst: (v) => v.charAt(0).toUpperCase() + v.slice(1),
|
|
514
|
+
lcfirst: (v) => v.charAt(0).toLowerCase() + v.slice(1),
|
|
515
|
+
studly: (v) => words(v).map((w) => Str.ucfirst(w.toLowerCase())).join(""),
|
|
516
|
+
camel: (v) => Str.lcfirst(Str.studly(v)),
|
|
517
|
+
snake: (v, delimiter = "_") => words(v).map((w) => w.toLowerCase()).join(delimiter),
|
|
518
|
+
kebab: (v) => Str.snake(v, "-"),
|
|
519
|
+
title: (v) => v.toLowerCase().replace(/(^|\s)\S/g, (m) => m.toUpperCase()),
|
|
520
|
+
slug: (v, separator = "-") => v.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z\d]+/g, separator).replace(new RegExp(`^${escapeRegex(separator)}+|${escapeRegex(separator)}+$`, "g"), ""),
|
|
521
|
+
plural: (v, count = 2) => pluralize(v, count),
|
|
522
|
+
singular: (v) => pluralize.singular(v),
|
|
523
|
+
random: (length = 16) => {
|
|
524
|
+
let out = "";
|
|
525
|
+
while (out.length < length) {
|
|
526
|
+
for (const byte of randomBytes(length)) {
|
|
527
|
+
if (byte < 248 && out.length < length) out += ALPHANUM[byte % 62];
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return out;
|
|
531
|
+
},
|
|
532
|
+
uuid: () => randomUUID(),
|
|
533
|
+
/** Wildcard match: `*` matches anything; everything else is literal. */
|
|
534
|
+
is: (pattern, value2) => pattern === value2 || new RegExp(`^${pattern.split("*").map(escapeRegex).join(".*")}$`, "s").test(value2),
|
|
535
|
+
startsWith: (v, needles) => anyOf(needles).some((n) => v.startsWith(n)),
|
|
536
|
+
endsWith: (v, needles) => anyOf(needles).some((n) => v.endsWith(n)),
|
|
537
|
+
contains: (v, needles) => anyOf(needles).some((n) => v.includes(n)),
|
|
538
|
+
after: (v, search) => search === "" || !v.includes(search) ? v : v.slice(v.indexOf(search) + search.length),
|
|
539
|
+
afterLast: (v, search) => search === "" || !v.includes(search) ? v : v.slice(v.lastIndexOf(search) + search.length),
|
|
540
|
+
before: (v, search) => search === "" || !v.includes(search) ? v : v.slice(0, v.indexOf(search)),
|
|
541
|
+
beforeLast: (v, search) => search === "" || !v.includes(search) ? v : v.slice(0, v.lastIndexOf(search)),
|
|
542
|
+
between: (v, from, to) => Str.beforeLast(Str.after(v, from), to),
|
|
543
|
+
limit: (v, limit = 100, end = "...") => v.length <= limit ? v : v.slice(0, limit).trimEnd() + end,
|
|
544
|
+
start: (v, prefix) => v.startsWith(prefix) ? v : prefix + v,
|
|
545
|
+
finish: (v, cap) => v.endsWith(cap) ? v : v + cap
|
|
546
|
+
};
|
|
547
|
+
var FORBIDDEN = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
548
|
+
var isWalkable = (v) => typeof v === "object" && v !== null;
|
|
549
|
+
var segments = (key) => key.split(".");
|
|
550
|
+
var Arr = {
|
|
551
|
+
get(target, key, defaultValue) {
|
|
552
|
+
if (key === void 0 || key === "") return target;
|
|
553
|
+
let current = target;
|
|
554
|
+
for (const segment of segments(key)) {
|
|
555
|
+
if (!isWalkable(current) || !Object.hasOwn(current, segment)) return defaultValue;
|
|
556
|
+
current = current[segment];
|
|
557
|
+
}
|
|
558
|
+
return current;
|
|
559
|
+
},
|
|
560
|
+
has(target, key) {
|
|
561
|
+
const missing = /* @__PURE__ */ Symbol("missing");
|
|
562
|
+
return Arr.get(target, key, missing) !== missing;
|
|
563
|
+
},
|
|
564
|
+
set(target, key, value2) {
|
|
565
|
+
const parts = segments(key);
|
|
566
|
+
if (parts.some((p) => FORBIDDEN.has(p))) throw new Error(`Refusing to set unsafe key "${key}"`);
|
|
567
|
+
let current = target;
|
|
568
|
+
parts.slice(0, -1).forEach((segment) => {
|
|
569
|
+
if (!isWalkable(current[segment])) current[segment] = {};
|
|
570
|
+
current = current[segment];
|
|
571
|
+
});
|
|
572
|
+
current[parts.at(-1)] = value2;
|
|
573
|
+
return target;
|
|
574
|
+
},
|
|
575
|
+
forget(target, key) {
|
|
576
|
+
const parts = segments(key);
|
|
577
|
+
const parent = parts.length === 1 ? target : Arr.get(target, parts.slice(0, -1).join("."));
|
|
578
|
+
if (isWalkable(parent)) delete parent[parts.at(-1)];
|
|
579
|
+
},
|
|
580
|
+
dot(target, prefix = "") {
|
|
581
|
+
const out = {};
|
|
582
|
+
for (const [k, v] of Object.entries(target)) {
|
|
583
|
+
const path = prefix + k;
|
|
584
|
+
if (isWalkable(v) && Object.keys(v).length > 0) Object.assign(out, Arr.dot(v, `${path}.`));
|
|
585
|
+
else out[path] = v;
|
|
586
|
+
}
|
|
587
|
+
return out;
|
|
588
|
+
},
|
|
589
|
+
undot(flat) {
|
|
590
|
+
const out = {};
|
|
591
|
+
for (const [k, v] of Object.entries(flat)) Arr.set(out, k, v);
|
|
592
|
+
return out;
|
|
593
|
+
},
|
|
594
|
+
only(target, keys) {
|
|
595
|
+
return Object.fromEntries(keys.filter((k) => Object.hasOwn(target, k)).map((k) => [k, target[k]]));
|
|
596
|
+
},
|
|
597
|
+
except(target, keys) {
|
|
598
|
+
const skip = new Set(keys);
|
|
599
|
+
return Object.fromEntries(Object.entries(target).filter(([k]) => !skip.has(k)));
|
|
600
|
+
},
|
|
601
|
+
wrap(value2) {
|
|
602
|
+
if (value2 === null || value2 === void 0) return [];
|
|
603
|
+
return Array.isArray(value2) ? value2 : [value2];
|
|
604
|
+
},
|
|
605
|
+
first(items, predicate, defaultValue) {
|
|
606
|
+
const index = predicate ? items.findIndex(predicate) : items.length > 0 ? 0 : -1;
|
|
607
|
+
return index === -1 ? defaultValue : items[index];
|
|
608
|
+
},
|
|
609
|
+
last(items, predicate, defaultValue) {
|
|
610
|
+
const index = predicate ? items.findLastIndex(predicate) : items.length - 1;
|
|
611
|
+
return index === -1 ? defaultValue : items[index];
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
var ServiceProvider = class {
|
|
615
|
+
constructor(app2) {
|
|
616
|
+
this.app = app2;
|
|
617
|
+
}
|
|
618
|
+
app;
|
|
619
|
+
register() {
|
|
620
|
+
}
|
|
621
|
+
boot() {
|
|
622
|
+
}
|
|
623
|
+
/** Package defaults under `key`; values the app already set win (shallow merge, like Laravel). */
|
|
624
|
+
mergeConfigFrom(defaults, key) {
|
|
625
|
+
const config2 = this.app.make(ConfigRepository);
|
|
626
|
+
config2.set(key, { ...defaults, ...config2.get(key, {}) });
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
function facade(abstract, extras) {
|
|
630
|
+
const container = () => {
|
|
631
|
+
const c = currentContainer();
|
|
632
|
+
if (!c) throw new ContainerNotAvailableError(describe(abstract));
|
|
633
|
+
return c;
|
|
634
|
+
};
|
|
635
|
+
const statics = {
|
|
636
|
+
getFacadeRoot: () => container().make(abstract),
|
|
637
|
+
swap: (instance) => void container().instance(abstract, instance)
|
|
638
|
+
};
|
|
639
|
+
const proxy = new Proxy({}, {
|
|
640
|
+
get(_target, prop) {
|
|
641
|
+
if (typeof prop === "symbol" || prop === "then") return void 0;
|
|
642
|
+
if (extras && Object.hasOwn(extras, prop)) {
|
|
643
|
+
const extra = extras[prop];
|
|
644
|
+
return typeof extra === "function" ? extra.bind(proxy) : extra;
|
|
645
|
+
}
|
|
646
|
+
if (Object.hasOwn(statics, prop)) return statics[prop];
|
|
647
|
+
const root = statics.getFacadeRoot();
|
|
648
|
+
const value2 = Reflect.get(root, prop, root);
|
|
649
|
+
return typeof value2 === "function" ? value2.bind(root) : value2;
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
return proxy;
|
|
653
|
+
}
|
|
654
|
+
var ClassRegistry2 = class {
|
|
655
|
+
byName = /* @__PURE__ */ new Map();
|
|
656
|
+
byClass = /* @__PURE__ */ new Map();
|
|
657
|
+
register(cls, name = cls.name) {
|
|
658
|
+
const existingName = this.byClass.get(cls);
|
|
659
|
+
if (existingName !== void 0) return existingName;
|
|
660
|
+
if (!name) throw new Error('Anonymous classes need an explicit name: registry.register(cls, "Some.Name")');
|
|
661
|
+
const existing = this.byName.get(name);
|
|
662
|
+
if (existing && existing !== cls) {
|
|
663
|
+
throw new Error(`"${name}" is already registered to a different class. Pass an explicit name: register(cls, "Module.${name}")`);
|
|
664
|
+
}
|
|
665
|
+
this.byName.set(name, cls);
|
|
666
|
+
this.byClass.set(cls, name);
|
|
667
|
+
return name;
|
|
668
|
+
}
|
|
669
|
+
nameOf(cls) {
|
|
670
|
+
return this.byClass.get(cls);
|
|
671
|
+
}
|
|
672
|
+
resolve(name) {
|
|
673
|
+
const cls = this.byName.get(name);
|
|
674
|
+
if (!cls) throw new Error(`No class registered as "${name}". Is it registered by its service provider?`);
|
|
675
|
+
return cls;
|
|
676
|
+
}
|
|
677
|
+
has(name) {
|
|
678
|
+
return this.byName.has(name);
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
var SCOPE_METHODS = /* @__PURE__ */ new Set(["make", "instance", "bound", "resolved", "forgetInstance", "createScope", "run"]);
|
|
682
|
+
var scopedViews = /* @__PURE__ */ new WeakMap();
|
|
683
|
+
function viewFrom(scope, application) {
|
|
684
|
+
let view = scopedViews.get(scope);
|
|
685
|
+
if (view === void 0) {
|
|
686
|
+
view = new Proxy(application, {
|
|
687
|
+
get(target, property) {
|
|
688
|
+
const source = SCOPE_METHODS.has(property) ? scope : target;
|
|
689
|
+
const member = Reflect.get(source, property, source);
|
|
690
|
+
return typeof member === "function" ? member.bind(source) : member;
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
scopedViews.set(scope, view);
|
|
694
|
+
}
|
|
695
|
+
return view;
|
|
696
|
+
}
|
|
697
|
+
function app(abstract) {
|
|
698
|
+
if (abstract !== void 0) return inject(abstract);
|
|
699
|
+
const application = inject(Application);
|
|
700
|
+
const current = currentContainer();
|
|
701
|
+
return current === void 0 || current === application ? application : viewFrom(current, application);
|
|
702
|
+
}
|
|
703
|
+
function config(keyOrValues, defaultValue) {
|
|
704
|
+
const repository = inject(ConfigRepository);
|
|
705
|
+
if (keyOrValues === void 0) return repository;
|
|
706
|
+
if (typeof keyOrValues === "string") return repository.get(keyOrValues, defaultValue);
|
|
707
|
+
repository.set(keyOrValues);
|
|
708
|
+
return void 0;
|
|
709
|
+
}
|
|
710
|
+
var now = () => /* @__PURE__ */ new Date();
|
|
711
|
+
var value = (v) => typeof v === "function" ? v() : v;
|
|
712
|
+
function tap(target, callback) {
|
|
713
|
+
callback(target);
|
|
714
|
+
return target;
|
|
715
|
+
}
|
|
716
|
+
async function retry(times, fn, sleepMs = 0, when) {
|
|
717
|
+
for (let attempt = 1; ; attempt++) {
|
|
718
|
+
try {
|
|
719
|
+
return await fn(attempt);
|
|
720
|
+
} catch (error) {
|
|
721
|
+
if (attempt >= times || when && !when(error)) throw error;
|
|
722
|
+
const ms = typeof sleepMs === "function" ? sleepMs(attempt) : sleepMs;
|
|
723
|
+
if (ms > 0) await sleep(ms);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// ../Config/dist/index.js
|
|
729
|
+
import { existsSync, readFileSync } from "fs";
|
|
730
|
+
import { join } from "path";
|
|
731
|
+
import { parse } from "dotenv";
|
|
732
|
+
import { existsSync as existsSync2, readdirSync } from "fs";
|
|
733
|
+
import { join as join2 } from "path";
|
|
734
|
+
import { pathToFileURL } from "url";
|
|
735
|
+
var Repository = class {
|
|
736
|
+
constructor(items = {}) {
|
|
737
|
+
this.items = items;
|
|
738
|
+
}
|
|
739
|
+
items;
|
|
740
|
+
has(key) {
|
|
741
|
+
return Arr.has(this.items, key);
|
|
742
|
+
}
|
|
743
|
+
get(key, defaultValue) {
|
|
744
|
+
return Arr.get(this.items, key, defaultValue);
|
|
745
|
+
}
|
|
746
|
+
set(keyOrValues, value2) {
|
|
747
|
+
const entries = typeof keyOrValues === "string" ? [[keyOrValues, value2]] : Object.entries(keyOrValues);
|
|
748
|
+
for (const [k, v] of entries) Arr.set(this.items, k, v);
|
|
749
|
+
}
|
|
750
|
+
push(key, value2) {
|
|
751
|
+
const current = this.get(key, []);
|
|
752
|
+
this.set(key, [...Array.isArray(current) ? current : [current], value2]);
|
|
753
|
+
}
|
|
754
|
+
all() {
|
|
755
|
+
return this.items;
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
var CASTS = {
|
|
759
|
+
"true": true,
|
|
760
|
+
"(true)": true,
|
|
761
|
+
"false": false,
|
|
762
|
+
"(false)": false,
|
|
763
|
+
"null": null,
|
|
764
|
+
"(null)": null,
|
|
765
|
+
"empty": "",
|
|
766
|
+
"(empty)": ""
|
|
767
|
+
};
|
|
768
|
+
function env(key, defaultValue) {
|
|
769
|
+
const raw = process.env[key];
|
|
770
|
+
if (raw === void 0) return typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
771
|
+
const lower = raw.toLowerCase();
|
|
772
|
+
if (Object.hasOwn(CASTS, lower)) return CASTS[lower];
|
|
773
|
+
const quoted = /^(["'])(.*)\1$/s.exec(raw);
|
|
774
|
+
return quoted ? quoted[2] : raw;
|
|
775
|
+
}
|
|
776
|
+
function loadEnvironment(basePath) {
|
|
777
|
+
const appEnv = process.env.APP_ENV;
|
|
778
|
+
const specific = appEnv ? join(basePath, `.env.${appEnv}`) : void 0;
|
|
779
|
+
const file = specific && existsSync(specific) ? specific : join(basePath, ".env");
|
|
780
|
+
if (!existsSync(file)) return void 0;
|
|
781
|
+
for (const [key, value2] of Object.entries(parse(readFileSync(file)))) {
|
|
782
|
+
if (process.env[key] === void 0) process.env[key] = value2;
|
|
783
|
+
}
|
|
784
|
+
return file;
|
|
785
|
+
}
|
|
786
|
+
var CONFIG_FILE = /^(?!.*\.d\.ts$)([A-Za-z0-9_-]+)\.(ts|js|mjs)$/;
|
|
787
|
+
async function loadConfiguration(configPath) {
|
|
788
|
+
if (!existsSync2(configPath)) return {};
|
|
789
|
+
const files = readdirSync(configPath).filter((f) => CONFIG_FILE.test(f)).sort();
|
|
790
|
+
const config2 = {};
|
|
791
|
+
for (const file of files) {
|
|
792
|
+
const name = CONFIG_FILE.exec(file)[1];
|
|
793
|
+
const mod = await import(pathToFileURL(join2(configPath, file)).href);
|
|
794
|
+
config2[name] = mod.default ?? {};
|
|
795
|
+
}
|
|
796
|
+
return config2;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// ../Foundation/dist/index.js
|
|
800
|
+
import { join as join22 } from "path";
|
|
801
|
+
import { isAbsolute, join as join3 } from "path";
|
|
802
|
+
var ApplicationBuilder = class {
|
|
803
|
+
constructor(app2) {
|
|
804
|
+
this.app = app2;
|
|
805
|
+
}
|
|
806
|
+
app;
|
|
807
|
+
providers = [];
|
|
808
|
+
middleware = [];
|
|
809
|
+
exceptions = [];
|
|
810
|
+
routing;
|
|
811
|
+
withProviders(providers = []) {
|
|
812
|
+
this.providers.push(...providers);
|
|
813
|
+
return this;
|
|
814
|
+
}
|
|
815
|
+
withRouting(options) {
|
|
816
|
+
const abs = (p) => p === void 0 ? void 0 : isAbsolute(p) ? p : join3(this.app.basePath(), p);
|
|
817
|
+
const paths = { apiPrefix: options.apiPrefix ?? "api" };
|
|
818
|
+
if (options.web !== void 0) paths.web = abs(options.web);
|
|
819
|
+
if (options.api !== void 0) paths.api = abs(options.api);
|
|
820
|
+
if (options.console !== void 0) paths.console = abs(options.console);
|
|
821
|
+
if (options.health !== void 0) paths.health = options.health;
|
|
822
|
+
this.routing = paths;
|
|
823
|
+
return this;
|
|
824
|
+
}
|
|
825
|
+
withMiddleware(callback) {
|
|
826
|
+
this.middleware.push(callback);
|
|
827
|
+
return this;
|
|
828
|
+
}
|
|
829
|
+
withExceptions(callback) {
|
|
830
|
+
this.exceptions.push(callback);
|
|
831
|
+
return this;
|
|
832
|
+
}
|
|
833
|
+
booting(callback) {
|
|
834
|
+
this.app.booting(callback);
|
|
835
|
+
return this;
|
|
836
|
+
}
|
|
837
|
+
booted(callback) {
|
|
838
|
+
this.app.booted(callback);
|
|
839
|
+
return this;
|
|
840
|
+
}
|
|
841
|
+
async create() {
|
|
842
|
+
loadEnvironment(this.app.basePath());
|
|
843
|
+
this.app.instance(ConfigRepository, new Repository(await loadConfiguration(this.app.configPath())));
|
|
844
|
+
if (this.routing) this.app.instance(RoutingPaths, this.routing);
|
|
845
|
+
this.app.instance(MiddlewareCallbacks, this.middleware);
|
|
846
|
+
this.app.instance(ExceptionCallbacks, this.exceptions);
|
|
847
|
+
for (const provider of this.providers) await this.app.register(provider);
|
|
848
|
+
return this.app;
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
var ProviderBootError = class extends Error {
|
|
852
|
+
constructor(provider, cause) {
|
|
853
|
+
super(`Service provider [${provider}] failed to boot: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
854
|
+
this.provider = provider;
|
|
855
|
+
}
|
|
856
|
+
provider;
|
|
857
|
+
name = "ProviderBootError";
|
|
858
|
+
};
|
|
859
|
+
var ProviderRegisterError = class extends Error {
|
|
860
|
+
constructor(provider, cause) {
|
|
861
|
+
super(`Service provider [${provider}] failed to register: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
862
|
+
this.provider = provider;
|
|
863
|
+
}
|
|
864
|
+
provider;
|
|
865
|
+
name = "ProviderRegisterError";
|
|
866
|
+
};
|
|
867
|
+
var Application2 = class _Application extends Container2 {
|
|
868
|
+
constructor(base) {
|
|
869
|
+
super();
|
|
870
|
+
this.base = base;
|
|
871
|
+
Container2.setInstance(this);
|
|
872
|
+
this.instance(Application, this);
|
|
873
|
+
this.instance(_Application, this);
|
|
874
|
+
this.singleton(ClassRegistry, ClassRegistry2);
|
|
875
|
+
}
|
|
876
|
+
base;
|
|
877
|
+
version = "0.0.0";
|
|
878
|
+
providers = [];
|
|
879
|
+
bootingCallbacks = [];
|
|
880
|
+
bootedCallbacks = [];
|
|
881
|
+
terminatingCallbacks = [];
|
|
882
|
+
bootPromise;
|
|
883
|
+
hasBooted = false;
|
|
884
|
+
inConsole = false;
|
|
885
|
+
/** Entry point used by bootstrap/app.ts. */
|
|
886
|
+
static configure(options) {
|
|
887
|
+
return new ApplicationBuilder(new _Application(options.basePath));
|
|
888
|
+
}
|
|
889
|
+
basePath(path = "") {
|
|
890
|
+
return join22(this.base, path);
|
|
891
|
+
}
|
|
892
|
+
appPath(path = "") {
|
|
893
|
+
return this.basePath(join22("app", path));
|
|
894
|
+
}
|
|
895
|
+
bootstrapPath(path = "") {
|
|
896
|
+
return this.basePath(join22("bootstrap", path));
|
|
897
|
+
}
|
|
898
|
+
configPath(path = "") {
|
|
899
|
+
return this.basePath(join22("config", path));
|
|
900
|
+
}
|
|
901
|
+
databasePath(path = "") {
|
|
902
|
+
return this.basePath(join22("database", path));
|
|
903
|
+
}
|
|
904
|
+
publicPath(path = "") {
|
|
905
|
+
return this.basePath(join22("public", path));
|
|
906
|
+
}
|
|
907
|
+
resourcePath(path = "") {
|
|
908
|
+
return this.basePath(join22("resources", path));
|
|
909
|
+
}
|
|
910
|
+
storagePath(path = "") {
|
|
911
|
+
return this.basePath(join22("storage", path));
|
|
912
|
+
}
|
|
913
|
+
environment(...environments) {
|
|
914
|
+
const fallback = process.env.APP_ENV ?? "production";
|
|
915
|
+
const current = this.bound(ConfigRepository) ? String(this.make(ConfigRepository).get("app.env", fallback)) : fallback;
|
|
916
|
+
return environments.length === 0 ? current : environments.some((pattern) => Str.is(pattern, current));
|
|
917
|
+
}
|
|
918
|
+
isProduction() {
|
|
919
|
+
return this.environment("production");
|
|
920
|
+
}
|
|
921
|
+
isLocal() {
|
|
922
|
+
return this.environment("local");
|
|
923
|
+
}
|
|
924
|
+
runningUnitTests() {
|
|
925
|
+
return this.environment("testing");
|
|
926
|
+
}
|
|
927
|
+
runningInConsole() {
|
|
928
|
+
return this.inConsole;
|
|
929
|
+
}
|
|
930
|
+
setRunningInConsole(value2 = true) {
|
|
931
|
+
this.inConsole = value2;
|
|
932
|
+
}
|
|
933
|
+
async register(provider) {
|
|
934
|
+
const cls = typeof provider === "function" ? provider : provider.constructor;
|
|
935
|
+
const existing = this.providers.find((p) => p.constructor === cls);
|
|
936
|
+
if (existing) return existing;
|
|
937
|
+
const instance = typeof provider === "function" ? new provider(this) : provider;
|
|
938
|
+
try {
|
|
939
|
+
instance.register?.();
|
|
940
|
+
} catch (error) {
|
|
941
|
+
throw new ProviderRegisterError(instance.constructor.name, error);
|
|
942
|
+
}
|
|
943
|
+
this.providers.push(instance);
|
|
944
|
+
if (this.hasBooted) await this.bootProvider(instance);
|
|
945
|
+
return instance;
|
|
946
|
+
}
|
|
947
|
+
getProviders() {
|
|
948
|
+
return [...this.providers];
|
|
949
|
+
}
|
|
950
|
+
boot() {
|
|
951
|
+
return this.bootPromise ??= this.runBoot();
|
|
952
|
+
}
|
|
953
|
+
isBooted() {
|
|
954
|
+
return this.hasBooted;
|
|
955
|
+
}
|
|
956
|
+
booting(callback) {
|
|
957
|
+
this.bootingCallbacks.push(callback);
|
|
958
|
+
}
|
|
959
|
+
/** If already booted, the callback runs immediately (a rejection surfaces as an unhandled rejection). */
|
|
960
|
+
booted(callback) {
|
|
961
|
+
this.bootedCallbacks.push(callback);
|
|
962
|
+
if (this.hasBooted) void callback(this);
|
|
963
|
+
}
|
|
964
|
+
terminating(callback) {
|
|
965
|
+
this.terminatingCallbacks.push(callback);
|
|
966
|
+
}
|
|
967
|
+
async handle(request) {
|
|
968
|
+
await this.boot();
|
|
969
|
+
const scope = this.createScope();
|
|
970
|
+
return scope.run(() => scope.make(HttpKernel).handle(request));
|
|
971
|
+
}
|
|
972
|
+
async terminate() {
|
|
973
|
+
for (const callback of this.terminatingCallbacks) await callback();
|
|
974
|
+
}
|
|
975
|
+
async runBoot() {
|
|
976
|
+
for (const callback of this.bootingCallbacks) await callback(this);
|
|
977
|
+
for (let i = 0; i < this.providers.length; i++) await this.bootProvider(this.providers[i]);
|
|
978
|
+
this.hasBooted = true;
|
|
979
|
+
for (const callback of this.bootedCallbacks) await callback(this);
|
|
980
|
+
}
|
|
981
|
+
async bootProvider(provider) {
|
|
982
|
+
try {
|
|
983
|
+
await provider.boot?.();
|
|
984
|
+
} catch (error) {
|
|
985
|
+
throw new ProviderBootError(provider.constructor.name, error);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
};
|
|
989
|
+
var ClosureKernel = class {
|
|
990
|
+
routes = /* @__PURE__ */ new Map();
|
|
991
|
+
on(method, path, handler) {
|
|
992
|
+
this.routes.set(`${method.toUpperCase()} ${path}`, handler);
|
|
993
|
+
return this;
|
|
994
|
+
}
|
|
995
|
+
async handle(request) {
|
|
996
|
+
const handler = this.routes.get(`${request.method} ${new URL(request.url).pathname}`);
|
|
997
|
+
if (!handler) return new Response("Not Found", { status: 404, headers: { "content-type": "text/plain; charset=utf-8" } });
|
|
998
|
+
return toResponse(await handler(request));
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
function toResponse(output) {
|
|
1002
|
+
if (output instanceof Response) return output;
|
|
1003
|
+
if (output === void 0 || output === null) return new Response(null, { status: 204 });
|
|
1004
|
+
if (typeof output === "string") return new Response(output, { headers: { "content-type": "text/html; charset=utf-8" } });
|
|
1005
|
+
return Response.json(output);
|
|
1006
|
+
}
|
|
1007
|
+
export {
|
|
1008
|
+
Application2 as Application,
|
|
1009
|
+
ApplicationBuilder,
|
|
1010
|
+
Arr,
|
|
1011
|
+
BindingResolutionError,
|
|
1012
|
+
CircularDependencyError,
|
|
1013
|
+
ClassRegistry2 as ClassRegistry,
|
|
1014
|
+
ClosureKernel,
|
|
1015
|
+
Collection,
|
|
1016
|
+
Container2 as Container,
|
|
1017
|
+
ContainerNotAvailableError,
|
|
1018
|
+
LazyCollection,
|
|
1019
|
+
ProviderBootError,
|
|
1020
|
+
ProviderRegisterError,
|
|
1021
|
+
Repository,
|
|
1022
|
+
ServiceProvider,
|
|
1023
|
+
Str,
|
|
1024
|
+
app,
|
|
1025
|
+
collect,
|
|
1026
|
+
config,
|
|
1027
|
+
currentContainer,
|
|
1028
|
+
env,
|
|
1029
|
+
facade,
|
|
1030
|
+
inject,
|
|
1031
|
+
now,
|
|
1032
|
+
retry,
|
|
1033
|
+
tap,
|
|
1034
|
+
value
|
|
1035
|
+
};
|
|
1036
|
+
//# sourceMappingURL=index.js.map
|