@capgo/capacitor-updater 3.2.0 → 3.2.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,97 @@
1
+ import Foundation
2
+
3
+ protocol ObjectSavable {
4
+ func setObj<Object>(_ object: Object, forKey: String) throws where Object: Encodable
5
+ func getObj<Object>(forKey: String, castTo type: Object.Type) throws -> Object where Object: Decodable
6
+ }
7
+
8
+ enum ObjectSavableError: String, LocalizedError {
9
+ case unableToEncode = "Unable to encode object into data"
10
+ case noValue = "No data object found for the given key"
11
+ case unableToDecode = "Unable to decode object into given type"
12
+
13
+ var errorDescription: String? {
14
+ rawValue
15
+ }
16
+ }
17
+
18
+ extension UserDefaults: ObjectSavable {
19
+ func setObj<Object>(_ object: Object, forKey: String) throws where Object: Encodable {
20
+ let encoder = JSONEncoder()
21
+ do {
22
+ let data = try encoder.encode(object)
23
+ set(data, forKey: forKey)
24
+ } catch {
25
+ throw ObjectSavableError.unableToEncode
26
+ }
27
+ }
28
+
29
+ func getObj<Object>(forKey: String, castTo type: Object.Type) throws -> Object where Object: Decodable {
30
+ print("forKey", forKey)
31
+ guard let data = data(forKey: forKey) else { throw ObjectSavableError.noValue }
32
+ print("data", data)
33
+ let decoder = JSONDecoder()
34
+ do {
35
+ let object = try decoder.decode(type, from: data)
36
+ return object
37
+ } catch {
38
+ throw ObjectSavableError.unableToDecode
39
+ }
40
+ }
41
+ }
42
+
43
+ //
44
+ //// MARK: - Methods
45
+ //public extension UserDefaults {
46
+ // /// SwifterSwift: get object from UserDefaults by using subscript.
47
+ // ///
48
+ // /// - Parameter key: key in the current user's defaults database.
49
+ // subscript(key: String) -> Any? {
50
+ // get {
51
+ // return object(forKey: key)
52
+ // }
53
+ // set {
54
+ // set(newValue, forKey: key)
55
+ // }
56
+ // }
57
+ //
58
+ // /// SwifterSwift: Float from UserDefaults.
59
+ // ///
60
+ // /// - Parameter key: key to find float for.
61
+ // /// - Returns: Float object for key (if exists).
62
+ // func float(forKey key: String) -> Float? {
63
+ // return object(forKey: key) as? Float
64
+ // }
65
+ //
66
+ // /// SwifterSwift: Date from UserDefaults.
67
+ // ///
68
+ // /// - Parameter key: key to find date for.
69
+ // /// - Returns: Date object for key (if exists).
70
+ // func date(forKey key: String) -> Date? {
71
+ // return object(forKey: key) as? Date
72
+ // }
73
+ //
74
+ // /// SwifterSwift: Retrieves a Codable object from UserDefaults.
75
+ // ///
76
+ // /// - Parameters:
77
+ // /// - type: Class that conforms to the Codable protocol.
78
+ // /// - key: Identifier of the object.
79
+ // /// - decoder: Custom JSONDecoder instance. Defaults to `JSONDecoder()`.
80
+ // /// - Returns: Codable object for key (if exists).
81
+ // func object<T: Codable>(_ type: T.Type, with key: String, usingDecoder decoder: JSONDecoder = JSONDecoder()) -> T? {
82
+ // guard let data = value(forKey: key) as? Data else { return nil }
83
+ // return try? decoder.decode(type.self, from: data)
84
+ // }
85
+ //
86
+ // /// SwifterSwift: Allows storing of Codable objects to UserDefaults.
87
+ // ///
88
+ // /// - Parameters:
89
+ // /// - object: Codable object to store.
90
+ // /// - key: Identifier of the object.
91
+ // /// - encoder: Custom JSONEncoder instance. Defaults to `JSONEncoder()`.
92
+ // func set<T: Codable>(object: T, forKey key: String, usingEncoder encoder: JSONEncoder = JSONEncoder()) {
93
+ // let data = try? encoder.encode(object)
94
+ // set(data, forKey: key)
95
+ // }
96
+ //}
97
+ //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "3.2.0",
3
+ "version": "3.2.1-alpha.0",
4
4
  "license": "AGPL-3.0-only",
5
5
  "description": "OTA update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",
@@ -53,6 +53,7 @@
53
53
  "devDependencies": {
54
54
  "@capacitor/android": "^3.4.3",
55
55
  "@capacitor/core": "^3.4.3",
56
+ "@capacitor/cli": "^3.4.3",
56
57
  "@capacitor/docgen": "^0.1.1",
57
58
  "@capacitor/ios": "^3.4.3",
58
59
  "@ionic/eslint-config": "^0.3.0",