ref to json

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2024-09-06 12:44:01 +02:00
parent b4ae0c8309
commit 8052b9b313
2 changed files with 22 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-plugin-api': patch
---
Add a `toJSON` on refs so that they can appear in expectations in jest tests
@@ -17,7 +17,9 @@
import { BackendFeature } from '../../types';
/**
* TODO
* A reference to a backend service. You can use these references to mark
* dependencies on services and having their implementations injected
* automatically.
*
* @public
*/
@@ -39,6 +41,11 @@ export type ServiceRef<
*/
scope: TScope;
/**
* Marks whether the service is a multiton or not. Multiton services the
* opposite of singletons - they can be provided many times, and when depended
* on, you receive an array of all provided instances.
*/
multiton?: TInstances extends 'multiton' ? true : false;
/**
@@ -142,6 +149,15 @@ export function createServiceRef<
toString() {
return `serviceRef{${options.id}}`;
},
toJSON() {
// This avoids accidental calls to T happening e.g. in tests
return {
$$type: '@backstage/ServiceRef',
id,
scope,
multiton,
};
},
$$type: '@backstage/ServiceRef',
__defaultFactory: defaultFactory,
} as ServiceRef<TService, typeof scope, TInstances> & {