cards-native/Sources/Core/Domain/Deck.swift
Till JS aece169360 chore(lint): SwiftLint-Config + 0-Warnings-Pass + Swift-6-Concurrency-Fixes
Bringt cards-native auf 0 SwiftLint-Violations bei 75 Files. Build-Status
unverändert grün (xcodebuild iOS Debug).

.swiftlint.yml
- identifier_name excludes erweitert um math/index-Konventionen
  (i, j, n, m, x, y, w, h, r, g, b, a, c, d, s, f, p, q, t, l) —
  in algorithmischem Code klarer als verbose
- opening_brace disabled — kollidiert mit SwiftFormats
  wrapMultilineStatementBraces (SwiftFormat ist im Pre-Commit-Hook
  und gewinnt)

Code-Modernisierungen (real, nicht nur Annotations)
- Cloze.swift: regex-Tuple bekommt `swiftlint:disable large_tuple`-
  Region — Regex-Output-Type ist Builder-bedingt nicht reduzierbar
- Media.swift: `data(using: .utf8)` → `Data(s.utf8)` (non-failable),
  `String(data:as:)` → `String(bytes:encoding:)`
- CardsTheme.swift: HSL-Wert-Typ statt anonymes 3-Tupel —
  konkretere Call-Sites, kein `large_tuple`-Warning mehr
- MediaCache.swift: `CacheEntry`-Struct statt 3-Tupel im Prune-Pfad
- GradeQueue / MediaCache / StudySession / MarketplaceStore: OSLog-
  Interpolations auf lokale Variablen ziehen — fixt Swift-6-Strict-
  Concurrency-Fail bei Actor-isolated-Property-Zugriff aus
  @Sendable-Autoclosure
- DeckMutations.swift, MarketplaceModeration.swift: verschachtelte
  VersionInfo-Sub-Types auf Top-Level (`PullUpdateVersion`,
  `OwnedMarketplaceVersion`) — fixt `nesting`-Warning
- Tests/UnitTests/*.swift: alle `""".data(using: .utf8)!` migriert auf
  `Data("""…""".utf8)`; force-cast `as!` in MutationEncodingTests
  durch guard-let + throw ersetzt

Pragmatische Disables (mit Doc-Comment-Begründung)
- DeckEditorView / MarketplacePublishView / DeckDetailView /
  PublicDeckView / DeckListView / CardEditorView / CardsAPI:
  `swiftlint:disable type_body_length` (+ teilweise file_length)
  als Region-Disable mit `enable` nach dem Struct. Begründung im
  Doc-Comment: Multi-State-Maschinen mit shared Toolbar + Sheets;
  Aufspalten würde nur @Binding-Plumbing produzieren

Auto-Format-Aufräumung
- Redundante `Sendable`-Conformance entfernt (Swift 6 leitet das
  bei Wert-Typen mit Sendable-Mitgliedern automatisch ab)
- EnvironmentValues nutzt jetzt @Entry-Macro statt manueller
  EnvironmentKey-Boilerplate
- Brace-Reformatting + Import-Sortierung auf allen 75 Files

Ergebnis: 80 Warnings + 3 Errors → 0 / 0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-14 02:04:29 +02:00

136 lines
3.8 KiB
Swift

import Foundation
/// Deck-DTO. Wire-Format aus `cards/apps/api/src/lib/dto.ts:toDeckDto`.
/// snake_case-Felder via `CodingKeys`, Optionals explizit nullable.
struct Deck: Codable, Identifiable, Hashable {
let id: String
let userId: String
let name: String
let description: String?
let color: String?
let category: DeckCategory?
let visibility: DeckVisibility
let fsrsSettings: FsrsSettings
let contentHash: String?
let forkedFromMarketplaceDeckId: String?
let forkedFromMarketplaceVersionId: String?
let archivedAt: Date?
let createdAt: Date
let updatedAt: Date
enum CodingKeys: String, CodingKey {
case id
case userId = "user_id"
case name
case description
case color
case category
case visibility
case fsrsSettings = "fsrs_settings"
case contentHash = "content_hash"
case forkedFromMarketplaceDeckId = "forked_from_marketplace_deck_id"
case forkedFromMarketplaceVersionId = "forked_from_marketplace_version_id"
case archivedAt = "archived_at"
case createdAt = "created_at"
case updatedAt = "updated_at"
}
/// Geforkt aus dem Cardecky-Marketplace?
var isFromMarketplace: Bool {
forkedFromMarketplaceDeckId != nil
}
}
enum DeckVisibility: String, Codable {
case `private`
case space
case `public`
}
/// Aus `cards/packages/cards-domain/src/schemas/deck.ts:DECK_CATEGORY_IDS`.
enum DeckCategory: String, Codable, CaseIterable {
case language
case medicine
case science
case math
case history
case law
case technology
case arts
case music
case sport
case other
/// Deutsche Labels aus `DECK_CATEGORY_LABELS`.
var label: String {
switch self {
case .language: "Sprache"
case .medicine: "Medizin"
case .science: "Wissenschaft"
case .math: "Mathematik"
case .history: "Geschichte"
case .law: "Recht"
case .technology: "Technik"
case .arts: "Kunst"
case .music: "Musik"
case .sport: "Sport"
case .other: "Sonstiges"
}
}
}
/// FSRS-Settings Native bleibt schematisch agnostisch, FSRS rechnet
/// nur der Server. Wir behalten die Felder als roh-JSON, damit eine
/// neue Setting auf dem Server uns nicht bricht.
struct FsrsSettings: Codable, Hashable {
let requestRetention: Double?
let maximumInterval: Int?
let enableFuzz: Bool?
enum CodingKeys: String, CodingKey {
case requestRetention = "request_retention"
case maximumInterval = "maximum_interval"
case enableFuzz = "enable_fuzz"
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
requestRetention = try container.decodeIfPresent(Double.self, forKey: .requestRetention)
maximumInterval = try container.decodeIfPresent(Int.self, forKey: .maximumInterval)
enableFuzz = try container.decodeIfPresent(Bool.self, forKey: .enableFuzz)
}
static let empty = FsrsSettings()
private init(
requestRetention: Double? = nil,
maximumInterval: Int? = nil,
enableFuzz: Bool? = nil
) {
self.requestRetention = requestRetention
self.maximumInterval = maximumInterval
self.enableFuzz = enableFuzz
}
}
/// Server-Response von `GET /api/v1/decks`.
struct DeckListResponse: Decodable {
let decks: [Deck]
let total: Int
}
/// Server-Response von `GET /api/v1/cards?deck_id=...`.
struct CardListResponse: Decodable {
let cards: [Card]
let total: Int
}
/// Server-Response von `GET /api/v1/reviews/due?deck_id=...`.
struct DueReviewsResponse: Decodable {
let total: Int
}
/// Server-Response von `GET /api/v1/decks/:deckId/distractors`.
struct DistractorsResponse: Decodable {
let distractors: [String]
}