Skip to content

refactor: Reduce code - #805

Merged
aXenDeveloper merged 12 commits into
canaryfrom
perf/reduce_code
Sep 12, 2026
Merged

aXenDeveloper merged 12 commits into
canaryfrom
perf/reduce_code

Conversation

@aXenDeveloper

Copy link
Copy Markdown
Owner

Improving Documentation

Description

What?

Why?

@vercel

vercel Bot commented Sep 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
vitnode-prod Ready Ready Preview Sep 12, 2026 2:39pm UTC

@github-actions github-actions Bot added the 🧱 Refactor A code change that neither fixes a bug nor adds a feature label Sep 12, 2026
aXenDeveloper and others added 9 commits September 12, 2026 15:49
Both auth transports implemented the same nine operations and the same
status mapping, differing only in which fetcher they call and whether the
answer's cookies are relayed.

`transport-operations.ts` now owns everything after the answer arrives -
the status mapping, the bodies read off the finite cases, the failures
that must not throw - behind a small semantic requester interface. It
imports neither fetcher and neither `clientModule`, so it cannot bake a
runtime in.

`default-transport.ts` and `server.ts` are thin adapters that write their
routes inline at the call site. `allowSaveCookies: true` stays on exactly
the six cookie-relay flows (sign-in, sign-out, the three SSO steps,
sign-up) and stays off the password reset request and the token-based
password change, as before. Every `*OnApi` export is unchanged.

`callUsersApi` is generic in its answer and `readJson`/`readText` take the
minimal shape they read, so the shared module needs no DOM `Response`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`readAdminSessionFromApi` and `readAdminSessionOnApi` were the same twelve
lines twice: the same status check, the same error logging, the same
mapping into the four states a route guard can act on.

`session-read.ts` now owns all of that, and it reaches for
`adminSessionReadFromStatus` - the full mapper that already existed in
`state.ts` and had no caller - so the failure-only helper and the full one
can no longer disagree. The body is read inside the requester and
therefore inside the shared `try`, which is what keeps an unparseable
`200` a raised failure rather than a grant carrying nothing.

Each adapter keeps its own `status === 200` narrowing: the route's `403`
is declared without a body, so only the `200` arm of the response union
has a payload type for `AdminSessionApi` to be inferred from.

`user-search.ts` is untouched, and so are both export names.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`eslint --fix` on a pre-existing `perfectionist/sort-exports` warning.
Re-ordering only - no export is added, removed or renamed. Separate from
the refactor so it can be dropped on its own.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…lders

`identifier`, `readJson`, `jsonBody`, `jsonResponse` and `plainOutcome`
were declared fourteen times across `routes.ts`, `translation-routes.ts`
and `localized-admin-routes.ts` - the same bodies, and in `plainOutcome`'s
case the same outcome written out twice with two spellings of the same
types.

`route-helpers.ts` holds one definition of each. `plainOutcome` is generic
in the content type definition, which is what both call sites already had
bound, so `changedFields` stays the localized field names of that content
type rather than widening to `string[]`.

Statuses, messages and OpenAPI fragments are byte-identical: the 400 is
still `Invalid identifier.`, and the two fragment builders still carry the
caller's own schema instance. Nothing about CRUD, permissions, effects,
transactions or the editorial paths moved.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`withCollections` was thirty identical lines in `public-service.ts` and in
`localized-public-service.ts`, including the comment explaining why the
file fields resolve last.

`public-row-hydration.ts` holds it once, as a factory bound to the
context, the definition and the exposed collection list. The order it
guarantees is the order that mattered: nest, load only the publicly
exposed collections, attach them, then batch-resolve the file fields -
because a `multiple: true` file field has no column and its identifiers
only exist on the row after `loadMany` wrote them.

`nestContentPublicRow` moved with it and is re-exported from
`public-service.ts`, so its import path is unchanged and there is no cycle
between the two modules.

The two services' statements and localization strategies are untouched;
only the hydration is shared.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`SessionModel` and `SessionAdminModel` each carried a private `hashToken`
with the same seventeen lines. `hashSessionToken` in `api/lib` is that
implementation, verbatim: SHA-256 over the token's UTF-8 bytes, lowercase
hex, zero-padded per byte, through Web Crypto and therefore async.

The token format and every existing query are untouched - the two models
just look the stored form up the same way now, and a test pins the digest
against `node:crypto` so neither the algorithm nor the encoding can drift
without a failure.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The user's download route and the admin one each carried the same fetch,
the same two headers, the same optional `Content-Length` and the same
re-streamed body - the admin one even carried the comment explaining why.

`attachStoredFile` in `api/lib` is that half, and only that half. It
answers `null` when the object could not be fetched, so each route still
returns its own `404 { error: "File not found" }`, and the OpenAPI
document is unchanged.

Authorization and lookup stay put, which is the point: the user route is
still scoped by `core_files.userId` and still 401s without a session, the
admin route still reaches any row behind `files.can_download`. A guard
test asserts both of those, and that neither route streams a file by hand
any more.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The list route re-scanned both loaded lists for every role on the page:
`names.filter(...)` once per row - a page of roles times every
translation of every one of them - and `userCounts.find(...)` once more.

`withRolesAdminListFields` builds a `Map<number, RoleName[]>` and a
`Map<number, number>` once, then reads each role's fields out of them.
Extracted beside the route rather than inlined so the mapping is testable
on its own: the test asserts it answers byte-identical JSON to the scan it
replaces, role order, per-role translation order, the empty-list and
zero-count fallbacks included.

The response contract is untouched, and the detail route's own selection
is left alone.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`readOne` was the same five lines in `my-files-query.ts` and in
`views/admin/table/params.ts`; `readParam` the same nine in
`tanstack/files/route-search.ts` and `tanstack/admin/table-search.ts`; and
`readPageSize` the same six in the first pair, differing only in which
constant it clamped to.

`lib/table-params.ts` holds `readFirstValue`, `asSearchValue` and
`readPageSize` - the last taking its maximum as an argument. It imports
nothing, and a test asserts it names no table's policy.

Everything domain-specific stays where it was: the admin `status` filter,
each table's allowed sort columns and default page size, whether there is
a search box, the cursor pattern, and the two page and row contracts. No
generic table library.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@aXenDeveloper
aXenDeveloper marked this pull request as ready for review September 12, 2026 14:38
@aXenDeveloper
aXenDeveloper merged commit f218a97 into canary Sep 12, 2026
4 checks passed
@aXenDeveloper
aXenDeveloper deleted the perf/reduce_code branch September 12, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🧱 Refactor A code change that neither fixes a bug nor adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant