Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: added ability to serialize/deserialize pods list and content items #213

Merged
merged 10 commits into from
Feb 14, 2023

Conversation

IgorShadurin
Copy link
Collaborator

@IgorShadurin IgorShadurin commented Jan 20, 2023

This PR changes the return data format for some methods. In general, all methods now return plain objects/arrays for ease of conversion to/from JSON.

Changed methods:
fdp.directory.read
fdp.file.downloadData
fdp.personalStorage.list
fdp.personalStorage.create

Close #209

@IgorShadurin IgorShadurin marked this pull request as ready for review January 23, 2023 06:30
@IgorShadurin IgorShadurin requested a review from nugaon as a code owner January 23, 2023 06:30
Copy link
Collaborator

@nugaon nugaon left a comment

Choose a reason for hiding this comment

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

See my comments below, but it can be merged from my side after @tomicvladan approved.

src/content-items/serialization.ts Outdated Show resolved Hide resolved
src/pod/utils.ts Outdated Show resolved Hide resolved
src/content-items/serialization.ts Outdated Show resolved Hide resolved
@tomicvladan
Copy link
Contributor

This approach could work, but it will be still complicated to use. Because there is no uniform API. The proxy object in Blossom will have to intercept each call and analyze whether it should apply serialization/deserialization or not. This might be difficult to maintain later when new changes are applied to fdp-storage. It will be difficult to keep track of changes and whether they require updates on the proxy side.

Instead of that, I think much better approach would be to reorganize these two classes: DirectoryItem and List. In the DirectoryItem class, instead of having getFiles and getDirectories methods, the class could contain public properties files and directories already filtered. It won't increase memory too much because those are just two arrays with the same references. But there will be no need for any methods inside it. Similar can be done with the List as well.

In the future we can keep the same approach for new features, so each method returns only pure objects without any methods inside. I think that will make fdp-storage much more usable, especially because we plan to use it in a variety of environments.

@IgorShadurin
Copy link
Collaborator Author

This approach could work, but it will be still complicated to use. Because there is no uniform API. The proxy object in Blossom will have to intercept each call and analyze whether it should apply serialization/deserialization or not. This might be difficult to maintain later when new changes are applied to fdp-storage. It will be difficult to keep track of changes and whether they require updates on the proxy side.

Instead of that, I think much better approach would be to reorganize these two classes: DirectoryItem and List. In the DirectoryItem class, instead of having getFiles and getDirectories methods, the class could contain public properties files and directories already filtered. It won't increase memory too much because those are just two arrays with the same references. But there will be no need for any methods inside it. Similar can be done with the List as well.

In the future we can keep the same approach for new features, so each method returns only pure objects without any methods inside. I think that will make fdp-storage much more usable, especially because we plan to use it in a variety of environments.

@nugaon wdyt?

@nugaon
Copy link
Collaborator

nugaon commented Jan 30, 2023

I agree with @tomicvladan let's rid of the classes and make simple objects/arrays from those.

@tomicvladan
Copy link
Contributor

I think all the changes should be:

src/pod/list.ts

Instead of:

getPods(): Pod[];
getSharedPods(): SharedPod[];

Should be:

pods: Pod[];
sharedPods : SharedPod[];

src/content-items/directory-item.ts

Instead of:

getFiles(): FileItem[];
getDirectories(): DirectoryItem[];
static fromRawDirectoryMetadata(item: RawDirectoryMetadata): DirectoryItem;

Should be:

files: FileItem[];
directories: DirectoryItem[];

// maybe exported function form another module?
export function fromRawDirectoryMetadata(item: RawDirectoryMetadata): DirectoryItem;

@tomicvladan
Copy link
Contributor

I remembered one more class that needs to be handled somehow, the Data response returned by File.downloadData. It has methods that transform data to different forms.

@IgorShadurin
Copy link
Collaborator Author

Now the returned results are simple objects that can be converted via JSON.stringify/parse

@tomicvladan

@IgorShadurin IgorShadurin requested a review from nugaon February 9, 2023 11:07
Copy link
Collaborator

@nugaon nugaon left a comment

Choose a reason for hiding this comment

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

We need to have a breaking change and make all returns JSON compatible without any mapping and transitions.
@tomicvladan, approve this PR if everything goes smoothly in Blossom.

src/content-items/utils.ts Outdated Show resolved Hide resolved
src/pod/utils.ts Outdated Show resolved Hide resolved
@tomicvladan
Copy link
Contributor

Other than class names, it looks good. I just think that we need to remove the Serializable from all class names.

@nugaon nugaon changed the title refactor: added ability to serialize/deserialize pods list and content items refactor!: added ability to serialize/deserialize pods list and content items Feb 13, 2023
@nugaon
Copy link
Collaborator

nugaon commented Feb 13, 2023

before merge, please update PR details about the interface changes

@IgorShadurin IgorShadurin merged commit 6ecc7f6 into master Feb 14, 2023
@IgorShadurin IgorShadurin deleted the feat/209-objects-serialization branch February 14, 2023 13:38
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.

Personal storage API changes
3 participants