@typed/router 0.31.0 → 1.0.0-beta.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.
Files changed (88) hide show
  1. package/README.md +111 -2
  2. package/dist/AST.d.ts +96 -0
  3. package/dist/AST.d.ts.map +1 -0
  4. package/dist/AST.js +32 -0
  5. package/dist/CurrentRoute.d.ts +18 -0
  6. package/dist/CurrentRoute.d.ts.map +1 -0
  7. package/dist/CurrentRoute.js +18 -0
  8. package/dist/Matcher.d.ts +191 -0
  9. package/dist/Matcher.d.ts.map +1 -0
  10. package/dist/Matcher.js +597 -0
  11. package/dist/Parser.d.ts +96 -0
  12. package/dist/Parser.d.ts.map +1 -0
  13. package/dist/Parser.js +1 -0
  14. package/dist/Path.d.ts +216 -0
  15. package/dist/Path.d.ts.map +1 -0
  16. package/dist/Path.js +248 -0
  17. package/dist/Route.d.ts +57 -0
  18. package/dist/Route.d.ts.map +1 -0
  19. package/dist/Route.js +151 -0
  20. package/dist/Router.d.ts +9 -0
  21. package/dist/Router.d.ts.map +1 -0
  22. package/dist/Router.js +8 -0
  23. package/dist/Uri.d.ts +115 -0
  24. package/dist/Uri.d.ts.map +1 -0
  25. package/dist/Uri.js +1 -0
  26. package/dist/index.d.ts +5 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +4 -0
  29. package/package.json +25 -69
  30. package/src/AST.ts +166 -0
  31. package/src/CurrentRoute.ts +30 -331
  32. package/src/Matcher.test.ts +476 -0
  33. package/src/Matcher.ts +1269 -328
  34. package/src/Parser.ts +282 -0
  35. package/src/Path.test.ts +318 -0
  36. package/src/Path.ts +691 -0
  37. package/src/Route.test.ts +268 -0
  38. package/src/Route.ts +316 -0
  39. package/src/Router.ts +31 -0
  40. package/src/Uri.ts +214 -0
  41. package/src/index.ts +4 -28
  42. package/tsconfig.json +6 -0
  43. package/CurrentRoute/package.json +0 -6
  44. package/LICENSE +0 -21
  45. package/MatchInput/package.json +0 -6
  46. package/Matcher/package.json +0 -6
  47. package/RouteGuard/package.json +0 -6
  48. package/RouteMatch/package.json +0 -6
  49. package/dist/cjs/CurrentRoute.js +0 -170
  50. package/dist/cjs/CurrentRoute.js.map +0 -1
  51. package/dist/cjs/MatchInput.js +0 -96
  52. package/dist/cjs/MatchInput.js.map +0 -1
  53. package/dist/cjs/Matcher.js +0 -138
  54. package/dist/cjs/Matcher.js.map +0 -1
  55. package/dist/cjs/RouteGuard.js +0 -78
  56. package/dist/cjs/RouteGuard.js.map +0 -1
  57. package/dist/cjs/RouteMatch.js +0 -49
  58. package/dist/cjs/RouteMatch.js.map +0 -1
  59. package/dist/cjs/index.js +0 -53
  60. package/dist/cjs/index.js.map +0 -1
  61. package/dist/dts/CurrentRoute.d.ts +0 -94
  62. package/dist/dts/CurrentRoute.d.ts.map +0 -1
  63. package/dist/dts/MatchInput.d.ts +0 -135
  64. package/dist/dts/MatchInput.d.ts.map +0 -1
  65. package/dist/dts/Matcher.d.ts +0 -121
  66. package/dist/dts/Matcher.d.ts.map +0 -1
  67. package/dist/dts/RouteGuard.d.ts +0 -94
  68. package/dist/dts/RouteGuard.d.ts.map +0 -1
  69. package/dist/dts/RouteMatch.d.ts +0 -50
  70. package/dist/dts/RouteMatch.d.ts.map +0 -1
  71. package/dist/dts/index.d.ts +0 -24
  72. package/dist/dts/index.d.ts.map +0 -1
  73. package/dist/esm/CurrentRoute.js +0 -152
  74. package/dist/esm/CurrentRoute.js.map +0 -1
  75. package/dist/esm/MatchInput.js +0 -79
  76. package/dist/esm/MatchInput.js.map +0 -1
  77. package/dist/esm/Matcher.js +0 -130
  78. package/dist/esm/Matcher.js.map +0 -1
  79. package/dist/esm/RouteGuard.js +0 -57
  80. package/dist/esm/RouteGuard.js.map +0 -1
  81. package/dist/esm/RouteMatch.js +0 -29
  82. package/dist/esm/RouteMatch.js.map +0 -1
  83. package/dist/esm/index.js +0 -24
  84. package/dist/esm/index.js.map +0 -1
  85. package/dist/esm/package.json +0 -4
  86. package/src/MatchInput.ts +0 -282
  87. package/src/RouteGuard.ts +0 -217
  88. package/src/RouteMatch.ts +0 -104
