I prefer semicolors, they also help avoiding certain pitfalls in JavaScript/TypeScript, such as the following code sample:
```js
const xyz = "test"
(something.else as string) = "another"
```
This results in a TypeError: "test" is not a function, this is because js thinks we are trying to call the string "test" as a function.
To fix this it requires a `;` somewhere before the `(`, such as `;(something ... ` which in my opinion is ugly and less clean overall.
forwardToBot has been removed in favor of directly using the events.message.
the default implementation for forwardToBot used to camelize the packet, however in most cases you want to preserve the snake_case, and for those that need camelCase it can be easly done in the message event function.
This also removes the gateway.preferSnakeCase option as it no longer has a use
The typedoc config is now only in the top-level config file instead of also being one per package
and all internal APIs are now marked as private so typedoc won't generate documentation for them, however we still need to export them to avoid typedoc warnings
The new internal APIs that are exported, since are marked as `@private` can have breaking changes without notices
* feat(gateway): Rework how shards are resharded
* Make bigbot example use the resharding
* fix reshard doesn't increment the lastShardId
From my testing it works, however i don't know if we should just do
this or is there a better way
* revert createGatewayManager type changes
It breaks if you want to disable resharding, didn't think of that
* Fix typo (#4252)
* Apply suggestions from code review
Co-authored-by: Link <lts20050703@gmail.com>
---------
Co-authored-by: NotDemonix <90858555+NotDemonix@users.noreply.github.com>
Co-authored-by: Link <lts20050703@gmail.com>
* Keep state to avoid unwanted disconnections
This keeps a state to know that we wanted to end the connection with a
code of 1000 or 1001 to avoid unwanted disconnections in case discord /
someone in the middle of the TCP connection (such as cloudflare) sends a
close code of 1000 or 1001.
* Apply suggestions from code review
Co-authored-by: Awesome Stickz <awesome@stickz.dev>
---------
Co-authored-by: Awesome Stickz <awesome@stickz.dev>
* fix(gateway): set a nonce if none is provided for gateway.requestMembers
* chore: update comment for gateway.requestMembers to clarify about gateway.cache.requestMembers.enabled
* chore: make the comment better
* fix: add node:crypto import to deno import map
* fix(gateway): shard.resume() ending in a loop of constant resumes
* refactor(gateway): change shard.close() to async and move resolve logic to shard.close()
* refactor: wait for shard.close() promise in gateway.shutdown()
* Fix integration test
---------
Co-authored-by: Fleny <fleny113@outlook.com>
* Attempt to fix shard reconnecting in a loop
* Add a bit of logging on READY & RESUMED
* Fix integration tests
* Revert turbo.json change
* Pass down the logger to LeakyBucket on HELLO
* Update some logs
---------
Co-authored-by: Awesome Stickz <awesome@stickz.dev>
* Add zlib-stream transport-compression support
* remove external buffer, add the url param
this also fixes the CI Deno error
* use a queue and promises
instead of calling handleDiscordPacket from the callback of inflate.on('data')
* Add zstd support
* Re-add payload compression, set fzstd as optional, refactor
* add comment for decompressionPromisesQueue
* fix comment for isCompressed
* Don't create a new Uint8Array if the input is a Buffer
* Use a Uint8Array buffer instead of parsing incomplete JSON chunks
* remove old commented code
* Change ts expect error message
* use type import for ShardGatewayConfig
* Apply suggestions from code review
Co-authored-by: LTS (Link) <lts20050703@gmail.com>
---------
Co-authored-by: LTS (Link) <lts20050703@gmail.com>
* Use the native WebSocket implementation when available
* merge types.js import in shard
* Apply suggestions from code review
Co-authored-by: Awesome Stickz <awesome@stickz.dev>
* Do not use the WebSocket global on Node
---------
Co-authored-by: Awesome Stickz <awesome@stickz.dev>
* Improve logging, keep shard collections separated
* revert to erroring in getSessionInfo. Fill the value in createBot
* removed useless if
* remove same number of shards check
Co-authored-by: Awesome Stickz <awesome@stickz.dev>
* Update manager.ts
* revert shard.events.message assignment for the spread
* use new Collection instead of .clear() + for-of
* Use fixed formula and note in the comment the inaccuracy
* Apply suggestions from code review
Co-authored-by: Awesome Stickz <awesome@stickz.dev>
* Add a remark to shardsFullPercentage to let the user know of the inaccuracy
* Update comment and add a clearInterval
The clearInterval is not strictly needed, however it is better to ensure there is always one and only one internal running at a given point
* revert check for all shards online
It was bugged as gateway.resharding.shards gets populated overtime and not instantly
---------
Co-authored-by: Awesome Stickz <awesome@stickz.dev>
* Migrate eslint and prettier to biomejs
This does NOT include examples/bigbot as it has its own formatter
* Update to biome 1.8.0
* Readd dotenv dev dependency to rest
During a merge it got lost
* feat: base work for reshardinf system
* fix: magic
* fix: y did i do this
* Fix typings for checkIfReshardingIsNeeded
* Update packages/gateway/src/manager.ts
Co-authored-by: Awesome Stickz <awesome@stickz.dev>
* Update packages/gateway/src/manager.ts
Co-authored-by: Awesome Stickz <awesome@stickz.dev>
* Update packages/gateway/src/manager.ts
Co-authored-by: LTS20050703 <lts20050703@gmail.com>
* fix: checking info.firstShardId, lastShardId
* fix: checking pending shards against totalShards instead of total used shards
* fix: changing new shards' message event when trying to change old shards' message event, causing it to be unable to process those events
* ci can stop crying now
* chore: specify usaage of updateGuildsShardId
* move executing updateGuildsShardId from shard.events to shard.forwardToBot as none of those events are being executed
* remove todo
* fix: calculateTotalShards() for bots in over 100k servers that don't have LBS and update comments
* use logger.debug in updateGuildsShardId instead of logger.warn
* feat: automatic resharding
* move auto resharding into gateway.spawnShards() and clear interval on gateway.shutdown()
* fix: both old shards and new shards processing events at the same time
* Copy all shard events provided in the options to new shards instead of just the mesasge event
* Added clearReshardingInterval parameter to manager.shutdown function so reshard function doesn't end up clearing this interval
---------
Co-authored-by: Awesome Stickz <awesome@stickz.dev>
Co-authored-by: Fleny <fleny113@outlook.com>
Co-authored-by: LTS20050703 <lts20050703@gmail.com>
* misc: Make the token a required property on the rest manager.
* refactor: Make unnecessarily required properties optional.
* misc: Improve interface for `createBot()` and allow passing in `transformers`/`handlers`.
* fix: Test made redundant by changes still being included.
* fix: Missing non-null assertions.
* fix: Benchmarks failing.
* misc: Remove `cache.requestMembers.pending` as an exposed option.
* style: Switch back to interface approach.
* chore(deps): upgrade deps to latest in range
* feat: upgrade node engine minimum
Closes#3173
* fix: typing errors after dep upgrade
* chore(deps): upgrade benchmark typescript version
* feat: upgrade eslint, lint staged, and es version
* fix: lint-staged failures
* style: formatting
* chore(deps): major version upgrades
* chore(deps): upgrade yarn to 4.0
* fix: lock typescript to 5.2.2 until ts-node/mocha fix
bug: https://github.com/mochajs/mocha/issues/5031
* chore: remove old Deno file
Went through history and can't find any reference to this after Deno rewrite
* chore(deps): more dep updates
* feat: typedoc config upgrade
* fix: temporarily reset docusaurus to main
* chore(deps): minor range upgrades
* chore(deps)!: docusaurus major upgrade
* revert: go back to original 2.x docusaurus