core-plugin-api: add forwards compatibility for route refs

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2025-11-17 21:19:03 +01:00
parent 4d03f08d19
commit 83439b1539
22 changed files with 496 additions and 108 deletions
+1 -1
View File
@@ -625,7 +625,7 @@ export function createExternalRouteRef<
}
| undefined = undefined,
TParamKeys extends string = string,
>(options?: {
>(config?: {
readonly params?: string extends TParamKeys
? (keyof TParams)[]
: TParamKeys[];
@@ -25,10 +25,12 @@ describe('ExternalRouteRef', () => {
expect(internal.getParams()).toEqual([]);
expect(String(internal)).toMatch(
/^ExternalRouteRef\{created at '.*ExternalRouteRef\.test\.ts.*'\}$/,
/^externalRouteRef\{id=undefined,at='.*ExternalRouteRef\.test\.ts.*'\}$/,
);
internal.setId('some-id');
expect(String(internal)).toBe('ExternalRouteRef{some-id}');
expect(String(internal)).toMatch(
/^externalRouteRef\{id=some-id,at='.*ExternalRouteRef\.test\.ts.*'\}$/,
);
});
it('should be created with params', () => {
@@ -27,7 +27,7 @@ describe('RouteRef', () => {
expect(internal.getDescription()).toMatch(/RouteRef\.test\.ts/);
expect(String(internal)).toMatch(
/^RouteRef\{created at .*RouteRef\.test\.ts.*\}$/,
/^routeRef\{id=undefined,at='.*RouteRef\.test\.ts.*'\}$/,
);
expect(() => internal.setId('')).toThrow(
@@ -35,7 +35,9 @@ describe('RouteRef', () => {
);
internal.setId('some-id');
expect(String(internal)).toBe('RouteRef{some-id}');
expect(String(internal)).toMatch(
/^routeRef\{id=some-id,at='.*RouteRef\.test\.ts.*'\}$/,
);
internal.setId('some-id'); // Should allow same ID
expect(() => internal.setId('some-other-id')).toThrow(
@@ -35,10 +35,12 @@ describe('SubRouteRef', () => {
expect(internal.getParent()).toBe(internalParent);
expect(internal.getParams()).toEqual([]);
expect(String(internal)).toMatch(
/SubRouteRef\{at \/foo with parent created at '.*SubRouteRef\.test\.ts.*'\}/,
/^subRouteRef\{path='\/foo',parent=routeRef\{id=undefined,at='.*SubRouteRef\.test\.ts.*'\}\}$/,
);
internalParent.setId('some-id');
expect(String(internal)).toBe('SubRouteRef{at /foo with parent some-id}');
expect(String(internal)).toMatch(
/^subRouteRef\{path='\/foo',parent=routeRef\{id=some-id,at='.*SubRouteRef\.test\.ts.*'\}\}$/,
);
});
it('should be created with params', () => {