Skip to content

Commit

Permalink
[Format] swiftformat formatted.
Browse files Browse the repository at this point in the history
  • Loading branch information
Grady Zhuo committed Jun 23, 2024
1 parent 595090c commit a6c38a9
Show file tree
Hide file tree
Showing 23 changed files with 148 additions and 161 deletions.
4 changes: 2 additions & 2 deletions Package@swift-6.0.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.15.0"),
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.6.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0")
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
Expand All @@ -40,7 +40,7 @@ let package = Package(
.testTarget(
name: "EventStoreDBTests",
dependencies: [
"EventStoreDB"
"EventStoreDB",
],
resources: [
.copy("Resources/ca.crt"),
Expand Down
67 changes: 32 additions & 35 deletions Sources/EventStoreDB/ClientSettings/Parser/EndpointParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ class EndpointParser: ConnctionStringParser {
typealias Result = [ClientSettings.Endpoint]
typealias HostReference = Reference<String>
typealias PortReference = Reference<UInt32>

let ipv4Regex = Regex {
Anchor.wordBoundary
Regex{
Regex {
Repeat(count: 3) {
Regex{
ChoiceOf{
Regex{
Regex {
ChoiceOf {
Regex {
One("25")
One("0"..."5")
One("0" ... "5")
}
Regex{
Regex {
One("2")
One("0"..."4")
One("0" ... "4")
One(.digit)
}
Regex{
Regex {
One("1")
One(.digit)
One(.digit)
}
Regex{
Optionally{
One("1"..."9")
Regex {
Optionally {
One("1" ... "9")
}
One(.digit)
}
Expand All @@ -45,56 +45,53 @@ class EndpointParser: ConnctionStringParser {
}
}
}

Regex {
ChoiceOf{
ChoiceOf {
Regex {
One("25")
One("0"..."5")
One("0" ... "5")
}
Regex{

Regex {
One("2")
One("0"..."4")
One("0" ... "4")
One(.digit)
}
Regex{

Regex {
One("1")
One(.digit)
One(.digit)
}
Regex{
Optionally{
One("1"..."9")

Regex {
Optionally {
One("1" ... "9")
}
One(.digit)

}
}
}
Anchor.wordBoundary

}

let hostRegex = Regex {
Anchor.wordBoundary
OneOrMore{
ChoiceOf{
"A"..."Z"
"a"..."z"
OneOrMore {
ChoiceOf {
"A" ... "Z"
"a" ... "z"
}
ZeroOrMore{
ZeroOrMore {
One(.word.subtracting(.anyOf(":?=&")))
}
Optionally{
Optionally {
One(".")
}
}
Anchor.wordBoundary
}


lazy var regex: RegexType = Regex {
ChoiceOf {
Expand All @@ -103,7 +100,7 @@ class EndpointParser: ConnctionStringParser {
","
}
Capture(as: _host) {
ChoiceOf{
ChoiceOf {
ipv4Regex
hostRegex
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/EventStoreDB/ClientSettings/UserCredentials.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public struct UserCredentials {
}

extension UserCredentials {
func makeBasicAuthHeader() throws-> String {
func makeBasicAuthHeader() throws -> String {
let credentialString = "\(username):\(password)"
guard let data = credentialString.data(using: .ascii) else {
throw ClientSettingsError.encodingError(message: "\(credentialString) encoding failed.", encoding: .ascii)
Expand Down
2 changes: 1 addition & 1 deletion Sources/EventStoreDB/Event/EventData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public struct EventData: EventStoreEvent, Codable, Equatable {
self.customMetadata = customMetadata
}

public init(id: UUID = .init() ,eventType: String, payload: Codable, customMetadata: Data? = nil) throws {
public init(id: UUID = .init(), eventType: String, payload: Codable, customMetadata: Data? = nil) throws {
let encoder = JSONEncoder()
let data = try encoder.encode(payload)
self.init(id: id, eventType: eventType, data: data, contentType: .json, customMetadata: customMetadata)
Expand Down
8 changes: 4 additions & 4 deletions Sources/EventStoreDB/EventStoreDBClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public struct EventStoreDBClient {
public init(settings: ClientSettings) {
var defaultCallOptions = CallOptions()
if let credentials = settings.defaultUserCredentials {
do{
do {
try defaultCallOptions.customMetadata.replaceOrAdd(name: "Authorization", value: credentials.makeBasicAuthHeader())
}catch{
} catch {
logger.error("Could not setting Authorization with credentials: \(credentials).\n Original error:\(error).")
}
}
Expand Down Expand Up @@ -123,14 +123,14 @@ extension EventStoreDBClient {

// MARK: Subscribe by all streams methods -

public func subscribeToAll(from cursor: Cursor<Stream.Position>, configure: (_ options: StreamClient.SubscribeToAll.Options) -> StreamClient.SubscribeToAll.Options = { $0 }) async throws -> StreamClient.Subscription{
public func subscribeToAll(from cursor: Cursor<Stream.Position>, configure: (_ options: StreamClient.SubscribeToAll.Options) -> StreamClient.SubscribeToAll.Options = { $0 }) async throws -> StreamClient.Subscription {
let client = try StreamClient(channel: channel, callOptions: defaultCallOptions)

let options = configure(.init())
return try await client.subscribeToAll(from: cursor, options: options)
}

public func subscribeTo(stream: Stream.Identifier, from cursor: Cursor<Stream.Revision>, configure: (_ options: StreamClient.Subscribe.Options) -> StreamClient.Subscribe.Options = { $0 }) async throws -> StreamClient.Subscription{
public func subscribeTo(stream: Stream.Identifier, from cursor: Cursor<Stream.Revision>, configure: (_ options: StreamClient.Subscribe.Options) -> StreamClient.Subscribe.Options = { $0 }) async throws -> StreamClient.Subscription {
let client = try StreamClient(channel: channel, callOptions: defaultCallOptions)

let options = configure(.init())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ extension PersistentSubscriptionsClient {
func subscribeTo(_ streamSelection: Selector<Stream.Identifier>, groupName: String, options: Read.Options) async throws -> Subscription {
let handler = Read(streamSelection: streamSelection, groupName: groupName, options: options)
let requests = try handler.build()

let getSubscriptionCall = underlyingClient.makeReadCall()
try await getSubscriptionCall.requestStream.send(requests)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Stream.ControlOption.swift
//
//
//
// Created by Grady Zhuo on 2024/6/23.
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Stream.Direction.swift
//
//
//
// Created by Grady Zhuo on 2024/6/23.
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Stream.FilterOption.swift
//
//
//
// Created by Grady Zhuo on 2024/6/23.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension Stream {

public let name: String
public var encoding: String.Encoding

public init(name: String, encoding: String.Encoding = .utf8) {
self.name = name
self.encoding = encoding
Expand Down
75 changes: 37 additions & 38 deletions Sources/EventStoreDB/StreamClient/Stream/Stream.Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,50 +46,50 @@ extension Stream {
var customProperties: [String: String]?

public init() {
self.maxCount = nil
self.maxAge = nil
self.truncateBefore = nil
self.cacheControl = nil
self.acl = nil
self.customProperties = nil
}
maxCount = nil
maxAge = nil
truncateBefore = nil
cacheControl = nil
acl = nil
customProperties = nil
}

public func maxCount(_ maxCount: UInt64) -> Self {
withCopy { copied in
copied.maxCount = maxCount
}
}

public func maxAge(_ maxAge: Duration) -> Self {
withCopy { copied in
copied.maxAge = maxAge
}
}

public func truncateBefore(_ truncateBefore: UInt64) -> Self {
withCopy { copied in
copied.truncateBefore = truncateBefore
}
}

public func cacheControl(_ cacheControl: Duration) -> Self {
withCopy { copied in
copied.cacheControl = cacheControl
}
}

public func acl(_ acl: Acl) -> Self {
withCopy { copied in
copied.acl = acl
}
}

public func customProperties(_ customProperties: [String: String]) -> Self {
withCopy { copied in
copied.customProperties = customProperties
}
}

func jsonData() throws -> Data? {
guard let customProperties else {
return nil
Expand Down Expand Up @@ -175,55 +175,54 @@ extension Stream.Metadata {

// Roles and users permitted to write stream metadata.
public private(set) var metaWriteRoles: [String]?

}
}

extension Stream.Metadata.StreamAcl: Buildable {
public func readRoles(_ roles: [String]) -> Self{
public func readRoles(_ roles: [String]) -> Self {
withCopy { copied in
copied.readRoles = roles
}
}
public func writeRoles(_ roles: [String]) -> Self{

public func writeRoles(_ roles: [String]) -> Self {
withCopy { copied in
copied.writeRoles = roles
}
}
public func deleteRoles(_ roles: [String]) -> Self{

public func deleteRoles(_ roles: [String]) -> Self {
withCopy { copied in
copied.deleteRoles = roles
}
}
public func metaReadRoles(_ roles: [String]) -> Self{

public func metaReadRoles(_ roles: [String]) -> Self {
withCopy { copied in
copied.metaReadRoles = roles
}
}
public func metaWriteRoles(_ roles: [String]) -> Self{

public func metaWriteRoles(_ roles: [String]) -> Self {
withCopy { copied in
copied.metaWriteRoles = roles
}
}
}

extension Stream.Metadata : Equatable {
public static func ==(lhs: Self, rhs: Self) -> Bool{
return lhs.cacheControl == rhs.cacheControl
&& lhs.customProperties == rhs.customProperties
&& lhs.maxAge == rhs.maxAge
&& lhs.truncateBefore == rhs.truncateBefore
&& lhs.acl == rhs.acl
extension Stream.Metadata: Equatable {
public static func == (lhs: Self, rhs: Self) -> Bool {
lhs.cacheControl == rhs.cacheControl
&& lhs.customProperties == rhs.customProperties
&& lhs.maxAge == rhs.maxAge
&& lhs.truncateBefore == rhs.truncateBefore
&& lhs.acl == rhs.acl
}
}

extension Stream.Metadata.Acl : Equatable {
extension Stream.Metadata.Acl: Equatable {
public static func == (lhs: Self, rhs: Self) -> Bool {
do{
do {
return try lhs.rawValue == rhs.rawValue
} catch {
logger.warning("It's failed when getting acl rawvalue of stream metadata. error: \(error)")
Expand All @@ -234,10 +233,10 @@ extension Stream.Metadata.Acl : Equatable {

extension Stream.Metadata.StreamAcl: Equatable {
public static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.deleteRoles == rhs.deleteRoles
&& lhs.metaReadRoles == rhs.metaReadRoles
&& lhs.metaWriteRoles == rhs.metaWriteRoles
&& lhs.readRoles == rhs.readRoles
&& lhs.writeRoles == rhs.writeRoles
lhs.deleteRoles == rhs.deleteRoles
&& lhs.metaReadRoles == rhs.metaReadRoles
&& lhs.metaWriteRoles == rhs.metaWriteRoles
&& lhs.readRoles == rhs.readRoles
&& lhs.writeRoles == rhs.writeRoles
}
}
Loading

0 comments on commit a6c38a9

Please sign in to comment.