Skip to content

Improve adapters returned interface #3

@alexandercerutti

Description

@alexandercerutti

As per the first version of sub37, the whole architecture expects Adapters always to return a ParseResult, containing data and perhaps some ParseError.

The idea was to have ParseResult and ParseError exposed by the BaseAdapter so that every adapter could use them without importing anything else and without making @sub37/server export other material.

However, the current situation reveals itself to be somehow inconsistent:

  1. BaseAdapter/index.ts exports BaseAdapter (default), ParseResult, and ParseError classes. We should technically move Parse* to a different file;

  2. BaseAdapter exposes ParseResult as an instance property, but not ParseError;

  3. Related to the points above, tests and WebVTT adapter use ParseResult from there, while BaseAdapter should have been the entry point to access them.
    This happens because BaseAdapter.ParseResult is actually a method that returns a new ParseResult and, therefore it cannot be used as right-hand in an instanceof comparison: we must use instanceof ParseResult, but we should use instanceof BaseAdapter.ParseResult;

  4. BaseAdapter exposes both ParseResult and ParseError types by using a namespace;

  5. ParseError class is exposed from BaseAdapter/index.ts module, but it is not used as a class (this happens due to the point 3, so it is an useless class.

Fixing the whole situation is quite breaking, so should be fixed in the next major.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions