@@ -30,6 +30,12 @@ type SharedStates<P extends InPageChannelProtocol>
3030
3131type FnArgs < F > = F extends ( ...args : infer A ) => any ? A : never
3232type FnReturn < F > = F extends ( ...args : any [ ] ) => infer R ? Awaited < R > : never
33+
34+ /**
35+ * Converts a protocol function to its accepted endpoint handler.
36+ *
37+ * @internal
38+ */
3339type ProtocolHandler < F > = F extends ( ...args : any [ ] ) => any
3440 ? ( ...args : FnArgs < F > ) => Thenable < FnReturn < F > >
3541 : never
@@ -78,47 +84,45 @@ export type InPageFunctionDefinition<
7884 handler : ( ...args : InferArgsType < AS > ) => Thenable < InferReturnType < RS > >
7985 }
8086
81- /** Loosely-typed definition — the registration unit both endpoints accept. */
87+ /**
88+ * Loosely-typed definition used by the internal function registry.
89+ *
90+ * @internal
91+ */
8292export type InPageFunctionDefinitionAny = InPageFunctionDefinition < string , any , any , any , any , any >
8393
84- type ProtocolSide = 'pageScript' | 'panel'
85- type ProtocolSideFunctions <
86- P extends InPageChannelProtocol ,
87- SIDE extends ProtocolSide ,
88- > = SideFunctions < NonNullable < P [ SIDE ] > >
94+ /**
95+ * Function metadata with its handler constrained by a protocol function.
96+ *
97+ * @internal
98+ */
99+ interface InPageFunctionOption < F > {
100+ type ?: InPageFunctionType
101+ /** Optional Standard Schema array validating the arguments. */
102+ args ?: RpcArgsSchema
103+ /** Optional Standard Schema validating the resolved return value. */
104+ returns ?: RpcReturnSchema
105+ jsonSerializable ?: boolean
106+ handler : ProtocolHandler < F >
107+ }
89108
90109/**
91- * A function definition constrained by one side of an in-page channel
92- * protocol. The `name` discriminant selects the matching protocol function,
93- * which contextually types the handler's arguments and return value.
110+ * Functions implemented by { @link createPageScriptChannel}.
111+ *
112+ * @internal
94113 */
95- export type InPageFunctionDefinitionFor <
96- P extends InPageChannelProtocol ,
97- SIDE extends ProtocolSide ,
98- > = {
99- [ NAME in keyof ProtocolSideFunctions < P , SIDE > & string ] : {
100- name : NAME
101- type ?: InPageFunctionType
102- /** Optional Standard Schema array validating the arguments. */
103- args ?: RpcArgsSchema
104- /** Optional Standard Schema validating the resolved return value. */
105- returns ?: RpcReturnSchema
106- jsonSerializable ?: boolean
107- handler : ProtocolHandler < ProtocolSideFunctions < P , SIDE > [ NAME ] >
108- }
109- } [ keyof ProtocolSideFunctions < P , SIDE > & string ]
114+ type CreatePageScriptChannelOptionsFunctions < P extends InPageChannelProtocol > = {
115+ [ NAME in keyof PageScriptFunctions < P > & string ] : InPageFunctionOption < PageScriptFunctions < P > [ NAME ] >
116+ }
110117
111- type InPageFunctionOptions <
112- P extends InPageChannelProtocol ,
113- SIDE extends ProtocolSide ,
114- > = InPageChannelProtocol extends P
115- ? Record < string , Omit < InPageFunctionDefinitionAny , 'name' > >
116- : {
117- [ NAME in keyof ProtocolSideFunctions < P , SIDE > & string ] : Omit <
118- Extract < InPageFunctionDefinitionFor < P , SIDE > , { name : NAME } > ,
119- 'name'
120- >
121- }
118+ /**
119+ * Functions implemented by {@link connectPanelChannel}.
120+ *
121+ * @internal
122+ */
123+ type ConnectPanelChannelOptionsFunctions < P extends InPageChannelProtocol > = {
124+ [ NAME in keyof PanelFunctions < P > & string ] : InPageFunctionOption < PanelFunctions < P > [ NAME ] >
125+ }
122126
123127/**
124128 * Connection lifecycle of a panel endpoint: `connecting` (handshake retry
@@ -127,6 +131,11 @@ type InPageFunctionOptions<
127131 */
128132export type InPageChannelStatus = 'connecting' | 'connected' | 'closed'
129133
134+ /**
135+ * Options shared by both in-page channel endpoints.
136+ *
137+ * @internal
138+ */
130139interface InPageChannelCommonOptions {
131140 /**
132141 * Channel name, namespaced with the devframe id by convention
@@ -165,7 +174,7 @@ interface InPageChannelCommonOptions {
165174/** Options for {@link createPageScriptChannel}. */
166175export interface CreatePageScriptChannelOptions < Protocol extends InPageChannelProtocol = InPageChannelProtocol > extends InPageChannelCommonOptions {
167176 /** Implementations of the protocol's page-script functions. */
168- functions ?: InPageFunctionOptions < Protocol , 'pageScript' >
177+ functions ?: CreatePageScriptChannelOptionsFunctions < Protocol >
169178 /**
170179 * Window whose `message` events carry panel hellos. Defaults to the
171180 * global `window`; pass `false` to skip the handshake listener entirely
@@ -177,7 +186,7 @@ export interface CreatePageScriptChannelOptions<Protocol extends InPageChannelPr
177186/** Options for {@link connectPanelChannel}. */
178187export interface ConnectPanelChannelOptions < Protocol extends InPageChannelProtocol = InPageChannelProtocol > extends InPageChannelCommonOptions {
179188 /** Implementations of the protocol's panel functions. */
180- functions ?: InPageFunctionOptions < Protocol , 'panel' >
189+ functions ?: ConnectPanelChannelOptionsFunctions < Protocol >
181190 /**
182191 * The panel's own window (listens for the handshake grant). Defaults to
183192 * the global `window`; pass `false` with `transport` to skip the handshake.
0 commit comments