Collection resources

Resgate looks like a great fit for my project. Thank you for providing this.

I have a few questions about collections, specifically how to do the following with collections:

replace, move: I see that these events are on the roadmap for 2020-Q4. Is there any chance of moving those earlier? I’m aware that they can both be implemented with multiple add/remove events.

clear, set: I need to clear or replace an entire collection. Once again these can be done with multiple add/remove events or deleting the collection resource and creating again but it would be great to have a more direct way of doing these.

Also, in regard to creating new collections, the RES service protocol spec says that the NEW call request is deprecated for creating new models and collections and to use “resource response” instead. I’m not sure what that means. What is the appropriate way to create new model and collection resources?

Hi, and welcome to the forum! :slightly_smiling_face:

Replace/move/clear/set

The roadmap is not set in stone, so it is possible to re-prioritize if needed.

Just to try to understand the need; I see a few reasons why this can be requested:

  1. Reducing the number of events. Changing [1,2,3] into [2,3,1] would require 2 events with remove/add, while having a move event would require only one.
  2. Simplify for the service to describe a mutation, especially when large parts/the entire collection is updated.
  3. For the sake of the client (and the UI) to better describe how the data transformed into the new state.

Now, if 1 and 2 is your reasons, this can sort of be achieved by sending a system.reset, but only for the specific resource. This will cause Resgate to refetch that specific resource, compare it with its own cached version, and generate add/remove events that describes the diff, and send those events to the client(s). So, system.reset is a single event to update any changes.

But 3 is different. Maybe the front-end UI wish to do different types of animations depending on the transformation. Maybe to animate a replaced value in a list by cross-fading from the old to the new, while a removed value should have the height of the graphical component collapsing. Or if the entire list is set, you would want to cross-fade the entire list. Those sort of things. A system.reset won’t help you here.

So, the question is, would system.reset work for you, or is it more about better describing the transition for the front-end client?

Resource response

The resource response is to make method calls that returns a resource. This is commonly used when making calls to create resources, as you often want to get that newly created resource back:

client.call('inventory.items', 'create', { name: "Rubber duck", quantity: 20 })
    .then(item => console.log(item.name)); // Logs Rubber duck

The client doesn’t know before-hand the resource ID of the newly created resource, but when the service responds with the resource ID, Resgate will fetch that resource and return it to the client in the
response.

The deprecated new call achieved the same, but forced you to use the method name new. Resource response allows you to use any method name.

So you can also use it for letting clients subscribe to resources they don’t know the resource ID for. Maybe, after logging in, you want to get your own user profile, without knowing your own user ID. Eg:

client.call('directory.users', 'getCurrentlyLoggedInUser')
    .then(user => console.log(user.name)); // Samuel

That said, you can create resources whenever/however you want. Resource response is just to allow you to send the newly created resource back to the client without it having to make a separate get request directly after.

Hope that clarifies it.

Best regards,
Samuel

Thank you for your quick reply. Using system.reset after updating collection resources is a good solution. Thank you.

And thank you for the clarification on creating new resources.

We are looking forward to using Resgate for our project.