Skip to content

Commit 4fc4df3

Browse files
authored
feat(external-router): integrate automatic URL resolution from in-memory routable objects (#4145)
Updates the in-memory driver to automatically resolve URLs by looking them up in the new centralized routable objects registry, eliminating the need for manual resolver configuration when using the in-memory drivers.
1 parent f9c012d commit 4fc4df3

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

  • libs/external-router/driver/in-memory/src

libs/external-router/driver/in-memory/src/config.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import { inject } from '@angular/core';
2+
13
import { createConfigInjectionToken } from '@daffodil/core';
4+
import {
5+
DAFF_INMEMORY_ROUTABLE_OBJECTS,
6+
DaffInMemoryRoutableObjects,
7+
} from '@daffodil/driver/in-memory';
28
import { DaffExternallyResolvableUrl } from '@daffodil/external-router';
3-
import { DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION } from '@daffodil/external-router/driver';
4-
59
/**
610
* A lookup for a URL.
711
* Returns an {@link DaffExternallyResolvableUrl} or
@@ -16,10 +20,6 @@ export interface DaffExternalRouterDriverInMemoryConfig {
1620
resolver: DaffExternalRouterDriverInMemoryResolver;
1721
}
1822

19-
const defaultConfig: DaffExternalRouterDriverInMemoryConfig = {
20-
resolver: () => DAFF_EXTERNAL_ROUTER_NOT_FOUND_RESOLUTION,
21-
};
22-
2323
export const {
2424
/**
2525
* The token used by Daffodil to hold the driver's configuration.
@@ -31,4 +31,19 @@ export const {
3131
* Provider function for {@link DAFF_EXTERNAL_ROUTER_DRIVER_IN_MEMORY_CONFIG}.
3232
*/
3333
provider: provideDaffExternalRouterDriverInMemoryConfig,
34-
} = createConfigInjectionToken<DaffExternalRouterDriverInMemoryConfig>(defaultConfig, 'DAFF_EXTERNAL_ROUTER_DRIVER_IN_MEMORY_CONFIG');
34+
} = createConfigInjectionToken<DaffExternalRouterDriverInMemoryConfig>(undefined, 'DAFF_EXTERNAL_ROUTER_DRIVER_IN_MEMORY_CONFIG', {
35+
factory: () => ({
36+
resolver: (url: string): DaffExternallyResolvableUrl => {
37+
const ROUTEABLE_OBJECTS: DaffInMemoryRoutableObjects = inject(DAFF_INMEMORY_ROUTABLE_OBJECTS);
38+
if(!ROUTEABLE_OBJECTS.has(url)) {
39+
return null;
40+
}
41+
return {
42+
id: ROUTEABLE_OBJECTS.get(url).url,
43+
code: 200,
44+
type: ROUTEABLE_OBJECTS.get(url).type,
45+
url: ROUTEABLE_OBJECTS.get(url).url,
46+
};
47+
},
48+
}),
49+
});

0 commit comments

Comments
 (0)