@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.
@@ -0,0 +1,799 @@
1
+ /** A typed, runtime-unique key for container bindings. */
2
+ interface Token$3<T> {
3
+ readonly id: symbol;
4
+ readonly description: string;
5
+ /** Phantom field: only carries T at the type level. Never set at runtime. */
6
+ readonly __type?: T;
7
+ }
8
+ type Class$2<T> = abstract new (...args: any[]) => T;
9
+ type Abstract$2<T> = Token$3<T> | Class$2<T>;
10
+ type Factory$2<T> = (container: Container$4) => T;
11
+ type Concrete$2<T> = Factory$2<T> | (new () => T);
12
+ interface Container$4 {
13
+ /** New instance on every make(). A class with no concrete binds to itself (constructed with no args). Root only; throws on a scope. */
14
+ bind<T>(abstract: Abstract$2<T>, concrete?: Concrete$2<T>): void;
15
+ /** One instance for the life of this container and its scopes. Root only; throws on a scope. */
16
+ singleton<T>(abstract: Abstract$2<T>, concrete?: Concrete$2<T>): void;
17
+ /** One instance per scope (e.g. per HTTP request or queue job). Root only; throws on a scope. */
18
+ scoped<T>(abstract: Abstract$2<T>, concrete?: Concrete$2<T>): void;
19
+ /** Register an existing object as a shared instance. Returns it. On a scope it stays local to that scope. */
20
+ instance<T>(abstract: Abstract$2<T>, instance: T): T;
21
+ /** Resolve. Unbound classes are constructed with `new Class()`. Unbound tokens throw BindingResolutionError. */
22
+ make<T>(abstract: Abstract$2<T>): T;
23
+ bound(abstract: Abstract$2<unknown>): boolean;
24
+ resolved(abstract: Abstract$2<unknown>): boolean;
25
+ /** Decorate or replace an instance each time it's resolved (applied before resolving callbacks). Root only; throws on a scope. */
26
+ extend<T>(abstract: Abstract$2<T>, extender: (instance: T, container: Container$4) => T): void;
27
+ /** Called after each resolution of the abstract. Root only; throws on a scope. */
28
+ resolving<T>(abstract: Abstract$2<T>, callback: (instance: T, container: Container$4) => void): void;
29
+ forgetInstance(abstract: Abstract$2<unknown>): void;
30
+ /** A child container: shares bindings and singletons with its parent, and has its own scoped instances. Bindings can't be registered on it. */
31
+ createScope(): Container$4;
32
+ /** Run fn with this container as the "current" one for inject(), helpers and facades (AsyncLocalStorage). */
33
+ run<R>(fn: () => R): R;
34
+ }
35
+ declare const Container$4: Token$3<Container$4>;
36
+
37
+ type ErrorKind = 'Http' | 'ModelNotFound' | 'Validation' | 'Authentication' | 'Authorization' | 'TokenMismatch' | 'BindingResolution' | 'CircularDependency' | 'ContainerNotAvailable';
38
+ /** Every error thrown by the framework implements this. The exception handler switches on `kind`. */
39
+ interface OrielError extends Error {
40
+ readonly kind: ErrorKind;
41
+ /** HTTP status the error should render as, when relevant. */
42
+ readonly status?: number;
43
+ readonly headers?: Record<string, string>;
44
+ }
45
+
46
+ type Key$1 = unknown;
47
+ type Lifetime$1 = 'transient' | 'singleton' | 'scoped';
48
+ interface Binding$1 {
49
+ lifetime: Lifetime$1;
50
+ factory: Factory$2<unknown>;
51
+ }
52
+ type Extender$1 = (instance: unknown, c: Container$4) => unknown;
53
+ type Callback$1 = (instance: unknown, c: Container$4) => void;
54
+ interface SharedState$1 {
55
+ bindings: Map<Key$1, Binding$1>;
56
+ extenders: Map<Key$1, Extender$1[]>;
57
+ resolving: Map<Key$1, Callback$1[]>;
58
+ resolved: Set<Key$1>;
59
+ }
60
+ declare class Container$3 implements Container$4 {
61
+ #private;
62
+ static getInstance(): Container$3 | undefined;
63
+ static setInstance(container: Container$3 | undefined): void;
64
+ protected readonly shared: SharedState$1;
65
+ protected readonly root: Container$3;
66
+ protected readonly parent: Container$3 | undefined;
67
+ protected readonly local: Map<unknown, unknown>;
68
+ constructor(parent?: Container$3);
69
+ bind<T>(abstract: Abstract$2<T>, concrete?: Concrete$2<T>): void;
70
+ singleton<T>(abstract: Abstract$2<T>, concrete?: Concrete$2<T>): void;
71
+ scoped<T>(abstract: Abstract$2<T>, concrete?: Concrete$2<T>): void;
72
+ instance<T>(abstract: Abstract$2<T>, instance: T): T;
73
+ make<T>(abstract: Abstract$2<T>): T;
74
+ bound(abstract: Abstract$2<unknown>): boolean;
75
+ resolved(abstract: Abstract$2<unknown>): boolean;
76
+ extend<T>(abstract: Abstract$2<T>, extender: (instance: T, container: Container$4) => T): void;
77
+ resolving<T>(abstract: Abstract$2<T>, callback: (instance: T, container: Container$4) => void): void;
78
+ forgetInstance(abstract: Abstract$2<unknown>): void;
79
+ /** Scopes are always plain Containers (never subclasses such as Application). */
80
+ createScope(): Container$3;
81
+ run<R>(fn: () => R): R;
82
+ protected build(abstract: Abstract$2<unknown>, key: Key$1, binding: Binding$1): unknown;
83
+ }
84
+
85
+ declare class BindingResolutionError extends Error implements OrielError {
86
+ readonly kind: "BindingResolution";
87
+ readonly name = "BindingResolutionError";
88
+ }
89
+ declare class CircularDependencyError extends Error implements OrielError {
90
+ readonly chain: string[];
91
+ readonly kind: "CircularDependency";
92
+ readonly name = "CircularDependencyError";
93
+ constructor(chain: string[]);
94
+ }
95
+ declare class ContainerNotAvailableError extends Error implements OrielError {
96
+ readonly kind: "ContainerNotAvailable";
97
+ readonly name = "ContainerNotAvailableError";
98
+ constructor(what: string);
99
+ }
100
+
101
+ declare function currentContainer(): Container$4 | undefined;
102
+ declare function inject<T>(abstract: Abstract$2<T>): T;
103
+
104
+ interface Arrayable<T = unknown> {
105
+ toArray(): T;
106
+ }
107
+ /** The minimal collection surface contracts rely on (implemented by @orieljs/collections). */
108
+ interface Enumerable<T> extends Iterable<T>, Arrayable<unknown[]> {
109
+ all(): T[];
110
+ count(): number;
111
+ isEmpty(): boolean;
112
+ }
113
+
114
+ type Operator$1 = '=' | '==' | '===' | '!=' | '!==' | '<>' | '<' | '<=' | '>' | '>=';
115
+
116
+ type Getter$1<T, V = unknown> = (keyof T & string) | ((item: T) => V);
117
+ declare class Collection$1<T> implements Enumerable<T> {
118
+ protected readonly items: T[];
119
+ constructor(items?: Iterable<T>);
120
+ static make<T>(items?: Iterable<T>): Collection$1<T>;
121
+ /** Laravel semantics: callback receives 1..n. */
122
+ static times<T>(count: number, callback: (index: number) => T): Collection$1<T>;
123
+ [Symbol.iterator](): Iterator<T>;
124
+ all(): T[];
125
+ count(): number;
126
+ isEmpty(): boolean;
127
+ isNotEmpty(): boolean;
128
+ toArray(): unknown[];
129
+ toJSON(): T[];
130
+ toJson(): string;
131
+ map<U>(callback: (item: T, index: number) => U): Collection$1<U>;
132
+ flatMap<U>(callback: (item: T, index: number) => U | U[] | Collection$1<U>): Collection$1<U>;
133
+ filter(callback?: (item: T, index: number) => unknown): Collection$1<T>;
134
+ reject(callback: (item: T, index: number) => unknown): Collection$1<T>;
135
+ /** Return false from the callback to stop. */
136
+ each(callback: (item: T, index: number) => unknown): this;
137
+ reduce<U>(callback: (carry: U, item: T, index: number) => U, initial: U): U;
138
+ first(): T | undefined;
139
+ first<D = undefined>(callback: (item: T, index: number) => unknown, defaultValue?: D): T | D;
140
+ last(): T | undefined;
141
+ last<D = undefined>(callback: (item: T, index: number) => unknown, defaultValue?: D): T | D;
142
+ where(key: Getter$1<T>, value: unknown): Collection$1<T>;
143
+ where(key: Getter$1<T>, operator: Operator$1, value: unknown): Collection$1<T>;
144
+ firstWhere(key: Getter$1<T>, value: unknown): T | undefined;
145
+ firstWhere(key: Getter$1<T>, operator: Operator$1, value: unknown): T | undefined;
146
+ whereIn(key: Getter$1<T>, values: readonly unknown[]): Collection$1<T>;
147
+ whereNotIn(key: Getter$1<T>, values: readonly unknown[]): Collection$1<T>;
148
+ pluck<K extends keyof T & string>(key: K): Collection$1<T[K]>;
149
+ keyBy(key: Getter$1<T>): Record<string, T>;
150
+ groupBy(key: Getter$1<T>): Record<string, Collection$1<T>>;
151
+ mapWithKeys<V>(callback: (item: T, index: number) => readonly [string, V]): Record<string, V>;
152
+ sortBy(key: Getter$1<T>, direction?: 'asc' | 'desc'): Collection$1<T>;
153
+ sortByDesc(key: Getter$1<T>): Collection$1<T>;
154
+ sum(key?: Getter$1<T>): number;
155
+ avg(key?: Getter$1<T>): number | undefined;
156
+ min(key?: Getter$1<T>): number | undefined;
157
+ max(key?: Getter$1<T>): number | undefined;
158
+ unique(key?: Getter$1<T>): Collection$1<T>;
159
+ chunk(size: number): Collection$1<Collection$1<T>>;
160
+ /** Negative count takes from the end. */
161
+ take(count: number): Collection$1<T>;
162
+ skip(count: number): Collection$1<T>;
163
+ slice(offset: number, length?: number): Collection$1<T>;
164
+ values(): Collection$1<T>;
165
+ contains(key: keyof T & string, value: unknown): boolean;
166
+ contains(callback: (item: T) => boolean): boolean;
167
+ contains(value: unknown): boolean;
168
+ /** Mutates, like Laravel. */
169
+ push(...values: T[]): this;
170
+ concat(values: Iterable<T>): Collection$1<T>;
171
+ partition(callback: (item: T, index: number) => unknown): [Collection$1<T>, Collection$1<T>];
172
+ implode(glue: string): string;
173
+ implode(key: keyof T & string, glue: string): string;
174
+ when<U = this>(condition: unknown, callback: (collection: this) => U): U | this;
175
+ pipe<U>(callback: (collection: this) => U): U;
176
+ tap(callback: (collection: this) => void): this;
177
+ }
178
+
179
+ type Source<T> = () => AsyncIterable<T> | Iterable<T>;
180
+ /** Pull-based and async: for DB cursors (Model.lazy()) and large files. */
181
+ declare class LazyCollection<T> implements AsyncIterable<T> {
182
+ private readonly source;
183
+ constructor(source: Source<T>);
184
+ static make<T>(source: Source<T>): LazyCollection<T>;
185
+ [Symbol.asyncIterator](): AsyncIterator<T>;
186
+ map<U>(callback: (item: T, index: number) => U | Promise<U>): LazyCollection<U>;
187
+ filter(callback: (item: T, index: number) => unknown): LazyCollection<T>;
188
+ take(count: number): LazyCollection<T>;
189
+ chunk(size: number): LazyCollection<Collection$1<T>>;
190
+ /** Return false from the callback to stop. */
191
+ each(callback: (item: T, index: number) => unknown): Promise<void>;
192
+ first(callback?: (item: T) => unknown): Promise<T | undefined>;
193
+ count(): Promise<number>;
194
+ collect(): Promise<Collection$1<T>>;
195
+ }
196
+
197
+ /** A typed, runtime-unique key for container bindings. */
198
+ interface Token$2<T> {
199
+ readonly id: symbol;
200
+ readonly description: string;
201
+ /** Phantom field: only carries T at the type level. Never set at runtime. */
202
+ readonly __type?: T;
203
+ }
204
+ type Class$1<T> = abstract new (...args: any[]) => T;
205
+ type Abstract$1<T> = Token$2<T> | Class$1<T>;
206
+ type Factory$1<T> = (container: Container$2) => T;
207
+ type Concrete$1<T> = Factory$1<T> | (new () => T);
208
+ interface Container$2 {
209
+ /** New instance on every make(). A class with no concrete binds to itself (constructed with no args). Root only; throws on a scope. */
210
+ bind<T>(abstract: Abstract$1<T>, concrete?: Concrete$1<T>): void;
211
+ /** One instance for the life of this container and its scopes. Root only; throws on a scope. */
212
+ singleton<T>(abstract: Abstract$1<T>, concrete?: Concrete$1<T>): void;
213
+ /** One instance per scope (e.g. per HTTP request or queue job). Root only; throws on a scope. */
214
+ scoped<T>(abstract: Abstract$1<T>, concrete?: Concrete$1<T>): void;
215
+ /** Register an existing object as a shared instance. Returns it. On a scope it stays local to that scope. */
216
+ instance<T>(abstract: Abstract$1<T>, instance: T): T;
217
+ /** Resolve. Unbound classes are constructed with `new Class()`. Unbound tokens throw BindingResolutionError. */
218
+ make<T>(abstract: Abstract$1<T>): T;
219
+ bound(abstract: Abstract$1<unknown>): boolean;
220
+ resolved(abstract: Abstract$1<unknown>): boolean;
221
+ /** Decorate or replace an instance each time it's resolved (applied before resolving callbacks). Root only; throws on a scope. */
222
+ extend<T>(abstract: Abstract$1<T>, extender: (instance: T, container: Container$2) => T): void;
223
+ /** Called after each resolution of the abstract. Root only; throws on a scope. */
224
+ resolving<T>(abstract: Abstract$1<T>, callback: (instance: T, container: Container$2) => void): void;
225
+ forgetInstance(abstract: Abstract$1<unknown>): void;
226
+ /** A child container: shares bindings and singletons with its parent, and has its own scoped instances. Bindings can't be registered on it. */
227
+ createScope(): Container$2;
228
+ /** Run fn with this container as the "current" one for inject(), helpers and facades (AsyncLocalStorage). */
229
+ run<R>(fn: () => R): R;
230
+ }
231
+ declare const Container$2: Token$2<Container$2>;
232
+
233
+ interface ServiceProvider$2 {
234
+ /** Bind things into the container. Synchronous. Don't resolve other services here. */
235
+ register?(): void;
236
+ /** Runs after every provider is registered. May be async (e.g. importing route files). */
237
+ boot?(): void | Promise<void>;
238
+ }
239
+ type ServiceProviderClass$1 = new (app: Application$2) => ServiceProvider$2;
240
+ interface Application$2 extends Container$2 {
241
+ readonly version: string;
242
+ basePath(path?: string): string;
243
+ appPath(path?: string): string;
244
+ bootstrapPath(path?: string): string;
245
+ configPath(path?: string): string;
246
+ databasePath(path?: string): string;
247
+ publicPath(path?: string): string;
248
+ resourcePath(path?: string): string;
249
+ storagePath(path?: string): string;
250
+ /** With no args returns the environment name. With args returns whether it matches any of them. */
251
+ environment(): string;
252
+ environment(...environments: string[]): boolean;
253
+ isProduction(): boolean;
254
+ isLocal(): boolean;
255
+ runningInConsole(): boolean;
256
+ /** Mark the app as running in the console (the CLI entry point calls this). Defaults to true. */
257
+ setRunningInConsole(value?: boolean): void;
258
+ runningUnitTests(): boolean;
259
+ /** Registers the provider. If the app is already booted, the provider is booted immediately. */
260
+ register(provider: ServiceProvider$2 | ServiceProviderClass$1): Promise<ServiceProvider$2>;
261
+ getProviders(): ServiceProvider$2[];
262
+ boot(): Promise<void>;
263
+ isBooted(): boolean;
264
+ booting(callback: (app: Application$2) => void | Promise<void>): void;
265
+ booted(callback: (app: Application$2) => void | Promise<void>): void;
266
+ /** Handle one HTTP request in a fresh request scope via the bound HttpKernel. */
267
+ handle(request: Request): Promise<Response>;
268
+ /** Register a callback that terminate() runs, in registration order. */
269
+ terminating(callback: () => void | Promise<void>): void;
270
+ terminate(): Promise<void>;
271
+ }
272
+ declare const Application$2: Token$2<Application$2>;
273
+
274
+ interface ConfigRepository$1 {
275
+ has(key: string): boolean;
276
+ /** Dot notation: get('database.connections.sqlite.database'). */
277
+ get<T = unknown>(key: string, defaultValue?: T): T;
278
+ set(key: string, value: unknown): void;
279
+ set(values: Record<string, unknown>): void;
280
+ push(key: string, value: unknown): void;
281
+ all(): Record<string, unknown>;
282
+ }
283
+ declare const ConfigRepository$1: Token$2<ConfigRepository$1>;
284
+ interface ClassRegistry$1 {
285
+ /** Registers under `name` (default: cls.name). Throws if the name is already taken by a different class. */
286
+ register(cls: Class$1<unknown>, name?: string): string;
287
+ nameOf(cls: Class$1<unknown>): string | undefined;
288
+ resolve<T = unknown>(name: string): Class$1<T>;
289
+ has(name: string): boolean;
290
+ }
291
+ declare const ClassRegistry$1: Token$2<ClassRegistry$1>;
292
+
293
+ type Operator = '=' | '==' | '===' | '!=' | '!==' | '<>' | '<' | '<=' | '>' | '>=';
294
+
295
+ type Getter<T, V = unknown> = (keyof T & string) | ((item: T) => V);
296
+ declare class Collection<T> implements Enumerable<T> {
297
+ protected readonly items: T[];
298
+ constructor(items?: Iterable<T>);
299
+ static make<T>(items?: Iterable<T>): Collection<T>;
300
+ /** Laravel semantics: callback receives 1..n. */
301
+ static times<T>(count: number, callback: (index: number) => T): Collection<T>;
302
+ [Symbol.iterator](): Iterator<T>;
303
+ all(): T[];
304
+ count(): number;
305
+ isEmpty(): boolean;
306
+ isNotEmpty(): boolean;
307
+ toArray(): unknown[];
308
+ toJSON(): T[];
309
+ toJson(): string;
310
+ map<U>(callback: (item: T, index: number) => U): Collection<U>;
311
+ flatMap<U>(callback: (item: T, index: number) => U | U[] | Collection<U>): Collection<U>;
312
+ filter(callback?: (item: T, index: number) => unknown): Collection<T>;
313
+ reject(callback: (item: T, index: number) => unknown): Collection<T>;
314
+ /** Return false from the callback to stop. */
315
+ each(callback: (item: T, index: number) => unknown): this;
316
+ reduce<U>(callback: (carry: U, item: T, index: number) => U, initial: U): U;
317
+ first(): T | undefined;
318
+ first<D = undefined>(callback: (item: T, index: number) => unknown, defaultValue?: D): T | D;
319
+ last(): T | undefined;
320
+ last<D = undefined>(callback: (item: T, index: number) => unknown, defaultValue?: D): T | D;
321
+ where(key: Getter<T>, value: unknown): Collection<T>;
322
+ where(key: Getter<T>, operator: Operator, value: unknown): Collection<T>;
323
+ firstWhere(key: Getter<T>, value: unknown): T | undefined;
324
+ firstWhere(key: Getter<T>, operator: Operator, value: unknown): T | undefined;
325
+ whereIn(key: Getter<T>, values: readonly unknown[]): Collection<T>;
326
+ whereNotIn(key: Getter<T>, values: readonly unknown[]): Collection<T>;
327
+ pluck<K extends keyof T & string>(key: K): Collection<T[K]>;
328
+ keyBy(key: Getter<T>): Record<string, T>;
329
+ groupBy(key: Getter<T>): Record<string, Collection<T>>;
330
+ mapWithKeys<V>(callback: (item: T, index: number) => readonly [string, V]): Record<string, V>;
331
+ sortBy(key: Getter<T>, direction?: 'asc' | 'desc'): Collection<T>;
332
+ sortByDesc(key: Getter<T>): Collection<T>;
333
+ sum(key?: Getter<T>): number;
334
+ avg(key?: Getter<T>): number | undefined;
335
+ min(key?: Getter<T>): number | undefined;
336
+ max(key?: Getter<T>): number | undefined;
337
+ unique(key?: Getter<T>): Collection<T>;
338
+ chunk(size: number): Collection<Collection<T>>;
339
+ /** Negative count takes from the end. */
340
+ take(count: number): Collection<T>;
341
+ skip(count: number): Collection<T>;
342
+ slice(offset: number, length?: number): Collection<T>;
343
+ values(): Collection<T>;
344
+ contains(key: keyof T & string, value: unknown): boolean;
345
+ contains(callback: (item: T) => boolean): boolean;
346
+ contains(value: unknown): boolean;
347
+ /** Mutates, like Laravel. */
348
+ push(...values: T[]): this;
349
+ concat(values: Iterable<T>): Collection<T>;
350
+ partition(callback: (item: T, index: number) => unknown): [Collection<T>, Collection<T>];
351
+ implode(glue: string): string;
352
+ implode(key: keyof T & string, glue: string): string;
353
+ when<U = this>(condition: unknown, callback: (collection: this) => U): U | this;
354
+ pipe<U>(callback: (collection: this) => U): U;
355
+ tap(callback: (collection: this) => void): this;
356
+ }
357
+ declare function collect<T>(items?: Iterable<T>): Collection<T>;
358
+
359
+ declare const Str: {
360
+ ucfirst: (v: string) => string;
361
+ lcfirst: (v: string) => string;
362
+ studly: (v: string) => string;
363
+ camel: (v: string) => string;
364
+ snake: (v: string, delimiter?: string) => string;
365
+ kebab: (v: string) => string;
366
+ title: (v: string) => string;
367
+ slug: (v: string, separator?: string) => string;
368
+ plural: (v: string, count?: number) => string;
369
+ singular: (v: string) => string;
370
+ random: (length?: number) => string;
371
+ uuid: () => `${string}-${string}-${string}-${string}-${string}`;
372
+ /** Wildcard match: `*` matches anything; everything else is literal. */
373
+ is: (pattern: string, value: string) => boolean;
374
+ startsWith: (v: string, needles: string | string[]) => boolean;
375
+ endsWith: (v: string, needles: string | string[]) => boolean;
376
+ contains: (v: string, needles: string | string[]) => boolean;
377
+ after: (v: string, search: string) => string;
378
+ afterLast: (v: string, search: string) => string;
379
+ before: (v: string, search: string) => string;
380
+ beforeLast: (v: string, search: string) => string;
381
+ between: (v: string, from: string, to: string) => string;
382
+ limit: (v: string, limit?: number, end?: string) => string;
383
+ start: (v: string, prefix: string) => string;
384
+ finish: (v: string, cap: string) => string;
385
+ };
386
+
387
+ type Obj = Record<string, unknown>;
388
+ declare const Arr: {
389
+ get<T = unknown>(target: unknown, key: string | undefined, defaultValue?: T): T;
390
+ has(target: unknown, key: string): boolean;
391
+ set(target: Obj, key: string, value: unknown): Obj;
392
+ forget(target: Obj, key: string): void;
393
+ dot(target: Obj, prefix?: string): Obj;
394
+ undot(flat: Obj): Obj;
395
+ only<T extends Obj>(target: T, keys: string[]): Partial<T>;
396
+ except<T extends Obj>(target: T, keys: string[]): Partial<T>;
397
+ wrap<T>(value: T | T[] | null | undefined): T[];
398
+ first<T, D = undefined>(items: readonly T[], predicate?: (item: T, index: number) => boolean, defaultValue?: D): T | D;
399
+ last<T, D = undefined>(items: readonly T[], predicate?: (item: T, index: number) => boolean, defaultValue?: D): T | D;
400
+ };
401
+
402
+ declare abstract class ServiceProvider$1 implements ServiceProvider$2 {
403
+ protected readonly app: Application$2;
404
+ constructor(app: Application$2);
405
+ register(): void;
406
+ boot(): void | Promise<void>;
407
+ /** Package defaults under `key`; values the app already set win (shallow merge, like Laravel). */
408
+ protected mergeConfigFrom(defaults: Record<string, unknown>, key: string): void;
409
+ }
410
+
411
+ interface FacadeStatics<T> {
412
+ getFacadeRoot(): T;
413
+ /** Replace the instance in the current container (used by X.fake()). */
414
+ swap(instance: T): void;
415
+ }
416
+ type Facade<T, X = object> = T & X & FacadeStatics<T>;
417
+ declare function facade<T extends object, X extends object = object>(abstract: Abstract$1<T>, extras?: X): Facade<T, X>;
418
+
419
+ declare class ClassRegistry implements ClassRegistry$1 {
420
+ private readonly byName;
421
+ private readonly byClass;
422
+ register(cls: Class$1<unknown>, name?: string): string;
423
+ nameOf(cls: Class$1<unknown>): string | undefined;
424
+ resolve<T = unknown>(name: string): Class$1<T>;
425
+ has(name: string): boolean;
426
+ }
427
+
428
+ /**
429
+ * The application, or an abstract resolved from the current container.
430
+ * Inside a request scope, app().make()/instance()/… act on that scope, so app().make(X) sees scoped services.
431
+ */
432
+ declare function app(): Application$2;
433
+ declare function app<T>(abstract: Abstract$1<T>): T;
434
+ declare function config(): ConfigRepository$1;
435
+ declare function config(values: Record<string, unknown>): void;
436
+ declare function config<T = unknown>(key: string, defaultValue?: T): T;
437
+ declare const now: () => Date;
438
+ declare const value: <T>(v: T | (() => T)) => T;
439
+ declare function tap<T>(target: T, callback: (target: T) => void): T;
440
+ /** Calls fn up to `times` times (attempt numbers are 1-based). Rethrows the last error, or the first one `when` rejects. */
441
+ declare function retry<T>(times: number, fn: (attempt: number) => T | Promise<T>, sleepMs?: number | ((attempt: number) => number), when?: (error: unknown) => boolean): Promise<T>;
442
+
443
+ /** A typed, runtime-unique key for container bindings. */
444
+ interface Token$1<T> {
445
+ readonly id: symbol;
446
+ readonly description: string;
447
+ /** Phantom field: only carries T at the type level. Never set at runtime. */
448
+ readonly __type?: T;
449
+ }
450
+
451
+ interface ConfigRepository {
452
+ has(key: string): boolean;
453
+ /** Dot notation: get('database.connections.sqlite.database'). */
454
+ get<T = unknown>(key: string, defaultValue?: T): T;
455
+ set(key: string, value: unknown): void;
456
+ set(values: Record<string, unknown>): void;
457
+ push(key: string, value: unknown): void;
458
+ all(): Record<string, unknown>;
459
+ }
460
+ declare const ConfigRepository: Token$1<ConfigRepository>;
461
+
462
+ declare class Repository implements ConfigRepository {
463
+ private readonly items;
464
+ constructor(items?: Record<string, unknown>);
465
+ has(key: string): boolean;
466
+ get<T = unknown>(key: string, defaultValue?: T): T;
467
+ set(key: string, value: unknown): void;
468
+ set(values: Record<string, unknown>): void;
469
+ push(key: string, value: unknown): void;
470
+ all(): Record<string, unknown>;
471
+ }
472
+
473
+ declare function env<T = undefined>(key: string, defaultValue?: T | (() => T)): T | string | boolean | null;
474
+
475
+ /** A typed, runtime-unique key for container bindings. */
476
+ interface Token<T> {
477
+ readonly id: symbol;
478
+ readonly description: string;
479
+ /** Phantom field: only carries T at the type level. Never set at runtime. */
480
+ readonly __type?: T;
481
+ }
482
+ type Class<T> = abstract new (...args: any[]) => T;
483
+ type Abstract<T> = Token<T> | Class<T>;
484
+ type Factory<T> = (container: Container$1) => T;
485
+ type Concrete<T> = Factory<T> | (new () => T);
486
+ interface Container$1 {
487
+ /** New instance on every make(). A class with no concrete binds to itself (constructed with no args). Root only; throws on a scope. */
488
+ bind<T>(abstract: Abstract<T>, concrete?: Concrete<T>): void;
489
+ /** One instance for the life of this container and its scopes. Root only; throws on a scope. */
490
+ singleton<T>(abstract: Abstract<T>, concrete?: Concrete<T>): void;
491
+ /** One instance per scope (e.g. per HTTP request or queue job). Root only; throws on a scope. */
492
+ scoped<T>(abstract: Abstract<T>, concrete?: Concrete<T>): void;
493
+ /** Register an existing object as a shared instance. Returns it. On a scope it stays local to that scope. */
494
+ instance<T>(abstract: Abstract<T>, instance: T): T;
495
+ /** Resolve. Unbound classes are constructed with `new Class()`. Unbound tokens throw BindingResolutionError. */
496
+ make<T>(abstract: Abstract<T>): T;
497
+ bound(abstract: Abstract<unknown>): boolean;
498
+ resolved(abstract: Abstract<unknown>): boolean;
499
+ /** Decorate or replace an instance each time it's resolved (applied before resolving callbacks). Root only; throws on a scope. */
500
+ extend<T>(abstract: Abstract<T>, extender: (instance: T, container: Container$1) => T): void;
501
+ /** Called after each resolution of the abstract. Root only; throws on a scope. */
502
+ resolving<T>(abstract: Abstract<T>, callback: (instance: T, container: Container$1) => void): void;
503
+ forgetInstance(abstract: Abstract<unknown>): void;
504
+ /** A child container: shares bindings and singletons with its parent, and has its own scoped instances. Bindings can't be registered on it. */
505
+ createScope(): Container$1;
506
+ /** Run fn with this container as the "current" one for inject(), helpers and facades (AsyncLocalStorage). */
507
+ run<R>(fn: () => R): R;
508
+ }
509
+ declare const Container$1: Token<Container$1>;
510
+
511
+ interface ServiceProvider {
512
+ /** Bind things into the container. Synchronous. Don't resolve other services here. */
513
+ register?(): void;
514
+ /** Runs after every provider is registered. May be async (e.g. importing route files). */
515
+ boot?(): void | Promise<void>;
516
+ }
517
+ type ServiceProviderClass = new (app: Application$1) => ServiceProvider;
518
+ interface Application$1 extends Container$1 {
519
+ readonly version: string;
520
+ basePath(path?: string): string;
521
+ appPath(path?: string): string;
522
+ bootstrapPath(path?: string): string;
523
+ configPath(path?: string): string;
524
+ databasePath(path?: string): string;
525
+ publicPath(path?: string): string;
526
+ resourcePath(path?: string): string;
527
+ storagePath(path?: string): string;
528
+ /** With no args returns the environment name. With args returns whether it matches any of them. */
529
+ environment(): string;
530
+ environment(...environments: string[]): boolean;
531
+ isProduction(): boolean;
532
+ isLocal(): boolean;
533
+ runningInConsole(): boolean;
534
+ /** Mark the app as running in the console (the CLI entry point calls this). Defaults to true. */
535
+ setRunningInConsole(value?: boolean): void;
536
+ runningUnitTests(): boolean;
537
+ /** Registers the provider. If the app is already booted, the provider is booted immediately. */
538
+ register(provider: ServiceProvider | ServiceProviderClass): Promise<ServiceProvider>;
539
+ getProviders(): ServiceProvider[];
540
+ boot(): Promise<void>;
541
+ isBooted(): boolean;
542
+ booting(callback: (app: Application$1) => void | Promise<void>): void;
543
+ booted(callback: (app: Application$1) => void | Promise<void>): void;
544
+ /** Handle one HTTP request in a fresh request scope via the bound HttpKernel. */
545
+ handle(request: Request): Promise<Response>;
546
+ /** Register a callback that terminate() runs, in registration order. */
547
+ terminating(callback: () => void | Promise<void>): void;
548
+ terminate(): Promise<void>;
549
+ }
550
+ declare const Application$1: Token<Application$1>;
551
+ /** The object passed to Application.configure().withExceptions(e => …), like Laravel's Exceptions class. */
552
+ interface ExceptionsConfigurator {
553
+ /** Custom reporting. Return false to stop the default logging. */
554
+ report(callback: (error: unknown) => void | boolean | Promise<void | boolean>): this;
555
+ /** Custom rendering. Return undefined to fall through to the default rendering. */
556
+ render(callback: (error: unknown, request: unknown) => Response | undefined | Promise<Response | undefined>): this;
557
+ /** Never report errors of these classes. */
558
+ dontReport(...classes: Array<abstract new (...args: never[]) => Error>): this;
559
+ }
560
+
561
+ /** The session of the current request (scoped). Loaded and saved by the StartSession middleware. */
562
+ interface Session {
563
+ getId(): string;
564
+ start(): Promise<void>;
565
+ save(): Promise<void>;
566
+ all(): Record<string, unknown>;
567
+ has(key: string): boolean;
568
+ get<T = unknown>(key: string, defaultValue?: T): T;
569
+ put(key: string | Record<string, unknown>, value?: unknown): void;
570
+ push(key: string, value: unknown): void;
571
+ pull<T = unknown>(key: string, defaultValue?: T): T;
572
+ forget(...keys: string[]): void;
573
+ flush(): void;
574
+ flash(key: string, value: unknown): void;
575
+ now(key: string, value: unknown): void;
576
+ reflash(): void;
577
+ keep(...keys: string[]): void;
578
+ getOldInput<T = unknown>(key?: string, defaultValue?: T): T;
579
+ flashInput(input: Record<string, unknown>): void;
580
+ token(): string;
581
+ regenerateToken(): void;
582
+ regenerate(destroy?: boolean): Promise<void>;
583
+ invalidate(): Promise<void>;
584
+ previousUrl(): string | undefined;
585
+ setPreviousUrl(url: string): void;
586
+ }
587
+ declare const Session: Token<Session>;
588
+ interface UploadedFile {
589
+ readonly clientName: string;
590
+ readonly mimeType: string;
591
+ readonly size: number;
592
+ extension(): string;
593
+ arrayBuffer(): Promise<ArrayBuffer>;
594
+ /** Stores on a Filesystem disk. Returns the stored path. */
595
+ store(directory: string, disk?: string): Promise<string>;
596
+ storeAs(directory: string, name: string, disk?: string): Promise<string>;
597
+ }
598
+ /**
599
+ * Oriel's request wrapper (one per request, scoped).
600
+ * The Http kernel awaits `load()` before any middleware runs, so every input accessor below is synchronous.
601
+ */
602
+ interface HttpRequest {
603
+ readonly raw: Request;
604
+ load(): Promise<this>;
605
+ method(): string;
606
+ isMethod(method: string): boolean;
607
+ url(): string;
608
+ fullUrl(): string;
609
+ path(): string;
610
+ is(...patterns: string[]): boolean;
611
+ routeIs(...names: string[]): boolean;
612
+ header(name: string): string | undefined;
613
+ header(name: string, defaultValue: string): string;
614
+ bearerToken(): string | undefined;
615
+ ip(): string | undefined;
616
+ expectsJson(): boolean;
617
+ ajax(): boolean;
618
+ query<T = unknown>(key?: string, defaultValue?: T): T;
619
+ input<T = unknown>(key?: string, defaultValue?: T): T;
620
+ all(): Record<string, unknown>;
621
+ only(...keys: string[]): Record<string, unknown>;
622
+ except(...keys: string[]): Record<string, unknown>;
623
+ has(...keys: string[]): boolean;
624
+ filled(key: string): boolean;
625
+ boolean(key: string, defaultValue?: boolean): boolean;
626
+ integer(key: string, defaultValue?: number): number;
627
+ merge(values: Record<string, unknown>): this;
628
+ file(key: string): UploadedFile | undefined;
629
+ cookie(name: string): string | undefined;
630
+ /** Route parameter (after model binding), or every parameter when called with no key. */
631
+ route<T = unknown>(key?: string): T;
632
+ session(): Session;
633
+ /** The user resolved earlier by auth middleware. Undefined for guests. Use `await Auth.user()` to resolve lazily. */
634
+ user<T = unknown>(guard?: string): T | undefined;
635
+ setUserResolver(resolver: (guard?: string) => unknown): void;
636
+ }
637
+ declare const HttpRequest: Token<HttpRequest>;
638
+ type Next = (request: HttpRequest) => Promise<Response>;
639
+ interface Middleware {
640
+ handle(request: HttpRequest, next: Next, ...parameters: string[]): Promise<Response>;
641
+ terminate?(request: HttpRequest, response: Response): Promise<void>;
642
+ }
643
+ type MiddlewareClass = new (...args: any[]) => Middleware;
644
+ /** The object passed to Application.configure().withMiddleware(m => …), like Laravel's Middleware class. */
645
+ interface MiddlewareConfigurator {
646
+ append(...middleware: MiddlewareClass[]): this;
647
+ prepend(...middleware: MiddlewareClass[]): this;
648
+ web(options: {
649
+ append?: MiddlewareClass[];
650
+ prepend?: MiddlewareClass[];
651
+ remove?: MiddlewareClass[];
652
+ }): this;
653
+ api(options: {
654
+ append?: MiddlewareClass[];
655
+ prepend?: MiddlewareClass[];
656
+ remove?: MiddlewareClass[];
657
+ }): this;
658
+ alias(aliases: Record<string, MiddlewareClass>): this;
659
+ group(name: string, middleware: Array<MiddlewareClass | string>): this;
660
+ validateCsrfTokens(options: {
661
+ except: string[];
662
+ }): this;
663
+ redirectGuestsTo(url: string | ((request: HttpRequest) => string)): this;
664
+ }
665
+ interface HttpKernel {
666
+ handle(request: Request): Promise<Response>;
667
+ terminate?(request: Request, response: Response): Promise<void>;
668
+ }
669
+ declare const HttpKernel: Token<HttpKernel>;
670
+
671
+ type Key = unknown;
672
+ type Lifetime = 'transient' | 'singleton' | 'scoped';
673
+ interface Binding {
674
+ lifetime: Lifetime;
675
+ factory: Factory$2<unknown>;
676
+ }
677
+ type Extender = (instance: unknown, c: Container$4) => unknown;
678
+ type Callback = (instance: unknown, c: Container$4) => void;
679
+ interface SharedState {
680
+ bindings: Map<Key, Binding>;
681
+ extenders: Map<Key, Extender[]>;
682
+ resolving: Map<Key, Callback[]>;
683
+ resolved: Set<Key>;
684
+ }
685
+ declare class Container implements Container$4 {
686
+ #private;
687
+ static getInstance(): Container | undefined;
688
+ static setInstance(container: Container | undefined): void;
689
+ protected readonly shared: SharedState;
690
+ protected readonly root: Container;
691
+ protected readonly parent: Container | undefined;
692
+ protected readonly local: Map<unknown, unknown>;
693
+ constructor(parent?: Container);
694
+ bind<T>(abstract: Abstract$2<T>, concrete?: Concrete$2<T>): void;
695
+ singleton<T>(abstract: Abstract$2<T>, concrete?: Concrete$2<T>): void;
696
+ scoped<T>(abstract: Abstract$2<T>, concrete?: Concrete$2<T>): void;
697
+ instance<T>(abstract: Abstract$2<T>, instance: T): T;
698
+ make<T>(abstract: Abstract$2<T>): T;
699
+ bound(abstract: Abstract$2<unknown>): boolean;
700
+ resolved(abstract: Abstract$2<unknown>): boolean;
701
+ extend<T>(abstract: Abstract$2<T>, extender: (instance: T, container: Container$4) => T): void;
702
+ resolving<T>(abstract: Abstract$2<T>, callback: (instance: T, container: Container$4) => void): void;
703
+ forgetInstance(abstract: Abstract$2<unknown>): void;
704
+ /** Scopes are always plain Containers (never subclasses such as Application). */
705
+ createScope(): Container;
706
+ run<R>(fn: () => R): R;
707
+ protected build(abstract: Abstract$2<unknown>, key: Key, binding: Binding): unknown;
708
+ }
709
+
710
+ interface RoutingOptions {
711
+ web?: string;
712
+ api?: string;
713
+ console?: string;
714
+ /** A URI such as '/up', not a file. */
715
+ health?: string;
716
+ apiPrefix?: string;
717
+ }
718
+ type Lifecycle = (app: Application$1) => void | Promise<void>;
719
+ declare class ApplicationBuilder {
720
+ private readonly app;
721
+ private readonly providers;
722
+ private readonly middleware;
723
+ private readonly exceptions;
724
+ private routing;
725
+ constructor(app: Application);
726
+ withProviders(providers?: Array<ServiceProvider | ServiceProviderClass>): this;
727
+ withRouting(options: RoutingOptions): this;
728
+ withMiddleware(callback: (middleware: MiddlewareConfigurator) => void): this;
729
+ withExceptions(callback: (exceptions: ExceptionsConfigurator) => void): this;
730
+ booting(callback: Lifecycle): this;
731
+ booted(callback: Lifecycle): this;
732
+ create(): Promise<Application>;
733
+ }
734
+
735
+ type LifecycleCallback = (app: Application$1) => void | Promise<void>;
736
+ declare class Application extends Container implements Application$1 {
737
+ private readonly base;
738
+ readonly version = "0.0.0";
739
+ private readonly providers;
740
+ private readonly bootingCallbacks;
741
+ private readonly bootedCallbacks;
742
+ private readonly terminatingCallbacks;
743
+ private bootPromise;
744
+ private hasBooted;
745
+ private inConsole;
746
+ constructor(base: string);
747
+ /** Entry point used by bootstrap/app.ts. */
748
+ static configure(options: {
749
+ basePath: string;
750
+ }): ApplicationBuilder;
751
+ basePath(path?: string): string;
752
+ appPath(path?: string): string;
753
+ bootstrapPath(path?: string): string;
754
+ configPath(path?: string): string;
755
+ databasePath(path?: string): string;
756
+ publicPath(path?: string): string;
757
+ resourcePath(path?: string): string;
758
+ storagePath(path?: string): string;
759
+ environment(): string;
760
+ environment(...environments: string[]): boolean;
761
+ isProduction(): boolean;
762
+ isLocal(): boolean;
763
+ runningUnitTests(): boolean;
764
+ runningInConsole(): boolean;
765
+ setRunningInConsole(value?: boolean): void;
766
+ register(provider: ServiceProvider | ServiceProviderClass): Promise<ServiceProvider>;
767
+ getProviders(): ServiceProvider[];
768
+ boot(): Promise<void>;
769
+ isBooted(): boolean;
770
+ booting(callback: LifecycleCallback): void;
771
+ /** If already booted, the callback runs immediately (a rejection surfaces as an unhandled rejection). */
772
+ booted(callback: LifecycleCallback): void;
773
+ terminating(callback: () => void | Promise<void>): void;
774
+ handle(request: Request): Promise<Response>;
775
+ terminate(): Promise<void>;
776
+ private runBoot;
777
+ private bootProvider;
778
+ }
779
+
780
+ type Handler = (request: Request) => unknown;
781
+ /** Wave 0 stand-in for the Http kernel: exact "METHOD /path" matching only. Replaced by Wave 1's router. */
782
+ declare class ClosureKernel implements HttpKernel {
783
+ private readonly routes;
784
+ on(method: string, path: string, handler: Handler): this;
785
+ handle(request: Request): Promise<Response>;
786
+ }
787
+
788
+ declare class ProviderBootError extends Error {
789
+ readonly provider: string;
790
+ readonly name = "ProviderBootError";
791
+ constructor(provider: string, cause: unknown);
792
+ }
793
+ declare class ProviderRegisterError extends Error {
794
+ readonly provider: string;
795
+ readonly name = "ProviderRegisterError";
796
+ constructor(provider: string, cause: unknown);
797
+ }
798
+
799
+ export { Application, ApplicationBuilder, Arr, BindingResolutionError, CircularDependencyError, ClassRegistry, ClosureKernel, Collection$1 as Collection, Container$3 as Container, ContainerNotAvailableError, type Facade, type FacadeStatics, LazyCollection, ProviderBootError, ProviderRegisterError, Repository, type RoutingOptions, ServiceProvider$1 as ServiceProvider, Str, app, collect, config, currentContainer, env, facade, inject, now, retry, tap, value };