Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ class NodeAdapterJS(val node: INode) : INodeJS_ {
}

override fun setReferenceTargetNode(role: ReferenceRole, target: INodeJS?) {
val unwrappedTarget = if (target == null) null else (target as NodeAdapterJS).node
node.asWritableNode().setReferenceTarget(IReferenceLinkReference.fromRoleOrString(role), unwrappedTarget?.asWritableNode())
if (target is NodeAdapterJS) {
node.asWritableNode().setReferenceTarget(IReferenceLinkReference.fromRoleOrString(role), target.node.asWritableNode())
} else {
val targetRef = target?.getReference()
setReferenceTargetRef(role, targetRef)
}
}

override fun setReferenceTargetRef(role: ReferenceRole, target: INodeReferenceJS?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,16 @@ sealed class IdSchemeJS() {
}

@JsExport
data class VersionInformationWithModelTree(val version: VersionInformationJS, val tree: MutableModelTreeJs)
data class VersionInformationWithModelTree(
/**
* The version information.
*/
val version: VersionInformationJS,
/**
* The model tree associated with the version.
*/
val tree: MutableModelTreeJs,
)

/**
* JS-API for [ModelClientV2].
Expand All @@ -104,6 +113,7 @@ data class VersionInformationWithModelTree(val version: VersionInformationJS, va
* See https://issues.modelix.org/issue/MODELIX-962
*/
@JsExport
@Suppress("TooManyFunctions")
interface ClientJS {

/**
Expand Down Expand Up @@ -211,10 +221,14 @@ data class ReplicatedModelParameters(
val repositoryId: String,
val branchId: String? = null,
val idScheme: IdSchemeJS,
val readonly: Boolean = false,
val versionHash: String? = null,
) {
init {
require((branchId != null) xor (versionHash != null)) { "Exactly one of branchId or versionHash must be provided" }
if (versionHash != null) {
require(readonly) { "versionHash requires readonly=true" }
}
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.modelix.model.client2

import kotlin.test.Test
import kotlin.test.assertFailsWith

class ReplicatedModelParametersTest {

@Test
fun test_valid_branchId() {
// Valid: branchId is positional 2nd arg
ReplicatedModelParameters("repo", "branch", IdSchemeJS.MODELIX)
}

@Test
fun test_valid_versionHash_with_readonly() {
// Valid: versionHash with readonly=true (branchId must be null)
ReplicatedModelParameters(
repositoryId = "repo",
branchId = null,
idScheme = IdSchemeJS.MODELIX,
readonly = true,
versionHash = "hash",
)
}

@Test
fun test_invalid_both_branchId_and_versionHash() {
// Invalid: cannot specify both branchId and versionHash
assertFailsWith<IllegalArgumentException> {
ReplicatedModelParameters(
repositoryId = "repo",
branchId = "branch",
idScheme = IdSchemeJS.MODELIX,
versionHash = "hash",
)
}
}

@Test
fun test_invalid_neither_branchId_nor_versionHash() {
// Invalid: must specify either branchId or versionHash
assertFailsWith<IllegalArgumentException> {
ReplicatedModelParameters(
repositoryId = "repo",
branchId = null,
idScheme = IdSchemeJS.MODELIX,
)
}
}

@Test
fun test_invalid_versionHash_without_readonly() {
// Invalid: versionHash requires readonly=true
assertFailsWith<IllegalArgumentException> {
ReplicatedModelParameters(
repositoryId = "repo",
branchId = null,
idScheme = IdSchemeJS.MODELIX,
readonly = false,
versionHash = "hash",
)
}
}
}
Loading
Loading