@google-cloud/bigquery-storage-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 (29) hide show
  1. package/README.md +111 -0
  2. package/build/protos/google/cloud/bigquery/storage/v1/annotations.proto +28 -0
  3. package/build/protos/google/cloud/bigquery/storage/v1/arrow.proto +89 -0
  4. package/build/protos/google/cloud/bigquery/storage/v1/avro.proto +81 -0
  5. package/build/protos/google/cloud/bigquery/storage/v1/protobuf.proto +48 -0
  6. package/build/protos/google/cloud/bigquery/storage/v1/storage.proto +786 -0
  7. package/build/protos/google/cloud/bigquery/storage/v1/stream.proto +335 -0
  8. package/build/protos/google/cloud/bigquery/storage/v1/table.proto +200 -0
  9. package/build/protos/protos.d.ts +12699 -0
  10. package/build/protos/protos.js +1 -0
  11. package/build/protos/protos.json +1 -0
  12. package/build/src/index.d.ts +14 -0
  13. package/build/src/index.js +30 -0
  14. package/build/src/index.js.map +1 -0
  15. package/build/src/v1/big_query_read_client.d.ts +424 -0
  16. package/build/src/v1/big_query_read_client.js +689 -0
  17. package/build/src/v1/big_query_read_client.js.map +1 -0
  18. package/build/src/v1/big_query_read_client_config.json +44 -0
  19. package/build/src/v1/big_query_read_proto_list.json +9 -0
  20. package/build/src/v1/big_query_write_client.d.ts +486 -0
  21. package/build/src/v1/big_query_write_client.js +835 -0
  22. package/build/src/v1/big_query_write_client.js.map +1 -0
  23. package/build/src/v1/big_query_write_client_config.json +73 -0
  24. package/build/src/v1/big_query_write_proto_list.json +9 -0
  25. package/build/src/v1/gapic_metadata.json +117 -0
  26. package/build/src/v1/index.d.ts +2 -0
  27. package/build/src/v1/index.js +25 -0
  28. package/build/src/v1/index.js.map +1 -0
  29. package/package.json +66 -0
