@tscircuit/parts-engine 0.0.26 → 0.0.27
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/README.md +8 -0
- package/dist/index.d.ts +36 -1
- package/dist/index.js +186 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
digikeyPartsEngine,
|
|
10
10
|
jlcPartsEngine,
|
|
11
11
|
DigiKeyPartsEngine,
|
|
12
|
+
mouserPartsEngine,
|
|
13
|
+
MouserPartsEngine,
|
|
12
14
|
} from "@tscircuit/parts-engine"
|
|
13
15
|
```
|
|
14
16
|
|
|
@@ -17,3 +19,9 @@ import {
|
|
|
17
19
|
shape as jlcsearch while caching DigiKey Product Information V4 calls. Use
|
|
18
20
|
`new DigiKeyPartsEngine({ platformFetch, apiBaseUrl })` to inject a platform
|
|
19
21
|
fetch implementation or a test/self-hosted endpoint.
|
|
22
|
+
|
|
23
|
+
`mouserPartsEngine.findPart(...)` queries
|
|
24
|
+
`https://mousersearch.tscircuit.com`, which exposes the same category route
|
|
25
|
+
shape while caching Mouser Search API calls. Use
|
|
26
|
+
`new MouserPartsEngine({ platformFetch, apiBaseUrl })` to inject a platform
|
|
27
|
+
fetch implementation or a test/self-hosted endpoint.
|
package/dist/index.d.ts
CHANGED
|
@@ -4409,4 +4409,39 @@ declare const withDigiKeyStockPreference: (parts: DigiKeySearchPart[] | undefine
|
|
|
4409
4409
|
|
|
4410
4410
|
declare const digikeyPartsEngine: DigiKeyPartsEngine;
|
|
4411
4411
|
|
|
4412
|
-
|
|
4412
|
+
type MouserPartsEngineOptions = {
|
|
4413
|
+
platformFetch?: PlatformFetch;
|
|
4414
|
+
apiBaseUrl?: string;
|
|
4415
|
+
};
|
|
4416
|
+
type MouserSearchPart = {
|
|
4417
|
+
mouser_product_number: string;
|
|
4418
|
+
supplier_part_number?: string;
|
|
4419
|
+
mfr: string;
|
|
4420
|
+
manufacturer?: string;
|
|
4421
|
+
package?: string;
|
|
4422
|
+
description?: string;
|
|
4423
|
+
stock: number;
|
|
4424
|
+
price?: number;
|
|
4425
|
+
normally_stocking?: boolean;
|
|
4426
|
+
};
|
|
4427
|
+
|
|
4428
|
+
declare class MouserPartsEngine implements PartsEngine {
|
|
4429
|
+
private readonly platformFetch;
|
|
4430
|
+
private readonly apiBaseUrl;
|
|
4431
|
+
constructor(options?: MouserPartsEngineOptions);
|
|
4432
|
+
private getCategoryParts;
|
|
4433
|
+
private getKeywordParts;
|
|
4434
|
+
private toSupplierPartNumbers;
|
|
4435
|
+
findPart({ sourceComponent, footprinterString, }: Parameters<PartsEngine["findPart"]>[0]): Promise<{}>;
|
|
4436
|
+
}
|
|
4437
|
+
|
|
4438
|
+
declare const mouserCache: Map<string, unknown>;
|
|
4439
|
+
declare const getMouserPartsCached: (path: string, params: Record<string, string | number | boolean | undefined>, options?: {
|
|
4440
|
+
platformFetch?: PlatformFetch;
|
|
4441
|
+
apiBaseUrl?: string;
|
|
4442
|
+
}) => Promise<Record<string, MouserSearchPart[]>>;
|
|
4443
|
+
declare const withMouserStockPreference: (parts: MouserSearchPart[] | undefined) => MouserSearchPart[];
|
|
4444
|
+
|
|
4445
|
+
declare const mouserPartsEngine: MouserPartsEngine;
|
|
4446
|
+
|
|
4447
|
+
export { DigiKeyPartsEngine, type DigiKeyPartsEngineOptions, type DigiKeySearchPart, type EasyEdaProxyConfig, type FetchPartCircuitJsonParams, JlcPcbPartsEngine, type JlcPcbPartsEngineOptions, MouserPartsEngine, type MouserPartsEngineOptions, type MouserSearchPart, type PlatformFetch, cache, digikeyCache, digikeyPartsEngine, getDigiKeyPartsCached, getFetchWithEasyEdaProxy, getMouserPartsCached, jlcPartsEngine, mouserCache, mouserPartsEngine, withDigiKeyStockPreference, withMouserStockPreference };
|
package/dist/index.js
CHANGED
|
@@ -11725,15 +11725,200 @@ var DigiKeyPartsEngine = class {
|
|
|
11725
11725
|
|
|
11726
11726
|
// lib/digikey-parts-engine/index.ts
|
|
11727
11727
|
var digikeyPartsEngine = new DigiKeyPartsEngine();
|
|
11728
|
+
|
|
11729
|
+
// lib/mouser-parts-engine/mouser-parts-cache.ts
|
|
11730
|
+
var mouserCache = /* @__PURE__ */ new Map();
|
|
11731
|
+
var normalizeBaseUrl2 = (baseUrl) => baseUrl.replace(/\/$/, "");
|
|
11732
|
+
var getMouserPartsCached = async (path, params, options = {}) => {
|
|
11733
|
+
const platformFetch = options.platformFetch ?? globalThis.fetch;
|
|
11734
|
+
const baseUrl = normalizeBaseUrl2(
|
|
11735
|
+
options.apiBaseUrl ?? "https://mousersearch.tscircuit.com"
|
|
11736
|
+
);
|
|
11737
|
+
const url = new URL(path, `${baseUrl}/`);
|
|
11738
|
+
for (const [name, value] of Object.entries(params)) {
|
|
11739
|
+
if (value !== void 0 && value !== "") {
|
|
11740
|
+
url.searchParams.set(name, String(value));
|
|
11741
|
+
}
|
|
11742
|
+
}
|
|
11743
|
+
url.searchParams.set("json", "true");
|
|
11744
|
+
const cacheKey = url.toString();
|
|
11745
|
+
const cached = mouserCache.get(cacheKey);
|
|
11746
|
+
if (cached) return cached;
|
|
11747
|
+
const response = await platformFetch(url);
|
|
11748
|
+
if (!response.ok) {
|
|
11749
|
+
throw new Error(
|
|
11750
|
+
`Mouser search failed (${response.status}): ${await response.text()}`
|
|
11751
|
+
);
|
|
11752
|
+
}
|
|
11753
|
+
const responseJson = await response.json();
|
|
11754
|
+
mouserCache.set(cacheKey, responseJson);
|
|
11755
|
+
return responseJson;
|
|
11756
|
+
};
|
|
11757
|
+
var withMouserStockPreference = (parts) => [...parts ?? []].sort(
|
|
11758
|
+
(a, b) => Number(b.normally_stocking ?? false) - Number(a.normally_stocking ?? false) || (b.stock ?? 0) - (a.stock ?? 0)
|
|
11759
|
+
);
|
|
11760
|
+
|
|
11761
|
+
// lib/mouser-parts-engine/MouserPartsEngine.ts
|
|
11762
|
+
var MouserPartsEngine = class {
|
|
11763
|
+
platformFetch;
|
|
11764
|
+
apiBaseUrl;
|
|
11765
|
+
constructor(options = {}) {
|
|
11766
|
+
this.platformFetch = options.platformFetch;
|
|
11767
|
+
this.apiBaseUrl = options.apiBaseUrl;
|
|
11768
|
+
this.findPart = this.findPart.bind(this);
|
|
11769
|
+
}
|
|
11770
|
+
async getCategoryParts(path, responseKey, params) {
|
|
11771
|
+
const response = await getMouserPartsCached(path, params, {
|
|
11772
|
+
platformFetch: this.platformFetch,
|
|
11773
|
+
apiBaseUrl: this.apiBaseUrl
|
|
11774
|
+
});
|
|
11775
|
+
return response[responseKey] ?? [];
|
|
11776
|
+
}
|
|
11777
|
+
async getKeywordParts(query) {
|
|
11778
|
+
const response = await getMouserPartsCached(
|
|
11779
|
+
"/api/search",
|
|
11780
|
+
{ q: query, limit: 20 },
|
|
11781
|
+
{
|
|
11782
|
+
platformFetch: this.platformFetch,
|
|
11783
|
+
apiBaseUrl: this.apiBaseUrl
|
|
11784
|
+
}
|
|
11785
|
+
);
|
|
11786
|
+
return response.components ?? [];
|
|
11787
|
+
}
|
|
11788
|
+
toSupplierPartNumbers(parts) {
|
|
11789
|
+
return {
|
|
11790
|
+
mouser: withMouserStockPreference(parts).map((part) => part.mouser_product_number).filter(Boolean).slice(0, 3)
|
|
11791
|
+
};
|
|
11792
|
+
}
|
|
11793
|
+
async findPart({
|
|
11794
|
+
sourceComponent,
|
|
11795
|
+
footprinterString
|
|
11796
|
+
}) {
|
|
11797
|
+
if (sourceComponent.type !== "source_component") return {};
|
|
11798
|
+
const packageName = getJlcpcbPackageName(footprinterString);
|
|
11799
|
+
if (sourceComponent.ftype === "simple_resistor") {
|
|
11800
|
+
return this.toSupplierPartNumbers(
|
|
11801
|
+
await this.getCategoryParts("/resistors/list", "resistors", {
|
|
11802
|
+
resistance: sourceComponent.resistance,
|
|
11803
|
+
package: packageName
|
|
11804
|
+
})
|
|
11805
|
+
);
|
|
11806
|
+
}
|
|
11807
|
+
if (sourceComponent.ftype === "simple_capacitor") {
|
|
11808
|
+
return this.toSupplierPartNumbers(
|
|
11809
|
+
await this.getCategoryParts("/capacitors/list", "capacitors", {
|
|
11810
|
+
capacitance: sourceComponent.capacitance,
|
|
11811
|
+
package: packageName
|
|
11812
|
+
})
|
|
11813
|
+
);
|
|
11814
|
+
}
|
|
11815
|
+
if (sourceComponent.ftype === "simple_pin_header") {
|
|
11816
|
+
return this.toSupplierPartNumbers(
|
|
11817
|
+
await this.getCategoryParts(
|
|
11818
|
+
"/headers/list",
|
|
11819
|
+
"headers",
|
|
11820
|
+
getPinHeaderSearchParams(sourceComponent, footprinterString)
|
|
11821
|
+
)
|
|
11822
|
+
);
|
|
11823
|
+
}
|
|
11824
|
+
if (sourceComponent.ftype === "simple_potentiometer") {
|
|
11825
|
+
return this.toSupplierPartNumbers(
|
|
11826
|
+
await this.getCategoryParts("/potentiometers/list", "potentiometers", {
|
|
11827
|
+
resistance: sourceComponent.max_resistance,
|
|
11828
|
+
package: packageName
|
|
11829
|
+
})
|
|
11830
|
+
);
|
|
11831
|
+
}
|
|
11832
|
+
if (sourceComponent.ftype === "simple_diode") {
|
|
11833
|
+
return this.toSupplierPartNumbers(
|
|
11834
|
+
await this.getCategoryParts("/diodes/list", "diodes", {
|
|
11835
|
+
package: packageName
|
|
11836
|
+
})
|
|
11837
|
+
);
|
|
11838
|
+
}
|
|
11839
|
+
if (sourceComponent.ftype === "simple_transistor") {
|
|
11840
|
+
return this.toSupplierPartNumbers(
|
|
11841
|
+
await this.getCategoryParts(
|
|
11842
|
+
"/bjt_transistors/list",
|
|
11843
|
+
"bjt_transistors",
|
|
11844
|
+
{ package: packageName }
|
|
11845
|
+
)
|
|
11846
|
+
);
|
|
11847
|
+
}
|
|
11848
|
+
if (sourceComponent.ftype === "simple_mosfet") {
|
|
11849
|
+
return this.toSupplierPartNumbers(
|
|
11850
|
+
await this.getCategoryParts("/mosfets/list", "mosfets", {
|
|
11851
|
+
package: packageName,
|
|
11852
|
+
channel_type: sourceComponent.channel_type,
|
|
11853
|
+
mosfet_mode: sourceComponent.mosfet_mode
|
|
11854
|
+
})
|
|
11855
|
+
);
|
|
11856
|
+
}
|
|
11857
|
+
if (sourceComponent.ftype === "simple_switch") {
|
|
11858
|
+
return this.toSupplierPartNumbers(
|
|
11859
|
+
await this.getCategoryParts("/switches/list", "switches", {
|
|
11860
|
+
package: packageName
|
|
11861
|
+
})
|
|
11862
|
+
);
|
|
11863
|
+
}
|
|
11864
|
+
if (sourceComponent.ftype === "simple_led") {
|
|
11865
|
+
return this.toSupplierPartNumbers(
|
|
11866
|
+
await this.getCategoryParts("/leds/list", "leds", {
|
|
11867
|
+
package: packageName
|
|
11868
|
+
})
|
|
11869
|
+
);
|
|
11870
|
+
}
|
|
11871
|
+
if (sourceComponent.ftype === "simple_fuse") {
|
|
11872
|
+
return this.toSupplierPartNumbers(
|
|
11873
|
+
await this.getCategoryParts("/fuses/list", "fuses", {
|
|
11874
|
+
package: packageName
|
|
11875
|
+
})
|
|
11876
|
+
);
|
|
11877
|
+
}
|
|
11878
|
+
if (sourceComponent.ftype === "simple_connector" && sourceComponent.standard === "usb_c") {
|
|
11879
|
+
return this.toSupplierPartNumbers(
|
|
11880
|
+
await this.getCategoryParts(
|
|
11881
|
+
"/usb_c_connectors/list",
|
|
11882
|
+
"usb_c_connectors",
|
|
11883
|
+
{ package: packageName }
|
|
11884
|
+
)
|
|
11885
|
+
);
|
|
11886
|
+
}
|
|
11887
|
+
const keywordByFtype = {
|
|
11888
|
+
simple_chip: "integrated circuit",
|
|
11889
|
+
simple_power_source: "power supply",
|
|
11890
|
+
simple_inductor: "inductor",
|
|
11891
|
+
simple_crystal: "crystal",
|
|
11892
|
+
simple_resonator: "resonator"
|
|
11893
|
+
};
|
|
11894
|
+
const keyword = keywordByFtype[sourceComponent.ftype];
|
|
11895
|
+
if (keyword) {
|
|
11896
|
+
return this.toSupplierPartNumbers(
|
|
11897
|
+
await this.getKeywordParts(
|
|
11898
|
+
[keyword, packageName].filter(Boolean).join(" ")
|
|
11899
|
+
)
|
|
11900
|
+
);
|
|
11901
|
+
}
|
|
11902
|
+
return {};
|
|
11903
|
+
}
|
|
11904
|
+
};
|
|
11905
|
+
|
|
11906
|
+
// lib/mouser-parts-engine/index.ts
|
|
11907
|
+
var mouserPartsEngine = new MouserPartsEngine();
|
|
11728
11908
|
export {
|
|
11729
11909
|
DigiKeyPartsEngine,
|
|
11730
11910
|
JlcPcbPartsEngine,
|
|
11911
|
+
MouserPartsEngine,
|
|
11731
11912
|
cache,
|
|
11732
11913
|
digikeyCache,
|
|
11733
11914
|
digikeyPartsEngine,
|
|
11734
11915
|
getDigiKeyPartsCached,
|
|
11735
11916
|
getFetchWithEasyEdaProxy,
|
|
11917
|
+
getMouserPartsCached,
|
|
11736
11918
|
jlcPartsEngine,
|
|
11737
|
-
|
|
11919
|
+
mouserCache,
|
|
11920
|
+
mouserPartsEngine,
|
|
11921
|
+
withDigiKeyStockPreference,
|
|
11922
|
+
withMouserStockPreference
|
|
11738
11923
|
};
|
|
11739
11924
|
//# sourceMappingURL=index.js.map
|