Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ export interface FuseProps<
/**
* Connections to other components
*/
connections?: Connections<PinLabel>;
connections?: Connections<FusePinLabels>;
}
```

Expand Down
13 changes: 2 additions & 11 deletions generated/COMPONENT_TYPES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2155,7 +2155,7 @@ export interface FuseProps<PinLabel extends string = string>

schOrientation?: SchematicOrientation

connections?: Connections<PinLabel>
connections?: Connections<FusePinLabels>
}
/**
* Schema for validating fuse props
Expand All @@ -2165,16 +2165,7 @@ export const fuseProps = commonComponentProps.extend({
voltageRating: z.union([z.number(), z.string()]).optional(),
schShowRatings: z.boolean().optional(),
schOrientation: schematicOrientation.optional(),
connections: z
.record(
z.string(),
z.union([
z.string(),
z.array(z.string()).readonly(),
z.array(z.string()),
]),
)
.optional(),
connections: createConnectionsProp(fusePinLabels).optional(),
})
```

Expand Down
2 changes: 1 addition & 1 deletion generated/PROPS_OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ export interface FuseProps<PinLabel extends string = string>
/**
* Connections to other components
*/
connections?: Connections<PinLabel>
connections?: Connections<FusePinLabels>
}


Expand Down
17 changes: 6 additions & 11 deletions lib/components/fuse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { z } from "zod"
import { createConnectionsProp } from "lib/common/connectionsProp"
import {
type CommonComponentProps,
commonComponentProps,
Expand All @@ -7,6 +8,7 @@ import {
schematicOrientation,
type SchematicOrientation,
} from "lib/common/schematicOrientation"
import { expectTypesMatch } from "lib/typecheck"
import type { Connections } from "lib/utility-types/connections-and-selectors"

/**
Expand Down Expand Up @@ -38,7 +40,7 @@ export interface FuseProps<PinLabel extends string = string>
/**
* Connections to other components
*/
connections?: Connections<PinLabel>
connections?: Connections<FusePinLabels>
}

/**
Expand All @@ -49,16 +51,9 @@ export const fuseProps = commonComponentProps.extend({
voltageRating: z.union([z.number(), z.string()]).optional(),
schShowRatings: z.boolean().optional(),
schOrientation: schematicOrientation.optional(),
connections: z
.record(
z.string(),
z.union([
z.string(),
z.array(z.string()).readonly(),
z.array(z.string()),
]),
)
.optional(),
connections: createConnectionsProp(fusePinLabels).optional(),
})

export type InferredFuseProps = z.input<typeof fuseProps>

expectTypesMatch<FuseProps, InferredFuseProps>(true)
48 changes: 48 additions & 0 deletions tests/fuse.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { expect, test } from "bun:test"
import { fuseProps, type FuseProps } from "lib/components/fuse"

test("should parse fuse connections keyed by pin labels", () => {
const raw: FuseProps = {
name: "F1",
currentRating: "1A",
connections: {
pin1: "net.VCC",
pin2: ["net.GND"],
},
}

const parsed = fuseProps.parse(raw)
expect(parsed.connections).toEqual({
pin1: "net.VCC",
pin2: ["net.GND"],
})
})

test("should reject fuse connections keyed by an unknown pin", () => {
const parsed = fuseProps.safeParse({
name: "F1",
currentRating: "1A",
connections: { pin99: ".R1 > .pin1" },
})

expect(parsed.success).toBe(false)
})

test("should reject fuse connections keyed by an empty string", () => {
const parsed = fuseProps.safeParse({
name: "F1",
currentRating: "1A",
connections: { "": ".R1 > .pin1" },
})

expect(parsed.success).toBe(false)
})

test("should allow optional fuse connections", () => {
const parsed = fuseProps.parse({
name: "F1",
currentRating: "1A",
})

expect(parsed.connections).toBeUndefined()
})
Loading