feat: new scope, actions and full concurrency #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are other fields that are only relevant when handling a nested
action so move the parent params into the scope object under the
"parentParams" field to make room for them.
The "where" action calls the middleware function for each relation
found in where objects.
In order to make the args have a consistent format the modifiers that
can be found after a relation such as "some" or "every" have been moved
to the scope object.
Also add the logical operators that needed to be traversed to find the
relation to the scope object, these can be either "OR", "NOT" or "AND".
Since these operators can be chained the "logicalOperators" field in
scope is an array.
The current recursive strategy for resolving nested middleware has a
major drawback that each layer of async middleware needs to be resolved
one after the other, this can make async middleware extremely slow.
Instead recurse through the params object to find all the nested params
that the middleware function needs to be called with and then execute
the middleware for all params at once.
Once all the updated params have been resolved execute the root next
function and then synchronously parse the result to find all the slices
necessary for "include" and "select" actions.
Once all the slices of the result have been found we can resolve the
nested middleware next functions and await their updated results in
parallel.
The final result object can then be updated synchronously as well.
Add "connect" and "disconnect" to the list of available actions
Support converting a single nested action to multiple actions
Since multiple nested actions can be found at the same level of a params
object it is possible to convert a single nested action into multiple
actions by setting the resulting params into the corresponding fields
based off their action type.
This is done by passing an array of NestedParams objects to the next
function.
When merging a nested boolean action, for example a delete true action,
the params do not support arrays of operations. Instead of merging into
an array of operations set the value of the operation to the new value.
Process calls that change the action last when building params, this
allows changes of action to overwrite the default args when the target
action is defined before the changed action.
Some middleware needs to make use of the relation from the current model
to the parent model, for example to find the foreign key that references
the parent.
relations are now stored on the scope object under "relations". The
relations object has "to" and "from" keys for the relation to the model
and from the model back to the parent respectively.
update README for new features and try to better explain how to write
middleware using createNestedMiddleware
fix count query without args
add smoke tests
BREAKING CHANGE: scope is no longer the parent params and relation has
been moved to live inside of the scope object.