Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: move types to @googleapis/bigquery package #1331

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@
"system-test": "mocha build/system-test --timeout 600000",
"presystem-test": "npm run compile",
"clean": "gts clean",
"compile": "tsc -p . && cp src/types.d.ts build/src/",
"compile": "tsc -p .",
"fix": "gts fix",
"predocs": "npm run compile",
"prepare": "npm run compile",
"pretest": "npm run compile",
"docs-test": "linkinator docs",
"predocs-test": "npm run docs",
"types": "dtsd bigquery v2 > ./src/types.d.ts",
"prelint": "cd samples; npm link ../; npm install",
"precompile": "gts clean"
},
Expand All @@ -52,6 +51,7 @@
"@google-cloud/paginator": "^5.0.0",
"@google-cloud/precise-date": "^4.0.0",
"@google-cloud/promisify": "^4.0.0",
"@googleapis/bigquery": "^7.0.0",
"arrify": "^2.0.1",
"big.js": "^6.0.0",
"duplexify": "^4.0.0",
Expand Down
73 changes: 40 additions & 33 deletions src/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
RowMetadata,
} from './table';
import {GoogleErrorBody} from '@google-cloud/common/build/src/util';
import bigquery from './types';
import {bigquery_v2} from '@googleapis/bigquery';

// Third-Party Re-exports
export {common};
Expand Down Expand Up @@ -82,21 +82,21 @@
export type QueryRowsResponse = PagedResponse<
RowMetadata,
Query,
bigquery.IGetQueryResultsResponse
bigquery_v2.Schema$GetQueryResultsResponse
>;
export type QueryRowsCallback = PagedCallback<
RowMetadata,
Query,
bigquery.IGetQueryResultsResponse
bigquery_v2.Schema$GetQueryResultsResponse
>;

export type SimpleQueryRowsResponse = [RowMetadata[], bigquery.IJob];
export type SimpleQueryRowsResponse = [RowMetadata[], bigquery_v2.Schema$Job];
export type SimpleQueryRowsCallback = ResourceCallback<
RowMetadata[],
bigquery.IJob
bigquery_v2.Schema$Job
>;

