@backstage/plugin-search-backend-node 0.6.1 → 0.6.2-next.2

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,38 @@
1
1
  # @backstage/plugin-search-backend-node
2
2
 
3
+ ## 0.6.2-next.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 7d8acfc32e: Replaced all `@beta` exports with `@public` exports
8
+ - Updated dependencies
9
+ - @backstage/plugin-search-common@0.3.5-next.1
10
+ - @backstage/backend-common@0.14.0-next.2
11
+ - @backstage/backend-tasks@0.3.2-next.2
12
+
13
+ ## 0.6.2-next.1
14
+
15
+ ### Patch Changes
16
+
17
+ - 3bb25a9acc: Introducing a `NewlineDelimitedJsonCollatorFactory`, which can be used to create search indices from newline delimited JSON files stored in external storage readable via a configured `UrlReader` instance.
18
+
19
+ This is useful if you have an independent process periodically generating `*.ndjson` files consisting of `IndexableDocument` objects and want to be able to generate a fresh index based on the latest version of such a file.
20
+
21
+ - 3bb25a9acc: Fixed a bug that prevented `TestPipeline.withSubject` from identifying valid `Readable` subjects that were technically transform streams.
22
+ - Updated dependencies
23
+ - @backstage/backend-tasks@0.3.2-next.1
24
+ - @backstage/backend-common@0.13.6-next.1
25
+ - @backstage/plugin-permission-common@0.6.2-next.0
26
+ - @backstage/plugin-search-common@0.3.5-next.0
27
+
28
+ ## 0.6.2-next.0
29
+
30
+ ### Patch Changes
31
+
32
+ - e7794a0aaa: propagate indexing errors so they don't appear successful to the task scheduler
33
+ - Updated dependencies
34
+ - @backstage/backend-tasks@0.3.2-next.0
35
+
3
36
  ## 0.6.1
4
37
 
5
38
  ### Patch Changes
package/dist/index.cjs.js CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var stream = require('stream');
6
6
  var nodeAbortController = require('node-abort-controller');
7
+ var ndjson = require('ndjson');
7
8
  var lunr = require('lunr');
8
9
  var uuid = require('uuid');
9
10
  var errors = require('@backstage/errors');
@@ -99,14 +100,15 @@ class IndexBuilder {
99
100
  return decorator;
100
101
  }));
101
102
  const indexer = await this.searchEngine.getIndexer(type);
102
- return new Promise((done) => {
103
+ return new Promise((resolve, reject) => {
103
104
  stream.pipeline([collator, ...decorators, indexer], (error) => {
104
105
  if (error) {
105
106
  this.logger.error(`Collating documents for ${type} failed: ${error}`);
107
+ reject(error);
106
108
  } else {
107
109
  this.logger.info(`Collating documents for ${type} succeeded`);
110
+ resolve();
108
111
  }
109
- done();
110
112
  });
111
113
  });
112
114
  }
@@ -118,6 +120,44 @@ class IndexBuilder {
118
120
  }
119
121
  }
120
122
 
