@orieljs/routing 0.1.0-alpha.1

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 ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,9 @@
1
+ Oriel
2
+ Copyright 2026 meeeet-dev and Oriel contributors
3
+
4
+ This product includes software developed by the Oriel project
5
+ (https://orieljs.vercel.app, https://github.com/orieljs).
6
+
7
+ Oriel is licensed under the Apache License, Version 2.0 (see LICENSE).
8
+ The Oriel name and logo are not covered by that license; see TRADEMARKS.md
9
+ (https://github.com/orieljs/framework/blob/main/TRADEMARKS.md).
@@ -0,0 +1,352 @@
1
+ import { Route as Route$1, RouteAction, Class, MiddlewareReference, RouteRegistrar, ResourceOptions, ControllerAction, RouteClosure, Router, Container, MiddlewareClass, HttpRequest, UrlGenerator, OrielError, Middleware, ModelNotFoundError, Application } from '@orieljs/contracts';
2
+ import * as _orieljs_support from '@orieljs/support';
3
+ import { ServiceProvider } from '@orieljs/support';
4
+
5
+ /** A closure, a [Controller, 'method'] tuple, or a method name inside Route.controller(X).group(). */
6
+ type RouteHandler = RouteAction | string;
7
+ interface RouteAttributes {
8
+ /** The group's name prefix ('admin.'); name() appends to it. */
9
+ namePrefix?: string;
10
+ /** Group middleware; the route's own middleware() is appended after it. */
11
+ middleware?: MiddlewareReference[];
12
+ /** The group controller that string actions call. */
13
+ controller?: Class<unknown>;
14
+ fallback?: boolean;
15
+ }
16
+ interface UriParameter {
17
+ readonly name: string;
18
+ readonly optional: boolean;
19
+ /** The binding column from '{post:slug}'. */
20
+ readonly field: string | undefined;
21
+ }
22
+ declare function parseParameters(uri: string): UriParameter[];
23
+ /** Laravel stores URIs without surrounding slashes, and '/' for the root. */
24
+ declare function normalizeUri(uri: string): string;
25
+ /** The form compiled patterns match against: '/posts/1/' → '/posts/1', '/' → ''. */
26
+ declare function normalizePath(pathname: string): string;
27
+ /** Sort order for matching: fallbacks last, then per-segment specificity; ties keep registration order. */
28
+ declare function compareRoutes(a: RouteDefinition, b: RouteDefinition): number;
29
+ declare class RouteDefinition implements Route$1 {
30
+ #private;
31
+ readonly methods: readonly string[];
32
+ readonly uri: string;
33
+ readonly action: RouteHandler;
34
+ readonly controller: Class<unknown> | undefined;
35
+ readonly isFallback: boolean;
36
+ readonly parameters: readonly UriParameter[];
37
+ constructor(methods: readonly string[], uri: string, action: RouteHandler, attributes?: RouteAttributes);
38
+ getName(): string | undefined;
39
+ /** Appends, like Laravel's $action['as'] .= $name. */
40
+ name(name: string): this;
41
+ middleware(...middleware: MiddlewareReference[]): this;
42
+ withoutMiddleware(...middleware: MiddlewareReference[]): this;
43
+ where(parameter: string | Record<string, string>, pattern?: string): this;
44
+ gatherMiddleware(): MiddlewareReference[];
45
+ excludedMiddleware(): MiddlewareReference[];
46
+ wheres(): Record<string, string>;
47
+ getActionName(): string;
48
+ /** Decoded parameter values when `path` (normalizePath output) matches, else undefined. */
49
+ match(path: string, patterns?: Readonly<Record<string, string>>, version?: number): Record<string, string | undefined> | undefined;
50
+ /** Per-segment specificity: static 0, parameter 1, optional parameter 2. Lower sorts first. */
51
+ rank(): number[];
52
+ }
53
+
54
+ /** Attributes shared by the routes of a group (Laravel's group attribute array). */
55
+ interface GroupAttributes {
56
+ prefix?: string;
57
+ /** Name prefix ('admin.'). */
58
+ as?: string;
59
+ middleware?: MiddlewareReference[];
60
+ controller?: Class<unknown>;
61
+ }
62
+ /** What a GroupRegistrar needs from the router. */
63
+ interface GroupHost {
64
+ group(attributes: GroupAttributes, routes: () => void | Promise<void>): Promise<void>;
65
+ addRoute(methods: readonly string[], uri: string, action: RouteHandler): RouteDefinition;
66
+ resource(name: string, controller: Class<unknown>, options?: ResourceOptions): void;
67
+ apiResource(name: string, controller: Class<unknown>, options?: ResourceOptions): void;
68
+ }
69
+ /** Merges a nested group's attributes into its parent's, like Laravel's RouteGroup::merge. */
70
+ declare function mergeGroup(parent: GroupAttributes, child: GroupAttributes): GroupAttributes;
71
+ /**
72
+ * Route.prefix('admin').name('admin.').middleware('auth').group(() => …), and the one-route form
73
+ * Route.middleware('auth').get('/x', action) (Laravel's RouteRegistrar).
74
+ */
75
+ declare class GroupRegistrar implements RouteRegistrar {
76
+ #private;
77
+ private readonly router;
78
+ constructor(router: GroupHost);
79
+ prefix(prefix: string): this;
80
+ name(prefix: string): this;
81
+ middleware(...middleware: MiddlewareReference[]): this;
82
+ controller(controller: Class<unknown>): this;
83
+ group(routes: () => void | Promise<void>): Promise<void>;
84
+ get<C>(uri: string, action: ControllerAction<C> | RouteClosure | string): RouteDefinition;
85
+ post<C>(uri: string, action: ControllerAction<C> | RouteClosure | string): RouteDefinition;
86
+ put<C>(uri: string, action: ControllerAction<C> | RouteClosure | string): RouteDefinition;
87
+ patch<C>(uri: string, action: ControllerAction<C> | RouteClosure | string): RouteDefinition;
88
+ delete<C>(uri: string, action: ControllerAction<C> | RouteClosure | string): RouteDefinition;
89
+ options<C>(uri: string, action: ControllerAction<C> | RouteClosure | string): RouteDefinition;
90
+ any<C>(uri: string, action: ControllerAction<C> | RouteClosure | string): RouteDefinition;
91
+ match<C>(methods: string[], uri: string, action: ControllerAction<C> | RouteClosure | string): RouteDefinition;
92
+ resource(name: string, controller: Class<unknown>, options?: ResourceOptions): void;
93
+ apiResource(name: string, controller: Class<unknown>, options?: ResourceOptions): void;
94
+ }
95
+
96
+ type RouteBinder = (value: string) => unknown | Promise<unknown>;
97
+ /** Laravel's Illuminate\Routing\Router: registration, groups, patterns, bindings, middleware aliases/groups and dispatch. */
98
+ declare class BaseRouter implements Router {
99
+ #private;
100
+ protected readonly container?: Container | undefined;
101
+ /** `container` is the application; request-time lookups use the current (request) container first. */
102
+ constructor(container?: Container | undefined);
103
+ get<C>(uri: string, action: ControllerAction<C> | RouteClosure | string): RouteDefinition;
104
+ post<C>(uri: string, action: ControllerAction<C> | RouteClosure | string): RouteDefinition;
105
+ put<C>(uri: string, action: ControllerAction<C> | RouteClosure | string): RouteDefinition;
106
+ patch<C>(uri: string, action: ControllerAction<C> | RouteClosure | string): RouteDefinition;
107
+ delete<C>(uri: string, action: ControllerAction<C> | RouteClosure | string): RouteDefinition;
108
+ options<C>(uri: string, action: ControllerAction<C> | RouteClosure | string): RouteDefinition;
109
+ any<C>(uri: string, action: ControllerAction<C> | RouteClosure | string): RouteDefinition;
110
+ match<C>(methods: string[], uri: string, action: ControllerAction<C> | RouteClosure | string): RouteDefinition;
111
+ /** Registers a route with the current group's prefix, name prefix, middleware and controller. GET implies HEAD. */
112
+ addRoute(methods: readonly string[], uri: string, action: RouteHandler, options?: {
113
+ fallback?: boolean;
114
+ }): RouteDefinition;
115
+ /** Route.redirect('/here', '/there'): any verb, 302 by default; '{param}' in the target is filled from the URI. */
116
+ redirect(from: string, to: string, status?: number): RouteDefinition;
117
+ permanentRedirect(from: string, to: string): RouteDefinition;
118
+ /** Route.view('/about', 'pages.about', data): GET/HEAD; route parameters are merged into the view data. */
119
+ view(uri: string, view: string, data?: Record<string, unknown>): RouteDefinition;
120
+ resource(name: string, controller: Class<unknown>, options?: ResourceOptions): void;
121
+ apiResource(name: string, controller: Class<unknown>, options?: ResourceOptions): void;
122
+ /** Matches any GET path no other route matches. Always tried last. */
123
+ fallback(action: RouteAction): RouteDefinition;
124
+ prefix(prefix: string): GroupRegistrar;
125
+ name(prefix: string): GroupRegistrar;
126
+ middleware(...middleware: MiddlewareReference[]): GroupRegistrar;
127
+ controller(controller: Class<unknown>): GroupRegistrar;
128
+ /**
129
+ * Laravel's Route::group(attributes, callback). A synchronous callback's attributes are popped before this
130
+ * returns, so an unawaited group never leaks into later routes; an async callback keeps them until it settles.
131
+ */
132
+ group(attributes: GroupAttributes, routes: () => void | Promise<void>): Promise<void>;
133
+ model(parameter: string, model: Class<unknown>): void;
134
+ bind(parameter: string, resolver: RouteBinder): void;
135
+ pattern(parameter: string, pattern: string): void;
136
+ patterns(patterns: Record<string, string>): void;
137
+ getPatterns(): Readonly<Record<string, string>>;
138
+ /** Bumped by pattern(); routes recompile their matcher when it changes. */
139
+ getPatternVersion(): number;
140
+ getBinder(parameter: string): RouteBinder | undefined;
141
+ getModel(parameter: string): Class<unknown> | undefined;
142
+ aliasMiddleware(name: string, middleware: MiddlewareClass): this;
143
+ /** The middleware aliases (Laravel's Router::getMiddleware()). */
144
+ getMiddleware(): Record<string, MiddlewareClass>;
145
+ middlewareGroup(name: string, middleware: MiddlewareReference[]): this;
146
+ pushMiddlewareToGroup(group: string, middleware: MiddlewareReference): this;
147
+ prependMiddlewareToGroup(group: string, middleware: MiddlewareReference): this;
148
+ hasMiddlewareGroup(name: string): boolean;
149
+ getMiddlewareGroups(): Record<string, MiddlewareReference[]>;
150
+ /** Every route, in registration order. */
151
+ getRoutes(): readonly RouteDefinition[];
152
+ /** Routes in matching order: static segments first, fallbacks last (cached until a route is added). */
153
+ getRoutesByMatchOrder(): readonly RouteDefinition[];
154
+ /** The last route registered with this name wins, as in Laravel. */
155
+ getByName(name: string): RouteDefinition | undefined;
156
+ has(...names: string[]): boolean;
157
+ /** The route matched for the current request (read from the request scope). */
158
+ current(): RouteDefinition | undefined;
159
+ currentRouteName(): string | undefined;
160
+ /** Match, bind and run the route middleware and action (Router.dispatch; called by the Http kernel). */
161
+ dispatch(request: HttpRequest): Promise<Response>;
162
+ }
163
+
164
+ /** PHP's http_build_query: nested objects and arrays become a[b]=1&a[0]=2; null/undefined are skipped. */
165
+ declare function buildQuery(values: Record<string, unknown>): string;
166
+ /** Laravel's UrlGenerator. The root is the current request's origin, else config('app.url'). */
167
+ declare class BaseUrlGenerator implements UrlGenerator {
168
+ #private;
169
+ private readonly router;
170
+ private readonly container?;
171
+ constructor(router: BaseRouter, container?: Container | undefined);
172
+ /** 'http://localhost' (no trailing slash). */
173
+ root(): string;
174
+ to(path: string, query?: Record<string, unknown>, absolute?: boolean): string;
175
+ /**
176
+ * route('posts.show', post) / route('posts.show', [post, comment]) / route('posts.show', { post: 1, page: 2 }).
177
+ * Named values fill their parameters, positional values fill the rest in URI order; extra named values become
178
+ * the query string, extra positional ones are dropped.
179
+ */
180
+ route(name: string, parameters?: unknown, absolute?: boolean): string;
181
+ asset(path: string): string;
182
+ /** The current URL without the query string. */
183
+ current(): string;
184
+ /** The current URL with the query string. */
185
+ full(): string;
186
+ /** The Referer header, then the session's previous URL, then `fallback`, then the root (Laravel's order). */
187
+ previous(fallback?: string): string;
188
+ hasRoute(name: string): boolean;
189
+ }
190
+
191
+ /** A middleware reference after alias and group expansion: 'throttle:60,1' → { cls: Throttle, parameters: ['60', '1'] }. */
192
+ interface ResolvedMiddleware {
193
+ readonly cls: MiddlewareClass;
194
+ readonly parameters: readonly string[];
195
+ }
196
+ /** A string middleware that is neither an alias nor a group. */
197
+ declare class MiddlewareNotFoundError extends Error implements OrielError {
198
+ readonly middleware: string;
199
+ readonly kind: "Server";
200
+ readonly status = 500;
201
+ readonly name = "MiddlewareNotFoundError";
202
+ constructor(middleware: string);
203
+ }
204
+ /**
205
+ * Expands aliases and groups (recursively), drops anything `excluded` resolves to (withoutMiddleware), and
206
+ * removes duplicates (same class and parameters), keeping the first occurrence like Laravel's uniqueMiddleware.
207
+ */
208
+ declare function resolveMiddleware(references: readonly MiddlewareReference[], excluded: readonly MiddlewareReference[], aliases: Readonly<Record<string, MiddlewareClass>>, groups: Readonly<Record<string, readonly MiddlewareReference[]>>): ResolvedMiddleware[];
209
+ /**
210
+ * Renders an error as a Response through the bound ExceptionHandler (reporting it first), like Laravel's
211
+ * Routing\Pipeline::handleException. Without a handler the error is rethrown.
212
+ */
213
+ declare function renderError(container: Container, request: HttpRequest, error: unknown): Promise<Response>;
214
+ /** An extra pipeline stage that runs before `middleware[at]` (route model binding uses it). */
215
+ interface RouteStage {
216
+ readonly at: number;
217
+ run(request: HttpRequest): Promise<void>;
218
+ }
219
+ /**
220
+ * Sends the request through the middleware (built from `container`, the request scope) to `destination`.
221
+ * Every stage converts its own errors into a response, so outer middleware always get a Response back.
222
+ * Built instances are pushed onto `instances` (for terminate()). `stage`, when given, runs at its position.
223
+ */
224
+ declare function runMiddleware(container: Container, request: HttpRequest, middleware: readonly ResolvedMiddleware[], instances: Middleware[], destination: (request: HttpRequest) => Promise<unknown>, stage?: RouteStage): Promise<Response>;
225
+
226
+ /**
227
+ * Laravel's $middlewarePriority around SubstituteBindings: the `web`/`api` group middleware and the `auth`/`guest`
228
+ * aliases run before binding, every other route middleware after it (so `can:` sees the models, and a guest is
229
+ * redirected before any lookup). Returns the middleware in that order (stable within each part) and the index
230
+ * where the binding stage runs.
231
+ */
232
+ declare function orderForBindings(router: BaseRouter, middleware: readonly ResolvedMiddleware[]): {
233
+ middleware: ResolvedMiddleware[];
234
+ at: number;
235
+ };
236
+ /**
237
+ * Laravel's SubstituteBindings, run as a route stage (see orderForBindings), in URI order:
238
+ * 1. Route.bind(name, fn): the callback's result, whatever it is
239
+ * 2. Route.model(name, Model): RouteModelResolver.resolveExplicit(); nothing found → 404
240
+ * 3. implicit: RouteModelResolver.resolve(name, value, field); undefined keeps the string, null → 404
241
+ * Missing optional parameters stay undefined. Without a resolver, implicit binding is skipped.
242
+ */
243
+ declare function substituteBindings(router: BaseRouter, route: RouteDefinition, values: Readonly<Record<string, string | undefined>>, container: Container): Promise<Record<string, unknown>>;
244
+
245
+ /** [Controller, 'missing'] (Laravel's BadMethodCallException). */
246
+ declare class ControllerMethodNotFoundError extends Error implements OrielError {
247
+ readonly kind: "Server";
248
+ readonly status = 500;
249
+ readonly name = "ControllerMethodNotFoundError";
250
+ constructor(controller: string, method: string);
251
+ }
252
+ /**
253
+ * Router::dispatch: match, record the current route in the request scope, then run the route middleware and the
254
+ * action. Matching errors (404/405) are thrown for the kernel's stage to render.
255
+ */
256
+ declare function dispatchRoute(router: BaseRouter, request: HttpRequest, container?: Container): Promise<Response>;
257
+
258
+ /** No route matches the path (Symfony's NotFoundHttpException). */
259
+ declare class NotFoundHttpError extends Error implements OrielError {
260
+ readonly kind: "Http";
261
+ readonly status = 404;
262
+ readonly name = "NotFoundHttpError";
263
+ constructor(path: string);
264
+ }
265
+ /** The path exists, but not for this method. */
266
+ declare class MethodNotAllowedHttpError extends Error implements OrielError {
267
+ readonly kind: "Http";
268
+ readonly status = 405;
269
+ readonly headers: Record<string, string>;
270
+ readonly name = "MethodNotAllowedHttpError";
271
+ constructor(method: string, path: string, allowed: string[]);
272
+ }
273
+ /** route('x') for a name no route has (Symfony's RouteNotFoundException). */
274
+ declare class RouteNotDefinedError extends Error implements OrielError {
275
+ readonly routeName: string;
276
+ readonly kind: "Server";
277
+ readonly status = 500;
278
+ readonly name = "RouteNotDefinedError";
279
+ constructor(routeName: string);
280
+ }
281
+ /** route('posts.show') without a required parameter. */
282
+ declare class UrlGenerationError extends Error implements OrielError {
283
+ readonly kind: "Server";
284
+ readonly status = 500;
285
+ readonly name = "UrlGenerationError";
286
+ constructor(routeName: string, uri: string, missing: string[]);
287
+ }
288
+ /** Thrown by the router when a binding finds no row, so a missing model is always a 404. */
289
+ declare class RouteModelNotFoundError extends Error implements ModelNotFoundError {
290
+ readonly model: string;
291
+ readonly kind: "ModelNotFound";
292
+ readonly status = 404;
293
+ readonly ids: unknown[];
294
+ readonly name = "RouteModelNotFoundError";
295
+ constructor(model: string, value: unknown);
296
+ }
297
+ /** Internal routing failures (a string action with no controller, a view route with no container, etc). */
298
+ declare class RoutingError extends Error implements OrielError {
299
+ readonly kind: "Server";
300
+ readonly status = 500;
301
+ readonly name = "RoutingError";
302
+ }
303
+
304
+ type ResourceMethod = 'index' | 'create' | 'store' | 'show' | 'edit' | 'update' | 'destroy';
305
+ interface ResourceRoute {
306
+ readonly method: ResourceMethod;
307
+ readonly verbs: readonly string[];
308
+ readonly uri: string;
309
+ readonly name: string;
310
+ }
311
+ /**
312
+ * The routes Route.resource()/apiResource() register. 'photos.comments' nests:
313
+ * photos/{photo}/comments/{comment}, named photos.comments.*.
314
+ */
315
+ declare function resourceRoutes(name: string, options?: ResourceOptions, api?: boolean): ResourceRoute[];
316
+
317
+ /** Laravel's Router::toResponse: turns whatever an action returned into a Response. */
318
+ declare function toResponse(request: unknown, value: unknown): Promise<Response>;
319
+
320
+ /**
321
+ * The Route facade: Route.get('/', …), Route.prefix('admin').group(…), Route.resource(…). Typed as the BaseRouter
322
+ * so the extras (permanentRedirect, patterns, has, currentRouteName, …) are available too.
323
+ */
324
+ declare const Route: _orieljs_support.Facade<BaseRouter, object>;
325
+
326
+ /** A route file may export a function instead of (or as well as) calling the Route facade at the top level. */
327
+ type RouteFileCallback = (router: Router) => void | Promise<void>;
328
+ /**
329
+ * Imports a route file inside app.run(), so the Route facade in it resolves this application. Each load adds a
330
+ * fresh `?oriel-routes=<n>` query: ESM caches modules, and a fresh app per test must register its routes again.
331
+ * A default export that is a function is called with the router.
332
+ */
333
+ declare function loadRoutesFrom(app: Application, router: Router, file: string): Promise<void>;
334
+ /** The health route's page (Laravel's `/up`): 200 as long as the application boots and handles requests. */
335
+ declare function healthResponse(): Response;
336
+
337
+ /**
338
+ * Binds the Router and the UrlGenerator, and once the app has booted loads the files given to withRouting(): the health URI,
339
+ * then routes/web.ts in the `web` middleware group, then routes/api.ts under the api prefix in the `api` group
340
+ * (Laravel's ApplicationBuilder::withRouting).
341
+ */
342
+ declare class RoutingServiceProvider extends ServiceProvider {
343
+ register(): void;
344
+ /**
345
+ * The files load in a booted() callback, after every provider's boot() (Laravel's withRouting does the same), so
346
+ * what the app's own providers set up at boot (Route.pattern/bind/model, gates, shared view data) is in place
347
+ * when the route files run.
348
+ */
349
+ boot(): void;
350
+ }
351
+
352
+ export { BaseRouter, BaseUrlGenerator, ControllerMethodNotFoundError, type GroupAttributes, type GroupHost, GroupRegistrar, MethodNotAllowedHttpError, MiddlewareNotFoundError, NotFoundHttpError, type ResolvedMiddleware, type ResourceMethod, type ResourceRoute, Route, type RouteAttributes, type RouteBinder, RouteDefinition, type RouteFileCallback, type RouteHandler, RouteModelNotFoundError, RouteNotDefinedError, type RouteStage, RoutingError, RoutingServiceProvider, type UriParameter, UrlGenerationError, buildQuery, compareRoutes, dispatchRoute, healthResponse, loadRoutesFrom, mergeGroup, normalizePath, normalizeUri, orderForBindings, parseParameters, renderError, resolveMiddleware, resourceRoutes, runMiddleware, substituteBindings, toResponse };