Skip to content

Conversation

@dirkwa
Copy link
Contributor

@dirkwa dirkwa commented Jan 23, 2026

Description:

Convert the interdependent request/response handling chain from JavaScript to TypeScript with proper type safety.

Files converted

  • requestResponse.js → requestResponse.ts
  • put.js → put.ts
  • interfaces/ws.js → interfaces/ws.ts
  • tokensecurity.js → tokensecurity.ts

Supporting changes

  • Add shared types to security.ts (SkPrincipal, Delta, SecurityStrategy interface)
  • Add type declarations for primus (src/@types/primus.d.ts)
  • Update dummysecurity.ts to use proper types instead of eslint-disable
  • Update consumers to use SkPrincipal type (deltacache.ts, subscriptionmanager.ts, api/streams/index.ts)
  • Add @types/bcryptjs, @types/cookie-parser, @types/ms dependencies

Approach

These four files form a dependency chain and needed to be converted together. Each file now has proper TypeScript types without using any, eslint-disable, or underscore-prefixed unused parameters. Intentionally unused parameters use void expressions for clarity.

Convert requestResponse.js to TypeScript with strict type definitions.
Remove lodash dependency by using native Object.values/Object.keys.
Convert put.js to TypeScript with proper type definitions, removing the
need for eslint-disable workarounds. Define interfaces for app parameters
(PutApp, PathApp, NotificationApp) that specify only the properties each
function actually uses.

Use branded types (Context, Path, SourceRef) from @signalk/server-api
for type-safe delta construction, following existing codebase patterns.

Add missing 'self' property to FullSignalK type declaration to match
runtime behavior.
Convert the WebSocket interface from JavaScript to TypeScript as part of
the ongoing migration effort.

Changes:
- Rename src/interfaces/ws.js to ws.ts with full type annotations
- Add local Primus type declarations (src/@types/primus.d.ts) since the
  official @types/primus is incompatible with SignalK's runtime mutation
  pattern
- Add AccessRequestData interface to requestResponse.ts for proper typing
  of access request replies
- Add @types/cookie and @types/jsonwebtoken dev dependencies

The conversion maintains all existing functionality while adding type
safety for WebSocket connections, delta handling, backpressure management,
and authentication flows.
@dirkwa
Copy link
Contributor Author

dirkwa commented Jan 23, 2026

The reason why I work in this refactor with a incremental PR approach are the dependencies:

requestResponse.js  ← Foundation (no dependencies)    
       ↓
    put.js          ← Core API                        
       ↓
    ws.js           ← WebSocket handler               
       ↓
tokensecurity.js    ← Security 

The interfaces/index.js dynamically loads interface modules using
require(), which expects module.exports to be the function directly.
ES module default exports compile to exports.default, causing
"theInterface is not a function" error at runtime.

Change from ES module default export to named function with explicit
module.exports assignment to maintain compatibility with the existing
CommonJS interface loading pattern.
Convert tokensecurity.js to tokensecurity.ts with full type safety,
completing the chain of 4 interdependent JS→TS conversions.

Add typed interfaces for internal structures (TokenSecurityApp,
JWTPayload, CookieOptions, SecurityOptions, AccessRequestRecord).
Export shared types from security.ts (SkPrincipal, Delta, etc.).
Update supporting files with proper SkPrincipal type usage.
@dirkwa
Copy link
Contributor Author

dirkwa commented Jan 25, 2026

@tkurki
As requested here the "all-in-one" PR.

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.

1 participant