@devp0nt/route0 1.0.0-next.76 → 1.0.0-next.78

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.
@@ -28,16 +28,24 @@ declare class Route0<TDefinition extends string, TSearchInput extends UnknownSea
28
28
  readonly params: _ParamsDefinition<TDefinition>;
29
29
  private _origin;
30
30
  private _callable;
31
- private _regexBaseStrictString?;
31
+ private _routeSegments?;
32
+ private _routeTokens?;
33
+ private _routePatternCandidates?;
34
+ private _pathParamsDefinition?;
35
+ private _definitionWithoutTrailingWildcard?;
36
+ private _routeRegexBaseStringRaw?;
32
37
  private _regexBaseString?;
33
- private _regexStrictString?;
34
38
  private _regexString?;
35
- private _regexStrict?;
36
39
  private _regex?;
37
40
  private _regexAncestor?;
41
+ private _regexDescendantMatchers?;
38
42
  private _captureKeys?;
39
43
  private _normalizedDefinition?;
40
44
  private _definitionParts?;
45
+ private static _getRouteSegments;
46
+ private static _normalizeRouteDefinition;
47
+ private static _normalizePathname;
48
+ private static _validateRouteDefinition;
41
49
  Infer: {
42
50
  ParamsDefinition: _ParamsDefinition<TDefinition>;
43
51
  ParamsInput: _ParamsInput<TDefinition>;
@@ -54,15 +62,14 @@ declare class Route0<TDefinition extends string, TSearchInput extends UnknownSea
54
62
  *
55
63
  * If an existing route/callable route is provided, it is cloned.
56
64
  */
57
- static create<TDefinition extends string>(definition: TDefinition | AnyRoute<TDefinition> | CallableRoute<TDefinition>, config?: RouteConfigInput): CallableRoute<TDefinition>;
65
+ static create<TDefinition extends string>(definition: TDefinition | AnyRoute<TDefinition> | CallableRoute<TDefinition>, config?: RouteConfigInput): CallableRoute<NormalizeRouteDefinition<TDefinition>>;
58
66
  /**
59
67
  * Normalizes a definition/route into a callable route.
60
68
  *
61
69
  * Unlike `create`, passing a callable route returns the same instance.
62
70
  */
63
- static from<TDefinition extends string, TSearchInput extends UnknownSearchInput>(definition: TDefinition | AnyRoute<TDefinition, TSearchInput> | CallableRoute<TDefinition, TSearchInput>): CallableRoute<TDefinition, TSearchInput>;
71
+ static from<TDefinition extends string, TSearchInput extends UnknownSearchInput>(definition: TDefinition | AnyRoute<TDefinition, TSearchInput> | CallableRoute<TDefinition, TSearchInput>): CallableRoute<NormalizeRouteDefinition<TDefinition>, TSearchInput>;
64
72
  private static _getAbsPath;
65
- private static _getParamsDefinitionByDefinition;
66
73
  search<TNewSearchInput extends UnknownSearchInput>(): CallableRoute<TDefinition, TNewSearchInput>;
67
74
  /** Extends the current route definition by appending a suffix route. */
68
75
  extend<TSuffixDefinition extends string>(suffixDefinition: TSuffixDefinition): CallableRoute<PathExtended<TDefinition, TSuffixDefinition>, TSearchInput>;
@@ -73,24 +80,24 @@ declare class Route0<TDefinition extends string, TSearchInput extends UnknownSea
73
80
  getTokens(): RouteToken[];
74
81
  /** Clones route with optional config override. */
75
82
  clone(config?: RouteConfigInput): CallableRoute<TDefinition>;
76
- get regexBaseStrictString(): string;
77
83
  get regexBaseString(): string;
78
- get regexStrictString(): string;
79
84
  get regexString(): string;
80
- get regexStrict(): RegExp;
81
85
  get regex(): RegExp;
82
86
  get regexAncestor(): RegExp;
87
+ private get regexDescendantMatchers();
83
88
  private get captureKeys();
89
+ private get routeSegments();
90
+ private get routeTokens();
91
+ private get routePatternCandidates();
92
+ private get pathParamsDefinition();
93
+ private get definitionWithoutTrailingWildcard();
94
+ private get routeRegexBaseStringRaw();
84
95
  private get normalizedDefinition();
85
96
  private get definitionParts();
86
97
  /** Fast pathname exact match check without building a full location object. */
87
98
  isExactPathnameMatch(pathname: string): boolean;
88
99
  /** Fast pathname exact or ancestor match check without building a full location object. */
89
100
  isExactOrAncestorPathnameMatch(pathname: string): boolean;
90
- /** Creates a grouped strict regex pattern string from many routes. */
91
- static getRegexStrictStringGroup(routes: AnyRoute[]): string;
92
- /** Creates a strict grouped regex from many routes. */
93
- static getRegexStrictGroup(routes: AnyRoute[]): RegExp;
94
101
  /** Creates a grouped regex pattern string from many routes. */
95
102
  static getRegexStringGroup(routes: AnyRoute[]): string;
96
103
  /** Creates a grouped regex from many routes. */
@@ -139,9 +146,14 @@ declare class Route0<TDefinition extends string, TSearchInput extends UnknownSea
139
146
  /** True when current route is broader/shallower than `other`. */
140
147
  isAncestor(other: AnyRoute | string | undefined): boolean;
141
148
  /** True when two route patterns can match the same concrete URL. */
149
+ isOverlap(other: AnyRoute | string | undefined): boolean;
150
+ /**
151
+ * True when overlap is not resolvable by route ordering inside one route set.
152
+ *
153
+ * Non-conflicting overlap means one route is a strict subset of another
154
+ * (e.g. `/x/y` is a strict subset of `/x/:id`) and can be safely ordered first.
155
+ */
142
156
  isConflict(other: AnyRoute | string | undefined): boolean;
143
- /** True when paths are same or can overlap when optional parts are omitted. */
144
- isMayBeSame(other: AnyRoute | string | undefined): boolean;
145
157
  /** Specificity comparator used for deterministic route ordering. */
146
158
  isMoreSpecificThan(other: AnyRoute | string | undefined): boolean;
147
159
  }
@@ -152,6 +164,7 @@ declare class Route0<TDefinition extends string, TSearchInput extends UnknownSea
152
164
  * and returns a "pretty" object with direct route access + helper methods under `._`.
153
165
  */
154
166
  declare class Routes<const T extends RoutesRecord = any> {
167
+ private static _getNormalizedPathnameFromInput;
155
168
  _routes: RoutesRecordHydrated<T>;
156
169
  _pathsOrdering: string[];
157
170
  _keysOrdering: string[];
@@ -422,8 +435,13 @@ type _RequiredParamKeys<TDefinition extends string> = {
422
435
  }[keyof _ParamsDefinition<TDefinition>];
423
436
  type ReplacePathParams<S extends string> = S extends `${infer Head}:${infer Tail}` ? Tail extends `${infer _Param}/${infer Rest}` ? ReplacePathParams<`${Head}${string}/${Rest}`> : `${Head}${string}` : S;
424
437
  type DedupeSlashes<S extends string> = S extends `${infer A}//${infer B}` ? DedupeSlashes<`${A}/${B}`> : S;
438
+ type EnsureLeadingSlash<S extends string> = S extends '' ? '/' : S extends `/${string}` ? S : `/${S}`;
439
+ type TrimTrailingSlash<S extends string> = S extends '/' ? '/' : S extends `${infer V}/` ? TrimTrailingSlash<V> : S;
440
+ type NormalizeRouteDefinition<S extends string> = TrimTrailingSlash<EnsureLeadingSlash<DedupeSlashes<S>>>;
425
441
  type EmptyRecord = Record<never, never>;
426
- type JoinPath<Parent extends string, Suffix extends string> = DedupeSlashes<Definition<Parent> extends infer A extends string ? Definition<Suffix> extends infer B extends string ? A extends '' ? B extends '' ? '' : B extends `/${string}` ? B : `/${B}` : B extends '' ? A : A extends `${string}/` ? `${A}${B}` : B extends `/${string}` ? `${A}${B}` : `${A}/${B}` : never : never>;
442
+ type JoinPath<Parent extends string, Suffix extends string> = NormalizeRouteDefinition<Definition<Parent> extends infer A extends string ? Definition<Suffix> extends infer B extends string ? NormalizeRouteDefinition<A> extends infer ANormalized extends string ? NormalizeRouteDefinition<B> extends infer BNormalized extends string ? BNormalized extends '/' ? ANormalized : ANormalized extends '/' ? BNormalized : `${ANormalized}/${BNormalized}` : never : never : never : never>;
443
+ type PathExtended<TSourceDefinitionDefinition extends string, TSuffixDefinitionDefinition extends string> = `${NormalizeRouteDefinition<JoinPath<StripTrailingWildcard<TSourceDefinitionDefinition>, TSuffixDefinitionDefinition>>}`;
444
+ type StripTrailingWildcard<TDefinition extends string> = TDefinition extends `${infer TPath}*?` ? NormalizeRouteDefinition<TPath> : TDefinition extends `${infer TPath}*` ? NormalizeRouteDefinition<TPath> : NormalizeRouteDefinition<TDefinition>;
427
445
  type OnlyIfNoParams<TRoute extends AnyRoute | string, Yes, No = never> = HasParams<TRoute> extends false ? Yes : No;
428
446
  type OnlyIfHasParams<TRoute extends AnyRoute | string, Yes, No = never> = HasParams<TRoute> extends true ? Yes : No;
429
447
  type GetPathInput<TDefinition extends string, TSearchInput extends UnknownSearchInput> = _ParamsInput<TDefinition> & {
@@ -431,8 +449,6 @@ type GetPathInput<TDefinition extends string, TSearchInput extends UnknownSearch
431
449
  '#'?: string | number;
432
450
  };
433
451
  type GetPathInputByRoute<TRoute extends AnyRoute | CallableRoute | string> = TRoute extends AnyRoute<any, infer TSearchInput> ? GetPathInput<Definition<TRoute>, TSearchInput> : TRoute extends string ? GetPathInput<TRoute, UnknownSearchInput> : never;
434
- type PathExtended<TSourceDefinitionDefinition extends string, TSuffixDefinitionDefinition extends string> = `${JoinPath<StripTrailingWildcard<TSourceDefinitionDefinition>, TSuffixDefinitionDefinition>}`;
435
- type StripTrailingWildcard<TDefinition extends string> = TDefinition extends `${infer TPath}*?` ? TPath : TDefinition extends `${infer TPath}*` ? TPath : TDefinition;
436
452
  type IsAny<T> = 0 extends 1 & T ? true : false;
437
453
  type _IsSameParams<T1 extends object | undefined, T2 extends object | undefined> = T1 extends undefined ? T2 extends undefined ? true : false : T2 extends undefined ? false : T1 extends T2 ? T2 extends T1 ? true : false : false;
438
454
  type _IsAncestor<T extends string, TAncestor extends string> = T extends TAncestor ? false : T extends `${TAncestor}${string}` ? true : false;
@@ -452,4 +468,4 @@ type SchemaRoute0<TInput extends Record<string, unknown>, TOutput extends Record
452
468
  safeParse: (input: unknown) => _SafeParseInputResult<TOutput>;
453
469
  };
