@databallr/sdk 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { components } from "./generated/schema.ts";
2
+ export { Databallr, PRODUCTION_API_KEY_PREFIX, PRODUCTION_BASE_URL, type DataballrOptions, } from "./client.ts";
3
+ export { DataballrConnectionError, DataballrError, DataballrTimeoutError } from "./errors.ts";
4
+ export { SPEC_HASH } from "./generated/methods.ts";
5
+ export type { components, operations as Operations, paths } from "./generated/schema.ts";
6
+ export type { CallOptions, GetPath, Methods, Operation, PostPath, RequestOptions, ResponseBody, } from "./types.ts";
7
+ /** A response model by its OpenAPI component name, e.g. `Schema<"StandingsResponse">`. */
8
+ export type Schema<Name extends keyof components["schemas"]> = components["schemas"][Name];
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { Databallr, PRODUCTION_API_KEY_PREFIX, PRODUCTION_BASE_URL, } from "./client.js";
2
+ export { DataballrConnectionError, DataballrError, DataballrTimeoutError } from "./errors.js";
3
+ export { SPEC_HASH } from "./generated/methods.js";
@@ -0,0 +1,83 @@
1
+ import type { paths } from "./generated/schema.ts";
2
+ export type Method = "get" | "post";
3
+ /** Every path that has an operation for `M` a personal API key can call. */
4
+ type PathsWith<M extends Method> = {
5
+ [P in keyof paths]: [NonNullable<paths[P][M]>] extends [never] ? never : P;
6
+ }[keyof paths];
7
+ export type GetPath = PathsWith<"get">;
8
+ export type PostPath = PathsWith<"post">;
9
+ export type Operation<P extends keyof paths, M extends Method> = NonNullable<paths[P][M]>;
10
+ type Parameters_<O> = O extends {
11
+ parameters: infer Params;
12
+ } ? Params : never;
13
+ /**
14
+ * openapi-typescript writes an unused parameter group as `name?: never` and a
15
+ * used one as `name: {...}` (required) or `name?: {...}`; `Pick` keeps that.
16
+ */
17
+ type ParameterOption<O, Name extends "path" | "query"> = Parameters_<O> extends {
18
+ [K in Name]?: never;
19
+ } ? {} : Pick<Parameters_<O>, Name & keyof Parameters_<O>>;
20
+ type BodyOption<O> = O extends {
21
+ requestBody: {
22
+ content: {
23
+ "application/json": infer Body;
24
+ };
25
+ };
26
+ } ? {
27
+ body: Body;
28
+ } : O extends {
29
+ requestBody?: {
30
+ content: {
31
+ "application/json": infer Body;
32
+ };
33
+ };
34
+ } ? {
35
+ body?: Body;
36
+ } : {};
37
+ export interface CallOptions {
38
+ /** Aborts the request, including any retry it is waiting on. */
39
+ signal?: AbortSignal;
40
+ /** Extra headers. `Authorization` is always the client's key. */
41
+ headers?: Record<string, string>;
42
+ /** Overrides the client's `timeoutMs` for this call. */
43
+ timeoutMs?: number;
44
+ /** Overrides the client's `maxRetries` for this call. */
45
+ maxRetries?: number;
46
+ }
47
+ export type RequestOptions<O> = ParameterOption<O, "path"> & ParameterOption<O, "query"> & BodyOption<O> & CallOptions;
48
+ /** The options argument is optional when nothing in it is required. */
49
+ export type RequestArgs<O> = {} extends RequestOptions<O> ? [options?: RequestOptions<O>] : [options: RequestOptions<O>];
50
+ type SuccessContent<O> = O extends {
51
+ responses: {
52
+ 200: {
53
+ content: infer Content;
54
+ };
55
+ };
56
+ } ? Content : never;
57
+ /** JSON bodies are parsed, `text/plain` is a string, anything else an ArrayBuffer. */
58
+ export type ResponseBody<O> = SuccessContent<O> extends {
59
+ "application/json": infer Json;
60
+ } ? Json : SuccessContent<O> extends {
61
+ "text/plain": unknown;
62
+ } ? string : ArrayBuffer;
63
+ /** `dbr.get` and `dbr.post`: a path for `M` and that operation's options. */
64
+ export type Call<M extends Method> = <P extends PathsWith<M>>(path: P, ...args: RequestArgs<Operation<P, M>>) => Promise<ResponseBody<Operation<P, M>>>;
65
+ /** A generated method's parameters: path and query parameters in one object. */
66
+ type MethodParams<O> = (Parameters_<O> extends {
67
+ path: infer Path;
68
+ } ? Path : {}) & (Parameters_<O> extends {
69
+ query: infer Query;
70
+ } ? Query : Parameters_<O> extends {
71
+ query?: infer Query;
72
+ } ? [Query] extends [undefined] ? {} : NonNullable<Query> : {});
73
+ type GetMethod<P extends GetPath> = (...args: {} extends MethodParams<Operation<P, "get">> ? [params?: MethodParams<Operation<P, "get">>, options?: CallOptions] : [params: MethodParams<Operation<P, "get">>, options?: CallOptions]) => Promise<ResponseBody<Operation<P, "get">>>;
74
+ type PostMethod<P extends PostPath> = (...args: BodyOption<Operation<P, "post">> extends {
75
+ body: infer Body;
76
+ } ? [body: Body, options?: CallOptions] : BodyOption<Operation<P, "post">> extends {
77
+ body?: infer Body;
78
+ } ? [body?: Body, options?: CallOptions] : [body?: undefined, options?: CallOptions]) => Promise<ResponseBody<Operation<P, "post">>>;
79
+ /** Turns the generated method table (paths, or `POST <path>`) into callable methods. */
80
+ export type Methods<Table> = {
81
+ readonly [K in keyof Table]: Table[K] extends `POST ${infer P extends PostPath}` ? PostMethod<P> : Table[K] extends GetPath ? GetMethod<Table[K]> : Methods<Table[K]>;
82
+ };
83
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "@databallr/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "TypeScript client for the databallr API (NBA and WNBA stats, SixRings)",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/databallr/databallr.git",
9
+ "directory": "packages/sdk"
10
+ },
11
+ "homepage": "https://api.databallr.com/docs",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "type": "module",
16
+ "sideEffects": false,
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ }
22
+ },
23
+ "devDependencies": {
24
+ "@arethetypeswrong/cli": "0.18.5",
25
+ "openapi-typescript": "7.13.0",
26
+ "publint": "0.3.25",
27
+ "typescript": "5.9.3",
28
+ "vite": "8.2.2",
29
+ "vitest": "4.1.10",
30
+ "@databallr/api-schemas": "0.1.0"
31
+ },
32
+ "engines": {
33
+ "node": ">=20"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public",
37
+ "tag": "next"
38
+ },
39
+ "scripts": {
40
+ "generate": "node scripts/generate.mjs",
41
+ "generate:check": "node scripts/generate.mjs --check",
42
+ "check:public-surface": "node scripts/check-public-surface.mjs",
43
+ "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json && tsc -p tsconfig.types.json",
44
+ "check:package": "publint && attw --pack . --profile esm-only && node scripts/check-size.mjs",
45
+ "test": "pnpm generate:check && pnpm check:public-surface && vitest run && pnpm build && pnpm check:package",
46
+ "typecheck": "tsc --noEmit"
47
+ }
6
48
  }