Skip to content

Commit

Permalink
Rename OpID and format
Browse files Browse the repository at this point in the history
  • Loading branch information
Erudition committed Nov 18, 2024
1 parent ee13b91 commit 83a5a35
Show file tree
Hide file tree
Showing 26 changed files with 60 additions and 61 deletions.
2 changes: 1 addition & 1 deletion elm-to-be-migrated/OldMain.elm
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import Replicated.Change as Change exposing (Frame)
import Replicated.Codec
import Replicated.Framework as Framework
import Replicated.Node.Node
import Replicated.Op.OpID
import Replicated.Op.ID
import Replicated.Reducer.RepDb as RepDb
import Replicated.Reducer.RepList as RepList exposing (RepList)
import Shared.PopupType as PopupType
Expand Down
2 changes: 1 addition & 1 deletion elm-to-be-migrated/Showstopper.elm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Profile exposing (..)
import Replicated.Codec as Codec
import Replicated.Node.Node as Node
import Replicated.Op.Op as Op
import Replicated.Op.OpID as OpID
import Replicated.Op.ID as OpID
import OldShared.Model exposing (..)
import SmartTime.Human.Duration exposing (HumanDuration(..))
import Url
Expand Down
4 changes: 2 additions & 2 deletions elm-to-be-migrated/Timeflow.elm
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import Incubator.IntDict.Extra as IntDict
import IntDict exposing (IntDict)
import List.Extra as List
import Log
import OldShared.Model exposing (..)
import Profile exposing (..)
import Refocus
import Replicated.Change as Change exposing (ChangeSet, Frame)
import Replicated.Op.OpID as OpID exposing (OpID)
import Replicated.Op.ID as OpID exposing (OpID)
import Replicated.Reducer.RepList as RepList exposing (RepList)
import OldShared.Model exposing (..)
import SmartTime.Duration as Duration exposing (Duration)
import SmartTime.Human.Calendar as Calendar exposing (CalendarDate, equal)
import SmartTime.Human.Calendar.Week as Week
Expand Down
5 changes: 1 addition & 4 deletions elm/Components/Replicator.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import Platform exposing (Task)
import Replicated.Change as Change
import Replicated.Codec as Codec exposing (SkelCodec)
import Replicated.Node.Node as Node exposing (Node, OpImportWarning)
import Replicated.Op.ID as OpID
import Replicated.Op.Op as Op
import Replicated.Op.OpID as OpID
import SmartTime.Moment as Moment exposing (Moment)
import Task

Expand Down Expand Up @@ -182,6 +182,3 @@ saveEffect framesToSave =

_ ->
Task.perform (ApplyFrames framesToSave) Moment.now



2 changes: 1 addition & 1 deletion elm/ExtraCodecs.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import IntDict exposing (IntDict)
import Log
import Replicated.Change exposing (Pointer(..))
import Replicated.Codec as Codec exposing (Codec, PrimitiveCodec)
import Replicated.Op.OpID as OpID
import Replicated.Op.ID as OpID
import SmartTime.Duration as Duration exposing (Duration)
import SmartTime.Human.Calendar exposing (CalendarDate)
import SmartTime.Human.Clock exposing (TimeOfDay)
Expand Down
4 changes: 2 additions & 2 deletions elm/ID.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ID exposing
( ID
, getObjectID, fromPointer, toInt, toPointer, toString, fromObjectID
, fromObjectID, fromPointer, getObjectID, toInt, toPointer, toString
)

