Skip to content

Commit 6c26cb0

Browse files
committed
feat(cache): disable caching for DELETE, POST, PUT and auth endpoints
1 parent 3885f01 commit 6c26cb0

15 files changed

+280
-129
lines changed

src/models/trakt/trakt-client.model.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ export type PartialTraktApiParams<
200200
(P extends false ? Record<string, never> : TraktApiParamsPagination);
201201

202202
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- this is a recursive type
203-
export type ITraktApi<T extends TraktApiParams = any> = {
204-
[key: string]: TraktClientEndpoint<T> | ITraktApi<T>;
203+
export type ITraktApi<Parameter extends TraktApiParams = any, Response = unknown, Cache extends boolean = boolean> = {
204+
[key: string]: TraktClientEndpoint<Parameter, Response, Cache> | ITraktApi<Parameter>;
205205
};
206206

207207
export const TraktApiHeaders = {

src/models/tvdb/tvdb-client.model.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,6 @@ export class TvdbClientEndpoint<
8585
> extends ClientEndpoint<Parameter, Response, Cache, TvdbApiTemplateOptions> {}
8686

8787
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- this is a recursive type
88-
export type ITvdbApi<T extends TvdbApiParam = any> = {
89-
[key: string]: TvdbClientEndpoint<T> | ITvdbApi<T>;
88+
export type ITvdbApi<Parameter extends TvdbApiParam = any, Response = unknown, Cache extends boolean = boolean> = {
89+
[key: string]: TvdbClientEndpoint<Parameter, Response, Cache> | ITvdbApi<Parameter>;
9090
};

src/services/common/base-client.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ export class ClientEndpoint<
116116
}
117117
}
118118

119-
export type IApi<T extends RecursiveRecord = RecursiveRecord> = {
120-
[key: string]: ClientEndpoint<T> | IApi<T>;
119+
export type IApi<Parameter extends RecursiveRecord = RecursiveRecord, Response = unknown, Cache extends boolean = boolean> = {
120+
[key: string]: ClientEndpoint<Parameter, Response, Cache> | IApi<Parameter>;
121121
};
122122

123123
/**
@@ -221,8 +221,7 @@ export abstract class BaseClient<
221221
*
222222
* @example client.endpoints({ request })
223223
*/
224-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- generic typing
225-
protected bindToEndpoint(api: IApi<any>) {
224+
protected bindToEndpoint(api: IApi) {
226225
const client = { ...api };
227226
Object.entries(client).forEach(([endpoint, template]) => {
228227
if (isApiTemplate(template) && isApiTemplate(client[endpoint])) {

src/services/trakt-client/api/endpoints/authentication.endpoint.ts

+24-6
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ export const authentication = {
3838
*
3939
* @see [authorize]{@link https://trakt.docs.apiary.io/#reference/authentication-oauth/authorize}
4040
*/
41-
authorize: new TraktClientEndpoint<TraktAuthenticationAuthorizeRequest>({
41+
authorize: new TraktClientEndpoint<TraktAuthenticationAuthorizeRequest, unknown, false>({
4242
method: HttpMethod.GET,
4343
url: '/oauth/authorize?response_type=code&client_id=&redirect_uri=&state=',
4444
init: {
4545
redirect: 'manual',
4646
credentials: 'omit',
4747
},
4848
opts: {
49+
cache: false,
4950
parameters: {
5051
query: {
5152
response_type: true,
@@ -71,9 +72,12 @@ export const authentication = {
7172
*
7273
* @see [exchange-code-for-access_token]{@link https://trakt.docs.apiary.io/reference/authentication-oauth/get-token/exchange-code-for-access_token}
7374
*/
74-
code: new TraktClientEndpoint<TraktAuthenticationCodeRequest, TraktAuthentication>({
75+
code: new TraktClientEndpoint<TraktAuthenticationCodeRequest, TraktAuthentication, false>({
7576
method: HttpMethod.POST,
7677
url: '/oauth/token',
78+
opts: {
79+
cache: false,
80+
},
7781
body: {
7882
code: true,
7983
client_id: true,
@@ -91,9 +95,12 @@ export const authentication = {
9195
*
9296
* @see [exchange-refresh_token-for-access_token]{@link https://trakt.docs.apiary.io/#reference/authentication-oauth/get-token/exchange-refresh_token-for-access_token}
9397
*/
94-
refresh: new TraktClientEndpoint<TraktAuthenticationRefreshRequest, TraktAuthentication>({
98+
refresh: new TraktClientEndpoint<TraktAuthenticationRefreshRequest, TraktAuthentication, false>({
9599
method: HttpMethod.POST,
96100
url: '/oauth/token',
101+
opts: {
102+
cache: false,
103+
},
97104
body: {
98105
refresh_token: true,
99106
client_id: true,
@@ -109,9 +116,12 @@ export const authentication = {
109116
*
110117
* @see [revoke-token]{@link https://trakt.docs.apiary.io/#reference/authentication-oauth/revoke-token}
111118
*/
112-
revoke: new TraktClientEndpoint<TraktAuthenticationRevokeRequest>({
119+
revoke: new TraktClientEndpoint<TraktAuthenticationRevokeRequest, unknown, false>({
113120
method: HttpMethod.POST,
114121
url: '/oauth/revoke',
122+
opts: {
123+
cache: false,
124+
},
115125
body: {
116126
token: true,
117127
client_id: true,
@@ -158,10 +168,14 @@ export const authentication = {
158168
/** Get this from your app settings. */
159169
client_id: string;
160170
},
161-
TraktDeviceAuthentication
171+
TraktDeviceAuthentication,
172+
false
162173
>({
163174
method: HttpMethod.POST,
164175
url: '/oauth/device/code',
176+
opts: {
177+
cache: false,
178+
},
165179
body: {
166180
client_id: true,
167181
},
@@ -197,10 +211,14 @@ export const authentication = {
197211
/** Get this from your app settings. */
198212
client_secret: string;
199213
},
200-
TraktAuthentication
214+
TraktAuthentication,
215+
false
201216
>({
202217
method: HttpMethod.POST,
203218
url: '/oauth/device/token',
219+
opts: {
220+
cache: false,
221+
},
204222
body: {
205223
code: true,
206224
client_id: true,

src/services/trakt-client/api/endpoints/checkin.endpoint.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ export const checkin = {
2525
*
2626
* @see [check-into-an-item]{@link https://trakt.docs.apiary.io/#reference/checkin/checkin/check-into-an-item}
2727
*/
28-
add: new TraktClientEndpoint<TraktCheckinRequest, TraktCheckin>({
28+
add: new TraktClientEndpoint<TraktCheckinRequest, TraktCheckin, false>({
2929
method: HttpMethod.POST,
3030
url: '/checkin',
3131
opts: {
3232
auth: true,
33+
cache: false,
3334
},
3435
body: {
3536
sharing: false,
@@ -45,11 +46,12 @@ export const checkin = {
4546
*
4647
* @see [delete-any-active-checkins]{@link https://trakt.docs.apiary.io/#reference/checkin/checkin/delete-any-active-checkins}
4748
*/
48-
delete: new TraktClientEndpoint({
49+
delete: new TraktClientEndpoint<Record<string, never>, unknown, false>({
4950
method: HttpMethod.DELETE,
5051
url: '/checkin',
5152
opts: {
5253
auth: true,
54+
cache: false,
5355
},
5456
}),
5557
};

src/services/trakt-client/api/endpoints/comments.endpoint.ts

+35-15
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ export const comments = {
5353
*
5454
* @see [post-a-comment]{@link https://trakt.docs.apiary.io/#reference/comments/comments/post-a-comment}
5555
*/
56-
add: new TraktClientEndpoint<TraktCommentRequest, TraktComment>({
56+
add: new TraktClientEndpoint<TraktCommentRequest, TraktComment, false>({
5757
method: HttpMethod.POST,
5858
url: '/comments',
5959
opts: {
6060
auth: true,
6161
emoji: true,
62+
cache: false,
6263
},
6364
body: {
6465
comment: true,
@@ -110,13 +111,15 @@ export const comments = {
110111
/** A specific comment ID. */
111112
id: number;
112113
},
113-
TraktComment
114+
TraktComment,
115+
false
114116
>({
115117
method: HttpMethod.PUT,
116118
url: '/comments/:id',
117119
opts: {
118120
auth: true,
119121
emoji: true,
122+
cache: false,
120123
parameters: {
121124
path: {
122125
id: true,
@@ -138,14 +141,19 @@ export const comments = {
138141
*
139142
* @see [delete-a-comment-or-reply]{@link https://trakt.docs.apiary.io/#reference/comments/comment/delete-a-comment-or-reply}
140143
*/
141-
remove: new TraktClientEndpoint<{
142-
/** A specific comment ID. */
143-
id: number;
144-
}>({
144+
remove: new TraktClientEndpoint<
145+
{
146+
/** A specific comment ID. */
147+
id: number;
148+
},
149+
unknown,
150+
false
151+
>({
145152
method: HttpMethod.DELETE,
146153
url: '/comments/:id',
147154
opts: {
148155
auth: true,
156+
cache: false,
149157
parameters: {
150158
path: {
151159
id: true,
@@ -196,13 +204,15 @@ export const comments = {
196204
/** Is this a spoiler? Defaults to false */
197205
spoiler?: boolean;
198206
},
199-
TraktComment
207+
TraktComment,
208+
false
200209
>({
201210
method: HttpMethod.POST,
202211
url: '/comments/:id/replies',
203212
opts: {
204213
auth: true,
205214
emoji: true,
215+
cache: false,
206216
parameters: {
207217
path: {
208218
id: true,
@@ -273,14 +283,19 @@ export const comments = {
273283
* @see [like-a-comment]{@link https://trakt.docs.apiary.io/#reference/comments/replies/like-a-comment}
274284
*/
275285
like: {
276-
add: new TraktClientEndpoint<{
277-
/** A specific comment ID. */
278-
id: number;
279-
}>({
286+
add: new TraktClientEndpoint<
287+
{
288+
/** A specific comment ID. */
289+
id: number;
290+
},
291+
unknown,
292+
false
293+
>({
280294
method: HttpMethod.POST,
281295
url: '/comments/:id/like',
282296
opts: {
283297
auth: true,
298+
cache: false,
284299
parameters: {
285300
path: {
286301
id: true,
@@ -295,14 +310,19 @@ export const comments = {
295310
*
296311
* @see [remove-like-on-a-comment]{@link https://trakt.docs.apiary.io/#reference/comments/like/remove-like-on-a-comment}
297312
*/
298-
remove: new TraktClientEndpoint<{
299-
/** A specific comment ID. */
300-
id: number;
301-
}>({
313+
remove: new TraktClientEndpoint<
314+
{
315+
/** A specific comment ID. */
316+
id: number;
317+
},
318+
unknown,
319+
false
320+
>({
302321
method: HttpMethod.DELETE,
303322
url: '/comments/:id/like',
304323
opts: {
305324
auth: true,
325+
cache: false,
306326
parameters: {
307327
path: {
308328
id: true,

src/services/trakt-client/api/endpoints/lists.endpoint.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,19 @@ export const lists = {
123123
*
124124
* @see [remove-like-on-a-list]{@link https://trakt.docs.apiary.io/#reference/lists/list-like/remove-like-on-a-list}
125125
*/
126-
remove: new TraktClientEndpoint<{
127-
/** Trakt ID (i.e. 15) */
128-
id: number;
129-
}>({
126+
remove: new TraktClientEndpoint<
127+
{
128+
/** Trakt ID (i.e. 15) */
129+
id: number;
130+
},
131+
unknown,
132+
false
133+
>({
130134
method: HttpMethod.DELETE,
131135
url: '/lists/:id/like',
132136
opts: {
133137
auth: true,
138+
cache: false,
134139
parameters: {
135140
path: {
136141
id: true,

src/services/trakt-client/api/endpoints/notes.endpoint.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ export const notes = {
2727
* @emoji true - [documentation]{@link https://trakt.docs.apiary.io/#introduction/emojis}
2828
* @auth required
2929
*/
30-
add: new TraktClientEndpoint<TraktNoteRequest, TraktNote>({
30+
add: new TraktClientEndpoint<TraktNoteRequest, TraktNote, false>({
3131
method: HttpMethod.POST,
3232
url: '/notes',
3333
opts: {
3434
auth: true,
3535
vip: true,
3636
emoji: true,
37+
cache: false,
3738
},
3839
body: {
3940
note: true,
@@ -94,14 +95,16 @@ export const notes = {
9495
/** A specific note ID */
9596
id: number;
9697
},
97-
TraktNote
98+
TraktNote,
99+
false
98100
>({
99101
method: HttpMethod.PUT,
100102
url: '/notes/:id',
101103
opts: {
102104
auth: true,
103105
vip: true,
104106
emoji: true,
107+
cache: false,
105108
parameters: {
106109
path: {
107110
id: true,
@@ -117,15 +120,20 @@ export const notes = {
117120
*
118121
* @see [delete-a-note]{@link https://trakt.docs.apiary.io/#reference/notes/note/delete-a-note}
119122
*/
120-
delete: new TraktClientEndpoint<{
121-
/** A specific note ID */
122-
id: number;
123-
}>({
123+
delete: new TraktClientEndpoint<
124+
{
125+
/** A specific note ID */
126+
id: number;
127+
},
128+
unknown,
129+
false
130+
>({
124131
method: HttpMethod.DELETE,
125132
url: '/notes/:id',
126133
opts: {
127134
auth: true,
128135
vip: true,
136+
cache: false,
129137
parameters: {
130138
path: {
131139
id: true,

src/services/trakt-client/api/endpoints/recommendations.endpoint.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,19 @@ export const recommendations = {
5252
*
5353
* @see [hide-a-movie-recommendation]{@link https://trakt.docs.apiary.io/#reference/recommendations/hide-movie/hide-a-movie-recommendation}
5454
*/
55-
hide: new TraktClientEndpoint<{
56-
/** Trakt ID, Trakt slug, or IMDB ID */
57-
id: string;
58-
}>({
55+
hide: new TraktClientEndpoint<
56+
{
57+
/** Trakt ID, Trakt slug, or IMDB ID */
58+
id: string;
59+
},
60+
unknown,
61+
false
62+
>({
5963
method: HttpMethod.DELETE,
6064
url: '/recommendations/movies/:id',
6165
opts: {
6266
auth: true,
67+
cache: false,
6368
parameters: {
6469
path: {
6570
id: true,

0 commit comments

Comments
 (0)