Skip to main content

Core Package Overview

@riftseer/core is the shared library that everything else in the monorepo depends on. It owns the provider interface all data access goes through, the autocomplete search engine, and the deck model. Card types and the parser live in @riftseer/types and are re-exported here for convenience.

Nothing in core is runtime-specific — it runs in Bun, Node, and Cloudflare Workers alike (except the server-only entry point, which is Bun/Node).


What's in core

ModuleFilePurpose
Typessrc/types.tsRe-exports Card, CardRequest, ResolvedCard, SimplifiedDeck, and all sub-interfaces from @riftseer/types
Provider interfacesrc/provider.tsCardDataProvider and SimplifiedDeckProvider — the only contracts the API cares about
Parsersrc/parser.tsRe-exports parseCardRequests() from @riftseer/types
Iconssrc/icons.tsRe-exports TOKEN_REGEX and TOKEN_ICON_MAP from @riftseer/types
Searchsrc/search.tsautocompleteSearch() — deterministic, position-aware name ranking
Normalizesrc/normalize.tsRe-exports normalizeCardName() from @riftseer/types
Supabase providersrc/providers/supabase.tsSupabaseCardProvider — the only CardDataProvider implementation
Decksrc/deck.tsDeck class — in-memory deck model with rule enforcement
Serialisersrc/serialiser.tsDeckSerializerV1 — compact binary + base64url deck encoding
Loggersrc/logger.tsLightweight structured logger
Server entrysrc/server.tsRe-exports Supabase and Redis clients (server-side only)

Provider pattern

The API does not import any database client directly. All data access goes through the CardDataProvider interface. The concrete implementation (SupabaseCardProvider) is selected at startup by the CARD_PROVIDER env var via the factory in src/providers/index.ts.

This means route code never changes when the data source changes — only the provider implementation does.

The ElysiaJS API server calls provider.warmup() on startup, then passes the provider into route modules as a dependency. See Provider Interface for the full contract.


Exports

The public surface is src/index.ts. Import from @riftseer/core:

import type { Card, CardRequest, ResolvedCard, SimplifiedDeck } from "@riftseer/core";
import { parseCardRequests } from "@riftseer/core";
import { autocompleteSearch } from "@riftseer/core";
import { Deck, DeckIssue } from "@riftseer/core";
import { DeckSerializerV1 } from "@riftseer/core";

Server-side clients (Supabase, Redis) are exported from @riftseer/core/server — do not import these in Workers or browser builds.

If you only need types or the parser and want to avoid core's heavier dependencies, import from @riftseer/types directly.


Testing

Tests live in src/__tests__/. Run with:

bun test packages/core

The provider tests use mock() from bun:test to stub the CardDataProvider interface. No live database connection is needed.