@@ -227,6 +227,12 @@ export interface BigQueryOptions extends GoogleAuthOptions {
227227 * Defaults to `bigquery.googleapis.com`.
228228 */
229229 apiEndpoint ?: string ;
230+
231+ /**
232+ * The Trusted Cloud Domain (TPC) DNS of the service used to make requests.
233+ * Defaults to `googleapis.com`.
234+ */
235+ universeDomain ?: string ;
230236}
231237
232238export interface IntegerTypeCastOptions {
@@ -311,6 +317,7 @@ export const PROTOCOL_REGEX = /^(\w*):\/\//;
311317 */
312318export class BigQuery extends Service {
313319 location ?: string ;
320+ private _universeDomain : string ;
314321
315322 createQueryStream ( options ?: Query | string ) : ResourceStream < RowMetadata > {
316323 // placeholder body, overwritten in constructor
@@ -328,10 +335,17 @@ export class BigQuery extends Service {
328335 }
329336
330337 constructor ( options : BigQueryOptions = { } ) {
331- let apiEndpoint = 'https://bigquery.googleapis.com' ;
338+ let universeDomain = 'googleapis.com' ;
339+ const servicePath = 'bigquery' ;
340+
341+ if ( options . universeDomain ) {
342+ universeDomain = BigQuery . sanitizeDomain ( options . universeDomain ) ;
343+ }
332344
333345 const EMULATOR_HOST = process . env . BIGQUERY_EMULATOR_HOST ;
334346
347+ let apiEndpoint = `https://${ servicePath } .${ universeDomain } ` ;
348+
335349 if ( typeof EMULATOR_HOST === 'string' ) {
336350 apiEndpoint = BigQuery . sanitizeEndpoint ( EMULATOR_HOST ) ;
337351 }
@@ -361,6 +375,7 @@ export class BigQuery extends Service {
361375
362376 super ( config , options ) ;
363377
378+ this . _universeDomain = universeDomain ;
364379 this . location = options . location ;
365380 /**
366381 * Run a query scoped to your project as a readable object stream.
@@ -473,10 +488,18 @@ export class BigQuery extends Service {
473488 } ) ;
474489 }
475490
491+ get universeDomain ( ) {
492+ return this . _universeDomain ;
493+ }
494+
476495 private static sanitizeEndpoint ( url : string ) {
477496 if ( ! PROTOCOL_REGEX . test ( url ) ) {
478497 url = `https://${ url } ` ;
479498 }
499+ return this . sanitizeDomain ( url ) ;
500+ }
501+
502+ private static sanitizeDomain ( url : string ) {
480503 return url . replace ( / \/ + $ / , '' ) ; // Remove trailing slashes
481504 }
482505
0 commit comments