@tscircuit/core 0.0.423 → 0.0.424

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/dist/index.d.ts CHANGED
@@ -1002,6 +1002,8 @@ declare class NormalComponent<ZodProps extends ZodType = any, PortNames extends
1002
1002
  _getSchematicBoxDimensions(): SchematicBoxDimensions | null;
1003
1003
  doInitialCadModelRender(): void;
1004
1004
  private _addCachebustToModelUrl;
1005
+ private _getPartsEngineCacheKey;
1006
+ private _getSupplierPartNumbers;
1005
1007
  doInitialPartsEngineRender(): void;
1006
1008
  updatePartsEngineRender(): void;
1007
1009
  doInitialCreateTracesFromProps(): void;
@@ -12290,6 +12292,12 @@ type ChipFnSel = <T extends ChipFn<any> | string>(chipFn?: T) => UnionToIntersec
12290
12292
  type Sel = ExplicitModuleSel & SelWithoutSubcircuit;
12291
12293
  declare const sel: Sel;
12292
12294
 
12295
+ interface LocalCacheEngine {
12296
+ getItem(key: string): string | Promise<string | null> | null;
12297
+ setItem(key: string, value: string): void | Promise<void>;
12298
+ removeItem?(key: string): void | Promise<void>;
12299
+ }
12300
+
12293
12301
  type AutorouterCompleteEvent = {
12294
12302
  type: "complete";
12295
12303
  traces: SimplifiedPcbTrace[];
@@ -12396,4 +12404,4 @@ declare module "react/jsx-runtime" {
12396
12404
  }
12397
12405
  }
12398
12406
 
12399
- export { type AsyncEffect, type AutorouterCompleteEvent, type AutorouterErrorEvent, type AutorouterEvent, type AutorouterProgressEvent, type AutoroutingEndEvent, type AutoroutingErrorEvent, type AutoroutingProgressEvent, type AutoroutingStartEvent, Battery, Board, Capacitor, Chip, Circuit, type ComponentWithPins, Constraint, Crystal, Cutout, Diode, FabricationNotePath, FabricationNoteText, Footprint, type GenericConnectionsAndSelectorsSel, type GenericLocalAutorouter, Group, Hole, type IRenderable, Inductor, Jumper, Keepout, Led, Mosfet, Net, NetAlias, NormalComponent, type Obstacle, PcbTrace, PinHeader, type PinLabelSpec, PlatedHole, Port, Potentiometer, PowerSource, PrimitiveComponent, Project, PushButton, type RenderPhase, type RenderPhaseFn, type RenderPhaseFunctions, type RenderPhaseStates, Renderable, Resistor, Resonator, RootCircuit, type RootCircuitEventName, SchematicText, type Sel, SilkscreenCircle, SilkscreenLine, SilkscreenPath, SilkscreenRect, SilkscreenText, type SimpleRouteConnection, type SimpleRouteJson, type SimplifiedPcbTrace, SmtPad, Subcircuit, Switch, Trace, TraceHint, Transistor, Via, applyEditEvents, applyEditEventsToManualEditsFile, applyPcbEditEventsToManualEditsFile, applySchematicEditEventsToManualEditsFile, createUseComponent, getPhaseTimingsFromRenderEvents, getSimpleRouteJsonFromCircuitJson, orderedRenderPhases, sel, useCapacitor, useChip, useDiode, useLed, useRenderedCircuit, useResistor };
12407
+ export { type AsyncEffect, type AutorouterCompleteEvent, type AutorouterErrorEvent, type AutorouterEvent, type AutorouterProgressEvent, type AutoroutingEndEvent, type AutoroutingErrorEvent, type AutoroutingProgressEvent, type AutoroutingStartEvent, Battery, Board, Capacitor, Chip, Circuit, type ComponentWithPins, Constraint, Crystal, Cutout, Diode, FabricationNotePath, FabricationNoteText, Footprint, type GenericConnectionsAndSelectorsSel, type GenericLocalAutorouter, Group, Hole, type IRenderable, Inductor, Jumper, Keepout, Led, type LocalCacheEngine, Mosfet, Net, NetAlias, NormalComponent, type Obstacle, PcbTrace, PinHeader, type PinLabelSpec, PlatedHole, Port, Potentiometer, PowerSource, PrimitiveComponent, Project, PushButton, type RenderPhase, type RenderPhaseFn, type RenderPhaseFunctions, type RenderPhaseStates, Renderable, Resistor, Resonator, RootCircuit, type RootCircuitEventName, SchematicText, type Sel, SilkscreenCircle, SilkscreenLine, SilkscreenPath, SilkscreenRect, SilkscreenText, type SimpleRouteConnection, type SimpleRouteJson, type SimplifiedPcbTrace, SmtPad, Subcircuit, Switch, Trace, TraceHint, Transistor, Via, applyEditEvents, applyEditEventsToManualEditsFile, applyPcbEditEventsToManualEditsFile, applySchematicEditEventsToManualEditsFile, createUseComponent, getPhaseTimingsFromRenderEvents, getSimpleRouteJsonFromCircuitJson, orderedRenderPhases, sel, useCapacitor, useChip, useDiode, useLed, useRenderedCircuit, useResistor };
package/dist/index.js CHANGED
@@ -5707,6 +5707,43 @@ var NormalComponent = class extends PrimitiveComponent2 {
5707
5707
  const origin = this.root?.getClientOrigin() ?? "";
5708
5708
  return `${url}${url.includes("?") ? "&" : "?"}cachebust_origin=${encodeURIComponent(origin)}`;
5709
5709
  }
