Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ db.sqlite3

# test databases
test-*.sqlite3
test-*.sqlite3-journal
db.sqlite3-journal
28 changes: 28 additions & 0 deletions fill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { sendCorrections } from './src/client';

await sendCorrections({
origin: 'http://localhost:3000',
corrections: Array.from({ length: parseInt(process.argv[2] || '1') }, (_, i) => ({
client_name: 'fill.ts',
client_version: '0.1.0',
comment: `Correction ${i + 1}`,
done_at: new Date().toISOString(),
metadata: 'auto-filled',
protocol_id: 'test-protocol',
protocol_version: '1.0.0',
subject: 'test',
subject_type: 'other',
subject_content_hash: 'sha256:examplehash',
user: null,
before: {
alternatives: [],
type: 'boolean',
value: 'false'
},
after: {
alternatives: [],
type: 'boolean',
value: 'true'
}
}))
});
18 changes: 12 additions & 6 deletions migrate.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { migrate } from 'drizzle-orm/bun-sqlite/migrator';

import { Database } from 'bun:sqlite';
import { drizzle } from 'drizzle-orm/bun-sqlite';
import * as migrator from 'drizzle-orm/bun-sqlite/migrator';
import * as c from './src/console.js';

console.info(`Running with database ${c.strong(Bun.env.DB_FILE_NAME)}`);
export async function migrate(dbFile: string, { quiet = false } = {}) {
Bun.env.DB_FILE_NAME = dbFile;
if (!quiet) console.info(`Migrating ${c.strong(dbFile)}`);

const sqlite = new Database(dbFile);
const db = drizzle(sqlite);
migrator.migrate(db, { migrationsFolder: './drizzle' });
}

const sqlite = new Database(Bun.env.DB_FILE_NAME);
const db = drizzle(sqlite);
migrate(db, { migrationsFolder: './drizzle' });
if (import.meta.main) {
await migrate(Bun.env.DB_FILE_NAME);
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"check:clutter": "bunx --bun knip",
"migrate": "bun run migrate.ts",
"makemigration": "bunx drizzle-kit generate --name",
"fill": "bun run fill.ts",
"dev": "bun run --watch src/index.ts",
"test": "bun test",
"test:watch": "bun test --watch",
Expand Down
3 changes: 2 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function correctionsOfProtocol({
if (response.ok) {
const results: typeof CorrectionsList.infer = await unrollPaginatedResponse({
response: await response.json(),
limit: Number(unroll === true ? Infinity : unroll)
limit: unroll === true ? Infinity : Number(unroll)
});

return results.map((correction) => ({
Expand Down Expand Up @@ -99,6 +99,7 @@ async function unrollPaginatedResponse<T>({
}): Promise<T[]> {
let requestsCount = 0;
let items = response.items;

while (response.next_url && requestsCount < limit) {
response = await fetch(response.next_url).then((r) => r.json());
items = [...items, ...response.items];
Expand Down
Loading
Loading