google-gax
Advanced tools
Comparing version 2.17.1 to 2.18.0
@@ -17,28 +17,22 @@ "use strict"; | ||
*/ | ||
var _a, _b; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fallback = exports.protobuf = exports.createApiCall = exports.lro = exports.GrpcClient = exports.version = exports.routingHeader = void 0; | ||
// Not all browsers support `TextEncoder`. The following `require` will | ||
// provide a fast UTF8-only replacement for those browsers that don't support | ||
// text encoding natively. | ||
const isbrowser_1 = require("./isbrowser"); | ||
let needTextEncoderPolyfill = false; | ||
if (isbrowser_1.isBrowser() && | ||
// eslint-disable-next-line node/no-unsupported-features/node-builtins | ||
(typeof TextEncoder === 'undefined' || typeof TextDecoder === 'undefined')) { | ||
needTextEncoderPolyfill = true; | ||
/* global window */ | ||
/* global AbortController */ | ||
const featureDetection_1 = require("./featureDetection"); | ||
if (!featureDetection_1.hasTextEncoder() || !featureDetection_1.hasTextDecoder()) { | ||
if (featureDetection_1.isNodeJS()) { | ||
// Node.js 10 does not have global TextDecoder | ||
// TODO(@alexander-fenster): remove this logic after Node.js 10 is EOL. | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const util = require('util'); | ||
Object.assign(global, { | ||
TextDecoder: util.TextDecoder, | ||
TextEncoder: util.TextEncoder, | ||
}); | ||
} | ||
else { | ||
require('fast-text-encoding'); | ||
} | ||
} | ||
if (typeof process !== 'undefined' && ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node) && ((_b = process === null || process === void 0 ? void 0 : process.versions) === null || _b === void 0 ? void 0 : _b.node.match(/^10\./))) { | ||
// Node.js 10 does not have global TextDecoder | ||
// TODO(@alexander-fenster): remove this logic after Node.js 10 is EOL. | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const util = require('util'); | ||
Object.assign(global, { | ||
TextDecoder: util.TextDecoder, | ||
TextEncoder: util.TextEncoder, | ||
}); | ||
} | ||
if (needTextEncoderPolyfill) { | ||
require('fast-text-encoding'); | ||
} | ||
const protobuf = require("protobufjs"); | ||
@@ -83,6 +77,6 @@ exports.protobuf = protobuf; | ||
constructor(options = {}) { | ||
if (isbrowser_1.isBrowser()) { | ||
if (!featureDetection_1.isNodeJS()) { | ||
if (!options.auth) { | ||
throw new Error(JSON.stringify(options) + | ||
'You need to pass auth instance to use gRPC-fallback client in browser. Use OAuth2Client from google-auth-library.'); | ||
'You need to pass auth instance to use gRPC-fallback client in browser or other non-Node.js environments. Use OAuth2Client from google-auth-library.'); | ||
} | ||
@@ -253,14 +247,6 @@ this.auth = options.auth; | ||
]); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let cancelController, cancelSignal; | ||
if (isbrowser_1.isBrowser() || typeof AbortController !== 'undefined') { | ||
// eslint-disable-next-line no-undef | ||
cancelController = new AbortController(); | ||
} | ||
else { | ||
cancelController = new abort_controller_1.AbortController(); | ||
} | ||
if (cancelController) { | ||
cancelSignal = cancelController.signal; | ||
} | ||
const cancelController = featureDetection_1.hasAbortController() | ||
? new AbortController() | ||
: new abort_controller_1.AbortController(); | ||
const cancelSignal = cancelController.signal; | ||
let cancelRequested = false; | ||
@@ -332,5 +318,4 @@ const headers = Object.assign({}, authHeader); | ||
} | ||
const fetch = isbrowser_1.isBrowser() | ||
? // eslint-disable-next-line no-undef | ||
window.fetch | ||
const fetch = featureDetection_1.hasWindowFetch() | ||
? window.fetch | ||
: node_fetch_1.default; | ||
@@ -389,6 +374,2 @@ const fetchRequest = { | ||
cancel: () => { | ||
if (!cancelController) { | ||
console.warn('AbortController not found: Cancellation is not supported in this environment'); | ||
return; | ||
} | ||
cancelRequested = true; | ||
@@ -395,0 +376,0 @@ cancelController.abort(); |
@@ -60,3 +60,8 @@ /** | ||
}; | ||
operationsStub: Promise<{ | ||
[method: string]: Function; | ||
}>; | ||
constructor(gaxGrpc: GrpcClient | FallbackGrpcClient, operationsProtos: any, options: ClientOptions); | ||
/** Closes this operations client. */ | ||
close(): void; | ||
/** | ||
@@ -63,0 +68,0 @@ * Get the project ID used by this class. |
@@ -82,3 +82,3 @@ "use strict"; | ||
// google.longrunning.Operations. | ||
const operationsStub = gaxGrpc.createStub(opts.fallback | ||
this.operationsStub = gaxGrpc.createStub(opts.fallback | ||
? operationsProtos.lookupService('google.longrunning.Operations') | ||
@@ -93,3 +93,3 @@ : operationsProtos.google.longrunning.Operations, opts); | ||
for (const methodName of operationsStubMethods) { | ||
const innerCallPromise = operationsStub.then(stub => (...args) => { | ||
const innerCallPromise = this.operationsStub.then(stub => (...args) => { | ||
const func = stub[methodName]; | ||
@@ -103,2 +103,6 @@ return func.apply(stub, args); | ||
} | ||
/** Closes this operations client. */ | ||
close() { | ||
this.operationsStub.then(stub => stub.close()); | ||
} | ||
getProjectId(callback) { | ||
@@ -105,0 +109,0 @@ if (this.auth && 'getProjectId' in this.auth) { |
@@ -64,3 +64,3 @@ "use strict"; | ||
} | ||
const resources = response[resourceFieldName]; | ||
const resources = response[resourceFieldName] || []; | ||
const pageToken = response[responsePageTokenFieldName]; | ||
@@ -67,0 +67,0 @@ let nextPageRequest = null; |
@@ -23,2 +23,3 @@ "use strict"; | ||
const pagedApiCaller_1 = require("./pagedApiCaller"); | ||
const maxAttemptsEmptyResponse = 10; | ||
/** | ||
@@ -111,6 +112,21 @@ * A descriptor for methods that support pagination. | ||
} | ||
if (nextPageRequest) { | ||
let attempts = 0; | ||
while (cache.length === 0 && nextPageRequest) { | ||
let result; | ||
[result, nextPageRequest] = (await apiCall(nextPageRequest, options)); | ||
cache.push(...result); | ||
// For pagination response with protobuf map type, use tuple as representation. | ||
if (result && !Array.isArray(result)) { | ||
for (const [key, value] of Object.entries(result)) { | ||
cache.push([key, value]); | ||
} | ||
} | ||
else { | ||
cache.push(...result); | ||
} | ||
if (cache.length === 0) { | ||
++attempts; | ||
if (attempts > maxAttemptsEmptyResponse) { | ||
break; | ||
} | ||
} | ||
} | ||
@@ -117,0 +133,0 @@ if (cache.length === 0) { |
@@ -19,3 +19,3 @@ "use strict"; | ||
exports.warn = void 0; | ||
const isbrowser_1 = require("./isbrowser"); | ||
const featureDetection_1 = require("./featureDetection"); | ||
const emittedWarnings = new Set(); | ||
@@ -29,3 +29,3 @@ // warnType is the type of warning (e.g. 'DeprecationWarning', 'ExperimentalWarning', etc.) | ||
emittedWarnings.add(code); | ||
if (isbrowser_1.isBrowser()) { | ||
if (!featureDetection_1.isNodeJS()) { | ||
console.warn(message); | ||
@@ -32,0 +32,0 @@ } |
@@ -7,2 +7,16 @@ # Changelog | ||
## [2.18.0](https://www.github.com/googleapis/gax-nodejs/compare/v2.17.1...v2.18.0) (2021-07-13) | ||
### Features | ||
* make OperationsClient closeable ([#1047](https://www.github.com/googleapis/gax-nodejs/issues/1047)) ([2dbba29](https://www.github.com/googleapis/gax-nodejs/commit/2dbba29dde552fb35c275a4a44b06fb4698eb5cf)) | ||
* support map handle for DIREGAPIC Pagination ([#1052](https://www.github.com/googleapis/gax-nodejs/issues/1052)) ([faab4c6](https://www.github.com/googleapis/gax-nodejs/commit/faab4c652c4943fc18c792995180bf59dbd5c7bc)) | ||
### Bug Fixes | ||
* make pagination work for empty responses ([#1043](https://www.github.com/googleapis/gax-nodejs/issues/1043)) ([cbe2d3f](https://www.github.com/googleapis/gax-nodejs/commit/cbe2d3f9de4ec01e8e61699b5fa6bf7b34b870a5)) | ||
* replace isBrowser() with home made feature detection ([#1054](https://www.github.com/googleapis/gax-nodejs/issues/1054)) ([2c8e56d](https://www.github.com/googleapis/gax-nodejs/commit/2c8e56d5812af7b08ff6d68169d1d8ea325e03c2)) | ||
### [2.17.1](https://www.github.com/googleapis/gax-nodejs/compare/v2.17.0...v2.17.1) (2021-07-09) | ||
@@ -9,0 +23,0 @@ |
{ | ||
"name": "google-gax", | ||
"version": "2.17.1", | ||
"version": "2.18.0", | ||
"description": "Google API Extensions", | ||
@@ -5,0 +5,0 @@ "main": "build/src/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
5851595
80424