kurierjs / kurier

TypeScript framework to create JSON:API compliant APIs

Home Page:https://kurier.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support JSON-based, light-weight syntax for resource definition

joelalejandro opened this issue · comments

It'd be interesting to make types in Application a dual-type property:

types: typeof Resource[] | ResourceSchemaList;

So in the Application constructor, we could dynamically create Resource classes accordingly.

ResourceSchemaList would be an object-based list like:

{
  ResourceName: {
    attributes: {},
    relationships: {}
  }
}

The resourceSchemaListToResourceClasses method would look something like:

Object.entries(resourceSchemaList).map(([resourceName, schemaDefinition]) => class extends Resource {
  static schema = { ...schemaDefinition };
});

Could be a way to mitigate a problem described in #294.

Supporting this feature implies a major rewrite of the way Processors work, it's too much of a cost for a minimal benefit. I'm calling off development on this.