Conversation
…#3] Adds encode/decode wrappers over @msgpack/msgpack, GatewayState enum, Opcodes constants, and typed payload interfaces (GatewayPayload, IdentifyData, ReadyData). GatewayClient connection layer is pending architecture decisions.
WebSocket lifecycle with Identify on open, Ready handler, heartbeat loop with missed-ACK tracking, exponential backoff reconnect, and sequence number tracking. Gateway is internal — not exported from the package.
discord.js-style Client over an internal Gateway WebSocket manager. Gateway handles connect/identify/heartbeat/reconnect with exponential backoff and a clean intentionalClose flag. Client maps raw SCREAMING_SNAKE dispatch events to camelCase EventEmitter events with typed overloads. Structure classes (Message, Server, Channel, User) wrap raw API shapes. Message exposes reply(), edit(), delete() via ClientRef to avoid circular imports. Shared src/types.ts deduplicates raw interfaces between REST and gateway. ReadyEvent emits structured User/Server objects, not raw wire data.
…caffold [refs #3] Heartbeat interval wasn't stopped before closing the socket on timeout — kept firing close() against an already-dying connection. Also swapped the ws! non-null assertion in _onOpen to optional chaining since disconnect() can race with the open event. Rate limit bucket had a 10ms spin loop for mutual exclusion, which is just wasteful. Replaced it with a promise-chain mutex. Also fixed processQueue blindly resetting remaining after sleeping without checking if update() shifted the window mid-wait. REST retry loop was skipping bucket.acquire() on retries, so retried requests flew under the bucket's radar entirely. And there was no token guard — missing token just gave you unhelpful 401s instead of a clear error up front. Gave Channel, Server, and User constructors a ClientRef param to match Message, so adding REST methods to them later won't break the constructor signature. Added vitest + 17 tests for the bucket, REST token guard, snowflake validation, and structure wiring. Test: vitest run -- 17 passed, 0 failed (RateLimitBucket, REST, structures)
vitest is wired up now, CI should actually run it. Test: n/a (workflow change)
Was gitignored, which broke actions/setup-node cache lookup. npm ci needs the lockfile anyway. Test: n/a (infra change)
tsconfig excludes *.test.ts but eslint was still trying to parse them against it. Added ignorePatterns so they don't collide. Test: eslint src --ext .ts — 0 errors, 1 pre-existing warning
…refs #3] Wrapped structure instantiation in #wire() handlers with try-catch so a malformed payload from the gateway doesn't crash the whole bot — errors route to the 'error' event instead. Capped incoming WebSocket frames at 4MB via maxPayload on the ws constructor. Without it a rogue payload could eat all memory. Swapped the Client event overload list for a proper ClientEvents mapped type — less duplication and kills the no-explicit-any warning. Added a 100ms backoff in the rate limit bucket's processQueue when the reset window shifts mid-sleep, prevents tight looping on inconsistent server headers.
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
Closes #3
Test plan
npm testpasses — 17 tests across bucket, REST, and structurestsc --noEmitclean