Skip to content

Commit 843f75a

Browse files
committed
feat(model-client): load readonly version in js client
1 parent 386eaf6 commit 843f75a

File tree

1 file changed

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

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ 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
1213
import org.modelix.model.TreeId
1314
import org.modelix.model.api.INode
1415
import org.modelix.model.api.INodeReference
1516
import org.modelix.model.api.JSNodeConverter
1617
import org.modelix.model.client.IdGenerator
1718
import org.modelix.model.data.ModelData
19+
import org.modelix.model.lazy.CLVersion
1820
import org.modelix.model.lazy.RepositoryId
1921
import org.modelix.model.lazy.createObjectStoreCache
2022
import org.modelix.model.mutable.DummyIdGenerator
2123
import org.modelix.model.mutable.INodeIdGenerator
2224
import org.modelix.model.mutable.ModelixIdGenerator
25+
import org.modelix.model.mutable.asMutableSingleThreaded
2326
import org.modelix.model.mutable.asMutableThreadSafe
2427
import org.modelix.model.mutable.load
2528
import org.modelix.model.mutable.withAutoTransactions
@@ -111,6 +114,8 @@ interface ClientJS {
111114
*/
112115
fun initRepository(repositoryId: String, useRoleIds: Boolean = true): Promise<Unit>
113116

117+
fun loadReadonlyVersion(repositoryId: String, versionHash: String): Promise<Pair<MutableModelTreeJs, VersionInformationJS>>
118+
114119
/**
115120
* Fetch existing branches for a given repository from the model server.
116121
*
@@ -192,6 +197,16 @@ internal class ClientJSImpl(private val modelClient: ModelClientV2) : ClientJS {
192197
}
193198
}
194199

200+
override fun loadReadonlyVersion(repositoryId: String, versionHash: String): Promise<Pair<MutableModelTreeJs, VersionInformationJS>> {
201+
return GlobalScope.promise {
202+
val version = modelClient.loadVersion(RepositoryId(repositoryId), versionHash, null)
203+
MutableModelTreeJsImpl(version.getModelTree().asMutableSingleThreaded()) to VersionInformationJS(
204+
(version as CLVersion).author,
205+
version.getTimestamp()?.toJSDate(),
206+
version.getContentHash())
207+
}
208+
}
209+
195210
override fun dispose() {
196211
modelClient.close()
197212
}

0 commit comments

Comments
 (0)