@tscircuit/parts-engine 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bun.lock CHANGED
@@ -5,9 +5,9 @@
5
5
  "name": "@tscircuit/parts-engine",
6
6
  "devDependencies": {
7
7
  "@biomejs/biome": "^1.9.4",
8
- "@tscircuit/props": "^0.0.227",
8
+ "@tscircuit/props": "^0.0.238",
9
9
  "@types/bun": "latest",
10
- "circuit-json": "^0.0.209",
10
+ "circuit-json": "^0.0.213",
11
11
  "tsup": "^8.4.0",
12
12
  },
13
13
  "peerDependencies": {
@@ -142,7 +142,7 @@
142
142
 
143
143
  "@tscircuit/manual-edit-events": ["@tscircuit/manual-edit-events@0.0.6", "", { "dependencies": { "zod": "^3.23.8" } }, "sha512-PLgy+/Dsw1YcnNVNqfieNGTNIaRKRJ70Jt2LcSMljwaBOtsiOwtdzj24xCYO9XzJUZc7opKytShMlx863PehTQ=="],
144
144
 
145
- "@tscircuit/props": ["@tscircuit/props@0.0.227", "", { "peerDependencies": { "@tscircuit/layout": "*", "circuit-json": "*", "react": "*", "zod": "*" } }, "sha512-vJMZ2vHPX3nhfYCwCoijp/r+w1SLM3zocVSdofr6VQpV4Ct8JrLJUJ+h3AhKPttD8kunZ66jbWMlC9wA+U7iNQ=="],
145
+ "@tscircuit/props": ["@tscircuit/props@0.0.238", "", { "peerDependencies": { "@tscircuit/layout": "*", "circuit-json": "*", "react": "*", "zod": "*" } }, "sha512-Mq9CScwlc/zd6wgTWGBKTN2x/qarImr1Um3dt0a/WY76pPIRdjnsznN+7IZVmNxY3H/RD6CbCNjgc0DKphWYIg=="],
146
146
 
147
147
  "@tscircuit/schematic-autolayout": ["@tscircuit/schematic-autolayout@0.0.6", "", { "dependencies": { "@tscircuit/soup-util": "^0.0.38", "transformation-matrix": "^2.16.1" } }, "sha512-34cQxtlSylBKyHkzaMBCynaWJgN9c/mWm7cz63StTYIafKmfFs383K8Xoc4QX8HXCvVrHYl1aK15onZua9MxeA=="],
148
148
 
@@ -172,7 +172,7 @@
172
172
 
173
173
  "chokidar": ["chokidar@4.0.3", "", { "dependencies": { "readdirp": "^4.0.1" } }, "sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA=="],
174
174
 
175
- "circuit-json": ["circuit-json@0.0.209", "", { "dependencies": { "nanoid": "^5.0.7", "zod": "^3.25.64" } }, "sha512-cu/LQQS7XPGgAfDvwbusQqJbPyMdYRkKN4jMvi837TuCSXa0Xt7cBvSqkQekyipXuAtqnLJiaAucFVHpMUNyWA=="],
175
+ "circuit-json": ["circuit-json@0.0.213", "", { "dependencies": { "nanoid": "^5.0.7", "zod": "*" } }, "sha512-WgKoSYyvhI+anWo1EzTBEgNQSyh68zgpW+7X3SPmpQwIkybB01j23uKp+SQPZ0U6iHRE5p84TuixWN0K6vApPQ=="],
176
176
 
177
177
  "color-convert": ["color-convert@2.0.1", "", { "dependencies": { "color-name": "~1.1.4" } }, "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ=="],
178
178
 
package/index.ts CHANGED
@@ -1 +1 @@
1
- export * from "./lib/jlc-parts-engine"
1
+ export * from "./lib/jlc-parts-engine"
@@ -33,7 +33,7 @@ export const jlcPartsEngine: PartsEngine = {
33
33
  })
34
34
 
35
35
  return {
36
- jlcpcb: resistors.map((r: any) => `C${r.lcsc}`).slice(0, 3),
36
+ jlcpcb: (resistors ?? []).map((r: any) => `C${r.lcsc}`).slice(0, 3),
37
37
  }
38
38
  } else if (
39
39
  sourceComponent.type === "source_component" &&
@@ -48,7 +48,7 @@ export const jlcPartsEngine: PartsEngine = {
48
48
  })
49
49
 
50
50
  return {
51
- jlcpcb: capacitors.map((c: any) => `C${c.lcsc}`).slice(0, 3),
51
+ jlcpcb: (capacitors ?? []).map((c: any) => `C${c.lcsc}`).slice(0, 3),
52
52
  }
