Skip to content

refactor(storage): extract parseJsonColumn helper in organization-settings - #6493

Merged
pedrofrxncx merged 1 commit into
mainfrom
refactor/dedupe-org-settings-json-column-parse-w2
Aug 25, 2026
Merged

refactor(storage): extract parseJsonColumn helper in organization-settings#6493
pedrofrxncx merged 1 commit into
mainfrom
refactor/dedupe-org-settings-json-column-parse-w2

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Source: C1 code-reduction, found while auditing the org-settings storage layer (apps/api/src/storage/organization-settings.ts) for the org-settings-persistence focus area. No related open PR touches this file — #6487/#6481/#6464/#6445 (recently merged/open) all touch update.ts/delete.ts/member-list.ts, not this file.

What/why: OrganizationSettingsStorage.get() inlined the same 'jsonb column may come back as a string or as an already-parsed value' ternary 7 times, once per settings field (sidebar_items, enabled_plugins, registry_config, simple_mode, default_home_agents, flags, sprint_config). Collapsed into one parseJsonColumn<T>() helper called per field. A maintainer gets one place to fix this normalization logic instead of seven.

Net delta: -35 / +28 lines in one file, no behavior change: same null-check, same typeof === "string" ? JSON.parse(...) : value logic, just factored out. Each call site passes an explicit type argument because Kysely's ColumnType select type doesn't infer cleanly through a bare generic parameter (confirmed via tsc --noEmit — inferring from the parameter directly produced a T[][] mismatch).

How a reviewer confirms: read the diff — parseJsonColumn is a straight extraction of the pre-existing ternary, and every field still round-trips through it. No integration test exists for this file that doesn't need real Postgres (this box has none available), so verification here is static: the change is a pure refactor with no schema/query changes.

Checks run locally: bun run fmt, cd apps/api && bunx tsc --noEmit (green), bunx oxlint apps/api/src/storage/organization-settings.ts (0 warnings/errors). Full CI (including the Postgres-backed integration test for this file) validates the rest.


Summary by cubic

Deduplicates JSON parsing for organization settings by extracting a parseJsonColumn<T>() helper. Behavior is unchanged: the previous per-field ternary becomes a single helper that normalizes string-or-object jsonb values with the same null check.

  • No schema or query changes; only get() in apps/api/src/storage/organization-settings.ts is touched.
  • Each call site passes an explicit generic due to kysely select type inference limits.
  • To review: compare the helper to the prior ternary and confirm all JSON fields (sidebar_items, enabled_plugins, registry_config, simple_mode, default_home_agents, flags, sprint_config) route through it.

Written for commit 1bec1b4. Summary will update on new commits.

Review in cubic

…tings

The get() method had the same 'string or already-parsed jsonb column'
ternary inlined 7 times, one per settings field. Collapse it into one
generic helper and call it per field with an explicit type argument
(kysely's ColumnType select type doesn't infer cleanly through a bare
generic, so the type argument is spelled out at each call site).
@pedrofrxncx
pedrofrxncx merged commit 2306a5e into main Aug 25, 2026
34 checks passed
@pedrofrxncx
pedrofrxncx deleted the refactor/dedupe-org-settings-json-column-parse-w2 branch August 25, 2026 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant