Skip to content

Commit

Permalink
Remove necessity for babel compilation step
Browse files Browse the repository at this point in the history
  • Loading branch information
queicherius committed Oct 4, 2018
1 parent d0c7e3b commit f4b0e39
Show file tree
Hide file tree
Showing 113 changed files with 313 additions and 331 deletions.
7 changes: 1 addition & 6 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
{
"presets": [
["env", {"targets": {"browsers": ["last 2 versions", "> 5%"], "node": 6}, "loose": true}],
"stage-0"
],
"env": {
"test": {
"plugins": [
["istanbul", {"include": ["src/**"]}],
"rewire"
]
}
}
}
}
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ npm-debug.log*

# Coverage directories
coverage/
.nyc_output/

# Compiled code
build/

# Dependencies
node_modules/
Expand All @@ -19,4 +15,4 @@ node_modules/

# Operating System
.DS_Store
Thumbs.db
Thumbs.db
22 changes: 0 additions & 22 deletions .npmignore

This file was deleted.

9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
language: node_js
node_js:
- "6"
after_script: "$(npm bin)/codecov"
- "8"
script:
- npm run test -- --coverage
- npm run lint
after_script: "curl -s https://codecov.io/bash | bash"
branches:
only:
- master
- /^greenkeeper.*$/
services:
- redis-server
- redis-server
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This module can be used for Node.js as well as browsers using [Browserify](https
### Basic usage

```js
import client from 'gw2api-client'
const client = require('gw2api-client')

// Get an instance of an API client
let api = client()
Expand Down Expand Up @@ -53,7 +53,7 @@ api.items().all().then(items => console.log(items))
By default, calling any endpoint requests data from the live API. However, you can easily enable caching for all appropriate endpoints by giving the client a cache storage to work with. You can find the default cache times of all endpoints [here](./docs/endpoints.md).

```js
import cacheMemory from 'gw2api-client/build/cache/memory'
const cacheMemory = require('gw2api-client/build/cache/memory')
api.cacheStorage(cacheMemory())

// This will only call the official API once
Expand All @@ -73,8 +73,8 @@ api.items().live().ids()
You can also chain multiple cache storages together. In this case, the cache gets saved in all storages and read from the first storage in the list answering with a valid value. The more persistent and more reliable cache storages should therefore be on the end of the list and the fastest (e.g. memory) should be at the start of the list.

```js
import cacheMemory from 'gw2api-client/build/cache/memory'
import cacheRedisStorage from 'gw2api-client/build/cache/redis'
const cacheMemory = require('gw2api-client/build/cache/memory')
const cacheRedisStorage = require('gw2api-client/build/cache/redis')

// Save in memory and local storage
// Try to answer from memory first, then from local storage and then hit the API
Expand Down Expand Up @@ -150,8 +150,8 @@ You can extend or overwrite the API client with your own endpoints if you wish s
If you need more specific ways to handle data then the already defined ones, take a look at how the existing endpoints handle these edge cases (e.g. in [`/src/endpoints/recipes.js`](/src/endpoints/recipes.js)).

```js
import client from 'gw2api-client'
import AbstractEndpoint from 'gw2api-client/build/endpoint'
const client = require('gw2api-client')
const AbstractEndpoint = require('gw2api-client/build/endpoint')

// Get an instance of an API client
const api = client()
Expand Down Expand Up @@ -192,8 +192,8 @@ api.items().many([123, 456])
If you want to mock this module in your tests, you can replace the underlying `lets-fetch` library with the provided mock module, e.g. using [rewire](https://github.com/speedskater/babel-plugin-rewire). You can find all available mock methods [here](https://github.com/queicherius/lets-fetch#mocking).

```js
import fetchMock from 'lets-fetch/mock'
import file from './some/file/using/gw2api/client.js'
const fetchMock = require('lets-fetch/mock')
const file = require('./some/file/using/gw2api/client.js')

// Get the variable "api" (which would be the initialized api client
// in your own code) and replace the fetch method with the fetchMock
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
"name": "gw2api-client",
"version": "6.1.1",
"description": "A javascript wrapper around the official Guild Wars 2 API",
"main": "./build/index.js",
"main": "./src/index.js",
"scripts": {
"build": "abc build",
"test": "jest --runInBand --forceExit && abc lint",
"version": "abc build"
"test": "jest --runInBand --forceExit",
"lint": "abc lint"
},
"author": "[email protected]",
"license": "MIT",
Expand Down
13 changes: 6 additions & 7 deletions src/cache/browser.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import debounce from 'debounce'
import * as idbKeyval from 'idb-keyval'
const debounce = require('debounce')
const idbKeyval = require('idb-keyval')

export default function (configuration) {
configuration = {
module.exports = function (configuration) {
configuration = Object.assign({
storageKey: 'gw2api-cache',
gcTick: 5 * 60 * 1000,
persistDebounce: 3 * 1000,
storageEngine: idbKeyval,
...configuration
}
storageEngine: idbKeyval
}, configuration)

let _storage = {}
const storageEngine = configuration.storageEngine
Expand Down
6 changes: 4 additions & 2 deletions src/cache/memory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export default function (configuration) {
configuration = {gcTick: 5 * 60 * 1000, ...configuration}
module.exports = function (configuration) {
configuration = Object.assign({
gcTick: 5 * 60 * 1000
}, configuration)

// Scope the storage to the function, so multiple instances don't interfere
let _storage = {}
Expand Down
2 changes: 1 addition & 1 deletion src/cache/null.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function () {
module.exports = function () {
return {get, set, mget, mset, flush}
}

Expand Down
6 changes: 4 additions & 2 deletions src/cache/redis.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export default function (configuration) {
configuration = {prefix: 'gw2api-', ...configuration}
module.exports = function (configuration) {
configuration = Object.assign({
prefix: 'gw2api-',
}, configuration)

if (!configuration.redis) {
throw new Error('The `redis` cache storage requires a `redis` instance')
Expand Down
12 changes: 6 additions & 6 deletions src/client.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import fetch from 'lets-fetch'
import flow from 'promise-control-flow'
import debugging from 'debug'
import nullCache from './cache/null'
import * as endpoints from './endpoints'
const fetch = require('lets-fetch')
const flow = require('promise-control-flow')
const debugging = require('debug')
const nullCache = require('./cache/null')
const endpoints = require('./endpoints')
const debug = debugging('gw2api-client')

export default class Client {
module.exports = class Client {
constructor () {
this.lang = 'en'
this.apiKey = false
Expand Down
14 changes: 7 additions & 7 deletions src/endpoint.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import parseUrl from 'url-parse'
import unique from 'array-unique'
import Rusha from 'rusha'
import clone from 'fast-clone'
import chunk from 'chunk'
import debugging from 'debug'
const parseUrl = require('url-parse')
const unique = require('array-unique')
const Rusha = require('rusha')
const clone = require('fast-clone')
const chunk = require('chunk')
const debugging = require('debug')
const sha = (s) => (new Rusha()).digestFromString(s)
const debug = debugging('gw2api-client')
const debugRequest = debugging('gw2api-client:request')

export default class AbstractEndpoint {
module.exports = class AbstractEndpoint {
constructor (parent) {
this.lang = parent.lang
this.apiKey = parent.apiKey
Expand Down
15 changes: 9 additions & 6 deletions src/endpoints/account-blob.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import flow from 'promise-control-flow'
import flat from 'flat'
import _get from 'fast-get'
import api from '../index.js'
const flow = require('promise-control-flow')
const flat = require('flat')
const _get = require('fast-get')
const api = require('../index.js')

export default function (parent) {
function blob (parent) {
const client = api()
.authenticate(parent.apiKey)
.language(parent.lang)
Expand Down Expand Up @@ -91,7 +91,7 @@ function filterBetaCharacters (characters) {
// Wrap a promise function so all errors that have to do with the API
// just result in an empty response instead of throwing an error
// This prevents API errors / changes breaking the entire infrastructure
export function wrap (func) {
function wrap (func) {
return () => new Promise((resolve, reject) => {
func()
.then(x => resolve(x))
Expand All @@ -108,3 +108,6 @@ export function wrap (func) {
})
})
}

module.exports = blob
module.exports.wrap = wrap
12 changes: 6 additions & 6 deletions src/endpoints/account.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import AbstractEndpoint from '../endpoint'
import CharactersEndpoint from './characters'
import PvpEndpoint from './pvp'
import CommerceEndpoint from './commerce'
import accountBlob from './account-blob.js'
const AbstractEndpoint = require('../endpoint')
const CharactersEndpoint = require('./characters')
const PvpEndpoint = require('./pvp')
const CommerceEndpoint = require('./commerce')
const accountBlob = require('./account-blob.js')

export default class AccountEndpoint extends AbstractEndpoint {
module.exports = class AccountEndpoint extends AbstractEndpoint {
constructor (client) {
super(client)
this.url = '/v2/account'
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/achievements.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AbstractEndpoint from '../endpoint'
const AbstractEndpoint = require('../endpoint')

export default class AchievementsEndpoint extends AbstractEndpoint {
module.exports = class AchievementsEndpoint extends AbstractEndpoint {
constructor (client) {
super(client)
this.url = '/v2/achievements'
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/backstory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AbstractEndpoint from '../endpoint'
const AbstractEndpoint = require('../endpoint')

export default class BackstoryEndpoint extends AbstractEndpoint {
module.exports = class BackstoryEndpoint extends AbstractEndpoint {
answers () {
return new AnswersEndpoint(this)
}
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AbstractEndpoint from '../endpoint'
const AbstractEndpoint = require('../endpoint')

export default class BuildEndpoint extends AbstractEndpoint {
module.exports = class BuildEndpoint extends AbstractEndpoint {
constructor (client) {
super(client)
this.url = '/v2/build'
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/cats.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AbstractEndpoint from '../endpoint'
const AbstractEndpoint = require('../endpoint')

export default class CatsEndpoint extends AbstractEndpoint {
module.exports = class CatsEndpoint extends AbstractEndpoint {
constructor (client) {
super(client)
this.url = '/v2/cats'
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/characters.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AbstractEndpoint from '../endpoint'
const AbstractEndpoint = require('../endpoint')

export default class CharactersEndpoint extends AbstractEndpoint {
module.exports = class CharactersEndpoint extends AbstractEndpoint {
constructor (client, name) {
super(client)
this.name = name
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/colors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AbstractEndpoint from '../endpoint'
const AbstractEndpoint = require('../endpoint')

export default class ColorsEndpoint extends AbstractEndpoint {
module.exports = class ColorsEndpoint extends AbstractEndpoint {
constructor (client) {
super(client)
this.url = '/v2/colors'
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/commerce.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AbstractEndpoint from '../endpoint'
const AbstractEndpoint = require('../endpoint')

export default class CommerceEndpoint extends AbstractEndpoint {
module.exports = class CommerceEndpoint extends AbstractEndpoint {
// Current things to grab in the delivery box
delivery () {
return new DeliveryEndpoint(this)
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/continents.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AbstractEndpoint from '../endpoint'
const AbstractEndpoint = require('../endpoint')

export default class ContinentsEndpoint extends AbstractEndpoint {
module.exports = class ContinentsEndpoint extends AbstractEndpoint {
constructor (client) {
super(client)
this.url = '/v2/continents'
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/currencies.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AbstractEndpoint from '../endpoint'
const AbstractEndpoint = require('../endpoint')

export default class CurrenciesEndpoint extends AbstractEndpoint {
module.exports = class CurrenciesEndpoint extends AbstractEndpoint {
constructor (client) {
super(client)
this.url = '/v2/currencies'
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/dungeons.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AbstractEndpoint from '../endpoint'
const AbstractEndpoint = require('../endpoint')

export default class DungeonsEndpoint extends AbstractEndpoint {
module.exports = class DungeonsEndpoint extends AbstractEndpoint {
constructor (client) {
super(client)
this.url = '/v2/dungeons'
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/emblem.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AbstractEndpoint from '../endpoint'
const AbstractEndpoint = require('../endpoint')

export default class EmblemEndpoint extends AbstractEndpoint {
module.exports = class EmblemEndpoint extends AbstractEndpoint {
backgrounds () {
return new LayersEndpoint(this, 'backgrounds')
}
Expand Down
6 changes: 3 additions & 3 deletions src/endpoints/events.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AbstractEndpoint from '../endpoint'
const AbstractEndpoint = require('../endpoint')

export default class EventsEndpoint extends AbstractEndpoint {
module.exports = class EventsEndpoint extends AbstractEndpoint {
constructor (client) {
super(client)
this.url = '/v1/event_details.json'
Expand All @@ -22,7 +22,7 @@ function transformV1Format (json) {
const keys = Object.keys(events)

for (let i = 0; i !== keys.length; i++) {
transformed.push({id: keys[i], ...events[keys[i]]})
transformed.push(Object.assign({id: keys[i]}, events[keys[i]]))
}

return transformed
Expand Down
Loading

0 comments on commit f4b0e39

Please sign in to comment.