| Total Complexity | 2 |
| Complexity/F | 0 |
| Lines of Code | 56 |
| 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 {CompoundDocument} from '../src/CompoundDocument'; |
||
| 7 | import {Document} from '../src/Document'; |
||
| 8 | import {ArrayC} from '../src/io/ArrayC'; |
||
| 9 | import {Json} from '../src/Json'; |
||
| 10 | import {RelationshipsCache} from '../src/RelationshipsCache'; |
||
| 11 | |||
| 12 | const TE = pipeable(taskEither); |
||
| 13 | const E = pipeable(either); |
||
| 14 | |||
| 15 | pipe( |
||
| 16 | Json.fromFile(process.argv[2]), |
||
| 17 | TE.map( |
||
| 18 | u => { |
||
| 19 | const count = null === u || undefined === u |
||
| 20 | ? 0 |
||
| 21 | : ArrayC().is(u) |
||
| 22 | ? u.length |
||
| 23 | : 1; |
||
| 24 | console.log(`>¦ Encoding ${count} item(s)`); |
||
| 25 | |||
| 26 | return u; |
||
| 27 | } |
||
| 28 | ), |
||
| 29 | TE.map(u => CompoundDocument.fromJson(u, true)), |
||
| 30 | TE.map( |
||
| 31 | w => { |
||
| 32 | const [data, relationships] = w(); |
||
| 33 | const cache = RelationshipsCache.fromRelationships(relationships); |
||
| 34 | const counter = RelationshipsCache.lens.counter.get(cache); |
||
| 35 | const included = Object.keys(RelationshipsCache.lens.global.get(cache)).length; |
||
| 36 | console.log(` ¦> ${included} resource(s) found among ${counter} relationship(s)`); |
||
| 37 | |||
| 38 | return w; |
||
| 39 | } |
||
| 40 | ), |
||
| 41 | TE.map(Document.fromCompoundDocument) |
||
| 42 | )() |
||
| 43 | .then( |
||
| 44 | either => pipe( |
||
| 45 | either, |
||
| 46 | E.map(JSON.stringify), |
||
| 47 | fold( |
||
| 48 | error => { |
||
| 49 | throw error; |
||
| 50 | }, |
||
| 51 | data => console.log(data) |
||
| 52 | ) |
||
| 53 | ) |
||
| 54 | ) |
||
| 55 | .catch(error => console.error(error)); |
||
| 56 |