package/src/RouteGuard.ts DELETED
@@ -1,217 +0,0 @@
1
- /**
2
- * @since 1.0.0
3
- */
4
-
5
- import * as Guard from "@typed/guard"
6
- import * as Route from "@typed/route"
7
- import * as Effect from "effect/Effect"
8
- import { dual, flow } from "effect/Function"
9
- import * as Option from "effect/Option"
10
-
11
- /**
12
- * @since 1.0.0
13
- */
14
- export interface RouteGuard<R extends Route.Route.Any, B, E2, R2> {
15
- readonly route: R
16
- readonly guard: Guard.Guard<string, B, E2, R2>
17
- }
18
-
19
- /**
20
- * @since 1.0.0
21
- */
22
- export namespace RouteGuard {
23
- /**
24
- * @since 1.0.0
25
- */
26
- export type Any = RouteGuard<Route.Route.Any, any, any, any>
27
-
28
- /**
29
- * @since 1.0.0
30
- */
31
- export type Route<T> = T extends RouteGuard<infer _R, infer _B, infer _E2, infer _R2> ? T["route"] : never
32
-
33
- /**
34
- * @since 1.0.0
35
- */
36
- export type Context<T> = T extends RouteGuard<infer _R, infer _B, infer _E2, infer R2> ? R2 : never
37
-
38
- /**
39
- * @since 1.0.0
40
- */
41
- export type Error<T> = T extends RouteGuard<infer _R, infer _B, infer E2, infer _R2> ? E2 : never
42
-
43
- /**
44
- * @since 1.0.0
45
- */
46
- export type Success<T> = T extends RouteGuard<infer _R, infer B, infer _E2, infer _R2> ? B : never
47
-
48
- /**
49
- * @since 1.0.0
50
- */
51
- export type UpdateSuccess<R extends RouteGuard.Any, B> = RouteGuard<
52
- Route<R>,
53
- B,
54
- Route.RouteDecodeError<R["route"]>,
55
- Route.Route.Context<Route<R>>
56
- >
57
- }
58
-
59
- /**
60
- * @since 1.0.0
61
- */
62
- export function make<R extends Route.Route.Any, B, E2, R2>(
63
- route: R,
64
- guard: Guard.Guard<string, B, E2, R2>
65
- ): RouteGuard<R, B, E2, R2> {
66
- return { route, guard }
67
- }
68
-
69
- /**
70
- * @since 1.0.0
71
- */
72
- export function fromRoute<R extends Route.Route.Any>(
73
- route: R
74
- ): RouteGuard<R, Route.Route.Type<R>, Route.RouteDecodeError<R>, Route.Route.Context<R>> {
75
- return make(route, flow(Route.decode_(route), Effect.optionFromOptional))
76
- }
77
-
78
- /**
79
- * @since 1.0.0
80
- */
81
- export const map: {
82
- <R extends RouteGuard.Any, C>(
83
- f: (b: NoInfer<RouteGuard.Success<R>>) => C
84
- ): (self: R) => RouteGuard<RouteGuard.Route<R>, C, RouteGuard.Error<R>, RouteGuard.Context<R>>
85
-
86
- <R extends RouteGuard.Any, C>(
87
- self: R,
88
- f: (b: NoInfer<RouteGuard.Success<R>>) => C
89
- ): RouteGuard<RouteGuard.Route<R>, C, RouteGuard.Error<R>, RouteGuard.Context<R>>
90
- } = dual(2, function map<R extends RouteGuard.Any, C>(
91
- self: R,
92
- f: (b: NoInfer<RouteGuard.Success<R>>) => C
93
- ): RouteGuard<RouteGuard.Route<R>, C, RouteGuard.Error<R>, RouteGuard.Context<R>> {
94
- return make(self.route, Guard.map(self.guard, f)) as any
95
- })
96
-
97
- /**
98
- * @since 1.0.0
99
- */
100
- export const mapEffect: {
101
- <R extends RouteGuard.Any, C, E3, R3>(
102
- f: (b: NoInfer<RouteGuard.Success<R>>) => Effect.Effect<C, E3, R3>
103
- ): (self: R) => RouteGuard<RouteGuard.Route<R>, C, E3 | RouteGuard.Error<R>, R3 | RouteGuard.Context<R>>
104
-
105
- <R extends RouteGuard.Any, C, E3, R3>(
106
- self: R,
107
- f: (b: NoInfer<RouteGuard.Success<R>>) => Effect.Effect<C, E3, R3>
108
- ): RouteGuard<RouteGuard.Route<R>, C, E3 | RouteGuard.Error<R>, R3 | RouteGuard.Context<R>>
109
- } = dual(2, function mapEffect<R extends RouteGuard.Any, C, E3, R3>(
110
- self: R,
111
- f: (b: NoInfer<RouteGuard.Success<R>>) => Effect.Effect<C, E3, R3>
112
- ): RouteGuard<RouteGuard.Route<R>, C, RouteGuard.Error<R> | E3, RouteGuard.Context<R> | R3> {
113
- return make(self.route, Guard.mapEffect(self.guard, f)) as any
114
- })
115
-
116
- /**
117
- * @since 1.0.0
118
- */
119
- export const filter: {
120
- <R extends RouteGuard.Any>(f: (b: NoInfer<RouteGuard.Success<R>>) => boolean): (self: R) => R
121
- <R extends RouteGuard.Any>(self: R, f: (b: NoInfer<RouteGuard.Success<R>>) => boolean): R
122
- } = dual(2, function filter<R extends RouteGuard.Any>(
123
- self: R,
124
- f: (b: NoInfer<RouteGuard.Success<R>>) => boolean
125
- ): R {
126
- return make(self.route, Guard.filter(self.guard, f)) as any
127
- })
128
-
129
- /**
130
- * @since 1.0.0
131
- */
132
- export const filterMap: {
133
- <R extends RouteGuard.Any, C>(
134
- f: (b: NoInfer<RouteGuard.Success<R>>) => Option.Option<C>
135
- ): (self: R) => RouteGuard<RouteGuard.Route<R>, C, RouteGuard.Error<R>, RouteGuard.Context<R>>
136
-
137
- <R extends RouteGuard.Any, C>(
138
- self: R,
139
- f: (b: NoInfer<RouteGuard.Success<R>>) => Option.Option<C>
140
- ): RouteGuard<RouteGuard.Route<R>, C, RouteGuard.Error<R>, RouteGuard.Context<R>>
141
- } = dual(2, function filterMap<R extends RouteGuard.Any, C>(
142
- self: R,
143
- f: (b: NoInfer<RouteGuard.Success<R>>) => Option.Option<C>
144
- ): RouteGuard<RouteGuard.Route<R>, C, RouteGuard.Error<R>, RouteGuard.Context<R>> {
145
- return make(self.route, Guard.filterMap(self.guard, f)) as any
146
- })
147
-
148
- /**
149
- * @since 1.0.0
150
- */
151
- export const flatMap: {
152
- <R extends RouteGuard.Any, C, E3, R3>(
153
- guard: Guard.Guard<RouteGuard.Success<R>, C, E3, R3>
154
- ): (self: R) => RouteGuard<RouteGuard.Route<R>, C, E3 | RouteGuard.Error<R>, R3 | RouteGuard.Context<R>>
155
-
156
- <R extends RouteGuard.Any, C, E3, R3>(
157
- self: R,
158
- guard: Guard.Guard<RouteGuard.Success<R>, C, E3, R3>
159
- ): RouteGuard<RouteGuard.Route<R>, C, E3 | RouteGuard.Error<R>, R3 | RouteGuard.Context<R>>
160
- } = dual(2, function flatMap<R extends RouteGuard.Any, C, E3, R3>(
161
- self: R,
162
- guard: Guard.Guard<RouteGuard.Success<R>, C, E3, R3>
163
- ): RouteGuard<RouteGuard.Route<R>, C, RouteGuard.Error<R> | E3, RouteGuard.Context<R> | R3> {
164
- return make(self.route, Guard.compose(self.guard, guard)) as any
165
- })
166
-
167
- /**
168
- * @since 1.0.0
169
- */
170
- export const concat: {
171
- <R extends RouteGuard.Any>(
172
- other: R
173
- ): <L extends RouteGuard.Any>(self: L) => RouteGuard<
174
- Route.Route.Concat<RouteGuard.Route<L>, RouteGuard.Route<R>>,
175
- RouteGuard.Success<L> & RouteGuard.Success<R>,
176
- RouteGuard.Error<L> | RouteGuard.Error<R>,
177
- RouteGuard.Context<L> | RouteGuard.Context<R>
178
- >
179
-
180
- <L extends RouteGuard.Any, R extends RouteGuard.Any>(
181
- self: L,
182
- other: R
183
- ): RouteGuard<
184
- Route.Route.Concat<RouteGuard.Route<L>, RouteGuard.Route<R>>,
185
- RouteGuard.Success<L> & RouteGuard.Success<R>,
186
- RouteGuard.Error<L> | RouteGuard.Error<R>,
187
- RouteGuard.Context<L> | RouteGuard.Context<R>
188
- >
189
- } = dual(2, function concat<L extends RouteGuard.Any, R extends RouteGuard.Any>(
190
- self: L,
191
- other: R
192
- ): RouteGuard<
193
- Route.Route.Concat<RouteGuard.Route<L>, RouteGuard.Route<R>>,
194
- RouteGuard.Success<L> & RouteGuard.Success<R>,
195
- RouteGuard.Error<L> | RouteGuard.Error<R>,
196
- RouteGuard.Context<L> | RouteGuard.Context<R>
197
- > {
198
- return make<
199
- Route.Route.Concat<RouteGuard.Route<L>, RouteGuard.Route<R>>,
200
- RouteGuard.Success<L> & RouteGuard.Success<R>,
201
- RouteGuard.Error<L> | RouteGuard.Error<R>,
202
- RouteGuard.Context<L> | RouteGuard.Context<R>
203
- >(
204
- Route.concat(self.route, other.route) as any,
205
- (input) =>
206
- Effect.Do.pipe(
207
- Effect.bind("a", () => self.guard(input)),
208
- Effect.bind("b", () => other.guard(input)),
209
- Effect.map((options) =>
210
- Option.map(
211
- Option.all(options),
212
- ({ a, b }) => ({ ...a, ...b }) as RouteGuard.Success<L> & RouteGuard.Success<R>
213
- )
214
- )
215
- )
216
- )
217
- })
package/src/RouteMatch.ts DELETED
@@ -1,104 +0,0 @@
1
- /**
2
- * @since 1.0.0
3
- */
4
-
5
- import { type Fx, middleware } from "@typed/fx/Fx"
6
- import type { RefSubject } from "@typed/fx/RefSubject"
7
- import type { Guard } from "@typed/guard"
8
- import type * as Route from "@typed/route"
9
- import { flow } from "effect/Function"
10
- import { type CurrentRoute, withCurrentRoute } from "./CurrentRoute.js"
11
- import type { MatchInput } from "./MatchInput.js"
12
- import { asRouteGuard } from "./MatchInput.js"
13
- import * as RouteGuard from "./RouteGuard.js"
14
-
15
- /**
16
- * @since 1.0.0
17
- */
18
- export interface RouteMatch<R extends Route.Route.Any, B, E2, R2, C, E3, R3>
19
- extends RouteGuard.RouteGuard<R, B, E2, R2>
20
- {
21
- readonly match: (ref: RefSubject<B>) => Fx<C, E3, R3>
22
- }
23
-
24
- /**
25
- * @since 1.0.0
26
- */
27
- export namespace RouteMatch {
28
- /**
29
- * @since 1.0.0
30
- */
31
- export type Any<O = any> = RouteMatch<Route.Route.Any, any, any, any, O, any, any>
32
-
33
- /**
34
- * @since 1.0.0
35
- */
36
- export type Context<T> = T extends
37
- RouteMatch<infer _R, infer _B, infer _E2, infer _R2, infer _C, infer _E3, infer _R3> ? _R2 | _R3
38
- : never
39
-
40
- /**
41
- * @since 1.0.0
42
- */
43
- export type Error<T> = T extends RouteMatch<infer _R, infer _B, infer E2, infer _R2, infer _C, infer E3, infer _R3> ?
44
- E2 | E3
45
- : never
46
-
47
- /**
48
- * @since 1.0.0
49
- */
50
- export type Success<T> = T extends
51
- RouteMatch<infer _R, infer _B, infer _E2, infer _R2, infer C, infer _E3, infer _R3> ? C
52
- : never
53
- }
54
-
55
- /**
56
- * @since 1.0.0
57
- */
58
- export function make<R extends Route.Route.Any, B, E2, R2, C, E3, R3>(
59
- route: R,
60
- guard: Guard<string, B, E2, R2>,
61
- match: (ref: RefSubject<B>) => Fx<C, E3, R3>
62
- ): RouteMatch<R, B, E2, R2, C, E3, Exclude<R3, CurrentRoute>> {
63
- return { route, guard, match: flow(match, middleware(withCurrentRoute(route))) }
64
- }
65
-
66
- /**
67
- * @since 1.0.0
68
- */
69
- export function fromRoute<R extends Route.Route.Any, C, E3, R3>(
70
- route: R,
71
- match: (ref: RefSubject<Route.Route.Type<R>>) => Fx<C, E3, R3>
72
- ): RouteMatch<
73
- R,
74
- Route.Route.Type<R>,
75
- Route.RouteDecodeError<R>,
76
- Route.Route.Context<R>,
77
- C,
78
- E3,
79
- Exclude<R3, CurrentRoute>
80
- > {
81
- const { guard } = RouteGuard.fromRoute(route)
82
-
83
- return make(route, guard, match)
84
- }
85
-
86
- /**
87
- * @since 1.0.0
88
- */
89
- export function fromInput<I extends MatchInput.Any, A, E, R>(
90
- input: I,
91
- match: (ref: RefSubject<MatchInput.Success<I>>) => Fx<A, E, R>
92
- ): RouteMatch<
93
- MatchInput.Route<I>,
94
- MatchInput.Success<I>,
95
- MatchInput.Error<I>,
96
- MatchInput.Context<I>,
97
- A,
98
- E,
99
- Exclude<R, CurrentRoute>
100
- > {
101
- const { guard, route } = asRouteGuard(input)
102
-
103
- return make(route, guard, match)
104
- }