Skip to content

Commit 41ec01b

Browse files
committed
Moved Foundation to FoundationCompat lib
1 parent 593f039 commit 41ec01b

File tree

8 files changed

+52
-19
lines changed

8 files changed

+52
-19
lines changed

Package.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ let package = Package(
1010
products: [
1111
// core library
1212
.library(name: "AWSLambdaRuntime", targets: ["AWSLambdaRuntime"]),
13+
// foundaation utils for the core library
14+
.library(name: "AWSLambdaRuntimeFoundationCompat", targets: ["AWSLambdaRuntimeFoundationCompat"]),
1315
// common AWS events
1416
.library(name: "AWSLambdaEvents", targets: ["AWSLambdaEvents"]),
1517
// for testing only
@@ -25,20 +27,24 @@ let package = Package(
2527
.product(name: "Logging", package: "swift-log"),
2628
.product(name: "Backtrace", package: "swift-backtrace"),
2729
.product(name: "NIOHTTP1", package: "swift-nio"),
30+
]),
31+
.target(name: "AWSLambdaRuntimeFoundationCompat", dependencies: [
32+
.byName(name: "AWSLambdaRuntime"),
33+
.product(name: "NIO", package: "swift-nio"),
2834
.product(name: "NIOFoundationCompat", package: "swift-nio"),
2935
]),
30-
.testTarget(name: "AWSLambdaRuntimeTests", dependencies: ["AWSLambdaRuntime"]),
36+
.testTarget(name: "AWSLambdaRuntimeTests", dependencies: ["AWSLambdaRuntime", "AWSLambdaRuntimeFoundationCompat"]),
3137
.target(name: "AWSLambdaEvents", dependencies: []),
3238
.testTarget(name: "AWSLambdaEventsTests", dependencies: ["AWSLambdaEvents"]),
3339
// testing helper
3440
.target(name: "AWSLambdaTesting", dependencies: [
3541
"AWSLambdaRuntime",
3642
.product(name: "NIO", package: "swift-nio"),
3743
]),
38-
.testTarget(name: "AWSLambdaTestingTests", dependencies: ["AWSLambdaTesting"]),
44+
.testTarget(name: "AWSLambdaTestingTests", dependencies: ["AWSLambdaTesting", "AWSLambdaRuntimeFoundationCompat"]),
3945
// samples
4046
.target(name: "StringSample", dependencies: ["AWSLambdaRuntime"]),
41-
.target(name: "CodableSample", dependencies: ["AWSLambdaRuntime"]),
47+
.target(name: "CodableSample", dependencies: ["AWSLambdaRuntime", "AWSLambdaRuntimeFoundationCompat"]),
4248
// perf tests
4349
.target(name: "MockServer", dependencies: [
4450
.product(name: "NIOHTTP1", package: "swift-nio"),

Sources/AWSLambdaRuntime/Lambda.swift

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

6565
// for testing and internal use
6666
@discardableResult
67-
internal static func run(configuration: Configuration = .init(), handler: Handler) -> Result<Int, Error> {
67+
public static func run(configuration: Configuration = .init(), handler: Handler) -> Result<Int, Error> {
6868
self.run(configuration: configuration, factory: { $0.makeSucceededFuture(handler) })
6969
}
7070

7171
// for testing and internal use
7272
@discardableResult
73-
internal static func run(configuration: Configuration = .init(), factory: @escaping (EventLoop) throws -> Handler) -> Result<Int, Error> {
73+
public static func run(configuration: Configuration = .init(), factory: @escaping (EventLoop) throws -> Handler) -> Result<Int, Error> {
7474
self.run(configuration: configuration, factory: { eventloop -> EventLoopFuture<Handler> in
7575
do {
7676
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/AWSLambdaTesting/Lambda+Testing.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// @testable is used to access of internal functions
1818
#if DEBUG
1919
@testable import AWSLambdaRuntime
20+
@testable import AWSLambdaRuntimeFoundationCompat
2021
import Dispatch
2122
import Logging
2223
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)