Skip to content

Commit e37323d

Browse files
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.
1 parent f789573 commit e37323d

32 files changed

+12869
-5565
lines changed

.eslintrc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
],
2323
"max-lines-per-function": "off",
2424
"consistent-return": "off",
25-
"jest/no-if": "off"
26-
}
25+
"jest/no-if": "off",
26+
"one-var": "off"
27+
},
28+
"overrides": [
29+
{
30+
"files": ["*.test.ts"],
31+
"rules": {
32+
"max-lines": "off"
33+
}
34+
}
35+
]
2736
}

.github/workflows/prisma-nested-middleware.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
- run: npm run validate
2424
env:
2525
CI: true
26+
2627
release:
2728
runs-on: ubuntu-latest
2829
needs: test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ dist
66

77
# Test coverage directory
88
coverage
9+
10+
# vscode
11+
.vscode

0 commit comments

Comments
 (0)