@typespec/ts-http-runtime 1.0.0-alpha.20240223.2 → 1.0.0-alpha.20240226.9
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/ts-http-runtime.d.ts +7 -0
- package/package.json +3 -2
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formDataPolicy.js","sourceRoot":"","sources":["../../../src/policies/formDataPolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,+DAA8D;AAC9D,sDAAsD;AAUtD;;GAEG;AACU,QAAA,kBAAkB,GAAG,gBAAgB,CAAC;AAEnD;;GAEG;AACH,SAAgB,cAAc;IAC5B,OAAO;QACL,IAAI,EAAE,0BAAkB;QACxB,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;gBACrB,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;gBACxD,IAAI,WAAW,IAAI,WAAW,CAAC,OAAO,CAAC,mCAAmC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;oBACnF,OAAO,CAAC,IAAI,GAAG,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBACpD,CAAC;qBAAM,CAAC;oBACN,MAAM,eAAe,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;gBACnD,CAAC;gBAED,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;YAC/B,CAAC;YACD,OA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\n\nimport { stringToUint8Array } from \"../util/bytesEncoding.js\";\nimport { createHttpHeaders } from \"../httpHeaders.js\";\nimport {\n BodyPart,\n FormDataMap,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n} from \"../interfaces.js\";\nimport { PipelinePolicy } from \"../pipeline.js\";\n\n/**\n * The programmatic identifier of the formDataPolicy.\n */\nexport const formDataPolicyName = \"formDataPolicy\";\n\n/**\n * A policy that encodes FormData on the request into the body.\n */\nexport function formDataPolicy(): PipelinePolicy {\n return {\n name: formDataPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n if (request.formData) {\n const contentType = request.headers.get(\"Content-Type\");\n if (contentType && contentType.indexOf(\"application/x-www-form-urlencoded\") !== -1) {\n request.body = wwwFormUrlEncode(request.formData);\n } else {\n await prepareFormData(request.formData, request);\n }\n\n request.formData = undefined;\n }\n return next(request);\n },\n };\n}\n\nfunction wwwFormUrlEncode(formData: FormDataMap): string {\n const urlSearchParams = new URLSearchParams();\n for (const [key, value] of Object.entries(formData)) {\n if (Array.isArray(value)) {\n for (const subValue of value) {\n urlSearchParams.append(key, subValue.toString());\n }\n } else {\n urlSearchParams.append(key, value.toString());\n }\n }\n return urlSearchParams.toString();\n}\n\nasync function prepareFormData(formData: FormDataMap, request: PipelineRequest): Promise<void> {\n // validate content type (multipart/form-data)\n const contentType = request.headers.get(\"Content-Type\");\n if (contentType && !contentType.startsWith(\"multipart/form-data\")) {\n // content type is specified and is not multipart/form-data. Exit.\n return;\n }\n\n request.headers.set(\"Content-Type\", contentType ?? \"multipart/form-data\");\n\n // set body to MultipartRequestBody using content from FormDataMap\n const parts: BodyPart[] = [];\n\n for (const [fieldName, values] of Object.entries(formData)) {\n for (const value of Array.isArray(values) ? values : [values]) {\n if (typeof value === \"string\") {\n parts.push({\n headers: createHttpHeaders({\n \"Content-Disposition\": `form-data; name=\"${fieldName}\"`,\n }),\n body: stringToUint8Array(value, \"utf-8\"),\n });\n } else if (value === undefined || value === null || typeof value !== \"object\") {\n throw new Error(\n `Unexpected value for key ${fieldName}: ${value}. Value should be serialized to string first.`,\n );\n } else {\n // using || instead of ?? here since if value.name is empty we should create a file name\n const fileName = (value as File).name || \"blob\";\n const headers = createHttpHeaders();\n headers.set(\n \"Content-Disposition\",\n `form-data; name=\"${fieldName}\"; filename=\"${fileName}\"`,\n );\n // again, || is used since an empty value.type means the content type is unset\n headers.set(\"Content-Type\", value.type || \"application/octet-stream\");\n\n parts.push({\n headers,\n body: value,\n });\n }\n }\n }\n\n request.multipartBody = { parts };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multipartPolicy.d.ts","sourceRoot":"","sources":["../../../src/policies/multipartPolicy.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"multipartPolicy.d.ts","sourceRoot":"","sources":["../../../src/policies/multipartPolicy.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAoFhD;;GAEG;AACH,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAiBrD;;GAEG;AACH,wBAAgB,eAAe,IAAI,cAAc,CA2ChD"}
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.multipartPolicy = exports.multipartPolicyName = void 0;
|
|
6
6
|
const bytesEncoding_js_1 = require("../util/bytesEncoding.js");
|
|
7
|
-
const stream_js_1 = require("../util/stream.js");
|
|
8
7
|
const typeGuards_js_1 = require("../util/typeGuards.js");
|
|
9
8
|
const uuidUtils_js_1 = require("../util/uuidUtils.js");
|
|
9
|
+
const concat_js_1 = require("../util/concat.js");
|
|
10
10
|
function generateBoundary() {
|
|
11
11
|
return `----AzSDKFormBoundary${(0, uuidUtils_js_1.randomUUID)()}`;
|
|
12
12
|
}
|
|
@@ -42,7 +42,7 @@ function getTotalLength(sources) {
|
|
|
42
42
|
}
|
|
43
43
|
return total;
|
|
44
44
|
}
|
|
45
|
-
function buildRequestBody(request, parts, boundary) {
|
|
45
|
+
async function buildRequestBody(request, parts, boundary) {
|
|
46
46
|
const sources = [
|
|
47
47
|
(0, bytesEncoding_js_1.stringToUint8Array)(`--${boundary}`, "utf-8"),
|
|
48
48
|
...parts.flatMap((part) => [
|
|
@@ -58,7 +58,7 @@ function buildRequestBody(request, parts, boundary) {
|
|
|
58
58
|
if (contentLength) {
|
|
59
59
|
request.headers.set("Content-Length", contentLength);
|
|
60
60
|
}
|
|
61
|
-
request.body =
|
|
61
|
+
request.body = await (0, concat_js_1.concat)(sources);
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Name of multipart policy
|
|
@@ -80,7 +80,7 @@ function assertValidBoundary(boundary) {
|
|
|
80
80
|
function multipartPolicy() {
|
|
81
81
|
return {
|
|
82
82
|
name: exports.multipartPolicyName,
|
|
83
|
-
sendRequest(request, next) {
|
|
83
|
+
async sendRequest(request, next) {
|
|
84
84
|
if (!request.multipartBody) {
|
|
85
85
|
return next(request);
|
|
86
86
|
}
|
|
@@ -105,7 +105,7 @@ function multipartPolicy() {
|
|
|
105
105
|
boundary = generateBoundary();
|
|
106
106
|
}
|
|
107
107
|
request.headers.set("Content-Type", `${contentType}; boundary=${boundary}`);
|
|
108
|
-
buildRequestBody(request, request.multipartBody.parts, boundary);
|
|
108
|
+
await buildRequestBody(request, request.multipartBody.parts, boundary);
|
|
109
109
|
request.multipartBody = undefined;
|
|
110
110
|
return next(request);
|
|
111
111
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multipartPolicy.js","sourceRoot":"","sources":["../../../src/policies/multipartPolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAIlC,+DAA8D;AAC9D,
|
|
1
|
+
{"version":3,"file":"multipartPolicy.js","sourceRoot":"","sources":["../../../src/policies/multipartPolicy.ts"],"names":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,QAAQ,EAAE,CAAC,CAAC;YAC5E,MAAM,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAEvE,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;YAElC,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AA3CD,0CA2CC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport type { BodyPart, HttpHeaders, PipelineRequest } from \"../interfaces.js\";\nimport { PipelinePolicy } from \"../pipeline.js\";\nimport { stringToUint8Array } from \"../util/bytesEncoding.js\";\nimport { isBlob } from \"../util/typeGuards.js\";\nimport { randomUUID } from \"../util/uuidUtils.js\";\nimport { concat } from \"../util/concat.js\";\n\nfunction generateBoundary(): string {\n return `----AzSDKFormBoundary${randomUUID()}`;\n}\n\nfunction encodeHeaders(headers: HttpHeaders): string {\n let result = \"\";\n for (const [key, value] of headers) {\n result += `${key}: ${value}\\r\\n`;\n }\n return result;\n}\n\nfunction getLength(\n source:\n | (() => ReadableStream<Uint8Array>)\n | (() => NodeJS.ReadableStream)\n | Uint8Array\n | Blob\n | ReadableStream\n | NodeJS.ReadableStream,\n): number | undefined {\n if (source instanceof Uint8Array) {\n return source.byteLength;\n } else if (isBlob(source)) {\n // if was created using createFile then -1 means we have an unknown size\n return source.size === -1 ? undefined : source.size;\n } else {\n return undefined;\n }\n}\n\nfunction getTotalLength(\n sources: (\n | (() => ReadableStream<Uint8Array>)\n | (() => NodeJS.ReadableStream)\n | Uint8Array\n | Blob\n | ReadableStream\n | NodeJS.ReadableStream\n )[],\n): number | undefined {\n let total = 0;\n for (const source of sources) {\n const partLength = getLength(source);\n if (partLength === undefined) {\n return undefined;\n } else {\n total += partLength;\n }\n }\n return total;\n}\n\nasync function buildRequestBody(\n request: PipelineRequest,\n parts: BodyPart[],\n boundary: string,\n): Promise<void> {\n const sources = [\n stringToUint8Array(`--${boundary}`, \"utf-8\"),\n ...parts.flatMap((part) => [\n stringToUint8Array(\"\\r\\n\", \"utf-8\"),\n stringToUint8Array(encodeHeaders(part.headers), \"utf-8\"),\n stringToUint8Array(\"\\r\\n\", \"utf-8\"),\n part.body,\n stringToUint8Array(`\\r\\n--${boundary}`, \"utf-8\"),\n ]),\n stringToUint8Array(\"--\\r\\n\\r\\n\", \"utf-8\"),\n ];\n\n const contentLength = getTotalLength(sources);\n if (contentLength) {\n request.headers.set(\"Content-Length\", contentLength);\n }\n\n request.body = await concat(sources);\n}\n\n/**\n * Name of multipart policy\n */\nexport const multipartPolicyName = \"multipartPolicy\";\n\nconst maxBoundaryLength = 70;\nconst validBoundaryCharacters = new Set(\n `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'()+,-./:=?`,\n);\n\nfunction assertValidBoundary(boundary: string): void {\n if (boundary.length > maxBoundaryLength) {\n throw new Error(`Multipart boundary \"${boundary}\" exceeds maximum length of 70 characters`);\n }\n\n if (Array.from(boundary).some((x) => !validBoundaryCharacters.has(x))) {\n throw new Error(`Multipart boundary \"${boundary}\" contains invalid characters`);\n }\n}\n\n/**\n * Pipeline policy for multipart requests\n */\nexport function multipartPolicy(): PipelinePolicy {\n return {\n name: multipartPolicyName,\n async sendRequest(request, next) {\n if (!request.multipartBody) {\n return next(request);\n }\n\n if (request.body) {\n throw new Error(\"multipartBody and regular body cannot be set at the same time\");\n }\n\n let boundary = request.multipartBody.boundary;\n\n const contentTypeHeader = request.headers.get(\"Content-Type\") ?? \"multipart/mixed\";\n const parsedHeader = contentTypeHeader.match(/^(multipart\\/[^ ;]+)(?:; *boundary=(.+))?$/);\n if (!parsedHeader) {\n throw new Error(\n `Got multipart request body, but content-type header was not multipart: ${contentTypeHeader}`,\n );\n }\n\n const [, contentType, parsedBoundary] = parsedHeader;\n if (parsedBoundary && boundary && parsedBoundary !== boundary) {\n throw new Error(\n `Multipart boundary was specified as ${parsedBoundary} in the header, but got ${boundary} in the request body`,\n );\n }\n\n boundary ??= parsedBoundary;\n if (boundary) {\n assertValidBoundary(boundary);\n } else {\n boundary = generateBoundary();\n }\n request.headers.set(\"Content-Type\", `${contentType}; boundary=${boundary}`);\n await buildRequestBody(request, request.multipartBody.parts, boundary);\n\n request.multipartBody = undefined;\n\n return next(request);\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* Accepted binary data types for concat
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export type ConcatSource = ReadableStream<Uint8Array> | NodeJS.ReadableStream | Uint8Array | Blob;
|
|
8
|
+
/**
|
|
9
|
+
* Utility function that concatenates a set of binary inputs into one combined output.
|
|
10
|
+
*
|
|
11
|
+
* @param sources - array of sources for the concatenation
|
|
12
|
+
* @returns - in Node, a (() =\> NodeJS.ReadableStream) which, when read, produces a concatenation of all the inputs.
|
|
13
|
+
* In browser, returns a `Blob` representing all the concatenated inputs.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare function concat(sources: (ConcatSource | (() => ConcatSource))[]): Promise<(() => NodeJS.ReadableStream) | Blob>;
|
|
18
|
+
//# sourceMappingURL=concat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concat.d.ts","sourceRoot":"","sources":["../../../src/util/concat.ts"],"names":[],"mappings":";AA2DA;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,cAAc,GAAG,UAAU,GAAG,IAAI,CAAC;AAElG;;;;;;;;GAQG;AACH,wBAAsB,MAAM,CAC1B,OAAO,EAAE,CAAC,YAAY,GAAG,CAAC,MAAM,YAAY,CAAC,CAAC,EAAE,GAC/C,OAAO,CAAC,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAc/C"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT license.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.concat = void 0;
|
|
6
|
+
const stream_1 = require("stream");
|
|
7
|
+
const typeGuards_js_1 = require("./typeGuards.js");
|
|
8
|
+
const file_js_1 = require("./file.js");
|
|
9
|
+
async function* streamAsyncIterator() {
|
|
10
|
+
const reader = this.getReader();
|
|
11
|
+
try {
|
|
12
|
+
while (true) {
|
|
13
|
+
const { done, value } = await reader.read();
|
|
14
|
+
if (done) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
yield value;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
reader.releaseLock();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function makeAsyncIterable(webStream) {
|
|
25
|
+
if (!webStream[Symbol.asyncIterator]) {
|
|
26
|
+
webStream[Symbol.asyncIterator] = streamAsyncIterator.bind(webStream);
|
|
27
|
+
}
|
|
28
|
+
if (!webStream.values) {
|
|
29
|
+
webStream.values = streamAsyncIterator.bind(webStream);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function ensureNodeStream(stream) {
|
|
33
|
+
if (stream instanceof ReadableStream) {
|
|
34
|
+
makeAsyncIterable(stream);
|
|
35
|
+
return stream_1.Readable.fromWeb(stream);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return stream;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function toStream(source) {
|
|
42
|
+
if (source instanceof Uint8Array) {
|
|
43
|
+
return stream_1.Readable.from(Buffer.from(source));
|
|
44
|
+
}
|
|
45
|
+
else if ((0, typeGuards_js_1.isBlob)(source)) {
|
|
46
|
+
return toStream((0, file_js_1.getRawContent)(source));
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return ensureNodeStream(source);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Utility function that concatenates a set of binary inputs into one combined output.
|
|
54
|
+
*
|
|
55
|
+
* @param sources - array of sources for the concatenation
|
|
56
|
+
* @returns - in Node, a (() =\> NodeJS.ReadableStream) which, when read, produces a concatenation of all the inputs.
|
|
57
|
+
* In browser, returns a `Blob` representing all the concatenated inputs.
|
|
58
|
+
*
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
async function concat(sources) {
|
|
62
|
+
return function () {
|
|
63
|
+
const streams = sources.map((x) => (typeof x === "function" ? x() : x)).map(toStream);
|
|
64
|
+
return stream_1.Readable.from((async function* () {
|
|
65
|
+
for (const stream of streams) {
|
|
66
|
+
for await (const chunk of stream) {
|
|
67
|
+
yield chunk;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
})());
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
exports.concat = concat;
|
|
74
|
+
//# 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,mCAAkC;AAElC,mDAAyC;AACzC,uCAA0C;AAE1C,KAAK,SAAS,CAAC,CAAC,mBAAmB;IAGjC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IAChC,IAAI,CAAC;QACH,OAAO,IAAI,EAAE,CAAC;YACZ,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,IAAI,EAAE,CAAC;gBACT,OAAO;YACT,CAAC;YAED,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,WAAW,EAAE,CAAC;IACvB,CAAC;AACH,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GAAG,CAAC,QAAQ,CAAC,CAAC;QAEtF,OAAO,iBAAQ,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;AAhBD,wBAgBC","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"]}
|
|
@@ -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"}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// Copyright (c) Microsoft Corporation.
|
|
3
3
|
// Licensed under the MIT license.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.createFile = exports.createFileFromStream = void 0;
|
|
6
|
-
const
|
|
5
|
+
exports.createFile = exports.createFileFromStream = exports.getRawContent = void 0;
|
|
6
|
+
const checkEnvironment_js_1 = require("./checkEnvironment.js");
|
|
7
|
+
const typeGuards_js_1 = require("./typeGuards.js");
|
|
7
8
|
const unimplementedMethods = {
|
|
8
9
|
arrayBuffer: () => {
|
|
9
10
|
throw new Error("Not implemented");
|
|
@@ -15,6 +16,40 @@ const unimplementedMethods = {
|
|
|
15
16
|
throw new Error("Not implemented");
|
|
16
17
|
},
|
|
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
|
+
function getRawContent(blob) {
|
|
45
|
+
if (hasRawContent(blob)) {
|
|
46
|
+
return blob[rawContent]();
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return blob.stream();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.getRawContent = getRawContent;
|
|
18
53
|
/**
|
|
19
54
|
* Create an object that implements the File interface. This object is intended to be
|
|
20
55
|
* passed into RequestBodyType.formData, and is not guaranteed to work as expected in
|
|
@@ -40,7 +75,14 @@ function createFileFromStream(stream, name, options = {}) {
|
|
|
40
75
|
webkitRelativePath: options.webkitRelativePath ?? "",
|
|
41
76
|
size: options.size ?? -1,
|
|
42
77
|
name,
|
|
43
|
-
stream: () =>
|
|
78
|
+
stream: () => {
|
|
79
|
+
const s = stream();
|
|
80
|
+
if ((0, typeGuards_js_1.isNodeReadableStream)(s)) {
|
|
81
|
+
throw new Error("Not supported: a Node stream was provided as input to createFileFromStream.");
|
|
82
|
+
}
|
|
83
|
+
return s;
|
|
84
|
+
},
|
|
85
|
+
[rawContent]: stream,
|
|
44
86
|
};
|
|
45
87
|
}
|
|
46
88
|
exports.createFileFromStream = createFileFromStream;
|
|
@@ -56,16 +98,22 @@ exports.createFileFromStream = createFileFromStream;
|
|
|
56
98
|
* @param options - optional metadata about the file, e.g. file name, file size, MIME type.
|
|
57
99
|
*/
|
|
58
100
|
function createFile(content, name, options = {}) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
101
|
+
if (checkEnvironment_js_1.isNode) {
|
|
102
|
+
return {
|
|
103
|
+
...unimplementedMethods,
|
|
104
|
+
type: options.type ?? "",
|
|
105
|
+
lastModified: options.lastModified ?? new Date().getTime(),
|
|
106
|
+
webkitRelativePath: options.webkitRelativePath ?? "",
|
|
107
|
+
size: content.byteLength,
|
|
108
|
+
name,
|
|
109
|
+
arrayBuffer: async () => content.buffer,
|
|
110
|
+
stream: () => new Blob([content]).stream(),
|
|
111
|
+
[rawContent]: () => content,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
return new File([content], name, options);
|
|
116
|
+
}
|
|
69
117
|
}
|
|
70
118
|
exports.createFile = createFile;
|
|
71
119
|
//# 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,
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/util/file.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,+DA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CAAoB,EAAC,CAAC,CAAC,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CACb,6EAA6E,CAC9E,CAAC;YACJ,CAAC;YAED,OAAO,CAAC,CAAC;QACX,CAAC;QACD,CAAC,UAAU,CAAC,EAAE,MAAM;KACA,CAAC;AACzB,CAAC;AAxBD,oDAwBC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACxB,OAAmB,EACnB,IAAY,EACZ,UAA6B,EAAE;IAE/B,IAAI,4BAAM,EAAE,CAAC;QACX,OAAO;YACL,GAAG,oBAAoB;YACvB,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,EAAE;YACxB,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC1D,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,IAAI,EAAE;YACpD,IAAI,EAAE,OAAO,CAAC,UAAU;YACxB,IAAI;YACJ,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM;YACvC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE;YAC1C,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC,OAAO;SACP,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC;AApBD,gCAoBC","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,CACzC,QAAkB,EAClB,OAAe,EACf,UAA8C,EAAE;IAEhD,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAC9C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO;IACT,CAAC;IAED,IAAI,iBAAiB,CAAC,UAAU,CAAC,EAAE,CAAC;QAClC,MAAM,WAAW,GAAG,+BAA+B,CAAC;YAClD,UAAU;YACV,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,IAAI,GAAG,OAAO,WAAW;SACpE,CAAC,CAAC;QACH,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAClC,CAAC;SAAM,IAAI,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;QACvC,IAAI,CAAC,aAAa,EAAE,WAAW,EAAE,gBAAgB,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QACD,MAAM,SAAS,GAAG,iCAAiC,CACjD,UAAU,EACV,aAAa,EAAE,WAAW,EAAE,gBAAgB,CAC7C,CAAC;QACF,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAe,EACf,UAA4C,EAC5C,UAAyB,EAAE;IAE3B,MAAM,QAAQ,GAAG,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAEpD,QAAQ,CAAC,SAAS,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;IAE9C,2BAA2B,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,UAAU,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,CAAC;IACvF,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,2BAA2B;IACzC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,gBAAgB,GAAG,uBAAuB,EAAE,CAAC;IAC/C,CAAC;IAED,OAAO,gBAAgB,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,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAoBlD,MAAM,UAAU,SAAS,CACvB,OAAe,EACf,4BAAgF,EAChF,gBAA+B,EAAE;IAEjC,IAAI,WAAwD,CAAC;IAC7D,IAAI,4BAA4B,EAAE,CAAC;QACjC,IAAI,YAAY,CAAC,4BAA4B,CAAC,EAAE,CAAC;YAC/C,WAAW,GAAG,4BAA4B,CAAC;QAC7C,CAAC;aAAM,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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
|
}
|