@effect/platform 0.61.2 → 0.61.3
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 +268 -30
- package/dist/cjs/HttpApp.js +26 -5
- package/dist/cjs/HttpApp.js.map +1 -1
- package/dist/dts/HttpApp.d.ts +1 -1
- package/dist/dts/HttpApp.d.ts.map +1 -1
- package/dist/esm/HttpApp.js +26 -5
- package/dist/esm/HttpApp.js.map +1 -1
- package/package.json +3 -3
- package/src/HttpApp.ts +27 -13
package/README.md
CHANGED
|
@@ -295,7 +295,7 @@ Here's a list of operations that can be performed using the `FileSystem` tag:
|
|
|
295
295
|
| **makeTempFile** | `options?: MakeTempFileOptions` | `Effect<string, PlatformError>` | Create a temporary file. The directory creation is functionally equivalent to `makeTempDirectory`. The file name will be a randomly generated string. |
|
|
296
296
|
| **makeTempFileScoped** | `options?: MakeTempFileOptions` | `Effect<string, PlatformError, Scope>` | Create a temporary file inside a scope. Functionally equivalent to `makeTempFile`, but the file will be automatically deleted when the scope is closed. |
|
|
297
297
|
| **open** | `path: string`, `options?: OpenFileOptions` | `Effect<File, PlatformError, Scope>` | Open a file at `path` with the specified `options`. The file handle will be automatically closed when the scope is closed. |
|
|
298
|
-
| **readDirectory** | `path: string`, `options?: ReadDirectoryOptions` | `Effect<Array<string>, PlatformError>`
|
|
298
|
+
| **readDirectory** | `path: string`, `options?: ReadDirectoryOptions` | `Effect<Array<string>, PlatformError>` | List the contents of a directory. You can recursively list the contents of nested directories by setting the `recursive` option. |
|
|
299
299
|
| **readFile** | `path: string` | `Effect<Uint8Array, PlatformError>` | Read the contents of a file. |
|
|
300
300
|
| **readFileString** | `path: string`, `encoding?: string` | `Effect<string, PlatformError>` | Read the contents of a file as a string. |
|
|
301
301
|
| **readLink** | `path: string` | `Effect<string, PlatformError>` | Read the destination of a symbolic link. |
|
|
@@ -420,9 +420,269 @@ In this example:
|
|
|
420
420
|
|
|
421
421
|
# HTTP Client
|
|
422
422
|
|
|
423
|
-
##
|
|
423
|
+
## Overview
|
|
424
|
+
|
|
425
|
+
An `HttpClient` is a function that takes a request and produces a certain value `A` in an effectful way (possibly resulting in an error `E` and depending on some requirement `R`).
|
|
426
|
+
|
|
427
|
+
```ts
|
|
428
|
+
type HttpClient<A, E, R> = (request: HttpClientRequest): Effect<A, E, R>
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
Generally, you'll deal with a specialization called `Default` where `A`, `E`, and `R` are predefined:
|
|
432
|
+
|
|
433
|
+
```ts
|
|
434
|
+
type Default = (request: HttpClientRequest): Effect<HttpClientResponse, RequestError | ResponseError, Scope>
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
The goal of `Default` is straightforward: transform a `HttpClientRequest` into a `HttpClientResponse`.
|
|
438
|
+
|
|
439
|
+
### A First Example: Retrieving JSON Data (GET)
|
|
440
|
+
|
|
441
|
+
Here's a simple example demonstrating how to retrieve JSON data using `HttpClient` from `@effect/platform`.
|
|
442
|
+
|
|
443
|
+
```ts
|
|
444
|
+
import {
|
|
445
|
+
HttpClient,
|
|
446
|
+
HttpClientRequest,
|
|
447
|
+
HttpClientResponse
|
|
448
|
+
} from "@effect/platform"
|
|
449
|
+
import { Effect } from "effect"
|
|
450
|
+
|
|
451
|
+
const req = HttpClientRequest.get(
|
|
452
|
+
"https://jsonplaceholder.typicode.com/posts/1"
|
|
453
|
+
)
|
|
454
|
+
|
|
455
|
+
// HttpClient.fetch is a Default
|
|
456
|
+
const res = HttpClient.fetch(req)
|
|
457
|
+
|
|
458
|
+
const json = HttpClientResponse.json(res)
|
|
459
|
+
|
|
460
|
+
Effect.runPromise(json).then(console.log)
|
|
461
|
+
/*
|
|
462
|
+
Output:
|
|
463
|
+
{
|
|
464
|
+
userId: 1,
|
|
465
|
+
id: 1,
|
|
466
|
+
title: 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit',
|
|
467
|
+
body: 'quia et suscipit\n' +
|
|
468
|
+
'suscipit recusandae consequuntur expedita et cum\n' +
|
|
469
|
+
'reprehenderit molestiae ut ut quas totam\n' +
|
|
470
|
+
'nostrum rerum est autem sunt rem eveniet architecto'
|
|
471
|
+
}
|
|
472
|
+
*/
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
In this example:
|
|
476
|
+
|
|
477
|
+
- `HttpClientRequest.get` creates a GET request to the specified URL.
|
|
478
|
+
- `HttpClient.fetch` executes the request.
|
|
479
|
+
- `HttpClientResponse.json` converts the response to JSON.
|
|
480
|
+
- `Effect.runPromise` runs the effect and logs the result.
|
|
481
|
+
|
|
482
|
+
### Built-in Defaults
|
|
483
|
+
|
|
484
|
+
| Default | Description |
|
|
485
|
+
| -------------------- | ------------------------------------------------------------------------- |
|
|
486
|
+
| `HttpClient.fetch` | Execute the request using the global `fetch` function |
|
|
487
|
+
| `HttpClient.fetchOk` | Same as `fetch` but ensures only `2xx` responses are treated as successes |
|
|
488
|
+
|
|
489
|
+
### Custom Default
|
|
490
|
+
|
|
491
|
+
You can create your own `Default` using the `HttpClient.makeDefault` constructor.
|
|
492
|
+
|
|
493
|
+
```ts
|
|
494
|
+
import { HttpClient, HttpClientResponse } from "@effect/platform"
|
|
495
|
+
import { Effect } from "effect"
|
|
496
|
+
|
|
497
|
+
const myClient = HttpClient.makeDefault((req) =>
|
|
498
|
+
Effect.succeed(
|
|
499
|
+
HttpClientResponse.fromWeb(
|
|
500
|
+
req,
|
|
501
|
+
// Simulate a response from a server
|
|
502
|
+
new Response(
|
|
503
|
+
JSON.stringify({ userId: 1, id: 1, title: "title...", body: "body..." })
|
|
504
|
+
)
|
|
505
|
+
)
|
|
506
|
+
)
|
|
507
|
+
)
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
## Tapping
|
|
511
|
+
|
|
512
|
+
```ts
|
|
513
|
+
import {
|
|
514
|
+
HttpClient,
|
|
515
|
+
HttpClientRequest,
|
|
516
|
+
HttpClientResponse
|
|
517
|
+
} from "@effect/platform"
|
|
518
|
+
import { Console, Effect } from "effect"
|
|
519
|
+
|
|
520
|
+
const req = HttpClientRequest.get(
|
|
521
|
+
"https://jsonplaceholder.typicode.com/posts/1"
|
|
522
|
+
)
|
|
523
|
+
|
|
524
|
+
// Log the request before fetching
|
|
525
|
+
const tapFetch: HttpClient.HttpClient.Default = HttpClient.fetch.pipe(
|
|
526
|
+
HttpClient.tapRequest(Console.log)
|
|
527
|
+
)
|
|
528
|
+
|
|
529
|
+
const res = tapFetch(req)
|
|
530
|
+
|
|
531
|
+
const json = HttpClientResponse.json(res)
|
|
532
|
+
|
|
533
|
+
Effect.runPromise(json).then(console.log)
|
|
534
|
+
/*
|
|
535
|
+
Output:
|
|
536
|
+
{
|
|
537
|
+
_id: '@effect/platform/HttpClientRequest',
|
|
538
|
+
method: 'GET',
|
|
539
|
+
url: 'https://jsonplaceholder.typicode.com/posts/1',
|
|
540
|
+
urlParams: [],
|
|
541
|
+
hash: { _id: 'Option', _tag: 'None' },
|
|
542
|
+
headers: Object <[Object: null prototype]> {},
|
|
543
|
+
body: { _id: '@effect/platform/HttpBody', _tag: 'Empty' }
|
|
544
|
+
}
|
|
545
|
+
{
|
|
546
|
+
userId: 1,
|
|
547
|
+
id: 1,
|
|
548
|
+
title: 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit',
|
|
549
|
+
body: 'quia et suscipit\n' +
|
|
550
|
+
'suscipit recusandae consequuntur expedita et cum\n' +
|
|
551
|
+
'reprehenderit molestiae ut ut quas totam\n' +
|
|
552
|
+
'nostrum rerum est autem sunt rem eveniet architecto'
|
|
553
|
+
}
|
|
554
|
+
*/
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
## HttpClientRequest
|
|
558
|
+
|
|
559
|
+
### Overview
|
|
560
|
+
|
|
561
|
+
You can create a `HttpClientRequest` using the following provided constructors:
|
|
562
|
+
|
|
563
|
+
| Constructor | Description |
|
|
564
|
+
| --------------------------- | ------------------------- |
|
|
565
|
+
| `HttpClientRequest.get` | Create a GET request |
|
|
566
|
+
| `HttpClientRequest.post` | Create a POST request |
|
|
567
|
+
| `HttpClientRequest.patch` | Create a PATCH request |
|
|
568
|
+
| `HttpClientRequest.put` | Create a PUT request |
|
|
569
|
+
| `HttpClientRequest.del` | Create a DELETE request |
|
|
570
|
+
| `HttpClientRequest.head` | Create a HEAD request |
|
|
571
|
+
| `HttpClientRequest.options` | Create an OPTIONS request |
|
|
424
572
|
|
|
425
|
-
|
|
573
|
+
### Setting Headers
|
|
574
|
+
|
|
575
|
+
When making HTTP requests, sometimes you need to include additional information in the request headers. You can set headers using the `setHeader` function for a single header or `setHeaders` for multiple headers simultaneously.
|
|
576
|
+
|
|
577
|
+
```ts
|
|
578
|
+
import { HttpClientRequest } from "@effect/platform"
|
|
579
|
+
|
|
580
|
+
const req = HttpClientRequest.get("https://api.example.com/data").pipe(
|
|
581
|
+
// Setting a single header
|
|
582
|
+
HttpClientRequest.setHeader("Authorization", "Bearer your_token_here"),
|
|
583
|
+
// Setting multiple headers
|
|
584
|
+
HttpClientRequest.setHeaders({
|
|
585
|
+
"Content-Type": "application/json; charset=UTF-8",
|
|
586
|
+
"Custom-Header": "CustomValue"
|
|
587
|
+
})
|
|
588
|
+
)
|
|
589
|
+
|
|
590
|
+
console.log(JSON.stringify(req.headers, null, 2))
|
|
591
|
+
/*
|
|
592
|
+
Output:
|
|
593
|
+
{
|
|
594
|
+
"authorization": "Bearer your_token_here",
|
|
595
|
+
"content-type": "application/json; charset=UTF-8",
|
|
596
|
+
"custom-header": "CustomValue"
|
|
597
|
+
}
|
|
598
|
+
*/
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
### basicAuth
|
|
602
|
+
|
|
603
|
+
To include basic authentication in your HTTP request, you can use the `basicAuth` method provided by `HttpClientRequest`.
|
|
604
|
+
|
|
605
|
+
```ts
|
|
606
|
+
import { HttpClientRequest } from "@effect/platform"
|
|
607
|
+
|
|
608
|
+
const req = HttpClientRequest.get("https://api.example.com/data").pipe(
|
|
609
|
+
HttpClientRequest.basicAuth("your_username", "your_password")
|
|
610
|
+
)
|
|
611
|
+
|
|
612
|
+
console.log(JSON.stringify(req.headers, null, 2))
|
|
613
|
+
/*
|
|
614
|
+
Output:
|
|
615
|
+
{
|
|
616
|
+
"authorization": "Basic eW91cl91c2VybmFtZTp5b3VyX3Bhc3N3b3Jk"
|
|
617
|
+
}
|
|
618
|
+
*/
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
### bearerToken
|
|
622
|
+
|
|
623
|
+
To include a Bearer token in your HTTP request, use the `bearerToken` method provided by `HttpClientRequest`.
|
|
624
|
+
|
|
625
|
+
```ts
|
|
626
|
+
import { HttpClientRequest } from "@effect/platform"
|
|
627
|
+
|
|
628
|
+
const req = HttpClientRequest.get("https://api.example.com/data").pipe(
|
|
629
|
+
HttpClientRequest.bearerToken("your_token")
|
|
630
|
+
)
|
|
631
|
+
|
|
632
|
+
console.log(JSON.stringify(req.headers, null, 2))
|
|
633
|
+
/*
|
|
634
|
+
Output:
|
|
635
|
+
{
|
|
636
|
+
"authorization": "Bearer your_token"
|
|
637
|
+
}
|
|
638
|
+
*/
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
### accept
|
|
642
|
+
|
|
643
|
+
To specify the media types that are acceptable for the response, use the `accept` method provided by `HttpClientRequest`.
|
|
644
|
+
|
|
645
|
+
```ts
|
|
646
|
+
import { HttpClientRequest } from "@effect/platform"
|
|
647
|
+
|
|
648
|
+
const req = HttpClientRequest.get("https://api.example.com/data").pipe(
|
|
649
|
+
HttpClientRequest.accept("application/xml")
|
|
650
|
+
)
|
|
651
|
+
|
|
652
|
+
console.log(JSON.stringify(req.headers, null, 2))
|
|
653
|
+
/*
|
|
654
|
+
Output:
|
|
655
|
+
{
|
|
656
|
+
"accept": "application/xml"
|
|
657
|
+
}
|
|
658
|
+
*/
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
### acceptJson
|
|
662
|
+
|
|
663
|
+
To indicate that the client accepts JSON responses, use the `acceptJson` method provided by `HttpClientRequest`.
|
|
664
|
+
|
|
665
|
+
```ts
|
|
666
|
+
import { HttpClientRequest } from "@effect/platform"
|
|
667
|
+
|
|
668
|
+
const req = HttpClientRequest.get("https://api.example.com/data").pipe(
|
|
669
|
+
HttpClientRequest.acceptJson
|
|
670
|
+
)
|
|
671
|
+
|
|
672
|
+
console.log(JSON.stringify(req.headers, null, 2))
|
|
673
|
+
/*
|
|
674
|
+
Output:
|
|
675
|
+
{
|
|
676
|
+
"accept": "application/json"
|
|
677
|
+
}
|
|
678
|
+
*/
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
## GET
|
|
682
|
+
|
|
683
|
+
### Converting to JSON
|
|
684
|
+
|
|
685
|
+
To convert a GET response to JSON:
|
|
426
686
|
|
|
427
687
|
```ts
|
|
428
688
|
import {
|
|
@@ -454,9 +714,9 @@ object {
|
|
|
454
714
|
*/
|
|
455
715
|
```
|
|
456
716
|
|
|
457
|
-
|
|
717
|
+
### Converting to Text
|
|
458
718
|
|
|
459
|
-
|
|
719
|
+
To convert a GET response to text:
|
|
460
720
|
|
|
461
721
|
```ts
|
|
462
722
|
import {
|
|
@@ -488,9 +748,11 @@ string {
|
|
|
488
748
|
*/
|
|
489
749
|
```
|
|
490
750
|
|
|
751
|
+
### More on Converting the Response
|
|
752
|
+
|
|
491
753
|
Here are some APIs you can use to convert the response:
|
|
492
754
|
|
|
493
|
-
|
|
|
755
|
+
| API | Description |
|
|
494
756
|
| ---------------------------------- | ------------------------------------- |
|
|
495
757
|
| `HttpClientResponse.arrayBuffer` | Convert to `ArrayBuffer` |
|
|
496
758
|
| `HttpClientResponse.formData` | Convert to `FormData` |
|
|
@@ -499,30 +761,6 @@ Here are some APIs you can use to convert the response:
|
|
|
499
761
|
| `HttpClientResponse.text` | Convert to text |
|
|
500
762
|
| `HttpClientResponse.urlParamsBody` | Convert to `Http.urlParams.UrlParams` |
|
|
501
763
|
|
|
502
|
-
### Setting Headers
|
|
503
|
-
|
|
504
|
-
When making HTTP requests, sometimes you need to include additional information in the request headers. You can set headers using the `setHeader` function for a single header or `setHeaders` for multiple headers simultaneously.
|
|
505
|
-
|
|
506
|
-
```ts
|
|
507
|
-
import { HttpClient, HttpClientRequest } from "@effect/platform"
|
|
508
|
-
|
|
509
|
-
const getPost = HttpClientRequest.get(
|
|
510
|
-
"https://jsonplaceholder.typicode.com/posts/1"
|
|
511
|
-
).pipe(
|
|
512
|
-
// Setting a single header
|
|
513
|
-
HttpClientRequest.setHeader(
|
|
514
|
-
"Content-type",
|
|
515
|
-
"application/json; charset=UTF-8"
|
|
516
|
-
),
|
|
517
|
-
// Setting multiple headers
|
|
518
|
-
HttpClientRequest.setHeaders({
|
|
519
|
-
"Content-type": "application/json; charset=UTF-8",
|
|
520
|
-
Foo: "Bar"
|
|
521
|
-
}),
|
|
522
|
-
HttpClient.fetch
|
|
523
|
-
)
|
|
524
|
-
```
|
|
525
|
-
|
|
526
764
|
### Decoding Data with Schemas
|
|
527
765
|
|
|
528
766
|
A common use case when fetching data is to validate the received format. For this purpose, the `HttpClient` module is integrated with `@effect/schema`.
|
package/dist/cjs/HttpApp.js
CHANGED
|
@@ -30,18 +30,39 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
30
30
|
*/
|
|
31
31
|
const toHandled = (self, handleResponse, middleware) => {
|
|
32
32
|
const responded = Effect.withFiberRuntime(fiber => {
|
|
33
|
+
let handled = false;
|
|
33
34
|
const request = Context.unsafeGet(fiber.getFiberRef(FiberRef.currentContext), ServerRequest.HttpServerRequest);
|
|
34
35
|
const preprocessResponse = response => {
|
|
35
36
|
const handler = fiber.getFiberRef(currentPreResponseHandlers);
|
|
36
37
|
return handler._tag === "Some" ? handler.value(request, response) : Effect.succeed(response);
|
|
37
38
|
};
|
|
38
|
-
|
|
39
|
-
onFailure: cause => Effect.flatMap(ServerError.causeResponse(cause), ([response, cause]) => preprocessResponse(response).pipe(Effect.flatMap(response =>
|
|
40
|
-
|
|
39
|
+
const responded = Effect.matchCauseEffect(self, {
|
|
40
|
+
onFailure: cause => Effect.flatMap(ServerError.causeResponse(cause), ([response, cause]) => preprocessResponse(response).pipe(Effect.flatMap(response => {
|
|
41
|
+
handled = true;
|
|
42
|
+
return handleResponse(request, response);
|
|
43
|
+
}), Effect.zipRight(Effect.failCause(cause)))),
|
|
44
|
+
onSuccess: response => Effect.tap(preprocessResponse(response), response => {
|
|
45
|
+
handled = true;
|
|
46
|
+
return handleResponse(request, response);
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
const withTracer = internalMiddleware.tracer(responded);
|
|
50
|
+
if (middleware === undefined) {
|
|
51
|
+
return withTracer;
|
|
52
|
+
}
|
|
53
|
+
return Effect.catchAllCause(middleware(withTracer), cause => {
|
|
54
|
+
if (handled) {
|
|
55
|
+
return Effect.void;
|
|
56
|
+
}
|
|
57
|
+
return Effect.matchCauseEffect(ServerError.causeResponse(cause), {
|
|
58
|
+
onFailure: _cause => handleResponse(request, ServerResponse.empty({
|
|
59
|
+
status: 500
|
|
60
|
+
})),
|
|
61
|
+
onSuccess: ([response]) => handleResponse(request, response)
|
|
62
|
+
});
|
|
41
63
|
});
|
|
42
64
|
});
|
|
43
|
-
|
|
44
|
-
return Effect.uninterruptible(Effect.catchAllCause(Effect.scoped(middleware === undefined ? withTracer : middleware(withTracer)), _ => Effect.void));
|
|
65
|
+
return Effect.uninterruptible(Effect.scoped(responded));
|
|
45
66
|
};
|
|
46
67
|
/**
|
|
47
68
|
* @since 1.0.0
|
package/dist/cjs/HttpApp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpApp.js","names":["Context","_interopRequireWildcard","require","Effect","Exit","FiberRef","_Function","_GlobalValue","Layer","Option","Runtime","Scope","ServerError","ServerRequest","ServerResponse","internalMiddleware","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","toHandled","self","handleResponse","middleware","responded","withFiberRuntime","fiber","request","unsafeGet","getFiberRef","currentContext","HttpServerRequest","preprocessResponse","response","handler","currentPreResponseHandlers","_tag","value","succeed","matchCauseEffect","onFailure","cause","flatMap","causeResponse","pipe","zipRight","failCause","onSuccess","tap","withTracer","tracer","
|
|
1
|
+
{"version":3,"file":"HttpApp.js","names":["Context","_interopRequireWildcard","require","Effect","Exit","FiberRef","_Function","_GlobalValue","Layer","Option","Runtime","Scope","ServerError","ServerRequest","ServerResponse","internalMiddleware","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","toHandled","self","handleResponse","middleware","responded","withFiberRuntime","fiber","handled","request","unsafeGet","getFiberRef","currentContext","HttpServerRequest","preprocessResponse","response","handler","currentPreResponseHandlers","_tag","value","succeed","matchCauseEffect","onFailure","cause","flatMap","causeResponse","pipe","zipRight","failCause","onSuccess","tap","withTracer","tracer","undefined","catchAllCause","void","_cause","empty","status","uninterruptible","scoped","exports","globalValue","Symbol","for","unsafeMake","none","appendPreResponseHandler","update","match","onNone","some","onSome","prev","withPreResponseHandler","dual","locallyWith","toWebHandlerRuntime","runtime","run","runFork","Promise","resolve","provideService","toWeb","withoutBody","method","fromWeb","signal","addEventListener","unsafeInterruptAsFork","clientAbortFiberId","once","toWebHandler","defaultRuntime","toWebHandlerLayer","layer","scope","runSync","make","close","runPromise","build","map","toRuntime","_","runner","extend","then"],"sources":["../../src/HttpApp.ts"],"sourcesContent":[null],"mappings":";;;;;;AAGA,IAAAA,OAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,uBAAA,CAAAC,OAAA;AACA,IAAAE,IAAA,GAAAH,uBAAA,CAAAC,OAAA;AACA,IAAAG,QAAA,GAAAJ,uBAAA,CAAAC,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,G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K,GAAGlH,MAAM,CAACmH,GAAG,CAAC9G,KAAK,CAAC+G,SAAS,CAACR,KAAK,CAAC,EAAGS,CAAC,IAAK5B,mBAAmB,CAAC4B,CAAC,CAAC,CAACnF,IAAI,EAAEE,UAAU,CAAC,CAAC;EACjG,MAAMkF,MAAM,GAAGtH,MAAM,CAACiH,UAAU,CAACzG,KAAK,CAAC+G,MAAM,CAACL,KAAK,EAAEL,KAAK,CAAC,CAAC;EAC5D,MAAM7D,OAAO,GAAIP,OAAgB,IAAwB6E,MAAM,CAACE,IAAI,CAAExE,OAAO,IAAKA,OAAO,CAACP,OAAO,CAAC,CAAC;EACnG,OAAO;IAAEuE,KAAK;IAAEhE;EAAO,CAAW;AACpC,CAAC;AAAAyB,OAAA,CAAAkC,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
package/dist/dts/HttpApp.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export type Default<E = never, R = never> = HttpApp<ServerResponse.HttpServerRes
|
|
|
22
22
|
* @since 1.0.0
|
|
23
23
|
* @category combinators
|
|
24
24
|
*/
|
|
25
|
-
export declare const toHandled: <E, R, _, EH, RH>(self: Default<E, R>, handleResponse: (request: ServerRequest.HttpServerRequest, response: ServerResponse.HttpServerResponse) => Effect.Effect<_, EH, RH>, middleware?: HttpMiddleware | undefined) => Effect.Effect<void, never, Exclude<R | RH, Scope.Scope>>;
|
|
25
|
+
export declare const toHandled: <E, R, _, EH, RH>(self: Default<E, R>, handleResponse: (request: ServerRequest.HttpServerRequest, response: ServerResponse.HttpServerResponse) => Effect.Effect<_, EH, RH>, middleware?: HttpMiddleware | undefined) => Effect.Effect<void, never, Exclude<R | RH | ServerRequest.HttpServerRequest, Scope.Scope>>;
|
|
26
26
|
/**
|
|
27
27
|
* @since 1.0.0
|
|
28
28
|
* @category models
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpApp.d.ts","sourceRoot":"","sources":["../../src/HttpApp.ts"],"names":[],"mappings":"AAIA,O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,KAAG,OAAO,CAAC,QAAQ,CAcrC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,CAAC,CAAC,EAC3B,IAAI,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,EAC7B,UAAU,CAAC,EAAE,cAAc,GAAG,SAAS,KACpC,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAA+C,CAAA;AAE1F;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAAE,CAAC,EAAE,EAAE,QAClC,OAAO,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,SAC1B,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,eACZ,cAAc,GAAG,SAAS,KACtC;IACD,QAAQ,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAQ1D,CAAA"}
|
package/dist/esm/HttpApp.js
CHANGED
|
@@ -21,18 +21,39 @@ import * as internalMiddleware from "./internal/httpMiddleware.js";
|
|
|
21
21
|
*/
|
|
22
22
|
export const toHandled = (self, handleResponse, middleware) => {
|
|
23
23
|
const responded = Effect.withFiberRuntime(fiber => {
|
|
24
|
+
let handled = false;
|
|
24
25
|
const request = Context.unsafeGet(fiber.getFiberRef(FiberRef.currentContext), ServerRequest.HttpServerRequest);
|
|
25
26
|
const preprocessResponse = response => {
|
|
26
27
|
const handler = fiber.getFiberRef(currentPreResponseHandlers);
|
|
27
28
|
return handler._tag === "Some" ? handler.value(request, response) : Effect.succeed(response);
|
|
28
29
|
};
|
|
29
|
-
|
|
30
|
-
onFailure: cause => Effect.flatMap(ServerError.causeResponse(cause), ([response, cause]) => preprocessResponse(response).pipe(Effect.flatMap(response =>
|
|
31
|
-
|
|
30
|
+
const responded = Effect.matchCauseEffect(self, {
|
|
31
|
+
onFailure: cause => Effect.flatMap(ServerError.causeResponse(cause), ([response, cause]) => preprocessResponse(response).pipe(Effect.flatMap(response => {
|
|
32
|
+
handled = true;
|
|
33
|
+
return handleResponse(request, response);
|
|
34
|
+
}), Effect.zipRight(Effect.failCause(cause)))),
|
|
35
|
+
onSuccess: response => Effect.tap(preprocessResponse(response), response => {
|
|
36
|
+
handled = true;
|
|
37
|
+
return handleResponse(request, response);
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
const withTracer = internalMiddleware.tracer(responded);
|
|
41
|
+
if (middleware === undefined) {
|
|
42
|
+
return withTracer;
|
|
43
|
+
}
|
|
44
|
+
return Effect.catchAllCause(middleware(withTracer), cause => {
|
|
45
|
+
if (handled) {
|
|
46
|
+
return Effect.void;
|
|
47
|
+
}
|
|
48
|
+
return Effect.matchCauseEffect(ServerError.causeResponse(cause), {
|
|
49
|
+
onFailure: _cause => handleResponse(request, ServerResponse.empty({
|
|
50
|
+
status: 500
|
|
51
|
+
})),
|
|
52
|
+
onSuccess: ([response]) => handleResponse(request, response)
|
|
53
|
+
});
|
|
32
54
|
});
|
|
33
55
|
});
|
|
34
|
-
|
|
35
|
-
return Effect.uninterruptible(Effect.catchAllCause(Effect.scoped(middleware === undefined ? withTracer : middleware(withTracer)), _ => Effect.void));
|
|
56
|
+
return Effect.uninterruptible(Effect.scoped(responded));
|
|
36
57
|
};
|
|
37
58
|
/**
|
|
38
59
|
* @since 1.0.0
|
package/dist/esm/HttpApp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpApp.js","names":["Context","Effect","Exit","FiberRef","dual","globalValue","Layer","Option","Runtime","Scope","ServerError","ServerRequest","ServerResponse","internalMiddleware","toHandled","self","handleResponse","middleware","responded","withFiberRuntime","fiber","request","unsafeGet","getFiberRef","currentContext","HttpServerRequest","preprocessResponse","response","handler","currentPreResponseHandlers","_tag","value","succeed","matchCauseEffect","onFailure","cause","flatMap","causeResponse","pipe","zipRight","failCause","onSuccess","tap","withTracer","tracer","
|
|
1
|
+
{"version":3,"file":"HttpApp.js","names":["Context","Effect","Exit","FiberRef","dual","globalValue","Layer","Option","Runtime","Scope","ServerError","ServerRequest","ServerResponse","internalMiddleware","toHandled","self","handleResponse","middleware","responded","withFiberRuntime","fiber","handled","request","unsafeGet","getFiberRef","currentContext","HttpServerRequest","preprocessResponse","response","handler","currentPreResponseHandlers","_tag","value","succeed","matchCauseEffect","onFailure","cause","flatMap","causeResponse","pipe","zipRight","failCause","onSuccess","tap","withTracer","tracer","undefined","catchAllCause","void","_cause","empty","status","uninterruptible","scoped","Symbol","for","unsafeMake","none","appendPreResponseHandler","update","match","onNone","some","onSome","prev","withPreResponseHandler","locallyWith","toWebHandlerRuntime","runtime","run","runFork","Promise","resolve","provideService","toWeb","withoutBody","method","fromWeb","signal","addEventListener","unsafeInterruptAsFork","clientAbortFiberId","once","toWebHandler","defaultRuntime","toWebHandlerLayer","layer","scope","runSync","make","close","runPromise","build","map","toRuntime","_","runner","extend","then"],"sources":["../../src/HttpApp.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,SAASC,IAAI,QAAQ,iBAAiB;AACtC,SAASC,WAAW,QAAQ,oBAAoB;AAChD,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,KAAK,MAAM,cAAc;AAErC,OAAO,KAAKC,WAAW,MAAM,sBAAsB;AACnD,OAAO,KAAKC,aAAa,MAAM,wBAAwB;AACvD,OAAO,KAAKC,cAAc,MAAM,yBAAyB;AACzD,OAAO,KAAKC,kBAAk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OAAO;IAAEoE,KAAK;IAAE7D;EAAO,CAAW;AACpC,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/platform",
|
|
3
|
-
"version": "0.61.
|
|
3
|
+
"version": "0.61.3",
|
|
4
4
|
"description": "Unified interfaces for common platform-specific services",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"multipasta": "^0.2.2"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@effect/schema": "^0.70.
|
|
18
|
-
"effect": "^3.6.
|
|
17
|
+
"@effect/schema": "^0.70.2",
|
|
18
|
+
"effect": "^3.6.1"
|
|
19
19
|
},
|
|
20
20
|
"publishConfig": {
|
|
21
21
|
"provenance": true
|
package/src/HttpApp.ts
CHANGED
|
@@ -44,38 +44,52 @@ export const toHandled = <E, R, _, EH, RH>(
|
|
|
44
44
|
response: ServerResponse.HttpServerResponse
|
|
45
45
|
) => Effect.Effect<_, EH, RH>,
|
|
46
46
|
middleware?: HttpMiddleware | undefined
|
|
47
|
-
): Effect.Effect<void, never, Exclude<R | RH, Scope.Scope>> => {
|
|
47
|
+
): Effect.Effect<void, never, Exclude<R | RH | ServerRequest.HttpServerRequest, Scope.Scope>> => {
|
|
48
48
|
const responded = Effect.withFiberRuntime<
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
void,
|
|
50
|
+
never,
|
|
51
51
|
R | RH | ServerRequest.HttpServerRequest
|
|
52
52
|
>((fiber) => {
|
|
53
|
+
let handled = false
|
|
53
54
|
const request = Context.unsafeGet(fiber.getFiberRef(FiberRef.currentContext), ServerRequest.HttpServerRequest)
|
|
54
55
|
const preprocessResponse = (response: ServerResponse.HttpServerResponse) => {
|
|
55
56
|
const handler = fiber.getFiberRef(currentPreResponseHandlers)
|
|
56
57
|
return handler._tag === "Some" ? handler.value(request, response) : Effect.succeed(response)
|
|
57
58
|
}
|
|
58
|
-
|
|
59
|
+
const responded = Effect.matchCauseEffect(self, {
|
|
59
60
|
onFailure: (cause) =>
|
|
60
61
|
Effect.flatMap(ServerError.causeResponse(cause), ([response, cause]) =>
|
|
61
62
|
preprocessResponse(response).pipe(
|
|
62
|
-
Effect.flatMap((response) =>
|
|
63
|
+
Effect.flatMap((response) => {
|
|
64
|
+
handled = true
|
|
65
|
+
return handleResponse(request, response)
|
|
66
|
+
}),
|
|
63
67
|
Effect.zipRight(Effect.failCause(cause))
|
|
64
68
|
)),
|
|
65
69
|
onSuccess: (response) =>
|
|
66
70
|
Effect.tap(
|
|
67
71
|
preprocessResponse(response),
|
|
68
|
-
(response) =>
|
|
72
|
+
(response) => {
|
|
73
|
+
handled = true
|
|
74
|
+
return handleResponse(request, response)
|
|
75
|
+
}
|
|
69
76
|
)
|
|
70
77
|
})
|
|
78
|
+
const withTracer = internalMiddleware.tracer(responded)
|
|
79
|
+
if (middleware === undefined) {
|
|
80
|
+
return withTracer as any
|
|
81
|
+
}
|
|
82
|
+
return Effect.catchAllCause(middleware(withTracer), (cause): Effect.Effect<void, EH, RH> => {
|
|
83
|
+
if (handled) {
|
|
84
|
+
return Effect.void
|
|
85
|
+
}
|
|
86
|
+
return Effect.matchCauseEffect(ServerError.causeResponse(cause), {
|
|
87
|
+
onFailure: (_cause) => handleResponse(request, ServerResponse.empty({ status: 500 })),
|
|
88
|
+
onSuccess: ([response]) => handleResponse(request, response)
|
|
89
|
+
})
|
|
90
|
+
})
|
|
71
91
|
})
|
|
72
|
-
|
|
73
|
-
return Effect.uninterruptible(
|
|
74
|
-
Effect.catchAllCause(
|
|
75
|
-
Effect.scoped(middleware === undefined ? withTracer : middleware(withTracer)),
|
|
76
|
-
(_) => Effect.void
|
|
77
|
-
)
|
|
78
|
-
)
|
|
92
|
+
return Effect.uninterruptible(Effect.scoped(responded))
|
|
79
93
|
}
|
|
80
94
|
|
|
81
95
|
/**
|