@@ -0,0 +1,835 @@
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.BigQueryWriteClient = void 0;
21
+ const stream_1 = require("stream");
22
+ const jsonProtos = require("../../protos/protos.json");
23
+ const google_gax_1 = require("google-gax");
24
+ /**
25
+ * Client JSON configuration object, loaded from
26
+ * `src/v1/big_query_write_client_config.json`.
27
+ * This file defines retry strategy and timeouts for all API methods in this library.
28
+ */
29
+ const gapicConfig = require("./big_query_write_client_config.json");
30
+ const version = require('../../../package.json').version;
31
+ /**
32
+ * BigQuery Write API.
33
+ *
34
+ * The Write API can be used to write data to BigQuery.
35
+ *
36
+ * For supplementary information about the Write API, see:
37
+ * https://cloud.google.com/bigquery/docs/write-api
38
+ * @class
39
+ * @memberof v1
40
+ */
41
+ class BigQueryWriteClient {
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('bigquery-storage-api');
52
+ auth;
53
+ descriptors = {
54
+ page: {},
55
+ stream: {},
56
+ longrunning: {},
57
+ batching: {},
58
+ };
59
+ warn;
60
+ innerApiCalls;
61
+ pathTemplates;
62
+ bigQueryWriteStub;
63
+ /**
64
+ * Construct an instance of BigQueryWriteClient.
65
+ *
66
+ * @param {object} [options] - The configuration object.
67
+ * The options accepted by the constructor are described in detail
68
+ * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
69
+ * The common options are:
70
+ * @param {object} [options.credentials] - Credentials object.
71
+ * @param {string} [options.credentials.client_email]
72
+ * @param {string} [options.credentials.private_key]
73
+ * @param {string} [options.email] - Account email address. Required when
74
+ * using a .pem or .p12 keyFilename.
75
+ * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or
76
+ * .p12 key downloaded from the Google Developers Console. If you provide
77
+ * a path to a JSON file, the projectId option below is not necessary.
78
+ * NOTE: .pem and .p12 require you to specify options.email as well.
79
+ * @param {number} [options.port] - The port on which to connect to
80
+ * the remote host.
81
+ * @param {string} [options.projectId] - The project ID from the Google
82
+ * Developer's Console, e.g. 'grape-spaceship-123'. We will also check
83
+ * the environment variable GCLOUD_PROJECT for your project ID. If your
84
+ * app is running in an environment which supports
85
+ * {@link https://cloud.google.com/docs/authentication/application-default-credentials Application Default Credentials},
86
+ * your project ID will be detected automatically.
87
+ * @param {string} [options.apiEndpoint] - The domain name of the
88
+ * API remote host.
89
+ * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
90
+ * Follows the structure of {@link gapicConfig}.
91
+ * @param {boolean} [options.fallback] - Use HTTP/1.1 REST mode.
92
+ * For more information, please check the
93
+ * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
94
+ * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you
95
+ * need to avoid loading the default gRPC version and want to use the fallback
96
+ * HTTP implementation. Load only fallback version and pass it to the constructor:
97
+ * ```
98
+ * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
99
+ * const client = new BigQueryWriteClient({fallback: true}, gax);
100
+ * ```
101
+ */
102
+ constructor(opts, gaxInstance) {
103
+ // Ensure that options include all the required fields.
104
+ const staticMembers = this.constructor;
105
+ if (opts?.universe_domain &&
106
+ opts?.universeDomain &&
107
+ opts?.universe_domain !== opts?.universeDomain) {
108
+ throw new Error('Please set either universe_domain or universeDomain, but not both.');
109
+ }
110
+ const universeDomainEnvVar = typeof process === 'object' && typeof process.env === 'object'
111
+ ? process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']
112
+ : undefined;
113
+ this._universeDomain =
114
+ opts?.universeDomain ??
115
+ opts?.universe_domain ??
116
+ universeDomainEnvVar ??
117
+ 'googleapis.com';
118
+ this._servicePath = 'bigquerystorage.' + this._universeDomain;
119
+ const servicePath = opts?.servicePath || opts?.apiEndpoint || this._servicePath;
120
+ this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint);
121
+ const port = opts?.port || staticMembers.port;
122
+ const clientConfig = opts?.clientConfig ?? {};
123
+ const fallback = opts?.fallback ??
124
+ (typeof window !== 'undefined' && typeof window?.fetch === 'function');
125
+ opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts);
126
+ // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
127
+ if (servicePath !== this._servicePath && !('scopes' in opts)) {
128
+ opts['scopes'] = staticMembers.scopes;
129
+ }
130
+ // Load google-gax module synchronously if needed
131
+ if (!gaxInstance) {
132
+ gaxInstance = require('google-gax');
133
+ }
134
+ // Choose either gRPC or proto-over-HTTP implementation of google-gax.
135
+ this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance;
136
+ // Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
137
+ this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
138
+ // Save options to use in initialize() method.
139
+ this._opts = opts;
140
+ // Save the auth object to the client, for use by other methods.
141
+ this.auth = this._gaxGrpc.auth;
142
+ // Set useJWTAccessWithScope on the auth object.
143
+ this.auth.useJWTAccessWithScope = true;
144
+ // Set defaultServicePath on the auth object.
145
+ this.auth.defaultServicePath = this._servicePath;
146
+ // Set the default scopes in auth client if needed.
147
+ if (servicePath === this._servicePath) {
148
+ this.auth.defaultScopes = staticMembers.scopes;
149
+ }
150
+ // Determine the client header string.
151
+ const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
152
+ if (typeof process === 'object' && 'versions' in process) {
153
+ clientHeader.push(`gl-node/${process.versions.node}`);
154
+ }
155
+ else {
156
+ clientHeader.push(`gl-web/${this._gaxModule.version}`);
157
+ }
158
+ if (!opts.fallback) {
159
+ clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`);
160
+ }
161
+ else {
162
+ clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`);
163
+ }
164
+ if (opts.libName && opts.libVersion) {
165
+ clientHeader.push(`${opts.libName}/${opts.libVersion}`);
166
+ }
167
+ // Load the applicable protos.
168
+ this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
169
+ // This API contains "path templates"; forward-slash-separated
170
+ // identifiers to uniquely identify resources within the API.
171
+ // Create useful helper objects for these.
172
+ this.pathTemplates = {
173
+ projectPathTemplate: new this._gaxModule.PathTemplate('projects/{project}'),
174
+ readSessionPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/sessions/{session}'),
175
+ readStreamPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/sessions/{session}/streams/{stream}'),
176
+ tablePathTemplate: new this._gaxModule.PathTemplate('projects/{project}/datasets/{dataset}/tables/{table}'),
177
+ writeStreamPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/datasets/{dataset}/tables/{table}/streams/{stream}'),
178
+ };
179
+ // Some of the methods on this service provide streaming responses.
180
+ // Provide descriptors for these.
181
+ this.descriptors.stream = {
182
+ appendRows: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.BIDI_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries),
183
+ };
184
+ // Put together the default options sent with requests.
185
+ this._defaults = this._gaxGrpc.constructSettings('google.cloud.bigquery.storage.v1.BigQueryWrite', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') });
186
+ // Set up a dictionary of "inner API calls"; the core implementation
187
+ // of calling the API is handled in `google-gax`, with this code
188
+ // merely providing the destination and request information.
189
+ this.innerApiCalls = {};
190
+ // Add a warn function to the client constructor so it can be easily tested.
191
+ this.warn = this._gaxModule.warn;
192
+ }
193
+ /**
194
+ * Initialize the client.
195
+ * Performs asynchronous operations (such as authentication) and prepares the client.
196
+ * This function will be called automatically when any class method is called for the
197
+ * first time, but if you need to initialize it before calling an actual method,
198
+ * feel free to call initialize() directly.
199
+ *
200
+ * You can await on this method if you want to make sure the client is initialized.
201
+ *
202
+ * @returns {Promise} A promise that resolves to an authenticated service stub.
203
+ */
204
+ initialize() {
205
+ // If the client stub promise is already initialized, return immediately.
206
+ if (this.bigQueryWriteStub) {
207
+ return this.bigQueryWriteStub;
208
+ }
209
+ // Put together the "service stub" for
210
+ // google.cloud.bigquery.storage.v1.BigQueryWrite.
211
+ this.bigQueryWriteStub = this._gaxGrpc.createStub(this._opts.fallback
212
+ ? this._protos.lookupService('google.cloud.bigquery.storage.v1.BigQueryWrite')
213
+ : // eslint-disable-next-line @typescript-eslint/no-explicit-any
214
+ this._protos.google.cloud.bigquery.storage.v1.BigQueryWrite, this._opts, this._providedCustomServicePath);
215
+ // Iterate over each of the methods that the service provides
216
+ // and create an API call method for each.
217
+ const bigQueryWriteStubMethods = [
218
+ 'createWriteStream',
219
+ 'appendRows',
220
+ 'getWriteStream',
221
+ 'finalizeWriteStream',
222
+ 'batchCommitWriteStreams',
223
+ 'flushRows',
224
+ ];
225
+ for (const methodName of bigQueryWriteStubMethods) {
226
+ const callPromise = this.bigQueryWriteStub.then((stub) => (...args) => {
227
+ if (this._terminated) {
228
+ if (methodName in this.descriptors.stream) {
229
+ const stream = new stream_1.PassThrough({ objectMode: true });
230
+ setImmediate(() => {
231
+ stream.emit('error', new this._gaxModule.GoogleError('The client has already been closed.'));
232
+ });
233
+ return stream;
234
+ }
235
+ return Promise.reject('The client has already been closed.');
236
+ }
237
+ const func = stub[methodName];
238
+ return func.apply(stub, args);
239
+ }, (err) => () => {
240
+ throw err;
241
+ });
242
+ const descriptor = this.descriptors.stream[methodName] || undefined;
243
+ const apiCall = this._gaxModule.createApiCall(callPromise, this._defaults[methodName], descriptor, this._opts.fallback);
244
+ this.innerApiCalls[methodName] = apiCall;
245
+ }
246
+ return this.bigQueryWriteStub;
247
+ }
248
+ /**
249
+ * The DNS address for this API service.
250
+ * @deprecated Use the apiEndpoint method of the client instance.
251
+ * @returns {string} The DNS address for this service.
252
+ */
253
+ static get servicePath() {
254
+ if (typeof process === 'object' &&
255
+ typeof process.emitWarning === 'function') {
256
+ process.emitWarning('Static servicePath is deprecated, please use the instance method instead.', 'DeprecationWarning');
257
+ }
258
+ return 'bigquerystorage.googleapis.com';
259
+ }
260
+ /**
261
+ * The DNS address for this API service - same as servicePath.
262
+ * @deprecated Use the apiEndpoint method of the client instance.
263
+ * @returns {string} The DNS address for this service.
264
+ */
265
+ static get apiEndpoint() {
266
+ if (typeof process === 'object' &&
267
+ typeof process.emitWarning === 'function') {
268
+ process.emitWarning('Static apiEndpoint is deprecated, please use the instance method instead.', 'DeprecationWarning');
269
+ }
270
+ return 'bigquerystorage.googleapis.com';
271
+ }
272
+ /**
273
+ * The DNS address for this API service.
274
+ * @returns {string} The DNS address for this service.
275
+ */
276
+ get apiEndpoint() {
277
+ return this._servicePath;
278
+ }
279
+ get universeDomain() {
280
+ return this._universeDomain;
281
+ }
282
+ /**
283
+ * The port for this API service.
284
+ * @returns {number} The default port for this service.
285
+ */
286
+ static get port() {
287
+ return 443;
288
+ }
289
+ /**
290
+ * The scopes needed to make gRPC calls for every method defined
291
+ * in this service.
292
+ * @returns {string[]} List of default scopes.
293
+ */
294
+ static get scopes() {
295
+ return [
296
+ 'https://www.googleapis.com/auth/bigquery',
297
+ 'https://www.googleapis.com/auth/bigquery.insertdata',
298
+ 'https://www.googleapis.com/auth/cloud-platform',
299
+ ];
300
+ }
301
+ /**
302
+ * Return the project ID used by this class.
303
+ * @returns {Promise} A promise that resolves to string containing the project ID.
304
+ */
305
+ getProjectId(callback) {
306
+ if (callback) {
307
+ this.auth.getProjectId(callback);
308
+ return;
309
+ }
310
+ return this.auth.getProjectId();
311
+ }
312
+ createWriteStream(request, optionsOrCallback, callback) {
313
+ request = request || {};
314
+ let options;
315
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
316
+ callback = optionsOrCallback;
317
+ options = {};
318
+ }
319
+ else {
320
+ options = optionsOrCallback;
321
+ }
322
+ options = options || {};
323
+ options.otherArgs = options.otherArgs || {};
324
+ options.otherArgs.headers = options.otherArgs.headers || {};
325
+ options.otherArgs.headers['x-goog-request-params'] =
326
+ this._gaxModule.routingHeader.fromParams({
327
+ parent: request.parent ?? '',
328
+ });
329
+ this.initialize().catch((err) => {
330
+ throw err;
331
+ });
332
+ this._log.info('createWriteStream request %j', request);
333
+ const wrappedCallback = callback
334
+ ? (error, response, options, rawResponse) => {
335
+ this._log.info('createWriteStream response %j', response);
336
+ callback(error, response, options, rawResponse); // We verified callback above.
337
+ }
338
+ : undefined;
339
+ return this.innerApiCalls
340
+ .createWriteStream(request, options, wrappedCallback)
341
+ ?.then(([response, options, rawResponse]) => {
342
+ this._log.info('createWriteStream response %j', response);
343
+ return [response, options, rawResponse];
344
+ })
345
+ .catch((error) => {
346
+ if (error &&
347
+ 'statusDetails' in error &&
348
+ error.statusDetails instanceof Array) {
349
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
350
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
351
+ }
352
+ throw error;
353
+ });
354
+ }
355
+ getWriteStream(request, optionsOrCallback, callback) {
356
+ request = request || {};
357
+ let options;
358
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
359
+ callback = optionsOrCallback;
360
+ options = {};
361
+ }
362
+ else {
363
+ options = optionsOrCallback;
364
+ }
365
+ options = options || {};
366
+ options.otherArgs = options.otherArgs || {};
367
+ options.otherArgs.headers = options.otherArgs.headers || {};
368
+ options.otherArgs.headers['x-goog-request-params'] =
369
+ this._gaxModule.routingHeader.fromParams({
370
+ name: request.name ?? '',
371
+ });
372
+ this.initialize().catch((err) => {
373
+ throw err;
374
+ });
375
+ this._log.info('getWriteStream request %j', request);
376
+ const wrappedCallback = callback
377
+ ? (error, response, options, rawResponse) => {
378
+ this._log.info('getWriteStream response %j', response);
379
+ callback(error, response, options, rawResponse); // We verified callback above.
380
+ }
381
+ : undefined;
382
+ return this.innerApiCalls
383
+ .getWriteStream(request, options, wrappedCallback)
384
+ ?.then(([response, options, rawResponse]) => {
385
+ this._log.info('getWriteStream response %j', response);
386
+ return [response, options, rawResponse];
387
+ })
388
+ .catch((error) => {
389
+ if (error &&
390
+ 'statusDetails' in error &&
391
+ error.statusDetails instanceof Array) {
392
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
393
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
394
+ }
395
+ throw error;
396
+ });
397
+ }
398
+ finalizeWriteStream(request, optionsOrCallback, callback) {
399
+ request = request || {};
400
+ let options;
401
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
402
+ callback = optionsOrCallback;
403
+ options = {};
404
+ }
405
+ else {
406
+ options = optionsOrCallback;
407
+ }
408
+ options = options || {};
409
+ options.otherArgs = options.otherArgs || {};
410
+ options.otherArgs.headers = options.otherArgs.headers || {};
411
+ options.otherArgs.headers['x-goog-request-params'] =
412
+ this._gaxModule.routingHeader.fromParams({
413
+ name: request.name ?? '',
414
+ });
415
+ this.initialize().catch((err) => {
416
+ throw err;
417
+ });
418
+ this._log.info('finalizeWriteStream request %j', request);
419
+ const wrappedCallback = callback
420
+ ? (error, response, options, rawResponse) => {
421
+ this._log.info('finalizeWriteStream response %j', response);
422
+ callback(error, response, options, rawResponse); // We verified callback above.
423
+ }
424
+ : undefined;
425
+ return this.innerApiCalls
426
+ .finalizeWriteStream(request, options, wrappedCallback)
427
+ ?.then(([response, options, rawResponse]) => {
428
+ this._log.info('finalizeWriteStream response %j', response);
429
+ return [response, options, rawResponse];
430
+ })
431
+ .catch((error) => {
432
+ if (error &&
433
+ 'statusDetails' in error &&
434
+ error.statusDetails instanceof Array) {
435
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
436
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
437
+ }
438
+ throw error;
439
+ });
440
+ }
441
+ batchCommitWriteStreams(request, optionsOrCallback, callback) {
442
+ request = request || {};
443
+ let options;
444
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
445
+ callback = optionsOrCallback;
446
+ options = {};
447
+ }
448
+ else {
449
+ options = optionsOrCallback;
450
+ }
451
+ options = options || {};
452
+ options.otherArgs = options.otherArgs || {};
453
+ options.otherArgs.headers = options.otherArgs.headers || {};
454
+ options.otherArgs.headers['x-goog-request-params'] =
455
+ this._gaxModule.routingHeader.fromParams({
456
+ parent: request.parent ?? '',
457
+ });
458
+ this.initialize().catch((err) => {
459
+ throw err;
460
+ });
461
+ this._log.info('batchCommitWriteStreams request %j', request);
462
+ const wrappedCallback = callback
463
+ ? (error, response, options, rawResponse) => {
464
+ this._log.info('batchCommitWriteStreams response %j', response);
465
+ callback(error, response, options, rawResponse); // We verified callback above.
466
+ }
467
+ : undefined;
468
+ return this.innerApiCalls
469
+ .batchCommitWriteStreams(request, options, wrappedCallback)
470
+ ?.then(([response, options, rawResponse]) => {
471
+ this._log.info('batchCommitWriteStreams response %j', response);
472
+ return [response, options, rawResponse];
473
+ })
474
+ .catch((error) => {
475
+ if (error &&
476
+ 'statusDetails' in error &&
477
+ error.statusDetails instanceof Array) {
478
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
479
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
480
+ }
481
+ throw error;
482
+ });
483
+ }
484
+ flushRows(request, optionsOrCallback, callback) {
485
+ request = request || {};
486
+ let options;
487
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
488
+ callback = optionsOrCallback;
489
+ options = {};
490
+ }
491
+ else {
492
+ options = optionsOrCallback;
493
+ }
494
+ options = options || {};
495
+ options.otherArgs = options.otherArgs || {};
496
+ options.otherArgs.headers = options.otherArgs.headers || {};
497
+ options.otherArgs.headers['x-goog-request-params'] =
498
+ this._gaxModule.routingHeader.fromParams({
499
+ write_stream: request.writeStream ?? '',
500
+ });
501
+ this.initialize().catch((err) => {
502
+ throw err;
503
+ });
504
+ this._log.info('flushRows request %j', request);
505
+ const wrappedCallback = callback
506
+ ? (error, response, options, rawResponse) => {
507
+ this._log.info('flushRows response %j', response);
508
+ callback(error, response, options, rawResponse); // We verified callback above.
509
+ }
510
+ : undefined;
511
+ return this.innerApiCalls
512
+ .flushRows(request, options, wrappedCallback)
513
+ ?.then(([response, options, rawResponse]) => {
514
+ this._log.info('flushRows response %j', response);
515
+ return [response, options, rawResponse];
516
+ })
517
+ .catch((error) => {
518
+ if (error &&
519
+ 'statusDetails' in error &&
520
+ error.statusDetails instanceof Array) {
521
+ const protos = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
522
+ error.statusDetails = (0, google_gax_1.decodeAnyProtosInArray)(error.statusDetails, protos);
523
+ }
524
+ throw error;
525
+ });
526
+ }
527
+ /**
528
+ * Appends data to the given stream.
529
+ *
530
+ * If `offset` is specified, the `offset` is checked against the end of
531
+ * stream. The server returns `OUT_OF_RANGE` in `AppendRowsResponse` if an
532
+ * attempt is made to append to an offset beyond the current end of the stream
533
+ * or `ALREADY_EXISTS` if user provides an `offset` that has already been
534
+ * written to. User can retry with adjusted offset within the same RPC
535
+ * connection. If `offset` is not specified, append happens at the end of the
536
+ * stream.
537
+ *
538
+ * The response contains an optional offset at which the append
539
+ * happened. No offset information will be returned for appends to a
540
+ * default stream.
541
+ *
542
+ * Responses are received in the same order in which requests are sent.
543
+ * There will be one response for each successful inserted request. Responses
544
+ * may optionally embed error information if the originating AppendRequest was
545
+ * not successfully processed.
546
+ *
547
+ * The specifics of when successfully appended data is made visible to the
548
+ * table are governed by the type of stream:
549
+ *
550
+ * * For COMMITTED streams (which includes the default stream), data is
551
+ * visible immediately upon successful append.
552
+ *
553
+ * * For BUFFERED streams, data is made visible via a subsequent `FlushRows`
554
+ * rpc which advances a cursor to a newer offset in the stream.
555
+ *
556
+ * * For PENDING streams, data is not made visible until the stream itself is
557
+ * finalized (via the `FinalizeWriteStream` rpc), and the stream is explicitly
558
+ * committed via the `BatchCommitWriteStreams` rpc.
559
+ *
560
+ * @param {object} [options]
561
+ * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
562
+ * @returns {Stream}
563
+ * An object stream which is both readable and writable. It accepts objects
564
+ * representing {@link protos.google.cloud.bigquery.storage.v1.AppendRowsRequest|AppendRowsRequest} for write() method, and
565
+ * will emit objects representing {@link protos.google.cloud.bigquery.storage.v1.AppendRowsResponse|AppendRowsResponse} on 'data' event asynchronously.
566
+ * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming | documentation }
567
+ * for more details and examples.
568
+ * @example <caption>include:samples/generated/v1/big_query_write.append_rows.js</caption>
569
+ * region_tag:bigquerystorage_v1_generated_BigQueryWrite_AppendRows_async
570
+ */
571
+ appendRows(options) {
572
+ this.initialize().catch((err) => {
573
+ throw err;
574
+ });
575
+ this._log.info('appendRows stream %j', options);
576
+ return this.innerApiCalls.appendRows(null, options);
577
+ }
578
+ // --------------------
579
+ // -- Path templates --
580
+ // --------------------
581
+ /**
582
+ * Return a fully-qualified project resource name string.
583
+ *
584
+ * @param {string} project
585
+ * @returns {string} Resource name string.
586
+ */
587
+ projectPath(project) {
588
+ return this.pathTemplates.projectPathTemplate.render({
589
+ project: project,
590
+ });
591
+ }
592
+ /**
593
+ * Parse the project from Project resource.
594
+ *
595
+ * @param {string} projectName
596
+ * A fully-qualified path representing Project resource.
597
+ * @returns {string} A string representing the project.
598
+ */
599
+ matchProjectFromProjectName(projectName) {
600
+ return this.pathTemplates.projectPathTemplate.match(projectName).project;
601
+ }
602
+ /**
603
+ * Return a fully-qualified readSession resource name string.
604
+ *
605
+ * @param {string} project
606
+ * @param {string} location
607
+ * @param {string} session
608
+ * @returns {string} Resource name string.
609
+ */
610
+ readSessionPath(project, location, session) {
611
+ return this.pathTemplates.readSessionPathTemplate.render({
612
+ project: project,
613
+ location: location,
614
+ session: session,
615
+ });
616
+ }
617
+ /**
618
+ * Parse the project from ReadSession resource.
619
+ *
620
+ * @param {string} readSessionName
621
+ * A fully-qualified path representing ReadSession resource.
622
+ * @returns {string} A string representing the project.
623
+ */
624
+ matchProjectFromReadSessionName(readSessionName) {
625
+ return this.pathTemplates.readSessionPathTemplate.match(readSessionName)
626
+ .project;
627
+ }
628
+ /**
629
+ * Parse the location from ReadSession resource.
630
+ *
631
+ * @param {string} readSessionName
632
+ * A fully-qualified path representing ReadSession resource.
633
+ * @returns {string} A string representing the location.
634
+ */
635
+ matchLocationFromReadSessionName(readSessionName) {
636
+ return this.pathTemplates.readSessionPathTemplate.match(readSessionName)
637
+ .location;
638
+ }
639
+ /**
640
+ * Parse the session from ReadSession resource.
641
+ *
642
+ * @param {string} readSessionName
643
+ * A fully-qualified path representing ReadSession resource.
644
+ * @returns {string} A string representing the session.
645
+ */
646
+ matchSessionFromReadSessionName(readSessionName) {
647
+ return this.pathTemplates.readSessionPathTemplate.match(readSessionName)
648
+ .session;
649
+ }
650
+ /**
651
+ * Return a fully-qualified readStream resource name string.
652
+ *
653
+ * @param {string} project
654
+ * @param {string} location
655
+ * @param {string} session
656
+ * @param {string} stream
657
+ * @returns {string} Resource name string.
658
+ */
659
+ readStreamPath(project, location, session, stream) {
660
+ return this.pathTemplates.readStreamPathTemplate.render({
661
+ project: project,
662
+ location: location,
663
+ session: session,
664
+ stream: stream,
665
+ });
666
+ }
667
+ /**
668
+ * Parse the project from ReadStream resource.
669
+ *
670
+ * @param {string} readStreamName
671
+ * A fully-qualified path representing ReadStream resource.
672
+ * @returns {string} A string representing the project.
673
+ */
674
+ matchProjectFromReadStreamName(readStreamName) {
675
+ return this.pathTemplates.readStreamPathTemplate.match(readStreamName)
676
+ .project;
677
+ }
678
+ /**
679
+ * Parse the location from ReadStream resource.
680
+ *
681
+ * @param {string} readStreamName
682
+ * A fully-qualified path representing ReadStream resource.
683
+ * @returns {string} A string representing the location.
684
+ */
685
+ matchLocationFromReadStreamName(readStreamName) {
686
+ return this.pathTemplates.readStreamPathTemplate.match(readStreamName)
687
+ .location;
688
+ }
689
+ /**
690
+ * Parse the session from ReadStream resource.
691
+ *
692
+ * @param {string} readStreamName
693
+ * A fully-qualified path representing ReadStream resource.
694
+ * @returns {string} A string representing the session.
695
+ */
696
+ matchSessionFromReadStreamName(readStreamName) {
697
+ return this.pathTemplates.readStreamPathTemplate.match(readStreamName)
698
+ .session;
699
+ }
700
+ /**
701
+ * Parse the stream from ReadStream resource.
702
+ *
703
+ * @param {string} readStreamName
704
+ * A fully-qualified path representing ReadStream resource.
705
+ * @returns {string} A string representing the stream.
706
+ */
707
+ matchStreamFromReadStreamName(readStreamName) {
708
+ return this.pathTemplates.readStreamPathTemplate.match(readStreamName)
709
+ .stream;
710
+ }
711
+ /**
712
+ * Return a fully-qualified table resource name string.
713
+ *
714
+ * @param {string} project
715
+ * @param {string} dataset
716
+ * @param {string} table
717
+ * @returns {string} Resource name string.
718
+ */
719
+ tablePath(project, dataset, table) {
720
+ return this.pathTemplates.tablePathTemplate.render({
721
+ project: project,
722
+ dataset: dataset,
723
+ table: table,
724
+ });
725
+ }
726
+ /**
727
+ * Parse the project from Table resource.
728
+ *
729
+ * @param {string} tableName
730
+ * A fully-qualified path representing Table resource.
731
+ * @returns {string} A string representing the project.
732
+ */
733
+ matchProjectFromTableName(tableName) {
734
+ return this.pathTemplates.tablePathTemplate.match(tableName).project;
735
+ }
736
+ /**
737
+ * Parse the dataset from Table resource.
738
+ *
739
+ * @param {string} tableName
740
+ * A fully-qualified path representing Table resource.
741
+ * @returns {string} A string representing the dataset.
742
+ */
743
+ matchDatasetFromTableName(tableName) {
744
+ return this.pathTemplates.tablePathTemplate.match(tableName).dataset;
745
+ }
746
+ /**
747
+ * Parse the table from Table resource.
748
+ *
749
+ * @param {string} tableName
750
+ * A fully-qualified path representing Table resource.
751
+ * @returns {string} A string representing the table.
752
+ */
753
+ matchTableFromTableName(tableName) {
754
+ return this.pathTemplates.tablePathTemplate.match(tableName).table;
755
+ }
756
+ /**
757
+ * Return a fully-qualified writeStream resource name string.
758
+ *
759
+ * @param {string} project
760
+ * @param {string} dataset
761
+ * @param {string} table
762
+ * @param {string} stream
763
+ * @returns {string} Resource name string.
764
+ */
765
+ writeStreamPath(project, dataset, table, stream) {
766
+ return this.pathTemplates.writeStreamPathTemplate.render({
767
+ project: project,
768
+ dataset: dataset,
769
+ table: table,
770
+ stream: stream,
771
+ });
772
+ }
773
+ /**
774
+ * Parse the project from WriteStream resource.
775
+ *
776
+ * @param {string} writeStreamName
777
+ * A fully-qualified path representing WriteStream resource.
778
+ * @returns {string} A string representing the project.
779
+ */
780
+ matchProjectFromWriteStreamName(writeStreamName) {
781
+ return this.pathTemplates.writeStreamPathTemplate.match(writeStreamName)
782
+ .project;
783
+ }
784
+ /**
785
+ * Parse the dataset from WriteStream resource.
786
+ *
787
+ * @param {string} writeStreamName
788
+ * A fully-qualified path representing WriteStream resource.
789
+ * @returns {string} A string representing the dataset.
790
+ */
791
+ matchDatasetFromWriteStreamName(writeStreamName) {
792
+ return this.pathTemplates.writeStreamPathTemplate.match(writeStreamName)
793
+ .dataset;
794
+ }
795
+ /**
796
+ * Parse the table from WriteStream resource.
797
+ *
798
+ * @param {string} writeStreamName
799
+ * A fully-qualified path representing WriteStream resource.
800
+ * @returns {string} A string representing the table.
801
+ */
802
+ matchTableFromWriteStreamName(writeStreamName) {
803
+ return this.pathTemplates.writeStreamPathTemplate.match(writeStreamName)
804
+ .table;
805
+ }
806
+ /**
807
+ * Parse the stream from WriteStream resource.
808
+ *
809
+ * @param {string} writeStreamName
810
+ * A fully-qualified path representing WriteStream resource.
811
+ * @returns {string} A string representing the stream.
812
+ */
813
+ matchStreamFromWriteStreamName(writeStreamName) {
814
+ return this.pathTemplates.writeStreamPathTemplate.match(writeStreamName)
815
+ .stream;
816
+ }
817
+ /**
818
+ * Terminate the gRPC channel and close the client.
819
+ *
820
+ * The client will no longer be usable and all future behavior is undefined.
821
+ * @returns {Promise} A promise that resolves when the client is closed.
822
+ */
823
+ close() {
824
+ if (this.bigQueryWriteStub && !this._terminated) {
825
+ return this.bigQueryWriteStub.then((stub) => {
826
+ this._log.info('ending gRPC channel');
827
+ this._terminated = true;
828
+ stub.close();
829
+ });
830
+ }
831
+ return Promise.resolve();
832
+ }
833
+ }
834
+ exports.BigQueryWriteClient = BigQueryWriteClient;
835
+ //# sourceMappingURL=big_query_write_client.js.map