Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript Conversion #75

Draft
wants to merge 72 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
a0c6cdc
Add basic TS setup
ogrady Apr 22, 2023
f4afd52
Add node types as dev dependency
ogrady Apr 22, 2023
b649f20
Start migration on endpoints and smaller files
ogrady Apr 22, 2023
4eeef21
Add type safety for worlds, teams, matchups
ogrady Apr 22, 2023
e68e24f
Convert world endpoint
ogrady Apr 22, 2023
bb3178f
Convert all js endpoints to ts
ogrady Apr 22, 2023
a7dbc29
Remove superfluous explicit return types and public modifiers
ogrady Apr 22, 2023
4df8695
Move generic parameter from get() et al. to AbstractEndpoint
ogrady Apr 23, 2023
02f4998
Define result types for achievement enpoints
ogrady Apr 23, 2023
65122e8
Add backstory types
ogrady Apr 23, 2023
db28cc7
Add result types for build endpoint
ogrady Apr 23, 2023
a444ed6
Add color reponse type
ogrady Apr 23, 2023
a08d3b1
Add dungeons endpoint
ogrady Apr 24, 2023
e5b2597
Add continent endpoint
ogrady Apr 24, 2023
353c7b1
Add currency endpoint
ogrady Apr 24, 2023
3f0d347
Add daily crafting endpoint
ogrady Apr 24, 2023
81362ef
Add new schema logic and migrate several endpoints (WIP)
ogrady Apr 24, 2023
cac10eb
Change chaining result type to this
ogrady May 3, 2023
6f2816c
Pivot type distribution
ogrady May 3, 2023
1374de0
Move all exports from schema_1970_* to their respective namespaces
ogrady May 3, 2023
96d09bb
Add some documentation and add dailycrafting
ogrady May 3, 2023
d5fd148
Make dungeon types more solid
ogrady May 3, 2023
9f3cd4b
Add currencies endpoint response
ogrady May 3, 2023
f687e75
Quickfix some compilation errors for review
ogrady May 3, 2023
b39edcb
Fix some compile errors
ogrady May 3, 2023
eb3dae9
Remove neccessity to re-declare every response via Omit
ogrady May 4, 2023
2f81373
Add emblem response
ogrady May 4, 2023
6926ad6
Add titles response
ogrady May 4, 2023
502f173
Add titles and skins
ogrady May 4, 2023
e63a880
Add tokeninfo
ogrady May 4, 2023
27f4794
Add nodes response
ogrady May 4, 2023
b1a71c2
Add minis response
ogrady May 4, 2023
d6bbe36
Add commerce and mailcarrier responses
ogrady May 4, 2023
115264e
Rename output directory from built/ to dist/
ogrady May 7, 2023
e718502
Add finishers endpoint response
ogrady May 7, 2023
ce8f611
Add legends endpoint reponse
ogrady May 7, 2023
b844d04
Fix a few compile errors
ogrady May 7, 2023
c4a17bc
Remove nominal types from `get`
ogrady May 7, 2023
e00ddc6
Remove some stale types
ogrady May 7, 2023
021a594
Add traits endpoint response
ogrady May 7, 2023
8acaf74
Add races endpoint response
ogrady May 26, 2023
7b92130
Add quaggans endpoint response
ogrady May 26, 2023
54129cd
Add novelties endpoint response
ogrady May 26, 2023
b861fb9
Add outfits response
ogrady May 26, 2023
6ae6435
Add pets response
ogrady May 26, 2023
9750d81
Add profession responses
ogrady May 26, 2023
6fbb897
Add files response
ogrady May 26, 2023
1eecb8d
Fix typo
ogrady May 26, 2023
f0dfaf5
Add idea.txt
ogrady May 27, 2023
7c5177c
Revert
ogrady May 27, 2023
160537c
Add mastery response
ogrady May 27, 2023
f284a7f
Add mounts response
ogrady May 27, 2023
7853cf4
Add raids response
ogrady May 28, 2023
988a0ee
Add mapchests response
ogrady May 28, 2023
32250e9
Add legendaryarmory response
ogrady May 29, 2023
cb62010
Move cats and nodes to home
ogrady May 29, 2023
1f8dd21
Add worldbosses response
ogrady May 29, 2023
8f9a896
Add world response
ogrady May 29, 2023
43662d8
Add quest response
ogrady May 29, 2023
287ad27
Add stories response
ogrady May 29, 2023
fbd115a
Add account response
ogrady Jun 3, 2023
6ea5c27
Add specializaations response
ogrady Jun 3, 2023
7647917
Add materials responses
ogrady Jun 3, 2023
9a36f21
Add response for guild enpoints
ogrady Jun 23, 2023
682ba2d
Add some of characters response
ogrady Jun 24, 2023
e4ecd2e
Add missing characters endpoint responses
ogrady Jun 24, 2023
5cdb556
Add endpoint response for skills
ogrady Jul 8, 2023
3fe9291
Add endpoint responses for event details
ogrady Jul 9, 2023
7a14f61
Add respnses for items
ogrady Jul 22, 2023
96d0ef2
Add itemstats response
ogrady Jul 28, 2023
fc57c41
Add maps endpoint
ogrady Aug 4, 2023
5113853
Add response schema for wvw
ogrady Aug 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist/
# Logs
npm-debug.log*

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"querystringify": "^2.0.0"
},
"devDependencies": {
"@types/node": "^18.15.13",
"babel-plugin-rewire": "^1.2.0",
"jest": "^23.6.0",
"mockdate": "^2.0.2",
Expand Down
44 changes: 25 additions & 19 deletions src/client.js → src/client.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,60 @@
const fetch = require('lets-fetch')
const nullCache = require('./cache/null')
const endpoints = require('./endpoints')
import * as endpoints from './endpoints/index'
import { Schema } from './endpoints/schemas/schema'
import { Language } from './types'
const flow = require('./flow')

module.exports = class Client {
export class Client<S extends Schema> {
private schemaVersion = '2019-03-20T00:00:00.000Z'
private lang: Language = 'en'
private fetch = fetch
private caches = [nullCache()]
private debug = false
private client: Client<S>
private apiKey: string

constructor () {
this.schemaVersion = '2019-03-20T00:00:00.000Z'
this.lang = 'en'
this.apiKey = false
this.fetch = fetch
this.caches = [nullCache()]
this.debug = false
this.client = this
}

// Set the schema version
schema (schema) {
schema (schema: string) {
this.schemaVersion = schema
this.debugMessage(`set the schema to ${schema}`)
return this
}

// Set the language for locale-aware endpoints
language (lang) {
language (lang: Language) {
this.lang = lang
this.debugMessage(`set the language to ${lang}`)
return this
}

// Set the api key for authenticated endpoints
authenticate (apiKey) {
authenticate (apiKey: string) {
this.apiKey = apiKey
this.debugMessage(`set the api key to ${apiKey}`)
return this
}

// Set the caching storage method(s)
cacheStorage (caches) {
// FIXME: type
cacheStorage (caches: any[]) {
this.caches = [].concat(caches)
this.debugMessage(`updated the cache storage`)
return this
}

// Set the debugging flag
debugging (flag) {
debugging (flag: boolean) {
this.debug = flag
return this
}

// Print out a debug message if debugging is enabled
debugMessage (string) {
debugMessage (string: string) {
if (this.debug) {
console.log(`[gw2api-client] ${string}`)
}
Expand Down Expand Up @@ -81,15 +86,15 @@ module.exports = class Client {

// All the different API endpoints
account () {
return new endpoints.AccountEndpoint(this)
return new endpoints.AccountEndpoint<S>(this)
}

achievements () {
return new endpoints.AchievementsEndpoint(this)
return new endpoints.AchievementsEndpoint<S>(this)
}

backstory () {
return new endpoints.BackstoryEndpoint(this)
return new endpoints.BackstoryEndpoint<S>(this)
}

build () {
Expand Down Expand Up @@ -221,7 +226,8 @@ module.exports = class Client {
}

pvp () {
return new endpoints.PvpEndpoint(this)
// FIXME: bug? No fromAccount argument was originally provided, so it always behaved falsey
return new endpoints.PvpEndpoint(this, false)
}
Comment on lines 228 to 231
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


quaggans () {
Expand Down Expand Up @@ -283,4 +289,4 @@ module.exports = class Client {
wvw () {
return new endpoints.WvwEndpoint(this)
}
}
}
Loading