Skip to content

Commit beb0a79

Browse files
committed
build: validate typed protocol registry fragments
1 parent ba9bb70 commit beb0a79

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

‎scripts/check-protocol-registry.mts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,25 @@ check(
3939
);
4040

4141
const composition = registrySource.match(
42-
/export const ProtocolSchemas = composeProtocolSchemaFragments\(\[([\s\S]*?)\]\s+as const\);/u,
42+
/export const ProtocolSchemas:\s*([\s\S]*?)\s*= composeProtocolSchemaFragments\(\[([\s\S]*?)\]\s+as const\);/u,
4343
);
44-
const composedBindings = (composition?.[1] ?? "")
44+
const composedBindings = (composition?.[2] ?? "")
4545
.split("\n")
4646
.map((line) => line.trim().replace(/,$/u, ""))
4747
.filter(Boolean);
48+
const annotatedBindings = (composition?.[1] ?? "")
49+
.split("&")
50+
.map((type) => /^typeof ([A-Za-z0-9_]+)$/u.exec(type.trim())?.[1]);
4851
const importedBindings = fragmentImports.map(({ binding }) => binding);
49-
check(Boolean(composition), `${registryPath} must explicitly compose an ordered fragment array`);
52+
check(
53+
Boolean(composition),
54+
`${registryPath} must explicitly type and compose an ordered fragment array`,
55+
);
56+
check(
57+
annotatedBindings.length === composedBindings.length &&
58+
annotatedBindings.every((binding, index) => binding === composedBindings[index]),
59+
`${registryPath} must annotate the composed fragments with their exact ordered typeof intersection`,
60+
);
5061
check(
5162
composedBindings.length === importedBindings.length &&
5263
new Set(composedBindings).size === composedBindings.length &&

0 commit comments

Comments
 (0)