UNPKG

37.1 kBJavaScriptView Raw
1"use strict";
2// Copyright 2024 Google LLC
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// https://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16// ** This file is automatically generated by gapic-generator-typescript. **
17// ** https://github.com/googleapis/gapic-generator-typescript **
18// ** All changes to this file may be overwritten. **
19Object.defineProperty(exports, "__esModule", { value: true });
20exports.DatastoreClient = void 0;
21const jsonProtos = require("../../protos/protos.json");
22/**
23 * Client JSON configuration object, loaded from
24 * `src/v1/datastore_client_config.json`.
25 * This file defines retry strategy and timeouts for all API methods in this library.
26 */
27const gapicConfig = require("./datastore_client_config.json");
28const version = require('../../../package.json').version;
29/**
30 * Each RPC normalizes the partition IDs of the keys in its input entities,
31 * and always returns entities with keys with normalized partition IDs.
32 * This applies to all keys and entities, including those in values, except keys
33 * with both an empty path and an empty or unset partition ID. Normalization of
34 * input keys sets the project ID (if not already set) to the project ID from
35 * the request.
36 *
37 * @class
38 * @memberof v1
39 */
40class DatastoreClient {
41 /**
42 * Construct an instance of DatastoreClient.
43 *
44 * @param {object} [options] - The configuration object.
45 * The options accepted by the constructor are described in detail
46 * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
47 * The common options are:
48 * @param {object} [options.credentials] - Credentials object.
49 * @param {string} [options.credentials.client_email]
50 * @param {string} [options.credentials.private_key]
51 * @param {string} [options.email] - Account email address. Required when
52 * using a .pem or .p12 keyFilename.
53 * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or
54 * .p12 key downloaded from the Google Developers Console. If you provide
55 * a path to a JSON file, the projectId option below is not necessary.
56 * NOTE: .pem and .p12 require you to specify options.email as well.
57 * @param {number} [options.port] - The port on which to connect to
58 * the remote host.
59 * @param {string} [options.projectId] - The project ID from the Google
60 * Developer's Console, e.g. 'grape-spaceship-123'. We will also check
61 * the environment variable GCLOUD_PROJECT for your project ID. If your
62 * app is running in an environment which supports
63 * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials},
64 * your project ID will be detected automatically.
65 * @param {string} [options.apiEndpoint] - The domain name of the
66 * API remote host.
67 * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
68 * Follows the structure of {@link gapicConfig}.
69 * @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode.
70 * For more information, please check the
71 * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
72 * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you
73 * need to avoid loading the default gRPC version and want to use the fallback
74 * HTTP implementation. Load only fallback version and pass it to the constructor:
75 * ```
76 * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
77 * const client = new DatastoreClient({fallback: true}, gax);
78 * ```
79 */
80 constructor(opts, gaxInstance) {
81 var _a, _b, _c, _d, _e;
82 this._terminated = false;
83 this.descriptors = {
84 page: {},
85 stream: {},
86 longrunning: {},
87 batching: {},
88 };
89 // Ensure that options include all the required fields.
90 const staticMembers = this.constructor;
91 if ((opts === null || opts === void 0 ? void 0 : opts.universe_domain) &&
92 (opts === null || opts === void 0 ? void 0 : opts.universeDomain) &&
93 (opts === null || opts === void 0 ? void 0 : opts.universe_domain) !== (opts === null || opts === void 0 ? void 0 : opts.universeDomain)) {
94 throw new Error('Please set either universe_domain or universeDomain, but not both.');
95 }
96 const universeDomainEnvVar = typeof process === 'object' && typeof process.env === 'object'
97 ? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']
98 : undefined;
99 this._universeDomain =
100 (_c = (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.universeDomain) !== null && _a !== void 0 ? _a : opts === null || opts === void 0 ? void 0 : opts.universe_domain) !== null && _b !== void 0 ? _b : universeDomainEnvVar) !== null && _c !== void 0 ? _c : 'googleapis.com';
101 this._servicePath = 'datastore.' + this._universeDomain;
102 const servicePath = (opts === null || opts === void 0 ? void 0 : opts.servicePath) || (opts === null || opts === void 0 ? void 0 : opts.apiEndpoint) || this._servicePath;
103 this._providedCustomServicePath = !!((opts === null || opts === void 0 ? void 0 : opts.servicePath) || (opts === null || opts === void 0 ? void 0 : opts.apiEndpoint));
104 const port = (opts === null || opts === void 0 ? void 0 : opts.port) || staticMembers.port;
105 const clientConfig = (_d = opts === null || opts === void 0 ? void 0 : opts.clientConfig) !== null && _d !== void 0 ? _d : {};
106 const fallback = (_e = opts === null || opts === void 0 ? void 0 : opts.fallback) !== null && _e !== void 0 ? _e : (typeof window !== 'undefined' && typeof (window === null || window === void 0 ? void 0 : window.fetch) === 'function');
107 opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts);
108 // Request numeric enum values if REST transport is used.
109 opts.numericEnums = true;
110 // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
111 if (servicePath !== this._servicePath && !('scopes' in opts)) {
112 opts['scopes'] = staticMembers.scopes;
113 }
114 // Load google-gax module synchronously if needed
115 if (!gaxInstance) {
116 gaxInstance = require('google-gax');
117 }
118 // Choose either gRPC or proto-over-HTTP implementation of google-gax.
119 this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance;
120 // Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
121 this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
122 // Save options to use in initialize() method.
123 this._opts = opts;
124 // Save the auth object to the client, for use by other methods.
125 this.auth = this._gaxGrpc.auth;
126 // Set useJWTAccessWithScope on the auth object.
127 this.auth.useJWTAccessWithScope = true;
128 // Set defaultServicePath on the auth object.
129 this.auth.defaultServicePath = this._servicePath;
130 // Set the default scopes in auth client if needed.
131 if (servicePath === this._servicePath) {
132 this.auth.defaultScopes = staticMembers.scopes;
133 }
134 // Determine the client header string.
135 const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
136 if (typeof process === 'object' && 'versions' in process) {
137 clientHeader.push(`gl-node/${process.versions.node}`);
138 }
139 else {
140 clientHeader.push(`gl-web/${this._gaxModule.version}`);
141 }
142 if (!opts.fallback) {
143 clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`);
144 }
145 else {
146 clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`);
147 }
148 if (opts.libName && opts.libVersion) {
149 clientHeader.push(`${opts.libName}/${opts.libVersion}`);
150 }
151 // Load the applicable protos.
152 this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
153 const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
154 // This API contains "long-running operations", which return a
155 // an Operation object that allows for tracking of the operation,
156 // rather than holding a request open.
157 const lroOptions = {
158 auth: this.auth,
159 grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
160 };
161 if (opts.fallback) {
162 lroOptions.protoJson = protoFilesRoot;
163 lroOptions.httpRules = [
164 {
165 selector: 'google.longrunning.Operations.CancelOperation',
166 post: '/v1/{name=projects/*/operations/*}:cancel',
167 },
168 {
169 selector: 'google.longrunning.Operations.DeleteOperation',
170 delete: '/v1/{name=projects/*/operations/*}',
171 },
172 {
173 selector: 'google.longrunning.Operations.GetOperation',
174 get: '/v1/{name=projects/*/operations/*}',
175 },
176 {
177 selector: 'google.longrunning.Operations.ListOperations',
178 get: '/v1/{name=projects/*}/operations',
179 },
180 ];
181 }
182 this.operationsClient = this._gaxModule
183 .lro(lroOptions)
184 .operationsClient(opts);
185 this.descriptors.longrunning = {};
186 // Put together the default options sent with requests.
187 this._defaults = this._gaxGrpc.constructSettings('google.datastore.v1.Datastore', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') });
188 // Set up a dictionary of "inner API calls"; the core implementation
189 // of calling the API is handled in `google-gax`, with this code
190 // merely providing the destination and request information.
191 this.innerApiCalls = {};
192 // Add a warn function to the client constructor so it can be easily tested.
193 this.warn = this._gaxModule.warn;
194 }
195 /**
196 * Initialize the client.
197 * Performs asynchronous operations (such as authentication) and prepares the client.
198 * This function will be called automatically when any class method is called for the
199 * first time, but if you need to initialize it before calling an actual method,
200 * feel free to call initialize() directly.
201 *
202 * You can await on this method if you want to make sure the client is initialized.
203 *
204 * @returns {Promise} A promise that resolves to an authenticated service stub.
205 */
206 initialize() {
207 // If the client stub promise is already initialized, return immediately.
208 if (this.datastoreStub) {
209 return this.datastoreStub;
210 }
211 // Put together the "service stub" for
212 // google.datastore.v1.Datastore.
213 this.datastoreStub = this._gaxGrpc.createStub(this._opts.fallback
214 ? this._protos.lookupService('google.datastore.v1.Datastore')
215 : // eslint-disable-next-line @typescript-eslint/no-explicit-any
216 this._protos.google.datastore.v1.Datastore, this._opts, this._providedCustomServicePath);
217 // Iterate over each of the methods that the service provides
218 // and create an API call method for each.
219 const datastoreStubMethods = [
220 'lookup',
221 'runQuery',
222 'runAggregationQuery',
223 'beginTransaction',
224 'commit',
225 'rollback',
226 'allocateIds',
227 'reserveIds',
228 ];
229 for (const methodName of datastoreStubMethods) {
230 const callPromise = this.datastoreStub.then(stub => (...args) => {
231 if (this._terminated) {
232 return Promise.reject('The client has already been closed.');
233 }
234 const func = stub[methodName];
235 return func.apply(stub, args);
236 }, (err) => () => {
237 throw err;
238 });
239 const descriptor = undefined;
240 const apiCall = this._gaxModule.createApiCall(callPromise, this._defaults[methodName], descriptor, this._opts.fallback);
241 this.innerApiCalls[methodName] = apiCall;
242 }
243 return this.datastoreStub;
244 }
245 /**
246 * The DNS address for this API service.
247 * @deprecated Use the apiEndpoint method of the client instance.
248 * @returns {string} The DNS address for this service.
249 */
250 static get servicePath() {
251 if (typeof process === 'object' &&
252 typeof process.emitWarning === 'function') {
253 process.emitWarning('Static servicePath is deprecated, please use the instance method instead.', 'DeprecationWarning');
254 }
255 return 'datastore.googleapis.com';
256 }
257 /**
258 * The DNS address for this API service - same as servicePath.
259 * @deprecated Use the apiEndpoint method of the client instance.
260 * @returns {string} The DNS address for this service.
261 */
262 static get apiEndpoint() {
263 if (typeof process === 'object' &&
264 typeof process.emitWarning === 'function') {
265 process.emitWarning('Static apiEndpoint is deprecated, please use the instance method instead.', 'DeprecationWarning');
266 }
267 return 'datastore.googleapis.com';
268 }
269 /**
270 * The DNS address for this API service.
271 * @returns {string} The DNS address for this service.
272 */
273 get apiEndpoint() {
274 return this._servicePath;
275 }
276 get universeDomain() {
277 return this._universeDomain;
278 }
279 /**
280 * The port for this API service.
281 * @returns {number} The default port for this service.
282 */
283 static get port() {
284 return 443;
285 }
286 /**
287 * The scopes needed to make gRPC calls for every method defined
288 * in this service.
289 * @returns {string[]} List of default scopes.
290 */
291 static get scopes() {
292 return [
293 'https://www.googleapis.com/auth/cloud-platform',
294 'https://www.googleapis.com/auth/datastore',
295 ];
296 }
297 /**
298 * Return the project ID used by this class.
299 * @returns {Promise} A promise that resolves to string containing the project ID.
300 */
301 getProjectId(callback) {
302 if (callback) {
303 this.auth.getProjectId(callback);
304 return;
305 }
306 return this.auth.getProjectId();
307 }
308 lookup(request, optionsOrCallback, callback) {
309 var _a, _b, _c, _d;
310 request = request || {};
311 let options;
312 if (typeof optionsOrCallback === 'function' && callback === undefined) {
313 callback = optionsOrCallback;
314 options = {};
315 }
316 else {
317 options = optionsOrCallback;
318 }
319 options = options || {};
320 options.otherArgs = options.otherArgs || {};
321 options.otherArgs.headers = options.otherArgs.headers || {};
322 const routingParameter = {};
323 {
324 const fieldValue = request.projectId;
325 if (fieldValue !== undefined && fieldValue !== null) {
326 const match = fieldValue.toString().match(RegExp('(?<project_id>.*)'));
327 if (match) {
328 const parameterValue = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a['project_id']) !== null && _b !== void 0 ? _b : fieldValue;
329 Object.assign(routingParameter, { project_id: parameterValue });
330 }
331 }
332 }
333 {
334 const fieldValue = request.databaseId;
335 if (fieldValue !== undefined && fieldValue !== null) {
336 const match = fieldValue.toString().match(RegExp('(?<database_id>.*)'));
337 if (match) {
338 const parameterValue = (_d = (_c = match.groups) === null || _c === void 0 ? void 0 : _c['database_id']) !== null && _d !== void 0 ? _d : fieldValue;
339 Object.assign(routingParameter, { database_id: parameterValue });
340 }
341 }
342 }
343 options.otherArgs.headers['x-goog-request-params'] =
344 this._gaxModule.routingHeader.fromParams(routingParameter);
345 this.initialize();
346 return this.innerApiCalls.lookup(request, options, callback);
347 }
348 runQuery(request, optionsOrCallback, callback) {
349 var _a, _b, _c, _d;
350 request = request || {};
351 let options;
352 if (typeof optionsOrCallback === 'function' && callback === undefined) {
353 callback = optionsOrCallback;
354 options = {};
355 }
356 else {
357 options = optionsOrCallback;
358 }
359 options = options || {};
360 options.otherArgs = options.otherArgs || {};
361 options.otherArgs.headers = options.otherArgs.headers || {};
362 const routingParameter = {};
363 {
364 const fieldValue = request.projectId;
365 if (fieldValue !== undefined && fieldValue !== null) {
366 const match = fieldValue.toString().match(RegExp('(?<project_id>.*)'));
367 if (match) {
368 const parameterValue = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a['project_id']) !== null && _b !== void 0 ? _b : fieldValue;
369 Object.assign(routingParameter, { project_id: parameterValue });
370 }
371 }
372 }
373 {
374 const fieldValue = request.databaseId;
375 if (fieldValue !== undefined && fieldValue !== null) {
376 const match = fieldValue.toString().match(RegExp('(?<database_id>.*)'));
377 if (match) {
378 const parameterValue = (_d = (_c = match.groups) === null || _c === void 0 ? void 0 : _c['database_id']) !== null && _d !== void 0 ? _d : fieldValue;
379 Object.assign(routingParameter, { database_id: parameterValue });
380 }
381 }
382 }
383 options.otherArgs.headers['x-goog-request-params'] =
384 this._gaxModule.routingHeader.fromParams(routingParameter);
385 this.initialize();
386 return this.innerApiCalls.runQuery(request, options, callback);
387 }
388 runAggregationQuery(request, optionsOrCallback, callback) {
389 var _a, _b, _c, _d;
390 request = request || {};
391 let options;
392 if (typeof optionsOrCallback === 'function' && callback === undefined) {
393 callback = optionsOrCallback;
394 options = {};
395 }
396 else {
397 options = optionsOrCallback;
398 }
399 options = options || {};
400 options.otherArgs = options.otherArgs || {};
401 options.otherArgs.headers = options.otherArgs.headers || {};
402 const routingParameter = {};
403 {
404 const fieldValue = request.projectId;
405 if (fieldValue !== undefined && fieldValue !== null) {
406 const match = fieldValue.toString().match(RegExp('(?<project_id>.*)'));
407 if (match) {
408 const parameterValue = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a['project_id']) !== null && _b !== void 0 ? _b : fieldValue;
409 Object.assign(routingParameter, { project_id: parameterValue });
410 }
411 }
412 }
413 {
414 const fieldValue = request.databaseId;
415 if (fieldValue !== undefined && fieldValue !== null) {
416 const match = fieldValue.toString().match(RegExp('(?<database_id>.*)'));
417 if (match) {
418 const parameterValue = (_d = (_c = match.groups) === null || _c === void 0 ? void 0 : _c['database_id']) !== null && _d !== void 0 ? _d : fieldValue;
419 Object.assign(routingParameter, { database_id: parameterValue });
420 }
421 }
422 }
423 options.otherArgs.headers['x-goog-request-params'] =
424 this._gaxModule.routingHeader.fromParams(routingParameter);
425 this.initialize();
426 return this.innerApiCalls.runAggregationQuery(request, options, callback);
427 }
428 beginTransaction(request, optionsOrCallback, callback) {
429 var _a, _b, _c, _d;
430 request = request || {};
431 let options;
432 if (typeof optionsOrCallback === 'function' && callback === undefined) {
433 callback = optionsOrCallback;
434 options = {};
435 }
436 else {
437 options = optionsOrCallback;
438 }
439 options = options || {};
440 options.otherArgs = options.otherArgs || {};
441 options.otherArgs.headers = options.otherArgs.headers || {};
442 const routingParameter = {};
443 {
444 const fieldValue = request.projectId;
445 if (fieldValue !== undefined && fieldValue !== null) {
446 const match = fieldValue.toString().match(RegExp('(?<project_id>.*)'));
447 if (match) {
448 const parameterValue = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a['project_id']) !== null && _b !== void 0 ? _b : fieldValue;
449 Object.assign(routingParameter, { project_id: parameterValue });
450 }
451 }
452 }
453 {
454 const fieldValue = request.databaseId;
455 if (fieldValue !== undefined && fieldValue !== null) {
456 const match = fieldValue.toString().match(RegExp('(?<database_id>.*)'));
457 if (match) {
458 const parameterValue = (_d = (_c = match.groups) === null || _c === void 0 ? void 0 : _c['database_id']) !== null && _d !== void 0 ? _d : fieldValue;
459 Object.assign(routingParameter, { database_id: parameterValue });
460 }
461 }
462 }
463 options.otherArgs.headers['x-goog-request-params'] =
464 this._gaxModule.routingHeader.fromParams(routingParameter);
465 this.initialize();
466 return this.innerApiCalls.beginTransaction(request, options, callback);
467 }
468 commit(request, optionsOrCallback, callback) {
469 var _a, _b, _c, _d;
470 request = request || {};
471 let options;
472 if (typeof optionsOrCallback === 'function' && callback === undefined) {
473 callback = optionsOrCallback;
474 options = {};
475 }
476 else {
477 options = optionsOrCallback;
478 }
479 options = options || {};
480 options.otherArgs = options.otherArgs || {};
481 options.otherArgs.headers = options.otherArgs.headers || {};
482 const routingParameter = {};
483 {
484 const fieldValue = request.projectId;
485 if (fieldValue !== undefined && fieldValue !== null) {
486 const match = fieldValue.toString().match(RegExp('(?<project_id>.*)'));
487 if (match) {
488 const parameterValue = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a['project_id']) !== null && _b !== void 0 ? _b : fieldValue;
489 Object.assign(routingParameter, { project_id: parameterValue });
490 }
491 }
492 }
493 {
494 const fieldValue = request.databaseId;
495 if (fieldValue !== undefined && fieldValue !== null) {
496 const match = fieldValue.toString().match(RegExp('(?<database_id>.*)'));
497 if (match) {
498 const parameterValue = (_d = (_c = match.groups) === null || _c === void 0 ? void 0 : _c['database_id']) !== null && _d !== void 0 ? _d : fieldValue;
499 Object.assign(routingParameter, { database_id: parameterValue });
500 }
501 }
502 }
503 options.otherArgs.headers['x-goog-request-params'] =
504 this._gaxModule.routingHeader.fromParams(routingParameter);
505 this.initialize();
506 return this.innerApiCalls.commit(request, options, callback);
507 }
508 rollback(request, optionsOrCallback, callback) {
509 var _a, _b, _c, _d;
510 request = request || {};
511 let options;
512 if (typeof optionsOrCallback === 'function' && callback === undefined) {
513 callback = optionsOrCallback;
514 options = {};
515 }
516 else {
517 options = optionsOrCallback;
518 }
519 options = options || {};
520 options.otherArgs = options.otherArgs || {};
521 options.otherArgs.headers = options.otherArgs.headers || {};
522 const routingParameter = {};
523 {
524 const fieldValue = request.projectId;
525 if (fieldValue !== undefined && fieldValue !== null) {
526 const match = fieldValue.toString().match(RegExp('(?<project_id>.*)'));
527 if (match) {
528 const parameterValue = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a['project_id']) !== null && _b !== void 0 ? _b : fieldValue;
529 Object.assign(routingParameter, { project_id: parameterValue });
530 }
531 }
532 }
533 {
534 const fieldValue = request.databaseId;
535 if (fieldValue !== undefined && fieldValue !== null) {
536 const match = fieldValue.toString().match(RegExp('(?<database_id>.*)'));
537 if (match) {
538 const parameterValue = (_d = (_c = match.groups) === null || _c === void 0 ? void 0 : _c['database_id']) !== null && _d !== void 0 ? _d : fieldValue;
539 Object.assign(routingParameter, { database_id: parameterValue });
540 }
541 }
542 }
543 options.otherArgs.headers['x-goog-request-params'] =
544 this._gaxModule.routingHeader.fromParams(routingParameter);
545 this.initialize();
546 return this.innerApiCalls.rollback(request, options, callback);
547 }
548 allocateIds(request, optionsOrCallback, callback) {
549 var _a, _b, _c, _d;
550 request = request || {};
551 let options;
552 if (typeof optionsOrCallback === 'function' && callback === undefined) {
553 callback = optionsOrCallback;
554 options = {};
555 }
556 else {
557 options = optionsOrCallback;
558 }
559 options = options || {};
560 options.otherArgs = options.otherArgs || {};
561 options.otherArgs.headers = options.otherArgs.headers || {};
562 const routingParameter = {};
563 {
564 const fieldValue = request.projectId;
565 if (fieldValue !== undefined && fieldValue !== null) {
566 const match = fieldValue.toString().match(RegExp('(?<project_id>.*)'));
567 if (match) {
568 const parameterValue = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a['project_id']) !== null && _b !== void 0 ? _b : fieldValue;
569 Object.assign(routingParameter, { project_id: parameterValue });
570 }
571 }
572 }
573 {
574 const fieldValue = request.databaseId;
575 if (fieldValue !== undefined && fieldValue !== null) {
576 const match = fieldValue.toString().match(RegExp('(?<database_id>.*)'));
577 if (match) {
578 const parameterValue = (_d = (_c = match.groups) === null || _c === void 0 ? void 0 : _c['database_id']) !== null && _d !== void 0 ? _d : fieldValue;
579 Object.assign(routingParameter, { database_id: parameterValue });
580 }
581 }
582 }
583 options.otherArgs.headers['x-goog-request-params'] =
584 this._gaxModule.routingHeader.fromParams(routingParameter);
585 this.initialize();
586 return this.innerApiCalls.allocateIds(request, options, callback);
587 }
588 reserveIds(request, optionsOrCallback, callback) {
589 var _a, _b, _c, _d;
590 request = request || {};
591 let options;
592 if (typeof optionsOrCallback === 'function' && callback === undefined) {
593 callback = optionsOrCallback;
594 options = {};
595 }
596 else {
597 options = optionsOrCallback;
598 }
599 options = options || {};
600 options.otherArgs = options.otherArgs || {};
601 options.otherArgs.headers = options.otherArgs.headers || {};
602 const routingParameter = {};
603 {
604 const fieldValue = request.projectId;
605 if (fieldValue !== undefined && fieldValue !== null) {
606 const match = fieldValue.toString().match(RegExp('(?<project_id>.*)'));
607 if (match) {
608 const parameterValue = (_b = (_a = match.groups) === null || _a === void 0 ? void 0 : _a['project_id']) !== null && _b !== void 0 ? _b : fieldValue;
609 Object.assign(routingParameter, { project_id: parameterValue });
610 }
611 }
612 }
613 {
614 const fieldValue = request.databaseId;
615 if (fieldValue !== undefined && fieldValue !== null) {
616 const match = fieldValue.toString().match(RegExp('(?<database_id>.*)'));
617 if (match) {
618 const parameterValue = (_d = (_c = match.groups) === null || _c === void 0 ? void 0 : _c['database_id']) !== null && _d !== void 0 ? _d : fieldValue;
619 Object.assign(routingParameter, { database_id: parameterValue });
620 }
621 }
622 }
623 options.otherArgs.headers['x-goog-request-params'] =
624 this._gaxModule.routingHeader.fromParams(routingParameter);
625 this.initialize();
626 return this.innerApiCalls.reserveIds(request, options, callback);
627 }
628 /**
629 * Gets the latest state of a long-running operation. Clients can use this
630 * method to poll the operation result at intervals as recommended by the API
631 * service.
632 *
633 * @param {Object} request - The request object that will be sent.
634 * @param {string} request.name - The name of the operation resource.
635 * @param {Object=} options
636 * Optional parameters. You can override the default settings for this call,
637 * e.g, timeout, retries, paginations, etc. See {@link
638 * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions}
639 * for the details.
640 * @param {function(?Error, ?Object)=} callback
641 * The function which will be called with the result of the API call.
642 *
643 * The second parameter to the callback is an object representing
644 * {@link google.longrunning.Operation | google.longrunning.Operation}.
645 * @return {Promise} - The promise which resolves to an array.
646 * The first element of the array is an object representing
647 * {@link google.longrunning.Operation | google.longrunning.Operation}.
648 * The promise has a method named "cancel" which cancels the ongoing API call.
649 *
650 * @example
651 * ```
652 * const client = longrunning.operationsClient();
653 * const name = '';
654 * const [response] = await client.getOperation({name});
655 * // doThingsWith(response)
656 * ```
657 */
658 getOperation(request, options, callback) {
659 return this.operationsClient.getOperation(request, options, callback);
660 }
661 /**
662 * Lists operations that match the specified filter in the request. If the
663 * server doesn't support this method, it returns `UNIMPLEMENTED`. Returns an iterable object.
664 *
665 * For-await-of syntax is used with the iterable to recursively get response element on-demand.
666 *
667 * @param {Object} request - The request object that will be sent.
668 * @param {string} request.name - The name of the operation collection.
669 * @param {string} request.filter - The standard list filter.
670 * @param {number=} request.pageSize -
671 * The maximum number of resources contained in the underlying API
672 * response. If page streaming is performed per-resource, this
673 * parameter does not affect the return value. If page streaming is
674 * performed per-page, this determines the maximum number of
675 * resources in a page.
676 * @param {Object=} options
677 * Optional parameters. You can override the default settings for this call,
678 * e.g, timeout, retries, paginations, etc. See {@link
679 * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions} for the
680 * details.
681 * @returns {Object}
682 * An iterable Object that conforms to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols | iteration protocols}.
683 *
684 * @example
685 * ```
686 * const client = longrunning.operationsClient();
687 * for await (const response of client.listOperationsAsync(request));
688 * // doThingsWith(response)
689 * ```
690 */
691 listOperationsAsync(request, options) {
692 return this.operationsClient.listOperationsAsync(request, options);
693 }
694 /**
695 * Starts asynchronous cancellation on a long-running operation. The server
696 * makes a best effort to cancel the operation, but success is not
697 * guaranteed. If the server doesn't support this method, it returns
698 * `google.rpc.Code.UNIMPLEMENTED`. Clients can use
699 * {@link Operations.GetOperation} or
700 * other methods to check whether the cancellation succeeded or whether the
701 * operation completed despite cancellation. On successful cancellation,
702 * the operation is not deleted; instead, it becomes an operation with
703 * an {@link Operation.error} value with a {@link google.rpc.Status.code} of
704 * 1, corresponding to `Code.CANCELLED`.
705 *
706 * @param {Object} request - The request object that will be sent.
707 * @param {string} request.name - The name of the operation resource to be cancelled.
708 * @param {Object=} options
709 * Optional parameters. You can override the default settings for this call,
710 * e.g, timeout, retries, paginations, etc. See {@link
711 * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions} for the
712 * details.
713 * @param {function(?Error)=} callback
714 * The function which will be called with the result of the API call.
715 * @return {Promise} - The promise which resolves when API call finishes.
716 * The promise has a method named "cancel" which cancels the ongoing API
717 * call.
718 *
719 * @example
720 * ```
721 * const client = longrunning.operationsClient();
722 * await client.cancelOperation({name: ''});
723 * ```
724 */
725 cancelOperation(request, options, callback) {
726 return this.operationsClient.cancelOperation(request, options, callback);
727 }
728 /**
729 * Deletes a long-running operation. This method indicates that the client is
730 * no longer interested in the operation result. It does not cancel the
731 * operation. If the server doesn't support this method, it returns
732 * `google.rpc.Code.UNIMPLEMENTED`.
733 *
734 * @param {Object} request - The request object that will be sent.
735 * @param {string} request.name - The name of the operation resource to be deleted.
736 * @param {Object=} options
737 * Optional parameters. You can override the default settings for this call,
738 * e.g, timeout, retries, paginations, etc. See {@link
739 * https://googleapis.github.io/gax-nodejs/global.html#CallOptions | gax.CallOptions}
740 * for the details.
741 * @param {function(?Error)=} callback
742 * The function which will be called with the result of the API call.
743 * @return {Promise} - The promise which resolves when API call finishes.
744 * The promise has a method named "cancel" which cancels the ongoing API
745 * call.
746 *
747 * @example
748 * ```
749 * const client = longrunning.operationsClient();
750 * await client.deleteOperation({name: ''});
751 * ```
752 */
753 deleteOperation(request, options, callback) {
754 return this.operationsClient.deleteOperation(request, options, callback);
755 }
756 /**
757 * Terminate the gRPC channel and close the client.
758 *
759 * The client will no longer be usable and all future behavior is undefined.
760 * @returns {Promise} A promise that resolves when the client is closed.
761 */
762 close() {
763 if (this.datastoreStub && !this._terminated) {
764 return this.datastoreStub.then(stub => {
765 this._terminated = true;
766 stub.close();
767 this.operationsClient.close();
768 });
769 }
770 return Promise.resolve();
771 }
772}
773exports.DatastoreClient = DatastoreClient;
774//# sourceMappingURL=datastore_client.js.map
\No newline at end of file