@ereo/router 0.1.6

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,67 @@
1
+ /**
2
+ * @ereo/router - URL Pattern Matching
3
+ *
4
+ * Matches URLs against route patterns and extracts parameters.
5
+ * Supports dynamic segments, catch-all, and optional segments.
6
+ */
7
+ import type { Route, RouteMatch } from '@ereo/core';
8
+ import type { RouteSegment, MatchResult } from './types';
9
+ /**
10
+ * Parse a path pattern into segments.
11
+ */
12
+ export declare function parsePathSegments(path: string): RouteSegment[];
13
+ /**
14
+ * Calculate route score for sorting.
15
+ * Higher scores are matched first.
16
+ */
17
+ export declare function calculateRouteScore(segments: RouteSegment[]): number;
18
+ /**
19
+ * Convert route pattern to regex.
20
+ */
21
+ export declare function patternToRegex(segments: RouteSegment[]): RegExp;
22
+ /**
23
+ * Match a URL path against a single route.
24
+ */
25
+ export declare function matchRoute(pathname: string, route: Route, segments: RouteSegment[]): RouteMatch | null;
26
+ /**
27
+ * Route matcher class.
28
+ * Pre-compiles routes for efficient matching.
29
+ */
30
+ export declare class RouteMatcher {
31
+ private routes;
32
+ constructor(routes: Route[]);
33
+ /**
34
+ * Compile and sort routes.
35
+ */
36
+ private compileRoutes;
37
+ /**
38
+ * Flatten nested routes.
39
+ */
40
+ private flattenRoutes;
41
+ /**
42
+ * Match a URL pathname against compiled routes.
43
+ */
44
+ match(pathname: string): RouteMatch | null;
45
+ /**
46
+ * Get all routes.
47
+ */
48
+ getRoutes(): Route[];
49
+ /**
50
+ * Add a route dynamically.
51
+ */
52
+ addRoute(route: Route): void;
53
+ /**
54
+ * Remove a route by ID.
55
+ */
56
+ removeRoute(routeId: string): boolean;
57
+ }
58
+ /**
59
+ * Create a route matcher from routes.
60
+ */
61
+ export declare function createMatcher(routes: Route[]): RouteMatcher;
62
+ /**
63
+ * Match with layout resolution.
64
+ * Returns all matching layouts from root to the matched route.
65
+ */
66
+ export declare function matchWithLayouts(pathname: string, routes: Route[]): MatchResult | null;
67
+ //# sourceMappingURL=matcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matcher.d.ts","sourceRoot":"","sources":["../src/matcher.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAe,UAAU,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAQzD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,EAAE,CA8C9D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,MAAM,CAyBpE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,MAAM,CA4B/D;AASD;;GAEG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,YAAY,EAAE,GACvB,UAAU,GAAG,IAAI,CA8BnB;AAED;;;GAGG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAKN;gBAEI,MAAM,EAAE,KAAK,EAAE;IAI3B;;OAEG;IACH,OAAO,CAAC,aAAa;IAgBrB;;OAEG;IACH,OAAO,CAAC,aAAa;IAiBrB;;OAEG;IACH,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAkC1C;;OAEG;IACH,SAAS,IAAI,KAAK,EAAE;IAIpB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAkB5B;;OAEG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;CAQtC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,YAAY,CAE3D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,KAAK,EAAE,GACd,WAAW,GAAG,IAAI,CAyCpB"}
@@ -0,0 +1,249 @@
1
+ /**
2
+ * @ereo/router - Middleware Chain Executor
3
+ *
4
+ * Executes route-level middleware chains with support for named middleware,
5
+ * inline middleware functions, and type-safe context passing.
6
+ *
7
+ * ## Type Compatibility
8
+ *
9
+ * This module provides `TypedMiddlewareHandler<TProvides, TRequires>` which extends
10
+ * the base `MiddlewareHandler` from `@ereo/core`. The typed version adds generic
11
+ * parameters for compile-time context type checking while remaining fully compatible
12
+ * with the core middleware system.
13
+ *
14
+ * ```typescript
15
+ * // Base type from @ereo/core:
16
+ * type MiddlewareHandler = (
17
+ * request: Request,
18
+ * context: AppContext,
19
+ * next: NextFunction
20
+ * ) => Response | Promise<Response>
21
+ *
22
+ * // Typed version (compatible with base):
23
+ * type TypedMiddlewareHandler<TProvides, TRequires> = (
24
+ * request: Request,
25
+ * context: AppContext & TRequires, // Extends AppContext
26
+ * next: NextFunction
27
+ * ) => Response | Promise<Response>
28
+ * ```
29
+ *
30
+ * Both types can be used interchangeably with `@ereo/server`'s middleware chain.
31
+ */
32
+ import type { MiddlewareReference, MiddlewareHandler, AppContext, NextFunction, RouteConfig } from '@ereo/core';
33
+ /**
34
+ * Typed middleware context values.
35
+ * Middleware can declare what values it adds to the context.
36
+ */
37
+ export interface TypedMiddlewareContext {
38
+ [key: string]: unknown;
39
+ }
40
+ /**
41
+ * Typed middleware handler that declares its context additions.
42
+ *
43
+ * This type is fully compatible with `MiddlewareHandler` from `@ereo/core`.
44
+ * The generic parameters allow TypeScript to track what context values
45
+ * are provided and required by each middleware.
46
+ *
47
+ * @template TProvides - Context keys/types this middleware adds
48
+ * @template TRequires - Context keys/types this middleware expects to exist
49
+ *
50
+ * @example
51
+ * // A TypedMiddlewareHandler can be used anywhere a MiddlewareHandler is expected:
52
+ * const typed: TypedMiddlewareHandler<{ user: User }> = async (req, ctx, next) => {
53
+ * ctx.set('user', await getUser(req));
54
+ * return next();
55
+ * };
56
+ *
57
+ * // This works because TypedMiddlewareHandler extends MiddlewareHandler:
58
+ * const handler: MiddlewareHandler = typed; // OK!
59
+ */
60
+ export type TypedMiddlewareHandler<TProvides extends TypedMiddlewareContext = {}, TRequires extends TypedMiddlewareContext = {}> = (request: Request, context: AppContext & TRequires, next: NextFunction) => Response | Promise<Response>;
61
+ /**
62
+ * Typed middleware definition with metadata.
63
+ */
64
+ export interface TypedMiddleware<TProvides extends TypedMiddlewareContext = {}, TRequires extends TypedMiddlewareContext = {}> {
65
+ name: string;
66
+ handler: TypedMiddlewareHandler<TProvides, TRequires>;
67
+ /** Keys this middleware provides to the context */
68
+ provides?: (keyof TProvides)[];
69
+ /** Keys this middleware requires from the context */
70
+ requires?: (keyof TRequires)[];
71
+ }
72
+ /**
73
+ * Create a typed middleware with context type safety.
74
+ *
75
+ * @example
76
+ * const authMiddleware = createMiddleware<{ user: User }>({
77
+ * name: 'auth',
78
+ * provides: ['user'],
79
+ * handler: async (req, ctx, next) => {
80
+ * const session = await getSession(req);
81
+ * if (!session) {
82
+ * return new Response('Unauthorized', { status: 401 });
83
+ * }
84
+ * ctx.set('user', session.user); // TypeScript knows 'user' is valid
85
+ * return next();
86
+ * },
87
+ * });
88
+ *
89
+ * // In your loader:
90
+ * export const loader = async ({ context }) => {
91
+ * const user = context.get<User>('user'); // Set by auth middleware
92
+ * };
93
+ */
94
+ export declare function createMiddleware<TProvides extends TypedMiddlewareContext = {}, TRequires extends TypedMiddlewareContext = {}>(config: TypedMiddleware<TProvides, TRequires>): TypedMiddleware<TProvides, TRequires> & {
95
+ register: () => void;
96
+ };
97
+ /**
98
+ * Chain multiple typed middleware together with type inference.
99
+ *
100
+ * @example
101
+ * const protectedRoute = chainMiddleware(
102
+ * authMiddleware, // provides: { user: User }
103
+ * adminMiddleware, // requires: { user: User }, provides: { isAdmin: boolean }
104
+ * rateLimitMiddleware
105
+ * );
106
+ */
107
+ export declare function chainMiddleware<M1 extends TypedMiddleware<any, any>, M2 extends TypedMiddleware<any, any>>(m1: M1, m2: M2): TypedMiddleware<M1 extends TypedMiddleware<infer P1, any> ? (M2 extends TypedMiddleware<infer P2, any> ? P1 & P2 : P1) : {}, M1 extends TypedMiddleware<any, infer R1> ? R1 : {}>;
108
+ export declare function chainMiddleware<M1 extends TypedMiddleware<any, any>, M2 extends TypedMiddleware<any, any>, M3 extends TypedMiddleware<any, any>>(m1: M1, m2: M2, m3: M3): TypedMiddleware<any, any>;
109
+ /**
110
+ * Register a named middleware in the global registry.
111
+ *
112
+ * @example
113
+ * registerMiddleware('auth', async (req, ctx, next) => {
114
+ * if (!ctx.get('user')) {
115
+ * return new Response('Unauthorized', { status: 401 });
116
+ * }
117
+ * return next();
118
+ * });
119
+ */
120
+ export declare function registerMiddleware(name: string, handler: MiddlewareHandler): void;
121
+ /**
122
+ * Register a typed middleware with metadata.
123
+ */
124
+ export declare function registerTypedMiddleware<TProvides extends TypedMiddlewareContext, TRequires extends TypedMiddlewareContext>(middleware: TypedMiddleware<TProvides, TRequires>): void;
125
+ /**
126
+ * Get typed middleware metadata.
127
+ */
128
+ export declare function getTypedMiddleware(name: string): TypedMiddleware<any, any> | undefined;
129
+ /**
130
+ * Validate middleware chain for type safety.
131
+ * Ensures that all required context values are provided by preceding middleware.
132
+ */
133
+ export declare function validateMiddlewareChain(names: string[]): {
134
+ valid: boolean;
135
+ errors: string[];
136
+ };
137
+ /**
138
+ * Get a named middleware from the registry.
139
+ */
140
+ export declare function getMiddleware(name: string): MiddlewareHandler | undefined;
141
+ /**
142
+ * Check if a named middleware exists in the registry.
143
+ */
144
+ export declare function hasMiddleware(name: string): boolean;
145
+ /**
146
+ * Remove a named middleware from the registry.
147
+ */
148
+ export declare function unregisterMiddleware(name: string): boolean;
149
+ /**
150
+ * Clear all named middleware from the registry.
151
+ */
152
+ export declare function clearMiddlewareRegistry(): void;
153
+ /**
154
+ * Resolve a middleware reference to a handler function.
155
+ * String references are looked up in the named middleware registry.
156
+ */
157
+ export declare function resolveMiddleware(reference: MiddlewareReference): MiddlewareHandler | undefined;
158
+ /**
159
+ * Options for executing a middleware chain.
160
+ */
161
+ export interface MiddlewareChainOptions {
162
+ /** Request object */
163
+ request: Request;
164
+ /** Application context */
165
+ context: AppContext;
166
+ /** Final handler to call when chain completes */
167
+ finalHandler: NextFunction;
168
+ /** Error handler for middleware errors */
169
+ onError?: (error: Error) => Response | Promise<Response>;
170
+ }
171
+ /**
172
+ * Execute a middleware chain.
173
+ *
174
+ * @param middleware Array of middleware references
175
+ * @param options Chain execution options
176
+ * @returns Response from the chain
177
+ *
178
+ * @example
179
+ * const response = await executeMiddlewareChain(
180
+ * ['csrf', 'auth', customMiddleware],
181
+ * {
182
+ * request,
183
+ * context,
184
+ * finalHandler: async () => renderRoute(),
185
+ * }
186
+ * );
187
+ */
188
+ export declare function executeMiddlewareChain(middleware: MiddlewareReference[], options: MiddlewareChainOptions): Promise<Response>;
189
+ /**
190
+ * Create a middleware chain executor bound to a route config.
191
+ *
192
+ * @param config Route configuration containing middleware array
193
+ * @returns Function to execute the middleware chain
194
+ *
195
+ * @example
196
+ * const executor = createMiddlewareExecutor(routeConfig);
197
+ * const response = await executor({ request, context, finalHandler });
198
+ */
199
+ export declare function createMiddlewareExecutor(config: RouteConfig): (options: Omit<MiddlewareChainOptions, "finalHandler"> & {
200
+ finalHandler: NextFunction;
201
+ }) => Promise<Response>;
202
+ /**
203
+ * Compose multiple middleware handlers into a single handler.
204
+ */
205
+ export declare function composeMiddleware(...handlers: MiddlewareHandler[]): MiddlewareHandler;
206
+ /**
207
+ * Create a conditional middleware that only runs when the predicate matches.
208
+ */
209
+ export declare function when(predicate: (request: Request, context: AppContext) => boolean | Promise<boolean>, middleware: MiddlewareHandler): MiddlewareHandler;
210
+ /**
211
+ * Create a middleware that only runs for specific HTTP methods.
212
+ */
213
+ export declare function method(methods: string | string[], middleware: MiddlewareHandler): MiddlewareHandler;
214
+ /**
215
+ * Convert a glob pattern to a RegExp.
216
+ * Supports * (match anything except /) and ** (match anything including /).
217
+ */
218
+ export declare function globToRegex(glob: string): RegExp;
219
+ /**
220
+ * Create a middleware that only runs for specific path patterns.
221
+ */
222
+ export declare function path(patterns: string | string[] | RegExp | RegExp[], middleware: MiddlewareHandler): MiddlewareHandler;
223
+ /**
224
+ * Create a logging middleware.
225
+ */
226
+ export declare function createLoggerMiddleware(options?: {
227
+ includeBody?: boolean;
228
+ includeHeaders?: string[];
229
+ }): MiddlewareHandler;
230
+ /**
231
+ * Create a CORS middleware.
232
+ */
233
+ export declare function createCorsMiddleware(options?: {
234
+ origin?: string | string[] | ((origin: string) => boolean);
235
+ methods?: string[];
236
+ headers?: string[];
237
+ credentials?: boolean;
238
+ maxAge?: number;
239
+ }): MiddlewareHandler;
240
+ /**
241
+ * Create a rate limiting middleware.
242
+ */
243
+ export declare function createRateLimitMiddleware(options?: {
244
+ windowMs?: number;
245
+ maxRequests?: number;
246
+ keyGenerator?: (request: Request) => string;
247
+ skipSuccessfulRequests?: boolean;
248
+ }): MiddlewareHandler;
249
+ //# sourceMappingURL=middleware-chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware-chain.d.ts","sourceRoot":"","sources":["../src/middleware-chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,WAAW,EACZ,MAAM,YAAY,CAAC;AAMpB;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,sBAAsB,CAChC,SAAS,SAAS,sBAAsB,GAAG,EAAE,EAC7C,SAAS,SAAS,sBAAsB,GAAG,EAAE,IAC3C,CACF,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,UAAU,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,GAC5B,iBAAiB,CAuBnB;AAMD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,GACjE,iBAAiB,CAsCnB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,GAAE;IAC5C,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;IAC3D,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;CACZ,GAAG,iBAAiB,CA2DzB;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,GAAE;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC;IAC5C,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAC7B,GAAG,iBAAiB,CAqDzB"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @ereo/router - Route Configuration Parser
3
+ *
4
+ * Parses and validates route-level configuration exports.
5
+ */
6
+ import type { RouteConfig, RenderConfig, IslandsConfig, RouteCacheConfig, ProgressiveConfig, AuthConfig, DevConfig, RouteVariant, MiddlewareReference } from '@ereo/core';
7
+ /** Parse and validate middleware chain */
8
+ export declare function parseMiddleware(middleware: unknown): MiddlewareReference[] | undefined;
9
+ /** Parse render configuration */
10
+ export declare function parseRenderConfig(config: unknown): RenderConfig;
11
+ /** Parse islands configuration */
12
+ export declare function parseIslandsConfig(config: unknown): IslandsConfig;
13
+ /** Parse cache configuration */
14
+ export declare function parseCacheConfig(config: unknown): RouteCacheConfig | undefined;
15
+ /** Parse progressive enhancement config */
16
+ export declare function parseProgressiveConfig(config: unknown): ProgressiveConfig;
17
+ /** Parse auth configuration */
18
+ export declare function parseAuthConfig(config: unknown): AuthConfig | undefined;
19
+ /** Parse dev configuration */
20
+ export declare function parseDevConfig(config: unknown): DevConfig | undefined;
21
+ /** Parse route variants */
22
+ export declare function parseVariants(config: unknown): RouteVariant[] | undefined;
23
+ /** Parse complete route configuration */
24
+ export declare function parseRouteConfig(config: unknown): RouteConfig;
25
+ /** Merge parent and child route configs */
26
+ export declare function mergeRouteConfigs(parent: RouteConfig | undefined, child: RouteConfig | undefined): RouteConfig;
27
+ //# sourceMappingURL=route-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-config.d.ts","sourceRoot":"","sources":["../src/route-config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,SAAS,EACT,YAAY,EACZ,mBAAmB,EAIpB,MAAM,YAAY,CAAC;AAoBpB,0CAA0C;AAC1C,wBAAgB,eAAe,CAC7B,UAAU,EAAE,OAAO,GAClB,mBAAmB,EAAE,GAAG,SAAS,CAWnC;AAED,iCAAiC;AACjC,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CAkB/D;AAyDD,kCAAkC;AAClC,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,aAAa,CAkBjE;AAED,gCAAgC;AAChC,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,GAAG,SAAS,CAS9E;AAyCD,2CAA2C;AAC3C,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,iBAAiB,CAUzE;AAqCD,+BAA+B;AAC/B,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAiBvE;AAED,8BAA8B;AAC9B,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CASrE;AAYD,2BAA2B;AAC3B,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,EAAE,GAAG,SAAS,CAsBzE;AAED,yCAAyC;AACzC,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,WAAW,CAiB7D;AAED,2CAA2C;AAC3C,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,KAAK,EAAE,WAAW,GAAG,SAAS,GAC7B,WAAW,CAeb"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * @ereo/router - Route Tree
3
+ *
4
+ * Builds a hierarchical route tree from flat routes.
5
+ * Handles layout nesting and route groups.
6
+ */
7
+ import type { Route } from '@ereo/core';
8
+ import type { RouteNode } from './types';
9
+ /**
10
+ * Route tree builder.
11
+ */
12
+ export declare class RouteTree {
13
+ private root;
14
+ constructor();
15
+ /**
16
+ * Create a route node.
17
+ */
18
+ private createNode;
19
+ /**
20
+ * Add a route to the tree.
21
+ */
22
+ addRoute(id: string, path: string, file: string, options?: {
23
+ index?: boolean;
24
+ layout?: boolean;
25
+ }): RouteNode;
26
+ /**
27
+ * Find the parent node for a path.
28
+ */
29
+ private findParent;
30
+ /**
31
+ * Get the root node.
32
+ */
33
+ getRoot(): RouteNode;
34
+ /**
35
+ * Convert tree to flat Route array.
36
+ */
37
+ toRoutes(): Route[];
38
+ /**
39
+ * Convert a node to a Route.
40
+ */
41
+ private nodeToRoute;
42
+ /**
43
+ * Find a node by path.
44
+ */
45
+ findByPath(path: string): RouteNode | null;
46
+ /**
47
+ * Find a node by ID.
48
+ */
49
+ findById(id: string): RouteNode | null;
50
+ /**
51
+ * Remove a route by ID.
52
+ */
53
+ removeById(id: string): boolean;
54
+ /**
55
+ * Get all routes as a flat array.
56
+ */
57
+ flatten(): RouteNode[];
58
+ /**
59
+ * Get all layout routes.
60
+ */
61
+ getLayouts(): RouteNode[];
62
+ /**
63
+ * Get the layout chain for a route.
64
+ */
65
+ getLayoutChain(routeId: string): RouteNode[];
66
+ }
67
+ /**
68
+ * Convert a file path to a URL path.
69
+ */
70
+ export declare function filePathToUrlPath(filePath: string, routesDir: string): {
71
+ path: string;
72
+ index: boolean;
73
+ layout: boolean;
74
+ };
75
+ /**
76
+ * Build a route tree from file paths.
77
+ */
78
+ export declare function buildRouteTree(files: Array<{
79
+ relativePath: string;
80
+ absolutePath: string;
81
+ }>, routesDir: string): RouteTree;
82
+ /**
83
+ * Create an empty route tree.
84
+ */
85
+ export declare function createRouteTree(): RouteTree;
86
+ //# sourceMappingURL=route-tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-tree.d.ts","sourceRoot":"","sources":["../src/route-tree.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAgB,MAAM,SAAS,CAAC;AAIvD;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,IAAI,CAAY;;IAMxB;;OAEG;IACH,OAAO,CAAC,UAAU;IAoBlB;;OAEG;IACH,QAAQ,CACN,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAO,GAClD,SAAS;IAeZ;;OAEG;IACH,OAAO,CAAC,UAAU;IA8BlB;;OAEG;IACH,OAAO,IAAI,SAAS;IAIpB;;OAEG;IACH,QAAQ,IAAI,KAAK,EAAE;IAInB;;OAEG;IACH,OAAO,CAAC,WAAW;IAoBnB;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAc1C;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IActC;;OAEG;IACH,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAe/B;;OAEG;IACH,OAAO,IAAI,SAAS,EAAE;IActB;;OAEG;IACH,UAAU,IAAI,SAAS,EAAE;IAIzB;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE;CAgB7C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAsCnD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,KAAK,CAAC;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC,EAC5D,SAAS,EAAE,MAAM,GAChB,SAAS,CAoBX;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,SAAS,CAE3C"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * @ereo/router - Route Type Definitions
3
+ *
4
+ * Types for file-based routing system.
5
+ */
6
+ import type { Route, RouteParams, RouteModule } from '@ereo/core';
7
+ /**
8
+ * File system route (before processing).
9
+ */
10
+ export interface FileRoute {
11
+ /** Relative file path from routes directory */
12
+ relativePath: string;
13
+ /** Absolute file path */
14
+ absolutePath: string;
15
+ /** File extension */
16
+ extension: string;
17
+ }
18
+ /**
19
+ * Parsed route segment.
20
+ */
21
+ export interface RouteSegment {
22
+ /** The raw segment value */
23
+ raw: string;
24
+ /** Type of segment */
25
+ type: 'static' | 'dynamic' | 'catchAll' | 'optional';
26
+ /** Parameter name (for dynamic/catchAll segments) */
27
+ paramName?: string;
28
+ }
29
+ /**
30
+ * Route node in the tree.
31
+ */
32
+ export interface RouteNode {
33
+ /** Route ID (unique identifier) */
34
+ id: string;
35
+ /** URL path pattern */
36
+ path: string;
37
+ /** Parsed path segments */
38
+ segments: RouteSegment[];
39
+ /** File path */
40
+ file: string;
41
+ /** Is this an index route? */
42
+ index: boolean;
43
+ /** Is this a layout? */
44
+ layout: boolean;
45
+ /** Child routes */
46
+ children: RouteNode[];
47
+ /** Parent route (for layout resolution) */
48
+ parent?: RouteNode;
49
+ /** Loaded module */
50
+ module?: RouteModule;
51
+ /** Score for sorting (more specific routes first) */
52
+ score: number;
53
+ }
54
+ /**
55
+ * Router options.
56
+ */
57
+ export interface RouterOptions {
58
+ /** Routes directory (default: 'app/routes') */
59
+ routesDir?: string;
60
+ /** Base path (default: '') */
61
+ basePath?: string;
62
+ /** File extensions to consider routes (default: ['.tsx', '.ts', '.jsx', '.js']) */
63
+ extensions?: string[];
64
+ /** Whether to watch for changes (dev mode) */
65
+ watch?: boolean;
66
+ }
67
+ /**
68
+ * Match result from URL pattern matching.
69
+ */
70
+ export interface MatchResult {
71
+ /** The matched route */
72
+ route: Route;
73
+ /** Extracted parameters */
74
+ params: RouteParams;
75
+ /** Matched pathname */
76
+ pathname: string;
77
+ /** Layouts to render (from root to leaf) */
78
+ layouts: Route[];
79
+ }
80
+ /**
81
+ * Route registry for type-safe routing.
82
+ */
83
+ export interface RouteRegistry {
84
+ /** All registered routes */
85
+ routes: Map<string, Route>;
86
+ /** Get route by path */
87
+ get(path: string): Route | undefined;
88
+ /** Check if route exists */
89
+ has(path: string): boolean;
90
+ }
91
+ /**
92
+ * File router events.
93
+ */
94
+ export interface RouterEvents {
95
+ /** Route added */
96
+ add: (route: Route) => void;
97
+ /** Route removed */
98
+ remove: (routeId: string) => void;
99
+ /** Route changed */
100
+ change: (route: Route) => void;
101
+ /** All routes reloaded */
102
+ reload: (routes: Route[]) => void;
103
+ }
104
+ /**
105
+ * Route sorting priority.
106
+ * Higher values = higher priority (matched first).
107
+ */
108
+ export declare const ROUTE_SCORE: {
109
+ readonly STATIC: 100;
110
+ readonly INDEX: 90;
111
+ readonly DYNAMIC: 50;
112
+ readonly OPTIONAL: 30;
113
+ readonly CATCH_ALL: 10;
114
+ };
115
+ /**
116
+ * Special file names.
117
+ */
118
+ export declare const SPECIAL_FILES: {
119
+ readonly LAYOUT: "_layout";
120
+ readonly ERROR: "_error";
121
+ readonly LOADING: "_loading";
122
+ readonly NOT_FOUND: "_404";
123
+ };
124
+ /**
125
+ * Route group pattern (parentheses).
126
+ */
127
+ export declare const ROUTE_GROUP_PATTERN: RegExp;
128
+ /**
129
+ * Dynamic segment pattern (brackets).
130
+ */
131
+ export declare const DYNAMIC_SEGMENT_PATTERN: RegExp;
132
+ /**
133
+ * Catch-all segment pattern (spread).
134
+ */
135
+ export declare const CATCH_ALL_PATTERN: RegExp;
136
+ /**
137
+ * Optional segment pattern (double brackets).
138
+ */
139
+ export declare const OPTIONAL_PATTERN: RegExp;
140
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAElE;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,+CAA+C;IAC/C,YAAY,EAAE,MAAM,CAAC;IACrB,yBAAyB;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,qBAAqB;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,4BAA4B;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,sBAAsB;IACtB,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;IACrD,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,mCAAmC;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,uBAAuB;IACv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