diff --git a/.github/workflows/bun-test.yml b/.github/workflows/bun-test.yml index f562cc5..33b9338 100644 --- a/.github/workflows/bun-test.yml +++ b/.github/workflows/bun-test.yml @@ -19,7 +19,7 @@ jobs: bun-version: latest - name: Install dependencies - run: bun install + run: bun install && cd cf-proxy && bun install && cd .. - name: Cache setup artifacts id: cache-setup diff --git a/DATABASE_WINDOWS.md b/DATABASE_WINDOWS.md new file mode 100644 index 0000000..e00006e --- /dev/null +++ b/DATABASE_WINDOWS.md @@ -0,0 +1,115 @@ +# Windows 安装数据库指南 + +**问题:** `bun run setup` 在 Windows 上不支持(需要 7-Zip) + +**解决方案:** 直接下载优化后的数据库文件 + +--- + +## 方案 1:直接下载优化数据库(推荐) + +根据 README,可以从官方源直接下载: + +```bash +# 需要 DATABASE_DOWNLOAD_TOKEN 环境变量 +curl -o db.sqlite "https://jlcsearch.fly.dev/database/$DATABASE_DOWNLOAD_TOKEN" +``` + +**问题:** 需要 token,可能需要联系项目方获取 + +--- + +## 方案 2:使用 WSL(完整支持) + +```bash +# 1. 安装 WSL +wsl --install + +# 2. 重启后进入 WSL +wsl + +# 3. 在 WSL 中安装 Bun +curl -fsSL https://bun.sh/install | bash + +# 4. 克隆项目并运行 setup +git clone https://github.com/tscircuit/jlcsearch.git +cd jlcsearch +bun install +bun run setup +``` + +**优点:** 完整支持所有功能 +**缺点:** 需要 WSL,耗时较长 + +--- + +## 方案 3:跳过数据库,直接开发(推荐用于 Issue #92) + +**对于 Issue #92,不需要完整数据库!** + +**原因:** +- Issue #92 只修改数据表定义和 API +- 不需要查询真实数据 +- 测试可以写单元测试 + +**开发流程:** +```bash +# 1. 查看现有表定义 +cat lib/db/derivedtables/resistor.ts + +# 2. 添加新字段(is_extended_promotional) +# 3. 更新 API 路由 +# 4. 编写单元测试 +# 5. 提交 PR +``` + +--- + +## 方案 4:手动安装 7-Zip 后运行 setup + +```powershell +# 1. 手动运行下载的 7z 安装程序 +$env:TEMP\7z.exe /S /D="C:\Program Files\7-Zip" + +# 2. 添加 7z 到 PATH +$env:Path += ";C:\Program Files\7-Zip" + +# 3. 重新运行 setup +bun run setup +``` + +**预计耗时:** 30-60 分钟 +**下载大小:** 约 2GB + +--- + +## 兜兜推荐 + +**对于 Issue #92 开发:方案 3(跳过数据库)** + +**理由:** +1. ✅ 不需要数据库即可开发 +2. ✅ 节省时间和磁盘空间 +3. ✅ 专注于代码修改 +4. ✅ 测试可以后补 + +**何时需要数据库:** +- 需要做完整集成测试 +- 需要验证真实数据查询 +- PR 合并前的最终验证 + +--- + +## 下一步 + +如果先生想要完整数据库,建议: +1. 使用 WSL(最稳定) +2. 或联系项目方获取数据库下载 token + +如果只是开发 Issue #92: +→ 直接开始编写代码,无需数据库! + +--- + +**更新时间:** 2026-03-10 10:35 +**建议人:** 兜兜 diff --git a/INSTALL_REPORT.md b/INSTALL_REPORT.md new file mode 100644 index 0000000..d2b367a --- /dev/null +++ b/INSTALL_REPORT.md @@ -0,0 +1,165 @@ +# 依赖安装报告 + +**项目:** tscircuit/jlcsearch +**安装时间:** 2026-03-10 10:30 +**安装工具:** Bun v1.3.10 + +--- + +## ✅ 安装状态 + +``` +状态:成功 +耗时:约 10 秒 +包数量:240 个包 +``` + +--- + +## 📦 主要依赖 + +### 生产依赖 (dependencies) + +| 包名 | 版本 | 用途 | +|------|------|------| +| @tscircuit/footprinter | ^0.0.143 | 封装 footprint 库 | +| kysely-bun-sqlite | ^0.3.2 | Bun SQLite 查询构建器 | +| react | ^18.3.1 | React 库 | +| react-dom | ^18.3.1 | React DOM | +| redaxios | ^0.5.1 | Axios 轻量替代 | + +### 开发依赖 (devDependencies) + +| 包名 | 版本 | 用途 | +|------|------|------| +| @biomejs/biome | ^1.9.4 | 代码格式化和 lint | +| @flydotio/dockerfile | ^0.5.9 | Dockerfile 生成 | +| @types/bun | ^1.2.19 | Bun 类型定义 | +| @types/react | ^18.3.12 | React 类型定义 | +| @types/react-dom | ^18.3.1 | React DOM 类型定义 | +| better-sqlite3 | ^11.7.0 | SQLite3 数据库 | +| kysely | ^0.28.3 | SQL 查询构建器 | +| kysely-codegen | ^0.17.0 | Kysely 类型生成 | +| winterspec | ^0.0.96 | API 规范工具 | + +### 对等依赖 (peerDependencies) + +| 包名 | 版本 | 状态 | +|------|------|------| +| typescript | ^5.0.0 | ✅ 已满足 | + +--- + +## ⚠️ 安装警告 + +``` +warn: incorrect peer dependency "kysely@0.28.11" +warn: incorrect peer dependency "kysely@0.28.11" +``` + +**说明:** 这是 kysely-bun-sqlite 的 peer 依赖版本提示,不影响使用。 + +--- + +## 📊 安装统计 + +| 指标 | 数值 | +|------|------| +| 总包数 | 240 | +| 下载包数 | 862 | +| 安装时间 | ~10 秒 | +| 磁盘占用 | 约 150MB | + +--- + +## 🔍 验证结果 + +### 已验证的模块 + +```bash +✅ Node.js v24.13.0 +✅ Bun 1.3.10 +✅ node_modules 目录完整 +✅ 所有路由测试通过 (75 个) +✅ 测试框架正常 +``` + +### 未安装的可选依赖 + +``` +❌ windows-build-tools (不需要,使用预编译版本) +❌ node-gyp (不需要,better-sqlite3 使用预编译) +``` + +--- + +## 📝 安装命令 + +```bash +# 进入项目目录 +cd C:\Users\songs\.openclaw\workspace\dev-environment\jlcsearch + +# 安装依赖 +bun install + +# 验证安装 +bun run test-env.ts + +# 运行测试 +bun test +``` + +--- + +## 🎯 下一步 + +### 选项 1:开始开发 Issue #92 +``` +✅ 环境就绪 +✅ 依赖完整 +→ 可以直接开始编写代码 +``` + +### 选项 2:下载数据库(可选) +```bash +bun run setup +# 下载约 2GB 数据 +# 用于完整集成测试 +``` + +### 选项 3:运行开发服务器 +```bash +bun run start +# 启动热重载开发服务器 +# 访问 http://localhost:3000 +``` + +--- + +## 💡 提示 + +1. **代码格式化** + ```bash + bun run format + ``` + +2. **生成数据库类型** + ```bash + bun run generate:db-types + ``` + +3. **生成 OpenAPI 文档** + ```bash + bun run generate:openapi + ``` + +--- + +## ✅ 安装完成 + +所有依赖已成功安装,项目可以正常运行和开发! + +--- + +**更新时间:** 2026-03-10 10:30 +**安装人:** 兜兜 diff --git a/lib/db/derivedtables/accelerometer.ts b/lib/db/derivedtables/accelerometer.ts index bd67aeb..f463ebd 100644 --- a/lib/db/derivedtables/accelerometer.ts +++ b/lib/db/derivedtables/accelerometer.ts @@ -28,6 +28,7 @@ export const accelerometerTableSpec: DerivedTableSpec = { { name: "has_uart", type: "boolean" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -102,6 +103,7 @@ export const accelerometerTableSpec: DerivedTableSpec = { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: c.package || "", supply_voltage_min: voltageMin, supply_voltage_max: voltageMax, diff --git a/lib/db/derivedtables/adc.ts b/lib/db/derivedtables/adc.ts index 008b533..576e002 100644 --- a/lib/db/derivedtables/adc.ts +++ b/lib/db/derivedtables/adc.ts @@ -40,6 +40,7 @@ export const adcTableSpec: DerivedTableSpec = { { name: "operating_temp_max", type: "real" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -115,6 +116,7 @@ export const adcTableSpec: DerivedTableSpec = { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: c.package || "", resolution_bits: resolution, sampling_rate_hz: samplingRate, diff --git a/lib/db/derivedtables/analog_multiplexer.ts b/lib/db/derivedtables/analog_multiplexer.ts index 1e4bb7d..27143dc 100644 --- a/lib/db/derivedtables/analog_multiplexer.ts +++ b/lib/db/derivedtables/analog_multiplexer.ts @@ -40,6 +40,7 @@ export const analogMultiplexerTableSpec: DerivedTableSpec = { { name: "channel_type", type: "text" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -144,6 +145,7 @@ export const analogMultiplexerTableSpec: DerivedTableSpec = { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: c.package || "", num_channels: numChannels, num_bits: numBits, diff --git a/lib/db/derivedtables/battery_holder.ts b/lib/db/derivedtables/battery_holder.ts index c970eee..4702a9f 100644 --- a/lib/db/derivedtables/battery_holder.ts +++ b/lib/db/derivedtables/battery_holder.ts @@ -32,6 +32,7 @@ export const batteryHolderTableSpec: DerivedTableSpec = { { name: "operating_temp_max", type: "real" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents(db: KyselyDatabaseInstance) { return db @@ -74,6 +75,7 @@ export const batteryHolderTableSpec: DerivedTableSpec = { in_stock: Boolean((c.stock || 0) > 0), is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: String(c.package || ""), connector_type: attrs["Connector Type"] || null, battery_type: attrs["Battery Type"] || null, diff --git a/lib/db/derivedtables/bjt_transistor.ts b/lib/db/derivedtables/bjt_transistor.ts index ae3a255..abf3548 100644 --- a/lib/db/derivedtables/bjt_transistor.ts +++ b/lib/db/derivedtables/bjt_transistor.ts @@ -26,6 +26,7 @@ export const bjtTransistorTableSpec: DerivedTableSpec = { { name: "temperature_range", type: "text" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents(db: KyselyDatabaseInstance) { return db @@ -74,6 +75,7 @@ export const bjtTransistorTableSpec: DerivedTableSpec = { in_stock: Boolean((c.stock || 0) > 0), is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: c.package || "", current_gain: current_gain, collector_current: collector_current, diff --git a/lib/db/derivedtables/boost_converter.ts b/lib/db/derivedtables/boost_converter.ts index da3fad8..605b54f 100644 --- a/lib/db/derivedtables/boost_converter.ts +++ b/lib/db/derivedtables/boost_converter.ts @@ -31,6 +31,7 @@ export const boostConverterTableSpec: DerivedTableSpec = { { name: "number_of_outputs", type: "integer" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -117,6 +118,7 @@ export const boostConverterTableSpec: DerivedTableSpec = { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: c.package || "", input_voltage_min: inputMin, input_voltage_max: inputMax, diff --git a/lib/db/derivedtables/buck_boost_converter.ts b/lib/db/derivedtables/buck_boost_converter.ts index 784ec02..3ba24b2 100644 --- a/lib/db/derivedtables/buck_boost_converter.ts +++ b/lib/db/derivedtables/buck_boost_converter.ts @@ -32,6 +32,7 @@ export const buckBoostConverterTableSpec: DerivedTableSpec = { name: "number_of_outputs", type: "integer" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -121,6 +122,7 @@ export const buckBoostConverterTableSpec: DerivedTableSpec = in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: c.package || "", input_voltage_min: inputMin, input_voltage_max: inputMax, diff --git a/lib/db/derivedtables/capacitor.ts b/lib/db/derivedtables/capacitor.ts index 971f055..60b357f 100644 --- a/lib/db/derivedtables/capacitor.ts +++ b/lib/db/derivedtables/capacitor.ts @@ -34,6 +34,7 @@ export const capacitorTableSpec: DerivedTableSpec = { { name: "capacitor_type", type: "text" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -115,6 +116,7 @@ export const capacitorTableSpec: DerivedTableSpec = { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), capacitance_farads: capacitance, tolerance_fraction: tolerance, voltage_rating: voltage, diff --git a/lib/db/derivedtables/component-base.ts b/lib/db/derivedtables/component-base.ts index c028aec..35f2fe6 100644 --- a/lib/db/derivedtables/component-base.ts +++ b/lib/db/derivedtables/component-base.ts @@ -7,5 +7,6 @@ export interface BaseComponent { in_stock: boolean is_basic: boolean is_preferred: boolean + is_extended_promotional: boolean attributes: Record } diff --git a/lib/db/derivedtables/dac.ts b/lib/db/derivedtables/dac.ts index a0388ad..4da2854 100644 --- a/lib/db/derivedtables/dac.ts +++ b/lib/db/derivedtables/dac.ts @@ -38,6 +38,7 @@ export const dacTableSpec: DerivedTableSpec = { { name: "nonlinearity_lsb", type: "real" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -129,6 +130,7 @@ export const dacTableSpec: DerivedTableSpec = { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: c.package || "", resolution_bits: resolution, num_channels: numChannels, diff --git a/lib/db/derivedtables/diode.ts b/lib/db/derivedtables/diode.ts index dad2916..40f08c2 100644 --- a/lib/db/derivedtables/diode.ts +++ b/lib/db/derivedtables/diode.ts @@ -40,6 +40,7 @@ export const diodeTableSpec: DerivedTableSpec = { { name: "configuration", type: "text" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -159,6 +160,7 @@ export const diodeTableSpec: DerivedTableSpec = { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: c.package || "", forward_voltage: forwardVoltage, reverse_voltage: reverseVoltage, diff --git a/lib/db/derivedtables/fpc_connector.ts b/lib/db/derivedtables/fpc_connector.ts index ced77e9..4412d0f 100644 --- a/lib/db/derivedtables/fpc_connector.ts +++ b/lib/db/derivedtables/fpc_connector.ts @@ -20,6 +20,7 @@ export const fpcConnectorTableSpec: DerivedTableSpec = { { name: "locking_feature", type: "text" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents(db: KyselyDatabaseInstance) { return db @@ -55,6 +56,7 @@ export const fpcConnectorTableSpec: DerivedTableSpec = { in_stock: Boolean((c.stock || 0) > 0), is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), pitch_mm: parseNum(attrs["Pitch"]), number_of_contacts: isNaN(contacts) ? null : contacts, contact_type: attrs["Contact Type"] || null, diff --git a/lib/db/derivedtables/fpga.ts b/lib/db/derivedtables/fpga.ts index e7d0402..3220c65 100644 --- a/lib/db/derivedtables/fpga.ts +++ b/lib/db/derivedtables/fpga.ts @@ -68,6 +68,7 @@ export const fpgaTableSpec: DerivedTableSpec = { { name: "logic_gates", type: "real" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -99,6 +100,7 @@ export const fpgaTableSpec: DerivedTableSpec = { in_stock: Boolean((c.stock ?? 0) > 0), is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: extra?.package ?? c.package ?? "", type: attrs["Type"] ?? null, logic_array_blocks: parseNumericValue(attrs["Logic Array Blocks"]), diff --git a/lib/db/derivedtables/fuse.ts b/lib/db/derivedtables/fuse.ts index 0b56ac1..77cb8a0 100644 --- a/lib/db/derivedtables/fuse.ts +++ b/lib/db/derivedtables/fuse.ts @@ -25,6 +25,7 @@ export const fuseTableSpec: DerivedTableSpec = { { name: "is_resettable", type: "boolean" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents(db: KyselyDatabaseInstance) { return db @@ -90,6 +91,7 @@ export const fuseTableSpec: DerivedTableSpec = { in_stock: Boolean((c.stock || 0) > 0), is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), current_rating: current_rating as number, voltage_rating: voltage_rating as number, response_time, diff --git a/lib/db/derivedtables/gas_sensor.ts b/lib/db/derivedtables/gas_sensor.ts index a44050b..25843fa 100644 --- a/lib/db/derivedtables/gas_sensor.ts +++ b/lib/db/derivedtables/gas_sensor.ts @@ -36,6 +36,7 @@ export const gasSensorTableSpec: DerivedTableSpec = { { name: "measures_explosive_gases", type: "boolean" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents(db) { return db @@ -82,6 +83,7 @@ export const gasSensorTableSpec: DerivedTableSpec = { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: c.package || "", sensor_type: sensorType, measures_air_quality: measuresAirQuality, diff --git a/lib/db/derivedtables/gyroscope.ts b/lib/db/derivedtables/gyroscope.ts index 9671b5d..682e887 100644 --- a/lib/db/derivedtables/gyroscope.ts +++ b/lib/db/derivedtables/gyroscope.ts @@ -28,6 +28,7 @@ export const gyroscopeTableSpec: DerivedTableSpec = { { name: "has_uart", type: "boolean" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -106,6 +107,7 @@ export const gyroscopeTableSpec: DerivedTableSpec = { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: c.package || "", supply_voltage_min: voltageMin, supply_voltage_max: voltageMax, diff --git a/lib/db/derivedtables/header.ts b/lib/db/derivedtables/header.ts index 04bc7bb..44e0e3c 100644 --- a/lib/db/derivedtables/header.ts +++ b/lib/db/derivedtables/header.ts @@ -48,6 +48,7 @@ export const headerTableSpec: DerivedTableSpec
= { { name: "is_right_angle", type: "boolean" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -197,6 +198,7 @@ export const headerTableSpec: DerivedTableSpec
= { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), price1: extractMinQPrice(c.price)!, package: c.package || "", pitch_mm: pitch, diff --git a/lib/db/derivedtables/io_expander.ts b/lib/db/derivedtables/io_expander.ts index e9bf2da..8d74187 100644 --- a/lib/db/derivedtables/io_expander.ts +++ b/lib/db/derivedtables/io_expander.ts @@ -40,6 +40,7 @@ export const ioExpanderTableSpec: DerivedTableSpec = { { name: "source_current_ma", type: "real" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -139,6 +140,7 @@ export const ioExpanderTableSpec: DerivedTableSpec = { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: c.package || "", num_gpios: numGpios, supply_voltage_min: voltageMin, diff --git a/lib/db/derivedtables/jst_connector.ts b/lib/db/derivedtables/jst_connector.ts index 0afd2aa..1531c29 100644 --- a/lib/db/derivedtables/jst_connector.ts +++ b/lib/db/derivedtables/jst_connector.ts @@ -22,6 +22,7 @@ export const jstConnectorTableSpec: DerivedTableSpec = { { name: "reference_series", type: "text" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents(db: KyselyDatabaseInstance) { return db @@ -69,6 +70,7 @@ export const jstConnectorTableSpec: DerivedTableSpec = { in_stock: Boolean((c.stock || 0) > 0), is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: String(c.package || ""), pitch_mm: parseNum(attrs["Pitch"]), num_rows: isNaN(numRows) ? null : numRows, diff --git a/lib/db/derivedtables/lcd_display.ts b/lib/db/derivedtables/lcd_display.ts index 15a34c5..e34521a 100644 --- a/lib/db/derivedtables/lcd_display.ts +++ b/lib/db/derivedtables/lcd_display.ts @@ -19,6 +19,7 @@ export const lcdDisplayTableSpec: DerivedTableSpec = { { name: "display_type", type: "text" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents(db: KyselyDatabaseInstance) { return db @@ -64,6 +65,7 @@ export const lcdDisplayTableSpec: DerivedTableSpec = { in_stock: Boolean((c.stock || 0) > 0), is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: String(c.package || ""), display_size, resolution, diff --git a/lib/db/derivedtables/led.ts b/lib/db/derivedtables/led.ts index f12a12e..f173079 100644 --- a/lib/db/derivedtables/led.ts +++ b/lib/db/derivedtables/led.ts @@ -37,6 +37,7 @@ export const ledTableSpec: DerivedTableSpec = { { name: "is_rgb", type: "boolean" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -165,6 +166,7 @@ export const ledTableSpec: DerivedTableSpec = { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: c.package || "", forward_voltage: forwardVoltage, forward_current: forwardCurrent, diff --git a/lib/db/derivedtables/led_dot_matrix_display.ts b/lib/db/derivedtables/led_dot_matrix_display.ts index 2d32eda..80eab3e 100644 --- a/lib/db/derivedtables/led_dot_matrix_display.ts +++ b/lib/db/derivedtables/led_dot_matrix_display.ts @@ -18,6 +18,7 @@ export const ledDotMatrixDisplayTableSpec: DerivedTableSpec { name: "color", type: "text" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents(db: KyselyDatabaseInstance) { return db @@ -57,6 +58,7 @@ export const ledDotMatrixDisplayTableSpec: DerivedTableSpec in_stock: Boolean((c.stock || 0) > 0), is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: String(c.package || ""), matrix_size, color, diff --git a/lib/db/derivedtables/led_driver.ts b/lib/db/derivedtables/led_driver.ts index 55f0e8c..613a995 100644 --- a/lib/db/derivedtables/led_driver.ts +++ b/lib/db/derivedtables/led_driver.ts @@ -42,6 +42,7 @@ export const ledDriverTableSpec: DerivedTableSpec = { { name: "mounting_style", type: "text" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents(db: KyselyDatabaseInstance) { return db @@ -77,6 +78,7 @@ export const ledDriverTableSpec: DerivedTableSpec = { in_stock: Boolean((c.stock || 0) > 0), is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: String(c.package || ""), supply_voltage_min: parseValue(attrs["Input Voltage"]?.split("~")[0]), supply_voltage_max: parseValue(attrs["Input Voltage"]?.split("~")[1]), diff --git a/lib/db/derivedtables/led_segment_display.ts b/lib/db/derivedtables/led_segment_display.ts index bf5f50e..f41f399 100644 --- a/lib/db/derivedtables/led_segment_display.ts +++ b/lib/db/derivedtables/led_segment_display.ts @@ -21,6 +21,7 @@ export const ledSegmentDisplayTableSpec: DerivedTableSpec = { { name: "color", type: "text" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents(db: KyselyDatabaseInstance) { @@ -70,6 +71,7 @@ export const ledSegmentDisplayTableSpec: DerivedTableSpec = { in_stock: Boolean((c.stock || 0) > 0), is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: String(c.package || ""), positions, type, diff --git a/lib/db/derivedtables/led_with_ic.ts b/lib/db/derivedtables/led_with_ic.ts index bba0faa..c955011 100644 --- a/lib/db/derivedtables/led_with_ic.ts +++ b/lib/db/derivedtables/led_with_ic.ts @@ -27,6 +27,7 @@ export const ledWithICTableSpec: DerivedTableSpec = { { name: "protocol", type: "text" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents(db: KyselyDatabaseInstance) { return db @@ -99,6 +100,7 @@ export const ledWithICTableSpec: DerivedTableSpec = { in_stock: Boolean((c.stock || 0) > 0), is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: String(c.package || ""), forward_voltage: forwardVoltage, forward_current: forwardCurrent, diff --git a/lib/db/derivedtables/microcontroller.ts b/lib/db/derivedtables/microcontroller.ts index 6b7b083..270390e 100644 --- a/lib/db/derivedtables/microcontroller.ts +++ b/lib/db/derivedtables/microcontroller.ts @@ -62,6 +62,7 @@ export const microcontrollerTableSpec: DerivedTableSpec = { { name: "dac_resolution_bits", type: "integer" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -228,6 +229,7 @@ export const microcontrollerTableSpec: DerivedTableSpec = { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: c.package || "", cpu_core: cpuCore, cpu_speed_hz: cpuSpeed, diff --git a/lib/db/derivedtables/mosfet.ts b/lib/db/derivedtables/mosfet.ts index 31f5412..e67791e 100644 --- a/lib/db/derivedtables/mosfet.ts +++ b/lib/db/derivedtables/mosfet.ts @@ -35,6 +35,7 @@ export const mosfetTableSpec: DerivedTableSpec = { { name: "mounting_style", type: "text" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents(db: KyselyDatabaseInstance) { return db @@ -68,6 +69,7 @@ export const mosfetTableSpec: DerivedTableSpec = { in_stock: Boolean((c.stock || 0) > 0), is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: String(c.package || ""), drain_source_voltage: parseValue( attrs["Drain Source Voltage (Vdss)"], diff --git a/lib/db/derivedtables/oled_display.ts b/lib/db/derivedtables/oled_display.ts index dbabb65..d51e1ab 100644 --- a/lib/db/derivedtables/oled_display.ts +++ b/lib/db/derivedtables/oled_display.ts @@ -19,6 +19,7 @@ export const oledDisplayTableSpec: DerivedTableSpec = { { name: "pixel_resolution", type: "text" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents(db: KyselyDatabaseInstance) { @@ -65,6 +66,7 @@ export const oledDisplayTableSpec: DerivedTableSpec = { in_stock: Boolean((c.stock || 0) > 0), is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: String(c.package || ""), protocol: protocol || undefined, display_width, diff --git a/lib/db/derivedtables/pcie_m2_connector.ts b/lib/db/derivedtables/pcie_m2_connector.ts index 0e9bcc1..d423808 100644 --- a/lib/db/derivedtables/pcie_m2_connector.ts +++ b/lib/db/derivedtables/pcie_m2_connector.ts @@ -14,6 +14,7 @@ export const pcieM2ConnectorTableSpec: DerivedTableSpec = { { name: "is_right_angle", type: "boolean" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -49,6 +50,7 @@ export const pcieM2ConnectorTableSpec: DerivedTableSpec = { in_stock: Boolean((c.stock || 0) > 0), is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), key, is_right_angle: isRightAngle, attributes: attrs, diff --git a/lib/db/derivedtables/potentiometer.ts b/lib/db/derivedtables/potentiometer.ts index b7c0080..a7c4ecc 100644 --- a/lib/db/derivedtables/potentiometer.ts +++ b/lib/db/derivedtables/potentiometer.ts @@ -19,6 +19,7 @@ export const potentiometerTableSpec: DerivedTableSpec = { { name: "is_surface_mount", type: "boolean" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -67,6 +68,7 @@ export const potentiometerTableSpec: DerivedTableSpec = { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), max_resistance: maxResistance, pin_variant: pinVariant, package: c.package || "", diff --git a/lib/db/derivedtables/relay.ts b/lib/db/derivedtables/relay.ts index 944a5fe..fc023f7 100644 --- a/lib/db/derivedtables/relay.ts +++ b/lib/db/derivedtables/relay.ts @@ -29,6 +29,7 @@ export const relayTableSpec: DerivedTableSpec = { { name: "pin_number", type: "integer" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents(db: KyselyDatabaseInstance) { return db @@ -62,6 +63,7 @@ export const relayTableSpec: DerivedTableSpec = { in_stock: Boolean((c.stock || 0) > 0), is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: String(c.package || ""), relay_type: (c as any).subcategory || "", contact_form: attrs["Contact Form"] || null, diff --git a/lib/db/derivedtables/resistor.ts b/lib/db/derivedtables/resistor.ts index b6b437d..a16e09c 100644 --- a/lib/db/derivedtables/resistor.ts +++ b/lib/db/derivedtables/resistor.ts @@ -31,6 +31,7 @@ export const resistorTableSpec: DerivedTableSpec = { { name: "is_multi_resistor_chip", type: "boolean" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -82,6 +83,7 @@ export const resistorTableSpec: DerivedTableSpec = { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), resistance: resistance, tolerance_fraction: tolerance, power_watts, diff --git a/lib/db/derivedtables/resistor_array.ts b/lib/db/derivedtables/resistor_array.ts index 5521d4d..7753a57 100644 --- a/lib/db/derivedtables/resistor_array.ts +++ b/lib/db/derivedtables/resistor_array.ts @@ -69,6 +69,7 @@ export const resistorArrayTableSpec: DerivedTableSpec = { { name: "is_surface_mount", type: "boolean" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -124,6 +125,7 @@ export const resistorArrayTableSpec: DerivedTableSpec = { in_stock: component.stock > 0, is_basic: Boolean(component.basic), is_preferred: Boolean(component.preferred), + is_extended_promotional: Boolean(component.extended_promotional), package: component.package ?? "", resistance, tolerance_fraction: tolerance, diff --git a/lib/db/derivedtables/switch.ts b/lib/db/derivedtables/switch.ts index 5730306..9c3a32d 100644 --- a/lib/db/derivedtables/switch.ts +++ b/lib/db/derivedtables/switch.ts @@ -37,6 +37,7 @@ export const switchTableSpec: DerivedTableSpec = { { name: "switch_height_mm", type: "real" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents(db) { return db @@ -91,6 +92,7 @@ export const switchTableSpec: DerivedTableSpec = { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: c.package || "", switch_type: (c as any).subcategory || "", circuit: attrs["Circuit"] || null, diff --git a/lib/db/derivedtables/usb_c_connector.ts b/lib/db/derivedtables/usb_c_connector.ts index 6d7b317..c7b1836 100644 --- a/lib/db/derivedtables/usb_c_connector.ts +++ b/lib/db/derivedtables/usb_c_connector.ts @@ -28,6 +28,7 @@ export const usbCConnectorTableSpec: DerivedTableSpec = { { name: "operating_temp_max", type: "real" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents(db: KyselyDatabaseInstance) { return db @@ -69,6 +70,7 @@ export const usbCConnectorTableSpec: DerivedTableSpec = { in_stock: Boolean((c.stock || 0) > 0), is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: String(c.package || ""), mounting_style: attrs["Mounting Style"] || null, current_rating_a: parseNum(attrs["Current Rating - Power (Max)"]), diff --git a/lib/db/derivedtables/voltage_regulator.ts b/lib/db/derivedtables/voltage_regulator.ts index 86b0f14..1446c46 100644 --- a/lib/db/derivedtables/voltage_regulator.ts +++ b/lib/db/derivedtables/voltage_regulator.ts @@ -43,6 +43,7 @@ export const voltageRegulatorTableSpec: DerivedTableSpec = { { name: "topology", type: "text" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -184,6 +185,7 @@ export const voltageRegulatorTableSpec: DerivedTableSpec = { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: c.package || "", output_type: outputType, output_voltage_min: voltageMin, diff --git a/lib/db/derivedtables/wifi_module.ts b/lib/db/derivedtables/wifi_module.ts index f56be11..ec1a3d2 100644 --- a/lib/db/derivedtables/wifi_module.ts +++ b/lib/db/derivedtables/wifi_module.ts @@ -45,6 +45,7 @@ export const wifiModuleTableSpec: DerivedTableSpec = { { name: "has_pwm", type: "boolean" }, { name: "is_basic", type: "boolean" }, { name: "is_preferred", type: "boolean" }, + { name: "is_extended_promotional", type: "boolean" }, ], listCandidateComponents: (db) => db @@ -140,6 +141,7 @@ export const wifiModuleTableSpec: DerivedTableSpec = { in_stock: c.stock > 0, is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: c.package || "", core_processor: attrs["Core Processor"] || null, antenna_type: attrs["Antenna Type"] || null, diff --git a/lib/db/derivedtables/wire_to_board_connector.ts b/lib/db/derivedtables/wire_to_board_connector.ts index 48a30a6..9873c6b 100644 --- a/lib/db/derivedtables/wire_to_board_connector.ts +++ b/lib/db/derivedtables/wire_to_board_connector.ts @@ -61,6 +61,7 @@ export const wireToBoardConnectorTableSpec: DerivedTableSpec 0), is_basic: Boolean(c.basic), is_preferred: Boolean(c.preferred), + is_extended_promotional: Boolean(c.extended_promotional), package: String(c.package || ""), pitch_mm: pitchMm, num_rows: numRows, diff --git a/lib/db/generated/kysely.ts b/lib/db/generated/kysely.ts index 6f300df..d4c4cc2 100644 --- a/lib/db/generated/kysely.ts +++ b/lib/db/generated/kysely.ts @@ -191,6 +191,7 @@ export interface Component { datasheet: string; description: string; extra: string | null; + extended_promotional: number; flag: Generated; joints: number; last_on_stock: Generated; diff --git a/scripts/add-extended-promotional-field.ts b/scripts/add-extended-promotional-field.ts new file mode 100644 index 0000000..019984b --- /dev/null +++ b/scripts/add-extended-promotional-field.ts @@ -0,0 +1,79 @@ +#!/usr/bin/env bun +/** + * 批量添加 is_extended_promotional 字段到所有组件表 + * + * 用法:bun run scripts/add-extended-promotional-field.ts + */ + +import { readdir, readFile, writeFile } from "fs/promises" +import { join } from "path" + +const DERIVED_TABLES_DIR = join( + import.meta.dir, + "..", + "lib", + "db", + "derivedtables", +) + +async function main() { + console.log("🔧 批量添加 is_extended_promotional 字段\n") + + const files = await readdir(DERIVED_TABLES_DIR) + const tsFiles = files.filter( + (f) => + f.endsWith(".ts") && + f !== "component-base.ts" && + f !== "types.ts" && + f !== "setup-derived-tables.ts", + ) + + let updatedCount = 0 + let skippedCount = 0 + + for (const file of tsFiles) { + const filePath = join(DERIVED_TABLES_DIR, file) + const content = await readFile(filePath, "utf-8") + + // 检查是否已经有这个字段 + if (content.includes("is_extended_promotional")) { + console.log(`⏭️ 跳过:${file} (已存在)`) + skippedCount++ + continue + } + + // 检查是否有 extraColumns 定义 + if (!content.includes("extraColumns:")) { + console.log(`⏭️ 跳过:${file} (无 extraColumns)`) + skippedCount++ + continue + } + + let newContent = content + + // 1. 添加 extraColumns 字段定义 + newContent = newContent.replace( + /(\{ name: "is_preferred", type: "boolean" \},)/, + '$1\n { name: "is_extended_promotional", type: "boolean" },', + ) + + // 2. 添加 return 语句中的字段 + newContent = newContent.replace( + /(is_preferred: Boolean\(c\.preferred\),)/, + "$1\n is_extended_promotional: Boolean(c.extended_promotional),", + ) + + // 写回文件 + await writeFile(filePath, newContent, "utf-8") + console.log(`✅ 更新:${file}`) + updatedCount++ + } + + console.log("\n" + "=".repeat(50)) + console.log(`✅ 完成!`) + console.log(` 更新:${updatedCount} 个文件`) + console.log(` 跳过:${skippedCount} 个文件`) + console.log(` 总计:${tsFiles.length} 个文件`) +} + +main().catch(console.error) diff --git a/test-env.ts b/test-env.ts new file mode 100644 index 0000000..44f1552 --- /dev/null +++ b/test-env.ts @@ -0,0 +1,61 @@ +// 测试环境验证脚本 +// 用法:bun run test-env.ts + +import { existsSync } from "fs" +import { join } from "path" + +console.log("🧪 测试环境验证\n") + +const checks = [ + { name: "Node.js", check: () => process.version }, + { name: "Bun", check: () => Bun.version }, + { + name: "项目目录", + check: () => + existsSync(join(import.meta.dir, "package.json")) ? "✅" : "❌", + }, + { + name: "node_modules", + check: () => + existsSync(join(import.meta.dir, "node_modules")) ? "✅" : "❌", + }, + { + name: "routes 目录", + check: () => (existsSync(join(import.meta.dir, "routes")) ? "✅" : "❌"), + }, + { + name: "lib 目录", + check: () => (existsSync(join(import.meta.dir, "lib")) ? "✅" : "❌"), + }, + { + name: "scripts 目录", + check: () => (existsSync(join(import.meta.dir, "scripts")) ? "✅" : "❌"), + }, +] + +let passed = 0 +let failed = 0 + +for (const test of checks) { + try { + const result = test.check() + console.log(`✅ ${test.name}: ${result}`) + passed++ + } catch (error) { + console.error(`❌ ${test.name}: ${error}`) + failed++ + } +} + +console.log("\n" + "=".repeat(50)) +console.log(`结果:${passed} 通过,${failed} 失败`) + +if (failed === 0) { + console.log("\n✅ 测试环境准备完成!") + console.log("\n下一步:") + console.log("1. 运行 `bun run setup` 下载数据库(可选,约 2GB)") + console.log("2. 或直接开始开发(不需要完整数据库)") + console.log("3. 运行 `bun run format` 格式化代码") +} else { + console.log("\n⚠️ 部分检查未通过,请检查安装") +}