@orieljs/framework 0.1.0-alpha.3 → 0.1.0-alpha.5

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.
@@ -1,745 +0,0 @@
1
- import {
2
- Application,
3
- ConfigRepository,
4
- Container
5
- } from "./chunk-S7YC43IH.js";
6
-
7
- // ../Container/dist/index.js
8
- import { AsyncLocalStorage } from "async_hooks";
9
- function describe(abstract) {
10
- return typeof abstract === "function" ? abstract.name || "<anonymous class>" : abstract.description;
11
- }
12
- var BindingResolutionError = class extends Error {
13
- kind = "BindingResolution";
14
- name = "BindingResolutionError";
15
- };
16
- var CircularDependencyError = class extends Error {
17
- constructor(chain) {
18
- super(`Circular dependency detected: ${chain.join(" -> ")}`);
19
- this.chain = chain;
20
- }
21
- chain;
22
- kind = "CircularDependency";
23
- name = "CircularDependencyError";
24
- };
25
- var ContainerNotAvailableError = class extends Error {
26
- kind = "ContainerNotAvailable";
27
- name = "ContainerNotAvailableError";
28
- constructor(what) {
29
- super(
30
- `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.`
31
- );
32
- }
33
- };
34
- var ALS_KEY = /* @__PURE__ */ Symbol.for("oriel:container.als");
35
- var GLOBAL_KEY = /* @__PURE__ */ Symbol.for("oriel:container.instance");
36
- var BUILDING_KEY = /* @__PURE__ */ Symbol.for("oriel:container.building");
37
- var g = globalThis;
38
- var storage = g[ALS_KEY] ??= new AsyncLocalStorage();
39
- var building = g[BUILDING_KEY] ??= {
40
- keys: [],
41
- names: [],
42
- containers: []
43
- };
44
- function currentContainer() {
45
- return building.containers.at(-1) ?? storage.getStore() ?? g[GLOBAL_KEY];
46
- }
47
- function inject(abstract) {
48
- const container = currentContainer();
49
- if (!container) throw new ContainerNotAvailableError(describe(abstract));
50
- return container.make(abstract);
51
- }
52
- var globals = globalThis;
53
- var keyOf = (abstract) => typeof abstract === "function" ? abstract : abstract.id;
54
- var isClass = (fn) => typeof fn === "function" && /^class[\s{]/.test(Function.prototype.toString.call(fn));
55
- var Container2 = class _Container {
56
- static getInstance() {
57
- return globals[GLOBAL_KEY];
58
- }
59
- static setInstance(container) {
60
- globals[GLOBAL_KEY] = container;
61
- }
62
- shared;
63
- root;
64
- parent;
65
- local = /* @__PURE__ */ new Map();
66
- constructor(parent) {
67
- this.parent = parent;
68
- this.root = parent?.root ?? this;
69
- this.shared = parent?.shared ?? { bindings: /* @__PURE__ */ new Map(), extenders: /* @__PURE__ */ new Map(), resolving: /* @__PURE__ */ new Map(), resolved: /* @__PURE__ */ new Set() };
70
- this.local.set(keyOf(Container), this);
71
- this.local.set(_Container, this);
72
- }
73
- bind(abstract, concrete) {
74
- this.#assertRoot("bind");
75
- this.#addBinding(abstract, concrete, "transient");
76
- }
77
- singleton(abstract, concrete) {
78
- this.#assertRoot("singleton");
79
- this.#addBinding(abstract, concrete, "singleton");
80
- }
81
- scoped(abstract, concrete) {
82
- this.#assertRoot("scoped");
83
- this.#addBinding(abstract, concrete, "scoped");
84
- }
85
- instance(abstract, instance) {
86
- const key = keyOf(abstract);
87
- this.local.set(key, instance);
88
- if (this === this.root) this.shared.resolved.add(key);
89
- return instance;
90
- }
91
- make(abstract) {
92
- const key = keyOf(abstract);
93
- const owner = this.#owning(key);
94
- if (owner) return owner.local.get(key);
95
- const binding = this.shared.bindings.get(key) ?? this.#implicitBinding(abstract);
96
- if (binding.lifetime === "scoped" && this === this.root) {
97
- throw new BindingResolutionError(
98
- `Scoped binding [${describe(abstract)}] was resolved outside a scope. Resolve it inside app.createScope().run(...), and don't inject scoped services into singletons.`
99
- );
100
- }
101
- const builder = binding.lifetime === "singleton" ? this.root : this;
102
- const instance = builder.build(abstract, key, binding);
103
- if (binding.lifetime === "singleton") this.root.local.set(key, instance);
104
- if (binding.lifetime === "scoped") this.local.set(key, instance);
105
- return instance;
106
- }
107
- bound(abstract) {
108
- const key = keyOf(abstract);
109
- return this.shared.bindings.has(key) || this.#owning(key) !== void 0;
110
- }
111
- resolved(abstract) {
112
- const key = keyOf(abstract);
113
- return this.shared.resolved.has(key) || this.#owning(key) !== void 0;
114
- }
115
- extend(abstract, extender) {
116
- this.#assertRoot("extend");
117
- const key = keyOf(abstract);
118
- const list = this.shared.extenders.get(key) ?? [];
119
- list.push(extender);
120
- this.shared.extenders.set(key, list);
121
- if (this.local.has(key)) this.local.set(key, extender(this.local.get(key), this));
122
- }
123
- resolving(abstract, callback) {
124
- this.#assertRoot("resolving");
125
- const key = keyOf(abstract);
126
- const list = this.shared.resolving.get(key) ?? [];
127
- list.push(callback);
128
- this.shared.resolving.set(key, list);
129
- }
130
- forgetInstance(abstract) {
131
- this.local.delete(keyOf(abstract));
132
- }
133
- /** Scopes are always plain Containers (never subclasses such as Application). */
134
- createScope() {
135
- return new _Container(this);
136
- }
137
- run(fn) {
138
- return storage.run(this, fn);
139
- }
140
- /** The nearest container in this -> parent scopes -> root that holds an instance for the key. */
141
- #owning(key) {
142
- if (this.local.has(key)) return this;
143
- return this.parent === void 0 ? void 0 : this.parent.#owning(key);
144
- }
145
- /** Bindings, extenders and callbacks are app-wide state: a request scope must never write them. */
146
- #assertRoot(method) {
147
- if (this !== this.root) {
148
- throw new Error(
149
- `Cannot register bindings on a request scope (${method}). Register them on the application in a service provider; use instance() for per-request values.`
150
- );
151
- }
152
- }
153
- #addBinding(abstract, concrete, lifetime) {
154
- const key = keyOf(abstract);
155
- let factory;
156
- if (concrete === void 0) {
157
- if (typeof abstract !== "function") throw new TypeError(`bind(${describe(abstract)}) needs a concrete: tokens can't be constructed`);
158
- factory = () => new abstract();
159
- } else if (isClass(concrete)) {
160
- factory = () => new concrete();
161
- } else {
162
- factory = concrete;
163
- }
164
- this.shared.bindings.set(key, { lifetime, factory });
165
- this.local.delete(key);
166
- }
167
- #implicitBinding(abstract) {
168
- if (typeof abstract === "function") {
169
- return { lifetime: "transient", factory: () => new abstract() };
170
- }
171
- throw new BindingResolutionError(
172
- `Target [${abstract.description}] is not bound. Is its service provider registered in bootstrap/providers.ts?`
173
- );
174
- }
175
- build(abstract, key, binding) {
176
- const stackIndex = building.keys.indexOf(key);
177
- if (stackIndex !== -1) {
178
- const chain = [...building.names.slice(stackIndex), describe(abstract)];
179
- throw new CircularDependencyError(chain);
180
- }
181
- building.keys.push(key);
182
- building.names.push(describe(abstract));
183
- building.containers.push(this);
184
- try {
185
- let instance = binding.factory(this);
186
- for (const extender of this.shared.extenders.get(key) ?? []) instance = extender(instance, this);
187
- for (const callback of this.shared.resolving.get(key) ?? []) callback(instance, this);
188
- this.shared.resolved.add(key);
189
- return instance;
190
- } finally {
191
- building.keys.pop();
192
- building.names.pop();
193
- building.containers.pop();
194
- }
195
- }
196
- };
197
-
198
- // ../Collections/dist/index.js
199
- function compare(left, operator, right) {
200
- switch (operator) {
201
- case "=":
202
- case "==":
203
- return left == right;
204
- case "===":
205
- return left === right;
206
- case "!=":
207
- case "<>":
208
- return left != right;
209
- case "!==":
210
- return left !== right;
211
- case "<":
212
- return left < right;
213
- case "<=":
214
- return left <= right;
215
- case ">":
216
- return left > right;
217
- case ">=":
218
- return left >= right;
219
- }
220
- }
221
- function ascending(a, b) {
222
- const aNil = a === null || a === void 0;
223
- const bNil = b === null || b === void 0;
224
- if (aNil || bNil) return aNil === bNil ? 0 : aNil ? 1 : -1;
225
- if (typeof a === "number" && typeof b === "number") return a - b;
226
- if (a instanceof Date && b instanceof Date) return a.getTime() - b.getTime();
227
- return String(a).localeCompare(String(b));
228
- }
229
- var read = (item, getter) => typeof getter === "function" ? getter(item) : item?.[getter];
230
- var isArrayable = (v) => typeof v === "object" && v !== null && typeof v.toArray === "function";
231
- var numbers = (items, getter) => items.map((item) => getter === void 0 ? item : read(item, getter)).filter((v) => typeof v === "number" && !Number.isNaN(v));
232
- var Collection = class _Collection {
233
- items;
234
- constructor(items = []) {
235
- this.items = [...items];
236
- }
237
- static make(items = []) {
238
- return new _Collection(items);
239
- }
240
- /** Laravel semantics: callback receives 1..n. */
241
- static times(count, callback) {
242
- return new _Collection(Array.from({ length: Math.max(0, count) }, (_, i) => callback(i + 1)));
243
- }
244
- [Symbol.iterator]() {
245
- return this.items[Symbol.iterator]();
246
- }
247
- all() {
248
- return [...this.items];
249
- }
250
- count() {
251
- return this.items.length;
252
- }
253
- isEmpty() {
254
- return this.items.length === 0;
255
- }
256
- isNotEmpty() {
257
- return this.items.length > 0;
258
- }
259
- toArray() {
260
- return this.items.map((i) => isArrayable(i) ? i.toArray() : i);
261
- }
262
- toJSON() {
263
- return this.all();
264
- }
265
- toJson() {
266
- return JSON.stringify(this);
267
- }
268
- map(callback) {
269
- return new _Collection(this.items.map(callback));
270
- }
271
- flatMap(callback) {
272
- return new _Collection(
273
- this.items.flatMap((item, i) => {
274
- const out = callback(item, i);
275
- return out instanceof _Collection ? out.all() : out;
276
- })
277
- );
278
- }
279
- filter(callback) {
280
- return new _Collection(this.items.filter(callback ?? ((item) => Boolean(item))));
281
- }
282
- reject(callback) {
283
- return new _Collection(this.items.filter((item, i) => !callback(item, i)));
284
- }
285
- /** Return false from the callback to stop. */
286
- each(callback) {
287
- for (let i = 0; i < this.items.length; i++) if (callback(this.items[i], i) === false) break;
288
- return this;
289
- }
290
- reduce(callback, initial) {
291
- return this.items.reduce(callback, initial);
292
- }
293
- first(callback, defaultValue) {
294
- if (!callback) return this.items[0];
295
- const index = this.items.findIndex(callback);
296
- return index === -1 ? defaultValue : this.items[index];
297
- }
298
- last(callback, defaultValue) {
299
- if (!callback) return this.items.at(-1);
300
- const index = this.items.findLastIndex(callback);
301
- return index === -1 ? defaultValue : this.items[index];
302
- }
303
- where(key, operatorOrValue, value2) {
304
- const [op, expected] = arguments.length === 2 ? ["=", operatorOrValue] : [operatorOrValue, value2];
305
- return this.filter((item) => compare(read(item, key), op, expected));
306
- }
307
- firstWhere(key, operatorOrValue, value2) {
308
- const [op, expected] = arguments.length === 2 ? ["=", operatorOrValue] : [operatorOrValue, value2];
309
- return this.items.find((item) => compare(read(item, key), op, expected));
310
- }
311
- whereIn(key, values) {
312
- const set = new Set(values);
313
- return this.filter((item) => set.has(read(item, key)));
314
- }
315
- whereNotIn(key, values) {
316
- const set = new Set(values);
317
- return this.filter((item) => !set.has(read(item, key)));
318
- }
319
- pluck(key) {
320
- return this.map((item) => read(item, key));
321
- }
322
- keyBy(key) {
323
- return Object.fromEntries(this.items.map((item) => [String(read(item, key)), item]));
324
- }
325
- groupBy(key) {
326
- const groups = {};
327
- for (const item of this.items) (groups[String(read(item, key))] ??= new _Collection()).push(item);
328
- return groups;
329
- }
330
- mapWithKeys(callback) {
331
- return Object.fromEntries(this.items.map(callback));
332
- }
333
- sortBy(key, direction = "asc") {
334
- const sign = direction === "asc" ? 1 : -1;
335
- return new _Collection(
336
- this.items.map((item, index) => ({ item, index, value: read(item, key) })).sort((a, b) => {
337
- const aNil = a.value === null || a.value === void 0;
338
- const bNil = b.value === null || b.value === void 0;
339
- if (aNil || bNil) return aNil === bNil ? a.index - b.index : aNil ? 1 : -1;
340
- return sign * ascending(a.value, b.value) || a.index - b.index;
341
- }).map((x) => x.item)
342
- );
343
- }
344
- sortByDesc(key) {
345
- return this.sortBy(key, "desc");
346
- }
347
- sum(key) {
348
- return numbers(this.items, key).reduce((a, b) => a + b, 0);
349
- }
350
- avg(key) {
351
- const values = numbers(this.items, key);
352
- return values.length ? values.reduce((a, b) => a + b, 0) / values.length : void 0;
353
- }
354
- min(key) {
355
- const values = numbers(this.items, key);
356
- return values.length ? Math.min(...values) : void 0;
357
- }
358
- max(key) {
359
- const values = numbers(this.items, key);
360
- return values.length ? Math.max(...values) : void 0;
361
- }
362
- unique(key) {
363
- const seen = /* @__PURE__ */ new Set();
364
- return this.filter((item) => {
365
- const v = key === void 0 ? item : read(item, key);
366
- if (seen.has(v)) return false;
367
- seen.add(v);
368
- return true;
369
- });
370
- }
371
- chunk(size) {
372
- if (size <= 0) return new _Collection();
373
- const chunks = [];
374
- for (let i = 0; i < this.items.length; i += size) chunks.push(new _Collection(this.items.slice(i, i + size)));
375
- return new _Collection(chunks);
376
- }
377
- /** Negative count takes from the end. */
378
- take(count) {
379
- return new _Collection(count < 0 ? this.items.slice(count) : this.items.slice(0, count));
380
- }
381
- skip(count) {
382
- return new _Collection(this.items.slice(count));
383
- }
384
- slice(offset, length) {
385
- return new _Collection(this.items.slice(offset, length === void 0 ? void 0 : offset + length));
386
- }
387
- values() {
388
- return new _Collection(this.items);
389
- }
390
- contains(keyOrValue, value2) {
391
- if (arguments.length === 2) return this.items.some((item) => read(item, keyOrValue) === value2);
392
- if (typeof keyOrValue === "function") return this.items.some(keyOrValue);
393
- return this.items.includes(keyOrValue);
394
- }
395
- /** Mutates, like Laravel. */
396
- push(...values) {
397
- this.items.push(...values);
398
- return this;
399
- }
400
- concat(values) {
401
- return new _Collection([...this.items, ...values]);
402
- }
403
- partition(callback) {
404
- return [this.filter(callback), this.reject(callback)];
405
- }
406
- implode(keyOrGlue, glue) {
407
- if (glue === void 0) return this.items.join(keyOrGlue);
408
- return this.items.map((item) => read(item, keyOrGlue)).join(glue);
409
- }
410
- when(condition, callback) {
411
- return condition ? callback(this) : this;
412
- }
413
- pipe(callback) {
414
- return callback(this);
415
- }
416
- tap(callback) {
417
- callback(this);
418
- return this;
419
- }
420
- };
421
- function collect(items = []) {
422
- return new Collection(items);
423
- }
424
- var LazyCollection = class _LazyCollection {
425
- constructor(source) {
426
- this.source = source;
427
- }
428
- source;
429
- static make(source) {
430
- return new _LazyCollection(source);
431
- }
432
- async *[Symbol.asyncIterator]() {
433
- yield* this.source();
434
- }
435
- map(callback) {
436
- const self = this;
437
- return new _LazyCollection(async function* () {
438
- let i = 0;
439
- for await (const item of self) yield await callback(item, i++);
440
- });
441
- }
442
- filter(callback) {
443
- const self = this;
444
- return new _LazyCollection(async function* () {
445
- let i = 0;
446
- for await (const item of self) if (await callback(item, i++)) yield item;
447
- });
448
- }
449
- take(count) {
450
- const self = this;
451
- return new _LazyCollection(async function* () {
452
- if (count <= 0) return;
453
- let taken = 0;
454
- for await (const item of self) {
455
- yield item;
456
- if (++taken >= count) return;
457
- }
458
- });
459
- }
460
- chunk(size) {
461
- const self = this;
462
- return new _LazyCollection(async function* () {
463
- if (size <= 0) return;
464
- let buffer = [];
465
- for await (const item of self) {
466
- buffer.push(item);
467
- if (buffer.length === size) {
468
- yield new Collection(buffer);
469
- buffer = [];
470
- }
471
- }
472
- if (buffer.length) yield new Collection(buffer);
473
- });
474
- }
475
- /** Return false from the callback to stop. */
476
- async each(callback) {
477
- let i = 0;
478
- for await (const item of this) if (await callback(item, i++) === false) return;
479
- }
480
- async first(callback) {
481
- for await (const item of this) if (!callback || await callback(item)) return item;
482
- return void 0;
483
- }
484
- async count() {
485
- let n = 0;
486
- for await (const item of this) {
487
- void item;
488
- n++;
489
- }
490
- return n;
491
- }
492
- async collect() {
493
- const items = [];
494
- for await (const item of this) items.push(item);
495
- return new Collection(items);
496
- }
497
- };
498
-
499
- // ../Support/dist/index.js
500
- import { randomBytes, randomUUID } from "crypto";
501
- import pluralize from "pluralize";
502
- import { setTimeout as sleep } from "timers/promises";
503
- 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);
504
- var ALPHANUM = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
505
- var escapeRegex = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
506
- var anyOf = (needles) => (Array.isArray(needles) ? needles : [needles]).filter((n) => n !== "");
507
- var Str = {
508
- ucfirst: (v) => v.charAt(0).toUpperCase() + v.slice(1),
509
- lcfirst: (v) => v.charAt(0).toLowerCase() + v.slice(1),
510
- studly: (v) => words(v).map((w) => Str.ucfirst(w.toLowerCase())).join(""),
511
- camel: (v) => Str.lcfirst(Str.studly(v)),
512
- snake: (v, delimiter = "_") => words(v).map((w) => w.toLowerCase()).join(delimiter),
513
- kebab: (v) => Str.snake(v, "-"),
514
- title: (v) => v.toLowerCase().replace(/(^|\s)\S/g, (m) => m.toUpperCase()),
515
- slug: (v, separator = "-") => v.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z\d]+/g, separator).replace(new RegExp(`^${escapeRegex(separator)}+|${escapeRegex(separator)}+$`, "g"), ""),
516
- plural: (v, count = 2) => pluralize(v, count),
517
- singular: (v) => pluralize.singular(v),
518
- random: (length = 16) => {
519
- let out = "";
520
- while (out.length < length) {
521
- for (const byte of randomBytes(length)) {
522
- if (byte < 248 && out.length < length) out += ALPHANUM[byte % 62];
523
- }
524
- }
525
- return out;
526
- },
527
- uuid: () => randomUUID(),
528
- /** Wildcard match: `*` matches anything; everything else is literal. */
529
- is: (pattern, value2) => pattern === value2 || new RegExp(`^${pattern.split("*").map(escapeRegex).join(".*")}$`, "s").test(value2),
530
- startsWith: (v, needles) => anyOf(needles).some((n) => v.startsWith(n)),
531
- endsWith: (v, needles) => anyOf(needles).some((n) => v.endsWith(n)),
532
- contains: (v, needles) => anyOf(needles).some((n) => v.includes(n)),
533
- after: (v, search) => search === "" || !v.includes(search) ? v : v.slice(v.indexOf(search) + search.length),
534
- afterLast: (v, search) => search === "" || !v.includes(search) ? v : v.slice(v.lastIndexOf(search) + search.length),
535
- before: (v, search) => search === "" || !v.includes(search) ? v : v.slice(0, v.indexOf(search)),
536
- beforeLast: (v, search) => search === "" || !v.includes(search) ? v : v.slice(0, v.lastIndexOf(search)),
537
- between: (v, from, to) => Str.beforeLast(Str.after(v, from), to),
538
- limit: (v, limit = 100, end = "...") => v.length <= limit ? v : v.slice(0, limit).trimEnd() + end,
539
- start: (v, prefix) => v.startsWith(prefix) ? v : prefix + v,
540
- finish: (v, cap) => v.endsWith(cap) ? v : v + cap
541
- };
542
- var FORBIDDEN = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
543
- var isWalkable = (v) => typeof v === "object" && v !== null;
544
- var segments = (key) => key.split(".");
545
- var Arr = {
546
- get(target, key, defaultValue) {
547
- if (key === void 0 || key === "") return target;
548
- let current = target;
549
- for (const segment of segments(key)) {
550
- if (!isWalkable(current) || !Object.hasOwn(current, segment)) return defaultValue;
551
- current = current[segment];
552
- }
553
- return current;
554
- },
555
- has(target, key) {
556
- const missing = /* @__PURE__ */ Symbol("missing");
557
- return Arr.get(target, key, missing) !== missing;
558
- },
559
- set(target, key, value2) {
560
- const parts = segments(key);
561
- if (parts.some((p) => FORBIDDEN.has(p))) throw new Error(`Refusing to set unsafe key "${key}"`);
562
- let current = target;
563
- parts.slice(0, -1).forEach((segment) => {
564
- if (!isWalkable(current[segment])) current[segment] = {};
565
- current = current[segment];
566
- });
567
- current[parts.at(-1)] = value2;
568
- return target;
569
- },
570
- forget(target, key) {
571
- const parts = segments(key);
572
- const parent = parts.length === 1 ? target : Arr.get(target, parts.slice(0, -1).join("."));
573
- if (isWalkable(parent)) delete parent[parts.at(-1)];
574
- },
575
- dot(target, prefix = "") {
576
- const out = {};
577
- for (const [k, v] of Object.entries(target)) {
578
- const path = prefix + k;
579
- if (isWalkable(v) && Object.keys(v).length > 0) Object.assign(out, Arr.dot(v, `${path}.`));
580
- else out[path] = v;
581
- }
582
- return out;
583
- },
584
- undot(flat) {
585
- const out = {};
586
- for (const [k, v] of Object.entries(flat)) Arr.set(out, k, v);
587
- return out;
588
- },
589
- only(target, keys) {
590
- return Object.fromEntries(keys.filter((k) => Object.hasOwn(target, k)).map((k) => [k, target[k]]));
591
- },
592
- except(target, keys) {
593
- const skip = new Set(keys);
594
- return Object.fromEntries(Object.entries(target).filter(([k]) => !skip.has(k)));
595
- },
596
- wrap(value2) {
597
- if (value2 === null || value2 === void 0) return [];
598
- return Array.isArray(value2) ? value2 : [value2];
599
- },
600
- first(items, predicate, defaultValue) {
601
- const index = predicate ? items.findIndex(predicate) : items.length > 0 ? 0 : -1;
602
- return index === -1 ? defaultValue : items[index];
603
- },
604
- last(items, predicate, defaultValue) {
605
- const index = predicate ? items.findLastIndex(predicate) : items.length - 1;
606
- return index === -1 ? defaultValue : items[index];
607
- }
608
- };
609
- var ServiceProvider = class {
610
- constructor(app2) {
611
- this.app = app2;
612
- }
613
- app;
614
- register() {
615
- }
616
- boot() {
617
- }
618
- /** Package defaults under `key`; values the app already set win (shallow merge, like Laravel). */
619
- mergeConfigFrom(defaults, key) {
620
- const config2 = this.app.make(ConfigRepository);
621
- config2.set(key, { ...defaults, ...config2.get(key, {}) });
622
- }
623
- };
624
- function facade(abstract, extras) {
625
- const container = () => {
626
- const c = currentContainer();
627
- if (!c) throw new ContainerNotAvailableError(describe(abstract));
628
- return c;
629
- };
630
- const statics = {
631
- getFacadeRoot: () => container().make(abstract),
632
- swap: (instance) => void container().instance(abstract, instance)
633
- };
634
- const proxy = new Proxy({}, {
635
- get(_target, prop) {
636
- if (typeof prop === "symbol" || prop === "then") return void 0;
637
- if (extras && Object.hasOwn(extras, prop)) {
638
- const extra = extras[prop];
639
- return typeof extra === "function" ? extra.bind(proxy) : extra;
640
- }
641
- if (Object.hasOwn(statics, prop)) return statics[prop];
642
- const root = statics.getFacadeRoot();
643
- const value2 = Reflect.get(root, prop, root);
644
- return typeof value2 === "function" ? value2.bind(root) : value2;
645
- }
646
- });
647
- return proxy;
648
- }
649
- var ClassRegistry = class {
650
- byName = /* @__PURE__ */ new Map();
651
- byClass = /* @__PURE__ */ new Map();
652
- register(cls, name = cls.name) {
653
- const existingName = this.byClass.get(cls);
654
- if (existingName !== void 0) return existingName;
655
- if (!name) throw new Error('Anonymous classes need an explicit name: registry.register(cls, "Some.Name")');
656
- const existing = this.byName.get(name);
657
- if (existing && existing !== cls) {
658
- throw new Error(`"${name}" is already registered to a different class. Pass an explicit name: register(cls, "Module.${name}")`);
659
- }
660
- this.byName.set(name, cls);
661
- this.byClass.set(cls, name);
662
- return name;
663
- }
664
- nameOf(cls) {
665
- return this.byClass.get(cls);
666
- }
667
- resolve(name) {
668
- const cls = this.byName.get(name);
669
- if (!cls) throw new Error(`No class registered as "${name}". Is it registered by its service provider?`);
670
- return cls;
671
- }
672
- has(name) {
673
- return this.byName.has(name);
674
- }
675
- };
676
- var SCOPE_METHODS = /* @__PURE__ */ new Set(["make", "instance", "bound", "resolved", "forgetInstance", "createScope", "run"]);
677
- var scopedViews = /* @__PURE__ */ new WeakMap();
678
- function viewFrom(scope, application) {
679
- let view = scopedViews.get(scope);
680
- if (view === void 0) {
681
- view = new Proxy(application, {
682
- get(target, property) {
683
- const source = SCOPE_METHODS.has(property) ? scope : target;
684
- const member = Reflect.get(source, property, source);
685
- return typeof member === "function" ? member.bind(source) : member;
686
- }
687
- });
688
- scopedViews.set(scope, view);
689
- }
690
- return view;
691
- }
692
- function app(abstract) {
693
- if (abstract !== void 0) return inject(abstract);
694
- const application = inject(Application);
695
- const current = currentContainer();
696
- return current === void 0 || current === application ? application : viewFrom(current, application);
697
- }
698
- function config(keyOrValues, defaultValue) {
699
- const repository = inject(ConfigRepository);
700
- if (keyOrValues === void 0) return repository;
701
- if (typeof keyOrValues === "string") return repository.get(keyOrValues, defaultValue);
702
- repository.set(keyOrValues);
703
- return void 0;
704
- }
705
- var now = () => /* @__PURE__ */ new Date();
706
- var value = (v) => typeof v === "function" ? v() : v;
707
- function tap(target, callback) {
708
- callback(target);
709
- return target;
710
- }
711
- async function retry(times, fn, sleepMs = 0, when) {
712
- for (let attempt = 1; ; attempt++) {
713
- try {
714
- return await fn(attempt);
715
- } catch (error) {
716
- if (attempt >= times || when && !when(error)) throw error;
717
- const ms = typeof sleepMs === "function" ? sleepMs(attempt) : sleepMs;
718
- if (ms > 0) await sleep(ms);
719
- }
720
- }
721
- }
722
-
723
- export {
724
- BindingResolutionError,
725
- CircularDependencyError,
726
- ContainerNotAvailableError,
727
- currentContainer,
728
- inject,
729
- Container2 as Container,
730
- Collection,
731
- collect,
732
- LazyCollection,
733
- Str,
734
- Arr,
735
- ServiceProvider,
736
- facade,
737
- ClassRegistry,
738
- app,
739
- config,
740
- now,
741
- value,
742
- tap,
743
- retry
744
- };
745
- //# sourceMappingURL=chunk-HU43NADT.js.map