Skip to content
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

Modernize Codebase #7563

Open
3 tasks done
dblythy opened this issue Sep 9, 2021 · 7 comments
Open
3 tasks done

Modernize Codebase #7563

dblythy opened this issue Sep 9, 2021 · 7 comments
Labels
type:feature New feature or improvement of existing feature

Comments

@dblythy
Copy link
Member

dblythy commented Sep 9, 2021

New Feature / Enhancement Checklist

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

@parse-github-assistant
Copy link

parse-github-assistant bot commented Sep 9, 2021

Thanks for opening this issue!

  • 🎉 We are excited about your ideas for improvement!

@dblythy
Copy link
Member Author

dblythy commented Sep 9, 2021

@mtrezza what is the safest way to do this? File at a time, src only and then spec later?

@mtrezza
Copy link
Member

mtrezza commented Sep 10, 2021

Maybe find a time when many PRs are merged, especially the complex ones.

@dblythy
Copy link
Member Author

dblythy commented Sep 14, 2021

This should include:

  • Converting tests to use expectAsync and not use done unless necessary
  • Improving test descriptions
  • Removing parse.com from tests
  • Convert tests to use JS SDK instead of REST API where applicable
  • Converting .then's to parallel where possible
  • Reducing duplicate code, minifying length of files
  • Removing var
  • Improving coverage

@mtrezza mtrezza added type:feature New feature or improvement of existing feature and removed type:improvement labels Dec 6, 2021
@dblythy dblythy mentioned this issue Oct 12, 2022
31 tasks
@Moumouls
Copy link
Member

Moumouls commented Nov 1, 2022

Hi @dblythy @mtrezza also what do you think about switching parse-server to TS progressively?

@dblythy
Copy link
Member Author

dblythy commented Nov 2, 2022

I am in favour! It will be a big task however

@mtrezza
Copy link
Member

mtrezza commented Nov 2, 2022

This #7334?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or improvement of existing feature
Projects
None yet
Development

No branches or pull requests

3 participants