@@ -4,7 +4,7 @@ import { pipe } from 'fp-ts/lib/pipeable';
4
4
import { isSome , map , Option } from 'fp-ts/lib/Option' ;
5
5
import { serializeOperationObject } from './operation-object' ;
6
6
import { array , flatten } from 'fp-ts/lib/Array' ;
7
- import { Dictionary } from '../../../../utils/types' ;
7
+ import { Dictionary , Kind } from '../../../../utils/types' ;
8
8
import { file , File } from '../../../../utils/fs' ;
9
9
import { serializedDependency , serializeDependencies } from '../../common/data/serialized-dependency' ;
10
10
import { decapitalize } from '@devexperts/utils/dist/string' ;
@@ -21,43 +21,43 @@ import { ask } from 'fp-ts/lib/Reader';
21
21
import { Context } from '../../common/utils' ;
22
22
23
23
const serializePath = combineReader ( ask < Context > ( ) , serializeOperationObject , ( e , serializeOperationObject ) => {
24
- const run = ( from : Ref , url : string , item : PathItemObject ) : Either < Error , SerializedType > => {
24
+ const run = ( from : Ref , url : string , kind : Kind , item : PathItemObject ) : Either < Error , SerializedType > => {
25
25
if ( isSome ( item . $ref ) ) {
26
26
const $ref = item . $ref . value ;
27
27
return pipe (
28
28
e . resolveRef ( { $ref } ) ,
29
29
PathItemObjectCodec . decode ,
30
30
either . mapLeft ( ( ) => new Error ( `Unable to resolve PathItem $ref: "${ $ref } "` ) ) ,
31
- either . chain ( resolved => run ( from , url , resolved ) ) ,
31
+ either . chain ( resolved => run ( from , url , kind , resolved ) ) ,
32
32
) ;
33
33
} else {
34
34
const get = pipe (
35
35
item . get ,
36
- map ( operation => serializeOperationObject ( from , url , 'GET' , operation , item ) ) ,
36
+ map ( operation => serializeOperationObject ( from , url , 'GET' , kind , operation , item ) ) ,
37
37
) ;
38
38
const put = pipe (
39
39
item . put ,
40
- map ( operation => serializeOperationObject ( from , url , 'PUT' , operation , item ) ) ,
40
+ map ( operation => serializeOperationObject ( from , url , 'PUT' , kind , operation , item ) ) ,
41
41
) ;
42
42
const post = pipe (
43
43
item . post ,
44
- map ( operation => serializeOperationObject ( from , url , 'POST' , operation , item ) ) ,
44
+ map ( operation => serializeOperationObject ( from , url , 'POST' , kind , operation , item ) ) ,
45
45
) ;
46
46
const remove = pipe (
47
47
item . delete ,
48
- map ( operation => serializeOperationObject ( from , url , 'DELETE' , operation , item ) ) ,
48
+ map ( operation => serializeOperationObject ( from , url , 'DELETE' , kind , operation , item ) ) ,
49
49
) ;
50
50
const options = pipe (
51
51
item . options ,
52
- map ( operation => serializeOperationObject ( from , url , 'OPTIONS' , operation , item ) ) ,
52
+ map ( operation => serializeOperationObject ( from , url , 'OPTIONS' , kind , operation , item ) ) ,
53
53
) ;
54
54
const head = pipe (
55
55
item . head ,
56
- map ( operation => serializeOperationObject ( from , url , 'HEAD' , operation , item ) ) ,
56
+ map ( operation => serializeOperationObject ( from , url , 'HEAD' , kind , operation , item ) ) ,
57
57
) ;
58
58
const patch = pipe (
59
59
item . patch ,
60
- map ( operation => serializeOperationObject ( from , url , 'PATCH' , operation , item ) ) ,
60
+ map ( operation => serializeOperationObject ( from , url , 'PATCH' , kind , operation , item ) ) ,
61
61
) ;
62
62
const operations = [ get , put , post , remove , options , head , patch ] ;
63
63
return pipe (
@@ -74,34 +74,72 @@ const serializePath = combineReader(ask<Context>(), serializeOperationObject, (e
74
74
export const serializePathGroup = combineReader (
75
75
serializePath ,
76
76
serializePath => ( from : Ref , name : string , group : Dictionary < PathItemObject > ) : Either < Error , File > => {
77
- const serialized = pipe (
77
+ const serializedHKT = pipe (
78
78
group ,
79
- record . collect ( ( url , item ) => serializePath ( from , url , item ) ) ,
79
+ record . collect ( ( url , item ) => serializePath ( from , url , 'HKT' , item ) ) ,
80
80
sequenceEither ,
81
81
either . map ( foldSerializedTypes ) ,
82
82
) ;
83
83
84
- return combineEither ( serialized , clientRef , ( serialized , clientRef ) => {
85
- const dependencies = serializeDependencies ( [
86
- ...serialized . dependencies ,
87
- serializedDependency ( 'asks' , 'fp-ts/lib/Reader' ) ,
88
- serializedDependency ( 'APIClient' , getRelativePath ( from , clientRef ) ) ,
89
- ] ) ;
90
- return file (
91
- `${ from . name } .ts` ,
92
- `
84
+ const serializedKind = pipe (
85
+ group ,
86
+ record . collect ( ( url , item ) => serializePath ( from , url , '*' , item ) ) ,
87
+ sequenceEither ,
88
+ either . map ( foldSerializedTypes ) ,
89
+ ) ;
90
+
91
+ const serializedKind2 = pipe (
92
+ group ,
93
+ record . collect ( ( url , item ) => serializePath ( from , url , '* -> *' , item ) ) ,
94
+ sequenceEither ,
95
+ either . map ( foldSerializedTypes ) ,
96
+ ) ;
97
+
98
+ return combineEither (
99
+ serializedHKT ,
100
+ serializedKind ,
101
+ serializedKind2 ,
102
+ clientRef ,
103
+ ( serializedHKT , serializedKind , serializedKind2 , clientRef ) => {
104
+ const dependencies = serializeDependencies ( [
105
+ ...serializedHKT . dependencies ,
106
+ ...serializedKind . dependencies ,
107
+ ...serializedKind2 . dependencies ,
108
+ serializedDependency ( 'HTTPClient' , getRelativePath ( from , clientRef ) ) ,
109
+ serializedDependency ( 'HTTPClient1' , getRelativePath ( from , clientRef ) ) ,
110
+ serializedDependency ( 'HTTPClient2' , getRelativePath ( from , clientRef ) ) ,
111
+ serializedDependency ( 'URIS' , 'fp-ts/lib/HKT' ) ,
112
+ serializedDependency ( 'URIS2' , 'fp-ts/lib/HKT' ) ,
113
+ ] ) ;
114
+ return file (
115
+ `${ from . name } .ts` ,
116
+ `
93
117
${ dependencies }
94
118
95
- export interface ${ from . name } {
96
- ${ serialized . type }
119
+ export interface ${ from . name } <F> {
120
+ ${ serializedHKT . type }
121
+ }
122
+
123
+ export interface ${ from . name } 1<F extends URIS> {
124
+ ${ serializedKind . type }
125
+ }
126
+
127
+ export interface ${ from . name } 2<F extends URIS2> {
128
+ ${ serializedKind2 . type }
97
129
}
98
130
99
- export const ${ decapitalize ( from . name ) } = asks((e: { apiClient: APIClient }): ${ from . name } => ({
100
- ${ serialized . io }
101
- }));
131
+ export function ${ decapitalize ( from . name ) } <F extends URIS2>(e: { httpClient: HTTPClient2<F> }): ${ from . name } 2<F>
132
+ export function ${ decapitalize ( from . name ) } <F extends URIS>(e: { httpClient: HTTPClient1<F> }): ${ from . name } 1<F>
133
+ export function ${ decapitalize ( from . name ) } <F>(e: { httpClient: HTTPClient<F> }): ${ from . name } <F>;
134
+ export function ${ decapitalize ( from . name ) } <F>(e: { httpClient: HTTPClient<F> }): ${ from . name } <F>; {
135
+ return {
136
+ ${ serializedHKT . io }
137
+ }
138
+ }
102
139
` ,
103
- ) ;
104
- } ) ;
140
+ ) ;
141
+ } ,
142
+ ) ;
105
143
} ,
106
144
) ;
107
145
0 commit comments