Skip to content

Commit 8029f17

Browse files
abstraktorslisson
authored andcommitted
feat(model-client): list branches with version hashes
1 parent 65ae533 commit 8029f17

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
@@ -11,6 +11,7 @@ import org.modelix.model.api.INode
1111
import org.modelix.model.async.IAsyncObjectStore
1212
import org.modelix.model.lazy.BranchReference
1313
import org.modelix.model.lazy.RepositoryId
14+
import org.modelix.model.server.api.BranchInfo
1415
import org.modelix.model.server.api.RepositoryConfig
1516
import org.modelix.modelql.core.IMonoStep
1617

@@ -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
@@ -84,6 +86,7 @@ import org.modelix.model.oauth.TokenProviderAuthConfig
8486
import org.modelix.model.operations.OTBranch
8587
import org.modelix.model.persistent.CPVersion
8688
import org.modelix.model.persistent.HashUtil
89+
import org.modelix.model.server.api.BranchInfo
8790
import org.modelix.model.server.api.RepositoryConfig
8891
import org.modelix.model.server.api.v2.ImmutableObjectsStream
8992
import org.modelix.model.server.api.v2.ObjectHashAndSerializedObject
@@ -284,13 +287,25 @@ class ModelClientV2(
284287

285288
override suspend fun listBranches(repository: RepositoryId): List<BranchReference> {
286289
return httpClient.get {
290+
// only accept text/plain, not application/json
291+
accept(ContentType.Text.Plain)
292+
exclude(ContentType.Application.Json)
287293
url {
288294
takeFrom(baseUrl)
289295
appendPathSegmentsEncodingSlash("repositories", repository.id, "branches")
290296
}
291297
}.bodyAsText().lines().filter { it.isNotEmpty() }.map { repository.getBranchReference(it) }
292298
}
293299

300+
override suspend fun listBranchesWithHashes(repository: RepositoryId): List<BranchInfo> {
301+
return httpClient.get {
302+
url {
303+
takeFrom(baseUrl)
304+
appendPathSegmentsEncodingSlash("repositories", repository.id, "branches")
305+
}
306+
}.body()
307+
}
308+
294309
override suspend fun deleteBranch(branch: BranchReference): Boolean {
295310
try {
296311
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
@@ -29,6 +29,7 @@ import org.modelix.model.mutable.asMutableThreadSafe
2929
import org.modelix.model.mutable.load
3030
import org.modelix.model.mutable.withAutoTransactions
3131
import org.modelix.model.persistent.MapBasedStore
32+
import org.modelix.model.server.api.BranchInfo
3233
import org.modelix.mps.multiplatform.model.MPSIdGenerator
3334
import kotlin.js.Date
3435
import kotlin.js.Promise
@@ -140,6 +141,15 @@ interface ClientJS {
140141
*/
141142
fun fetchBranches(repositoryId: String): Promise<Array<String>>
142143

144+
/**
145+
* Fetch existing branches for a given repository from the model server.
146+
*
147+
* @param repositoryId Repository ID to fetch branches from.
148+
*/
149+
fun fetchBranchesWithHashes(
150+
repositoryId: String,
151+
): Promise<Array<BranchInfo>>
152+
143153
fun createBranch(repositoryId: String, branchId: String, versionHash: String, failIfExists: Boolean = false): Promise<Boolean>
144154

145155
/**
@@ -192,6 +202,12 @@ internal class ClientJSImpl(private val modelClient: ModelClientV2) : ClientJS {
192202
}
193203
}
194204

205+
override fun fetchBranchesWithHashes(
206+
repositoryId: String,
207+
): Promise<Array<BranchInfo>> = GlobalScope.promise {
208+
return@promise modelClient.listBranchesWithHashes(RepositoryId(repositoryId)).toTypedArray()
209+
}
210+
195211
override fun createBranch(
196212
repositoryId: String,
197213
branchId: String,

0 commit comments

Comments
 (0)