Skip to content

feat(memory-storage): implement listRequests method#3727

Open
harryautomazione wants to merge 2 commits into
apify:masterfrom
harryautomazione:feat/memory-storage-list-requests
Open

feat(memory-storage): implement listRequests method#3727
harryautomazione wants to merge 2 commits into
apify:masterfrom
harryautomazione:feat/memory-storage-list-requests

Conversation

@harryautomazione

Copy link
Copy Markdown

Description

Closes #2781

The method RequestQueueClient.listRequests exists for platform usage (in apify-client), but it was entirely missing from the local MemoryStorage client (@crawlee/memory-storage). This discrepancy prevented users from inspecting request queues programmatically in local environments.

This PR implements the missing method to ensure full API parity:

  • @crawlee/types: Extended RequestQueueClient to include listRequests alongside its options/results interfaces (RequestQueueClientListRequestsOptions, etc.).
  • @crawlee/memory-storage: Implemented the core logic using the Map insertion order. It properly handles both the limit and exclusiveStartId parameters to allow safe, deterministic pagination of local requests.
  • Tests: Added full coverage in list-requests.test.ts to simulate and verify single, limited, and fully paginated extractions.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds missing RequestQueueClient.listRequests() support to local @crawlee/memory-storage to reduce the API gap versus the platform client and enable programmatic inspection/pagination of request queues in local environments.

Changes:

  • Extended @crawlee/types RequestQueueClient with listRequests() plus its options/result interfaces.
  • Implemented listRequests() in the memory-storage RequestQueueClient using Map iteration with limit + exclusiveStartId.
  • Added unit tests covering default listing, limit, exclusiveStartId, and basic pagination.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/types/src/storages.ts Adds listRequests() typing and associated option/result interfaces to RequestQueueClient.
packages/memory-storage/src/resource-clients/request-queue.ts Implements the new listRequests() method in the local memory-storage request queue client.
packages/memory-storage/test/request-queue/list-requests.test.ts Adds tests validating listing behavior and pagination semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +303 to +306
export interface RequestQueueClientListRequestsOptions {
limit?: number;
exclusiveStartId?: string;
}
Comment on lines +308 to +312
export interface RequestQueueClientListRequestsResult {
limit: number;
exclusiveStartId?: string;
items: RequestSchema[];
}
Comment on lines +238 to +257
const queue = await this.getQueue();
const items: storage.RequestSchema[] = [];

let isAfterExclusiveStartId = !exclusiveStartId;

for (const [requestId, storageEntry] of queue.requests.entries()) {
if (!isAfterExclusiveStartId) {
if (requestId === exclusiveStartId) {
isAfterExclusiveStartId = true;
}
continue;
}

if (items.length >= limit) {
break;
}

const request = await storageEntry.get();
items.push(this._jsonToRequest<storage.RequestSchema>(request.json)!);
}

@barjin barjin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @harryautomazione ,
the changes look all right to me, although I agree with the Copilot comments.

If you want to proceed with this PR, please go over the Copilot comments and address these issues. Cheers!

@harryautomazione

Copy link
Copy Markdown
Author

Hi @barjin! Thank you for the review.
I've just pushed a new commit addressing all the Copilot comments. Specifically: 1. Added the cursor property to both RequestQueueClientListRequestsOptions and the result interface. 2. Deprecated exclusiveStartId as suggested, keeping it for backwards compatibility. 3. Updated listRequests to sort the IDs alphabetically during iteration, ensuring that the pagination order remains fully stable across process restarts. 4. Updated all related tests to verify the new cursor behavior and sorting.
Let me know if there's anything else needed or if it looks good to go! Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RequestQueue...client...listRequests for local usage

4 participants