-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more refactoring to better defined props, split out capacitor and res…
…istor, add jumper, add pullupFor, decouplingFor (#35)
- Loading branch information
Showing
11 changed files
with
230 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,64 @@ | ||
import { z } from "zod" | ||
import { point3 } from "./point3" | ||
import { expectTypesMatch } from "lib/typecheck" | ||
|
||
export const rotationPoint3 = z.object({ | ||
x: z.union([z.number(), z.string()]), | ||
y: z.union([z.number(), z.string()]), | ||
z: z.union([z.number(), z.string()]), | ||
}) | ||
|
||
export interface CadModelBase { | ||
rotationOffset?: | ||
| number | ||
| { x: number | string; y: number | string; z: number | string } | ||
positionOffset?: { | ||
x: number | string | ||
y: number | string | ||
z: number | string | ||
} | ||
size?: { x: number | string; y: number | string; z: number | string } | ||
} | ||
|
||
export const cadModelBase = z.object({ | ||
rotationOffset: z.number().or(rotationPoint3).optional(), | ||
positionOffset: point3.optional(), | ||
size: point3.optional(), | ||
}) | ||
|
||
expectTypesMatch<CadModelBase, z.input<typeof cadModelBase>>(true) | ||
|
||
export interface CadModelStl extends CadModelBase { | ||
stlUrl: string | ||
} | ||
export const cadModelStl = cadModelBase.extend({ | ||
stlUrl: z.string(), | ||
}) | ||
|
||
export interface CadModelObj extends CadModelBase { | ||
objUrl: string | ||
mtlUrl?: string | ||
} | ||
export const cadModelObj = cadModelBase.extend({ | ||
objUrl: z.string(), | ||
mtlUrl: z.string().optional(), | ||
}) | ||
|
||
export interface CadModelJscad extends CadModelBase { | ||
jscad: Record<string, any> | ||
} | ||
export const cadModelJscad = cadModelBase.extend({ | ||
jscad: z.any(), | ||
jscad: z.record(z.any()), | ||
}) | ||
|
||
export type CadModelProp = string | CadModelStl | CadModelObj | CadModelJscad | ||
|
||
export const cadModelProp = z.union([ | ||
z.string(), | ||
cadModelStl, | ||
cadModelObj, | ||
cadModelJscad, | ||
]) | ||
|
||
type InferredCadModelProp = z.input<typeof cadModelProp> | ||
expectTypesMatch<CadModelProp, InferredCadModelProp>(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { z } from "zod" | ||
import { distance } from "@tscircuit/soup" | ||
import { expectTypesMatch } from "lib/typecheck" | ||
|
||
export type SchematicPinStyle = Record< | ||
string, | ||
{ | ||
leftMargin?: number | string | ||
rightMargin?: number | string | ||
topMargin?: number | string | ||
bottomMargin?: number | string | ||
} | ||
> | ||
|
||
export const schematicPinStyle = z.record( | ||
z.object({ | ||
leftMargin: distance.optional(), | ||
rightMargin: distance.optional(), | ||
topMargin: distance.optional(), | ||
bottomMargin: distance.optional(), | ||
}), | ||
) | ||
|
||
expectTypesMatch<SchematicPinStyle, z.input<typeof schematicPinStyle>>(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { z } from "zod" | ||
import { capacitance } from "@tscircuit/soup" | ||
import { | ||
commonComponentProps, | ||
lrPins, | ||
lrPolarPins, | ||
type CommonComponentProps, | ||
} from "lib/common/layout" | ||
import { expectTypesMatch } from "lib/typecheck" | ||
|
||
export interface CapacitorProps extends CommonComponentProps { | ||
capacitance: number | string | ||
|
||
decouplingFor?: string | ||
decouplingTo?: string | ||
|
||
bypassFor?: string | ||
bypassTo?: string | ||
} | ||
|
||
export const capacitorProps = commonComponentProps.extend({ | ||
capacitance, | ||
|
||
decouplingFor: z.string().optional(), | ||
decouplingTo: z.string().optional(), | ||
|
||
bypassFor: z.string().optional(), | ||
bypassTo: z.string().optional(), | ||
}) | ||
export const capacitorPins = lrPolarPins | ||
|
||
expectTypesMatch<CapacitorProps, z.input<typeof capacitorProps>>(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { z } from "zod" | ||
import { | ||
commonComponentProps, | ||
type CommonComponentProps, | ||
} from "lib/common/layout" | ||
import { | ||
schematicPinStyle, | ||
type SchematicPinStyle, | ||
} from "lib/common/schematicPinStyle" | ||
import { distance } from "@tscircuit/soup" | ||
import { expectTypesMatch } from "lib/typecheck" | ||
|
||
export interface JumperProps extends CommonComponentProps { | ||
manufacturerPartNumber?: string | ||
pinLabels?: Record<number | string, string> | ||
schPinStyle?: SchematicPinStyle | ||
schPinSpacing?: number | string | ||
schWidth?: number | string | ||
schHeight?: number | string | ||
} | ||
|
||
export const jumperProps = commonComponentProps.extend({ | ||
manufacturerPartNumber: z.string().optional(), | ||
pinLabels: z.record(z.number().or(z.string()), z.string()).optional(), | ||
schPinStyle: schematicPinStyle.optional(), | ||
schPinSpacing: distance.optional(), | ||
schWidth: distance.optional(), | ||
schHeight: distance.optional(), | ||
}) | ||
|
||
type InferredJumperProps = z.input<typeof jumperProps> | ||
expectTypesMatch<JumperProps, InferredJumperProps>(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { z } from "zod" | ||
import { resistance } from "@tscircuit/soup" | ||
import { | ||
commonComponentProps, | ||
lrPins, | ||
type CommonComponentProps, | ||
} from "lib/common/layout" | ||
import { expectTypesMatch } from "lib/typecheck" | ||
|
||
export interface ResistorProps extends CommonComponentProps { | ||
resistance: number | string | ||
pullupFor?: string | ||
pullupTo?: string | ||
pulldownFor?: string | ||
pulldownTo?: string | ||
} | ||
|
||
export const resistorProps = commonComponentProps.extend({ | ||
resistance, | ||
|
||
pullupFor: z.string().optional(), | ||
pullupTo: z.string().optional(), | ||
|
||
pulldownFor: z.string().optional(), | ||
pulldownTo: z.string().optional(), | ||
}) | ||
export const resistorPins = lrPins | ||
|
||
type InferredResistorProps = z.input<typeof resistorProps> | ||
expectTypesMatch<ResistorProps, InferredResistorProps>(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export const expectTypesMatch = <T1, T2>( | ||
shouldBe: T1 extends T2 ? (T2 extends T1 ? true : false) : false, | ||
import type { TypeEqual } from "ts-expect" | ||
|
||
export const expectTypesMatch = <const T1, const T2>( | ||
shouldBe: TypeEqual<T1, T2>, | ||
): void => {} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters