diff --git a/typescript/src/schema/api.ts b/typescript/src/schema/api.ts index 6ab68f24f..d2a8dbac8 100644 --- a/typescript/src/schema/api.ts +++ b/typescript/src/schema/api.ts @@ -19,7 +19,6 @@ import * as path from 'path'; import { Naming, Options as namingOptions } from './naming'; import { Proto, MessagesMap } from './proto'; import { ResourceDatabase, ResourceDescriptor } from './resourceDatabase'; -import { Options } from 'yargs-parser'; const googleGaxLocation = path.dirname(require.resolve('google-gax')); const gaxProtosLocation = path.join(googleGaxLocation, '..', '..', 'protos'); @@ -54,7 +53,9 @@ export class API { this.publishName = options.publishName || this.naming.productName.toKebabCase(); // construct resource map - const resourceMap = getResourceDatabase(fileDescriptors); + const [resourceDatabase, resourceDefinitionDatabase] = getResourceDatabase( + fileDescriptors + ); // parse resource map to Proto constructor this.protos = fileDescriptors .filter(fd => fd.name) @@ -64,7 +65,8 @@ export class API { fd, packageName, options.grpcServiceConfig, - resourceMap + resourceDatabase, + resourceDefinitionDatabase ); return map; }, {} as ProtosMap); @@ -131,13 +133,14 @@ export class API { function getResourceDatabase( fileDescriptors: plugin.google.protobuf.IFileDescriptorProto[] -): ResourceDatabase { +): ResourceDatabase[] { const resourceDatabase = new ResourceDatabase(); + const resourceDefinitionDatabase = new ResourceDatabase(); for (const fd of fileDescriptors.filter(fd => fd)) { // process file-level options for (const resource of fd.options?.['.google.api.resourceDefinition'] ?? []) { - resourceDatabase.registerResource( + resourceDefinitionDatabase.registerResource( resource as ResourceDescriptor, `file ${fd.name} resource_definition option` ); @@ -158,5 +161,5 @@ function getResourceDatabase( ); } } - return resourceDatabase; + return [resourceDatabase, resourceDefinitionDatabase]; } diff --git a/typescript/src/schema/proto.ts b/typescript/src/schema/proto.ts index 69cddc009..b90e49b1c 100644 --- a/typescript/src/schema/proto.ts +++ b/typescript/src/schema/proto.ts @@ -472,7 +472,8 @@ function augmentService( service: plugin.google.protobuf.IServiceDescriptorProto, commentsMap: CommentsMap, grpcServiceConfig: plugin.grpc.service_config.ServiceConfig, - resourceDatabase: ResourceDatabase + resourceDatabase: ResourceDatabase, + resourceDefinitionDatabase: ResourceDatabase ) { const augmentedService = service as ServiceDescriptorProto; augmentedService.packageName = packageName; @@ -526,30 +527,22 @@ function augmentService( // Build a list of resources referenced by this service const uniqueResources: { [name: string]: ResourceDescriptor } = {}; + // Copy all resources in resourceDatabase to uniqueResources + const allPatterns = resourceDatabase.patterns; + for (const pattern of Object.keys(allPatterns)) { + const resource = allPatterns[pattern]; + uniqueResources[resource.name] = resource; + } + + // Copy all resources definination which are referenced into unique resources map. for (const property of Object.keys(messages)) { const errorLocation = `service ${service.name} message ${property}`; - // take the option['.google.api.resource'] of the message as resource, add it to resourceDatabase id it's not there. - const descriptorProto = messages[property]; - if ( - descriptorProto.options && - descriptorProto.options['.google.api.resource'] - ) { - const resource = descriptorProto.options['.google.api.resource']; - if (!resourceDatabase.getResourceByType(resource.type)) { - resourceDatabase.registerResource(resource); - const registeredResource = resourceDatabase.getResourceByType( - resource.type - )!; - uniqueResources[registeredResource.name] = registeredResource; - } - } for (const fieldDescriptor of messages[property].field ?? []) { // note: ResourceDatabase can accept `undefined` values, so we happily use optional chaining here. const resourceReference = fieldDescriptor.options?.['.google.api.resourceReference']; - // 1. If this resource reference has .child_type, figure out if we have any known parent resources. - const parentResources = resourceDatabase.getParentResourcesByChildType( + const parentResources = resourceDefinitionDatabase.getParentResourcesByChildType( resourceReference?.childType, errorLocation ); @@ -557,16 +550,21 @@ function augmentService( resource => (uniqueResources[resource.name] = resource) ); - // 2. If this resource reference has .type, we should have a known resource with this type. - const resourceByType = resourceDatabase.getResourceByType( - resourceReference?.type, - errorLocation + // 2. If this resource reference has .type, we should have a known resource with this type, check two maps. + let resourceByType = resourceDefinitionDatabase.getResourceByType( + resourceReference?.type ); + resourceByType = + resourceByType ?? + resourceDatabase.getResourceByType( + resourceReference?.type, + errorLocation + ); if (!resourceByType || !resourceByType.pattern) continue; // For multi pattern resources, we look up the type first, and get the [pattern] from resource, // look up pattern map for all resources. for (const pattern of resourceByType!.pattern!) { - const resourceByPattern = resourceDatabase.getResourceByPattern( + const resourceByPattern = resourceDefinitionDatabase.getResourceByPattern( pattern ); if (!resourceByPattern) continue; @@ -574,7 +572,7 @@ function augmentService( } } } - augmentedService.pathTemplates = Object.values(uniqueResources); + augmentedService.pathTemplates = Object.values(uniqueResources).sort(); return augmentedService; } @@ -590,7 +588,8 @@ export class Proto { fd: plugin.google.protobuf.IFileDescriptorProto, packageName: string, grpcServiceConfig: plugin.grpc.service_config.ServiceConfig, - resourceDatabase: ResourceDatabase + resourceDatabase: ResourceDatabase, + resourceDefinitionDatabase: ResourceDatabase ) { fd.enumType = fd.enumType || []; fd.messageType = fd.messageType || []; @@ -624,7 +623,8 @@ export class Proto { service, commentsMap, grpcServiceConfig, - resourceDatabase + resourceDatabase, + resourceDefinitionDatabase ) ) .reduce((map, service) => { diff --git a/typescript/src/schema/resourceDatabase.ts b/typescript/src/schema/resourceDatabase.ts index a734cd095..d79443d0b 100644 --- a/typescript/src/schema/resourceDatabase.ts +++ b/typescript/src/schema/resourceDatabase.ts @@ -21,8 +21,8 @@ export interface ResourceDescriptor } export class ResourceDatabase { - private patterns: { [pattern: string]: ResourceDescriptor }; - private types: { [type: string]: ResourceDescriptor }; + patterns: { [pattern: string]: ResourceDescriptor }; + types: { [type: string]: ResourceDescriptor }; constructor() { this.patterns = {}; @@ -92,8 +92,9 @@ export class ResourceDatabase { }; this.patterns[pattern] = resourceDescriptor; resourceDescriptor = this.getResourceDescriptor(name, params, resource); - if (this.types[resource.type]) continue; - this.types[resource.type] = resourceDescriptor; + if (!this.types[resource.type]) { + this.types[resource.type] = resourceDescriptor; + } } } } diff --git a/typescript/test/testdata/dlp/src/v2/dlp_service_client.ts.baseline b/typescript/test/testdata/dlp/src/v2/dlp_service_client.ts.baseline index 0126cd08d..f16e5bc47 100644 --- a/typescript/test/testdata/dlp/src/v2/dlp_service_client.ts.baseline +++ b/typescript/test/testdata/dlp/src/v2/dlp_service_client.ts.baseline @@ -139,36 +139,33 @@ export class DlpServiceClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - projectPathTemplate: new gaxModule.PathTemplate( - 'projects/{project}' - ), - organizationPathTemplate: new gaxModule.PathTemplate( - 'organizations/{organization}' - ), organizationInspectTemplatePathTemplate: new gaxModule.PathTemplate( 'organizations/{organization}/inspectTemplates/{inspect_template}' ), projectInspectTemplatePathTemplate: new gaxModule.PathTemplate( 'projects/{project}/inspectTemplates/{inspect_template}' ), - jobTriggerPathTemplate: new gaxModule.PathTemplate( - 'projects/{project}/jobTriggers/{job_trigger}' - ), - dlpJobPathTemplate: new gaxModule.PathTemplate( - 'projects/{project}/dlpJobs/{dlp_job}' - ), organizationDeidentifyTemplatePathTemplate: new gaxModule.PathTemplate( 'organizations/{organization}/deidentifyTemplates/{deidentify_template}' ), projectDeidentifyTemplatePathTemplate: new gaxModule.PathTemplate( 'projects/{project}/deidentifyTemplates/{deidentify_template}' ), + jobTriggerPathTemplate: new gaxModule.PathTemplate( + 'projects/{project}/jobTriggers/{job_trigger}' + ), + dlpJobPathTemplate: new gaxModule.PathTemplate( + 'projects/{project}/dlpJobs/{dlp_job}' + ), organizationStoredInfoTypePathTemplate: new gaxModule.PathTemplate( 'organizations/{organization}/storedInfoTypes/{stored_info_type}' ), projectStoredInfoTypePathTemplate: new gaxModule.PathTemplate( 'projects/{project}/storedInfoTypes/{stored_info_type}' ), + projectPathTemplate: new gaxModule.PathTemplate( + 'projects/{project}' + ), }; // Some of the methods on this service return "paged" results, @@ -2984,52 +2981,6 @@ export class DlpServiceClient { // -- Path templates -- // -------------------- - /** - * Return a fully-qualified project resource name string. - * - * @param {string} project - * @returns {string} Resource name string. - */ - projectPath(project:string) { - return this._pathTemplates.projectPathTemplate.render({ - project: project, - }); - } - - /** - * Parse the project from Project resource. - * - * @param {string} projectName - * A fully-qualified path representing Project resource. - * @returns {string} A string representing the project. - */ - matchProjectFromProjectName(projectName: string) { - return this._pathTemplates.projectPathTemplate.match(projectName).project; - } - - /** - * Return a fully-qualified organization resource name string. - * - * @param {string} organization - * @returns {string} Resource name string. - */ - organizationPath(organization:string) { - return this._pathTemplates.organizationPathTemplate.render({ - organization: organization, - }); - } - - /** - * Parse the organization from Organization resource. - * - * @param {string} organizationName - * A fully-qualified path representing Organization resource. - * @returns {string} A string representing the organization. - */ - matchOrganizationFromOrganizationName(organizationName: string) { - return this._pathTemplates.organizationPathTemplate.match(organizationName).organization; - } - /** * Return a fully-qualified organizationInspectTemplate resource name string. * @@ -3103,147 +3054,147 @@ export class DlpServiceClient { } /** - * Return a fully-qualified jobTrigger resource name string. + * Return a fully-qualified organizationDeidentifyTemplate resource name string. * - * @param {string} project - * @param {string} job_trigger + * @param {string} organization + * @param {string} deidentify_template * @returns {string} Resource name string. */ - jobTriggerPath(project:string,jobTrigger:string) { - return this._pathTemplates.jobTriggerPathTemplate.render({ - project: project, - job_trigger: jobTrigger, + organizationDeidentifyTemplatePath(organization:string,deidentifyTemplate:string) { + return this._pathTemplates.organizationDeidentifyTemplatePathTemplate.render({ + organization: organization, + deidentify_template: deidentifyTemplate, }); } /** - * Parse the project from JobTrigger resource. + * Parse the organization from OrganizationDeidentifyTemplate resource. * - * @param {string} jobTriggerName - * A fully-qualified path representing JobTrigger resource. - * @returns {string} A string representing the project. + * @param {string} organizationDeidentifyTemplateName + * A fully-qualified path representing organization_deidentify_template resource. + * @returns {string} A string representing the organization. */ - matchProjectFromJobTriggerName(jobTriggerName: string) { - return this._pathTemplates.jobTriggerPathTemplate.match(jobTriggerName).project; + matchOrganizationFromOrganizationDeidentifyTemplateName(organizationDeidentifyTemplateName: string) { + return this._pathTemplates.organizationDeidentifyTemplatePathTemplate.match(organizationDeidentifyTemplateName).organization; } /** - * Parse the job_trigger from JobTrigger resource. + * Parse the deidentify_template from OrganizationDeidentifyTemplate resource. * - * @param {string} jobTriggerName - * A fully-qualified path representing JobTrigger resource. - * @returns {string} A string representing the job_trigger. + * @param {string} organizationDeidentifyTemplateName + * A fully-qualified path representing organization_deidentify_template resource. + * @returns {string} A string representing the deidentify_template. */ - matchJobTriggerFromJobTriggerName(jobTriggerName: string) { - return this._pathTemplates.jobTriggerPathTemplate.match(jobTriggerName).job_trigger; + matchDeidentifyTemplateFromOrganizationDeidentifyTemplateName(organizationDeidentifyTemplateName: string) { + return this._pathTemplates.organizationDeidentifyTemplatePathTemplate.match(organizationDeidentifyTemplateName).deidentify_template; } /** - * Return a fully-qualified dlpJob resource name string. + * Return a fully-qualified projectDeidentifyTemplate resource name string. * * @param {string} project - * @param {string} dlp_job + * @param {string} deidentify_template * @returns {string} Resource name string. */ - dlpJobPath(project:string,dlpJob:string) { - return this._pathTemplates.dlpJobPathTemplate.render({ + projectDeidentifyTemplatePath(project:string,deidentifyTemplate:string) { + return this._pathTemplates.projectDeidentifyTemplatePathTemplate.render({ project: project, - dlp_job: dlpJob, + deidentify_template: deidentifyTemplate, }); } /** - * Parse the project from DlpJob resource. + * Parse the project from ProjectDeidentifyTemplate resource. * - * @param {string} dlpJobName - * A fully-qualified path representing DlpJob resource. + * @param {string} projectDeidentifyTemplateName + * A fully-qualified path representing project_deidentify_template resource. * @returns {string} A string representing the project. */ - matchProjectFromDlpJobName(dlpJobName: string) { - return this._pathTemplates.dlpJobPathTemplate.match(dlpJobName).project; + matchProjectFromProjectDeidentifyTemplateName(projectDeidentifyTemplateName: string) { + return this._pathTemplates.projectDeidentifyTemplatePathTemplate.match(projectDeidentifyTemplateName).project; } /** - * Parse the dlp_job from DlpJob resource. + * Parse the deidentify_template from ProjectDeidentifyTemplate resource. * - * @param {string} dlpJobName - * A fully-qualified path representing DlpJob resource. - * @returns {string} A string representing the dlp_job. + * @param {string} projectDeidentifyTemplateName + * A fully-qualified path representing project_deidentify_template resource. + * @returns {string} A string representing the deidentify_template. */ - matchDlpJobFromDlpJobName(dlpJobName: string) { - return this._pathTemplates.dlpJobPathTemplate.match(dlpJobName).dlp_job; + matchDeidentifyTemplateFromProjectDeidentifyTemplateName(projectDeidentifyTemplateName: string) { + return this._pathTemplates.projectDeidentifyTemplatePathTemplate.match(projectDeidentifyTemplateName).deidentify_template; } /** - * Return a fully-qualified organizationDeidentifyTemplate resource name string. + * Return a fully-qualified jobTrigger resource name string. * - * @param {string} organization - * @param {string} deidentify_template + * @param {string} project + * @param {string} job_trigger * @returns {string} Resource name string. */ - organizationDeidentifyTemplatePath(organization:string,deidentifyTemplate:string) { - return this._pathTemplates.organizationDeidentifyTemplatePathTemplate.render({ - organization: organization, - deidentify_template: deidentifyTemplate, + jobTriggerPath(project:string,jobTrigger:string) { + return this._pathTemplates.jobTriggerPathTemplate.render({ + project: project, + job_trigger: jobTrigger, }); } /** - * Parse the organization from OrganizationDeidentifyTemplate resource. + * Parse the project from JobTrigger resource. * - * @param {string} organizationDeidentifyTemplateName - * A fully-qualified path representing organization_deidentify_template resource. - * @returns {string} A string representing the organization. + * @param {string} jobTriggerName + * A fully-qualified path representing JobTrigger resource. + * @returns {string} A string representing the project. */ - matchOrganizationFromOrganizationDeidentifyTemplateName(organizationDeidentifyTemplateName: string) { - return this._pathTemplates.organizationDeidentifyTemplatePathTemplate.match(organizationDeidentifyTemplateName).organization; + matchProjectFromJobTriggerName(jobTriggerName: string) { + return this._pathTemplates.jobTriggerPathTemplate.match(jobTriggerName).project; } /** - * Parse the deidentify_template from OrganizationDeidentifyTemplate resource. + * Parse the job_trigger from JobTrigger resource. * - * @param {string} organizationDeidentifyTemplateName - * A fully-qualified path representing organization_deidentify_template resource. - * @returns {string} A string representing the deidentify_template. + * @param {string} jobTriggerName + * A fully-qualified path representing JobTrigger resource. + * @returns {string} A string representing the job_trigger. */ - matchDeidentifyTemplateFromOrganizationDeidentifyTemplateName(organizationDeidentifyTemplateName: string) { - return this._pathTemplates.organizationDeidentifyTemplatePathTemplate.match(organizationDeidentifyTemplateName).deidentify_template; + matchJobTriggerFromJobTriggerName(jobTriggerName: string) { + return this._pathTemplates.jobTriggerPathTemplate.match(jobTriggerName).job_trigger; } /** - * Return a fully-qualified projectDeidentifyTemplate resource name string. + * Return a fully-qualified dlpJob resource name string. * * @param {string} project - * @param {string} deidentify_template + * @param {string} dlp_job * @returns {string} Resource name string. */ - projectDeidentifyTemplatePath(project:string,deidentifyTemplate:string) { - return this._pathTemplates.projectDeidentifyTemplatePathTemplate.render({ + dlpJobPath(project:string,dlpJob:string) { + return this._pathTemplates.dlpJobPathTemplate.render({ project: project, - deidentify_template: deidentifyTemplate, + dlp_job: dlpJob, }); } /** - * Parse the project from ProjectDeidentifyTemplate resource. + * Parse the project from DlpJob resource. * - * @param {string} projectDeidentifyTemplateName - * A fully-qualified path representing project_deidentify_template resource. + * @param {string} dlpJobName + * A fully-qualified path representing DlpJob resource. * @returns {string} A string representing the project. */ - matchProjectFromProjectDeidentifyTemplateName(projectDeidentifyTemplateName: string) { - return this._pathTemplates.projectDeidentifyTemplatePathTemplate.match(projectDeidentifyTemplateName).project; + matchProjectFromDlpJobName(dlpJobName: string) { + return this._pathTemplates.dlpJobPathTemplate.match(dlpJobName).project; } /** - * Parse the deidentify_template from ProjectDeidentifyTemplate resource. + * Parse the dlp_job from DlpJob resource. * - * @param {string} projectDeidentifyTemplateName - * A fully-qualified path representing project_deidentify_template resource. - * @returns {string} A string representing the deidentify_template. + * @param {string} dlpJobName + * A fully-qualified path representing DlpJob resource. + * @returns {string} A string representing the dlp_job. */ - matchDeidentifyTemplateFromProjectDeidentifyTemplateName(projectDeidentifyTemplateName: string) { - return this._pathTemplates.projectDeidentifyTemplatePathTemplate.match(projectDeidentifyTemplateName).deidentify_template; + matchDlpJobFromDlpJobName(dlpJobName: string) { + return this._pathTemplates.dlpJobPathTemplate.match(dlpJobName).dlp_job; } /** @@ -3318,6 +3269,29 @@ export class DlpServiceClient { return this._pathTemplates.projectStoredInfoTypePathTemplate.match(projectStoredInfoTypeName).stored_info_type; } + /** + * Return a fully-qualified project resource name string. + * + * @param {string} project + * @returns {string} Resource name string. + */ + projectPath(project:string) { + return this._pathTemplates.projectPathTemplate.render({ + project: project, + }); + } + + /** + * Parse the project from Project resource. + * + * @param {string} projectName + * A fully-qualified path representing Project resource. + * @returns {string} A string representing the project. + */ + matchProjectFromProjectName(projectName: string) { + return this._pathTemplates.projectPathTemplate.match(projectName).project; + } + /** * Terminate the GRPC channel and close the client. * diff --git a/typescript/test/testdata/redis/src/v1beta1/cloud_redis_client.ts.baseline b/typescript/test/testdata/redis/src/v1beta1/cloud_redis_client.ts.baseline index aa9ddfbb8..6a231ac40 100644 --- a/typescript/test/testdata/redis/src/v1beta1/cloud_redis_client.ts.baseline +++ b/typescript/test/testdata/redis/src/v1beta1/cloud_redis_client.ts.baseline @@ -146,12 +146,12 @@ export class CloudRedisClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - locationPathTemplate: new gaxModule.PathTemplate( - 'projects/{project}/locations/{location}' - ), instancePathTemplate: new gaxModule.PathTemplate( 'projects/{project}/locations/{location}/instances/{instance}' ), + locationPathTemplate: new gaxModule.PathTemplate( + 'projects/{project}/locations/{location}' + ), }; // Some of the methods on this service return "paged" results, @@ -959,42 +959,6 @@ export class CloudRedisClient { // -- Path templates -- // -------------------- - /** - * Return a fully-qualified location resource name string. - * - * @param {string} project - * @param {string} location - * @returns {string} Resource name string. - */ - locationPath(project:string,location:string) { - return this._pathTemplates.locationPathTemplate.render({ - project: project, - location: location, - }); - } - - /** - * Parse the project from Location resource. - * - * @param {string} locationName - * A fully-qualified path representing Location resource. - * @returns {string} A string representing the project. - */ - matchProjectFromLocationName(locationName: string) { - return this._pathTemplates.locationPathTemplate.match(locationName).project; - } - - /** - * Parse the location from Location resource. - * - * @param {string} locationName - * A fully-qualified path representing Location resource. - * @returns {string} A string representing the location. - */ - matchLocationFromLocationName(locationName: string) { - return this._pathTemplates.locationPathTemplate.match(locationName).location; - } - /** * Return a fully-qualified instance resource name string. * @@ -1044,6 +1008,42 @@ export class CloudRedisClient { return this._pathTemplates.instancePathTemplate.match(instanceName).instance; } + /** + * Return a fully-qualified location resource name string. + * + * @param {string} project + * @param {string} location + * @returns {string} Resource name string. + */ + locationPath(project:string,location:string) { + return this._pathTemplates.locationPathTemplate.render({ + project: project, + location: location, + }); + } + + /** + * Parse the project from Location resource. + * + * @param {string} locationName + * A fully-qualified path representing Location resource. + * @returns {string} A string representing the project. + */ + matchProjectFromLocationName(locationName: string) { + return this._pathTemplates.locationPathTemplate.match(locationName).project; + } + + /** + * Parse the location from Location resource. + * + * @param {string} locationName + * A fully-qualified path representing Location resource. + * @returns {string} A string representing the location. + */ + matchLocationFromLocationName(locationName: string) { + return this._pathTemplates.locationPathTemplate.match(locationName).location; + } + /** * Terminate the GRPC channel and close the client. * 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 b947ccbbe..b12ae89fc 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 @@ -132,12 +132,12 @@ export class TranslationServiceClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - locationPathTemplate: new gaxModule.PathTemplate( - 'projects/{project}/locations/{location}' - ), glossaryPathTemplate: new gaxModule.PathTemplate( 'projects/{project}/locations/{location}/glossaries/{glossary}' ), + locationPathTemplate: new gaxModule.PathTemplate( + 'projects/{project}/locations/{location}' + ), }; // Some of the methods on this service return "paged" results, @@ -1032,42 +1032,6 @@ export class TranslationServiceClient { // -- Path templates -- // -------------------- - /** - * Return a fully-qualified location resource name string. - * - * @param {string} project - * @param {string} location - * @returns {string} Resource name string. - */ - locationPath(project:string,location:string) { - return this._pathTemplates.locationPathTemplate.render({ - project: project, - location: location, - }); - } - - /** - * Parse the project from Location resource. - * - * @param {string} locationName - * A fully-qualified path representing Location resource. - * @returns {string} A string representing the project. - */ - matchProjectFromLocationName(locationName: string) { - return this._pathTemplates.locationPathTemplate.match(locationName).project; - } - - /** - * Parse the location from Location resource. - * - * @param {string} locationName - * A fully-qualified path representing Location resource. - * @returns {string} A string representing the location. - */ - matchLocationFromLocationName(locationName: string) { - return this._pathTemplates.locationPathTemplate.match(locationName).location; - } - /** * Return a fully-qualified glossary resource name string. * @@ -1117,6 +1081,42 @@ export class TranslationServiceClient { return this._pathTemplates.glossaryPathTemplate.match(glossaryName).glossary; } + /** + * Return a fully-qualified location resource name string. + * + * @param {string} project + * @param {string} location + * @returns {string} Resource name string. + */ + locationPath(project:string,location:string) { + return this._pathTemplates.locationPathTemplate.render({ + project: project, + location: location, + }); + } + + /** + * Parse the project from Location resource. + * + * @param {string} locationName + * A fully-qualified path representing Location resource. + * @returns {string} A string representing the project. + */ + matchProjectFromLocationName(locationName: string) { + return this._pathTemplates.locationPathTemplate.match(locationName).project; + } + + /** + * Parse the location from Location resource. + * + * @param {string} locationName + * A fully-qualified path representing Location resource. + * @returns {string} A string representing the location. + */ + matchLocationFromLocationName(locationName: string) { + return this._pathTemplates.locationPathTemplate.match(locationName).location; + } + /** * Terminate the GRPC channel and close the client. *