Skip to content

Commit 92d4669

Browse files
committed
chore!: client feature flag
BREAKING CHANGES: - without `client` feature, crate is just some api helpers - codemp::Client -> codemp::Session - most stuff now is under src/client
1 parent 4ad7bca commit 92d4669

File tree

36 files changed

+436
-395
lines changed

36 files changed

+436
-395
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
repo-token: ${{ secrets.GITHUB_TOKEN }}
1919
- uses: actions/checkout@v4
2020
- uses: dtolnay/rust-toolchain@stable
21-
- run: cargo test --verbose
21+
- run: cargo test --verbose --features=client
2222

2323
test-doc:
2424
runs-on: ubuntu-latest
@@ -28,7 +28,7 @@ jobs:
2828
repo-token: ${{ secrets.GITHUB_TOKEN }}
2929
- uses: actions/checkout@v4
3030
- uses: dtolnay/rust-toolchain@stable
31-
- run: cargo doc --features=serialize
31+
- run: cargo doc --features=client,serialize
3232

3333
test-beta:
3434
runs-on: ubuntu-latest
@@ -47,7 +47,7 @@ jobs:
4747
- uses: dtolnay/rust-toolchain@master
4848
with:
4949
toolchain: ${{ matrix.toolchain }}
50-
- run: cargo test --verbose
50+
- run: cargo test --verbose --features=client
5151

5252
test-build:
5353
needs: [test-unit]
@@ -100,7 +100,7 @@ jobs:
100100
repo-token: ${{ secrets.GITHUB_TOKEN }}
101101
- uses: actions/checkout@v4
102102
- uses: dtolnay/rust-toolchain@stable
103-
- run: cargo test --verbose --features=test-e2e tests::e2e
103+
- run: cargo test --verbose --features=ci,test-e2e tests::e2e
104104
env:
105105
CODEMP_TEST_USERNAME_ALICE: ${{ secrets.CODEMP_TEST_USERNAME_ALICE }}
106106
CODEMP_TEST_PASSWORD_ALICE: ${{ secrets.CODEMP_TEST_PASSWORD_ALICE }}

Cargo.toml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ thiserror = "2.0"
3131
# crdt
3232
diamond-types = "1.0"
3333
# proto
34-
codemp-proto = { git = "https://github.com/hexedtech/codemp-proto", rev = "6b45fd7bd7c03ef60234880c59157481def4ca71", features = ["client"] }
35-
uuid = { version = "1.17", features = ["v4"] }
36-
tonic = { version = "0.14", features = ["tls-native-roots"] }
34+
codemp-proto = { git = "https://github.com/hexedtech/codemp-proto", rev = "6b45fd7bd7c03ef60234880c59157481def4ca71", optional = true }
3735
# api
38-
tokio = { version = "1.47", features = ["macros", "rt-multi-thread", "sync"] }
3936
xxhash-rust = { version = "0.8", features = ["xxh3"] }
4037
# client
41-
tokio-stream = "0.1"
42-
dashmap = "6.1"
38+
tokio = { version = "1.47", features = ["macros", "rt-multi-thread", "sync"], optional = true }
39+
tonic = { version = "0.14", features = ["tls-native-roots"], optional = true }
40+
tokio-stream = { version = "0.1", optional = true }
41+
dashmap = { version = "6.1", optional = true }
4342

4443
# glue (multiple)
4544
tracing-subscriber = { version = "0.3", optional = true }
@@ -66,6 +65,7 @@ async-trait = { version = "0.1", optional = true }
6665
serde = { version = "1.0", features = ["derive"], optional = true }
6766
syn = { version = "2.0", features = ["full"], optional = true }
6867
regex = { version = "1.12", optional = true }
68+
uuid = { version = "1.17", features = ["v4"], optional = true }
6969

7070

7171
[build-dependencies]
@@ -76,18 +76,21 @@ pyo3-build-config = { version = "0.28", optional = true }
7676
pyo3-introspection = { version = "0.28", optional = true }
7777

