@backstage/plugin-catalog-node 1.16.3 → 1.17.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/dist/catalogService.cjs.js +6 -0
- package/dist/catalogService.cjs.js.map +1 -1
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +21 -2
- package/dist/processing/parse.cjs.js +43 -0
- package/dist/processing/parse.cjs.js.map +1 -0
- package/dist/testUtils/catalogServiceMock.cjs.js +1 -0
- package/dist/testUtils/catalogServiceMock.cjs.js.map +1 -1
- package/dist/testUtils.d.ts +2 -1
- package/package.json +13 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# @backstage/plugin-catalog-node
|
|
2
2
|
|
|
3
|
+
## 1.17.0-next.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a459f17: Added `parseEntityYaml` from `@backstage/plugin-catalog-backend`, to make it more easily usable by custom plugins and modules
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @backstage/backend-plugin-api@1.3.1-next.1
|
|
13
|
+
- @backstage/plugin-permission-common@0.9.0-next.0
|
|
14
|
+
- @backstage/plugin-permission-node@0.10.0-next.1
|
|
15
|
+
- @backstage/catalog-client@1.10.0-next.0
|
|
16
|
+
- @backstage/catalog-model@1.7.3
|
|
17
|
+
- @backstage/errors@1.2.7
|
|
18
|
+
- @backstage/types@1.2.1
|
|
19
|
+
- @backstage/plugin-catalog-common@1.1.4-next.0
|
|
20
|
+
|
|
21
|
+
## 1.17.0-next.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- 1a003ff: Add `getLocations` method to `CatalogApi` and `CatalogClient`. This method calls the [`GET /locations`](https://backstage.io/docs/features/software-catalog/software-catalog-api/#get-locations) endpoint from the catalog backend.
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies
|
|
30
|
+
- @backstage/catalog-client@1.10.0-next.0
|
|
31
|
+
- @backstage/backend-plugin-api@1.3.1-next.0
|
|
32
|
+
- @backstage/plugin-permission-node@0.9.2-next.0
|
|
33
|
+
- @backstage/catalog-model@1.7.3
|
|
34
|
+
- @backstage/errors@1.2.7
|
|
35
|
+
- @backstage/types@1.2.1
|
|
36
|
+
- @backstage/plugin-catalog-common@1.1.3
|
|
37
|
+
- @backstage/plugin-permission-common@0.8.4
|
|
38
|
+
|
|
3
39
|
## 1.16.3
|
|
4
40
|
|
|
5
41
|
### Patch Changes
|
|
@@ -61,6 +61,12 @@ class DefaultCatalogService {
|
|
|
61
61
|
await this.#getOptions(options)
|
|
62
62
|
);
|
|
63
63
|
}
|
|
64
|
+
async getLocations(request, options) {
|
|
65
|
+
return this.#catalogApi.getLocations(
|
|
66
|
+
request,
|
|
67
|
+
await this.#getOptions(options)
|
|
68
|
+
);
|
|
69
|
+
}
|
|
64
70
|
async getLocationById(id, options) {
|
|
65
71
|
return this.#catalogApi.getLocationById(
|
|
66
72
|
id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalogService.cjs.js","sources":["../src/catalogService.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createServiceFactory,\n createServiceRef,\n coreServices,\n BackstageCredentials,\n AuthService,\n} from '@backstage/backend-plugin-api';\nimport {\n AddLocationRequest,\n AddLocationResponse,\n CatalogApi,\n CatalogClient,\n CatalogRequestOptions,\n GetEntitiesByRefsRequest,\n GetEntitiesByRefsResponse,\n GetEntitiesRequest,\n GetEntitiesResponse,\n GetEntityAncestorsRequest,\n GetEntityAncestorsResponse,\n GetEntityFacetsRequest,\n GetEntityFacetsResponse,\n Location,\n QueryEntitiesRequest,\n QueryEntitiesResponse,\n ValidateEntityResponse,\n} from '@backstage/catalog-client';\nimport { CompoundEntityRef, Entity } from '@backstage/catalog-model';\n\n/**\n * @public\n */\nexport interface CatalogServiceRequestOptions {\n credentials: BackstageCredentials;\n}\n\n/**\n * A version of the {@link @backstage/catalog-client#CatalogApi | CatalogApi} that\n * requires backend credentials to be passed instead of a token.\n *\n * @public\n */\nexport interface CatalogService {\n getEntities(\n request: GetEntitiesRequest | undefined,\n options: CatalogServiceRequestOptions,\n ): Promise<GetEntitiesResponse>;\n\n getEntitiesByRefs(\n request: GetEntitiesByRefsRequest,\n options: CatalogServiceRequestOptions,\n ): Promise<GetEntitiesByRefsResponse>;\n\n queryEntities(\n request: QueryEntitiesRequest | undefined,\n options: CatalogServiceRequestOptions,\n ): Promise<QueryEntitiesResponse>;\n\n getEntityAncestors(\n request: GetEntityAncestorsRequest,\n options: CatalogServiceRequestOptions,\n ): Promise<GetEntityAncestorsResponse>;\n\n getEntityByRef(\n entityRef: string | CompoundEntityRef,\n options: CatalogServiceRequestOptions,\n ): Promise<Entity | undefined>;\n\n removeEntityByUid(\n uid: string,\n options: CatalogServiceRequestOptions,\n ): Promise<void>;\n\n refreshEntity(\n entityRef: string,\n options: CatalogServiceRequestOptions,\n ): Promise<void>;\n\n getEntityFacets(\n request: GetEntityFacetsRequest,\n options: CatalogServiceRequestOptions,\n ): Promise<GetEntityFacetsResponse>;\n\n getLocationById(\n id: string,\n options: CatalogServiceRequestOptions,\n ): Promise<Location | undefined>;\n\n getLocationByRef(\n locationRef: string,\n options: CatalogServiceRequestOptions,\n ): Promise<Location | undefined>;\n\n addLocation(\n location: AddLocationRequest,\n options: CatalogServiceRequestOptions,\n ): Promise<AddLocationResponse>;\n\n removeLocationById(\n id: string,\n options: CatalogServiceRequestOptions,\n ): Promise<void>;\n\n getLocationByEntity(\n entityRef: string | CompoundEntityRef,\n options: CatalogServiceRequestOptions,\n ): Promise<Location | undefined>;\n\n validateEntity(\n entity: Entity,\n locationRef: string,\n options: CatalogServiceRequestOptions,\n ): Promise<ValidateEntityResponse>;\n}\n\nclass DefaultCatalogService implements CatalogService {\n readonly #auth: AuthService;\n readonly #catalogApi: CatalogApi;\n\n constructor({\n catalogApi,\n auth,\n }: {\n catalogApi: CatalogApi;\n auth: AuthService;\n }) {\n this.#catalogApi = catalogApi;\n this.#auth = auth;\n }\n\n async getEntities(\n request: GetEntitiesRequest | undefined,\n options: CatalogServiceRequestOptions,\n ): Promise<GetEntitiesResponse> {\n return this.#catalogApi.getEntities(\n request,\n await this.#getOptions(options),\n );\n }\n\n async getEntitiesByRefs(\n request: GetEntitiesByRefsRequest,\n options: CatalogServiceRequestOptions,\n ): Promise<GetEntitiesByRefsResponse> {\n return this.#catalogApi.getEntitiesByRefs(\n request,\n await this.#getOptions(options),\n );\n }\n\n async queryEntities(\n request: QueryEntitiesRequest | undefined,\n options: CatalogServiceRequestOptions,\n ): Promise<QueryEntitiesResponse> {\n return this.#catalogApi.queryEntities(\n request,\n await this.#getOptions(options),\n );\n }\n\n async getEntityAncestors(\n request: GetEntityAncestorsRequest,\n options: CatalogServiceRequestOptions,\n ): Promise<GetEntityAncestorsResponse> {\n return this.#catalogApi.getEntityAncestors(\n request,\n await this.#getOptions(options),\n );\n }\n\n async getEntityByRef(\n entityRef: string | CompoundEntityRef,\n options: CatalogServiceRequestOptions,\n ): Promise<Entity | undefined> {\n return this.#catalogApi.getEntityByRef(\n entityRef,\n await this.#getOptions(options),\n );\n }\n\n async removeEntityByUid(\n uid: string,\n options: CatalogServiceRequestOptions,\n ): Promise<void> {\n return this.#catalogApi.removeEntityByUid(\n uid,\n await this.#getOptions(options),\n );\n }\n\n async refreshEntity(\n entityRef: string,\n options: CatalogServiceRequestOptions,\n ): Promise<void> {\n return this.#catalogApi.refreshEntity(\n entityRef,\n await this.#getOptions(options),\n );\n }\n\n async getEntityFacets(\n request: GetEntityFacetsRequest,\n options: CatalogServiceRequestOptions,\n ): Promise<GetEntityFacetsResponse> {\n return this.#catalogApi.getEntityFacets(\n request,\n await this.#getOptions(options),\n );\n }\n\n async getLocationById(\n id: string,\n options: CatalogServiceRequestOptions,\n ): Promise<Location | undefined> {\n return this.#catalogApi.getLocationById(\n id,\n await this.#getOptions(options),\n );\n }\n\n async getLocationByRef(\n locationRef: string,\n options: CatalogServiceRequestOptions,\n ): Promise<Location | undefined> {\n return this.#catalogApi.getLocationByRef(\n locationRef,\n await this.#getOptions(options),\n );\n }\n\n async addLocation(\n location: AddLocationRequest,\n options: CatalogServiceRequestOptions,\n ): Promise<AddLocationResponse> {\n return this.#catalogApi.addLocation(\n location,\n await this.#getOptions(options),\n );\n }\n\n async removeLocationById(\n id: string,\n options: CatalogServiceRequestOptions,\n ): Promise<void> {\n return this.#catalogApi.removeLocationById(\n id,\n await this.#getOptions(options),\n );\n }\n\n async getLocationByEntity(\n entityRef: string | CompoundEntityRef,\n options: CatalogServiceRequestOptions,\n ): Promise<Location | undefined> {\n return this.#catalogApi.getLocationByEntity(\n entityRef,\n await this.#getOptions(options),\n );\n }\n\n async validateEntity(\n entity: Entity,\n locationRef: string,\n options: CatalogServiceRequestOptions,\n ): Promise<ValidateEntityResponse> {\n return this.#catalogApi.validateEntity(\n entity,\n locationRef,\n await this.#getOptions(options),\n );\n }\n\n async #getOptions(\n options: CatalogServiceRequestOptions,\n ): Promise<CatalogRequestOptions> {\n return this.#auth.getPluginRequestToken({\n onBehalfOf: options.credentials,\n targetPluginId: 'catalog',\n });\n }\n}\n\n/**\n * The catalogService provides the catalog API.\n *\n * @public\n */\nexport const catalogServiceRef = createServiceRef<CatalogService>({\n id: 'catalog-client',\n defaultFactory: async service =>\n createServiceFactory({\n service,\n deps: {\n auth: coreServices.auth,\n discoveryApi: coreServices.discovery,\n },\n async factory({ auth, discoveryApi }) {\n return new DefaultCatalogService({\n auth,\n catalogApi: new CatalogClient({ discoveryApi }),\n });\n },\n }),\n});\n"],"names":["createServiceRef","createServiceFactory","coreServices","CatalogClient"],"mappings":";;;;;AAkIA,MAAM,qBAAgD,CAAA;AAAA,EAC3C,KAAA;AAAA,EACA,WAAA;AAAA,EAET,WAAY,CAAA;AAAA,IACV,UAAA;AAAA,IACA;AAAA,GAIC,EAAA;AACD,IAAA,IAAA,CAAK,WAAc,GAAA,UAAA;AACnB,IAAA,IAAA,CAAK,KAAQ,GAAA,IAAA;AAAA;AACf,EAEA,MAAM,WACJ,CAAA,OAAA,EACA,OAC8B,EAAA;AAC9B,IAAA,OAAO,KAAK,WAAY,CAAA,WAAA;AAAA,MACtB,OAAA;AAAA,MACA,MAAM,IAAK,CAAA,WAAA,CAAY,OAAO;AAAA,KAChC;AAAA;AACF,EAEA,MAAM,iBACJ,CAAA,OAAA,EACA,OACoC,EAAA;AACpC,IAAA,OAAO,KAAK,WAAY,CAAA,iBAAA;AAAA,MACtB,OAAA;AAAA,MACA,MAAM,IAAK,CAAA,WAAA,CAAY,OAAO;AAAA,KAChC;AAAA;AACF,EAEA,MAAM,aACJ,CAAA,OAAA,EACA,OACgC,EAAA;AAChC,IAAA,OAAO,KAAK,WAAY,CAAA,aAAA;AAAA,MACtB,OAAA;AAAA,MACA,MAAM,IAAK,CAAA,WAAA,CAAY,OAAO;AAAA,KAChC;AAAA;AACF,EAEA,MAAM,kBACJ,CAAA,OAAA,EACA,OACqC,EAAA;AACrC,IAAA,OAAO,KAAK,WAAY,CAAA,kBAAA;AAAA,MACtB,OAAA;AAAA,MACA,MAAM,IAAK,CAAA,WAAA,CAAY,OAAO;AAAA,KAChC;AAAA;AACF,EAEA,MAAM,cACJ,CAAA,SAAA,EACA,OAC6B,EAAA;AAC7B,IAAA,OAAO,K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\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createServiceFactory,\n createServiceRef,\n coreServices,\n BackstageCredentials,\n AuthService,\n} from '@backstage/backend-plugin-api';\nimport {\n AddLocationRequest,\n AddLocationResponse,\n CatalogApi,\n CatalogClient,\n CatalogRequestOptions,\n GetEntitiesByRefsRequest,\n GetEntitiesByRefsResponse,\n GetEntitiesRequest,\n GetEntitiesResponse,\n GetEntityAncestorsRequest,\n GetEntityAncestorsResponse,\n GetEntityFacetsRequest,\n GetEntityFacetsResponse,\n GetLocationsResponse,\n Location,\n QueryEntitiesRequest,\n QueryEntitiesResponse,\n ValidateEntityResponse,\n} from '@backstage/catalog-client';\nimport { CompoundEntityRef, Entity } from '@backstage/catalog-model';\n\n/**\n * @public\n */\nexport interface CatalogServiceRequestOptions {\n credentials: BackstageCredentials;\n}\n\n/**\n * A version of the {@link @backstage/catalog-client#CatalogApi | CatalogApi} that\n * requires backend credentials to be passed instead of a token.\n *\n * @public\n */\nexport interface CatalogService {\n getEntities(\n request: GetEntitiesRequest | undefined,\n options: CatalogServiceRequestOptions,\n ): Promise<GetEntitiesResponse>;\n\n getEntitiesByRefs(\n request: GetEntitiesByRefsRequest,\n options: CatalogServiceRequestOptions,\n ): Promise<GetEntitiesByRefsResponse>;\n\n queryEntities(\n request: QueryEntitiesRequest | undefined,\n options: CatalogServiceRequestOptions,\n ): Promise<QueryEntitiesResponse>;\n\n getEntityAncestors(\n request: GetEntityAncestorsRequest,\n options: CatalogServiceRequestOptions,\n ): Promise<GetEntityAncestorsResponse>;\n\n getEntityByRef(\n entityRef: string | CompoundEntityRef,\n options: CatalogServiceRequestOptions,\n ): Promise<Entity | undefined>;\n\n removeEntityByUid(\n uid: string,\n options: CatalogServiceRequestOptions,\n ): Promise<void>;\n\n refreshEntity(\n entityRef: string,\n options: CatalogServiceRequestOptions,\n ): Promise<void>;\n\n getEntityFacets(\n request: GetEntityFacetsRequest,\n options: CatalogServiceRequestOptions,\n ): Promise<GetEntityFacetsResponse>;\n\n getLocations(\n request: {} | undefined,\n options: CatalogServiceRequestOptions,\n ): Promise<GetLocationsResponse>;\n\n getLocationById(\n id: string,\n options: CatalogServiceRequestOptions,\n ): Promise<Location | undefined>;\n\n getLocationByRef(\n locationRef: string,\n options: CatalogServiceRequestOptions,\n ): Promise<Location | undefined>;\n\n addLocation(\n location: AddLocationRequest,\n options: CatalogServiceRequestOptions,\n ): Promise<AddLocationResponse>;\n\n removeLocationById(\n id: string,\n options: CatalogServiceRequestOptions,\n ): Promise<void>;\n\n getLocationByEntity(\n entityRef: string | CompoundEntityRef,\n options: CatalogServiceRequestOptions,\n ): Promise<Location | undefined>;\n\n validateEntity(\n entity: Entity,\n locationRef: string,\n options: CatalogServiceRequestOptions,\n ): Promise<ValidateEntityResponse>;\n}\n\nclass DefaultCatalogService implements CatalogService {\n readonly #auth: AuthService;\n readonly #catalogApi: CatalogApi;\n\n constructor({\n catalogApi,\n auth,\n }: {\n catalogApi: CatalogApi;\n auth: AuthService;\n }) {\n this.#catalogApi = catalogApi;\n this.#auth = auth;\n }\n\n async getEntities(\n request: GetEntitiesRequest | undefined,\n options: CatalogServiceRequestOptions,\n ): Promise<GetEntitiesResponse> {\n return this.#catalogApi.getEntities(\n request,\n await this.#getOptions(options),\n );\n }\n\n async getEntitiesByRefs(\n request: GetEntitiesByRefsRequest,\n options: CatalogServiceRequestOptions,\n ): Promise<GetEntitiesByRefsResponse> {\n return this.#catalogApi.getEntitiesByRefs(\n request,\n await this.#getOptions(options),\n );\n }\n\n async queryEntities(\n request: QueryEntitiesRequest | undefined,\n options: CatalogServiceRequestOptions,\n ): Promise<QueryEntitiesResponse> {\n return this.#catalogApi.queryEntities(\n request,\n await this.#getOptions(options),\n );\n }\n\n async getEntityAncestors(\n request: GetEntityAncestorsRequest,\n options: CatalogServiceRequestOptions,\n ): Promise<GetEntityAncestorsResponse> {\n return this.#catalogApi.getEntityAncestors(\n request,\n await this.#getOptions(options),\n );\n }\n\n async getEntityByRef(\n entityRef: string | CompoundEntityRef,\n options: CatalogServiceRequestOptions,\n ): Promise<Entity | undefined> {\n return this.#catalogApi.getEntityByRef(\n entityRef,\n await this.#getOptions(options),\n );\n }\n\n async removeEntityByUid(\n uid: string,\n options: CatalogServiceRequestOptions,\n ): Promise<void> {\n return this.#catalogApi.removeEntityByUid(\n uid,\n await this.#getOptions(options),\n );\n }\n\n async refreshEntity(\n entityRef: string,\n options: CatalogServiceRequestOptions,\n ): Promise<void> {\n return this.#catalogApi.refreshEntity(\n entityRef,\n await this.#getOptions(options),\n );\n }\n\n async getEntityFacets(\n request: GetEntityFacetsRequest,\n options: CatalogServiceRequestOptions,\n ): Promise<GetEntityFacetsResponse> {\n return this.#catalogApi.getEntityFacets(\n request,\n await this.#getOptions(options),\n );\n }\n\n async getLocations(\n request: {} | undefined,\n options: CatalogServiceRequestOptions,\n ): Promise<GetLocationsResponse> {\n return this.#catalogApi.getLocations(\n request,\n await this.#getOptions(options),\n );\n }\n\n async getLocationById(\n id: string,\n options: CatalogServiceRequestOptions,\n ): Promise<Location | undefined> {\n return this.#catalogApi.getLocationById(\n id,\n await this.#getOptions(options),\n );\n }\n\n async getLocationByRef(\n locationRef: string,\n options: CatalogServiceRequestOptions,\n ): Promise<Location | undefined> {\n return this.#catalogApi.getLocationByRef(\n locationRef,\n await this.#getOptions(options),\n );\n }\n\n async addLocation(\n location: AddLocationRequest,\n options: CatalogServiceRequestOptions,\n ): Promise<AddLocationResponse> {\n return this.#catalogApi.addLocation(\n location,\n await this.#getOptions(options),\n );\n }\n\n async removeLocationById(\n id: string,\n options: CatalogServiceRequestOptions,\n ): Promise<void> {\n return this.#catalogApi.removeLocationById(\n id,\n await this.#getOptions(options),\n );\n }\n\n async getLocationByEntity(\n entityRef: string | CompoundEntityRef,\n options: CatalogServiceRequestOptions,\n ): Promise<Location | undefined> {\n return this.#catalogApi.getLocationByEntity(\n entityRef,\n await this.#getOptions(options),\n );\n }\n\n async validateEntity(\n entity: Entity,\n locationRef: string,\n options: CatalogServiceRequestOptions,\n ): Promise<ValidateEntityResponse> {\n return this.#catalogApi.validateEntity(\n entity,\n locationRef,\n await this.#getOptions(options),\n );\n }\n\n async #getOptions(\n options: CatalogServiceRequestOptions,\n ): Promise<CatalogRequestOptions> {\n return this.#auth.getPluginRequestToken({\n onBehalfOf: options.credentials,\n targetPluginId: 'catalog',\n });\n }\n}\n\n/**\n * The catalogService provides the catalog API.\n *\n * @public\n */\nexport const catalogServiceRef = createServiceRef<CatalogService>({\n id: 'catalog-client',\n defaultFactory: async service =>\n createServiceFactory({\n service,\n deps: {\n auth: coreServices.auth,\n discoveryApi: coreServices.discovery,\n },\n async factory({ auth, discoveryApi }) {\n return new DefaultCatalogService({\n auth,\n catalogApi: new CatalogClient({ discoveryApi }),\n });\n },\n }),\n});\n"],"names":["createServiceRef","createServiceFactory","coreServices","CatalogClient"],"mappings":";;;;;AAwIA,MAAM,qBAAgD,CAAA;AAAA,EAC3C,KAAA;AAAA,EACA,WAAA;AAAA,EAET,WAAY,CAAA;AAAA,IACV,UAAA;AAAA,IACA;AAAA,GAIC,EAAA;AACD,IAAA,IAAA,CAAK,WAAc,GAAA,UAAA;AACnB,IAAA,IAAA,CAAK,KAAQ,GAAA,IAAA;AAAA;AACf,EAEA,MAAM,WACJ,CAAA,OAAA,EACA,OAC8B,EAAA;AAC9B,IAAA,OAAO,KAAK,WAAY,CAAA,WAAA;AAAA,MACtB,OAAA;AAAA,MACA,MAAM,IAAK,CAAA,WAAA,CAAY,OAAO;AAAA,KAChC;AAAA;AACF,EAEA,MAAM,iBACJ,CAA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AA,CAAY,OAAO;AAAA,KAChC;AAAA;AACF,EAEA,MAAM,YACJ,OACgC,EAAA;AAChC,IAAO,OAAA,IAAA,CAAK,MAAM,qBAAsB,CAAA;AAAA,MACtC,YAAY,OAAQ,CAAA,WAAA;AAAA,MACpB,cAAgB,EAAA;AAAA,KACjB,CAAA;AAAA;AAEL;AAOO,MAAM,oBAAoBA,iCAAiC,CAAA;AAAA,EAChE,EAAI,EAAA,gBAAA;AAAA,EACJ,cAAA,EAAgB,OAAM,OAAA,KACpBC,qCAAqB,CAAA;AAAA,IACnB,OAAA;AAAA,IACA,IAAM,EAAA;AAAA,MACJ,MAAMC,6BAAa,CAAA,IAAA;AAAA,MACnB,cAAcA,6BAAa,CAAA;AAAA,KAC7B;AAAA,IACA,MAAM,OAAA,CAAQ,EAAE,IAAA,EAAM,cAAgB,EAAA;AACpC,MAAA,OAAO,IAAI,qBAAsB,CAAA;AAAA,QAC/B,IAAA;AAAA,QACA,UAAY,EAAA,IAAIC,2BAAc,CAAA,EAAE,cAAc;AAAA,OAC/C,CAAA;AAAA;AACH,GACD;AACL,CAAC;;;;"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var processingResult = require('./api/processingResult.cjs.js');
|
|
4
4
|
var conversion = require('./conversion.cjs.js');
|
|
5
|
+
var parse = require('./processing/parse.cjs.js');
|
|
5
6
|
var catalogService = require('./catalogService.cjs.js');
|
|
6
7
|
|
|
7
8
|
|
|
@@ -9,5 +10,6 @@ var catalogService = require('./catalogService.cjs.js');
|
|
|
9
10
|
exports.processingResult = processingResult.processingResult;
|
|
10
11
|
exports.locationSpecToLocationEntity = conversion.locationSpecToLocationEntity;
|
|
11
12
|
exports.locationSpecToMetadataName = conversion.locationSpecToMetadataName;
|
|
13
|
+
exports.parseEntityYaml = parse.parseEntityYaml;
|
|
12
14
|
exports.catalogServiceRef = catalogService.catalogServiceRef;
|
|
13
15
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { JsonValue } from '@backstage/types';
|
|
|
3
3
|
import { LocationSpec as LocationSpec$1, AnalyzeLocationRequest, AnalyzeLocationResponse, AnalyzeLocationExistingEntity } from '@backstage/plugin-catalog-common';
|
|
4
4
|
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
5
5
|
import { BackstageCredentials } from '@backstage/backend-plugin-api';
|
|
6
|
-
import { GetEntitiesRequest, GetEntitiesResponse, GetEntitiesByRefsRequest, GetEntitiesByRefsResponse, QueryEntitiesRequest, QueryEntitiesResponse, GetEntityAncestorsRequest, GetEntityAncestorsResponse, GetEntityFacetsRequest, GetEntityFacetsResponse, Location, AddLocationRequest, AddLocationResponse, ValidateEntityResponse } from '@backstage/catalog-client';
|
|
6
|
+
import { GetEntitiesRequest, GetEntitiesResponse, GetEntitiesByRefsRequest, GetEntitiesByRefsResponse, QueryEntitiesRequest, QueryEntitiesResponse, GetEntityAncestorsRequest, GetEntityAncestorsResponse, GetEntityFacetsRequest, GetEntityFacetsResponse, GetLocationsResponse, Location, AddLocationRequest, AddLocationResponse, ValidateEntityResponse } from '@backstage/catalog-client';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Holds the entity location information.
|
|
@@ -298,6 +298,24 @@ type ScmLocationAnalyzer = {
|
|
|
298
298
|
}>;
|
|
299
299
|
};
|
|
300
300
|
|
|
301
|
+
/**
|
|
302
|
+
* A helper function that parses a YAML file, properly handling multiple
|
|
303
|
+
* documents in a single file.
|
|
304
|
+
*
|
|
305
|
+
* @public
|
|
306
|
+
* @remarks
|
|
307
|
+
*
|
|
308
|
+
* Each document is expected to be a valid Backstage entity. Each item in the
|
|
309
|
+
* iterable is in the form of an entity result if the document seemed like a
|
|
310
|
+
* valid object, or in the form of an error result if it seemed incorrect. This
|
|
311
|
+
* way, you can choose to retain a partial result if you want.
|
|
312
|
+
*
|
|
313
|
+
* Note that this function does NOT perform any validation of the entities. No
|
|
314
|
+
* assumptions whatsoever can be made on the emnitted entities except that they
|
|
315
|
+
* are valid JSON objects.
|
|
316
|
+
*/
|
|
317
|
+
declare function parseEntityYaml(data: string | Buffer, location: LocationSpec$1): Iterable<CatalogProcessorResult>;
|
|
318
|
+
|
|
301
319
|
/**
|
|
302
320
|
* A 'full' mutation replaces all existing entities created by this entity provider with new ones.
|
|
303
321
|
* A 'delta' mutation can both add and remove entities provided by this provider. Previously provided
|
|
@@ -397,6 +415,7 @@ interface CatalogService {
|
|
|
397
415
|
removeEntityByUid(uid: string, options: CatalogServiceRequestOptions): Promise<void>;
|
|
398
416
|
refreshEntity(entityRef: string, options: CatalogServiceRequestOptions): Promise<void>;
|
|
399
417
|
getEntityFacets(request: GetEntityFacetsRequest, options: CatalogServiceRequestOptions): Promise<GetEntityFacetsResponse>;
|
|
418
|
+
getLocations(request: {} | undefined, options: CatalogServiceRequestOptions): Promise<GetLocationsResponse>;
|
|
400
419
|
getLocationById(id: string, options: CatalogServiceRequestOptions): Promise<Location | undefined>;
|
|
401
420
|
getLocationByRef(locationRef: string, options: CatalogServiceRequestOptions): Promise<Location | undefined>;
|
|
402
421
|
addLocation(location: AddLocationRequest, options: CatalogServiceRequestOptions): Promise<AddLocationResponse>;
|
|
@@ -411,4 +430,4 @@ interface CatalogService {
|
|
|
411
430
|
*/
|
|
412
431
|
declare const catalogServiceRef: _backstage_backend_plugin_api.ServiceRef<CatalogService, "plugin", "singleton">;
|
|
413
432
|
|
|
414
|
-
export { type AnalyzeOptions, type CatalogProcessor, type CatalogProcessorCache, type CatalogProcessorEmit, type CatalogProcessorEntityResult, type CatalogProcessorErrorResult, type CatalogProcessorLocationResult, type CatalogProcessorParser, type CatalogProcessorRefreshKeysResult, type CatalogProcessorRelationResult, type CatalogProcessorResult, type CatalogService, type CatalogServiceRequestOptions, type DeferredEntity, type EntitiesSearchFilter, type EntityFilter, type EntityProvider, type EntityProviderConnection, type EntityProviderMutation, type EntityProviderRefreshOptions, type EntityRelationSpec, type LocationAnalyzer, type LocationSpec, type PlaceholderResolver, type PlaceholderResolverParams, type PlaceholderResolverRead, type PlaceholderResolverResolveUrl, type ScmLocationAnalyzer, catalogServiceRef, locationSpecToLocationEntity, locationSpecToMetadataName, processingResult };
|
|
433
|
+
export { type AnalyzeOptions, type CatalogProcessor, type CatalogProcessorCache, type CatalogProcessorEmit, type CatalogProcessorEntityResult, type CatalogProcessorErrorResult, type CatalogProcessorLocationResult, type CatalogProcessorParser, type CatalogProcessorRefreshKeysResult, type CatalogProcessorRelationResult, type CatalogProcessorResult, type CatalogService, type CatalogServiceRequestOptions, type DeferredEntity, type EntitiesSearchFilter, type EntityFilter, type EntityProvider, type EntityProviderConnection, type EntityProviderMutation, type EntityProviderRefreshOptions, type EntityRelationSpec, type LocationAnalyzer, type LocationSpec, type PlaceholderResolver, type PlaceholderResolverParams, type PlaceholderResolverRead, type PlaceholderResolverResolveUrl, type ScmLocationAnalyzer, catalogServiceRef, locationSpecToLocationEntity, locationSpecToMetadataName, parseEntityYaml, processingResult };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var catalogModel = require('@backstage/catalog-model');
|
|
4
|
+
var lodash = require('lodash');
|
|
5
|
+
var yaml = require('yaml');
|
|
6
|
+
var processingResult = require('../api/processingResult.cjs.js');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var lodash__default = /*#__PURE__*/_interopDefaultCompat(lodash);
|
|
11
|
+
var yaml__default = /*#__PURE__*/_interopDefaultCompat(yaml);
|
|
12
|
+
|
|
13
|
+
function* parseEntityYaml(data, location) {
|
|
14
|
+
let documents;
|
|
15
|
+
try {
|
|
16
|
+
documents = yaml__default.default.parseAllDocuments(
|
|
17
|
+
typeof data === "string" ? data : data.toString("utf8")
|
|
18
|
+
).filter((d) => d);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
const loc = catalogModel.stringifyLocationRef(location);
|
|
21
|
+
const message = `Failed to parse YAML at ${loc}, ${e}`;
|
|
22
|
+
yield processingResult.processingResult.generalError(location, message);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
for (const document of documents) {
|
|
26
|
+
if (document.errors?.length) {
|
|
27
|
+
const loc = catalogModel.stringifyLocationRef(location);
|
|
28
|
+
const message = `YAML error at ${loc}, ${document.errors[0]}`;
|
|
29
|
+
yield processingResult.processingResult.generalError(location, message);
|
|
30
|
+
} else {
|
|
31
|
+
const json = document.toJSON();
|
|
32
|
+
if (lodash__default.default.isPlainObject(json)) {
|
|
33
|
+
yield processingResult.processingResult.entity(location, json);
|
|
34
|
+
} else if (json === null) ; else {
|
|
35
|
+
const message = `Expected object at root, got ${typeof json}`;
|
|
36
|
+
yield processingResult.processingResult.generalError(location, message);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.parseEntityYaml = parseEntityYaml;
|
|
43
|
+
//# sourceMappingURL=parse.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.cjs.js","sources":["../../src/processing/parse.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Entity, stringifyLocationRef } from '@backstage/catalog-model';\nimport lodash from 'lodash';\nimport yaml from 'yaml';\nimport { LocationSpec } from '@backstage/plugin-catalog-common';\nimport { CatalogProcessorResult } from '../api/processor';\nimport { processingResult } from '../api/processingResult';\n\n/**\n * A helper function that parses a YAML file, properly handling multiple\n * documents in a single file.\n *\n * @public\n * @remarks\n *\n * Each document is expected to be a valid Backstage entity. Each item in the\n * iterable is in the form of an entity result if the document seemed like a\n * valid object, or in the form of an error result if it seemed incorrect. This\n * way, you can choose to retain a partial result if you want.\n *\n * Note that this function does NOT perform any validation of the entities. No\n * assumptions whatsoever can be made on the emnitted entities except that they\n * are valid JSON objects.\n */\nexport function* parseEntityYaml(\n data: string | Buffer,\n location: LocationSpec,\n): Iterable<CatalogProcessorResult> {\n let documents: yaml.Document.Parsed[];\n try {\n documents = yaml\n .parseAllDocuments(\n typeof data === 'string' ? data : data.toString('utf8'),\n )\n .filter(d => d);\n } catch (e) {\n const loc = stringifyLocationRef(location);\n const message = `Failed to parse YAML at ${loc}, ${e}`;\n yield processingResult.generalError(location, message);\n return;\n }\n\n for (const document of documents) {\n if (document.errors?.length) {\n const loc = stringifyLocationRef(location);\n const message = `YAML error at ${loc}, ${document.errors[0]}`;\n yield processingResult.generalError(location, message);\n } else {\n const json = document.toJSON();\n if (lodash.isPlainObject(json)) {\n yield processingResult.entity(location, json as Entity);\n } else if (json === null) {\n // Ignore null values, these happen if there is an empty document in the\n // YAML file, for example if --- is added to the end of the file.\n } else {\n const message = `Expected object at root, got ${typeof json}`;\n yield processingResult.generalError(location, message);\n }\n }\n }\n}\n"],"names":["yaml","stringifyLocationRef","processingResult","lodash"],"mappings":";;;;;;;;;;;;AAuCiB,UAAA,eAAA,CACf,MACA,QACkC,EAAA;AAClC,EAAI,IAAA,SAAA;AACJ,EAAI,IAAA;AACF,IAAA,SAAA,GAAYA,qBACT,CAAA,iBAAA;AAAA,MACC,OAAO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["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ServiceFactory,\n ServiceRef,\n createServiceFactory,\n} from '@backstage/backend-plugin-api';\nimport { InMemoryCatalogClient } from '@backstage/catalog-client/testUtils';\nimport { Entity } from '@backstage/catalog-model';\nimport { catalogServiceRef } from '@backstage/plugin-catalog-node';\n// eslint-disable-next-line @backstage/no-undeclared-imports\nimport { ServiceMock } from '@backstage/backend-test-utils';\nimport { CatalogServiceMock } from './types';\n\n/** @internal */\nfunction simpleMock<TService>(\n ref: ServiceRef<TService, any>,\n mockFactory: () => jest.Mocked<TService>,\n): (partialImpl?: Partial<TService>) => ServiceMock<TService> {\n return partialImpl => {\n const mock = mockFactory();\n if (partialImpl) {\n for (const [key, impl] of Object.entries(partialImpl)) {\n if (typeof impl === 'function') {\n (mock as any)[key].mockImplementation(impl);\n } else {\n (mock as any)[key] = impl;\n }\n }\n }\n return Object.assign(mock, {\n factory: createServiceFactory({\n service: ref,\n deps: {},\n factory: () => mock,\n }),\n }) as ServiceMock<TService>;\n };\n}\n\n/**\n * Creates a fake catalog client that handles entities in memory storage. Note\n * that this client may be severely limited in functionality, and advanced\n * functions may not be available at all.\n *\n * @public\n */\nexport function catalogServiceMock(options?: {\n entities?: Entity[];\n}): CatalogServiceMock {\n return new InMemoryCatalogClient(options);\n}\n\n/**\n * A collection of mock functionality for the catalog service.\n *\n * @public\n */\nexport namespace catalogServiceMock {\n /**\n * Creates a fake catalog client that handles entities in memory storage. Note\n * that this client may be severely limited in functionality, and advanced\n * functions may not be available at all.\n */\n export const factory = (options?: { entities?: Entity[] }) =>\n createServiceFactory({\n service: catalogServiceRef,\n deps: {},\n factory: () => new InMemoryCatalogClient(options),\n }) as ServiceFactory<CatalogServiceMock, 'plugin', 'singleton'>;\n /**\n * Creates a catalog client whose methods are mock functions, possibly with\n * some of them overloaded by the caller.\n */\n export const mock = simpleMock<CatalogServiceMock>(catalogServiceRef, () => ({\n getEntities: jest.fn(),\n getEntitiesByRefs: jest.fn(),\n queryEntities: jest.fn(),\n getEntityAncestors: jest.fn(),\n getEntityByRef: jest.fn(),\n removeEntityByUid: jest.fn(),\n refreshEntity: jest.fn(),\n getEntityFacets: jest.fn(),\n getLocationById: jest.fn(),\n getLocationByRef: jest.fn(),\n addLocation: jest.fn(),\n removeLocationById: jest.fn(),\n getLocationByEntity: jest.fn(),\n validateEntity: jest.fn(),\n }));\n}\n"],"names":["createServiceFactory","InMemoryCatalogClient","catalogServiceMock","catalogServiceRef"],"mappings":";;;;;;AA6BA,SAAS,UAAA,CACP,KACA,WAC4D,EAAA;AAC5D,EAAA,OAAO,CAAe,WAAA,KAAA;AACpB,IAAA,MAAM,OAAO,WAAY,EAAA;AACzB,IAAA,IAAI,WAAa,EAAA;AACf,MAAA,KAAA,MAAW,CAAC,GAAK,EAAA,IAAI,KAAK,MAAO,CAAA,OAAA,CAAQ,WAAW,CAAG,EAAA;AACrD,QAAI,IAAA,OAAO,SAAS,UAAY,EAAA;AAC9B,UAAC,IAAa,CAAA,GAAG,CAAE,CAAA,kBAAA,CAAmB,IAAI,CAAA;AAAA,SACrC,MAAA;AACL,UAAC,IAAA,CAAa,GAAG,CAAI,GAAA,IAAA;AAAA;AACvB;AACF;AAEF,IAAO,OAAA,MAAA,CAAO,OAAO,IAAM,EAAA;AAAA,MACzB,SAASA,qCAAqB,CAAA;AAAA,QAC5B,OAAS,EAAA,GAAA;AAAA,QACT,MAAM,EAAC;AAAA,QACP,SAAS,MAAM;AAAA,OAChB;AAAA,KACF,CAAA;AAAA,GACH;AACF;AASO,SAAS,mBAAmB,OAEZ,EAAA;AACrB,EAAO,OAAA,IAAIC,gCAAsB,OAAO,CAAA;AAC1C;AAAA,CAOO,CAAUC,mBAAV,KAAA;AAME,EAAMA,mBAAA,CAAA,OAAA,GAAU,CAAC,OAAA,KACtBF,qCAAqB,CAAA;AAAA,IACnB,OAAS,EAAAG,mCAAA;AAAA,IACT,MAAM,EAAC;AAAA,IACP,OAAS,EAAA,MAAM,IAAIF,+BAAA,CAAsB,OAAO;AAAA,GACjD,CAAA;AAKI,EAAMC,mBAAA,CAAA,IAAA,GAAO,UAA+B,CAAAC,mCAAA,EAAmB,OAAO;AAAA,IAC3E,WAAA,EAAa,KAAK,EAAG,EAAA;AAAA,IACrB,iBAAA,EAAmB,KAAK,EAAG,EAAA;AAAA,IAC3B,aAAA,EAAe,KAAK,EAAG,EAAA;AAAA,IACvB,kBAAA,EAAoB,KAAK,EAAG,EAAA;AAAA,IAC5B,cAAA,EAAgB,KAAK,EAAG,EAAA;AAAA,IACxB,iBAAA,EAAmB,KAAK,EAAG,EAAA;AAAA,IAC3B,aAAA,EAAe,KAAK,EAAG,EAAA;AAAA,IACvB,eAAA,EAAiB,KAAK,EAAG,EAAA;AAAA,IACzB,eAAA,EAAiB,KAAK,EAAG,EAAA;AAAA,IACzB,gBAAA,EAAkB,KAAK,EAAG,EAAA;AAAA,IAC1B,WAAA,EAAa,KAAK,EAAG,EAAA;AAAA,IACrB,kBAAA,EAAoB,KAAK,EAAG,EAAA;AAAA,IAC5B,mBAAA,EAAqB,KAAK,EAAG,EAAA;AAAA,IAC7B,cAAA,EAAgB,KAAK,EAAG;AAAA,GACxB,CAAA,CAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"catalogServiceMock.cjs.js","sources":["../../src/testUtils/catalogServiceMock.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ServiceFactory,\n ServiceRef,\n createServiceFactory,\n} from '@backstage/backend-plugin-api';\nimport { InMemoryCatalogClient } from '@backstage/catalog-client/testUtils';\nimport { Entity } from '@backstage/catalog-model';\nimport { catalogServiceRef } from '@backstage/plugin-catalog-node';\n// eslint-disable-next-line @backstage/no-undeclared-imports\nimport { ServiceMock } from '@backstage/backend-test-utils';\nimport { CatalogServiceMock } from './types';\n\n/** @internal */\nfunction simpleMock<TService>(\n ref: ServiceRef<TService, any>,\n mockFactory: () => jest.Mocked<TService>,\n): (partialImpl?: Partial<TService>) => ServiceMock<TService> {\n return partialImpl => {\n const mock = mockFactory();\n if (partialImpl) {\n for (const [key, impl] of Object.entries(partialImpl)) {\n if (typeof impl === 'function') {\n (mock as any)[key].mockImplementation(impl);\n } else {\n (mock as any)[key] = impl;\n }\n }\n }\n return Object.assign(mock, {\n factory: createServiceFactory({\n service: ref,\n deps: {},\n factory: () => mock,\n }),\n }) as ServiceMock<TService>;\n };\n}\n\n/**\n * Creates a fake catalog client that handles entities in memory storage. Note\n * that this client may be severely limited in functionality, and advanced\n * functions may not be available at all.\n *\n * @public\n */\nexport function catalogServiceMock(options?: {\n entities?: Entity[];\n}): CatalogServiceMock {\n return new InMemoryCatalogClient(options);\n}\n\n/**\n * A collection of mock functionality for the catalog service.\n *\n * @public\n */\nexport namespace catalogServiceMock {\n /**\n * Creates a fake catalog client that handles entities in memory storage. Note\n * that this client may be severely limited in functionality, and advanced\n * functions may not be available at all.\n */\n export const factory = (options?: { entities?: Entity[] }) =>\n createServiceFactory({\n service: catalogServiceRef,\n deps: {},\n factory: () => new InMemoryCatalogClient(options),\n }) as ServiceFactory<CatalogServiceMock, 'plugin', 'singleton'>;\n /**\n * Creates a catalog client whose methods are mock functions, possibly with\n * some of them overloaded by the caller.\n */\n export const mock = simpleMock<CatalogServiceMock>(catalogServiceRef, () => ({\n getEntities: jest.fn(),\n getEntitiesByRefs: jest.fn(),\n queryEntities: jest.fn(),\n getEntityAncestors: jest.fn(),\n getEntityByRef: jest.fn(),\n removeEntityByUid: jest.fn(),\n refreshEntity: jest.fn(),\n getEntityFacets: jest.fn(),\n getLocations: jest.fn(),\n getLocationById: jest.fn(),\n getLocationByRef: jest.fn(),\n addLocation: jest.fn(),\n removeLocationById: jest.fn(),\n getLocationByEntity: jest.fn(),\n validateEntity: jest.fn(),\n }));\n}\n"],"names":["createServiceFactory","InMemoryCatalogClient","catalogServiceMock","catalogServiceRef"],"mappings":";;;;;;AA6BA,SAAS,UAAA,CACP,KACA,WAC4D,EAAA;AAC5D,EAAA,OAAO,CAAe,WAAA,KAAA;AACpB,IAAA,MAAM,OAAO,WAAY,EAAA;AACzB,IAAA,IAAI,WAAa,EAAA;AACf,MAAA,KAAA,MAAW,CAAC,GAAK,EAAA,IAAI,KAAK,MAAO,CAAA,OAAA,CAAQ,WAAW,CAAG,EAAA;AACrD,QAAI,IAAA,OAAO,SAAS,UAAY,EAAA;AAC9B,UAAC,IAAa,CAAA,GAAG,CAAE,CAAA,kBAAA,CAAmB,IAAI,CAAA;AAAA,SACrC,MAAA;AACL,UAAC,IAAA,CAAa,GAAG,CAAI,GAAA,IAAA;AAAA;AACvB;AACF;AAEF,IAAO,OAAA,MAAA,CAAO,OAAO,IAAM,EAAA;AAAA,MACzB,SAASA,qCAAqB,CAAA;AAAA,QAC5B,OAAS,EAAA,GAAA;AAAA,QACT,MAAM,EAAC;AAAA,QACP,SAAS,MAAM;AAAA,OAChB;AAAA,KACF,CAAA;AAAA,GACH;AACF;AASO,SAAS,mBAAmB,OAEZ,EAAA;AACrB,EAAO,OAAA,IAAIC,gCAAsB,OAAO,CAAA;AAC1C;AAAA,CAOO,CAAUC,mBAAV,KAAA;AAME,EAAMA,mBAAA,CAAA,OAAA,GAAU,CAAC,OAAA,KACtBF,qCAAqB,CAAA;AAAA,IACnB,OAAS,EAAAG,mCAAA;AAAA,IACT,MAAM,EAAC;AAAA,IACP,OAAS,EAAA,MAAM,IAAIF,+BAAA,CAAsB,OAAO;AAAA,GACjD,CAAA;AAKI,EAAMC,mBAAA,CAAA,IAAA,GAAO,UAA+B,CAAAC,mCAAA,EAAmB,OAAO;AAAA,IAC3E,WAAA,EAAa,KAAK,EAAG,EAAA;AAAA,IACrB,iBAAA,EAAmB,KAAK,EAAG,EAAA;AAAA,IAC3B,aAAA,EAAe,KAAK,EAAG,EAAA;AAAA,IACvB,kBAAA,EAAoB,KAAK,EAAG,EAAA;AAAA,IAC5B,cAAA,EAAgB,KAAK,EAAG,EAAA;AAAA,IACxB,iBAAA,EAAmB,KAAK,EAAG,EAAA;AAAA,IAC3B,aAAA,EAAe,KAAK,EAAG,EAAA;AAAA,IACvB,eAAA,EAAiB,KAAK,EAAG,EAAA;AAAA,IACzB,YAAA,EAAc,KAAK,EAAG,EAAA;AAAA,IACtB,eAAA,EAAiB,KAAK,EAAG,EAAA;AAAA,IACzB,gBAAA,EAAkB,KAAK,EAAG,EAAA;AAAA,IAC1B,WAAA,EAAa,KAAK,EAAG,EAAA;AAAA,IACrB,kBAAA,EAAoB,KAAK,EAAG,EAAA;AAAA,IAC5B,mBAAA,EAAqB,KAAK,EAAG,EAAA;AAAA,IAC7B,cAAA,EAAgB,KAAK,EAAG;AAAA,GACxB,CAAA,CAAA;AAAA,CAhCa,EAAA,kBAAA,KAAA,kBAAA,GAAA,EAAA,CAAA,CAAA;;;;"}
|
package/dist/testUtils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ServiceFactory } from '@backstage/backend-plugin-api';
|
|
2
2
|
import { CompoundEntityRef, Entity } from '@backstage/catalog-model';
|
|
3
3
|
import { ServiceMock } from '@backstage/backend-test-utils';
|
|
4
|
-
import { CatalogApi, GetEntitiesRequest, CatalogRequestOptions, GetEntitiesResponse, GetEntitiesByRefsRequest, GetEntitiesByRefsResponse, QueryEntitiesRequest, QueryEntitiesResponse, GetEntityAncestorsRequest, GetEntityAncestorsResponse, GetEntityFacetsRequest, GetEntityFacetsResponse, Location, AddLocationRequest, AddLocationResponse, ValidateEntityResponse } from '@backstage/catalog-client';
|
|
4
|
+
import { CatalogApi, GetEntitiesRequest, CatalogRequestOptions, GetEntitiesResponse, GetEntitiesByRefsRequest, GetEntitiesByRefsResponse, QueryEntitiesRequest, QueryEntitiesResponse, GetEntityAncestorsRequest, GetEntityAncestorsResponse, GetEntityFacetsRequest, GetEntityFacetsResponse, GetLocationsResponse, Location, AddLocationRequest, AddLocationResponse, ValidateEntityResponse } from '@backstage/catalog-client';
|
|
5
5
|
import { CatalogService, CatalogServiceRequestOptions } from '@backstage/plugin-catalog-node';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -24,6 +24,7 @@ interface CatalogServiceMock extends CatalogService, CatalogApi {
|
|
|
24
24
|
removeEntityByUid(uid: string, options?: CatalogServiceRequestOptions | CatalogRequestOptions): Promise<void>;
|
|
25
25
|
refreshEntity(entityRef: string, options?: CatalogServiceRequestOptions | CatalogRequestOptions): Promise<void>;
|
|
26
26
|
getEntityFacets(request: GetEntityFacetsRequest, options?: CatalogServiceRequestOptions | CatalogRequestOptions): Promise<GetEntityFacetsResponse>;
|
|
27
|
+
getLocations(request?: {}, options?: CatalogServiceRequestOptions | CatalogRequestOptions): Promise<GetLocationsResponse>;
|
|
27
28
|
getLocationById(id: string, options?: CatalogServiceRequestOptions | CatalogRequestOptions): Promise<Location | undefined>;
|
|
28
29
|
getLocationByRef(locationRef: string, options?: CatalogServiceRequestOptions | CatalogRequestOptions): Promise<Location | undefined>;
|
|
29
30
|
addLocation(location: AddLocationRequest, options?: CatalogServiceRequestOptions | CatalogRequestOptions): Promise<AddLocationResponse>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-catalog-node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0-next.1",
|
|
4
4
|
"description": "The plugin-catalog-node module for @backstage/plugin-catalog-backend",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "node-library",
|
|
@@ -72,18 +72,20 @@
|
|
|
72
72
|
"test": "backstage-cli package test"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@backstage/backend-plugin-api": "
|
|
76
|
-
"@backstage/catalog-client": "
|
|
77
|
-
"@backstage/catalog-model": "
|
|
78
|
-
"@backstage/errors": "
|
|
79
|
-
"@backstage/plugin-catalog-common": "
|
|
80
|
-
"@backstage/plugin-permission-common": "
|
|
81
|
-
"@backstage/plugin-permission-node": "
|
|
82
|
-
"@backstage/types": "
|
|
75
|
+
"@backstage/backend-plugin-api": "1.3.1-next.1",
|
|
76
|
+
"@backstage/catalog-client": "1.10.0-next.0",
|
|
77
|
+
"@backstage/catalog-model": "1.7.3",
|
|
78
|
+
"@backstage/errors": "1.2.7",
|
|
79
|
+
"@backstage/plugin-catalog-common": "1.1.4-next.0",
|
|
80
|
+
"@backstage/plugin-permission-common": "0.9.0-next.0",
|
|
81
|
+
"@backstage/plugin-permission-node": "0.10.0-next.1",
|
|
82
|
+
"@backstage/types": "1.2.1",
|
|
83
|
+
"lodash": "^4.17.21",
|
|
84
|
+
"yaml": "^2.0.0"
|
|
83
85
|
},
|
|
84
86
|
"devDependencies": {
|
|
85
|
-
"@backstage/backend-test-utils": "
|
|
86
|
-
"@backstage/cli": "
|
|
87
|
+
"@backstage/backend-test-utils": "1.5.0-next.1",
|
|
88
|
+
"@backstage/cli": "0.32.1-next.1",
|
|
87
89
|
"msw": "^1.0.0"
|
|
88
90
|
}
|
|
89
91
|
}
|