mirror of
https://github.com/trailbaseio/trailbase.git
synced 2026-01-06 01:40:12 -06:00
Make JS/TS client more testable and move generic parameter from individual methods to RecordApi.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user