Repository navigation
fix: return receivers from fluent methods - #256
Conversation
|
Warning Review limit reached
Next review available in: 36 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (9)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Summary
Smocket declared and implemented five Socket.IO methods as returning
voideven though each method is fluent in both Socket.IO's runtime and public TypeScript surface.Server.use()andNamespace.use()registered middleware correctly, serverSocket.disconnect()performed the expected teardown, and clientSocket.connect()andSocket.disconnect()changed connection state correctly, but application code could not use the receiver returned by the equivalent Socket.IO call. The mismatch also erased the event maps and socket data that should remain available after a fluent call.This changes those five contracts to return
thisand makes every implementation path return the object on which it was called. The server and namespace middleware methods return their own registration receiver. Server socket disconnect returns the same socket after initiating its existing teardown. Client connect returns the same socket while already connected, while starting a reconnection, and after an invalid namespace result. Client disconnect returns the same socket after an active teardown and while already disconnected. The terminal missing-origin client remains inert under ADR 0005, but its connect and disconnect methods now return that same failed client instead ofundefined.No delivery, admission, or lifecycle rule changes with the return value. Middleware order and rejection remain unchanged, reconnect still creates a fresh server socket under ADR 0013, disconnect still uses the existing reasons and cleanup order, and callers that ignore a result continue to compile.
Server.on()is deliberately untouched. Socket.IO declares that method as returningthiswhile its runtime returns the root namespace, so issue #233 excludes it rather than treating every server method as uniformly fluent.Socket.IO reference
Fresh runtime probes and strict consumer type fixtures were run independently against Socket.IO and socket.io-client 4.7.5 and 4.8.3 before Smocket changed. Both supported version pairs produced the same receiver identity and declared every covered method as returning
this.io.use(middleware)Serverinstanceio.of(name).use(middleware)Namespaceinstancesocket.disconnect()Socketinstancesocket.connect()before openingSocketinstancesocket.connect()while connectedSocketinstancesocket.disconnect()while connectedSocketinstancesocket.disconnect()while disconnectedSocketinstancethisThe two version fixtures also chained
Server.use()twice with non-default client-to-server events, server-to-client events, inter-server events, and socket data. Middleware on both calls retained the incoming listener map, outgoing emitter map, and typedsocket.data; namespace middleware retained the same four generic positions. Server and client socket assignments confirmed that disconnect and connect return their fully parameterized socket types rather than a broad untyped receiver.Runtime identity and branches
The implementation returns from the concrete receivers instead of relying on delegated return values.
Server.use()still delegates registration to the root namespace but returns the server, whileNamespace.use()returns the namespace that stores the middleware. This distinction matters because returning the namespace from the server method would preserve chaining but fail the measured identity.Client methods close every branch with the receiver. An already-connected connect remains a no-op that returns the client. A disconnected client with a registered namespace starts the same fresh pairing as before and then returns the client. A missing namespace emits the same
Invalid namespaceresult and returns the client, allowing a later registration and retry. Active and inactive disconnect calls likewise preserve their existing teardown or cancellation behavior before returning the client. The missing-originFailedClientSocketkeeps its terminal no-retry behavior while exposing the same fluent shape as an unconnected Socket.IO client.Server socket disconnect returns only after the existing synchronous peer state transition and asynchronous teardown have been initiated. It does not await teardown, change the
closeargument behavior, or broaden the connection-wide scope tracked separately by ADR 0028 and issue #254.Public type surface
ServerContract,NamespaceContract,ServerSocketContract, andClientSocketContractnow express the five returns with polymorphicthis, so a concrete SmocketServeror socket subtype is not widened by chaining. Existing calls that discard the result remain valid because TypeScript permits an ignored non-void return.The structural Socket.IO parity projections use explicit recursive receiver types for these members. TypeScript does not allow a
thistype in the intersection type aliases used to omit Socket.IO's internal listener fallback declarations, so naming each projection's own parameterized type preserves the same check without weakening it toany. TheEnsureguards continue to compile for default and concrete event maps against the installed Socket.IO declarations.src/event-maps.typecheck.tsexercises all five Smocket returns and their real Socket.IO counterparts. It chains root middleware twice, registers typed namespace middleware, assigns the server socket disconnect result, and assigns both client connect and disconnect results. The callbacks read and write non-default event maps and socket data after each fluent boundary, so a return that lost generic information would fail typecheck.Tests and documentation
src/emitter-returns.test.tsadds real-first identity cases for server and namespace middleware registration, client connect while connected and reconnecting, client disconnect while connected and already disconnected, and server socket disconnect. Existing namespace coverage now asserts the receiver on a rejected retry before registration and on the successful retry after registration. The missing-origin test asserts both inert client methods, covering the terminal client implementation without changing its intentional divergence.docs/conformance.mdis regenerated from the green dual run, records the four new real-first cases, and broadens the generated area from emitter-only returns to the full return-value surface. The fluent-return entry is removed fromdocs/differences.mdsection C because #233 is no longer an accidental fidelity gap. Thedisconnect(true)gap added by ADR 0028 remains present and is unaffected. Under ADR 0019 this observable correction toward measured Socket.IO behavior lands in the pre-1.0 patch scheduled for v0.4.3.Locally, the Node dual run passes 454 tests across 50 files, the Chromium mock run passes 227 tests across 25 files, and the published dist run passes 196 tests across 22 files. Every executable line changed in
src/mock-server.ts, including invalid-namespace and terminal missing-origin returns, has a non-zero hit count in the local coverage report. TypeScript, ESLint, Prettier, coverage, conformance drift, build, smoke, external-import inspection, publint, and Are the Types Wrong all pass.Related issue
Closes #233
Checklist