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

Commit

Permalink
fix(browser): check for fetch on window (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored Nov 24, 2020
1 parent f12577e commit a25c71f
Show file tree
Hide file tree
Showing 14 changed files with 1,186 additions and 546 deletions.
807 changes: 748 additions & 59 deletions protos/protos.json

Large diffs are not rendered by default.

70 changes: 39 additions & 31 deletions src/v4/company_service_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 @@ -30,6 +31,11 @@ import * as path from 'path';
import {Transform} from 'stream';
import {RequestType} from 'google-gax/build/src/apitypes';
import * as protos from '../../protos/protos';
/**
* Client JSON configuration object, loaded from
* `src/v4/company_service_client_config.json`.
* This file defines retry strategy and timeouts for all API methods in this library.
*/
import * as gapicConfig from './company_service_client_config.json';

const version = require('../../../package.json').version;
Expand Down Expand Up @@ -83,9 +89,9 @@ export class CompanyServiceClient {
* 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 CompanyServiceClient {
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 @@ -317,7 +325,7 @@ export class CompanyServiceClient {
// -------------------
createCompany(
request: protos.google.cloud.talent.v4.ICreateCompanyRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.cloud.talent.v4.ICompany,
Expand All @@ -327,7 +335,7 @@ export class CompanyServiceClient {
>;
createCompany(
request: protos.google.cloud.talent.v4.ICreateCompanyRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.cloud.talent.v4.ICompany,
protos.google.cloud.talent.v4.ICreateCompanyRequest | null | undefined,
Expand Down Expand Up @@ -367,7 +375,7 @@ export class CompanyServiceClient {
createCompany(
request: protos.google.cloud.talent.v4.ICreateCompanyRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.cloud.talent.v4.ICompany,
| protos.google.cloud.talent.v4.ICreateCompanyRequest
Expand All @@ -388,12 +396,12 @@ export class CompanyServiceClient {
]
> | 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 @@ -408,7 +416,7 @@ export class CompanyServiceClient {
}
getCompany(
request: protos.google.cloud.talent.v4.IGetCompanyRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.cloud.talent.v4.ICompany,
Expand All @@ -418,7 +426,7 @@ export class CompanyServiceClient {
>;
getCompany(
request: protos.google.cloud.talent.v4.IGetCompanyRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.cloud.talent.v4.ICompany,
protos.google.cloud.talent.v4.IGetCompanyRequest | null | undefined,
Expand Down Expand Up @@ -457,7 +465,7 @@ export class CompanyServiceClient {
getCompany(
request: protos.google.cloud.talent.v4.IGetCompanyRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.cloud.talent.v4.ICompany,
protos.google.cloud.talent.v4.IGetCompanyRequest | null | undefined,
Expand All @@ -476,12 +484,12 @@ export class CompanyServiceClient {
]
> | 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 @@ -496,7 +504,7 @@ export class CompanyServiceClient {
}
updateCompany(
request: protos.google.cloud.talent.v4.IUpdateCompanyRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.cloud.talent.v4.ICompany,
Expand All @@ -506,7 +514,7 @@ export class CompanyServiceClient {
>;
updateCompany(
request: protos.google.cloud.talent.v4.IUpdateCompanyRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.cloud.talent.v4.ICompany,
protos.google.cloud.talent.v4.IUpdateCompanyRequest | null | undefined,
Expand Down Expand Up @@ -549,7 +557,7 @@ export class CompanyServiceClient {
updateCompany(
request: protos.google.cloud.talent.v4.IUpdateCompanyRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.cloud.talent.v4.ICompany,
| protos.google.cloud.talent.v4.IUpdateCompanyRequest
Expand All @@ -570,12 +578,12 @@ export class CompanyServiceClient {
]
> | 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 @@ -590,7 +598,7 @@ export class CompanyServiceClient {
}
deleteCompany(
request: protos.google.cloud.talent.v4.IDeleteCompanyRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.protobuf.IEmpty,
Expand All @@ -600,7 +608,7 @@ export class CompanyServiceClient {
>;
deleteCompany(
request: protos.google.cloud.talent.v4.IDeleteCompanyRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.protobuf.IEmpty,
protos.google.cloud.talent.v4.IDeleteCompanyRequest | null | undefined,
Expand Down Expand Up @@ -640,7 +648,7 @@ export class CompanyServiceClient {
deleteCompany(
request: protos.google.cloud.talent.v4.IDeleteCompanyRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.protobuf.IEmpty,
| protos.google.cloud.talent.v4.IDeleteCompanyRequest
Expand All @@ -661,12 +669,12 @@ export class CompanyServiceClient {
]
> | 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 @@ -682,7 +690,7 @@ export class CompanyServiceClient {

listCompanies(
request: protos.google.cloud.talent.v4.IListCompaniesRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.cloud.talent.v4.ICompany[],
Expand All @@ -692,7 +700,7 @@ export class CompanyServiceClient {
>;
listCompanies(
request: protos.google.cloud.talent.v4.IListCompaniesRequest,
options: gax.CallOptions,
options: CallOptions,
callback: PaginationCallback<
protos.google.cloud.talent.v4.IListCompaniesRequest,
protos.google.cloud.talent.v4.IListCompaniesResponse | null | undefined,
Expand Down Expand Up @@ -745,7 +753,7 @@ export class CompanyServiceClient {
listCompanies(
request: protos.google.cloud.talent.v4.IListCompaniesRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| PaginationCallback<
protos.google.cloud.talent.v4.IListCompaniesRequest,
| protos.google.cloud.talent.v4.IListCompaniesResponse
Expand All @@ -766,12 +774,12 @@ export class CompanyServiceClient {
]
> | 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 @@ -820,7 +828,7 @@ export class CompanyServiceClient {
*/
listCompaniesStream(
request?: protos.google.cloud.talent.v4.IListCompaniesRequest,
options?: gax.CallOptions
options?: CallOptions
): Transform {
request = request || {};
options = options || {};
Expand Down Expand Up @@ -881,7 +889,7 @@ export class CompanyServiceClient {
*/
listCompaniesAsync(
request?: protos.google.cloud.talent.v4.IListCompaniesRequest,
options?: gax.CallOptions
options?: CallOptions
): AsyncIterable<protos.google.cloud.talent.v4.ICompany> {
request = request || {};
options = options || {};
Expand Down
26 changes: 17 additions & 9 deletions src/v4/completion_client.ts
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/v4/completion_client_config.json`.
* This file defines retry strategy and timeouts for all API methods in this library.
*/
import * as gapicConfig from './completion_client_config.json';

const version = require('../../../package.json').version;
Expand Down Expand Up @@ -74,9 +80,9 @@ export class CompletionClient {
* 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 @@ -89,7 +95,9 @@ export class CompletionClient {
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 @@ -291,7 +299,7 @@ export class CompletionClient {
// -------------------
completeQuery(
request: protos.google.cloud.talent.v4.ICompleteQueryRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
protos.google.cloud.talent.v4.ICompleteQueryResponse,
Expand All @@ -301,7 +309,7 @@ export class CompletionClient {
>;
completeQuery(
request: protos.google.cloud.talent.v4.ICompleteQueryRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
protos.google.cloud.talent.v4.ICompleteQueryResponse,
protos.google.cloud.talent.v4.ICompleteQueryRequest | null | undefined,
Expand Down Expand Up @@ -365,7 +373,7 @@ export class CompletionClient {
completeQuery(
request: protos.google.cloud.talent.v4.ICompleteQueryRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
protos.google.cloud.talent.v4.ICompleteQueryResponse,
| protos.google.cloud.talent.v4.ICompleteQueryRequest
Expand All @@ -386,12 +394,12 @@ export class CompletionClient {
]
> | 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
Loading

0 comments on commit a25c71f

Please sign in to comment.