Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: new scope, actions and full concurrency
- 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.
  • Loading branch information
olivierwilkinson committed Mar 28, 2023
commit 6d9d661d6bf6ef141babb85edb8f3b86682dfbe6
13 changes: 11 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
],
"max-lines-per-function": "off",
"consistent-return": "off",
"jest/no-if": "off"
}
"jest/no-if": "off",
"one-var": "off"
},
"overrides": [
{
"files": ["*.test.ts"],
"rules": {
"max-lines": "off"
}
}
]
}
1 change: 1 addition & 0 deletions .github/workflows/prisma-nested-middleware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- run: npm run validate
env:
CI: true

release:
runs-on: ubuntu-latest
needs: test
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ dist

# Test coverage directory
coverage

# vscode
.vscode
Loading