- Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathtypings.ts
100 lines (90 loc) · 2.99 KB
/
typings.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
100
exportnamespaceCreate{
exportinterfaceSketch{
readonlyname: string;
readonlypath: string;
readonlymodified_at: string;
readonlycreated_at: string;
readonlysecrets?: {name: string;value: string}[];
readonlyid: string;
readonlyis_public: boolean;
readonlyboard_fqbn: '';
readonlyboard_name: '';
readonlyboard_type: 'serial'|'network'|'cloud'|'';
readonlyhref?: string;
readonlylibraries: string[];
readonlytutorials: string[]|null;
readonlytypes: string[]|null;
readonlyuser_id: string;
}
exporttypeResourceType='sketch'|'folder'|'file';
exportconstarduino_secrets_file='arduino_secrets.h';
exportconstdo_not_sync_files=['.theia','sketch.json'];
exportinterfaceResource{
readonlyname: string;
/**
* Note: this path is **not** the POSIX path we use. It has the leading segments with the `user_id`.
*/
readonlypath: string;
readonlytype: ResourceType;
readonlysketchId?: string;
readonlymodified_at: string;// As an ISO-8601 formatted string: `YYYY-MM-DDTHH:mm:ss.sssZ`
readonlycreated_at: string;// As an ISO-8601 formatted string: `YYYY-MM-DDTHH:mm:ss.sssZ`
readonlychildren?: number;// For 'sketch' and 'folder' types.
readonlysize?: number;// For 'sketch' type only.
readonlyisPublic?: boolean;// For 'sketch' type only.
readonlymimetype?: string;// For 'file' type.
readonlyhref?: string;
}
exportnamespaceResource{
exportfunctionis(arg: any): arg is Resource{
return(
!!arg&&
'name'inarg&&
typeofarg['name']==='string'&&
'path'inarg&&
typeofarg['path']==='string'&&
'type'inarg&&
typeofarg['type']==='string'&&
'modified_at'inarg&&
typeofarg['modified_at']==='string'&&
(arg['type']==='sketch'||
arg['type']==='folder'||
arg['type']==='file')
);
}
}
exporttypeRawResource=Omit<Resource,'sketchId'|'isPublic'>;
}
exportclassCreateErrorextendsError{
constructor(
message: string,
readonlystatus: number,
readonlydetails?: string
){
super(message);
Object.setPrototypeOf(this,CreateError.prototype);
}
}
exporttypeConflictError=CreateError&{status: 409};
exportfunctionisConflict(err: unknown): err is ConflictError{
returnisErrorWithStatusOf(err,409);
}
exporttypeNotFoundError=CreateError&{status: 404};
exportfunctionisNotFound(err: unknown): err is NotFoundError{
returnisErrorWithStatusOf(err,404);
}
exporttypeUnprocessableContentError=CreateError&{status: 422};
exportfunctionisUnprocessableContent(
err: unknown
): err is UnprocessableContentError{
returnisErrorWithStatusOf(err,422);
}
functionisErrorWithStatusOf(
err: unknown,
status: number
): err is CreateError&{status: number}{
if(errinstanceofCreateError){
returnerr.status===status;
}
returnfalse;
}