diff --git a/src/VariableDecoder/origin.test.ts b/src/VariableDecoder/origin.test.ts index 6dcf339..067782f 100644 --- a/src/VariableDecoder/origin.test.ts +++ b/src/VariableDecoder/origin.test.ts @@ -20,7 +20,11 @@ describe(origin, () => { .map(([url, port]) => `${new URL(url).origin}:${port}`), (str) => { const variable = new Variable('KEY', str); - expect(decoder(variable)).toStrictEqual(E.right(str)); + + const { protocol, hostname, port } = new URL(str); + const expected = { protocol, hostname, port }; + + expect(decoder(variable)).toStrictEqual(E.right(expected)); }, ), ); diff --git a/src/VariableDecoder/origin.ts b/src/VariableDecoder/origin.ts index b78d896..c542a86 100644 --- a/src/VariableDecoder/origin.ts +++ b/src/VariableDecoder/origin.ts @@ -4,10 +4,12 @@ import * as RE from 'fp-ts/ReaderEither'; import { ask, decodeFailed, validate, VariableDecoder } from './VariableDecoder'; +type Origin = Pick; + /** * Decodes a URL origin (scheme + hostname + port). */ -const origin = (): VariableDecoder => +const origin = (): VariableDecoder => pipe( RE.Do, RE.bind('value', () => ask()), @@ -19,7 +21,11 @@ const origin = (): VariableDecoder => ), RE.chain(validate(({ url }) => url.pathname !== '', 'must not have a pathname')), RE.chain(validate(({ value, url }) => url.origin === value, 'must be a valid URL origin')), - RE.map(({ value }) => value), + RE.map(({ url: { protocol, hostname, port } }) => ({ + protocol, + hostname, + port, + })), ); export { origin };