export type Query = JobRequest<bigquery.IJobConfigurationQuery> & {
export type Query = JobRequest<bigquery_v2.Schema$JobConfigurationQuery> & {
destination?: Table;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
params?: any[] | {[param: string]: any};
Expand Down Expand Up @@ -129,39 +129,44 @@
wrapIntegers?: boolean | IntegerTypeCastOptions;
parseJSON?: boolean;
};
export type DatasetResource = bigquery.IDataset & {
export type DatasetResource = bigquery_v2.Schema$Dataset & {
projectId?: string;
};
export type ValueType = bigquery.IQueryParameterType;
export type ValueType = bigquery_v2.Schema$QueryParameterType;

export type GetDatasetsOptions = PagedRequest<bigquery.datasets.IListParams> & {
projectId?: string;
};
export type GetDatasetsOptions =
PagedRequest<bigquery_v2.Params$Resource$Datasets$List> & {
projectId?: string;
};

export type DatasetsResponse = PagedResponse<
Dataset,
GetDatasetsOptions,
bigquery.IDatasetList
bigquery_v2.Schema$DatasetList
>;
export type DatasetsCallback = PagedCallback<
Dataset,
GetDatasetsOptions,
bigquery.IDatasetList
bigquery_v2.Schema$DatasetList
>;

export type DatasetResponse = [Dataset, bigquery.IDataset];
export type DatasetCallback = ResourceCallback<Dataset, bigquery.IDataset>;
export type DatasetResponse = [Dataset, bigquery_v2.Schema$Dataset];
export type DatasetCallback = ResourceCallback<
Dataset,
bigquery_v2.Schema$Dataset
>;

export type GetJobsOptions = PagedRequest<bigquery.jobs.IListParams>;
export type GetJobsOptions =
PagedRequest<bigquery_v2.Params$Resource$Jobs$List>;
export type GetJobsResponse = PagedResponse<
Job,
GetJobsOptions,
bigquery.IJobList
bigquery_v2.Schema$JobList
>;
export type GetJobsCallback = PagedCallback<
Job,
GetJobsOptions,
bigquery.IJobList
bigquery_v2.Schema$JobList
>;

export interface BigQueryTimeOptions {
Expand Down Expand Up @@ -193,7 +198,7 @@
[key: string]: string | ProvidedTypeArray | ProvidedTypeStruct;
}

export type QueryParameter = bigquery.IQueryParameter;
export type QueryParameter = bigquery_v2.Schema$QueryParameter;

export interface BigQueryOptions extends GoogleAuthOptions {
/**
Expand Down Expand Up @@ -236,7 +241,7 @@

export type IntegerTypeCastValue = {
integerValue: string | number;
schemaFieldName?: string;
schemaFieldName?: string | null;
};

export const PROTOCOL_REGEX = /^(\w*):\/\//;
Expand Down Expand Up @@ -312,17 +317,17 @@
export class BigQuery extends Service {
location?: string;

createQueryStream(options?: Query | string): ResourceStream<RowMetadata> {

Check warning on line 320 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<RowMetadata>({}, () => {});
}

getDatasetsStream(options?: GetDatasetsOptions): ResourceStream<Dataset> {

Check warning on line 325 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<Dataset>({}, () => {});
}

getJobsStream(options?: GetJobsOptions): ResourceStream<Job> {

Check warning on line 330 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<Job>({}, () => {});
}
Expand Down Expand Up @@ -989,7 +994,7 @@
static getTypeDescriptorFromProvidedType_(
providedType: string | ProvidedTypeStruct | ProvidedTypeArray
): ValueType {
// The list of types can be found in src/types.d.ts
// The list of types can be found in @googleapis/bigquery package.
const VALID_TYPES = [
'DATE',
'DATETIME',
Expand Down Expand Up @@ -1141,7 +1146,7 @@
if (is.date(value)) {
value = BigQuery.timestamp(value as Date);
}
let parameterType: bigquery.IQueryParameterType;
let parameterType: bigquery_v2.Schema$QueryParameterType;
if (providedType) {
parameterType = BigQuery.getTypeDescriptorFromProvidedType_(providedType);
} else {
Expand All @@ -1163,7 +1168,7 @@
return BigQuery.valueToQueryParameter_(value).parameterValue!;
}
}
return {value} as bigquery.IQueryParameterValue;
return {value} as bigquery_v2.Schema$QueryParameterValue;
}
);
} else if (typeName === 'STRUCT') {
Expand Down Expand Up @@ -1627,7 +1632,7 @@
}

const job = this.job(jobId!, {
location: reqOpts.jobReference.location,
location: reqOpts.jobReference.location ?? undefined,
});

this.request(
Expand Down Expand Up @@ -1785,7 +1790,7 @@

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const datasets = (resp.datasets || []).map(
(dataset: bigquery.IDataset) => {
(dataset: bigquery_v2.Schema$Dataset) => {
const dsOpts: DatasetOptions = {
location: dataset.location!,
};
Expand Down Expand Up @@ -1899,13 +1904,15 @@
pageToken: resp.nextPageToken,
});
}
const jobs = (resp.jobs || []).map((jobObject: bigquery.IJob) => {
const job = this.job(jobObject.jobReference!.jobId!, {
location: jobObject.jobReference!.location!,
});
job.metadata = jobObject!;
return job;
});
const jobs = (resp.jobs || []).map(
(jobObject: bigquery_v2.Schema$Job) => {
const job = this.job(jobObject.jobReference!.jobId!, {
location: jobObject.jobReference!.location!,
});
job.metadata = jobObject!;
return job;
}
);
callback!(null, jobs, nextQuery, resp);
}
);
Expand Down Expand Up @@ -2287,7 +2294,7 @@
type: string;
value: string;
typeCastFunction?: Function;
private _schemaFieldName: string | undefined;
private _schemaFieldName: string | undefined | null;
constructor(
value: string | number | IntegerTypeCastValue,
typeCastOptions?: IntegerTypeCastOptions
Expand Down
44 changes: 25 additions & 19 deletions src/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,61 +45,67 @@
} from './table';
import {Model} from './model';
import {Routine} from './routine';
import bigquery from './types';
import {bigquery_v2} from '@googleapis/bigquery';

export interface DatasetDeleteOptions {
force?: boolean;
}

export interface DatasetOptions {
location?: string;
location?: string | null;
projectId?: string;
}

export type CreateDatasetOptions = bigquery.IDataset;
export type CreateDatasetOptions = bigquery_v2.Schema$Dataset;

export type GetModelsOptions = PagedRequest<bigquery.models.IListParams>;
export type GetModelsOptions =
PagedRequest<bigquery_v2.Params$Resource$Models$List>;
export type GetModelsResponse = PagedResponse<
Model,
GetModelsOptions,
bigquery.IListModelsResponse
bigquery_v2.Schema$ListModelsResponse
>;
export type GetModelsCallback = PagedCallback<
Model,
GetModelsOptions,
bigquery.IListModelsResponse
bigquery_v2.Schema$ListModelsResponse
>;

export type GetRoutinesOptions = PagedRequest<bigquery.routines.IListParams>;
export type GetRoutinesOptions =
PagedRequest<bigquery_v2.Params$Resource$Routines$List>;
export type GetRoutinesResponse = PagedResponse<
Routine,
GetRoutinesOptions,
bigquery.IListRoutinesResponse
bigquery_v2.Schema$ListRoutinesResponse
>;
export type GetRoutinesCallback = PagedCallback<
Routine,
GetRoutinesOptions,
bigquery.IListRoutinesResponse
bigquery_v2.Schema$ListRoutinesResponse
>;

export type GetTablesOptions = PagedRequest<bigquery.tables.IListParams>;
export type GetTablesOptions =
PagedRequest<bigquery_v2.Params$Resource$Tables$List>;
export type GetTablesResponse = PagedResponse<
Table,
GetTablesOptions,
bigquery.ITableList
bigquery_v2.Schema$TableList
>;
export type GetTablesCallback = PagedCallback<
Table,
GetTablesOptions,
bigquery.ITableList
bigquery_v2.Schema$TableList
>;

export type RoutineMetadata = bigquery.IRoutine;
export type RoutineResponse = [Routine, bigquery.IRoutine];
export type RoutineCallback = ResourceCallback<Routine, bigquery.IRoutine>;
export type RoutineMetadata = bigquery_v2.Schema$Routine;
export type RoutineResponse = [Routine, bigquery_v2.Schema$Routine];
export type RoutineCallback = ResourceCallback<
Routine,
bigquery_v2.Schema$Routine
>;

export type TableResponse = [Table, bigquery.ITable];
export type TableCallback = ResourceCallback<Table, bigquery.ITable>;
export type TableResponse = [Table, bigquery_v2.Schema$Table];
export type TableCallback = ResourceCallback<Table, bigquery_v2.Schema$Table>;

/**
* Interact with your BigQuery dataset. Create a Dataset instance with
Expand All @@ -124,15 +130,15 @@
bigQuery: BigQuery;
location?: string;
projectId: string;
getModelsStream(options?: GetModelsOptions): ResourceStream<Model> {

Check warning on line 133 in src/dataset.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<Model>({}, () => {});
}
getRoutinesStream(options?: GetRoutinesOptions): ResourceStream<Routine> {

Check warning on line 137 in src/dataset.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<Routine>({}, () => {});
}
getTablesStream(options?: GetTablesOptions): ResourceStream<Table> {

Check warning on line 141 in src/dataset.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<Table>({}, () => {});
}
Expand Down Expand Up @@ -931,7 +937,7 @@
uri: '/models',
qs: options,
},
(err: null | Error, resp: bigquery.IListModelsResponse) => {
(err: null | Error, resp: bigquery_v2.Schema$ListModelsResponse) => {
if (err) {
callback!(err, null, null, resp);
return;
Expand Down Expand Up @@ -1045,7 +1051,7 @@
uri: '/routines',
qs: options,
},
(err: Error | null, resp: bigquery.IListRoutinesResponse) => {
(err: Error | null, resp: bigquery_v2.Schema$ListRoutinesResponse) => {
if (err) {
callback!(err, null, null, resp);
return;
Expand Down
11 changes: 6 additions & 5 deletions src/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@
RequestCallback,
} from './bigquery';
import {RowMetadata} from './table';
import bigquery from './types';
import {bigquery_v2} from '@googleapis/bigquery';

export type JobMetadata = bigquery.IJob;
export type JobMetadata = bigquery_v2.Schema$Job;
export type JobOptions = JobRequest<JobMetadata>;

export type CancelCallback = RequestCallback<bigquery.IJobCancelResponse>;
export type CancelResponse = [bigquery.IJobCancelResponse];
export type CancelCallback =
RequestCallback<bigquery_v2.Schema$JobCancelResponse>;
export type CancelResponse = [bigquery_v2.Schema$JobCancelResponse];

export type QueryResultsOptions = {
job?: Job;
wrapIntegers?: boolean | IntegerTypeCastOptions;
parseJSON?: boolean;
} & PagedRequest<bigquery.jobs.IGetQueryResultsParams>;
} & PagedRequest<bigquery_v2.Params$Resource$Jobs$Getqueryresults>;

/**
* @callback QueryResultsCallback
Expand Down Expand Up @@ -127,7 +128,7 @@
location?: string;
projectId?: string;
getQueryResultsStream(
options?: QueryResultsOptions

Check warning on line 131 in src/job.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
): ResourceStream<RowMetadata> {
// placeholder body, overwritten in constructor
return new ResourceStream<RowMetadata>({}, () => {});
Expand Down
8 changes: 4 additions & 4 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
JobRequest,
} from '.';
import {JobMetadata} from './job';
import bigquery from './types';
import {bigquery_v2} from '@googleapis/bigquery';

// This is supposed to be a @google-cloud/storage `File` type. The storage npm
// module includes these types, but is currently installed as a devDependency.
Expand All @@ -46,11 +46,11 @@ export interface File {
export type JobMetadataCallback = RequestCallback<JobMetadata>;
export type JobMetadataResponse = [JobMetadata];

export type JobResponse = [Job, bigquery.IJob];
export type JobCallback = ResourceCallback<Job, bigquery.IJob>;
export type JobResponse = [Job, bigquery_v2.Schema$Job];
export type JobCallback = ResourceCallback<Job, bigquery_v2.Schema$Job>;

export type CreateExtractJobOptions =
JobRequest<bigquery.IJobConfigurationExtract> & {
JobRequest<bigquery_v2.Schema$JobConfigurationExtract> & {
format?: 'ML_TF_SAVED_MODEL' | 'ML_XGBOOST_BOOSTER';
};

Expand Down
11 changes: 6 additions & 5 deletions src/rowQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as extend from 'extend';
import * as uuid from 'uuid';
import {RequestCallback, Table, InsertStreamOptions} from '.';
import {GoogleErrorBody} from '@google-cloud/common/build/src/util';
import bigquery from './types';
import {bigquery_v2} from '@googleapis/bigquery';
import {BATCH_LIMITS, RowBatch} from './rowBatch';
import {Stream} from 'stream';
import {RowBatchOptions, InsertRowsOptions, RowMetadata} from './table';
Expand All @@ -41,17 +41,18 @@ export const defaultOptions: MaxInsertOptions = {
maxDelayMillis: 10000,
};

export type InsertRowsStreamResponse = bigquery.ITableDataInsertAllResponse;
export type InsertRowsStreamResponse =
bigquery_v2.Schema$TableDataInsertAllResponse;

export type InsertRowsCallback = RequestCallback<
bigquery.ITableDataInsertAllResponse | bigquery.ITable
bigquery_v2.Schema$TableDataInsertAllResponse | bigquery_v2.Schema$Table
>;
export interface InsertRow {
insertId?: string;
json?: bigquery.IJsonObject;
json?: bigquery_v2.Schema$JsonObject;
}

export type TableRow = bigquery.ITableRow;
export type TableRow = bigquery_v2.Schema$TableRow;
export interface PartialInsertFailure {
message: string;
reason: string;
Expand Down
Loading
Loading