Skip to content

Convert CoreManager and controllers to ES modules #2495

Open
@dplewis

Description

@dplewis

New Feature / Enhancement Checklist

Current Limitation

Controllers are currently plain JS objects and their types are created and maintained separately in the CoreManager. These types are easily overlooked and aren't up to date.

Feature / Enhancement Description

Move the controllers to a separate folder /Controllers. Converting to ES Modules will allow for type generation without having to manually update types in the CoreManager. We can then re-export the types if we need to.

Example Use Case

Controllers/SessionController.ts

  export function getSession(options?: RequestOptions): Promise<ParseSession> {
    const RESTController = CoreManager.getRESTController();
    const session = new ParseSession();

    return RESTController.request('GET', 'sessions/me', {}, options).then(sessionData => {
      session._finishFetch(sessionData);
      session._setExisted(true);
      return session;
    });
}

CoreManager.ts

import * as SessionController from './Controllers/SessionController.ts';

// Can now be deleted
type SessionController = {
  getSession: (options?: RequestOptions) => Promise<ParseSession>;
};

type Config = {
...
SessionController?: SessionController;
...
};

setSessionController(controller: SessionController) {
  requireMethods('SessionController', ['getSession'], controller);
  config['SessionController'] = controller;
},

getSessionController(): SessionController {
   return config['SessionController']!;
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:featureNew feature or improvement of existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions