@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.
Files changed (199) hide show
  1. package/LICENSE +3 -3
  2. package/README.md +52 -71
  3. package/dist/browser/clientDefinitions.d.ts +125 -0
  4. package/dist/browser/clientDefinitions.d.ts.map +1 -0
  5. package/dist/browser/clientDefinitions.js +4 -0
  6. package/dist/browser/clientDefinitions.js.map +1 -0
  7. package/dist/browser/documentTranslator.d.ts +14 -0
  8. package/dist/browser/documentTranslator.d.ts.map +1 -0
  9. package/dist/browser/documentTranslator.js +33 -0
  10. package/dist/browser/documentTranslator.js.map +1 -0
  11. package/dist/browser/index.d.ts +12 -0
  12. package/dist/browser/index.d.ts.map +1 -0
  13. package/dist/browser/index.js +14 -0
  14. package/dist/browser/index.js.map +1 -0
  15. package/dist/browser/isUnexpected.d.ts +11 -0
  16. package/dist/browser/isUnexpected.d.ts.map +1 -0
  17. package/dist/browser/isUnexpected.js +78 -0
  18. package/dist/browser/isUnexpected.js.map +1 -0
  19. package/dist/browser/logger.d.ts +2 -0
  20. package/dist/browser/logger.d.ts.map +1 -0
  21. package/dist/browser/logger.js +5 -0
  22. package/dist/browser/logger.js.map +1 -0
  23. package/dist/browser/models.d.ts +69 -0
  24. package/dist/browser/models.d.ts.map +1 -0
  25. package/dist/browser/models.js +4 -0
  26. package/dist/browser/models.js.map +1 -0
  27. package/dist/browser/outputModels.d.ts +144 -0
  28. package/dist/browser/outputModels.d.ts.map +1 -0
  29. package/dist/browser/outputModels.js +4 -0
  30. package/dist/browser/outputModels.js.map +1 -0
  31. package/dist/browser/package.json +3 -0
  32. package/dist/browser/paginateHelper.d.ts +68 -0
  33. package/dist/browser/paginateHelper.d.ts.map +1 -0
  34. package/dist/browser/paginateHelper.js +167 -0
  35. package/dist/browser/paginateHelper.js.map +1 -0
  36. package/dist/browser/parameters.d.ts +98 -0
  37. package/dist/browser/parameters.d.ts.map +1 -0
  38. package/dist/browser/parameters.js +4 -0
  39. package/dist/browser/parameters.js.map +1 -0
  40. package/dist/browser/pollingHelper.d.ts +76 -0
  41. package/dist/browser/pollingHelper.d.ts.map +1 -0
  42. package/dist/browser/pollingHelper.js +104 -0
  43. package/dist/browser/pollingHelper.js.map +1 -0
  44. package/{types/ai-document-translator.d.ts → dist/browser/responses.d.ts} +725 -1242
  45. package/dist/browser/responses.d.ts.map +1 -0
  46. package/dist/browser/responses.js +4 -0
  47. package/dist/browser/responses.js.map +1 -0
  48. package/dist/commonjs/clientDefinitions.d.ts +125 -0
  49. package/dist/commonjs/clientDefinitions.d.ts.map +1 -0
  50. package/dist/commonjs/clientDefinitions.js +5 -0
  51. package/dist/commonjs/clientDefinitions.js.map +1 -0
  52. package/dist/commonjs/documentTranslator.d.ts +14 -0
  53. package/dist/commonjs/documentTranslator.d.ts.map +1 -0
  54. package/dist/commonjs/documentTranslator.js +36 -0
  55. package/dist/commonjs/documentTranslator.js.map +1 -0
  56. package/dist/commonjs/index.d.ts +12 -0
  57. package/dist/commonjs/index.d.ts.map +1 -0
  58. package/dist/commonjs/index.js +17 -0
  59. package/dist/commonjs/index.js.map +1 -0
  60. package/dist/commonjs/isUnexpected.d.ts +11 -0
  61. package/dist/commonjs/isUnexpected.d.ts.map +1 -0
  62. package/dist/commonjs/isUnexpected.js +81 -0
  63. package/dist/commonjs/isUnexpected.js.map +1 -0
  64. package/dist/commonjs/logger.d.ts +2 -0
  65. package/dist/commonjs/logger.d.ts.map +1 -0
  66. package/dist/commonjs/logger.js +8 -0
  67. package/dist/commonjs/logger.js.map +1 -0
  68. package/dist/commonjs/models.d.ts +69 -0
  69. package/dist/commonjs/models.d.ts.map +1 -0
  70. package/dist/commonjs/models.js +5 -0
  71. package/dist/commonjs/models.js.map +1 -0
  72. package/dist/commonjs/outputModels.d.ts +144 -0
  73. package/dist/commonjs/outputModels.d.ts.map +1 -0
  74. package/dist/commonjs/outputModels.js +5 -0
  75. package/dist/commonjs/outputModels.js.map +1 -0
  76. package/dist/commonjs/package.json +3 -0
  77. package/dist/commonjs/paginateHelper.d.ts +68 -0
  78. package/dist/commonjs/paginateHelper.d.ts.map +1 -0
  79. package/dist/commonjs/paginateHelper.js +170 -0
  80. package/dist/commonjs/paginateHelper.js.map +1 -0
  81. package/dist/commonjs/parameters.d.ts +98 -0
  82. package/dist/commonjs/parameters.d.ts.map +1 -0
  83. package/dist/commonjs/parameters.js +5 -0
  84. package/dist/commonjs/parameters.js.map +1 -0
  85. package/dist/commonjs/pollingHelper.d.ts +76 -0
  86. package/dist/commonjs/pollingHelper.d.ts.map +1 -0
  87. package/dist/commonjs/pollingHelper.js +107 -0
  88. package/dist/commonjs/pollingHelper.js.map +1 -0
  89. package/dist/commonjs/responses.d.ts +725 -0
  90. package/dist/commonjs/responses.d.ts.map +1 -0
  91. package/dist/commonjs/responses.js +5 -0
  92. package/dist/commonjs/responses.js.map +1 -0
  93. package/dist/commonjs/tsdoc-metadata.json +11 -0
  94. package/dist/esm/clientDefinitions.d.ts +125 -0
  95. package/dist/esm/clientDefinitions.d.ts.map +1 -0
  96. package/dist/esm/clientDefinitions.js +4 -0
  97. package/dist/esm/clientDefinitions.js.map +1 -0
  98. package/dist/esm/documentTranslator.d.ts +14 -0
  99. package/dist/esm/documentTranslator.d.ts.map +1 -0
  100. package/dist/esm/documentTranslator.js +33 -0
  101. package/dist/esm/documentTranslator.js.map +1 -0
  102. package/dist/esm/index.d.ts +12 -0
  103. package/dist/esm/index.d.ts.map +1 -0
  104. package/dist/esm/index.js +14 -0
  105. package/dist/esm/index.js.map +1 -0
  106. package/dist/esm/isUnexpected.d.ts +11 -0
  107. package/dist/esm/isUnexpected.d.ts.map +1 -0
  108. package/dist/esm/isUnexpected.js +78 -0
  109. package/dist/esm/isUnexpected.js.map +1 -0
  110. package/dist/esm/logger.d.ts +2 -0
  111. package/dist/esm/logger.d.ts.map +1 -0
  112. package/dist/esm/logger.js +5 -0
  113. package/dist/esm/logger.js.map +1 -0
  114. package/dist/esm/models.d.ts +69 -0
  115. package/dist/esm/models.d.ts.map +1 -0
  116. package/dist/esm/models.js +4 -0
  117. package/dist/esm/models.js.map +1 -0
  118. package/dist/esm/outputModels.d.ts +144 -0
  119. package/dist/esm/outputModels.d.ts.map +1 -0
  120. package/dist/esm/outputModels.js +4 -0
  121. package/dist/esm/outputModels.js.map +1 -0
  122. package/dist/esm/package.json +3 -0
  123. package/dist/esm/paginateHelper.d.ts +68 -0
  124. package/dist/esm/paginateHelper.d.ts.map +1 -0
  125. package/dist/esm/paginateHelper.js +167 -0
  126. package/dist/esm/paginateHelper.js.map +1 -0
  127. package/dist/esm/parameters.d.ts +98 -0
  128. package/dist/esm/parameters.d.ts.map +1 -0
  129. package/dist/esm/parameters.js +4 -0
  130. package/dist/esm/parameters.js.map +1 -0
  131. package/dist/esm/pollingHelper.d.ts +76 -0
  132. package/dist/esm/pollingHelper.d.ts.map +1 -0
  133. package/dist/esm/pollingHelper.js +104 -0
  134. package/dist/esm/pollingHelper.js.map +1 -0
  135. package/dist/esm/responses.d.ts +725 -0
  136. package/dist/esm/responses.d.ts.map +1 -0
  137. package/dist/esm/responses.js +4 -0
  138. package/dist/esm/responses.js.map +1 -0
  139. package/dist/react-native/clientDefinitions.d.ts +125 -0
  140. package/dist/react-native/clientDefinitions.d.ts.map +1 -0
  141. package/dist/react-native/clientDefinitions.js +4 -0
  142. package/dist/react-native/clientDefinitions.js.map +1 -0
  143. package/dist/react-native/documentTranslator.d.ts +14 -0
  144. package/dist/react-native/documentTranslator.d.ts.map +1 -0
  145. package/dist/react-native/documentTranslator.js +33 -0
  146. package/dist/react-native/documentTranslator.js.map +1 -0
  147. package/dist/react-native/index.d.ts +12 -0
  148. package/dist/react-native/index.d.ts.map +1 -0
  149. package/dist/react-native/index.js +14 -0
  150. package/dist/react-native/index.js.map +1 -0
  151. package/dist/react-native/isUnexpected.d.ts +11 -0
  152. package/dist/react-native/isUnexpected.d.ts.map +1 -0
  153. package/dist/react-native/isUnexpected.js +78 -0
  154. package/dist/react-native/isUnexpected.js.map +1 -0
  155. package/dist/react-native/logger.d.ts +2 -0
  156. package/dist/react-native/logger.d.ts.map +1 -0
  157. package/dist/react-native/logger.js +5 -0
  158. package/dist/react-native/logger.js.map +1 -0
  159. package/dist/react-native/models.d.ts +69 -0
  160. package/dist/react-native/models.d.ts.map +1 -0
  161. package/dist/react-native/models.js +4 -0
  162. package/dist/react-native/models.js.map +1 -0
  163. package/dist/react-native/outputModels.d.ts +144 -0
  164. package/dist/react-native/outputModels.d.ts.map +1 -0
  165. package/dist/react-native/outputModels.js +4 -0
  166. package/dist/react-native/outputModels.js.map +1 -0
  167. package/dist/react-native/package.json +3 -0
  168. package/dist/react-native/paginateHelper.d.ts +68 -0
  169. package/dist/react-native/paginateHelper.d.ts.map +1 -0
  170. package/dist/react-native/paginateHelper.js +167 -0
  171. package/dist/react-native/paginateHelper.js.map +1 -0
  172. package/dist/react-native/parameters.d.ts +98 -0
  173. package/dist/react-native/parameters.d.ts.map +1 -0
  174. package/dist/react-native/parameters.js +4 -0
  175. package/dist/react-native/parameters.js.map +1 -0
  176. package/dist/react-native/pollingHelper.d.ts +76 -0
  177. package/dist/react-native/pollingHelper.d.ts.map +1 -0
  178. package/dist/react-native/pollingHelper.js +104 -0
  179. package/dist/react-native/pollingHelper.js.map +1 -0
  180. package/dist/react-native/responses.d.ts +725 -0
  181. package/dist/react-native/responses.d.ts.map +1 -0
  182. package/dist/react-native/responses.js +4 -0
  183. package/dist/react-native/responses.js.map +1 -0
  184. package/package.json +86 -71
  185. package/CHANGELOG.md +0 -5
  186. package/dist/index.js +0 -19
  187. package/dist/index.js.map +0 -1
  188. package/dist-esm/src/constants.js +0 -7
  189. package/dist-esm/src/constants.js.map +0 -1
  190. package/dist-esm/src/documentTranslator.js +0 -13
  191. package/dist-esm/src/documentTranslator.js.map +0 -1
  192. package/dist-esm/src/index.js +0 -13
  193. package/dist-esm/src/index.js.map +0 -1
  194. package/dist-esm/src/models.js +0 -4
  195. package/dist-esm/src/models.js.map +0 -1
  196. package/dist-esm/src/parameters.js +0 -4
  197. package/dist-esm/src/parameters.js.map +0 -1
  198. package/dist-esm/src/responses.js +0 -4
  199. package/dist-esm/src/responses.js.map +0 -1
