src/Document.ts   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 28
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
eloc 23
mnd 1
bc 1
fnc 0
dl 0
loc 28
ccs 0
cts 7
cp 0
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
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