effect-start 0.20.1 → 0.22.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/README.md +1 -4
- package/dist/Cookies.js +392 -0
- package/dist/FileSystem.js +131 -0
- package/dist/Socket.js +37 -0
- package/package.json +39 -40
- package/src/Commander.ts +73 -130
- package/src/ContentNegotiation.ts +68 -100
- package/src/Cookies.ts +408 -0
- package/src/Development.ts +48 -63
- package/src/Effectify.ts +222 -206
- package/src/Entity.ts +59 -86
- package/src/FilePathPattern.ts +5 -5
- package/src/FileRouter.ts +38 -63
- package/src/FileRouterCodegen.ts +64 -56
- package/src/FileSystem.ts +390 -0
- package/src/Http.ts +17 -50
- package/src/PathPattern.ts +33 -41
- package/src/PlatformError.ts +29 -50
- package/src/PlatformRuntime.ts +39 -47
- package/src/Route.ts +68 -187
- package/src/RouteBody.ts +45 -161
- package/src/RouteHook.ts +22 -45
- package/src/RouteHttp.ts +88 -142
- package/src/RouteHttpTracer.ts +25 -26
- package/src/RouteMount.ts +100 -238
- package/src/RouteSchema.ts +67 -201
- package/src/RouteSse.ts +28 -82
- package/src/RouteTree.ts +31 -79
- package/src/RouteTrie.ts +13 -32
- package/src/SchemaExtra.ts +3 -5
- package/src/Socket.ts +51 -0
- package/src/Start.ts +20 -21
- package/src/StreamExtra.ts +93 -96
- package/src/TuplePathPattern.ts +54 -43
- package/src/Unique.ts +9 -15
- package/src/Values.ts +26 -30
- package/src/bun/BunBundle.ts +27 -73
- package/src/bun/BunImportTrackerPlugin.ts +67 -65
- package/src/bun/BunRoute.ts +12 -31
- package/src/bun/BunRuntime.ts +3 -10
- package/src/bun/BunServer.ts +50 -60
- package/src/bun/BunVirtualFilesPlugin.ts +1 -4
- package/src/bun/_BunEnhancedResolve.ts +17 -42
- package/src/bun/_empty.html +0 -1
- package/src/bundler/Bundle.ts +20 -36
- package/src/bundler/BundleFiles.ts +36 -56
- package/src/client/Overlay.ts +1 -2
- package/src/client/ScrollState.ts +5 -9
- package/src/client/index.ts +10 -13
- package/src/datastar/actions/fetch.ts +29 -48
- package/src/datastar/actions/peek.ts +1 -5
- package/src/datastar/actions/setAll.ts +2 -2
- package/src/datastar/actions/toggleAll.ts +2 -2
- package/src/datastar/attributes/attr.ts +17 -18
- package/src/datastar/attributes/bind.ts +41 -61
- package/src/datastar/attributes/class.ts +2 -5
- package/src/datastar/attributes/computed.ts +2 -10
- package/src/datastar/attributes/effect.ts +1 -2
- package/src/datastar/attributes/indicator.ts +2 -8
- package/src/datastar/attributes/init.ts +2 -10
- package/src/datastar/attributes/jsonSignals.ts +1 -6
- package/src/datastar/attributes/on.ts +4 -13
- package/src/datastar/attributes/onIntersect.ts +10 -22
- package/src/datastar/attributes/onInterval.ts +2 -10
- package/src/datastar/attributes/onSignalPatch.ts +18 -28
- package/src/datastar/attributes/ref.ts +1 -2
- package/src/datastar/attributes/show.ts +1 -2
- package/src/datastar/attributes/signals.ts +1 -5
- package/src/datastar/attributes/style.ts +6 -12
- package/src/datastar/attributes/text.ts +1 -2
- package/src/datastar/engine.ts +102 -158
- package/src/datastar/index.ts +2 -2
- package/src/datastar/utils.ts +16 -51
- package/src/datastar/watchers/patchElements.ts +35 -93
- package/src/datastar/watchers/patchSignals.ts +1 -2
- package/src/experimental/EncryptedCookies.ts +81 -175
- package/src/experimental/index.ts +0 -1
- package/src/hyper/Hyper.ts +14 -33
- package/src/hyper/HyperHtml.ts +13 -10
- package/src/hyper/HyperNode.ts +2 -7
- package/src/hyper/HyperRoute.ts +2 -5
- package/src/hyper/jsx-runtime.ts +2 -10
- package/src/hyper/jsx.d.ts +171 -440
- package/src/lint/plugin.js +276 -0
- package/src/node/NodeFileSystem.ts +140 -202
- package/src/node/NodeUtils.ts +1 -3
- package/src/testing/TestLogger.ts +9 -22
- package/src/testing/index.ts +0 -1
- package/src/testing/utils.ts +30 -31
- package/src/x/cloudflare/CloudflareTunnel.ts +53 -65
- package/src/x/datastar/Datastar.ts +3 -10
- package/src/x/datastar/index.ts +1 -3
- package/src/x/datastar/jsx-datastar.d.ts +1 -4
- package/src/x/tailwind/TailwindPlugin.ts +119 -112
- package/src/x/tailwind/compile.ts +10 -33
- package/src/x/tailwind/plugin.ts +2 -2
- package/src/HttpAppExtra.ts +0 -478
- package/src/HttpUtils.ts +0 -17
- package/src/bun/BunPlatformHttpServer.ts +0 -88
- package/src/bun/BunServerRequest.ts +0 -396
- package/src/bundler/BundleHttp.ts +0 -259
- package/src/experimental/SseHttpResponse.ts +0 -55
- package/src/middlewares/BasicAuthMiddleware.ts +0 -36
- package/src/middlewares/index.ts +0 -1
- package/src/testing/TestHttpClient.ts +0 -148
package/src/RouteBody.ts
CHANGED
|
@@ -5,12 +5,7 @@ import * as Entity from "./Entity.ts"
|
|
|
5
5
|
import * as Route from "./Route.ts"
|
|
6
6
|
import type * as Values from "./Values.ts"
|
|
7
7
|
|
|
8
|
-
export type Format =
|
|
9
|
-
| "text"
|
|
10
|
-
| "html"
|
|
11
|
-
| "json"
|
|
12
|
-
| "bytes"
|
|
13
|
-
| "*"
|
|
8
|
+
export type Format = "text" | "html" | "json" | "bytes" | "*"
|
|
14
9
|
|
|
15
10
|
const formatToContentType: Record<Format, string | undefined> = {
|
|
16
11
|
text: "text/plain; charset=utf-8",
|
|
@@ -22,19 +17,13 @@ const formatToContentType: Record<Format, string | undefined> = {
|
|
|
22
17
|
|
|
23
18
|
type UnwrapStream<T> = T extends Stream.Stream<infer V, any, any> ? V : T
|
|
24
19
|
|
|
25
|
-
type YieldError<T> = T extends Utils.YieldWrap<Effect.Effect<any, infer E, any>>
|
|
26
|
-
? E
|
|
27
|
-
: never
|
|
20
|
+
type YieldError<T> = T extends Utils.YieldWrap<Effect.Effect<any, infer E, any>> ? E : never
|
|
28
21
|
|
|
29
|
-
type YieldContext<T> = T extends
|
|
30
|
-
Utils.YieldWrap<Effect.Effect<any, any, infer R>> ? R
|
|
31
|
-
: never
|
|
22
|
+
type YieldContext<T> = T extends Utils.YieldWrap<Effect.Effect<any, any, infer R>> ? R : never
|
|
32
23
|
|
|
33
24
|
export type GeneratorHandler<B, A, Y> = (
|
|
34
25
|
context: Values.Simplify<B>,
|
|
35
|
-
next: (
|
|
36
|
-
context?: Partial<B> & Record<string, unknown>,
|
|
37
|
-
) => Entity.Entity<UnwrapStream<A>>,
|
|
26
|
+
next: (context?: Partial<B> & Record<string, unknown>) => Entity.Entity<UnwrapStream<A>>,
|
|
38
27
|
) => Generator<Y, A | Entity.Entity<A>, never>
|
|
39
28
|
|
|
40
29
|
export type HandlerInput<B, A, E, R> =
|
|
@@ -42,23 +31,13 @@ export type HandlerInput<B, A, E, R> =
|
|
|
42
31
|
| Entity.Entity<A>
|
|
43
32
|
| Effect.Effect<A | Entity.Entity<A>, E, R>
|
|
44
33
|
| ((
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
| Effect.Effect<A | Entity.Entity<A>, E, R>
|
|
51
|
-
| Generator<
|
|
52
|
-
Utils.YieldWrap<Effect.Effect<unknown, E, R>>,
|
|
53
|
-
A | Entity.Entity<A>,
|
|
54
|
-
unknown
|
|
55
|
-
>)
|
|
34
|
+
context: Values.Simplify<B>,
|
|
35
|
+
next: (context?: Partial<B> & Record<string, unknown>) => Entity.Entity<UnwrapStream<A>>,
|
|
36
|
+
) =>
|
|
37
|
+
| Effect.Effect<A | Entity.Entity<A>, E, R>
|
|
38
|
+
| Generator<Utils.YieldWrap<Effect.Effect<unknown, E, R>>, A | Entity.Entity<A>, unknown>)
|
|
56
39
|
|
|
57
|
-
export function handle<
|
|
58
|
-
B,
|
|
59
|
-
A,
|
|
60
|
-
Y extends Utils.YieldWrap<Effect.Effect<any, any, any>>,
|
|
61
|
-
>(
|
|
40
|
+
export function handle<B, A, Y extends Utils.YieldWrap<Effect.Effect<any, any, any>>>(
|
|
62
41
|
handler: GeneratorHandler<B, A, Y>,
|
|
63
42
|
): Route.Route.Handler<B, A, YieldError<Y>, YieldContext<Y>>
|
|
64
43
|
export function handle<B, A, E, R>(
|
|
@@ -70,32 +49,25 @@ export function handle<B, A, E, R>(
|
|
|
70
49
|
if (typeof handler === "function") {
|
|
71
50
|
return (
|
|
72
51
|
context: B,
|
|
73
|
-
next: (
|
|
74
|
-
context?: Partial<B> & Record<string, unknown>,
|
|
75
|
-
) => Entity.Entity<A>,
|
|
52
|
+
next: (context?: Partial<B> & Record<string, unknown>) => Entity.Entity<A>,
|
|
76
53
|
): Effect.Effect<Entity.Entity<A>, E, R> => {
|
|
77
54
|
const result = (handler as Function)(context, next)
|
|
78
55
|
const effect = Effect.isEffect(result)
|
|
79
|
-
? result as Effect.Effect<A | Entity.Entity<A>, E, R>
|
|
80
|
-
: Effect.gen(function*() {
|
|
81
|
-
|
|
82
|
-
|
|
56
|
+
? (result as Effect.Effect<A | Entity.Entity<A>, E, R>)
|
|
57
|
+
: (Effect.gen(function* () {
|
|
58
|
+
return yield* result
|
|
59
|
+
}) as Effect.Effect<A | Entity.Entity<A>, E, R>)
|
|
83
60
|
return Effect.map(effect, normalizeToEntity)
|
|
84
61
|
}
|
|
85
62
|
}
|
|
86
63
|
if (Effect.isEffect(handler)) {
|
|
87
64
|
return (_context, _next) =>
|
|
88
|
-
Effect.map(handler, normalizeToEntity) as Effect.Effect<
|
|
89
|
-
Entity.Entity<A>,
|
|
90
|
-
E,
|
|
91
|
-
R
|
|
92
|
-
>
|
|
65
|
+
Effect.map(handler, normalizeToEntity) as Effect.Effect<Entity.Entity<A>, E, R>
|
|
93
66
|
}
|
|
94
67
|
if (Entity.isEntity(handler)) {
|
|
95
68
|
return (_context, _next) => Effect.succeed(handler as Entity.Entity<A>)
|
|
96
69
|
}
|
|
97
|
-
return (_context, _next) =>
|
|
98
|
-
Effect.succeed(normalizeToEntity(handler as A) as Entity.Entity<A>)
|
|
70
|
+
return (_context, _next) => Effect.succeed(normalizeToEntity(handler as A) as Entity.Entity<A>)
|
|
99
71
|
}
|
|
100
72
|
|
|
101
73
|
function normalizeToEntity<A>(value: A | Entity.Entity<A>): Entity.Entity<A> {
|
|
@@ -105,87 +77,47 @@ function normalizeToEntity<A>(value: A | Entity.Entity<A>): Entity.Entity<A> {
|
|
|
105
77
|
return Entity.make(value as A, { status: 200 })
|
|
106
78
|
}
|
|
107
79
|
|
|
108
|
-
export interface BuildReturn<
|
|
109
|
-
Value,
|
|
110
|
-
F extends Format,
|
|
111
|
-
> {
|
|
80
|
+
export interface BuildReturn<Value, F extends Format> {
|
|
112
81
|
<
|
|
113
82
|
D extends Route.RouteDescriptor.Any,
|
|
114
83
|
B,
|
|
115
84
|
I extends Route.Route.Tuple,
|
|
116
|
-
A extends F extends "json" ? Value
|
|
117
|
-
: Value | Stream.Stream<Value, any, any>,
|
|
85
|
+
A extends F extends "json" ? Value : Value | Stream.Stream<Value, any, any>,
|
|
118
86
|
Y extends Utils.YieldWrap<Effect.Effect<any, any, any>>,
|
|
119
87
|
>(
|
|
120
|
-
handler: GeneratorHandler<
|
|
121
|
-
NoInfer<D & B & Route.ExtractBindings<I> & { format: F }>,
|
|
122
|
-
A,
|
|
123
|
-
Y
|
|
124
|
-
>,
|
|
88
|
+
handler: GeneratorHandler<NoInfer<D & B & Route.ExtractBindings<I> & { format: F }>, A, Y>,
|
|
125
89
|
): (
|
|
126
90
|
self: Route.RouteSet.RouteSet<D, B, I>,
|
|
127
91
|
) => Route.RouteSet.RouteSet<
|
|
128
92
|
D,
|
|
129
93
|
B,
|
|
130
|
-
[
|
|
131
|
-
...I,
|
|
132
|
-
Route.Route.Route<{ format: F }, {}, A, YieldError<Y>, YieldContext<Y>>,
|
|
133
|
-
]
|
|
94
|
+
[...I, Route.Route.Route<{ format: F }, {}, A, YieldError<Y>, YieldContext<Y>>]
|
|
134
95
|
>
|
|
135
96
|
|
|
136
97
|
<
|
|
137
98
|
D extends Route.RouteDescriptor.Any,
|
|
138
99
|
B,
|
|
139
100
|
I extends Route.Route.Tuple,
|
|
140
|
-
A extends F extends "json" ? Value
|
|
141
|
-
: Value | Stream.Stream<Value, any, any>,
|
|
101
|
+
A extends F extends "json" ? Value : Value | Stream.Stream<Value, any, any>,
|
|
142
102
|
E = never,
|
|
143
103
|
R = never,
|
|
144
104
|
>(
|
|
145
|
-
handler: HandlerInput<
|
|
146
|
-
NoInfer<
|
|
147
|
-
D & B & Route.ExtractBindings<I> & { format: F }
|
|
148
|
-
>,
|
|
149
|
-
A,
|
|
150
|
-
E,
|
|
151
|
-
R
|
|
152
|
-
>,
|
|
105
|
+
handler: HandlerInput<NoInfer<D & B & Route.ExtractBindings<I> & { format: F }>, A, E, R>,
|
|
153
106
|
): (
|
|
154
107
|
self: Route.RouteSet.RouteSet<D, B, I>,
|
|
155
|
-
) => Route.RouteSet.RouteSet<
|
|
156
|
-
D,
|
|
157
|
-
B,
|
|
158
|
-
[...I, Route.Route.Route<{ format: F }, {}, A, E, R>]
|
|
159
|
-
>
|
|
108
|
+
) => Route.RouteSet.RouteSet<D, B, [...I, Route.Route.Route<{ format: F }, {}, A, E, R>]>
|
|
160
109
|
}
|
|
161
110
|
|
|
162
|
-
export function build<
|
|
163
|
-
|
|
164
|
-
F extends Format,
|
|
165
|
-
>(
|
|
166
|
-
descriptors: { format: F },
|
|
167
|
-
) {
|
|
168
|
-
return (function<
|
|
111
|
+
export function build<Value, F extends Format>(descriptors: { format: F }) {
|
|
112
|
+
return function <
|
|
169
113
|
D extends Route.RouteDescriptor.Any,
|
|
170
114
|
B extends {},
|
|
171
115
|
I extends Route.Route.Tuple,
|
|
172
|
-
A extends F extends "json" ? Value
|
|
173
|
-
: Value | Stream.Stream<Value, any, any>,
|
|
116
|
+
A extends F extends "json" ? Value : Value | Stream.Stream<Value, any, any>,
|
|
174
117
|
E = never,
|
|
175
118
|
R = never,
|
|
176
|
-
>(
|
|
177
|
-
|
|
178
|
-
NoInfer<
|
|
179
|
-
D & B & Route.ExtractBindings<I> & { format: F }
|
|
180
|
-
>,
|
|
181
|
-
A,
|
|
182
|
-
E,
|
|
183
|
-
R
|
|
184
|
-
>,
|
|
185
|
-
) {
|
|
186
|
-
return function(
|
|
187
|
-
self: Route.RouteSet.RouteSet<D, B, I>,
|
|
188
|
-
) {
|
|
119
|
+
>(handler: HandlerInput<NoInfer<D & B & Route.ExtractBindings<I> & { format: F }>, A, E, R>) {
|
|
120
|
+
return function (self: Route.RouteSet.RouteSet<D, B, I>) {
|
|
189
121
|
const contentType = formatToContentType[descriptors.format]
|
|
190
122
|
const baseHandler = handle(handler)
|
|
191
123
|
const wrappedHandler: Route.Route.Handler<
|
|
@@ -194,44 +126,32 @@ export function build<
|
|
|
194
126
|
E,
|
|
195
127
|
R
|
|
196
128
|
> = (ctx, next) =>
|
|
197
|
-
Effect.map(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
entity.
|
|
201
|
-
? entity
|
|
202
|
-
: Entity.make(entity.body, {
|
|
129
|
+
Effect.map(baseHandler(ctx as any, next as any), (entity) =>
|
|
130
|
+
entity.headers["content-type"]
|
|
131
|
+
? entity
|
|
132
|
+
: Entity.make(entity.body, {
|
|
203
133
|
status: entity.status,
|
|
204
134
|
url: entity.url,
|
|
205
135
|
headers: { ...entity.headers, "content-type": contentType },
|
|
206
136
|
}),
|
|
207
137
|
)
|
|
208
138
|
|
|
209
|
-
const route = Route.make<{ format: F }, {}, A, E, R>(
|
|
210
|
-
wrappedHandler as any,
|
|
211
|
-
descriptors,
|
|
212
|
-
)
|
|
139
|
+
const route = Route.make<{ format: F }, {}, A, E, R>(wrappedHandler as any, descriptors)
|
|
213
140
|
|
|
214
141
|
const items: [...I, Route.Route.Route<{ format: F }, {}, A, E, R>] = [
|
|
215
142
|
...Route.items(self),
|
|
216
143
|
route,
|
|
217
144
|
]
|
|
218
145
|
|
|
219
|
-
return Route.set<
|
|
220
|
-
D,
|
|
221
|
-
B,
|
|
222
|
-
[...I, Route.Route.Route<{ format: F }, {}, A, E, R>]
|
|
223
|
-
>(
|
|
146
|
+
return Route.set<D, B, [...I, Route.Route.Route<{ format: F }, {}, A, E, R>]>(
|
|
224
147
|
items,
|
|
225
148
|
Route.descriptor(self),
|
|
226
149
|
)
|
|
227
150
|
}
|
|
228
|
-
}
|
|
151
|
+
} as unknown as BuildReturn<Value, F>
|
|
229
152
|
}
|
|
230
153
|
|
|
231
|
-
export type RenderValue =
|
|
232
|
-
| string
|
|
233
|
-
| Uint8Array
|
|
234
|
-
| Stream.Stream<string | Uint8Array, any, any>
|
|
154
|
+
export type RenderValue = string | Uint8Array | Stream.Stream<string | Uint8Array, any, any>
|
|
235
155
|
|
|
236
156
|
export function render<
|
|
237
157
|
D extends Route.RouteDescriptor.Any,
|
|
@@ -240,20 +160,13 @@ export function render<
|
|
|
240
160
|
A extends RenderValue,
|
|
241
161
|
Y extends Utils.YieldWrap<Effect.Effect<any, any, any>>,
|
|
242
162
|
>(
|
|
243
|
-
handler: GeneratorHandler<
|
|
244
|
-
NoInfer<D & B & Route.ExtractBindings<I> & { format: "*" }>,
|
|
245
|
-
A,
|
|
246
|
-
Y
|
|
247
|
-
>,
|
|
163
|
+
handler: GeneratorHandler<NoInfer<D & B & Route.ExtractBindings<I> & { format: "*" }>, A, Y>,
|
|
248
164
|
): (
|
|
249
165
|
self: Route.RouteSet.RouteSet<D, B, I>,
|
|
250
166
|
) => Route.RouteSet.RouteSet<
|
|
251
167
|
D,
|
|
252
168
|
B,
|
|
253
|
-
[
|
|
254
|
-
...I,
|
|
255
|
-
Route.Route.Route<{ format: "*" }, {}, A, YieldError<Y>, YieldContext<Y>>,
|
|
256
|
-
]
|
|
169
|
+
[...I, Route.Route.Route<{ format: "*" }, {}, A, YieldError<Y>, YieldContext<Y>>]
|
|
257
170
|
>
|
|
258
171
|
export function render<
|
|
259
172
|
D extends Route.RouteDescriptor.Any,
|
|
@@ -263,21 +176,10 @@ export function render<
|
|
|
263
176
|
E = never,
|
|
264
177
|
R = never,
|
|
265
178
|
>(
|
|
266
|
-
handler: HandlerInput<
|
|
267
|
-
NoInfer<
|
|
268
|
-
D & B & Route.ExtractBindings<I> & { format: "*" }
|
|
269
|
-
>,
|
|
270
|
-
A,
|
|
271
|
-
E,
|
|
272
|
-
R
|
|
273
|
-
>,
|
|
179
|
+
handler: HandlerInput<NoInfer<D & B & Route.ExtractBindings<I> & { format: "*" }>, A, E, R>,
|
|
274
180
|
): (
|
|
275
181
|
self: Route.RouteSet.RouteSet<D, B, I>,
|
|
276
|
-
) => Route.RouteSet.RouteSet<
|
|
277
|
-
D,
|
|
278
|
-
B,
|
|
279
|
-
[...I, Route.Route.Route<{ format: "*" }, {}, A, E, R>]
|
|
280
|
-
>
|
|
182
|
+
) => Route.RouteSet.RouteSet<D, B, [...I, Route.Route.Route<{ format: "*" }, {}, A, E, R>]>
|
|
281
183
|
export function render<
|
|
282
184
|
D extends Route.RouteDescriptor.Any,
|
|
283
185
|
B extends {},
|
|
@@ -285,34 +187,16 @@ export function render<
|
|
|
285
187
|
A extends RenderValue,
|
|
286
188
|
E = never,
|
|
287
189
|
R = never,
|
|
288
|
-
>(
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
D & B & Route.ExtractBindings<I> & { format: "*" }
|
|
292
|
-
>,
|
|
293
|
-
A,
|
|
294
|
-
E,
|
|
295
|
-
R
|
|
296
|
-
>,
|
|
297
|
-
) {
|
|
298
|
-
return function(
|
|
299
|
-
self: Route.RouteSet.RouteSet<D, B, I>,
|
|
300
|
-
) {
|
|
301
|
-
const route = Route.make<{ format: "*" }, {}, A, E, R>(
|
|
302
|
-
handle(handler) as any,
|
|
303
|
-
{ format: "*" },
|
|
304
|
-
)
|
|
190
|
+
>(handler: HandlerInput<NoInfer<D & B & Route.ExtractBindings<I> & { format: "*" }>, A, E, R>) {
|
|
191
|
+
return function (self: Route.RouteSet.RouteSet<D, B, I>) {
|
|
192
|
+
const route = Route.make<{ format: "*" }, {}, A, E, R>(handle(handler) as any, { format: "*" })
|
|
305
193
|
|
|
306
194
|
const items: [...I, Route.Route.Route<{ format: "*" }, {}, A, E, R>] = [
|
|
307
195
|
...Route.items(self),
|
|
308
196
|
route,
|
|
309
197
|
]
|
|
310
198
|
|
|
311
|
-
return Route.set<
|
|
312
|
-
D,
|
|
313
|
-
B,
|
|
314
|
-
[...I, Route.Route.Route<{ format: "*" }, {}, A, E, R>]
|
|
315
|
-
>(
|
|
199
|
+
return Route.set<D, B, [...I, Route.Route.Route<{ format: "*" }, {}, A, E, R>]>(
|
|
316
200
|
items,
|
|
317
201
|
Route.descriptor(self),
|
|
318
202
|
)
|
package/src/RouteHook.ts
CHANGED
|
@@ -3,19 +3,15 @@ import type * as Utils from "effect/Utils"
|
|
|
3
3
|
import * as Entity from "./Entity.ts"
|
|
4
4
|
import * as Route from "./Route.ts"
|
|
5
5
|
|
|
6
|
-
export type FilterResult<BOut, E, R> =
|
|
7
|
-
| { context: BOut }
|
|
8
|
-
| Effect.Effect<{ context: BOut }, E, R>
|
|
6
|
+
export type FilterResult<BOut, E, R> = { context: BOut } | Effect.Effect<{ context: BOut }, E, R>
|
|
9
7
|
|
|
10
8
|
export type FilterHandlerInput<BIn, BOut, E, R> =
|
|
11
9
|
| FilterResult<BOut, E, R>
|
|
12
|
-
| ((
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
{ context: BOut },
|
|
17
|
-
unknown
|
|
18
|
-
>)
|
|
10
|
+
| ((
|
|
11
|
+
context: BIn,
|
|
12
|
+
) =>
|
|
13
|
+
| FilterResult<BOut, E, R>
|
|
14
|
+
| Generator<Utils.YieldWrap<Effect.Effect<unknown, E, R>>, { context: BOut }, unknown>)
|
|
19
15
|
|
|
20
16
|
export function filter<
|
|
21
17
|
D extends Route.RouteDescriptor.Any,
|
|
@@ -25,44 +21,25 @@ export function filter<
|
|
|
25
21
|
E = never,
|
|
26
22
|
R = never,
|
|
27
23
|
BIn = D & SB & Route.ExtractBindings<P>,
|
|
28
|
-
>(
|
|
29
|
-
filterHandler: FilterHandlerInput<BIn, BOut, E, R>,
|
|
30
|
-
) {
|
|
24
|
+
>(filterHandler: FilterHandlerInput<BIn, BOut, E, R>) {
|
|
31
25
|
const normalized = normalizeFilterHandler(filterHandler)
|
|
32
26
|
|
|
33
|
-
return function(
|
|
27
|
+
return function (
|
|
34
28
|
self: Route.RouteSet.RouteSet<D, SB, P>,
|
|
35
|
-
): Route.RouteSet.RouteSet<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
Route.Route.Route<{}, BOut, unknown, E, R>,
|
|
41
|
-
]
|
|
42
|
-
> {
|
|
43
|
-
const route = Route.make<
|
|
44
|
-
{},
|
|
45
|
-
BOut,
|
|
46
|
-
unknown,
|
|
47
|
-
E,
|
|
48
|
-
R
|
|
49
|
-
>((context: BOut, next: (ctx?: Partial<BOut>) => Entity.Entity<unknown>) =>
|
|
50
|
-
Effect.gen(function*() {
|
|
51
|
-
const filterResult = yield* normalized(context as unknown as BIn)
|
|
29
|
+
): Route.RouteSet.RouteSet<D, SB, [...P, Route.Route.Route<{}, BOut, unknown, E, R>]> {
|
|
30
|
+
const route = Route.make<{}, BOut, unknown, E, R>(
|
|
31
|
+
(context: BOut, next: (ctx?: Partial<BOut>) => Entity.Entity<unknown>) =>
|
|
32
|
+
Effect.gen(function* () {
|
|
33
|
+
const filterResult = yield* normalized(context as unknown as BIn)
|
|
52
34
|
|
|
53
|
-
|
|
54
|
-
? { ...context, ...filterResult.context }
|
|
55
|
-
: context
|
|
35
|
+
const mergedContext = filterResult ? { ...context, ...filterResult.context } : context
|
|
56
36
|
|
|
57
|
-
|
|
58
|
-
|
|
37
|
+
return yield* Entity.resolve(next(mergedContext as Partial<BOut>))
|
|
38
|
+
}),
|
|
59
39
|
)
|
|
60
40
|
|
|
61
41
|
return Route.set(
|
|
62
|
-
[
|
|
63
|
-
...Route.items(self),
|
|
64
|
-
route,
|
|
65
|
-
] as [...P, Route.Route.Route<{}, BOut, unknown, E, R>],
|
|
42
|
+
[...Route.items(self), route] as [...P, Route.Route.Route<{}, BOut, unknown, E, R>],
|
|
66
43
|
Route.descriptor(self),
|
|
67
44
|
)
|
|
68
45
|
}
|
|
@@ -70,10 +47,10 @@ export function filter<
|
|
|
70
47
|
|
|
71
48
|
function isGenerator(value: unknown): value is Generator {
|
|
72
49
|
return (
|
|
73
|
-
typeof value === "object"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
50
|
+
typeof value === "object" &&
|
|
51
|
+
value !== null &&
|
|
52
|
+
Symbol.iterator in value &&
|
|
53
|
+
typeof (value as Generator).next === "function"
|
|
77
54
|
)
|
|
78
55
|
}
|
|
79
56
|
|
|
@@ -89,7 +66,7 @@ function normalizeFilterHandler<BIn, BOut, E, R>(
|
|
|
89
66
|
}
|
|
90
67
|
|
|
91
68
|
if (isGenerator(result)) {
|
|
92
|
-
return Effect.gen(function*() {
|
|
69
|
+
return Effect.gen(function* () {
|
|
93
70
|
return yield* result
|
|
94
71
|
}) as Effect.Effect<{ context: BOut }, E, R>
|
|
95
72
|
}
|