Skip to content

Commit 98e0cca

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

File tree

1 file changed

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

1 file changed

+29
-0
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,23 @@ 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
2124
import org.modelix.model.mutable.INodeIdGenerator
2225
import org.modelix.model.mutable.ModelixIdGenerator
26+
import org.modelix.model.mutable.VersionedModelTree
27+
import org.modelix.model.mutable.asMutableSingleThreaded
2328
import org.modelix.model.mutable.asMutableThreadSafe
2429
import org.modelix.model.mutable.load
2530
import org.modelix.model.mutable.withAutoTransactions
@@ -111,6 +116,8 @@ interface ClientJS {
111116
*/
112117
fun initRepository(repositoryId: String, useRoleIds: Boolean = true): Promise<Unit>
113118

119+
fun getHistoryRangeForBranch(repositoryId: String, branchId: String, skip: Int, limit: Int): Promise<Array<VersionInformationJS>>
120+
fun getHistoryRange(repositoryId: String, headVersion: String, skip: Int, limit: Int): Promise<Array<VersionInformationJS>>
114121
/**
115122
* Fetch existing branches for a given repository from the model server.
116123
*
@@ -192,6 +199,28 @@ internal class ClientJSImpl(private val modelClient: ModelClientV2) : ClientJS {
192199
}
193200
}
194201

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

0 commit comments

Comments
 (0)