@azure/cosmos
Version:
Microsoft Azure Cosmos DB Service Node.js SDK for NOSQL API
51 lines • 2.44 kB
TypeScript
import type { FilterContext, FilterStrategy } from "../index.js";
/**
* Implements post-fetch filtering for ORDER BY queries to handle continuation tokens correctly.
* This logic is applied only to the target partition from which a query is resumed.
* It filters out documents that have already been emitted in previous pages by comparing
* ORDER BY item values first, then document _rid, and finally using skip count for tie-breaking.
*
* Follows the .NET SDK FilterNextAsync logic:
* 1. Compare OrderBy values with continuation token values
* 2. Skip documents that come before continuation point
* 3. For exact OrderBy matches, use RID comparison
* 4. For exact RID matches, apply skip count logic
*/
export declare class RidSkipCountFilter implements FilterStrategy {
private readonly filterContext;
private remainingSkipCount;
/**
* @param filterContext - The context containing values from the continuation token.
*/
constructor(filterContext: FilterContext);
/**
* Applies the comprehensive OrderBy + RID + SkipCount filtering logic.
* @param documents - The documents fetched from the target partition.
* @returns A new array containing only the documents that should be processed.
*/
applyFilter(documents: any[]): any[];
/**
* Determines if a document should be included based on OrderBy values, RID, and skip count.
* Implements the .NET SDK's FilterNextAsync logic with robust OrderBy comparison.
*/
private shouldIncludeDocument;
/**
* Convert RID to BigInt for accurate comparison.
* Decodes base64 RID and extracts the Document ID portion (8 bytes at offset 8) as BigInt.
*
* RID Structure (from Java SDK ResourceId.java):
* - Bytes 0-3: Database ID (4 bytes)
* - Bytes 4-7: Collection ID (4 bytes)
* - Bytes 8-15: Document ID (8 bytes, stored in Big Endian but compared in Little Endian)
* - Bytes 16-19: Attachment ID (4 bytes, optional)
*/
private ridToBigInt;
/**
* Compares the OrderBy items of a document with the continuation token's OrderBy items.
* Uses the exported compareOrderByItems utility function from orderByItemComparator.
* @param doc - The document to compare
* @returns negative if doc comes before continuation, 0 if same, positive if doc comes after
*/
private compareOrderByItems;
}
//# sourceMappingURL=RidSkipCountFilter.d.ts.map