refactor: timestamps arrive as Date through the hey-api transformers plugin

Merged
HA
3d ago
+830-310

Closes #326 with its last bullet. The generated SDK now runs every response and SSE event through @hey-api/transformers, so date-time fields are Date objects, in the types and at runtime. No parseISO on API data is left.

Requests take Date too. The client writes a Date as ISO in a JSON body and in a query string, so the event filter keeps Date values, and only the datetime-local inputs convert, with date-fns reading and writing local wall time. The formatters accept Date only, so the compiler finds any string that slips through.

One catch: TanStack's structural sharing only understands JSON values and treats every Date as changed. Every refetch would then hand out new objects, and the drafts on the settings pages and in the rate limits modal would reset whenever the tab regained focus. Following TanStack's docs for non-JSON data, the query client compares the old and new data as JSON and keeps the old object when they match. A unit test covers it, and it fails without that option.

Vitest passes 1061 tests with coverage unchanged, and check, lint, prettier, build and regeneration are clean. Against a local backend the Playwright suite passes 149 tests, and the 3 failures are the k3s-only execution tests. In Chrome, set to Berlin time, the checks were:

  • The admin tables, settings history and notifications render their times.
  • A start time of 03:04 local goes out as 02:04:00.000Z, in the browse body and the export URL.
  • A restore sends its timestamp as ISO.
  • A visibility refetch on the settings page keeps an unsaved edit.

Summary by cubic

Closes #326. Enables the @hey-api/transformers plugin so the generated SDK returns every date-time field — in responses and SSE events alike — as a Date object in the types and at runtime. All parseISO calls on API data are removed, the formatters now accept Date only, so the compiler catches any string that slips through, and dates sent in request bodies and query strings serialize to ISO. Only the datetime-local inputs convert, keeping Date values in the event filter.

One caveat: TanStack's structural sharing treats every Date as changed, so each refetch handed out new objects and reset drafts on the settings pages and in the rate limits modal. The query client now compares old and new data as JSON and keeps the previous object when they match; a unit test covers it and fails without that option. Docs and test fixtures were updated to build timestamps with new Date(...) instead of ISO strings.