Skip to content

Commit cf9e29c

Browse files
committed
[UPDATE] fix payload with contenttype
1 parent 0654029 commit cf9e29c

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Sources/KurrentDB/Core/Event/EventData.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,54 +16,54 @@ public struct EventData: EventStoreEvent {
1616

1717
public private(set) var metadata: [String: String]
1818

19-
private init(id: UUID = .init(), eventType: String, payload: Payload, contentType _: ContentType, customMetadata: Data? = nil) {
19+
private init(id: UUID = .init(), eventType: String, payload: Payload, customMetadata: Data? = nil) {
2020
self.id = id
2121
self.eventType = eventType
2222
self.payload = payload
2323
self.customMetadata = customMetadata
2424

2525
metadata = [
26-
"content-type": payload.contentType,
26+
"content-type": payload.contentType.rawValue,
2727
"type": eventType,
2828
]
2929
}
3030

3131
@available(*, deprecated)
3232
public init(id: UUID = .init(), eventType: String, payload: Codable & Sendable, customMetadata: Data? = nil) {
33-
self.init(id: id, eventType: eventType, payload: .json(payload), contentType: .json, customMetadata: customMetadata)
33+
self.init(id: id, eventType: eventType, payload: .json(payload), customMetadata: customMetadata)
3434
}
3535

3636
public init(id: UUID = .init(), eventType: String, model: Codable & Sendable, customMetadata: Data? = nil) {
37-
self.init(id: id, eventType: eventType, payload: .json(model), contentType: .json, customMetadata: customMetadata)
37+
self.init(id: id, eventType: eventType, payload: .json(model), customMetadata: customMetadata)
3838
}
3939

4040
public init(id: UUID = .init(), eventType: String, data: Data, contentType: ContentType = .json, customMetadata: Data? = nil) {
41-
self.init(id: id, eventType: eventType, payload: .data(data), contentType: contentType, customMetadata: customMetadata)
41+
self.init(id: id, eventType: eventType, payload: .data(data, contentType), customMetadata: customMetadata)
4242
}
4343

44-
public init(id: UUID = .init(), eventType: String, bytes: [UInt8], customMetadata: Data? = nil) {
45-
self.init(id: id, eventType: eventType, payload: .data(.init(bytes)), contentType: .binary, customMetadata: customMetadata)
44+
public init(id: UUID = .init(), eventType: String, bytes: [UInt8], contentType: ContentType = .json, customMetadata: Data? = nil) {
45+
self.init(id: id, eventType: eventType, payload: .data(.init(bytes), contentType), customMetadata: customMetadata)
4646
}
4747
}
4848

4949
extension EventData {
5050
public enum Payload: Sendable {
51-
case data(Data)
51+
case data(Data, ContentType)
5252
case json(Codable & Sendable)
5353

54-
var contentType: String {
54+
var contentType: ContentType {
5555
switch self {
56-
case .data:
57-
"application/octet-stream"
56+
case let .data(_, contentType):
57+
contentType
5858
case .json:
59-
"application/json"
59+
ContentType.json
6060
}
6161
}
6262

6363
package var data: Data {
6464
get throws {
6565
switch self {
66-
case let .data(data):
66+
case let .data(data, _):
6767
data
6868
case let .json(json):
6969
try JSONEncoder().encode(json)

0 commit comments

Comments
 (0)