@effect/platform 0.73.0 → 0.74.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 (37) hide show
  1. package/dist/cjs/HttpApiClient.js +1 -1
  2. package/dist/cjs/HttpApiClient.js.map +1 -1
  3. package/dist/cjs/HttpApiError.js +6 -15
  4. package/dist/cjs/HttpApiError.js.map +1 -1
  5. package/dist/cjs/HttpClient.js +8 -1
  6. package/dist/cjs/HttpClient.js.map +1 -1
  7. package/dist/cjs/HttpMethod.js +24 -1
  8. package/dist/cjs/HttpMethod.js.map +1 -1
  9. package/dist/cjs/OpenApi.js +1 -1
  10. package/dist/cjs/OpenApi.js.map +1 -1
  11. package/dist/cjs/internal/httpClient.js +3 -1
  12. package/dist/cjs/internal/httpClient.js.map +1 -1
  13. package/dist/dts/HttpApiError.d.ts +7 -31
  14. package/dist/dts/HttpApiError.d.ts.map +1 -1
  15. package/dist/dts/HttpClient.d.ts +22 -0
  16. package/dist/dts/HttpClient.d.ts.map +1 -1
  17. package/dist/dts/HttpMethod.d.ts +22 -0
  18. package/dist/dts/HttpMethod.d.ts.map +1 -1
  19. package/dist/esm/HttpApiClient.js +1 -1
  20. package/dist/esm/HttpApiClient.js.map +1 -1
  21. package/dist/esm/HttpApiError.js +4 -14
  22. package/dist/esm/HttpApiError.js.map +1 -1
  23. package/dist/esm/HttpClient.js +7 -0
  24. package/dist/esm/HttpClient.js.map +1 -1
  25. package/dist/esm/HttpMethod.js +22 -0
  26. package/dist/esm/HttpMethod.js.map +1 -1
  27. package/dist/esm/OpenApi.js +1 -1
  28. package/dist/esm/OpenApi.js.map +1 -1
  29. package/dist/esm/internal/httpClient.js +2 -0
  30. package/dist/esm/internal/httpClient.js.map +1 -1
  31. package/package.json +2 -2
  32. package/src/HttpApiClient.ts +1 -1
  33. package/src/HttpApiError.ts +4 -55
  34. package/src/HttpClient.ts +28 -0
  35. package/src/HttpMethod.ts +24 -0
  36. package/src/OpenApi.ts +1 -1
  37. package/src/internal/httpClient.ts +11 -0
package/src/HttpClient.ts CHANGED
@@ -719,6 +719,34 @@ export const tap: {
719
719
  ): HttpClient.With<E | E2, R | R2>
720
720
  } = internal.tap
721
721
 
722
+ /**
723
+ * Performs an additional effect after an unsuccessful request.
724
+ *
725
+ * @since 1.0.0
726
+ * @category mapping & sequencing
727
+ */
728
+ export const tapError: {
729
+ /**
730
+ * Performs an additional effect after an unsuccessful request.
731
+ *
732
+ * @since 1.0.0
733
+ * @category mapping & sequencing
734
+ */
735
+ <_, E, E2, R2>(
736
+ f: (e: NoInfer<E>) => Effect.Effect<_, E2, R2>
737
+ ): <R>(self: HttpClient.With<E, R>) => HttpClient.With<E | E2, R | R2>
738
+ /**
739
+ * Performs an additional effect after an unsuccessful request.
740
+ *
741
+ * @since 1.0.0
742
+ * @category mapping & sequencing
743
+ */
744
+ <E, R, _, E2, R2>(
745
+ self: HttpClient.With<E, R>,
746
+ f: (e: NoInfer<E>) => Effect.Effect<_, E2, R2>
747
+ ): HttpClient.With<E | E2, R | R2>
748
+ } = internal.tapError
749
+
722
750
  /**
723
751
  * Performs an additional effect on the request before sending it.
724
752
  *
package/src/HttpMethod.ts CHANGED
@@ -33,3 +33,27 @@ export declare namespace HttpMethod {
33
33
  * @since 1.0.0
34
34
  */
35
35
  export const hasBody = (method: HttpMethod): boolean => method !== "GET" && method !== "HEAD" && method !== "OPTIONS"
36
+
37
+ /**
38
+ * @since 1.0.0
39
+ */
40
+ export const all: ReadonlySet<HttpMethod> = new Set(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"])
41
+
42
+ /**
43
+ * Tests if a value is a `HttpMethod`.
44
+ *
45
+ * @param input - The value to test.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { HttpMethod } from "@effect/platform"
50
+ *
51
+ * assert.deepStrictEqual(HttpMethod.isHttpMethod("GET"), true)
52
+ * assert.deepStrictEqual(HttpMethod.isHttpMethod("get"), false)
53
+ * assert.deepStrictEqual(HttpMethod.isHttpMethod(1), false)
54
+ * ```
55
+ *
56
+ * @since 1.0.0
57
+ * @category refinements
58
+ */
59
+ export const isHttpMethod = (u: unknown): u is HttpMethod => all.has(u as HttpMethod)
package/src/OpenApi.ts CHANGED
@@ -403,7 +403,7 @@ export const fromApi = <Id extends string, Groups extends HttpApiGroup.Any, E, R
403
403
  processResponseMap(successes, () => "Success")
404
404
  processResponseMap(errors, () => "Error")
405
405
 
406
- const path = endpoint.path.replace(/:(\w+)[^/]*/g, "{$1}")
406
+ const path = endpoint.path.replace(/:(\w+)/g, "{$1}")
407
407
  const method = endpoint.method.toLowerCase() as OpenAPISpecMethodName
408
408
  if (!spec.paths[path]) {
409
409
  spec.paths[path] = {}
@@ -621,6 +621,17 @@ export const tap = dual<
621
621
  ) => Client.HttpClient.With<E | E2, R | R2>
622
622
  >(2, (self, f) => transformResponse(self, Effect.tap(f)))
623
623
 
624
+ /** @internal */
625
+ export const tapError = dual<
626
+ <_, E, E2, R2>(
627
+ f: (e: NoInfer<E>) => Effect.Effect<_, E2, R2>
628
+ ) => <R>(self: Client.HttpClient.With<E, R>) => Client.HttpClient.With<E | E2, R | R2>,
629
+ <E, R, _, E2, R2>(
630
+ self: Client.HttpClient.With<E, R>,
631
+ f: (e: NoInfer<E>) => Effect.Effect<_, E2, R2>
632
+ ) => Client.HttpClient.With<E | E2, R | R2>
633
+ >(2, (self, f) => transformResponse(self, Effect.tapError(f)))
634
+
624
635
  /** @internal */
625
636
  export const tapRequest = dual<
626
637
  <_, E2, R2>(