Make JS/TS client more testable and move generic parameter from individual methods to RecordApi.

This commit is contained in:
Sebastian Jeltsch
2025-07-04 15:52:30 +02:00
parent a7a83e7ee2
commit 94e10149ff
23 changed files with 169 additions and 132 deletions

View File

@@ -1,17 +1,17 @@
import { readFile } from "node:fs/promises";
import { parse } from "csv-parse/sync";
import { Client } from "trailbase";
import { initClient } from "trailbase";
import type { Movie } from "@schema/movie";
const client = new Client("http://localhost:4000");
const client = initClient("http://localhost:4000");
await client.login("admin@localhost", "secret");
const api = client.records("movies");
const api = client.records<Movie>("movies");
// Start fresh: delete all existing movies.
let cnt = 0;
while (true) {
const movies = await api.list<Movie>({
const movies = await api.list({
pagination: {
limit: 100,
},
@@ -35,11 +35,11 @@ const file = await readFile("data/Top_1000_IMDb_movies_New_version.csv");
const records = parse(file, {
fromLine: 2,
// prettier-ignore
columns: [ "rank", "name", "year", "watch_time", "rating", "metascore", "gross", "votes", "description" ],
columns: ["rank", "name", "year", "watch_time", "rating", "metascore", "gross", "votes", "description"],
});
for (const movie of records) {
await api.create<Movie>({
await api.create({
rank: parseInt(movie.rank),
name: movie.name,
year: movie.year,

View File

@@ -1,6 +1,6 @@
import { Client } from "trailbase";
import { initClient } from "trailbase";
const client = new Client("http://localhost:4000");
const client = initClient("http://localhost:4000");
await client.login("admin@localhost", "secret");
const movies = client.records("movies");