Skip to content

Commit 28503b5

Browse files
committed
fix: declare empty a11y panel protocol
1 parent 9541c9a commit 28503b5

5 files changed

Lines changed: 14 additions & 25 deletions

File tree

‎packages/devframe/src/in-page-channel/page-script.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { AttachedChannelPort } from './internal'
22
import type {
33
CreatePageScriptChannelOptions,
44
InPageChannelProtocol,
5-
InPageFunctionDefinitionAny,
65
PageScriptChannel,
76
PageScriptChannelEvents,
87
PanelPeer,
@@ -64,7 +63,7 @@ export function createPageScriptChannel<P extends InPageChannelProtocol>(
6463
let heartbeatTimer: ReturnType<typeof setInterval> | undefined
6564

6665
const registry = createLocalFunctionRegistry(codec)
67-
for (const [fnName, definition] of Object.entries(options.functions) as [string, Omit<InPageFunctionDefinitionAny, 'name'>][])
66+
for (const [fnName, definition] of Object.entries(options.functions ?? {}))
6867
registry.register({ ...definition, name: fnName })
6968

7069
const stateHost = createPageScriptStateHost<P>(function* () {

‎packages/devframe/src/in-page-channel/panel.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
ConnectPanelChannelOptions,
44
InPageChannelProtocol,
55
InPageChannelStatus,
6-
InPageFunctionDefinitionAny,
76
PanelChannel,
87
PanelChannelEvents,
98
} from './types'
@@ -63,7 +62,7 @@ export function connectPanelChannel<P extends InPageChannelProtocol>(
6362

6463
const events = createEventEmitter<PanelChannelEvents>()
6564
const registry = createLocalFunctionRegistry(codec)
66-
for (const [fnName, definition] of Object.entries(options.functions) as [string, Omit<InPageFunctionDefinitionAny, 'name'>][])
65+
for (const [fnName, definition] of Object.entries(options.functions ?? {}))
6766
registry.register({ ...definition, name: fnName })
6867

6968
let status: InPageChannelStatus = 'connecting'

‎packages/devframe/src/in-page-channel/types.test-d.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import type { InPageChannelProtocol } from './types'
21
import { describe, expectTypeOf, it } from 'vitest'
32
import { createPageScriptChannel } from './page-script'
43
import { connectPanelChannel } from './panel'
54

6-
interface TestProtocol extends InPageChannelProtocol {
5+
interface TestProtocol {
76
pageScript: {
87
echo: (value: string) => string
98
sum: (a: number, b: number) => number
@@ -14,10 +13,11 @@ interface TestProtocol extends InPageChannelProtocol {
1413
}
1514
}
1615

17-
interface PageScriptOnlyProtocol extends InPageChannelProtocol {
16+
interface PageScriptOnlyProtocol {
1817
pageScript: {
1918
echo: (value: string) => string
2019
}
20+
panel: Record<string, never>
2121
}
2222

2323
describe('In-page script channel', () => {
@@ -124,7 +124,7 @@ describe('In-page script channel', () => {
124124
panel.call('notify', false)
125125
})
126126

127-
it('rejects calls when the protocol omits panel functions', () => {
127+
it('rejects calls when the protocol declares no panel functions', () => {
128128
const pageScriptOnlyChannel = createPageScriptChannel<PageScriptOnlyProtocol>({
129129
name: 'devframes:page-script-only',
130130
functions: {
@@ -219,7 +219,7 @@ describe('Panel channel', () => {
219219
})
220220
})
221221

222-
it('rejects definitions when the protocol omits panel functions', () => {
222+
it('accepts an explicitly empty panel function map', () => {
223223
connectPanelChannel<PageScriptOnlyProtocol>({
224224
name: 'devframes:page-script-only',
225225
functions: {},

‎packages/devframe/src/in-page-channel/types.ts‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@ export interface InPageChannelProtocol {
2222
sharedStates?: Record<string, object>
2323
}
2424

25-
type SideFunctions<P, S> = InPageChannelProtocol extends P
26-
? Record<string, (...args: any[]) => any>
27-
: S extends Record<string, (...args: any[]) => any>
28-
? string extends keyof S ? Record<never, never> : S
29-
: Record<never, never>
30-
type PageScriptFunctions<P extends InPageChannelProtocol> = SideFunctions<P, NonNullable<P['pageScript']>>
31-
type PanelFunctions<P extends InPageChannelProtocol> = SideFunctions<P, NonNullable<P['panel']>>
25+
type SideFunctions<S> = S extends Record<string, (...args: any[]) => any> ? S : Record<string, never>
26+
type PageScriptFunctions<P extends InPageChannelProtocol> = SideFunctions<NonNullable<P['pageScript']>>
27+
type PanelFunctions<P extends InPageChannelProtocol> = SideFunctions<NonNullable<P['panel']>>
3228
type SharedStates<P extends InPageChannelProtocol>
3329
= P['sharedStates'] extends Record<string, object> ? P['sharedStates'] : Record<string, never>
3430

@@ -117,9 +113,7 @@ interface InPageFunctionOption<F> {
117113
*/
118114
type CreatePageScriptChannelOptionsFunctions<P extends InPageChannelProtocol> = {
119115
[NAME in keyof PageScriptFunctions<P> & string]: InPageFunctionOption<PageScriptFunctions<P>[NAME]>
120-
} extends infer FUNCTIONS
121-
? keyof FUNCTIONS extends never ? Record<string, never> : FUNCTIONS
122-
: never
116+
}
123117

124118
/**
125119
* Functions implemented by {@link connectPanelChannel}.
@@ -128,9 +122,7 @@ type CreatePageScriptChannelOptionsFunctions<P extends InPageChannelProtocol> =
128122
*/
129123
type ConnectPanelChannelOptionsFunctions<P extends InPageChannelProtocol> = {
130124
[NAME in keyof PanelFunctions<P> & string]: InPageFunctionOption<PanelFunctions<P>[NAME]>
131-
} extends infer FUNCTIONS
132-
? keyof FUNCTIONS extends never ? Record<string, never> : FUNCTIONS
133-
: never
125+
}
134126

135127
/**
136128
* Connection lifecycle of a panel endpoint: `connecting` (handshake retry

‎plugins/a11y/src/shared/protocol.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
* `static` RPC the panel resolves) is forwarded to the page script over the
2020
* same channel, keeping the page script itself free of any RPC dependency.
2121
*/
22-
import type { InPageChannelProtocol } from 'devframe/in-page-channel'
23-
2422
/** In-page channel name. Namespaced with the devframe id, per convention. */
2523
export const A11Y_CHANNEL = 'devframes:plugin:a11y'
2624

@@ -164,7 +162,7 @@ export interface PageScriptConfig {
164162
* aggregate the page script owns. All functions are fire-and-forget events —
165163
* results flow back through the shared state.
166164
*/
167-
export interface A11yChannelProtocol extends InPageChannelProtocol {
165+
export interface A11yChannelProtocol {
168166
pageScript: {
169167
/**
170168
* Draw the transient hover-preview ring around a node's element.
@@ -187,6 +185,7 @@ export interface A11yChannelProtocol extends InPageChannelProtocol {
187185
/** Drop the whole tracked-route history. */
188186
'clear-all': () => void
189187
}
188+
panel: Record<string, never>
190189
sharedStates: {
191190
/** The authoritative route → report aggregate the page script owns. */
192191
state: A11yState

0 commit comments

Comments
 (0)