Isomorphic JavaScript client for Supabase providing authentication, database, real-time, storage, and edge functions capabilities.
89
Build a product catalog API that efficiently retrieves products with pagination support.
You need to create a module that fetches products from a database with pagination capabilities. The system should support two pagination strategies: limit-based pagination for simple page sizes and range-based pagination for more precise control over result sets.
Implement a ProductCatalog class with the following methods:
getProductsWithLimit(pageSize)
getProductsInRange(startIndex, endIndex)
getPagedProducts(page, pageSize)
The database contains a products table with the following structure:
id (integer): Product IDname (string): Product nameprice (number): Product pricecategory (string): Product categorycreated_at (timestamp): Creation timestampImplement the following test cases in product-catalog.test.ts:
// Given a database with 100 products
// When fetching with a limit of 10
const products = await catalog.getProductsWithLimit(10);
// Then exactly 10 products should be returned
assert(products.length === 10);// Given a database with 100 products
// When fetching products from index 20 to 29 (inclusive)
const products = await catalog.getProductsInRange(20, 29);
// Then exactly 10 products should be returned (indices 20-29)
assert(products.length === 10);// Given a database with 100 products and pageSize of 25
// When fetching page 2
const products = await catalog.getPagedProducts(2, 25);
// Then exactly 25 products should be returned (items 26-50)
assert(products.length === 25);Provides database client for querying the PostgreSQL database with pagination support.
product-catalog.ts: Main implementation file with the ProductCatalog classproduct-catalog.test.ts: Test file with all test cases passingInstall with Tessl CLI
npx tessl i tessl/npm-supabase--supabase-jsevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10