neighbour-hoods / sensemaker-lite

11 stars 1 forks source link

wrap all returned payloads in utility wrapper for simpler client handling #71

Closed weswalla closed 9 months ago

weswalla commented 10 months ago

I propose that we update all our zome functions to return entries in the below wrapper:

pub struct WrappedEntry<T> {
    pub action_hash: ActionHash,
    pub entry_hash: EntryHash,
    pub entry: T,
}

this gives us flexibility on the client side to use either hash in constructing reactive store objects keyed by hash.

weswalla commented 10 months ago

@nick-stebbings @adaburrows @pospi thoughts?

I know @nick-stebbings could really use this.

weswalla commented 10 months ago

Or, alternatively, we can return Record but provide utility functions to make it easier for developers on the JS side to extract valuable information from it. For example, to get the entry_hash from the record, the object needs to be keyed in the following way: <Record>.signed_action.hashed.content.entry_hash

adaburrows commented 10 months ago

I actually prefer having an envelope that returns records indexed by their entry hash, see the outdated PR https://github.com/neighbour-hoods/sensemaker-lite/pull/46/files#diff-c81f75774fa1ca9e6ab11b0cabd31dd763a8b87d45d3d2c67fd02f56955ce42fR54. What I'd change is that we'd just use the record type so we have access to all the data at that level; but we would still have the data indexed by entry hash, which functions as a good source of identity.

Having utility methods to make it easier for devs is always welcome, but also check out the utilities that holochain open dev has https://github.com/holochain-open-dev/common/tree/main/packages/utils [personally, I haven't looked into these too much, and they might not be general enough to my liking]. There might be some things there we can use, but I'd prefer to have utilities that check the shape to make sure each part of the record is there. If there isn't a convention around returning null/throwing an error/or some other value for "not present" that would be good. I also have some libraries for traversing objects and maintaining type safety that could be improved upon https://github.com/lightningrodlabs/rea-playspace/blob/main/modules/typed-object-tweezers/src/index.ts#L227.