Open History to see the last commit
1import {
2 createCollection,
3 localOnlyCollectionOptions,
4} from "@tanstack/react-db";
5
6export type ApiRequest = {
7 id: string;
8 timestamp: number;
9 method: "GET" | "PATCH" | "POST" | "DELETE";
10 pathname: string;
11 requestBody?: unknown;
12 responseBody?: unknown;
13 status: number | "pending";
14 duration: number | null; // null when pending
15};
16
17export const apiRequestsCollection = createCollection(
18 localOnlyCollectionOptions({
19 id: "apiRequests",
20 getKey: (item) => item.id,
21 initialData: [] as ApiRequest[],
22 // onUpdate: async ({ transaction }) => {
23 // // Custom logic before confirming the update
24 // const { original, modified } = transaction.mutations[0];
25 // console.log("Updating from", original, "to", modified);
26 // },
27 }),
28);