From e11b788bbc0f753435a72a9c4c07db89132fa459 Mon Sep 17 00:00:00 2001 From: seveibar Date: Sun, 26 Jul 2026 19:38:32 -0700 Subject: [PATCH] Add bus routing constraint props --- README.md | 13 +++++++++++++ generated/COMPONENT_TYPES.md | 18 ++++++++++++++++++ generated/PROPS_OVERVIEW.md | 7 +++++++ lib/components/bus.ts | 20 ++++++++++++++++++++ lib/index.ts | 1 + tests/bus.test.ts | 20 ++++++++++++++++++++ 6 files changed, 79 insertions(+) create mode 100644 lib/components/bus.ts create mode 100644 tests/bus.test.ts diff --git a/README.md b/README.md index 00b0c010..57ee539d 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ resistorProps.parse({ resistance: "10k" } as ResistorPropsInput); | `` | [`BoardProps`](#boardprops-board) | | `` | [`BreakoutProps`](#breakoutprops-breakout) | | `` | [`BreakoutPointProps`](#breakoutpointprops-breakoutpoint) | +| `` | [`BusProps`](#busprops-bus) | | `` | [`CadAssemblyProps`](#cadassemblyprops-cadassembly) | | `` | [`CadModelProps`](#cadmodelprops-cadmodel) | | `` | [`CapacitorProps`](#capacitorprops-capacitor) | @@ -429,6 +430,18 @@ export interface BreakoutPointProps extends Omit< [Source](https://github.com/tscircuit/props/blob/main/lib/components/breakoutpoint.ts) +### BusProps `` + +```ts +export interface BusProps { + name?: string; + /** Trace names or port selectors for the connections in the bus. */ + connections: string[]; +} +``` + +[Source](https://github.com/tscircuit/props/blob/main/lib/components/bus.ts) + ### CadAssemblyProps `` ```ts diff --git a/generated/COMPONENT_TYPES.md b/generated/COMPONENT_TYPES.md index 99bec4ed..0b9f15d3 100644 --- a/generated/COMPONENT_TYPES.md +++ b/generated/COMPONENT_TYPES.md @@ -1275,6 +1275,24 @@ export const breakoutPointProps = pcbLayoutProps }) ``` +### bus + +```typescript +/** + * Declares a group of connections that an autorouter should keep together. + * Each connection may be a trace name or a port selector. + */ +export interface BusProps { + name?: string + connections: string[] +} +/** Trace names or port selectors for the connections in the bus. */ +export const busProps = z.object({ + name: z.string().optional(), + connections: z.array(z.string()).min(2), +}) +``` + ### cadassembly ```typescript diff --git a/generated/PROPS_OVERVIEW.md b/generated/PROPS_OVERVIEW.md index ab5d8baf..a1a77650 100644 --- a/generated/PROPS_OVERVIEW.md +++ b/generated/PROPS_OVERVIEW.md @@ -408,6 +408,13 @@ export interface BreakoutProps } +export interface BusProps { + name?: string + /** Trace names or port selectors for the connections in the bus. */ + connections: string[] +} + + export interface CadAssemblyProps { /** * The layer that the CAD assembly is designed for. If you set this to "top" diff --git a/lib/components/bus.ts b/lib/components/bus.ts new file mode 100644 index 00000000..0eed3577 --- /dev/null +++ b/lib/components/bus.ts @@ -0,0 +1,20 @@ +import { expectTypesMatch } from "lib/typecheck" +import { z } from "zod" + +/** + * Declares a group of connections that an autorouter should keep together. + * Each connection may be a trace name or a port selector. + */ +export interface BusProps { + name?: string + /** Trace names or port selectors for the connections in the bus. */ + connections: string[] +} + +export const busProps = z.object({ + name: z.string().optional(), + connections: z.array(z.string()).min(2), +}) + +type InferredBusProps = z.input +expectTypesMatch(true) diff --git a/lib/index.ts b/lib/index.ts index c53f2f52..e2dec7f8 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -58,6 +58,7 @@ export * from "./components/smtpad" export * from "./components/solderpaste" export * from "./components/hole" export * from "./components/trace" +export * from "./components/bus" export * from "./components/differentialpair" export * from "./components/footprint" export * from "./components/symbol" diff --git a/tests/bus.test.ts b/tests/bus.test.ts new file mode 100644 index 00000000..0fee5925 --- /dev/null +++ b/tests/bus.test.ts @@ -0,0 +1,20 @@ +import { expect, test } from "bun:test" +import { busProps, type BusProps } from "lib/components/bus" + +test("busProps accepts two or more connection references", () => { + const rawProps: BusProps = { + name: "DATA", + connections: ["D0", ".U1 > .D1"], + } + + expect(busProps.parse(rawProps)).toEqual(rawProps) +}) + +test("busProps rejects a single connection", () => { + expect( + busProps.safeParse({ + name: "DATA", + connections: ["D0"], + }).success, + ).toBe(false) +})