File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { Model } from '../client/interfaces/Model.d' ;
2
+
3
+ const formatDate = [ 'date-time' ] ;
4
+ export type RequiredFields < T > = Pick < Model , 'export' | 'format' | 'base' > & { properties : RequiredFields < T > [ ] ; link : RequiredFields < T > | null } & T ;
5
+ /**
6
+ * Change Model.base if it is a string and has the format 'date-time'
7
+ * @param models Array of Models
8
+ */
9
+ export function dateTypeOverride < T > ( models : RequiredFields < T > [ ] ) : RequiredFields < T > [ ] {
10
+ return models . map ( model => {
11
+ if ( model . export === 'interface' ) {
12
+ return { ...model , properties : dateTypeOverride ( model . properties ) } ;
13
+ }
14
+
15
+ if ( model . export === 'array' ) {
16
+ if ( model . link !== null ) {
17
+ const link = cloneObject ( model . link ) ;
18
+ link . properties = dateTypeOverride ( link . properties ) ;
19
+ return { ...model , link } ;
20
+ }
21
+ return { ...model } ;
22
+ }
23
+
24
+ if ( model . base !== 'string' || model . format === undefined ) {
25
+ return { ...model } ;
26
+ }
27
+
28
+ let base = model . base ;
29
+ if ( formatDate . includes ( model . format ) ) {
30
+ base = 'Date' ;
31
+ }
32
+
33
+ return { ...model , base } ;
34
+ } ) ;
35
+ }
36
+
37
+ function cloneObject < T > ( object : T ) : T {
38
+ return { ...object } ;
39
+ }
You can’t perform that action at this time.
0 commit comments