@@ -19,6 +19,9 @@ import { JSONPrimitive } from '../../../../utils/io-ts';
19
19
import { pipe } from 'fp-ts/lib/pipeable' ;
20
20
import { nonEmptyArray , option } from 'fp-ts' ;
21
21
import { none , Option , some } from 'fp-ts/lib/Option' ;
22
+ import { utilsRef } from '../bundled/utils' ;
23
+ import { Either } from 'fp-ts/lib/Either' ;
24
+ import { combineEither } from '@devexperts/utils/dist/adt/either.utils' ;
22
25
23
26
export interface SerializedType {
24
27
readonly type : string ;
@@ -79,30 +82,33 @@ export const SERIALIZED_DATETIME_TYPE = serializedType(
79
82
[ serializedDependency ( 'DateFromISOString' , 'io-ts-types/lib/DateFromISOString' ) ] ,
80
83
[ ] ,
81
84
) ;
82
- export const SERIALIZED_DATE_TYPE = serializedType (
83
- 'Date' ,
84
- 'DateFromISODateStringIO' ,
85
- [ serializedDependency ( 'DateFromISODateStringIO' , '../utils/utils' ) ] ,
86
- [ ] ,
87
- ) ;
88
85
export const SERIALIZED_STRING_TYPE = serializedType ( 'string' , 'string' , [ serializedDependency ( 'string' , 'io-ts' ) ] , [ ] ) ;
89
- export const getSerializedStringType = ( format : Option < string > ) : SerializedType => {
90
- return pipe (
91
- format ,
92
- option . chain ( format => {
93
- // https://xml2rfc.tools.ietf.org/public/rfc/html/rfc3339.html#anchor14
94
- switch ( format ) {
95
- case 'date-time' : {
96
- return some ( SERIALIZED_DATETIME_TYPE ) ;
86
+ export const getSerializedStringType = ( from : Ref , format : Option < string > ) : Either < Error , SerializedType > => {
87
+ return combineEither ( utilsRef , utilsRef => {
88
+ return pipe (
89
+ format ,
90
+ option . chain ( format => {
91
+ // https://xml2rfc.tools.ietf.org/public/rfc/html/rfc3339.html#anchor14
92
+ switch ( format ) {
93
+ case 'date-time' : {
94
+ return some ( SERIALIZED_DATETIME_TYPE ) ;
95
+ }
96
+ case 'date' : {
97
+ return some (
98
+ serializedType (
99
+ 'Date' ,
100
+ 'DateFromISODateStringIO' ,
101
+ [ serializedDependency ( 'DateFromISODateStringIO' , getRelativePath ( from , utilsRef ) ) ] ,
102
+ [ ] ,
103
+ ) ,
104
+ ) ;
105
+ }
97
106
}
98
- case 'date' : {
99
- return some ( SERIALIZED_DATE_TYPE ) ;
100
- }
101
- }
102
- return none ;
103
- } ) ,
104
- option . getOrElse ( ( ) => SERIALIZED_STRING_TYPE ) ,
105
- ) ;
107
+ return none ;
108
+ } ) ,
109
+ option . getOrElse ( ( ) => SERIALIZED_STRING_TYPE ) ,
110
+ ) ;
111
+ } ) ;
106
112
} ;
107
113
export const SERIALIZED_NULL_TYPE = serializedType ( 'null' , 'nullType' , [ serializedDependency ( 'nullType' , 'io-ts' ) ] , [ ] ) ;
108
114
export const getSerializedNullableType = ( isNullable : boolean ) => ( type : SerializedType ) : SerializedType =>
0 commit comments