@wolfstar/plugin-gateway 0.2.0-next-20260927082257 → 0.2.0-next-20260927120310
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -16
- package/dist/esm/index.d.ts +512 -489
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +726 -833
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -340,16 +340,29 @@ passing either alongside it throws. `destroy({ resumable: true })` also works wi
|
|
|
340
340
|
|
|
341
341
|
## Structures
|
|
342
342
|
|
|
343
|
-
|
|
343
|
+
Structures extend the ones
|
|
344
|
+
[`@discordjs/structures`](https://github.com/discordjs/discord.js/tree/main/packages/structures)
|
|
345
|
+
already ships (`User`, `Message`, `Attachment`, `Embed`, `Reaction`, `Poll`, `Emoji`, `Invite`,
|
|
346
|
+
`Presence`, `Activity`, `VoiceState`, `Webhook`, `Sticker`, `StickerPack`, `SoundboardSound`,
|
|
347
|
+
`StageInstance`, `AutoModerationRule`, and every channel type), adding relations resolved from the
|
|
348
|
+
cache, CDN URLs, and actions through the client. The ones it has no counterpart for yet (`Guild`,
|
|
349
|
+
`GuildMember`, `Role`, `ThreadMember`, `GuildScheduledEvent`, ...) extend its base `Structure`.
|
|
350
|
+
They live in one folder per domain, each with an `index.ts`, mirroring `@discordjs/structures`:
|
|
351
|
+
`automoderation/`, `channels/` (and `channels/mixins/`), `emojis/`, `guilds/`, `invites/`,
|
|
352
|
+
`messages/`, `polls/`, `presences/`, `soundboards/`, `stageInstances/`, `stickers/`, `users/`,
|
|
353
|
+
`voice/`, and `webhooks/`.
|
|
354
|
+
|
|
355
|
+
Where a getter of ours has stricter semantics (e.g. `null` or a default instead of `undefined`),
|
|
356
|
+
it overrides `@discordjs/structures`' one, which keeps typing it.
|
|
357
|
+
|
|
344
358
|
Channels get one class per type (`TextChannel`, `VoiceChannel`, `ForumChannel`,
|
|
345
|
-
`PublicThreadChannel`, `DMChannel`, ...),
|
|
346
|
-
(`GuildChannelMixin`, `ChannelTopicMixin`, `ThreadChannelMixin`, ...)
|
|
347
|
-
|
|
348
|
-
`
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
original API fields.
|
|
359
|
+
`PublicThreadChannel`, `DMChannel`, ...), each extending `@discordjs/structures`' own and composed
|
|
360
|
+
from mixins (`GuildChannelMixin`, `ChannelTopicMixin`, `ThreadChannelMixin`, ...). `instanceof
|
|
361
|
+
Channel` matches any of them. `ChannelManager` picks the class matching the channel type,
|
|
362
|
+
`BaseChannel` covers the unknown ones. Channel mixins can supply a `DataTemplate`, an
|
|
363
|
+
`optimizeData` hook, and an `enrichToJSON` hook. Construction and patches optimize timestamps
|
|
364
|
+
across channels, messages, members, invites, events, templates, and voice states, as well as role
|
|
365
|
+
and overwrite permission bits. `toJSON()` retains the original API fields.
|
|
353
366
|
|
|
354
367
|
```ts
|
|
355
368
|
client.on("channelCreate", (channel) => {
|
|
@@ -360,8 +373,8 @@ client.on("channelCreate", (channel) => {
|
|
|
360
373
|
Structures never hold a reference to the client. Every channel has `fetch()` and `delete()`
|
|
361
374
|
(from `BaseChannelMixin`), which use `@discordjs/core` for API calls.
|
|
362
375
|
|
|
363
|
-
`Structure`, `Mixin`, and the `kData`, `kPatch`,
|
|
364
|
-
can be subclassed and new mixins written:
|
|
376
|
+
`Structure`, `StructureMixin`, `initStructure`, `Mixin`, `MixinTypes`, and the `kData`, `kPatch`,
|
|
377
|
+
and `kClone` symbols are exported, so structures can be subclassed and new mixins written:
|
|
365
378
|
|
|
366
379
|
```ts
|
|
367
380
|
import { Mixin, TextChannel, kData } from "@wolfstar/plugin-gateway";
|
|
@@ -370,14 +383,28 @@ class MyTextChannel extends TextChannel {}
|
|
|
370
383
|
Mixin(MyTextChannel, [MyMixin]);
|
|
371
384
|
```
|
|
372
385
|
|
|
386
|
+
To extend another `@discordjs/structures` class the same way, mix `StructureMixin` in and call
|
|
387
|
+
`initStructure` from the constructor:
|
|
388
|
+
|
|
389
|
+
```ts
|
|
390
|
+
import { User as BaseUser } from "@discordjs/structures";
|
|
391
|
+
import { initStructure, Mixin, StructureMixin } from "@wolfstar/plugin-gateway";
|
|
392
|
+
|
|
393
|
+
export interface MyUser extends StructureMixin<APIUser> {}
|
|
394
|
+
export class MyUser extends BaseUser {
|
|
395
|
+
public constructor(data: APIUser, relations: object = {}) {
|
|
396
|
+
super(data);
|
|
397
|
+
initStructure(this, data, relations);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
Mixin(MyUser, [StructureMixin]);
|
|
401
|
+
```
|
|
402
|
+
|
|
373
403
|
> [!NOTE]
|
|
374
|
-
> `
|
|
375
|
-
> [`@discordjs/structures`](https://github.com/discordjs/discord.js/tree/main/packages/structures)'
|
|
376
|
-
> own base class. That package does not export the symbols keying a structure's data and its
|
|
404
|
+
> `@discordjs/structures` does not export the symbols keying a structure's data and its
|
|
377
405
|
> patch/clone methods, but creates them with `Symbol.for`, so `kData`, `kPatch`, and `kClone` are the
|
|
378
406
|
> very same symbols, re-exported for subclasses and mixins. It is only published as `dev` snapshots
|
|
379
|
-
> requiring Node.js 24.17 (hence this package's `engines`)
|
|
380
|
-
> yet: the structures here are this package's own, following its conventions.
|
|
407
|
+
> requiring Node.js 24.17 (hence this package's `engines`).
|
|
381
408
|
|
|
382
409
|
### Guilds, emojis, stickers and invites
|
|
383
410
|
|