Skip to content
Open
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
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
/.build
/.swiftpm
/.vscode
/.index-build
/Packages
/*.xcodeproj
Expand Down
5 changes: 5 additions & 0 deletions .sourcekit-lsp/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"swiftPM": {
"swiftSDK": "swift-6.2.2-RELEASE_wasm"
}
}
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.2.2
10 changes: 5 additions & 5 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 3 additions & 10 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -35,9 +32,5 @@ let package = Package(
name: "ComputeTests",
dependencies: ["Compute"]
),
],
swiftLanguageVersions: [
.version("6"),
.v5,
]
)
17 changes: 3 additions & 14 deletions Sources/Compute/Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Encodable>(
_ 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)
Expand Down
8 changes: 4 additions & 4 deletions Sources/Compute/Compute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions Sources/Compute/Concurrency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 1 addition & 19 deletions Sources/Compute/Console.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
25 changes: 0 additions & 25 deletions Sources/Compute/Fanout/FanoutClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// Created by Andrew Barba on 2/1/23.
//

import Foundation

public struct FanoutClient: Sendable {

public let service: String
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 0 additions & 12 deletions Sources/Compute/Fanout/FanoutMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,6 @@ extension FanoutMessage {
return try decoder.decode(type, from: data())
}

public func json<T: Sendable>() 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
Expand Down
4 changes: 1 addition & 3 deletions Sources/Compute/Fanout/IncomingRequest+Fanout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// Created by Andrew Barba on 2/1/23.
//

import Foundation

public enum FanoutRequestError: Error, Sendable {
case invalidSignature
}
Expand Down Expand Up @@ -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<EmptyJWTPayload>(token: token)
try jwt.verify(key: fanoutPublicKey)
}

Expand Down
2 changes: 0 additions & 2 deletions Sources/Compute/Fanout/OutgoingResponse+Fanout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// Created by Andrew Barba on 2/2/23.
//

import Foundation

extension OutgoingResponse {

public func meta(_ key: String, _ value: String?) -> Self {
Expand Down
18 changes: 0 additions & 18 deletions Sources/Compute/Fastly/FastlyLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) ?? ""
Expand Down
11 changes: 4 additions & 7 deletions Sources/Compute/Fastly/FastlyUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// Created by Andrew Barba on 1/12/22.
//

import Foundation

internal typealias WasiBufferReader = (
_ buffer: UnsafeMutablePointer<UInt8>?, _ maxLength: Int, _ length: inout Int
) -> Int32
Expand Down Expand Up @@ -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
// }
10 changes: 0 additions & 10 deletions Sources/Compute/Fetch/FetchRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 0 additions & 12 deletions Sources/Compute/Fetch/FetchResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@ extension FetchResponse {
return try await body.decode(type, decoder: decoder)
}

public func json<T: Sendable>() 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()
}
Expand Down
Loading