Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce the sel object #549

Merged
merged 2 commits into from
Jan 24, 2025
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
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from "./hooks/use-diode"
export * from "./hooks/use-led"
export * from "./hooks/use-resistor"
export * from "./utils/public-exports"
export * from "./sel"

// Allows easier introspection of render process
export * from "./components/base-components/Renderable"
Expand Down
1 change: 1 addition & 0 deletions lib/sel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./sel"
189 changes: 189 additions & 0 deletions lib/sel/sel-utility-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
export type Nums16 =
| "1"
| "2"
| "3"
| "4"
| "5"
| "6"
| "7"
| "8"
| "9"
| "10"
| "11"
| "12"
| "13"
| "14"
| "15"
| "16"

export type Nums40 =
| "1"
| "2"
| "3"
| "4"
| "5"
| "6"
| "7"
| "8"
| "9"
| "10"
| "11"
| "12"
| "13"
| "14"
| "15"
| "16"
| "17"
| "18"
| "19"
| "20"
| "21"
| "22"
| "23"
| "24"
| "25"
| "26"
| "27"
| "28"
| "29"
| "30"
| "31"
| "32"
| "33"
| "34"
| "35"
| "36"
| "37"
| "38"
| "39"
| "40"

export type PinNumbers100 =
| "pin1"
| "pin2"
| "pin3"
| "pin4"
| "pin5"
| "pin6"
| "pin7"
| "pin8"
| "pin9"
| "pin10"
| "pin11"
| "pin12"
| "pin13"
| "pin14"
| "pin15"
| "pin16"
| "pin17"
| "pin18"
| "pin19"
| "pin20"
| "pin21"
| "pin22"
| "pin23"
| "pin24"
| "pin25"
| "pin26"
| "pin27"
| "pin28"
| "pin29"
| "pin30"
| "pin31"
| "pin32"
| "pin33"
| "pin34"
| "pin35"
| "pin36"
| "pin37"
| "pin38"
| "pin39"
| "pin40"
| "pin41"
| "pin42"
| "pin43"
| "pin44"
| "pin45"
| "pin46"
| "pin47"
| "pin48"
| "pin49"
| "pin50"
| "pin51"
| "pin52"
| "pin53"
| "pin54"
| "pin55"
| "pin56"
| "pin57"
| "pin58"
| "pin59"
| "pin60"
| "pin61"
| "pin62"
| "pin63"
| "pin64"
| "pin65"
| "pin66"
| "pin67"
| "pin68"
| "pin69"
| "pin70"
| "pin71"
| "pin72"
| "pin73"
| "pin74"
| "pin75"
| "pin76"
| "pin77"
| "pin78"
| "pin79"
| "pin80"
| "pin81"
| "pin82"
| "pin83"
| "pin84"
| "pin85"
| "pin86"
| "pin87"
| "pin88"
| "pin89"
| "pin90"
| "pin91"
| "pin92"
| "pin93"
| "pin94"
| "pin95"
| "pin96"
| "pin97"
| "pin98"
| "pin99"
| "pin100"

export type CommonPinNames =
| "pos"
| "neg"
| "V5"
| "V3_3"
| "VCC"
| "VDD"
| "GND"
| `D${Nums40}`
| `GP${Nums40}`
| `GPIO${Nums40}`
| "DP"
| "DN"
| "VIN"
| "VOUT"
| "VREF"
| "VIN"
| "VOUT"
| "VREF"
| "VIN"
| "VOUT"
| "VREF"
| `A${Nums40}`
| `B${Nums40}`
| PinNumbers100

export type TransistorPinNames = "base" | "collector" | "emitter"
68 changes: 68 additions & 0 deletions lib/sel/sel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type {
CommonPinNames,
Nums16,
Nums40,
PinNumbers100,
TransistorPinNames,
} from "./sel-utility-types"

type NonPolarizedSel = Record<
`R${Nums40}` | `SW${Nums40}`,
{
pin1: string
pin2: string
pos: string
neg: string
}
>

type PolarizedSel = Record<
| `C${Nums40}`
| `L${Nums40}`
| `LED${Nums40}`
| `D${Nums40}`
| `Y${Nums40}`
| `B${Nums16}`,
{
pin1: string
pin2: string
anode: string
cathode: string
pos: string
neg: string
}
>

type TransistorSel = Record<`Q${Nums40}`, Record<TransistorPinNames, string>>

type JumperSel = Record<`J${Nums40}`, Record<PinNumbers100, string>>

type ChipSel = Record<`U${Nums40}`, Record<CommonPinNames, string>>

type NetSel = Record<"net", Record<"VCC" | "GND" | "VDD", string>>

export type Sel = NonPolarizedSel &
PolarizedSel &
TransistorSel &
JumperSel &
ChipSel &
NetSel

export const sel: Sel = new Proxy(
{},
{
get: (_, prop1: string) => {
return new Proxy(
{},
{
get: (_, prop2: string) => {
if (prop1 === "net") {
return `net.${prop2}`
}
return `.${prop1} > .${prop2}`
},
},
)
},
},
) as any
29 changes: 29 additions & 0 deletions tests/sel/sel1.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { sel } from "lib/sel"
import { test, expect } from "bun:test"

test("sel1 - sel.R1.pos = .R1 > .pos", () => {
expect(sel.R1.pos).toBe(".R1 > .pos")
})

test("sel1 - sel.U1.VCC = .U1 > .VCC", () => {
expect(sel.U1.VCC).toBe(".U1 > .VCC")
})

test("sel1 - invalid refdes", () => {
// @ts-expect-error
const someval = sel.ASDF1.pin1
})

test("sel1 - invalid net", () => {
// @ts-expect-error
const someval = sel.net.ASDF1
})

test("sel1 - invalid pin number", () => {
// @ts-expect-error
const someval = sel.R1.pin3
})

test("sel1 - sel.net.VCC = net.VCC", () => {
expect(sel.net.VCC).toBe("net.VCC")
})
Loading