@real-router/core 0.77.4 → 0.79.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cjs/{Router-Bm2qafJA.d.ts → Router-BG5yNYUG.d.ts} +4 -10
- package/dist/cjs/Router-BG5yNYUG.d.ts.map +1 -0
- package/dist/cjs/Router-BRuC-daj.js +2 -0
- package/dist/cjs/Router-BRuC-daj.js.map +1 -0
- package/dist/cjs/RouterValidator-CZ8kPkrI.d.ts +107 -0
- package/dist/cjs/RouterValidator-CZ8kPkrI.d.ts.map +1 -0
- package/dist/cjs/api.d.ts +20 -4
- package/dist/cjs/api.d.ts.map +1 -1
- package/dist/cjs/api.js +1 -1
- package/dist/cjs/api.js.map +1 -1
- package/dist/cjs/buildParamMeta-DniluAIV.js +2 -0
- package/dist/cjs/buildParamMeta-DniluAIV.js.map +1 -0
- package/dist/cjs/cloneRouter-3AOUeQ8M.js +2 -0
- package/dist/cjs/cloneRouter-3AOUeQ8M.js.map +1 -0
- package/dist/cjs/index-CAnGQpnz.d.ts +974 -0
- package/dist/cjs/index-CAnGQpnz.d.ts.map +1 -0
- package/dist/{esm/index-Cwd11Hun.d.mts → cjs/index-DDrryY2U.d.ts} +3 -3
- package/dist/cjs/{index-A1sdfTRT.d.ts.map → index-DDrryY2U.d.ts.map} +1 -1
- package/dist/cjs/index.d.ts +192 -7
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types-DaXCTxi1.d.ts +138 -0
- package/dist/cjs/types-DaXCTxi1.d.ts.map +1 -0
- package/dist/cjs/types.d.ts +2 -0
- package/dist/cjs/types.js +0 -0
- package/dist/cjs/utils.d.ts +1 -1
- package/dist/cjs/utils.js +1 -1
- package/dist/cjs/utils.js.map +1 -1
- package/dist/cjs/validation.d.ts +163 -8
- package/dist/cjs/validation.d.ts.map +1 -1
- package/dist/cjs/validation.js +2 -1
- package/dist/cjs/validation.js.map +1 -0
- package/dist/esm/{Router-Bm2qafJA.d.mts → Router-Cy75qbgU.d.mts} +4 -10
- package/dist/{cjs/Router-Bm2qafJA.d.ts.map → esm/Router-Cy75qbgU.d.mts.map} +1 -1
- package/dist/esm/Router-DikzugaD.mjs +2 -0
- package/dist/esm/Router-DikzugaD.mjs.map +1 -0
- package/dist/esm/RouterValidator-CZ8kPkrI.d.mts +107 -0
- package/dist/esm/RouterValidator-CZ8kPkrI.d.mts.map +1 -0
- package/dist/esm/api.d.mts +20 -4
- package/dist/esm/api.d.mts.map +1 -1
- package/dist/esm/api.mjs +1 -1
- package/dist/esm/api.mjs.map +1 -1
- package/dist/esm/buildParamMeta-bOLhLF9h.mjs +2 -0
- package/dist/esm/buildParamMeta-bOLhLF9h.mjs.map +1 -0
- package/dist/esm/cloneRouter-CAh5vA3l.mjs +2 -0
- package/dist/esm/cloneRouter-CAh5vA3l.mjs.map +1 -0
- package/dist/esm/index-CAnGQpnz.d.mts +974 -0
- package/dist/esm/index-CAnGQpnz.d.mts.map +1 -0
- package/dist/{cjs/index-A1sdfTRT.d.ts → esm/index-DnSU6huX.d.mts} +3 -3
- package/dist/esm/{index-Cwd11Hun.d.mts.map → index-DnSU6huX.d.mts.map} +1 -1
- package/dist/esm/index.d.mts +192 -7
- package/dist/esm/index.d.mts.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/types-DaXCTxi1.d.mts +138 -0
- package/dist/esm/types-DaXCTxi1.d.mts.map +1 -0
- package/dist/esm/types.d.mts +2 -0
- package/dist/esm/types.mjs +0 -0
- package/dist/esm/utils.d.mts +1 -1
- package/dist/esm/utils.mjs +1 -1
- package/dist/esm/utils.mjs.map +1 -1
- package/dist/esm/validation.d.mts +162 -9
- package/dist/esm/validation.d.mts.map +1 -1
- package/dist/esm/validation.mjs +2 -1
- package/dist/esm/validation.mjs.map +1 -0
- package/package.json +15 -12
- package/dist/cjs/Router-27ftBmfo.js +0 -2
- package/dist/cjs/Router-27ftBmfo.js.map +0 -1
- package/dist/cjs/RouterError-OKaEXSBZ.d.ts +0 -292
- package/dist/cjs/RouterError-OKaEXSBZ.d.ts.map +0 -1
- package/dist/cjs/cloneRouter-B1tPtpNE.js +0 -2
- package/dist/cjs/cloneRouter-B1tPtpNE.js.map +0 -1
- package/dist/cjs/esm-egdCFOaS.js +0 -2
- package/dist/cjs/esm-egdCFOaS.js.map +0 -1
- package/dist/cjs/index-0GKsQ2r9.d.ts +0 -336
- package/dist/cjs/index-0GKsQ2r9.d.ts.map +0 -1
- package/dist/esm/Router-Bm2qafJA.d.mts.map +0 -1
- package/dist/esm/Router-CTGJBKd7.mjs +0 -2
- package/dist/esm/Router-CTGJBKd7.mjs.map +0 -1
- package/dist/esm/RouterError-OKaEXSBZ.d.mts +0 -292
- package/dist/esm/RouterError-OKaEXSBZ.d.mts.map +0 -1
- package/dist/esm/cloneRouter-C4v9Xl2F.mjs +0 -2
- package/dist/esm/cloneRouter-C4v9Xl2F.mjs.map +0 -1
- package/dist/esm/esm-Cnywzxys.mjs +0 -2
- package/dist/esm/esm-Cnywzxys.mjs.map +0 -1
- package/dist/esm/index-0GKsQ2r9.d.mts +0 -336
- package/dist/esm/index-0GKsQ2r9.d.mts.map +0 -1
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
//#region src/types/RouterValidator.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* RouterValidator interface - defines all validation methods used by the router.
|
|
4
|
-
*
|
|
5
|
-
* This interface is implemented by the validation plugin and injected into RouterInternals.
|
|
6
|
-
* When ctx.validator is null (default), validation is skipped.
|
|
7
|
-
* When ctx.validator is set (by validation plugin), all methods are called.
|
|
8
|
-
*
|
|
9
|
-
* All parameters use `unknown` type to avoid coupling to internal type names.
|
|
10
|
-
*/
|
|
11
|
-
interface RouterValidator {
|
|
12
|
-
/**
|
|
13
|
-
* Route validation methods
|
|
14
|
-
*/
|
|
15
|
-
routes: {
|
|
16
|
-
validateBuildPathArgs: (route: unknown) => void;
|
|
17
|
-
validateMatchPathArgs: (path: unknown) => void;
|
|
18
|
-
validateIsActiveRouteArgs: (name: unknown, params: unknown, strict: unknown, ignoreQP: unknown) => void;
|
|
19
|
-
validateShouldUpdateNodeArgs: (name: unknown) => void;
|
|
20
|
-
validateStateBuilderArgs: (name: unknown, params: unknown, caller: string) => void;
|
|
21
|
-
validateAddRouteArgs: (routes: unknown) => void;
|
|
22
|
-
validateRoutes: (routes: unknown[], tree: unknown, parentName?: string) => void;
|
|
23
|
-
validateRemoveRouteArgs: (name: unknown) => void;
|
|
24
|
-
validateUpdateRouteBasicArgs: (name: unknown, updates: unknown) => void;
|
|
25
|
-
validateUpdateRoutePropertyTypes: (name: string, updates: unknown) => void;
|
|
26
|
-
validateUpdateRoute: (name: string, updates: unknown, tree: unknown) => void;
|
|
27
|
-
validateParentOption: (parent: unknown, tree: unknown) => void;
|
|
28
|
-
validateRouteName: (name: unknown, caller: string) => void;
|
|
29
|
-
throwIfInternalRoute: (name: unknown, caller: string) => void;
|
|
30
|
-
throwIfInternalRouteInArray: (routes: unknown[], caller: string) => void;
|
|
31
|
-
validateSetRootPathArgs: (rootPath: unknown) => void;
|
|
32
|
-
guardRouteCallbacks: (route: unknown) => void;
|
|
33
|
-
guardNoAsyncCallbacks: (route: unknown) => void;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Options validation methods
|
|
37
|
-
*/
|
|
38
|
-
options: {
|
|
39
|
-
validateOptions: (options: unknown, methodName: string) => void;
|
|
40
|
-
validateResolvedDefaultRoute: (routeName: unknown, store: unknown) => void;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Dependencies validation methods
|
|
44
|
-
*/
|
|
45
|
-
dependencies: {
|
|
46
|
-
validateDependencyName: (name: unknown, caller: string) => void;
|
|
47
|
-
validateSetDependencyArgs: (name: unknown, value: unknown, caller: string) => void;
|
|
48
|
-
validateDependenciesObject: (deps: unknown, caller: string) => void;
|
|
49
|
-
validateDependencyExists: (name: string, store: unknown) => void;
|
|
50
|
-
validateDependencyCount: (store: unknown, methodName: string) => void;
|
|
51
|
-
validateCloneArgs: (dependencies: unknown) => void;
|
|
52
|
-
warnOverwrite: (name: string, methodName: string) => void;
|
|
53
|
-
warnBatchOverwrite: (keys: string[], methodName: string) => void;
|
|
54
|
-
warnRemoveNonExistent: (name: unknown) => void;
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Plugin validation methods
|
|
58
|
-
*/
|
|
59
|
-
plugins: {
|
|
60
|
-
validatePluginLimit: (count: number, limits: unknown) => void;
|
|
61
|
-
validateNoDuplicatePlugins: (factory: unknown, factories: unknown[]) => void;
|
|
62
|
-
validatePluginKeys: (plugin: unknown) => void;
|
|
63
|
-
validateCountThresholds: (count: number) => void;
|
|
64
|
-
warnBatchDuplicates: (plugins: unknown[]) => void;
|
|
65
|
-
warnPluginMethodType: (methodName: string) => void;
|
|
66
|
-
warnPluginAfterStart: (methodName: string) => void;
|
|
67
|
-
validateAddInterceptorArgs: (method: unknown, fn: unknown) => void;
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Lifecycle guard validation methods
|
|
71
|
-
*/
|
|
72
|
-
lifecycle: {
|
|
73
|
-
validateHandler: (handler: unknown, caller: string) => void;
|
|
74
|
-
validateHandlerLimit: (count: number, methodName: string) => void;
|
|
75
|
-
validateCountThresholds: (count: number, methodName: string) => void;
|
|
76
|
-
warnOverwrite: (name: string, type: string, methodName: string) => void;
|
|
77
|
-
warnAsyncGuardSync: (name: string, methodName: string) => void;
|
|
78
|
-
};
|
|
79
|
-
/**
|
|
80
|
-
* Navigation validation methods
|
|
81
|
-
*/
|
|
82
|
-
navigation: {
|
|
83
|
-
validateNavigateArgs: (name: unknown) => void;
|
|
84
|
-
validateNavigateToDefaultArgs: (options: unknown) => void;
|
|
85
|
-
validateNavigateToStateArgs: (state: unknown) => void;
|
|
86
|
-
validateNavigationOptions: (options: unknown, caller: string) => void;
|
|
87
|
-
validateParams: (params: unknown, methodName: string) => void;
|
|
88
|
-
validateStartArgs: (path: unknown) => void;
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* State validation methods
|
|
92
|
-
*/
|
|
93
|
-
state: {
|
|
94
|
-
validateMakeStateArgs: (name: unknown, params: unknown, path: unknown) => void;
|
|
95
|
-
validateAreStatesEqualArgs: (s1: unknown, s2: unknown, ignoreQP: unknown) => void;
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Event bus validation methods
|
|
99
|
-
*/
|
|
100
|
-
eventBus: {
|
|
101
|
-
validateListenerArgs: (name: unknown, cb: unknown) => void;
|
|
102
|
-
validateCountThresholds: (count: number, eventName: string, methodName: string) => void;
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
//#endregion
|
|
106
|
-
//#region src/RouterError.d.ts
|
|
107
|
-
declare class RouterError extends Error {
|
|
108
|
-
[key: string]: unknown;
|
|
109
|
-
readonly segment: string | undefined;
|
|
110
|
-
readonly path: string | undefined;
|
|
111
|
-
code: string;
|
|
112
|
-
/**
|
|
113
|
-
* Creates a new RouterError instance.
|
|
114
|
-
*
|
|
115
|
-
* The options object accepts built-in fields (message, segment, path)
|
|
116
|
-
* and any additional custom fields, which will all be attached to the error instance.
|
|
117
|
-
*
|
|
118
|
-
* @param code - The error code (e.g., "ROUTE_NOT_FOUND", "CANNOT_ACTIVATE")
|
|
119
|
-
* @param options - Optional configuration object
|
|
120
|
-
* @param options.message - Custom error message (defaults to code if not provided)
|
|
121
|
-
* @param options.segment - The route segment where the error occurred
|
|
122
|
-
* @param options.path - The full path where the error occurred
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* ```typescript
|
|
126
|
-
* // Basic error
|
|
127
|
-
* const err1 = new RouterError("ROUTE_NOT_FOUND");
|
|
128
|
-
*
|
|
129
|
-
* // Error with custom message
|
|
130
|
-
* const err2 = new RouterError("ERR", { message: "Something went wrong" });
|
|
131
|
-
*
|
|
132
|
-
* // Error with context and custom fields
|
|
133
|
-
* const err3 = new RouterError("CANNOT_ACTIVATE", {
|
|
134
|
-
* message: "Insufficient permissions",
|
|
135
|
-
* segment: "admin",
|
|
136
|
-
* path: "/admin/users",
|
|
137
|
-
* userId: "123" // custom field
|
|
138
|
-
* });
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
|
-
constructor(code: string, {
|
|
142
|
-
message,
|
|
143
|
-
segment,
|
|
144
|
-
path,
|
|
145
|
-
...rest
|
|
146
|
-
}?: {
|
|
147
|
-
[key: string]: unknown;
|
|
148
|
-
message?: string | undefined;
|
|
149
|
-
segment?: string | undefined;
|
|
150
|
-
path?: string | undefined;
|
|
151
|
-
});
|
|
152
|
-
/**
|
|
153
|
-
* Updates the error code and conditionally updates the message.
|
|
154
|
-
*
|
|
155
|
-
* If the current message is one of the standard error code values
|
|
156
|
-
* (e.g., "ROUTE_NOT_FOUND", "SAME_STATES"), it will be replaced with the new code.
|
|
157
|
-
* This allows keeping error messages in sync with codes when using standard error codes.
|
|
158
|
-
*
|
|
159
|
-
* If the message is custom (not a standard error code), it will be preserved.
|
|
160
|
-
*
|
|
161
|
-
* @param newCode - The new error code to set
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* // Message follows code (standard error code as message)
|
|
165
|
-
* const err = new RouterError("ROUTE_NOT_FOUND", { message: "ROUTE_NOT_FOUND" });
|
|
166
|
-
* err.setCode("CUSTOM_ERROR"); // message becomes "CUSTOM_ERROR"
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* // Custom message is preserved
|
|
170
|
-
* const err = new RouterError("ERR", { message: "Custom error message" });
|
|
171
|
-
* err.setCode("NEW_CODE"); // message stays "Custom error message"
|
|
172
|
-
*/
|
|
173
|
-
setCode(newCode: string): void;
|
|
174
|
-
/**
|
|
175
|
-
* Copies properties from another Error instance to this RouterError.
|
|
176
|
-
*
|
|
177
|
-
* This method updates the message, cause, and stack trace from the provided error.
|
|
178
|
-
* Useful for wrapping native errors while preserving error context.
|
|
179
|
-
*
|
|
180
|
-
* @param err - The Error instance to copy properties from
|
|
181
|
-
* @throws {TypeError} If err is null or undefined
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ```typescript
|
|
185
|
-
* const routerErr = new RouterError("TRANSITION_ERR");
|
|
186
|
-
* try {
|
|
187
|
-
* // some operation that might fail
|
|
188
|
-
* } catch (nativeErr) {
|
|
189
|
-
* routerErr.setErrorInstance(nativeErr);
|
|
190
|
-
* throw routerErr;
|
|
191
|
-
* }
|
|
192
|
-
* ```
|
|
193
|
-
*/
|
|
194
|
-
setErrorInstance(err: Error): void;
|
|
195
|
-
/**
|
|
196
|
-
* Adds custom fields to the error object.
|
|
197
|
-
*
|
|
198
|
-
* This method allows attaching arbitrary data to the error for debugging or logging purposes.
|
|
199
|
-
* All fields become accessible as properties on the error instance and are included in JSON serialization.
|
|
200
|
-
*
|
|
201
|
-
* Reserved method names (setCode, setErrorInstance, setAdditionalFields, hasField, getField, toJSON)
|
|
202
|
-
* are automatically filtered out to prevent accidental overwriting of class methods.
|
|
203
|
-
*
|
|
204
|
-
* @param fields - Object containing custom fields to add to the error
|
|
205
|
-
*
|
|
206
|
-
* @example
|
|
207
|
-
* ```typescript
|
|
208
|
-
* const err = new RouterError("CANNOT_ACTIVATE");
|
|
209
|
-
* err.setAdditionalFields({
|
|
210
|
-
* userId: "123",
|
|
211
|
-
* attemptedRoute: "/admin",
|
|
212
|
-
* reason: "insufficient permissions"
|
|
213
|
-
* });
|
|
214
|
-
*
|
|
215
|
-
* console.log(err.userId); // "123"
|
|
216
|
-
* console.log(JSON.stringify(err)); // includes all custom fields
|
|
217
|
-
* ```
|
|
218
|
-
*/
|
|
219
|
-
setAdditionalFields(fields: Record<string, unknown>): void;
|
|
220
|
-
/**
|
|
221
|
-
* Checks if a custom field exists on the error object.
|
|
222
|
-
*
|
|
223
|
-
* This method checks for both custom fields added via setAdditionalFields()
|
|
224
|
-
* and built-in fields (code, message, segment, etc.).
|
|
225
|
-
*
|
|
226
|
-
* @param key - The field name to check
|
|
227
|
-
* @returns `true` if the field exists, `false` otherwise
|
|
228
|
-
*
|
|
229
|
-
* @example
|
|
230
|
-
* ```typescript
|
|
231
|
-
* const err = new RouterError("ERR", { segment: "users" });
|
|
232
|
-
* err.setAdditionalFields({ userId: "123" });
|
|
233
|
-
*
|
|
234
|
-
* err.hasField("userId"); // true
|
|
235
|
-
* err.hasField("segment"); // true
|
|
236
|
-
* err.hasField("unknown"); // false
|
|
237
|
-
* ```
|
|
238
|
-
*/
|
|
239
|
-
hasField(key: string): boolean;
|
|
240
|
-
/**
|
|
241
|
-
* Retrieves a custom field value from the error object.
|
|
242
|
-
*
|
|
243
|
-
* This method can access both custom fields and built-in fields.
|
|
244
|
-
* Returns `undefined` if the field doesn't exist.
|
|
245
|
-
*
|
|
246
|
-
* @param key - The field name to retrieve
|
|
247
|
-
* @returns The field value, or `undefined` if it doesn't exist
|
|
248
|
-
*
|
|
249
|
-
* @example
|
|
250
|
-
* ```typescript
|
|
251
|
-
* const err = new RouterError("ERR");
|
|
252
|
-
* err.setAdditionalFields({ userId: "123", role: "admin" });
|
|
253
|
-
*
|
|
254
|
-
* err.getField("userId"); // "123"
|
|
255
|
-
* err.getField("role"); // "admin"
|
|
256
|
-
* err.getField("code"); // "ERR" (built-in field)
|
|
257
|
-
* err.getField("unknown"); // undefined
|
|
258
|
-
* ```
|
|
259
|
-
*/
|
|
260
|
-
getField(key: string): unknown;
|
|
261
|
-
/**
|
|
262
|
-
* Serializes the error to a JSON-compatible object.
|
|
263
|
-
*
|
|
264
|
-
* This method is automatically called by JSON.stringify() and includes:
|
|
265
|
-
* - Built-in fields: code, message, segment (if set), path (if set)
|
|
266
|
-
* - All custom fields added via setAdditionalFields() or constructor
|
|
267
|
-
* - Excludes: stack trace (for security/cleanliness)
|
|
268
|
-
*
|
|
269
|
-
* @returns A plain object representation of the error, suitable for JSON serialization
|
|
270
|
-
*
|
|
271
|
-
* @example
|
|
272
|
-
* ```typescript
|
|
273
|
-
* const err = new RouterError("ROUTE_NOT_FOUND", {
|
|
274
|
-
* message: "Route not found",
|
|
275
|
-
* path: "/admin/users/123"
|
|
276
|
-
* });
|
|
277
|
-
* err.setAdditionalFields({ userId: "123" });
|
|
278
|
-
*
|
|
279
|
-
* JSON.stringify(err);
|
|
280
|
-
* // {
|
|
281
|
-
* // "code": "ROUTE_NOT_FOUND",
|
|
282
|
-
* // "message": "Route not found",
|
|
283
|
-
* // "path": "/admin/users/123",
|
|
284
|
-
* // "userId": "123"
|
|
285
|
-
* // }
|
|
286
|
-
* ```
|
|
287
|
-
*/
|
|
288
|
-
toJSON(): Record<string, unknown>;
|
|
289
|
-
}
|
|
290
|
-
//#endregion
|
|
291
|
-
export { RouterValidator as n, RouterError as t };
|
|
292
|
-
//# sourceMappingURL=RouterError-OKaEXSBZ.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RouterError-OKaEXSBZ.d.mts","names":[],"sources":["../../src/types/RouterValidator.ts","../../src/RouterError.ts"],"mappings":";;AAUA;;;;;;;;UAAiB,eAAA;EAOb;;;EAHF,MAAA;IACE,qBAAA,GAAwB,KAAA;IACxB,qBAAA,GAAwB,IAAA;IACxB,yBAAA,GACE,IAAA,WACA,MAAA,WACA,MAAA,WACA,QAAA;IAEF,4BAAA,GAA+B,IAAA;IAC/B,wBAAA,GACE,IAAA,WACA,MAAA,WACA,MAAA;IAEF,oBAAA,GAAuB,MAAA;IACvB,cAAA,GACE,MAAA,aACA,IAAA,WACA,UAAA;IAEF,uBAAA,GAA0B,IAAA;IAC1B,4BAAA,GAA+B,IAAA,WAAe,OAAA;IAC9C,gCAAA,GAAmC,IAAA,UAAc,OAAA;IACjD,mBAAA,GACE,IAAA,UACA,OAAA,WACA,IAAA;IAEF,oBAAA,GAAuB,MAAA,WAAiB,IAAA;IACxC,iBAAA,GAAoB,IAAA,WAAe,MAAA;IACnC,oBAAA,GAAuB,IAAA,WAAe,MAAA;IACtC,2BAAA,GAA8B,MAAA,aAAmB,MAAA;IACjD,uBAAA,GAA0B,QAAA;IAC1B,mBAAA,GAAsB,KAAA;IACtB,qBAAA,GAAwB,KAAA;EAAA;EAZW;;;EAkBrC,OAAA;IACE,eAAA,GAAkB,OAAA,WAAkB,UAAA;IACpC,4BAAA,GAA+B,SAAA,WAAoB,KAAA;EAAA;EAd5B;;;EAoBzB,YAAA;IACE,sBAAA,GAAyB,IAAA,WAAe,MAAA;IACxC,yBAAA,GACE,IAAA,WACA,KAAA,WACA,MAAA;IAEF,0BAAA,GAA6B,IAAA,WAAe,MAAA;IAC5C,wBAAA,GAA2B,IAAA,UAAc,KAAA;IACzC,uBAAA,GAA0B,KAAA,WAAgB,UAAA;IAC1C,iBAAA,GAAoB,YAAA;IACpB,aAAA,GAAgB,IAAA,UAAc,UAAA;IAC9B,kBAAA,GAAqB,IAAA,YAAgB,UAAA;IACrC,qBAAA,GAAwB,IAAA;EAAA;EA5BF;;;EAkCxB,OAAA;IACE,mBAAA,GAAsB,KAAA,UAAe,MAAA;IACrC,0BAAA,GACE,OAAA,WACA,SAAA;IAEF,kBAAA,GAAqB,MAAA;IACrB,uBAAA,GAA0B,KAAA;IAC1B,mBAAA,GAAsB,OAAA;IACtB,oBAAA,GAAuB,UAAA;IACvB,oBAAA,GAAuB,UAAA;IACvB,0BAAA,GAA6B,MAAA,WAAiB,EAAA;EAAA;EA7BN;;;EAmC1C,SAAA;IACE,eAAA,GAAkB,OAAA,WAAkB,MAAA;IACpC,oBAAA,GAAuB,KAAA,UAAe,UAAA;IACtC,uBAAA,GAA0B,KAAA,UAAe,UAAA;IACzC,aAAA,GAAgB,IAAA,UAAc,IAAA,UAAc,UAAA;IAC5C,kBAAA,GAAqB,IAAA,UAAc,UAAA;EAAA;EAjCM;;;EAuC3C,UAAA;IACE,oBAAA,GAAuB,IAAA;IACvB,6BAAA,GAAgC,OAAA;IAChC,2BAAA,GAA8B,KAAA;IAC9B,yBAAA,GAA4B,OAAA,WAAkB,MAAA;IAC9C,cAAA,GAAiB,MAAA,WAAiB,UAAA;IAClC,iBAAA,GAAoB,IAAA;EAAA;EAzCiB;;;EA+CvC,KAAA;IACE,qBAAA,GACE,IAAA,WACA,MAAA,WACA,IAAA;IAEF,0BAAA,GACE,EAAA,WACA,EAAA,WACA,QAAA;EAAA;EA/CF;;;EAsDF,QAAA;IACE,oBAAA,GAAuB,IAAA,WAAe,EAAA;IACtC,uBAAA,GACE,KAAA,UACA,SAAA,UACA,UAAA;EAAA;AAAA;;;cC1HO,WAAA,SAAoB,KAAA;EAAA,CAC9B,GAAA;EAAA,SAIQ,OAAA;EAAA,SACA,IAAA;EAIT,IAAA;EDjBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cCiDE,IAAA;IAEE,OAAA;IACA,OAAA;IACA,IAAA;IAAA,GACG;EAAA;IAAA,CAEF,GAAA;IACD,OAAA;IACA,OAAA;IACA,IAAA;EAAA;ED9BqB;;;;;;;;;;;;;;;;;;;;;ECgFzB,OAAA,CAAQ,OAAA;EDlEyB;;;;;;;;;;;;;;;;;;;;EC+FjC,gBAAA,CAAiB,GAAA,EAAK,KAAA;ED9EpB;;;;;;;;;;;;;;;;;;;;;;;;ECmHF,mBAAA,CAAoB,MAAA,EAAQ,MAAA;EDhG1B;;;;;;;;;;;;;;;;;;;ECkIF,QAAA,CAAS,GAAA;EDjHT;;;;;;;;;;;;;;;;;;;;ECyIA,QAAA,CAAS,GAAA;EDtHL;;;;;;;;;;;;AAckB;;;;AC1HxB;;;;;;;;;;;EAiQE,MAAA,IAAU,MAAA;AAAA"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{C as e,_ as t,n,t as r}from"./Router-CTGJBKd7.mjs";import{a as i,l as a}from"./esm-Cnywzxys.mjs";function o(t){if(t())throw new n(e.ROUTER_DISPOSED)}function s(t){if(t())throw new n(e.REENTRANT_TREE_MUTATION)}const c=new WeakMap;function l(t){let r=c.get(t);if(r)return r;let i=a(t),s={makeState:(e,t,n,r)=>(i.validator?.state.validateMakeStateArgs(e,t,n),i.makeState(e,t,n,r?.params)),buildState:(e,t)=>{i.validator?.routes.validateStateBuilderArgs(e,t,`buildState`);let{name:n,params:r}=i.forwardState(e,t);return i.buildStateResolved(n,r)},forwardState:(e,t)=>(i.validator?.routes.validateStateBuilderArgs(e,t,`forwardState`),i.forwardState(e,t)),matchPath:e=>(i.validator?.routes.validateMatchPathArgs(e),i.matchPath(e,i.getOptions())),navigateToState:(e,t)=>(o(i.isDisposed),i.validator?.navigation.validateNavigateToStateArgs(e),t!==void 0&&i.validator?.navigation.validateNavigationOptions(t,`navigateToState`),i.navigateToState(e,t)),setRootPath:e=>{o(i.isDisposed),i.validator?.routes.validateSetRootPathArgs(e),i.setRootPath(e)},getRootPath:i.getRootPath,addEventListener:(e,t)=>(o(i.isDisposed),i.validator?.eventBus.validateListenerArgs(e,t),i.addEventListener(e,t)),buildNavigationState:(e,t={})=>{i.validator?.routes.validateStateBuilderArgs(e,t,`buildNavigationState`);let{name:n,params:r}=i.forwardState(e,t),a=i.buildStateResolved(n,r);if(a)return i.makeState(a.name,a.params,i.buildPath(a.name,a.params),a.meta)},getOptions:i.getOptions,getTree:i.getTree,addInterceptor:(e,t)=>{o(i.isDisposed),i.validator?.plugins.validateAddInterceptorArgs(e,t);let n=i.interceptors.get(e);n||(n=[],i.interceptors.set(e,n)),n.push(t);let r=!1;return()=>{r||(r=!0,n.splice(n.indexOf(t),1))}},getRouteConfig:e=>{let t=i.routeGetStore();if(t.matcher.hasRoute(e))return t.routeCustomFields[e]},extendRouter:r=>{o(i.isDisposed);let a=Object.keys(r);for(let r of a)if(r in t)throw new n(e.PLUGIN_CONFLICT,{message:`Cannot extend router: property "${r}" already exists`});for(let e of a)t[e]=r[e];let s={keys:a};i.routerExtensions.push(s);let c=!1;return()=>{if(c)return;c=!0;for(let e of s.keys)delete t[e];let e=i.routerExtensions.indexOf(s);e!==-1&&i.routerExtensions.splice(e,1)}},emitTransitionError:e=>{o(i.isDisposed),i.emitTransitionError(e)},claimContextNamespace:t=>{if(o(i.isDisposed),typeof t!=`string`||t===``)throw TypeError(`[claimContextNamespace] namespace must be a non-empty string, got ${typeof t==`string`?`an empty string`:typeof t}`);if(i.contextClaimRecords.has(t))throw new n(e.CONTEXT_NAMESPACE_ALREADY_CLAIMED,{message:`Cannot claim context namespace: "${t}" is already claimed by another plugin`});return i.contextClaimRecords.add(t),{write(e,n){t===`__proto__`?Object.defineProperty(e.context,t,{value:n,writable:!0,enumerable:!0,configurable:!0}):e.context[t]=n},release(){i.contextClaimRecords.delete(t)}}}};return c.set(t,s),s}function u(e){let t=a(e),n=t.routeGetStore().lifecycleNamespace;return{addActivateGuard(e,r){o(t.isDisposed),t.validator?.routes.validateRouteName(e,`addActivateGuard`),t.validator?.lifecycle.validateHandler(r,`addActivateGuard`),n.addCanActivate(e,r)},addDeactivateGuard(e,r){o(t.isDisposed),t.validator?.routes.validateRouteName(e,`addDeactivateGuard`),t.validator?.lifecycle.validateHandler(r,`addDeactivateGuard`),n.addCanDeactivate(e,r)},removeActivateGuard(e){o(t.isDisposed),t.validator?.routes.validateRouteName(e,`removeActivateGuard`),n.clearCanActivate(e,`external`)},removeDeactivateGuard(e){o(t.isDisposed),t.validator?.routes.validateRouteName(e,`removeDeactivateGuard`),n.clearCanDeactivate(e,`external`)}}}function d(o,s){let c=a(o);if(c.isDisposed())throw new n(e.ROUTER_DISPOSED);c.validator?.dependencies.validateCloneArgs(s);let l=c.routeGetStore(),d=i(l.tree),f=l.config,p=l.resolvedForwardMap,m=l.routeCustomFields,{options:h,dependencies:g,pluginFactories:_}=c.getCloneState(),{definition:v,external:y}=l.lifecycleNamespace.getFactoriesByOrigin(),b=new r(d,h,{...g,...s}),x=a(b),S=x.routeGetStore(),C=S.lifecycleNamespace;t(S.config,f),Object.assign(S.resolvedForwardMap,p),Object.assign(S.routeCustomFields,m),l.rootPath!==``&&x.setRootPath(l.rootPath);let[w,T]=v,[E,D]=y;for(let[e,t]of Object.entries(w))C.addCanDeactivate(e,t,!0);for(let[e,t]of Object.entries(T))C.addCanActivate(e,t,!0);let O=u(b);for(let[e,t]of Object.entries(E))O.addDeactivateGuard(e,t);for(let[e,t]of Object.entries(D))O.addActivateGuard(e,t);let k=new Set(x.getCloneState().pluginFactories),A=_.filter(e=>!k.has(e));return A.length>0&&b.usePlugin(...A),b}export{s as a,o as i,u as n,l as r,d as t};
|
|
2
|
-
//# sourceMappingURL=cloneRouter-C4v9Xl2F.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cloneRouter-C4v9Xl2F.mjs","names":["routeTreeToDefinitions","RouterClass"],"sources":["../../src/api/helpers.ts","../../src/api/getPluginApi.ts","../../src/api/getLifecycleApi.ts","../../src/api/cloneRouter.ts"],"sourcesContent":["// packages/core/src/api/helpers.ts\n\nimport { errorCodes } from \"../constants\";\nimport { RouterError } from \"../RouterError\";\n\nexport function throwIfDisposed(isDisposed: () => boolean): void {\n if (isDisposed()) {\n throw new RouterError(errorCodes.ROUTER_DISPOSED);\n }\n}\n\n/**\n * Bans synchronous reentrant route-CRUD: a CRUD op called while a `TREE_CHANGED`\n * emit is on the stack (i.e. from inside a `subscribeChanges` handler) throws\n * `REENTRANT_TREE_MUTATION` BEFORE mutating — the tree stays atomic (#1032).\n * Deferred CRUD (`queueMicrotask` / `await`) runs after the dispatch settles and\n * is unaffected; CRUD from a transition listener is not a TREE_CHANGED dispatch.\n */\nexport function throwIfReentrantTreeMutation(isEmitting: () => boolean): void {\n if (isEmitting()) {\n throw new RouterError(errorCodes.REENTRANT_TREE_MUTATION);\n }\n}\n","import { throwIfDisposed } from \"./helpers\";\nimport { errorCodes } from \"../constants\";\nimport { getInternals } from \"../internals\";\nimport { RouterError } from \"../RouterError\";\n\nimport type { PluginApi } from \"./types\";\nimport type {\n ContextNamespaceClaim,\n DefaultDependencies,\n Params,\n Router,\n State,\n} from \"@real-router/types\";\n\n// Cache the assembled PluginApi per router — mirrors getNavigator() (#525):\n// avoids re-allocating the closure-bag on each call (plugins call this once\n// at init, but tests + nested plugins poll it), and gives spy/stub helpers\n// a stable object identity to attach to (e.g. spying on\n// `getPluginApi(router).navigateToState` to inject errors in popstate\n// recovery tests).\nconst cache = new WeakMap<object, PluginApi>();\n\nexport function getPluginApi<\n Dependencies extends DefaultDependencies = DefaultDependencies,\n>(router: Router<Dependencies>): PluginApi {\n const cached = cache.get(router);\n\n if (cached) {\n return cached;\n }\n\n const ctx = getInternals(router);\n const api: PluginApi = {\n makeState: (name, params, path, meta) => {\n ctx.validator?.state.validateMakeStateArgs(name, params, path);\n\n return ctx.makeState(\n name,\n params,\n path,\n meta?.params as\n Record<string, Record<string, \"url\" | \"query\">> | undefined,\n );\n },\n buildState: (routeName, routeParams) => {\n ctx.validator?.routes.validateStateBuilderArgs(\n routeName,\n routeParams,\n \"buildState\",\n );\n\n const { name, params } = ctx.forwardState(routeName, routeParams);\n\n return ctx.buildStateResolved(name, params);\n },\n forwardState: <P extends Params = Params>(\n routeName: string,\n routeParams: P,\n ) => {\n ctx.validator?.routes.validateStateBuilderArgs(\n routeName,\n routeParams,\n \"forwardState\",\n );\n\n return ctx.forwardState(routeName, routeParams);\n },\n matchPath: (path) => {\n ctx.validator?.routes.validateMatchPathArgs(path);\n\n return ctx.matchPath(path, ctx.getOptions());\n },\n navigateToState: (state, options) => {\n throwIfDisposed(ctx.isDisposed);\n\n ctx.validator?.navigation.validateNavigateToStateArgs(state);\n\n if (options !== undefined) {\n ctx.validator?.navigation.validateNavigationOptions(\n options,\n \"navigateToState\",\n );\n }\n\n return ctx.navigateToState(state, options);\n },\n setRootPath: (rootPath) => {\n throwIfDisposed(ctx.isDisposed);\n\n ctx.validator?.routes.validateSetRootPathArgs(rootPath);\n\n ctx.setRootPath(rootPath);\n },\n getRootPath: ctx.getRootPath,\n addEventListener: (eventName, cb) => {\n throwIfDisposed(ctx.isDisposed);\n\n ctx.validator?.eventBus.validateListenerArgs(eventName, cb);\n\n return ctx.addEventListener(eventName, cb);\n },\n buildNavigationState: (name, params = {}) => {\n ctx.validator?.routes.validateStateBuilderArgs(\n name,\n params,\n \"buildNavigationState\",\n );\n\n const { name: resolvedName, params: resolvedParams } = ctx.forwardState(\n name,\n params,\n );\n const routeInfo = ctx.buildStateResolved(resolvedName, resolvedParams);\n\n if (!routeInfo) {\n return;\n }\n\n return ctx.makeState(\n routeInfo.name,\n routeInfo.params,\n ctx.buildPath(routeInfo.name, routeInfo.params),\n routeInfo.meta,\n );\n },\n getOptions: ctx.getOptions,\n getTree: ctx.getTree,\n addInterceptor: (method, fn) => {\n throwIfDisposed(ctx.isDisposed);\n ctx.validator?.plugins.validateAddInterceptorArgs(method, fn);\n let list = ctx.interceptors.get(method);\n\n if (!list) {\n list = [];\n ctx.interceptors.set(method, list);\n }\n\n list.push(fn);\n\n // Idempotency flag (#1198). Without it, a double call would `indexOf(fn)`\n // again and splice a DUPLICATE registration of the same fn — silently\n // deactivating another plugin's interceptor whose own unsubscribe was never\n // called. The `Unsubscribe` contract is documented idempotent. The flag\n // guarantees exactly one splice of a still-present `fn`, so no `index !== -1`\n // guard is needed (it would be dead — the second call returns above).\n let removed = false;\n\n return () => {\n if (removed) {\n return;\n }\n\n removed = true;\n list.splice(list.indexOf(fn), 1);\n };\n },\n getRouteConfig: (name) => {\n const store = ctx.routeGetStore();\n\n // Stryker disable next-line ConditionalExpression,BlockStatement: equivalent — a missing route yields routeCustomFields[name] === undefined, identical to this early return\n if (!store.matcher.hasRoute(name)) {\n return;\n }\n\n return store.routeCustomFields[name];\n },\n extendRouter: (extensions: Record<string, unknown>) => {\n throwIfDisposed(ctx.isDisposed);\n\n const keys = Object.keys(extensions);\n\n for (const key of keys) {\n if (key in router) {\n throw new RouterError(errorCodes.PLUGIN_CONFLICT, {\n message: `Cannot extend router: property \"${key}\" already exists`,\n });\n }\n }\n\n for (const key of keys) {\n (router as Record<string, unknown>)[key] = extensions[key];\n }\n\n const extensionRecord = { keys };\n\n ctx.routerExtensions.push(extensionRecord);\n\n let removed = false;\n\n return () => {\n if (removed) {\n return;\n }\n\n removed = true;\n\n for (const key of extensionRecord.keys) {\n delete (router as Record<string, unknown>)[key];\n }\n\n const idx = ctx.routerExtensions.indexOf(extensionRecord);\n\n // Stryker disable next-line ConditionalExpression,EqualityOperator,UnaryOperator,BlockStatement: equivalent — this splice only tidies the `routerExtensions` TRACKING array; the router INSTANCE is cleaned by the `delete router[key]` loop above, and dispose()'s safety-net re-deletes any leaked key harmlessly. So no mutation of this guard/splice is behaviourally observable (full suite green with `===`, `+1`, and an empty body). Contrast the addInterceptor splice, which IS observable through buildPath and is killed behaviourally by invariantGuardMutants.test.ts.\n if (idx !== -1) {\n ctx.routerExtensions.splice(idx, 1);\n }\n };\n },\n emitTransitionError: (error) => {\n throwIfDisposed(ctx.isDisposed);\n ctx.emitTransitionError(error);\n },\n claimContextNamespace: (namespace: string) => {\n throwIfDisposed(ctx.isDisposed);\n\n // Input-shape guard, symmetric with the other always-on invariant guards\n // (subscribe / start / navigateToNotFound each typeof-check their input).\n // A non-string namespace coerces to an inconsistent key (\"42\"); an empty\n // string is a meaningless namespace (#1191 N4).\n if (typeof namespace !== \"string\" || namespace === \"\") {\n throw new TypeError(\n `[claimContextNamespace] namespace must be a non-empty string, got ${\n typeof namespace === \"string\" ? \"an empty string\" : typeof namespace\n }`,\n );\n }\n\n if (ctx.contextClaimRecords.has(namespace)) {\n throw new RouterError(errorCodes.CONTEXT_NAMESPACE_ALREADY_CLAIMED, {\n message: `Cannot claim context namespace: \"${namespace}\" is already claimed by another plugin`,\n });\n }\n\n ctx.contextClaimRecords.add(namespace);\n\n return {\n write(state: State, value: unknown) {\n // `state.context[namespace] = value` dispatches into the inherited\n // Object.prototype.__proto__ setter for the literal key \"__proto__\",\n // swapping the prototype instead of creating an own entry — the data\n // then vanishes from Object.keys / serializeRouterState (#1191 N3).\n // Mirror search-params' assignParam: defineProperty writes a genuine\n // own property; normal names keep the plain-assignment fast path.\n if (namespace === \"__proto__\") {\n Object.defineProperty(state.context, namespace, {\n value,\n writable: true,\n enumerable: true,\n configurable: true,\n });\n } else {\n state.context[namespace] = value;\n }\n },\n release() {\n ctx.contextClaimRecords.delete(namespace);\n },\n } satisfies ContextNamespaceClaim;\n },\n };\n\n cache.set(router, api);\n\n return api;\n}\n","import { throwIfDisposed } from \"./helpers\";\nimport { getInternals } from \"../internals\";\n\nimport type { LifecycleApi } from \"./types\";\nimport type { DefaultDependencies, Router } from \"@real-router/types\";\n\nexport function getLifecycleApi<\n Dependencies extends DefaultDependencies = DefaultDependencies,\n>(router: Router<Dependencies>): LifecycleApi<Dependencies> {\n const ctx = getInternals(router);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- guaranteed set after wiring\n const lifecycleNamespace = ctx.routeGetStore().lifecycleNamespace!;\n\n return {\n addActivateGuard(name, handler) {\n throwIfDisposed(ctx.isDisposed);\n\n ctx.validator?.routes.validateRouteName(name, \"addActivateGuard\");\n ctx.validator?.lifecycle.validateHandler(handler, \"addActivateGuard\");\n\n // Handler-limit enforcement lives at the namespace registration choke point\n // (RouteLifecycleNamespace.#registerHandler) so all paths are bounded\n // uniformly — see #961.\n lifecycleNamespace.addCanActivate(name, handler);\n },\n\n addDeactivateGuard(name, handler) {\n throwIfDisposed(ctx.isDisposed);\n\n ctx.validator?.routes.validateRouteName(name, \"addDeactivateGuard\");\n ctx.validator?.lifecycle.validateHandler(handler, \"addDeactivateGuard\");\n\n lifecycleNamespace.addCanDeactivate(name, handler);\n },\n\n removeActivateGuard(name) {\n throwIfDisposed(ctx.isDisposed);\n\n ctx.validator?.routes.validateRouteName(name, \"removeActivateGuard\");\n\n // Inverse of addActivateGuard (external): clears only the external guard;\n // a route-config (definition) canActivate survives (#1171).\n lifecycleNamespace.clearCanActivate(name, \"external\");\n },\n\n removeDeactivateGuard(name) {\n throwIfDisposed(ctx.isDisposed);\n\n ctx.validator?.routes.validateRouteName(name, \"removeDeactivateGuard\");\n\n // Inverse of addDeactivateGuard (external): clears only the external guard;\n // a route-config (definition) canDeactivate survives (#1171).\n lifecycleNamespace.clearCanDeactivate(name, \"external\");\n },\n };\n}\n","import { routeTreeToDefinitions } from \"engine\";\n\nimport { errorCodes } from \"../constants\";\nimport { getInternals } from \"../internals\";\nimport { assignConfigEntries } from \"../namespaces/RoutesNamespace/helpers\";\nimport { Router as RouterClass } from \"../Router\";\nimport { RouterError } from \"../RouterError\";\nimport { getLifecycleApi } from \"./getLifecycleApi\";\n\nimport type { Route } from \"../types\";\nimport type { DefaultDependencies, Router } from \"@real-router/types\";\n\n/**\n * Build an independent router instance that shares the route tree, options,\n * lifecycle guards, and plugin factories of `router`. The primary use case\n * is **SSR multi-tenancy** — one base router per process, one clone per\n * request.\n *\n * @param router - Source router (must not be disposed).\n * @param dependencies - Optional per-clone overrides merged on top of the\n * base router's dependencies. Always **fresh per call** in the documented\n * SSR pattern: pass per-request state here, never store it in the base.\n *\n * @remarks\n *\n * **Dependency merge — shallow by design.** `base.dependencies` are spread\n * into the clone via `{ ...sourceDeps, ...dependencies }`. Top-level keys\n * are new objects, but **values are shared by reference**: a `Map`, `Set`,\n * class instance, function, or nested plain object stored in\n * `base.dependencies` is the **same instance** in every clone. Mutations\n * in one clone are visible in the base and in every sibling clone.\n *\n * This is intentional. `structuredClone` of dep values is **not** applied\n * because it would:\n * - strip class prototypes (`new DbClient()` → plain object, methods lost)\n * - reject functions and symbols (`DataCloneError`)\n * - fragment singleton pools (one connection pool per request — pool\n * semantics destroyed)\n * - reject circular references\n *\n * **SSR rule of thumb.** Place values in `base.dependencies` according to\n * their lifecycle:\n *\n * - **Singletons / shared services** → `base.dependencies`. Examples: DB\n * client, connection pool, logger, config, feature-flag client. Process-\n * wide pooling depends on sharing these by reference.\n * - **Per-request state** → the `dependencies` override parameter (or\n * `createRequestScope`'s `deps` argument). Examples: `currentUser`,\n * `traceId`, `sessionId`, `abortSignal`. The override is applied last,\n * so it wins over base keys; pass a fresh object per call.\n *\n * Cross-request data leaks are **only possible** when per-request mutable\n * state is incorrectly placed in `base.dependencies`. The override slot is\n * the safe channel.\n *\n * @example\n * ```typescript\n * // Server boot — singletons only\n * const base = createRouter(routes, options, {\n * db: new DbClient(dbUrl),\n * logger,\n * });\n *\n * // Per request — fresh override per call\n * const clone = cloneRouter(base, {\n * currentUser,\n * traceId,\n * });\n * // clone.deps.db === base.deps.db ✓ shared pool (intentional)\n * // clone.deps.currentUser ✓ unique per request\n * ```\n *\n * @see createRequestScope — `@real-router/core/utils` SSR helper that\n * wraps this function and injects `abortSignal` automatically.\n */\nexport function cloneRouter<\n Dependencies extends DefaultDependencies = DefaultDependencies,\n>(\n router: Router<Dependencies>,\n dependencies?: Dependencies,\n): RouterClass<Dependencies> {\n const ctx = getInternals(router);\n\n if (ctx.isDisposed()) {\n throw new RouterError(errorCodes.ROUTER_DISPOSED);\n }\n\n ctx.validator?.dependencies.validateCloneArgs(dependencies);\n\n // Get source store directly\n const sourceStore = ctx.routeGetStore();\n const routes = routeTreeToDefinitions(sourceStore.tree);\n const routeConfig = sourceStore.config;\n const resolvedForwardMap = sourceStore.resolvedForwardMap;\n const routeCustomFields = sourceStore.routeCustomFields;\n\n const {\n options,\n dependencies: sourceDeps,\n pluginFactories,\n } = ctx.getCloneState();\n // Origin-aware factory snapshot — definition guards are re-registered with\n // `isFromDefinition=true` on the clone so `replace()` can still strip them\n // via `clearDefinitionGuards()`. External guards take the public lifecycle\n // API path so they survive `replace()` symmetric with the base.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- guaranteed set after wiring\n const sourceLifecycleNamespace = sourceStore.lifecycleNamespace!;\n const { definition: definitionFactories, external: externalFactories } =\n sourceLifecycleNamespace.getFactoriesByOrigin();\n\n const mergedDeps = {\n ...sourceDeps,\n ...dependencies,\n } as Dependencies;\n\n const newRouter = new RouterClass<Dependencies>(\n routes as Route<Dependencies>[],\n options,\n mergedDeps,\n );\n\n const newCtx = getInternals(newRouter);\n const newStore = newCtx.routeGetStore();\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- guaranteed set after wiring\n const newLifecycleNamespace = newStore.lifecycleNamespace!;\n\n // Copy the source config + store-level maps BEFORE re-registering guards\n // (#1331 review): the definition-guard factories re-executed below must\n // observe the fully-built clone (encoders/decoders/defaultParams/custom\n // fields), mirroring the constructor where flushPendingGuards runs after the\n // store is complete. The five RouteConfig sub-maps go through a single\n // enumeration so a newly added config field is carried over automatically\n // (#965); resolvedForwardMap and routeCustomFields are store-level (not part\n // of RouteConfig) and stay explicit.\n assignConfigEntries(newStore.config, routeConfig);\n Object.assign(newStore.resolvedForwardMap, resolvedForwardMap);\n Object.assign(newStore.routeCustomFields, routeCustomFields);\n\n // #1175: carry the source rootPath. It lives in the store (not options/config),\n // and neither routeTreeToDefinitions nor getCloneState include it — so a clone\n // of a base configured with `setRootPath(\"/app\")` would otherwise build/match\n // under \"\" and 404 every request of a sub-path SSR deployment. setRootPath\n // rebuilds the tree in place with the just-copied config; the rebuild is only\n // paid when a rootPath is actually set, and it runs before the definition-guard\n // factories below so they observe the fully-built clone (rootPath included).\n if (sourceStore.rootPath !== \"\") {\n newCtx.setRootPath(sourceStore.rootPath);\n }\n\n const [definitionDeactivate, definitionActivate] = definitionFactories;\n const [externalDeactivate, externalActivate] = externalFactories;\n\n for (const [name, handler] of Object.entries(definitionDeactivate)) {\n newLifecycleNamespace.addCanDeactivate(name, handler, true);\n }\n\n for (const [name, handler] of Object.entries(definitionActivate)) {\n newLifecycleNamespace.addCanActivate(name, handler, true);\n }\n\n const lifecycle = getLifecycleApi(newRouter);\n\n for (const [name, handler] of Object.entries(externalDeactivate)) {\n lifecycle.addDeactivateGuard(name, handler);\n }\n\n for (const [name, handler] of Object.entries(externalActivate)) {\n lifecycle.addActivateGuard(name, handler);\n }\n\n // Plugin replay runs last and skips factories that a (contract-violating)\n // definition-guard factory already registered on the clone during the\n // re-compilation above — without the filter every clone would double-apply\n // such a plugin: once via the factory, once via this replay (#1331 review).\n const alreadyRegistered = new Set(newCtx.getCloneState().pluginFactories);\n const pluginsToReplay = pluginFactories.filter(\n (factory) => !alreadyRegistered.has(factory),\n );\n\n // Stryker disable next-line EqualityOperator: equivalent — `>= 0` is always true, but `usePlugin(...[])` with an empty spread is a no-op, so entering the block on an empty list behaves identically to skipping it. (ConditionalExpression stays live: `→false` skips a real plugin list and is killable.)\n if (pluginsToReplay.length > 0) {\n newRouter.usePlugin(...pluginsToReplay);\n }\n\n return newRouter;\n}\n"],"mappings":"wGAKA,SAAgB,EAAgB,EAAiC,CAC/D,GAAI,EAAW,EACb,MAAM,IAAI,EAAY,EAAW,eAAe,CAEpD,CASA,SAAgB,EAA6B,EAAiC,CAC5E,GAAI,EAAW,EACb,MAAM,IAAI,EAAY,EAAW,uBAAuB,CAE5D,CCFA,MAAM,EAAQ,IAAI,QAElB,SAAgB,EAEd,EAAyC,CACzC,IAAM,EAAS,EAAM,IAAI,CAAM,EAE/B,GAAI,EACF,OAAO,EAGT,IAAM,EAAM,EAAa,CAAM,EACzB,EAAiB,CACrB,WAAY,EAAM,EAAQ,EAAM,KAC9B,EAAI,WAAW,MAAM,sBAAsB,EAAM,EAAQ,CAAI,EAEtD,EAAI,UACT,EACA,EACA,EACA,GAAM,MAER,GAEF,YAAa,EAAW,IAAgB,CACtC,EAAI,WAAW,OAAO,yBACpB,EACA,EACA,YACF,EAEA,GAAM,CAAE,OAAM,UAAW,EAAI,aAAa,EAAW,CAAW,EAEhE,OAAO,EAAI,mBAAmB,EAAM,CAAM,CAC5C,EACA,cACE,EACA,KAEA,EAAI,WAAW,OAAO,yBACpB,EACA,EACA,cACF,EAEO,EAAI,aAAa,EAAW,CAAW,GAEhD,UAAY,IACV,EAAI,WAAW,OAAO,sBAAsB,CAAI,EAEzC,EAAI,UAAU,EAAM,EAAI,WAAW,CAAC,GAE7C,iBAAkB,EAAO,KACvB,EAAgB,EAAI,UAAU,EAE9B,EAAI,WAAW,WAAW,4BAA4B,CAAK,EAEvD,IAAY,IAAA,IACd,EAAI,WAAW,WAAW,0BACxB,EACA,iBACF,EAGK,EAAI,gBAAgB,EAAO,CAAO,GAE3C,YAAc,GAAa,CACzB,EAAgB,EAAI,UAAU,EAE9B,EAAI,WAAW,OAAO,wBAAwB,CAAQ,EAEtD,EAAI,YAAY,CAAQ,CAC1B,EACA,YAAa,EAAI,YACjB,kBAAmB,EAAW,KAC5B,EAAgB,EAAI,UAAU,EAE9B,EAAI,WAAW,SAAS,qBAAqB,EAAW,CAAE,EAEnD,EAAI,iBAAiB,EAAW,CAAE,GAE3C,sBAAuB,EAAM,EAAS,CAAC,IAAM,CAC3C,EAAI,WAAW,OAAO,yBACpB,EACA,EACA,sBACF,EAEA,GAAM,CAAE,KAAM,EAAc,OAAQ,GAAmB,EAAI,aACzD,EACA,CACF,EACM,EAAY,EAAI,mBAAmB,EAAc,CAAc,EAEhE,KAIL,OAAO,EAAI,UACT,EAAU,KACV,EAAU,OACV,EAAI,UAAU,EAAU,KAAM,EAAU,MAAM,EAC9C,EAAU,IACZ,CACF,EACA,WAAY,EAAI,WAChB,QAAS,EAAI,QACb,gBAAiB,EAAQ,IAAO,CAC9B,EAAgB,EAAI,UAAU,EAC9B,EAAI,WAAW,QAAQ,2BAA2B,EAAQ,CAAE,EAC5D,IAAI,EAAO,EAAI,aAAa,IAAI,CAAM,EAEjC,IACH,EAAO,CAAC,EACR,EAAI,aAAa,IAAI,EAAQ,CAAI,GAGnC,EAAK,KAAK,CAAE,EAQZ,IAAI,EAAU,GAEd,UAAa,CACP,IAIJ,EAAU,GACV,EAAK,OAAO,EAAK,QAAQ,CAAE,EAAG,CAAC,EACjC,CACF,EACA,eAAiB,GAAS,CACxB,IAAM,EAAQ,EAAI,cAAc,EAG3B,KAAM,QAAQ,SAAS,CAAI,EAIhC,OAAO,EAAM,kBAAkB,EACjC,EACA,aAAe,GAAwC,CACrD,EAAgB,EAAI,UAAU,EAE9B,IAAM,EAAO,OAAO,KAAK,CAAU,EAEnC,IAAK,IAAM,KAAO,EAChB,GAAI,KAAO,EACT,MAAM,IAAI,EAAY,EAAW,gBAAiB,CAChD,QAAS,mCAAmC,EAAI,iBAClD,CAAC,EAIL,IAAK,IAAM,KAAO,EAChB,EAAoC,GAAO,EAAW,GAGxD,IAAM,EAAkB,CAAE,MAAK,EAE/B,EAAI,iBAAiB,KAAK,CAAe,EAEzC,IAAI,EAAU,GAEd,UAAa,CACX,GAAI,EACF,OAGF,EAAU,GAEV,IAAK,IAAM,KAAO,EAAgB,KAChC,OAAQ,EAAmC,GAG7C,IAAM,EAAM,EAAI,iBAAiB,QAAQ,CAAe,EAGpD,IAAQ,IACV,EAAI,iBAAiB,OAAO,EAAK,CAAC,CAEtC,CACF,EACA,oBAAsB,GAAU,CAC9B,EAAgB,EAAI,UAAU,EAC9B,EAAI,oBAAoB,CAAK,CAC/B,EACA,sBAAwB,GAAsB,CAO5C,GANA,EAAgB,EAAI,UAAU,EAM1B,OAAO,GAAc,UAAY,IAAc,GACjD,MAAU,UACR,qEACE,OAAO,GAAc,SAAW,kBAAoB,OAAO,GAE/D,EAGF,GAAI,EAAI,oBAAoB,IAAI,CAAS,EACvC,MAAM,IAAI,EAAY,EAAW,kCAAmC,CAClE,QAAS,oCAAoC,EAAU,uCACzD,CAAC,EAKH,OAFA,EAAI,oBAAoB,IAAI,CAAS,EAE9B,CACL,MAAM,EAAc,EAAgB,CAO9B,IAAc,YAChB,OAAO,eAAe,EAAM,QAAS,EAAW,CAC9C,QACA,SAAU,GACV,WAAY,GACZ,aAAc,EAChB,CAAC,EAED,EAAM,QAAQ,GAAa,CAE/B,EACA,SAAU,CACR,EAAI,oBAAoB,OAAO,CAAS,CAC1C,CACF,CACF,CACF,EAIA,OAFA,EAAM,IAAI,EAAQ,CAAG,EAEd,CACT,CClQA,SAAgB,EAEd,EAA0D,CAC1D,IAAM,EAAM,EAAa,CAAM,EAEzB,EAAqB,EAAI,cAAc,CAAC,CAAC,mBAE/C,MAAO,CACL,iBAAiB,EAAM,EAAS,CAC9B,EAAgB,EAAI,UAAU,EAE9B,EAAI,WAAW,OAAO,kBAAkB,EAAM,kBAAkB,EAChE,EAAI,WAAW,UAAU,gBAAgB,EAAS,kBAAkB,EAKpE,EAAmB,eAAe,EAAM,CAAO,CACjD,EAEA,mBAAmB,EAAM,EAAS,CAChC,EAAgB,EAAI,UAAU,EAE9B,EAAI,WAAW,OAAO,kBAAkB,EAAM,oBAAoB,EAClE,EAAI,WAAW,UAAU,gBAAgB,EAAS,oBAAoB,EAEtE,EAAmB,iBAAiB,EAAM,CAAO,CACnD,EAEA,oBAAoB,EAAM,CACxB,EAAgB,EAAI,UAAU,EAE9B,EAAI,WAAW,OAAO,kBAAkB,EAAM,qBAAqB,EAInE,EAAmB,iBAAiB,EAAM,UAAU,CACtD,EAEA,sBAAsB,EAAM,CAC1B,EAAgB,EAAI,UAAU,EAE9B,EAAI,WAAW,OAAO,kBAAkB,EAAM,uBAAuB,EAIrE,EAAmB,mBAAmB,EAAM,UAAU,CACxD,CACF,CACF,CCoBA,SAAgB,EAGd,EACA,EAC2B,CAC3B,IAAM,EAAM,EAAa,CAAM,EAE/B,GAAI,EAAI,WAAW,EACjB,MAAM,IAAI,EAAY,EAAW,eAAe,EAGlD,EAAI,WAAW,aAAa,kBAAkB,CAAY,EAG1D,IAAM,EAAc,EAAI,cAAc,EAChC,EAASA,EAAuB,EAAY,IAAI,EAChD,EAAc,EAAY,OAC1B,EAAqB,EAAY,mBACjC,EAAoB,EAAY,kBAEhC,CACJ,UACA,aAAc,EACd,mBACE,EAAI,cAAc,EAOhB,CAAE,WAAY,EAAqB,SAAU,GADlB,EAAY,mBAElB,qBAAqB,EAO1C,EAAY,IAAIC,EACpB,EACA,EACA,CAPA,GAAG,EACH,GAAG,CAMM,CACX,EAEM,EAAS,EAAa,CAAS,EAC/B,EAAW,EAAO,cAAc,EAEhC,EAAwB,EAAS,mBAUvC,EAAoB,EAAS,OAAQ,CAAW,EAChD,OAAO,OAAO,EAAS,mBAAoB,CAAkB,EAC7D,OAAO,OAAO,EAAS,kBAAmB,CAAiB,EASvD,EAAY,WAAa,IAC3B,EAAO,YAAY,EAAY,QAAQ,EAGzC,GAAM,CAAC,EAAsB,GAAsB,EAC7C,CAAC,EAAoB,GAAoB,EAE/C,IAAK,GAAM,CAAC,EAAM,KAAY,OAAO,QAAQ,CAAoB,EAC/D,EAAsB,iBAAiB,EAAM,EAAS,EAAI,EAG5D,IAAK,GAAM,CAAC,EAAM,KAAY,OAAO,QAAQ,CAAkB,EAC7D,EAAsB,eAAe,EAAM,EAAS,EAAI,EAG1D,IAAM,EAAY,EAAgB,CAAS,EAE3C,IAAK,GAAM,CAAC,EAAM,KAAY,OAAO,QAAQ,CAAkB,EAC7D,EAAU,mBAAmB,EAAM,CAAO,EAG5C,IAAK,GAAM,CAAC,EAAM,KAAY,OAAO,QAAQ,CAAgB,EAC3D,EAAU,iBAAiB,EAAM,CAAO,EAO1C,IAAM,EAAoB,IAAI,IAAI,EAAO,cAAc,CAAC,CAAC,eAAe,EAClE,EAAkB,EAAgB,OACrC,GAAY,CAAC,EAAkB,IAAI,CAAO,CAC7C,EAOA,OAJI,EAAgB,OAAS,GAC3B,EAAU,UAAU,GAAG,CAAe,EAGjC,CACT"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=new WeakMap;function t(t){let n=e.get(t);if(!n)throw TypeError(`[real-router] Invalid router instance — not found in internals registry`);return n}function n(t,n){e.set(t,n)}function r(e,t,n){let r=t;for(let t of e){let e=r;r=(...n)=>t(e,...n)}return r(...n)}function i(e,t,n){return((...i)=>{let a=n.get(e);return!a||a.length===0?t(...i):r(a,t,i)})}function a(e,t,n){return(i,a)=>{let o=n.get(e);return!o||o.length===0?t(i,a):r(o,t,[i,a])}}function o(e,t){let n=e.path,r=n.startsWith(`~`),i=r?n.slice(1):n,a={name:e.name,path:i,absolute:r,children:[],parent:t};if(e.children)for(let t of e.children){let e=o(t,a);a.children.push(e)}return a}function s(e,t,n){let r=o({name:e,path:t},null);for(let e of n){let t=o(e,r);r.children.push(t)}return r}const c=`[^>]*`;function l(e){let t=!1;for(let n of e)if(n===`<`)t=!0;else if(n===`>`){if(!t)return!1;t=!1}return!t}const u=/[<>]/u,d=e=>e===58||e===42;function f(e){let t=[],n=0,r=!1;for(let i=0;i<e.length;i+=1){let a=e.charCodeAt(i);a===60?r=!0:a===62?r=!1:a===47&&!r&&(t.push(e.slice(n,i)),n=i+1)}return t.push(e.slice(n)),t}function p(e){let t=e.length;if(t===0)return{kind:`static`,text:``};if(!d(e.charCodeAt(0))){for(let n=0;n<t;n+=1){let r=e.charCodeAt(n);if(r===60)return{error:`constraint-in-static`};if(d(r)&&n+1<t&&e.charCodeAt(n+1)!==60)return{error:`fused-marker`}}return e.charCodeAt(t-1)===63?{error:`name-less`}:{kind:`static`,text:e}}let n=e.charCodeAt(0)===42,r=1;for(;r<t;){let t=e.charCodeAt(r);if(t===60||t===63)break;r+=1}let i=e.slice(1,r);if(i.length===0)return{error:`name-less`};if(d(i.charCodeAt(i.length-1)))return{error:`trailing-marker`};let a,o=!1;if(r<t)if(e.charCodeAt(r)===60){let n=e.indexOf(`>`,r+1);if(n===-1)return{error:`unbalanced-constraint`};if(n===r+1)return{error:`empty-constraint`};a=e.slice(r,n+1);let i=n+1;if(i<t)if(e.charCodeAt(i)===63)o=!0;else return{error:`fused-constraint-suffix`}}else o=!0;return n?o?{error:`optional-splat`}:{kind:`splat`,name:i}:a===void 0?{kind:`param`,name:i,optional:o}:{kind:`param`,name:i,constraint:a,optional:o}}function m(e){for(let t of f(e)){let e=p(t);if(`error`in e)return e.error}}function h(e){let t=f(e);for(let e=2;e<t.length;e+=1)if(t[e].startsWith(`*`)&&g(t[e-1])&&g(t[e-2]))return!0;return!1}function g(e){return e.startsWith(`:`)&&e.endsWith(`?`)}function ee(e){return`(${e.slice(1,-1)})`}function te(e,t){try{return RegExp(`^${ee(e)}$`)}catch{throw Error(`[buildParamMeta] Invalid constraint '${e}' on parameter '${t}': the body between '<' and '>' must be a valid regular expression (e.g. '<[0-9]+>', '<[a-z]+>').`)}}const ne=new RegExp(String.raw`([:*]${`[^/?<]+`}(?:<${c}>)?)\?(?=[/?]|$)`,`g`),re=RegExp(`<${c}>`,`g`),ie=/\?(.+)$/;function ae(e){return e.replaceAll(re,e=>`<${`x`.repeat(e.length-2)}>`).replaceAll(ne,`$1\0`)}const _=Object.freeze([]),v=Object.freeze({}),oe=new Map,se=Object.freeze({urlParams:_,queryParams:_,spatParams:_,paramTypeMap:v,constraintPatterns:oe,pathPattern:``});function ce(e,t,n,r,i){for(let a of f(e)){if(a.length===0)continue;let e=p(a);`error`in e||e.kind===`static`||(t.push(e.name),r[e.name]=`url`,e.kind===`splat`?n.push(e.name):e.constraint!==void 0&&i.set(e.name,{pattern:te(e.constraint,e.name),constraint:e.constraint}))}}function le(e){let t=[],n=[],r=[],i={},a=new Map,o=ie.exec(ae(e));if(o!==null){let t=e.slice(o.index+1).split(`&`);for(let e of t){let t=e.trim();t.length>0&&(n.push(t),i[t]=`query`)}e=e.slice(0,o.index)}return ce(e,t,r,i,a),ue(t,n,r,i,a,e)}function ue(e,t,n,r,i,a){return{urlParams:e.length===0?_:e,queryParams:t.length===0?_:t,spatParams:n.length===0?_:n,paramTypeMap:e.length===0&&t.length===0?v:r,constraintPatterns:i.size===0?oe:i,pathPattern:a}}const de=/[^\w!$'()*+,.:;|~-]/gu,fe=/[^\w!$'()*+,.:;|~-]/u,pe=/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g,y=e=>t=>{try{return e(t)}catch{return e(t.replaceAll(pe,`�`))}},me=y(e=>e.replaceAll(de,e=>encodeURIComponent(e))),b={default:e=>fe.test(e)?me(e):e,uri:y(encodeURI),uriComponent:y(encodeURIComponent),none:e=>e},he={default:decodeURIComponent,uri:decodeURI,uriComponent:decodeURIComponent,none:e=>e},ge=(e,t)=>{let n=b[t],r=String(e).split(`/`),i=n(r[0]);for(let e=1;e<r.length;e++)i+=`/`+n(r[e]);return i},x=Object.freeze(Object.create(null));function S(){return{staticChildren:x,hasChildren:!1,paramChild:void 0,splatChild:void 0,route:void 0,routeIsStrong:!1,slashChildRoute:void 0}}function C(e){return e.length>1&&e.endsWith(`/`)?e.slice(0,-1):e}function _e(e,t){return e===``?t:t===``?e:e+t}function w(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function ve(e){let t=0;for(;t<e.length;)if(e.codePointAt(t)===37){if(t+2>=e.length)return!1;let n=e.codePointAt(t+1)??0,r=e.codePointAt(t+2)??0;if(!w(n)||!w(r))return!1;t+=3}else t++;return!0}const ye=Object.freeze([]),T=Object.freeze(new Set),be=Object.freeze(new Map),xe=Object.freeze([]),Se=Object.freeze({}),Ce=Object.freeze({}),we=RegExp(`<${c}>`,`g`);function Te(e,t,n){let r=t.has(e.name);return{paramName:e.name,isOptional:e.kind===`param`?e.optional:!1,encoder:r?e=>ge(e,n):b[n]}}function Ee(e,t,n){let r=new Set,i=new Set;for(let e of t){for(let t of e.paramMeta.urlParams)r.add(t);for(let t of e.paramMeta.spatParams)i.add(t)}if(r.size===0)return{buildStaticParts:[e],buildParamSlots:xe};let a=[],o=[],s=``,c=f(e);for(let[e,t]of c.entries()){e>0&&(s+=`/`);let r=p(t);if(`error`in r||r.kind===`static`){s+=t;continue}a.push(s),s=``,o.push(Te(r,i,n))}return a.push(s),{buildStaticParts:a,buildParamSlots:o}}function E(e,t,n){throw Error(`[SegmentMatcher.registerTree] Parameter name conflict at the same path position: '${n}${e}' and '${n}${t}'. A parametric URL segment binds to a single name across every route that shares that position — the value cannot be captured under two names. Rename one so both routes agree (e.g. use '${n}${e}' in both).`)}function D(){throw Error(`[SegmentMatcher.registerTree] Empty parameter name: a parameter marker (':' or '*') or an optional '?' must be followed by a name (e.g. ':id', '*rest', ':id?'). A name-less marker or modifier would capture under an empty key at match but emit a literal at build — the two disagree, so it is rejected.`)}function De(e){throw Error(`[SegmentMatcher.registerTree] Fused parameter marker in segment "${e}": a ':'/'*' marker must begin a segment (e.g. 'a/:b', not 'a:b'). build extracts it as a param while the trie treats the segment as a literal — the two disagree.`)}function Oe(e){throw Error(`[SegmentMatcher.registerTree] Trailing parameter marker in segment "${e}": a param name cannot end in a bare ':' or '*' (e.g. ':y*' — the name is 'y' plus a stray marker). build/meta would capture the marker into the name while the gate rejects it as name-less — the two disagree, so it is rejected.`)}function ke(e){throw Error(`[SegmentMatcher.registerTree] Two optional params directly before a splat in "${e}": a single trie slot carries only one optional→splat fork, so the outer optional would overwrite the inner and the omit-outer/take-inner form would silently reshape into the splat. Split into separate routes, or drop the '?' on one.`)}function Ae(e){throw Error(`[SegmentMatcher.registerTree] Non-ASCII static segment "${e}": match rejects non-ASCII input and compares static keys raw, so this route would never match. Percent-encode it (e.g. "/caf%C3%A9") or use a param.`)}function je(e){throw Error(`[SegmentMatcher.registerTree] Optional splat "${e}" is not supported: a splat cannot be optional — build emits multi-segment URLs the matcher rejects. Use a required splat "*name".`)}function Me(e){throw Error(`[SegmentMatcher.registerTree] Optional param ":${e}?" before a splat must be constrained: an unconstrained optional before a splat is ambiguous (every multi-segment value has two readings). Add a constraint, e.g. ":${e}<[a-z]+>?", or model it as two routes.`)}function O(e){throw Error(`[SegmentMatcher.registerTree] Unbalanced constraint delimiter ('<' or '>') in path "${e}": every '<' must be closed by a '>'. A stray delimiter desyncs match vs build (buildPath would emit a URL match rejects).`)}function Ne(e){throw Error(`[SegmentMatcher.registerTree] Empty constraint '<>' in path "${e}": a constraint body must be non-empty (e.g. '<[0-9]+>'). An empty '<>' compiles to a never-matching pattern.`)}function Pe(e){throw Error(`[SegmentMatcher.registerTree] Text fused to a constraint '>' in path "${e}": a '<...>' constraint must end its segment or be followed by '/' or an optional '?' — use "/:id<...>/rest", not "/:id<...>rest".`)}function Fe(e){throw Error(`[SegmentMatcher.registerTree] Constraint '<...>' in a static segment in path "${e}": a '<...>' constraint must follow a parameter marker (':' or '*') — a static segment carrying '<...>' is silently stripped. Attach it to a param (e.g. "/:id<...>") or drop it.`)}function Ie(e,t,n){switch(e){case`name-less`:return D();case`trailing-marker`:return Oe(t);case`fused-marker`:return De(t);case`optional-splat`:return je(t);case`empty-constraint`:return Ne(n);case`fused-constraint-suffix`:return Pe(n);case`constraint-in-static`:return Fe(n);case`unbalanced-constraint`:return O(n)}}function Le(e,t){let n=new Set,r=``;for(let e of t){if(n.has(e)){r=e;break}n.add(e)}throw Error(`[SegmentMatcher.registerTree] Duplicate parameter name ':${r}' in route "${e}": a param name must be unique within a route — two positions cannot both bind ':${r}' (the second silently overwrites the first). Rename one.`)}function Re(e,t){throw Error(`[SegmentMatcher.registerTree] Invalid query-param declaration "${t}" in route "${e}": a query-param name cannot contain '<' or '>'. This is a reverse-order modifier typo that leaked a constraint into the query — put the optional '?' AFTER the constraint (':id<...>?', not ':id?<...>'). It would never round-trip.`)}function ze(e,t){throw Error(`[SegmentMatcher.registerTree] Name collision in route "${e}": "${t}" is declared as BOTH a path param (':${t}') and a query param ('?${t}'). buildPath would emit its value twice (once in the path, once in the query). Rename one.`)}function Be(e,t){throw Error(`[SegmentMatcher.registerTree] Duplicate route path: routes "${e}" and "${t}" resolve to the same URL. The later registration would silently shadow the earlier (its deep link would resolve to the other route). Give them distinct paths.`)}function Ve(e,t){throw Error(`[SegmentMatcher.registerTree] Index route "${e}" (path "/") under the dynamic parent "${t}" is not supported: the index cannot reliably replace the parent on every form of its path — under an optional param it binds only the present form, under a splat it is unreachable. Give the index a distinct path, or make the parent static.`)}function k(e){let t=p(e);return(`error`in t||t.kind===`static`)&&D(),t.name}function A(e,t,n){return e.paramChild?e.paramChild.name!==t&&!n.has(e)&&E(e.paramChild.name,t,`:`):(e.paramChild={node:S(),name:t,fork:void 0},n.add(e)),e.paramChild.node}function He(e,t,n,r,i,a){let o=t.constraintPatterns.get(n)?.pattern;if(e.paramChild&&e.splatChild){o===void 0&&Me(n),e.paramChild.fork={constraint:o};return}let s=i+1;if(s<=a){let t=r.indexOf(`/`,s),n=r.slice(s,t===-1?a:t);e.paramChild&&n.startsWith(`:`)&&!n.endsWith(`?`)&&(e.paramChild.fork={skipName:k(n)})}}function Ue(e,t,n){if(!t.hasConstraints||!n.startsWith(`:`)||e.paramChild===void 0)return;let r=t.constraintPatterns.get(k(n))?.pattern;if(r===void 0)return;let i=e.paramChild;i.fork?.constraint===void 0?i.fork={...i.fork,constraint:r}:i.fork.constraint.source!==r.source&&(i.fork={...i.fork,constraint:RegExp(`(?:${i.fork.constraint.source})|(?:${r.source})`,i.fork.constraint.flags)})}function We(e,t,n){return e.splatChild?e.splatChild.name!==t&&!n.has(e)&&E(e.splatChild.name,t,`*`):(e.splatChild={node:S(),name:t},n.add(e)),e.splatChild.node}function j(e,t){e.route!==void 0&&e.route!==t&&e.routeIsStrong===!0&&Be(e.route.name,t.name),e.route=t,e.routeIsStrong=!0}function Ge(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>=128)return!0;return!1}function Ke(e,t,n){let r=C(n);if(r===`/`){j(e.root,t);return}let i=new Set,a=new Map;M(e,e.root,r,1,t,i,a)}function M(e,t,n,r,i,a,o){let s=o.get(t);if(s===void 0)s=new Set,o.set(t,s);else if(s.has(r))return;s.add(r);let c=n.length;for(;r<=c;){let s=n.indexOf(`/`,r),l=s===-1?c:s,u=n.slice(r,l);if(u.endsWith(`?`)){let r=k(u);M(e,A(t,r,a),n,l+1,i,a,o),l>=c?t.route??=i:M(e,t,n,l+1,i,a,o),He(t,i,r,n,l,c);return}let d=t;t=N(e,t,u,a),Ue(d,i,u),r=l+1}j(t,i)}function qe(e,t,n){let r=n.slice(n.lastIndexOf(`/`)+1),i=n.split(`/`).some(e=>e.startsWith(`:`)&&e.endsWith(`?`)),a=r.startsWith(`*`);(i||a)&&Ve(t.name,n);let o=Je(e,n);o.slashChildRoute=t}function Je(e,t){return Ye(e,e.root,t)}function Ye(e,t,n){let r=C(n);if(r===`/`||r===``)return t;let i=t,a=1,o=r.length,s=new Set;for(;a<=o;){let t=r.indexOf(`/`,a),n=t===-1?o:t;if(n<=a)break;let c=r.slice(a,n);i=N(e,i,c,s),a=n+1}return i}function N(e,t,n,r){if(n.startsWith(`*`)){let e=We(t,k(n),r);return t.hasChildren=!0,e}if(n.startsWith(`:`)){let e=A(t,k(n),r);return t.hasChildren=!0,e}Ge(n)&&Ae(n);let i=e.options.caseSensitive?n:n.toLowerCase();return i in t.staticChildren||(t.staticChildren===x&&(t.staticChildren=Object.create(null)),t.staticChildren[i]=S(),t.hasChildren=!0),t.staticChildren[i]}function P(e,t,n,r,i){let a=t.fullName===``;a||r.push(t);let o=t.absolute,s=t.paramMeta===se?t.path:t.paramMeta.pathPattern,c=o&&s.startsWith(`~`)?s.slice(1):s,u=o?c:s;l(u)||O(u);for(let e of f(u)){let t=p(e);`error`in t&&Ie(t.error,e,u)}let d=u.replaceAll(we,``);h(u)&&ke(u);let m=o?d:_e(n,d),g=a?i:Xe(e,t,m,o?``:n,r,i);for(let n of t.children.values())P(e,n,m,r,g);a||r.pop()}function Xe(e,t,n,r,i,a){let o=tt(n,r),s=Object.freeze([...i]),c=Ze(s),l=C(n),u=nt(e.rootQueryParams,i),d=rt(i),{buildStaticParts:f,buildParamSlots:p}=Ee(o?C(r):l,o?i.slice(0,-1):i,e.options.urlParamsEncoding),m=p.map(e=>e.paramName),h=m.length===0?T:new Set(m);h.size!==m.length&&Le(t.fullName,m),it(t.fullName,u,h);let g={name:t.fullName,parent:a,matchSegments:s,meta:c,declaredQueryParams:u,declaredQueryParamsSet:u.length===0?T:new Set(u),hasTrailingSlash:n.length>1&&n.endsWith(`/`),constraintPatterns:d,hasConstraints:d.size>0,buildStaticParts:f,buildParamSlots:p,buildParamNamesSet:h,cachedResult:void 0};return t.paramMeta.urlParams.length===0&&(g.cachedResult=Object.freeze({segments:g.matchSegments,params:Se,meta:g.meta})),e.routesByName.set(t.fullName,g),o?$e(e,g,r):et(e,g,n,l,t),g}function Ze(e){let t;for(let n of e)Qe(n.paramTypeMap)&&(t??={},t[n.fullName]=n.paramTypeMap);return t===void 0?Ce:Object.freeze(t)}function Qe(e){for(let t in e)if(Object.hasOwn(e,t))return!0;return!1}function $e(e,t,n){qe(e,t,n);let r=C(n),i=e.options.caseSensitive?r:r.toLowerCase();e.staticCache.has(i)&&e.staticCache.set(i,t)}function et(e,t,n,r,i){if(Ke(e,t,n),i.paramMeta.urlParams.length===0){let n=e.options.caseSensitive?r:r.toLowerCase();e.staticCache.set(n,t)}}function tt(e,t){return C(e)===C(t)}function nt(e,t){let n=[];e.length>0&&n.push(...e);for(let e of t)e.paramMeta.queryParams.length>0&&n.push(...e.paramMeta.queryParams);return n.length===0?ye:n}function rt(e){let t=new Map;for(let n of e)for(let[e,r]of n.paramMeta.constraintPatterns)t.set(e,r);return t.size===0?be:t}function it(e,t,n){for(let r of t)u.test(r)&&Re(e,r),n.has(r)&&ze(e,r)}function at(e){return typeof e==`string`?e:typeof e==`object`?JSON.stringify(e):String(e)}function F(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0}):e[t]=n}var ot=class{get options(){return this.#e}#e;#t=S();#n=new Map;#r=new Map;#i={cleanPath:``,normalized:``,queryString:void 0};#a=[];#o=``;#s;#c;constructor(e){this.#e={caseSensitive:e.caseSensitive??!0,strictTrailingSlash:e.strictTrailingSlash??!1,strictQueryParams:e.strictQueryParams??!1,urlParamsEncoding:e.urlParamsEncoding??`default`,parseQueryString:e.parseQueryString,buildQueryString:e.buildQueryString},this.#s=this.#e.caseSensitive,this.#c=this.#e.urlParamsEncoding===`none`?null:he[this.#e.urlParamsEncoding]}registerTree(e){this.#a=e.paramMeta.queryParams,P({root:this.#t,options:this.#e,routesByName:this.#n,staticCache:this.#r,rootQueryParams:this.#a},e,``,[],null)}match(e){if(!this.#p(e))return;let{cleanPath:t,normalized:n,queryString:r}=this.#i,i=this.#s?n:n.toLowerCase(),a=this.#r.get(i);if(a)return this.#e.strictTrailingSlash&&!this.#_(t,a)?void 0:r===void 0&&a.cachedResult?a.cachedResult:this.#h(a,{},r);let o={},s=this.#v(n,o);if(s&&!(this.#e.strictTrailingSlash&&!this.#_(t,s))&&this.#S(o)&&!(s.hasConstraints&&!this.#w(o,s)))return this.#h(s,o,r)}buildPath(e,t,n){let r=this.#n.get(e);if(!r)throw Error(`[SegmentMatcher.buildPath] '${e}' is not defined`);r.hasConstraints&&t&&this.#l(r,e,t);let i=this.#u(r,t),a=this.#d(i,n?.trailingSlash),o=this.#f(r,t,n?.queryParamsMode);return a+(o?`?${o}`:``)}getSegmentsByName(e){return this.#n.get(e)?.matchSegments}getMetaByName(e){return this.#n.get(e)?.meta}hasRoute(e){return this.#n.has(e)}#l(e,t,n){for(let[r,i]of e.constraintPatterns){let e=n[r];if(e!=null){let n=typeof e==`object`?JSON.stringify(e):String(e);if(!i.pattern.test(n))throw Error(`[SegmentMatcher.buildPath] '${t}' — param '${r}' value '${n}' does not match constraint '${i.constraint}'`)}}}#u(e,t){let n=e.buildStaticParts,r=e.buildParamSlots;if(r.length===0)return n[0];let i=n[0];for(let[e,a]of r.entries()){let r=t?.[a.paramName];if(r==null){if(!a.isOptional)throw Error(`[SegmentMatcher.buildPath] Missing required param '${a.paramName}'`);i.length>1?i=i.slice(0,-1):n[e+1].startsWith(`/`)&&(i=``),i+=n[e+1];continue}if(r===``&&!a.isOptional)throw Error(`[SegmentMatcher.buildPath] Missing required param '${a.paramName}' (empty string)`);let o=a.encoder(at(r));i+=o+n[e+1]}return i}#d(e,t){return t===`always`&&!e.endsWith(`/`)?`${e}/`:t===`never`&&e!==`/`&&e.endsWith(`/`)?e.slice(0,-1):e}#f(e,t,n){if(!t||e.declaredQueryParams.length===0&&n!==`loose`)return``;let r={},i=!1;for(let n of e.declaredQueryParams)n in t&&(r[n]=t[n],i=!0);if(n===`loose`)for(let n in t)Object.hasOwn(t,n)&&!e.declaredQueryParamsSet.has(n)&&!e.buildParamNamesSet.has(n)&&(r[n]=t[n],i=!0);return i?this.#e.buildQueryString(r):``}#p(e){if(e===``&&(e=`/`),e.codePointAt(0)!==47)return!1;let t=this.#m(e);if(t===-2)return!1;t===-3&&(e=this.#o);let n=t>=0?e.slice(0,t):e,r=t>=0?e.slice(t+1):void 0;if(r!==void 0){let e=r.indexOf(`#`);e!==-1&&(r=r.slice(0,e))}let i=C(n);return this.#i.cleanPath=n,this.#i.normalized=i,this.#i.queryString=r,!0}#m(e){let t=!1;for(let n=0;n<e.length;n++){let r=e.codePointAt(n);if(r===35)return this.#o=e.slice(0,n),-3;if(r===63)return n;if(r>=128)return-2;if(r===47){if(t)return-2;t=!0}else t=!1}return-1}#h(e,t,n){if(!(n!==void 0&&!this.#g(e,t,n)))return{segments:e.matchSegments,params:t,meta:e.meta}}#g(e,t,n){let r;try{r=this.#e.parseQueryString(n)}catch{return!1}if(this.#e.strictQueryParams){let n=e.declaredQueryParamsSet;for(let e in r){if(!n.has(e))return!1;F(t,e,r[e])}}else for(let e in r)F(t,e,r[e]);return!0}#_(e,t){return(e.length>1&&e.endsWith(`/`))===t.hasTrailingSlash}#v(e,t){return e.length===1?this.#t.slashChildRoute??this.#t.route:this.#y(this.#t,e,1,t)}#y(e,t,n,r){let i=e,a=t.length,o=this.#s;for(;n<=a;){let e=t.indexOf(`/`,n),s=e===-1?a:e,c=t.slice(n,s),l=o?c:c.toLowerCase(),u;if(l in i.staticChildren)u=i.staticChildren[l];else if(i.paramChild){let e=i.paramChild,o=e.fork;if(i.splatChild!==void 0){if(o?.constraint!==void 0&&!this.#x(o.constraint,c))return this.#b(i.splatChild,t,n,r);let l={[o?.skipName!==void 0&&s>=a?o.skipName:e.name]:c},u=this.#y(e.node,t,s+1,l);return u!==void 0&&(!u.hasConstraints||this.#C(u,l))?(Object.assign(r,l),u):this.#b(i.splatChild,t,n,r)}u=e.node,o?.skipName!==void 0&&s>=a?r[o.skipName]=c:r[e.name]=c}else if(i.splatChild)return this.#b(i.splatChild,t,n,r);else return;i=u,n=s+1}return i.slashChildRoute??i.route}#b(e,t,n,r){let i=e.node;if(!i.hasChildren)return r[e.name]=t.slice(n),i.route;let a={},o=this.#y(i,t,n,a);return o&&(!o.hasConstraints||this.#C(o,a))?(Object.assign(r,a),o):(r[e.name]=t.slice(n),i.route)}#x(e,t){try{return e.test(this.#c?this.#c(t):t)}catch{return!1}}#S(e){let t=this.#c;if(!t)return!0;for(let n in e){let r=e[n];if(r.includes(`%`)){if(!ve(r))return!1;try{e[n]=t(r)}catch{return!1}}}return!0}#C(e,t){let n=this.#c;for(let[r,i]of e.constraintPatterns){if(!Object.hasOwn(t,r))continue;let e=t[r];if(n&&e.includes(`%`))try{e=n(e)}catch{return!1}if(!i.pattern.test(e))return!1}return!0}#w(e,t){for(let[n,r]of t.constraintPatterns)if(Object.hasOwn(e,n)&&!r.pattern.test(e[n]))return!1;return!0}};const st=Object.freeze(new Map),ct=Object.freeze([]);function lt(e){return e.parent?.name?`${e.parent.fullName}.${e.name}`:e.name}function ut(e){let t=new Map;for(let n of e)t.set(n.name,n);return t}function dt(e,t){let n=[],r=[];for(let i of e){let e=I(i,t);n.push(e),e.absolute||r.push(e)}return{childrenMap:ut(n),nonAbsoluteChildren:r}}function I(e,t){let n=le(e.path),r=n.urlParams.length===0&&n.queryParams.length===0&&n.spatParams.length===0&&n.constraintPatterns.size===0&&n.pathPattern===e.path?se:n,i=r.paramTypeMap,a={name:e.name,path:e.path,absolute:e.absolute,parent:t,children:void 0,paramMeta:r,nonAbsoluteChildren:void 0,fullName:``,paramTypeMap:i};if(a.fullName=lt(a),e.children.length===0)a.children=st,a.nonAbsoluteChildren=ct;else{let{childrenMap:t,nonAbsoluteChildren:n}=dt(e.children,a);a.children=t,a.nonAbsoluteChildren=n,Object.freeze(a.nonAbsoluteChildren),Object.freeze(a.children)}return Object.freeze(i),Object.freeze(r.urlParams),Object.freeze(r.queryParams),Object.freeze(r.spatParams),Object.freeze(r),Object.freeze(a),a}function ft(e){return I(e,null)}function pt(e,t,n){return ft(s(e,t,n))}function L(e){let t=e.absolute?`~${e.path}`:e.path,n={name:e.name,path:t};return e.children.size>0&&(n.children=Array.from(e.children.values(),L)),n}function mt(e){return Array.from(e.children.values(),L)}const R=e=>{let t=e.indexOf(`%`),n=e.indexOf(`+`);if(t===-1&&n===-1)return e;let r=n===-1?e:e.replaceAll(`+`,` `);return t===-1?r:decodeURIComponent(r)},z=(e,t)=>{if(e===void 0)return t.boolean.decodeUndefined();let n=t.boolean.decodeRaw(e);if(n!==null)return n;let r=R(e),i=t.number.decode(r);return i===null?t.boolean.decodeValue(r):i},ht=/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g,B=e=>{try{return encodeURIComponent(e)}catch(t){if(!(t instanceof URIError))throw t;return encodeURIComponent(String(e).replaceAll(ht,`�`))}},V=e=>{let t=typeof e;if(t!==`string`&&t!==`number`&&t!==`boolean`)throw TypeError(`[search-params] Array element must be a string, number, or boolean — received ${t}`);return B(e)},H=(e,t,n,r)=>{let i=`${e}${n}`,a=[];for(let e of t)if(e===null){let e=r.encode(i);e&&a.push(e)}else a.push(`${i}=${V(e)}`);return a.join(`&`)},U={none:{encodeArray:(e,t,n)=>H(e,t,``,n)},brackets:{encodeArray:(e,t,n)=>H(e,t,`[]`,n)},index:{encodeArray:(e,t,n)=>{let r=[];for(let[i,a]of t.entries()){let t=`${e}[${i}]`;if(a===null){let e=n.encode(t);e&&r.push(e)}else r.push(`${t}=${V(a)}`)}return r.join(`&`)},indexed:!0},comma:{encodeArray:(e,t)=>{let n=[];for(let e of t)e!==null&&n.push(V(e));return n.length===0?``:`${e}=${n.join(`,`)}`},decodeValue:e=>e.includes(`,`)?e.split(`,`):null}},W={none:{encode:(e,t)=>`${e}=${t}`,decodeUndefined:()=>null,decodeRaw:()=>null,decodeValue:e=>e},auto:{encode:(e,t)=>`${e}=${t}`,decodeUndefined:()=>null,decodeRaw:e=>e===`true`?!0:e===`false`?!1:null,decodeValue:e=>e},"empty-true":{encode:(e,t)=>t?e:`${e}=false`,decodeUndefined:()=>!0,decodeRaw:e=>e===`true`?!0:e===`false`?!1:null,decodeValue:e=>e}},G={default:{encode:e=>e},hidden:{encode:()=>``}},gt={auto:{decode:e=>{let t=e.length;if(t===0)return null;let n=+(e.codePointAt(0)===45);if(n===t||t-n>1&&e.codePointAt(n)===48&&e.codePointAt(n+1)!==46)return null;let r=!1;for(let i=n;i<t;i++){let a=e.codePointAt(i);if(!(a!==void 0&&a>=48&&a<=57)){if(a===46&&!r&&i!==n&&i!==t-1){r=!0;continue}return null}}let i=Number(e);return Object.is(i,-0)||!Number.isSafeInteger(i)&&!r?null:i}},none:{decode:()=>null}},K=(e,t,n,r)=>{if(e===void 0)throw TypeError(`[search-params] Unknown ${t} "${n}" — expected ${r}`);return e},_t=(e,t,n,r)=>({boolean:K(W[t],`booleanFormat`,t,`"none" | "auto" | "empty-true"`),null:K(G[n],`nullFormat`,n,`"default" | "hidden"`),number:K(gt[r],`numberFormat`,r,`"none" | "auto"`),array:K(U[e],`arrayFormat`,e,`"none" | "brackets" | "index" | "comma"`)}),vt={boolean:W.auto,null:G.default,number:gt.auto,array:U.none},q={arrayFormat:`none`,booleanFormat:`auto`,nullFormat:`default`,numberFormat:`auto`},yt={...q,strategies:vt},bt=e=>{if(!e||e.arrayFormat===void 0&&e.booleanFormat===void 0&&e.nullFormat===void 0&&e.numberFormat===void 0)return yt;let t=e.arrayFormat??q.arrayFormat,n=e.booleanFormat??q.booleanFormat,r=e.nullFormat??q.nullFormat,i=e.numberFormat??q.numberFormat;return{arrayFormat:t,booleanFormat:n,nullFormat:r,numberFormat:i,strategies:_t(t,n,r,i)}},J=e=>B(e),xt=(e,t,n)=>{let r=J(e);switch(typeof t){case`string`:case`number`:return`${r}=${J(t)}`;case`boolean`:return n.strategies.boolean.encode(r,t);case`object`:return t===null?n.strategies.null.encode(r):Array.isArray(t)?n.strategies.array.encodeArray(r,t,n.strategies.null):`${r}=${J(t)}`;default:return`${r}=${J(t)}`}};function Y(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0}):e[t]=n}function St(e,t,n,r){if(!Object.hasOwn(e,t)){Y(e,t,r?[n]:n);return}let i=e[t];Array.isArray(i)?i.push(n):Y(e,t,[i,n])}function Ct(e,t,n,r,i){return z(r?e.slice(t+1,n):void 0,i)}function wt(e,t,n){let r=t+1,i=0,a=!1;for(;r<n;){let t=e.codePointAt(r);if(t===93)return a?i:null;if(t!==void 0&&t>=48&&t<=57){i=i*10+(t-48),a=!0,r++;continue}return null}return null}function Tt(e,t,n){let{searchPart:r,nameEnd:i,nameSourceEnd:a,eqPos:o,end:s,hasValue:c,decodedName:l}=e,u=wt(r,i,a);if(u===null)return!1;let d=Ct(r,o,s,c,t),f=n.get(l);return f===void 0?n.set(l,[[u,d]]):f.push([u,d]),!0}function Et(e,t,n,r,i,a,o){let s=a!==-1&&a<n,c=s?a:n,l=c,u=!1;for(let n=t;n<c;n++)if(e.codePointAt(n)===91){l=n,u=!0;break}let d=R(e.slice(t,l));if(!(o!==void 0&&u&&Tt({searchPart:e,nameEnd:l,nameSourceEnd:c,eqPos:a,end:n,hasValue:s,decodedName:d},i,o))){if(!u&&s&&i.array.decodeValue){let t=e.slice(a+1,n),o=i.array.decodeValue(t);if(o){for(let e of o)St(r,d,z(e,i),!0);return}}St(r,d,Ct(e,a,n,s,i),u)}}const Dt=(e,t)=>{if(e===``||e===`?`)return{};let n={};return Ot(e,n,bt(t).strategies),n};function Ot(e,t,n){let r=n.array.indexed?new Map:void 0,i=0,a=e.length,o=-2;for(;i<a;){let s=e.indexOf(`&`,i);s===-1&&(s=a),s>i&&(o!==-1&&o<i&&(o=e.indexOf(`=`,i)),Et(e,i,s,t,n,o,r)),i=s+1}if(r!==void 0)for(let[e,n]of r)n.sort((e,t)=>e[0]-t[0]),Y(t,e,n.map(e=>e[1]))}const kt=(e,t)=>{let n=Object.keys(e);if(n.length===0)return``;let r=bt(t),i=[];for(let t of n){let n=e[t];if(n===void 0)continue;let a=xt(t,n,r);a&&i.push(a)}return i.join(`&`)};function At(e){let t=e?.queryParams;return new ot({...e?.caseSensitive!==void 0&&{caseSensitive:e.caseSensitive},...e?.strictTrailingSlash!==void 0&&{strictTrailingSlash:e.strictTrailingSlash},...e?.strictQueryParams!==void 0&&{strictQueryParams:e.strictQueryParams},...e?.urlParamsEncoding!==void 0&&{urlParamsEncoding:e.urlParamsEncoding},parseQueryString:e=>Dt(e,t),buildQueryString:e=>kt(e,t)})}function X(e,t){return TypeError(`[router.${e}] ${t}`)}function jt(e,t,n){if(!l(e))throw X(n,`Invalid path for route "${t}": unbalanced constraint delimiter ('<' or '>') in "${e}"`);if(e.includes(`<>`))throw X(n,`Invalid path for route "${t}": empty constraint '<>' in "${e}" (a constraint body must be non-empty, e.g. '<[0-9]+>')`)}function Mt(e,t,n,r){let i=new Set;for(let a of e){if(i.has(a))throw X(n,`Invalid path for route "${t}": duplicate parameter name ':${a}' in "${r}" (a param name must be unique within a route — the second binding would overwrite the first)`);i.add(a)}}function Nt(e,t,n,r,i){let a=new Set(e);for(let e of t){if(u.test(e))throw X(r,`Invalid path for route "${n}": invalid query-param name "${e}" in "${i}" (a query-param name cannot contain '<' or '>' — a reverse-order modifier typo that leaked a constraint into the query; put the optional '?' after the constraint, ':id<...>?')`);if(a.has(e))throw X(r,`Invalid path for route "${n}": "${e}" is declared as both a path param and a query param in "${i}" — buildPath would emit its value twice (rename one)`)}}function Pt(e){let t=!0,n=!1,r=!1;for(let i of e){if(r){r=i!==`>`;continue}if(i===`<`){r=!0;continue}if(i===`/`){t=!0;continue}if(t&&=(n=i===`:`||i===`*`,!1),!n&&i.codePointAt(0)>=128)return!0}return!1}function Ft(e){for(let t=1;t<e.length;t++)if(e[t]===`?`&&e[t-1]!==`>`&&e[t+1]===`/`&&e[t+2]===`*`)return!0;return!1}function It(e,t,n,r){if(h(e))throw X(r,`Invalid path for route "${t}": two optional params directly before a splat are not supported in "${n}" — a single trie slot carries one optional→splat fork, so the omit-outer/take-inner form would silently reshape into the splat. Split into two routes, or drop the '?' on one`);if(Ft(e))throw X(r,`Invalid path for route "${t}": an unconstrained optional param before a splat is not supported in "${n}" — it is ambiguous (every multi-segment value has two readings). Add a constraint (e.g. ':lang<[a-z]+>?') or model it as two routes`)}function Lt(e,t,n){switch(e){case`name-less`:case`trailing-marker`:return`Invalid path for route "${t}": parameter marker (':' or '*') without a name in "${n}"`;case`fused-marker`:return`Invalid path for route "${t}": parameter marker (':' or '*') must begin a segment, but "${n}" fuses one to a static prefix (use a boundary marker like "/a/:b")`;case`fused-constraint-suffix`:return`Invalid path for route "${t}": text fused to a constraint '>' in "${n}" (a '<...>' must end its segment or be followed by '/' or an optional '?' — use "/:id<...>/rest", not "/:id<...>rest")`;case`constraint-in-static`:return`Invalid path for route "${t}": constraint '<...>' in a static segment in "${n}" (a '<...>' must follow a parameter marker ':' or '*' — attach it to a param like "/:id<...>", or drop it)`;case`optional-splat`:return`Invalid path for route "${t}": optional splat ('*name?') is not supported in "${n}" — a splat cannot be optional (use a required splat '*name')`;case`unbalanced-constraint`:case`empty-constraint`:return`Invalid path for route "${t}": invalid constraint in "${n}"`}}function Rt(e,t,n){try{return le(e)}catch(r){throw X(n,`Invalid path for route "${t}": ${(r instanceof Error?r.message:String(r)).replace(/^\[buildParamMeta] /,``)} (in "${e}")`)}}function zt(e,t,n,r){if(typeof e!=`string`){let t;throw t=e===null?`null`:Array.isArray(e)?`array`:typeof e,X(n,`Route path must be a string, got ${t}`)}if(e===``)return;if(/\s/.test(e))throw X(n,`Invalid path for route "${t}": whitespace not allowed in "${e}"`);if(!/^([/?~]|[^/]+$)/.test(e))throw X(n,`Route "${t}" has invalid path format: "${e}". Path should start with '/', '~', '?' or be a relative segment.`);if(e.includes(`//`))throw X(n,`Invalid path for route "${t}": double slashes not allowed in "${e}"`);jt(e,t,n);let{pathPattern:i,urlParams:a,queryParams:o}=Rt(e,t,n);Mt(a,t,n,e),Nt(a,o,t,n,e);let s=m(i);if(s!==void 0)throw X(n,Lt(s,t,e));if(It(i,t,e,n),Pt(i))throw X(n,`Invalid path for route "${t}": non-ASCII static segment in "${e}" — match compares static segments raw and rejects non-ASCII input, so this route would never match. Percent-encode it (e.g. '/caf%C3%A9') or use a param`);let c=r&&r.paramMeta.urlParams.length>0;if(e.startsWith(`~`)&&c)throw X(n,`Absolute path "${e}" cannot be used under parent route with URL parameters`)}const Bt=/^[A-Z_a-z][\w-]*$/,Vt=/\S/,Ht=1e4;function Z(e){if(e===null)return`null`;if(typeof e==`object`){try{let t=e.constructor;if(typeof t==`function`&&t.name!==`Object`)return t.name||`object`}catch{}return`object`}return typeof e}function Ut(e){for(let t of Object.keys(e)){let n=Object.getOwnPropertyDescriptor(e,t);if(n&&(n.get||n.set))return!0}return!1}function Wt(e,t){if(!e||typeof e!=`object`)throw TypeError(`[router.${t}] Route must be an object, got ${Z(e)}`);let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw TypeError(`[router.${t}] Route must be a plain object, got ${Z(e)}`);if(Ut(e))throw TypeError(`[router.${t}] Route must not have getters or setters`)}function Gt(e,t){if(e.encodeParams!==void 0&&typeof e.encodeParams!=`function`)throw TypeError(`[router.${t}] Route "${String(e.name)}" encodeParams must be a function`)}function Kt(e,t){if(e.decodeParams!==void 0&&typeof e.decodeParams!=`function`)throw TypeError(`[router.${t}] Route "${String(e.name)}" decodeParams must be a function`)}function qt(e,t){if(typeof e.name!=`string`)throw TypeError(`[router.${t}] Route name must be a string, got ${Z(e.name)}`);let n=e.name;if(n===``)throw TypeError(`[router.${t}] Route name cannot be empty`);if(!Vt.test(n))throw TypeError(`[router.${t}] Route name cannot contain only whitespace`);if(n.length>Ht)throw TypeError(`[router.${t}] Route name exceeds maximum length of ${Ht} characters`);if(!n.startsWith(`@@`)){if(n.includes(`.`))throw TypeError(`[router.${t}] Route name "${n}" cannot contain dots. Use children array or { parent } option in addRoute() instead.`);if(!Bt.test(n))throw TypeError(`[router.${t}] Invalid route name "${n}". Name must start with a letter or underscore, followed by letters, numbers, underscores, or hyphens.`)}}function Q(e,t){if(!t.includes(`.`))return e.children.get(t);let n=e;for(let e of t.split(`.`))if(n=n.children.get(e),!n)return;return n}function Jt(e,t,n){if(Q(e,t))throw Error(`[router.${n}] Route "${t}" already exists`)}function Yt(e,t,n){if(e.has(t))throw Error(`[router.${n}] Duplicate route "${t}" in batch`);e.add(t)}function Xt(e,t,n,r){let i=t===``?e:Q(e,t);if(i){for(let e of i.children.values())if(e.path===n)throw Error(`[router.${r}] Path "${n}" is already defined`)}}function Zt(e,t,n,r){let i=e.get(t);if(i?.has(n))throw Error(`[router.${r}] Path "${n}" is already defined`);i?i.add(n):e.set(t,new Set([n]))}function $(e,t,n,r=``,i,a){Wt(e,t);let o=e;qt(o,t),zt(o.path,o.name,t,n),Gt(o,t),Kt(o,t);let s=o.name,c=r?`${r}.${s}`:s;n&&c&&Jt(n,c,t),i&&Yt(i,c,t);let l=o.path,u=r;if(n&&Xt(n,u,l,t),a&&Zt(a,u,l,t),o.children!==void 0){if(!Array.isArray(o.children))throw TypeError(`[router.${t}] Route "${s}" children must be an array, got ${Z(o.children)}`);for(let e of o.children)$(e,t,n,c,i,a)}}export{mt as a,i as c,L as i,t as l,q as n,pt as o,$ as r,a as s,At as t,n as u};
|
|
2
|
-
//# sourceMappingURL=esm-Cnywzxys.mjs.map
|