@backstage/plugin-search-backend-node 1.0.0 → 1.0.2-next.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 CHANGED
@@ -1,5 +1,32 @@
1
1
  # @backstage/plugin-search-backend-node
2
2
 
3
+ ## 1.0.2-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 3f739be9d9: Minor API signatures cleanup
8
+ - Updated dependencies
9
+ - @backstage/backend-common@0.15.1-next.0
10
+ - @backstage/backend-tasks@0.3.5-next.0
11
+ - @backstage/plugin-permission-common@0.6.4-next.0
12
+ - @backstage/plugin-search-common@1.0.1-next.0
13
+
14
+ ## 1.0.1
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies
19
+ - @backstage/backend-common@0.15.0
20
+ - @backstage/backend-tasks@0.3.4
21
+
22
+ ## 1.0.1-next.0
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies
27
+ - @backstage/backend-common@0.15.0-next.0
28
+ - @backstage/backend-tasks@0.3.4-next.0
29
+
3
30
  ## 1.0.0
4
31
 
5
32
  ### Major Changes
package/dist/index.cjs.js CHANGED
@@ -14,15 +14,18 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
14
14
  var lunr__default = /*#__PURE__*/_interopDefaultLegacy(lunr);
15
15
 
16
16
  class Scheduler {
17
- constructor({ logger }) {
18
- this.logger = logger;
17
+ constructor(options) {
18
+ this.logger = options.logger;
19
19
  this.schedule = {};
20
20
  this.abortController = new nodeAbortController.AbortController();
21
21
  this.isRunning = false;
22
22
  }
23
- addToSchedule({ id, task, scheduledRunner }) {
23
+ addToSchedule(options) {
24
+ const { id, task, scheduledRunner } = options;
24
25
  if (this.isRunning) {
25
- throw new Error("Cannot add task to schedule that has already been started.");
26
+ throw new Error(
27
+ "Cannot add task to schedule that has already been started."
28
+ );
26
29
  }
27
30
  if (this.schedule[id]) {
28
31
  throw new Error(`Task with id ${id} already exists.`);
@@ -49,12 +52,12 @@ class Scheduler {
49
52
  }
50
53
 
51
54
  class IndexBuilder {
52
- constructor({ logger, searchEngine }) {
55
+ constructor(options) {
53
56
  this.collators = {};
54
57
  this.decorators = {};
55
58
  this.documentTypes = {};
56
- this.logger = logger;
57
- this.searchEngine = searchEngine;
59
+ this.logger = options.logger;
60
+ this.searchEngine = options.searchEngine;
58
61
  }
59
62
  getSearchEngine() {
60
63
  return this.searchEngine;
@@ -62,8 +65,11 @@ class IndexBuilder {
62
65
  getDocumentTypes() {
63
66
  return this.documentTypes;
64
67
  }
65
- addCollator({ factory, schedule }) {
66
- this.logger.info(`Added ${factory.constructor.name} collator factory for type ${factory.type}`);
68
+ addCollator(options) {
69
+ const { factory, schedule } = options;
70
+ this.logger.info(
71
+ `Added ${factory.constructor.name} collator factory for type ${factory.type}`
72
+ );
67
73
  this.collators[factory.type] = {
68
74
  factory,
69
75
  schedule
@@ -72,9 +78,14 @@ class IndexBuilder {
72
78
  visibilityPermission: factory.visibilityPermission
73
79
  };
74
80
  }
75
- addDecorator({ factory }) {
81
+ addDecorator(options) {
82
+ const { factory } = options;
76
83
  const types = factory.types || ["*"];
77
- this.logger.info(`Added decorator ${factory.constructor.name} to types ${types.join(", ")}`);
84
+ this.logger.info(
85
+ `Added decorator ${factory.constructor.name} to types ${types.join(
86
+ ", "
87
+ )}`
88
+ );
78
89
  types.forEach((type) => {
79
90
  if (this.decorators.hasOwnProperty(type)) {
80
91
  this.decorators[type].push(factory);
@@ -93,23 +104,34 @@ class IndexBuilder {
93
104
  scheduledRunner: this.collators[type].schedule,
94
105
  task: async () => {
95
106
  const collator = await this.collators[type].factory.getCollator();
96
- this.logger.info(`Collating documents for ${type} via ${this.collators[type].factory.constructor.name}`);
97
- const decorators = await Promise.all((this.decorators["*"] || []).concat(this.decorators[type] || []).map(async (factory) => {
98
- const decorator = await factory.getDecorator();
99
- this.logger.info(`Attached decorator via ${factory.constructor.name} to ${type} index pipeline.`);
100
- return decorator;
101
- }));
107
+ this.logger.info(
108
+ `Collating documents for ${type} via ${this.collators[type].factory.constructor.name}`
109
+ );
110
+ const decorators = await Promise.all(
111
+ (this.decorators["*"] || []).concat(this.decorators[type] || []).map(async (factory) => {
112
+ const decorator = await factory.getDecorator();
113
+ this.logger.info(
114
+ `Attached decorator via ${factory.constructor.name} to ${type} index pipeline.`
115
+ );
116
+ return decorator;
117
+ })
118
+ );
102
119
  const indexer = await this.searchEngine.getIndexer(type);
103
120
  return new Promise((resolve, reject) => {
104
- stream.pipeline([collator, ...decorators, indexer], (error) => {
105
- if (error) {
106
- this.logger.error(`Collating documents for ${type} failed: ${error}`);
107
- reject(error);
108
- } else {
109
- this.logger.info(`Collating documents for ${type} succeeded`);
110
- resolve();
121
+ stream.pipeline(
122
+ [collator, ...decorators, indexer],
123
+ (error) => {
124
+ if (error) {
125
+ this.logger.error(
126
+ `Collating documents for ${type} failed: ${error}`
127
+ );
128
+ reject(error);
129
+ } else {
130
+ this.logger.info(`Collating documents for ${type} succeeded`);
131
+ resolve();
132
+ }
111
133
  }
112
- });
134
+ );
113
135
  });
114
136
  }
115
137
  });
@@ -129,12 +151,20 @@ class NewlineDelimitedJsonCollatorFactory {
129
151
  this.visibilityPermission = visibilityPermission;
130
152
  }
131
153
  static fromConfig(_config, options) {
132
- return new NewlineDelimitedJsonCollatorFactory(options.type, options.searchPattern, options.reader, options.logger, options.visibilityPermission);
154
+ return new NewlineDelimitedJsonCollatorFactory(
155
+ options.type,
156
+ options.searchPattern,
157
+ options.reader,
158
+ options.logger,
159
+ options.visibilityPermission
160
+ );
133
161
  }
134
162
  async lastUrl() {
135
163
  var _a;
136
164
  try {
137
- this.logger.info(`Attempting to find latest .ndjson matching ${this.searchPattern}`);
165
+ this.logger.info(
166
+ `Attempting to find latest .ndjson matching ${this.searchPattern}`
167
+ );
138
168
  const { files } = await this.reader.search(this.searchPattern);
139
169
  const candidates = files.filter((file) => file.url.endsWith(".ndjson")).sort((a, b) => a.url.localeCompare(b.url)).reverse();
140
170
  return (_a = candidates[0]) == null ? void 0 : _a.url;
@@ -308,7 +338,7 @@ class LunrSearchEngineIndexer extends BatchSearchEngineIndexer {
308
338
  }
309
339
 
310
340
  class LunrSearchEngine {
311
- constructor({ logger }) {
341
+ constructor(options) {
312
342
  this.lunrIndices = {};
313
343
  this.translator = ({
314
344
  term,
@@ -345,7 +375,9 @@ class LunrSearchEngine {
345
375
  fields: [field]
346
376
  });
347
377
  } else if (Array.isArray(value)) {
348
- this.logger.warn(`Non-scalar filter value used for field ${field}. Consider using a different Search Engine for better results.`);
378
+ this.logger.warn(
379
+ `Non-scalar filter value used for field ${field}. Consider using a different Search Engine for better results.`
380
+ );
349
381
  q.term(lunr__default["default"].tokenizer(value), {
350
382
  presence: lunr__default["default"].Query.presence.OPTIONAL,
351
383
  fields: [field]
@@ -360,7 +392,7 @@ class LunrSearchEngine {
360
392
  pageSize
361
393
  };
362
394
  };
363
- this.logger = logger;
395
+ this.logger = options.logger;
364
396
  this.docStore = {};
365
397
  const uuidTag = uuid.v4();
366
398
  this.highlightPreTag = `<${uuidTag}>`;
@@ -378,20 +410,28 @@ class LunrSearchEngine {
378
410
  return indexer;
379
411
  }
380
412
  async query(query) {
381
- const { lunrQueryBuilder, documentTypes, pageSize } = this.translator(query);
413
+ const { lunrQueryBuilder, documentTypes, pageSize } = this.translator(
414
+ query
415
+ );
382
416
  const results = [];
383
- const indexKeys = Object.keys(this.lunrIndices).filter((type) => !documentTypes || documentTypes.includes(type));
417
+ const indexKeys = Object.keys(this.lunrIndices).filter(
418
+ (type) => !documentTypes || documentTypes.includes(type)
419
+ );
384
420
  if ((documentTypes == null ? void 0 : documentTypes.length) && !indexKeys.length) {
385
- throw new MissingIndexError(`Missing index for ${documentTypes == null ? void 0 : documentTypes.toString()}. This could be because the index hasn't been created yet or there was a problem during index creation.`);
421
+ throw new MissingIndexError(
422
+ `Missing index for ${documentTypes == null ? void 0 : documentTypes.toString()}. This could be because the index hasn't been created yet or there was a problem during index creation.`
423
+ );
386
424
  }
387
425
  indexKeys.forEach((type) => {
388
426
  try {
389
- results.push(...this.lunrIndices[type].query(lunrQueryBuilder).map((result) => {
390
- return {
391
- result,
392
- type
393
- };
394
- }));
427
+ results.push(
428
+ ...this.lunrIndices[type].query(lunrQueryBuilder).map((result) => {
429
+ return {
430
+ result,
431
+ type
432
+ };
433
+ })
434
+ );
395
435
  } catch (err) {
396
436
  if (err instanceof Error && err.message.startsWith("unrecognised field")) {
397
437
  return;
@@ -447,21 +487,26 @@ function parseHighlightFields({
447
487
  doc,
448
488
  positionMetadata
449
489
  }) {
450
- const highlightFieldPositions = Object.values(positionMetadata).reduce((fieldPositions, metadata) => {
451
- Object.keys(metadata).map((fieldKey) => {
452
- var _a;
453
- fieldPositions[fieldKey] = (_a = fieldPositions[fieldKey]) != null ? _a : [];
454
- fieldPositions[fieldKey].push(...metadata[fieldKey].position);
455
- });
456
- return fieldPositions;
457
- }, {});
458
- return Object.fromEntries(Object.entries(highlightFieldPositions).map(([field, positions]) => {
459
- positions.sort((a, b) => b[0] - a[0]);
460
- const highlightedField = positions.reduce((content, pos) => {
461
- return `${content.substring(0, pos[0])}${preTag}${content.substring(pos[0], pos[0] + pos[1])}${postTag}${content.substring(pos[0] + pos[1])}`;
462
- }, doc[field]);
463
- return [field, highlightedField];
464
- }));
490
+ const highlightFieldPositions = Object.values(positionMetadata).reduce(
491
+ (fieldPositions, metadata) => {
492
+ Object.keys(metadata).map((fieldKey) => {
493
+ var _a;
494
+ fieldPositions[fieldKey] = (_a = fieldPositions[fieldKey]) != null ? _a : [];
495
+ fieldPositions[fieldKey].push(...metadata[fieldKey].position);
496
+ });
497
+ return fieldPositions;
498
+ },
499
+ {}
500
+ );
501
+ return Object.fromEntries(
502
+ Object.entries(highlightFieldPositions).map(([field, positions]) => {
503
+ positions.sort((a, b) => b[0] - a[0]);
504
+ const highlightedField = positions.reduce((content, pos) => {
505
+ return `${content.substring(0, pos[0])}${preTag}${content.substring(pos[0], pos[0] + pos[1])}${postTag}${content.substring(pos[0] + pos[1])}`;
506
+ }, doc[field]);
507
+ return [field, highlightedField];
508
+ })
509
+ );
465
510
  }
466
511
 
467
512
  class TestPipeline {
@@ -484,7 +529,9 @@ class TestPipeline {
484
529
  if (subject.readable || subject instanceof stream.Readable) {
485
530
  return new TestPipeline({ collator: subject });
486
531
  }
487
- throw new Error("Unknown test subject: are you passing a readable, writable, or transform stream?");
532
+ throw new Error(
533
+ "Unknown test subject: are you passing a readable, writable, or transform stream?"
534
+ );
488
535
  }
489
536
  withDocuments(documents) {
490
537
  if (this.collator) {
@@ -504,7 +551,9 @@ class TestPipeline {
504
551
  async execute() {
505
552
  const documents = [];
506
553
  if (!this.collator) {
507
- throw new Error("Cannot execute pipeline without a collator or documents");
554
+ throw new Error(
555
+ "Cannot execute pipeline without a collator or documents"
556
+ );
508
557
  }
509
558
  if (!this.indexer) {
510
559
  this.indexer = new stream.Writable({ objectMode: true });
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/Scheduler.ts","../src/IndexBuilder.ts","../src/collators/NewlineDelimitedJsonCollatorFactory.ts","../src/errors.ts","../src/indexing/BatchSearchEngineIndexer.ts","../src/indexing/DecoratorBase.ts","../src/engines/LunrSearchEngineIndexer.ts","../src/engines/LunrSearchEngine.ts","../src/test-utils/TestPipeline.ts"],"sourcesContent":["/*\n * Copyright 2021 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 { AbortController } from 'node-abort-controller';\nimport { Logger } from 'winston';\nimport { TaskFunction, TaskRunner } from '@backstage/backend-tasks';\n\ntype TaskEnvelope = {\n task: TaskFunction;\n scheduledRunner: TaskRunner;\n};\n\n/**\n * ScheduleTaskParameters\n * @public\n */\nexport type ScheduleTaskParameters = {\n id: string;\n task: TaskFunction;\n scheduledRunner: TaskRunner;\n};\n\n/**\n * Scheduler responsible for all search tasks.\n * @public\n */\nexport class Scheduler {\n private logger: Logger;\n private schedule: { [id: string]: TaskEnvelope };\n private abortController: AbortController;\n private isRunning: boolean;\n\n constructor({ logger }: { logger: Logger }) {\n this.logger = logger;\n this.schedule = {};\n this.abortController = new AbortController();\n this.isRunning = false;\n }\n\n /**\n * Adds each task and interval to the schedule.\n * When running the tasks, the scheduler waits at least for the time specified\n * in the interval once the task was completed, before running it again.\n */\n addToSchedule({ id, task, scheduledRunner }: ScheduleTaskParameters) {\n if (this.isRunning) {\n throw new Error(\n 'Cannot add task to schedule that has already been started.',\n );\n }\n\n if (this.schedule[id]) {\n throw new Error(`Task with id ${id} already exists.`);\n }\n\n this.schedule[id] = { task, scheduledRunner };\n }\n\n /**\n * Starts the scheduling process for each task\n */\n start() {\n this.logger.info('Starting all scheduled search tasks.');\n this.isRunning = true;\n Object.keys(this.schedule).forEach(id => {\n const { task, scheduledRunner } = this.schedule[id];\n scheduledRunner.run({\n id,\n fn: task,\n signal: this.abortController.signal,\n });\n });\n }\n\n /**\n * Stop all scheduled tasks.\n */\n stop() {\n this.logger.info('Stopping all scheduled search tasks.');\n this.abortController.abort();\n this.isRunning = false;\n }\n}\n","/*\n * Copyright 2021 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 */\nimport {\n DocumentDecoratorFactory,\n DocumentTypeInfo,\n SearchEngine,\n} from '@backstage/plugin-search-common';\nimport { Transform, pipeline } from 'stream';\nimport { Logger } from 'winston';\nimport { Scheduler } from './Scheduler';\nimport {\n IndexBuilderOptions,\n RegisterCollatorParameters,\n RegisterDecoratorParameters,\n} from './types';\n\n/**\n * Used for adding collators, decorators and compile them into tasks which are added to a scheduler returned to the caller.\n * @public\n */\nexport class IndexBuilder {\n private collators: Record<string, RegisterCollatorParameters>;\n private decorators: Record<string, DocumentDecoratorFactory[]>;\n private documentTypes: Record<string, DocumentTypeInfo>;\n private searchEngine: SearchEngine;\n private logger: Logger;\n\n constructor({ logger, searchEngine }: IndexBuilderOptions) {\n this.collators = {};\n this.decorators = {};\n this.documentTypes = {};\n this.logger = logger;\n this.searchEngine = searchEngine;\n }\n\n /**\n * Responsible for returning the registered search engine.\n */\n getSearchEngine(): SearchEngine {\n return this.searchEngine;\n }\n\n /**\n * Responsible for returning the registered document types.\n */\n getDocumentTypes(): Record<string, DocumentTypeInfo> {\n return this.documentTypes;\n }\n\n /**\n * Makes the index builder aware of a collator that should be executed at the\n * given refresh interval.\n */\n addCollator({ factory, schedule }: RegisterCollatorParameters): void {\n this.logger.info(\n `Added ${factory.constructor.name} collator factory for type ${factory.type}`,\n );\n this.collators[factory.type] = {\n factory,\n schedule,\n };\n this.documentTypes[factory.type] = {\n visibilityPermission: factory.visibilityPermission,\n };\n }\n\n /**\n * Makes the index builder aware of a decorator. If no types are provided on\n * the decorator, it will be applied to documents from all known collators,\n * otherwise it will only be applied to documents of the given types.\n */\n addDecorator({ factory }: RegisterDecoratorParameters): void {\n const types = factory.types || ['*'];\n this.logger.info(\n `Added decorator ${factory.constructor.name} to types ${types.join(\n ', ',\n )}`,\n );\n types.forEach(type => {\n if (this.decorators.hasOwnProperty(type)) {\n this.decorators[type].push(factory);\n } else {\n this.decorators[type] = [factory];\n }\n });\n }\n\n /**\n * Compiles collators and decorators into tasks, which are added to a\n * scheduler returned to the caller.\n */\n async build(): Promise<{ scheduler: Scheduler }> {\n const scheduler = new Scheduler({\n logger: this.logger,\n });\n\n Object.keys(this.collators).forEach(type => {\n scheduler.addToSchedule({\n id: `search_index_${type.replace('-', '_').toLocaleLowerCase('en-US')}`,\n scheduledRunner: this.collators[type].schedule,\n task: async () => {\n // Instantiate the collator.\n const collator = await this.collators[type].factory.getCollator();\n this.logger.info(\n `Collating documents for ${type} via ${this.collators[type].factory.constructor.name}`,\n );\n\n // Instantiate all relevant decorators.\n const decorators: Transform[] = await Promise.all(\n (this.decorators['*'] || [])\n .concat(this.decorators[type] || [])\n .map(async factory => {\n const decorator = await factory.getDecorator();\n this.logger.info(\n `Attached decorator via ${factory.constructor.name} to ${type} index pipeline.`,\n );\n return decorator;\n }),\n );\n\n // Instantiate the indexer.\n const indexer = await this.searchEngine.getIndexer(type);\n\n // Compose collator/decorators/indexer into a pipeline\n return new Promise<void>((resolve, reject) => {\n pipeline(\n [collator, ...decorators, indexer],\n (error: NodeJS.ErrnoException | null) => {\n if (error) {\n this.logger.error(\n `Collating documents for ${type} failed: ${error}`,\n );\n reject(error);\n } else {\n // Signal index pipeline completion!\n this.logger.info(`Collating documents for ${type} succeeded`);\n resolve();\n }\n },\n );\n });\n },\n });\n });\n\n return {\n scheduler,\n };\n }\n}\n","/*\n * Copyright 2021 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 { UrlReader } from '@backstage/backend-common';\nimport { Config } from '@backstage/config';\nimport { Permission } from '@backstage/plugin-permission-common';\nimport { DocumentCollatorFactory } from '@backstage/plugin-search-common';\nimport { parse as parseNdjson } from 'ndjson';\nimport { Readable } from 'stream';\nimport { Logger } from 'winston';\n\n/**\n * Options for instansiate NewlineDelimitedJsonCollatorFactory\n * @public\n */\nexport type NewlineDelimitedJsonCollatorFactoryOptions = {\n type: string;\n searchPattern: string;\n reader: UrlReader;\n logger: Logger;\n visibilityPermission?: Permission;\n};\n\n/**\n * Factory class producing a collator that can be used to index documents\n * sourced from the latest newline delimited JSON file matching a given search\n * pattern. \"Latest\" is determined by the name of the file (last alphabetically\n * is considered latest).\n *\n * @remarks\n * The reader provided must implement the `search()` method as well as the\n * `readUrl` method whose response includes the `stream()` method. Naturally,\n * the reader must also be configured to understand the given search pattern.\n *\n * @example\n * Here's an example configuration using Google Cloud Storage, which would\n * return the latest file under the `bucket` GCS bucket with files like\n * `xyz-2021.ndjson` or `xyz-2022.ndjson`.\n * ```ts\n * indexBuilder.addCollator({\n * schedule,\n * factory: NewlineDelimitedJsonCollatorFactory.fromConfig(env.config, {\n * type: 'techdocs',\n * searchPattern: 'https://storage.cloud.google.com/bucket/xyz-*',\n * reader: env.reader,\n * logger: env.logger,\n * })\n * });\n * ```\n *\n * @public\n */\nexport class NewlineDelimitedJsonCollatorFactory\n implements DocumentCollatorFactory\n{\n readonly type: string;\n\n public readonly visibilityPermission: Permission | undefined;\n\n private constructor(\n type: string,\n private readonly searchPattern: string,\n private readonly reader: UrlReader,\n private readonly logger: Logger,\n visibilityPermission: Permission | undefined,\n ) {\n this.type = type;\n this.visibilityPermission = visibilityPermission;\n }\n\n /**\n * Returns a NewlineDelimitedJsonCollatorFactory instance from configuration\n * and a set of options.\n */\n static fromConfig(\n _config: Config,\n options: NewlineDelimitedJsonCollatorFactoryOptions,\n ): NewlineDelimitedJsonCollatorFactory {\n return new NewlineDelimitedJsonCollatorFactory(\n options.type,\n options.searchPattern,\n options.reader,\n options.logger,\n options.visibilityPermission,\n );\n }\n\n /**\n * Returns the \"latest\" URL for the given search pattern (e.g. the one at the\n * end of the list, sorted alphabetically).\n */\n private async lastUrl(): Promise<string | undefined> {\n try {\n // Search for files matching the given pattern, then sort/reverse. The\n // first item in the list will be the \"latest\" file.\n this.logger.info(\n `Attempting to find latest .ndjson matching ${this.searchPattern}`,\n );\n const { files } = await this.reader.search(this.searchPattern);\n const candidates = files\n .filter(file => file.url.endsWith('.ndjson'))\n .sort((a, b) => a.url.localeCompare(b.url))\n .reverse();\n\n return candidates[0]?.url;\n } catch (e) {\n this.logger.error(`Could not search for ${this.searchPattern}`, e);\n throw e;\n }\n }\n\n async getCollator(): Promise<Readable> {\n // Search for files matching the given pattern.\n const lastUrl = await this.lastUrl();\n\n // Abort if no such file could be found.\n if (!lastUrl) {\n const noMatchingFile = `Could not find an .ndjson file matching ${this.searchPattern}`;\n this.logger.error(noMatchingFile);\n throw new Error(noMatchingFile);\n } else {\n this.logger.info(`Using latest .ndjson file ${lastUrl}`);\n }\n\n // Use the UrlReader to try and stream the file.\n const readerResponse = await this.reader.readUrl!(lastUrl);\n const stream = readerResponse.stream!();\n\n // Use ndjson's parser to turn the raw file into an object-mode stream.\n return stream.pipe(parseNdjson());\n }\n}\n","/*\n * Copyright 2021 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 { isError } from '@backstage/errors';\n\n/**\n * Failed to query documents for index that does not exist.\n * @public\n */\nexport class MissingIndexError extends Error {\n /**\n * An inner error that caused this error to be thrown, if any.\n */\n readonly cause?: Error | undefined;\n\n constructor(message?: string, cause?: Error | unknown) {\n super(message);\n\n Error.captureStackTrace?.(this, this.constructor);\n\n this.name = this.constructor.name;\n this.cause = isError(cause) ? cause : undefined;\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 { assertError } from '@backstage/errors';\nimport { IndexableDocument } from '@backstage/plugin-search-common';\nimport { Writable } from 'stream';\n\n/**\n * Options for {@link BatchSearchEngineIndexer}\n * @public\n */\nexport type BatchSearchEngineOptions = {\n batchSize: number;\n};\n\n/**\n * Base class encapsulating batch-based stream processing. Useful as a base\n * class for search engine indexers.\n * @public\n */\nexport abstract class BatchSearchEngineIndexer extends Writable {\n private batchSize: number;\n private currentBatch: IndexableDocument[] = [];\n private initialized: Promise<undefined | Error>;\n\n constructor(options: BatchSearchEngineOptions) {\n super({ objectMode: true });\n this.batchSize = options.batchSize;\n\n // @todo Once node v15 is minimum, convert to _construct implementation.\n this.initialized = new Promise(done => {\n // Necessary to allow concrete implementation classes to construct\n // themselves before calling their initialize() methods.\n setImmediate(async () => {\n try {\n await this.initialize();\n done(undefined);\n } catch (e) {\n assertError(e);\n done(e);\n }\n });\n });\n }\n\n /**\n * Receives an array of indexable documents (of size this.batchSize) which\n * should be written to the search engine. This method won't be called again\n * at least until it resolves.\n */\n public abstract index(documents: IndexableDocument[]): Promise<void>;\n\n /**\n * Any asynchronous setup tasks can be performed here.\n */\n public abstract initialize(): Promise<void>;\n\n /**\n * Any asynchronous teardown tasks can be performed here.\n */\n public abstract finalize(): Promise<void>;\n\n /**\n * Encapsulates batch stream write logic.\n * @internal\n */\n async _write(\n doc: IndexableDocument,\n _e: any,\n done: (error?: Error | null) => void,\n ) {\n // Wait for init before proceeding. Throw error if initialization failed.\n const maybeError = await this.initialized;\n if (maybeError) {\n done(maybeError);\n return;\n }\n\n this.currentBatch.push(doc);\n if (this.currentBatch.length < this.batchSize) {\n done();\n return;\n }\n\n try {\n await this.index(this.currentBatch);\n this.currentBatch = [];\n done();\n } catch (e) {\n assertError(e);\n done(e);\n }\n }\n\n /**\n * Encapsulates finalization and final error handling logic.\n * @internal\n */\n async _final(done: (error?: Error | null) => void) {\n try {\n // Index any remaining documents.\n if (this.currentBatch.length) {\n await this.index(this.currentBatch);\n this.currentBatch = [];\n }\n await this.finalize();\n done();\n } catch (e) {\n assertError(e);\n done(e);\n }\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 { assertError } from '@backstage/errors';\nimport { IndexableDocument } from '@backstage/plugin-search-common';\nimport { Transform } from 'stream';\n\n/**\n * Base class encapsulating simple async transformations. Useful as a base\n * class for Backstage search decorators.\n * @public\n */\nexport abstract class DecoratorBase extends Transform {\n private initialized: Promise<undefined | Error>;\n\n constructor() {\n super({ objectMode: true });\n\n // @todo Once node v15 is minimum, convert to _construct implementation.\n this.initialized = new Promise(done => {\n // Necessary to allow concrete implementation classes to construct\n // themselves before calling their initialize() methods.\n setImmediate(async () => {\n try {\n await this.initialize();\n done(undefined);\n } catch (e) {\n assertError(e);\n done(e);\n }\n });\n });\n }\n\n /**\n * Any asynchronous setup tasks can be performed here.\n */\n public abstract initialize(): Promise<void>;\n\n /**\n * Receives a single indexable document. In your decorate method, you can:\n *\n * - Resolve `undefined` to indicate the record should be omitted.\n * - Resolve a single modified document, which could contain new fields,\n * edited fields, or removed fields.\n * - Resolve an array of indexable documents, if the purpose if the decorator\n * is to convert one document into multiple derivative documents.\n */\n public abstract decorate(\n document: IndexableDocument,\n ): Promise<IndexableDocument | IndexableDocument[] | undefined>;\n\n /**\n * Any asynchronous teardown tasks can be performed here.\n */\n public abstract finalize(): Promise<void>;\n\n /**\n * Encapsulates simple transform stream logic.\n * @internal\n */\n async _transform(\n document: IndexableDocument,\n _: any,\n done: (error?: Error | null) => void,\n ) {\n // Wait for init before proceeding. Throw error if initialization failed.\n const maybeError = await this.initialized;\n if (maybeError) {\n done(maybeError);\n return;\n }\n\n try {\n const decorated = await this.decorate(document);\n\n // If undefined was returned, omit the record and move on.\n if (decorated === undefined) {\n done();\n return;\n }\n\n // If an array of documents was given, push them all.\n if (Array.isArray(decorated)) {\n decorated.forEach(doc => {\n this.push(doc);\n });\n done();\n return;\n }\n\n // Otherwise, just push the decorated document.\n this.push(decorated);\n done();\n } catch (e) {\n assertError(e);\n done(e);\n }\n }\n\n /**\n * Encapsulates finalization and final error handling logic.\n * @internal\n */\n async _final(done: (error?: Error | null) => void) {\n try {\n await this.finalize();\n done();\n } catch (e) {\n assertError(e);\n done(e);\n }\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 { IndexableDocument } from '@backstage/plugin-search-common';\nimport lunr from 'lunr';\nimport { BatchSearchEngineIndexer } from '../indexing';\n\n/**\n * Lunr specific search engine indexer\n * @public\n */\nexport class LunrSearchEngineIndexer extends BatchSearchEngineIndexer {\n private schemaInitialized = false;\n private builder: lunr.Builder;\n private docStore: Record<string, IndexableDocument> = {};\n\n constructor() {\n super({ batchSize: 1000 });\n\n this.builder = new lunr.Builder();\n this.builder.pipeline.add(lunr.trimmer, lunr.stopWordFilter, lunr.stemmer);\n this.builder.searchPipeline.add(lunr.stemmer);\n this.builder.metadataWhitelist = ['position'];\n }\n\n // No async initialization required.\n async initialize(): Promise<void> {}\n async finalize(): Promise<void> {}\n\n async index(documents: IndexableDocument[]): Promise<void> {\n if (!this.schemaInitialized) {\n // Make this lunr index aware of all relevant fields.\n Object.keys(documents[0]).forEach(field => {\n this.builder.field(field);\n });\n\n // Set \"location\" field as reference field\n this.builder.ref('location');\n\n this.schemaInitialized = true;\n }\n\n documents.forEach(document => {\n // Add document to Lunar index\n this.builder.add(document);\n\n // Store documents in memory to be able to look up document using the ref during query time\n // This is not how you should implement your SearchEngine implementation! Do not copy!\n this.docStore[document.location] = document;\n });\n }\n\n buildIndex() {\n return this.builder.build();\n }\n\n getDocumentStore() {\n return this.docStore;\n }\n}\n","/*\n * Copyright 2021 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 IndexableDocument,\n IndexableResultSet,\n SearchQuery,\n QueryTranslator,\n SearchEngine,\n} from '@backstage/plugin-search-common';\nimport { MissingIndexError } from '../errors';\nimport lunr from 'lunr';\nimport { v4 as uuid } from 'uuid';\nimport { Logger } from 'winston';\nimport { LunrSearchEngineIndexer } from './LunrSearchEngineIndexer';\n\n/**\n * Type of translated query for the Lunr Search Engine.\n * @public\n */\nexport type ConcreteLunrQuery = {\n lunrQueryBuilder: lunr.Index.QueryBuilder;\n documentTypes?: string[];\n pageSize: number;\n};\n\ntype LunrResultEnvelope = {\n result: lunr.Index.Result;\n type: string;\n};\n\n/**\n * Translator repsonsible for translating search term and filters to a query that the Lunr Search Engine understands.\n * @public\n */\nexport type LunrQueryTranslator = (query: SearchQuery) => ConcreteLunrQuery;\n\n/**\n * Lunr specific search engine implementation.\n * @public\n */\nexport class LunrSearchEngine implements SearchEngine {\n protected lunrIndices: Record<string, lunr.Index> = {};\n protected docStore: Record<string, IndexableDocument>;\n protected logger: Logger;\n protected highlightPreTag: string;\n protected highlightPostTag: string;\n\n constructor({ logger }: { logger: Logger }) {\n this.logger = logger;\n this.docStore = {};\n const uuidTag = uuid();\n this.highlightPreTag = `<${uuidTag}>`;\n this.highlightPostTag = `</${uuidTag}>`;\n }\n\n protected translator: QueryTranslator = ({\n term,\n filters,\n types,\n }: SearchQuery): ConcreteLunrQuery => {\n const pageSize = 25;\n\n return {\n lunrQueryBuilder: q => {\n const termToken = lunr.tokenizer(term);\n\n // Support for typeahead search is based on https://github.com/olivernn/lunr.js/issues/256#issuecomment-295407852\n // look for an exact match and apply a large positive boost\n q.term(termToken, {\n usePipeline: true,\n boost: 100,\n });\n // look for terms that match the beginning of this term and apply a\n // medium boost\n q.term(termToken, {\n usePipeline: false,\n boost: 10,\n wildcard: lunr.Query.wildcard.TRAILING,\n });\n // look for terms that match with an edit distance of 2 and apply a\n // small boost\n q.term(termToken, {\n usePipeline: false,\n editDistance: 2,\n boost: 1,\n });\n\n if (filters) {\n Object.entries(filters).forEach(([field, fieldValue]) => {\n if (!q.allFields.includes(field)) {\n // Throw for unknown field, as this will be a non match\n throw new Error(`unrecognised field ${field}`);\n }\n // Arrays are poorly supported, but we can make it better for single-item arrays,\n // which should be a common case\n const value =\n Array.isArray(fieldValue) && fieldValue.length === 1\n ? fieldValue[0]\n : fieldValue;\n\n // Require that the given field has the given value\n if (['string', 'number', 'boolean'].includes(typeof value)) {\n q.term(lunr.tokenizer(value?.toString()), {\n presence: lunr.Query.presence.REQUIRED,\n fields: [field],\n });\n } else if (Array.isArray(value)) {\n // Illustrate how multi-value filters could work.\n // But warn that Lurn supports this poorly.\n this.logger.warn(\n `Non-scalar filter value used for field ${field}. Consider using a different Search Engine for better results.`,\n );\n q.term(lunr.tokenizer(value), {\n presence: lunr.Query.presence.OPTIONAL,\n fields: [field],\n });\n } else {\n // Log a warning or something about unknown filter value\n this.logger.warn(`Unknown filter type used on field ${field}`);\n }\n });\n }\n },\n documentTypes: types,\n pageSize,\n };\n };\n\n setTranslator(translator: LunrQueryTranslator) {\n this.translator = translator;\n }\n\n async getIndexer(type: string) {\n const indexer = new LunrSearchEngineIndexer();\n\n indexer.on('close', () => {\n // Once the stream is closed, build the index and store the documents in\n // memory for later retrieval.\n this.lunrIndices[type] = indexer.buildIndex();\n this.docStore = { ...this.docStore, ...indexer.getDocumentStore() };\n });\n\n return indexer;\n }\n\n async query(query: SearchQuery): Promise<IndexableResultSet> {\n const { lunrQueryBuilder, documentTypes, pageSize } = this.translator(\n query,\n ) as ConcreteLunrQuery;\n\n const results: LunrResultEnvelope[] = [];\n\n const indexKeys = Object.keys(this.lunrIndices).filter(\n type => !documentTypes || documentTypes.includes(type),\n );\n\n if (documentTypes?.length && !indexKeys.length) {\n throw new MissingIndexError(\n `Missing index for ${documentTypes?.toString()}. This could be because the index hasn't been created yet or there was a problem during index creation.`,\n );\n }\n\n // Iterate over the filtered list of this.lunrIndex keys.\n indexKeys.forEach(type => {\n try {\n results.push(\n ...this.lunrIndices[type].query(lunrQueryBuilder).map(result => {\n return {\n result: result,\n type: type,\n };\n }),\n );\n } catch (err) {\n // if a field does not exist on a index, we can see that as a no-match\n if (\n err instanceof Error &&\n err.message.startsWith('unrecognised field')\n ) {\n return;\n }\n throw err;\n }\n });\n\n // Sort results.\n results.sort((doc1, doc2) => {\n return doc2.result.score - doc1.result.score;\n });\n\n // Perform paging\n const { page } = decodePageCursor(query.pageCursor);\n const offset = page * pageSize;\n const hasPreviousPage = page > 0;\n const hasNextPage = results.length > offset + pageSize;\n const nextPageCursor = hasNextPage\n ? encodePageCursor({ page: page + 1 })\n : undefined;\n const previousPageCursor = hasPreviousPage\n ? encodePageCursor({ page: page - 1 })\n : undefined;\n\n // Translate results into IndexableResultSet\n const realResultSet: IndexableResultSet = {\n results: results.slice(offset, offset + pageSize).map((d, index) => ({\n type: d.type,\n document: this.docStore[d.result.ref],\n rank: page * pageSize + index + 1,\n highlight: {\n preTag: this.highlightPreTag,\n postTag: this.highlightPostTag,\n fields: parseHighlightFields({\n preTag: this.highlightPreTag,\n postTag: this.highlightPostTag,\n doc: this.docStore[d.result.ref],\n positionMetadata: d.result.matchData.metadata as any,\n }),\n },\n })),\n nextPageCursor,\n previousPageCursor,\n };\n\n return realResultSet;\n }\n}\n\nexport function decodePageCursor(pageCursor?: string): { page: number } {\n if (!pageCursor) {\n return { page: 0 };\n }\n\n return {\n page: Number(Buffer.from(pageCursor, 'base64').toString('utf-8')),\n };\n}\n\nexport function encodePageCursor({ page }: { page: number }): string {\n return Buffer.from(`${page}`, 'utf-8').toString('base64');\n}\n\ntype ParseHighlightFieldsProps = {\n preTag: string;\n postTag: string;\n doc: any;\n positionMetadata: {\n [term: string]: {\n [field: string]: {\n position: number[][];\n };\n };\n };\n};\n\nexport function parseHighlightFields({\n preTag,\n postTag,\n doc,\n positionMetadata,\n}: ParseHighlightFieldsProps): { [field: string]: string } {\n // Merge the field positions across all query terms\n const highlightFieldPositions = Object.values(positionMetadata).reduce(\n (fieldPositions, metadata) => {\n Object.keys(metadata).map(fieldKey => {\n fieldPositions[fieldKey] = fieldPositions[fieldKey] ?? [];\n fieldPositions[fieldKey].push(...metadata[fieldKey].position);\n });\n\n return fieldPositions;\n },\n {} as { [field: string]: number[][] },\n );\n\n return Object.fromEntries(\n Object.entries(highlightFieldPositions).map(([field, positions]) => {\n positions.sort((a, b) => b[0] - a[0]);\n\n const highlightedField = positions.reduce((content, pos) => {\n return (\n `${content.substring(0, pos[0])}${preTag}` +\n `${content.substring(pos[0], pos[0] + pos[1])}` +\n `${postTag}${content.substring(pos[0] + pos[1])}`\n );\n }, doc[field]);\n\n return [field, highlightedField];\n }),\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 { IndexableDocument } from '@backstage/plugin-search-common';\nimport { pipeline, Readable, Transform, Writable } from 'stream';\n\n/**\n * Object resolved after a test pipeline is executed.\n * @public\n */\nexport type TestPipelineResult = {\n /**\n * If an error was emitted by the pipeline, it will be set here.\n */\n error: unknown;\n\n /**\n * A list of documents collected at the end of the pipeline. If the subject\n * under test is an indexer, this will be an empty array (because your\n * indexer should have received the documents instead).\n */\n documents: IndexableDocument[];\n};\n\n/**\n * Test utility for Backstage Search collators, decorators, and indexers.\n * @public\n */\nexport class TestPipeline {\n private collator?: Readable;\n private decorator?: Transform;\n private indexer?: Writable;\n\n private constructor({\n collator,\n decorator,\n indexer,\n }: {\n collator?: Readable;\n decorator?: Transform;\n indexer?: Writable;\n }) {\n this.collator = collator;\n this.decorator = decorator;\n this.indexer = indexer;\n }\n\n /**\n * Provide the collator, decorator, or indexer to be tested.\n */\n static withSubject(subject: Readable | Transform | Writable) {\n if (subject instanceof Transform) {\n return new TestPipeline({ decorator: subject });\n }\n\n if (subject instanceof Writable) {\n return new TestPipeline({ indexer: subject });\n }\n\n if (subject.readable || subject instanceof Readable) {\n return new TestPipeline({ collator: subject });\n }\n\n throw new Error(\n 'Unknown test subject: are you passing a readable, writable, or transform stream?',\n );\n }\n\n /**\n * Provide documents for testing decorators and indexers.\n */\n withDocuments(documents: IndexableDocument[]): TestPipeline {\n if (this.collator) {\n throw new Error('Cannot provide documents when testing a collator.');\n }\n\n // Set a naive readable stream that just pushes all given documents.\n this.collator = new Readable({ objectMode: true });\n this.collator._read = () => {};\n process.nextTick(() => {\n documents.forEach(document => {\n this.collator!.push(document);\n });\n this.collator!.push(null);\n });\n\n return this;\n }\n\n /**\n * Execute the test pipeline so that you can make assertions about the result\n * or behavior of the given test subject.\n */\n async execute(): Promise<TestPipelineResult> {\n const documents: IndexableDocument[] = [];\n if (!this.collator) {\n throw new Error(\n 'Cannot execute pipeline without a collator or documents',\n );\n }\n\n // If we are here and there is no indexer, we are testing a collator or a\n // decorator. Set up a naive writable that captures documents in memory.\n if (!this.indexer) {\n this.indexer = new Writable({ objectMode: true });\n this.indexer._write = (document: IndexableDocument, _, done) => {\n documents.push(document);\n done();\n };\n }\n\n return new Promise<TestPipelineResult>(done => {\n const pipes: (Readable | Transform | Writable)[] = [this.collator!];\n if (this.decorator) {\n pipes.push(this.decorator);\n }\n pipes.push(this.indexer!);\n\n pipeline(pipes, (error: NodeJS.ErrnoException | null) => {\n done({\n error,\n documents,\n });\n });\n });\n }\n}\n"],"names":["AbortController","pipeline","parseNdjson","isError","Writable","assertError","Transform","lunr","uuid","Readable"],"mappings":";;;;;;;;;;;;;;;AACO,MAAM,SAAS,CAAC;AACvB,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,EAAE;AAC1B,IAAI,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;AACzB,IAAI,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;AACvB,IAAI,IAAI,CAAC,eAAe,GAAG,IAAIA,mCAAe,EAAE,CAAC;AACjD,IAAI,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;AAC3B,GAAG;AACH,EAAE,aAAa,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,EAAE;AAC/C,IAAI,IAAI,IAAI,CAAC,SAAS,EAAE;AACxB,MAAM,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;AACpF,KAAK;AACL,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE;AAC3B,MAAM,MAAM,IAAI,KAAK,CAAC,CAAC,aAAa,EAA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sonCollatorFactory.ts","../src/errors.ts","../src/indexing/BatchSearchEngineIndexer.ts","../src/indexing/DecoratorBase.ts","../src/engines/LunrSearchEngineIndexer.ts","../src/engines/LunrSearchEngine.ts","../src/test-utils/TestPipeline.ts"],"sourcesContent":["/*\n * Copyright 2021 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 { AbortController } from 'node-abort-controller';\nimport { Logger } from 'winston';\nimport { TaskFunction, TaskRunner } from '@backstage/backend-tasks';\n\ntype TaskEnvelope = {\n task: TaskFunction;\n scheduledRunner: TaskRunner;\n};\n\n/**\n * ScheduleTaskParameters\n * @public\n */\nexport type ScheduleTaskParameters = {\n id: string;\n task: TaskFunction;\n scheduledRunner: TaskRunner;\n};\n\n/**\n * Scheduler responsible for all search tasks.\n * @public\n */\nexport class Scheduler {\n private logger: Logger;\n private schedule: { [id: string]: TaskEnvelope };\n private abortController: AbortController;\n private isRunning: boolean;\n\n constructor(options: { logger: Logger }) {\n this.logger = options.logger;\n this.schedule = {};\n this.abortController = new AbortController();\n this.isRunning = false;\n }\n\n /**\n * Adds each task and interval to the schedule.\n * When running the tasks, the scheduler waits at least for the time specified\n * in the interval once the task was completed, before running it again.\n */\n addToSchedule(options: ScheduleTaskParameters) {\n const { id, task, scheduledRunner } = options;\n\n if (this.isRunning) {\n throw new Error(\n 'Cannot add task to schedule that has already been started.',\n );\n }\n\n if (this.schedule[id]) {\n throw new Error(`Task with id ${id} already exists.`);\n }\n\n this.schedule[id] = { task, scheduledRunner };\n }\n\n /**\n * Starts the scheduling process for each task\n */\n start() {\n this.logger.info('Starting all scheduled search tasks.');\n this.isRunning = true;\n Object.keys(this.schedule).forEach(id => {\n const { task, scheduledRunner } = this.schedule[id];\n scheduledRunner.run({\n id,\n fn: task,\n signal: this.abortController.signal,\n });\n });\n }\n\n /**\n * Stop all scheduled tasks.\n */\n stop() {\n this.logger.info('Stopping all scheduled search tasks.');\n this.abortController.abort();\n this.isRunning = false;\n }\n}\n","/*\n * Copyright 2021 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 DocumentDecoratorFactory,\n DocumentTypeInfo,\n SearchEngine,\n} from '@backstage/plugin-search-common';\nimport { Transform, pipeline } from 'stream';\nimport { Logger } from 'winston';\nimport { Scheduler } from './Scheduler';\nimport {\n IndexBuilderOptions,\n RegisterCollatorParameters,\n RegisterDecoratorParameters,\n} from './types';\n\n/**\n * Used for adding collators, decorators and compile them into tasks which are added to a scheduler returned to the caller.\n * @public\n */\nexport class IndexBuilder {\n private collators: Record<string, RegisterCollatorParameters>;\n private decorators: Record<string, DocumentDecoratorFactory[]>;\n private documentTypes: Record<string, DocumentTypeInfo>;\n private searchEngine: SearchEngine;\n private logger: Logger;\n\n constructor(options: IndexBuilderOptions) {\n this.collators = {};\n this.decorators = {};\n this.documentTypes = {};\n this.logger = options.logger;\n this.searchEngine = options.searchEngine;\n }\n\n /**\n * Responsible for returning the registered search engine.\n */\n getSearchEngine(): SearchEngine {\n return this.searchEngine;\n }\n\n /**\n * Responsible for returning the registered document types.\n */\n getDocumentTypes(): Record<string, DocumentTypeInfo> {\n return this.documentTypes;\n }\n\n /**\n * Makes the index builder aware of a collator that should be executed at the\n * given refresh interval.\n */\n addCollator(options: RegisterCollatorParameters): void {\n const { factory, schedule } = options;\n\n this.logger.info(\n `Added ${factory.constructor.name} collator factory for type ${factory.type}`,\n );\n this.collators[factory.type] = {\n factory,\n schedule,\n };\n this.documentTypes[factory.type] = {\n visibilityPermission: factory.visibilityPermission,\n };\n }\n\n /**\n * Makes the index builder aware of a decorator. If no types are provided on\n * the decorator, it will be applied to documents from all known collators,\n * otherwise it will only be applied to documents of the given types.\n */\n addDecorator(options: RegisterDecoratorParameters): void {\n const { factory } = options;\n const types = factory.types || ['*'];\n this.logger.info(\n `Added decorator ${factory.constructor.name} to types ${types.join(\n ', ',\n )}`,\n );\n types.forEach(type => {\n if (this.decorators.hasOwnProperty(type)) {\n this.decorators[type].push(factory);\n } else {\n this.decorators[type] = [factory];\n }\n });\n }\n\n /**\n * Compiles collators and decorators into tasks, which are added to a\n * scheduler returned to the caller.\n */\n async build(): Promise<{ scheduler: Scheduler }> {\n const scheduler = new Scheduler({\n logger: this.logger,\n });\n\n Object.keys(this.collators).forEach(type => {\n scheduler.addToSchedule({\n id: `search_index_${type.replace('-', '_').toLocaleLowerCase('en-US')}`,\n scheduledRunner: this.collators[type].schedule,\n task: async () => {\n // Instantiate the collator.\n const collator = await this.collators[type].factory.getCollator();\n this.logger.info(\n `Collating documents for ${type} via ${this.collators[type].factory.constructor.name}`,\n );\n\n // Instantiate all relevant decorators.\n const decorators: Transform[] = await Promise.all(\n (this.decorators['*'] || [])\n .concat(this.decorators[type] || [])\n .map(async factory => {\n const decorator = await factory.getDecorator();\n this.logger.info(\n `Attached decorator via ${factory.constructor.name} to ${type} index pipeline.`,\n );\n return decorator;\n }),\n );\n\n // Instantiate the indexer.\n const indexer = await this.searchEngine.getIndexer(type);\n\n // Compose collator/decorators/indexer into a pipeline\n return new Promise<void>((resolve, reject) => {\n pipeline(\n [collator, ...decorators, indexer],\n (error: NodeJS.ErrnoException | null) => {\n if (error) {\n this.logger.error(\n `Collating documents for ${type} failed: ${error}`,\n );\n reject(error);\n } else {\n // Signal index pipeline completion!\n this.logger.info(`Collating documents for ${type} succeeded`);\n resolve();\n }\n },\n );\n });\n },\n });\n });\n\n return {\n scheduler,\n };\n }\n}\n","/*\n * Copyright 2021 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 { UrlReader } from '@backstage/backend-common';\nimport { Config } from '@backstage/config';\nimport { Permission } from '@backstage/plugin-permission-common';\nimport { DocumentCollatorFactory } from '@backstage/plugin-search-common';\nimport { parse as parseNdjson } from 'ndjson';\nimport { Readable } from 'stream';\nimport { Logger } from 'winston';\n\n/**\n * Options for instansiate NewlineDelimitedJsonCollatorFactory\n * @public\n */\nexport type NewlineDelimitedJsonCollatorFactoryOptions = {\n type: string;\n searchPattern: string;\n reader: UrlReader;\n logger: Logger;\n visibilityPermission?: Permission;\n};\n\n/**\n * Factory class producing a collator that can be used to index documents\n * sourced from the latest newline delimited JSON file matching a given search\n * pattern. \"Latest\" is determined by the name of the file (last alphabetically\n * is considered latest).\n *\n * @remarks\n * The reader provided must implement the `search()` method as well as the\n * `readUrl` method whose response includes the `stream()` method. Naturally,\n * the reader must also be configured to understand the given search pattern.\n *\n * @example\n * Here's an example configuration using Google Cloud Storage, which would\n * return the latest file under the `bucket` GCS bucket with files like\n * `xyz-2021.ndjson` or `xyz-2022.ndjson`.\n * ```ts\n * indexBuilder.addCollator({\n * schedule,\n * factory: NewlineDelimitedJsonCollatorFactory.fromConfig(env.config, {\n * type: 'techdocs',\n * searchPattern: 'https://storage.cloud.google.com/bucket/xyz-*',\n * reader: env.reader,\n * logger: env.logger,\n * })\n * });\n * ```\n *\n * @public\n */\nexport class NewlineDelimitedJsonCollatorFactory\n implements DocumentCollatorFactory\n{\n readonly type: string;\n\n public readonly visibilityPermission: Permission | undefined;\n\n private constructor(\n type: string,\n private readonly searchPattern: string,\n private readonly reader: UrlReader,\n private readonly logger: Logger,\n visibilityPermission: Permission | undefined,\n ) {\n this.type = type;\n this.visibilityPermission = visibilityPermission;\n }\n\n /**\n * Returns a NewlineDelimitedJsonCollatorFactory instance from configuration\n * and a set of options.\n */\n static fromConfig(\n _config: Config,\n options: NewlineDelimitedJsonCollatorFactoryOptions,\n ): NewlineDelimitedJsonCollatorFactory {\n return new NewlineDelimitedJsonCollatorFactory(\n options.type,\n options.searchPattern,\n options.reader,\n options.logger,\n options.visibilityPermission,\n );\n }\n\n /**\n * Returns the \"latest\" URL for the given search pattern (e.g. the one at the\n * end of the list, sorted alphabetically).\n */\n private async lastUrl(): Promise<string | undefined> {\n try {\n // Search for files matching the given pattern, then sort/reverse. The\n // first item in the list will be the \"latest\" file.\n this.logger.info(\n `Attempting to find latest .ndjson matching ${this.searchPattern}`,\n );\n const { files } = await this.reader.search(this.searchPattern);\n const candidates = files\n .filter(file => file.url.endsWith('.ndjson'))\n .sort((a, b) => a.url.localeCompare(b.url))\n .reverse();\n\n return candidates[0]?.url;\n } catch (e) {\n this.logger.error(`Could not search for ${this.searchPattern}`, e);\n throw e;\n }\n }\n\n async getCollator(): Promise<Readable> {\n // Search for files matching the given pattern.\n const lastUrl = await this.lastUrl();\n\n // Abort if no such file could be found.\n if (!lastUrl) {\n const noMatchingFile = `Could not find an .ndjson file matching ${this.searchPattern}`;\n this.logger.error(noMatchingFile);\n throw new Error(noMatchingFile);\n } else {\n this.logger.info(`Using latest .ndjson file ${lastUrl}`);\n }\n\n // Use the UrlReader to try and stream the file.\n const readerResponse = await this.reader.readUrl!(lastUrl);\n const stream = readerResponse.stream!();\n\n // Use ndjson's parser to turn the raw file into an object-mode stream.\n return stream.pipe(parseNdjson());\n }\n}\n","/*\n * Copyright 2021 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 { isError } from '@backstage/errors';\n\n/**\n * Failed to query documents for index that does not exist.\n * @public\n */\nexport class MissingIndexError extends Error {\n /**\n * An inner error that caused this error to be thrown, if any.\n */\n readonly cause?: Error | undefined;\n\n constructor(message?: string, cause?: Error | unknown) {\n super(message);\n\n Error.captureStackTrace?.(this, this.constructor);\n\n this.name = this.constructor.name;\n this.cause = isError(cause) ? cause : undefined;\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 { assertError } from '@backstage/errors';\nimport { IndexableDocument } from '@backstage/plugin-search-common';\nimport { Writable } from 'stream';\n\n/**\n * Options for {@link BatchSearchEngineIndexer}\n * @public\n */\nexport type BatchSearchEngineOptions = {\n batchSize: number;\n};\n\n/**\n * Base class encapsulating batch-based stream processing. Useful as a base\n * class for search engine indexers.\n * @public\n */\nexport abstract class BatchSearchEngineIndexer extends Writable {\n private batchSize: number;\n private currentBatch: IndexableDocument[] = [];\n private initialized: Promise<undefined | Error>;\n\n constructor(options: BatchSearchEngineOptions) {\n super({ objectMode: true });\n this.batchSize = options.batchSize;\n\n // @todo Once node v15 is minimum, convert to _construct implementation.\n this.initialized = new Promise(done => {\n // Necessary to allow concrete implementation classes to construct\n // themselves before calling their initialize() methods.\n setImmediate(async () => {\n try {\n await this.initialize();\n done(undefined);\n } catch (e) {\n assertError(e);\n done(e);\n }\n });\n });\n }\n\n /**\n * Receives an array of indexable documents (of size this.batchSize) which\n * should be written to the search engine. This method won't be called again\n * at least until it resolves.\n */\n public abstract index(documents: IndexableDocument[]): Promise<void>;\n\n /**\n * Any asynchronous setup tasks can be performed here.\n */\n public abstract initialize(): Promise<void>;\n\n /**\n * Any asynchronous teardown tasks can be performed here.\n */\n public abstract finalize(): Promise<void>;\n\n /**\n * Encapsulates batch stream write logic.\n * @internal\n */\n async _write(\n doc: IndexableDocument,\n _e: any,\n done: (error?: Error | null) => void,\n ) {\n // Wait for init before proceeding. Throw error if initialization failed.\n const maybeError = await this.initialized;\n if (maybeError) {\n done(maybeError);\n return;\n }\n\n this.currentBatch.push(doc);\n if (this.currentBatch.length < this.batchSize) {\n done();\n return;\n }\n\n try {\n await this.index(this.currentBatch);\n this.currentBatch = [];\n done();\n } catch (e) {\n assertError(e);\n done(e);\n }\n }\n\n /**\n * Encapsulates finalization and final error handling logic.\n * @internal\n */\n async _final(done: (error?: Error | null) => void) {\n try {\n // Index any remaining documents.\n if (this.currentBatch.length) {\n await this.index(this.currentBatch);\n this.currentBatch = [];\n }\n await this.finalize();\n done();\n } catch (e) {\n assertError(e);\n done(e);\n }\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 { assertError } from '@backstage/errors';\nimport { IndexableDocument } from '@backstage/plugin-search-common';\nimport { Transform } from 'stream';\n\n/**\n * Base class encapsulating simple async transformations. Useful as a base\n * class for Backstage search decorators.\n * @public\n */\nexport abstract class DecoratorBase extends Transform {\n private initialized: Promise<undefined | Error>;\n\n constructor() {\n super({ objectMode: true });\n\n // @todo Once node v15 is minimum, convert to _construct implementation.\n this.initialized = new Promise(done => {\n // Necessary to allow concrete implementation classes to construct\n // themselves before calling their initialize() methods.\n setImmediate(async () => {\n try {\n await this.initialize();\n done(undefined);\n } catch (e) {\n assertError(e);\n done(e);\n }\n });\n });\n }\n\n /**\n * Any asynchronous setup tasks can be performed here.\n */\n public abstract initialize(): Promise<void>;\n\n /**\n * Receives a single indexable document. In your decorate method, you can:\n *\n * - Resolve `undefined` to indicate the record should be omitted.\n * - Resolve a single modified document, which could contain new fields,\n * edited fields, or removed fields.\n * - Resolve an array of indexable documents, if the purpose if the decorator\n * is to convert one document into multiple derivative documents.\n */\n public abstract decorate(\n document: IndexableDocument,\n ): Promise<IndexableDocument | IndexableDocument[] | undefined>;\n\n /**\n * Any asynchronous teardown tasks can be performed here.\n */\n public abstract finalize(): Promise<void>;\n\n /**\n * Encapsulates simple transform stream logic.\n * @internal\n */\n async _transform(\n document: IndexableDocument,\n _: any,\n done: (error?: Error | null) => void,\n ) {\n // Wait for init before proceeding. Throw error if initialization failed.\n const maybeError = await this.initialized;\n if (maybeError) {\n done(maybeError);\n return;\n }\n\n try {\n const decorated = await this.decorate(document);\n\n // If undefined was returned, omit the record and move on.\n if (decorated === undefined) {\n done();\n return;\n }\n\n // If an array of documents was given, push them all.\n if (Array.isArray(decorated)) {\n decorated.forEach(doc => {\n this.push(doc);\n });\n done();\n return;\n }\n\n // Otherwise, just push the decorated document.\n this.push(decorated);\n done();\n } catch (e) {\n assertError(e);\n done(e);\n }\n }\n\n /**\n * Encapsulates finalization and final error handling logic.\n * @internal\n */\n async _final(done: (error?: Error | null) => void) {\n try {\n await this.finalize();\n done();\n } catch (e) {\n assertError(e);\n done(e);\n }\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 { IndexableDocument } from '@backstage/plugin-search-common';\nimport lunr from 'lunr';\nimport { BatchSearchEngineIndexer } from '../indexing';\n\n/**\n * Lunr specific search engine indexer\n * @public\n */\nexport class LunrSearchEngineIndexer extends BatchSearchEngineIndexer {\n private schemaInitialized = false;\n private builder: lunr.Builder;\n private docStore: Record<string, IndexableDocument> = {};\n\n constructor() {\n super({ batchSize: 1000 });\n\n this.builder = new lunr.Builder();\n this.builder.pipeline.add(lunr.trimmer, lunr.stopWordFilter, lunr.stemmer);\n this.builder.searchPipeline.add(lunr.stemmer);\n this.builder.metadataWhitelist = ['position'];\n }\n\n // No async initialization required.\n async initialize(): Promise<void> {}\n async finalize(): Promise<void> {}\n\n async index(documents: IndexableDocument[]): Promise<void> {\n if (!this.schemaInitialized) {\n // Make this lunr index aware of all relevant fields.\n Object.keys(documents[0]).forEach(field => {\n this.builder.field(field);\n });\n\n // Set \"location\" field as reference field\n this.builder.ref('location');\n\n this.schemaInitialized = true;\n }\n\n documents.forEach(document => {\n // Add document to Lunar index\n this.builder.add(document);\n\n // Store documents in memory to be able to look up document using the ref during query time\n // This is not how you should implement your SearchEngine implementation! Do not copy!\n this.docStore[document.location] = document;\n });\n }\n\n buildIndex() {\n return this.builder.build();\n }\n\n getDocumentStore() {\n return this.docStore;\n }\n}\n","/*\n * Copyright 2021 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 IndexableDocument,\n IndexableResultSet,\n SearchQuery,\n QueryTranslator,\n SearchEngine,\n} from '@backstage/plugin-search-common';\nimport { MissingIndexError } from '../errors';\nimport lunr from 'lunr';\nimport { v4 as uuid } from 'uuid';\nimport { Logger } from 'winston';\nimport { LunrSearchEngineIndexer } from './LunrSearchEngineIndexer';\n\n/**\n * Type of translated query for the Lunr Search Engine.\n * @public\n */\nexport type ConcreteLunrQuery = {\n lunrQueryBuilder: lunr.Index.QueryBuilder;\n documentTypes?: string[];\n pageSize: number;\n};\n\ntype LunrResultEnvelope = {\n result: lunr.Index.Result;\n type: string;\n};\n\n/**\n * Translator responsible for translating search term and filters to a query that the Lunr Search Engine understands.\n * @public\n */\nexport type LunrQueryTranslator = (query: SearchQuery) => ConcreteLunrQuery;\n\n/**\n * Lunr specific search engine implementation.\n * @public\n */\nexport class LunrSearchEngine implements SearchEngine {\n protected lunrIndices: Record<string, lunr.Index> = {};\n protected docStore: Record<string, IndexableDocument>;\n protected logger: Logger;\n protected highlightPreTag: string;\n protected highlightPostTag: string;\n\n constructor(options: { logger: Logger }) {\n this.logger = options.logger;\n this.docStore = {};\n const uuidTag = uuid();\n this.highlightPreTag = `<${uuidTag}>`;\n this.highlightPostTag = `</${uuidTag}>`;\n }\n\n protected translator: QueryTranslator = ({\n term,\n filters,\n types,\n }: SearchQuery): ConcreteLunrQuery => {\n const pageSize = 25;\n\n return {\n lunrQueryBuilder: q => {\n const termToken = lunr.tokenizer(term);\n\n // Support for typeahead search is based on https://github.com/olivernn/lunr.js/issues/256#issuecomment-295407852\n // look for an exact match and apply a large positive boost\n q.term(termToken, {\n usePipeline: true,\n boost: 100,\n });\n // look for terms that match the beginning of this term and apply a\n // medium boost\n q.term(termToken, {\n usePipeline: false,\n boost: 10,\n wildcard: lunr.Query.wildcard.TRAILING,\n });\n // look for terms that match with an edit distance of 2 and apply a\n // small boost\n q.term(termToken, {\n usePipeline: false,\n editDistance: 2,\n boost: 1,\n });\n\n if (filters) {\n Object.entries(filters).forEach(([field, fieldValue]) => {\n if (!q.allFields.includes(field)) {\n // Throw for unknown field, as this will be a non match\n throw new Error(`unrecognised field ${field}`);\n }\n // Arrays are poorly supported, but we can make it better for single-item arrays,\n // which should be a common case\n const value =\n Array.isArray(fieldValue) && fieldValue.length === 1\n ? fieldValue[0]\n : fieldValue;\n\n // Require that the given field has the given value\n if (['string', 'number', 'boolean'].includes(typeof value)) {\n q.term(lunr.tokenizer(value?.toString()), {\n presence: lunr.Query.presence.REQUIRED,\n fields: [field],\n });\n } else if (Array.isArray(value)) {\n // Illustrate how multi-value filters could work.\n // But warn that Lurn supports this poorly.\n this.logger.warn(\n `Non-scalar filter value used for field ${field}. Consider using a different Search Engine for better results.`,\n );\n q.term(lunr.tokenizer(value), {\n presence: lunr.Query.presence.OPTIONAL,\n fields: [field],\n });\n } else {\n // Log a warning or something about unknown filter value\n this.logger.warn(`Unknown filter type used on field ${field}`);\n }\n });\n }\n },\n documentTypes: types,\n pageSize,\n };\n };\n\n setTranslator(translator: LunrQueryTranslator) {\n this.translator = translator;\n }\n\n async getIndexer(type: string) {\n const indexer = new LunrSearchEngineIndexer();\n\n indexer.on('close', () => {\n // Once the stream is closed, build the index and store the documents in\n // memory for later retrieval.\n this.lunrIndices[type] = indexer.buildIndex();\n this.docStore = { ...this.docStore, ...indexer.getDocumentStore() };\n });\n\n return indexer;\n }\n\n async query(query: SearchQuery): Promise<IndexableResultSet> {\n const { lunrQueryBuilder, documentTypes, pageSize } = this.translator(\n query,\n ) as ConcreteLunrQuery;\n\n const results: LunrResultEnvelope[] = [];\n\n const indexKeys = Object.keys(this.lunrIndices).filter(\n type => !documentTypes || documentTypes.includes(type),\n );\n\n if (documentTypes?.length && !indexKeys.length) {\n throw new MissingIndexError(\n `Missing index for ${documentTypes?.toString()}. This could be because the index hasn't been created yet or there was a problem during index creation.`,\n );\n }\n\n // Iterate over the filtered list of this.lunrIndex keys.\n indexKeys.forEach(type => {\n try {\n results.push(\n ...this.lunrIndices[type].query(lunrQueryBuilder).map(result => {\n return {\n result: result,\n type: type,\n };\n }),\n );\n } catch (err) {\n // if a field does not exist on a index, we can see that as a no-match\n if (\n err instanceof Error &&\n err.message.startsWith('unrecognised field')\n ) {\n return;\n }\n throw err;\n }\n });\n\n // Sort results.\n results.sort((doc1, doc2) => {\n return doc2.result.score - doc1.result.score;\n });\n\n // Perform paging\n const { page } = decodePageCursor(query.pageCursor);\n const offset = page * pageSize;\n const hasPreviousPage = page > 0;\n const hasNextPage = results.length > offset + pageSize;\n const nextPageCursor = hasNextPage\n ? encodePageCursor({ page: page + 1 })\n : undefined;\n const previousPageCursor = hasPreviousPage\n ? encodePageCursor({ page: page - 1 })\n : undefined;\n\n // Translate results into IndexableResultSet\n const realResultSet: IndexableResultSet = {\n results: results.slice(offset, offset + pageSize).map((d, index) => ({\n type: d.type,\n document: this.docStore[d.result.ref],\n rank: page * pageSize + index + 1,\n highlight: {\n preTag: this.highlightPreTag,\n postTag: this.highlightPostTag,\n fields: parseHighlightFields({\n preTag: this.highlightPreTag,\n postTag: this.highlightPostTag,\n doc: this.docStore[d.result.ref],\n positionMetadata: d.result.matchData.metadata as any,\n }),\n },\n })),\n nextPageCursor,\n previousPageCursor,\n };\n\n return realResultSet;\n }\n}\n\nexport function decodePageCursor(pageCursor?: string): { page: number } {\n if (!pageCursor) {\n return { page: 0 };\n }\n\n return {\n page: Number(Buffer.from(pageCursor, 'base64').toString('utf-8')),\n };\n}\n\nexport function encodePageCursor({ page }: { page: number }): string {\n return Buffer.from(`${page}`, 'utf-8').toString('base64');\n}\n\ntype ParseHighlightFieldsProps = {\n preTag: string;\n postTag: string;\n doc: any;\n positionMetadata: {\n [term: string]: {\n [field: string]: {\n position: number[][];\n };\n };\n };\n};\n\nexport function parseHighlightFields({\n preTag,\n postTag,\n doc,\n positionMetadata,\n}: ParseHighlightFieldsProps): { [field: string]: string } {\n // Merge the field positions across all query terms\n const highlightFieldPositions = Object.values(positionMetadata).reduce(\n (fieldPositions, metadata) => {\n Object.keys(metadata).map(fieldKey => {\n fieldPositions[fieldKey] = fieldPositions[fieldKey] ?? [];\n fieldPositions[fieldKey].push(...metadata[fieldKey].position);\n });\n\n return fieldPositions;\n },\n {} as { [field: string]: number[][] },\n );\n\n return Object.fromEntries(\n Object.entries(highlightFieldPositions).map(([field, positions]) => {\n positions.sort((a, b) => b[0] - a[0]);\n\n const highlightedField = positions.reduce((content, pos) => {\n return (\n `${content.substring(0, pos[0])}${preTag}` +\n `${content.substring(pos[0], pos[0] + pos[1])}` +\n `${postTag}${content.substring(pos[0] + pos[1])}`\n );\n }, doc[field]);\n\n return [field, highlightedField];\n }),\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 { IndexableDocument } from '@backstage/plugin-search-common';\nimport { pipeline, Readable, Transform, Writable } from 'stream';\n\n/**\n * Object resolved after a test pipeline is executed.\n * @public\n */\nexport type TestPipelineResult = {\n /**\n * If an error was emitted by the pipeline, it will be set here.\n */\n error: unknown;\n\n /**\n * A list of documents collected at the end of the pipeline. If the subject\n * under test is an indexer, this will be an empty array (because your\n * indexer should have received the documents instead).\n */\n documents: IndexableDocument[];\n};\n\n/**\n * Test utility for Backstage Search collators, decorators, and indexers.\n * @public\n */\nexport class TestPipeline {\n private collator?: Readable;\n private decorator?: Transform;\n private indexer?: Writable;\n\n private constructor({\n collator,\n decorator,\n indexer,\n }: {\n collator?: Readable;\n decorator?: Transform;\n indexer?: Writable;\n }) {\n this.collator = collator;\n this.decorator = decorator;\n this.indexer = indexer;\n }\n\n /**\n * Provide the collator, decorator, or indexer to be tested.\n */\n static withSubject(subject: Readable | Transform | Writable) {\n if (subject instanceof Transform) {\n return new TestPipeline({ decorator: subject });\n }\n\n if (subject instanceof Writable) {\n return new TestPipeline({ indexer: subject });\n }\n\n if (subject.readable || subject instanceof Readable) {\n return new TestPipeline({ collator: subject });\n }\n\n throw new Error(\n 'Unknown test subject: are you passing a readable, writable, or transform stream?',\n );\n }\n\n /**\n * Provide documents for testing decorators and indexers.\n */\n withDocuments(documents: IndexableDocument[]): TestPipeline {\n if (this.collator) {\n throw new Error('Cannot provide documents when testing a collator.');\n }\n\n // Set a naive readable stream that just pushes all given documents.\n this.collator = new Readable({ objectMode: true });\n this.collator._read = () => {};\n process.nextTick(() => {\n documents.forEach(document => {\n this.collator!.push(document);\n });\n this.collator!.push(null);\n });\n\n return this;\n }\n\n /**\n * Execute the test pipeline so that you can make assertions about the result\n * or behavior of the given test subject.\n */\n async execute(): Promise<TestPipelineResult> {\n const documents: IndexableDocument[] = [];\n if (!this.collator) {\n throw new Error(\n 'Cannot execute pipeline without a collator or documents',\n );\n }\n\n // If we are here and there is no indexer, we are testing a collator or a\n // decorator. Set up a naive writable that captures documents in memory.\n if (!this.indexer) {\n this.indexer = new Writable({ objectMode: true });\n this.indexer._write = (document: IndexableDocument, _, done) => {\n documents.push(document);\n done();\n };\n }\n\n return new Promise<TestPipelineResult>(done => {\n const pipes: (Readable | Transform | Writable)[] = [this.collator!];\n if (this.decorator) {\n pipes.push(this.decorator);\n }\n pipes.push(this.indexer!);\n\n pipeline(pipes, (error: NodeJS.ErrnoException | null) => {\n done({\n error,\n documents,\n });\n });\n });\n }\n}\n"],"names":["AbortController","pipeline","parseNdjson","isError","Writable","assertError","Transform","lunr","uuid","Readable"],"mappings":";;;;;;;;;;;;;;;AACO,MAAM,SAA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AAyD;AACjE,OAAO,CAAC;AACR,KAAK;AACL,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;AACvB,MAAM,IAAI,CAAC,OAAO,GAAG,IAAIL,eAAQ,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;AACxD,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,KAAK;AACnD,QAAQ,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACjC,QAAQ,IAAI,EAAE,CAAC;AACf,OAAO,CAAC;AACR,KAAK;AACL,IAAI,OAAO,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK;AACjC,MAAM,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACpC,MAAM,IAAI,IAAI,CAAC,SAAS,EAAE;AAC1B,QAAQ,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACnC,OAAO;AACP,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC/B,MAAMH,eAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,KAAK;AACjC,QAAQ,IAAI,CAAC;AACb,UAAU,KAAK;AACf,UAAU,SAAS;AACnB,SAAS,CAAC,CAAC;AACX,OAAO,CAAC,CAAC;AACT,KAAK,CAAC,CAAC;AACP,GAAG;AACH;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -26,7 +26,7 @@ declare class Scheduler {
26
26
  private schedule;
27
27
  private abortController;
28
28
  private isRunning;
29
- constructor({ logger }: {
29
+ constructor(options: {
30
30
  logger: Logger;
31
31
  });
32
32
  /**
@@ -34,7 +34,7 @@ declare class Scheduler {
34
34
  * When running the tasks, the scheduler waits at least for the time specified
35
35
  * in the interval once the task was completed, before running it again.
36
36
  */
37
- addToSchedule({ id, task, scheduledRunner }: ScheduleTaskParameters): void;
37
+ addToSchedule(options: ScheduleTaskParameters): void;
38
38
  /**
39
39
  * Starts the scheduling process for each task
40
40
  */
@@ -89,7 +89,7 @@ declare class IndexBuilder {
89
89
  private documentTypes;
90
90
  private searchEngine;
91
91
  private logger;
92
- constructor({ logger, searchEngine }: IndexBuilderOptions);
92
+ constructor(options: IndexBuilderOptions);
93
93
  /**
94
94
  * Responsible for returning the registered search engine.
95
95
  */
@@ -102,13 +102,13 @@ declare class IndexBuilder {
102
102
  * Makes the index builder aware of a collator that should be executed at the
103
103
  * given refresh interval.
104
104
  */
105
- addCollator({ factory, schedule }: RegisterCollatorParameters): void;
105
+ addCollator(options: RegisterCollatorParameters): void;
106
106
  /**
107
107
  * Makes the index builder aware of a decorator. If no types are provided on
108
108
  * the decorator, it will be applied to documents from all known collators,
109
109
  * otherwise it will only be applied to documents of the given types.
110
110
  */
111
- addDecorator({ factory }: RegisterDecoratorParameters): void;
111
+ addDecorator(options: RegisterDecoratorParameters): void;
112
112
  /**
113
113
  * Compiles collators and decorators into tasks, which are added to a
114
114
  * scheduler returned to the caller.
@@ -265,7 +265,7 @@ declare type ConcreteLunrQuery = {
265
265
  pageSize: number;
266
266
  };
267
267
  /**
268
- * Translator repsonsible for translating search term and filters to a query that the Lunr Search Engine understands.
268
+ * Translator responsible for translating search term and filters to a query that the Lunr Search Engine understands.
269
269
  * @public
270
270
  */
271
271
  declare type LunrQueryTranslator = (query: SearchQuery) => ConcreteLunrQuery;
@@ -279,7 +279,7 @@ declare class LunrSearchEngine implements SearchEngine {
279
279
  protected logger: Logger;
280
280
  protected highlightPreTag: string;
281
281
  protected highlightPostTag: string;
282
- constructor({ logger }: {
282
+ constructor(options: {
283
283
  logger: Logger;
284
284
  });
285
285
  protected translator: QueryTranslator;
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": "1.0.0",
4
+ "version": "1.0.2-next.0",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -23,12 +23,12 @@
23
23
  "clean": "backstage-cli package clean"
24
24
  },
25
25
  "dependencies": {
26
- "@backstage/backend-common": "^0.14.1",
27
- "@backstage/backend-tasks": "^0.3.3",
26
+ "@backstage/backend-common": "^0.15.1-next.0",
27
+ "@backstage/backend-tasks": "^0.3.5-next.0",
28
28
  "@backstage/config": "^1.0.1",
29
29
  "@backstage/errors": "^1.1.0",
30
- "@backstage/plugin-permission-common": "^0.6.3",
31
- "@backstage/plugin-search-common": "^1.0.0",
30
+ "@backstage/plugin-permission-common": "^0.6.4-next.0",
31
+ "@backstage/plugin-search-common": "^1.0.1-next.0",
32
32
  "@types/lunr": "^2.3.3",
33
33
  "lodash": "^4.17.21",
34
34
  "lunr": "^2.3.9",
@@ -38,12 +38,12 @@
38
38
  "winston": "^3.2.1"
39
39
  },
40
40
  "devDependencies": {
41
- "@backstage/backend-common": "^0.14.1",
42
- "@backstage/cli": "^0.18.0",
41
+ "@backstage/backend-common": "^0.15.1-next.0",
42
+ "@backstage/cli": "^0.18.2-next.0",
43
43
  "@types/ndjson": "^2.0.1"
44
44
  },
45
45
  "files": [
46
46
  "dist"
47
47
  ],
48
- "gitHead": "999878d8f1ae30f6a15925816af2016cb9d717a1"
48
+ "gitHead": "c6c0b1978a7ab4d29d813996c56beb7e6b48a268"
49
49
  }