@azure-rest/ai-document-translator 1.0.0-beta.1 → 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +3 -3
- package/README.md +52 -71
- package/dist/browser/clientDefinitions.d.ts +125 -0
- package/dist/browser/clientDefinitions.d.ts.map +1 -0
- package/dist/browser/clientDefinitions.js +4 -0
- package/dist/browser/clientDefinitions.js.map +1 -0
- package/dist/browser/documentTranslator.d.ts +14 -0
- package/dist/browser/documentTranslator.d.ts.map +1 -0
- package/dist/browser/documentTranslator.js +33 -0
- package/dist/browser/documentTranslator.js.map +1 -0
- package/dist/browser/index.d.ts +12 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +14 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/isUnexpected.d.ts +11 -0
- package/dist/browser/isUnexpected.d.ts.map +1 -0
- package/dist/browser/isUnexpected.js +78 -0
- package/dist/browser/isUnexpected.js.map +1 -0
- package/dist/browser/logger.d.ts +2 -0
- package/dist/browser/logger.d.ts.map +1 -0
- package/dist/browser/logger.js +5 -0
- package/dist/browser/logger.js.map +1 -0
- package/dist/browser/models.d.ts +69 -0
- package/dist/browser/models.d.ts.map +1 -0
- package/dist/browser/models.js +4 -0
- package/dist/browser/models.js.map +1 -0
- package/dist/browser/outputModels.d.ts +144 -0
- package/dist/browser/outputModels.d.ts.map +1 -0
- package/dist/browser/outputModels.js +4 -0
- package/dist/browser/outputModels.js.map +1 -0
- package/dist/browser/package.json +3 -0
- package/dist/browser/paginateHelper.d.ts +68 -0
- package/dist/browser/paginateHelper.d.ts.map +1 -0
- package/dist/browser/paginateHelper.js +167 -0
- package/dist/browser/paginateHelper.js.map +1 -0
- package/dist/browser/parameters.d.ts +98 -0
- package/dist/browser/parameters.d.ts.map +1 -0
- package/dist/browser/parameters.js +4 -0
- package/dist/browser/parameters.js.map +1 -0
- package/dist/browser/pollingHelper.d.ts +76 -0
- package/dist/browser/pollingHelper.d.ts.map +1 -0
- package/dist/browser/pollingHelper.js +104 -0
- package/dist/browser/pollingHelper.js.map +1 -0
- package/{types/ai-document-translator.d.ts → dist/browser/responses.d.ts} +725 -1242
- package/dist/browser/responses.d.ts.map +1 -0
- package/dist/browser/responses.js +4 -0
- package/dist/browser/responses.js.map +1 -0
- package/dist/commonjs/clientDefinitions.d.ts +125 -0
- package/dist/commonjs/clientDefinitions.d.ts.map +1 -0
- package/dist/commonjs/clientDefinitions.js +5 -0
- package/dist/commonjs/clientDefinitions.js.map +1 -0
- package/dist/commonjs/documentTranslator.d.ts +14 -0
- package/dist/commonjs/documentTranslator.d.ts.map +1 -0
- package/dist/commonjs/documentTranslator.js +36 -0
- package/dist/commonjs/documentTranslator.js.map +1 -0
- package/dist/commonjs/index.d.ts +12 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +17 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/isUnexpected.d.ts +11 -0
- package/dist/commonjs/isUnexpected.d.ts.map +1 -0
- package/dist/commonjs/isUnexpected.js +81 -0
- package/dist/commonjs/isUnexpected.js.map +1 -0
- package/dist/commonjs/logger.d.ts +2 -0
- package/dist/commonjs/logger.d.ts.map +1 -0
- package/dist/commonjs/logger.js +8 -0
- package/dist/commonjs/logger.js.map +1 -0
- package/dist/commonjs/models.d.ts +69 -0
- package/dist/commonjs/models.d.ts.map +1 -0
- package/dist/commonjs/models.js +5 -0
- package/dist/commonjs/models.js.map +1 -0
- package/dist/commonjs/outputModels.d.ts +144 -0
- package/dist/commonjs/outputModels.d.ts.map +1 -0
- package/dist/commonjs/outputModels.js +5 -0
- package/dist/commonjs/outputModels.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/paginateHelper.d.ts +68 -0
- package/dist/commonjs/paginateHelper.d.ts.map +1 -0
- package/dist/commonjs/paginateHelper.js +170 -0
- package/dist/commonjs/paginateHelper.js.map +1 -0
- package/dist/commonjs/parameters.d.ts +98 -0
- package/dist/commonjs/parameters.d.ts.map +1 -0
- package/dist/commonjs/parameters.js +5 -0
- package/dist/commonjs/parameters.js.map +1 -0
- package/dist/commonjs/pollingHelper.d.ts +76 -0
- package/dist/commonjs/pollingHelper.d.ts.map +1 -0
- package/dist/commonjs/pollingHelper.js +107 -0
- package/dist/commonjs/pollingHelper.js.map +1 -0
- package/dist/commonjs/responses.d.ts +725 -0
- package/dist/commonjs/responses.d.ts.map +1 -0
- package/dist/commonjs/responses.js +5 -0
- package/dist/commonjs/responses.js.map +1 -0
- package/dist/commonjs/tsdoc-metadata.json +11 -0
- package/dist/esm/clientDefinitions.d.ts +125 -0
- package/dist/esm/clientDefinitions.d.ts.map +1 -0
- package/dist/esm/clientDefinitions.js +4 -0
- package/dist/esm/clientDefinitions.js.map +1 -0
- package/dist/esm/documentTranslator.d.ts +14 -0
- package/dist/esm/documentTranslator.d.ts.map +1 -0
- package/dist/esm/documentTranslator.js +33 -0
- package/dist/esm/documentTranslator.js.map +1 -0
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/isUnexpected.d.ts +11 -0
- package/dist/esm/isUnexpected.d.ts.map +1 -0
- package/dist/esm/isUnexpected.js +78 -0
- package/dist/esm/isUnexpected.js.map +1 -0
- package/dist/esm/logger.d.ts +2 -0
- package/dist/esm/logger.d.ts.map +1 -0
- package/dist/esm/logger.js +5 -0
- package/dist/esm/logger.js.map +1 -0
- package/dist/esm/models.d.ts +69 -0
- package/dist/esm/models.d.ts.map +1 -0
- package/dist/esm/models.js +4 -0
- package/dist/esm/models.js.map +1 -0
- package/dist/esm/outputModels.d.ts +144 -0
- package/dist/esm/outputModels.d.ts.map +1 -0
- package/dist/esm/outputModels.js +4 -0
- package/dist/esm/outputModels.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/paginateHelper.d.ts +68 -0
- package/dist/esm/paginateHelper.d.ts.map +1 -0
- package/dist/esm/paginateHelper.js +167 -0
- package/dist/esm/paginateHelper.js.map +1 -0
- package/dist/esm/parameters.d.ts +98 -0
- package/dist/esm/parameters.d.ts.map +1 -0
- package/dist/esm/parameters.js +4 -0
- package/dist/esm/parameters.js.map +1 -0
- package/dist/esm/pollingHelper.d.ts +76 -0
- package/dist/esm/pollingHelper.d.ts.map +1 -0
- package/dist/esm/pollingHelper.js +104 -0
- package/dist/esm/pollingHelper.js.map +1 -0
- package/dist/esm/responses.d.ts +725 -0
- package/dist/esm/responses.d.ts.map +1 -0
- package/dist/esm/responses.js +4 -0
- package/dist/esm/responses.js.map +1 -0
- package/dist/react-native/clientDefinitions.d.ts +125 -0
- package/dist/react-native/clientDefinitions.d.ts.map +1 -0
- package/dist/react-native/clientDefinitions.js +4 -0
- package/dist/react-native/clientDefinitions.js.map +1 -0
- package/dist/react-native/documentTranslator.d.ts +14 -0
- package/dist/react-native/documentTranslator.d.ts.map +1 -0
- package/dist/react-native/documentTranslator.js +33 -0
- package/dist/react-native/documentTranslator.js.map +1 -0
- package/dist/react-native/index.d.ts +12 -0
- package/dist/react-native/index.d.ts.map +1 -0
- package/dist/react-native/index.js +14 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/react-native/isUnexpected.d.ts +11 -0
- package/dist/react-native/isUnexpected.d.ts.map +1 -0
- package/dist/react-native/isUnexpected.js +78 -0
- package/dist/react-native/isUnexpected.js.map +1 -0
- package/dist/react-native/logger.d.ts +2 -0
- package/dist/react-native/logger.d.ts.map +1 -0
- package/dist/react-native/logger.js +5 -0
- package/dist/react-native/logger.js.map +1 -0
- package/dist/react-native/models.d.ts +69 -0
- package/dist/react-native/models.d.ts.map +1 -0
- package/dist/react-native/models.js +4 -0
- package/dist/react-native/models.js.map +1 -0
- package/dist/react-native/outputModels.d.ts +144 -0
- package/dist/react-native/outputModels.d.ts.map +1 -0
- package/dist/react-native/outputModels.js +4 -0
- package/dist/react-native/outputModels.js.map +1 -0
- package/dist/react-native/package.json +3 -0
- package/dist/react-native/paginateHelper.d.ts +68 -0
- package/dist/react-native/paginateHelper.d.ts.map +1 -0
- package/dist/react-native/paginateHelper.js +167 -0
- package/dist/react-native/paginateHelper.js.map +1 -0
- package/dist/react-native/parameters.d.ts +98 -0
- package/dist/react-native/parameters.d.ts.map +1 -0
- package/dist/react-native/parameters.js +4 -0
- package/dist/react-native/parameters.js.map +1 -0
- package/dist/react-native/pollingHelper.d.ts +76 -0
- package/dist/react-native/pollingHelper.d.ts.map +1 -0
- package/dist/react-native/pollingHelper.js +104 -0
- package/dist/react-native/pollingHelper.js.map +1 -0
- package/dist/react-native/responses.d.ts +725 -0
- package/dist/react-native/responses.d.ts.map +1 -0
- package/dist/react-native/responses.js +4 -0
- package/dist/react-native/responses.js.map +1 -0
- package/package.json +86 -71
- package/CHANGELOG.md +0 -5
- package/dist/index.js +0 -19
- package/dist/index.js.map +0 -1
- package/dist-esm/src/constants.js +0 -7
- package/dist-esm/src/constants.js.map +0 -1
- package/dist-esm/src/documentTranslator.js +0 -13
- package/dist-esm/src/documentTranslator.js.map +0 -1
- package/dist-esm/src/index.js +0 -13
- package/dist-esm/src/index.js.map +0 -1
- package/dist-esm/src/models.js +0 -4
- package/dist-esm/src/models.js.map +0 -1
- package/dist-esm/src/parameters.js +0 -4
- package/dist-esm/src/parameters.js.map +0 -1
- package/dist-esm/src/responses.js +0 -4
- package/dist-esm/src/responses.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,MAAM,qCAA+C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.logger = void 0;
|
|
6
|
+
const logger_1 = require("@azure/logger");
|
|
7
|
+
exports.logger = (0, logger_1.createClientLogger)("ai-document-translator");
|
|
8
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,0CAAmD;AACtC,QAAA,MAAM,GAAG,IAAA,2BAAkB,EAAC,wBAAwB,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { createClientLogger } from \"@azure/logger\";\nexport const logger = createClientLogger(\"ai-document-translator\");\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** Translation job submission batch request */
|
|
2
|
+
export interface StartTranslationDetails {
|
|
3
|
+
/** The input list of documents or folders containing documents */
|
|
4
|
+
inputs: Array<BatchRequest>;
|
|
5
|
+
}
|
|
6
|
+
/** Definition for the input batch translation request */
|
|
7
|
+
export interface BatchRequest {
|
|
8
|
+
/** Source of the input documents */
|
|
9
|
+
source: SourceInput;
|
|
10
|
+
/** Location of the destination for the output */
|
|
11
|
+
targets: Array<TargetInput>;
|
|
12
|
+
/** Storage type of the input documents source string */
|
|
13
|
+
storageType?: "Folder" | "File";
|
|
14
|
+
}
|
|
15
|
+
/** Source of the input documents */
|
|
16
|
+
export interface SourceInput {
|
|
17
|
+
/** Location of the folder / container or single file with your documents */
|
|
18
|
+
sourceUrl: string;
|
|
19
|
+
filter?: DocumentFilter;
|
|
20
|
+
/**
|
|
21
|
+
* Language code
|
|
22
|
+
* If none is specified, we will perform auto detect on the document
|
|
23
|
+
*/
|
|
24
|
+
language?: string;
|
|
25
|
+
/** Storage Source */
|
|
26
|
+
storageSource?: "AzureBlob";
|
|
27
|
+
}
|
|
28
|
+
export interface DocumentFilter {
|
|
29
|
+
/**
|
|
30
|
+
* A case-sensitive prefix string to filter documents in the source path for translation.
|
|
31
|
+
* For example, when using a Azure storage blob Uri, use the prefix to restrict sub folders for translation.
|
|
32
|
+
*/
|
|
33
|
+
prefix?: string;
|
|
34
|
+
/**
|
|
35
|
+
* A case-sensitive suffix string to filter documents in the source path for translation.
|
|
36
|
+
* This is most often use for file extensions
|
|
37
|
+
*/
|
|
38
|
+
suffix?: string;
|
|
39
|
+
}
|
|
40
|
+
/** Destination for the finished translated documents */
|
|
41
|
+
export interface TargetInput {
|
|
42
|
+
/** Location of the folder / container with your documents */
|
|
43
|
+
targetUrl: string;
|
|
44
|
+
/** Category / custom system for translation request */
|
|
45
|
+
category?: string;
|
|
46
|
+
/** Target Language */
|
|
47
|
+
language: string;
|
|
48
|
+
/** List of Glossary */
|
|
49
|
+
glossaries?: Array<Glossary>;
|
|
50
|
+
/** Storage Source */
|
|
51
|
+
storageSource?: "AzureBlob";
|
|
52
|
+
}
|
|
53
|
+
/** Glossary / translation memory for the request */
|
|
54
|
+
export interface Glossary {
|
|
55
|
+
/**
|
|
56
|
+
* Location of the glossary.
|
|
57
|
+
* We will use the file extension to extract the formatting if the format parameter is not supplied.
|
|
58
|
+
*
|
|
59
|
+
* If the translation language pair is not present in the glossary, it will not be applied
|
|
60
|
+
*/
|
|
61
|
+
glossaryUrl: string;
|
|
62
|
+
/** Format */
|
|
63
|
+
format: string;
|
|
64
|
+
/** Optional Version. If not specified, default is used. */
|
|
65
|
+
version?: string;
|
|
66
|
+
/** Storage Source */
|
|
67
|
+
storageSource?: "AzureBlob";
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/models.ts"],"names":[],"mappings":"AAGA,+CAA+C;AAC/C,MAAM,WAAW,uBAAuB;IACtC,kEAAkE;IAClE,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;CAC7B;AAED,yDAAyD;AACzD,MAAM,WAAW,YAAY;IAC3B,oCAAoC;IACpC,MAAM,EAAE,WAAW,CAAC;IACpB,iDAAiD;IACjD,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAC5B,wDAAwD;IACxD,WAAW,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;CACjC;AAED,oCAAoC;AACpC,MAAM,WAAW,WAAW;IAC1B,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qBAAqB;IACrB,aAAa,CAAC,EAAE,WAAW,CAAC;CAC7B;AAED,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wDAAwD;AACxD,MAAM,WAAW,WAAW;IAC1B,6DAA6D;IAC7D,SAAS,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sBAAsB;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,uBAAuB;IACvB,UAAU,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7B,qBAAqB;IACrB,aAAa,CAAC,EAAE,WAAW,CAAC;CAC7B;AAED,oDAAoD;AACpD,MAAM,WAAW,QAAQ;IACvB;;;;;OAKG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa;IACb,MAAM,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qBAAqB;IACrB,aAAa,CAAC,EAAE,WAAW,CAAC;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/models.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/** Translation job submission batch request */\nexport interface StartTranslationDetails {\n /** The input list of documents or folders containing documents */\n inputs: Array<BatchRequest>;\n}\n\n/** Definition for the input batch translation request */\nexport interface BatchRequest {\n /** Source of the input documents */\n source: SourceInput;\n /** Location of the destination for the output */\n targets: Array<TargetInput>;\n /** Storage type of the input documents source string */\n storageType?: \"Folder\" | \"File\";\n}\n\n/** Source of the input documents */\nexport interface SourceInput {\n /** Location of the folder / container or single file with your documents */\n sourceUrl: string;\n filter?: DocumentFilter;\n /**\n * Language code\n * If none is specified, we will perform auto detect on the document\n */\n language?: string;\n /** Storage Source */\n storageSource?: \"AzureBlob\";\n}\n\nexport interface DocumentFilter {\n /**\n * A case-sensitive prefix string to filter documents in the source path for translation.\n * For example, when using a Azure storage blob Uri, use the prefix to restrict sub folders for translation.\n */\n prefix?: string;\n /**\n * A case-sensitive suffix string to filter documents in the source path for translation.\n * This is most often use for file extensions\n */\n suffix?: string;\n}\n\n/** Destination for the finished translated documents */\nexport interface TargetInput {\n /** Location of the folder / container with your documents */\n targetUrl: string;\n /** Category / custom system for translation request */\n category?: string;\n /** Target Language */\n language: string;\n /** List of Glossary */\n glossaries?: Array<Glossary>;\n /** Storage Source */\n storageSource?: \"AzureBlob\";\n}\n\n/** Glossary / translation memory for the request */\nexport interface Glossary {\n /**\n * Location of the glossary.\n * We will use the file extension to extract the formatting if the format parameter is not supplied.\n *\n * If the translation language pair is not present in the glossary, it will not be applied\n */\n glossaryUrl: string;\n /** Format */\n format: string;\n /** Optional Version. If not specified, default is used. */\n version?: string;\n /** Storage Source */\n storageSource?: \"AzureBlob\";\n}\n"]}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contains unified error information used for HTTP responses across any Cognitive Service. Instances
|
|
3
|
+
* can be created either through Microsoft.CloudAI.Containers.HttpStatusExceptionV2 or by returning it directly from
|
|
4
|
+
* a controller.
|
|
5
|
+
*/
|
|
6
|
+
export interface TranslationErrorResponseOutput {
|
|
7
|
+
/** This contains an outer error with error code, message, details, target and an inner error with more descriptive details. */
|
|
8
|
+
error?: TranslationErrorOutput;
|
|
9
|
+
}
|
|
10
|
+
/** This contains an outer error with error code, message, details, target and an inner error with more descriptive details. */
|
|
11
|
+
export interface TranslationErrorOutput {
|
|
12
|
+
/** Enums containing high level error codes. */
|
|
13
|
+
code: "InvalidRequest" | "InvalidArgument" | "InternalServerError" | "ServiceUnavailable" | "ResourceNotFound" | "Unauthorized" | "RequestRateTooHigh";
|
|
14
|
+
/** Gets high level error message. */
|
|
15
|
+
message: string;
|
|
16
|
+
/**
|
|
17
|
+
* Gets the source of the error.
|
|
18
|
+
* For example it would be "documents" or "document id" in case of invalid document.
|
|
19
|
+
*/
|
|
20
|
+
readonly target?: string;
|
|
21
|
+
/**
|
|
22
|
+
* 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.
|
|
23
|
+
* This contains required properties ErrorCode, message and optional properties target, details(key value pair), inner error(this can be nested).
|
|
24
|
+
*/
|
|
25
|
+
innerError?: InnerTranslationErrorOutput;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 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.
|
|
29
|
+
* This contains required properties ErrorCode, message and optional properties target, details(key value pair), inner error(this can be nested).
|
|
30
|
+
*/
|
|
31
|
+
export interface InnerTranslationErrorOutput {
|
|
32
|
+
/** Gets code error string. */
|
|
33
|
+
code: string;
|
|
34
|
+
/** Gets high level error message. */
|
|
35
|
+
message: string;
|
|
36
|
+
/**
|
|
37
|
+
* Gets the source of the error.
|
|
38
|
+
* For example it would be "documents" or "document id" in case of invalid document.
|
|
39
|
+
*/
|
|
40
|
+
readonly target?: string;
|
|
41
|
+
/**
|
|
42
|
+
* 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.
|
|
43
|
+
* This contains required properties ErrorCode, message and optional properties target, details(key value pair), inner error(this can be nested).
|
|
44
|
+
*/
|
|
45
|
+
innerError?: InnerTranslationErrorOutput;
|
|
46
|
+
}
|
|
47
|
+
/** Translation job Status Response */
|
|
48
|
+
export interface TranslationsStatusOutput {
|
|
49
|
+
/** The summary status of individual operation */
|
|
50
|
+
value: Array<TranslationStatusOutput>;
|
|
51
|
+
/** Url for the next page. Null if no more pages available */
|
|
52
|
+
"@nextLink"?: string;
|
|
53
|
+
}
|
|
54
|
+
/** Translation job status response */
|
|
55
|
+
export interface TranslationStatusOutput {
|
|
56
|
+
/**
|
|
57
|
+
* Id of the operation.
|
|
58
|
+
*
|
|
59
|
+
* Value may contain a UUID
|
|
60
|
+
*/
|
|
61
|
+
id: string;
|
|
62
|
+
/** Operation created date time */
|
|
63
|
+
createdDateTimeUtc: string;
|
|
64
|
+
/** Date time in which the operation's status has been updated */
|
|
65
|
+
lastActionDateTimeUtc: string;
|
|
66
|
+
/** List of possible statuses for job or document */
|
|
67
|
+
status: "NotStarted" | "Running" | "Succeeded" | "Failed" | "Cancelled" | "Cancelling" | "ValidationFailed";
|
|
68
|
+
/** This contains an outer error with error code, message, details, target and an inner error with more descriptive details. */
|
|
69
|
+
error?: TranslationErrorOutput;
|
|
70
|
+
summary: StatusSummaryOutput;
|
|
71
|
+
}
|
|
72
|
+
export interface StatusSummaryOutput {
|
|
73
|
+
/** Total count */
|
|
74
|
+
total: number;
|
|
75
|
+
/** Failed count */
|
|
76
|
+
failed: number;
|
|
77
|
+
/** Number of Success */
|
|
78
|
+
success: number;
|
|
79
|
+
/** Number of in progress */
|
|
80
|
+
inProgress: number;
|
|
81
|
+
/** Count of not yet started */
|
|
82
|
+
notYetStarted: number;
|
|
83
|
+
/** Number of cancelled */
|
|
84
|
+
cancelled: number;
|
|
85
|
+
/** Total characters charged by the API */
|
|
86
|
+
totalCharacterCharged: number;
|
|
87
|
+
}
|
|
88
|
+
/** Document Status Response */
|
|
89
|
+
export interface DocumentStatusOutput {
|
|
90
|
+
/** Location of the document or folder */
|
|
91
|
+
path?: string;
|
|
92
|
+
/** Location of the source document */
|
|
93
|
+
sourcePath: string;
|
|
94
|
+
/** Operation created date time */
|
|
95
|
+
createdDateTimeUtc: string;
|
|
96
|
+
/** Date time in which the operation's status has been updated */
|
|
97
|
+
lastActionDateTimeUtc: string;
|
|
98
|
+
/** List of possible statuses for job or document */
|
|
99
|
+
status: "NotStarted" | "Running" | "Succeeded" | "Failed" | "Cancelled" | "Cancelling" | "ValidationFailed";
|
|
100
|
+
/** To language */
|
|
101
|
+
to: string;
|
|
102
|
+
/** This contains an outer error with error code, message, details, target and an inner error with more descriptive details. */
|
|
103
|
+
error?: TranslationErrorOutput;
|
|
104
|
+
/** Progress of the translation if available */
|
|
105
|
+
progress: number;
|
|
106
|
+
/**
|
|
107
|
+
* Document Id
|
|
108
|
+
*
|
|
109
|
+
* Value may contain a UUID
|
|
110
|
+
*/
|
|
111
|
+
id: string;
|
|
112
|
+
/** Character charged by the API */
|
|
113
|
+
characterCharged?: number;
|
|
114
|
+
}
|
|
115
|
+
/** Documents Status Response */
|
|
116
|
+
export interface DocumentsStatusOutput {
|
|
117
|
+
/** The detail status of individual documents */
|
|
118
|
+
value: Array<DocumentStatusOutput>;
|
|
119
|
+
/** Url for the next page. Null if no more pages available */
|
|
120
|
+
"@nextLink"?: string;
|
|
121
|
+
}
|
|
122
|
+
/** Base type for List return in our api */
|
|
123
|
+
export interface SupportedFileFormatsOutput {
|
|
124
|
+
/** list of objects */
|
|
125
|
+
value: Array<FileFormatOutput>;
|
|
126
|
+
}
|
|
127
|
+
export interface FileFormatOutput {
|
|
128
|
+
/** Name of the format */
|
|
129
|
+
format: string;
|
|
130
|
+
/** Supported file extension for this format */
|
|
131
|
+
fileExtensions: Array<string>;
|
|
132
|
+
/** Supported Content-Types for this format */
|
|
133
|
+
contentTypes: Array<string>;
|
|
134
|
+
/** Default version if none is specified */
|
|
135
|
+
defaultVersion?: string;
|
|
136
|
+
/** Supported Version */
|
|
137
|
+
versions?: Array<string>;
|
|
138
|
+
}
|
|
139
|
+
/** Base type for List return in our api */
|
|
140
|
+
export interface SupportedStorageSourcesOutput {
|
|
141
|
+
/** list of objects */
|
|
142
|
+
value: Array<"AzureBlob">;
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=outputModels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputModels.d.ts","sourceRoot":"","sources":["../../src/outputModels.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,WAAW,8BAA8B;IAC7C,+HAA+H;IAC/H,KAAK,CAAC,EAAE,sBAAsB,CAAC;CAChC;AAED,+HAA+H;AAC/H,MAAM,WAAW,sBAAsB;IACrC,+CAA+C;IAC/C,IAAI,EACA,gBAAgB,GAChB,iBAAiB,GACjB,qBAAqB,GACrB,oBAAoB,GACpB,kBAAkB,GAClB,cAAc,GACd,oBAAoB,CAAC;IACzB,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,UAAU,CAAC,EAAE,2BAA2B,CAAC;CAC1C;AAED;;;GAGG;AACH,MAAM,WAAW,2BAA2B;IAC1C,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,UAAU,CAAC,EAAE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AAW,GACX,YAAY,GACZ,kBAAkB,CAAC;IACvB,kBAAkB;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,+HAA+H;IAC/H,KAAK,CAAC,EAAE,sBAAsB,CAAC;IAC/B,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,EAAE,EAAE,MAAM,CAAC;IACX,mCAAmC;IACnC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,gCAAgC;AAChC,MAAM,WAAW,qBAAqB;IACpC,gDAAgD;IAChD,KAAK,EAAE,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACnC,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,2CAA2C;AAC3C,MAAM,WAAW,0BAA0B;IACzC,sBAAsB;IACtB,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,gBAAgB;IAC/B,yBAAyB;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,cAAc,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B,8CAA8C;IAC9C,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,wBAAwB;IACxB,QAAQ,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CAC1B;AAED,2CAA2C;AAC3C,MAAM,WAAW,6BAA6B;IAC5C,sBAAsB;IACtB,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputModels.js","sourceRoot":"","sources":["../../src/outputModels.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Contains unified error information used for HTTP responses across any Cognitive Service. Instances\n * can be created either through Microsoft.CloudAI.Containers.HttpStatusExceptionV2 or by returning it directly from\n * a controller.\n */\nexport interface TranslationErrorResponseOutput {\n /** This contains an outer error with error code, message, details, target and an inner error with more descriptive details. */\n error?: TranslationErrorOutput;\n}\n\n/** This contains an outer error with error code, message, details, target and an inner error with more descriptive details. */\nexport interface TranslationErrorOutput {\n /** Enums containing high level error codes. */\n code:\n | \"InvalidRequest\"\n | \"InvalidArgument\"\n | \"InternalServerError\"\n | \"ServiceUnavailable\"\n | \"ResourceNotFound\"\n | \"Unauthorized\"\n | \"RequestRateTooHigh\";\n /** Gets high level error message. */\n message: string;\n /**\n * Gets the source of the error.\n * For example it would be \"documents\" or \"document id\" in case of invalid document.\n */\n readonly target?: string;\n /**\n * 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.\n * This contains required properties ErrorCode, message and optional properties target, details(key value pair), inner error(this can be nested).\n */\n innerError?: InnerTranslationErrorOutput;\n}\n\n/**\n * 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.\n * This contains required properties ErrorCode, message and optional properties target, details(key value pair), inner error(this can be nested).\n */\nexport interface InnerTranslationErrorOutput {\n /** Gets code error string. */\n code: string;\n /** Gets high level error message. */\n message: string;\n /**\n * Gets the source of the error.\n * For example it would be \"documents\" or \"document id\" in case of invalid document.\n */\n readonly target?: string;\n /**\n * 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.\n * This contains required properties ErrorCode, message and optional properties target, details(key value pair), inner error(this can be nested).\n */\n innerError?: InnerTranslationErrorOutput;\n}\n\n/** Translation job Status Response */\nexport interface TranslationsStatusOutput {\n /** The summary status of individual operation */\n value: Array<TranslationStatusOutput>;\n /** Url for the next page. Null if no more pages available */\n \"@nextLink\"?: string;\n}\n\n/** Translation job status response */\nexport interface TranslationStatusOutput {\n /**\n * Id of the operation.\n *\n * Value may contain a UUID\n */\n id: string;\n /** Operation created date time */\n createdDateTimeUtc: string;\n /** Date time in which the operation's status has been updated */\n lastActionDateTimeUtc: string;\n /** List of possible statuses for job or document */\n status:\n | \"NotStarted\"\n | \"Running\"\n | \"Succeeded\"\n | \"Failed\"\n | \"Cancelled\"\n | \"Cancelling\"\n | \"ValidationFailed\";\n /** This contains an outer error with error code, message, details, target and an inner error with more descriptive details. */\n error?: TranslationErrorOutput;\n summary: StatusSummaryOutput;\n}\n\nexport interface StatusSummaryOutput {\n /** Total count */\n total: number;\n /** Failed count */\n failed: number;\n /** Number of Success */\n success: number;\n /** Number of in progress */\n inProgress: number;\n /** Count of not yet started */\n notYetStarted: number;\n /** Number of cancelled */\n cancelled: number;\n /** Total characters charged by the API */\n totalCharacterCharged: number;\n}\n\n/** Document Status Response */\nexport interface DocumentStatusOutput {\n /** Location of the document or folder */\n path?: string;\n /** Location of the source document */\n sourcePath: string;\n /** Operation created date time */\n createdDateTimeUtc: string;\n /** Date time in which the operation's status has been updated */\n lastActionDateTimeUtc: string;\n /** List of possible statuses for job or document */\n status:\n | \"NotStarted\"\n | \"Running\"\n | \"Succeeded\"\n | \"Failed\"\n | \"Cancelled\"\n | \"Cancelling\"\n | \"ValidationFailed\";\n /** To language */\n to: string;\n /** This contains an outer error with error code, message, details, target and an inner error with more descriptive details. */\n error?: TranslationErrorOutput;\n /** Progress of the translation if available */\n progress: number;\n /**\n * Document Id\n *\n * Value may contain a UUID\n */\n id: string;\n /** Character charged by the API */\n characterCharged?: number;\n}\n\n/** Documents Status Response */\nexport interface DocumentsStatusOutput {\n /** The detail status of individual documents */\n value: Array<DocumentStatusOutput>;\n /** Url for the next page. Null if no more pages available */\n \"@nextLink\"?: string;\n}\n\n/** Base type for List return in our api */\nexport interface SupportedFileFormatsOutput {\n /** list of objects */\n value: Array<FileFormatOutput>;\n}\n\nexport interface FileFormatOutput {\n /** Name of the format */\n format: string;\n /** Supported file extension for this format */\n fileExtensions: Array<string>;\n /** Supported Content-Types for this format */\n contentTypes: Array<string>;\n /** Default version if none is specified */\n defaultVersion?: string;\n /** Supported Version */\n versions?: Array<string>;\n}\n\n/** Base type for List return in our api */\nexport interface SupportedStorageSourcesOutput {\n /** list of objects */\n value: Array<\"AzureBlob\">;\n}\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Client, PathUncheckedResponse } from "@azure-rest/core-client";
|
|
2
|
+
/**
|
|
3
|
+
* An interface that tracks the settings for paged iteration
|
|
4
|
+
*/
|
|
5
|
+
export interface PageSettings {
|
|
6
|
+
/**
|
|
7
|
+
* The token that keeps track of where to continue the iterator
|
|
8
|
+
*/
|
|
9
|
+
continuationToken?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* An interface that allows async iterable iteration both to completion and by page.
|
|
13
|
+
*/
|
|
14
|
+
export interface PagedAsyncIterableIterator<TElement, TPage = TElement[], TPageSettings = PageSettings> {
|
|
15
|
+
/**
|
|
16
|
+
* The next method, part of the iteration protocol
|
|
17
|
+
*/
|
|
18
|
+
next(): Promise<IteratorResult<TElement>>;
|
|
19
|
+
/**
|
|
20
|
+
* The connection to the async iterator, part of the iteration protocol
|
|
21
|
+
*/
|
|
22
|
+
[Symbol.asyncIterator](): PagedAsyncIterableIterator<TElement, TPage, TPageSettings>;
|
|
23
|
+
/**
|
|
24
|
+
* Return an AsyncIterableIterator that works a page at a time
|
|
25
|
+
*/
|
|
26
|
+
byPage: (settings?: TPageSettings) => AsyncIterableIterator<TPage>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Helper type to extract the type of an array
|
|
30
|
+
*/
|
|
31
|
+
export type GetArrayType<T> = T extends Array<infer TData> ? TData : never;
|
|
32
|
+
/**
|
|
33
|
+
* The type of a custom function that defines how to get a page and a link to the next one if any.
|
|
34
|
+
*/
|
|
35
|
+
export type GetPage<TPage> = (pageLink: string) => Promise<{
|
|
36
|
+
page: TPage;
|
|
37
|
+
nextPageLink?: string;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Options for the paging helper
|
|
41
|
+
*/
|
|
42
|
+
export interface PagingOptions<TResponse> {
|
|
43
|
+
/**
|
|
44
|
+
* Custom function to extract pagination details for crating the PagedAsyncIterableIterator
|
|
45
|
+
*/
|
|
46
|
+
customGetPage?: GetPage<PaginateReturn<TResponse>[]>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Helper type to infer the Type of the paged elements from the response type
|
|
50
|
+
* This type is generated based on the swagger information for x-ms-pageable
|
|
51
|
+
* specifically on the itemName property which indicates the property of the response
|
|
52
|
+
* where the page items are found. The default value is `value`.
|
|
53
|
+
* This type will allow us to provide strongly typed Iterator based on the response we get as second parameter
|
|
54
|
+
*/
|
|
55
|
+
export type PaginateReturn<TResult> = TResult extends {
|
|
56
|
+
body: {
|
|
57
|
+
value?: infer TPage;
|
|
58
|
+
};
|
|
59
|
+
} ? GetArrayType<TPage> : Array<unknown>;
|
|
60
|
+
/**
|
|
61
|
+
* Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension
|
|
62
|
+
* @param client - Client to use for sending the next page requests
|
|
63
|
+
* @param initialResponse - Initial response containing the nextLink and current page of elements
|
|
64
|
+
* @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results
|
|
65
|
+
* @returns - PagedAsyncIterableIterator to iterate the elements
|
|
66
|
+
*/
|
|
67
|
+
export declare function paginate<TResponse extends PathUncheckedResponse>(client: Client, initialResponse: TResponse, options?: PagingOptions<TResponse>): PagedAsyncIterableIterator<PaginateReturn<TResponse>>;
|
|
68
|
+
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AAS;IACpD,IAAI,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAA;KAAE,CAAC;CAC/B,GACG,YAAY,CAAC,KAAK,CAAC,GACnB,KAAK,CAAC,OAAO,CAAC,CAAC;AAEnB;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,SAAS,SAAS,qBAAqB,EAC9D,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,SAAS,EAC1B,OAAO,GAAE,aAAa,CAAC,SAAS,CAAM,GACrC,0BAA0B,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CA0BvD"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.paginate = paginate;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const core_client_1 = require("@azure-rest/core-client");
|
|
8
|
+
/**
|
|
9
|
+
* returns an async iterator that iterates over results. It also has a `byPage`
|
|
10
|
+
* method that returns pages of items at once.
|
|
11
|
+
*
|
|
12
|
+
* @param pagedResult - an object that specifies how to get pages.
|
|
13
|
+
* @returns a paged async iterator that iterates over results.
|
|
14
|
+
*/
|
|
15
|
+
function getPagedAsyncIterator(pagedResult) {
|
|
16
|
+
var _a;
|
|
17
|
+
const iter = getItemAsyncIterator(pagedResult);
|
|
18
|
+
return {
|
|
19
|
+
next() {
|
|
20
|
+
return iter.next();
|
|
21
|
+
},
|
|
22
|
+
[Symbol.asyncIterator]() {
|
|
23
|
+
return this;
|
|
24
|
+
},
|
|
25
|
+
byPage: (_a = pagedResult === null || pagedResult === void 0 ? void 0 : pagedResult.byPage) !== null && _a !== void 0 ? _a : ((settings) => {
|
|
26
|
+
const { continuationToken } = settings !== null && settings !== void 0 ? settings : {};
|
|
27
|
+
return getPageAsyncIterator(pagedResult, {
|
|
28
|
+
pageLink: continuationToken,
|
|
29
|
+
});
|
|
30
|
+
}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function getItemAsyncIterator(pagedResult) {
|
|
34
|
+
return tslib_1.__asyncGenerator(this, arguments, function* getItemAsyncIterator_1() {
|
|
35
|
+
var _a, e_1, _b, _c, _d, e_2, _e, _f;
|
|
36
|
+
const pages = getPageAsyncIterator(pagedResult);
|
|
37
|
+
const firstVal = yield tslib_1.__await(pages.next());
|
|
38
|
+
// if the result does not have an array shape, i.e. TPage = TElement, then we return it as is
|
|
39
|
+
if (!Array.isArray(firstVal.value)) {
|
|
40
|
+
// can extract elements from this page
|
|
41
|
+
const { toElements } = pagedResult;
|
|
42
|
+
if (toElements) {
|
|
43
|
+
yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(toElements(firstVal.value))));
|
|
44
|
+
try {
|
|
45
|
+
for (var _g = true, pages_1 = tslib_1.__asyncValues(pages), pages_1_1; pages_1_1 = yield tslib_1.__await(pages_1.next()), _a = pages_1_1.done, !_a; _g = true) {
|
|
46
|
+
_c = pages_1_1.value;
|
|
47
|
+
_g = false;
|
|
48
|
+
const page = _c;
|
|
49
|
+
yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(toElements(page))));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
53
|
+
finally {
|
|
54
|
+
try {
|
|
55
|
+
if (!_g && !_a && (_b = pages_1.return)) yield tslib_1.__await(_b.call(pages_1));
|
|
56
|
+
}
|
|
57
|
+
finally { if (e_1) throw e_1.error; }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
yield yield tslib_1.__await(firstVal.value);
|
|
62
|
+
// `pages` is of type `AsyncIterableIterator<TPage>` but TPage = TElement in this case
|
|
63
|
+
yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(pages)));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(firstVal.value)));
|
|
68
|
+
try {
|
|
69
|
+
for (var _h = true, pages_2 = tslib_1.__asyncValues(pages), pages_2_1; pages_2_1 = yield tslib_1.__await(pages_2.next()), _d = pages_2_1.done, !_d; _h = true) {
|
|
70
|
+
_f = pages_2_1.value;
|
|
71
|
+
_h = false;
|
|
72
|
+
const page = _f;
|
|
73
|
+
// pages is of type `AsyncIterableIterator<TPage>` so `page` is of type `TPage`. In this branch,
|
|
74
|
+
// it must be the case that `TPage = TElement[]`
|
|
75
|
+
yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(page)));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
79
|
+
finally {
|
|
80
|
+
try {
|
|
81
|
+
if (!_h && !_d && (_e = pages_2.return)) yield tslib_1.__await(_e.call(pages_2));
|
|
82
|
+
}
|
|
83
|
+
finally { if (e_2) throw e_2.error; }
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function getPageAsyncIterator(pagedResult_1) {
|
|
89
|
+
return tslib_1.__asyncGenerator(this, arguments, function* getPageAsyncIterator_1(pagedResult, options = {}) {
|
|
90
|
+
const { pageLink } = options;
|
|
91
|
+
let response = yield tslib_1.__await(pagedResult.getPage(pageLink !== null && pageLink !== void 0 ? pageLink : pagedResult.firstPageLink));
|
|
92
|
+
if (!response) {
|
|
93
|
+
return yield tslib_1.__await(void 0);
|
|
94
|
+
}
|
|
95
|
+
yield yield tslib_1.__await(response.page);
|
|
96
|
+
while (response.nextPageLink) {
|
|
97
|
+
response = yield tslib_1.__await(pagedResult.getPage(response.nextPageLink));
|
|
98
|
+
if (!response) {
|
|
99
|
+
return yield tslib_1.__await(void 0);
|
|
100
|
+
}
|
|
101
|
+
yield yield tslib_1.__await(response.page);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension
|
|
107
|
+
* @param client - Client to use for sending the next page requests
|
|
108
|
+
* @param initialResponse - Initial response containing the nextLink and current page of elements
|
|
109
|
+
* @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results
|
|
110
|
+
* @returns - PagedAsyncIterableIterator to iterate the elements
|
|
111
|
+
*/
|
|
112
|
+
function paginate(client, initialResponse, options = {}) {
|
|
113
|
+
let firstRun = true;
|
|
114
|
+
const itemName = "value";
|
|
115
|
+
const nextLinkName = "nextLink";
|
|
116
|
+
const { customGetPage } = options;
|
|
117
|
+
const pagedResult = {
|
|
118
|
+
firstPageLink: "",
|
|
119
|
+
getPage: typeof customGetPage === "function"
|
|
120
|
+
? customGetPage
|
|
121
|
+
: async (pageLink) => {
|
|
122
|
+
const result = firstRun ? initialResponse : await client.pathUnchecked(pageLink).get();
|
|
123
|
+
firstRun = false;
|
|
124
|
+
checkPagingRequest(result);
|
|
125
|
+
const nextLink = getNextLink(result.body, nextLinkName);
|
|
126
|
+
const values = getElements(result.body, itemName);
|
|
127
|
+
return {
|
|
128
|
+
page: values,
|
|
129
|
+
nextPageLink: nextLink,
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
return getPagedAsyncIterator(pagedResult);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Gets for the value of nextLink in the body
|
|
137
|
+
*/
|
|
138
|
+
function getNextLink(body, nextLinkName) {
|
|
139
|
+
if (!nextLinkName) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
const nextLink = body[nextLinkName];
|
|
143
|
+
if (typeof nextLink !== "string" && typeof nextLink !== "undefined") {
|
|
144
|
+
throw new Error(`Body Property ${nextLinkName} should be a string or undefined`);
|
|
145
|
+
}
|
|
146
|
+
return nextLink;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Gets the elements of the current request in the body.
|
|
150
|
+
*/
|
|
151
|
+
function getElements(body, itemName) {
|
|
152
|
+
const value = body[itemName];
|
|
153
|
+
// value has to be an array according to the x-ms-pageable extension.
|
|
154
|
+
// The fact that this must be an array is used above to calculate the
|
|
155
|
+
// type of elements in the page in PaginateReturn
|
|
156
|
+
if (!Array.isArray(value)) {
|
|
157
|
+
throw new Error(`Couldn't paginate response\n Body doesn't contain an array property with name: ${itemName}`);
|
|
158
|
+
}
|
|
159
|
+
return value !== null && value !== void 0 ? value : [];
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Checks if a request failed
|
|
163
|
+
*/
|
|
164
|
+
function checkPagingRequest(response) {
|
|
165
|
+
const Http2xxStatusCodes = ["200", "201", "202", "203", "204", "205", "206", "207", "208", "226"];
|
|
166
|
+
if (!Http2xxStatusCodes.includes(response.status)) {
|
|
167
|
+
throw (0, core_client_1.createRestError)(`Pagination failed with unexpected statusCode ${response.status}`, response);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=paginateHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paginateHelper.js","sourceRoot":"","sources":["../../src/paginateHelper.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AA2LlC,4BA8BC;;AAtND,yDAA0D;AAE1D;;;;;;GAMG;AACH,SAAS,qBAAqB,CAM5B,WAAqD;;IAErD,MAAM,IAAI,GAAG,oBAAoB,CAAwC,WAAW,CAAC,CAAC;IACtF,OAAO;QACL,IAAI;YACF,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;QACrB,CAAC;QACD,CAAC,MAAM,CAAC,aAAa,CAAC;YACpB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,EACJ,MAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,MAAM,mCAClB,CAAC,C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b,kFAAkF,QAAQ,EAAE,CAC7F,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB,CAAC,QAA+B;IACzD,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAClG,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,MAAM,IAAA,6BAAe,EACnB,gDAAgD,QAAQ,CAAC,MAAM,EAAE,EACjE,QAAQ,CACT,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Client, PathUncheckedResponse } from \"@azure-rest/core-client\";\nimport { createRestError } from \"@azure-rest/core-client\";\n\n/**\n * returns an async iterator that iterates over results. It also has a `byPage`\n * method that returns pages of items at once.\n *\n * @param pagedResult - an object that specifies how to get pages.\n * @returns a paged async iterator that iterates over results.\n */\nfunction getPagedAsyncIterator<\n TElement,\n TPage = TElement[],\n TPageSettings = PageSettings,\n TLink = string,\n>(\n pagedResult: PagedResult<TPage, TPageSettings, TLink>,\n): PagedAsyncIterableIterator<TElement, TPage, TPageSettings> {\n const iter = getItemAsyncIterator<TElement, TPage, TLink, TPageSettings>(pagedResult);\n return {\n next() {\n return iter.next();\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n byPage:\n pagedResult?.byPage ??\n (((settings?: PageSettings) => {\n const { continuationToken } = settings ?? {};\n return getPageAsyncIterator(pagedResult, {\n pageLink: continuationToken as unknown as TLink | undefined,\n });\n }) as unknown as (settings?: TPageSettings) => AsyncIterableIterator<TPage>),\n };\n}\n\nasync function* getItemAsyncIterator<TElement, TPage, TLink, TPageSettings>(\n pagedResult: PagedResult<TPage, TPageSettings, TLink>,\n): AsyncIterableIterator<TElement> {\n const pages = getPageAsyncIterator(pagedResult);\n const firstVal = await pages.next();\n // if the result does not have an array shape, i.e. TPage = TElement, then we return it as is\n if (!Array.isArray(firstVal.value)) {\n // can extract elements from this page\n const { toElements } = pagedResult;\n if (toElements) {\n yield* toElements(firstVal.value) as TElement[];\n for await (const page of pages) {\n yield* toElements(page) as TElement[];\n }\n } else {\n yield firstVal.value;\n // `pages` is of type `AsyncIterableIterator<TPage>` but TPage = TElement in this case\n yield* pages as unknown as AsyncIterableIterator<TElement>;\n }\n } else {\n yield* firstVal.value;\n for await (const page of pages) {\n // pages is of type `AsyncIterableIterator<TPage>` so `page` is of type `TPage`. In this branch,\n // it must be the case that `TPage = TElement[]`\n yield* page as unknown as TElement[];\n }\n }\n}\n\nasync function* getPageAsyncIterator<TPage, TLink, TPageSettings>(\n pagedResult: PagedResult<TPage, TPageSettings, TLink>,\n options: {\n pageLink?: TLink;\n } = {},\n): AsyncIterableIterator<TPage> {\n const { pageLink } = options;\n let response = await pagedResult.getPage(pageLink ?? pagedResult.firstPageLink);\n if (!response) {\n return;\n }\n yield response.page;\n while (response.nextPageLink) {\n response = await pagedResult.getPage(response.nextPageLink);\n if (!response) {\n return;\n }\n yield response.page;\n }\n}\n\n/**\n * An interface that tracks the settings for paged iteration\n */\nexport interface PageSettings {\n /**\n * The token that keeps track of where to continue the iterator\n */\n continuationToken?: string;\n}\n\n/**\n * An interface that allows async iterable iteration both to completion and by page.\n */\nexport interface PagedAsyncIterableIterator<\n TElement,\n TPage = TElement[],\n TPageSettings = PageSettings,\n> {\n /**\n * The next method, part of the iteration protocol\n */\n next(): Promise<IteratorResult<TElement>>;\n /**\n * The connection to the async iterator, part of the iteration protocol\n */\n [Symbol.asyncIterator](): PagedAsyncIterableIterator<TElement, TPage, TPageSettings>;\n /**\n * Return an AsyncIterableIterator that works a page at a time\n */\n byPage: (settings?: TPageSettings) => AsyncIterableIterator<TPage>;\n}\n\n/**\n * An interface that describes how to communicate with the service.\n */\ninterface PagedResult<TPage, TPageSettings = PageSettings, TLink = string> {\n /**\n * Link to the first page of results.\n */\n firstPageLink: TLink;\n /**\n * A method that returns a page of results.\n */\n getPage: (pageLink: TLink) => Promise<{ page: TPage; nextPageLink?: TLink } | undefined>;\n /**\n * a function to implement the `byPage` method on the paged async iterator.\n */\n byPage?: (settings?: TPageSettings) => AsyncIterableIterator<TPage>;\n\n /**\n * A function to extract elements from a page.\n */\n toElements?: (page: TPage) => unknown[];\n}\n\n/**\n * Helper type to extract the type of an array\n */\nexport type GetArrayType<T> = T extends Array<infer TData> ? TData : never;\n\n/**\n * The type of a custom function that defines how to get a page and a link to the next one if any.\n */\nexport type GetPage<TPage> = (pageLink: string) => Promise<{\n page: TPage;\n nextPageLink?: string;\n}>;\n\n/**\n * Options for the paging helper\n */\nexport interface PagingOptions<TResponse> {\n /**\n * Custom function to extract pagination details for crating the PagedAsyncIterableIterator\n */\n customGetPage?: GetPage<PaginateReturn<TResponse>[]>;\n}\n\n/**\n * Helper type to infer the Type of the paged elements from the response type\n * This type is generated based on the swagger information for x-ms-pageable\n * specifically on the itemName property which indicates the property of the response\n * where the page items are found. The default value is `value`.\n * This type will allow us to provide strongly typed Iterator based on the response we get as second parameter\n */\nexport type PaginateReturn<TResult> = TResult extends {\n body: { value?: infer TPage };\n}\n ? GetArrayType<TPage>\n : Array<unknown>;\n\n/**\n * Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension\n * @param client - Client to use for sending the next page requests\n * @param initialResponse - Initial response containing the nextLink and current page of elements\n * @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results\n * @returns - PagedAsyncIterableIterator to iterate the elements\n */\nexport function paginate<TResponse extends PathUncheckedResponse>(\n client: Client,\n initialResponse: TResponse,\n options: PagingOptions<TResponse> = {},\n): PagedAsyncIterableIterator<PaginateReturn<TResponse>> {\n // Extract element type from initial response\n type TElement = PaginateReturn<TResponse>;\n let firstRun = true;\n const itemName = \"value\";\n const nextLinkName = \"nextLink\";\n const { customGetPage } = options;\n const pagedResult: PagedResult<TElement[]> = {\n firstPageLink: \"\",\n getPage:\n typeof customGetPage === \"function\"\n ? customGetPage\n : async (pageLink: string) => {\n const result = firstRun ? initialResponse : await client.pathUnchecked(pageLink).get();\n firstRun = false;\n checkPagingRequest(result);\n const nextLink = getNextLink(result.body, nextLinkName);\n const values = getElements<TElement>(result.body, itemName);\n return {\n page: values,\n nextPageLink: nextLink,\n };\n },\n };\n\n return getPagedAsyncIterator(pagedResult);\n}\n\n/**\n * Gets for the value of nextLink in the body\n */\nfunction getNextLink(body: unknown, nextLinkName?: string): string | undefined {\n if (!nextLinkName) {\n return undefined;\n }\n\n const nextLink = (body as Record<string, unknown>)[nextLinkName];\n\n if (typeof nextLink !== \"string\" && typeof nextLink !== \"undefined\") {\n throw new Error(`Body Property ${nextLinkName} should be a string or undefined`);\n }\n\n return nextLink;\n}\n\n/**\n * Gets the elements of the current request in the body.\n */\nfunction getElements<T = unknown>(body: unknown, itemName: string): T[] {\n const value = (body as Record<string, unknown>)[itemName] as T[];\n\n // value has to be an array according to the x-ms-pageable extension.\n // The fact that this must be an array is used above to calculate the\n // type of elements in the page in PaginateReturn\n if (!Array.isArray(value)) {\n throw new Error(\n `Couldn't paginate response\\n Body doesn't contain an array property with name: ${itemName}`,\n );\n }\n\n return value ?? [];\n}\n\n/**\n * Checks if a request failed\n */\nfunction checkPagingRequest(response: PathUncheckedResponse): void {\n const Http2xxStatusCodes = [\"200\", \"201\", \"202\", \"203\", \"204\", \"205\", \"206\", \"207\", \"208\", \"226\"];\n if (!Http2xxStatusCodes.includes(response.status)) {\n throw createRestError(\n `Pagination failed with unexpected statusCode ${response.status}`,\n response,\n );\n }\n}\n"]}
|