Skip to content

Conversation

@olivierwilkinson
Copy link
Owner

@olivierwilkinson olivierwilkinson commented Mar 28, 2023

  • move parent params into the scope object

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.

  • add a new "where" action

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.

  • improve speed of async middleware

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.

  • fix merging nested boolean actions

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.

  • include relations in both directions in scope

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.

  • add relation from model to 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.

@olivierwilkinson olivierwilkinson force-pushed the v3 branch 8 times, most recently from 90f7b95 to c037981 Compare March 28, 2023 23:24
- move parent params into the scope object

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.

- add a new "where" action

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.

- improve speed of async middleware

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.

- fix merging nested boolean actions

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.

- include relations in both directions in scope

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.

- add relation from model to 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.
@github-actions
Copy link

🎉 This PR is included in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants