@azure-tools/typespec-ts 0.31.0 → 0.32.0
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 +25 -7
- package/README.md +8 -0
- package/dist/src/contextManager.d.ts +2 -0
- package/dist/src/contextManager.d.ts.map +1 -1
- package/dist/src/contextManager.js.map +1 -1
- package/dist/src/framework/dependency.d.ts +69 -0
- package/dist/src/framework/dependency.d.ts.map +1 -0
- package/dist/src/framework/dependency.js +2 -0
- package/dist/src/framework/dependency.js.map +1 -0
- package/dist/src/framework/hooks/binder.d.ts +8 -2
- package/dist/src/framework/hooks/binder.d.ts.map +1 -1
- package/dist/src/framework/hooks/binder.js +107 -20
- package/dist/src/framework/hooks/binder.js.map +1 -1
- package/dist/src/framework/hooks/useDependencies.d.ts +4 -0
- package/dist/src/framework/hooks/useDependencies.d.ts.map +1 -0
- package/dist/src/framework/hooks/useDependencies.js +13 -0
- package/dist/src/framework/hooks/useDependencies.js.map +1 -0
- package/dist/src/framework/load-static-helpers.d.ts +16 -0
- package/dist/src/framework/load-static-helpers.d.ts.map +1 -0
- package/dist/src/framework/load-static-helpers.js +93 -0
- package/dist/src/framework/load-static-helpers.js.map +1 -0
- package/dist/src/framework/reference.d.ts +1 -1
- package/dist/src/framework/reference.d.ts.map +1 -1
- package/dist/src/framework/reference.js +16 -2
- package/dist/src/framework/reference.js.map +1 -1
- package/dist/src/framework/sample.js +1 -1
- package/dist/src/framework/sample.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +113 -79
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib.d.ts +10 -1
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +8 -1
- package/dist/src/lib.js.map +1 -1
- package/dist/src/modular/buildClassicalClient.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalClient.js +12 -9
- package/dist/src/modular/buildClassicalClient.js.map +1 -1
- package/dist/src/modular/buildClassicalOperationGroups.d.ts.map +1 -1
- package/dist/src/modular/buildClassicalOperationGroups.js +1 -11
- package/dist/src/modular/buildClassicalOperationGroups.js.map +1 -1
- package/dist/src/modular/buildClientContext.d.ts.map +1 -1
- package/dist/src/modular/buildClientContext.js +73 -52
- package/dist/src/modular/buildClientContext.js.map +1 -1
- package/dist/src/modular/buildCodeModel.d.ts +1 -1
- package/dist/src/modular/buildCodeModel.d.ts.map +1 -1
- package/dist/src/modular/buildCodeModel.js +36 -62
- package/dist/src/modular/buildCodeModel.js.map +1 -1
- package/dist/src/modular/buildHelperSerializers.d.ts.map +1 -1
- package/dist/src/modular/buildHelperSerializers.js.map +1 -1
- package/dist/src/modular/buildOperations.d.ts +1 -3
- package/dist/src/modular/buildOperations.d.ts.map +1 -1
- package/dist/src/modular/buildOperations.js +9 -69
- package/dist/src/modular/buildOperations.js.map +1 -1
- package/dist/src/modular/buildRestorePoller.d.ts +3 -0
- package/dist/src/modular/buildRestorePoller.d.ts.map +1 -0
- package/dist/src/modular/buildRestorePoller.js +203 -0
- package/dist/src/modular/buildRestorePoller.js.map +1 -0
- package/dist/src/modular/buildRootIndex.d.ts.map +1 -1
- package/dist/src/modular/buildRootIndex.js +37 -0
- package/dist/src/modular/buildRootIndex.js.map +1 -1
- package/dist/src/modular/emitLoggerFile.d.ts +4 -0
- package/dist/src/modular/emitLoggerFile.d.ts.map +1 -0
- package/dist/src/modular/emitLoggerFile.js +16 -0
- package/dist/src/modular/emitLoggerFile.js.map +1 -0
- package/dist/src/modular/emitModels.d.ts.map +1 -1
- package/dist/src/modular/emitModels.js +0 -5
- package/dist/src/modular/emitModels.js.map +1 -1
- package/dist/src/modular/external-dependencies.d.ts +26 -0
- package/dist/src/modular/external-dependencies.d.ts.map +1 -0
- package/dist/src/modular/external-dependencies.js +137 -0
- package/dist/src/modular/external-dependencies.js.map +1 -0
- package/dist/src/modular/helpers/clientHelpers.d.ts +13 -6
- package/dist/src/modular/helpers/clientHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/clientHelpers.js +92 -7
- package/dist/src/modular/helpers/clientHelpers.js.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts +6 -1
- package/dist/src/modular/helpers/operationHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/operationHelpers.js +43 -69
- package/dist/src/modular/helpers/operationHelpers.js.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.d.ts +1 -0
- package/dist/src/modular/helpers/typeHelpers.d.ts.map +1 -1
- package/dist/src/modular/helpers/typeHelpers.js +6 -0
- package/dist/src/modular/helpers/typeHelpers.js.map +1 -1
- package/dist/src/modular/interfaces.d.ts +1 -0
- package/dist/src/modular/interfaces.d.ts.map +1 -1
- package/dist/src/modular/serialization/buildSerializerFunction.d.ts.map +1 -1
- package/dist/src/modular/serialization/buildSerializerFunction.js +2 -20
- package/dist/src/modular/serialization/buildSerializerFunction.js.map +1 -1
- package/dist/src/modular/static-helpers-metadata.d.ts +72 -0
- package/dist/src/modular/static-helpers-metadata.d.ts.map +1 -0
- package/dist/src/modular/static-helpers-metadata.js +72 -0
- package/dist/src/modular/static-helpers-metadata.js.map +1 -0
- package/dist/src/transform/transfromRLCOptions.d.ts.map +1 -1
- package/dist/src/transform/transfromRLCOptions.js +56 -49
- package/dist/src/transform/transfromRLCOptions.js.map +1 -1
- package/dist/src/utils/credentialUtils.d.ts +10 -0
- package/dist/src/utils/credentialUtils.d.ts.map +1 -0
- package/dist/src/utils/credentialUtils.js +37 -0
- package/dist/src/utils/credentialUtils.js.map +1 -0
- package/dist/src/utils/dirname.d.ts +9 -0
- package/dist/src/utils/dirname.d.ts.map +1 -0
- package/dist/src/utils/dirname.js +12 -0
- package/dist/src/utils/dirname.js.map +1 -0
- package/dist/src/utils/emitUtil.d.ts.map +1 -1
- package/dist/src/utils/emitUtil.js +3 -5
- package/dist/src/utils/emitUtil.js.map +1 -1
- package/dist/src/utils/modelUtils.d.ts +1 -1
- package/dist/src/utils/modelUtils.js +3 -2
- package/dist/src/utils/modelUtils.js.map +1 -1
- package/dist/src/utils/operationUtil.d.ts.map +1 -1
- package/dist/src/utils/operationUtil.js +20 -2
- package/dist/src/utils/operationUtil.js.map +1 -1
- package/dist/src/utils/resolve-project-root.d.ts +7 -0
- package/dist/src/utils/resolve-project-root.d.ts.map +1 -0
- package/dist/src/utils/resolve-project-root.js +22 -0
- package/dist/src/utils/resolve-project-root.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +29 -25
- package/src/contextManager.ts +2 -0
- package/src/framework/dependency.ts +56 -0
- package/src/framework/hooks/binder.ts +144 -27
- package/src/framework/hooks/useDependencies.ts +18 -0
- package/src/framework/load-static-helpers.ts +174 -0
- package/src/framework/reference.ts +27 -3
- package/src/framework/sample.ts +1 -1
- package/src/index.ts +154 -113
- package/src/lib.ts +8 -1
- package/src/modular/buildClassicalClient.ts +14 -12
- package/src/modular/buildClassicalOperationGroups.ts +1 -24
- package/src/modular/buildClientContext.ts +93 -63
- package/src/modular/buildCodeModel.ts +93 -128
- package/src/modular/buildHelperSerializers.ts +1 -0
- package/src/modular/buildOperations.ts +9 -110
- package/src/modular/buildRestorePoller.ts +239 -0
- package/src/modular/buildRootIndex.ts +68 -0
- package/src/modular/emitLoggerFile.ts +28 -0
- package/src/modular/emitModels.ts +0 -8
- package/src/modular/external-dependencies.ts +140 -0
- package/src/modular/helpers/clientHelpers.ts +148 -14
- package/src/modular/helpers/operationHelpers.ts +72 -109
- package/src/modular/helpers/typeHelpers.ts +8 -0
- package/src/modular/interfaces.ts +1 -0
- package/src/modular/serialization/buildSerializerFunction.ts +3 -33
- package/src/modular/static-helpers-metadata.ts +73 -0
- package/src/transform/transfromRLCOptions.ts +61 -53
- package/src/utils/credentialUtils.ts +41 -0
- package/src/utils/dirname.ts +12 -0
- package/src/utils/emitUtil.ts +3 -2
- package/src/utils/modelUtils.ts +4 -4
- package/src/utils/operationUtil.ts +25 -2
- package/src/utils/resolve-project-root.ts +28 -0
- package/static/static-helpers/pagingHelpers.ts +274 -0
- package/static/static-helpers/pollingHelpers.ts +137 -0
- package/static/static-helpers/serialization/build-csv-collection.ts +6 -0
- package/static/static-helpers/serialization/build-multi-collection.ts +13 -0
- package/static/static-helpers/serialization/build-pipe-collection.ts +3 -0
- package/static/static-helpers/serialization/build-ssv-collection.ts +3 -0
- package/static/static-helpers/serialization/build-tsv-collection.ts +3 -0
- package/dist/src/modular/buildLroFiles.d.ts +0 -24
- package/dist/src/modular/buildLroFiles.d.ts.map +0 -1
- package/dist/src/modular/buildLroFiles.js +0 -393
- package/dist/src/modular/buildLroFiles.js.map +0 -1
- package/dist/src/modular/buildPagingFiles.d.ts +0 -4
- package/dist/src/modular/buildPagingFiles.d.ts.map +0 -1
- package/dist/src/modular/buildPagingFiles.js +0 -333
- package/dist/src/modular/buildPagingFiles.js.map +0 -1
- package/src/modular/buildLroFiles.ts +0 -429
- package/src/modular/buildPagingFiles.ts +0 -356
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import {
|
|
3
|
-
hasPagingOnlyOperation,
|
|
4
|
-
isPagingOnlyOperation
|
|
5
|
-
} from "./helpers/operationHelpers.js";
|
|
6
|
-
import { Client, ModularCodeModel } from "./modularCodeModel.js";
|
|
7
|
-
|
|
8
|
-
export function buildPagingTypes(client: Client, codeModel: ModularCodeModel) {
|
|
9
|
-
if (!hasPagingOnlyOperation(client)) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
const filePath = path.join(
|
|
13
|
-
codeModel.modularOptions.sourceRoot,
|
|
14
|
-
client.subfolder ?? "",
|
|
15
|
-
`models/pagingTypes.ts`
|
|
16
|
-
);
|
|
17
|
-
const fileContent = codeModel.project.createSourceFile(filePath, undefined, {
|
|
18
|
-
overwrite: true
|
|
19
|
-
});
|
|
20
|
-
fileContent.addStatements([
|
|
21
|
-
`
|
|
22
|
-
/**
|
|
23
|
-
* Options for the byPage method
|
|
24
|
-
*/
|
|
25
|
-
export interface PageSettings {
|
|
26
|
-
/**
|
|
27
|
-
* A reference to a specific page to start iterating from.
|
|
28
|
-
*/
|
|
29
|
-
continuationToken?: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* An interface that describes a page of results.
|
|
34
|
-
*/
|
|
35
|
-
export type ContinuablePage<TElement, TPage = TElement[]> = TPage & {
|
|
36
|
-
/**
|
|
37
|
-
* The token that keeps track of where to continue the iterator
|
|
38
|
-
*/
|
|
39
|
-
continuationToken?: string;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* An interface that allows async iterable iteration both to completion and by page.
|
|
44
|
-
*/
|
|
45
|
-
export interface PagedAsyncIterableIterator<
|
|
46
|
-
TElement,
|
|
47
|
-
TPage = TElement[],
|
|
48
|
-
TPageSettings extends PageSettings = PageSettings
|
|
49
|
-
> {
|
|
50
|
-
/**
|
|
51
|
-
* The next method, part of the iteration protocol
|
|
52
|
-
*/
|
|
53
|
-
next(): Promise<IteratorResult<TElement>>;
|
|
54
|
-
/**
|
|
55
|
-
* The connection to the async iterator, part of the iteration protocol
|
|
56
|
-
*/
|
|
57
|
-
[Symbol.asyncIterator](): PagedAsyncIterableIterator<
|
|
58
|
-
TElement,
|
|
59
|
-
TPage,
|
|
60
|
-
TPageSettings
|
|
61
|
-
>;
|
|
62
|
-
/**
|
|
63
|
-
* Return an AsyncIterableIterator that works a page at a time
|
|
64
|
-
*/
|
|
65
|
-
byPage: (
|
|
66
|
-
settings?: TPageSettings
|
|
67
|
-
) => AsyncIterableIterator<ContinuablePage<TElement, TPage>>;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* An interface that describes how to communicate with the service.
|
|
72
|
-
*/
|
|
73
|
-
export interface PagedResult<
|
|
74
|
-
TElement,
|
|
75
|
-
TPage = TElement[],
|
|
76
|
-
TPageSettings extends PageSettings = PageSettings
|
|
77
|
-
> {
|
|
78
|
-
/**
|
|
79
|
-
* Link to the first page of results.
|
|
80
|
-
*/
|
|
81
|
-
firstPageLink?: string;
|
|
82
|
-
/**
|
|
83
|
-
* A method that returns a page of results.
|
|
84
|
-
*/
|
|
85
|
-
getPage: (
|
|
86
|
-
pageLink?: string
|
|
87
|
-
) => Promise<{ page: TPage; nextPageLink?: string } | undefined>;
|
|
88
|
-
/**
|
|
89
|
-
* a function to implement the \`byPage\` method on the paged async iterator.
|
|
90
|
-
*/
|
|
91
|
-
byPage?: (
|
|
92
|
-
settings?: TPageSettings
|
|
93
|
-
) => AsyncIterableIterator<ContinuablePage<TElement, TPage>>;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* A function to extract elements from a page.
|
|
97
|
-
*/
|
|
98
|
-
toElements?: (page: TPage) => TElement[];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Options for the paging helper
|
|
103
|
-
*/
|
|
104
|
-
export interface BuildPagedAsyncIteratorOptions {
|
|
105
|
-
itemName?: string;
|
|
106
|
-
nextLinkName?: string;
|
|
107
|
-
}
|
|
108
|
-
`
|
|
109
|
-
]);
|
|
110
|
-
|
|
111
|
-
return fileContent;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function buildPagingHelpers(
|
|
115
|
-
client: Client,
|
|
116
|
-
codeModel: ModularCodeModel,
|
|
117
|
-
needUnexpectedHelper: boolean = true,
|
|
118
|
-
isMultiClients: boolean = false
|
|
119
|
-
) {
|
|
120
|
-
const pagingOperstions = client.operationGroups
|
|
121
|
-
.flatMap((op) => op.operations)
|
|
122
|
-
.filter(isPagingOnlyOperation);
|
|
123
|
-
if (!pagingOperstions || pagingOperstions.length === 0) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const checkingPagingRequestContent = needUnexpectedHelper
|
|
128
|
-
? `if (isUnexpected(response)) {
|
|
129
|
-
throw createRestError(
|
|
130
|
-
\`Pagination failed with unexpected statusCode \${response.status}\`,
|
|
131
|
-
response
|
|
132
|
-
);
|
|
133
|
-
}`
|
|
134
|
-
: `const Http2xxStatusCodes = [
|
|
135
|
-
"200",
|
|
136
|
-
"201",
|
|
137
|
-
"202",
|
|
138
|
-
"203",
|
|
139
|
-
"204",
|
|
140
|
-
"205",
|
|
141
|
-
"206",
|
|
142
|
-
"207",
|
|
143
|
-
"208",
|
|
144
|
-
"226",
|
|
145
|
-
];
|
|
146
|
-
if (!Http2xxStatusCodes.includes(response.status)) {
|
|
147
|
-
throw createRestError(
|
|
148
|
-
\`Pagination failed with unexpected statusCode \${response.status}\`,
|
|
149
|
-
response
|
|
150
|
-
);
|
|
151
|
-
}`;
|
|
152
|
-
|
|
153
|
-
const unexpectedHelperImport = needUnexpectedHelper
|
|
154
|
-
? `import { isUnexpected } from "${
|
|
155
|
-
isMultiClients ? "../" : ""
|
|
156
|
-
}../rest/index.js";`
|
|
157
|
-
: "";
|
|
158
|
-
const pagingTypesPath = `../models/pagingTypes.js`;
|
|
159
|
-
const filePath = path.join(
|
|
160
|
-
codeModel.modularOptions.sourceRoot,
|
|
161
|
-
client.subfolder ?? "",
|
|
162
|
-
`api/pagingHelpers.ts`
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
const fileContent = codeModel.project.createSourceFile(filePath, undefined, {
|
|
166
|
-
overwrite: true
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
fileContent.addStatements([
|
|
170
|
-
`
|
|
171
|
-
import {
|
|
172
|
-
Client,
|
|
173
|
-
createRestError,
|
|
174
|
-
PathUncheckedResponse
|
|
175
|
-
} from "@azure-rest/core-client";
|
|
176
|
-
import { RestError } from "@azure/core-rest-pipeline";
|
|
177
|
-
import {
|
|
178
|
-
BuildPagedAsyncIteratorOptions,
|
|
179
|
-
ContinuablePage,
|
|
180
|
-
PageSettings,
|
|
181
|
-
PagedAsyncIterableIterator,
|
|
182
|
-
PagedResult,
|
|
183
|
-
} from "${pagingTypesPath}";
|
|
184
|
-
${unexpectedHelperImport}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Helper to paginate results in a generic way and return a PagedAsyncIterableIterator
|
|
188
|
-
*/
|
|
189
|
-
export function buildPagedAsyncIterator<
|
|
190
|
-
TElement,
|
|
191
|
-
TPage = TElement[],
|
|
192
|
-
TPageSettings extends PageSettings = PageSettings,
|
|
193
|
-
TResponse extends PathUncheckedResponse = PathUncheckedResponse
|
|
194
|
-
>(
|
|
195
|
-
client: Client,
|
|
196
|
-
getInitialResponse: () => PromiseLike<TResponse>,
|
|
197
|
-
processResponseBody: (result: TResponse) => PromiseLike<unknown>,
|
|
198
|
-
options: BuildPagedAsyncIteratorOptions = {}
|
|
199
|
-
): PagedAsyncIterableIterator<TElement, TPage, TPageSettings> {
|
|
200
|
-
const itemName = options.itemName ?? "value";
|
|
201
|
-
const nextLinkName = options.nextLinkName ?? "nextLink";
|
|
202
|
-
const pagedResult: PagedResult<TElement, TPage, TPageSettings> = {
|
|
203
|
-
getPage: async (pageLink?: string) => {
|
|
204
|
-
const result =
|
|
205
|
-
pageLink === undefined
|
|
206
|
-
? await getInitialResponse()
|
|
207
|
-
: await client.pathUnchecked(pageLink).get();
|
|
208
|
-
checkPagingRequest(result);
|
|
209
|
-
const results = await processResponseBody(result as TResponse);
|
|
210
|
-
const nextLink = getNextLink(results, nextLinkName);
|
|
211
|
-
const values = getElements<TElement>(results, itemName) as TPage;
|
|
212
|
-
return {
|
|
213
|
-
page: values,
|
|
214
|
-
nextPageLink: nextLink,
|
|
215
|
-
};
|
|
216
|
-
},
|
|
217
|
-
byPage: (settings?: TPageSettings) => {
|
|
218
|
-
const { continuationToken } = settings ?? {};
|
|
219
|
-
return getPageAsyncIterator(pagedResult, {
|
|
220
|
-
pageLink: continuationToken,
|
|
221
|
-
});
|
|
222
|
-
},
|
|
223
|
-
};
|
|
224
|
-
return getPagedAsyncIterator(pagedResult);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* returns an async iterator that iterates over results. It also has a \`byPage\`
|
|
229
|
-
* method that returns pages of items at once.
|
|
230
|
-
*
|
|
231
|
-
* @param pagedResult - an object that specifies how to get pages.
|
|
232
|
-
* @returns a paged async iterator that iterates over results.
|
|
233
|
-
*/
|
|
234
|
-
|
|
235
|
-
function getPagedAsyncIterator<
|
|
236
|
-
TElement,
|
|
237
|
-
TPage = TElement[],
|
|
238
|
-
TPageSettings extends PageSettings = PageSettings
|
|
239
|
-
>(
|
|
240
|
-
pagedResult: PagedResult<TElement, TPage, TPageSettings>
|
|
241
|
-
): PagedAsyncIterableIterator<TElement, TPage, TPageSettings> {
|
|
242
|
-
const iter = getItemAsyncIterator<TElement, TPage, TPageSettings>(
|
|
243
|
-
pagedResult
|
|
244
|
-
);
|
|
245
|
-
return {
|
|
246
|
-
next() {
|
|
247
|
-
return iter.next();
|
|
248
|
-
},
|
|
249
|
-
[Symbol.asyncIterator]() {
|
|
250
|
-
return this;
|
|
251
|
-
},
|
|
252
|
-
byPage:
|
|
253
|
-
pagedResult?.byPage ??
|
|
254
|
-
((settings?: TPageSettings) => {
|
|
255
|
-
const { continuationToken } = settings ?? {};
|
|
256
|
-
return getPageAsyncIterator(pagedResult, {
|
|
257
|
-
pageLink: continuationToken,
|
|
258
|
-
});
|
|
259
|
-
}),
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
async function* getItemAsyncIterator<
|
|
264
|
-
TElement,
|
|
265
|
-
TPage,
|
|
266
|
-
TPageSettings extends PageSettings
|
|
267
|
-
>(
|
|
268
|
-
pagedResult: PagedResult<TElement, TPage, TPageSettings>
|
|
269
|
-
): AsyncIterableIterator<TElement> {
|
|
270
|
-
const pages = getPageAsyncIterator(pagedResult);
|
|
271
|
-
for await (const page of pages) {
|
|
272
|
-
yield* page as unknown as TElement[];
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
async function* getPageAsyncIterator<
|
|
277
|
-
TElement,
|
|
278
|
-
TPage,
|
|
279
|
-
TPageSettings extends PageSettings
|
|
280
|
-
>(
|
|
281
|
-
pagedResult: PagedResult<TElement, TPage, TPageSettings>,
|
|
282
|
-
options: {
|
|
283
|
-
pageLink?: string;
|
|
284
|
-
} = {}
|
|
285
|
-
): AsyncIterableIterator<ContinuablePage<TElement, TPage>> {
|
|
286
|
-
const { pageLink } = options;
|
|
287
|
-
let response = await pagedResult.getPage(
|
|
288
|
-
pageLink ?? pagedResult.firstPageLink
|
|
289
|
-
);
|
|
290
|
-
if (!response) {
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
let result = response.page as ContinuablePage<TElement, TPage>;
|
|
294
|
-
result.continuationToken = response.nextPageLink;
|
|
295
|
-
yield result;
|
|
296
|
-
while (response.nextPageLink) {
|
|
297
|
-
response = await pagedResult.getPage(response.nextPageLink);
|
|
298
|
-
if (!response) {
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
result = response.page as ContinuablePage<TElement, TPage>;
|
|
302
|
-
result.continuationToken = response.nextPageLink;
|
|
303
|
-
yield result;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Gets for the value of nextLink in the body
|
|
309
|
-
*/
|
|
310
|
-
function getNextLink(body: unknown, nextLinkName?: string): string | undefined {
|
|
311
|
-
if (!nextLinkName) {
|
|
312
|
-
return undefined;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
const nextLink = (body as Record<string, unknown>)[nextLinkName];
|
|
316
|
-
|
|
317
|
-
if (
|
|
318
|
-
typeof nextLink !== "string" &&
|
|
319
|
-
typeof nextLink !== "undefined" &&
|
|
320
|
-
nextLink !== null
|
|
321
|
-
) {
|
|
322
|
-
throw new RestError(
|
|
323
|
-
\`Body Property \${nextLinkName} should be a string or undefined or null but got \${typeof nextLink}\`
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
if (nextLink === null) {
|
|
328
|
-
return undefined;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
return nextLink;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Gets the elements of the current request in the body.
|
|
336
|
-
*/
|
|
337
|
-
function getElements<T = unknown>(body: unknown, itemName: string): T[] {
|
|
338
|
-
const value = (body as Record<string, unknown>)[itemName] as T[];
|
|
339
|
-
if (!Array.isArray(value)) {
|
|
340
|
-
throw new RestError(
|
|
341
|
-
\`Couldn't paginate response\\n Body doesn't contain an array property with name: \${itemName}\`
|
|
342
|
-
);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
return value ?? [];
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Checks if a request failed
|
|
350
|
-
*/
|
|
351
|
-
function checkPagingRequest(response: PathUncheckedResponse): void {
|
|
352
|
-
${checkingPagingRequestContent}
|
|
353
|
-
}
|
|
354
|
-
`
|
|
355
|
-
]);
|
|
356
|
-
}
|