@@ -469,6 +469,7 @@ class Admin {
469
469
public enum SyncMode {
470
470
case pbs( String ) // partition based
471
471
case flx( [ String ] ) // flexible sync
472
+ case notSync
472
473
}
473
474
474
475
// MARK: RealmServer
@@ -815,6 +816,10 @@ public class RealmServer: NSObject {
815
816
}
816
817
}
817
818
819
+ if case . notSync = syncMode {
820
+ return clientAppId
821
+ }
822
+
818
823
app. secrets. post ( on: group, [
819
824
" name " : " BackingDB_uri " ,
820
825
" value " : " mongodb://localhost:26000 "
@@ -927,6 +932,8 @@ public class RealmServer: NSObject {
927
932
" delete " : true
928
933
] ]
929
934
] ) . get ( )
935
+ default :
936
+ fatalError ( )
930
937
}
931
938
_ = try app. services [ serviceId] . config. patch ( serviceConfig) . get ( )
932
939
@@ -1011,6 +1018,10 @@ public class RealmServer: NSObject {
1011
1018
return try createApp ( syncMode: . pbs( partitionKeyType) , types: types, persistent: persistent)
1012
1019
}
1013
1020
1021
+ @objc public func createNotSyncApp( ) throws -> AppId {
1022
+ return try createApp ( syncMode: . notSync, types: [ ] , persistent: false )
1023
+ }
1024
+
1014
1025
/// Delete all Apps created without `persistent: true`
1015
1026
@objc func deleteApps( ) throws {
1016
1027
for appId in appIds {
@@ -1028,10 +1039,7 @@ public class RealmServer: NSObject {
1028
1039
1029
1040
// Retrieve Atlas App Services AppId with ClientAppId using the Admin API
1030
1041
public func retrieveAppServerId( _ clientAppId: String ) throws -> String {
1031
- guard let session = session else {
1032
- fatalError ( )
1033
- }
1034
-
1042
+ let session = try XCTUnwrap ( session)
1035
1043
let appsListInfo = try session. apps. get ( ) . get ( )
1036
1044
guard let appsList = appsListInfo as? [ [ String : Any ] ] else {
1037
1045
throw URLError ( . badServerResponse)
@@ -1052,9 +1060,7 @@ public class RealmServer: NSObject {
1052
1060
}
1053
1061
1054
1062
public func retrieveSyncServiceId( appServerId: String ) throws -> String {
1055
- guard let session = session else {
1056
- fatalError ( )
1057
- }
1063
+ let session = try XCTUnwrap ( session)
1058
1064
let app = session. apps [ appServerId]
1059
1065
// Get all services
1060
1066
guard let syncServices = try app. services. get ( ) . get ( ) as? [ [ String : Any ] ] else {
@@ -1083,14 +1089,11 @@ public class RealmServer: NSObject {
1083
1089
}
1084
1090
}
1085
1091
1086
- public func isSyncEnabled( flexibleSync: Bool = false , appServerId: String , syncServiceId: String ) throws -> Bool {
1087
- let configOption = flexibleSync ? " flexible_sync " : " sync "
1088
- guard let session = session else {
1089
- fatalError ( )
1090
- }
1092
+ public func isSyncEnabled( appServerId: String , syncServiceId: String ) throws -> Bool {
1093
+ let session = try XCTUnwrap ( session)
1091
1094
let app = session. apps [ appServerId]
1092
1095
let response = try app. services [ syncServiceId] . config. get ( ) . get ( ) as? [ String : Any ]
1093
- guard let syncInfo = response ? [ configOption ] as? [ String : Any ] else {
1096
+ guard let syncInfo = response ? [ " flexible_sync " ] as? [ String : Any ] else {
1094
1097
return false
1095
1098
}
1096
1099
return syncInfo [ " state " ] as? String == " enabled "
@@ -1113,28 +1116,23 @@ public class RealmServer: NSObject {
1113
1116
return app. sync. config. put ( [ " development_mode_enabled " : true ] )
1114
1117
}
1115
1118
1116
- public func disableSync( flexibleSync: Bool = false , appServerId: String , syncServiceId: String )
1117
- -> Result < Any ? , Error > {
1118
- let configOption = flexibleSync ? " flexible_sync " : " sync "
1119
- guard let session = session else {
1120
- return . failure( URLError ( . unknown) )
1121
- }
1119
+ public func disableSync( appServerId: String , syncServiceId: String ) throws -> Any ? {
1120
+ let session = try XCTUnwrap ( session)
1122
1121
let app = session. apps [ appServerId]
1123
- return app. services [ syncServiceId] . config. patch ( [ configOption : [ " state " : " " ] ] )
1122
+ return app. services [ syncServiceId] . config. patch ( [ " flexible_sync " : [ " state " : " " ] ] )
1124
1123
}
1125
1124
1126
- public func enableSync( flexibleSync: Bool = false , appServerId: String , syncServiceId: String , syncServiceConfiguration: [ String : Any ] ) -> Result < Any ? , Error > {
1127
- let configOption = flexibleSync ? " flexible_sync " : " sync "
1125
+ public func enableSync( appServerId: String , syncServiceId: String , syncServiceConfiguration: [ String : Any ] ) -> Result < Any ? , Error > {
1128
1126
var syncConfig = syncServiceConfiguration
1129
1127
guard let session = session else {
1130
1128
return . failure( URLError ( . unknown) )
1131
1129
}
1132
1130
let app = session. apps [ appServerId]
1133
- guard var syncInfo = syncConfig [ configOption ] as? [ String : Any ] else {
1131
+ guard var syncInfo = syncConfig [ " flexible_sync " ] as? [ String : Any ] else {
1134
1132
return . failure( URLError ( . unknown) )
1135
1133
}
1136
1134
syncInfo [ " state " ] = " enabled "
1137
- syncConfig [ configOption ] = syncInfo
1135
+ syncConfig [ " flexible_sync " ] = syncInfo
1138
1136
return app. services [ syncServiceId] . config. patch ( syncConfig)
1139
1137
}
1140
1138
0 commit comments