diff --git a/generated/COMPONENT_TYPES.md b/generated/COMPONENT_TYPES.md index a792aa4b..73473428 100644 --- a/generated/COMPONENT_TYPES.md +++ b/generated/COMPONENT_TYPES.md @@ -98,7 +98,7 @@ export const cadModelJscad = cadModelBase.extend({ }) export const cadModelProp = z.union([ z.null(), - url, + z.string().min(1), z.custom((v) => { return v && typeof v === "object" && "type" in v && "props" in v }), diff --git a/lib/common/cadModel.ts b/lib/common/cadModel.ts index 2a3e7207..6bedd841 100644 --- a/lib/common/cadModel.ts +++ b/lib/common/cadModel.ts @@ -113,10 +113,18 @@ export const cadModelJscad = cadModelBase.extend({ jscad: z.record(z.any()), }) +/** + * A Footprinter string used to procedurally generate the component's CAD model, + * independently of the component's PCB footprint. + * + * @example "soic8" + */ +export type CadModelFootprinterString = string + export type CadModelProp = | null - | string | ReactElement + | CadModelFootprinterString | CadModelStl | CadModelObj | CadModelGltf @@ -127,7 +135,7 @@ export type CadModelProp = export const cadModelProp = z.union([ z.null(), - url, + z.string().min(1), z.custom((v) => { return v && typeof v === "object" && "type" in v && "props" in v }), diff --git a/tests/cad-model-prop.test.ts b/tests/cad-model-prop.test.ts new file mode 100644 index 00000000..d32f3fe9 --- /dev/null +++ b/tests/cad-model-prop.test.ts @@ -0,0 +1,15 @@ +import { expect, test } from "bun:test" +import { cadModelProp } from "../lib/common/cadModel" +import { chipProps } from "../lib/components/chip" + +test("cadModel accepts a Footprinter string as the procedural model", () => { + expect(cadModelProp.parse("soic8")).toBe("soic8") + expect(() => cadModelProp.parse("")).toThrow() + + const parsedChip = chipProps.parse({ + name: "U1", + cadModel: "soic8", + }) + + expect(parsedChip.cadModel).toBe("soic8") +})