Skip to content
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
81 changes: 81 additions & 0 deletions Package.resolved

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

80 changes: 75 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,23 @@ let package = Package(
"HaystackClientNIO"
]
),
.library(
name: "HaystackServer",
targets: [
"HaystackServer"
]
),
.library(
name: "HaystackServerVapor",
targets: [
"HaystackServerVapor"
]
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "3.0.0"),
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.9.0")
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.9.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
],
targets: [
.target(
Expand Down Expand Up @@ -62,7 +75,21 @@ let package = Package(
.product(name: "AsyncHTTPClient", package: "async-http-client"),
]
),

.target(
name: "HaystackServer",
dependencies: [
"Haystack",
]
),
.target(
name: "HaystackServerVapor",
dependencies: [
"Haystack",
"HaystackServer",
.product(name: "Vapor", package: "vapor")
]
),

// Tests
.testTarget(
name: "HaystackTests",
Expand All @@ -80,6 +107,14 @@ let package = Package(
name: "HaystackClientDarwinIntegrationTests",
dependencies: ["HaystackClientDarwin"]
),
.testTarget(
name: "HaystackServerTests",
dependencies: ["HaystackServer"]
),
.testTarget(
name: "HaystackServerVaporTests",
dependencies: ["HaystackServerVapor", .product(name: "XCTVapor", package: "vapor")]
),
]
)
#else
Expand All @@ -97,10 +132,23 @@ let package = Package(
"HaystackClientNIO"
]
),
.library(
name: "HaystackServer",
targets: [
"HaystackServer"
]
),
.library(
name: "HaystackServerVapor",
targets: [
"HaystackServerVapor"
]
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "3.0.0"),
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.9.0")
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.9.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
],
targets: [
.target(
Expand All @@ -122,7 +170,21 @@ let package = Package(
.product(name: "AsyncHTTPClient", package: "async-http-client"),
]
),

.target(
name: "HaystackServer",
dependencies: [
"Haystack"
]
),
.target(
name: "HaystackServerVapor",
dependencies: [
"Haystack",
"HaystackServer",
.product(name: "Vapor", package: "vapor")
]
),

// Tests
.testTarget(
name: "HaystackTests",
Expand All @@ -136,6 +198,14 @@ let package = Package(
name: "HaystackClientNIOIntegrationTests",
dependencies: ["HaystackClientNIO"]
),
.testTarget(
name: "HaystackServerTests",
dependencies: ["HaystackServer"]
),
.testTarget(
name: "HaystackServerVaporTests",
dependencies: ["HaystackServerVapor", .product(name: "XCTVapor", package: "vapor")]
),
]
)
#endif
#endif
45 changes: 40 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ See below for available libraries and descriptions.

### Haystack

This contains the
This contains the
[Haystack type-system primitives](https://project-haystack.org/doc/docHaystack/Kinds)
and utilities to interact with them.

Expand Down Expand Up @@ -101,20 +101,55 @@ 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
}
```

### HaystackServerVapor

A server for the [Haystack HTTP API](https://project-haystack.org/doc/docHaystack/HttpApi) that uses
[Vapor](https://github.com/vapor/vapor). It's separated from the `HaystackServer` package so that clients may use
alternative server technologies if they choose, including Hummingbird or NIO directly.

It exposes a `HaystackRouteCollection` that can be registered on a Vapor
application:

```swift
let app = Application()
try app.register(collection: HaystackRouteCollection(delegate: ...))
```

The delegate is a protocol that can be implemented however the user sees fit, although the standard Haystack
implementation is defined in `HaystackServer`.

### HaystackServer

This defines the standard functionality and data processing of Haystack API servers, based on generic backing data
stores. In most cases, Haystack servers should use the `HaystackServer` class and customize storage behavior by
implementing the `RecordStore`, `HistoryStore`, and `WatchStore` protocols.

```swift
struct InfluxHistoryStore: HistoryStore {
// Define storage behavior here
...
}

let server = HaystackServer(
historyStore: InfluxHistoryStore(),
...
)
```

## License

This package is licensed under the Academic Free License 3.0 for maximum compatibility with
Expand Down
Loading