**feat(storage): add pagination and filtering support for nouns and verbs**
- Introduced `PaginationOptions`, `NounFilterOptions`, and `VerbFilterOptions` types for improved query flexibility in data retrieval operations. - Added `getNouns` and `getVerbs` methods with pagination and filtering capabilities, replacing existing methods for broader use cases and scalability. - Marked legacy methods (`getAllNouns`, `getAllVerbs`, `getVerbsBySource`, `getVerbsByTarget`, `getVerbsByType`) as deprecated, directing users to use new methods. - Updated `coreTypes`, `memoryStorage`, and related modules to support new functionality, including cursor and offset-based pagination handling. - Updated fallback logic for storage adapters, ensuring compatibility with non-paginated operations when required. **Purpose**: Enhance scalability and query precision by implementing paginated and filtered retrieval of nouns and verbs, aligning query methods with modern requirements.
This commit is contained in:
parent
59caa6ab5b
commit
c3c4ca31e1
8 changed files with 1309 additions and 143 deletions
130
src/types/paginationTypes.ts
Normal file
130
src/types/paginationTypes.ts
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
/**
|
||||
* Types for pagination and filtering in data retrieval operations
|
||||
*/
|
||||
|
||||
/**
|
||||
* Pagination options for data retrieval
|
||||
*/
|
||||
export interface PaginationOptions {
|
||||
/**
|
||||
* The number of items to skip (for offset-based pagination)
|
||||
*/
|
||||
offset?: number;
|
||||
|
||||
/**
|
||||
* The maximum number of items to return
|
||||
*/
|
||||
limit?: number;
|
||||
|
||||
/**
|
||||
* Token for cursor-based pagination (for continuing from a previous page)
|
||||
*/
|
||||
cursor?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter options for noun retrieval
|
||||
*/
|
||||
export interface NounFilterOptions {
|
||||
/**
|
||||
* Filter by noun type
|
||||
*/
|
||||
nounType?: string | string[];
|
||||
|
||||
/**
|
||||
* Filter by service
|
||||
*/
|
||||
service?: string | string[];
|
||||
|
||||
/**
|
||||
* Filter by metadata fields (key-value pairs)
|
||||
*/
|
||||
metadata?: Record<string, any>;
|
||||
|
||||
/**
|
||||
* Filter by creation date range
|
||||
*/
|
||||
createdAt?: {
|
||||
from?: Date | number;
|
||||
to?: Date | number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Filter by update date range
|
||||
*/
|
||||
updatedAt?: {
|
||||
from?: Date | number;
|
||||
to?: Date | number;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter options for verb retrieval
|
||||
*/
|
||||
export interface VerbFilterOptions {
|
||||
/**
|
||||
* Filter by verb type
|
||||
*/
|
||||
verbType?: string | string[];
|
||||
|
||||
/**
|
||||
* Filter by source noun ID
|
||||
*/
|
||||
sourceId?: string | string[];
|
||||
|
||||
/**
|
||||
* Filter by target noun ID
|
||||
*/
|
||||
targetId?: string | string[];
|
||||
|
||||
/**
|
||||
* Filter by service
|
||||
*/
|
||||
service?: string | string[];
|
||||
|
||||
/**
|
||||
* Filter by metadata fields (key-value pairs)
|
||||
*/
|
||||
metadata?: Record<string, any>;
|
||||
|
||||
/**
|
||||
* Filter by creation date range
|
||||
*/
|
||||
createdAt?: {
|
||||
from?: Date | number;
|
||||
to?: Date | number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Filter by update date range
|
||||
*/
|
||||
updatedAt?: {
|
||||
from?: Date | number;
|
||||
to?: Date | number;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Result of a paginated query
|
||||
*/
|
||||
export interface PaginatedResult<T> {
|
||||
/**
|
||||
* The items for the current page
|
||||
*/
|
||||
items: T[];
|
||||
|
||||
/**
|
||||
* The total number of items matching the query (may be estimated)
|
||||
*/
|
||||
totalCount?: number;
|
||||
|
||||
/**
|
||||
* Whether there are more items available
|
||||
*/
|
||||
hasMore: boolean;
|
||||
|
||||
/**
|
||||
* Cursor for fetching the next page (for cursor-based pagination)
|
||||
*/
|
||||
nextCursor?: string;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue