@effect/platform 0.13.11 → 0.13.13
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/Http/Body.d.ts +16 -0
- package/Http/Body.d.ts.map +1 -1
- package/Http/Body.js +7 -1
- package/Http/Body.js.map +1 -1
- package/Http/ClientRequest.d.ts +8 -0
- package/Http/ClientRequest.d.ts.map +1 -1
- package/Http/ClientRequest.js +7 -1
- package/Http/ClientRequest.js.map +1 -1
- package/Http/Etag.d.ts +2 -0
- package/Http/Etag.d.ts.map +1 -1
- package/Http/Etag.js.map +1 -1
- package/Http/Router.d.ts +45 -32
- package/Http/Router.d.ts.map +1 -1
- package/Http/Router.js.map +1 -1
- package/Http/ServerResponse.d.ts +5 -0
- package/Http/ServerResponse.d.ts.map +1 -1
- package/Http/ServerResponse.js +8 -2
- package/Http/ServerResponse.js.map +1 -1
- package/internal/http/body.js +6 -1
- package/internal/http/body.js.map +1 -1
- package/internal/http/clientRequest.js +4 -1
- package/internal/http/clientRequest.js.map +1 -1
- package/internal/http/router.d.ts +1 -1
- package/internal/http/router.d.ts.map +1 -1
- package/internal/http/router.js.map +1 -1
- package/internal/http/serverResponse.js +12 -1
- package/internal/http/serverResponse.js.map +1 -1
- package/mjs/Http/Body.mjs +5 -0
- package/mjs/Http/Body.mjs.map +1 -1
- package/mjs/Http/ClientRequest.mjs +5 -0
- package/mjs/Http/ClientRequest.mjs.map +1 -1
- package/mjs/Http/Etag.mjs.map +1 -1
- package/mjs/Http/Router.mjs.map +1 -1
- package/mjs/Http/ServerResponse.mjs +5 -0
- package/mjs/Http/ServerResponse.mjs.map +1 -1
- package/mjs/internal/http/body.mjs +4 -0
- package/mjs/internal/http/body.mjs.map +1 -1
- package/mjs/internal/http/clientRequest.mjs +2 -0
- package/mjs/internal/http/clientRequest.mjs.map +1 -1
- package/mjs/internal/http/router.mjs.map +1 -1
- package/mjs/internal/http/serverResponse.mjs +10 -0
- package/mjs/internal/http/serverResponse.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Http/Body.ts +18 -0
- package/src/Http/ClientRequest.ts +9 -0
- package/src/Http/Etag.ts +2 -0
- package/src/Http/Router.ts +65 -93
- package/src/Http/ServerResponse.ts +9 -0
- package/src/internal/http/body.ts +6 -1
- package/src/internal/http/clientRequest.ts +6 -0
- package/src/internal/http/router.ts +31 -30
- package/src/internal/http/serverResponse.ts +21 -0
|
@@ -68,7 +68,7 @@ class RouterImpl<R, E> implements Router.Router<R, E> {
|
|
|
68
68
|
pipe() {
|
|
69
69
|
return pipeArguments(this, arguments)
|
|
70
70
|
}
|
|
71
|
-
private httpApp: App.Default<
|
|
71
|
+
private httpApp: App.Default<Router.Router.ExcludeProvided<R>, E | Error.RouteNotFound> | undefined
|
|
72
72
|
commit() {
|
|
73
73
|
if (this.httpApp === undefined) {
|
|
74
74
|
this.httpApp = toHttpApp(this)
|
|
@@ -95,7 +95,7 @@ class RouterImpl<R, E> implements Router.Router<R, E> {
|
|
|
95
95
|
|
|
96
96
|
const toHttpApp = <R, E>(
|
|
97
97
|
self: Router.Router<R, E>
|
|
98
|
-
): App.Default<
|
|
98
|
+
): App.Default<Router.Router.ExcludeProvided<R>, E | Error.RouteNotFound> => {
|
|
99
99
|
const router = FindMyWay()
|
|
100
100
|
const mounts = Chunk.toReadonlyArray(self.mounts)
|
|
101
101
|
const mountsLen = mounts.length
|
|
@@ -111,7 +111,7 @@ const toHttpApp = <R, E>(
|
|
|
111
111
|
})
|
|
112
112
|
return Effect.flatMap(
|
|
113
113
|
ServerRequest.ServerRequest,
|
|
114
|
-
(request): App.Default<
|
|
114
|
+
(request): App.Default<Router.Router.ExcludeProvided<R>, E | Error.RouteNotFound> => {
|
|
115
115
|
if (mountsLen > 0) {
|
|
116
116
|
for (let i = 0; i < mountsLen; i++) {
|
|
117
117
|
const [path, app] = mounts[i]
|
|
@@ -120,7 +120,7 @@ const toHttpApp = <R, E>(
|
|
|
120
120
|
app,
|
|
121
121
|
ServerRequest.ServerRequest,
|
|
122
122
|
sliceRequestUrl(request, path)
|
|
123
|
-
) as App.Default<
|
|
123
|
+
) as App.Default<Router.Router.ExcludeProvided<R>, E>
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
}
|
|
@@ -134,7 +134,7 @@ const toHttpApp = <R, E>(
|
|
|
134
134
|
request = sliceRequestUrl(request, route.prefix.value)
|
|
135
135
|
}
|
|
136
136
|
return Effect.mapInputContext(
|
|
137
|
-
route.handler as Effect.Effect<
|
|
137
|
+
route.handler as Effect.Effect<Router.Router.ExcludeProvided<R>, E, ServerResponse.ServerResponse>,
|
|
138
138
|
(context) =>
|
|
139
139
|
Context.add(
|
|
140
140
|
Context.add(context, ServerRequest.ServerRequest, request),
|
|
@@ -244,12 +244,12 @@ export const mountApp = dual<
|
|
|
244
244
|
that: App.Default<R1, E1>
|
|
245
245
|
) => <R, E>(
|
|
246
246
|
self: Router.Router<R, E>
|
|
247
|
-
) => Router.Router<
|
|
247
|
+
) => Router.Router.WithoutProvided<R | R1, E | E1>,
|
|
248
248
|
<R, E, R1, E1>(
|
|
249
249
|
self: Router.Router<R, E>,
|
|
250
250
|
path: string,
|
|
251
251
|
that: App.Default<R1, E1>
|
|
252
|
-
) => Router.Router<
|
|
252
|
+
) => Router.Router.WithoutProvided<R | R1, E | E1>
|
|
253
253
|
>(
|
|
254
254
|
3,
|
|
255
255
|
(self, path, that) =>
|
|
@@ -263,12 +263,12 @@ export const route = (method: Method.Method | "*"): {
|
|
|
263
263
|
handler: Router.Route.Handler<R1, E1>
|
|
264
264
|
): <R, E>(
|
|
265
265
|
self: Router.Router<R, E>
|
|
266
|
-
) => Router.Router<R |
|
|
266
|
+
) => Router.Router.WithoutProvided<R | R1, E1 | E>
|
|
267
267
|
<R, E, R1, E1>(
|
|
268
268
|
self: Router.Router<R, E>,
|
|
269
269
|
path: string,
|
|
270
270
|
handler: Router.Route.Handler<R1, E1>
|
|
271
|
-
): Router.Router<R |
|
|
271
|
+
): Router.Router.WithoutProvided<R | R1, E1 | E>
|
|
272
272
|
} =>
|
|
273
273
|
dual<
|
|
274
274
|
<R1, E1>(
|
|
@@ -276,15 +276,15 @@ export const route = (method: Method.Method | "*"): {
|
|
|
276
276
|
handler: Router.Route.Handler<R1, E1>
|
|
277
277
|
) => <R, E>(
|
|
278
278
|
self: Router.Router<R, E>
|
|
279
|
-
) => Router.Router<R |
|
|
279
|
+
) => Router.Router.WithoutProvided<R | R1, E | E1>,
|
|
280
280
|
<R, E, R1, E1>(
|
|
281
281
|
self: Router.Router<R, E>,
|
|
282
282
|
path: string,
|
|
283
283
|
handler: Router.Route.Handler<R1, E1>
|
|
284
|
-
) => Router.Router<R |
|
|
284
|
+
) => Router.Router.WithoutProvided<R | R1, E | E1>
|
|
285
285
|
>(3, (self, path, handler) =>
|
|
286
|
-
new RouterImpl(
|
|
287
|
-
Chunk.append(self.routes, new RouteImpl(method, path, handler))
|
|
286
|
+
new RouterImpl<any, any>(
|
|
287
|
+
Chunk.append(self.routes, new RouteImpl(method, path, handler)),
|
|
288
288
|
self.mounts
|
|
289
289
|
))
|
|
290
290
|
|
|
@@ -316,11 +316,11 @@ export const options = route("OPTIONS")
|
|
|
316
316
|
export const use = dual<
|
|
317
317
|
<R, E, R1, E1>(
|
|
318
318
|
f: (self: Router.Route.Handler<R, E>) => App.Default<R1, E1>
|
|
319
|
-
) => (self: Router.Router<R, E>) => Router.Router<
|
|
319
|
+
) => (self: Router.Router<R, E>) => Router.Router.WithoutProvided<R1, E1>,
|
|
320
320
|
<R, E, R1, E1>(
|
|
321
321
|
self: Router.Router<R, E>,
|
|
322
322
|
f: (self: Router.Route.Handler<R, E>) => App.Default<R1, E1>
|
|
323
|
-
) => Router.Router<
|
|
323
|
+
) => Router.Router.WithoutProvided<R1, E1>
|
|
324
324
|
>(2, (self, f) =>
|
|
325
325
|
new RouterImpl<any, any>(
|
|
326
326
|
Chunk.map(
|
|
@@ -337,22 +337,22 @@ export const use = dual<
|
|
|
337
337
|
export const catchAll = dual<
|
|
338
338
|
<E, R2, E2>(
|
|
339
339
|
f: (e: E) => Router.Route.Handler<R2, E2>
|
|
340
|
-
) => <R>(self: Router.Router<R, E>) => Router.Router<R2 | R, E2>,
|
|
340
|
+
) => <R>(self: Router.Router<R, E>) => Router.Router.WithoutProvided<R2 | R, E2>,
|
|
341
341
|
<R, E, R2, E2>(
|
|
342
342
|
self: Router.Router<R, E>,
|
|
343
343
|
f: (e: E) => Router.Route.Handler<R2, E2>
|
|
344
|
-
) => Router.Router<R2 | R, E2>
|
|
344
|
+
) => Router.Router.WithoutProvided<R2 | R, E2>
|
|
345
345
|
>(2, (self, f) => use(self, Effect.catchAll(f)))
|
|
346
346
|
|
|
347
347
|
/** @internal */
|
|
348
348
|
export const catchAllCause = dual<
|
|
349
349
|
<E, R2, E2>(
|
|
350
350
|
f: (e: Cause.Cause<E>) => Router.Route.Handler<R2, E2>
|
|
351
|
-
) => <R>(self: Router.Router<R, E>) => Router.Router<R2 | R, E2>,
|
|
351
|
+
) => <R>(self: Router.Router<R, E>) => Router.Router.WithoutProvided<R2 | R, E2>,
|
|
352
352
|
<R, E, R2, E2>(
|
|
353
353
|
self: Router.Router<R, E>,
|
|
354
354
|
f: (e: Cause.Cause<E>) => Router.Route.Handler<R2, E2>
|
|
355
|
-
) => Router.Router<R2 | R, E2>
|
|
355
|
+
) => Router.Router.WithoutProvided<R2 | R, E2>
|
|
356
356
|
>(2, (self, f) => use(self, Effect.catchAllCause(f)))
|
|
357
357
|
|
|
358
358
|
/** @internal */
|
|
@@ -360,12 +360,12 @@ export const catchTag = dual<
|
|
|
360
360
|
<K extends (E extends { _tag: string } ? E["_tag"] : never), E, R1, E1>(
|
|
361
361
|
k: K,
|
|
362
362
|
f: (e: Extract<E, { _tag: K }>) => Router.Route.Handler<R1, E1>
|
|
363
|
-
) => <R>(self: Router.Router<R, E>) => Router.Router<R | R1, Exclude<E, { _tag: K }> | E1>,
|
|
363
|
+
) => <R>(self: Router.Router<R, E>) => Router.Router.WithoutProvided<R | R1, Exclude<E, { _tag: K }> | E1>,
|
|
364
364
|
<R, E, K extends (E extends { _tag: string } ? E["_tag"] : never), R1, E1>(
|
|
365
365
|
self: Router.Router<R, E>,
|
|
366
366
|
k: K,
|
|
367
367
|
f: (e: Extract<E, { _tag: K }>) => Router.Route.Handler<R1, E1>
|
|
368
|
-
) => Router.Router<R | R1, Exclude<E, { _tag: K }> | E1>
|
|
368
|
+
) => Router.Router.WithoutProvided<R | R1, Exclude<E, { _tag: K }> | E1>
|
|
369
369
|
>(3, (self, k, f) => use(self, Effect.catchTag(k, f)))
|
|
370
370
|
|
|
371
371
|
/** @internal */
|
|
@@ -378,7 +378,7 @@ export const catchTags: {
|
|
|
378
378
|
{})
|
|
379
379
|
>(
|
|
380
380
|
cases: Cases
|
|
381
|
-
): <R>(self: Router.Router<R, E>) => Router.Router<
|
|
381
|
+
): <R>(self: Router.Router<R, E>) => Router.Router.WithoutProvided<
|
|
382
382
|
| R
|
|
383
383
|
| {
|
|
384
384
|
[K in keyof Cases]: Cases[K] extends ((...args: Array<any>) => Effect.Effect<infer R, any, any>) ? R : never
|
|
@@ -398,7 +398,7 @@ export const catchTags: {
|
|
|
398
398
|
>(
|
|
399
399
|
self: Router.Router<R, E>,
|
|
400
400
|
cases: Cases
|
|
401
|
-
): Router.Router<
|
|
401
|
+
): Router.Router.WithoutProvided<
|
|
402
402
|
| R
|
|
403
403
|
| {
|
|
404
404
|
[K in keyof Cases]: Cases[K] extends ((...args: Array<any>) => Effect.Effect<infer R, any, any>) ? R : never
|
|
@@ -414,17 +414,18 @@ export const provideService = dual<
|
|
|
414
414
|
<T extends Context.Tag<any, any>>(
|
|
415
415
|
tag: T,
|
|
416
416
|
service: Context.Tag.Service<T>
|
|
417
|
-
) => <R, E>(self: Router.Router<R, E>) => Router.Router<Exclude<R, Context.Tag.Identifier<T>>, E>,
|
|
417
|
+
) => <R, E>(self: Router.Router<R, E>) => Router.Router.WithoutProvided<Exclude<R, Context.Tag.Identifier<T>>, E>,
|
|
418
418
|
<R, E, T extends Context.Tag<any, any>>(
|
|
419
419
|
self: Router.Router<R, E>,
|
|
420
420
|
tag: T,
|
|
421
421
|
service: Context.Tag.Service<T>
|
|
422
|
-
) => Router.Router<Exclude<R, Context.Tag.Identifier<T>>, E>
|
|
422
|
+
) => Router.Router.WithoutProvided<Exclude<R, Context.Tag.Identifier<T>>, E>
|
|
423
423
|
>(3, <R, E, T extends Context.Tag<any, any>>(
|
|
424
424
|
self: Router.Router<R, E>,
|
|
425
425
|
tag: T,
|
|
426
426
|
service: Context.Tag.Service<T>
|
|
427
|
-
): Router.Router<Exclude<R, Context.Tag.Identifier<T>>, E> =>
|
|
427
|
+
): Router.Router.WithoutProvided<Exclude<R, Context.Tag.Identifier<T>>, E> =>
|
|
428
|
+
use(self, Effect.provideService(tag, service)))
|
|
428
429
|
|
|
429
430
|
/* @internal */
|
|
430
431
|
export const provideServiceEffect = dual<
|
|
@@ -433,16 +434,16 @@ export const provideServiceEffect = dual<
|
|
|
433
434
|
effect: Effect.Effect<R1, E1, Context.Tag.Service<T>>
|
|
434
435
|
) => <R, E>(
|
|
435
436
|
self: Router.Router<R, E>
|
|
436
|
-
) => Router.Router<
|
|
437
|
-
|
|
437
|
+
) => Router.Router.WithoutProvided<
|
|
438
|
+
R1 | Exclude<R, Context.Tag.Identifier<T>>,
|
|
438
439
|
E | E1
|
|
439
440
|
>,
|
|
440
441
|
<R, E, T extends Context.Tag<any, any>, R1, E1>(
|
|
441
442
|
self: Router.Router<R, E>,
|
|
442
443
|
tag: T,
|
|
443
444
|
effect: Effect.Effect<R1, E1, Context.Tag.Service<T>>
|
|
444
|
-
) => Router.Router<
|
|
445
|
-
|
|
445
|
+
) => Router.Router.WithoutProvided<
|
|
446
|
+
R1 | Exclude<R, Context.Tag.Identifier<T>>,
|
|
446
447
|
E | E1
|
|
447
448
|
>
|
|
448
449
|
>(3, <R, E, T extends Context.Tag<any, any>, R1, E1>(
|
|
@@ -159,6 +159,27 @@ export const file = (
|
|
|
159
159
|
})
|
|
160
160
|
)
|
|
161
161
|
|
|
162
|
+
/** @internal */
|
|
163
|
+
export const fileWeb = (
|
|
164
|
+
file: Body.Body.FileLike,
|
|
165
|
+
options?: ServerResponse.Options.WithContent
|
|
166
|
+
): Effect.Effect<Etag.Generator, never, ServerResponse.ServerResponse> =>
|
|
167
|
+
Effect.flatMap(Etag.Generator, (generator) =>
|
|
168
|
+
Effect.map(generator.fromFileWeb(file), (etag) => {
|
|
169
|
+
const body = internalBody.fileWeb(file)
|
|
170
|
+
const headers: Record<string, string> = {
|
|
171
|
+
...(options?.headers ?? {}),
|
|
172
|
+
etag: Etag.toString(etag),
|
|
173
|
+
"last-modified": new Date(file.lastModified).toUTCString()
|
|
174
|
+
}
|
|
175
|
+
return new ServerResponseImpl(
|
|
176
|
+
options?.status ?? 200,
|
|
177
|
+
options?.statusText,
|
|
178
|
+
headers,
|
|
179
|
+
body
|
|
180
|
+
)
|
|
181
|
+
}))
|
|
182
|
+
|
|
162
183
|
/** @internal */
|
|
163
184
|
export const urlParams = (
|
|
164
185
|
body: UrlParams.Input,
|