Skip to content

feat(shared-data): item and variant schemas, model_key helpers (#1149) - #1167

Merged
JOY (JOY) merged 3 commits into
devfrom
feat/1149-item-variant-keys
Oct 28, 2026
Merged

JOY (JOY) merged 3 commits into
devfrom
feat/1149-item-variant-keys

Conversation

@JOY

@JOY JOY (JOY) commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1149

Task 3 of the Item / variant / listing model (#1129, design doc Docs/Proposals/2026-10-27-item-variant-listing-model.md, sections 4 and 10). Pure library code; nothing consumes it yet.

What changes

packages/shared-data:

  • rules/model-key.ts (zod-free, exported from the root entry and from @repo/shared-data/rules):
    • splitModelKey(modelKey) returns { itemKey, variantKey }, or null when the key is not in the brand:model:variant shape.
    • composeModelKey(itemKey, variantKey) builds item_key:variant_key and throws a RangeError on an invalid part or a key over 200 characters.
    • isItemKey, isVariantKey, isModelKey, isSizedVariantKey (^\d+(gb|tb)$, the multi-size rule of 4.2 / 7.2), UNKNOWN_VARIANT_KEY, and the *_PATTERN regexes.
    • The segment shapes are the design doc's inventory regex (7.3), with _ allowed. variant_key is the literal third segment (256gb, 1024gb, standard, unknown, and later 256gb-cellular). Apple screen and case sizes stay in the Item key (apple:ipad-pro-m5-11).
  • schemas/item.schema.ts:
    • ItemSchema: a rate.items row per the 4.3 DDL. Like the table, item_key has no shape check, because legacy keys still get an Item.
    • VariantSchema: MasterProductSchema plus nullable item_id, variant_key and sort_order. It refines that variant_key equals the model_key's third segment when the key is well formed.
    • VariantSourceSchema: the products.variant_source values.
    • Strict ItemKeySchema, VariantKeySchema and ModelKeySchema.

Tests

pnpm --filter @repo/shared-data test adds a new 8/8 step:

  • Every three-part key literal in apps/importer/src/shopee/__tests__ (155 today, read at test time) round-trips through split and compose. This covers Apple size-keyed lines, :unknown, earbuds, Garmin and Apple watches, and 1024gb.
  • The fixture scan is wider than the key shape (upper case, _), so a fixture key the helpers would reject fails the test instead of being skipped.
  • The suite also covers malformed keys and the schema defaults and refinements.

Also checked locally: @repo/crawlers build, test:dist, and @repo/web typecheck.

Review

  • A fresh-context subagent review and a Codex adversarial pass found no P0.
  • Fixed in round 1: the legacy variant_key note, the test comments, and the fixture scan's strictness.
  • Decided by the PO (round 1): the doc's key regex rejected _, yet slugify in the normalizer keeps it, as in asus:vivobook-x1504_va:512gb (Codex rated this P1).

🤖 Generated with Claude Code


📌 TL;DR

Introduces a new Item/Variant data model with strict model_key parsing/composition utilities and Zod schemas to enforce the brand:model:variant structure, ensuring data integrity across the shared data package.

🎯 Type of Change

  • 🚀 New feature
  • 🐛 Bugfix
  • 🧹 Refactor
  • ⚡ Performance
  • 📚 Documentation
  • ⚙️ CI / Configuration

🔍 Changes Walkthrough

File Summary of Changes
packages/shared-data/src/rules/model-key.ts New file. Defines regex patterns and utility functions (splitModelKey, composeModelKey, isItemKey, etc.) to parse and validate the brand:model:variant key structure. Enforces length limits and segment shapes.
packages/shared-data/src/schemas/item.schema.ts New file. Defines Zod schemas for Item, Variant, and key types. Includes a superRefine check on VariantSchema to ensure variant_key matches the third segment of model_key.
packages/shared-data/src/rules/index.ts Re-exports the new model-key utilities to make them available via the @repo/shared-data/rules entry point.
packages/shared-data/src/schemas/index.ts Re-exports the new item.schema to make Item/Variant schemas available via the main package entry.
packages/shared-data/src/index.ts Re-exports model-key rules from the root entry point.
packages/shared-data/src/__tests__/shared-data.test.ts Adds comprehensive tests for key parsing/composition round-trips, edge cases (invalid keys, legacy keys), and schema validation (Item/Variant defaults, constraints, and consistency checks).

📊 Architectural Flow

flowchart TD
    subgraph "Input"
        A[Raw model_key string]
    end

    subgraph "Rules: model-key.ts"
        B{isModelKey?}
        C[splitModelKey]
        D[composeModelKey]
        E[isItemKey / isVariantKey]
    end

    subgraph "Schemas: item.schema.ts"
        F[ItemSchema]
        G[VariantSchema]
        H[superRefine: Check variant_key consistency]
    end

    A --> B
    B -->|Valid| C
    B -->|Invalid| I[Return null]
    
    C --> J[ModelKeyParts: itemKey, variantKey]
    
    K[itemKey] --> E
    L[variantKey] --> E
    E -->|Valid| D
    D --> M[Composed model_key]
    
    N[Item Data] --> F
    O[Variant Data] --> G
    G --> H
    H -->|Uses splitModelKey| C
    H -->|Pass| P[Valid Variant]
    H -->|Fail| Q[Validation Error]
Loading

JOY (JOY) and others added 2 commits October 28, 2026 00:31
Add the Item / variant key rules from the design doc (#1129, section 4):
composeModelKey and splitModelKey (model_key = item_key:variant_key),
isItemKey / isVariantKey / isModelKey / isSizedVariantKey, and the
ItemSchema, VariantSchema and VariantSourceSchema zod contracts. The
helpers are zod-free and exported from both the root entry and
@repo/shared-data/rules. Tests round-trip every key in the importer
fixtures. Nothing consumes them yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… rule (#1149)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@vercel

vercel Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
rate Ready Ready Preview Oct 27, 2026 5:36pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 20 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e075780a-e459-4b9d-94e6-3e0c138a0380
Commits

Reviewing files that changed from the base of the PR and between 645c155 and 3eb34cc.

Files selected for processing: 7
  • Docs/Proposals/2026-10-27-item-variant-listing-model.md
  • packages/shared-data/src/__tests__/shared-data.test.ts
  • packages/shared-data/src/index.ts
  • packages/shared-data/src/rules/index.ts
  • packages/shared-data/src/rules/model-key.ts
  • packages/shared-data/src/schemas/index.ts
  • packages/shared-data/src/schemas/item.schema.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…1149)

PO decision: the key shape accepts '_' in all three segments, because
the normalizer's slugify keeps it and real keys carry it. Empty segments
(e.g. samsung::unknown) stay rejected. The design doc's 7.3 inventory
regex now matches the helpers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dos[bot]
dos Bot approved these changes Oct 27, 2026

@dos dos Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⏱️ Code Review completed (7 eligible files · 22,220 chars · 1 model call(s) · 1 PR unit(s))

Whole diff with bounded context at base 645c155 / head 3eb34cc.

✅ CLEAN_PASS: Complete diff reviewed

@JOY JOY (JOY) changed the title feat(shared-data): Item and Variant schemas, model_key helpers (#1149) feat(shared-data): item and variant schemas, model_key helpers (#1149) Oct 27, 2026
@JOY
JOY (JOY) merged commit 06edb5d into dev Oct 28, 2026
20 of 23 checks passed
@JOY
JOY (JOY) deleted the feat/1149-item-variant-keys branch October 28, 2026 04:00
@JOY JOY (JOY) mentioned this pull request Oct 28, 2026
3 of 6 tasks

This branch was successfully deployed

1 active deployment
Preview — 3eb34cc0 Deployed Oct 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:shared Shared packages / contracts / configs docs Documentation changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shared-data: Item and Variant schemas, composeModelKey/splitModelKey, item_key and variant_key rules

1 participant