-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathExpression.ts
99 lines (77 loc) · 2.2 KB
/
Expression.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { ClassType, Field, InputType, ObjectType } from "type-graphql";
import { Icon } from "../language/Icon";
import { LanguageRef } from "../language/LanguageRef";
@ObjectType()
@InputType()
export class ExpressionProof {
@Field()
signature: string;
@Field()
key: string;
@Field({nullable: true})
valid?: boolean;
@Field({nullable: true})
invalid?: boolean;
constructor(sig: string, k: string) {
this.key = k
this.signature = sig
}
}
@InputType()
export class ExpressionProofInput {
@Field()
signature: string;
@Field()
key: string;
@Field({nullable: true})
valid?: boolean;
@Field({nullable: true})
invalid?: boolean;
}
//Note having any as return type here fixes compilation errors but I think we loose the ExpressionClass type in resulting .d.ts gql files
export function ExpressionGeneric<DataType>(DataTypeClass: ClassType<DataType>): any {
@ObjectType()
abstract class ExpressionClass {
@Field()
author: string;
@Field()
timestamp: string;
@Field(type => DataTypeClass)
data: DataType;
@Field()
proof: ExpressionProof;
constructor(author: string, timestamp: string, data: DataType, proof: ExpressionProof) {
this.author = author;
this.timestamp = timestamp;
this.data = data;
this.proof = proof;
}
}
return ExpressionClass;
}
export function ExpressionGenericInput<DataType>(DataTypeClass: ClassType<DataType>): any {
@InputType()
abstract class ExpressionClass {
@Field()
author: string;
@Field()
timestamp: string;
@Field(type => DataTypeClass)
data: DataType;
@Field()
proof: ExpressionProofInput;
}
return ExpressionClass;
}
@ObjectType()
export class Expression extends ExpressionGeneric(Object) {};
@ObjectType()
export class ExpressionRendered extends ExpressionGeneric(String) {
@Field()
language: LanguageRef
@Field()
icon: Icon
};
export function isExpression(e: any): boolean {
return e && e.author && e.timestamp && e.data
}