frontend-plugin-api: refactor to use opaque type for route refs

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2025-11-17 10:35:21 +01:00
parent 766215437e
commit 4d03f08d19
19 changed files with 282 additions and 278 deletions
+1
View File
@@ -14,4 +14,5 @@
* limitations under the License.
*/
export * from './routing';
export * from './wiring';
@@ -0,0 +1,34 @@
/*
* Copyright 2025 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ExternalRouteRef } from '@backstage/frontend-plugin-api';
import { OpaqueType } from '@internal/opaque';
export const OpaqueExternalRouteRef = OpaqueType.create<{
public: ExternalRouteRef;
versions: {
readonly version: 'v1';
getParams(): string[];
getDescription(): string;
getDefaultTarget(): string | undefined;
setId(id: string): void;
};
}>({
type: '@backstage/ExternalRouteRef',
versions: ['v1'],
});
@@ -0,0 +1,35 @@
/*
* Copyright 2025 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { RouteRef } from '@backstage/frontend-plugin-api';
import { OpaqueType } from '@internal/opaque';
export const OpaqueRouteRef = OpaqueType.create<{
public: RouteRef;
versions: {
readonly version: 'v1';
getParams(): string[];
getDescription(): string;
alias: string | undefined;
setId(id: string): void;
};
}>({
type: '@backstage/RouteRef',
versions: ['v1'],
});
@@ -0,0 +1,32 @@
/*
* Copyright 2025 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { RouteRef, SubRouteRef } from '@backstage/frontend-plugin-api';
import { OpaqueType } from '@internal/opaque';
export const OpaqueSubRouteRef = OpaqueType.create<{
public: SubRouteRef;
versions: {
readonly version: 'v1';
getParams(): string[];
getParent(): RouteRef;
getDescription(): string;
};
}>({
type: '@backstage/SubRouteRef',
versions: ['v1'],
});
@@ -0,0 +1,19 @@
/*
* Copyright 2025 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { OpaqueRouteRef } from './OpaqueRouteRef';
export { OpaqueSubRouteRef } from './OpaqueSubRouteRef';
export { OpaqueExternalRouteRef } from './OpaqueExternalRouteRef';