@azure-rest/ai-translation-document 1.0.0-alpha.20250227.1 → 1.0.0-alpha.20250303.1

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 (190) hide show
  1. package/README.md +227 -167
  2. package/dist/browser/clientDefinitions.d.ts +191 -0
  3. package/dist/browser/clientDefinitions.d.ts.map +1 -0
  4. package/dist/browser/documentTranslationClient.d.ts +16 -0
  5. package/dist/browser/documentTranslationClient.d.ts.map +1 -0
  6. package/{dist-esm/src → dist/browser}/documentTranslationClient.js +1 -1
  7. package/dist/browser/documentTranslationClient.js.map +1 -0
  8. package/dist/browser/index.d.ts +12 -0
  9. package/dist/browser/index.d.ts.map +1 -0
  10. package/dist/browser/index.js +14 -0
  11. package/dist/browser/index.js.map +1 -0
  12. package/dist/browser/isUnexpected.d.ts +10 -0
  13. package/dist/browser/isUnexpected.d.ts.map +1 -0
  14. package/dist/browser/logger.d.ts +2 -0
  15. package/dist/browser/logger.d.ts.map +1 -0
  16. package/dist/browser/models.d.ts +112 -0
  17. package/dist/browser/models.d.ts.map +1 -0
  18. package/dist/browser/outputModels.d.ts +166 -0
  19. package/dist/browser/outputModels.d.ts.map +1 -0
  20. package/dist/browser/package.json +3 -0
  21. package/dist/browser/paginateHelper.d.ts +43 -0
  22. package/dist/browser/paginateHelper.d.ts.map +1 -0
  23. package/dist/browser/parameters.d.ts +184 -0
  24. package/dist/browser/parameters.d.ts.map +1 -0
  25. package/dist/browser/pollingHelper.d.ts +77 -0
  26. package/dist/browser/pollingHelper.d.ts.map +1 -0
  27. package/dist/browser/responses.d.ts +132 -0
  28. package/dist/browser/responses.d.ts.map +1 -0
  29. package/dist/commonjs/clientDefinitions.d.ts +191 -0
  30. package/dist/commonjs/clientDefinitions.d.ts.map +1 -0
  31. package/dist/commonjs/clientDefinitions.js +3 -0
  32. package/dist/commonjs/clientDefinitions.js.map +1 -0
  33. package/dist/commonjs/documentTranslationClient.d.ts +16 -0
  34. package/dist/commonjs/documentTranslationClient.d.ts.map +1 -0
  35. package/dist/commonjs/documentTranslationClient.js +45 -0
  36. package/dist/commonjs/documentTranslationClient.js.map +1 -0
  37. package/dist/commonjs/index.d.ts +12 -0
  38. package/dist/commonjs/index.d.ts.map +1 -0
  39. package/dist/commonjs/index.js +17 -0
  40. package/dist/commonjs/index.js.map +1 -0
  41. package/dist/commonjs/isUnexpected.d.ts +10 -0
  42. package/dist/commonjs/isUnexpected.d.ts.map +1 -0
  43. package/dist/commonjs/isUnexpected.js +78 -0
  44. package/dist/commonjs/isUnexpected.js.map +1 -0
  45. package/dist/commonjs/logger.d.ts +2 -0
  46. package/dist/commonjs/logger.d.ts.map +1 -0
  47. package/dist/commonjs/logger.js +8 -0
  48. package/dist/commonjs/logger.js.map +1 -0
  49. package/dist/commonjs/models.d.ts +112 -0
  50. package/dist/commonjs/models.d.ts.map +1 -0
  51. package/dist/commonjs/models.js +5 -0
  52. package/dist/commonjs/models.js.map +1 -0
  53. package/dist/commonjs/outputModels.d.ts +166 -0
  54. package/dist/commonjs/outputModels.d.ts.map +1 -0
  55. package/dist/commonjs/outputModels.js +5 -0
  56. package/dist/commonjs/outputModels.js.map +1 -0
  57. package/dist/commonjs/package.json +3 -0
  58. package/dist/commonjs/paginateHelper.d.ts +43 -0
  59. package/dist/commonjs/paginateHelper.d.ts.map +1 -0
  60. package/dist/commonjs/paginateHelper.js +71 -0
  61. package/dist/commonjs/paginateHelper.js.map +1 -0
  62. package/dist/commonjs/parameters.d.ts +184 -0
  63. package/dist/commonjs/parameters.d.ts.map +1 -0
  64. package/dist/commonjs/parameters.js +3 -0
  65. package/dist/commonjs/parameters.js.map +1 -0
  66. package/dist/commonjs/pollingHelper.d.ts +77 -0
  67. package/dist/commonjs/pollingHelper.d.ts.map +1 -0
  68. package/dist/commonjs/pollingHelper.js +98 -0
  69. package/dist/commonjs/pollingHelper.js.map +1 -0
  70. package/dist/commonjs/responses.d.ts +132 -0
  71. package/dist/commonjs/responses.d.ts.map +1 -0
  72. package/dist/commonjs/responses.js +3 -0
  73. package/dist/commonjs/responses.js.map +1 -0
  74. package/dist/commonjs/tsdoc-metadata.json +11 -0
  75. package/dist/esm/clientDefinitions.d.ts +191 -0
  76. package/dist/esm/clientDefinitions.d.ts.map +1 -0
  77. package/dist/esm/clientDefinitions.js +2 -0
  78. package/dist/esm/clientDefinitions.js.map +1 -0
  79. package/dist/esm/documentTranslationClient.d.ts +16 -0
  80. package/dist/esm/documentTranslationClient.d.ts.map +1 -0
  81. package/dist/esm/documentTranslationClient.js +42 -0
  82. package/dist/esm/documentTranslationClient.js.map +1 -0
  83. package/dist/esm/index.d.ts +12 -0
  84. package/dist/esm/index.d.ts.map +1 -0
  85. package/dist/esm/index.js +14 -0
  86. package/dist/esm/index.js.map +1 -0
  87. package/dist/esm/isUnexpected.d.ts +10 -0
  88. package/dist/esm/isUnexpected.d.ts.map +1 -0
  89. package/dist/esm/isUnexpected.js +75 -0
  90. package/dist/esm/isUnexpected.js.map +1 -0
  91. package/dist/esm/logger.d.ts +2 -0
  92. package/dist/esm/logger.d.ts.map +1 -0
  93. package/dist/esm/logger.js +5 -0
  94. package/dist/esm/logger.js.map +1 -0
  95. package/dist/esm/models.d.ts +112 -0
  96. package/dist/esm/models.d.ts.map +1 -0
  97. package/dist/esm/models.js +4 -0
  98. package/dist/esm/models.js.map +1 -0
  99. package/dist/esm/outputModels.d.ts +166 -0
  100. package/dist/esm/outputModels.d.ts.map +1 -0
  101. package/dist/esm/outputModels.js +4 -0
  102. package/dist/esm/outputModels.js.map +1 -0
  103. package/dist/esm/package.json +3 -0
  104. package/dist/esm/paginateHelper.d.ts +43 -0
  105. package/dist/esm/paginateHelper.d.ts.map +1 -0
  106. package/dist/esm/paginateHelper.js +68 -0
  107. package/dist/esm/paginateHelper.js.map +1 -0
  108. package/dist/esm/parameters.d.ts +184 -0
  109. package/dist/esm/parameters.d.ts.map +1 -0
  110. package/dist/esm/parameters.js +2 -0
  111. package/dist/esm/parameters.js.map +1 -0
  112. package/dist/esm/pollingHelper.d.ts +77 -0
  113. package/dist/esm/pollingHelper.d.ts.map +1 -0
  114. package/dist/esm/pollingHelper.js +95 -0
  115. package/dist/esm/pollingHelper.js.map +1 -0
  116. package/dist/esm/responses.d.ts +132 -0
  117. package/dist/esm/responses.d.ts.map +1 -0
  118. package/dist/esm/responses.js +2 -0
  119. package/dist/esm/responses.js.map +1 -0
  120. package/dist/react-native/clientDefinitions.d.ts +191 -0
  121. package/dist/react-native/clientDefinitions.d.ts.map +1 -0
  122. package/dist/react-native/clientDefinitions.js +2 -0
  123. package/dist/react-native/clientDefinitions.js.map +1 -0
  124. package/dist/react-native/documentTranslationClient.d.ts +16 -0
  125. package/dist/react-native/documentTranslationClient.d.ts.map +1 -0
  126. package/dist/react-native/documentTranslationClient.js +42 -0
  127. package/dist/react-native/documentTranslationClient.js.map +1 -0
  128. package/dist/react-native/index.d.ts +12 -0
  129. package/dist/react-native/index.d.ts.map +1 -0
  130. package/dist/react-native/index.js +14 -0
  131. package/dist/react-native/index.js.map +1 -0
  132. package/dist/react-native/isUnexpected.d.ts +10 -0
  133. package/dist/react-native/isUnexpected.d.ts.map +1 -0
  134. package/dist/react-native/isUnexpected.js +75 -0
  135. package/dist/react-native/isUnexpected.js.map +1 -0
  136. package/dist/react-native/logger.d.ts +2 -0
  137. package/dist/react-native/logger.d.ts.map +1 -0
  138. package/dist/react-native/logger.js +5 -0
  139. package/dist/react-native/logger.js.map +1 -0
  140. package/dist/react-native/models.d.ts +112 -0
  141. package/dist/react-native/models.d.ts.map +1 -0
  142. package/dist/react-native/models.js +4 -0
  143. package/dist/react-native/models.js.map +1 -0
  144. package/dist/react-native/outputModels.d.ts +166 -0
  145. package/dist/react-native/outputModels.d.ts.map +1 -0
  146. package/dist/react-native/outputModels.js +4 -0
  147. package/dist/react-native/outputModels.js.map +1 -0
  148. package/dist/react-native/package.json +3 -0
  149. package/dist/react-native/paginateHelper.d.ts +43 -0
  150. package/dist/react-native/paginateHelper.d.ts.map +1 -0
  151. package/dist/react-native/paginateHelper.js +68 -0
  152. package/dist/react-native/paginateHelper.js.map +1 -0
  153. package/dist/react-native/parameters.d.ts +184 -0
  154. package/dist/react-native/parameters.d.ts.map +1 -0
  155. package/dist/react-native/parameters.js +2 -0
  156. package/dist/react-native/parameters.js.map +1 -0
  157. package/dist/react-native/pollingHelper.d.ts +77 -0
  158. package/dist/react-native/pollingHelper.d.ts.map +1 -0
  159. package/dist/react-native/pollingHelper.js +95 -0
  160. package/dist/react-native/pollingHelper.js.map +1 -0
  161. package/dist/react-native/responses.d.ts +132 -0
  162. package/dist/react-native/responses.d.ts.map +1 -0
  163. package/dist/react-native/responses.js +2 -0
  164. package/dist/react-native/responses.js.map +1 -0
  165. package/package.json +68 -43
  166. package/CHANGELOG.md +0 -34
  167. package/dist/index.js +0 -293
  168. package/dist/index.js.map +0 -1
  169. package/dist-esm/src/documentTranslationClient.js.map +0 -1
  170. package/dist-esm/src/index.js +0 -14
  171. package/dist-esm/src/index.js.map +0 -1
  172. package/types/ai-translation-document.d.ts +0 -1018
  173. /package/{dist-esm/src → dist/browser}/clientDefinitions.js +0 -0
  174. /package/{dist-esm/src → dist/browser}/clientDefinitions.js.map +0 -0
  175. /package/{dist-esm/src → dist/browser}/isUnexpected.js +0 -0
  176. /package/{dist-esm/src → dist/browser}/isUnexpected.js.map +0 -0
  177. /package/{dist-esm/src → dist/browser}/logger.js +0 -0
  178. /package/{dist-esm/src → dist/browser}/logger.js.map +0 -0
  179. /package/{dist-esm/src → dist/browser}/models.js +0 -0
  180. /package/{dist-esm/src → dist/browser}/models.js.map +0 -0
  181. /package/{dist-esm/src → dist/browser}/outputModels.js +0 -0
  182. /package/{dist-esm/src → dist/browser}/outputModels.js.map +0 -0
  183. /package/{dist-esm/src → dist/browser}/paginateHelper.js +0 -0
  184. /package/{dist-esm/src → dist/browser}/paginateHelper.js.map +0 -0
  185. /package/{dist-esm/src → dist/browser}/parameters.js +0 -0
  186. /package/{dist-esm/src → dist/browser}/parameters.js.map +0 -0
  187. /package/{dist-esm/src → dist/browser}/pollingHelper.js +0 -0
  188. /package/{dist-esm/src → dist/browser}/pollingHelper.js.map +0 -0
  189. /package/{dist-esm/src → dist/browser}/responses.js +0 -0
  190. /package/{dist-esm/src → dist/browser}/responses.js.map +0 -0
