Repository navigation
Convert providers/harvest/ to TypeScript - #1548
Conversation
There was a problem hiding this comment.
Pull request overview
Converts the providers/harvest/ area from paired .js + .d.ts modules into native .ts implementations and updates runtime/test import paths accordingly (including harvest throttling and crawler queue components).
Changes:
- Replaced multiple
providers/harvest/**.js+.d.tspairs with.tssources and migrated JSDoc typedefs to TypeScript types/interfaces. - Updated application/provider wiring (
app.js,providers/index.js) and test imports to reference the new.tsmodules. - Introduced/ported the cache-based harvester implementation to TypeScript (
providers/harvest/cacheBasedCrawler.ts) and removed legacy JS/DTs counterparts.
Show a summary per file
| File | Description |
|---|---|
| test/routes/harvest.ts | Updates throttling import to the new .ts module. |
| test/providers/harvest/throttling/listBasedFilterTest.ts | Updates import path to .ts throttling filter. |
| test/providers/harvest/throttling/listBasedFilterConfigTest.ts | Updates esmock target to .ts config module. |
| test/providers/harvest/processTest.ts | Updates import to .ts harvest processor. |
| test/providers/harvest/crawlerConfig.ts | Updates esmock targets for crawler config/crawler modules to .ts. |
| test/providers/harvest/cacheBasedCrawlerTest.ts | Updates import to .ts cache-based crawler/harvester. |
| providers/index.js | Switches harvest provider imports (and throttler config) to .ts modules. |
| providers/harvest/throttling/listBasedFilterConfig.ts | Converts config factory to TS types and imports the .ts filter. |
| providers/harvest/throttling/listBasedFilterConfig.d.ts | Removed (types now live in .ts). |
| providers/harvest/throttling/listBasedFilter.ts | Converts filter implementation and options typing to TypeScript. |
| providers/harvest/throttling/listBasedFilter.d.ts | Removed (types now live in .ts). |
| providers/harvest/process.ts | Converts harvest queue processor to TS, adds typed imports and additional guards. |
| providers/harvest/process.d.ts | Removed (types now live in .ts). |
| providers/harvest/crawlerQueueConfig.ts | Converts crawler-queue service factory to TS and adds option typing. |
| providers/harvest/crawlerQueueConfig.d.ts | Removed (types now live in .ts). |
| providers/harvest/crawlerQueue.ts | Converts queue-backed harvester to TS and exports typed options/class. |
| providers/harvest/crawlerQueue.d.ts | Removed (types now live in .ts). |
| providers/harvest/crawlerConfig.ts | Converts HTTP crawler service factory to TS and adds option typing. |
| providers/harvest/crawlerConfig.d.ts | Removed (types now live in .ts). |
| providers/harvest/crawler.ts | Converts HTTP crawler harvester to TS and exports typed options/class. |
| providers/harvest/crawler.d.ts | Removed (types now live in .ts). |
| providers/harvest/cacheBasedCrawler.ts | Adds TS implementation for cache-based harvest tracking and concurrency control. |
| providers/harvest/cacheBasedCrawler.js | Removed (replaced by .ts). |
| providers/harvest/cacheBasedCrawler.d.ts | Removed (types now live in .ts). |
| providers/harvest/azureQueueConfig.ts | Converts Azure queue config factory to TS signature. |
| providers/harvest/azureQueueConfig.d.ts | Removed (types now live in .ts). |
| app.js | Updates harvest processing import to the new .ts processor module. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (6)
providers/harvest/throttling/listBasedFilter.ts:28
versionlessCoordinatesis inferred as(EntityCoordinates | null)[]because.filter(Boolean)is not a type guard under strict TS settings. That makes the subsequentmap(c => c.type)/map(c => c.toString())unsafe and can fail type-checking. Use an explicit type predicate in the filter (e.g., filter toc !== null) so the array isEntityCoordinates[].
providers/harvest/process.ts:48toolRevisionis optional inparseUrn()output, butcomputeAndStoreIfNecessaryrequires astring. The non-null assertion (toolRevision!) only silences the compiler and can still passundefinedat runtime, breaking tool-result tracking. Add an explicitif (!toolRevision) { ... }handling (e.g., log + return, or treat as invalid message) before callingcomputeAndStoreIfNecessary.
providers/harvest/crawlerQueue.ts:34IQueue.queue()returns aPromise<void>, but the enqueues here are not awaited. As a result,harvest()can resolve before messages are actually written, and any enqueue rejection becomes unhandled. Await thequeue()calls (sequentially or viaPromise.all) soharvest()only resolves after all messages are queued.
providers/harvest/crawlerQueueConfig.ts:40initialize()returns a promise onIQueue, but these calls are not awaited. If initialization is asynchronous (e.g., Azure queue), the returned harvester may start using queues before they're ready, and initialization errors will be dropped. Consider makingserviceFactoryasync and awaiting both initializations (or otherwise ensure initialization happens before use).
providers/harvest/crawlerConfig.ts:26CrawlerConfigOptionsrequirescachingService, butserviceFactoryallowsoptionsto be omitted. IfserviceFactory()is ever called without args, it will passundefinedcachingService intocacheBasedCrawler(...)and fail at runtime. Consider makingoptionsrequired (or providing a safe default / explicit error) to match the type contract.
providers/harvest/crawlerQueueConfig.ts:44CrawlerQueueConfigOptionsrequirescachingService, butserviceFactorydeclaresoptions?. If called without args,cacheBasedCrawler({ ...options, ... })will omitcachingServiceand can throw at construction time. Consider makingoptionsrequired (or explicitly validating and throwing a clear error) to align runtime behavior with the declared options interface.
- Files reviewed: 18/27 changed files
- Comments generated: 1
569f162 to
d912865
Compare
There was a problem hiding this comment.
Pull request overview
Converts the providers/harvest/ implementation (including throttling and crawler/queue wiring) from paired .js + .d.ts files into consolidated .ts sources, and updates imports across runtime and tests accordingly.
Changes:
- Update application and test imports to reference the new
.tsharvest provider modules. - Migrate harvest provider modules (crawler, queue crawler, cache-based crawler, processing, throttling config/filter) to TypeScript and remove corresponding
.d.tsfiles. - Introduce explicit TS interfaces/types for harvest provider configuration and harvester contracts.
Show a summary per file
| File | Description |
|---|---|
| test/routes/harvest.ts | Update throttling filter import to .ts. |
| test/providers/harvest/throttling/listBasedFilterTest.ts | Update throttling filter import to .ts. |
| test/providers/harvest/throttling/listBasedFilterConfigTest.ts | Update esmock target to .ts config module. |
| test/providers/harvest/processTest.ts | Update harvest process import to .ts. |
| test/providers/harvest/crawlerConfig.ts | Update esmock targets for crawler config + crawler modules to .ts. |
| test/providers/harvest/cacheBasedCrawlerTest.ts | Update cache-based crawler import to .ts. |
| providers/index.js | Switch harvest provider imports to .ts modules. |
| providers/harvest/throttling/listBasedFilterConfig.ts | Convert throttler factory/config parsing module to TS and inline types. |
| providers/harvest/throttling/listBasedFilterConfig.d.ts | Removed (types merged into .ts). |
| providers/harvest/throttling/listBasedFilter.ts | Convert throttling filter implementation to TS and inline option types. |
| providers/harvest/throttling/listBasedFilter.d.ts | Removed (types merged into .ts). |
| providers/harvest/process.ts | Convert queue processor to TS and add additional parsing guards. |
| providers/harvest/process.d.ts | Removed (types merged into .ts). |
| providers/harvest/crawlerQueueConfig.ts | Convert queue-crawler config factory to TS and inline option types. |
| providers/harvest/crawlerQueueConfig.d.ts | Removed (types merged into .ts). |
| providers/harvest/crawlerQueue.ts | Convert queue-based harvester to TS and export option types/class. |
| providers/harvest/crawlerQueue.d.ts | Removed (types merged into .ts). |
| providers/harvest/crawlerConfig.ts | Convert HTTP crawler config factory to TS and inline option types. |
| providers/harvest/crawlerConfig.d.ts | Removed (types merged into .ts). |
| providers/harvest/crawler.ts | Convert HTTP crawler harvester to TS and export option types/class. |
| providers/harvest/crawler.d.ts | Removed (types merged into .ts). |
| providers/harvest/cacheBasedCrawler.ts | Add TS implementation for cache-based harvester and its exported types. |
| providers/harvest/cacheBasedCrawler.js | Removed (replaced by .ts). |
| providers/harvest/cacheBasedCrawler.d.ts | Removed (types merged into .ts). |
| providers/harvest/azureQueueConfig.ts | Convert Azure queue config factory to TS (typed options). |
| providers/harvest/azureQueueConfig.d.ts | Removed (types merged into .ts). |
| app.js | Update harvest processor import to .ts. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (3)
providers/harvest/process.ts:43
processMessagereturns early whencoordinatesortoolare missing, which skipsqueue.delete(message)and leaves the message in the queue without any logging. If these cases represent malformed/unsupported events, consider logging a warning and deleting (or dead-lettering) the message to avoid infinite retries/queue buildup.
providers/harvest/process.ts:48- Avoid using the non-null assertion on
toolRevision.parseUrn()returnstoolRevision?: string, and at runtime this can still beundefined, which then gets passed intocomputeAndStoreIfNecessary(expects astring) and can break tool-result deduping (e.g.,tool/undefined). ValidatetoolRevision(and decide whether to delete/dead-letter the message) or provide a safe default before calling the definition service.
providers/harvest/crawler.ts:31 - The debug log
JSON.stringify(headers)includes theX-tokenauth token. Even at debug level this can leak secrets into logs. Consider removing this log line or redacting/masking the token value before logging.
- Files reviewed: 18/27 changed files
- Comments generated: 1
17f3527 to
aec304a
Compare
There was a problem hiding this comment.
Pull request overview
Converts the providers/harvest/ provider set from mixed .js + .d.ts pairs into native .ts modules and updates all internal/test import paths accordingly (including throttling and crawler queue integration).
Changes:
- Migrated harvest provider modules (crawler, queue harvester, cache wrapper, throttling, process runner, queue config) to TypeScript and removed corresponding
.d.ts/.jsartifacts. - Updated runtime and configuration wiring (
app.js,providers/index.js) to import the new.tsharvest modules. - Updated tests to import the new
.tsharvest modules and config factories.
Show a summary per file
| File | Description |
|---|---|
| app.js | Switches harvest processing import to the new TypeScript module. |
| providers/index.js | Updates harvest-related provider wiring to import .ts implementations. |
| providers/harvest/process.ts | Converts queue processor to TS and tightens URN parsing/processing types. |
| providers/harvest/cacheBasedCrawler.ts | Introduces TS version of cache-based harvester and consolidates types. |
| providers/harvest/crawler.ts | Converts HTTP crawler harvester to TS with explicit option/types. |
| providers/harvest/crawlerConfig.ts | Converts crawler service factory to TS and merges type definitions. |
| providers/harvest/crawlerQueue.ts | Converts queue-based harvester to TS and merges type definitions. |
| providers/harvest/crawlerQueueConfig.ts | Converts queue crawler service factory to TS and merges type definitions. |
| providers/harvest/azureQueueConfig.ts | Converts harvest queue factory to TS and removes redundant typedefs. |
| providers/harvest/throttling/listBasedFilter.ts | Converts throttling filter to TS and inlines option typings. |
| providers/harvest/throttling/listBasedFilterConfig.ts | Converts throttler factory to TS and removes separate .d.ts. |
| test/routes/harvest.ts | Updates test imports to point at the new TS throttling filter. |
| test/providers/harvest/processTest.ts | Updates test import to new TS harvest processor. |
| test/providers/harvest/cacheBasedCrawlerTest.ts | Updates test import to new TS cache-based crawler. |
| test/providers/harvest/crawlerConfig.ts | Updates esmock wiring to use the TS crawler config & modules. |
| test/providers/harvest/throttling/listBasedFilterTest.ts | Updates test import to TS throttling filter. |
| test/providers/harvest/throttling/listBasedFilterConfigTest.ts | Updates esmock wiring to use TS throttler config. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (3)
providers/harvest/process.ts:48
toolRevisionfromparseUrn()can beundefined(URNs without a tool revision). The non-null assertion (toolRevision!) can hide real runtime cases and will end up passingundefinedintocomputeAndStoreIfNecessary, which expects a string. Add a guard for missingtoolRevision(or derive a default) before callingcomputeAndStoreIfNecessaryso the behavior is explicit and safe.
providers/harvest/crawlerQueueConfig.ts:36optionsis optional here, butCacheBasedHarvesterrequirescachingServiceandserviceFactorywill ultimately pass through tocacheBasedCrawler(...). As written, callingserviceFactory()without arguments is allowed by the type signature but will fail at runtime whencachingServiceis missing. Either makeoptionsrequired, or keep it optional but add an explicit runtime check and throw a clear error whencachingServiceisn’t provided.
providers/harvest/crawlerConfig.ts:25optionsis marked optional, butCrawlerConfigOptionsrequirescachingServiceandcacheBasedCrawler(...)will fail if it’s absent. Consider makingoptionsrequired or adding a runtime validation with a clear error message whencachingServiceis missing, so the API contract matches actual requirements.
- Files reviewed: 18/27 changed files
- Comments generated: 1
There was a problem hiding this comment.
Pull request overview
Converts the providers/harvest/ provider implementations (including throttling and queue/crawler components) from .js + .d.ts pairs into consolidated .ts modules, and updates runtime and test import paths accordingly.
Changes:
- Replaced Harvest provider
.jsimplementations and accompanying.d.tsfiles with.tssources (e.g., crawler, queue crawler, cache-based crawler, throttling filter/config, processing). - Updated application and provider registry imports to reference the new
.tsmodules. - Updated unit/integration tests and
esmockpaths to target the TypeScript modules.
Show a summary per file
| File | Description |
|---|---|
| app.js | Updates Harvest processor import to the new .ts module. |
| providers/index.js | Points Harvest provider wiring to .ts implementations (crawler, queue crawler, throttler config). |
| providers/harvest/azureQueueConfig.ts | Converts queue config factory typing from JSDoc to TS. |
| providers/harvest/azureQueueConfig.d.ts | Removed (types now live in .ts). |
| providers/harvest/cacheBasedCrawler.ts | New TS implementation replacing prior .js + .d.ts. |
| providers/harvest/cacheBasedCrawler.js | Removed (superseded by .ts). |
| providers/harvest/cacheBasedCrawler.d.ts | Removed (types now live in .ts). |
| providers/harvest/crawler.ts | Converts HTTP crawler harvester to TS with exported types/classes. |
| providers/harvest/crawler.d.ts | Removed (types now live in .ts). |
| providers/harvest/crawlerConfig.ts | Converts crawler service factory to TS and updates imports. |
| providers/harvest/crawlerConfig.d.ts | Removed (types now live in .ts). |
| providers/harvest/crawlerQueue.ts | Converts queue-based harvester to TS with exported types/classes. |
| providers/harvest/crawlerQueue.d.ts | Removed (types now live in .ts). |
| providers/harvest/crawlerQueueConfig.ts | Converts queue crawler factory/config to TS and updates imports. |
| providers/harvest/crawlerQueueConfig.d.ts | Removed (types now live in .ts). |
| providers/harvest/process.ts | Converts harvest queue processing to TS and tightens some runtime guards. |
| providers/harvest/process.d.ts | Removed (types now live in .ts). |
| providers/harvest/throttling/listBasedFilter.ts | Converts throttling filter implementation to TS and inlines options typing. |
| providers/harvest/throttling/listBasedFilter.d.ts | Removed (types now live in .ts). |
| providers/harvest/throttling/listBasedFilterConfig.ts | Converts throttler factory/config parsing to TS. |
| providers/harvest/throttling/listBasedFilterConfig.d.ts | Removed (types now live in .ts). |
| test/routes/harvest.ts | Updates throttler filter import to .ts. |
| test/providers/harvest/cacheBasedCrawlerTest.ts | Updates cache-based crawler import to .ts. |
| test/providers/harvest/crawlerConfig.ts | Updates esmock paths to .ts modules. |
| test/providers/harvest/processTest.ts | Updates harvest process import to .ts. |
| test/providers/harvest/throttling/listBasedFilterTest.ts | Updates filter import to .ts. |
| test/providers/harvest/throttling/listBasedFilterConfigTest.ts | Updates esmock path to .ts. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (4)
providers/harvest/process.ts:48
toolRevisioncan beundefinedfor URNs that don’t include a tool revision (seeparseUrninlib/utils.ts, which returns split parts as-is). The non-null assertion (toolRevision!) makes this easy to miss and can lead tocomputeAndStoreIfNecessarybeing called withundefinedat runtime. Please explicitly handle the missing revision (e.g., return early with a warning/log, or derive a default) before callingcomputeAndStoreIfNecessary.
providers/harvest/crawlerConfig.ts:24CrawlerConfigOptionsrequirescachingService, butserviceFactorycurrently makesoptionsoptional. This allows callers to invokeserviceFactory()without providing a cache, which will fail at runtime whencacheBasedCrawlerexpectscachingService. Consider makingoptionsnon-optional (or providing a safe default/explicit error when it’s missing).
providers/harvest/crawlerQueueConfig.ts:37CrawlerQueueConfigOptionsrequirescachingService, butserviceFactoryacceptsoptions?. This makes it possible to callserviceFactory()without the required cache and then pass an invalid options object intocacheBasedCrawler. Please makeoptionsrequired (or throw a clear error whencachingServiceisn’t provided).
providers/harvest/throttling/listBasedFilterConfig.ts:12parseListEnvis declared to returnstring[], but the implementation returns the rawJSON.parseresult after only checkingArray.isArray. This can include non-string items (numbers/objects), which violates the return type and relies on downstream code to tolerate invalid entries. Please validate/filter the parsed array to strings before returning it (and optionally warn/drop invalid items).
- Files reviewed: 18/27 changed files
- Comments generated: 0 new
qtomlinson
left a comment
There was a problem hiding this comment.
Follow-up suggestion: tighten HarvestEntry.coordinates back to EntityCoordinates
The widening to EntityCoordinates | string is currently needed to accommodate routes/harvest.js:139:
return { ...entry, coordinates: normalized.toString() }As a follow-up, consider passing the object directly instead:
return { ...entry, coordinates: normalized }This would allow HarvestEntry.coordinates to be kept as EntityCoordinates only. The POST /harvest route and its unit tests would need to be reviewed and adjusted accordingly.
Merge 9
.js+.d.tspairs into.tsinproviders/harvest/(incl. throttling).Review commit-by-commit: renames, import paths, type merges.