Skip to content

Commit 43eb52d

Browse files
abstraktorslisson
authored andcommitted
feat(model-client): add createBranch to ClientJS
1 parent b1f5eb6 commit 43eb52d

File tree

1 file changed

+23
-0
lines changed
  • model-client/src/jsMain/kotlin/org/modelix/model/client2

1 file changed

+23
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ interface ClientJS {
140140
*/
141141
fun fetchBranches(repositoryId: String): Promise<Array<String>>
142142

143+
fun createBranch(repositoryId: String, branchId: String, versionHash: String, failIfExists: Boolean = false): Promise<Boolean>
144+
143145
/**
144146
* Fetch existing repositories from the model server.
145147
*/
@@ -190,6 +192,27 @@ internal class ClientJSImpl(private val modelClient: ModelClientV2) : ClientJS {
190192
}
191193
}
192194

195+
override fun createBranch(
196+
repositoryId: String,
197+
branchId: String,
198+
versionHash: String,
199+
failIfExists: Boolean,
200+
): Promise<Boolean> {
201+
return GlobalScope.promise {
202+
RepositoryId(repositoryId).let { repositoryId ->
203+
val branchReference = repositoryId.getBranchReference(branchId)
204+
205+
if (failIfExists) {
206+
throw TODO("implement server endpoint for this")
207+
} else {
208+
val version = modelClient.lazyLoadVersion(repositoryId, versionHash)
209+
modelClient.push(branchReference, version, version, true)
210+
return@promise true
211+
}
212+
}
213+
}
214+
}
215+
193216
override fun startReplicatedModel(
194217
repositoryId: String,
195218
branchId: String,

0 commit comments

Comments
 (0)