CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-supabase--supabase-js

Isomorphic JavaScript client for Supabase providing authentication, database, real-time, storage, and edge functions capabilities.

89

0.95x
Overview
Eval results
Files

task.mdevals/scenario-8/

Product Catalog Pagination API

Build a product catalog API that efficiently retrieves products with pagination support.

Overview

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.

Requirements

Core Functionality

Implement a ProductCatalog class with the following methods:

  1. getProductsWithLimit(pageSize)

    • Fetches products limited to a specific page size
    • Returns an array of product objects
    • Should retrieve only the specified number of products
  2. getProductsInRange(startIndex, endIndex)

    • Fetches products within a specific index range (inclusive)
    • Returns an array of product objects
    • The range should be zero-based and inclusive on both ends
  3. getPagedProducts(page, pageSize)

    • Fetches a specific page of products
    • Page numbers start at 1
    • Returns an array of product objects for the requested page

Database Schema

The database contains a products table with the following structure:

  • id (integer): Product ID
  • name (string): Product name
  • price (number): Product price
  • category (string): Product category
  • created_at (timestamp): Creation timestamp

Error Handling

  • Handle cases where the range or limit parameters are invalid
  • Return appropriate error responses for database connection issues

Test Cases

Implement the following test cases in product-catalog.test.ts:

Test 1: Fetch products with limit { @test }

// 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);

Test 2: Fetch products in a range { @test }

// 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);

Test 3: Fetch a specific page { @test }

// 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);

Implementation Notes

  • Focus on implementing efficient pagination queries
  • Ensure the range-based method correctly handles zero-based inclusive ranges
  • The paged products method should internally calculate the correct range based on page number and page size

Dependencies { .dependencies }

@supabase/supabase-js { .dependency }

Provides database client for querying the PostgreSQL database with pagination support.

Deliverables

  • product-catalog.ts: Main implementation file with the ProductCatalog class
  • product-catalog.test.ts: Test file with all test cases passing

Install with Tessl CLI

npx tessl i tessl/npm-supabase--supabase-js

tile.json