Skip to content

Commit 7c9c780

Browse files
committed
Demonstrate JSON Schema as source of truth
1 parent f9e880f commit 7c9c780

9 files changed

+1524
-15
lines changed

.prettierignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/**/*.dist
33
/**/dist
44

5-
65
# Exclude the website includes since these are typically fragments, or include
76
# things that makes Prettier unhappy.
87
/gh-pages/src/_includes/**
@@ -18,7 +17,7 @@ towards-features.md
1817
/docs
1918
!/docs/publishing.md
2019
/features/draft
21-
/schemas
20+
/schemas/data.schema.json
2221
/scripts/caniuse.ts
2322
/scripts/schema.ts
2423
/scripts/specs.ts

index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from 'path';
44
import { Temporal } from '@js-temporal/polyfill';
55
import { fdir } from 'fdir';
66
import YAML from 'yaml';
7-
import { FeatureData, GroupData, SnapshotData, WebFeaturesData } from './types';
7+
import { FeatureData, GroupData, SnapshotData, WebFeaturesData } from './newtypes';
88

99
import { toString as hastTreeToString } from 'hast-util-to-string';
1010
import rehypeStringify from 'rehype-stringify';

new.quicktype.ts

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
/**
2+
* The top-level web-features data package
3+
*/
4+
export interface WebFeaturesData {
5+
/**
6+
* Browsers and browser release data
7+
*/
8+
browsers: Browsers;
9+
/**
10+
* Feature identifiers and data
11+
*/
12+
features: { [key: string]: FeatureData };
13+
/**
14+
* Group identifiers and data
15+
*/
16+
groups: { [key: string]: GroupData };
17+
/**
18+
* Snapshot identifiers and data
19+
*/
20+
snapshots?: { [key: string]: SnapshotData };
21+
}
22+
23+
/**
24+
* Browsers and browser release data
25+
*/
26+
export interface Browsers {
27+
chrome: BrowserData;
28+
chrome_android: BrowserData;
29+
edge: BrowserData;
30+
firefox: BrowserData;
31+
firefox_android: BrowserData;
32+
safari: BrowserData;
33+
safari_ios: BrowserData;
34+
}
35+
36+
/**
37+
* Browser information
38+
*/
39+
export interface BrowserData {
40+
/**
41+
* The name of the browser, as in "Edge" or "Safari on iOS"
42+
*/
43+
name: string;
44+
releases: Release[];
45+
}
46+
47+
/**
48+
* Browser release information
49+
*/
50+
export interface Release {
51+
/**
52+
* The release date, as in "2023-12-11"
53+
*/
54+
date: string;
55+
/**
56+
* The version string, as in "10" or "17.1"
57+
*/
58+
version: string;
59+
}
60+
61+
/**
62+
* A feature data entry
63+
*/
64+
export interface FeatureData {
65+
/**
66+
* caniuse.com identifier(s)
67+
*/
68+
caniuse?: string[] | string;
69+
/**
70+
* Sources of support data for this feature
71+
*/
72+
compat_features?: string[];
73+
/**
74+
* Short description of the feature, as a plain text string
75+
*/
76+
description: string;
77+
/**
78+
* Short description of the feature, as an HTML string
79+
*/
80+
description_html: string;
81+
/**
82+
* Whether developers are formally discouraged from using this feature
83+
*/
84+
discouraged?: Discouraged;
85+
/**
86+
* Group identifier(s)
87+
*/
88+
group?: string[] | string;
89+
/**
90+
* Short name
91+
*/
92+
name: string;
93+
/**
94+
* Snapshot identifier(s)
95+
*/
96+
snapshot?: string[] | string;
97+
/**
98+
* Specification URL(s)
99+
*/
100+
spec: string[] | string;
101+
/**
102+
* Whether a feature is considered a "Baseline" web platform feature and when it achieved
103+
* that status
104+
*/
105+
status?: StatusHeadline;
106+
}
107+
108+
/**
109+
* Whether developers are formally discouraged from using this feature
110+
*/
111+
export interface Discouraged {
112+
/**
113+
* Links to a formal discouragement notice, such as specification text, intent-to-unship,
114+
* etc.
115+
*/
116+
according_to: string[];
117+
/**
118+
* IDs for features that substitute some or all of this feature's utility
119+
*/
120+
alternatives?: string[];
121+
}
122+
123+
/**
124+
* Whether a feature is considered a "Baseline" web platform feature and when it achieved
125+
* that status
126+
*/
127+
export interface StatusHeadline {
128+
/**
129+
* Whether the feature is Baseline (low substatus), Baseline (high substatus), or not (false)
130+
*/
131+
baseline: boolean | BaselineEnum;
132+
/**
133+
* Date the feature achieved Baseline high status
134+
*/
135+
baseline_high_date?: string;
136+
/**
137+
* Date the feature achieved Baseline low status
138+
*/
139+
baseline_low_date?: string;
140+
/**
141+
* Browser versions that most-recently introduced the feature
142+
*/
143+
support: Support;
144+
/**
145+
* Statuses for each key in the feature's compat_features list, if applicable. Not available
146+
* to the npm release of web-features.
147+
*/
148+
by_compat_key?: { [key: string]: Status };
149+
[property: string]: any;
150+
}
151+
152+
export type BaselineEnum = "high" | "low";
153+
154+
export interface Status {
155+
/**
156+
* Whether the feature is Baseline (low substatus), Baseline (high substatus), or not (false)
157+
*/
158+
baseline: boolean | BaselineEnum;
159+
/**
160+
* Date the feature achieved Baseline high status
161+
*/
162+
baseline_high_date?: string;
163+
/**
164+
* Date the feature achieved Baseline low status
165+
*/
166+
baseline_low_date?: string;
167+
/**
168+
* Browser versions that most-recently introduced the feature
169+
*/
170+
support: Support;
171+
[property: string]: any;
172+
}
173+
174+
/**
175+
* Browser versions that most-recently introduced the feature
176+
*/
177+
export interface Support {
178+
chrome?: string;
179+
chrome_android?: string;
180+
edge?: string;
181+
firefox?: string;
182+
firefox_android?: string;
183+
safari?: string;
184+
safari_ios?: string;
185+
}
186+
187+
export interface GroupData {
188+
/**
189+
* Short name
190+
*/
191+
name: string;
192+
/**
193+
* Identifier of parent group
194+
*/
195+
parent?: string;
196+
}
197+
198+
export interface SnapshotData {
199+
/**
200+
* Short name
201+
*/
202+
name?: string;
203+
/**
204+
* Specification
205+
*/
206+
spec?: string;
207+
[property: string]: any;
208+
}

