Skip to content

Remove 'flat' dependency#509

Merged
Amndeep7 merged 4 commits intomainfrom
remove_flat
Jul 9, 2025
Merged

Remove 'flat' dependency#509
Amndeep7 merged 4 commits intomainfrom
remove_flat

Conversation

@Amndeep7
Copy link
Contributor

@Amndeep7 Amndeep7 commented Jul 9, 2025

It's causing issues downstream with the esm/cjs stuff esp in jest, also I don't think it is necessary at all.

Amndeep7 added 3 commits July 9, 2025 12:41
Signed-off-by: Amndeep Singh Mann <amann@mitre.org>
Signed-off-by: Amndeep Singh Mann <amann@mitre.org>
…ass this means just the instance variables more or less. since not all the values in the instance variables are primitives, do a deep clone so as to ensure everythign is a copy and not a shared reference to an object

Signed-off-by: Amndeep Singh Mann <amann@mitre.org>
@Amndeep7 Amndeep7 requested review from em-c-rod and georgedias July 9, 2025 16:46
});

return new Control(unflatten(flattened));
return new Control(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason not to remove this function entirely?

Copy link
Contributor

Choose a reason for hiding this comment

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

@em-c-rod I agree, there isn't any references to control.toUnformattedObject() only the Profile.toUnformattedObject() is used.

Therefore, I don't know what issue this was causing to warrant being changed during testing!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@em-c-rod it seems like it's useful as a pseudo-factory function to create a clone of the original clone for whatever reason it was needed.

in any case, i want to make minimal changes here so reduce scope creep of something that's already larger than i want it to be

this.tags = {};
if (data) {
Object.entries(data).forEach(([key, value]) => {
Object.entries(_.cloneDeep(data)).forEach(([key, value]) => {
Copy link

Choose a reason for hiding this comment

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

Would the original purpose of the usage of the flat library have been to ensure a deep clone of the control object?

Copy link
Contributor

Choose a reason for hiding this comment

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

@DMedina6 The _.cloneDeep is creating a copy (copying by value, recursively, including nested objects) of data and assigning to this. If data gets changes this is not changed. We do not make use (not in the SAF CLI) of the Control contractor with data.

I'm ok with this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DMedina6 that's what it seems like might be happening to me but idk what the point of the loop was with the string only values

@DMedina6
Copy link

DMedina6 commented Jul 9, 2025

Cloned and ran the tests and everything passed on my end.

Copy link
Contributor

@georgedias georgedias left a comment

Choose a reason for hiding this comment

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

I'm ok with proposed changes.

this.tags = {};
if (data) {
Object.entries(data).forEach(([key, value]) => {
Object.entries(_.cloneDeep(data)).forEach(([key, value]) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

@DMedina6 The _.cloneDeep is creating a copy (copying by value, recursively, including nested objects) of data and assigning to this. If data gets changes this is not changed. We do not make use (not in the SAF CLI) of the Control contractor with data.

I'm ok with this change.

});

return new Control(unflatten(flattened));
return new Control(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

@em-c-rod I agree, there isn't any references to control.toUnformattedObject() only the Profile.toUnformattedObject() is used.

Therefore, I don't know what issue this was causing to warrant being changed during testing!

@Amndeep7 Amndeep7 merged commit ad0b703 into main Jul 9, 2025
3 checks passed
@Amndeep7 Amndeep7 deleted the remove_flat branch July 9, 2025 22:27
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.

4 participants