diff --git a/core/token-pooling/token-provider.js b/core/token-pooling/token-provider.js deleted file mode 100644 index 95d40269e3b810aecc38f886a953e6739f63b711..0000000000000000000000000000000000000000 --- a/core/token-pooling/token-provider.js +++ /dev/null @@ -1,66 +0,0 @@ -'use strict' - -const { Token, TokenPool } = require('./token-pool') - -class StaticTokenProvider { - constructor({ tokenValidator, tokenString }) { - if (typeof tokenValidator !== 'function') { - throw Error('tokenValidator is not a function') - } - if (!tokenValidator(tokenString)) { - throw Error(`Not a valid token: ${tokenString}`) - } - - this.staticToken = new Token(tokenString, null) - } - - addToken() { - throw Error( - 'When using token persistence, do not provide a static gh_token' - ) - } - - nextToken() { - return this.staticToken - } -} - -class PoolingTokenProvider { - /* - tokenValidator: A function which returns true if the argument is a valid token. - */ - constructor({ tokenValidator, batchSize = 25 }) { - if (typeof tokenValidator !== 'function') { - throw Error('tokenValidator is not a function') - } - - this.tokenValidator = tokenValidator - this.tokenPool = new TokenPool({ batchSize }) - } - - addToken(tokenString) { - if (!this.tokenValidator(tokenString)) { - throw Error(`Not a valid token: ${tokenString}`) - } - - this.tokenPool.add(tokenString) - } - - nextToken() { - return this.tokenPool.next() - } - - // Return an array of token strings. - toNative() { - return this.tokenPool.allValidTokenIds() - } - - serializeDebugInfo(options) { - return this.tokenPool.serializeDebugInfo(options) - } -} - -module.exports = { - StaticTokenProvider, - PoolingTokenProvider, -} diff --git a/core/token-pooling/token-provider.spec.js b/core/token-pooling/token-provider.spec.js deleted file mode 100644 index 2647a785f34e8dab7d9ca7bb03f5c86aeecea5b0..0000000000000000000000000000000000000000 --- a/core/token-pooling/token-provider.spec.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict' - -const assert = require('assert') -const { PoolingTokenProvider } = require('./token-provider') -const isValidGithubToken = require('../../services/github/auth/is-valid-token') - -describe('The token provider', function() { - describe('toNative', function() { - it('should return the expected value', function() { - const tokens = ['1', '2', '3', '4', '5'].map(c => c.repeat(40)) - const provider = new PoolingTokenProvider({ - tokenValidator: isValidGithubToken, - }) - tokens.forEach(t => provider.addToken(t)) - assert.deepStrictEqual( - provider.toNative().sort(), - Array.from(tokens).sort() - ) - }) - }) -})