@tmdb-graphql-api/rest-client 0.0.6
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.
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/cjs/index.cjs +162 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.mjs +132 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/cjs/constants.d.cts +29 -0
- package/dist/types/cjs/constants.d.cts.map +1 -0
- package/dist/types/cjs/helpers/pathTemplateCallback.d.cts +2 -0
- package/dist/types/cjs/helpers/pathTemplateCallback.d.cts.map +1 -0
- package/dist/types/cjs/index.d.cts +4 -0
- package/dist/types/cjs/index.d.cts.map +1 -0
- package/dist/types/cjs/main.d.cts +3 -0
- package/dist/types/cjs/main.d.cts.map +1 -0
- package/dist/types/cjs/types.d.cts +13 -0
- package/dist/types/cjs/types.d.cts.map +1 -0
- package/dist/types/esm/constants.d.ts +29 -0
- package/dist/types/esm/constants.d.ts.map +1 -0
- package/dist/types/esm/helpers/pathTemplateCallback.d.ts +2 -0
- package/dist/types/esm/helpers/pathTemplateCallback.d.ts.map +1 -0
- package/dist/types/esm/index.d.ts +4 -0
- package/dist/types/esm/index.d.ts.map +1 -0
- package/dist/types/esm/main.d.ts +3 -0
- package/dist/types/esm/main.d.ts.map +1 -0
- package/dist/types/esm/types.d.ts +13 -0
- package/dist/types/esm/types.d.ts.map +1 -0
- package/dist/types/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +58 -0
- package/src/__snapshots__/main.test.ts.snap +57 -0
- package/src/constants.ts +31 -0
- package/src/helpers/pathTemplateCallback.ts +11 -0
- package/src/index.ts +3 -0
- package/src/main.test.ts +21 -0
- package/src/main.ts +78 -0
- package/src/types.ts +35 -0
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +8 -0
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tmdb-graphql-api/rest-client",
|
|
3
|
+
"description": "The TMDB GraphQL rest client module.",
|
|
4
|
+
"version": "0.0.6",
|
|
5
|
+
"author": "Dylan Aubrey",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/badbatch/themoviedb-graphql-api",
|
|
8
|
+
"repository": {
|
|
9
|
+
"directory": "packages/rest-client",
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/badbatch/themoviedb-graphql-api/packages/rest-client"
|
|
12
|
+
},
|
|
13
|
+
"bugs": "https://github.com/badbatch/themoviedb-graphql-api/issues",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/cjs/index.cjs",
|
|
16
|
+
"module": "./dist/esm/index.mjs",
|
|
17
|
+
"types": "./dist/types/cjs/index.d.cts",
|
|
18
|
+
"exports": {
|
|
19
|
+
"types": {
|
|
20
|
+
"import": "./dist/types/esm/index.d.ts",
|
|
21
|
+
"require": "./dist/types/cjs/index.d.cts"
|
|
22
|
+
},
|
|
23
|
+
"import": "./dist/esm/index.mjs",
|
|
24
|
+
"require": "./dist/cjs/index.cjs"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@cachemap/core": "^5.0.7",
|
|
31
|
+
"@graphql-box/core": "^5.0.0",
|
|
32
|
+
"getta": "^1.0.4",
|
|
33
|
+
"type-fest": "^4.5.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@babel/runtime": "<8",
|
|
37
|
+
"core-js": "<4",
|
|
38
|
+
"lodash-es": "<5"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@babel/runtime": "^7.23.2",
|
|
42
|
+
"@jest/globals": "^29.7.0",
|
|
43
|
+
"@types/lodash-es": "^4.14.191",
|
|
44
|
+
"core-js": "^3.33.1",
|
|
45
|
+
"cts-types": "^0.0.4",
|
|
46
|
+
"del-cli": "^5.1.0",
|
|
47
|
+
"lodash-es": "^4.17.21"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "pnpm run clean:dist && pnpm run compile",
|
|
51
|
+
"clean:deps": "del-cli ./node_modules",
|
|
52
|
+
"clean:dist": "del-cli ./dist",
|
|
53
|
+
"compile": "pnpm run /^compile:.*/",
|
|
54
|
+
"compile:cjs": "MODULE_SYSTEM=cjs rollup -c ../../rollup.config.cjs",
|
|
55
|
+
"compile:esm": "rollup -c ../../rollup.config.cjs",
|
|
56
|
+
"compile:types": "tsc --project ./tsconfig.build.json && cts-types build dist/types/esm dist/types/cjs"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`createRestClient > WHEN the dollygrip rest client is created > THEN it should have the correct properties and methods 1`] = `
|
|
4
|
+
Getta {
|
|
5
|
+
"_basePath": "https://api.themoviedb.org/3/",
|
|
6
|
+
"_bodyParser": [Function],
|
|
7
|
+
"_cache": "mock-cache",
|
|
8
|
+
"_conditionalRequestsEnabled": true,
|
|
9
|
+
"_fetchTimeout": 5000,
|
|
10
|
+
"_headers": {
|
|
11
|
+
"content-type": "application/json",
|
|
12
|
+
},
|
|
13
|
+
"_log": [Function],
|
|
14
|
+
"_maxRedirects": 5,
|
|
15
|
+
"_maxRetries": 3,
|
|
16
|
+
"_optionalPathTemplateRegExp": /\\(\\{\\\\w\\+\\\\\\?\\}\\)/g,
|
|
17
|
+
"_pathTemplateCallback": [Function],
|
|
18
|
+
"_pathTemplateRegExp": /\\(\\{type\\}\\)\\|\\(\\{subType\\}\\)\\|\\(\\{number\\}\\)\\|\\(\\{seasonNumber\\}\\)\\|\\(\\{episodeNumber\\}\\)\\|\\(\\{id\\}\\)/g,
|
|
19
|
+
"_performance": "mock-performance",
|
|
20
|
+
"_queryParams": {
|
|
21
|
+
"api_key": "12345",
|
|
22
|
+
},
|
|
23
|
+
"_rateLimit": false,
|
|
24
|
+
"_rateLimitCount": 0,
|
|
25
|
+
"_rateLimitPerSecond": 30,
|
|
26
|
+
"_rateLimitTimer": undefined,
|
|
27
|
+
"_rateLimitedRequestQueue": [],
|
|
28
|
+
"_requestRetryWait": 100,
|
|
29
|
+
"_requestTracker": {
|
|
30
|
+
"active": [],
|
|
31
|
+
"pending": Map {},
|
|
32
|
+
},
|
|
33
|
+
"_streamReader": "json",
|
|
34
|
+
"authenticate": [Function],
|
|
35
|
+
"certifications": [Function],
|
|
36
|
+
"collection": [Function],
|
|
37
|
+
"company": [Function],
|
|
38
|
+
"configuration": [Function],
|
|
39
|
+
"credit": [Function],
|
|
40
|
+
"discover": [Function],
|
|
41
|
+
"episode": [Function],
|
|
42
|
+
"find": [Function],
|
|
43
|
+
"genres": [Function],
|
|
44
|
+
"keyword": [Function],
|
|
45
|
+
"movie": [Function],
|
|
46
|
+
"network": [Function],
|
|
47
|
+
"person": [Function],
|
|
48
|
+
"popular": [Function],
|
|
49
|
+
"rated": [Function],
|
|
50
|
+
"review": [Function],
|
|
51
|
+
"search": [Function],
|
|
52
|
+
"season": [Function],
|
|
53
|
+
"trending": [Function],
|
|
54
|
+
"tv": [Function],
|
|
55
|
+
"watchProviders": [Function],
|
|
56
|
+
}
|
|
57
|
+
`;
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const BASE_PATH = 'https://api.themoviedb.org/3/';
|
|
2
|
+
|
|
3
|
+
export const GET_METHOD = 'get' as const;
|
|
4
|
+
export const POST_METHOD = 'post' as const;
|
|
5
|
+
export const PUT_METHOD = 'put' as const;
|
|
6
|
+
export const DELETE_METHOD = 'delete' as const;
|
|
7
|
+
|
|
8
|
+
export const OPTIONAL_TYPE_PATH_TEMPLATE_REGEX = /({type\?})/g;
|
|
9
|
+
|
|
10
|
+
export const AUTHENTICATE_PATH = 'authentication/{type}/new';
|
|
11
|
+
export const CERTIFICATIONS_PATH = 'certification/{type}/list';
|
|
12
|
+
export const COLLECTION_PATH = 'collection/{id}/{type?}';
|
|
13
|
+
export const COMPANY_PATH = 'company/{id}/{type?}';
|
|
14
|
+
export const CONFIGURATION_PATH = 'configuration/{type?}';
|
|
15
|
+
export const CREDIT_PATH = 'credit/{id}';
|
|
16
|
+
export const DISCOVER_PATH = 'discover/{type}';
|
|
17
|
+
export const EPISODE_PATH = 'tv/{id}/season/{seasonNumber}/episode/{episodeNumber}/{type?}';
|
|
18
|
+
export const FIND_PATH = 'find/{id}';
|
|
19
|
+
export const GENRE_PATH = 'genre/{type}/list';
|
|
20
|
+
export const KEYWORD_PATH = 'keyword/{id}';
|
|
21
|
+
export const MOVIE_PATH = 'movie/{id}/{type?}';
|
|
22
|
+
export const NETWORK_PATH = 'network/{id}/{type?}';
|
|
23
|
+
export const PERSON_PATH = 'person/{id}/{type?}';
|
|
24
|
+
export const POPULAR_PATH = '{type}/popular';
|
|
25
|
+
export const RATED_PATH = 'guest_session/{id}/rated/{type}';
|
|
26
|
+
export const REVIEW_PATH = 'review/{id}';
|
|
27
|
+
export const SEARCH_PATH = 'search/{type}';
|
|
28
|
+
export const SEASON_PATH = 'tv/{id}/season/{number}/{type?}';
|
|
29
|
+
export const TRENDING_PATH = 'trending/{type}/{subType}';
|
|
30
|
+
export const TV_PATH = 'tv/{id}/{type?}';
|
|
31
|
+
export const WATCH_PROVIDER_PATH = '{type}/{id}/watch/providers';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defaultPathTemplateCallback } from 'getta';
|
|
2
|
+
import { OPTIONAL_TYPE_PATH_TEMPLATE_REGEX } from '../constants.ts';
|
|
3
|
+
|
|
4
|
+
export const pathTemplateCallback = (
|
|
5
|
+
pathTemplate: string,
|
|
6
|
+
data: Record<string, string>,
|
|
7
|
+
pathTemplateRegExp: RegExp
|
|
8
|
+
) => {
|
|
9
|
+
const populatedPath = defaultPathTemplateCallback(pathTemplate, data, pathTemplateRegExp);
|
|
10
|
+
return populatedPath.replace(OPTIONAL_TYPE_PATH_TEMPLATE_REGEX, data.type ?? '');
|
|
11
|
+
};
|
package/src/index.ts
ADDED
package/src/main.test.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Core } from '@cachemap/core';
|
|
2
|
+
import { jest } from '@jest/globals';
|
|
3
|
+
|
|
4
|
+
jest.unstable_mockModule('node:perf_hooks', () => ({
|
|
5
|
+
performance: 'mock-performance',
|
|
6
|
+
}));
|
|
7
|
+
|
|
8
|
+
describe('createRestClient >', () => {
|
|
9
|
+
describe('WHEN the dollygrip rest client is created >', () => {
|
|
10
|
+
it('THEN it should have the correct properties and methods', async () => {
|
|
11
|
+
const { createRestClient } = await import('./index.ts');
|
|
12
|
+
|
|
13
|
+
const restClient = createRestClient({
|
|
14
|
+
cache: 'mock-cache' as unknown as Core,
|
|
15
|
+
queryParams: { api_key: '12345' },
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
expect(restClient).toMatchSnapshot();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
});
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { RESOLVER_EXECUTED, RESOLVER_RESOLVED } from '@graphql-box/core';
|
|
2
|
+
import { REQUEST_SENT, RESPONSE_RECEIVED, createRestClient as create } from 'getta';
|
|
3
|
+
import { performance } from 'node:perf_hooks';
|
|
4
|
+
import {
|
|
5
|
+
AUTHENTICATE_PATH,
|
|
6
|
+
BASE_PATH,
|
|
7
|
+
CERTIFICATIONS_PATH,
|
|
8
|
+
COLLECTION_PATH,
|
|
9
|
+
COMPANY_PATH,
|
|
10
|
+
CONFIGURATION_PATH,
|
|
11
|
+
CREDIT_PATH,
|
|
12
|
+
DISCOVER_PATH,
|
|
13
|
+
EPISODE_PATH,
|
|
14
|
+
FIND_PATH,
|
|
15
|
+
GENRE_PATH,
|
|
16
|
+
GET_METHOD,
|
|
17
|
+
KEYWORD_PATH,
|
|
18
|
+
MOVIE_PATH,
|
|
19
|
+
NETWORK_PATH,
|
|
20
|
+
PERSON_PATH,
|
|
21
|
+
POPULAR_PATH,
|
|
22
|
+
RATED_PATH,
|
|
23
|
+
REVIEW_PATH,
|
|
24
|
+
SEARCH_PATH,
|
|
25
|
+
SEASON_PATH,
|
|
26
|
+
TRENDING_PATH,
|
|
27
|
+
TV_PATH,
|
|
28
|
+
WATCH_PROVIDER_PATH,
|
|
29
|
+
} from './constants.ts';
|
|
30
|
+
import { pathTemplateCallback } from './helpers/pathTemplateCallback.ts';
|
|
31
|
+
import type { CreateRestClientParams, ShortcutMethodNames } from './types.ts';
|
|
32
|
+
|
|
33
|
+
const { NODE_ENV } = process.env;
|
|
34
|
+
|
|
35
|
+
export const createRestClient = ({ cache, debugManager, queryParams }: CreateRestClientParams) =>
|
|
36
|
+
create<ShortcutMethodNames>(
|
|
37
|
+
{
|
|
38
|
+
basePath: BASE_PATH,
|
|
39
|
+
cache,
|
|
40
|
+
fetchTimeout: NODE_ENV === 'development' ? 999_999 : undefined,
|
|
41
|
+
log: (message, data, logLevel) => {
|
|
42
|
+
if (message === REQUEST_SENT) {
|
|
43
|
+
debugManager?.log(RESOLVER_EXECUTED, data, logLevel);
|
|
44
|
+
} else if (message === RESPONSE_RECEIVED) {
|
|
45
|
+
debugManager?.log(RESOLVER_RESOLVED, data, logLevel);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
pathTemplateCallback,
|
|
49
|
+
pathTemplateRegExp: /({type})|({subType})|({number})|({seasonNumber})|({episodeNumber})|({id})/g,
|
|
50
|
+
performance,
|
|
51
|
+
queryParams,
|
|
52
|
+
rateLimitPerSecond: 30,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
authenticate: [AUTHENTICATE_PATH, { method: GET_METHOD }],
|
|
56
|
+
certifications: [CERTIFICATIONS_PATH, { method: GET_METHOD }],
|
|
57
|
+
collection: [COLLECTION_PATH, { method: GET_METHOD }],
|
|
58
|
+
company: [COMPANY_PATH, { method: GET_METHOD }],
|
|
59
|
+
configuration: [CONFIGURATION_PATH, { method: GET_METHOD }],
|
|
60
|
+
credit: [CREDIT_PATH, { method: GET_METHOD }],
|
|
61
|
+
discover: [DISCOVER_PATH, { method: GET_METHOD }],
|
|
62
|
+
episode: [EPISODE_PATH, { method: GET_METHOD }],
|
|
63
|
+
find: [FIND_PATH, { method: GET_METHOD }],
|
|
64
|
+
genres: [GENRE_PATH, { method: GET_METHOD }],
|
|
65
|
+
keyword: [KEYWORD_PATH, { method: GET_METHOD }],
|
|
66
|
+
movie: [MOVIE_PATH, { method: GET_METHOD }],
|
|
67
|
+
network: [NETWORK_PATH, { method: GET_METHOD }],
|
|
68
|
+
person: [PERSON_PATH, { method: GET_METHOD }],
|
|
69
|
+
popular: [POPULAR_PATH, { method: GET_METHOD }],
|
|
70
|
+
rated: [RATED_PATH, { method: GET_METHOD }],
|
|
71
|
+
review: [REVIEW_PATH, { method: GET_METHOD }],
|
|
72
|
+
search: [SEARCH_PATH, { method: GET_METHOD }],
|
|
73
|
+
season: [SEASON_PATH, { method: GET_METHOD }],
|
|
74
|
+
trending: [TRENDING_PATH, { method: GET_METHOD }],
|
|
75
|
+
tv: [TV_PATH, { method: GET_METHOD }],
|
|
76
|
+
watchProviders: [WATCH_PROVIDER_PATH, { method: GET_METHOD }],
|
|
77
|
+
}
|
|
78
|
+
);
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Core } from '@cachemap/core';
|
|
2
|
+
import type { DebugManagerDef } from '@graphql-box/core';
|
|
3
|
+
import type { JsonObject } from 'type-fest';
|
|
4
|
+
|
|
5
|
+
export type ShortcutMethodNames =
|
|
6
|
+
| 'authenticate'
|
|
7
|
+
| 'certifications'
|
|
8
|
+
| 'collection'
|
|
9
|
+
| 'company'
|
|
10
|
+
| 'configuration'
|
|
11
|
+
| 'credit'
|
|
12
|
+
| 'discover'
|
|
13
|
+
| 'episode'
|
|
14
|
+
| 'find'
|
|
15
|
+
| 'genres'
|
|
16
|
+
| 'keyword'
|
|
17
|
+
| 'latest'
|
|
18
|
+
| 'movie'
|
|
19
|
+
| 'network'
|
|
20
|
+
| 'person'
|
|
21
|
+
| 'popular'
|
|
22
|
+
| 'rated'
|
|
23
|
+
| 'review'
|
|
24
|
+
| 'search'
|
|
25
|
+
| 'season'
|
|
26
|
+
| 'trending'
|
|
27
|
+
| 'tv'
|
|
28
|
+
| 'watchProviders';
|
|
29
|
+
|
|
30
|
+
export interface CreateRestClientParams {
|
|
31
|
+
cache?: Core;
|
|
32
|
+
debugManager?: DebugManagerDef;
|
|
33
|
+
// eslint-disable-next-line camelcase
|
|
34
|
+
queryParams: JsonObject & { api_key: string; language?: string };
|
|
35
|
+
}
|