diff --git a/sdk/cognitiveservices/cognitiveservices-translation-batch/LICENSE.txt b/sdk/cognitiveservices/cognitiveservices-translation-batch/LICENSE.txt new file mode 100644 index 000000000000..ea8fb1516028 --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-translation-batch/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2020 Microsoft + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/sdk/cognitiveservices/cognitiveservices-translation-batch/README.md b/sdk/cognitiveservices/cognitiveservices-translation-batch/README.md new file mode 100644 index 000000000000..5a0094fc802d --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-translation-batch/README.md @@ -0,0 +1,103 @@ +## An isomorphic javascript sdk for - BatchDocumentTranslationClient + +This package contains an isomorphic SDK for BatchDocumentTranslationClient. + +### Currently supported environments + +- Node.js version 6.x.x or higher +- Browser JavaScript + +### How to Install + +```bash +npm install @azure/cognitiveservices-translation-batch +``` + +### How to use + +#### nodejs - Authentication, client creation and getOperations translation as an example written in TypeScript. + +##### Install @azure/ms-rest-nodeauth + +- Please install minimum version of `"@azure/ms-rest-nodeauth": "^3.0.0"`. +```bash +npm install @azure/ms-rest-nodeauth@"^3.0.0" +``` + +##### Sample code + +```typescript +import * as msRest from "@azure/ms-rest-js"; +import * as msRestNodeAuth from "@azure/ms-rest-nodeauth"; +import { BatchDocumentTranslationClient, BatchDocumentTranslationModels, BatchDocumentTranslationMappers } from "@azure/cognitiveservices-translation-batch"; +const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; + +msRestNodeAuth.interactiveLogin().then((creds) => { + const client = new BatchDocumentTranslationClient(creds, subscriptionId); + const endpoint = "testendpoint"; + const top = 1; + const skip = 1; + client.translation.getOperations(endpoint, top, skip).then((result) => { + console.log("The result is:"); + console.log(result); + }); +}).catch((err) => { + console.error(err); +}); +``` + +#### browser - Authentication, client creation and getOperations translation as an example written in JavaScript. + +##### Install @azure/ms-rest-browserauth + +```bash +npm install @azure/ms-rest-browserauth +``` + +##### Sample code + +See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser. + +- index.html +```html + + + + @azure/cognitiveservices-translation-batch sample + + + + + + + +``` + +## Related projects + +- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js) + +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js/sdk/cognitiveservices/cognitiveservices-translation-batch/README.png) diff --git a/sdk/cognitiveservices/cognitiveservices-translation-batch/package.json b/sdk/cognitiveservices/cognitiveservices-translation-batch/package.json new file mode 100644 index 000000000000..c9fdef5a14eb --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-translation-batch/package.json @@ -0,0 +1,57 @@ +{ + "name": "@azure/cognitiveservices-translation-batch", + "author": "Microsoft Corporation", + "description": "BatchDocumentTranslationClient Library with typescript type definitions for node.js and browser.", + "version": "1.0.0", + "dependencies": { + "@azure/ms-rest-js": "^2.0.4", + "tslib": "^1.10.0" + }, + "keywords": [ + "node", + "azure", + "typescript", + "browser", + "isomorphic" + ], + "license": "MIT", + "main": "./dist/cognitiveservices-translation-batch.js", + "module": "./esm/batchDocumentTranslationClient.js", + "types": "./esm/batchDocumentTranslationClient.d.ts", + "devDependencies": { + "typescript": "^3.5.3", + "rollup": "^1.18.0", + "rollup-plugin-node-resolve": "^5.2.0", + "rollup-plugin-sourcemaps": "^0.4.2", + "uglify-js": "^3.6.0" + }, + "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/cognitiveservices/cognitiveservices-translation-batch", + "repository": { + "type": "git", + "url": "https://github.com/Azure/azure-sdk-for-js.git" + }, + "bugs": { + "url": "https://github.com/Azure/azure-sdk-for-js/issues" + }, + "files": [ + "dist/**/*.js", + "dist/**/*.js.map", + "dist/**/*.d.ts", + "dist/**/*.d.ts.map", + "esm/**/*.js", + "esm/**/*.js.map", + "esm/**/*.d.ts", + "esm/**/*.d.ts.map", + "src/**/*.ts", + "README.md", + "rollup.config.js", + "tsconfig.json" + ], + "scripts": { + "build": "tsc && rollup -c rollup.config.js && npm run minify", + "minify": "uglifyjs -c -m --comments --source-map \"content='./dist/cognitiveservices-translation-batch.js.map'\" -o ./dist/cognitiveservices-translation-batch.min.js ./dist/cognitiveservices-translation-batch.js", + "prepack": "npm install && npm run build" + }, + "sideEffects": false, + "autoPublish": true +} diff --git a/sdk/cognitiveservices/cognitiveservices-translation-batch/rollup.config.js b/sdk/cognitiveservices/cognitiveservices-translation-batch/rollup.config.js new file mode 100644 index 000000000000..887300f07941 --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-translation-batch/rollup.config.js @@ -0,0 +1,37 @@ +import rollup from "rollup"; +import nodeResolve from "rollup-plugin-node-resolve"; +import sourcemaps from "rollup-plugin-sourcemaps"; + +/** + * @type {rollup.RollupFileOptions} + */ +const config = { + input: "./esm/batchDocumentTranslationClient.js", + external: [ + "@azure/ms-rest-js", + "@azure/ms-rest-azure-js" + ], + output: { + file: "./dist/cognitiveservices-translation-batch.js", + format: "umd", + name: "Azure.CognitiveservicesTranslationBatch", + sourcemap: true, + globals: { + "@azure/ms-rest-js": "msRest", + "@azure/ms-rest-azure-js": "msRestAzure" + }, + banner: `/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */` + }, + plugins: [ + nodeResolve({ mainFields: ['module', 'main'] }), + sourcemaps() + ] +}; + +export default config; diff --git a/sdk/cognitiveservices/cognitiveservices-translation-batch/src/batchDocumentTranslationClient.ts b/sdk/cognitiveservices/cognitiveservices-translation-batch/src/batchDocumentTranslationClient.ts new file mode 100644 index 000000000000..0687c4a59636 --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-translation-batch/src/batchDocumentTranslationClient.ts @@ -0,0 +1,40 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +import * as msRest from "@azure/ms-rest-js"; +import * as Models from "./models"; +import * as Mappers from "./models/mappers"; +import * as operations from "./operations"; +import { BatchDocumentTranslationClientContext } from "./batchDocumentTranslationClientContext"; + +class BatchDocumentTranslationClient extends BatchDocumentTranslationClientContext { + // Operation groups + translation: operations.Translation; + + /** + * Initializes a new instance of the BatchDocumentTranslationClient class. + * @param credentials Subscription credentials which uniquely identify client subscription. + * @param [options] The parameter options + */ + constructor(credentials: msRest.ServiceClientCredentials, options?: msRest.ServiceClientOptions) { + super(credentials, options); + this.translation = new operations.Translation(this); + } +} + +// Operation Specifications + +export { + BatchDocumentTranslationClient, + BatchDocumentTranslationClientContext, + Models as BatchDocumentTranslationModels, + Mappers as BatchDocumentTranslationMappers +}; +export * from "./operations"; diff --git a/sdk/cognitiveservices/cognitiveservices-translation-batch/src/batchDocumentTranslationClientContext.ts b/sdk/cognitiveservices/cognitiveservices-translation-batch/src/batchDocumentTranslationClientContext.ts new file mode 100644 index 000000000000..2c3c34bb007a --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-translation-batch/src/batchDocumentTranslationClientContext.ts @@ -0,0 +1,44 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +import * as msRest from "@azure/ms-rest-js"; + +const packageName = "@azure/cognitiveservices-translation-batch"; +const packageVersion = "1.0.0"; + +export class BatchDocumentTranslationClientContext extends msRest.ServiceClient { + credentials: msRest.ServiceClientCredentials; + + /** + * Initializes a new instance of the BatchDocumentTranslationClientContext class. + * @param credentials Subscription credentials which uniquely identify client subscription. + * @param [options] The parameter options + */ + constructor(credentials: msRest.ServiceClientCredentials, options?: msRest.ServiceClientOptions) { + if (credentials == undefined) { + throw new Error("'credentials' cannot be null."); + } + + if (!options) { + options = {}; + } + + if (!options.userAgent) { + const defaultUserAgent = msRest.getDefaultUserAgentValue(); + options.userAgent = `${packageName}/${packageVersion} ${defaultUserAgent}`; + } + + super(credentials, options); + + this.baseUri = "{endpoint}/translator/text/document/v1.0-preview.1"; + this.requestContentType = "application/json; charset=utf-8"; + this.credentials = credentials; + } +} diff --git a/sdk/cognitiveservices/cognitiveservices-translation-batch/src/models/index.ts b/sdk/cognitiveservices/cognitiveservices-translation-batch/src/models/index.ts new file mode 100644 index 000000000000..e875ebe57f38 --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-translation-batch/src/models/index.ts @@ -0,0 +1,700 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + + +import * as msRest from "@azure/ms-rest-js"; + +/** + * An interface representing DocumentFilter. + */ +export interface DocumentFilter { + /** + * A case-sensitive prefix string to filter documents in the source path for translation. + * For example, when using a Azure storage blob Uri, use the prefix to restrict sub folders for + * translation. + */ + prefix?: string; + /** + * A case-sensitive suffix string to filter documents in the source path for translation. + * This is most often use for file extensions + */ + suffix?: string; +} + +/** + * Source of the input documents + */ +export interface SourceInput { + /** + * Location of the folder / container with your documents + */ + sourceUrl: string; + filter?: DocumentFilter; + /** + * Language code + * If none is specified, we will perform auto detect on the document + */ + language?: string; + /** + * Possible values include: 'AzureBlob' + */ + storageSource?: StorageSource; +} + +/** + * Glossary / translation memory for the request + */ +export interface Glossary { + /** + * Location of the glossary. + * We will use the file extension to extract the formating if the format parameter is not + * supplied. + * + * If the translation language pair is not present in the glossary, it will not be applied + */ + glossaryUrl: string; + /** + * Format + */ + format?: string; + /** + * Version + */ + version?: string; +} + +/** + * Destination for the finished translated documents + */ +export interface TargetInput { + /** + * Location of the folder / container with your documents + */ + targetUrl: string; + /** + * Category / custom system for translation request + */ + category?: string; + /** + * Target Language + */ + language: string; + /** + * List of Glossary + */ + glossaries?: Glossary[]; + /** + * Possible values include: 'AzureBlob' + */ + storageSource?: StorageSource1; +} + +/** + * Definition for the input batch translation request + */ +export interface BatchRequest { + source: SourceInput; + /** + * Location of the destination for the output + */ + targets: TargetInput[]; +} + +/** + * Job submission batch request + */ +export interface BatchSubmissionRequest { + /** + * The input list of documents or folders containing documents + */ + inputs: BatchRequest[]; +} + +/** + * An interface representing StatusSummary. + */ +export interface StatusSummary { + /** + * Total count + */ + total?: number; + /** + * Failed count + */ + failed?: number; + /** + * Number of Success + */ + success?: number; + /** + * Number of in progress + */ + inProgress?: number; + /** + * Count of not yet started + */ + notYetStarted?: number; + /** + * Number of cancelled + */ + cancelled?: number; +} + +/** + * Job status response + */ +export interface BatchStatusDetail { + /** + * Id of the operation. + */ + id: string; + /** + * Operation created date time + */ + createdDateTimeUtc: Date; + /** + * Date time in which the operation's status has been updated + */ + lastActionDateTimeUtc: Date; + /** + * Possible values include: 'NotStarted', 'Running', 'Succeeded', 'Failed', 'Cancelled', + * 'Cancelling' + */ + status?: Status; + summary: StatusSummary; +} + +/** + * Document Status Response + */ +export interface BatchStatusResponse { + /** + * The summary status of individual operation + */ + value?: BatchStatusDetail[]; + /** + * Url for the next page. Null if no more pages available + */ + nextLink?: string; +} + +/** + * New Inner Error format which conforms to Cognitive Services API Guidelines which is available at + * https://microsoft.sharepoint.com/%3Aw%3A/t/CognitiveServicesPMO/EUoytcrjuJdKpeOKIK_QRC8BPtUYQpKBi8JsWyeDMRsWlQ?e=CPq8ow. + * This contains required properties ErrorCode, message and optional properties target, details(key + * value pair), inner error(this can be nested). + */ +export interface InnerErrorV2 { + /** + * Gets detailed error code. + * **NOTE: This property will not be serialized. It can only be populated by the server.** + */ + readonly code?: number; + /** + * Gets detailed error string. + * **NOTE: This property will not be serialized. It can only be populated by the server.** + */ + readonly error?: string; + /** + * Gets high level error message. + * **NOTE: This property will not be serialized. It can only be populated by the server.** + */ + readonly message?: string; + /** + * Gets the source of the error. + * For example it would be "documents" or "document id" in case of invalid document. + * **NOTE: This property will not be serialized. It can only be populated by the server.** + */ + readonly target?: string; + innerError?: InnerErrorV2; +} + +/** + * This contains an outer error with error code, message, details, target and an inner error with + * more descriptive details. + */ +export interface ErrorV2 { + /** + * Possible values include: 'InvalidRequest', 'InvalidArgument', 'InternalServerError', + * 'ServiceUnavailable', 'ResourceNotFound', 'Unauthorized', 'RequestRateTooHigh' + */ + code?: Code; + /** + * Gets high level error message. + * **NOTE: This property will not be serialized. It can only be populated by the server.** + */ + readonly message?: string; + /** + * Gets the source of the error. + * For example it would be "documents" or "document id" in case of invalid document. + * **NOTE: This property will not be serialized. It can only be populated by the server.** + */ + readonly target?: string; + innerError?: InnerErrorV2; +} + +/** + * An interface representing DocumentStatusDetail. + */ +export interface DocumentStatusDetail { + /** + * Location of the document or folder + */ + path: string; + /** + * Operation created date time + */ + createdDateTimeUtc: Date; + /** + * Date time in which the operation's status has been updated + */ + lastActionDateTimeUtc: Date; + /** + * Possible values include: 'NotStarted', 'Running', 'Succeeded', 'Failed', 'Cancelled', + * 'Cancelling' + */ + status: Status1; + /** + * Detected language of the original document (to be implemented) + */ + detectedLanguage?: string; + /** + * To language + */ + to: string; + error?: ErrorV2; + /** + * Progress of the translation if available + */ + progress?: number; + /** + * Document Id + */ + id?: string; +} + +/** + * Document Status Response + */ +export interface DocumentStatusResponse { + /** + * The detail status of individual documents + */ + value?: DocumentStatusDetail[]; + /** + * Url for the next page. Null if no more pages available + */ + nextLink?: string; +} + +/** + * An interface representing FileFormat. + */ +export interface FileFormat { + /** + * Name of the format + */ + format?: string; + /** + * Supported file extension for this format + */ + fileExtensions?: string[]; + /** + * Supported Content-Types for this format + */ + contentTypes?: string[]; + /** + * Supported Version + */ + versions?: string[]; +} + +/** + * Base type for List return in our api + */ +export interface FileFormatListResult { + /** + * list of objects + */ + value?: FileFormat[]; +} + +/** + * Base type for List return in our api + */ +export interface StorageSourceListResult { + /** + * list of objects + */ + value?: string[]; +} + +/** + * Contains unified error information used for HTTP responses across any Cognitive Service. + * Instances + * can be created either through Microsoft.CloudAI.Containers.HttpStatusExceptionV2 or by returning + * it directly from + * a controller. + */ +export interface ErrorResponseV2 { + error?: ErrorV2; +} + +/** + * Optional Parameters. + */ +export interface TranslationSubmitBatchRequestOptionalParams extends msRest.RequestOptionsBase { + /** + * request details + */ + body?: BatchSubmissionRequest; +} + +/** + * Optional Parameters. + */ +export interface TranslationGetOperationsOptionalParams extends msRest.RequestOptionsBase { + /** + * Take the $top entries in the collection + * When both $top and $skip are supplied, $skip is applied first. Default value: 50. + */ + top?: number; + /** + * Skip the $skip entries in the collection + * When both $top and $skip are supplied, $skip is applied first. Default value: 0. + */ + skip?: number; +} + +/** + * Optional Parameters. + */ +export interface TranslationGetOperationDocumentsStatusOptionalParams extends msRest.RequestOptionsBase { + /** + * Take the $top entries in the collection + * When both $top and $skip are supplied, $skip is applied first. Default value: 50. + */ + top?: number; + /** + * Skip the $skip entries in the collection + * When both $top and $skip are supplied, $skip is applied first. Default value: 0. + */ + skip?: number; +} + +/** + * Defines headers for SubmitBatchRequest operation. + */ +export interface TranslationSubmitBatchRequestHeaders { + /** + * Location of batch the operation + */ + operationLocation: string; +} + +/** + * Defines headers for GetOperations operation. + */ +export interface TranslationGetOperationsHeaders { + /** + * Indicates how long to wait before making a new request. + */ + retryAfter: number; + /** + * The ETag response-header field provides the current value of the entity tag for the requested + * variant. Used with If-Match, If-None-Match and If-Range to implement optimistic concurrency + * control. + */ + eTag: string; +} + +/** + * Defines headers for GetDocumentStatus operation. + */ +export interface TranslationGetDocumentStatusHeaders { + /** + * Indicates how long to wait before making a new request. + */ + retryAfter: number; + /** + * The ETag response-header field provides the current value of the entity tag for the requested + * variant. Used with If-Match, If-None-Match and If-Range to implement optimistic concurrency + * control. + */ + eTag: string; +} + +/** + * Defines headers for GetOperationStatus operation. + */ +export interface TranslationGetOperationStatusHeaders { + /** + * Indicates how long to wait before making a new request. + */ + retryAfter: number; + /** + * The ETag response-header field provides the current value of the entity tag for the requested + * variant. Used with If-Match, If-None-Match and If-Range to implement optimistic concurrency + * control. + */ + eTag: string; +} + +/** + * Defines headers for GetOperationDocumentsStatus operation. + */ +export interface TranslationGetOperationDocumentsStatusHeaders { + /** + * Indicates how long to wait before making a new request. + */ + retryAfter: number; + /** + * The ETag response-header field provides the current value of the entity tag for the requested + * variant. Used with If-Match, If-None-Match and If-Range to implement optimistic concurrency + * control. + */ + eTag: string; +} + +/** + * Defines values for StorageSource. + * Possible values include: 'AzureBlob' + * @readonly + * @enum {string} + */ +export type StorageSource = 'AzureBlob'; + +/** + * Defines values for StorageSource1. + * Possible values include: 'AzureBlob' + * @readonly + * @enum {string} + */ +export type StorageSource1 = 'AzureBlob'; + +/** + * Defines values for Status. + * Possible values include: 'NotStarted', 'Running', 'Succeeded', 'Failed', 'Cancelled', + * 'Cancelling' + * @readonly + * @enum {string} + */ +export type Status = 'NotStarted' | 'Running' | 'Succeeded' | 'Failed' | 'Cancelled' | 'Cancelling'; + +/** + * Defines values for Code. + * Possible values include: 'InvalidRequest', 'InvalidArgument', 'InternalServerError', + * 'ServiceUnavailable', 'ResourceNotFound', 'Unauthorized', 'RequestRateTooHigh' + * @readonly + * @enum {string} + */ +export type Code = 'InvalidRequest' | 'InvalidArgument' | 'InternalServerError' | 'ServiceUnavailable' | 'ResourceNotFound' | 'Unauthorized' | 'RequestRateTooHigh'; + +/** + * Defines values for Status1. + * Possible values include: 'NotStarted', 'Running', 'Succeeded', 'Failed', 'Cancelled', + * 'Cancelling' + * @readonly + * @enum {string} + */ +export type Status1 = 'NotStarted' | 'Running' | 'Succeeded' | 'Failed' | 'Cancelled' | 'Cancelling'; + +/** + * Contains response data for the submitBatchRequest operation. + */ +export type TranslationSubmitBatchRequestResponse = TranslationSubmitBatchRequestHeaders & { + /** + * The underlying HTTP response. + */ + _response: msRest.HttpResponse & { + /** + * The parsed HTTP response headers. + */ + parsedHeaders: TranslationSubmitBatchRequestHeaders; + }; +}; + +/** + * Contains response data for the getOperations operation. + */ +export type TranslationGetOperationsResponse = BatchStatusResponse & TranslationGetOperationsHeaders & { + /** + * The underlying HTTP response. + */ + _response: msRest.HttpResponse & { + /** + * The parsed HTTP response headers. + */ + parsedHeaders: TranslationGetOperationsHeaders; + + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: BatchStatusResponse; + }; +}; + +/** + * Contains response data for the getDocumentStatus operation. + */ +export type TranslationGetDocumentStatusResponse = DocumentStatusDetail & TranslationGetDocumentStatusHeaders & { + /** + * The underlying HTTP response. + */ + _response: msRest.HttpResponse & { + /** + * The parsed HTTP response headers. + */ + parsedHeaders: TranslationGetDocumentStatusHeaders; + + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: DocumentStatusDetail; + }; +}; + +/** + * Contains response data for the getOperationStatus operation. + */ +export type TranslationGetOperationStatusResponse = BatchStatusDetail & TranslationGetOperationStatusHeaders & { + /** + * The underlying HTTP response. + */ + _response: msRest.HttpResponse & { + /** + * The parsed HTTP response headers. + */ + parsedHeaders: TranslationGetOperationStatusHeaders; + + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: BatchStatusDetail; + }; +}; + +/** + * Contains response data for the cancelOperation operation. + */ +export type TranslationCancelOperationResponse = BatchStatusDetail & { + /** + * The underlying HTTP response. + */ + _response: msRest.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: BatchStatusDetail; + }; +}; + +/** + * Contains response data for the getOperationDocumentsStatus operation. + */ +export type TranslationGetOperationDocumentsStatusResponse = DocumentStatusResponse & TranslationGetOperationDocumentsStatusHeaders & { + /** + * The underlying HTTP response. + */ + _response: msRest.HttpResponse & { + /** + * The parsed HTTP response headers. + */ + parsedHeaders: TranslationGetOperationDocumentsStatusHeaders; + + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: DocumentStatusResponse; + }; +}; + +/** + * Contains response data for the getDocumentFormats operation. + */ +export type TranslationGetDocumentFormatsResponse = FileFormatListResult & { + /** + * The underlying HTTP response. + */ + _response: msRest.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: FileFormatListResult; + }; +}; + +/** + * Contains response data for the getGlossaryFormats operation. + */ +export type TranslationGetGlossaryFormatsResponse = FileFormatListResult & { + /** + * The underlying HTTP response. + */ + _response: msRest.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: FileFormatListResult; + }; +}; + +/** + * Contains response data for the getDocumentStorageSource operation. + */ +export type TranslationGetDocumentStorageSourceResponse = StorageSourceListResult & { + /** + * The underlying HTTP response. + */ + _response: msRest.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + + /** + * The response body as parsed JSON or XML + */ + parsedBody: StorageSourceListResult; + }; +}; diff --git a/sdk/cognitiveservices/cognitiveservices-translation-batch/src/models/mappers.ts b/sdk/cognitiveservices/cognitiveservices-translation-batch/src/models/mappers.ts new file mode 100644 index 000000000000..521b952e341d --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-translation-batch/src/models/mappers.ts @@ -0,0 +1,715 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import * as msRest from "@azure/ms-rest-js"; + + +export const DocumentFilter: msRest.CompositeMapper = { + serializedName: "DocumentFilter", + type: { + name: "Composite", + className: "DocumentFilter", + modelProperties: { + prefix: { + serializedName: "prefix", + type: { + name: "String" + } + }, + suffix: { + serializedName: "suffix", + type: { + name: "String" + } + } + } + } +}; + +export const SourceInput: msRest.CompositeMapper = { + serializedName: "SourceInput", + type: { + name: "Composite", + className: "SourceInput", + modelProperties: { + sourceUrl: { + required: true, + serializedName: "sourceUrl", + type: { + name: "String" + } + }, + filter: { + serializedName: "filter", + type: { + name: "Composite", + className: "DocumentFilter" + } + }, + language: { + serializedName: "language", + type: { + name: "String" + } + }, + storageSource: { + serializedName: "storageSource", + type: { + name: "String" + } + } + } + } +}; + +export const Glossary: msRest.CompositeMapper = { + serializedName: "Glossary", + type: { + name: "Composite", + className: "Glossary", + modelProperties: { + glossaryUrl: { + required: true, + serializedName: "glossaryUrl", + type: { + name: "String" + } + }, + format: { + serializedName: "format", + type: { + name: "String" + } + }, + version: { + serializedName: "version", + type: { + name: "String" + } + } + } + } +}; + +export const TargetInput: msRest.CompositeMapper = { + serializedName: "TargetInput", + type: { + name: "Composite", + className: "TargetInput", + modelProperties: { + targetUrl: { + required: true, + serializedName: "targetUrl", + type: { + name: "String" + } + }, + category: { + serializedName: "category", + type: { + name: "String" + } + }, + language: { + required: true, + serializedName: "language", + type: { + name: "String" + } + }, + glossaries: { + serializedName: "glossaries", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "Glossary" + } + } + } + }, + storageSource: { + serializedName: "storageSource", + type: { + name: "String" + } + } + } + } +}; + +export const BatchRequest: msRest.CompositeMapper = { + serializedName: "BatchRequest", + type: { + name: "Composite", + className: "BatchRequest", + modelProperties: { + source: { + required: true, + serializedName: "source", + type: { + name: "Composite", + className: "SourceInput" + } + }, + targets: { + required: true, + serializedName: "targets", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "TargetInput" + } + } + } + } + } + } +}; + +export const BatchSubmissionRequest: msRest.CompositeMapper = { + serializedName: "BatchSubmissionRequest", + type: { + name: "Composite", + className: "BatchSubmissionRequest", + modelProperties: { + inputs: { + required: true, + serializedName: "inputs", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "BatchRequest" + } + } + } + } + } + } +}; + +export const StatusSummary: msRest.CompositeMapper = { + serializedName: "StatusSummary", + type: { + name: "Composite", + className: "StatusSummary", + modelProperties: { + total: { + serializedName: "total", + type: { + name: "Number" + } + }, + failed: { + serializedName: "failed", + type: { + name: "Number" + } + }, + success: { + serializedName: "success", + type: { + name: "Number" + } + }, + inProgress: { + serializedName: "inProgress", + type: { + name: "Number" + } + }, + notYetStarted: { + serializedName: "notYetStarted", + type: { + name: "Number" + } + }, + cancelled: { + serializedName: "cancelled", + type: { + name: "Number" + } + } + } + } +}; + +export const BatchStatusDetail: msRest.CompositeMapper = { + serializedName: "BatchStatusDetail", + type: { + name: "Composite", + className: "BatchStatusDetail", + modelProperties: { + id: { + required: true, + serializedName: "id", + type: { + name: "Uuid" + } + }, + createdDateTimeUtc: { + required: true, + serializedName: "createdDateTimeUtc", + type: { + name: "DateTime" + } + }, + lastActionDateTimeUtc: { + required: true, + serializedName: "lastActionDateTimeUtc", + type: { + name: "DateTime" + } + }, + status: { + serializedName: "status", + type: { + name: "String" + } + }, + summary: { + required: true, + serializedName: "summary", + type: { + name: "Composite", + className: "StatusSummary" + } + } + } + } +}; + +export const BatchStatusResponse: msRest.CompositeMapper = { + serializedName: "BatchStatusResponse", + type: { + name: "Composite", + className: "BatchStatusResponse", + modelProperties: { + value: { + serializedName: "value", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "BatchStatusDetail" + } + } + } + }, + nextLink: { + serializedName: "@nextLink", + type: { + name: "String" + } + } + } + } +}; + +export const InnerErrorV2: msRest.CompositeMapper = { + serializedName: "InnerErrorV2", + type: { + name: "Composite", + className: "InnerErrorV2", + modelProperties: { + code: { + readOnly: true, + serializedName: "code", + type: { + name: "Number" + } + }, + error: { + readOnly: true, + serializedName: "error", + type: { + name: "String" + } + }, + message: { + readOnly: true, + serializedName: "message", + type: { + name: "String" + } + }, + target: { + readOnly: true, + serializedName: "target", + type: { + name: "String" + } + }, + innerError: { + serializedName: "innerError", + type: { + name: "Composite", + className: "InnerErrorV2" + } + } + } + } +}; + +export const ErrorV2: msRest.CompositeMapper = { + serializedName: "ErrorV2", + type: { + name: "Composite", + className: "ErrorV2", + modelProperties: { + code: { + serializedName: "code", + type: { + name: "String" + } + }, + message: { + readOnly: true, + serializedName: "message", + type: { + name: "String" + } + }, + target: { + readOnly: true, + serializedName: "target", + type: { + name: "String" + } + }, + innerError: { + serializedName: "innerError", + type: { + name: "Composite", + className: "InnerErrorV2" + } + } + } + } +}; + +export const DocumentStatusDetail: msRest.CompositeMapper = { + serializedName: "DocumentStatusDetail", + type: { + name: "Composite", + className: "DocumentStatusDetail", + modelProperties: { + path: { + required: true, + serializedName: "path", + type: { + name: "String" + } + }, + createdDateTimeUtc: { + required: true, + serializedName: "createdDateTimeUtc", + type: { + name: "DateTime" + } + }, + lastActionDateTimeUtc: { + required: true, + serializedName: "lastActionDateTimeUtc", + type: { + name: "DateTime" + } + }, + status: { + required: true, + serializedName: "status", + type: { + name: "String" + } + }, + detectedLanguage: { + serializedName: "detectedLanguage", + type: { + name: "String" + } + }, + to: { + required: true, + serializedName: "to", + type: { + name: "String" + } + }, + error: { + serializedName: "error", + type: { + name: "Composite", + className: "ErrorV2" + } + }, + progress: { + serializedName: "progress", + constraints: { + InclusiveMaximum: 1, + InclusiveMinimum: 0 + }, + type: { + name: "Number" + } + }, + id: { + serializedName: "id", + type: { + name: "Uuid" + } + } + } + } +}; + +export const DocumentStatusResponse: msRest.CompositeMapper = { + serializedName: "DocumentStatusResponse", + type: { + name: "Composite", + className: "DocumentStatusResponse", + modelProperties: { + value: { + serializedName: "value", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "DocumentStatusDetail" + } + } + } + }, + nextLink: { + serializedName: "@nextLink", + type: { + name: "String" + } + } + } + } +}; + +export const FileFormat: msRest.CompositeMapper = { + serializedName: "FileFormat", + type: { + name: "Composite", + className: "FileFormat", + modelProperties: { + format: { + serializedName: "format", + type: { + name: "String" + } + }, + fileExtensions: { + serializedName: "fileExtensions", + type: { + name: "Sequence", + element: { + type: { + name: "String" + } + } + } + }, + contentTypes: { + serializedName: "contentTypes", + type: { + name: "Sequence", + element: { + type: { + name: "String" + } + } + } + }, + versions: { + serializedName: "versions", + type: { + name: "Sequence", + element: { + type: { + name: "String" + } + } + } + } + } + } +}; + +export const FileFormatListResult: msRest.CompositeMapper = { + serializedName: "FileFormatListResult", + type: { + name: "Composite", + className: "FileFormatListResult", + modelProperties: { + value: { + serializedName: "value", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "FileFormat" + } + } + } + } + } + } +}; + +export const StorageSourceListResult: msRest.CompositeMapper = { + serializedName: "StorageSourceListResult", + type: { + name: "Composite", + className: "StorageSourceListResult", + modelProperties: { + value: { + serializedName: "value", + type: { + name: "Sequence", + element: { + type: { + name: "String" + } + } + } + } + } + } +}; + +export const ErrorResponseV2: msRest.CompositeMapper = { + serializedName: "ErrorResponseV2", + type: { + name: "Composite", + className: "ErrorResponseV2", + modelProperties: { + error: { + serializedName: "error", + type: { + name: "Composite", + className: "ErrorV2" + } + } + } + } +}; + +export const TranslationSubmitBatchRequestHeaders: msRest.CompositeMapper = { + serializedName: "translation-submitbatchrequest-headers", + type: { + name: "Composite", + className: "TranslationSubmitBatchRequestHeaders", + modelProperties: { + operationLocation: { + serializedName: "operation-location", + type: { + name: "String" + } + } + } + } +}; + +export const TranslationGetOperationsHeaders: msRest.CompositeMapper = { + serializedName: "translation-getoperations-headers", + type: { + name: "Composite", + className: "TranslationGetOperationsHeaders", + modelProperties: { + retryAfter: { + serializedName: "retry-after", + type: { + name: "Number" + } + }, + eTag: { + serializedName: "etag", + type: { + name: "String" + } + } + } + } +}; + +export const TranslationGetDocumentStatusHeaders: msRest.CompositeMapper = { + serializedName: "translation-getdocumentstatus-headers", + type: { + name: "Composite", + className: "TranslationGetDocumentStatusHeaders", + modelProperties: { + retryAfter: { + serializedName: "retry-after", + type: { + name: "Number" + } + }, + eTag: { + serializedName: "etag", + type: { + name: "String" + } + } + } + } +}; + +export const TranslationGetOperationStatusHeaders: msRest.CompositeMapper = { + serializedName: "translation-getoperationstatus-headers", + type: { + name: "Composite", + className: "TranslationGetOperationStatusHeaders", + modelProperties: { + retryAfter: { + serializedName: "retry-after", + type: { + name: "Number" + } + }, + eTag: { + serializedName: "etag", + type: { + name: "String" + } + } + } + } +}; + +export const TranslationGetOperationDocumentsStatusHeaders: msRest.CompositeMapper = { + serializedName: "translation-getoperationdocumentsstatus-headers", + type: { + name: "Composite", + className: "TranslationGetOperationDocumentsStatusHeaders", + modelProperties: { + retryAfter: { + serializedName: "retry-after", + type: { + name: "Number" + } + }, + eTag: { + serializedName: "etag", + type: { + name: "String" + } + } + } + } +}; diff --git a/sdk/cognitiveservices/cognitiveservices-translation-batch/src/models/parameters.ts b/sdk/cognitiveservices/cognitiveservices-translation-batch/src/models/parameters.ts new file mode 100644 index 000000000000..bb6a6f4d5393 --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-translation-batch/src/models/parameters.ts @@ -0,0 +1,78 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +import * as msRest from "@azure/ms-rest-js"; + +export const documentId: msRest.OperationURLParameter = { + parameterPath: "documentId", + mapper: { + required: true, + serializedName: "documentId", + type: { + name: "Uuid" + } + } +}; +export const endpoint: msRest.OperationURLParameter = { + parameterPath: "endpoint", + mapper: { + required: true, + serializedName: "endpoint", + defaultValue: '', + type: { + name: "String" + } + }, + skipEncoding: true +}; +export const id: msRest.OperationURLParameter = { + parameterPath: "id", + mapper: { + required: true, + serializedName: "id", + type: { + name: "Uuid" + } + } +}; +export const skip: msRest.OperationQueryParameter = { + parameterPath: [ + "options", + "skip" + ], + mapper: { + serializedName: "$skip", + defaultValue: 0, + constraints: { + InclusiveMaximum: 2147483647, + InclusiveMinimum: 0 + }, + type: { + name: "Number" + } + } +}; +export const top: msRest.OperationQueryParameter = { + parameterPath: [ + "options", + "top" + ], + mapper: { + serializedName: "$top", + defaultValue: 50, + constraints: { + InclusiveMaximum: 100, + InclusiveMinimum: 1 + }, + type: { + name: "Number" + } + } +}; diff --git a/sdk/cognitiveservices/cognitiveservices-translation-batch/src/models/translationMappers.ts b/sdk/cognitiveservices/cognitiveservices-translation-batch/src/models/translationMappers.ts new file mode 100644 index 000000000000..0846f74261e5 --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-translation-batch/src/models/translationMappers.ts @@ -0,0 +1,32 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +export { + BatchRequest, + BatchStatusDetail, + BatchStatusResponse, + BatchSubmissionRequest, + DocumentFilter, + DocumentStatusDetail, + DocumentStatusResponse, + ErrorResponseV2, + ErrorV2, + FileFormat, + FileFormatListResult, + Glossary, + InnerErrorV2, + SourceInput, + StatusSummary, + StorageSourceListResult, + TargetInput, + TranslationGetDocumentStatusHeaders, + TranslationGetOperationDocumentsStatusHeaders, + TranslationGetOperationsHeaders, + TranslationGetOperationStatusHeaders, + TranslationSubmitBatchRequestHeaders +} from "../models/mappers"; diff --git a/sdk/cognitiveservices/cognitiveservices-translation-batch/src/operations/index.ts b/sdk/cognitiveservices/cognitiveservices-translation-batch/src/operations/index.ts new file mode 100644 index 000000000000..25de02076ffa --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-translation-batch/src/operations/index.ts @@ -0,0 +1,11 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +export * from "./translation"; diff --git a/sdk/cognitiveservices/cognitiveservices-translation-batch/src/operations/translation.ts b/sdk/cognitiveservices/cognitiveservices-translation-batch/src/operations/translation.ts new file mode 100644 index 000000000000..2a2267365325 --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-translation-batch/src/operations/translation.ts @@ -0,0 +1,701 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +import * as msRest from "@azure/ms-rest-js"; +import * as Models from "../models"; +import * as Mappers from "../models/translationMappers"; +import * as Parameters from "../models/parameters"; +import { BatchDocumentTranslationClientContext } from "../batchDocumentTranslationClientContext"; + +/** Class representing a Translation. */ +export class Translation { + private readonly client: BatchDocumentTranslationClientContext; + + /** + * Create a Translation. + * @param {BatchDocumentTranslationClientContext} client Reference to the service client. + */ + constructor(client: BatchDocumentTranslationClientContext) { + this.client = client; + } + + /** + * Submit a batch request to the document translation service. + * + * Each request can consists of multiple inputs. + * Each input will contains both a source and destination container for source and target language + * pair. + * + * The prefix and suffix filter (if supplied) will be used to filter the folders. + * The prefix will be applied to the subpath after the container name + * + * Glossaries / Translation memory can be supplied and will be applied when the document is being + * translated. + * If the glossary is invalid or unreachable during translation time. An error will be indicated + * in the document status. + * + * If the file with the same name already exists in the destination, it will be overwritten. + * TargetUrl for each target language needs to be unique. + * @summary Submit a batch document translation request to the translation service + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param [options] The optional parameters + * @returns Promise + */ + submitBatchRequest(endpoint: string, options?: Models.TranslationSubmitBatchRequestOptionalParams): Promise; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param callback The callback + */ + submitBatchRequest(endpoint: string, callback: msRest.ServiceCallback): void; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param options The optional parameters + * @param callback The callback + */ + submitBatchRequest(endpoint: string, options: Models.TranslationSubmitBatchRequestOptionalParams, callback: msRest.ServiceCallback): void; + submitBatchRequest(endpoint: string, options?: Models.TranslationSubmitBatchRequestOptionalParams | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { + return this.client.sendOperationRequest( + { + endpoint, + options + }, + submitBatchRequestOperationSpec, + callback) as Promise; + } + + /** + * Returns the list of status of the translation batch operation. + * The list will consist only of the batch request submitted by the user (based on their + * subscription) + * + * The operation status are sorted by the operation Id + * + * If the number of operations exceed our paging limit, server side paging will be used. + * Paginated responses will indicate a partial result by including a continuation token in the + * response. The absence of a continuation token means that no additional pages are available. + * + * Clients MAY use $top and $skip query parameters to specify a number of results to return and an + * offset into the collection. + * The server will honor the values specified by the client; however, clients MUST be prepared to + * handle responses that contain a different page size or contain a continuation token. + * When both $top and $skip are given by a client, the server SHOULD first apply $skip and then + * $top on the collection. + * Note: If the server can't honor $top and/or $skip, the server MUST return an error to the client + * informing about it instead of just ignoring the query options. This will avoid the risk of the + * client making assumptions about the data returned. + * @summary Returns the list of operations submitted and their summary status + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param [options] The optional parameters + * @returns Promise + */ + getOperations(endpoint: string, options?: Models.TranslationGetOperationsOptionalParams): Promise; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param callback The callback + */ + getOperations(endpoint: string, callback: msRest.ServiceCallback): void; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param options The optional parameters + * @param callback The callback + */ + getOperations(endpoint: string, options: Models.TranslationGetOperationsOptionalParams, callback: msRest.ServiceCallback): void; + getOperations(endpoint: string, options?: Models.TranslationGetOperationsOptionalParams | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { + return this.client.sendOperationRequest( + { + endpoint, + options + }, + getOperationsOperationSpec, + callback) as Promise; + } + + /** + * Returns the status of the translation of the document. + * @summary Returns the status of the specific document + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param id Format - uuid. The batch id + * @param documentId Format - uuid. The document id + * @param [options] The optional parameters + * @returns Promise + */ + getDocumentStatus(endpoint: string, id: string, documentId: string, options?: msRest.RequestOptionsBase): Promise; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param id Format - uuid. The batch id + * @param documentId Format - uuid. The document id + * @param callback The callback + */ + getDocumentStatus(endpoint: string, id: string, documentId: string, callback: msRest.ServiceCallback): void; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param id Format - uuid. The batch id + * @param documentId Format - uuid. The document id + * @param options The optional parameters + * @param callback The callback + */ + getDocumentStatus(endpoint: string, id: string, documentId: string, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + getDocumentStatus(endpoint: string, id: string, documentId: string, options?: msRest.RequestOptionsBase | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { + return this.client.sendOperationRequest( + { + endpoint, + id, + documentId, + options + }, + getDocumentStatusOperationSpec, + callback) as Promise; + } + + /** + * Returns the status of the translation batch operation. + * The status will include the overall job status as well as a summary of the current progress of + * all the documents being translated. + * @summary Returns the status of the batch translation operation + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param id Format - uuid. The operation id + * @param [options] The optional parameters + * @returns Promise + */ + getOperationStatus(endpoint: string, id: string, options?: msRest.RequestOptionsBase): Promise; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param id Format - uuid. The operation id + * @param callback The callback + */ + getOperationStatus(endpoint: string, id: string, callback: msRest.ServiceCallback): void; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param id Format - uuid. The operation id + * @param options The optional parameters + * @param callback The callback + */ + getOperationStatus(endpoint: string, id: string, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + getOperationStatus(endpoint: string, id: string, options?: msRest.RequestOptionsBase | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { + return this.client.sendOperationRequest( + { + endpoint, + id, + options + }, + getOperationStatusOperationSpec, + callback) as Promise; + } + + /** + * Cancel a currently processing or queued operation. + * An operation will not be cancelled if it is already completed or failed or cancelling. A bad + * request will be returned. + * All documents that have completed translation will not be cancelled and will be charged. + * All pending documents will be cancelled if possible. + * @summary Cancel a currently processing or queued operation. + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param id Format - uuid. The operation-id + * @param [options] The optional parameters + * @returns Promise + */ + cancelOperation(endpoint: string, id: string, options?: msRest.RequestOptionsBase): Promise; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param id Format - uuid. The operation-id + * @param callback The callback + */ + cancelOperation(endpoint: string, id: string, callback: msRest.ServiceCallback): void; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param id Format - uuid. The operation-id + * @param options The optional parameters + * @param callback The callback + */ + cancelOperation(endpoint: string, id: string, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + cancelOperation(endpoint: string, id: string, options?: msRest.RequestOptionsBase | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { + return this.client.sendOperationRequest( + { + endpoint, + id, + options + }, + cancelOperationOperationSpec, + callback) as Promise; + } + + /** + * Returns the status of the list of documents translation operation by a given operation id. + * + * The documents are sorted by the document Id + * + * If the number of documents exceed our paging limit, server side paging will be used. + * Paginated responses will indicate a partial result by including a continuation token in the + * response. The absence of a continuation token means that no additional pages are available. + * + * Clients MAY use $top and $skip query parameters to specify a number of results to return and an + * offset into the collection. + * The server will honor the values specified by the client; however, clients MUST be prepared to + * handle responses that contain a different page size or contain a continuation token. + * When both $top and $skip are given by a client, the server SHOULD first apply $skip and then + * $top on the collection. + * Note: If the server can't honor $top and/or $skip, the server MUST return an error to the client + * informing about it instead of just ignoring the query options. This will avoid the risk of the + * client making assumptions about the data returned. + * @summary Returns the status of the documents of a translation batch operation + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param id Format - uuid. The operation id + * @param [options] The optional parameters + * @returns Promise + */ + getOperationDocumentsStatus(endpoint: string, id: string, options?: Models.TranslationGetOperationDocumentsStatusOptionalParams): Promise; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param id Format - uuid. The operation id + * @param callback The callback + */ + getOperationDocumentsStatus(endpoint: string, id: string, callback: msRest.ServiceCallback): void; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param id Format - uuid. The operation id + * @param options The optional parameters + * @param callback The callback + */ + getOperationDocumentsStatus(endpoint: string, id: string, options: Models.TranslationGetOperationDocumentsStatusOptionalParams, callback: msRest.ServiceCallback): void; + getOperationDocumentsStatus(endpoint: string, id: string, options?: Models.TranslationGetOperationDocumentsStatusOptionalParams | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { + return this.client.sendOperationRequest( + { + endpoint, + id, + options + }, + getOperationDocumentsStatusOperationSpec, + callback) as Promise; + } + + /** + * The list of supported document formats supported by our service. + * The list will include the common file extension used and supported as well as the content-type + * if using the upload API. + * @summary Returns the list of supported document formats + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param [options] The optional parameters + * @returns Promise + */ + getDocumentFormats(endpoint: string, options?: msRest.RequestOptionsBase): Promise; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param callback The callback + */ + getDocumentFormats(endpoint: string, callback: msRest.ServiceCallback): void; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param options The optional parameters + * @param callback The callback + */ + getDocumentFormats(endpoint: string, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + getDocumentFormats(endpoint: string, options?: msRest.RequestOptionsBase | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { + return this.client.sendOperationRequest( + { + endpoint, + options + }, + getDocumentFormatsOperationSpec, + callback) as Promise; + } + + /** + * The list of supported glossary formats supported by our service. + * The list will include the common file extension used. + * @summary Returns the list of supported document formats + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param [options] The optional parameters + * @returns Promise + */ + getGlossaryFormats(endpoint: string, options?: msRest.RequestOptionsBase): Promise; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param callback The callback + */ + getGlossaryFormats(endpoint: string, callback: msRest.ServiceCallback): void; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param options The optional parameters + * @param callback The callback + */ + getGlossaryFormats(endpoint: string, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + getGlossaryFormats(endpoint: string, options?: msRest.RequestOptionsBase | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { + return this.client.sendOperationRequest( + { + endpoint, + options + }, + getGlossaryFormatsOperationSpec, + callback) as Promise; + } + + /** + * The list of storage sources supported by our service. + * @summary Returns the list of supported storage sources + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param [options] The optional parameters + * @returns Promise + */ + getDocumentStorageSource(endpoint: string, options?: msRest.RequestOptionsBase): Promise; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param callback The callback + */ + getDocumentStorageSource(endpoint: string, callback: msRest.ServiceCallback): void; + /** + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus.api.cognitive.microsoft.com). + * @param options The optional parameters + * @param callback The callback + */ + getDocumentStorageSource(endpoint: string, options: msRest.RequestOptionsBase, callback: msRest.ServiceCallback): void; + getDocumentStorageSource(endpoint: string, options?: msRest.RequestOptionsBase | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { + return this.client.sendOperationRequest( + { + endpoint, + options + }, + getDocumentStorageSourceOperationSpec, + callback) as Promise; + } +} + +// Operation Specifications +const serializer = new msRest.Serializer(Mappers); +const submitBatchRequestOperationSpec: msRest.OperationSpec = { + httpMethod: "POST", + path: "v1.0-preview.1/batches", + urlParameters: [ + Parameters.endpoint + ], + requestBody: { + parameterPath: [ + "options", + "body" + ], + mapper: Mappers.BatchSubmissionRequest + }, + responses: { + 202: { + headersMapper: Mappers.TranslationSubmitBatchRequestHeaders + }, + 400: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationSubmitBatchRequestHeaders + }, + 401: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationSubmitBatchRequestHeaders + }, + 429: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationSubmitBatchRequestHeaders + }, + 500: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationSubmitBatchRequestHeaders + }, + 503: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationSubmitBatchRequestHeaders + }, + default: {} + }, + serializer +}; + +const getOperationsOperationSpec: msRest.OperationSpec = { + httpMethod: "GET", + path: "v1.0-preview.1/batches", + urlParameters: [ + Parameters.endpoint + ], + queryParameters: [ + Parameters.top, + Parameters.skip + ], + responses: { + 200: { + bodyMapper: Mappers.BatchStatusResponse, + headersMapper: Mappers.TranslationGetOperationsHeaders + }, + 400: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetOperationsHeaders + }, + 401: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetOperationsHeaders + }, + 429: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetOperationsHeaders + }, + 500: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetOperationsHeaders + }, + 503: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetOperationsHeaders + }, + default: {} + }, + serializer +}; + +const getDocumentStatusOperationSpec: msRest.OperationSpec = { + httpMethod: "GET", + path: "v1.0-preview.1/batches/{id}/documents/{documentId}", + urlParameters: [ + Parameters.endpoint, + Parameters.id, + Parameters.documentId + ], + responses: { + 200: { + bodyMapper: Mappers.DocumentStatusDetail, + headersMapper: Mappers.TranslationGetDocumentStatusHeaders + }, + 401: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetDocumentStatusHeaders + }, + 404: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetDocumentStatusHeaders + }, + 429: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetDocumentStatusHeaders + }, + 500: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetDocumentStatusHeaders + }, + 503: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetDocumentStatusHeaders + }, + default: {} + }, + serializer +}; + +const getOperationStatusOperationSpec: msRest.OperationSpec = { + httpMethod: "GET", + path: "v1.0-preview.1/batches/{id}", + urlParameters: [ + Parameters.endpoint, + Parameters.id + ], + responses: { + 200: { + bodyMapper: Mappers.BatchStatusDetail, + headersMapper: Mappers.TranslationGetOperationStatusHeaders + }, + 401: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetOperationStatusHeaders + }, + 404: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetOperationStatusHeaders + }, + 429: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetOperationStatusHeaders + }, + 500: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetOperationStatusHeaders + }, + 503: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetOperationStatusHeaders + }, + default: {} + }, + serializer +}; + +const cancelOperationOperationSpec: msRest.OperationSpec = { + httpMethod: "DELETE", + path: "v1.0-preview.1/batches/{id}", + urlParameters: [ + Parameters.endpoint, + Parameters.id + ], + responses: { + 200: { + bodyMapper: Mappers.BatchStatusDetail + }, + 401: { + bodyMapper: Mappers.ErrorResponseV2 + }, + 404: { + bodyMapper: Mappers.ErrorResponseV2 + }, + 429: { + bodyMapper: Mappers.ErrorResponseV2 + }, + 500: { + bodyMapper: Mappers.ErrorResponseV2 + }, + 503: { + bodyMapper: Mappers.ErrorResponseV2 + }, + default: {} + }, + serializer +}; + +const getOperationDocumentsStatusOperationSpec: msRest.OperationSpec = { + httpMethod: "GET", + path: "v1.0-preview.1/batches/{id}/documents", + urlParameters: [ + Parameters.endpoint, + Parameters.id + ], + queryParameters: [ + Parameters.top, + Parameters.skip + ], + responses: { + 200: { + bodyMapper: Mappers.DocumentStatusResponse, + headersMapper: Mappers.TranslationGetOperationDocumentsStatusHeaders + }, + 400: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetOperationDocumentsStatusHeaders + }, + 401: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetOperationDocumentsStatusHeaders + }, + 404: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetOperationDocumentsStatusHeaders + }, + 429: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetOperationDocumentsStatusHeaders + }, + 500: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetOperationDocumentsStatusHeaders + }, + 503: { + bodyMapper: Mappers.ErrorResponseV2, + headersMapper: Mappers.TranslationGetOperationDocumentsStatusHeaders + }, + default: {} + }, + serializer +}; + +const getDocumentFormatsOperationSpec: msRest.OperationSpec = { + httpMethod: "GET", + path: "v1.0-preview.1/documents/formats", + urlParameters: [ + Parameters.endpoint + ], + responses: { + 200: { + bodyMapper: Mappers.FileFormatListResult + }, + 429: { + bodyMapper: Mappers.ErrorResponseV2 + }, + 500: { + bodyMapper: Mappers.ErrorResponseV2 + }, + 503: { + bodyMapper: Mappers.ErrorResponseV2 + }, + default: {} + }, + serializer +}; + +const getGlossaryFormatsOperationSpec: msRest.OperationSpec = { + httpMethod: "GET", + path: "v1.0-preview.1/glossaries/formats", + urlParameters: [ + Parameters.endpoint + ], + responses: { + 200: { + bodyMapper: Mappers.FileFormatListResult + }, + 429: { + bodyMapper: Mappers.ErrorResponseV2 + }, + 500: { + bodyMapper: Mappers.ErrorResponseV2 + }, + 503: { + bodyMapper: Mappers.ErrorResponseV2 + }, + default: {} + }, + serializer +}; + +const getDocumentStorageSourceOperationSpec: msRest.OperationSpec = { + httpMethod: "GET", + path: "v1.0-preview.1/storagesources", + urlParameters: [ + Parameters.endpoint + ], + responses: { + 200: { + bodyMapper: Mappers.StorageSourceListResult + }, + 429: { + bodyMapper: Mappers.ErrorResponseV2 + }, + 500: { + bodyMapper: Mappers.ErrorResponseV2 + }, + 503: { + bodyMapper: Mappers.ErrorResponseV2 + }, + default: {} + }, + serializer +}; diff --git a/sdk/cognitiveservices/cognitiveservices-translation-batch/tsconfig.json b/sdk/cognitiveservices/cognitiveservices-translation-batch/tsconfig.json new file mode 100644 index 000000000000..422b584abd5e --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-translation-batch/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "es6", + "moduleResolution": "node", + "strict": true, + "target": "es5", + "sourceMap": true, + "declarationMap": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "lib": ["es6", "dom"], + "declaration": true, + "outDir": "./esm", + "importHelpers": true + }, + "include": ["./src/**/*.ts"], + "exclude": ["node_modules"] +}