Skip to content

Commit

Permalink
feat(*): moves the core data types out of common/types and into commo…
Browse files Browse the repository at this point in the history
…n/schema and introduces tsoa

this update touches a lot of files, but the interfaces from here on out should not be changing in
any way. the addition of the server.ts file is an attempt to address #4, using tsoa. testing and
refinements still need to be made on that front. the schema file is also a move in the direction of
having this file be generated by the sanity project biketag-games.
  • Loading branch information
KenEucker committed Dec 3, 2021
1 parent 5a4f523 commit d8ab3b9
Show file tree
Hide file tree
Showing 42 changed files with 2,738 additions and 1,942 deletions.
4,057 changes: 2,280 additions & 1,777 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"homepage": "https://keneucker.github.io/biketag-api/",
"scripts": {
"dev": "npm run dev:node",
"dev:build": "npm run build && npm run compile && npm run expose && npm run dev",
"dev:node": "node examples/node/index.js",
"dev:test": "jest examples/node/index.test.ts",
"dev:browser": "npm-run-all --parallel watch serve",
Expand Down Expand Up @@ -48,7 +49,7 @@
"lint:write": "prettier . --write && eslint . --fix",
"lint:staged": "npx --no-install lint-staged",
"commit": "cz",
"convert": "typeconv -f ts -t oapi -o openapi 'src/**/*.ts'",
"convert": "tsoa",
"remove-gun-log": "gun-annoyance-remove || true"
},
"dependencies": {
Expand Down Expand Up @@ -95,6 +96,7 @@
"ts-jest": "^27.0.7",
"ts-loader": "^9.1.1",
"ts-node": "^10.4.0",
"tsoa": "^3.14.1",
"typeconv": "^1.4.1",
"typescript": "^4.2.4",
"webpack": "^5.33.2",
Expand Down
3 changes: 2 additions & 1 deletion src/biketag/getQueue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getQueuePayload } from '../common/payloads'
import { BikeTagApiResponse, Tag } from '../common/types'
import { BikeTagApiResponse } from '../common/types'
import { Tag } from '../common/schema'
import { BikeTagGunClient } from '../common/types'
import { AvailableApis, HttpStatusCode } from '../common/enums'

Expand Down
3 changes: 2 additions & 1 deletion src/biketag/getTag.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getTagPayload } from '../common/payloads'
import { BikeTagApiResponse, Tag } from '../common/types'
import { BikeTagApiResponse } from '../common/types'
import { Tag } from '../common/schema'
import { BikeTagGunClient } from '../common/types'
import { AvailableApis, HttpStatusCode } from '../common/enums'

Expand Down
3 changes: 2 additions & 1 deletion src/biketag/getTags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getTagsPayload } from '../common/payloads'
import { BikeTagApiResponse, Tag } from '../common/types'
import { BikeTagApiResponse } from '../common/types'
import { Tag } from '../common/schema'
import { BikeTagGunClient } from '../common/types'
import { AvailableApis, HttpStatusCode } from '../common/enums'

Expand Down
3 changes: 2 additions & 1 deletion src/biketag/queueTagImage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BikeTagClient } from '../client'
import { Payload, BikeTagApiResponse, Tag } from '../common/types'
import { Payload, BikeTagApiResponse } from '../common/types'
import { Tag } from '../common/schema'
import { QUEUE_ENDPOINT } from '../common/endpoints'

