Skip to content

Commit 9ff6801

Browse files
authored
Merge pull request #88 from makinosp/develop
Develop
2 parents 9f0b2d7 + 8a97642 commit 9ff6801

36 files changed

+190
-144
lines changed

.swiftlint.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ disabled_rules:
55

66
opt_in_rules:
77
- array_init
8-
- attributes
8+
- attributes:
9+
attributes_with_arguments_always_on_line_above: false
910
- closure_end_indentation
1011
- closure_spacing
1112
- collection_alignment
@@ -21,7 +22,7 @@ opt_in_rules:
2122
- fatal_error_message
2223
- first_where
2324
- flatmap_over_map_reduce
24-
# - force_unwrapping
25+
- force_unwrapping
2526
- identical_operands
2627
- implicit_return
2728
- implicitly_unwrapped_optional

Sources/VRCKit/Models/AuthenticationModel.swift renamed to Sources/VRCKit/Models/Authentication/AuthenticationModel.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ struct VerifyResponse: Codable, Sendable {
2323

2424
struct RequiresTwoFactorAuthResponse: Codable, Sendable {
2525
let requiresTwoFactorAuth: [VerifyType]
26+
}
2627

28+
extension RequiresTwoFactorAuthResponse {
2729
var requires: VerifyType? {
2830
requiresTwoFactorAuth.first { [.totp, .emailOtp].contains($0) }
2931
}

Sources/VRCKit/Models/CommonModels.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ public struct ResponseMessage: Codable, Sendable {
1313
public let statusCode: Int
1414
}
1515

16+
public extension ResponseMessage {
17+
static var ok: ResponseMessage {
18+
ResponseMessage(message: "OK", statusCode: 200)
19+
}
20+
}
21+
1622
@MemberwiseInit(.public)
1723
public struct SuccessResponse: Codable, Sendable {
1824
public let success: ResponseMessage

Sources/VRCKit/Models/FavoriteModel.swift renamed to Sources/VRCKit/Models/Favorite/FavoriteModel.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
import Foundation
99
import MemberwiseInit
1010

11-
public enum FavoriteType: String, Codable, Sendable {
11+
public enum FavoriteType: String, Codable, Sendable, CaseIterable {
1212
case world, avatar, friend
1313
}
1414

15+
extension FavoriteType: Identifiable {
16+
public var id: Int { hashValue }
17+
}
18+
1519
@MemberwiseInit(.public)
1620
public struct Favorite: Codable, Sendable, Identifiable {
1721
public let id: String
@@ -23,8 +27,10 @@ public struct Favorite: Codable, Sendable, Identifiable {
2327
public struct FavoriteDetail: Sendable, Identifiable {
2428
public let id: String
2529
public let favorites: [Favorite]
30+
}
2631

27-
public func allFavoritesAre(_ type: FavoriteType) -> Bool {
32+
public extension FavoriteDetail {
33+
func allFavoritesAre(_ type: FavoriteType) -> Bool {
2834
favorites.allSatisfy { $0.type == type }
2935
}
3036
}
@@ -52,4 +58,5 @@ struct RequestToAddFavorite: Codable, Sendable {
5258
struct RequestToUpdateFavoriteGroup: Codable, Sendable {
5359
let displayName: String?
5460
let visibility: FavoriteGroup.Visibility?
61+
let tags: [String]
5562
}

Sources/VRCKit/Models/FriendModel+Decodable.swift renamed to Sources/VRCKit/Models/Friend/FriendModel+Decodable.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ extension Friend: Decodable {
1212
let container = try decoder.container(keyedBy: CodingKeys.self)
1313
bio = try container.decodeIfPresent(String.self, forKey: .bio)
1414
bioLinks = try container.decodeSafeNullableArray(URL.self, forKey: .bioLinks)
15-
avatarImageUrl = try container.decodeIfPresent(URL.self, forKey: .avatarImageUrl)
16-
avatarThumbnailUrl = try container.decodeIfPresent(URL.self, forKey: .avatarThumbnailUrl)
15+
avatarImageUrl = try container.decodeIfPresent(URL.self, forKey: .currentAvatarImageUrl)
16+
avatarThumbnailUrl = try container.decodeIfPresent(URL.self, forKey: .currentAvatarThumbnailImageUrl)
1717
displayName = try container.decode(String.self, forKey: .displayName)
18-
id = try container.decode(String.self, forKey: .id)
18+
id = try container.decode(Friend.ID.self, forKey: .id)
1919
isFriend = try container.decode(Bool.self, forKey: .isFriend)
2020
lastLogin = try container.decode(Date.self, forKey: .lastLogin)
2121
lastPlatform = try container.decode(String.self, forKey: .lastPlatform)
@@ -34,8 +34,8 @@ extension Friend {
3434
private enum CodingKeys: String, CodingKey {
3535
case bio
3636
case bioLinks
37-
case avatarImageUrl = "currentAvatarImageUrl"
38-
case avatarThumbnailUrl = "currentAvatarThumbnailImageUrl"
37+
case currentAvatarImageUrl
38+
case currentAvatarThumbnailImageUrl
3939
case displayName
4040
case id
4141
case isFriend
File renamed without changes.

Sources/VRCKit/Models/ImageResolution.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
// Created by makinosp on 2024/09/02.
66
//
77

8-
public enum ImageResolution: Int, Sendable, CustomStringConvertible {
8+
public enum ImageResolution: Int, Sendable {
99
case x256 = 256
1010
case x512 = 512
1111
case x1024 = 1024
1212
case origin = 0
13+
}
1314

14-
public var description: String {
15-
rawValue.description
16-
}
15+
extension ImageResolution: CustomStringConvertible {
16+
public var description: String { rawValue.description }
1717
}

Sources/VRCKit/Utils/OptionalISO8601Date.swift renamed to Sources/VRCKit/Models/OptionalISO8601Date.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@
66
//
77

88
import Foundation
9+
import MemberwiseInit
910

11+
@MemberwiseInit(.public)
1012
public struct OptionalISO8601Date: Sendable {
11-
public let date: Date?
13+
@Init(default: nil) public let date: Date?
1214
private let formatter = DateFormatter.iso8601Full
1315
}
1416

15-
public extension OptionalISO8601Date {
16-
init() {
17-
date = nil
18-
}
19-
}
20-
2117
extension OptionalISO8601Date: Decodable {
2218
public init(from decoder: any Decoder) throws {
2319
let container = try decoder.singleValueContainer()
@@ -39,7 +35,7 @@ extension OptionalISO8601Date: Decodable {
3935
extension OptionalISO8601Date: Encodable {
4036
public func encode(to encoder: Encoder) throws {
4137
var container = encoder.singleValueContainer()
42-
if let date = self.date {
38+
if let date = date {
4339
let dateString = formatter.string(from: date)
4440
try container.encode(dateString)
4541
} else {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// SafeDecoding.swift
3+
// VRCKit
4+
//
5+
// Created by makinosp on 2024/09/30.
6+
//
7+
8+
import MemberwiseInit
9+
10+
@propertyWrapper @MemberwiseInit(.public)
11+
public struct SafeDecoding<T> {
12+
@Init(default: nil) public var wrappedValue: T?
13+
}
14+
15+
extension SafeDecoding: Decodable where T: Decodable {
16+
public init(from decoder: Decoder) throws {
17+
let container = try decoder.singleValueContainer()
18+
wrappedValue = try? container.decode(T.self)
19+
}
20+
}
21+
22+
extension SafeDecoding: Identifiable where T: Identifiable {
23+
public var id: T.ID? { wrappedValue?.id }
24+
}
25+
26+
extension SafeDecoding: Encodable where T: Encodable {}
27+
extension SafeDecoding: Equatable where T: Equatable {}
28+
extension SafeDecoding: Hashable where T: Hashable {}
29+
extension SafeDecoding: Sendable where T: Sendable {}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// SafeDecodingArray.swift
3+
// VRCKit
4+
//
5+
// Created by makinosp on 2024/07/28.
6+
//
7+
8+
import MemberwiseInit
9+
10+
@propertyWrapper @MemberwiseInit(.public)
11+
public struct SafeDecodingArray<T> {
12+
@Init(default: []) public var wrappedValue: [T]
13+
}
14+
15+
extension SafeDecodingArray: Decodable where T: Decodable {
16+
private struct AnyDecodable: Decodable {}
17+
public init(from decoder: Decoder) throws {
18+
wrappedValue = []
19+
var container = try decoder.unkeyedContainer()
20+
while !container.isAtEnd {
21+
if let value = try? container.decode(T.self) {
22+
wrappedValue.append(value)
23+
} else {
24+
_ = try container.decode(AnyDecodable.self)
25+
}
26+
}
27+
}
28+
}
29+
30+
extension SafeDecodingArray: Hashable where T: Hashable {
31+
public static func == (lhs: SafeDecodingArray<T>, rhs: SafeDecodingArray<T>) -> Bool {
32+
lhs.wrappedValue.hashValue == rhs.wrappedValue.hashValue
33+
}
34+
}
35+
36+
extension SafeDecodingArray: Encodable where T: Encodable {}
37+
extension SafeDecodingArray: Equatable where T: Equatable {}
38+
extension SafeDecodingArray: Sendable where T: Sendable {}

0 commit comments

Comments
 (0)