rettiwt-api 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/dist/{queries → graphql/queries}/RootQuery.d.ts +0 -0
  2. package/dist/{queries → graphql/queries}/RootQuery.js +4 -3
  3. package/dist/graphql/queries/RootQuery.js.map +1 -0
  4. package/dist/{resolvers → graphql/resolvers}/AccountResolver.d.ts +1 -1
  5. package/dist/{resolvers → graphql/resolvers}/AccountResolver.js +0 -0
  6. package/dist/graphql/resolvers/AccountResolver.js.map +1 -0
  7. package/dist/{resolvers → graphql/resolvers}/ResolverBase.d.ts +1 -1
  8. package/dist/{resolvers → graphql/resolvers}/ResolverBase.js +0 -0
  9. package/dist/graphql/resolvers/ResolverBase.js.map +1 -0
  10. package/dist/{resolvers → graphql/resolvers}/TweetResolver.d.ts +10 -9
  11. package/dist/{resolvers → graphql/resolvers}/TweetResolver.js +51 -35
  12. package/dist/graphql/resolvers/TweetResolver.js.map +1 -0
  13. package/dist/{resolvers → graphql/resolvers}/UserResolver.d.ts +5 -4
  14. package/dist/{resolvers → graphql/resolvers}/UserResolver.js +51 -35
  15. package/dist/graphql/resolvers/UserResolver.js.map +1 -0
  16. package/dist/{models/graphql → graphql/types}/Global.d.ts +0 -0
  17. package/dist/{models/graphql → graphql/types}/Global.js +0 -0
  18. package/dist/graphql/types/Global.js.map +1 -0
  19. package/dist/graphql/types/TweetTypes.d.ts +4 -0
  20. package/dist/{models/graphql → graphql/types}/TweetTypes.js +5 -7
  21. package/dist/graphql/types/TweetTypes.js.map +1 -0
  22. package/dist/graphql/types/UserTypes.d.ts +3 -0
  23. package/dist/{models/graphql → graphql/types}/UserTypes.js +9 -11
  24. package/dist/graphql/types/UserTypes.js.map +1 -0
  25. package/dist/index.d.ts +2 -2
  26. package/dist/index.js +2 -2
  27. package/dist/index.js.map +1 -1
  28. package/dist/server.js +3 -3
  29. package/dist/server.js.map +1 -1
  30. package/dist/services/AuthService.js +2 -2
  31. package/dist/services/AuthService.js.map +1 -1
  32. package/dist/services/CacheService.d.ts +3 -3
  33. package/dist/services/CacheService.js +22 -75
  34. package/dist/services/CacheService.js.map +1 -1
  35. package/dist/services/FetcherService.d.ts +3 -2
  36. package/dist/services/FetcherService.js +11 -29
  37. package/dist/services/FetcherService.js.map +1 -1
  38. package/dist/services/data/TweetService.d.ts +6 -6
  39. package/dist/services/data/TweetService.js +44 -27
  40. package/dist/services/data/TweetService.js.map +1 -1
  41. package/dist/services/data/UserAccountService.d.ts +3 -3
  42. package/dist/services/data/UserAccountService.js +22 -8
  43. package/dist/services/data/UserAccountService.js.map +1 -1
  44. package/dist/services/data/UserService.d.ts +42 -0
  45. package/dist/services/data/UserService.js +255 -0
  46. package/dist/services/data/UserService.js.map +1 -0
  47. package/dist/services/helper/Extractors.js +1 -1
  48. package/dist/services/helper/Extractors.js.map +1 -1
  49. package/dist/services/helper/Parser.d.ts +1 -1
  50. package/dist/services/helper/Parser.js +4 -3
  51. package/dist/services/helper/Parser.js.map +1 -1
  52. package/dist/services/helper/Urls.d.ts +2 -2
  53. package/dist/services/helper/Urls.js +19 -3
  54. package/dist/services/helper/Urls.js.map +1 -1
  55. package/dist/services/helper/deserializers/Tweets.d.ts +12 -0
  56. package/dist/services/helper/deserializers/Tweets.js +92 -0
  57. package/dist/services/helper/deserializers/Tweets.js.map +1 -0
  58. package/dist/services/{accounting/Flows.d.ts → helper/deserializers/User.d.ts} +0 -0
  59. package/dist/services/helper/deserializers/User.js +2 -0
  60. package/dist/services/helper/deserializers/User.js.map +1 -0
  61. package/dist/services/helper/deserializers/Users.d.ts +7 -0
  62. package/dist/services/helper/deserializers/Users.js +27 -0
  63. package/dist/services/helper/deserializers/Users.js.map +1 -0
  64. package/dist/services/helper/extractors/TweetExtractors.d.ts +0 -0
  65. package/dist/services/helper/extractors/TweetExtractors.js +2 -0
  66. package/dist/services/helper/extractors/TweetExtractors.js.map +1 -0
  67. package/dist/services/helper/extractors/Tweets.d.ts +32 -0
  68. package/dist/services/helper/extractors/Tweets.js +264 -0
  69. package/dist/services/helper/extractors/Tweets.js.map +1 -0
  70. package/dist/services/helper/extractors/UserExtractors.d.ts +45 -0
  71. package/dist/services/helper/extractors/UserExtractors.js +176 -0
  72. package/dist/services/helper/extractors/UserExtractors.js.map +1 -0
  73. package/dist/services/helper/extractors/Users.d.ts +20 -0
  74. package/dist/services/helper/extractors/Users.js +151 -0
  75. package/dist/services/helper/extractors/Users.js.map +1 -0
  76. package/dist/services/helper/urls/Authentication.d.ts +4 -0
  77. package/dist/services/helper/urls/Authentication.js +11 -0
  78. package/dist/services/helper/urls/Authentication.js.map +1 -0
  79. package/dist/services/helper/urls/Tweets.d.ts +32 -0
  80. package/dist/services/helper/urls/Tweets.js +51 -0
  81. package/dist/services/helper/urls/Tweets.js.map +1 -0
  82. package/dist/services/helper/urls/Urls.d.ts +4 -0
  83. package/dist/services/helper/urls/Urls.js +11 -0
  84. package/dist/services/helper/urls/Urls.js.map +1 -0
  85. package/dist/services/helper/urls/Users.d.ts +31 -0
  86. package/dist/services/helper/urls/Users.js +66 -0
  87. package/dist/services/helper/urls/Users.js.map +1 -0
  88. package/dist/types/{graphql/Errors.d.ts → Errors.d.ts} +0 -0
  89. package/dist/types/{graphql/Errors.js → Errors.js} +0 -0
  90. package/dist/types/Errors.js.map +1 -0
  91. package/dist/types/Resolvers.d.ts +9 -0
  92. package/dist/types/Resolvers.js +3 -0
  93. package/dist/types/Resolvers.js.map +1 -0
  94. package/dist/types/Tweet.d.ts +1 -0
  95. package/dist/types/Tweet.js.map +1 -1
  96. package/dist/types/User.d.ts +19 -0
  97. package/dist/types/User.js +4 -0
  98. package/dist/types/User.js.map +1 -0
  99. package/dist/types/data/Errors.d.ts +26 -0
  100. package/dist/types/data/Errors.js +36 -0
  101. package/dist/types/data/Errors.js.map +1 -0
  102. package/dist/types/data/Service.d.ts +29 -0
  103. package/dist/types/data/Service.js +19 -0
  104. package/dist/types/data/Service.js.map +1 -0
  105. package/dist/types/data/Tweet.d.ts +41 -0
  106. package/dist/types/data/Tweet.js +5 -0
  107. package/dist/types/data/Tweet.js.map +1 -0
  108. package/dist/types/data/User.d.ts +19 -0
  109. package/dist/types/data/User.js +4 -0
  110. package/dist/types/data/User.js.map +1 -0
  111. package/dist/types/raw/http/Error.d.ts +34 -0
  112. package/dist/types/raw/{user/Users.js → http/Error.js} +1 -1
  113. package/dist/types/raw/http/Error.js.map +1 -0
  114. package/dist/types/raw/http/Response.d.ts +34 -0
  115. package/dist/types/raw/http/Response.js +3 -0
  116. package/dist/types/raw/http/Response.js.map +1 -0
  117. package/package.json +1 -1
  118. package/src/{queries → graphql/queries}/RootQuery.ts +5 -4
  119. package/src/{resolvers → graphql/resolvers}/AccountResolver.ts +21 -21
  120. package/src/{resolvers → graphql/resolvers}/ResolverBase.ts +1 -1
  121. package/src/{resolvers → graphql/resolvers}/TweetResolver.ts +43 -30
  122. package/src/{resolvers → graphql/resolvers}/UserResolver.ts +41 -27
  123. package/src/{models/graphql → graphql/types}/Global.ts +0 -0
  124. package/src/{models/graphql → graphql/types}/TweetTypes.ts +9 -11
  125. package/src/{models/graphql → graphql/types}/UserTypes.ts +13 -15
  126. package/src/index.ts +2 -2
  127. package/src/server.ts +3 -3
  128. package/src/services/AuthService.ts +1 -1
  129. package/src/services/CacheService.ts +6 -8
  130. package/src/services/FetcherService.ts +11 -14
  131. package/src/services/data/TweetService.ts +53 -37
  132. package/src/services/data/UserService.ts +187 -0
  133. package/src/services/helper/Parser.ts +6 -4
  134. package/src/services/helper/{Deserializers.ts → deserializers/Tweets.ts} +3 -28
  135. package/src/services/helper/deserializers/Users.ts +26 -0
  136. package/src/services/helper/extractors/Tweets.ts +252 -0
  137. package/src/services/helper/extractors/Users.ts +137 -0
  138. package/src/services/helper/urls/Authentication.ts +6 -0
  139. package/src/services/helper/urls/Tweets.ts +46 -0
  140. package/src/services/helper/urls/Users.ts +62 -0
  141. package/src/types/Resolvers.ts +9 -0
  142. package/src/types/data/Errors.ts +28 -0
  143. package/src/types/{Service.ts → data/Service.ts} +4 -5
  144. package/src/types/{Tweet.ts → data/Tweet.ts} +1 -0
  145. package/src/types/{UserAccount.ts → data/User.ts} +0 -0
  146. package/tsconfig.json +2 -2
  147. package/dist/models/graphql/Global.js.map +0 -1
  148. package/dist/models/graphql/TweetTypes.d.ts +0 -6
  149. package/dist/models/graphql/TweetTypes.js.map +0 -1
  150. package/dist/models/graphql/UserTypes.d.ts +0 -3
  151. package/dist/models/graphql/UserTypes.js.map +0 -1
  152. package/dist/queries/RootQuery.js.map +0 -1
  153. package/dist/resolvers/AccountResolver.js.map +0 -1
  154. package/dist/resolvers/ResolverBase.js.map +0 -1
  155. package/dist/resolvers/TweetResolver.js.map +0 -1
  156. package/dist/resolvers/UserResolver.js.map +0 -1
  157. package/dist/services/AccountsService.d.ts +0 -17
  158. package/dist/services/AccountsService.js +0 -171
  159. package/dist/services/AccountsService.js.map +0 -1
  160. package/dist/services/accounting/AccountsService.d.ts +0 -20
  161. package/dist/services/accounting/AccountsService.js +0 -147
  162. package/dist/services/accounting/AccountsService.js.map +0 -1
  163. package/dist/services/accounting/Flows.js +0 -2
  164. package/dist/services/accounting/Flows.js.map +0 -1
  165. package/dist/services/accounting/LoginFlows.d.ts +0 -20
  166. package/dist/services/accounting/LoginFlows.js +0 -70
  167. package/dist/services/accounting/LoginFlows.js.map +0 -1
  168. package/dist/test/Test.js +0 -2
  169. package/dist/test/Test.js.map +0 -1
  170. package/dist/types/graphql/Errors.js.map +0 -1
  171. package/dist/types/raw/user/Users.d.ts +0 -120
  172. package/dist/types/raw/user/Users.js.map +0 -1
  173. package/src/services/data/UserAccountService.ts +0 -176
  174. package/src/services/helper/Extractors.ts +0 -455
  175. package/src/services/helper/Urls.ts +0 -109
  176. package/src/types/graphql/Errors.ts +0 -16
  177. package/src/types/raw/user/Tweets.ts +0 -2847
