({
domain,
className,
types,
commands,
events,
enhancement,
specVersion,
typeNameToDomain,
})
| 782 | } |
| 783 | |
| 784 | function generateDomainFile({ |
| 785 | domain, |
| 786 | className, |
| 787 | types, |
| 788 | commands, |
| 789 | events, |
| 790 | enhancement, |
| 791 | specVersion, |
| 792 | typeNameToDomain, |
| 793 | }) { |
| 794 | const parts = [LICENSE_HEADER, ''] |
| 795 | |
| 796 | parts.push(`// Auto-generated from WebDriver BiDi CDDL spec (v${specVersion}) — DO NOT EDIT MANUALLY`) |
| 797 | parts.push(`// Source: https://github.com/w3c/webref/tree/main/ed/cddl`) |
| 798 | parts.push('') |
| 799 | |
| 800 | const filteredCommands = commands.filter((c) => !enhancement.excludeMethods?.includes(c.methodName)) |
| 801 | const filteredEvents = events.filter((e) => !enhancement.excludeMethods?.includes(e.eventName)) |
| 802 | const hasImplementation = className != null && (filteredCommands.length > 0 || filteredEvents.length > 0) |
| 803 | |
| 804 | // Filter out excluded types before emitting. |
| 805 | let typeBlock = types |
| 806 | if (enhancement.excludeTypes?.length) { |
| 807 | typeBlock = filterExcludedTypes(typeBlock, enhancement.excludeTypes) |
| 808 | } |
| 809 | |
| 810 | // Compute cross-domain imports needed by this domain's type block. |
| 811 | // Types from other domains are referenced by name but live in separate files. |
| 812 | const crossDomainImports = computeCrossDomainImports(typeBlock, domain, typeNameToDomain) |
| 813 | |
| 814 | if (crossDomainImports.length > 0) { |
| 815 | for (const line of crossDomainImports) { |
| 816 | parts.push(line) |
| 817 | } |
| 818 | parts.push('') |
| 819 | } |
| 820 | |
| 821 | if (hasImplementation) { |
| 822 | // Define the BiDi connection interface inline so the generated file is |
| 823 | // self-contained for tsc and doesn't need to resolve ../index.js. |
| 824 | parts.push(`/** Minimal BiDi transport interface (satisfied structurally by bidi/index.js). */`) |
| 825 | parts.push(`interface BidiConnection {`) |
| 826 | parts.push(` send(command: Record<string, unknown>): Promise<unknown>`) |
| 827 | parts.push(` subscribe(event: string | string[], contexts?: string[]): Promise<void>`) |
| 828 | parts.push(` on(event: string, listener: (params: unknown) => void): void`) |
| 829 | parts.push(`}`) |
| 830 | parts.push('') |
| 831 | } |
| 832 | |
| 833 | if (typeBlock) { |
| 834 | parts.push(`// --- Types ---`) |
| 835 | parts.push('') |
| 836 | parts.push(typeBlock) |
| 837 | parts.push('') |
| 838 | } |
| 839 | |
| 840 | if (enhancement.extraTypes) { |
| 841 | parts.push(`// --- Additional Types ---`) |
no test coverage detected