Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ let package = Package(
dependencies: [
.byName(name: "AWSLambdaRuntime"),
.product(name: "NIO", package: "swift-nio"),
],
swiftSettings: [.swiftLanguageMode(.v5)]
]
),
.testTarget(
name: "AWSLambdaTestingTests",
dependencies: ["AWSLambdaTesting"],
swiftSettings: [.swiftLanguageMode(.v5)]
dependencies: [
.byName(name: "AWSLambdaTesting"),
.product(name: "Testing", package: "swift-testing"),
]
),
// for perf testing
.executableTarget(
Expand Down
3 changes: 1 addition & 2 deletions Sources/AWSLambdaRuntime/Context+Foundation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
//===----------------------------------------------------------------------===//

import AWSLambdaRuntimeCore

import struct Foundation.Date

extension LambdaContext {
extension NewLambdaContext {
var deadlineDate: Date {
let secondsSinceEpoch = Double(Int64(bitPattern: self.deadline.rawValue)) / -1_000_000_000
return Date(timeIntervalSince1970: secondsSinceEpoch)
Expand Down
119 changes: 0 additions & 119 deletions Sources/AWSLambdaRuntime/Lambda+Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,125 +24,6 @@ import class Foundation.JSONDecoder
import class Foundation.JSONEncoder
#endif

// MARK: - SimpleLambdaHandler Codable support

/// Implementation of `ByteBuffer` to `Event` decoding.
extension SimpleLambdaHandler where Event: Decodable {
@inlinable
public func decode(buffer: ByteBuffer) throws -> Event {
try self.decoder.decode(Event.self, from: buffer)
}
}

/// Implementation of `Output` to `ByteBuffer` encoding.
extension SimpleLambdaHandler where Output: Encodable {
@inlinable
public func encode(value: Output, into buffer: inout ByteBuffer) throws {
try self.encoder.encode(value, into: &buffer)
}
}

/// Default `ByteBuffer` to `Event` decoder using Foundation's `JSONDecoder`.
/// Advanced users who want to inject their own codec can do it by overriding these functions.
extension SimpleLambdaHandler where Event: Decodable {
public var decoder: LambdaCodableDecoder {
Lambda.defaultJSONDecoder
}
}

/// Default `Output` to `ByteBuffer` encoder using Foundation's `JSONEncoder`.
/// Advanced users who want to inject their own codec can do it by overriding these functions.
extension SimpleLambdaHandler where Output: Encodable {
public var encoder: LambdaCodableEncoder {
Lambda.defaultJSONEncoder
}
}

// MARK: - LambdaHandler Codable support

/// Implementation of `ByteBuffer` to `Event` decoding.
extension LambdaHandler where Event: Decodable {
@inlinable
public func decode(buffer: ByteBuffer) throws -> Event {
try self.decoder.decode(Event.self, from: buffer)
}
}

/// Implementation of `Output` to `ByteBuffer` encoding.
extension LambdaHandler where Output: Encodable {
@inlinable
public func encode(value: Output, into buffer: inout ByteBuffer) throws {
try self.encoder.encode(value, into: &buffer)
}
}

/// Default `ByteBuffer` to `Event` decoder using Foundation's `JSONDecoder`.
/// Advanced users who want to inject their own codec can do it by overriding these functions.
extension LambdaHandler where Event: Decodable {
public var decoder: LambdaCodableDecoder {
Lambda.defaultJSONDecoder
}
}

/// Default `Output` to `ByteBuffer` encoder using Foundation's `JSONEncoder`.
/// Advanced users who want to inject their own codec can do it by overriding these functions.
extension LambdaHandler where Output: Encodable {
public var encoder: LambdaCodableEncoder {
Lambda.defaultJSONEncoder
}
}

// MARK: - EventLoopLambdaHandler Codable support

/// Implementation of `ByteBuffer` to `Event` decoding.
extension EventLoopLambdaHandler where Event: Decodable {
@inlinable
public func decode(buffer: ByteBuffer) throws -> Event {
try self.decoder.decode(Event.self, from: buffer)
}
}

/// Implementation of `Output` to `ByteBuffer` encoding.
extension EventLoopLambdaHandler where Output: Encodable {
@inlinable
public func encode(value: Output, into buffer: inout ByteBuffer) throws {
try self.encoder.encode(value, into: &buffer)
}
}

/// Default `ByteBuffer` to `Event` decoder using Foundation's `JSONDecoder`.
/// Advanced users that want to inject their own codec can do it by overriding these functions.
extension EventLoopLambdaHandler where Event: Decodable {
public var decoder: LambdaCodableDecoder {
Lambda.defaultJSONDecoder
}
}

/// Default `Output` to `ByteBuffer` encoder using Foundation's `JSONEncoder`.
/// Advanced users that want to inject their own codec can do it by overriding these functions.
extension EventLoopLambdaHandler where Output: Encodable {
public var encoder: LambdaCodableEncoder {
Lambda.defaultJSONEncoder
}
}

public protocol LambdaCodableDecoder {
func decode<T: Decodable>(_ type: T.Type, from buffer: ByteBuffer) throws -> T
}

public protocol LambdaCodableEncoder {
func encode<T: Encodable>(_ value: T, into buffer: inout ByteBuffer) throws
}

extension Lambda {
fileprivate static let defaultJSONDecoder = JSONDecoder()
fileprivate static let defaultJSONEncoder = JSONEncoder()
}

extension JSONDecoder: LambdaCodableDecoder {}

extension JSONEncoder: LambdaCodableEncoder {}

extension JSONDecoder: AWSLambdaRuntimeCore.LambdaEventDecoder {}

@usableFromInline
Expand Down
8 changes: 4 additions & 4 deletions Sources/AWSLambdaRuntimeCore/ControlPlaneRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ package struct InvocationMetadata: Hashable {
package let clientContext: String?
package let cognitoIdentity: String?

package init(headers: HTTPHeaders) throws {
package init(headers: HTTPHeaders) throws(NewLambdaRuntimeError) {
guard let requestID = headers.first(name: AmazonHeaders.requestID), !requestID.isEmpty else {
throw LambdaRuntimeError.invocationMissingHeader(AmazonHeaders.requestID)
throw NewLambdaRuntimeError(code: .nextInvocationMissingHeaderRequestID)
}

guard let deadline = headers.first(name: AmazonHeaders.deadline),
let unixTimeInMilliseconds = Int64(deadline)
else {
throw LambdaRuntimeError.invocationMissingHeader(AmazonHeaders.deadline)
throw NewLambdaRuntimeError(code: .nextInvocationMissingHeaderDeadline)
}

guard let invokedFunctionARN = headers.first(name: AmazonHeaders.invokedFunctionARN) else {
throw LambdaRuntimeError.invocationMissingHeader(AmazonHeaders.invokedFunctionARN)
throw NewLambdaRuntimeError(code: .nextInvocationMissingHeaderInvokeFuctionARN)
}

self.requestID = requestID
Expand Down
94 changes: 0 additions & 94 deletions Sources/AWSLambdaRuntimeCore/DetachedTasks.swift

This file was deleted.

Loading
Loading