newtypes.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Quicktype produces a definitions that are correct, but not as narrow or
2+
// well-named as hand-written type definition might produce. This module takes
3+
// the Quicktype-generated types as renames or modifies the types to be somewhat
4+
// nicer to work with in TypeScript.
5+
6+
import type {
7+
BaselineEnum as BaselineHighLow,
8+
BrowserData,
9+
Browsers,
10+
GroupData,
11+
FeatureData as QuicktypeMonolithicFeatureData,
12+
WebFeaturesData as QuicktypeWebFeaturesData,
13+
Release,
14+
SnapshotData,
15+
Status,
16+
StatusHeadline,
17+
Support,
18+
} from "./new.quicktype";
19+
20+
// Passthrough types
21+
export type {
22+
BaselineHighLow,
23+
BrowserData,
24+
Browsers,
25+
GroupData,
26+
Release,
27+
SnapshotData,
28+
Status,
29+
StatusHeadline,
30+
Support,
31+
};
32+
33+
export interface WebFeaturesData
34+
extends Pick<QuicktypeWebFeaturesData, "browsers" | "groups" | "snapshots"> {
35+
features: { [key: string]: FeatureData };
36+
}
37+
38+
export type FeatureData = Required<
39+
Pick<
40+
QuicktypeMonolithicFeatureData,
41+
"description_html" | "description" | "name" | "spec" | "status"
42+
>
43+
> &
44+
Partial<
45+
Pick<
46+
QuicktypeMonolithicFeatureData,
47+
"caniuse" | "compat_features" | "discouraged"
48+
>
49+
>;
50+
51+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
52+
const t1: FeatureData = {
53+
name: "Test",
54+
description: "Hi",
55+
description_html: "Hi",
56+
spec: "",
57+
status: {
58+
baseline: false,
59+
support: {},
60+
},
61+
};
62+
63+
export type BrowserIdentifier = keyof Browsers;

0 commit comments

Comments
 (0)