tbarequest 1.0.0 → 1.0.1
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/dist/index.d.ts +3 -0
- package/dist/index.js +69 -0
- package/dist/types/endpoints/districts.d.ts +161 -0
- package/dist/types/endpoints/districts.js +50 -0
- package/dist/types/endpoints/events.d.ts +1500 -0
- package/dist/types/endpoints/events.js +153 -0
- package/dist/types/endpoints/index.d.ts +25 -0
- package/dist/types/endpoints/index.js +25 -0
- package/dist/types/endpoints/insights.d.ts +29 -0
- package/dist/types/endpoints/insights.js +12 -0
- package/dist/types/endpoints/matches.d.ts +1101 -0
- package/dist/types/endpoints/matches.js +23 -0
- package/dist/types/endpoints/regionalAdvancements.d.ts +32 -0
- package/dist/types/endpoints/regionalAdvancements.js +12 -0
- package/dist/types/endpoints/status.d.ts +19 -0
- package/dist/types/endpoints/status.js +16 -0
- package/dist/types/endpoints/teams.d.ts +2713 -0
- package/dist/types/endpoints/teams.js +162 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.js +1 -0
- package/dist/types/schemas/districts.d.ts +25 -0
- package/dist/types/schemas/districts.js +28 -0
- package/dist/types/schemas/events.d.ts +186 -0
- package/dist/types/schemas/events.js +109 -0
- package/dist/types/schemas/insights.d.ts +21 -0
- package/dist/types/schemas/insights.js +22 -0
- package/dist/types/schemas/matches.d.ts +2781 -0
- package/dist/types/schemas/matches.js +597 -0
- package/dist/types/schemas/regionalAdvancements.d.ts +22 -0
- package/dist/types/schemas/regionalAdvancements.js +23 -0
- package/dist/types/schemas/status.d.ts +4 -0
- package/dist/types/schemas/status.js +5 -0
- package/dist/types/schemas/teams.d.ts +52 -0
- package/dist/types/schemas/teams.js +41 -0
- package/dist/utils.d.ts +11 -0
- package/dist/utils.js +9 -0
- package/package.json +1 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Result } from "./utils.js";
|
|
2
|
+
import { TBAEndpoint, TBAEndpoints } from "./types/endpoints/index.js";
|
|
3
|
+
export declare function createTBACaller(api_key: string): <T extends TBAEndpoint>(endpoint: T, ...args: TBAEndpoints[T]["arguments"]["infer"]) => Promise<Result<TBAEndpoints[T]["schema"]["infer"]>>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { tryCatch } from "./utils.js";
|
|
2
|
+
import { endpoints } from "./types/endpoints/index.js";
|
|
3
|
+
import { ArkErrors } from "arktype";
|
|
4
|
+
/*
|
|
5
|
+
* Creates a function that can call the TBA api.
|
|
6
|
+
* @see https://www.thebluealliance.com/apidocs/v3
|
|
7
|
+
* @param api_key The api key given to you from The Blue Alliance.
|
|
8
|
+
* @returns A function that can request from any endpoint in the TBA api. Go to the TBA api docs to see more information on endpoints and arguments required.
|
|
9
|
+
*/
|
|
10
|
+
export function createTBACaller(api_key) {
|
|
11
|
+
return async (endpoint, ...args) => await TBA(endpoint, api_key, ...args);
|
|
12
|
+
}
|
|
13
|
+
async function TBA(endpoint, api_key, ...args) {
|
|
14
|
+
let numArg = -1;
|
|
15
|
+
// Fills all the arguments that are needed.
|
|
16
|
+
const filledEndpoint = endpoint.replace(/{(.+?)}/g, () => {
|
|
17
|
+
numArg++;
|
|
18
|
+
return args[numArg].toString();
|
|
19
|
+
});
|
|
20
|
+
const result = await tryCatch(fetch(`https://www.thebluealliance.com/api/v3${filledEndpoint}`, {
|
|
21
|
+
headers: {
|
|
22
|
+
"X-TBA-Auth-Key": api_key,
|
|
23
|
+
},
|
|
24
|
+
}));
|
|
25
|
+
if (result.error)
|
|
26
|
+
return {
|
|
27
|
+
data: null, error: result.error,
|
|
28
|
+
};
|
|
29
|
+
if (result.data.status !== 200)
|
|
30
|
+
return {
|
|
31
|
+
data: null,
|
|
32
|
+
error: new Error(`${result.data.status} - ${result.data.statusText}`),
|
|
33
|
+
};
|
|
34
|
+
const json = await tryCatch(result.data.json());
|
|
35
|
+
if (json.error)
|
|
36
|
+
return {
|
|
37
|
+
data: null,
|
|
38
|
+
error: new Error(`JSON didn't parse for endpoint ${endpoint}. Please contact the developers of the TBArequest package with this error: ${json.error.message}`),
|
|
39
|
+
};
|
|
40
|
+
if ("transformMatch" in endpoints[endpoint]) {
|
|
41
|
+
let data;
|
|
42
|
+
switch (endpoint) {
|
|
43
|
+
case "/event/{event_key}/matches":
|
|
44
|
+
case "/match/{match_key}": {
|
|
45
|
+
data = { key: args[0] };
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case "/team/{team_key}/event/{event_key}/matches": {
|
|
49
|
+
data = { key: args[1] };
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case "/team/{team_key}/matches/{year}": {
|
|
53
|
+
data = { year: args[1] };
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
default: {
|
|
57
|
+
data = {};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
json.data = endpoints[endpoint].transformMatch(data, json.data);
|
|
61
|
+
}
|
|
62
|
+
let schema = endpoints[endpoint].schema(json.data);
|
|
63
|
+
if (schema instanceof ArkErrors)
|
|
64
|
+
return {
|
|
65
|
+
data: null,
|
|
66
|
+
error: new Error(`Schema for endpoint ${endpoint} didn't work. Please contact the developers of the TBArequest package with this error: ${schema}`),
|
|
67
|
+
};
|
|
68
|
+
return { data: schema, error: null };
|
|
69
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
export declare const districtEndpoints: {
|
|
2
|
+
"/districts/{year}": {
|
|
3
|
+
schema: import("arktype/internal/methods/array.ts").ArrayType<{
|
|
4
|
+
abbreviation: string;
|
|
5
|
+
display_name: string;
|
|
6
|
+
key: string;
|
|
7
|
+
year: number;
|
|
8
|
+
}[], {}>;
|
|
9
|
+
arguments: import("arktype/internal/methods/array.ts").ArrayType<[number], {}>;
|
|
10
|
+
};
|
|
11
|
+
"/district/{district_abbreviation}/history": {
|
|
12
|
+
schema: import("arktype/internal/methods/array.ts").ArrayType<{
|
|
13
|
+
abbreviation: string;
|
|
14
|
+
display_name: string;
|
|
15
|
+
key: string;
|
|
16
|
+
year: number;
|
|
17
|
+
}[], {}>;
|
|
18
|
+
arguments: import("arktype/internal/methods/array.ts").ArrayType<[string], {}>;
|
|
19
|
+
};
|
|
20
|
+
"/district/{district_key}/events": {
|
|
21
|
+
schema: import("arktype/internal/methods/array.ts").ArrayType<{
|
|
22
|
+
key: string;
|
|
23
|
+
name: string;
|
|
24
|
+
event_code: string;
|
|
25
|
+
event_type: number;
|
|
26
|
+
district: {
|
|
27
|
+
abbreviation: string;
|
|
28
|
+
display_name: string;
|
|
29
|
+
key: string;
|
|
30
|
+
year: number;
|
|
31
|
+
} | null;
|
|
32
|
+
city: string | null;
|
|
33
|
+
state_prov: string | null;
|
|
34
|
+
country: string | null;
|
|
35
|
+
start_date: string;
|
|
36
|
+
end_date: string;
|
|
37
|
+
year: number;
|
|
38
|
+
short_name: string | null;
|
|
39
|
+
event_type_string: string;
|
|
40
|
+
week: number | null;
|
|
41
|
+
address: string | null;
|
|
42
|
+
postal_code: string | null;
|
|
43
|
+
gmaps_place_id: string | null;
|
|
44
|
+
gmaps_url: string | null;
|
|
45
|
+
lat: number | null;
|
|
46
|
+
lng: number | null;
|
|
47
|
+
location_name: string | null;
|
|
48
|
+
timezone: string | null;
|
|
49
|
+
website: string | null;
|
|
50
|
+
first_event_id: string | null;
|
|
51
|
+
first_event_code: string | null;
|
|
52
|
+
webcasts: {
|
|
53
|
+
type: "youtube" | "twitch" | "ustream" | "iframe" | "html5" | "rtmp" | "livestream" | "direct_link" | "mms" | "justin" | "stemtv" | "dacast";
|
|
54
|
+
channel: string;
|
|
55
|
+
date?: string | null | undefined;
|
|
56
|
+
file?: string | null | undefined;
|
|
57
|
+
}[];
|
|
58
|
+
division_keys: string[];
|
|
59
|
+
parent_event_key: string | null;
|
|
60
|
+
playoff_type: number | null;
|
|
61
|
+
playoff_type_string: string | null;
|
|
62
|
+
}[], {}>;
|
|
63
|
+
arguments: import("arktype/internal/methods/array.ts").ArrayType<[string], {}>;
|
|
64
|
+
};
|
|
65
|
+
"/district/{district_key}/awards": {
|
|
66
|
+
schema: import("arktype/internal/methods/array.ts").ArrayType<{
|
|
67
|
+
name: string;
|
|
68
|
+
award_type: number;
|
|
69
|
+
event_key: string;
|
|
70
|
+
recipient_list: {
|
|
71
|
+
team_key: string | null;
|
|
72
|
+
awardee: string | null;
|
|
73
|
+
}[];
|
|
74
|
+
year: number;
|
|
75
|
+
}[], {}>;
|
|
76
|
+
arguments: import("arktype/internal/methods/array.ts").ArrayType<[string], {}>;
|
|
77
|
+
};
|
|
78
|
+
"/district/{district_key}/events/simple": {
|
|
79
|
+
schema: import("arktype/internal/methods/array.ts").ArrayType<{
|
|
80
|
+
key: string;
|
|
81
|
+
name: string;
|
|
82
|
+
event_code: string;
|
|
83
|
+
event_type: number;
|
|
84
|
+
district: {
|
|
85
|
+
abbreviation: string;
|
|
86
|
+
display_name: string;
|
|
87
|
+
key: string;
|
|
88
|
+
year: number;
|
|
89
|
+
} | null;
|
|
90
|
+
city: string | null;
|
|
91
|
+
state_prov: string | null;
|
|
92
|
+
country: string | null;
|
|
93
|
+
start_date: string;
|
|
94
|
+
end_date: string;
|
|
95
|
+
year: number;
|
|
96
|
+
}[], {}>;
|
|
97
|
+
arguments: import("arktype/internal/methods/array.ts").ArrayType<[string], {}>;
|
|
98
|
+
};
|
|
99
|
+
"/district/{district_key}/events/keys": {
|
|
100
|
+
schema: import("arktype/internal/methods/array.ts").ArrayType<string[], {}>;
|
|
101
|
+
arguments: import("arktype/internal/methods/array.ts").ArrayType<[string], {}>;
|
|
102
|
+
};
|
|
103
|
+
"/district/{district_key}/teams": {
|
|
104
|
+
schema: import("arktype/internal/methods/array.ts").ArrayType<{
|
|
105
|
+
key: string;
|
|
106
|
+
team_number: number;
|
|
107
|
+
nickname: string;
|
|
108
|
+
name: string;
|
|
109
|
+
city: string | null;
|
|
110
|
+
state_prov: string | null;
|
|
111
|
+
country: string | null;
|
|
112
|
+
postal_code: string | null;
|
|
113
|
+
rookie_year: number | null;
|
|
114
|
+
website?: string | null | undefined;
|
|
115
|
+
}[], {}>;
|
|
116
|
+
arguments: import("arktype/internal/methods/array.ts").ArrayType<[string], {}>;
|
|
117
|
+
};
|
|
118
|
+
"/district/{district_key}/teams/simple": {
|
|
119
|
+
schema: import("arktype/internal/methods/array.ts").ArrayType<{
|
|
120
|
+
key: string;
|
|
121
|
+
team_number: number;
|
|
122
|
+
nickname: string;
|
|
123
|
+
name: string;
|
|
124
|
+
city: string | null;
|
|
125
|
+
state_prov: string | null;
|
|
126
|
+
country: string | null;
|
|
127
|
+
}[], {}>;
|
|
128
|
+
arguments: import("arktype/internal/methods/array.ts").ArrayType<[string], {}>;
|
|
129
|
+
};
|
|
130
|
+
"/district/{district_key}/teams/keys": {
|
|
131
|
+
schema: import("arktype/internal/methods/array.ts").ArrayType<string[], {}>;
|
|
132
|
+
arguments: import("arktype/internal/methods/array.ts").ArrayType<[string], {}>;
|
|
133
|
+
};
|
|
134
|
+
"/district/{district_key}/rankings": {
|
|
135
|
+
schema: import("arktype").BaseType<{
|
|
136
|
+
team_key: string;
|
|
137
|
+
rank: number;
|
|
138
|
+
point_total: number;
|
|
139
|
+
rookie_bonus?: number | undefined;
|
|
140
|
+
event_point?: {
|
|
141
|
+
district_cmp: boolean;
|
|
142
|
+
total: number;
|
|
143
|
+
alliance_points: number;
|
|
144
|
+
elim_points: number;
|
|
145
|
+
award_points: number;
|
|
146
|
+
event_key: string;
|
|
147
|
+
qual_points: number;
|
|
148
|
+
}[] | undefined;
|
|
149
|
+
}[] | null, {}>;
|
|
150
|
+
arguments: import("arktype/internal/methods/array.ts").ArrayType<[string], {}>;
|
|
151
|
+
};
|
|
152
|
+
"/district/{district_key}/advancement": {
|
|
153
|
+
schema: import("arktype").BaseType<{
|
|
154
|
+
[x: string]: {
|
|
155
|
+
dcmp: boolean;
|
|
156
|
+
cmp: boolean;
|
|
157
|
+
};
|
|
158
|
+
} | null, {}>;
|
|
159
|
+
arguments: import("arktype/internal/methods/array.ts").ArrayType<[string], {}>;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { District_Advancement, District_List, District_Ranking, } from "../schemas/districts.js";
|
|
2
|
+
import { Event, Event_Simple } from "../schemas/events.js";
|
|
3
|
+
import { Award, Team, Team_Simple } from "../schemas/teams.js";
|
|
4
|
+
import { type } from "arktype";
|
|
5
|
+
export const districtEndpoints = {
|
|
6
|
+
"/districts/{year}": {
|
|
7
|
+
schema: District_List.array(),
|
|
8
|
+
arguments: type(["number"]),
|
|
9
|
+
},
|
|
10
|
+
"/district/{district_abbreviation}/history": {
|
|
11
|
+
schema: District_List.array(),
|
|
12
|
+
arguments: type(["string"]),
|
|
13
|
+
},
|
|
14
|
+
"/district/{district_key}/events": {
|
|
15
|
+
schema: Event.array(),
|
|
16
|
+
arguments: type(["string"]),
|
|
17
|
+
},
|
|
18
|
+
"/district/{district_key}/awards": {
|
|
19
|
+
schema: Award.array(),
|
|
20
|
+
arguments: type(["string"]),
|
|
21
|
+
},
|
|
22
|
+
"/district/{district_key}/events/simple": {
|
|
23
|
+
schema: Event_Simple.array(),
|
|
24
|
+
arguments: type(["string"]),
|
|
25
|
+
},
|
|
26
|
+
"/district/{district_key}/events/keys": {
|
|
27
|
+
schema: type("string[]"),
|
|
28
|
+
arguments: type(["string"]),
|
|
29
|
+
},
|
|
30
|
+
"/district/{district_key}/teams": {
|
|
31
|
+
schema: Team.array(),
|
|
32
|
+
arguments: type(["string"]),
|
|
33
|
+
},
|
|
34
|
+
"/district/{district_key}/teams/simple": {
|
|
35
|
+
schema: Team_Simple.array(),
|
|
36
|
+
arguments: type(["string"]),
|
|
37
|
+
},
|
|
38
|
+
"/district/{district_key}/teams/keys": {
|
|
39
|
+
schema: type("string[]"),
|
|
40
|
+
arguments: type(["string"]),
|
|
41
|
+
},
|
|
42
|
+
"/district/{district_key}/rankings": {
|
|
43
|
+
schema: type(District_Ranking.array(), "|", "null"),
|
|
44
|
+
arguments: type(["string"]),
|
|
45
|
+
},
|
|
46
|
+
"/district/{district_key}/advancement": {
|
|
47
|
+
schema: type({ "[string]": District_Advancement }, "|", "null"),
|
|
48
|
+
arguments: type(["string"]),
|
|
49
|
+
},
|
|
50
|
+
};
|