Parse-SDK-JS icon indicating copy to clipboard operation
Parse-SDK-JS copied to clipboard

Convert CoreManager and controllers to ES modules

Open dplewis opened this issue 8 months ago • 1 comments

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']!;
},

dplewis avatar Mar 12 '25 01:03 dplewis