Skip to content

Commit 32de43b

Browse files
committed
Moved Foundation to FoundationCompat lib
1 parent b61aab0 commit 32de43b

File tree

7 files changed

+49
-18
lines changed

7 files changed

+49
-18
lines changed

Package.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ let package = Package(
66
name: "swift-aws-lambda-runtime",
77
products: [
88
.library(name: "AWSLambdaRuntime", targets: ["AWSLambdaRuntime"]),
9+
.library(name: "AWSLambdaRuntimeFoundationCompat", targets: ["AWSLambdaRuntimeFoundationCompat"]),
910
],
1011
dependencies: [
1112
.package(url: "https://github.com/apple/swift-nio.git", from: "2.8.0"),
@@ -17,12 +18,16 @@ let package = Package(
1718
.product(name: "Logging", package: "swift-log"),
1819
.product(name: "Backtrace", package: "swift-backtrace"),
1920
.product(name: "NIOHTTP1", package: "swift-nio"),
21+
]),
22+
.target(name: "AWSLambdaRuntimeFoundationCompat", dependencies: [
23+
.byName(name: "AWSLambdaRuntime"),
24+
.product(name: "NIO", package: "swift-nio"),
2025
.product(name: "NIOFoundationCompat", package: "swift-nio"),
2126
]),
22-
.testTarget(name: "AWSLambdaRuntimeTests", dependencies: ["AWSLambdaRuntime"]),
27+
.testTarget(name: "AWSLambdaRuntimeTests", dependencies: ["AWSLambdaRuntime", "AWSLambdaRuntimeFoundationCompat"]),
2328
// samples
2429
.target(name: "StringSample", dependencies: ["AWSLambdaRuntime"]),
25-
.target(name: "CodableSample", dependencies: ["AWSLambdaRuntime"]),
30+
.target(name: "CodableSample", dependencies: ["AWSLambdaRuntime", "AWSLambdaRuntimeFoundationCompat"]),
2631
// perf tests
2732
.target(name: "MockServer", dependencies: [
2833
.product(name: "NIOHTTP1", package: "swift-nio"),

Sources/AWSLambdaRuntime/Lambda.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ public enum Lambda {
4646

4747
// for testing and internal use
4848
@discardableResult
49-
internal static func run(configuration: Configuration = .init(), handler: ByteBufferLambdaHandler) -> Result<Int, Error> {
49+
public static func run(configuration: Configuration = .init(), handler: ByteBufferLambdaHandler) -> Result<Int, Error> {
5050
self.run(configuration: configuration, factory: { $0.makeSucceededFuture(handler) })
5151
}
5252

5353
// for testing and internal use
5454
@discardableResult
55-
internal static func run(configuration: Configuration = .init(), factory: @escaping (EventLoop) throws -> ByteBufferLambdaHandler) -> Result<Int, Error> {
55+
public static func run(configuration: Configuration = .init(), factory: @escaping (EventLoop) throws -> ByteBufferLambdaHandler) -> Result<Int, Error> {
5656
self.run(configuration: configuration, factory: { eventloop -> EventLoopFuture<ByteBufferLambdaHandler> in
5757
do {
5858
let handler = try factory(eventloop)

Sources/AWSLambdaRuntime/LambdaConfiguration.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import Logging
1717
import NIO
1818

1919
extension Lambda {
20-
internal struct Configuration: CustomStringConvertible {
21-
let general: General
22-
let lifecycle: Lifecycle
23-
let runtimeEngine: RuntimeEngine
20+
public struct Configuration: CustomStringConvertible {
21+
public let general: General
22+
public let lifecycle: Lifecycle
23+
public let runtimeEngine: RuntimeEngine
2424

25-
init() {
25+
public init() {
2626
self.init(general: .init(), lifecycle: .init(), runtimeEngine: .init())
2727
}
2828

@@ -32,19 +32,19 @@ extension Lambda {
3232
self.runtimeEngine = runtimeEngine ?? RuntimeEngine()
3333
}
3434

35-
struct General: CustomStringConvertible {
35+
public struct General: CustomStringConvertible {
3636
let logLevel: Logger.Level
3737

3838
init(logLevel: Logger.Level? = nil) {
3939
self.logLevel = logLevel ?? env("LOG_LEVEL").flatMap(Logger.Level.init) ?? .info
4040
}
4141

42-
var description: String {
42+
public var description: String {
4343
"\(General.self)(logLevel: \(self.logLevel))"
4444
}
4545
}
4646

47-
struct Lifecycle: CustomStringConvertible {
47+
public struct Lifecycle: CustomStringConvertible {
4848
let id: String
4949
let maxTimes: Int
5050
let stopSignal: Signal
@@ -56,12 +56,12 @@ extension Lambda {
5656
precondition(self.maxTimes >= 0, "maxTimes must be equal or larger than 0")
5757
}
5858

59-
var description: String {
59+
public var description: String {
6060
"\(Lifecycle.self)(id: \(self.id), maxTimes: \(self.maxTimes), stopSignal: \(self.stopSignal))"
6161
}
6262
}
6363

64-
struct RuntimeEngine: CustomStringConvertible {
64+
public struct RuntimeEngine: CustomStringConvertible {
6565
let ip: String
6666
let port: Int
6767
let keepAlive: Bool
@@ -78,12 +78,12 @@ extension Lambda {
7878
self.requestTimeout = requestTimeout ?? env("REQUEST_TIMEOUT").flatMap(Int64.init).flatMap { .milliseconds($0) }
7979
}
8080

81-
var description: String {
81+
public var description: String {
8282
"\(RuntimeEngine.self)(ip: \(self.ip), port: \(self.port), keepAlive: \(self.keepAlive), requestTimeout: \(String(describing: self.requestTimeout))"
8383
}
8484
}
8585

86-
var description: String {
86+
public var description: String {
8787
"\(Configuration.self)\n \(self.general))\n \(self.lifecycle)\n \(self.runtimeEngine)"
8888
}
8989
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftAWSLambdaRuntime open source project
4+
//
5+
// Copyright (c) 2017-2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import AWSLambdaRuntime
16+
import Foundation
17+
18+
extension Lambda.Context {
19+
var deadlineDate: Date {
20+
let secondsSinceEpoch = Double(Int64(bitPattern: self.deadline.rawValue)) / -1_000_000_000
21+
return Date(timeIntervalSince1970: secondsSinceEpoch)
22+
}
23+
}

Sources/AWSLambdaRuntime/Lambda+Codable.swift renamed to Sources/AWSLambdaRuntimeFoundationCompat/Lambda+Codable.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the SwiftAWSLambdaRuntime open source project
44
//
5-
// Copyright (c) 2017-2018 Apple Inc. and the SwiftAWSLambdaRuntime project authors
5+
// Copyright (c) 2017-2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -12,6 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
import AWSLambdaRuntime
1516
import class Foundation.JSONDecoder
1617
import class Foundation.JSONEncoder
1718
import NIO

Sources/CodableSample/main.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the SwiftAWSLambdaRuntime open source project
44
//
5-
// Copyright (c) 2017-2018 Apple Inc. and the SwiftAWSLambdaRuntime project authors
5+
// Copyright (c) 2017-2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -13,6 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import AWSLambdaRuntime
16+
import AWSLambdaRuntimeFoundationCompat
1617
import NIO
1718

1819
struct Request: Codable {

Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
@testable import AWSLambdaRuntime
16+
@testable import AWSLambdaRuntimeFoundationCompat
1617
import NIO
1718
import XCTest
1819

0 commit comments

Comments
 (0)