Skip to content

feat: add is_extended_promotional column to all component tables#138

Open
usernametooshort wants to merge 1 commit intotscircuit:mainfrom
usernametooshort:feat/is-extended-promotional-column
Open

feat: add is_extended_promotional column to all component tables#138
usernametooshort wants to merge 1 commit intotscircuit:mainfrom
usernametooshort:feat/is-extended-promotional-column

Conversation

@usernametooshort
Copy link

Closes #92

Summary

Adds is_extended_promotional to all component tables and the base components table.

Changes

  • component-base.ts: Added is_extended_promotional: boolean to BaseComponent interface
  • 37 derived component tables: Added the column spec and value extraction from json_extract(extra, "$.promotional")
  • New optimization component-extended-promotional-column.ts: Adds is_extended_promotional as a SQLite GENERATED ALWAYS AS column on the base components table, with an index

Data Source

The value is derived from extra JSON field: json_extract(extra, "$.promotional"), which is the same source used by jlcparts. This is consistent with how basic and preferred are stored.

Testing

  • TypeScript compiles without new errors
  • Consistent pattern with existing in_stock and is_basic columns

Adds the is_extended_promotional field to:
- BaseComponent interface (component-base.ts)
- All 37 derived component tables
- A new DB optimization (component-extended-promotional-column.ts) that
  adds the column to the base components table via a SQLite generated
  column using json_extract(extra, '$.promotional')

The value is sourced from the 'promotional' key in the component's extra
JSON field, consistent with how is_basic / is_preferred are derived.

Fixes tscircuit#92

/bounty $75
in_stock: c.stock > 0,
is_basic: Boolean(c.basic),
is_preferred: Boolean(c.preferred),
is_extended_promotional: Boolean(c.extra && JSON.parse(c.extra).promotional),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent boolean conversion logic across base and derived tables

The derived tables use Boolean(c.extra && JSON.parse(c.extra).promotional) which treats the string "false" as truthy, while the base table's GENERATED column in component-extended-promotional-column.ts explicitly checks != 'false' to treat it as falsy.

This creates data inconsistency:

  • If promotional: "false" (string): derived tables return true, base table returns false
  • Components will have mismatched values between base and derived tables

Fix by aligning the logic:

is_extended_promotional: Boolean(
  c.extra && 
  JSON.parse(c.extra).promotional && 
  JSON.parse(c.extra).promotional !== 'false'
)

Or better, cache the parsed value to avoid parsing twice and handle edge cases.

Suggested change
is_extended_promotional: Boolean(c.extra && JSON.parse(c.extra).promotional),
is_extended_promotional: (() => { if (!c.extra) return false; try { const parsed = JSON.parse(c.extra); return Boolean(parsed.promotional && parsed.promotional !== 'false'); } catch { return false; } })(),

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add is_extended_promotional column to components (from data source)

1 participant