Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support changing nested params action
Currently modifications to the params of nested actions has been limited to the args field in order to prevent breaking params. The reason changing the action in nested params can cause unexpected behaviour is that the new action may already exist, causing the old args to be overwritten by the new args. Changing two different actions to be the same action would also cause args to be lost. When combining the updated params from nested middleware with the original params there are a few scenarios we need to handle: - if the action does not already exist set the args - if the action exists but and is an operation array push the args - if the action exists but is not an operation array turn it into one and make the previous args the first operation and the new args the second - if the action is createMany operation arrays are not supported and so the args.data arrays must be combined instead. For nested reads the above problems go away since a select cannot be found at the same level as an include, instead of merging we can set and delete the original action. Supporting changing actions also introduces a new problem: Since the passed middleware function for each action at a particular level is processed in parallel the order the actions are defined on the params object matters. If the middleware processes action A before action B then if action B is changed to be action A the new operations added will not be processed by the middleware. Since it is only possible to know if an action has been changed when the params have been passed to next the execution strategy of nested middleware needs to change. Update the middleware execution to wait for params to be passed to next and then execute middleware with the updated params again if the action has changed. This recursive execution ensures every operation is processed regardless of the order of nested actions.
- Loading branch information