-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
80 lines (66 loc) · 1.76 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import {Concept} from './concept'
import {NotFound, ValidationError} from './error'
import {Comparator} from './comparator';
export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
export interface ClaimsResponse {
[key: string]: boolean | ValidationError | NotFound | Error
}
export interface Qualifiers {
[key: string]: unknown
}
export enum Relationship {
GT = 'gt',
GTE = 'gt_or_eq',
LT = 'lt',
LTE = 'lt_or_eq',
EQ = 'eq',
NE = 'not_eq',
UN = 'undefined',
DE = 'defined'
}
export enum Mode {
ONE = 'one',
ANY = 'any',
ALL = 'all'
}
export type ClaimItem = {
concept: string
relationship: Relationship.GT | Relationship.GTE | Relationship.LT | Relationship.LTE | Relationship.EQ | Relationship.NE
value: string
qualifier?: Qualifiers
} | {
concept: string
relationship: Relationship.UN | Relationship.DE
qualifier?: Qualifiers
}
export interface Claim {
subject: string
mode?: Mode
claims: ClaimItem[]
}
export interface Claims {
[key: string]: Claim
}
export interface ConceptMap {
[key: string]: Concept<unknown>;
}
export interface ConceptInfo {
name: string
description: string
longDescription?: string
relationships: Relationship[]
qualifiers: string[]
}
export interface ConceptOptions<T> {
name: string
description: string
longDescription?: string
relationships: [Relationship, ...Relationship[]]
qualifiers?: string[]
getValue: GetValueFunction<T>
compare: CompareFn<T> | Comparator<T>
cast: CastFn<T>
}
export type GetValueFunction<T> = (subjectId: string, qualifiers?: Qualifiers) => Promise<T | undefined>
export type CompareFn<T> = (left: T, right: T) => number
export type CastFn<T> = (value: string) => T