Breaking: nest records in output of RecordAPI.list to contain cursor now and potentially more in the future.

Also update all the client libraries to accept the new format.
This commit is contained in:
Sebastian Jeltsch
2025-01-19 00:34:16 +01:00
parent f942fb7771
commit 2fb294f17c
22 changed files with 297 additions and 378 deletions

View File

@@ -6,8 +6,8 @@
"scripts": {
"build": "tsc",
"format": "prettier -w src",
"read": "tsc && node dist/src/index.js",
"fill": "tsc && node dist/src/fill.js",
"read": "node --loader ts-node/esm src/index.js",
"fill": "node --loader ts-node/esm src/fill.js",
"check": "tsc --noEmit --skipLibCheck && eslint"
},
"devDependencies": {
@@ -16,6 +16,7 @@
"eslint": "^9.18.0",
"prettier": "^3.4.2",
"quicktype": "^23.0.170",
"ts-node": "^10.9.2",
"typescript": "^5.7.3",
"typescript-eslint": "^8.20.0"
},

View File

@@ -8,18 +8,28 @@ const client = new Client("http://localhost:4000");
await client.login("admin@localhost", "secret");
const api = client.records("movies");
let movies = [];
do {
movies = await api.list<Movie>({
// Start fresh: delete all existing movies.
let cnt = 0;
while (true) {
const movies = await api.list<Movie>({
pagination: {
limit: 100,
},
});
for (const movie of movies) {
const records = movies.records;
const length = records.length;
if (length === 0) {
break;
}
cnt += length;
for (const movie of records) {
await api.delete(movie.rank!);
}
} while (movies.length > 0);
}
console.log(`Cleaned up ${cnt} movies`);
const file = await readFile("../data/Top_1000_IMDb_movies_New_version.csv");
const records = parse(file, {
@@ -41,3 +51,5 @@ for (const movie of records) {
description: movie.description,
});
}
console.log(`Inserted ${records.length} movies`);

View File

@@ -12,4 +12,4 @@ const m = await movies.list({
filters: ["watch_time[lt]=120"],
});
console.log(m);
console.log(m.records);

View File

@@ -3,3 +3,8 @@ backups/
data/
secrets/
uploads/
!migrations/
trailbase.js
trailbase.d.ts