feat: add notes app

This commit is contained in:
2026-10-01 19:39:20 +02:00
parent ccb8dd3d15
commit ddbb6f37b5
35 changed files with 706 additions and 52 deletions
+12 -4
View File
@@ -13,7 +13,7 @@ const TIMEOUT_MS = 15_000
async function request<T>(
event: H3Event,
path: string,
options: { method?: 'GET' | 'POST' | 'PATCH', query?: Fields, body?: Fields } = {}
options: { method?: 'GET' | 'POST' | 'PATCH' | 'DELETE', query?: Fields, body?: Fields } = {}
): Promise<T> {
const { baserowUrl, baserowToken } = useRuntimeConfig(event)
if (!baserowUrl || !baserowToken) {
@@ -38,13 +38,13 @@ async function request<T>(
}
}
/** All rows of a table. `filters` are Baserow row filters, e.g. `{ filter__read__boolean: true }`. */
export async function listRows<Row>(event: H3Event, tableId: string, filters: Fields = {}): Promise<Row[]> {
/** All rows of a table. `query` adds Baserow list parameters, e.g. `{ filter__read__boolean: true }` or `{ include: 'title' }`. */
export async function listRows<Row>(event: H3Event, tableId: string, query: Fields = {}): Promise<Row[]> {
const path = `rows/table/${tableId}/`
const rows: Row[] = []
for (let page = 1; ; page++) {
const { count, results } = await request<RowPage<Row>>(event, path, {
query: { ...filters, user_field_names: true, size: PAGE_SIZE, page }
query: { ...query, user_field_names: true, size: PAGE_SIZE, page }
})
rows.push(...results)
if (rows.length >= count || results.length === 0) return rows
@@ -59,6 +59,14 @@ export function createRow<Row>(event: H3Event, tableId: string, fields: Fields):
})
}
export function getRow<Row>(event: H3Event, tableId: string, rowId: number): Promise<Row> {
return request<Row>(event, `rows/table/${tableId}/${rowId}/`, { query: { user_field_names: true } })
}
export async function deleteRow(event: H3Event, tableId: string, rowId: number): Promise<void> {
await request(event, `rows/table/${tableId}/${rowId}/`, { method: 'DELETE' })
}
export function updateRow<Row>(event: H3Event, tableId: string, rowId: number, fields: Fields): Promise<Row> {
return request<Row>(event, `rows/table/${tableId}/${rowId}/`, {
method: 'PATCH',