@real-router/core 0.52.0 → 0.54.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -10
- package/dist/cjs/Router-CJihdrWA.d.ts +67 -0
- package/dist/cjs/Router-CJihdrWA.d.ts.map +1 -0
- package/dist/cjs/Router-D8Awa7bY.js +6 -0
- package/dist/cjs/Router-D8Awa7bY.js.map +1 -0
- package/dist/cjs/RouterError-Bm9YnZ6e.d.ts +310 -0
- package/dist/cjs/RouterError-Bm9YnZ6e.d.ts.map +1 -0
- package/dist/cjs/api.d.ts +2 -1
- 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/cloneRouter-q-jHlBiv.js +2 -0
- package/dist/cjs/cloneRouter-q-jHlBiv.js.map +1 -0
- package/dist/cjs/index-8oPDJBQc.d.ts +306 -0
- package/dist/cjs/index-8oPDJBQc.d.ts.map +1 -0
- package/dist/cjs/{Router-DrBkBdZ5.d.ts → index-EwbhzRQw.d.ts} +4 -69
- package/dist/cjs/index-EwbhzRQw.d.ts.map +1 -0
- package/dist/cjs/index.d.ts +4 -197
- 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/{internals-na15rxo_.js → internals-CM6oaz9n.js} +1 -1
- package/dist/cjs/internals-CM6oaz9n.js.map +1 -0
- package/dist/cjs/utils.d.ts +2 -91
- package/dist/cjs/utils.js +1 -1
- package/dist/cjs/utils.js.map +1 -1
- package/dist/cjs/validation.d.ts +55 -44
- package/dist/cjs/validation.d.ts.map +1 -1
- package/dist/cjs/validation.js +1 -1
- package/dist/esm/Router-BeMyxy_V.mjs +6 -0
- package/dist/esm/Router-BeMyxy_V.mjs.map +1 -0
- package/dist/esm/Router-BmhiDQUJ.d.mts +67 -0
- package/dist/esm/Router-BmhiDQUJ.d.mts.map +1 -0
- package/dist/esm/RouterError-hhfSVGtY.d.mts +310 -0
- package/dist/esm/RouterError-hhfSVGtY.d.mts.map +1 -0
- package/dist/esm/api.d.mts +2 -1
- 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/cloneRouter-C_ULpzHM.mjs +2 -0
- package/dist/esm/cloneRouter-C_ULpzHM.mjs.map +1 -0
- package/dist/esm/{Router-BeXr2zW4.d.mts → index-DNjaY7KH.d.mts} +4 -69
- package/dist/esm/index-DNjaY7KH.d.mts.map +1 -0
- package/dist/esm/index-r_JTvSBH.d.mts +306 -0
- package/dist/esm/index-r_JTvSBH.d.mts.map +1 -0
- package/dist/esm/index.d.mts +4 -197
- 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/{internals-CCymabFj.mjs → internals-C59msvHY.mjs} +1 -1
- package/dist/esm/internals-C59msvHY.mjs.map +1 -0
- package/dist/esm/utils.d.mts +2 -91
- package/dist/esm/utils.mjs +1 -1
- package/dist/esm/utils.mjs.map +1 -1
- package/dist/esm/validation.d.mts +56 -43
- package/dist/esm/validation.d.mts.map +1 -1
- package/dist/esm/validation.mjs +1 -1
- package/package.json +1 -1
- package/src/Router.ts +13 -16
- package/src/api/getDependenciesApi.ts +3 -11
- package/src/api/getPluginApi.ts +3 -3
- package/src/api/getRoutesApi.ts +4 -2
- package/src/internals.ts +13 -1
- package/src/namespaces/DependenciesNamespace/dependenciesStore.ts +1 -1
- package/src/namespaces/NavigationNamespace/NavigationNamespace.ts +8 -4
- package/src/namespaces/NavigationNamespace/transition/completeTransition.ts +4 -0
- package/src/namespaces/RoutesNamespace/RoutesNamespace.ts +3 -3
- package/src/namespaces/StateNamespace/StateNamespace.ts +2 -2
- package/src/utils/createRequestScope.ts +174 -0
- package/src/utils/hydrateRouter.ts +68 -12
- package/src/utils/index.ts +17 -1
- package/src/utils/serializeRouterState.ts +51 -4
- package/src/utils/serializeState.ts +46 -5
- package/dist/cjs/Router-DrBkBdZ5.d.ts.map +0 -1
- package/dist/cjs/Router-Pztue5fk.js +0 -6
- package/dist/cjs/Router-Pztue5fk.js.map +0 -1
- package/dist/cjs/RouterError-BmvAyBlx.js +0 -2
- package/dist/cjs/RouterError-BmvAyBlx.js.map +0 -1
- package/dist/cjs/RouterValidator-DLy_W2du.d.ts +0 -114
- package/dist/cjs/RouterValidator-DLy_W2du.d.ts.map +0 -1
- package/dist/cjs/getPluginApi-CUcFDzuA.js +0 -2
- package/dist/cjs/getPluginApi-CUcFDzuA.js.map +0 -1
- package/dist/cjs/internals-na15rxo_.js.map +0 -1
- package/dist/cjs/utils.d.ts.map +0 -1
- package/dist/esm/Router-BeXr2zW4.d.mts.map +0 -1
- package/dist/esm/Router-CK8U23pP.mjs +0 -6
- package/dist/esm/Router-CK8U23pP.mjs.map +0 -1
- package/dist/esm/RouterError-D-Zjbdv9.mjs +0 -2
- package/dist/esm/RouterError-D-Zjbdv9.mjs.map +0 -1
- package/dist/esm/RouterValidator-C-PvV00i.d.mts +0 -114
- package/dist/esm/RouterValidator-C-PvV00i.d.mts.map +0 -1
- package/dist/esm/getPluginApi-CsTfDB-O.mjs +0 -2
- package/dist/esm/getPluginApi-CsTfDB-O.mjs.map +0 -1
- package/dist/esm/internals-CCymabFj.mjs.map +0 -1
- package/dist/esm/utils.d.mts.map +0 -1
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { t as Router$1 } from "./Router-CJihdrWA.js";
|
|
2
|
+
import { DefaultDependencies, Params, Router, State } from "@real-router/types";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/createRequestScope.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Subset of Node's `http.IncomingMessage` that `createRequestScope` relies on:
|
|
7
|
+
* a `"close"` event indicating that the client disconnected (or the response
|
|
8
|
+
* was fully sent) and the standard `removeListener` cleanup hook.
|
|
9
|
+
*/
|
|
10
|
+
interface IncomingMessageLike {
|
|
11
|
+
on: (event: "close", listener: () => void) => unknown;
|
|
12
|
+
removeListener?: (event: "close", listener: () => void) => unknown;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Web `Request`-shaped object — anything carrying an `AbortSignal`. Web
|
|
16
|
+
* runtimes (Bun, Cloudflare Workers, Vite RSC) surface client-disconnect via
|
|
17
|
+
* `request.signal` directly, so no listener attachment is needed.
|
|
18
|
+
*/
|
|
19
|
+
interface RequestLike {
|
|
20
|
+
signal: AbortSignal;
|
|
21
|
+
}
|
|
22
|
+
type RequestScopeSource = IncomingMessageLike | RequestLike;
|
|
23
|
+
interface RequestScope<Dependencies extends DefaultDependencies = DefaultDependencies> extends AsyncDisposable {
|
|
24
|
+
/**
|
|
25
|
+
* Per-request router clone. Carries `abortSignal` injected into its
|
|
26
|
+
* dependencies — loaders can `getDep("abortSignal")` and pass it to fetch /
|
|
27
|
+
* `withTimeout` for cooperative cancellation when the client disconnects.
|
|
28
|
+
*/
|
|
29
|
+
readonly router: Router$1<Dependencies>;
|
|
30
|
+
/**
|
|
31
|
+
* Aborts when the request closes (Node `IncomingMessage`'s `"close"` event)
|
|
32
|
+
* or when the upstream Web `Request.signal` aborts.
|
|
33
|
+
*/
|
|
34
|
+
readonly signal: AbortSignal;
|
|
35
|
+
/**
|
|
36
|
+
* Detach the close listener (if attached to a Node `IncomingMessage`) and
|
|
37
|
+
* dispose the cloned router. Idempotent — safe to call multiple times or in
|
|
38
|
+
* combination with `Symbol.asyncDispose`.
|
|
39
|
+
*/
|
|
40
|
+
dispose: () => Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Build a per-request router scope: clones `base`, attaches an `AbortSignal`
|
|
44
|
+
* tied to the request's lifetime, and exposes `dispose()` (plus
|
|
45
|
+
* `Symbol.asyncDispose` for `await using` declarations).
|
|
46
|
+
*
|
|
47
|
+
* Replaces the four-step boilerplate that every server entry repeats:
|
|
48
|
+
*
|
|
49
|
+
* 1. `new AbortController()` per request
|
|
50
|
+
* 2. `req.on("close", () => controller.abort())`
|
|
51
|
+
* 3. `cloneRouter(base, { ...deps, abortSignal: signal })`
|
|
52
|
+
* 4. `try { ... } finally { router.dispose() }`
|
|
53
|
+
*
|
|
54
|
+
* The signal is injected into the router clone under `abortSignal` so existing
|
|
55
|
+
* loaders that read `getDep("abortSignal")` keep working without changes.
|
|
56
|
+
*
|
|
57
|
+
* ## `await using` compatibility
|
|
58
|
+
*
|
|
59
|
+
* The scope implements `Symbol.asyncDispose`, so `await using scope = …` is
|
|
60
|
+
* supported on runtimes that ship the well-known `Symbol.asyncDispose`:
|
|
61
|
+
*
|
|
62
|
+
* - **Node.js 24+** (full support; partial in 20.4–20.17 only for `fs`/`stream`)
|
|
63
|
+
* - **Bun 1.0.23+**, **Deno 1.37+**
|
|
64
|
+
* - **Chrome / Edge 127+**, **Firefox 141+**
|
|
65
|
+
* - **Safari**: not yet supported (irrelevant in practice — this helper is
|
|
66
|
+
* server-side only and never reaches the browser)
|
|
67
|
+
*
|
|
68
|
+
* On Node.js 22 LTS the well-known symbol is unavailable, so `await using`
|
|
69
|
+
* fails. **The bundled SSR examples therefore use the explicit
|
|
70
|
+
* `try/finally` + `await scope.dispose()` form**, which works on every
|
|
71
|
+
* runtime. Use `await using` only when you control the deployment target and
|
|
72
|
+
* know it ships the symbol.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* // Explicit dispose — works on Node 18+, all browsers, every CI image
|
|
77
|
+
* export async function render(url: string, req: IncomingMessage) {
|
|
78
|
+
* const scope = createRequestScope(req, baseRouter, { currentUser });
|
|
79
|
+
* try {
|
|
80
|
+
* scope.router.usePlugin(ssrDataPluginFactory(loaders));
|
|
81
|
+
* return await renderShell(scope.router, url);
|
|
82
|
+
* } finally {
|
|
83
|
+
* await scope.dispose();
|
|
84
|
+
* }
|
|
85
|
+
* }
|
|
86
|
+
*
|
|
87
|
+
* // `await using` — Node 24+, Bun, Deno, modern browsers
|
|
88
|
+
* export async function render(url: string, req: IncomingMessage) {
|
|
89
|
+
* await using scope = createRequestScope(req, baseRouter, { currentUser });
|
|
90
|
+
* scope.router.usePlugin(ssrDataPluginFactory(loaders));
|
|
91
|
+
* return await renderShell(scope.router, url);
|
|
92
|
+
* }
|
|
93
|
+
*
|
|
94
|
+
* // Web runtime (signal already on the request)
|
|
95
|
+
* async function handler(request: Request) {
|
|
96
|
+
* const scope = createRequestScope(request, baseRouter, { db });
|
|
97
|
+
* try {
|
|
98
|
+
* scope.router.usePlugin(rscServerPluginFactory(loaders));
|
|
99
|
+
* return await render(scope.router, request.url);
|
|
100
|
+
* } finally {
|
|
101
|
+
* await scope.dispose();
|
|
102
|
+
* }
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function createRequestScope<Dependencies extends DefaultDependencies = DefaultDependencies>(request: RequestScopeSource, base: Router<Dependencies>, deps?: Partial<Dependencies>): RequestScope<Dependencies>;
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/utils/getStaticPaths.d.ts
|
|
109
|
+
type StaticPathEntries = Record<string, () => Promise<Record<string, string>[]>>;
|
|
110
|
+
declare function getStaticPaths<Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router<Dependencies>, entries?: StaticPathEntries): Promise<string[]>;
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/utils/hydrateRouter.d.ts
|
|
113
|
+
/**
|
|
114
|
+
* Custom deserializer signature for {@link hydrateRouter} (#606). Compatible
|
|
115
|
+
* with `JSON.parse` (default), `devalue.parse`, `superjson.parse`, or any
|
|
116
|
+
* user-supplied function.
|
|
117
|
+
*/
|
|
118
|
+
type Deserialize = (json: string) => unknown;
|
|
119
|
+
interface HydrateRouterOptions {
|
|
120
|
+
/**
|
|
121
|
+
* Custom deserializer (e.g., `devalue.parse` / `superjson.parse`) for
|
|
122
|
+
* matching the `serialize` passed to {@link serializeRouterState}. Defaults
|
|
123
|
+
* to `JSON.parse`. Ignored when `source` is already an object.
|
|
124
|
+
*
|
|
125
|
+
* @default JSON.parse
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* import * as devalue from "devalue";
|
|
130
|
+
* await hydrateRouter(router, ssrJson, { deserialize: devalue.parse });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
deserialize?: Deserialize;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Hydrate a fresh router from server-serialized State (#563, #596).
|
|
137
|
+
*
|
|
138
|
+
* Accepts either a JSON string (parsed via `JSON.parse` by default, or
|
|
139
|
+
* `options.deserialize` when provided) or a State-shaped object. Extracts
|
|
140
|
+
* `state.path` and delegates to `router.start(state.path)` — the canonical
|
|
141
|
+
* URL is the source of truth for the router on hydration.
|
|
142
|
+
*
|
|
143
|
+
* The full parsed state (incl. `state.context.<namespace>` payloads) is
|
|
144
|
+
* deposited into a one-shot scratchpad on `RouterInternals.hydrationState`
|
|
145
|
+
* before `start()` is invoked and cleared in the matching `finally`. SSR
|
|
146
|
+
* loader plugins (`@real-router/ssr-data-plugin`,
|
|
147
|
+
* `@real-router/rsc-server-plugin`) read this scratchpad to skip their loader
|
|
148
|
+
* call when the server-resolved namespace value is already present — avoiding
|
|
149
|
+
* the post-hydration loader re-run on first paint.
|
|
150
|
+
*
|
|
151
|
+
* Single-shot semantics: the scratchpad is consumed during the first `start()`
|
|
152
|
+
* triggered by `hydrateRouter` regardless of route mismatch; subsequent
|
|
153
|
+
* `start()` calls run loaders normally.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* // Client
|
|
158
|
+
* const router = createAppRouter();
|
|
159
|
+
* router.usePlugin(browserPluginFactory());
|
|
160
|
+
* await hydrateRouter(router, window.__SSR_STATE__);
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* // With non-JSON types (Date / Map / Set / RegExp / BigInt) via devalue (#606)
|
|
166
|
+
* import * as devalue from "devalue";
|
|
167
|
+
*
|
|
168
|
+
* await hydrateRouter(router, window.__SSR_STATE__, {
|
|
169
|
+
* deserialize: devalue.parse,
|
|
170
|
+
* });
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
declare function hydrateRouter(router: Router, source: string | {
|
|
174
|
+
path: string;
|
|
175
|
+
}, options?: HydrateRouterOptions): Promise<State>;
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/utils/serializeState.d.ts
|
|
178
|
+
/**
|
|
179
|
+
* Custom serializer signature for {@link serializeState} (#606).
|
|
180
|
+
*
|
|
181
|
+
* Compatible with `JSON.stringify` (default) as well as `devalue.stringify`,
|
|
182
|
+
* `superjson.stringify`, or any user-supplied function that returns a JSON
|
|
183
|
+
* string. The output is run through XSS-safe character escapes regardless
|
|
184
|
+
* of which serializer produced it.
|
|
185
|
+
*/
|
|
186
|
+
type Serialize = (data: unknown) => string;
|
|
187
|
+
interface SerializeStateOptions {
|
|
188
|
+
/**
|
|
189
|
+
* Custom serializer (e.g., `devalue.stringify` / `superjson.stringify`) to
|
|
190
|
+
* support non-JSON types (Date / Map / Set / RegExp / BigInt). Defaults to
|
|
191
|
+
* `JSON.stringify`. Output is still XSS-escaped.
|
|
192
|
+
*
|
|
193
|
+
* @default JSON.stringify
|
|
194
|
+
*/
|
|
195
|
+
serialize?: Serialize;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* XSS-safe JSON serialization for embedding data in HTML `<script>` tags.
|
|
199
|
+
*
|
|
200
|
+
* Escapes `<`, `>`, and `&` to their Unicode equivalents to prevent
|
|
201
|
+
* injection via `</script>` or HTML entities inside inline scripts.
|
|
202
|
+
*
|
|
203
|
+
* Pass `options.serialize` to use a custom serializer such as `devalue` or
|
|
204
|
+
* `superjson` for non-JSON types (Date/Map/Set/RegExp/BigInt). The serializer
|
|
205
|
+
* must return a string; XSS-escape is applied to its output.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const json = serializeState({ name: "home", path: "/" });
|
|
210
|
+
* const html = `<script>window.__STATE__=${json}</script>`;
|
|
211
|
+
* ```
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* import * as devalue from "devalue";
|
|
216
|
+
*
|
|
217
|
+
* const json = serializeState(
|
|
218
|
+
* { date: new Date(), tags: new Set(["a", "b"]) },
|
|
219
|
+
* { serialize: devalue.stringify },
|
|
220
|
+
* );
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
declare function serializeState(data: unknown, options?: SerializeStateOptions): string;
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/utils/serializeRouterState.d.ts
|
|
226
|
+
/**
|
|
227
|
+
* Parsed shape produced by {@link serializeRouterState} (after `JSON.parse`).
|
|
228
|
+
*
|
|
229
|
+
* Identical to {@link State} minus `transition` (per-navigation `TransitionMeta`
|
|
230
|
+
* is meaningless after hydration; the client builds its own on commit). Used as
|
|
231
|
+
* the input shape for {@link hydrateRouter} and as the type of the one-shot
|
|
232
|
+
* hydration scratchpad consumed by SSR loader plugins.
|
|
233
|
+
*/
|
|
234
|
+
type SerializedRouterState<P extends Params = Params> = Omit<State<P>, "transition">;
|
|
235
|
+
interface SerializeRouterStateOptions {
|
|
236
|
+
/**
|
|
237
|
+
* Plugin context namespaces to strip from the serialized output.
|
|
238
|
+
* Use when a plugin populates `state.context.<ns>` with non-JSON-serializable
|
|
239
|
+
* values (e.g., RSC payload: ReactNode trees containing functions/symbols).
|
|
240
|
+
*
|
|
241
|
+
* @default []
|
|
242
|
+
*/
|
|
243
|
+
excludeContext?: readonly string[];
|
|
244
|
+
/**
|
|
245
|
+
* Custom serializer (e.g., `devalue.stringify` / `superjson.stringify`) to
|
|
246
|
+
* support non-JSON types in `state.params` and `state.context.<ns>` payloads
|
|
247
|
+
* (Date / Map / Set / RegExp / BigInt). Defaults to `JSON.stringify`.
|
|
248
|
+
*
|
|
249
|
+
* Pair with the matching `deserialize` on `hydrateRouter` to round-trip the
|
|
250
|
+
* extended types on the client.
|
|
251
|
+
*
|
|
252
|
+
* @default JSON.stringify
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* import * as devalue from "devalue";
|
|
257
|
+
*
|
|
258
|
+
* const json = serializeRouterState(state, { serialize: devalue.stringify });
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
serialize?: Serialize;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* XSS-safe JSON serialization of router State for SSR → client transport (#563).
|
|
265
|
+
*
|
|
266
|
+
* Strips `state.transition` (per-navigation `TransitionMeta` — meaningless after
|
|
267
|
+
* hydration; the client's hydration commit produces its own `transition`).
|
|
268
|
+
* Keeps `name`, `params`, `path`, and `context` (plugin context namespaces are
|
|
269
|
+
* preserved as-is — server's `state.context.data` from `ssr-data-plugin` and
|
|
270
|
+
* any other plugin claims travel to the client untouched).
|
|
271
|
+
*
|
|
272
|
+
* Pass `options.excludeContext` to strip specific namespaces from the output —
|
|
273
|
+
* required for plugins that publish non-JSON-serializable values (e.g., RSC
|
|
274
|
+
* `ReactNode` trees from `@real-router/rsc-server-plugin`).
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```typescript
|
|
278
|
+
* // Server
|
|
279
|
+
* const state = await router.start(req.url);
|
|
280
|
+
* const html = `<script>window.__SSR_STATE__=${serializeRouterState(state)}</script>`;
|
|
281
|
+
*
|
|
282
|
+
* // Client
|
|
283
|
+
* await hydrateRouter(router, window.__SSR_STATE__);
|
|
284
|
+
* ```
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```typescript
|
|
288
|
+
* // With RSC plugin: strip the "rsc" namespace before transport
|
|
289
|
+
* const state = await router.start(url);
|
|
290
|
+
* const json = serializeRouterState(state, { excludeContext: ["rsc"] });
|
|
291
|
+
* ```
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```typescript
|
|
295
|
+
* // Non-JSON types (Date / Map / Set / RegExp / BigInt) via devalue (#606)
|
|
296
|
+
* import * as devalue from "devalue";
|
|
297
|
+
*
|
|
298
|
+
* const json = serializeRouterState(state, { serialize: devalue.stringify });
|
|
299
|
+
* // On the client:
|
|
300
|
+
* await hydrateRouter(router, json, { deserialize: devalue.parse });
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
declare function serializeRouterState(state: State, options?: SerializeRouterStateOptions): string;
|
|
304
|
+
//#endregion
|
|
305
|
+
export { SerializeStateOptions as a, HydrateRouterOptions as c, getStaticPaths as d, IncomingMessageLike as f, createRequestScope as g, RequestScopeSource as h, Serialize as i, hydrateRouter as l, RequestScope as m, SerializedRouterState as n, serializeState as o, RequestLike as p, serializeRouterState as r, Deserialize as s, SerializeRouterStateOptions as t, StaticPathEntries as u };
|
|
306
|
+
//# sourceMappingURL=index-8oPDJBQc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-8oPDJBQc.d.ts","names":[],"sources":["../../src/utils/createRequestScope.ts","../../src/utils/getStaticPaths.ts","../../src/utils/hydrateRouter.ts","../../src/utils/serializeState.ts","../../src/utils/serializeRouterState.ts"],"mappings":";;;;;;AAUA;;;UAAiB,mBAAA;EACf,EAAA,GAAK,KAAA,WAAgB,QAAA;EACrB,cAAA,IAAkB,KAAA,WAAgB,QAAA;AAAA;;;;;AAAoB;UAQvC,WAAA;EACf,MAAA,EAAQ,WAAW;AAAA;AAAA,KAGT,kBAAA,GAAqB,mBAAA,GAAsB,WAAW;AAAA,UAEjD,YAAA,sBACM,mBAAA,GAAsB,mBAAA,UACnC,eAAA;EAJE;;;;AAAsD;EAAtD,SAUD,MAAA,EAAQ,QAAA,CAAY,YAAA;EARF;;;;EAAA,SAclB,MAAA,EAAQ,WAAA;EANA;;;;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EImBE,SAAA,GAAY,SAAS;AAAA;;;;;;;;;;;;AJEC;AA4ExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBInCgB,oBAAA,CACd,KAAA,EAAO,KAAA,EACP,OAAA,GAAU,2BAA2B"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { DefaultDependencies, EventMethodMap, GuardFnFactory, LeaveFn, LimitsConfig, NavigationOptions, Options, Params, PluginFactory, Route, RouteConfigUpdate, RouteTreeState, Router, State, SubscribeFn, Unsubscribe } from "@real-router/types";
|
|
2
|
-
|
|
3
1
|
//#region ../path-matcher/dist/esm/index.d.mts
|
|
4
2
|
//#region src/types.d.ts
|
|
5
3
|
/**
|
|
@@ -232,7 +230,7 @@ type NumberFormat = "none" | "auto";
|
|
|
232
230
|
/**
|
|
233
231
|
* Options for search-params parsing and building.
|
|
234
232
|
*/
|
|
235
|
-
interface Options
|
|
233
|
+
interface Options {
|
|
236
234
|
/** Array parameter encoding format. @default "none" */
|
|
237
235
|
arrayFormat?: ArrayFormat;
|
|
238
236
|
/** Boolean parameter encoding format. @default "auto" */
|
|
@@ -309,7 +307,7 @@ interface RouteTree {
|
|
|
309
307
|
*
|
|
310
308
|
* Controls how arrays, booleans, nulls, and numbers are serialized in query strings.
|
|
311
309
|
*/
|
|
312
|
-
type QueryParamsConfig = Readonly<Options
|
|
310
|
+
type QueryParamsConfig = Readonly<Options>;
|
|
313
311
|
/**
|
|
314
312
|
* Options for creating a path matcher.
|
|
315
313
|
*/
|
|
@@ -344,68 +342,5 @@ type Matcher = SegmentMatcher;
|
|
|
344
342
|
* ```
|
|
345
343
|
*/
|
|
346
344
|
//#endregion
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
* Immutable limits configuration type.
|
|
350
|
-
*/
|
|
351
|
-
type Limits = Readonly<LimitsConfig>;
|
|
352
|
-
/**
|
|
353
|
-
* Extended build result that includes segments for path building.
|
|
354
|
-
* Used internally to avoid duplicate getSegmentsByName calls.
|
|
355
|
-
*
|
|
356
|
-
* @param segments - Route segments from getSegmentsByName (typed as unknown[] for cross-package compatibility)
|
|
357
|
-
* @internal
|
|
358
|
-
*/
|
|
359
|
-
interface BuildStateResultWithSegments<P extends Params = Params> {
|
|
360
|
-
readonly state: RouteTreeState<P>;
|
|
361
|
-
readonly segments: readonly unknown[];
|
|
362
|
-
}
|
|
363
|
-
//#endregion
|
|
364
|
-
//#region src/Router.d.ts
|
|
365
|
-
/**
|
|
366
|
-
* Router class with integrated namespace architecture.
|
|
367
|
-
*
|
|
368
|
-
* All functionality is provided by namespace classes:
|
|
369
|
-
* - OptionsNamespace: getOptions (immutable)
|
|
370
|
-
* - DependenciesStore: get/set/remove dependencies
|
|
371
|
-
* - EventEmitter: subscribe
|
|
372
|
-
* - StateNamespace: state storage (getState, setState, getPreviousState)
|
|
373
|
-
* - RoutesNamespace: route tree operations
|
|
374
|
-
* - RouteLifecycleNamespace: canActivate/canDeactivate guards
|
|
375
|
-
* - PluginsNamespace: plugin lifecycle
|
|
376
|
-
* - NavigationNamespace: navigate
|
|
377
|
-
* - RouterLifecycleNamespace: start, stop, isStarted
|
|
378
|
-
*
|
|
379
|
-
* @internal This class implementation is internal. Use createRouter() instead.
|
|
380
|
-
*/
|
|
381
|
-
declare class Router$1<Dependencies extends DefaultDependencies = DefaultDependencies> implements Router<Dependencies> {
|
|
382
|
-
#private;
|
|
383
|
-
[key: string]: unknown;
|
|
384
|
-
/**
|
|
385
|
-
* @param routes - Route definitions
|
|
386
|
-
* @param options - Router options
|
|
387
|
-
* @param dependencies - DI dependencies
|
|
388
|
-
*/
|
|
389
|
-
constructor(routes?: Route<Dependencies>[], options?: Partial<Options>, dependencies?: Dependencies);
|
|
390
|
-
isActiveRoute(name: string, params?: Params, strictEquality?: boolean, ignoreQueryParams?: boolean): boolean;
|
|
391
|
-
buildPath(route: string, params?: Params): string;
|
|
392
|
-
getState<P extends Params = Params>(): State<P> | undefined;
|
|
393
|
-
getPreviousState(): State | undefined;
|
|
394
|
-
areStatesEqual(state1: State | undefined, state2: State | undefined, ignoreQueryParams?: boolean): boolean;
|
|
395
|
-
shouldUpdateNode(nodeName: string): (toState: State, fromState?: State) => boolean;
|
|
396
|
-
isActive(): boolean;
|
|
397
|
-
start(startPath: string): Promise<State>;
|
|
398
|
-
stop(): this;
|
|
399
|
-
dispose(): void;
|
|
400
|
-
canNavigateTo(name: string, params?: Params): boolean;
|
|
401
|
-
usePlugin(...plugins: (PluginFactory<Dependencies> | false | null | undefined)[]): Unsubscribe;
|
|
402
|
-
subscribe(listener: SubscribeFn): Unsubscribe;
|
|
403
|
-
subscribeLeave(listener: LeaveFn): Unsubscribe;
|
|
404
|
-
isLeaveApproved(): boolean;
|
|
405
|
-
navigate(routeName: string, routeParams?: Params, options?: NavigationOptions): Promise<State>;
|
|
406
|
-
navigateToDefault(options?: NavigationOptions): Promise<State>;
|
|
407
|
-
navigateToNotFound(path?: string): State;
|
|
408
|
-
}
|
|
409
|
-
//#endregion
|
|
410
|
-
export { Limits as a, RouteConfigUpdate as c, RouteDefinition as d, RouteTree as f, GuardFnFactory as i, CreateMatcherOptions as l, BuildStateResultWithSegments as n, PluginFactory as o, EventMethodMap as r, Route as s, Router$1 as t, Matcher as u };
|
|
411
|
-
//# sourceMappingURL=Router-DrBkBdZ5.d.ts.map
|
|
345
|
+
export { RouteTree as i, Matcher as n, RouteDefinition as r, CreateMatcherOptions as t };
|
|
346
|
+
//# sourceMappingURL=index-EwbhzRQw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-EwbhzRQw.d.ts","names":["ConstraintPattern","RegExp","pattern","constraint","ParamMeta","Record","Readonly","ReadonlyMap","urlParams","queryParams","spatParams","paramTypeMap","constraintPatterns","pathPattern","URLParamsEncodingType","MatcherInputNode","name","path","fullName","absolute","children","nonAbsoluteChildren","paramMeta","staticPath","CompiledRoute","ReadonlySet","BuildParamSlot","MatchResult","parent","depth","matchSegments","meta","declaredQueryParams","declaredQueryParamsSet","hasTrailingSlash","hasConstraints","buildStaticParts","buildParamSlots","buildParamNamesSet","cachedResult","forwardTo","defaultParams","paramName","encoder","value","isOptional","BuildPathOptions","queryParamsMode","trailingSlash","SegmentNode","staticChildren","hasChildren","paramChild","node","splatChild","route","slashChildRoute","segments","params","SegmentMatcherOptions","caseSensitive","strictTrailingSlash","strictQueryParams","urlParamsEncoding","parseQueryString","queryString","buildQueryString","ResolvedMatcherOptions","buildParamMeta","validateConstraints","encodeURIComponentExcludingSubDelims","segment","ENCODING_METHODS","param","DECODING_METHODS","encodeParam","encoding","isSpatParam","createSegmentNode","SegmentMatcher","private","options","constructor","registerTree","match","buildPath","getSegmentsByName","getMetaByName","hasRoute","setRootPath","rootPath","ArrayFormat","BooleanFormat","NullFormat","NumberFormat","Options","arrayFormat","booleanFormat","nullFormat","numberFormat","FinalOptions","QueryParamPrimitive","QueryParamValue","SearchParams","Record","OmitResponse","querystring","removedParams","KeepResponse","keptParams","DecodeResult","parse","path","opts","parseInto","queryString","target","build","params","omit","paramsToOmit","keep","paramsToKeep","DEFAULT_QUERY_PARAMS","ParamMeta","SegmentMatcher","URLParamsEncodingType","DEFAULT_QUERY_PARAMS","Options","RouteDefinition","key","name","path","children","RouteTree","ReadonlyMap","Record","Readonly","absolute","paramMeta","parent","nonAbsoluteChildren","fullName","staticPath","paramTypeMap","TreeBuildOptions","skipFreeze","QueryParamsMode","TrailingSlashMode","BasePathOptions","trailingSlashMode","queryParamsMode","queryParams","urlParamsEncoding","BuildOptions","ignoreConstraints","MatchOptions","strictTrailingSlash","strongMatching","ParamSource","ParamTypeMap","RouteTreeStateMeta","MatchResult","P","RouteParams","segments","params","meta","RouteTreeState","createRouteTree","routes","options","getSegmentsByName","tree","routeName","nodeToDefinition","node","routeTreeToDefinitions","QueryParamsConfig","CreateMatcherOptions","caseSensitive","strictQueryParams","Matcher","createMatcher","validateRoute","Set","Map","route","methodName","rootNode","parentName","seenNames","seenPathsByParent"],"sources":["../../../path-matcher/dist/esm/index.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,GAAaL,UAAAA;EDsC0B9E;ECpCvCoF,YAAAA,GAAeL,YAAAA;AAAAA;;;;;;;;;;UC/CPmC,eAAAA;EAAAA,CACPC,GAAAA;EACDC,IAAAA;EACAC,IAAAA;EACAC,QAAAA,GAAWJ,eAAe;AAAA;;;;;;;;;;;;;UAclBK,SAAAA;EF2CqB/H;EAAAA,SEzCpB4H,IAAAA;EF+CAtH;EAAAA,SE7CAuH,IAAAA;EF6CW;EAAA,SE3CXM,QAAAA;EFqDe;EAAA,SEnDfL,QAAAA,EAAUE,WAAAA,SAAoBD,SAAAA;EFmDf;EAAA,SEjDfK,SAAAA,EAAWf,SAAAA;EFiDI;EAAA,SE/CfgB,MAAAA,EAAQN,SAAAA;;WAERO,mBAAAA,WAA8BP,SAAAA;EFmDpB/H;EAAAA,SEjDVuI,QAAAA;EFmDW1I;;;;;EAAAA,SE7CX2I,UAAAA;EFwCA9H;;;;;EAAAA,SElCA+H,YAAAA,EAAcP,QAAAA,CAASD,MAAAA;AAAAA;;;;;;ADCL;;;;ACrDiC;ADqDjC,KC4KxB0C,iBAAAA,GAAoBzC,QAAQ,CAACT,OAAAA;;;;UAIxBmD,oBAAAA;EAAAA,SACCC,aAAAA;EAAAA,SACAvB,mBAAAA;EAAAA,SACAwB,iBAAAA;EAAAA,SACA5B,iBAAAA;EAAAA,SACAD,WAAAA,GAAc0B,iBAAiB;AAAA;;;;;;;KAQrCI,OAAAA,GAAUzD,cAAc"}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
3
|
-
import {
|
|
1
|
+
import { i as RouteTree } from "./index-EwbhzRQw.js";
|
|
2
|
+
import { c as RouteConfigUpdate, i as GuardFnFactory, n as BuildStateResultWithSegments, o as PluginFactory, s as Route, t as Router } from "./Router-CJihdrWA.js";
|
|
3
|
+
import { n as RouterValidator, t as RouterError } from "./RouterError-Bm9YnZ6e.js";
|
|
4
|
+
import { Config, DefaultDependencies, DefaultDependencies as DefaultDependencies$1, ErrorCodeKeys, ErrorCodeToValueMap, ErrorCodeValues, EventToNameMap, GuardFn, Listener, NavigationOptions, Navigator, Navigator as Navigator$1, Options, Options as Options$1, Params, Plugin, Router as Router$1, SimpleState, State, SubscribeFn, SubscribeState, Subscription, Unsubscribe } from "@real-router/types";
|
|
4
5
|
|
|
5
6
|
//#region src/constants.d.ts
|
|
6
7
|
type ConstantsKeys = "UNKNOWN_ROUTE";
|
|
@@ -24,200 +25,6 @@ declare const constants: Constants;
|
|
|
24
25
|
*/
|
|
25
26
|
declare const events: EventToNameMap;
|
|
26
27
|
//#endregion
|
|
27
|
-
//#region src/RouterError.d.ts
|
|
28
|
-
declare class RouterError extends Error {
|
|
29
|
-
[key: string]: unknown;
|
|
30
|
-
readonly segment: string | undefined;
|
|
31
|
-
readonly path: string | undefined;
|
|
32
|
-
readonly redirect: State$1 | undefined;
|
|
33
|
-
code: string;
|
|
34
|
-
/**
|
|
35
|
-
* Creates a new RouterError instance.
|
|
36
|
-
*
|
|
37
|
-
* The options object accepts built-in fields (message, segment, path, redirect)
|
|
38
|
-
* and any additional custom fields, which will all be attached to the error instance.
|
|
39
|
-
*
|
|
40
|
-
* @param code - The error code (e.g., "ROUTE_NOT_FOUND", "CANNOT_ACTIVATE")
|
|
41
|
-
* @param options - Optional configuration object
|
|
42
|
-
* @param options.message - Custom error message (defaults to code if not provided)
|
|
43
|
-
* @param options.segment - The route segment where the error occurred
|
|
44
|
-
* @param options.path - The full path where the error occurred
|
|
45
|
-
* @param options.redirect - Optional redirect state for navigation errors
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* // Basic error
|
|
50
|
-
* const err1 = new RouterError("ROUTE_NOT_FOUND");
|
|
51
|
-
*
|
|
52
|
-
* // Error with custom message
|
|
53
|
-
* const err2 = new RouterError("ERR", { message: "Something went wrong" });
|
|
54
|
-
*
|
|
55
|
-
* // Error with context and custom fields
|
|
56
|
-
* const err3 = new RouterError("CANNOT_ACTIVATE", {
|
|
57
|
-
* message: "Insufficient permissions",
|
|
58
|
-
* segment: "admin",
|
|
59
|
-
* path: "/admin/users",
|
|
60
|
-
* userId: "123" // custom field
|
|
61
|
-
* });
|
|
62
|
-
*
|
|
63
|
-
* // Error with redirect
|
|
64
|
-
* const err4 = new RouterError("TRANSITION_ERR", {
|
|
65
|
-
* redirect: { name: "home", path: "/", params: {} }
|
|
66
|
-
* });
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
constructor(code: string, {
|
|
70
|
-
message,
|
|
71
|
-
segment,
|
|
72
|
-
path,
|
|
73
|
-
redirect,
|
|
74
|
-
...rest
|
|
75
|
-
}?: {
|
|
76
|
-
[key: string]: unknown;
|
|
77
|
-
message?: string | undefined;
|
|
78
|
-
segment?: string | undefined;
|
|
79
|
-
path?: string | undefined;
|
|
80
|
-
redirect?: State$1 | undefined;
|
|
81
|
-
});
|
|
82
|
-
/**
|
|
83
|
-
* Updates the error code and conditionally updates the message.
|
|
84
|
-
*
|
|
85
|
-
* If the current message is one of the standard error code values
|
|
86
|
-
* (e.g., "ROUTE_NOT_FOUND", "SAME_STATES"), it will be replaced with the new code.
|
|
87
|
-
* This allows keeping error messages in sync with codes when using standard error codes.
|
|
88
|
-
*
|
|
89
|
-
* If the message is custom (not a standard error code), it will be preserved.
|
|
90
|
-
*
|
|
91
|
-
* @param newCode - The new error code to set
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* // Message follows code (standard error code as message)
|
|
95
|
-
* const err = new RouterError("ROUTE_NOT_FOUND", { message: "ROUTE_NOT_FOUND" });
|
|
96
|
-
* err.setCode("CUSTOM_ERROR"); // message becomes "CUSTOM_ERROR"
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* // Custom message is preserved
|
|
100
|
-
* const err = new RouterError("ERR", { message: "Custom error message" });
|
|
101
|
-
* err.setCode("NEW_CODE"); // message stays "Custom error message"
|
|
102
|
-
*/
|
|
103
|
-
setCode(newCode: string): void;
|
|
104
|
-
/**
|
|
105
|
-
* Copies properties from another Error instance to this RouterError.
|
|
106
|
-
*
|
|
107
|
-
* This method updates the message, cause, and stack trace from the provided error.
|
|
108
|
-
* Useful for wrapping native errors while preserving error context.
|
|
109
|
-
*
|
|
110
|
-
* @param err - The Error instance to copy properties from
|
|
111
|
-
* @throws {TypeError} If err is null or undefined
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```typescript
|
|
115
|
-
* const routerErr = new RouterError("TRANSITION_ERR");
|
|
116
|
-
* try {
|
|
117
|
-
* // some operation that might fail
|
|
118
|
-
* } catch (nativeErr) {
|
|
119
|
-
* routerErr.setErrorInstance(nativeErr);
|
|
120
|
-
* throw routerErr;
|
|
121
|
-
* }
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
setErrorInstance(err: Error): void;
|
|
125
|
-
/**
|
|
126
|
-
* Adds custom fields to the error object.
|
|
127
|
-
*
|
|
128
|
-
* This method allows attaching arbitrary data to the error for debugging or logging purposes.
|
|
129
|
-
* All fields become accessible as properties on the error instance and are included in JSON serialization.
|
|
130
|
-
*
|
|
131
|
-
* Reserved method names (setCode, setErrorInstance, setAdditionalFields, hasField, getField, toJSON)
|
|
132
|
-
* are automatically filtered out to prevent accidental overwriting of class methods.
|
|
133
|
-
*
|
|
134
|
-
* @param fields - Object containing custom fields to add to the error
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* ```typescript
|
|
138
|
-
* const err = new RouterError("CANNOT_ACTIVATE");
|
|
139
|
-
* err.setAdditionalFields({
|
|
140
|
-
* userId: "123",
|
|
141
|
-
* attemptedRoute: "/admin",
|
|
142
|
-
* reason: "insufficient permissions"
|
|
143
|
-
* });
|
|
144
|
-
*
|
|
145
|
-
* console.log(err.userId); // "123"
|
|
146
|
-
* console.log(JSON.stringify(err)); // includes all custom fields
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
|
-
setAdditionalFields(fields: Record<string, unknown>): void;
|
|
150
|
-
/**
|
|
151
|
-
* Checks if a custom field exists on the error object.
|
|
152
|
-
*
|
|
153
|
-
* This method checks for both custom fields added via setAdditionalFields()
|
|
154
|
-
* and built-in fields (code, message, segment, etc.).
|
|
155
|
-
*
|
|
156
|
-
* @param key - The field name to check
|
|
157
|
-
* @returns `true` if the field exists, `false` otherwise
|
|
158
|
-
*
|
|
159
|
-
* @example
|
|
160
|
-
* ```typescript
|
|
161
|
-
* const err = new RouterError("ERR", { segment: "users" });
|
|
162
|
-
* err.setAdditionalFields({ userId: "123" });
|
|
163
|
-
*
|
|
164
|
-
* err.hasField("userId"); // true
|
|
165
|
-
* err.hasField("segment"); // true
|
|
166
|
-
* err.hasField("unknown"); // false
|
|
167
|
-
* ```
|
|
168
|
-
*/
|
|
169
|
-
hasField(key: string): boolean;
|
|
170
|
-
/**
|
|
171
|
-
* Retrieves a custom field value from the error object.
|
|
172
|
-
*
|
|
173
|
-
* This method can access both custom fields and built-in fields.
|
|
174
|
-
* Returns `undefined` if the field doesn't exist.
|
|
175
|
-
*
|
|
176
|
-
* @param key - The field name to retrieve
|
|
177
|
-
* @returns The field value, or `undefined` if it doesn't exist
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* ```typescript
|
|
181
|
-
* const err = new RouterError("ERR");
|
|
182
|
-
* err.setAdditionalFields({ userId: "123", role: "admin" });
|
|
183
|
-
*
|
|
184
|
-
* err.getField("userId"); // "123"
|
|
185
|
-
* err.getField("role"); // "admin"
|
|
186
|
-
* err.getField("code"); // "ERR" (built-in field)
|
|
187
|
-
* err.getField("unknown"); // undefined
|
|
188
|
-
* ```
|
|
189
|
-
*/
|
|
190
|
-
getField(key: string): unknown;
|
|
191
|
-
/**
|
|
192
|
-
* Serializes the error to a JSON-compatible object.
|
|
193
|
-
*
|
|
194
|
-
* This method is automatically called by JSON.stringify() and includes:
|
|
195
|
-
* - Built-in fields: code, message, segment (if set), path (if set), redirect (if set)
|
|
196
|
-
* - All custom fields added via setAdditionalFields() or constructor
|
|
197
|
-
* - Excludes: stack trace (for security/cleanliness)
|
|
198
|
-
*
|
|
199
|
-
* @returns A plain object representation of the error, suitable for JSON serialization
|
|
200
|
-
*
|
|
201
|
-
* @example
|
|
202
|
-
* ```typescript
|
|
203
|
-
* const err = new RouterError("ROUTE_NOT_FOUND", {
|
|
204
|
-
* message: "Route not found",
|
|
205
|
-
* path: "/admin/users/123"
|
|
206
|
-
* });
|
|
207
|
-
* err.setAdditionalFields({ userId: "123" });
|
|
208
|
-
*
|
|
209
|
-
* JSON.stringify(err);
|
|
210
|
-
* // {
|
|
211
|
-
* // "code": "ROUTE_NOT_FOUND",
|
|
212
|
-
* // "message": "Route not found",
|
|
213
|
-
* // "path": "/admin/users/123",
|
|
214
|
-
* // "userId": "123"
|
|
215
|
-
* // }
|
|
216
|
-
* ```
|
|
217
|
-
*/
|
|
218
|
-
toJSON(): Record<string, unknown>;
|
|
219
|
-
}
|
|
220
|
-
//#endregion
|
|
221
28
|
//#region src/createRouter.d.ts
|
|
222
29
|
/**
|
|
223
30
|
* Creates a new router instance.
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/constants.ts","../../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/constants.ts","../../src/createRouter.ts","../../src/getNavigator.ts","../../src/namespaces/RoutesNamespace/forwardChain.ts"],"mappings":";;;;;;KAWY,aAAA;AAAA,KAEA,SAAA,GAAY,MAAM,CAAC,aAAA;AAAA,KAMnB,UAAA,GAAa,MAAA,CAAO,aAAA,EAAe,eAAA;;;AAR/C;;;cAea,UAAA,EAAY,mBAavB;AA5BuB;AAEzB;;;AAFyB,cAkCZ,aAAA;AAAA,cAEA,SAAA,EAAW,SAEvB;;;;;cAoBY,MAAA,EAAQ,cAQpB;;;;;;AAlED;;;;AAAyB;AAEzB;;;;AAA4C;AAM5C;;;cCIa,YAAA,wBACU,qBAAA,GAAsB,qBAAA,EAE3C,MAAA,GAAQ,KAAA,CAAM,YAAA,KACd,OAAA,GAAS,OAAA,CAAQ,SAAA,GACjB,YAAA,GAAc,YAAA,KACb,MAAA,CAAO,YAAA;;;cCrBG,YAAA,wBACU,qBAAA,GAAsB,qBAAA,EAE3C,MAAA,EAAQ,QAAA,CAAO,YAAA,MACd,WAAA;;;iBCVa,mBAAA,CACd,UAAA,UACA,UAAA,EAAY,MAAM,kBAClB,QAAA"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./Router-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./Router-D8Awa7bY.js`),t=(t=[],n={},r={})=>new e.t(t,n,r),n=new WeakMap,r=e=>{let t=n.get(e);return t||(t=Object.freeze({navigate:e.navigate,getState:e.getState,isActiveRoute:e.isActiveRoute,canNavigateTo:e.canNavigateTo,subscribe:e.subscribe,subscribeLeave:e.subscribeLeave,isLeaveApproved:e.isLeaveApproved}),n.set(e,t)),t};exports.Router=e.t,exports.RouterError=e.n,exports.UNKNOWN_ROUTE=e.f,exports.constants=e.p,exports.createRouter=t,exports.errorCodes=e.m,exports.events=e.h,exports.getNavigator=r,exports.resolveForwardChain=e.o;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Router"],"sources":["../../src/createRouter.ts","../../src/getNavigator.ts"],"sourcesContent":["// packages/core/src/createRouter.ts\n\nimport { Router } from \"./Router\";\n\nimport type { Route } from \"./types\";\nimport type { DefaultDependencies, Options } from \"@real-router/types\";\n\n/**\n * Creates a new router instance.\n *\n * @param routes - Array of route definitions\n * @param options - Router configuration options\n * @param dependencies - Dependencies to inject into the router\n * @returns A new Router instance\n *\n * @example\n * const router = createRouter([\n * { name: 'home', path: '/' },\n * { name: 'users', path: '/users' },\n * ]);\n *\n * router.start('/');\n */\nexport const createRouter = <\n Dependencies extends DefaultDependencies = DefaultDependencies,\n>(\n routes: Route<Dependencies>[] = [],\n options: Partial<Options> = {},\n dependencies: Dependencies = {} as Dependencies,\n): Router<Dependencies> => {\n return new Router<Dependencies>(routes, options, dependencies);\n};\n","import type {\n Navigator,\n DefaultDependencies,\n Router,\n} from \"@real-router/types\";\n\nconst cache = new WeakMap<Router, Navigator>();\n\nexport const getNavigator = <\n Dependencies extends DefaultDependencies = DefaultDependencies,\n>(\n router: Router<Dependencies>,\n): Navigator => {\n let nav = cache.get(router);\n\n if (!nav) {\n nav = Object.freeze({\n navigate: router.navigate,\n getState: router.getState,\n isActiveRoute: router.isActiveRoute,\n canNavigateTo: router.canNavigateTo,\n subscribe: router.subscribe,\n subscribeLeave: router.subscribeLeave,\n isLeaveApproved: router.isLeaveApproved,\n } as Navigator);\n cache.set(router, nav);\n }\n\n return nav;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["Router"],"sources":["../../src/createRouter.ts","../../src/getNavigator.ts"],"sourcesContent":["// packages/core/src/createRouter.ts\n\nimport { Router } from \"./Router\";\n\nimport type { Route } from \"./types\";\nimport type { DefaultDependencies, Options } from \"@real-router/types\";\n\n/**\n * Creates a new router instance.\n *\n * @param routes - Array of route definitions\n * @param options - Router configuration options\n * @param dependencies - Dependencies to inject into the router\n * @returns A new Router instance\n *\n * @example\n * const router = createRouter([\n * { name: 'home', path: '/' },\n * { name: 'users', path: '/users' },\n * ]);\n *\n * router.start('/');\n */\nexport const createRouter = <\n Dependencies extends DefaultDependencies = DefaultDependencies,\n>(\n routes: Route<Dependencies>[] = [],\n options: Partial<Options> = {},\n dependencies: Dependencies = {} as Dependencies,\n): Router<Dependencies> => {\n return new Router<Dependencies>(routes, options, dependencies);\n};\n","import type {\n Navigator,\n DefaultDependencies,\n Router,\n} from \"@real-router/types\";\n\nconst cache = new WeakMap<Router, Navigator>();\n\nexport const getNavigator = <\n Dependencies extends DefaultDependencies = DefaultDependencies,\n>(\n router: Router<Dependencies>,\n): Navigator => {\n let nav = cache.get(router);\n\n if (!nav) {\n nav = Object.freeze({\n navigate: router.navigate,\n getState: router.getState,\n isActiveRoute: router.isActiveRoute,\n canNavigateTo: router.canNavigateTo,\n subscribe: router.subscribe,\n subscribeLeave: router.subscribeLeave,\n isLeaveApproved: router.isLeaveApproved,\n } as Navigator);\n cache.set(router, nav);\n }\n\n return nav;\n};\n"],"mappings":"2GAuBa,GAGX,EAAgC,CAAC,EACjC,EAA4B,CAAC,EAC7B,EAA6B,CAAC,IAEvB,IAAIA,EAAAA,EAAqB,EAAQ,EAAS,CAAY,ECxBzD,EAAQ,IAAI,QAEL,EAGX,GACc,CACd,IAAI,EAAM,EAAM,IAAI,CAAM,EAe1B,OAbK,IACH,EAAM,OAAO,OAAO,CAClB,SAAU,EAAO,SACjB,SAAU,EAAO,SACjB,cAAe,EAAO,cACtB,cAAe,EAAO,cACtB,UAAW,EAAO,UAClB,eAAgB,EAAO,eACvB,gBAAiB,EAAO,eAC1B,CAAc,EACd,EAAM,IAAI,EAAQ,CAAG,GAGhB,CACT"}
|