123
+ class NewlineDelimitedJsonCollatorFactory {
124
+ constructor(type, searchPattern, reader, logger, visibilityPermission) {
125
+ this.searchPattern = searchPattern;
126
+ this.reader = reader;
127
+ this.logger = logger;
128
+ this.type = type;
129
+ this.visibilityPermission = visibilityPermission;
130
+ }
131
+ static fromConfig(_config, options) {
132
+ return new NewlineDelimitedJsonCollatorFactory(options.type, options.searchPattern, options.reader, options.logger, options.visibilityPermission);
133
+ }
134
+ async lastUrl() {
135
+ var _a;
136
+ try {
137
+ this.logger.info(`Attempting to find latest .ndjson matching ${this.searchPattern}`);
138
+ const { files } = await this.reader.search(this.searchPattern);
139
+ const candidates = files.filter((file) => file.url.endsWith(".ndjson")).sort((a, b) => a.url.localeCompare(b.url)).reverse();
140
+ return (_a = candidates[0]) == null ? void 0 : _a.url;
141
+ } catch (e) {
142
+ this.logger.error(`Could not search for ${this.searchPattern}`, e);
143
+ throw e;
144
+ }
145
+ }
146
+ async getCollator() {
147
+ const lastUrl = await this.lastUrl();
148
+ if (!lastUrl) {
149
+ const noMatchingFile = `Could not find an .ndjson file matching ${this.searchPattern}`;
150
+ this.logger.error(noMatchingFile);
151
+ throw new Error(noMatchingFile);
152
+ } else {
153
+ this.logger.info(`Using latest .ndjson file ${lastUrl}`);
154
+ }
155
+ const readerResponse = await this.reader.readUrl(lastUrl);
156
+ const stream = readerResponse.stream();
157
+ return stream.pipe(ndjson.parse());
158
+ }
159
+ }
160
+
121
161
  class BatchSearchEngineIndexer extends stream.Writable {
122
162
  constructor(options) {
123
163
  super({ objectMode: true });
@@ -423,12 +463,12 @@ class TestPipeline {
423
463
  if (subject instanceof stream.Transform) {
424
464
  return new TestPipeline({ decorator: subject });
425
465
  }
426
- if (subject instanceof stream.Readable) {
427
- return new TestPipeline({ collator: subject });
428
- }
429
466
  if (subject instanceof stream.Writable) {
430
467
  return new TestPipeline({ indexer: subject });
431
468
  }
469
+ if (subject.readable || subject instanceof stream.Readable) {
470
+ return new TestPipeline({ collator: subject });
471
+ }
432
472
  throw new Error("Unknown test subject: are you passing a readable, writable, or transform stream?");
433
473
  }
434
474
  withDocuments(documents) {
@@ -478,6 +518,7 @@ exports.BatchSearchEngineIndexer = BatchSearchEngineIndexer;
478
518
  exports.DecoratorBase = DecoratorBase;
479
519
  exports.IndexBuilder = IndexBuilder;
480
520
  exports.LunrSearchEngine = LunrSearchEngine;
521
+ exports.NewlineDelimitedJsonCollatorFactory = NewlineDelimitedJsonCollatorFactory;
481
522
  exports.Scheduler = Scheduler;
482
523
  exports.TestPipeline = TestPipeline;
483
524
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/Scheduler.ts","../src/IndexBuilder.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 * @public ScheduleTaskParameters\n */\nexport interface ScheduleTaskParameters {\n id: string;\n task: TaskFunction;\n scheduledRunner: TaskRunner;\n}\n\n/**\n * @beta\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 * @beta\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 getSearchEngine(): SearchEngine {\n return this.searchEngine;\n }\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>(done => {\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 } else {\n this.logger.info(`Collating documents for ${type} succeeded`);\n }\n\n // Signal index pipeline completion!\n done();\n },\n );\n });\n },\n });\n });\n\n return {\n scheduler,\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 { Writable } from 'stream';\n\n/**\n * @beta\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 * @beta\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 * @beta\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 * @beta\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 lunr from 'lunr';\nimport { v4 as uuid } from 'uuid';\nimport { Logger } from 'winston';\nimport { LunrSearchEngineIndexer } from './LunrSearchEngineIndexer';\n\n/**\n * @beta\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 * @beta\n */\nexport type LunrQueryTranslator = (query: SearchQuery) => ConcreteLunrQuery;\n\n/**\n * @beta\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 // Iterate over the filtered list of this.lunrIndex keys.\n Object.keys(this.lunrIndices)\n .filter(type => !documentTypes || documentTypes.includes(type))\n .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 => ({\n type: d.type,\n document: this.docStore[d.result.ref],\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 * @beta\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 * @beta\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 Readable) {\n return new TestPipeline({ collator: subject });\n }\n\n if (subject instanceof Writable) {\n return new TestPipeline({ indexer: 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","Writable","assertError","Transform","lunr","uuid","Readable"],"mappings":";;;;;;;;;;;;;;AACO,MAAM,SAAS,CAAC;AACvB,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,EAAE;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AAyD,CAAC,CAAC;AACjF,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,MAAMD,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;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/Scheduler.ts","../src/IndexBuilder.ts","../src/collators/NewlineDelimitedJsonCollatorFactory.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 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 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 // Iterate over the filtered list of this.lunrIndex keys.\n Object.keys(this.lunrIndices)\n .filter(type => !documentTypes || documentTypes.includes(type))\n .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 => ({\n type: d.type,\n document: this.docStore[d.result.ref],\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","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,EAAE,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAC5D,KAAK;AACL,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;AAClD,GAAG;AACH,EAAE,KAAK,GAAG;AACV,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;AAC7D,IAAI,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;AAC1B,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK;AAC/C,MAAM,MAAM,EAAE,IAAI,E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AAM,SAAS,GAAG,EAAE,CAAC;AACzB,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;AACxB,MAAM,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;AACjF,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,MAAMF,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
@@ -3,19 +3,24 @@ import { SearchEngine, DocumentCollatorFactory, DocumentDecoratorFactory, Docume
3
3
  export { SearchEngine } from '@backstage/plugin-search-common';
4
4
  import { Logger } from 'winston';
5
5
  import { TaskFunction, TaskRunner } from '@backstage/backend-tasks';
6
+ import { UrlReader } from '@backstage/backend-common';
7
+ import { Config } from '@backstage/config';
8
+ import { Permission } from '@backstage/plugin-permission-common';
9
+ import { Readable, Writable, Transform } from 'stream';
6
10
  import lunr from 'lunr';
7
- import { Writable, Transform, Readable } from 'stream';
8
11
 
9
12
  /**
10
- * @public ScheduleTaskParameters
13
+ * ScheduleTaskParameters
14
+ * @public
11
15
  */
12
- interface ScheduleTaskParameters {
16
+ declare type ScheduleTaskParameters = {
13
17
  id: string;
14
18
  task: TaskFunction;
15
19
  scheduledRunner: TaskRunner;
16
- }
20
+ };
17
21
  /**
18
- * @beta
22
+ * Scheduler responsible for all search tasks.
23
+ * @public
19
24
  */
20
25
  declare class Scheduler {
21
26
  private logger;
@@ -42,7 +47,8 @@ declare class Scheduler {
42
47
  }
43
48
 
44
49
  /**
45
- * @beta
50
+ * Options required to instantiate the index builder.
51
+ * @public
46
52
  */
47
53
  declare type IndexBuilderOptions = {
48
54
  searchEngine: SearchEngine;
@@ -50,7 +56,7 @@ declare type IndexBuilderOptions = {
50
56
  };
51
57
  /**
52
58
  * Parameters required to register a collator.
53
- * @beta
59
+ * @public
54
60
  */
55
61
  interface RegisterCollatorParameters {
56
62
  /**
@@ -65,7 +71,7 @@ interface RegisterCollatorParameters {
65
71
  }
66
72
  /**
67
73
  * Parameters required to register a decorator
68
- * @beta
74
+ * @public
69
75
  */
70
76
  interface RegisterDecoratorParameters {
71
77
  /**
@@ -75,7 +81,8 @@ interface RegisterDecoratorParameters {
75
81
  }
76
82
 
77
83
  /**
78
- * @beta
84
+ * Used for adding collators, decorators and compile them into tasks which are added to a scheduler returned to the caller.
85
+ * @public
79
86
  */
80
87
  declare class IndexBuilder {
81
88
  private collators;
@@ -84,7 +91,13 @@ declare class IndexBuilder {
84
91
  private searchEngine;
85
92
  private logger;
86
93
  constructor({ logger, searchEngine }: IndexBuilderOptions);
94
+ /**
95
+ * Responsible for returning the registered search engine.
96
+ */
87
97
  getSearchEngine(): SearchEngine;
98
+ /**
99
+ * Responsible for returning the registered document types.
100
+ */
88
101
  getDocumentTypes(): Record<string, DocumentTypeInfo>;
89
102
  /**
90
103
  * Makes the index builder aware of a collator that should be executed at the
@@ -107,7 +120,68 @@ declare class IndexBuilder {
107
120
  }
108
121
 
109
122
  /**
110
- * @beta
123
+ * Options for instansiate NewlineDelimitedJsonCollatorFactory
124
+ * @public
125
+ */
126
+ declare type NewlineDelimitedJsonCollatorFactoryOptions = {
127
+ type: string;
128
+ searchPattern: string;
129
+ reader: UrlReader;
130
+ logger: Logger;
131
+ visibilityPermission?: Permission;
132
+ };
133
+ /**
134
+ * Factory class producing a collator that can be used to index documents
135
+ * sourced from the latest newline delimited JSON file matching a given search
136
+ * pattern. "Latest" is determined by the name of the file (last alphabetically
137
+ * is considered latest).
138
+ *
139
+ * @remarks
140
+ * The reader provided must implement the `search()` method as well as the
141
+ * `readUrl` method whose response includes the `stream()` method. Naturally,
142
+ * the reader must also be configured to understand the given search pattern.
143
+ *
144
+ * @example
145
+ * Here's an example configuration using Google Cloud Storage, which would
146
+ * return the latest file under the `bucket` GCS bucket with files like
147
+ * `xyz-2021.ndjson` or `xyz-2022.ndjson`.
148
+ * ```ts
149
+ * indexBuilder.addCollator({
150
+ * schedule,
151
+ * factory: NewlineDelimitedJsonCollatorFactory.fromConfig(env.config, {
152
+ * type: 'techdocs',
153
+ * searchPattern: 'https://storage.cloud.google.com/bucket/xyz-*',
154
+ * reader: env.reader,
155
+ * logger: env.logger,
156
+ * })
157
+ * });
158
+ * ```
159
+ *
160
+ * @public
161
+ */
162
+ declare class NewlineDelimitedJsonCollatorFactory implements DocumentCollatorFactory {
163
+ private readonly searchPattern;
164
+ private readonly reader;
165
+ private readonly logger;
166
+ readonly type: string;
167
+ readonly visibilityPermission: Permission | undefined;
168
+ private constructor();
169
+ /**
170
+ * Returns a NewlineDelimitedJsonCollatorFactory instance from configuration
171
+ * and a set of options.
172
+ */
173
+ static fromConfig(_config: Config, options: NewlineDelimitedJsonCollatorFactoryOptions): NewlineDelimitedJsonCollatorFactory;
174
+ /**
175
+ * Returns the "latest" URL for the given search pattern (e.g. the one at the
176
+ * end of the list, sorted alphabetically).
177
+ */
178
+ private lastUrl;
179
+ getCollator(): Promise<Readable>;
180
+ }
181
+
182
+ /**
183
+ * Options for {@link BatchSearchEngineIndexer}
184
+ * @public
111
185
  */
112
186
  declare type BatchSearchEngineOptions = {
113
187
  batchSize: number;
@@ -115,7 +189,7 @@ declare type BatchSearchEngineOptions = {
115
189
  /**
116
190
  * Base class encapsulating batch-based stream processing. Useful as a base
117
191
  * class for search engine indexers.
118
- * @beta
192
+ * @public
119
193
  */
120
194
  declare abstract class BatchSearchEngineIndexer extends Writable {
121
195
  private batchSize;
@@ -141,7 +215,7 @@ declare abstract class BatchSearchEngineIndexer extends Writable {
141
215
  /**
142
216
  * Base class encapsulating simple async transformations. Useful as a base
143
217
  * class for Backstage search decorators.
144
- * @beta
218
+ * @public
145
219
  */
146
220
  declare abstract class DecoratorBase extends Transform {
147
221
  private initialized;
@@ -167,7 +241,8 @@ declare abstract class DecoratorBase extends Transform {
167
241
  }
168
242
 
169
243
  /**
170
- * @beta
244
+ * Lunr specific search engine indexer
245
+ * @public
171
246
  */
172
247
  declare class LunrSearchEngineIndexer extends BatchSearchEngineIndexer {
173
248
  private schemaInitialized;
@@ -182,7 +257,8 @@ declare class LunrSearchEngineIndexer extends BatchSearchEngineIndexer {
182
257
  }
183
258
 
184
259
  /**
185
- * @beta
260
+ * Type of translated query for the Lunr Search Engine.
261
+ * @public
186
262
  */
187
263
  declare type ConcreteLunrQuery = {
188
264
  lunrQueryBuilder: lunr.Index.QueryBuilder;
@@ -190,11 +266,13 @@ declare type ConcreteLunrQuery = {
190
266
  pageSize: number;
191
267
  };
192
268
  /**
193
- * @beta
269
+ * Translator repsonsible for translating search term and filters to a query that the Lunr Search Engine understands.
270
+ * @public
194
271
  */
195
272
  declare type LunrQueryTranslator = (query: SearchQuery) => ConcreteLunrQuery;
196
273
  /**
197
- * @beta
274
+ * Lunr specific search engine implementation.
275
+ * @public
198
276
  */
199
277
  declare class LunrSearchEngine implements SearchEngine {
200
278
  protected lunrIndices: Record<string, lunr.Index>;
@@ -213,7 +291,7 @@ declare class LunrSearchEngine implements SearchEngine {
213
291
 
214
292
  /**
215
293
  * Object resolved after a test pipeline is executed.
216
- * @beta
294
+ * @public
217
295
  */
218
296
  declare type TestPipelineResult = {
219
297
  /**
@@ -229,7 +307,7 @@ declare type TestPipelineResult = {
229
307
  };
230
308
  /**
231
309
  * Test utility for Backstage Search collators, decorators, and indexers.
232
- * @beta
310
+ * @public
233
311
  */
234
312
  declare class TestPipeline {
235
313
  private collator?;
@@ -251,4 +329,4 @@ declare class TestPipeline {
251
329
  execute(): Promise<TestPipelineResult>;
252
330
  }
253
331
 
254
- export { BatchSearchEngineIndexer, BatchSearchEngineOptions, ConcreteLunrQuery, DecoratorBase, IndexBuilder, IndexBuilderOptions, LunrQueryTranslator, LunrSearchEngine, LunrSearchEngineIndexer, RegisterCollatorParameters, RegisterDecoratorParameters, ScheduleTaskParameters, Scheduler, TestPipeline, TestPipelineResult };
332
+ export { BatchSearchEngineIndexer, BatchSearchEngineOptions, ConcreteLunrQuery, DecoratorBase, IndexBuilder, IndexBuilderOptions, LunrQueryTranslator, LunrSearchEngine, LunrSearchEngineIndexer, NewlineDelimitedJsonCollatorFactory, NewlineDelimitedJsonCollatorFactoryOptions, RegisterCollatorParameters, RegisterDecoratorParameters, ScheduleTaskParameters, Scheduler, TestPipeline, TestPipelineResult };
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.6.1",
4
+ "version": "0.6.2-next.2",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -23,22 +23,27 @@
23
23
  "clean": "backstage-cli package clean"
24
24
  },
25
25
  "dependencies": {
26
- "@backstage/backend-tasks": "^0.3.1",
26
+ "@backstage/backend-common": "^0.14.0-next.2",
27
+ "@backstage/backend-tasks": "^0.3.2-next.2",
28
+ "@backstage/config": "^1.0.1",
27
29
  "@backstage/errors": "^1.0.0",
28
- "@backstage/plugin-search-common": "^0.3.4",
30
+ "@backstage/plugin-permission-common": "^0.6.2-next.0",
31
+ "@backstage/plugin-search-common": "^0.3.5-next.1",
29
32
  "@types/lunr": "^2.3.3",
30
33
  "lodash": "^4.17.21",
31
34
  "lunr": "^2.3.9",
35
+ "ndjson": "^2.0.0",
32
36
  "node-abort-controller": "^3.0.1",
33
37
  "uuid": "^8.3.2",
34
38
  "winston": "^3.2.1"
35
39
  },
36
40
  "devDependencies": {
37
- "@backstage/backend-common": "^0.13.3",
38
- "@backstage/cli": "^0.17.1"
41
+ "@backstage/backend-common": "^0.14.0-next.2",
42
+ "@backstage/cli": "^0.17.2-next.2",
43
+ "@types/ndjson": "^2.0.1"
39
44
  },
40
45
  "files": [
41
46
  "dist"
42
47
  ],
43
- "gitHead": "96323f280ba32ee526c5b151cda42260aee927c9"
48
+ "gitHead": "afc672d59763a835574e6c47819107d22cfd1ad7"
44
49
  }