diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5feb4f0..565c2be 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,3 +67,37 @@ jobs: :sample-compose:main-parallel:ui:assembleDebug \ :sample-compose:categories:routing:assembleDebug \ :sample-compose:permissions:routing:assembleDebug + + ios-tests: + runs-on: macos-latest + timeout-minutes: 60 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '17' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Setup Android SDK + uses: android-actions/setup-android@v3 + with: + packages: platform-tools + + - name: Install Android SDK packages + run: | + sdkmanager --install \ + "platforms;android-36" \ + "build-tools;36.0.0" + + - name: Run iOS simulator tests + run: | + ./gradlew --no-daemon --stacktrace \ + :way:iosSimulatorArm64Test \ + :way-dsl:iosSimulatorArm64Test diff --git a/CHANGELOG.md b/CHANGELOG.md index 814bca0..734294c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## Unreleased +## 0.13.0 - 2026-11-09 ### Added @@ -14,6 +14,19 @@ * Parallel flows anywhere a `.dot` file allows them, regions may be local flows and parallel flows. * An included graph may have several parents in one region, `target(payload, via = parent)` picks the one to enter it from. + * Full targets: `target(payload, shop with shopId, item with itemId)` passes the payloads of every parameterized + ancestor (a missing one throws), so they are rebuilt when they are not alive, like a generated full target. + * `ParallelRef.regionId(child)` gives the region id of a child of a parallel flow, like a generated + `RegionId`, in place of `Schema.regionByName`. +* way-compose: `NodeHost(service, autoStart = false)` doesn't start the service and renders nothing until the app + calls `start(payload)`, for a start which waits for something (e.g. DataStore). + +### Fixed + +* Gradle plugin: the node builder of a local flow nested in a flow builds the targets of its children under its own + segment; the root segment was repeated (`settings.settings.general`) and the builder failed. +* Gradle plugin: a `history`/`deepHistory` child of a `parallelFlow` is no longer a region of the parallel flow, the + schema and the node builder failed for it. A parallel flow with only history children has no children. ## 0.12.0 - 2026-11-08 diff --git a/README.md b/README.md index ed4601c..4bac383 100644 --- a/README.md +++ b/README.md @@ -340,13 +340,27 @@ needs the parent it is entered from, the counterpart of a generated `ViaRegionId`: + +```kotlin +override val initialRegions = setOf(TabsGraph.tabs.regionId(TabsGraph.home)) +``` + The graph is checked when its `schema` or `nodeBuilder` is first used, with the rules of a `.dot` file: one root which is a flow or a parallel flow, no cycles, children under a root flow and under every parallel flow, several parents only for an included graph, no children under an included graph, history nodes in place, a factory for every node but a history one. Segments are `@`, so graph ids have to be unique among the graphs of a service. -Not supported, unlike `.dot` files: screens as regions of a parallel flow (wrap them in a flow), full targets (with -the payloads of ancestors, use `AbsoluteTarget`), typed region accessors (use `Schema.regionByName`) and a separate node +Not supported, unlike `.dot` files: screens as regions of a parallel flow (wrap them in a flow) and a separate node builder per local flow (include a graph instead). The target of a node under a parallel flow starts at its closest flow, not at the flow above the parallel one as in generated code; both resolve to the same node. @@ -690,7 +704,7 @@ a flow node extends `BaseFlowNode`. - `ComposableNode` interface with `@Composable fun Content(modifier: Modifier)` - A `ParallelFlowNode` renders by implementing `ComposableNode` — its `Content()` lays out the parallel and calls `NodeHost(regionId)` inside it to render each sub-region's screen stack. - `LocalNavigationService` — `CompositionLocal>` provided by `NodeHost(service)`. Available inside any `Content()` for reading state. -- `NodeHost(service)` composable — auto-starts service, observes root region's active node, renders `ComposableNode.Content()`, applies animated transitions. +- `NodeHost(service)` composable — auto-starts service (`autoStart = false` renders nothing until the app calls `start`), observes root region's active node, renders `ComposableNode.Content()`, applies animated transitions. - `LocalEventSink` — the `EventSink` of the node being rendered, provided by `NodeHost` to every node's `Content()`. Always use it in UI: an event sent from a screen's `Content()` starts at that screen, one sent from a parallel's `Content()` at the active children of its regions; it then reaches every parallel enclosing the node and bubbles up through each parallel's ancestors, like `service.send`, and a tap on a screen which is animating out after Back is dropped instead of being applied to the new screen. Outside any node (but under `LocalNavigationService`) it is the service itself, the root sink. - `NodeHost(regionId)` composable — renders the active screen in a specific sub-region. Call from a parallel node's `Content()` for each sub-region. Requires a parent `NodeHost(service)` to have provided `LocalNavigationService`. - `FocusedRegionHost(regionId)` composable — renders only the given sub-region and keeps the saved state of the other ones. diff --git a/ROADMAP.md b/ROADMAP.md index a795cf1..61fc2d7 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -18,14 +18,6 @@ hand-write an `AbsoluteTarget`. `AbsoluteTarget` stays as the load-bearing engin - **Value:** removes cross-schema navigation boilerplate for consumers. - **Trigger:** first app site that would otherwise hand-write an `AbsoluteTarget`. -### `NodeHost` auto-start opt-out -`NodeHost` calls `service.start()` without a payload when the service isn't started yet -(`way-compose/.../NodeHost.kt`), so an app that must read something (e.g. DataStore) before -`start(payload)` has to gate `NodeHost` behind its own "started" flag. -- **Approach:** `autoStart: Boolean = true` parameter on `NodeHost`; with `false`, render nothing until - `start()` is called. -- **Trigger:** first app that gates `NodeHost` behind its own "started" flag because of an async start. - ## Feature extensions (on demand) ### History under imported (cross-schema) flows diff --git a/gradle.properties b/gradle.properties index 38b3d8b..b0da3ca 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ kotlin.native.ignoreDisabledTargets=true android.useAndroidX=true -versionName=0.12.0 +versionName=0.13.0 pomGroupId=ru.kode pomDescription=Navigation library based on statechart-like node graphs pomUrl=https://github.com/appKODE/way diff --git a/way-compose/src/androidHostTest/kotlin/ru/kode/way/compose/EventSinkTest.kt b/way-compose/src/androidHostTest/kotlin/ru/kode/way/compose/EventSinkTest.kt index 15c34c0..7feee9f 100644 --- a/way-compose/src/androidHostTest/kotlin/ru/kode/way/compose/EventSinkTest.kt +++ b/way-compose/src/androidHostTest/kotlin/ru/kode/way/compose/EventSinkTest.kt @@ -33,6 +33,20 @@ class EventSinkTest { rule.waitForIdle() } + @Test + fun `host without auto start renders nothing until the service is started`() { + val fixture = FlowFixture() + rule.setContent { NodeHost(fixture.service, autoStart = false) } + rule.waitForIdle() + assertEquals(false, fixture.service.isStarted()) + assertTrue(fixture.screens.isEmpty()) + + rule.runOnIdle { fixture.service.start() } + rule.waitForIdle() + + assertTrue("main was never rendered", fixture.screen("main").sinks.isNotEmpty()) + } + @Test fun `sink stays the same instance across recompositions of a node`() { val fixture = FlowFixture().host() diff --git a/way-compose/src/commonMain/kotlin/ru/kode/way/compose/NodeHost.kt b/way-compose/src/commonMain/kotlin/ru/kode/way/compose/NodeHost.kt index 445ecc2..01c134b 100644 --- a/way-compose/src/commonMain/kotlin/ru/kode/way/compose/NodeHost.kt +++ b/way-compose/src/commonMain/kotlin/ru/kode/way/compose/NodeHost.kt @@ -40,14 +40,20 @@ import ru.kode.way.isRegionAtRoot import ru.kode.way.resolveAbsolute import ru.kode.way.startsWith +/** + * Renders the root of [service]. With [autoStart] (default) it starts a service which is not started yet without a + * payload; with `false` it renders nothing until the app calls `service.start(payload)`, e.g. after an async read of + * the start payload. + */ @ExperimentalAnimationApi @Composable fun NodeHost( service: NavigationService<*>, transitionSpec: AnimatedContentTransitionScope.() -> ContentTransform = defaultTransitionSpec, + autoStart: Boolean = true, ) { - LaunchedEffect(service) { - if (!service.isStarted()) { + LaunchedEffect(service, autoStart) { + if (autoStart && !service.isStarted()) { service.start() } } diff --git a/way-dsl/src/commonMain/kotlin/ru/kode/way/dsl/Graph.kt b/way-dsl/src/commonMain/kotlin/ru/kode/way/dsl/Graph.kt index 675af11..8daa43a 100644 --- a/way-dsl/src/commonMain/kotlin/ru/kode/way/dsl/Graph.kt +++ b/way-dsl/src/commonMain/kotlin/ru/kode/way/dsl/Graph.kt @@ -6,6 +6,7 @@ import ru.kode.way.HistoryTarget import ru.kode.way.NodeBuilder import ru.kode.way.NullPayload import ru.kode.way.Path +import ru.kode.way.RegionId import ru.kode.way.Schema import ru.kode.way.ScreenTarget import ru.kode.way.Segment @@ -261,21 +262,56 @@ sealed class NodeRef( } return Path(segments) } + + /** + * [FlowTarget.ancestorPayloads] / [ScreenTarget.ancestorPayloads] of a full target: [ancestors] must be the payloads + * of every parameterized ancestor of this node (entered through [via]) below the root of the graph, which is always + * alive, as the arguments of a generated full target are. No [ancestors] is a short target. + */ + internal fun ancestorPayloads(ancestors: Array, via: NodeRef? = null): Map { + if (ancestors.isEmpty()) return emptyMap() + val required = generateSequence(via ?: graph.parentsOf(this).firstOrNull(), graph::parentOf) + .filter { it.parameterized && graph.parentsOf(it).isNotEmpty() } + .toList() + val payloads = ancestors.associate { + require(it.ref in required) { "'${it.ref.id}' is not a parameterized ancestor of '$id'" } + it.ref.segment to it.value + } + val missing = required.filter { it.segment !in payloads } + require(missing.isEmpty()) { + "full target of '$id' has no payloads for parameterized ancestors: ${missing.asReversed().joinToString { it.id }}" + } + return payloads + } } +/** A payload of a parameterized ancestor in a full target, made with [with]. */ +class AncestorPayload internal constructor(internal val ref: NodeRef, internal val value: Any?) + +/** The [payload] of this parameterized flow when it is an ancestor in a full target. */ +infix fun

