-
Notifications
You must be signed in to change notification settings - Fork 120
feat!: v3 is now the default API surface #355
Conversation
BREAKING CHANGE: this signficantly changes TypeScript types and API surface from the v2 API. Reference samples for help making the migration from v2 to v3.
fb24b8f
to
1b3400c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this PR we move from v2
(a hand written TypeScript veneer) to an auto-generated v3
as the default export.
Whereas v3beta1
did not have any TypeScript typings, v3
uses the new TypeScript micro-generator and does have types.
@@ -1,3 +1,6 @@ | |||
{ | |||
"extends": "gts/tslint.json" | |||
"extends": "gts/tslint.json", | |||
"rules": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these new rules were added during @alexander-fenster's generation of the client, and I believe are automatic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll have two instances of @ts-ignore
for now (in the place where we load protos). They might go away later if I figure out how to deal with that. Those are only for dealing with dynamic protos.
"rootDir": ".", | ||
"outDir": "build" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these new rules were added during @alexander-fenster's generation of the client, and I believe are automatic.
for (const input of INPUT) { | ||
const [result] = await translate.detectLanguage({ | ||
content: input.content, | ||
parent: `projects/${projectId}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like a slightly more difficult to work with API surface, that we now need to provide a parent
. I noticed this was also the case for v3beta1
@nnegrey?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Translate now has user managed resources and locations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 so this is an expected change to the API? thought it might be a bug, and was talking to @alexander-fenster about it, sounds like it's not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only difference with JS gapic-generator is that gapic-generator provides a helper function for this:
const contents = [];
const targetLanguageCode = '';
const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');
// ^^^ we don't have this yet in TypeScript so
// we need to concatenate a string manually
const request = {
contents: contents,
targetLanguageCode: targetLanguageCode,
parent: formattedParent,
};
const [response] = await client.translateText(request);
We will provide the same interface soon (@xiaozhenliu-gg5 is working on it). But the fact that it now requires project
to be passed is an API change, not much we can do here.
samples/translate.js
Outdated
}); | ||
|
||
const projectId = await translate.getProjectId(); | ||
for (const text of texts) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the generated API, detect
becomes detectLanguage
.
Codecov Report
@@ Coverage Diff @@
## master #355 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 1 1
Lines 3 85 +82
=====================================
+ Hits 3 85 +82
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v2 samples need to remain as is for docs. New v3 samples will be added.
v2 samples should just change to import the v2 client library |
@nnegrey this seems weird if we're making the default export of our library const {TranslationServiceClient} = require('@google-cloud/translate'); I'd potentially suggest creating a |
@@ -0,0 +1,3 @@ | |||
{ | |||
"ignoreFiles": ["protos/*"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure about that? Instead, I'd rather we make the change in the underlying generator/protos if needed. If we don't want to block on that, please leave a TODO with a reference to a tracking bug so we don't lose this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JustinBeckwith created a TODO on this repo, #356
@alexander-fenster could you perhaps create a corresponding tracking issue, for adding license headers, and reference #356.
"extends": "gts/tslint.json" | ||
"extends": "gts/tslint.json", | ||
"rules": { | ||
"ban-ts-ignore": false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would strongly advise against that flag. @alexander-fenster what's up here?
@nnegrey and I had an out of band conversation, I'm comfortable with us sticking with default examples being |
async function batchTranslateTextWithGlossaryAndModel() { | ||
// Construct request | ||
const request = { | ||
parent: `projects/${projectId}/locations/${location}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will be fixed in an upcoming "feature" release, in which we re-introduce the helper for parent:
see: https://github.com/googleapis/nodejs-translate/issues/359
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (but noting that I wrote the samples)
|
||
// Instantiates a client | ||
const translate = new Translate({projectId}); | ||
|
||
// The text to translate | ||
const text = 'Hello, world!'; | ||
async function quickStart() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for doing this 👍 this makes the embedded samples much better.
* Updates [google-cloud/translate][1] dependency to version `5.0.0`. * Updates declaration of clients to specify the version 2 of the API instead of the version 3, which is the default in the Translate library. Note: The google-cloud/translate library made v3 the default in googleapis/nodejs-translate#355 [1]: https://github.com/googleapis/nodejs-translate
BREAKING CHANGE: this significantly changes TypeScript types and API surface from the v2 API. Reference samples/ for help making the migration from v2 to v3.