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

Commit builder API - linking resources to commits #24

Closed
joepio opened this issue Oct 1, 2020 · 6 comments
Closed

Commit builder API - linking resources to commits #24

joepio opened this issue Oct 1, 2020 · 6 comments

Comments

@joepio
Copy link
Member

joepio commented Oct 1, 2020

Atomic Commits describe how a resource is to be mutated. A Commit might mean the resource should be removed, it might mean some fields will be added, it might mean a single field is changed.

Constucting these Commits should be simple. Ideally, developers should not have to deal with commits - they should simply call "destroy" on some instance and it should be removed accordingly.

However, sometimes developers will need to manually create these commits. For example if a developer tries to batch various changes instead of sending the commit after a single change.

This asks for a nice API for building / constructing these commits.

let commit = Commit::new("mySubject");
commit.set("someprop", "someval");
commit.set("otherprop", "otherval");
commit.send();
// send makes sure the signature and timestamp are correct, and it's sent to the right places.
@joepio
Copy link
Member Author

joepio commented Oct 1, 2020

It might also make sense to give Resource instances a CommitBuilder. So when some data manipulation method is called on a resource, a Commit will be instantiated. Only when resource.commit() is called, the Commit will be constructed fully (including timestamp + signature) and it will be shared.

So perhaps a Resource has an Option<Commit>, which is constructed when calling resource.set(prop, val) for example.

joepio added a commit that referenced this issue Oct 2, 2020
joepio added a commit that referenced this issue Oct 2, 2020
@joepio
Copy link
Member Author

joepio commented Oct 10, 2020

The current implementation of storelike.commit indirectly uses Resource.save() - which is a dependency I think should be removed. Resources should probably only write stuff to the store using Commits. This ensures that the Commits are persisted and can be shared to other users.

@joepio
Copy link
Member Author

joepio commented Oct 29, 2020

I think I need to convert Resource into a trait, and have a ResourceLinked for providing the easiest API for external use, but create a ResourceOwned for using in the Commit function. This also fixes a problem where the commit throws an error after some set attributes are applied, but before all the Commit fields are processed - in other words, this would make it transactional.

@joepio
Copy link
Member Author

joepio commented Oct 29, 2020

Or... Instead of the above, where resource methods implicitly call Resource.save() on every update, I can make calling save explicit. Perhaps even better - I think this does not require a new trait.

@joepio joepio changed the title Commit builder API Commit builder API - linking resources to commits Oct 29, 2020
joepio added a commit that referenced this issue Oct 30, 2020
joepio added a commit that referenced this issue Oct 30, 2020
joepio added a commit that referenced this issue Nov 23, 2020
joepio added a commit that referenced this issue Nov 23, 2020
joepio added a commit that referenced this issue Dec 20, 2020
joepio added a commit that referenced this issue Dec 20, 2020
joepio added a commit that referenced this issue Dec 20, 2020
@joepio
Copy link
Member Author

joepio commented Dec 20, 2020

The resource.save() method keeps making things difficult, because I can't invoke the store.commit() method method, since it has sized bounds. #45

@joepio
Copy link
Member Author

joepio commented Dec 21, 2020

A (temporary) fix is calling a similar method from the Store, instead of from the Commit. This method (store.commit_resource_changes) takes the CommitBuilder from a resource and applies it to the store using the default agent.

@joepio joepio closed this as completed Dec 21, 2020
joepio added a commit that referenced this issue Dec 25, 2020
joepio added a commit that referenced this issue Dec 25, 2020
joepio added a commit that referenced this issue Dec 25, 2020
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

No branches or pull requests

1 participant