Skip to content

Commit eda6a07

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

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import io.ktor.client.plugins.ResponseException
1010
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
1111
import io.ktor.client.plugins.expectSuccess
1212
import io.ktor.client.request.HttpRequestBuilder
13+
import io.ktor.client.request.accept
1314
import io.ktor.client.request.delete
1415
import io.ktor.client.request.get
1516
import io.ktor.client.request.post
@@ -79,6 +80,7 @@ import org.modelix.model.oauth.TokenProviderAuthConfig
7980
import org.modelix.model.operations.OTBranch
8081
import org.modelix.model.persistent.CPVersion
8182
import org.modelix.model.persistent.HashUtil
83+
import org.modelix.model.server.api.BranchInfo
8284
import org.modelix.model.server.api.RepositoryConfig
8385
import org.modelix.model.server.api.v2.ImmutableObjectsStream
8486
import org.modelix.model.server.api.v2.ObjectHashAndSerializedObject
@@ -281,13 +283,24 @@ class ModelClientV2(
281283

282284
override suspend fun listBranches(repository: RepositoryId): List<BranchReference> {
283285
return httpClient.get {
286+
accept(ContentType.Text.Plain)
284287
url {
285288
takeFrom(baseUrl)
286289
appendPathSegmentsEncodingSlash("repositories", repository.id, "branches")
287290
}
288291
}.bodyAsText().lines().filter { it.isNotEmpty() }.map { repository.getBranchReference(it) }
289292
}
290293

294+
override suspend fun listBranchesWithHashes(repository: RepositoryId): List<BranchInfo> {
295+
return httpClient.get {
296+
accept(ContentType.Application.Json)
297+
url {
298+
takeFrom(baseUrl)
299+
appendPathSegmentsEncodingSlash("repositories", repository.id, "branches")
300+
}
301+
}.body()
302+
}
303+
291304
override suspend fun deleteBranch(branch: BranchReference): Boolean {
292305
try {
293306
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)