Add proposed cable-sizing module

Isolated module (mirrors src/external-model/ dependency direction) that
adds an on-demand, DIN VDE 0298-4 referenced cable cross-section
calculator: a click-on-a-circuit input mask for laying method,
insulation, ambient temperature, grouping and voltage-drop limit that
suggests a cross-section for the circuit cableCrossSection/cableLength
fields. Applying a suggestion goes through the existing circuit.update
command (expectedRevision, undo/redo) unchanged - nothing here writes
to circuits directly or touches the revision/command system. See
docs/cable-sizing-module.md for the full rationale, API contract,
verification status and maintenance plan. Proposal, not yet reviewed
by the project owner - see the docs file.

423 existing + 11 new tests pass, build:api/build:web/typecheck:scripts
clean.
This commit is contained in:
Grovy311 2026-08-07 17:13:59 +02:00
parent a17e2e3f4b
commit 1d030971dd
17 changed files with 4179 additions and 2 deletions

View file

@ -0,0 +1,37 @@
import { desc, eq } from "drizzle-orm";
import type { AppDatabase } from "../database-context.js";
import {
cableSizingCalculations,
type CableSizingCalculation,
type NewCableSizingCalculation,
} from "../schema/cable-sizing-calculations.js";
// Plain repository, no revision/command semantics - mirrors
// application-repositories.ts's flat repository pattern, not the
// project-command-transaction boundary. A calculation is an audit record,
// not a project mutation.
export class CableSizingCalculationRepository {
constructor(private readonly db: AppDatabase) {}
create(input: NewCableSizingCalculation): CableSizingCalculation {
return this.db.insert(cableSizingCalculations).values(input).returning().get();
}
listByCircuit(circuitId: string): CableSizingCalculation[] {
return this.db
.select()
.from(cableSizingCalculations)
.where(eq(cableSizingCalculations.circuitId, circuitId))
.orderBy(desc(cableSizingCalculations.createdAt))
.all();
}
markApplied(id: string): CableSizingCalculation | undefined {
return this.db
.update(cableSizingCalculations)
.set({ appliedToCircuit: 1 })
.where(eq(cableSizingCalculations.id, id))
.returning()
.get();
}
}