@azure-rest/ai-translation-text
Advanced tools
Comparing version 1.0.0-alpha.20240325.1 to 1.0.0-alpha.20240327.1
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
import TextTranslation from "./customClient"; | ||
export * from "./customClient"; | ||
export * from "./generated/parameters"; | ||
export * from "./generated/responses"; | ||
export * from "./generated/clientDefinitions"; | ||
export * from "./generated/isUnexpected"; | ||
export * from "./generated/models"; | ||
export * from "./generated/outputModels"; | ||
export * from "./generated/serializeHelper"; | ||
export default TextTranslation; | ||
import TextTranslationClient from "./custom/customClient"; | ||
export * from "./custom/customClient"; | ||
export * from "./parameters"; | ||
export * from "./responses"; | ||
export * from "./clientDefinitions"; | ||
export * from "./isUnexpected"; | ||
export * from "./models"; | ||
export * from "./outputModels"; | ||
export * from "./serializeHelper"; | ||
export default TextTranslationClient; | ||
//# sourceMappingURL=index.js.map |
@@ -6,2 +6,3 @@ 'use strict'; | ||
var coreClient = require('@azure-rest/core-client'); | ||
var logger$1 = require('@azure/logger'); | ||
var coreRestPipeline = require('@azure/core-rest-pipeline'); | ||
@@ -30,2 +31,6 @@ | ||
// Licensed under the MIT license. | ||
const logger = logger$1.createClientLogger("ai-translation-text"); | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
const APIM_KEY_HEADER_NAME = "Ocp-Apim-Subscription-Key"; | ||
@@ -67,19 +72,2 @@ const APIM_REGION_HEADER_NAME = "Ocp-Apim-Subscription-Region"; | ||
} | ||
/** Policy that sets the api-version (or equivalent) to reflect the library version. */ | ||
const apiVersionPolicy = { | ||
name: "MTApiVersionPolicy", | ||
async sendRequest(request, next) { | ||
const param = request.url.split("?"); | ||
if (param.length > 1) { | ||
const newParams = param[1].split("&"); | ||
newParams.push("api-version=3.0"); | ||
request.url = param[0] + "?" + newParams.join("&"); | ||
} | ||
else { | ||
// no query parameters in request url | ||
request.url = param[0] + "?api-version=3.0"; | ||
} | ||
return next(request); | ||
}, | ||
}; | ||
/** | ||
@@ -92,4 +80,5 @@ * Initialize a new instance of `TextTranslationClient` | ||
function createClient(endpoint, credential = undefined, options = {}) { | ||
var _a; | ||
var _a, _b, _c, _d; | ||
let serviceEndpoint; | ||
options.apiVersion = (_a = options.apiVersion) !== null && _a !== void 0 ? _a : "3.0"; | ||
if (!endpoint) { | ||
@@ -104,3 +93,3 @@ serviceEndpoint = DEFAULT_ENPOINT; | ||
} | ||
const baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : `${serviceEndpoint}`; | ||
const baseUrl = (_b = options.baseUrl) !== null && _b !== void 0 ? _b : `${serviceEndpoint}`; | ||
const userAgentInfo = `azsdk-js-ai-translation-text-rest/1.0.0-beta.2`; | ||
@@ -112,5 +101,6 @@ const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix | ||
userAgentPrefix, | ||
}, loggingOptions: { | ||
logger: (_d = (_c = options.loggingOptions) === null || _c === void 0 ? void 0 : _c.logger) !== null && _d !== void 0 ? _d : logger.info, | ||
} }); | ||
const client = coreClient.getClient(baseUrl, options); | ||
client.pipeline.addPolicy(apiVersionPolicy); | ||
if (isTranslatorKeyCredential(credential)) { | ||
@@ -147,13 +137,67 @@ const mtAuthneticationPolicy = new TranslatorAuthenticationPolicy(credential); | ||
const method = response.request.method; | ||
const pathDetails = responseMap[`${method} ${url.pathname}`]; | ||
let pathDetails = responseMap[`${method} ${url.pathname}`]; | ||
if (!pathDetails) { | ||
return true; | ||
pathDetails = getParametrizedPathSuccess(method, url.pathname); | ||
} | ||
return !pathDetails.includes(response.status); | ||
} | ||
function getParametrizedPathSuccess(method, path) { | ||
var _a, _b, _c, _d; | ||
const pathParts = path.split("/"); | ||
// Traverse list to match the longest candidate | ||
// matchedLen: the length of candidate path | ||
// matchedValue: the matched status code array | ||
let matchedLen = -1, matchedValue = []; | ||
// Iterate the responseMap to find a match | ||
for (const [key, value] of Object.entries(responseMap)) { | ||
// Extracting the path from the map key which is in format | ||
// GET /path/foo | ||
if (!key.startsWith(method)) { | ||
continue; | ||
} | ||
const candidatePath = getPathFromMapKey(key); | ||
// Get each part of the url path | ||
const candidateParts = candidatePath.split("/"); | ||
// track if we have found a match to return the values found. | ||
let found = true; | ||
for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) { | ||
if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) && ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) { | ||
const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length; | ||
// If the current part of the candidate is a "template" part | ||
// Try to use the suffix of pattern to match the path | ||
// {guid} ==> $ | ||
// {guid}:export ==> :export$ | ||
const isMatched = new RegExp(`${(_d = candidateParts[i]) === null || _d === void 0 ? void 0 : _d.slice(start, end)}`).test(pathParts[j] || ""); | ||
if (!isMatched) { | ||
found = false; | ||
break; | ||
} | ||
continue; | ||
} | ||
// If the candidate part is not a template and | ||
// the parts don't match mark the candidate as not found | ||
// to move on with the next candidate path. | ||
if (candidateParts[i] !== pathParts[j]) { | ||
found = false; | ||
break; | ||
} | ||
} | ||
// We finished evaluating the current candidate parts | ||
// Update the matched value if and only if we found the longer pattern | ||
if (found && candidatePath.length > matchedLen) { | ||
matchedLen = candidatePath.length; | ||
matchedValue = value; | ||
} | ||
} | ||
return matchedValue; | ||
} | ||
function getPathFromMapKey(mapKey) { | ||
const pathStart = mapKey.indexOf("/"); | ||
return mapKey.slice(pathStart); | ||
} | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
function buildMultiCollection(queryParameters, parameterName) { | ||
return queryParameters | ||
function buildMultiCollection(items, parameterName) { | ||
return items | ||
.map((item, index) => { | ||
@@ -160,0 +204,0 @@ if (index === 0) { |
@@ -5,3 +5,3 @@ { | ||
"author": "Microsoft Corporation", | ||
"version": "1.0.0-alpha.20240325.1", | ||
"version": "1.0.0-alpha.20240327.1", | ||
"description": "An isomorphic client library for the Azure Cognitive Translator Service", | ||
@@ -8,0 +8,0 @@ "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/translation/ai-translation-text-rest/README.md", |
@@ -307,3 +307,3 @@ # Azure TextTranslation REST client library for JavaScript | ||
[service_errors]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-reference#errors | ||
[translator_client_class]: https://github.com/azure/azure-sdk-for-js/blob/main/sdk/translation/ai-translation-text-rest/src/generated/clientDefinitions.ts | ||
[translator_client_class]: https://learn.microsoft.com/javascript/api/@azure-rest/ai-translation-text/texttranslationclient | ||
[languages_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-languages | ||
@@ -310,0 +310,0 @@ [translate_doc]: https://learn.microsoft.com/azure/cognitive-services/translator/reference/v3-0-translate |
@@ -40,3 +40,3 @@ import { Client } from '@azure-rest/core-client'; | ||
/** Elemented containing break sentence result. */ | ||
/** Item containing break sentence result. */ | ||
export declare interface BreakSentenceItemOutput { | ||
@@ -52,3 +52,3 @@ /** The detectedLanguage property is only present in the result object when language auto-detection is requested. */ | ||
export declare function buildMultiCollection(queryParameters: string[], parameterName: string): string; | ||
export declare function buildMultiCollection(items: string[], parameterName: string): string; | ||
@@ -200,3 +200,3 @@ /** Common properties of language script */ | ||
export declare interface ErrorDetailsOutput { | ||
/** Number indetifier of the error. */ | ||
/** Number identifier of the error. */ | ||
code: number; | ||
@@ -231,3 +231,3 @@ /** Human readable error description. */ | ||
export declare interface FindSentenceBoundariesBodyParam { | ||
/** Array of the text for which values the sentence boundaries will be calculated. */ | ||
/** Defines the content of the request */ | ||
body: Array<InputTextItem>; | ||
@@ -395,3 +395,3 @@ } | ||
export declare interface LookupDictionaryEntriesBodyParam { | ||
/** Array of the text to be sent to dictionary. */ | ||
/** Defines the content of the request */ | ||
body: Array<InputTextItem>; | ||
@@ -457,3 +457,3 @@ } | ||
export declare interface LookupDictionaryExamplesBodyParam { | ||
/** Array of the text to be sent to dictionary. */ | ||
/** Defines the content of the request */ | ||
body: Array<DictionaryExampleTextItem>; | ||
@@ -596,3 +596,3 @@ } | ||
export declare interface TranslateBodyParam { | ||
/** Array of the text to be translated. */ | ||
/** Defines the content of the request */ | ||
body: Array<InputTextItem>; | ||
@@ -679,3 +679,3 @@ } | ||
*/ | ||
textType?: "plain" | "html"; | ||
textType?: string; | ||
/** | ||
@@ -691,3 +691,3 @@ * A string specifying the category (domain) of the translation. This parameter is used to get translations | ||
*/ | ||
profanityAction?: "NoAction" | "Marked" | "Deleted"; | ||
profanityAction?: string; | ||
/** | ||
@@ -697,3 +697,3 @@ * Specifies how profanities should be marked in translations. | ||
*/ | ||
profanityMarker?: "Asterisk" | "Tag"; | ||
profanityMarker?: string; | ||
/** | ||
@@ -752,3 +752,3 @@ * Specifies whether to include alignment projection from source text to translated text. | ||
/** An object giving the translated text in the script specified by the toScript parameter. */ | ||
transliteration?: TransliterationOutput; | ||
transliteration?: TransliteratedTextOutput; | ||
/** Alignment information. */ | ||
@@ -789,3 +789,3 @@ alignment?: TranslatedTextAlignmentOutput; | ||
export declare interface TransliterateBodyParam { | ||
/** Array of the text to be transliterated. */ | ||
/** Defines the content of the request */ | ||
body: Array<InputTextItem>; | ||
@@ -861,10 +861,2 @@ } | ||
/** An object giving the translated text in the script specified by the toScript parameter. */ | ||
export declare interface TransliterationOutput { | ||
/** A string specifying the target script. */ | ||
script: string; | ||
/** A string giving the translated text in the target script. */ | ||
text: string; | ||
} | ||
export { } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
144313
28
1152