@@ -341,49 +341,6 @@ internal extension API.Command {
341
341
mapper: mapper)
342
342
}
343
343
344
- // MARK: Saving ParseObjects - Encodable
345
- static func saveCommand( object: T ) throws -> API . Command < T , PointerType > where T: Encodable {
346
- guard let objectable = object as? Objectable else {
347
- throw ParseError ( code: . unknownError, message: " Not able to cast to objectable. Not saving " )
348
- }
349
- if objectable. isSaved {
350
- return try updateCommand ( object: object)
351
- } else {
352
- return try createCommand ( object: object)
353
- }
354
- }
355
-
356
- // MARK: Saving ParseObjects - [Encodable] - private
357
- private static func createCommand( object: T ) throws -> API . Command < T , PointerType > where T: Encodable {
358
- guard var objectable = object as? Objectable else {
359
- throw ParseError ( code: . unknownError, message: " Not able to cast to objectable. Not saving " )
360
- }
361
- let mapper = { ( data: Data ) -> PointerType in
362
- let baseObjectable = try ParseCoding . jsonDecoder ( ) . decode ( BaseObjectable . self, from: data)
363
- objectable. objectId = baseObjectable. objectId
364
- return try objectable. toPointer ( )
365
- }
366
- return API . Command < T , PointerType > ( method: . POST,
367
- path: objectable. endpoint,
368
- body: object,
369
- mapper: mapper)
370
- }
371
-
372
- private static func updateCommand( object: T ) throws -> API . Command < T , PointerType > where T: Encodable {
373
- guard var objectable = object as? Objectable else {
374
- throw ParseError ( code: . unknownError, message: " Not able to cast to objectable. Not saving " )
375
- }
376
- let mapper = { ( data: Data ) -> PointerType in
377
- let baseObjectable = try ParseCoding . jsonDecoder ( ) . decode ( BaseObjectable . self, from: data)
378
- objectable. objectId = baseObjectable. objectId
379
- return try objectable. toPointer ( )
380
- }
381
- return API . Command < T , PointerType > ( method: . PUT,
382
- path: objectable. endpoint,
383
- body: object,
384
- mapper: mapper)
385
- }
386
-
387
344
// MARK: Saving ParseObjects - Encodable
388
345
static func saveCommand< T> ( _ object: T ) throws -> API . Command < T , PointerType > where T: Encodable {
389
346
guard let objectable = object as? Objectable else {
@@ -544,26 +501,26 @@ extension API.Command where T: ParseObject {
544
501
545
502
//This has been disabled, looking into getting it working in the future.
546
503
//It's only needed for sending batches of childObjects which currently isn't being used.
547
-
504
+ /*
548
505
// MARK: Batch - Child Objects
549
- extension API . Command where T : ParseType {
506
+ extension API.ChildCommand {
550
507
551
508
internal var data: Data? {
552
509
guard let body = body else { return nil }
553
510
return try? ParseCoding.jsonEncoder().encode(body)
554
511
}
555
512
556
- static func batch( commands: [ API . Command < T , PointerType > ] ,
557
- transaction: Bool ) -> RESTBatchCommandTypeEncodable < T > {
558
- let commands = commands. compactMap { ( command) -> API . Command < T , PointerType > ? in
513
+ static func batch(commands: [API.ChildCommand< PointerType>],
514
+ transaction: Bool) -> RESTBatchCommandTypeEncodable<ParseType > {
515
+ let commands = commands.compactMap { (command) -> API.ChildCommand< PointerType>? in
559
516
let path = ParseConfiguration.mountPath + command.path.urlComponent
560
517
guard let body = command.body else {
561
518
return nil
562
519
}
563
- return API . Command < T , PointerType > ( method: command. method, path: . any( path) ,
520
+ return API.ChildCommand< PointerType>(method: command.method, path: .any(path),
564
521
body: body, mapper: command.mapper)
565
522
}
566
- let bodies = commands. compactMap { ( command) -> ( body: T , command: API . Method ) ? in
523
+ let bodies = commands.compactMap { (command) -> (body: ParseType , command: API.Method)? in
567
524
guard let body = command.body else {
568
525
return nil
569
526
}
@@ -599,7 +556,7 @@ extension API.Command where T: ParseType {
599
556
return RESTBatchCommandTypeEncodable<T>(method: .POST, path: .batch, body: batchCommand, mapper: mapper)
600
557
}
601
558
}
602
-
559
+ */
603
560
// MARK: API.NonParseBodyCommand
604
561
internal extension API {
605
562
struct NonParseBodyCommand < T, U> : Encodable where T: Encodable {
@@ -718,4 +675,78 @@ internal extension API.NonParseBodyCommand {
718
675
}
719
676
}
720
677
}
721
- } // swiftlint:disable:this file_length
678
+ }
679
+ /*
680
+ // MARK: API.Command
681
+ internal extension API {
682
+ struct ChildCommand<U>: ParseType {
683
+ typealias ReturnType = U
684
+ let method: API.Method
685
+ let path: API.Endpoint
686
+ let body: ParseType?
687
+ let mapper: ((Data) throws -> U)
688
+ let params: [String: String?]?
689
+
690
+ init(method: API.Method,
691
+ path: API.Endpoint,
692
+ params: [String: String]? = nil,
693
+ body: ParseType? = nil,
694
+ mapper: @escaping ((Data) throws -> U)) {
695
+ self.method = method
696
+ self.path = path
697
+ self.body = body
698
+ self.mapper = mapper
699
+ self.params = params
700
+ }
701
+ }
702
+
703
+ enum CodingKeys: String, CodingKey {
704
+ case method, body, path
705
+ }
706
+ }
707
+
708
+ internal extension API.ChildCommand {
709
+ // MARK: Saving ParseObjects - Encodable
710
+ static func saveCommand(_ object: ParseType) throws -> API.ChildCommand<PointerType> {
711
+ guard let objectable = object as? Objectable else {
712
+ throw ParseError(code: .unknownError, message: "Not able to cast to objectable. Not saving")
713
+ }
714
+ if objectable.isSaved {
715
+ return try updateCommand(object)
716
+ } else {
717
+ return try createCommand(object)
718
+ }
719
+ }
720
+
721
+ // MARK: Saving ParseObjects - Encodable - private
722
+ private static func createCommand(_ object: ParseType) throws -> API.ChildCommand<PointerType> {
723
+ guard var objectable = object as? Objectable else {
724
+ throw ParseError(code: .unknownError, message: "Not able to cast to objectable. Not saving")
725
+ }
726
+ let mapper = { (data: Data) -> PointerType in
727
+ let baseObjectable = try ParseCoding.jsonDecoder().decode(BaseObjectable.self, from: data)
728
+ objectable.objectId = baseObjectable.objectId
729
+ return try objectable.toPointer()
730
+ }
731
+ return API.ChildCommand<PointerType>(method: .POST,
732
+ path: objectable.endpoint,
733
+ body: object,
734
+ mapper: mapper)
735
+ }
736
+
737
+ private static func updateCommand(_ object: ParseType) throws -> API.ChildCommand<PointerType> {
738
+ guard var objectable = object as? Objectable else {
739
+ throw ParseError(code: .unknownError, message: "Not able to cast to objectable. Not saving")
740
+ }
741
+ let mapper = { (data: Data) -> PointerType in
742
+ let baseObjectable = try ParseCoding.jsonDecoder().decode(BaseObjectable.self, from: data)
743
+ objectable.objectId = baseObjectable.objectId
744
+ return try objectable.toPointer()
745
+ }
746
+ return API.ChildCommand<PointerType>(method: .PUT,
747
+ path: objectable.endpoint,
748
+ body: object,
749
+ mapper: mapper)
750
+ }
751
+ }// swiftlint:disable:this file_length
752
+ */
0 commit comments