Skip to content

Conversation

@JamieMagee
Copy link
Contributor

@JamieMagee JamieMagee commented Jan 27, 2026

  • Cast catch block errors to any so we can check error.code and error.statusCode
  • Call Buffer.toString() before JSON.parse() in fileAttachmentStore (was passing Buffer directly)
  • Rename unused parameters with underscore prefix (_result, _coordinates) instead of eslint-disable comments
  • Wrap forEach callback in braces to avoid returning the result of delete expression
  • Use Type suffix for typedef imports to avoid shadowing require() constants

Why these changes

The existing code worked fine at runtime but had patterns that confused the type checker. For example, catching an error and immediately accessing error.code fails because caught values are unknown by default. The Buffer issue was a real bug waiting to happen on some Node versions.

…tations

Several JavaScript changes were needed to satisfy the type checker:

- Cast catch block errors to any (e.g., catch (/** @type {any} */ error))
  to access error.code and error.statusCode properties
- Call Buffer.toString() before JSON.parse in fileAttachmentStore
- Rename unused parameters with underscore prefix (_result, _coordinates)
  to signal intentional non-use
- Wrap forEach callbacks in braces to avoid returning delete expression
- Use Type suffix for typedef imports to avoid shadowing require() consts

The abstract store base classes now accept both EntityCoordinates and
ResultCoordinates in list/get methods, matching how subclasses actually
use them.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves type safety and error handling across the store implementations by adding comprehensive TypeScript definitions and JSDoc annotations. The changes address several type-checker issues and fix a potential bug with Buffer handling.

Changes:

  • Added TypeScript definition files (.d.ts) for 12 store implementation files to improve type checking
  • Fixed Buffer.toString() calls before JSON.parse() in attachment and harvest stores to prevent potential runtime errors
  • Improved error handling by properly typing caught errors with @type {any} annotations where error properties are accessed
  • Replaced eslint-disable comments with underscore-prefixed parameter names for unused parameters
  • Added comprehensive JSDoc documentation to all store classes and methods
  • Used Type suffix for typedef imports to avoid shadowing require() constants

Reviewed changes

Copilot reviewed 13 out of 30 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tsconfig.json Added new .d.ts and .js files to TypeScript configuration
trimmedMongoDefinitionStore.js/.d.ts Added TypeScript definitions and JSDoc, wrapped forEach callback, renamed unused parameters
mongoConfig.js/.d.ts Added TypeScript definitions and JSDoc for factory functions
mongo.js/.d.ts Added TypeScript definitions, JSDoc, wrapped forEach callback, used bracket notation for property access
fileHarvestStore.js/.d.ts Added TypeScript definitions, JSDoc, fixed Buffer.toString(), typed error catches
fileDefinitionStore.js/.d.ts Added TypeScript definitions, JSDoc, typed error catches, renamed unused parameters
fileConfig.js/.d.ts Added TypeScript definitions and JSDoc for factory functions
fileAttachmentStore.js/.d.ts Added TypeScript definitions, JSDoc, fixed Buffer.toString(), typed error catches
dispatchDefinitionStore.js/.d.ts Added TypeScript definitions and JSDoc for dispatch store
dispatchConfig.js/.d.ts Added TypeScript definitions and JSDoc for dispatch configuration
azblobHarvestStore.js/.d.ts Added TypeScript definitions, JSDoc, renamed unused parameter
azblobDefinitionStore.js/.d.ts Added TypeScript definitions, JSDoc, typed error catches
azblobConfig.js/.d.ts Added TypeScript definitions and JSDoc for Azure Blob configuration
azblobAttachmentStore.js/.d.ts Added TypeScript definitions, JSDoc, typed error catches
abstractMongoDefinitionStore.d.ts Changed export pattern from export default to export =
abstractFileStore.d.ts Changed export pattern and updated type signatures
abstractAzblobStore.d.ts Changed export pattern from export default to export =

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const definitionDoc = clone(definition)
definitionDoc._id = this.getId(definition.coordinates)
delete definitionDoc.files
delete definitionDoc['files']
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent property access notation: This line uses bracket notation definitionDoc['files'], but similar delete operations elsewhere (e.g., line 61 with def._id and line 80 in mongo.js with def._mongo) use dot notation. Consider using dot notation for consistency unless there's a specific reason to use bracket notation.

Suggested change
delete definitionDoc['files']
delete definitionDoc.files

Copilot uses AI. Check for mistakes.
await cursor.forEach(
/** @param {any} page */ page => {
if (!definition) definition = page
else definition.files = definition.files.concat(page['files'])
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent property access notation: This line uses bracket notation page['files'], but similar property access elsewhere in the file (e.g., line 80 with def._mongo) uses dot notation. Consider using dot notation for consistency unless there's a specific reason to use bracket notation.

Suggested change
else definition.files = definition.files.concat(page['files'])
else definition.files = definition.files.concat(page.files)

Copilot uses AI. Check for mistakes.
const list = await super.list(
coordinates,
/** @param {BlobEntry} entry */ entry => {
const path = entry.metadata['id']
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent property access notation: This line uses bracket notation entry.metadata['id'], but dot notation is more commonly used elsewhere in the codebase. Consider using entry.metadata.id for consistency unless there's a specific reason to use bracket notation.

Suggested change
const path = entry.metadata['id']
const path = entry.metadata.id

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants