@typespec/ts-http-runtime 0.2.1 → 0.2.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 (247) hide show
  1. package/README.md +1 -1
  2. package/dist/browser/client/common.d.ts +6 -0
  3. package/dist/browser/client/common.js.map +1 -1
  4. package/dist/browser/client/getClient.js +4 -4
  5. package/dist/browser/client/getClient.js.map +1 -1
  6. package/dist/browser/client/restError.js +1 -1
  7. package/dist/browser/client/restError.js.map +1 -1
  8. package/dist/browser/constants.js +1 -1
  9. package/dist/browser/constants.js.map +1 -1
  10. package/dist/browser/fetchHttpClient.js +1 -1
  11. package/dist/browser/fetchHttpClient.js.map +1 -1
  12. package/dist/browser/index.d.ts +3 -2
  13. package/dist/browser/index.js +3 -1
  14. package/dist/browser/index.js.map +1 -1
  15. package/dist/browser/interfaces.d.ts +11 -0
  16. package/dist/browser/interfaces.js.map +1 -1
  17. package/dist/browser/logger/internal.d.ts +2 -0
  18. package/dist/browser/logger/internal.js +4 -0
  19. package/dist/browser/logger/internal.js.map +1 -0
  20. package/dist/browser/logger/logger.d.ts +70 -22
  21. package/dist/browser/logger/logger.js +91 -68
  22. package/dist/browser/logger/logger.js.map +1 -1
  23. package/dist/browser/nodeHttpClient.js +1 -8
  24. package/dist/browser/nodeHttpClient.js.map +1 -1
  25. package/dist/browser/pipelineRequest.d.ts +11 -0
  26. package/dist/browser/pipelineRequest.js +1 -0
  27. package/dist/browser/pipelineRequest.js.map +1 -1
  28. package/dist/browser/policies/internal.d.ts +16 -0
  29. package/dist/browser/policies/internal.js +17 -0
  30. package/dist/browser/policies/internal.js.map +1 -0
  31. package/dist/browser/policies/retryPolicy.js +2 -2
  32. package/dist/browser/policies/retryPolicy.js.map +1 -1
  33. package/dist/browser/util/checkEnvironment.d.ts +0 -5
  34. package/dist/browser/util/checkEnvironment.js +0 -5
  35. package/dist/browser/util/checkEnvironment.js.map +1 -1
  36. package/dist/browser/util/concat.common.js +3 -10
  37. package/dist/browser/util/concat.common.js.map +1 -1
  38. package/dist/browser/util/delay.d.ts +0 -13
  39. package/dist/browser/util/delay.js +0 -19
  40. package/dist/browser/util/delay.js.map +1 -1
  41. package/dist/browser/util/error.d.ts +0 -7
  42. package/dist/browser/util/error.js +0 -26
  43. package/dist/browser/util/error.js.map +1 -1
  44. package/dist/browser/util/internal.d.ts +10 -0
  45. package/dist/browser/util/internal.js +12 -0
  46. package/dist/browser/util/internal.js.map +1 -0
  47. package/dist/browser/util/sanitizer.d.ts +12 -2
  48. package/dist/browser/util/sanitizer.js +11 -1
  49. package/dist/browser/util/sanitizer.js.map +1 -1
  50. package/dist/browser/util/typeGuards.d.ts +0 -17
  51. package/dist/browser/util/typeGuards.js +0 -31
  52. package/dist/browser/util/typeGuards.js.map +1 -1
  53. package/dist/commonjs/client/common.d.ts +6 -0
  54. package/dist/commonjs/client/common.js.map +1 -1
  55. package/dist/commonjs/client/getClient.js +4 -4
  56. package/dist/commonjs/client/getClient.js.map +1 -1
  57. package/dist/commonjs/client/restError.js +1 -1
  58. package/dist/commonjs/client/restError.js.map +1 -1
  59. package/dist/commonjs/constants.js +1 -1
  60. package/dist/commonjs/constants.js.map +1 -1
  61. package/dist/commonjs/fetchHttpClient.js +1 -1
  62. package/dist/commonjs/fetchHttpClient.js.map +1 -1
  63. package/dist/commonjs/index.d.ts +3 -2
  64. package/dist/commonjs/index.js +7 -1
  65. package/dist/commonjs/index.js.map +1 -1
  66. package/dist/commonjs/interfaces.d.ts +11 -0
  67. package/dist/commonjs/interfaces.js.map +1 -1
  68. package/dist/commonjs/logger/internal.d.ts +2 -0
  69. package/dist/commonjs/logger/internal.js +8 -0
  70. package/dist/commonjs/logger/internal.js.map +1 -0
  71. package/dist/commonjs/logger/logger.d.ts +70 -22
  72. package/dist/commonjs/logger/logger.js +92 -68
  73. package/dist/commonjs/logger/logger.js.map +1 -1
  74. package/dist/commonjs/nodeHttpClient.js +1 -8
  75. package/dist/commonjs/nodeHttpClient.js.map +1 -1
  76. package/dist/commonjs/pipelineRequest.d.ts +11 -0
  77. package/dist/commonjs/pipelineRequest.js +1 -0
  78. package/dist/commonjs/pipelineRequest.js.map +1 -1
  79. package/dist/commonjs/policies/internal.d.ts +16 -0
  80. package/dist/commonjs/policies/internal.js +48 -0
  81. package/dist/commonjs/policies/internal.js.map +1 -0
  82. package/dist/commonjs/policies/retryPolicy.js +2 -2
  83. package/dist/commonjs/policies/retryPolicy.js.map +1 -1
  84. package/dist/commonjs/tsdoc-metadata.json +1 -1
  85. package/dist/commonjs/util/checkEnvironment.d.ts +0 -5
  86. package/dist/commonjs/util/checkEnvironment.js +1 -6
  87. package/dist/commonjs/util/checkEnvironment.js.map +1 -1
  88. package/dist/commonjs/util/concat.common.js +2 -9
  89. package/dist/commonjs/util/concat.common.js.map +1 -1
  90. package/dist/commonjs/util/concat.js +1 -2
  91. package/dist/commonjs/util/concat.js.map +1 -1
  92. package/dist/commonjs/util/delay.d.ts +0 -13
  93. package/dist/commonjs/util/delay.js +0 -20
  94. package/dist/commonjs/util/delay.js.map +1 -1
  95. package/dist/commonjs/util/error.d.ts +0 -7
  96. package/dist/commonjs/util/error.js +0 -27
  97. package/dist/commonjs/util/error.js.map +1 -1
  98. package/dist/commonjs/util/internal.d.ts +10 -0
  99. package/dist/commonjs/util/internal.js +32 -0
  100. package/dist/commonjs/util/internal.js.map +1 -0
  101. package/dist/commonjs/util/sanitizer.d.ts +12 -2
  102. package/dist/commonjs/util/sanitizer.js +11 -1
  103. package/dist/commonjs/util/sanitizer.js.map +1 -1
  104. package/dist/commonjs/util/typeGuards.d.ts +0 -17
  105. package/dist/commonjs/util/typeGuards.js +0 -34
  106. package/dist/commonjs/util/typeGuards.js.map +1 -1
  107. package/dist/esm/client/common.d.ts +6 -0
  108. package/dist/esm/client/common.js.map +1 -1
  109. package/dist/esm/client/getClient.js +4 -4
  110. package/dist/esm/client/getClient.js.map +1 -1
  111. package/dist/esm/client/restError.js +1 -1
  112. package/dist/esm/client/restError.js.map +1 -1
  113. package/dist/esm/constants.js +1 -1
  114. package/dist/esm/constants.js.map +1 -1
  115. package/dist/esm/fetchHttpClient.js +1 -1
  116. package/dist/esm/fetchHttpClient.js.map +1 -1
  117. package/dist/esm/index.d.ts +3 -2
  118. package/dist/esm/index.js +3 -1
  119. package/dist/esm/index.js.map +1 -1
  120. package/dist/esm/interfaces.d.ts +11 -0
  121. package/dist/esm/interfaces.js.map +1 -1
  122. package/dist/esm/logger/internal.d.ts +2 -0
  123. package/dist/esm/logger/internal.js +4 -0
  124. package/dist/esm/logger/internal.js.map +1 -0
  125. package/dist/esm/logger/logger.d.ts +70 -22
  126. package/dist/esm/logger/logger.js +91 -68
  127. package/dist/esm/logger/logger.js.map +1 -1
  128. package/dist/esm/nodeHttpClient.js +1 -8
  129. package/dist/esm/nodeHttpClient.js.map +1 -1
  130. package/dist/esm/pipelineRequest.d.ts +11 -0
  131. package/dist/esm/pipelineRequest.js +1 -0
  132. package/dist/esm/pipelineRequest.js.map +1 -1
  133. package/dist/esm/policies/internal.d.ts +16 -0
  134. package/dist/esm/policies/internal.js +17 -0
  135. package/dist/esm/policies/internal.js.map +1 -0
  136. package/dist/esm/policies/retryPolicy.js +2 -2
  137. package/dist/esm/policies/retryPolicy.js.map +1 -1
  138. package/dist/esm/util/checkEnvironment.d.ts +0 -5
  139. package/dist/esm/util/checkEnvironment.js +0 -5
  140. package/dist/esm/util/checkEnvironment.js.map +1 -1
  141. package/dist/esm/util/concat.common.js +3 -10
  142. package/dist/esm/util/concat.common.js.map +1 -1
  143. package/dist/esm/util/concat.js +1 -2
  144. package/dist/esm/util/concat.js.map +1 -1
  145. package/dist/esm/util/delay.d.ts +0 -13
  146. package/dist/esm/util/delay.js +0 -19
  147. package/dist/esm/util/delay.js.map +1 -1
  148. package/dist/esm/util/error.d.ts +0 -7
  149. package/dist/esm/util/error.js +0 -26
  150. package/dist/esm/util/error.js.map +1 -1
  151. package/dist/esm/util/internal.d.ts +10 -0
  152. package/dist/esm/util/internal.js +12 -0
  153. package/dist/esm/util/internal.js.map +1 -0
  154. package/dist/esm/util/sanitizer.d.ts +12 -2
  155. package/dist/esm/util/sanitizer.js +11 -1
  156. package/dist/esm/util/sanitizer.js.map +1 -1
  157. package/dist/esm/util/typeGuards.d.ts +0 -17
  158. package/dist/esm/util/typeGuards.js +0 -31
  159. package/dist/esm/util/typeGuards.js.map +1 -1
  160. package/dist/react-native/client/common.d.ts +6 -0
  161. package/dist/react-native/client/common.js.map +1 -1
  162. package/dist/react-native/client/getClient.js +4 -4
  163. package/dist/react-native/client/getClient.js.map +1 -1
  164. package/dist/react-native/client/restError.js +1 -1
  165. package/dist/react-native/client/restError.js.map +1 -1
  166. package/dist/react-native/constants.js +1 -1
  167. package/dist/react-native/constants.js.map +1 -1
  168. package/dist/react-native/fetchHttpClient.js +1 -1
  169. package/dist/react-native/fetchHttpClient.js.map +1 -1
  170. package/dist/react-native/index.d.ts +3 -2
  171. package/dist/react-native/index.js +3 -1
  172. package/dist/react-native/index.js.map +1 -1
  173. package/dist/react-native/interfaces.d.ts +11 -0
  174. package/dist/react-native/interfaces.js.map +1 -1
  175. package/dist/react-native/logger/internal.d.ts +2 -0
  176. package/dist/react-native/logger/internal.js +4 -0
  177. package/dist/react-native/logger/internal.js.map +1 -0
  178. package/dist/react-native/logger/logger.d.ts +70 -22
  179. package/dist/react-native/logger/logger.js +91 -68
  180. package/dist/react-native/logger/logger.js.map +1 -1
  181. package/dist/react-native/nodeHttpClient.js +1 -8
  182. package/dist/react-native/nodeHttpClient.js.map +1 -1
  183. package/dist/react-native/pipelineRequest.d.ts +11 -0
  184. package/dist/react-native/pipelineRequest.js +1 -0
  185. package/dist/react-native/pipelineRequest.js.map +1 -1
  186. package/dist/react-native/policies/internal.d.ts +16 -0
  187. package/dist/react-native/policies/internal.js +17 -0
  188. package/dist/react-native/policies/internal.js.map +1 -0
  189. package/dist/react-native/policies/retryPolicy.js +2 -2
  190. package/dist/react-native/policies/retryPolicy.js.map +1 -1
  191. package/dist/react-native/util/checkEnvironment.d.ts +0 -5
  192. package/dist/react-native/util/checkEnvironment.js +0 -5
  193. package/dist/react-native/util/checkEnvironment.js.map +1 -1
  194. package/dist/react-native/util/concat.common.js +3 -10
  195. package/dist/react-native/util/concat.common.js.map +1 -1
  196. package/dist/react-native/util/delay.d.ts +0 -13
  197. package/dist/react-native/util/delay.js +0 -19
  198. package/dist/react-native/util/delay.js.map +1 -1
  199. package/dist/react-native/util/error.d.ts +0 -7
  200. package/dist/react-native/util/error.js +0 -26
  201. package/dist/react-native/util/error.js.map +1 -1
  202. package/dist/react-native/util/internal.d.ts +10 -0
  203. package/dist/react-native/util/internal.js +12 -0
  204. package/dist/react-native/util/internal.js.map +1 -0
  205. package/dist/react-native/util/sanitizer.d.ts +12 -2
  206. package/dist/react-native/util/sanitizer.js +11 -1
  207. package/dist/react-native/util/sanitizer.js.map +1 -1
  208. package/dist/react-native/util/typeGuards.d.ts +0 -17
  209. package/dist/react-native/util/typeGuards.js +0 -31
  210. package/dist/react-native/util/typeGuards.js.map +1 -1
  211. package/package.json +62 -5
  212. package/dist/browser/util/aborterUtils.d.ts +0 -26
  213. package/dist/browser/util/aborterUtils.js +0 -21
  214. package/dist/browser/util/aborterUtils.js.map +0 -1
  215. package/dist/browser/util/createAbortablePromise.d.ts +0 -16
  216. package/dist/browser/util/createAbortablePromise.js +0 -42
  217. package/dist/browser/util/createAbortablePromise.js.map +0 -1
  218. package/dist/browser/util/file.d.ts +0 -69
  219. package/dist/browser/util/file.js +0 -99
  220. package/dist/browser/util/file.js.map +0 -1
  221. package/dist/commonjs/util/aborterUtils.d.ts +0 -26
  222. package/dist/commonjs/util/aborterUtils.js +0 -24
  223. package/dist/commonjs/util/aborterUtils.js.map +0 -1
  224. package/dist/commonjs/util/createAbortablePromise.d.ts +0 -16
  225. package/dist/commonjs/util/createAbortablePromise.js +0 -45
  226. package/dist/commonjs/util/createAbortablePromise.js.map +0 -1
  227. package/dist/commonjs/util/file.d.ts +0 -69
  228. package/dist/commonjs/util/file.js +0 -104
  229. package/dist/commonjs/util/file.js.map +0 -1
  230. package/dist/esm/util/aborterUtils.d.ts +0 -26
  231. package/dist/esm/util/aborterUtils.js +0 -21
  232. package/dist/esm/util/aborterUtils.js.map +0 -1
  233. package/dist/esm/util/createAbortablePromise.d.ts +0 -16
  234. package/dist/esm/util/createAbortablePromise.js +0 -42
  235. package/dist/esm/util/createAbortablePromise.js.map +0 -1
  236. package/dist/esm/util/file.d.ts +0 -69
  237. package/dist/esm/util/file.js +0 -99
  238. package/dist/esm/util/file.js.map +0 -1
  239. package/dist/react-native/util/aborterUtils.d.ts +0 -26
  240. package/dist/react-native/util/aborterUtils.js +0 -21
  241. package/dist/react-native/util/aborterUtils.js.map +0 -1
  242. package/dist/react-native/util/createAbortablePromise.d.ts +0 -16
  243. package/dist/react-native/util/createAbortablePromise.js +0 -42
  244. package/dist/react-native/util/createAbortablePromise.js.map +0 -1
  245. package/dist/react-native/util/file.d.ts +0 -69
  246. package/dist/react-native/util/file.js +0 -99
  247. package/dist/react-native/util/file.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/ts-http-runtime",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Isomorphic client library for making HTTP requests in node.js and browser.",
5
5
  "sdk-type": "client",
6
6
  "type": "module",
@@ -27,6 +27,60 @@
27
27
  "types": "./dist/commonjs/index.d.ts",
28
28
  "default": "./dist/commonjs/index.js"
29
29
  }
30
+ },
31
+ "./internal/util": {
32
+ "browser": {
33
+ "types": "./dist/browser/util/internal.d.ts",
34
+ "default": "./dist/browser/util/internal.js"
35
+ },
36
+ "react-native": {
37
+ "types": "./dist/react-native/util/internal.d.ts",
38
+ "default": "./dist/react-native/util/internal.js"
39
+ },
40
+ "import": {
41
+ "types": "./dist/esm/util/internal.d.ts",
42
+ "default": "./dist/esm/util/internal.js"
43
+ },
44
+ "require": {
45
+ "types": "./dist/commonjs/util/internal.d.ts",
46
+ "default": "./dist/commonjs/util/internal.js"
47
+ }
48
+ },
49
+ "./internal/logger": {
50
+ "browser": {
51
+ "types": "./dist/browser/logger/internal.d.ts",
52
+ "default": "./dist/browser/logger/internal.js"
53
+ },
54
+ "react-native": {
55
+ "types": "./dist/react-native/logger/internal.d.ts",
56
+ "default": "./dist/react-native/logger/internal.js"
57
+ },
58
+ "import": {
59
+ "types": "./dist/esm/logger/internal.d.ts",
60
+ "default": "./dist/esm/logger/internal.js"
61
+ },
62
+ "require": {
63
+ "types": "./dist/commonjs/logger/internal.d.ts",
64
+ "default": "./dist/commonjs/logger/internal.js"
65
+ }
66
+ },
67
+ "./internal/policies": {
68
+ "browser": {
69
+ "types": "./dist/browser/policies/internal.d.ts",
70
+ "default": "./dist/browser/policies/internal.js"
71
+ },
72
+ "react-native": {
73
+ "types": "./dist/react-native/policies/internal.d.ts",
74
+ "default": "./dist/react-native/policies/internal.js"
75
+ },
76
+ "import": {
77
+ "types": "./dist/esm/policies/internal.d.ts",
78
+ "default": "./dist/esm/policies/internal.js"
79
+ },
80
+ "require": {
81
+ "types": "./dist/commonjs/policies/internal.d.ts",
82
+ "default": "./dist/commonjs/policies/internal.js"
83
+ }
30
84
  }
