Skip to content

Comments

feat(config): add global productAttributes and contentAttributes sections#152

Open
mariobrgomes wants to merge 3 commits intomainfrom
003-global-attributes
Open

feat(config): add global productAttributes and contentAttributes sections#152
mariobrgomes wants to merge 3 commits intomainfrom
003-global-attributes

Conversation

@mariobrgomes
Copy link
Contributor

Summary

Add new productAttributes and contentAttributes config sections that allow defining shared attributes once and referencing them across product types and model types.

Key Changes

  • New config sections: productAttributes for PRODUCT_TYPE attributes, contentAttributes for PAGE_TYPE attributes
  • AttributeCache: In-memory cache for O(1) attribute lookup during deployment
  • Preflight validation: Rejects inline attribute definitions with migration guidance
  • Introspect: Automatically extracts attributes into separate sections by type
  • Validation errors: "Did you mean?" suggestions using Levenshtein distance for typos
  • Diff engine: Shows changes under "Product Attributes" and "Content Attributes" headers
  • Backward compatibility: Legacy attributes section still works with deprecation warning

Example Config

productAttributes:
  - name: Color
    inputType: DROPDOWN
    values:
      - name: Red
      - name: Blue

contentAttributes:
  - name: Author
    inputType: PLAIN_TEXT

productTypes:
  - name: T-Shirt
    productAttributes:
      - attribute: Color  # Reference by name

Test plan

  • Unit tests for AttributeCache (18 tests)
  • Unit tests for global attributes schema (discriminated unions)
  • Unit tests for inline attribute detection (29 tests)
  • Unit tests for validation errors with Levenshtein distance (20 tests)
  • Unit tests for diff comparator with new entity types (9 tests)
  • E2E: introspect → deploy → deploy (idempotent) → diff (no changes)

🤖 Generated with Claude Code

…ions

- Add productAttributes and contentAttributes config sections for shared attribute definitions
- Implement AttributeCache for O(1) attribute lookup during deployment
- Add preflight validation rejecting inline attribute definitions with migration guidance
- Enhance introspect to separate attributes by type (PRODUCT_TYPE vs PAGE_TYPE)
- Add "did you mean?" suggestions using Levenshtein distance for typos
- Extend diff engine with "Product Attributes" and "Content Attributes" entity types
- Deprecate legacy 'attributes' section with backward compatibility

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Feb 4, 2026

🦋 Changeset detected

Latest commit: 3fb2c70

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@peelar
Copy link
Member

peelar commented Feb 4, 2026

Let's make sure to add it to example.yml and README.md.

Keep main's refactored method extraction (displayDeploymentResult,
displayCleanupSuggestions, saveAndPruneReport, etc.) while preserving
PR's attributeCache in DeploymentContext and runPreflightValidation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Critical fixes:
- Pass attributeCache to pageTypesStage (was missing, causing perf regression
  and silent validation skip)
- Include legacy attributes in StageAggregateError success count

Important fixes:
- Remove Console() instantiation from validateNoInlineAttributeDefinitions;
  let caller handle presentation
- Add logger.warn to empty catch blocks in deploy.ts
- Pass entity name to resolveReferencedAttributesWithCache in PageTypeService
  for actionable error messages
- Log warning when API returns null for attribute resolution in both services
- Add productAttributes/contentAttributes to ConfigurationSection union and
  AVAILABLE_SECTIONS for --include/--exclude support
- Add UnsupportedInputTypeError handling to retrieveWithoutSaving
- Replace unsafe `as FullAttribute` cast with fullAttributeSchema.parse()

Type design improvements:
- WrongSectionResult: boolean discriminant → discriminated union
- AttributeValidationResult: boolean discriminant → discriminated union
- CachedAttribute.inputType: string → AttributeInputType union
- isInlineAttributeDefinition: boolean return → type predicate

Test coverage (+13 tests):
- validateAttributeReference: 7 tests (valid, wrong section, not found,
  Levenshtein suggestions)
- PageTypeService cache path: 3 tests (cache hit, miss, null API)
- ProductTypeService cache path: 3 tests (cache hit, miss, null API)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

2 participants