{-| This package exposes a really simple type called `ID`.
Expand Down Expand Up @@ -77,7 +77,7 @@ import Json.Decode.Exploration as Decode exposing (Decoder)
import Json.Encode as Encode
import Log
import Replicated.Change as Change exposing (Pointer)
import Replicated.Op.OpID as OpID exposing (OpID)
import Replicated.Op.ID as OpID exposing (OpID)


type ID userType
Expand Down
2 changes: 1 addition & 1 deletion elm/Layouts/AppFrame.elm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import Profile exposing (..)
import Replicated.Change as Change exposing (Frame)
import Replicated.Codec
import Replicated.Node.Node
import Replicated.Op.OpID
import Replicated.Op.ID
import Replicated.Reducer.RepDb as RepDb
import Replicated.Reducer.RepList as RepList exposing (RepList)
import Route exposing (Route)
Expand Down
2 changes: 1 addition & 1 deletion elm/Refocus.elm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import NativeScript.Notification as Notif exposing (Notification)
import Profile exposing (Profile)
import Random
import Replicated.Change as Change exposing (Change)
import Replicated.Op.OpID as OpID
import Replicated.Op.ID as OpID
import Replicated.Reducer.Register as Reg exposing (Reg)
import Replicated.Reducer.RepList as RepList exposing (RepList)
import Shared.Model exposing (..)
Expand Down
19 changes: 12 additions & 7 deletions elm/Replicated/Change.elm
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module Replicated.Change exposing (Change(..), ChangeSet(..), Changer, ComplexAtom(..), ComplexPayload, Context(..), Creator, DelayedChange, ExistingID, Frame(..), ObjectChange(..), Parent, PendingID, Pointer(..), PrimitiveAtom(..), PrimitivePayload, SoloObjectEncoded, UndoData, becomeDelayedParent, becomeInstantParent, changeObject, changeObjectWithExternal, changeSetDebug, collapseChangesToChangeSet, complexFromSolo, contextDifferentiatorString, createReversionFrame, delayedChangeObject, delayedChangesToSets, emptyChangeSet, emptyFrame, equalPointers, extractOwnSubChanges, genesisParent, getContextLocation, getContextParent, getObjectChanges, getPointerObjectID, getPointerReducer, isEmptyChangeSet, isPlaceholder, mapChanger, mapCreator, mergeChanges, mergeMaybeChange, newPointer, noChange, nonEmptyFrames, pendingIDToComparable, pendingIDToString, primitiveAtomToRonAtom, primitiveAtomToString, redundantObjectChange, reuseContext, saveSystemChanges, saveUserChanges, startContext)
module Replicated.Change exposing (Change(..), ChangeSet(..), Changer, ComplexAtom(..), ComplexPayload, Context(..), Creator, DelayedChange, ExistingID, Frame(..), ObjectChange(..), Parent, PendingID, Pointer(..), PrimitiveAtom(..), PrimitivePayload, SoloObjectEncoded, UndoData, becomeDelayedParent, becomeInstantParent, changeObject, changeObjectWithExternal, changeSetDebug, collapseChangesToChangeSet, complexFromSolo, contextDifferentiatorString, createReversionFrame, delayedChangeObject, delayedChangesToSets, emptyChangeSet, emptyFrame, equalPointers, extractOwnSubChanges, genesisParent, getContextLocation, getContextParent, getObjectChanges, getPointerObjectID, getPointerReducer, isEmptyChangeSet, isPlaceholder, mapChanger, mapCreator, mergeChanges, mergeMaybeChange, newPointer, noChange, nonEmptyFrames, pendingIDToComparable, pendingIDToString, primitiveAtomToRonAtom, primitiveAtomToString, redundantObjectChange, reuseContext, saveSystemChanges, saveUserChanges, startContext)

import Console
import Dict.Any as AnyDict exposing (AnyDict)
import Set.Any as AnySet exposing (AnySet)
import Html exposing (del)
import Json.Encode as JE
import List.Extra
import List.Nonempty as Nonempty exposing (Nonempty(..))
import Log
import Maybe.Extra
import Replicated.Change.Location as Location exposing (Location, toString)
import Replicated.Op.ID as OpID exposing (ObjectID, OpID)
import Replicated.Op.Op as Op exposing (Op)
import Replicated.Op.OpID as OpID exposing (ObjectID, OpID)
import Result.Extra
import Set.Any as AnySet exposing (AnySet)


type ChangeSet
Expand Down Expand Up @@ -99,6 +99,7 @@ mergeMaybeChange maybeChange change =
Nothing ->
change


{-| Set of all changes to make.
Decision: real changes only, no repeated ops. Ops to be reverted are specified at the frame level.
-}
Expand Down Expand Up @@ -626,7 +627,7 @@ saveUserChanges description changes =

saveSystemChanges : List Change -> Frame desc
saveSystemChanges changes =
Frame { changes = collapseChangesToChangeSet "save" changes, description = Nothing}
Frame { changes = collapseChangesToChangeSet "save" changes, description = Nothing }


{-| An empty Frame, for when you have no changes to save.
Expand All @@ -635,6 +636,7 @@ emptyFrame : Frame desc
emptyFrame =
Frame { changes = emptyChangeSet, description = Nothing }


{-| Returns True if a change Frame contains no changes (including Ops to invert).
-}
isEmpty : Frame desc -> Bool
Expand All @@ -649,12 +651,15 @@ nonEmptyFrames frames =

{-| Data that can be used for user undo/redo.
Internally, this type contains a set of IDs for all the Ops that can be reverted, if any, that were generated by an applied Change Frame. You can use this to create a new Change Frame to undo those changes, or redo those changes if they were previously undone.
-}
type alias UndoData = OpIDSet
-}
type alias UndoData =
OpIDSet


{-| Used internally by Node module to create a Change Frame that reverts the given Ops.
{-| Used internally by Node module to create a Change Frame that reverts the given Ops.
Note: does not work with the original Ops (before all reversions). The Node module takes the UndoData (OpIDs of original changes) and traces all undo/redo operations recursively to the most recent reversion of each one, and provides this function with the those Ops (actual Ops, not just IDs).
-}
createReversionFrame : List Op -> Frame desc
createReversionFrame opsToRevert =
Expand Down
2 changes: 1 addition & 1 deletion elm/Replicated/Codec.elm
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ import Replicated.Change as Change exposing (Change, ChangeSet(..), Changer, Com
import Replicated.Change.Location as Location exposing (Location)
import Replicated.Node.Node as Node exposing (Node)
import Replicated.Object as Object exposing (Object)
import Replicated.Op.ID as OpID exposing (InCounter, ObjectID, OpID, OutCounter)
import Replicated.Op.Op as Op exposing (Op)
import Replicated.Op.OpID as OpID exposing (InCounter, ObjectID, OpID, OutCounter)
import Replicated.Reducer.Register as Reg exposing (..)
import Replicated.Reducer.RepDb as RepDb exposing (RepDb)
import Replicated.Reducer.RepDict as RepDict exposing (RepDict, RepDictEntry(..))
Expand Down
45 changes: 21 additions & 24 deletions elm/Replicated/Node/Node.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import List.Nonempty as Nonempty exposing (Nonempty(..))
import Log
import Maybe.Extra
import Parser.Advanced as Parser
import Set.Any as AnySet exposing (AnySet)
import Replicated.Change as Change exposing (Change, ChangeSet(..), ComplexAtom, PendingID, Pointer(..), pendingIDToString)
import Replicated.Change.Location as Location exposing (Location)
import Replicated.Identifier exposing (..)
import Replicated.Node.NodeID as NodeID exposing (NodeID)
import Replicated.Object as Object exposing (Object)
import Replicated.Op.ID as OpID exposing (InCounter, ObjectID, ObjectIDString, OpID, OpIDSortable, OutCounter)
import Replicated.Op.Op as Op exposing (Op, ReducerID, create)
import Replicated.Op.OpID as OpID exposing (InCounter, ObjectID, ObjectIDString, OpID, OpIDSortable, OutCounter)
import Set exposing (Set)
import Set.Any as AnySet exposing (AnySet)
import SmartTime.Moment exposing (Moment)


Expand Down Expand Up @@ -265,9 +265,9 @@ updateNodeWithChunk chunk old =

Just firstOpenOp ->
case ( firstOpenOp.objectSpecified, firstOpenOp.reducerSpecified, firstOpenOp.reference ) of
( Just explicitObject, Just explicitReducer, _ ) ->
( Just explicitObject, Just explicitReducer, _ ) ->
-- closed ops - reducer and objectID are explicit
Ok ( explicitReducer, explicitObject )
Ok ( explicitReducer, explicitObject )

( _, _, Op.ReducerReference reducerID ) ->
-- It's a header / creation op, no need to lookup
Expand All @@ -277,6 +277,7 @@ updateNodeWithChunk chunk old =
case lookupObject old.node referencedOpID of
Just foundBoth ->
Ok foundBoth

Nothing ->
Err (UnknownReference referencedOpID)

Expand Down Expand Up @@ -433,8 +434,6 @@ apply timeMaybe testMode node (Change.Frame { changes, description }) =
, [ "Delayed Updates:" ]
, [ Op.closedChunksToFrameText (List.concat step2OutChunks) ]
]


in
Log.logMessageOnly logApplyResults
{ outputFrame = outChunks
Expand Down Expand Up @@ -484,21 +483,23 @@ getReversibleOps ops =
in
List.filterMap getCreationIDs ops


{-| Find all Ops that use the given Op as a reference.
TODO just index the OpDb by reference
-}
findAllReferencesToOp : Node -> OpID -> List Op
findAllReferencesToOp node opID =
AnyDict.filter (\_ op -> Op.opIDFromReference (Op.reference op) == Just opID) node.ops
|> AnyDict.values
|> AnyDict.values


{-| Given a list of OpIDs representing the original change, find the Ops of their latest reversion.
TODO: once OpDb is indexed by object and reference, eliminate the recursive search.
-}
findFinalOpsToRevert : Node -> Change.UndoData -> List Op
findFinalOpsToRevert node opIDsToRevert =
findFinalOpsToRevert node opIDsToRevert =
let
findFinalReversionOp earlierOpID =
let
Expand All @@ -507,15 +508,15 @@ findFinalOpsToRevert node opIDsToRevert =
AnyDict.get earlierOpID node.ops

earlierOpPatternMaybe =
Maybe.map (Op.pattern) earlierOpMaybe
Maybe.map Op.pattern earlierOpMaybe

-- if the op is normal, the next reversion will be a deletion op.
-- if the op is a deletion already, the next reversion (undeletion) will look like a normal opID.
opPatternToLookFor =
opPatternToLookFor =
case earlierOpPatternMaybe of
Just Op.DeletionOp ->
Op.UnDeletionOp

Just Op.UnDeletionOp ->
Op.DeletionOp

Expand All @@ -525,22 +526,21 @@ findFinalOpsToRevert node opIDsToRevert =
allOpsReferringToEarlierOp =
findAllReferencesToOp node earlierOpID
in
case List.filter (\op -> Op.pattern op == opPatternToLookFor ) allOpsReferringToEarlierOp of
[] ->
-- Looks like this op was never reverted, so it's the final op
earlierOpMaybe
case List.filter (\op -> Op.pattern op == opPatternToLookFor) allOpsReferringToEarlierOp of
[] ->
-- Looks like this op was never reverted, so it's the final op
earlierOpMaybe

[foundReversionOp] ->
-- the earlier op has been reverted, repeat the process with the newfound reversion
findFinalReversionOp (Op.id foundReversionOp)
[ foundReversionOp ] ->
-- the earlier op has been reverted, repeat the process with the newfound reversion
findFinalReversionOp (Op.id foundReversionOp)

firstOpFound :: moreFound ->
Log.crashInDev "When trying to find reversions of an op, I found multiple..." (Just firstOpFound)
firstOpFound :: moreFound ->
Log.crashInDev "When trying to find reversions of an op, I found multiple..." (Just firstOpFound)
in
List.filterMap findFinalReversionOp (AnySet.toList opIDsToRevert)



{-| Collects info on what ObjectIDs map back to what placeholder IDs from before they were initialized. In case we want to reference the new object same-frame.
Use with Change.pendingIDToString
-}
Expand All @@ -555,8 +555,6 @@ keepChangeSetIfNonempty changeSetMaybe =
Maybe.Extra.filter (not << Change.isEmptyChangeSet) changeSetMaybe




{-| Passed to mapAccuml, so must have accumulator and change as last params
-}
oneChangeSetToOpChunks :
Expand Down Expand Up @@ -600,7 +598,6 @@ oneChangeSetToOpChunks node ( inCounter, inMapping ) (ChangeSet changeSet) =
outMapping =
{ postExistingMapping | delayed = postExistingMapping.delayed ++ changeSet.delayed }


-- logOps =
-- List.map (\op -> Op.closedOpToString Op.OpenOps op ++ "\n") (List.concat generatedChunks)
-- |> String.concat
Expand Down
2 changes: 1 addition & 1 deletion elm/Replicated/Object.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import List.Nonempty as Nonempty exposing (Nonempty)
import Log
import Replicated.Change as Change exposing (ChangeSet)
import Replicated.Change.Location as Location exposing (Location)
import Replicated.Op.ID as OpID exposing (ObjectID, OpID, OpIDSortable, OpIDString)
import Replicated.Op.Op as Op exposing (Op, OpPayloadAtoms)
import Replicated.Op.OpID as OpID exposing (ObjectID, OpID, OpIDSortable, OpIDString)
import SmartTime.Moment as Moment exposing (Moment)


Expand Down
2 changes: 1 addition & 1 deletion elm/Replicated/Op/OpID.elm → elm/Replicated/Op/ID.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Replicated.Op.OpID exposing (EventStamp, InCounter, ObjectID, ObjectIDString, ObjectVersion, OpID, OpIDSortable, OpIDString, OutCounter, exportCounter, firstCounterOfFrame, fromPrimitives, fromRonPointerString, fromSortable, fromString, fromStringForced, generate, getClock, getMoment, highestCounter, importCounter, isIncremental, isDeletion, jsonDecoder, latest, nextGenCounter, nextOpInChain, parser, toInt, toRonPointerString, toSortablePrimitives, toString, unusedCounter)
module Replicated.Op.ID exposing (EventStamp, InCounter, ObjectID, ObjectIDString, ObjectVersion, OpID, OpIDSortable, OpIDString, OutCounter, exportCounter, firstCounterOfFrame, fromPrimitives, fromRonPointerString, fromSortable, fromString, fromStringForced, generate, getClock, getMoment, highestCounter, importCounter, isIncremental, isDeletion, jsonDecoder, latest, nextGenCounter, nextOpInChain, parser, toInt, toRonPointerString, toSortablePrimitives, toString, unusedCounter)

import Json.Decode as JD
import Parser.Advanced as Parser exposing ((|.), (|=), Parser, float, spaces, succeed, symbol)
Expand Down
4 changes: 2 additions & 2 deletions elm/Replicated/Op/Op.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Replicated.Op.Op exposing (ClosedChunk, Context(..), FrameChunk, Op(..), OpPattern(..), OpPayloadAtom(..), OpPayloadAtoms, OpenTextOp, OpenTextRonFrame, Problem(..), ReducerID, Reference(..), RonFormat(..), atomToJsonValue, atomToRonString, closedChunksToFrameText, closedOpToString, contextStackToString, create, id, initObject, object, pattern, payload, payloadToJsonValue, problemToString, reducer, reference, ronParser, opIDFromReference)
module Replicated.Op.Op exposing (ClosedChunk, Context(..), FrameChunk, Op(..), OpPattern(..), OpPayloadAtom(..), OpPayloadAtoms, OpenTextOp, OpenTextRonFrame, Problem(..), ReducerID, Reference(..), RonFormat(..), atomToJsonValue, atomToRonString, closedChunksToFrameText, closedOpToString, contextStackToString, create, id, initObject, object, opIDFromReference, pattern, payload, payloadToJsonValue, problemToString, reducer, reference, ronParser)

{-| Just Ops - already-happened events and such. Ignore Frames for now, they are "write batches" so once they're written they will slef-concatenate in the list of Ops.
-}
Expand All @@ -8,7 +8,7 @@ import Json.Encode as JE
import List.Extra
import List.Nonempty as Nonempty exposing (Nonempty(..))
import Parser.Advanced as Parser exposing ((|.), (|=), Token(..), float, inContext, succeed, symbol)
import Replicated.Op.OpID as OpID exposing (ObjectID, OpID)
import Replicated.Op.ID as OpID exposing (ObjectID, OpID)
import Result.Extra
import Set exposing (Set)
import SmartTime.Moment as Moment
Expand Down
2 changes: 1 addition & 1 deletion elm/Replicated/Reducer/Register.elm
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import Replicated.Change.Location as Location exposing (Location)
import Replicated.Node.Node exposing (Node)
import Replicated.Node.NodeID exposing (NodeID)
import Replicated.Object as Object
import Replicated.Op.ID as OpID exposing (OpID, OpIDSortable)
import Replicated.Op.Op as Op exposing (Op)
import Replicated.Op.OpID as OpID exposing (OpID, OpIDSortable)
import SmartTime.Moment as Moment exposing (Moment)


Expand Down
2 changes: 1 addition & 1 deletion elm/Replicated/Reducer/RepDb.elm
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import Replicated.Change.Location as Location exposing (Location)
import Replicated.Node.Node as Node exposing (Node)
import Replicated.Node.NodeID as NodeID exposing (NodeID)
import Replicated.Object as Object exposing (Object)
import Replicated.Op.ID as OpID exposing (ObjectID, OpID, OpIDString)
import Replicated.Op.Op as Op
import Replicated.Op.OpID as OpID exposing (ObjectID, OpID, OpIDString)
import SmartTime.Moment as Moment exposing (Moment)


Expand Down
2 changes: 1 addition & 1 deletion elm/Replicated/Reducer/RepDict.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import Replicated.Change.Location as Location exposing (Location)
import Replicated.Node.Node as Node exposing (Node)
import Replicated.Node.NodeID as NodeID exposing (NodeID)
import Replicated.Object as Object exposing (Object)
import Replicated.Op.ID as OpID exposing (ObjectID, OpID, OpIDString)
import Replicated.Op.Op as Op
import Replicated.Op.OpID as OpID exposing (ObjectID, OpID, OpIDString)
import SmartTime.Moment as Moment exposing (Moment)


Expand Down
2 changes: 1 addition & 1 deletion elm/Replicated/Reducer/RepList.elm
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import Replicated.Change.Location as Location exposing (Location)
import Replicated.Node.Node as Node exposing (Node)
import Replicated.Node.NodeID as NodeID exposing (NodeID)
import Replicated.Object as Object exposing (Object)
import Replicated.Op.ID as OpID exposing (ObjectID, OpID, OpIDString)
import Replicated.Op.Op as Op
import Replicated.Op.OpID as OpID exposing (ObjectID, OpID, OpIDString)
import SmartTime.Moment as Moment exposing (Moment)


Expand Down
Loading

0 comments on commit 83a5a35

Please sign in to comment.