diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b528cb24..1319cd66 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,13 +5,13 @@ on: push jobs: build: runs-on: ubuntu-latest - container: swift:6.0 + container: swift:6.2.2 steps: - uses: actions/checkout@v4 - run: swift --version - - run: swift sdk install https://github.com/swiftwasm/swift/releases/download/swift-wasm-6.0.2-RELEASE/swift-wasm-6.0.2-RELEASE-wasm32-unknown-wasi.artifactbundle.zip --checksum 6ffedb055cb9956395d9f435d03d53ebe9f6a8d45106b979d1b7f53358e1dcb4 + - run: swift sdk install https://download.swift.org/swift-6.2.2-release/wasm-sdk/swift-6.2.2-RELEASE/swift-6.2.2-RELEASE_wasm.artifactbundle.tar.gz --checksum 128fa003e0cad624897c2b1d5f07cedf400e3c8bd851d304e57440b591cbe606 - - run: swift build --swift-sdk wasm32-unknown-wasi + - run: swift build --swift-sdk swift-6.2.2-RELEASE_wasm diff --git a/.gitignore b/.gitignore index fd87f2b8..e0b0fa92 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store /.build /.swiftpm +/.vscode /.index-build /Packages /*.xcodeproj diff --git a/.sourcekit-lsp/config.json b/.sourcekit-lsp/config.json new file mode 100644 index 00000000..300c9892 --- /dev/null +++ b/.sourcekit-lsp/config.json @@ -0,0 +1,5 @@ +{ + "swiftPM": { + "swiftSDK": "swift-6.2.2-RELEASE_wasm" + } +} diff --git a/.swift-version b/.swift-version new file mode 100644 index 00000000..ca063943 --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +6.2.2 diff --git a/Package.resolved b/Package.resolved index 22f05f53..fb384863 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,13 +1,13 @@ { - "originHash" : "855ce8eacf9681f7bdcd3af746f9a9ab64de63ba7cb67a7817c839d4dd767e17", + "originHash" : "950f0569a41e5c4ffe688ed19aa43ccc8b15bb3a945ab1499ffd2d0f44d58ee9", "pins" : [ { "identity" : "swift-asn1", "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-asn1.git", "state" : { - "revision" : "7faebca1ea4f9aaf0cda1cef7c43aecd2311ddf6", - "version" : "1.3.0" + "revision" : "810496cf121e525d660cd0ea89a758740476b85f", + "version" : "1.5.1" } }, { @@ -15,8 +15,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-crypto", "state" : { - "revision" : "ff0f781cf7c6a22d52957e50b104f5768b50c779", - "version" : "3.10.0" + "revision" : "6f70fa9eab24c1fd982af18c281c4525d05e3095", + "version" : "4.2.0" } } ], diff --git a/Package.swift b/Package.swift index 8a9054bd..6389cda5 100644 --- a/Package.swift +++ b/Package.swift @@ -1,20 +1,17 @@ -// swift-tools-version:5.10 +// swift-tools-version:6.2 import PackageDescription let package = Package( name: "Compute", platforms: [ - .macOS(.v11), - .iOS(.v14), - .tvOS(.v14), - .watchOS(.v7), + .macOS(.v15) ], products: [ .library(name: "Compute", targets: ["Compute"]) ], dependencies: [ - .package(url: "https://github.com/apple/swift-crypto", "1.0.0"..<"4.0.0") + .package(url: "https://github.com/apple/swift-crypto", from: "4.2.0") ], targets: [ .target( @@ -35,9 +32,5 @@ let package = Package( name: "ComputeTests", dependencies: ["Compute"] ), - ], - swiftLanguageVersions: [ - .version("6"), - .v5, ] ) diff --git a/Sources/Compute/Cache.swift b/Sources/Compute/Cache.swift index 55832c47..c95d4cf7 100644 --- a/Sources/Compute/Cache.swift +++ b/Sources/Compute/Cache.swift @@ -48,23 +48,12 @@ public struct Cache: Sendable { return try .init(trx) } - public static func getOrSet( - _ key: String, _ handler: () async throws -> ([String: Sendable], CachePolicy) - ) async throws -> Entry { - let trx = try await Fastly.Cache.getOrSet(key) { - let (json, cachePolicy) = try await handler() - let data = try JSONSerialization.data(withJSONObject: json) - return (.bytes(data.bytes), cachePolicy) - } - return try .init(trx) - } - - public static func getOrSet( - _ key: String, _ handler: () async throws -> ([Sendable], CachePolicy) + public static func getOrSet( + _ key: String, _ handler: () async throws -> (T, CachePolicy) ) async throws -> Entry { let trx = try await Fastly.Cache.getOrSet(key) { let (json, cachePolicy) = try await handler() - let data = try JSONSerialization.data(withJSONObject: json) + let data = try JSONEncoder().encode(json) return (.bytes(data.bytes), cachePolicy) } return try .init(trx) diff --git a/Sources/Compute/Compute.swift b/Sources/Compute/Compute.swift index 3a3a401d..1ed3e8c4 100644 --- a/Sources/Compute/Compute.swift +++ b/Sources/Compute/Compute.swift @@ -5,10 +5,10 @@ // Created by Andrew Barba on 1/11/22. // -@_exported import Foundation - -#if canImport(FoundationNetworking) - @_exported import FoundationNetworking +#if canImport(FoundationEssentials) + @_exported import FoundationEssentials +#else + @_exported import Foundation #endif @MainActor diff --git a/Sources/Compute/Concurrency.swift b/Sources/Compute/Concurrency.swift index 6cc08358..2919492a 100644 --- a/Sources/Compute/Concurrency.swift +++ b/Sources/Compute/Concurrency.swift @@ -5,12 +5,8 @@ // Created by Andrew Barba on 11/27/22. // -extension Data: @unchecked Sendable {} - -extension URL: @unchecked Sendable {} - #if !arch(wasm32) - extension HTTPURLResponse: @unchecked Sendable {} +extension HTTPURLResponse: @unchecked Sendable {} #endif extension Task where Success == Never, Failure == Never { diff --git a/Sources/Compute/Console.swift b/Sources/Compute/Console.swift index 64869040..96a06a74 100644 --- a/Sources/Compute/Console.swift +++ b/Sources/Compute/Console.swift @@ -25,24 +25,6 @@ public struct Console: Sendable { } public func error(_ items: Any...) { - var errorStream = StandardErrorOutputStream() - let text = items.map { String(describing: $0) }.joined(separator: " ") - if let prefix = prefix { - print(prefix, text, to: &errorStream) - } else { - print(text, to: &errorStream) - } - } -} - -private struct StandardErrorOutputStream: TextOutputStream { - - private let stderr = FileHandle.standardError - - func write(_ string: String) { - guard let data = string.data(using: .utf8) else { - return - } - stderr.write(data) + log("error:", items) } } diff --git a/Sources/Compute/Fanout/FanoutClient.swift b/Sources/Compute/Fanout/FanoutClient.swift index 59179211..017e510e 100644 --- a/Sources/Compute/Fanout/FanoutClient.swift +++ b/Sources/Compute/Fanout/FanoutClient.swift @@ -5,8 +5,6 @@ // Created by Andrew Barba on 2/1/23. // -import Foundation - public struct FanoutClient: Sendable { public let service: String @@ -54,29 +52,6 @@ public struct FanoutClient: Sendable { let content = try encoder.encode(value) return try await publish(content, to: channel) } - - @discardableResult - public func publish(_ json: Any, to channel: String) async throws -> FetchResponse { - let data = try JSONSerialization.data(withJSONObject: json) - let content = String(data: data, encoding: .utf8) - return try await publish(content, to: channel) - } - - @discardableResult - public func publish(_ jsonObject: [String: Any], to channel: String) async throws - -> FetchResponse - { - let data = try JSONSerialization.data(withJSONObject: jsonObject) - let content = String(data: data, encoding: .utf8) - return try await publish(content, to: channel) - } - - @discardableResult - public func publish(_ jsonArray: [Any], to channel: String) async throws -> FetchResponse { - let data = try JSONSerialization.data(withJSONObject: jsonArray) - let content = String(data: data, encoding: .utf8) - return try await publish(content, to: channel) - } } extension FanoutClient { diff --git a/Sources/Compute/Fanout/FanoutMessage.swift b/Sources/Compute/Fanout/FanoutMessage.swift index fb749d3d..1658a7b6 100644 --- a/Sources/Compute/Fanout/FanoutMessage.swift +++ b/Sources/Compute/Fanout/FanoutMessage.swift @@ -74,18 +74,6 @@ extension FanoutMessage { return try decoder.decode(type, from: data()) } - public func json() throws -> T { - return try JSONSerialization.jsonObject(with: data()) as! T - } - - public func jsonObject() throws -> [String: Sendable] { - return try json() - } - - public func jsonArray() throws -> [Sendable] { - return try json() - } - public func data() throws -> Data { guard let data = content.data(using: .utf8) else { throw FanoutMessageError.invalidFormat diff --git a/Sources/Compute/Fanout/IncomingRequest+Fanout.swift b/Sources/Compute/Fanout/IncomingRequest+Fanout.swift index 02e4f64a..4c4aa7ce 100644 --- a/Sources/Compute/Fanout/IncomingRequest+Fanout.swift +++ b/Sources/Compute/Fanout/IncomingRequest+Fanout.swift @@ -5,8 +5,6 @@ // Created by Andrew Barba on 2/1/23. // -import Foundation - public enum FanoutRequestError: Error, Sendable { case invalidSignature } @@ -40,7 +38,7 @@ extension IncomingRequest { guard let token = headers[.gripSig] else { throw FanoutRequestError.invalidSignature } - let jwt = try JWT(token: token) + let jwt = try JWT(token: token) try jwt.verify(key: fanoutPublicKey) } diff --git a/Sources/Compute/Fanout/OutgoingResponse+Fanout.swift b/Sources/Compute/Fanout/OutgoingResponse+Fanout.swift index a80d26a4..1b6f09dc 100644 --- a/Sources/Compute/Fanout/OutgoingResponse+Fanout.swift +++ b/Sources/Compute/Fanout/OutgoingResponse+Fanout.swift @@ -5,8 +5,6 @@ // Created by Andrew Barba on 2/2/23. // -import Foundation - extension OutgoingResponse { public func meta(_ key: String, _ value: String?) -> Self { diff --git a/Sources/Compute/Fastly/FastlyLogger.swift b/Sources/Compute/Fastly/FastlyLogger.swift index 3a0d5414..c6d956ec 100644 --- a/Sources/Compute/Fastly/FastlyLogger.swift +++ b/Sources/Compute/Fastly/FastlyLogger.swift @@ -37,24 +37,6 @@ extension Fastly { return try write(data) } - @discardableResult - public func write( - _ jsonObject: [String: Any], - options: JSONSerialization.WritingOptions = [.sortedKeys] - ) throws -> Int { - let data = try JSONSerialization.data(withJSONObject: jsonObject, options: options) - return try write(data) - } - - @discardableResult - public func write( - _ jsonArray: [Any], - options: JSONSerialization.WritingOptions = [.sortedKeys] - ) throws -> Int { - let data = try JSONSerialization.data(withJSONObject: jsonArray, options: options) - return try write(data) - } - @discardableResult public func write(_ data: Data) throws -> Int { let text = String(bytes: data, encoding: .utf8) ?? "" diff --git a/Sources/Compute/Fastly/FastlyUtils.swift b/Sources/Compute/Fastly/FastlyUtils.swift index 49056699..2ff25bda 100644 --- a/Sources/Compute/Fastly/FastlyUtils.swift +++ b/Sources/Compute/Fastly/FastlyUtils.swift @@ -5,8 +5,6 @@ // Created by Andrew Barba on 1/12/22. // -import Foundation - internal typealias WasiBufferReader = ( _ buffer: UnsafeMutablePointer?, _ maxLength: Int, _ length: inout Int ) -> Int32 @@ -96,8 +94,7 @@ extension DataProtocol { } } -extension CharacterSet { - - static let javascriptURLAllowed: CharacterSet = - .alphanumerics.union(.init(charactersIn: "-_.!~*'()")) // as per RFC 3986 -} +// extension CharacterSet { +// static let javascriptURLAllowed: CharacterSet = +// .alphanumerics.union(.init(charactersIn: "-_.!~*'()")) // as per RFC 3986 +// } diff --git a/Sources/Compute/Fetch/FetchRequest.swift b/Sources/Compute/Fetch/FetchRequest.swift index 422460b2..058f642c 100644 --- a/Sources/Compute/Fetch/FetchRequest.swift +++ b/Sources/Compute/Fetch/FetchRequest.swift @@ -116,16 +116,6 @@ extension FetchRequest { return Body.json(data) } - public static func json(_ jsonObject: [String: Any]) throws -> Body { - let data = try JSONSerialization.data(withJSONObject: jsonObject) - return Body.json(data) - } - - public static func json(_ jsonArray: [Any]) throws -> Body { - let data = try JSONSerialization.data(withJSONObject: jsonArray) - return Body.json(data) - } - public var defaultContentType: String? { switch self { case .json: diff --git a/Sources/Compute/Fetch/FetchResponse.swift b/Sources/Compute/Fetch/FetchResponse.swift index 3b79bf34..957acb3e 100644 --- a/Sources/Compute/Fetch/FetchResponse.swift +++ b/Sources/Compute/Fetch/FetchResponse.swift @@ -41,18 +41,6 @@ extension FetchResponse { return try await body.decode(type, decoder: decoder) } - public func json() async throws -> T { - return try await body.json() - } - - public func jsonObject() async throws -> [String: Sendable] { - return try await body.jsonObject() - } - - public func jsonArray() async throws -> [Sendable] { - return try await body.jsonArray() - } - public func formValues() async throws -> HTTPSearchParams { return try await body.formValues() } diff --git a/Sources/Compute/JWT/JWT.swift b/Sources/Compute/JWT/JWT.swift index c11ab4ad..a520b60f 100644 --- a/Sources/Compute/JWT/JWT.swift +++ b/Sources/Compute/JWT/JWT.swift @@ -5,20 +5,52 @@ // Created by Andrew Barba on 11/27/22. // -public struct JWT: Sendable { +public protocol JWTPayload: Sendable, Codable { + var iat: TimeInterval? { get set } + var exp: TimeInterval? { get set } + var sub: String? { get set } + var iss: String? { get set } + var jti: String? { get set } +} + +public enum JWTAlgorithm: String, Codable, Sendable { + case hs256 = "HS256" + case hs384 = "HS384" + case hs512 = "HS512" + case es256 = "ES256" + case es384 = "ES384" + case es512 = "ES512" +} + +public struct JWTHeader: Sendable, Codable { + public let alg: JWTAlgorithm + public let typ: String +} + +public struct EmptyJWTPayload: JWTPayload { + public var iat: TimeInterval? + public var exp: TimeInterval? + public var sub: String? + public var iss: String? + public var jti: String? + + public init() {} +} + +public struct JWT: Sendable, Codable { public let token: String - public let algorithm: Algorithm + public let algorithm: JWTAlgorithm - public let header: [String: Sendable] + public let header: JWTHeader - public let payload: [String: Sendable] + public let payload: Payload public let signature: Data public func claim(name: String) -> Claim { - return .init(value: payload[name]) + return .init(value: payload)[name] } public subscript(key: String) -> Claim { @@ -33,15 +65,10 @@ public struct JWT: Sendable { } // Parse header - let header = try decodeJWTPart(parts[0]) - - // Parse algorithm - guard let alg = header["alg"] as? String, let algorithm = Algorithm(rawValue: alg) else { - throw JWTError.unsupportedAlgorithm - } + let header: JWTHeader = try decodeJWTPart(parts[0]) // Parse payload - let payload = try decodeJWTPart(parts[1]) + let payload: Payload = try decodeJWTPart(parts[1]) // Parse signature let signature = try base64UrlDecode(parts[2]) @@ -49,47 +76,42 @@ public struct JWT: Sendable { self.header = header self.payload = payload self.signature = signature - self.algorithm = algorithm + self.algorithm = header.alg self.token = token } public init( - claims: [String: Sendable], + claims: Payload, secret: String, - algorithm: Algorithm = .hs256, + algorithm: JWTAlgorithm = .hs256, issuedAt: Date = .init(), expiresAt: Date? = nil, issuer: String? = nil, subject: String? = nil, identifier: String? = nil ) throws { - let header: [String: Sendable] = [ - "alg": algorithm.rawValue, - "typ": "JWT", - ] + let header = JWTHeader(alg: algorithm, typ: "JWT") - var properties: [String: Sendable] = [ - "iat": floor(issuedAt.timeIntervalSince1970) - ] + var payload = claims + + payload.iat = issuedAt.timeIntervalSince1970.rounded(.down) if let expiresAt { - properties["exp"] = ceil(expiresAt.timeIntervalSince1970) + payload.exp = expiresAt.timeIntervalSince1970.rounded(.up) } if let subject { - properties["sub"] = subject + payload.sub = subject } if let issuer { - properties["iss"] = issuer + payload.iss = issuer } if let identifier { - properties["jti"] = identifier + payload.jti = identifier } - let payload = claims.merging(properties, uniquingKeysWith: { $1 }) - let _header = try encodeJWTPart(header) let _payload = try encodeJWTPart(payload) @@ -151,7 +173,7 @@ extension JWT { @discardableResult public func verify( key: String, - using algorithm: Algorithm? = nil, + using algorithm: JWTAlgorithm? = nil, issuer: String? = nil, subject: String? = nil, expiration: Bool = true @@ -182,31 +204,20 @@ extension JWT { } } -extension JWT { - public enum Algorithm: String, Sendable { - case hs256 = "HS256" - case hs384 = "HS384" - case hs512 = "HS512" - case es256 = "ES256" - case es384 = "ES384" - case es512 = "ES512" - } -} - -private func decodeJWTPart(_ value: String) throws -> [String: Sendable] { +private func decodeJWTPart(_ value: String) throws -> T { let bodyData = try base64UrlDecode(value) - guard let json = try JSONSerialization.jsonObject(with: bodyData) as? [String: Sendable] else { + guard let json = try? JSONDecoder().decode(T.self, from: bodyData) else { throw JWTError.invalidJSON } return json } -private func encodeJWTPart(_ value: [String: Any]) throws -> String { - let data = try JSONSerialization.data(withJSONObject: value, options: [.sortedKeys]) +private func encodeJWTPart(_ value: T) throws -> String { + let data = try JSONEncoder().encode(value) return try base64UrlEncode(data) } -private func hmacSignature(_ input: String, secret: String, using algorithm: JWT.Algorithm) throws +private func hmacSignature(_ input: String, secret: String, using algorithm: JWTAlgorithm) throws -> Data { switch algorithm { @@ -226,7 +237,7 @@ private func hmacSignature(_ input: String, secret: String, using algorithm: JWT } private func verifySignature( - _ input: String, signature: Data, key: String, using algorithm: JWT.Algorithm + _ input: String, signature: Data, key: String, using algorithm: JWTAlgorithm ) throws { let verified: Bool switch algorithm { @@ -254,7 +265,7 @@ private func base64UrlDecode(_ value: String) throws -> Data { .replacingOccurrences(of: "-", with: "+") .replacingOccurrences(of: "_", with: "/") let length = Double(base64.lengthOfBytes(using: String.Encoding.utf8)) - let requiredLength = 4 * ceil(length / 4.0) + let requiredLength = 4 * (length / 4.0).rounded(.up) let paddingLength = requiredLength - length if paddingLength > 0 { let padding = "".padding(toLength: Int(paddingLength), withPad: "=", startingAt: 0) diff --git a/Sources/Compute/KVStore.swift b/Sources/Compute/KVStore.swift index 95116797..8dc41e73 100644 --- a/Sources/Compute/KVStore.swift +++ b/Sources/Compute/KVStore.swift @@ -70,16 +70,6 @@ extension KVStore { try await put(key, data: data) } - public func put(_ key: String, jsonObject: [String: Any]) async throws { - let data = try JSONSerialization.data(withJSONObject: jsonObject) - try await put(key, data: data) - } - - public func put(_ key: String, jsonArray: [Any]) async throws { - let data = try JSONSerialization.data(withJSONObject: jsonArray) - try await put(key, data: data) - } - public func put(_ key: String, value: T, encoder: JSONEncoder = .init()) async throws where T: Encodable { let data = try encoder.encode(value) diff --git a/Sources/Compute/OutgoingResponse.swift b/Sources/Compute/OutgoingResponse.swift index 7b1d00ff..f764516e 100644 --- a/Sources/Compute/OutgoingResponse.swift +++ b/Sources/Compute/OutgoingResponse.swift @@ -124,18 +124,6 @@ extension OutgoingResponse { try await sendAndClose() } - public func send(_ jsonObject: [String: Sendable]) async throws { - try defaultContentType("application/json") - try await body.write(jsonObject) - try await sendAndClose() - } - - public func send(_ jsonArray: [Sendable]) async throws { - try defaultContentType("application/json") - try await body.write(jsonArray) - try await sendAndClose() - } - public func send(_ text: String) async throws { try defaultContentType("text/plain") let data = text.data(using: .utf8) ?? .init() @@ -229,20 +217,6 @@ extension OutgoingResponse { return self } - @discardableResult - public func write(_ jsonObject: [String: Sendable]) async throws -> Self { - try await sendAndStream() - try await body.write(jsonObject) - return self - } - - @discardableResult - public func write(_ jsonArray: [Sendable]) async throws -> Self { - try await sendAndStream() - try await body.write(jsonArray) - return self - } - @discardableResult public func write(_ text: String) async throws -> Self { try await sendAndStream() @@ -417,9 +391,9 @@ extension OutgoingResponse { _ options: [CookieOption] ) -> Self { let encodedName = - name.addingPercentEncoding(withAllowedCharacters: .javascriptURLAllowed) ?? name + name.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? name let encodedValue = - value.addingPercentEncoding(withAllowedCharacters: .javascriptURLAllowed) ?? value + value.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? value let parts = ["\(encodedName)=\(encodedValue)"] + options.map(\.value) let header = parts.joined(separator: "; ") headers.append(.setCookie, header) diff --git a/Sources/Compute/ReadableBody/ReadableBody+Data.swift b/Sources/Compute/ReadableBody/ReadableBody+Data.swift index bcf6d12d..d85f4b3d 100644 --- a/Sources/Compute/ReadableBody/ReadableBody+Data.swift +++ b/Sources/Compute/ReadableBody/ReadableBody+Data.swift @@ -38,18 +38,6 @@ return try decoder.decode(type, from: data) } - func json() async throws -> T { - return try JSONSerialization.jsonObject(with: data) as! T - } - - func jsonObject() async throws -> [String: Sendable] { - return try await json() - } - - func jsonArray() async throws -> [Sendable] { - return try await json() - } - func formValues() async throws -> HTTPSearchParams { let query = try await text() let components = URLComponents(string: "?\(query)") diff --git a/Sources/Compute/ReadableBody/ReadableBody+Wasi.swift b/Sources/Compute/ReadableBody/ReadableBody+Wasi.swift index 023a4172..a39fc456 100644 --- a/Sources/Compute/ReadableBody/ReadableBody+Wasi.swift +++ b/Sources/Compute/ReadableBody/ReadableBody+Wasi.swift @@ -50,19 +50,6 @@ extension ReadableWasiBody { return try decoder.decode(type, from: data) } - func json() async throws -> T { - let data = try await data() - return try JSONSerialization.jsonObject(with: data) as! T - } - - func jsonObject() async throws -> [String: Sendable] { - return try await json() - } - - func jsonArray() async throws -> [Sendable] { - return try await json() - } - func formValues() async throws -> HTTPSearchParams { let query = try await text() let components = URLComponents(string: "?\(query)") diff --git a/Sources/Compute/ReadableBody/ReadableBody.swift b/Sources/Compute/ReadableBody/ReadableBody.swift index 911baaa1..992f23bd 100644 --- a/Sources/Compute/ReadableBody/ReadableBody.swift +++ b/Sources/Compute/ReadableBody/ReadableBody.swift @@ -17,12 +17,6 @@ public protocol ReadableBody: Actor, Sendable { func decode(_ type: T.Type, decoder: JSONDecoder) async throws -> T where T: Decodable - func json() async throws -> T - - func jsonObject() async throws -> [String: Sendable] - - func jsonArray() async throws -> [Sendable] - func formValues() async throws -> HTTPSearchParams func text() async throws -> String diff --git a/Sources/Compute/WritableBody.swift b/Sources/Compute/WritableBody.swift index 0bf3e80b..387a9b17 100644 --- a/Sources/Compute/WritableBody.swift +++ b/Sources/Compute/WritableBody.swift @@ -57,22 +57,6 @@ extension WritableBody { try await write(data) } - public func write( - _ jsonObject: [String: Sendable], - options: JSONSerialization.WritingOptions = [.sortedKeys] - ) async throws { - let data = try JSONSerialization.data(withJSONObject: jsonObject, options: options) - try await write(data) - } - - public func write( - _ jsonArray: [Sendable], - options: JSONSerialization.WritingOptions = [.sortedKeys] - ) async throws { - let data = try JSONSerialization.data(withJSONObject: jsonArray, options: options) - try await write(data) - } - public func write(_ text: String) async throws { let data = text.data(using: .utf8) ?? .init() try await write(data) diff --git a/Sources/ComputeDemo/main.swift b/Sources/ComputeDemo/main.swift index c9868716..f773581e 100644 --- a/Sources/ComputeDemo/main.swift +++ b/Sources/ComputeDemo/main.swift @@ -6,17 +6,7 @@ private let token = """ try await onIncomingRequest { req, res in - let jwt = try JWT(token: token) - let verified: Bool - do { - try jwt.verify(key: fanoutPublicKey, issuer: "fastly", expiration: false) - verified = true - } catch { - verified = false - } - try await res.send([ - "verified": verified, - "signature": jwt.signature.toHexString(), - "jwt": JWT(claims: ["a": "b"], secret: "hello-world").token, - ]) + let jwt = try JWT(token: token) + try jwt.verify(key: fanoutPublicKey, issuer: "fastly", expiration: false) + try await res.send(jwt) }