Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/assembly-cable.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,14 @@ are inferred; there are no corresponding props or aliases.
This is an additive props API and requires no migration. The schema validates
the inputs; endpoint resolution, routing, and rendering require support in core
and the CAD renderer.

## Explicit cable models

Set `model` to use a cable specification instead of inferring it from the endpoints.

```tsx
<assembly.cable name="C1" from=".J1" to=".J2"
model="adaptercable_a(jst_sh_pins4)_b(jst_ph_pins4)" />
```

`standard` retains its existing meaning. Omitting `model` preserves endpoint inference.
2 changes: 2 additions & 0 deletions generated/PROPS_OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ export interface AssemblyCableProps {
to: string
/** Optional USB-C-to-USB-C preset. Omit to infer the cable from its endpoints. */
standard?: AssemblyCableStandard
/** Explicit cable model specification. Omit to infer the cable from its endpoints. */
model?: string
}


Expand Down
3 changes: 3 additions & 0 deletions lib/assembly/cable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ export interface AssemblyCableProps {
to: string
/** Optional USB-C-to-USB-C preset. Omit to infer the cable from its endpoints. */
standard?: AssemblyCableStandard
/** Explicit cable model specification. Omit to infer the cable from its endpoints. */
model?: string
}

export const assemblyCableProps = z.object({
name: z.string().trim().min(1),
from: z.string().trim().min(1),
to: z.string().trim().min(1),
standard: z.literal("usb_c").optional(),
model: z.string().trim().min(1).optional(),
})

export type AssemblyCablePropsInput = z.input<typeof assemblyCableProps>
Expand Down
14 changes: 14 additions & 0 deletions tests/assembly-cable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,17 @@ test("assembly.cable requires an identity and two nonempty endpoint strings", ()
)
}
})

test("assembly.cable accepts an explicit model without changing standard behavior", () => {
const input = {
name: "C1",
from: ".J1",
to: ".J2",
model: "adaptercable_a(jst_sh_pins4)_b(jst_ph_pins4)",
}
expect(assemblyCableProps.parse(input)).toEqual(input)
for (const model of ["", " ", 4, null])
expect(assemblyCableProps.safeParse({ ...input, model }).success).toBe(
false,
)
})
Comment on lines +57 to +69

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A *.test.ts file may have AT MOST one test(...) call. The file assembly-cable.test.ts already contained at least one test(...) before this diff, and this change adds another one ("assembly.cable accepts an explicit model without changing standard behavior"). Per the style guide, once a second test is needed the tests must be split into multiple numbered files, e.g. assembly-cable1.test.ts, assembly-cable2.test.ts. Please move this new test into its own numbered file.

Spotted by Graphite (based on custom rule: Custom rule)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Loading