-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: Allow short circuit of beforeFind #9770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EmpiDev
wants to merge
34
commits into
parse-community:alpha
Choose a base branch
from
EmpiDev:beforeFind-fix
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
6f65ec5
feat: allow short circuit of beforeFind
dblythy 41bf1b7
improve test description
mtrezza 21c9289
Update CloudCode.spec.js
dblythy ca74929
wip
dblythy 207c3c0
wip
dblythy bc68816
wip
dblythy d66fa48
Merge branch 'alpha' into beforeFind-objects
mtrezza 34f7741
feat: allow short circuit of beforeFind
dblythy 5825abf
improve test description
mtrezza 6daa039
Update CloudCode.spec.js
dblythy ec37789
wip
dblythy 09fcde2
wip
dblythy 8de0edb
Merge branch 'beforeFind-objects' of https://github.com/dblythy/parse…
EmpiDev dd75062
refactor: remove redundant beforeFind tests and clean up afterFind hooks
EmpiDev 8d6aae6
refactor: improve condition checks and format function parameters for…
EmpiDev c5dd665
test: update beforeFind test to create and save a new object
EmpiDev 55c3b3b
Merge branch 'alpha' into beforeFind-fix
EmpiDev d8525e9
fix : Unexpected token '}' 2057
EmpiDev 04ae88f
Merge branch 'alpha' into beforeFind-fix
EmpiDev f083527
Merge branch 'alpha' into beforeFind-fix
EmpiDev f679ba0
Merge branch 'alpha' into beforeFind-fix
EmpiDev dfd4082
Merge branch 'alpha' into beforeFind-fix
EmpiDev 43a87bb
Merge branch 'alpha' into beforeFind-fix
mtrezza c417118
refactor: Improve afterFind trigger handling and object processing
EmpiDev c6463c3
Merge branch 'alpha' into beforeFind-fix
EmpiDev 0c2ad57
Merge branch 'alpha' into beforeFind-fix
mtrezza 92ef147
refactor in CloudCode.spec.js
EmpiDev 546e5b0
refactor in triggers.js
EmpiDev 00b104e
test: Add direct function tests for maybeRunAfterFindTrigger
EmpiDev 2a5dce9
Remove unnecessary comment
EmpiDev 98be232
refactor: Replace isGet boolean flag with options object
EmpiDev 0d42676
Provide isGet context to afterFind trigger
EmpiDev f197119
fix: Correct parameter formatting in afterFind trigger test
EmpiDev 06e2bcc
Merge branch 'alpha' into beforeFind-fix
EmpiDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,36 +23,93 @@ function checkTriggers(className, config, types) { | |
function checkLiveQuery(className, config) { | ||
return config.liveQueryController && config.liveQueryController.hasLiveQuery(className); | ||
} | ||
async function runFindTriggers( | ||
config, | ||
auth, | ||
className, | ||
restWhere, | ||
restOptions, | ||
clientSDK, | ||
context, | ||
options = {} | ||
) { | ||
const { isGet } = options; | ||
const result = await triggers.maybeRunQueryTrigger( | ||
triggers.Types.beforeFind, | ||
className, | ||
restWhere, | ||
restOptions, | ||
config, | ||
auth, | ||
context, | ||
isGet | ||
); | ||
|
||
restWhere = result.restWhere || restWhere; | ||
restOptions = result.restOptions || restOptions; | ||
|
||
if (result?.objects) { | ||
const objectsFromBeforeFind = result.objects; | ||
|
||
const afterFindProcessedObjects = await triggers.maybeRunAfterFindTrigger( | ||
triggers.Types.afterFind, | ||
auth, | ||
className, | ||
objectsFromBeforeFind, | ||
config, | ||
new Parse.Query(className).withJSON({ where: restWhere, ...restOptions }), | ||
context, | ||
isGet | ||
); | ||
|
||
return { | ||
results: afterFindProcessedObjects, | ||
}; | ||
} | ||
|
||
// Returns a promise for an object with optional keys 'results' and 'count'. | ||
const find = async (config, auth, className, restWhere, restOptions, clientSDK, context) => { | ||
const query = await RestQuery({ | ||
method: RestQuery.Method.find, | ||
method: isGet ? RestQuery.Method.get : RestQuery.Method.find, | ||
config, | ||
auth, | ||
className, | ||
restWhere, | ||
restOptions, | ||
clientSDK, | ||
context, | ||
runBeforeFind: false, | ||
}); | ||
|
||
return query.execute(); | ||
} | ||
|
||
// Returns a promise for an object with optional keys 'results' and 'count'. | ||
const find = async (config, auth, className, restWhere, restOptions, clientSDK, context) => { | ||
enforceRoleSecurity('find', className, auth); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: how the enforce role security was implemented before, it's not clear |
||
return runFindTriggers( | ||
config, | ||
auth, | ||
className, | ||
restWhere, | ||
restOptions, | ||
clientSDK, | ||
context, | ||
{ isGet: false } | ||
); | ||
}; | ||
|
||
// get is just like find but only queries an objectId. | ||
const get = async (config, auth, className, objectId, restOptions, clientSDK, context) => { | ||
var restWhere = { objectId }; | ||
const query = await RestQuery({ | ||
method: RestQuery.Method.get, | ||
enforceRoleSecurity('get', className, auth); | ||
return runFindTriggers( | ||
config, | ||
auth, | ||
className, | ||
restWhere, | ||
{ objectId }, | ||
restOptions, | ||
clientSDK, | ||
context, | ||
}); | ||
return query.execute(); | ||
{ isGet: true } | ||
); | ||
}; | ||
|
||
// Returns a promise that doesn't resolve to any useful value. | ||
|
Oops, something went wrong.
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 was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: i suggest to introduce a new context variable like "beforeFindReturnObjects" to allow developers to adjust afterFind or skip afterFind logic if beforeFind returned objects