refactor(adapter): extract MessagingManager from adapter.ts#3365
Open
Apollon77 wants to merge 20 commits into
Open
refactor(adapter): extract MessagingManager from adapter.ts#3365Apollon77 wants to merge 20 commits into
Apollon77 wants to merge 20 commits into
Conversation
Sets up a mocha + ts-node/esm unit-test runner for packages/adapter. register-test.mjs registers ts-node and an @/ path-alias ESM hook; tsconfig.test.json adds @iobroker/types-dev and test types so the type checker passes without the triple-slash reference in index.ts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…anager Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Wire MessagingManager into AdapterClass: construct it in the constructor with late-bound getters for namespace/namespaceLog/host and the states/objects/common handles (all re-derived or assigned after construction in _initAdapter), reduce sendTo/sendToHost/sendToUI/ registerNotification to assert+delegate, and route the messagebox-ack handler and stop cleanup through resolveCallback/clearPendingCallbacks. Removes the inline _sendTo/_sendToHost and the messageCallbacks/ _callbackId/mboxSubscribed fields. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ssaging-manager # Conflicts: # packages/adapter/src/lib/adapter/adapter.ts
register-test.mjs is a Node ESM test-harness hook, not part of any tsconfig project; the eslint project service errors on it. Exclude it from linting. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The pinned redis-64 3.0.503 was removed from the Chocolatey community feed, failing the Windows CI 'Prepare installation' step. 3.1.0 is the latest available (deprecated) redis-64 build. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
redis-64 3.1.0 is now a shim that installs Memurai (Redis-compatible), which provides a 'Memurai' Windows service and no redis-server.exe. The old Start-Process redis-server.exe failed with 'cannot find the file'. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
choco redis-64 3.1.0 now installs Memurai, whose Developer-edition service does not reliably serve on 6379 in CI (REDIS tests failed with 'DB closed'). Download tporadowski/redis (maintained native Windows Redis port) and run its real redis-server.exe, restoring the original -PassThru start. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…n compat layer Async-only core: MessagingManager throws on error (no maybeCallback internals), sendTo/sendToHost return Promises, reply-wait uses a promise-resolver registry, resolveCallback resolves the pending promise. sendToAsync becomes canonical; sendTo/sendToHost are thin callback-compat wrappers. Validation errors now surface async (callback arg / rejected promise) instead of sync-throw. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ared AdapterContext AsyncAdapter (new) owns the async-only managers and exposes the clean async API (no *Async postfix); AdapterClass holds it as #async and delegates the converted methods in (sendToAsync -> async.sendTo, callback sendTo wraps it). Managers now read a single shared AdapterContext (live getter properties) instead of per-manager getter bundles, ready for reuse by future managers. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
3240106 to
f415cee
Compare
All sendTo/sendToHost/sendToUI/registerNotification param assertions now live in the AsyncAdapter facade (typed-public + unknown-impl overloads validate and narrow without casts), so direct async calls are validated too. MessagingManager is now pure async logic; adapter.ts callback wrappers keep only arg-shuffle + callback routing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ssaging-manager # Conflicts: # packages/adapter/src/lib/adapter/adapter.ts
TS6's stricter inference makes the obj/42 'as any' casts unnecessary; @typescript-eslint/no-unnecessary-type-assertion now errors on them. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First step of the
adapter.tsdecomposition (perdocs/superpowers/specs/2026-06-23-adapter-refactor-design.md, approach A3 hybrid): extract the messaging subsystem out of the 13,805-lineAdapterClassgod-object into a composed, independently-testableMessagingManager, behind an unchanged public API.What moved
sendTo,sendToHost,sendToUI,registerNotification, plus the pending message-callback registry (messageCallbacksmap, id counter, mbox-subscribed flag) now live inpackages/adapter/src/lib/adapter/managers/MessagingManager.ts.assert + delegate.assertXreturns aValidated<T>discriminated union; the public wrapper preserves each method's original error mechanism (synchronous throw forsendTo/sendToHost/sendToUI, async reject forregisterNotification).#states,#objects,common,host,namespace,namespaceLog) exclusively through injected getters — avoiding the value-capture trap, since several of these are (re)assigned in_initAdapterafter the manager is constructed._sendTo/_sendToHostand the three moved fields are deleted fromadapter.ts; two external touch-points (incoming-ack handler, stop cleanup) callresolveCallback/clearPendingCallbacks.Tests
adapterpackage (npm run test-adapter, mocha + ts-node ESM hook).MessagingManagerunit tests — first isolated coverage of this subsystem, no controller boot required.tsc -bcompiles clean. Fullnpm testintegration suite green except 4 Redis-backend tests that require a local Redis (no DB code touched here).Scope / not in this PR
Deliberately a behavior-preserving pure move — no public API change. Logging, ACL, Certificate managers and the object/state/lifecycle core remain in
adapter.ts(future PRs per the spec).🤖 Generated with Claude Code