Repository navigation
Collapse XJogStateChange action-type stubs into a plain-action union (C6) - #68
Merged
Merged
Conversation
15 of the 18 XJogStateChange*Action variants were empty '// TODO ?' stubs whose only field was 'type', and mapActions never populated anything else for them. Collapse them into a single XJogStateChangePlainAction with a narrowed XJogStateChangePlainActionType union; the serialized shape of journaled actions is unchanged. Also make XJogActionTypes a real enum (it was 'declare enum', so XJogActionTypes.Unknown did not exist at runtime), use it in mapActions instead of a hardcoded 'xjog.unknown' literal, drop the blanket @ts-expect-error now that the mapping type-checks, and add unit tests covering every branch of mapActions. Resolves TODO item C6.
juhovuo
force-pushed
the
fix/xjog-state-change-action-stubs
branch
from
July 5, 2026 00:41
f5e8dda to
8d0631a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves TODO item C6, which asked for a design proposal before coding. Proposal and rationale below.
Design proposal
packages/util/src/XJogStateChange.tsdeclared 18 per-action-type variants plusUnknown, but 15 of them were empty// TODO ?stubs whose only field wastype. The TODO offered two options: fill in payloads, or collapse to a smaller union.Chosen: collapse to a smaller union.
Rationale:
XJogStateChangeState.actionsis the journal writer, which passes the array toJournalPersistenceAdapter.record()where it is JSON-serialized as-is. No code narrows on the stub variants — none of the 15 stub type names were referenced anywhere outside the union itself.assignassignments,pure/choose/logexpressions), which cannot be JSON-serialized into the journal. Populating the serializable subset would be speculative API surface with no consumer, and a behavior change to persisted journal rows.mapActionsalready mapped all 15 stub types to a bare{ type }; the serialized shape of journaled actions is byte-for-byte unchanged.New shape:
XJogStateChangeAction=Send | Cancel | Start | Stop(the four variantsmapActionsactually populates)| XJogStateChangePlainAction | Unknown, whereXJogStateChangePlainActionis{ type: XJogStateChangePlainActionType }andXJogStateChangePlainActionTypeis the union of the 15 built-in action types recorded by type only. Discriminated-union narrowing on the payload variants still works.Bugs fixed along the way
XJogActionTypeswas adeclare enum, so it emitted no runtime value:XJogActionTypes.Unknownwas a crash/never-match for any consumer (which is whymapActionshardcoded'xjog.unknown'behind a commented-out line). It is now a real enum with the same member and value. The new regression test fails before this fix (TypeError: Cannot read properties of undefined (reading 'Unknown')).mapActionsdropped its blanket// @ts-expect-error; the switch is now fully type-checked, usesXJogActionTypes.Unknown(same runtime string), and the dead commented-out line is gone.Tests
Added a
mapActionssuite inresolveXJogStateChange.test.ts: send/cancel/start/stop payload mapping, all 15 plain built-ins mapping to{ type }only (payload fields dropped), custom types mapping to the runtimexjog.unknownmarker, and one end-to-end case through a real machine transition.Breaking change note (types only)
The 15 removed type aliases (e.g.
XJogStateChangeLogAction) were exported from@telia-oss/xjog-util; external code importing them should switch toXJogStateChangePlainAction. Runtime behavior and persisted data are unchanged. Changeset:minorforxjog-util,patchforxjog.Verification
pnpm run build— 15/15 tasks passpnpm run test— 13/13 tasks pass (11 tests in the touched suite)pnpm run lint— clean🤖 Generated with Claude Code