@azure-rest/health-insights-radiologyinsights 2.0.0-alpha.20250718.1 → 2.0.0-alpha.20250730.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/azureHealthInsightsClient.js +15 -13
- package/dist/browser/azureHealthInsightsClient.js.map +1 -1
- package/dist/browser/isUnexpected.js +4 -5
- package/dist/browser/isUnexpected.js.map +1 -1
- package/dist/browser/pollingHelper.js +14 -8
- package/dist/browser/pollingHelper.js.map +1 -1
- package/dist/commonjs/azureHealthInsightsClient.js +15 -13
- package/dist/commonjs/azureHealthInsightsClient.js.map +1 -1
- package/dist/commonjs/isUnexpected.js +4 -5
- package/dist/commonjs/isUnexpected.js.map +1 -1
- package/dist/commonjs/pollingHelper.js +14 -8
- package/dist/commonjs/pollingHelper.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +11 -11
- package/dist/esm/azureHealthInsightsClient.js +15 -13
- package/dist/esm/azureHealthInsightsClient.js.map +1 -1
- package/dist/esm/isUnexpected.js +4 -5
- package/dist/esm/isUnexpected.js.map +1 -1
- package/dist/esm/pollingHelper.js +14 -8
- package/dist/esm/pollingHelper.js.map +1 -1
- package/dist/react-native/azureHealthInsightsClient.js +15 -13
- package/dist/react-native/azureHealthInsightsClient.js.map +1 -1
- package/dist/react-native/isUnexpected.js +4 -5
- package/dist/react-native/isUnexpected.js.map +1 -1
- package/dist/react-native/pollingHelper.js +14 -8
- package/dist/react-native/pollingHelper.js.map +1 -1
- package/package.json +2 -2
- package/review/health-insights-radiologyinsights-node.api.md +1503 -1503
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
-
import { __rest } from "tslib";
|
|
4
3
|
import { getClient } from "@azure-rest/core-client";
|
|
5
4
|
import { logger } from "./logger.js";
|
|
6
5
|
/**
|
|
@@ -9,22 +8,25 @@ import { logger } from "./logger.js";
|
|
|
9
8
|
* @param credentials - uniquely identify client credential
|
|
10
9
|
* @param options - the parameter for all optional parameters
|
|
11
10
|
*/
|
|
12
|
-
export default function createClient(endpointParam, credentials,
|
|
13
|
-
|
|
14
|
-
var { apiVersion = "2024-10-01" } = _a, options = __rest(_a, ["apiVersion"]);
|
|
15
|
-
const endpointUrl = (_c = (_b = options.endpoint) !== null && _b !== void 0 ? _b : options.baseUrl) !== null && _c !== void 0 ? _c : `${endpointParam}/health-insights`;
|
|
11
|
+
export default function createClient(endpointParam, credentials, { apiVersion = "2024-10-01", ...options } = {}) {
|
|
12
|
+
const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/health-insights`;
|
|
16
13
|
const userAgentInfo = `azsdk-js-health-insights-radiologyinsights-rest/2.0.0`;
|
|
17
14
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
18
15
|
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
|
19
16
|
: `${userAgentInfo}`;
|
|
20
|
-
const clientOptions =
|
|
17
|
+
const clientOptions = {
|
|
18
|
+
...options,
|
|
19
|
+
userAgentOptions: {
|
|
21
20
|
userAgentPrefix,
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
},
|
|
22
|
+
loggingOptions: {
|
|
23
|
+
logger: options.loggingOptions?.logger ?? logger.info,
|
|
24
|
+
},
|
|
25
|
+
credentials: {
|
|
26
|
+
scopes: options.credentials?.scopes ?? ["https://cognitiveservices.azure.com/.default"],
|
|
27
|
+
apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key",
|
|
28
|
+
},
|
|
29
|
+
};
|
|
28
30
|
const client = getClient(endpointUrl, credentials, clientOptions);
|
|
29
31
|
client.pipeline.removePolicy({ name: "ApiVersionPolicy" });
|
|
30
32
|
client.pipeline.addPolicy({
|
|
@@ -35,7 +37,7 @@ export default function createClient(endpointParam, credentials, _a = {}) {
|
|
|
35
37
|
const url = new URL(req.url);
|
|
36
38
|
if (!url.searchParams.get("api-version") && apiVersion) {
|
|
37
39
|
const newUrl = `${req.url}${Array.from(url.searchParams.keys()).length > 0 ? "&" : "?"}api-version=${apiVersion}`;
|
|
38
|
-
const newReq =
|
|
40
|
+
const newReq = { ...req, url: newUrl };
|
|
39
41
|
return next(newReq);
|
|
40
42
|
}
|
|
41
43
|
return next(req);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"azureHealthInsightsClient.js","sourceRoot":"","sources":["../../src/azureHealthInsightsClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC
|
|
1
|
+
{"version":3,"file":"azureHealthInsightsClient.js","sourceRoot":"","sources":["../../src/azureHealthInsightsClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAUrC;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,aAAqB,EACrB,WAA4C,EAC5C,EAAE,UAAU,GAAG,YAAY,EAAE,GAAG,OAAO,KAAuC,EAAE;IAEhF,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,OAAO,IAAI,GAAG,aAAa,kBAAkB,CAAC;IAC9F,MAAM,aAAa,GAAG,uDAAuD,CAAC;IAC9E,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,eAAe;QAClE,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,eAAe,IAAI,aAAa,EAAE;QAChE,CAAC,CAAC,GAAG,aAAa,EAAE,CAAC;IACzB,MAAM,aAAa,GAAqC;QACtD,GAAG,OAAO;QACV,gBAAgB,EAAE;YAChB,eAAe;SAChB;QACD,cAAc,EAA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// Licensed under the MIT License.\n\nimport type { ClientOptions } from \"@azure-rest/core-client\";\nimport { getClient } from \"@azure-rest/core-client\";\nimport { logger } from \"./logger.js\";\nimport type { TokenCredential, KeyCredential } from \"@azure/core-auth\";\nimport type { AzureHealthInsightsClient } from \"./clientDefinitions.js\";\n\n/** The optional parameters for the client */\nexport interface AzureHealthInsightsClientOptions extends ClientOptions {\n /** The api version option of the client */\n apiVersion?: string;\n}\n\n/**\n * Initialize a new instance of `AzureHealthInsightsClient`\n * @param endpointParam - Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus2.api.cognitive.microsoft.com).\n * @param credentials - uniquely identify client credential\n * @param options - the parameter for all optional parameters\n */\nexport default function createClient(\n endpointParam: string,\n credentials: TokenCredential | KeyCredential,\n { apiVersion = \"2024-10-01\", ...options }: AzureHealthInsightsClientOptions = {},\n): AzureHealthInsightsClient {\n const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/health-insights`;\n const userAgentInfo = `azsdk-js-health-insights-radiologyinsights-rest/2.0.0`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n const clientOptions: AzureHealthInsightsClientOptions = {\n ...options,\n userAgentOptions: {\n userAgentPrefix,\n },\n loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info,\n },\n credentials: {\n scopes: options.credentials?.scopes ?? [\"https://cognitiveservices.azure.com/.default\"],\n apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? \"Ocp-Apim-Subscription-Key\",\n },\n };\n const client = getClient(endpointUrl, credentials, clientOptions) as AzureHealthInsightsClient;\n\n client.pipeline.removePolicy({ name: \"ApiVersionPolicy\" });\n client.pipeline.addPolicy({\n name: \"ClientApiVersionPolicy\",\n sendRequest: (req, next) => {\n // Use the apiVersion defined in request url directly\n // Append one if there is no apiVersion and we have one at client options\n const url = new URL(req.url);\n if (!url.searchParams.get(\"api-version\") && apiVersion) {\n const newUrl = `${req.url}${Array.from(url.searchParams.keys()).length > 0 ? \"&\" : \"?\"}api-version=${apiVersion}`;\n const newReq = { ...req, url: newUrl };\n return next(newReq);\n }\n\n return next(req);\n },\n });\n\n return client;\n}\n"]}
|
|
@@ -7,7 +7,7 @@ const responseMap = {
|
|
|
7
7
|
/** Unexpected responses for get & create job calls */
|
|
8
8
|
export function isUnexpected(response) {
|
|
9
9
|
const lroOriginal = response.headers["x-ms-original-url"];
|
|
10
|
-
const url = new URL(lroOriginal
|
|
10
|
+
const url = new URL(lroOriginal ?? response.request.url);
|
|
11
11
|
const method = response.request.method;
|
|
12
12
|
let pathDetails = responseMap[`${method} ${url.pathname}`];
|
|
13
13
|
if (!pathDetails) {
|
|
@@ -16,7 +16,6 @@ export function isUnexpected(response) {
|
|
|
16
16
|
return !pathDetails.includes(response.status);
|
|
17
17
|
}
|
|
18
18
|
function getParametrizedPathSuccess(method, path) {
|
|
19
|
-
var _a, _b, _c, _d;
|
|
20
19
|
const pathParts = path.split("/");
|
|
21
20
|
// Traverse list to match the longest candidate
|
|
22
21
|
// matchedLen: the length of candidate path
|
|
@@ -35,13 +34,13 @@ function getParametrizedPathSuccess(method, path) {
|
|
|
35
34
|
// track if we have found a match to return the values found.
|
|
36
35
|
let found = true;
|
|
37
36
|
for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
|
|
38
|
-
if (
|
|
39
|
-
const start = candidateParts[i].indexOf("}") + 1, end =
|
|
37
|
+
if (candidateParts[i]?.startsWith("{") && candidateParts[i]?.indexOf("}") !== -1) {
|
|
38
|
+
const start = candidateParts[i].indexOf("}") + 1, end = candidateParts[i]?.length;
|
|
40
39
|
// If the current part of the candidate is a "template" part
|
|
41
40
|
// Try to use the suffix of pattern to match the path
|
|
42
41
|
// {guid} ==> $
|
|
43
42
|
// {guid}:export ==> :export$
|
|
44
|
-
const isMatched = new RegExp(`${
|
|
43
|
+
const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(pathParts[j] || "");
|
|
45
44
|
if (!isMatched) {
|
|
46
45
|
found = false;
|
|
47
46
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../src/isUnexpected.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAWlC,MAAM,WAAW,GAA6B;IAC5C,mCAAmC,EAAE,CAAC,KAAK,CAAC;IAC5C,mCAAmC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;CACpD,CAAC;AAgBF,sDAAsD;AACtD,MAAM,UAAU,YAAY,CAC1B,QAM4B;IAE5B,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,
|
|
1
|
+
{"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../src/isUnexpected.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAWlC,MAAM,WAAW,GAA6B;IAC5C,mCAAmC,EAAE,CAAC,KAAK,CAAC;IAC5C,mCAAmC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;CACpD,CAAC;AAgBF,sDAAsD;AACtD,MAAM,UAAU,YAAY,CAC1B,QAM4B;IAE5B,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC;IACvC,IAAI,WAAW,GAAG,WAAW,CAAC,GAAG,MAAM,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC3D,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,WAAW,GAAG,0BAA0B,CAAC,MAAM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AAG,CAAC,EAC/C,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC;gBAClC,4DAA4D;gBAC5D,qDAAqD;gBACrD,eAAe;gBACf,6BAA6B;gBAC7B,MAAM,SAAS,GAAG,IAAI,MAAM,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAC1E,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,CACnB,CAAC;gBAEF,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,KAAK,GAAG,KAAK,CAAC;oBACd,MAAM;gBACR,CAAC;gBACD,SAAS;YACX,CAAC;YAED,8CAA8C;YAC9C,wDAAwD;YACxD,2CAA2C;YAC3C,IAAI,cAAc,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;gBACvC,KAAK,GAAG,KAAK,CAAC;gBACd,MAAM;YACR,CAAC;QACH,CAAC;QAED,qDAAqD;QACrD,sEAAsE;QACtE,IAAI,KAAK,IAAI,aAAa,CAAC,MAAM,GAAG,UAAU,EAAE,CAAC;YAC/C,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC;YAClC,YAAY,GAAG,KAAK,CAAC;QACvB,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAc;IACvC,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACjC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n GetJob200Response,\n GetJobDefaultResponse,\n CreateJob200Response,\n CreateJob201Response,\n CreateJobLogicalResponse,\n CreateJobDefaultResponse,\n} from \"./responses.js\";\n\nconst responseMap: Record<string, string[]> = {\n \"GET /radiology-insights/jobs/{id}\": [\"200\"],\n \"PUT /radiology-insights/jobs/{id}\": [\"200\", \"201\"],\n};\n\n/** Unexpected responses for get job calls */\nexport function isUnexpected(\n response: GetJob200Response | GetJobDefaultResponse,\n): response is GetJobDefaultResponse;\n\n/** Unexpected responses for create job calls */\nexport function isUnexpected(\n response:\n | CreateJob200Response\n | CreateJob201Response\n | CreateJobLogicalResponse\n | CreateJobDefaultResponse,\n): response is CreateJobDefaultResponse;\n\n/** Unexpected responses for get & create job calls */\nexport function isUnexpected(\n response:\n | GetJob200Response\n | GetJobDefaultResponse\n | CreateJob200Response\n | CreateJob201Response\n | CreateJobLogicalResponse\n | CreateJobDefaultResponse,\n): response is GetJobDefaultResponse | CreateJobDefaultResponse {\n const lroOriginal = response.headers[\"x-ms-original-url\"];\n const url = new URL(lroOriginal ?? response.request.url);\n const method = response.request.method;\n let pathDetails = responseMap[`${method} ${url.pathname}`];\n if (!pathDetails) {\n pathDetails = getParametrizedPathSuccess(method, url.pathname);\n }\n return !pathDetails.includes(response.status);\n}\n\nfunction getParametrizedPathSuccess(method: string, path: string): string[] {\n const pathParts = path.split(\"/\");\n\n // Traverse list to match the longest candidate\n // matchedLen: the length of candidate path\n // matchedValue: the matched status code array\n let matchedLen = -1,\n matchedValue: string[] = [];\n\n // Iterate the responseMap to find a match\n for (const [key, value] of Object.entries(responseMap)) {\n // Extracting the path from the map key which is in format\n // GET /path/foo\n if (!key.startsWith(method)) {\n continue;\n }\n const candidatePath = getPathFromMapKey(key);\n // Get each part of the url path\n const candidateParts = candidatePath.split(\"/\");\n\n // track if we have found a match to return the values found.\n let found = true;\n for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {\n if (candidateParts[i]?.startsWith(\"{\") && candidateParts[i]?.indexOf(\"}\") !== -1) {\n const start = candidateParts[i]!.indexOf(\"}\") + 1,\n end = candidateParts[i]?.length;\n // If the current part of the candidate is a \"template\" part\n // Try to use the suffix of pattern to match the path\n // {guid} ==> $\n // {guid}:export ==> :export$\n const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(\n pathParts[j] || \"\",\n );\n\n if (!isMatched) {\n found = false;\n break;\n }\n continue;\n }\n\n // If the candidate part is not a template and\n // the parts don't match mark the candidate as not found\n // to move on with the next candidate path.\n if (candidateParts[i] !== pathParts[j]) {\n found = false;\n break;\n }\n }\n\n // We finished evaluating the current candidate parts\n // Update the matched value if and only if we found the longer pattern\n if (found && candidatePath.length > matchedLen) {\n matchedLen = candidatePath.length;\n matchedValue = value;\n }\n }\n\n return matchedValue;\n}\n\nfunction getPathFromMapKey(mapKey: string): string {\n const pathStart = mapKey.indexOf(\"/\");\n return mapKey.slice(pathStart);\n}\n"]}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
import { createHttpPoller } from "@azure/core-lro";
|
|
4
4
|
export async function getLongRunningPoller(client, initialResponse, options = {}) {
|
|
5
|
-
var _a;
|
|
6
5
|
const abortController = new AbortController();
|
|
7
6
|
const poller = {
|
|
8
7
|
sendInitialRequest: async () => {
|
|
@@ -19,31 +18,34 @@ export async function getLongRunningPoller(client, initialResponse, options = {}
|
|
|
19
18
|
function abortListener() {
|
|
20
19
|
abortController.abort();
|
|
21
20
|
}
|
|
22
|
-
const inputAbortSignal = pollOptions
|
|
21
|
+
const inputAbortSignal = pollOptions?.abortSignal;
|
|
23
22
|
const abortSignal = abortController.signal;
|
|
24
|
-
if (inputAbortSignal
|
|
23
|
+
if (inputAbortSignal?.aborted) {
|
|
25
24
|
abortController.abort();
|
|
26
25
|
}
|
|
27
26
|
else if (!abortSignal.aborted) {
|
|
28
|
-
inputAbortSignal
|
|
27
|
+
inputAbortSignal?.addEventListener("abort", abortListener, {
|
|
29
28
|
once: true,
|
|
30
29
|
});
|
|
31
30
|
}
|
|
32
31
|
let response;
|
|
33
32
|
try {
|
|
34
33
|
response = await client
|
|
35
|
-
.pathUnchecked(path
|
|
34
|
+
.pathUnchecked(path ?? initialResponse.request.url)
|
|
36
35
|
.get({ abortSignal });
|
|
37
36
|
}
|
|
38
37
|
finally {
|
|
39
|
-
inputAbortSignal
|
|
38
|
+
inputAbortSignal?.removeEventListener("abort", abortListener);
|
|
40
39
|
}
|
|
41
40
|
const lroResponse = getLroResponse(response);
|
|
42
41
|
lroResponse.rawResponse.headers["x-ms-original-url"] = initialResponse.request.url;
|
|
43
42
|
return lroResponse;
|
|
44
43
|
},
|
|
45
44
|
};
|
|
46
|
-
const mergedOptions =
|
|
45
|
+
const mergedOptions = {
|
|
46
|
+
...options,
|
|
47
|
+
resolveOnUnsuccessful: options?.resolveOnUnsuccessful ?? true,
|
|
48
|
+
};
|
|
47
49
|
const httpPoller = createHttpPoller(poller, mergedOptions);
|
|
48
50
|
const simplePoller = {
|
|
49
51
|
isDone() {
|
|
@@ -91,7 +93,11 @@ function getLroResponse(response) {
|
|
|
91
93
|
}
|
|
92
94
|
return {
|
|
93
95
|
flatResponse: response,
|
|
94
|
-
rawResponse:
|
|
96
|
+
rawResponse: {
|
|
97
|
+
...response,
|
|
98
|
+
statusCode: Number.parseInt(response.status),
|
|
99
|
+
body: response.body,
|
|
100
|
+
},
|
|
95
101
|
};
|
|
96
102
|
}
|
|
97
103
|
//# sourceMappingURL=pollingHelper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pollingHelper.js","sourceRoot":"","sources":["../../src/pollingHelper.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAWlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAwFnD,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAAc,EACd,eAAwB,EACxB,UAAqE,EAAE;;IAEvE,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;IAC9C,MAAM,MAAM,GAA8B;QACxC,kBAAkB,EAAE,KAAK,IAAI,EAAE;YAC7B,sGAAsG;YACtG,2FAA2F;YAC3F,6BAA6B;YA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AAM,IAAI,SAAS,CAAC,uDAAuD,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAChG,CAAC;IAED,OAAO;QACL,YAAY,EAAE,QAAQ;QACtB,WAAW,kCACN,QAAQ,KACX,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAC5C,IAAI,EAAE,QAAQ,CAAC,IAAI,GACpB;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Client, HttpResponse } from \"@azure-rest/core-client\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type {\n CancelOnProgress,\n CreateHttpPollerOptions,\n RunningOperation,\n OperationResponse,\n OperationState,\n} from \"@azure/core-lro\";\nimport { createHttpPoller } from \"@azure/core-lro\";\nimport type {\n CreateJob200Response,\n CreateJob201Response,\n CreateJobDefaultResponse,\n CreateJobLogicalResponse,\n} from \"./responses.js\";\n\n/**\n * A simple poller that can be used to poll a long running operation.\n */\nexport interface SimplePollerLike<TState extends OperationState<TResult>, TResult> {\n /**\n * Returns true if the poller has finished polling.\n */\n isDone(): boolean;\n /**\n * Returns the state of the operation.\n */\n getOperationState(): TState;\n /**\n * Returns the result value of the operation,\n * regardless of the state of the poller.\n * It can return undefined or an incomplete form of the final TResult value\n * depending on the implementation.\n */\n getResult(): TResult | undefined;\n /**\n * Returns a promise that will resolve once a single polling request finishes.\n * It does this by calling the update method of the Poller's operation.\n */\n poll(options?: { abortSignal?: AbortSignalLike }): Promise<TState>;\n /**\n * Returns a promise that will resolve once the underlying operation is completed.\n */\n pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }): Promise<TResult>;\n /**\n * Invokes the provided callback after each polling is completed,\n * sending the current state of the poller's operation.\n *\n * It returns a method that can be used to stop receiving updates on the given callback function.\n */\n onProgress(callback: (state: TState) => void): CancelOnProgress;\n\n /**\n * Returns a promise that could be used for serialized version of the poller's operation\n * by invoking the operation's serialize method.\n */\n serialize(): Promise<string>;\n\n /**\n * Wait the poller to be submitted.\n */\n submitted(): Promise<void>;\n\n /**\n * Returns a string representation of the poller's operation. Similar to serialize but returns a string.\n * @deprecated Use serialize() instead.\n */\n toString(): string;\n\n /**\n * Stops the poller from continuing to poll. Please note this will only stop the client-side polling\n * @deprecated Use abortSignal to stop polling instead.\n */\n stopPolling(): void;\n\n /**\n * Returns true if the poller is stopped.\n * @deprecated Use abortSignal status to track this instead.\n */\n isStopped(): boolean;\n}\n\n/**\n * Helper function that builds a Poller object to help polling a long running operation.\n * @param client - Client to use for sending the request to get additional pages.\n * @param initialResponse - The initial response.\n * @param options - Options to set a resume state or custom polling interval.\n * @returns - A poller object to poll for operation state updates and eventually get the final response.\n */\nexport async function getLongRunningPoller<\n TResult extends CreateJobLogicalResponse | CreateJobDefaultResponse,\n>(\n client: Client,\n initialResponse: CreateJob200Response | CreateJob201Response | CreateJobDefaultResponse,\n options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>,\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;\nexport async function getLongRunningPoller<TResult extends HttpResponse>(\n client: Client,\n initialResponse: TResult,\n options: CreateHttpPollerOptions<TResult, OperationState<TResult>> = {},\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>> {\n const abortController = new AbortController();\n const poller: RunningOperation<TResult> = {\n sendInitialRequest: async () => {\n // In the case of Rest Clients we are building the LRO poller object from a response that's the reason\n // we are not triggering the initial request here, just extracting the information from the\n // response we were provided.\n return getLroResponse(initialResponse);\n },\n sendPollRequest: async (path: string, pollOptions?: { abortSignal?: AbortSignalLike }) => {\n // This is the callback that is going to be called to poll the service\n // to get the latest status. We use the client provided and the polling path\n // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location\n // depending on the lro pattern that the service implements. If non is provided we default to the initial path.\n function abortListener(): void {\n abortController.abort();\n }\n const inputAbortSignal = pollOptions?.abortSignal;\n const abortSignal = abortController.signal;\n if (inputAbortSignal?.aborted) {\n abortController.abort();\n } else if (!abortSignal.aborted) {\n inputAbortSignal?.addEventListener(\"abort\", abortListener, {\n once: true,\n });\n }\n let response;\n try {\n response = await client\n .pathUnchecked(path ?? initialResponse.request.url)\n .get({ abortSignal });\n } finally {\n inputAbortSignal?.removeEventListener(\"abort\", abortListener);\n }\n const lroResponse = getLroResponse(response as TResult);\n lroResponse.rawResponse.headers[\"x-ms-original-url\"] = initialResponse.request.url;\n return lroResponse;\n },\n };\n\n const mergedOptions = {\n ...options,\n resolveOnUnsuccessful: options?.resolveOnUnsuccessful ?? true,\n };\n const httpPoller = createHttpPoller(poller, mergedOptions);\n const simplePoller: SimplePollerLike<OperationState<TResult>, TResult> = {\n isDone() {\n return httpPoller.isDone;\n },\n isStopped() {\n return abortController.signal.aborted;\n },\n getOperationState() {\n if (!httpPoller.operationState) {\n throw new Error(\n \"Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().\",\n );\n }\n return httpPoller.operationState;\n },\n getResult() {\n return httpPoller.result;\n },\n toString() {\n if (!httpPoller.operationState) {\n throw new Error(\n \"Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().\",\n );\n }\n return JSON.stringify({\n state: httpPoller.operationState,\n });\n },\n stopPolling() {\n abortController.abort();\n },\n onProgress: httpPoller.onProgress,\n poll: httpPoller.poll,\n pollUntilDone: httpPoller.pollUntilDone,\n serialize: httpPoller.serialize,\n submitted: httpPoller.submitted,\n };\n return simplePoller;\n}\n\n/**\n * Converts a Rest Client response to a response that the LRO implementation understands\n * @param response - a rest client http response\n * @returns - An LRO response that the LRO implementation understands\n */\nfunction getLroResponse<TResult extends HttpResponse>(\n response: TResult,\n): OperationResponse<TResult> {\n if (Number.isNaN(response.status)) {\n throw new TypeError(`Status code of the response is not a number. Value: ${response.status}`);\n }\n\n return {\n flatResponse: response,\n rawResponse: {\n ...response,\n statusCode: Number.parseInt(response.status),\n body: response.body,\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"p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SAAS;QAC/B,SAAS,EAAE,UAAU,CAAC,SAAS;KAChC,CAAC;IACF,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc,CACrB,QAAiB;IAEjB,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,SAAS,CAAC,uDAAuD,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAChG,CAAC;IAED,OAAO;QACL,YAAY,EAAE,QAAQ;QACtB,WAAW,EAAE;YACX,GAAG,QAAQ;YACX,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;YAC5C,IAAI,EAAE,QAAQ,CAAC,IAAI;SACpB;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Client, HttpResponse } from \"@azure-rest/core-client\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type {\n CancelOnProgress,\n CreateHttpPollerOptions,\n RunningOperation,\n OperationResponse,\n OperationState,\n} from \"@azure/core-lro\";\nimport { createHttpPoller } from \"@azure/core-lro\";\nimport type {\n CreateJob200Response,\n CreateJob201Response,\n CreateJobDefaultResponse,\n CreateJobLogicalResponse,\n} from \"./responses.js\";\n\n/**\n * A simple poller that can be used to poll a long running operation.\n */\nexport interface SimplePollerLike<TState extends OperationState<TResult>, TResult> {\n /**\n * Returns true if the poller has finished polling.\n */\n isDone(): boolean;\n /**\n * Returns the state of the operation.\n */\n getOperationState(): TState;\n /**\n * Returns the result value of the operation,\n * regardless of the state of the poller.\n * It can return undefined or an incomplete form of the final TResult value\n * depending on the implementation.\n */\n getResult(): TResult | undefined;\n /**\n * Returns a promise that will resolve once a single polling request finishes.\n * It does this by calling the update method of the Poller's operation.\n */\n poll(options?: { abortSignal?: AbortSignalLike }): Promise<TState>;\n /**\n * Returns a promise that will resolve once the underlying operation is completed.\n */\n pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }): Promise<TResult>;\n /**\n * Invokes the provided callback after each polling is completed,\n * sending the current state of the poller's operation.\n *\n * It returns a method that can be used to stop receiving updates on the given callback function.\n */\n onProgress(callback: (state: TState) => void): CancelOnProgress;\n\n /**\n * Returns a promise that could be used for serialized version of the poller's operation\n * by invoking the operation's serialize method.\n */\n serialize(): Promise<string>;\n\n /**\n * Wait the poller to be submitted.\n */\n submitted(): Promise<void>;\n\n /**\n * Returns a string representation of the poller's operation. Similar to serialize but returns a string.\n * @deprecated Use serialize() instead.\n */\n toString(): string;\n\n /**\n * Stops the poller from continuing to poll. Please note this will only stop the client-side polling\n * @deprecated Use abortSignal to stop polling instead.\n */\n stopPolling(): void;\n\n /**\n * Returns true if the poller is stopped.\n * @deprecated Use abortSignal status to track this instead.\n */\n isStopped(): boolean;\n}\n\n/**\n * Helper function that builds a Poller object to help polling a long running operation.\n * @param client - Client to use for sending the request to get additional pages.\n * @param initialResponse - The initial response.\n * @param options - Options to set a resume state or custom polling interval.\n * @returns - A poller object to poll for operation state updates and eventually get the final response.\n */\nexport async function getLongRunningPoller<\n TResult extends CreateJobLogicalResponse | CreateJobDefaultResponse,\n>(\n client: Client,\n initialResponse: CreateJob200Response | CreateJob201Response | CreateJobDefaultResponse,\n options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>,\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;\nexport async function getLongRunningPoller<TResult extends HttpResponse>(\n client: Client,\n initialResponse: TResult,\n options: CreateHttpPollerOptions<TResult, OperationState<TResult>> = {},\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>> {\n const abortController = new AbortController();\n const poller: RunningOperation<TResult> = {\n sendInitialRequest: async () => {\n // In the case of Rest Clients we are building the LRO poller object from a response that's the reason\n // we are not triggering the initial request here, just extracting the information from the\n // response we were provided.\n return getLroResponse(initialResponse);\n },\n sendPollRequest: async (path: string, pollOptions?: { abortSignal?: AbortSignalLike }) => {\n // This is the callback that is going to be called to poll the service\n // to get the latest status. We use the client provided and the polling path\n // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location\n // depending on the lro pattern that the service implements. If non is provided we default to the initial path.\n function abortListener(): void {\n abortController.abort();\n }\n const inputAbortSignal = pollOptions?.abortSignal;\n const abortSignal = abortController.signal;\n if (inputAbortSignal?.aborted) {\n abortController.abort();\n } else if (!abortSignal.aborted) {\n inputAbortSignal?.addEventListener(\"abort\", abortListener, {\n once: true,\n });\n }\n let response;\n try {\n response = await client\n .pathUnchecked(path ?? initialResponse.request.url)\n .get({ abortSignal });\n } finally {\n inputAbortSignal?.removeEventListener(\"abort\", abortListener);\n }\n const lroResponse = getLroResponse(response as TResult);\n lroResponse.rawResponse.headers[\"x-ms-original-url\"] = initialResponse.request.url;\n return lroResponse;\n },\n };\n\n const mergedOptions = {\n ...options,\n resolveOnUnsuccessful: options?.resolveOnUnsuccessful ?? true,\n };\n const httpPoller = createHttpPoller(poller, mergedOptions);\n const simplePoller: SimplePollerLike<OperationState<TResult>, TResult> = {\n isDone() {\n return httpPoller.isDone;\n },\n isStopped() {\n return abortController.signal.aborted;\n },\n getOperationState() {\n if (!httpPoller.operationState) {\n throw new Error(\n \"Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().\",\n );\n }\n return httpPoller.operationState;\n },\n getResult() {\n return httpPoller.result;\n },\n toString() {\n if (!httpPoller.operationState) {\n throw new Error(\n \"Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().\",\n );\n }\n return JSON.stringify({\n state: httpPoller.operationState,\n });\n },\n stopPolling() {\n abortController.abort();\n },\n onProgress: httpPoller.onProgress,\n poll: httpPoller.poll,\n pollUntilDone: httpPoller.pollUntilDone,\n serialize: httpPoller.serialize,\n submitted: httpPoller.submitted,\n };\n return simplePoller;\n}\n\n/**\n * Converts a Rest Client response to a response that the LRO implementation understands\n * @param response - a rest client http response\n * @returns - An LRO response that the LRO implementation understands\n */\nfunction getLroResponse<TResult extends HttpResponse>(\n response: TResult,\n): OperationResponse<TResult> {\n if (Number.isNaN(response.status)) {\n throw new TypeError(`Status code of the response is not a number. Value: ${response.status}`);\n }\n\n return {\n flatResponse: response,\n rawResponse: {\n ...response,\n statusCode: Number.parseInt(response.status),\n body: response.body,\n },\n };\n}\n"]}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
// Licensed under the MIT License.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.default = createClient;
|
|
6
|
-
const tslib_1 = require("tslib");
|
|
7
6
|
const core_client_1 = require("@azure-rest/core-client");
|
|
8
7
|
const logger_js_1 = require("./logger.js");
|
|
9
8
|
/**
|
|
@@ -12,22 +11,25 @@ const logger_js_1 = require("./logger.js");
|
|
|
12
11
|
* @param credentials - uniquely identify client credential
|
|
13
12
|
* @param options - the parameter for all optional parameters
|
|
14
13
|
*/
|
|
15
|
-
function createClient(endpointParam, credentials,
|
|
16
|
-
|
|
17
|
-
var { apiVersion = "2024-10-01" } = _a, options = tslib_1.__rest(_a, ["apiVersion"]);
|
|
18
|
-
const endpointUrl = (_c = (_b = options.endpoint) !== null && _b !== void 0 ? _b : options.baseUrl) !== null && _c !== void 0 ? _c : `${endpointParam}/health-insights`;
|
|
14
|
+
function createClient(endpointParam, credentials, { apiVersion = "2024-10-01", ...options } = {}) {
|
|
15
|
+
const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/health-insights`;
|
|
19
16
|
const userAgentInfo = `azsdk-js-health-insights-radiologyinsights-rest/2.0.0`;
|
|
20
17
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
21
18
|
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
|
22
19
|
: `${userAgentInfo}`;
|
|
23
|
-
const clientOptions =
|
|
20
|
+
const clientOptions = {
|
|
21
|
+
...options,
|
|
22
|
+
userAgentOptions: {
|
|
24
23
|
userAgentPrefix,
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
},
|
|
25
|
+
loggingOptions: {
|
|
26
|
+
logger: options.loggingOptions?.logger ?? logger_js_1.logger.info,
|
|
27
|
+
},
|
|
28
|
+
credentials: {
|
|
29
|
+
scopes: options.credentials?.scopes ?? ["https://cognitiveservices.azure.com/.default"],
|
|
30
|
+
apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key",
|
|
31
|
+
},
|
|
32
|
+
};
|
|
31
33
|
const client = (0, core_client_1.getClient)(endpointUrl, credentials, clientOptions);
|
|
32
34
|
client.pipeline.removePolicy({ name: "ApiVersionPolicy" });
|
|
33
35
|
client.pipeline.addPolicy({
|
|
@@ -38,7 +40,7 @@ function createClient(endpointParam, credentials, _a = {}) {
|
|
|
38
40
|
const url = new URL(req.url);
|
|
39
41
|
if (!url.searchParams.get("api-version") && apiVersion) {
|
|
40
42
|
const newUrl = `${req.url}${Array.from(url.searchParams.keys()).length > 0 ? "&" : "?"}api-version=${apiVersion}`;
|
|
41
|
-
const newReq =
|
|
43
|
+
const newReq = { ...req, url: newUrl };
|
|
42
44
|
return next(newReq);
|
|
43
45
|
}
|
|
44
46
|
return next(req);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"azureHealthInsightsClient.js","sourceRoot":"","sources":["../../src/azureHealthInsightsClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAoBlC,+BA4CC
|
|
1
|
+
{"version":3,"file":"azureHealthInsightsClient.js","sourceRoot":"","sources":["../../src/azureHealthInsightsClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAoBlC,+BA4CC;AA7DD,yDAAoD;AACpD,2CAAqC;AAUrC;;;;;GAKG;AACH,SAAwB,YAAY,CAClC,aAAqB,EACrB,WAA4C,EAC5C,EAAE,UAAU,GAAG,YAAY,EAAE,GAAG,O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G,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,eAAe,UAAU,EAAE,CAAC;gBAClH,MAAM,MAAM,GAAG,EAAE,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;gBACvC,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;YACtB,CAAC;YAED,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ClientOptions } from \"@azure-rest/core-client\";\nimport { getClient } from \"@azure-rest/core-client\";\nimport { logger } from \"./logger.js\";\nimport type { TokenCredential, KeyCredential } from \"@azure/core-auth\";\nimport type { AzureHealthInsightsClient } from \"./clientDefinitions.js\";\n\n/** The optional parameters for the client */\nexport interface AzureHealthInsightsClientOptions extends ClientOptions {\n /** The api version option of the client */\n apiVersion?: string;\n}\n\n/**\n * Initialize a new instance of `AzureHealthInsightsClient`\n * @param endpointParam - Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus2.api.cognitive.microsoft.com).\n * @param credentials - uniquely identify client credential\n * @param options - the parameter for all optional parameters\n */\nexport default function createClient(\n endpointParam: string,\n credentials: TokenCredential | KeyCredential,\n { apiVersion = \"2024-10-01\", ...options }: AzureHealthInsightsClientOptions = {},\n): AzureHealthInsightsClient {\n const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/health-insights`;\n const userAgentInfo = `azsdk-js-health-insights-radiologyinsights-rest/2.0.0`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n const clientOptions: AzureHealthInsightsClientOptions = {\n ...options,\n userAgentOptions: {\n userAgentPrefix,\n },\n loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info,\n },\n credentials: {\n scopes: options.credentials?.scopes ?? [\"https://cognitiveservices.azure.com/.default\"],\n apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? \"Ocp-Apim-Subscription-Key\",\n },\n };\n const client = getClient(endpointUrl, credentials, clientOptions) as AzureHealthInsightsClient;\n\n client.pipeline.removePolicy({ name: \"ApiVersionPolicy\" });\n client.pipeline.addPolicy({\n name: \"ClientApiVersionPolicy\",\n sendRequest: (req, next) => {\n // Use the apiVersion defined in request url directly\n // Append one if there is no apiVersion and we have one at client options\n const url = new URL(req.url);\n if (!url.searchParams.get(\"api-version\") && apiVersion) {\n const newUrl = `${req.url}${Array.from(url.searchParams.keys()).length > 0 ? \"&\" : \"?\"}api-version=${apiVersion}`;\n const newReq = { ...req, url: newUrl };\n return next(newReq);\n }\n\n return next(req);\n },\n });\n\n return client;\n}\n"]}
|
|
@@ -10,7 +10,7 @@ const responseMap = {
|
|
|
10
10
|
/** Unexpected responses for get & create job calls */
|
|
11
11
|
function isUnexpected(response) {
|
|
12
12
|
const lroOriginal = response.headers["x-ms-original-url"];
|
|
13
|
-
const url = new URL(lroOriginal
|
|
13
|
+
const url = new URL(lroOriginal ?? response.request.url);
|
|
14
14
|
const method = response.request.method;
|
|
15
15
|
let pathDetails = responseMap[`${method} ${url.pathname}`];
|
|
16
16
|
if (!pathDetails) {
|
|
@@ -19,7 +19,6 @@ function isUnexpected(response) {
|
|
|
19
19
|
return !pathDetails.includes(response.status);
|
|
20
20
|
}
|
|
21
21
|
function getParametrizedPathSuccess(method, path) {
|
|
22
|
-
var _a, _b, _c, _d;
|
|
23
22
|
const pathParts = path.split("/");
|
|
24
23
|
// Traverse list to match the longest candidate
|
|
25
24
|
// matchedLen: the length of candidate path
|
|
@@ -38,13 +37,13 @@ function getParametrizedPathSuccess(method, path) {
|
|
|
38
37
|
// track if we have found a match to return the values found.
|
|
39
38
|
let found = true;
|
|
40
39
|
for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
|
|
41
|
-
if (
|
|
42
|
-
const start = candidateParts[i].indexOf("}") + 1, end =
|
|
40
|
+
if (candidateParts[i]?.startsWith("{") && candidateParts[i]?.indexOf("}") !== -1) {
|
|
41
|
+
const start = candidateParts[i].indexOf("}") + 1, end = candidateParts[i]?.length;
|
|
43
42
|
// If the current part of the candidate is a "template" part
|
|
44
43
|
// Try to use the suffix of pattern to match the path
|
|
45
44
|
// {guid} ==> $
|
|
46
45
|
// {guid}:export ==> :export$
|
|
47
|
-
const isMatched = new RegExp(`${
|
|
46
|
+
const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(pathParts[j] || "");
|
|
48
47
|
if (!isMatched) {
|
|
49
48
|
found = false;
|
|
50
49
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../src/isUnexpected.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AA+BlC,oCAiBC;AArCD,MAAM,WAAW,GAA6B;IAC5C,mCAAmC,EAAE,CAAC,KAAK,CAAC;IAC5C,mCAAmC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;CACpD,CAAC;AAgBF,sDAAsD;AACtD,SAAgB,YAAY,CAC1B,QAM4B;IAE5B,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,
|
|
1
|
+
{"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../src/isUnexpected.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AA+BlC,oCAiBC;AArCD,MAAM,WAAW,GAA6B;IAC5C,mCAAmC,EAAE,CAAC,KAAK,CAAC;IAC5C,mCAAmC,EAAE,CAA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a,CAAC,MAAM,CAAC;YAClC,YAAY,GAAG,KAAK,CAAC;QACvB,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAc;IACvC,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACjC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n GetJob200Response,\n GetJobDefaultResponse,\n CreateJob200Response,\n CreateJob201Response,\n CreateJobLogicalResponse,\n CreateJobDefaultResponse,\n} from \"./responses.js\";\n\nconst responseMap: Record<string, string[]> = {\n \"GET /radiology-insights/jobs/{id}\": [\"200\"],\n \"PUT /radiology-insights/jobs/{id}\": [\"200\", \"201\"],\n};\n\n/** Unexpected responses for get job calls */\nexport function isUnexpected(\n response: GetJob200Response | GetJobDefaultResponse,\n): response is GetJobDefaultResponse;\n\n/** Unexpected responses for create job calls */\nexport function isUnexpected(\n response:\n | CreateJob200Response\n | CreateJob201Response\n | CreateJobLogicalResponse\n | CreateJobDefaultResponse,\n): response is CreateJobDefaultResponse;\n\n/** Unexpected responses for get & create job calls */\nexport function isUnexpected(\n response:\n | GetJob200Response\n | GetJobDefaultResponse\n | CreateJob200Response\n | CreateJob201Response\n | CreateJobLogicalResponse\n | CreateJobDefaultResponse,\n): response is GetJobDefaultResponse | CreateJobDefaultResponse {\n const lroOriginal = response.headers[\"x-ms-original-url\"];\n const url = new URL(lroOriginal ?? response.request.url);\n const method = response.request.method;\n let pathDetails = responseMap[`${method} ${url.pathname}`];\n if (!pathDetails) {\n pathDetails = getParametrizedPathSuccess(method, url.pathname);\n }\n return !pathDetails.includes(response.status);\n}\n\nfunction getParametrizedPathSuccess(method: string, path: string): string[] {\n const pathParts = path.split(\"/\");\n\n // Traverse list to match the longest candidate\n // matchedLen: the length of candidate path\n // matchedValue: the matched status code array\n let matchedLen = -1,\n matchedValue: string[] = [];\n\n // Iterate the responseMap to find a match\n for (const [key, value] of Object.entries(responseMap)) {\n // Extracting the path from the map key which is in format\n // GET /path/foo\n if (!key.startsWith(method)) {\n continue;\n }\n const candidatePath = getPathFromMapKey(key);\n // Get each part of the url path\n const candidateParts = candidatePath.split(\"/\");\n\n // track if we have found a match to return the values found.\n let found = true;\n for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {\n if (candidateParts[i]?.startsWith(\"{\") && candidateParts[i]?.indexOf(\"}\") !== -1) {\n const start = candidateParts[i]!.indexOf(\"}\") + 1,\n end = candidateParts[i]?.length;\n // If the current part of the candidate is a \"template\" part\n // Try to use the suffix of pattern to match the path\n // {guid} ==> $\n // {guid}:export ==> :export$\n const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(\n pathParts[j] || \"\",\n );\n\n if (!isMatched) {\n found = false;\n break;\n }\n continue;\n }\n\n // If the candidate part is not a template and\n // the parts don't match mark the candidate as not found\n // to move on with the next candidate path.\n if (candidateParts[i] !== pathParts[j]) {\n found = false;\n break;\n }\n }\n\n // We finished evaluating the current candidate parts\n // Update the matched value if and only if we found the longer pattern\n if (found && candidatePath.length > matchedLen) {\n matchedLen = candidatePath.length;\n matchedValue = value;\n }\n }\n\n return matchedValue;\n}\n\nfunction getPathFromMapKey(mapKey: string): string {\n const pathStart = mapKey.indexOf(\"/\");\n return mapKey.slice(pathStart);\n}\n"]}
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
exports.getLongRunningPoller = getLongRunningPoller;
|
|
6
6
|
const core_lro_1 = require("@azure/core-lro");
|
|
7
7
|
async function getLongRunningPoller(client, initialResponse, options = {}) {
|
|
8
|
-
var _a;
|
|
9
8
|
const abortController = new AbortController();
|
|
10
9
|
const poller = {
|
|
11
10
|
sendInitialRequest: async () => {
|
|
@@ -22,31 +21,34 @@ async function getLongRunningPoller(client, initialResponse, options = {}) {
|
|
|
22
21
|
function abortListener() {
|
|
23
22
|
abortController.abort();
|
|
24
23
|
}
|
|
25
|
-
const inputAbortSignal = pollOptions
|
|
24
|
+
const inputAbortSignal = pollOptions?.abortSignal;
|
|
26
25
|
const abortSignal = abortController.signal;
|
|
27
|
-
if (inputAbortSignal
|
|
26
|
+
if (inputAbortSignal?.aborted) {
|
|
28
27
|
abortController.abort();
|
|
29
28
|
}
|
|
30
29
|
else if (!abortSignal.aborted) {
|
|
31
|
-
inputAbortSignal
|
|
30
|
+
inputAbortSignal?.addEventListener("abort", abortListener, {
|
|
32
31
|
once: true,
|
|
33
32
|
});
|
|
34
33
|
}
|
|
35
34
|
let response;
|
|
36
35
|
try {
|
|
37
36
|
response = await client
|
|
38
|
-
.pathUnchecked(path
|
|
37
|
+
.pathUnchecked(path ?? initialResponse.request.url)
|
|
39
38
|
.get({ abortSignal });
|
|
40
39
|
}
|
|
41
40
|
finally {
|
|
42
|
-
inputAbortSignal
|
|
41
|
+
inputAbortSignal?.removeEventListener("abort", abortListener);
|
|
43
42
|
}
|
|
44
43
|
const lroResponse = getLroResponse(response);
|
|
45
44
|
lroResponse.rawResponse.headers["x-ms-original-url"] = initialResponse.request.url;
|
|
46
45
|
return lroResponse;
|
|
47
46
|
},
|
|
48
47
|
};
|
|
49
|
-
const mergedOptions =
|
|
48
|
+
const mergedOptions = {
|
|
49
|
+
...options,
|
|
50
|
+
resolveOnUnsuccessful: options?.resolveOnUnsuccessful ?? true,
|
|
51
|
+
};
|
|
50
52
|
const httpPoller = (0, core_lro_1.createHttpPoller)(poller, mergedOptions);
|
|
51
53
|
const simplePoller = {
|
|
52
54
|
isDone() {
|
|
@@ -94,7 +96,11 @@ function getLroResponse(response) {
|
|
|
94
96
|
}
|
|
95
97
|
return {
|
|
96
98
|
flatResponse: response,
|
|
97
|
-
rawResponse:
|
|
99
|
+
rawResponse: {
|
|
100
|
+
...response,
|
|
101
|
+
statusCode: Number.parseInt(response.status),
|
|
102
|
+
body: response.body,
|
|
103
|
+
},
|
|
98
104
|
};
|
|
99
105
|
}
|
|
100
106
|
//# sourceMappingURL=pollingHelper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pollingHelper.js","sourceRoot":"","sources":["../../src/pollingHelper.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAmGlC,oDAuFC;AA/KD,8CAAmD;AAwF5C,KAAK,UAAU,oBAAoB,CACxC,MAAc,EACd,eAAwB,EACxB,UAAqE,EAAE;;IAEvE,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;IAC9C,MAAM,MAAM,GAA8B;QACxC,kBAAkB,EAAE,KAAK,IAAI,EAAE;YAC7B,sGAAsG;YACtG,2FAA2F;YAC3F,6BAA6B;YAC7B,OAAO,cAAc,CAAC,eAAe,CAAC,CAAC;QACzC,CAAC;QACD,eAAe,EAAE,KAAK,EAAE,IAAY,EAAE,WAA+C,EAAE,EAAE;YACvF,sEAAsE;YACtE,4EAA4E;YAC5E,0JAA0J;YAC1J,+GAA+G;YAC/G,SAAS,aAAa;gBACpB,eAAe,CAAC,KAAK,EAAE,CAAC;YAC1B,CAAC;YACD,MAAM,gBAAgB,GAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,WAAW,CAAC;YAClD,MAAM,WAAW,GAAG,eAAe,CAAC,MAAM,CAAC;YAC3C,IAAI,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,OAAO,EAAE,CAAC;gBAC9B,eAAe,CAAC,KAAK,EAAE,CAAC;YAC1B,CAAC;iBAAM,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;gBAChC,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,gBAAgB,CAAC,OAAO,EAAE,aAAa,EAAE;oBACzD,IAAI,EAAE,IAAI;iBACX,CAAC,CAAC;YACL,CAAC;YACD,IAAI,QAAQ,CAAC;YACb,IAAI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ACD,OAAO,IAAI,CAAC,SAAS,CAAC;gBACpB,KAAK,EAAE,UAAU,CAAC,cAAc;aACjC,CAAC,CAAC;QACL,CAAC;QACD,WAAW;YACT,eAAe,CAAC,KAAK,EAAE,CAAC;QAC1B,CAAC;QACD,UAAU,EAAE,UAAU,CAAC,UAAU;QACjC,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,SAAS,EAAE,UAAU,CAAC,SAAS;QAC/B,SAAS,EAAE,UAAU,CAAC,SAAS;KAChC,CAAC;IACF,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc,CACrB,QAAiB;IAEjB,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,SAAS,CAAC,uDAAuD,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAChG,CAAC;IAED,OAAO;QACL,YAAY,EAAE,QAAQ;QACtB,WAAW,kCACN,QAAQ,KACX,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAC5C,IAAI,EAAE,QAAQ,CAAC,IAAI,GACpB;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Client, HttpResponse } from \"@azure-rest/core-client\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type {\n CancelOnProgress,\n CreateHttpPollerOptions,\n RunningOperation,\n OperationResponse,\n OperationState,\n} from \"@azure/core-lro\";\nimport { createHttpPoller } from \"@azure/core-lro\";\nimport type {\n CreateJob200Response,\n CreateJob201Response,\n CreateJobDefaultResponse,\n CreateJobLogicalResponse,\n} from \"./responses.js\";\n\n/**\n * A simple poller that can be used to poll a long running operation.\n */\nexport interface SimplePollerLike<TState extends OperationState<TResult>, TResult> {\n /**\n * Returns true if the poller has finished polling.\n */\n isDone(): boolean;\n /**\n * Returns the state of the operation.\n */\n getOperationState(): TState;\n /**\n * Returns the result value of the operation,\n * regardless of the state of the poller.\n * It can return undefined or an incomplete form of the final TResult value\n * depending on the implementation.\n */\n getResult(): TResult | undefined;\n /**\n * Returns a promise that will resolve once a single polling request finishes.\n * It does this by calling the update method of the Poller's operation.\n */\n poll(options?: { abortSignal?: AbortSignalLike }): Promise<TState>;\n /**\n * Returns a promise that will resolve once the underlying operation is completed.\n */\n pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }): Promise<TResult>;\n /**\n * Invokes the provided callback after each polling is completed,\n * sending the current state of the poller's operation.\n *\n * It returns a method that can be used to stop receiving updates on the given callback function.\n */\n onProgress(callback: (state: TState) => void): CancelOnProgress;\n\n /**\n * Returns a promise that could be used for serialized version of the poller's operation\n * by invoking the operation's serialize method.\n */\n serialize(): Promise<string>;\n\n /**\n * Wait the poller to be submitted.\n */\n submitted(): Promise<void>;\n\n /**\n * Returns a string representation of the poller's operation. Similar to serialize but returns a string.\n * @deprecated Use serialize() instead.\n */\n toString(): string;\n\n /**\n * Stops the poller from continuing to poll. Please note this will only stop the client-side polling\n * @deprecated Use abortSignal to stop polling instead.\n */\n stopPolling(): void;\n\n /**\n * Returns true if the poller is stopped.\n * @deprecated Use abortSignal status to track this instead.\n */\n isStopped(): boolean;\n}\n\n/**\n * Helper function that builds a Poller object to help polling a long running operation.\n * @param client - Client to use for sending the request to get additional pages.\n * @param initialResponse - The initial response.\n * @param options - Options to set a resume state or custom polling interval.\n * @returns - A poller object to poll for operation state updates and eventually get the final response.\n */\nexport async function getLongRunningPoller<\n TResult extends CreateJobLogicalResponse | CreateJobDefaultResponse,\n>(\n client: Client,\n initialResponse: CreateJob200Response | CreateJob201Response | CreateJobDefaultResponse,\n options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>,\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;\nexport async function getLongRunningPoller<TResult extends HttpResponse>(\n client: Client,\n initialResponse: TResult,\n options: CreateHttpPollerOptions<TResult, OperationState<TResult>> = {},\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>> {\n const abortController = new AbortController();\n const poller: RunningOperation<TResult> = {\n sendInitialRequest: async () => {\n // In the case of Rest Clients we are building the LRO poller object from a response that's the reason\n // we are not triggering the initial request here, just extracting the information from the\n // response we were provided.\n return getLroResponse(initialResponse);\n },\n sendPollRequest: async (path: string, pollOptions?: { abortSignal?: AbortSignalLike }) => {\n // This is the callback that is going to be called to poll the service\n // to get the latest status. We use the client provided and the polling path\n // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location\n // depending on the lro pattern that the service implements. If non is provided we default to the initial path.\n function abortListener(): void {\n abortController.abort();\n }\n const inputAbortSignal = pollOptions?.abortSignal;\n const abortSignal = abortController.signal;\n if (inputAbortSignal?.aborted) {\n abortController.abort();\n } else if (!abortSignal.aborted) {\n inputAbortSignal?.addEventListener(\"abort\", abortListener, {\n once: true,\n });\n }\n let response;\n try {\n response = await client\n .pathUnchecked(path ?? initialResponse.request.url)\n .get({ abortSignal });\n } finally {\n inputAbortSignal?.removeEventListener(\"abort\", abortListener);\n }\n const lroResponse = getLroResponse(response as TResult);\n lroResponse.rawResponse.headers[\"x-ms-original-url\"] = initialResponse.request.url;\n return lroResponse;\n },\n };\n\n const mergedOptions = {\n ...options,\n resolveOnUnsuccessful: options?.resolveOnUnsuccessful ?? true,\n };\n const httpPoller = createHttpPoller(poller, mergedOptions);\n const simplePoller: SimplePollerLike<OperationState<TResult>, TResult> = {\n isDone() {\n return httpPoller.isDone;\n },\n isStopped() {\n return abortController.signal.aborted;\n },\n getOperationState() {\n if (!httpPoller.operationState) {\n throw new Error(\n \"Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().\",\n );\n }\n return httpPoller.operationState;\n },\n getResult() {\n return httpPoller.result;\n },\n toString() {\n if (!httpPoller.operationState) {\n throw new Error(\n \"Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().\",\n );\n }\n return JSON.stringify({\n state: httpPoller.operationState,\n });\n },\n stopPolling() {\n abortController.abort();\n },\n onProgress: httpPoller.onProgress,\n poll: httpPoller.poll,\n pollUntilDone: httpPoller.pollUntilDone,\n serialize: httpPoller.serialize,\n submitted: httpPoller.submitted,\n };\n return simplePoller;\n}\n\n/**\n * Converts a Rest Client response to a response that the LRO implementation understands\n * @param response - a rest client http response\n * @returns - An LRO response that the LRO implementation understands\n */\nfunction getLroResponse<TResult extends HttpResponse>(\n response: TResult,\n): OperationResponse<TResult> {\n if (Number.isNaN(response.status)) {\n throw new TypeError(`Status code of the response is not a number. Value: ${response.status}`);\n }\n\n return {\n flatResponse: response,\n rawResponse: {\n ...response,\n statusCode: Number.parseInt(response.status),\n body: response.body,\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pollingHelper.js","sourceRoot":"","sources":["../../src/pollingHelper.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAmGlC,oDAuFC;AA/KD,8CAAmD;AAwF5C,KAAK,UAAU,oBAAoB,CACxC,MAAc,EACd,eAAwB,EACxB,UAAqE,EAAE;IAEvE,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;IAC9C,MAAM,MAAM,GAA8B;QACxC,kBAAkB,EAAE,KAAK,IAAI,EAAE;YAC7B,sGAAsG;YACtG,2FAA2F;YAC3F,6BAA6B;YAC7B,OAAO,cAAc,CAAC,eAAe,CAAC,CAAC;QACzC,CAAC;QACD,eAAe,EAAE,KAAK,EAAE,IAAY,EAAE,WAA+C,EAAE,EAAE;YACvF,sEAAsE;YACtE,4EAA4E;YAC5E,0JAA0J;YAC1J,+GAA+G;YAC/G,SAAS,aAAa;gBACpB,eAAe,CAAC,KAAK,EAAE,CAAC;YAC1B,CAAC;YACD,MAAM,gBAAgB,GAAG,WAAW,EAAE,WAAW,CAAC;YAClD,MAAM,WAAW,GAAG,eAAe,CAAC,MAAM,CAAC;YAC3C,IAAI,gBAAgB,EAA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CAAC;QACD,SAAS;YACP,OAAO,UAAU,CAAC,MAAM,CAAC;QAC3B,CAAC;QACD,QAAQ;YACN,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC;gBAC/B,MAAM,IAAI,KAAK,CACb,4IAA4I,CAC7I,CAAC;YACJ,CAAC;YACD,OAAO,IAAI,CAAC,SAAS,CAAC;gBACpB,KAAK,EAAE,UAAU,CAAC,cAAc;aACjC,CAAC,CAAC;QACL,CAAC;QACD,WAAW;YACT,eAAe,CAAC,KAAK,EAAE,CAAC;QAC1B,CAAC;QACD,UAAU,EAAE,UAAU,CAAC,UAAU;QACjC,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,SAAS,EAAE,UAAU,CAAC,SAAS;QAC/B,SAAS,EAAE,UAAU,CAAC,SAAS;KAChC,CAAC;IACF,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc,CACrB,QAAiB;IAEjB,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,SAAS,CAAC,uDAAuD,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAChG,CAAC;IAED,OAAO;QACL,YAAY,EAAE,QAAQ;QACtB,WAAW,EAAE;YACX,GAAG,QAAQ;YACX,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;YAC5C,IAAI,EAAE,QAAQ,CAAC,IAAI;SACpB;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Client, HttpResponse } from \"@azure-rest/core-client\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type {\n CancelOnProgress,\n CreateHttpPollerOptions,\n RunningOperation,\n OperationResponse,\n OperationState,\n} from \"@azure/core-lro\";\nimport { createHttpPoller } from \"@azure/core-lro\";\nimport type {\n CreateJob200Response,\n CreateJob201Response,\n CreateJobDefaultResponse,\n CreateJobLogicalResponse,\n} from \"./responses.js\";\n\n/**\n * A simple poller that can be used to poll a long running operation.\n */\nexport interface SimplePollerLike<TState extends OperationState<TResult>, TResult> {\n /**\n * Returns true if the poller has finished polling.\n */\n isDone(): boolean;\n /**\n * Returns the state of the operation.\n */\n getOperationState(): TState;\n /**\n * Returns the result value of the operation,\n * regardless of the state of the poller.\n * It can return undefined or an incomplete form of the final TResult value\n * depending on the implementation.\n */\n getResult(): TResult | undefined;\n /**\n * Returns a promise that will resolve once a single polling request finishes.\n * It does this by calling the update method of the Poller's operation.\n */\n poll(options?: { abortSignal?: AbortSignalLike }): Promise<TState>;\n /**\n * Returns a promise that will resolve once the underlying operation is completed.\n */\n pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }): Promise<TResult>;\n /**\n * Invokes the provided callback after each polling is completed,\n * sending the current state of the poller's operation.\n *\n * It returns a method that can be used to stop receiving updates on the given callback function.\n */\n onProgress(callback: (state: TState) => void): CancelOnProgress;\n\n /**\n * Returns a promise that could be used for serialized version of the poller's operation\n * by invoking the operation's serialize method.\n */\n serialize(): Promise<string>;\n\n /**\n * Wait the poller to be submitted.\n */\n submitted(): Promise<void>;\n\n /**\n * Returns a string representation of the poller's operation. Similar to serialize but returns a string.\n * @deprecated Use serialize() instead.\n */\n toString(): string;\n\n /**\n * Stops the poller from continuing to poll. Please note this will only stop the client-side polling\n * @deprecated Use abortSignal to stop polling instead.\n */\n stopPolling(): void;\n\n /**\n * Returns true if the poller is stopped.\n * @deprecated Use abortSignal status to track this instead.\n */\n isStopped(): boolean;\n}\n\n/**\n * Helper function that builds a Poller object to help polling a long running operation.\n * @param client - Client to use for sending the request to get additional pages.\n * @param initialResponse - The initial response.\n * @param options - Options to set a resume state or custom polling interval.\n * @returns - A poller object to poll for operation state updates and eventually get the final response.\n */\nexport async function getLongRunningPoller<\n TResult extends CreateJobLogicalResponse | CreateJobDefaultResponse,\n>(\n client: Client,\n initialResponse: CreateJob200Response | CreateJob201Response | CreateJobDefaultResponse,\n options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>,\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;\nexport async function getLongRunningPoller<TResult extends HttpResponse>(\n client: Client,\n initialResponse: TResult,\n options: CreateHttpPollerOptions<TResult, OperationState<TResult>> = {},\n): Promise<SimplePollerLike<OperationState<TResult>, TResult>> {\n const abortController = new AbortController();\n const poller: RunningOperation<TResult> = {\n sendInitialRequest: async () => {\n // In the case of Rest Clients we are building the LRO poller object from a response that's the reason\n // we are not triggering the initial request here, just extracting the information from the\n // response we were provided.\n return getLroResponse(initialResponse);\n },\n sendPollRequest: async (path: string, pollOptions?: { abortSignal?: AbortSignalLike }) => {\n // This is the callback that is going to be called to poll the service\n // to get the latest status. We use the client provided and the polling path\n // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location\n // depending on the lro pattern that the service implements. If non is provided we default to the initial path.\n function abortListener(): void {\n abortController.abort();\n }\n const inputAbortSignal = pollOptions?.abortSignal;\n const abortSignal = abortController.signal;\n if (inputAbortSignal?.aborted) {\n abortController.abort();\n } else if (!abortSignal.aborted) {\n inputAbortSignal?.addEventListener(\"abort\", abortListener, {\n once: true,\n });\n }\n let response;\n try {\n response = await client\n .pathUnchecked(path ?? initialResponse.request.url)\n .get({ abortSignal });\n } finally {\n inputAbortSignal?.removeEventListener(\"abort\", abortListener);\n }\n const lroResponse = getLroResponse(response as TResult);\n lroResponse.rawResponse.headers[\"x-ms-original-url\"] = initialResponse.request.url;\n return lroResponse;\n },\n };\n\n const mergedOptions = {\n ...options,\n resolveOnUnsuccessful: options?.resolveOnUnsuccessful ?? true,\n };\n const httpPoller = createHttpPoller(poller, mergedOptions);\n const simplePoller: SimplePollerLike<OperationState<TResult>, TResult> = {\n isDone() {\n return httpPoller.isDone;\n },\n isStopped() {\n return abortController.signal.aborted;\n },\n getOperationState() {\n if (!httpPoller.operationState) {\n throw new Error(\n \"Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().\",\n );\n }\n return httpPoller.operationState;\n },\n getResult() {\n return httpPoller.result;\n },\n toString() {\n if (!httpPoller.operationState) {\n throw new Error(\n \"Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().\",\n );\n }\n return JSON.stringify({\n state: httpPoller.operationState,\n });\n },\n stopPolling() {\n abortController.abort();\n },\n onProgress: httpPoller.onProgress,\n poll: httpPoller.poll,\n pollUntilDone: httpPoller.pollUntilDone,\n serialize: httpPoller.serialize,\n submitted: httpPoller.submitted,\n };\n return simplePoller;\n}\n\n/**\n * Converts a Rest Client response to a response that the LRO implementation understands\n * @param response - a rest client http response\n * @returns - An LRO response that the LRO implementation understands\n */\nfunction getLroResponse<TResult extends HttpResponse>(\n response: TResult,\n): OperationResponse<TResult> {\n if (Number.isNaN(response.status)) {\n throw new TypeError(`Status code of the response is not a number. Value: ${response.status}`);\n }\n\n return {\n flatResponse: response,\n rawResponse: {\n ...response,\n statusCode: Number.parseInt(response.status),\n body: response.body,\n },\n };\n}\n"]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
-
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
-
{
|
|
4
|
-
"tsdocVersion": "0.12",
|
|
5
|
-
"toolPackages": [
|
|
6
|
-
{
|
|
7
|
-
"packageName": "@microsoft/api-extractor",
|
|
8
|
-
"packageVersion": "7.52.
|
|
9
|
-
}
|
|
10
|
-
]
|
|
11
|
-
}
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.52.9"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
-
import { __rest } from "tslib";
|
|
4
3
|
import { getClient } from "@azure-rest/core-client";
|
|
5
4
|
import { logger } from "./logger.js";
|
|
6
5
|
/**
|
|
@@ -9,22 +8,25 @@ import { logger } from "./logger.js";
|
|
|
9
8
|
* @param credentials - uniquely identify client credential
|
|
10
9
|
* @param options - the parameter for all optional parameters
|
|
11
10
|
*/
|
|
12
|
-
export default function createClient(endpointParam, credentials,
|
|
13
|
-
|
|
14
|
-
var { apiVersion = "2024-10-01" } = _a, options = __rest(_a, ["apiVersion"]);
|
|
15
|
-
const endpointUrl = (_c = (_b = options.endpoint) !== null && _b !== void 0 ? _b : options.baseUrl) !== null && _c !== void 0 ? _c : `${endpointParam}/health-insights`;
|
|
11
|
+
export default function createClient(endpointParam, credentials, { apiVersion = "2024-10-01", ...options } = {}) {
|
|
12
|
+
const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}/health-insights`;
|
|
16
13
|
const userAgentInfo = `azsdk-js-health-insights-radiologyinsights-rest/2.0.0`;
|
|
17
14
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
18
15
|
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
|
19
16
|
: `${userAgentInfo}`;
|
|
20
|
-
const clientOptions =
|
|
17
|
+
const clientOptions = {
|
|
18
|
+
...options,
|
|
19
|
+
userAgentOptions: {
|
|
21
20
|
userAgentPrefix,
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
},
|
|
22
|
+
loggingOptions: {
|
|
23
|
+
logger: options.loggingOptions?.logger ?? logger.info,
|
|
24
|
+
},
|
|
25
|
+
credentials: {
|
|
26
|
+
scopes: options.credentials?.scopes ?? ["https://cognitiveservices.azure.com/.default"],
|
|
27
|
+
apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key",
|
|
28
|
+
},
|
|
29
|
+
};
|
|
28
30
|
const client = getClient(endpointUrl, credentials, clientOptions);
|
|
29
31
|
client.pipeline.removePolicy({ name: "ApiVersionPolicy" });
|
|
30
32
|
client.pipeline.addPolicy({
|
|
@@ -35,7 +37,7 @@ export default function createClient(endpointParam, credentials, _a = {}) {
|
|
|
35
37
|
const url = new URL(req.url);
|
|
36
38
|
if (!url.searchParams.get("api-version") && apiVersion) {
|
|
37
39
|
const newUrl = `${req.url}${Array.from(url.searchParams.keys()).length > 0 ? "&" : "?"}api-version=${apiVersion}`;
|
|
38
|
-
const newReq =
|
|
40
|
+
const newReq = { ...req, url: newUrl };
|
|
39
41
|
return next(newReq);
|
|
40
42
|
}
|
|
41
43
|
return next(req);
|