export async function queueTagImage(
Expand Down
3 changes: 2 additions & 1 deletion src/biketag/updateTag.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { updateTagPayload } from '../common/payloads'
import { BikeTagApiResponse, Tag } from '../common/types'
import { BikeTagApiResponse } from '../common/types'
import { Tag } from '../common/schema'
import { BikeTagGunClient } from '../common/types'
import { AvailableApis, HttpStatusCode } from '../common/enums'

Expand Down
54 changes: 25 additions & 29 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { BIKETAG_API_PREFIX } from './common/endpoints'
import { Game, Tag, Player, Ambassador, Setting } from './common/schema'
import {
Credentials,
Tag,
Game,
BikeTagApiResponse,
ImgurCredentials,
SanityCredentials,
Expand All @@ -14,9 +13,6 @@ import {
TwitterCredentials,
BikeTagGunClient,
BikeTagGameState,
Player,
Ambassador,
Setting,
ApiOptions,
} from './common/types'
import {
Expand Down Expand Up @@ -88,21 +84,21 @@ export class BikeTagClient extends EventEmitter {
expressions: any = BikeTagExpressions
getters: any = BikeTagGetters

private fetcher: AxiosInstance
private plainFetcher: AxiosInstance
private cachedFetcher: AxiosInstance

private mostAvailableApi: AvailableApis
private biketagClient?: BikeTagGunClient
private imgurClient?: ImgurClient
private sanityClient?: SanityClient
private redditClient?: RedditClient
private twitterClient?: any
private sanityConfig?: SanityCredentials
private imgurConfig?: ImgurCredentials
private redditConfig?: RedditCredentials
private biketagConfig?: BikeTagCredentials
private twitterConfig?: TwitterCredentials
protected fetcher: AxiosInstance
protected plainFetcher: AxiosInstance
protected cachedFetcher: AxiosInstance

protected mostAvailableApi: AvailableApis
protected biketagClient?: BikeTagGunClient
protected imgurClient?: ImgurClient
protected sanityClient?: SanityClient
protected redditClient?: RedditClient
protected twitterClient?: any
protected sanityConfig?: SanityCredentials
protected imgurConfig?: ImgurCredentials
protected redditConfig?: RedditCredentials
protected biketagConfig?: BikeTagCredentials
protected twitterConfig?: TwitterCredentials

constructor(readonly configuration: Credentials | BikeTagConfiguration) {
super()
Expand Down Expand Up @@ -144,9 +140,9 @@ export class BikeTagClient extends EventEmitter {
})
}

/// **************************** Private Class Methods ******************************** ///
/// **************************** protected Class Methods ******************************** ///

private getInitialPayload(
protected getInitialPayload(
opts: any,
source?: AvailableApis | string,
method?: string
Expand Down Expand Up @@ -199,7 +195,7 @@ export class BikeTagClient extends EventEmitter {
return payload
}

private getDefaultOptions(
protected getDefaultOptions(
options: ApiOptions,
dataType: DataTypes = DataTypes.tag,
overrides: any = {}
Expand Down Expand Up @@ -274,7 +270,7 @@ export class BikeTagClient extends EventEmitter {
return { ...options, ...overrides }
}

private getClientAdapter(
protected getClientAdapter(
opts: any,
overrides: any = {},
dataType: DataTypes = DataTypes.tag,
Expand Down Expand Up @@ -317,7 +313,7 @@ export class BikeTagClient extends EventEmitter {
}
}

private getMostAvailableClient(method?: string): AvailableApis {
protected getMostAvailableClient(method?: string): AvailableApis {
if (this.mostAvailableApi && !method) {
return this.mostAvailableApi
}
Expand Down Expand Up @@ -373,7 +369,7 @@ export class BikeTagClient extends EventEmitter {
return null
}

private getPassthroughApiMethod(
protected getPassthroughApiMethod(
method: any,
client:
| RedditClient
Expand All @@ -390,7 +386,7 @@ export class BikeTagClient extends EventEmitter {
}
}

private getConfig(config?: BikeTagConfiguration): BikeTagConfiguration {
protected getConfig(config?: BikeTagConfiguration): BikeTagConfiguration {
return {
biketag: config?.biketag ?? this.biketagConfig,
sanity: config?.sanity ?? this.sanityConfig,
Expand All @@ -400,7 +396,7 @@ export class BikeTagClient extends EventEmitter {
} as BikeTagConfiguration
}

private initializeClients(
protected initializeClients(
config?: BikeTagConfiguration
): BikeTagConfiguration {
config = config ?? this.config()
Expand Down Expand Up @@ -911,7 +907,7 @@ export class BikeTagClient extends EventEmitter {
deleteTags(
payload: RequireAtLeastOne<deleteTagsPayload> | number[],
opts?: RequireAtLeastOne<Credentials>
): Promise<BikeTagApiResponse<any>> {
): Promise<BikeTagApiResponse<boolean[]>> {
const { client, options, api, source } = this.getClientAdapter(
payload,
opts,
Expand Down
2 changes: 1 addition & 1 deletion src/common/data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tag, Game, Player, Ambassador, Setting } from './types'
import { Tag, Game, Player, Ambassador, Setting } from './schema'

export const cacheKeys = {
sanityUrlText: `sanity::`,
Expand Down
3 changes: 2 additions & 1 deletion src/common/getters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { geopoint, Tag } from './types'
import { geopoint } from './types'
import {
getTagnumberFromSlugRegex,
getTagNumbersFromTextRegex,
Expand All @@ -15,6 +15,7 @@ import {
import { getCacheIfExists, putCacheIfExists } from '../common/methods'
import { cacheKeys } from '../common/data'
import TinyCache from 'tinycache'
import { Tag } from './schema'

export const getTagnumberFromSlug = (
inputText: string,
Expand Down
6 changes: 1 addition & 5 deletions src/common/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@ import {
BikeTagConfiguration,
CommonData,
TwitterCredentials,
Tag,
Player,
RequireAtLeastOne,
Ambassador,
Setting,
Game,
} from './types'
import FormData from 'form-data'
import TinyCache from 'tinycache'
import { USERAGENT } from '../client'
import { Tag, Game, Player, Ambassador, Setting } from './schema'

export const putCacheIfExists = (
key: string,
Expand Down
47 changes: 17 additions & 30 deletions src/common/payloads.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CommonData, RequireAtLeastOne, Tag } from './types'
import { Tag } from './schema'
import { CommonData, RequireAtLeastOne } from './types'

export type getTagsPayload = {
fields?: string[]
Expand All @@ -10,21 +11,18 @@ export type getTagsPayload = {
sort?: 'new' | 'relevance' | 'hot' | 'top' | 'comments'
limit?: number
tagnumbers: number[]
game: string
}
} & CommonData

export type deleteTagPayload = {
slug?: string
tagnumber?: string
game?: string
}
} & CommonData

export type deleteTagsPayload = {
slugs?: string[]
tagnumbers: number[]
tags?: Partial<Tag>[]
game: string
}
} & CommonData

export type getTagPayload = {
tagnumber: number
Expand All @@ -34,22 +32,20 @@ export type getTagPayload = {
hash?: string
subreddit?: string
account?: string
game: string
slug: string
fields?: string[]
}
} & CommonData

export type updateTagPayload = {
tag: RequireAtLeastOne<Tag>
game: string
}
} & CommonData

export type uploadTagImagePayload = {
tagnumber: number
type: 'found' | 'mystery'
slug?: string
stream: ReadableStream
}
} & CommonData

export type ImgurUploadPayload = {
image: string
Expand All @@ -64,7 +60,7 @@ export type getGamePayload = {
slug: string
name: string
fields?: string[]
}
} & CommonData

export type getPlayersPayload = {
fields?: string[]
Expand All @@ -73,47 +69,38 @@ export type getPlayersPayload = {
hash?: string
account?: string
subreddit?: string
game: string
}
} & CommonData

export type getPlayerPayload = {
fields?: string[]
slug?: string
hash?: string
account?: string
subreddit?: string
game: string
}
} & CommonData

export type getSettingPayload = {
fields?: string[]
slug?: string
game: string
}
} & CommonData

export type getSettingsPayload = {
fields?: string[]
slugs?: string[]
game: string
}
} & CommonData

export type getAmbassadorsPayload = {
fields?: string[]
slugs?: string[]
game: string
}
} & CommonData
export type getAmbassadorPayload = {
fields?: string[]
slug?: string
game: string
}
} & CommonData

export type importTagPayload = Pick<
Tag,
| 'discussionUrl'
| 'mysteryImageUrl'
| 'foundImageUrl'
| 'mentionUrl'
| 'shareUrl'
'discussionUrl' | 'mysteryImageUrl' | 'foundImageUrl' | 'mentionUrl'
> &
CommonData

Expand Down
Loading

0 comments on commit d8ab3b9

Please sign in to comment.