Skip to content

Commit e6d68ab

Browse files
committed
feat(model-client): list branches with version hashes
1 parent 2229f15 commit e6d68ab

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

model-client/src/commonMain/kotlin/org/modelix/model/client2/IModelClientV2.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.modelix.model.api.INode
1010
import org.modelix.model.async.IAsyncObjectStore
1111
import org.modelix.model.lazy.BranchReference
1212
import org.modelix.model.lazy.RepositoryId
13+
import org.modelix.model.server.api.BranchInfo
1314
import org.modelix.model.server.api.RepositoryConfig
1415
import org.modelix.modelql.core.IMonoStep
1516
import kotlin.time.Duration
@@ -54,6 +55,7 @@ interface IModelClientV2 {
5455
suspend fun listRepositories(): List<RepositoryId>
5556
suspend fun deleteRepository(repository: RepositoryId): Boolean
5657
suspend fun listBranches(repository: RepositoryId): List<BranchReference>
58+
suspend fun listBranchesWithHashes(repository: RepositoryId): List<BranchInfo>
5759

5860
/**
5961
* Deletes a branch from a repository if it exists.

model-client/src/commonMain/kotlin/org/modelix/model/client2/ModelClientV2.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import io.ktor.client.plugins.HttpRequestRetry
88
import io.ktor.client.plugins.HttpTimeout
99
import io.ktor.client.plugins.ResponseException
1010
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
11+
import io.ktor.client.plugins.contentnegotiation.exclude
1112
import io.ktor.client.plugins.expectSuccess
1213
import io.ktor.client.request.HttpRequestBuilder
14+
import io.ktor.client.request.accept
1315
import io.ktor.client.request.delete
1416
import io.ktor.client.request.get
1517
import io.ktor.client.request.post
@@ -79,6 +81,7 @@ import org.modelix.model.oauth.TokenProviderAuthConfig
7981
import org.modelix.model.operations.OTBranch
8082
import org.modelix.model.persistent.CPVersion
8183
import org.modelix.model.persistent.HashUtil
84+
import org.modelix.model.server.api.BranchInfo
8285
import org.modelix.model.server.api.RepositoryConfig
8386
import org.modelix.model.server.api.v2.ImmutableObjectsStream
8487
import org.modelix.model.server.api.v2.ObjectHashAndSerializedObject
@@ -281,13 +284,25 @@ class ModelClientV2(
281284

282285
override suspend fun listBranches(repository: RepositoryId): List<BranchReference> {
283286
return httpClient.get {
287+
// only accept text/plain, not application/json
288+
accept(ContentType.Text.Plain)
289+
exclude(ContentType.Application.Json)
284290
url {
285291
takeFrom(baseUrl)
286292
appendPathSegmentsEncodingSlash("repositories", repository.id, "branches")
287293
}
288294
}.bodyAsText().lines().filter { it.isNotEmpty() }.map { repository.getBranchReference(it) }
289295
}
290296

297+
override suspend fun listBranchesWithHashes(repository: RepositoryId): List<BranchInfo> {
298+
return httpClient.get {
299+
url {
300+
takeFrom(baseUrl)
301+
appendPathSegmentsEncodingSlash("repositories", repository.id, "branches")
302+
}
303+
}.body()
304+
}
305+
291306
override suspend fun deleteBranch(branch: BranchReference): Boolean {
292307
try {
293308
return httpClient.delete {

model-client/src/jsMain/kotlin/org/modelix/model/client2/ClientJS.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import org.modelix.model.mutable.asMutableThreadSafe
2828
import org.modelix.model.mutable.load
2929
import org.modelix.model.mutable.withAutoTransactions
3030
import org.modelix.model.persistent.MapBasedStore
31+
import org.modelix.model.server.api.BranchInfo
3132
import org.modelix.mps.multiplatform.model.MPSIdGenerator
3233
import kotlin.js.Promise
3334

@@ -130,6 +131,15 @@ interface ClientJS {
130131
*/
131132
fun fetchBranches(repositoryId: String): Promise<Array<String>>
132133

134+
/**
135+
* Fetch existing branches for a given repository from the model server.
136+
*
137+
* @param repositoryId Repository ID to fetch branches from.
138+
*/
139+
fun fetchBranchesWithHashes(
140+
repositoryId: String,
141+
): Promise<Array<BranchInfo>>
142+
133143
fun createBranch(repositoryId: String, branchId: String, versionHash: String, failIfExists: Boolean = false): Promise<Boolean>
134144

135145
/**
@@ -182,6 +192,12 @@ internal class ClientJSImpl(private val modelClient: ModelClientV2) : ClientJS {
182192
}
183193
}
184194

195+
override fun fetchBranchesWithHashes(
196+
repositoryId: String,
197+
): Promise<Array<BranchInfo>> = GlobalScope.promise {
198+
return@promise modelClient.listBranchesWithHashes(RepositoryId(repositoryId)).toTypedArray()
199+
}
200+
185201
override fun createBranch(
186202
repositoryId: String,
187203
branchId: String,

0 commit comments

Comments
 (0)