From 58d88990755240a5a5b36db501cb3d1814f3b513 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 3 Dec 2025 11:58:54 -0800 Subject: [PATCH] add WeaponSeriesRef type definitions --- src/lib/types/api/weaponSeries.ts | 104 ++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/lib/types/api/weaponSeries.ts diff --git a/src/lib/types/api/weaponSeries.ts b/src/lib/types/api/weaponSeries.ts new file mode 100644 index 00000000..c1ddb337 --- /dev/null +++ b/src/lib/types/api/weaponSeries.ts @@ -0,0 +1,104 @@ +/** + * Weapon Series Types + * + * Type definitions for weapon series data from the API. + * WeaponSeries is a database-driven classification system for weapons. + * + * @module types/api/weaponSeries + */ + +/** + * Embedded series reference on weapons. + * This is the structure returned in weapon.series field. + * Includes boolean flags for convenience to avoid extra lookups. + */ +export interface WeaponSeriesRef { + id: string + slug: string + name: { en: string; ja: string } + hasWeaponKeys: boolean + hasAwakening: boolean + hasAxSkills: boolean + extra: boolean + elementChangeable: boolean +} + +/** + * Full weapon series from /api/v1/weapon_series endpoint. + * The list endpoint returns a minimal view, while the show endpoint returns the full view. + */ +export interface WeaponSeries { + id: string + name: { en: string; ja: string } + slug: string + order: number + // Only included in :full view (show endpoint) + extra?: boolean + elementChangeable?: boolean + hasWeaponKeys?: boolean + hasAwakening?: boolean + hasAxSkills?: boolean + weaponCount?: number +} + +/** + * Input type for weapon series form (client-side) + */ +export interface WeaponSeriesInput { + name_en: string + name_jp: string + slug: string + order: number + extra: boolean + element_changeable: boolean + has_weapon_keys: boolean + has_awakening: boolean + has_ax_skills: boolean +} + +/** + * Payload for creating a new weapon series (editor only) + */ +export interface CreateWeaponSeriesPayload { + name_en: string + name_jp: string + slug: string + order?: number + extra?: boolean + element_changeable?: boolean + has_weapon_keys?: boolean + has_awakening?: boolean + has_ax_skills?: boolean +} + +/** + * Payload for updating an existing weapon series (editor only) + */ +export interface UpdateWeaponSeriesPayload { + name_en?: string + name_jp?: string + slug?: string + order?: number + extra?: boolean + element_changeable?: boolean + has_weapon_keys?: boolean + has_awakening?: boolean + has_ax_skills?: boolean +} + +/** + * Type guard to check if a series value is the new object format vs legacy integer. + * During migration, some weapons may still have integer series values. + * + * @param series - The series value to check + * @returns True if series is a WeaponSeriesRef object + */ +export function isWeaponSeriesRef(series: unknown): series is WeaponSeriesRef { + return ( + series !== null && + typeof series === 'object' && + 'slug' in series && + 'id' in series && + 'name' in series + ) +}