@@ -1,16 +1,15 @@
1
1
  // PACKAGE
2
- import { GraphQLList, GraphQLString, GraphQLObjectType, GraphQLInt, GraphQLBoolean, GraphQLUnionType } from "graphql";
2
+ import { GraphQLList, GraphQLString, GraphQLObjectType, GraphQLInt, GraphQLBoolean, GraphQLUnionType, GraphQLType } from "graphql";
3
3
 
4
4
  // TYPES
5
5
  import { User, UserList } from './UserTypes';
6
6
  import { Cursor } from './Global';
7
7
 
8
8
  // RESOLVERS
9
- import TweetResolver from '../../resolvers/TweetResolver';
10
- import UserResolver from "../../resolvers/UserResolver";
9
+ import TweetResolver from '../resolvers/TweetResolver';
10
+ import UserResolver from "../resolvers/UserResolver";
11
11
 
12
- //@ts-ignore
13
- export const TweetTokens = new GraphQLObjectType({
12
+ export const TweetTokens: GraphQLObjectType = new GraphQLObjectType({
14
13
  name: 'TweetTokens',
15
14
  description: 'Additional extracted tokens from the tweet like mentions, hashtags, etc',
16
15
  fields: () => ({
@@ -24,8 +23,7 @@ export const TweetTokens = new GraphQLObjectType({
24
23
  })
25
24
  });
26
25
 
27
- //@ts-ignore
28
- export const Tweet = new GraphQLObjectType({
26
+ export const Tweet: GraphQLObjectType = new GraphQLObjectType({
29
27
  name: 'Tweet',
30
28
  description: 'The details of single tweet',
31
29
  fields: () => ({
@@ -52,7 +50,7 @@ export const Tweet = new GraphQLObjectType({
52
50
  args: {
53
51
  count: {
54
52
  type: GraphQLInt,
55
- description: "The number of quotes to fetch",
53
+ description: "The number of quotes to fetch, must be >= 1",
56
54
  defaultValue: 10
57
55
  },
58
56
  all: {
@@ -74,7 +72,7 @@ export const Tweet = new GraphQLObjectType({
74
72
  args: {
75
73
  count: {
76
74
  type: GraphQLInt,
77
- description: "The number of likers to fetch",
75
+ description: "The number of likers to fetch, must be >= 10 (when no cursor if provided)",
78
76
  defaultValue: 10
79
77
  },
80
78
  all: {
@@ -96,7 +94,7 @@ export const Tweet = new GraphQLObjectType({
96
94
  args: {
97
95
  count: {
98
96
  type: GraphQLInt,
99
- description: "The number of retweeters to fetch",
97
+ description: "The number of retweeters to fetch, must be >= 10 (when no cursor if provided)",
100
98
  defaultValue: 10
101
99
  },
102
100
  all: {
@@ -137,7 +135,7 @@ export const Tweet = new GraphQLObjectType({
137
135
  })
138
136
  });
139
137
 
140
- export const TweetList = new GraphQLList(new GraphQLUnionType({
138
+ export const TweetList: GraphQLList<GraphQLType> = new GraphQLList(new GraphQLUnionType({
141
139
  name: 'TweetCursorUnion',
142
140
  description: 'A union type which can either be a Tweet or a Cursor, used in cursored tweet lists',
143
141
  types: [Tweet, Cursor],
@@ -1,17 +1,16 @@
1
1
  // PACKAGE
2
- import { GraphQLBoolean, GraphQLObjectType, GraphQLString, GraphQLInt, GraphQLList, GraphQLUnionType } from 'graphql';
2
+ import { GraphQLBoolean, GraphQLObjectType, GraphQLString, GraphQLInt, GraphQLList, GraphQLUnionType, GraphQLType } from 'graphql';
3
3
 
4
4
  // TYPES
5
5
  import { Tweet, TweetList } from './TweetTypes'
6
6
  import { Cursor } from './Global';
7
- import { TweetFilter } from '../../types/Tweet';
7
+ import { TweetFilter } from '../../types/data/Tweet';
8
8
 
9
9
  // RESOLVERS
10
- import UserResolver from '../../resolvers/UserResolver';
11
- import TweetResolver from '../../resolvers/TweetResolver';
10
+ import UserResolver from '../resolvers/UserResolver';
11
+ import TweetResolver from '../resolvers/TweetResolver';
12
12
 
13
- //@ts-ignore
14
- export const User = new GraphQLObjectType({
13
+ export const User: GraphQLObjectType = new GraphQLObjectType({
15
14
  name: 'User',
16
15
  description: 'The details of a single target twitter user',
17
16
  fields: () => ({
@@ -33,7 +32,7 @@ export const User = new GraphQLObjectType({
33
32
  type: TweetList,
34
33
  args: {
35
34
  count: {
36
- description: "The number of liked tweets to fetch",
35
+ description: "The number of liked tweets to fetch, must be >= 40 (when no cursor if provided)",
37
36
  type: GraphQLInt,
38
37
  defaultValue: 10
39
38
  },
@@ -55,9 +54,9 @@ export const User = new GraphQLObjectType({
55
54
  type: UserList,
56
55
  args: {
57
56
  count: {
58
- description: "The number of followers to fetch",
57
+ description: "The number of followers to fetch, must be >= 40 (when no cursor is provided)",
59
58
  type: GraphQLInt,
60
- defaultValue: 20
59
+ defaultValue: 40
61
60
  },
62
61
  all: {
63
62
  description: "Whether to fetch all followers list",
@@ -78,8 +77,8 @@ export const User = new GraphQLObjectType({
78
77
  args: {
79
78
  count: {
80
79
  type: GraphQLInt,
81
- description: "The number of followings to fetch",
82
- defaultValue: 20
80
+ description: "The number of followings to fetch, must be >= 40 (when no cursor is provided)",
81
+ defaultValue: 40
83
82
  },
84
83
  all: {
85
84
  description: "Whether to fetch all followings list",
@@ -99,7 +98,7 @@ export const User = new GraphQLObjectType({
99
98
  type: TweetList,
100
99
  args: {
101
100
  count: {
102
- description: "The number of tweets to fetch",
101
+ description: "The number of tweets to fetch, must be >= 1",
103
102
  type: GraphQLInt,
104
103
  defaultValue: 10
105
104
  },
@@ -114,13 +113,12 @@ export const User = new GraphQLObjectType({
114
113
  defaultValue: ''
115
114
  }
116
115
  },
117
- resolve: (parent, args, context) => new TweetResolver(context).resolveTweets({ fromUsers: [parent.userName] } as TweetFilter, args.count, args.cursor)
116
+ resolve: (parent, args, context) => new TweetResolver(context).resolveTweets({ fromUsers: [parent.userName] } as TweetFilter, args.all ? parent.statusesCount : args.count, args.cursor)
118
117
  }
119
118
  })
120
119
  });
121
120
 
122
- //@ts-ignore
123
- export const UserList = new GraphQLList(new GraphQLUnionType({
121
+ export const UserList: GraphQLList<GraphQLType> = new GraphQLList(new GraphQLUnionType({
124
122
  name: 'UserCursorUnion',
125
123
  description: 'A union type which can either be a User or a Cursor, used in cursored User lists',
126
124
  types: [User, Cursor],
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // SERVICES
2
2
  import { AuthService } from "./services/AuthService";
3
- import { UserAccountService } from "./services/data/UserAccountService";
3
+ import { UserService } from "./services/data/UserService";
4
4
  import { TweetService } from "./services/data/TweetService";
5
5
  import { AccountService } from "./services/accounts/AccountService";
6
6
 
@@ -14,7 +14,7 @@ export const Rettiwt = (cookie: string = '') => {
14
14
 
15
15
  // Using the auth service instance to create data services instances
16
16
  return {
17
- users: new UserAccountService(auth),
17
+ users: new UserService(auth),
18
18
  tweets: new TweetService(auth),
19
19
  account: new AccountService()
20
20
  };
package/src/server.ts CHANGED
@@ -4,13 +4,13 @@ import { graphqlHTTP } from 'express-graphql';
4
4
  import { GraphQLSchema } from 'graphql';
5
5
 
6
6
  // Services
7
- import { UserAccountService } from './services/data/UserAccountService';
7
+ import { UserService } from './services/data/UserService';
8
8
  import { TweetService } from './services/data/TweetService';
9
9
  import { AccountService } from './services/accounts/AccountService';
10
10
  import { AuthService } from './services/AuthService';
11
11
 
12
12
  // SCHEMA
13
- import { rootQuery } from './queries/RootQuery';
13
+ import { rootQuery } from './graphql/queries/RootQuery';
14
14
 
15
15
  // CONFIGS
16
16
  import { config } from './config/env';
@@ -24,7 +24,7 @@ app.use('/graphql', graphqlHTTP(req => ({
24
24
  query: rootQuery
25
25
  }),
26
26
  context: {
27
- users: new UserAccountService(new AuthService(req.headers.cookie as string)),
27
+ users: new UserService(new AuthService(req.headers.cookie as string)),
28
28
  tweets: new TweetService(new AuthService(req.headers.cookie as string)),
29
29
  account: new AccountService()
30
30
  },
@@ -2,7 +2,7 @@
2
2
  import axios from 'axios';
3
3
 
4
4
  // URLS
5
- import { guestTokenUrl } from './helper/Urls';
5
+ import { guestTokenUrl } from './helper/urls/Authentication';
6
6
 
7
7
  // TYPES
8
8
  import { GuestCredentials, AuthCredentials } from '../types/Authentication';
@@ -23,16 +23,14 @@ export class CacheService {
23
23
  /**
24
24
  * @returns The current working instance of CacheService
25
25
  */
26
- static async getInstance(): Promise<CacheService> {
26
+ static getInstance(): CacheService {
27
27
  // If an instance doesnt exists already
28
28
  if (!this.instance) {
29
29
  this.instance = new CacheService();
30
- return this.instance;
31
- }
32
- // If an instance already exists, returning it
33
- else {
34
- return this.instance;
35
30
  }
31
+
32
+ // Returning the current instance
33
+ return this.instance;
36
34
  }
37
35
 
38
36
  /**
@@ -40,7 +38,7 @@ export class CacheService {
40
38
  * @returns Whether writing to cache was successful or not
41
39
  * @param data The input data to store
42
40
  */
43
- async write(data: any): Promise<void> {
41
+ public write(data: any): void {
44
42
  // Converting the data to a list of data
45
43
  data = Parsers.dataToList(data);
46
44
 
@@ -61,7 +59,7 @@ export class CacheService {
61
59
  * @returns The data with the given id/rest id from cache
62
60
  * @param id The id/rest id of the data to be fetched from cache
63
61
  */
64
- async read(id: string): Promise<any> {
62
+ public read(id: string): any {
65
63
  // Getting data from cache
66
64
  let res = this.client.get(id);
67
65
 
@@ -12,7 +12,8 @@ import { Result as RawTweet } from '../types/raw/tweet/Tweet';
12
12
 
13
13
  // HELPERS
14
14
  import * as Headers from './helper/Headers'
15
- import * as Deserializers from './helper/Deserializers';
15
+ import * as UserDeserializers from './helper/deserializers/Users';
16
+ import * as TweetDeserializers from './helper/deserializers/Tweets';
16
17
  import { CurlyOptions } from 'node-libcurl/dist/curly';
17
18
 
18
19
  /**
@@ -29,11 +30,13 @@ export enum HttpMethods {
29
30
  export class FetcherService {
30
31
  // MEMBER DATA
31
32
  private auth: AuthService; // To store the auth service instance to use for authentication
33
+ private cache: CacheService; // To stoer the cache service instance to use for caching data
32
34
  protected isAuthenticated: boolean; // To store whether user is authenticated or not
33
35
 
34
36
  // MEMBER METHODS
35
37
  constructor(auth: AuthService) {
36
38
  this.auth = auth;
39
+ this.cache = CacheService.getInstance();
37
40
  this.isAuthenticated = this.auth.isAuthenticated;
38
41
  }
39
42
 
@@ -77,28 +80,22 @@ export class FetcherService {
77
80
  * @summary Caches the extracted data
78
81
  * @param data The extracted data to be cached
79
82
  */
80
- protected async cacheData(data: any): Promise<void> {
81
- // Creating an instance of cache
82
- let cache = await CacheService.getInstance();
83
-
83
+ protected cacheData(data: any): void {
84
84
  // Parsing the extracted data
85
- let users = data.users.map((user: RawUser) => Deserializers.toUser(user));
86
- let tweets = data.tweets.map((tweet: RawTweet) => Deserializers.toTweet(tweet));
85
+ let users = data.users.map((user: RawUser) => UserDeserializers.toUser(user));
86
+ let tweets = data.tweets.map((tweet: RawTweet) => TweetDeserializers.toTweet(tweet));
87
87
 
88
88
  // Caching the data
89
- cache.write(users);
90
- cache.write(tweets);
89
+ this.cache.write(users);
90
+ this.cache.write(tweets);
91
91
  }
92
92
 
93
93
  /**
94
94
  * @returns The data with the given id (if it exists in cache)
95
95
  * @param id The id of the data to be read from cache
96
96
  */
97
- protected async readData(id: string): Promise<any> {
98
- // Creating an instance of cache
99
- let cache = await CacheService.getInstance();
100
-
97
+ protected readData(id: string): any {
101
98
  // Reading data from cache
102
- return cache.read(id);
99
+ return this.cache.read(id);
103
100
  }
104
101
  }
@@ -3,22 +3,25 @@ import { FetcherService } from "../FetcherService";
3
3
  import { AuthService } from "../AuthService";
4
4
 
5
5
  // TYPES
6
- import { TweetFilter, Tweet } from "../../types/Tweet";
7
- import { User } from "../../types/UserAccount";
8
- import { CursoredData } from '../../types/Service';
9
- import RawTweet from '../../types/raw/tweet/Tweet';
6
+ import { TweetFilter, Tweet } from "../../types/data/Tweet";
7
+ import { User } from "../../types/data/User";
8
+ import { CursoredData } from '../../types/data/Service';
9
+ import RawTweet, { Result as TweetData } from '../../types/raw/tweet/Tweet';
10
+ import { Result as UserData } from "../../types/raw/user/User";
10
11
  import RawTweets from '../../types/raw/tweet/Tweets';
11
12
  import RawLikers from '../../types/raw/tweet/Favouriters';
12
13
  import RawRetweeters from '../../types/raw/tweet/Retweeters';
14
+ import * as Errors from '../../types/data/Errors';
13
15
 
14
16
  // URLS
15
- import * as Urls from '../helper/Urls';
17
+ import * as TweetUrls from '../helper/urls/Tweets';
16
18
 
17
19
  // EXTRACTORS
18
- import * as Extractors from "../helper/Extractors";
20
+ import * as TweetExtractors from "../helper/extractors/Tweets";
19
21
 
20
22
  // DESERIALIZERS
21
- import * as Deserializers from '../helper/Deserializers';
23
+ import * as UserDeserializers from '../helper/deserializers/Users';
24
+ import * as TweetDeserializers from '../helper/deserializers/Tweets';
22
25
 
23
26
  // PARSERS
24
27
  import { toQueryString } from '../helper/Parser';
@@ -35,21 +38,26 @@ export class TweetService extends FetcherService {
35
38
  /**
36
39
  * @returns The list of tweets that match the given filter
37
40
  * @param filter The filter be used for searching the tweets
38
- * @param count The number of tweets to fetch
41
+ * @param count The number of tweets to fetch, must be >= 1 and <= 100
39
42
  * @param cursor The cursor to the next batch of tweets. If blank, first batch is fetched
40
43
  */
41
44
  async getTweets(filter: TweetFilter, count: number, cursor: string): Promise<CursoredData<Tweet>> {
45
+ // If invalid count provided
46
+ if (count < 1 && !cursor) {
47
+ throw new Error(Errors.ValidationErrors.InvalidCount);
48
+ }
49
+
42
50
  // Getting the raw data
43
- let res = await this.request<RawTweets>(Urls.tweetsUrl(toQueryString(filter), count, cursor), false).then(res => res.data);
51
+ let res = await this.request<RawTweets>(TweetUrls.tweetsUrl(toQueryString(filter), count, cursor), false).then(res => res.data);
44
52
 
45
53
  // Extracting data
46
- let data = Extractors.extractTweets(res);
54
+ let data = TweetExtractors.extractTweets(res);
47
55
 
48
56
  // Caching data
49
57
  this.cacheData(data);
50
58
 
51
59
  // Parsing data
52
- let tweets = data.required.map(item => Deserializers.toTweet(item));
60
+ let tweets = data.required.map((item: TweetData) => TweetDeserializers.toTweet(item));
53
61
 
54
62
  return {
55
63
  list: tweets,
@@ -69,47 +77,50 @@ export class TweetService extends FetcherService {
69
77
  if (cachedData) {
70
78
  return cachedData;
71
79
  }
72
- // If data does not exist in cache
73
- else {
74
- // Fetching the raw data
75
- let res = await this.request<RawTweet>(Urls.tweetDetailsUrl(tweetId), false).then(res => res.data);
80
+
81
+ // Fetching the raw data
82
+ let res = await this.request<RawTweet>(TweetUrls.tweetDetailsUrl(tweetId), false).then(res => res.data);
76
83
 
77
- // Extracting data
78
- let data = Extractors.extractTweet(res, tweetId);
84
+ // Extracting data
85
+ let data = TweetExtractors.extractTweet(res, tweetId);
79
86
 
80
- // Caching data
81
- this.cacheData(data);
87
+ // Caching data
88
+ this.cacheData(data);
82
89
 
83
- // Parsing data
84
- let tweet = Deserializers.toTweet(data.required[0]);
90
+ // Parsing data
91
+ let tweet = TweetDeserializers.toTweet(data.required[0]);
85
92
 
86
- return tweet;
87
- }
93
+ return tweet;
88
94
  }
89
95
 
90
96
  /**
91
97
  * @returns The list of users who liked the given tweet
92
98
  * @param tweetId The rest id of the target tweet
93
- * @param count The batch size of the list
99
+ * @param count The batch size of the list, must be >= 10 (when no cursor is provided) and <= 100
94
100
  * @param cursor The cursor to the next batch of users. If blank, first batch is fetched
95
101
  */
96
102
  async getTweetLikers(tweetId: string, count: number, cursor: string): Promise<CursoredData<User>> {
97
103
  // If user is not authenticated, abort
98
104
  if(!this.isAuthenticated) {
99
- return { error: new Error('Cannot fetch tweet likes without authentication!') };
105
+ throw new Error(Errors.AuthenticationErrors.NotAuthenticated);
106
+ }
107
+
108
+ // If invalid count provided
109
+ if (count < 10 && !cursor) {
110
+ throw new Error(Errors.ValidationErrors.InvalidCount);
100
111
  }
101
112
 
102
113
  // Fetching the raw data
103
- let res = await this.request<RawLikers>(Urls.tweetLikesUrl(tweetId, count, cursor)).then(res => res.data);
114
+ let res = await this.request<RawLikers>(TweetUrls.tweetLikesUrl(tweetId, count, cursor)).then(res => res.data);
104
115
 
105
116
  // Extracting data
106
- let data = Extractors.extractTweetLikers(res);
117
+ let data = TweetExtractors.extractTweetLikers(res);
107
118
 
108
119
  // Caching data
109
120
  this.cacheData(data);
110
121
 
111
122
  // Parsing data
112
- let users = data.required.map(item => Deserializers.toUser(item));
123
+ let users = data.required.map((item: UserData) => UserDeserializers.toUser(item));
113
124
 
114
125
  return {
115
126
  list: users,
@@ -120,26 +131,31 @@ export class TweetService extends FetcherService {
120
131
  /**
121
132
  * @returns The list of users who retweeted the given tweet
122
133
  * @param tweetId The rest id of the target tweet
123
- * @param count The batch size of the list
134
+ * @param count The batch size of the list, must be >= 10 (when no cursor is provided) and <= 100
124
135
  * @param cursor The cursor to the next batch of users. If blank, first batch is fetched
125
136
  */
126
137
  async getTweetRetweeters(tweetId: string, count: number, cursor: string): Promise<CursoredData<User>> {
127
138
  // If user is not authenticated, abort
128
139
  if(!this.isAuthenticated) {
129
- return { error: new Error('Cannot fetch tweet retweeters without authentication!') };
140
+ throw new Error(Errors.AuthenticationErrors.NotAuthenticated);
141
+ }
142
+
143
+ // If invalid count provided
144
+ if (count < 10 && !cursor) {
145
+ throw new Error(Errors.ValidationErrors.InvalidCount);
130
146
  }
131
147
 
132
148
  // Fetching the raw data
133
- let res = await this.request<RawRetweeters>(Urls.tweetRetweetUrl(tweetId, count, cursor)).then(res => res.data);
149
+ let res = await this.request<RawRetweeters>(TweetUrls.tweetRetweetUrl(tweetId, count, cursor)).then(res => res.data);
134
150
 
135
151
  // Extracting data
136
- let data = Extractors.extractTweetRetweeters(res);
152
+ let data = TweetExtractors.extractTweetRetweeters(res);
137
153
 
138
154
  // Caching data
139
155
  this.cacheData(data);
140
156
 
141
157
  // Parsing data
142
- let users = data.required.map(item => Deserializers.toUser(item));
158
+ let users = data.required.map((item: UserData) => UserDeserializers.toUser(item));
143
159
 
144
160
  return {
145
161
  list: users,
@@ -155,20 +171,20 @@ export class TweetService extends FetcherService {
155
171
  async getTweetReplies(tweetId: string, cursor: string): Promise<CursoredData<Tweet>> {
156
172
  // If user is not authenticated, abort
157
173
  if(!this.isAuthenticated) {
158
- return { error: new Error('Cannot fetch tweet replies without authentication!') };
174
+ throw new Error(Errors.AuthenticationErrors.NotAuthenticated);
159
175
  }
160
176
 
161
177
  // Fetching the raw data
162
- let res = await this.request<RawTweet>(Urls.tweetRepliesUrl(tweetId, cursor)).then(res => res.data);
178
+ let res = await this.request<RawTweet>(TweetUrls.tweetRepliesUrl(tweetId, cursor)).then(res => res.data);
163
179
 
164
180
  // Extracting data
165
- let data = Extractors.extractTweetReplies(res, tweetId);
181
+ let data = TweetExtractors.extractTweetReplies(res, tweetId);
166
182
 
167
183
  // Caching data
168
184
  this.cacheData(data);
169
185
 
170
186
  // Parsing data
171
- let tweets = data.required.map(item => Deserializers.toTweet(item));
187
+ let tweets = data.required.map((item: TweetData) => TweetDeserializers.toTweet(item));
172
188
 
173
189
  return {
174
190
  list: tweets,