Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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