Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

Commit f67a841

Browse files
authored
feat: add support for TPC Universes (#1333)
1 parent 9907cec commit f67a841

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

samples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"dependencies": {
2020
"@google-cloud/bigquery": "^7.4.0",
2121
"@google-cloud/storage": "^7.0.0",
22-
"google-auth-library": "^9.0.0",
22+
"google-auth-library": "^9.6.0",
2323
"readline-promise": "^1.0.4",
2424
"yargs": "^17.0.0"
2525
},

src/bigquery.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

232238
export interface IntegerTypeCastOptions {
@@ -311,6 +317,7 @@ export const PROTOCOL_REGEX = /^(\w*):\/\//;
311317
*/
312318
export 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

test/bigquery.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,22 @@ describe('BigQuery', () => {
263263
assert.strictEqual(calledWith.apiEndpoint, 'https://some.fake.endpoint');
264264
});
265265

266+
it('should allow overriding TPC universe', () => {
267+
const universeDomain = 'fake-tpc-env.example.com/';
268+
bq = new BigQuery({
269+
universeDomain: universeDomain,
270+
});
271+
const calledWith = bq.calledWith_[0];
272+
assert.strictEqual(
273+
calledWith.baseUrl,
274+
'https://bigquery.fake-tpc-env.example.com/bigquery/v2'
275+
);
276+
assert.strictEqual(
277+
calledWith.apiEndpoint,
278+
'https://bigquery.fake-tpc-env.example.com'
279+
);
280+
});
281+
266282
it('should capture any user specified location', () => {
267283
const bq = new BigQuery({
268284
projectId: PROJECT_ID,

0 commit comments

Comments
 (0)