EventCoordinate should own its persistenceId|sequenceNr string format #47
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
iterative-works/support#47
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
EventCoordinatehas a wire format —persistenceId|sequenceNr— but no owner for it.Every consumer that needs to put a coordinate into a string (a Mongo
_id, an HTTP pathsegment) has to reinvent the serialize/parse pair, and each reinvention is a place where a
malformed input can throw instead of decoding into an error.
Trigger. In
mdr-poptavky(MEDECA-447) the format was reimplemented at four call sites —two
TimelineDoc.idOfand two tapirCodec[String, EventCoordinate, ...]path codecs. Codereview flagged it as duplication.
EventCoordinateis monomorphic, so there is nothingper-module about the format and no reason for four copies. The project consolidated them into a
project-local
model/shared/src/main/scala/mdr/EventCoordinateFormat.scalawithserialize/parse, whereparsereturns anOptionand rejects a negativesequenceNr(a journalsequence number is never negative, and
toLongOptionalone accepted-5).Ask.
EventCoordinate's companion object should carry the format itself —serialize/parse, or aCodec— so consumers delegate instead of reimplementing. Once released, theproject-local
mdr.EventCoordinateFormatis retired.Reference implementation (project-local, to be superseded):
model/shared/src/main/scala/mdr/EventCoordinateFormat.scalaand its specmodel/shared/src/test/scala/mdr/EventCoordinateFormatSpec.scalainCMI/mdr/medeca-modul-poptavky, branchMEDECA-447.parsemust reject a negativesequenceNr, so the round trip is total in one direction only.Raised from MEDECA-447 lesson triage.