parse-community / parse-community/parse-server
Modernize Codebase
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 21.4k
- Forks
- 4.8k
- Avg merge
- 7h 45m
- Merged PRs (30d)
- 11
Description
New Feature / Enhancement Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
Current Limitation
Sometimes, contributing can be really hard as some of the internal code was written in 2015, without the uses of await/async or modern JS features. The hardest part can be getting your head around how the code works.
Feature / Enhancement Description
Modernize codebase and unit tests to make future contributing easier. A lot of the unit tests could be written in much less lines using expectAsync.
Would obviously have to be a progressive, file-by-file approach with minimal interruptions.
An example is the function that handles cloud functions:
static createResponseObject(resolve, reject) {
return {
success: function (result) {
resolve({
response: {
result: Parse._encode(result),
},
});
},
error: function (message) {
const error = triggers.resolveError(message);
reject(error);
},
};
}
static handleCloudFunction(req) {
const functionName = req.params.functionName;
const applicationId = req.config.applicationId;
const theFunction = triggers.getFunction(functionName, applicationId);
if (!theFunction) {
throw new Parse.Error(Parse.Error.SCRIPT_FAILED, `Invalid function: "${functionName}"`);
}
let params = Object.assign({}, req.body, req.query);
params = parseParams(params);
const request = {
params: params,
master: req.auth && req.auth.isMaster,
user: req.auth && req.auth.user,
installationId: req.info.installationId,
log: req.config.loggerController,
headers: req.config.headers,
ip: req.config.ip,
functionName,
context: req.info.context,
};
return new Promise(function (resolve, reject) {
const userString = req.auth && req.auth.user ? req.auth.user.id : undefined;
const cleanInput = logger.truncateLogMessage(JSON.stringify(params));
const { success, error } = FunctionsRouter.createResponseObject(
result => {
try {
const cleanResult = logger.truncateLogMessage(JSON.stringify(result.response.result));
logger.info(
`Ran cloud function ${functionName} for user ${userString} with:\n Input: ${cleanInput}\n Result: ${cleanResult}`,
{
functionName,
params,
user: userString,
}
);
resolve(result);
} catch (e) {
reject(e);
}
},
error => {
try {
logger.error(
`Failed running cloud function ${functionName} for user ${userString} with:\n Input: ${cleanInput}\n Error: ` +
JSON.stringify(error),
{
functionName,
error,
params,
user: userString,
}
);
reject(error);
} catch (e) {
reject(e);
}
}
);
return Promise.resolve()
.then(() => {
return triggers.maybeRunValidator(request, functionName, req.auth);
})
.then(() => {
return theFunction(request);
})
.then(success, error);
});
}
Example Use Case
Alternatives / Workarounds
Leave as is
3rd Party References
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the FunctionsRouter.handleCloudFunction example and the unit tests around it. Review how the current promise chains and callbacks could be modernized, then identify a narrowly scoped file-by-file change using async/await or expectAsync. Done is not defined for the broader codebase modernization, so the specific target and tests must be agreed first.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- backend, developer-experience, testing
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100