Skip to content

fix: migrates another part of indexer to strict types#2686

Open
stalniy wants to merge 1 commit intomainfrom
fix/indexer-strict-types2
Open

fix: migrates another part of indexer to strict types#2686
stalniy wants to merge 1 commit intomainfrom
fix/indexer-strict-types2

Conversation

@stalniy
Copy link
Contributor

@stalniy stalniy commented Feb 6, 2026

Why

to improve reliability on indexer

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation of identity data with proper null/empty checks.
    • Enhanced robustness of resource data processing with safer handling of missing or undefined fields.
    • Better error recovery when processing provider status information.
  • Refactor

    • Strengthened data validation and type safety across indexer modules.

@stalniy stalniy requested a review from a team as a code owner February 6, 2026 22:25
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

This PR introduces TypeScript type safety improvements across the indexer module by adding optional chaining guards for GRPC data access, updating function signatures to handle undefined inputs, and expanding strict type checking configuration. Input validation is also enhanced for identifier processing.

Changes

Cohort / File(s) Summary
Type Safety & Optional Chaining
apps/indexer/src/providers/statusEndpointHandlers/grpc.ts, apps/indexer/src/shared/utils/files.ts
Updated GRPC nested field access with optional chaining for cluster, inventory, storage, and resource data; broadened helper functions (parseResources, parseNodeResources) to accept undefined inputs with safe fallbacks; updated queryStatus signature to return Promise.
Configuration & Strict Scope
apps/indexer/tsconfig.strict.json
Expanded strict TypeScript compilation scope to include providers, database connection, keybase provider, and price history provider source files.
Input Validation
apps/indexer/src/db/keybaseProvider.ts
Added regex validation for 16-character hex identity strings with warning log for invalid/missing identities before processing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • ygrishajev
  • baktun14

Poem

🐰 Optional chains link the data flow,
Undefined guards say "whoa, whoa, whoa!"
Identity checks with regex tight,
Strict configs making types all right,
Safety bounds through the indexer we go! 🔐

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the changeset - migrating the indexer codebase to use strict TypeScript types across multiple files and helper functions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/indexer-strict-types2

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
apps/indexer/src/providers/statusEndpointHandlers/grpc.ts (1)

90-90: Double type cast as unknown as hides potential type mismatch.

This casting pattern bypasses TypeScript's type checking entirely. If there's a mismatch between the storage variable structure and ProviderStatusInfo["storage"], it will cause runtime issues.

Consider investigating why the types don't align and either:

  1. Adjust the mapping to produce the correct type directly, or
  2. Create an explicit type guard or transformation function

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
apps/indexer/src/shared/utils/files.ts (1)

38-53: ⚠️ Potential issue | 🟠 Major

Use LoggerService instead of console.error for logging errors.

Both parseSizeStr (line 51) and parseDecimalKubernetesString (line 79) use console.error which violates the logging standard. Replace with LoggerService.forContext() or remove the redundant logging before the error is thrown.

apps/indexer/src/db/keybaseProvider.ts (1)

14-35: ⚠️ Potential issue | 🟠 Major

Replace console.* logging with LoggerService.

The code uses console.warn (line 15), console.log (line 19), and console.error (line 34) for logging. Per the coding guidelines, use LoggerService instead to comply with the project's standardized logging approach.

apps/indexer/src/providers/statusEndpointHandlers/grpc.ts (1)

13-38: ⚠️ Potential issue | 🔴 Critical

Guard .map() and .includes() calls against undefined values.

The optional chaining on data.cluster?.inventory?.cluster?.nodes (line 15) and ...storage (line 34) returns undefined if any intermediate property is falsy, and calling .map() directly on undefined will throw a TypeError. Similarly, node.capabilities?.storageClasses.includes() on lines 71–73 uses incomplete optional chaining—if node.capabilities is undefined, the .includes() call will throw. Additionally, the double cast on line 90 (as unknown as ProviderStatusInfo["storage"]) can be avoided by properly typing storage at declaration (line 34). Update getAvailableResources to accept NodeResources | undefined to remove the non-null assertion on line 16.

Proposed fix
-  const availableResources = data.cluster?.inventory?.cluster?.nodes
-    .map(x => getAvailableResources(x.resources!))
+  const nodes = data.cluster?.inventory?.cluster?.nodes ?? [];
+  const availableResources = nodes
+    .map(x => getAvailableResources(x.resources))
     .reduce(
       (prev, next) => ({
         cpu: prev.cpu + next.cpu,
@@
-  const storage = data.cluster?.inventory?.cluster?.storage.map(storage => ({
+  const storage: ProviderStatusInfo["storage"] = (data.cluster?.inventory?.cluster?.storage ?? []).map(storage => ({
     class: storage?.info?.class,
     allocatable: parseSizeStr(storage?.quantity?.allocatable?.string),
     allocated: parseSizeStr(storage?.quantity?.allocated?.string)
   }));
@@
-    storage: storage as unknown as ProviderStatusInfo["storage"]
+    storage
   };
 }
@@
-function getAvailableResources(resources: NodeResources) {
+function getAvailableResources(resources: NodeResources | undefined) {
@@
-        capabilitiesStorageHDD: !!node.capabilities?.storageClasses.includes("beta1"),
-        capabilitiesStorageSSD: !!node.capabilities?.storageClasses.includes("beta2"),
-        capabilitiesStorageNVME: !!node.capabilities?.storageClasses.includes("beta3"),
+        capabilitiesStorageHDD: !!node.capabilities?.storageClasses?.includes("beta1"),
+        capabilitiesStorageSSD: !!node.capabilities?.storageClasses?.includes("beta2"),
+        capabilitiesStorageNVME: !!node.capabilities?.storageClasses?.includes("beta3"),
🤖 Fix all issues with AI agents
In `@apps/indexer/src/providers/statusEndpointHandlers/grpc.ts`:
- Around line 71-73: The three capability booleans (capabilitiesStorageHDD,
capabilitiesStorageSSD, capabilitiesStorageNVME) call
node.capabilities?.storageClasses.includes(...), which can throw if
storageClasses is undefined; update each to safely check with optional chaining
and a default (e.g., node.capabilities?.storageClasses?.includes(...) ?? false)
so the expression returns false instead of throwing when storageClasses is
missing. Locate these symbols in grpc.ts and apply the change to all three
lines.
🧹 Nitpick comments (1)
apps/indexer/tsconfig.build.json (1)

2-8: Confirm noImplicitAny override is intended with strict enabled.

With "strict": true, the explicit "noImplicitAny": false disables a core strictness check. If the goal is full strictness, consider removing the override or setting it to true; otherwise please confirm it’s intentional.

Suggested adjustment
-    "noImplicitAny": false,
+    "noImplicitAny": true,

baktun14
baktun14 previously approved these changes Feb 6, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@apps/indexer/src/providers/statusEndpointHandlers/grpc.ts`:
- Around line 15-16: The call site uses a non-null assertion on x.resources when
building availableResources; change getAvailableResources to accept resources?:
NodeResources (or the appropriate type) and handle undefined internally (reusing
parseNodeResources behavior), then remove the non-null assertion in the map
(i.e., call getAvailableResources(x.resources)); update the
getAvailableResources signature and any callers to accept undefined so no
runtime error occurs when resources is missing.

@stalniy stalniy force-pushed the fix/indexer-strict-types2 branch from 84a84b8 to 51a7b88 Compare February 8, 2026 05:56
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