Skip to content

Commit

Permalink
feat(types): specify response types for most of the endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Qrzy committed Aug 15, 2023
1 parent 711d8b4 commit 5f2bae6
Show file tree
Hide file tree
Showing 14 changed files with 567 additions and 47 deletions.
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export type ResourceName =

export type OneOrNothing = 1 | undefined

export type SingleOrMany<T> = T | T[]

export interface OfValue<T = any> {
value: T
}

export type ThingType =
| 'boardgame'
| 'boardgameexpansion'
Expand Down
1 change: 0 additions & 1 deletion src/typings.d.ts

This file was deleted.

100 changes: 95 additions & 5 deletions src/wrappers/getBggCollection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bggXmlApiClient } from '../client'
import type { OneOrNothing } from '../types'
import type { OfValue, OneOrNothing } from '../types'

type BggCollectionSubtype =
| 'boardgame'
Expand Down Expand Up @@ -44,15 +44,105 @@ export interface BggCollectionParams {
modifiedsince?: string // YY-MM-DD or YY-MM-DD%20HH:MM:SS
}

// TODO: specify this interface
export interface BggCollectionResponse {
[prop: string]: any
items: {
item: {
name: {
text: string
sortindex: number
}
originalname: string
yearpublished: number
image: string
thumbnail: string
stats: {
rating: {
usersrated: OfValue<number>
average: OfValue<number>
bayesaverage: OfValue<number>
stddev: OfValue<number>
median: OfValue<number>
ranks: {
rank: {
type: 'subtype' | 'family' | string
id: number
name: string
friendlyname: string
value: number
bayesaverage: number
}[]
}
value: string
}
minplayers: 2
maxplayers: 2
minplaytime: 150
maxplaytime: 150
playingtime: 150
numowned: 4434
}
status: {
own: ZeroOrOne
prevowned: ZeroOrOne
fortrade: ZeroOrOne
want: ZeroOrOne
wanttoplay: ZeroOrOne
wanttobuy: ZeroOrOne
wishlist: ZeroOrOne
wishlistpriority?: 1 | 2 | 3 | 4 | 5
preordered: ZeroOrOne
lastmodified: string
}
numlpays: number
version?: {
item: {
thumbnail: string
image: string
link: {
type:
| 'boardgameversion'
| 'boardgamepublisher'
| 'language'
| string
id: number
value: string
inbound?: boolean
}[]
name: {
type: 'primary' | string
sortindex: number
value: string
}
yearpublished: OfValue<number>
productcode: OfValue<string>
width: OfValue<number>
length: OfValue<number>
depth: OfValue<number>
weight: OfValue<number>
type: 'boardgameversion' | string
id: number
}
}
objecttype: 'thing' | string
objectid: number
subtype: string
collid: number
}[]
totalitems: number
termsofuse: string
pubdate: string
[prop: string]: unknown
}
}

