| Total Complexity | 3 |
| Complexity/F | 0 |
| Lines of Code | 49 |
| Function Count | 0 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | #!/usr/bin/env node |
||
| 2 | |||
| 3 | import {either, fold} from 'fp-ts/lib/Either'; |
||
| 4 | import {pipe, pipeable} from 'fp-ts/lib/pipeable'; |
||
| 5 | import {taskEither} from 'fp-ts/lib/TaskEither'; |
||
| 6 | import {decode} from '../src'; |
||
| 7 | import {ArrayC} from '../src/io/ArrayC'; |
||
| 8 | import {DocumentC} from '../src/io/DocumentC'; |
||
| 9 | import {Json} from '../src/Json'; |
||
| 10 | |||
| 11 | const TE = pipeable(taskEither); |
||
| 12 | const E = pipeable(either); |
||
| 13 | |||
| 14 | pipe( |
||
| 15 | Json.fromFile(process.argv[2]), |
||
| 16 | TE.map( |
||
| 17 | u => { |
||
| 18 | if (!DocumentC.is(u)) { |
||
| 19 | console.warn('Cannot find a JSON:API document'); |
||
| 20 | |||
| 21 | return u; |
||
| 22 | } |
||
| 23 | |||
| 24 | const count = null === u.data || undefined === u.data |
||
| 25 | ? 0 |
||
| 26 | : ArrayC().is(u.data) |
||
| 27 | ? u.data.length |
||
| 28 | : 1; |
||
| 29 | console.log(`>¦ Decoding ${count} item(s) with ${(u.included || []).length} relationship(s)`); |
||
| 30 | |||
| 31 | return u; |
||
| 32 | } |
||
| 33 | ), |
||
| 34 | TE.map(decode) |
||
| 35 | )() |
||
| 36 | .then( |
||
| 37 | either => pipe( |
||
| 38 | either, |
||
| 39 | E.map(JSON.stringify), |
||
| 40 | fold( |
||
| 41 | error => { |
||
| 42 | throw error; |
||
| 43 | }, |
||
| 44 | data => console.log(data) |
||
| 45 | ) |
||
| 46 | ) |
||
| 47 | ) |
||
| 48 | .catch(error => console.error(error)); |
||
| 49 | |||
| 50 |