5.5 KiB
5.5 KiB
Type Migration Strategy: Existing Types vs New Architecture
Current State Analysis
After examining the 35+ type definition files in /src/lib/types/, here's how they'll interact with the new architecture:
Types to REPLACE
These types have direct conflicts with the new architecture and will be replaced:
1. Core Entity Types (Will be replaced with clean versions)
-
Party.d.ts → New
Partyinterface- Current uses snake_case (e.g.,
full_auto,charge_attack) - New version will use camelCase consistently
- Will properly type grid items with named entities
- Current uses snake_case (e.g.,
-
GridWeapon.d.ts → New
GridWeaponinterface- Current has
object: Weapon(matching API's naming) - New version will have
weapon: Weapon(semantic naming)
- Current has
-
GridCharacter.d.ts → New
GridCharacterinterface- Current has
object: Character - New version will have
character: Character
- Current has
-
GridSummon.d.ts → New
GridSummoninterface- Current has
object: Summon - New version will have
summon: Summon
- Current has
2. Redundant View Types (Will be removed entirely)
- From party.ts schema file:
PartyView→ Use newPartyonlyGridWeaponItemView→ Use newGridWeapononlyGridCharacterItemView→ Use newGridCharacteronlyGridSummonItemView→ Use newGridSummononly
Types to KEEP
These types serve specific purposes and will remain:
1. UI State Types
- CheckedState.d.ts - UI selection state
- ElementState.d.ts - Element filtering state
- ProficiencyState.d.ts - Proficiency filtering state
- RarityState.d.ts - Rarity filtering state
- FilterSet.d.ts - Filter combinations
2. Domain-Specific Types
- Awakening.d.ts - Enhancement system
- WeaponKey.d.ts - Weapon upgrades
- SimpleAxSkill.d.ts - AX skill system
- ItemSkill.d.ts - Item skills
- TeamElement.d.ts - Team element logic
3. Infrastructure Types
- User.d.ts - User authentication
- AccountCookie.d.ts - Auth cookies
- UserCookie.d.ts - User preferences
- GranblueCookie.d.ts - Game data cookies
- AppUpdate.d.ts - App versioning
4. Helper Types
- OnClickEvent.d.ts - Event handlers
- MentionItem.d.ts - Rich text mentions
- declarations.d.ts - Module declarations
- index.d.ts - Type exports and utilities
Types to MODIFY
These need minor updates to work with new architecture:
1. Base Entity Types
- Weapon.d.ts - Keep structure, but ensure camelCase
- Character.d.ts - Keep structure, but ensure camelCase
- Summon.d.ts - Keep structure, but ensure camelCase
- Job.d.ts - Keep structure, but ensure camelCase
- JobSkill.d.ts - Keep structure, but ensure camelCase
- JobAccessory.d.ts - Keep structure, but ensure camelCase
- Raid.d.ts - Keep structure, but ensure camelCase
- RaidGroup.d.ts - Keep structure, but ensure camelCase
- Guidebook.d.ts - Keep structure, but ensure camelCase
Migration Plan
Phase 1: Create New Type Definitions
- Create
/src/lib/types/api/directory for new clean types - Define base entities matching Rails blueprints
- Use consistent camelCase throughout
- Properly name nested entities (
weapon, notobject)
Phase 2: Update API Client
- Implement automatic transformation layer in
/src/lib/api/client.ts - Handle
object→ proper entity name mapping - Apply snake_case ↔ camelCase transformation
Phase 3: Gradual Component Migration
- Update components to import from new type locations
- Change property access from
item.objecttoitem.weapon/character/summon - Remove type casts and
as anyusage
Phase 4: Cleanup
- Delete old conflicting type files
- Remove PartyView and other view types from schemas
- Update all imports
Type Import Strategy
// OLD (current)
import type { Party } from '$lib/types/Party'
import type { GridWeapon } from '$lib/types/GridWeapon'
import type { PartyView } from '$lib/api/schemas/party'
// NEW (after migration)
import type { Party, GridWeapon, GridCharacter, GridSummon } from '$lib/types/api/party'
import type { Weapon, Character, Summon } from '$lib/types/api/entities'
// No more PartyView - just use Party
Benefits of This Approach
- Preserves existing work: Keeps all UI state types, domain logic types
- Single source of truth: One
Partytype, not Party + PartyView - Type safety: Proper TypeScript types throughout
- Clean naming:
weaponinstead ofobjecteverywhere - Backwards compatible: Can migrate gradually, component by component
Example Type Transformation
Before (Current)
// Multiple conflicting types
interface Party { // from Party.d.ts
full_auto: boolean
weapons: Array<GridWeapon>
}
interface GridWeapon { // from GridWeapon.d.ts
object: Weapon // Confusing naming
}
interface PartyView { // from party.ts schema
fullAuto?: boolean
weapons: GridWeaponItemView[]
}
After (New Architecture)
// Single clean type
interface Party {
fullAuto: boolean
weapons: GridWeapon[]
}
interface GridWeapon {
weapon: Weapon // Semantic naming
position: number
mainhand?: boolean
// ... other fields
}
// No PartyView needed!
Implementation Order
- Start with Party types - Most critical for hydration fix
- Then Grid types - Fix the object → entity naming
- Keep all other types - They're working fine
- Update components - As needed for functionality
This approach minimizes disruption while fixing the core hydration and type safety issues.