Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
@azure/core-paging
Advanced tools
@azure/core-paging is a library that provides utilities for handling paginated responses from Azure services. It simplifies the process of iterating over paginated data, making it easier to work with large sets of data that are returned in multiple pages.
Iterating over paginated results
This feature allows you to iterate over paginated results using an asynchronous iterator. The code sample demonstrates how to use the PagedAsyncIterableIterator to loop through items returned by a client's listItems method.
const { PagedAsyncIterableIterator } = require('@azure/core-paging');
async function iteratePages(client) {
const pagedIterator = client.listItems();
for await (const item of pagedIterator) {
console.log(item);
}
}
Handling paginated responses
This feature allows you to handle paginated responses page by page. The code sample demonstrates how to use the byPage method to iterate through each page of results and process the items within each page.
const { PagedAsyncIterableIterator } = require('@azure/core-paging');
async function handlePages(client) {
const pagedIterator = client.listItems();
let pageCount = 0;
for await (const page of pagedIterator.byPage()) {
console.log(`Page ${++pageCount}:`);
for (const item of page) {
console.log(item);
}
}
}
Axios is a popular HTTP client for making requests to APIs. While it does not provide built-in support for pagination, it can be used in conjunction with custom logic to handle paginated responses. Compared to @azure/core-paging, axios requires more manual handling of pagination.
Node-fetch is a lightweight module that brings window.fetch to Node.js. Similar to axios, it does not have built-in pagination support but can be used with custom logic to manage paginated data. It is more low-level compared to @azure/core-paging, which offers higher-level utilities for pagination.
Request-promise is a simplified HTTP request client for Node.js with Promise support. Like axios and node-fetch, it does not include pagination utilities out of the box. Users need to implement their own pagination handling, making it less convenient than @azure/core-paging for working with paginated data.
This library provides core types for paging async iterable iterators.
If using this as part of another project in the azure-sdk-for-js repo,
then run rush install
after cloning the repo.
Otherwise, use npm to install this package in your application as follows
npm install @azure/core-paging
You can find an explanation of how this repository's code works by going to our architecture overview.
Example of building with the types:
public listSecrets(
options: ListSecretsOptions = {}
): PagedAsyncIterableIterator<SecretAttributes> {
const iter = this.listSecretsAll(options);
return {
async next() { return iter.next(); },
[Symbol.asyncIterator]() { return this; },
byPage: (settings: PageSettings = {}) => this.listSecretsPage(settings, options),
};
}
And using the types:
for await (let page of client.listSecrets().byPage({ maxPageSize: 2 })) {
for (const secret of page) {
console.log("secret: ", secret);
}
}
Try out this package in your application when dealing with async iterable iterators and provide feedback!
Log an issue at https://github.com/Azure/azure-sdk-for-js/issues
If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.
FAQs
Core types for paging async iterable iterators
The npm package @azure/core-paging receives a total of 2,895,091 weekly downloads. As such, @azure/core-paging popularity was classified as popular.
We found that @azure/core-paging demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.