UNPKG

@azure/ai-language-text

Version:

An isomorphic client library for the text analysis features in the Azure Cognitive Language Service.

129 lines 5.09 kB
/* * Copyright (c) Microsoft Corporation. * Licensed under the MIT License. * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ import * as coreClient from "@azure/core-client"; import { AnalyzeTextImpl } from "./operations"; import * as Parameters from "./models/parameters"; import * as Mappers from "./models/mappers"; /** @internal */ export class GeneratedClient extends coreClient.ServiceClient { /** * Initializes a new instance of the GeneratedClient class. * @param endpoint Supported Cognitive Services endpoint (e.g., * https://<resource-name>.api.cognitiveservices.azure.com). * @param options The parameter options */ constructor(endpoint, options) { var _a, _b; if (endpoint === undefined) { throw new Error("'endpoint' cannot be null"); } // Initializing default values for options if (!options) { options = {}; } const defaults = { requestContentType: "application/json; charset=utf-8" }; const packageDetails = `azsdk-js-ai-language-text/1.1.0`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}` : `${packageDetails}`; const optionsWithDefaults = Object.assign(Object.assign(Object.assign({}, defaults), options), { userAgentOptions: { userAgentPrefix }, endpoint: (_b = (_a = options.endpoint) !== null && _a !== void 0 ? _a : options.baseUri) !== null && _b !== void 0 ? _b : "{Endpoint}/language" }); super(optionsWithDefaults); // Parameter assignments this.endpoint = endpoint; // Assigning values to Constant parameters this.apiVersion = options.apiVersion || "2023-04-01"; this.analyzeText = new AnalyzeTextImpl(this); this.addCustomApiVersionPolicy(options.apiVersion); } /** A function that adds a policy that sets the api-version (or equivalent) to reflect the library version. */ addCustomApiVersionPolicy(apiVersion) { if (!apiVersion) { return; } const apiVersionPolicy = { name: "CustomApiVersionPolicy", async sendRequest(request, next) { const param = request.url.split("?"); if (param.length > 1) { const newParams = param[1].split("&").map((item) => { if (item.indexOf("api-version") > -1) { return "api-version=" + apiVersion; } else { return item; } }); request.url = param[0] + "?" + newParams.join("&"); } return next(request); } }; this.pipeline.addPolicy(apiVersionPolicy); } /** * Submit a collection of text documents for analysis. Specify a single unique task to be executed * immediately. * @param body Collection of documents to analyze and a single task to execute. * @param options The options parameters. */ analyze(body, options) { return this.sendOperationRequest({ body, options }, analyzeOperationSpec); } /** * Submit a collection of text documents for analysis. Specify one or more unique tasks to be executed * as a long-running operation. * @param body Collection of documents to analyze and one or more tasks to execute. * @param options The options parameters. */ analyzeBatch(body, options) { return this.sendOperationRequest({ body, options }, analyzeBatchOperationSpec); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const analyzeOperationSpec = { path: "/:analyze-text", httpMethod: "POST", responses: { 200: { bodyMapper: Mappers.AnalyzeTextTaskResult }, default: { bodyMapper: Mappers.ErrorResponse } }, requestBody: Parameters.body, queryParameters: [Parameters.apiVersion, Parameters.includeStatistics], urlParameters: [Parameters.endpoint], headerParameters: [Parameters.contentType, Parameters.accept], mediaType: "json", serializer }; const analyzeBatchOperationSpec = { path: "/analyze-text/jobs", httpMethod: "POST", responses: { 202: { headersMapper: Mappers.GeneratedClientAnalyzeBatchHeaders }, default: { bodyMapper: Mappers.ErrorResponse } }, requestBody: Parameters.body1, queryParameters: [Parameters.apiVersion], urlParameters: [Parameters.endpoint], headerParameters: [Parameters.contentType, Parameters.accept], mediaType: "json", serializer }; //# sourceMappingURL=generatedClient.js.map