Skip to content

fix: clone history events to prevent mutation#479

Open
sam-goodwin wants to merge 3 commits intomainfrom
sam/fix-mutable-events
Open

fix: clone history events to prevent mutation#479
sam-goodwin wants to merge 3 commits intomainfrom
sam/fix-mutable-events

Conversation

@sam-goodwin
Copy link
Copy Markdown
Owner

No description provided.

Comment on lines +1597 to +1599
e = await mutateEntity.get({
pk: "pk",
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: delete to clean up

Comment on lines +2 to +3
// TODO: more efficient deep clone
return item === undefined ? item : JSON.parse(JSON.stringify(item));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create issue?

): Promise<{ storedBytes: number }> {
// provides a shallow copy of the history events.
const historyEvents = executor.history.slice(0);
const historyEvents = executor.historyCloned.slice(0);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use .historyCloned in the iterator in here, leave it private, and then leave the original array in the .history?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants