mdn / browser-compat-data

This repository contains compatibility data for Web technologies as displayed on MDN
https://developer.mozilla.org
Creative Commons Zero v1.0 Universal
4.92k stars 1.98k forks source link

Proposal: "Active” BCD API for exploring browser and feature data #18828

Open ddbeck opened 1 year ago

ddbeck commented 1 year ago

Summary

BCD ought to have an API to make it easier to resolve questions across data contained within BCD, such as comparing specific browsers releases against feature support data. This will unburden BCD consumers of having to hold top-to-bottom knowledge of BCD’s schema and its many concrete permutations.

Problem statement

While BCD is a rich data source, it has a complicated structure and schema that makes it difficult to consume BCD in ways that aren’t not already lined up with its hierarchical, feature-focused structure.

For example, as a consumer, I have to write new code to do any of the following tasks with BCD:

None of this requires data external to BCD, yet the tasks can be remarkably complicated. Generalized consumer code must be able to handle:

To do comparative analysis of a feature’s support (e.g., to compare one browser to another or one feature to another) adds additional complexity that often goes against the grain of BCD’s structure, which was designed to facilitate tabular, version-number oriented reports (i.e., the compat tables on MDN).

This is an active barrier to concrete work consuming BCD for the benefit of web developer audiences. For example, my work with the WebDX CG's feature-set repo is partly blocked by the question of where and how we'll maintain the code for consuming BCD. We anticipate complexity and somewhat strong coupling with BCD, which has caused some of the work to be deferred.

In all other cases, BCD is a passive, complicated data source. But one with immense promise, owing to its detail and quality.

Proposal

To help ameliorate some of the pains I’ve just described, I propose implementing a consumer API—a suite of functions, classes, and methods—that support consumers in the following tasks:

(See the Technical vignette section for more information on a possible shape for this API.)

Expose the API as (preferred) a named export form the BCD package (to support co-versioning with BCD’s schema) or (less preferred) a companion package versioned against BCD’s schema.

Key questions

Key questions remain to be answered before proceeding:

Technical vignette

I understand that it’s hard to accept a vague proposal, so here I’d like to offer an illustration of what that API might look like. Please remember that this is for illustrative purposes, to characterize the overall flavor of such an API—I expect the review of PRs to determine the actual working API.

But consider this non-working code snippet:

let b = browser("safari");
const currentSafari = b.releaseAt(0);
currentSafari.release_date;
// ⮐ "2023-01-23"

let currentChrome /* = … */;
let currentFirefox /* = … */;

const containerAtRule = feature("css.at-rules.container");
containerAtRule.supportedBy(currentSafari);
// ⮐ true

containerAtRule.supportedBy(currentSafari, currentChrome, currentFirefox);
// ⮐ true

// And so on…
containerAtRule.supportedBy(...browser("safari").releasesSince("2022-01-01"))

Briefly, the API would consist of:

I’ve put together a TypeScript declaration that provides a more detailed specification of the API described above. Do keep in mind that it’s far from final (and a great many details depend on the implementation, rather than the interface declaration).

ddbeck commented 1 year ago

@queengooborg, @Elchi3: This is a follow on from our chat last week.

cc: @foolip write up continues the TS declaration you've seen previously

Elchi3 commented 1 year ago

Maintainers of https://github.com/mdn/bcd-utils, what do you think?

@fiji-flo @caugner @LeoMcA @Guyzeroth

ddbeck commented 1 year ago

In a chat earlier today, @Elchi3 asked a great question: how would this impact semantic versioning? BCD took a long time to achieve some consistency around semver, so it's good to think about how this might affect that.

I think there's two plausible routes and I prefer the first:

  1. Initially, declare the API as experimental and not subject to semver. If possible, emit a warning when you explicitly import the API (I think this is possible with a named export). After we achieve stability, add the API to the semver contract. I expect that, once stable, the API and schema would change together, so it would be rare to have a semver major release caused by API-only changes.

  2. Publish the API as a standalone package, versioned to mirror the BCD schema version (e.g., use the BCD version plus build metadata as in 5.2.36+utils-1.0.0). This is workable, but less convenient: it requires a peer dependency with BCD and—depending on the versioning scheme—doesn't play as nicely with package management tools.

There's also a third route, which is option 1 with extra steps: develop as a standalone package and merge into the main BCD package at a later date (i.e., when the API is "1.0.0"-ready).

A fourth route that I considered and think we ought to reject is letting the API and data diverge. Testing an API in a matrix with multiple versions of BCD (even within the same semver major range) is intrinsically more complicated. I don't think it's a good use of contributors' time and attention to build or maintain such a thing.