Skip to content

Commit

Permalink
fix: Expose isSaved method on ParseFile and ParseOperation (#135)
Browse files Browse the repository at this point in the history
* fix: Expose isSaved method on ParseFile and ParseOperation

* nit changelog

* nit
  • Loading branch information
cbaker6 authored Sep 24, 2023
1 parent 5817123 commit 5c3118c
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 3 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
# Parse-Swift Changelog

### main
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.8.1...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.8.2...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
* _Contributing to this repo? Add info about your change here to be included in the next release_

### 5.8.2
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.8.1...5.8.2), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.8.2/documentation/parseswift)

__Fixes__
* Expose isSaved method on ParseFile and ParseOperation ([#135](https://github.com/netreconlab/Parse-Swift/pull/135)), thanks to [Corey Baker](https://github.com/cbaker6).

### 5.8.1
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.8.0...5.8.1), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.8.1/documentation/parseswift)

Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/ParseConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

enum ParseConstants {
static let sdk = "swift"
static let version = "5.8.1"
static let version = "5.8.2"
static let fileManagementDirectory = "parse/"
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
static let fileManagementLibraryDirectory = "Library/"
Expand Down
1 change: 1 addition & 0 deletions Sources/ParseSwift/Protocols/Savable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public protocol Savable: Encodable {

func save(options: API.Options) async throws -> SavingType
func save() async throws -> SavingType
func isSaved() async throws -> Bool
}

extension Savable {
Expand Down
6 changes: 5 additions & 1 deletion Sources/ParseSwift/Types/ParseFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct ParseFile: Fileable, Savable, Deletable, Hashable, Identifiable {

internal var isDownloadNeeded: Bool {
return cloudURL != nil
&& url == nil
&& !isSaved
&& localURL == nil
&& data == nil
}
Expand Down Expand Up @@ -163,6 +163,10 @@ public struct ParseFile: Fileable, Savable, Deletable, Hashable, Identifiable {
hasher.combine(self.id)
}

public func isSaved() async throws -> Bool {
isSaved
}

enum CodingKeys: String, CodingKey {
case url
case name
Expand Down
9 changes: 9 additions & 0 deletions Sources/ParseSwift/Types/ParseOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public struct ParseOperation<T>: Savable,
self.target = target
}

/**
Specifies if this object related to the operation has been saved.
- returns: Returns **true** if this object is saved, **false** otherwise.
- throws: An error of `ParseError` type.
*/
public func isSaved() async throws -> Bool {
try await target.isSaved()
}

/**
An operation that sets a field's value.
- Parameters:
Expand Down
4 changes: 4 additions & 0 deletions Tests/ParseSwiftTests/ParseFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ class ParseFileTests: XCTestCase { // swiftlint:disable:this type_body_length
let savedFile = try await parseFile.save()
XCTAssertEqual(savedFile.name, response.name)
XCTAssertEqual(savedFile.url, response.url)
let isSavedBefore = try await parseFile.isSaved()
XCTAssertFalse(isSavedBefore)
let isSavedAfter = try await savedFile.isSaved()
XCTAssertTrue(isSavedAfter)
}

@MainActor
Expand Down
2 changes: 2 additions & 0 deletions Tests/ParseSwiftTests/ParseOperationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class ParseOperationTests: XCTestCase {
XCTAssertEqual(savedUpdatedAt, originalUpdatedAt)
XCTAssertEqual(saved.ACL, scoreOnServer.ACL)
XCTAssertEqual(saved.points, originalPoints-1)
let isSavedAfter = try await operations.isSaved()
XCTAssertTrue(isSavedAfter)
} catch {
XCTFail(error.localizedDescription)
}
Expand Down

0 comments on commit 5c3118c

Please sign in to comment.