@@ -0,0 +1,10 @@
1
+ import type { DocumentTranslate200Response, DocumentTranslateDefaultResponse, StartTranslation202Response, StartTranslationLogicalResponse, StartTranslationDefaultResponse, GetTranslationsStatus200Response, GetTranslationsStatusDefaultResponse, GetDocumentStatus200Response, GetDocumentStatusDefaultResponse, GetTranslationStatus200Response, GetTranslationStatusDefaultResponse, CancelTranslation200Response, CancelTranslationDefaultResponse, GetDocumentsStatus200Response, GetDocumentsStatusDefaultResponse, GetSupportedFormats200Response, GetSupportedFormatsDefaultResponse } from "./responses.js";
2
+ export declare function isUnexpected(response: DocumentTranslate200Response | DocumentTranslateDefaultResponse): response is DocumentTranslateDefaultResponse;
3
+ export declare function isUnexpected(response: StartTranslation202Response | StartTranslationLogicalResponse | StartTranslationDefaultResponse): response is StartTranslationDefaultResponse;
4
+ export declare function isUnexpected(response: GetTranslationsStatus200Response | GetTranslationsStatusDefaultResponse): response is GetTranslationsStatusDefaultResponse;
5
+ export declare function isUnexpected(response: GetDocumentStatus200Response | GetDocumentStatusDefaultResponse): response is GetDocumentStatusDefaultResponse;
6
+ export declare function isUnexpected(response: GetTranslationStatus200Response | GetTranslationStatusDefaultResponse): response is GetTranslationStatusDefaultResponse;
7
+ export declare function isUnexpected(response: CancelTranslation200Response | CancelTranslationDefaultResponse): response is CancelTranslationDefaultResponse;
8
+ export declare function isUnexpected(response: GetDocumentsStatus200Response | GetDocumentsStatusDefaultResponse): response is GetDocumentsStatusDefaultResponse;
9
+ export declare function isUnexpected(response: GetSupportedFormats200Response | GetSupportedFormatsDefaultResponse): response is GetSupportedFormatsDefaultResponse;
10
+ //# sourceMappingURL=isUnexpected.d.ts.map
@@ -0,0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ST /document:translate": ["200"],
3
+ "GET /document/batches": ["200"],
4
+ "POST /document/batches": ["202"],
5
+ "GET /document/batches/{id}/documents/{documentId}": ["200"],
6
+ "GET /document/batches/{id}": ["200"],
7
+ "DELETE /document/batches/{id}": ["200"],
8
+ "GET /document/batches/{id}/documents": ["200"],
9
+ "GET /document/formats": ["200"],
10
+ };
11
+ export function isUnexpected(response) {
12
+ const lroOriginal = response.headers["x-ms-original-url"];
13
+ const url = new URL(lroOriginal !== null && lroOriginal !== void 0 ? lroOriginal : response.request.url);
14
+ const method = response.request.method;
15
+ let pathDetails = responseMap[`${method} ${url.pathname}`];
16
+ if (!pathDetails) {
17
+ pathDetails = getParametrizedPathSuccess(method, url.pathname);
18
+ }
19
+ return !pathDetails.includes(response.status);
20
+ }
21
+ function getParametrizedPathSuccess(method, path) {
22
+ var _a, _b, _c, _d;
23
+ const pathParts = path.split("/");
24
+ // Traverse list to match the longest candidate
25
+ // matchedLen: the length of candidate path
26
+ // matchedValue: the matched status code array
27
+ let matchedLen = -1, matchedValue = [];
28
+ // Iterate the responseMap to find a match
29
+ for (const [key, value] of Object.entries(responseMap)) {
30
+ // Extracting the path from the map key which is in format
31
+ // GET /path/foo
32
+ if (!key.startsWith(method)) {
33
+ continue;
34
+ }
35
+ const candidatePath = getPathFromMapKey(key);
36
+ // Get each part of the url path
37
+ const candidateParts = candidatePath.split("/");
38
+ // track if we have found a match to return the values found.
39
+ let found = true;
40
+ for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
41
+ if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) && ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
42
+ const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length;
43
+ // If the current part of the candidate is a "template" part
44
+ // Try to use the suffix of pattern to match the path
45
+ // {guid} ==> $
46
+ // {guid}:export ==> :export$
47
+ const isMatched = new RegExp(`${(_d = candidateParts[i]) === null || _d === void 0 ? void 0 : _d.slice(start, end)}`).test(pathParts[j] || "");
48
+ if (!isMatched) {
49
+ found = false;
50
+ break;
51
+ }
52
+ continue;
53
+ }
54
+ // If the candidate part is not a template and
55
+ // the parts don't match mark the candidate as not found
56
+ // to move on with the next candidate path.
57
+ if (candidateParts[i] !== pathParts[j]) {
58
+ found = false;
59
+ break;
60
+ }
61
+ }
62
+ // We finished evaluating the current candidate parts
63
+ // Update the matched value if and only if we found the longer pattern
64
+ if (found && candidatePath.length > matchedLen) {
65
+ matchedLen = candidatePath.length;
66
+ matchedValue = value;
67
+ }
68
+ }
69
+ return matchedValue;
70
+ }
71
+ function getPathFromMapKey(mapKey) {
72
+ const pathStart = mapKey.indexOf("/");
73
+ return mapKey.slice(pathStart);
74
+ }
75
+ //# sourceMappingURL=isUnexpected.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../src/isUnexpected.ts"],"names":[],"mappings":"AAsBA,MAAM,WAAW,GAA6B;IAC5C,0BAA0B,EAAE,CAAC,KAAK,CAAC;IACnC,uBAAuB,EAAE,CAAC,KAAK,CAAC;IAChC,wBAAwB,EAAE,CAAC,KAAK,CAAC;IACjC,mDAAmD,EAAE,CAAC,KAAK,CAAC;IAC5D,4BAA4B,EAAE,CAAC,KAAK,CAAC;IACrC,+BAA+B,EAAE,CAAC,KAAK,CAAC;IACxC,sCAAsC,EAAE,CAAC,KAAK,CAAC;IAC/C,uBAAuB,EAAE,CAAC,KAAK,CAAC;CACjC,CAAC;AA6BF,MAAM,UAAU,YAAY,CAC1B,QAiBsC;IAUtC,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC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AO,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACjC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport type {\n DocumentTranslate200Response,\n DocumentTranslateDefaultResponse,\n StartTranslation202Response,\n StartTranslationLogicalResponse,\n StartTranslationDefaultResponse,\n GetTranslationsStatus200Response,\n GetTranslationsStatusDefaultResponse,\n GetDocumentStatus200Response,\n GetDocumentStatusDefaultResponse,\n GetTranslationStatus200Response,\n GetTranslationStatusDefaultResponse,\n CancelTranslation200Response,\n CancelTranslationDefaultResponse,\n GetDocumentsStatus200Response,\n GetDocumentsStatusDefaultResponse,\n GetSupportedFormats200Response,\n GetSupportedFormatsDefaultResponse,\n} from \"./responses.js\";\n\nconst responseMap: Record<string, string[]> = {\n \"POST /document:translate\": [\"200\"],\n \"GET /document/batches\": [\"200\"],\n \"POST /document/batches\": [\"202\"],\n \"GET /document/batches/{id}/documents/{documentId}\": [\"200\"],\n \"GET /document/batches/{id}\": [\"200\"],\n \"DELETE /document/batches/{id}\": [\"200\"],\n \"GET /document/batches/{id}/documents\": [\"200\"],\n \"GET /document/formats\": [\"200\"],\n};\n\nexport function isUnexpected(\n response: DocumentTranslate200Response | DocumentTranslateDefaultResponse,\n): response is DocumentTranslateDefaultResponse;\nexport function isUnexpected(\n response:\n | StartTranslation202Response\n | StartTranslationLogicalResponse\n | StartTranslationDefaultResponse,\n): response is StartTranslationDefaultResponse;\nexport function isUnexpected(\n response: GetTranslationsStatus200Response | GetTranslationsStatusDefaultResponse,\n): response is GetTranslationsStatusDefaultResponse;\nexport function isUnexpected(\n response: GetDocumentStatus200Response | GetDocumentStatusDefaultResponse,\n): response is GetDocumentStatusDefaultResponse;\nexport function isUnexpected(\n response: GetTranslationStatus200Response | GetTranslationStatusDefaultResponse,\n): response is GetTranslationStatusDefaultResponse;\nexport function isUnexpected(\n response: CancelTranslation200Response | CancelTranslationDefaultResponse,\n): response is CancelTranslationDefaultResponse;\nexport function isUnexpected(\n response: GetDocumentsStatus200Response | GetDocumentsStatusDefaultResponse,\n): response is GetDocumentsStatusDefaultResponse;\nexport function isUnexpected(\n response: GetSupportedFormats200Response | GetSupportedFormatsDefaultResponse,\n): response is GetSupportedFormatsDefaultResponse;\nexport function isUnexpected(\n response:\n | DocumentTranslate200Response\n | DocumentTranslateDefaultResponse\n | StartTranslation202Response\n | StartTranslationLogicalResponse\n | StartTranslationDefaultResponse\n | GetTranslationsStatus200Response\n | GetTranslationsStatusDefaultResponse\n | GetDocumentStatus200Response\n | GetDocumentStatusDefaultResponse\n | GetTranslationStatus200Response\n | GetTranslationStatusDefaultResponse\n | CancelTranslation200Response\n | CancelTranslationDefaultResponse\n | GetDocumentsStatus200Response\n | GetDocumentsStatusDefaultResponse\n | GetSupportedFormats200Response\n | GetSupportedFormatsDefaultResponse,\n): response is\n | DocumentTranslateDefaultResponse\n | StartTranslationDefaultResponse\n | GetTranslationsStatusDefaultResponse\n | GetDocumentStatusDefaultResponse\n | GetTranslationStatusDefaultResponse\n | CancelTranslationDefaultResponse\n | GetDocumentsStatusDefaultResponse\n | GetSupportedFormatsDefaultResponse {\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":"AAGA,eAAO,MAAM,MAAM,qCAAgD,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-translation-document");
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;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC,yBAAyB,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport { createClientLogger } from \"@azure/logger\";\nexport const logger = createClientLogger(\"ai-translation-document\");\n"]}
@@ -0,0 +1,112 @@
1
+ export interface DocumentTranslateContentDocumentPartDescriptor {
2
+ name: "document";
3
+ body: string | Uint8Array | ReadableStream<Uint8Array> | NodeJS.ReadableStream | File;
4
+ filename?: string;
5
+ contentType?: string;
6
+ }
7
+ export interface DocumentTranslateContentGlossaryPartDescriptor {
8
+ name: "glossary";
9
+ body: string | Uint8Array | ReadableStream<Uint8Array> | NodeJS.ReadableStream | File;
10
+ filename?: string;
11
+ contentType?: string;
12
+ }
13
+ /** Translation job submission batch request */
14
+ export interface StartTranslationDetails {
15
+ /** The input list of documents or folders containing documents */
16
+ inputs: Array<BatchRequest>;
17
+ }
18
+ /** Definition for the input batch translation request */
19
+ export interface BatchRequest {
20
+ /** Source of the input documents */
21
+ source: SourceInput;
22
+ /** Location of the destination for the output */
23
+ targets: Array<TargetInput>;
24
+ /**
25
+ * Storage type of the input documents source string
26
+ *
27
+ * Possible values: "Folder", "File"
28
+ */
29
+ storageType?: StorageInputType;
30
+ }
31
+ /** Source of the input documents */
32
+ export interface SourceInput {
33
+ /** Location of the folder / container or single file with your documents */
34
+ sourceUrl: string;
35
+ /** Document filter */
36
+ filter?: DocumentFilter;
37
+ /**
38
+ * Language code
39
+ * If none is specified, we will perform auto detect on the document
40
+ */
41
+ language?: string;
42
+ /**
43
+ * Storage Source
44
+ *
45
+ * Possible values: "AzureBlob"
46
+ */
47
+ storageSource?: StorageSource;
48
+ }
49
+ /** Document filter */
50
+ export interface DocumentFilter {
51
+ /**
52
+ * A case-sensitive prefix string to filter documents in the source path for
53
+ * translation.
54
+ * For example, when using a Azure storage blob Uri, use the prefix
55
+ * to restrict sub folders for translation.
56
+ */
57
+ prefix?: string;
58
+ /**
59
+ * A case-sensitive suffix string to filter documents in the source path for
60
+ * translation.
61
+ * This is most often use for file extensions
62
+ */
63
+ suffix?: string;
64
+ }
65
+ /** Destination for the finished translated documents */
66
+ export interface TargetInput {
67
+ /** Location of the folder / container with your documents */
68
+ targetUrl: string;
69
+ /** Category / custom system for translation request */
70
+ category?: string;
71
+ /** Target Language */
72
+ language: string;
73
+ /** List of Glossary */
74
+ glossaries?: Array<Glossary>;
75
+ /**
76
+ * Storage Source
77
+ *
78
+ * Possible values: "AzureBlob"
79
+ */
80
+ storageSource?: StorageSource;
81
+ }
82
+ /** Glossary / translation memory for the request */
83
+ export interface Glossary {
84
+ /**
85
+ * Location of the glossary.
86
+ * We will use the file extension to extract the
87
+ * formatting if the format parameter is not supplied.
88
+ *
89
+ * If the translation
90
+ * language pair is not present in the glossary, it will not be applied
91
+ */
92
+ glossaryUrl: string;
93
+ /** Format */
94
+ format: string;
95
+ /** Optional Version. If not specified, default is used. */
96
+ version?: string;
97
+ /**
98
+ * Storage Source
99
+ *
100
+ * Possible values: "AzureBlob"
101
+ */
102
+ storageSource?: StorageSource;
103
+ }
104
+ /** Document Translate Request Content */
105
+ export type DocumentTranslateContent = FormData | Array<DocumentTranslateContentDocumentPartDescriptor | DocumentTranslateContentGlossaryPartDescriptor>;
106
+ /** Alias for StorageSource */
107
+ export type StorageSource = string;
108
+ /** Alias for StorageInputType */
109
+ export type StorageInputType = string;
110
+ /** Alias for FileFormatType */
111
+ export type FileFormatType = string;
112
+ //# sourceMappingURL=models.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/models.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,8CAA8C;IAC7D,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;IACtF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,W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AAC;IAC7B;;;;OAIG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED,oDAAoD;AACpD,MAAM,WAAW,QAAQ;IACvB;;;;;;;OAOG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa;IACb,MAAM,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED,yCAAyC;AACzC,MAAM,MAAM,wBAAwB,GAChC,QAAQ,GACR,KAAK,CACD,8CAA8C,GAC9C,8CAA8C,CACjD,CAAC;AACN,8BAA8B;AAC9B,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AACnC,iCAAiC;AACjC,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AACtC,+BAA+B;AAC/B,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC"}
@@ -0,0 +1,4 @@
1
+ // Copyright (c) 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\nexport interface DocumentTranslateContentDocumentPartDescriptor {\n name: \"document\";\n body: string | Uint8Array | ReadableStream<Uint8Array> | NodeJS.ReadableStream | File;\n filename?: string;\n contentType?: string;\n}\n\nexport interface DocumentTranslateContentGlossaryPartDescriptor {\n name: \"glossary\";\n body: string | Uint8Array | ReadableStream<Uint8Array> | NodeJS.ReadableStream | File;\n filename?: string;\n contentType?: string;\n}\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 /**\n * Storage type of the input documents source string\n *\n * Possible values: \"Folder\", \"File\"\n */\n storageType?: StorageInputType;\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 /** Document filter */\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 /**\n * Storage Source\n *\n * Possible values: \"AzureBlob\"\n */\n storageSource?: StorageSource;\n}\n\n/** Document filter */\nexport interface DocumentFilter {\n /**\n * A case-sensitive prefix string to filter documents in the source path for\n * translation.\n * For example, when using a Azure storage blob Uri, use the prefix\n * 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\n * 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 /**\n * Storage Source\n *\n * Possible values: \"AzureBlob\"\n */\n storageSource?: StorageSource;\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\n * formatting if the format parameter is not supplied.\n *\n * If the translation\n * 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 /**\n * Storage Source\n *\n * Possible values: \"AzureBlob\"\n */\n storageSource?: StorageSource;\n}\n\n/** Document Translate Request Content */\nexport type DocumentTranslateContent =\n | FormData\n | Array<\n | DocumentTranslateContentDocumentPartDescriptor\n | DocumentTranslateContentGlossaryPartDescriptor\n >;\n/** Alias for StorageSource */\nexport type StorageSource = string;\n/** Alias for StorageInputType */\nexport type StorageInputType = string;\n/** Alias for FileFormatType */\nexport type FileFormatType = string;\n"]}
@@ -0,0 +1,166 @@
1
+ /** Translation job Status Response */
2
+ export interface TranslationsStatusOutput {
3
+ /** The summary status of individual operation */
4
+ value: Array<TranslationStatusOutput>;
5
+ /** Url for the next page. Null if no more pages available */
6
+ nextLink?: string;
7
+ }
8
+ /** Translation job status response */
9
+ export interface TranslationStatusOutput {
10
+ /** Id of the operation. */
11
+ id: string;
12
+ /** Operation created date time */
13
+ createdDateTimeUtc: string;
14
+ /** Date time in which the operation's status has been updated */
15
+ lastActionDateTimeUtc: string;
16
+ /**
17
+ * List of possible statuses for job or document
18
+ *
19
+ * Possible values: "NotStarted", "Running", "Succeeded", "Failed", "Cancelled", "Cancelling", "ValidationFailed"
20
+ */
21
+ status: StatusOutput;
22
+ /**
23
+ * This contains an outer error with error code, message, details, target and an
24
+ * inner error with more descriptive details.
25
+ */
26
+ error?: TranslationErrorOutput;
27
+ /** Status Summary */
28
+ summary: StatusSummaryOutput;
29
+ }
30
+ /**
31
+ * This contains an outer error with error code, message, details, target and an
32
+ * inner error with more descriptive details.
33
+ */
34
+ export interface TranslationErrorOutput {
35
+ /**
36
+ * Enums containing high level error codes.
37
+ *
38
+ * Possible values: "InvalidRequest", "InvalidArgument", "InternalServerError", "ServiceUnavailable", "ResourceNotFound", "Unauthorized", "RequestRateTooHigh"
39
+ */
40
+ code: TranslationErrorCodeOutput;
41
+ /** Gets high level error message. */
42
+ message: string;
43
+ /**
44
+ * Gets the source of the error.
45
+ * For example it would be "documents" or
46
+ * "document id" in case of invalid document.
47
+ */
48
+ readonly target?: string;
49
+ /**
50
+ * New Inner Error format which conforms to Cognitive Services API Guidelines
51
+ * which is available at
52
+ * https://microsoft.sharepoint.com/%3Aw%3A/t/CognitiveServicesPMO/EUoytcrjuJdKpeOKIK_QRC8BPtUYQpKBi8JsWyeDMRsWlQ?e=CPq8ow.
53
+ * This
54
+ * contains required properties ErrorCode, message and optional properties target,
55
+ * details(key value pair), inner error(this can be nested).
56
+ */
57
+ innerError?: InnerTranslationErrorOutput;
58
+ }
59
+ /**
60
+ * New Inner Error format which conforms to Cognitive Services API Guidelines
61
+ * which is available at
62
+ * https://microsoft.sharepoint.com/%3Aw%3A/t/CognitiveServicesPMO/EUoytcrjuJdKpeOKIK_QRC8BPtUYQpKBi8JsWyeDMRsWlQ?e=CPq8ow.
63
+ * This
64
+ * contains required properties ErrorCode, message and optional properties target,
65
+ * details(key value pair), inner error(this can be nested).
66
+ */
67
+ export interface InnerTranslationErrorOutput {
68
+ /** Gets code error string. */
69
+ code: string;
70
+ /** Gets high level error message. */
71
+ message: string;
72
+ /**
73
+ * Gets the source of the error.
74
+ * For example it would be "documents" or
75
+ * "document id" in case of invalid document.
76
+ */
77
+ readonly target?: string;
78
+ /**
79
+ * New Inner Error format which conforms to Cognitive Services API Guidelines
80
+ * which is available at
81
+ * https://microsoft.sharepoint.com/%3Aw%3A/t/CognitiveServicesPMO/EUoytcrjuJdKpeOKIK_QRC8BPtUYQpKBi8JsWyeDMRsWlQ?e=CPq8ow.
82
+ * This
83
+ * contains required properties ErrorCode, message and optional properties target,
84
+ * details(key value pair), inner error(this can be nested).
85
+ */
86
+ innerError?: InnerTranslationErrorOutput;
87
+ }
88
+ /** Status Summary */
89
+ export interface StatusSummaryOutput {
90
+ /** Total count */
91
+ total: number;
92
+ /** Failed count */
93
+ failed: number;
94
+ /** Number of Success */
95
+ success: number;
96
+ /** Number of in progress */
97
+ inProgress: number;
98
+ /** Count of not yet started */
99
+ notYetStarted: number;
100
+ /** Number of cancelled */
101
+ cancelled: number;
102
+ /** Total characters charged by the API */
103
+ totalCharacterCharged: number;
104
+ }
105
+ /** Document Status Response */
106
+ export interface DocumentStatusOutput {
107
+ /** Location of the document or folder */
108
+ path?: string;
109
+ /** Location of the source document */
110
+ sourcePath: string;
111
+ /** Operation created date time */
112
+ createdDateTimeUtc: string;
113
+ /** Date time in which the operation's status has been updated */
114
+ lastActionDateTimeUtc: string;
115
+ /**
116
+ * List of possible statuses for job or document
117
+ *
118
+ * Possible values: "NotStarted", "Running", "Succeeded", "Failed", "Cancelled", "Cancelling", "ValidationFailed"
119
+ */
120
+ status: StatusOutput;
121
+ /** To language */
122
+ to: string;
123
+ /**
124
+ * This contains an outer error with error code, message, details, target and an
125
+ * inner error with more descriptive details.
126
+ */
127
+ error?: TranslationErrorOutput;
128
+ /** Progress of the translation if available */
129
+ progress: number;
130
+ /** Document Id */
131
+ id: string;
132
+ /** Character charged by the API */
133
+ characterCharged?: number;
134
+ }
135
+ /** Documents Status Response */
136
+ export interface DocumentsStatusOutput {
137
+ /** The detail status of individual documents */
138
+ value: Array<DocumentStatusOutput>;
139
+ /** Url for the next page. Null if no more pages available */
140
+ nextLink?: string;
141
+ }
142
+ /** List of supported file formats */
143
+ export interface SupportedFileFormatsOutput {
144
+ /** list of objects */
145
+ value: Array<FileFormatOutput>;
146
+ }
147
+ /** File Format */
148
+ export interface FileFormatOutput {
149
+ /** Name of the format */
150
+ format: string;
151
+ /** Supported file extension for this format */
152
+ fileExtensions: string[];
153
+ /** Supported Content-Types for this format */
154
+ contentTypes: string[];
155
+ /** Default version if none is specified */
156
+ defaultVersion?: string;
157
+ /** Supported Version */
158
+ versions?: string[];
159
+ /** Supported Type for this format */
160
+ type?: string;
161
+ }
162
+ /** Alias for StatusOutput */
163
+ export type StatusOutput = string;
164
+ /** Alias for TranslationErrorCodeOutput */
165
+ export type TranslationErrorCodeOutput = string;
166
+ //# sourceMappingURL=outputModels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outputModels.d.ts","sourceRoot":"","sources":["../../src/outputModels.ts"],"names":[],"mappings":"AAGA,sCAAsC;AACtC,MAAM,WAAW,wBAAwB;IACvC,iDAAiD;IACjD,KAAK,EAAE,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACtC,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,sCAAsC;AACtC,MAAM,WAAW,uBAAuB;IACtC,2BAA2B;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,kC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};
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/** 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 /** Id of the operation. */\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 /**\n * List of possible statuses for job or document\n *\n * Possible values: \"NotStarted\", \"Running\", \"Succeeded\", \"Failed\", \"Cancelled\", \"Cancelling\", \"ValidationFailed\"\n */\n status: StatusOutput;\n /**\n * This contains an outer error with error code, message, details, target and an\n * inner error with more descriptive details.\n */\n error?: TranslationErrorOutput;\n /** Status Summary */\n summary: StatusSummaryOutput;\n}\n\n/**\n * This contains an outer error with error code, message, details, target and an\n * inner error with more descriptive details.\n */\nexport interface TranslationErrorOutput {\n /**\n * Enums containing high level error codes.\n *\n * Possible values: \"InvalidRequest\", \"InvalidArgument\", \"InternalServerError\", \"ServiceUnavailable\", \"ResourceNotFound\", \"Unauthorized\", \"RequestRateTooHigh\"\n */\n code: TranslationErrorCodeOutput;\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\n * \"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\n * which is available at\n * https://microsoft.sharepoint.com/%3Aw%3A/t/CognitiveServicesPMO/EUoytcrjuJdKpeOKIK_QRC8BPtUYQpKBi8JsWyeDMRsWlQ?e=CPq8ow.\n * This\n * contains required properties ErrorCode, message and optional properties target,\n * 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\n * which is available at\n * https://microsoft.sharepoint.com/%3Aw%3A/t/CognitiveServicesPMO/EUoytcrjuJdKpeOKIK_QRC8BPtUYQpKBi8JsWyeDMRsWlQ?e=CPq8ow.\n * This\n * contains required properties ErrorCode, message and optional properties target,\n * 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\n * \"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\n * which is available at\n * https://microsoft.sharepoint.com/%3Aw%3A/t/CognitiveServicesPMO/EUoytcrjuJdKpeOKIK_QRC8BPtUYQpKBi8JsWyeDMRsWlQ?e=CPq8ow.\n * This\n * contains required properties ErrorCode, message and optional properties target,\n * details(key value pair), inner error(this can be nested).\n */\n innerError?: InnerTranslationErrorOutput;\n}\n\n/** Status Summary */\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 /**\n * List of possible statuses for job or document\n *\n * Possible values: \"NotStarted\", \"Running\", \"Succeeded\", \"Failed\", \"Cancelled\", \"Cancelling\", \"ValidationFailed\"\n */\n status: StatusOutput;\n /** To language */\n to: string;\n /**\n * This contains an outer error with error code, message, details, target and an\n * inner error with more descriptive details.\n */\n error?: TranslationErrorOutput;\n /** Progress of the translation if available */\n progress: number;\n /** Document Id */\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/** List of supported file formats */\nexport interface SupportedFileFormatsOutput {\n /** list of objects */\n value: Array<FileFormatOutput>;\n}\n\n/** File Format */\nexport interface FileFormatOutput {\n /** Name of the format */\n format: string;\n /** Supported file extension for this format */\n fileExtensions: string[];\n /** Supported Content-Types for this format */\n contentTypes: string[];\n /** Default version if none is specified */\n defaultVersion?: string;\n /** Supported Version */\n versions?: string[];\n /** Supported Type for this format */\n type?: string;\n}\n\n/** Alias for StatusOutput */\nexport type StatusOutput = string;\n/** Alias for TranslationErrorCodeOutput */\nexport type TranslationErrorCodeOutput = string;\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,43 @@
1
+ import type { PagedAsyncIterableIterator } from "@azure/core-paging";
2
+ import type { Client, PathUncheckedResponse } from "@azure-rest/core-client";
3
+ /**
4
+ * Helper type to extract the type of an array
5
+ */
6
+ export type GetArrayType<T> = T extends Array<infer TData> ? TData : never;
7
+ /**
8
+ * The type of a custom function that defines how to get a page and a link to the next one if any.
9
+ */
10
+ export type GetPage<TPage> = (pageLink: string, maxPageSize?: number) => Promise<{
11
+ page: TPage;
12
+ nextPageLink?: string;
13
+ }>;
14
+ /**
15
+ * Options for the paging helper
16
+ */
17
+ export interface PagingOptions<TResponse> {
18
+ /**
19
+ * Custom function to extract pagination details for crating the PagedAsyncIterableIterator
20
+ */
21
+ customGetPage?: GetPage<PaginateReturn<TResponse>[]>;
22
+ }
23
+ /**
24
+ * Helper type to infer the Type of the paged elements from the response type
25
+ * This type is generated based on the swagger information for x-ms-pageable
26
+ * specifically on the itemName property which indicates the property of the response
27
+ * where the page items are found. The default value is `value`.
28
+ * This type will allow us to provide strongly typed Iterator based on the response we get as second parameter
29
+ */
30
+ export type PaginateReturn<TResult> = TResult extends {
31
+ body: {
32
+ value?: infer TPage;
33
+ };
34
+ } ? GetArrayType<TPage> : Array<unknown>;
35
+ /**
36
+ * Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension
37
+ * @param client - Client to use for sending the next page requests
38
+ * @param initialResponse - Initial response containing the nextLink and current page of elements
39
+ * @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results
40
+ * @returns - PagedAsyncIterableIterator to iterate the elements
41
+ */
42
+ export declare function paginate<TResponse extends PathUncheckedResponse>(client: Client, initialResponse: TResponse, options?: PagingOptions<TResponse>): PagedAsyncIterableIterator<PaginateReturn<TResponse>>;
43
+ //# sourceMappingURL=paginateHelper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paginateHelper.d.ts","sourceRoot":"","sources":["../../src/paginateHelper.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,0BAA0B,EAAe,MAAM,oBAAoB,CAAC;AAElF,OAAO,KAAK,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAG7E;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,CAAC,MAAM,KAAK,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,OAAO,CAAC,KAAK,IAAI,CAC3B,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,KACjB,OAAO,CAAC;IACX,IAAI,EAAE,KAAK,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,SAAS;IACtC;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;CACtD;AAED;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,CAAC,OAAO,IAAI,OAAO,SAAS;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,68 @@
1
+ import { getPagedAsyncIterator } from "@azure/core-paging";
2
+ import { createRestError } from "@azure-rest/core-client";
3
+ /**
4
+ * Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension
5
+ * @param client - Client to use for sending the next page requests
6
+ * @param initialResponse - Initial response containing the nextLink and current page of elements
7
+ * @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results
8
+ * @returns - PagedAsyncIterableIterator to iterate the elements
9
+ */
10
+ export function paginate(client, initialResponse, options = {}) {
11
+ let firstRun = true;
12
+ const itemName = "value";
13
+ const nextLinkName = "nextLink";
14
+ const { customGetPage } = options;
15
+ const pagedResult = {
16
+ firstPageLink: "",
17
+ getPage: typeof customGetPage === "function"
18
+ ? customGetPage
19
+ : async (pageLink) => {
20
+ const result = firstRun ? initialResponse : await client.pathUnchecked(pageLink).get();
21
+ firstRun = false;
22
+ checkPagingRequest(result);
23
+ const nextLink = getNextLink(result.body, nextLinkName);
24
+ const values = getElements(result.body, itemName);
25
+ return {
26
+ page: values,
27
+ nextPageLink: nextLink,
28
+ };
29
+ },
30
+ };
31
+ return getPagedAsyncIterator(pagedResult);
32
+ }
33
+ /**
34
+ * Gets for the value of nextLink in the body
35
+ */
36
+ function getNextLink(body, nextLinkName) {
37
+ if (!nextLinkName) {
38
+ return undefined;
39
+ }
40
+ const nextLink = body[nextLinkName];
41
+ if (typeof nextLink !== "string" && typeof nextLink !== "undefined") {
42
+ throw new Error(`Body Property ${nextLinkName} should be a string or undefined`);
43
+ }
44
+ return nextLink;
45
+ }
46
+ /**
47
+ * Gets the elements of the current request in the body.
48
+ */
49
+ function getElements(body, itemName) {
50
+ const value = body[itemName];
51
+ // value has to be an array according to the x-ms-pageable extension.
52
+ // The fact that this must be an array is used above to calculate the
53
+ // type of elements in the page in PaginateReturn
54
+ if (!Array.isArray(value)) {
55
+ throw new Error(`Couldn't paginate response\n Body doesn't contain an array property with name: ${itemName}`);
56
+ }
57
+ return value !== null && value !== void 0 ? value : [];
58
+ }
59
+ /**
60
+ * Checks if a request failed
61
+ */
62
+ function checkPagingRequest(response) {
63
+ const Http2xxStatusCodes = ["200", "201", "202", "203", "204", "205", "206", "207", "208", "226"];
64
+ if (!Http2xxStatusCodes.includes(response.status)) {
65
+ throw createRestError(`Pagination failed with unexpected statusCode ${response.status}`, response);
66
+ }
67
+ }
68
+ //# sourceMappingURL=paginateHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paginateHelper.js","sourceRoot":"","sources":["../../src/paginateHelper.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAyC1D;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CACtB,MAAc,EACd,eAA0B,EAC1B,UAAoC,EAAE;IAItC,IAAI,QAAQ,GAAG,IAAI,CAAC;IACpB,MAAM,QAAQ,GAAG,OAAO,CAAC;IACzB,MAAM,YAAY,GAAG,UAAU,CAAC;IAChC,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAClC,MAAM,WAAW,GAA4B;QAC3C,aAAa,EAAE,EAAE;QACjB,OAAO,EACL,OAAO,aAAa,KAAK,UAAU;YACjC,CAAC,CAAC,aAAa;YACf,CAAC,CAAC,KAAK,E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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,eAAe,CACnB,gDAAgD,QAAQ,CAAC,MAAM,EAAE,EACjE,QAAQ,CACT,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nimport type { PagedAsyncIterableIterator, PagedResult } from \"@azure/core-paging\";\nimport { getPagedAsyncIterator } from \"@azure/core-paging\";\nimport type { Client, PathUncheckedResponse } from \"@azure-rest/core-client\";\nimport { createRestError } from \"@azure-rest/core-client\";\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> = (\n pageLink: string,\n maxPageSize?: number,\n) => 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"]}