From 41ddf80f2674af808727688a8dd43c1d6e36620e Mon Sep 17 00:00:00 2001 From: Patrick McLaughlin Date: Thu, 28 Apr 2022 14:26:18 -0400 Subject: [PATCH] chore: fix inconsistent file names in io-ts-http --- .../array-from-non-empty-delimited-string.ts | 33 ------------------ packages/io-ts-http/src/index.ts | 3 +- .../src/{query-params.ts => queryParams.ts} | 34 +++++++++++++++++-- ...uery-param.test.ts => queryParams.test.ts} | 2 +- 4 files changed, 33 insertions(+), 39 deletions(-) delete mode 100644 packages/io-ts-http/src/array-from-non-empty-delimited-string.ts rename packages/io-ts-http/src/{query-params.ts => queryParams.ts} (56%) rename packages/io-ts-http/test/{query-param.test.ts => queryParams.test.ts} (99%) diff --git a/packages/io-ts-http/src/array-from-non-empty-delimited-string.ts b/packages/io-ts-http/src/array-from-non-empty-delimited-string.ts deleted file mode 100644 index 730948da..00000000 --- a/packages/io-ts-http/src/array-from-non-empty-delimited-string.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { pipe } from 'fp-ts/function'; -import * as E from 'fp-ts/Either'; -import { NonEmptyArray } from 'fp-ts/NonEmptyArray'; -import * as t from 'io-ts'; -import { nonEmptyArray, NonEmptyString } from 'io-ts-types'; - -function arrayFromNonEmptyDelimitedString( - delimiter: string, - delimiterName: string, -): >( - codec: C, - codecName?: string, -) => t.Type>, string> { - return >(codec: C, codecName: string = codec.name) => { - const neaCodec = nonEmptyArray(codec); - return new t.Type>, string>( - `ArrayFromNonEmpty${delimiterName}DelimitedString(${codecName})`, - neaCodec.is, - (input, context) => - pipe( - NonEmptyString.validate(input, context), - E.map((s) => s.split(delimiter)), - E.chain((arr) => neaCodec.validate(arr, context)), - ), - (a) => a.map(codec.encode).join(delimiter), - ); - }; -} - -export const arrayFromNonEmptyCommaDelimitedString = arrayFromNonEmptyDelimitedString( - ',', - 'Comma', -); diff --git a/packages/io-ts-http/src/index.ts b/packages/io-ts-http/src/index.ts index 66cb8063..80165425 100644 --- a/packages/io-ts-http/src/index.ts +++ b/packages/io-ts-http/src/index.ts @@ -3,9 +3,8 @@ * Codecs for (de)serializing HTTP requests from both the client and server side */ -export * from './array-from-non-empty-delimited-string'; export * from './combinators'; export * from './httpResponse'; export * from './httpRequest'; export * from './httpRoute'; -export * from './query-params'; +export * from './queryParams'; diff --git a/packages/io-ts-http/src/query-params.ts b/packages/io-ts-http/src/queryParams.ts similarity index 56% rename from packages/io-ts-http/src/query-params.ts rename to packages/io-ts-http/src/queryParams.ts index 7fce6842..255280e8 100644 --- a/packages/io-ts-http/src/query-params.ts +++ b/packages/io-ts-http/src/queryParams.ts @@ -1,11 +1,39 @@ +import { pipe } from 'fp-ts/function'; +import * as E from 'fp-ts/Either'; import { NonEmptyArray } from 'fp-ts/NonEmptyArray'; import * as t from 'io-ts'; -import { nonEmptyArray } from 'io-ts-types'; - -import { arrayFromNonEmptyCommaDelimitedString } from './array-from-non-empty-delimited-string'; +import { nonEmptyArray, NonEmptyString } from 'io-ts-types'; export type { NonEmptyArray } from 'fp-ts/NonEmptyArray'; +function arrayFromNonEmptyDelimitedString( + delimiter: string, + delimiterName: string, +): >( + codec: C, + codecName?: string, +) => t.Type>, string> { + return >(codec: C, codecName: string = codec.name) => { + const neaCodec = nonEmptyArray(codec); + return new t.Type>, string>( + `ArrayFromNonEmpty${delimiterName}DelimitedString(${codecName})`, + neaCodec.is, + (input, context) => + pipe( + NonEmptyString.validate(input, context), + E.map((s) => s.split(delimiter)), + E.chain((arr) => neaCodec.validate(arr, context)), + ), + (a) => a.map(codec.encode).join(delimiter), + ); + }; +} + +const arrayFromNonEmptyCommaDelimitedString = arrayFromNonEmptyDelimitedString( + ',', + 'Comma', +); + const emptyArrayFromUndefined = () => new t.Type( 'EmptyArrayFromUndefined', diff --git a/packages/io-ts-http/test/query-param.test.ts b/packages/io-ts-http/test/queryParams.test.ts similarity index 99% rename from packages/io-ts-http/test/query-param.test.ts rename to packages/io-ts-http/test/queryParams.test.ts index 98850305..f2d04949 100644 --- a/packages/io-ts-http/test/query-param.test.ts +++ b/packages/io-ts-http/test/queryParams.test.ts @@ -4,7 +4,7 @@ import * as E from 'fp-ts/Either'; import * as t from 'io-ts'; import { PathReporter } from 'io-ts/lib/PathReporter'; -import { arrayFromQueryParam, nonEmptyArrayFromQueryParam } from '../src/query-params'; +import { arrayFromQueryParam, nonEmptyArrayFromQueryParam } from '../src/queryParams'; import { NumberFromString } from 'io-ts-types'; describe('nonEmptyArrayFromQueryParam combinations', () => {