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

fix: make request optional in all cases #843

Merged
Merged
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
53 changes: 18 additions & 35 deletions src/v1/datastore_admin_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import {
PaginationCallback,
GaxCall,
} from 'google-gax';
import * as path from 'path';

import {Transform} from 'stream';
import {RequestType} from 'google-gax/build/src/apitypes';
import * as protos from '../../protos/protos';
import jsonProtos = require('../../protos/protos.json');
/**
* Client JSON configuration object, loaded from
* `src/v1/datastore_admin_client_config.json`.
Expand Down Expand Up @@ -201,27 +201,14 @@ export class DatastoreAdminClient {
}
if (!opts.fallback) {
clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`);
} else if (opts.fallback === 'rest') {
clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`);
}
if (opts.libName && opts.libVersion) {
clientHeader.push(`${opts.libName}/${opts.libVersion}`);
}
// Load the applicable protos.
// For Node.js, pass the path to JSON proto file.
// For browsers, pass the JSON content.

const nodejsProtoPath = path.join(
__dirname,
'..',
'..',
'protos',
'protos.json'
);
this._protos = this._gaxGrpc.loadProto(
opts.fallback
? // eslint-disable-next-line @typescript-eslint/no-var-requires
require('../../protos/protos.json')
: nodejsProtoPath
);
this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);

// Some of the methods on this service return "paged" results,
// (e.g. 50 results at a time, with tokens to get subsequent
Expand All @@ -234,15 +221,11 @@ export class DatastoreAdminClient {
),
};

const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);

// This API contains "long-running operations", which return a
// an Operation object that allows for tracking of the operation,
// rather than holding a request open.
const protoFilesRoot = opts.fallback
? this._gaxModule.protobuf.Root.fromJSON(
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('../../protos/protos.json')
)
: this._gaxModule.protobuf.loadSync(nodejsProtoPath);

this.operationsClient = this._gaxModule
.lro({
Expand Down Expand Up @@ -439,7 +422,7 @@ export class DatastoreAdminClient {
// -- Service calls --
// -------------------
getIndex(
request: protos.google.datastore.admin.v1.IGetIndexRequest,
request?: protos.google.datastore.admin.v1.IGetIndexRequest,
options?: CallOptions
): Promise<
[
Expand Down Expand Up @@ -485,7 +468,7 @@ export class DatastoreAdminClient {
* const [response] = await client.getIndex(request);
*/
getIndex(
request: protos.google.datastore.admin.v1.IGetIndexRequest,
request?: protos.google.datastore.admin.v1.IGetIndexRequest,
optionsOrCallback?:
| CallOptions
| Callback<
Expand Down Expand Up @@ -525,7 +508,7 @@ export class DatastoreAdminClient {
}

exportEntities(
request: protos.google.datastore.admin.v1.IExportEntitiesRequest,
request?: protos.google.datastore.admin.v1.IExportEntitiesRequest,
options?: CallOptions
): Promise<
[
Expand Down Expand Up @@ -611,7 +594,7 @@ export class DatastoreAdminClient {
* const [response] = await operation.promise();
*/
exportEntities(
request: protos.google.datastore.admin.v1.IExportEntitiesRequest,
request?: protos.google.datastore.admin.v1.IExportEntitiesRequest,
optionsOrCallback?:
| CallOptions
| Callback<
Expand Down Expand Up @@ -696,7 +679,7 @@ export class DatastoreAdminClient {
>;
}
importEntities(
request: protos.google.datastore.admin.v1.IImportEntitiesRequest,
request?: protos.google.datastore.admin.v1.IImportEntitiesRequest,
options?: CallOptions
): Promise<
[
Expand Down Expand Up @@ -777,7 +760,7 @@ export class DatastoreAdminClient {
* const [response] = await operation.promise();
*/
importEntities(
request: protos.google.datastore.admin.v1.IImportEntitiesRequest,
request?: protos.google.datastore.admin.v1.IImportEntitiesRequest,
optionsOrCallback?:
| CallOptions
| Callback<
Expand Down Expand Up @@ -862,7 +845,7 @@ export class DatastoreAdminClient {
>;
}
createIndex(
request: protos.google.datastore.admin.v1.ICreateIndexRequest,
request?: protos.google.datastore.admin.v1.ICreateIndexRequest,
options?: CallOptions
): Promise<
[
Expand Down Expand Up @@ -934,7 +917,7 @@ export class DatastoreAdminClient {
* const [response] = await operation.promise();
*/
createIndex(
request: protos.google.datastore.admin.v1.ICreateIndexRequest,
request?: protos.google.datastore.admin.v1.ICreateIndexRequest,
optionsOrCallback?:
| CallOptions
| Callback<
Expand Down Expand Up @@ -1019,7 +1002,7 @@ export class DatastoreAdminClient {
>;
}
deleteIndex(
request: protos.google.datastore.admin.v1.IDeleteIndexRequest,
request?: protos.google.datastore.admin.v1.IDeleteIndexRequest,
options?: CallOptions
): Promise<
[
Expand Down Expand Up @@ -1086,7 +1069,7 @@ export class DatastoreAdminClient {
* const [response] = await operation.promise();
*/
deleteIndex(
request: protos.google.datastore.admin.v1.IDeleteIndexRequest,
request?: protos.google.datastore.admin.v1.IDeleteIndexRequest,
optionsOrCallback?:
| CallOptions
| Callback<
Expand Down Expand Up @@ -1171,7 +1154,7 @@ export class DatastoreAdminClient {
>;
}
listIndexes(
request: protos.google.datastore.admin.v1.IListIndexesRequest,
request?: protos.google.datastore.admin.v1.IListIndexesRequest,
options?: CallOptions
): Promise<
[
Expand Down Expand Up @@ -1226,7 +1209,7 @@ export class DatastoreAdminClient {
* for more details and examples.
*/
listIndexes(
request: protos.google.datastore.admin.v1.IListIndexesRequest,
request?: protos.google.datastore.admin.v1.IListIndexesRequest,
optionsOrCallback?:
| CallOptions
| PaginationCallback<
Expand Down
49 changes: 18 additions & 31 deletions src/v1/datastore_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
/* 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';
import jsonProtos = require('../../protos/protos.json');
/**
* Client JSON configuration object, loaded from
* `src/v1/datastore_client_config.json`.
Expand Down Expand Up @@ -136,27 +136,14 @@ export class DatastoreClient {
}
if (!opts.fallback) {
clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`);
} else if (opts.fallback === 'rest') {
clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`);
}
if (opts.libName && opts.libVersion) {
clientHeader.push(`${opts.libName}/${opts.libVersion}`);
}
// Load the applicable protos.
// For Node.js, pass the path to JSON proto file.
// For browsers, pass the JSON content.

const nodejsProtoPath = path.join(
__dirname,
'..',
'..',
'protos',
'protos.json'
);
this._protos = this._gaxGrpc.loadProto(
opts.fallback
? // eslint-disable-next-line @typescript-eslint/no-var-requires
require('../../protos/protos.json')
: nodejsProtoPath
);
this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);

// Put together the default options sent with requests.
this._defaults = this._gaxGrpc.constructSettings(
Expand Down Expand Up @@ -297,7 +284,7 @@ export class DatastoreClient {
// -- Service calls --
// -------------------
lookup(
request: protos.google.datastore.v1.ILookupRequest,
request?: protos.google.datastore.v1.ILookupRequest,
options?: CallOptions
): Promise<
[
Expand Down Expand Up @@ -345,7 +332,7 @@ export class DatastoreClient {
* const [response] = await client.lookup(request);
*/
lookup(
request: protos.google.datastore.v1.ILookupRequest,
request?: protos.google.datastore.v1.ILookupRequest,
optionsOrCallback?:
| CallOptions
| Callback<
Expand Down Expand Up @@ -384,7 +371,7 @@ export class DatastoreClient {
return this.innerApiCalls.lookup(request, options, callback);
}
runQuery(
request: protos.google.datastore.v1.IRunQueryRequest,
request?: protos.google.datastore.v1.IRunQueryRequest,
options?: CallOptions
): Promise<
[
Expand Down Expand Up @@ -439,7 +426,7 @@ export class DatastoreClient {
* const [response] = await client.runQuery(request);
*/
runQuery(
request: protos.google.datastore.v1.IRunQueryRequest,
request?: protos.google.datastore.v1.IRunQueryRequest,
optionsOrCallback?:
| CallOptions
| Callback<
Expand Down Expand Up @@ -478,7 +465,7 @@ export class DatastoreClient {
return this.innerApiCalls.runQuery(request, options, callback);
}
beginTransaction(
request: protos.google.datastore.v1.IBeginTransactionRequest,
request?: protos.google.datastore.v1.IBeginTransactionRequest,
options?: CallOptions
): Promise<
[
Expand Down Expand Up @@ -524,7 +511,7 @@ export class DatastoreClient {
* const [response] = await client.beginTransaction(request);
*/
beginTransaction(
request: protos.google.datastore.v1.IBeginTransactionRequest,
request?: protos.google.datastore.v1.IBeginTransactionRequest,
optionsOrCallback?:
| CallOptions
| Callback<
Expand Down Expand Up @@ -565,7 +552,7 @@ export class DatastoreClient {
return this.innerApiCalls.beginTransaction(request, options, callback);
}
commit(
request: protos.google.datastore.v1.ICommitRequest,
request?: protos.google.datastore.v1.ICommitRequest,
options?: CallOptions
): Promise<
[
Expand Down Expand Up @@ -630,7 +617,7 @@ export class DatastoreClient {
* const [response] = await client.commit(request);
*/
commit(
request: protos.google.datastore.v1.ICommitRequest,
request?: protos.google.datastore.v1.ICommitRequest,
optionsOrCallback?:
| CallOptions
| Callback<
Expand Down Expand Up @@ -669,7 +656,7 @@ export class DatastoreClient {
return this.innerApiCalls.commit(request, options, callback);
}
rollback(
request: protos.google.datastore.v1.IRollbackRequest,
request?: protos.google.datastore.v1.IRollbackRequest,
options?: CallOptions
): Promise<
[
Expand Down Expand Up @@ -716,7 +703,7 @@ export class DatastoreClient {
* const [response] = await client.rollback(request);
*/
rollback(
request: protos.google.datastore.v1.IRollbackRequest,
request?: protos.google.datastore.v1.IRollbackRequest,
optionsOrCallback?:
| CallOptions
| Callback<
Expand Down Expand Up @@ -755,7 +742,7 @@ export class DatastoreClient {
return this.innerApiCalls.rollback(request, options, callback);
}
allocateIds(
request: protos.google.datastore.v1.IAllocateIdsRequest,
request?: protos.google.datastore.v1.IAllocateIdsRequest,
options?: CallOptions
): Promise<
[
Expand Down Expand Up @@ -803,7 +790,7 @@ export class DatastoreClient {
* const [response] = await client.allocateIds(request);
*/
allocateIds(
request: protos.google.datastore.v1.IAllocateIdsRequest,
request?: protos.google.datastore.v1.IAllocateIdsRequest,
optionsOrCallback?:
| CallOptions
| Callback<
Expand Down Expand Up @@ -842,7 +829,7 @@ export class DatastoreClient {
return this.innerApiCalls.allocateIds(request, options, callback);
}
reserveIds(
request: protos.google.datastore.v1.IReserveIdsRequest,
request?: protos.google.datastore.v1.IReserveIdsRequest,
options?: CallOptions
): Promise<
[
Expand Down Expand Up @@ -892,7 +879,7 @@ export class DatastoreClient {
* const [response] = await client.reserveIds(request);
*/
reserveIds(
request: protos.google.datastore.v1.IReserveIdsRequest,
request?: protos.google.datastore.v1.IReserveIdsRequest,
optionsOrCallback?:
| CallOptions
| Callback<
Expand Down