frontend-plugin-api: convert ApiRef to an opaque type

Convert the ApiRef type in the new frontend system to an opaque type
with a $$type discriminator, matching the pattern used by route refs
and extension data refs. Add a builder-pattern creation overload
(createApiRef<T>().with({ id })) alongside the existing direct-config
form. Create OpaqueApiRef in frontend-internal for internal type
validation.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
Made-with: Cursor
This commit is contained in:
Patrik Oldsberg
2026-03-16 11:09:17 +01:00
parent 05594087b9
commit cc459f73a8
10 changed files with 174 additions and 56 deletions
@@ -166,10 +166,11 @@ describe('createSpecializedApp', () => {
"factories": Map {
"core.featureflags" => {
"factory": {
"api": ApiRefImpl {
"config": {
"id": "core.featureflags",
},
"api": {
"$$type": "@backstage/ApiRef",
"id": "core.featureflags",
"toString": [Function],
"version": "v1",
},
"deps": {},
"factory": [Function],
@@ -178,10 +179,11 @@ describe('createSpecializedApp', () => {
},
"core.app-tree" => {
"factory": {
"api": ApiRefImpl {
"config": {
"id": "core.app-tree",
},
"api": {
"$$type": "@backstage/ApiRef",
"id": "core.app-tree",
"toString": [Function],
"version": "v1",
},
"deps": {},
"factory": [Function],
@@ -190,10 +192,11 @@ describe('createSpecializedApp', () => {
},
"core.config" => {
"factory": {
"api": ApiRefImpl {
"config": {
"id": "core.config",
},
"api": {
"$$type": "@backstage/ApiRef",
"id": "core.config",
"toString": [Function],
"version": "v1",
},
"deps": {},
"factory": [Function],
@@ -202,10 +205,11 @@ describe('createSpecializedApp', () => {
},
"core.route-resolution" => {
"factory": {
"api": ApiRefImpl {
"config": {
"id": "core.route-resolution",
},
"api": {
"$$type": "@backstage/ApiRef",
"id": "core.route-resolution",
"toString": [Function],
"version": "v1",
},
"deps": {},
"factory": [Function],
@@ -214,10 +218,11 @@ describe('createSpecializedApp', () => {
},
"core.identity" => {
"factory": {
"api": ApiRefImpl {
"config": {
"id": "core.identity",
},
"api": {
"$$type": "@backstage/ApiRef",
"id": "core.identity",
"toString": [Function],
"version": "v1",
},
"deps": {},
"factory": [Function],