From 1906f8291593f840185d592ffa5e4d18c8928966 Mon Sep 17 00:00:00 2001 From: Josh Slate Date: Fri, 27 Jun 2025 14:52:40 -0700 Subject: [PATCH 1/2] try to fix date key equality issue --- psm/statemachine.go | 49 +++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/psm/statemachine.go b/psm/statemachine.go index a0abf82..af9808d 100644 --- a/psm/statemachine.go +++ b/psm/statemachine.go @@ -5,6 +5,7 @@ import ( "database/sql" "errors" "fmt" + "github.com/pentops/j5/j5types/date_j5t" "time" "buf.build/go/protovalidate" @@ -36,12 +37,12 @@ func MustSystemActor(id string) struct{} { // StateMachine is a database wrapper around the eventer. Using sane defaults // with overrides for table configuration. type StateMachine[ - K IKeyset, - S IState[K, ST, SD], // Outer State Entity - ST IStatusEnum, // Status Enum in State Entity - SD IStateData, - E IEvent[K, S, ST, SD, IE], // Event Wrapper, with IDs and Metadata - IE IInnerEvent, // Inner Event, the typed event +K IKeyset, +S IState[K, ST, SD], // Outer State Entity +ST IStatusEnum, // Status Enum in State Entity +SD IStateData, +E IEvent[K, S, ST, SD, IE], // Event Wrapper, with IDs and Metadata +IE IInnerEvent, // Inner Event, the typed event ] struct { transitionSet[K, S, ST, SD, E, IE] @@ -55,12 +56,12 @@ type StateMachine[ } func NewStateMachine[ - K IKeyset, - S IState[K, ST, SD], - ST IStatusEnum, - SD IStateData, - E IEvent[K, S, ST, SD, IE], - IE IInnerEvent, +K IKeyset, +S IState[K, ST, SD], +ST IStatusEnum, +SD IStateData, +E IEvent[K, S, ST, SD, IE], +IE IInnerEvent, ]( cb *StateMachineConfig[K, S, ST, SD, E, IE], ) (*StateMachine[K, S, ST, SD, E, IE], error) { @@ -129,12 +130,12 @@ func (sm *StateMachine[K, S, ST, SD, E, IE]) WithDB(db Transactor) *DBStateMachi // DBStateMachine adds the 'Transaction' method to the state machine, which // runs the transition in a new transaction from the state machine's database type DBStateMachine[ - K IKeyset, - S IState[K, ST, SD], - ST IStatusEnum, - SD IStateData, - E IEvent[K, S, ST, SD, IE], - IE IInnerEvent, +K IKeyset, +S IState[K, ST, SD], +ST IStatusEnum, +SD IStateData, +E IEvent[K, S, ST, SD, IE], +IE IInnerEvent, ] struct { *StateMachine[K, S, ST, SD, E, IE] db Transactor @@ -528,8 +529,16 @@ func assertPresentKeysMatch[K IKeyset](existing, event K) error { if !ok { return fmt.Errorf("event key %s is not present in existing keys", key) } - if existingValue != eventValue { - return status.Errorf(codes.FailedPrecondition, "event key %s value %s does not match existing value %s", key, eventValue, existingValue) + + switch v := existingValue.(type) { + case *date_j5t.Date: + if eventValueAsDate, ok := eventValue.(*date_j5t.Date); !ok || !v.Equals(eventValueAsDate) { + return status.Errorf(codes.FailedPrecondition, "event key %s value %s does not match existing value %s", key, eventValue, existingValue) + } + default: + if existingValue != eventValue { + return status.Errorf(codes.FailedPrecondition, "event key %s value %s does not match existing value %s", key, eventValue, existingValue) + } } } From 8d21699f1bd0417a4b40073e56c38c475cac1a21 Mon Sep 17 00:00:00 2001 From: Josh Slate Date: Fri, 27 Jun 2025 14:55:42 -0700 Subject: [PATCH 2/2] gofmt --- psm/statemachine.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/psm/statemachine.go b/psm/statemachine.go index af9808d..8e1acda 100644 --- a/psm/statemachine.go +++ b/psm/statemachine.go @@ -37,12 +37,12 @@ func MustSystemActor(id string) struct{} { // StateMachine is a database wrapper around the eventer. Using sane defaults // with overrides for table configuration. type StateMachine[ -K IKeyset, -S IState[K, ST, SD], // Outer State Entity -ST IStatusEnum, // Status Enum in State Entity -SD IStateData, -E IEvent[K, S, ST, SD, IE], // Event Wrapper, with IDs and Metadata -IE IInnerEvent, // Inner Event, the typed event + K IKeyset, + S IState[K, ST, SD], // Outer State Entity + ST IStatusEnum, // Status Enum in State Entity + SD IStateData, + E IEvent[K, S, ST, SD, IE], // Event Wrapper, with IDs and Metadata + IE IInnerEvent, // Inner Event, the typed event ] struct { transitionSet[K, S, ST, SD, E, IE] @@ -56,12 +56,12 @@ IE IInnerEvent, // Inner Event, the typed event } func NewStateMachine[ -K IKeyset, -S IState[K, ST, SD], -ST IStatusEnum, -SD IStateData, -E IEvent[K, S, ST, SD, IE], -IE IInnerEvent, + K IKeyset, + S IState[K, ST, SD], + ST IStatusEnum, + SD IStateData, + E IEvent[K, S, ST, SD, IE], + IE IInnerEvent, ]( cb *StateMachineConfig[K, S, ST, SD, E, IE], ) (*StateMachine[K, S, ST, SD, E, IE], error) { @@ -130,12 +130,12 @@ func (sm *StateMachine[K, S, ST, SD, E, IE]) WithDB(db Transactor) *DBStateMachi // DBStateMachine adds the 'Transaction' method to the state machine, which // runs the transition in a new transaction from the state machine's database type DBStateMachine[ -K IKeyset, -S IState[K, ST, SD], -ST IStatusEnum, -SD IStateData, -E IEvent[K, S, ST, SD, IE], -IE IInnerEvent, + K IKeyset, + S IState[K, ST, SD], + ST IStatusEnum, + SD IStateData, + E IEvent[K, S, ST, SD, IE], + IE IInnerEvent, ] struct { *StateMachine[K, S, ST, SD, E, IE] db Transactor