Skip to content

Commit

Permalink
Merge pull request #56 from bitgopatmcl/consistent-file-names
Browse files Browse the repository at this point in the history
chore: fix inconsistent file names in io-ts-http
  • Loading branch information
bitgopatmcl authored Apr 29, 2022
2 parents 4d21e38 + 41ddf80 commit 94b374d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 39 deletions.
33 changes: 0 additions & 33 deletions packages/io-ts-http/src/array-from-non-empty-delimited-string.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/io-ts-http/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
@@ -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,
): <C extends t.Type<any, string>>(
codec: C,
codecName?: string,
) => t.Type<NonEmptyArray<t.TypeOf<C>>, string> {
return <C extends t.Type<any, string>>(codec: C, codecName: string = codec.name) => {
const neaCodec = nonEmptyArray(codec);
return new t.Type<NonEmptyArray<t.TypeOf<C>>, 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 = <C>() =>
new t.Type(
'EmptyArrayFromUndefined',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 94b374d

Please sign in to comment.