auto-builder-sdk
Version:
SDK for building Auto Builder workflow plugins
114 lines (113 loc) • 3.86 kB
TypeScript
/**
* Standard Pagination Utilities for Auto-Builder SDK
*
* This module provides utilities to enforce consistent pagination across all nodes
* and plugins. It implements the StandardPaginationParams interface and provides
* helper functions for converting between different pagination formats.
*/
/**
* Standard pagination parameters interface
*/
export interface StandardPaginationParams {
page?: number;
pageSize?: number;
totalRecords?: number;
}
/**
* Standard pagination response interface
*/
export interface StandardPaginationResponse<T> {
data: T[];
pagination: {
page: number;
pageSize: number;
totalRecords?: number;
totalPages?: number;
hasNextPage: boolean;
hasPreviousPage: boolean;
};
}
/**
* Convert page/pageSize to limit/offset for database queries
*/
export declare function convertToLimitOffset(page?: number, pageSize?: number): {
limit: number;
offset: number;
};
/**
* Calculate pagination metadata
*/
export declare function calculatePaginationMeta(page: number | undefined, pageSize: number | undefined, totalRecords: number): {
page: number;
pageSize: number;
totalRecords: number;
totalPages: number;
hasNextPage: boolean;
hasPreviousPage: boolean;
};
/**
* Validate and apply defaults to pagination parameters
*/
export declare function validatePaginationParams(params: Partial<StandardPaginationParams>): Required<Omit<StandardPaginationParams, 'totalRecords'>> & {
totalRecords?: number;
};
/**
* Create a standardized pagination response
*/
export declare function createPaginationResponse<T>(data: T[], page?: number, pageSize?: number, totalRecords?: number): StandardPaginationResponse<T>;
/**
* Extract pagination parameters from node parameters
*/
export declare function extractPaginationParams(params: Record<string, any>): StandardPaginationParams;
/**
* Convert legacy pagination parameter names to standard format
*/
export declare function convertLegacyPagination(params: Record<string, any>): StandardPaginationParams;
/**
* Build API-specific pagination parameters
*/
export declare function buildApiPaginationParams(params: StandardPaginationParams, apiType?: 'graphql' | 'odata' | 'rest' | 'firebase' | 'mongo'): Record<string, any>;
/**
* Parse API response and extract pagination metadata
*/
export declare function parseApiPaginationResponse<T>(response: any, dataPath?: string, paginationPath?: string): StandardPaginationResponse<T>;
/**
* Standard pagination node definition for easy integration
*/
export declare const PAGINATION_NODE_DEFINITION: {
readonly displayName: "Page";
readonly name: "page";
readonly type: "number";
readonly default: number;
readonly description: `Page number (${number}-based)`;
readonly displayOptions: {
readonly show: {
readonly resource: readonly ["*"];
readonly operation: readonly ["getAll", "list", "search", "query"];
};
};
};
/**
* Standard page size node definition
*/
export declare const PAGINATION_SIZE_NODE_DEFINITION: {
readonly displayName: "Page Size";
readonly name: "pageSize";
readonly type: "number";
readonly default: number;
readonly description: `Number of records per page (max ${number})`;
readonly displayOptions: {
readonly show: {
readonly resource: readonly ["*"];
readonly operation: readonly ["getAll", "list", "search", "query"];
};
};
};
/**
* Helper function to add standard pagination to node properties
*/
export declare function addStandardPagination(properties: any[]): any[];
/**
* Helper function to validate pagination in node execution
*/
export declare function validateNodePagination(this: any, items: any[], resource: string, operation: string): void;