diff --git a/eng/ignore-links.txt b/eng/ignore-links.txt index 819f5052a312..5c95d9162703 100644 --- a/eng/ignore-links.txt +++ b/eng/ignore-links.txt @@ -8,6 +8,7 @@ https://docs.microsoft.com/javascript/api/@azure/arm-computefleet?view=azure-nod https://github.com/Azure/azure-resource-manager-rpc/blob/master/v1.0/async-api-reference.md https://docs.microsoft.com/javascript/api/@azure/arm-computeschedule?view=azure-node-preview https://docs.microsoft.com/javascript/api/@azure/arm-healthdataaiservices?view=azure-node-preview +https://docs.microsoft.com/javascript/api/@azure/ai-document-translator https://docs.microsoft.com/javascript/api/@azure/arm-fabric?view=azure-node-preview https://docs.microsoft.com/javascript/api/@azure/arm-trustedsigning?view=azure-node-preview https://docs.microsoft.com/javascript/api/@azure/arm-containerorchestratorruntime?view=azure-node-preview diff --git a/sdk/documenttranslator/ai-document-translator-rest/CHANGELOG.md b/sdk/documenttranslator/ai-document-translator-rest/CHANGELOG.md index 561e625930b3..344f09204027 100644 --- a/sdk/documenttranslator/ai-document-translator-rest/CHANGELOG.md +++ b/sdk/documenttranslator/ai-document-translator-rest/CHANGELOG.md @@ -1,7 +1,9 @@ # Release History -## 1.0.0-beta.2 (Unreleased) +## 1.0.0-beta.2 (2024-12-16) +### Features Added +- refresh @azure-rest/ai-document-translator sdk ## 1.0.0-beta.1 (2021-04-22) diff --git a/sdk/documenttranslator/ai-document-translator-rest/eslint.config.mjs b/sdk/documenttranslator/ai-document-translator-rest/eslint.config.mjs new file mode 100644 index 000000000000..b57e15e8e044 --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/eslint.config.mjs @@ -0,0 +1,9 @@ +import azsdkEslint from "@azure/eslint-plugin-azure-sdk"; + +export default azsdkEslint.config([ + { + rules: { + "@azure/azure-sdk/ts-modules-only-named": "warn", + }, + }, +]); diff --git a/sdk/documenttranslator/ai-document-translator-rest/package.json b/sdk/documenttranslator/ai-document-translator-rest/package.json index a3005c879571..aeb94be99275 100644 --- a/sdk/documenttranslator/ai-document-translator-rest/package.json +++ b/sdk/documenttranslator/ai-document-translator-rest/package.json @@ -82,6 +82,9 @@ "sideEffects": false, "autoPublish": false, "dependencies": { + "@azure-tools/test-recorder": "^3.0.0", + "@azure/core-lro": "^3.0.0", + "@azure/abort-controller": "^2.1.2", "@azure-rest/core-client": "^2.3.1", "@azure/core-auth": "^1.9.0", "@azure/core-rest-pipeline": "^1.18.0", diff --git a/sdk/documenttranslator/ai-document-translator-rest/review/ai-document-translator.api.md b/sdk/documenttranslator/ai-document-translator-rest/review/ai-document-translator.api.md index d6e761ff1da9..116f22e87005 100644 --- a/sdk/documenttranslator/ai-document-translator-rest/review/ai-document-translator.api.md +++ b/sdk/documenttranslator/ai-document-translator-rest/review/ai-document-translator.api.md @@ -4,738 +4,823 @@ ```ts +import type { AbortSignalLike } from '@azure/abort-controller'; +import type { CancelOnProgress } from '@azure/core-lro'; import type { Client } from '@azure-rest/core-client'; import type { ClientOptions } from '@azure-rest/core-client'; +import type { CreateHttpPollerOptions } from '@azure/core-lro'; import type { HttpResponse } from '@azure-rest/core-client'; import type { KeyCredential } from '@azure/core-auth'; +import type { OperationState } from '@azure/core-lro'; +import type { PathUncheckedResponse } from '@azure-rest/core-client'; import type { RawHttpHeaders } from '@azure/core-rest-pipeline'; import type { RequestParameters } from '@azure-rest/core-client'; -import type { TokenCredential } from '@azure/core-auth'; +import type { StreamableMethod } from '@azure-rest/core-client'; -// @public (undocumented) +// @public export interface BatchRequest { source: SourceInput; - storageType?: StorageInputType; - targets: TargetInput[]; + storageType?: "Folder" | "File"; + targets: Array; } +// @public +function createClient(endpoint: string, credentials: KeyCredential, options?: DocumentTranslatorClientOptions): DocumentTranslatorClient; +export default createClient; + // @public (undocumented) -export interface CancelTranslation { - delete(options?: CancelTranslationParameters): Promise; - get(options?: GetTranslationStatusParameters): Promise; +export interface DocumentFilter { + prefix?: string; + suffix?: string; +} + +// @public +export interface DocumentsStatusOutput { + "@nextLink"?: string; + value: Array; +} + +// @public +export interface DocumentStatusOutput { + characterCharged?: number; + createdDateTimeUtc: string; + error?: TranslationErrorOutput; + id: string; + lastActionDateTimeUtc: string; + path?: string; + progress: number; + sourcePath: string; + status: "NotStarted" | "Running" | "Succeeded" | "Failed" | "Cancelled" | "Cancelling" | "ValidationFailed"; + to: string; } // @public -export interface CancelTranslation200Response extends HttpResponse { +export interface DocumentTranslationCancelTranslation200Response extends HttpResponse { // (undocumented) - body: TranslationStatus; + body: TranslationStatusOutput; // (undocumented) status: "200"; } // @public -export interface CancelTranslation401Response extends HttpResponse { +export interface DocumentTranslationCancelTranslation401Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "401"; } // @public -export interface CancelTranslation404Response extends HttpResponse { +export interface DocumentTranslationCancelTranslation404Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "404"; } // @public -export interface CancelTranslation429Response extends HttpResponse { +export interface DocumentTranslationCancelTranslation429Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "429"; } // @public -export interface CancelTranslation500Response extends HttpResponse { +export interface DocumentTranslationCancelTranslation500Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "500"; } // @public -export interface CancelTranslation503Response extends HttpResponse { +export interface DocumentTranslationCancelTranslation503Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "503"; } // @public (undocumented) -export type CancelTranslationParameters = RequestParameters; +export type DocumentTranslationCancelTranslationParameters = RequestParameters; // @public (undocumented) -export interface DocumentFilter { - prefix?: string; - suffix?: string; -} - -// @public (undocumented) -export interface DocumentsStatus { - nextLink?: string; - value: DocumentStatus[]; -} - -// @public (undocumented) -export interface DocumentStatus { - characterCharged?: number; - createdDateTimeUtc: Date; - error?: TranslationError; - id: string; - lastActionDateTimeUtc: Date; - path?: string; - progress: number; - sourcePath: string; - status: Status; - to: string; -} - -// @public (undocumented) -function DocumentTranslator(endpoint: string, credentials: TokenCredential | KeyCredential, options?: ClientOptions): DocumentTranslatorClient; -export default DocumentTranslator; - -// @public (undocumented) -export type DocumentTranslatorClient = Client & { - path: Routes; -}; - -// @public (undocumented) -export interface DocumentTranslatorFactory { - // (undocumented) - (endpoint: string, credentials: TokenCredential | KeyCredential, options?: ClientOptions): void; -} - -// @public (undocumented) -export interface FileFormat { - contentTypes: string[]; - defaultVersion?: string; - fileExtensions: string[]; - format: string; - versions?: string[]; -} - -// @public (undocumented) -export interface GetDocumentsStatus { - get(options?: GetDocumentsStatusParameters): Promise; -} - -// @public (undocumented) -export interface GetDocumentsStatus200Headers { - "retry-after"?: string; +export interface DocumentTranslationGetDocumentsStatus200Headers { + "retry-after"?: number; etag?: string; } // @public -export interface GetDocumentsStatus200Response extends HttpResponse { +export interface DocumentTranslationGetDocumentsStatus200Response extends HttpResponse { // (undocumented) - body: DocumentsStatus; + body: DocumentsStatusOutput; // (undocumented) - headers: RawHttpHeaders & GetDocumentsStatus200Headers; + headers: RawHttpHeaders & DocumentTranslationGetDocumentsStatus200Headers; // (undocumented) status: "200"; } // @public -export interface GetDocumentsStatus400Response extends HttpResponse { +export interface DocumentTranslationGetDocumentsStatus400Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "400"; } // @public -export interface GetDocumentsStatus401Response extends HttpResponse { +export interface DocumentTranslationGetDocumentsStatus401Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "401"; } // @public -export interface GetDocumentsStatus404Response extends HttpResponse { +export interface DocumentTranslationGetDocumentsStatus404Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "404"; } // @public -export interface GetDocumentsStatus429Response extends HttpResponse { +export interface DocumentTranslationGetDocumentsStatus429Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "429"; } // @public -export interface GetDocumentsStatus500Response extends HttpResponse { +export interface DocumentTranslationGetDocumentsStatus500Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "500"; } // @public -export interface GetDocumentsStatus503Response extends HttpResponse { +export interface DocumentTranslationGetDocumentsStatus503Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "503"; } // @public (undocumented) -export type GetDocumentsStatusParameters = RequestParameters & GetDocumentsStatusQueryParam; +export type DocumentTranslationGetDocumentsStatusParameters = DocumentTranslationGetDocumentsStatusQueryParam & RequestParameters; // @public (undocumented) -export interface GetDocumentsStatusQueryParam { +export interface DocumentTranslationGetDocumentsStatusQueryParam { // (undocumented) - queryParameters?: GetDocumentsStatusQueryParamProperties; + queryParameters?: DocumentTranslationGetDocumentsStatusQueryParamProperties; } // @public (undocumented) -export interface GetDocumentsStatusQueryParamProperties { +export interface DocumentTranslationGetDocumentsStatusQueryParamProperties { $maxpagesize?: number; - $orderBy?: string[]; + $orderBy?: Array; $skip?: number; $top?: number; - createdDateTimeUtcEnd?: Date; - createdDateTimeUtcStart?: Date; - ids?: string[]; - statuses?: string[]; + createdDateTimeUtcEnd?: Date | string; + createdDateTimeUtcStart?: Date | string; + ids?: Array; + statuses?: Array; } // @public (undocumented) -export interface GetDocumentStatus { - get(options?: GetDocumentStatusParameters): Promise; -} - -// @public (undocumented) -export interface GetDocumentStatus200Headers { - "retry-after"?: string; +export interface DocumentTranslationGetDocumentStatus200Headers { + "retry-after"?: number; etag?: string; } // @public -export interface GetDocumentStatus200Response extends HttpResponse { +export interface DocumentTranslationGetDocumentStatus200Response extends HttpResponse { // (undocumented) - body: DocumentStatus; + body: DocumentStatusOutput; // (undocumented) - headers: RawHttpHeaders & GetDocumentStatus200Headers; + headers: RawHttpHeaders & DocumentTranslationGetDocumentStatus200Headers; // (undocumented) status: "200"; } // @public -export interface GetDocumentStatus401Response extends HttpResponse { +export interface DocumentTranslationGetDocumentStatus401Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "401"; } // @public -export interface GetDocumentStatus404Response extends HttpResponse { +export interface DocumentTranslationGetDocumentStatus404Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "404"; } // @public -export interface GetDocumentStatus429Response extends HttpResponse { +export interface DocumentTranslationGetDocumentStatus429Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "429"; } // @public -export interface GetDocumentStatus500Response extends HttpResponse { +export interface DocumentTranslationGetDocumentStatus500Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "500"; } // @public -export interface GetDocumentStatus503Response extends HttpResponse { +export interface DocumentTranslationGetDocumentStatus503Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "503"; } // @public (undocumented) -export type GetDocumentStatusParameters = RequestParameters; - -// @public (undocumented) -export interface GetSupportedDocumentFormats { - get(options?: GetSupportedDocumentFormatsParameters): Promise; -} +export type DocumentTranslationGetDocumentStatusParameters = RequestParameters; // @public (undocumented) -export interface GetSupportedDocumentFormats200Headers { - "retry-after"?: string; +export interface DocumentTranslationGetSupportedDocumentFormats200Headers { + "retry-after"?: number; } // @public -export interface GetSupportedDocumentFormats200Response extends HttpResponse { +export interface DocumentTranslationGetSupportedDocumentFormats200Response extends HttpResponse { // (undocumented) - body: SupportedFileFormats; + body: SupportedFileFormatsOutput; // (undocumented) - headers: RawHttpHeaders & GetSupportedDocumentFormats200Headers; + headers: RawHttpHeaders & DocumentTranslationGetSupportedDocumentFormats200Headers; // (undocumented) status: "200"; } // @public -export interface GetSupportedDocumentFormats429Response extends HttpResponse { +export interface DocumentTranslationGetSupportedDocumentFormats429Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "429"; } // @public -export interface GetSupportedDocumentFormats500Response extends HttpResponse { +export interface DocumentTranslationGetSupportedDocumentFormats500Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "500"; } // @public -export interface GetSupportedDocumentFormats503Response extends HttpResponse { +export interface DocumentTranslationGetSupportedDocumentFormats503Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "503"; } // @public (undocumented) -export type GetSupportedDocumentFormatsParameters = RequestParameters; +export type DocumentTranslationGetSupportedDocumentFormatsParameters = RequestParameters; // @public (undocumented) -export interface GetSupportedGlossaryFormats { - get(options?: GetSupportedGlossaryFormatsParameters): Promise; -} - -// @public (undocumented) -export interface GetSupportedGlossaryFormats200Headers { - "retry-after"?: string; +export interface DocumentTranslationGetSupportedGlossaryFormats200Headers { + "retry-after"?: number; } // @public -export interface GetSupportedGlossaryFormats200Response extends HttpResponse { +export interface DocumentTranslationGetSupportedGlossaryFormats200Response extends HttpResponse { // (undocumented) - body: SupportedFileFormats; + body: SupportedFileFormatsOutput; // (undocumented) - headers: RawHttpHeaders & GetSupportedGlossaryFormats200Headers; + headers: RawHttpHeaders & DocumentTranslationGetSupportedGlossaryFormats200Headers; // (undocumented) status: "200"; } // @public -export interface GetSupportedGlossaryFormats429Response extends HttpResponse { +export interface DocumentTranslationGetSupportedGlossaryFormats429Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "429"; } // @public -export interface GetSupportedGlossaryFormats500Response extends HttpResponse { +export interface DocumentTranslationGetSupportedGlossaryFormats500Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "500"; } // @public -export interface GetSupportedGlossaryFormats503Response extends HttpResponse { +export interface DocumentTranslationGetSupportedGlossaryFormats503Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "503"; } // @public (undocumented) -export type GetSupportedGlossaryFormatsParameters = RequestParameters; +export type DocumentTranslationGetSupportedGlossaryFormatsParameters = RequestParameters; // @public (undocumented) -export interface GetSupportedStorageSources { - get(options?: GetSupportedStorageSourcesParameters): Promise; -} - -// @public (undocumented) -export interface GetSupportedStorageSources200Headers { - "retry-after"?: string; +export interface DocumentTranslationGetSupportedStorageSources200Headers { + "retry-after"?: number; } // @public -export interface GetSupportedStorageSources200Response extends HttpResponse { +export interface DocumentTranslationGetSupportedStorageSources200Response extends HttpResponse { // (undocumented) - body: SupportedStorageSources; + body: SupportedStorageSourcesOutput; // (undocumented) - headers: RawHttpHeaders & GetSupportedStorageSources200Headers; + headers: RawHttpHeaders & DocumentTranslationGetSupportedStorageSources200Headers; // (undocumented) status: "200"; } // @public -export interface GetSupportedStorageSources429Response extends HttpResponse { +export interface DocumentTranslationGetSupportedStorageSources429Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "429"; } // @public -export interface GetSupportedStorageSources500Response extends HttpResponse { +export interface DocumentTranslationGetSupportedStorageSources500Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "500"; } // @public -export interface GetSupportedStorageSources503Response extends HttpResponse { +export interface DocumentTranslationGetSupportedStorageSources503Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "503"; } // @public (undocumented) -export type GetSupportedStorageSourcesParameters = RequestParameters; +export type DocumentTranslationGetSupportedStorageSourcesParameters = RequestParameters; // @public (undocumented) -export interface GetTranslationsStatus { - get(options?: GetTranslationsStatusParameters): Promise; - post(options: StartTranslationParameters): Promise; -} - -// @public (undocumented) -export interface GetTranslationsStatus200Headers { - "retry-after"?: string; +export interface DocumentTranslationGetTranslationsStatus200Headers { + "retry-after"?: number; etag?: string; } // @public -export interface GetTranslationsStatus200Response extends HttpResponse { +export interface DocumentTranslationGetTranslationsStatus200Response extends HttpResponse { // (undocumented) - body: TranslationsStatus; + body: TranslationsStatusOutput; // (undocumented) - headers: RawHttpHeaders & GetTranslationsStatus200Headers; + headers: RawHttpHeaders & DocumentTranslationGetTranslationsStatus200Headers; // (undocumented) status: "200"; } // @public -export interface GetTranslationsStatus400Response extends HttpResponse { +export interface DocumentTranslationGetTranslationsStatus400Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "400"; } // @public -export interface GetTranslationsStatus401Response extends HttpResponse { +export interface DocumentTranslationGetTranslationsStatus401Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "401"; } // @public -export interface GetTranslationsStatus429Response extends HttpResponse { +export interface DocumentTranslationGetTranslationsStatus429Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "429"; } // @public -export interface GetTranslationsStatus500Response extends HttpResponse { +export interface DocumentTranslationGetTranslationsStatus500Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "500"; } // @public -export interface GetTranslationsStatus503Response extends HttpResponse { +export interface DocumentTranslationGetTranslationsStatus503Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "503"; } // @public (undocumented) -export type GetTranslationsStatusParameters = RequestParameters & GetTranslationsStatusQueryParam; +export type DocumentTranslationGetTranslationsStatusParameters = DocumentTranslationGetTranslationsStatusQueryParam & RequestParameters; // @public (undocumented) -export interface GetTranslationsStatusQueryParam { +export interface DocumentTranslationGetTranslationsStatusQueryParam { // (undocumented) - queryParameters?: GetTranslationsStatusQueryParamProperties; + queryParameters?: DocumentTranslationGetTranslationsStatusQueryParamProperties; } // @public (undocumented) -export interface GetTranslationsStatusQueryParamProperties { +export interface DocumentTranslationGetTranslationsStatusQueryParamProperties { $maxpagesize?: number; - $orderBy?: string[]; + $orderBy?: Array; $skip?: number; $top?: number; - createdDateTimeUtcEnd?: Date; - createdDateTimeUtcStart?: Date; - ids?: string[]; - statuses?: string[]; + createdDateTimeUtcEnd?: Date | string; + createdDateTimeUtcStart?: Date | string; + ids?: Array; + statuses?: Array; } // @public (undocumented) -export interface GetTranslationStatus200Headers { - "retry-after"?: string; +export interface DocumentTranslationGetTranslationStatus200Headers { + "retry-after"?: number; etag?: string; } // @public -export interface GetTranslationStatus200Response extends HttpResponse { +export interface DocumentTranslationGetTranslationStatus200Response extends HttpResponse { // (undocumented) - body: TranslationStatus; + body: TranslationStatusOutput; // (undocumented) - headers: RawHttpHeaders & GetTranslationStatus200Headers; + headers: RawHttpHeaders & DocumentTranslationGetTranslationStatus200Headers; // (undocumented) status: "200"; } // @public -export interface GetTranslationStatus401Response extends HttpResponse { +export interface DocumentTranslationGetTranslationStatus401Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "401"; } // @public -export interface GetTranslationStatus404Response extends HttpResponse { +export interface DocumentTranslationGetTranslationStatus404Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "404"; } // @public -export interface GetTranslationStatus429Response extends HttpResponse { +export interface DocumentTranslationGetTranslationStatus429Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "429"; } // @public -export interface GetTranslationStatus500Response extends HttpResponse { +export interface DocumentTranslationGetTranslationStatus500Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "500"; } // @public -export interface GetTranslationStatus503Response extends HttpResponse { +export interface DocumentTranslationGetTranslationStatus503Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "503"; } // @public (undocumented) -export type GetTranslationStatusParameters = RequestParameters; - -// @public (undocumented) -export interface Glossary { - format: string; - glossaryUrl: string; - storageSource?: StorageSource; - version?: string; -} - -// @public (undocumented) -export interface InnerTranslationError { - code: string; - innerError?: InnerTranslationError; - message: string; - target?: string; -} - -// @public (undocumented) -export interface Routes { - (path: "/batches"): GetTranslationsStatus; - (path: "/batches/{id}/documents/{documentId}", id: string, documentId: string): GetDocumentStatus; - (path: "/batches/{id}", id: string): CancelTranslation; - (path: "/batches/{id}/documents", id: string): GetDocumentsStatus; - (path: "/documents/formats"): GetSupportedDocumentFormats; - (path: "/glossaries/formats"): GetSupportedGlossaryFormats; - (path: "/storagesources"): GetSupportedStorageSources; -} +export type DocumentTranslationGetTranslationStatusParameters = RequestParameters; // @public (undocumented) -export interface SourceInput { - // (undocumented) - filter?: DocumentFilter; - language?: string; - sourceUrl: string; - storageSource?: StorageSource; -} - -// @public (undocumented) -export interface StartTranslation202Headers { +export interface DocumentTranslationStartTranslation202Headers { "operation-location"?: string; } // @public -export interface StartTranslation202Response extends HttpResponse { +export interface DocumentTranslationStartTranslation202Response extends HttpResponse { // (undocumented) - headers: RawHttpHeaders & StartTranslation202Headers; + headers: RawHttpHeaders & DocumentTranslationStartTranslation202Headers; // (undocumented) status: "202"; } // @public -export interface StartTranslation400Response extends HttpResponse { +export interface DocumentTranslationStartTranslation400Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "400"; } // @public -export interface StartTranslation401Response extends HttpResponse { +export interface DocumentTranslationStartTranslation401Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "401"; } // @public -export interface StartTranslation429Response extends HttpResponse { +export interface DocumentTranslationStartTranslation429Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "429"; } // @public -export interface StartTranslation500Response extends HttpResponse { +export interface DocumentTranslationStartTranslation500Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "500"; } // @public -export interface StartTranslation503Response extends HttpResponse { +export interface DocumentTranslationStartTranslation503Response extends HttpResponse { // (undocumented) - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; // (undocumented) status: "503"; } // @public (undocumented) -export interface StartTranslationBodyParam { - // (undocumented) +export interface DocumentTranslationStartTranslationBodyParam { body: StartTranslationDetails; } // @public (undocumented) -export interface StartTranslationDetails { - inputs: BatchRequest[]; +export interface DocumentTranslationStartTranslationMediaTypesParam { + contentType?: "application/json" | "text/json" | "application/*+json"; } // @public (undocumented) -export type StartTranslationParameters = RequestParameters & StartTranslationBodyParam; +export type DocumentTranslationStartTranslationParameters = DocumentTranslationStartTranslationMediaTypesParam & DocumentTranslationStartTranslationBodyParam & RequestParameters; // @public (undocumented) -export type Status = "NotStarted" | "Running" | "Succeeded" | "Failed" | "Cancelled" | "Cancelling" | "ValidationFailed"; +export type DocumentTranslatorClient = Client & { + path: Routes; +}; + +// @public +export interface DocumentTranslatorClientOptions extends ClientOptions { +} // @public (undocumented) -export interface StatusSummary { - cancelled: number; - failed: number; - inProgress: number; - notYetStarted: number; - success: number; - total: number; - totalCharacterCharged: number; +export interface FileFormatOutput { + contentTypes: Array; + defaultVersion?: string; + fileExtensions: Array; + format: string; + versions?: Array; } +// @public +export type GetArrayType = T extends Array ? TData : never; + // @public (undocumented) -export type StorageInputType = "Folder" | "File"; +export interface GetDocumentsStatus { + get(options?: DocumentTranslationGetDocumentsStatusParameters): StreamableMethod; +} // @public (undocumented) -export type StorageSource = "AzureBlob"; +export interface GetDocumentStatus { + get(options?: DocumentTranslationGetDocumentStatusParameters): StreamableMethod; +} + +// @public +export function getLongRunningPoller(client: Client, initialResponse: TResult, options?: CreateHttpPollerOptions>): Promise, TResult>>; + +// @public +export type GetPage = (pageLink: string) => Promise<{ + page: TPage; + nextPageLink?: string; +}>; // @public (undocumented) -export interface SupportedFileFormats { - value: FileFormat[]; +export interface GetSupportedDocumentFormats { + get(options?: DocumentTranslationGetSupportedDocumentFormatsParameters): StreamableMethod; } // @public (undocumented) -export interface SupportedStorageSources { - value: "AzureBlob"[]; +export interface GetSupportedGlossaryFormats { + get(options?: DocumentTranslationGetSupportedGlossaryFormatsParameters): StreamableMethod; } // @public (undocumented) -export interface TargetInput { - category?: string; - glossaries?: Glossary[]; - language: string; - storageSource?: StorageSource; - targetUrl: string; +export interface GetSupportedStorageSources { + get(options?: DocumentTranslationGetSupportedStorageSourcesParameters): StreamableMethod; } // @public (undocumented) -export interface TranslationError { - code: TranslationErrorCode; - innerError?: InnerTranslationError; +export interface GetTranslationStatus { + delete(options?: DocumentTranslationCancelTranslationParameters): StreamableMethod; + get(options?: DocumentTranslationGetTranslationStatusParameters): StreamableMethod; +} + +// @public +export interface Glossary { + format: string; + glossaryUrl: string; + storageSource?: "AzureBlob"; + version?: string; +} + +// @public +export interface InnerTranslationErrorOutput { + code: string; + innerError?: InnerTranslationErrorOutput; message: string; - target?: string; + readonly target?: string; } // @public (undocumented) -export type TranslationErrorCode = "InvalidRequest" | "InvalidArgument" | "InternalServerError" | "ServiceUnavailable" | "ResourceNotFound" | "Unauthorized" | "RequestRateTooHigh"; +export function isUnexpected(response: DocumentTranslationStartTranslation202Response | DocumentTranslationStartTranslation400Response | DocumentTranslationStartTranslation401Response | DocumentTranslationStartTranslation429Response | DocumentTranslationStartTranslation500Response | DocumentTranslationStartTranslation503Response): response is DocumentTranslationStartTranslation400Response; + +// @public (undocumented) +export function isUnexpected(response: DocumentTranslationGetTranslationsStatus200Response | DocumentTranslationGetTranslationsStatus400Response | DocumentTranslationGetTranslationsStatus401Response | DocumentTranslationGetTranslationsStatus429Response | DocumentTranslationGetTranslationsStatus500Response | DocumentTranslationGetTranslationsStatus503Response): response is DocumentTranslationGetTranslationsStatus400Response; + +// @public (undocumented) +export function isUnexpected(response: DocumentTranslationGetDocumentStatus200Response | DocumentTranslationGetDocumentStatus401Response | DocumentTranslationGetDocumentStatus404Response | DocumentTranslationGetDocumentStatus429Response | DocumentTranslationGetDocumentStatus500Response | DocumentTranslationGetDocumentStatus503Response): response is DocumentTranslationGetDocumentStatus401Response; + +// @public (undocumented) +export function isUnexpected(response: DocumentTranslationGetTranslationStatus200Response | DocumentTranslationGetTranslationStatus401Response | DocumentTranslationGetTranslationStatus404Response | DocumentTranslationGetTranslationStatus429Response | DocumentTranslationGetTranslationStatus500Response | DocumentTranslationGetTranslationStatus503Response): response is DocumentTranslationGetTranslationStatus401Response; + +// @public (undocumented) +export function isUnexpected(response: DocumentTranslationCancelTranslation200Response | DocumentTranslationCancelTranslation401Response | DocumentTranslationCancelTranslation404Response | DocumentTranslationCancelTranslation429Response | DocumentTranslationCancelTranslation500Response | DocumentTranslationCancelTranslation503Response): response is DocumentTranslationCancelTranslation401Response; + +// @public (undocumented) +export function isUnexpected(response: DocumentTranslationGetDocumentsStatus200Response | DocumentTranslationGetDocumentsStatus400Response | DocumentTranslationGetDocumentsStatus401Response | DocumentTranslationGetDocumentsStatus404Response | DocumentTranslationGetDocumentsStatus429Response | DocumentTranslationGetDocumentsStatus500Response | DocumentTranslationGetDocumentsStatus503Response): response is DocumentTranslationGetDocumentsStatus400Response; + +// @public (undocumented) +export function isUnexpected(response: DocumentTranslationGetSupportedDocumentFormats200Response | DocumentTranslationGetSupportedDocumentFormats429Response | DocumentTranslationGetSupportedDocumentFormats500Response | DocumentTranslationGetSupportedDocumentFormats503Response): response is DocumentTranslationGetSupportedDocumentFormats429Response; // @public (undocumented) -export interface TranslationErrorResponse { - error?: TranslationError; +export function isUnexpected(response: DocumentTranslationGetSupportedGlossaryFormats200Response | DocumentTranslationGetSupportedGlossaryFormats429Response | DocumentTranslationGetSupportedGlossaryFormats500Response | DocumentTranslationGetSupportedGlossaryFormats503Response): response is DocumentTranslationGetSupportedGlossaryFormats429Response; + +// @public (undocumented) +export function isUnexpected(response: DocumentTranslationGetSupportedStorageSources200Response | DocumentTranslationGetSupportedStorageSources429Response | DocumentTranslationGetSupportedStorageSources500Response | DocumentTranslationGetSupportedStorageSources503Response): response is DocumentTranslationGetSupportedStorageSources429Response; + +// @public +export interface PagedAsyncIterableIterator { + [Symbol.asyncIterator](): PagedAsyncIterableIterator; + byPage: (settings?: TPageSettings) => AsyncIterableIterator; + next(): Promise>; +} + +// @public +export interface PageSettings { + continuationToken?: string; +} + +// @public +export function paginate(client: Client, initialResponse: TResponse, options?: PagingOptions): PagedAsyncIterableIterator>; + +// @public +export type PaginateReturn = TResult extends { + body: { + value?: infer TPage; + }; +} ? GetArrayType : Array; + +// @public +export interface PagingOptions { + customGetPage?: GetPage[]>; } // @public (undocumented) -export interface TranslationsStatus { - nextLink?: string; - value: TranslationStatus[]; +export interface Routes { + (path: "/batches"): StartTranslation; + (path: "/batches/{id}/documents/{documentId}", id: string, documentId: string): GetDocumentStatus; + (path: "/batches/{id}", id: string): GetTranslationStatus; + (path: "/batches/{id}/documents", id: string): GetDocumentsStatus; + (path: "/documents/formats"): GetSupportedDocumentFormats; + (path: "/glossaries/formats"): GetSupportedGlossaryFormats; + (path: "/storagesources"): GetSupportedStorageSources; +} + +// @public +export interface SimplePollerLike, TResult> { + getOperationState(): TState; + getResult(): TResult | undefined; + isDone(): boolean; + // @deprecated + isStopped(): boolean; + onProgress(callback: (state: TState) => void): CancelOnProgress; + poll(options?: { + abortSignal?: AbortSignalLike; + }): Promise; + pollUntilDone(pollOptions?: { + abortSignal?: AbortSignalLike; + }): Promise; + serialize(): Promise; + // @deprecated + stopPolling(): void; + submitted(): Promise; + // @deprecated + toString(): string; +} + +// @public +export interface SourceInput { + // (undocumented) + filter?: DocumentFilter; + language?: string; + sourceUrl: string; + storageSource?: "AzureBlob"; +} + +// @public (undocumented) +export interface StartTranslation { + get(options?: DocumentTranslationGetTranslationsStatusParameters): StreamableMethod; + post(options: DocumentTranslationStartTranslationParameters): StreamableMethod; +} + +// @public +export interface StartTranslationDetails { + inputs: Array; } // @public (undocumented) -export interface TranslationStatus { - createdDateTimeUtc: Date; - error?: TranslationError; +export interface StatusSummaryOutput { + cancelled: number; + failed: number; + inProgress: number; + notYetStarted: number; + success: number; + total: number; + totalCharacterCharged: number; +} + +// @public +export interface SupportedFileFormatsOutput { + value: Array; +} + +// @public +export interface SupportedStorageSourcesOutput { + value: Array<"AzureBlob">; +} + +// @public +export interface TargetInput { + category?: string; + glossaries?: Array; + language: string; + storageSource?: "AzureBlob"; + targetUrl: string; +} + +// @public +export interface TranslationErrorOutput { + code: "InvalidRequest" | "InvalidArgument" | "InternalServerError" | "ServiceUnavailable" | "ResourceNotFound" | "Unauthorized" | "RequestRateTooHigh"; + innerError?: InnerTranslationErrorOutput; + message: string; + readonly target?: string; +} + +// @public +export interface TranslationErrorResponseOutput { + error?: TranslationErrorOutput; +} + +// @public +export interface TranslationsStatusOutput { + "@nextLink"?: string; + value: Array; +} + +// @public +export interface TranslationStatusOutput { + createdDateTimeUtc: string; + error?: TranslationErrorOutput; id: string; - lastActionDateTimeUtc: Date; - status: Status; + lastActionDateTimeUtc: string; + status: "NotStarted" | "Running" | "Succeeded" | "Failed" | "Cancelled" | "Cancelling" | "ValidationFailed"; // (undocumented) - summary: StatusSummary; + summary: StatusSummaryOutput; } +// (No @packageDocumentation comment for this package) + ``` diff --git a/sdk/documenttranslator/ai-document-translator-rest/samples-dev/translateFromBlob.ts b/sdk/documenttranslator/ai-document-translator-rest/samples-dev/translateFromBlob.ts index 0200353fa815..6b48ce697a17 100644 --- a/sdk/documenttranslator/ai-document-translator-rest/samples-dev/translateFromBlob.ts +++ b/sdk/documenttranslator/ai-document-translator-rest/samples-dev/translateFromBlob.ts @@ -89,7 +89,7 @@ export async function main(): Promise { // The checkStatus operation returns a retry-after header that contains the // time in seconds to wait before sending the next polling request - const parsedRetryAfter = Number.parseInt(operationState.headers["retry-after"] || "5"); + const parsedRetryAfter = Number.parseInt(String(operationState.headers["retry-after"]) || "5"); const waitTime = Number.isInteger(parsedRetryAfter) ? parsedRetryAfter : 5; await wait(waitTime); } while (!terminalStates.includes(operationState.body.status)); diff --git a/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/javascript/README.md b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/javascript/README.md new file mode 100644 index 000000000000..5da66423ea68 --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/javascript/README.md @@ -0,0 +1,66 @@ +--- +page_type: sample +languages: + - javascript +products: + - azure + - azure-cognitive-services + - azure-translator +urlFragment: ai-document-translator-javascript-beta +--- + +# Azure Document Translator rest client library samples for JavaScript (Beta) + +These sample programs show how to use the JavaScript client libraries for Azure Document Translator rest in some common scenarios. + +| **File Name** | **Description** | +| ----------------------------------------- | --------------------------------------------- | +| [listFormats.js][listformats] | gets a list of all supported document formats | +| [translateFromBlob.js][translatefromblob] | translates a collection of documents | + +## Prerequisites + +The sample programs are compatible with [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule). + +You need [an Azure subscription][freesub] and the following Azure resources to run these sample programs: + +- [Azure Cognitive Services instance][createinstance_azurecognitiveservicesinstance] + +Samples retrieve credentials to access the service endpoint from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function. + +Adapting the samples to run in the browser may require some additional consideration. For details, please see the [package README][package]. + +## Setup + +To run the samples using the published version of the package: + +1. Install the dependencies using `npm`: + +```bash +npm install +``` + +2. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically. + +3. Run whichever samples you like (note that some samples may require additional setup, see the table above): + +```bash +node listFormats.js +``` + +Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform): + +```bash +npx cross-env ENDPOINT="" DOCUMENT_TRANSLATOR_API_KEY="" node listFormats.js +``` + +## Next Steps + +Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. + +[listformats]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/javascript/listFormats.js +[translatefromblob]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/javascript/translateFromBlob.js +[apiref]: https://docs.microsoft.com/javascript/api/@azure/ai-document-translator +[freesub]: https://azure.microsoft.com/free/ +[createinstance_azurecognitiveservicesinstance]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account +[package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/documenttranslator/ai-document-translator-rest/README.md diff --git a/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/javascript/listFormats.js b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/javascript/listFormats.js new file mode 100644 index 000000000000..7810fbd1e5b7 --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/javascript/listFormats.js @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * This sample demonstrates how to make a simple call to the Azure Document Translator + * service to get a list of supported file formats + * + * @summary gets a list of all supported document formats + */ + +const DocumentTranslator = require("@azure-rest/ai-document-translator").default; + +require("dotenv").config(); + +const endpoint = process.env["ENDPOINT"] || "document-translator endpoint"; +const apiKey = process.env["DOCUMENT_TRANSLATOR_API_KEY"] || ""; + +async function main() { + console.log("== List supported document formats sample =="); + + const client = DocumentTranslator(endpoint, { key: apiKey }); + const formats = await client.path("/documents/formats").get(); + + if (formats.status !== "200") { + throw formats.body.error; + } + + console.log(formats.body.value.map((v) => v.format).join("\n")); +} + +main().catch((err) => { + console.error(err); +}); + +module.exports = { main }; diff --git a/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/javascript/package.json b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/javascript/package.json new file mode 100644 index 000000000000..88a5332b69f1 --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/javascript/package.json @@ -0,0 +1,32 @@ +{ + "name": "@azure-samples/ai-document-translator-js-beta", + "private": true, + "version": "1.0.0", + "description": "Azure Document Translator rest client library samples for JavaScript (Beta)", + "engines": { + "node": ">=18.0.0" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Azure/azure-sdk-for-js.git", + "directory": "sdk/documenttranslator/ai-document-translator-rest" + }, + "keywords": [ + "node", + "azure", + "cloud", + "typescript", + "browser", + "isomorphic" + ], + "author": "Microsoft Corporation", + "license": "MIT", + "bugs": { + "url": "https://github.com/Azure/azure-sdk-for-js/issues" + }, + "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/documenttranslator/ai-document-translator-rest", + "dependencies": { + "@azure-rest/ai-document-translator": "next", + "dotenv": "latest" + } +} diff --git a/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/javascript/sample.env b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/javascript/sample.env new file mode 100644 index 000000000000..700e9d42eebd --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/javascript/sample.env @@ -0,0 +1,7 @@ +# API key to authenticate service calls +DOCUMENT_TRANSLATOR_API_KEY= +# Document translation service endpoint +ENDPOINT= +# URLs to the Source and Target Azure Storage Blob containers +SOURCE_CONTAINER= +TARGET_CONTAINER= diff --git a/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/javascript/translateFromBlob.js b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/javascript/translateFromBlob.js new file mode 100644 index 000000000000..e7a0d7173352 --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/javascript/translateFromBlob.js @@ -0,0 +1,124 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * This sample demonstrates how translate a colletion of documents stored in a Azure Storage Blob container + * and output the translated documents to another container. + * + * Translating documents is considered a Long Running Operation because it may take a long time to complete, + * specially if translating large files or a batch with several files. + * + * To handle these long running operations we need to call a few different endpoints, to track the status of the operation + * + * @summary translates a collection of documents + */ + +const DocumentTranslator = require("@azure-rest/ai-document-translator").default; + +require("dotenv").config(); + +/** + * These are states of the Long Running Operation considered as terminal + * that means that the operation has finished + */ +const terminalStates = ["Succeeded", "Failed", "Cancelled", "ValidationFailed"]; + +// Document Translation service endpoint +const endpoint = process.env["ENDPOINT"] || "document-translator endpoint"; +// Api key to authenticate the requests +const apiKey = process.env["DOCUMENT_TRANSLATOR_API_KEY"] || ""; +/** + * Azure Storage Blob containers, sourceContainer has the documents to be translated + * and targetContainer is the container where the translated documents will be output + */ +const sourceContainer = process.env["SOURCE_CONTAINER"] || ""; +const targetContainer = process.env["TARGET_CONTAINER"] || ""; + +/** + * This is the body that we need to send to the /batch endpoint + * to start a translation job on all the documents in sourceContainer + */ +const batchSubmissionRequest = { + inputs: [ + { + source: { sourceUrl: sourceContainer }, + targets: [{ language: "fr", targetUrl: targetContainer }], + }, + ], +}; + +async function main() { + console.log("== Translate documents in a container sample =="); + + // Create a new client + const client = DocumentTranslator(endpoint, { key: apiKey }); + + // Call the /batches path to initiate the translation job + const formats = await client.path("/batches").post({ + body: batchSubmissionRequest, + }); + + // If we get a non-success status code, throw an error + if (formats.status !== "202") { + throw formats.body.error; + } + + // The initial response contains an operation-location header which indicates + // the url in which we can poll for the status of the operation + // this URL is in a format in which the last part of the url is the operationId + // we can extract that ID and use it to call "/batches/{id}" + const batchId = extractBatchId(formats.headers["operation-location"]); + + /** + * We need to keep polling for the operation state until we find a terminal state + * once we reached the terminal state we can proceed and access the translated documents + * or throw an error in case something failed + */ + // Setting up the batch status path to reuse it in the loop + const checkStatus = client.path("/batches/{id}", batchId); + let operationState; + do { + // We just call get on checkStatus and store the current state + operationState = await checkStatus.get(); + + // If we get a non-success status code, throw the error + if (operationState.status !== "200") { + throw operationState.body.error; + } + + // The checkStatus operation returns a retry-after header that contains the + // time in seconds to wait before sending the next polling request + const parsedRetryAfter = Number.parseInt(String(operationState.headers["retry-after"]) || "5"); + const waitTime = Number.isInteger(parsedRetryAfter) ? parsedRetryAfter : 5; + await wait(waitTime); + } while (!terminalStates.includes(operationState.body.status)); + + // Now that the operation is complete, we can list the translated documents + const documents = await client.path("/batches/{id}/documents", batchId).get(); + + if (documents.status !== "200") { + throw documents.body.error; + } + + console.log(documents.body.value.map((doc) => doc.path).join("\n")); +} + +// Helper function to wait/sleep for N seconds +function wait(seconds) { + return new Promise((resolve) => { + setTimeout(resolve, seconds * 1000); + }); +} + +// Helper function that extracts the batch id from operation-location header +function extractBatchId(batchUrl = "") { + const parts = batchUrl.split("/"); + + return parts[parts.length - 1]; +} + +main().catch((err) => { + console.error(err); +}); + +module.exports = { main }; diff --git a/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/README.md b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/README.md new file mode 100644 index 000000000000..af55007fb3d6 --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/README.md @@ -0,0 +1,79 @@ +--- +page_type: sample +languages: + - typescript +products: + - azure + - azure-cognitive-services + - azure-translator +urlFragment: ai-document-translator-typescript-beta +--- + +# Azure Document Translator rest client library samples for TypeScript (Beta) + +These sample programs show how to use the TypeScript client libraries for Azure Document Translator rest in some common scenarios. + +| **File Name** | **Description** | +| ----------------------------------------- | --------------------------------------------- | +| [listFormats.ts][listformats] | gets a list of all supported document formats | +| [translateFromBlob.ts][translatefromblob] | translates a collection of documents | + +## Prerequisites + +The sample programs are compatible with [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule). + +Before running the samples in Node, they must be compiled to JavaScript using the TypeScript compiler. For more information on TypeScript, see the [TypeScript documentation][typescript]. Install the TypeScript compiler using: + +```bash +npm install -g typescript +``` + +You need [an Azure subscription][freesub] and the following Azure resources to run these sample programs: + +- [Azure Cognitive Services instance][createinstance_azurecognitiveservicesinstance] + +Samples retrieve credentials to access the service endpoint from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function. + +Adapting the samples to run in the browser may require some additional consideration. For details, please see the [package README][package]. + +## Setup + +To run the samples using the published version of the package: + +1. Install the dependencies using `npm`: + +```bash +npm install +``` + +2. Compile the samples: + +```bash +npm run build +``` + +3. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically. + +4. Run whichever samples you like (note that some samples may require additional setup, see the table above): + +```bash +node dist/listFormats.js +``` + +Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform): + +```bash +npx cross-env ENDPOINT="" DOCUMENT_TRANSLATOR_API_KEY="" node dist/listFormats.js +``` + +## Next Steps + +Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients. + +[listformats]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/src/listFormats.ts +[translatefromblob]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/src/translateFromBlob.ts +[apiref]: https://docs.microsoft.com/javascript/api/@azure/ai-document-translator +[freesub]: https://azure.microsoft.com/free/ +[createinstance_azurecognitiveservicesinstance]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account +[package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/documenttranslator/ai-document-translator-rest/README.md +[typescript]: https://www.typescriptlang.org/docs/home.html diff --git a/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/package.json b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/package.json new file mode 100644 index 000000000000..d35eeba35296 --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/package.json @@ -0,0 +1,41 @@ +{ + "name": "@azure-samples/ai-document-translator-ts-beta", + "private": true, + "version": "1.0.0", + "description": "Azure Document Translator rest client library samples for TypeScript (Beta)", + "engines": { + "node": ">=18.0.0" + }, + "scripts": { + "build": "tsc", + "prebuild": "rimraf dist/" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Azure/azure-sdk-for-js.git", + "directory": "sdk/documenttranslator/ai-document-translator-rest" + }, + "keywords": [ + "node", + "azure", + "cloud", + "typescript", + "browser", + "isomorphic" + ], + "author": "Microsoft Corporation", + "license": "MIT", + "bugs": { + "url": "https://github.com/Azure/azure-sdk-for-js/issues" + }, + "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/documenttranslator/ai-document-translator-rest", + "dependencies": { + "@azure-rest/ai-document-translator": "next", + "dotenv": "latest" + }, + "devDependencies": { + "@types/node": "^18.0.0", + "typescript": "~5.5.3", + "rimraf": "latest" + } +} diff --git a/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/sample.env b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/sample.env new file mode 100644 index 000000000000..700e9d42eebd --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/sample.env @@ -0,0 +1,7 @@ +# API key to authenticate service calls +DOCUMENT_TRANSLATOR_API_KEY= +# Document translation service endpoint +ENDPOINT= +# URLs to the Source and Target Azure Storage Blob containers +SOURCE_CONTAINER= +TARGET_CONTAINER= diff --git a/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/src/listFormats.ts b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/src/listFormats.ts new file mode 100644 index 000000000000..e6ad05e13f3b --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/src/listFormats.ts @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * This sample demonstrates how to make a simple call to the Azure Document Translator + * service to get a list of supported file formats + * + * @summary gets a list of all supported document formats + */ + +import DocumentTranslator from "@azure-rest/ai-document-translator"; + +import * as dotenv from "dotenv"; +dotenv.config(); + +const endpoint = process.env["ENDPOINT"] || "document-translator endpoint"; +const apiKey = process.env["DOCUMENT_TRANSLATOR_API_KEY"] || ""; + +export async function main() { + console.log("== List supported document formats sample =="); + + const client = DocumentTranslator(endpoint, { key: apiKey }); + const formats = await client.path("/documents/formats").get(); + + if (formats.status !== "200") { + throw formats.body.error; + } + + console.log(formats.body.value.map((v) => v.format).join("\n")); +} + +main().catch((err) => { + console.error(err); +}); diff --git a/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/src/translateFromBlob.ts b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/src/translateFromBlob.ts new file mode 100644 index 000000000000..51edcdaf913c --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/src/translateFromBlob.ts @@ -0,0 +1,123 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * This sample demonstrates how translate a colletion of documents stored in a Azure Storage Blob container + * and output the translated documents to another container. + * + * Translating documents is considered a Long Running Operation because it may take a long time to complete, + * specially if translating large files or a batch with several files. + * + * To handle these long running operations we need to call a few different endpoints, to track the status of the operation + * + * @summary translates a collection of documents + */ + +import DocumentTranslator, { StartTranslationDetails } from "@azure-rest/ai-document-translator"; + +import * as dotenv from "dotenv"; +dotenv.config(); + +/** + * These are states of the Long Running Operation considered as terminal + * that means that the operation has finished + */ +const terminalStates = ["Succeeded", "Failed", "Cancelled", "ValidationFailed"]; + +// Document Translation service endpoint +const endpoint = process.env["ENDPOINT"] || "document-translator endpoint"; +// Api key to authenticate the requests +const apiKey = process.env["DOCUMENT_TRANSLATOR_API_KEY"] || ""; +/** + * Azure Storage Blob containers, sourceContainer has the documents to be translated + * and targetContainer is the container where the translated documents will be output + */ +const sourceContainer = process.env["SOURCE_CONTAINER"] || ""; +const targetContainer = process.env["TARGET_CONTAINER"] || ""; + +/** + * This is the body that we need to send to the /batch endpoint + * to start a translation job on all the documents in sourceContainer + */ +const batchSubmissionRequest: StartTranslationDetails = { + inputs: [ + { + source: { sourceUrl: sourceContainer }, + targets: [{ language: "fr", targetUrl: targetContainer }], + }, + ], +}; + +export async function main() { + console.log("== Translate documents in a container sample =="); + + // Create a new client + const client = DocumentTranslator(endpoint, { key: apiKey }); + + // Call the /batches path to initiate the translation job + const formats = await client.path("/batches").post({ + body: batchSubmissionRequest, + }); + + // If we get a non-success status code, throw an error + if (formats.status !== "202") { + throw formats.body.error; + } + + // The initial response contains an operation-location header which indicates + // the url in which we can poll for the status of the operation + // this URL is in a format in which the last part of the url is the operationId + // we can extract that ID and use it to call "/batches/{id}" + const batchId = extractBatchId(formats.headers["operation-location"]); + + /** + * We need to keep polling for the operation state until we find a terminal state + * once we reached the terminal state we can proceed and access the translated documents + * or throw an error in case something failed + */ + // Setting up the batch status path to reuse it in the loop + const checkStatus = client.path("/batches/{id}", batchId); + let operationState; + do { + // We just call get on checkStatus and store the current state + operationState = await checkStatus.get(); + + // If we get a non-success status code, throw the error + if (operationState.status !== "200") { + throw operationState.body.error; + } + + // The checkStatus operation returns a retry-after header that contains the + // time in seconds to wait before sending the next polling request + const parsedRetryAfter = Number.parseInt(String(operationState.headers["retry-after"]) || "5"); + const waitTime = Number.isInteger(parsedRetryAfter) ? parsedRetryAfter : 5; + await wait(waitTime); + } while (!terminalStates.includes(operationState.body.status)); + + // Now that the operation is complete, we can list the translated documents + const documents = await client.path("/batches/{id}/documents", batchId).get(); + + if (documents.status !== "200") { + throw documents.body.error; + } + + console.log(documents.body.value.map((doc) => doc.path).join("\n")); +} + +// Helper function to wait/sleep for N seconds +function wait(seconds: number): Promise { + return new Promise((resolve) => { + setTimeout(resolve, seconds * 1000); + }); +} + +// Helper function that extracts the batch id from operation-location header +function extractBatchId(batchUrl: string = "") { + const parts = batchUrl.split("/"); + + return parts[parts.length - 1]; +} + +main().catch((err) => { + console.error(err); +}); diff --git a/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/tsconfig.json b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/tsconfig.json new file mode 100644 index 000000000000..984eed535aa8 --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/samples/v1-beta/typescript/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "target": "ES2020", + "module": "commonjs", + "moduleResolution": "node", + "resolveJsonModule": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "alwaysStrict": true, + "outDir": "dist", + "rootDir": "src" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/sdk/documenttranslator/ai-document-translator-rest/src/clientDefinitions.ts b/sdk/documenttranslator/ai-document-translator-rest/src/clientDefinitions.ts new file mode 100644 index 000000000000..d4f02adf23ff --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/src/clientDefinitions.ts @@ -0,0 +1,272 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import type { + DocumentTranslationStartTranslationParameters, + DocumentTranslationGetTranslationsStatusParameters, + DocumentTranslationGetDocumentStatusParameters, + DocumentTranslationGetTranslationStatusParameters, + DocumentTranslationCancelTranslationParameters, + DocumentTranslationGetDocumentsStatusParameters, + DocumentTranslationGetSupportedDocumentFormatsParameters, + DocumentTranslationGetSupportedGlossaryFormatsParameters, + DocumentTranslationGetSupportedStorageSourcesParameters, +} from "./parameters.js"; +import type { + DocumentTranslationStartTranslation202Response, + DocumentTranslationStartTranslation400Response, + DocumentTranslationStartTranslation401Response, + DocumentTranslationStartTranslation429Response, + DocumentTranslationStartTranslation500Response, + DocumentTranslationStartTranslation503Response, + DocumentTranslationGetTranslationsStatus200Response, + DocumentTranslationGetTranslationsStatus400Response, + DocumentTranslationGetTranslationsStatus401Response, + DocumentTranslationGetTranslationsStatus429Response, + DocumentTranslationGetTranslationsStatus500Response, + DocumentTranslationGetTranslationsStatus503Response, + DocumentTranslationGetDocumentStatus200Response, + DocumentTranslationGetDocumentStatus401Response, + DocumentTranslationGetDocumentStatus404Response, + DocumentTranslationGetDocumentStatus429Response, + DocumentTranslationGetDocumentStatus500Response, + DocumentTranslationGetDocumentStatus503Response, + DocumentTranslationGetTranslationStatus200Response, + DocumentTranslationGetTranslationStatus401Response, + DocumentTranslationGetTranslationStatus404Response, + DocumentTranslationGetTranslationStatus429Response, + DocumentTranslationGetTranslationStatus500Response, + DocumentTranslationGetTranslationStatus503Response, + DocumentTranslationCancelTranslation200Response, + DocumentTranslationCancelTranslation401Response, + DocumentTranslationCancelTranslation404Response, + DocumentTranslationCancelTranslation429Response, + DocumentTranslationCancelTranslation500Response, + DocumentTranslationCancelTranslation503Response, + DocumentTranslationGetDocumentsStatus200Response, + DocumentTranslationGetDocumentsStatus400Response, + DocumentTranslationGetDocumentsStatus401Response, + DocumentTranslationGetDocumentsStatus404Response, + DocumentTranslationGetDocumentsStatus429Response, + DocumentTranslationGetDocumentsStatus500Response, + DocumentTranslationGetDocumentsStatus503Response, + DocumentTranslationGetSupportedDocumentFormats200Response, + DocumentTranslationGetSupportedDocumentFormats429Response, + DocumentTranslationGetSupportedDocumentFormats500Response, + DocumentTranslationGetSupportedDocumentFormats503Response, + DocumentTranslationGetSupportedGlossaryFormats200Response, + DocumentTranslationGetSupportedGlossaryFormats429Response, + DocumentTranslationGetSupportedGlossaryFormats500Response, + DocumentTranslationGetSupportedGlossaryFormats503Response, + DocumentTranslationGetSupportedStorageSources200Response, + DocumentTranslationGetSupportedStorageSources429Response, + DocumentTranslationGetSupportedStorageSources500Response, + DocumentTranslationGetSupportedStorageSources503Response, +} from "./responses.js"; +import type { Client, StreamableMethod } from "@azure-rest/core-client"; + +export interface StartTranslation { + /** + * Use this API to submit a bulk (batch) translation request to the Document Translation service. + * Each request can contain multiple documents and must contain a source and destination container for each document. + * + * The prefix and suffix filter (if supplied) are used to filter folders. The prefix is applied to the subpath after the container name. + * + * Glossaries / Translation memory can be included in the request and are applied by the service when the document is translated. + * + * If the glossary is invalid or unreachable during translation, an error is indicated in the document status. + * If a file with the same name already exists at the destination, it will be overwritten. The targetUrl for each target language must be unique. + */ + post( + options: DocumentTranslationStartTranslationParameters, + ): StreamableMethod< + | DocumentTranslationStartTranslation202Response + | DocumentTranslationStartTranslation400Response + | DocumentTranslationStartTranslation401Response + | DocumentTranslationStartTranslation429Response + | DocumentTranslationStartTranslation500Response + | DocumentTranslationStartTranslation503Response + >; + /** + * Returns a list of batch requests submitted and the status for each request. + * This list only contains batch requests submitted by the user (based on the resource). + * + * If the number of requests exceeds our paging limit, server-side paging is used. Paginated responses indicate a partial result and include a continuation token in the response. + * The absence of a continuation token means that no additional pages are available. + * + * $top, $skip and $maxpagesize query parameters can be used to specify a number of results to return and an offset for the collection. + * + * $top indicates the total number of records the user wants to be returned across all pages. + * $skip indicates the number of records to skip from the list of batches based on the sorting method specified. By default, we sort by descending start time. + * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), '\@nextLink' will contain the link to the next page. + * + * $orderBy query parameter can be used to sort the returned list (ex "$orderBy=createdDateTimeUtc asc" or "$orderBy=createdDateTimeUtc desc"). + * The default sorting is descending by createdDateTimeUtc. + * Some query parameters can be used to filter the returned list (ex: "status=Succeeded,Cancelled") will only return succeeded and cancelled operations. + * createdDateTimeUtcStart and createdDateTimeUtcEnd can be used combined or separately to specify a range of datetime to filter the returned list by. + * The supported filtering query parameters are (status, ids, createdDateTimeUtcStart, createdDateTimeUtcEnd). + * + * The server honors 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 included, 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 reduces the risk of the client making assumptions about the data returned. + */ + get( + options?: DocumentTranslationGetTranslationsStatusParameters, + ): StreamableMethod< + | DocumentTranslationGetTranslationsStatus200Response + | DocumentTranslationGetTranslationsStatus400Response + | DocumentTranslationGetTranslationsStatus401Response + | DocumentTranslationGetTranslationsStatus429Response + | DocumentTranslationGetTranslationsStatus500Response + | DocumentTranslationGetTranslationsStatus503Response + >; +} + +export interface GetDocumentStatus { + /** Returns the translation status for a specific document based on the request Id and document Id. */ + get( + options?: DocumentTranslationGetDocumentStatusParameters, + ): StreamableMethod< + | DocumentTranslationGetDocumentStatus200Response + | DocumentTranslationGetDocumentStatus401Response + | DocumentTranslationGetDocumentStatus404Response + | DocumentTranslationGetDocumentStatus429Response + | DocumentTranslationGetDocumentStatus500Response + | DocumentTranslationGetDocumentStatus503Response + >; +} + +export interface GetTranslationStatus { + /** + * Returns the status for a document translation request. + * The status includes the overall request status, as well as the status for documents that are being translated as part of that request. + */ + get( + options?: DocumentTranslationGetTranslationStatusParameters, + ): StreamableMethod< + | DocumentTranslationGetTranslationStatus200Response + | DocumentTranslationGetTranslationStatus401Response + | DocumentTranslationGetTranslationStatus404Response + | DocumentTranslationGetTranslationStatus429Response + | DocumentTranslationGetTranslationStatus500Response + | DocumentTranslationGetTranslationStatus503Response + >; + /** + * Cancel a currently processing or queued translation. + * Cancel a currently processing or queued translation. + * A translation 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. + */ + delete( + options?: DocumentTranslationCancelTranslationParameters, + ): StreamableMethod< + | DocumentTranslationCancelTranslation200Response + | DocumentTranslationCancelTranslation401Response + | DocumentTranslationCancelTranslation404Response + | DocumentTranslationCancelTranslation429Response + | DocumentTranslationCancelTranslation500Response + | DocumentTranslationCancelTranslation503Response + >; +} + +export interface GetDocumentsStatus { + /** + * Returns the status for all documents in a batch document translation request. + * + * If the number of documents in the response exceeds our paging limit, server-side paging is used. + * Paginated responses indicate a partial result and include a continuation token in the response. The absence of a continuation token means that no additional pages are available. + * + * $top, $skip and $maxpagesize query parameters can be used to specify a number of results to return and an offset for the collection. + * + * $top indicates the total number of records the user wants to be returned across all pages. + * $skip indicates the number of records to skip from the list of document status held by the server based on the sorting method specified. By default, we sort by descending start time. + * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), '\@nextLink' will contain the link to the next page. + * + * $orderBy query parameter can be used to sort the returned list (ex "$orderBy=createdDateTimeUtc asc" or "$orderBy=createdDateTimeUtc desc"). + * The default sorting is descending by createdDateTimeUtc. + * Some query parameters can be used to filter the returned list (ex: "status=Succeeded,Cancelled") will only return succeeded and cancelled documents. + * createdDateTimeUtcStart and createdDateTimeUtcEnd can be used combined or separately to specify a range of datetime to filter the returned list by. + * The supported filtering query parameters are (status, ids, createdDateTimeUtcStart, createdDateTimeUtcEnd). + * + * When both $top and $skip are included, 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 reduces the risk of the client making assumptions about the data returned. + */ + get( + options?: DocumentTranslationGetDocumentsStatusParameters, + ): StreamableMethod< + | DocumentTranslationGetDocumentsStatus200Response + | DocumentTranslationGetDocumentsStatus400Response + | DocumentTranslationGetDocumentsStatus401Response + | DocumentTranslationGetDocumentsStatus404Response + | DocumentTranslationGetDocumentsStatus429Response + | DocumentTranslationGetDocumentsStatus500Response + | DocumentTranslationGetDocumentsStatus503Response + >; +} + +export interface GetSupportedDocumentFormats { + /** + * The list of supported document formats supported by the Document Translation service. + * The list includes the common file extension, as well as the content-type if using the upload API. + */ + get( + options?: DocumentTranslationGetSupportedDocumentFormatsParameters, + ): StreamableMethod< + | DocumentTranslationGetSupportedDocumentFormats200Response + | DocumentTranslationGetSupportedDocumentFormats429Response + | DocumentTranslationGetSupportedDocumentFormats500Response + | DocumentTranslationGetSupportedDocumentFormats503Response + >; +} + +export interface GetSupportedGlossaryFormats { + /** + * The list of supported glossary formats supported by the Document Translation service. + * The list includes the common file extension used. + */ + get( + options?: DocumentTranslationGetSupportedGlossaryFormatsParameters, + ): StreamableMethod< + | DocumentTranslationGetSupportedGlossaryFormats200Response + | DocumentTranslationGetSupportedGlossaryFormats429Response + | DocumentTranslationGetSupportedGlossaryFormats500Response + | DocumentTranslationGetSupportedGlossaryFormats503Response + >; +} + +export interface GetSupportedStorageSources { + /** Returns a list of storage sources/options supported by the Document Translation service. */ + get( + options?: DocumentTranslationGetSupportedStorageSourcesParameters, + ): StreamableMethod< + | DocumentTranslationGetSupportedStorageSources200Response + | DocumentTranslationGetSupportedStorageSources429Response + | DocumentTranslationGetSupportedStorageSources500Response + | DocumentTranslationGetSupportedStorageSources503Response + >; +} + +export interface Routes { + /** Resource for '/batches' has methods for the following verbs: post, get */ + (path: "/batches"): StartTranslation; + /** Resource for '/batches/\{id\}/documents/\{documentId\}' has methods for the following verbs: get */ + (path: "/batches/{id}/documents/{documentId}", id: string, documentId: string): GetDocumentStatus; + /** Resource for '/batches/\{id\}' has methods for the following verbs: get, delete */ + (path: "/batches/{id}", id: string): GetTranslationStatus; + /** Resource for '/batches/\{id\}/documents' has methods for the following verbs: get */ + (path: "/batches/{id}/documents", id: string): GetDocumentsStatus; + /** Resource for '/documents/formats' has methods for the following verbs: get */ + (path: "/documents/formats"): GetSupportedDocumentFormats; + /** Resource for '/glossaries/formats' has methods for the following verbs: get */ + (path: "/glossaries/formats"): GetSupportedGlossaryFormats; + /** Resource for '/storagesources' has methods for the following verbs: get */ + (path: "/storagesources"): GetSupportedStorageSources; +} + +export type DocumentTranslatorClient = Client & { + path: Routes; +}; diff --git a/sdk/documenttranslator/ai-document-translator-rest/src/constants.ts b/sdk/documenttranslator/ai-document-translator-rest/src/constants.ts deleted file mode 100644 index f1e1289a14e5..000000000000 --- a/sdk/documenttranslator/ai-document-translator-rest/src/constants.ts +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * @internal - */ -export const SDK_VERSION: string = "1.0.0-beta.2"; diff --git a/sdk/documenttranslator/ai-document-translator-rest/src/documentTranslator.ts b/sdk/documenttranslator/ai-document-translator-rest/src/documentTranslator.ts index cce578145d12..999c81730d79 100644 --- a/sdk/documenttranslator/ai-document-translator-rest/src/documentTranslator.ts +++ b/sdk/documenttranslator/ai-document-translator-rest/src/documentTranslator.ts @@ -1,295 +1,54 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import type { - CancelTranslation200Response, - CancelTranslation401Response, - CancelTranslation404Response, - CancelTranslation429Response, - CancelTranslation500Response, - CancelTranslation503Response, - GetDocumentStatus200Response, - GetDocumentStatus401Response, - GetDocumentStatus404Response, - GetDocumentStatus429Response, - GetDocumentStatus500Response, - GetDocumentStatus503Response, - GetDocumentsStatus200Response, - GetDocumentsStatus400Response, - GetDocumentsStatus401Response, - GetDocumentsStatus404Response, - GetDocumentsStatus429Response, - GetDocumentsStatus500Response, - GetDocumentsStatus503Response, - GetSupportedDocumentFormats200Response, - GetSupportedDocumentFormats429Response, - GetSupportedDocumentFormats500Response, - GetSupportedDocumentFormats503Response, - GetSupportedGlossaryFormats200Response, - GetSupportedGlossaryFormats429Response, - GetSupportedGlossaryFormats500Response, - GetSupportedGlossaryFormats503Response, - GetSupportedStorageSources200Response, - GetSupportedStorageSources429Response, - GetSupportedStorageSources500Response, - GetSupportedStorageSources503Response, - GetTranslationStatus200Response, - GetTranslationStatus401Response, - GetTranslationStatus404Response, - GetTranslationStatus429Response, - GetTranslationStatus500Response, - GetTranslationStatus503Response, - GetTranslationsStatus200Response, - GetTranslationsStatus400Response, - GetTranslationsStatus401Response, - GetTranslationsStatus429Response, - GetTranslationsStatus500Response, - GetTranslationsStatus503Response, - StartTranslation202Response, - StartTranslation400Response, - StartTranslation401Response, - StartTranslation429Response, - StartTranslation500Response, - StartTranslation503Response, -} from "./responses.js"; -import type { - CancelTranslationParameters, - GetDocumentStatusParameters, - GetDocumentsStatusParameters, - GetSupportedDocumentFormatsParameters, - GetSupportedGlossaryFormatsParameters, - GetSupportedStorageSourcesParameters, - GetTranslationStatusParameters, - GetTranslationsStatusParameters, - StartTranslationParameters, -} from "./parameters.js"; -import type { Client, ClientOptions } from "@azure-rest/core-client"; +import type { ClientOptions } from "@azure-rest/core-client"; import { getClient } from "@azure-rest/core-client"; -import type { KeyCredential, TokenCredential } from "@azure/core-auth"; - -export interface GetTranslationsStatus { - /** - * Use this API to submit a bulk (batch) translation request to the Document Translation service. - * Each request can contain multiple documents and must contain a source and destination container for each document. - * - * The prefix and suffix filter (if supplied) are used to filter folders. The prefix is applied to the subpath after the container name. - * - * Glossaries / Translation memory can be included in the request and are applied by the service when the document is translated. - * - * If the glossary is invalid or unreachable during translation, an error is indicated in the document status. - * If a file with the same name already exists at the destination, it will be overwritten. The targetUrl for each target language must be unique. - */ - post( - options: StartTranslationParameters, - ): Promise< - | StartTranslation202Response - | StartTranslation400Response - | StartTranslation401Response - | StartTranslation429Response - | StartTranslation500Response - | StartTranslation503Response - >; - /** - * Returns a list of batch requests submitted and the status for each request. - * This list only contains batch requests submitted by the user (based on the resource). - * - * If the number of requests exceeds our paging limit, server-side paging is used. Paginated responses indicate a partial result and include a continuation token in the response. - * The absence of a continuation token means that no additional pages are available. - * - * $top, $skip and $maxpagesize query parameters can be used to specify a number of results to return and an offset for the collection. - * - * $top indicates the total number of records the user wants to be returned across all pages. - * $skip indicates the number of records to skip from the list of batches based on the sorting method specified. By default, we sort by descending start time. - * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), \@nextLink will contain the link to the next page. - * - * $orderBy query parameter can be used to sort the returned list (ex "$orderBy=createdDateTimeUtc asc" or "$orderBy=createdDateTimeUtc desc"). - * The default sorting is descending by createdDateTimeUtc. - * Some query parameters can be used to filter the returned list (ex: "status=Succeeded,Cancelled") will only return succeeded and cancelled operations. - * createdDateTimeUtcStart and createdDateTimeUtcEnd can be used combined or separately to specify a range of datetime to filter the returned list by. - * The supported filtering query parameters are (status, ids, createdDateTimeUtcStart, createdDateTimeUtcEnd). - * - * The server honors 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 included, 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 reduces the risk of the client making assumptions about the data returned. - */ - get( - options?: GetTranslationsStatusParameters, - ): Promise< - | GetTranslationsStatus200Response - | GetTranslationsStatus400Response - | GetTranslationsStatus401Response - | GetTranslationsStatus429Response - | GetTranslationsStatus500Response - | GetTranslationsStatus503Response - >; -} - -export interface GetDocumentStatus { - /** Returns the translation status for a specific document based on the request Id and document Id. */ - get( - options?: GetDocumentStatusParameters, - ): Promise< - | GetDocumentStatus200Response - | GetDocumentStatus401Response - | GetDocumentStatus404Response - | GetDocumentStatus429Response - | GetDocumentStatus500Response - | GetDocumentStatus503Response - >; -} - -export interface CancelTranslation { - /** - * Returns the status for a document translation request. - * The status includes the overall request status, as well as the status for documents that are being translated as part of that request. - */ - get( - options?: GetTranslationStatusParameters, - ): Promise< - | GetTranslationStatus200Response - | GetTranslationStatus401Response - | GetTranslationStatus404Response - | GetTranslationStatus429Response - | GetTranslationStatus500Response - | GetTranslationStatus503Response - >; - /** - * Cancel a currently processing or queued translation. - * Cancel a currently processing or queued translation. - * A translation 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. - */ - delete( - options?: CancelTranslationParameters, - ): Promise< - | CancelTranslation200Response - | CancelTranslation401Response - | CancelTranslation404Response - | CancelTranslation429Response - | CancelTranslation500Response - | CancelTranslation503Response - >; -} - -export interface GetDocumentsStatus { - /** - * Returns the status for all documents in a batch document translation request. - * - * If the number of documents in the response exceeds our paging limit, server-side paging is used. - * Paginated responses indicate a partial result and include a continuation token in the response. The absence of a continuation token means that no additional pages are available. - * - * $top, $skip and $maxpagesize query parameters can be used to specify a number of results to return and an offset for the collection. - * - * $top indicates the total number of records the user wants to be returned across all pages. - * $skip indicates the number of records to skip from the list of document status held by the server based on the sorting method specified. By default, we sort by descending start time. - * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), \@nextLink will contain the link to the next page. - * - * $orderBy query parameter can be used to sort the returned list (ex "$orderBy=createdDateTimeUtc asc" or "$orderBy=createdDateTimeUtc desc"). - * The default sorting is descending by createdDateTimeUtc. - * Some query parameters can be used to filter the returned list (ex: "status=Succeeded,Cancelled") will only return succeeded and cancelled documents. - * createdDateTimeUtcStart and createdDateTimeUtcEnd can be used combined or separately to specify a range of datetime to filter the returned list by. - * The supported filtering query parameters are (status, ids, createdDateTimeUtcStart, createdDateTimeUtcEnd). - * - * When both $top and $skip are included, 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 reduces the risk of the client making assumptions about the data returned. - */ - get( - options?: GetDocumentsStatusParameters, - ): Promise< - | GetDocumentsStatus200Response - | GetDocumentsStatus400Response - | GetDocumentsStatus401Response - | GetDocumentsStatus404Response - | GetDocumentsStatus429Response - | GetDocumentsStatus500Response - | GetDocumentsStatus503Response - >; -} - -export interface GetSupportedDocumentFormats { - /** - * The list of supported document formats supported by the Document Translation service. - * The list includes the common file extension, as well as the content-type if using the upload API. - */ - get( - options?: GetSupportedDocumentFormatsParameters, - ): Promise< - | GetSupportedDocumentFormats200Response - | GetSupportedDocumentFormats429Response - | GetSupportedDocumentFormats500Response - | GetSupportedDocumentFormats503Response - >; -} - -export interface GetSupportedGlossaryFormats { - /** - * The list of supported glossary formats supported by the Document Translation service. - * The list includes the common file extension used. - */ - get( - options?: GetSupportedGlossaryFormatsParameters, - ): Promise< - | GetSupportedGlossaryFormats200Response - | GetSupportedGlossaryFormats429Response - | GetSupportedGlossaryFormats500Response - | GetSupportedGlossaryFormats503Response - >; -} - -export interface GetSupportedStorageSources { - /** Returns a list of storage sources/options supported by the Document Translation service. */ - get( - options?: GetSupportedStorageSourcesParameters, - ): Promise< - | GetSupportedStorageSources200Response - | GetSupportedStorageSources429Response - | GetSupportedStorageSources500Response - | GetSupportedStorageSources503Response - >; -} - -export interface Routes { - /** Resource for '/batches' has methods for the following verbs: post, get */ - (path: "/batches"): GetTranslationsStatus; - /** Resource for '/batches/\{id\}/documents/\{documentId\}' has methods for the following verbs: get */ - (path: "/batches/{id}/documents/{documentId}", id: string, documentId: string): GetDocumentStatus; - /** Resource for '/batches/\{id\}' has methods for the following verbs: get, delete */ - (path: "/batches/{id}", id: string): CancelTranslation; - /** Resource for '/batches/\{id\}/documents' has methods for the following verbs: get */ - (path: "/batches/{id}/documents", id: string): GetDocumentsStatus; - /** Resource for '/documents/formats' has methods for the following verbs: get */ - (path: "/documents/formats"): GetSupportedDocumentFormats; - /** Resource for '/glossaries/formats' has methods for the following verbs: get */ - (path: "/glossaries/formats"): GetSupportedGlossaryFormats; - /** Resource for '/storagesources' has methods for the following verbs: get */ - (path: "/storagesources"): GetSupportedStorageSources; -} - -export type DocumentTranslatorClient = Client & { - path: Routes; -}; - -export interface DocumentTranslatorFactory { - (endpoint: string, credentials: TokenCredential | KeyCredential, options?: ClientOptions): void; -} - -export default function DocumentTranslator( +import { logger } from "./logger.js"; +import type { KeyCredential } from "@azure/core-auth"; +import type { DocumentTranslatorClient } from "./clientDefinitions.js"; + +/** The optional parameters for the client */ +export interface DocumentTranslatorClientOptions extends ClientOptions {} + +/** + * Initialize a new instance of `DocumentTranslatorClient` + * @param endpoint - Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus.api.cognitive.microsoft.com). + * @param credentials - uniquely identify client credential + * @param options - the parameter for all optional parameters + */ +export default function createClient( endpoint: string, - credentials: TokenCredential | KeyCredential, - options: ClientOptions = {}, + credentials: KeyCredential, + options: DocumentTranslatorClientOptions = {}, ): DocumentTranslatorClient { - const baseUrl = options.baseUrl ?? `${endpoint}/translator/text/batch/v1.0`; + const endpointUrl = + options.endpoint ?? options.baseUrl ?? `${endpoint}/translator/text/batch/v1.0`; + const userAgentInfo = `azsdk-js-ai-document-translator-rest/1.0.0-beta.2`; + const userAgentPrefix = + options.userAgentOptions && options.userAgentOptions.userAgentPrefix + ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}` + : `${userAgentInfo}`; options = { ...options, + userAgentOptions: { + userAgentPrefix, + }, + loggingOptions: { + logger: options.loggingOptions?.logger ?? logger.info, + }, credentials: { scopes: ["https://cognitiveservices.azure.com/.default"], - apiKeyHeaderName: "Ocp-Apim-Subscription-Key", + apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key", }, }; + const client = getClient(endpointUrl, credentials, options) as DocumentTranslatorClient; + + client.pipeline.removePolicy({ name: "ApiVersionPolicy" }); + if (options.apiVersion) { + logger.warning( + "This client does not support client api-version, please change it at the operation level", + ); + } - return getClient(baseUrl, credentials, options) as DocumentTranslatorClient; + return client; } diff --git a/sdk/documenttranslator/ai-document-translator-rest/src/index.ts b/sdk/documenttranslator/ai-document-translator-rest/src/index.ts index 1d400e531bb4..49a668ddaa30 100644 --- a/sdk/documenttranslator/ai-document-translator-rest/src/index.ts +++ b/sdk/documenttranslator/ai-document-translator-rest/src/index.ts @@ -1,15 +1,16 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -/** - * A rest library for working with the Azure Document Translator service. - * @packageDocumentation - */ - import DocumentTranslator from "./documentTranslator.js"; + export * from "./documentTranslator.js"; -export * from "./models.js"; export * from "./parameters.js"; export * from "./responses.js"; -// eslint-disable-next-line @azure/azure-sdk/ts-modules-only-named +export * from "./clientDefinitions.js"; +export * from "./isUnexpected.js"; +export * from "./models.js"; +export * from "./outputModels.js"; +export * from "./paginateHelper.js"; +export * from "./pollingHelper.js"; + export default DocumentTranslator; diff --git a/sdk/documenttranslator/ai-document-translator-rest/src/isUnexpected.ts b/sdk/documenttranslator/ai-document-translator-rest/src/isUnexpected.ts new file mode 100644 index 000000000000..a8b8d4e3e2b6 --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/src/isUnexpected.ts @@ -0,0 +1,310 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import type { + DocumentTranslationStartTranslation202Response, + DocumentTranslationStartTranslation400Response, + DocumentTranslationStartTranslation401Response, + DocumentTranslationStartTranslation429Response, + DocumentTranslationStartTranslation500Response, + DocumentTranslationStartTranslation503Response, + DocumentTranslationGetTranslationsStatus200Response, + DocumentTranslationGetTranslationsStatus400Response, + DocumentTranslationGetTranslationsStatus401Response, + DocumentTranslationGetTranslationsStatus429Response, + DocumentTranslationGetTranslationsStatus500Response, + DocumentTranslationGetTranslationsStatus503Response, + DocumentTranslationGetDocumentStatus200Response, + DocumentTranslationGetDocumentStatus401Response, + DocumentTranslationGetDocumentStatus404Response, + DocumentTranslationGetDocumentStatus429Response, + DocumentTranslationGetDocumentStatus500Response, + DocumentTranslationGetDocumentStatus503Response, + DocumentTranslationGetTranslationStatus200Response, + DocumentTranslationGetTranslationStatus401Response, + DocumentTranslationGetTranslationStatus404Response, + DocumentTranslationGetTranslationStatus429Response, + DocumentTranslationGetTranslationStatus500Response, + DocumentTranslationGetTranslationStatus503Response, + DocumentTranslationCancelTranslation200Response, + DocumentTranslationCancelTranslation401Response, + DocumentTranslationCancelTranslation404Response, + DocumentTranslationCancelTranslation429Response, + DocumentTranslationCancelTranslation500Response, + DocumentTranslationCancelTranslation503Response, + DocumentTranslationGetDocumentsStatus200Response, + DocumentTranslationGetDocumentsStatus400Response, + DocumentTranslationGetDocumentsStatus401Response, + DocumentTranslationGetDocumentsStatus404Response, + DocumentTranslationGetDocumentsStatus429Response, + DocumentTranslationGetDocumentsStatus500Response, + DocumentTranslationGetDocumentsStatus503Response, + DocumentTranslationGetSupportedDocumentFormats200Response, + DocumentTranslationGetSupportedDocumentFormats429Response, + DocumentTranslationGetSupportedDocumentFormats500Response, + DocumentTranslationGetSupportedDocumentFormats503Response, + DocumentTranslationGetSupportedGlossaryFormats200Response, + DocumentTranslationGetSupportedGlossaryFormats429Response, + DocumentTranslationGetSupportedGlossaryFormats500Response, + DocumentTranslationGetSupportedGlossaryFormats503Response, + DocumentTranslationGetSupportedStorageSources200Response, + DocumentTranslationGetSupportedStorageSources429Response, + DocumentTranslationGetSupportedStorageSources500Response, + DocumentTranslationGetSupportedStorageSources503Response, +} from "./responses.js"; + +const responseMap: Record = { + "GET /batches": ["200"], + "POST /batches": ["202"], + "GET /batches/{id}/documents/{documentId}": ["200"], + "GET /batches/{id}": ["200"], + "DELETE /batches/{id}": ["200"], + "GET /batches/{id}/documents": ["200"], + "GET /documents/formats": ["200"], + "GET /glossaries/formats": ["200"], + "GET /storagesources": ["200"], +}; + +export function isUnexpected( + response: + | DocumentTranslationStartTranslation202Response + | DocumentTranslationStartTranslation400Response + | DocumentTranslationStartTranslation401Response + | DocumentTranslationStartTranslation429Response + | DocumentTranslationStartTranslation500Response + | DocumentTranslationStartTranslation503Response, +): response is DocumentTranslationStartTranslation400Response; +export function isUnexpected( + response: + | DocumentTranslationGetTranslationsStatus200Response + | DocumentTranslationGetTranslationsStatus400Response + | DocumentTranslationGetTranslationsStatus401Response + | DocumentTranslationGetTranslationsStatus429Response + | DocumentTranslationGetTranslationsStatus500Response + | DocumentTranslationGetTranslationsStatus503Response, +): response is DocumentTranslationGetTranslationsStatus400Response; +export function isUnexpected( + response: + | DocumentTranslationGetDocumentStatus200Response + | DocumentTranslationGetDocumentStatus401Response + | DocumentTranslationGetDocumentStatus404Response + | DocumentTranslationGetDocumentStatus429Response + | DocumentTranslationGetDocumentStatus500Response + | DocumentTranslationGetDocumentStatus503Response, +): response is DocumentTranslationGetDocumentStatus401Response; +export function isUnexpected( + response: + | DocumentTranslationGetTranslationStatus200Response + | DocumentTranslationGetTranslationStatus401Response + | DocumentTranslationGetTranslationStatus404Response + | DocumentTranslationGetTranslationStatus429Response + | DocumentTranslationGetTranslationStatus500Response + | DocumentTranslationGetTranslationStatus503Response, +): response is DocumentTranslationGetTranslationStatus401Response; +export function isUnexpected( + response: + | DocumentTranslationCancelTranslation200Response + | DocumentTranslationCancelTranslation401Response + | DocumentTranslationCancelTranslation404Response + | DocumentTranslationCancelTranslation429Response + | DocumentTranslationCancelTranslation500Response + | DocumentTranslationCancelTranslation503Response, +): response is DocumentTranslationCancelTranslation401Response; +export function isUnexpected( + response: + | DocumentTranslationGetDocumentsStatus200Response + | DocumentTranslationGetDocumentsStatus400Response + | DocumentTranslationGetDocumentsStatus401Response + | DocumentTranslationGetDocumentsStatus404Response + | DocumentTranslationGetDocumentsStatus429Response + | DocumentTranslationGetDocumentsStatus500Response + | DocumentTranslationGetDocumentsStatus503Response, +): response is DocumentTranslationGetDocumentsStatus400Response; +export function isUnexpected( + response: + | DocumentTranslationGetSupportedDocumentFormats200Response + | DocumentTranslationGetSupportedDocumentFormats429Response + | DocumentTranslationGetSupportedDocumentFormats500Response + | DocumentTranslationGetSupportedDocumentFormats503Response, +): response is DocumentTranslationGetSupportedDocumentFormats429Response; +export function isUnexpected( + response: + | DocumentTranslationGetSupportedGlossaryFormats200Response + | DocumentTranslationGetSupportedGlossaryFormats429Response + | DocumentTranslationGetSupportedGlossaryFormats500Response + | DocumentTranslationGetSupportedGlossaryFormats503Response, +): response is DocumentTranslationGetSupportedGlossaryFormats429Response; +export function isUnexpected( + response: + | DocumentTranslationGetSupportedStorageSources200Response + | DocumentTranslationGetSupportedStorageSources429Response + | DocumentTranslationGetSupportedStorageSources500Response + | DocumentTranslationGetSupportedStorageSources503Response, +): response is DocumentTranslationGetSupportedStorageSources429Response; +export function isUnexpected( + response: + | DocumentTranslationStartTranslation202Response + | DocumentTranslationStartTranslation400Response + | DocumentTranslationStartTranslation401Response + | DocumentTranslationStartTranslation429Response + | DocumentTranslationStartTranslation500Response + | DocumentTranslationStartTranslation503Response + | DocumentTranslationGetTranslationsStatus200Response + | DocumentTranslationGetTranslationsStatus400Response + | DocumentTranslationGetTranslationsStatus401Response + | DocumentTranslationGetTranslationsStatus429Response + | DocumentTranslationGetTranslationsStatus500Response + | DocumentTranslationGetTranslationsStatus503Response + | DocumentTranslationGetDocumentStatus200Response + | DocumentTranslationGetDocumentStatus401Response + | DocumentTranslationGetDocumentStatus404Response + | DocumentTranslationGetDocumentStatus429Response + | DocumentTranslationGetDocumentStatus500Response + | DocumentTranslationGetDocumentStatus503Response + | DocumentTranslationGetTranslationStatus200Response + | DocumentTranslationGetTranslationStatus401Response + | DocumentTranslationGetTranslationStatus404Response + | DocumentTranslationGetTranslationStatus429Response + | DocumentTranslationGetTranslationStatus500Response + | DocumentTranslationGetTranslationStatus503Response + | DocumentTranslationCancelTranslation200Response + | DocumentTranslationCancelTranslation401Response + | DocumentTranslationCancelTranslation404Response + | DocumentTranslationCancelTranslation429Response + | DocumentTranslationCancelTranslation500Response + | DocumentTranslationCancelTranslation503Response + | DocumentTranslationGetDocumentsStatus200Response + | DocumentTranslationGetDocumentsStatus400Response + | DocumentTranslationGetDocumentsStatus401Response + | DocumentTranslationGetDocumentsStatus404Response + | DocumentTranslationGetDocumentsStatus429Response + | DocumentTranslationGetDocumentsStatus500Response + | DocumentTranslationGetDocumentsStatus503Response + | DocumentTranslationGetSupportedDocumentFormats200Response + | DocumentTranslationGetSupportedDocumentFormats429Response + | DocumentTranslationGetSupportedDocumentFormats500Response + | DocumentTranslationGetSupportedDocumentFormats503Response + | DocumentTranslationGetSupportedGlossaryFormats200Response + | DocumentTranslationGetSupportedGlossaryFormats429Response + | DocumentTranslationGetSupportedGlossaryFormats500Response + | DocumentTranslationGetSupportedGlossaryFormats503Response + | DocumentTranslationGetSupportedStorageSources200Response + | DocumentTranslationGetSupportedStorageSources429Response + | DocumentTranslationGetSupportedStorageSources500Response + | DocumentTranslationGetSupportedStorageSources503Response, +): response is + | DocumentTranslationStartTranslation400Response + | DocumentTranslationStartTranslation401Response + | DocumentTranslationStartTranslation429Response + | DocumentTranslationStartTranslation500Response + | DocumentTranslationStartTranslation503Response + | DocumentTranslationGetTranslationsStatus400Response + | DocumentTranslationGetTranslationsStatus401Response + | DocumentTranslationGetTranslationsStatus429Response + | DocumentTranslationGetTranslationsStatus500Response + | DocumentTranslationGetTranslationsStatus503Response + | DocumentTranslationGetDocumentStatus401Response + | DocumentTranslationGetDocumentStatus404Response + | DocumentTranslationGetDocumentStatus429Response + | DocumentTranslationGetDocumentStatus500Response + | DocumentTranslationGetDocumentStatus503Response + | DocumentTranslationGetTranslationStatus401Response + | DocumentTranslationGetTranslationStatus404Response + | DocumentTranslationGetTranslationStatus429Response + | DocumentTranslationGetTranslationStatus500Response + | DocumentTranslationGetTranslationStatus503Response + | DocumentTranslationCancelTranslation401Response + | DocumentTranslationCancelTranslation404Response + | DocumentTranslationCancelTranslation429Response + | DocumentTranslationCancelTranslation500Response + | DocumentTranslationCancelTranslation503Response + | DocumentTranslationGetDocumentsStatus400Response + | DocumentTranslationGetDocumentsStatus401Response + | DocumentTranslationGetDocumentsStatus404Response + | DocumentTranslationGetDocumentsStatus429Response + | DocumentTranslationGetDocumentsStatus500Response + | DocumentTranslationGetDocumentsStatus503Response + | DocumentTranslationGetSupportedDocumentFormats429Response + | DocumentTranslationGetSupportedDocumentFormats500Response + | DocumentTranslationGetSupportedDocumentFormats503Response + | DocumentTranslationGetSupportedGlossaryFormats429Response + | DocumentTranslationGetSupportedGlossaryFormats500Response + | DocumentTranslationGetSupportedGlossaryFormats503Response + | DocumentTranslationGetSupportedStorageSources429Response + | DocumentTranslationGetSupportedStorageSources500Response + | DocumentTranslationGetSupportedStorageSources503Response { + const lroOriginal = response.headers["x-ms-original-url"]; + const url = new URL(lroOriginal ?? response.request.url); + const method = response.request.method; + let pathDetails = responseMap[`${method} ${url.pathname}`]; + if (!pathDetails) { + pathDetails = getParametrizedPathSuccess(method, url.pathname); + } + return !pathDetails.includes(response.status); +} + +function getParametrizedPathSuccess(method: string, path: string): string[] { + 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: string[] = []; + + // 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 (candidateParts[i]?.startsWith("{") && candidateParts[i]?.indexOf("}") !== -1) { + const start = candidateParts[i]!.indexOf("}") + 1, + end = candidateParts[i]?.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(`${candidateParts[i]?.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: string): string { + const pathStart = mapKey.indexOf("/"); + return mapKey.slice(pathStart); +} diff --git a/sdk/documenttranslator/ai-document-translator-rest/src/logger.ts b/sdk/documenttranslator/ai-document-translator-rest/src/logger.ts new file mode 100644 index 000000000000..0f5e8a7eb852 --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/src/logger.ts @@ -0,0 +1,5 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { createClientLogger } from "@azure/logger"; +export const logger = createClientLogger("ai-document-translator"); diff --git a/sdk/documenttranslator/ai-document-translator-rest/src/models.ts b/sdk/documenttranslator/ai-document-translator-rest/src/models.ts index a72b27877428..1a07bcabb050 100644 --- a/sdk/documenttranslator/ai-document-translator-rest/src/models.ts +++ b/sdk/documenttranslator/ai-document-translator-rest/src/models.ts @@ -1,24 +1,26 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +/** Translation job submission batch request */ export interface StartTranslationDetails { /** The input list of documents or folders containing documents */ - inputs: BatchRequest[]; + inputs: Array; } +/** Definition for the input batch translation request */ export interface BatchRequest { /** Source of the input documents */ source: SourceInput; /** Location of the destination for the output */ - targets: TargetInput[]; + targets: Array; /** Storage type of the input documents source string */ - storageType?: StorageInputType; + storageType?: "Folder" | "File"; } +/** Source of the input documents */ export interface SourceInput { /** Location of the folder / container or single file with your documents */ sourceUrl: string; - /** */ filter?: DocumentFilter; /** * Language code @@ -26,7 +28,7 @@ export interface SourceInput { */ language?: string; /** Storage Source */ - storageSource?: StorageSource; + storageSource?: "AzureBlob"; } export interface DocumentFilter { @@ -42,6 +44,7 @@ export interface DocumentFilter { suffix?: string; } +/** Destination for the finished translated documents */ export interface TargetInput { /** Location of the folder / container with your documents */ targetUrl: string; @@ -50,11 +53,12 @@ export interface TargetInput { /** Target Language */ language: string; /** List of Glossary */ - glossaries?: Glossary[]; + glossaries?: Array; /** Storage Source */ - storageSource?: StorageSource; + storageSource?: "AzureBlob"; } +/** Glossary / translation memory for the request */ export interface Glossary { /** * Location of the glossary. @@ -68,155 +72,5 @@ export interface Glossary { /** Optional Version. If not specified, default is used. */ version?: string; /** Storage Source */ - storageSource?: StorageSource; + storageSource?: "AzureBlob"; } - -export interface TranslationErrorResponse { - /** This contains an outer error with error code, message, details, target and an inner error with more descriptive details. */ - error?: TranslationError; -} - -export interface TranslationError { - /** Enums containing high level error codes. */ - code: TranslationErrorCode; - /** Gets high level error message. */ - message: string; - /** - * Gets the source of the error. - * For example it would be "documents" or "document id" in case of invalid document. - */ - target?: 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). - */ - innerError?: InnerTranslationError; -} - -export interface InnerTranslationError { - /** Gets code error string. */ - code: string; - /** Gets high level error message. */ - message: string; - /** - * Gets the source of the error. - * For example it would be "documents" or "document id" in case of invalid document. - */ - target?: 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). - */ - innerError?: InnerTranslationError; -} - -export interface TranslationsStatus { - /** The summary status of individual operation */ - value: TranslationStatus[]; - /** Url for the next page. Null if no more pages available */ - nextLink?: string; -} - -export interface TranslationStatus { - /** 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; - /** List of possible statuses for job or document */ - status: Status; - /** This contains an outer error with error code, message, details, target and an inner error with more descriptive details. */ - error?: TranslationError; - /** */ - summary: 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; - /** Total characters charged by the API */ - totalCharacterCharged: number; -} - -export interface DocumentStatus { - /** Location of the document or folder */ - path?: string; - /** Location of the source document */ - sourcePath: string; - /** Operation created date time */ - createdDateTimeUtc: Date; - /** Date time in which the operation's status has been updated */ - lastActionDateTimeUtc: Date; - /** List of possible statuses for job or document */ - status: Status; - /** To language */ - to: string; - /** This contains an outer error with error code, message, details, target and an inner error with more descriptive details. */ - error?: TranslationError; - /** Progress of the translation if available */ - progress: number; - /** Document Id */ - id: string; - /** Character charged by the API */ - characterCharged?: number; -} - -export interface DocumentsStatus { - /** The detail status of individual documents */ - value: DocumentStatus[]; - /** Url for the next page. Null if no more pages available */ - nextLink?: string; -} - -export interface SupportedFileFormats { - /** list of objects */ - value: 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[]; - /** Default version if none is specified */ - defaultVersion?: string; - /** Supported Version */ - versions?: string[]; -} - -export interface SupportedStorageSources { - /** list of objects */ - value: "AzureBlob"[]; -} - -export type StorageSource = "AzureBlob"; -export type StorageInputType = "Folder" | "File"; -export type TranslationErrorCode = - | "InvalidRequest" - | "InvalidArgument" - | "InternalServerError" - | "ServiceUnavailable" - | "ResourceNotFound" - | "Unauthorized" - | "RequestRateTooHigh"; -export type Status = - | "NotStarted" - | "Running" - | "Succeeded" - | "Failed" - | "Cancelled" - | "Cancelling" - | "ValidationFailed"; diff --git a/sdk/documenttranslator/ai-document-translator-rest/src/outputModels.ts b/sdk/documenttranslator/ai-document-translator-rest/src/outputModels.ts new file mode 100644 index 000000000000..9026ec3dc21c --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/src/outputModels.ts @@ -0,0 +1,177 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * 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 TranslationErrorResponseOutput { + /** This contains an outer error with error code, message, details, target and an inner error with more descriptive details. */ + error?: TranslationErrorOutput; +} + +/** This contains an outer error with error code, message, details, target and an inner error with more descriptive details. */ +export interface TranslationErrorOutput { + /** Enums containing high level error codes. */ + code: + | "InvalidRequest" + | "InvalidArgument" + | "InternalServerError" + | "ServiceUnavailable" + | "ResourceNotFound" + | "Unauthorized" + | "RequestRateTooHigh"; + /** Gets high level error message. */ + message: string; + /** + * Gets the source of the error. + * For example it would be "documents" or "document id" in case of invalid document. + */ + readonly target?: 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). + */ + innerError?: InnerTranslationErrorOutput; +} + +/** + * 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 InnerTranslationErrorOutput { + /** Gets code error string. */ + code: string; + /** Gets high level error message. */ + message: string; + /** + * Gets the source of the error. + * For example it would be "documents" or "document id" in case of invalid document. + */ + readonly target?: 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). + */ + innerError?: InnerTranslationErrorOutput; +} + +/** Translation job Status Response */ +export interface TranslationsStatusOutput { + /** The summary status of individual operation */ + value: Array; + /** Url for the next page. Null if no more pages available */ + "@nextLink"?: string; +} + +/** Translation job status response */ +export interface TranslationStatusOutput { + /** + * Id of the operation. + * + * Value may contain a UUID + */ + id: string; + /** Operation created date time */ + createdDateTimeUtc: string; + /** Date time in which the operation's status has been updated */ + lastActionDateTimeUtc: string; + /** List of possible statuses for job or document */ + status: + | "NotStarted" + | "Running" + | "Succeeded" + | "Failed" + | "Cancelled" + | "Cancelling" + | "ValidationFailed"; + /** This contains an outer error with error code, message, details, target and an inner error with more descriptive details. */ + error?: TranslationErrorOutput; + summary: StatusSummaryOutput; +} + +export interface StatusSummaryOutput { + /** 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; + /** Total characters charged by the API */ + totalCharacterCharged: number; +} + +/** Document Status Response */ +export interface DocumentStatusOutput { + /** Location of the document or folder */ + path?: string; + /** Location of the source document */ + sourcePath: string; + /** Operation created date time */ + createdDateTimeUtc: string; + /** Date time in which the operation's status has been updated */ + lastActionDateTimeUtc: string; + /** List of possible statuses for job or document */ + status: + | "NotStarted" + | "Running" + | "Succeeded" + | "Failed" + | "Cancelled" + | "Cancelling" + | "ValidationFailed"; + /** To language */ + to: string; + /** This contains an outer error with error code, message, details, target and an inner error with more descriptive details. */ + error?: TranslationErrorOutput; + /** Progress of the translation if available */ + progress: number; + /** + * Document Id + * + * Value may contain a UUID + */ + id: string; + /** Character charged by the API */ + characterCharged?: number; +} + +/** Documents Status Response */ +export interface DocumentsStatusOutput { + /** The detail status of individual documents */ + value: Array; + /** Url for the next page. Null if no more pages available */ + "@nextLink"?: string; +} + +/** Base type for List return in our api */ +export interface SupportedFileFormatsOutput { + /** list of objects */ + value: Array; +} + +export interface FileFormatOutput { + /** Name of the format */ + format: string; + /** Supported file extension for this format */ + fileExtensions: Array; + /** Supported Content-Types for this format */ + contentTypes: Array; + /** Default version if none is specified */ + defaultVersion?: string; + /** Supported Version */ + versions?: Array; +} + +/** Base type for List return in our api */ +export interface SupportedStorageSourcesOutput { + /** list of objects */ + value: Array<"AzureBlob">; +} diff --git a/sdk/documenttranslator/ai-document-translator-rest/src/paginateHelper.ts b/sdk/documenttranslator/ai-document-translator-rest/src/paginateHelper.ts new file mode 100644 index 000000000000..9ea946d9d6c5 --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/src/paginateHelper.ts @@ -0,0 +1,267 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import type { Client, PathUncheckedResponse } from "@azure-rest/core-client"; +import { createRestError } from "@azure-rest/core-client"; + +/** + * returns an async iterator that iterates over results. It also has a `byPage` + * method that returns pages of items at once. + * + * @param pagedResult - an object that specifies how to get pages. + * @returns a paged async iterator that iterates over results. + */ +function getPagedAsyncIterator< + TElement, + TPage = TElement[], + TPageSettings = PageSettings, + TLink = string, +>( + pagedResult: PagedResult, +): PagedAsyncIterableIterator { + const iter = getItemAsyncIterator(pagedResult); + return { + next() { + return iter.next(); + }, + [Symbol.asyncIterator]() { + return this; + }, + byPage: + pagedResult?.byPage ?? + (((settings?: PageSettings) => { + const { continuationToken } = settings ?? {}; + return getPageAsyncIterator(pagedResult, { + pageLink: continuationToken as unknown as TLink | undefined, + }); + }) as unknown as (settings?: TPageSettings) => AsyncIterableIterator), + }; +} + +async function* getItemAsyncIterator( + pagedResult: PagedResult, +): AsyncIterableIterator { + const pages = getPageAsyncIterator(pagedResult); + const firstVal = await pages.next(); + // if the result does not have an array shape, i.e. TPage = TElement, then we return it as is + if (!Array.isArray(firstVal.value)) { + // can extract elements from this page + const { toElements } = pagedResult; + if (toElements) { + yield* toElements(firstVal.value) as TElement[]; + for await (const page of pages) { + yield* toElements(page) as TElement[]; + } + } else { + yield firstVal.value; + // `pages` is of type `AsyncIterableIterator` but TPage = TElement in this case + yield* pages as unknown as AsyncIterableIterator; + } + } else { + yield* firstVal.value; + for await (const page of pages) { + // pages is of type `AsyncIterableIterator` so `page` is of type `TPage`. In this branch, + // it must be the case that `TPage = TElement[]` + yield* page as unknown as TElement[]; + } + } +} + +async function* getPageAsyncIterator( + pagedResult: PagedResult, + options: { + pageLink?: TLink; + } = {}, +): AsyncIterableIterator { + const { pageLink } = options; + let response = await pagedResult.getPage(pageLink ?? pagedResult.firstPageLink); + if (!response) { + return; + } + yield response.page; + while (response.nextPageLink) { + response = await pagedResult.getPage(response.nextPageLink); + if (!response) { + return; + } + yield response.page; + } +} + +/** + * An interface that tracks the settings for paged iteration + */ +export interface PageSettings { + /** + * The token that keeps track of where to continue the iterator + */ + continuationToken?: string; +} + +/** + * An interface that allows async iterable iteration both to completion and by page. + */ +export interface PagedAsyncIterableIterator< + TElement, + TPage = TElement[], + TPageSettings = PageSettings, +> { + /** + * The next method, part of the iteration protocol + */ + next(): Promise>; + /** + * The connection to the async iterator, part of the iteration protocol + */ + [Symbol.asyncIterator](): PagedAsyncIterableIterator; + /** + * Return an AsyncIterableIterator that works a page at a time + */ + byPage: (settings?: TPageSettings) => AsyncIterableIterator; +} + +/** + * An interface that describes how to communicate with the service. + */ +interface PagedResult { + /** + * Link to the first page of results. + */ + firstPageLink: TLink; + /** + * A method that returns a page of results. + */ + getPage: (pageLink: TLink) => Promise<{ page: TPage; nextPageLink?: TLink } | undefined>; + /** + * a function to implement the `byPage` method on the paged async iterator. + */ + byPage?: (settings?: TPageSettings) => AsyncIterableIterator; + + /** + * A function to extract elements from a page. + */ + toElements?: (page: TPage) => unknown[]; +} + +/** + * Helper type to extract the type of an array + */ +export type GetArrayType = T extends Array ? TData : never; + +/** + * The type of a custom function that defines how to get a page and a link to the next one if any. + */ +export type GetPage = (pageLink: string) => Promise<{ + page: TPage; + nextPageLink?: string; +}>; + +/** + * Options for the paging helper + */ +export interface PagingOptions { + /** + * Custom function to extract pagination details for crating the PagedAsyncIterableIterator + */ + customGetPage?: GetPage[]>; +} + +/** + * Helper type to infer the Type of the paged elements from the response type + * This type is generated based on the swagger information for x-ms-pageable + * specifically on the itemName property which indicates the property of the response + * where the page items are found. The default value is `value`. + * This type will allow us to provide strongly typed Iterator based on the response we get as second parameter + */ +export type PaginateReturn = TResult extends { + body: { value?: infer TPage }; +} + ? GetArrayType + : Array; + +/** + * Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension + * @param client - Client to use for sending the next page requests + * @param initialResponse - Initial response containing the nextLink and current page of elements + * @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results + * @returns - PagedAsyncIterableIterator to iterate the elements + */ +export function paginate( + client: Client, + initialResponse: TResponse, + options: PagingOptions = {}, +): PagedAsyncIterableIterator> { + // Extract element type from initial response + type TElement = PaginateReturn; + let firstRun = true; + const itemName = "value"; + const nextLinkName = "nextLink"; + const { customGetPage } = options; + const pagedResult: PagedResult = { + firstPageLink: "", + getPage: + typeof customGetPage === "function" + ? customGetPage + : async (pageLink: string) => { + const result = firstRun ? initialResponse : await client.pathUnchecked(pageLink).get(); + firstRun = false; + checkPagingRequest(result); + const nextLink = getNextLink(result.body, nextLinkName); + const values = getElements(result.body, itemName); + return { + page: values, + nextPageLink: nextLink, + }; + }, + }; + + return getPagedAsyncIterator(pagedResult); +} + +/** + * Gets for the value of nextLink in the body + */ +function getNextLink(body: unknown, nextLinkName?: string): string | undefined { + if (!nextLinkName) { + return undefined; + } + + const nextLink = (body as Record)[nextLinkName]; + + if (typeof nextLink !== "string" && typeof nextLink !== "undefined") { + throw new Error(`Body Property ${nextLinkName} should be a string or undefined`); + } + + return nextLink; +} + +/** + * Gets the elements of the current request in the body. + */ +function getElements(body: unknown, itemName: string): T[] { + const value = (body as Record)[itemName] as T[]; + + // value has to be an array according to the x-ms-pageable extension. + // The fact that this must be an array is used above to calculate the + // type of elements in the page in PaginateReturn + if (!Array.isArray(value)) { + throw new Error( + `Couldn't paginate response\n Body doesn't contain an array property with name: ${itemName}`, + ); + } + + return value ?? []; +} + +/** + * Checks if a request failed + */ +function checkPagingRequest(response: PathUncheckedResponse): void { + const Http2xxStatusCodes = ["200", "201", "202", "203", "204", "205", "206", "207", "208", "226"]; + if (!Http2xxStatusCodes.includes(response.status)) { + throw createRestError( + `Pagination failed with unexpected statusCode ${response.status}`, + response, + ); + } +} diff --git a/sdk/documenttranslator/ai-document-translator-rest/src/parameters.ts b/sdk/documenttranslator/ai-document-translator-rest/src/parameters.ts index d88aa204ca1f..605e6426b3eb 100644 --- a/sdk/documenttranslator/ai-document-translator-rest/src/parameters.ts +++ b/sdk/documenttranslator/ai-document-translator-rest/src/parameters.ts @@ -4,13 +4,22 @@ import type { RequestParameters } from "@azure-rest/core-client"; import type { StartTranslationDetails } from "./models.js"; -export interface StartTranslationBodyParam { +export interface DocumentTranslationStartTranslationBodyParam { + /** request details */ body: StartTranslationDetails; } -export type StartTranslationParameters = RequestParameters & StartTranslationBodyParam; +export interface DocumentTranslationStartTranslationMediaTypesParam { + /** Request content type */ + contentType?: "application/json" | "text/json" | "application/*+json"; +} + +export type DocumentTranslationStartTranslationParameters = + DocumentTranslationStartTranslationMediaTypesParam & + DocumentTranslationStartTranslationBodyParam & + RequestParameters; -export interface GetTranslationsStatusQueryParamProperties { +export interface DocumentTranslationGetTranslationsStatusQueryParamProperties { /** * $top indicates the total number of records the user wants to be returned across all pages. * @@ -30,33 +39,34 @@ export interface GetTranslationsStatusQueryParamProperties { */ $skip?: number; /** - * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), \@nextLink will contain the link to the next page. + * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), '\@nextLink' will contain the link to the next page. * * Clients MAY request server-driven paging with a specific page size by specifying a $maxpagesize preference. The server SHOULD honor this preference if the specified page size is smaller than the server's default page size. */ $maxpagesize?: number; /** Ids to use in filtering */ - ids?: string[]; + ids?: Array; /** Statuses to use in filtering */ - statuses?: string[]; + statuses?: Array; /** the start datetime to get items after */ - createdDateTimeUtcStart?: Date; + createdDateTimeUtcStart?: Date | string; /** the end datetime to get items before */ - createdDateTimeUtcEnd?: Date; + createdDateTimeUtcEnd?: Date | string; /** the sorting query for the collection (ex: 'CreatedDateTimeUtc asc', 'CreatedDateTimeUtc desc') */ - $orderBy?: string[]; + $orderBy?: Array; } -export interface GetTranslationsStatusQueryParam { - queryParameters?: GetTranslationsStatusQueryParamProperties; +export interface DocumentTranslationGetTranslationsStatusQueryParam { + queryParameters?: DocumentTranslationGetTranslationsStatusQueryParamProperties; } -export type GetTranslationsStatusParameters = RequestParameters & GetTranslationsStatusQueryParam; -export type GetDocumentStatusParameters = RequestParameters; -export type GetTranslationStatusParameters = RequestParameters; -export type CancelTranslationParameters = RequestParameters; +export type DocumentTranslationGetTranslationsStatusParameters = + DocumentTranslationGetTranslationsStatusQueryParam & RequestParameters; +export type DocumentTranslationGetDocumentStatusParameters = RequestParameters; +export type DocumentTranslationGetTranslationStatusParameters = RequestParameters; +export type DocumentTranslationCancelTranslationParameters = RequestParameters; -export interface GetDocumentsStatusQueryParamProperties { +export interface DocumentTranslationGetDocumentsStatusQueryParamProperties { /** * $top indicates the total number of records the user wants to be returned across all pages. * @@ -76,28 +86,29 @@ export interface GetDocumentsStatusQueryParamProperties { */ $skip?: number; /** - * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), \@nextLink will contain the link to the next page. + * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), '\@nextLink' will contain the link to the next page. * * Clients MAY request server-driven paging with a specific page size by specifying a $maxpagesize preference. The server SHOULD honor this preference if the specified page size is smaller than the server's default page size. */ $maxpagesize?: number; /** Ids to use in filtering */ - ids?: string[]; + ids?: Array; /** Statuses to use in filtering */ - statuses?: string[]; + statuses?: Array; /** the start datetime to get items after */ - createdDateTimeUtcStart?: Date; + createdDateTimeUtcStart?: Date | string; /** the end datetime to get items before */ - createdDateTimeUtcEnd?: Date; + createdDateTimeUtcEnd?: Date | string; /** the sorting query for the collection (ex: 'CreatedDateTimeUtc asc', 'CreatedDateTimeUtc desc') */ - $orderBy?: string[]; + $orderBy?: Array; } -export interface GetDocumentsStatusQueryParam { - queryParameters?: GetDocumentsStatusQueryParamProperties; +export interface DocumentTranslationGetDocumentsStatusQueryParam { + queryParameters?: DocumentTranslationGetDocumentsStatusQueryParamProperties; } -export type GetDocumentsStatusParameters = RequestParameters & GetDocumentsStatusQueryParam; -export type GetSupportedDocumentFormatsParameters = RequestParameters; -export type GetSupportedGlossaryFormatsParameters = RequestParameters; -export type GetSupportedStorageSourcesParameters = RequestParameters; +export type DocumentTranslationGetDocumentsStatusParameters = + DocumentTranslationGetDocumentsStatusQueryParam & RequestParameters; +export type DocumentTranslationGetSupportedDocumentFormatsParameters = RequestParameters; +export type DocumentTranslationGetSupportedGlossaryFormatsParameters = RequestParameters; +export type DocumentTranslationGetSupportedStorageSourcesParameters = RequestParameters; diff --git a/sdk/documenttranslator/ai-document-translator-rest/src/pollingHelper.ts b/sdk/documenttranslator/ai-document-translator-rest/src/pollingHelper.ts new file mode 100644 index 000000000000..a2668fc5d9c7 --- /dev/null +++ b/sdk/documenttranslator/ai-document-translator-rest/src/pollingHelper.ts @@ -0,0 +1,194 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import type { Client, HttpResponse } from "@azure-rest/core-client"; +import type { AbortSignalLike } from "@azure/abort-controller"; +import type { + CancelOnProgress, + CreateHttpPollerOptions, + RunningOperation, + OperationResponse, + OperationState, +} from "@azure/core-lro"; +import { createHttpPoller } from "@azure/core-lro"; + +/** + * A simple poller that can be used to poll a long running operation. + */ +export interface SimplePollerLike, TResult> { + /** + * Returns true if the poller has finished polling. + */ + isDone(): boolean; + /** + * Returns the state of the operation. + */ + getOperationState(): TState; + /** + * Returns the result value of the operation, + * regardless of the state of the poller. + * It can return undefined or an incomplete form of the final TResult value + * depending on the implementation. + */ + getResult(): TResult | undefined; + /** + * Returns a promise that will resolve once a single polling request finishes. + * It does this by calling the update method of the Poller's operation. + */ + poll(options?: { abortSignal?: AbortSignalLike }): Promise; + /** + * Returns a promise that will resolve once the underlying operation is completed. + */ + pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }): Promise; + /** + * Invokes the provided callback after each polling is completed, + * sending the current state of the poller's operation. + * + * It returns a method that can be used to stop receiving updates on the given callback function. + */ + onProgress(callback: (state: TState) => void): CancelOnProgress; + + /** + * Returns a promise that could be used for serialized version of the poller's operation + * by invoking the operation's serialize method. + */ + serialize(): Promise; + + /** + * Wait the poller to be submitted. + */ + submitted(): Promise; + + /** + * Returns a string representation of the poller's operation. Similar to serialize but returns a string. + * @deprecated Use serialize() instead. + */ + toString(): string; + + /** + * Stops the poller from continuing to poll. Please note this will only stop the client-side polling + * @deprecated Use abortSignal to stop polling instead. + */ + stopPolling(): void; + + /** + * Returns true if the poller is stopped. + * @deprecated Use abortSignal status to track this instead. + */ + isStopped(): boolean; +} + +/** + * Helper function that builds a Poller object to help polling a long running operation. + * @param client - Client to use for sending the request to get additional pages. + * @param initialResponse - The initial response. + * @param options - Options to set a resume state or custom polling interval. + * @returns - A poller object to poll for operation state updates and eventually get the final response. + */ +export async function getLongRunningPoller( + client: Client, + initialResponse: TResult, + options: CreateHttpPollerOptions> = {}, +): Promise, TResult>> { + const abortController = new AbortController(); + const poller: RunningOperation = { + sendInitialRequest: async () => { + // In the case of Rest Clients we are building the LRO poller object from a response that's the reason + // we are not triggering the initial request here, just extracting the information from the + // response we were provided. + return getLroResponse(initialResponse); + }, + sendPollRequest: async (path: string, pollOptions?: { abortSignal?: AbortSignalLike }) => { + // This is the callback that is going to be called to poll the service + // to get the latest status. We use the client provided and the polling path + // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location + // depending on the lro pattern that the service implements. If non is provided we default to the initial path. + function abortListener(): void { + abortController.abort(); + } + const inputAbortSignal = pollOptions?.abortSignal; + const abortSignal = abortController.signal; + if (inputAbortSignal?.aborted) { + abortController.abort(); + } else if (!abortSignal.aborted) { + inputAbortSignal?.addEventListener("abort", abortListener, { + once: true, + }); + } + let response; + try { + response = await client + .pathUnchecked(path ?? initialResponse.request.url) + .get({ abortSignal }); + } finally { + inputAbortSignal?.removeEventListener("abort", abortListener); + } + const lroResponse = getLroResponse(response as TResult); + lroResponse.rawResponse.headers["x-ms-original-url"] = initialResponse.request.url; + return lroResponse; + }, + }; + + options.resolveOnUnsuccessful = options.resolveOnUnsuccessful ?? true; + const httpPoller = createHttpPoller(poller, options); + const simplePoller: SimplePollerLike, TResult> = { + isDone() { + return httpPoller.isDone; + }, + isStopped() { + return abortController.signal.aborted; + }, + getOperationState() { + if (!httpPoller.operationState) { + throw new Error( + "Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().", + ); + } + return httpPoller.operationState; + }, + getResult() { + return httpPoller.result; + }, + toString() { + if (!httpPoller.operationState) { + throw new Error( + "Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().", + ); + } + return JSON.stringify({ + state: httpPoller.operationState, + }); + }, + stopPolling() { + abortController.abort(); + }, + onProgress: httpPoller.onProgress, + poll: httpPoller.poll, + pollUntilDone: httpPoller.pollUntilDone, + serialize: httpPoller.serialize, + submitted: httpPoller.submitted, + }; + return simplePoller; +} + +/** + * Converts a Rest Client response to a response that the LRO implementation understands + * @param response - a rest client http response + * @returns - An LRO response that the LRO implementation understands + */ +function getLroResponse( + response: TResult, +): OperationResponse { + if (Number.isNaN(response.status)) { + throw new TypeError(`Status code of the response is not a number. Value: ${response.status}`); + } + + return { + flatResponse: response, + rawResponse: { + ...response, + statusCode: Number.parseInt(response.status), + body: response.body, + }, + }; +} diff --git a/sdk/documenttranslator/ai-document-translator-rest/src/responses.ts b/sdk/documenttranslator/ai-document-translator-rest/src/responses.ts index 4f5b0b4f7122..0177e184c805 100644 --- a/sdk/documenttranslator/ai-document-translator-rest/src/responses.ts +++ b/sdk/documenttranslator/ai-document-translator-rest/src/responses.ts @@ -1,19 +1,19 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import type { - TranslationErrorResponse, - TranslationsStatus, - DocumentStatus, - TranslationStatus, - DocumentsStatus, - SupportedFileFormats, - SupportedStorageSources, -} from "./models.js"; -import type { HttpResponse } from "@azure-rest/core-client"; import type { RawHttpHeaders } from "@azure/core-rest-pipeline"; - -export interface StartTranslation202Headers { +import type { HttpResponse } from "@azure-rest/core-client"; +import type { + TranslationErrorResponseOutput, + TranslationsStatusOutput, + DocumentStatusOutput, + TranslationStatusOutput, + DocumentsStatusOutput, + SupportedFileFormatsOutput, + SupportedStorageSourcesOutput, +} from "./outputModels.js"; + +export interface DocumentTranslationStartTranslation202Headers { /** Location of batch the operation */ "operation-location"?: string; } @@ -29,9 +29,9 @@ export interface StartTranslation202Headers { * If the glossary is invalid or unreachable during translation, an error is indicated in the document status. * If a file with the same name already exists at the destination, it will be overwritten. The targetUrl for each target language must be unique. */ -export interface StartTranslation202Response extends HttpResponse { +export interface DocumentTranslationStartTranslation202Response extends HttpResponse { status: "202"; - headers: RawHttpHeaders & StartTranslation202Headers; + headers: RawHttpHeaders & DocumentTranslationStartTranslation202Headers; } /** @@ -45,9 +45,9 @@ export interface StartTranslation202Response extends HttpResponse { * If the glossary is invalid or unreachable during translation, an error is indicated in the document status. * If a file with the same name already exists at the destination, it will be overwritten. The targetUrl for each target language must be unique. */ -export interface StartTranslation400Response extends HttpResponse { +export interface DocumentTranslationStartTranslation400Response extends HttpResponse { status: "400"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -61,9 +61,9 @@ export interface StartTranslation400Response extends HttpResponse { * If the glossary is invalid or unreachable during translation, an error is indicated in the document status. * If a file with the same name already exists at the destination, it will be overwritten. The targetUrl for each target language must be unique. */ -export interface StartTranslation401Response extends HttpResponse { +export interface DocumentTranslationStartTranslation401Response extends HttpResponse { status: "401"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -77,9 +77,9 @@ export interface StartTranslation401Response extends HttpResponse { * If the glossary is invalid or unreachable during translation, an error is indicated in the document status. * If a file with the same name already exists at the destination, it will be overwritten. The targetUrl for each target language must be unique. */ -export interface StartTranslation429Response extends HttpResponse { +export interface DocumentTranslationStartTranslation429Response extends HttpResponse { status: "429"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -93,9 +93,9 @@ export interface StartTranslation429Response extends HttpResponse { * If the glossary is invalid or unreachable during translation, an error is indicated in the document status. * If a file with the same name already exists at the destination, it will be overwritten. The targetUrl for each target language must be unique. */ -export interface StartTranslation500Response extends HttpResponse { +export interface DocumentTranslationStartTranslation500Response extends HttpResponse { status: "500"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -109,14 +109,14 @@ export interface StartTranslation500Response extends HttpResponse { * If the glossary is invalid or unreachable during translation, an error is indicated in the document status. * If a file with the same name already exists at the destination, it will be overwritten. The targetUrl for each target language must be unique. */ -export interface StartTranslation503Response extends HttpResponse { +export interface DocumentTranslationStartTranslation503Response extends HttpResponse { status: "503"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } -export interface GetTranslationsStatus200Headers { +export interface DocumentTranslationGetTranslationsStatus200Headers { /** Indicates how long to wait before making a new request. */ - "retry-after"?: string; + "retry-after"?: 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; } @@ -132,7 +132,7 @@ export interface GetTranslationsStatus200Headers { * * $top indicates the total number of records the user wants to be returned across all pages. * $skip indicates the number of records to skip from the list of batches based on the sorting method specified. By default, we sort by descending start time. - * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), \@nextLink will contain the link to the next page. + * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), '\@nextLink' will contain the link to the next page. * * $orderBy query parameter can be used to sort the returned list (ex "$orderBy=createdDateTimeUtc asc" or "$orderBy=createdDateTimeUtc desc"). * The default sorting is descending by createdDateTimeUtc. @@ -146,10 +146,10 @@ export interface GetTranslationsStatus200Headers { * 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 reduces the risk of the client making assumptions about the data returned. */ -export interface GetTranslationsStatus200Response extends HttpResponse { +export interface DocumentTranslationGetTranslationsStatus200Response extends HttpResponse { status: "200"; - body: TranslationsStatus; - headers: RawHttpHeaders & GetTranslationsStatus200Headers; + body: TranslationsStatusOutput; + headers: RawHttpHeaders & DocumentTranslationGetTranslationsStatus200Headers; } /** @@ -163,7 +163,7 @@ export interface GetTranslationsStatus200Response extends HttpResponse { * * $top indicates the total number of records the user wants to be returned across all pages. * $skip indicates the number of records to skip from the list of batches based on the sorting method specified. By default, we sort by descending start time. - * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), \@nextLink will contain the link to the next page. + * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), '\@nextLink' will contain the link to the next page. * * $orderBy query parameter can be used to sort the returned list (ex "$orderBy=createdDateTimeUtc asc" or "$orderBy=createdDateTimeUtc desc"). * The default sorting is descending by createdDateTimeUtc. @@ -177,9 +177,9 @@ export interface GetTranslationsStatus200Response extends HttpResponse { * 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 reduces the risk of the client making assumptions about the data returned. */ -export interface GetTranslationsStatus400Response extends HttpResponse { +export interface DocumentTranslationGetTranslationsStatus400Response extends HttpResponse { status: "400"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -193,7 +193,7 @@ export interface GetTranslationsStatus400Response extends HttpResponse { * * $top indicates the total number of records the user wants to be returned across all pages. * $skip indicates the number of records to skip from the list of batches based on the sorting method specified. By default, we sort by descending start time. - * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), \@nextLink will contain the link to the next page. + * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), '\@nextLink' will contain the link to the next page. * * $orderBy query parameter can be used to sort the returned list (ex "$orderBy=createdDateTimeUtc asc" or "$orderBy=createdDateTimeUtc desc"). * The default sorting is descending by createdDateTimeUtc. @@ -207,9 +207,9 @@ export interface GetTranslationsStatus400Response extends HttpResponse { * 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 reduces the risk of the client making assumptions about the data returned. */ -export interface GetTranslationsStatus401Response extends HttpResponse { +export interface DocumentTranslationGetTranslationsStatus401Response extends HttpResponse { status: "401"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -223,7 +223,7 @@ export interface GetTranslationsStatus401Response extends HttpResponse { * * $top indicates the total number of records the user wants to be returned across all pages. * $skip indicates the number of records to skip from the list of batches based on the sorting method specified. By default, we sort by descending start time. - * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), \@nextLink will contain the link to the next page. + * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), '\@nextLink' will contain the link to the next page. * * $orderBy query parameter can be used to sort the returned list (ex "$orderBy=createdDateTimeUtc asc" or "$orderBy=createdDateTimeUtc desc"). * The default sorting is descending by createdDateTimeUtc. @@ -237,9 +237,9 @@ export interface GetTranslationsStatus401Response extends HttpResponse { * 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 reduces the risk of the client making assumptions about the data returned. */ -export interface GetTranslationsStatus429Response extends HttpResponse { +export interface DocumentTranslationGetTranslationsStatus429Response extends HttpResponse { status: "429"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -253,7 +253,7 @@ export interface GetTranslationsStatus429Response extends HttpResponse { * * $top indicates the total number of records the user wants to be returned across all pages. * $skip indicates the number of records to skip from the list of batches based on the sorting method specified. By default, we sort by descending start time. - * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), \@nextLink will contain the link to the next page. + * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), '\@nextLink' will contain the link to the next page. * * $orderBy query parameter can be used to sort the returned list (ex "$orderBy=createdDateTimeUtc asc" or "$orderBy=createdDateTimeUtc desc"). * The default sorting is descending by createdDateTimeUtc. @@ -267,9 +267,9 @@ export interface GetTranslationsStatus429Response extends HttpResponse { * 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 reduces the risk of the client making assumptions about the data returned. */ -export interface GetTranslationsStatus500Response extends HttpResponse { +export interface DocumentTranslationGetTranslationsStatus500Response extends HttpResponse { status: "500"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -283,7 +283,7 @@ export interface GetTranslationsStatus500Response extends HttpResponse { * * $top indicates the total number of records the user wants to be returned across all pages. * $skip indicates the number of records to skip from the list of batches based on the sorting method specified. By default, we sort by descending start time. - * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), \@nextLink will contain the link to the next page. + * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), '\@nextLink' will contain the link to the next page. * * $orderBy query parameter can be used to sort the returned list (ex "$orderBy=createdDateTimeUtc asc" or "$orderBy=createdDateTimeUtc desc"). * The default sorting is descending by createdDateTimeUtc. @@ -297,58 +297,58 @@ export interface GetTranslationsStatus500Response extends HttpResponse { * 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 reduces the risk of the client making assumptions about the data returned. */ -export interface GetTranslationsStatus503Response extends HttpResponse { +export interface DocumentTranslationGetTranslationsStatus503Response extends HttpResponse { status: "503"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } -export interface GetDocumentStatus200Headers { +export interface DocumentTranslationGetDocumentStatus200Headers { /** Indicates how long to wait before making a new request. */ - "retry-after"?: string; + "retry-after"?: 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; } /** Returns the translation status for a specific document based on the request Id and document Id. */ -export interface GetDocumentStatus200Response extends HttpResponse { +export interface DocumentTranslationGetDocumentStatus200Response extends HttpResponse { status: "200"; - body: DocumentStatus; - headers: RawHttpHeaders & GetDocumentStatus200Headers; + body: DocumentStatusOutput; + headers: RawHttpHeaders & DocumentTranslationGetDocumentStatus200Headers; } /** Returns the translation status for a specific document based on the request Id and document Id. */ -export interface GetDocumentStatus401Response extends HttpResponse { +export interface DocumentTranslationGetDocumentStatus401Response extends HttpResponse { status: "401"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** Returns the translation status for a specific document based on the request Id and document Id. */ -export interface GetDocumentStatus404Response extends HttpResponse { +export interface DocumentTranslationGetDocumentStatus404Response extends HttpResponse { status: "404"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** Returns the translation status for a specific document based on the request Id and document Id. */ -export interface GetDocumentStatus429Response extends HttpResponse { +export interface DocumentTranslationGetDocumentStatus429Response extends HttpResponse { status: "429"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** Returns the translation status for a specific document based on the request Id and document Id. */ -export interface GetDocumentStatus500Response extends HttpResponse { +export interface DocumentTranslationGetDocumentStatus500Response extends HttpResponse { status: "500"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** Returns the translation status for a specific document based on the request Id and document Id. */ -export interface GetDocumentStatus503Response extends HttpResponse { +export interface DocumentTranslationGetDocumentStatus503Response extends HttpResponse { status: "503"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } -export interface GetTranslationStatus200Headers { +export interface DocumentTranslationGetTranslationStatus200Headers { /** Indicates how long to wait before making a new request. */ - "retry-after"?: string; + "retry-after"?: 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; } @@ -357,55 +357,55 @@ export interface GetTranslationStatus200Headers { * Returns the status for a document translation request. * The status includes the overall request status, as well as the status for documents that are being translated as part of that request. */ -export interface GetTranslationStatus200Response extends HttpResponse { +export interface DocumentTranslationGetTranslationStatus200Response extends HttpResponse { status: "200"; - body: TranslationStatus; - headers: RawHttpHeaders & GetTranslationStatus200Headers; + body: TranslationStatusOutput; + headers: RawHttpHeaders & DocumentTranslationGetTranslationStatus200Headers; } /** * Returns the status for a document translation request. * The status includes the overall request status, as well as the status for documents that are being translated as part of that request. */ -export interface GetTranslationStatus401Response extends HttpResponse { +export interface DocumentTranslationGetTranslationStatus401Response extends HttpResponse { status: "401"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** * Returns the status for a document translation request. * The status includes the overall request status, as well as the status for documents that are being translated as part of that request. */ -export interface GetTranslationStatus404Response extends HttpResponse { +export interface DocumentTranslationGetTranslationStatus404Response extends HttpResponse { status: "404"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** * Returns the status for a document translation request. * The status includes the overall request status, as well as the status for documents that are being translated as part of that request. */ -export interface GetTranslationStatus429Response extends HttpResponse { +export interface DocumentTranslationGetTranslationStatus429Response extends HttpResponse { status: "429"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** * Returns the status for a document translation request. * The status includes the overall request status, as well as the status for documents that are being translated as part of that request. */ -export interface GetTranslationStatus500Response extends HttpResponse { +export interface DocumentTranslationGetTranslationStatus500Response extends HttpResponse { status: "500"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** * Returns the status for a document translation request. * The status includes the overall request status, as well as the status for documents that are being translated as part of that request. */ -export interface GetTranslationStatus503Response extends HttpResponse { +export interface DocumentTranslationGetTranslationStatus503Response extends HttpResponse { status: "503"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -415,9 +415,9 @@ export interface GetTranslationStatus503Response extends HttpResponse { * All documents that have completed translation will not be cancelled and will be charged. * All pending documents will be cancelled if possible. */ -export interface CancelTranslation200Response extends HttpResponse { +export interface DocumentTranslationCancelTranslation200Response extends HttpResponse { status: "200"; - body: TranslationStatus; + body: TranslationStatusOutput; } /** @@ -427,9 +427,9 @@ export interface CancelTranslation200Response extends HttpResponse { * All documents that have completed translation will not be cancelled and will be charged. * All pending documents will be cancelled if possible. */ -export interface CancelTranslation401Response extends HttpResponse { +export interface DocumentTranslationCancelTranslation401Response extends HttpResponse { status: "401"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -439,9 +439,9 @@ export interface CancelTranslation401Response extends HttpResponse { * All documents that have completed translation will not be cancelled and will be charged. * All pending documents will be cancelled if possible. */ -export interface CancelTranslation404Response extends HttpResponse { +export interface DocumentTranslationCancelTranslation404Response extends HttpResponse { status: "404"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -451,9 +451,9 @@ export interface CancelTranslation404Response extends HttpResponse { * All documents that have completed translation will not be cancelled and will be charged. * All pending documents will be cancelled if possible. */ -export interface CancelTranslation429Response extends HttpResponse { +export interface DocumentTranslationCancelTranslation429Response extends HttpResponse { status: "429"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -463,9 +463,9 @@ export interface CancelTranslation429Response extends HttpResponse { * All documents that have completed translation will not be cancelled and will be charged. * All pending documents will be cancelled if possible. */ -export interface CancelTranslation500Response extends HttpResponse { +export interface DocumentTranslationCancelTranslation500Response extends HttpResponse { status: "500"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -475,14 +475,14 @@ export interface CancelTranslation500Response extends HttpResponse { * All documents that have completed translation will not be cancelled and will be charged. * All pending documents will be cancelled if possible. */ -export interface CancelTranslation503Response extends HttpResponse { +export interface DocumentTranslationCancelTranslation503Response extends HttpResponse { status: "503"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } -export interface GetDocumentsStatus200Headers { +export interface DocumentTranslationGetDocumentsStatus200Headers { /** Indicates how long to wait before making a new request. */ - "retry-after"?: string; + "retry-after"?: 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; } @@ -497,7 +497,7 @@ export interface GetDocumentsStatus200Headers { * * $top indicates the total number of records the user wants to be returned across all pages. * $skip indicates the number of records to skip from the list of document status held by the server based on the sorting method specified. By default, we sort by descending start time. - * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), \@nextLink will contain the link to the next page. + * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), '\@nextLink' will contain the link to the next page. * * $orderBy query parameter can be used to sort the returned list (ex "$orderBy=createdDateTimeUtc asc" or "$orderBy=createdDateTimeUtc desc"). * The default sorting is descending by createdDateTimeUtc. @@ -509,10 +509,10 @@ export interface GetDocumentsStatus200Headers { * 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 reduces the risk of the client making assumptions about the data returned. */ -export interface GetDocumentsStatus200Response extends HttpResponse { +export interface DocumentTranslationGetDocumentsStatus200Response extends HttpResponse { status: "200"; - body: DocumentsStatus; - headers: RawHttpHeaders & GetDocumentsStatus200Headers; + body: DocumentsStatusOutput; + headers: RawHttpHeaders & DocumentTranslationGetDocumentsStatus200Headers; } /** @@ -525,7 +525,7 @@ export interface GetDocumentsStatus200Response extends HttpResponse { * * $top indicates the total number of records the user wants to be returned across all pages. * $skip indicates the number of records to skip from the list of document status held by the server based on the sorting method specified. By default, we sort by descending start time. - * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), \@nextLink will contain the link to the next page. + * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), '\@nextLink' will contain the link to the next page. * * $orderBy query parameter can be used to sort the returned list (ex "$orderBy=createdDateTimeUtc asc" or "$orderBy=createdDateTimeUtc desc"). * The default sorting is descending by createdDateTimeUtc. @@ -537,9 +537,9 @@ export interface GetDocumentsStatus200Response extends HttpResponse { * 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 reduces the risk of the client making assumptions about the data returned. */ -export interface GetDocumentsStatus400Response extends HttpResponse { +export interface DocumentTranslationGetDocumentsStatus400Response extends HttpResponse { status: "400"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -552,7 +552,7 @@ export interface GetDocumentsStatus400Response extends HttpResponse { * * $top indicates the total number of records the user wants to be returned across all pages. * $skip indicates the number of records to skip from the list of document status held by the server based on the sorting method specified. By default, we sort by descending start time. - * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), \@nextLink will contain the link to the next page. + * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), '\@nextLink' will contain the link to the next page. * * $orderBy query parameter can be used to sort the returned list (ex "$orderBy=createdDateTimeUtc asc" or "$orderBy=createdDateTimeUtc desc"). * The default sorting is descending by createdDateTimeUtc. @@ -564,9 +564,9 @@ export interface GetDocumentsStatus400Response extends HttpResponse { * 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 reduces the risk of the client making assumptions about the data returned. */ -export interface GetDocumentsStatus401Response extends HttpResponse { +export interface DocumentTranslationGetDocumentsStatus401Response extends HttpResponse { status: "401"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -579,7 +579,7 @@ export interface GetDocumentsStatus401Response extends HttpResponse { * * $top indicates the total number of records the user wants to be returned across all pages. * $skip indicates the number of records to skip from the list of document status held by the server based on the sorting method specified. By default, we sort by descending start time. - * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), \@nextLink will contain the link to the next page. + * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), '\@nextLink' will contain the link to the next page. * * $orderBy query parameter can be used to sort the returned list (ex "$orderBy=createdDateTimeUtc asc" or "$orderBy=createdDateTimeUtc desc"). * The default sorting is descending by createdDateTimeUtc. @@ -591,9 +591,9 @@ export interface GetDocumentsStatus401Response extends HttpResponse { * 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 reduces the risk of the client making assumptions about the data returned. */ -export interface GetDocumentsStatus404Response extends HttpResponse { +export interface DocumentTranslationGetDocumentsStatus404Response extends HttpResponse { status: "404"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -606,7 +606,7 @@ export interface GetDocumentsStatus404Response extends HttpResponse { * * $top indicates the total number of records the user wants to be returned across all pages. * $skip indicates the number of records to skip from the list of document status held by the server based on the sorting method specified. By default, we sort by descending start time. - * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), \@nextLink will contain the link to the next page. + * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), '\@nextLink' will contain the link to the next page. * * $orderBy query parameter can be used to sort the returned list (ex "$orderBy=createdDateTimeUtc asc" or "$orderBy=createdDateTimeUtc desc"). * The default sorting is descending by createdDateTimeUtc. @@ -618,9 +618,9 @@ export interface GetDocumentsStatus404Response extends HttpResponse { * 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 reduces the risk of the client making assumptions about the data returned. */ -export interface GetDocumentsStatus429Response extends HttpResponse { +export interface DocumentTranslationGetDocumentsStatus429Response extends HttpResponse { status: "429"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -633,7 +633,7 @@ export interface GetDocumentsStatus429Response extends HttpResponse { * * $top indicates the total number of records the user wants to be returned across all pages. * $skip indicates the number of records to skip from the list of document status held by the server based on the sorting method specified. By default, we sort by descending start time. - * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), \@nextLink will contain the link to the next page. + * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), '\@nextLink' will contain the link to the next page. * * $orderBy query parameter can be used to sort the returned list (ex "$orderBy=createdDateTimeUtc asc" or "$orderBy=createdDateTimeUtc desc"). * The default sorting is descending by createdDateTimeUtc. @@ -645,9 +645,9 @@ export interface GetDocumentsStatus429Response extends HttpResponse { * 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 reduces the risk of the client making assumptions about the data returned. */ -export interface GetDocumentsStatus500Response extends HttpResponse { +export interface DocumentTranslationGetDocumentsStatus500Response extends HttpResponse { status: "500"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** @@ -660,7 +660,7 @@ export interface GetDocumentsStatus500Response extends HttpResponse { * * $top indicates the total number of records the user wants to be returned across all pages. * $skip indicates the number of records to skip from the list of document status held by the server based on the sorting method specified. By default, we sort by descending start time. - * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), \@nextLink will contain the link to the next page. + * $maxpagesize is the maximum items returned in a page. If more items are requested via $top (or $top is not specified and there are more items to be returned), '\@nextLink' will contain the link to the next page. * * $orderBy query parameter can be used to sort the returned list (ex "$orderBy=createdDateTimeUtc asc" or "$orderBy=createdDateTimeUtc desc"). * The default sorting is descending by createdDateTimeUtc. @@ -672,121 +672,121 @@ export interface GetDocumentsStatus500Response extends HttpResponse { * 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 reduces the risk of the client making assumptions about the data returned. */ -export interface GetDocumentsStatus503Response extends HttpResponse { +export interface DocumentTranslationGetDocumentsStatus503Response extends HttpResponse { status: "503"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } -export interface GetSupportedDocumentFormats200Headers { +export interface DocumentTranslationGetSupportedDocumentFormats200Headers { /** Indicates how long to wait before making a new request. */ - "retry-after"?: string; + "retry-after"?: number; } /** * The list of supported document formats supported by the Document Translation service. * The list includes the common file extension, as well as the content-type if using the upload API. */ -export interface GetSupportedDocumentFormats200Response extends HttpResponse { +export interface DocumentTranslationGetSupportedDocumentFormats200Response extends HttpResponse { status: "200"; - body: SupportedFileFormats; - headers: RawHttpHeaders & GetSupportedDocumentFormats200Headers; + body: SupportedFileFormatsOutput; + headers: RawHttpHeaders & DocumentTranslationGetSupportedDocumentFormats200Headers; } /** * The list of supported document formats supported by the Document Translation service. * The list includes the common file extension, as well as the content-type if using the upload API. */ -export interface GetSupportedDocumentFormats429Response extends HttpResponse { +export interface DocumentTranslationGetSupportedDocumentFormats429Response extends HttpResponse { status: "429"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** * The list of supported document formats supported by the Document Translation service. * The list includes the common file extension, as well as the content-type if using the upload API. */ -export interface GetSupportedDocumentFormats500Response extends HttpResponse { +export interface DocumentTranslationGetSupportedDocumentFormats500Response extends HttpResponse { status: "500"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** * The list of supported document formats supported by the Document Translation service. * The list includes the common file extension, as well as the content-type if using the upload API. */ -export interface GetSupportedDocumentFormats503Response extends HttpResponse { +export interface DocumentTranslationGetSupportedDocumentFormats503Response extends HttpResponse { status: "503"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } -export interface GetSupportedGlossaryFormats200Headers { +export interface DocumentTranslationGetSupportedGlossaryFormats200Headers { /** Indicates how long to wait before making a new request. */ - "retry-after"?: string; + "retry-after"?: number; } /** * The list of supported glossary formats supported by the Document Translation service. * The list includes the common file extension used. */ -export interface GetSupportedGlossaryFormats200Response extends HttpResponse { +export interface DocumentTranslationGetSupportedGlossaryFormats200Response extends HttpResponse { status: "200"; - body: SupportedFileFormats; - headers: RawHttpHeaders & GetSupportedGlossaryFormats200Headers; + body: SupportedFileFormatsOutput; + headers: RawHttpHeaders & DocumentTranslationGetSupportedGlossaryFormats200Headers; } /** * The list of supported glossary formats supported by the Document Translation service. * The list includes the common file extension used. */ -export interface GetSupportedGlossaryFormats429Response extends HttpResponse { +export interface DocumentTranslationGetSupportedGlossaryFormats429Response extends HttpResponse { status: "429"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** * The list of supported glossary formats supported by the Document Translation service. * The list includes the common file extension used. */ -export interface GetSupportedGlossaryFormats500Response extends HttpResponse { +export interface DocumentTranslationGetSupportedGlossaryFormats500Response extends HttpResponse { status: "500"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** * The list of supported glossary formats supported by the Document Translation service. * The list includes the common file extension used. */ -export interface GetSupportedGlossaryFormats503Response extends HttpResponse { +export interface DocumentTranslationGetSupportedGlossaryFormats503Response extends HttpResponse { status: "503"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } -export interface GetSupportedStorageSources200Headers { +export interface DocumentTranslationGetSupportedStorageSources200Headers { /** Indicates how long to wait before making a new request. */ - "retry-after"?: string; + "retry-after"?: number; } /** Returns a list of storage sources/options supported by the Document Translation service. */ -export interface GetSupportedStorageSources200Response extends HttpResponse { +export interface DocumentTranslationGetSupportedStorageSources200Response extends HttpResponse { status: "200"; - body: SupportedStorageSources; - headers: RawHttpHeaders & GetSupportedStorageSources200Headers; + body: SupportedStorageSourcesOutput; + headers: RawHttpHeaders & DocumentTranslationGetSupportedStorageSources200Headers; } /** Returns a list of storage sources/options supported by the Document Translation service. */ -export interface GetSupportedStorageSources429Response extends HttpResponse { +export interface DocumentTranslationGetSupportedStorageSources429Response extends HttpResponse { status: "429"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** Returns a list of storage sources/options supported by the Document Translation service. */ -export interface GetSupportedStorageSources500Response extends HttpResponse { +export interface DocumentTranslationGetSupportedStorageSources500Response extends HttpResponse { status: "500"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } /** Returns a list of storage sources/options supported by the Document Translation service. */ -export interface GetSupportedStorageSources503Response extends HttpResponse { +export interface DocumentTranslationGetSupportedStorageSources503Response extends HttpResponse { status: "503"; - body: TranslationErrorResponse; + body: TranslationErrorResponseOutput; } diff --git a/sdk/documenttranslator/ai-document-translator-rest/swagger/README.md b/sdk/documenttranslator/ai-document-translator-rest/swagger/README.md index a80832d44f87..9314dee1adc3 100644 --- a/sdk/documenttranslator/ai-document-translator-rest/swagger/README.md +++ b/sdk/documenttranslator/ai-document-translator-rest/swagger/README.md @@ -5,6 +5,9 @@ ## Configuration ```yaml +flavor: azure +openapi-type: data-plane +generate-test: true package-name: "@azure-rest/ai-document-translator" title: DocumentTranslator description: Document Translator Client @@ -12,13 +15,13 @@ generate-metadata: false license-header: MICROSOFT_MIT_NO_VERSION output-folder: ../ source-code-folder-path: ./src -input-file: https://github.com/Azure/azure-rest-api-specs/blob/ebbdda9f9ba6cab2fbd4efccad59019a62649ea6/specification/cognitiveservices/data-plane/TranslatorText/preview/v1.0-preview.1/TranslatorBatch.json +input-file: https://github.com/Azure/azure-rest-api-specs/blob/ebbdda9f9ba6cab2fbd4efccad59019a62649ea6/specification/cognitiveservices/data-plane/TranslatorText/stable/v1.0/TranslatorBatch.json package-version: 1.0.0-beta.2 hide-clients: true -low-level-client: true +rest-level-client: true add-credentials: true credential-scopes: "https://cognitiveservices.azure.com/.default" credential-key-header-name: "Ocp-Apim-Subscription-Key" use-extension: - "@autorest/typescript": "https://aka.ms/azsdk/typescript/rlc" + "@autorest/typescript": "latest" ```