| Total Complexity | 1 |
| Complexity/F | 0 |
| Lines of Code | 28 |
| Function Count | 0 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | import * as t from 'io-ts'; |
||
| 2 | import {CompoundDocument} from './CompoundDocument'; |
||
| 3 | import {DocumentC} from './io/DocumentC'; |
||
| 4 | import {RelationshipsCache} from './RelationshipsCache'; |
||
| 5 | |||
| 6 | export interface Document extends t.TypeOf<typeof DocumentC> { |
||
| 7 | } |
||
| 8 | |||
| 9 | const fromCompoundDocument = (w: CompoundDocument<unknown>): Document => { |
||
| 10 | const [data, relationships] = w(); |
||
| 11 | const cache = RelationshipsCache.fromRelationships(relationships); |
||
| 12 | const included = Object.values(RelationshipsCache.lens.global.get(cache)); |
||
| 13 | |||
| 14 | return { |
||
| 15 | data, |
||
| 16 | ...(included.length > 0 ? {included} : null) |
||
| 17 | } as Document; |
||
| 18 | }; |
||
| 19 | |||
| 20 | const fromJson = (u: unknown): Document => fromCompoundDocument( |
||
| 21 | CompoundDocument.fromJson(u, true) |
||
| 22 | ); |
||
| 23 | |||
| 24 | export const Document = { |
||
| 25 | fromCompoundDocument: fromCompoundDocument, |
||
| 26 | fromJson: fromJson |
||
| 27 | }; |
||
| 28 |