From a5af42f70196c6af479b47a213d5969ce72329a5 Mon Sep 17 00:00:00 2001 From: Maxim Khramtsov Date: Mon, 29 Jun 2026 20:03:52 +0200 Subject: [PATCH 1/5] make input type like in great duration module --- packages/effect/src/unstable/http/Headers.ts | 4 ++++ packages/effect/src/unstable/http/HttpBody.ts | 4 ++-- .../effect/src/unstable/http/HttpClientRequest.ts | 2 +- packages/effect/src/unstable/http/Url.ts | 14 +++++++------- packages/effect/src/unstable/http/UrlParams.ts | 4 ++++ 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/effect/src/unstable/http/Headers.ts b/packages/effect/src/unstable/http/Headers.ts index f0fb26744b..9849172215 100644 --- a/packages/effect/src/unstable/http/Headers.ts +++ b/packages/effect/src/unstable/http/Headers.ts @@ -163,6 +163,7 @@ export const HeadersSchema: HeadersSchema = Schema.declare( * @since 4.0.0 */ export type Input = + | Headers | Record.ReadonlyRecord | undefined> | Iterable @@ -185,6 +186,9 @@ export const empty: Headers = Object.create(Proto) * @since 4.0.0 */ export const fromInput: (input?: Input) => Headers = (input) => { + if (isHeaders(input)) { + return input + } if (input === undefined) { return empty } else if (Symbol.iterator in input) { diff --git a/packages/effect/src/unstable/http/HttpBody.ts b/packages/effect/src/unstable/http/HttpBody.ts index 57d6d3254b..c43a60d4b3 100644 --- a/packages/effect/src/unstable/http/HttpBody.ts +++ b/packages/effect/src/unstable/http/HttpBody.ts @@ -335,8 +335,8 @@ export const jsonSchema = ( * @category constructors * @since 4.0.0 */ -export const urlParams = (urlParams: UrlParams.UrlParams, contentType?: string): Uint8Array => - text(UrlParams.toString(urlParams), contentType ?? "application/x-www-form-urlencoded") +export const urlParams = (urlParams: UrlParams.Input, contentType?: string): Uint8Array => + text(UrlParams.toString(UrlParams.fromInput(urlParams)), contentType ?? "application/x-www-form-urlencoded") /** * HTTP body variant backed by Web `FormData`. diff --git a/packages/effect/src/unstable/http/HttpClientRequest.ts b/packages/effect/src/unstable/http/HttpClientRequest.ts index 22ba2b8f15..dd69bf6dd9 100644 --- a/packages/effect/src/unstable/http/HttpClientRequest.ts +++ b/packages/effect/src/unstable/http/HttpClientRequest.ts @@ -116,7 +116,7 @@ const Proto = { export function makeWith( method: HttpMethod, url: string, - urlParams: UrlParams.UrlParams, + urlParams: UrlParams.Input, hash: Option.Option, headers: Headers.Headers, body: HttpBody.HttpBody diff --git a/packages/effect/src/unstable/http/Url.ts b/packages/effect/src/unstable/http/Url.ts index 284d1a3a9d..c50e28002d 100644 --- a/packages/effect/src/unstable/http/Url.ts +++ b/packages/effect/src/unstable/http/Url.ts @@ -259,11 +259,11 @@ export const setUsername: { * @since 4.0.0 */ export const setUrlParams: { - (urlParams: UrlParams.UrlParams): (url: URL) => URL - (url: URL, urlParams: UrlParams.UrlParams): URL -} = dual(2, (url: URL, searchParams: UrlParams.UrlParams) => + (urlParams: UrlParams.Input): (url: URL) => URL + (url: URL, urlParams: UrlParams.Input): URL +} = dual(2, (url: URL, urlParams: UrlParams.Input) => mutate(url, (url) => { - url.search = UrlParams.toString(searchParams) + url.search = UrlParams.toString(UrlParams.fromInput(urlParams)) })) /** @@ -321,9 +321,9 @@ export const urlParams = (url: URL): UrlParams.UrlParams => UrlParams.fromInput( * @since 4.0.0 */ export const modifyUrlParams: { - (f: (urlParams: UrlParams.UrlParams) => UrlParams.UrlParams): (url: URL) => URL - (url: URL, f: (urlParams: UrlParams.UrlParams) => UrlParams.UrlParams): URL -} = dual(2, (url: URL, f: (urlParams: UrlParams.UrlParams) => UrlParams.UrlParams) => + (f: (urlParams: UrlParams.Input) => UrlParams.UrlParams): (url: URL) => URL + (url: URL, f: (urlParams: UrlParams.Input) => UrlParams.UrlParams): URL +} = dual(2, (url: URL, f: (urlParams: UrlParams.Input) => UrlParams.UrlParams) => mutate(url, (url) => { const params = f(UrlParams.fromInput(url.searchParams)) url.search = UrlParams.toString(params) diff --git a/packages/effect/src/unstable/http/UrlParams.ts b/packages/effect/src/unstable/http/UrlParams.ts index c95bf8b80d..4243c930ee 100644 --- a/packages/effect/src/unstable/http/UrlParams.ts +++ b/packages/effect/src/unstable/http/UrlParams.ts @@ -65,6 +65,7 @@ export const isUrlParams = (u: unknown): u is UrlParams => hasProperty(u, TypeId * @since 4.0.0 */ export type Input = + | UrlParams | CoercibleRecordInput | Iterable | URLSearchParams @@ -157,6 +158,9 @@ export const make = (params: ReadonlyArray): UrlParam * @since 4.0.0 */ export const fromInput = (input: Input): UrlParams => { + if (isUrlParams(input)) { + return input + } const parsed = fromInputNested(input) const out: Array<[string, string]> = [] for (let i = 0; i < parsed.length; i++) { From a801177d69787c5c9defd6288fe269255d98aa69 Mon Sep 17 00:00:00 2001 From: Maxim Khramtsov Date: Tue, 30 Jun 2026 18:22:47 +0200 Subject: [PATCH 2/5] remove input from the contravariant position --- packages/effect/src/unstable/http/Url.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/effect/src/unstable/http/Url.ts b/packages/effect/src/unstable/http/Url.ts index c50e28002d..5302dfcc46 100644 --- a/packages/effect/src/unstable/http/Url.ts +++ b/packages/effect/src/unstable/http/Url.ts @@ -321,9 +321,9 @@ export const urlParams = (url: URL): UrlParams.UrlParams => UrlParams.fromInput( * @since 4.0.0 */ export const modifyUrlParams: { - (f: (urlParams: UrlParams.Input) => UrlParams.UrlParams): (url: URL) => URL - (url: URL, f: (urlParams: UrlParams.Input) => UrlParams.UrlParams): URL -} = dual(2, (url: URL, f: (urlParams: UrlParams.Input) => UrlParams.UrlParams) => + (f: (urlParams: UrlParams.UrlParams) => UrlParams.UrlParams): (url: URL) => URL + (url: URL, f: (urlParams: UrlParams.UrlParams) => UrlParams.UrlParams): URL +} = dual(2, (url: URL, f: (urlParams: UrlParams.UrlParams) => UrlParams.UrlParams) => mutate(url, (url) => { const params = f(UrlParams.fromInput(url.searchParams)) url.search = UrlParams.toString(params) From 3954cf2face0db901465ab1cffee52039a443c11 Mon Sep 17 00:00:00 2001 From: Maxim Khramtsov Date: Tue, 30 Jun 2026 18:26:54 +0200 Subject: [PATCH 3/5] fix: rollback header module --- packages/effect/src/unstable/http/Headers.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/effect/src/unstable/http/Headers.ts b/packages/effect/src/unstable/http/Headers.ts index 9849172215..f0fb26744b 100644 --- a/packages/effect/src/unstable/http/Headers.ts +++ b/packages/effect/src/unstable/http/Headers.ts @@ -163,7 +163,6 @@ export const HeadersSchema: HeadersSchema = Schema.declare( * @since 4.0.0 */ export type Input = - | Headers | Record.ReadonlyRecord | undefined> | Iterable @@ -186,9 +185,6 @@ export const empty: Headers = Object.create(Proto) * @since 4.0.0 */ export const fromInput: (input?: Input) => Headers = (input) => { - if (isHeaders(input)) { - return input - } if (input === undefined) { return empty } else if (Symbol.iterator in input) { From 396e16a8fb5f563304cbc4f0994a0fee7f886ecf Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Thu, 2 Jul 2026 09:38:30 +1200 Subject: [PATCH 4/5] wip --- packages/effect/src/unstable/http/Url.ts | 6 +++--- packages/effect/src/unstable/http/UrlParams.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/effect/src/unstable/http/Url.ts b/packages/effect/src/unstable/http/Url.ts index 5302dfcc46..18f5acaa2a 100644 --- a/packages/effect/src/unstable/http/Url.ts +++ b/packages/effect/src/unstable/http/Url.ts @@ -321,9 +321,9 @@ export const urlParams = (url: URL): UrlParams.UrlParams => UrlParams.fromInput( * @since 4.0.0 */ export const modifyUrlParams: { - (f: (urlParams: UrlParams.UrlParams) => UrlParams.UrlParams): (url: URL) => URL - (url: URL, f: (urlParams: UrlParams.UrlParams) => UrlParams.UrlParams): URL -} = dual(2, (url: URL, f: (urlParams: UrlParams.UrlParams) => UrlParams.UrlParams) => + (f: (urlParams: UrlParams.UrlParams) => UrlParams.Input): (url: URL) => URL + (url: URL, f: (urlParams: UrlParams.UrlParams) => UrlParams.Input): URL +} = dual(2, (url: URL, f: (urlParams: UrlParams.UrlParams) => UrlParams.Input) => mutate(url, (url) => { const params = f(UrlParams.fromInput(url.searchParams)) url.search = UrlParams.toString(params) diff --git a/packages/effect/src/unstable/http/UrlParams.ts b/packages/effect/src/unstable/http/UrlParams.ts index 4243c930ee..1685e28731 100644 --- a/packages/effect/src/unstable/http/UrlParams.ts +++ b/packages/effect/src/unstable/http/UrlParams.ts @@ -499,7 +499,7 @@ export const makeUrl = ( * @category converting * @since 4.0.0 */ -export const toString = (self: UrlParams): string => new URLSearchParams(self.params as any).toString() +export const toString = (input: Input): string => new URLSearchParams(fromInput(input).params as any).toString() const baseUrl = (): string | undefined => { if ( From 6ab7cfd3d73fe8f9b416729a1542b19517b19885 Mon Sep 17 00:00:00 2001 From: Tim Smart Date: Thu, 2 Jul 2026 09:39:05 +1200 Subject: [PATCH 5/5] changeset --- .changeset/shaky-beans-throw.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/shaky-beans-throw.md diff --git a/.changeset/shaky-beans-throw.md b/.changeset/shaky-beans-throw.md new file mode 100644 index 0000000000..e0fa124dd1 --- /dev/null +++ b/.changeset/shaky-beans-throw.md @@ -0,0 +1,5 @@ +--- +"effect": patch +--- + +accept UrlParams.Input in some UrlParams apis