@backstage/plugin-catalog-node 1.12.7-next.2 → 1.13.0
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 +20 -0
- package/alpha/package.json +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/testUtils.cjs.js +56 -0
- package/dist/testUtils.cjs.js.map +1 -0
- package/dist/testUtils.d.ts +37 -0
- package/package.json +15 -9
- package/testUtils/package.json +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @backstage/plugin-catalog-node
|
|
2
2
|
|
|
3
|
+
## 1.13.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- bd35cdb: The `analyze-location` endpoint is now protected by the `catalog.location.analyze` permission.
|
|
8
|
+
The `validate-entity` endpoint is now protected by the `catalog.entity.validate` permission.
|
|
9
|
+
- 29e57c7: Add catalog service mocks under the `/testUtils` subpath export.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
- @backstage/backend-plugin-api@1.0.0
|
|
15
|
+
- @backstage/catalog-model@1.7.0
|
|
16
|
+
- @backstage/catalog-client@1.7.0
|
|
17
|
+
- @backstage/plugin-permission-node@0.8.3
|
|
18
|
+
- @backstage/plugin-catalog-common@1.1.0
|
|
19
|
+
- @backstage/errors@1.2.4
|
|
20
|
+
- @backstage/types@1.1.1
|
|
21
|
+
- @backstage/plugin-permission-common@0.8.1
|
|
22
|
+
|
|
3
23
|
## 1.12.7-next.2
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/alpha/package.json
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { CompoundEntityRef, Entity, LocationEntityV1alpha1 } from '@backstage/catalog-model';
|
|
3
3
|
import { JsonValue } from '@backstage/types';
|
|
4
4
|
import { LocationSpec as LocationSpec$1, AnalyzeLocationRequest, AnalyzeLocationResponse, AnalyzeLocationExistingEntity } from '@backstage/plugin-catalog-common';
|
|
5
|
+
import { BackstageCredentials } from '@backstage/backend-plugin-api';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Holds the entity location information.
|
|
@@ -270,7 +271,7 @@ type LocationAnalyzer = {
|
|
|
270
271
|
*
|
|
271
272
|
* @param location - Git repository to analyze and generate config for.
|
|
272
273
|
*/
|
|
273
|
-
analyzeLocation(location: AnalyzeLocationRequest): Promise<AnalyzeLocationResponse>;
|
|
274
|
+
analyzeLocation(location: AnalyzeLocationRequest, credentials: BackstageCredentials): Promise<AnalyzeLocationResponse>;
|
|
274
275
|
};
|
|
275
276
|
/** @public */
|
|
276
277
|
type AnalyzeOptions = {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
4
|
+
var testUtils = require('@backstage/catalog-client/testUtils');
|
|
5
|
+
var alpha = require('@backstage/plugin-catalog-node/alpha');
|
|
6
|
+
|
|
7
|
+
function simpleMock(ref, mockFactory) {
|
|
8
|
+
return (partialImpl) => {
|
|
9
|
+
const mock = mockFactory();
|
|
10
|
+
if (partialImpl) {
|
|
11
|
+
for (const [key, impl] of Object.entries(partialImpl)) {
|
|
12
|
+
if (typeof impl === "function") {
|
|
13
|
+
mock[key].mockImplementation(impl);
|
|
14
|
+
} else {
|
|
15
|
+
mock[key] = impl;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return Object.assign(mock, {
|
|
20
|
+
factory: backendPluginApi.createServiceFactory({
|
|
21
|
+
service: ref,
|
|
22
|
+
deps: {},
|
|
23
|
+
factory: () => mock
|
|
24
|
+
})
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function catalogServiceMock(options) {
|
|
29
|
+
return new testUtils.InMemoryCatalogClient(options);
|
|
30
|
+
}
|
|
31
|
+
((catalogServiceMock2) => {
|
|
32
|
+
catalogServiceMock2.factory = (options) => backendPluginApi.createServiceFactory({
|
|
33
|
+
service: alpha.catalogServiceRef,
|
|
34
|
+
deps: {},
|
|
35
|
+
factory: () => new testUtils.InMemoryCatalogClient(options)
|
|
36
|
+
});
|
|
37
|
+
catalogServiceMock2.mock = simpleMock(alpha.catalogServiceRef, () => ({
|
|
38
|
+
getEntities: jest.fn(),
|
|
39
|
+
getEntitiesByRefs: jest.fn(),
|
|
40
|
+
queryEntities: jest.fn(),
|
|
41
|
+
getEntityAncestors: jest.fn(),
|
|
42
|
+
getEntityByRef: jest.fn(),
|
|
43
|
+
removeEntityByUid: jest.fn(),
|
|
44
|
+
refreshEntity: jest.fn(),
|
|
45
|
+
getEntityFacets: jest.fn(),
|
|
46
|
+
getLocationById: jest.fn(),
|
|
47
|
+
getLocationByRef: jest.fn(),
|
|
48
|
+
addLocation: jest.fn(),
|
|
49
|
+
removeLocationById: jest.fn(),
|
|
50
|
+
getLocationByEntity: jest.fn(),
|
|
51
|
+
validateEntity: jest.fn()
|
|
52
|
+
}));
|
|
53
|
+
})(catalogServiceMock || (catalogServiceMock = {}));
|
|
54
|
+
|
|
55
|
+
exports.catalogServiceMock = catalogServiceMock;
|
|
56
|
+
//# sourceMappingURL=testUtils.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testUtils.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 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/alpha';\n// eslint-disable-next-line @backstage/no-undeclared-imports\nimport { ServiceMock } from '@backstage/backend-test-utils';\nimport { CatalogApi } from '@backstage/catalog-client';\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}): CatalogApi {\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 });\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(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":";;;;;;AA4BA,SAAS,UAAA,CACP,KACA,WAC4D,EAAA;AAC5D,EAAA,OAAO,CAAe,WAAA,KAAA;AACpB,IAAA,MAAM,OAAO,WAAY,EAAA,CAAA;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,CAAA;AAAA,SACrC,MAAA;AACL,UAAC,IAAA,CAAa,GAAG,CAAI,GAAA,IAAA,CAAA;AAAA,SACvB;AAAA,OACF;AAAA,KACF;AACA,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,IAAA;AAAA,OAChB,CAAA;AAAA,KACF,CAAA,CAAA;AAAA,GACH,CAAA;AACF,CAAA;AASO,SAAS,mBAAmB,OAEpB,EAAA;AACb,EAAO,OAAA,IAAIC,gCAAsB,OAAO,CAAA,CAAA;AAC1C,CAAA;AAAA,CAOO,CAAUC,mBAAV,KAAA;AAME,EAAMA,mBAAA,CAAA,OAAA,GAAU,CAAC,OAAA,KACtBF,qCAAqB,CAAA;AAAA,IACnB,OAAS,EAAAG,uBAAA;AAAA,IACT,MAAM,EAAC;AAAA,IACP,OAAS,EAAA,MAAM,IAAIF,+BAAA,CAAsB,OAAO,CAAA;AAAA,GACjD,CAAA,CAAA;AAKI,EAAMC,mBAAA,CAAA,IAAA,GAAO,UAAW,CAAAC,uBAAA,EAAmB,OAAO;AAAA,IACvD,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,EAAA;AAAA,GACxB,CAAA,CAAA,CAAA;AAAA,CA/Ba,EAAA,kBAAA,KAAA,kBAAA,GAAA,EAAA,CAAA,CAAA;;;;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
+
import { Entity } from '@backstage/catalog-model';
|
|
3
|
+
import { ServiceMock } from '@backstage/backend-test-utils';
|
|
4
|
+
import { CatalogApi } from '@backstage/catalog-client';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a fake catalog client that handles entities in memory storage. Note
|
|
8
|
+
* that this client may be severely limited in functionality, and advanced
|
|
9
|
+
* functions may not be available at all.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
declare function catalogServiceMock(options?: {
|
|
14
|
+
entities?: Entity[];
|
|
15
|
+
}): CatalogApi;
|
|
16
|
+
/**
|
|
17
|
+
* A collection of mock functionality for the catalog service.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
declare namespace catalogServiceMock {
|
|
22
|
+
/**
|
|
23
|
+
* Creates a fake catalog client that handles entities in memory storage. Note
|
|
24
|
+
* that this client may be severely limited in functionality, and advanced
|
|
25
|
+
* functions may not be available at all.
|
|
26
|
+
*/
|
|
27
|
+
const factory: (options?: {
|
|
28
|
+
entities?: Entity[];
|
|
29
|
+
}) => _backstage_backend_plugin_api.ServiceFactory<CatalogApi, "plugin", "singleton">;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a catalog client whose methods are mock functions, possibly with
|
|
32
|
+
* some of them overloaded by the caller.
|
|
33
|
+
*/
|
|
34
|
+
const mock: (partialImpl?: Partial<CatalogApi> | undefined) => ServiceMock<CatalogApi>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { catalogServiceMock };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-catalog-node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "The plugin-catalog-node module for @backstage/plugin-catalog-backend",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "node-library",
|
|
@@ -34,13 +34,19 @@
|
|
|
34
34
|
"types": "./dist/alpha.d.ts",
|
|
35
35
|
"default": "./dist/alpha.cjs.js"
|
|
36
36
|
},
|
|
37
|
+
"./testUtils": {
|
|
38
|
+
"require": "./dist/testUtils.cjs.js",
|
|
39
|
+
"types": "./dist/testUtils.d.ts",
|
|
40
|
+
"default": "./dist/testUtils.cjs.js"
|
|
41
|
+
},
|
|
37
42
|
"./package.json": "./package.json"
|
|
38
43
|
},
|
|
39
44
|
"main": "./dist/index.cjs.js",
|
|
40
45
|
"types": "./dist/index.d.ts",
|
|
41
46
|
"files": [
|
|
42
47
|
"dist",
|
|
43
|
-
"alpha"
|
|
48
|
+
"alpha",
|
|
49
|
+
"testUtils"
|
|
44
50
|
],
|
|
45
51
|
"scripts": {
|
|
46
52
|
"build": "backstage-cli package build",
|
|
@@ -52,17 +58,17 @@
|
|
|
52
58
|
"test": "backstage-cli package test"
|
|
53
59
|
},
|
|
54
60
|
"dependencies": {
|
|
55
|
-
"@backstage/backend-plugin-api": "^1.0.0
|
|
56
|
-
"@backstage/catalog-client": "^1.7.0
|
|
57
|
-
"@backstage/catalog-model": "^1.
|
|
61
|
+
"@backstage/backend-plugin-api": "^1.0.0",
|
|
62
|
+
"@backstage/catalog-client": "^1.7.0",
|
|
63
|
+
"@backstage/catalog-model": "^1.7.0",
|
|
58
64
|
"@backstage/errors": "^1.2.4",
|
|
59
|
-
"@backstage/plugin-catalog-common": "^1.0
|
|
65
|
+
"@backstage/plugin-catalog-common": "^1.1.0",
|
|
60
66
|
"@backstage/plugin-permission-common": "^0.8.1",
|
|
61
|
-
"@backstage/plugin-permission-node": "^0.8.3
|
|
67
|
+
"@backstage/plugin-permission-node": "^0.8.3",
|
|
62
68
|
"@backstage/types": "^1.1.1"
|
|
63
69
|
},
|
|
64
70
|
"devDependencies": {
|
|
65
|
-
"@backstage/backend-test-utils": "^1.0.0
|
|
66
|
-
"@backstage/cli": "^0.27.1
|
|
71
|
+
"@backstage/backend-test-utils": "^1.0.0",
|
|
72
|
+
"@backstage/cli": "^0.27.1"
|
|
67
73
|
}
|
|
68
74
|
}
|