7878
[features]
79-
default = ["lua-jit", "py-abi3", "py-extmod"]
79+
default = ["lua-jit", "py-abi3", "py-extmod", "test-coverage"]
80+
proto = ["dep:codemp-proto"]
81+
client = ["proto", "dep:tonic", "dep:tokio", "dep:tokio-stream", "dep:dashmap", "codemp-proto?/client"]
82+
server = ["proto", "codemp-proto?/server"]
8083
# extra
8184
async-trait = ["dep:async-trait"]
82-
serialize = ["dep:serde", "uuid/serde"]
85+
serialize = ["dep:serde", "uuid?/serde"]
8386
# special tests which require more setup
84-
test-e2e = []
87+
test-e2e = ["dep:uuid"]
8588
test-coverage = ["dep:syn", "dep:regex"]
8689
# ffi
87-
java = ["dep:jni", "dep:tracing-subscriber", "dep:jni-toolbox", "codemp-proto/java"]
88-
js = ["dep:napi-build", "dep:tracing-subscriber", "dep:napi", "dep:napi-derive", "codemp-proto/js"]
89-
py = ["dep:pyo3", "dep:tracing-subscriber", "dep:pyo3-build-config", "dep:pyo3-introspection", "codemp-proto/py"]
90-
lua = ["serialize", "dep:mlua", "dep:mlua-serde-derive", "dep:tracing-subscriber", "codemp-proto/lua"]
90+
java = ["client", "dep:jni", "dep:tracing-subscriber", "dep:jni-toolbox", "codemp-proto/java"]
91+
js = ["client", "dep:napi-build", "dep:tracing-subscriber", "dep:napi", "dep:napi-derive", "codemp-proto/js"]
92+
py = ["client", "dep:pyo3", "dep:tracing-subscriber", "dep:pyo3-build-config", "dep:pyo3-introspection", "codemp-proto/py"]
93+
lua = ["client", "serialize", "dep:mlua", "dep:mlua-serde-derive", "dep:tracing-subscriber", "dep:uuid", "codemp-proto/lua"]
9194
# ffi variants
9295
lua-jit = ["mlua?/luajit"]
9396
lua-54 = ["mlua?/lua54"]
@@ -98,7 +101,7 @@ ci = []
98101

99102

100103
[package.metadata.docs.rs] # enabled features when building on docs.rs
101-
features = ["serialize"]
104+
features = ["client", "serialize"]
102105