5710
+ _getPartsEngineCacheKey(source_component, footprinterString) {
5711
+ return JSON.stringify({
5712
+ ftype: source_component.ftype,
5713
+ name: source_component.name,
5714
+ manufacturer_part_number: source_component.manufacturer_part_number,
5715
+ footprinterString
5716
+ });
5717
+ }
5718
+ async _getSupplierPartNumbers(partsEngine, source_component, footprinterString) {
5719
+ const cacheEngine = this.root?.platform?.localCacheEngine;
5720
+ const cacheKey = this._getPartsEngineCacheKey(
5721
+ source_component,
5722
+ footprinterString
5723
+ );
5724
+ if (cacheEngine) {
5725
+ const cached = await cacheEngine.getItem(cacheKey);
5726
+ if (cached) {
5727
+ try {
5728
+ return JSON.parse(cached);
5729
+ } catch {
5730
+ }
5731
+ }
5732
+ }
5733
+ const result = await Promise.resolve(
5734
+ partsEngine.findPart({
5735
+ sourceComponent: source_component,
5736
+ footprinterString
5737
+ })
5738
+ );
5739
+ if (cacheEngine) {
5740
+ try {
5741
+ await cacheEngine.setItem(cacheKey, JSON.stringify(result));
5742
+ } catch {
5743
+ }
5744
+ }
5745
+ return result;
5746
+ }
5710
5747
  doInitialPartsEngineRender() {
5711
5748
  const partsEngine = this.getInheritedProperty("partsEngine");
5712
5749
  if (!partsEngine) return;
@@ -5718,10 +5755,11 @@ var NormalComponent = class extends PrimitiveComponent2 {
5718
5755
  if (this.props.footprint && typeof this.props.footprint === "string") {
5719
5756
  footprinterString = this.props.footprint;
5720
5757
  }
5721
- const supplierPartNumbersMaybePromise = partsEngine.findPart({
5722
- sourceComponent: source_component,
5758
+ const supplierPartNumbersMaybePromise = this._getSupplierPartNumbers(
5759
+ partsEngine,
5760
+ source_component,
5723
5761
  footprinterString
5724
- });
5762
+ );
5725
5763
  if (!(supplierPartNumbersMaybePromise instanceof Promise)) {
5726
5764
  db.source_component.update(this.source_component_id, {
5727
5765
  supplier_part_numbers: supplierPartNumbersMaybePromise
@@ -8481,7 +8519,7 @@ import { identity as identity4 } from "transformation-matrix";
8481
8519
  var package_default = {
8482
8520
  name: "@tscircuit/core",
8483
8521
  type: "module",
8484
- version: "0.0.422",
8522
+ version: "0.0.423",
8485
8523
  types: "dist/index.d.ts",
8486
8524
  main: "dist/index.js",
8487
8525
  module: "dist/index.js",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.423",
4
+ "version": "0.0.424",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",