-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from NeedleInAJayStack/feature/linux-compat
Linux compatibility
- Loading branch information
Showing
18 changed files
with
705 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{ | ||
"pins" : [ | ||
{ | ||
"identity" : "async-http-client", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/swift-server/async-http-client.git", | ||
"state" : { | ||
"revision" : "5bee16a79922e3efcb5cea06ecd27e6f8048b56b", | ||
"version" : "1.13.1" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-atomics", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-atomics.git", | ||
"state" : { | ||
"revision" : "ff3d2212b6b093db7f177d0855adbc4ef9c5f036", | ||
"version" : "1.0.3" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-collections", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-collections.git", | ||
"state" : { | ||
"revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2", | ||
"version" : "1.0.4" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-crypto", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-crypto.git", | ||
"state" : { | ||
"revision" : "92a04c10fc5ce0504f8396aac7392126033e547c", | ||
"version" : "2.2.2" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-log", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-log.git", | ||
"state" : { | ||
"revision" : "6fe203dc33195667ce1759bf0182975e4653ba1c", | ||
"version" : "1.4.4" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-nio", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-nio.git", | ||
"state" : { | ||
"revision" : "e855380cb5234e96b760d93e0bfdc403e381e928", | ||
"version" : "2.45.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-nio-extras", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-nio-extras.git", | ||
"state" : { | ||
"revision" : "91dd2d61fb772e1311bb5f13b59266b579d77e42", | ||
"version" : "1.15.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-nio-http2", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-nio-http2.git", | ||
"state" : { | ||
"revision" : "d6656967f33ed8b368b38e4b198631fc7c484a40", | ||
"version" : "1.23.1" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-nio-ssl", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-nio-ssl.git", | ||
"state" : { | ||
"revision" : "4fb7ead803e38949eb1d6fabb849206a72c580f3", | ||
"version" : "2.23.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-nio-transport-services", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-nio-transport-services.git", | ||
"state" : { | ||
"revision" : "c0d9a144cfaec8d3d596aadde3039286a266c15c", | ||
"version" : "1.15.0" | ||
} | ||
} | ||
], | ||
"version" : 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,120 @@ | ||
# Swift Haystack | ||
|
||
An implementation of Project Haystack in Swift. | ||
An implementation of [Project Haystack](https://project-haystack.org/) in Swift. | ||
|
||
## Getting Started | ||
|
||
To use this package, add it to your `Package.swift` dependencies: | ||
|
||
```swift | ||
dependencies: [ | ||
.package(url: "https://github.com/NeedleInAJayStack/swift-haystack.git", from: "0.0.0"), | ||
], | ||
targets: [ | ||
.target( | ||
name: "MyTarget", | ||
dependencies: [ | ||
.product(name: "Haystack", package: "swift-haystack"), | ||
] | ||
), | ||
] | ||
``` | ||
|
||
You can then import and use the different libraries: | ||
|
||
```swift | ||
import Haystack | ||
|
||
func testGrid() throws -> Grid { | ||
return try ZincReader( | ||
""" | ||
ver:"3.0" foo:"bar" | ||
dis dis:"Equip Name", equip, siteRef, installed | ||
"RTU-1", M, @153c-699a HQ, 2005-06-01 | ||
"RTU-2", M, @153c-699b Library, 1997-07-12 | ||
""" | ||
).readGrid() | ||
} | ||
``` | ||
|
||
See below for available libraries and descriptions. | ||
|
||
## Available Packages | ||
|
||
### Haystack | ||
|
||
This contains the | ||
[Haystack type-system primitives](https://project-haystack.org/doc/docHaystack/Kinds) | ||
and utilities to interact with them. | ||
|
||
### HaystackClientDarwin | ||
|
||
A Darwin-only client driver for the | ||
[Haystack HTTP API](https://project-haystack.org/doc/docHaystack/HttpApi) that | ||
requires minimal dependencies. Use this if you are only deploying to MacOS, iOS, etc and want | ||
to reduce dependencies. | ||
|
||
Here's an example of how to use it: | ||
|
||
```swift | ||
import HaystackClientDarwin | ||
|
||
func client() throws -> Client { | ||
return try Client( | ||
baseUrl: "http://mydomain.com/api/", | ||
username: "username", | ||
password: "password" | ||
) | ||
} | ||
``` | ||
|
||
### HaystackClientNIO | ||
|
||
A cross-platform client driver for the | ||
[Haystack HTTP API](https://project-haystack.org/doc/docHaystack/HttpApi) that | ||
has larger dependency requirements. Use this if you are only deploying to Linux or if you | ||
are deploying to Darwin platforms and are willing to accept more dependencies. | ||
|
||
Here's an example of how to use it: | ||
|
||
```swift | ||
import HaystackClientNIO | ||
|
||
func client() throws -> Client { | ||
return try Client( | ||
baseUrl: "http://mydomain.com/api/", | ||
username: "username", | ||
password: "password", | ||
eventLoopGroup: MultiThreadedEventLoopGroup(numberOfThreads: 1) | ||
) | ||
} | ||
``` | ||
|
||
### HaystackClient | ||
|
||
This defines the main functionality of Haystack API clients. It should not be imported directly; | ||
its assets are imported automatically by `HaystackClientDarwin` or `HaystackClientNIO`. | ||
|
||
Once you create a client, you can use it to make requests: | ||
|
||
```swift | ||
func yesterdaysValues() async throws -> Grid { | ||
let client = ... | ||
|
||
// Open and authenticate. This must be called before requests can be made | ||
try await client.open() | ||
|
||
// Request the historical values for @28e7fb7d-e20316e0 | ||
let grid = try await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .yesterday) | ||
|
||
// Close the client session and log out | ||
try await client.close() | ||
|
||
return grid | ||
} | ||
``` | ||
|
||
## License | ||
|
||
This package is licensed under the Academic Free License 3.0 for maximum compatibility with | ||
Project Haystack itself. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
import CryptoKit | ||
import Crypto | ||
|
||
@available(macOS 10.15, *) | ||
enum AuthHash: String { | ||
case SHA512 = "SHA-512" | ||
case SHA256 = "SHA-256" | ||
|
||
var hash: any HashFunction.Type { | ||
switch self { | ||
case .SHA256: | ||
return CryptoKit.SHA256.self | ||
return Crypto.SHA256.self | ||
case .SHA512: | ||
return CryptoKit.SHA512.self | ||
return Crypto.SHA512.self | ||
} | ||
} | ||
} |
Oops, something went wrong.