@azure-rest/communication-job-router 1.1.0-beta.2 → 1.1.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/LICENSE +21 -0
  3. package/dist/browser/azureCommunicationRoutingServiceClient.js +11 -10
  4. package/dist/browser/azureCommunicationRoutingServiceClient.js.map +1 -1
  5. package/dist/browser/isUnexpected.js +4 -5
  6. package/dist/browser/isUnexpected.js.map +1 -1
  7. package/dist/browser/paginateHelper.js +43 -73
  8. package/dist/browser/paginateHelper.js.map +1 -1
  9. package/dist/commonjs/azureCommunicationRoutingServiceClient.js +11 -10
  10. package/dist/commonjs/azureCommunicationRoutingServiceClient.js.map +1 -1
  11. package/dist/commonjs/isUnexpected.js +4 -5
  12. package/dist/commonjs/isUnexpected.js.map +1 -1
  13. package/dist/commonjs/paginateHelper.js +43 -73
  14. package/dist/commonjs/paginateHelper.js.map +1 -1
  15. package/dist/commonjs/tsdoc-metadata.json +11 -11
  16. package/dist/esm/azureCommunicationRoutingServiceClient.js +11 -10
  17. package/dist/esm/azureCommunicationRoutingServiceClient.js.map +1 -1
  18. package/dist/esm/isUnexpected.js +4 -5
  19. package/dist/esm/isUnexpected.js.map +1 -1
  20. package/dist/esm/paginateHelper.js +43 -73
  21. package/dist/esm/paginateHelper.js.map +1 -1
  22. package/dist/react-native/azureCommunicationRoutingServiceClient.js +11 -10
  23. package/dist/react-native/azureCommunicationRoutingServiceClient.js.map +1 -1
  24. package/dist/react-native/isUnexpected.js +4 -5
  25. package/dist/react-native/isUnexpected.js.map +1 -1
  26. package/dist/react-native/paginateHelper.js +43 -73
  27. package/dist/react-native/paginateHelper.js.map +1 -1
  28. package/package.json +38 -45
  29. package/review/communication-job-router-node.api.md +2598 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,51 @@
1
+ # Release History
2
+
3
+ ## 1.1.0-beta.3 (Unreleased)
4
+
5
+ ### Features Added
6
+
7
+ ### Breaking Changes
8
+
9
+ ### Bugs Fixed
10
+
11
+ ### Other Changes
12
+
13
+ ## 1.1.0-beta.2 (2025-02-10)
14
+
15
+ ### Features Added
16
+
17
+ - refresh @azure-rest/communication-job-router sdk
18
+
19
+ ## 1.1.0-beta.1 (2024-04-12)
20
+
21
+ ### Features Added
22
+
23
+ #### RouterWorker
24
+
25
+ - Added `MaxConcurrentOffers`
26
+
27
+ ## 1.0.0 (2023-11-01)
28
+
29
+ ### Features Added
30
+
31
+ This is the initial release of the @azure-rest version of Job Router SDK.
32
+ There was a previous preview SDK under a different package named @azure/communication-job-router which will be deprecated.
33
+
34
+ Using AzureCommunicationRoutingServiceClient:
35
+
36
+ - Upsert, get, list and delete DistributionPolicy.
37
+ - Upsert, get, list and delete RouterQueue.
38
+ - Upsert, get, list and delete ClassificationPolicy.
39
+ - Upsert, get, list and delete ExceptionPolicy.
40
+ - Upsert, get, list and delete RouterJob.
41
+ - RouterJob can be created and updated with different matching modes: QueueAndMatchMode, ScheduleAndSuspendMode and SuspendMode.
42
+ - Reclassify a RouterJob.
43
+ - Close a RouterJob.
44
+ - Complete a RouterJob.
45
+ - Cancel a RouterJob.
46
+ - Unassign a RouterJob.
47
+ - Get the position of a RouterJob in a queue.
48
+ - Upsert, get, list and delete RouterWorker.
49
+ - Accept an offer.
50
+ - Decline an offer.
51
+ - Get queue statistics.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Microsoft
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -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
  /**
@@ -8,19 +7,21 @@ import { logger } from "./logger.js";
8
7
  * @param endpointParam - Uri of your Communication resource
9
8
  * @param options - the parameter for all optional parameters
10
9
  */
11
- export default function createClient(endpointParam, _a = {}) {
12
- var _b, _c, _d, _e;
13
- var { apiVersion = "2024-01-18-preview" } = _a, options = __rest(_a, ["apiVersion"]);
14
- const endpointUrl = (_c = (_b = options.endpoint) !== null && _b !== void 0 ? _b : options.baseUrl) !== null && _c !== void 0 ? _c : `${endpointParam}`;
15
- const userAgentInfo = `azsdk-js-communication-job-router-rest/1.0.0-beta.1`;
10
+ export default function createClient(endpointParam, { apiVersion = "2024-01-18-preview", ...options } = {}) {
11
+ const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`;
12
+ const userAgentInfo = `azsdk-js-communication-job-router-rest/1.1.0-beta.3`;
16
13
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
17
14
  ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
18
15
  : `${userAgentInfo}`;
19
- options = Object.assign(Object.assign({}, options), { userAgentOptions: {
16
+ options = {
17
+ ...options,
18
+ userAgentOptions: {
20
19
  userAgentPrefix,
21
- }, loggingOptions: {
22
- logger: (_e = (_d = options.loggingOptions) === null || _d === void 0 ? void 0 : _d.logger) !== null && _e !== void 0 ? _e : logger.info,
23
- } });
20
+ },
21
+ loggingOptions: {
22
+ logger: options.loggingOptions?.logger ?? logger.info,
23
+ },
24
+ };
24
25
  const client = getClient(endpointUrl, options);
25
26
  client.pipeline.removePolicy({ name: "ApiVersionPolicy" });
26
27
  client.pipeline.addPolicy({
@@ -1 +1 @@
1
- {"version":3,"file":"azureCommunicationRoutingServiceClient.js","sourceRoot":"","sources":["../../src/azureCommunicationRoutingServiceClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AASrC;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,aAAqB,EACrB,KAGmD,EAAE;;QAHrD,EACE,UAAU,GAAG,oBAAoB,OAEkB,EADhD,OAAO,cAFZ,cAGC,CADW;IAGZ,MAAM,WAAW,GAAG,MAAA,MAAA,OAAO,CAAC,QAAQ,mCAAI,OAAO,CAAC,OAAO,mCAAI,GAAG,aAAa,EAAE,CAAC;IAC9E,MAAM,aAAa,GAAG,qDAAqD,CAAC;IAC5E,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,OAAO,mCACF,OAAO,KACV,gBAAgB,EAAE;YAChB,eAAe;SAChB,EACD,cAAc,EAAE;YACd,MAAM,EAAE,MAAA,MAAA,OAAO,CAAC,cAAc,0CAAE,MAAM,mCAAI,MAAM,CAAC,IAAI;SACtD,GACF,CAAC;IACF,MAAM,MAAM,GAAG,SAAS,CAAC,WAAW,EAAE,OAAO,CAA2C,CAAC;IAEzF,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAC3D,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;QACxB,IAAI,EAAE,wBAAwB;QAC9B,WAAW,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;YACzB,qDAAqD;YACrD,yEAAyE;YACzE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,UAAU,EAAE,CAAC;gBACvD,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,GAAG,GAClB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GACzD,eAAe,UAAU,EAAE,CAAC;YAC9B,CAAC;YACD,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 { AzureCommunicationRoutingServiceClient } from \"./clientDefinitions.js\";\n\n/** The optional parameters for the client */\nexport interface AzureCommunicationRoutingServiceClientOptions extends ClientOptions {\n /** The api version option of the client */\n apiVersion?: string;\n}\n\n/**\n * Initialize a new instance of `AzureCommunicationRoutingServiceClient`\n * @param endpointParam - Uri of your Communication resource\n * @param options - the parameter for all optional parameters\n */\nexport default function createClient(\n endpointParam: string,\n {\n apiVersion = \"2024-01-18-preview\",\n ...options\n }: AzureCommunicationRoutingServiceClientOptions = {},\n): AzureCommunicationRoutingServiceClient {\n const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`;\n const userAgentInfo = `azsdk-js-communication-job-router-rest/1.0.0-beta.1`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n options = {\n ...options,\n userAgentOptions: {\n userAgentPrefix,\n },\n loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info,\n },\n };\n const client = getClient(endpointUrl, options) as AzureCommunicationRoutingServiceClient;\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 req.url = `${req.url}${\n Array.from(url.searchParams.keys()).length > 0 ? \"&\" : \"?\"\n }api-version=${apiVersion}`;\n }\n return next(req);\n },\n });\n\n return client;\n}\n"]}
1
+ {"version":3,"file":"azureCommunicationRoutingServiceClient.js","sourceRoot":"","sources":["../../src/azureCommunicationRoutingServiceClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AASrC;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,aAAqB,EACrB,EACE,UAAU,GAAG,oBAAoB,EACjC,GAAG,OAAO,KACuC,EAAE;IAErD,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,OAAO,IAAI,GAAG,aAAa,EAAE,CAAC;IAC9E,MAAM,aAAa,GAAG,qDAAqD,CAAC;IAC5E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IT License.\n\nimport type { ClientOptions } from \"@azure-rest/core-client\";\nimport { getClient } from \"@azure-rest/core-client\";\nimport { logger } from \"./logger.js\";\nimport type { AzureCommunicationRoutingServiceClient } from \"./clientDefinitions.js\";\n\n/** The optional parameters for the client */\nexport interface AzureCommunicationRoutingServiceClientOptions extends ClientOptions {\n /** The api version option of the client */\n apiVersion?: string;\n}\n\n/**\n * Initialize a new instance of `AzureCommunicationRoutingServiceClient`\n * @param endpointParam - Uri of your Communication resource\n * @param options - the parameter for all optional parameters\n */\nexport default function createClient(\n endpointParam: string,\n {\n apiVersion = \"2024-01-18-preview\",\n ...options\n }: AzureCommunicationRoutingServiceClientOptions = {},\n): AzureCommunicationRoutingServiceClient {\n const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`;\n const userAgentInfo = `azsdk-js-communication-job-router-rest/1.1.0-beta.3`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n options = {\n ...options,\n userAgentOptions: {\n userAgentPrefix,\n },\n loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info,\n },\n };\n const client = getClient(endpointUrl, options) as AzureCommunicationRoutingServiceClient;\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 req.url = `${req.url}${\n Array.from(url.searchParams.keys()).length > 0 ? \"&\" : \"?\"\n }api-version=${apiVersion}`;\n }\n return next(req);\n },\n });\n\n return client;\n}\n"]}
@@ -37,7 +37,7 @@ const responseMap = {
37
37
  };
