@effect/platform 0.58.13 → 0.58.15

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.
@@ -748,3 +748,41 @@ export const withCookiesRef = dual<
748
748
  ))
749
749
  )
750
750
  )
751
+
752
+ /** @internal */
753
+ export const followRedirects = dual<
754
+ (
755
+ maxRedirects?: number | undefined
756
+ ) => <E, R>(self: Client.HttpClient.WithResponse<E, R>) => Client.HttpClient.WithResponse<E, R>,
757
+ <E, R>(
758
+ self: Client.HttpClient.WithResponse<E, R>,
759
+ maxRedirects?: number | undefined
760
+ ) => Client.HttpClient.WithResponse<E, R>
761
+ >((args) => isClient(args[0]), <E, R>(
762
+ self: Client.HttpClient.WithResponse<E, R>,
763
+ maxRedirects?: number | undefined
764
+ ): Client.HttpClient.WithResponse<E, R> =>
765
+ make(
766
+ (request) => {
767
+ const loop = (
768
+ request: ClientRequest.HttpClientRequest,
769
+ redirects: number
770
+ ): Effect.Effect<ClientResponse.HttpClientResponse, E, R> =>
771
+ Effect.flatMap(
772
+ self.execute(Effect.succeed(request)),
773
+ (response) =>
774
+ response.status >= 300 && response.status < 400 && response.headers.location &&
775
+ redirects < (maxRedirects ?? 10)
776
+ ? loop(
777
+ internalRequest.setUrl(
778
+ request,
779
+ response.headers.location
780
+ ),
781
+ redirects + 1
782
+ )
783
+ : Effect.succeed(response)
784
+ )
785
+ return Effect.flatMap(request, (request) => loop(request, 0))
786
+ },
787
+ self.preprocess
788
+ ))
@@ -150,7 +150,7 @@ class RouterImpl<E = never, R = never> extends Effectable.StructuralClass<
150
150
  readonly mounts: Chunk.Chunk<
151
151
  readonly [
152
152
  prefix: string,
153
- httpApp: App.HttpApp<Respondable.Respondable, E, R>,
153
+ httpApp: App.Default<E, R>,
154
154
  options?: { readonly includePrefix?: boolean | undefined } | undefined
155
155
  ]
156
156
  >
@@ -506,6 +506,34 @@ export const options = route("OPTIONS")
506
506
 
507
507
  /** @internal */
508
508
  export const use = dual<
509
+ <E, R, R1, E1>(
510
+ f: (self: Router.Route.Middleware<E, R>) => App.Default<E1, R1>
511
+ ) => (self: Router.HttpRouter<E, R>) => Router.HttpRouter<E1, Router.HttpRouter.ExcludeProvided<R1>>,
512
+ <E, R, R1, E1>(
513
+ self: Router.HttpRouter<E, R>,
514
+ f: (self: Router.Route.Middleware<E, R>) => App.Default<E1, R1>
515
+ ) => Router.HttpRouter<E1, Router.HttpRouter.ExcludeProvided<R1>>
516
+ >(2, (self, f) =>
517
+ new RouterImpl<any, any>(
518
+ Chunk.map(
519
+ self.routes,
520
+ (route) =>
521
+ new RouteImpl(
522
+ route.method,
523
+ route.path,
524
+ f(Effect.flatMap(route.handler, Respondable.toResponse)) as any,
525
+ route.prefix,
526
+ route.uninterruptible
527
+ )
528
+ ),
529
+ Chunk.map(
530
+ self.mounts,
531
+ ([path, app]) => [path, f(app as any)]
532
+ )
533
+ ))
534
+
535
+ /** @internal */
536
+ export const transform = dual<
509
537
  <E, R, R1, E1>(
510
538
  f: (self: Router.Route.Handler<E, R>) => App.HttpApp<Respondable.Respondable, E1, R1>
511
539
  ) => (self: Router.HttpRouter<E, R>) => Router.HttpRouter<E1, Router.HttpRouter.ExcludeProvided<R1>>,
@@ -517,11 +545,18 @@ export const use = dual<
517
545
  new RouterImpl<any, any>(
518
546
  Chunk.map(
519
547
  self.routes,
520
- (route) => new RouteImpl(route.method, route.path, f(route.handler) as any, route.prefix, route.uninterruptible)
548
+ (route) =>
549
+ new RouteImpl(
550
+ route.method,
551
+ route.path,
552
+ f(route.handler) as any,
553
+ route.prefix,
554
+ route.uninterruptible
555
+ )
521
556
  ),
522
557
  Chunk.map(
523
558
  self.mounts,
524
- ([path, app]) => [path, f(app as any)]
559
+ ([path, app]) => [path, Effect.flatMap(f(app as any), Respondable.toResponse)]
525
560
  )
526
561
  ))
527
562
 
@@ -534,7 +569,7 @@ export const catchAll = dual<
534
569
  self: Router.HttpRouter<E, R>,
535
570
  f: (e: E) => Router.Route.Handler<E2, R2>
536
571
  ) => Router.HttpRouter<E2, R | Router.HttpRouter.ExcludeProvided<R2>>
537
- >(2, (self, f) => use(self, Effect.catchAll(f)))
572
+ >(2, (self, f) => transform(self, Effect.catchAll(f)))
538
573
 
539
574
  /** @internal */
540
575
  export const catchAllCause = dual<
@@ -545,7 +580,7 @@ export const catchAllCause = dual<
545
580
  self: Router.HttpRouter<E, R>,
546
581
  f: (e: Cause.Cause<E>) => Router.Route.Handler<E2, R2>
547
582
  ) => Router.HttpRouter<E2, R | Router.HttpRouter.ExcludeProvided<R2>>
548
- >(2, (self, f) => use(self, Effect.catchAllCause(f)))
583
+ >(2, (self, f) => transform(self, Effect.catchAllCause(f)))
549
584
 
550
585
  /** @internal */
551
586
  export const catchTag = dual<
@@ -560,7 +595,7 @@ export const catchTag = dual<
560
595
  k: K,
561
596
  f: (e: Extract<E, { _tag: K }>) => Router.Route.Handler<E1, R1>
562
597
  ) => Router.HttpRouter<Exclude<E, { _tag: K }> | E1, R | Router.HttpRouter.ExcludeProvided<R1>>
563
- >(3, (self, k, f) => use(self, Effect.catchTag(k, f)))
598
+ >(3, (self, k, f) => transform(self, Effect.catchTag(k, f)))
564
599
 
565
600
  /** @internal */
566
601
  export const catchTags: {