31
85
  },
32
86
  "files": [
@@ -63,10 +117,10 @@
63
117
  "integration-test": "npm run integration-test:node && npm run integration-test:browser",
64
118
  "integration-test:browser": "echo skipped",
65
119
  "integration-test:node": "echo skipped",
66
- "lint": "tsx scripts/azure-diff.ts && eslint README.md package.json api-extractor.json src test",
67
- "lint:fix": "tsx scripts/azure-diff.ts --update && eslint README.md package.json api-extractor.json src test --fix --fix-type [problem,suggestion]",
120
+ "lint": "eslint README.md package.json api-extractor.json src test",
121
+ "lint:fix": "eslint README.md package.json api-extractor.json src test --fix --fix-type [problem,suggestion]",
68
122
  "pack": "npm pack 2>&1",
69
- "test": "npm run clean && dev-tool run build-package && npm run unit-test:node && dev-tool run bundle && npm run unit-test:browser && npm run integration-test",
123
+ "test": "npm run clean && dev-tool run build-package && npm run unit-test:node && npm run unit-test:browser && npm run integration-test",
70
124
  "test:browser": "npm run clean && npm run unit-test:browser && npm run integration-test:browser",
71
125
  "test:node": "npm run clean && dev-tool run build-package && npm run unit-test:node && npm run integration-test:node",
72
126
  "unit-test": "npm run unit-test:node && npm run unit-test:browser",
@@ -112,7 +166,10 @@
112
166
  "tshy": {
113
167
  "exports": {
114
168
  "./package.json": "./package.json",
115
- ".": "./src/index.ts"
169
+ ".": "./src/index.ts",
170
+ "./internal/util": "./src/util/internal.ts",
171
+ "./internal/logger": "./src/logger/internal.ts",
172
+ "./internal/policies": "./src/policies/internal.ts"
116
173
  },
117
174
  "dialects": [
118
175
  "esm",
@@ -1,26 +0,0 @@
1
- /**
2
- * Options related to abort controller.
3
- */
4
- export interface AbortOptions {
5
- /**
6
- * The abortSignal associated with containing operation.
7
- */
8
- abortSignal?: AbortSignal;
9
- /**
10
- * The abort error message associated with containing operation.
11
- */
12
- abortErrorMsg?: string;
13
- }
14
- /**
15
- * Represents a function that returns a promise that can be aborted.
16
- */
17
- export type AbortablePromiseBuilder<T> = (abortOptions: {
18
- abortSignal?: AbortSignal;
19
- }) => Promise<T>;
20
- /**
21
- * promise.race() wrapper that aborts rest of promises as soon as the first promise settles.
22
- */
23
- export declare function cancelablePromiseRace<T extends unknown[]>(abortablePromiseBuilders: AbortablePromiseBuilder<T[number]>[], options?: {
24
- abortSignal?: AbortSignal;
25
- }): Promise<T[number]>;
26
- //# sourceMappingURL=aborterUtils.d.ts.map
@@ -1,21 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- /**
4
- * promise.race() wrapper that aborts rest of promises as soon as the first promise settles.
5
- */
6
- export async function cancelablePromiseRace(abortablePromiseBuilders, options) {
7
- var _a, _b;
8
- const aborter = new AbortController();
9
- function abortHandler() {
10
- aborter.abort();
11
- }
12
- (_a = options === null || options === void 0 ? void 0 : options.abortSignal) === null || _a === void 0 ? void 0 : _a.addEventListener("abort", abortHandler);
13
- try {
14
- return await Promise.race(abortablePromiseBuilders.map((p) => p({ abortSignal: aborter.signal })));
15
- }
16
- finally {
17
- aborter.abort();
18
- (_b = options === null || options === void 0 ? void 0 : options.abortSignal) === null || _b === void 0 ? void 0 : _b.removeEventListener("abort", abortHandler);
19
- }
20
- }
21
- //# sourceMappingURL=aborterUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"aborterUtils.js","sourceRoot":"","sources":["../../../src/util/aborterUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAuBlC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,wBAA8D,EAC9D,OAAuC;;IAEvC,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE,CAAC;IACtC,SAAS,YAAY;QACnB,OAAO,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;IACD,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,0CAAE,gBAAgB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC9D,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CACvB,wBAAwB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CACxE,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,0CAAE,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACnE,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Options related to abort controller.\n */\nexport interface AbortOptions {\n /**\n * The abortSignal associated with containing operation.\n */\n abortSignal?: AbortSignal;\n /**\n * The abort error message associated with containing operation.\n */\n abortErrorMsg?: string;\n}\n\n/**\n * Represents a function that returns a promise that can be aborted.\n */\nexport type AbortablePromiseBuilder<T> = (abortOptions: {\n abortSignal?: AbortSignal;\n}) => Promise<T>;\n\n/**\n * promise.race() wrapper that aborts rest of promises as soon as the first promise settles.\n */\nexport async function cancelablePromiseRace<T extends unknown[]>(\n abortablePromiseBuilders: AbortablePromiseBuilder<T[number]>[],\n options?: { abortSignal?: AbortSignal },\n): Promise<T[number]> {\n const aborter = new AbortController();\n function abortHandler(): void {\n aborter.abort();\n }\n options?.abortSignal?.addEventListener(\"abort\", abortHandler);\n try {\n return await Promise.race(\n abortablePromiseBuilders.map((p) => p({ abortSignal: aborter.signal })),\n );\n } finally {\n aborter.abort();\n options?.abortSignal?.removeEventListener(\"abort\", abortHandler);\n }\n}\n"]}
@@ -1,16 +0,0 @@
1
- import type { AbortOptions } from "./aborterUtils.js";
2
- /**
3
- * Options for the createAbortablePromise function.
4
- */
5
- export interface CreateAbortablePromiseOptions extends AbortOptions {
6
- /** A function to be called if the promise was aborted */
7
- cleanupBeforeAbort?: () => void;
8
- }
9
- /**
10
- * Creates an abortable promise.
11
- * @param buildPromise - A function that takes the resolve and reject functions as parameters.
12
- * @param options - The options for the abortable promise.
13
- * @returns A promise that can be aborted.
14
- */
15
- export declare function createAbortablePromise<T>(buildPromise: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void, options?: CreateAbortablePromiseOptions): Promise<T>;
16
- //# sourceMappingURL=createAbortablePromise.d.ts.map
@@ -1,42 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import { AbortError } from "../abort-controller/AbortError.js";
4
- /**
5
- * Creates an abortable promise.
6
- * @param buildPromise - A function that takes the resolve and reject functions as parameters.
7
- * @param options - The options for the abortable promise.
8
- * @returns A promise that can be aborted.
9
- */
10
- export function createAbortablePromise(buildPromise, options) {
11
- const { cleanupBeforeAbort, abortSignal, abortErrorMsg } = options !== null && options !== void 0 ? options : {};
12
- return new Promise((resolve, reject) => {
13
- function rejectOnAbort() {
14
- reject(new AbortError(abortErrorMsg !== null && abortErrorMsg !== void 0 ? abortErrorMsg : "The operation was aborted."));
15
- }
16
- function removeListeners() {
17
- abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener("abort", onAbort);
18
- }
19
- function onAbort() {
20
- cleanupBeforeAbort === null || cleanupBeforeAbort === void 0 ? void 0 : cleanupBeforeAbort();
21
- removeListeners();
22
- rejectOnAbort();
23
- }
24
- if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
25
- return rejectOnAbort();
26
- }
27
- try {
28
- buildPromise((x) => {
29
- removeListeners();
30
- resolve(x);
31
- }, (x) => {
32
- removeListeners();
33
- reject(x);
34
- });
35
- }
36
- catch (err) {
37
- reject(err);
38
- }
39
- abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.addEventListener("abort", onAbort);
40
- });
41
- }
42
- //# sourceMappingURL=createAbortablePromise.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAbortablePromise.js","sourceRoot":"","sources":["../../../src/util/createAbortablePromise.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAW/D;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,YAGS,EACT,OAAuC;IAEvC,MAAM,EAAE,kBAAkB,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;IACzE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,SAAS,aAAa;YACpB,MAAM,CAAC,IAAI,UAAU,CAAC,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,4BAA4B,CAAC,CAAC,CAAC;QACxE,CAAC;QACD,SAAS,eAAe;YACtB,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACrD,CAAC;QACD,SAAS,OAAO;YACd,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,EAAI,CAAC;YACvB,eAAe,EAAE,CAAC;YAClB,aAAa,EAAE,CAAC;QAClB,CAAC;QACD,IAAI,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,EAAE,CAAC;YACzB,OAAO,aAAa,EAAE,CAAC;QACzB,CAAC;QACD,IAAI,CAAC;YACH,YAAY,CACV,CAAC,CAAC,EAAE,EAAE;gBACJ,eAAe,EAAE,CAAC;gBAClB,OAAO,CAAC,CAAC,CAAC,CAAC;YACb,CAAC,EACD,CAAC,CAAC,EAAE,EAAE;gBACJ,eAAe,EAAE,CAAC;gBAClB,MAAM,CAAC,CAAC,CAAC,CAAC;YACZ,CAAC,CACF,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC;QACD,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AbortError } from \"../abort-controller/AbortError.js\";\nimport type { AbortOptions } from \"./aborterUtils.js\";\n\n/**\n * Options for the createAbortablePromise function.\n */\nexport interface CreateAbortablePromiseOptions extends AbortOptions {\n /** A function to be called if the promise was aborted */\n cleanupBeforeAbort?: () => void;\n}\n\n/**\n * Creates an abortable promise.\n * @param buildPromise - A function that takes the resolve and reject functions as parameters.\n * @param options - The options for the abortable promise.\n * @returns A promise that can be aborted.\n */\nexport function createAbortablePromise<T>(\n buildPromise: (\n resolve: (value: T | PromiseLike<T>) => void,\n reject: (reason?: any) => void,\n ) => void,\n options?: CreateAbortablePromiseOptions,\n): Promise<T> {\n const { cleanupBeforeAbort, abortSignal, abortErrorMsg } = options ?? {};\n return new Promise((resolve, reject) => {\n function rejectOnAbort(): void {\n reject(new AbortError(abortErrorMsg ?? \"The operation was aborted.\"));\n }\n function removeListeners(): void {\n abortSignal?.removeEventListener(\"abort\", onAbort);\n }\n function onAbort(): void {\n cleanupBeforeAbort?.();\n removeListeners();\n rejectOnAbort();\n }\n if (abortSignal?.aborted) {\n return rejectOnAbort();\n }\n try {\n buildPromise(\n (x) => {\n removeListeners();\n resolve(x);\n },\n (x) => {\n removeListeners();\n reject(x);\n },\n );\n } catch (err) {\n reject(err);\n }\n abortSignal?.addEventListener(\"abort\", onAbort);\n });\n}\n"]}
@@ -1,69 +0,0 @@
1
- /**
2
- * Options passed into createFile specifying metadata about the file.
3
- */
4
- export interface CreateFileOptions {
5
- /**
6
- * The MIME type of the file.
7
- */
8
- type?: string;
9
- /**
10
- * Last modified time of the file as a UNIX timestamp.
11
- * This will default to the current date.
12
- */
13
- lastModified?: number;
14
- /**
15
- * relative path of this file when uploading a directory.
16
- */
17
- webkitRelativePath?: string;
18
- }
19
- /**
20
- * Extra options for createFile when a stream is being passed in.
21
- */
22
- export interface CreateFileFromStreamOptions extends CreateFileOptions {
23
- /**
24
- * Size of the file represented by the stream in bytes.
25
- *
26
- * This will be used by the pipeline when calculating the Content-Length header
27
- * for the overall request.
28
- */
29
- size?: number;
30
- }
31
- /**
32
- * Extract the raw content from a given blob-like object. If the input was created using createFile
33
- * or createFileFromStream, the exact content passed into createFile/createFileFromStream will be used.
34
- * For true instances of Blob and File, returns the blob's content as a Web ReadableStream<Uint8Array>.
35
- *
36
- * @internal
37
- */
38
- export declare function getRawContent(blob: Blob): NodeJS.ReadableStream | ReadableStream<Uint8Array> | Uint8Array;
39
- /**
40
- * Create an object that implements the File interface. This object is intended to be
41
- * passed into RequestBodyType.formData, and is not guaranteed to work as expected in
42
- * other situations.
43
- *
44
- * Use this function to:
45
- * - Create a File object for use in RequestBodyType.formData in environments where the
46
- * global File object is unavailable.
47
- * - Create a File-like object from a readable stream without reading the stream into memory.
48
- *
49
- * @param stream - the content of the file as a callback returning a stream. When a File object made using createFile is
50
- * passed in a request's form data map, the stream will not be read into memory
51
- * and instead will be streamed when the request is made. In the event of a retry, the
52
- * stream needs to be read again, so this callback SHOULD return a fresh stream if possible.
53
- * @param name - the name of the file.
54
- * @param options - optional metadata about the file, e.g. file name, file size, MIME type.
55
- */
56
- export declare function createFileFromStream(stream: () => ReadableStream<Uint8Array> | NodeJS.ReadableStream, name: string, options?: CreateFileFromStreamOptions): File;
57
- /**
58
- * Create an object that implements the File interface. This object is intended to be
59
- * passed into RequestBodyType.formData, and is not guaranteed to work as expected in
60
- * other situations.
61
- *
62
- * Use this function create a File object for use in RequestBodyType.formData in environments where the global File object is unavailable.
63
- *
64
- * @param content - the content of the file as a Uint8Array in memory.
65
- * @param name - the name of the file.
66
- * @param options - optional metadata about the file, e.g. file name, file size, MIME type.
67
- */
68
- export declare function createFile(content: Uint8Array, name: string, options?: CreateFileOptions): File;
69
- //# sourceMappingURL=file.d.ts.map
@@ -1,99 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import { isNodeLike } from "./checkEnvironment.js";
4
- import { isNodeReadableStream } from "./typeGuards.js";
5
- const unimplementedMethods = {
6
- arrayBuffer: () => {
7
- throw new Error("Not implemented");
8
- },
9
- bytes: () => {
10
- throw new Error("Not implemented");
11
- },
12
- slice: () => {
13
- throw new Error("Not implemented");
14
- },
15
- text: () => {
16
- throw new Error("Not implemented");
17
- },
18
- };
19
- /**
20
- * Private symbol used as key on objects created using createFile containing the
21
- * original source of the file object.
22
- *
23
- * This is used in Node to access the original Node stream without using Blob#stream, which
24
- * returns a web stream. This is done to avoid a couple of bugs to do with Blob#stream and
25
- * Readable#to/fromWeb in Node versions we support:
26
- * - https://github.com/nodejs/node/issues/42694 (fixed in Node 18.14)
27
- * - https://github.com/nodejs/node/issues/48916 (fixed in Node 20.6)
28
- *
29
- * Once these versions are no longer supported, we may be able to stop doing this.
30
- *
31
- * @internal
32
- */
33
- const rawContent = Symbol("rawContent");
34
- function hasRawContent(x) {
35
- return typeof x[rawContent] === "function";
36
- }
37
- /**
38
- * Extract the raw content from a given blob-like object. If the input was created using createFile
39
- * or createFileFromStream, the exact content passed into createFile/createFileFromStream will be used.
40
- * For true instances of Blob and File, returns the blob's content as a Web ReadableStream<Uint8Array>.
41
- *
42
- * @internal
43
- */
44
- export function getRawContent(blob) {
45
- if (hasRawContent(blob)) {
46
- return blob[rawContent]();
47
- }
48
- else {
49
- return blob.stream();
50
- }
51
- }
52
- /**
53
- * Create an object that implements the File interface. This object is intended to be
54
- * passed into RequestBodyType.formData, and is not guaranteed to work as expected in
55
- * other situations.
56
- *
57
- * Use this function to:
58
- * - Create a File object for use in RequestBodyType.formData in environments where the
59
- * global File object is unavailable.
60
- * - Create a File-like object from a readable stream without reading the stream into memory.
61
- *
62
- * @param stream - the content of the file as a callback returning a stream. When a File object made using createFile is
63
- * passed in a request's form data map, the stream will not be read into memory
64
- * and instead will be streamed when the request is made. In the event of a retry, the
65
- * stream needs to be read again, so this callback SHOULD return a fresh stream if possible.
66
- * @param name - the name of the file.
67
- * @param options - optional metadata about the file, e.g. file name, file size, MIME type.
68
- */
69
- export function createFileFromStream(stream, name, options = {}) {
70
- var _a, _b, _c, _d;
71
- return Object.assign(Object.assign({}, unimplementedMethods), { type: (_a = options.type) !== null && _a !== void 0 ? _a : "", lastModified: (_b = options.lastModified) !== null && _b !== void 0 ? _b : new Date().getTime(), webkitRelativePath: (_c = options.webkitRelativePath) !== null && _c !== void 0 ? _c : "", size: (_d = options.size) !== null && _d !== void 0 ? _d : -1, name, stream: () => {
72
- const s = stream();
73
- if (isNodeReadableStream(s)) {
74
- throw new Error("Not supported: a Node stream was provided as input to createFileFromStream.");
75
- }
76
- return s;
77
- }, [rawContent]: stream });
78
- }
79
- /**
80
- * Create an object that implements the File interface. This object is intended to be
81
- * passed into RequestBodyType.formData, and is not guaranteed to work as expected in
82
- * other situations.
83
- *
84
- * Use this function create a File object for use in RequestBodyType.formData in environments where the global File object is unavailable.
85
- *
86
- * @param content - the content of the file as a Uint8Array in memory.
87
- * @param name - the name of the file.
88
- * @param options - optional metadata about the file, e.g. file name, file size, MIME type.
89
- */
90
- export function createFile(content, name, options = {}) {
91
- var _a, _b, _c;
92
- if (isNodeLike) {
93
- return Object.assign(Object.assign({}, unimplementedMethods), { type: (_a = options.type) !== null && _a !== void 0 ? _a : "", lastModified: (_b = options.lastModified) !== null && _b !== void 0 ? _b : new Date().getTime(), webkitRelativePath: (_c = options.webkitRelativePath) !== null && _c !== void 0 ? _c : "", size: content.byteLength, name, arrayBuffer: async () => content.buffer, stream: () => new Blob([content]).stream(), [rawContent]: () => content });
94
- }
95
- else {
96
- return new File([content], name, options);
97
- }
98
- }
99
- //# sourceMappingURL=file.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/util/file.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAoCvD,MAAM,oBAAoB,GAAG;IAC3B,WAAW,EAAE,GAAG,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,KAAK,EAAE,GAAG,EAAE;QACV,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,KAAK,EAAE,GAAG,EAAE;QACV,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,IAAI,EAAE,GAAG,EAAE;QACT,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;CACF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,GAAkB,MAAM,CAAC,YAAY,CAAC,CAAC;AASvD,SAAS,aAAa,CAAC,CAAU;IAC/B,OAAO,OAAQ,CAAgB,CAAC,UAAU,CAAC,KAAK,UAAU,CAAC;AAC7D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAU;IAEV,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;IAC5B,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAgE,EAChE,IAAY,EACZ,UAAuC,EAAE;;IAEzC,OAAO,gCACF,oBAAoB,KACvB,IAAI,EAAE,MAAA,OAAO,CAAC,IAAI,mCAAI,EAAE,EACxB,YAAY,EAAE,MAAA,OAAO,CAAC,YAAY,mCAAI,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,EAC1D,kBAAkB,EAAE,MAAA,OAAO,CAAC,kBAAkB,mCAAI,EAAE,EACpD,IAAI,EAAE,MAAA,OAAO,CAAC,IAAI,mCAAI,CAAC,CAAC,EACxB,IAAI,EACJ,MAAM,EAAE,GAAG,EAAE;YACX,MAAM,CAAC,GAAG,MAAM,EAAE,CAAC;YACnB,IAAI,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CACb,6EAA6E,CAC9E,CAAC;YACJ,CAAC;YAED,OAAO,CAAC,CAAC;QACX,CAAC,EACD,CAAC,UAAU,CAAC,EAAE,MAAM,GACA,CAAC;AACzB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU,CACxB,OAAmB,EACnB,IAAY,EACZ,UAA6B,EAAE;;IAE/B,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,gCACF,oBAAoB,KACvB,IAAI,EAAE,MAAA,OAAO,CAAC,IAAI,mCAAI,EAAE,EACxB,YAAY,EAAE,MAAA,OAAO,CAAC,YAAY,mCAAI,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,EAC1D,kBAAkB,EAAE,MAAA,OAAO,CAAC,kBAAkB,mCAAI,EAAE,EACpD,IAAI,EAAE,OAAO,CAAC,UAAU,EACxB,IAAI,EACJ,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EACvC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,EAC1C,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC,OAAO,GACP,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { isNodeLike } from \"./checkEnvironment.js\";\nimport { isNodeReadableStream } from \"./typeGuards.js\";\n\n/**\n * Options passed into createFile specifying metadata about the file.\n */\nexport interface CreateFileOptions {\n /**\n * The MIME type of the file.\n */\n type?: string;\n\n /**\n * Last modified time of the file as a UNIX timestamp.\n * This will default to the current date.\n */\n lastModified?: number;\n\n /**\n * relative path of this file when uploading a directory.\n */\n webkitRelativePath?: string;\n}\n\n/**\n * Extra options for createFile when a stream is being passed in.\n */\nexport interface CreateFileFromStreamOptions extends CreateFileOptions {\n /**\n * Size of the file represented by the stream in bytes.\n *\n * This will be used by the pipeline when calculating the Content-Length header\n * for the overall request.\n */\n size?: number;\n}\n\nconst unimplementedMethods = {\n arrayBuffer: () => {\n throw new Error(\"Not implemented\");\n },\n bytes: () => {\n throw new Error(\"Not implemented\");\n },\n slice: () => {\n throw new Error(\"Not implemented\");\n },\n text: () => {\n throw new Error(\"Not implemented\");\n },\n};\n\n/**\n * Private symbol used as key on objects created using createFile containing the\n * original source of the file object.\n *\n * This is used in Node to access the original Node stream without using Blob#stream, which\n * returns a web stream. This is done to avoid a couple of bugs to do with Blob#stream and\n * Readable#to/fromWeb in Node versions we support:\n * - https://github.com/nodejs/node/issues/42694 (fixed in Node 18.14)\n * - https://github.com/nodejs/node/issues/48916 (fixed in Node 20.6)\n *\n * Once these versions are no longer supported, we may be able to stop doing this.\n *\n * @internal\n */\nconst rawContent: unique symbol = Symbol(\"rawContent\");\n\n/**\n * Type signature of a blob-like object with a raw content property.\n */\ninterface RawContent {\n [rawContent](): Uint8Array | NodeJS.ReadableStream | ReadableStream<Uint8Array>;\n}\n\nfunction hasRawContent(x: unknown): x is RawContent {\n return typeof (x as RawContent)[rawContent] === \"function\";\n}\n\n/**\n * Extract the raw content from a given blob-like object. If the input was created using createFile\n * or createFileFromStream, the exact content passed into createFile/createFileFromStream will be used.\n * For true instances of Blob and File, returns the blob's content as a Web ReadableStream<Uint8Array>.\n *\n * @internal\n */\nexport function getRawContent(\n blob: Blob,\n): NodeJS.ReadableStream | ReadableStream<Uint8Array> | Uint8Array {\n if (hasRawContent(blob)) {\n return blob[rawContent]();\n } else {\n return blob.stream();\n }\n}\n\n/**\n * Create an object that implements the File interface. This object is intended to be\n * passed into RequestBodyType.formData, and is not guaranteed to work as expected in\n * other situations.\n *\n * Use this function to:\n * - Create a File object for use in RequestBodyType.formData in environments where the\n * global File object is unavailable.\n * - Create a File-like object from a readable stream without reading the stream into memory.\n *\n * @param stream - the content of the file as a callback returning a stream. When a File object made using createFile is\n * passed in a request's form data map, the stream will not be read into memory\n * and instead will be streamed when the request is made. In the event of a retry, the\n * stream needs to be read again, so this callback SHOULD return a fresh stream if possible.\n * @param name - the name of the file.\n * @param options - optional metadata about the file, e.g. file name, file size, MIME type.\n */\nexport function createFileFromStream(\n stream: () => ReadableStream<Uint8Array> | NodeJS.ReadableStream,\n name: string,\n options: CreateFileFromStreamOptions = {},\n): File {\n return {\n ...unimplementedMethods,\n type: options.type ?? \"\",\n lastModified: options.lastModified ?? new Date().getTime(),\n webkitRelativePath: options.webkitRelativePath ?? \"\",\n size: options.size ?? -1,\n name,\n stream: () => {\n const s = stream();\n if (isNodeReadableStream(s)) {\n throw new Error(\n \"Not supported: a Node stream was provided as input to createFileFromStream.\",\n );\n }\n\n return s;\n },\n [rawContent]: stream,\n } as File & RawContent;\n}\n\n/**\n * Create an object that implements the File interface. This object is intended to be\n * passed into RequestBodyType.formData, and is not guaranteed to work as expected in\n * other situations.\n *\n * Use this function create a File object for use in RequestBodyType.formData in environments where the global File object is unavailable.\n *\n * @param content - the content of the file as a Uint8Array in memory.\n * @param name - the name of the file.\n * @param options - optional metadata about the file, e.g. file name, file size, MIME type.\n */\nexport function createFile(\n content: Uint8Array,\n name: string,\n options: CreateFileOptions = {},\n): File {\n if (isNodeLike) {\n return {\n ...unimplementedMethods,\n type: options.type ?? \"\",\n lastModified: options.lastModified ?? new Date().getTime(),\n webkitRelativePath: options.webkitRelativePath ?? \"\",\n size: content.byteLength,\n name,\n arrayBuffer: async () => content.buffer,\n stream: () => new Blob([content]).stream(),\n [rawContent]: () => content,\n } as File & RawContent;\n } else {\n return new File([content], name, options);\n }\n}\n"]}
@@ -1,26 +0,0 @@
1
- /**
2
- * Options related to abort controller.
3
- */
4
- export interface AbortOptions {
5
- /**
6
- * The abortSignal associated with containing operation.
7
- */
8
- abortSignal?: AbortSignal;
9
- /**
10
- * The abort error message associated with containing operation.
11
- */
12
- abortErrorMsg?: string;
13
- }
14
- /**
15
- * Represents a function that returns a promise that can be aborted.
16
- */
17
- export type AbortablePromiseBuilder<T> = (abortOptions: {
18
- abortSignal?: AbortSignal;
19
- }) => Promise<T>;
20
- /**
21
- * promise.race() wrapper that aborts rest of promises as soon as the first promise settles.
22
- */
23
- export declare function cancelablePromiseRace<T extends unknown[]>(abortablePromiseBuilders: AbortablePromiseBuilder<T[number]>[], options?: {
24
- abortSignal?: AbortSignal;
25
- }): Promise<T[number]>;
26
- //# sourceMappingURL=aborterUtils.d.ts.map
@@ -1,24 +0,0 @@
1
- "use strict";
2
- // Copyright (c) Microsoft Corporation.
3
- // Licensed under the MIT License.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.cancelablePromiseRace = cancelablePromiseRace;
6
- /**
7
- * promise.race() wrapper that aborts rest of promises as soon as the first promise settles.
8
- */
9
- async function cancelablePromiseRace(abortablePromiseBuilders, options) {
10
- var _a, _b;
11
- const aborter = new AbortController();
12
- function abortHandler() {
13
- aborter.abort();
14
- }
15
- (_a = options === null || options === void 0 ? void 0 : options.abortSignal) === null || _a === void 0 ? void 0 : _a.addEventListener("abort", abortHandler);
16
- try {
17
- return await Promise.race(abortablePromiseBuilders.map((p) => p({ abortSignal: aborter.signal })));
18
- }
19
- finally {
20
- aborter.abort();
21
- (_b = options === null || options === void 0 ? void 0 : options.abortSignal) === null || _b === void 0 ? void 0 : _b.removeEventListener("abort", abortHandler);
22
- }
23
- }
24
- //# sourceMappingURL=aborterUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"aborterUtils.js","sourceRoot":"","sources":["../../../src/util/aborterUtils.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AA0BlC,sDAiBC;AApBD;;GAEG;AACI,KAAK,UAAU,qBAAqB,CACzC,wBAA8D,EAC9D,OAAuC;;IAEvC,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE,CAAC;IACtC,SAAS,YAAY;QACnB,OAAO,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;IACD,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,0CAAE,gBAAgB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC9D,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CACvB,wBAAwB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CACxE,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,0CAAE,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACnE,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Options related to abort controller.\n */\nexport interface AbortOptions {\n /**\n * The abortSignal associated with containing operation.\n */\n abortSignal?: AbortSignal;\n /**\n * The abort error message associated with containing operation.\n */\n abortErrorMsg?: string;\n}\n\n/**\n * Represents a function that returns a promise that can be aborted.\n */\nexport type AbortablePromiseBuilder<T> = (abortOptions: {\n abortSignal?: AbortSignal;\n}) => Promise<T>;\n\n/**\n * promise.race() wrapper that aborts rest of promises as soon as the first promise settles.\n */\nexport async function cancelablePromiseRace<T extends unknown[]>(\n abortablePromiseBuilders: AbortablePromiseBuilder<T[number]>[],\n options?: { abortSignal?: AbortSignal },\n): Promise<T[number]> {\n const aborter = new AbortController();\n function abortHandler(): void {\n aborter.abort();\n }\n options?.abortSignal?.addEventListener(\"abort\", abortHandler);\n try {\n return await Promise.race(\n abortablePromiseBuilders.map((p) => p({ abortSignal: aborter.signal })),\n );\n } finally {\n aborter.abort();\n options?.abortSignal?.removeEventListener(\"abort\", abortHandler);\n }\n}\n"]}
@@ -1,16 +0,0 @@
1
- import type { AbortOptions } from "./aborterUtils.js";
2
- /**
3
- * Options for the createAbortablePromise function.
4
- */
5
- export interface CreateAbortablePromiseOptions extends AbortOptions {
6
- /** A function to be called if the promise was aborted */
7
- cleanupBeforeAbort?: () => void;
8
- }
9
- /**
10
- * Creates an abortable promise.
11
- * @param buildPromise - A function that takes the resolve and reject functions as parameters.
12
- * @param options - The options for the abortable promise.
13
- * @returns A promise that can be aborted.
14
- */
15
- export declare function createAbortablePromise<T>(buildPromise: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void, options?: CreateAbortablePromiseOptions): Promise<T>;
16
- //# sourceMappingURL=createAbortablePromise.d.ts.map
@@ -1,45 +0,0 @@
1
- "use strict";
2
- // Copyright (c) Microsoft Corporation.
3
- // Licensed under the MIT License.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.createAbortablePromise = createAbortablePromise;
6
- const AbortError_js_1 = require("../abort-controller/AbortError.js");
7
- /**
8
- * Creates an abortable promise.
9
- * @param buildPromise - A function that takes the resolve and reject functions as parameters.
10
- * @param options - The options for the abortable promise.
11
- * @returns A promise that can be aborted.
12
- */
13
- function createAbortablePromise(buildPromise, options) {
14
- const { cleanupBeforeAbort, abortSignal, abortErrorMsg } = options !== null && options !== void 0 ? options : {};
15
- return new Promise((resolve, reject) => {
16
- function rejectOnAbort() {
17
- reject(new AbortError_js_1.AbortError(abortErrorMsg !== null && abortErrorMsg !== void 0 ? abortErrorMsg : "The operation was aborted."));
18
- }
19
- function removeListeners() {
20
- abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener("abort", onAbort);
21
- }
22
- function onAbort() {
23
- cleanupBeforeAbort === null || cleanupBeforeAbort === void 0 ? void 0 : cleanupBeforeAbort();
24
- removeListeners();
25
- rejectOnAbort();
26
- }
27
- if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
28
- return rejectOnAbort();
29
- }
30
- try {
31
- buildPromise((x) => {
32
- removeListeners();
33
- resolve(x);
34
- }, (x) => {
35
- removeListeners();
36
- reject(x);
37
- });
38
- }
39
- catch (err) {
40
- reject(err);
41
- }
42
- abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.addEventListener("abort", onAbort);
43
- });
44
- }
45
- //# sourceMappingURL=createAbortablePromise.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAbortablePromise.js","sourceRoot":"","sources":["../../../src/util/createAbortablePromise.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAmBlC,wDAuCC;AAxDD,qEAA+D;AAW/D;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,YAGS,EACT,OAAuC;IAEvC,MAAM,EAAE,kBAAkB,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;IACzE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,SAAS,aAAa;YACpB,MAAM,CAAC,IAAI,0BAAU,CAAC,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,4BAA4B,CAAC,CAAC,CAAC;QACxE,CAAC;QACD,SAAS,eAAe;YACtB,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACrD,CAAC;QACD,SAAS,OAAO;YACd,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,EAAI,CAAC;YACvB,eAAe,EAAE,CAAC;YAClB,aAAa,EAAE,CAAC;QAClB,CAAC;QACD,IAAI,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,EAAE,CAAC;YACzB,OAAO,aAAa,EAAE,CAAC;QACzB,CAAC;QACD,IAAI,CAAC;YACH,YAAY,CACV,CAAC,CAAC,EAAE,EAAE;gBACJ,eAAe,EAAE,CAAC;gBAClB,OAAO,CAAC,CAAC,CAAC,CAAC;YACb,CAAC,EACD,CAAC,CAAC,EAAE,EAAE;gBACJ,eAAe,EAAE,CAAC;gBAClB,MAAM,CAAC,CAAC,CAAC,CAAC;YACZ,CAAC,CACF,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC;QACD,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AbortError } from \"../abort-controller/AbortError.js\";\nimport type { AbortOptions } from \"./aborterUtils.js\";\n\n/**\n * Options for the createAbortablePromise function.\n */\nexport interface CreateAbortablePromiseOptions extends AbortOptions {\n /** A function to be called if the promise was aborted */\n cleanupBeforeAbort?: () => void;\n}\n\n/**\n * Creates an abortable promise.\n * @param buildPromise - A function that takes the resolve and reject functions as parameters.\n * @param options - The options for the abortable promise.\n * @returns A promise that can be aborted.\n */\nexport function createAbortablePromise<T>(\n buildPromise: (\n resolve: (value: T | PromiseLike<T>) => void,\n reject: (reason?: any) => void,\n ) => void,\n options?: CreateAbortablePromiseOptions,\n): Promise<T> {\n const { cleanupBeforeAbort, abortSignal, abortErrorMsg } = options ?? {};\n return new Promise((resolve, reject) => {\n function rejectOnAbort(): void {\n reject(new AbortError(abortErrorMsg ?? \"The operation was aborted.\"));\n }\n function removeListeners(): void {\n abortSignal?.removeEventListener(\"abort\", onAbort);\n }\n function onAbort(): void {\n cleanupBeforeAbort?.();\n removeListeners();\n rejectOnAbort();\n }\n if (abortSignal?.aborted) {\n return rejectOnAbort();\n }\n try {\n buildPromise(\n (x) => {\n removeListeners();\n resolve(x);\n },\n (x) => {\n removeListeners();\n reject(x);\n },\n );\n } catch (err) {\n reject(err);\n }\n abortSignal?.addEventListener(\"abort\", onAbort);\n });\n}\n"]}
@@ -1,69 +0,0 @@
1
- /**
2
- * Options passed into createFile specifying metadata about the file.
3
- */
4
- export interface CreateFileOptions {
5
- /**
6
- * The MIME type of the file.
7
- */
8
- type?: string;
9
- /**
10
- * Last modified time of the file as a UNIX timestamp.
11
- * This will default to the current date.
12
- */
13
- lastModified?: number;
14
- /**
15
- * relative path of this file when uploading a directory.
16
- */
17
- webkitRelativePath?: string;
18
- }
19
- /**
20
- * Extra options for createFile when a stream is being passed in.
21
- */
22
- export interface CreateFileFromStreamOptions extends CreateFileOptions {
23
- /**
24
- * Size of the file represented by the stream in bytes.
25
- *
26
- * This will be used by the pipeline when calculating the Content-Length header
27
- * for the overall request.
28
- */
29
- size?: number;
30
- }
31
- /**
32
- * Extract the raw content from a given blob-like object. If the input was created using createFile
33
- * or createFileFromStream, the exact content passed into createFile/createFileFromStream will be used.
34
- * For true instances of Blob and File, returns the blob's content as a Web ReadableStream<Uint8Array>.
35
- *
36
- * @internal
37
- */
38
- export declare function getRawContent(blob: Blob): NodeJS.ReadableStream | ReadableStream<Uint8Array> | Uint8Array;
39
- /**
40
- * Create an object that implements the File interface. This object is intended to be
41
- * passed into RequestBodyType.formData, and is not guaranteed to work as expected in
42
- * other situations.
43
- *
44
- * Use this function to:
45
- * - Create a File object for use in RequestBodyType.formData in environments where the
46
- * global File object is unavailable.
47
- * - Create a File-like object from a readable stream without reading the stream into memory.
48
- *
49
- * @param stream - the content of the file as a callback returning a stream. When a File object made using createFile is
50
- * passed in a request's form data map, the stream will not be read into memory
51
- * and instead will be streamed when the request is made. In the event of a retry, the
52
- * stream needs to be read again, so this callback SHOULD return a fresh stream if possible.
53
- * @param name - the name of the file.
54
- * @param options - optional metadata about the file, e.g. file name, file size, MIME type.
55
- */
56
- export declare function createFileFromStream(stream: () => ReadableStream<Uint8Array> | NodeJS.ReadableStream, name: string, options?: CreateFileFromStreamOptions): File;
57
- /**
58
- * Create an object that implements the File interface. This object is intended to be
59
- * passed into RequestBodyType.formData, and is not guaranteed to work as expected in
60
- * other situations.
61
- *
62
- * Use this function create a File object for use in RequestBodyType.formData in environments where the global File object is unavailable.
63
- *
64
- * @param content - the content of the file as a Uint8Array in memory.
65
- * @param name - the name of the file.
66
- * @param options - optional metadata about the file, e.g. file name, file size, MIME type.
67
- */
68
- export declare function createFile(content: Uint8Array, name: string, options?: CreateFileOptions): File;
69
- //# sourceMappingURL=file.d.ts.map