Skip to content

Commit 9846b90

Browse files
committed
Demonstrate JSON Schema as source of truth
1 parent f9e880f commit 9846b90

9 files changed

+1527
-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: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
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+
[property: string]: any;
107+
}
108+
109+
/**
110+
* Whether developers are formally discouraged from using this feature
111+
*/
112+
export interface Discouraged {
113+
/**
114+
* Links to a formal discouragement notice, such as specification text, intent-to-unship,
115+
* etc.
116+
*/
117+
according_to: string[];
118+
/**
119+
* IDs for features that substitute some or all of this feature's utility
120+
*/
121+
alternatives?: string[];
122+
}
123+
124+
/**
125+
* Whether a feature is considered a "Baseline" web platform feature and when it achieved
126+
* that status
127+
*/
128+
export interface StatusHeadline {
129+
/**
130+
* Whether the feature is Baseline (low substatus), Baseline (high substatus), or not (false)
131+
*/
132+
baseline: boolean | BaselineEnum;
133+
/**
134+
* Date the feature achieved Baseline high status
135+
*/
136+
baseline_high_date?: string;
137+
/**
138+
* Date the feature achieved Baseline low status
139+
*/
140+
baseline_low_date?: string;
141+
/**
142+
* Browser versions that most-recently introduced the feature
143+
*/
144+
support: Support;
145+
/**
146+
* Statuses for each key in the feature's compat_features list, if applicable. Not available
147+
* to the npm release of web-features.
148+
*/
149+
by_compat_key?: { [key: string]: Status };
150+
[property: string]: any;
151+
}
152+
153+
export type BaselineEnum = "high" | "low";
154+
155+
export interface Status {
156+
/**
157+
* Whether the feature is Baseline (low substatus), Baseline (high substatus), or not (false)
158+
*/
159+
baseline: boolean | BaselineEnum;
160+
/**
161+
* Date the feature achieved Baseline high status
162+
*/
163+
baseline_high_date?: string;
164+
/**
165+
* Date the feature achieved Baseline low status
166+
*/
167+
baseline_low_date?: string;
168+
/**
169+
* Browser versions that most-recently introduced the feature
170+
*/
171+
support: Support;
172+
[property: string]: any;
173+
}
174+
175+
/**
176+
* Browser versions that most-recently introduced the feature
177+
*/
178+
export interface Support {
179+
chrome?: string;
180+
chrome_android?: string;
181+
edge?: string;
182+
firefox?: string;
183+
firefox_android?: string;
184+
safari?: string;
185+
safari_ios?: string;
186+
}
187+
188+
export interface GroupData {
189+
/**
190+
* Short name
191+
*/
192+
name: string;
193+
/**
194+
* Identifier of parent group
195+
*/
196+
parent?: string;
197+
}
198+
199+
export interface SnapshotData {
200+
/**
201+
* Short name
202+
*/
203+
name?: string;
204+
/**
205+
* Specification
206+
*/
207+
spec?: string;
208+
[property: string]: any;
209+
}

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)