Skip to content

Commit 8ae4978

Browse files
refactor: Formats package
1 parent 290aaef commit 8ae4978

File tree

72 files changed

+1237
-1256
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1237
-1256
lines changed

Package.swift

Lines changed: 202 additions & 202 deletions
Large diffs are not rendered by default.

Sources/Haystack/API/API.swift

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
public protocol API {
2-
32
/// Closes the current authentication session.
43
///
54
/// https://project-haystack.org/doc/docHaystack/Ops#close
6-
func close() async throws -> Void
7-
5+
func close() async throws
6+
87
/// Queries basic information about the server
98
///
109
/// https://project-haystack.org/doc/docHaystack/Ops#about
1110
func about() async throws -> Grid
12-
11+
1312
/// Queries def dicts from the current namespace
1413
///
1514
/// https://project-haystack.org/doc/docHaystack/Ops#defs
@@ -19,7 +18,7 @@ public protocol API {
1918
/// - limit: The maximum number of defs to return in response
2019
/// - Returns: A grid with the dict representation of each def
2120
func defs(filter: String?, limit: Number?) async throws -> Grid
22-
21+
2322
/// Queries lib defs from current namspace
2423
///
2524
/// https://project-haystack.org/doc/docHaystack/Ops#libs
@@ -29,7 +28,7 @@ public protocol API {
2928
/// - limit: The maximum number of defs to return in response
3029
/// - Returns: A grid with the dict representation of each def
3130
func libs(filter: String?, limit: Number?) async throws -> Grid
32-
31+
3332
/// Queries op defs from current namspace
3433
///
3534
/// https://project-haystack.org/doc/docHaystack/Ops#ops
@@ -39,7 +38,7 @@ public protocol API {
3938
/// - limit: The maximum number of defs to return in response
4039
/// - Returns: A grid with the dict representation of each def
4140
func ops(filter: String?, limit: Number?) async throws -> Grid
42-
41+
4342
/// Queries filetype defs from current namspace
4443
///
4544
/// https://project-haystack.org/doc/docHaystack/Ops#filetypes
@@ -49,15 +48,15 @@ public protocol API {
4948
/// - limit: The maximum number of defs to return in response
5049
/// - Returns: A grid with the dict representation of each def
5150
func filetypes(filter: String?, limit: Number?) async throws -> Grid
52-
51+
5352
/// Read a set of entity records by their unique identifier
5453
///
5554
/// https://project-haystack.org/doc/docHaystack/Ops#read
5655
///
5756
/// - Parameter ids: Ref identifiers
5857
/// - Returns: A grid with a row for each entity read
5958
func read(ids: [Ref]) async throws -> Grid
60-
59+
6160
/// Read a set of entity records using a filter
6261
///
6362
/// https://project-haystack.org/doc/docHaystack/Ops#read
@@ -67,15 +66,15 @@ public protocol API {
6766
/// - limit: The maximum number of entities to return in response
6867
/// - Returns: A grid with a row for each entity read
6968
func read(filter: String, limit: Number?) async throws -> Grid
70-
69+
7170
/// Navigate a project for learning and discovery
7271
///
7372
/// https://project-haystack.org/doc/docHaystack/Ops#nav
7473
///
7574
/// - Parameter navId: The ID of the entity to navigate from. If null, the navigation root is used.
7675
/// - Returns: A grid of navigation children for the navId specified by the request
7776
func nav(navId: Ref?) async throws -> Grid
78-
77+
7978
/// Reads time-series data from historized point
8079
///
8180
/// https://project-haystack.org/doc/docHaystack/Ops#hisRead
@@ -85,7 +84,7 @@ public protocol API {
8584
/// - range: A date-time range
8685
/// - Returns: A grid whose rows represent timetamp/value pairs with a DateTime ts column and a val column for each scalar value
8786
func hisRead(id: Ref, range: HisReadRange) async throws -> Grid
88-
87+
8988
/// Posts new time-series data to a historized point
9089
///
9190
/// https://project-haystack.org/doc/docHaystack/Ops#hisWrite
@@ -95,7 +94,7 @@ public protocol API {
9594
/// - items: New timestamp/value samples to write
9695
/// - Returns: An empty grid
9796
func hisWrite(id: Ref, items: [HisItem]) async throws -> Grid
98-
97+
9998
/// Write to a given level of a writable point's priority array
10099
///
101100
/// https://project-haystack.org/doc/docHaystack/Ops#pointWrite
@@ -108,15 +107,15 @@ public protocol API {
108107
/// - duration: Number with duration unit if setting level 8
109108
/// - Returns: An empty grid
110109
func pointWrite(id: Ref, level: Number, val: any Val, who: String?, duration: Number?) async throws -> Grid
111-
110+
112111
/// Read the current status of a writable point's priority array
113112
///
114113
/// https://project-haystack.org/doc/docHaystack/Ops#pointWrite
115114
///
116115
/// - Parameter id: Identifier of writable point
117116
/// - Returns: A grid with current priority array state
118117
func pointWriteStatus(id: Ref) async throws -> Grid
119-
118+
120119
/// Used to create new watches.
121120
///
122121
/// https://project-haystack.org/doc/docHaystack/Ops#watchSub
@@ -128,7 +127,7 @@ public protocol API {
128127
/// - Returns: A grid where rows correspond to the current entity state of the requested identifiers. Grid metadata contains
129128
/// `watchId` and `lease`.
130129
func watchSubCreate(watchDis: String, lease: Number?, ids: [Ref]) async throws -> Grid
131-
130+
132131
/// Used to add entities to an existing watch.
133132
///
134133
/// https://project-haystack.org/doc/docHaystack/Ops#watchSub
@@ -140,7 +139,7 @@ public protocol API {
140139
/// - Returns: A grid where rows correspond to the current entity state of the requested identifiers. Grid metadata contains
141140
/// `watchId` and `lease`.
142141
func watchSubAdd(watchId: String, lease: Number?, ids: [Ref]) async throws -> Grid
143-
142+
144143
/// Used remove entities from a watch
145144
///
146145
/// https://project-haystack.org/doc/docHaystack/Ops#watchUnsub
@@ -150,7 +149,7 @@ public protocol API {
150149
/// - ids: Ref values for each entity to unsubscribe. If empty the entire watch is closed.
151150
/// - Returns: An empty grid
152151
func watchUnsubRemove(watchId: String, ids: [Ref]) async throws -> Grid
153-
152+
154153
/// Used to close a watch entirely
155154
///
156155
/// https://project-haystack.org/doc/docHaystack/Ops#watchUnsub
@@ -159,7 +158,7 @@ public protocol API {
159158
/// - watchId: Watch identifier
160159
/// - Returns: An empty grid
161160
func watchUnsubDelete(watchId: String) async throws -> Grid
162-
161+
163162
/// Used to poll a watch for changes to the subscribed entity records
164163
///
165164
/// https://project-haystack.org/doc/docHaystack/Ops#watchPoll
@@ -169,15 +168,15 @@ public protocol API {
169168
/// - refresh: Whether a full refresh should occur
170169
/// - Returns: A grid where each row correspondes to a watched entity
171170
func watchPoll(watchId: String, refresh: Bool) async throws -> Grid
172-
171+
173172
/// https://project-haystack.org/doc/docHaystack/Ops#invokeAction
174173
/// - Parameters:
175174
/// - id: Identifier of target rec
176175
/// - action: The name of the action func
177176
/// - args: The arguments to the action
178177
/// - Returns: A grid of undefined shape
179178
func invokeAction(id: Ref, action: String, args: [String: any Val]) async throws -> Grid
180-
179+
181180
/// Evaluate an Axon expression
182181
///
183182
/// https://haxall.io/doc/lib-hx/op~eval

Sources/Haystack/API/HisItem.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
public struct HisItem {
33
public let ts: DateTime
44
public let val: any Val
5-
5+
66
public init(ts: DateTime, val: any Val) {
77
self.ts = ts
88
self.val = val
99
}
10-
10+
1111
public func toDict() -> Dict {
1212
return ["ts": ts, "val": val]
1313
}

Sources/Haystack/API/HisReadRange.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public enum HisReadRange {
3838
return to.endOfDay(timezone: nil)
3939
case let .dateTimeRange(_, to):
4040
return to.date
41-
case .after(_):
41+
case .after:
4242
return nil
4343
}
4444
}

Sources/Haystack/Bool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Foundation
55
/// [Docs](https://project-haystack.org/doc/docHaystack/Kinds#bool)
66
extension Bool: Val {
77
public static var valType: ValType { .Bool }
8-
8+
99
/// Converts to Zinc formatted string.
1010
/// See [Zinc Literals](https://project-haystack.org/doc/docHaystack/Zinc#literals)
1111
public func toZinc() -> String {

Sources/Haystack/Coord.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ import Foundation
77
/// [Docs](https://project-haystack.org/doc/docHaystack/Kinds#coord)
88
public struct Coord: Val {
99
public static var valType: ValType { .Coord }
10-
10+
1111
public let latitude: Double
1212
public let longitude: Double
13-
13+
1414
public init(latitude: Double, longitude: Double) throws {
15-
guard -90 <= latitude, latitude <= 90, -180 <= longitude, longitude <= 180 else {
15+
guard latitude >= -90, latitude <= 90, longitude >= -180, longitude <= 180 else {
1616
throw CoordError.invalidCoordinates(lat: latitude, lng: longitude)
1717
}
1818
self.latitude = latitude
1919
self.longitude = longitude
2020
}
21-
21+
2222
/// Converts to Zinc formatted string.
2323
/// See [Zinc Literals](https://project-haystack.org/doc/docHaystack/Zinc#literals)
2424
public func toZinc() -> String {
@@ -29,13 +29,13 @@ public struct Coord: Val {
2929
// Coord + Codable
3030
extension Coord: Codable {
3131
static let kindValue = "coord"
32-
32+
3333
enum CodingKeys: CodingKey {
3434
case _kind
3535
case lat
3636
case lng
3737
}
38-
38+
3939
/// Read from decodable data
4040
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#coord)
4141
public init(from decoder: Decoder) throws {
@@ -49,7 +49,7 @@ extension Coord: Codable {
4949
)
5050
)
5151
}
52-
52+
5353
try self.init(
5454
latitude: container.decode(Double.self, forKey: .lat),
5555
longitude: container.decode(Double.self, forKey: .lng)
@@ -64,7 +64,7 @@ extension Coord: Codable {
6464
)
6565
}
6666
}
67-
67+
6868
/// Write to encodable data
6969
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#coord)
7070
public func encode(to encoder: Encoder) throws {

Sources/Haystack/Date.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import Foundation
55
/// [Docs](https://project-haystack.org/doc/docHaystack/Kinds#date)
66
public struct Date: Val {
77
public static var valType: ValType { .Date }
8-
8+
99
public let year: Int
1010
public let month: Int
1111
public let day: Int
12-
12+
1313
public init(
1414
year: Int,
1515
month: Int,
@@ -23,12 +23,12 @@ public struct Date: Val {
2323
guard components.isValidDate(in: calendar) else {
2424
throw ValError.invalidDateDefinition
2525
}
26-
26+
2727
self.year = year
2828
self.month = month
2929
self.day = day
3030
}
31-
31+
3232
public init(_ isoString: String) throws {
3333
let dashSplit = isoString.split(separator: "-")
3434
guard
@@ -39,14 +39,14 @@ public struct Date: Val {
3939
else {
4040
throw ValError.invalidDateFormat(isoString)
4141
}
42-
42+
4343
try self.init(
4444
year: year,
4545
month: month,
4646
day: day
4747
)
4848
}
49-
49+
5050
public func startOfDay(timezone: TimeZone?) -> Foundation.Date {
5151
return DateComponents(
5252
calendar: .current,
@@ -56,17 +56,17 @@ public struct Date: Val {
5656
day: day
5757
).date!
5858
}
59-
59+
6060
public func endOfDay(timezone: TimeZone?) -> Foundation.Date {
6161
return Calendar.current.date(byAdding: .day, value: 1, to: startOfDay(timezone: timezone))!
6262
}
63-
63+
6464
/// Converts to Zinc formatted string.
6565
/// See [Zinc Literals](https://project-haystack.org/doc/docHaystack/Zinc#literals)
6666
public func toZinc() -> String {
6767
return isoString
6868
}
69-
69+
7070
var isoString: String {
7171
let yearStr = String(format: "%04d", arguments: [year])
7272
let monthStr = String(format: "%02d", arguments: [month])
@@ -78,12 +78,12 @@ public struct Date: Val {
7878
// Date + Codable
7979
extension Date {
8080
static let kindValue = "date"
81-
81+
8282
enum CodingKeys: CodingKey {
8383
case _kind
8484
case val
8585
}
86-
86+
8787
/// Read from decodable data
8888
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#date)
8989
public init(from decoder: Decoder) throws {
@@ -97,7 +97,7 @@ extension Date {
9797
)
9898
)
9999
}
100-
100+
101101
let isoString = try container.decode(String.self, forKey: .val)
102102
do {
103103
try self.init(isoString)
@@ -120,7 +120,7 @@ extension Date {
120120
)
121121
}
122122
}
123-
123+
124124
/// Write to encodable data
125125
/// See [JSON format](https://project-haystack.org/doc/docHaystack/Json#date)
126126
public func encode(to encoder: Encoder) throws {

0 commit comments

Comments
 (0)