@benjavicente/router-generator 1.166.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/cjs/config.cjs +134 -0
- package/dist/cjs/config.cjs.map +1 -0
- package/dist/cjs/config.d.cts +254 -0
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs +234 -0
- package/dist/cjs/filesystem/physical/getRouteNodes.cjs.map +1 -0
- package/dist/cjs/filesystem/physical/getRouteNodes.d.cts +25 -0
- package/dist/cjs/filesystem/physical/rootPathId.cjs +6 -0
- package/dist/cjs/filesystem/physical/rootPathId.cjs.map +1 -0
- package/dist/cjs/filesystem/physical/rootPathId.d.cts +1 -0
- package/dist/cjs/filesystem/virtual/config.cjs +39 -0
- package/dist/cjs/filesystem/virtual/config.cjs.map +1 -0
- package/dist/cjs/filesystem/virtual/config.d.cts +3 -0
- package/dist/cjs/filesystem/virtual/getRouteNodes.cjs +175 -0
- package/dist/cjs/filesystem/virtual/getRouteNodes.cjs.map +1 -0
- package/dist/cjs/filesystem/virtual/getRouteNodes.d.cts +9 -0
- package/dist/cjs/filesystem/virtual/loadConfigFile.cjs +12 -0
- package/dist/cjs/filesystem/virtual/loadConfigFile.cjs.map +1 -0
- package/dist/cjs/filesystem/virtual/loadConfigFile.d.cts +1 -0
- package/dist/cjs/generator.cjs +805 -0
- package/dist/cjs/generator.cjs.map +1 -0
- package/dist/cjs/generator.d.cts +116 -0
- package/dist/cjs/index.cjs +33 -0
- package/dist/cjs/index.d.cts +12 -0
- package/dist/cjs/logger.cjs +31 -0
- package/dist/cjs/logger.cjs.map +1 -0
- package/dist/cjs/logger.d.cts +10 -0
- package/dist/cjs/plugin/types.d.cts +18 -0
- package/dist/cjs/template.cjs +203 -0
- package/dist/cjs/template.cjs.map +1 -0
- package/dist/cjs/template.d.cts +34 -0
- package/dist/cjs/transform/transform.cjs +302 -0
- package/dist/cjs/transform/transform.cjs.map +1 -0
- package/dist/cjs/transform/transform.d.cts +4 -0
- package/dist/cjs/transform/types.d.cts +31 -0
- package/dist/cjs/transform/utils.cjs +34 -0
- package/dist/cjs/transform/utils.cjs.map +1 -0
- package/dist/cjs/transform/utils.d.cts +2 -0
- package/dist/cjs/types.d.cts +57 -0
- package/dist/cjs/utils.cjs +653 -0
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/utils.d.cts +212 -0
- package/dist/cjs/validate-route-params.cjs +73 -0
- package/dist/cjs/validate-route-params.cjs.map +1 -0
- package/dist/cjs/validate-route-params.d.cts +9 -0
- package/dist/esm/config.d.ts +254 -0
- package/dist/esm/config.js +129 -0
- package/dist/esm/config.js.map +1 -0
- package/dist/esm/filesystem/physical/getRouteNodes.d.ts +25 -0
- package/dist/esm/filesystem/physical/getRouteNodes.js +230 -0
- package/dist/esm/filesystem/physical/getRouteNodes.js.map +1 -0
- package/dist/esm/filesystem/physical/rootPathId.d.ts +1 -0
- package/dist/esm/filesystem/physical/rootPathId.js +6 -0
- package/dist/esm/filesystem/physical/rootPathId.js.map +1 -0
- package/dist/esm/filesystem/virtual/config.d.ts +3 -0
- package/dist/esm/filesystem/virtual/config.js +38 -0
- package/dist/esm/filesystem/virtual/config.js.map +1 -0
- package/dist/esm/filesystem/virtual/getRouteNodes.d.ts +9 -0
- package/dist/esm/filesystem/virtual/getRouteNodes.js +173 -0
- package/dist/esm/filesystem/virtual/getRouteNodes.js.map +1 -0
- package/dist/esm/filesystem/virtual/loadConfigFile.d.ts +1 -0
- package/dist/esm/filesystem/virtual/loadConfigFile.js +11 -0
- package/dist/esm/filesystem/virtual/loadConfigFile.js.map +1 -0
- package/dist/esm/generator.d.ts +116 -0
- package/dist/esm/generator.js +801 -0
- package/dist/esm/generator.js.map +1 -0
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/logger.d.ts +10 -0
- package/dist/esm/logger.js +31 -0
- package/dist/esm/logger.js.map +1 -0
- package/dist/esm/plugin/types.d.ts +18 -0
- package/dist/esm/template.d.ts +34 -0
- package/dist/esm/template.js +202 -0
- package/dist/esm/template.js.map +1 -0
- package/dist/esm/transform/transform.d.ts +4 -0
- package/dist/esm/transform/transform.js +301 -0
- package/dist/esm/transform/transform.js.map +1 -0
- package/dist/esm/transform/types.d.ts +31 -0
- package/dist/esm/transform/utils.d.ts +2 -0
- package/dist/esm/transform/utils.js +34 -0
- package/dist/esm/transform/utils.js.map +1 -0
- package/dist/esm/types.d.ts +57 -0
- package/dist/esm/utils.d.ts +212 -0
- package/dist/esm/utils.js +609 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/esm/validate-route-params.d.ts +9 -0
- package/dist/esm/validate-route-params.js +73 -0
- package/dist/esm/validate-route-params.js.map +1 -0
- package/package.json +82 -0
- package/src/config.ts +247 -0
- package/src/filesystem/physical/getRouteNodes.ts +541 -0
- package/src/filesystem/physical/rootPathId.ts +1 -0
- package/src/filesystem/virtual/config.ts +45 -0
- package/src/filesystem/virtual/getRouteNodes.ts +307 -0
- package/src/filesystem/virtual/loadConfigFile.ts +8 -0
- package/src/generator.ts +1686 -0
- package/src/index.ts +54 -0
- package/src/logger.ts +43 -0
- package/src/plugin/types.ts +18 -0
- package/src/template.ts +313 -0
- package/src/transform/transform.ts +534 -0
- package/src/transform/types.ts +39 -0
- package/src/transform/utils.ts +42 -0
- package/src/types.ts +74 -0
- package/src/utils.ts +1067 -0
- package/src/validate-route-params.ts +118 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { Config, TokenMatcher } from './config.js';
|
|
2
|
+
import { ImportDeclaration, RouteNode } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Prefix map for O(1) parent route lookups.
|
|
5
|
+
* Maps each route path prefix to the route node that owns that prefix.
|
|
6
|
+
* Enables finding longest matching parent without linear search.
|
|
7
|
+
*/
|
|
8
|
+
export declare class RoutePrefixMap {
|
|
9
|
+
private prefixToRoute;
|
|
10
|
+
private layoutRoutes;
|
|
11
|
+
constructor(routes: Array<RouteNode>);
|
|
12
|
+
/**
|
|
13
|
+
* Find the longest matching parent route for a given path.
|
|
14
|
+
* O(k) where k is the number of path segments, not O(n) routes.
|
|
15
|
+
*/
|
|
16
|
+
findParent(routePath: string): RouteNode | null;
|
|
17
|
+
/**
|
|
18
|
+
* Check if a route exists at the given path.
|
|
19
|
+
*/
|
|
20
|
+
has(routePath: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Get a route by exact path.
|
|
23
|
+
*/
|
|
24
|
+
get(routePath: string): RouteNode | undefined;
|
|
25
|
+
}
|
|
26
|
+
export declare function multiSortBy<T>(arr: Array<T>, accessors?: Array<(item: T) => any>): Array<T>;
|
|
27
|
+
export declare function cleanPath(path: string): string;
|
|
28
|
+
export declare function trimPathLeft(path: string): string;
|
|
29
|
+
export declare function removeLeadingSlash(path: string): string;
|
|
30
|
+
export declare function removeTrailingSlash(s: string): string;
|
|
31
|
+
export declare function determineInitialRoutePath(routePath: string): {
|
|
32
|
+
routePath: string;
|
|
33
|
+
originalRoutePath: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Checks if the leading underscore in a segment is escaped.
|
|
37
|
+
* Returns true if:
|
|
38
|
+
* - Segment starts with [_] pattern: "[_]layout" -> "_layout"
|
|
39
|
+
* - Segment is fully escaped and content starts with _: "[_1nd3x]" -> "_1nd3x"
|
|
40
|
+
*/
|
|
41
|
+
export declare function hasEscapedLeadingUnderscore(originalSegment: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Checks if the trailing underscore in a segment is escaped.
|
|
44
|
+
* Returns true if:
|
|
45
|
+
* - Segment ends with [_] pattern: "blog[_]" -> "blog_"
|
|
46
|
+
* - Segment is fully escaped and content ends with _: "[_r0ut3_]" -> "_r0ut3_"
|
|
47
|
+
*/
|
|
48
|
+
export declare function hasEscapedTrailingUnderscore(originalSegment: string): boolean;
|
|
49
|
+
export declare function replaceBackslash(s: string): string;
|
|
50
|
+
export declare function routePathToVariable(routePath: string): string;
|
|
51
|
+
export declare function removeUnderscores(s?: string): string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Removes underscores from a path, but preserves underscores that were escaped
|
|
54
|
+
* in the original path (indicated by [_] syntax).
|
|
55
|
+
*
|
|
56
|
+
* @param routePath - The path with brackets removed
|
|
57
|
+
* @param originalPath - The original path that may contain [_] escape sequences
|
|
58
|
+
* @returns The path with non-escaped underscores removed
|
|
59
|
+
*/
|
|
60
|
+
export declare function removeUnderscoresWithEscape(routePath?: string, originalPath?: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* Removes layout segments (segments starting with underscore) from a path,
|
|
63
|
+
* but preserves segments where the underscore was escaped.
|
|
64
|
+
*
|
|
65
|
+
* @param routePath - The path with brackets removed
|
|
66
|
+
* @param originalPath - The original path that may contain [_] escape sequences
|
|
67
|
+
* @returns The path with non-escaped layout segments removed
|
|
68
|
+
*/
|
|
69
|
+
export declare function removeLayoutSegmentsWithEscape(routePath?: string, originalPath?: string): string;
|
|
70
|
+
/**
|
|
71
|
+
* Checks if a segment should be treated as a pathless/layout segment.
|
|
72
|
+
* A segment is pathless if it starts with underscore and the underscore is not escaped.
|
|
73
|
+
*
|
|
74
|
+
* @param segment - The segment from routePath (brackets removed)
|
|
75
|
+
* @param originalSegment - The segment from originalRoutePath (may contain brackets)
|
|
76
|
+
* @returns true if the segment is pathless (has non-escaped leading underscore)
|
|
77
|
+
*/
|
|
78
|
+
export declare function isSegmentPathless(segment: string, originalSegment: string): boolean;
|
|
79
|
+
export declare function escapeRegExp(s: string): string;
|
|
80
|
+
export declare function createTokenRegex(token: TokenMatcher, opts: {
|
|
81
|
+
type: 'segment' | 'filename';
|
|
82
|
+
}): RegExp;
|
|
83
|
+
export declare function isBracketWrappedSegment(segment: string): boolean;
|
|
84
|
+
export declare function unwrapBracketWrappedSegment(segment: string): string;
|
|
85
|
+
export declare function removeLeadingUnderscores(s: string, routeToken: string): string;
|
|
86
|
+
export declare function removeTrailingUnderscores(s: string, routeToken: string): string;
|
|
87
|
+
export declare function capitalize(s: string): string;
|
|
88
|
+
export declare function removeExt(d: string, addExtensions?: boolean | string): string;
|
|
89
|
+
/**
|
|
90
|
+
* This function writes to a file if the content is different.
|
|
91
|
+
*
|
|
92
|
+
* @param filepath The path to the file
|
|
93
|
+
* @param content Original content
|
|
94
|
+
* @param incomingContent New content
|
|
95
|
+
* @param callbacks Callbacks to run before and after writing
|
|
96
|
+
* @returns Whether the file was written
|
|
97
|
+
*/
|
|
98
|
+
export declare function writeIfDifferent(filepath: string, content: string, incomingContent: string, callbacks?: {
|
|
99
|
+
beforeWrite?: () => void;
|
|
100
|
+
afterWrite?: () => void;
|
|
101
|
+
}): Promise<boolean>;
|
|
102
|
+
/**
|
|
103
|
+
* This function formats the source code using the default formatter (Prettier).
|
|
104
|
+
*
|
|
105
|
+
* @param source The content to format
|
|
106
|
+
* @param config The configuration object
|
|
107
|
+
* @returns The formatted content
|
|
108
|
+
*/
|
|
109
|
+
export declare function format(source: string, config: {
|
|
110
|
+
quoteStyle: 'single' | 'double';
|
|
111
|
+
semicolons: boolean;
|
|
112
|
+
}): Promise<string>;
|
|
113
|
+
/**
|
|
114
|
+
* This function resets the regex index to 0 so that it can be reused
|
|
115
|
+
* without having to create a new regex object or worry about the last
|
|
116
|
+
* state when using the global flag.
|
|
117
|
+
*
|
|
118
|
+
* @param regex The regex object to reset
|
|
119
|
+
* @returns
|
|
120
|
+
*/
|
|
121
|
+
export declare function resetRegex(regex: RegExp): void;
|
|
122
|
+
/**
|
|
123
|
+
* This function checks if a file exists.
|
|
124
|
+
*
|
|
125
|
+
* @param file The path to the file
|
|
126
|
+
* @returns Whether the file exists
|
|
127
|
+
*/
|
|
128
|
+
export declare function checkFileExists(file: string): Promise<boolean>;
|
|
129
|
+
export declare function removeGroups(s: string): string;
|
|
130
|
+
/**
|
|
131
|
+
* Removes all segments from a given path that start with an underscore ('_').
|
|
132
|
+
*
|
|
133
|
+
* @param {string} routePath - The path from which to remove segments. Defaults to '/'.
|
|
134
|
+
* @returns {string} The path with all underscore-prefixed segments removed.
|
|
135
|
+
* @example
|
|
136
|
+
* removeLayoutSegments('/workspace/_auth/foo') // '/workspace/foo'
|
|
137
|
+
*/
|
|
138
|
+
export declare function removeLayoutSegments(routePath?: string): string;
|
|
139
|
+
/**
|
|
140
|
+
* The `node.path` is used as the `id` in the route definition.
|
|
141
|
+
* This function checks if the given node has a parent and if so, it determines the correct path for the given node.
|
|
142
|
+
* @param node - The node to determine the path for.
|
|
143
|
+
* @returns The correct path for the given node.
|
|
144
|
+
*/
|
|
145
|
+
export declare function determineNodePath(node: RouteNode): string | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* Removes the last segment from a given path. Segments are considered to be separated by a '/'.
|
|
148
|
+
*
|
|
149
|
+
* @param {string} routePath - The path from which to remove the last segment. Defaults to '/'.
|
|
150
|
+
* @returns {string} The path with the last segment removed.
|
|
151
|
+
* @example
|
|
152
|
+
* removeLastSegmentFromPath('/workspace/_auth/foo') // '/workspace/_auth'
|
|
153
|
+
*/
|
|
154
|
+
export declare function removeLastSegmentFromPath(routePath?: string): string;
|
|
155
|
+
/**
|
|
156
|
+
* Find parent route using RoutePrefixMap for O(k) lookups instead of O(n).
|
|
157
|
+
*/
|
|
158
|
+
export declare function hasParentRoute(prefixMap: RoutePrefixMap, node: RouteNode, routePathToCheck: string | undefined): RouteNode | null;
|
|
159
|
+
/**
|
|
160
|
+
* Gets the final variable name for a route
|
|
161
|
+
*/
|
|
162
|
+
export declare const getResolvedRouteNodeVariableName: (routeNode: RouteNode) => string;
|
|
163
|
+
/**
|
|
164
|
+
* Checks if a given RouteNode is valid for augmenting it with typing based on conditions.
|
|
165
|
+
* Also asserts that the RouteNode is defined.
|
|
166
|
+
*
|
|
167
|
+
* @param routeNode - The RouteNode to check.
|
|
168
|
+
* @returns A boolean indicating whether the RouteNode is defined.
|
|
169
|
+
*/
|
|
170
|
+
export declare function isRouteNodeValidForAugmentation(routeNode?: RouteNode): routeNode is RouteNode;
|
|
171
|
+
/**
|
|
172
|
+
* Infers the path for use by TS
|
|
173
|
+
*/
|
|
174
|
+
export declare const inferPath: (routeNode: RouteNode) => string;
|
|
175
|
+
/**
|
|
176
|
+
* Infers the full path for use by TS
|
|
177
|
+
*/
|
|
178
|
+
export declare const inferFullPath: (routeNode: RouteNode) => string;
|
|
179
|
+
/**
|
|
180
|
+
* Creates a map from fullPath to routeNode
|
|
181
|
+
*/
|
|
182
|
+
export declare const createRouteNodesByFullPath: (routeNodes: Array<RouteNode>) => Map<string, RouteNode>;
|
|
183
|
+
/**
|
|
184
|
+
* Create a map from 'to' to a routeNode
|
|
185
|
+
*/
|
|
186
|
+
export declare const createRouteNodesByTo: (routeNodes: Array<RouteNode>) => Map<string, RouteNode>;
|
|
187
|
+
/**
|
|
188
|
+
* Create a map from 'id' to a routeNode
|
|
189
|
+
*/
|
|
190
|
+
export declare const createRouteNodesById: (routeNodes: Array<RouteNode>) => Map<string, RouteNode>;
|
|
191
|
+
/**
|
|
192
|
+
* Infers to path
|
|
193
|
+
*/
|
|
194
|
+
export declare const inferTo: (routeNode: RouteNode) => string;
|
|
195
|
+
/**
|
|
196
|
+
* Dedupes branches and index routes
|
|
197
|
+
*/
|
|
198
|
+
export declare const dedupeBranchesAndIndexRoutes: (routes: Array<RouteNode>) => Array<RouteNode>;
|
|
199
|
+
export declare function checkRouteFullPathUniqueness(_routes: Array<RouteNode>, config: Config): void;
|
|
200
|
+
export declare function buildRouteTreeConfig(nodes: Array<RouteNode>, disableTypes: boolean, depth?: number): Array<string>;
|
|
201
|
+
export declare function buildImportString(importDeclaration: ImportDeclaration): string;
|
|
202
|
+
export declare function lowerCaseFirstChar(value: string): string;
|
|
203
|
+
export declare function mergeImportDeclarations(imports: Array<ImportDeclaration>): Array<ImportDeclaration>;
|
|
204
|
+
export declare const findParent: (node: RouteNode | undefined) => string;
|
|
205
|
+
export declare function buildFileRoutesByPathInterface(opts: {
|
|
206
|
+
routeNodes: Array<RouteNode>;
|
|
207
|
+
module: string;
|
|
208
|
+
interfaceName: string;
|
|
209
|
+
config?: Pick<Config, 'routeToken'>;
|
|
210
|
+
}): string;
|
|
211
|
+
export declare function getImportPath(node: RouteNode, config: Config, generatedRouteTreePath: string): string;
|
|
212
|
+
export declare function getImportForRouteNode(node: RouteNode, config: Config, generatedRouteTreePath: string, root: string): ImportDeclaration;
|