Skip to content

Commit

Permalink
feat: add support for accessing jobs cross-project (#1083)
Browse files Browse the repository at this point in the history
* feat: add support accessing jobs cross-project

* fix test
  • Loading branch information
steffnay committed Mar 1, 2022
1 parent 6cbe7da commit 9e5bae2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/bigquery.ts
Expand Up @@ -66,6 +66,7 @@ export type JobRequest<J> = J & {
jobId?: string;
jobPrefix?: string;
location?: string;
projectId?: string;
};

export type PagedRequest<P> = P & {
Expand Down
5 changes: 5 additions & 0 deletions src/job.ts
Expand Up @@ -124,6 +124,7 @@ export type QueryResultsOptions = {
class Job extends Operation {
bigQuery: BigQuery;
location?: string;
projectId?: string;
getQueryResultsStream(
options?: QueryResultsOptions
): ResourceStream<RowMetadata> {
Expand Down Expand Up @@ -344,6 +345,10 @@ class Job extends Operation {
this.location = options.location;
}

if (options?.projectId) {
this.projectId = options.projectId;
}

/**
* Get the results of a job as a readable object stream.
*
Expand Down
7 changes: 7 additions & 0 deletions test/job.ts
Expand Up @@ -147,6 +147,13 @@ describe('BigQuery/Job', () => {
assert.strictEqual(job.location, options.location);
});

it('should accept a projectId option', () => {
const options = {projectId: 'cool-project'};
const job = new Job(BIGQUERY, JOB_ID, options);

assert.strictEqual(job.projectId, options.projectId);
});

it('should send the location via getMetadata', () => {
const job = new Job(BIGQUERY, JOB_ID, {location: LOCATION});
const calledWith = job.calledWith_[0];
Expand Down

0 comments on commit 9e5bae2

Please sign in to comment.