103106
[profile.release]
104107
opt-level = 'z'
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,26 @@
1616
* This is the only object you are expected to hold yourself; unlike all the others,
1717
* there are no copies of it managed exclusively by the library. When this is garbage
1818
* collected, it will free the underlying memory.
19-
* A Client is used to join and manage workspaces, and to obtain information about
19+
* A Session is used to join and manage workspaces, and to obtain information about
2020
* the current session.
2121
*/
2222
@Getter
23-
public final class Client {
23+
public final class Session {
2424
private final long ptr;
2525

26-
Client(long ptr) {
26+
Session(long ptr) {
2727
this.ptr = ptr;
2828
Extensions.CLEANER.register(this, () -> free(ptr));
2929
}
3030

3131
/**
32-
* Connects to a remote CodeMP server and creates a {@link Client} instance
32+
* Connects to a remote CodeMP server and creates a {@link Session} instance
3333
* for interacting with it.
3434
* @param config a {@link Config} object containing the connection settings
35-
* @return a holder for the Client's pointer
35+
* @return a holder for the Session's pointer
3636
* @throws ConnectionException if an error occurs in communicating with the server
3737
*/
38-
public static native Client connect(Config config) throws ConnectionException;
38+
public static native Session connect(Config config) throws ConnectionException;
3939

4040
private static native UserInfo current_user(long self);
4141

@@ -222,7 +222,7 @@ public SessionEvent recv() throws ControllerException {
222222
return recv(this.ptr);
223223
}
224224

225-
private static native void callback(long self, Consumer<Client> cb);
225+
private static native void callback(long self, Consumer<Session> cb);
226226

227227
/**
228228
* Registers a callback to be invoked whenever a {@link SessionEvent} occurs.
@@ -231,7 +231,7 @@ public SessionEvent recv() throws ControllerException {
231231
* you should probably spawn a new thread in here, to avoid deadlocking
232232
* @see Extensions#drive(boolean)
233233
*/
234-
public void callback(Consumer<Client> cb) {
234+
public void callback(Consumer<Session> cb) {
235235
callback(this.ptr, cb);
236236
}
237237

dist/lua/annotations.lua

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ function StringArrayPromise:cancel() end
5353
function StringArrayPromise:and_then(cb) end
5454

5555

56-
---@class (exact) ClientPromise : Promise
57-
local ClientPromise = {}
56+
---@class (exact) SessionPromise : Promise
57+
local SessionPromise = {}
5858
--- block until promise is ready and return value
59-
--- @return Client
60-
function ClientPromise:await() end
59+
--- @return Session
60+
function SessionPromise:await() end
6161
--- cancel promise execution
62-
function ClientPromise:cancel() end
63-
---@param cb fun(x: Client) callback to invoke
62+
function SessionPromise:cancel() end
63+
---@param cb fun(x: Session) callback to invoke
6464
---invoke callback asynchronously as soon as promise is ready
65-
function ClientPromise:and_then(cb) end
65+
function SessionPromise:and_then(cb) end
6666

6767

6868
---@class (exact) WorkspacePromise : Promise
@@ -216,107 +216,107 @@ function WorkspaceIdentifierListPromise:and_then(cb) end
216216
-- [[ END ASYNC STUFF ]]
217217

218218

219-
---@class (exact) Client
219+
---@class (exact) Session
220220
---the effective local client, handling connecting to codemp server
221-
local Client = {}
221+
local Session = {}
222222

223223
---@return UserInfo
224224
---current logged in user for this client
225-
function Client:current_user() end
225+
function Session:current_user() end
226226

227227
---@return string[]
228228
---array of all currently active workspace names
229-
function Client:active_workspaces() end
229+
function Session:active_workspaces() end
230230

231231
---@return NilPromise
232232
---@async
233233
---@nodiscard
234234
---refresh current user token if possible
235-
function Client:refresh() end
235+
function Session:refresh() end
236236

237237
---@param user string workspace owning user
238238
---@param ws string workspace id to connect to
239239
---@return WorkspacePromise
240240
---@async
241241
---@nodiscard
242242
---join requested workspace if possible and subscribe to event bus
243-
function Client:attach_workspace(user, ws) end
243+
function Session:attach_workspace(user, ws) end
244244

245245
---@param ws string workspace id to create
246246
---@return NilPromise
247247
---@async
248248
---@nodiscard
249249
---create a new workspace with given id
250-
function Client:create_workspace(ws) end
250+
function Session:create_workspace(ws) end
251251

252252
---@param user string workspace owning user
253253
---@param ws string workspace id to leave
254254
---leave workspace with given id, detaching and disconnecting
255-
function Client:leave_workspace(user, ws) end
255+
function Session:leave_workspace(user, ws) end
256256

257257
---@param ws string workspace id to delete
258258
---@return NilPromise
259259
---@async
260260
---@nodiscard
261261
---delete workspace with given id
262-
function Client:delete_workspace(ws) end
262+
function Session:delete_workspace(ws) end
263263

264264
---@param user string user owning the workspace to quit
265265
---@param workspace string workspace to quit
266266
---@return NilPromise
267267
---@async
268268
---@nodiscard
269269
---quit a joined workspace, by user + workspace name
270-
function Client:quit_workspace(user, workspace) end
270+
function Session:quit_workspace(user, workspace) end
271271

272272
---@param user string user inviting us
273273
---@param workspace string workspace being invited to
274274
---@return NilPromise
275275
---@async
276276
---@nodiscard
277277
---accept an invite to a new workspace
278-
function Client:accept_invite(user, workspace) end
278+
function Session:accept_invite(user, workspace) end
279279

280280
---@param user string user inviting us
281281
---@param workspace string workspace being invited to
282282
---@return NilPromise
283283
---@async
284284
---@nodiscard
285285
---reject an invite to a new workspace
286-
function Client:reject_invite(user, workspace) end
286+
function Session:reject_invite(user, workspace) end
287287

288288
---@param ws string workspace id to delete
289289
---@param user string user name to invite to given workspace
290290
---@return NilPromise
291291
---@async
292292
---@nodiscard
293293
---grant user acccess to workspace
294-
function Client:invite_to_workspace(ws, user) end
294+
function Session:invite_to_workspace(ws, user) end
295295

296296
---@return WorkspaceIdentifierListPromise
297297
---@async
298298
---@nodiscard
299299
---fetch and list owned workspaces
300-
function Client:fetch_owned_workspaces() end
300+
function Session:fetch_owned_workspaces() end
301301

302302
---@return WorkspaceIdentifierListPromise
303303
---@async
304304
---@nodiscard
305305
---fetch and list joined workspaces
306-
function Client:fetch_joined_workspaces() end
306+
function Session:fetch_joined_workspaces() end
307307

308308
---@param user string user owning this workspace
309309
---@param ws string workspace id to get
310310
---@return Workspace?
311311
---get an active workspace by name
312-
function Client:get_workspace(user, ws) end
312+
function Session:get_workspace(user, ws) end
313313

314314
---@param user string username to lookup
315315
---@return UserInfoPromise
316316
---@async
317317
---@nodiscard
318318
---get full user info for given username from server
319-
function Client:get_user_info(user) end
319+
function Session:get_user_info(user) end
320320

321321
---@class (exact) SessionEvent
322322
---@field kind integer (SessionEventKind) event kind
@@ -327,26 +327,26 @@ function Client:get_user_info(user) end
327327
---@async
328328
---@nodiscard
329329
---try to receive session events, returning nil if none is available
330-
function Client:try_recv() end
330+
function Session:try_recv() end
331331

332332
---@return SessionEventPromise
333333
---@async
334334
---@nodiscard
335335
---block until next client event and return it
336-
function Client:recv() end
336+
function Session:recv() end
337337

338338
---@return NilPromise
339339
---@async
340340
---@nodiscard
341341
---block until next session event without returning it
342-
function Client:poll() end
342+
function Session:poll() end
343343

344344
---clears any previously registered session callback
345-
function Client:clear_callback() end
345+
function Session:clear_callback() end
346346

347-
---@param cb fun(w: Client) callback to invoke on each workspace event received
347+
---@param cb fun(w: Session) callback to invoke on each workspace event received
348348
---register a new callback to be called on session events (replaces any previously registered one)
349-
function Client:callback(cb) end
349+
function Session:callback(cb) end
350350

351351

352352

@@ -657,7 +657,7 @@ function CursorController:callback(cb) end
657657
local Codemp = {}
658658

659659
---@param config Config configuration for
660-
---@return ClientPromise
660+
---@return SessionPromise
661661
---@async
662662
---@nodiscard
663663
---connect to codemp server, authenticate and return client

src/api/config.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,26 @@ impl Config {
4242
}
4343
}
4444

45+
/// get server host address
4546
#[inline]
46-
pub(crate) fn host(&self) -> &str {
47+
pub fn host(&self) -> &str {
4748
self.host.as_deref().unwrap_or("api.code.mp")
4849
}
4950

51+
/// get server port number
5052
#[inline]
51-
pub(crate) fn port(&self) -> u16 {
53+
pub fn port(&self) -> u16 {
5254
self.port.unwrap_or(50053)
5355
}
5456

57+
/// get whether TLS should be used
5558
#[inline]
56-
pub(crate) fn tls(&self) -> bool {
59+
pub fn tls(&self) -> bool {
5760
self.tls.unwrap_or(true)
5861
}
5962

60-
pub(crate) fn endpoint(&self) -> String {
63+
/// get the actual server uri, combining its parts (tls,host,port)
64+
pub fn endpoint(&self) -> String {
6165
format!(
6266
"{}://{}:{}",
6367
if self.tls() { "https" } else { "http" },

src/api/controller.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ pub trait AsyncReceiver<T: Sized + Send + Sync>: Sized + Send + Sync {
7878
pub struct ControllerCallback<T>(pub Box<dyn Sync + Send + Fn(T)>);
7979

8080
impl<T> ControllerCallback<T> {
81-
pub(crate) fn call(&self, x: T) {
81+
/// Invoke the callback blockingly, passing its associated controller
82+
pub fn call(&self, x: T) {
8283
self.0(x)
8384
}
8485
}

0 commit comments

Comments
 (0)