File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -138,6 +138,7 @@ export function defineResource(
138138) : ResourceAction {
139139 const action = dynamicResource ( opts , fn ) ;
140140 action . matches = createMatcher ( opts . uri , opts . template ) ;
141+ action . __action . metadata . dynamic = false ;
141142 registry . registerAction ( 'resource' , action ) ;
142143 return action ;
143144}
@@ -193,7 +194,7 @@ export async function findMatchingResource(
193194
194195/** Checks whether provided object is a dynamic resource. */
195196export function isDynamicResourceAction ( t : unknown ) : t is ResourceAction {
196- return isAction ( t ) && ! t . __registry ;
197+ return isAction ( t ) && t . __action ?. metadata ?. dynamic === true ;
197198}
198199
199200/**
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import {
2323 dynamicResource ,
2424 findMatchingResource ,
2525 isDynamicResourceAction ,
26+ resource ,
2627} from '../../src/resource.js' ;
2728import { defineEchoModel } from '../helpers.js' ;
2829
@@ -58,7 +59,7 @@ describe('resource', () => {
5859 uri : 'foo://bar' ,
5960 } ,
6061 type : 'resource' ,
61- dynamic : true ,
62+ dynamic : false ,
6263 } ) ;
6364
6465 assert . strictEqual ( testResource . matches ( { uri : 'foo://bar' } ) , true ) ;
@@ -229,7 +230,7 @@ describe('resource', () => {
229230 uri : undefined ,
230231 } ,
231232 type : 'resource' ,
232- dynamic : true ,
233+ dynamic : false ,
233234 } ) ;
234235
235236 const gotBaz = await findMatchingResource ( registry , resList , {
@@ -286,4 +287,15 @@ describe('isDynamicResourceAction', () => {
286287 true
287288 ) ;
288289 } ) ;
290+
291+ it ( 'should remain dynamic after registration' , ( ) => {
292+ const dynamic = resource ( { uri : 'bar://baz' } , ( ) => ( {
293+ content : [ { text : `bar` } ] ,
294+ } ) ) ;
295+ assert . strictEqual ( isDynamicResourceAction ( dynamic ) , true ) ;
296+
297+ registry . registerAction ( 'resource' , dynamic ) ;
298+
299+ assert . strictEqual ( isDynamicResourceAction ( dynamic ) , true ) ;
300+ } ) ;
289301} ) ;
You can’t perform that action at this time.
0 commit comments