-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.ts
128 lines (104 loc) · 3.09 KB
/
service.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import {EverythingData, Group, List, Post, User, Comment} from "./everything";
export enum UserDetail {
Overview = 'overview',
Submitted = 'submitted',
Comments = 'comments',
Upvoted = 'upvoted',
Downvoted = 'downvoted',
Hidden = 'hidden',
Saved = 'saved',
Gilded = 'gilded',
}
export enum SearchType {
Group = 'sr',
Post = 'link',
User = 'user'
}
export class Unimplemented {
readonly status: number = 400
readonly message: string = 'Not Implemented'
}
export class ServiceOptions {
headers?: {}
}
export type Result<T> = T | Unimplemented;
export type GetGroupResult = Result<EverythingData<Group>>;
export type GetPostResult = Result<EverythingData<Post>>;
export type GetUserResult = Result<EverythingData<User>>;
export type GetPostsResult = Result<EverythingData<List<Post>>>;
export type GetUserDetailsResult = Result<EverythingData<List<Post | Comment>>>;
export type GetNestedCommentsResult = Result<Array<EverythingData<List>>>;
export type AutocompleteResult = Result<EverythingData<List>>;
export type SearchResult = Result<EverythingData<List>>
export type Id = string;
export type Name = string;
export type Limit = number;
export type Page = string;
export type Sort = string;
export type Depth = number;
export type Query = string;
export interface GetGroupOptions {
group: Name
}
export interface GetPostOptions {
group: Name
id: Id
}
export interface GetUserOptions {
username: Name
}
export interface GetPostsOptions {
group: Name
limit: Limit,
page?: Page,
sort?: Sort,
secondarySort?: Sort,
}
export interface GetUserDetailsOptions {
username: Name,
limit: Limit,
page?: Page,
userDetail: UserDetail
sort?: Sort,
secondarySort?: Sort,
}
export interface CommentIds {
postId: Id,
commentId?: Id
}
export interface GetNestedCommentsOptions {
group: Name
ids: CommentIds
limit: Limit,
sort?: Sort,
secondarySort?: Sort,
depth?: Depth
}
export interface AutocompleteOptions {
query: Query,
limit: Limit,
exact?: boolean
includeOver18?: boolean,
searchType: SearchType.Group | [SearchType.Group, SearchType.User]
}
export interface SearchOptions {
group?: Name,
query: Query,
limit: Limit,
page?: Page,
sort?: Sort,
secondarySort?: Sort,
searchType: SearchType | Array<SearchType>
searchInGroup?: boolean
}
export interface IService {
init(options?: ServiceOptions): IService
getGroup(getGroupOptions: GetGroupOptions): Promise<GetGroupResult>
getPost(getPostOptions: GetPostOptions): Promise<GetPostResult>
getUser(getUserOptions: GetUserOptions): Promise<GetUserResult>
getPosts(getPostsOptions: GetPostsOptions): Promise<GetPostsResult>
getUserDetails(getUserDetailsOptions: GetUserDetailsOptions): Promise<GetUserDetailsResult>
getNestedComments(getNestedCommentOptions: GetNestedCommentsOptions): Promise<GetNestedCommentsResult>
autocomplete(autocompleteOptions: AutocompleteOptions): Promise<AutocompleteResult>
search(searchOptions: SearchOptions): Promise<SearchResult>
}