export function getBggCollection(params: BggCollectionParams): Promise<BggCollectionResponse> {
export function getBggCollection(
params: BggCollectionParams,
): Promise<BggCollectionResponse> {
const newParams = {
...params,
...(params.id && { id: Array.isArray(params.id) ? params.id.join(',') : params.id }),
...(params.id && {
id: Array.isArray(params.id) ? params.id.join(',') : params.id,
}),
}
return bggXmlApiClient.get('collection', newParams)
}
25 changes: 22 additions & 3 deletions src/wrappers/getBggFamily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,29 @@ export interface BggFamilyParams {
type?: BggFamilyType
}

// TODO: specify this interface

export interface BggFamilyResponse {
[prop: string]: any
items: {
item: {
thumbnail: string
image: string
name: {
type: 'primary' | string
sortindex: number
value: string
}
description: string
link: {
type: 'boardgamefamily' | string
id: number
value: string
inbound: boolean
}[]
type: 'boardgamefamily' | string
[prop: string]: unknown
}
termsofuse: string
[prop: string]: unknown
}
}

export function getBggFamily(params: BggFamilyParams): Promise<BggFamilyResponse> {
Expand Down
27 changes: 23 additions & 4 deletions src/wrappers/getBggForum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,30 @@ export interface BggForumParams {
page?: number
}

// TODO: specify this interface

export interface BggForumResponse {

[prop: string]: any
forum: {
threads: {
thread: {
id: number
subject: string
author: string
numarticles: number
postdate: string
lastpostdate: string
[prop: string]: unknown
}[]
[prop: string]: unknown
}
id: number
title: string
numthreads: number
numposts: number
lastpostdate: string
noposting: number
termsofuse: string
[prop: string]: unknown
}
[prop: string]: unknown
}

export function getBggForum(params: BggForumParams): Promise<BggForumResponse> {
Expand Down
7 changes: 3 additions & 4 deletions src/wrappers/getBggForumlist.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
/* istanbul ignore file */
// TODO: get known what is it and test properly!

import { bggXmlApiClient } from '../client'

export interface BggForumlistParams {
id?: number
type?: 'thing' | 'family'
}

// TODO: specify this interface

export interface BggForumlistResponse {

[prop: string]: any
// TODO: specify this interface
[prop: string]: unknown
}

export function getBggForumlist(params: BggForumlistParams): Promise<BggForumlistResponse> {
Expand Down
42 changes: 39 additions & 3 deletions src/wrappers/getBggGeeklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,47 @@ export interface GeeklistParams {
comments?: OneOrNothing
}

// TODO: specify this interface
interface GeeklistItemComment {
text: string
username: string
date: string
postdate: string
editdate: string
thumbs: number
[prop: string]: unknown
}

export interface GeeklistResponse {

[prop: string]: any
geeklist: {
postdate: string
postdate_timestamp: number
editdate: string
editdate_timestamp: number
thumbs: number
numitems: number
username: string
title: string
description: string
item: {
body: string
comment: GeeklistItemComment | GeeklistItemComment[]
id: number
objecttype: 'thing' | string
subtype: 'boardgame' | 'boardgameaccessory' | string
objectid: number
objectname: string
username: string
postdate: string
editdate: string
thumbs: number
imageid: number
[prop: string]: unknown
}[]
id: number
termsofuse: string
[prop: string]: unknown
}
[prop: string]: unknown
}

export function getBggGeeklist(params: GeeklistParams): Promise<GeeklistResponse> {
Expand Down
34 changes: 30 additions & 4 deletions src/wrappers/getBggGuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,37 @@ export interface BggGuildParams {
page?: number
}

// TODO: specify this interface

export interface BggGuildResponse {

[prop: string]: any
guild: {
category: string
website: string
manager: string
description: string
location: {
addr1: string
addr2: string
city: string
stateorprovince: string
postalcode: string
country: string
[prop: string]: unknown
}
members: {
member: {
name: string
date: string
[prop: string]: unknown
}[]
count: number
page: number
}
id: number
name: string
created: string
termsofuse: string
[prop: string]: unknown
}
[prop: string]: unknown
}

export function getBggGuild(params: BggGuildParams): Promise<BggGuildResponse> {
Expand Down
18 changes: 14 additions & 4 deletions src/wrappers/getBggHot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { bggXmlApiClient } from '../client'
import type { OfValue } from '../types'

export interface BggHotParams {
type:
Expand All @@ -12,11 +13,20 @@ export interface BggHotParams {
| 'videogamecompany'
}

// TODO: specify this interface

export interface BggHotResponse {

[prop: string]: any
items: {
item: {
thumbnail: OfValue<string>
name: OfValue<string>
yearpublished?: OfValue<number>
id: number
rank: number
[prop: string]: unknown
}[]
termsofuse: string
[prop: string]: unknown
}
[prop: string]: unknown
}

export function getBggHot(params: BggHotParams): Promise<BggHotResponse> {
Expand Down
33 changes: 29 additions & 4 deletions src/wrappers/getBggPlays.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { bggXmlApiClient } from '../client'
import type { OfValue } from '../types'

export interface BggPlaysParams {
username?: string
Expand All @@ -10,11 +11,35 @@ export interface BggPlaysParams {
page?: number
}

// TODO: specify this interface

export interface BggPlaysResponse {

[prop: string]: any
plays: {
play: {
item: {
subtypes: {
subtype: OfValue<string> | OfValue<string>[]
}
name: string
objecttype: 'thing' | string
objectid: number
[prop: string]: unknown
}
id: number
date: string
quantity: number
length: number
incomplete: number
nowinstats: number
location: string
[prop: string]: unknown
}[]
username: string
userid: number
total: number
page: number
termsofuse: string
[prop: string]: unknown
}
[prop: string]: unknown
}

export function getBggPlays(params: BggPlaysParams): Promise<BggPlaysResponse> {
Expand Down
Loading

0 comments on commit 5f2bae6

Please sign in to comment.