@backstage/plugin-search-backend-module-catalog 0.0.0-nightly-20230323021924
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 +21 -0
- package/README.md +41 -0
- package/alpha/package.json +6 -0
- package/dist/alpha.cjs.js +52 -0
- package/dist/alpha.cjs.js.map +1 -0
- package/dist/alpha.d.ts +18 -0
- package/dist/index.cjs.js +102 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/package.json +58 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @backstage/plugin-search-backend-module-catalog
|
|
2
|
+
|
|
3
|
+
## 0.0.0-nightly-20230323021924
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 01ae205352e: Package introduced to export search backend modules that can be used with the new backend system to extend search with plugin specific functionality, such as collators. For documentation on how to migrate, check out the [how to migrate to the new backend system guide](../docs/features/search/how-to-guides.md#how-to-migrate-to-use-search-together-with-the-new-backend-system).
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @backstage/backend-common@0.0.0-nightly-20230323021924
|
|
13
|
+
- @backstage/plugin-search-backend-node@0.0.0-nightly-20230323021924
|
|
14
|
+
- @backstage/backend-plugin-api@0.0.0-nightly-20230323021924
|
|
15
|
+
- @backstage/backend-tasks@0.0.0-nightly-20230323021924
|
|
16
|
+
- @backstage/catalog-client@1.4.0
|
|
17
|
+
- @backstage/catalog-model@1.2.1
|
|
18
|
+
- @backstage/config@1.0.7
|
|
19
|
+
- @backstage/plugin-catalog-common@1.0.12
|
|
20
|
+
- @backstage/plugin-permission-common@0.7.4
|
|
21
|
+
- @backstage/plugin-search-common@1.2.2
|
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# search-backend-module-catalog
|
|
2
|
+
|
|
3
|
+
> DISCLAIMER: The new backend system is in alpha, and so are the search backend module support for the new backend system. We don't recommend you to migrate your backend installations to the new system yet. But if you want to experiment, you can find getting started guides below.
|
|
4
|
+
|
|
5
|
+
This package exports catalog backend modules responsible for extending search.
|
|
6
|
+
|
|
7
|
+
## Example
|
|
8
|
+
|
|
9
|
+
### Use default schedule
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
// packages/backend-next/src/index.ts
|
|
13
|
+
import { createBackend } from '@backstage/backend-defaults';
|
|
14
|
+
import { searchPlugin } from '@backstage/plugin-search-backend/alpha';
|
|
15
|
+
import { searchModuleCatalogCollator } from '@backstage/plugin-search-backend-module-catalog/alpha';
|
|
16
|
+
|
|
17
|
+
const backend = createBackend();
|
|
18
|
+
backend.add(searchPlugin());
|
|
19
|
+
backend.add(searchModuleCatalogCollator());
|
|
20
|
+
backend.start();
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Use custom schedule
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
// packages/backend-next/src/index.ts
|
|
27
|
+
import { createBackend } from '@backstage/backend-defaults';
|
|
28
|
+
import { searchPlugin } from '@backstage/plugin-search-backend/alpha';
|
|
29
|
+
import { searchModuleCatalogCollator } from '@backstage/plugin-search-backend-module-catalog/alpha';
|
|
30
|
+
|
|
31
|
+
const schedule = {
|
|
32
|
+
frequency: { minutes: 10 },
|
|
33
|
+
timeout: { minutes: 15 },
|
|
34
|
+
initialDelay: { seconds: 3 },
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const backend = createBackend();
|
|
38
|
+
backend.add(searchPlugin());
|
|
39
|
+
backend.add(searchModuleCatalogCollator({ schedule }));
|
|
40
|
+
backend.start();
|
|
41
|
+
```
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
6
|
+
var alpha = require('@backstage/plugin-search-backend-node/alpha');
|
|
7
|
+
var pluginSearchBackendModuleCatalog = require('@backstage/plugin-search-backend-module-catalog');
|
|
8
|
+
|
|
9
|
+
const searchModuleCatalogCollator = backendPluginApi.createBackendModule(
|
|
10
|
+
(options) => ({
|
|
11
|
+
moduleId: "catalogCollator",
|
|
12
|
+
pluginId: "search",
|
|
13
|
+
register(env) {
|
|
14
|
+
env.registerInit({
|
|
15
|
+
deps: {
|
|
16
|
+
config: backendPluginApi.coreServices.config,
|
|
17
|
+
discovery: backendPluginApi.coreServices.discovery,
|
|
18
|
+
tokenManager: backendPluginApi.coreServices.tokenManager,
|
|
19
|
+
scheduler: backendPluginApi.coreServices.scheduler,
|
|
20
|
+
indexRegistry: alpha.searchIndexRegistryExtensionPoint
|
|
21
|
+
},
|
|
22
|
+
async init({
|
|
23
|
+
config,
|
|
24
|
+
discovery,
|
|
25
|
+
tokenManager,
|
|
26
|
+
scheduler,
|
|
27
|
+
indexRegistry
|
|
28
|
+
}) {
|
|
29
|
+
var _a;
|
|
30
|
+
const defaultSchedule = {
|
|
31
|
+
frequency: { minutes: 10 },
|
|
32
|
+
timeout: { minutes: 15 },
|
|
33
|
+
initialDelay: { seconds: 3 }
|
|
34
|
+
};
|
|
35
|
+
indexRegistry.addCollator({
|
|
36
|
+
schedule: scheduler.createScheduledTaskRunner(
|
|
37
|
+
(_a = options == null ? void 0 : options.schedule) != null ? _a : defaultSchedule
|
|
38
|
+
),
|
|
39
|
+
factory: pluginSearchBackendModuleCatalog.DefaultCatalogCollatorFactory.fromConfig(config, {
|
|
40
|
+
...options,
|
|
41
|
+
discovery,
|
|
42
|
+
tokenManager
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
exports.searchModuleCatalogCollator = searchModuleCatalogCollator;
|
|
52
|
+
//# sourceMappingURL=alpha.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alpha.cjs.js","sources":["../src/alpha.ts"],"sourcesContent":["/*\n * Copyright 2023 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\n/**\n * @packageDocumentation\n * A module for the search backend that exports Catalog modules.\n */\n\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { TaskScheduleDefinition } from '@backstage/backend-tasks';\nimport { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha';\n\nimport {\n DefaultCatalogCollatorFactory,\n DefaultCatalogCollatorFactoryOptions,\n} from '@backstage/plugin-search-backend-module-catalog';\n\n/**\n * @alpha\n * Options for {@link searchModuleCatalogCollator}.\n */\nexport type SearchModuleCatalogCollatorOptions = Omit<\n DefaultCatalogCollatorFactoryOptions,\n 'discovery' | 'tokenManager'\n> & {\n schedule?: TaskScheduleDefinition;\n};\n\n/**\n * @alpha\n * Search backend module for the Catalog index.\n */\nexport const searchModuleCatalogCollator = createBackendModule(\n (options?: SearchModuleCatalogCollatorOptions) => ({\n moduleId: 'catalogCollator',\n pluginId: 'search',\n register(env) {\n env.registerInit({\n deps: {\n config: coreServices.config,\n discovery: coreServices.discovery,\n tokenManager: coreServices.tokenManager,\n scheduler: coreServices.scheduler,\n indexRegistry: searchIndexRegistryExtensionPoint,\n },\n async init({\n config,\n discovery,\n tokenManager,\n scheduler,\n indexRegistry,\n }) {\n const defaultSchedule = {\n frequency: { minutes: 10 },\n timeout: { minutes: 15 },\n initialDelay: { seconds: 3 },\n };\n\n indexRegistry.addCollator({\n schedule: scheduler.createScheduledTaskRunner(\n options?.schedule ?? defaultSchedule,\n ),\n factory: DefaultCatalogCollatorFactory.fromConfig(config, {\n ...options,\n discovery,\n tokenManager,\n }),\n });\n },\n });\n },\n }),\n);\n"],"names":["createBackendModule","coreServices","searchIndexRegistryExtensionPoint","DefaultCatalogCollatorFactory"],"mappings":";;;;;;;;AAgDO,MAAM,2BAA8B,GAAAA,oCAAA;AAAA,EACzC,CAAC,OAAkD,MAAA;AAAA,IACjD,QAAU,EAAA,iBAAA;AAAA,IACV,QAAU,EAAA,QAAA;AAAA,IACV,SAAS,GAAK,EAAA;AACZ,MAAA,GAAA,CAAI,YAAa,CAAA;AAAA,QACf,IAAM,EAAA;AAAA,UACJ,QAAQC,6BAAa,CAAA,MAAA;AAAA,UACrB,WAAWA,6BAAa,CAAA,SAAA;AAAA,UACxB,cAAcA,6BAAa,CAAA,YAAA;AAAA,UAC3B,WAAWA,6BAAa,CAAA,SAAA;AAAA,UACxB,aAAe,EAAAC,uCAAA;AAAA,SACjB;AAAA,QACA,MAAM,IAAK,CAAA;AAAA,UACT,MAAA;AAAA,UACA,SAAA;AAAA,UACA,YAAA;AAAA,UACA,SAAA;AAAA,UACA,aAAA;AAAA,SACC,EAAA;AAnEX,UAAA,IAAA,EAAA,CAAA;AAoEU,UAAA,MAAM,eAAkB,GAAA;AAAA,YACtB,SAAA,EAAW,EAAE,OAAA,EAAS,EAAG,EAAA;AAAA,YACzB,OAAA,EAAS,EAAE,OAAA,EAAS,EAAG,EAAA;AAAA,YACvB,YAAA,EAAc,EAAE,OAAA,EAAS,CAAE,EAAA;AAAA,WAC7B,CAAA;AAEA,UAAA,aAAA,CAAc,WAAY,CAAA;AAAA,YACxB,UAAU,SAAU,CAAA,yBAAA;AAAA,cAClB,CAAA,EAAA,GAAA,OAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,OAAA,CAAS,aAAT,IAAqB,GAAA,EAAA,GAAA,eAAA;AAAA,aACvB;AAAA,YACA,OAAA,EAASC,8DAA8B,CAAA,UAAA,CAAW,MAAQ,EAAA;AAAA,cACxD,GAAG,OAAA;AAAA,cACH,SAAA;AAAA,cACA,YAAA;AAAA,aACD,CAAA;AAAA,WACF,CAAA,CAAA;AAAA,SACH;AAAA,OACD,CAAA,CAAA;AAAA,KACH;AAAA,GACF,CAAA;AACF;;;;"}
|
package/dist/alpha.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
+
import { TaskScheduleDefinition } from '@backstage/backend-tasks';
|
|
3
|
+
import { DefaultCatalogCollatorFactoryOptions } from '@backstage/plugin-search-backend-module-catalog';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @alpha
|
|
7
|
+
* Options for {@link searchModuleCatalogCollator}.
|
|
8
|
+
*/
|
|
9
|
+
declare type SearchModuleCatalogCollatorOptions = Omit<DefaultCatalogCollatorFactoryOptions, 'discovery' | 'tokenManager'> & {
|
|
10
|
+
schedule?: TaskScheduleDefinition;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @alpha
|
|
14
|
+
* Search backend module for the Catalog index.
|
|
15
|
+
*/
|
|
16
|
+
declare const searchModuleCatalogCollator: (options?: SearchModuleCatalogCollatorOptions | undefined) => _backstage_backend_plugin_api.BackendFeature;
|
|
17
|
+
|
|
18
|
+
export { SearchModuleCatalogCollatorOptions, searchModuleCatalogCollator };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var catalogClient = require('@backstage/catalog-client');
|
|
6
|
+
var alpha = require('@backstage/plugin-catalog-common/alpha');
|
|
7
|
+
var stream = require('stream');
|
|
8
|
+
var catalogModel = require('@backstage/catalog-model');
|
|
9
|
+
|
|
10
|
+
const getDocumentText = (entity) => {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const documentTexts = [];
|
|
13
|
+
documentTexts.push(entity.metadata.description || "");
|
|
14
|
+
if (catalogModel.isUserEntity(entity) || catalogModel.isGroupEntity(entity)) {
|
|
15
|
+
if ((_b = (_a = entity.spec) == null ? void 0 : _a.profile) == null ? void 0 : _b.displayName) {
|
|
16
|
+
documentTexts.push(entity.spec.profile.displayName);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return documentTexts.join(" : ");
|
|
20
|
+
};
|
|
21
|
+
const defaultCatalogCollatorEntityTransformer = (entity) => {
|
|
22
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
23
|
+
return {
|
|
24
|
+
title: (_a = entity.metadata.title) != null ? _a : entity.metadata.name,
|
|
25
|
+
text: getDocumentText(entity),
|
|
26
|
+
componentType: ((_c = (_b = entity.spec) == null ? void 0 : _b.type) == null ? void 0 : _c.toString()) || "other",
|
|
27
|
+
type: ((_e = (_d = entity.spec) == null ? void 0 : _d.type) == null ? void 0 : _e.toString()) || "other",
|
|
28
|
+
namespace: entity.metadata.namespace || "default",
|
|
29
|
+
kind: entity.kind,
|
|
30
|
+
lifecycle: ((_f = entity.spec) == null ? void 0 : _f.lifecycle) || "",
|
|
31
|
+
owner: ((_g = entity.spec) == null ? void 0 : _g.owner) || ""
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
class DefaultCatalogCollatorFactory {
|
|
36
|
+
constructor(options) {
|
|
37
|
+
this.type = "software-catalog";
|
|
38
|
+
this.visibilityPermission = alpha.catalogEntityReadPermission;
|
|
39
|
+
const {
|
|
40
|
+
batchSize,
|
|
41
|
+
discovery,
|
|
42
|
+
locationTemplate,
|
|
43
|
+
filter,
|
|
44
|
+
catalogClient: catalogClient$1,
|
|
45
|
+
tokenManager,
|
|
46
|
+
entityTransformer
|
|
47
|
+
} = options;
|
|
48
|
+
this.locationTemplate = locationTemplate || "/catalog/:namespace/:kind/:name";
|
|
49
|
+
this.filter = filter;
|
|
50
|
+
this.batchSize = batchSize || 500;
|
|
51
|
+
this.catalogClient = catalogClient$1 || new catalogClient.CatalogClient({ discoveryApi: discovery });
|
|
52
|
+
this.tokenManager = tokenManager;
|
|
53
|
+
this.entityTransformer = entityTransformer != null ? entityTransformer : defaultCatalogCollatorEntityTransformer;
|
|
54
|
+
}
|
|
55
|
+
static fromConfig(_config, options) {
|
|
56
|
+
return new DefaultCatalogCollatorFactory(options);
|
|
57
|
+
}
|
|
58
|
+
async getCollator() {
|
|
59
|
+
return stream.Readable.from(this.execute());
|
|
60
|
+
}
|
|
61
|
+
async *execute() {
|
|
62
|
+
const { token } = await this.tokenManager.getToken();
|
|
63
|
+
let entitiesRetrieved = 0;
|
|
64
|
+
let moreEntitiesToGet = true;
|
|
65
|
+
while (moreEntitiesToGet) {
|
|
66
|
+
const entities = (await this.catalogClient.getEntities(
|
|
67
|
+
{
|
|
68
|
+
filter: this.filter,
|
|
69
|
+
limit: this.batchSize,
|
|
70
|
+
offset: entitiesRetrieved
|
|
71
|
+
},
|
|
72
|
+
{ token }
|
|
73
|
+
)).items;
|
|
74
|
+
moreEntitiesToGet = entities.length === this.batchSize;
|
|
75
|
+
entitiesRetrieved += entities.length;
|
|
76
|
+
for (const entity of entities) {
|
|
77
|
+
yield {
|
|
78
|
+
...this.entityTransformer(entity),
|
|
79
|
+
authorization: {
|
|
80
|
+
resourceRef: catalogModel.stringifyEntityRef(entity)
|
|
81
|
+
},
|
|
82
|
+
location: this.applyArgsToFormat(this.locationTemplate, {
|
|
83
|
+
namespace: entity.metadata.namespace || "default",
|
|
84
|
+
kind: entity.kind,
|
|
85
|
+
name: entity.metadata.name
|
|
86
|
+
})
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
applyArgsToFormat(format, args) {
|
|
92
|
+
let formatted = format;
|
|
93
|
+
for (const [key, value] of Object.entries(args)) {
|
|
94
|
+
formatted = formatted.replace(`:${key}`, value);
|
|
95
|
+
}
|
|
96
|
+
return formatted.toLowerCase();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
exports.DefaultCatalogCollatorFactory = DefaultCatalogCollatorFactory;
|
|
101
|
+
exports.defaultCatalogCollatorEntityTransformer = defaultCatalogCollatorEntityTransformer;
|
|
102
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/collators/defaultCatalogCollatorEntityTransformer.ts","../src/collators/DefaultCatalogCollatorFactory.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 { Entity, isGroupEntity, isUserEntity } from '@backstage/catalog-model';\nimport { CatalogCollatorEntityTransformer } from './CatalogCollatorEntityTransformer';\n\nconst getDocumentText = (entity: Entity): string => {\n const documentTexts: string[] = [];\n documentTexts.push(entity.metadata.description || '');\n\n if (isUserEntity(entity) || isGroupEntity(entity)) {\n if (entity.spec?.profile?.displayName) {\n documentTexts.push(entity.spec.profile.displayName);\n }\n }\n\n return documentTexts.join(' : ');\n};\n\n/** @public */\nexport const defaultCatalogCollatorEntityTransformer: CatalogCollatorEntityTransformer =\n (entity: Entity) => {\n return {\n title: entity.metadata.title ?? entity.metadata.name,\n text: getDocumentText(entity),\n componentType: entity.spec?.type?.toString() || 'other',\n type: entity.spec?.type?.toString() || 'other',\n namespace: entity.metadata.namespace || 'default',\n kind: entity.kind,\n lifecycle: (entity.spec?.lifecycle as string) || '',\n owner: (entity.spec?.owner as string) || '',\n };\n };\n","/*\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 { Config } from '@backstage/config';\nimport {\n PluginEndpointDiscovery,\n TokenManager,\n} from '@backstage/backend-common';\nimport {\n CatalogApi,\n CatalogClient,\n GetEntitiesRequest,\n} from '@backstage/catalog-client';\nimport { DocumentCollatorFactory } from '@backstage/plugin-search-common';\nimport { catalogEntityReadPermission } from '@backstage/plugin-catalog-common/alpha';\nimport { CatalogEntityDocument } from '@backstage/plugin-catalog-common';\nimport { Permission } from '@backstage/plugin-permission-common';\nimport { Readable } from 'stream';\nimport { CatalogCollatorEntityTransformer } from './CatalogCollatorEntityTransformer';\nimport { defaultCatalogCollatorEntityTransformer } from './defaultCatalogCollatorEntityTransformer';\nimport { stringifyEntityRef } from '@backstage/catalog-model';\n\n/** @public */\nexport type DefaultCatalogCollatorFactoryOptions = {\n discovery: PluginEndpointDiscovery;\n tokenManager: TokenManager;\n locationTemplate?: string;\n filter?: GetEntitiesRequest['filter'];\n batchSize?: number;\n catalogClient?: CatalogApi;\n entityTransformer?: CatalogCollatorEntityTransformer;\n};\n\n/** @public */\nexport class DefaultCatalogCollatorFactory implements DocumentCollatorFactory {\n public readonly type = 'software-catalog';\n public readonly visibilityPermission: Permission =\n catalogEntityReadPermission;\n\n private locationTemplate: string;\n private filter?: GetEntitiesRequest['filter'];\n private batchSize: number;\n private readonly catalogClient: CatalogApi;\n private tokenManager: TokenManager;\n private entityTransformer: CatalogCollatorEntityTransformer;\n\n static fromConfig(\n _config: Config,\n options: DefaultCatalogCollatorFactoryOptions,\n ) {\n return new DefaultCatalogCollatorFactory(options);\n }\n\n private constructor(options: DefaultCatalogCollatorFactoryOptions) {\n const {\n batchSize,\n discovery,\n locationTemplate,\n filter,\n catalogClient,\n tokenManager,\n entityTransformer,\n } = options;\n\n this.locationTemplate =\n locationTemplate || '/catalog/:namespace/:kind/:name';\n this.filter = filter;\n this.batchSize = batchSize || 500;\n this.catalogClient =\n catalogClient || new CatalogClient({ discoveryApi: discovery });\n this.tokenManager = tokenManager;\n this.entityTransformer =\n entityTransformer ?? defaultCatalogCollatorEntityTransformer;\n }\n\n async getCollator(): Promise<Readable> {\n return Readable.from(this.execute());\n }\n\n private async *execute(): AsyncGenerator<CatalogEntityDocument> {\n const { token } = await this.tokenManager.getToken();\n let entitiesRetrieved = 0;\n let moreEntitiesToGet = true;\n\n // Offset/limit pagination is used on the Catalog Client in order to\n // limit (and allow some control over) memory used by the search backend\n // at index-time.\n while (moreEntitiesToGet) {\n const entities = (\n await this.catalogClient.getEntities(\n {\n filter: this.filter,\n limit: this.batchSize,\n offset: entitiesRetrieved,\n },\n { token },\n )\n ).items;\n\n // Control looping through entity batches.\n moreEntitiesToGet = entities.length === this.batchSize;\n entitiesRetrieved += entities.length;\n\n for (const entity of entities) {\n yield {\n ...this.entityTransformer(entity),\n authorization: {\n resourceRef: stringifyEntityRef(entity),\n },\n location: this.applyArgsToFormat(this.locationTemplate, {\n namespace: entity.metadata.namespace || 'default',\n kind: entity.kind,\n name: entity.metadata.name,\n }),\n };\n }\n }\n }\n\n private applyArgsToFormat(\n format: string,\n args: Record<string, string>,\n ): string {\n let formatted = format;\n\n for (const [key, value] of Object.entries(args)) {\n formatted = formatted.replace(`:${key}`, value);\n }\n\n return formatted.toLowerCase();\n }\n}\n"],"names":["isUserEntity","isGroupEntity","catalogEntityReadPermission","catalogClient","CatalogClient","Readable","stringifyEntityRef"],"mappings":";;;;;;;;;AAmBA,MAAM,eAAA,GAAkB,CAAC,MAA2B,KAAA;AAnBpD,EAAA,IAAA,EAAA,EAAA,EAAA,CAAA;AAoBE,EAAA,MAAM,gB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A;AACR,IAAA,IAAI,SAAY,GAAA,MAAA,CAAA;AAEhB,IAAA,KAAA,MAAW,CAAC,GAAK,EAAA,KAAK,KAAK,MAAO,CAAA,OAAA,CAAQ,IAAI,CAAG,EAAA;AAC/C,MAAA,SAAA,GAAY,SAAU,CAAA,OAAA,CAAQ,CAAI,CAAA,EAAA,GAAA,CAAA,CAAA,EAAO,KAAK,CAAA,CAAA;AAAA,KAChD;AAEA,IAAA,OAAO,UAAU,WAAY,EAAA,CAAA;AAAA,GAC/B;AACF;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Config } from '@backstage/config';
|
|
3
|
+
import { PluginEndpointDiscovery, TokenManager } from '@backstage/backend-common';
|
|
4
|
+
import { GetEntitiesRequest, CatalogApi } from '@backstage/catalog-client';
|
|
5
|
+
import { DocumentCollatorFactory } from '@backstage/plugin-search-common';
|
|
6
|
+
import { Permission } from '@backstage/plugin-permission-common';
|
|
7
|
+
import { Readable } from 'stream';
|
|
8
|
+
import { Entity } from '@backstage/catalog-model';
|
|
9
|
+
import { CatalogEntityDocument } from '@backstage/plugin-catalog-common';
|
|
10
|
+
|
|
11
|
+
/** @public */
|
|
12
|
+
declare type CatalogCollatorEntityTransformer = (entity: Entity) => Omit<CatalogEntityDocument, 'location' | 'authorization'>;
|
|
13
|
+
|
|
14
|
+
/** @public */
|
|
15
|
+
declare type DefaultCatalogCollatorFactoryOptions = {
|
|
16
|
+
discovery: PluginEndpointDiscovery;
|
|
17
|
+
tokenManager: TokenManager;
|
|
18
|
+
locationTemplate?: string;
|
|
19
|
+
filter?: GetEntitiesRequest['filter'];
|
|
20
|
+
batchSize?: number;
|
|
21
|
+
catalogClient?: CatalogApi;
|
|
22
|
+
entityTransformer?: CatalogCollatorEntityTransformer;
|
|
23
|
+
};
|
|
24
|
+
/** @public */
|
|
25
|
+
declare class DefaultCatalogCollatorFactory implements DocumentCollatorFactory {
|
|
26
|
+
readonly type = "software-catalog";
|
|
27
|
+
readonly visibilityPermission: Permission;
|
|
28
|
+
private locationTemplate;
|
|
29
|
+
private filter?;
|
|
30
|
+
private batchSize;
|
|
31
|
+
private readonly catalogClient;
|
|
32
|
+
private tokenManager;
|
|
33
|
+
private entityTransformer;
|
|
34
|
+
static fromConfig(_config: Config, options: DefaultCatalogCollatorFactoryOptions): DefaultCatalogCollatorFactory;
|
|
35
|
+
private constructor();
|
|
36
|
+
getCollator(): Promise<Readable>;
|
|
37
|
+
private execute;
|
|
38
|
+
private applyArgsToFormat;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** @public */
|
|
42
|
+
declare const defaultCatalogCollatorEntityTransformer: CatalogCollatorEntityTransformer;
|
|
43
|
+
|
|
44
|
+
export { CatalogCollatorEntityTransformer, DefaultCatalogCollatorFactory, DefaultCatalogCollatorFactoryOptions, defaultCatalogCollatorEntityTransformer };
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@backstage/plugin-search-backend-module-catalog",
|
|
3
|
+
"description": "A module for the search backend that exports catalog modules",
|
|
4
|
+
"version": "0.0.0-nightly-20230323021924",
|
|
5
|
+
"main": "./dist/index.cjs.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"require": "./dist/index.cjs.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.cjs.js"
|
|
16
|
+
},
|
|
17
|
+
"./alpha": {
|
|
18
|
+
"require": "./dist/alpha.cjs.js",
|
|
19
|
+
"types": "./dist/alpha.d.ts",
|
|
20
|
+
"default": "./dist/alpha.cjs.js"
|
|
21
|
+
},
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"backstage": {
|
|
25
|
+
"role": "backend-plugin-module"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"start": "backstage-cli package start",
|
|
29
|
+
"build": "backstage-cli package build",
|
|
30
|
+
"lint": "backstage-cli package lint",
|
|
31
|
+
"test": "backstage-cli package test",
|
|
32
|
+
"prepack": "backstage-cli package prepack",
|
|
33
|
+
"postpack": "backstage-cli package postpack",
|
|
34
|
+
"clean": "backstage-cli package clean"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@backstage/backend-common": "^0.0.0-nightly-20230323021924",
|
|
38
|
+
"@backstage/backend-plugin-api": "^0.0.0-nightly-20230323021924",
|
|
39
|
+
"@backstage/backend-tasks": "^0.0.0-nightly-20230323021924",
|
|
40
|
+
"@backstage/catalog-client": "^1.4.0",
|
|
41
|
+
"@backstage/catalog-model": "^1.2.1",
|
|
42
|
+
"@backstage/config": "^1.0.7",
|
|
43
|
+
"@backstage/plugin-catalog-common": "^1.0.12",
|
|
44
|
+
"@backstage/plugin-permission-common": "^0.7.4",
|
|
45
|
+
"@backstage/plugin-search-backend-node": "^0.0.0-nightly-20230323021924",
|
|
46
|
+
"@backstage/plugin-search-common": "^1.2.2"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@backstage/backend-common": "^0.0.0-nightly-20230323021924",
|
|
50
|
+
"@backstage/backend-test-utils": "^0.0.0-nightly-20230323021924",
|
|
51
|
+
"@backstage/cli": "^0.0.0-nightly-20230323021924",
|
|
52
|
+
"msw": "^1.0.0"
|
|
53
|
+
},
|
|
54
|
+
"files": [
|
|
55
|
+
"dist",
|
|
56
|
+
"alpha"
|
|
57
|
+
]
|
|
58
|
+
}
|