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C,IAAvB,EAAM,eAC3B,GAAe,IAGvB,MAAM,EAAkB,CACpB,MAAO,GAAS,CAAC,EACjB,eACA,cACA,aACA,YAMJ,OAJA,EAAgB,cAAgB,QAAO,EAAM,CAAC,EAAG,EAAgB,cAC1D,EAAgB,cAAc,oBAC9B,EAAgB,cAAc,kBAC9B,EAAgB,cAAc,SAC9B,CACX,CAiBA,IAAA,CAAK,EAAiB,GAClB,MAAM,EAAQ,EAAgB,MACxB,EAAW,EAAgB,SACjC,IAAK,EAAgB,aACjB,OAAO,EAAe,EAAO,GAEjC,MAAM,EAAU,IAAI,MACpB,IAAI,EAAY,GAChB,MAAM,EAAU,IAAI,QAAQ,CAAC,EAAS,KAClC,MAAM,EAAS,UAAU,aAAa,EAAiB,GACvD,EACK,GAAG,QAAS,GACZ,GAAG,OAAS,GAAS,EAAQ,KAAK,IAClC,GAAG,MAAO,KACX,EAAY,EAAO,YAAc,GACjC,EAAQ,OAGhB,IAAK,EACD,OAAO,EAAQ,KAAK,GAAW,CAAC,EAAS,KAAU,IAEvD,EAAQ,KAAK,GAAW,EAAS,KAAM,EAAS,KAAU,GAAa,GAAQ,EAAS,GAC5F,CAoBA,YAAA,CAAa,EAAiB,GAC1B,OAAO,IAAI,kBAAkB,eAAe,EAAiB,EACjE,EAEJ,QAAQ,UAAY,UACpB,MAAM,UAAY,IAAI,UACtB,QAAQ,UAAY","file":"/npm/@google-cloud/paginator@6.0.2/build/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.48.0.\n * Original file: /npm/@google-cloud/paginator@6.0.2/build/src/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\n/*!\n * Copyright 2015 Google Inc. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ResourceStream = exports.paginator = exports.Paginator = void 0;\n/*!\n * @module common/paginator\n */\nconst extend = require(\"extend\");\nconst resource_stream_1 = require(\"./resource-stream\");\nObject.defineProperty(exports, \"ResourceStream\", { enumerable: true, get: function () { return resource_stream_1.ResourceStream; } });\n/*! Developer Documentation\n *\n * paginator is used to auto-paginate `nextQuery` methods as well as\n * streamifying them.\n *\n * Before:\n *\n *   search.query('done=true', function(err, results, nextQuery) {\n *     search.query(nextQuery, function(err, results, nextQuery) {});\n *   });\n *\n * After:\n *\n *   search.query('done=true', function(err, results) {});\n *\n * Methods to extend should be written to accept callbacks and return a\n * `nextQuery`.\n */\nclass Paginator {\n    /**\n     * Cache the original method, then overwrite it on the Class's prototype.\n     *\n     * @param {function} Class - The parent class of the methods to extend.\n     * @param {string|string[]} methodNames - Name(s) of the methods to extend.\n     */\n    // tslint:disable-next-line:variable-name\n    extend(Class, methodNames) {\n        if (typeof methodNames === 'string') {\n            methodNames = [methodNames];\n        }\n        methodNames.forEach(methodName => {\n            const originalMethod = Class.prototype[methodName];\n            // map the original method to a private member\n            Class.prototype[methodName + '_'] = originalMethod;\n            // overwrite the original to auto-paginate\n            /* eslint-disable  @typescript-eslint/no-explicit-any */\n            Class.prototype[methodName] = function (...args) {\n                const parsedArguments = paginator.parseArguments_(args);\n                return paginator.run_(parsedArguments, originalMethod.bind(this));\n            };\n        });\n    }\n    /**\n     * Wraps paginated API calls in a readable object stream.\n     *\n     * This method simply calls the nextQuery recursively, emitting results to a\n     * stream. The stream ends when `nextQuery` is null.\n     *\n     * `maxResults` will act as a cap for how many results are fetched and emitted\n     * to the stream.\n     *\n     * @param {string} methodName - Name of the method to streamify.\n     * @return {function} - Wrapped function.\n     */\n    /* eslint-disable  @typescript-eslint/no-explicit-any */\n    streamify(methodName) {\n        return function (\n        /* eslint-disable  @typescript-eslint/no-explicit-any */\n        ...args) {\n            const parsedArguments = paginator.parseArguments_(args);\n            const originalMethod = this[methodName + '_'] || this[methodName];\n            return paginator.runAsStream_(parsedArguments, originalMethod.bind(this));\n        };\n    }\n    /**\n     * Parse a pseudo-array `arguments` for a query and callback.\n     *\n     * @param {array} args - The original `arguments` pseduo-array that the original\n     *     method received.\n     */\n    /* eslint-disable  @typescript-eslint/no-explicit-any */\n    parseArguments_(args) {\n        let query;\n        let autoPaginate = true;\n        let maxApiCalls = -1;\n        let maxResults = -1;\n        let callback;\n        const firstArgument = args[0];\n        const lastArgument = args[args.length - 1];\n        if (typeof firstArgument === 'function') {\n            callback = firstArgument;\n        }\n        else {\n            query = firstArgument;\n        }\n        if (typeof lastArgument === 'function') {\n            callback = lastArgument;\n        }\n        if (typeof query === 'object') {\n            query = extend(true, {}, query);\n            // Check if the user only asked for a certain amount of results.\n            if (query.maxResults && typeof query.maxResults === 'number') {\n                // `maxResults` is used API-wide.\n                maxResults = query.maxResults;\n            }\n            else if (typeof query.pageSize === 'number') {\n                // `pageSize` is Pub/Sub's `maxResults`.\n                maxResults = query.pageSize;\n            }\n            if (query.maxApiCalls && typeof query.maxApiCalls === 'number') {\n                maxApiCalls = query.maxApiCalls;\n                delete query.maxApiCalls;\n            }\n            // maxResults is the user specified limit.\n            if (maxResults !== -1 || query.autoPaginate === false) {\n                autoPaginate = false;\n            }\n        }\n        const parsedArguments = {\n            query: query || {},\n            autoPaginate,\n            maxApiCalls,\n            maxResults,\n            callback,\n        };\n        parsedArguments.streamOptions = extend(true, {}, parsedArguments.query);\n        delete parsedArguments.streamOptions.autoPaginate;\n        delete parsedArguments.streamOptions.maxResults;\n        delete parsedArguments.streamOptions.pageSize;\n        return parsedArguments;\n    }\n    /**\n     * This simply checks to see if `autoPaginate` is set or not, if it's true\n     * then we buffer all results, otherwise simply call the original method.\n     *\n     * @param {array} parsedArguments - Parsed arguments from the original method\n     *     call.\n     * @param {object=|string=} parsedArguments.query - Query object. This is most\n     *     commonly an object, but to make the API more simple, it can also be a\n     *     string in some places.\n     * @param {function=} parsedArguments.callback - Callback function.\n     * @param {boolean} parsedArguments.autoPaginate - Auto-pagination enabled.\n     * @param {boolean} parsedArguments.maxApiCalls - Maximum API calls to make.\n     * @param {number} parsedArguments.maxResults - Maximum results to return.\n     * @param {function} originalMethod - The cached method that accepts a callback\n     *     and returns `nextQuery` to receive more results.\n     */\n    run_(parsedArguments, originalMethod) {\n        const query = parsedArguments.query;\n        const callback = parsedArguments.callback;\n        if (!parsedArguments.autoPaginate) {\n            return originalMethod(query, callback);\n        }\n        const results = new Array();\n        let otherArgs = [];\n        const promise = new Promise((resolve, reject) => {\n            const stream = paginator.runAsStream_(parsedArguments, originalMethod);\n            stream\n                .on('error', reject)\n                .on('data', (data) => results.push(data))\n                .on('end', () => {\n                otherArgs = stream._otherArgs || [];\n                resolve(results);\n            });\n        });\n        if (!callback) {\n            return promise.then(results => [results, query, ...otherArgs]);\n        }\n        promise.then(results => callback(null, results, query, ...otherArgs), (err) => callback(err));\n    }\n    /**\n     * This method simply calls the nextQuery recursively, emitting results to a\n     * stream. The stream ends when `nextQuery` is null.\n     *\n     * `maxResults` will act as a cap for how many results are fetched and emitted\n     * to the stream.\n     *\n     * @param {object=|string=} parsedArguments.query - Query object. This is most\n     *     commonly an object, but to make the API more simple, it can also be a\n     *     string in some places.\n     * @param {function=} parsedArguments.callback - Callback function.\n     * @param {boolean} parsedArguments.autoPaginate - Auto-pagination enabled.\n     * @param {boolean} parsedArguments.maxApiCalls - Maximum API calls to make.\n     * @param {number} parsedArguments.maxResults - Maximum results to return.\n     * @param {function} originalMethod - The cached method that accepts a callback\n     *     and returns `nextQuery` to receive more results.\n     * @return {stream} - Readable object stream.\n     */\n    /* eslint-disable  @typescript-eslint/no-explicit-any */\n    runAsStream_(parsedArguments, originalMethod) {\n        return new resource_stream_1.ResourceStream(parsedArguments, originalMethod);\n    }\n}\nexports.Paginator = Paginator;\nconst paginator = new Paginator();\nexports.paginator = paginator;\n"]}