Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
fix(browser): check for fetch on window
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation committed Nov 23, 2020
1 parent 8377b42 commit ef95fb1
Show file tree
Hide file tree
Showing 10 changed files with 1,424 additions and 478 deletions.
1,022 changes: 949 additions & 73 deletions protos/protos.json

Large diffs are not rendered by default.

56 changes: 32 additions & 24 deletions src/v1/image_annotator_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

/* global window */
import * as gax from 'google-gax';
import {
Callback,
Expand All @@ -27,6 +28,11 @@ import {
import * as path from 'path';

import * as protos from '../../protos/protos';
/**
* Client JSON configuration object, loaded from
* `src/v1/image_annotator_client_config.json`.
* This file defines retry strategy and timeouts for all API methods in this library.
*/
import * as gapicConfig from './image_annotator_client_config.json';
import {operationsProtos} from 'google-gax';
const version = require('../../../package.json').version;
Expand Down Expand Up @@ -83,9 +89,9 @@ export class ImageAnnotatorClient {
* your project ID will be detected automatically.
* @param {string} [options.apiEndpoint] - The domain name of the
* API remote host.
* @param {gax.ClientConfig} [options.clientConfig] - client configuration override.
* TODO(@alexander-fenster): link to gax documentation.
* @param {boolean} fallback - Use HTTP fallback mode.
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
* Follows the structure of {@link gapicConfig}.
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
* In fallback mode, a special browser-compatible transport implementation is used
* instead of gRPC transport. In browser context (if the `window` object is defined)
* the fallback mode is enabled automatically; set `options.fallback` to `false`
Expand All @@ -98,7 +104,9 @@ export class ImageAnnotatorClient {
opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath;
const port = opts?.port || staticMembers.port;
const clientConfig = opts?.clientConfig ?? {};
const fallback = opts?.fallback ?? typeof window !== 'undefined';
const fallback =
opts?.fallback ??
(typeof window !== 'undefined' && typeof window?.fetch === 'function');
opts = Object.assign({servicePath, port, clientConfig, fallback}, opts);

// If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
Expand Down Expand Up @@ -355,7 +363,7 @@ export class ImageAnnotatorClient {
// -------------------
batchAnnotateImages(
request: protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.cloud.vision.v1.IBatchAnnotateImagesResponse,
Expand All @@ -365,7 +373,7 @@ export class ImageAnnotatorClient {
>;
batchAnnotateImages(
request: protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.cloud.vision.v1.IBatchAnnotateImagesResponse,
| protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest
Expand Down Expand Up @@ -417,7 +425,7 @@ export class ImageAnnotatorClient {
batchAnnotateImages(
request: protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.cloud.vision.v1.IBatchAnnotateImagesResponse,
| protos.google.cloud.vision.v1.IBatchAnnotateImagesRequest
Expand All @@ -440,12 +448,12 @@ export class ImageAnnotatorClient {
]
> | void {
request = request || {};
let options: gax.CallOptions;
let options: CallOptions;
if (typeof optionsOrCallback === 'function' && callback === undefined) {
callback = optionsOrCallback;
options = {};
} else {
options = optionsOrCallback as gax.CallOptions;
options = optionsOrCallback as CallOptions;
}
options = options || {};
options.otherArgs = options.otherArgs || {};
Expand All @@ -460,7 +468,7 @@ export class ImageAnnotatorClient {
}
batchAnnotateFiles(
request: protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.cloud.vision.v1.IBatchAnnotateFilesResponse,
Expand All @@ -470,7 +478,7 @@ export class ImageAnnotatorClient {
>;
batchAnnotateFiles(
request: protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.cloud.vision.v1.IBatchAnnotateFilesResponse,
| protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest
Expand Down Expand Up @@ -529,7 +537,7 @@ export class ImageAnnotatorClient {
batchAnnotateFiles(
request: protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.cloud.vision.v1.IBatchAnnotateFilesResponse,
| protos.google.cloud.vision.v1.IBatchAnnotateFilesRequest
Expand All @@ -552,12 +560,12 @@ export class ImageAnnotatorClient {
]
> | void {
request = request || {};
let options: gax.CallOptions;
let options: CallOptions;
if (typeof optionsOrCallback === 'function' && callback === undefined) {
callback = optionsOrCallback;
options = {};
} else {
options = optionsOrCallback as gax.CallOptions;
options = optionsOrCallback as CallOptions;
}
options = options || {};
options.otherArgs = options.otherArgs || {};
Expand All @@ -573,7 +581,7 @@ export class ImageAnnotatorClient {

asyncBatchAnnotateImages(
request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
LROperation<
Expand All @@ -586,7 +594,7 @@ export class ImageAnnotatorClient {
>;
asyncBatchAnnotateImages(
request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
LROperation<
protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse,
Expand Down Expand Up @@ -653,7 +661,7 @@ export class ImageAnnotatorClient {
asyncBatchAnnotateImages(
request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
LROperation<
protos.google.cloud.vision.v1.IAsyncBatchAnnotateImagesResponse,
Expand Down Expand Up @@ -681,12 +689,12 @@ export class ImageAnnotatorClient {
]
> | void {
request = request || {};
let options: gax.CallOptions;
let options: CallOptions;
if (typeof optionsOrCallback === 'function' && callback === undefined) {
callback = optionsOrCallback;
options = {};
} else {
options = optionsOrCallback as gax.CallOptions;
options = optionsOrCallback as CallOptions;
}
options = options || {};
options.otherArgs = options.otherArgs || {};
Expand Down Expand Up @@ -742,7 +750,7 @@ export class ImageAnnotatorClient {
}
asyncBatchAnnotateFiles(
request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
LROperation<
Expand All @@ -755,7 +763,7 @@ export class ImageAnnotatorClient {
>;
asyncBatchAnnotateFiles(
request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
LROperation<
protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse,
Expand Down Expand Up @@ -817,7 +825,7 @@ export class ImageAnnotatorClient {
asyncBatchAnnotateFiles(
request: protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
LROperation<
protos.google.cloud.vision.v1.IAsyncBatchAnnotateFilesResponse,
Expand Down Expand Up @@ -845,12 +853,12 @@ export class ImageAnnotatorClient {
]
> | void {
request = request || {};
let options: gax.CallOptions;
let options: CallOptions;
if (typeof optionsOrCallback === 'function' && callback === undefined) {
callback = optionsOrCallback;
options = {};
} else {
options = optionsOrCallback as gax.CallOptions;
options = optionsOrCallback as CallOptions;
}
options = options || {};
options.otherArgs = options.otherArgs || {};
Expand Down

0 comments on commit ef95fb1

Please sign in to comment.