38
38
  export function isUnexpected(response) {
39
39
  const lroOriginal = response.headers["x-ms-original-url"];
40
- const url = new URL(lroOriginal !== null && lroOriginal !== void 0 ? lroOriginal : response.request.url);
40
+ const url = new URL(lroOriginal ?? response.request.url);
41
41
  const method = response.request.method;
42
42
  let pathDetails = responseMap[`${method} ${url.pathname}`];
43
43
  if (!pathDetails) {
@@ -46,7 +46,6 @@ export function isUnexpected(response) {
46
46
  return !pathDetails.includes(response.status);
47
47
  }
48
48
  function getParametrizedPathSuccess(method, path) {
49
- var _a, _b, _c, _d;
50
49
  const pathParts = path.split("/");
51
50
  // Traverse list to match the longest candidate
52
51
  // matchedLen: the length of candidate path
@@ -65,13 +64,13 @@ function getParametrizedPathSuccess(method, path) {
65
64
  // track if we have found a match to return the values found.
66
65
  let found = true;
67
66
  for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
68
- if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) && ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
69
- const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length;
67
+ if (candidateParts[i]?.startsWith("{") && candidateParts[i]?.indexOf("}") !== -1) {
68
+ const start = candidateParts[i].indexOf("}") + 1, end = candidateParts[i]?.length;
70
69
  // If the current part of the candidate is a "template" part
71
70
  // Try to use the suffix of pattern to match the path
72
71
  // {guid} ==> $
73
72
  // {guid}:export ==> :export$
74
- const isMatched = new RegExp(`${(_d = candidateParts[i]) === null || _d === void 0 ? void 0 : _d.slice(start, end)}`).test(pathParts[j] || "");
73
+ const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(pathParts[j] || "");
75
74
  if (!isMatched) {
76
75
  found = false;
77
76
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../src/isUnexpected.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AA6ElC,MAAM,WAAW,GAA6B;IAC5C,gEAAgE,EAAE,CAAC,KAAK,EAA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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;IACD,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 UpsertClassificationPolicy200Response,\n UpsertClassificationPolicy201Response,\n UpsertClassificationPolicyDefaultResponse,\n GetClassificationPolicy200Response,\n GetClassificationPolicyDefaultResponse,\n DeleteClassificationPolicy204Response,\n DeleteClassificationPolicyDefaultResponse,\n ListClassificationPolicies200Response,\n ListClassificationPoliciesDefaultResponse,\n UpsertDistributionPolicy200Response,\n UpsertDistributionPolicy201Response,\n UpsertDistributionPolicyDefaultResponse,\n GetDistributionPolicy200Response,\n GetDistributionPolicyDefaultResponse,\n DeleteDistributionPolicy204Response,\n DeleteDistributionPolicyDefaultResponse,\n ListDistributionPolicies200Response,\n ListDistributionPoliciesDefaultResponse,\n UpsertExceptionPolicy200Response,\n UpsertExceptionPolicy201Response,\n UpsertExceptionPolicyDefaultResponse,\n GetExceptionPolicy200Response,\n GetExceptionPolicyDefaultResponse,\n DeleteExceptionPolicy204Response,\n DeleteExceptionPolicyDefaultResponse,\n ListExceptionPolicies200Response,\n ListExceptionPoliciesDefaultResponse,\n UpsertQueue200Response,\n UpsertQueue201Response,\n UpsertQueueDefaultResponse,\n GetQueue200Response,\n GetQueueDefaultResponse,\n DeleteQueue204Response,\n DeleteQueueDefaultResponse,\n ListQueues200Response,\n ListQueuesDefaultResponse,\n UpsertJob200Response,\n UpsertJob201Response,\n UpsertJobDefaultResponse,\n GetJob200Response,\n GetJobDefaultResponse,\n DeleteJob204Response,\n DeleteJobDefaultResponse,\n Reclassify200Response,\n ReclassifyDefaultResponse,\n Cancel200Response,\n CancelDefaultResponse,\n Complete200Response,\n CompleteDefaultResponse,\n Close200Response,\n CloseDefaultResponse,\n ListJobs200Response,\n ListJobsDefaultResponse,\n GetInQueuePosition200Response,\n GetInQueuePositionDefaultResponse,\n Unassign200Response,\n UnassignDefaultResponse,\n Accept200Response,\n AcceptDefaultResponse,\n Decline200Response,\n DeclineDefaultResponse,\n GetQueueStatistics200Response,\n GetQueueStatisticsDefaultResponse,\n UpsertWorker200Response,\n UpsertWorker201Response,\n UpsertWorkerDefaultResponse,\n GetWorker200Response,\n GetWorkerDefaultResponse,\n DeleteWorker204Response,\n DeleteWorkerDefaultResponse,\n ListWorkers200Response,\n ListWorkersDefaultResponse,\n} from \"./responses.js\";\n\nconst responseMap: Record<string, string[]> = {\n \"PATCH /routing/classificationPolicies/{classificationPolicyId}\": [\"200\", \"201\"],\n \"GET /routing/classificationPolicies/{classificationPolicyId}\": [\"200\"],\n \"DELETE /routing/classificationPolicies/{classificationPolicyId}\": [\"204\"],\n \"GET /routing/classificationPolicies\": [\"200\"],\n \"PATCH /routing/distributionPolicies/{distributionPolicyId}\": [\"200\", \"201\"],\n \"GET /routing/distributionPolicies/{distributionPolicyId}\": [\"200\"],\n \"DELETE /routing/distributionPolicies/{distributionPolicyId}\": [\"204\"],\n \"GET /routing/distributionPolicies\": [\"200\"],\n \"PATCH /routing/exceptionPolicies/{exceptionPolicyId}\": [\"200\", \"201\"],\n \"GET /routing/exceptionPolicies/{exceptionPolicyId}\": [\"200\"],\n \"DELETE /routing/exceptionPolicies/{exceptionPolicyId}\": [\"204\"],\n \"GET /routing/exceptionPolicies\": [\"200\"],\n \"PATCH /routing/queues/{queueId}\": [\"200\", \"201\"],\n \"GET /routing/queues/{queueId}\": [\"200\"],\n \"DELETE /routing/queues/{queueId}\": [\"204\"],\n \"GET /routing/queues\": [\"200\"],\n \"PATCH /routing/jobs/{jobId}\": [\"200\", \"201\"],\n \"GET /routing/jobs/{jobId}\": [\"200\"],\n \"DELETE /routing/jobs/{jobId}\": [\"204\"],\n \"POST /routing/jobs/{jobId}:reclassify\": [\"200\"],\n \"POST /routing/jobs/{jobId}:cancel\": [\"200\"],\n \"POST /routing/jobs/{jobId}/assignments/{assignmentId}:complete\": [\"200\"],\n \"POST /routing/jobs/{jobId}/assignments/{assignmentId}:close\": [\"200\"],\n \"GET /routing/jobs\": [\"200\"],\n \"GET /routing/jobs/{jobId}/position\": [\"200\"],\n \"POST /routing/jobs/{jobId}/assignments/{assignmentId}:unassign\": [\"200\"],\n \"POST /routing/workers/{workerId}/offers/{offerId}:accept\": [\"200\"],\n \"POST /routing/workers/{workerId}/offers/{offerId}:decline\": [\"200\"],\n \"GET /routing/queues/{queueId}/statistics\": [\"200\"],\n \"PATCH /routing/workers/{workerId}\": [\"200\", \"201\"],\n \"GET /routing/workers/{workerId}\": [\"200\"],\n \"DELETE /routing/workers/{workerId}\": [\"204\"],\n \"GET /routing/workers\": [\"200\"],\n};\n\nexport function isUnexpected(\n response:\n | UpsertClassificationPolicy200Response\n | UpsertClassificationPolicy201Response\n | UpsertClassificationPolicyDefaultResponse,\n): response is UpsertClassificationPolicyDefaultResponse;\nexport function isUnexpected(\n response: GetClassificationPolicy200Response | GetClassificationPolicyDefaultResponse,\n): response is GetClassificationPolicyDefaultResponse;\nexport function isUnexpected(\n response: DeleteClassificationPolicy204Response | DeleteClassificationPolicyDefaultResponse,\n): response is DeleteClassificationPolicyDefaultResponse;\nexport function isUnexpected(\n response: ListClassificationPolicies200Response | ListClassificationPoliciesDefaultResponse,\n): response is ListClassificationPoliciesDefaultResponse;\nexport function isUnexpected(\n response:\n | UpsertDistributionPolicy200Response\n | UpsertDistributionPolicy201Response\n | UpsertDistributionPolicyDefaultResponse,\n): response is UpsertDistributionPolicyDefaultResponse;\nexport function isUnexpected(\n response: GetDistributionPolicy200Response | GetDistributionPolicyDefaultResponse,\n): response is GetDistributionPolicyDefaultResponse;\nexport function isUnexpected(\n response: DeleteDistributionPolicy204Response | DeleteDistributionPolicyDefaultResponse,\n): response is DeleteDistributionPolicyDefaultResponse;\nexport function isUnexpected(\n response: ListDistributionPolicies200Response | ListDistributionPoliciesDefaultResponse,\n): response is ListDistributionPoliciesDefaultResponse;\nexport function isUnexpected(\n response:\n | UpsertExceptionPolicy200Response\n | UpsertExceptionPolicy201Response\n | UpsertExceptionPolicyDefaultResponse,\n): response is UpsertExceptionPolicyDefaultResponse;\nexport function isUnexpected(\n response: GetExceptionPolicy200Response | GetExceptionPolicyDefaultResponse,\n): response is GetExceptionPolicyDefaultResponse;\nexport function isUnexpected(\n response: DeleteExceptionPolicy204Response | DeleteExceptionPolicyDefaultResponse,\n): response is DeleteExceptionPolicyDefaultResponse;\nexport function isUnexpected(\n response: ListExceptionPolicies200Response | ListExceptionPoliciesDefaultResponse,\n): response is ListExceptionPoliciesDefaultResponse;\nexport function isUnexpected(\n response: UpsertQueue200Response | UpsertQueue201Response | UpsertQueueDefaultResponse,\n): response is UpsertQueueDefaultResponse;\nexport function isUnexpected(\n response: GetQueue200Response | GetQueueDefaultResponse,\n): response is GetQueueDefaultResponse;\nexport function isUnexpected(\n response: DeleteQueue204Response | DeleteQueueDefaultResponse,\n): response is DeleteQueueDefaultResponse;\nexport function isUnexpected(\n response: ListQueues200Response | ListQueuesDefaultResponse,\n): response is ListQueuesDefaultResponse;\nexport function isUnexpected(\n response: UpsertJob200Response | UpsertJob201Response | UpsertJobDefaultResponse,\n): response is UpsertJobDefaultResponse;\nexport function isUnexpected(\n response: GetJob200Response | GetJobDefaultResponse,\n): response is GetJobDefaultResponse;\nexport function isUnexpected(\n response: DeleteJob204Response | DeleteJobDefaultResponse,\n): response is DeleteJobDefaultResponse;\nexport function isUnexpected(\n response: Reclassify200Response | ReclassifyDefaultResponse,\n): response is ReclassifyDefaultResponse;\nexport function isUnexpected(\n response: Cancel200Response | CancelDefaultResponse,\n): response is CancelDefaultResponse;\nexport function isUnexpected(\n response: Complete200Response | CompleteDefaultResponse,\n): response is CompleteDefaultResponse;\nexport function isUnexpected(\n response: Close200Response | CloseDefaultResponse,\n): response is CloseDefaultResponse;\nexport function isUnexpected(\n response: ListJobs200Response | ListJobsDefaultResponse,\n): response is ListJobsDefaultResponse;\nexport function isUnexpected(\n response: GetInQueuePosition200Response | GetInQueuePositionDefaultResponse,\n): response is GetInQueuePositionDefaultResponse;\nexport function isUnexpected(\n response: Unassign200Response | UnassignDefaultResponse,\n): response is UnassignDefaultResponse;\nexport function isUnexpected(\n response: Accept200Response | AcceptDefaultResponse,\n): response is AcceptDefaultResponse;\nexport function isUnexpected(\n response: Decline200Response | DeclineDefaultResponse,\n): response is DeclineDefaultResponse;\nexport function isUnexpected(\n response: GetQueueStatistics200Response | GetQueueStatisticsDefaultResponse,\n): response is GetQueueStatisticsDefaultResponse;\nexport function isUnexpected(\n response: UpsertWorker200Response | UpsertWorker201Response | UpsertWorkerDefaultResponse,\n): response is UpsertWorkerDefaultResponse;\nexport function isUnexpected(\n response: GetWorker200Response | GetWorkerDefaultResponse,\n): response is GetWorkerDefaultResponse;\nexport function isUnexpected(\n response: DeleteWorker204Response | DeleteWorkerDefaultResponse,\n): response is DeleteWorkerDefaultResponse;\nexport function isUnexpected(\n response: ListWorkers200Response | ListWorkersDefaultResponse,\n): response is ListWorkersDefaultResponse;\nexport function isUnexpected(\n response:\n | UpsertClassificationPolicy200Response\n | UpsertClassificationPolicy201Response\n | UpsertClassificationPolicyDefaultResponse\n | GetClassificationPolicy200Response\n | GetClassificationPolicyDefaultResponse\n | DeleteClassificationPolicy204Response\n | DeleteClassificationPolicyDefaultResponse\n | ListClassificationPolicies200Response\n | ListClassificationPoliciesDefaultResponse\n | UpsertDistributionPolicy200Response\n | UpsertDistributionPolicy201Response\n | UpsertDistributionPolicyDefaultResponse\n | GetDistributionPolicy200Response\n | GetDistributionPolicyDefaultResponse\n | DeleteDistributionPolicy204Response\n | DeleteDistributionPolicyDefaultResponse\n | ListDistributionPolicies200Response\n | ListDistributionPoliciesDefaultResponse\n | UpsertExceptionPolicy200Response\n | UpsertExceptionPolicy201Response\n | UpsertExceptionPolicyDefaultResponse\n | GetExceptionPolicy200Response\n | GetExceptionPolicyDefaultResponse\n | DeleteExceptionPolicy204Response\n | DeleteExceptionPolicyDefaultResponse\n | ListExceptionPolicies200Response\n | ListExceptionPoliciesDefaultResponse\n | UpsertQueue200Response\n | UpsertQueue201Response\n | UpsertQueueDefaultResponse\n | GetQueue200Response\n | GetQueueDefaultResponse\n | DeleteQueue204Response\n | DeleteQueueDefaultResponse\n | ListQueues200Response\n | ListQueuesDefaultResponse\n | UpsertJob200Response\n | UpsertJob201Response\n | UpsertJobDefaultResponse\n | GetJob200Response\n | GetJobDefaultResponse\n | DeleteJob204Response\n | DeleteJobDefaultResponse\n | Reclassify200Response\n | ReclassifyDefaultResponse\n | Cancel200Response\n | CancelDefaultResponse\n | Complete200Response\n | CompleteDefaultResponse\n | Close200Response\n | CloseDefaultResponse\n | ListJobs200Response\n | ListJobsDefaultResponse\n | GetInQueuePosition200Response\n | GetInQueuePositionDefaultResponse\n | Unassign200Response\n | UnassignDefaultResponse\n | Accept200Response\n | AcceptDefaultResponse\n | Decline200Response\n | DeclineDefaultResponse\n | GetQueueStatistics200Response\n | GetQueueStatisticsDefaultResponse\n | UpsertWorker200Response\n | UpsertWorker201Response\n | UpsertWorkerDefaultResponse\n | GetWorker200Response\n | GetWorkerDefaultResponse\n | DeleteWorker204Response\n | DeleteWorkerDefaultResponse\n | ListWorkers200Response\n | ListWorkersDefaultResponse,\n): response is\n | UpsertClassificationPolicyDefaultResponse\n | GetClassificationPolicyDefaultResponse\n | DeleteClassificationPolicyDefaultResponse\n | ListClassificationPoliciesDefaultResponse\n | UpsertDistributionPolicyDefaultResponse\n | GetDistributionPolicyDefaultResponse\n | DeleteDistributionPolicyDefaultResponse\n | ListDistributionPoliciesDefaultResponse\n | UpsertExceptionPolicyDefaultResponse\n | GetExceptionPolicyDefaultResponse\n | DeleteExceptionPolicyDefaultResponse\n | ListExceptionPoliciesDefaultResponse\n | UpsertQueueDefaultResponse\n | GetQueueDefaultResponse\n | DeleteQueueDefaultResponse\n | ListQueuesDefaultResponse\n | UpsertJobDefaultResponse\n | GetJobDefaultResponse\n | DeleteJobDefaultResponse\n | ReclassifyDefaultResponse\n | CancelDefaultResponse\n | CompleteDefaultResponse\n | CloseDefaultResponse\n | ListJobsDefaultResponse\n | GetInQueuePositionDefaultResponse\n | UnassignDefaultResponse\n | AcceptDefaultResponse\n | DeclineDefaultResponse\n | GetQueueStatisticsDefaultResponse\n | UpsertWorkerDefaultResponse\n | GetWorkerDefaultResponse\n | DeleteWorkerDefaultResponse\n | ListWorkersDefaultResponse {\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 return matchedValue;\n}\n\nfunction getPathFromMapKey(mapKey: string): string {\n const pathStart = mapKey.indexOf(\"/\");\n return mapKey.slice(pathStart);\n}\n"]}
1
+ {"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../src/isUnexpected.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AA6ElC,MAAM,WAAW,GAA6B;IAC5C,gEAAgE,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;IAChF,8DAA8D,EAAE,CAAC,KAAK,CAAC;IACvE,iEAAiE,EAAE,CAAC,KAAK,CAAC;IAC1E,qCAAqC,EAAE,CAAC,KAAK,CAAC;IAC9C,4DAA4D,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;IAC5E,0DAA0D,EAAE,CAAC,KAAK,CAAC;IACnE,6DAA6D,EAAE,CAAC,KAAK,CAAC;IACtE,mCAAmC,EAAE,CAAC,KAAK,CAAC;IAC5C,sDAAsD,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;IACtE,oDAAoD,EAAE,CAAC,KAAK,CAAC;IAC7D,uDAAuD,EAAE,CAAC,KAAK,CAAC;IAChE,gCAAgC,EAAE,CAAC,KAAK,CAAC;IACzC,iCAAiC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;IACjD,+BAA+B,EA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AAC,GAAG,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;IACD,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 UpsertClassificationPolicy200Response,\n UpsertClassificationPolicy201Response,\n UpsertClassificationPolicyDefaultResponse,\n GetClassificationPolicy200Response,\n GetClassificationPolicyDefaultResponse,\n DeleteClassificationPolicy204Response,\n DeleteClassificationPolicyDefaultResponse,\n ListClassificationPolicies200Response,\n ListClassificationPoliciesDefaultResponse,\n UpsertDistributionPolicy200Response,\n UpsertDistributionPolicy201Response,\n UpsertDistributionPolicyDefaultResponse,\n GetDistributionPolicy200Response,\n GetDistributionPolicyDefaultResponse,\n DeleteDistributionPolicy204Response,\n DeleteDistributionPolicyDefaultResponse,\n ListDistributionPolicies200Response,\n ListDistributionPoliciesDefaultResponse,\n UpsertExceptionPolicy200Response,\n UpsertExceptionPolicy201Response,\n UpsertExceptionPolicyDefaultResponse,\n GetExceptionPolicy200Response,\n GetExceptionPolicyDefaultResponse,\n DeleteExceptionPolicy204Response,\n DeleteExceptionPolicyDefaultResponse,\n ListExceptionPolicies200Response,\n ListExceptionPoliciesDefaultResponse,\n UpsertQueue200Response,\n UpsertQueue201Response,\n UpsertQueueDefaultResponse,\n GetQueue200Response,\n GetQueueDefaultResponse,\n DeleteQueue204Response,\n DeleteQueueDefaultResponse,\n ListQueues200Response,\n ListQueuesDefaultResponse,\n UpsertJob200Response,\n UpsertJob201Response,\n UpsertJobDefaultResponse,\n GetJob200Response,\n GetJobDefaultResponse,\n DeleteJob204Response,\n DeleteJobDefaultResponse,\n Reclassify200Response,\n ReclassifyDefaultResponse,\n Cancel200Response,\n CancelDefaultResponse,\n Complete200Response,\n CompleteDefaultResponse,\n Close200Response,\n CloseDefaultResponse,\n ListJobs200Response,\n ListJobsDefaultResponse,\n GetInQueuePosition200Response,\n GetInQueuePositionDefaultResponse,\n Unassign200Response,\n UnassignDefaultResponse,\n Accept200Response,\n AcceptDefaultResponse,\n Decline200Response,\n DeclineDefaultResponse,\n GetQueueStatistics200Response,\n GetQueueStatisticsDefaultResponse,\n UpsertWorker200Response,\n UpsertWorker201Response,\n UpsertWorkerDefaultResponse,\n GetWorker200Response,\n GetWorkerDefaultResponse,\n DeleteWorker204Response,\n DeleteWorkerDefaultResponse,\n ListWorkers200Response,\n ListWorkersDefaultResponse,\n} from \"./responses.js\";\n\nconst responseMap: Record<string, string[]> = {\n \"PATCH /routing/classificationPolicies/{classificationPolicyId}\": [\"200\", \"201\"],\n \"GET /routing/classificationPolicies/{classificationPolicyId}\": [\"200\"],\n \"DELETE /routing/classificationPolicies/{classificationPolicyId}\": [\"204\"],\n \"GET /routing/classificationPolicies\": [\"200\"],\n \"PATCH /routing/distributionPolicies/{distributionPolicyId}\": [\"200\", \"201\"],\n \"GET /routing/distributionPolicies/{distributionPolicyId}\": [\"200\"],\n \"DELETE /routing/distributionPolicies/{distributionPolicyId}\": [\"204\"],\n \"GET /routing/distributionPolicies\": [\"200\"],\n \"PATCH /routing/exceptionPolicies/{exceptionPolicyId}\": [\"200\", \"201\"],\n \"GET /routing/exceptionPolicies/{exceptionPolicyId}\": [\"200\"],\n \"DELETE /routing/exceptionPolicies/{exceptionPolicyId}\": [\"204\"],\n \"GET /routing/exceptionPolicies\": [\"200\"],\n \"PATCH /routing/queues/{queueId}\": [\"200\", \"201\"],\n \"GET /routing/queues/{queueId}\": [\"200\"],\n \"DELETE /routing/queues/{queueId}\": [\"204\"],\n \"GET /routing/queues\": [\"200\"],\n \"PATCH /routing/jobs/{jobId}\": [\"200\", \"201\"],\n \"GET /routing/jobs/{jobId}\": [\"200\"],\n \"DELETE /routing/jobs/{jobId}\": [\"204\"],\n \"POST /routing/jobs/{jobId}:reclassify\": [\"200\"],\n \"POST /routing/jobs/{jobId}:cancel\": [\"200\"],\n \"POST /routing/jobs/{jobId}/assignments/{assignmentId}:complete\": [\"200\"],\n \"POST /routing/jobs/{jobId}/assignments/{assignmentId}:close\": [\"200\"],\n \"GET /routing/jobs\": [\"200\"],\n \"GET /routing/jobs/{jobId}/position\": [\"200\"],\n \"POST /routing/jobs/{jobId}/assignments/{assignmentId}:unassign\": [\"200\"],\n \"POST /routing/workers/{workerId}/offers/{offerId}:accept\": [\"200\"],\n \"POST /routing/workers/{workerId}/offers/{offerId}:decline\": [\"200\"],\n \"GET /routing/queues/{queueId}/statistics\": [\"200\"],\n \"PATCH /routing/workers/{workerId}\": [\"200\", \"201\"],\n \"GET /routing/workers/{workerId}\": [\"200\"],\n \"DELETE /routing/workers/{workerId}\": [\"204\"],\n \"GET /routing/workers\": [\"200\"],\n};\n\nexport function isUnexpected(\n response:\n | UpsertClassificationPolicy200Response\n | UpsertClassificationPolicy201Response\n | UpsertClassificationPolicyDefaultResponse,\n): response is UpsertClassificationPolicyDefaultResponse;\nexport function isUnexpected(\n response: GetClassificationPolicy200Response | GetClassificationPolicyDefaultResponse,\n): response is GetClassificationPolicyDefaultResponse;\nexport function isUnexpected(\n response: DeleteClassificationPolicy204Response | DeleteClassificationPolicyDefaultResponse,\n): response is DeleteClassificationPolicyDefaultResponse;\nexport function isUnexpected(\n response: ListClassificationPolicies200Response | ListClassificationPoliciesDefaultResponse,\n): response is ListClassificationPoliciesDefaultResponse;\nexport function isUnexpected(\n response:\n | UpsertDistributionPolicy200Response\n | UpsertDistributionPolicy201Response\n | UpsertDistributionPolicyDefaultResponse,\n): response is UpsertDistributionPolicyDefaultResponse;\nexport function isUnexpected(\n response: GetDistributionPolicy200Response | GetDistributionPolicyDefaultResponse,\n): response is GetDistributionPolicyDefaultResponse;\nexport function isUnexpected(\n response: DeleteDistributionPolicy204Response | DeleteDistributionPolicyDefaultResponse,\n): response is DeleteDistributionPolicyDefaultResponse;\nexport function isUnexpected(\n response: ListDistributionPolicies200Response | ListDistributionPoliciesDefaultResponse,\n): response is ListDistributionPoliciesDefaultResponse;\nexport function isUnexpected(\n response:\n | UpsertExceptionPolicy200Response\n | UpsertExceptionPolicy201Response\n | UpsertExceptionPolicyDefaultResponse,\n): response is UpsertExceptionPolicyDefaultResponse;\nexport function isUnexpected(\n response: GetExceptionPolicy200Response | GetExceptionPolicyDefaultResponse,\n): response is GetExceptionPolicyDefaultResponse;\nexport function isUnexpected(\n response: DeleteExceptionPolicy204Response | DeleteExceptionPolicyDefaultResponse,\n): response is DeleteExceptionPolicyDefaultResponse;\nexport function isUnexpected(\n response: ListExceptionPolicies200Response | ListExceptionPoliciesDefaultResponse,\n): response is ListExceptionPoliciesDefaultResponse;\nexport function isUnexpected(\n response: UpsertQueue200Response | UpsertQueue201Response | UpsertQueueDefaultResponse,\n): response is UpsertQueueDefaultResponse;\nexport function isUnexpected(\n response: GetQueue200Response | GetQueueDefaultResponse,\n): response is GetQueueDefaultResponse;\nexport function isUnexpected(\n response: DeleteQueue204Response | DeleteQueueDefaultResponse,\n): response is DeleteQueueDefaultResponse;\nexport function isUnexpected(\n response: ListQueues200Response | ListQueuesDefaultResponse,\n): response is ListQueuesDefaultResponse;\nexport function isUnexpected(\n response: UpsertJob200Response | UpsertJob201Response | UpsertJobDefaultResponse,\n): response is UpsertJobDefaultResponse;\nexport function isUnexpected(\n response: GetJob200Response | GetJobDefaultResponse,\n): response is GetJobDefaultResponse;\nexport function isUnexpected(\n response: DeleteJob204Response | DeleteJobDefaultResponse,\n): response is DeleteJobDefaultResponse;\nexport function isUnexpected(\n response: Reclassify200Response | ReclassifyDefaultResponse,\n): response is ReclassifyDefaultResponse;\nexport function isUnexpected(\n response: Cancel200Response | CancelDefaultResponse,\n): response is CancelDefaultResponse;\nexport function isUnexpected(\n response: Complete200Response | CompleteDefaultResponse,\n): response is CompleteDefaultResponse;\nexport function isUnexpected(\n response: Close200Response | CloseDefaultResponse,\n): response is CloseDefaultResponse;\nexport function isUnexpected(\n response: ListJobs200Response | ListJobsDefaultResponse,\n): response is ListJobsDefaultResponse;\nexport function isUnexpected(\n response: GetInQueuePosition200Response | GetInQueuePositionDefaultResponse,\n): response is GetInQueuePositionDefaultResponse;\nexport function isUnexpected(\n response: Unassign200Response | UnassignDefaultResponse,\n): response is UnassignDefaultResponse;\nexport function isUnexpected(\n response: Accept200Response | AcceptDefaultResponse,\n): response is AcceptDefaultResponse;\nexport function isUnexpected(\n response: Decline200Response | DeclineDefaultResponse,\n): response is DeclineDefaultResponse;\nexport function isUnexpected(\n response: GetQueueStatistics200Response | GetQueueStatisticsDefaultResponse,\n): response is GetQueueStatisticsDefaultResponse;\nexport function isUnexpected(\n response: UpsertWorker200Response | UpsertWorker201Response | UpsertWorkerDefaultResponse,\n): response is UpsertWorkerDefaultResponse;\nexport function isUnexpected(\n response: GetWorker200Response | GetWorkerDefaultResponse,\n): response is GetWorkerDefaultResponse;\nexport function isUnexpected(\n response: DeleteWorker204Response | DeleteWorkerDefaultResponse,\n): response is DeleteWorkerDefaultResponse;\nexport function isUnexpected(\n response: ListWorkers200Response | ListWorkersDefaultResponse,\n): response is ListWorkersDefaultResponse;\nexport function isUnexpected(\n response:\n | UpsertClassificationPolicy200Response\n | UpsertClassificationPolicy201Response\n | UpsertClassificationPolicyDefaultResponse\n | GetClassificationPolicy200Response\n | GetClassificationPolicyDefaultResponse\n | DeleteClassificationPolicy204Response\n | DeleteClassificationPolicyDefaultResponse\n | ListClassificationPolicies200Response\n | ListClassificationPoliciesDefaultResponse\n | UpsertDistributionPolicy200Response\n | UpsertDistributionPolicy201Response\n | UpsertDistributionPolicyDefaultResponse\n | GetDistributionPolicy200Response\n | GetDistributionPolicyDefaultResponse\n | DeleteDistributionPolicy204Response\n | DeleteDistributionPolicyDefaultResponse\n | ListDistributionPolicies200Response\n | ListDistributionPoliciesDefaultResponse\n | UpsertExceptionPolicy200Response\n | UpsertExceptionPolicy201Response\n | UpsertExceptionPolicyDefaultResponse\n | GetExceptionPolicy200Response\n | GetExceptionPolicyDefaultResponse\n | DeleteExceptionPolicy204Response\n | DeleteExceptionPolicyDefaultResponse\n | ListExceptionPolicies200Response\n | ListExceptionPoliciesDefaultResponse\n | UpsertQueue200Response\n | UpsertQueue201Response\n | UpsertQueueDefaultResponse\n | GetQueue200Response\n | GetQueueDefaultResponse\n | DeleteQueue204Response\n | DeleteQueueDefaultResponse\n | ListQueues200Response\n | ListQueuesDefaultResponse\n | UpsertJob200Response\n | UpsertJob201Response\n | UpsertJobDefaultResponse\n | GetJob200Response\n | GetJobDefaultResponse\n | DeleteJob204Response\n | DeleteJobDefaultResponse\n | Reclassify200Response\n | ReclassifyDefaultResponse\n | Cancel200Response\n | CancelDefaultResponse\n | Complete200Response\n | CompleteDefaultResponse\n | Close200Response\n | CloseDefaultResponse\n | ListJobs200Response\n | ListJobsDefaultResponse\n | GetInQueuePosition200Response\n | GetInQueuePositionDefaultResponse\n | Unassign200Response\n | UnassignDefaultResponse\n | Accept200Response\n | AcceptDefaultResponse\n | Decline200Response\n | DeclineDefaultResponse\n | GetQueueStatistics200Response\n | GetQueueStatisticsDefaultResponse\n | UpsertWorker200Response\n | UpsertWorker201Response\n | UpsertWorkerDefaultResponse\n | GetWorker200Response\n | GetWorkerDefaultResponse\n | DeleteWorker204Response\n | DeleteWorkerDefaultResponse\n | ListWorkers200Response\n | ListWorkersDefaultResponse,\n): response is\n | UpsertClassificationPolicyDefaultResponse\n | GetClassificationPolicyDefaultResponse\n | DeleteClassificationPolicyDefaultResponse\n | ListClassificationPoliciesDefaultResponse\n | UpsertDistributionPolicyDefaultResponse\n | GetDistributionPolicyDefaultResponse\n | DeleteDistributionPolicyDefaultResponse\n | ListDistributionPoliciesDefaultResponse\n | UpsertExceptionPolicyDefaultResponse\n | GetExceptionPolicyDefaultResponse\n | DeleteExceptionPolicyDefaultResponse\n | ListExceptionPoliciesDefaultResponse\n | UpsertQueueDefaultResponse\n | GetQueueDefaultResponse\n | DeleteQueueDefaultResponse\n | ListQueuesDefaultResponse\n | UpsertJobDefaultResponse\n | GetJobDefaultResponse\n | DeleteJobDefaultResponse\n | ReclassifyDefaultResponse\n | CancelDefaultResponse\n | CompleteDefaultResponse\n | CloseDefaultResponse\n | ListJobsDefaultResponse\n | GetInQueuePositionDefaultResponse\n | UnassignDefaultResponse\n | AcceptDefaultResponse\n | DeclineDefaultResponse\n | GetQueueStatisticsDefaultResponse\n | UpsertWorkerDefaultResponse\n | GetWorkerDefaultResponse\n | DeleteWorkerDefaultResponse\n | ListWorkersDefaultResponse {\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 return matchedValue;\n}\n\nfunction getPathFromMapKey(mapKey: string): string {\n const pathStart = mapKey.indexOf(\"/\");\n return mapKey.slice(pathStart);\n}\n"]}
@@ -1,6 +1,5 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
- import { __asyncDelegator, __asyncGenerator, __asyncValues, __await } from "tslib";
4
3
  import { createRestError } from "@azure-rest/core-client";
5
4
  /**
6
5
  * returns an async iterator that iterates over results. It also has a `byPage`
@@ -10,7 +9,6 @@ import { createRestError } from "@azure-rest/core-client";
10
9
  * @returns a paged async iterator that iterates over results.
11
10
  */
12
11
  function getPagedAsyncIterator(pagedResult) {
13
- var _a;
14
12
  const iter = getItemAsyncIterator(pagedResult);
15
13
  return {
16
14
  next() {
@@ -19,85 +17,57 @@ function getPagedAsyncIterator(pagedResult) {
19
17
  [Symbol.asyncIterator]() {
20
18
  return this;
21
19
  },
22
- byPage: (_a = pagedResult === null || pagedResult === void 0 ? void 0 : pagedResult.byPage) !== null && _a !== void 0 ? _a : ((settings) => {
23
- const { continuationToken } = settings !== null && settings !== void 0 ? settings : {};
24
- return getPageAsyncIterator(pagedResult, {
25
- pageLink: continuationToken,
26
- });
27
- }),
20
+ byPage: pagedResult?.byPage ??
21
+ ((settings) => {
22
+ const { continuationToken } = settings ?? {};
23
+ return getPageAsyncIterator(pagedResult, {
24
+ pageLink: continuationToken,
25
+ });
26
+ }),
28
27
  };
29
28
  }
30
- function getItemAsyncIterator(pagedResult) {
31
- return __asyncGenerator(this, arguments, function* getItemAsyncIterator_1() {
32
- var _a, e_1, _b, _c, _d, e_2, _e, _f;
33
- const pages = getPageAsyncIterator(pagedResult);
34
- const firstVal = yield __await(pages.next());
35
- // if the result does not have an array shape, i.e. TPage = TElement, then we return it as is
36
- if (!Array.isArray(firstVal.value)) {
37
- // can extract elements from this page
38
- const { toElements } = pagedResult;
39
- if (toElements) {
40
- yield __await(yield* __asyncDelegator(__asyncValues(toElements(firstVal.value))));
41
- try {
42
- for (var _g = true, pages_1 = __asyncValues(pages), pages_1_1; pages_1_1 = yield __await(pages_1.next()), _a = pages_1_1.done, !_a; _g = true) {
43
- _c = pages_1_1.value;
44
- _g = false;
45
- const page = _c;
46
- yield __await(yield* __asyncDelegator(__asyncValues(toElements(page))));
47
- }
48
- }
49
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
50
- finally {
51
- try {
52
- if (!_g && !_a && (_b = pages_1.return)) yield __await(_b.call(pages_1));
53
- }
54
- finally { if (e_1) throw e_1.error; }
55
- }
56
- }
57
- else {
58
- yield yield __await(firstVal.value);
59
- // `pages` is of type `AsyncIterableIterator<TPage>` but TPage = TElement in this case
60
- yield __await(yield* __asyncDelegator(__asyncValues(pages)));
29
+ async function* getItemAsyncIterator(pagedResult) {
30
+ const pages = getPageAsyncIterator(pagedResult);
31
+ const firstVal = await pages.next();
32
+ // if the result does not have an array shape, i.e. TPage = TElement, then we return it as is
33
+ if (!Array.isArray(firstVal.value)) {
34
+ // can extract elements from this page
35
+ const { toElements } = pagedResult;
36
+ if (toElements) {
37
+ yield* toElements(firstVal.value);
38
+ for await (const page of pages) {
39
+ yield* toElements(page);
61
40
  }
62
41
  }
63
42
  else {
64
- yield __await(yield* __asyncDelegator(__asyncValues(firstVal.value)));
65
- try {
66
- for (var _h = true, pages_2 = __asyncValues(pages), pages_2_1; pages_2_1 = yield __await(pages_2.next()), _d = pages_2_1.done, !_d; _h = true) {
67
- _f = pages_2_1.value;
68
- _h = false;
69
- const page = _f;
70
- // pages is of type `AsyncIterableIterator<TPage>` so `page` is of type `TPage`. In this branch,
71
- // it must be the case that `TPage = TElement[]`
72
- yield __await(yield* __asyncDelegator(__asyncValues(page)));
73
- }
74
- }
75
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
76
- finally {
77
- try {
78
- if (!_h && !_d && (_e = pages_2.return)) yield __await(_e.call(pages_2));
79
- }
80
- finally { if (e_2) throw e_2.error; }
81
- }
43
+ yield firstVal.value;
44
+ // `pages` is of type `AsyncIterableIterator<TPage>` but TPage = TElement in this case
45
+ yield* pages;
46
+ }
47
+ }
48
+ else {
49
+ yield* firstVal.value;
50
+ for await (const page of pages) {
51
+ // pages is of type `AsyncIterableIterator<TPage>` so `page` is of type `TPage`. In this branch,
52
+ // it must be the case that `TPage = TElement[]`
53
+ yield* page;
82
54
  }
83
- });
55
+ }
84
56
  }
85
- function getPageAsyncIterator(pagedResult_1) {
86
- return __asyncGenerator(this, arguments, function* getPageAsyncIterator_1(pagedResult, options = {}) {
87
- const { pageLink } = options;
88
- let response = yield __await(pagedResult.getPage(pageLink !== null && pageLink !== void 0 ? pageLink : pagedResult.firstPageLink));
57
+ async function* getPageAsyncIterator(pagedResult, options = {}) {
58
+ const { pageLink } = options;
59
+ let response = await pagedResult.getPage(pageLink ?? pagedResult.firstPageLink);
60
+ if (!response) {
61
+ return;
62
+ }
63
+ yield response.page;
64
+ while (response.nextPageLink) {
65
+ response = await pagedResult.getPage(response.nextPageLink);
89
66
  if (!response) {
90
- return yield __await(void 0);
67
+ return;
91
68
  }
92
- yield yield __await(response.page);
93
- while (response.nextPageLink) {
94
- response = yield __await(pagedResult.getPage(response.nextPageLink));
95
- if (!response) {
96
- return yield __await(void 0);
97
- }
98
- yield yield __await(response.page);
99
- }
100
- });
69
+ yield response.page;
70
+ }
101
71
  }
102
72
  /**
103
73
  * Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension
@@ -153,7 +123,7 @@ function getElements(body, itemName) {
153
123
  if (!Array.isArray(value)) {
154
124
  throw new Error(`Couldn't paginate response\n Body doesn't contain an array property with name: ${itemName}`);
155
125
  }
156
- return value !== null && value !== void 0 ? value : [];
126
+ return value ?? [];
157
127
  }
158
128
  /**
159
129
  * Checks if a request failed
@@ -1 +1 @@
1
- {"version":3,"file":"paginateHelper.js","sourceRoot":"","sources":["../../src/paginateHelper.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAGlC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D;;;;;;GAMG;AACH,SAAS,qBAAqB,CAM5B,WAAqD;;IAErD,MAAM,IAAI,GAAG,oBAAoB,CAAwC,WAAW,CAAC,CAAC;IACtF,OAAO;QACL,IAAI;YACF,OAAO,IAAI,CAAC,I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,CAAC,QAAQ,CAAQ,CAAC;IAEjE,qEAAqE;IACrE,qEAAqE;IACrE,iDAAiD;IACjD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,kFAAkF,QAAQ,EAAE,CAC7F,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB,CAAC,QAA+B;IACzD,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAClG,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,MAAM,eAAe,CACnB,gDAAgD,QAAQ,CAAC,MAAM,EAAE,EACjE,QAAQ,CACT,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Client, PathUncheckedResponse } from \"@azure-rest/core-client\";\nimport { createRestError } from \"@azure-rest/core-client\";\n\n/**\n * returns an async iterator that iterates over results. It also has a `byPage`\n * method that returns pages of items at once.\n *\n * @param pagedResult - an object that specifies how to get pages.\n * @returns a paged async iterator that iterates over results.\n */\nfunction getPagedAsyncIterator<\n TElement,\n TPage = TElement[],\n TPageSettings = PageSettings,\n TLink = string,\n>(\n pagedResult: PagedResult<TPage, TPageSettings, TLink>,\n): PagedAsyncIterableIterator<TElement, TPage, TPageSettings> {\n const iter = getItemAsyncIterator<TElement, TPage, TLink, TPageSettings>(pagedResult);\n return {\n next() {\n return iter.next();\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n byPage:\n pagedResult?.byPage ??\n (((settings?: PageSettings) => {\n const { continuationToken } = settings ?? {};\n return getPageAsyncIterator(pagedResult, {\n pageLink: continuationToken as unknown as TLink | undefined,\n });\n }) as unknown as (settings?: TPageSettings) => AsyncIterableIterator<TPage>),\n };\n}\n\nasync function* getItemAsyncIterator<TElement, TPage, TLink, TPageSettings>(\n pagedResult: PagedResult<TPage, TPageSettings, TLink>,\n): AsyncIterableIterator<TElement> {\n const pages = getPageAsyncIterator(pagedResult);\n const firstVal = await pages.next();\n // if the result does not have an array shape, i.e. TPage = TElement, then we return it as is\n if (!Array.isArray(firstVal.value)) {\n // can extract elements from this page\n const { toElements } = pagedResult;\n if (toElements) {\n yield* toElements(firstVal.value) as TElement[];\n for await (const page of pages) {\n yield* toElements(page) as TElement[];\n }\n } else {\n yield firstVal.value;\n // `pages` is of type `AsyncIterableIterator<TPage>` but TPage = TElement in this case\n yield* pages as unknown as AsyncIterableIterator<TElement>;\n }\n } else {\n yield* firstVal.value;\n for await (const page of pages) {\n // pages is of type `AsyncIterableIterator<TPage>` so `page` is of type `TPage`. In this branch,\n // it must be the case that `TPage = TElement[]`\n yield* page as unknown as TElement[];\n }\n }\n}\n\nasync function* getPageAsyncIterator<TPage, TLink, TPageSettings>(\n pagedResult: PagedResult<TPage, TPageSettings, TLink>,\n options: {\n pageLink?: TLink;\n } = {},\n): AsyncIterableIterator<TPage> {\n const { pageLink } = options;\n let response = await pagedResult.getPage(pageLink ?? pagedResult.firstPageLink);\n if (!response) {\n return;\n }\n yield response.page;\n while (response.nextPageLink) {\n response = await pagedResult.getPage(response.nextPageLink);\n if (!response) {\n return;\n }\n yield response.page;\n }\n}\n\n/**\n * An interface that tracks the settings for paged iteration\n */\nexport interface PageSettings {\n /**\n * The token that keeps track of where to continue the iterator\n */\n continuationToken?: string;\n}\n\n/**\n * An interface that allows async iterable iteration both to completion and by page.\n */\nexport interface PagedAsyncIterableIterator<\n TElement,\n TPage = TElement[],\n TPageSettings = PageSettings,\n> {\n /**\n * The next method, part of the iteration protocol\n */\n next(): Promise<IteratorResult<TElement>>;\n /**\n * The connection to the async iterator, part of the iteration protocol\n */\n [Symbol.asyncIterator](): PagedAsyncIterableIterator<TElement, TPage, TPageSettings>;\n /**\n * Return an AsyncIterableIterator that works a page at a time\n */\n byPage: (settings?: TPageSettings) => AsyncIterableIterator<TPage>;\n}\n\n/**\n * An interface that describes how to communicate with the service.\n */\ninterface PagedResult<TPage, TPageSettings = PageSettings, TLink = string> {\n /**\n * Link to the first page of results.\n */\n firstPageLink: TLink;\n /**\n * A method that returns a page of results.\n */\n getPage: (pageLink: TLink) => Promise<{ page: TPage; nextPageLink?: TLink } | undefined>;\n /**\n * a function to implement the `byPage` method on the paged async iterator.\n */\n byPage?: (settings?: TPageSettings) => AsyncIterableIterator<TPage>;\n\n /**\n * A function to extract elements from a page.\n */\n toElements?: (page: TPage) => unknown[];\n}\n\n/**\n * Helper type to extract the type of an array\n */\nexport type GetArrayType<T> = T extends Array<infer TData> ? TData : never;\n\n/**\n * The type of a custom function that defines how to get a page and a link to the next one if any.\n */\nexport type GetPage<TPage> = (pageLink: string) => Promise<{\n page: TPage;\n nextPageLink?: string;\n}>;\n\n/**\n * Options for the paging helper\n */\nexport interface PagingOptions<TResponse> {\n /**\n * Custom function to extract pagination details for crating the PagedAsyncIterableIterator\n */\n customGetPage?: GetPage<PaginateReturn<TResponse>[]>;\n}\n\n/**\n * Helper type to infer the Type of the paged elements from the response type\n * This type is generated based on the swagger information for x-ms-pageable\n * specifically on the itemName property which indicates the property of the response\n * where the page items are found. The default value is `value`.\n * This type will allow us to provide strongly typed Iterator based on the response we get as second parameter\n */\nexport type PaginateReturn<TResult> = TResult extends {\n body: { value?: infer TPage };\n}\n ? GetArrayType<TPage>\n : Array<unknown>;\n\n/**\n * Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension\n * @param client - Client to use for sending the next page requests\n * @param initialResponse - Initial response containing the nextLink and current page of elements\n * @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results\n * @returns - PagedAsyncIterableIterator to iterate the elements\n */\nexport function paginate<TResponse extends PathUncheckedResponse>(\n client: Client,\n initialResponse: TResponse,\n options: PagingOptions<TResponse> = {},\n): PagedAsyncIterableIterator<PaginateReturn<TResponse>> {\n // Extract element type from initial response\n type TElement = PaginateReturn<TResponse>;\n let firstRun = true;\n const itemName = \"value\";\n const nextLinkName = \"nextLink\";\n const { customGetPage } = options;\n const pagedResult: PagedResult<TElement[]> = {\n firstPageLink: \"\",\n getPage:\n typeof customGetPage === \"function\"\n ? customGetPage\n : async (pageLink: string) => {\n const result = firstRun ? initialResponse : await client.pathUnchecked(pageLink).get();\n firstRun = false;\n checkPagingRequest(result);\n const nextLink = getNextLink(result.body, nextLinkName);\n const values = getElements<TElement>(result.body, itemName);\n return {\n page: values,\n nextPageLink: nextLink,\n };\n },\n };\n\n return getPagedAsyncIterator(pagedResult);\n}\n\n/**\n * Gets for the value of nextLink in the body\n */\nfunction getNextLink(body: unknown, nextLinkName?: string): string | undefined {\n if (!nextLinkName) {\n return undefined;\n }\n\n const nextLink = (body as Record<string, unknown>)[nextLinkName];\n\n if (typeof nextLink !== \"string\" && typeof nextLink !== \"undefined\") {\n throw new Error(`Body Property ${nextLinkName} should be a string or undefined`);\n }\n\n return nextLink;\n}\n\n/**\n * Gets the elements of the current request in the body.\n */\nfunction getElements<T = unknown>(body: unknown, itemName: string): T[] {\n const value = (body as Record<string, unknown>)[itemName] as T[];\n\n // value has to be an array according to the x-ms-pageable extension.\n // The fact that this must be an array is used above to calculate the\n // type of elements in the page in PaginateReturn\n if (!Array.isArray(value)) {\n throw new Error(\n `Couldn't paginate response\\n Body doesn't contain an array property with name: ${itemName}`,\n );\n }\n\n return value ?? [];\n}\n\n/**\n * Checks if a request failed\n */\nfunction checkPagingRequest(response: PathUncheckedResponse): void {\n const Http2xxStatusCodes = [\"200\", \"201\", \"202\", \"203\", \"204\", \"205\", \"206\", \"207\", \"208\", \"226\"];\n if (!Http2xxStatusCodes.includes(response.status)) {\n throw createRestError(\n `Pagination failed with unexpected statusCode ${response.status}`,\n response,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"paginateHelper.js","sourceRoot":"","sources":["../../src/paginateHelper.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D;;;;;;GAMG;AACH,SAAS,qBAAqB,CAM5B,WAAqD;IAErD,MAAM,IAAI,GAAG,oBAAoB,CAAwC,WAAW,CAAC,CAAC;IACtF,OAAO;QACL,IAAI;YACF,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;QACrB,CAAC;QACD,CAAC,MAAM,CAAC,aAAa,CAAC;YACpB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,EACJ,WAAW,EAAE,MAAM;YAClB,CAAC,CAAC,QAAuB,EAAE,EAAE;gBAC5B,MAAM,EAAE,iBAAiB,EAAE,GAAG,QAAQ,IAAI,EAAE,CAAC;gBAC7C,OAAO,oBAAoB,CAAC,WAAW,EAAE;oBACvC,QAAQ,EAAE,iBAAiD;iBAC5D,CAAC,CAAC;YACL,CAAC,CAA2E;KAC/E,CAAC;AACJ,CAAC;AAED,KAAK,SAAS,CAAC,CAAC,oBAAoB,CAClC,WAAqD;IAErD,MAAM,KAAK,GAAG,oBAAoB,CAAC,WAAW,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;IACpC,6FAA6F;IAC7F,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,sCAAsC;QACtC,MAAM,EAAE,UAAU,EAAE,GAAG,WAAW,CAAC;QACnC,IAAI,UAAU,EAAE,CAAC;YACf,KAAK,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAe,CAAC;YAChD,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBAC/B,KAAK,CAAC,CAAC,U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,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,kFAAkF,QAAQ,EAAE,CAC7F,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,IAAI,EAAE,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB,CAAC,QAA+B;IACzD,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAClG,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,MAAM,eAAe,CACnB,gDAAgD,QAAQ,CAAC,MAAM,EAAE,EACjE,QAAQ,CACT,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Client, PathUncheckedResponse } from \"@azure-rest/core-client\";\nimport { createRestError } from \"@azure-rest/core-client\";\n\n/**\n * returns an async iterator that iterates over results. It also has a `byPage`\n * method that returns pages of items at once.\n *\n * @param pagedResult - an object that specifies how to get pages.\n * @returns a paged async iterator that iterates over results.\n */\nfunction getPagedAsyncIterator<\n TElement,\n TPage = TElement[],\n TPageSettings = PageSettings,\n TLink = string,\n>(\n pagedResult: PagedResult<TPage, TPageSettings, TLink>,\n): PagedAsyncIterableIterator<TElement, TPage, TPageSettings> {\n const iter = getItemAsyncIterator<TElement, TPage, TLink, TPageSettings>(pagedResult);\n return {\n next() {\n return iter.next();\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n byPage:\n pagedResult?.byPage ??\n (((settings?: PageSettings) => {\n const { continuationToken } = settings ?? {};\n return getPageAsyncIterator(pagedResult, {\n pageLink: continuationToken as unknown as TLink | undefined,\n });\n }) as unknown as (settings?: TPageSettings) => AsyncIterableIterator<TPage>),\n };\n}\n\nasync function* getItemAsyncIterator<TElement, TPage, TLink, TPageSettings>(\n pagedResult: PagedResult<TPage, TPageSettings, TLink>,\n): AsyncIterableIterator<TElement> {\n const pages = getPageAsyncIterator(pagedResult);\n const firstVal = await pages.next();\n // if the result does not have an array shape, i.e. TPage = TElement, then we return it as is\n if (!Array.isArray(firstVal.value)) {\n // can extract elements from this page\n const { toElements } = pagedResult;\n if (toElements) {\n yield* toElements(firstVal.value) as TElement[];\n for await (const page of pages) {\n yield* toElements(page) as TElement[];\n }\n } else {\n yield firstVal.value;\n // `pages` is of type `AsyncIterableIterator<TPage>` but TPage = TElement in this case\n yield* pages as unknown as AsyncIterableIterator<TElement>;\n }\n } else {\n yield* firstVal.value;\n for await (const page of pages) {\n // pages is of type `AsyncIterableIterator<TPage>` so `page` is of type `TPage`. In this branch,\n // it must be the case that `TPage = TElement[]`\n yield* page as unknown as TElement[];\n }\n }\n}\n\nasync function* getPageAsyncIterator<TPage, TLink, TPageSettings>(\n pagedResult: PagedResult<TPage, TPageSettings, TLink>,\n options: {\n pageLink?: TLink;\n } = {},\n): AsyncIterableIterator<TPage> {\n const { pageLink } = options;\n let response = await pagedResult.getPage(pageLink ?? pagedResult.firstPageLink);\n if (!response) {\n return;\n }\n yield response.page;\n while (response.nextPageLink) {\n response = await pagedResult.getPage(response.nextPageLink);\n if (!response) {\n return;\n }\n yield response.page;\n }\n}\n\n/**\n * An interface that tracks the settings for paged iteration\n */\nexport interface PageSettings {\n /**\n * The token that keeps track of where to continue the iterator\n */\n continuationToken?: string;\n}\n\n/**\n * An interface that allows async iterable iteration both to completion and by page.\n */\nexport interface PagedAsyncIterableIterator<\n TElement,\n TPage = TElement[],\n TPageSettings = PageSettings,\n> {\n /**\n * The next method, part of the iteration protocol\n */\n next(): Promise<IteratorResult<TElement>>;\n /**\n * The connection to the async iterator, part of the iteration protocol\n */\n [Symbol.asyncIterator](): PagedAsyncIterableIterator<TElement, TPage, TPageSettings>;\n /**\n * Return an AsyncIterableIterator that works a page at a time\n */\n byPage: (settings?: TPageSettings) => AsyncIterableIterator<TPage>;\n}\n\n/**\n * An interface that describes how to communicate with the service.\n */\ninterface PagedResult<TPage, TPageSettings = PageSettings, TLink = string> {\n /**\n * Link to the first page of results.\n */\n firstPageLink: TLink;\n /**\n * A method that returns a page of results.\n */\n getPage: (pageLink: TLink) => Promise<{ page: TPage; nextPageLink?: TLink } | undefined>;\n /**\n * a function to implement the `byPage` method on the paged async iterator.\n */\n byPage?: (settings?: TPageSettings) => AsyncIterableIterator<TPage>;\n\n /**\n * A function to extract elements from a page.\n */\n toElements?: (page: TPage) => unknown[];\n}\n\n/**\n * Helper type to extract the type of an array\n */\nexport type GetArrayType<T> = T extends Array<infer TData> ? TData : never;\n\n/**\n * The type of a custom function that defines how to get a page and a link to the next one if any.\n */\nexport type GetPage<TPage> = (pageLink: string) => Promise<{\n page: TPage;\n nextPageLink?: string;\n}>;\n\n/**\n * Options for the paging helper\n */\nexport interface PagingOptions<TResponse> {\n /**\n * Custom function to extract pagination details for crating the PagedAsyncIterableIterator\n */\n customGetPage?: GetPage<PaginateReturn<TResponse>[]>;\n}\n\n/**\n * Helper type to infer the Type of the paged elements from the response type\n * This type is generated based on the swagger information for x-ms-pageable\n * specifically on the itemName property which indicates the property of the response\n * where the page items are found. The default value is `value`.\n * This type will allow us to provide strongly typed Iterator based on the response we get as second parameter\n */\nexport type PaginateReturn<TResult> = TResult extends {\n body: { value?: infer TPage };\n}\n ? GetArrayType<TPage>\n : Array<unknown>;\n\n/**\n * Helper to paginate results from an initial response that follows the specification of Autorest `x-ms-pageable` extension\n * @param client - Client to use for sending the next page requests\n * @param initialResponse - Initial response containing the nextLink and current page of elements\n * @param customGetPage - Optional - Function to define how to extract the page and next link to be used to paginate the results\n * @returns - PagedAsyncIterableIterator to iterate the elements\n */\nexport function paginate<TResponse extends PathUncheckedResponse>(\n client: Client,\n initialResponse: TResponse,\n options: PagingOptions<TResponse> = {},\n): PagedAsyncIterableIterator<PaginateReturn<TResponse>> {\n // Extract element type from initial response\n type TElement = PaginateReturn<TResponse>;\n let firstRun = true;\n const itemName = \"value\";\n const nextLinkName = \"nextLink\";\n const { customGetPage } = options;\n const pagedResult: PagedResult<TElement[]> = {\n firstPageLink: \"\",\n getPage:\n typeof customGetPage === \"function\"\n ? customGetPage\n : async (pageLink: string) => {\n const result = firstRun ? initialResponse : await client.pathUnchecked(pageLink).get();\n firstRun = false;\n checkPagingRequest(result);\n const nextLink = getNextLink(result.body, nextLinkName);\n const values = getElements<TElement>(result.body, itemName);\n return {\n page: values,\n nextPageLink: nextLink,\n };\n },\n };\n\n return getPagedAsyncIterator(pagedResult);\n}\n\n/**\n * Gets for the value of nextLink in the body\n */\nfunction getNextLink(body: unknown, nextLinkName?: string): string | undefined {\n if (!nextLinkName) {\n return undefined;\n }\n\n const nextLink = (body as Record<string, unknown>)[nextLinkName];\n\n if (typeof nextLink !== \"string\" && typeof nextLink !== \"undefined\") {\n throw new Error(`Body Property ${nextLinkName} should be a string or undefined`);\n }\n\n return nextLink;\n}\n\n/**\n * Gets the elements of the current request in the body.\n */\nfunction getElements<T = unknown>(body: unknown, itemName: string): T[] {\n const value = (body as Record<string, unknown>)[itemName] as T[];\n\n // value has to be an array according to the x-ms-pageable extension.\n // The fact that this must be an array is used above to calculate the\n // type of elements in the page in PaginateReturn\n if (!Array.isArray(value)) {\n throw new Error(\n `Couldn't paginate response\\n Body doesn't contain an array property with name: ${itemName}`,\n );\n }\n\n return value ?? [];\n}\n\n/**\n * Checks if a request failed\n */\nfunction checkPagingRequest(response: PathUncheckedResponse): void {\n const Http2xxStatusCodes = [\"200\", \"201\", \"202\", \"203\", \"204\", \"205\", \"206\", \"207\", \"208\", \"226\"];\n if (!Http2xxStatusCodes.includes(response.status)) {\n throw createRestError(\n `Pagination failed with unexpected statusCode ${response.status}`,\n response,\n );\n }\n}\n"]}
@@ -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
  /**
@@ -11,19 +10,21 @@ const logger_js_1 = require("./logger.js");
11
10
  * @param endpointParam - Uri of your Communication resource
12
11
  * @param options - the parameter for all optional parameters
13
12
  */
14
- function createClient(endpointParam, _a = {}) {
15
- var _b, _c, _d, _e;
16
- var { apiVersion = "2024-01-18-preview" } = _a, options = tslib_1.__rest(_a, ["apiVersion"]);
17
- const endpointUrl = (_c = (_b = options.endpoint) !== null && _b !== void 0 ? _b : options.baseUrl) !== null && _c !== void 0 ? _c : `${endpointParam}`;
18
- const userAgentInfo = `azsdk-js-communication-job-router-rest/1.0.0-beta.1`;
13
+ function createClient(endpointParam, { apiVersion = "2024-01-18-preview", ...options } = {}) {
14
+ const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`;
15
+ const userAgentInfo = `azsdk-js-communication-job-router-rest/1.1.0-beta.3`;
19
16
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
20
17
  ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
21
18
  : `${userAgentInfo}`;
22
- options = Object.assign(Object.assign({}, options), { userAgentOptions: {
19
+ options = {
20
+ ...options,
21
+ userAgentOptions: {
23
22
  userAgentPrefix,
24
- }, loggingOptions: {
25
- logger: (_e = (_d = options.loggingOptions) === null || _d === void 0 ? void 0 : _d.logger) !== null && _e !== void 0 ? _e : logger_js_1.logger.info,
26
- } });
23
+ },
24
+ loggingOptions: {
25
+ logger: options.loggingOptions?.logger ?? logger_js_1.logger.info,
26
+ },
27
+ };
27
28
  const client = (0, core_client_1.getClient)(endpointUrl, options);
28
29
  client.pipeline.removePolicy({ name: "ApiVersionPolicy" });
29
30
  client.pipeline.addPolicy({
@@ -1 +1 @@
1
- {"version":3,"file":"azureCommunicationRoutingServiceClient.js","sourceRoot":"","sources":["../../src/azureCommunicationRoutingServiceClient.ts"],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U,EAAE,CAAC;gBACvD,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,GAAG,GAClB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GACzD,eAAe,UAAU,EAAE,CAAC;YAC9B,CAAC;YACD,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 { AzureCommunicationRoutingServiceClient } from \"./clientDefinitions.js\";\n\n/** The optional parameters for the client */\nexport interface AzureCommunicationRoutingServiceClientOptions extends ClientOptions {\n /** The api version option of the client */\n apiVersion?: string;\n}\n\n/**\n * Initialize a new instance of `AzureCommunicationRoutingServiceClient`\n * @param endpointParam - Uri of your Communication resource\n * @param options - the parameter for all optional parameters\n */\nexport default function createClient(\n endpointParam: string,\n {\n apiVersion = \"2024-01-18-preview\",\n ...options\n }: AzureCommunicationRoutingServiceClientOptions = {},\n): AzureCommunicationRoutingServiceClient {\n const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`;\n const userAgentInfo = `azsdk-js-communication-job-router-rest/1.0.0-beta.1`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n options = {\n ...options,\n userAgentOptions: {\n userAgentPrefix,\n },\n loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info,\n },\n };\n const client = getClient(endpointUrl, options) as AzureCommunicationRoutingServiceClient;\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 req.url = `${req.url}${\n Array.from(url.searchParams.keys()).length > 0 ? \"&\" : \"?\"\n }api-version=${apiVersion}`;\n }\n return next(req);\n },\n });\n\n return client;\n}\n"]}
1
+ {"version":3,"file":"azureCommunicationRoutingServiceClient.js","sourceRoot":"","sources":["../../src/azureCommunicationRoutingServiceClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAkBlC,+BAyCC;AAxDD,yDAAoD;AACpD,2CAAqC;AASrC;;;;GAIG;AACH,SAAwB,YAAY,CAClC,aAAqB,EACrB,EACE,UAAU,GAAG,oBAAoB,EACjC,GAAG,OAAO,KACuC,EAAE;IAErD,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,OAAO,IAAI,GAAG,aAAa,EAAE,CAAC;IAC9E,MAAM,aAAa,GAAG,qDAAqD,CAAC;IAC5E,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,OAAO,GAAG;QACR,GAAG,OAAO;QACV,gBAAgB,EAAE;YAChB,eAAe;SAChB;QACD,cAAc,EAAE;YACd,MAAM,EAAE,OAAO,CAAC,cAAc,EAAE,MAAM,IAAI,kBAAM,CAAC,IAAI;SACtD;KACF,CAAC;IACF,MAAM,MAAM,GAAG,IAAA,uBAAS,EAAC,WAAW,EAAE,OAAO,CAA2C,CAAC;IAEzF,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAC3D,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;QACxB,IAAI,EAAE,wBAAwB;QAC9B,WAAW,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;YACzB,qDAAqD;YACrD,yEAAyE;YACzE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,UAAU,EAAE,CAAC;gBACvD,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,GAAG,GAClB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GACzD,eAAe,UAAU,EAAE,CAAC;YAC9B,CAAC;YACD,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 { AzureCommunicationRoutingServiceClient } from \"./clientDefinitions.js\";\n\n/** The optional parameters for the client */\nexport interface AzureCommunicationRoutingServiceClientOptions extends ClientOptions {\n /** The api version option of the client */\n apiVersion?: string;\n}\n\n/**\n * Initialize a new instance of `AzureCommunicationRoutingServiceClient`\n * @param endpointParam - Uri of your Communication resource\n * @param options - the parameter for all optional parameters\n */\nexport default function createClient(\n endpointParam: string,\n {\n apiVersion = \"2024-01-18-preview\",\n ...options\n }: AzureCommunicationRoutingServiceClientOptions = {},\n): AzureCommunicationRoutingServiceClient {\n const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`;\n const userAgentInfo = `azsdk-js-communication-job-router-rest/1.1.0-beta.3`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n options = {\n ...options,\n userAgentOptions: {\n userAgentPrefix,\n },\n loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info,\n },\n };\n const client = getClient(endpointUrl, options) as AzureCommunicationRoutingServiceClient;\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 req.url = `${req.url}${\n Array.from(url.searchParams.keys()).length > 0 ? \"&\" : \"?\"\n }api-version=${apiVersion}`;\n }\n return next(req);\n },\n });\n\n return client;\n}\n"]}
@@ -40,7 +40,7 @@ const responseMap = {
40
40
  };
41
41
  function isUnexpected(response) {
42
42
  const lroOriginal = response.headers["x-ms-original-url"];
43
- const url = new URL(lroOriginal !== null && lroOriginal !== void 0 ? lroOriginal : response.request.url);
43
+ const url = new URL(lroOriginal ?? response.request.url);
44
44
  const method = response.request.method;
45
45
  let pathDetails = responseMap[`${method} ${url.pathname}`];
46
46
  if (!pathDetails) {
@@ -49,7 +49,6 @@ function isUnexpected(response) {
49
49
  return !pathDetails.includes(response.status);
50
50
  }
51
51
  function getParametrizedPathSuccess(method, path) {
52
- var _a, _b, _c, _d;
53
52
  const pathParts = path.split("/");
54
53
  // Traverse list to match the longest candidate
55
54
  // matchedLen: the length of candidate path
@@ -68,13 +67,13 @@ function getParametrizedPathSuccess(method, path) {
68
67
  // track if we have found a match to return the values found.
69
68
  let found = true;
70
69
  for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
71
- if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) && ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
72
- const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length;
70
+ if (candidateParts[i]?.startsWith("{") && candidateParts[i]?.indexOf("}") !== -1) {
71
+ const start = candidateParts[i].indexOf("}") + 1, end = candidateParts[i]?.length;
73
72
  // If the current part of the candidate is a "template" part
74
73
  // Try to use the suffix of pattern to match the path
75
74
  // {guid} ==> $
76
75
  // {guid}:export ==> :export$
77
- const isMatched = new RegExp(`${(_d = candidateParts[i]) === null || _d === void 0 ? void 0 : _d.slice(start, end)}`).test(pathParts[j] || "");
76
+ const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(pathParts[j] || "");
78
77
  if (!isMatched) {
79
78
  found = false;
80
79
  break;