Skip to content

Commit 94b374d

Browse files
authored
Merge pull request #56 from bitgopatmcl/consistent-file-names
chore: fix inconsistent file names in io-ts-http
2 parents 4d21e38 + 41ddf80 commit 94b374d

File tree

4 files changed

+33
-39
lines changed

4 files changed

+33
-39
lines changed

packages/io-ts-http/src/array-from-non-empty-delimited-string.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

packages/io-ts-http/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
* Codecs for (de)serializing HTTP requests from both the client and server side
44
*/
55

6-
export * from './array-from-non-empty-delimited-string';
76
export * from './combinators';
87
export * from './httpResponse';
98
export * from './httpRequest';
109
export * from './httpRoute';
11-
export * from './query-params';
10+
export * from './queryParams';

packages/io-ts-http/src/query-params.ts renamed to packages/io-ts-http/src/queryParams.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
1+
import { pipe } from 'fp-ts/function';
2+
import * as E from 'fp-ts/Either';
13
import { NonEmptyArray } from 'fp-ts/NonEmptyArray';
24
import * as t from 'io-ts';
3-
import { nonEmptyArray } from 'io-ts-types';
4-
5-
import { arrayFromNonEmptyCommaDelimitedString } from './array-from-non-empty-delimited-string';
5+
import { nonEmptyArray, NonEmptyString } from 'io-ts-types';
66

77
export type { NonEmptyArray } from 'fp-ts/NonEmptyArray';
88

9+
function arrayFromNonEmptyDelimitedString(
10+
delimiter: string,
11+
delimiterName: string,
12+
): <C extends t.Type<any, string>>(
13+
codec: C,
14+
codecName?: string,
15+
) => t.Type<NonEmptyArray<t.TypeOf<C>>, string> {
16+
return <C extends t.Type<any, string>>(codec: C, codecName: string = codec.name) => {
17+
const neaCodec = nonEmptyArray(codec);
18+
return new t.Type<NonEmptyArray<t.TypeOf<C>>, string>(
19+
`ArrayFromNonEmpty${delimiterName}DelimitedString(${codecName})`,
20+
neaCodec.is,
21+
(input, context) =>
22+
pipe(
23+
NonEmptyString.validate(input, context),
24+
E.map((s) => s.split(delimiter)),
25+
E.chain((arr) => neaCodec.validate(arr, context)),
26+
),
27+
(a) => a.map(codec.encode).join(delimiter),
28+
);
29+
};
30+
}
31+
32+
const arrayFromNonEmptyCommaDelimitedString = arrayFromNonEmptyDelimitedString(
33+
',',
34+
'Comma',
35+
);
36+
937
const emptyArrayFromUndefined = <C>() =>
1038
new t.Type(
1139
'EmptyArrayFromUndefined',

packages/io-ts-http/test/query-param.test.ts renamed to packages/io-ts-http/test/queryParams.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as E from 'fp-ts/Either';
44
import * as t from 'io-ts';
55
import { PathReporter } from 'io-ts/lib/PathReporter';
66

7-
import { arrayFromQueryParam, nonEmptyArrayFromQueryParam } from '../src/query-params';
7+
import { arrayFromQueryParam, nonEmptyArrayFromQueryParam } from '../src/queryParams';
88
import { NumberFromString } from 'io-ts-types';
99

1010
describe('nonEmptyArrayFromQueryParam combinations', () => {

0 commit comments

Comments
 (0)