fix: clone history events to prevent mutation#479
Open
sam-goodwin wants to merge 3 commits intomainfrom
Open
Conversation
thantos
suggested changes
Nov 9, 2023
Comment on lines
+1597
to
+1599
| e = await mutateEntity.get({ | ||
| pk: "pk", | ||
| }); |
Comment on lines
+2
to
+3
| // TODO: more efficient deep clone | ||
| return item === undefined ? item : JSON.parse(JSON.stringify(item)); |
| ): Promise<{ storedBytes: number }> { | ||
| // provides a shallow copy of the history events. | ||
| const historyEvents = executor.history.slice(0); | ||
| const historyEvents = executor.historyCloned.slice(0); |
Contributor
There was a problem hiding this comment.
maybe just use the cloned one in the executor's iterator and return the original array in .history?
Comment on lines
+210
to
+220
| // clone the history so it cannot be modified by the user | ||
| public historyCloned: HistoryStateEvent[]; | ||
|
|
||
| constructor( | ||
| private workflow: Workflow<any, Input, Output>, | ||
| public history: HistoryStateEvent[], | ||
| // TODO: properties used in the workflow should be encoded in the history to keep them constant between runs | ||
| private propertyRetriever: PropertyRetriever, | ||
| private eventualFactory: EventualFactory = createDefaultEventualFactory() | ||
| ) { | ||
| this.historyCloned = deepClone(history); |
Contributor
There was a problem hiding this comment.
maybe use .historyCloned in the iterator in here, leave it private, and then leave the original array in the .history?
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.
No description provided.