Skip to content

Commit

Permalink
schematic pin defs (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar authored Sep 30, 2024
1 parent 832d1da commit 1abba45
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 30 deletions.
48 changes: 18 additions & 30 deletions lib/common/schematicPinDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export interface SchematicPortArrangementWithSides {
bottomSide?: PinSideDefinition
}

export type SchematicPortArrangement =
| SchematicPortArrangementWithSizes
| SchematicPortArrangementWithSides
| SchematicPortArrangementWithPinCounts
export interface SchematicPortArrangement
extends SchematicPortArrangementWithSizes,
SchematicPortArrangementWithSides,
SchematicPortArrangementWithPinCounts {}

export const explicitPinSideDefinition = z.object({
pins: z.array(z.number()),
Expand All @@ -52,32 +52,20 @@ export const explicitPinSideDefinition = z.object({
]),
})

export const schematicPortArrangement = z
.object({
leftSize: z.number().optional().describe("@deprecated, use leftPinCount"),
topSize: z.number().optional().describe("@deprecated, use topPinCount"),
rightSize: z.number().optional().describe("@deprecated, use rightPinCount"),
bottomSize: z
.number()
.optional()
.describe("@deprecated, use bottomPinCount"),
})
.or(
z.object({
leftPinCount: z.number().optional(),
rightPinCount: z.number().optional(),
topPinCount: z.number().optional(),
bottomPinCount: z.number().optional(),
}),
)
.or(
z.object({
leftSide: explicitPinSideDefinition.optional(),
rightSide: explicitPinSideDefinition.optional(),
topSide: explicitPinSideDefinition.optional(),
bottomSide: explicitPinSideDefinition.optional(),
}),
)
export const schematicPortArrangement = z.object({
leftSize: z.number().optional().describe("@deprecated, use leftPinCount"),
topSize: z.number().optional().describe("@deprecated, use topPinCount"),
rightSize: z.number().optional().describe("@deprecated, use rightPinCount"),
bottomSize: z.number().optional().describe("@deprecated, use bottomPinCount"),
leftPinCount: z.number().optional(),
rightPinCount: z.number().optional(),
topPinCount: z.number().optional(),
bottomPinCount: z.number().optional(),
leftSide: explicitPinSideDefinition.optional(),
rightSide: explicitPinSideDefinition.optional(),
topSide: explicitPinSideDefinition.optional(),
bottomSide: explicitPinSideDefinition.optional(),
})

expectTypesMatch<
SchematicPortArrangement,
Expand Down
File renamed without changes.
41 changes: 41 additions & 0 deletions tests/chip2-schematic-port-arrangement.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { expect, test } from "bun:test"
import { chipProps, type ChipProps } from "lib/components/chip"
import type { z } from "zod"
import { expectTypeOf } from "expect-type"

test("should parse chip props", () => {
const rawProps: ChipProps = {
name: "chip",
manufacturerPartNumber: "1234",
pinLabels: {
1: "1",
2: "2",
3: "3",
4: "4",
},
schPortArrangement: {
leftSide: {
pins: [29, 7, 8, 20, 19, 22],
direction: "top-to-bottom",
},
topSide: {
direction: "left-to-right",
pins: [4, 18],
},
rightSide: {
direction: "bottom-to-top",
pins: [12, 13, 14, 15, 16, 17, 23],
},
},
schPinSpacing: "0.2mm",
schWidth: 2,
}

// expectTypeOf(rawProps).toMatchTypeOf<z.input<typeof chipProps>>()

const parsedProps = chipProps.parse(rawProps)

expect((parsedProps.schPortArrangement as any)?.leftSide.pins).toEqual([
29, 7, 8, 20, 19, 22,
])
})

0 comments on commit 1abba45

Please sign in to comment.