Architecture-deepening candidate #3 (Worth exploring) from the improve-codebase-architecture review.
Problem
packages/core/src/context/nested-operations.ts processes nested relationship writes (create / connect / connectOrCreate / disconnect) via recursive functions dispatched by an in-place if (value.create) … else if (value.connect) … chain in processNestedOperations. The module is localized (deleting it would scatter ~150 lines back into the two call sites — it earns its keep), but its intent is opaque and adding a kind (e.g. upsert) means editing the dispatch in place rather than adding at a seam.
Deletion test → concentrates (already does); the goal here is navigability, not relocating complexity.
Proposed deepening
Give it a clear interface and move dispatch to a handler registry:
interface NestedOperationProcessor {
// Validate + transform nested relationship operations in this data per the schema.
process(data: Record<string, unknown>): Promise<ProcessedNestedOps>
}
// registry of per-kind handlers, each: { validate(op), execute(op, ctx) }
const handlers = { create, connect, connectOrCreate, disconnect /* , upsert later */ }
New nested-op kinds become new adapters at the seam, not edits to a growing if/else. Locality is unchanged; readability and extensibility improve.
Acceptance criteria
Notes
Architecture-deepening candidate #3 (Worth exploring) from the
improve-codebase-architecturereview.Problem
packages/core/src/context/nested-operations.tsprocesses nested relationship writes (create/connect/connectOrCreate/disconnect) via recursive functions dispatched by an in-placeif (value.create) … else if (value.connect) …chain inprocessNestedOperations. The module is localized (deleting it would scatter ~150 lines back into the two call sites — it earns its keep), but its intent is opaque and adding a kind (e.g.upsert) means editing the dispatch in place rather than adding at a seam.Deletion test → concentrates (already does); the goal here is navigability, not relocating complexity.
Proposed deepening
Give it a clear interface and move dispatch to a handler registry:
New nested-op kinds become new adapters at the seam, not edits to a growing
if/else. Locality is unchanged; readability and extensibility improve.Acceptance criteria
process(data)entry point over a per-kind handler registry; no in-placeif/elsedispatch chain.@opensaas/stack-corechangeset (patch). Lint/format clean; noany/casts introduced beyond the existing dynamic-model access.Notes