
Complete documentation for all available tRPC procedures in the @sstraatemans/sw_trpcclient package.
All procedures return type-safe results with full TypeScript support. The API is organized into four main routers:
albums.countGet the total number of albums in the database.
Type: Query
Authentication: None required
No input parameters required.
// Zod Schema
z.void();
// Return Type
number;
import { createClient } from '@sstraatemans/sw_trpcclient';
const trpc = createClient({
url: 'https://playground-trpcserver.vercel.app/trpc/v1',
});
const count = await trpc.albums.count.query();
console.log(`Total albums: ${count}`);
// Output: Total albums: 378
albums.allGet a paginated list of all albums with their details.
Type: Query
Authentication: None required
// Zod Schema
z.object({
offset: z.number().optional(),
limit: z.number().optional(),
}).optional();
// TypeScript Type
interface AllAlbumsInput {
offset?: number; // Default: 0
limit?: number; // Default: 50, Max: 50
}
// Return Type
interface AllAlbumsOutput {
totalCount: number;
data: Album[];
}
// Album Type
interface Album {
id: number;
title: string;
date: string;
scenarioArtistId: number | null;
drawArtistId: number | null;
wikiURL: string | null;
description: string | null;
image: string | null;
}
const albums = await trpc.albums.all.query({
offset: 0,
limit: 10,
});
console.log(`Found ${albums.totalCount} total albums`);
console.log(`First album: ${albums.data[0].title}`);
{
"totalCount": 378,
"data": [
{
"id": 1,
"title": "Rikki en Wiske in Chocowakije",
"date": "1945",
"scenarioArtistId": 1,
"drawArtistId": 1,
"wikiURL": "https://nl.wikipedia.org/wiki/Rikki_en_Wiske_in_Chocowakije",
"description": "Het eerste album in de reeks...",
"image": "/images/album-1.jpg"
}
]
}
INTERNAL_SERVER_ERROR - Unexpected database errorSERVICE_UNAVAILABLE - Database connection unavailablealbums.getAlbumByIdGet detailed information about a specific album by its ID.
Type: Query
Authentication: None required
// Zod Schema
z.number();
// TypeScript Type
number;
// Album Type (same as above)
Album | null;
const album = await trpc.albums.getAlbumById.query(1);
if (album) {
console.log(`Title: ${album.title}`);
console.log(`Released: ${album.date}`);
}
albums.getAlbumCharactersByIdGet all characters that appear in a specific album.
Type: Query
Authentication: None required
// Zod Schema
z.number();
// Return Type
Character[]
interface Character {
id: number;
name: string;
description: string;
years: string;
albumsTemp: string;
wikiURL: string | null;
}
const characters = await trpc.albums.getAlbumCharactersById.query(1);
console.log(`Characters in album: ${characters.length}`);
characters.forEach((char) => {
console.log(`- ${char.name}`);
});
albums.getAlbumCollectionsByIdGet all collections/series that include a specific album.
Type: Query
Authentication: None required
// Zod Schema
z.number();
// Return Type
CollectionAlbum[]
interface CollectionAlbum {
albumId: number;
collectionId: string;
number: number;
image: string | null;
collection: Collection;
}
interface Collection {
id: string;
name: string;
startYear: string;
endYear: string;
wikiURL: string | null;
}
const collections = await trpc.albums.getAlbumCollectionsById.query(1);
collections.forEach((item) => {
console.log(`${item.collection.name} #${item.number}`);
});
characters.countGet the total number of characters in the database.
Type: Query
Authentication: None required
No input parameters required.
number;
const count = await trpc.characters.count.query();
console.log(`Total characters: ${count}`);
characters.allGet a paginated list of all characters.
Type: Query
Authentication: None required
// Zod Schema
z.object({
offset: z.number().optional(),
limit: z.number().optional(),
}).optional();
// TypeScript Type
interface AllCharactersInput {
offset?: number; // Default: 0
limit?: number; // Default: 50, Max: 50
}
interface AllCharactersOutput {
totalCount: number;
data: Character[];
}
const characters = await trpc.characters.all.query({
offset: 0,
limit: 20,
});
console.log(`Total characters: ${characters.totalCount}`);
characters.getCharacterByIdGet detailed information about a specific character.
Type: Query
Authentication: None required
// Zod Schema
z.number();
Character | null;
const character = await trpc.characters.getCharacterById.query(1);
if (character) {
console.log(`Name: ${character.name}`);
console.log(`Description: ${character.description}`);
}
characters.getCharactersAlbumsByIdGet all albums featuring a specific character.
Type: Query
Authentication: None required
// Zod Schema
z.number();
Album[]
const albums = await trpc.characters.getCharactersAlbumsById.query(1);
console.log(`Albums featuring this character: ${albums.length}`);
albums.forEach((album) => {
console.log(`- ${album.title} (${album.date})`);
});
artists.countGet the total number of artists in the database.
Type: Query
Authentication: None required
No input parameters required.
number;
const count = await trpc.artists.count.query();
console.log(`Total artists: ${count}`);
artists.allGet a paginated list of all artists (writers and illustrators).
Type: Query
Authentication: None required
// Zod Schema
z.object({
offset: z.number().optional(),
limit: z.number().optional(),
}).optional();
// TypeScript Type
interface AllArtistsInput {
offset?: number; // Default: 0
limit?: number; // Default: 50, Max: 50
}
interface AllArtistsOutput {
totalCount: number;
data: Artist[];
}
interface Artist {
id: number;
name: string;
wikiURL: string | null;
image: string | null;
}
const artists = await trpc.artists.all.query({
offset: 0,
limit: 10,
});
console.log(`Total artists: ${artists.totalCount}`);
artists.getArtistByIdGet detailed information about a specific artist.
Type: Query
Authentication: None required
// Zod Schema
z.number();
Artist | null;
const artist = await trpc.artists.getArtistById.query(1);
if (artist) {
console.log(`Name: ${artist.name}`);
console.log(`Wikipedia: ${artist.wikiURL}`);
}
artists.getArtistAlbumsByIdGet all albums created by a specific artist (as writer or illustrator).
Type: Query
Authentication: None required
// Zod Schema
z.number();
Album[]
const albums = await trpc.artists.getArtistAlbumsById.query(1);
console.log(`Albums by this artist: ${albums.length}`);
albums.forEach((album) => {
console.log(`- ${album.title}`);
});
collections.countGet the total number of collections/series in the database.
Type: Query
Authentication: None required
No input parameters required.
number;
const count = await trpc.collections.count.query();
console.log(`Total collections: ${count}`);
collections.allGet a paginated list of all collections/series.
Type: Query
Authentication: None required
// Zod Schema
z.object({
offset: z.number().optional(),
limit: z.number().optional(),
}).optional();
// TypeScript Type
interface AllCollectionsInput {
offset?: number; // Default: 0
limit?: number; // Default: 50, Max: 50
}
interface AllCollectionsOutput {
totalCount: number;
data: Collection[];
}
interface Collection {
id: string;
name: string;
startYear: string;
endYear: string;
wikiURL: string | null;
}
const collections = await trpc.collections.all.query({
offset: 0,
limit: 10,
});
console.log(`Total collections: ${collections.totalCount}`);
collections.getCollectionByIdGet detailed information about a specific collection.
Type: Query
Authentication: None required
// Zod Schema
z.string();
Collection | null;
const collection =
await trpc.collections.getCollectionById.query('blauwe-reeks');
if (collection) {
console.log(`Name: ${collection.name}`);
console.log(`Years: ${collection.startYear} - ${collection.endYear}`);
}
collections.getCollectionAlbumsByIdGet all albums in a specific collection/series.
Type: Query
Authentication: None required
// Zod Schema
z.string();
CollectionAlbum[]
interface CollectionAlbum {
albumId: number;
collectionId: string;
number: number;
image: string | null;
album: Album;
}
const albums =
await trpc.collections.getCollectionAlbumsById.query('blauwe-reeks');
console.log(`Albums in collection: ${albums.length}`);
albums.forEach((item) => {
console.log(`#${item.number}: ${item.album.title}`);
});
All list endpoints (albums.all, characters.all, artists.all, collections.all) support pagination with the following parameters:
offset (optional): Number of records to skip. Default: 0
0limit (optional): Maximum number of records to return. Default: 50, Max: 50
5050// Get page 1 (first 20 items)
const page1 = await trpc.albums.all.query({
offset: 0,
limit: 20,
});
// Get page 2 (next 20 items)
const page2 = await trpc.albums.all.query({
offset: 20,
limit: 20,
});
// Get page 3 (next 20 items)
const page3 = await trpc.albums.all.query({
offset: 40,
limit: 20,
});
// Calculate total pages
const totalPages = Math.ceil(page1.totalCount / 20);
console.log(`Total pages: ${totalPages}`);
let offset = 0;
const limit = 20;
let hasMore = true;
const allAlbums: Album[] = [];
while (hasMore) {
const result = await trpc.albums.all.query({ offset, limit });
allAlbums.push(...result.data);
offset += limit;
hasMore = offset < result.totalCount;
}
console.log(`Loaded all ${allAlbums.length} albums`);
All queries may throw tRPC errors. Common error codes:
INTERNAL_SERVER_ERRORUnexpected server or database error.
try {
const albums = await trpc.albums.all.query();
} catch (error) {
if (error.data?.code === 'INTERNAL_SERVER_ERROR') {
console.error('Server error:', error.message);
}
}
SERVICE_UNAVAILABLEDatabase connection is temporarily unavailable.
try {
const count = await trpc.albums.count.query();
} catch (error) {
if (error.data?.code === 'SERVICE_UNAVAILABLE') {
console.error('Database unavailable. Please try again later.');
}
}
import type { AppRouter } from '@sstraatemans/sw_trpcclient';
import { TRPCClientError } from '@trpc/client';
try {
const albums = await trpc.albums.all.query({ offset: 0, limit: 10 });
console.log(albums);
} catch (error) {
if (error instanceof TRPCClientError<AppRouter>) {
// Handle known tRPC errors
switch (error.data?.code) {
case 'SERVICE_UNAVAILABLE':
console.error('Service temporarily unavailable');
break;
case 'INTERNAL_SERVER_ERROR':
console.error('Internal server error:', error.message);
break;
default:
console.error('Unexpected error:', error);
}
} else {
// Handle network or other errors
console.error('Network error:', error);
}
}