Skip to content

Commit 0ab3554

Browse files
committed
feat(model-client): add getHistoryRangeForBranch to ClientJS
1 parent b4ee5d1 commit 0ab3554

File tree

1 file changed

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

1 file changed

+30
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ import kotlinx.coroutines.DelicateCoroutinesApi
88
import kotlinx.coroutines.GlobalScope
99
import kotlinx.coroutines.await
1010
import kotlinx.coroutines.promise
11+
import kotlinx.datetime.toJSDate
1112
import org.modelix.datastructures.model.IGenericModelTree
13+
import org.modelix.datastructures.objects.ObjectHash
1214
import org.modelix.model.TreeId
1315
import org.modelix.model.api.INode
1416
import org.modelix.model.api.INodeReference
1517
import org.modelix.model.api.JSNodeConverter
1618
import org.modelix.model.client.IdGenerator
1719
import org.modelix.model.data.ModelData
20+
import org.modelix.model.lazy.CLVersion
1821
import org.modelix.model.lazy.RepositoryId
1922
import org.modelix.model.lazy.createObjectStoreCache
2023
import org.modelix.model.mutable.DummyIdGenerator
@@ -111,6 +114,9 @@ interface ClientJS {
111114
*/
112115
fun initRepository(repositoryId: String, useRoleIds: Boolean = true): Promise<Unit>
113116

117+
fun getHistoryRangeForBranch(repositoryId: String, branchId: String, skip: Int, limit: Int): Promise<Array<VersionInformationJS>>
118+
fun getHistoryRange(repositoryId: String, headVersion: String, skip: Int, limit: Int): Promise<Array<VersionInformationJS>>
119+
114120
/**
115121
* Fetch existing branches for a given repository from the model server.
116122
*
@@ -192,6 +198,30 @@ internal class ClientJSImpl(private val modelClient: ModelClientV2) : ClientJS {
192198
}
193199
}
194200

201+
override fun getHistoryRangeForBranch(repositoryId: String, branchId: String, skip: Int, limit: Int) =
202+
GlobalScope.promise { modelClient.pullHash(RepositoryId(repositoryId).getBranchReference(branchId)) }
203+
.then { getHistoryRange(repositoryId, it, skip, limit) }
204+
.then { it }
205+
206+
override fun getHistoryRange(repositoryId: String, headVersion: String, skip: Int, limit: Int) =
207+
GlobalScope.promise {
208+
modelClient.getHistoryRange(
209+
RepositoryId(repositoryId),
210+
ObjectHash(headVersion),
211+
skip.toLong(),
212+
limit.toLong(),
213+
)
214+
.filterIsInstance<CLVersion>()
215+
.map {
216+
VersionInformationJS(
217+
it.author,
218+
it.getTimestamp()?.toJSDate(),
219+
it.getObjectHash().toString(),
220+
)
221+
}
222+
.toTypedArray()
223+
}
224+
195225
override fun dispose() {
196226
modelClient.close()
197227
}

0 commit comments

Comments
 (0)