@real-router/core 0.40.1 → 0.42.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/dist/cjs/Router-B2tmtNiM.d.ts +353 -0
- package/dist/cjs/Router-CVNR-dug.js +6 -0
- package/dist/cjs/Router-CVNR-dug.js.map +1 -0
- package/dist/cjs/RouterError-BkgjTHQg.js +2 -0
- package/dist/cjs/RouterError-BkgjTHQg.js.map +1 -0
- package/dist/cjs/RouterValidator-TUi8eT8Q.d.ts +112 -0
- package/dist/cjs/api.d.ts +17 -12
- package/dist/cjs/api.js +2 -1
- package/dist/cjs/api.js.map +1 -1
- package/dist/cjs/getPluginApi-BXrM_Nwv.js +2 -0
- package/dist/cjs/getPluginApi-BXrM_Nwv.js.map +1 -0
- package/dist/cjs/index.d.ts +206 -196
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internals-na15rxo_.js +2 -0
- package/dist/cjs/internals-na15rxo_.js.map +1 -0
- package/dist/cjs/utils.d.ts +6 -3
- package/dist/cjs/utils.js +2 -1
- package/dist/cjs/utils.js.map +1 -1
- package/dist/cjs/validation.d.ts +153 -152
- package/dist/cjs/validation.js +1 -1
- package/dist/esm/Router-4JRfQLMM.d.mts +353 -0
- package/dist/esm/Router-C_k70gHi.mjs +6 -0
- package/dist/esm/Router-C_k70gHi.mjs.map +1 -0
- package/dist/esm/RouterError-D0RlQE_5.mjs +2 -0
- package/dist/esm/RouterError-D0RlQE_5.mjs.map +1 -0
- package/dist/esm/RouterValidator-DphcVMEp.d.mts +112 -0
- package/dist/esm/api.d.mts +17 -12
- package/dist/esm/api.mjs +2 -1
- package/dist/esm/api.mjs.map +1 -1
- package/dist/esm/getPluginApi-D0bBPuLp.mjs +2 -0
- package/dist/esm/getPluginApi-D0bBPuLp.mjs.map +1 -0
- package/dist/esm/index.d.mts +206 -196
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/internals-CCymabFj.mjs +2 -0
- package/dist/{cjs/validation.js.map → esm/internals-CCymabFj.mjs.map} +1 -1
- package/dist/esm/utils.d.mts +6 -3
- package/dist/esm/utils.mjs +2 -1
- package/dist/esm/utils.mjs.map +1 -1
- package/dist/esm/validation.d.mts +153 -152
- package/dist/esm/validation.mjs +1 -1
- package/package.json +5 -7
- package/src/Router.ts +4 -6
- package/src/api/getPluginApi.ts +2 -3
- package/src/helpers.ts +9 -7
- package/src/index.ts +0 -1
- package/src/internals.ts +4 -5
- package/src/namespaces/NavigationNamespace/NavigationNamespace.ts +0 -1
- package/src/namespaces/OptionsNamespace/constants.ts +1 -0
- package/src/namespaces/OptionsNamespace/helpers.ts +0 -1
- package/src/namespaces/RouterLifecycleNamespace/types.ts +1 -3
- package/src/namespaces/RoutesNamespace/RoutesNamespace.ts +3 -3
- package/src/namespaces/RoutesNamespace/types.ts +2 -2
- package/src/namespaces/StateNamespace/StateNamespace.ts +30 -34
- package/src/namespaces/StateNamespace/helpers.ts +8 -27
- package/src/stateMetaStore.ts +15 -0
- package/src/transitionPath.ts +13 -16
- package/src/types/RouterValidator.ts +0 -1
- package/src/wiring/RouterWiringBuilder.ts +1 -1
- package/dist/cjs/Router-B-Pev7K2.d.ts +0 -46
- package/dist/cjs/RouterValidator-mx2Zooya.d.ts +0 -136
- package/dist/cjs/index.d-y2b-8_3Y.d.ts +0 -236
- package/dist/cjs/metafile-cjs.json +0 -1
- package/dist/esm/Router-B-Pev7K2.d.mts +0 -46
- package/dist/esm/RouterValidator-mx2Zooya.d.mts +0 -136
- package/dist/esm/chunk-5QXFUUDL.mjs +0 -1
- package/dist/esm/chunk-5QXFUUDL.mjs.map +0 -1
- package/dist/esm/chunk-HHIXK5UM.mjs +0 -1
- package/dist/esm/chunk-HHIXK5UM.mjs.map +0 -1
- package/dist/esm/chunk-MNRZAE7T.mjs +0 -1
- package/dist/esm/chunk-MNRZAE7T.mjs.map +0 -1
- package/dist/esm/chunk-QUUNDESP.mjs +0 -1
- package/dist/esm/chunk-QUUNDESP.mjs.map +0 -1
- package/dist/esm/index.d-y2b-8_3Y.d.mts +0 -236
- package/dist/esm/metafile-esm.json +0 -1
- package/dist/esm/validation.mjs.map +0 -1
package/dist/esm/index.d.mts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export { Config, DefaultDependencies, GuardFn, GuardFnFactory, Listener, NavigationOptions, Navigator, Options, Params, Plugin, PluginFactory, Route, RouteConfigUpdate, SimpleState, State, StateMeta, SubscribeFn, SubscribeState, Subscription, Unsubscribe } from '@real-router/types';
|
|
5
|
-
export { R as RouteTree } from './index.d-y2b-8_3Y.mjs';
|
|
1
|
+
import { c as RouteConfigUpdate, f as RouteTree, i as GuardFnFactory, n as BuildStateResultWithSegments, o as PluginFactory, s as Route, t as Router } from "./Router-4JRfQLMM.mjs";
|
|
2
|
+
import { t as RouterValidator } from "./RouterValidator-DphcVMEp.mjs";
|
|
3
|
+
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, State as State$1, SubscribeFn, SubscribeState, Subscription, Unsubscribe } from "@real-router/types";
|
|
6
4
|
|
|
5
|
+
//#region src/constants.d.ts
|
|
7
6
|
type ConstantsKeys = "UNKNOWN_ROUTE";
|
|
8
7
|
type Constants = Record<ConstantsKeys, string>;
|
|
9
8
|
type ErrorCodes = Record<ErrorCodeKeys, ErrorCodeValues>;
|
|
@@ -24,194 +23,202 @@ declare const constants: Constants;
|
|
|
24
23
|
* Used with addEventListener/removeEventListener for reactive subscriptions.
|
|
25
24
|
*/
|
|
26
25
|
declare const events: EventToNameMap;
|
|
27
|
-
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/RouterError.d.ts
|
|
28
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
|
+
}?: {
|
|
29
76
|
[key: string]: unknown;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* ```typescript
|
|
175
|
-
* const err = new RouterError("ERR");
|
|
176
|
-
* err.setAdditionalFields({ userId: "123", role: "admin" });
|
|
177
|
-
*
|
|
178
|
-
* err.getField("userId"); // "123"
|
|
179
|
-
* err.getField("role"); // "admin"
|
|
180
|
-
* err.getField("code"); // "ERR" (built-in field)
|
|
181
|
-
* err.getField("unknown"); // undefined
|
|
182
|
-
* ```
|
|
183
|
-
*/
|
|
184
|
-
getField(key: string): unknown;
|
|
185
|
-
/**
|
|
186
|
-
* Serializes the error to a JSON-compatible object.
|
|
187
|
-
*
|
|
188
|
-
* This method is automatically called by JSON.stringify() and includes:
|
|
189
|
-
* - Built-in fields: code, message, segment (if set), path (if set), redirect (if set)
|
|
190
|
-
* - All custom fields added via setAdditionalFields() or constructor
|
|
191
|
-
* - Excludes: stack trace (for security/cleanliness)
|
|
192
|
-
*
|
|
193
|
-
* @returns A plain object representation of the error, suitable for JSON serialization
|
|
194
|
-
*
|
|
195
|
-
* @example
|
|
196
|
-
* ```typescript
|
|
197
|
-
* const err = new RouterError("ROUTE_NOT_FOUND", {
|
|
198
|
-
* message: "Route not found",
|
|
199
|
-
* path: "/admin/users/123"
|
|
200
|
-
* });
|
|
201
|
-
* err.setAdditionalFields({ userId: "123" });
|
|
202
|
-
*
|
|
203
|
-
* JSON.stringify(err);
|
|
204
|
-
* // {
|
|
205
|
-
* // "code": "ROUTE_NOT_FOUND",
|
|
206
|
-
* // "message": "Route not found",
|
|
207
|
-
* // "path": "/admin/users/123",
|
|
208
|
-
* // "userId": "123"
|
|
209
|
-
* // }
|
|
210
|
-
* ```
|
|
211
|
-
*/
|
|
212
|
-
toJSON(): Record<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>;
|
|
213
219
|
}
|
|
214
|
-
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/createRouter.d.ts
|
|
215
222
|
/**
|
|
216
223
|
* Creates a new router instance.
|
|
217
224
|
*
|
|
@@ -228,10 +235,13 @@ declare class RouterError extends Error {
|
|
|
228
235
|
*
|
|
229
236
|
* router.start('/');
|
|
230
237
|
*/
|
|
231
|
-
declare const createRouter: <Dependencies extends DefaultDependencies = DefaultDependencies>(routes?: Route<Dependencies>[], options?: Partial<Options>, dependencies?: Dependencies) => Router<Dependencies>;
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
238
|
+
declare const createRouter: <Dependencies extends DefaultDependencies$1 = DefaultDependencies$1>(routes?: Route<Dependencies>[], options?: Partial<Options$1>, dependencies?: Dependencies) => Router<Dependencies>;
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/getNavigator.d.ts
|
|
241
|
+
declare const getNavigator: <Dependencies extends DefaultDependencies$1 = DefaultDependencies$1>(router: Router$1<Dependencies>) => Navigator$1;
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region src/namespaces/RoutesNamespace/forwardChain.d.ts
|
|
235
244
|
declare function resolveForwardChain(startRoute: string, forwardMap: Record<string, string>, maxDepth?: number): string;
|
|
236
|
-
|
|
237
|
-
export { type Constants, type ErrorCodes, Router, RouterError, UNKNOWN_ROUTE, constants, createRouter, errorCodes, events, getNavigator, resolveForwardChain };
|
|
245
|
+
//#endregion
|
|
246
|
+
export { type BuildStateResultWithSegments, type Config, type Constants, type DefaultDependencies, type ErrorCodes, type GuardFn, type GuardFnFactory, type Listener, type NavigationOptions, type Navigator, type Options, type Params, type Plugin, type PluginFactory, type Route, type RouteConfigUpdate, type RouteTree, Router, RouterError, type RouterValidator, type SimpleState, type State, type SubscribeFn, type SubscribeState, type Subscription, UNKNOWN_ROUTE, type Unsubscribe, constants, createRouter, errorCodes, events, getNavigator, resolveForwardChain };
|
|
247
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{a as e,t}from"./Router-C_k70gHi.mjs";import{c as n,l as r,o as i,s as a,t as o}from"./RouterError-D0RlQE_5.mjs";const s=(e=[],n={},r={})=>new t(e,n,r),c=new WeakMap,l=e=>{let t=c.get(e);return t||(t=Object.freeze({navigate:e.navigate,getState:e.getState,isActiveRoute:e.isActiveRoute,canNavigateTo:e.canNavigateTo,subscribe:e.subscribe}),c.set(e,t)),t};export{t as Router,o as RouterError,i as UNKNOWN_ROUTE,a as constants,s as createRouter,n as errorCodes,r as events,l as getNavigator,e as resolveForwardChain};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"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 });\n cache.set(router, nav);\n }\n\n return nav;\n};\n"],"mappings":"uHAuBA,MAAa,GAGX,EAAgC,EAAE,CAClC,EAA4B,EAAE,CAC9B,EAA6B,EAAE,GAExB,IAAI,EAAqB,EAAQ,EAAS,EAAa,CCxB1D,EAAQ,IAAI,QAEL,EAGX,GACc,CACd,IAAI,EAAM,EAAM,IAAI,EAAO,CAa3B,OAXK,IACH,EAAM,OAAO,OAAO,CAClB,SAAU,EAAO,SACjB,SAAU,EAAO,SACjB,cAAe,EAAO,cACtB,cAAe,EAAO,cACtB,UAAW,EAAO,UACnB,CAAC,CACF,EAAM,IAAI,EAAQ,EAAI,EAGjB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
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])}}export{n as i,a as n,t as r,i as t};
|
|
2
|
+
//# sourceMappingURL=internals-CCymabFj.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"internals-CCymabFj.mjs","names":[],"sources":["../../src/internals.ts"],"sourcesContent":["import type { DependenciesStore } from \"./namespaces/DependenciesNamespace\";\nimport type { RoutesStore } from \"./namespaces/RoutesNamespace\";\nimport type { Router as RouterClass } from \"./Router\";\nimport type { EventMethodMap, GuardFnFactory, PluginFactory } from \"./types\";\nimport type { RouterValidator } from \"./types/RouterValidator\";\nimport type {\n DefaultDependencies,\n EventName,\n Options,\n Params,\n Plugin,\n Router as RouterInterface,\n RouteTreeState,\n SimpleState,\n State,\n Unsubscribe,\n} from \"@real-router/types\";\nimport type { RouteTree } from \"route-tree\";\n\nexport interface RouterInternals<\n D extends DefaultDependencies = DefaultDependencies,\n> {\n readonly makeState: <P extends Params = Params>(\n name: string,\n params?: P,\n path?: string,\n meta?: Record<string, Record<string, \"url\" | \"query\">>,\n ) => State<P>;\n\n readonly forwardState: <P extends Params = Params>(\n routeName: string,\n routeParams: P,\n ) => SimpleState<P>;\n\n readonly buildStateResolved: (\n resolvedName: string,\n resolvedParams: Params,\n ) => RouteTreeState | undefined;\n\n readonly matchPath: <P extends Params = Params>(\n path: string,\n options?: Options,\n ) => State<P> | undefined;\n\n readonly getOptions: () => Options;\n\n readonly addEventListener: <E extends EventName>(\n eventName: E,\n cb: Plugin[EventMethodMap[E]],\n ) => Unsubscribe;\n\n readonly buildPath: (route: string, params?: Params) => string;\n\n readonly start: (path: string) => Promise<State>;\n\n /* eslint-disable @typescript-eslint/no-explicit-any -- heterogeneous map: stores different InterceptorFn<M> types under different keys */\n readonly interceptors: Map<\n string,\n ((next: (...args: any[]) => any, ...args: any[]) => any)[]\n >;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n\n readonly setRootPath: (rootPath: string) => void;\n readonly getRootPath: () => string;\n\n readonly getTree: () => RouteTree;\n\n readonly isDisposed: () => boolean;\n\n validator: RouterValidator | null;\n\n // Dependencies (issue #172)\n readonly dependenciesGetStore: () => DependenciesStore<D>;\n\n // Clone support (issue #173)\n readonly cloneOptions: () => Options;\n readonly cloneDependencies: () => Record<string, unknown>;\n readonly getLifecycleFactories: () => [\n Record<string, GuardFnFactory<D>>,\n Record<string, GuardFnFactory<D>>,\n ];\n readonly getPluginFactories: () => PluginFactory<D>[];\n\n // Consolidated route data store (issue #174 Phase 2)\n readonly routeGetStore: () => RoutesStore<D>;\n\n // Cross-namespace state (issue #174)\n readonly getStateName: () => string | undefined;\n readonly isTransitioning: () => boolean;\n readonly clearState: () => void;\n readonly setState: (state: State) => void;\n readonly routerExtensions: { keys: string[] }[];\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- existential type: stores RouterInternals for all Dependencies types\nconst internals = new WeakMap<object, RouterInternals<any>>();\n\nexport function getInternals<D extends DefaultDependencies>(\n router: RouterInterface<D>,\n): RouterInternals<D> {\n const ctx = internals.get(router);\n\n if (!ctx) {\n throw new TypeError(\n \"[real-router] Invalid router instance — not found in internals registry\",\n );\n }\n\n return ctx as RouterInternals<D>;\n}\n\nexport function registerInternals<D extends DefaultDependencies>(\n router: RouterClass<D>,\n ctx: RouterInternals<D>,\n): void {\n internals.set(router, ctx);\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-argument -- internal chain execution: type safety enforced at public API boundary (PluginApi.addInterceptor) */\nfunction executeInterceptorChain<T>(\n interceptors: ((next: (...args: any[]) => any, ...args: any[]) => any)[],\n original: (...args: any[]) => T,\n args: any[],\n): T {\n let chain = original as (...args: any[]) => any;\n\n for (const interceptor of interceptors) {\n const prev = chain;\n\n chain = (...chainArgs: any[]) => interceptor(prev, ...chainArgs);\n }\n\n return chain(...args) as T;\n}\n\nexport function createInterceptable<T extends (...args: any[]) => any>(\n name: string,\n original: T,\n interceptors: Map<\n string,\n ((next: (...args: any[]) => any, ...args: any[]) => any)[]\n >,\n): T {\n return ((...args: any[]) => {\n const chain = interceptors.get(name);\n\n if (!chain || chain.length === 0) {\n return original(...args);\n }\n\n return executeInterceptorChain(chain, original, args);\n }) as T;\n}\n\nexport function createInterceptable2<A, B, R>(\n name: string,\n original: (a: A, b: B) => R,\n interceptors: Map<\n string,\n ((next: (...args: any[]) => any, ...args: any[]) => any)[]\n >,\n): (a: A, b: B) => R {\n return (arg1: A, arg2: B) => {\n const chain = interceptors.get(name);\n\n if (!chain || chain.length === 0) {\n return original(arg1, arg2);\n }\n\n return executeInterceptorChain(chain, original, [arg1, arg2]);\n };\n}\n/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-argument */\n"],"mappings":"AA+FA,MAAM,EAAY,IAAI,QAEtB,SAAgB,EACd,EACoB,CACpB,IAAM,EAAM,EAAU,IAAI,EAAO,CAEjC,GAAI,CAAC,EACH,MAAU,UACR,0EACD,CAGH,OAAO,EAGT,SAAgB,EACd,EACA,EACM,CACN,EAAU,IAAI,EAAQ,EAAI,CAI5B,SAAS,EACP,EACA,EACA,EACG,CACH,IAAI,EAAQ,EAEZ,IAAK,IAAM,KAAe,EAAc,CACtC,IAAM,EAAO,EAEb,GAAS,GAAG,IAAqB,EAAY,EAAM,GAAG,EAAU,CAGlE,OAAO,EAAM,GAAG,EAAK,CAGvB,SAAgB,EACd,EACA,EACA,EAIG,CACH,QAAS,GAAG,IAAgB,CAC1B,IAAM,EAAQ,EAAa,IAAI,EAAK,CAMpC,MAJI,CAAC,GAAS,EAAM,SAAW,EACtB,EAAS,GAAG,EAAK,CAGnB,EAAwB,EAAO,EAAU,EAAK,GAIzD,SAAgB,EACd,EACA,EACA,EAImB,CACnB,OAAQ,EAAS,IAAY,CAC3B,IAAM,EAAQ,EAAa,IAAI,EAAK,CAMpC,MAJI,CAAC,GAAS,EAAM,SAAW,EACtB,EAAS,EAAM,EAAK,CAGtB,EAAwB,EAAO,EAAU,CAAC,EAAM,EAAK,CAAC"}
|
package/dist/esm/utils.d.mts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { DefaultDependencies, Router } from
|
|
1
|
+
import { DefaultDependencies, Router } from "@real-router/types";
|
|
2
2
|
|
|
3
|
+
//#region src/utils/getStaticPaths.d.ts
|
|
3
4
|
type StaticPathEntries = Record<string, () => Promise<Record<string, string>[]>>;
|
|
4
5
|
declare function getStaticPaths<Dependencies extends DefaultDependencies = DefaultDependencies>(router: Router<Dependencies>, entries?: StaticPathEntries): Promise<string[]>;
|
|
5
|
-
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/utils/serializeState.d.ts
|
|
6
8
|
/**
|
|
7
9
|
* XSS-safe JSON serialization for embedding data in HTML `<script>` tags.
|
|
8
10
|
*
|
|
@@ -16,5 +18,6 @@ declare function getStaticPaths<Dependencies extends DefaultDependencies = Defau
|
|
|
16
18
|
* ```
|
|
17
19
|
*/
|
|
18
20
|
declare function serializeState(data: unknown): string;
|
|
19
|
-
|
|
21
|
+
//#endregion
|
|
20
22
|
export { type StaticPathEntries, getStaticPaths, serializeState };
|
|
23
|
+
//# sourceMappingURL=utils.d.mts.map
|
package/dist/esm/utils.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{t as e}from"./getPluginApi-D0bBPuLp.mjs";function t(e){let n=[];for(let r of e.children.values())r.children.size===0?n.push(r.fullName):n.push(...t(r));return n}async function n(n,r){let i=t(e(n).getTree()),a=[];for(let e of i){let t=r?.[e];if(t){let r=await t();for(let t of r)a.push(n.buildPath(e,t))}else a.push(n.buildPath(e,{}))}return a}function r(e){return e===void 0?`null`:JSON.stringify(e).replaceAll(`<`,String.raw`\u003c`).replaceAll(`>`,String.raw`\u003e`).replaceAll(`&`,String.raw`\u0026`)}export{n as getStaticPaths,r as serializeState};
|
|
2
|
+
//# sourceMappingURL=utils.mjs.map
|
package/dist/esm/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/getStaticPaths.ts","../../src/utils/serializeState.ts"],"
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../../src/utils/getStaticPaths.ts","../../src/utils/serializeState.ts"],"sourcesContent":["import { getPluginApi } from \"../api/getPluginApi\";\n\nimport type { DefaultDependencies, Router } from \"@real-router/types\";\nimport type { RouteTree } from \"route-tree\";\n\nexport type StaticPathEntries = Record<\n string,\n () => Promise<Record<string, string>[]>\n>;\n\nfunction getLeafRouteNames(node: RouteTree): string[] {\n const result: string[] = [];\n\n for (const child of node.children.values()) {\n if (child.children.size === 0) {\n result.push(child.fullName);\n } else {\n result.push(...getLeafRouteNames(child));\n }\n }\n\n return result;\n}\n\nexport async function getStaticPaths<\n Dependencies extends DefaultDependencies = DefaultDependencies,\n>(\n router: Router<Dependencies>,\n entries?: StaticPathEntries,\n): Promise<string[]> {\n const tree = getPluginApi(router).getTree();\n const leafRoutes = getLeafRouteNames(tree);\n const paths: string[] = [];\n\n for (const routeName of leafRoutes) {\n const entryFn = entries?.[routeName];\n\n if (entryFn) {\n const paramSets = await entryFn();\n\n for (const params of paramSets) {\n paths.push(router.buildPath(routeName, params));\n }\n } else {\n paths.push(router.buildPath(routeName, {}));\n }\n }\n\n return paths;\n}\n","/**\n * XSS-safe JSON serialization for embedding data in HTML `<script>` tags.\n *\n * Escapes `<`, `>`, and `&` to their Unicode equivalents to prevent\n * injection via `</script>` or HTML entities inside inline scripts.\n *\n * @example\n * ```typescript\n * const json = serializeState({ name: \"home\", path: \"/\" });\n * const html = `<script>window.__STATE__=${json}</script>`;\n * ```\n */\nexport function serializeState(data: unknown): string {\n if (data === undefined) {\n return \"null\";\n }\n\n return JSON.stringify(data)\n .replaceAll(\"<\", String.raw`\\u003c`)\n .replaceAll(\">\", String.raw`\\u003e`)\n .replaceAll(\"&\", String.raw`\\u0026`);\n}\n"],"mappings":"gDAUA,SAAS,EAAkB,EAA2B,CACpD,IAAM,EAAmB,EAAE,CAE3B,IAAK,IAAM,KAAS,EAAK,SAAS,QAAQ,CACpC,EAAM,SAAS,OAAS,EAC1B,EAAO,KAAK,EAAM,SAAS,CAE3B,EAAO,KAAK,GAAG,EAAkB,EAAM,CAAC,CAI5C,OAAO,EAGT,eAAsB,EAGpB,EACA,EACmB,CAEnB,IAAM,EAAa,EADN,EAAa,EAAO,CAAC,SAAS,CACD,CACpC,EAAkB,EAAE,CAE1B,IAAK,IAAM,KAAa,EAAY,CAClC,IAAM,EAAU,IAAU,GAE1B,GAAI,EAAS,CACX,IAAM,EAAY,MAAM,GAAS,CAEjC,IAAK,IAAM,KAAU,EACnB,EAAM,KAAK,EAAO,UAAU,EAAW,EAAO,CAAC,MAGjD,EAAM,KAAK,EAAO,UAAU,EAAW,EAAE,CAAC,CAAC,CAI/C,OAAO,ECpCT,SAAgB,EAAe,EAAuB,CAKpD,OAJI,IAAS,IAAA,GACJ,OAGF,KAAK,UAAU,EAAK,CACxB,WAAW,IAAK,OAAO,GAAG,SAAS,CACnC,WAAW,IAAK,OAAO,GAAG,SAAS,CACnC,WAAW,IAAK,OAAO,GAAG,SAAS"}
|