Skip to content

Split oversized database command functions into focused helpers#47

Merged
devxoul merged 1 commit intomainfrom
refactor/split-database-functions
Mar 10, 2026
Merged

Split oversized database command functions into focused helpers#47
devxoul merged 1 commit intomainfrom
refactor/split-database-functions

Conversation

@devxoul
Copy link
Owner

@devxoul devxoul commented Mar 10, 2026

Summary

Split the largest functions in database.ts into smaller, focused helpers to improve readability and reduce duplication. Pure refactor — no behavior changes.

Changes

viewUpdateAction decomposition

Helper Responsibility
applyVisibilityUpdates() Process --show and --hide options into property visibility flags.
applyReorderUpdates() Reorder the property map according to --reorder option.
applyResizeUpdates() Apply column width changes from --resize option.
parseCommaSeparatedNames() Shared parser for comma-delimited option values.

viewUpdateAction is now an orchestrator that delegates to these three helpers instead of inlining all the logic in one 167-line body.

serializeRowProperties decomposition

Helper Responsibility
serializePropertyValue() Dispatcher that routes to the correct type-specific serializer.
serializeTitleProperty() Title property format.
serializeSelectProperty() Select/status property format.
serializeMultiSelectProperty() Multi-select with option registration.
serializeNumberProperty() Number-to-string conversion.
serializeCheckboxProperty() Checkbox Yes/No encoding.
serializeDateProperty() Date/daterange with marker format.
serializeTextProperty() URL, email, phone, and text properties.
serializePersonProperty() Person + u annotation segments.
serializeRelationProperty() Relation + p annotation segments.
serializeDefaultProperty() Fallback for unrecognized types.

The original 85-line if/else chain becomes a 4-line loop body calling serializePropertyValue().

Shared helpers for add-row and update-row

Helper Responsibility
buildSchemaNameToId() Build property name → ID lookup map from schema.
createSchemaOptionRegistrar() Create a closure that registers new select/multi-select option values.
buildSerializedInputProperties() Parse raw JSON input and serialize through the property pipeline.
buildRowPropertySetOperations() Build the set operation array for saveTransactions.
unknownPropertyError() Consistent error message for invalid property names.
resolvePropertyIdOrThrow() Name-to-ID lookup with descriptive error on miss.

handleDatabaseAddRow and handleDatabaseUpdateRow previously duplicated the schema-to-nameToId loop and the option registration closure verbatim. Both now call the shared helpers.

Context

database.ts had several functions that exceeded comfortable readability thresholds. viewUpdateAction at 167 lines mixed three independent concerns (visibility, reorder, resize) in one body. serializeRowProperties at 85 lines was a long if/else chain where each branch was self-contained. The add-row and update-row handlers duplicated ~20 lines of identical schema setup code. Extracting focused helpers makes each unit independently understandable and eliminates the duplication.

Testing

Pure refactor — no behavioral changes. All existing tests pass unchanged: bun run typecheck clean, bun test src/ = 599 pass / 0 fail, database tests = 50 pass / 0 fail.


Summary by cubic

Split oversized database command functions into small, focused helpers to improve readability and remove duplication. Pure refactor with no behavior changes; tests pass unchanged.

  • Refactors
    • View updates: extracted applyVisibilityUpdates, applyReorderUpdates, applyResizeUpdates, and parseCommaSeparatedNames.
    • Property serialization: added serializePropertyValue and type-specific serializers (title, select/status, multi-select, number, checkbox, date, text/url/email/phone, person, relation, default).
    • Shared helpers for add/update row: buildSchemaNameToId, createSchemaOptionRegistrar, buildSerializedInputProperties, buildRowPropertySetOperations, resolvePropertyIdOrThrow, and unknownPropertyError.
    • Consolidated name-to-ID lookups and option registration to eliminate duplicate logic in add/update handlers.

Written for commit f45095b. Summary will update on new commits.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@devxoul devxoul merged commit 06ad69b into main Mar 10, 2026
2 checks passed
@devxoul devxoul deleted the refactor/split-database-functions branch March 10, 2026 09:32
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