@backstage/plugin-search-backend-node 0.4.6 → 0.4.7

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @backstage/plugin-search-backend-node
2
2
 
3
+ ## 0.4.7
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix for the previous release with missing type declarations.
8
+ - Updated dependencies
9
+ - @backstage/search-common@0.2.4
10
+
3
11
  ## 0.4.6
4
12
 
5
13
  ### Patch Changes
@@ -0,0 +1,107 @@
1
+ import { DocumentCollator, DocumentDecorator, SearchEngine, DocumentTypeInfo, IndexableDocument, QueryTranslator, SearchQuery, SearchResultSet } from '@backstage/search-common';
2
+ export { SearchEngine } from '@backstage/search-common';
3
+ import { Logger } from 'winston';
4
+ import lunr from 'lunr';
5
+
6
+ /**
7
+ * Parameters required to register a collator.
8
+ */
9
+ interface RegisterCollatorParameters {
10
+ /**
11
+ * The default interval (in seconds) that the provided collator will be called (can be overridden in config).
12
+ */
13
+ defaultRefreshIntervalSeconds: number;
14
+ /**
15
+ * The collator class responsible for returning all documents of the given type.
16
+ */
17
+ collator: DocumentCollator;
18
+ }
19
+ /**
20
+ * Parameters required to register a decorator
21
+ */
22
+ interface RegisterDecoratorParameters {
23
+ /**
24
+ * The decorator class responsible for appending or modifying documents of the given type(s).
25
+ */
26
+ decorator: DocumentDecorator;
27
+ }
28
+
29
+ declare type IndexBuilderOptions = {
30
+ searchEngine: SearchEngine;
31
+ logger: Logger;
32
+ };
33
+ declare class IndexBuilder {
34
+ private collators;
35
+ private decorators;
36
+ private documentTypes;
37
+ private searchEngine;
38
+ private logger;
39
+ constructor({ logger, searchEngine }: IndexBuilderOptions);
40
+ getSearchEngine(): SearchEngine;
41
+ getDocumentTypes(): Record<string, DocumentTypeInfo>;
42
+ /**
43
+ * Makes the index builder aware of a collator that should be executed at the
44
+ * given refresh interval.
45
+ */
46
+ addCollator({ collator, defaultRefreshIntervalSeconds, }: RegisterCollatorParameters): void;
47
+ /**
48
+ * Makes the index builder aware of a decorator. If no types are provided on
49
+ * the decorator, it will be applied to documents from all known collators,
50
+ * otherwise it will only be applied to documents of the given types.
51
+ */
52
+ addDecorator({ decorator }: RegisterDecoratorParameters): void;
53
+ /**
54
+ * Compiles collators and decorators into tasks, which are added to a
55
+ * scheduler returned to the caller.
56
+ */
57
+ build(): Promise<{
58
+ scheduler: Scheduler;
59
+ }>;
60
+ }
61
+
62
+ /**
63
+ * TODO: coordination, error handling
64
+ */
65
+ declare class Scheduler {
66
+ private logger;
67
+ private schedule;
68
+ private runningTasks;
69
+ constructor({ logger }: {
70
+ logger: Logger;
71
+ });
72
+ /**
73
+ * Adds each task and interval to the schedule.
74
+ * When running the tasks, the scheduler waits at least for the time specified
75
+ * in the interval once the task was completed, before running it again.
76
+ */
77
+ addToSchedule(task: Function, interval: number): void;
78
+ /**
79
+ * Starts the scheduling process for each task
80
+ */
81
+ start(): void;
82
+ /**
83
+ * Stop all scheduled tasks.
84
+ */
85
+ stop(): void;
86
+ }
87
+
88
+ declare type ConcreteLunrQuery = {
89
+ lunrQueryBuilder: lunr.Index.QueryBuilder;
90
+ documentTypes?: string[];
91
+ pageSize: number;
92
+ };
93
+ declare type LunrQueryTranslator = (query: SearchQuery) => ConcreteLunrQuery;
94
+ declare class LunrSearchEngine implements SearchEngine {
95
+ protected lunrIndices: Record<string, lunr.Index>;
96
+ protected docStore: Record<string, IndexableDocument>;
97
+ protected logger: Logger;
98
+ constructor({ logger }: {
99
+ logger: Logger;
100
+ });
101
+ protected translator: QueryTranslator;
102
+ setTranslator(translator: LunrQueryTranslator): void;
103
+ index(type: string, documents: IndexableDocument[]): Promise<void>;
104
+ query(query: SearchQuery): Promise<SearchResultSet>;
105
+ }
106
+
107
+ export { IndexBuilder, LunrSearchEngine, Scheduler };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/plugin-search-backend-node",
3
3
  "description": "A library for Backstage backend plugins that want to interact with the search backend plugin",
4
- "version": "0.4.6",
4
+ "version": "0.4.7",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -23,17 +23,17 @@
23
23
  "clean": "backstage-cli package clean"
24
24
  },
25
25
  "dependencies": {
26
- "@backstage/search-common": "^0.2.3",
26
+ "@backstage/search-common": "^0.2.4",
27
27
  "@types/lunr": "^2.3.3",
28
28
  "lunr": "^2.3.9",
29
29
  "winston": "^3.2.1"
30
30
  },
31
31
  "devDependencies": {
32
- "@backstage/backend-common": "^0.10.8",
32
+ "@backstage/backend-common": "^0.10.9",
33
33
  "@backstage/cli": "^0.14.0"
34
34
  },
35
35
  "files": [
36
36
  "dist"
37
37
  ],
38
- "gitHead": "4805c3d13ce9bfc369e53c271b1b95e722b3b4dc"
38
+ "gitHead": "e244b348c473700e7d5e5fbcef38bd9f9fd1d0ba"
39
39
  }