diff --git a/package.json b/package.json index 4e4cba53d..e8fb19ec2 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "file-system": "^2.2.2", "fs-extra": "^8.1.0", "get-stdin": "^7.0.0", - "google-gax": "^1.7.5", + "google-gax": "^1.8.0", "nunjucks": "^3.1.3", "object-hash": "^2.0.0", "protobufjs": "^6.8.8", diff --git a/templates/typescript_gapic/package.json.njk b/templates/typescript_gapic/package.json.njk index fe1710ad6..8c8f34937 100644 --- a/templates/typescript_gapic/package.json.njk +++ b/templates/typescript_gapic/package.json.njk @@ -27,7 +27,7 @@ limitations under the License. "build/protos" ], "dependencies": { - "google-gax": "^1.7.5" + "google-gax": "^1.8.0" }, "devDependencies": { "@types/node": "^12.0.0", diff --git a/templates/typescript_gapic/src/$version/$service_client.ts.njk b/templates/typescript_gapic/src/$version/$service_client.ts.njk index 7d4d8e07e..e12b0dc6a 100644 --- a/templates/typescript_gapic/src/$version/$service_client.ts.njk +++ b/templates/typescript_gapic/src/$version/$service_client.ts.njk @@ -21,7 +21,9 @@ limitations under the License. import * as gax from 'google-gax'; import * as path from 'path'; - +{% if (service.paging.length > 0) %} +import { Transform } from 'stream'; +{%- endif %} import * as protosTypes from '../../protos/protos'; import * as gapicConfig from './{{ service.name.toSnakeCase() }}_client_config.json'; @@ -566,6 +568,19 @@ export class {{ service.name }}Client { {%- endif %} return this._innerApiCalls.{{ method.name.toCamelCase() }}(request, options, callback); } + + {{ method.name.toCamelCase() }}Stream( + request?: protosTypes{{ util.toInterface(method.inputInterface) }}, + options?: gax.CallOptions | {}): + Transform{ + request = request || {}; + const callSettings = new gax.CallSettings(options); + return this._descriptors.page.{{ method.name.toCamelCase() }}.createStream( + this._innerApiCalls.{{ method.name.toCamelCase() }} as gax.GaxCall, + request, + callSettings + ); + } {%- endfor %} {%- if (service.pathTemplates.length > 0) %} // -------------------- diff --git a/templates/typescript_gapic/test/gapic-$service-$version.ts.njk b/templates/typescript_gapic/test/gapic-$service-$version.ts.njk index 2c8efadf1..b51fa9d51 100644 --- a/templates/typescript_gapic/test/gapic-$service-$version.ts.njk +++ b/templates/typescript_gapic/test/gapic-$service-$version.ts.njk @@ -356,5 +356,29 @@ describe('{{ service.name }}Client', () => { }); }); }); + describe('{{ method.name.toCamelCase() }}Stream', () => { + it('invokes {{ method.name.toCamelCase() }}Stream without error', done => { + const client = new {{ service.name.toLowerCase() }}Module.{{ api.naming.version }}.{{ service.name }}Client({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + // Mock request + {{ util.initRequestWithHeaderParam(method) }} + // Mock response + const expectedResponse = {}; + // Mock Grpc layer + client._innerApiCalls.{{ method.name.toCamelCase() }} = (actualRequest: {}, options: {}, callback: Callback) => { + assert.deepStrictEqual(actualRequest, request); + callback(null, expectedResponse); + }; + const stream = client.{{ method.name.toCamelCase() }}Stream(request, {}).on('data', (response: {}) =>{ + assert.deepStrictEqual(response, expectedResponse); + done(); + }).on('error', (err: FakeError) => { + done(err); + }); + stream.write(request); + }); + }); {%- endfor %} }); diff --git a/typescript/test/test_application_js/index.js b/typescript/test/test_application_js/index.js index 7011c420d..0fd2a942e 100644 --- a/typescript/test/test_application_js/index.js +++ b/typescript/test/test_application_js/index.js @@ -50,6 +50,7 @@ function runTest(client, opts) { testChat(client); } testPagedExpand(client); + testPagedExpandStream(client); testWait(client); } @@ -98,6 +99,28 @@ function testPagedExpand(client) { }); } +function testPagedExpandStream(client) { + it('pagedExpand with streaming', async () => { + const words = ['I', 'did', 'not', 'even', 'know', 'it', 'works']; + const request = { + content: words.join(' '), + pageSize: 2, + }; + const result = await new Promise((resolve, reject) => { + const stream = client.pagedExpandStream(request); + const result = []; + stream.on('data', response => { + result.push(response.content); + }); + stream.on('end', () => { + resolve(result); + }); + stream.on('error', reject); + }); + assert.deepStrictEqual(words, result); + }); +} + function testCollect(client) { it('collect', async () => { const words = ['nobody', 'ever', 'reads', 'test', 'input']; diff --git a/typescript/test/test_application_ts/package.json b/typescript/test/test_application_ts/package.json index 3a5c8fda9..dc8492d8e 100644 --- a/typescript/test/test_application_ts/package.json +++ b/typescript/test/test_application_ts/package.json @@ -16,7 +16,7 @@ }, "devDependencies": { "gts": "^1.1.0", - "typescript": "~3.5.0", + "typescript": "~3.7.0", "@types/node": "^10.0.3", "@types/mocha": "^5.2.7", "mocha": "^6.2.0", diff --git a/typescript/test/testdata/keymanager/package.json.baseline b/typescript/test/testdata/keymanager/package.json.baseline index 43324fff8..582197081 100644 --- a/typescript/test/testdata/keymanager/package.json.baseline +++ b/typescript/test/testdata/keymanager/package.json.baseline @@ -10,7 +10,7 @@ "build/protos" ], "dependencies": { - "google-gax": "^1.7.5" + "google-gax": "^1.8.0" }, "devDependencies": { "@types/node": "^12.0.0", diff --git a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline index 9e6e47d69..2c5e28d12 100644 --- a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline +++ b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline @@ -19,6 +19,7 @@ import * as gax from 'google-gax'; import * as path from 'path'; +import { Transform } from 'stream'; import * as protosTypes from '../../protos/protos'; import * as gapicConfig from './key_management_service_client_config.json'; @@ -1631,6 +1632,19 @@ export class KeyManagementServiceClient { 'parent': request.parent || '', }); return this._innerApiCalls.listKeyRings(request, options, callback); + } + + listKeyRingsStream( + request?: protosTypes.google.cloud.kms.v1.IListKeyRingsRequest, + options?: gax.CallOptions | {}): + Transform{ + request = request || {}; + const callSettings = new gax.CallSettings(options); + return this._descriptors.page.listKeyRings.createStream( + this._innerApiCalls.listKeyRings as gax.GaxCall, + request, + callSettings + ); } listCryptoKeys( request: protosTypes.google.cloud.kms.v1.IListCryptoKeysRequest, @@ -1716,6 +1730,19 @@ export class KeyManagementServiceClient { 'parent': request.parent || '', }); return this._innerApiCalls.listCryptoKeys(request, options, callback); + } + + listCryptoKeysStream( + request?: protosTypes.google.cloud.kms.v1.IListCryptoKeysRequest, + options?: gax.CallOptions | {}): + Transform{ + request = request || {}; + const callSettings = new gax.CallSettings(options); + return this._descriptors.page.listCryptoKeys.createStream( + this._innerApiCalls.listCryptoKeys as gax.GaxCall, + request, + callSettings + ); } listCryptoKeyVersions( request: protosTypes.google.cloud.kms.v1.IListCryptoKeyVersionsRequest, @@ -1802,6 +1829,19 @@ export class KeyManagementServiceClient { 'parent': request.parent || '', }); return this._innerApiCalls.listCryptoKeyVersions(request, options, callback); + } + + listCryptoKeyVersionsStream( + request?: protosTypes.google.cloud.kms.v1.IListCryptoKeyVersionsRequest, + options?: gax.CallOptions | {}): + Transform{ + request = request || {}; + const callSettings = new gax.CallSettings(options); + return this._descriptors.page.listCryptoKeyVersions.createStream( + this._innerApiCalls.listCryptoKeyVersions as gax.GaxCall, + request, + callSettings + ); } listImportJobs( request: protosTypes.google.cloud.kms.v1.IListImportJobsRequest, @@ -1885,5 +1925,18 @@ export class KeyManagementServiceClient { 'parent': request.parent || '', }); return this._innerApiCalls.listImportJobs(request, options, callback); + } + + listImportJobsStream( + request?: protosTypes.google.cloud.kms.v1.IListImportJobsRequest, + options?: gax.CallOptions | {}): + Transform{ + request = request || {}; + const callSettings = new gax.CallSettings(options); + return this._descriptors.page.listImportJobs.createStream( + this._innerApiCalls.listImportJobs as gax.GaxCall, + request, + callSettings + ); } } diff --git a/typescript/test/testdata/keymanager/test/gapic-key_management_service-v1.ts.baseline b/typescript/test/testdata/keymanager/test/gapic-key_management_service-v1.ts.baseline index 1f51424e8..d855b4395 100644 --- a/typescript/test/testdata/keymanager/test/gapic-key_management_service-v1.ts.baseline +++ b/typescript/test/testdata/keymanager/test/gapic-key_management_service-v1.ts.baseline @@ -982,6 +982,30 @@ describe('KeyManagementServiceClient', () => { }); }); }); + describe('listKeyRingsStream', () => { + it('invokes listKeyRingsStream without error', done => { + const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + // Mock request + const request: protosTypes.google.cloud.kms.v1.IListKeyRingsRequest = {}; + // Mock response + const expectedResponse = {}; + // Mock Grpc layer + client._innerApiCalls.listKeyRings = (actualRequest: {}, options: {}, callback: Callback) => { + assert.deepStrictEqual(actualRequest, request); + callback(null, expectedResponse); + }; + const stream = client.listKeyRingsStream(request, {}).on('data', (response: {}) =>{ + assert.deepStrictEqual(response, expectedResponse); + done(); + }).on('error', (err: FakeError) => { + done(err); + }); + stream.write(request); + }); + }); describe('listCryptoKeys', () => { it('invokes listCryptoKeys without error', done => { const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ @@ -1004,6 +1028,30 @@ describe('KeyManagementServiceClient', () => { }); }); }); + describe('listCryptoKeysStream', () => { + it('invokes listCryptoKeysStream without error', done => { + const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + // Mock request + const request: protosTypes.google.cloud.kms.v1.IListCryptoKeysRequest = {}; + // Mock response + const expectedResponse = {}; + // Mock Grpc layer + client._innerApiCalls.listCryptoKeys = (actualRequest: {}, options: {}, callback: Callback) => { + assert.deepStrictEqual(actualRequest, request); + callback(null, expectedResponse); + }; + const stream = client.listCryptoKeysStream(request, {}).on('data', (response: {}) =>{ + assert.deepStrictEqual(response, expectedResponse); + done(); + }).on('error', (err: FakeError) => { + done(err); + }); + stream.write(request); + }); + }); describe('listCryptoKeyVersions', () => { it('invokes listCryptoKeyVersions without error', done => { const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ @@ -1026,6 +1074,30 @@ describe('KeyManagementServiceClient', () => { }); }); }); + describe('listCryptoKeyVersionsStream', () => { + it('invokes listCryptoKeyVersionsStream without error', done => { + const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + // Mock request + const request: protosTypes.google.cloud.kms.v1.IListCryptoKeyVersionsRequest = {}; + // Mock response + const expectedResponse = {}; + // Mock Grpc layer + client._innerApiCalls.listCryptoKeyVersions = (actualRequest: {}, options: {}, callback: Callback) => { + assert.deepStrictEqual(actualRequest, request); + callback(null, expectedResponse); + }; + const stream = client.listCryptoKeyVersionsStream(request, {}).on('data', (response: {}) =>{ + assert.deepStrictEqual(response, expectedResponse); + done(); + }).on('error', (err: FakeError) => { + done(err); + }); + stream.write(request); + }); + }); describe('listImportJobs', () => { it('invokes listImportJobs without error', done => { const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ @@ -1048,4 +1120,28 @@ describe('KeyManagementServiceClient', () => { }); }); }); + describe('listImportJobsStream', () => { + it('invokes listImportJobsStream without error', done => { + const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + // Mock request + const request: protosTypes.google.cloud.kms.v1.IListImportJobsRequest = {}; + // Mock response + const expectedResponse = {}; + // Mock Grpc layer + client._innerApiCalls.listImportJobs = (actualRequest: {}, options: {}, callback: Callback) => { + assert.deepStrictEqual(actualRequest, request); + callback(null, expectedResponse); + }; + const stream = client.listImportJobsStream(request, {}).on('data', (response: {}) =>{ + assert.deepStrictEqual(response, expectedResponse); + done(); + }).on('error', (err: FakeError) => { + done(err); + }); + stream.write(request); + }); + }); }); diff --git a/typescript/test/testdata/showcase/package.json.baseline b/typescript/test/testdata/showcase/package.json.baseline index ab2b1dba7..caf7afedd 100644 --- a/typescript/test/testdata/showcase/package.json.baseline +++ b/typescript/test/testdata/showcase/package.json.baseline @@ -10,7 +10,7 @@ "build/protos" ], "dependencies": { - "google-gax": "^1.7.5" + "google-gax": "^1.8.0" }, "devDependencies": { "@types/node": "^12.0.0", diff --git a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline index 6fff43538..eb238410f 100644 --- a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline +++ b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline @@ -19,6 +19,7 @@ import * as gax from 'google-gax'; import * as path from 'path'; +import { Transform } from 'stream'; import * as protosTypes from '../../protos/protos'; import * as gapicConfig from './echo_client_config.json'; @@ -562,5 +563,18 @@ export class EchoClient { } options = options || {}; return this._innerApiCalls.pagedExpand(request, options, callback); + } + + pagedExpandStream( + request?: protosTypes.google.showcase.v1beta1.IPagedExpandRequest, + options?: gax.CallOptions | {}): + Transform{ + request = request || {}; + const callSettings = new gax.CallSettings(options); + return this._descriptors.page.pagedExpand.createStream( + this._innerApiCalls.pagedExpand as gax.GaxCall, + request, + callSettings + ); } } diff --git a/typescript/test/testdata/showcase/test/gapic-echo-v1beta1.ts.baseline b/typescript/test/testdata/showcase/test/gapic-echo-v1beta1.ts.baseline index 90e1a9d3e..225a5153c 100644 --- a/typescript/test/testdata/showcase/test/gapic-echo-v1beta1.ts.baseline +++ b/typescript/test/testdata/showcase/test/gapic-echo-v1beta1.ts.baseline @@ -339,4 +339,28 @@ describe('EchoClient', () => { }); }); }); + describe('pagedExpandStream', () => { + it('invokes pagedExpandStream without error', done => { + const client = new echoModule.v1beta1.EchoClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + // Mock request + const request: protosTypes.google.showcase.v1beta1.IPagedExpandRequest = {}; + // Mock response + const expectedResponse = {}; + // Mock Grpc layer + client._innerApiCalls.pagedExpand = (actualRequest: {}, options: {}, callback: Callback) => { + assert.deepStrictEqual(actualRequest, request); + callback(null, expectedResponse); + }; + const stream = client.pagedExpandStream(request, {}).on('data', (response: {}) =>{ + assert.deepStrictEqual(response, expectedResponse); + done(); + }).on('error', (err: FakeError) => { + done(err); + }); + stream.write(request); + }); + }); }); diff --git a/typescript/test/testdata/texttospeech/package.json.baseline b/typescript/test/testdata/texttospeech/package.json.baseline index 610e11867..f30c2517d 100644 --- a/typescript/test/testdata/texttospeech/package.json.baseline +++ b/typescript/test/testdata/texttospeech/package.json.baseline @@ -10,7 +10,7 @@ "build/protos" ], "dependencies": { - "google-gax": "^1.7.5" + "google-gax": "^1.8.0" }, "devDependencies": { "@types/node": "^12.0.0", diff --git a/typescript/test/testdata/translate/package.json.baseline b/typescript/test/testdata/translate/package.json.baseline index 8c23a4445..653ffe9c3 100644 --- a/typescript/test/testdata/translate/package.json.baseline +++ b/typescript/test/testdata/translate/package.json.baseline @@ -10,7 +10,7 @@ "build/protos" ], "dependencies": { - "google-gax": "^1.7.5" + "google-gax": "^1.8.0" }, "devDependencies": { "@types/node": "^12.0.0", diff --git a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline index 5fc8e7465..a3a763bca 100644 --- a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline +++ b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline @@ -19,6 +19,7 @@ import * as gax from 'google-gax'; import * as path from 'path'; +import { Transform } from 'stream'; import * as protosTypes from '../../protos/protos'; import * as gapicConfig from './translation_service_client_config.json'; @@ -998,6 +999,19 @@ export class TranslationServiceClient { 'parent': request.parent || '', }); return this._innerApiCalls.listGlossaries(request, options, callback); + } + + listGlossariesStream( + request?: protosTypes.google.cloud.translation.v3beta1.IListGlossariesRequest, + options?: gax.CallOptions | {}): + Transform{ + request = request || {}; + const callSettings = new gax.CallSettings(options); + return this._descriptors.page.listGlossaries.createStream( + this._innerApiCalls.listGlossaries as gax.GaxCall, + request, + callSettings + ); } // -------------------- // -- Path templates -- diff --git a/typescript/test/testdata/translate/test/gapic-translation_service-v3beta1.ts.baseline b/typescript/test/testdata/translate/test/gapic-translation_service-v3beta1.ts.baseline index 33d9175d9..ab034796a 100644 --- a/typescript/test/testdata/translate/test/gapic-translation_service-v3beta1.ts.baseline +++ b/typescript/test/testdata/translate/test/gapic-translation_service-v3beta1.ts.baseline @@ -461,4 +461,28 @@ describe('TranslationServiceClient', () => { }); }); }); + describe('listGlossariesStream', () => { + it('invokes listGlossariesStream without error', done => { + const client = new translationserviceModule.v3beta1.TranslationServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + // Mock request + const request: protosTypes.google.cloud.translation.v3beta1.IListGlossariesRequest = {}; + // Mock response + const expectedResponse = {}; + // Mock Grpc layer + client._innerApiCalls.listGlossaries = (actualRequest: {}, options: {}, callback: Callback) => { + assert.deepStrictEqual(actualRequest, request); + callback(null, expectedResponse); + }; + const stream = client.listGlossariesStream(request, {}).on('data', (response: {}) =>{ + assert.deepStrictEqual(response, expectedResponse); + done(); + }).on('error', (err: FakeError) => { + done(err); + }); + stream.write(request); + }); + }); });