Skip to content

Clarify nested-operation handling behind a registry seam (architecture follow-up) #436

@borisno2

Description

@borisno2

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

  • A single process(data) entry point over a per-kind handler registry; no in-place if/else dispatch chain.
  • Behaviour preserved for create/connect/connectOrCreate/disconnect (existing nested-operation tests stay green; add tests per handler if missing).
  • @opensaas/stack-core changeset (patch). Lint/format clean; no any/casts introduced beyond the existing dynamic-model access.

Notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentFully specified, ready for an AFK agent

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions