@google-cloud/paginator
Advanced tools
Comparing version 0.1.2 to 0.2.0
@@ -18,3 +18,3 @@ /*! | ||
import { Transform, TransformOptions } from 'stream'; | ||
interface CreateLimiterOptions { | ||
export interface CreateLimiterOptions { | ||
/** | ||
@@ -29,2 +29,15 @@ * The maximum number of API calls to make. | ||
} | ||
export interface Limiter { | ||
makeRequest(...args: any[]): Transform | undefined; | ||
stream: Transform; | ||
} | ||
export declare type ResourceStream<T> = { | ||
addListener(event: 'data', listener: (data: T) => void): ResourceStream<T>; | ||
emit(event: 'data', data: T): boolean; | ||
on(event: 'data', listener: (data: T) => void): ResourceStream<T>; | ||
once(event: 'data', listener: (data: T) => void): ResourceStream<T>; | ||
prependListener(event: 'data', listener: (data: T) => void): ResourceStream<T>; | ||
prependOnceListener(event: 'data', listener: (data: T) => void): ResourceStream<T>; | ||
removeListener(event: 'data', listener: (data: T) => void): ResourceStream<T>; | ||
} & Transform; | ||
/** | ||
@@ -38,6 +51,3 @@ * Limit requests according to a `maxApiCalls` limit. | ||
*/ | ||
export declare function createLimiter(makeRequestFn: Function, options?: CreateLimiterOptions): { | ||
makeRequest(...args: any[]): Transform | undefined; | ||
stream: Transform; | ||
}; | ||
export declare function createLimiter(makeRequestFn: Function, options?: CreateLimiterOptions): Limiter; | ||
export interface ParsedArguments extends TransformOptions { | ||
@@ -106,5 +116,5 @@ /** | ||
*/ | ||
streamify(methodName: string): (this: { | ||
streamify<T = any>(methodName: string): (this: { | ||
[index: string]: Function; | ||
}, ...args: any[]) => any; | ||
}, ...args: any[]) => ResourceStream<T>; | ||
/** | ||
@@ -133,3 +143,3 @@ * Parse a pseudo-array `arguments` for a query and callback. | ||
*/ | ||
run_(parsedArguments: ParsedArguments, originalMethod: Function): void; | ||
run_(parsedArguments: ParsedArguments, originalMethod: Function): any; | ||
/** | ||
@@ -136,0 +146,0 @@ * This method simply calls the nextQuery recursively, emitting results to a |
@@ -23,3 +23,2 @@ "use strict"; | ||
const extend = require("extend"); | ||
const is = require("is"); | ||
const split_array_stream_1 = require("split-array-stream"); | ||
@@ -43,3 +42,3 @@ const stream_1 = require("stream"); | ||
let requestsToMake = -1; | ||
if (is.number(options.maxApiCalls)) { | ||
if (typeof options.maxApiCalls === 'number') { | ||
requestsToMake = options.maxApiCalls; | ||
@@ -114,4 +113,4 @@ } | ||
*/ | ||
// tslint:disable-next-line:no-any | ||
streamify(methodName) { | ||
// tslint:disable-next-line:no-any | ||
return function (...args) { | ||
@@ -138,3 +137,3 @@ const parsedArguments = paginator.parseArguments_(args); | ||
const lastArgument = args[args.length - 1]; | ||
if (is.fn(firstArgument)) { | ||
if (typeof firstArgument === 'function') { | ||
callback = firstArgument; | ||
@@ -145,3 +144,3 @@ } | ||
} | ||
if (is.fn(lastArgument)) { | ||
if (typeof lastArgument === 'function') { | ||
callback = lastArgument; | ||
@@ -152,16 +151,16 @@ } | ||
// Check if the user only asked for a certain amount of results. | ||
if (query.maxResults && is.number(query.maxResults)) { | ||
if (query.maxResults && typeof query.maxResults === 'number') { | ||
// `maxResults` is used API-wide. | ||
maxResults = query.maxResults; | ||
} | ||
else if (is.number(query.pageSize)) { | ||
else if (typeof query.pageSize === 'number') { | ||
// `pageSize` is Pub/Sub's `maxResults`. | ||
maxResults = query.pageSize; | ||
} | ||
if (query.maxApiCalls && is.number(query.maxApiCalls)) { | ||
if (query.maxApiCalls && typeof query.maxApiCalls === 'number') { | ||
maxApiCalls = query.maxApiCalls; | ||
delete query.maxApiCalls; | ||
} | ||
// maxResults is the user specified a limit. | ||
if (callback && (maxResults !== -1 || query.autoPaginate === false)) { | ||
// maxResults is the user specified limit. | ||
if (maxResults !== -1 || query.autoPaginate === false) { | ||
autoPaginate = false; | ||
@@ -202,12 +201,16 @@ } | ||
const callback = parsedArguments.callback; | ||
if (parsedArguments.autoPaginate) { | ||
const results = new Array(); | ||
if (!parsedArguments.autoPaginate) { | ||
return originalMethod(query, callback); | ||
} | ||
const results = new Array(); | ||
const promise = new Promise((resolve, reject) => { | ||
paginator.runAsStream_(parsedArguments, originalMethod) | ||
.on('error', callback) | ||
.on('error', reject) | ||
.on('data', (data) => results.push(data)) | ||
.on('end', () => callback(null, results)); | ||
.on('end', () => resolve(results)); | ||
}); | ||
if (!callback) { | ||
return promise.then(results => [results]); | ||
} | ||
else { | ||
originalMethod(query, callback); | ||
} | ||
promise.then(results => callback(null, results), (err) => callback(err)); | ||
} | ||
@@ -214,0 +217,0 @@ /** |
@@ -7,2 +7,52 @@ # Changelog | ||
## v0.2.0 | ||
03-08-2019 12:15 PST | ||
### New Features | ||
- feat: handle promise based functions ([#91](https://github.com/googleapis/nodejs-paginator/pull/91)) | ||
- refactor(ts): create generic for object streams ([#101](https://github.com/googleapis/nodejs-paginator/pull/101)) | ||
### Dependencies | ||
- chore(deps): update dependency through2 to v3 ([#53](https://github.com/googleapis/nodejs-paginator/pull/53)) | ||
- chore(deps): update dependency @types/is to v0.0.21 ([#55](https://github.com/googleapis/nodejs-paginator/pull/55)) | ||
- chore(deps): update dependency gts to ^0.9.0 ([#57](https://github.com/googleapis/nodejs-paginator/pull/57)) | ||
- fix: Pin @types/sinon to last compatible version ([#61](https://github.com/googleapis/nodejs-paginator/pull/61)) | ||
- refactor: trim a few dependencies ([#60](https://github.com/googleapis/nodejs-paginator/pull/60)) | ||
- chore(deps): update dependency @types/sinon to v5.0.7 ([#62](https://github.com/googleapis/nodejs-paginator/pull/62)) | ||
- chore(deps): update dependency @types/sinon to v7 ([#81](https://github.com/googleapis/nodejs-paginator/pull/81)) | ||
- chore(deps): update dependency mocha to v6 | ||
### Documentation | ||
- docs: add lint/fix example to contributing guide ([#85](https://github.com/googleapis/nodejs-paginator/pull/85)) | ||
- chore: move CONTRIBUTING.md to root ([#87](https://github.com/googleapis/nodejs-paginator/pull/87)) | ||
- docs: update links in contrib guide ([#94](https://github.com/googleapis/nodejs-paginator/pull/94)) | ||
- docs: update contributing path in README ([#88](https://github.com/googleapis/nodejs-paginator/pull/88)) | ||
### Internal / Testing Changes | ||
- chore: include build in eslintignore ([#49](https://github.com/googleapis/nodejs-paginator/pull/49)) | ||
- chore: update CircleCI config ([#52](https://github.com/googleapis/nodejs-paginator/pull/52)) | ||
- chore: use latest npm on Windows ([#54](https://github.com/googleapis/nodejs-paginator/pull/54)) | ||
- chore: update eslintignore config ([#56](https://github.com/googleapis/nodejs-paginator/pull/56)) | ||
- chore: add synth.metadata | ||
- fix(build): fix system key decryption ([#64](https://github.com/googleapis/nodejs-paginator/pull/64)) | ||
- chore: update license file ([#68](https://github.com/googleapis/nodejs-paginator/pull/68)) | ||
- chore(build): update prettier config ([#69](https://github.com/googleapis/nodejs-paginator/pull/69)) | ||
- chore: nyc ignore build/test by default ([#71](https://github.com/googleapis/nodejs-paginator/pull/71)) | ||
- chore: always nyc report before calling codecov ([#72](https://github.com/googleapis/nodejs-paginator/pull/72)) | ||
- build: add Kokoro configs for autorelease ([#75](https://github.com/googleapis/nodejs-paginator/pull/75)) | ||
- fix(build): fix Kokoro release script ([#76](https://github.com/googleapis/nodejs-paginator/pull/76)) | ||
- chore: fix publish.sh permission +x ([#77](https://github.com/googleapis/nodejs-paginator/pull/77)) | ||
- chore: update nyc and eslint configs ([#79](https://github.com/googleapis/nodejs-paginator/pull/79)) | ||
- chore(build): inject yoshi automation key ([#80](https://github.com/googleapis/nodejs-paginator/pull/80)) | ||
- build: check broken links in generated docs ([#82](https://github.com/googleapis/nodejs-paginator/pull/82)) | ||
- build: ignore googleapis.com in doc link check ([#84](https://github.com/googleapis/nodejs-paginator/pull/84)) | ||
- build: test using @grpc/grpc-js in CI ([#89](https://github.com/googleapis/nodejs-paginator/pull/89)) | ||
- build: create docs test npm scripts ([#90](https://github.com/googleapis/nodejs-paginator/pull/90)) | ||
- build: use linkinator for docs test ([#93](https://github.com/googleapis/nodejs-paginator/pull/93)) | ||
- build: update release configuration | ||
- build: fix types for sinon ([#98](https://github.com/googleapis/nodejs-paginator/pull/98)) | ||
- build: use node10 to run samples-test, system-test etc ([#97](https://github.com/googleapis/nodejs-paginator/pull/97)) | ||
- build: Add docuploader credentials to node publish jobs ([#99](https://github.com/googleapis/nodejs-paginator/pull/99)) | ||
## v0.1.2 | ||
@@ -9,0 +59,0 @@ |
{ | ||
"name": "@google-cloud/paginator", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "A result paging utility used by Google node.js modules", | ||
@@ -9,5 +9,3 @@ "main": "build/src/index.js", | ||
"scripts": { | ||
"test": "npm run test-only", | ||
"test-only": "nyc mocha build/test", | ||
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json", | ||
"test": "nyc mocha build/test", | ||
"lint": "gts check", | ||
@@ -20,6 +18,8 @@ "clean": "gts clean", | ||
"posttest": "npm run lint", | ||
"docs": "echo no docs 👻", | ||
"docs": "compodoc src/", | ||
"presystem-test": "npm run compile", | ||
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../", | ||
"system-test": "mocha build/system-test" | ||
"system-test": "mocha build/system-test", | ||
"docs-test": "linkinator docs -r --skip www.googleapis.com", | ||
"predocs-test": "npm run docs" | ||
}, | ||
@@ -34,16 +34,15 @@ "keywords": [], | ||
"devDependencies": { | ||
"@compodoc/compodoc": "^1.1.7", | ||
"@types/arrify": "^1.0.4", | ||
"@types/extend": "^3.0.0", | ||
"@types/is": "0.0.20", | ||
"@types/mocha": "^5.2.4", | ||
"@types/node": "^10.5.2", | ||
"@types/proxyquire": "^1.3.28", | ||
"@types/sinon": "^5.0.1", | ||
"@types/through2": "^2.0.33", | ||
"@types/sinon": "^7.0.0", | ||
"@types/through2": "^2.0.34", | ||
"@types/uuid": "^3.4.3", | ||
"codecov": "^3.0.4", | ||
"gts": "^0.8.0", | ||
"hard-rejection": "^1.0.0", | ||
"gts": "^0.9.0", | ||
"intelli-espower-loader": "^1.0.1", | ||
"mocha": "^5.2.0", | ||
"mocha": "^6.0.0", | ||
"nyc": "^13.0.0", | ||
@@ -53,15 +52,10 @@ "proxyquire": "^2.0.1", | ||
"source-map-support": "^0.5.6", | ||
"through2": "^2.0.3", | ||
"through2": "^3.0.0", | ||
"typescript": "^3.0.0", | ||
"uuid": "^3.3.2" | ||
"uuid": "^3.3.2", | ||
"linkinator": "^1.1.2" | ||
}, | ||
"nyc": { | ||
"exclude": [ | ||
"build/test" | ||
] | ||
}, | ||
"dependencies": { | ||
"arrify": "^1.0.1", | ||
"extend": "^3.0.1", | ||
"is": "^3.2.1", | ||
"split-array-stream": "^2.0.0", | ||
@@ -68,0 +62,0 @@ "stream-events": "^1.0.4" |
@@ -34,3 +34,3 @@ <img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/> | ||
Contributions welcome! See the [Contributing Guide](https://github.com/googlecloudplatform/google-cloud-node/blob/master/.github/CONTRIBUTING.md). | ||
Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/nodejs-paginator/blob/master/CONTRIBUTING.md). | ||
@@ -37,0 +37,0 @@ ## License |
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
38143
4
429