@athletes.gg/agg-sdk
Advanced tools
Comparing version 3.0.0-alpha.1 to 3.0.0-alpha.2
@@ -6,11 +6,20 @@ /// <reference types="socket.io-client" /> | ||
interface ClientOptions { | ||
pageLimit?: number; | ||
pageSizeLimit?: number; | ||
storage?: Storage; | ||
timeout?: number; | ||
tryLimit?: number; | ||
url: string; | ||
} | ||
declare class Client implements ClientOptions { | ||
static DEFAULT_PAGE_LIMIT: number; | ||
static DEFAULT_PAGE_SIZE_LIMIT: number; | ||
static DEFAULT_TIMEOUT: number; | ||
static DEFAULT_TRY_LIMIT: number; | ||
readonly app: Application; | ||
readonly socket: SocketIOClient.Socket; | ||
private _pageLimit; | ||
private _pageSizeLimit; | ||
private _timeout; | ||
private _tryLimit; | ||
private _url; | ||
@@ -46,3 +55,4 @@ authManagement: Service<any>; | ||
getUsers(query: Query): Promise<Record<string, unknown>[]>; | ||
findPaginate(service: string, buildQuery: (lastItem?: Record<string, unknown>) => Query, job: (data?: Record<string, unknown>[]) => Promise<void> | void, pageLimit?: number, lastItem?: Record<string, unknown>, tries?: number, pages?: number): Promise<void>; | ||
} | ||
export default Client; |
import feathers from '@feathersjs/feathers'; | ||
import authentication, { defaultStorage, } from '@feathersjs/authentication-client'; | ||
import _ from 'lodash'; | ||
import socketio from '@feathersjs/socketio-client'; | ||
@@ -7,6 +8,9 @@ import io from 'socket.io-client'; | ||
constructor(options) { | ||
const { storage = defaultStorage, timeout = Client.DEFAULT_TIMEOUT, url, } = options; | ||
const { pageLimit = Client.DEFAULT_PAGE_LIMIT, pageSizeLimit = Client.DEFAULT_PAGE_SIZE_LIMIT, storage = defaultStorage, timeout = Client.DEFAULT_TIMEOUT, tryLimit = Client.DEFAULT_TRY_LIMIT, url, } = options; | ||
this._pageLimit = pageLimit; | ||
this._pageSizeLimit = pageSizeLimit; | ||
this._url = url; | ||
this._timeout = timeout; | ||
this._tryLimit = tryLimit; | ||
this.socket = io(this._url); | ||
this._timeout = timeout; | ||
this.app = feathers(); | ||
@@ -89,5 +93,33 @@ this.app | ||
} | ||
async findPaginate(service, buildQuery, job, pageLimit = this._pageLimit, lastItem, tries = 0, pages = 1) { | ||
const query = { | ||
$limit: this._pageSizeLimit, | ||
...buildQuery(lastItem), | ||
}; | ||
try { | ||
const data = await this.getService(service).find({ | ||
query, | ||
}); | ||
await job(data); | ||
if (data.length < this._pageSizeLimit) { | ||
return; | ||
} | ||
if (pages >= pageLimit) { | ||
return; | ||
} | ||
return this.findPaginate(service, buildQuery, job, pageLimit, _.last(data), 0, pages + 1); | ||
} | ||
catch (error) { | ||
if (tries >= this._tryLimit) { | ||
throw error; | ||
} | ||
return this.findPaginate(service, buildQuery, job, pageLimit, lastItem, tries + 1, pages); | ||
} | ||
} | ||
} | ||
Client.DEFAULT_PAGE_LIMIT = 5; | ||
Client.DEFAULT_PAGE_SIZE_LIMIT = 50; | ||
Client.DEFAULT_TIMEOUT = 3000; | ||
Client.DEFAULT_TRY_LIMIT = 3; | ||
export default Client; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@athletes.gg/agg-sdk", | ||
"version": "3.0.0-alpha.1", | ||
"version": "3.0.0-alpha.2", | ||
"description": "The SDK for Athletes.gg.", | ||
@@ -19,6 +19,6 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@feathersjs/authentication": "^4.5.10", | ||
"@feathersjs/authentication-client": "^4.5.10", | ||
"@feathersjs/feathers": "^4.5.10", | ||
"@feathersjs/socketio-client": "^4.5.10", | ||
"@feathersjs/authentication": "^4.5.11", | ||
"@feathersjs/authentication-client": "^4.5.11", | ||
"@feathersjs/feathers": "^4.5.11", | ||
"@feathersjs/socketio-client": "^4.5.11", | ||
"debug": "^4.3.1", | ||
@@ -30,18 +30,19 @@ "lodash": "^4.17.20", | ||
"devDependencies": { | ||
"@types/jest": "^26.0.16", | ||
"@types/jest": "^26.0.19", | ||
"@types/lodash": "^4.14.166", | ||
"@types/socket.io-client": "^1.4.34", | ||
"@typescript-eslint/eslint-plugin": "^4.9.0", | ||
"@typescript-eslint/parser": "^4.9.0", | ||
"@typescript-eslint/eslint-plugin": "^4.11.1", | ||
"@typescript-eslint/parser": "^4.11.1", | ||
"codecov": "^3.8.1", | ||
"eslint": "^7.14.0", | ||
"eslint": "^7.16.0", | ||
"eslint-plugin-jest": "^24.1.3", | ||
"eslint-plugin-sort-destructure-keys": "^1.3.5", | ||
"husky": "^4.3.0", | ||
"husky": "^4.3.6", | ||
"jest": "^26.6.3", | ||
"jest-junit": "^12.0.0", | ||
"jest-localstorage-mock": "^2.4.3", | ||
"lint-staged": "^10.5.2", | ||
"jest-localstorage-mock": "^2.4.6", | ||
"lint-staged": "^10.5.3", | ||
"socket.io-mock": "^1.3.1", | ||
"ts-jest": "^26.4.4", | ||
"typescript": "^4.1.2" | ||
"typescript": "^4.1.3" | ||
}, | ||
@@ -48,0 +49,0 @@ "husky": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12461
180
17