Skip to content

Commit aee1318

Browse files
Merge pull request #6 from atelier-saulx/feature/tls-host-discovery
Update based universal client
2 parents 3fd8467 + 6ed26c5 commit aee1318

File tree

10 files changed

+45
-49
lines changed

10 files changed

+45
-49
lines changed

Examples/BasicExample/BasicExample/ActorListView.swift

+8-15
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public struct Actors: Decodable {
2525

2626
@Published var actors = Actors(actors: [])
2727
private var task: Task<(), Error>?
28-
private var sequence: BasedAsyncSequence<Actors>?
29-
28+
3029
func fetchActors() {
3130
let query = BasedQuery.query(
3231
.field(
@@ -41,21 +40,15 @@ public struct Actors: Decodable {
4140
)
4241
)
4342
)
44-
45-
sequence = Current.client.based.subscribe(query: query).asBasedAsyncSequence()
46-
47-
if let sequence {
48-
49-
task = Task {
50-
do {
51-
for try await actors in sequence {
52-
self.actors = actors
53-
}
54-
} catch {
55-
print(error)
43+
44+
task = Task {
45+
do {
46+
for try await actors in try Current.client.based.subscribe(query: query) as AsyncThrowingStream<Actors, Error> {
47+
self.actors = actors
5648
}
49+
} catch {
50+
print(error)
5751
}
58-
5952
}
6053
}
6154

Examples/BasicExample/BasicExample/MovieListView.swift

+7-14
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,21 @@ class MovieListViewModel: ObservableObject {
2525

2626
@Published var movies = Movies(movies: [])
2727
private var task: Task<(), Error>?
28-
private var sequence: BasedAsyncSequence<Movies>?
29-
28+
3029
func fetchMovies() {
3130

3231
let query = BasedQuery.query(
3332
.field("movies", .field("name", true), .field("id", true), .list(.find(.traverse("children"), .filter(.from("type"), .operator("="), .value("movie")))))
3433
)
3534

36-
sequence = Current.client.based.subscribe(query: query).asBasedAsyncSequence()
37-
38-
if let sequence {
39-
40-
task = Task {
41-
do {
42-
for try await movies in sequence {
43-
self.movies = movies
44-
}
45-
} catch {
46-
print(error)
35+
task = Task {
36+
do {
37+
for try await movies in try Current.client.based.subscribe(query: query) as AsyncThrowingStream<Movies, Error> {
38+
self.movies = movies
4739
}
40+
} catch {
41+
print(error)
4842
}
49-
5043
}
5144
}
5245

Package.swift

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ let package = Package(
1616
targets: ["BasedClient"])
1717
],
1818
targets: [
19-
.binaryTarget(name: "Based", url: "https://github.com/atelier-saulx/based-universal/releases/download/v2.1.4/based-universal-v2.1.4-xcframework.zip", checksum: "61501392276a6dbd098bbd2d00a39d07fb8662995ef1d126d657ff0625fdfb71"),
20-
// .binaryTarget(
21-
// name: "Based",
22-
// path: "Based.xcframework"),
19+
.binaryTarget(
20+
name: "Based",
21+
url: "https://github.com/atelier-saulx/based-universal/releases/download/v2.1.6/based-universal-v2.1.6-xcframework.zip",
22+
checksum: "40d1d754633942985f01253db14b10bde4534ad85538f1f0dc80c20305356eb4"
23+
),
2324
.target(
2425
name: "BasedOBJCWrapper",
2526
dependencies: [

Sources/BasedClient/Based.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public final class Based {
3535
env: configuration.env,
3636
name: configuration.name,
3737
key: configuration.key,
38-
optionalKey: configuration.optionalKey
38+
optionalKey: configuration.optionalKey,
39+
host: configuration.host,
40+
discoveryUrl: configuration.discoveryUrl
3941
)
4042
}
4143
}

Sources/BasedClient/BasedConfiguration.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public struct BasedConfiguration {
1515
let name: String = "@based/env-hub"
1616
let key: String = ""
1717
let optionalKey: Bool = false
18-
18+
let host: String = ""
19+
let discoveryUrl: String = ""
20+
1921
public init(org: String, project: String, env: String) {
2022
self.org = org
2123
self.project = project

Sources/BasedClient/Client/BasedClient.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,11 @@ final class BasedClient: BasedClientProtocol {
109109
var functionCallbacks: FunctionCallbackStore
110110

111111
var basedCClient: BasedCClientProtocol
112-
112+
var enableTls: Bool = false
113+
113114
/// 32 bit integer representing the id of the c++ client
114115
var clientId: BasedClientId
115-
116+
116117
required init(
117118
cClient: BasedCClientProtocol = BasedCClient(),
118119
observeCallbacks: ObserveCallbackStore = ObserveCallbacks.shared,
@@ -123,7 +124,7 @@ final class BasedClient: BasedClientProtocol {
123124
self.observeCallbacks = observeCallbacks
124125
self.getCallbacks = getCallbacks
125126
self.functionCallbacks = functionCallbacks
126-
clientId = basedCClient.create()
127+
clientId = basedCClient.create(enableTls: enableTls)
127128
}
128129

129130
deinit {

Sources/BasedClient/Client/BasedClientProtocol+Ext.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ extension BasedClientProtocol {
2121
env: String,
2222
name: String = "@based/env-hub",
2323
key: String = "",
24-
optionalKey: Bool = false
24+
optionalKey: Bool = false,
25+
host: String,
26+
discoveryUrl: String
2527
) {
26-
basedCClient.connect(clientId: clientId, cluster: cluster, org: org, project: project, env: env, name: name, key: key, optionalKey: optionalKey)
28+
basedCClient.connect(clientId: clientId, cluster: cluster, org: org, project: project, env: env, name: name, key: key, optionalKey: optionalKey, host: host, discoveryUrl: discoveryUrl)
2729
}
2830

2931
func disconnect() {

Sources/BasedClient/Client/BasedClientProtocol.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ protocol BasedClientProtocol {
4444
env: String,
4545
name: String,
4646
key: String,
47-
optionalKey: Bool
47+
optionalKey: Bool,
48+
host: String,
49+
discoveryUrl: String
4850
)
4951

5052
/// Disconnects the client with id

Sources/BasedOBJCWrapper/BasedCClient.mm

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ @interface BasedCClient ()
1414

1515
@implementation BasedCClient
1616

17-
- (BasedClientID) create {
18-
int clientId = Based__new_client();
19-
return clientId;
17+
- (BasedClientID)create:(BOOL)enableTls {
18+
return Based__new_client(enableTls);
2019
}
2120

2221
- (void)delete:(BasedClientID)clientId {
@@ -27,8 +26,8 @@ - (void)connect:(BasedClientID)clientId withUrl:(NSString *)url {
2726
Based__connect_to_url(clientId, (char *)url.UTF8String);
2827
}
2928

30-
- (void)connect:(BasedClientID)clientId withCluster:(NSString *)cluster withOrg:(NSString *)org withProject:(NSString *)project withEnv:(NSString *)env withName:(NSString *)name withKey:(NSString *)key withOptionalKey:(BOOL) optionalKey {
31-
Based__connect(clientId, (char *)cluster.UTF8String, (char *)org.UTF8String, (char *)project.UTF8String, (char *)env.UTF8String, (char *)name.UTF8String, (char *)key.UTF8String, optionalKey);
29+
- (void)connect:(BasedClientID)clientId withCluster:(NSString *)cluster withOrg:(NSString *)org withProject:(NSString *)project withEnv:(NSString *)env withName:(NSString *)name withKey:(NSString *)key withOptionalKey:(BOOL)optionalKey withHost:(NSString *)host withDiscoveryUrl:(NSString *)discovery_url {
30+
Based__connect(clientId, (char *)cluster.UTF8String, (char *)org.UTF8String, (char *)project.UTF8String, (char *)env.UTF8String, (char *)name.UTF8String, (char *)key.UTF8String, optionalKey, (char *)host.UTF8String, (char *)discovery_url.UTF8String);
3231
}
3332

3433
- (void)disconnect:(BasedClientID)clientId {

Sources/BasedOBJCWrapper/include/BasedCClientProtocol.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ typedef int BasedClientID;
1414

1515
@protocol BasedCClientProtocol
1616

17-
- (int)create;
17+
- (int)create: (BOOL)enableTls
18+
NS_SWIFT_NAME(create(enableTls:));
1819

1920
- (void)delete: (BasedClientID)clientId;
2021

2122
- (void)connect: (BasedClientID)clientId withUrl: (NSString *)url
2223
NS_SWIFT_NAME(connect(clientId:url:));
2324

24-
- (void)connect: (BasedClientID)clientId withCluster: (NSString *)cluster withOrg: (NSString *)org withProject: (NSString *)project withEnv: (NSString *)env withName: (NSString *) name withKey: (NSString *) key withOptionalKey: (BOOL) optionalKey
25-
NS_SWIFT_NAME(connect(clientId:cluster:org:project:env:name:key:optionalKey:));
25+
- (void)connect: (BasedClientID)clientId withCluster: (NSString *)cluster withOrg: (NSString *)org withProject: (NSString *)project withEnv: (NSString *)env withName: (NSString *)name withKey: (NSString *)key withOptionalKey: (BOOL)optionalKey withHost: (NSString *)host withDiscoveryUrl: (NSString *)discovery_url
26+
NS_SWIFT_NAME(connect(clientId:cluster:org:project:env:name:key:optionalKey:host:discoveryUrl:));
2627

2728
- (void)disconnect: (BasedClientID)clientId
2829
NS_SWIFT_NAME(disconnect(clientId:));

0 commit comments

Comments
 (0)