@typespec/ts-http-runtime 1.0.0-alpha.20240226.1 → 1.0.0-alpha.20240228.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.
- package/dist/browser/auth/keyCredential.d.ts +6 -0
- package/dist/browser/auth/keyCredential.d.ts.map +1 -1
- package/dist/browser/auth/keyCredential.js +9 -1
- package/dist/browser/auth/keyCredential.js.map +1 -1
- package/dist/browser/client/clientHelpers.d.ts.map +1 -1
- package/dist/browser/client/clientHelpers.js +1 -3
- package/dist/browser/client/clientHelpers.js.map +1 -1
- package/dist/browser/client/getClient.d.ts.map +1 -1
- package/dist/browser/client/getClient.js +5 -7
- package/dist/browser/client/getClient.js.map +1 -1
- package/dist/browser/client/sendRequest.d.ts +1 -14
- package/dist/browser/client/sendRequest.d.ts.map +1 -1
- package/dist/browser/client/sendRequest.js +50 -51
- package/dist/browser/client/sendRequest.js.map +1 -1
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +1 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/nodeHttpClient.js.map +1 -1
- package/dist/browser/policies/formDataPolicy.js +5 -3
- package/dist/browser/policies/formDataPolicy.js.map +1 -1
- package/dist/browser/policies/multipartPolicy.d.ts.map +1 -1
- package/dist/browser/policies/multipartPolicy.js +5 -5
- package/dist/browser/policies/multipartPolicy.js.map +1 -1
- package/dist/browser/util/concat-browser.d.mts.map +1 -0
- package/dist/browser/util/concat-browser.mjs.map +1 -0
- package/dist/browser/util/concat.d.ts +19 -0
- package/dist/browser/util/concat.js +45 -0
- package/dist/browser/util/file.d.ts +8 -0
- package/dist/browser/util/file.d.ts.map +1 -1
- package/dist/browser/util/file.js +59 -12
- package/dist/browser/util/file.js.map +1 -1
- package/dist/commonjs/auth/keyCredential.d.ts +6 -0
- package/dist/commonjs/auth/keyCredential.d.ts.map +1 -1
- package/dist/commonjs/auth/keyCredential.js +11 -0
- package/dist/commonjs/auth/keyCredential.js.map +1 -1
- package/dist/commonjs/client/clientHelpers.d.ts.map +1 -1
- package/dist/commonjs/client/clientHelpers.js +2 -4
- package/dist/commonjs/client/clientHelpers.js.map +1 -1
- package/dist/commonjs/client/getClient.d.ts.map +1 -1
- package/dist/commonjs/client/getClient.js +4 -6
- package/dist/commonjs/client/getClient.js.map +1 -1
- package/dist/commonjs/client/sendRequest.d.ts +1 -14
- package/dist/commonjs/client/sendRequest.d.ts.map +1 -1
- package/dist/commonjs/client/sendRequest.js +51 -53
- package/dist/commonjs/client/sendRequest.js.map +1 -1
- package/dist/commonjs/index.d.ts +1 -1
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +4 -2
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/nodeHttpClient.js.map +1 -1
- package/dist/commonjs/policies/formDataPolicy.js +5 -3
- package/dist/commonjs/policies/formDataPolicy.js.map +1 -1
- package/dist/commonjs/policies/multipartPolicy.d.ts.map +1 -1
- package/dist/commonjs/policies/multipartPolicy.js +5 -5
- package/dist/commonjs/policies/multipartPolicy.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/commonjs/util/concat.d.ts +18 -0
- package/dist/commonjs/util/concat.d.ts.map +1 -0
- package/dist/commonjs/util/concat.js +74 -0
- package/dist/commonjs/util/concat.js.map +1 -0
- package/dist/commonjs/util/file.d.ts +8 -0
- package/dist/commonjs/util/file.d.ts.map +1 -1
- package/dist/commonjs/util/file.js +61 -13
- package/dist/commonjs/util/file.js.map +1 -1
- package/dist/esm/auth/keyCredential.d.ts +6 -0
- package/dist/esm/auth/keyCredential.d.ts.map +1 -1
- package/dist/esm/auth/keyCredential.js +9 -1
- package/dist/esm/auth/keyCredential.js.map +1 -1
- package/dist/esm/client/clientHelpers.d.ts.map +1 -1
- package/dist/esm/client/clientHelpers.js +1 -3
- package/dist/esm/client/clientHelpers.js.map +1 -1
- package/dist/esm/client/getClient.d.ts.map +1 -1
- package/dist/esm/client/getClient.js +5 -7
- package/dist/esm/client/getClient.js.map +1 -1
- package/dist/esm/client/sendRequest.d.ts +1 -14
- package/dist/esm/client/sendRequest.d.ts.map +1 -1
- package/dist/esm/client/sendRequest.js +50 -51
- package/dist/esm/client/sendRequest.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/nodeHttpClient.js.map +1 -1
- package/dist/esm/policies/formDataPolicy.js +5 -3
- package/dist/esm/policies/formDataPolicy.js.map +1 -1
- package/dist/esm/policies/multipartPolicy.d.ts.map +1 -1
- package/dist/esm/policies/multipartPolicy.js +5 -5
- package/dist/esm/policies/multipartPolicy.js.map +1 -1
- package/dist/esm/util/concat.d.ts +18 -0
- package/dist/esm/util/concat.d.ts.map +1 -0
- package/dist/esm/util/concat.js +70 -0
- package/dist/esm/util/concat.js.map +1 -0
- package/dist/esm/util/file.d.ts +8 -0
- package/dist/esm/util/file.d.ts.map +1 -1
- package/dist/esm/util/file.js +59 -12
- package/dist/esm/util/file.js.map +1 -1
- package/dist/react-native/auth/keyCredential.d.ts +6 -0
- package/dist/react-native/auth/keyCredential.d.ts.map +1 -1
- package/dist/react-native/auth/keyCredential.js +9 -1
- package/dist/react-native/auth/keyCredential.js.map +1 -1
- package/dist/react-native/client/clientHelpers.d.ts.map +1 -1
- package/dist/react-native/client/clientHelpers.js +1 -3
- package/dist/react-native/client/clientHelpers.js.map +1 -1
- package/dist/react-native/client/getClient.d.ts.map +1 -1
- package/dist/react-native/client/getClient.js +5 -7
- package/dist/react-native/client/getClient.js.map +1 -1
- package/dist/react-native/client/sendRequest.d.ts +1 -14
- package/dist/react-native/client/sendRequest.d.ts.map +1 -1
- package/dist/react-native/client/sendRequest.js +50 -51
- package/dist/react-native/client/sendRequest.js.map +1 -1
- package/dist/react-native/index.d.ts +1 -1
- package/dist/react-native/index.d.ts.map +1 -1
- package/dist/react-native/index.js +1 -0
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native/nodeHttpClient.js.map +1 -1
- package/dist/react-native/policies/formDataPolicy.js +5 -3
- package/dist/react-native/policies/formDataPolicy.js.map +1 -1
- package/dist/react-native/policies/multipartPolicy.d.ts.map +1 -1
- package/dist/react-native/policies/multipartPolicy.js +5 -5
- package/dist/react-native/policies/multipartPolicy.js.map +1 -1
- package/dist/react-native/util/concat.d.ts +18 -0
- package/dist/react-native/util/concat.d.ts.map +1 -0
- package/dist/react-native/util/concat.js +70 -0
- package/dist/react-native/util/concat.js.map +1 -0
- package/dist/react-native/util/file.d.ts +8 -0
- package/dist/react-native/util/file.d.ts.map +1 -1
- package/dist/react-native/util/file.js +59 -12
- package/dist/react-native/util/file.js.map +1 -1
- package/dist/react-native/util/userAgentPlatform-react-native.d.mts.map +1 -1
- package/dist/react-native/util/userAgentPlatform-react-native.mjs.map +1 -1
- package/dist/react-native/util/userAgentPlatform.js +1 -3
- package/dist/ts-http-runtime.d.ts +7 -0
- package/package.json +5 -5
- package/dist/browser/client/helpers/getBinaryBody.d.ts +0 -5
- package/dist/browser/client/helpers/getBinaryBody.d.ts.map +0 -1
- package/dist/browser/client/helpers/getBinaryBody.js +0 -13
- package/dist/browser/client/helpers/getBinaryBody.js.map +0 -1
- package/dist/browser/util/stream-browser.d.mts.map +0 -1
- package/dist/browser/util/stream-browser.mjs.map +0 -1
- package/dist/browser/util/stream.d.ts +0 -5
- package/dist/browser/util/stream.js +0 -62
- package/dist/commonjs/client/helpers/getBinaryBody.d.ts +0 -5
- package/dist/commonjs/client/helpers/getBinaryBody.d.ts.map +0 -1
- package/dist/commonjs/client/helpers/getBinaryBody.js +0 -17
- package/dist/commonjs/client/helpers/getBinaryBody.js.map +0 -1
- package/dist/commonjs/util/stream.d.ts +0 -5
- package/dist/commonjs/util/stream.d.ts.map +0 -1
- package/dist/commonjs/util/stream.js +0 -69
- package/dist/commonjs/util/stream.js.map +0 -1
- package/dist/esm/client/helpers/getBinaryBody.d.ts +0 -5
- package/dist/esm/client/helpers/getBinaryBody.d.ts.map +0 -1
- package/dist/esm/client/helpers/getBinaryBody.js +0 -13
- package/dist/esm/client/helpers/getBinaryBody.js.map +0 -1
- package/dist/esm/util/stream.d.ts +0 -5
- package/dist/esm/util/stream.d.ts.map +0 -1
- package/dist/esm/util/stream.js +0 -63
- package/dist/esm/util/stream.js.map +0 -1
- package/dist/react-native/client/helpers/getBinaryBody.d.ts +0 -5
- package/dist/react-native/client/helpers/getBinaryBody.d.ts.map +0 -1
- package/dist/react-native/client/helpers/getBinaryBody.js +0 -13
- package/dist/react-native/client/helpers/getBinaryBody.js.map +0 -1
- package/dist/react-native/util/stream.d.ts +0 -5
- package/dist/react-native/util/stream.d.ts.map +0 -1
- package/dist/react-native/util/stream.js +0 -63
- package/dist/react-native/util/stream.js.map +0 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
import { Readable } from "stream";
|
|
4
|
+
import { isBlob } from "./typeGuards.js";
|
|
5
|
+
import { getRawContent } from "./file.js";
|
|
6
|
+
async function* streamAsyncIterator() {
|
|
7
|
+
const reader = this.getReader();
|
|
8
|
+
try {
|
|
9
|
+
while (true) {
|
|
10
|
+
const { done, value } = await reader.read();
|
|
11
|
+
if (done) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
yield value;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
finally {
|
|
18
|
+
reader.releaseLock();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function makeAsyncIterable(webStream) {
|
|
22
|
+
if (!webStream[Symbol.asyncIterator]) {
|
|
23
|
+
webStream[Symbol.asyncIterator] = streamAsyncIterator.bind(webStream);
|
|
24
|
+
}
|
|
25
|
+
if (!webStream.values) {
|
|
26
|
+
webStream.values = streamAsyncIterator.bind(webStream);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function ensureNodeStream(stream) {
|
|
30
|
+
if (stream instanceof ReadableStream) {
|
|
31
|
+
makeAsyncIterable(stream);
|
|
32
|
+
return Readable.fromWeb(stream);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return stream;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function toStream(source) {
|
|
39
|
+
if (source instanceof Uint8Array) {
|
|
40
|
+
return Readable.from(Buffer.from(source));
|
|
41
|
+
}
|
|
42
|
+
else if (isBlob(source)) {
|
|
43
|
+
return toStream(getRawContent(source));
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return ensureNodeStream(source);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Utility function that concatenates a set of binary inputs into one combined output.
|
|
51
|
+
*
|
|
52
|
+
* @param sources - array of sources for the concatenation
|
|
53
|
+
* @returns - in Node, a (() =\> NodeJS.ReadableStream) which, when read, produces a concatenation of all the inputs.
|
|
54
|
+
* In browser, returns a `Blob` representing all the concatenated inputs.
|
|
55
|
+
*
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
58
|
+
export async function concat(sources) {
|
|
59
|
+
return function () {
|
|
60
|
+
const streams = sources.map((x) => (typeof x === "function" ? x() : x)).map(toStream);
|
|
61
|
+
return Readable.from((async function* () {
|
|
62
|
+
for (const stream of streams) {
|
|
63
|
+
for await (const chunk of stream) {
|
|
64
|
+
yield chunk;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
})());
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=concat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concat.js","sourceRoot":"","sources":["../../../src/util/concat.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,MAAM,EAA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AAI,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IACzC,CAAC;SAAM,CAAC;QACN,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;AACH,CAAC;AASD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,OAAgD;IAEhD,OAAO;QACL,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAEtF,OAAO,QAAQ,CAAC,IAAI,CAClB,CAAC,KAAK,SAAS,CAAC;YACd,KAAK,MAAM,MAAM,IAAI,OAAkC,EAAE,CAAC;gBACxD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;oBACjC,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC,CAAC,EAAE,CACL,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Readable } from \"stream\";\nimport type { ReadableStream as AsyncIterableReadableStream } from \"stream/web\";\nimport { isBlob } from \"./typeGuards.js\";\nimport { getRawContent } from \"./file.js\";\n\nasync function* streamAsyncIterator(\n this: ReadableStream<Uint8Array>,\n): AsyncIterableIterator<Uint8Array> {\n const reader = this.getReader();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n return;\n }\n\n yield value;\n }\n } finally {\n reader.releaseLock();\n }\n}\n\nfunction makeAsyncIterable<T>(webStream: any): asserts webStream is AsyncIterableReadableStream<T> {\n if (!webStream[Symbol.asyncIterator]) {\n webStream[Symbol.asyncIterator] = streamAsyncIterator.bind(webStream);\n }\n\n if (!webStream.values) {\n webStream.values = streamAsyncIterator.bind(webStream);\n }\n}\n\nfunction ensureNodeStream(\n stream: ReadableStream<Uint8Array> | NodeJS.ReadableStream,\n): NodeJS.ReadableStream {\n if (stream instanceof ReadableStream) {\n makeAsyncIterable<Uint8Array>(stream);\n return Readable.fromWeb(stream);\n } else {\n return stream;\n }\n}\n\nfunction toStream(\n source: ReadableStream<Uint8Array> | NodeJS.ReadableStream | Uint8Array | Blob,\n): NodeJS.ReadableStream {\n if (source instanceof Uint8Array) {\n return Readable.from(Buffer.from(source));\n } else if (isBlob(source)) {\n return toStream(getRawContent(source));\n } else {\n return ensureNodeStream(source);\n }\n}\n\n/**\n * Accepted binary data types for concat\n *\n * @internal\n */\nexport type ConcatSource = ReadableStream<Uint8Array> | NodeJS.ReadableStream | Uint8Array | Blob;\n\n/**\n * Utility function that concatenates a set of binary inputs into one combined output.\n *\n * @param sources - array of sources for the concatenation\n * @returns - in Node, a (() =\\> NodeJS.ReadableStream) which, when read, produces a concatenation of all the inputs.\n * In browser, returns a `Blob` representing all the concatenated inputs.\n *\n * @internal\n */\nexport async function concat(\n sources: (ConcatSource | (() => ConcatSource))[],\n): Promise<(() => NodeJS.ReadableStream) | Blob> {\n return function () {\n const streams = sources.map((x) => (typeof x === \"function\" ? x() : x)).map(toStream);\n\n return Readable.from(\n (async function* () {\n for (const stream of streams as NodeJS.ReadableStream[]) {\n for await (const chunk of stream) {\n yield chunk;\n }\n }\n })(),\n );\n };\n}\n"]}
|
package/dist/esm/util/file.d.ts
CHANGED
|
@@ -29,6 +29,14 @@ export interface CreateFileFromStreamOptions extends CreateFileOptions {
|
|
|
29
29
|
*/
|
|
30
30
|
size?: number;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Extract the raw content from a given blob-like object. If the input was created using createFile
|
|
34
|
+
* or createFileFromStream, the exact content passed into createFile/createFileFromStream will be used.
|
|
35
|
+
* For true instances of Blob and File, returns the blob's content as a Web ReadableStream<Uint8Array>.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export declare function getRawContent(blob: Blob): NodeJS.ReadableStream | ReadableStream<Uint8Array> | Uint8Array;
|
|
32
40
|
/**
|
|
33
41
|
* Create an object that implements the File interface. This object is intended to be
|
|
34
42
|
* passed into RequestBodyType.formData, and is not guaranteed to work as expected in
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../src/util/file.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../src/util/file.ts"],"names":[],"mappings":";AAMA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,2BAA4B,SAAQ,iBAAiB;IACpE;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAyCD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,IAAI,GACT,MAAM,CAAC,cAAc,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,CAMjE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,cAAc,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,cAAc,EAChE,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,2BAAgC,GACxC,IAAI,CAoBN;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,iBAAsB,GAC9B,IAAI,CAgBN"}
|
package/dist/esm/util/file.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
|
-
import {
|
|
3
|
+
import { isNode } from "./checkEnvironment.js";
|
|
4
|
+
import { isNodeReadableStream } from "./typeGuards.js";
|
|
4
5
|
const unimplementedMethods = {
|
|
5
6
|
arrayBuffer: () => {
|
|
6
7
|
throw new Error("Not implemented");
|
|
@@ -12,6 +13,39 @@ const unimplementedMethods = {
|
|
|
12
13
|
throw new Error("Not implemented");
|
|
13
14
|
},
|
|
14
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Private symbol used as key on objects created using createFile containing the
|
|
18
|
+
* original source of the file object.
|
|
19
|
+
*
|
|
20
|
+
* This is used in Node to access the original Node stream without using Blob#stream, which
|
|
21
|
+
* returns a web stream. This is done to avoid a couple of bugs to do with Blob#stream and
|
|
22
|
+
* Readable#to/fromWeb in Node versions we support:
|
|
23
|
+
* - https://github.com/nodejs/node/issues/42694 (fixed in Node 18.14)
|
|
24
|
+
* - https://github.com/nodejs/node/issues/48916 (fixed in Node 20.6)
|
|
25
|
+
*
|
|
26
|
+
* Once these versions are no longer supported, we may be able to stop doing this.
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
const rawContent = Symbol("rawContent");
|
|
31
|
+
function hasRawContent(x) {
|
|
32
|
+
return typeof x[rawContent] === "function";
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Extract the raw content from a given blob-like object. If the input was created using createFile
|
|
36
|
+
* or createFileFromStream, the exact content passed into createFile/createFileFromStream will be used.
|
|
37
|
+
* For true instances of Blob and File, returns the blob's content as a Web ReadableStream<Uint8Array>.
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export function getRawContent(blob) {
|
|
42
|
+
if (hasRawContent(blob)) {
|
|
43
|
+
return blob[rawContent]();
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return blob.stream();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
15
49
|
/**
|
|
16
50
|
* Create an object that implements the File interface. This object is intended to be
|
|
17
51
|
* passed into RequestBodyType.formData, and is not guaranteed to work as expected in
|
|
@@ -37,7 +71,14 @@ export function createFileFromStream(stream, name, options = {}) {
|
|
|
37
71
|
webkitRelativePath: options.webkitRelativePath ?? "",
|
|
38
72
|
size: options.size ?? -1,
|
|
39
73
|
name,
|
|
40
|
-
stream: () =>
|
|
74
|
+
stream: () => {
|
|
75
|
+
const s = stream();
|
|
76
|
+
if (isNodeReadableStream(s)) {
|
|
77
|
+
throw new Error("Not supported: a Node stream was provided as input to createFileFromStream.");
|
|
78
|
+
}
|
|
79
|
+
return s;
|
|
80
|
+
},
|
|
81
|
+
[rawContent]: stream,
|
|
41
82
|
};
|
|
42
83
|
}
|
|
43
84
|
/**
|
|
@@ -52,15 +93,21 @@ export function createFileFromStream(stream, name, options = {}) {
|
|
|
52
93
|
* @param options - optional metadata about the file, e.g. file name, file size, MIME type.
|
|
53
94
|
*/
|
|
54
95
|
export function createFile(content, name, options = {}) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
96
|
+
if (isNode) {
|
|
97
|
+
return {
|
|
98
|
+
...unimplementedMethods,
|
|
99
|
+
type: options.type ?? "",
|
|
100
|
+
lastModified: options.lastModified ?? new Date().getTime(),
|
|
101
|
+
webkitRelativePath: options.webkitRelativePath ?? "",
|
|
102
|
+
size: content.byteLength,
|
|
103
|
+
name,
|
|
104
|
+
arrayBuffer: async () => content.buffer,
|
|
105
|
+
stream: () => new Blob([content]).stream(),
|
|
106
|
+
[rawContent]: () => content,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
return new File([content], name, options);
|
|
111
|
+
}
|
|
65
112
|
}
|
|
66
113
|
//# sourceMappingURL=file.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/util/file.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/util/file.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,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,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;QACL,GAAG,oBAAoB;QACvB,IAAI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AC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { isNode } 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 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 (isNode) {\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"]}
|
|
@@ -7,4 +7,10 @@ export interface KeyCredential {
|
|
|
7
7
|
*/
|
|
8
8
|
readonly key: string;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Tests an object to determine whether it implements KeyCredential.
|
|
12
|
+
*
|
|
13
|
+
* @param credential - The assumed KeyCredential to be tested.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isKeyCredential(credential: unknown): credential is KeyCredential;
|
|
10
16
|
//# sourceMappingURL=keyCredential.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyCredential.d.ts","sourceRoot":"","sources":["../../../src/auth/keyCredential.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"keyCredential.d.ts","sourceRoot":"","sources":["../../../src/auth/keyCredential.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,IAAI,aAAa,CAEhF"}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
|
-
|
|
3
|
+
import { isObjectWithProperties } from "../util/typeGuards.js";
|
|
4
|
+
/**
|
|
5
|
+
* Tests an object to determine whether it implements KeyCredential.
|
|
6
|
+
*
|
|
7
|
+
* @param credential - The assumed KeyCredential to be tested.
|
|
8
|
+
*/
|
|
9
|
+
export function isKeyCredential(credential) {
|
|
10
|
+
return isObjectWithProperties(credential, ["key"]) && typeof credential.key === "string";
|
|
11
|
+
}
|
|
4
12
|
//# sourceMappingURL=keyCredential.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyCredential.js","sourceRoot":"","sources":["../../../src/auth/keyCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * Represents a credential defined by a static API key.\n */\nexport interface KeyCredential {\n /**\n * The value of the API key represented as a string\n */\n readonly key: string;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"keyCredential.js","sourceRoot":"","sources":["../../../src/auth/keyCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAY/D;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,UAAmB;IACjD,OAAO,sBAAsB,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,OAAO,UAAU,CAAC,GAAG,KAAK,QAAQ,CAAC;AAC3F,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { isObjectWithProperties } from \"../util/typeGuards.js\";\n\n/**\n * Represents a credential defined by a static API key.\n */\nexport interface KeyCredential {\n /**\n * The value of the API key represented as a string\n */\n readonly key: string;\n}\n\n/**\n * Tests an object to determine whether it implements KeyCredential.\n *\n * @param credential - The assumed KeyCredential to be tested.\n */\nexport function isKeyCredential(credential: unknown): credential is KeyCredential {\n return isObjectWithProperties(credential, [\"key\"]) && typeof credential.key === \"string\";\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientHelpers.d.ts","sourceRoot":"","sources":["../../../src/client/clientHelpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI1C,OAAO,EAAE,eAAe,EAAqB,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"clientHelpers.d.ts","sourceRoot":"","sources":["../../../src/client/clientHelpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI1C,OAAO,EAAE,eAAe,EAAqB,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAE,aAAa,EAAmB,MAAM,0BAA0B,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAM5C;;GAEG;AACH,MAAM,WAAW,kCAAkC;IACjD;;OAEG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B;;OAEG;IACH,UAAU,CAAC,EAAE,eAAe,GAAG,aAAa,CAAC;CAC9C;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,kCAAuC,GAC/C,IAAI,CAsBN;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,eAAe,GAAG,aAAa,EAC5C,OAAO,GAAE,aAAkB,GAC1B,QAAQ,CAOV;AAED,wBAAgB,2BAA2B,IAAI,UAAU,CAMxD"}
|
|
@@ -4,6 +4,7 @@ import { bearerTokenAuthenticationPolicy } from "../policies/bearerTokenAuthenti
|
|
|
4
4
|
import { createDefaultHttpClient } from "../defaultHttpClient.js";
|
|
5
5
|
import { createPipelineFromOptions } from "../createPipelineFromOptions.js";
|
|
6
6
|
import { isTokenCredential } from "../auth/tokenCredential.js";
|
|
7
|
+
import { isKeyCredential } from "../auth/keyCredential.js";
|
|
7
8
|
import { apiVersionPolicy } from "./apiVersionPolicy.js";
|
|
8
9
|
import { keyCredentialAuthenticationPolicy } from "./keyCredentialAuthenticationPolicy.js";
|
|
9
10
|
let cachedHttpClient;
|
|
@@ -39,9 +40,6 @@ export function createDefaultPipeline(baseUrl, credential, options = {}) {
|
|
|
39
40
|
addCredentialPipelinePolicy(pipeline, baseUrl, { credential, clientOptions: options });
|
|
40
41
|
return pipeline;
|
|
41
42
|
}
|
|
42
|
-
function isKeyCredential(credential) {
|
|
43
|
-
return credential.key !== undefined;
|
|
44
|
-
}
|
|
45
43
|
export function getCachedDefaultHttpsClient() {
|
|
46
44
|
if (!cachedHttpClient) {
|
|
47
45
|
cachedHttpClient = createDefaultHttpClient();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientHelpers.js","sourceRoot":"","sources":["../../../src/client/clientHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,+BAA+B,EAAE,MAAM,gDAAgD,CAAC;AACjG,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAmB,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"clientHelpers.js","sourceRoot":"","sources":["../../../src/client/clientHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,+BAA+B,EAAE,MAAM,gDAAgD,CAAC;AACjG,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAmB,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAiB,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAE3F,IAAI,gBAAwC,CAAC;AAgB7C;;GAEG;AACH,MAAM,UAAU,2BAA2B,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BAAgB,CAAC;AAC1B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { HttpClient } from \"../interfaces.js\";\nimport { Pipeline } from \"../pipeline.js\";\nimport { bearerTokenAuthenticationPolicy } from \"../policies/bearerTokenAuthenticationPolicy.js\";\nimport { createDefaultHttpClient } from \"../defaultHttpClient.js\";\nimport { createPipelineFromOptions } from \"../createPipelineFromOptions.js\";\nimport { TokenCredential, isTokenCredential } from \"../auth/tokenCredential.js\";\nimport { KeyCredential, isKeyCredential } from \"../auth/keyCredential.js\";\nimport { ClientOptions } from \"./common.js\";\nimport { apiVersionPolicy } from \"./apiVersionPolicy.js\";\nimport { keyCredentialAuthenticationPolicy } from \"./keyCredentialAuthenticationPolicy.js\";\n\nlet cachedHttpClient: HttpClient | undefined;\n\n/**\n * Optional parameters for adding a credential policy to the pipeline.\n */\nexport interface AddCredentialPipelinePolicyOptions {\n /**\n * Options related to the client.\n */\n clientOptions?: ClientOptions;\n /**\n * The credential to use.\n */\n credential?: TokenCredential | KeyCredential;\n}\n\n/**\n * Adds a credential policy to the pipeline if a credential is provided. If none is provided, no policy is added.\n */\nexport function addCredentialPipelinePolicy(\n pipeline: Pipeline,\n baseUrl: string,\n options: AddCredentialPipelinePolicyOptions = {},\n): void {\n const { credential, clientOptions } = options;\n if (!credential) {\n return;\n }\n\n if (isTokenCredential(credential)) {\n const tokenPolicy = bearerTokenAuthenticationPolicy({\n credential,\n scopes: clientOptions?.credentials?.scopes ?? `${baseUrl}/.default`,\n });\n pipeline.addPolicy(tokenPolicy);\n } else if (isKeyCredential(credential)) {\n if (!clientOptions?.credentials?.apiKeyHeaderName) {\n throw new Error(`Missing API Key Header Name`);\n }\n const keyPolicy = keyCredentialAuthenticationPolicy(\n credential,\n clientOptions?.credentials?.apiKeyHeaderName,\n );\n pipeline.addPolicy(keyPolicy);\n }\n}\n\n/**\n * Creates a default rest pipeline to re-use accross Rest Level Clients\n */\nexport function createDefaultPipeline(\n baseUrl: string,\n credential?: TokenCredential | KeyCredential,\n options: ClientOptions = {},\n): Pipeline {\n const pipeline = createPipelineFromOptions(options);\n\n pipeline.addPolicy(apiVersionPolicy(options));\n\n addCredentialPipelinePolicy(pipeline, baseUrl, { credential, clientOptions: options });\n return pipeline;\n}\n\nexport function getCachedDefaultHttpsClient(): HttpClient {\n if (!cachedHttpClient) {\n cachedHttpClient = createDefaultHttpClient();\n }\n\n return cachedHttpClient;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getClient.d.ts","sourceRoot":"","sources":["../../../src/client/getClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAqB,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"getClient.d.ts","sourceRoot":"","sources":["../../../src/client/getClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAqB,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAE,aAAa,EAAmB,MAAM,0BAA0B,CAAC;AAI1E,OAAO,EACL,MAAM,EACN,aAAa,EAKd,MAAM,aAAa,CAAC;AAKrB;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC;AAC5E;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,eAAe,GAAG,aAAa,EAC7C,OAAO,CAAC,EAAE,aAAa,GACtB,MAAM,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT license.
|
|
3
3
|
import { isTokenCredential } from "../auth/tokenCredential.js";
|
|
4
|
+
import { isKeyCredential } from "../auth/keyCredential.js";
|
|
4
5
|
import { createDefaultPipeline } from "./clientHelpers.js";
|
|
5
|
-
import { sendRequest
|
|
6
|
+
import { sendRequest } from "./sendRequest.js";
|
|
6
7
|
import { buildRequestUrl } from "./urlHelpers.js";
|
|
7
8
|
export function getClient(baseUrl, credentialsOrPipelineOptions, clientOptions = {}) {
|
|
8
9
|
let credentials;
|
|
@@ -68,17 +69,14 @@ function buildOperation(method, url, pipeline, options, allowInsecureConnection,
|
|
|
68
69
|
return sendRequest(method, url, pipeline, { ...options, allowInsecureConnection }, httpClient).then(onFulfilled, onrejected);
|
|
69
70
|
},
|
|
70
71
|
async asBrowserStream() {
|
|
71
|
-
return
|
|
72
|
+
return sendRequest(method, url, pipeline, { ...options, allowInsecureConnection, responseAsStream: true }, httpClient);
|
|
72
73
|
},
|
|
73
74
|
async asNodeStream() {
|
|
74
|
-
return
|
|
75
|
+
return sendRequest(method, url, pipeline, { ...options, allowInsecureConnection, responseAsStream: true }, httpClient);
|
|
75
76
|
},
|
|
76
77
|
};
|
|
77
78
|
}
|
|
78
79
|
function isCredential(param) {
|
|
79
|
-
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
return false;
|
|
80
|
+
return isKeyCredential(param) || isTokenCredential(param);
|
|
83
81
|
}
|
|
84
82
|
//# sourceMappingURL=getClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getClient.js","sourceRoot":"","sources":["../../../src/client/getClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAmB,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"getClient.js","sourceRoot":"","sources":["../../../src/client/getClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAmB,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAiB,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAG1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAS3D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,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c,CACnB,OAAO,EACP,MAAM,CAAC,cAAc,CAAC,EACtB,QAAQ,EACR,cAAc,EACd,uBAAuB,EACvB,UAAU,CACX,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,aAAa,EAAE,MAAM;QACrB,QAAQ;KACT,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CACrB,MAAmB,EACnB,GAAW,EACX,QAAkB,EAClB,OAA0B,EAC1B,uBAAiC,EACjC,UAAuB;IAEvB,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,IAAI,uBAAuB,CAAC;IACrF,OAAO;QACL,IAAI,EAAE,UAAU,WAAW,EAAE,UAAU;YACrC,OAAO,WAAW,CAChB,MAAM,EACN,GAAG,EACH,QAAQ,EACR,EAAE,GAAG,OAAO,EAAE,uBAAuB,EAAE,EACvC,UAAU,CACX,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QAClC,CAAC;QACD,KAAK,CAAC,eAAe;YACnB,OAAO,WAAW,CAChB,MAAM,EACN,GAAG,EACH,QAAQ,EACR,EAAE,GAAG,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,IAAI,EAAE,EAC/D,UAAU,CAC2B,CAAC;QAC1C,CAAC;QACD,KAAK,CAAC,YAAY;YAChB,OAAO,WAAW,CAChB,MAAM,EACN,GAAG,EACH,QAAQ,EACR,EAAE,GAAG,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,IAAI,EAAE,EAC/D,UAAU,CACwB,CAAC;QACvC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,KAA0D;IAE1D,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { TokenCredential, isTokenCredential } from \"../auth/tokenCredential.js\";\nimport { KeyCredential, isKeyCredential } from \"../auth/keyCredential.js\";\nimport { HttpClient, HttpMethods } from \"../interfaces.js\";\nimport { Pipeline } from \"../pipeline.js\";\nimport { createDefaultPipeline } from \"./clientHelpers.js\";\nimport {\n Client,\n ClientOptions,\n HttpBrowserStreamResponse,\n HttpNodeStreamResponse,\n RequestParameters,\n StreamableMethod,\n} from \"./common.js\";\nimport { sendRequest } from \"./sendRequest.js\";\nimport { buildRequestUrl } from \"./urlHelpers.js\";\nimport { PipelineOptions } from \"../createPipelineFromOptions.js\";\n\n/**\n * Creates a client with a default pipeline\n * @param baseUrl - Base endpoint for the client\n * @param options - Client options\n */\nexport function getClient(baseUrl: string, options?: ClientOptions): Client;\n/**\n * Creates a client with a default pipeline\n * @param baseUrl - Base endpoint for the client\n * @param credentials - Credentials to authenticate the requests\n * @param options - Client options\n */\nexport function getClient(\n baseUrl: string,\n credentials?: TokenCredential | KeyCredential,\n options?: ClientOptions,\n): Client;\nexport function getClient(\n baseUrl: string,\n credentialsOrPipelineOptions?: (TokenCredential | KeyCredential) | ClientOptions,\n clientOptions: ClientOptions = {},\n): Client {\n let credentials: TokenCredential | KeyCredential | undefined;\n if (credentialsOrPipelineOptions) {\n if (isCredential(credentialsOrPipelineOptions)) {\n credentials = credentialsOrPipelineOptions;\n } else {\n clientOptions = credentialsOrPipelineOptions ?? {};\n }\n }\n\n const pipeline = createDefaultPipeline(baseUrl, credentials, clientOptions);\n if (clientOptions.additionalPolicies?.length) {\n for (const { policy, position } of clientOptions.additionalPolicies) {\n // Sign happens after Retry and is commonly needed to occur\n // before policies that intercept post-retry.\n const afterPhase = position === \"perRetry\" ? \"Sign\" : undefined;\n pipeline.addPolicy(policy, {\n afterPhase,\n });\n }\n }\n\n const { allowInsecureConnection, httpClient } = clientOptions;\n const client = (path: string, ...args: Array<any>) => {\n const getUrl = (requestOptions: RequestParameters): string =>\n buildRequestUrl(baseUrl, path, args, { allowInsecureConnection, ...requestOptions });\n\n return {\n get: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"GET\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n post: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"POST\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n put: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"PUT\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n patch: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"PATCH\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n delete: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"DELETE\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n head: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"HEAD\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n options: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"OPTIONS\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n trace: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"TRACE\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n };\n };\n\n return {\n path: client,\n pathUnchecked: client,\n pipeline,\n };\n}\n\nfunction buildOperation(\n method: HttpMethods,\n url: string,\n pipeline: Pipeline,\n options: RequestParameters,\n allowInsecureConnection?: boolean,\n httpClient?: HttpClient,\n): StreamableMethod {\n allowInsecureConnection = options.allowInsecureConnection ?? allowInsecureConnection;\n return {\n then: function (onFulfilled, onrejected) {\n return sendRequest(\n method,\n url,\n pipeline,\n { ...options, allowInsecureConnection },\n httpClient,\n ).then(onFulfilled, onrejected);\n },\n async asBrowserStream() {\n return sendRequest(\n method,\n url,\n pipeline,\n { ...options, allowInsecureConnection, responseAsStream: true },\n httpClient,\n ) as Promise<HttpBrowserStreamResponse>;\n },\n async asNodeStream() {\n return sendRequest(\n method,\n url,\n pipeline,\n { ...options, allowInsecureConnection, responseAsStream: true },\n httpClient,\n ) as Promise<HttpNodeStreamResponse>;\n },\n };\n}\n\nfunction isCredential(\n param: (TokenCredential | KeyCredential) | PipelineOptions,\n): param is TokenCredential | KeyCredential {\n return isKeyCredential(param) || isTokenCredential(param);\n}\n"]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import { HttpClient, HttpMethods } from "../interfaces.js";
|
|
3
2
|
import { Pipeline } from "../pipeline.js";
|
|
4
3
|
import { HttpResponse, RequestParameters } from "./common.js";
|
|
@@ -11,19 +10,7 @@ import { HttpResponse, RequestParameters } from "./common.js";
|
|
|
11
10
|
* @param customHttpClient - a custom HttpClient to use when making the request
|
|
12
11
|
* @returns returns and HttpResponse
|
|
13
12
|
*/
|
|
14
|
-
export declare function sendRequest(method: HttpMethods, url: string, pipeline: Pipeline, options?:
|
|
15
|
-
/**
|
|
16
|
-
* Helper function to send request used by the client
|
|
17
|
-
* @param method - method to use to send the request
|
|
18
|
-
* @param url - url to send the request to
|
|
19
|
-
* @param pipeline - pipeline with the policies to run when sending the request
|
|
20
|
-
* @param options - request options
|
|
21
|
-
* @param customHttpClient - a custom HttpClient to use when making the request
|
|
22
|
-
* @returns returns and HttpResponse
|
|
23
|
-
*/
|
|
24
|
-
export declare function sendRequestAsStream<TResponse extends HttpResponse & {
|
|
25
|
-
body: NodeJS.ReadableStream | ReadableStream<Uint8Array> | undefined;
|
|
26
|
-
}>(method: HttpMethods, url: string, pipeline: Pipeline, options?: RequestParameters, customHttpClient?: HttpClient): Promise<TResponse>;
|
|
13
|
+
export declare function sendRequest(method: HttpMethods, url: string, pipeline: Pipeline, options?: InternalRequestParameters, customHttpClient?: HttpClient): Promise<HttpResponse>;
|
|
27
14
|
export interface InternalRequestParameters extends RequestParameters {
|
|
28
15
|
responseAsStream?: boolean;
|
|
29
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendRequest.d.ts","sourceRoot":"","sources":["../../../src/client/sendRequest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sendRequest.d.ts","sourceRoot":"","sources":["../../../src/client/sendRequest.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,UAAU,EACV,WAAW,EAIZ,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAK1C,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAG9D;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,WAAW,EACnB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE,yBAA8B,EACvC,gBAAgB,CAAC,EAAE,UAAU,GAC5B,OAAO,CAAC,YAAY,CAAC,CAoBvB;AAuCD,MAAM,WAAW,yBAA0B,SAAQ,iBAAiB;IAClE,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B"}
|
|
@@ -5,7 +5,7 @@ import { createHttpHeaders } from "../httpHeaders.js";
|
|
|
5
5
|
import { createPipelineRequest } from "../pipelineRequest.js";
|
|
6
6
|
import { getCachedDefaultHttpsClient } from "./clientHelpers.js";
|
|
7
7
|
import { isReadableStream } from "../util/typeGuards.js";
|
|
8
|
-
import {
|
|
8
|
+
import { createFile } from "../util/file.js";
|
|
9
9
|
/**
|
|
10
10
|
* Helper function to send request used by the client
|
|
11
11
|
* @param method - method to use to send the request
|
|
@@ -19,39 +19,29 @@ export async function sendRequest(method, url, pipeline, options = {}, customHtt
|
|
|
19
19
|
const httpClient = customHttpClient ?? getCachedDefaultHttpsClient();
|
|
20
20
|
const request = buildPipelineRequest(method, url, options);
|
|
21
21
|
const response = await pipeline.sendRequest(httpClient, request);
|
|
22
|
-
const
|
|
23
|
-
const
|
|
22
|
+
const headers = response.headers.toJSON();
|
|
23
|
+
const stream = response.readableStreamBody ?? response.browserStreamBody;
|
|
24
|
+
const parsedBody = options.responseAsStream || stream !== undefined ? undefined : getResponseBody(response);
|
|
25
|
+
const body = stream ?? parsedBody;
|
|
24
26
|
if (options?.onResponse) {
|
|
25
|
-
options.onResponse({ ...response, request, rawHeaders, parsedBody });
|
|
27
|
+
options.onResponse({ ...response, request, rawHeaders: headers, parsedBody });
|
|
26
28
|
}
|
|
27
29
|
return {
|
|
28
30
|
request,
|
|
29
|
-
headers
|
|
31
|
+
headers,
|
|
30
32
|
status: `${response.status}`,
|
|
31
|
-
body
|
|
33
|
+
body,
|
|
32
34
|
};
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
35
|
-
*
|
|
36
|
-
* @param
|
|
37
|
-
* @
|
|
38
|
-
* @param pipeline - pipeline with the policies to run when sending the request
|
|
39
|
-
* @param options - request options
|
|
40
|
-
* @param customHttpClient - a custom HttpClient to use when making the request
|
|
41
|
-
* @returns returns and HttpResponse
|
|
37
|
+
* Function to determine the request content type
|
|
38
|
+
* @param options - request options InternalRequestParameters
|
|
39
|
+
* @returns returns the content-type
|
|
42
40
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const rawHeaders = response.headers.toJSON();
|
|
48
|
-
const parsedBody = response.browserStreamBody ?? response.readableStreamBody;
|
|
49
|
-
return {
|
|
50
|
-
request,
|
|
51
|
-
headers: rawHeaders,
|
|
52
|
-
status: `${response.status}`,
|
|
53
|
-
body: parsedBody,
|
|
54
|
-
};
|
|
41
|
+
function getRequestContentType(options = {}) {
|
|
42
|
+
return (options.contentType ??
|
|
43
|
+
options.headers?.["content-type"] ??
|
|
44
|
+
getContentType(options.body));
|
|
55
45
|
}
|
|
56
46
|
/**
|
|
57
47
|
* Function to determine the content-type of a body
|
|
@@ -63,17 +53,29 @@ function getContentType(body) {
|
|
|
63
53
|
if (ArrayBuffer.isView(body)) {
|
|
64
54
|
return "application/octet-stream";
|
|
65
55
|
}
|
|
56
|
+
if (typeof body === "string") {
|
|
57
|
+
try {
|
|
58
|
+
JSON.parse(body);
|
|
59
|
+
return "application/json; charset=UTF-8";
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
// If we fail to parse the body, it is not json
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
66
|
// By default return json
|
|
67
67
|
return "application/json; charset=UTF-8";
|
|
68
68
|
}
|
|
69
69
|
function buildPipelineRequest(method, url, options = {}) {
|
|
70
|
-
const
|
|
70
|
+
const requestContentType = getRequestContentType(options);
|
|
71
|
+
const { body, formData } = getRequestBody(options.body, requestContentType);
|
|
71
72
|
const hasContent = body !== undefined || formData !== undefined;
|
|
72
73
|
const headers = createHttpHeaders({
|
|
73
74
|
...(options.headers ? options.headers : {}),
|
|
74
75
|
accept: options.accept ?? "application/json",
|
|
75
|
-
...(hasContent &&
|
|
76
|
-
|
|
76
|
+
...(hasContent &&
|
|
77
|
+
requestContentType && {
|
|
78
|
+
"content-type": requestContentType,
|
|
77
79
|
}),
|
|
78
80
|
});
|
|
79
81
|
return createPipelineRequest({
|
|
@@ -104,24 +106,16 @@ function getRequestBody(body, contentType = "") {
|
|
|
104
106
|
if (isReadableStream(body)) {
|
|
105
107
|
return { body };
|
|
106
108
|
}
|
|
107
|
-
if (!contentType && typeof body === "string") {
|
|
108
|
-
return { body };
|
|
109
|
-
}
|
|
110
109
|
const firstType = contentType.split(";")[0];
|
|
111
110
|
if (firstType === "application/json") {
|
|
112
111
|
return { body: JSON.stringify(body) };
|
|
113
112
|
}
|
|
114
113
|
if (ArrayBuffer.isView(body)) {
|
|
115
|
-
|
|
116
|
-
return { body: binaryArrayToString(body) };
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
return { body: JSON.stringify(body) };
|
|
120
|
-
}
|
|
114
|
+
return { body: body instanceof Uint8Array ? body : JSON.stringify(body) };
|
|
121
115
|
}
|
|
122
116
|
switch (firstType) {
|
|
123
117
|
case "multipart/form-data":
|
|
124
|
-
return
|
|
118
|
+
return isRLCFormDataInput(body)
|
|
125
119
|
? { formData: processFormData(body) }
|
|
126
120
|
: { body: JSON.stringify(body) };
|
|
127
121
|
case "text/plain":
|
|
@@ -133,26 +127,31 @@ function getRequestBody(body, contentType = "") {
|
|
|
133
127
|
return { body: JSON.stringify(body) };
|
|
134
128
|
}
|
|
135
129
|
}
|
|
136
|
-
function
|
|
137
|
-
return
|
|
130
|
+
function isRLCFormDataValue(value) {
|
|
131
|
+
return (typeof value === "string" ||
|
|
132
|
+
value instanceof Uint8Array ||
|
|
133
|
+
// We don't do `instanceof Blob` since we should also accept polyfills of e.g. File in Node.
|
|
134
|
+
typeof value.stream === "function");
|
|
135
|
+
}
|
|
136
|
+
function isRLCFormDataInput(body) {
|
|
137
|
+
return (body !== undefined &&
|
|
138
|
+
body instanceof Object &&
|
|
139
|
+
Object.values(body).every((value) => isRLCFormDataValue(value) || (Array.isArray(value) && value.every(isRLCFormDataValue))));
|
|
140
|
+
}
|
|
141
|
+
function processFormDataValue(value) {
|
|
142
|
+
return value instanceof Uint8Array ? createFile(value, "blob") : value;
|
|
138
143
|
}
|
|
139
144
|
/**
|
|
140
|
-
* Checks if binary data is in Uint8Array format, if so
|
|
145
|
+
* Checks if binary data is in Uint8Array format, if so wrap it in a Blob
|
|
141
146
|
* to send over the wire
|
|
142
147
|
*/
|
|
143
148
|
function processFormData(formData) {
|
|
144
|
-
if (!formData) {
|
|
145
|
-
return formData;
|
|
146
|
-
}
|
|
147
149
|
const processedFormData = {};
|
|
148
150
|
for (const element in formData) {
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
else {
|
|
154
|
-
processedFormData[element] = item;
|
|
155
|
-
}
|
|
151
|
+
const value = formData[element];
|
|
152
|
+
processedFormData[element] = Array.isArray(value)
|
|
153
|
+
? value.map(processFormDataValue)
|
|
154
|
+
: processFormDataValue(value);
|
|
156
155
|
}
|
|
157
156
|
return processedFormData;
|
|
158
157
|
}
|