refactor(table): split the 5.3k-line service.ts god-file into per-concern modules#5069
Conversation
…m service.ts Move the row position/fractional-ordering internals to rows/ordering.ts, the row-execution (workflow-group result) internals to rows/executions.ts, and the shared tx-timeout helpers to tx.ts. Pure code-motion — verbatim bodies, identical behavior. service.ts: 5324 -> 4442 lines.
Move insert/update/upsert/delete/replace/batch row writes, queryRows/ getRowById reads, and findRowMatches into rows/service.ts. Verbatim bodies; consumers repointed; @/lib/table barrel re-exports the new module so callers are unchanged. service.ts: 4442 -> 2788 lines.
…e.ts Move add/rename/delete column ops and column-type/constraint updates into columns/service.ts. addTableColumnsWithTx stays in service.ts (table-creation primitive) to avoid a cycle. Verbatim bodies; barrel re-exports the module. service.ts: 2788 -> 2149 lines.
…service.ts Move tableJobs reads/mapping, the job lifecycle state machine, and export-job queries into jobs/service.ts. service.ts imports latestJob* one-way for table metadata enrichment (no cycle). Import-data orchestration helpers stay in service.ts for now. Verbatim bodies. service.ts: 2149 -> 1791 lines.
…ps/service.ts Move add/update/delete workflow groups + outputs and pruneStale into workflow-groups/service.ts, preserving the dynamic backfill-runner import (cycle-breaker). Verbatim bodies; no cycle. service.ts: 1791 -> 851 lines.
Move bulk insert, schema setup, and append/replace import operations into import-data.ts (consumed by import-runner + import route). service.ts is now the pure table-entity module (root CRUD + shared lock/column primitives). Verbatim bodies; no cycle. service.ts: 851 -> 664 lines (5324 at start).
…t-split Un-export DerivedJobFields/JOB_PROJECTION/mapJobRow (file-local in jobs/service.ts, were private pre-split) so they no longer leak into the @/lib/table barrel. Remove dead code carried into the new modules: countTables (createTable does its own inline count check) and the unused buildOrderedRowValues/OrderedRowValue pair.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Call sites across table API routes, v1 APIs, background workers ( No intended behavior change—logic is moved verbatim into the new files with dependency ordering preserved (e.g. column ops still use Reviewed by Cursor Bugbot for commit a5a2b7e. Configure here. |
Greptile SummaryThis PR decomposes the monolithic
Confidence Score: 5/5Safe to merge — pure code-motion with no logic changes, a valid acyclic dependency graph, and all consumers correctly repointed. Every moved function body is verbatim from the original file. The dependency graph is a strict DAG with the backfill-runner cycle preserved via lazy dynamic import. No consumer imports a symbol missing from the new barrel or sub-module paths. The only difference from the stated intent is that three previously-private helpers become reachable via the barrel, which is additive and cannot regress existing callers. The new barrel (index.ts) is the only place worth a second glance to confirm intentional surface exposure of the three newly-public job helpers. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
barrel["@/lib/table (index.ts)\n— public barrel —"]
service["service.ts\nroot CRUD + withLockedTable\naddTableColumnsWithTx"]
rows_svc["rows/service.ts\ninsertRow / updateRow / deleteRow\nqueryRows / findRowMatches"]
cols_svc["columns/service.ts\naddTableColumn / renameColumn\ndeleteColumn / updateColumnType"]
jobs_svc["jobs/service.ts\nmarkTableJobRunning / releaseJobClaim\nselectExportRowPage / getTableJob"]
wfg_svc["workflow-groups/service.ts\naddWorkflowGroup / updateWorkflowGroup\npruneStaleWorkflowGroupOutputs"]
import_data["import-data.ts\nbulkInsertImportBatch\nimportAppendRows / importReplaceRows"]
rows_ord["rows/ordering.ts internal\nacquireRowOrderLock / selectRowIdPage"]
rows_exec["rows/executions.ts internal\nloadExecutionsByRow / applyExecutionsPatch"]
tx["tx.ts internal\nsetTableTxTimeouts / scaledStatementTimeoutMs"]
backfill["backfill-runner.ts\n— lazy dynamic import —"]
barrel --> service
barrel --> rows_svc
barrel --> cols_svc
barrel --> jobs_svc
barrel --> wfg_svc
barrel --> import_data
service --> jobs_svc
cols_svc --> service
wfg_svc --> service
import_data --> service
import_data --> rows_svc
jobs_svc --> rows_svc
rows_svc --> rows_ord
rows_svc --> rows_exec
cols_svc --> rows_exec
wfg_svc --> rows_exec
service --> tx
rows_svc --> tx
cols_svc --> tx
rows_ord --> tx
wfg_svc --> tx
wfg_svc -. "await import()" .-> backfill
backfill --> jobs_svc
backfill --> rows_svc
Reviews (3): Last reviewed commit: "refactor(table): use absolute imports th..." | Re-trigger Greptile |
…TSDoc Normalize all relative imports under lib/table to absolute @/lib/table/... per the project import rule (the split modules and a few pre-existing holdouts), and relocate the getTableById TSDoc that had drifted above applyColumnOrderToSchema. Comment/import-only; zero behavior change.
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit a5a2b7e. Configure here.
|
Re: the partial This whole PR is mechanically verified pure code-motion: of the 93 functions in the original Re-triggering on the latest commit ( @greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit a5a2b7e. Configure here.
Summary
Decompose
lib/table/service.ts(5,324 lines / 58 exports) into per-concern modules, following the establishedlib/knowledge/pattern (subdomainservice.tsfiles, plain exported functions, drizzle inline — no repository/manager layer) while keeping the@/lib/tablebarrel stable.service.ts: 5,324 → 651 lines (now the pure table-entity module: root CRUD + the sharedwithLockedTable/addTableColumnsWithTxprimitives). New modules:rows/ordering.ts,rows/executions.ts— leaf foundations (position/order-key, workflow-group result rows)rows/service.ts— row CRUD + querycolumns/service.ts— schema/column managementjobs/service.ts—tableJobsstate machine + export jobsworkflow-groups/service.ts— workflow-group management (lazybackfill-runnercycle-breaker preserved)tx.ts,import-data.ts— shared tx helpers; import-job data opsBuilt in 7 dependency-ordered, individually-green commits (leaves first).
Type of Change
Testing
origin/staging, no cycles, public surface preserved, all consumers + test mocks repointed correctly, no duplication, no shims.check:api-validation+ monorepo-boundary pass.countTables—createTablehas its own inline count check; unusedbuildOrderedRowValues); over-exported file-local symbols restored to private so the public barrel surface is unchanged.Checklist