Skip to content

Explicitly only use FoundationEssentials where possible #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions Examples/BackgroundTasks/Sources/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
//===----------------------------------------------------------------------===//

import AWSLambdaRuntime

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

struct BackgroundProcessingHandler: LambdaWithBackgroundProcessingHandler {
struct Input: Decodable {
Expand Down
4 changes: 4 additions & 0 deletions Sources/AWSLambdaRuntime/Context+Foundation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

import AWSLambdaRuntimeCore

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import struct Foundation.Date
#endif

extension LambdaContext {
var deadlineDate: Date {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@
//
//===----------------------------------------------------------------------===//

import Foundation
import NIOCore

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

// This is NIO's `NIOFoundationCompat` module which at the moment only adds `ByteBuffer` utility methods
// for Foundation's `Data` type.
//
Expand Down
7 changes: 6 additions & 1 deletion Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@
//
//===----------------------------------------------------------------------===//

import Foundation
import Logging
import NIOConcurrencyHelpers
import NIOCore

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

// We need `@unchecked` Sendable here, as `NIOLockedValueBox` does not understand `sending` today.
// We don't want to use `NIOLockedValueBox` here anyway. We would love to use Mutex here, but this
// sadly crashes the compiler today.
Expand Down
8 changes: 7 additions & 1 deletion Sources/MockServer/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@
//
//===----------------------------------------------------------------------===//

import Foundation
import Dispatch
import NIOCore
import NIOHTTP1
import NIOPosix

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

struct MockServer {
private let group: EventLoopGroup
private let host: String
Expand Down
7 changes: 6 additions & 1 deletion Tests/AWSLambdaRuntimeCoreTests/InvocationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
//
//===----------------------------------------------------------------------===//

import Foundation
import NIOHTTP1
import Testing

@testable import AWSLambdaRuntimeCore

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

@Suite
struct InvocationTest {
@Test
Expand Down
7 changes: 6 additions & 1 deletion Tests/AWSLambdaRuntimeCoreTests/LambdaMockClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
//===----------------------------------------------------------------------===//

import AWSLambdaRuntimeCore
import Foundation
import Logging
import NIOCore

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

struct LambdaMockWriter: LambdaRuntimeClientResponseStreamWriter {
var underlying: LambdaMockClient

Expand Down
9 changes: 8 additions & 1 deletion Tests/AWSLambdaRuntimeCoreTests/LambdaRequestIDTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
//
//===----------------------------------------------------------------------===//

import Foundation
import NIOCore
import Testing

@testable import AWSLambdaRuntimeCore

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

@Suite("LambdaRequestID tests")
struct LambdaRequestIDTest {
@Test
Expand Down Expand Up @@ -100,6 +105,7 @@ struct LambdaRequestIDTest {
#expect(buffer.readableBytes == readableBeforeRead)
}

#if os(macOS)
@Test
func testInitFromNSStringSuccess() {
let nsString = NSMutableString(capacity: 16)
Expand All @@ -121,6 +127,7 @@ struct LambdaRequestIDTest {
#expect(requestID?.uuidString == LambdaRequestID(uuidString: nsString as String)?.uuidString)
#expect(requestID?.uppercased == nsString as String)
}
#endif

@Test
func testUnparse() {
Expand Down
7 changes: 6 additions & 1 deletion Tests/AWSLambdaRuntimeCoreTests/LambdaRunLoopTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
//
//===----------------------------------------------------------------------===//

import Foundation
import Logging
import NIOCore
import Testing

@testable import AWSLambdaRuntimeCore

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

@Suite
struct LambdaRunLoopTests {
struct MockEchoHandler: StreamingLambdaHandler {
Expand Down
7 changes: 6 additions & 1 deletion Tests/AWSLambdaRuntimeCoreTests/MockLambdaServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@
//
//===----------------------------------------------------------------------===//

import Foundation // for JSON
import Logging
import NIOCore
import NIOHTTP1
import NIOPosix

@testable import AWSLambdaRuntimeCore

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

func withMockServer<Result>(
behaviour: some LambdaServerBehavior,
port: Int = 0,
Expand Down
4 changes: 4 additions & 0 deletions Tests/AWSLambdaRuntimeCoreTests/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
//
//===----------------------------------------------------------------------===//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

extension Date {
var millisSinceEpoch: Int64 {
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ Background tasks allow code to execute asynchronously after the main response ha
Here is an example of a minimal function that waits 10 seconds after it returned a response but before the handler returns.
```swift
import AWSLambdaRuntime
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

struct BackgroundProcessingHandler: LambdaWithBackgroundProcessingHandler {
struct Input: Decodable {
Expand Down
Loading