@azure/template 1.0.13-beta.6056743 → 1.0.13-beta.6127129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/api/widgetAnalyticsContext.js +1 -1
- package/dist/browser/api/widgetAnalyticsContext.js.map +1 -1
- package/dist/commonjs/api/index.js +1 -0
- package/dist/commonjs/api/index.js.map +1 -1
- package/dist/commonjs/api/widgetAnalyticsContext.js +2 -1
- package/dist/commonjs/api/widgetAnalyticsContext.js.map +2 -2
- package/dist/commonjs/api/widgets/index.js +1 -0
- package/dist/commonjs/api/widgets/index.js.map +1 -1
- package/dist/commonjs/api/widgets/operations.js +1 -0
- package/dist/commonjs/api/widgets/operations.js.map +1 -1
- package/dist/commonjs/api/widgets/options.js +1 -0
- package/dist/commonjs/api/widgets/options.js.map +1 -1
- package/dist/commonjs/classic/index.js +1 -0
- package/dist/commonjs/classic/index.js.map +1 -1
- package/dist/commonjs/classic/widgets/index.js +1 -0
- package/dist/commonjs/classic/widgets/index.js.map +1 -1
- package/dist/commonjs/index.js +1 -0
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/logger.js +1 -0
- package/dist/commonjs/logger.js.map +1 -1
- package/dist/commonjs/models/index.js +1 -0
- package/dist/commonjs/models/index.js.map +1 -1
- package/dist/commonjs/models/models.js +1 -0
- package/dist/commonjs/models/models.js.map +1 -1
- package/dist/commonjs/restorePollerHelpers.js +1 -0
- package/dist/commonjs/restorePollerHelpers.js.map +1 -1
- package/dist/commonjs/static-helpers/pagingHelpers.js +1 -0
- package/dist/commonjs/static-helpers/pagingHelpers.js.map +1 -1
- package/dist/commonjs/static-helpers/pollingHelpers.js +1 -0
- package/dist/commonjs/static-helpers/pollingHelpers.js.map +1 -1
- package/dist/commonjs/static-helpers/urlTemplate.js +1 -0
- package/dist/commonjs/static-helpers/urlTemplate.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/commonjs/widgetAnalyticsClient.js +1 -0
- package/dist/commonjs/widgetAnalyticsClient.js.map +1 -1
- package/dist/esm/api/index.js +4 -6
- package/dist/esm/api/index.js.map +1 -7
- package/dist/esm/api/widgetAnalyticsContext.js +34 -30
- package/dist/esm/api/widgetAnalyticsContext.js.map +1 -7
- package/dist/esm/api/widgets/index.js +4 -14
- package/dist/esm/api/widgets/index.js.map +1 -7
- package/dist/esm/api/widgets/operations.js +138 -184
- package/dist/esm/api/widgets/operations.js.map +1 -7
- package/dist/esm/api/widgets/options.js +4 -0
- package/dist/esm/api/widgets/options.js.map +1 -7
- package/dist/esm/classic/index.js +4 -0
- package/dist/esm/classic/index.js.map +1 -7
- package/dist/esm/classic/widgets/index.js +15 -21
- package/dist/esm/classic/widgets/index.js.map +1 -7
- package/dist/esm/index.js +6 -12
- package/dist/esm/index.js.map +1 -7
- package/dist/esm/logger.js +4 -4
- package/dist/esm/logger.js.map +1 -7
- package/dist/esm/models/index.js +4 -8
- package/dist/esm/models/index.js.map +1 -7
- package/dist/esm/models/models.js +65 -62
- package/dist/esm/models/models.js.map +1 -7
- package/dist/esm/restorePollerHelpers.js +83 -75
- package/dist/esm/restorePollerHelpers.js.map +1 -7
- package/dist/esm/static-helpers/pagingHelpers.js +99 -85
- package/dist/esm/static-helpers/pagingHelpers.js.map +1 -7
- package/dist/esm/static-helpers/pollingHelpers.js +72 -62
- package/dist/esm/static-helpers/pollingHelpers.js.map +1 -7
- package/dist/esm/static-helpers/urlTemplate.js +156 -134
- package/dist/esm/static-helpers/urlTemplate.js.map +1 -7
- package/dist/esm/widgetAnalyticsClient.js +28 -26
- package/dist/esm/widgetAnalyticsClient.js.map +1 -7
- package/dist/react-native/api/widgetAnalyticsContext.js +1 -1
- package/dist/react-native/api/widgetAnalyticsContext.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["/mnt/vss/_work/1/s/sdk/template/template/src/models/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport {\n type WidgetSuite,\n type FakedSharedModel,\n type ResourceOperationStatusWidgetSuiteWidgetSuiteError,\n KnownOperationState,\n type OperationState,\n KnownVersions,\n} from \"./models.js\";\n"],
|
|
5
|
-
"mappings": "AAGA;AAAA,EAIE;AAAA,EAEA;AAAA,OACK;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/models/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAIL,mBAAmB,EAEnB,aAAa,GACd,MAAM,aAAa,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport {\n type WidgetSuite,\n type FakedSharedModel,\n type ResourceOperationStatusWidgetSuiteWidgetSuiteError,\n KnownOperationState,\n type OperationState,\n KnownVersions,\n} from \"./models.js\";\n"]}
|
|
@@ -1,70 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
export function widgetSuiteSerializer(item) {
|
|
4
|
+
return {
|
|
5
|
+
manufacturerId: item["manufacturerId"],
|
|
6
|
+
sharedModel: !item["sharedModel"]
|
|
7
|
+
? item["sharedModel"]
|
|
8
|
+
: fakedSharedModelSerializer(item["sharedModel"]),
|
|
9
|
+
};
|
|
6
10
|
}
|
|
7
|
-
function widgetSuiteDeserializer(item) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
export function widgetSuiteDeserializer(item) {
|
|
12
|
+
return {
|
|
13
|
+
name: item["name"],
|
|
14
|
+
manufacturerId: item["manufacturerId"],
|
|
15
|
+
sharedModel: !item["sharedModel"]
|
|
16
|
+
? item["sharedModel"]
|
|
17
|
+
: fakedSharedModelDeserializer(item["sharedModel"]),
|
|
18
|
+
};
|
|
13
19
|
}
|
|
14
|
-
function fakedSharedModelSerializer(item) {
|
|
15
|
-
|
|
20
|
+
export function fakedSharedModelSerializer(item) {
|
|
21
|
+
return { tag: item["tag"], createdAt: item["createdAt"].toISOString() };
|
|
16
22
|
}
|
|
17
|
-
function fakedSharedModelDeserializer(item) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
export function fakedSharedModelDeserializer(item) {
|
|
24
|
+
return {
|
|
25
|
+
tag: item["tag"],
|
|
26
|
+
createdAt: new Date(item["createdAt"]),
|
|
27
|
+
};
|
|
22
28
|
}
|
|
23
|
-
function resourceOperationStatusWidgetSuiteWidgetSuiteErrorDeserializer(item) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
export function resourceOperationStatusWidgetSuiteWidgetSuiteErrorDeserializer(item) {
|
|
30
|
+
return {
|
|
31
|
+
id: item["id"],
|
|
32
|
+
status: item["status"],
|
|
33
|
+
error: !item["error"] ? item["error"] : item["error"],
|
|
34
|
+
result: !item["result"] ? item["result"] : widgetSuiteDeserializer(item["result"]),
|
|
35
|
+
};
|
|
30
36
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
/** Enum describing allowed operation states. */
|
|
38
|
+
export var KnownOperationState;
|
|
39
|
+
(function (KnownOperationState) {
|
|
40
|
+
/** The operation has not started. */
|
|
41
|
+
KnownOperationState["NotStarted"] = "NotStarted";
|
|
42
|
+
/** The operation is in progress. */
|
|
43
|
+
KnownOperationState["Running"] = "Running";
|
|
44
|
+
/** The operation has completed successfully. */
|
|
45
|
+
KnownOperationState["Succeeded"] = "Succeeded";
|
|
46
|
+
/** The operation has failed. */
|
|
47
|
+
KnownOperationState["Failed"] = "Failed";
|
|
48
|
+
/** The operation has been canceled by the user. */
|
|
49
|
+
KnownOperationState["Canceled"] = "Canceled";
|
|
50
|
+
})(KnownOperationState || (KnownOperationState = {}));
|
|
51
|
+
export function _pagedWidgetSuiteDeserializer(item) {
|
|
52
|
+
return {
|
|
53
|
+
value: widgetSuiteArrayDeserializer(item["value"]),
|
|
54
|
+
nextLink: item["nextLink"],
|
|
55
|
+
};
|
|
44
56
|
}
|
|
45
|
-
function widgetSuiteArraySerializer(result) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
export function widgetSuiteArraySerializer(result) {
|
|
58
|
+
return result.map((item) => {
|
|
59
|
+
return widgetSuiteSerializer(item);
|
|
60
|
+
});
|
|
49
61
|
}
|
|
50
|
-
function widgetSuiteArrayDeserializer(result) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
export function widgetSuiteArrayDeserializer(result) {
|
|
63
|
+
return result.map((item) => {
|
|
64
|
+
return widgetSuiteDeserializer(item);
|
|
65
|
+
});
|
|
54
66
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
_pagedWidgetSuiteDeserializer,
|
|
63
|
-
fakedSharedModelDeserializer,
|
|
64
|
-
fakedSharedModelSerializer,
|
|
65
|
-
resourceOperationStatusWidgetSuiteWidgetSuiteErrorDeserializer,
|
|
66
|
-
widgetSuiteArrayDeserializer,
|
|
67
|
-
widgetSuiteArraySerializer,
|
|
68
|
-
widgetSuiteDeserializer,
|
|
69
|
-
widgetSuiteSerializer
|
|
70
|
-
};
|
|
67
|
+
/** Versions info. */
|
|
68
|
+
export var KnownVersions;
|
|
69
|
+
(function (KnownVersions) {
|
|
70
|
+
/** The 2022-12-01 version. */
|
|
71
|
+
KnownVersions["V20221201"] = "2022-12-01";
|
|
72
|
+
})(KnownVersions || (KnownVersions = {}));
|
|
73
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["/mnt/vss/_work/1/s/sdk/template/template/src/models/models.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ErrorModel } from \"@azure-rest/core-client\";\n\n/** A widget. */\nexport interface WidgetSuite {\n /** The widget name. */\n readonly name: string;\n /** The ID of the widget's manufacturer. */\n manufacturerId: string;\n /** The faked shared model. */\n sharedModel?: FakedSharedModel;\n}\n\nexport function widgetSuiteSerializer(item: WidgetSuite): any {\n return {\n manufacturerId: item[\"manufacturerId\"],\n sharedModel: !item[\"sharedModel\"]\n ? item[\"sharedModel\"]\n : fakedSharedModelSerializer(item[\"sharedModel\"]),\n };\n}\n\nexport function widgetSuiteDeserializer(item: any): WidgetSuite {\n return {\n name: item[\"name\"],\n manufacturerId: item[\"manufacturerId\"],\n sharedModel: !item[\"sharedModel\"]\n ? item[\"sharedModel\"]\n : fakedSharedModelDeserializer(item[\"sharedModel\"]),\n };\n}\n\n/** Faked shared model */\nexport interface FakedSharedModel {\n /** The tag. */\n tag: string;\n /** The created date. */\n createdAt: Date;\n}\n\nexport function fakedSharedModelSerializer(item: FakedSharedModel): any {\n return { tag: item[\"tag\"], createdAt: item[\"createdAt\"].toISOString() };\n}\n\nexport function fakedSharedModelDeserializer(item: any): FakedSharedModel {\n return {\n tag: item[\"tag\"],\n createdAt: new Date(item[\"createdAt\"]),\n };\n}\n\n/** Provides status details for long running operations. */\nexport interface ResourceOperationStatusWidgetSuiteWidgetSuiteError {\n /** The unique ID of the operation. */\n id: string;\n /** The status of the operation */\n status: OperationState;\n /** Error object that describes the error when status is \"Failed\". */\n error?: ErrorModel;\n /** The result of the operation. */\n result?: WidgetSuite;\n}\n\nexport function resourceOperationStatusWidgetSuiteWidgetSuiteErrorDeserializer(\n item: any,\n): ResourceOperationStatusWidgetSuiteWidgetSuiteError {\n return {\n id: item[\"id\"],\n status: item[\"status\"],\n error: !item[\"error\"] ? item[\"error\"] : item[\"error\"],\n result: !item[\"result\"] ? item[\"result\"] : widgetSuiteDeserializer(item[\"result\"]),\n };\n}\n\n/** Enum describing allowed operation states. */\nexport enum KnownOperationState {\n /** The operation has not started. */\n NotStarted = \"NotStarted\",\n /** The operation is in progress. */\n Running = \"Running\",\n /** The operation has completed successfully. */\n Succeeded = \"Succeeded\",\n /** The operation has failed. */\n Failed = \"Failed\",\n /** The operation has been canceled by the user. */\n Canceled = \"Canceled\",\n}\n\n/**\n * Enum describing allowed operation states. \\\n * {@link KnownOperationState} can be used interchangeably with OperationState,\n * this enum contains the known values that the service supports.\n * ### Known values supported by the service\n * **NotStarted**: The operation has not started. \\\n * **Running**: The operation is in progress. \\\n * **Succeeded**: The operation has completed successfully. \\\n * **Failed**: The operation has failed. \\\n * **Canceled**: The operation has been canceled by the user.\n */\nexport type OperationState = string;\n\n/** Paged collection of WidgetSuite items */\nexport interface _PagedWidgetSuite {\n /** The WidgetSuite items on this page */\n value: WidgetSuite[];\n /** The link to the next page of items */\n nextLink?: string;\n}\n\nexport function _pagedWidgetSuiteDeserializer(item: any): _PagedWidgetSuite {\n return {\n value: widgetSuiteArrayDeserializer(item[\"value\"]),\n nextLink: item[\"nextLink\"],\n };\n}\n\nexport function widgetSuiteArraySerializer(result: Array<WidgetSuite>): any[] {\n return result.map((item) => {\n return widgetSuiteSerializer(item);\n });\n}\n\nexport function widgetSuiteArrayDeserializer(result: Array<WidgetSuite>): any[] {\n return result.map((item) => {\n return widgetSuiteDeserializer(item);\n });\n}\n\n/** Versions info. */\nexport enum KnownVersions {\n /** The 2022-12-01 version. */\n V20221201 = \"2022-12-01\",\n}\n"],
|
|
5
|
-
"mappings": "AAeO,SAAS,sBAAsB,MAAwB;AAC5D,SAAO;AAAA,IACL,gB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AI,CAAC,SAAS;AAC1B,WAAO,sBAAsB,IAAI;AAAA,EACnC,CAAC;AACH;AAEO,SAAS,6BAA6B,QAAmC;AAC9E,SAAO,OAAO,IAAI,CAAC,SAAS;AAC1B,WAAO,wBAAwB,IAAI;AAAA,EACrC,CAAC;AACH;AAGO,IAAK,gBAAL,kBAAKC,mBAAL;AAEL,EAAAA,eAAA,eAAY;AAFF,SAAAA;AAAA,GAAA;",
|
|
6
|
-
"names": ["KnownOperationState", "KnownVersions"]
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../src/models/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAclC,MAAM,UAAU,qBAAqB,CAAC,IAAiB;IACrD,OAAO;QACL,cAAc,EAAE,IAAI,CAAC,gBAAgB,CAAC;QACtC,WAAW,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC;YAC/B,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC;YACrB,CAAC,CAAC,0BAA0B,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;KACpD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,IAAS;IAC/C,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;QAClB,cAAc,EAAE,IAAI,CAAC,gBAAgB,CAAC;QACtC,WAAW,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC;YAC/B,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC;YACrB,CAAC,CAAC,4BAA4B,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;KACtD,CAAC;AACJ,CAAC;AAUD,MAAM,UAAU,0BAA0B,CAAC,IAAsB;IAC/D,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,IAAS;I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CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,MAA0B;IACrE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACzB,OAAO,uBAAuB,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,qBAAqB;AACrB,MAAM,CAAN,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,8BAA8B;IAC9B,yCAAwB,CAAA;AAC1B,CAAC,EAHW,aAAa,KAAb,aAAa,QAGxB","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ErrorModel } from \"@azure-rest/core-client\";\n\n/** A widget. */\nexport interface WidgetSuite {\n /** The widget name. */\n readonly name: string;\n /** The ID of the widget's manufacturer. */\n manufacturerId: string;\n /** The faked shared model. */\n sharedModel?: FakedSharedModel;\n}\n\nexport function widgetSuiteSerializer(item: WidgetSuite): any {\n return {\n manufacturerId: item[\"manufacturerId\"],\n sharedModel: !item[\"sharedModel\"]\n ? item[\"sharedModel\"]\n : fakedSharedModelSerializer(item[\"sharedModel\"]),\n };\n}\n\nexport function widgetSuiteDeserializer(item: any): WidgetSuite {\n return {\n name: item[\"name\"],\n manufacturerId: item[\"manufacturerId\"],\n sharedModel: !item[\"sharedModel\"]\n ? item[\"sharedModel\"]\n : fakedSharedModelDeserializer(item[\"sharedModel\"]),\n };\n}\n\n/** Faked shared model */\nexport interface FakedSharedModel {\n /** The tag. */\n tag: string;\n /** The created date. */\n createdAt: Date;\n}\n\nexport function fakedSharedModelSerializer(item: FakedSharedModel): any {\n return { tag: item[\"tag\"], createdAt: item[\"createdAt\"].toISOString() };\n}\n\nexport function fakedSharedModelDeserializer(item: any): FakedSharedModel {\n return {\n tag: item[\"tag\"],\n createdAt: new Date(item[\"createdAt\"]),\n };\n}\n\n/** Provides status details for long running operations. */\nexport interface ResourceOperationStatusWidgetSuiteWidgetSuiteError {\n /** The unique ID of the operation. */\n id: string;\n /** The status of the operation */\n status: OperationState;\n /** Error object that describes the error when status is \"Failed\". */\n error?: ErrorModel;\n /** The result of the operation. */\n result?: WidgetSuite;\n}\n\nexport function resourceOperationStatusWidgetSuiteWidgetSuiteErrorDeserializer(\n item: any,\n): ResourceOperationStatusWidgetSuiteWidgetSuiteError {\n return {\n id: item[\"id\"],\n status: item[\"status\"],\n error: !item[\"error\"] ? item[\"error\"] : item[\"error\"],\n result: !item[\"result\"] ? item[\"result\"] : widgetSuiteDeserializer(item[\"result\"]),\n };\n}\n\n/** Enum describing allowed operation states. */\nexport enum KnownOperationState {\n /** The operation has not started. */\n NotStarted = \"NotStarted\",\n /** The operation is in progress. */\n Running = \"Running\",\n /** The operation has completed successfully. */\n Succeeded = \"Succeeded\",\n /** The operation has failed. */\n Failed = \"Failed\",\n /** The operation has been canceled by the user. */\n Canceled = \"Canceled\",\n}\n\n/**\n * Enum describing allowed operation states. \\\n * {@link KnownOperationState} can be used interchangeably with OperationState,\n * this enum contains the known values that the service supports.\n * ### Known values supported by the service\n * **NotStarted**: The operation has not started. \\\n * **Running**: The operation is in progress. \\\n * **Succeeded**: The operation has completed successfully. \\\n * **Failed**: The operation has failed. \\\n * **Canceled**: The operation has been canceled by the user.\n */\nexport type OperationState = string;\n\n/** Paged collection of WidgetSuite items */\nexport interface _PagedWidgetSuite {\n /** The WidgetSuite items on this page */\n value: WidgetSuite[];\n /** The link to the next page of items */\n nextLink?: string;\n}\n\nexport function _pagedWidgetSuiteDeserializer(item: any): _PagedWidgetSuite {\n return {\n value: widgetSuiteArrayDeserializer(item[\"value\"]),\n nextLink: item[\"nextLink\"],\n };\n}\n\nexport function widgetSuiteArraySerializer(result: Array<WidgetSuite>): any[] {\n return result.map((item) => {\n return widgetSuiteSerializer(item);\n });\n}\n\nexport function widgetSuiteArrayDeserializer(result: Array<WidgetSuite>): any[] {\n return result.map((item) => {\n return widgetSuiteDeserializer(item);\n });\n}\n\n/** Versions info. */\nexport enum KnownVersions {\n /** The 2022-12-01 version. */\n V20221201 = \"2022-12-01\",\n}\n"]}
|
|
@@ -1,87 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./api/widgets/operations.js";
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { _deleteWidgetDeserialize, _createOrUpdateWidgetDeserialize, } from "./api/widgets/operations.js";
|
|
5
4
|
import { getLongRunningPoller } from "./static-helpers/pollingHelpers.js";
|
|
6
5
|
import { deserializeState } from "@azure/core-lro";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const deserializeHelper = options?.processResponseBody ?? deserializer;
|
|
18
|
-
if (!deserializeHelper) {
|
|
19
|
-
throw new Error(
|
|
20
|
-
`Please ensure the operation is in this client! We can't find its deserializeHelper for ${sourceOperation?.name}.`
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
return getLongRunningPoller(
|
|
24
|
-
client["_client"] ?? client,
|
|
25
|
-
deserializeHelper,
|
|
26
|
-
expectedStatuses,
|
|
27
|
-
{
|
|
28
|
-
updateIntervalInMs: options?.updateIntervalInMs,
|
|
29
|
-
abortSignal: options?.abortSignal,
|
|
30
|
-
resourceLocationConfig,
|
|
31
|
-
restoreFrom: serializedState,
|
|
32
|
-
initialRequestUrl
|
|
6
|
+
/**
|
|
7
|
+
* Creates a poller from the serialized state of another poller. This can be
|
|
8
|
+
* useful when you want to create pollers on a different host or a poller
|
|
9
|
+
* needs to be constructed after the original one is not in scope.
|
|
10
|
+
*/
|
|
11
|
+
export function restorePoller(client, serializedState, sourceOperation, options) {
|
|
12
|
+
const pollerConfig = deserializeState(serializedState).config;
|
|
13
|
+
const { initialRequestUrl, requestMethod, metadata } = pollerConfig;
|
|
14
|
+
if (!initialRequestUrl || !requestMethod) {
|
|
15
|
+
throw new Error(`Invalid serialized state: ${serializedState} for sourceOperation ${sourceOperation?.name}`);
|
|
33
16
|
}
|
|
34
|
-
|
|
17
|
+
const resourceLocationConfig = metadata?.["resourceLocationConfig"];
|
|
18
|
+
const { deserializer, expectedStatuses = [] } = getDeserializationHelper(initialRequestUrl, requestMethod) ?? {};
|
|
19
|
+
const deserializeHelper = options?.processResponseBody ?? deserializer;
|
|
20
|
+
if (!deserializeHelper) {
|
|
21
|
+
throw new Error(`Please ensure the operation is in this client! We can't find its deserializeHelper for ${sourceOperation?.name}.`);
|
|
22
|
+
}
|
|
23
|
+
return getLongRunningPoller(client["_client"] ?? client, deserializeHelper, expectedStatuses, {
|
|
24
|
+
updateIntervalInMs: options?.updateIntervalInMs,
|
|
25
|
+
abortSignal: options?.abortSignal,
|
|
26
|
+
resourceLocationConfig,
|
|
27
|
+
restoreFrom: serializedState,
|
|
28
|
+
initialRequestUrl,
|
|
29
|
+
});
|
|
35
30
|
}
|
|
36
31
|
const deserializeMap = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
"DELETE /widgets/{widgetName}": {
|
|
33
|
+
deserializer: _deleteWidgetDeserialize,
|
|
34
|
+
expectedStatuses: ["202", "200"],
|
|
35
|
+
},
|
|
36
|
+
"PATCH /widgets/{widgetName}": {
|
|
37
|
+
deserializer: _createOrUpdateWidgetDeserialize,
|
|
38
|
+
expectedStatuses: ["201", "200", "202"],
|
|
39
|
+
},
|
|
45
40
|
};
|
|
46
41
|
function getDeserializationHelper(urlStr, method) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
);
|
|
63
|
-
if
|
|
64
|
-
|
|
65
|
-
|
|
42
|
+
const path = new URL(urlStr).pathname;
|
|
43
|
+
const pathParts = path.split("/");
|
|
44
|
+
// Traverse list to match the longest candidate
|
|
45
|
+
// matchedLen: the length of candidate path
|
|
46
|
+
// matchedValue: the matched status code array
|
|
47
|
+
let matchedLen = -1, matchedValue;
|
|
48
|
+
// Iterate the responseMap to find a match
|
|
49
|
+
for (const [key, value] of Object.entries(deserializeMap)) {
|
|
50
|
+
// Extracting the path from the map key which is in format
|
|
51
|
+
// GET /path/foo
|
|
52
|
+
if (!key.startsWith(method)) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const candidatePath = getPathFromMapKey(key);
|
|
56
|
+
// Get each part of the url path
|
|
57
|
+
const candidateParts = candidatePath.split("/");
|
|
58
|
+
// track if we have found a match to return the values found.
|
|
59
|
+
let found = true;
|
|
60
|
+
for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
|
|
61
|
+
if (candidateParts[i]?.startsWith("{") && candidateParts[i]?.indexOf("}") !== -1) {
|
|
62
|
+
const start = candidateParts[i].indexOf("}") + 1, end = candidateParts[i]?.length;
|
|
63
|
+
// If the current part of the candidate is a "template" part
|
|
64
|
+
// Try to use the suffix of pattern to match the path
|
|
65
|
+
// {guid} ==> $
|
|
66
|
+
// {guid}:export ==> :export$
|
|
67
|
+
const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(pathParts[j] || "");
|
|
68
|
+
if (!isMatched) {
|
|
69
|
+
found = false;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
// If the candidate part is not a template and
|
|
75
|
+
// the parts don't match mark the candidate as not found
|
|
76
|
+
// to move on with the next candidate path.
|
|
77
|
+
if (candidateParts[i] !== pathParts[j]) {
|
|
78
|
+
found = false;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// We finished evaluating the current candidate parts
|
|
83
|
+
// Update the matched value if and only if we found the longer pattern
|
|
84
|
+
if (found && candidatePath.length > matchedLen) {
|
|
85
|
+
matchedLen = candidatePath.length;
|
|
86
|
+
matchedValue = value;
|
|
66
87
|
}
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
if (candidateParts[i] !== pathParts[j]) {
|
|
70
|
-
found = false;
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (found && candidatePath.length > matchedLen) {
|
|
75
|
-
matchedLen = candidatePath.length;
|
|
76
|
-
matchedValue = value;
|
|
77
88
|
}
|
|
78
|
-
|
|
79
|
-
return matchedValue;
|
|
89
|
+
return matchedValue;
|
|
80
90
|
}
|
|
81
91
|
function getPathFromMapKey(mapKey) {
|
|
82
|
-
|
|
83
|
-
|
|
92
|
+
const pathStart = mapKey.indexOf("/");
|
|
93
|
+
return mapKey.slice(pathStart);
|
|
84
94
|
}
|
|
85
|
-
|
|
86
|
-
restorePoller
|
|
87
|
-
};
|
|
95
|
+
//# sourceMappingURL=restorePollerHelpers.js.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["/mnt/vss/_work/1/s/sdk/template/template/src/restorePollerHelpers.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { WidgetAnalyticsClient } from \"./widgetAnalyticsClient.js\";\nimport {\n _deleteWidgetDeserialize,\n _createOrUpdateWidgetDeserialize,\n} from \"./api/widgets/operations.js\";\nimport { getLongRunningPoller } from \"./static-helpers/pollingHelpers.js\";\nimport type { OperationOptions, PathUncheckedResponse } from \"@azure-rest/core-client\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { PollerLike, OperationState, ResourceLocationConfig } from \"@azure/core-lro\";\nimport { deserializeState } from \"@azure/core-lro\";\n\nexport interface RestorePollerOptions<\n TResult,\n TResponse extends PathUncheckedResponse = PathUncheckedResponse,\n> extends OperationOptions {\n /** Delay to wait until next poll, in milliseconds. */\n updateIntervalInMs?: number;\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n /** Deserialization function for raw response body */\n processResponseBody?: (result: TResponse) => Promise<TResult>;\n}\n\n/**\n * Creates a poller from the serialized state of another poller. This can be\n * useful when you want to create pollers on a different host or a poller\n * needs to be constructed after the original one is not in scope.\n */\nexport function restorePoller<TResponse extends PathUncheckedResponse, TResult>(\n client: WidgetAnalyticsClient,\n serializedState: string,\n sourceOperation: (...args: any[]) => PollerLike<OperationState<TResult>, TResult>,\n options?: RestorePollerOptions<TResult>,\n): PollerLike<OperationState<TResult>, TResult> {\n const pollerConfig = deserializeState(serializedState).config;\n const { initialRequestUrl, requestMethod, metadata } = pollerConfig;\n if (!initialRequestUrl || !requestMethod) {\n throw new Error(\n `Invalid serialized state: ${serializedState} for sourceOperation ${sourceOperation?.name}`,\n );\n }\n const resourceLocationConfig = metadata?.[\"resourceLocationConfig\"] as\n | ResourceLocationConfig\n | undefined;\n const { deserializer, expectedStatuses = [] } =\n getDeserializationHelper(initialRequestUrl, requestMethod) ?? {};\n const deserializeHelper = options?.processResponseBody ?? deserializer;\n if (!deserializeHelper) {\n throw new Error(\n `Please ensure the operation is in this client! We can't find its deserializeHelper for ${sourceOperation?.name}.`,\n );\n }\n return getLongRunningPoller(\n (client as any)[\"_client\"] ?? client,\n deserializeHelper as (result: TResponse) => Promise<TResult>,\n expectedStatuses,\n {\n updateIntervalInMs: options?.updateIntervalInMs,\n abortSignal: options?.abortSignal,\n resourceLocationConfig,\n restoreFrom: serializedState,\n initialRequestUrl,\n },\n );\n}\n\ninterface DeserializationHelper {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n deserializer: Function;\n expectedStatuses: string[];\n}\n\nconst deserializeMap: Record<string, DeserializationHelper> = {\n \"DELETE /widgets/{widgetName}\": {\n deserializer: _deleteWidgetDeserialize,\n expectedStatuses: [\"202\", \"200\"],\n },\n \"PATCH /widgets/{widgetName}\": {\n deserializer: _createOrUpdateWidgetDeserialize,\n expectedStatuses: [\"201\", \"200\", \"202\"],\n },\n};\n\nfunction getDeserializationHelper(\n urlStr: string,\n method: string,\n): DeserializationHelper | undefined {\n const path = new URL(urlStr).pathname;\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: DeserializationHelper | undefined;\n\n // Iterate the responseMap to find a match\n for (const [key, value] of Object.entries(deserializeMap)) {\n // Extracting the path from the map key which is in format\n // GET /path/foo\n if (!key.startsWith(method)) {\n continue;\n }\n const candidatePath = getPathFromMapKey(key);\n // Get each part of the url path\n const candidateParts = candidatePath.split(\"/\");\n\n // track if we have found a match to return the values found.\n let found = true;\n for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {\n if (candidateParts[i]?.startsWith(\"{\") && candidateParts[i]?.indexOf(\"}\") !== -1) {\n const start = candidateParts[i]!.indexOf(\"}\") + 1,\n end = candidateParts[i]?.length;\n // If the current part of the candidate is a \"template\" part\n // Try to use the suffix of pattern to match the path\n // {guid} ==> $\n // {guid}:export ==> :export$\n const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(\n pathParts[j] || \"\",\n );\n\n if (!isMatched) {\n found = false;\n break;\n }\n continue;\n }\n\n // If the candidate part is not a template and\n // the parts don't match mark the candidate as not found\n // to move on with the next candidate path.\n if (candidateParts[i] !== pathParts[j]) {\n found = false;\n break;\n }\n }\n\n // We finished evaluating the current candidate parts\n // Update the matched value if and only if we found the longer pattern\n if (found && candidatePath.length > matchedLen) {\n matchedLen = candidatePath.length;\n matchedValue = value;\n }\n }\n\n return matchedValue;\n}\n\nfunction getPathFromMapKey(mapKey: string): string {\n const pathStart = mapKey.indexOf(\"/\");\n return mapKey.slice(pathStart);\n}\n"],
|
|
5
|
-
"mappings": "AAIA;AAAA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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 { WidgetAnalyticsClient } from \"./widgetAnalyticsClient.js\";\nimport {\n _deleteWidgetDeserialize,\n _createOrUpdateWidgetDeserialize,\n} from \"./api/widgets/operations.js\";\nimport { getLongRunningPoller } from \"./static-helpers/pollingHelpers.js\";\nimport type { OperationOptions, PathUncheckedResponse } from \"@azure-rest/core-client\";\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\nimport type { PollerLike, OperationState, ResourceLocationConfig } from \"@azure/core-lro\";\nimport { deserializeState } from \"@azure/core-lro\";\n\nexport interface RestorePollerOptions<\n TResult,\n TResponse extends PathUncheckedResponse = PathUncheckedResponse,\n> extends OperationOptions {\n /** Delay to wait until next poll, in milliseconds. */\n updateIntervalInMs?: number;\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n /** Deserialization function for raw response body */\n processResponseBody?: (result: TResponse) => Promise<TResult>;\n}\n\n/**\n * Creates a poller from the serialized state of another poller. This can be\n * useful when you want to create pollers on a different host or a poller\n * needs to be constructed after the original one is not in scope.\n */\nexport function restorePoller<TResponse extends PathUncheckedResponse, TResult>(\n client: WidgetAnalyticsClient,\n serializedState: string,\n sourceOperation: (...args: any[]) => PollerLike<OperationState<TResult>, TResult>,\n options?: RestorePollerOptions<TResult>,\n): PollerLike<OperationState<TResult>, TResult> {\n const pollerConfig = deserializeState(serializedState).config;\n const { initialRequestUrl, requestMethod, metadata } = pollerConfig;\n if (!initialRequestUrl || !requestMethod) {\n throw new Error(\n `Invalid serialized state: ${serializedState} for sourceOperation ${sourceOperation?.name}`,\n );\n }\n const resourceLocationConfig = metadata?.[\"resourceLocationConfig\"] as\n | ResourceLocationConfig\n | undefined;\n const { deserializer, expectedStatuses = [] } =\n getDeserializationHelper(initialRequestUrl, requestMethod) ?? {};\n const deserializeHelper = options?.processResponseBody ?? deserializer;\n if (!deserializeHelper) {\n throw new Error(\n `Please ensure the operation is in this client! We can't find its deserializeHelper for ${sourceOperation?.name}.`,\n );\n }\n return getLongRunningPoller(\n (client as any)[\"_client\"] ?? client,\n deserializeHelper as (result: TResponse) => Promise<TResult>,\n expectedStatuses,\n {\n updateIntervalInMs: options?.updateIntervalInMs,\n abortSignal: options?.abortSignal,\n resourceLocationConfig,\n restoreFrom: serializedState,\n initialRequestUrl,\n },\n );\n}\n\ninterface DeserializationHelper {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n deserializer: Function;\n expectedStatuses: string[];\n}\n\nconst deserializeMap: Record<string, DeserializationHelper> = {\n \"DELETE /widgets/{widgetName}\": {\n deserializer: _deleteWidgetDeserialize,\n expectedStatuses: [\"202\", \"200\"],\n },\n \"PATCH /widgets/{widgetName}\": {\n deserializer: _createOrUpdateWidgetDeserialize,\n expectedStatuses: [\"201\", \"200\", \"202\"],\n },\n};\n\nfunction getDeserializationHelper(\n urlStr: string,\n method: string,\n): DeserializationHelper | undefined {\n const path = new URL(urlStr).pathname;\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: DeserializationHelper | undefined;\n\n // Iterate the responseMap to find a match\n for (const [key, value] of Object.entries(deserializeMap)) {\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,104 +1,118 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
1
3
|
import { createRestError } from "@azure-rest/core-client";
|
|
2
4
|
import { RestError } from "@azure/core-rest-pipeline";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Helper to paginate results in a generic way and return a PagedAsyncIterableIterator
|
|
7
|
+
*/
|
|
8
|
+
export function buildPagedAsyncIterator(client, getInitialResponse, processResponseBody, expectedStatuses, options = {}) {
|
|
9
|
+
const itemName = options.itemName ?? "value";
|
|
10
|
+
const nextLinkName = options.nextLinkName ?? "nextLink";
|
|
11
|
+
const pagedResult = {
|
|
12
|
+
getPage: async (pageLink) => {
|
|
13
|
+
const result = pageLink === undefined
|
|
14
|
+
? await getInitialResponse()
|
|
15
|
+
: await client.pathUnchecked(pageLink).get();
|
|
16
|
+
checkPagingRequest(result, expectedStatuses);
|
|
17
|
+
const results = await processResponseBody(result);
|
|
18
|
+
const nextLink = getNextLink(results, nextLinkName);
|
|
19
|
+
const values = getElements(results, itemName);
|
|
20
|
+
return {
|
|
21
|
+
page: values,
|
|
22
|
+
nextPageLink: nextLink,
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
byPage: (settings) => {
|
|
26
|
+
const { continuationToken } = settings ?? {};
|
|
27
|
+
return getPageAsyncIterator(pagedResult, {
|
|
28
|
+
pageLink: continuationToken,
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
return getPagedAsyncIterator(pagedResult);
|
|
26
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* returns an async iterator that iterates over results. It also has a `byPage`
|
|
36
|
+
* method that returns pages of items at once.
|
|
37
|
+
*
|
|
38
|
+
* @param pagedResult - an object that specifies how to get pages.
|
|
39
|
+
* @returns a paged async iterator that iterates over results.
|
|
40
|
+
*/
|
|
27
41
|
function getPagedAsyncIterator(pagedResult) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
const iter = getItemAsyncIterator(pagedResult);
|
|
43
|
+
return {
|
|
44
|
+
next() {
|
|
45
|
+
return iter.next();
|
|
46
|
+
},
|
|
47
|
+
[Symbol.asyncIterator]() {
|
|
48
|
+
return this;
|
|
49
|
+
},
|
|
50
|
+
byPage: pagedResult?.byPage ??
|
|
51
|
+
((settings) => {
|
|
52
|
+
const { continuationToken } = settings ?? {};
|
|
53
|
+
return getPageAsyncIterator(pagedResult, {
|
|
54
|
+
pageLink: continuationToken,
|
|
55
|
+
});
|
|
56
|
+
}),
|
|
57
|
+
};
|
|
43
58
|
}
|
|
44
59
|
async function* getItemAsyncIterator(pagedResult) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
const pages = getPageAsyncIterator(pagedResult);
|
|
61
|
+
for await (const page of pages) {
|
|
62
|
+
yield* page;
|
|
63
|
+
}
|
|
49
64
|
}
|
|
50
65
|
async function* getPageAsyncIterator(pagedResult, options = {}) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (!response) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
let result = response.page;
|
|
57
|
-
result.continuationToken = response.nextPageLink;
|
|
58
|
-
yield result;
|
|
59
|
-
while (response.nextPageLink) {
|
|
60
|
-
response = await pagedResult.getPage(response.nextPageLink);
|
|
66
|
+
const { pageLink } = options;
|
|
67
|
+
let response = await pagedResult.getPage(pageLink ?? pagedResult.firstPageLink);
|
|
61
68
|
if (!response) {
|
|
62
|
-
|
|
69
|
+
return;
|
|
63
70
|
}
|
|
64
|
-
result = response.page;
|
|
71
|
+
let result = response.page;
|
|
65
72
|
result.continuationToken = response.nextPageLink;
|
|
66
73
|
yield result;
|
|
67
|
-
|
|
74
|
+
while (response.nextPageLink) {
|
|
75
|
+
response = await pagedResult.getPage(response.nextPageLink);
|
|
76
|
+
if (!response) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
result = response.page;
|
|
80
|
+
result.continuationToken = response.nextPageLink;
|
|
81
|
+
yield result;
|
|
82
|
+
}
|
|
68
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Gets for the value of nextLink in the body
|
|
86
|
+
*/
|
|
69
87
|
function getNextLink(body, nextLinkName) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
return nextLink;
|
|
88
|
+
if (!nextLinkName) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
const nextLink = body[nextLinkName];
|
|
92
|
+
if (typeof nextLink !== "string" && typeof nextLink !== "undefined" && nextLink !== null) {
|
|
93
|
+
throw new RestError(`Body Property ${nextLinkName} should be a string or undefined or null but got ${typeof nextLink}`);
|
|
94
|
+
}
|
|
95
|
+
if (nextLink === null) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
return nextLink;
|
|
83
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Gets the elements of the current request in the body.
|
|
102
|
+
*/
|
|
84
103
|
function getElements(body, itemName) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
return value ?? [];
|
|
104
|
+
const value = body[itemName];
|
|
105
|
+
if (!Array.isArray(value)) {
|
|
106
|
+
throw new RestError(`Couldn't paginate response\n Body doesn't contain an array property with name: ${itemName}`);
|
|
107
|
+
}
|
|
108
|
+
return value ?? [];
|
|
93
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Checks if a request failed
|
|
112
|
+
*/
|
|
94
113
|
function checkPagingRequest(response, expectedStatuses) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
response
|
|
99
|
-
);
|
|
100
|
-
}
|
|
114
|
+
if (!expectedStatuses.includes(response.status)) {
|
|
115
|
+
throw createRestError(`Pagination failed with unexpected statusCode ${response.status}`, response);
|
|
116
|
+
}
|
|
101
117
|
}
|
|
102
|
-
|
|
103
|
-
buildPagedAsyncIterator
|
|
104
|
-
};
|
|
118
|
+
//# sourceMappingURL=pagingHelpers.js.map
|