53
53
  } else if (
54
54
  sourceComponent.type === "source_component" &&
@@ -72,7 +72,7 @@ export const jlcPartsEngine: PartsEngine = {
72
72
  },
73
73
  )
74
74
  return {
75
- jlcpcb: headers.map((h: any) => `C${h.lcsc}`).slice(0, 3),
75
+ jlcpcb: (headers ?? []).map((h: any) => `C${h.lcsc}`).slice(0, 3),
76
76
  }
77
77
  } else if (
78
78
  sourceComponent.type === "source_component" &&
@@ -83,7 +83,9 @@ export const jlcPartsEngine: PartsEngine = {
83
83
  package: footprinterString,
84
84
  })
85
85
  return {
86
- jlcpcb: potentiometers.map((p: any) => `C${p.lcsc}`).slice(0, 3),
86
+ jlcpcb: (potentiometers ?? [])
87
+ .map((p: any) => `C${p.lcsc}`)
88
+ .slice(0, 3),
87
89
  }
88
90
  } else if (
89
91
  sourceComponent.type === "source_component" &&
@@ -93,7 +95,7 @@ export const jlcPartsEngine: PartsEngine = {
93
95
  package: footprinterString,
94
96
  })
95
97
  return {
96
- jlcpcb: diodes.map((d: any) => `C${d.lcsc}`).slice(0, 3),
98
+ jlcpcb: (diodes ?? []).map((d: any) => `C${d.lcsc}`).slice(0, 3),
97
99
  }
98
100
  } else if (
99
101
  sourceComponent.type === "source_component" &&
@@ -103,7 +105,7 @@ export const jlcPartsEngine: PartsEngine = {
103
105
  package: footprinterString,
104
106
  })
105
107
  return {
106
- jlcpcb: chips.map((c: any) => `C${c.lcsc}`).slice(0, 3),
108
+ jlcpcb: (chips ?? []).map((c: any) => `C${c.lcsc}`).slice(0, 3),
107
109
  }
108
110
  } else if (
109
111
  sourceComponent.type === "source_component" &&
@@ -114,7 +116,7 @@ export const jlcPartsEngine: PartsEngine = {
114
116
  transistor_type: sourceComponent.transistor_type,
115
117
  })
116
118
  return {
117
- jlcpcb: transistors.map((t: any) => `C${t.lcsc}`).slice(0, 3),
119
+ jlcpcb: (transistors ?? []).map((t: any) => `C${t.lcsc}`).slice(0, 3),
118
120
  }
119
121
  } else if (
120
122
  sourceComponent.type === "source_component" &&
@@ -125,7 +127,7 @@ export const jlcPartsEngine: PartsEngine = {
125
127
  package: footprinterString,
126
128
  })
127
129
  return {
128
- jlcpcb: power_sources.map((p: any) => `C${p.lcsc}`).slice(0, 3),
130
+ jlcpcb: (power_sources ?? []).map((p: any) => `C${p.lcsc}`).slice(0, 3),
129
131
  }
130
132
  } else if (
131
133
  sourceComponent.type === "source_component" &&
@@ -136,7 +138,7 @@ export const jlcPartsEngine: PartsEngine = {
136
138
  package: footprinterString,
137
139
  })
138
140
  return {
139
- jlcpcb: inductors.map((i: any) => `C${i.lcsc}`).slice(0, 3),
141
+ jlcpcb: (inductors ?? []).map((i: any) => `C${i.lcsc}`).slice(0, 3),
140
142
  }
141
143
  } else if (
142
144
  sourceComponent.type === "source_component" &&
@@ -148,7 +150,7 @@ export const jlcPartsEngine: PartsEngine = {
148
150
  package: footprinterString,
149
151
  })
150
152
  return {
151
- jlcpcb: crystals.map((c: any) => `C${c.lcsc}`).slice(0, 3),
153
+ jlcpcb: (crystals ?? []).map((c: any) => `C${c.lcsc}`).slice(0, 3),
152
154
  }
153
155
  } else if (
154
156
  sourceComponent.type === "source_component" &&
@@ -160,7 +162,7 @@ export const jlcPartsEngine: PartsEngine = {
160
162
  channel_type: sourceComponent.channel_type,
161
163
  })
162
164
  return {
163
- jlcpcb: mosfets.map((m: any) => `C${m.lcsc}`).slice(0, 3),
165
+ jlcpcb: (mosfets ?? []).map((m: any) => `C${m.lcsc}`).slice(0, 3),
164
166
  }
