Skip to content

Commit 79bffce

Browse files
authored
change refs emission to be for all named non-container types (#1765)
* change refs emission to be for all named non-container types (still do not auto-promote root) * format * doc with both short- and long-term strategies for finishing this implementation * progress towards working implementation, still WIP * update fixtures to no longer expect root types to always be promoted to named defs (only promote if referenced elsewhere) * and finish updating js-runtime fixtures' expectations too * don't include callables/function-like things in json schemas * update README about skipping callables * handle anonymous type cycles more properly by synthesizing a name for them AnonymousType_{counter} * fix linting * factor out structure for special-casing certain built-in types' schemas * handle certain built-in types specially * fix bug i just introduced * fix built-in type handling * improve handling of boolean schemas as per robin's PR comment * fmt
1 parent 9f605a1 commit 79bffce

31 files changed

+1124
-480
lines changed

packages/js-runtime/test/fixtures/handler-schema/array-cell-remove-intersection.expected.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,32 @@ interface ListState {
77
items: Cell<Item[]>;
88
}
99
const removeItem = handler({} as const satisfies JSONSchema, {
10+
$schema: "https://json-schema.org/draft-07/schema#",
1011
type: "object",
1112
properties: {
1213
items: {
1314
type: "array",
1415
items: {
15-
type: "object",
16-
properties: {
17-
text: {
18-
type: "string"
19-
}
20-
},
21-
required: ["text"]
16+
$ref: "#/definitions/Item"
2217
},
2318
asCell: true
2419
},
2520
index: {
2621
type: "number"
2722
}
2823
},
29-
required: ["items", "index"]
24+
required: ["items", "index"],
25+
definitions: {
26+
Item: {
27+
type: "object",
28+
properties: {
29+
text: {
30+
type: "string"
31+
}
32+
},
33+
required: ["text"]
34+
}
35+
}
3036
} as const satisfies JSONSchema, (_, { items, index }) => {
3137
const next = items.get().slice();
3238
if (index >= 0 && index < next.length)
@@ -38,26 +44,32 @@ type ListStateWithIndex = ListState & {
3844
index: number;
3945
};
4046
const removeItemAlias = handler({} as const satisfies JSONSchema, {
47+
$schema: "https://json-schema.org/draft-07/schema#",
4148
type: "object",
4249
properties: {
4350
items: {
4451
type: "array",
4552
items: {
46-
type: "object",
47-
properties: {
48-
text: {
49-
type: "string"
50-
}
51-
},
52-
required: ["text"]
53+
$ref: "#/definitions/Item"
5354
},
5455
asCell: true
5556
},
5657
index: {
5758
type: "number"
5859
}
5960
},
60-
required: ["items", "index"]
61+
required: ["items", "index"],
62+
definitions: {
63+
Item: {
64+
type: "object",
65+
properties: {
66+
text: {
67+
type: "string"
68+
}
69+
},
70+
required: ["text"]
71+
}
72+
}
6173
} as const satisfies JSONSchema, (_, { items, index }) => {
6274
const next = items.get().slice();
6375
if (index >= 0 && index < next.length)

packages/js-runtime/test/fixtures/handler-schema/date-and-map-types.expected.ts

Lines changed: 19 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -9,117 +9,57 @@ interface TimedState {
99
history: Map<string, Date>;
1010
}
1111
const timedHandler = handler({
12+
$schema: "https://json-schema.org/draft-07/schema#",
1213
type: "object",
1314
properties: {
1415
timestamp: {
1516
type: "string",
1617
format: "date-time"
1718
},
1819
data: {
20+
$ref: "#/definitions/Map"
21+
}
22+
},
23+
required: ["timestamp", "data"],
24+
definitions: {
25+
Map: {
1926
type: "object",
2027
properties: {
21-
clear: {
22-
type: "object",
23-
properties: {}
24-
},
25-
delete: {
26-
type: "object",
27-
properties: {}
28-
},
29-
forEach: {
30-
type: "object",
31-
properties: {}
32-
},
33-
get: {
34-
type: "object",
35-
properties: {}
36-
},
37-
has: {
38-
type: "object",
39-
properties: {}
40-
},
41-
set: {
42-
type: "object",
43-
properties: {}
44-
},
4528
size: {
4629
type: "number"
47-
},
48-
entries: {
49-
type: "object",
50-
properties: {}
51-
},
52-
keys: {
53-
type: "object",
54-
properties: {}
55-
},
56-
values: {
57-
type: "object",
58-
properties: {}
5930
}
6031
},
61-
required: ["clear", "delete", "forEach", "get", "has", "set", "size", "entries", "keys", "values"]
32+
required: ["size"]
6233
}
63-
},
64-
required: ["timestamp", "data"]
34+
}
6535
} as const satisfies JSONSchema, {
36+
$schema: "https://json-schema.org/draft-07/schema#",
6637
type: "object",
6738
properties: {
6839
lastUpdate: {
6940
type: "string",
7041
format: "date-time"
7142
},
7243
history: {
44+
$ref: "#/definitions/Map"
45+
}
46+
},
47+
required: ["lastUpdate", "history"],
48+
definitions: {
49+
Map: {
7350
type: "object",
7451
properties: {
75-
clear: {
76-
type: "object",
77-
properties: {}
78-
},
79-
delete: {
80-
type: "object",
81-
properties: {}
82-
},
83-
forEach: {
84-
type: "object",
85-
properties: {}
86-
},
87-
get: {
88-
type: "object",
89-
properties: {}
90-
},
91-
has: {
92-
type: "object",
93-
properties: {}
94-
},
95-
set: {
96-
type: "object",
97-
properties: {}
98-
},
9952
size: {
10053
type: "number"
101-
},
102-
entries: {
103-
type: "object",
104-
properties: {}
105-
},
106-
keys: {
107-
type: "object",
108-
properties: {}
109-
},
110-
values: {
111-
type: "object",
112-
properties: {}
11354
}
11455
},
115-
required: ["clear", "delete", "forEach", "get", "has", "set", "size", "entries", "keys", "values"]
56+
required: ["size"]
11657
}
117-
},
118-
required: ["lastUpdate", "history"]
58+
}
11959
} as const satisfies JSONSchema, (event, state) => {
12060
state.lastUpdate = event.timestamp;
12161
event.data.forEach((value, key) => {
12262
state.history.set(key, new Date());
12363
});
12464
});
125-
export { timedHandler };
65+
export { timedHandler };

packages/js-runtime/test/fixtures/jsx-expressions/jsx-complex-mixed.expected.tsx

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,13 @@ interface State {
1313
taxRate: number;
1414
}
1515
export default recipe({
16+
$schema: "https://json-schema.org/draft-07/schema#",
1617
type: "object",
1718
properties: {
1819
items: {
1920
type: "array",
2021
items: {
21-
type: "object",
22-
properties: {
23-
id: {
24-
type: "number"
25-
},
26-
name: {
27-
type: "string"
28-
},
29-
price: {
30-
type: "number"
31-
},
32-
active: {
33-
type: "boolean"
34-
}
35-
},
36-
required: ["id", "name", "price", "active"]
22+
$ref: "#/definitions/Item"
3723
}
3824
},
3925
filter: {
@@ -46,7 +32,27 @@ export default recipe({
4632
type: "number"
4733
}
4834
},
49-
required: ["items", "filter", "discount", "taxRate"]
35+
required: ["items", "filter", "discount", "taxRate"],
36+
definitions: {
37+
Item: {
38+
type: "object",
39+
properties: {
40+
id: {
41+
type: "number"
42+
},
43+
name: {
44+
type: "string"
45+
},
46+
price: {
47+
type: "number"
48+
},
49+
active: {
50+
type: "boolean"
51+
}
52+
},
53+
required: ["id", "name", "price", "active"]
54+
}
55+
}
5056
} as const satisfies JSONSchema, (state) => {
5157
return {
5258
[UI]: (<div>
@@ -84,4 +90,3 @@ export default recipe({
8490
</div>),
8591
};
8692
});
87-

0 commit comments

Comments
 (0)