Skip to content

Commit

Permalink
fix HeaderValues
Browse files Browse the repository at this point in the history
  • Loading branch information
patroza committed Oct 2, 2024
1 parent 827b8cf commit 18bf3bf
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions packages/platform/src/Headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as Schema from "@effect/schema/Schema"
import * as Equivalence from "effect/Equivalence"
import * as FiberRef from "effect/FiberRef"
import { dual } from "effect/Function"
import { dual, identity } from "effect/Function"
import { globalValue } from "effect/GlobalValue"
import type * as Option from "effect/Option"
import * as Predicate from "effect/Predicate"
Expand Down Expand Up @@ -37,7 +37,7 @@ export const isHeaders = (u: unknown): u is Headers => Predicate.hasProperty(u,
*/
export interface Headers {
readonly [HeadersTypeId]: HeadersTypeId
readonly [key: string]: Redacted.Redacted<string> | string
readonly [key: string]: HeaderValues
}

const Proto = Object.assign(Object.create(null), {
Expand Down Expand Up @@ -65,10 +65,7 @@ export const schemaFromSelf: Schema.Schema<Headers> = Schema.declare(isHeaders,
)
})

const HeaderValues = Schema.Union(
Schema.Union(Schema.String, Schema.Array(Schema.String)),
Schema.Union(Schema.Redacted(Schema.String), Schema.Array(Schema.Redacted(Schema.String)))
)
const HeaderValues = Schema.Union(Schema.String, Schema.Redacted(Schema.String))
type HeaderValues = typeof HeaderValues.Type

/**
Expand All @@ -79,13 +76,13 @@ export const schema: Schema.Schema<
Headers,
Record.ReadonlyRecord<
string,
HeaderValues
HeaderValues | ReadonlyArray<HeaderValues>
>
> = Schema
.transform(
Schema.Record({ key: Schema.String, value: HeaderValues }),
Schema.Record({ key: Schema.String, value: Schema.Union(Schema.String, Schema.Array(Schema.String)) }),
schemaFromSelf,
{ strict: true, decode: (record) => fromInput(record), encode: (a) => a }
{ strict: true, decode: (record) => fromInput(record), encode: identity }

Check failure on line 85 in packages/platform/src/Headers.ts

View workflow job for this annotation

GitHub Actions / Snapshot

Argument of type '{ strict: true; decode: (record: { readonly [x: string]: string | readonly string[]; }) => Headers; encode: <A>(a: A) => A; }' is not assignable to parameter of type '{ readonly decode: (fromA: { readonly [x: string]: string | readonly string[]; }, fromI: { readonly [x: string]: string | readonly string[]; }) => Headers; readonly encode: (toI: Headers, toA: Headers) => { ...; }; readonly strict?: true | undefined; } | { ...; }'.

Check failure on line 85 in packages/platform/src/Headers.ts

View workflow job for this annotation

GitHub Actions / Types

Argument of type '{ strict: true; decode: (record: { readonly [x: string]: string | readonly string[]; }) => Headers; encode: <A>(a: A) => A; }' is not assignable to parameter of type '{ readonly decode: (fromA: { readonly [x: string]: string | readonly string[]; }, fromI: { readonly [x: string]: string | readonly string[]; }) => Headers; readonly encode: (toI: Headers, toA: Headers) => { ...; }; readonly strict?: true | undefined; } | { ...; }'.
)

/**
Expand All @@ -110,16 +107,19 @@ export const fromInput: (input?: Input) => Headers = (input) => {
if (input === undefined) {
return empty
} else if (Symbol.iterator in input) {
const out: Record<string, string> = Object.create(Proto)
const out: Record<string, HeaderValues> = Object.create(Proto)
for (const [k, v] of input) {
out[k.toLowerCase()] = Redacted.isRedacted(v) ? Redacted.value(v) : v
out[k.toLowerCase()] = v
}
return out as Headers
}
const out: Record<string, string> = Object.create(Proto)
const out: Record<string, HeaderValues> = Object.create(Proto)
for (const [k, v] of Object.entries(input)) {
if (Array.isArray(v)) {
out[k.toLowerCase()] = v.join(", ")
const redacted = v.some((_) => Redacted.isRedacted(_))
out[k.toLowerCase()] = redacted
? Redacted.make(v.map((_) => Redacted.isRedacted(_) ? Redacted.value(_) : _).join(", "))
: v.join(", ")
} else if (v !== undefined) {
out[k.toLowerCase()] = v as string
}
Expand Down

0 comments on commit 18bf3bf

Please sign in to comment.