diff --git a/Package.resolved b/Package.resolved index ec02aa65..db862e1f 100644 --- a/Package.resolved +++ b/Package.resolved @@ -41,8 +41,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/netreconlab/Parse-Swift.git", "state" : { - "revision" : "10ec67c29050cc7e9d69bc59dda787ec5a145e75", - "version" : "5.10.0" + "revision" : "ef83e349e3c4d055f8fc96f9fa2e3ffdcddee616", + "version" : "5.10.1" } }, { diff --git a/Package.swift b/Package.swift index 158ae524..02ac7d0b 100644 --- a/Package.swift +++ b/Package.swift @@ -25,7 +25,7 @@ let package = Package( ), .package( url: "https://github.com/netreconlab/Parse-Swift.git", - .upToNextMajor(from: "5.10.0") + .upToNextMajor(from: "5.10.1") ) ], targets: [ diff --git a/Sources/ParseServerSwift/Extensions/Parse+Vapor.swift b/Sources/ParseServerSwift/Extensions/Parse+Vapor.swift index c23f8e74..5536e15d 100644 --- a/Sources/ParseServerSwift/Extensions/Parse+Vapor.swift +++ b/Sources/ParseServerSwift/Extensions/Parse+Vapor.swift @@ -11,6 +11,7 @@ import ParseSwift extension ParseHookFunctionRequest: Content {} extension ParseHookTriggerRequest: Content {} extension ParseHookResponse: Content {} + public extension ParseHookRequestable { /** Produce the set of options that should be used for subsequent `ParseHook` requests. @@ -53,3 +54,55 @@ public extension ParseHookRequestable { return try await self.hydrateUser(options: updatedOptions) } } + +extension ParseEncoder: ContentEncoder { + + public func encode( + _ encodable: E, + to body: inout ByteBuffer, + headers: inout HTTPHeaders + ) throws where E: Encodable { + try self.encode( + encodable, + to: &body, + headers: &headers, + userInfo: [:] + ) + } + + public func encode( + _ encodable: E, + to body: inout ByteBuffer, + headers: inout HTTPHeaders, + userInfo: [CodingUserInfoKey: Sendable] + ) throws where E: Encodable { + headers.contentType = .json + let jsonEncoder = User.getJSONEncoder() + + if !userInfo.isEmpty { + try body.writeBytes(JSONEncoder.custom( + dates: jsonEncoder.dateEncodingStrategy, + data: jsonEncoder.dataEncodingStrategy, + keys: jsonEncoder.keyEncodingStrategy, + format: jsonEncoder.outputFormatting, + floats: jsonEncoder.nonConformingFloatEncodingStrategy, + userInfo: jsonEncoder.userInfo.merging(userInfo) { $1 } + ).encode(encodable)) + } else { + if let parseEncodable = encodable as? ParseCloudTypeable { + try body.writeBytes(self.encode(parseEncodable, skipKeys: .cloud)) + } else if let parseEncodable = encodable as? ParseEncodable { + let skipKeys: SkipKeys + if !ParseSwift.configuration.isRequiringCustomObjectIds { + skipKeys = .object + } else { + skipKeys = .customObjectId + } + try body.writeBytes(self.encode(parseEncodable, skipKeys: skipKeys)) + } else { + try body.writeBytes(jsonEncoder.encode(encodable)) + } + + } + } +} diff --git a/Sources/ParseServerSwift/Parse.swift b/Sources/ParseServerSwift/Parse.swift index 4fa66f96..7ef219dc 100644 --- a/Sources/ParseServerSwift/Parse.swift +++ b/Sources/ParseServerSwift/Parse.swift @@ -47,7 +47,7 @@ func initializeServer(_ configuration: ParseServerConfiguration, app: Application) async throws { // Parse uses tailored encoders/decoders. These can be retrieved from any ParseObject - ContentConfiguration.global.use(encoder: User.getJSONEncoder(), for: .json) + ContentConfiguration.global.use(encoder: User.getEncoder(), for: .json) ContentConfiguration.global.use(decoder: User.getDecoder(), for: .json) guard let parseServerURL = URL(string: configuration.primaryParseServerURLString) else { diff --git a/Sources/ParseServerSwift/ParseServerConfiguration.swift b/Sources/ParseServerSwift/ParseServerConfiguration.swift index de47ede5..9b898e9d 100644 --- a/Sources/ParseServerSwift/ParseServerConfiguration.swift +++ b/Sources/ParseServerSwift/ParseServerConfiguration.swift @@ -35,7 +35,7 @@ public struct ParseServerConfiguration { var hooks = Hooks() var isTesting = false - var logger = Logger(label: "com.parseserverswift") + var logger = Logger(label: "com.parse-server-swift") /** Create a configuration for `ParseServerSwift`.