curveball / core

The Curveball framework is a TypeScript framework for node.js with support for modern HTTP features.
https://curveballjs.org/
MIT License
525 stars 7 forks source link

Remove the Context interface #192

Closed evert closed 2 years ago

evert commented 2 years ago

Curveball had a Context interface and BaseContext class. The idea was that it might be possible for users to create alternative Context classes.

In practice this has never happened, and is probably not that useful. The idea of using interfaces for everything is also something that I blindly applied before fully getting my bearings in Typescript.

The way things work with Curveball is that subclassing the Context is not the primary way to extend it, we monkey patch it because sublassing is not practical (for different reasons, lemme know if you want to know more).

There's some drawbacks to the interface. Patching the Context by other middlewares such as the router, session, oauth2 middleware and others is a really useful feature and lets them add new properties like ctx.session. To do that these packages all need to extend the interfaces twice and it's annoying. See for example this example from the router package:

import '@curveball/core';

declare module '@curveball/core' {

  interface BaseContext {
    params: Record<string, string>;
  }
  interface Context {
    params: Record<string, string>;
  }

}

This is a breaking change so this will be part of Curveball 0.18.