454
470
 
455
- export { type AncestorLocation, type AncestorLocationState, type AnyLocation, type AnyRoute, type AnyRouteOrDefinition, type CallableRoute, type DedupeSlashes, type Definition, type DescendantLocation, type DescendantLocationState, type EmptyRecord, type ExactLocation, type ExactLocationState, type Extended, type ExtractRoute, type ExtractRoutesKeys, type GetPathInput, type GetPathInputByRoute, type HasParams, type HasRequiredParams, type HasWildcard, type IsAncestor, type IsAny, type IsDescendant, type IsParamsOptional, type IsSame, type IsSameParams, type JoinPath, type KnownLocation, type LocationParams, type OnlyIfHasParams, type OnlyIfNoParams, type ParamsDefinition, type ParamsInput, type ParamsInputStringOnly, type ParamsOutput, type PathExtended, type ReplacePathParams, Route0, type RouteConfigInput, type RouteToken, Routes, type RoutesPretty, type RoutesRecord, type RoutesRecordHydrated, type SchemaRoute0, type StripTrailingWildcard, type UnknownLocation, type UnknownLocationState, type UnknownSearchInput, type UnknownSearchParsed, type UnknownSearchParsedValue, type UnmatchedLocation, type UnmatchedLocationState, type WeakAncestorLocation, type WeakAncestorLocationState, type WeakDescendantLocation, type WeakDescendantLocationState, type _ExtractParamsDefinitionBySegments, type _GeneralLocation, type _IfNoKeys, type _IsAncestor, type _IsDescendant, type _IsSame, type _IsSameParams, type _MergeParamDefinitions, type _ParamDefinitionFromSegment, type _ParamsDefinition, type _ParamsInput, type _ParamsInputStringOnly, type _RequiredParamKeys, type _SafeParseInputResult, type _Simplify, type _SplitPathSegments };
471
+ export { type AncestorLocation, type AncestorLocationState, type AnyLocation, type AnyRoute, type AnyRouteOrDefinition, type CallableRoute, type DedupeSlashes, type Definition, type DescendantLocation, type DescendantLocationState, type EmptyRecord, type EnsureLeadingSlash, type ExactLocation, type ExactLocationState, type Extended, type ExtractRoute, type ExtractRoutesKeys, type GetPathInput, type GetPathInputByRoute, type HasParams, type HasRequiredParams, type HasWildcard, type IsAncestor, type IsAny, type IsDescendant, type IsParamsOptional, type IsSame, type IsSameParams, type JoinPath, type KnownLocation, type LocationParams, type NormalizeRouteDefinition, type OnlyIfHasParams, type OnlyIfNoParams, type ParamsDefinition, type ParamsInput, type ParamsInputStringOnly, type ParamsOutput, type PathExtended, type ReplacePathParams, Route0, type RouteConfigInput, type RouteToken, Routes, type RoutesPretty, type RoutesRecord, type RoutesRecordHydrated, type SchemaRoute0, type StripTrailingWildcard, type TrimTrailingSlash, type UnknownLocation, type UnknownLocationState, type UnknownSearchInput, type UnknownSearchParsed, type UnknownSearchParsedValue, type UnmatchedLocation, type UnmatchedLocationState, type WeakAncestorLocation, type WeakAncestorLocationState, type WeakDescendantLocation, type WeakDescendantLocationState, type _ExtractParamsDefinitionBySegments, type _GeneralLocation, type _IfNoKeys, type _IsAncestor, type _IsDescendant, type _IsSame, type _IsSameParams, type _MergeParamDefinitions, type _ParamDefinitionFromSegment, type _ParamsDefinition, type _ParamsInput, type _ParamsInputStringOnly, type _RequiredParamKeys, type _SafeParseInputResult, type _Simplify, type _SplitPathSegments };