@brickset-api/types 0.0.13 → 0.0.14
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/CHANGELOG.md +6 -0
- package/endpoints.ts +19 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/endpoints.ts
CHANGED
|
@@ -5,11 +5,19 @@ export type KnownAuthenticatedEndpoint =
|
|
|
5
5
|
|
|
6
6
|
export type KnownUnauthorizedEndpoint =
|
|
7
7
|
| '/api/v3.asmx/getSets'
|
|
8
|
-
| '/api/v3.asmx/getThemes'
|
|
9
|
-
| '/api/v3.asmx/getYears';
|
|
8
|
+
| '/api/v3.asmx/getThemes';
|
|
10
9
|
|
|
11
10
|
export type KnownEndpoint = KnownAuthenticatedEndpoint | KnownUnauthorizedEndpoint;
|
|
12
11
|
|
|
12
|
+
// helper types for parameters
|
|
13
|
+
type CombineParameters<P1 extends string, P2 extends string> = `${P1}&${P2}` | `${P2}&${P1}`;
|
|
14
|
+
|
|
15
|
+
type WithParameters<Url extends string, Parameters extends string | undefined = undefined> =
|
|
16
|
+
Parameters extends undefined ? Url : `${Url}?${Parameters}`;
|
|
17
|
+
|
|
18
|
+
type UrlWithParams<Url extends KnownEndpoint> =
|
|
19
|
+
| WithParameters<Url, `params=${string}`>;
|
|
20
|
+
|
|
13
21
|
// options
|
|
14
22
|
type Options = {};
|
|
15
23
|
|
|
@@ -17,19 +25,24 @@ export type ApiKeyOptions = {
|
|
|
17
25
|
apiKey: string;
|
|
18
26
|
};
|
|
19
27
|
|
|
20
|
-
export type AuthenticatedOptions = ApiKeyOptions &{
|
|
28
|
+
export type AuthenticatedOptions = ApiKeyOptions & {
|
|
21
29
|
userHash: string;
|
|
22
30
|
};
|
|
23
31
|
|
|
24
32
|
export type OptionsByEndpoint<Endpoint extends string> =
|
|
25
|
-
Endpoint extends '/api/v3.asmx/getSets' ? Options &
|
|
33
|
+
Endpoint extends UrlWithParams<'/api/v3.asmx/getSets'> ? Options & ApiKeyOptions :
|
|
26
34
|
Endpoint extends '/api/v3.asmx/getThemes' ? Options & ApiKeyOptions :
|
|
27
|
-
Endpoint extends '/api/v3.asmx/getYears' ? Options & { theme?: string } & ApiKeyOptions :
|
|
28
35
|
Partial<AuthenticatedOptions & ApiKeyOptions>;
|
|
29
36
|
|
|
37
|
+
// Common Brickset API v3 response
|
|
38
|
+
export type ApiResponse<T> = { status: 'success' } & T | { status: 'error'; message: string };
|
|
39
|
+
|
|
40
|
+
// Brickset API v3
|
|
41
|
+
|
|
30
42
|
// result type for endpoint
|
|
31
43
|
export type EndpointType<Url extends KnownEndpoint | (string & {})> =
|
|
32
|
-
Url extends '/api/v3.asmx/getSets' ? {
|
|
44
|
+
Url extends UrlWithParams<'/api/v3.asmx/getSets'> ? ApiResponse<{ matches: number; sets: GetSets[] }> :
|
|
45
|
+
Url extends '/api/v3.asmx/getThemes' ? ApiResponse<{ matches: number, themes: string[] }> :
|
|
33
46
|
unknown;
|
|
34
47
|
|
|
35
48
|
export type ValidateEndpointUrl<T extends string> = unknown extends EndpointType<T> ? 'unknown endpoint url' : T;
|