@backstage/plugin-search-backend-module-explore 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 ADDED
@@ -0,0 +1,18 @@
1
+ # @backstage/plugin-search-backend-module-explore
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/config@1.0.7
17
+ - @backstage/plugin-explore-common@0.0.1
18
+ - @backstage/plugin-search-common@1.2.2
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # search-backend-module-explore
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 explore 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 { searchModuleExploreCollator } from '@backstage/plugin-search-backend-module-explore/alpha';
16
+
17
+ const backend = createBackend();
18
+ backend.add(searchPlugin());
19
+ backend.add(searchModuleExploreCollator());
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 { searchModuleExploreCollator } from '@backstage/plugin-search-backend-module-explore/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(searchModuleExploreCollator({ schedule }));
40
+ backend.start();
41
+ ```
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "@backstage/plugin-search-backend-module-explore",
3
+ "version": "0.0.0-nightly-20230323021924",
4
+ "main": "../dist/alpha.cjs.js",
5
+ "types": "../dist/alpha.d.ts"
6
+ }
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var backendPluginApi = require('@backstage/backend-plugin-api');
6
+ var backendCommon = require('@backstage/backend-common');
7
+ var alpha = require('@backstage/plugin-search-backend-node/alpha');
8
+ var pluginSearchBackendModuleExplore = require('@backstage/plugin-search-backend-module-explore');
9
+
10
+ const searchModuleExploreCollator = backendPluginApi.createBackendModule(
11
+ (options) => ({
12
+ moduleId: "exploreCollator",
13
+ pluginId: "search",
14
+ register(env) {
15
+ env.registerInit({
16
+ deps: {
17
+ config: backendPluginApi.coreServices.config,
18
+ logger: backendPluginApi.coreServices.logger,
19
+ discovery: backendPluginApi.coreServices.discovery,
20
+ scheduler: backendPluginApi.coreServices.scheduler,
21
+ indexRegistry: alpha.searchIndexRegistryExtensionPoint
22
+ },
23
+ async init({ config, logger, discovery, scheduler, indexRegistry }) {
24
+ var _a;
25
+ const defaultSchedule = {
26
+ frequency: { minutes: 10 },
27
+ timeout: { minutes: 15 },
28
+ initialDelay: { seconds: 3 }
29
+ };
30
+ indexRegistry.addCollator({
31
+ schedule: scheduler.createScheduledTaskRunner(
32
+ (_a = options == null ? void 0 : options.schedule) != null ? _a : defaultSchedule
33
+ ),
34
+ factory: pluginSearchBackendModuleExplore.ToolDocumentCollatorFactory.fromConfig(config, {
35
+ ...options,
36
+ discovery,
37
+ logger: backendCommon.loggerToWinstonLogger(logger)
38
+ })
39
+ });
40
+ }
41
+ });
42
+ }
43
+ })
44
+ );
45
+
46
+ exports.searchModuleExploreCollator = searchModuleExploreCollator;
47
+ //# 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 Explore modules.\n */\n\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { TaskScheduleDefinition } from '@backstage/backend-tasks';\nimport { loggerToWinstonLogger } from '@backstage/backend-common';\nimport { searchIndexRegistryExtensionPoint } from '@backstage/plugin-search-backend-node/alpha';\n\nimport {\n ToolDocumentCollatorFactory,\n ToolDocumentCollatorFactoryOptions,\n} from '@backstage/plugin-search-backend-module-explore';\n\n/**\n * @alpha\n * Options for {@link searchModuleExploreCollator}.\n */\nexport type SearchModuleExploreCollatorOptions = Omit<\n ToolDocumentCollatorFactoryOptions,\n 'logger' | 'discovery'\n> & {\n schedule?: TaskScheduleDefinition;\n};\n\n/**\n * @alpha\n * Search backend module for the Explore index.\n */\nexport const searchModuleExploreCollator = createBackendModule(\n (options?: SearchModuleExploreCollatorOptions) => ({\n moduleId: 'exploreCollator',\n pluginId: 'search',\n register(env) {\n env.registerInit({\n deps: {\n config: coreServices.config,\n logger: coreServices.logger,\n discovery: coreServices.discovery,\n scheduler: coreServices.scheduler,\n indexRegistry: searchIndexRegistryExtensionPoint,\n },\n async init({ config, logger, discovery, scheduler, indexRegistry }) {\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: ToolDocumentCollatorFactory.fromConfig(config, {\n ...options,\n discovery,\n logger: loggerToWinstonLogger(logger),\n }),\n });\n },\n });\n },\n }),\n);\n"],"names":["createBackendModule","coreServices","searchIndexRegistryExtensionPoint","ToolDocumentCollatorFactory","loggerToWinstonLogger"],"mappings":";;;;;;;;;AAiDO,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,QAAQA,6BAAa,CAAA,MAAA;AAAA,UACrB,WAAWA,6BAAa,CAAA,SAAA;AAAA,UACxB,WAAWA,6BAAa,CAAA,SAAA;AAAA,UACxB,aAAe,EAAAC,uCAAA;AAAA,SACjB;AAAA,QACA,MAAM,KAAK,EAAE,MAAA,EAAQ,QAAQ,SAAW,EAAA,SAAA,EAAW,eAAiB,EAAA;AA9D5E,UAAA,IAAA,EAAA,CAAA;AA+DU,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,4DAA4B,CAAA,UAAA,CAAW,MAAQ,EAAA;AAAA,cACtD,GAAG,OAAA;AAAA,cACH,SAAA;AAAA,cACA,MAAA,EAAQC,oCAAsB,MAAM,CAAA;AAAA,aACrC,CAAA;AAAA,WACF,CAAA,CAAA;AAAA,SACH;AAAA,OACD,CAAA,CAAA;AAAA,KACH;AAAA,GACF,CAAA;AACF;;;;"}
@@ -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 { ToolDocumentCollatorFactoryOptions } from '@backstage/plugin-search-backend-module-explore';
4
+
5
+ /**
6
+ * @alpha
7
+ * Options for {@link searchModuleExploreCollator}.
8
+ */
9
+ declare type SearchModuleExploreCollatorOptions = Omit<ToolDocumentCollatorFactoryOptions, 'logger' | 'discovery'> & {
10
+ schedule?: TaskScheduleDefinition;
11
+ };
12
+ /**
13
+ * @alpha
14
+ * Search backend module for the Explore index.
15
+ */
16
+ declare const searchModuleExploreCollator: (options?: SearchModuleExploreCollatorOptions | undefined) => _backstage_backend_plugin_api.BackendFeature;
17
+
18
+ export { SearchModuleExploreCollatorOptions, searchModuleExploreCollator };
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var fetch = require('node-fetch');
6
+ var stream = require('stream');
7
+
8
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
+
10
+ var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
11
+
12
+ class ToolDocumentCollatorFactory {
13
+ constructor(options) {
14
+ this.type = "tools";
15
+ this.discovery = options.discovery;
16
+ this.logger = options.logger;
17
+ }
18
+ static fromConfig(_config, options) {
19
+ return new ToolDocumentCollatorFactory(options);
20
+ }
21
+ async getCollator() {
22
+ return stream.Readable.from(this.execute());
23
+ }
24
+ async *execute() {
25
+ this.logger.info("Starting collation of explore tools");
26
+ const tools = await this.fetchTools();
27
+ for (const tool of tools) {
28
+ yield {
29
+ ...tool,
30
+ text: tool.description,
31
+ location: tool.url
32
+ };
33
+ }
34
+ this.logger.info("Finished collation of explore tools");
35
+ }
36
+ async fetchTools() {
37
+ const baseUrl = await this.discovery.getBaseUrl("explore");
38
+ const response = await fetch__default["default"](`${baseUrl}/tools`);
39
+ if (!response.ok) {
40
+ throw new Error(
41
+ `Failed to explore fetch tools, ${response.status}: ${response.statusText}`
42
+ );
43
+ }
44
+ const data = await response.json();
45
+ return data.tools;
46
+ }
47
+ }
48
+
49
+ exports.ToolDocumentCollatorFactory = ToolDocumentCollatorFactory;
50
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/collators/ToolDocumentCollatorFactory.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 { PluginEndpointDiscovery } from '@backstage/backend-common';\nimport { Config } from '@backstage/config';\nimport { ExploreTool } from '@backstage/plugin-explore-common';\nimport {\n DocumentCollatorFactory,\n IndexableDocument,\n} from '@backstage/plugin-search-common';\nimport fetch from 'node-fetch';\nimport { Readable } from 'stream';\nimport { Logger } from 'winston';\n\n/**\n * Extended IndexableDocument with explore tool specific properties\n *\n * @public\n */\nexport interface ToolDocument extends IndexableDocument, ExploreTool {}\n\n/**\n * The options for the {@link ToolDocumentCollatorFactory}.\n *\n * @public\n */\nexport type ToolDocumentCollatorFactoryOptions = {\n discovery: PluginEndpointDiscovery;\n logger: Logger;\n};\n\n/**\n * Search collator responsible for collecting explore tools to index.\n *\n * @public\n */\nexport class ToolDocumentCollatorFactory implements DocumentCollatorFactory {\n public readonly type: string = 'tools';\n\n private readonly discovery: PluginEndpointDiscovery;\n private readonly logger: Logger;\n\n private constructor(options: ToolDocumentCollatorFactoryOptions) {\n this.discovery = options.discovery;\n this.logger = options.logger;\n }\n\n static fromConfig(\n _config: Config,\n options: ToolDocumentCollatorFactoryOptions,\n ) {\n return new ToolDocumentCollatorFactory(options);\n }\n\n async getCollator() {\n return Readable.from(this.execute());\n }\n\n async *execute(): AsyncGenerator<ToolDocument> {\n this.logger.info('Starting collation of explore tools');\n\n const tools = await this.fetchTools();\n\n for (const tool of tools) {\n yield {\n ...tool,\n text: tool.description,\n location: tool.url,\n };\n }\n\n this.logger.info('Finished collation of explore tools');\n }\n\n private async fetchTools() {\n const baseUrl = await this.discovery.getBaseUrl('explore');\n const response = await fetch(`${baseUrl}/tools`);\n\n if (!response.ok) {\n throw new Error(\n `Failed to explore fetch tools, ${response.status}: ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n return data.tools;\n }\n}\n"],"names":["Readable","fetch"],"mappings":";;;;;;;;;;;AAiDO,MAAM,2BAA+D,CAAA;AAAA,EAMlE,YAAY,OAA6C,EAAA;AALjE,IAAA,IAAA,CAAgB,IAAe,GAAA,OAAA,CAAA;AAM7B,IAAA,IAAA,CAAK,YAAY,OAAQ,CAAA,SAAA,CAAA;AACzB,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA,CAAA;AAAA,GACxB;AAAA,EAEA,OAAO,UACL,CAAA,OAAA,EACA,OACA,EAAA;AACA,IAAO,OAAA,IAAI,4BAA4B,OAAO,CAAA,CAAA;AAAA,GAChD;AAAA,EAEA,MAAM,WAAc,GAAA;AAClB,IAAA,OAAOA,eAAS,CAAA,IAAA,CAAK,IAAK,CAAA,OAAA,EAAS,CAAA,CAAA;AAAA,GACrC;AAAA,EAEA,OAAO,OAAwC,GAAA;AAC7C,IAAK,IAAA,CAAA,MAAA,CAAO,KAAK,qCAAqC,CAAA,CAAA;AAEtD,IAAM,MAAA,KAAA,GAAQ,MAAM,IAAA,CAAK,UAAW,EAAA,CAAA;AAEpC,IAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACxB,MAAM,MAAA;AAAA,QACJ,GAAG,IAAA;AAAA,QACH,MAAM,IAAK,CAAA,WAAA;AAAA,QACX,UAAU,IAAK,CAAA,GAAA;AAAA,OACjB,CAAA;AAAA,KACF;AAEA,IAAK,IAAA,CAAA,MAAA,CAAO,KAAK,qCAAqC,CAAA,CAAA;AAAA,GACxD;AAAA,EAEA,MAAc,UAAa,GAAA;AACzB,IAAA,MAAM,OAAU,GAAA,MAAM,IAAK,CAAA,SAAA,CAAU,WAAW,SAAS,CAAA,CAAA;AACzD,IAAA,MAAM,QAAW,GAAA,MAAMC,yBAAM,CAAA,CAAA,EAAG,OAAe,CAAA,MAAA,CAAA,CAAA,CAAA;AAE/C,IAAI,IAAA,CAAC,SAAS,EAAI,EAAA;AAChB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,+BAAA,EAAkC,QAAS,CAAA,MAAA,CAAA,EAAA,EAAW,QAAS,CAAA,UAAA,CAAA,CAAA;AAAA,OACjE,CAAA;AAAA,KACF;AAEA,IAAM,MAAA,IAAA,GAAO,MAAM,QAAA,CAAS,IAAK,EAAA,CAAA;AACjC,IAAA,OAAO,IAAK,CAAA,KAAA,CAAA;AAAA,GACd;AACF;;;;"}
@@ -0,0 +1,41 @@
1
+ /// <reference types="node" />
2
+ import { PluginEndpointDiscovery } from '@backstage/backend-common';
3
+ import { Config } from '@backstage/config';
4
+ import { ExploreTool } from '@backstage/plugin-explore-common';
5
+ import { IndexableDocument, DocumentCollatorFactory } from '@backstage/plugin-search-common';
6
+ import { Readable } from 'stream';
7
+ import { Logger } from 'winston';
8
+
9
+ /**
10
+ * Extended IndexableDocument with explore tool specific properties
11
+ *
12
+ * @public
13
+ */
14
+ interface ToolDocument extends IndexableDocument, ExploreTool {
15
+ }
16
+ /**
17
+ * The options for the {@link ToolDocumentCollatorFactory}.
18
+ *
19
+ * @public
20
+ */
21
+ declare type ToolDocumentCollatorFactoryOptions = {
22
+ discovery: PluginEndpointDiscovery;
23
+ logger: Logger;
24
+ };
25
+ /**
26
+ * Search collator responsible for collecting explore tools to index.
27
+ *
28
+ * @public
29
+ */
30
+ declare class ToolDocumentCollatorFactory implements DocumentCollatorFactory {
31
+ readonly type: string;
32
+ private readonly discovery;
33
+ private readonly logger;
34
+ private constructor();
35
+ static fromConfig(_config: Config, options: ToolDocumentCollatorFactoryOptions): ToolDocumentCollatorFactory;
36
+ getCollator(): Promise<Readable>;
37
+ execute(): AsyncGenerator<ToolDocument>;
38
+ private fetchTools;
39
+ }
40
+
41
+ export { ToolDocument, ToolDocumentCollatorFactory, ToolDocumentCollatorFactoryOptions };
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@backstage/plugin-search-backend-module-explore",
3
+ "description": "A module for the search backend that exports explore 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/config": "^1.0.7",
41
+ "@backstage/plugin-explore-common": "^0.0.1",
42
+ "@backstage/plugin-search-backend-node": "^0.0.0-nightly-20230323021924",
43
+ "@backstage/plugin-search-common": "^1.2.2",
44
+ "node-fetch": "^2.6.7",
45
+ "winston": "^3.2.1"
46
+ },
47
+ "devDependencies": {
48
+ "@backstage/backend-test-utils": "^0.0.0-nightly-20230323021924",
49
+ "@backstage/cli": "^0.0.0-nightly-20230323021924"
50
+ },
51
+ "files": [
52
+ "dist",
53
+ "alpha"
54
+ ]
55
+ }