@@ -0,0 +1,78 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ const responseMap = {
4
+ "GET /batches": ["200"],
5
+ "POST /batches": ["202"],
6
+ "GET /batches/{id}/documents/{documentId}": ["200"],
7
+ "GET /batches/{id}": ["200"],
8
+ "DELETE /batches/{id}": ["200"],
9
+ "GET /batches/{id}/documents": ["200"],
10
+ "GET /documents/formats": ["200"],
11
+ "GET /glossaries/formats": ["200"],
12
+ "GET /storagesources": ["200"],
13
+ };
14
+ export function isUnexpected(response) {
15
+ const lroOriginal = response.headers["x-ms-original-url"];
16
+ const url = new URL(lroOriginal !== null && lroOriginal !== void 0 ? lroOriginal : response.request.url);
17
+ const method = response.request.method;
18
+ let pathDetails = responseMap[`${method} ${url.pathname}`];
19
+ if (!pathDetails) {
20
+ pathDetails = getParametrizedPathSuccess(method, url.pathname);
21
+ }
22
+ return !pathDetails.includes(response.status);
23
+ }
24
+ function getParametrizedPathSuccess(method, path) {
25
+ var _a, _b, _c, _d;
26
+ const pathParts = path.split("/");
27
+ // Traverse list to match the longest candidate
28
+ // matchedLen: the length of candidate path
29
+ // matchedValue: the matched status code array
30
+ let matchedLen = -1, matchedValue = [];
31
+ // Iterate the responseMap to find a match
32
+ for (const [key, value] of Object.entries(responseMap)) {
33
+ // Extracting the path from the map key which is in format
34
+ // GET /path/foo
35
+ if (!key.startsWith(method)) {
36
+ continue;
37
+ }
38
+ const candidatePath = getPathFromMapKey(key);
39
+ // Get each part of the url path
40
+ const candidateParts = candidatePath.split("/");
41
+ // track if we have found a match to return the values found.
42
+ let found = true;
43
+ for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
44
+ if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) && ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
45
+ const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length;
46
+ // If the current part of the candidate is a "template" part
47
+ // Try to use the suffix of pattern to match the path
48
+ // {guid} ==> $
49
+ // {guid}:export ==> :export$
50
+ const isMatched = new RegExp(`${(_d = candidateParts[i]) === null || _d === void 0 ? void 0 : _d.slice(start, end)}`).test(pathParts[j] || "");
51
+ if (!isMatched) {
52
+ found = false;
53
+ break;
54
+ }
55
+ continue;
56
+ }
57
+ // If the candidate part is not a template and
58
+ // the parts don't match mark the candidate as not found
59
+ // to move on with the next candidate path.
60
+ if (candidateParts[i] !== pathParts[j]) {
61
+ found = false;
62
+ break;
63
+ }
64
+ }
65
+ // We finished evaluating the current candidate parts
66
+ // Update the matched value if and only if we found the longer pattern
67
+ if (found && candidatePath.length > matchedLen) {
68
+ matchedLen = candidatePath.length;
69
+ matchedValue = value;
70
+ }
71
+ }
72
+ return matchedValue;
73
+ }
74
+ function getPathFromMapKey(mapKey) {
75
+ const pathStart = mapKey.indexOf("/");
76
+ return mapKey.slice(pathStart);
77
+ }
78
+ //# sourceMappingURL=isUnexpected.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../src/isUnexpected.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAsDlC,MAAM,WAAW,GAA6B;IAC5C,cAAc,EAAE,CAAC,KAAK,CAAC;IACvB,eAAe,EAAE,CAAC,KAAK,CAAC;IACxB,0CAA0C,EAAE,CAAC,KAAK,CAAC;IACnD,mBAAmB,EAAE,CAAC,KAAK,CAAC;IAC5B,sBAAsB,EAAE,CAAC,KAAK,CAAC;IAC/B,6BAA6B,EAAE,CAAC,KAAK,CAAC;IACtC,wBAAwB,EAAE,C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QACH,CAAC;QAED,qDAAqD;QACrD,sEAAsE;QACtE,IAAI,KAAK,IAAI,aAAa,CAAC,MAAM,GAAG,UAAU,EAAE,CAAC;YAC/C,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC;YAClC,YAAY,GAAG,KAAK,CAAC;QACvB,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAc;IACvC,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACjC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n DocumentTranslationStartTranslation202Response,\n DocumentTranslationStartTranslation400Response,\n DocumentTranslationStartTranslation401Response,\n DocumentTranslationStartTranslation429Response,\n DocumentTranslationStartTranslation500Response,\n DocumentTranslationStartTranslation503Response,\n DocumentTranslationGetTranslationsStatus200Response,\n DocumentTranslationGetTranslationsStatus400Response,\n DocumentTranslationGetTranslationsStatus401Response,\n DocumentTranslationGetTranslationsStatus429Response,\n DocumentTranslationGetTranslationsStatus500Response,\n DocumentTranslationGetTranslationsStatus503Response,\n DocumentTranslationGetDocumentStatus200Response,\n DocumentTranslationGetDocumentStatus401Response,\n DocumentTranslationGetDocumentStatus404Response,\n DocumentTranslationGetDocumentStatus429Response,\n DocumentTranslationGetDocumentStatus500Response,\n DocumentTranslationGetDocumentStatus503Response,\n DocumentTranslationGetTranslationStatus200Response,\n DocumentTranslationGetTranslationStatus401Response,\n DocumentTranslationGetTranslationStatus404Response,\n DocumentTranslationGetTranslationStatus429Response,\n DocumentTranslationGetTranslationStatus500Response,\n DocumentTranslationGetTranslationStatus503Response,\n DocumentTranslationCancelTranslation200Response,\n DocumentTranslationCancelTranslation401Response,\n DocumentTranslationCancelTranslation404Response,\n DocumentTranslationCancelTranslation429Response,\n DocumentTranslationCancelTranslation500Response,\n DocumentTranslationCancelTranslation503Response,\n DocumentTranslationGetDocumentsStatus200Response,\n DocumentTranslationGetDocumentsStatus400Response,\n DocumentTranslationGetDocumentsStatus401Response,\n DocumentTranslationGetDocumentsStatus404Response,\n DocumentTranslationGetDocumentsStatus429Response,\n DocumentTranslationGetDocumentsStatus500Response,\n DocumentTranslationGetDocumentsStatus503Response,\n DocumentTranslationGetSupportedDocumentFormats200Response,\n DocumentTranslationGetSupportedDocumentFormats429Response,\n DocumentTranslationGetSupportedDocumentFormats500Response,\n DocumentTranslationGetSupportedDocumentFormats503Response,\n DocumentTranslationGetSupportedGlossaryFormats200Response,\n DocumentTranslationGetSupportedGlossaryFormats429Response,\n DocumentTranslationGetSupportedGlossaryFormats500Response,\n DocumentTranslationGetSupportedGlossaryFormats503Response,\n DocumentTranslationGetSupportedStorageSources200Response,\n DocumentTranslationGetSupportedStorageSources429Response,\n DocumentTranslationGetSupportedStorageSources500Response,\n DocumentTranslationGetSupportedStorageSources503Response,\n} from \"./responses.js\";\n\nconst responseMap: Record<string, string[]> = {\n \"GET /batches\": [\"200\"],\n \"POST /batches\": [\"202\"],\n \"GET /batches/{id}/documents/{documentId}\": [\"200\"],\n \"GET /batches/{id}\": [\"200\"],\n \"DELETE /batches/{id}\": [\"200\"],\n \"GET /batches/{id}/documents\": [\"200\"],\n \"GET /documents/formats\": [\"200\"],\n \"GET /glossaries/formats\": [\"200\"],\n \"GET /storagesources\": [\"200\"],\n};\n\nexport function isUnexpected(\n response:\n | DocumentTranslationStartTranslation202Response\n | DocumentTranslationStartTranslation400Response\n | DocumentTranslationStartTranslation401Response\n | DocumentTranslationStartTranslation429Response\n | DocumentTranslationStartTranslation500Response\n | DocumentTranslationStartTranslation503Response,\n): response is DocumentTranslationStartTranslation400Response;\nexport function isUnexpected(\n response:\n | DocumentTranslationGetTranslationsStatus200Response\n | DocumentTranslationGetTranslationsStatus400Response\n | DocumentTranslationGetTranslationsStatus401Response\n | DocumentTranslationGetTranslationsStatus429Response\n | DocumentTranslationGetTranslationsStatus500Response\n | DocumentTranslationGetTranslationsStatus503Response,\n): response is DocumentTranslationGetTranslationsStatus400Response;\nexport function isUnexpected(\n response:\n | DocumentTranslationGetDocumentStatus200Response\n | DocumentTranslationGetDocumentStatus401Response\n | DocumentTranslationGetDocumentStatus404Response\n | DocumentTranslationGetDocumentStatus429Response\n | DocumentTranslationGetDocumentStatus500Response\n | DocumentTranslationGetDocumentStatus503Response,\n): response is DocumentTranslationGetDocumentStatus401Response;\nexport function isUnexpected(\n response:\n | DocumentTranslationGetTranslationStatus200Response\n | DocumentTranslationGetTranslationStatus401Response\n | DocumentTranslationGetTranslationStatus404Response\n | DocumentTranslationGetTranslationStatus429Response\n | DocumentTranslationGetTranslationStatus500Response\n | DocumentTranslationGetTranslationStatus503Response,\n): response is DocumentTranslationGetTranslationStatus401Response;\nexport function isUnexpected(\n response:\n | DocumentTranslationCancelTranslation200Response\n | DocumentTranslationCancelTranslation401Response\n | DocumentTranslationCancelTranslation404Response\n | DocumentTranslationCancelTranslation429Response\n | DocumentTranslationCancelTranslation500Response\n | DocumentTranslationCancelTranslation503Response,\n): response is DocumentTranslationCancelTranslation401Response;\nexport function isUnexpected(\n response:\n | DocumentTranslationGetDocumentsStatus200Response\n | DocumentTranslationGetDocumentsStatus400Response\n | DocumentTranslationGetDocumentsStatus401Response\n | DocumentTranslationGetDocumentsStatus404Response\n | DocumentTranslationGetDocumentsStatus429Response\n | DocumentTranslationGetDocumentsStatus500Response\n | DocumentTranslationGetDocumentsStatus503Response,\n): response is DocumentTranslationGetDocumentsStatus400Response;\nexport function isUnexpected(\n response:\n | DocumentTranslationGetSupportedDocumentFormats200Response\n | DocumentTranslationGetSupportedDocumentFormats429Response\n | DocumentTranslationGetSupportedDocumentFormats500Response\n | DocumentTranslationGetSupportedDocumentFormats503Response,\n): response is DocumentTranslationGetSupportedDocumentFormats429Response;\nexport function isUnexpected(\n response:\n | DocumentTranslationGetSupportedGlossaryFormats200Response\n | DocumentTranslationGetSupportedGlossaryFormats429Response\n | DocumentTranslationGetSupportedGlossaryFormats500Response\n | DocumentTranslationGetSupportedGlossaryFormats503Response,\n): response is DocumentTranslationGetSupportedGlossaryFormats429Response;\nexport function isUnexpected(\n response:\n | DocumentTranslationGetSupportedStorageSources200Response\n | DocumentTranslationGetSupportedStorageSources429Response\n | DocumentTranslationGetSupportedStorageSources500Response\n | DocumentTranslationGetSupportedStorageSources503Response,\n): response is DocumentTranslationGetSupportedStorageSources429Response;\nexport function isUnexpected(\n response:\n | DocumentTranslationStartTranslation202Response\n | DocumentTranslationStartTranslation400Response\n | DocumentTranslationStartTranslation401Response\n | DocumentTranslationStartTranslation429Response\n | DocumentTranslationStartTranslation500Response\n | DocumentTranslationStartTranslation503Response\n | DocumentTranslationGetTranslationsStatus200Response\n | DocumentTranslationGetTranslationsStatus400Response\n | DocumentTranslationGetTranslationsStatus401Response\n | DocumentTranslationGetTranslationsStatus429Response\n | DocumentTranslationGetTranslationsStatus500Response\n | DocumentTranslationGetTranslationsStatus503Response\n | DocumentTranslationGetDocumentStatus200Response\n | DocumentTranslationGetDocumentStatus401Response\n | DocumentTranslationGetDocumentStatus404Response\n | DocumentTranslationGetDocumentStatus429Response\n | DocumentTranslationGetDocumentStatus500Response\n | DocumentTranslationGetDocumentStatus503Response\n | DocumentTranslationGetTranslationStatus200Response\n | DocumentTranslationGetTranslationStatus401Response\n | DocumentTranslationGetTranslationStatus404Response\n | DocumentTranslationGetTranslationStatus429Response\n | DocumentTranslationGetTranslationStatus500Response\n | DocumentTranslationGetTranslationStatus503Response\n | DocumentTranslationCancelTranslation200Response\n | DocumentTranslationCancelTranslation401Response\n | DocumentTranslationCancelTranslation404Response\n | DocumentTranslationCancelTranslation429Response\n | DocumentTranslationCancelTranslation500Response\n | DocumentTranslationCancelTranslation503Response\n | DocumentTranslationGetDocumentsStatus200Response\n | DocumentTranslationGetDocumentsStatus400Response\n | DocumentTranslationGetDocumentsStatus401Response\n | DocumentTranslationGetDocumentsStatus404Response\n | DocumentTranslationGetDocumentsStatus429Response\n | DocumentTranslationGetDocumentsStatus500Response\n | DocumentTranslationGetDocumentsStatus503Response\n | DocumentTranslationGetSupportedDocumentFormats200Response\n | DocumentTranslationGetSupportedDocumentFormats429Response\n | DocumentTranslationGetSupportedDocumentFormats500Response\n | DocumentTranslationGetSupportedDocumentFormats503Response\n | DocumentTranslationGetSupportedGlossaryFormats200Response\n | DocumentTranslationGetSupportedGlossaryFormats429Response\n | DocumentTranslationGetSupportedGlossaryFormats500Response\n | DocumentTranslationGetSupportedGlossaryFormats503Response\n | DocumentTranslationGetSupportedStorageSources200Response\n | DocumentTranslationGetSupportedStorageSources429Response\n | DocumentTranslationGetSupportedStorageSources500Response\n | DocumentTranslationGetSupportedStorageSources503Response,\n): response is\n | DocumentTranslationStartTranslation400Response\n | DocumentTranslationStartTranslation401Response\n | DocumentTranslationStartTranslation429Response\n | DocumentTranslationStartTranslation500Response\n | DocumentTranslationStartTranslation503Response\n | DocumentTranslationGetTranslationsStatus400Response\n | DocumentTranslationGetTranslationsStatus401Response\n | DocumentTranslationGetTranslationsStatus429Response\n | DocumentTranslationGetTranslationsStatus500Response\n | DocumentTranslationGetTranslationsStatus503Response\n | DocumentTranslationGetDocumentStatus401Response\n | DocumentTranslationGetDocumentStatus404Response\n | DocumentTranslationGetDocumentStatus429Response\n | DocumentTranslationGetDocumentStatus500Response\n | DocumentTranslationGetDocumentStatus503Response\n | DocumentTranslationGetTranslationStatus401Response\n | DocumentTranslationGetTranslationStatus404Response\n | DocumentTranslationGetTranslationStatus429Response\n | DocumentTranslationGetTranslationStatus500Response\n | DocumentTranslationGetTranslationStatus503Response\n | DocumentTranslationCancelTranslation401Response\n | DocumentTranslationCancelTranslation404Response\n | DocumentTranslationCancelTranslation429Response\n | DocumentTranslationCancelTranslation500Response\n | DocumentTranslationCancelTranslation503Response\n | DocumentTranslationGetDocumentsStatus400Response\n | DocumentTranslationGetDocumentsStatus401Response\n | DocumentTranslationGetDocumentsStatus404Response\n | DocumentTranslationGetDocumentsStatus429Response\n | DocumentTranslationGetDocumentsStatus500Response\n | DocumentTranslationGetDocumentsStatus503Response\n | DocumentTranslationGetSupportedDocumentFormats429Response\n | DocumentTranslationGetSupportedDocumentFormats500Response\n | DocumentTranslationGetSupportedDocumentFormats503Response\n | DocumentTranslationGetSupportedGlossaryFormats429Response\n | DocumentTranslationGetSupportedGlossaryFormats500Response\n | DocumentTranslationGetSupportedGlossaryFormats503Response\n | DocumentTranslationGetSupportedStorageSources429Response\n | DocumentTranslationGetSupportedStorageSources500Response\n | DocumentTranslationGetSupportedStorageSources503Response {\n const lroOriginal = response.headers[\"x-ms-original-url\"];\n const url = new URL(lroOriginal ?? response.request.url);\n const method = response.request.method;\n let pathDetails = responseMap[`${method} ${url.pathname}`];\n if (!pathDetails) {\n pathDetails = getParametrizedPathSuccess(method, url.pathname);\n }\n return !pathDetails.includes(response.status);\n}\n\nfunction getParametrizedPathSuccess(method: string, path: string): string[] {\n const pathParts = path.split(\"/\");\n\n // Traverse list to match the longest candidate\n // matchedLen: the length of candidate path\n // matchedValue: the matched status code array\n let matchedLen = -1,\n matchedValue: string[] = [];\n\n // Iterate the responseMap to find a match\n for (const [key, value] of Object.entries(responseMap)) {\n // Extracting the path from the map key which is in format\n // GET /path/foo\n if (!key.startsWith(method)) {\n continue;\n }\n const candidatePath = getPathFromMapKey(key);\n // Get each part of the url path\n const candidateParts = candidatePath.split(\"/\");\n\n // track if we have found a match to return the values found.\n let found = true;\n for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {\n if (candidateParts[i]?.startsWith(\"{\") && candidateParts[i]?.indexOf(\"}\") !== -1) {\n const start = candidateParts[i]!.indexOf(\"}\") + 1,\n end = candidateParts[i]?.length;\n // If the current part of the candidate is a \"template\" part\n // Try to use the suffix of pattern to match the path\n // {guid} ==> $\n // {guid}:export ==> :export$\n const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(\n pathParts[j] || \"\",\n );\n\n if (!isMatched) {\n found = false;\n break;\n }\n continue;\n }\n\n // If the candidate part is not a template and\n // the parts don't match mark the candidate as not found\n // to move on with the next candidate path.\n if (candidateParts[i] !== pathParts[j]) {\n found = false;\n break;\n }\n }\n\n // We finished evaluating the current candidate parts\n // Update the matched value if and only if we found the longer pattern\n if (found && candidatePath.length > matchedLen) {\n matchedLen = candidatePath.length;\n matchedValue = value;\n }\n }\n\n return matchedValue;\n}\n\nfunction getPathFromMapKey(mapKey: string): string {\n const pathStart = mapKey.indexOf(\"/\");\n return mapKey.slice(pathStart);\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const logger: import("@azure/logger").AzureLogger;
2
+ //# sourceMappingURL=logger.d.ts.map
@@ -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,5 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { createClientLogger } from "@azure/logger";
4
+ export const logger = createClientLogger("ai-document-translator");
5
+ //# 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,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC,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,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Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ export {};
4
+ //# sourceMappingURL=models.js.map
@@ -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,qCAAq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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,4 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ export {};
4
+ //# sourceMappingURL=outputModels.js.map
@@ -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,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -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>>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pD,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,167 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { __asyncDelegator, __asyncGenerator, __asyncValues, __await } from "tslib";
4
+ import { createRestError } from "@azure-rest/core-client";
5
+ /**
6
+ * returns an async iterator that iterates over results. It also has a `byPage`
7
+ * method that returns pages of items at once.
8
+ *
9
+ * @param pagedResult - an object that specifies how to get pages.
10
+ * @returns a paged async iterator that iterates over results.
11
+ */
12
+ function getPagedAsyncIterator(pagedResult) {
13
+ var _a;
14
+ const iter = getItemAsyncIterator(pagedResult);
15
+ return {
16
+ next() {
17
+ return iter.next();
18
+ },
19
+ [Symbol.asyncIterator]() {
20
+ return this;
21
+ },
22
+ byPage: (_a = pagedResult === null || pagedResult === void 0 ? void 0 : pagedResult.byPage) !== null && _a !== void 0 ? _a : ((settings) => {
23
+ const { continuationToken } = settings !== null && settings !== void 0 ? settings : {};
24
+ return getPageAsyncIterator(pagedResult, {
25
+ pageLink: continuationToken,
26
+ });
27
+ }),
28
+ };
29
+ }
30
+ function getItemAsyncIterator(pagedResult) {
31
+ return __asyncGenerator(this, arguments, function* getItemAsyncIterator_1() {
32
+ var _a, e_1, _b, _c, _d, e_2, _e, _f;
33
+ const pages = getPageAsyncIterator(pagedResult);
34
+ const firstVal = yield __await(pages.next());
35
+ // if the result does not have an array shape, i.e. TPage = TElement, then we return it as is
36
+ if (!Array.isArray(firstVal.value)) {
37
+ // can extract elements from this page
38
+ const { toElements } = pagedResult;
39
+ if (toElements) {
40
+ yield __await(yield* __asyncDelegator(__asyncValues(toElements(firstVal.value))));
41
+ try {
42
+ for (var _g = true, pages_1 = __asyncValues(pages), pages_1_1; pages_1_1 = yield __await(pages_1.next()), _a = pages_1_1.done, !_a; _g = true) {
43
+ _c = pages_1_1.value;
44
+ _g = false;
45
+ const page = _c;
46
+ yield __await(yield* __asyncDelegator(__asyncValues(toElements(page))));
47
+ }
48
+ }
49
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
50
+ finally {
51
+ try {
52
+ if (!_g && !_a && (_b = pages_1.return)) yield __await(_b.call(pages_1));
53
+ }
54
+ finally { if (e_1) throw e_1.error; }
55
+ }
56
+ }
57
+ else {
58
+ yield yield __await(firstVal.value);
59
+ // `pages` is of type `AsyncIterableIterator<TPage>` but TPage = TElement in this case
60
+ yield __await(yield* __asyncDelegator(__asyncValues(pages)));
61
+ }
62
+ }
63
+ else {
64
+ yield __await(yield* __asyncDelegator(__asyncValues(firstVal.value)));
65
+ try {
66
+ for (var _h = true, pages_2 = __asyncValues(pages), pages_2_1; pages_2_1 = yield __await(pages_2.next()), _d = pages_2_1.done, !_d; _h = true) {
67
+ _f = pages_2_1.value;
68
+ _h = false;
69
+ const page = _f;
70
+ // pages is of type `AsyncIterableIterator<TPage>` so `page` is of type `TPage`. In this branch,
71
+ // it must be the case that `TPage = TElement[]`
72
+ yield __await(yield* __asyncDelegator(__asyncValues(page)));
73
+ }
74
+ }
75
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
76
+ finally {
77
+ try {
78
+ if (!_h && !_d && (_e = pages_2.return)) yield __await(_e.call(pages_2));
79
+ }
80
+ finally { if (e_2) throw e_2.error; }
81
+ }
82
+ }
83
+ });
84
+ }
85
+ function getPageAsyncIterator(pagedResult_1) {
86
+ return __asyncGenerator(this, arguments, function* getPageAsyncIterator_1(pagedResult, options = {}) {
87
+ const { pageLink } = options;
88
+ let response = yield __await(pagedResult.getPage(pageLink !== null && pageLink !== void 0 ? pageLink : pagedResult.firstPageLink));
89
+ if (!response) {
90
+ return yield __await(void 0);
91
+ }
92
+ yield yield __await(response.page);
93
+ while (response.nextPageLink) {
94
+ response = yield __await(pagedResult.getPage(response.nextPageLink));
95
+ if (!response) {
96
+ return yield __await(void 0);
97
+ }
98
+ yield yield __await(response.page);
99
+ }
100
+ });
101
+ }
102
+ /**
103
+ * Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension
104
+ * @param client - Client to use for sending the next page requests
105
+ * @param initialResponse - Initial response containing the nextLink and current page of elements
106
+ * @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results
107
+ * @returns - PagedAsyncIterableIterator to iterate the elements
108
+ */
109
+ export function paginate(client, initialResponse, options = {}) {
110
+ let firstRun = true;
111
+ const itemName = "value";
112
+ const nextLinkName = "nextLink";
113
+ const { customGetPage } = options;
114
+ const pagedResult = {
115
+ firstPageLink: "",
116
+ getPage: typeof customGetPage === "function"
117
+ ? customGetPage
118
+ : async (pageLink) => {
119
+ const result = firstRun ? initialResponse : await client.pathUnchecked(pageLink).get();
120
+ firstRun = false;
121
+ checkPagingRequest(result);
122
+ const nextLink = getNextLink(result.body, nextLinkName);
123
+ const values = getElements(result.body, itemName);
124
+ return {
125
+ page: values,
126
+ nextPageLink: nextLink,
127
+ };
128
+ },
129
+ };
130
+ return getPagedAsyncIterator(pagedResult);
131
+ }
132
+ /**
133
+ * Gets for the value of nextLink in the body
134
+ */
135
+ function getNextLink(body, nextLinkName) {
136
+ if (!nextLinkName) {
137
+ return undefined;
138
+ }
139
+ const nextLink = body[nextLinkName];
140
+ if (typeof nextLink !== "string" && typeof nextLink !== "undefined") {
141
+ throw new Error(`Body Property ${nextLinkName} should be a string or undefined`);
142
+ }
143
+ return nextLink;
144
+ }
145
+ /**
146
+ * Gets the elements of the current request in the body.
147
+ */
148
+ function getElements(body, itemName) {
149
+ const value = body[itemName];
150
+ // value has to be an array according to the x-ms-pageable extension.
151
+ // The fact that this must be an array is used above to calculate the
152
+ // type of elements in the page in PaginateReturn
153
+ if (!Array.isArray(value)) {
154
+ throw new Error(`Couldn't paginate response\n Body doesn't contain an array property with name: ${itemName}`);
155
+ }
156
+ return value !== null && value !== void 0 ? value : [];
157
+ }
158
+ /**
159
+ * Checks if a request failed
160
+ */
161
+ function checkPagingRequest(response) {
162
+ const Http2xxStatusCodes = ["200", "201", "202", "203", "204", "205", "206", "207", "208", "226"];
163
+ if (!Http2xxStatusCodes.includes(response.status)) {
164
+ throw createRestError(`Pagination failed with unexpected statusCode ${response.status}`, response);
165
+ }
166
+ }
167
+ //# sourceMappingURL=paginateHelper.js.map