@google-cloud/datastore-api 0.1.0

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