Skip to content

Commit

Permalink
feat: update esm templates as well
Browse files Browse the repository at this point in the history
  • Loading branch information
feywind committed Dec 19, 2024
1 parent 5695463 commit 33dfa6b
Showing 1 changed file with 82 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {fileURLToPath} from 'url';
import {getJSON} from '../json-helper.cjs';
// @ts-ignore
const dirname = path.dirname(fileURLToPath(import.meta.url));
import * as logging from 'google-logging-utils';

/**
* Client JSON configuration object, loaded from
Expand Down Expand Up @@ -86,6 +87,7 @@ export class {{ service.name }}Client {
private _defaults: {[method: string]: gax.CallSettings};
private _universeDomain: string;
private _servicePath: string;
private _log = logging.log('{{api.loggingName}}');
auth: gax.GoogleAuth;
descriptors: Descriptors = {
page: {},
Expand Down Expand Up @@ -668,17 +670,44 @@ export class {{ service.name }}Client {
{%- if method.options and method.options.deprecated %}
this.warn('DEP${{service.name}}-${{method.name}}','{{method.name}} is deprecated and may be removed in a future version.', 'DeprecationWarning');
{%- endif %}
this._log.info('{{ method.name.toCamelCase() }} request %j', request);
{%- if method.isDiregapicLRO %}
return this.innerApiCalls.{{ method.name.toCamelCase(true) }}(request, options, callback)
.then(([response, operation, rawResponse]: [protos.google.cloud.compute.v1.IOperation, protos.google.cloud.compute.v1.IOperation, protos.google.cloud.compute.v1.IOperation]) => {
return [
{ latestResponse: response, done: false, name: response.id, metadata: null, result: {}},
operation,
rawResponse
const wrappedCallback: Callback<
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IOperation>|undefined = callback
? (error, response, nextRequest, rawResponse) => {
this._log.info('{{ method.name.toCamelCase() }} response %j', response);
callback(error, response, nextRequest, rawResponse);
}
: undefined;
return this.innerApiCalls.{{ method.name.toCamelCase(true) }}(request, options, wrappedCallback)
?.then(([response, operation, rawResponse]: [protos.google.cloud.compute.v1.IOperation, protos.google.cloud.compute.v1.IOperation, protos.google.cloud.compute.v1.IOperation]) => {
this._log.info('{{ method.name.toCamelCase() }} response %j', response);
return [
{ latestResponse: response, done: false, name: response.id, metadata: null, result: {}},
operation,
rawResponse
];
});
});
{%- else %}
return this.innerApiCalls.{{ method.name.toCamelCase(true) }}(request, options, callback);
const wrappedCallback: Callback<
{{ util.toInterface(method.outputInterface) }},
{{ util.toInterface(method.inputInterface) }}|null|undefined,
{}|null|undefined>|undefined = callback
? (error, response, options, rawResponse) => {
this._log.info('{{ method.name.toCamelCase() }} response %j', response);
callback(error, response, options, rawResponse);
}
: undefined;
return this.innerApiCalls.{{ method.name.toCamelCase(true) }}(request, options, wrappedCallback)
?.then(([response, options, rawResponse]: [
{{ util.toInterface(method.outputInterface) }},
{{ util.toInterface(method.inputInterface) }}|undefined, {}|undefined
]) => {
this._log.info('{{ method.name.toCamelCase() }} response %j', response);
return [response, options, rawResponse];
});
{%- endif %}
}
{%- endfor %}
Expand All @@ -701,6 +730,7 @@ export class {{ service.name }}Client {
{%- if method.options and method.options.deprecated %}
this.warn('DEP${{service.name}}-${{method.name}}','{{method.name}} is deprecated and may be removed in a future version.', 'DeprecationWarning');
{%- endif %}
this._log.info('{{ method.name.toCamelCase() }} stream %j', options);
return this.innerApiCalls.{{ method.name.toCamelCase(true) }}(null, options);
}
{%- elif method.serverStreaming %}
Expand All @@ -724,6 +754,7 @@ export class {{ service.name }}Client {
{%- if method.options and method.options.deprecated %}
this.warn('DEP${{service.name}}-${{method.name}}','{{method.name}} is deprecated and may be removed in a future version.', 'DeprecationWarning');
{%- endif %}
this._log.info('{{ method.name.toCamelCase() }} stream %j', options);
return this.innerApiCalls.{{ method.name.toCamelCase(true) }}(request, options);
}
{%- elif method.clientStreaming %}
Expand Down Expand Up @@ -769,6 +800,7 @@ export class {{ service.name }}Client {
{%- if method.options and method.options.deprecated %}
this.warn('DEP${{service.name}}-${{method.name}}','{{method.name}} is deprecated and may be removed in a future version.', 'DeprecationWarning');
{%- endif %}
this._log.info('{{ method.name.toCamelCase() }} stream %j', options);
return this.innerApiCalls.{{ method.name.toCamelCase(true) }}(null, options, callback);
}
{%- endif %}
Expand Down Expand Up @@ -836,7 +868,24 @@ export class {{ service.name }}Client {
{%- if method.options and method.options.deprecated %}
this.warn('DEP${{service.name}}-${{method.name}}','{{method.name}} is deprecated and may be removed in a future version.', 'DeprecationWarning');
{%- endif %}
return this.innerApiCalls.{{ method.name.toCamelCase(true) }}(request, options, callback);
const wrappedCallback: Callback<
{{ util.toInterface(method.outputInterface) }},
{{ util.toInterface(method.inputInterface) }}|null|undefined,
{}|null|undefined>|undefined = callback
? (error, response, options, rawResponse) => {
this._log.info('{{ method.name.toCamelCase() }} response %j', response);
callback(error, response, options, rawResponse);
}
: undefined;
this._log.info('{{ method.name.toCamelCase() }} request %j', request);
return this.innerApiCalls.{{ method.name.toCamelCase(true) }}(request, options, wrappedCallback)
?.then(([response, options, rawResponse]: [
{{ util.toInterface(method.outputInterface) }},
{{ util.toInterface(method.inputInterface) }}|undefined, {}|undefined
]) => {
this._log.info('{{ method.name.toCamelCase() }} response %j', response);
return [response, options, rawResponse];
});
}
/**
{%- set decodeMethodName = id.get("check" + method.name.toPascalCase() + "Progress") -%}
Expand All @@ -853,6 +902,7 @@ export class {{ service.name }}Client {
{%- if method.options and method.options.deprecated %}
this.warn('DEP${{service.name}}-${{decodeMethodName}}','{{decodeMethodName}} is deprecated and may be removed in a future version.', 'DeprecationWarning');
{%- endif %}
this._log.info('{{method.name.toCamelCase()}} long-running');
const request = new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest({name});
const [operation] = await this.operationsClient.getOperation(request);
const decodeOperation = new this._gaxModule.Operation(operation, this.descriptors.longrunning.{{ method.name.toCamelCase() }}, this._gaxModule.createDefaultBackoffSettings());
Expand Down Expand Up @@ -929,7 +979,26 @@ export class {{ service.name }}Client {
{%- if method.options and method.options.deprecated %}
this.warn('DEP${{service.name}}-${{method.name}}','{{method.name}} is deprecated and may be removed in a future version.', 'DeprecationWarning');
{%- endif %}
return this.innerApiCalls.{{ method.name.toCamelCase(true) }}(request, options, callback);
const wrappedCallback: PaginationCallback<
{{ util.toInterface(method.inputInterface) }},
{{ util.toInterface(method.outputInterface) }}|null|undefined,
{{ util.toInterface(method.pagingResponseType) }}>|undefined = callback
? (error, values, nextPageRequest, rawResponse) => {
this._log.info('{{ method.name.toCamelCase() }} values %j', values);
callback(error, values, nextPageRequest, rawResponse);
}
: undefined;
this._log.info('{{ method.name.toCamelCase() }} request %j', request);
return this.innerApiCalls
.{{ method.name.toCamelCase(true) }}(request, options, wrappedCallback)
?.then(([response, input, output]: [
{{ util.toInterface(method.pagingResponseType) }}[],
{{ util.toInterface(method.inputInterface) }}|null,
{{ util.toInterface(method.outputInterface) }}
]) => {
this._log.info('{{ method.name.toCamelCase() }} values %j', response);
return [response, input, output];
});
}

/**
Expand All @@ -954,6 +1023,7 @@ export class {{ service.name }}Client {
{%- if method.options and method.options.deprecated %}
this.warn('DEP${{service.name}}-${{method.name}}','{{method.name}} is deprecated and may be removed in a future version.', 'DeprecationWarning');
{%- endif %}
this._log.info('{{ method.name.toCamelCase() }} stream %j', request);
return this.descriptors.page.{{ method.name.toCamelCase() }}.createStream(
this.innerApiCalls.{{ method.name.toCamelCase(true) }} as GaxCall,
request,
Expand Down Expand Up @@ -992,6 +1062,7 @@ export class {{ service.name }}Client {
{%- if method.options and method.options.deprecated %}
this.warn('DEP${{service.name}}-${{method.name}}','{{method.name}} is deprecated and may be removed in a future version.', 'DeprecationWarning');
{%- endif %}
this._log.info('{{ method.name.toCamelCase() }} iterate %j', request);
return this.descriptors.page.{{ method.name.toCamelCase() }}.asyncIterate(
this.innerApiCalls['{{ method.name.toCamelCase(true) }}'] as GaxCall,
request as {},
Expand Down Expand Up @@ -1064,6 +1135,7 @@ export class {{ service.name }}Client {
{{ id.get("close") }}(): Promise<void> {
if (this.{{ service.name.toCamelCase() }}Stub && !this._terminated) {
return this.{{ service.name.toCamelCase() }}Stub.then(stub => {
this._log.info('ending gRPC channel');
this._terminated = true;
stub.close();
{%- if service.IAMPolicyMixin > 0 %}
Expand Down

0 comments on commit 33dfa6b

Please sign in to comment.