From 5df49b586bc762a53402d208f3534657d5732fa6 Mon Sep 17 00:00:00 2001 From: "Marcel W. Wysocki" Date: Mon, 6 Jul 2026 14:32:23 +0800 Subject: [PATCH 1/2] fix(schema): accept string or number for szlcsc/lcsc id EasyEDA returns the szlcsc.id (and lcsc.id) field as a number for some parts and as a string for others (e.g. C356849). SzlcscSchema/LcscSchema hardcoded z.number(), so parsing crashed with 'szlcsc.id: Expected number, received string' and 'tsci import ' failed for every affected part. The field is unused downstream, so widen it to z.union([z.number(), z.string()]). Adds a no-network regression test. --- lib/schemas/easy-eda-json-schema.ts | 6 ++++-- tests/szlcsc-schema-id.test.ts | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/szlcsc-schema-id.test.ts diff --git a/lib/schemas/easy-eda-json-schema.ts b/lib/schemas/easy-eda-json-schema.ts index 5c516640..ad0d554c 100644 --- a/lib/schemas/easy-eda-json-schema.ts +++ b/lib/schemas/easy-eda-json-schema.ts @@ -11,7 +11,9 @@ export const maybeNumber = z .pipe(z.number().nullable().optional()) export const SzlcscSchema = z.object({ - id: z.number(), + // EasyEDA returns this id as a number for some parts and a string for others + // (e.g. C356849); the value is unused, so accept either to avoid import crashes. + id: z.union([z.number(), z.string()]), number: z.string(), step: z.number().optional(), min: z.number().optional(), @@ -22,7 +24,7 @@ export const SzlcscSchema = z.object({ }) export const LcscSchema = z.object({ - id: z.number(), + id: z.union([z.number(), z.string()]), number: z.string(), step: z.number().optional(), min: z.number().optional(), diff --git a/tests/szlcsc-schema-id.test.ts b/tests/szlcsc-schema-id.test.ts new file mode 100644 index 00000000..e3ffd810 --- /dev/null +++ b/tests/szlcsc-schema-id.test.ts @@ -0,0 +1,18 @@ +import { describe, expect, test } from "bun:test" +import { SzlcscSchema, LcscSchema } from "lib/schemas/easy-eda-json-schema" + +// EasyEDA returns the szlcsc/lcsc `id` as a number for some parts and a string +// for others (e.g. C356849), which used to crash `tsci import` on those parts. +describe("szlcsc/lcsc id accepts number or string", () => { + for (const [name, schema] of [ + ["SzlcscSchema", SzlcscSchema], + ["LcscSchema", LcscSchema], + ] as const) { + test(`${name} accepts a numeric id`, () => { + expect(schema.safeParse({ id: 2384679, number: "C356849" }).success).toBe(true) + }) + test(`${name} accepts a string id`, () => { + expect(schema.safeParse({ id: "2384679", number: "C356849" }).success).toBe(true) + }) + } +}) From 6101218a657273cef820a61170e46a0ad0571bf1 Mon Sep 17 00:00:00 2001 From: "Marcel W. Wysocki" Date: Tue, 7 Jul 2026 17:10:52 +0800 Subject: [PATCH 2/2] chore: biome format --- tests/szlcsc-schema-id.test.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/szlcsc-schema-id.test.ts b/tests/szlcsc-schema-id.test.ts index e3ffd810..ac0fee45 100644 --- a/tests/szlcsc-schema-id.test.ts +++ b/tests/szlcsc-schema-id.test.ts @@ -9,10 +9,14 @@ describe("szlcsc/lcsc id accepts number or string", () => { ["LcscSchema", LcscSchema], ] as const) { test(`${name} accepts a numeric id`, () => { - expect(schema.safeParse({ id: 2384679, number: "C356849" }).success).toBe(true) + expect(schema.safeParse({ id: 2384679, number: "C356849" }).success).toBe( + true, + ) }) test(`${name} accepts a string id`, () => { - expect(schema.safeParse({ id: "2384679", number: "C356849" }).success).toBe(true) + expect( + schema.safeParse({ id: "2384679", number: "C356849" }).success, + ).toBe(true) }) } })