Skip to content

Commit

Permalink
add key as optional parameter for trace props (#50)
Browse files Browse the repository at this point in the history
* add key as optional parameter for trace props

* add key to common component props

* fix type issue by adding to zod prop

* formatbot: Automatically format code

* switch to bun lockfiles

* update lockfile

* switch typehceck to bun

* update formatcheck

---------

Co-authored-by: tscircuitbot <tscircuitbot@users.noreply.github.com>
  • Loading branch information
seveibar and tscircuitbot authored Sep 15, 2024
1 parent 44af085 commit b0a8305
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 6,719 deletions.
23 changes: 12 additions & 11 deletions .github/workflows/formatcheck.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
# Created using @tscircuit/plop (npm install -g @tscircuit/plop)
name: Format Check

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:
format-check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '22'
- name: Setup bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install dependencies
run: npm ci
- name: Install dependencies
run: bun install

- name: Run format check
run: npm run format:check
- name: Run format check
run: bun run format:check
12 changes: 6 additions & 6 deletions .github/workflows/npm-typecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
- name: Setup bun
uses: oven-sh/setup-bun@v1
with:
node-version: "22"
bun-version: latest

- name: Install dependencies
run: npm ci
run: bun i

- name: Run format check
run: npx tsc --noEmit
- name: Run type check
run: bunx tsc --noEmit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
dist
.vscode
.aider*
package-lock.json
Binary file added bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions lib/common/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const supplierProps = z.object({
expectTypesMatch<SupplierProps, z.input<typeof supplierProps>>(true)

export interface CommonComponentProps extends CommonLayoutProps {
key?: any
name: string
supplierPartNumbers?: SupplierProps["supplierPartNumbers"]
cadModel?: CadModelProp
Expand All @@ -92,6 +93,7 @@ export interface CommonComponentProps extends CommonLayoutProps {
export const commonComponentProps = commonLayoutProps
.merge(supplierProps)
.extend({
key: z.any().optional(),
name: z.string(),
cadModel: cadModelProp.optional(),
children: z.any().optional(),
Expand Down
30 changes: 30 additions & 0 deletions lib/components/trace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { z } from "zod"
import { distance, route_hint_point } from "@tscircuit/soup"
import { point } from "../common/point"

export const portRef = z.union([
z.string(),
z.custom<{ getPortSelector: () => string }>((v) =>
Boolean(v.getPortSelector),
),
])

const baseTraceProps = z.object({
key: z.string().optional(),
path: z.array(portRef),
thickness: distance.optional(),
schematicRouteHints: z.array(point).optional(),
pcbRouteHints: z.array(route_hint_point).optional(),
})

export const traceProps = z.union([
baseTraceProps.extend({
path: z.array(portRef),
}),
baseTraceProps.extend({
from: portRef,
to: portRef,
}),
])

export type TraceProps = z.input<typeof traceProps>
26 changes: 1 addition & 25 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export * from "./components/constrainedlayout"
export * from "./components/constraint"
export * from "./components/smtpad"
export * from "./components/hole"
export * from "./components/trace"

export const inductorProps = commonComponentProps.extend({
inductance,
Expand Down Expand Up @@ -96,31 +97,6 @@ export const netAliasProps = commonLayoutProps.extend({
})
export type NetAliasProps = z.input<typeof netAliasProps>

export const portRef = z.union([
z.string(),
z.custom<{ getPortSelector: () => string }>((v) =>
Boolean(v.getPortSelector),
),
])

export const traceProps = z
.object({
path: z.array(portRef),
thickness: distance.optional(),
schematicRouteHints: z.array(point).optional(),
pcbRouteHints: z.array(route_hint_point).optional(),
})
.or(
z.object({
from: portRef,
to: portRef,
thickness: distance.optional(),
schematicRouteHints: z.array(point).optional(),
pcbRouteHints: z.array(route_hint_point).optional(),
}),
)
export type TraceProps = z.input<typeof traceProps>

export const platedHoleProps = z.union([
pcbLayoutProps.omit({ pcbRotation: true, layer: true }).extend({
name: z.string().optional(),
Expand Down
Loading

0 comments on commit b0a8305

Please sign in to comment.