FlowNodeRef.with(payload: P): AncestorPayload = AncestorPayload(this, payload) + +/** The [payload] of this parameterized screen when it is an ancestor in a full target. */ +infix fun

ParameterizedScreenRef

.with(payload: P): AncestorPayload = AncestorPayload(this, payload) + /** A flow or a parallel flow with a parameter of type [P] (`Unit` for none) and a result of type [R]. */ sealed class FlowNodeRef(graph: Graph, id: String, parameterized: Boolean, nullable: Boolean) : NodeRef(graph, id, parameterized, nullable) { /** * A target which starts this flow with [payload]. An included graph with several parents needs [via], the parent - * it is entered from (a generated `Via` target). + * it is entered from (a generated `Via` target). Payloads of parameterized [ancestors] + * (`shop with shopId`) make it a full target, which rebuilds them when they are not alive, like a generated full target. */ - fun target(payload: P, via: NodeRef? = null): FlowTarget = - FlowTarget(targetPath(via), if (parameterized) payload ?: NullPayload else null) + fun target(payload: P, vararg ancestors: AncestorPayload, via: NodeRef? = null): FlowTarget = FlowTarget( + targetPath(via), + if (parameterized) payload ?: NullPayload else null, + ancestorPayloads(ancestors, via), + ) } /** A target of a flow without a parameter, see [FlowNodeRef.target]. */ -fun FlowNodeRef.target(via: NodeRef? = null): FlowTarget = target(Unit, via) +fun FlowNodeRef.target(vararg ancestors: AncestorPayload, via: NodeRef? = null): FlowTarget = + target(Unit, *ancestors, via = via) class FlowRef internal constructor( graph: Graph, @@ -290,15 +326,29 @@ class ParallelRef internal constructor( id: String, parameterized: Boolean, nullable: Boolean, -) : FlowNodeRef(graph, id, parameterized, nullable) +) : FlowNodeRef(graph, id, parameterized, nullable) { + /** + * Id of the region which starts at [child], relative to the schema of this parallel flow, like a generated + * `RegionId`. Use it in `initialRegions`, `startRegion`, `DispatchBackTo` and `NodeHost(regionId = ...)`. + */ + fun regionId(child: FlowNodeRef<*, *>): RegionId { + graph.schema // validates and freezes the graph + require(this in graph.parentsOf(child)) { "'${child.id}' is not a region of parallel '$id'" } + return RegionId(Path(listOf(segment, child.segment))) + } +} class ScreenRef internal constructor(graph: Graph, id: String) : NodeRef(graph, id, parameterized = false) { - fun target(): ScreenTarget = ScreenTarget(targetPath()) + /** A target of this screen, a full one with payloads of parameterized [ancestors], see [FlowNodeRef.target]. */ + fun target(vararg ancestors: AncestorPayload): ScreenTarget = + ScreenTarget(targetPath(), ancestorPayloads = ancestorPayloads(ancestors)) } class ParameterizedScreenRef

internal constructor(graph: Graph, id: String) : NodeRef(graph, id, parameterized = true) { - fun target(payload: P): ScreenTarget = ScreenTarget(targetPath(), payload ?: NullPayload) + /** A target of this screen, a full one with payloads of parameterized [ancestors], see [FlowNodeRef.target]. */ + fun target(payload: P, vararg ancestors: AncestorPayload): ScreenTarget = + ScreenTarget(targetPath(), payload ?: NullPayload, ancestorPayloads(ancestors)) } /** diff --git a/way-dsl/src/commonTest/kotlin/ru/kode/way/TestNodeBuilder.kt b/way-dsl/src/commonTest/kotlin/ru/kode/way/TestNodeBuilder.kt deleted file mode 100644 index 512ab4d..0000000 --- a/way-dsl/src/commonTest/kotlin/ru/kode/way/TestNodeBuilder.kt +++ /dev/null @@ -1,20 +0,0 @@ -package ru.kode.way - -class TestNodeBuilder( - override val schema: Schema, - private val mapping: Map, - private val throwAtBuild: Path? = null, - private val throwAtBuildMessage: String = "TestNodeBuilder.build injected throw", - private val throwOnInvalidateCache: Boolean = false, - private val throwOnInvalidateCacheMessage: String = "TestNodeBuilder.invalidateCache injected throw", -) : NodeBuilder { - override fun build(path: Path, payloads: Map, rootSegmentAlias: Segment?): Node { - if (path == throwAtBuild) error(throwAtBuildMessage) - return mapping[path.segments.joinToString(".") { it.name }] - ?: error("no test node mapping for path $path. Existing keys: ${mapping.keys}") - } - - override fun invalidateCache(alivePaths: Set) { - if (throwOnInvalidateCache) error(throwOnInvalidateCacheMessage) - } -} diff --git a/way-dsl/src/commonTest/kotlin/ru/kode/way/dsl/DslParityTest.kt b/way-dsl/src/commonTest/kotlin/ru/kode/way/dsl/DslParityTest.kt index a8673d3..7a942ba 100644 --- a/way-dsl/src/commonTest/kotlin/ru/kode/way/dsl/DslParityTest.kt +++ b/way-dsl/src/commonTest/kotlin/ru/kode/way/dsl/DslParityTest.kt @@ -1,5 +1,6 @@ package ru.kode.way.dsl +import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.ShouldSpec import io.kotest.matchers.collections.shouldContainExactly import io.kotest.matchers.shouldBe @@ -17,13 +18,13 @@ import ru.kode.way.TestEvent import ru.kode.way.TestFlowNode import ru.kode.way.TestFlowNodeWithResult import ru.kode.way.TestFlowTransitionSpec -import ru.kode.way.TestNodeBuilder import ru.kode.way.TestParallelNode import ru.kode.way.TestParallelTransitionSpec import ru.kode.way.TestScreenNode import ru.kode.way.dslparity.AppChildFinishRequest import ru.kode.way.dslparity.AppNodeBuilder import ru.kode.way.dslparity.DslParityAppSchema +import ru.kode.way.dslparity.SettingsNodeBuilder import ru.kode.way.dslparity.app import ru.kode.way.dslparity.counter.CounterNodeBuilder import ru.kode.way.dslparity.counter.DslParityCounterSchema @@ -35,8 +36,13 @@ import ru.kode.way.dslparity.fanin.shared import ru.kode.way.dslparity.feed.DslParityFeedSchema import ru.kode.way.dslparity.feed.FeedNodeBuilder import ru.kode.way.dslparity.feed.feed +import ru.kode.way.dslparity.full.DslParityFullSchema +import ru.kode.way.dslparity.full.FullNodeBuilder +import ru.kode.way.dslparity.full.PromoNodeBuilder +import ru.kode.way.dslparity.full.full import ru.kode.way.dslparity.history.DslParityHistorySchema import ru.kode.way.dslparity.history.HistNodeBuilder +import ru.kode.way.dslparity.history.ShopNodeBuilder import ru.kode.way.dslparity.history.hist import ru.kode.way.dslparity.history.shop import ru.kode.way.dslparity.home.DslParityHomeSchema @@ -69,6 +75,9 @@ import ru.kode.way.dslparity.tabs.DslParityTabsSchema import ru.kode.way.dslparity.tabs.TabsChildFinishRequest import ru.kode.way.dslparity.tabs.TabsNodeBuilder import ru.kode.way.tr +import ru.kode.way.dslparity.full.ShopNodeBuilder as FullShopNodeBuilder +import ru.kode.way.dslparity.full.promo as fullPromo +import ru.kode.way.dslparity.full.shop as fullShop import ru.kode.way.dslparity.nested.TabsNodeBuilder as NestedTabsNodeBuilder /** The DSL counterparts of `dsl-parity-*.dot`. */ @@ -266,10 +275,13 @@ private fun generatedAppBuilder(): NodeBuilder { override fun createIntroNode() = TestScreenNode() override fun createDetailsNode(id: String?) = TestScreenNode(payload = id) - // the generated SettingsNodeBuilder resolves "general" to app.settings.general under the "settings" alias and - // fails to build it, so the local flow is built by hand - override fun createSettingsNodeBuilder(): NodeBuilder = - TestNodeBuilder(schema, mapOf("settings" to settingsNode(spec), "settings.general" to TestScreenNode())) + override fun createSettingsNodeBuilder(): NodeBuilder = SettingsNodeBuilder( + object : SettingsNodeBuilder.Factory { + override fun createRootNode() = settingsNode(spec) + override fun createGeneralNode() = TestScreenNode() + }, + schema, + ) override fun createLoginNodeBuilder(userName: String): NodeBuilder = LoginNodeBuilder( object : LoginNodeBuilder.Factory { @@ -361,6 +373,63 @@ private fun dslTabsBuilder(): NodeBuilder = TabsGraph.nodeBuilder { } } +private object FullGraph : Graph("DslParityFull") { + val full = flow("full") + val home = screen("home") + val shop = parameterizedFlow("shop") + val shopScreen = screen("shopScreen") + val item = parameterizedScreen("item") + val promo = flow("promo") + val promoScreen = screen("promoScreen") + + init { + full to home + full to shop to shopScreen + shop to item to promo to promoScreen + } +} + +private fun fullRootNode(home: Target, promo: Target) = + TestFlowNode(initialTarget = home, transitions = listOf(tr("P", promo))) + +private fun generatedFullBuilder(): NodeBuilder { + val schema = DslParityFullSchema() + return FullNodeBuilder( + object : FullNodeBuilder.Factory { + override fun createRootNode() = fullRootNode(Target.full.home, Target.full.promo("s1", 5)) + override fun createHomeNode() = TestScreenNode() + override fun createShopNodeBuilder(shopId: String): NodeBuilder = FullShopNodeBuilder( + object : FullShopNodeBuilder.Factory { + override fun createRootNode(shopId: String) = + TestFlowNode(initialTarget = Target.fullShop.shopScreen, payload = shopId) + override fun createShopScreenNode() = TestScreenNode() + override fun createItemNode(itemId: Int) = TestScreenNode(payload = itemId) + }, + schema, + ) + override fun createPromoNodeBuilder(): NodeBuilder = PromoNodeBuilder( + object : PromoNodeBuilder.Factory { + override fun createRootNode() = TestFlowNode(initialTarget = Target.fullPromo.promoScreen) + override fun createPromoScreenNode() = TestScreenNode() + }, + schema, + ) + }, + schema, + ) +} + +private fun dslFullBuilder(): NodeBuilder = FullGraph.nodeBuilder { + val promo = FullGraph.promo.target(FullGraph.shop with "s1", FullGraph.item with 5) + flow(FullGraph.full) { fullRootNode(FullGraph.home.target(), promo) } + screen(FullGraph.home) { TestScreenNode() } + flow(FullGraph.shop) { TestFlowNode(initialTarget = FullGraph.shopScreen.target(), payload = it) } + screen(FullGraph.shopScreen) { TestScreenNode() } + screen(FullGraph.item) { TestScreenNode(payload = it) } + flow(FullGraph.promo) { TestFlowNode(initialTarget = FullGraph.promoScreen.target()) } + screen(FullGraph.promoScreen) { TestScreenNode() } +} + private class ParamsSpec( val paramsScreen: Target, val counter: (Int?) -> Target, @@ -465,10 +534,13 @@ private fun generatedHistoryBuilder(): NodeBuilder { override fun createRootNode() = histRootNode(spec) override fun createHomeNode() = TestScreenNode() - // way#19: the generated ShopNodeBuilder duplicates the root segment of the nested flow, built by hand - override fun createShopNodeBuilder(): NodeBuilder = TestNodeBuilder( + override fun createShopNodeBuilder(): NodeBuilder = ShopNodeBuilder( + object : ShopNodeBuilder.Factory { + override fun createRootNode() = shopNode(spec) + override fun createCartNode() = TestScreenNode() + override fun createCheckoutNode() = TestScreenNode() + }, schema, - mapOf("shop" to shopNode(spec), "shop.cart" to TestScreenNode(), "shop.cart.checkout" to TestScreenNode()), ) }, schema, @@ -496,8 +568,7 @@ private fun dslHistoryBuilder(): NodeBuilder { private class NestedSpec( val start: Target, val tabs: Target, - /** Only in the DSL graph: the generated one can't enter a parallel flow with a history child. */ - val tabsHistory: Target?, + val tabsHistory: Target, val leftScreen: Target, val leftDetails: Target, val inner: Target, @@ -507,7 +578,7 @@ private class NestedSpec( private fun mainRootNode(spec: NestedSpec) = TestFlowNode( initialTarget = spec.start, - transitions = listOfNotNull(tr("T", spec.tabs), tr("B", spec.start), spec.tabsHistory?.let { tr("TH", it) }), + transitions = listOf(tr("T", spec.tabs), tr("B", spec.start), tr("TH", spec.tabsHistory)), ) private fun leftNode(spec: NestedSpec) = TestFlowNode( @@ -527,7 +598,7 @@ private fun generatedNestedBuilder(): NodeBuilder { val spec = NestedSpec( start = Target.main.start, tabs = Target.main.tabs, - tabsHistory = null, + tabsHistory = Target.main.tabsHistory, leftScreen = Target.left.leftScreen, leftDetails = Target.left.leftDetails, inner = Target.main.inner, @@ -773,6 +844,22 @@ class DslParityTest : } } + should("rebuild ancestors which are not alive from a full target as the generated graph does") { + val (generated, _) = run(generatedFullBuilder(), rootPayload = null, listOf("P")) + val (dsl, _) = run(dslFullBuilder(), rootPayload = null, listOf("P")) + + dsl shouldBe generated + dsl.last().single() shouldBe + "full.shop.item.promo.promoScreen [full=null, full.shop=s1, full.shop.item=5, full.shop.item.promo=null, " + + "full.shop.item.promo.promoScreen=null]" + shouldThrow { FullGraph.shopScreen.target(FullGraph.item with 5) }.message shouldBe + "'item' is not a parameterized ancestor of 'shopScreen'" + shouldThrow { FullGraph.item.target(5, FullGraph.item with 5) }.message shouldBe + "'item' is not a parameterized ancestor of 'item'" + shouldThrow { FullGraph.promo.target(FullGraph.item with 5) }.message shouldBe + "full target of 'promo' has no payloads for parameterized ancestors: shop" + } + should("navigate to history nodes as the generated graph does") { val events = listOf("S", "C", "H", "D", "H", "R") @@ -807,7 +894,9 @@ class DslParityTest : ) dsl[4].single() shouldStartWith "main.start " // the deep history of the outer parallel flow restores its regions, the nested ones included + val (generatedWithHistory, _) = run(generatedNestedBuilder(), rootPayload = null, events + "TH") val (withHistory, _) = run(dslNestedBuilder(), rootPayload = null, events + "TH") + withHistory shouldBe generatedWithHistory withHistory.last() shouldBe dsl[3] } diff --git a/way-dsl/src/commonTest/kotlin/ru/kode/way/dsl/GraphTest.kt b/way-dsl/src/commonTest/kotlin/ru/kode/way/dsl/GraphTest.kt index 17cebf1..509a412 100644 --- a/way-dsl/src/commonTest/kotlin/ru/kode/way/dsl/GraphTest.kt +++ b/way-dsl/src/commonTest/kotlin/ru/kode/way/dsl/GraphTest.kt @@ -412,6 +412,18 @@ class GraphTest : HistoryTarget(Path(listOf(graph.main.segment, graph.tabs.segment)), deep = true) } + should("give the region id of a parallel's child relative to the parallel's schema") { + val graph = NestedParallelGraph() + val tabsRegions = graph.schema.childSchemas.getValue(graph.tabs.segment).regions + val innerRegions = graph.schema.childSchemas.getValue(graph.inner.segment).regions + + graph.tabs.regionId(graph.left) shouldBe tabsRegions.first() + graph.inner.regionId(graph.right) shouldBe innerRegions[0] + graph.inner.regionId(graph.feed) shouldBe innerRegions[1] + shouldThrow { graph.tabs.regionId(graph.right) }.message shouldContain + "'right' is not a region of parallel 'tabs'" + } + should("reject a parallel flow without children") { fun invalid(build: () -> Graph) = shouldThrow { build().schema }.message!! diff --git a/way-dsl/src/commonTest/way/dsl-parity-full.dot b/way-dsl/src/commonTest/way/dsl-parity-full.dot new file mode 100644 index 0000000..8f26ea5 --- /dev/null +++ b/way-dsl/src/commonTest/way/dsl-parity-full.dot @@ -0,0 +1,13 @@ +digraph DslParityFull { + package = "ru.kode.way.dslparity.full" + + // Mirrored by DslParityTest.kt: a full target into a branch whose parameterized ancestors are not alive. + full [type = flow] + shop [type = flow, parameterName = shopId, parameterType = "kotlin.String"] + item [parameterName = itemId, parameterType = "kotlin.Int"] + promo [type = flow] + + full -> home + full -> shop -> shopScreen + shop -> item -> promo -> promoScreen +} diff --git a/way-dsl/src/commonTest/way/dsl-parity-nested.dot b/way-dsl/src/commonTest/way/dsl-parity-nested.dot index 0597d06..4cc08bb 100644 --- a/way-dsl/src/commonTest/way/dsl-parity-nested.dot +++ b/way-dsl/src/commonTest/way/dsl-parity-nested.dot @@ -1,14 +1,15 @@ digraph DslParityNested { package = "ru.kode.way.dslparity.nested" - // Mirrored by DslParityTest.kt: a parallel under a flow whose region holds another parallel. The DSL graph also has a - // history of the outer parallel, which codegen lists as a region and fails to build. + // Mirrored by DslParityTest.kt: a parallel under a flow whose region holds another parallel, with a deep history of + // the outer parallel. main [type = flow] tabs [type = parallelFlow] left [type = flow] inner [type = parallelFlow] right [type = flow] feed [type = schema] + tabsHistory [type = deepHistory] main -> start main -> tabs @@ -16,4 +17,5 @@ digraph DslParityNested { left -> inner inner -> right -> rightScreen inner -> feed + tabs -> tabsHistory } diff --git a/way-gradle-plugin/src/main/kotlin/ru/kode/way/gradle/AdjacencyList.kt b/way-gradle-plugin/src/main/kotlin/ru/kode/way/gradle/AdjacencyList.kt index b2888eb..a428610 100644 --- a/way-gradle-plugin/src/main/kotlin/ru/kode/way/gradle/AdjacencyList.kt +++ b/way-gradle-plugin/src/main/kotlin/ru/kode/way/gradle/AdjacencyList.kt @@ -164,7 +164,8 @@ internal fun buildRegionRoots(adjacencyList: AdjacencyList): List { if (root !is Node.Flow.LocalParallel) regionRoots.add(root) adjacencyList.forEach { (node, children) -> if (node is Node.Flow.LocalParallel && adjacencyList.findParent(node) !is Node.Flow.LocalParallel) { - regionRoots.addAll(children) + // a history child of a parallel only restores its regions, it is not a region itself + regionRoots.addAll(children.filterNot { it is Node.History }) } } return regionRoots diff --git a/way-gradle-plugin/src/main/kotlin/ru/kode/way/gradle/NodeBuilderCodegen.kt b/way-gradle-plugin/src/main/kotlin/ru/kode/way/gradle/NodeBuilderCodegen.kt index 13e27d9..48e5690 100644 --- a/way-gradle-plugin/src/main/kotlin/ru/kode/way/gradle/NodeBuilderCodegen.kt +++ b/way-gradle-plugin/src/main/kotlin/ru/kode/way/gradle/NodeBuilderCodegen.kt @@ -266,7 +266,7 @@ internal fun buildNodeBuilderTypeSpec( // For parallel nodes: emit named val RegionId constants so users never need // to hardcode Path strings for sub-region lookups. if (flow is Node.Flow.LocalParallel) { - adjacencyList[flow].orEmpty().forEach { child -> + adjacencyList[flow].orEmpty().filterNot { it is Node.History }.forEach { child -> addProperty( PropertySpec .builder("${child.id}RegionId", REGION_ID) @@ -358,8 +358,12 @@ internal fun buildNodeBuilderTypeSpec( ) } } - .addFunction(buildTargetOrErrorFunSpec()) + // A non-root flow shares the schema of its root: its targets come from the schema root, so they are re-based + // onto this flow's own segment (or its alias), else the alias would replace the schema root and repeat this one. .apply { + val ownRoot = if (isRootNode) null else OwnRoot(buildSegmentId(flow), reversedParents(flow, adjacencyList).size) + addFunction(buildTargetOrErrorFunSpec(ownRoot)) + // only a root flow builds nested flows (and so fan-in schemas) itself if (lazyNodeBuilderFactories.keys.any { adjacencyList.isFanIn(it) }) addFunction(buildTargetsOrErrorFunSpec()) } .addFunction(buildPayloadOrErrorFunSpec()) @@ -579,6 +583,9 @@ private fun buildFanInLazyNodeBuilderFunSpec(node: Node.Flow, flowFactoryName: S .endControlFlow() .build() +/** A non-root flow's own segment id and the length of its path from the schema root, itself included. */ +private data class OwnRoot(val segmentId: String, val prefixSize: Int) + private fun buildTargetsOrErrorFunSpec(): FunSpec = FunSpec.builder(TARGETS_OR_ERROR_FUN_NAME) .returns(LIST.parameterizedBy(PATH)) .addParameter("segment", SEGMENT) @@ -592,16 +599,34 @@ private fun buildTargetsOrErrorFunSpec(): FunSpec = FunSpec.builder(TARGETS_OR_E ) .build() -private fun buildTargetOrErrorFunSpec(): FunSpec = FunSpec.builder(TARGET_OR_ERROR_FUN_NAME) +private fun buildTargetOrErrorFunSpec(ownRoot: OwnRoot?): FunSpec = FunSpec.builder(TARGET_OR_ERROR_FUN_NAME) .returns(PATH) .addParameter("segment", SEGMENT) .addParameter("rootSegmentAlias", SEGMENT.copy(nullable = true)) - .addCode( - "return %L.regions.firstNotNullOfOrNull·{·%L.target(it,${NBSP}segment, rootSegmentAlias)·}·?: error(%P)", - SCHEMA_PARAMETER_NAME, - SCHEMA_PARAMETER_NAME, - "internal error: no target generated for segment \"\${segment.id}\"", - ) + .apply { + if (ownRoot == null) { + addCode( + "return %L.regions.firstNotNullOfOrNull·{·%L.target(it,${NBSP}segment, rootSegmentAlias)·}·?: error(%P)", + SCHEMA_PARAMETER_NAME, + SCHEMA_PARAMETER_NAME, + "internal error: no target generated for segment \"\${segment.id}\"", + ) + } else { + addStatement( + "val path = %L.regions.firstNotNullOfOrNull·{·%L.target(it,${NBSP}segment, null)·}·?: error(%P)", + SCHEMA_PARAMETER_NAME, + SCHEMA_PARAMETER_NAME, + "internal error: no target generated for segment \"\${segment.id}\"", + ) + addStatement( + "return %T(listOf(rootSegmentAlias·?: %T(%S)) + path.segments.drop(%L))", + PATH, + SEGMENT, + ownRoot.segmentId, + ownRoot.prefixSize, + ) + } + } .build() private fun buildPayloadOrErrorFunSpec(): FunSpec = FunSpec.builder(PAYLOAD_OR_ERROR_FUN_NAME) diff --git a/way-gradle-plugin/src/main/kotlin/ru/kode/way/gradle/Parser.kt b/way-gradle-plugin/src/main/kotlin/ru/kode/way/gradle/Parser.kt index 3ec1991..b52f8d5 100644 --- a/way-gradle-plugin/src/main/kotlin/ru/kode/way/gradle/Parser.kt +++ b/way-gradle-plugin/src/main/kotlin/ru/kode/way/gradle/Parser.kt @@ -398,7 +398,7 @@ private fun validateNoEmptyFlows(adjacencyList: AdjacencyList) { // Imported (schema) flows are excluded — they always appear childless here by design. val nodesWithIncoming = adjacencyList.values.flatten().toSet() for ((node, children) in adjacencyList) { - if (node is Node.Flow.LocalParallel && children.isEmpty()) { + if (node is Node.Flow.LocalParallel && children.none { it !is Node.History }) { error("parallel node \"${node.id}\" has no children; a parallel node must have at least one child flow") } if (node is Node.Flow.Local && node !in nodesWithIncoming && children.isEmpty()) { diff --git a/way-gradle-plugin/src/test/kotlin/ru/kode/way/gradle/NodeBuilderGenerateTest.kt b/way-gradle-plugin/src/test/kotlin/ru/kode/way/gradle/NodeBuilderGenerateTest.kt index b1292f9..764b0fc 100644 --- a/way-gradle-plugin/src/test/kotlin/ru/kode/way/gradle/NodeBuilderGenerateTest.kt +++ b/way-gradle-plugin/src/test/kotlin/ru/kode/way/gradle/NodeBuilderGenerateTest.kt @@ -52,5 +52,15 @@ class NodeBuilderGenerateTest : expectedOutputFiles = listOf("Fi01appNodeBuilder.txt"), testName = "imported schema reachable from several parents is built per path with that path's payloads", ), + TestCase( + schemaFile = "node-builders-nested-local-flow.dot", + expectedOutputFiles = listOf("Nlf01settingsNodeBuilder.txt"), + testName = "nested local flow builds its children under its own segment", + ), + TestCase( + schemaFile = "schema-parallel-history.dot", + expectedOutputFiles = listOf("Ph01mainNodeBuilder.txt", "Ph01tabsNodeBuilder.txt"), + testName = "history child of a parallel is not a region", + ), ) { runTest(it) } }) diff --git a/way-gradle-plugin/src/test/kotlin/ru/kode/way/gradle/SchemaGenerateTest.kt b/way-gradle-plugin/src/test/kotlin/ru/kode/way/gradle/SchemaGenerateTest.kt index 6346fda..91ab603 100644 --- a/way-gradle-plugin/src/test/kotlin/ru/kode/way/gradle/SchemaGenerateTest.kt +++ b/way-gradle-plugin/src/test/kotlin/ru/kode/way/gradle/SchemaGenerateTest.kt @@ -49,6 +49,11 @@ class SchemaGenerateTest : ), testName = "multiple parallel in one schema", ), + TestCase( + schemaFile = "schema-parallel-history.dot", + expectedOutputFiles = listOf("schema-parallel-history.txt", "Ph01tabsSchema.txt"), + testName = "history child of a parallel is not a region", + ), // These two fixtures only prove that two independently valid graphs codegen correctly and // differently from each other — they do NOT exercise resolveOverriddenDotFiles itself (no // source-set resolution happens here, each file is codegenned standalone). The actual diff --git a/way-gradle-plugin/src/test/resources/Nb01loginNodeBuilder.txt b/way-gradle-plugin/src/test/resources/Nb01loginNodeBuilder.txt index e7a7188..7c151f8 100644 --- a/way-gradle-plugin/src/test/resources/Nb01loginNodeBuilder.txt +++ b/way-gradle-plugin/src/test/resources/Nb01loginNodeBuilder.txt @@ -37,7 +37,10 @@ public class Nb01loginNodeBuilder( override fun invalidateCache(alivePaths: Set): Unit = Unit - public fun targetOrError(segment: Segment, rootSegmentAlias: Segment?): Path = schema.regions.firstNotNullOfOrNull { schema.target(it, segment, rootSegmentAlias) } ?: error("""internal error: no target generated for segment "${segment.id}"""") + public fun targetOrError(segment: Segment, rootSegmentAlias: Segment?): Path { + val path = schema.regions.firstNotNullOfOrNull { schema.target(it, segment, null) } ?: error("""internal error: no target generated for segment "${segment.id}"""") + return Path(listOf(rootSegmentAlias ?: Segment("nb01login@NodeBuildersTest01:src/test/resources/node-builders-multiple-flows.dot")) + path.segments.drop(2)) + } @Suppress("UNCHECKED_CAST") public fun payloadOrError( diff --git a/way-gradle-plugin/src/test/resources/Nb01onboardingNodeBuilder.txt b/way-gradle-plugin/src/test/resources/Nb01onboardingNodeBuilder.txt index 9178b34..28655f1 100644 --- a/way-gradle-plugin/src/test/resources/Nb01onboardingNodeBuilder.txt +++ b/way-gradle-plugin/src/test/resources/Nb01onboardingNodeBuilder.txt @@ -37,7 +37,10 @@ public class Nb01onboardingNodeBuilder( override fun invalidateCache(alivePaths: Set): Unit = Unit - public fun targetOrError(segment: Segment, rootSegmentAlias: Segment?): Path = schema.regions.firstNotNullOfOrNull { schema.target(it, segment, rootSegmentAlias) } ?: error("""internal error: no target generated for segment "${segment.id}"""") + public fun targetOrError(segment: Segment, rootSegmentAlias: Segment?): Path { + val path = schema.regions.firstNotNullOfOrNull { schema.target(it, segment, null) } ?: error("""internal error: no target generated for segment "${segment.id}"""") + return Path(listOf(rootSegmentAlias ?: Segment("nb01onboarding@NodeBuildersTest01:src/test/resources/node-builders-multiple-flows.dot")) + path.segments.drop(4)) + } @Suppress("UNCHECKED_CAST") public fun payloadOrError( diff --git a/way-gradle-plugin/src/test/resources/Nlf01settingsNodeBuilder.txt b/way-gradle-plugin/src/test/resources/Nlf01settingsNodeBuilder.txt new file mode 100644 index 0000000..52e25ce --- /dev/null +++ b/way-gradle-plugin/src/test/resources/Nlf01settingsNodeBuilder.txt @@ -0,0 +1,61 @@ +package ru.kode.test.app.schema + +import kotlin.Any +import kotlin.Suppress +import kotlin.Unit +import kotlin.collections.Map +import kotlin.collections.Set +import ru.kode.way.FlowNode +import ru.kode.way.MissingPayloadException +import ru.kode.way.Node +import ru.kode.way.NodeBuilder +import ru.kode.way.NullPayload +import ru.kode.way.Path +import ru.kode.way.ScreenNode +import ru.kode.way.Segment +import ru.kode.way.firstSegment + +public class Nlf01settingsNodeBuilder( + private val nodeFactory: Factory, + override val schema: NestedLocalFlowSchema, +) : NodeBuilder { + override fun build( + path: Path, + payloads: Map, + rootSegmentAlias: Segment?, + ): Node { + val rootPath = rootSegmentAlias?.let { Path(it) } ?: Path(Segment("nlf01settings@NestedLocalFlow:src/test/resources/node-builders-nested-local-flow.dot")) + check(path.firstSegment().id == rootPath.firstSegment().id) { + """illegal path build requested for "nlf01settings" node: $path""" + } + return when { + path == rootPath -> nodeFactory.createRootNode() + path == targetOrError(Segment("nlf01general@NestedLocalFlow:src/test/resources/node-builders-nested-local-flow.dot"), rootSegmentAlias) -> nodeFactory.createNlf01generalNode() + else -> error("""illegal path build requested for "nlf01settings" node: $path""") + } + } + + override fun invalidateCache(alivePaths: Set): Unit = Unit + + public fun targetOrError(segment: Segment, rootSegmentAlias: Segment?): Path { + val path = schema.regions.firstNotNullOfOrNull { schema.target(it, segment, null) } ?: error("""internal error: no target generated for segment "${segment.id}"""") + return Path(listOf(rootSegmentAlias ?: Segment("nlf01settings@NestedLocalFlow:src/test/resources/node-builders-nested-local-flow.dot")) + path.segments.drop(2)) + } + + @Suppress("UNCHECKED_CAST") + public fun payloadOrError( + segment: Segment, + payloads: Map, + rootSegmentAlias: Segment?, + ): T { + val targetPath = targetOrError(segment, rootSegmentAlias) + val payload = payloads[targetPath] ?: throw MissingPayloadException(targetPath) + return (if (payload === NullPayload) null else payload) as T + } + + public interface Factory { + public fun createRootNode(): FlowNode<*> + + public fun createNlf01generalNode(): ScreenNode + } +} diff --git a/way-gradle-plugin/src/test/resources/Ph01mainNodeBuilder.txt b/way-gradle-plugin/src/test/resources/Ph01mainNodeBuilder.txt new file mode 100644 index 0000000..21a99e7 --- /dev/null +++ b/way-gradle-plugin/src/test/resources/Ph01mainNodeBuilder.txt @@ -0,0 +1,94 @@ +package ru.kode.test.app.schema + +import kotlin.Any +import kotlin.Pair +import kotlin.Suppress +import kotlin.collections.HashMap +import kotlin.collections.Map +import kotlin.collections.MutableMap +import kotlin.collections.Set +import ru.kode.way.FlowNode +import ru.kode.way.MissingPayloadException +import ru.kode.way.Node +import ru.kode.way.NodeBuilder +import ru.kode.way.NullPayload +import ru.kode.way.Path +import ru.kode.way.ScreenNode +import ru.kode.way.Segment +import ru.kode.way.drop +import ru.kode.way.firstSegment +import ru.kode.way.lastSegment +import ru.kode.way.startsWith + +public class Ph01mainNodeBuilder( + private val nodeFactory: Factory, + override val schema: ParallelHistorySchema, +) : NodeBuilder { + private val nodeBuilders: MutableMap = HashMap(1) + + private fun ph01tabsNodeBuilder(rootSegmentAlias: Segment?): NodeBuilder = nodeBuilders.getOrPut(targetOrError(Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), rootSegmentAlias)) { + nodeFactory.createPh01tabsNodeBuilder() + } + + override fun build( + path: Path, + payloads: Map, + rootSegmentAlias: Segment?, + ): Node { + val rootPath = rootSegmentAlias?.let { Path(it) } ?: Path(Segment("ph01main@ParallelHistory:src/test/resources/schema-parallel-history.dot")) + check(path.firstSegment().id == rootPath.firstSegment().id) { + """illegal path build requested for "ph01main" node: $path""" + } + return when { + path == rootPath -> nodeFactory.createRootNode() + path.startsWith(targetOrError(Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), rootSegmentAlias)) -> { + val targetPath = targetOrError(Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), rootSegmentAlias) + val nodeBuilder = ph01tabsNodeBuilder(rootSegmentAlias) + nodeBuilder.build(path.drop(targetPath.length - 1), payloads = payloads.filterKeys { it.length > targetPath.length - 1 }.mapKeys { it.key.drop(targetPath.length - 1) }, rootSegmentAlias = targetPath.lastSegment()) + } + path == targetOrError(Segment("ph01start@ParallelHistory:src/test/resources/schema-parallel-history.dot"), rootSegmentAlias) -> nodeFactory.createPh01startNode() + else -> error("""illegal path build requested for "ph01main" node: $path""") + } + } + + override fun invalidateCache(alivePaths: Set) { + nodeBuilders.keys.retainAll { key -> alivePaths.any { it.startsWith(key) } } + nodeBuilders.forEach { (builderPath, builder) -> + val drop = builderPath.length - 1 + val childAlive = alivePaths.filter { it.startsWith(builderPath) && it.length > drop }.map { it.drop(drop) }.toSet() + builder.invalidateCache(childAlive) + } + } + + override fun snapshotCache(): Any? = nodeBuilders.mapValues { (_, builder) -> builder to builder.snapshotCache() } + + override fun restoreCache(snapshot: Any?) { + nodeBuilders.clear() + (snapshot as Map<*, *>).forEach { (path, saved) -> + val (builder, childSnapshot) = saved as Pair<*, *> + nodeBuilders[path as Path] = builder as NodeBuilder + builder.restoreCache(childSnapshot) + } + } + + public fun targetOrError(segment: Segment, rootSegmentAlias: Segment?): Path = schema.regions.firstNotNullOfOrNull { schema.target(it, segment, rootSegmentAlias) } ?: error("""internal error: no target generated for segment "${segment.id}"""") + + @Suppress("UNCHECKED_CAST") + public fun payloadOrError( + segment: Segment, + payloads: Map, + rootSegmentAlias: Segment?, + ): T { + val targetPath = targetOrError(segment, rootSegmentAlias) + val payload = payloads[targetPath] ?: throw MissingPayloadException(targetPath) + return (if (payload === NullPayload) null else payload) as T + } + + public interface Factory { + public fun createRootNode(): FlowNode<*> + + public fun createPh01tabsNodeBuilder(): NodeBuilder + + public fun createPh01startNode(): ScreenNode + } +} diff --git a/way-gradle-plugin/src/test/resources/Ph01tabsNodeBuilder.txt b/way-gradle-plugin/src/test/resources/Ph01tabsNodeBuilder.txt new file mode 100644 index 0000000..a92d8b9 --- /dev/null +++ b/way-gradle-plugin/src/test/resources/Ph01tabsNodeBuilder.txt @@ -0,0 +1,108 @@ +package ru.kode.test.app.schema + +import kotlin.Any +import kotlin.Pair +import kotlin.Suppress +import kotlin.collections.HashMap +import kotlin.collections.Map +import kotlin.collections.MutableMap +import kotlin.collections.Set +import ru.kode.way.MissingPayloadException +import ru.kode.way.Node +import ru.kode.way.NodeBuilder +import ru.kode.way.NullPayload +import ru.kode.way.ParallelFlowNode +import ru.kode.way.Path +import ru.kode.way.RegionId +import ru.kode.way.Segment +import ru.kode.way.drop +import ru.kode.way.firstSegment +import ru.kode.way.lastSegment +import ru.kode.way.startsWith + +public class Ph01tabsNodeBuilder( + private val nodeFactory: Factory, + override val schema: Ph01tabsSchema, +) : NodeBuilder { + private val nodeBuilders: MutableMap = HashMap(2) + + public val ph01leftRegionId: RegionId + get() = RegionId(Path(listOf(Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot")))) + + public val ph01rightRegionId: RegionId + get() = RegionId(Path(listOf(Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot")))) + + private fun ph01rightNodeBuilder(rootSegmentAlias: Segment?): NodeBuilder = nodeBuilders.getOrPut(targetOrError(Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"), rootSegmentAlias)) { + nodeFactory.createPh01rightNodeBuilder() + } + + private fun ph01leftNodeBuilder(rootSegmentAlias: Segment?): NodeBuilder = nodeBuilders.getOrPut(targetOrError(Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"), rootSegmentAlias)) { + nodeFactory.createPh01leftNodeBuilder() + } + + override fun build( + path: Path, + payloads: Map, + rootSegmentAlias: Segment?, + ): Node { + val rootPath = rootSegmentAlias?.let { Path(it) } ?: Path(Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot")) + check(path.firstSegment().id == rootPath.firstSegment().id) { + """illegal path build requested for "ph01tabs" node: $path""" + } + return when { + path == rootPath -> nodeFactory.createRootNode() + path.startsWith(targetOrError(Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"), rootSegmentAlias)) -> { + val targetPath = targetOrError(Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"), rootSegmentAlias) + val nodeBuilder = ph01rightNodeBuilder(rootSegmentAlias) + nodeBuilder.build(path.drop(targetPath.length - 1), payloads = payloads.filterKeys { it.length > targetPath.length - 1 }.mapKeys { it.key.drop(targetPath.length - 1) }, rootSegmentAlias = targetPath.lastSegment()) + } + path.startsWith(targetOrError(Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"), rootSegmentAlias)) -> { + val targetPath = targetOrError(Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"), rootSegmentAlias) + val nodeBuilder = ph01leftNodeBuilder(rootSegmentAlias) + nodeBuilder.build(path.drop(targetPath.length - 1), payloads = payloads.filterKeys { it.length > targetPath.length - 1 }.mapKeys { it.key.drop(targetPath.length - 1) }, rootSegmentAlias = targetPath.lastSegment()) + } + else -> error("""illegal path build requested for "ph01tabs" node: $path""") + } + } + + override fun invalidateCache(alivePaths: Set) { + nodeBuilders.keys.retainAll { key -> alivePaths.any { it.startsWith(key) } } + nodeBuilders.forEach { (builderPath, builder) -> + val drop = builderPath.length - 1 + val childAlive = alivePaths.filter { it.startsWith(builderPath) && it.length > drop }.map { it.drop(drop) }.toSet() + builder.invalidateCache(childAlive) + } + } + + override fun snapshotCache(): Any? = nodeBuilders.mapValues { (_, builder) -> builder to builder.snapshotCache() } + + override fun restoreCache(snapshot: Any?) { + nodeBuilders.clear() + (snapshot as Map<*, *>).forEach { (path, saved) -> + val (builder, childSnapshot) = saved as Pair<*, *> + nodeBuilders[path as Path] = builder as NodeBuilder + builder.restoreCache(childSnapshot) + } + } + + public fun targetOrError(segment: Segment, rootSegmentAlias: Segment?): Path = schema.regions.firstNotNullOfOrNull { schema.target(it, segment, rootSegmentAlias) } ?: error("""internal error: no target generated for segment "${segment.id}"""") + + @Suppress("UNCHECKED_CAST") + public fun payloadOrError( + segment: Segment, + payloads: Map, + rootSegmentAlias: Segment?, + ): T { + val targetPath = targetOrError(segment, rootSegmentAlias) + val payload = payloads[targetPath] ?: throw MissingPayloadException(targetPath) + return (if (payload === NullPayload) null else payload) as T + } + + public interface Factory { + public fun createRootNode(): ParallelFlowNode<*> + + public fun createPh01rightNodeBuilder(): NodeBuilder + + public fun createPh01leftNodeBuilder(): NodeBuilder + } +} diff --git a/way-gradle-plugin/src/test/resources/Ph01tabsSchema.txt b/way-gradle-plugin/src/test/resources/Ph01tabsSchema.txt new file mode 100644 index 0000000..d2430ca --- /dev/null +++ b/way-gradle-plugin/src/test/resources/Ph01tabsSchema.txt @@ -0,0 +1,128 @@ +package ru.kode.test.app.schema + +import kotlin.Any +import kotlin.Boolean +import kotlin.collections.List +import kotlin.collections.Map +import ru.kode.way.Event +import ru.kode.way.Path +import ru.kode.way.RegionId +import ru.kode.way.Schema +import ru.kode.way.Segment + +public class Ph01tabsSchema : Schema { + override val rootSegment: Segment = + Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot") + + override val childSchemas: Map = + mapOf(Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot") to Ph01leftSchema(), Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot") to Ph01rightSchema()) + + override val regions: List = + listOf(RegionId(Path(listOf(Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot")))), RegionId(Path(listOf(Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"))))) + + public val ph01leftRegionId: RegionId + get() = regions[0] + + public val ph01rightRegionId: RegionId + get() = regions[1] + + override fun target( + regionId: RegionId, + segment: Segment, + rootSegmentAlias: Segment?, + ): Path? = when (regionId) { + regions[0] -> { + val rootSegment = rootSegmentAlias ?: Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot") + when(segment.id) { + "ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(rootSegment) + "ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01rightScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01rightScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01leftScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01leftScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + else -> null + } + } + regions[1] -> { + val rootSegment = rootSegmentAlias ?: Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot") + when(segment.id) { + "ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(rootSegment) + "ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01rightScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01rightScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01leftScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01leftScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + else -> null + } + } + else -> { + error("""unknown regionId=$regionId""") + } + } + + override fun nodeType( + regionId: RegionId, + path: Path, + rootSegmentAlias: Segment?, + ): Schema.NodeType = when (regionId) { + regions[0] -> { + val rootSegment = rootSegmentAlias ?: Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot") + when { + path == Path(rootSegment) -> Schema.NodeType.ParallelFlow + path == Path(listOf(rootSegment, Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Flow + path == Path(listOf(rootSegment, Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01rightScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Screen + path == Path(listOf(rootSegment, Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Flow + path == Path(listOf(rootSegment, Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01leftScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Screen + else -> { + error("""internal error: no nodeType for path=$path""") + } + } + } + regions[1] -> { + val rootSegment = rootSegmentAlias ?: Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot") + when { + path == Path(rootSegment) -> Schema.NodeType.ParallelFlow + path == Path(listOf(rootSegment, Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Flow + path == Path(listOf(rootSegment, Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01rightScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Screen + path == Path(listOf(rootSegment, Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Flow + path == Path(listOf(rootSegment, Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01leftScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Screen + else -> { + error("""internal error: no nodeType for path=$path""") + } + } + } + else -> { + error("""unknown regionId=$regionId""") + } + } + + override fun isParameterized( + regionId: RegionId, + path: Path, + rootSegmentAlias: Segment?, + ): Boolean = false + + override fun createChildFlowFinishRequestEvent( + regionId: RegionId, + path: Path, + result: Any, + ): Event = when (regionId) { + regions[0] -> { + when(path) { + Path(Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot")) -> Ph01tabsChildFinishRequest.Ph01left + else -> { + error("""internal error: failed to build child finish event for path=$path""") + } + } + } + regions[1] -> { + when(path) { + Path(Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot")) -> Ph01tabsChildFinishRequest.Ph01right + else -> { + error("""internal error: failed to build child finish event for path=$path""") + } + } + } + else -> { + error("""unknown regionId=$regionId""") + } + } +} diff --git a/way-gradle-plugin/src/test/resources/node-builders-nested-local-flow.dot b/way-gradle-plugin/src/test/resources/node-builders-nested-local-flow.dot new file mode 100644 index 0000000..659d988 --- /dev/null +++ b/way-gradle-plugin/src/test/resources/node-builders-nested-local-flow.dot @@ -0,0 +1,10 @@ +digraph NestedLocalFlow { + schemaFileName = "node-builders-nested-local-flow-schema" + targetsFileName = "node-builders-nested-local-flow-targets" + + nlf01app [type = flow, parameterName = timeout, parameterType = "kotlin.Int"] + nlf01settings [type = flow, resultType = "kotlin.String"] + + nlf01app -> nlf01intro + nlf01app -> nlf01settings -> nlf01general +} diff --git a/way-gradle-plugin/src/test/resources/schema-parallel-history.dot b/way-gradle-plugin/src/test/resources/schema-parallel-history.dot new file mode 100644 index 0000000..0e88c93 --- /dev/null +++ b/way-gradle-plugin/src/test/resources/schema-parallel-history.dot @@ -0,0 +1,16 @@ +digraph ParallelHistory { + schemaFileName = "schema-parallel-history" + targetsFileName = "schema-parallel-history-targets" + + ph01main [type = flow] + ph01tabs [type = parallelFlow] + ph01left [type = flow] + ph01right [type = flow] + ph01tabsHistory [type = deepHistory] + + ph01main -> ph01start + ph01main -> ph01tabs + ph01tabs -> ph01left -> ph01leftScreen + ph01tabs -> ph01right -> ph01rightScreen + ph01tabs -> ph01tabsHistory +} diff --git a/way-gradle-plugin/src/test/resources/schema-parallel-history.txt b/way-gradle-plugin/src/test/resources/schema-parallel-history.txt new file mode 100644 index 0000000..715d6c1 --- /dev/null +++ b/way-gradle-plugin/src/test/resources/schema-parallel-history.txt @@ -0,0 +1,175 @@ +package ru.kode.test.app.schema + +import kotlin.Any +import kotlin.Boolean +import kotlin.collections.List +import kotlin.collections.Map +import ru.kode.way.Event +import ru.kode.way.Path +import ru.kode.way.RegionId +import ru.kode.way.Schema +import ru.kode.way.Segment + +public class ParallelHistorySchema : Schema { + override val rootSegment: Segment = + Segment("ph01main@ParallelHistory:src/test/resources/schema-parallel-history.dot") + + override val childSchemas: Map = + mapOf(Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot") to Ph01tabsSchema(), Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot") to Ph01leftSchema(), Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot") to Ph01rightSchema()) + + override val regions: List = + listOf(RegionId(Path(listOf(Segment("ph01main@ParallelHistory:src/test/resources/schema-parallel-history.dot")))), RegionId(Path(listOf(Segment("ph01main@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot")))), RegionId(Path(listOf(Segment("ph01main@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"))))) + + public val ph01mainRegionId: RegionId + get() = regions[0] + + public val ph01leftRegionId: RegionId + get() = regions[1] + + public val ph01rightRegionId: RegionId + get() = regions[2] + + override fun target( + regionId: RegionId, + segment: Segment, + rootSegmentAlias: Segment?, + ): Path? = when (regionId) { + regions[0] -> { + val rootSegment = rootSegmentAlias ?: Segment("ph01main@ParallelHistory:src/test/resources/schema-parallel-history.dot") + when(segment.id) { + "ph01main@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(rootSegment) + "ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01rightScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01rightScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01leftScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01leftScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01start@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01start@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + else -> null + } + } + regions[1] -> { + val rootSegment = rootSegmentAlias ?: Segment("ph01main@ParallelHistory:src/test/resources/schema-parallel-history.dot") + when(segment.id) { + "ph01main@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(rootSegment) + "ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01rightScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01rightScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01leftScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01leftScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01start@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01start@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + else -> null + } + } + regions[2] -> { + val rootSegment = rootSegmentAlias ?: Segment("ph01main@ParallelHistory:src/test/resources/schema-parallel-history.dot") + when(segment.id) { + "ph01main@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(rootSegment) + "ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01rightScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01rightScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01leftScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01leftScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + "ph01start@ParallelHistory:src/test/resources/schema-parallel-history.dot" -> Path(listOf(rootSegment, Segment("ph01start@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) + else -> null + } + } + else -> { + error("""unknown regionId=$regionId""") + } + } + + override fun nodeType( + regionId: RegionId, + path: Path, + rootSegmentAlias: Segment?, + ): Schema.NodeType = when (regionId) { + regions[0] -> { + val rootSegment = rootSegmentAlias ?: Segment("ph01main@ParallelHistory:src/test/resources/schema-parallel-history.dot") + when { + path == Path(rootSegment) -> Schema.NodeType.Flow + path == Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.ParallelFlow + path == Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Flow + path == Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01rightScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Screen + path == Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Flow + path == Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01leftScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Screen + path == Path(listOf(rootSegment, Segment("ph01start@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Screen + else -> { + error("""internal error: no nodeType for path=$path""") + } + } + } + regions[1] -> { + val rootSegment = rootSegmentAlias ?: Segment("ph01main@ParallelHistory:src/test/resources/schema-parallel-history.dot") + when { + path == Path(rootSegment) -> Schema.NodeType.Flow + path == Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.ParallelFlow + path == Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Flow + path == Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01rightScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Screen + path == Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Flow + path == Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01leftScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Screen + path == Path(listOf(rootSegment, Segment("ph01start@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Screen + else -> { + error("""internal error: no nodeType for path=$path""") + } + } + } + regions[2] -> { + val rootSegment = rootSegmentAlias ?: Segment("ph01main@ParallelHistory:src/test/resources/schema-parallel-history.dot") + when { + path == Path(rootSegment) -> Schema.NodeType.Flow + path == Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.ParallelFlow + path == Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Flow + path == Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01rightScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Screen + path == Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Flow + path == Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot"), Segment("ph01leftScreen@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Screen + path == Path(listOf(rootSegment, Segment("ph01start@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Schema.NodeType.Screen + else -> { + error("""internal error: no nodeType for path=$path""") + } + } + } + else -> { + error("""unknown regionId=$regionId""") + } + } + + override fun isParameterized( + regionId: RegionId, + path: Path, + rootSegmentAlias: Segment?, + ): Boolean = false + + override fun createChildFlowFinishRequestEvent( + regionId: RegionId, + path: Path, + result: Any, + ): Event = when (regionId) { + regions[0] -> { + when(path) { + Path(listOf(rootSegment, Segment("ph01tabs@ParallelHistory:src/test/resources/schema-parallel-history.dot"))) -> Ph01mainChildFinishRequest.Ph01tabs + else -> { + error("""internal error: failed to build child finish event for path=$path""") + } + } + } + regions[1] -> { + when(path) { + Path(Segment("ph01left@ParallelHistory:src/test/resources/schema-parallel-history.dot")) -> Ph01tabsChildFinishRequest.Ph01left + else -> { + error("""internal error: failed to build child finish event for path=$path""") + } + } + } + regions[2] -> { + when(path) { + Path(Segment("ph01right@ParallelHistory:src/test/resources/schema-parallel-history.dot")) -> Ph01tabsChildFinishRequest.Ph01right + else -> { + error("""internal error: failed to build child finish event for path=$path""") + } + } + } + else -> { + error("""unknown regionId=$regionId""") + } + } +}