Skip to content

Commit 84e71e2

Browse files
author
Andrea Scuderi
committed
Add Dooc
1 parent 91157ca commit 84e71e2

11 files changed

+64
-9
lines changed

.spi.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version: 1
2+
builder:
3+
configs:
4+
- documentation_targets: [BreezeLambdaWebHook]

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ test:
2626
coverage:
2727
llvm-cov export $(TEST_PACKAGE) \
2828
--instr-profile=$(SWIFT_BIN_PATH)/codecov/default.profdata \
29-
--format=lcov > $(GITHUB_WORKSPACE)/lcov.info
29+
--format=lcov > $(GITHUB_WORKSPACE)/lcov.info
30+
31+
preview_docc_lambda_api:
32+
swift package --disable-sandbox preview-documentation --target BreezeLambdaWebHook
33+

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ let package = Package(
2222
.package(url: "https://github.com/andrea-scuderi/swift-aws-lambda-runtime.git", branch: "main"),
2323
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "0.5.0"),
2424
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.22.0"),
25-
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.6.3")
25+
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.6.3"),
26+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
2627
],
2728
targets: [
2829
.target(

Sources/BreezeLambdaWebHook/APIGatewayV2Response+Extensions.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ import struct AWSLambdaEvents.APIGatewayV2Response
1616
import HTTPTypes
1717
import class Foundation.JSONEncoder
1818

19+
/// Extensions for `APIGatewayV2Response` to simplify response creation
1920
public extension APIGatewayV2Response {
2021
private static let encoder = JSONEncoder()
2122

23+
/// Body of an error response
2224
struct BodyError: Codable {
2325
public let error: String
2426
}
2527

26-
/// init
28+
/// Initializer with body error and status code
2729
/// - Parameters:
2830
/// - error: Error
2931
/// - statusCode: HTTP Status Code
@@ -32,11 +34,16 @@ public extension APIGatewayV2Response {
3234
self.init(with: bodyError, statusCode: statusCode)
3335
}
3436

35-
/// init
37+
/// Initializer with decodable object, status code, and headers
3638
/// - Parameters:
3739
/// - object: Encodable Object
3840
/// - statusCode: HTTP Status Code
3941
/// - headers: HTTP Headers
42+
/// - Returns: APIGatewayV2Response
43+
///
44+
/// This initializer encodes the object to JSON and sets it as the body of the response.
45+
/// If encoding fails, it defaults to an empty JSON object.
46+
/// - Note: The `Content-Type` header is set to `application/json` by default.
4047
init<Output: Encodable>(
4148
with object: Output,
4249
statusCode: HTTPResponse.Status,

Sources/BreezeLambdaWebHook/BreezeHTTPClientConfig.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
import Logging
1616
import NIOCore
1717

18+
/// Error types for BreezeClientService
1819
public enum BreezeClientServiceError: Error {
19-
case invalidHttpClient
20+
/// The handler is invalid or not set
21+
case invalidHandler
2022
}
2123

24+
/// Configuration for the Breeze HTTP Client
2225
public struct BreezeHTTPClientConfig: Sendable {
2326
public init(timeout: TimeAmount, logger: Logger) {
2427
self.timeout = timeout

Sources/BreezeLambdaWebHook/BreezeLambdaWebHook.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,29 @@ import ServiceLifecycle
1818
import Logging
1919
import NIOCore
2020

21+
/// The Service that handles Breeze Lambda WebHook functionality.
2122
public struct BreezeLambdaWebHook<LambdaHandler: BreezeLambdaWebHookHandler>: Service {
2223

24+
/// The name of the service, used for logging and identification.
2325
public let name: String
26+
/// Configuration for the Breeze HTTP Client.
2427
public let config: BreezeHTTPClientConfig
2528

29+
/// Initializes a new instance of with the given name and configuration.
30+
/// - Parameters:
31+
/// - name: The name of the service.
32+
/// - config: Configuration for the Breeze HTTP Client.
2633
public init(name: String, config: BreezeHTTPClientConfig) {
2734
self.name = name
2835
self.config = config
2936
}
3037

38+
/// Runs the Breeze Lambda WebHook service.
39+
/// - Throws: An error if the service fails to start or run.
40+
///
41+
/// This method initializes the Breeze Lambda WebHook service and starts it,
42+
/// handling any errors that may occur during the process.
43+
/// It gracefully shuts down the service on termination signals.
3144
public func run() async throws {
3245
do {
3346
let lambdaService = BreezeLambdaWebHookService<LambdaHandler>(

Sources/BreezeLambdaWebHook/BreezeLambdaWebHookError.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import Foundation
1616

17+
/// Error types for BreezeLambdaWebHook
1718
public enum BreezeLambdaWebHookError: Error {
19+
/// The request is invalid or malformed
1820
case invalidRequest
1921
}

Sources/BreezeLambdaWebHook/BreezeLambdaWebHookHandler.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ public protocol BreezeLambdaWebHookHandler: LambdaHandler {
2323
func handle(_ event: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response
2424
}
2525

26+
/// A default implementation of the BreezeLambdaWebHookHandler protocol
2627
public extension BreezeLambdaWebHookHandler {
2728
var handler: String? {
2829
Lambda.env("_HANDLER")
2930
}
31+
3032
var httpClient: AsyncHTTPClient.HTTPClient {
3133
handlerContext.httpClient
3234
}

Sources/BreezeLambdaWebHook/BreezeLambdaWebHookService.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@ public struct HandlerContext: Sendable {
2727
}
2828
}
2929

30+
/// A service that runs a Breeze Lambda WebHook handler
31+
///
32+
/// This service is responsible for providing the necessary context and configuration to the handler,
33+
/// including the HTTP client and any other required resources.
34+
///
35+
/// - Note: This service is designed to be used with the Breeze Lambda WebHook framework, which allows for handling webhooks in a serverless environment.
3036
public actor BreezeLambdaWebHookService<Handler: BreezeLambdaWebHookHandler>: Service {
3137

3238
let config: BreezeHTTPClientConfig
3339
var handlerContext: HandlerContext?
3440
let httpClient: HTTPClient
35-
private var isStarted = false
3641

42+
/// Initialilizer with a configuration for the Breeze HTTP Client.
3743
public init(config: BreezeHTTPClientConfig) {
3844
self.config = config
3945
let timeout = HTTPClient.Configuration.Timeout(
@@ -47,8 +53,8 @@ public actor BreezeLambdaWebHookService<Handler: BreezeLambdaWebHookHandler>: Se
4753
)
4854
}
4955

56+
/// Runs the Breeze Lambda WebHook service.
5057
public func run() async throws {
51-
isStarted = true
5258
let handlerContext = HandlerContext(httpClient: httpClient)
5359
self.handlerContext = handlerContext
5460
let runtime = LambdaRuntime(body: handler)
@@ -61,9 +67,10 @@ public actor BreezeLambdaWebHookService<Handler: BreezeLambdaWebHookHandler>: Se
6167
}
6268
}
6369

70+
/// Handler function that processes incoming events.
6471
func handler(event: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response {
6572
guard let handlerContext = handlerContext else {
66-
throw BreezeClientServiceError.invalidHttpClient
73+
throw BreezeClientServiceError.invalidHandler
6774
}
6875
return try await Handler(handlerContext: handlerContext).handle(event, context: context)
6976
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"theme": {
3+
"color": {
4+
"header": "#DE5E44",
5+
"documentation-intro-title": "#FFFFFF",
6+
"documentation-intro-fill": "linear-gradient(30deg, #DE5E44, #A2331D)",
7+
"documentation-intro-accent": "#FFFFFF",
8+
"documentation-intro-eyebrow": "#FFFFFF",
9+
"link": "var(--color-header)"
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)