@abide/abide 0.117.2 → 0.118.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/src/shared/url.ts CHANGED
@@ -12,26 +12,31 @@ type Parts<P extends string> = P extends `${infer Head}/${infer Tail}`
12
12
  ? Head | Parts<Tail>
13
13
  : P
14
14
 
15
+ // 23.26 — a segment's param is named before any `=`: `[symbol=TICKER]` is `symbol`.
16
+ type ParamName<Body extends string> = Body extends `${infer Name}=${string}`
17
+ ? Name
18
+ : Body
19
+
15
20
  export type RequiredNames<P extends string> =
16
21
  Parts<P> extends infer Part
17
22
  ? Part extends `[${infer Name}]`
18
23
  ? Name extends `[${string}` | `...${string}`
19
24
  ? never
20
- : Name
25
+ : ParamName<Name>
21
26
  : never
22
27
  : never
23
28
 
24
29
  export type OptionalNames<P extends string> =
25
30
  Parts<P> extends infer Part
26
31
  ? Part extends `[[${infer Name}]]`
27
- ? Name
32
+ ? ParamName<Name>
28
33
  : never
29
34
  : never
30
35
 
31
36
  export type RestNames<P extends string> =
32
37
  Parts<P> extends infer Part
33
38
  ? Part extends `[...${infer Name}]`
34
- ? Name
39
+ ? ParamName<Name>
35
40
  : never
36
41
  : never
37
42
 
@@ -51,18 +56,28 @@ export type HasSegments<P extends string> = [
51
56
 
52
57
  export type Query = Record<string, unknown> | URLSearchParams
53
58
 
54
- /** The params a route literal takes, by segment kind. */
59
+ /** The params a route literal takes, by segment kind, and 30.3 — narrowed where `abide check` says. */
55
60
  export type ParamsOf<P extends string> = {
56
61
  [K in RequiredNames<P>]: string | number
57
62
  } & { [K in OptionalNames<P>]?: string | number } & {
58
63
  [K in RestNames<P>]?: string | number | (string | number)[]
59
- }
64
+ } & Narrowed<P>
65
+
66
+ /**
67
+ * 23.9, 30.3 — the params `abide check` declared for `P` beside its key: each whose matcher is an
68
+ * alternation of literals, as their union. Nothing where it declared none, or nothing at all.
69
+ */
70
+ type Narrowed<P extends string> = P extends keyof Routes
71
+ ? Routes[P] extends true
72
+ ? unknown
73
+ : Routes[P]
74
+ : unknown
60
75
 
61
76
  /**
62
77
  * 30.26 — the route literals an app files its pages under, which `abide check` declares for the app
63
78
  * it checks. Where nothing declared them any literal is taken, so a plain `tsc` still compiles.
64
79
  */
65
- // biome-ignore lint/suspicious/noEmptyInterface: filled by declaration merging, per app
80
+ // biome-ignore lint/suspicious/noEmptyInterface: filled by declaration merging, per app — each literal to `true`, or to the params it narrows (23.9)
66
81
  export interface Routes {}
67
82
 
68
83
  /** 30.26 — what `url` takes: one of the app's route literals, or any where none were declared. */
@@ -76,7 +91,9 @@ export type RouteLiteral = [keyof Routes] extends [never]
76
91
  */
77
92
  export type RouteParams<P extends string> = {
78
93
  [K in RequiredNames<P>]: string
79
- } & { [K in OptionalNames<P>]?: string } & { [K in RestNames<P>]: string[] }
94
+ } & { [K in OptionalNames<P>]?: string } & {
95
+ [K in RestNames<P>]: string[]
96
+ } & Narrowed<P>
80
97
 
81
98
  /**
82
99
  * An address from a route literal and its params, resolved against the mount, with an optional