@azure-rest/purview-administration 1.0.0-beta.2 → 1.0.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.
- package/CHANGELOG.md +22 -0
- package/README.md +53 -27
- package/dist/browser/account/isUnexpected.js +4 -5
- package/dist/browser/account/isUnexpected.js.map +1 -1
- package/dist/browser/account/paginateHelper.js +43 -73
- package/dist/browser/account/paginateHelper.js.map +1 -1
- package/dist/browser/account/purviewAccount.js +12 -10
- package/dist/browser/account/purviewAccount.js.map +1 -1
- package/dist/browser/metadataPolicies/isUnexpected.js +4 -5
- package/dist/browser/metadataPolicies/isUnexpected.js.map +1 -1
- package/dist/browser/metadataPolicies/paginateHelper.js +43 -73
- package/dist/browser/metadataPolicies/paginateHelper.js.map +1 -1
- package/dist/browser/metadataPolicies/purviewMetadataPolicies.js +12 -10
- package/dist/browser/metadataPolicies/purviewMetadataPolicies.js.map +1 -1
- package/dist/commonjs/account/isUnexpected.js +4 -5
- package/dist/commonjs/account/isUnexpected.js.map +1 -1
- package/dist/commonjs/account/paginateHelper.js +43 -73
- package/dist/commonjs/account/paginateHelper.js.map +1 -1
- package/dist/commonjs/account/purviewAccount.js +12 -10
- package/dist/commonjs/account/purviewAccount.js.map +1 -1
- package/dist/commonjs/metadataPolicies/isUnexpected.js +4 -5
- package/dist/commonjs/metadataPolicies/isUnexpected.js.map +1 -1
- package/dist/commonjs/metadataPolicies/paginateHelper.js +43 -73
- package/dist/commonjs/metadataPolicies/paginateHelper.js.map +1 -1
- package/dist/commonjs/metadataPolicies/purviewMetadataPolicies.js +12 -10
- package/dist/commonjs/metadataPolicies/purviewMetadataPolicies.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +11 -11
- package/dist/esm/account/isUnexpected.js +4 -5
- package/dist/esm/account/isUnexpected.js.map +1 -1
- package/dist/esm/account/paginateHelper.js +43 -73
- package/dist/esm/account/paginateHelper.js.map +1 -1
- package/dist/esm/account/purviewAccount.js +12 -10
- package/dist/esm/account/purviewAccount.js.map +1 -1
- package/dist/esm/metadataPolicies/isUnexpected.js +4 -5
- package/dist/esm/metadataPolicies/isUnexpected.js.map +1 -1
- package/dist/esm/metadataPolicies/paginateHelper.js +43 -73
- package/dist/esm/metadataPolicies/paginateHelper.js.map +1 -1
- package/dist/esm/metadataPolicies/purviewMetadataPolicies.js +12 -10
- package/dist/esm/metadataPolicies/purviewMetadataPolicies.js.map +1 -1
- package/dist/react-native/account/isUnexpected.js +4 -5
- package/dist/react-native/account/isUnexpected.js.map +1 -1
- package/dist/react-native/account/paginateHelper.js +43 -73
- package/dist/react-native/account/paginateHelper.js.map +1 -1
- package/dist/react-native/account/purviewAccount.js +12 -10
- package/dist/react-native/account/purviewAccount.js.map +1 -1
- package/dist/react-native/metadataPolicies/isUnexpected.js +4 -5
- package/dist/react-native/metadataPolicies/isUnexpected.js.map +1 -1
- package/dist/react-native/metadataPolicies/paginateHelper.js +43 -73
- package/dist/react-native/metadataPolicies/paginateHelper.js.map +1 -1
- package/dist/react-native/metadataPolicies/purviewMetadataPolicies.js +12 -10
- package/dist/react-native/metadataPolicies/purviewMetadataPolicies.js.map +1 -1
- package/package.json +40 -46
- package/review/purview-administration-node.api.md +1722 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Release History
|
|
2
|
+
|
|
3
|
+
## 1.0.0-beta.3 (Unreleased)
|
|
4
|
+
|
|
5
|
+
### Features Added
|
|
6
|
+
|
|
7
|
+
### Breaking Changes
|
|
8
|
+
|
|
9
|
+
### Bugs Fixed
|
|
10
|
+
|
|
11
|
+
### Other Changes
|
|
12
|
+
|
|
13
|
+
## 1.0.0-beta.2 (2025-02-10)
|
|
14
|
+
|
|
15
|
+
### Features Added
|
|
16
|
+
|
|
17
|
+
- refresh @azure-rest/purview-administration sdk
|
|
18
|
+
|
|
19
|
+
## 1.0.0-beta.1 (2021-10-15)
|
|
20
|
+
|
|
21
|
+
- This is the initial release of the Azure Purview Administration client sdk.
|
|
22
|
+
- This package includes the operations of azure-purview-account that was previously released
|
package/README.md
CHANGED
|
@@ -53,18 +53,16 @@ AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
|
|
|
53
53
|
|
|
54
54
|
Use the returned token credential to authenticate the client:
|
|
55
55
|
|
|
56
|
-
```
|
|
57
|
-
import {
|
|
58
|
-
PurviewAccountClient,
|
|
59
|
-
PurviewMetadataPoliciesClient,
|
|
60
|
-
} from "@azure-rest/purview-administration";
|
|
56
|
+
```ts snippet:ReadmeSampleCreateClient_Node
|
|
57
|
+
import { PurviewAccount, PurviewMetadataPolicies } from "@azure-rest/purview-administration";
|
|
61
58
|
import { DefaultAzureCredential } from "@azure/identity";
|
|
62
|
-
|
|
59
|
+
|
|
60
|
+
const accountClient = PurviewAccount.createClient(
|
|
63
61
|
"https://<my-account-name>.purview.azure.com",
|
|
64
62
|
new DefaultAzureCredential(),
|
|
65
63
|
);
|
|
66
64
|
|
|
67
|
-
const metadataClient =
|
|
65
|
+
const metadataClient = PurviewMetadataPolicies.createClient(
|
|
68
66
|
"https://<my-account-name>.purview.azure.com",
|
|
69
67
|
new DefaultAzureCredential(),
|
|
70
68
|
);
|
|
@@ -78,33 +76,63 @@ This client is one of our REST clients. We highly recommend you read how to use
|
|
|
78
76
|
|
|
79
77
|
## Examples
|
|
80
78
|
|
|
81
|
-
The following section shows you how to initialize and authenticate your client
|
|
79
|
+
The following section shows you how to initialize and authenticate your client and perform various operations.
|
|
80
|
+
|
|
81
|
+
- Get A List of Collections
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
Gets a list of collections in the account.
|
|
84
84
|
|
|
85
|
-
```
|
|
86
|
-
import {
|
|
85
|
+
```ts snippet:ReadmeSampleGetCollections
|
|
86
|
+
import { PurviewAccount } from "@azure-rest/purview-administration";
|
|
87
87
|
import { DefaultAzureCredential } from "@azure/identity";
|
|
88
|
-
import dotenv from "dotenv";
|
|
89
88
|
|
|
90
|
-
|
|
89
|
+
const accountClient = PurviewAccount.createClient(
|
|
90
|
+
"https://<my-account-name>.purview.azure.com",
|
|
91
|
+
new DefaultAzureCredential(),
|
|
92
|
+
);
|
|
91
93
|
|
|
92
|
-
const
|
|
94
|
+
const response = await accountClient.path("/collections").get();
|
|
93
95
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
if (PurviewAccount.UnexpectedHelper.isUnexpected(response)) {
|
|
97
|
+
throw response.body.error;
|
|
98
|
+
}
|
|
97
99
|
|
|
98
|
-
|
|
100
|
+
const paginated = PurviewAccount.PaginateHelper.paginate(accountClient, response);
|
|
101
|
+
for await (const collection of paginated) {
|
|
102
|
+
console.log(
|
|
103
|
+
`Collection name: ${collection.name}\tCollection description: ${collection.description}`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
```
|
|
99
107
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
- Get A List of Metadata Policies
|
|
109
|
+
|
|
110
|
+
Gets a list of metadata policies in the account.
|
|
111
|
+
|
|
112
|
+
```ts snippet:ReadmeSampleGetMetadataPolicies
|
|
113
|
+
import { PurviewMetadataPolicies } from "@azure-rest/purview-administration";
|
|
114
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
115
|
+
|
|
116
|
+
const metadataClient = PurviewMetadataPolicies.createClient(
|
|
117
|
+
"https://<my-account-name>.purview.azure.com",
|
|
118
|
+
new DefaultAzureCredential(),
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const response = await metadataClient.path("/metadataPolicies").get();
|
|
103
122
|
|
|
104
|
-
|
|
123
|
+
if (PurviewMetadataPolicies.UnexpectedHelper.isUnexpected(response)) {
|
|
124
|
+
throw response.body.error;
|
|
105
125
|
}
|
|
106
126
|
|
|
107
|
-
|
|
127
|
+
const policies = PurviewMetadataPolicies.PaginateHelper.paginate(metadataClient, response);
|
|
128
|
+
|
|
129
|
+
for await (const policy of policies) {
|
|
130
|
+
if (Array.isArray(policy)) {
|
|
131
|
+
console.error("Unexpected array:", policy);
|
|
132
|
+
} else {
|
|
133
|
+
console.log(`Policy name: ${policy.name}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
108
136
|
```
|
|
109
137
|
|
|
110
138
|
## Troubleshooting
|
|
@@ -113,7 +141,7 @@ main().catch(console.error);
|
|
|
113
141
|
|
|
114
142
|
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
|
|
115
143
|
|
|
116
|
-
```ts
|
|
144
|
+
```ts snippet:SetLogLevel
|
|
117
145
|
import { setLogLevel } from "@azure/logger";
|
|
118
146
|
|
|
119
147
|
setLogLevel("info");
|
|
@@ -131,11 +159,9 @@ If you'd like to contribute to this library, please read the [contributing guide
|
|
|
131
159
|
|
|
132
160
|
- [Microsoft Azure SDK for JavaScript](https://github.com/Azure/azure-sdk-for-js)
|
|
133
161
|
|
|
134
|
-
|
|
135
|
-
|
|
136
162
|
[account_product_documentation]: https://azure.microsoft.com/services/purview/
|
|
137
163
|
[rest_client]: https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md
|
|
138
|
-
[source_code]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/purview/purview-
|
|
164
|
+
[source_code]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/purview/purview-administration-rest
|
|
139
165
|
[account_npm]: https://www.npmjs.com/org/azure-rest
|
|
140
166
|
[account_ref_docs]: https://azure.github.io/azure-sdk-for-js
|
|
141
167
|
[azure_subscription]: https://azure.microsoft.com/free/
|
|
@@ -18,7 +18,7 @@ const responseMap = {
|
|
|
18
18
|
};
|
|
19
19
|
export function isUnexpected(response) {
|
|
20
20
|
const lroOriginal = response.headers["x-ms-original-url"];
|
|
21
|
-
const url = new URL(lroOriginal
|
|
21
|
+
const url = new URL(lroOriginal ?? response.request.url);
|
|
22
22
|
const method = response.request.method;
|
|
23
23
|
let pathDetails = responseMap[`${method} ${url.pathname}`];
|
|
24
24
|
if (!pathDetails) {
|
|
@@ -27,7 +27,6 @@ export function isUnexpected(response) {
|
|
|
27
27
|
return !pathDetails.includes(response.status);
|
|
28
28
|
}
|
|
29
29
|
function getParametrizedPathSuccess(method, path) {
|
|
30
|
-
var _a, _b, _c, _d;
|
|
31
30
|
const pathParts = path.split("/");
|
|
32
31
|
// Traverse list to match the longest candidate
|
|
33
32
|
// matchedLen: the length of candidate path
|
|
@@ -46,13 +45,13 @@ function getParametrizedPathSuccess(method, path) {
|
|
|
46
45
|
// track if we have found a match to return the values found.
|
|
47
46
|
let found = true;
|
|
48
47
|
for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
|
|
49
|
-
if (
|
|
50
|
-
const start = candidateParts[i].indexOf("}") + 1, end =
|
|
48
|
+
if (candidateParts[i]?.startsWith("{") && candidateParts[i]?.indexOf("}") !== -1) {
|
|
49
|
+
const start = candidateParts[i].indexOf("}") + 1, end = candidateParts[i]?.length;
|
|
51
50
|
// If the current part of the candidate is a "template" part
|
|
52
51
|
// Try to use the suffix of pattern to match the path
|
|
53
52
|
// {guid} ==> $
|
|
54
53
|
// {guid}:export ==> :export$
|
|
55
|
-
const isMatched = new RegExp(`${
|
|
54
|
+
const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(pathParts[j] || "");
|
|
56
55
|
if (!isMatched) {
|
|
57
56
|
found = false;
|
|
58
57
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../../src/account/isUnexpected.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAkClC,MAAM,WAAW,GAA6B;IAC5C,OAAO,EAAE,CAAC,KAAK,CAAC;IAChB,SAAS,EAAE,CAAC,KAAK,CAAC;IAClB,gBAAgB,EAAE,CAAC,KAAK,CAAC;IACz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AC1E,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 AccountsGetAccountProperties200Response,\n AccountsGetAccountPropertiesDefaultResponse,\n AccountsUpdateAccountProperties200Response,\n AccountsUpdateAccountPropertiesDefaultResponse,\n AccountsGetAccessKeys200Response,\n AccountsGetAccessKeysDefaultResponse,\n AccountsRegenerateAccessKey200Response,\n AccountsRegenerateAccessKeyDefaultResponse,\n CollectionsGetCollection200Response,\n CollectionsGetCollectionDefaultResponse,\n CollectionsCreateOrUpdateCollection200Response,\n CollectionsCreateOrUpdateCollectionDefaultResponse,\n CollectionsDeleteCollection204Response,\n CollectionsDeleteCollectionDefaultResponse,\n CollectionsListCollections200Response,\n CollectionsListCollectionsDefaultResponse,\n CollectionsListChildCollectionNames200Response,\n CollectionsListChildCollectionNamesDefaultResponse,\n CollectionsGetCollectionPath200Response,\n CollectionsGetCollectionPathDefaultResponse,\n ResourceSetRulesGetResourceSetRule200Response,\n ResourceSetRulesGetResourceSetRuleDefaultResponse,\n ResourceSetRulesCreateOrUpdateResourceSetRule200Response,\n ResourceSetRulesCreateOrUpdateResourceSetRuleDefaultResponse,\n ResourceSetRulesDeleteResourceSetRule200Response,\n ResourceSetRulesDeleteResourceSetRule204Response,\n ResourceSetRulesDeleteResourceSetRuleDefaultResponse,\n ResourceSetRulesListResourceSetRules200Response,\n ResourceSetRulesListResourceSetRulesDefaultResponse,\n} from \"./responses.js\";\n\nconst responseMap: Record<string, string[]> = {\n \"GET /\": [\"200\"],\n \"PATCH /\": [\"200\"],\n \"POST /listkeys\": [\"200\"],\n \"POST /regeneratekeys\": [\"200\"],\n \"GET /collections/{collectionName}\": [\"200\"],\n \"PUT /collections/{collectionName}\": [\"200\"],\n \"DELETE /collections/{collectionName}\": [\"204\"],\n \"GET /collections\": [\"200\"],\n \"GET /collections/{collectionName}/getChildCollectionNames\": [\"200\"],\n \"GET /collections/{collectionName}/getCollectionPath\": [\"200\"],\n \"GET /resourceSetRuleConfigs/defaultResourceSetRuleConfig\": [\"200\"],\n \"PUT /resourceSetRuleConfigs/defaultResourceSetRuleConfig\": [\"200\"],\n \"DELETE /resourceSetRuleConfigs/defaultResourceSetRuleConfig\": [\"200\", \"204\"],\n \"GET /resourceSetRuleConfigs\": [\"200\"],\n};\n\nexport function isUnexpected(\n response: AccountsGetAccountProperties200Response | AccountsGetAccountPropertiesDefaultResponse,\n): response is AccountsGetAccountPropertiesDefaultResponse;\nexport function isUnexpected(\n response:\n | AccountsUpdateAccountProperties200Response\n | AccountsUpdateAccountPropertiesDefaultResponse,\n): response is AccountsUpdateAccountPropertiesDefaultResponse;\nexport function isUnexpected(\n response: AccountsGetAccessKeys200Response | AccountsGetAccessKeysDefaultResponse,\n): response is AccountsGetAccessKeysDefaultResponse;\nexport function isUnexpected(\n response: AccountsRegenerateAccessKey200Response | AccountsRegenerateAccessKeyDefaultResponse,\n): response is AccountsRegenerateAccessKeyDefaultResponse;\nexport function isUnexpected(\n response: CollectionsGetCollection200Response | CollectionsGetCollectionDefaultResponse,\n): response is CollectionsGetCollectionDefaultResponse;\nexport function isUnexpected(\n response:\n | CollectionsCreateOrUpdateCollection200Response\n | CollectionsCreateOrUpdateCollectionDefaultResponse,\n): response is CollectionsCreateOrUpdateCollectionDefaultResponse;\nexport function isUnexpected(\n response: CollectionsDeleteCollection204Response | CollectionsDeleteCollectionDefaultResponse,\n): response is CollectionsDeleteCollectionDefaultResponse;\nexport function isUnexpected(\n response: CollectionsListCollections200Response | CollectionsListCollectionsDefaultResponse,\n): response is CollectionsListCollectionsDefaultResponse;\nexport function isUnexpected(\n response:\n | CollectionsListChildCollectionNames200Response\n | CollectionsListChildCollectionNamesDefaultResponse,\n): response is CollectionsListChildCollectionNamesDefaultResponse;\nexport function isUnexpected(\n response: CollectionsGetCollectionPath200Response | CollectionsGetCollectionPathDefaultResponse,\n): response is CollectionsGetCollectionPathDefaultResponse;\nexport function isUnexpected(\n response:\n | ResourceSetRulesGetResourceSetRule200Response\n | ResourceSetRulesGetResourceSetRuleDefaultResponse,\n): response is ResourceSetRulesGetResourceSetRuleDefaultResponse;\nexport function isUnexpected(\n response:\n | ResourceSetRulesCreateOrUpdateResourceSetRule200Response\n | ResourceSetRulesCreateOrUpdateResourceSetRuleDefaultResponse,\n): response is ResourceSetRulesCreateOrUpdateResourceSetRuleDefaultResponse;\nexport function isUnexpected(\n response:\n | ResourceSetRulesDeleteResourceSetRule200Response\n | ResourceSetRulesDeleteResourceSetRule204Response\n | ResourceSetRulesDeleteResourceSetRuleDefaultResponse,\n): response is ResourceSetRulesDeleteResourceSetRuleDefaultResponse;\nexport function isUnexpected(\n response:\n | ResourceSetRulesListResourceSetRules200Response\n | ResourceSetRulesListResourceSetRulesDefaultResponse,\n): response is ResourceSetRulesListResourceSetRulesDefaultResponse;\nexport function isUnexpected(\n response:\n | AccountsGetAccountProperties200Response\n | AccountsGetAccountPropertiesDefaultResponse\n | AccountsUpdateAccountProperties200Response\n | AccountsUpdateAccountPropertiesDefaultResponse\n | AccountsGetAccessKeys200Response\n | AccountsGetAccessKeysDefaultResponse\n | AccountsRegenerateAccessKey200Response\n | AccountsRegenerateAccessKeyDefaultResponse\n | CollectionsGetCollection200Response\n | CollectionsGetCollectionDefaultResponse\n | CollectionsCreateOrUpdateCollection200Response\n | CollectionsCreateOrUpdateCollectionDefaultResponse\n | CollectionsDeleteCollection204Response\n | CollectionsDeleteCollectionDefaultResponse\n | CollectionsListCollections200Response\n | CollectionsListCollectionsDefaultResponse\n | CollectionsListChildCollectionNames200Response\n | CollectionsListChildCollectionNamesDefaultResponse\n | CollectionsGetCollectionPath200Response\n | CollectionsGetCollectionPathDefaultResponse\n | ResourceSetRulesGetResourceSetRule200Response\n | ResourceSetRulesGetResourceSetRuleDefaultResponse\n | ResourceSetRulesCreateOrUpdateResourceSetRule200Response\n | ResourceSetRulesCreateOrUpdateResourceSetRuleDefaultResponse\n | ResourceSetRulesDeleteResourceSetRule200Response\n | ResourceSetRulesDeleteResourceSetRule204Response\n | ResourceSetRulesDeleteResourceSetRuleDefaultResponse\n | ResourceSetRulesListResourceSetRules200Response\n | ResourceSetRulesListResourceSetRulesDefaultResponse,\n): response is\n | AccountsGetAccountPropertiesDefaultResponse\n | AccountsUpdateAccountPropertiesDefaultResponse\n | AccountsGetAccessKeysDefaultResponse\n | AccountsRegenerateAccessKeyDefaultResponse\n | CollectionsGetCollectionDefaultResponse\n | CollectionsCreateOrUpdateCollectionDefaultResponse\n | CollectionsDeleteCollectionDefaultResponse\n | CollectionsListCollectionsDefaultResponse\n | CollectionsListChildCollectionNamesDefaultResponse\n | CollectionsGetCollectionPathDefaultResponse\n | ResourceSetRulesGetResourceSetRuleDefaultResponse\n | ResourceSetRulesCreateOrUpdateResourceSetRuleDefaultResponse\n | ResourceSetRulesDeleteResourceSetRuleDefaultResponse\n | ResourceSetRulesListResourceSetRulesDefaultResponse {\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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,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 AccountsGetAccountProperties200Response,\n AccountsGetAccountPropertiesDefaultResponse,\n AccountsUpdateAccountProperties200Response,\n AccountsUpdateAccountPropertiesDefaultResponse,\n AccountsGetAccessKeys200Response,\n AccountsGetAccessKeysDefaultResponse,\n AccountsRegenerateAccessKey200Response,\n AccountsRegenerateAccessKeyDefaultResponse,\n CollectionsGetCollection200Response,\n CollectionsGetCollectionDefaultResponse,\n CollectionsCreateOrUpdateCollection200Response,\n CollectionsCreateOrUpdateCollectionDefaultResponse,\n CollectionsDeleteCollection204Response,\n CollectionsDeleteCollectionDefaultResponse,\n CollectionsListCollections200Response,\n CollectionsListCollectionsDefaultResponse,\n CollectionsListChildCollectionNames200Response,\n CollectionsListChildCollectionNamesDefaultResponse,\n CollectionsGetCollectionPath200Response,\n CollectionsGetCollectionPathDefaultResponse,\n ResourceSetRulesGetResourceSetRule200Response,\n ResourceSetRulesGetResourceSetRuleDefaultResponse,\n ResourceSetRulesCreateOrUpdateResourceSetRule200Response,\n ResourceSetRulesCreateOrUpdateResourceSetRuleDefaultResponse,\n ResourceSetRulesDeleteResourceSetRule200Response,\n ResourceSetRulesDeleteResourceSetRule204Response,\n ResourceSetRulesDeleteResourceSetRuleDefaultResponse,\n ResourceSetRulesListResourceSetRules200Response,\n ResourceSetRulesListResourceSetRulesDefaultResponse,\n} from \"./responses.js\";\n\nconst responseMap: Record<string, string[]> = {\n \"GET /\": [\"200\"],\n \"PATCH /\": [\"200\"],\n \"POST /listkeys\": [\"200\"],\n \"POST /regeneratekeys\": [\"200\"],\n \"GET /collections/{collectionName}\": [\"200\"],\n \"PUT /collections/{collectionName}\": [\"200\"],\n \"DELETE /collections/{collectionName}\": [\"204\"],\n \"GET /collections\": [\"200\"],\n \"GET /collections/{collectionName}/getChildCollectionNames\": [\"200\"],\n \"GET /collections/{collectionName}/getCollectionPath\": [\"200\"],\n \"GET /resourceSetRuleConfigs/defaultResourceSetRuleConfig\": [\"200\"],\n \"PUT /resourceSetRuleConfigs/defaultResourceSetRuleConfig\": [\"200\"],\n \"DELETE /resourceSetRuleConfigs/defaultResourceSetRuleConfig\": [\"200\", \"204\"],\n \"GET /resourceSetRuleConfigs\": [\"200\"],\n};\n\nexport function isUnexpected(\n response: AccountsGetAccountProperties200Response | AccountsGetAccountPropertiesDefaultResponse,\n): response is AccountsGetAccountPropertiesDefaultResponse;\nexport function isUnexpected(\n response:\n | AccountsUpdateAccountProperties200Response\n | AccountsUpdateAccountPropertiesDefaultResponse,\n): response is AccountsUpdateAccountPropertiesDefaultResponse;\nexport function isUnexpected(\n response: AccountsGetAccessKeys200Response | AccountsGetAccessKeysDefaultResponse,\n): response is AccountsGetAccessKeysDefaultResponse;\nexport function isUnexpected(\n response: AccountsRegenerateAccessKey200Response | AccountsRegenerateAccessKeyDefaultResponse,\n): response is AccountsRegenerateAccessKeyDefaultResponse;\nexport function isUnexpected(\n response: CollectionsGetCollection200Response | CollectionsGetCollectionDefaultResponse,\n): response is CollectionsGetCollectionDefaultResponse;\nexport function isUnexpected(\n response:\n | CollectionsCreateOrUpdateCollection200Response\n | CollectionsCreateOrUpdateCollectionDefaultResponse,\n): response is CollectionsCreateOrUpdateCollectionDefaultResponse;\nexport function isUnexpected(\n response: CollectionsDeleteCollection204Response | CollectionsDeleteCollectionDefaultResponse,\n): response is CollectionsDeleteCollectionDefaultResponse;\nexport function isUnexpected(\n response: CollectionsListCollections200Response | CollectionsListCollectionsDefaultResponse,\n): response is CollectionsListCollectionsDefaultResponse;\nexport function isUnexpected(\n response:\n | CollectionsListChildCollectionNames200Response\n | CollectionsListChildCollectionNamesDefaultResponse,\n): response is CollectionsListChildCollectionNamesDefaultResponse;\nexport function isUnexpected(\n response: CollectionsGetCollectionPath200Response | CollectionsGetCollectionPathDefaultResponse,\n): response is CollectionsGetCollectionPathDefaultResponse;\nexport function isUnexpected(\n response:\n | ResourceSetRulesGetResourceSetRule200Response\n | ResourceSetRulesGetResourceSetRuleDefaultResponse,\n): response is ResourceSetRulesGetResourceSetRuleDefaultResponse;\nexport function isUnexpected(\n response:\n | ResourceSetRulesCreateOrUpdateResourceSetRule200Response\n | ResourceSetRulesCreateOrUpdateResourceSetRuleDefaultResponse,\n): response is ResourceSetRulesCreateOrUpdateResourceSetRuleDefaultResponse;\nexport function isUnexpected(\n response:\n | ResourceSetRulesDeleteResourceSetRule200Response\n | ResourceSetRulesDeleteResourceSetRule204Response\n | ResourceSetRulesDeleteResourceSetRuleDefaultResponse,\n): response is ResourceSetRulesDeleteResourceSetRuleDefaultResponse;\nexport function isUnexpected(\n response:\n | ResourceSetRulesListResourceSetRules200Response\n | ResourceSetRulesListResourceSetRulesDefaultResponse,\n): response is ResourceSetRulesListResourceSetRulesDefaultResponse;\nexport function isUnexpected(\n response:\n | AccountsGetAccountProperties200Response\n | AccountsGetAccountPropertiesDefaultResponse\n | AccountsUpdateAccountProperties200Response\n | AccountsUpdateAccountPropertiesDefaultResponse\n | AccountsGetAccessKeys200Response\n | AccountsGetAccessKeysDefaultResponse\n | AccountsRegenerateAccessKey200Response\n | AccountsRegenerateAccessKeyDefaultResponse\n | CollectionsGetCollection200Response\n | CollectionsGetCollectionDefaultResponse\n | CollectionsCreateOrUpdateCollection200Response\n | CollectionsCreateOrUpdateCollectionDefaultResponse\n | CollectionsDeleteCollection204Response\n | CollectionsDeleteCollectionDefaultResponse\n | CollectionsListCollections200Response\n | CollectionsListCollectionsDefaultResponse\n | CollectionsListChildCollectionNames200Response\n | CollectionsListChildCollectionNamesDefaultResponse\n | CollectionsGetCollectionPath200Response\n | CollectionsGetCollectionPathDefaultResponse\n | ResourceSetRulesGetResourceSetRule200Response\n | ResourceSetRulesGetResourceSetRuleDefaultResponse\n | ResourceSetRulesCreateOrUpdateResourceSetRule200Response\n | ResourceSetRulesCreateOrUpdateResourceSetRuleDefaultResponse\n | ResourceSetRulesDeleteResourceSetRule200Response\n | ResourceSetRulesDeleteResourceSetRule204Response\n | ResourceSetRulesDeleteResourceSetRuleDefaultResponse\n | ResourceSetRulesListResourceSetRules200Response\n | ResourceSetRulesListResourceSetRulesDefaultResponse,\n): response is\n | AccountsGetAccountPropertiesDefaultResponse\n | AccountsUpdateAccountPropertiesDefaultResponse\n | AccountsGetAccessKeysDefaultResponse\n | AccountsRegenerateAccessKeyDefaultResponse\n | CollectionsGetCollectionDefaultResponse\n | CollectionsCreateOrUpdateCollectionDefaultResponse\n | CollectionsDeleteCollectionDefaultResponse\n | CollectionsListCollectionsDefaultResponse\n | CollectionsListChildCollectionNamesDefaultResponse\n | CollectionsGetCollectionPathDefaultResponse\n | ResourceSetRulesGetResourceSetRuleDefaultResponse\n | ResourceSetRulesCreateOrUpdateResourceSetRuleDefaultResponse\n | ResourceSetRulesDeleteResourceSetRuleDefaultResponse\n | ResourceSetRulesListResourceSetRulesDefaultResponse {\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"]}
|
|
@@ -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:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
yield
|
|
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
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
|
67
|
+
return;
|
|
91
68
|
}
|
|
92
|
-
yield
|
|
93
|
-
|
|
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
|
|
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/account/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,MAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,MAAM,mCAClB,CAAC,CAAC,QAAuB,EAAE,EAAE;YAC5B,MAAM,EAAE,iBAAiB,EAAE,GAAG,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC;YAC7C,OAAO,oBAAoB,CAAC,WAAW,EAAE;gBACvC,QAAQ,EAAE,iBAAiD;aAC5D,CAAC,CAAC;QACL,CAAC,CAA2E;KAC/E,CAAC;AACJ,CAAC;AAED,SAAgB,oBAAoB,CAClC,WAAqD;;;QAErD,MAAM,KAAK,GAAG,oBAAoB,CAAC,WAAW,CAAC,CAAC;QAChD,MAAM,QAAQ,GAAG,cAAM,KAAK,CAAC,IAAI,EAAE,CAAA,CAAC;QACpC,6FAA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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/account/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,CAA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// 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,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,21 +8,24 @@ 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 function createClient(endpoint, credentials,
|
|
13
|
-
|
|
14
|
-
var { apiVersion = "2019-11-01-preview" } = _a, options = __rest(_a, ["apiVersion"]);
|
|
15
|
-
const endpointUrl = (_c = (_b = options.endpoint) !== null && _b !== void 0 ? _b : options.baseUrl) !== null && _c !== void 0 ? _c : `${endpoint}`;
|
|
11
|
+
export function createClient(endpoint, credentials, { apiVersion = "2019-11-01-preview", ...options } = {}) {
|
|
12
|
+
const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpoint}`;
|
|
16
13
|
const userAgentInfo = `azsdk-js-purview-administration-rest/1.0.0-beta.2`;
|
|
17
14
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
18
15
|
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
|
19
16
|
: `${userAgentInfo}`;
|
|
20
|
-
options =
|
|
17
|
+
options = {
|
|
18
|
+
...options,
|
|
19
|
+
userAgentOptions: {
|
|
21
20
|
userAgentPrefix,
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
},
|
|
22
|
+
loggingOptions: {
|
|
23
|
+
logger: options.loggingOptions?.logger ?? logger.info,
|
|
24
|
+
},
|
|
25
|
+
credentials: {
|
|
25
26
|
scopes: ["https://purview.azure.net/.default"],
|
|
26
|
-
}
|
|
27
|
+
},
|
|
28
|
+
};
|
|
27
29
|
const client = getClient(endpointUrl, credentials, options);
|
|
28
30
|
client.pipeline.removePolicy({ name: "ApiVersionPolicy" });
|
|
29
31
|
client.pipeline.addPolicy({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"purviewAccount.js","sourceRoot":"","sources":["../../../src/account/purviewAccount.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC
|
|
1
|
+
{"version":3,"file":"purviewAccount.js","sourceRoot":"","sources":["../../../src/account/purviewAccount.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAUtC;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,QAAgB,EAChB,WAA4B,EAC5B,EAAE,UAAU,GAAG,oBAAoB,EAAE,GAAG,OAAO,KAAkC,EAAE;IAEnF,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,OAAO,IAAI,GAAG,QAAQ,EAAE,CAAC;IACzE,MAAM,aAAa,GAAG,mD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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 } from \"@azure/core-auth\";\nimport type { PurviewAccountClient } from \"./clientDefinitions.js\";\n\n/** The optional parameters for the client */\nexport interface PurviewAccountClientOptions extends ClientOptions {\n /** The api version option of the client */\n apiVersion?: string;\n}\n\n/**\n * Initialize a new instance of `PurviewAccountClient`\n * @param endpoint - The account endpoint of your Purview account. Example: https://\\{accountName\\}.purview.azure.com/account/\n * @param credentials - uniquely identify client credential\n * @param options - the parameter for all optional parameters\n */\nexport function createClient(\n endpoint: string,\n credentials: TokenCredential,\n { apiVersion = \"2019-11-01-preview\", ...options }: PurviewAccountClientOptions = {},\n): PurviewAccountClient {\n const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpoint}`;\n const userAgentInfo = `azsdk-js-purview-administration-rest/1.0.0-beta.2`;\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 credentials: {\n scopes: [\"https://purview.azure.net/.default\"],\n },\n };\n const client = getClient(endpointUrl, credentials, options) as PurviewAccountClient;\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\n return next(req);\n },\n });\n\n return client;\n}\n"]}
|
|
@@ -8,7 +8,7 @@ const responseMap = {
|
|
|
8
8
|
};
|
|
9
9
|
export function isUnexpected(response) {
|
|
10
10
|
const lroOriginal = response.headers["x-ms-original-url"];
|
|
11
|
-
const url = new URL(lroOriginal
|
|
11
|
+
const url = new URL(lroOriginal ?? response.request.url);
|
|
12
12
|
const method = response.request.method;
|
|
13
13
|
let pathDetails = responseMap[`${method} ${url.pathname}`];
|
|
14
14
|
if (!pathDetails) {
|
|
@@ -17,7 +17,6 @@ export function isUnexpected(response) {
|
|
|
17
17
|
return !pathDetails.includes(response.status);
|
|
18
18
|
}
|
|
19
19
|
function getParametrizedPathSuccess(method, path) {
|
|
20
|
-
var _a, _b, _c, _d;
|
|
21
20
|
const pathParts = path.split("/");
|
|
22
21
|
// Traverse list to match the longest candidate
|
|
23
22
|
// matchedLen: the length of candidate path
|
|
@@ -36,13 +35,13 @@ function getParametrizedPathSuccess(method, path) {
|
|
|
36
35
|
// track if we have found a match to return the values found.
|
|
37
36
|
let found = true;
|
|
38
37
|
for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
|
|
39
|
-
if (
|
|
40
|
-
const start = candidateParts[i].indexOf("}") + 1, end =
|
|
38
|
+
if (candidateParts[i]?.startsWith("{") && candidateParts[i]?.indexOf("}") !== -1) {
|
|
39
|
+
const start = candidateParts[i].indexOf("}") + 1, end = candidateParts[i]?.length;
|
|
41
40
|
// If the current part of the candidate is a "template" part
|
|
42
41
|
// Try to use the suffix of pattern to match the path
|
|
43
42
|
// {guid} ==> $
|
|
44
43
|
// {guid}:export ==> :export$
|
|
45
|
-
const isMatched = new RegExp(`${
|
|
44
|
+
const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(pathParts[j] || "");
|
|
46
45
|
if (!isMatched) {
|
|
47
46
|
found = false;
|
|
48
47
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../../src/metadataPolicies/isUnexpected.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAalC,MAAM,WAAW,GAA6B;IAC5C,oBAAoB,EAAE,CAAC,KAAK,CAAC;IAC7B,uBAAuB,EAAE,CAAC,KAAK,CAAC;IAChC,kCAAkC,EAAE,CAAC,KAAK,CAAC;IAC3C,kCAAkC,EAAE,CAAC,KAAK,CAAC;CAC5C,CAAC;AAcF,MAAM,UAAU,YAAY,CAC1B,QAQoC;IAMpC,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/metadataPolicies/isUnexpected.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAalC,MAAM,WAAW,GAA6B;IAC5C,oBAAoB,EAAE,CAAC,KAAK,CAAC;IAC7B,uBAAuB,EAAE,CAAC,KAAK,CAAC;IAChC,kCAAkC,EAAE,CAAC,KAAK,CAAC;IAC3C,kCAAkC,EAAE,CAAC,KAAK,CAAC;CAC5C,CAAC;AAcF,MAAM,UAAU,YAAY,CAC1B,QAQoC;IAMpC,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,EAAE,GAAG,CAAC,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AAG,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 MetadataRolesList200Response,\n MetadataRolesListDefaultResponse,\n MetadataPolicyListAll200Response,\n MetadataPolicyListAllDefaultResponse,\n MetadataPolicyUpdate200Response,\n MetadataPolicyUpdateDefaultResponse,\n MetadataPolicyGet200Response,\n MetadataPolicyGetDefaultResponse,\n} from \"./responses.js\";\n\nconst responseMap: Record<string, string[]> = {\n \"GET /metadataRoles\": [\"200\"],\n \"GET /metadataPolicies\": [\"200\"],\n \"PUT /metadataPolicies/{policyId}\": [\"200\"],\n \"GET /metadataPolicies/{policyId}\": [\"200\"],\n};\n\nexport function isUnexpected(\n response: MetadataRolesList200Response | MetadataRolesListDefaultResponse,\n): response is MetadataRolesListDefaultResponse;\nexport function isUnexpected(\n response: MetadataPolicyListAll200Response | MetadataPolicyListAllDefaultResponse,\n): response is MetadataPolicyListAllDefaultResponse;\nexport function isUnexpected(\n response: MetadataPolicyUpdate200Response | MetadataPolicyUpdateDefaultResponse,\n): response is MetadataPolicyUpdateDefaultResponse;\nexport function isUnexpected(\n response: MetadataPolicyGet200Response | MetadataPolicyGetDefaultResponse,\n): response is MetadataPolicyGetDefaultResponse;\nexport function isUnexpected(\n response:\n | MetadataRolesList200Response\n | MetadataRolesListDefaultResponse\n | MetadataPolicyListAll200Response\n | MetadataPolicyListAllDefaultResponse\n | MetadataPolicyUpdate200Response\n | MetadataPolicyUpdateDefaultResponse\n | MetadataPolicyGet200Response\n | MetadataPolicyGetDefaultResponse,\n): response is\n | MetadataRolesListDefaultResponse\n | MetadataPolicyListAllDefaultResponse\n | MetadataPolicyUpdateDefaultResponse\n | MetadataPolicyGetDefaultResponse {\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"]}
|