This repository was archived by the owner on Feb 5, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -147,7 +147,9 @@ describe('API functions', () => {
147147 } ;
148148
149149 // Use type assertion to bypass TypeScript check for testing runtime validation
150- expect ( ( ) => registerAbility ( ability as unknown as ClientAbility ) ) . toThrow (
150+ expect ( ( ) =>
151+ registerAbility ( ability as unknown as ClientAbility )
152+ ) . toThrow (
151153 'Server abilities cannot be registered via registerAbility'
152154 ) ;
153155 } ) ;
@@ -170,9 +172,9 @@ describe('API functions', () => {
170172 } ;
171173
172174 // Use type assertion to bypass TypeScript check
173- expect ( ( ) => registerAbility ( ability as unknown as ClientAbility ) ) . toThrow (
174- 'Client abilities must include a callback function'
175- ) ;
175+ expect ( ( ) =>
176+ registerAbility ( ability as unknown as ClientAbility )
177+ ) . toThrow ( 'Client abilities must include a callback function' ) ;
176178 } ) ;
177179
178180 it ( 'should throw error for ability without name' , ( ) => {
Original file line number Diff line number Diff line change @@ -382,8 +382,18 @@ describe('validateValueFromSchema', () => {
382382 it ( 'should handle empty schema as valid' , ( ) => {
383383 expect ( validateValueFromSchema ( 'anything' , undefined ) ) . toBe ( true ) ;
384384 // Testing edge cases where schema is null or falsy
385- expect ( validateValueFromSchema ( 123 , null as unknown as Record < string , any > ) ) . toBe ( true ) ;
386- expect ( validateValueFromSchema ( true , false as unknown as Record < string , any > ) ) . toBe ( true ) ;
385+ expect (
386+ validateValueFromSchema (
387+ 123 ,
388+ null as unknown as Record < string , any >
389+ )
390+ ) . toBe ( true ) ;
391+ expect (
392+ validateValueFromSchema (
393+ true ,
394+ false as unknown as Record < string , any >
395+ )
396+ ) . toBe ( true ) ;
387397 } ) ;
388398
389399 it ( 'should handle schema compilation errors' , ( ) => {
Original file line number Diff line number Diff line change @@ -76,12 +76,15 @@ export function registerAbility(ability: ClientAbility): void {
7676 throw new Error ( 'Ability description is required' ) ;
7777 }
7878
79- // Check if it's a server ability and reject it
80- if ( ability . location === 'server' ) {
81- throw new Error ( 'Server abilities cannot be registered via registerAbility' ) ;
79+ // Runtime check for JavaScript consumers who might pass server abilities
80+ // TypeScript users are protected by the ClientAbility type
81+ const anyAbility = ability as any ;
82+ if ( anyAbility . location === 'server' ) {
83+ throw new Error (
84+ 'Server abilities cannot be registered via registerAbility'
85+ ) ;
8286 }
8387
84- // Now we know it's supposed to be a client ability
8588 if ( ! ability . callback || typeof ability . callback !== 'function' ) {
8689 throw new Error ( 'Client abilities must include a callback function' ) ;
8790 }
You can’t perform that action at this time.
0 commit comments