165
167
  } else if (
166
168
  sourceComponent.type === "source_component" &&
@@ -171,7 +173,7 @@ export const jlcPartsEngine: PartsEngine = {
171
173
  package: footprinterString,
172
174
  })
173
175
  return {
174
- jlcpcb: resonators.map((r: any) => `C${r.lcsc}`).slice(0, 3),
176
+ jlcpcb: (resonators ?? []).map((r: any) => `C${r.lcsc}`).slice(0, 3),
175
177
  }
176
178
  } else if (
177
179
  sourceComponent.type === "source_component" &&
@@ -182,10 +184,9 @@ export const jlcPartsEngine: PartsEngine = {
182
184
  package: footprinterString,
183
185
  })
184
186
  return {
185
- jlcpcb: switches.map((s: any) => `C${s.lcsc}`).slice(0, 3),
187
+ jlcpcb: (switches ?? []).map((s: any) => `C${s.lcsc}`).slice(0, 3),
186
188
  }
187
- }
188
- else if (
189
+ } else if (
189
190
  sourceComponent.type === "source_component" &&
190
191
  sourceComponent.ftype === "simple_led"
191
192
  ) {
@@ -193,7 +194,17 @@ export const jlcPartsEngine: PartsEngine = {
193
194
  package: footprinterString,
194
195
  })
195
196
  return {
196
- jlcpcb: leds.map((l: any) => `C${l.lcsc}`).slice(0, 3),
197
+ jlcpcb: (leds ?? []).map((l: any) => `C${l.lcsc}`).slice(0, 3),
198
+ }
199
+ } else if (
200
+ sourceComponent.type === "source_component" &&
201
+ sourceComponent.ftype === "simple_fuse"
202
+ ) {
203
+ const { fuses } = await getJlcPartsCached("fuses", {
204
+ package: footprinterString,
205
+ })
206
+ return {
207
+ jlcpcb: fuses.map((l: any) => `C${l.lcsc}`).slice(0, 3),
197
208
  }
198
209
  }
199
210
  return {}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@tscircuit/parts-engine",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "devDependencies": {
7
7
  "@biomejs/biome": "^1.9.4",
8
- "@tscircuit/props": "^0.0.227",
8
+ "@tscircuit/props": "^0.0.238",
9
9
  "@types/bun": "latest",
10
- "circuit-json": "^0.0.209",
10
+ "circuit-json": "^0.0.213",
11
11
  "tsup": "^8.4.0"
12
12
  },
13
13
  "scripts": {
@@ -22,7 +22,11 @@ describe("jlcPartsEngine", () => {
22
22
  if (url.includes("/potentiometers/")) {
23
23
  return {
24
24
  json: async () => ({
25
- potentiometers: [{ lcsc: "1234" }, { lcsc: "5678" }, { lcsc: "9012" }],
25
+ potentiometers: [
26
+ { lcsc: "1234" },
27
+ { lcsc: "5678" },
28
+ { lcsc: "9012" },
29
+ ],
26
30
  }),
27
31
  } as Response
28
32
  }
@@ -57,7 +61,11 @@ describe("jlcPartsEngine", () => {
57
61
  if (url.includes("/power_sources/")) {
58
62
  return {
59
63
  json: async () => ({
60
- power_sources: [{ lcsc: "7890" }, { lcsc: "1234" }, { lcsc: "5678" }],
64
+ power_sources: [
65
+ { lcsc: "7890" },
66
+ { lcsc: "1234" },
67
+ { lcsc: "5678" },
68
+ ],
61
69
  }),
62
70
  } as Response
63
71
  }
@@ -365,4 +373,25 @@ describe("jlcPartsEngine", () => {
365
373
 
366
374
  expect(result).toEqual({})
367
375
  })
376
+
377
+ test("should handle missing API data", async () => {
378
+ globalThis.fetch = (async () => ({
379
+ json: async () => ({}),
380
+ })) as unknown as typeof fetch
381
+
382
+ const resistor: AnySourceComponent = {
383
+ type: "source_component",
384
+ ftype: "simple_resistor",
385
+ resistance: 1000,
386
+ source_component_id: "source_component_0",
387
+ name: "R2",
388
+ }
389
+
390
+ const result = await jlcPartsEngine.findPart({
391
+ sourceComponent: resistor,
392
+ footprinterString: "0603",
393
+ })
394
+
395
+ expect(result).toEqual({ jlcpcb: [] })
396
+ })
368
397
  })