Skip to content

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 authored Nov 23, 2020
1 parent 7f14b1a commit cedb1ad
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 52 deletions.
101 changes: 93 additions & 8 deletions packages/google-cloud-bigquery-storage/protos/protos.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@
// ** 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, CallOptions, Descriptors, ClientOptions} from 'google-gax';
import * as path from 'path';

import * as protos from '../../protos/protos';
/**
* Client JSON configuration object, loaded from
* `src/v1/big_query_read_client_config.json`.
* This file defines retry strategy and timeouts for all API methods in this library.
*/
import * as gapicConfig from './big_query_read_client_config.json';

const version = require('../../../package.json').version;
Expand Down Expand Up @@ -76,9 +82,9 @@ export class BigQueryReadClient {
* 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 @@ -91,7 +97,9 @@ export class BigQueryReadClient {
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 @@ -306,7 +314,7 @@ export class BigQueryReadClient {
// -------------------
createReadSession(
request: protos.google.cloud.bigquery.storage.v1.ICreateReadSessionRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.cloud.bigquery.storage.v1.IReadSession,
Expand All @@ -319,7 +327,7 @@ export class BigQueryReadClient {
>;
createReadSession(
request: protos.google.cloud.bigquery.storage.v1.ICreateReadSessionRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.cloud.bigquery.storage.v1.IReadSession,
| protos.google.cloud.bigquery.storage.v1.ICreateReadSessionRequest
Expand Down Expand Up @@ -388,7 +396,7 @@ export class BigQueryReadClient {
createReadSession(
request: protos.google.cloud.bigquery.storage.v1.ICreateReadSessionRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.cloud.bigquery.storage.v1.IReadSession,
| protos.google.cloud.bigquery.storage.v1.ICreateReadSessionRequest
Expand All @@ -414,12 +422,12 @@ export class BigQueryReadClient {
]
> | 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 @@ -434,7 +442,7 @@ export class BigQueryReadClient {
}
splitReadStream(
request: protos.google.cloud.bigquery.storage.v1.ISplitReadStreamRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.cloud.bigquery.storage.v1.ISplitReadStreamResponse,
Expand All @@ -447,7 +455,7 @@ export class BigQueryReadClient {
>;
splitReadStream(
request: protos.google.cloud.bigquery.storage.v1.ISplitReadStreamRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.cloud.bigquery.storage.v1.ISplitReadStreamResponse,
| protos.google.cloud.bigquery.storage.v1.ISplitReadStreamRequest
Expand Down Expand Up @@ -505,7 +513,7 @@ export class BigQueryReadClient {
splitReadStream(
request: protos.google.cloud.bigquery.storage.v1.ISplitReadStreamRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.cloud.bigquery.storage.v1.ISplitReadStreamResponse,
| protos.google.cloud.bigquery.storage.v1.ISplitReadStreamRequest
Expand All @@ -531,12 +539,12 @@ export class BigQueryReadClient {
]
> | 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 @@ -581,7 +589,7 @@ export class BigQueryReadClient {
*/
readRows(
request?: protos.google.cloud.bigquery.storage.v1.IReadRowsRequest,
options?: gax.CallOptions
options?: CallOptions
): gax.CancellableStream {
request = request || {};
options = options || {};
Expand Down
Loading

0 comments on commit cedb1ad

Please sign in to comment.